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
00327 void insertItem(ListboxItem* item, const ListboxItem* position);
00328
00329
00341 void removeItem(const ListboxItem* item);
00342
00343
00351 void clearAllSelections(void);
00352
00353
00364 void setSortingEnabled(bool setting);
00365
00366
00378 void setMultiselectEnabled(bool setting);
00379
00380
00392 void setShowVertScrollbar(bool setting);
00393
00394
00406 void setShowHorzScrollbar(bool setting);
00407
00408 void setItemTooltipsEnabled(bool setting);
00428 void setItemSelectState(ListboxItem* item, bool state);
00429
00430
00450 void setItemSelectState(size_t item_index, bool state);
00451
00452
00465 void handleUpdatedItemData(void);
00466
00467
00479 void ensureItemIsVisible(size_t item_index);
00480
00481
00494 void ensureItemIsVisible(const ListboxItem* item);
00495
00496
00506 virtual Rect getListRenderArea(void) const;
00507
00508
00520 Scrollbar* getVertScrollbar() const;
00521
00533 Scrollbar* getHorzScrollbar() const;
00534
00535
00540 float getTotalItemsHeight(void) const;
00541
00542
00547 float getWidestItemWidth(void) const;
00548
00549
00550
00551
00552
00557 Listbox(const String& type, const String& name);
00558
00559
00564 virtual ~Listbox(void);
00565
00566
00567 protected:
00568
00569
00570
00580
00581
00582
00583
00584
00585
00590 void configureScrollbars(void);
00591
00597 void selectRange(size_t start, size_t end);
00598
00599
00607 bool clearAllSelections_impl(void);
00608
00609
00618 ListboxItem* getItemAtPoint(const Point& pt) const;
00619
00620
00632 bool resetList_impl(void);
00633
00634
00645 virtual bool testClassName_impl(const String& class_name) const
00646 {
00647 if (class_name=="Listbox") return true;
00648 return Window::testClassName_impl(class_name);
00649 }
00650
00655 bool handle_scrollChange(const EventArgs& args);
00656
00657
00658
00659 virtual bool validateWindowRenderer(const String& name) const
00660 {
00661 return (name == "Listbox");
00662 }
00663
00668 void resortList();
00669
00670
00671
00672
00677 virtual void onListContentsChanged(WindowEventArgs& e);
00678
00679
00684 virtual void onSelectionChanged(WindowEventArgs& e);
00685
00686
00691 virtual void onSortModeChanged(WindowEventArgs& e);
00692
00693
00698 virtual void onMultiselectModeChanged(WindowEventArgs& e);
00699
00700
00705 virtual void onVertScrollbarModeChanged(WindowEventArgs& e);
00706
00707
00712 virtual void onHorzScrollbarModeChanged(WindowEventArgs& e);
00713
00714
00715
00716
00717
00718 virtual void onSized(WindowEventArgs& e);
00719 virtual void onMouseButtonDown(MouseEventArgs& e);
00720 virtual void onMouseWheel(MouseEventArgs& e);
00721 virtual void onMouseMove(MouseEventArgs& e);
00722
00723
00724
00725
00726
00727 typedef std::vector<ListboxItem*> LBItemList;
00728 bool d_sorted;
00729 bool d_multiselect;
00730 bool d_forceVertScroll;
00731 bool d_forceHorzScroll;
00732 bool d_itemTooltips;
00733 LBItemList d_listItems;
00734 ListboxItem* d_lastSelected;
00735
00736 friend class ListboxWindowRenderer;
00737
00738 private:
00739
00740
00741
00742 static ListboxProperties::Sort d_sortProperty;
00743 static ListboxProperties::MultiSelect d_multiSelectProperty;
00744 static ListboxProperties::ForceVertScrollbar d_forceVertProperty;
00745 static ListboxProperties::ForceHorzScrollbar d_forceHorzProperty;
00746 static ListboxProperties::ItemTooltips d_itemTooltipsProperty;
00747
00748
00749
00750
00751 void addListboxProperties(void);
00752 };
00753
00754
00760 bool lbi_less(const ListboxItem* a, const ListboxItem* b);
00761
00762
00768 bool lbi_greater(const ListboxItem* a, const ListboxItem* b);
00769
00770 }
00771
00772
00773 #if defined(_MSC_VER)
00774 # pragma warning(pop)
00775 #endif
00776
00777 #endif // end of guard _CEGUIListbox_h_