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 "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
00092 static const String EventListContentsChanged;
00099 static const String EventSelectionChanged;
00105 static const String EventSortModeChanged;
00111 static const String EventMultiselectModeChanged;
00118 static const String EventVertScrollbarModeChanged;
00125 static const String EventHorzScrollbarModeChanged;
00126
00127
00128
00129
00130 static const String VertScrollbarNameSuffix;
00131 static const String HorzScrollbarNameSuffix;
00132
00133
00134
00135
00143 size_t getItemCount(void) const {return d_listItems.size();}
00144
00145
00153 size_t getSelectedCount(void) const;
00154
00155
00164 ListboxItem* getFirstSelectedItem(void) const;
00165
00166
00181 ListboxItem* getNextSelected(const ListboxItem* start_item) const;
00182
00183
00196 ListboxItem* getListboxItemFromIndex(size_t index) const;
00197
00198
00211 size_t getItemIndex(const ListboxItem* item) const;
00212
00213
00221 bool isSortEnabled(void) const {return d_sorted;}
00222
00230 bool isMultiselectEnabled(void) const {return d_multiselect;}
00231
00232 bool isItemTooltipsEnabled(void) const {return d_itemTooltips;}
00233
00246 bool isItemSelected(size_t index) const;
00247
00248
00266 ListboxItem* findItemWithText(const String& text, const ListboxItem* start_item);
00267
00268
00276 bool isListboxItemInList(const ListboxItem* item) const;
00277
00278
00287 bool isVertScrollbarAlwaysShown(void) const;
00288
00289
00298 bool isHorzScrollbarAlwaysShown(void) const;
00299
00300
00301
00302
00303
00314 virtual void initialiseComponents(void);
00315
00316
00323 void resetList(void);
00324
00325
00337 void addItem(ListboxItem* item);
00338
00339
00363 void insertItem(ListboxItem* item, const ListboxItem* position);
00364
00365
00377 void removeItem(const ListboxItem* item);
00378
00379
00387 void clearAllSelections(void);
00388
00389
00400 void setSortingEnabled(bool setting);
00401
00402
00414 void setMultiselectEnabled(bool setting);
00415
00416
00428 void setShowVertScrollbar(bool setting);
00429
00430
00442 void setShowHorzScrollbar(bool setting);
00443
00444 void setItemTooltipsEnabled(bool setting);
00464 void setItemSelectState(ListboxItem* item, bool state);
00465
00466
00486 void setItemSelectState(size_t item_index, bool state);
00487
00488
00501 void handleUpdatedItemData(void);
00502
00503
00515 void ensureItemIsVisible(size_t item_index);
00516
00517
00530 void ensureItemIsVisible(const ListboxItem* item);
00531
00532
00542 virtual Rect getListRenderArea(void) const;
00543
00544
00556 Scrollbar* getVertScrollbar() const;
00557
00569 Scrollbar* getHorzScrollbar() const;
00570
00571
00576 float getTotalItemsHeight(void) const;
00577
00578
00583 float getWidestItemWidth(void) const;
00584
00585
00596 ListboxItem* getItemAtPoint(const Point& pt) const;
00597
00598
00599
00600
00601
00606 Listbox(const String& type, const String& name);
00607
00608
00613 virtual ~Listbox(void);
00614
00615
00616 protected:
00617
00618
00619
00629
00630
00631
00632
00633
00634
00639 void configureScrollbars(void);
00640
00646 void selectRange(size_t start, size_t end);
00647
00648
00656 bool clearAllSelections_impl(void);
00657
00658
00670 bool resetList_impl(void);
00671
00672
00683 virtual bool testClassName_impl(const String& class_name) const
00684 {
00685 if (class_name=="Listbox") return true;
00686 return Window::testClassName_impl(class_name);
00687 }
00688
00693 bool handle_scrollChange(const EventArgs& args);
00694
00695
00696
00697 virtual bool validateWindowRenderer(const String& name) const
00698 {
00699 return (name == "Listbox");
00700 }
00701
00706 void resortList();
00707
00708
00709
00710
00715 virtual void onListContentsChanged(WindowEventArgs& e);
00716
00717
00722 virtual void onSelectionChanged(WindowEventArgs& e);
00723
00724
00729 virtual void onSortModeChanged(WindowEventArgs& e);
00730
00731
00736 virtual void onMultiselectModeChanged(WindowEventArgs& e);
00737
00738
00743 virtual void onVertScrollbarModeChanged(WindowEventArgs& e);
00744
00745
00750 virtual void onHorzScrollbarModeChanged(WindowEventArgs& e);
00751
00752
00753
00754
00755
00756 virtual void onSized(WindowEventArgs& e);
00757 virtual void onMouseButtonDown(MouseEventArgs& e);
00758 virtual void onMouseWheel(MouseEventArgs& e);
00759 virtual void onMouseMove(MouseEventArgs& e);
00760
00761
00762
00763
00764
00765 typedef std::vector<ListboxItem*> LBItemList;
00766 bool d_sorted;
00767 bool d_multiselect;
00768 bool d_forceVertScroll;
00769 bool d_forceHorzScroll;
00770 bool d_itemTooltips;
00771 LBItemList d_listItems;
00772 ListboxItem* d_lastSelected;
00773
00774 friend class ListboxWindowRenderer;
00775
00776 private:
00777
00778
00779
00780 static ListboxProperties::Sort d_sortProperty;
00781 static ListboxProperties::MultiSelect d_multiSelectProperty;
00782 static ListboxProperties::ForceVertScrollbar d_forceVertProperty;
00783 static ListboxProperties::ForceHorzScrollbar d_forceHorzProperty;
00784 static ListboxProperties::ItemTooltips d_itemTooltipsProperty;
00785
00786
00787
00788
00789 void addListboxProperties(void);
00790 };
00791
00792
00798 bool lbi_less(const ListboxItem* a, const ListboxItem* b);
00799
00800
00806 bool lbi_greater(const ListboxItem* a, const ListboxItem* b);
00807
00808 }
00809
00810
00811 #if defined(_MSC_VER)
00812 # pragma warning(pop)
00813 #endif
00814
00815 #endif // end of guard _CEGUIListbox_h_