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 #if defined(_MSC_VER)
00039 # pragma warning(push)
00040 # pragma warning(disable : 4251)
00041 #endif
00042
00043
00044 namespace CEGUI
00045 {
00046 class ImagerySection;
00047
00053 class CEGUIEXPORT TreeEventArgs : public WindowEventArgs
00054 {
00055 public:
00056 TreeEventArgs(Window* wnd) : WindowEventArgs(wnd)
00057 { treeItem = 0; }
00058
00059 TreeItem *treeItem;
00060 };
00061
00062
00077 class CEGUIEXPORT Tree : public Window
00078 {
00079 friend class TreeItem;
00080 typedef std::vector<TreeItem*> LBItemList;
00081
00082 public:
00084 static const String EventNamespace;
00085 static const String WidgetTypeName;
00086
00087
00088
00089
00090
00092 static const String EventListContentsChanged;
00094 static const String EventSelectionChanged;
00096 static const String EventSortModeChanged;
00098 static const String EventMultiselectModeChanged;
00100 static const String EventVertScrollbarModeChanged;
00102 static const String EventHorzScrollbarModeChanged;
00104 static const String EventBranchOpened;
00106 static const String EventBranchClosed;
00107
00108
00109 void doTreeRender()
00110 { populateRenderCache(); }
00111
00112
00113 void doScrollbars()
00114 { configureScrollbars(); }
00115
00116
00117
00118
00126 size_t getItemCount(void) const
00127 { return d_listItems.size(); }
00128
00136 size_t getSelectedCount(void) const;
00137
00146 TreeItem* getFirstSelectedItem(void) const;
00147
00157 TreeItem* getLastSelectedItem(void) const
00158 { return d_lastSelected; }
00159
00177 TreeItem* getNextSelected(const TreeItem* start_item) const;
00178
00179 TreeItem* getNextSelectedItemFromList(const LBItemList &itemList,
00180 const TreeItem* start_item,
00181 bool foundStartItem) const;
00182
00191 bool isSortEnabled(void) const
00192 { return d_sorted; }
00193
00194 void setItemRenderArea(Rect& r)
00195 { d_itemArea = r; }
00196
00197 Scrollbar* getVertScrollbar()
00198 { return d_vertScrollbar; }
00199
00200 Scrollbar* getHorzScrollbar()
00201 { return d_horzScrollbar; }
00202
00210 bool isMultiselectEnabled(void) const
00211 { return d_multiselect; }
00212
00213 bool isItemTooltipsEnabled(void) const
00214 { return d_itemTooltips; }
00215
00235 TreeItem* findFirstItemWithText(const String& text);
00236
00237 TreeItem* findNextItemWithText(const String& text,
00238 const TreeItem* start_item);
00239
00240 TreeItem* findItemWithTextFromList(const LBItemList &itemList,
00241 const String& text,
00242 const TreeItem* start_item,
00243 bool foundStartItem);
00244
00264 TreeItem* findFirstItemWithID(uint searchID);
00265 TreeItem* findNextItemWithID(uint searchID, const TreeItem* start_item);
00266 TreeItem* findItemWithIDFromList(const LBItemList &itemList, uint searchID,
00267 const TreeItem* start_item,
00268 bool foundStartItem);
00269
00278 bool isTreeItemInList(const TreeItem* item) const;
00279
00288 bool isVertScrollbarAlwaysShown(void) const;
00289
00298 bool isHorzScrollbarAlwaysShown(void) const;
00299
00300
00301
00302
00314 virtual void initialise(void);
00315
00322 void resetList(void);
00323
00336 void addItem(TreeItem* item);
00337
00361 void insertItem(TreeItem* item, const TreeItem* position);
00362
00375 void removeItem(const TreeItem* item);
00376
00384 void clearAllSelections(void);
00385 bool clearAllSelectionsFromList(const LBItemList &itemList);
00386
00398 void setSortingEnabled(bool setting);
00399
00412 void setMultiselectEnabled(bool setting);
00413
00427 void setShowVertScrollbar(bool setting);
00428
00442 void setShowHorzScrollbar(bool setting);
00443
00444 void setItemTooltipsEnabled(bool setting);
00445
00469 void setItemSelectState(TreeItem* item, bool state);
00470
00494 void setItemSelectState(size_t item_index, bool state);
00495
00513 virtual void setLookNFeel(const String& look);
00514
00528 void handleUpdatedItemData(void);
00529
00543 void ensureItemIsVisible(const TreeItem* item);
00544
00545
00546
00547
00548
00553 Tree(const String& type, const String& name);
00554
00559 virtual ~Tree(void);
00560
00561 protected:
00562
00563
00564
00574 virtual Rect getTreeRenderArea(void) const
00575 { return d_itemArea; }
00576
00588 virtual Scrollbar* createVertScrollbar(const String& name) const
00589 { return (Scrollbar*)(WindowManager::getSingleton().getWindow(name)); }
00590
00602 virtual Scrollbar* createHorzScrollbar(const String& name) const
00603 { return (Scrollbar*)(WindowManager::getSingleton().getWindow(name)); }
00604
00615 virtual void cacheTreeBaseImagery()
00616 {}
00617
00618
00619
00620
00625 bool containsOpenItemRecursive(const LBItemList& itemList, TreeItem* item);
00626
00631 void addTreeEvents(void);
00632
00633
00639 void configureScrollbars(void);
00640
00646 void selectRange(size_t start, size_t end);
00647
00652 float getTotalItemsHeight(void) const;
00653 void getTotalItemsInListHeight(const LBItemList &itemList,
00654 float *heightSum) const;
00655
00660 float getWidestItemWidth(void) const;
00661 void getWidestItemWidthInList(const LBItemList &itemList, int itemDepth,
00662 float *widest) const;
00663
00672 bool getHeightToItemInList(const LBItemList &itemList,
00673 const TreeItem *treeItem,
00674 int itemDepth,
00675 float *height) const;
00676
00685 bool clearAllSelections_impl(void);
00686
00695 TreeItem* getItemAtPoint(const Point& pt) const;
00696 TreeItem* getItemFromListAtPoint(const LBItemList &itemList, float *bottomY,
00697 const Point& pt) const;
00698
00710 bool resetList_impl(void);
00711
00723 virtual bool testClassName_impl(const String& class_name) const
00724 {
00725 if (class_name==(const utf8*)"Tree")
00726 return true;
00727
00728 return Window::testClassName_impl(class_name);
00729 }
00730
00736 bool handle_scrollChange(const EventArgs& args);
00737
00738
00739 virtual void populateRenderCache();
00740
00741 void drawItemList(LBItemList &itemList, Rect &itemsArea, float widest,
00742 Vector3 &itemPos, RenderCache& cache, float alpha);
00743
00744
00745
00746
00751 virtual void onListContentsChanged(WindowEventArgs& e);
00752
00758 virtual void onSelectionChanged(TreeEventArgs& e);
00759
00764 virtual void onSortModeChanged(WindowEventArgs& e);
00765
00770 virtual void onMultiselectModeChanged(WindowEventArgs& e);
00771
00777 virtual void onVertScrollbarModeChanged(WindowEventArgs& e);
00778
00784 virtual void onHorzScrollbarModeChanged(WindowEventArgs& e);
00785
00790 virtual void onBranchOpened(TreeEventArgs& e);
00791
00796 virtual void onBranchClosed(TreeEventArgs& e);
00797
00798
00799
00800
00801 virtual void onSized(WindowEventArgs& e);
00802 virtual void onMouseButtonDown(MouseEventArgs& e);
00803 virtual void onMouseWheel(MouseEventArgs& e);
00804 virtual void onMouseMove(MouseEventArgs& e);
00805
00806
00807
00808
00810 bool d_sorted;
00812 bool d_multiselect;
00814 bool d_forceVertScroll;
00816 bool d_forceHorzScroll;
00818 bool d_itemTooltips;
00820 Scrollbar* d_vertScrollbar;
00822 Scrollbar* d_horzScrollbar;
00824 LBItemList d_listItems;
00826 TreeItem* d_lastSelected;
00827 ImagerySection* openButtonImagery;
00828 ImagerySection* closeButtonImagery;
00829
00830 private:
00831
00832
00833
00834 static TreeProperties::Sort d_sortProperty;
00835 static TreeProperties::MultiSelect d_multiSelectProperty;
00836 static TreeProperties::ForceVertScrollbar d_forceVertProperty;
00837 static TreeProperties::ForceHorzScrollbar d_forceHorzProperty;
00838 static TreeProperties::ItemTooltips d_itemTooltipsProperty;
00839
00840
00841
00842
00843 void addTreeProperties(void);
00844 Rect d_itemArea;
00845 };
00846
00852 bool lbi_less(const TreeItem* a, const TreeItem* b);
00853
00854
00860 bool lbi_greater(const TreeItem* a, const TreeItem* b);
00861
00862 }
00863
00864
00865 #if defined(_MSC_VER)
00866 # pragma warning(pop)
00867 #endif
00868
00869 #endif // end of guard _CEGUITree_h_