Crazy Eddies GUI System  0.7.9
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
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
126 
127  /*************************************************************************
128  Child Widget name suffix constants
129  *************************************************************************/
132 
133  /*************************************************************************
134  Accessor Methods
135  *************************************************************************/
143  size_t getItemCount(void) const {return d_listItems.size();}
144 
145 
153  size_t getSelectedCount(void) const;
154 
155 
164  ListboxItem* getFirstSelectedItem(void) const;
165 
166 
181  ListboxItem* getNextSelected(const ListboxItem* start_item) const;
182 
183 
196  ListboxItem* getListboxItemFromIndex(size_t index) const;
197 
198 
211  size_t getItemIndex(const ListboxItem* item) const;
212 
213 
221  bool isSortEnabled(void) const {return d_sorted;}
222 
230  bool isMultiselectEnabled(void) const {return d_multiselect;}
231 
232  bool isItemTooltipsEnabled(void) const {return d_itemTooltips;}
233 
246  bool isItemSelected(size_t index) const;
247 
248 
266  ListboxItem* findItemWithText(const String& text, const ListboxItem* start_item);
267 
268 
276  bool isListboxItemInList(const ListboxItem* item) const;
277 
278 
287  bool isVertScrollbarAlwaysShown(void) const;
288 
289 
298  bool isHorzScrollbarAlwaysShown(void) const;
299 
300 
301  /*************************************************************************
302  Manipulator Methods
303  *************************************************************************/
314  virtual void initialiseComponents(void);
315 
316 
323  void resetList(void);
324 
325 
337  void addItem(ListboxItem* item);
338 
339 
363  void insertItem(ListboxItem* item, const ListboxItem* position);
364 
365 
377  void removeItem(const ListboxItem* item);
378 
379 
387  void clearAllSelections(void);
388 
389 
400  void setSortingEnabled(bool setting);
401 
402 
414  void setMultiselectEnabled(bool setting);
415 
416 
428  void setShowVertScrollbar(bool setting);
429 
430 
442  void setShowHorzScrollbar(bool setting);
443 
444  void setItemTooltipsEnabled(bool setting);
464  void setItemSelectState(ListboxItem* item, bool state);
465 
466 
486  void setItemSelectState(size_t item_index, bool state);
487 
488 
501  void handleUpdatedItemData(void);
502 
503 
515  void ensureItemIsVisible(size_t item_index);
516 
517 
530  void ensureItemIsVisible(const ListboxItem* item);
531 
532 
542  virtual Rect getListRenderArea(void) const;
543 
544 
556  Scrollbar* getVertScrollbar() const;
557 
569  Scrollbar* getHorzScrollbar() const;
570 
571 
576  float getTotalItemsHeight(void) const;
577 
578 
583  float getWidestItemWidth(void) const;
584 
585 
596  ListboxItem* getItemAtPoint(const Point& pt) const;
597 
598 
599  /*************************************************************************
600  Construction and Destruction
601  *************************************************************************/
606  Listbox(const String& type, const String& name);
607 
608 
613  virtual ~Listbox(void);
614 
615 
616 protected:
617  /*************************************************************************
618  Abstract Implementation Functions (must be provided by derived class)
619  *************************************************************************/
629  //virtual Rect getListRenderArea_impl(void) const = 0;
630 
631 
632  /*************************************************************************
633  Implementation Functions
634  *************************************************************************/
639  void configureScrollbars(void);
640 
646  void selectRange(size_t start, size_t end);
647 
648 
656  bool clearAllSelections_impl(void);
657 
658 
670  bool resetList_impl(void);
671 
672 
683  virtual bool testClassName_impl(const String& class_name) const
684  {
685  if (class_name=="Listbox") return true;
686  return Window::testClassName_impl(class_name);
687  }
688 
693  bool handle_scrollChange(const EventArgs& args);
694 
695 
696  // validate window renderer
697  virtual bool validateWindowRenderer(const String& name) const
698  {
699  return (name == "Listbox");
700  }
701 
706  void resortList();
707 
708  /*************************************************************************
709  New event handlers
710  *************************************************************************/
715  virtual void onListContentsChanged(WindowEventArgs& e);
716 
717 
722  virtual void onSelectionChanged(WindowEventArgs& e);
723 
724 
729  virtual void onSortModeChanged(WindowEventArgs& e);
730 
731 
736  virtual void onMultiselectModeChanged(WindowEventArgs& e);
737 
738 
743  virtual void onVertScrollbarModeChanged(WindowEventArgs& e);
744 
745 
750  virtual void onHorzScrollbarModeChanged(WindowEventArgs& e);
751 
752 
753  /*************************************************************************
754  Overridden Event handlers
755  *************************************************************************/
756  virtual void onSized(WindowEventArgs& e);
757  virtual void onMouseButtonDown(MouseEventArgs& e);
758  virtual void onMouseWheel(MouseEventArgs& e);
759  virtual void onMouseMove(MouseEventArgs& e);
760 
761 
762  /*************************************************************************
763  Implementation Data
764  *************************************************************************/
765  typedef std::vector<ListboxItem*> LBItemList;
766  bool d_sorted;
771  LBItemList d_listItems;
773 
774  friend class ListboxWindowRenderer;
775 
776 private:
777  /*************************************************************************
778  Static Properties for this class
779  *************************************************************************/
780  static ListboxProperties::Sort d_sortProperty;
781  static ListboxProperties::MultiSelect d_multiSelectProperty;
782  static ListboxProperties::ForceVertScrollbar d_forceVertProperty;
783  static ListboxProperties::ForceHorzScrollbar d_forceHorzProperty;
784  static ListboxProperties::ItemTooltips d_itemTooltipsProperty;
785 
786  /*************************************************************************
787  Private methods
788  *************************************************************************/
789  void addListboxProperties(void);
790 };
791 
792 
798 bool lbi_less(const ListboxItem* a, const ListboxItem* b);
799 
800 
806 bool lbi_greater(const ListboxItem* a, const ListboxItem* b);
807 
808 } // End of CEGUI namespace section
809 
810 
811 #if defined(_MSC_VER)
812 # pragma warning(pop)
813 #endif
814 
815 #endif // end of guard _CEGUIListbox_h_