Crazy Eddie's GUI System  0.8.4
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
widgets/Listbox.h
1 /***********************************************************************
2  created: 13/4/2004
3  author: Paul D Turner
4 
5  purpose: Interface to base class for Listbox widget
6 *************************************************************************/
7 /***************************************************************************
8  * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining
11  * a copy of this software and associated documentation files (the
12  * "Software"), to deal in the Software without restriction, including
13  * without limitation the rights to use, copy, modify, merge, publish,
14  * distribute, sublicense, and/or sell copies of the Software, and to
15  * permit persons to whom the Software is furnished to do so, subject to
16  * the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be
19  * included in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27  * OTHER DEALINGS IN THE SOFTWARE.
28  ***************************************************************************/
29 #ifndef _CEGUIListbox_h_
30 #define _CEGUIListbox_h_
31 
32 #include "../Base.h"
33 #include "../Window.h"
34 #include <vector>
35 
36 
37 #if defined(_MSC_VER)
38 # pragma warning(push)
39 # pragma warning(disable : 4251)
40 #endif
41 
42 
43 // Start of CEGUI namespace section
44 namespace CEGUI
45 {
46 
51 class CEGUIEXPORT ListboxWindowRenderer : public WindowRenderer
52 {
53 public:
58  ListboxWindowRenderer(const String& name);
59 
65  virtual Rectf getListRenderArea(void) const = 0;
66 
73  virtual void resizeListToContent(bool fit_width,
74  bool fit_height) const = 0;
75 };
76 
81 class CEGUIEXPORT Listbox : public Window
82 {
83 public:
84  static const String EventNamespace;
85  static const String WidgetTypeName;
86 
87  /*************************************************************************
88  Constants
89  *************************************************************************/
90  // event names
129 
130  /*************************************************************************
131  Child Widget name constants
132  *************************************************************************/
133  static const String VertScrollbarName;
134  static const String HorzScrollbarName;
135 
136  /*************************************************************************
137  Accessor Methods
138  *************************************************************************/
146  size_t getItemCount(void) const {return d_listItems.size();}
147 
148 
156  size_t getSelectedCount(void) const;
157 
158 
167  ListboxItem* getFirstSelectedItem(void) const;
168 
169 
184  ListboxItem* getNextSelected(const ListboxItem* start_item) const;
185 
186 
199  ListboxItem* getListboxItemFromIndex(size_t index) const;
200 
201 
214  size_t getItemIndex(const ListboxItem* item) const;
215 
216 
224  bool isSortEnabled(void) const {return d_sorted;}
225 
233  bool isMultiselectEnabled(void) const {return d_multiselect;}
234 
235  bool isItemTooltipsEnabled(void) const {return d_itemTooltips;}
236 
249  bool isItemSelected(size_t index) const;
250 
251 
269  ListboxItem* findItemWithText(const String& text, const ListboxItem* start_item);
270 
271 
279  bool isListboxItemInList(const ListboxItem* item) const;
280 
281 
290  bool isVertScrollbarAlwaysShown(void) const;
291 
292 
301  bool isHorzScrollbarAlwaysShown(void) const;
302 
303 
304  /*************************************************************************
305  Manipulator Methods
306  *************************************************************************/
317  virtual void initialiseComponents(void);
318 
319 
326  void resetList(void);
327 
328 
340  void addItem(ListboxItem* item);
341 
342 
366  void insertItem(ListboxItem* item, const ListboxItem* position);
367 
368 
380  void removeItem(const ListboxItem* item);
381 
382 
390  void clearAllSelections(void);
391 
392 
403  void setSortingEnabled(bool setting);
404 
405 
417  void setMultiselectEnabled(bool setting);
418 
419 
431  void setShowVertScrollbar(bool setting);
432 
433 
445  void setShowHorzScrollbar(bool setting);
446 
447  void setItemTooltipsEnabled(bool setting);
467  void setItemSelectState(ListboxItem* item, bool state);
468 
469 
489  void setItemSelectState(size_t item_index, bool state);
490 
491 
504  void handleUpdatedItemData(void);
505 
506 
518  void ensureItemIsVisible(size_t item_index);
519 
520 
533  void ensureItemIsVisible(const ListboxItem* item);
534 
535 
545  virtual Rectf getListRenderArea(void) const;
546 
547 
559  Scrollbar* getVertScrollbar() const;
560 
572  Scrollbar* getHorzScrollbar() const;
573 
574 
579  float getTotalItemsHeight(void) const;
580 
581 
586  float getWidestItemWidth(void) const;
587 
588 
599  ListboxItem* getItemAtPoint(const Vector2f& pt) const;
600 
601 
602  /*************************************************************************
603  Construction and Destruction
604  *************************************************************************/
609  Listbox(const String& type, const String& name);
610 
611 
616  virtual ~Listbox(void);
617 
618 
619 protected:
620  /*************************************************************************
621  Abstract Implementation Functions (must be provided by derived class)
622  *************************************************************************/
632  //virtual Rect getListRenderArea_impl(void) const = 0;
633 
634 
635  /*************************************************************************
636  Implementation Functions
637  *************************************************************************/
642  void configureScrollbars(void);
643 
649  void selectRange(size_t start, size_t end);
650 
651 
659  bool clearAllSelections_impl(void);
660 
661 
673  bool resetList_impl(void);
674 
679  bool handle_scrollChange(const EventArgs& args);
680 
681 
682  // validate window renderer
683  virtual bool validateWindowRenderer(const WindowRenderer* renderer) const;
684 
689  void resortList();
690 
691  /*************************************************************************
692  New event handlers
693  *************************************************************************/
698  virtual void onListContentsChanged(WindowEventArgs& e);
699 
700 
705  virtual void onSelectionChanged(WindowEventArgs& e);
706 
707 
712  virtual void onSortModeChanged(WindowEventArgs& e);
713 
714 
719  virtual void onMultiselectModeChanged(WindowEventArgs& e);
720 
721 
726  virtual void onVertScrollbarModeChanged(WindowEventArgs& e);
727 
728 
733  virtual void onHorzScrollbarModeChanged(WindowEventArgs& e);
734 
735 
736  /*************************************************************************
737  Overridden Event handlers
738  *************************************************************************/
739  virtual void onSized(ElementEventArgs& e);
740  virtual void onMouseButtonDown(MouseEventArgs& e);
741  virtual void onMouseWheel(MouseEventArgs& e);
742  virtual void onMouseMove(MouseEventArgs& e);
743 
744 
745  /*************************************************************************
746  Implementation Data
747  *************************************************************************/
748  typedef std::vector<ListboxItem*
749  CEGUI_VECTOR_ALLOC(ListboxItem*)> LBItemList;
750  bool d_sorted;
755  LBItemList d_listItems;
757 
758  friend class ListboxWindowRenderer;
759 
760 private:
761 
762  /*************************************************************************
763  Private methods
764  *************************************************************************/
765  void addListboxProperties(void);
766 };
767 
768 
774 bool lbi_less(const ListboxItem* a, const ListboxItem* b);
775 
776 
782 bool lbi_greater(const ListboxItem* a, const ListboxItem* b);
783 
784 } // End of CEGUI namespace section
785 
786 
787 #if defined(_MSC_VER)
788 # pragma warning(pop)
789 #endif
790 
791 #endif // end of guard _CEGUIListbox_h_