MyGUI  3.4.0
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 
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  void setPosition(const IntPoint& _value) override;
166  void setSize(const IntSize& _value) override;
168  void setCoord(const IntCoord& _value) override;
169 
170  using Widget::setPosition;
171  using Widget::setSize;
172  using Widget::setCoord;
174 
176  int getOptimalHeight();
177 
181  void setActivateOnClick(bool activateOnClick);
182 
188  Widget* getWidgetByIndex(size_t _index);
189 
190  /*events:*/
197 
204 
211 
218 
225 
232 
233  /*internal:*/
238  // дебажная проверка на правильность выравнивания списка
239  void _checkAlign();
240 
241  // вспомогательные методы для составных списков
242  void _setItemFocus(size_t _position, bool _focus);
243  void _sendEventChangeScroll(size_t _position);
244 
245  // IItemContainer impl
246  size_t _getItemCount() override;
247  void _addItem(const MyGUI::UString& _name) override;
248  void _removeItemAt(size_t _index) override;
249  void _setItemNameAt(size_t _index, const UString& _name) override;
250  const UString& _getItemNameAt(size_t _index) override;
251 
252  void _resetContainer(bool _update) override;
254 
255  protected:
256  void initialiseOverride() override;
257  void shutdownOverride() override;
258 
259  void onMouseWheel(int _rel) override;
260  void onKeyButtonPressed(KeyCode _key, Char _char) override;
261  void onKeyButtonReleased(KeyCode _key) override;
262 
263  void notifyScrollChangePosition(ScrollBar* _sender, size_t _rel);
264  void notifyMousePressed(Widget* _sender, int _left, int _top, MouseButton _id);
265  void notifyMouseClick(Widget* _sender);
266  void notifyMouseDoubleClick(Widget* _sender);
267  void notifyMouseWheel(Widget* _sender, int _rel);
268  void notifyMouseSetFocus(Widget* _sender, Widget* _old);
269  void notifyMouseLostFocus(Widget* _sender, Widget* _new);
270  void notifyKeyButtonPressed(Widget* _sender, KeyCode _key, Char _char);
271  void notifyKeyButtonReleased(Widget* _sender, KeyCode _key);
272  void notifyMouseButtonReleased(Widget* _sender, int _left, int _top, MouseButton _id);
273 
274  void updateScroll();
275  void updateLine(bool _reset = false);
276 
277  void _activateItem(Widget* _sender);
278 
279  void _setScrollView(size_t _position);
280 
281  // перерисовывает от индекса до низа
282  void _redrawItemRange(size_t _start = 0);
283 
284  // перерисовывает индекс
285  void _redrawItem(size_t _index);
286 
287  // ищет и выделяет елемент
288  void _selectIndex(size_t _index, bool _select);
289 
290  // метод для запроса номера айтема и контейнера
291  size_t _getItemIndex(Widget* _item) override;
292 
293  void setPropertyOverride(const std::string& _key, const std::string& _value) override;
294 
295  private:
296  void _checkMapping(const std::string& _owner);
297 
298  size_t getIndexByWidget(Widget* _widget);
299 
300  private:
301  std::string mSkinLine;
302  ScrollBar* mWidgetScroll;
303 
304  // наши дети в строках
305  typedef std::vector<Button*> VectorButton;
306  VectorButton mWidgetLines;
307 
308  bool mActivateOnClick; // Require a full mouse click rather than only mouse press to activate an item
309 
310  int mHeightLine; // высота одной строки
311  int mTopIndex; // индекс самого верхнего элемента
312  int mOffsetTop; // текущее смещение
313  int mRangeIndex; // размерность скрола
314  size_t mLastRedrawLine; // последняя перерисованная линия
315 
316  size_t mIndexSelect; // текущий выделенный элемент или ITEM_NONE
317  size_t mLineActive; // текущий виджет над которым мыша
318 
319  typedef std::pair<UString, Any> PairItem;
320  typedef std::vector<PairItem> VectorItemInfo;
321  VectorItemInfo mItemsInfo;
322 
323  // имеем ли мы фокус ввода
324  bool mNeedVisibleScroll;
325 
326  IntSize mOldSize;
327  };
328 
329 } // namespace MyGUI
330 
331 #endif // MYGUI_LIST_BOX_H_
MyGUI::IItemContainer
Definition: MyGUI_IItemContainer.h:19
MyGUI::Char
unsigned int Char
Definition: MyGUI_Types.h:48
MyGUI::ListBox::eventNotifyItem
EventHandle_ListBoxPtrCIBNotifyCellDataRef eventNotifyItem
Definition: MyGUI_ListBox.h:231
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::Widget::setPosition
void setPosition(const IntPoint &_value) override
Definition: MyGUI_Widget.cpp:630
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:45
MyGUI::delegates::MultiDelegate
Definition: MyGUI_Delegate.h:183
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
Definition: MyGUI_EventPair.h:17
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:196
MyGUI::ListBox::eventListChangeScroll
EventPair< EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT > eventListChangeScroll
Definition: MyGUI_ListBox.h:224
MyGUI_IBItemInfo.h
MyGUI_Prerequest.h
MyGUI_Button.h
MyGUI::Widget::setSize
void setSize(const IntSize &_value) override
Definition: MyGUI_Widget.cpp:647
MYGUI_RTTI_DERIVED
#define MYGUI_RTTI_DERIVED(DerivedType)
Definition: MyGUI_RTTI.h:48
MyGUI::MemberObsolete
Definition: MyGUI_DeprecatedTypes.h:14
MyGUI::types::TSize
Definition: MyGUI_TSize.h:19
MyGUI::Widget::setCoord
void setCoord(const IntCoord &_value) override
Definition: MyGUI_Widget.cpp:684
MyGUI::ListBox::eventListChangePosition
EventPair< EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT > eventListChangePosition
Definition: MyGUI_ListBox.h:203
MyGUI_IItem.h
MYGUI_EXPORT
#define MYGUI_EXPORT
Definition: MyGUI_Platform.h:89
MyGUI::ListBox::eventListMouseItemActivate
EventPair< EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT > eventListMouseItemActivate
Definition: MyGUI_ListBox.h:210
MyGUI::EventHandle_ListBoxPtrCIBNotifyCellDataRef
delegates::CMultiDelegate2< ListBox *, const IBNotifyItemData & > EventHandle_ListBoxPtrCIBNotifyCellDataRef
Definition: MyGUI_ListBox.h:22
MyGUI::types::TCoord< int >
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:217
MyGUI::KeyCode
Definition: MyGUI_KeyCode.h:16