68 #include "FXRectangle.h" 69 #include "FXRegistry.h" 70 #include "FXAccelTable.h" 73 #include "FXTextField.h" 98 #define BUTTONWIDTH 12 101 #define INTMAX 2147483647 102 #define INTMIN (-INTMAX-1) 104 #define SPINDIAL_MASK (SPINDIAL_CYCLIC|SPINDIAL_NOTEXT|SPINDIAL_NOBUTTONS|SPINDIAL_NODIAL|SPINDIAL_NOMAX|SPINDIAL_NOMIN|SPINDIAL_LOG) 121 long onKey(FXObject*, FXSelector,
void*);
126 long onMotion(FXObject*, FXSelector,
void*);
127 long onAuto(FXObject*, FXSelector,
void*);
135 FXRealSpinDialDial(FXComposite* p, FXObject* tgt = NULL, FXSelector sel = 0, FXuint opts = DIAL_NORMAL,
136 FXint x = 0, FXint y = 0, FXint w = 0, FXint h = 0,
137 FXint pl = DEFAULT_PAD, FXint pr = DEFAULT_PAD, FXint pt = DEFAULT_PAD, FXint pb = DEFAULT_PAD):
138 FXDial(p, tgt, sel, opts, x, y, w, h, pl, pr, pt, pb) {}
167 return target->handle(o, s, p);
173 return FXDial::onLeftBtnPress(o, s, p);
177 return FXDial::onLeftBtnRelease(o, s, p);
184 FXEvent*
event = (FXEvent*)p;
185 if (options & DIAL_HORIZONTAL) {
186 dragpoint =
event->win_x;
188 dragpoint =
event->win_y;
190 getApp()->addTimeout(
this,
ID_AUTOSPIN, getApp()->getScrollSpeed());
205 getApp()->addTimeout(
this,
ID_AUTOSPIN, getApp()->getScrollSpeed());
206 setValue(getValue() +
int((dragpoint - dragpos) /
float(5)));
209 target->handle(
this, FXSEL(SEL_CHANGED, message), &v);
218 if (target && target->handle(
this, FXSEL(SEL_MOTION, message), p)) {
222 FXbool bJump = FALSE;
223 FXEvent* e = (FXEvent*)p;
224 if (!(flags & FLAG_PRESSED)) {
227 FXWindow* rootWin = getApp()->getRootWindow();
228 FXint x = e->root_x, y = e->root_y;
229 if (e->root_x >= rootWin->getWidth() - 1) {
233 }
else if (e->root_x <= 10) {
238 if (e->root_y >= rootWin->getHeight() - 1) {
242 }
else if (e->root_y <= 10) {
248 rootWin->setCursorPosition(x, y);
251 return FXDial::onMotion(o, s, p);
270 long onKey(FXObject*, FXSelector,
void*);
281 FXuint opts = ARROW_NORMAL,
282 FXint x = 0, FXint y = 0, FXint w = 0, FXint h = 0,
283 FXint pl = DEFAULT_PAD, FXint pr = DEFAULT_PAD, FXint pt = DEFAULT_PAD, FXint pb = DEFAULT_PAD):
284 FXArrowButton(p, tgt, sel, opts, x, y, w, h, pl, pr, pt, pb) {}
298 FXIMPLEMENT(
FXRealSpinDialBtn, FXArrowButton, FXSpinDialBtnMap, ARRAYNUMBER(FXSpinDialBtnMap))
309 return target->handle(o, s, p);
315 return FXArrowButton::onLeftBtnPress(o, s, p);
319 return FXArrowButton::onLeftBtnRelease(o, s, p);
339 long onCmdSetRealValue(FXObject*, FXSelector,
void*);
340 long onMotion(FXObject*, FXSelector,
void*);
351 FXuint opts = TEXTFIELD_NORMAL,
352 FXint x = 0, FXint y = 0, FXint w = 0, FXint h = 0, FXint
353 pl = DEFAULT_PAD, FXint pr = DEFAULT_PAD, FXint pt = DEFAULT_PAD, FXint pb = DEFAULT_PAD
355 FXTextField(p, ncols, tgt, sel, opts, x, y, w, h, pl, pr, pt, pb),
363 flags &= ~FLAG_FMTSTRING;
373 flags |= FLAG_FMTSTRING;
390 FXIMPLEMENT(
FXRealSpinDialText, FXTextField, FXSpinDialTextMap, ARRAYNUMBER(FXSpinDialTextMap))
398 if (target && target->handle(
this, FXSEL(SEL_MOTION, message), ptr)) {
401 return FXTextField::onMotion(o, s, ptr);
405 if (flags & FLAG_FMTSTRING) {
406 setText(FXStringFormat(fmtString.text(), *((FXdouble*)ptr)));
408 setText(FXStringVal(*((FXdouble*)ptr), precision, exponent));
455 FXIMPLEMENT(
FXRealSpinDial, FXPacker, FXRealSpinDialMap, ARRAYNUMBER(FXRealSpinDialMap))
460 flags = (flags | FLAG_ENABLED | FLAG_SHOWN) & ~FLAG_UPDATE;
476 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):
477 FXPacker(p, opts & ~(FRAME_RIDGE), x, y, w, h, 0, 0, 0, 0, 0, 0) {
478 flags = (flags | FLAG_ENABLED | FLAG_SHOWN) & ~FLAG_UPDATE;
481 dial =
new FXRealSpinDialDial(
this,
this,
ID_DIAL, DIAL_VERTICAL, 0, 0, 0, 0, 0, 0, 0, 0);
482 dial->setNotchSpacing(450);
484 upButton =
new FXRealSpinDialBtn(
this,
this,
ID_INCREMENT, FRAME_RAISED | FRAME_THICK | ARROW_UP | ARROW_REPEAT, 0, 0, 0, 0, 0, 0, 0, 0);
485 downButton =
new FXRealSpinDialBtn(
this,
this,
ID_DECREMENT, FRAME_RAISED | FRAME_THICK | ARROW_DOWN | ARROW_REPEAT, 0, 0, 0, 0, 0, 0, 0, 0);
488 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);
514 return textField->getDefaultHeight() + (border << 1);
526 if (!(flags & FLAG_ENABLED)) {
536 if (flags & FLAG_ENABLED) {
546 FXint dialHeight, buttonHeight, textHeight;
548 textHeight = height - 2 * border;
549 dialHeight = textHeight;
550 buttonHeight = textHeight >> 1;
553 if ((options & hideOpts) == hideOpts) {
554 flags &= ~FLAG_DIRTY;
558 FXint right = width - border;
567 upButton->position(border, border, bw, buttonHeight);
568 downButton->position(border, height - buttonHeight - border, bw, buttonHeight);
571 dial->position(left, border, right - left, dialHeight);
573 upButton->position(border, border, right - border, buttonHeight);
574 downButton->position(border, height - buttonHeight - border, right - border, buttonHeight);
580 dial->position(right - w, border, w, dialHeight);
585 upButton->position(right - w, border, w, buttonHeight);
586 downButton->position(right - w, height - buttonHeight - border, w, buttonHeight);
589 textField->position(border, border, right - border, textHeight);
591 flags &= ~FLAG_DIRTY;
598 sender->handle(
this, FXSEL(SEL_COMMAND, ID_ENABLE), NULL);
600 sender->handle(
this, FXSEL(SEL_COMMAND, ID_DISABLE), NULL);
613 if (FXApp::instance()->getKeyState(CONTROLMASK)) {
615 }
else if (FXApp::instance()->getKeyState(SHIFTMASK)) {
628 if (options & SPINDIAL_LOG) {
630 FXdouble lr0 = log(
range[0]), lr1 = log(
range[1]), lnp = log(newpos);
631 newpos = exp(lr0 + fmod(lnp - lr0, lr1 - lr0));
639 if (options & SPINDIAL_LOG) {
641 FXdouble lr0 = log(
range[0]), lr1 = log(
range[1]), lpos = log(
pos);
642 FXdouble span = lr1 - lr0;
643 newpos = exp(lr0 + fmod(lpos - lr0 + 1 + (span - inc), span));
653 target->handle(
this, FXSEL(SEL_COMMAND, message), (
void*)&
pos);
673 if (isEnabled() && ((options & REALSPIN_CYCLIC) || (
pos <
range[1]))) {
674 sender->handle(
this, FXSEL(SEL_COMMAND, ID_ENABLE), NULL);
676 sender->handle(
this, FXSEL(SEL_COMMAND, ID_DISABLE), NULL);
697 target->handle(
this, FXSEL(SEL_COMMAND, message), (
void*)&
pos);
705 if (isEnabled() && ((options & REALSPIN_CYCLIC) || (
range[0] <
pos))) {
706 sender->handle(
this, FXSEL(SEL_COMMAND, ID_ENABLE), NULL);
708 sender->handle(
this, FXSEL(SEL_COMMAND, ID_DISABLE), NULL);
729 target->handle(
this, FXSEL(SEL_COMMAND, message), (
void*)&
pos);
738 return target && target->handle(
this, FXSEL(SEL_UPDATE, message), NULL);
751 if (((FXEvent*)p)->code > 0) {
757 target->handle(
this, FXSEL(SEL_COMMAND, message), (
void*)&
pos);
764 register FXdouble value = FXDoubleVal(
textField->getText());
765 if (value <
range[0]) {
768 if (value >
range[1]) {
774 target->handle(
this, FXSEL(SEL_CHANGED, message), (
void*)&
pos);
785 target->handle(
this, FXSEL(SEL_COMMAND, message), (
void*)&
pos);
793 FXEvent*
event = (FXEvent*)ptr;
798 if (target && target->handle(
this, FXSEL(SEL_KEYPRESS, message), ptr)) {
809 switch (event->code) {
814 target->handle(
this, FXSEL(SEL_COMMAND, message), (
void*)&
pos);
821 target->handle(
this, FXSEL(SEL_COMMAND, message), (
void*)&
pos);
825 return textField->handle(sender, sel, ptr);
832 FXEvent*
event = (FXEvent*)ptr;
837 if (target && target->handle(
this, FXSEL(SEL_KEYRELEASE, message), ptr)) {
840 switch (event->code) {
847 return textField->handle(sender, sel, ptr);
883 FXdouble lo = (FXdouble)((FXint*)ptr)[0];
884 FXdouble hi = (FXdouble)((FXint*)ptr)[1];
892 ((FXdouble*)ptr)[0] =
range[0];
893 ((FXdouble*)ptr)[1] =
range[1];
914 setRange(((FXdouble*)ptr)[0], ((FXdouble*)ptr)[1]);
921 getRange(((FXdouble*)ptr)[0], ((FXdouble*)ptr)[1]);
929 FXdouble inc =
incr[incMode + 1];
936 FXdouble lr0 = log(
range[0]), lr1 = log(
range[1]), lnp = log(newpos);
937 newpos = exp(lr0 + fmod(lnp - lr0, lr1 - lr0));
952 FXdouble inc =
incr[incMode + 1];
959 FXdouble lr0 = log(
range[0]), lr1 = log(
range[1]), lpos = log(
pos);
960 FXdouble span = lr1 - lr0;
961 newpos = exp(lr0 + fmod(lpos - lr0 + 1 + (span - inc), span));
992 fxerror(
"%s::setRange: trying to set negative range.\n", getClassName());
1004 if (value <
range[0]) {
1007 if (value >
range[1]) {
1011 textField->handle(
this, FXSEL(SEL_COMMAND, ID_SETREALVALUE), &value);
1020 fxerror(
"%s::setIncrement: negative or zero increment specified.\n", getClassName());
1026 fxerror(
"%s::setIncrement: negative or zero increment specified.\n", getClassName());
1032 fxerror(
"%s::setIncrement: negative or zero increment specified.\n", getClassName());
1038 fxerror(
"%s::setIncrement: negative or zero increment specified.\n", getClassName());
1055 if (options != opts) {
1077 dial->setHelpText(text);
1092 dial->setTipText(text);
1108 if (options != opts) {
1110 range[0] = -DBL_MAX;
1140 dial->setBackColor(clr);
1145 return dial->getBackColor();
1231 FXPacker::save(store);
1244 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.
void selectAll()
Mark the text entry as selected.
void setFineIncrement(FXdouble increment)
Change spinner fine adjustment increment (when CTRL key held down)
long onKey(FXObject *, FXSelector, void *)
FXbool isTextVisible() const
Return TRUE if text is visible.
FXColor getTextColor() const
Return text color.
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.
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.
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.
long onCmdSetValue(FXObject *, FXSelector, void *)
virtual void create()
Create server-side resources.
long onCmdSetRealRange(FXObject *, FXSelector, void *)
long onKeyPress(FXObject *, FXSelector, void *)
const FXDial & getDial() const
FXColor getUpArrowColor() const
Return color of the up arrow.
virtual void disable()
Disable spinner.
long onRightButtonRelease(FXObject *, FXSelector, void *)
FXRealSpinDialDial & operator=(const FXRealSpinDialDial &)
FXbool isEditable() const
Return TRUE if text field is editable.
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.
FXbool getNumberFormatExponent() const
void setSelBackColor(FXColor clr)
Change selected background color.
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 *)
FXdouble getValue() const
Return current value.
long onButtonPress(FXObject *, FXSelector, void *)
virtual void save(FXStream &store) const
Save spinner to a stream.
FXint getNumberFormatPrecision() const
long onUpdDial(FXObject *, FXSelector, void *)
FXString getNumberFormatString() const
Return the format string for number display.
void setFormatString(const FXchar *fmt)
FXString getTipText() const
Get the tool tip message for this spinner.
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.
FXColor getSelTextColor() const
Return selected text color.
long onKeyRelease(FXObject *, FXSelector, void *)
long onUpdDecrement(FXObject *, FXSelector, void *)
long onCmdDial(FXObject *, FXSelector, void *)
void setFormatString(const FXchar *fmt)
FXColor getCursorColor() const
Return the cursor color.
void getRange(FXdouble &lo, FXdouble &hi) const
Get the spinner's current range.
long onCmdGetRealValue(FXObject *, FXSelector, void *)
FXString getNumberFormatString() const
FXColor getDownArrowColor() const
Return color of the the down arrow.
void setTextVisible(FXbool shown)
Set text visible flag.
void setNumberFormat(FXint prec, FXbool bExp=FALSE)
long onKey(FXObject *, FXSelector, void *)
long onCmdIncrement(FXObject *, FXSelector, void *)
FXColor getDialColor() const
Return color of the dial.
long onMotion(FXObject *, FXSelector, void *)
void increment(FXint incMode=SPINDIAL_INC_NORMAL)
Increment spinner.
FXint getNumberFormatPrecision() const
Return the digits of precision used to display numbers.
long onChgEntry(FXObject *, FXSelector, void *)
FXuint getSpinnerStyle() const
Return current spinner style.
long onCmdSetRealValue(FXObject *, FXSelector, void *)
FXbool getNumberFormatExponent() const
Return whether the exponent is used in number display.
void setHelpText(const FXString &text)
Set the status line help text for this spinner.
FXbool isCyclic() const
Return TRUE if in cyclic mode.
FXString getHelpText() const
Get 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 *)
FXFont * getFont() const
Get the text font.
void setSelTextColor(FXColor clr)
Change selected text color.
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 *)
long onChgDial(FXObject *, FXSelector, void *)