MyGUI  3.2.0
MyGUI_MultiListBox.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_MULTI_LIST_BOX_H__
23 #define __MYGUI_MULTI_LIST_BOX_H__
24 
25 #include "MyGUI_Prerequest.h"
26 #include "MyGUI_Widget.h"
27 #include "MyGUI_ListBox.h"
28 #include "MyGUI_Any.h"
29 #include "MyGUI_BiIndexBase.h"
30 #include "MyGUI_EventPair.h"
31 #include "MyGUI_IItem.h"
32 #include "MyGUI_IItemContainer.h"
33 #include "MyGUI_ResizingPolicy.h"
34 
35 namespace MyGUI
36 {
37 
38  //OBSOLETE
40 
43 
45  public Widget,
46  public BiIndexBase,
47  public IItemContainer,
48  public MemberObsolete<MultiListBox>
49  {
51 
52  public:
53  MultiListBox();
54 
56  virtual void setPosition(const IntPoint& _value);
58  virtual void setSize(const IntSize& _value);
60  virtual void setCoord(const IntCoord& _value);
61 
63  void setPosition(int _left, int _top);
65  void setSize(int _width, int _height);
67  void setCoord(int _left, int _top, int _width, int _height);
68 
69  //------------------------------------------------------------------------------//
70  // Methods for work with columns (RU:методы для работы со столбцами)
71  //------------------------------------------------------------------------------//
72  // манипуляции айтемами
73 
75  size_t getColumnCount() const;
76 
83  void insertColumnAt(size_t _column, const UString& _name, int _width = 0, Any _data = Any::Null);
84 
90  void addColumn(const UString& _name, int _width = 0, Any _data = Any::Null);
91 
93  void removeColumnAt(size_t _column);
94 
96  void removeAllColumns();
97 
99  void swapColumnsAt(size_t _index1, size_t _index2);
100 
101  //------------------------------------------------------------------------------//
102  // манипуляции отображением
103 
108  void setColumnNameAt(size_t _column, const UString& _name);
109 
114  void setColumnName(MultiListItem* _item, const UString& _name);
115 
120  void setColumnWidthAt(size_t _column, int _width);
121 
126  void setColumnWidth(MultiListItem* _item, int _width);
127 
129  const UString& getColumnNameAt(size_t _column);
130 
132  const UString& getColumnName(MultiListItem* _item);
133 
135  int getColumnWidthAt(size_t _column);
136 
138  void sortByColumn(size_t _column, bool _backward = false);
139 
141  size_t getColumnIndex(MultiListItem* _item);
142 
147  void setColumnResizingPolicy(MultiListItem* _item, ResizingPolicy _value);
152  void setColumnResizingPolicyAt(size_t _index, ResizingPolicy _value);
153 
154  //------------------------------------------------------------------------------//
155  // манипуляции данными
156 
158  void setColumnDataAt(size_t _index, Any _data);
159 
161  void clearColumnDataAt(size_t _index);
162 
164  template <typename ValueType>
165  ValueType* getColumnDataAt(size_t _index, bool _throw = true)
166  {
167  MYGUI_ASSERT_RANGE(_index, mVectorColumnInfo.size(), "MultiListBox::getItemDataAt");
168  return mVectorColumnInfo[_index].data.castType<ValueType>(_throw);
169  }
170 
171  //------------------------------------------------------------------------------//
172  // Methods for work with lines (RU:методы для работы со строками)
178  //------------------------------------------------------------------------------//
179  // манипуляции айтемами
180 
182  size_t getItemCount() const;
183 
185  void insertItemAt(size_t _index, const UString& _name, Any _data = Any::Null);
186 
188  void addItem(const UString& _name, Any _data = Any::Null);
189 
191  void removeItemAt(size_t _index);
192 
194  void removeAllItems();
195 
197  void swapItemsAt(size_t _index1, size_t _index2);
198 
199 
200  //------------------------------------------------------------------------------//
201  // манипуляции отображением
202 
204  void setItemNameAt(size_t _index, const UString& _name);
205 
207  const UString& getItemNameAt(size_t _index);
208 
209 
210  //------------------------------------------------------------------------------//
211  // манипуляции выделениями
212 
214  size_t getIndexSelected() const;
215 
217  void setIndexSelected(size_t _index);
218 
220  void clearIndexSelected();
221 
222 
223  //------------------------------------------------------------------------------//
224  // манипуляции данными
225 
227  void setItemDataAt(size_t _index, Any _data);
228 
230  void clearItemDataAt(size_t _index);
231 
233  template <typename ValueType>
234  ValueType* getItemDataAt(size_t _index, bool _throw = true)
235  {
236  return getSubItemDataAt<ValueType>(0, _index, _throw);
237  }
238 
239 
240  //------------------------------------------------------------------------------//
241  // Methods for work with sub lines (RU:методы для работы со саб строками)
242  //------------------------------------------------------------------------------//
243  // манипуляции данными
244 
250  void setSubItemNameAt(size_t _column, size_t _index, const UString& _name);
251 
253  const UString& getSubItemNameAt(size_t _column, size_t _index);
254 
256  size_t findSubItemWith(size_t _column, const UString& _name);
257 
258  //------------------------------------------------------------------------------//
259  // манипуляции данными
260 
262  void setSubItemDataAt(size_t _column, size_t _index, Any _data);
263 
265  void clearSubItemDataAt(size_t _column, size_t _index);
266 
268  template <typename ValueType>
269  ValueType* getSubItemDataAt(size_t _column, size_t _index, bool _throw = true)
270  {
271  MYGUI_ASSERT_RANGE(_index, mVectorColumnInfo.begin()->list->getItemCount(), "MultiListBox::getSubItemDataAt");
272 
273  size_t index = BiIndexBase::convertToBack(_index);
274  return getSubItemAt(_column)->getItemDataAt<ValueType>(index, _throw);
275  }
276 
277  /*events:*/
285 
293 
304 
305  /*internal:*/
306  // IItemContainer impl
307  virtual size_t _getItemCount();
308  virtual void _addItem(const MyGUI::UString& _name);
309  virtual void _removeItemAt(size_t _index);
310  virtual Widget* _getItemAt(size_t _index);
311  virtual void _setItemNameAt(size_t _index, const UString& _name);
312  virtual const UString& _getItemNameAt(size_t _index);
313 
314  protected:
315  virtual void initialiseOverride();
316  virtual void shutdownOverride();
317 
318  virtual void onWidgetCreated(Widget* _widget);
319  virtual void onWidgetDestroy(Widget* _widget);
320 
321  private:
322  void notifyListChangePosition(ListBox* _sender, size_t _position);
323  void notifyListChangeFocus(ListBox* _sender, size_t _position);
324  void notifyListChangeScrollPosition(ListBox* _sender, size_t _position);
325  void notifyButtonClick(Widget* _sender);
326  void notifyListSelectAccept(ListBox* _sender, size_t _position);
327 
328  void updateColumns();
329  void redrawButtons();
330  void updateOnlyEmpty();
331 
332  bool compare(ListBox* _list, size_t _left, size_t _right);
333  void sortList();
334  void flipList();
335 
336  Widget* getSeparator(size_t _index);
337 
338  void updateBackSelected(size_t _index);
339 
340  struct ColumnInfo
341  {
342  MultiListItem* item;
343  ListBox* list;
344  Button* button;
345  int width;
346  int realWidth;
347  UString name;
348  Any data;
349  ResizingPolicy sizeType;
350  };
351 
352  typedef std::vector<ColumnInfo> VectorColumnInfo;
353 
354  void frameEntered(float _frame);
355  void frameAdvise(bool _advise);
356 
357  ListBox* getSubItemAt(size_t _column);
358  int getButtonHeight() const;
359 
360  void _wrapItem(MultiListItem* _item);
361  void _unwrapItem(MultiListItem* _item);
362  void _swapColumnsAt(size_t _index1, size_t _index2);
363 
364  int getColumnWidth(size_t _index, int _freeSpace, size_t _countStars, size_t _lastIndexStar, int _starWidth) const;
365  bool getUpdateByResize();
366  int updateWidthColumns(size_t& _countStars, size_t& _lastIndexStar);
367 
368  private:
369  int mHeightButton;
370  int mWidthBar;
371  std::string mSkinButton;
372  std::string mSkinList;
373  Widget* mWidgetEmpty;
374 
375  VectorColumnInfo mVectorColumnInfo;
376 
377  VectorWidgetPtr mSeparators;
378 
379  size_t mLastMouseFocusIndex;
380 
381  bool mSortUp;
382  size_t mSortColumnIndex;
383 
384  int mWidthSeparator;
385  std::string mSkinSeparator;
386  int mOffsetButtonSeparator;
387 
388  size_t mItemSelected;
389 
390  bool mFrameAdvise;
391  Widget* mClient;
392  Widget* mHeaderPlace;
393  };
394 
395 } // namespace MyGUI
396 
397 #endif // __MYGUI_MULTI_LIST_BOX_H__