Crazy Eddies GUI System  0.7.1
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 "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 
331  void insertItem(ListboxItem* item, const ListboxItem* position);
332 
333 
345  void removeItem(const ListboxItem* item);
346 
347 
355  void clearAllSelections(void);
356 
357 
368  void setSortingEnabled(bool setting);
369 
370 
382  void setMultiselectEnabled(bool setting);
383 
384 
396  void setShowVertScrollbar(bool setting);
397 
398 
410  void setShowHorzScrollbar(bool setting);
411 
412  void setItemTooltipsEnabled(bool setting);
432  void setItemSelectState(ListboxItem* item, bool state);
433 
434 
454  void setItemSelectState(size_t item_index, bool state);
455 
456 
469  void handleUpdatedItemData(void);
470 
471 
483  void ensureItemIsVisible(size_t item_index);
484 
485 
498  void ensureItemIsVisible(const ListboxItem* item);
499 
500 
510  virtual Rect getListRenderArea(void) const;
511 
512 
524  Scrollbar* getVertScrollbar() const;
525 
537  Scrollbar* getHorzScrollbar() const;
538 
539 
544  float getTotalItemsHeight(void) const;
545 
546 
551  float getWidestItemWidth(void) const;
552 
553 
554  /*************************************************************************
555  Construction and Destruction
556  *************************************************************************/
561  Listbox(const String& type, const String& name);
562 
563 
568  virtual ~Listbox(void);
569 
570 
571 protected:
572  /*************************************************************************
573  Abstract Implementation Functions (must be provided by derived class)
574  *************************************************************************/
584  //virtual Rect getListRenderArea_impl(void) const = 0;
585 
586 
587  /*************************************************************************
588  Implementation Functions
589  *************************************************************************/
594  void configureScrollbars(void);
595 
601  void selectRange(size_t start, size_t end);
602 
603 
611  bool clearAllSelections_impl(void);
612 
613 
622  ListboxItem* getItemAtPoint(const Point& pt) const;
623 
624 
636  bool resetList_impl(void);
637 
638 
649  virtual bool testClassName_impl(const String& class_name) const
650  {
651  if (class_name=="Listbox") return true;
652  return Window::testClassName_impl(class_name);
653  }
654 
659  bool handle_scrollChange(const EventArgs& args);
660 
661 
662  // validate window renderer
663  virtual bool validateWindowRenderer(const String& name) const
664  {
665  return (name == "Listbox");
666  }
667 
672  void resortList();
673 
674  /*************************************************************************
675  New event handlers
676  *************************************************************************/
681  virtual void onListContentsChanged(WindowEventArgs& e);
682 
683 
688  virtual void onSelectionChanged(WindowEventArgs& e);
689 
690 
695  virtual void onSortModeChanged(WindowEventArgs& e);
696 
697 
702  virtual void onMultiselectModeChanged(WindowEventArgs& e);
703 
704 
709  virtual void onVertScrollbarModeChanged(WindowEventArgs& e);
710 
711 
716  virtual void onHorzScrollbarModeChanged(WindowEventArgs& e);
717 
718 
719  /*************************************************************************
720  Overridden Event handlers
721  *************************************************************************/
722  virtual void onSized(WindowEventArgs& e);
723  virtual void onMouseButtonDown(MouseEventArgs& e);
724  virtual void onMouseWheel(MouseEventArgs& e);
725  virtual void onMouseMove(MouseEventArgs& e);
726 
727 
728  /*************************************************************************
729  Implementation Data
730  *************************************************************************/
731  typedef std::vector<ListboxItem*> LBItemList;
732  bool d_sorted;
737  LBItemList d_listItems;
739 
740  friend class ListboxWindowRenderer;
741 
742 private:
743  /*************************************************************************
744  Static Properties for this class
745  *************************************************************************/
746  static ListboxProperties::Sort d_sortProperty;
747  static ListboxProperties::MultiSelect d_multiSelectProperty;
748  static ListboxProperties::ForceVertScrollbar d_forceVertProperty;
749  static ListboxProperties::ForceHorzScrollbar d_forceHorzProperty;
750  static ListboxProperties::ItemTooltips d_itemTooltipsProperty;
751 
752  /*************************************************************************
753  Private methods
754  *************************************************************************/
755  void addListboxProperties(void);
756 };
757 
758 
764 bool lbi_less(const ListboxItem* a, const ListboxItem* b);
765 
766 
772 bool lbi_greater(const ListboxItem* a, const ListboxItem* b);
773 
774 } // End of CEGUI namespace section
775 
776 
777 #if defined(_MSC_VER)
778 # pragma warning(pop)
779 #endif
780 
781 #endif // end of guard _CEGUIListbox_h_