MyGUI  3.2.0
MyGUI_ListBox.h
Go to the documentation of this file.
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_LIST_BOX_H__
00023 #define __MYGUI_LIST_BOX_H__
00024 
00025 #include "MyGUI_Prerequest.h"
00026 #include "MyGUI_Button.h"
00027 #include "MyGUI_Any.h"
00028 #include "MyGUI_EventPair.h"
00029 #include "MyGUI_IItem.h"
00030 #include "MyGUI_IItemContainer.h"
00031 
00032 namespace MyGUI
00033 {
00034 
00035     typedef delegates::CMultiDelegate2<ListBox*, size_t> EventHandle_ListPtrSizeT;
00036 
00037     class MYGUI_EXPORT ListBox :
00038         public Widget,
00039         public IItemContainer,
00040         public MemberObsolete<ListBox>
00041     {
00042         MYGUI_RTTI_DERIVED( ListBox )
00043 
00044     public:
00045         ListBox();
00046 
00047         //------------------------------------------------------------------------------//
00048         // манипуляции айтемами
00049 
00054 
00055         size_t getItemCount() const;
00056 
00058         void insertItemAt(size_t _index, const UString& _name, Any _data = Any::Null);
00059 
00061         void addItem(const UString& _name, Any _data = Any::Null);
00062 
00064         void removeItemAt(size_t _index);
00065 
00067         void removeAllItems();
00068 
00070         void swapItemsAt(size_t _index1, size_t _index2);
00071 
00072 
00074         size_t findItemIndexWith(const UString& _name);
00076 
00077         //------------------------------------------------------------------------------//
00078         // манипуляции выделениями
00079 
00085         size_t getIndexSelected() const;
00086 
00088         void setIndexSelected(size_t _index);
00089 
00091         void clearIndexSelected();
00093 
00094         //------------------------------------------------------------------------------//
00095         // манипуляции данными
00096 
00101 
00102         void setItemDataAt(size_t _index, Any _data);
00103 
00105         void clearItemDataAt(size_t _index);
00106 
00108         template <typename ValueType>
00109         ValueType* getItemDataAt(size_t _index, bool _throw = true)
00110         {
00111             MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "ListBox::getItemDataAt");
00112             return mItemsInfo[_index].second.castType<ValueType>(_throw);
00113         }
00115 
00116         //------------------------------------------------------------------------------//
00117         // манипуляции отображением
00118 
00120         void setItemNameAt(size_t _index, const UString& _name);
00121 
00123         const UString& getItemNameAt(size_t _index);
00124 
00125 
00126         //------------------------------------------------------------------------------//
00127         // манипуляции выдимостью
00128 
00133 
00134         void beginToItemAt(size_t _index);
00135 
00137         void beginToItemFirst();
00138 
00140         void beginToItemLast();
00141 
00143         void beginToItemSelected();
00144 
00145         //------------------------------------------------------------------------------//
00146 
00147         // видим ли мы элемент, полностью или нет
00156         bool isItemVisibleAt(size_t _index, bool _fill = true);
00158         bool isItemSelectedVisible(bool _fill = true);
00159 
00160 
00162         void setScrollVisible(bool _visible);
00164         void setScrollPosition(size_t _position);
00166 
00167         //------------------------------------------------------------------------------------//
00168 
00173 
00174         virtual void setPosition(const IntPoint& _value);
00176         virtual void setSize(const IntSize& _value);
00178         virtual void setCoord(const IntCoord& _value);
00179 
00181         void setPosition(int _left, int _top);
00183         void setSize(int _width, int _height);
00185         void setCoord(int _left, int _top, int _width, int _height);
00187 
00188         // возвращает максимальную высоту вмещающую все строки и родительский бордюр
00190         int getOptimalHeight();
00191 
00192     /*events:*/
00198         EventPair<EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT>
00199             eventListSelectAccept;
00200 
00206         EventPair<EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT>
00207             eventListChangePosition;
00208 
00214         EventPair<EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT>
00215             eventListMouseItemActivate;
00216 
00222         EventPair<EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT>
00223             eventListMouseItemFocus;
00224 
00230         EventPair<EventHandle_WidgetSizeT, EventHandle_ListPtrSizeT>
00231             eventListChangeScroll;
00232 
00233     /*internal:*/
00238         // дебажная проверка на правильность выравнивания списка
00239         void _checkAlign();
00240 
00241         // вспомогательные методы для составных списков
00242         void _setItemFocus(size_t _position, bool _focus);
00243         void _sendEventChangeScroll(size_t _position);
00244 
00245         // IItemContainer impl
00246         virtual size_t _getItemCount();
00247         virtual void _addItem(const MyGUI::UString& _name);
00248         virtual void _removeItemAt(size_t _index);
00249         virtual void _setItemNameAt(size_t _index, const UString& _name);
00250         virtual const UString& _getItemNameAt(size_t _index);
00251 
00252         virtual void _resetContainer(bool _update);
00254 
00255     protected:
00256         virtual void initialiseOverride();
00257         virtual void shutdownOverride();
00258 
00259         void onMouseWheel(int _rel);
00260         void onKeyButtonPressed(KeyCode _key, Char _char);
00261 
00262         void notifyScrollChangePosition(ScrollBar* _sender, size_t _rel);
00263         void notifyMousePressed(Widget* _sender, int _left, int _top, MouseButton _id);
00264         void notifyMouseDoubleClick(Widget* _sender);
00265         void notifyMouseWheel(Widget* _sender, int _rel);
00266         void notifyMouseSetFocus(Widget* _sender, Widget* _old);
00267         void notifyMouseLostFocus(Widget* _sender, Widget* _new);
00268 
00269         void updateScroll();
00270         void updateLine(bool _reset = false);
00271         void _setScrollView(size_t _position);
00272 
00273         // перерисовывает от индекса до низа
00274         void _redrawItemRange(size_t _start = 0);
00275 
00276         // перерисовывает индекс
00277         void _redrawItem(size_t _index);
00278 
00279         // ищет и выделяет елемент
00280         void _selectIndex(size_t _index, bool _select);
00281 
00282         // метод для запроса номера айтема и контейнера
00283         virtual size_t _getItemIndex(Widget* _item);
00284 
00285         virtual void setPropertyOverride(const std::string& _key, const std::string& _value);
00286 
00287     private:
00288         void _checkMapping(const std::string& _owner);
00289 
00290         Widget* _getClientWidget();
00291 
00292     private:
00293         std::string mSkinLine;
00294         ScrollBar* mWidgetScroll;
00295 
00296         // наши дети в строках
00297         typedef std::vector<Button*> VectorButton;
00298         VectorButton mWidgetLines;
00299 
00300         int mHeightLine; // высота одной строки
00301         int mTopIndex; // индекс самого верхнего элемента
00302         int mOffsetTop; // текущее смещение
00303         int mRangeIndex; // размерность скрола
00304         size_t mLastRedrawLine; // последняя перерисованная линия
00305 
00306         size_t mIndexSelect; // текущий выделенный элемент или ITEM_NONE
00307         size_t mLineActive; // текущий виджет над которым мыша
00308 
00309         typedef std::pair<UString, Any> PairItem;
00310         typedef std::vector<PairItem> VectorItemInfo;
00311         VectorItemInfo mItemsInfo;
00312 
00313         // имеем ли мы фокус ввода
00314         bool mNeedVisibleScroll;
00315 
00316         IntSize mOldSize;
00317 
00318         Widget* mClient;
00319     };
00320 
00321 } // namespace MyGUI
00322 
00323 #endif // __MYGUI_LIST_BOX_H__