Crazy Eddie's GUI System
0.8.4
|
00001 /*********************************************************************** 00002 created: 31/3/2005 00003 author: Tomas Lindquist Olsen (based on original Listbox code by Paul D Turner) 00004 00005 purpose: Interface to base class for ItemListBase widgets 00006 *************************************************************************/ 00007 /*************************************************************************** 00008 * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team 00009 * 00010 * Permission is hereby granted, free of charge, to any person obtaining 00011 * a copy of this software and associated documentation files (the 00012 * "Software"), to deal in the Software without restriction, including 00013 * without limitation the rights to use, copy, modify, merge, publish, 00014 * distribute, sublicense, and/or sell copies of the Software, and to 00015 * permit persons to whom the Software is furnished to do so, subject to 00016 * the following conditions: 00017 * 00018 * The above copyright notice and this permission notice shall be 00019 * included in all copies or substantial portions of the Software. 00020 * 00021 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00022 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00023 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00024 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 00025 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00026 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00027 * OTHER DEALINGS IN THE SOFTWARE. 00028 ***************************************************************************/ 00029 #ifndef _CEGUIItemListBase_h_ 00030 #define _CEGUIItemListBase_h_ 00031 00032 #include "../Base.h" 00033 #include "../Window.h" 00034 #include "./ItemEntry.h" 00035 00036 #include <vector> 00037 00038 00039 #if defined(_MSC_VER) 00040 # pragma warning(push) 00041 # pragma warning(disable : 4251) 00042 #endif 00043 00044 00045 // Start of CEGUI namespace section 00046 namespace CEGUI 00047 { 00048 00053 class CEGUIEXPORT ItemListBaseWindowRenderer : public WindowRenderer 00054 { 00055 public: 00060 ItemListBaseWindowRenderer(const String& name); 00061 00071 virtual Rectf getItemRenderArea(void) const = 0; 00072 }; 00073 00078 class CEGUIEXPORT ItemListBase : public Window 00079 { 00080 public: 00081 static const String EventNamespace; 00082 00087 enum SortMode 00088 { 00089 Ascending, 00090 Descending, 00091 UserSort 00092 }; 00093 00095 typedef bool (*SortCallback)(const ItemEntry* a, const ItemEntry* b); 00096 00097 /************************************************************************* 00098 Constants 00099 *************************************************************************/ 00100 // event names 00106 static const String EventListContentsChanged; 00112 static const String EventSortEnabledChanged; 00118 static const String EventSortModeChanged; 00119 00120 /************************************************************************* 00121 Accessor Methods 00122 *************************************************************************/ 00130 size_t getItemCount(void) const {return d_listItems.size();} 00131 00132 00145 ItemEntry* getItemFromIndex(size_t index) const; 00146 00147 00160 size_t getItemIndex(const ItemEntry* item) const; 00161 00162 00180 ItemEntry* findItemWithText(const String& text, const ItemEntry* start_item); 00181 00182 00190 bool isItemInList(const ItemEntry* item) const; 00191 00192 00200 bool isAutoResizeEnabled() const {return d_autoResize;} 00201 00202 00207 bool isSortEnabled(void) const {return d_sortEnabled;} 00208 00209 00214 SortMode getSortMode(void) const {return d_sortMode;} 00215 00216 00221 SortCallback getSortCallback(void) const {return d_sortCallback;} 00222 00223 /************************************************************************* 00224 Manipulator Methods 00225 *************************************************************************/ 00236 virtual void initialiseComponents(void); 00237 00238 00245 void resetList(void); 00246 00247 00259 void addItem(ItemEntry* item); 00260 00261 00281 void insertItem(ItemEntry* item, const ItemEntry* position); 00282 00283 00295 void removeItem(ItemEntry* item); 00296 00297 00313 void handleUpdatedItemData(bool resort=false); 00314 00315 00326 void setAutoResizeEnabled(bool setting); 00327 00328 00338 virtual void sizeToContent(void) {sizeToContent_impl();} 00339 00340 00346 virtual void endInitialisation(void); 00347 00348 00350 void performChildWindowLayout(bool nonclient_sized_hint = false, 00351 bool client_sized_hint = false); 00352 00353 00363 Rectf getItemRenderArea(void) const; 00364 00373 Window* getContentPane(void) const {return d_pane;} 00374 00380 virtual void notifyItemClicked(ItemEntry*) {} 00381 00387 virtual void notifyItemSelectState(ItemEntry*, bool) {} 00388 00393 void setSortEnabled(bool setting); 00394 00401 void setSortMode(SortMode mode); 00402 00410 void setSortCallback(SortCallback cb); 00411 00423 void sortList(bool relayout=true); 00424 00425 /************************************************************************* 00426 Construction and Destruction 00427 *************************************************************************/ 00432 ItemListBase(const String& type, const String& name); 00433 00434 00439 virtual ~ItemListBase(void); 00440 00441 00442 protected: 00443 /************************************************************************* 00444 Abstract Implementation Functions (must be provided by derived class) 00445 *************************************************************************/ 00455 virtual void sizeToContent_impl(void); 00456 00457 00465 virtual Sizef getContentSize() const = 0; 00466 00467 00477 //virtual Rect getItemRenderArea_impl(void) const = 0; 00478 00479 00487 virtual void layoutItemWidgets() = 0; 00488 00489 00490 /************************************************************************* 00491 Implementation Functions 00492 *************************************************************************/ 00504 bool resetList_impl(void); 00505 00506 // validate window renderer 00507 virtual bool validateWindowRenderer(const WindowRenderer* renderer) const; 00508 00513 SortCallback getRealSortCallback(void) const; 00514 00515 /************************************************************************* 00516 New event handlers 00517 *************************************************************************/ 00522 virtual void onListContentsChanged(WindowEventArgs& e); 00523 00528 virtual void onSortEnabledChanged(WindowEventArgs& e); 00529 00534 virtual void onSortModeChanged(WindowEventArgs& e); 00535 00536 /************************************************************************* 00537 Overridden Event handlers 00538 *************************************************************************/ 00539 virtual void onParentSized(ElementEventArgs& e); 00540 //virtual void onChildRemoved(WindowEventArgs& e); 00541 //virtual void onDestructionStarted(WindowEventArgs& e); 00542 00543 00553 virtual bool handle_PaneChildRemoved(const EventArgs& e); 00554 00555 /************************************************************************* 00556 Implementation Data 00557 *************************************************************************/ 00558 typedef std::vector<ItemEntry* 00559 CEGUI_VECTOR_ALLOC(ItemEntry*)> ItemEntryList; 00560 ItemEntryList d_listItems; 00561 00563 bool d_autoResize; 00564 00566 Window* d_pane; 00567 00569 bool d_sortEnabled; 00571 SortMode d_sortMode; 00573 SortCallback d_sortCallback; 00575 bool d_resort; 00576 00577 private: 00578 /************************************************************************* 00579 Private methods 00580 *************************************************************************/ 00581 void addItemListBaseProperties(void); 00582 00583 00587 virtual void addChild_impl(Element* element); 00588 }; 00589 00590 00591 template<> 00592 class PropertyHelper<ItemListBase::SortMode> 00593 { 00594 public: 00595 typedef ItemListBase::SortMode return_type; 00596 typedef return_type safe_method_return_type; 00597 typedef ItemListBase::SortMode pass_type; 00598 typedef String string_return_type; 00599 00600 static const String& getDataTypeName() 00601 { 00602 static String type("SortMode"); 00603 00604 return type; 00605 } 00606 00607 static return_type fromString(const String& str) 00608 { 00609 if (str == "Ascending") 00610 { 00611 return ItemListBase::Ascending; 00612 } 00613 else if (str == "Descending") 00614 { 00615 return ItemListBase::Descending; 00616 } 00617 else 00618 { 00619 return ItemListBase::UserSort; 00620 } 00621 } 00622 00623 static string_return_type toString(pass_type val) 00624 { 00625 if (val == ItemListBase::UserSort) 00626 { 00627 return "UserSort"; 00628 } 00629 else if (val == ItemListBase::Ascending) 00630 { 00631 return "Ascending"; 00632 } 00633 else if (val == ItemListBase::Descending) 00634 { 00635 return "Descending"; 00636 } 00637 else 00638 { 00639 assert(false && "Invalid sort mode"); 00640 return "Ascending"; 00641 } 00642 } 00643 }; 00644 00645 00646 } // End of CEGUI namespace section 00647 00648 00649 #if defined(_MSC_VER) 00650 # pragma warning(pop) 00651 #endif 00652 00653 #endif // end of guard _CEGUIItemListBase_h_