llcombobox.h

Go to the documentation of this file.
00001 
00032 // A control that displays the name of the chosen item, which when clicked
00033 // shows a scrolling box of choices.
00034 
00035 #ifndef LL_LLCOMBOBOX_H
00036 #define LL_LLCOMBOBOX_H
00037 
00038 #include "llbutton.h"
00039 #include "lluictrl.h"
00040 #include "llctrlselectioninterface.h"
00041 #include "llimagegl.h"
00042 #include "llrect.h"
00043 
00044 // Classes
00045 
00046 class LLFontGL;
00047 class LLButton;
00048 class LLSquareButton;
00049 class LLScrollListCtrl;
00050 class LLLineEditor;
00051 class LLViewBorder;
00052 
00053 extern S32 LLCOMBOBOX_HEIGHT;
00054 extern S32 LLCOMBOBOX_WIDTH;
00055 
00056 class LLComboBox
00057 :       public LLUICtrl, public LLCtrlListInterface
00058 {
00059 public:
00060         typedef enum e_preferred_position
00061         {
00062                 ABOVE,
00063                 BELOW
00064         } EPreferredPosition;
00065 
00066         LLComboBox(
00067                 const LLString& name, 
00068                 const LLRect &rect,
00069                 const LLString& label,
00070                 void (*commit_callback)(LLUICtrl*, void*) = NULL,
00071                 void *callback_userdata = NULL
00072                 );
00073         virtual ~LLComboBox(); 
00074 
00075         // LLView interface
00076         virtual EWidgetType getWidgetType() const { return WIDGET_TYPE_COMBO_BOX; }
00077         virtual LLString getWidgetTag() const { return LL_COMBO_BOX_TAG; }
00078         virtual LLXMLNodePtr getXML(bool save_children = true) const;
00079         static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory);
00080 
00081         virtual void    draw();
00082         virtual void    onFocusLost();
00083 
00084         virtual void    setEnabled(BOOL enabled);
00085 
00086         virtual BOOL    handleToolTip(S32 x, S32 y, LLString& msg, LLRect* sticky_rect);
00087         virtual BOOL    handleKeyHere(KEY key, MASK mask, BOOL called_from_parent);
00088         virtual BOOL    handleUnicodeCharHere(llwchar uni_char, BOOL called_from_parent);
00089 
00090         // LLUICtrl interface
00091         virtual void    clear();                                        // select nothing
00092         virtual void    onCommit();
00093         virtual BOOL    acceptsTextInput() const                { return mAllowTextEntry; }
00094         virtual BOOL    isDirty() const;                        // Returns TRUE if the user has modified this control.
00095         virtual void    resetDirty();                           // Clear dirty state
00096 
00097         virtual void    setFocus(BOOL b);
00098 
00099         // Selects item by underlying LLSD value, using LLSD::asString() matching.  
00100         // For simple items, this is just the name of the label.
00101         virtual void    setValue(const LLSD& value );
00102 
00103         // Gets underlying LLSD value for currently selected items.  For simple
00104         // items, this is just the label.
00105         virtual LLSD    getValue() const;
00106 
00107         void                    setAllowTextEntry(BOOL allow, S32 max_chars = 50, BOOL make_tentative = TRUE);
00108         void                    setTextEntry(const LLStringExplicit& text);
00109 
00110         void                    add(const LLString& name, EAddPosition pos = ADD_BOTTOM, BOOL enabled = TRUE);  // add item "name" to menu
00111         void                    add(const LLString& name, const LLUUID& id, EAddPosition pos = ADD_BOTTOM, BOOL enabled = TRUE);
00112         void                    add(const LLString& name, void* userdata, EAddPosition pos = ADD_BOTTOM, BOOL enabled = TRUE);
00113         void                    add(const LLString& name, LLSD value, EAddPosition pos = ADD_BOTTOM, BOOL enabled = TRUE);
00114         BOOL                    remove( S32 index );    // remove item by index, return TRUE if found and removed
00115         void                    removeall() { clearRows(); }
00116 
00117         void                    sortByName(); // Sort the entries in the combobox by name
00118 
00119         // Select current item by name using selectSimpleItem.  Returns FALSE if not found.
00120         BOOL                    setSimple(const LLStringExplicit& name);
00121         // Get name of current item. Returns an empty string if not found.
00122         const LLString& getSimple() const;
00123         // Get contents of column x of selected row
00124         const LLString& getSimpleSelectedItem(S32 column = 0) const;
00125 
00126         // Sets the label, which doesn't have to exist in the label.
00127         // This is probably a UI abuse.
00128         void                    setLabel(const LLStringExplicit& name);
00129 
00130         BOOL                    remove(const LLString& name);   // remove item "name", return TRUE if found and removed
00131         
00132         BOOL                    setCurrentByIndex( S32 index );
00133         S32                             getCurrentIndex() const;
00134 
00135         //========================================================================
00136         LLCtrlSelectionInterface* getSelectionInterface()       { return (LLCtrlSelectionInterface*)this; };
00137         LLCtrlListInterface* getListInterface()                         { return (LLCtrlListInterface*)this; };
00138 
00139         // LLCtrlListInterface functions
00140         // See llscrolllistctrl.h
00141         virtual S32             getItemCount() const;
00142         // Overwrites the default column (See LLScrollListCtrl for format)
00143         virtual void    addColumn(const LLSD& column, EAddPosition pos = ADD_BOTTOM);
00144         virtual void    clearColumns();
00145         virtual void    setColumnLabel(const LLString& column, const LLString& label);
00146         virtual LLScrollListItem* addElement(const LLSD& value, EAddPosition pos = ADD_BOTTOM, void* userdata = NULL);
00147         virtual LLScrollListItem* addSimpleElement(const LLString& value, EAddPosition pos = ADD_BOTTOM, const LLSD& id = LLSD());
00148         virtual void    clearRows();
00149         virtual void    sortByColumn(LLString name, BOOL ascending);
00150 
00151         // LLCtrlSelectionInterface functions
00152         virtual BOOL    getCanSelect() const                            { return TRUE; }
00153         virtual BOOL    selectFirstItem()                                       { return setCurrentByIndex(0); }
00154         virtual BOOL    selectNthItem( S32 index )                      { return setCurrentByIndex(index); }
00155         virtual S32             getFirstSelectedIndex() const           { return getCurrentIndex(); }
00156         virtual BOOL    setCurrentByID( const LLUUID& id );
00157         virtual LLUUID  getCurrentID();                         // LLUUID::null if no items in menu
00158         virtual BOOL    setSelectedByValue(LLSD value, BOOL selected);
00159         virtual LLSD    getSimpleSelectedValue();
00160         virtual BOOL    isSelected(LLSD value);
00161         virtual BOOL    operateOnSelection(EOperation op);
00162         virtual BOOL    operateOnAll(EOperation op);
00163 
00164         //========================================================================
00165         
00166         void*                   getCurrentUserdata();
00167 
00168         void                    setPrearrangeCallback( void (*cb)(LLUICtrl*,void*) ) { mPrearrangeCallback = cb; }
00169         void                    setTextEntryCallback( void (*cb)(LLLineEditor*, void*) ) { mTextEntryCallback = cb; }
00170 
00171         void                    setButtonVisible(BOOL visible);
00172 
00173         static void             onButtonDown(void *userdata);
00174         static void             onItemSelected(LLUICtrl* item, void *userdata);
00175         static void             onListFocusChanged(LLUICtrl* item, void *userdata);
00176         static void             onTextEntry(LLLineEditor* line_editor, void* user_data);
00177         static void             onTextCommit(LLUICtrl* caller, void* user_data);
00178 
00179         void                    updateSelection();
00180         virtual void    showList();
00181         virtual void    hideList();
00182         
00183 protected:
00184         LLButton*                       mButton;
00185         LLScrollListCtrl*       mList;
00186         LLViewBorder*           mBorder;
00187         BOOL                            mKeyboardFocusOnClick;
00188         BOOL                            mDrawArrow;
00189         LLLineEditor*           mTextEntry;
00190         LLPointer<LLImageGL>    mArrowImage;
00191         S32                                     mArrowImageWidth;
00192         BOOL                            mAllowTextEntry;
00193         S32                                     mMaxChars;
00194         BOOL                            mTextEntryTentative;
00195         EPreferredPosition      mListPosition;
00196         void                            (*mPrearrangeCallback)(LLUICtrl*,void*);
00197         void                            (*mTextEntryCallback)(LLLineEditor*, void*);
00198 };
00199 
00200 #endif

Generated on Thu Jul 1 06:08:22 2010 for Second Life Viewer by  doxygen 1.4.7