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 #ifndef _CEGUIListbox_h_
00027 #define _CEGUIListbox_h_
00028
00029 #include "CEGUIBase.h"
00030 #include "CEGUIWindow.h"
00031 #include "elements/CEGUIListboxProperties.h"
00032 #include <vector>
00033
00034
00035 #if defined(_MSC_VER)
00036 # pragma warning(push)
00037 # pragma warning(disable : 4251)
00038 #endif
00039
00040
00041
00042 namespace CEGUI
00043 {
00044
00049 class CEGUIEXPORT Listbox : public Window
00050 {
00051 public:
00052 static const String EventNamespace;
00053
00054
00055
00056
00057
00058
00059 static const String EventListContentsChanged;
00060 static const String EventSelectionChanged;
00061 static const String EventSortModeChanged;
00062 static const String EventMultiselectModeChanged;
00063 static const String EventVertScrollbarModeChanged;
00064 static const String EventHorzScrollbarModeChanged;
00065
00066
00067
00068
00069
00077 size_t getItemCount(void) const {return d_listItems.size();}
00078
00079
00087 size_t getSelectedCount(void) const;
00088
00089
00098 ListboxItem* getFirstSelectedItem(void) const;
00099
00100
00115 ListboxItem* getNextSelected(const ListboxItem* start_item) const;
00116
00117
00130 ListboxItem* getListboxItemFromIndex(size_t index) const;
00131
00132
00145 size_t getItemIndex(const ListboxItem* item) const;
00146
00147
00155 bool isSortEnabled(void) const {return d_sorted;}
00156
00164 bool isMultiselectEnabled(void) const {return d_multiselect;}
00165
00166 bool isItemTooltipsEnabled(void) const {return d_itemTooltips;}
00167
00180 bool isItemSelected(size_t index) const;
00181
00182
00200 ListboxItem* findItemWithText(const String& text, const ListboxItem* start_item);
00201
00202
00210 bool isListboxItemInList(const ListboxItem* item) const;
00211
00212
00221 bool isVertScrollbarAlwaysShown(void) const;
00222
00223
00232 bool isHorzScrollbarAlwaysShown(void) const;
00233
00234
00235
00236
00237
00248 virtual void initialise(void);
00249
00250
00257 void resetList(void);
00258
00259
00271 void addItem(ListboxItem* item);
00272
00273
00293 void insertItem(ListboxItem* item, const ListboxItem* position);
00294
00295
00307 void removeItem(const ListboxItem* item);
00308
00309
00317 void clearAllSelections(void);
00318
00319
00330 void setSortingEnabled(bool setting);
00331
00332
00344 void setMultiselectEnabled(bool setting);
00345
00346
00358 void setShowVertScrollbar(bool setting);
00359
00360
00372 void setShowHorzScrollbar(bool setting);
00373
00374 void setItemTooltipsEnabled(bool setting);
00394 void setItemSelectState(ListboxItem* item, bool state);
00395
00396
00416 void setItemSelectState(size_t item_index, bool state);
00417
00418
00431 void handleUpdatedItemData(void);
00432
00433
00445 void ensureItemIsVisible(size_t item_index);
00446
00447
00460 void ensureItemIsVisible(const ListboxItem* item);
00461
00462
00463
00464
00465
00470 Listbox(const String& type, const String& name);
00471
00472
00477 virtual ~Listbox(void);
00478
00479
00480 protected:
00481
00482
00483
00493 virtual Rect getListRenderArea(void) const = 0;
00494
00495
00506 virtual Scrollbar* createVertScrollbar(const String& name) const = 0;
00507
00508
00519 virtual Scrollbar* createHorzScrollbar(const String& name) const = 0;
00520
00521
00532 virtual void cacheListboxBaseImagery() = 0;
00533
00534
00535
00536
00537
00542 void addListboxEvents(void);
00543
00544
00549 void configureScrollbars(void);
00550
00556 void selectRange(size_t start, size_t end);
00557
00558
00563 float getTotalItemsHeight(void) const;
00564
00565
00570 float getWidestItemWidth(void) const;
00571
00572
00580 bool clearAllSelections_impl(void);
00581
00582
00591 ListboxItem* getItemAtPoint(const Point& pt) const;
00592
00593
00605 bool resetList_impl(void);
00606
00607
00618 virtual bool testClassName_impl(const String& class_name) const
00619 {
00620 if (class_name==(const utf8*)"Listbox") return true;
00621 return Window::testClassName_impl(class_name);
00622 }
00623
00628 bool handle_scrollChange(const EventArgs& args);
00629
00630
00631 void populateRenderCache();
00632
00633
00634
00635
00636
00641 virtual void onListContentsChanged(WindowEventArgs& e);
00642
00643
00648 virtual void onSelectionChanged(WindowEventArgs& e);
00649
00650
00655 virtual void onSortModeChanged(WindowEventArgs& e);
00656
00657
00662 virtual void onMultiselectModeChanged(WindowEventArgs& e);
00663
00664
00669 virtual void onVertScrollbarModeChanged(WindowEventArgs& e);
00670
00671
00676 virtual void onHorzScrollbarModeChanged(WindowEventArgs& e);
00677
00678
00679
00680
00681
00682 virtual void onSized(WindowEventArgs& e);
00683 virtual void onMouseButtonDown(MouseEventArgs& e);
00684 virtual void onMouseWheel(MouseEventArgs& e);
00685 virtual void onMouseMove(MouseEventArgs& e);
00686
00687
00688
00689
00690
00691 typedef std::vector<ListboxItem*> LBItemList;
00692 bool d_sorted;
00693 bool d_multiselect;
00694 bool d_forceVertScroll;
00695 bool d_forceHorzScroll;
00696 bool d_itemTooltips;
00697 Scrollbar* d_vertScrollbar;
00698 Scrollbar* d_horzScrollbar;
00699 LBItemList d_listItems;
00700 ListboxItem* d_lastSelected;
00701
00702
00703 private:
00704
00705
00706
00707 static ListboxProperties::Sort d_sortProperty;
00708 static ListboxProperties::MultiSelect d_multiSelectProperty;
00709 static ListboxProperties::ForceVertScrollbar d_forceVertProperty;
00710 static ListboxProperties::ForceHorzScrollbar d_forceHorzProperty;
00711 static ListboxProperties::ItemTooltips d_itemTooltipsProperty;
00712
00713
00714
00715
00716 void addListboxProperties(void);
00717 };
00718
00719
00725 bool lbi_less(const ListboxItem* a, const ListboxItem* b);
00726
00727
00733 bool lbi_greater(const ListboxItem* a, const ListboxItem* b);
00734
00735 }
00736
00737
00738 #if defined(_MSC_VER)
00739 # pragma warning(pop)
00740 #endif
00741
00742 #endif // end of guard _CEGUIListbox_h_