Crazy Eddies GUI System  0.6.0
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 
39 #if defined(_MSC_VER)
40 # pragma warning(push)
41 # pragma warning(disable : 4251)
42 #endif
43 
44 
45 // Start of CEGUI namespace section
46 namespace CEGUI
47 {
48 class ImagerySection; // forward declaration
49 
55 class CEGUIEXPORT TreeEventArgs : public WindowEventArgs
56  {
57 public:
58  TreeEventArgs(Window* wnd) : WindowEventArgs(wnd) { treeItem = 0; }
59  TreeItem *treeItem;
60  };
61 
62 
67 class CEGUIEXPORT Tree : public Window
68 {
69 friend class TreeItem;
70 typedef std::vector<TreeItem*> LBItemList;
71 
72 public:
73  static const String EventNamespace;
74  static const String WidgetTypeName;
75 
76  /*************************************************************************
77  Constants
78  *************************************************************************/
79  // event names
86  static const String EventBranchOpened;
87  static const String EventBranchClosed;
88 
89  //Render the actual tree
90  void doTreeRender() { populateRenderCache(); }
91  //UpdateScrollbars
92  void doScrollbars() { configureScrollbars(); }
93  /*************************************************************************
94  Accessor Methods
95  *************************************************************************/
103  size_t getItemCount(void) const {return d_listItems.size();}
104 
105 
113  size_t getSelectedCount(void) const;
114 
115 
124  TreeItem* getFirstSelectedItem(void) const;
125 
126 
135  TreeItem* getLastSelectedItem(void) const { return d_lastSelected; }
136 
137 
152  TreeItem* getNextSelected(const TreeItem* start_item) const;
153 
154 
155  TreeItem* getNextSelectedItemFromList(const LBItemList &itemList, const TreeItem* start_item, bool foundStartItem) const;
156 
164  bool isSortEnabled(void) const {return d_sorted;}
165 
166  void setItemRenderArea(Rect& r)
167  {
168  d_itemArea = r;
169  }
170 
171  Scrollbar* getVertScrollbar() { return d_vertScrollbar; }
172  Scrollbar* getHorzScrollbar() { return d_horzScrollbar; }
173 
181  bool isMultiselectEnabled(void) const {return d_multiselect;}
182 
183  bool isItemTooltipsEnabled(void) const {return d_itemTooltips;}
184 
185 
203  TreeItem* findFirstItemWithText(const String& text);
204  TreeItem* findNextItemWithText(const String& text, const TreeItem* start_item);
205  TreeItem* findItemWithTextFromList(const LBItemList &itemList, const String& text, const TreeItem* start_item, bool foundStartItem);
206 
207 
225  TreeItem* findFirstItemWithID(uint searchID);
226  TreeItem* findNextItemWithID(uint searchID, const TreeItem* start_item);
227  TreeItem* findItemWithIDFromList(const LBItemList &itemList, uint searchID, const TreeItem* start_item, bool foundStartItem);
228 
229 
237  bool isTreeItemInList(const TreeItem* item) const;
238 
239 
248  bool isVertScrollbarAlwaysShown(void) const;
249 
250 
259  bool isHorzScrollbarAlwaysShown(void) const;
260 
261 
262  /*************************************************************************
263  Manipulator Methods
264  *************************************************************************/
275  virtual void initialise(void);
276 
277 
284  void resetList(void);
285 
286 
298  void addItem(TreeItem* item);
299 
300 
320  void insertItem(TreeItem* item, const TreeItem* position);
321 
322 
334  void removeItem(const TreeItem* item);
335 
336 
344  void clearAllSelections(void);
345  bool clearAllSelectionsFromList(const LBItemList &itemList);
346 
347 
358  void setSortingEnabled(bool setting);
359 
360 
372  void setMultiselectEnabled(bool setting);
373 
374 
386  void setShowVertScrollbar(bool setting);
387 
388 
400  void setShowHorzScrollbar(bool setting);
401 
402  void setItemTooltipsEnabled(bool setting);
422  void setItemSelectState(TreeItem* item, bool state);
423 
424 
444  void setItemSelectState(size_t item_index, bool state);
445 
462  virtual void setLookNFeel(const String& look);
463 
476  void handleUpdatedItemData(void);
477 
478 
491  void ensureItemIsVisible(const TreeItem* item);
492 
493 
494  /*************************************************************************
495  Construction and Destruction
496  *************************************************************************/
501  Tree(const String& type, const String& name);
502 
503 
508  virtual ~Tree(void);
509 
510 
511 protected:
512  /*************************************************************************
513  Abstract Implementation Functions (must be provided by derived class)
514  *************************************************************************/
524  virtual Rect getTreeRenderArea(void) const
525  {
526  return d_itemArea;
527  }
528 
539  virtual Scrollbar* createVertScrollbar(const String& name) const
540  {
541  return (Scrollbar*)(WindowManager::getSingleton().getWindow(name));
542  }
543 
554  virtual Scrollbar* createHorzScrollbar(const String& name) const
555  {
556  return (Scrollbar*)(WindowManager::getSingleton().getWindow(name));
557  }
558 
559 
570  virtual void cacheTreeBaseImagery()
571  {
572 
573  }
574 
575 
576 
577 
578  /*************************************************************************
579  Implementation Functions
580  *************************************************************************/
585  void addTreeEvents(void);
586 
587 
592  void configureScrollbars(void);
593 
599  void selectRange(size_t start, size_t end);
600 
601 
606  float getTotalItemsHeight(void) const;
607  void getTotalItemsInListHeight(const LBItemList &itemList, float *heightSum) const;
608 
609 
614  float getWidestItemWidth(void) const;
615  void getWidestItemWidthInList(const LBItemList &itemList, int itemDepth, float *widest) const;
616 
624  bool getHeightToItemInList(const LBItemList &itemList, const TreeItem *treeItem, int itemDepth, float *height) const;
625 
626 
634  bool clearAllSelections_impl(void);
635 
636 
645  TreeItem* getItemAtPoint(const Point& pt) const;
646  TreeItem* getItemFromListAtPoint(const LBItemList &itemList, float *bottomY, const Point& pt) const;
647 
648 
660  bool resetList_impl(void);
661 
662 
673  virtual bool testClassName_impl(const String& class_name) const
674  {
675  if (class_name==(const utf8*)"Tree") return true;
676  return Window::testClassName_impl(class_name);
677  }
678 
683  bool handle_scrollChange(const EventArgs& args);
684 
685  // overridden from Window base class.
686  virtual void populateRenderCache();
687 
688  void drawItemList(LBItemList &itemList, Rect &itemsArea, float widest, Vector3 &itemPos, RenderCache& cache, float alpha);
689 
690 
691  /*************************************************************************
692  New event handlers
693  *************************************************************************/
698  virtual void onListContentsChanged(WindowEventArgs& e);
699 
700 
705  virtual void onSelectionChanged(TreeEventArgs& e);
706 
707 
712  virtual void onSortModeChanged(WindowEventArgs& e);
713 
714 
719  virtual void onMultiselectModeChanged(WindowEventArgs& e);
720 
721 
726  virtual void onVertScrollbarModeChanged(WindowEventArgs& e);
727 
728 
733  virtual void onHorzScrollbarModeChanged(WindowEventArgs& e);
734 
739  virtual void onBranchOpened(TreeEventArgs& e);
740 
745  virtual void onBranchClosed(TreeEventArgs& e);
746 
747 
748 
749  /*************************************************************************
750  Overridden Event handlers
751  *************************************************************************/
752  virtual void onSized(WindowEventArgs& e);
753  virtual void onMouseButtonDown(MouseEventArgs& e);
754  virtual void onMouseWheel(MouseEventArgs& e);
755  virtual void onMouseMove(MouseEventArgs& e);
756 
757 
758  /*************************************************************************
759  Implementation Data
760  *************************************************************************/
761  bool d_sorted;
768  LBItemList d_listItems;
770  ImagerySection *openButtonImagery;
771  ImagerySection *closeButtonImagery;
772 
773 
774 private:
775  /*************************************************************************
776  Static Properties for this class
777  *************************************************************************/
778  static TreeProperties::Sort d_sortProperty;
779  static TreeProperties::MultiSelect d_multiSelectProperty;
780  static TreeProperties::ForceVertScrollbar d_forceVertProperty;
781  static TreeProperties::ForceHorzScrollbar d_forceHorzProperty;
782  static TreeProperties::ItemTooltips d_itemTooltipsProperty;
783 
784  /*************************************************************************
785  Private methods
786  *************************************************************************/
787  void addTreeProperties(void);
788  Rect d_itemArea;
789 };
790 
791 
797 bool lbi_less(const TreeItem* a, const TreeItem* b);
798 
799 
805 bool lbi_greater(const TreeItem* a, const TreeItem* b);
806 
807 } // End of CEGUI namespace section
808 
809 
810 #if defined(_MSC_VER)
811 # pragma warning(pop)
812 #endif
813 
814 #endif // end of guard _CEGUITree_h_