MyGUI
3.2.0
|
00001 00006 /* 00007 This file is part of MyGUI. 00008 00009 MyGUI is free software: you can redistribute it and/or modify 00010 it under the terms of the GNU Lesser General Public License as published by 00011 the Free Software Foundation, either version 3 of the License, or 00012 (at your option) any later version. 00013 00014 MyGUI is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License 00020 along with MyGUI. If not, see <http://www.gnu.org/licenses/>. 00021 */ 00022 #ifndef __MYGUI_MULTI_LIST_BOX_H__ 00023 #define __MYGUI_MULTI_LIST_BOX_H__ 00024 00025 #include "MyGUI_Prerequest.h" 00026 #include "MyGUI_Widget.h" 00027 #include "MyGUI_ListBox.h" 00028 #include "MyGUI_Any.h" 00029 #include "MyGUI_BiIndexBase.h" 00030 #include "MyGUI_EventPair.h" 00031 #include "MyGUI_IItem.h" 00032 #include "MyGUI_IItemContainer.h" 00033 #include "MyGUI_ResizingPolicy.h" 00034 00035 namespace MyGUI 00036 { 00037 00038 //OBSOLETE 00039 typedef delegates::CMultiDelegate5<Widget*, size_t, const UString&, const UString&, bool&> EventHandle_WidgetIntUTFStringUTFStringBool; 00040 00041 typedef delegates::CDelegate5<MultiListBox*, size_t, const UString&, const UString&, bool&> EventHandle_MultiListPtrSizeTCUTFStringRefCUTFStringRefBoolRef; 00042 typedef delegates::CMultiDelegate2<MultiListBox*, size_t> EventHandle_MultiListPtrSizeT; 00043 00044 class MYGUI_EXPORT MultiListBox : 00045 public Widget, 00046 public BiIndexBase, 00047 public IItemContainer, 00048 public MemberObsolete<MultiListBox> 00049 { 00050 MYGUI_RTTI_DERIVED( MultiListBox ) 00051 00052 public: 00053 MultiListBox(); 00054 00056 virtual void setPosition(const IntPoint& _value); 00058 virtual void setSize(const IntSize& _value); 00060 virtual void setCoord(const IntCoord& _value); 00061 00063 void setPosition(int _left, int _top); 00065 void setSize(int _width, int _height); 00067 void setCoord(int _left, int _top, int _width, int _height); 00068 00069 //------------------------------------------------------------------------------// 00070 // Methods for work with columns (RU:методы для работы со столбцами) 00071 //------------------------------------------------------------------------------// 00072 // манипуляции айтемами 00073 00075 size_t getColumnCount() const; 00076 00083 void insertColumnAt(size_t _column, const UString& _name, int _width = 0, Any _data = Any::Null); 00084 00090 void addColumn(const UString& _name, int _width = 0, Any _data = Any::Null); 00091 00093 void removeColumnAt(size_t _column); 00094 00096 void removeAllColumns(); 00097 00099 void swapColumnsAt(size_t _index1, size_t _index2); 00100 00101 //------------------------------------------------------------------------------// 00102 // манипуляции отображением 00103 00108 void setColumnNameAt(size_t _column, const UString& _name); 00109 00114 void setColumnName(MultiListItem* _item, const UString& _name); 00115 00120 void setColumnWidthAt(size_t _column, int _width); 00121 00126 void setColumnWidth(MultiListItem* _item, int _width); 00127 00129 const UString& getColumnNameAt(size_t _column); 00130 00132 const UString& getColumnName(MultiListItem* _item); 00133 00135 int getColumnWidthAt(size_t _column); 00136 00138 void sortByColumn(size_t _column, bool _backward = false); 00139 00141 size_t getColumnIndex(MultiListItem* _item); 00142 00147 void setColumnResizingPolicy(MultiListItem* _item, ResizingPolicy _value); 00152 void setColumnResizingPolicyAt(size_t _index, ResizingPolicy _value); 00153 00154 //------------------------------------------------------------------------------// 00155 // манипуляции данными 00156 00158 void setColumnDataAt(size_t _index, Any _data); 00159 00161 void clearColumnDataAt(size_t _index); 00162 00164 template <typename ValueType> 00165 ValueType* getColumnDataAt(size_t _index, bool _throw = true) 00166 { 00167 MYGUI_ASSERT_RANGE(_index, mVectorColumnInfo.size(), "MultiListBox::getItemDataAt"); 00168 return mVectorColumnInfo[_index].data.castType<ValueType>(_throw); 00169 } 00170 00171 //------------------------------------------------------------------------------// 00172 // Methods for work with lines (RU:методы для работы со строками) 00178 //------------------------------------------------------------------------------// 00179 // манипуляции айтемами 00180 00182 size_t getItemCount() const; 00183 00185 void insertItemAt(size_t _index, const UString& _name, Any _data = Any::Null); 00186 00188 void addItem(const UString& _name, Any _data = Any::Null); 00189 00191 void removeItemAt(size_t _index); 00192 00194 void removeAllItems(); 00195 00197 void swapItemsAt(size_t _index1, size_t _index2); 00198 00199 00200 //------------------------------------------------------------------------------// 00201 // манипуляции отображением 00202 00204 void setItemNameAt(size_t _index, const UString& _name); 00205 00207 const UString& getItemNameAt(size_t _index); 00208 00209 00210 //------------------------------------------------------------------------------// 00211 // манипуляции выделениями 00212 00214 size_t getIndexSelected() const; 00215 00217 void setIndexSelected(size_t _index); 00218 00220 void clearIndexSelected(); 00221 00222 00223 //------------------------------------------------------------------------------// 00224 // манипуляции данными 00225 00227 void setItemDataAt(size_t _index, Any _data); 00228 00230 void clearItemDataAt(size_t _index); 00231 00233 template <typename ValueType> 00234 ValueType* getItemDataAt(size_t _index, bool _throw = true) 00235 { 00236 return getSubItemDataAt<ValueType>(0, _index, _throw); 00237 } 00238 00239 00240 //------------------------------------------------------------------------------// 00241 // Methods for work with sub lines (RU:методы для работы со саб строками) 00242 //------------------------------------------------------------------------------// 00243 // манипуляции данными 00244 00250 void setSubItemNameAt(size_t _column, size_t _index, const UString& _name); 00251 00253 const UString& getSubItemNameAt(size_t _column, size_t _index); 00254 00256 size_t findSubItemWith(size_t _column, const UString& _name); 00257 00258 //------------------------------------------------------------------------------// 00259 // манипуляции данными 00260 00262 void setSubItemDataAt(size_t _column, size_t _index, Any _data); 00263 00265 void clearSubItemDataAt(size_t _column, size_t _index); 00266 00268 template <typename ValueType> 00269 ValueType* getSubItemDataAt(size_t _column, size_t _index, bool _throw = true) 00270 { 00271 MYGUI_ASSERT_RANGE(_index, mVectorColumnInfo.begin()->list->getItemCount(), "MultiListBox::getSubItemDataAt"); 00272 00273 size_t index = BiIndexBase::convertToBack(_index); 00274 return getSubItemAt(_column)->getItemDataAt<ValueType>(index, _throw); 00275 } 00276 00277 /*events:*/ 00283 EventPair<EventHandle_WidgetSizeT, EventHandle_MultiListPtrSizeT> 00284 eventListSelectAccept; 00285 00291 EventPair<EventHandle_WidgetSizeT, EventHandle_MultiListPtrSizeT> 00292 eventListChangePosition; 00293 00302 EventHandle_MultiListPtrSizeTCUTFStringRefCUTFStringRefBoolRef 00303 requestOperatorLess; 00304 00305 /*internal:*/ 00306 // IItemContainer impl 00307 virtual size_t _getItemCount(); 00308 virtual void _addItem(const MyGUI::UString& _name); 00309 virtual void _removeItemAt(size_t _index); 00310 virtual Widget* _getItemAt(size_t _index); 00311 virtual void _setItemNameAt(size_t _index, const UString& _name); 00312 virtual const UString& _getItemNameAt(size_t _index); 00313 00314 protected: 00315 virtual void initialiseOverride(); 00316 virtual void shutdownOverride(); 00317 00318 virtual void onWidgetCreated(Widget* _widget); 00319 virtual void onWidgetDestroy(Widget* _widget); 00320 00321 private: 00322 void notifyListChangePosition(ListBox* _sender, size_t _position); 00323 void notifyListChangeFocus(ListBox* _sender, size_t _position); 00324 void notifyListChangeScrollPosition(ListBox* _sender, size_t _position); 00325 void notifyButtonClick(Widget* _sender); 00326 void notifyListSelectAccept(ListBox* _sender, size_t _position); 00327 00328 void updateColumns(); 00329 void redrawButtons(); 00330 void updateOnlyEmpty(); 00331 00332 bool compare(ListBox* _list, size_t _left, size_t _right); 00333 void sortList(); 00334 void flipList(); 00335 00336 Widget* getSeparator(size_t _index); 00337 00338 void updateBackSelected(size_t _index); 00339 00340 struct ColumnInfo 00341 { 00342 MultiListItem* item; 00343 ListBox* list; 00344 Button* button; 00345 int width; 00346 int realWidth; 00347 UString name; 00348 Any data; 00349 ResizingPolicy sizeType; 00350 }; 00351 00352 typedef std::vector<ColumnInfo> VectorColumnInfo; 00353 00354 void frameEntered(float _frame); 00355 void frameAdvise(bool _advise); 00356 00357 ListBox* getSubItemAt(size_t _column); 00358 int getButtonHeight() const; 00359 00360 void _wrapItem(MultiListItem* _item); 00361 void _unwrapItem(MultiListItem* _item); 00362 void _swapColumnsAt(size_t _index1, size_t _index2); 00363 00364 int getColumnWidth(size_t _index, int _freeSpace, size_t _countStars, size_t _lastIndexStar, int _starWidth) const; 00365 bool getUpdateByResize(); 00366 int updateWidthColumns(size_t& _countStars, size_t& _lastIndexStar); 00367 00368 private: 00369 int mHeightButton; 00370 int mWidthBar; 00371 std::string mSkinButton; 00372 std::string mSkinList; 00373 Widget* mWidgetEmpty; 00374 00375 VectorColumnInfo mVectorColumnInfo; 00376 00377 VectorWidgetPtr mSeparators; 00378 00379 size_t mLastMouseFocusIndex; 00380 00381 bool mSortUp; 00382 size_t mSortColumnIndex; 00383 00384 int mWidthSeparator; 00385 std::string mSkinSeparator; 00386 int mOffsetButtonSeparator; 00387 00388 size_t mItemSelected; 00389 00390 bool mFrameAdvise; 00391 Widget* mClient; 00392 Widget* mHeaderPlace; 00393 }; 00394 00395 } // namespace MyGUI 00396 00397 #endif // __MYGUI_MULTI_LIST_BOX_H__