00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef _CEGUIListbox_h_
00031 #define _CEGUIListbox_h_
00032
00033 #include "CEGUIBase.h"
00034 #include "CEGUIWindow.h"
00035 #include "elements/CEGUIListboxProperties.h"
00036 #include <vector>
00037
00038
00039 #if defined(_MSC_VER)
00040 # pragma warning(push)
00041 # pragma warning(disable : 4251)
00042 #endif
00043
00044
00045
00046 namespace CEGUI
00047 {
00048
00053 class CEGUIEXPORT ListboxWindowRenderer : public WindowRenderer
00054 {
00055 public:
00060 ListboxWindowRenderer(const String& name);
00061
00071 virtual Rect getListRenderArea(void) const = 0;
00072 };
00073
00078 class CEGUIEXPORT Listbox : public Window
00079 {
00080 public:
00081 static const String EventNamespace;
00082 static const String WidgetTypeName;
00083
00084
00085
00086
00087
00088 static const String EventListContentsChanged;
00089 static const String EventSelectionChanged;
00090 static const String EventSortModeChanged;
00091 static const String EventMultiselectModeChanged;
00092 static const String EventVertScrollbarModeChanged;
00093 static const String EventHorzScrollbarModeChanged;
00094
00095
00096
00097
00098 static const String VertScrollbarNameSuffix;
00099 static const String HorzScrollbarNameSuffix;
00100
00101
00102
00103
00111 size_t getItemCount(void) const {return d_listItems.size();}
00112
00113
00121 size_t getSelectedCount(void) const;
00122
00123
00132 ListboxItem* getFirstSelectedItem(void) const;
00133
00134
00149 ListboxItem* getNextSelected(const ListboxItem* start_item) const;
00150
00151
00164 ListboxItem* getListboxItemFromIndex(size_t index) const;
00165
00166
00179 size_t getItemIndex(const ListboxItem* item) const;
00180
00181
00189 bool isSortEnabled(void) const {return d_sorted;}
00190
00198 bool isMultiselectEnabled(void) const {return d_multiselect;}
00199
00200 bool isItemTooltipsEnabled(void) const {return d_itemTooltips;}
00201
00214 bool isItemSelected(size_t index) const;
00215
00216
00234 ListboxItem* findItemWithText(const String& text, const ListboxItem* start_item);
00235
00236
00244 bool isListboxItemInList(const ListboxItem* item) const;
00245
00246
00255 bool isVertScrollbarAlwaysShown(void) const;
00256
00257
00266 bool isHorzScrollbarAlwaysShown(void) const;
00267
00268
00269
00270
00271
00282 virtual void initialiseComponents(void);
00283
00284
00291 void resetList(void);
00292
00293
00305 void addItem(ListboxItem* item);
00306
00307
00331 void insertItem(ListboxItem* item, const ListboxItem* position);
00332
00333
00345 void removeItem(const ListboxItem* item);
00346
00347
00355 void clearAllSelections(void);
00356
00357
00368 void setSortingEnabled(bool setting);
00369
00370
00382 void setMultiselectEnabled(bool setting);
00383
00384
00396 void setShowVertScrollbar(bool setting);
00397
00398
00410 void setShowHorzScrollbar(bool setting);
00411
00412 void setItemTooltipsEnabled(bool setting);
00432 void setItemSelectState(ListboxItem* item, bool state);
00433
00434
00454 void setItemSelectState(size_t item_index, bool state);
00455
00456
00469 void handleUpdatedItemData(void);
00470
00471
00483 void ensureItemIsVisible(size_t item_index);
00484
00485
00498 void ensureItemIsVisible(const ListboxItem* item);
00499
00500
00510 virtual Rect getListRenderArea(void) const;
00511
00512
00524 Scrollbar* getVertScrollbar() const;
00525
00537 Scrollbar* getHorzScrollbar() const;
00538
00539
00544 float getTotalItemsHeight(void) const;
00545
00546
00551 float getWidestItemWidth(void) const;
00552
00553
00554
00555
00556
00561 Listbox(const String& type, const String& name);
00562
00563
00568 virtual ~Listbox(void);
00569
00570
00571 protected:
00572
00573
00574
00584
00585
00586
00587
00588
00589
00594 void configureScrollbars(void);
00595
00601 void selectRange(size_t start, size_t end);
00602
00603
00611 bool clearAllSelections_impl(void);
00612
00613
00622 ListboxItem* getItemAtPoint(const Point& pt) const;
00623
00624
00636 bool resetList_impl(void);
00637
00638
00649 virtual bool testClassName_impl(const String& class_name) const
00650 {
00651 if (class_name=="Listbox") return true;
00652 return Window::testClassName_impl(class_name);
00653 }
00654
00659 bool handle_scrollChange(const EventArgs& args);
00660
00661
00662
00663 virtual bool validateWindowRenderer(const String& name) const
00664 {
00665 return (name == "Listbox");
00666 }
00667
00672 void resortList();
00673
00674
00675
00676
00681 virtual void onListContentsChanged(WindowEventArgs& e);
00682
00683
00688 virtual void onSelectionChanged(WindowEventArgs& e);
00689
00690
00695 virtual void onSortModeChanged(WindowEventArgs& e);
00696
00697
00702 virtual void onMultiselectModeChanged(WindowEventArgs& e);
00703
00704
00709 virtual void onVertScrollbarModeChanged(WindowEventArgs& e);
00710
00711
00716 virtual void onHorzScrollbarModeChanged(WindowEventArgs& e);
00717
00718
00719
00720
00721
00722 virtual void onSized(WindowEventArgs& e);
00723 virtual void onMouseButtonDown(MouseEventArgs& e);
00724 virtual void onMouseWheel(MouseEventArgs& e);
00725 virtual void onMouseMove(MouseEventArgs& e);
00726
00727
00728
00729
00730
00731 typedef std::vector<ListboxItem*> LBItemList;
00732 bool d_sorted;
00733 bool d_multiselect;
00734 bool d_forceVertScroll;
00735 bool d_forceHorzScroll;
00736 bool d_itemTooltips;
00737 LBItemList d_listItems;
00738 ListboxItem* d_lastSelected;
00739
00740 friend class ListboxWindowRenderer;
00741
00742 private:
00743
00744
00745
00746 static ListboxProperties::Sort d_sortProperty;
00747 static ListboxProperties::MultiSelect d_multiSelectProperty;
00748 static ListboxProperties::ForceVertScrollbar d_forceVertProperty;
00749 static ListboxProperties::ForceHorzScrollbar d_forceHorzProperty;
00750 static ListboxProperties::ItemTooltips d_itemTooltipsProperty;
00751
00752
00753
00754
00755 void addListboxProperties(void);
00756 };
00757
00758
00764 bool lbi_less(const ListboxItem* a, const ListboxItem* b);
00765
00766
00772 bool lbi_greater(const ListboxItem* a, const ListboxItem* b);
00773
00774 }
00775
00776
00777 #if defined(_MSC_VER)
00778 # pragma warning(pop)
00779 #endif
00780
00781 #endif // end of guard _CEGUIListbox_h_