Crazy Eddies GUI System  0.6.2
CEGUITree.h
1 /***********************************************************************
2  filename: CEGUITree.h
3  created: 5-13-07
4  author: Jonathan Welch (Based on Code by David Durant)
5  *************************************************************************/
6 /***************************************************************************
7  * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining
10  * a copy of this software and associated documentation files (the
11  * "Software"), to deal in the Software without restriction, including
12  * without limitation the rights to use, copy, modify, merge, publish,
13  * distribute, sublicense, and/or sell copies of the Software, and to
14  * permit persons to whom the Software is furnished to do so, subject to
15  * the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be
18  * included in all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26  * OTHER DEALINGS IN THE SOFTWARE.
27  ***************************************************************************/
28 #ifndef _CEGUITree_h_
29 #define _CEGUITree_h_
30 
31 #include "CEGUIBase.h"
32 #include "CEGUIWindow.h"
33 #include "CEGUIWindowManager.h"
34 #include "elements/CEGUITreeItem.h"
35 #include "elements/CEGUITreeProperties.h"
36 #include <vector>
37 
38 #if defined(_MSC_VER)
39 # pragma warning(push)
40 # pragma warning(disable : 4251)
41 #endif
42 
43 // Start of CEGUI namespace section
44 namespace CEGUI
45 {
46 class ImagerySection; // forward declaration
47 
53 class CEGUIEXPORT TreeEventArgs : public WindowEventArgs
54 {
55 public:
57  { treeItem = 0; }
58 
59  TreeItem *treeItem;
60 };
61 
62 
77 class CEGUIEXPORT Tree : public Window
78 {
79  friend class TreeItem;
80  typedef std::vector<TreeItem*> LBItemList;
81 
82 public:
84  static const String EventNamespace;
85  static const String WidgetTypeName;
86 
87  /*************************************************************************
88  Constants
89  *************************************************************************/
90  // event names
104  static const String EventBranchOpened;
106  static const String EventBranchClosed;
107 
108  //Render the actual tree
109  void doTreeRender()
110  { populateRenderCache(); }
111 
112  //UpdateScrollbars
113  void doScrollbars()
114  { configureScrollbars(); }
115 
116  /*************************************************************************
117  Accessor Methods
118  *************************************************************************/
126  size_t getItemCount(void) const
127  { return d_listItems.size(); }
128 
136  size_t getSelectedCount(void) const;
137 
146  TreeItem* getFirstSelectedItem(void) const;
147 
157  TreeItem* getLastSelectedItem(void) const
158  { return d_lastSelected; }
159 
177  TreeItem* getNextSelected(const TreeItem* start_item) const;
178 
179  TreeItem* getNextSelectedItemFromList(const LBItemList &itemList,
180  const TreeItem* start_item,
181  bool foundStartItem) const;
182 
191  bool isSortEnabled(void) const
192  { return d_sorted; }
193 
194  void setItemRenderArea(Rect& r)
195  { d_itemArea = r; }
196 
197  Scrollbar* getVertScrollbar()
198  { return d_vertScrollbar; }
199 
200  Scrollbar* getHorzScrollbar()
201  { return d_horzScrollbar; }
202 
210  bool isMultiselectEnabled(void) const
211  { return d_multiselect; }
212 
213  bool isItemTooltipsEnabled(void) const
214  { return d_itemTooltips; }
215 
235  TreeItem* findFirstItemWithText(const String& text);
236 
237  TreeItem* findNextItemWithText(const String& text,
238  const TreeItem* start_item);
239 
240  TreeItem* findItemWithTextFromList(const LBItemList &itemList,
241  const String& text,
242  const TreeItem* start_item,
243  bool foundStartItem);
244 
264  TreeItem* findFirstItemWithID(uint searchID);
265  TreeItem* findNextItemWithID(uint searchID, const TreeItem* start_item);
266  TreeItem* findItemWithIDFromList(const LBItemList &itemList, uint searchID,
267  const TreeItem* start_item,
268  bool foundStartItem);
269 
278  bool isTreeItemInList(const TreeItem* item) const;
279 
288  bool isVertScrollbarAlwaysShown(void) const;
289 
298  bool isHorzScrollbarAlwaysShown(void) const;
299 
300  /*************************************************************************
301  Manipulator Methods
302  *************************************************************************/
314  virtual void initialise(void);
315 
322  void resetList(void);
323 
336  void addItem(TreeItem* item);
337 
361  void insertItem(TreeItem* item, const TreeItem* position);
362 
375  void removeItem(const TreeItem* item);
376 
384  void clearAllSelections(void);
385  bool clearAllSelectionsFromList(const LBItemList &itemList);
386 
398  void setSortingEnabled(bool setting);
399 
412  void setMultiselectEnabled(bool setting);
413 
427  void setShowVertScrollbar(bool setting);
428 
442  void setShowHorzScrollbar(bool setting);
443 
444  void setItemTooltipsEnabled(bool setting);
445 
469  void setItemSelectState(TreeItem* item, bool state);
470 
494  void setItemSelectState(size_t item_index, bool state);
495 
513  virtual void setLookNFeel(const String& look);
514 
528  void handleUpdatedItemData(void);
529 
543  void ensureItemIsVisible(const TreeItem* item);
544 
545 
546  /*************************************************************************
547  Construction and Destruction
548  *************************************************************************/
553  Tree(const String& type, const String& name);
554 
559  virtual ~Tree(void);
560 
561 protected:
562  /*************************************************************************
563  Abstract Implementation Functions (must be provided by derived class)
564  *************************************************************************/
574  virtual Rect getTreeRenderArea(void) const
575  { return d_itemArea; }
576 
588  virtual Scrollbar* createVertScrollbar(const String& name) const
589  { return (Scrollbar*)(WindowManager::getSingleton().getWindow(name)); }
590 
602  virtual Scrollbar* createHorzScrollbar(const String& name) const
603  { return (Scrollbar*)(WindowManager::getSingleton().getWindow(name)); }
604 
615  virtual void cacheTreeBaseImagery()
616  {}
617 
618  /*************************************************************************
619  Implementation Functions
620  *************************************************************************/
625  bool containsOpenItemRecursive(const LBItemList& itemList, TreeItem* item);
626 
631  void addTreeEvents(void);
632 
633 
639  void configureScrollbars(void);
640 
646  void selectRange(size_t start, size_t end);
647 
652  float getTotalItemsHeight(void) const;
653  void getTotalItemsInListHeight(const LBItemList &itemList,
654  float *heightSum) const;
655 
660  float getWidestItemWidth(void) const;
661  void getWidestItemWidthInList(const LBItemList &itemList, int itemDepth,
662  float *widest) const;
663 
672  bool getHeightToItemInList(const LBItemList &itemList,
673  const TreeItem *treeItem,
674  int itemDepth,
675  float *height) const;
676 
685  bool clearAllSelections_impl(void);
686 
695  TreeItem* getItemAtPoint(const Point& pt) const;
696  TreeItem* getItemFromListAtPoint(const LBItemList &itemList, float *bottomY,
697  const Point& pt) const;
698 
710  bool resetList_impl(void);
711 
723  virtual bool testClassName_impl(const String& class_name) const
724  {
725  if (class_name==(const utf8*)"Tree")
726  return true;
727 
728  return Window::testClassName_impl(class_name);
729  }
730 
736  bool handle_scrollChange(const EventArgs& args);
737 
738  // overridden from Window base class.
739  virtual void populateRenderCache();
740 
741  void drawItemList(LBItemList &itemList, Rect &itemsArea, float widest,
742  Vector3 &itemPos, RenderCache& cache, float alpha);
743 
744  /*************************************************************************
745  New event handlers
746  *************************************************************************/
751  virtual void onListContentsChanged(WindowEventArgs& e);
752 
758  virtual void onSelectionChanged(TreeEventArgs& e);
759 
764  virtual void onSortModeChanged(WindowEventArgs& e);
765 
770  virtual void onMultiselectModeChanged(WindowEventArgs& e);
771 
777  virtual void onVertScrollbarModeChanged(WindowEventArgs& e);
778 
784  virtual void onHorzScrollbarModeChanged(WindowEventArgs& e);
785 
790  virtual void onBranchOpened(TreeEventArgs& e);
791 
796  virtual void onBranchClosed(TreeEventArgs& e);
797 
798  /*************************************************************************
799  Overridden Event handlers
800  *************************************************************************/
801  virtual void onSized(WindowEventArgs& e);
802  virtual void onMouseButtonDown(MouseEventArgs& e);
803  virtual void onMouseWheel(MouseEventArgs& e);
804  virtual void onMouseMove(MouseEventArgs& e);
805 
806  /*************************************************************************
807  Implementation Data
808  *************************************************************************/
810  bool d_sorted;
824  LBItemList d_listItems;
827  ImagerySection* openButtonImagery;
828  ImagerySection* closeButtonImagery;
829 
830 private:
831  /*************************************************************************
832  Static Properties for this class
833  *************************************************************************/
834  static TreeProperties::Sort d_sortProperty;
835  static TreeProperties::MultiSelect d_multiSelectProperty;
836  static TreeProperties::ForceVertScrollbar d_forceVertProperty;
837  static TreeProperties::ForceHorzScrollbar d_forceHorzProperty;
838  static TreeProperties::ItemTooltips d_itemTooltipsProperty;
839 
840  /*************************************************************************
841  Private methods
842  *************************************************************************/
843  void addTreeProperties(void);
844  Rect d_itemArea;
845 };
846 
852 bool lbi_less(const TreeItem* a, const TreeItem* b);
853 
854 
860 bool lbi_greater(const TreeItem* a, const TreeItem* b);
861 
862 } // End of CEGUI namespace section
863 
864 
865 #if defined(_MSC_VER)
866 # pragma warning(pop)
867 #endif
868 
869 #endif // end of guard _CEGUITree_h_