Crazy Eddies GUI System  0.7.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 "CEGUIItemListBaseProperties.h"
36 #include "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 
268  void insertItem(ItemEntry* item, const ItemEntry* position);
269 
270 
282  void removeItem(ItemEntry* item);
283 
284 
300  void handleUpdatedItemData(bool resort=false);
301 
302 
313  void setAutoResizeEnabled(bool setting);
314 
315 
325  virtual void sizeToContent(void) {sizeToContent_impl();}
326 
327 
333  virtual void endInitialisation(void);
334 
335 
346  virtual void performChildWindowLayout(void);
347 
348 
358  Rect getItemRenderArea(void) const;
359 
368  Window* getContentPane(void) const {return d_pane;}
369 
375  virtual void notifyItemClicked(ItemEntry*) {}
376 
382  virtual void notifyItemSelectState(ItemEntry*, bool) {}
383 
388  void setSortEnabled(bool setting);
389 
396  void setSortMode(SortMode mode);
397 
405  void setSortCallback(SortCallback cb);
406 
418  void sortList(bool relayout=true);
419 
420  /*************************************************************************
421  Construction and Destruction
422  *************************************************************************/
427  ItemListBase(const String& type, const String& name);
428 
429 
434  virtual ~ItemListBase(void);
435 
436 
437 protected:
438  /*************************************************************************
439  Abstract Implementation Functions (must be provided by derived class)
440  *************************************************************************/
450  virtual void sizeToContent_impl(void);
451 
452 
460  virtual Size getContentSize() const = 0;
461 
462 
472  //virtual Rect getItemRenderArea_impl(void) const = 0;
473 
474 
482  virtual void layoutItemWidgets() = 0;
483 
484 
485  /*************************************************************************
486  Implementation Functions
487  *************************************************************************/
499  bool resetList_impl(void);
500 
511  virtual bool testClassName_impl(const String& class_name) const
512  {
513  if (class_name=="ItemListBase") return true;
514  return Window::testClassName_impl(class_name);
515  }
516 
517  // validate window renderer
518  virtual bool validateWindowRenderer(const String& name) const
519  {
520  return (name == EventNamespace);
521  }
522 
527  SortCallback getRealSortCallback(void) const;
528 
529  /*************************************************************************
530  New event handlers
531  *************************************************************************/
536  virtual void onListContentsChanged(WindowEventArgs& e);
537 
542  virtual void onSortEnabledChanged(WindowEventArgs& e);
543 
548  virtual void onSortModeChanged(WindowEventArgs& e);
549 
550  /*************************************************************************
551  Overridden Event handlers
552  *************************************************************************/
553  virtual void onParentSized(WindowEventArgs& e);
554  //virtual void onChildRemoved(WindowEventArgs& e);
555  //virtual void onDestructionStarted(WindowEventArgs& e);
556 
557 
558  /*************************************************************************
559  Implementation Data
560  *************************************************************************/
561  typedef std::vector<ItemEntry*> ItemEntryList;
562  ItemEntryList d_listItems;
563 
565  bool d_autoResize;
566 
568  Window* d_pane;
569 
571  bool d_sortEnabled;
573  SortMode d_sortMode;
575  SortCallback d_sortCallback;
577  bool d_resort;
578 
579 private:
580  /*************************************************************************
581  Static Properties for this class
582  *************************************************************************/
583  static ItemListBaseProperties::AutoResizeEnabled d_autoResizeEnabledProperty;
584  static ItemListBaseProperties::SortEnabled d_sortEnabledProperty;
585  static ItemListBaseProperties::SortMode d_sortModeProperty;
586 
587  /*************************************************************************
588  Private methods
589  *************************************************************************/
590  void addItemListBaseProperties(void);
591 
592 
597  virtual void addChild_impl(Window* wnd);
598 
604  bool handle_PaneChildRemoved(const EventArgs& e);
605 };
606 
607 } // End of CEGUI namespace section
608 
609 
610 #if defined(_MSC_VER)
611 # pragma warning(pop)
612 #endif
613 
614 #endif // end of guard _CEGUIItemListBase_h_