66 #include "FXRectangle.h" 67 #include "FXRegistry.h" 68 #include "FXAccelTable.h" 71 #include "FXTextField.h" 96 #define BUTTONWIDTH 12 99 #define INTMAX 2147483647 100 #define INTMIN (-INTMAX-1) 102 #define SPINDIAL_MASK (SPINDIAL_CYCLIC|SPINDIAL_NOTEXT|SPINDIAL_NOBUTTONS|SPINDIAL_NODIAL|SPINDIAL_NOMAX|SPINDIAL_NOMIN|SPINDIAL_LOG) 119 long onKey(FXObject*, FXSelector,
void*);
124 long onMotion(FXObject*, FXSelector,
void*);
125 long onAuto(FXObject*, FXSelector,
void*);
133 FXRealSpinDialDial(FXComposite* p, FXObject* tgt = NULL, FXSelector sel = 0, FXuint opts = DIAL_NORMAL,
134 FXint x = 0, FXint y = 0, FXint w = 0, FXint h = 0,
135 FXint pl = DEFAULT_PAD, FXint pr = DEFAULT_PAD, FXint pt = DEFAULT_PAD, FXint pb = DEFAULT_PAD):
136 FXDial(p, tgt, sel, opts, x, y, w, h, pl, pr, pt, pb) {}
165 return target->handle(o, s, p);
171 return FXDial::onLeftBtnPress(o, s, p);
175 return FXDial::onLeftBtnRelease(o, s, p);
182 FXEvent*
event = (FXEvent*)p;
183 if (options & DIAL_HORIZONTAL) {
184 dragpoint =
event->win_x;
186 dragpoint =
event->win_y;
188 getApp()->addTimeout(
this,
ID_AUTOSPIN, getApp()->getScrollSpeed());
203 getApp()->addTimeout(
this,
ID_AUTOSPIN, getApp()->getScrollSpeed());
204 setValue(getValue() +
int((dragpoint - dragpos) /
float(5)));
207 target->handle(
this, FXSEL(SEL_CHANGED, message), &v);
216 if (target && target->handle(
this, FXSEL(SEL_MOTION, message), p)) {
220 FXbool bJump = FALSE;
221 FXEvent* e = (FXEvent*)p;
222 if (!(flags & FLAG_PRESSED)) {
225 FXWindow* rootWin = getApp()->getRootWindow();
226 FXint x = e->root_x, y = e->root_y;
227 if (e->root_x >= rootWin->getWidth() - 1) {
231 }
else if (e->root_x <= 10) {
236 if (e->root_y >= rootWin->getHeight() - 1) {
240 }
else if (e->root_y <= 10) {
246 rootWin->setCursorPosition(x, y);
249 return FXDial::onMotion(o, s, p);
268 long onKey(FXObject*, FXSelector,
void*);
279 FXuint opts = ARROW_NORMAL,
280 FXint x = 0, FXint y = 0, FXint w = 0, FXint h = 0,
281 FXint pl = DEFAULT_PAD, FXint pr = DEFAULT_PAD, FXint pt = DEFAULT_PAD, FXint pb = DEFAULT_PAD):
282 FXArrowButton(p, tgt, sel, opts, x, y, w, h, pl, pr, pt, pb) {}
296 FXIMPLEMENT(
FXRealSpinDialBtn, FXArrowButton, FXSpinDialBtnMap, ARRAYNUMBER(FXSpinDialBtnMap))
307 return target->handle(o, s, p);
313 return FXArrowButton::onLeftBtnPress(o, s, p);
317 return FXArrowButton::onLeftBtnRelease(o, s, p);
337 long onCmdSetRealValue(FXObject*, FXSelector,
void*);
338 long onMotion(FXObject*, FXSelector,
void*);
349 FXuint opts = TEXTFIELD_NORMAL,
350 FXint x = 0, FXint y = 0, FXint w = 0, FXint h = 0, FXint
351 pl = DEFAULT_PAD, FXint pr = DEFAULT_PAD, FXint pt = DEFAULT_PAD, FXint pb = DEFAULT_PAD
353 FXTextField(p, ncols, tgt, sel, opts, x, y, w, h, pl, pr, pt, pb),
361 flags &= ~FLAG_FMTSTRING;
371 flags |= FLAG_FMTSTRING;
388 FXIMPLEMENT(
FXRealSpinDialText, FXTextField, FXSpinDialTextMap, ARRAYNUMBER(FXSpinDialTextMap))
396 if (target && target->handle(
this, FXSEL(SEL_MOTION, message), ptr)) {
399 return FXTextField::onMotion(o, s, ptr);
403 if (flags & FLAG_FMTSTRING) {
404 setText(FXStringFormat(fmtString.text(), *((FXdouble*)ptr)));
406 setText(FXStringVal(*((FXdouble*)ptr), precision, exponent));
453 FXIMPLEMENT(
FXRealSpinDial, FXPacker, FXRealSpinDialMap, ARRAYNUMBER(FXRealSpinDialMap))
458 flags = (flags | FLAG_ENABLED | FLAG_SHOWN) & ~FLAG_UPDATE;
474 FXRealSpinDial::FXRealSpinDial(FXComposite* p, FXint cols, FXObject* tgt, FXSelector sel, FXuint opts, FXint x, FXint y, FXint w, FXint h, FXint pl, FXint pr, FXint pt, FXint pb):
475 FXPacker(p, opts & ~(FRAME_RIDGE), x, y, w, h, 0, 0, 0, 0, 0, 0) {
476 flags = (flags | FLAG_ENABLED | FLAG_SHOWN) & ~FLAG_UPDATE;
479 dial =
new FXRealSpinDialDial(
this,
this,
ID_DIAL, DIAL_VERTICAL, 0, 0, 0, 0, 0, 0, 0, 0);
480 dial->setNotchSpacing(450);
482 upButton =
new FXRealSpinDialBtn(
this,
this,
ID_INCREMENT, FRAME_RAISED | FRAME_THICK | ARROW_UP | ARROW_REPEAT, 0, 0, 0, 0, 0, 0, 0, 0);
483 downButton =
new FXRealSpinDialBtn(
this,
this,
ID_DECREMENT, FRAME_RAISED | FRAME_THICK | ARROW_DOWN | ARROW_REPEAT, 0, 0, 0, 0, 0, 0, 0, 0);
486 textField =
new FXRealSpinDialText(
this, cols,
this,
ID_ENTRY, (opts & ~(
SPINDIAL_NOMAX |
SPINDIAL_NOMIN)) | TEXTFIELD_REAL | JUSTIFY_RIGHT, 0, 0, 0, 0, pl, pr, pt, pb);
512 return textField->getDefaultHeight() + (border << 1);
524 if (!(flags & FLAG_ENABLED)) {
534 if (flags & FLAG_ENABLED) {
544 FXint dialHeight, buttonHeight, textHeight;
546 textHeight = height - 2 * border;
547 dialHeight = textHeight;
548 buttonHeight = textHeight >> 1;
551 if ((options & hideOpts) == hideOpts) {
552 flags &= ~FLAG_DIRTY;
556 FXint right = width - border;
565 upButton->position(border, border, bw, buttonHeight);
566 downButton->position(border, height - buttonHeight - border, bw, buttonHeight);
569 dial->position(left, border, right - left, dialHeight);
571 upButton->position(border, border, right - border, buttonHeight);
572 downButton->position(border, height - buttonHeight - border, right - border, buttonHeight);
578 dial->position(right - w, border, w, dialHeight);
583 upButton->position(right - w, border, w, buttonHeight);
584 downButton->position(right - w, height - buttonHeight - border, w, buttonHeight);
587 textField->position(border, border, right - border, textHeight);
589 flags &= ~FLAG_DIRTY;
596 sender->handle(
this, FXSEL(SEL_COMMAND, ID_ENABLE), NULL);
598 sender->handle(
this, FXSEL(SEL_COMMAND, ID_DISABLE), NULL);
611 if (FXApp::instance()->getKeyState(CONTROLMASK)) {
613 }
else if (FXApp::instance()->getKeyState(SHIFTMASK)) {
626 if (options & SPINDIAL_LOG) {
628 FXdouble lr0 = log(
range[0]), lr1 = log(
range[1]), lnp = log(newpos);
629 newpos = exp(lr0 + fmod(lnp - lr0, lr1 - lr0));
637 if (options & SPINDIAL_LOG) {
639 FXdouble lr0 = log(
range[0]), lr1 = log(
range[1]), lpos = log(
pos);
640 FXdouble span = lr1 - lr0;
641 newpos = exp(lr0 + fmod(lpos - lr0 + 1 + (span - inc), span));
651 target->handle(
this, FXSEL(SEL_COMMAND, message), (
void*)&
pos);
671 if (isEnabled() && ((options & REALSPIN_CYCLIC) || (
pos <
range[1]))) {
672 sender->handle(
this, FXSEL(SEL_COMMAND, ID_ENABLE), NULL);
674 sender->handle(
this, FXSEL(SEL_COMMAND, ID_DISABLE), NULL);
695 target->handle(
this, FXSEL(SEL_COMMAND, message), (
void*)&
pos);
703 if (isEnabled() && ((options & REALSPIN_CYCLIC) || (
range[0] <
pos))) {
704 sender->handle(
this, FXSEL(SEL_COMMAND, ID_ENABLE), NULL);
706 sender->handle(
this, FXSEL(SEL_COMMAND, ID_DISABLE), NULL);
727 target->handle(
this, FXSEL(SEL_COMMAND, message), (
void*)&
pos);
736 return target && target->handle(
this, FXSEL(SEL_UPDATE, message), NULL);
749 if (((FXEvent*)p)->code > 0) {
755 target->handle(
this, FXSEL(SEL_COMMAND, message), (
void*)&
pos);
762 register FXdouble value = FXDoubleVal(
textField->getText());
763 if (value <
range[0]) {
766 if (value >
range[1]) {
772 target->handle(
this, FXSEL(SEL_CHANGED, message), (
void*)&
pos);
783 target->handle(
this, FXSEL(SEL_COMMAND, message), (
void*)&
pos);
791 FXEvent*
event = (FXEvent*)ptr;
796 if (target && target->handle(
this, FXSEL(SEL_KEYPRESS, message), ptr)) {
807 switch (event->code) {
812 target->handle(
this, FXSEL(SEL_COMMAND, message), (
void*)&
pos);
819 target->handle(
this, FXSEL(SEL_COMMAND, message), (
void*)&
pos);
823 return textField->handle(sender, sel, ptr);
830 FXEvent*
event = (FXEvent*)ptr;
835 if (target && target->handle(
this, FXSEL(SEL_KEYRELEASE, message), ptr)) {
838 switch (event->code) {
845 return textField->handle(sender, sel, ptr);
881 FXdouble lo = (FXdouble)((FXint*)ptr)[0];
882 FXdouble hi = (FXdouble)((FXint*)ptr)[1];
890 ((FXdouble*)ptr)[0] =
range[0];
891 ((FXdouble*)ptr)[1] =
range[1];
912 setRange(((FXdouble*)ptr)[0], ((FXdouble*)ptr)[1]);
919 getRange(((FXdouble*)ptr)[0], ((FXdouble*)ptr)[1]);
927 FXdouble inc =
incr[incMode + 1];
934 FXdouble lr0 = log(
range[0]), lr1 = log(
range[1]), lnp = log(newpos);
935 newpos = exp(lr0 + fmod(lnp - lr0, lr1 - lr0));
950 FXdouble inc =
incr[incMode + 1];
957 FXdouble lr0 = log(
range[0]), lr1 = log(
range[1]), lpos = log(
pos);
958 FXdouble span = lr1 - lr0;
959 newpos = exp(lr0 + fmod(lpos - lr0 + 1 + (span - inc), span));
990 fxerror(
"%s::setRange: trying to set negative range.\n", getClassName());
1002 if (value <
range[0]) {
1005 if (value >
range[1]) {
1009 textField->handle(
this, FXSEL(SEL_COMMAND, ID_SETREALVALUE), &value);
1018 fxerror(
"%s::setIncrement: negative or zero increment specified.\n", getClassName());
1024 fxerror(
"%s::setIncrement: negative or zero increment specified.\n", getClassName());
1030 fxerror(
"%s::setIncrement: negative or zero increment specified.\n", getClassName());
1036 fxerror(
"%s::setIncrement: negative or zero increment specified.\n", getClassName());
1053 if (options != opts) {
1075 dial->setHelpText(text);
1090 dial->setTipText(text);
1106 if (options != opts) {
1108 range[0] = -DBL_MAX;
1138 dial->setBackColor(clr);
1143 return dial->getBackColor();
1229 FXPacker::save(store);
1242 FXPacker::load(store);
long onCmdDecrement(FXObject *, FXSelector, void *)
long onCmdGetIntRange(FXObject *, FXSelector, void *)
long onCmdGetRealRange(FXObject *, FXSelector, void *)
FXRealSpinDialText(FXComposite *p, FXint ncols, FXObject *tgt=NULL, FXSelector sel=0, FXuint opts=TEXTFIELD_NORMAL, FXint x=0, FXint y=0, FXint w=0, FXint h=0, FXint pl=DEFAULT_PAD, FXint pr=DEFAULT_PAD, FXint pt=DEFAULT_PAD, FXint pb=DEFAULT_PAD)
Construct a text widget.
FXString getHelpText() const
Get the status line help text for this spinner.
FXbool isEditable() const
Return TRUE if text field is editable.
void selectAll()
Mark the text entry as selected.
void setFineIncrement(FXdouble increment)
Change spinner fine adjustment increment (when CTRL key held down)
FXuint getSpinnerStyle() const
Return current spinner style.
FXColor getDialColor() const
Return color of the dial.
long onKey(FXObject *, FXSelector, void *)
FXFont * getFont() const
Get the text font.
FXString getNumberFormatString() const
Return the format string for number display.
long onUpdEntry(FXObject *, FXSelector, void *)
FXRealSpinDialBtn(FXComposite *p, FXObject *tgt=NULL, FXSelector sel=0, FXuint opts=ARROW_NORMAL, FXint x=0, FXint y=0, FXint w=0, FXint h=0, FXint pl=DEFAULT_PAD, FXint pr=DEFAULT_PAD, FXint pt=DEFAULT_PAD, FXint pb=DEFAULT_PAD)
Construct a dial widget.
FXbool getNumberFormatExponent() const
void setFont(FXFont *fnt)
Set the text font.
void setDialColor(FXColor clr)
Change color of the dial.
virtual FXint getDefaultHeight()
Return default height.
virtual void load(FXStream &store)
Load spinner from a stream.
FXString getTipText() const
Get the tool tip message for this spinner.
virtual void setValue(FXdouble value)
Change current value.
long onButtonPress(FXObject *, FXSelector, void *)
long onCmdSetIntRange(FXObject *, FXSelector, void *)
void setNumberFormat(FXint prec, FXbool bExp=FALSE)
void setCoarseIncrement(FXdouble increment)
Change spinner coarse adjustment increment (when SHIFT key held down)
FXArrowButton * downButton
virtual FXint getDefaultWidth()
Return default width.
void setSpinnerStyle(FXuint style)
Change spinner style.
void setCursorColor(FXColor clr)
Changes the cursor color.
FXbool isCyclic() const
Return TRUE if in cyclic mode.
FXint getNumberFormatPrecision() const
Return the digits of precision used to display numbers.
long onCmdSetValue(FXObject *, FXSelector, void *)
virtual void create()
Create server-side resources.
long onCmdSetRealRange(FXObject *, FXSelector, void *)
void getRange(FXdouble &lo, FXdouble &hi) const
Get the spinner's current range.
long onKeyPress(FXObject *, FXSelector, void *)
virtual void disable()
Disable spinner.
long onRightButtonRelease(FXObject *, FXSelector, void *)
FXColor getCursorColor() const
Return the cursor color.
FXRealSpinDialDial & operator=(const FXRealSpinDialDial &)
FXRealSpinDialDial(FXComposite *p, FXObject *tgt=NULL, FXSelector sel=0, FXuint opts=DIAL_NORMAL, FXint x=0, FXint y=0, FXint w=0, FXint h=0, FXint pl=DEFAULT_PAD, FXint pr=DEFAULT_PAD, FXint pt=DEFAULT_PAD, FXint pb=DEFAULT_PAD)
Construct a dial widget.
void setEditable(FXbool edit=TRUE)
Allow editing of the text field.
void setTextColor(FXColor clr)
Change text color.
long onButtonRelease(FXObject *, FXSelector, void *)
void decrement(FXint incMode=SPINDIAL_INC_NORMAL)
Decrement spinner.
const FXDial & getDial() const
void setSelBackColor(FXColor clr)
Change selected background color.
FXint getNumberFormatPrecision() const
void setRange(FXdouble lo, FXdouble hi)
Change the spinner's range.
long onCmdEntry(FXObject *, FXSelector, void *)
long onCmdSetIntValue(FXObject *, FXSelector, void *)
long onMotion(FXObject *, FXSelector, void *)
long onButtonPress(FXObject *, FXSelector, void *)
FXColor getSelTextColor() const
Return selected text color.
FXColor getTextColor() const
Return text color.
long onUpdDial(FXObject *, FXSelector, void *)
void setFormatString(const FXchar *fmt)
void setTipText(const FXString &text)
Set the tool tip message for this spinner.
long onButtonRelease(FXObject *, FXSelector, void *)
virtual ~FXRealSpinDial()
Destructor.
FXColor getSelBackColor() const
Return selected background color.
void setCyclic(FXbool cyclic)
Set to cyclic mode, i.e. wrap around at maximum/minimum.
long onKeyRelease(FXObject *, FXSelector, void *)
long onUpdDecrement(FXObject *, FXSelector, void *)
long onCmdDial(FXObject *, FXSelector, void *)
void setFormatString(const FXchar *fmt)
long onCmdGetRealValue(FXObject *, FXSelector, void *)
void setTextVisible(FXbool shown)
Set text visible flag.
FXbool getNumberFormatExponent() const
Return whether the exponent is used in number display.
void setNumberFormat(FXint prec, FXbool bExp=FALSE)
long onKey(FXObject *, FXSelector, void *)
long onCmdIncrement(FXObject *, FXSelector, void *)
long onMotion(FXObject *, FXSelector, void *)
FXString getNumberFormatString() const
void increment(FXint incMode=SPINDIAL_INC_NORMAL)
Increment spinner.
FXdouble getValue() const
Return current value.
long onChgEntry(FXObject *, FXSelector, void *)
long onCmdSetRealValue(FXObject *, FXSelector, void *)
void setHelpText(const FXString &text)
Set the status line help text for this spinner.
void setDownArrowColor(FXColor clr)
Change color of the down arrow.
long onMotion(FXObject *, FXSelector, void *)
void setIncrement(FXdouble increment)
Change spinner increment.
long onCmdGetIntValue(FXObject *, FXSelector, void *)
long onUpdIncrement(FXObject *, FXSelector, void *)
void setIncrements(FXdouble fine, FXdouble norm, FXdouble coarse)
Change all spinner increment.
FXDEFMAP(FXRealSpinDialDial) FXSpinDialMap[]
virtual void layout()
Perform layout.
long onMouseWheel(FXObject *, FXSelector, void *)
FXColor getDownArrowColor() const
Return color of the the down arrow.
void setSelTextColor(FXColor clr)
Change selected text color.
FXColor getUpArrowColor() const
Return color of the up arrow.
FXRealSpinDialText * textField
long onAuto(FXObject *, FXSelector, void *)
long onRightButtonPress(FXObject *, FXSelector, void *)
virtual void enable()
Enable spinner.
void setUpArrowColor(FXColor clr)
Change color of the up arrow.
long onCmdSetRealValue(FXObject *, FXSelector, void *)
FXbool isTextVisible() const
Return TRUE if text is visible.
long onChgDial(FXObject *, FXSelector, void *)
virtual void save(FXStream &store) const
Save spinner to a stream.