Crazy Eddies GUI System  0.7.1
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 "CEGUITreeItem.h"
35 #include "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 {
51 class CEGUIEXPORT TreeEventArgs : public WindowEventArgs
52 {
53 public:
55  { treeItem = 0; }
56 
57  TreeItem *treeItem;
58 };
59 
60 
75 class CEGUIEXPORT Tree : public Window
76 {
77  friend class TreeItem;
78  typedef std::vector<TreeItem*> LBItemList;
79 
80 public:
82  static const String EventNamespace;
83  static const String WidgetTypeName;
84 
85  /*************************************************************************
86  Constants
87  *************************************************************************/
88  // event names
102  static const String EventBranchOpened;
104  static const String EventBranchClosed;
105 
106  //Render the actual tree
107  void doTreeRender()
108  { populateGeometryBuffer(); }
109 
110  //UpdateScrollbars
111  void doScrollbars()
112  { configureScrollbars(); }
113 
114  /*************************************************************************
115  Accessor Methods
116  *************************************************************************/
124  size_t getItemCount(void) const
125  { return d_listItems.size(); }
126 
134  size_t getSelectedCount(void) const;
135 
144  TreeItem* getFirstSelectedItem(void) const;
145 
155  TreeItem* getLastSelectedItem(void) const
156  { return d_lastSelected; }
157 
175  TreeItem* getNextSelected(const TreeItem* start_item) const;
176 
177  TreeItem* getNextSelectedItemFromList(const LBItemList &itemList,
178  const TreeItem* start_item,
179  bool& foundStartItem) const;
180 
189  bool isSortEnabled(void) const
190  { return d_sorted; }
191 
192  void setItemRenderArea(Rect& r)
193  { d_itemArea = r; }
194 
195  Scrollbar* getVertScrollbar()
196  { return d_vertScrollbar; }
197 
198  Scrollbar* getHorzScrollbar()
199  { return d_horzScrollbar; }
200 
208  bool isMultiselectEnabled(void) const
209  { return d_multiselect; }
210 
211  bool isItemTooltipsEnabled(void) const
212  { return d_itemTooltips; }
213 
233  TreeItem* findFirstItemWithText(const String& text);
234 
235  TreeItem* findNextItemWithText(const String& text,
236  const TreeItem* start_item);
237 
238  TreeItem* findItemWithTextFromList(const LBItemList &itemList,
239  const String& text,
240  const TreeItem* start_item,
241  bool foundStartItem);
242 
262  TreeItem* findFirstItemWithID(uint searchID);
263  TreeItem* findNextItemWithID(uint searchID, const TreeItem* start_item);
264  TreeItem* findItemWithIDFromList(const LBItemList &itemList, uint searchID,
265  const TreeItem* start_item,
266  bool foundStartItem);
267 
276  bool isTreeItemInList(const TreeItem* item) const;
277 
286  bool isVertScrollbarAlwaysShown(void) const;
287 
296  bool isHorzScrollbarAlwaysShown(void) const;
297 
298  /*************************************************************************
299  Manipulator Methods
300  *************************************************************************/
312  virtual void initialise(void);
313 
320  void resetList(void);
321 
334  void addItem(TreeItem* item);
335 
359  void insertItem(TreeItem* item, const TreeItem* position);
360 
373  void removeItem(const TreeItem* item);
374 
382  void clearAllSelections(void);
383  bool clearAllSelectionsFromList(const LBItemList &itemList);
384 
396  void setSortingEnabled(bool setting);
397 
410  void setMultiselectEnabled(bool setting);
411 
425  void setShowVertScrollbar(bool setting);
426 
440  void setShowHorzScrollbar(bool setting);
441 
442  void setItemTooltipsEnabled(bool setting);
443 
467  void setItemSelectState(TreeItem* item, bool state);
468 
492  void setItemSelectState(size_t item_index, bool state);
493 
511  virtual void setLookNFeel(const String& look);
512 
526  void handleUpdatedItemData(void);
527 
541  void ensureItemIsVisible(const TreeItem* item);
542 
543 
544  /*************************************************************************
545  Construction and Destruction
546  *************************************************************************/
551  Tree(const String& type, const String& name);
552 
557  virtual ~Tree(void);
558 
559 protected:
560  /*************************************************************************
561  Abstract Implementation Functions (must be provided by derived class)
562  *************************************************************************/
572  virtual Rect getTreeRenderArea(void) const
573  { return d_itemArea; }
574 
586  virtual Scrollbar* createVertScrollbar(const String& name) const
587  { return (Scrollbar*)(WindowManager::getSingleton().getWindow(name)); }
588 
600  virtual Scrollbar* createHorzScrollbar(const String& name) const
601  { return (Scrollbar*)(WindowManager::getSingleton().getWindow(name)); }
602 
613  virtual void cacheTreeBaseImagery()
614  {}
615 
616  /*************************************************************************
617  Implementation Functions
618  *************************************************************************/
623  bool containsOpenItemRecursive(const LBItemList& itemList, TreeItem* item);
624 
629  void addTreeEvents(void);
630 
631 
637  void configureScrollbars(void);
638 
644  void selectRange(size_t start, size_t end);
645 
650  float getTotalItemsHeight(void) const;
651  void getTotalItemsInListHeight(const LBItemList &itemList,
652  float *heightSum) const;
653 
658  float getWidestItemWidth(void) const;
659  void getWidestItemWidthInList(const LBItemList &itemList, int itemDepth,
660  float *widest) const;
661 
670  bool getHeightToItemInList(const LBItemList &itemList,
671  const TreeItem *treeItem,
672  int itemDepth,
673  float *height) const;
674 
683  bool clearAllSelections_impl(void);
684 
693  TreeItem* getItemAtPoint(const Point& pt) const;
694  TreeItem* getItemFromListAtPoint(const LBItemList &itemList, float *bottomY,
695  const Point& pt) const;
696 
708  bool resetList_impl(void);
709 
721  virtual bool testClassName_impl(const String& class_name) const
722  {
723  if (class_name==(const utf8*)"Tree")
724  return true;
725 
726  return Window::testClassName_impl(class_name);
727  }
728 
734  bool handle_scrollChange(const EventArgs& args);
735 
736  // overridden from Window base class.
737  virtual void populateGeometryBuffer();
738 
739  void drawItemList(LBItemList& itemList, Rect& itemsArea, float widest,
740  Vector2& itemPos, GeometryBuffer& geometry, float alpha);
741 
742  /*************************************************************************
743  New event handlers
744  *************************************************************************/
749  virtual void onListContentsChanged(WindowEventArgs& e);
750 
756  virtual void onSelectionChanged(TreeEventArgs& e);
757 
762  virtual void onSortModeChanged(WindowEventArgs& e);
763 
768  virtual void onMultiselectModeChanged(WindowEventArgs& e);
769 
775  virtual void onVertScrollbarModeChanged(WindowEventArgs& e);
776 
782  virtual void onHorzScrollbarModeChanged(WindowEventArgs& e);
783 
788  virtual void onBranchOpened(TreeEventArgs& e);
789 
794  virtual void onBranchClosed(TreeEventArgs& e);
795 
796  /*************************************************************************
797  Overridden Event handlers
798  *************************************************************************/
799  virtual void onSized(WindowEventArgs& e);
800  virtual void onMouseButtonDown(MouseEventArgs& e);
801  virtual void onMouseWheel(MouseEventArgs& e);
802  virtual void onMouseMove(MouseEventArgs& e);
803 
804  /*************************************************************************
805  Implementation Data
806  *************************************************************************/
808  bool d_sorted;
822  LBItemList d_listItems;
825  ImagerySection* d_openButtonImagery;
826  ImagerySection* d_closeButtonImagery;
827 
828 private:
829  /*************************************************************************
830  Static Properties for this class
831  *************************************************************************/
832  static TreeProperties::Sort d_sortProperty;
833  static TreeProperties::MultiSelect d_multiSelectProperty;
834  static TreeProperties::ForceVertScrollbar d_forceVertProperty;
835  static TreeProperties::ForceHorzScrollbar d_forceHorzProperty;
836  static TreeProperties::ItemTooltips d_itemTooltipsProperty;
837 
838  /*************************************************************************
839  Private methods
840  *************************************************************************/
841  void addTreeProperties(void);
842  Rect d_itemArea;
843 };
844 
850 bool lbi_less(const TreeItem* a, const TreeItem* b);
851 
852 
858 bool lbi_greater(const TreeItem* a, const TreeItem* b);
859 
860 } // End of CEGUI namespace section
861 
862 
863 #if defined(_MSC_VER)
864 # pragma warning(pop)
865 #endif
866 
867 #endif // end of guard _CEGUITree_h_