Crazy Eddies GUI System  0.7.9
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
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
133  static const String EventBranchOpened;
140  static const String EventBranchClosed;
141 
142  //Render the actual tree
143  void doTreeRender()
144  { populateGeometryBuffer(); }
145 
146  //UpdateScrollbars
147  void doScrollbars()
148  { configureScrollbars(); }
149 
150  /*************************************************************************
151  Accessor Methods
152  *************************************************************************/
160  size_t getItemCount(void) const
161  { return d_listItems.size(); }
162 
170  size_t getSelectedCount(void) const;
171 
180  TreeItem* getFirstSelectedItem(void) const;
181 
191  TreeItem* getLastSelectedItem(void) const
192  { return d_lastSelected; }
193 
211  TreeItem* getNextSelected(const TreeItem* start_item) const;
212 
213  TreeItem* getNextSelectedItemFromList(const LBItemList &itemList,
214  const TreeItem* start_item,
215  bool& foundStartItem) const;
216 
225  bool isSortEnabled(void) const
226  { return d_sorted; }
227 
228  void setItemRenderArea(Rect& r)
229  { d_itemArea = r; }
230 
231  Scrollbar* getVertScrollbar()
232  { return d_vertScrollbar; }
233 
234  Scrollbar* getHorzScrollbar()
235  { return d_horzScrollbar; }
236 
244  bool isMultiselectEnabled(void) const
245  { return d_multiselect; }
246 
247  bool isItemTooltipsEnabled(void) const
248  { return d_itemTooltips; }
249 
269  TreeItem* findFirstItemWithText(const String& text);
270 
271  TreeItem* findNextItemWithText(const String& text,
272  const TreeItem* start_item);
273 
274  TreeItem* findItemWithTextFromList(const LBItemList &itemList,
275  const String& text,
276  const TreeItem* start_item,
277  bool foundStartItem);
278 
298  TreeItem* findFirstItemWithID(uint searchID);
299  TreeItem* findNextItemWithID(uint searchID, const TreeItem* start_item);
300  TreeItem* findItemWithIDFromList(const LBItemList &itemList, uint searchID,
301  const TreeItem* start_item,
302  bool foundStartItem);
303 
312  bool isTreeItemInList(const TreeItem* item) const;
313 
322  bool isVertScrollbarAlwaysShown(void) const;
323 
332  bool isHorzScrollbarAlwaysShown(void) const;
333 
334  /*************************************************************************
335  Manipulator Methods
336  *************************************************************************/
348  virtual void initialise(void);
349 
356  void resetList(void);
357 
370  void addItem(TreeItem* item);
371 
395  void insertItem(TreeItem* item, const TreeItem* position);
396 
409  void removeItem(const TreeItem* item);
410 
418  void clearAllSelections(void);
419  bool clearAllSelectionsFromList(const LBItemList &itemList);
420 
432  void setSortingEnabled(bool setting);
433 
446  void setMultiselectEnabled(bool setting);
447 
461  void setShowVertScrollbar(bool setting);
462 
476  void setShowHorzScrollbar(bool setting);
477 
478  void setItemTooltipsEnabled(bool setting);
479 
503  void setItemSelectState(TreeItem* item, bool state);
504 
528  void setItemSelectState(size_t item_index, bool state);
529 
547  virtual void setLookNFeel(const String& look);
548 
562  void handleUpdatedItemData(void);
563 
577  void ensureItemIsVisible(const TreeItem* item);
578 
579 
580  /*************************************************************************
581  Construction and Destruction
582  *************************************************************************/
587  Tree(const String& type, const String& name);
588 
593  virtual ~Tree(void);
594 
595 protected:
596  /*************************************************************************
597  Abstract Implementation Functions (must be provided by derived class)
598  *************************************************************************/
608  virtual Rect getTreeRenderArea(void) const
609  { return d_itemArea; }
610 
622  virtual Scrollbar* createVertScrollbar(const String& name) const
623  { return (Scrollbar*)(WindowManager::getSingleton().getWindow(name)); }
624 
636  virtual Scrollbar* createHorzScrollbar(const String& name) const
637  { return (Scrollbar*)(WindowManager::getSingleton().getWindow(name)); }
638 
649  virtual void cacheTreeBaseImagery()
650  {}
651 
652  /*************************************************************************
653  Implementation Functions
654  *************************************************************************/
659  bool containsOpenItemRecursive(const LBItemList& itemList, TreeItem* item);
660 
665  void addTreeEvents(void);
666 
667 
673  void configureScrollbars(void);
674 
680  void selectRange(size_t start, size_t end);
681 
686  float getTotalItemsHeight(void) const;
687  void getTotalItemsInListHeight(const LBItemList &itemList,
688  float *heightSum) const;
689 
694  float getWidestItemWidth(void) const;
695  void getWidestItemWidthInList(const LBItemList &itemList, int itemDepth,
696  float *widest) const;
697 
706  bool getHeightToItemInList(const LBItemList &itemList,
707  const TreeItem *treeItem,
708  int itemDepth,
709  float *height) const;
710 
719  bool clearAllSelections_impl(void);
720 
729  TreeItem* getItemAtPoint(const Point& pt) const;
730  TreeItem* getItemFromListAtPoint(const LBItemList &itemList, float *bottomY,
731  const Point& pt) const;
732 
744  bool resetList_impl(void);
745 
757  virtual bool testClassName_impl(const String& class_name) const
758  {
759  if (class_name==(const utf8*)"Tree")
760  return true;
761 
762  return Window::testClassName_impl(class_name);
763  }
764 
770  bool handle_scrollChange(const EventArgs& args);
771 
772  // overridden from Window base class.
773  virtual void populateGeometryBuffer();
774 
775  void drawItemList(LBItemList& itemList, Rect& itemsArea, float widest,
776  Vector2& itemPos, GeometryBuffer& geometry, float alpha);
777 
778  /*************************************************************************
779  New event handlers
780  *************************************************************************/
785  virtual void onListContentsChanged(WindowEventArgs& e);
786 
792  virtual void onSelectionChanged(TreeEventArgs& e);
793 
798  virtual void onSortModeChanged(WindowEventArgs& e);
799 
804  virtual void onMultiselectModeChanged(WindowEventArgs& e);
805 
811  virtual void onVertScrollbarModeChanged(WindowEventArgs& e);
812 
818  virtual void onHorzScrollbarModeChanged(WindowEventArgs& e);
819 
824  virtual void onBranchOpened(TreeEventArgs& e);
825 
830  virtual void onBranchClosed(TreeEventArgs& e);
831 
832  /*************************************************************************
833  Overridden Event handlers
834  *************************************************************************/
835  virtual void onSized(WindowEventArgs& e);
836  virtual void onMouseButtonDown(MouseEventArgs& e);
837  virtual void onMouseWheel(MouseEventArgs& e);
838  virtual void onMouseMove(MouseEventArgs& e);
839 
840  /*************************************************************************
841  Implementation Data
842  *************************************************************************/
844  bool d_sorted;
858  LBItemList d_listItems;
861  ImagerySection* d_openButtonImagery;
862  ImagerySection* d_closeButtonImagery;
863 
864 private:
865  /*************************************************************************
866  Static Properties for this class
867  *************************************************************************/
868  static TreeProperties::Sort d_sortProperty;
869  static TreeProperties::MultiSelect d_multiSelectProperty;
870  static TreeProperties::ForceVertScrollbar d_forceVertProperty;
871  static TreeProperties::ForceHorzScrollbar d_forceHorzProperty;
872  static TreeProperties::ItemTooltips d_itemTooltipsProperty;
873 
874  /*************************************************************************
875  Private methods
876  *************************************************************************/
877  void addTreeProperties(void);
878  Rect d_itemArea;
879 };
880 
886 bool lbi_less(const TreeItem* a, const TreeItem* b);
887 
888 
894 bool lbi_greater(const TreeItem* a, const TreeItem* b);
895 
896 } // End of CEGUI namespace section
897 
898 
899 #if defined(_MSC_VER)
900 # pragma warning(pop)
901 #endif
902 
903 #endif // end of guard _CEGUITree_h_