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 #ifndef _CEGUITree_h_
00029 #define _CEGUITree_h_
00030
00031 #include "CEGUIBase.h"
00032 #include "CEGUIWindow.h"
00033 #include "CEGUIWindowManager.h"
00034 #include "elements/CEGUITreeItem.h"
00035 #include "elements/CEGUITreeProperties.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 class ImagerySection;
00049
00055 class CEGUIEXPORT TreeEventArgs : public WindowEventArgs
00056 {
00057 public:
00058 TreeEventArgs(Window* wnd) : WindowEventArgs(wnd) { treeItem = 0; }
00059 TreeItem *treeItem;
00060 };
00061
00062
00067 class CEGUIEXPORT Tree : public Window
00068 {
00069 friend class TreeItem;
00070 typedef std::vector<TreeItem*> LBItemList;
00071
00072 public:
00073 static const String EventNamespace;
00074 static const String WidgetTypeName;
00075
00076
00077
00078
00079
00080 static const String EventListContentsChanged;
00081 static const String EventSelectionChanged;
00082 static const String EventSortModeChanged;
00083 static const String EventMultiselectModeChanged;
00084 static const String EventVertScrollbarModeChanged;
00085 static const String EventHorzScrollbarModeChanged;
00086 static const String EventBranchOpened;
00087 static const String EventBranchClosed;
00088
00089
00090 void doTreeRender() { populateRenderCache(); }
00091
00092 void doScrollbars() { configureScrollbars(); }
00093
00094
00095
00103 size_t getItemCount(void) const {return d_listItems.size();}
00104
00105
00113 size_t getSelectedCount(void) const;
00114
00115
00124 TreeItem* getFirstSelectedItem(void) const;
00125
00126
00135 TreeItem* getLastSelectedItem(void) const { return d_lastSelected; }
00136
00137
00152 TreeItem* getNextSelected(const TreeItem* start_item) const;
00153
00154
00155 TreeItem* getNextSelectedItemFromList(const LBItemList &itemList, const TreeItem* start_item, bool foundStartItem) const;
00156
00164 bool isSortEnabled(void) const {return d_sorted;}
00165
00166 void setItemRenderArea(Rect& r)
00167 {
00168 d_itemArea = r;
00169 }
00170
00171 Scrollbar* getVertScrollbar() { return d_vertScrollbar; }
00172 Scrollbar* getHorzScrollbar() { return d_horzScrollbar; }
00173
00181 bool isMultiselectEnabled(void) const {return d_multiselect;}
00182
00183 bool isItemTooltipsEnabled(void) const {return d_itemTooltips;}
00184
00185
00203 TreeItem* findFirstItemWithText(const String& text);
00204 TreeItem* findNextItemWithText(const String& text, const TreeItem* start_item);
00205 TreeItem* findItemWithTextFromList(const LBItemList &itemList, const String& text, const TreeItem* start_item, bool foundStartItem);
00206
00207
00225 TreeItem* findFirstItemWithID(uint searchID);
00226 TreeItem* findNextItemWithID(uint searchID, const TreeItem* start_item);
00227 TreeItem* findItemWithIDFromList(const LBItemList &itemList, uint searchID, const TreeItem* start_item, bool foundStartItem);
00228
00229
00237 bool isTreeItemInList(const TreeItem* item) const;
00238
00239
00248 bool isVertScrollbarAlwaysShown(void) const;
00249
00250
00259 bool isHorzScrollbarAlwaysShown(void) const;
00260
00261
00262
00263
00264
00275 virtual void initialise(void);
00276
00277
00284 void resetList(void);
00285
00286
00298 void addItem(TreeItem* item);
00299
00300
00320 void insertItem(TreeItem* item, const TreeItem* position);
00321
00322
00334 void removeItem(const TreeItem* item);
00335
00336
00344 void clearAllSelections(void);
00345 bool clearAllSelectionsFromList(const LBItemList &itemList);
00346
00347
00358 void setSortingEnabled(bool setting);
00359
00360
00372 void setMultiselectEnabled(bool setting);
00373
00374
00386 void setShowVertScrollbar(bool setting);
00387
00388
00400 void setShowHorzScrollbar(bool setting);
00401
00402 void setItemTooltipsEnabled(bool setting);
00422 void setItemSelectState(TreeItem* item, bool state);
00423
00424
00444 void setItemSelectState(size_t item_index, bool state);
00445
00462 virtual void setLookNFeel(const String& look);
00463
00476 void handleUpdatedItemData(void);
00477
00478
00491 void ensureItemIsVisible(const TreeItem* item);
00492
00493
00494
00495
00496
00501 Tree(const String& type, const String& name);
00502
00503
00508 virtual ~Tree(void);
00509
00510
00511 protected:
00512
00513
00514
00524 virtual Rect getTreeRenderArea(void) const
00525 {
00526 return d_itemArea;
00527 }
00528
00539 virtual Scrollbar* createVertScrollbar(const String& name) const
00540 {
00541 return (Scrollbar*)(WindowManager::getSingleton().getWindow(name));
00542 }
00543
00554 virtual Scrollbar* createHorzScrollbar(const String& name) const
00555 {
00556 return (Scrollbar*)(WindowManager::getSingleton().getWindow(name));
00557 }
00558
00559
00570 virtual void cacheTreeBaseImagery()
00571 {
00572
00573 }
00574
00575
00576
00577
00578
00579
00580
00585 void addTreeEvents(void);
00586
00587
00592 void configureScrollbars(void);
00593
00599 void selectRange(size_t start, size_t end);
00600
00601
00606 float getTotalItemsHeight(void) const;
00607 void getTotalItemsInListHeight(const LBItemList &itemList, float *heightSum) const;
00608
00609
00614 float getWidestItemWidth(void) const;
00615 void getWidestItemWidthInList(const LBItemList &itemList, int itemDepth, float *widest) const;
00616
00624 bool getHeightToItemInList(const LBItemList &itemList, const TreeItem *treeItem, int itemDepth, float *height) const;
00625
00626
00634 bool clearAllSelections_impl(void);
00635
00636
00645 TreeItem* getItemAtPoint(const Point& pt) const;
00646 TreeItem* getItemFromListAtPoint(const LBItemList &itemList, float *bottomY, const Point& pt) const;
00647
00648
00660 bool resetList_impl(void);
00661
00662
00673 virtual bool testClassName_impl(const String& class_name) const
00674 {
00675 if (class_name==(const utf8*)"Tree") return true;
00676 return Window::testClassName_impl(class_name);
00677 }
00678
00683 bool handle_scrollChange(const EventArgs& args);
00684
00685
00686 virtual void populateRenderCache();
00687
00688 void drawItemList(LBItemList &itemList, Rect &itemsArea, float widest, Vector3 &itemPos, RenderCache& cache, float alpha);
00689
00690
00691
00692
00693
00698 virtual void onListContentsChanged(WindowEventArgs& e);
00699
00700
00705 virtual void onSelectionChanged(TreeEventArgs& e);
00706
00707
00712 virtual void onSortModeChanged(WindowEventArgs& e);
00713
00714
00719 virtual void onMultiselectModeChanged(WindowEventArgs& e);
00720
00721
00726 virtual void onVertScrollbarModeChanged(WindowEventArgs& e);
00727
00728
00733 virtual void onHorzScrollbarModeChanged(WindowEventArgs& e);
00734
00739 virtual void onBranchOpened(TreeEventArgs& e);
00740
00745 virtual void onBranchClosed(TreeEventArgs& e);
00746
00747
00748
00749
00750
00751
00752 virtual void onSized(WindowEventArgs& e);
00753 virtual void onMouseButtonDown(MouseEventArgs& e);
00754 virtual void onMouseWheel(MouseEventArgs& e);
00755 virtual void onMouseMove(MouseEventArgs& e);
00756
00757
00758
00759
00760
00761 bool d_sorted;
00762 bool d_multiselect;
00763 bool d_forceVertScroll;
00764 bool d_forceHorzScroll;
00765 bool d_itemTooltips;
00766 Scrollbar* d_vertScrollbar;
00767 Scrollbar* d_horzScrollbar;
00768 LBItemList d_listItems;
00769 TreeItem* d_lastSelected;
00770 ImagerySection *openButtonImagery;
00771 ImagerySection *closeButtonImagery;
00772
00773
00774 private:
00775
00776
00777
00778 static TreeProperties::Sort d_sortProperty;
00779 static TreeProperties::MultiSelect d_multiSelectProperty;
00780 static TreeProperties::ForceVertScrollbar d_forceVertProperty;
00781 static TreeProperties::ForceHorzScrollbar d_forceHorzProperty;
00782 static TreeProperties::ItemTooltips d_itemTooltipsProperty;
00783
00784
00785
00786
00787 void addTreeProperties(void);
00788 Rect d_itemArea;
00789 };
00790
00791
00797 bool lbi_less(const TreeItem* a, const TreeItem* b);
00798
00799
00805 bool lbi_greater(const TreeItem* a, const TreeItem* b);
00806
00807 }
00808
00809
00810 #if defined(_MSC_VER)
00811 # pragma warning(pop)
00812 #endif
00813
00814 #endif // end of guard _CEGUITree_h_