MyGUI  3.0.1
MyGUI_ComboBox.h
Go to the documentation of this file.
1 
7 /*
8  This file is part of MyGUI.
9 
10  MyGUI is free software: you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  MyGUI is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
22 */
23 #ifndef __MYGUI_COMBO_BOX_H__
24 #define __MYGUI_COMBO_BOX_H__
25 
26 #include "MyGUI_Prerequest.h"
27 #include "MyGUI_Edit.h"
28 #include "MyGUI_List.h"
29 #include "MyGUI_Any.h"
30 #include "MyGUI_EventPair.h"
32 
33 namespace MyGUI
34 {
35 
37 
39  public Edit
40  {
42 
43  public:
44  ComboBox();
45 
46  //------------------------------------------------------------------------------//
47  // манипуляции айтемами
48 
50  size_t getItemCount() const { return mList->getItemCount(); }
51 
53  void insertItemAt(size_t _index, const UString& _name, Any _data = Any::Null);
54 
56  void addItem(const UString& _name, Any _data = Any::Null) { return insertItemAt(ITEM_NONE, _name, _data); }
57 
59  void removeItemAt(size_t _index);
60 
62  void removeAllItems();
63 
64 
66  size_t findItemIndexWith(const UString& _name);
67 
68 
69  //------------------------------------------------------------------------------//
70  // манипуляции выделениями
71 
73  size_t getIndexSelected() { return mItemIndex; }
74 
76  void setIndexSelected(size_t _index);
77 
79  void clearIndexSelected() { setIndexSelected(ITEM_NONE); }
80 
81 
82  //------------------------------------------------------------------------------//
83  // манипуляции данными
84 
86  void setItemDataAt(size_t _index, Any _data);
87 
89  void clearItemDataAt(size_t _index) { setItemDataAt(_index, Any::Null); }
90 
92  template <typename ValueType>
93  ValueType * getItemDataAt(size_t _index, bool _throw = true)
94  {
95  return mList->getItemDataAt<ValueType>(_index, _throw);
96  }
97 
98 
99  //------------------------------------------------------------------------------//
100  // манипуляции отображением
101 
103  void setItemNameAt(size_t _index, const UString& _name);
104 
106  const UString& getItemNameAt(size_t _index) { return mList->getItemNameAt(_index); }
107 
108 
109  //------------------------------------------------------------------------------//
110  // манипуляции выдимостью
111 
113  void beginToItemAt(size_t _index) { mList->beginToItemAt(_index); }
114 
116  void beginToItemFirst() { if (getItemCount()) beginToItemAt(0); }
117 
119  void beginToItemLast() { if (getItemCount()) beginToItemAt(getItemCount() - 1); }
120 
122  void beginToItemSelected() { if (getIndexSelected() != ITEM_NONE) beginToItemAt(getIndexSelected()); }
123 
124 
125  //------------------------------------------------------------------------------------//
126  // методы для управления отображением
127 
129  void setComboModeDrop(bool _value);
131  bool getComboModeDrop() { return mModeDrop; }
132 
134  void setSmoothShow(bool _value) { mShowSmooth = _value; }
136  bool getSmoothShow() { return mShowSmooth; }
137 
139  void setMaxListHeight(int _value) { mMaxHeight = _value; }
141  int getMaxListHeight() { return mMaxHeight; }
142 
144  virtual void setProperty(const std::string& _key, const std::string& _value);
145 
146  /*event:*/
153 
160 
161 
162  /*internal:*/
163  virtual void _initialise(WidgetStyle _style, const IntCoord& _coord, Align _align, ResourceSkin* _info, Widget* _parent, ICroppedRectangle * _croppedParent, IWidgetCreator * _creator, const std::string& _name);
164 
165  /*obsolete:*/
166 #ifndef MYGUI_DONT_USE_OBSOLETE
167 
168  MYGUI_OBSOLETE("use : size_t ComboBox::getIndexSelected()")
169  size_t getItemIndexSelected() { return getIndexSelected(); }
170  MYGUI_OBSOLETE("use : void ComboBox::setIndexSelected(size_t _index)")
171  void setItemSelectedAt(size_t _index) { setIndexSelected(_index); }
172  MYGUI_OBSOLETE("use : void ComboBox::clearIndexSelected()")
173  void clearItemSelected() { clearIndexSelected(); }
174 
175  MYGUI_OBSOLETE("use : void ComboBox::insertItemAt(size_t _index, const UString& _name)")
176  void insertItem(size_t _index, const UString& _name) { insertItemAt(_index, _name); }
177  MYGUI_OBSOLETE("use : void ComboBox::setItemNameAt(size_t _index, const UString& _name)")
178  void setItem(size_t _index, const UString& _item) { setItemNameAt(_index, _item); }
179  MYGUI_OBSOLETE("use : const UString& ComboBox::getItemNameAt(size_t _index)")
180  const UString& getItem(size_t _index) { return getItemNameAt(_index); }
181  MYGUI_OBSOLETE("use : void ComboBox::removeItemAt(size_t _index)")
182  void deleteItem(size_t _index) { removeItemAt(_index); }
183  MYGUI_OBSOLETE("use : void ComboBox::removeAllItems()")
184  void deleteAllItems() { removeAllItems(); }
185  MYGUI_OBSOLETE("use : size_t ComboBox::getIndexSelected()")
186  size_t getItemSelect() { return getIndexSelected(); }
187  MYGUI_OBSOLETE("use : void void ComboBox::clearIndexSelected()")
188  void resetItemSelect() { clearIndexSelected(); }
189  MYGUI_OBSOLETE("use : void ComboBox::setIndexSelected(size_t _index)")
190  void setItemSelect(size_t _index) { setIndexSelected(_index); }
191 
192 #endif // MYGUI_DONT_USE_OBSOLETE
193 
194  protected:
195  virtual ~ComboBox();
196 
197  virtual void onKeyButtonPressed(KeyCode _key, Char _char);
198 
199  virtual void baseChangeWidgetSkin(ResourceSkin* _info);
200 
201  private:
202  void notifyButtonPressed(Widget* _sender, int _left, int _top, MouseButton _id);
203  void notifyListLostFocus(Widget* _sender, MyGUI::Widget* _new);
204  void notifyListSelectAccept(List* _widget, size_t _position);
205  void notifyListMouseItemActivate(List* _widget, size_t _position);
206  void notifyListChangePosition(List* _widget, size_t _position);
207  void notifyMouseWheel(Widget* _sender, int _rel);
208  void notifyMousePressed(Widget* _sender, int _left, int _top, MouseButton _id);
209  void notifyEditTextChange(Edit* _sender);
210 
211  void showList();
212  void hideList();
213 
214  void initialiseWidgetSkin(ResourceSkin* _info);
215  void shutdownWidgetSkin();
216 
217  void actionWidgetHide(Widget* _widget);
218 
219  ControllerFadeAlpha* createControllerFadeAlpha(float _alpha, float _coef, bool _enable);
220 
221  private:
222  Button* mButton;
223  List* mList;
224 
225  bool mListShow;
226  int mMaxHeight;
227  size_t mItemIndex;
228  bool mModeDrop;
229  bool mDropMouse;
230  bool mShowSmooth;
231  bool mManualList;
232 
233  };
234 
235 } // namespace MyGUI
236 
237 #endif // __MYGUI_COMBO_BOX_H__