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 class LLSpinCtrl
00052 : public LLUICtrl
00053 {
00054 public:
00055 LLSpinCtrl(const LLString& name, const LLRect& rect,
00056 const LLString& label,
00057 const LLFontGL* font,
00058 void (*commit_callback)(LLUICtrl*, void*),
00059 void* callback_userdata,
00060 F32 initial_value, F32 min_value, F32 max_value, F32 increment,
00061 const LLString& control_name = LLString(),
00062 S32 label_width = SPINCTRL_DEFAULT_LABEL_WIDTH );
00063
00064 virtual ~LLSpinCtrl() {}
00065
00066 virtual LLXMLNodePtr getXML(bool save_children = true) const;
00067 static LLView* fromXML(LLXMLNodePtr node, LLView *parent, class LLUICtrlFactory *factory);
00068
00069 virtual void forceSetValue(const LLSD& value ) ;
00070 virtual void setValue(const LLSD& value );
00071 virtual LLSD getValue() const { return mValue; }
00072 F32 get() const { return (F32)getValue().asReal(); }
00073 void set(F32 value) { setValue(value); mInitialValue = value; }
00074
00075 virtual void setMinValue(LLSD min_value) { setMinValue((F32)min_value.asReal()); }
00076 virtual void setMaxValue(LLSD max_value) { setMaxValue((F32)max_value.asReal()); }
00077
00078 BOOL isMouseHeldDown() const;
00079
00080 virtual void setEnabled( BOOL b );
00081 virtual void setFocus( BOOL b );
00082 virtual void clear();
00083 virtual BOOL isDirty() const { return( mValue != mInitialValue ); }
00084
00085 virtual void setPrecision(S32 precision);
00086 virtual void setMinValue(F32 min) { mMinValue = min; }
00087 virtual void setMaxValue(F32 max) { mMaxValue = max; }
00088 virtual void setIncrement(F32 inc) { mIncrement = inc; }
00089 virtual F32 getMinValue() { return mMinValue ; }
00090 virtual F32 getMaxValue() { return mMaxValue ; }
00091 virtual F32 getIncrement() { return mIncrement ; }
00092
00093 void setLabel(const LLStringExplicit& label);
00094 void setLabelColor(const LLColor4& c) { mTextEnabledColor = c; }
00095 void setDisabledLabelColor(const LLColor4& c) { mTextDisabledColor = c; }
00096
00097 virtual void onTabInto();
00098
00099 virtual void setTentative(BOOL b);
00100 virtual void onCommit();
00101
00102 void forceEditorCommit();
00103
00104 virtual BOOL handleScrollWheel(S32 x,S32 y,S32 clicks);
00105 virtual BOOL handleKeyHere(KEY key, MASK mask);
00106
00107 virtual void draw();
00108
00109 static void onEditorCommit(LLUICtrl* caller, void* userdata);
00110 static void onEditorGainFocus(LLFocusableElement* caller, void *userdata);
00111 static void onEditorChangeFocus(LLUICtrl* caller, S32 direction, void *userdata);
00112
00113 static void onUpBtn(void *userdata);
00114 static void onDownBtn(void *userdata);
00115
00116 private:
00117 void updateEditor();
00118 void reportInvalidData();
00119
00120 F32 mValue;
00121 F32 mInitialValue;
00122 F32 mMaxValue;
00123 F32 mMinValue;
00124 F32 mIncrement;
00125
00126 S32 mPrecision;
00127 class LLTextBox* mLabelBox;
00128
00129 class LLLineEditor* mEditor;
00130 LLColor4 mTextEnabledColor;
00131 LLColor4 mTextDisabledColor;
00132
00133 class LLButton* mUpBtn;
00134 class LLButton* mDownBtn;
00135
00136 BOOL mbHasBeenSet;
00137 };
00138
00139 #endif // LL_LLSPINCTRL_H