Crazy Eddie's GUI System  0.8.4
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
ItemListBase.h
1 /***********************************************************************
2  created: 31/3/2005
3  author: Tomas Lindquist Olsen (based on original Listbox code by Paul D Turner)
4 
5  purpose: Interface to base class for ItemListBase widgets
6 *************************************************************************/
7 /***************************************************************************
8  * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining
11  * a copy of this software and associated documentation files (the
12  * "Software"), to deal in the Software without restriction, including
13  * without limitation the rights to use, copy, modify, merge, publish,
14  * distribute, sublicense, and/or sell copies of the Software, and to
15  * permit persons to whom the Software is furnished to do so, subject to
16  * the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be
19  * included in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27  * OTHER DEALINGS IN THE SOFTWARE.
28  ***************************************************************************/
29 #ifndef _CEGUIItemListBase_h_
30 #define _CEGUIItemListBase_h_
31 
32 #include "../Base.h"
33 #include "../Window.h"
34 #include "./ItemEntry.h"
35 
36 #include <vector>
37 
38 
39 #if defined(_MSC_VER)
40 # pragma warning(push)
41 # pragma warning(disable : 4251)
42 #endif
43 
44 
45 // Start of CEGUI namespace section
46 namespace CEGUI
47 {
48 
53 class CEGUIEXPORT ItemListBaseWindowRenderer : public WindowRenderer
54 {
55 public:
61 
71  virtual Rectf getItemRenderArea(void) const = 0;
72 };
73 
78 class CEGUIEXPORT ItemListBase : public Window
79 {
80 public:
81  static const String EventNamespace;
82 
87  enum SortMode
88  {
89  Ascending,
90  Descending,
91  UserSort
92  };
93 
95  typedef bool (*SortCallback)(const ItemEntry* a, const ItemEntry* b);
96 
97  /*************************************************************************
98  Constants
99  *************************************************************************/
100  // event names
119 
120  /*************************************************************************
121  Accessor Methods
122  *************************************************************************/
130  size_t getItemCount(void) const {return d_listItems.size();}
131 
132 
145  ItemEntry* getItemFromIndex(size_t index) const;
146 
147 
160  size_t getItemIndex(const ItemEntry* item) const;
161 
162 
180  ItemEntry* findItemWithText(const String& text, const ItemEntry* start_item);
181 
182 
190  bool isItemInList(const ItemEntry* item) const;
191 
192 
200  bool isAutoResizeEnabled() const {return d_autoResize;}
201 
202 
207  bool isSortEnabled(void) const {return d_sortEnabled;}
208 
209 
214  SortMode getSortMode(void) const {return d_sortMode;}
215 
216 
221  SortCallback getSortCallback(void) const {return d_sortCallback;}
222 
223  /*************************************************************************
224  Manipulator Methods
225  *************************************************************************/
236  virtual void initialiseComponents(void);
237 
238 
245  void resetList(void);
246 
247 
259  void addItem(ItemEntry* item);
260 
261 
281  void insertItem(ItemEntry* item, const ItemEntry* position);
282 
283 
295  void removeItem(ItemEntry* item);
296 
297 
313  void handleUpdatedItemData(bool resort=false);
314 
315 
326  void setAutoResizeEnabled(bool setting);
327 
328 
338  virtual void sizeToContent(void) {sizeToContent_impl();}
339 
340 
346  virtual void endInitialisation(void);
347 
348 
350  void performChildWindowLayout(bool nonclient_sized_hint = false,
351  bool client_sized_hint = false);
352 
353 
363  Rectf getItemRenderArea(void) const;
364 
373  Window* getContentPane(void) const {return d_pane;}
374 
380  virtual void notifyItemClicked(ItemEntry*) {}
381 
387  virtual void notifyItemSelectState(ItemEntry*, bool) {}
388 
393  void setSortEnabled(bool setting);
394 
401  void setSortMode(SortMode mode);
402 
410  void setSortCallback(SortCallback cb);
411 
423  void sortList(bool relayout=true);
424 
425  /*************************************************************************
426  Construction and Destruction
427  *************************************************************************/
432  ItemListBase(const String& type, const String& name);
433 
434 
439  virtual ~ItemListBase(void);
440 
441 
442 protected:
443  /*************************************************************************
444  Abstract Implementation Functions (must be provided by derived class)
445  *************************************************************************/
455  virtual void sizeToContent_impl(void);
456 
457 
465  virtual Sizef getContentSize() const = 0;
466 
467 
477  //virtual Rect getItemRenderArea_impl(void) const = 0;
478 
479 
487  virtual void layoutItemWidgets() = 0;
488 
489 
490  /*************************************************************************
491  Implementation Functions
492  *************************************************************************/
504  bool resetList_impl(void);
505 
506  // validate window renderer
507  virtual bool validateWindowRenderer(const WindowRenderer* renderer) const;
508 
513  SortCallback getRealSortCallback(void) const;
514 
515  /*************************************************************************
516  New event handlers
517  *************************************************************************/
522  virtual void onListContentsChanged(WindowEventArgs& e);
523 
528  virtual void onSortEnabledChanged(WindowEventArgs& e);
529 
534  virtual void onSortModeChanged(WindowEventArgs& e);
535 
536  /*************************************************************************
537  Overridden Event handlers
538  *************************************************************************/
539  virtual void onParentSized(ElementEventArgs& e);
540  //virtual void onChildRemoved(WindowEventArgs& e);
541  //virtual void onDestructionStarted(WindowEventArgs& e);
542 
543 
553  virtual bool handle_PaneChildRemoved(const EventArgs& e);
554 
555  /*************************************************************************
556  Implementation Data
557  *************************************************************************/
558  typedef std::vector<ItemEntry*
559  CEGUI_VECTOR_ALLOC(ItemEntry*)> ItemEntryList;
560  ItemEntryList d_listItems;
561 
563  bool d_autoResize;
564 
566  Window* d_pane;
567 
569  bool d_sortEnabled;
571  SortMode d_sortMode;
573  SortCallback d_sortCallback;
575  bool d_resort;
576 
577 private:
578  /*************************************************************************
579  Private methods
580  *************************************************************************/
581  void addItemListBaseProperties(void);
582 
583 
587  virtual void addChild_impl(Element* element);
588 };
589 
590 
591 template<>
592 class PropertyHelper<ItemListBase::SortMode>
593 {
594 public:
598  typedef String string_return_type;
599 
600  static const String& getDataTypeName()
601  {
602  static String type("SortMode");
603 
604  return type;
605  }
606 
607  static return_type fromString(const String& str)
608  {
609  if (str == "Ascending")
610  {
611  return ItemListBase::Ascending;
612  }
613  else if (str == "Descending")
614  {
615  return ItemListBase::Descending;
616  }
617  else
618  {
619  return ItemListBase::UserSort;
620  }
621  }
622 
623  static string_return_type toString(pass_type val)
624  {
625  if (val == ItemListBase::UserSort)
626  {
627  return "UserSort";
628  }
629  else if (val == ItemListBase::Ascending)
630  {
631  return "Ascending";
632  }
633  else if (val == ItemListBase::Descending)
634  {
635  return "Descending";
636  }
637  else
638  {
639  assert(false && "Invalid sort mode");
640  return "Ascending";
641  }
642  }
643 };
644 
645 
646 } // End of CEGUI namespace section
647 
648 
649 #if defined(_MSC_VER)
650 # pragma warning(pop)
651 #endif
652 
653 #endif // end of guard _CEGUIItemListBase_h_