PageRenderTime 189ms CodeModel.GetById 44ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llui/llcombobox.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 265 lines | 166 code | 51 blank | 48 comment | 0 complexity | 4e48e703e4789abfea31b535c01cda26 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llcombobox.h
  3. * @brief LLComboBox base class
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. // A control that displays the name of the chosen item, which when clicked
  27. // shows a scrolling box of choices.
  28. #ifndef LL_LLCOMBOBOX_H
  29. #define LL_LLCOMBOBOX_H
  30. #include "llbutton.h"
  31. #include "lluictrl.h"
  32. #include "llctrlselectioninterface.h"
  33. #include "llrect.h"
  34. #include "llscrolllistctrl.h"
  35. #include "lllineeditor.h"
  36. #include <boost/function.hpp>
  37. // Classes
  38. class LLFontGL;
  39. class LLViewBorder;
  40. class LLComboBox
  41. : public LLUICtrl, public LLCtrlListInterface
  42. {
  43. public:
  44. typedef enum e_preferred_position
  45. {
  46. ABOVE,
  47. BELOW
  48. } EPreferredPosition;
  49. struct PreferredPositionValues : public LLInitParam::TypeValuesHelper<EPreferredPosition, PreferredPositionValues>
  50. {
  51. static void declareValues();
  52. };
  53. struct ItemParams : public LLInitParam::Block<ItemParams, LLScrollListItem::Params>
  54. {
  55. Optional<std::string> label;
  56. ItemParams();
  57. };
  58. struct Params
  59. : public LLInitParam::Block<Params, LLUICtrl::Params>
  60. {
  61. Optional<bool> allow_text_entry,
  62. show_text_as_tentative,
  63. allow_new_values;
  64. Optional<S32> max_chars;
  65. Optional<commit_callback_t> prearrange_callback,
  66. text_entry_callback,
  67. text_changed_callback;
  68. Optional<EPreferredPosition, PreferredPositionValues> list_position;
  69. // components
  70. Optional<LLButton::Params> combo_button;
  71. Optional<LLScrollListCtrl::Params> combo_list;
  72. Optional<LLLineEditor::Params> combo_editor;
  73. Optional<LLButton::Params> drop_down_button;
  74. Multiple<ItemParams> items;
  75. Params();
  76. };
  77. virtual ~LLComboBox();
  78. /*virtual*/ BOOL postBuild();
  79. protected:
  80. friend class LLUICtrlFactory;
  81. LLComboBox(const Params&);
  82. void initFromParams(const Params&);
  83. void prearrangeList(std::string filter = "");
  84. public:
  85. // LLView interface
  86. virtual void onFocusLost();
  87. virtual BOOL handleToolTip(S32 x, S32 y, MASK mask);
  88. virtual BOOL handleKeyHere(KEY key, MASK mask);
  89. virtual BOOL handleUnicodeCharHere(llwchar uni_char);
  90. // LLUICtrl interface
  91. virtual void clear(); // select nothing
  92. virtual void onCommit();
  93. virtual BOOL acceptsTextInput() const { return mAllowTextEntry; }
  94. virtual BOOL isDirty() const; // Returns TRUE if the user has modified this control.
  95. virtual void resetDirty(); // Clear dirty state
  96. virtual void setFocus(BOOL b);
  97. // Selects item by underlying LLSD value, using LLSD::asString() matching.
  98. // For simple items, this is just the name of the label.
  99. virtual void setValue(const LLSD& value );
  100. // Gets underlying LLSD value for currently selected items. For simple
  101. // items, this is just the label.
  102. virtual LLSD getValue() const;
  103. void setTextEntry(const LLStringExplicit& text);
  104. LLScrollListItem* add(const std::string& name, EAddPosition pos = ADD_BOTTOM, BOOL enabled = TRUE); // add item "name" to menu
  105. LLScrollListItem* add(const std::string& name, const LLUUID& id, EAddPosition pos = ADD_BOTTOM, BOOL enabled = TRUE);
  106. LLScrollListItem* add(const std::string& name, void* userdata, EAddPosition pos = ADD_BOTTOM, BOOL enabled = TRUE);
  107. LLScrollListItem* add(const std::string& name, LLSD value, EAddPosition pos = ADD_BOTTOM, BOOL enabled = TRUE);
  108. LLScrollListItem* addSeparator(EAddPosition pos = ADD_BOTTOM);
  109. BOOL remove( S32 index ); // remove item by index, return TRUE if found and removed
  110. void removeall() { clearRows(); }
  111. bool itemExists(const std::string& name);
  112. void sortByName(BOOL ascending = TRUE); // Sort the entries in the combobox by name
  113. // Select current item by name using selectItemByLabel. Returns FALSE if not found.
  114. BOOL setSimple(const LLStringExplicit& name);
  115. // Get name of current item. Returns an empty string if not found.
  116. const std::string getSimple() const;
  117. // Get contents of column x of selected row
  118. virtual const std::string getSelectedItemLabel(S32 column = 0) const;
  119. // Sets the label, which doesn't have to exist in the label.
  120. // This is probably a UI abuse.
  121. void setLabel(const LLStringExplicit& name);
  122. // Updates the combobox label to match the selected list item.
  123. void updateLabel();
  124. BOOL remove(const std::string& name); // remove item "name", return TRUE if found and removed
  125. BOOL setCurrentByIndex( S32 index );
  126. S32 getCurrentIndex() const;
  127. void createLineEditor(const Params&);
  128. //========================================================================
  129. LLCtrlSelectionInterface* getSelectionInterface() { return (LLCtrlSelectionInterface*)this; };
  130. LLCtrlListInterface* getListInterface() { return (LLCtrlListInterface*)this; };
  131. // LLCtrlListInterface functions
  132. // See llscrolllistctrl.h
  133. virtual S32 getItemCount() const;
  134. // Overwrites the default column (See LLScrollListCtrl for format)
  135. virtual void addColumn(const LLSD& column, EAddPosition pos = ADD_BOTTOM);
  136. virtual void clearColumns();
  137. virtual void setColumnLabel(const std::string& column, const std::string& label);
  138. virtual LLScrollListItem* addElement(const LLSD& value, EAddPosition pos = ADD_BOTTOM, void* userdata = NULL);
  139. virtual LLScrollListItem* addSimpleElement(const std::string& value, EAddPosition pos = ADD_BOTTOM, const LLSD& id = LLSD());
  140. virtual void clearRows();
  141. virtual void sortByColumn(const std::string& name, BOOL ascending);
  142. // LLCtrlSelectionInterface functions
  143. virtual BOOL getCanSelect() const { return TRUE; }
  144. virtual BOOL selectFirstItem() { return setCurrentByIndex(0); }
  145. virtual BOOL selectNthItem( S32 index ) { return setCurrentByIndex(index); }
  146. virtual BOOL selectItemRange( S32 first, S32 last );
  147. virtual S32 getFirstSelectedIndex() const { return getCurrentIndex(); }
  148. virtual BOOL setCurrentByID( const LLUUID& id );
  149. virtual LLUUID getCurrentID() const; // LLUUID::null if no items in menu
  150. virtual BOOL setSelectedByValue(const LLSD& value, BOOL selected);
  151. virtual LLSD getSelectedValue();
  152. virtual BOOL isSelected(const LLSD& value) const;
  153. virtual BOOL operateOnSelection(EOperation op);
  154. virtual BOOL operateOnAll(EOperation op);
  155. //========================================================================
  156. void* getCurrentUserdata();
  157. void setPrearrangeCallback( commit_callback_t cb ) { mPrearrangeCallback = cb; }
  158. void setTextEntryCallback( commit_callback_t cb ) { mTextEntryCallback = cb; }
  159. void setTextChangedCallback( commit_callback_t cb ) { mTextChangedCallback = cb; }
  160. void setButtonVisible(BOOL visible);
  161. void onButtonMouseDown();
  162. void onListMouseUp();
  163. void onItemSelected(const LLSD& data);
  164. void onTextCommit(const LLSD& data);
  165. void updateSelection();
  166. virtual void showList();
  167. virtual void hideList();
  168. virtual void onTextEntry(LLLineEditor* line_editor);
  169. protected:
  170. LLButton* mButton;
  171. LLLineEditor* mTextEntry;
  172. LLScrollListCtrl* mList;
  173. EPreferredPosition mListPosition;
  174. LLPointer<LLUIImage> mArrowImage;
  175. LLUIString mLabel;
  176. BOOL mHasAutocompletedText;
  177. private:
  178. BOOL mAllowTextEntry;
  179. BOOL mAllowNewValues;
  180. S32 mMaxChars;
  181. BOOL mTextEntryTentative;
  182. commit_callback_t mPrearrangeCallback;
  183. commit_callback_t mTextEntryCallback;
  184. commit_callback_t mTextChangedCallback;
  185. commit_callback_t mSelectionCallback;
  186. boost::signals2::connection mTopLostSignalConnection;
  187. S32 mLastSelectedIndex;
  188. };
  189. // A combo box with icons for the list of items.
  190. class LLIconsComboBox
  191. : public LLComboBox
  192. {
  193. public:
  194. struct Params
  195. : public LLInitParam::Block<Params, LLComboBox::Params>
  196. {
  197. Optional<S32> icon_column,
  198. label_column;
  199. Params();
  200. };
  201. /*virtual*/ const std::string getSelectedItemLabel(S32 column = 0) const;
  202. private:
  203. enum EColumnIndex
  204. {
  205. ICON_COLUMN = 0,
  206. LABEL_COLUMN
  207. };
  208. friend class LLUICtrlFactory;
  209. LLIconsComboBox(const Params&);
  210. virtual ~LLIconsComboBox() {};
  211. S32 mIconColumnIndex;
  212. S32 mLabelColumnIndex;
  213. };
  214. #endif