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 "CEGUITreeItem.h"
00035 #include "CEGUITreeProperties.h"
00036 #include <vector>
00037
00038 #if defined(_MSC_VER)
00039 # pragma warning(push)
00040 # pragma warning(disable : 4251)
00041 #endif
00042
00043
00044 namespace CEGUI
00045 {
00051 class CEGUIEXPORT TreeEventArgs : public WindowEventArgs
00052 {
00053 public:
00054 TreeEventArgs(Window* wnd) : WindowEventArgs(wnd)
00055 { treeItem = 0; }
00056
00057 TreeItem *treeItem;
00058 };
00059
00060
00075 class CEGUIEXPORT Tree : public Window
00076 {
00077 friend class TreeItem;
00078 typedef std::vector<TreeItem*> LBItemList;
00079
00080 public:
00082 static const String EventNamespace;
00083 static const String WidgetTypeName;
00084
00085
00086
00087
00088
00090 static const String EventListContentsChanged;
00092 static const String EventSelectionChanged;
00094 static const String EventSortModeChanged;
00096 static const String EventMultiselectModeChanged;
00098 static const String EventVertScrollbarModeChanged;
00100 static const String EventHorzScrollbarModeChanged;
00102 static const String EventBranchOpened;
00104 static const String EventBranchClosed;
00105
00106
00107 void doTreeRender()
00108 { populateGeometryBuffer(); }
00109
00110
00111 void doScrollbars()
00112 { configureScrollbars(); }
00113
00114
00115
00116
00124 size_t getItemCount(void) const
00125 { return d_listItems.size(); }
00126
00134 size_t getSelectedCount(void) const;
00135
00144 TreeItem* getFirstSelectedItem(void) const;
00145
00155 TreeItem* getLastSelectedItem(void) const
00156 { return d_lastSelected; }
00157
00175 TreeItem* getNextSelected(const TreeItem* start_item) const;
00176
00177 TreeItem* getNextSelectedItemFromList(const LBItemList &itemList,
00178 const TreeItem* start_item,
00179 bool& foundStartItem) const;
00180
00189 bool isSortEnabled(void) const
00190 { return d_sorted; }
00191
00192 void setItemRenderArea(Rect& r)
00193 { d_itemArea = r; }
00194
00195 Scrollbar* getVertScrollbar()
00196 { return d_vertScrollbar; }
00197
00198 Scrollbar* getHorzScrollbar()
00199 { return d_horzScrollbar; }
00200
00208 bool isMultiselectEnabled(void) const
00209 { return d_multiselect; }
00210
00211 bool isItemTooltipsEnabled(void) const
00212 { return d_itemTooltips; }
00213
00233 TreeItem* findFirstItemWithText(const String& text);
00234
00235 TreeItem* findNextItemWithText(const String& text,
00236 const TreeItem* start_item);
00237
00238 TreeItem* findItemWithTextFromList(const LBItemList &itemList,
00239 const String& text,
00240 const TreeItem* start_item,
00241 bool foundStartItem);
00242
00262 TreeItem* findFirstItemWithID(uint searchID);
00263 TreeItem* findNextItemWithID(uint searchID, const TreeItem* start_item);
00264 TreeItem* findItemWithIDFromList(const LBItemList &itemList, uint searchID,
00265 const TreeItem* start_item,
00266 bool foundStartItem);
00267
00276 bool isTreeItemInList(const TreeItem* item) const;
00277
00286 bool isVertScrollbarAlwaysShown(void) const;
00287
00296 bool isHorzScrollbarAlwaysShown(void) const;
00297
00298
00299
00300
00312 virtual void initialise(void);
00313
00320 void resetList(void);
00321
00334 void addItem(TreeItem* item);
00335
00359 void insertItem(TreeItem* item, const TreeItem* position);
00360
00373 void removeItem(const TreeItem* item);
00374
00382 void clearAllSelections(void);
00383 bool clearAllSelectionsFromList(const LBItemList &itemList);
00384
00396 void setSortingEnabled(bool setting);
00397
00410 void setMultiselectEnabled(bool setting);
00411
00425 void setShowVertScrollbar(bool setting);
00426
00440 void setShowHorzScrollbar(bool setting);
00441
00442 void setItemTooltipsEnabled(bool setting);
00443
00467 void setItemSelectState(TreeItem* item, bool state);
00468
00492 void setItemSelectState(size_t item_index, bool state);
00493
00511 virtual void setLookNFeel(const String& look);
00512
00526 void handleUpdatedItemData(void);
00527
00541 void ensureItemIsVisible(const TreeItem* item);
00542
00543
00544
00545
00546
00551 Tree(const String& type, const String& name);
00552
00557 virtual ~Tree(void);
00558
00559 protected:
00560
00561
00562
00572 virtual Rect getTreeRenderArea(void) const
00573 { return d_itemArea; }
00574
00586 virtual Scrollbar* createVertScrollbar(const String& name) const
00587 { return (Scrollbar*)(WindowManager::getSingleton().getWindow(name)); }
00588
00600 virtual Scrollbar* createHorzScrollbar(const String& name) const
00601 { return (Scrollbar*)(WindowManager::getSingleton().getWindow(name)); }
00602
00613 virtual void cacheTreeBaseImagery()
00614 {}
00615
00616
00617
00618
00623 bool containsOpenItemRecursive(const LBItemList& itemList, TreeItem* item);
00624
00629 void addTreeEvents(void);
00630
00631
00637 void configureScrollbars(void);
00638
00644 void selectRange(size_t start, size_t end);
00645
00650 float getTotalItemsHeight(void) const;
00651 void getTotalItemsInListHeight(const LBItemList &itemList,
00652 float *heightSum) const;
00653
00658 float getWidestItemWidth(void) const;
00659 void getWidestItemWidthInList(const LBItemList &itemList, int itemDepth,
00660 float *widest) const;
00661
00670 bool getHeightToItemInList(const LBItemList &itemList,
00671 const TreeItem *treeItem,
00672 int itemDepth,
00673 float *height) const;
00674
00683 bool clearAllSelections_impl(void);
00684
00693 TreeItem* getItemAtPoint(const Point& pt) const;
00694 TreeItem* getItemFromListAtPoint(const LBItemList &itemList, float *bottomY,
00695 const Point& pt) const;
00696
00708 bool resetList_impl(void);
00709
00721 virtual bool testClassName_impl(const String& class_name) const
00722 {
00723 if (class_name==(const utf8*)"Tree")
00724 return true;
00725
00726 return Window::testClassName_impl(class_name);
00727 }
00728
00734 bool handle_scrollChange(const EventArgs& args);
00735
00736
00737 virtual void populateGeometryBuffer();
00738
00739 void drawItemList(LBItemList& itemList, Rect& itemsArea, float widest,
00740 Vector2& itemPos, GeometryBuffer& geometry, float alpha);
00741
00742
00743
00744
00749 virtual void onListContentsChanged(WindowEventArgs& e);
00750
00756 virtual void onSelectionChanged(TreeEventArgs& e);
00757
00762 virtual void onSortModeChanged(WindowEventArgs& e);
00763
00768 virtual void onMultiselectModeChanged(WindowEventArgs& e);
00769
00775 virtual void onVertScrollbarModeChanged(WindowEventArgs& e);
00776
00782 virtual void onHorzScrollbarModeChanged(WindowEventArgs& e);
00783
00788 virtual void onBranchOpened(TreeEventArgs& e);
00789
00794 virtual void onBranchClosed(TreeEventArgs& e);
00795
00796
00797
00798
00799 virtual void onSized(WindowEventArgs& e);
00800 virtual void onMouseButtonDown(MouseEventArgs& e);
00801 virtual void onMouseWheel(MouseEventArgs& e);
00802 virtual void onMouseMove(MouseEventArgs& e);
00803
00804
00805
00806
00808 bool d_sorted;
00810 bool d_multiselect;
00812 bool d_forceVertScroll;
00814 bool d_forceHorzScroll;
00816 bool d_itemTooltips;
00818 Scrollbar* d_vertScrollbar;
00820 Scrollbar* d_horzScrollbar;
00822 LBItemList d_listItems;
00824 TreeItem* d_lastSelected;
00825 ImagerySection* d_openButtonImagery;
00826 ImagerySection* d_closeButtonImagery;
00827
00828 private:
00829
00830
00831
00832 static TreeProperties::Sort d_sortProperty;
00833 static TreeProperties::MultiSelect d_multiSelectProperty;
00834 static TreeProperties::ForceVertScrollbar d_forceVertProperty;
00835 static TreeProperties::ForceHorzScrollbar d_forceHorzProperty;
00836 static TreeProperties::ItemTooltips d_itemTooltipsProperty;
00837
00838
00839
00840
00841 void addTreeProperties(void);
00842 Rect d_itemArea;
00843 };
00844
00850 bool lbi_less(const TreeItem* a, const TreeItem* b);
00851
00852
00858 bool lbi_greater(const TreeItem* a, const TreeItem* b);
00859
00860 }
00861
00862
00863 #if defined(_MSC_VER)
00864 # pragma warning(pop)
00865 #endif
00866
00867 #endif // end of guard _CEGUITree_h_