MyGUI  3.2.2
MyGUI_ListBox.h
Go to the documentation of this file.
1 /*
2  * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3  * Distributed under the MIT License
4  * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5  */
6 
7 #ifndef MYGUI_LIST_BOX_H_
8 #define MYGUI_LIST_BOX_H_
9 
10 #include "MyGUI_Prerequest.h"
11 #include "MyGUI_Button.h"
12 #include "MyGUI_Any.h"
13 #include "MyGUI_EventPair.h"
14 #include "MyGUI_IItem.h"
15 #include "MyGUI_IItemContainer.h"
16 #include "MyGUI_IBItemInfo.h"
17 
18 namespace MyGUI
19 {
20 
21  typedef delegates::CMultiDelegate2<ListBox*, size_t> EventHandle_ListPtrSizeT;
22  typedef delegates::CMultiDelegate2<ListBox*, const IBNotifyItemData&> EventHandle_ListBoxPtrCIBNotifyCellDataRef;
23 
28  public Widget,
29  public IItemContainer,
30  public MemberObsolete<ListBox>
31  {
33 
34  public:
35  ListBox();
36 
37  //------------------------------------------------------------------------------//
38  // манипуляции айтемами
39 
44  size_t getItemCount() const;
46 
48  void insertItemAt(size_t _index, const UString& _name, Any _data = Any::Null);
49 
51  void addItem(const UString& _name, Any _data = Any::Null);
52 
54  void removeItemAt(size_t _index);
55 
57  void removeAllItems();
58 
60  void swapItemsAt(size_t _index1, size_t _index2);
61 
62 
64  size_t findItemIndexWith(const UString& _name);
66 
67  //------------------------------------------------------------------------------//
68  // манипуляции выделениями
69 
75  size_t getIndexSelected() const;
76 
78  void setIndexSelected(size_t _index);
79 
81  void clearIndexSelected();
83 
84  //------------------------------------------------------------------------------//
85  // манипуляции данными
86 
91  void setItemDataAt(size_t _index, Any _data);
93 
95  void clearItemDataAt(size_t _index);
96 
98  template <typename ValueType>
99  ValueType* getItemDataAt(size_t _index, bool _throw = true)
100  {
101  MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "ListBox::getItemDataAt");
102  return mItemsInfo[_index].second.castType<ValueType>(_throw);
103  }
105 
106  //------------------------------------------------------------------------------//
107  // манипуляции отображением
108 
110  void setItemNameAt(size_t _index, const UString& _name);
111 
113  const UString& getItemNameAt(size_t _index);
114 
115 
116  //------------------------------------------------------------------------------//
117  // манипуляции выдимостью
118 
123  void beginToItemAt(size_t _index);
125 
127  void beginToItemFirst();
128 
130  void beginToItemLast();
131 
133  void beginToItemSelected();
134 
135  //------------------------------------------------------------------------------//
136 
137  // видим ли мы элемент, полностью или нет
146  bool isItemVisibleAt(size_t _index, bool _fill = true);
148  bool isItemSelectedVisible(bool _fill = true);
149 
150 
152  void setScrollVisible(bool _visible);
154  void setScrollPosition(size_t _position);
156 
157  //------------------------------------------------------------------------------------//
158 
163  virtual void setPosition(const IntPoint& _value);
166  virtual void setSize(const IntSize& _value);
168  virtual void setCoord(const IntCoord& _value);
169 
171  void setPosition(int _left, int _top);
173  void setSize(int _width, int _height);
175  void setCoord(int _left, int _top, int _width, int _height);
177 
178  // возвращает максимальную высоту вмещающую все строки и родительский бордюр
180  int getOptimalHeight();
181 
185  void setActivateOnClick(bool activateOnClick);
186 
192  Widget* getWidgetByIndex(size_t _index);
193 
194  /*events:*/
201 
208 
215 
222 
229 
236 
237  /*internal:*/
242  // дебажная проверка на правильность выравнивания списка
243  void _checkAlign();
244 
245  // вспомогательные методы для составных списков
246  void _setItemFocus(size_t _position, bool _focus);
247  void _sendEventChangeScroll(size_t _position);
248 
249  // IItemContainer impl
250  virtual size_t _getItemCount();
251  virtual void _addItem(const MyGUI::UString& _name);
252  virtual void _removeItemAt(size_t _index);
253  virtual void _setItemNameAt(size_t _index, const UString& _name);
254  virtual const UString& _getItemNameAt(size_t _index);
255 
256  virtual void _resetContainer(bool _update);
258 
259  protected:
260  virtual void initialiseOverride();
261  virtual void shutdownOverride();
262 
263  void onMouseWheel(int _rel);
264  void onKeyButtonPressed(KeyCode _key, Char _char);
265  void onKeyButtonReleased(KeyCode _key);
266 
267  void notifyScrollChangePosition(ScrollBar* _sender, size_t _rel);
268  void notifyMousePressed(Widget* _sender, int _left, int _top, MouseButton _id);
269  void notifyMouseClick(Widget* _sender);
270  void notifyMouseDoubleClick(Widget* _sender);
271  void notifyMouseWheel(Widget* _sender, int _rel);
272  void notifyMouseSetFocus(Widget* _sender, Widget* _old);
273  void notifyMouseLostFocus(Widget* _sender, Widget* _new);
274  void notifyKeyButtonPressed(Widget* _sender, KeyCode _key, Char _char);
275  void notifyKeyButtonReleased(Widget* _sender, KeyCode _key);
276  void notifyMouseButtonReleased(Widget* _sender, int _left, int _top, MouseButton _id);
277 
278  void updateScroll();
279  void updateLine(bool _reset = false);
280 
281  void _activateItem(Widget* _sender);
282 
283  void _setScrollView(size_t _position);
284 
285  // перерисовывает от индекса до низа
286  void _redrawItemRange(size_t _start = 0);
287 
288  // перерисовывает индекс
289  void _redrawItem(size_t _index);
290 
291  // ищет и выделяет елемент
292  void _selectIndex(size_t _index, bool _select);
293 
294  // метод для запроса номера айтема и контейнера
295  virtual size_t _getItemIndex(Widget* _item);
296 
297  virtual void setPropertyOverride(const std::string& _key, const std::string& _value);
298 
299  private:
300  void _checkMapping(const std::string& _owner);
301 
302  Widget* _getClientWidget();
303 
304  size_t getIndexByWidget(Widget* _widget);
305 
306  private:
307  std::string mSkinLine;
308  ScrollBar* mWidgetScroll;
309 
310  // наши дети в строках
311  typedef std::vector<Button*> VectorButton;
312  VectorButton mWidgetLines;
313 
314  bool mActivateOnClick; // Require a full mouse click rather than only mouse press to activate an item
315 
316  int mHeightLine; // высота одной строки
317  int mTopIndex; // индекс самого верхнего элемента
318  int mOffsetTop; // текущее смещение
319  int mRangeIndex; // размерность скрола
320  size_t mLastRedrawLine; // последняя перерисованная линия
321 
322  size_t mIndexSelect; // текущий выделенный элемент или ITEM_NONE
323  size_t mLineActive; // текущий виджет над которым мыша
324 
325  typedef std::pair<UString, Any> PairItem;
326  typedef std::vector<PairItem> VectorItemInfo;
327  VectorItemInfo mItemsInfo;
328 
329  // имеем ли мы фокус ввода
330  bool mNeedVisibleScroll;
331 
332  IntSize mOldSize;
333 
334  Widget* mClient;
335  };
336 
337 } // namespace MyGUI
338 
339 #endif // MYGUI_LIST_BOX_H_
MyGUI::IItemContainer
Definition: MyGUI_IItemContainer.h:19
MyGUI::ListBox::eventNotifyItem
EventHandle_ListBoxPtrCIBNotifyCellDataRef eventNotifyItem
Definition: MyGUI_ListBox.h:235
MyGUI::EventHandle_ListPtrSizeT
delegates::CMultiDelegate2< ListBox *, size_t > EventHandle_ListPtrSizeT
Definition: MyGUI_ListBox.h:21
MyGUI::ListBox
ListBox properties. Skin childs. ListBox widget description should be here.
Definition: MyGUI_ListBox.h:31
MyGUI::ScrollBar
ScrollBar properties. Skin childs. ScrollBar widget description should be here.
Definition: MyGUI_ScrollBar.h:26
MyGUI::ListBox::getItemDataAt
ValueType * getItemDataAt(size_t _index, bool _throw=true)
Get item data from specified position.
Definition: MyGUI_ListBox.h:99
MyGUI_EventPair.h
MYGUI_ASSERT_RANGE
#define MYGUI_ASSERT_RANGE(index, size, owner)
Definition: MyGUI_Diagnostic.h:54
MyGUI::Widget
Widget properties. Skin childs. Widget widget description should be here.
Definition: MyGUI_Widget.h:37
MyGUI_IItemContainer.h
MyGUI::types::TPoint< int >
MyGUI::Any
Definition: MyGUI_Any.h:64
MyGUI::EventPair< EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT >
MyGUI::UString
A UTF-16 string with implicit conversion to/from std::string and std::wstring.
Definition: MyGUI_UString.h:168
MyGUI::MouseButton
Definition: MyGUI_MouseButton.h:16
MyGUI::ListBox::eventListSelectAccept
EventPair< EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT > eventListSelectAccept
Definition: MyGUI_ListBox.h:200
MyGUI::ListBox::eventListChangeScroll
EventPair< EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT > eventListChangeScroll
Definition: MyGUI_ListBox.h:228
MyGUI_IBItemInfo.h
MyGUI_Prerequest.h
MyGUI_Button.h
MYGUI_RTTI_DERIVED
#define MYGUI_RTTI_DERIVED(DerivedType)
Definition: MyGUI_RTTI.h:61
MyGUI::MemberObsolete
Definition: MyGUI_DeprecatedTypes.h:14
MyGUI::types::TSize< int >
MyGUI::ListBox::eventListChangePosition
EventPair< EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT > eventListChangePosition
Definition: MyGUI_ListBox.h:207
MyGUI_IItem.h
MYGUI_EXPORT
#define MYGUI_EXPORT
Definition: MyGUI_Platform.h:103
MyGUI::Char
unsigned int Char
Definition: MyGUI_Types.h:51
MyGUI::ListBox::eventListMouseItemActivate
EventPair< EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT > eventListMouseItemActivate
Definition: MyGUI_ListBox.h:214
MyGUI::EventHandle_ListBoxPtrCIBNotifyCellDataRef
delegates::CMultiDelegate2< ListBox *, const IBNotifyItemData & > EventHandle_ListBoxPtrCIBNotifyCellDataRef
Definition: MyGUI_ListBox.h:22
MyGUI::types::TCoord
Definition: MyGUI_TCoord.h:21
MyGUI::Any::Null
static AnyEmpty Null
Definition: MyGUI_Any.h:67
MyGUI
Definition: MyGUI_ActionController.h:15
MyGUI_Any.h
MyGUI::ListBox::eventListMouseItemFocus
EventPair< EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT > eventListMouseItemFocus
Definition: MyGUI_ListBox.h:221
MyGUI::KeyCode
Definition: MyGUI_KeyCode.h:16