MyGUI
3.2.1
|
00001 /* 00002 * This source file is part of MyGUI. For the latest info, see http://mygui.info/ 00003 * Distributed under the MIT License 00004 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT) 00005 */ 00006 00007 #ifndef __MYGUI_MULTI_LIST_BOX_H__ 00008 #define __MYGUI_MULTI_LIST_BOX_H__ 00009 00010 #include "MyGUI_Prerequest.h" 00011 #include "MyGUI_Widget.h" 00012 #include "MyGUI_ListBox.h" 00013 #include "MyGUI_Any.h" 00014 #include "MyGUI_BiIndexBase.h" 00015 #include "MyGUI_EventPair.h" 00016 #include "MyGUI_IItem.h" 00017 #include "MyGUI_IItemContainer.h" 00018 #include "MyGUI_ResizingPolicy.h" 00019 00020 namespace MyGUI 00021 { 00022 00023 //OBSOLETE 00024 typedef delegates::CMultiDelegate5<Widget*, size_t, const UString&, const UString&, bool&> EventHandle_WidgetIntUTFStringUTFStringBool; 00025 00026 typedef delegates::CDelegate5<MultiListBox*, size_t, const UString&, const UString&, bool&> EventHandle_MultiListPtrSizeTCUTFStringRefCUTFStringRefBoolRef; 00027 typedef delegates::CMultiDelegate2<MultiListBox*, size_t> EventHandle_MultiListPtrSizeT; 00028 00032 class MYGUI_EXPORT MultiListBox : 00033 public Widget, 00034 public BiIndexBase, 00035 public IItemContainer, 00036 public MemberObsolete<MultiListBox> 00037 { 00038 MYGUI_RTTI_DERIVED( MultiListBox ) 00039 00040 public: 00041 MultiListBox(); 00042 00044 virtual void setPosition(const IntPoint& _value); 00046 virtual void setSize(const IntSize& _value); 00048 virtual void setCoord(const IntCoord& _value); 00049 00051 void setPosition(int _left, int _top); 00053 void setSize(int _width, int _height); 00055 void setCoord(int _left, int _top, int _width, int _height); 00056 00057 //------------------------------------------------------------------------------// 00058 // Methods for work with columns (RU:методы для работы со столбцами) 00059 //------------------------------------------------------------------------------// 00060 // манипуляции айтемами 00061 00063 size_t getColumnCount() const; 00064 00071 void insertColumnAt(size_t _column, const UString& _name, int _width = 0, Any _data = Any::Null); 00072 00078 void addColumn(const UString& _name, int _width = 0, Any _data = Any::Null); 00079 00081 void removeColumnAt(size_t _column); 00082 00084 void removeAllColumns(); 00085 00087 void swapColumnsAt(size_t _index1, size_t _index2); 00088 00089 //------------------------------------------------------------------------------// 00090 // манипуляции отображением 00091 00096 void setColumnNameAt(size_t _column, const UString& _name); 00097 00102 void setColumnName(MultiListItem* _item, const UString& _name); 00103 00108 void setColumnWidthAt(size_t _column, int _width); 00109 00114 void setColumnWidth(MultiListItem* _item, int _width); 00115 00117 const UString& getColumnNameAt(size_t _column); 00118 00120 const UString& getColumnName(MultiListItem* _item); 00121 00123 int getColumnWidthAt(size_t _column); 00124 00126 void sortByColumn(size_t _column, bool _backward = false); 00127 00129 size_t getColumnIndex(MultiListItem* _item); 00130 00135 void setColumnResizingPolicy(MultiListItem* _item, ResizingPolicy _value); 00140 void setColumnResizingPolicyAt(size_t _index, ResizingPolicy _value); 00141 00142 //------------------------------------------------------------------------------// 00143 // манипуляции данными 00144 00146 void setColumnDataAt(size_t _index, Any _data); 00147 00149 void clearColumnDataAt(size_t _index); 00150 00152 template <typename ValueType> 00153 ValueType* getColumnDataAt(size_t _index, bool _throw = true) 00154 { 00155 MYGUI_ASSERT_RANGE(_index, mVectorColumnInfo.size(), "MultiListBox::getItemDataAt"); 00156 return mVectorColumnInfo[_index].data.castType<ValueType>(_throw); 00157 } 00158 00159 //------------------------------------------------------------------------------// 00160 // Methods for work with lines (RU:методы для работы со строками) 00166 //------------------------------------------------------------------------------// 00167 // манипуляции айтемами 00168 00170 size_t getItemCount() const; 00171 00173 void insertItemAt(size_t _index, const UString& _name, Any _data = Any::Null); 00174 00176 void addItem(const UString& _name, Any _data = Any::Null); 00177 00179 void removeItemAt(size_t _index); 00180 00182 void removeAllItems(); 00183 00185 void swapItemsAt(size_t _index1, size_t _index2); 00186 00187 00188 //------------------------------------------------------------------------------// 00189 // манипуляции отображением 00190 00192 void setItemNameAt(size_t _index, const UString& _name); 00193 00195 const UString& getItemNameAt(size_t _index); 00196 00197 00198 //------------------------------------------------------------------------------// 00199 // манипуляции выделениями 00200 00202 size_t getIndexSelected() const; 00203 00205 void setIndexSelected(size_t _index); 00206 00208 void clearIndexSelected(); 00209 00210 00211 //------------------------------------------------------------------------------// 00212 // манипуляции данными 00213 00215 void setItemDataAt(size_t _index, Any _data); 00216 00218 void clearItemDataAt(size_t _index); 00219 00221 template <typename ValueType> 00222 ValueType* getItemDataAt(size_t _index, bool _throw = true) 00223 { 00224 return getSubItemDataAt<ValueType>(0, _index, _throw); 00225 } 00226 00227 00228 //------------------------------------------------------------------------------// 00229 // Methods for work with sub lines (RU:методы для работы со саб строками) 00230 //------------------------------------------------------------------------------// 00231 // манипуляции данными 00232 00238 void setSubItemNameAt(size_t _column, size_t _index, const UString& _name); 00239 00241 const UString& getSubItemNameAt(size_t _column, size_t _index); 00242 00244 size_t findSubItemWith(size_t _column, const UString& _name); 00245 00246 //------------------------------------------------------------------------------// 00247 // манипуляции данными 00248 00250 void setSubItemDataAt(size_t _column, size_t _index, Any _data); 00251 00253 void clearSubItemDataAt(size_t _column, size_t _index); 00254 00256 template <typename ValueType> 00257 ValueType* getSubItemDataAt(size_t _column, size_t _index, bool _throw = true) 00258 { 00259 MYGUI_ASSERT_RANGE(_index, mVectorColumnInfo.begin()->list->getItemCount(), "MultiListBox::getSubItemDataAt"); 00260 00261 size_t index = BiIndexBase::convertToBack(_index); 00262 return getSubItemAt(_column)->getItemDataAt<ValueType>(index, _throw); 00263 } 00264 00265 /*events:*/ 00271 EventPair<EventHandle_WidgetSizeT, EventHandle_MultiListPtrSizeT> eventListSelectAccept; 00272 00278 EventPair<EventHandle_WidgetSizeT, EventHandle_MultiListPtrSizeT> eventListChangePosition; 00279 00288 EventHandle_MultiListPtrSizeTCUTFStringRefCUTFStringRefBoolRef requestOperatorLess; 00289 00290 /*internal:*/ 00291 // IItemContainer impl 00292 virtual size_t _getItemCount(); 00293 virtual void _addItem(const MyGUI::UString& _name); 00294 virtual void _removeItemAt(size_t _index); 00295 virtual Widget* _getItemAt(size_t _index); 00296 virtual void _setItemNameAt(size_t _index, const UString& _name); 00297 virtual const UString& _getItemNameAt(size_t _index); 00298 00299 protected: 00300 virtual void initialiseOverride(); 00301 virtual void shutdownOverride(); 00302 00303 virtual void onWidgetCreated(Widget* _widget); 00304 virtual void onWidgetDestroy(Widget* _widget); 00305 00306 private: 00307 void notifyListChangePosition(ListBox* _sender, size_t _position); 00308 void notifyListChangeFocus(ListBox* _sender, size_t _position); 00309 void notifyListChangeScrollPosition(ListBox* _sender, size_t _position); 00310 void notifyButtonClick(Widget* _sender); 00311 void notifyListSelectAccept(ListBox* _sender, size_t _position); 00312 00313 void updateColumns(); 00314 void redrawButtons(); 00315 void updateOnlyEmpty(); 00316 00317 bool compare(ListBox* _list, size_t _left, size_t _right); 00318 void sortList(); 00319 void flipList(); 00320 00321 Widget* getSeparator(size_t _index); 00322 00323 void updateBackSelected(size_t _index); 00324 00325 struct ColumnInfo 00326 { 00327 MultiListItem* item; 00328 ListBox* list; 00329 Button* button; 00330 int width; 00331 int realWidth; 00332 UString name; 00333 Any data; 00334 ResizingPolicy sizeType; 00335 }; 00336 00337 typedef std::vector<ColumnInfo> VectorColumnInfo; 00338 00339 void frameEntered(float _frame); 00340 void frameAdvise(bool _advise); 00341 00342 ListBox* getSubItemAt(size_t _column); 00343 int getButtonHeight() const; 00344 00345 void _wrapItem(MultiListItem* _item); 00346 void _unwrapItem(MultiListItem* _item); 00347 void _swapColumnsAt(size_t _index1, size_t _index2); 00348 00349 int getColumnWidth(size_t _index, int _freeSpace, size_t _countStars, size_t _lastIndexStar, int _starWidth) const; 00350 bool getUpdateByResize(); 00351 int updateWidthColumns(size_t& _countStars, size_t& _lastIndexStar); 00352 00353 private: 00354 int mHeightButton; 00355 int mWidthBar; 00356 std::string mSkinButton; 00357 std::string mSkinList; 00358 Widget* mWidgetEmpty; 00359 00360 VectorColumnInfo mVectorColumnInfo; 00361 00362 VectorWidgetPtr mSeparators; 00363 00364 size_t mLastMouseFocusIndex; 00365 00366 bool mSortUp; 00367 size_t mSortColumnIndex; 00368 00369 int mWidthSeparator; 00370 std::string mSkinSeparator; 00371 00372 size_t mItemSelected; 00373 00374 bool mFrameAdvise; 00375 Widget* mClient; 00376 Widget* mHeaderPlace; 00377 }; 00378 00379 } // namespace MyGUI 00380 00381 #endif // __MYGUI_MULTI_LIST_BOX_H__