MyGUI
3.0.1
|
00001 00007 /* 00008 This file is part of MyGUI. 00009 00010 MyGUI is free software: you can redistribute it and/or modify 00011 it under the terms of the GNU Lesser General Public License as published by 00012 the Free Software Foundation, either version 3 of the License, or 00013 (at your option) any later version. 00014 00015 MyGUI is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU Lesser General Public License for more details. 00019 00020 You should have received a copy of the GNU Lesser General Public License 00021 along with MyGUI. If not, see <http://www.gnu.org/licenses/>. 00022 */ 00023 #ifndef __MYGUI_COMBO_BOX_H__ 00024 #define __MYGUI_COMBO_BOX_H__ 00025 00026 #include "MyGUI_Prerequest.h" 00027 #include "MyGUI_Edit.h" 00028 #include "MyGUI_List.h" 00029 #include "MyGUI_Any.h" 00030 #include "MyGUI_EventPair.h" 00031 #include "MyGUI_ControllerFadeAlpha.h" 00032 00033 namespace MyGUI 00034 { 00035 00036 typedef delegates::CDelegate2<ComboBox*, size_t> EventHandle_ComboBoxPtrSizeT; 00037 00038 class MYGUI_EXPORT ComboBox : 00039 public Edit 00040 { 00041 MYGUI_RTTI_DERIVED( ComboBox ) 00042 00043 public: 00044 ComboBox(); 00045 00046 //------------------------------------------------------------------------------// 00047 // манипуляции айтемами 00048 00050 size_t getItemCount() const { return mList->getItemCount(); } 00051 00053 void insertItemAt(size_t _index, const UString& _name, Any _data = Any::Null); 00054 00056 void addItem(const UString& _name, Any _data = Any::Null) { return insertItemAt(ITEM_NONE, _name, _data); } 00057 00059 void removeItemAt(size_t _index); 00060 00062 void removeAllItems(); 00063 00064 00066 size_t findItemIndexWith(const UString& _name); 00067 00068 00069 //------------------------------------------------------------------------------// 00070 // манипуляции выделениями 00071 00073 size_t getIndexSelected() { return mItemIndex; } 00074 00076 void setIndexSelected(size_t _index); 00077 00079 void clearIndexSelected() { setIndexSelected(ITEM_NONE); } 00080 00081 00082 //------------------------------------------------------------------------------// 00083 // манипуляции данными 00084 00086 void setItemDataAt(size_t _index, Any _data); 00087 00089 void clearItemDataAt(size_t _index) { setItemDataAt(_index, Any::Null); } 00090 00092 template <typename ValueType> 00093 ValueType * getItemDataAt(size_t _index, bool _throw = true) 00094 { 00095 return mList->getItemDataAt<ValueType>(_index, _throw); 00096 } 00097 00098 00099 //------------------------------------------------------------------------------// 00100 // манипуляции отображением 00101 00103 void setItemNameAt(size_t _index, const UString& _name); 00104 00106 const UString& getItemNameAt(size_t _index) { return mList->getItemNameAt(_index); } 00107 00108 00109 //------------------------------------------------------------------------------// 00110 // манипуляции выдимостью 00111 00113 void beginToItemAt(size_t _index) { mList->beginToItemAt(_index); } 00114 00116 void beginToItemFirst() { if (getItemCount()) beginToItemAt(0); } 00117 00119 void beginToItemLast() { if (getItemCount()) beginToItemAt(getItemCount() - 1); } 00120 00122 void beginToItemSelected() { if (getIndexSelected() != ITEM_NONE) beginToItemAt(getIndexSelected()); } 00123 00124 00125 //------------------------------------------------------------------------------------// 00126 // методы для управления отображением 00127 00129 void setComboModeDrop(bool _value); 00131 bool getComboModeDrop() { return mModeDrop; } 00132 00134 void setSmoothShow(bool _value) { mShowSmooth = _value; } 00136 bool getSmoothShow() { return mShowSmooth; } 00137 00139 void setMaxListHeight(int _value) { mMaxHeight = _value; } 00141 int getMaxListHeight() { return mMaxHeight; } 00142 00144 virtual void setProperty(const std::string& _key, const std::string& _value); 00145 00146 /*event:*/ 00152 EventPair<EventHandle_WidgetVoid, EventHandle_ComboBoxPtrSizeT> eventComboAccept; 00153 00159 EventPair<EventHandle_WidgetSizeT, EventHandle_ComboBoxPtrSizeT> eventComboChangePosition; 00160 00161 00162 /*internal:*/ 00163 virtual void _initialise(WidgetStyle _style, const IntCoord& _coord, Align _align, ResourceSkin* _info, Widget* _parent, ICroppedRectangle * _croppedParent, IWidgetCreator * _creator, const std::string& _name); 00164 00165 /*obsolete:*/ 00166 #ifndef MYGUI_DONT_USE_OBSOLETE 00167 00168 MYGUI_OBSOLETE("use : size_t ComboBox::getIndexSelected()") 00169 size_t getItemIndexSelected() { return getIndexSelected(); } 00170 MYGUI_OBSOLETE("use : void ComboBox::setIndexSelected(size_t _index)") 00171 void setItemSelectedAt(size_t _index) { setIndexSelected(_index); } 00172 MYGUI_OBSOLETE("use : void ComboBox::clearIndexSelected()") 00173 void clearItemSelected() { clearIndexSelected(); } 00174 00175 MYGUI_OBSOLETE("use : void ComboBox::insertItemAt(size_t _index, const UString& _name)") 00176 void insertItem(size_t _index, const UString& _name) { insertItemAt(_index, _name); } 00177 MYGUI_OBSOLETE("use : void ComboBox::setItemNameAt(size_t _index, const UString& _name)") 00178 void setItem(size_t _index, const UString& _item) { setItemNameAt(_index, _item); } 00179 MYGUI_OBSOLETE("use : const UString& ComboBox::getItemNameAt(size_t _index)") 00180 const UString& getItem(size_t _index) { return getItemNameAt(_index); } 00181 MYGUI_OBSOLETE("use : void ComboBox::removeItemAt(size_t _index)") 00182 void deleteItem(size_t _index) { removeItemAt(_index); } 00183 MYGUI_OBSOLETE("use : void ComboBox::removeAllItems()") 00184 void deleteAllItems() { removeAllItems(); } 00185 MYGUI_OBSOLETE("use : size_t ComboBox::getIndexSelected()") 00186 size_t getItemSelect() { return getIndexSelected(); } 00187 MYGUI_OBSOLETE("use : void void ComboBox::clearIndexSelected()") 00188 void resetItemSelect() { clearIndexSelected(); } 00189 MYGUI_OBSOLETE("use : void ComboBox::setIndexSelected(size_t _index)") 00190 void setItemSelect(size_t _index) { setIndexSelected(_index); } 00191 00192 #endif // MYGUI_DONT_USE_OBSOLETE 00193 00194 protected: 00195 virtual ~ComboBox(); 00196 00197 virtual void onKeyButtonPressed(KeyCode _key, Char _char); 00198 00199 virtual void baseChangeWidgetSkin(ResourceSkin* _info); 00200 00201 private: 00202 void notifyButtonPressed(Widget* _sender, int _left, int _top, MouseButton _id); 00203 void notifyListLostFocus(Widget* _sender, MyGUI::Widget* _new); 00204 void notifyListSelectAccept(List* _widget, size_t _position); 00205 void notifyListMouseItemActivate(List* _widget, size_t _position); 00206 void notifyListChangePosition(List* _widget, size_t _position); 00207 void notifyMouseWheel(Widget* _sender, int _rel); 00208 void notifyMousePressed(Widget* _sender, int _left, int _top, MouseButton _id); 00209 void notifyEditTextChange(Edit* _sender); 00210 00211 void showList(); 00212 void hideList(); 00213 00214 void initialiseWidgetSkin(ResourceSkin* _info); 00215 void shutdownWidgetSkin(); 00216 00217 void actionWidgetHide(Widget* _widget); 00218 00219 ControllerFadeAlpha* createControllerFadeAlpha(float _alpha, float _coef, bool _enable); 00220 00221 private: 00222 Button* mButton; 00223 List* mList; 00224 00225 bool mListShow; 00226 int mMaxHeight; 00227 size_t mItemIndex; 00228 bool mModeDrop; 00229 bool mDropMouse; 00230 bool mShowSmooth; 00231 bool mManualList; 00232 00233 }; 00234 00235 } // namespace MyGUI 00236 00237 #endif // __MYGUI_COMBO_BOX_H__