Crazy Eddie's GUI System  0.8.7
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 
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  *************************************************************************/
523 
529 
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 
564 
567 
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_
EventArgs based class that is used for objects passed to handlers triggered for events concerning som...
Definition: Element.h:211
A positioned and sized rectangular node in a tree graph.
Definition: Element.h:246
Base class used as the argument to all subscribers Event object.
Definition: EventArgs.h:51
Base class for item type widgets.
Definition: widgets/ItemEntry.h:77
Base class for ItemListBase window renderer.
Definition: ItemListBase.h:54
virtual Rectf getItemRenderArea(void) const =0
Return a Rect object describing, in un-clipped pixels, the window relative area that is to be used fo...
ItemListBaseWindowRenderer(const String &name)
Constructor.
Base class for item list widgets.
Definition: ItemListBase.h:79
virtual void layoutItemWidgets()=0
Return a Rect object describing, in un-clipped pixels, the window relative area that is to be used fo...
void resetList(void)
Remove all items from the list.
size_t getItemIndex(const ItemEntry *item) const
Return the index of ItemEntry item.
SortCallback getRealSortCallback(void) const
Returns the SortCallback that's really going to be used for the sorting operation.
ItemListBase(const String &type, const String &name)
Constructor for ItemListBase base class.
virtual Sizef getContentSize() const =0
Returns the Size in unclipped pixels of the content attached to this ItemListBase that is attached to...
bool d_autoResize
Pointer to the content pane (for items), 0 if we're not using one.
Definition: ItemListBase.h:563
void setSortMode(SortMode mode)
Set mode to be used when sorting the list.
virtual void notifyItemSelectState(ItemEntry *, bool)
Notify this ItemListBase that the given item just changed selection state. Internal function - NOT to...
Definition: ItemListBase.h:387
void setSortCallback(SortCallback cb)
Set a user callback as sorting function.
Window * d_pane
True if this ItemListBase is sorted. False if not.
Definition: ItemListBase.h:566
ItemEntry * findItemWithText(const String &text, const ItemEntry *start_item)
Search the list for an item with the specified text.
virtual void onSortModeChanged(WindowEventArgs &e)
Handler called internally when the sorting mode is changed.
bool isSortEnabled(void) const
Returns 'true' if the list is sorted.
Definition: ItemListBase.h:207
SortMode getSortMode(void) const
Get sort mode.
Definition: ItemListBase.h:214
virtual void endInitialisation(void)
Triggers a ListContentsChanged event. These are not fired during initialisation for optimization purp...
size_t getItemCount(void) const
Return number of items attached to the list.
Definition: ItemListBase.h:130
static const String EventSortEnabledChanged
Definition: ItemListBase.h:112
ItemEntry * getItemFromIndex(size_t index) const
Return the item at index position index.
virtual ~ItemListBase(void)
Destructor for ItemListBase base class.
SortMode
Sort modes for ItemListBase.
Definition: ItemListBase.h:88
void addItem(ItemEntry *item)
Add the given ItemEntry to the list.
SortMode d_sortMode
The user sort callback or 0 if none.
Definition: ItemListBase.h:571
void setSortEnabled(bool setting)
Set whether the list should be sorted (by text).
void setAutoResizeEnabled(bool setting)
Set whether or not this ItemListBase widget should automatically resize to fit its content.
virtual bool validateWindowRenderer(const WindowRenderer *renderer) const
Function used in checking if a WindowRenderer is valid for this window.
virtual bool handle_PaneChildRemoved(const EventArgs &e)
Handler to manage items being removed from the content pane. If there is one!
Rectf getItemRenderArea(void) const
Return a Rect object describing, in un-clipped pixels, the window relative area that is to be used fo...
bool isItemInList(const ItemEntry *item) const
Return whether the specified ItemEntry is in the List.
virtual void sizeToContent_impl(void)
Resize the ItemListBase to exactly fit the content that is attached to it. Return a Rect object descr...
void handleUpdatedItemData(bool resort=false)
void performChildWindowLayout(bool nonclient_sized_hint=false, bool client_sized_hint=false)
Layout child window content.
bool resetList_impl(void)
Remove all items from the list.
void sortList(bool relayout=true)
Sort the list.
static const String EventListContentsChanged
Definition: ItemListBase.h:106
void removeItem(ItemEntry *item)
Removes the given item from the list. If the item is has the 'DestroyedByParent' property set to 'tru...
virtual void notifyItemClicked(ItemEntry *)
Notify this ItemListBase that the given item was just clicked. Internal function - NOT to be used fro...
Definition: ItemListBase.h:380
static const String EventSortModeChanged
Definition: ItemListBase.h:118
virtual void initialiseComponents(void)
Initialise the Window based object ready for use.
virtual void sizeToContent(void)
Resize the ItemListBase to exactly fit the content that is attached to it. Return a Rect object descr...
Definition: ItemListBase.h:338
Window * getContentPane(void) const
Returns a pointer to the window that all items are directed too.
Definition: ItemListBase.h:373
bool isAutoResizeEnabled() const
Return whether this window is automatically resized to fit its content.
Definition: ItemListBase.h:200
ItemEntryList d_listItems
list of items in the list.
Definition: ItemListBase.h:560
SortCallback getSortCallback(void) const
Get user sorting callback.
Definition: ItemListBase.h:221
SortCallback d_sortCallback
True if the list needs to be resorted.
Definition: ItemListBase.h:573
static const String EventNamespace
Namespace for global events.
Definition: ItemListBase.h:81
virtual void onListContentsChanged(WindowEventArgs &e)
Handler called internally when the list contents are changed.
void insertItem(ItemEntry *item, const ItemEntry *position)
Insert an item into the list before a specified item already in the list.
virtual void onSortEnabledChanged(WindowEventArgs &e)
Handler called internally when sorting gets enabled.
virtual void onParentSized(ElementEventArgs &e)
Handler called when this window's parent window has been resized. If this window is the root / GUI Sh...
bool d_sortEnabled
The current sorting mode applied if sorting is enabled.
Definition: ItemListBase.h:569
Helper class used to convert various data types to and from the format expected in Property strings.
Definition: ForwardRefs.h:84
String class used within the GUI system.
Definition: String.h:64
EventArgs based class that is used for objects passed to handlers triggered for events concerning som...
Definition: InputEvent.h:252
Base-class for the assignable WindowRenderer object.
Definition: WindowRenderer.h:52
An abstract base class providing common functionality and specifying the required interface for deriv...
Definition: Window.h:151
Main namespace for Crazy Eddie's GUI Library.
Definition: arch_overview.dox:1