MyGUI  3.2.0
MyGUI_ListBox.h
Go to the documentation of this file.
1 
6 /*
7  This file is part of MyGUI.
8 
9  MyGUI is free software: you can redistribute it and/or modify
10  it under the terms of the GNU Lesser General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  MyGUI 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
17  GNU Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
21 */
22 #ifndef __MYGUI_LIST_BOX_H__
23 #define __MYGUI_LIST_BOX_H__
24 
25 #include "MyGUI_Prerequest.h"
26 #include "MyGUI_Button.h"
27 #include "MyGUI_Any.h"
28 #include "MyGUI_EventPair.h"
29 #include "MyGUI_IItem.h"
30 #include "MyGUI_IItemContainer.h"
31 
32 namespace MyGUI
33 {
34 
36 
38  public Widget,
39  public IItemContainer,
40  public MemberObsolete<ListBox>
41  {
43 
44  public:
45  ListBox();
46 
47  //------------------------------------------------------------------------------//
48  // манипуляции айтемами
49 
54 
55  size_t getItemCount() const;
56 
58  void insertItemAt(size_t _index, const UString& _name, Any _data = Any::Null);
59 
61  void addItem(const UString& _name, Any _data = Any::Null);
62 
64  void removeItemAt(size_t _index);
65 
67  void removeAllItems();
68 
70  void swapItemsAt(size_t _index1, size_t _index2);
71 
72 
74  size_t findItemIndexWith(const UString& _name);
76 
77  //------------------------------------------------------------------------------//
78  // манипуляции выделениями
79 
85  size_t getIndexSelected() const;
86 
88  void setIndexSelected(size_t _index);
89 
91  void clearIndexSelected();
93 
94  //------------------------------------------------------------------------------//
95  // манипуляции данными
96 
101 
102  void setItemDataAt(size_t _index, Any _data);
103 
105  void clearItemDataAt(size_t _index);
106 
108  template <typename ValueType>
109  ValueType* getItemDataAt(size_t _index, bool _throw = true)
110  {
111  MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "ListBox::getItemDataAt");
112  return mItemsInfo[_index].second.castType<ValueType>(_throw);
113  }
115 
116  //------------------------------------------------------------------------------//
117  // манипуляции отображением
118 
120  void setItemNameAt(size_t _index, const UString& _name);
121 
123  const UString& getItemNameAt(size_t _index);
124 
125 
126  //------------------------------------------------------------------------------//
127  // манипуляции выдимостью
128 
133 
134  void beginToItemAt(size_t _index);
135 
137  void beginToItemFirst();
138 
140  void beginToItemLast();
141 
143  void beginToItemSelected();
144 
145  //------------------------------------------------------------------------------//
146 
147  // видим ли мы элемент, полностью или нет
156  bool isItemVisibleAt(size_t _index, bool _fill = true);
158  bool isItemSelectedVisible(bool _fill = true);
159 
160 
162  void setScrollVisible(bool _visible);
164  void setScrollPosition(size_t _position);
166 
167  //------------------------------------------------------------------------------------//
168 
173 
174  virtual void setPosition(const IntPoint& _value);
176  virtual void setSize(const IntSize& _value);
178  virtual void setCoord(const IntCoord& _value);
179 
181  void setPosition(int _left, int _top);
183  void setSize(int _width, int _height);
185  void setCoord(int _left, int _top, int _width, int _height);
187 
188  // возвращает максимальную высоту вмещающую все строки и родительский бордюр
190  int getOptimalHeight();
191 
192  /*events:*/
200 
208 
216 
224 
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  virtual size_t _getItemCount();
247  virtual void _addItem(const MyGUI::UString& _name);
248  virtual void _removeItemAt(size_t _index);
249  virtual void _setItemNameAt(size_t _index, const UString& _name);
250  virtual const UString& _getItemNameAt(size_t _index);
251 
252  virtual void _resetContainer(bool _update);
254 
255  protected:
256  virtual void initialiseOverride();
257  virtual void shutdownOverride();
258 
259  void onMouseWheel(int _rel);
260  void onKeyButtonPressed(KeyCode _key, Char _char);
261 
262  void notifyScrollChangePosition(ScrollBar* _sender, size_t _rel);
263  void notifyMousePressed(Widget* _sender, int _left, int _top, MouseButton _id);
264  void notifyMouseDoubleClick(Widget* _sender);
265  void notifyMouseWheel(Widget* _sender, int _rel);
266  void notifyMouseSetFocus(Widget* _sender, Widget* _old);
267  void notifyMouseLostFocus(Widget* _sender, Widget* _new);
268 
269  void updateScroll();
270  void updateLine(bool _reset = false);
271  void _setScrollView(size_t _position);
272 
273  // перерисовывает от индекса до низа
274  void _redrawItemRange(size_t _start = 0);
275 
276  // перерисовывает индекс
277  void _redrawItem(size_t _index);
278 
279  // ищет и выделяет елемент
280  void _selectIndex(size_t _index, bool _select);
281 
282  // метод для запроса номера айтема и контейнера
283  virtual size_t _getItemIndex(Widget* _item);
284 
285  virtual void setPropertyOverride(const std::string& _key, const std::string& _value);
286 
287  private:
288  void _checkMapping(const std::string& _owner);
289 
290  Widget* _getClientWidget();
291 
292  private:
293  std::string mSkinLine;
294  ScrollBar* mWidgetScroll;
295 
296  // наши дети в строках
297  typedef std::vector<Button*> VectorButton;
298  VectorButton mWidgetLines;
299 
300  int mHeightLine; // высота одной строки
301  int mTopIndex; // индекс самого верхнего элемента
302  int mOffsetTop; // текущее смещение
303  int mRangeIndex; // размерность скрола
304  size_t mLastRedrawLine; // последняя перерисованная линия
305 
306  size_t mIndexSelect; // текущий выделенный элемент или ITEM_NONE
307  size_t mLineActive; // текущий виджет над которым мыша
308 
309  typedef std::pair<UString, Any> PairItem;
310  typedef std::vector<PairItem> VectorItemInfo;
311  VectorItemInfo mItemsInfo;
312 
313  // имеем ли мы фокус ввода
314  bool mNeedVisibleScroll;
315 
316  IntSize mOldSize;
317 
318  Widget* mClient;
319  };
320 
321 } // namespace MyGUI
322 
323 #endif // __MYGUI_LIST_BOX_H__