Crazy Eddies GUI System  0.6.0
CEGUIItemListBase.h
1 /***********************************************************************
2  filename: CEGUIItemListBase.h
3  created: 31/3/2005
4  author: Tomas Lindquist Olsen (based on original Listbox code by Paul D Turner)
5 
6  purpose: Interface to base class for ItemListBase widgets
7 *************************************************************************/
8 /***************************************************************************
9  * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining
12  * a copy of this software and associated documentation files (the
13  * "Software"), to deal in the Software without restriction, including
14  * without limitation the rights to use, copy, modify, merge, publish,
15  * distribute, sublicense, and/or sell copies of the Software, and to
16  * permit persons to whom the Software is furnished to do so, subject to
17  * the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be
20  * included in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
26  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
27  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28  * OTHER DEALINGS IN THE SOFTWARE.
29  ***************************************************************************/
30 #ifndef _CEGUIItemListBase_h_
31 #define _CEGUIItemListBase_h_
32 
33 #include "CEGUIBase.h"
34 #include "CEGUIWindow.h"
35 #include "elements/CEGUIItemListBaseProperties.h"
36 #include "elements/CEGUIItemEntry.h"
37 
38 #include <vector>
39 
40 
41 #if defined(_MSC_VER)
42 # pragma warning(push)
43 # pragma warning(disable : 4251)
44 #endif
45 
46 
47 // Start of CEGUI namespace section
48 namespace CEGUI
49 {
50 
55 class CEGUIEXPORT ItemListBaseWindowRenderer : public WindowRenderer
56 {
57 public:
63 
73  virtual Rect getItemRenderArea(void) const = 0;
74 };
75 
80 class CEGUIEXPORT ItemListBase : public Window
81 {
82 public:
83  static const String EventNamespace;
84 
89  enum SortMode
90  {
91  Ascending,
92  Descending,
93  UserSort
94  };
95 
97  typedef bool (*SortCallback)(const ItemEntry* a, const ItemEntry* b);
98 
99  /*************************************************************************
100  Constants
101  *************************************************************************/
102  // event names
106 
107  /*************************************************************************
108  Accessor Methods
109  *************************************************************************/
117  size_t getItemCount(void) const {return d_listItems.size();}
118 
119 
132  ItemEntry* getItemFromIndex(size_t index) const;
133 
134 
147  size_t getItemIndex(const ItemEntry* item) const;
148 
149 
167  ItemEntry* findItemWithText(const String& text, const ItemEntry* start_item);
168 
169 
177  bool isItemInList(const ItemEntry* item) const;
178 
179 
187  bool isAutoResizeEnabled() const {return d_autoResize;}
188 
189 
194  bool isSortEnabled(void) const {return d_sortEnabled;}
195 
196 
201  SortMode getSortMode(void) const {return d_sortMode;}
202 
203 
208  SortCallback getSortCallback(void) const {return d_sortCallback;}
209 
210  /*************************************************************************
211  Manipulator Methods
212  *************************************************************************/
223  virtual void initialiseComponents(void);
224 
225 
232  void resetList(void);
233 
234 
246  void addItem(ItemEntry* item);
247 
248 
266  void insertItem(ItemEntry* item, const ItemEntry* position);
267 
268 
280  void removeItem(ItemEntry* item);
281 
282 
298  void handleUpdatedItemData(bool resort=false);
299 
300 
311  void setAutoResizeEnabled(bool setting);
312 
313 
323  virtual void sizeToContent(void) {sizeToContent_impl();}
324 
325 
331  virtual void endInitialisation(void);
332 
333 
344  virtual void performChildWindowLayout(void);
345 
346 
356  Rect getItemRenderArea(void) const;
357 
366  Window* getContentPane(void) const {return d_pane;}
367 
373  virtual void notifyItemClicked(ItemEntry* li) {}
374 
380  virtual void notifyItemSelectState(ItemEntry* li, bool state) {}
381 
386  void setSortEnabled(bool setting);
387 
394  void setSortMode(SortMode mode);
395 
403  void setSortCallback(SortCallback cb);
404 
416  void sortList(bool relayout=true);
417 
418  /*************************************************************************
419  Construction and Destruction
420  *************************************************************************/
425  ItemListBase(const String& type, const String& name);
426 
427 
432  virtual ~ItemListBase(void);
433 
434 
435 protected:
436  /*************************************************************************
437  Abstract Implementation Functions (must be provided by derived class)
438  *************************************************************************/
448  virtual void sizeToContent_impl(void);
449 
450 
458  virtual Size getContentSize() const = 0;
459 
460 
470  //virtual Rect getItemRenderArea_impl(void) const = 0;
471 
472 
480  virtual void layoutItemWidgets() = 0;
481 
482 
483  /*************************************************************************
484  Implementation Functions
485  *************************************************************************/
497  bool resetList_impl(void);
498 
509  virtual bool testClassName_impl(const String& class_name) const
510  {
511  if (class_name=="ItemListBase") return true;
512  return Window::testClassName_impl(class_name);
513  }
514 
515  // validate window renderer
516  virtual bool validateWindowRenderer(const String& name) const
517  {
518  return (name == EventNamespace);
519  }
520 
525  SortCallback getRealSortCallback(void) const;
526 
527  /*************************************************************************
528  New event handlers
529  *************************************************************************/
534  virtual void onListContentsChanged(WindowEventArgs& e);
535 
540  virtual void onSortEnabledChanged(WindowEventArgs& e);
541 
546  virtual void onSortModeChanged(WindowEventArgs& e);
547 
548  /*************************************************************************
549  Overridden Event handlers
550  *************************************************************************/
551  //virtual void onChildRemoved(WindowEventArgs& e);
552  //virtual void onDestructionStarted(WindowEventArgs& e);
553 
554 
555  /*************************************************************************
556  Implementation Data
557  *************************************************************************/
558  typedef std::vector<ItemEntry*> ItemEntryList;
559  ItemEntryList d_listItems;
560 
562  bool d_autoResize;
563 
565  Window* d_pane;
566 
568  bool d_sortEnabled;
570  SortMode d_sortMode;
572  SortCallback d_sortCallback;
574  bool d_resort;
575 
576 private:
577  /*************************************************************************
578  Static Properties for this class
579  *************************************************************************/
580  static ItemListBaseProperties::AutoResizeEnabled d_autoResizeEnabledProperty;
581  static ItemListBaseProperties::SortEnabled d_sortEnabledProperty;
582  static ItemListBaseProperties::SortMode d_sortModeProperty;
583 
584  /*************************************************************************
585  Private methods
586  *************************************************************************/
587  void addItemListBaseProperties(void);
588 
589 
594  virtual void addChild_impl(Window* wnd);
595 
601  bool handle_PaneChildRemoved(const EventArgs& e);
602 };
603 
604 } // End of CEGUI namespace section
605 
606 
607 #if defined(_MSC_VER)
608 # pragma warning(pop)
609 #endif
610 
611 #endif // end of guard _CEGUIItemListBase_h_