Crazy Eddies GUI System  0.7.9
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
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
121 
122  /*************************************************************************
123  Accessor Methods
124  *************************************************************************/
132  size_t getItemCount(void) const {return d_listItems.size();}
133 
134 
147  ItemEntry* getItemFromIndex(size_t index) const;
148 
149 
162  size_t getItemIndex(const ItemEntry* item) const;
163 
164 
182  ItemEntry* findItemWithText(const String& text, const ItemEntry* start_item);
183 
184 
192  bool isItemInList(const ItemEntry* item) const;
193 
194 
202  bool isAutoResizeEnabled() const {return d_autoResize;}
203 
204 
209  bool isSortEnabled(void) const {return d_sortEnabled;}
210 
211 
216  SortMode getSortMode(void) const {return d_sortMode;}
217 
218 
223  SortCallback getSortCallback(void) const {return d_sortCallback;}
224 
225  /*************************************************************************
226  Manipulator Methods
227  *************************************************************************/
238  virtual void initialiseComponents(void);
239 
240 
247  void resetList(void);
248 
249 
261  void addItem(ItemEntry* item);
262 
263 
283  void insertItem(ItemEntry* item, const ItemEntry* position);
284 
285 
297  void removeItem(ItemEntry* item);
298 
299 
315  void handleUpdatedItemData(bool resort=false);
316 
317 
328  void setAutoResizeEnabled(bool setting);
329 
330 
340  virtual void sizeToContent(void) {sizeToContent_impl();}
341 
342 
348  virtual void endInitialisation(void);
349 
350 
361  virtual void performChildWindowLayout(void);
362 
363 
373  Rect getItemRenderArea(void) const;
374 
383  Window* getContentPane(void) const {return d_pane;}
384 
390  virtual void notifyItemClicked(ItemEntry*) {}
391 
397  virtual void notifyItemSelectState(ItemEntry*, bool) {}
398 
403  void setSortEnabled(bool setting);
404 
411  void setSortMode(SortMode mode);
412 
420  void setSortCallback(SortCallback cb);
421 
433  void sortList(bool relayout=true);
434 
435  /*************************************************************************
436  Construction and Destruction
437  *************************************************************************/
442  ItemListBase(const String& type, const String& name);
443 
444 
449  virtual ~ItemListBase(void);
450 
451 
452 protected:
453  /*************************************************************************
454  Abstract Implementation Functions (must be provided by derived class)
455  *************************************************************************/
465  virtual void sizeToContent_impl(void);
466 
467 
475  virtual Size getContentSize() const = 0;
476 
477 
487  //virtual Rect getItemRenderArea_impl(void) const = 0;
488 
489 
497  virtual void layoutItemWidgets() = 0;
498 
499 
500  /*************************************************************************
501  Implementation Functions
502  *************************************************************************/
514  bool resetList_impl(void);
515 
526  virtual bool testClassName_impl(const String& class_name) const
527  {
528  if (class_name=="ItemListBase") return true;
529  return Window::testClassName_impl(class_name);
530  }
531 
532  // validate window renderer
533  virtual bool validateWindowRenderer(const String& name) const
534  {
535  return (name == EventNamespace);
536  }
537 
542  SortCallback getRealSortCallback(void) const;
543 
544  /*************************************************************************
545  New event handlers
546  *************************************************************************/
551  virtual void onListContentsChanged(WindowEventArgs& e);
552 
557  virtual void onSortEnabledChanged(WindowEventArgs& e);
558 
563  virtual void onSortModeChanged(WindowEventArgs& e);
564 
565  /*************************************************************************
566  Overridden Event handlers
567  *************************************************************************/
568  virtual void onParentSized(WindowEventArgs& e);
569  //virtual void onChildRemoved(WindowEventArgs& e);
570  //virtual void onDestructionStarted(WindowEventArgs& e);
571 
572 
573  /*************************************************************************
574  Implementation Data
575  *************************************************************************/
576  typedef std::vector<ItemEntry*> ItemEntryList;
577  ItemEntryList d_listItems;
578 
580  bool d_autoResize;
581 
583  Window* d_pane;
584 
586  bool d_sortEnabled;
588  SortMode d_sortMode;
590  SortCallback d_sortCallback;
592  bool d_resort;
593 
594 private:
595  /*************************************************************************
596  Static Properties for this class
597  *************************************************************************/
598  static ItemListBaseProperties::AutoResizeEnabled d_autoResizeEnabledProperty;
599  static ItemListBaseProperties::SortEnabled d_sortEnabledProperty;
600  static ItemListBaseProperties::SortMode d_sortModeProperty;
601 
602  /*************************************************************************
603  Private methods
604  *************************************************************************/
605  void addItemListBaseProperties(void);
606 
607 
612  virtual void addChild_impl(Window* wnd);
613 
619  bool handle_PaneChildRemoved(const EventArgs& e);
620 };
621 
622 } // End of CEGUI namespace section
623 
624 
625 #if defined(_MSC_VER)
626 # pragma warning(pop)
627 #endif
628 
629 #endif // end of guard _CEGUIItemListBase_h_