Crazy Eddie's GUI System  0.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
ItemListBase.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 "../Base.h"
34 #include "../Window.h"
35 #include "./ItemEntry.h"
36 
37 #include <vector>
38 
39 
40 #if defined(_MSC_VER)
41 # pragma warning(push)
42 # pragma warning(disable : 4251)
43 #endif
44 
45 
46 // Start of CEGUI namespace section
47 namespace CEGUI
48 {
49 
54 class CEGUIEXPORT ItemListBaseWindowRenderer : public WindowRenderer
55 {
56 public:
62 
72  virtual Rectf getItemRenderArea(void) const = 0;
73 };
74 
79 class CEGUIEXPORT ItemListBase : public Window
80 {
81 public:
82  static const String EventNamespace;
83 
88  enum SortMode
89  {
90  Ascending,
91  Descending,
92  UserSort
93  };
94 
96  typedef bool (*SortCallback)(const ItemEntry* a, const ItemEntry* b);
97 
98  /*************************************************************************
99  Constants
100  *************************************************************************/
101  // event names
120 
121  /*************************************************************************
122  Accessor Methods
123  *************************************************************************/
131  size_t getItemCount(void) const {return d_listItems.size();}
132 
133 
146  ItemEntry* getItemFromIndex(size_t index) const;
147 
148 
161  size_t getItemIndex(const ItemEntry* item) const;
162 
163 
181  ItemEntry* findItemWithText(const String& text, const ItemEntry* start_item);
182 
183 
191  bool isItemInList(const ItemEntry* item) const;
192 
193 
201  bool isAutoResizeEnabled() const {return d_autoResize;}
202 
203 
208  bool isSortEnabled(void) const {return d_sortEnabled;}
209 
210 
215  SortMode getSortMode(void) const {return d_sortMode;}
216 
217 
222  SortCallback getSortCallback(void) const {return d_sortCallback;}
223 
224  /*************************************************************************
225  Manipulator Methods
226  *************************************************************************/
237  virtual void initialiseComponents(void);
238 
239 
246  void resetList(void);
247 
248 
260  void addItem(ItemEntry* item);
261 
262 
282  void insertItem(ItemEntry* item, const ItemEntry* position);
283 
284 
296  void removeItem(ItemEntry* item);
297 
298 
314  void handleUpdatedItemData(bool resort=false);
315 
316 
327  void setAutoResizeEnabled(bool setting);
328 
329 
339  virtual void sizeToContent(void) {sizeToContent_impl();}
340 
341 
347  virtual void endInitialisation(void);
348 
349 
351  void performChildWindowLayout(bool nonclient_sized_hint = false,
352  bool client_sized_hint = false);
353 
354 
364  Rectf getItemRenderArea(void) const;
365 
374  Window* getContentPane(void) const {return d_pane;}
375 
381  virtual void notifyItemClicked(ItemEntry*) {}
382 
388  virtual void notifyItemSelectState(ItemEntry*, bool) {}
389 
394  void setSortEnabled(bool setting);
395 
402  void setSortMode(SortMode mode);
403 
411  void setSortCallback(SortCallback cb);
412 
424  void sortList(bool relayout=true);
425 
426  /*************************************************************************
427  Construction and Destruction
428  *************************************************************************/
433  ItemListBase(const String& type, const String& name);
434 
435 
440  virtual ~ItemListBase(void);
441 
442 
443 protected:
444  /*************************************************************************
445  Abstract Implementation Functions (must be provided by derived class)
446  *************************************************************************/
456  virtual void sizeToContent_impl(void);
457 
458 
466  virtual Sizef getContentSize() const = 0;
467 
468 
478  //virtual Rect getItemRenderArea_impl(void) const = 0;
479 
480 
488  virtual void layoutItemWidgets() = 0;
489 
490 
491  /*************************************************************************
492  Implementation Functions
493  *************************************************************************/
505  bool resetList_impl(void);
506 
507  // validate window renderer
508  virtual bool validateWindowRenderer(const WindowRenderer* renderer) const;
509 
514  SortCallback getRealSortCallback(void) const;
515 
516  /*************************************************************************
517  New event handlers
518  *************************************************************************/
523  virtual void onListContentsChanged(WindowEventArgs& e);
524 
529  virtual void onSortEnabledChanged(WindowEventArgs& e);
530 
535  virtual void onSortModeChanged(WindowEventArgs& e);
536 
537  /*************************************************************************
538  Overridden Event handlers
539  *************************************************************************/
540  virtual void onParentSized(ElementEventArgs& e);
541  //virtual void onChildRemoved(WindowEventArgs& e);
542  //virtual void onDestructionStarted(WindowEventArgs& e);
543 
544 
554  virtual bool handle_PaneChildRemoved(const EventArgs& e);
555 
556  /*************************************************************************
557  Implementation Data
558  *************************************************************************/
559  typedef std::vector<ItemEntry*
560  CEGUI_VECTOR_ALLOC(ItemEntry*)> ItemEntryList;
561  ItemEntryList d_listItems;
562 
564  bool d_autoResize;
565 
567  Window* d_pane;
568 
570  bool d_sortEnabled;
572  SortMode d_sortMode;
574  SortCallback d_sortCallback;
576  bool d_resort;
577 
578 private:
579  /*************************************************************************
580  Private methods
581  *************************************************************************/
582  void addItemListBaseProperties(void);
583 
584 
588  virtual void addChild_impl(Element* element);
589 };
590 
591 
592 template<>
593 class PropertyHelper<ItemListBase::SortMode>
594 {
595 public:
599  typedef String string_return_type;
600 
601  static const String& getDataTypeName()
602  {
603  static String type("SortMode");
604 
605  return type;
606  }
607 
608  static return_type fromString(const String& str)
609  {
610  if (str == "Ascending")
611  {
612  return ItemListBase::Ascending;
613  }
614  else if (str == "Descending")
615  {
616  return ItemListBase::Descending;
617  }
618  else
619  {
620  return ItemListBase::UserSort;
621  }
622  }
623 
624  static string_return_type toString(pass_type val)
625  {
626  if (val == ItemListBase::UserSort)
627  {
628  return "UserSort";
629  }
630  else if (val == ItemListBase::Ascending)
631  {
632  return "Ascending";
633  }
634  else if (val == ItemListBase::Descending)
635  {
636  return "Descending";
637  }
638  else
639  {
640  assert(false && "Invalid sort mode");
641  return "Ascending";
642  }
643  }
644 };
645 
646 
647 } // End of CEGUI namespace section
648 
649 
650 #if defined(_MSC_VER)
651 # pragma warning(pop)
652 #endif
653 
654 #endif // end of guard _CEGUIItemListBase_h_