Crazy Eddie's GUI System  0.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
widgets/Listbox.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 "../Base.h"
34 #include "../Window.h"
35 #include <vector>
36 
37 
38 #if defined(_MSC_VER)
39 # pragma warning(push)
40 # pragma warning(disable : 4251)
41 #endif
42 
43 
44 // Start of CEGUI namespace section
45 namespace CEGUI
46 {
47 
52 class CEGUIEXPORT ListboxWindowRenderer : public WindowRenderer
53 {
54 public:
59  ListboxWindowRenderer(const String& name);
60 
66  virtual Rectf getListRenderArea(void) const = 0;
67 
74  virtual void resizeListToContent(bool fit_width,
75  bool fit_height) const = 0;
76 };
77 
82 class CEGUIEXPORT Listbox : public Window
83 {
84 public:
85  static const String EventNamespace;
86  static const String WidgetTypeName;
87 
88  /*************************************************************************
89  Constants
90  *************************************************************************/
91  // event names
130 
131  /*************************************************************************
132  Child Widget name constants
133  *************************************************************************/
134  static const String VertScrollbarName;
135  static const String HorzScrollbarName;
136 
137  /*************************************************************************
138  Accessor Methods
139  *************************************************************************/
147  size_t getItemCount(void) const {return d_listItems.size();}
148 
149 
157  size_t getSelectedCount(void) const;
158 
159 
168  ListboxItem* getFirstSelectedItem(void) const;
169 
170 
185  ListboxItem* getNextSelected(const ListboxItem* start_item) const;
186 
187 
200  ListboxItem* getListboxItemFromIndex(size_t index) const;
201 
202 
215  size_t getItemIndex(const ListboxItem* item) const;
216 
217 
225  bool isSortEnabled(void) const {return d_sorted;}
226 
234  bool isMultiselectEnabled(void) const {return d_multiselect;}
235 
236  bool isItemTooltipsEnabled(void) const {return d_itemTooltips;}
237 
250  bool isItemSelected(size_t index) const;
251 
252 
270  ListboxItem* findItemWithText(const String& text, const ListboxItem* start_item);
271 
272 
280  bool isListboxItemInList(const ListboxItem* item) const;
281 
282 
291  bool isVertScrollbarAlwaysShown(void) const;
292 
293 
302  bool isHorzScrollbarAlwaysShown(void) const;
303 
304 
305  /*************************************************************************
306  Manipulator Methods
307  *************************************************************************/
318  virtual void initialiseComponents(void);
319 
320 
327  void resetList(void);
328 
329 
341  void addItem(ListboxItem* item);
342 
343 
367  void insertItem(ListboxItem* item, const ListboxItem* position);
368 
369 
381  void removeItem(const ListboxItem* item);
382 
383 
391  void clearAllSelections(void);
392 
393 
404  void setSortingEnabled(bool setting);
405 
406 
418  void setMultiselectEnabled(bool setting);
419 
420 
432  void setShowVertScrollbar(bool setting);
433 
434 
446  void setShowHorzScrollbar(bool setting);
447 
448  void setItemTooltipsEnabled(bool setting);
468  void setItemSelectState(ListboxItem* item, bool state);
469 
470 
490  void setItemSelectState(size_t item_index, bool state);
491 
492 
505  void handleUpdatedItemData(void);
506 
507 
519  void ensureItemIsVisible(size_t item_index);
520 
521 
534  void ensureItemIsVisible(const ListboxItem* item);
535 
536 
546  virtual Rectf getListRenderArea(void) const;
547 
548 
560  Scrollbar* getVertScrollbar() const;
561 
573  Scrollbar* getHorzScrollbar() const;
574 
575 
580  float getTotalItemsHeight(void) const;
581 
582 
587  float getWidestItemWidth(void) const;
588 
589 
600  ListboxItem* getItemAtPoint(const Vector2f& pt) const;
601 
602 
603  /*************************************************************************
604  Construction and Destruction
605  *************************************************************************/
610  Listbox(const String& type, const String& name);
611 
612 
617  virtual ~Listbox(void);
618 
619 
620 protected:
621  /*************************************************************************
622  Abstract Implementation Functions (must be provided by derived class)
623  *************************************************************************/
633  //virtual Rect getListRenderArea_impl(void) const = 0;
634 
635 
636  /*************************************************************************
637  Implementation Functions
638  *************************************************************************/
643  void configureScrollbars(void);
644 
650  void selectRange(size_t start, size_t end);
651 
652 
660  bool clearAllSelections_impl(void);
661 
662 
674  bool resetList_impl(void);
675 
680  bool handle_scrollChange(const EventArgs& args);
681 
682 
683  // validate window renderer
684  virtual bool validateWindowRenderer(const WindowRenderer* renderer) const;
685 
690  void resortList();
691 
692  /*************************************************************************
693  New event handlers
694  *************************************************************************/
699  virtual void onListContentsChanged(WindowEventArgs& e);
700 
701 
706  virtual void onSelectionChanged(WindowEventArgs& e);
707 
708 
713  virtual void onSortModeChanged(WindowEventArgs& e);
714 
715 
720  virtual void onMultiselectModeChanged(WindowEventArgs& e);
721 
722 
727  virtual void onVertScrollbarModeChanged(WindowEventArgs& e);
728 
729 
734  virtual void onHorzScrollbarModeChanged(WindowEventArgs& e);
735 
736 
737  /*************************************************************************
738  Overridden Event handlers
739  *************************************************************************/
740  virtual void onSized(ElementEventArgs& e);
741  virtual void onMouseButtonDown(MouseEventArgs& e);
742  virtual void onMouseWheel(MouseEventArgs& e);
743  virtual void onMouseMove(MouseEventArgs& e);
744 
745 
746  /*************************************************************************
747  Implementation Data
748  *************************************************************************/
749  typedef std::vector<ListboxItem*
750  CEGUI_VECTOR_ALLOC(ListboxItem*)> LBItemList;
751  bool d_sorted;
756  LBItemList d_listItems;
758 
759  friend class ListboxWindowRenderer;
760 
761 private:
762 
763  /*************************************************************************
764  Private methods
765  *************************************************************************/
766  void addListboxProperties(void);
767 };
768 
769 
775 bool lbi_less(const ListboxItem* a, const ListboxItem* b);
776 
777 
783 bool lbi_greater(const ListboxItem* a, const ListboxItem* b);
784 
785 } // End of CEGUI namespace section
786 
787 
788 #if defined(_MSC_VER)
789 # pragma warning(pop)
790 #endif
791 
792 #endif // end of guard _CEGUIListbox_h_