llradiogroup.h

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

Generated on Thu Jul 1 06:09:04 2010 for Second Life Viewer by  doxygen 1.4.7