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 #include "MyGUI_Precompiled.h" 00024 #include "MyGUI_ListBox.h" 00025 #include "MyGUI_Button.h" 00026 00027 namespace MyGUI 00028 { 00029 00030 ListBox::ListBox() : 00031 mHeightLine(0) 00032 { 00033 requestCreateWidgetItem = MyGUI::newDelegate(this, &ListBox::notifyCreateWidgetItem); 00034 requestDrawItem = MyGUI::newDelegate(this, &ListBox::notifyDrawItem); 00035 } 00036 00037 void ListBox::_initialise(WidgetStyle _style, const IntCoord& _coord, Align _align, ResourceSkin* _info, Widget* _parent, ICroppedRectangle * _croppedParent, IWidgetCreator * _creator, const std::string& _name) 00038 { 00039 Base::_initialise(_style, _coord, _align, _info, _parent, _croppedParent, _creator, _name); 00040 00041 initialiseWidgetSkin(_info); 00042 } 00043 00044 ListBox::~ListBox() 00045 { 00046 shutdownWidgetSkin(); 00047 } 00048 00049 void ListBox::baseChangeWidgetSkin(ResourceSkin* _info) 00050 { 00051 shutdownWidgetSkin(); 00052 Base::baseChangeWidgetSkin(_info); 00053 initialiseWidgetSkin(_info); 00054 } 00055 00056 void ListBox::initialiseWidgetSkin(ResourceSkin* _info) 00057 { 00058 mHeightLine = 20; 00059 mChangeContentByResize = false; 00060 00061 const MapString& properties = _info->getProperties(); 00062 if (!properties.empty()) 00063 { 00064 MapString::const_iterator iter = properties.end(); 00065 iter = properties.find("SkinLine"); 00066 if (iter != properties.end()) mSkinLine = iter->second; 00067 iter = properties.find("HeightLine"); 00068 if (iter != properties.end()) mHeightLine = utility::parseInt(iter->second); 00069 } 00070 00071 _setScrollViewPage(mHeightLine); 00072 } 00073 00074 void ListBox::shutdownWidgetSkin() 00075 { 00076 } 00077 00078 void ListBox::notifyCreateWidgetItem(MyGUI::ListCtrl* _sender, MyGUI::Widget* _item) 00079 { 00080 const MyGUI::IntSize& size = _item->getSize(); 00081 00082 MyGUI::Button* text = _item->createWidget<MyGUI::Button>(mSkinLine, MyGUI::IntCoord(0, 0, size.width, size.height), MyGUI::Align::Stretch); 00083 00084 text->setNeedMouseFocus(false); 00085 00086 _item->setUserData(text); 00087 } 00088 00089 void ListBox::notifyDrawItem(MyGUI::ListCtrl* _sender, MyGUI::Widget* _item, const MyGUI::IBDrawItemInfo& _info, MyGUI::IntCoord& _coord) 00090 { 00091 MyGUI::Button* text = *_item->getUserData<MyGUI::Button*>(); 00092 00093 if (_info.update) 00094 { 00095 text->setCaption(mItemsInfo[_info.index]); 00096 00097 MyGUI::IntSize size = text->getTextSize() + (text->getSize() - text->getTextRegion().size()); 00098 size.height = mHeightLine; 00099 _coord.set(0, 0, size.width, size.height); 00100 } 00101 00102 text->setButtonPressed(_info.select); 00103 text->_setMouseFocus(_info.active); 00104 } 00105 00106 void ListBox::insertItemAt(size_t _index, const UString& _name, Any _data) 00107 { 00108 MYGUI_ASSERT_RANGE_INSERT(_index, mItemsInfo.size(), "ListBox::insertItemAt"); 00109 if (_index == ITEM_NONE) _index = mItemsInfo.size(); 00110 00111 mItemsInfo.insert(mItemsInfo.begin() + _index, _name); 00112 00113 Base::insertItemAt(_index, _data); 00114 } 00115 00116 void ListBox::removeItemAt(size_t _index) 00117 { 00118 MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "ListBox::removeItemAt"); 00119 mItemsInfo.erase(mItemsInfo.begin() + _index); 00120 00121 Base::removeItemAt(_index); 00122 } 00123 00124 void ListBox::removeAllItems() 00125 { 00126 mItemsInfo.clear(); 00127 00128 Base::removeAllItems(); 00129 } 00130 00131 void ListBox::swapItemsAt(size_t _index1, size_t _index2) 00132 { 00133 MYGUI_ASSERT_RANGE(_index1, mItemsInfo.size(), "ListBox::swapItemsAt"); 00134 MYGUI_ASSERT_RANGE(_index2, mItemsInfo.size(), "ListBox::swapItemsAt"); 00135 00136 if (_index1 == _index2) return; 00137 00138 std::swap(mItemsInfo[_index1], mItemsInfo[_index2]); 00139 00140 Base::redrawItemAt(_index1); 00141 Base::redrawItemAt(_index2); 00142 } 00143 00144 size_t ListBox::findItemIndexWith(const UString& _name) 00145 { 00146 for (size_t pos=0; pos<mItemsInfo.size(); pos++) 00147 { 00148 if (mItemsInfo[pos] == _name) return pos; 00149 } 00150 return ITEM_NONE; 00151 } 00152 00153 void ListBox::setItemNameAt(size_t _index, const UString& _name) 00154 { 00155 MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "ListBox::setItemNameAt"); 00156 00157 Base::redrawItemAt(_index); 00158 } 00159 00160 const UString& ListBox::getItemNameAt(size_t _index) 00161 { 00162 MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "ListBox::getItemNameAt"); 00163 00164 return mItemsInfo[_index]; 00165 } 00166 00167 void ListBox::beginToItemAt(size_t _index) 00168 { 00169 MYGUI_ASSERT_RANGE(_index, mItemsInfo.size(), "ListBox::beginToItemAt"); 00170 00171 //FIXME 00172 } 00173 00174 } // namespace MyGUI