00001
00032 #ifndef LL_LLSPINCTRL_H
00033 #define LL_LLSPINCTRL_H
00034
00035
00036 #include "stdtypes.h"
00037 #include "lluictrl.h"
00038 #include "v4color.h"
00039 #include "llrect.h"
00040
00041
00042
00043
00044 const S32 SPINCTRL_BTN_HEIGHT = 8;
00045 const S32 SPINCTRL_BTN_WIDTH = 16;
00046 const S32 SPINCTRL_SPACING = 2;
00047 const S32 SPINCTRL_HEIGHT = 2 * SPINCTRL_BTN_HEIGHT;
00048 const S32 SPINCTRL_DEFAULT_LABEL_WIDTH = 10;
00049
00050
00051
00052
00053 class LLFontGL;
00054 class LLButton;
00055 class LLTextBox;
00056 class LLLineEditor;
00057 class LLUICtrlFactory;
00058
00059
00060 class LLSpinCtrl
00061 : public LLUICtrl
00062 {
00063 public:
00064 LLSpinCtrl(const LLString& name, const LLRect& rect,
00065 const LLString& label,
00066 const LLFontGL* font,
00067 void (*commit_callback)(LLUICtrl*, void*),
00068 void* callback_userdata,
00069 F32 initial_value, F32 min_value, F32 max_value, F32 increment,
00070 const LLString& control_name = LLString(),
00071 S32 label_width = SPINCTRL_DEFAULT_LABEL_WIDTH );
00072
00073 virtual ~LLSpinCtrl();
00074 virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_SPINNER; }
00075 virtual LLString getWidgetTag() const { return LL_SPIN_CTRL_TAG; }
00076 virtual LLXMLNodePtr getXML(bool save_children = true) const;
00077 static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory);
00078
00079 virtual void setValue(const LLSD& value );
00080 virtual LLSD getValue() const;
00081 F32 get() { return (F32)getValue().asReal(); }
00082 void set(F32 value) { setValue(value); mInitialValue = value; }
00083
00084 virtual void setMinValue(LLSD min_value) { setMinValue((F32)min_value.asReal()); }
00085 virtual void setMaxValue(LLSD max_value) { setMaxValue((F32)max_value.asReal()); }
00086
00087 BOOL isMouseHeldDown();
00088
00089 virtual void setEnabled( BOOL b );
00090 virtual void setFocus( BOOL b );
00091 virtual void clear();
00092 virtual BOOL isDirty() const;
00093
00094 virtual void setPrecision(S32 precision);
00095 virtual void setMinValue(F32 min) { mMinValue = min; }
00096 virtual void setMaxValue(F32 max) { mMaxValue = max; }
00097 virtual void setIncrement(F32 inc) { mIncrement = inc; }
00098
00099 void setLabel(const LLStringExplicit& label);
00100 void setLabelColor(const LLColor4& c) { mTextEnabledColor = c; }
00101 void setDisabledLabelColor(const LLColor4& c) { mTextDisabledColor = c; }
00102
00103 virtual void onTabInto();
00104
00105 virtual void setTentative(BOOL b);
00106 virtual void onCommit();
00107
00108 void forceEditorCommit();
00109
00110 virtual BOOL handleScrollWheel(S32 x,S32 y,S32 clicks);
00111 virtual BOOL handleKeyHere(KEY key, MASK mask, BOOL called_from_parent);
00112
00113 virtual void draw();
00114
00115 static void onEditorCommit(LLUICtrl* caller, void* userdata);
00116 static void onEditorGainFocus(LLUICtrl* caller, void *userdata);
00117 static void onEditorChangeFocus(LLUICtrl* caller, S32 direction, void *userdata);
00118
00119 static void onUpBtn(void *userdata);
00120 static void onDownBtn(void *userdata);
00121
00122 protected:
00123 void updateEditor();
00124 void reportInvalidData();
00125
00126 protected:
00127
00128 F32 mValue;
00129 F32 mInitialValue;
00130 F32 mMaxValue;
00131 F32 mMinValue;
00132 F32 mIncrement;
00133
00134 S32 mPrecision;
00135 LLTextBox* mLabelBox;
00136
00137 LLLineEditor* mEditor;
00138 LLColor4 mTextEnabledColor;
00139 LLColor4 mTextDisabledColor;
00140
00141 LLButton* mUpBtn;
00142 LLButton* mDownBtn;
00143
00144 BOOL mbHasBeenSet;
00145 };
00146
00147 #endif // LL_LLSPINCTRL_H