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