Crazy Eddies GUI System
0.7.6
|
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 * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team 00010 * 00011 * Permission is hereby granted, free of charge, to any person obtaining 00012 * a copy of this software and associated documentation files (the 00013 * "Software"), to deal in the Software without restriction, including 00014 * without limitation the rights to use, copy, modify, merge, publish, 00015 * distribute, sublicense, and/or sell copies of the Software, and to 00016 * permit persons to whom the Software is furnished to do so, subject to 00017 * the following conditions: 00018 * 00019 * The above copyright notice and this permission notice shall be 00020 * included in all copies or substantial portions of the Software. 00021 * 00022 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00023 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00024 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00025 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 00026 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00027 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00028 * OTHER DEALINGS IN THE SOFTWARE. 00029 ***************************************************************************/ 00030 #ifndef _CEGUIItemListBase_h_ 00031 #define _CEGUIItemListBase_h_ 00032 00033 #include "../CEGUIBase.h" 00034 #include "../CEGUIWindow.h" 00035 #include "CEGUIItemListBaseProperties.h" 00036 #include "CEGUIItemEntry.h" 00037 00038 #include <vector> 00039 00040 00041 #if defined(_MSC_VER) 00042 # pragma warning(push) 00043 # pragma warning(disable : 4251) 00044 #endif 00045 00046 00047 // Start of CEGUI namespace section 00048 namespace CEGUI 00049 { 00050 00055 class CEGUIEXPORT ItemListBaseWindowRenderer : public WindowRenderer 00056 { 00057 public: 00062 ItemListBaseWindowRenderer(const String& name); 00063 00073 virtual Rect getItemRenderArea(void) const = 0; 00074 }; 00075 00080 class CEGUIEXPORT ItemListBase : public Window 00081 { 00082 public: 00083 static const String EventNamespace; 00084 00089 enum SortMode 00090 { 00091 Ascending, 00092 Descending, 00093 UserSort 00094 }; 00095 00097 typedef bool (*SortCallback)(const ItemEntry* a, const ItemEntry* b); 00098 00099 /************************************************************************* 00100 Constants 00101 *************************************************************************/ 00102 // event names 00108 static const String EventListContentsChanged; 00114 static const String EventSortEnabledChanged; 00120 static const String EventSortModeChanged; 00121 00122 /************************************************************************* 00123 Accessor Methods 00124 *************************************************************************/ 00132 size_t getItemCount(void) const {return d_listItems.size();} 00133 00134 00147 ItemEntry* getItemFromIndex(size_t index) const; 00148 00149 00162 size_t getItemIndex(const ItemEntry* item) const; 00163 00164 00182 ItemEntry* findItemWithText(const String& text, const ItemEntry* start_item); 00183 00184 00192 bool isItemInList(const ItemEntry* item) const; 00193 00194 00202 bool isAutoResizeEnabled() const {return d_autoResize;} 00203 00204 00209 bool isSortEnabled(void) const {return d_sortEnabled;} 00210 00211 00216 SortMode getSortMode(void) const {return d_sortMode;} 00217 00218 00223 SortCallback getSortCallback(void) const {return d_sortCallback;} 00224 00225 /************************************************************************* 00226 Manipulator Methods 00227 *************************************************************************/ 00238 virtual void initialiseComponents(void); 00239 00240 00247 void resetList(void); 00248 00249 00261 void addItem(ItemEntry* item); 00262 00263 00283 void insertItem(ItemEntry* item, const ItemEntry* position); 00284 00285 00297 void removeItem(ItemEntry* item); 00298 00299 00315 void handleUpdatedItemData(bool resort=false); 00316 00317 00328 void setAutoResizeEnabled(bool setting); 00329 00330 00340 virtual void sizeToContent(void) {sizeToContent_impl();} 00341 00342 00348 virtual void endInitialisation(void); 00349 00350 00361 virtual void performChildWindowLayout(void); 00362 00363 00373 Rect getItemRenderArea(void) const; 00374 00383 Window* getContentPane(void) const {return d_pane;} 00384 00390 virtual void notifyItemClicked(ItemEntry*) {} 00391 00397 virtual void notifyItemSelectState(ItemEntry*, bool) {} 00398 00403 void setSortEnabled(bool setting); 00404 00411 void setSortMode(SortMode mode); 00412 00420 void setSortCallback(SortCallback cb); 00421 00433 void sortList(bool relayout=true); 00434 00435 /************************************************************************* 00436 Construction and Destruction 00437 *************************************************************************/ 00442 ItemListBase(const String& type, const String& name); 00443 00444 00449 virtual ~ItemListBase(void); 00450 00451 00452 protected: 00453 /************************************************************************* 00454 Abstract Implementation Functions (must be provided by derived class) 00455 *************************************************************************/ 00465 virtual void sizeToContent_impl(void); 00466 00467 00475 virtual Size getContentSize() const = 0; 00476 00477 00487 //virtual Rect getItemRenderArea_impl(void) const = 0; 00488 00489 00497 virtual void layoutItemWidgets() = 0; 00498 00499 00500 /************************************************************************* 00501 Implementation Functions 00502 *************************************************************************/ 00514 bool resetList_impl(void); 00515 00526 virtual bool testClassName_impl(const String& class_name) const 00527 { 00528 if (class_name=="ItemListBase") return true; 00529 return Window::testClassName_impl(class_name); 00530 } 00531 00532 // validate window renderer 00533 virtual bool validateWindowRenderer(const String& name) const 00534 { 00535 return (name == EventNamespace); 00536 } 00537 00542 SortCallback getRealSortCallback(void) const; 00543 00544 /************************************************************************* 00545 New event handlers 00546 *************************************************************************/ 00551 virtual void onListContentsChanged(WindowEventArgs& e); 00552 00557 virtual void onSortEnabledChanged(WindowEventArgs& e); 00558 00563 virtual void onSortModeChanged(WindowEventArgs& e); 00564 00565 /************************************************************************* 00566 Overridden Event handlers 00567 *************************************************************************/ 00568 virtual void onParentSized(WindowEventArgs& e); 00569 //virtual void onChildRemoved(WindowEventArgs& e); 00570 //virtual void onDestructionStarted(WindowEventArgs& e); 00571 00572 00573 /************************************************************************* 00574 Implementation Data 00575 *************************************************************************/ 00576 typedef std::vector<ItemEntry*> ItemEntryList; 00577 ItemEntryList d_listItems; 00578 00580 bool d_autoResize; 00581 00583 Window* d_pane; 00584 00586 bool d_sortEnabled; 00588 SortMode d_sortMode; 00590 SortCallback d_sortCallback; 00592 bool d_resort; 00593 00594 private: 00595 /************************************************************************* 00596 Static Properties for this class 00597 *************************************************************************/ 00598 static ItemListBaseProperties::AutoResizeEnabled d_autoResizeEnabledProperty; 00599 static ItemListBaseProperties::SortEnabled d_sortEnabledProperty; 00600 static ItemListBaseProperties::SortMode d_sortModeProperty; 00601 00602 /************************************************************************* 00603 Private methods 00604 *************************************************************************/ 00605 void addItemListBaseProperties(void); 00606 00607 00612 virtual void addChild_impl(Window* wnd); 00613 00619 bool handle_PaneChildRemoved(const EventArgs& e); 00620 }; 00621 00622 } // End of CEGUI namespace section 00623 00624 00625 #if defined(_MSC_VER) 00626 # pragma warning(pop) 00627 #endif 00628 00629 #endif // end of guard _CEGUIItemListBase_h_