00001 /************************************************************************ 00002 filename: CEGUIItemListBase.h 00003 created: 31/3/2005 00004 author: Tomas Lindquist Olsen (based on original Listbox code by Paul D Turner) 00005 00006 purpose: Interface to base class for ItemListBase widgets 00007 *************************************************************************/ 00008 /************************************************************************* 00009 Crazy Eddie's GUI System (http://www.cegui.org.uk) 00010 Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk) 00011 00012 This library is free software; you can redistribute it and/or 00013 modify it under the terms of the GNU Lesser General Public 00014 License as published by the Free Software Foundation; either 00015 version 2.1 of the License, or (at your option) any later version. 00016 00017 This library is distributed in the hope that it will be useful, 00018 but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00020 Lesser General Public License for more details. 00021 00022 You should have received a copy of the GNU Lesser General Public 00023 License along with this library; if not, write to the Free Software 00024 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00025 *************************************************************************/ 00026 #ifndef _CEGUIItemListBase_h_ 00027 #define _CEGUIItemListBase_h_ 00028 00029 #include "CEGUIBase.h" 00030 #include "CEGUIWindow.h" 00031 #include "elements/CEGUIItemListBaseProperties.h" 00032 #include "elements/CEGUIItemEntry.h" 00033 00034 #include <vector> 00035 00036 00037 #if defined(_MSC_VER) 00038 # pragma warning(push) 00039 # pragma warning(disable : 4251) 00040 #endif 00041 00042 00043 // Start of CEGUI namespace section 00044 namespace CEGUI 00045 { 00046 00051 class CEGUIEXPORT ItemListBase : public Window 00052 { 00053 public: 00054 static const String EventNamespace; 00055 00056 00057 /************************************************************************* 00058 Constants 00059 *************************************************************************/ 00060 // event names 00061 static const String EventListContentsChanged; 00062 00063 00064 /************************************************************************* 00065 Accessor Methods 00066 *************************************************************************/ 00074 size_t getItemCount(void) const {return d_listItems.size();} 00075 00076 00089 ItemEntry* getItemFromIndex(size_t index) const; 00090 00091 00104 size_t getItemIndex(const ItemEntry* item) const; 00105 00106 00124 ItemEntry* findItemWithText(const String& text, const ItemEntry* start_item); 00125 00126 00134 bool isItemInList(const ItemEntry* item) const; 00135 00136 00144 bool isAutoResizeEnabled() const {return d_autoResize;} 00145 00146 00147 /************************************************************************* 00148 Manipulator Methods 00149 *************************************************************************/ 00160 virtual void initialise(void); 00161 00162 00169 void resetList(void); 00170 00171 00183 void addItem(ItemEntry* item); 00184 00185 00203 void insertItem(ItemEntry* item, const ItemEntry* position); 00204 00205 00217 void removeItem(ItemEntry* item); 00218 00219 00232 void handleUpdatedItemData(void); 00233 00234 00245 void setAutoResizeEnabled(bool setting); 00246 00247 00257 virtual void sizeToContent(void) {sizeToContent_impl();} 00258 00259 00260 /************************************************************************* 00261 Construction and Destruction 00262 *************************************************************************/ 00267 ItemListBase(const String& type, const String& name); 00268 00269 00274 virtual ~ItemListBase(void); 00275 00276 00277 protected: 00278 /************************************************************************* 00279 Abstract Implementation Functions (must be provided by derived class) 00280 *************************************************************************/ 00290 virtual void sizeToContent_impl(void) = 0; 00291 00292 00300 virtual Size getContentSize() = 0; 00301 00302 00312 virtual Rect getItemRenderArea(void) const = 0; 00313 00314 00322 virtual void layoutItemWidgets() = 0; 00323 00324 00332 virtual void populateRenderCache() = 0; 00333 00334 00335 /************************************************************************* 00336 Implementation Functions 00337 *************************************************************************/ 00342 void addItemListBaseEvents(void); 00343 00344 00356 bool resetList_impl(void); 00357 00358 00369 virtual bool testClassName_impl(const String& class_name) const 00370 { 00371 if (class_name==(const utf8*)"ItemListBase") return true; 00372 return Window::testClassName_impl(class_name); 00373 } 00374 00375 /************************************************************************* 00376 New event handlers 00377 *************************************************************************/ 00382 virtual void onListContentsChanged(WindowEventArgs& e); 00383 00384 00385 /************************************************************************* 00386 Overridden Event handlers 00387 *************************************************************************/ 00388 virtual void onSized(WindowEventArgs& e); 00389 00390 00391 /************************************************************************* 00392 Implementation Data 00393 *************************************************************************/ 00394 typedef std::vector<ItemEntry*> ItemEntryList; 00395 ItemEntryList d_listItems; 00396 00397 // boolean telling if this ItemListBase widget should automatically resize to fit its content. 00398 bool d_autoResize; 00399 00400 private: 00401 /************************************************************************* 00402 Static Properties for this class 00403 *************************************************************************/ 00404 static ItemListBaseProperties::AutoResizeEnabled d_autoResizeEnabledProperty; 00405 00406 00407 /************************************************************************* 00408 Private methods 00409 *************************************************************************/ 00410 void addItemListBaseProperties(void); 00411 00412 00417 virtual void addChild_impl(Window* wnd); 00418 }; 00419 00420 } // End of CEGUI namespace section 00421 00422 00423 #if defined(_MSC_VER) 00424 # pragma warning(pop) 00425 #endif 00426 00427 #endif // end of guard _CEGUIItemListBase_h_