Crazy Eddies GUI System  0.6.0
CEGUIListbox.h
1 /***********************************************************************
2  filename: CEGUIListbox.h
3  created: 13/4/2004
4  author: Paul D Turner
5 
6  purpose: Interface to base class for Listbox widget
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 _CEGUIListbox_h_
31 #define _CEGUIListbox_h_
32 
33 #include "CEGUIBase.h"
34 #include "CEGUIWindow.h"
35 #include "elements/CEGUIListboxProperties.h"
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 ListboxWindowRenderer : public WindowRenderer
54 {
55 public:
60  ListboxWindowRenderer(const String& name);
61 
71  virtual Rect getListRenderArea(void) const = 0;
72 };
73 
78 class CEGUIEXPORT Listbox : public Window
79 {
80 public:
81  static const String EventNamespace;
82  static const String WidgetTypeName;
83 
84  /*************************************************************************
85  Constants
86  *************************************************************************/
87  // event names
94 
95  /*************************************************************************
96  Child Widget name suffix constants
97  *************************************************************************/
100 
101  /*************************************************************************
102  Accessor Methods
103  *************************************************************************/
111  size_t getItemCount(void) const {return d_listItems.size();}
112 
113 
121  size_t getSelectedCount(void) const;
122 
123 
132  ListboxItem* getFirstSelectedItem(void) const;
133 
134 
149  ListboxItem* getNextSelected(const ListboxItem* start_item) const;
150 
151 
164  ListboxItem* getListboxItemFromIndex(size_t index) const;
165 
166 
179  size_t getItemIndex(const ListboxItem* item) const;
180 
181 
189  bool isSortEnabled(void) const {return d_sorted;}
190 
198  bool isMultiselectEnabled(void) const {return d_multiselect;}
199 
200  bool isItemTooltipsEnabled(void) const {return d_itemTooltips;}
201 
214  bool isItemSelected(size_t index) const;
215 
216 
234  ListboxItem* findItemWithText(const String& text, const ListboxItem* start_item);
235 
236 
244  bool isListboxItemInList(const ListboxItem* item) const;
245 
246 
255  bool isVertScrollbarAlwaysShown(void) const;
256 
257 
266  bool isHorzScrollbarAlwaysShown(void) const;
267 
268 
269  /*************************************************************************
270  Manipulator Methods
271  *************************************************************************/
282  virtual void initialiseComponents(void);
283 
284 
291  void resetList(void);
292 
293 
305  void addItem(ListboxItem* item);
306 
307 
327  void insertItem(ListboxItem* item, const ListboxItem* position);
328 
329 
341  void removeItem(const ListboxItem* item);
342 
343 
351  void clearAllSelections(void);
352 
353 
364  void setSortingEnabled(bool setting);
365 
366 
378  void setMultiselectEnabled(bool setting);
379 
380 
392  void setShowVertScrollbar(bool setting);
393 
394 
406  void setShowHorzScrollbar(bool setting);
407 
408  void setItemTooltipsEnabled(bool setting);
428  void setItemSelectState(ListboxItem* item, bool state);
429 
430 
450  void setItemSelectState(size_t item_index, bool state);
451 
452 
465  void handleUpdatedItemData(void);
466 
467 
479  void ensureItemIsVisible(size_t item_index);
480 
481 
494  void ensureItemIsVisible(const ListboxItem* item);
495 
496 
506  virtual Rect getListRenderArea(void) const;
507 
508 
520  Scrollbar* getVertScrollbar() const;
521 
533  Scrollbar* getHorzScrollbar() const;
534 
535 
540  float getTotalItemsHeight(void) const;
541 
542 
547  float getWidestItemWidth(void) const;
548 
549 
550  /*************************************************************************
551  Construction and Destruction
552  *************************************************************************/
557  Listbox(const String& type, const String& name);
558 
559 
564  virtual ~Listbox(void);
565 
566 
567 protected:
568  /*************************************************************************
569  Abstract Implementation Functions (must be provided by derived class)
570  *************************************************************************/
580  //virtual Rect getListRenderArea_impl(void) const = 0;
581 
582 
583  /*************************************************************************
584  Implementation Functions
585  *************************************************************************/
590  void configureScrollbars(void);
591 
597  void selectRange(size_t start, size_t end);
598 
599 
607  bool clearAllSelections_impl(void);
608 
609 
618  ListboxItem* getItemAtPoint(const Point& pt) const;
619 
620 
632  bool resetList_impl(void);
633 
634 
645  virtual bool testClassName_impl(const String& class_name) const
646  {
647  if (class_name=="Listbox") return true;
648  return Window::testClassName_impl(class_name);
649  }
650 
655  bool handle_scrollChange(const EventArgs& args);
656 
657 
658  // validate window renderer
659  virtual bool validateWindowRenderer(const String& name) const
660  {
661  return (name == "Listbox");
662  }
663 
668  void resortList();
669 
670  /*************************************************************************
671  New event handlers
672  *************************************************************************/
677  virtual void onListContentsChanged(WindowEventArgs& e);
678 
679 
684  virtual void onSelectionChanged(WindowEventArgs& e);
685 
686 
691  virtual void onSortModeChanged(WindowEventArgs& e);
692 
693 
698  virtual void onMultiselectModeChanged(WindowEventArgs& e);
699 
700 
705  virtual void onVertScrollbarModeChanged(WindowEventArgs& e);
706 
707 
712  virtual void onHorzScrollbarModeChanged(WindowEventArgs& e);
713 
714 
715  /*************************************************************************
716  Overridden Event handlers
717  *************************************************************************/
718  virtual void onSized(WindowEventArgs& e);
719  virtual void onMouseButtonDown(MouseEventArgs& e);
720  virtual void onMouseWheel(MouseEventArgs& e);
721  virtual void onMouseMove(MouseEventArgs& e);
722 
723 
724  /*************************************************************************
725  Implementation Data
726  *************************************************************************/
727  typedef std::vector<ListboxItem*> LBItemList;
728  bool d_sorted;
733  LBItemList d_listItems;
735 
736  friend class ListboxWindowRenderer;
737 
738 private:
739  /*************************************************************************
740  Static Properties for this class
741  *************************************************************************/
742  static ListboxProperties::Sort d_sortProperty;
743  static ListboxProperties::MultiSelect d_multiSelectProperty;
744  static ListboxProperties::ForceVertScrollbar d_forceVertProperty;
745  static ListboxProperties::ForceHorzScrollbar d_forceHorzProperty;
746  static ListboxProperties::ItemTooltips d_itemTooltipsProperty;
747 
748  /*************************************************************************
749  Private methods
750  *************************************************************************/
751  void addListboxProperties(void);
752 };
753 
754 
760 bool lbi_less(const ListboxItem* a, const ListboxItem* b);
761 
762 
768 bool lbi_greater(const ListboxItem* a, const ListboxItem* b);
769 
770 } // End of CEGUI namespace section
771 
772 
773 #if defined(_MSC_VER)
774 # pragma warning(pop)
775 #endif
776 
777 #endif // end of guard _CEGUIListbox_h_