llradiogroup.h

Go to the documentation of this file.
00001 
00032 #ifndef LL_LLRADIOGROUP_H
00033 #define LL_LLRADIOGROUP_H
00034 
00035 #include "lluictrl.h"
00036 #include "llcheckboxctrl.h"
00037 #include "llctrlselectioninterface.h"
00038 
00039 
00040 /*
00041  * A checkbox control with use_radio_style == true.
00042  */
00043 class LLRadioCtrl : public LLCheckBoxCtrl 
00044 {
00045 public:
00046         LLRadioCtrl(const LLString& name, const LLRect& rect, const LLString& label, const LLFontGL* font = NULL,
00047                 void (*commit_callback)(LLUICtrl*, void*) = NULL, void* callback_userdata = NULL) :
00048                                 LLCheckBoxCtrl(name, rect, label, font, commit_callback, callback_userdata, FALSE, RADIO_STYLE)
00049         {
00050                 setTabStop(FALSE);
00051         }
00052         /*virtual*/ ~LLRadioCtrl();
00053 
00054         /*virtual*/ void setValue(const LLSD& value);
00055 };
00056 
00057 
00058 /*
00059  * An invisible view containing multiple mutually exclusive toggling 
00060  * buttons (usually radio buttons).  Automatically handles the mutex
00061  * condition by highlighting only one button at a time.
00062  */
00063 class LLRadioGroup
00064 :       public LLUICtrl, public LLCtrlSelectionInterface
00065 {
00066 public:
00067         // Build a radio group.  The number (0...n-1) of the currently selected
00068         // element will be stored in the named control.  After the control is
00069         // changed the callback will be called.
00070         LLRadioGroup(const LLString& name, const LLRect& rect, 
00071                 const LLString& control_name, 
00072                 LLUICtrlCallback callback = NULL,
00073                 void* userdata = NULL,
00074                 BOOL border = TRUE);
00075 
00076         // Another radio group constructor, but this one doesn't rely on
00077         // needing a control
00078         LLRadioGroup(const LLString& name, const LLRect& rect,
00079                                  S32 initial_index,
00080                                  LLUICtrlCallback callback = NULL,
00081                                  void* userdata = NULL,
00082                                  BOOL border = TRUE);
00083 
00084         virtual ~LLRadioGroup();
00085 
00086         virtual BOOL handleKeyHere(KEY key, MASK mask);
00087 
00088         virtual void setEnabled(BOOL enabled);
00089         virtual LLXMLNodePtr getXML(bool save_children = true) const;
00090         static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory);
00091         void setIndexEnabled(S32 index, BOOL enabled);
00092         
00093         // return the index value of the selected item
00094         S32 getSelectedIndex() const { return mSelectedIndex; }
00095         
00096         // set the index value programatically
00097         BOOL setSelectedIndex(S32 index, BOOL from_event = FALSE);
00098 
00099         // Accept and retrieve strings of the radio group control names
00100         virtual void    setValue(const LLSD& value );
00101         virtual LLSD    getValue() const;
00102 
00103         // Draw the group, but also fix the highlighting based on the control.
00104         void draw();
00105 
00106         // You must use this method to add buttons to a radio group.
00107         // Don't use addChild -- it won't set the callback function
00108         // correctly.
00109         LLRadioCtrl* addRadioButton(const LLString& name, const LLString& label, const LLRect& rect, const LLFontGL* font);
00110         LLRadioCtrl* getRadioButton(const S32& index) { return mRadioButtons[index]; }
00111         // Update the control as needed.  Userdata must be a pointer to the button.
00112         static void onClickButton(LLUICtrl* radio, void* userdata);
00113         
00114         //========================================================================
00115         LLCtrlSelectionInterface* getSelectionInterface()       { return (LLCtrlSelectionInterface*)this; };
00116 
00117         // LLCtrlSelectionInterface functions
00118         /*virtual*/ S32         getItemCount() const                            { return mRadioButtons.size(); }
00119         /*virtual*/ BOOL        getCanSelect() const                            { return TRUE; }
00120         /*virtual*/ BOOL        selectFirstItem()                                       { return setSelectedIndex(0); }
00121         /*virtual*/ BOOL        selectNthItem( S32 index )                      { return setSelectedIndex(index); }
00122         /*virtual*/ BOOL        selectItemRange( S32 first, S32 last ) { return setSelectedIndex(first); }
00123         /*virtual*/ S32         getFirstSelectedIndex() const           { return getSelectedIndex(); }
00124         /*virtual*/ BOOL        setCurrentByID( const LLUUID& id );
00125         /*virtual*/ LLUUID      getCurrentID() const;                           // LLUUID::null if no items in menu
00126         /*virtual*/ BOOL        setSelectedByValue(const LLSD& value, BOOL selected);
00127         /*virtual*/ LLSD        getSelectedValue();
00128         /*virtual*/ BOOL        isSelected(const LLSD& value) const;
00129         /*virtual*/ BOOL        operateOnSelection(EOperation op);
00130         /*virtual*/ BOOL        operateOnAll(EOperation op);
00131 
00132 private:
00133         // protected function shared by the two constructors.
00134         void init(BOOL border);
00135 
00136         S32 mSelectedIndex;
00137         typedef std::vector<LLRadioCtrl*> button_list_t;
00138         button_list_t mRadioButtons;
00139 
00140         BOOL mHasBorder;
00141 };
00142 
00143 
00144 #endif

Generated on Fri May 16 08:32:56 2008 for SecondLife by  doxygen 1.5.5