Crazy Eddie's GUI System  0.8.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
widgets/Tree.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 "../Base.h"
32 #include "../Window.h"
33 #include "../WindowManager.h"
34 #include "./TreeItem.h"
35 #include "./Scrollbar.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 
79  typedef std::vector<TreeItem*
80  CEGUI_VECTOR_ALLOC(TreeItem*)> LBItemList;
81 
82 public:
84  static const String EventNamespace;
85  static const String WidgetTypeName;
86 
87  /*************************************************************************
88  Constants
89  *************************************************************************/
90  // event names
135  static const String EventBranchOpened;
142  static const String EventBranchClosed;
143 
144  //Render the actual tree
145  void doTreeRender()
146  { populateGeometryBuffer(); }
147 
148  //UpdateScrollbars
149  void doScrollbars()
150  { configureScrollbars(); }
151 
152  /*************************************************************************
153  Accessor Methods
154  *************************************************************************/
162  size_t getItemCount(void) const
163  { return d_listItems.size(); }
164 
172  size_t getSelectedCount(void) const;
173 
182  TreeItem* getFirstSelectedItem(void) const;
183 
193  TreeItem* getLastSelectedItem(void) const
194  { return d_lastSelected; }
195 
213  TreeItem* getNextSelected(const TreeItem* start_item) const;
214 
215  TreeItem* getNextSelectedItemFromList(const LBItemList &itemList,
216  const TreeItem* start_item,
217  bool& foundStartItem) const;
218 
227  bool isSortEnabled(void) const
228  { return d_sorted; }
229 
230  void setItemRenderArea(Rectf& r)
231  { d_itemArea = r; }
232 
233  Scrollbar* getVertScrollbar()
234  { return d_vertScrollbar; }
235 
236  Scrollbar* getHorzScrollbar()
237  { return d_horzScrollbar; }
238 
246  bool isMultiselectEnabled(void) const
247  { return d_multiselect; }
248 
249  bool isItemTooltipsEnabled(void) const
250  { return d_itemTooltips; }
251 
271  TreeItem* findFirstItemWithText(const String& text);
272 
273  TreeItem* findNextItemWithText(const String& text,
274  const TreeItem* start_item);
275 
276  TreeItem* findItemWithTextFromList(const LBItemList &itemList,
277  const String& text,
278  const TreeItem* start_item,
279  bool foundStartItem);
280 
300  TreeItem* findFirstItemWithID(uint searchID);
301  TreeItem* findNextItemWithID(uint searchID, const TreeItem* start_item);
302  TreeItem* findItemWithIDFromList(const LBItemList &itemList, uint searchID,
303  const TreeItem* start_item,
304  bool foundStartItem);
305 
314  bool isTreeItemInList(const TreeItem* item) const;
315 
324  bool isVertScrollbarAlwaysShown(void) const;
325 
334  bool isHorzScrollbarAlwaysShown(void) const;
335 
336  /*************************************************************************
337  Manipulator Methods
338  *************************************************************************/
350  virtual void initialise(void);
351 
358  void resetList(void);
359 
372  void addItem(TreeItem* item);
373 
397  void insertItem(TreeItem* item, const TreeItem* position);
398 
411  void removeItem(const TreeItem* item);
412 
420  void clearAllSelections(void);
421  bool clearAllSelectionsFromList(const LBItemList &itemList);
422 
434  void setSortingEnabled(bool setting);
435 
448  void setMultiselectEnabled(bool setting);
449 
463  void setShowVertScrollbar(bool setting);
464 
478  void setShowHorzScrollbar(bool setting);
479 
480  void setItemTooltipsEnabled(bool setting);
481 
505  void setItemSelectState(TreeItem* item, bool state);
506 
530  void setItemSelectState(size_t item_index, bool state);
531 
549  virtual void setLookNFeel(const String& look);
550 
564  void handleUpdatedItemData(void);
565 
579  void ensureItemIsVisible(const TreeItem* item);
580 
581 
582  /*************************************************************************
583  Construction and Destruction
584  *************************************************************************/
589  Tree(const String& type, const String& name);
590 
595  virtual ~Tree(void);
596 
597 protected:
598  /*************************************************************************
599  Abstract Implementation Functions (must be provided by derived class)
600  *************************************************************************/
610  virtual Rectf getTreeRenderArea(void) const
611  { return d_itemArea; }
612 
624  virtual Scrollbar* createVertScrollbar(const String& name) const
625  { return static_cast<Scrollbar*>(getChild(name)); }
626 
638  virtual Scrollbar* createHorzScrollbar(const String& name) const
639  { return static_cast<Scrollbar*>(getChild(name)); }
640 
651  virtual void cacheTreeBaseImagery()
652  {}
653 
654  /*************************************************************************
655  Implementation Functions
656  *************************************************************************/
661  bool containsOpenItemRecursive(const LBItemList& itemList, TreeItem* item);
662 
667  void addTreeEvents(void);
668 
669 
675  void configureScrollbars(void);
676 
682  void selectRange(size_t start, size_t end);
683 
688  float getTotalItemsHeight(void) const;
689  void getTotalItemsInListHeight(const LBItemList &itemList,
690  float *heightSum) const;
691 
696  float getWidestItemWidth(void) const;
697  void getWidestItemWidthInList(const LBItemList &itemList, int itemDepth,
698  float *widest) const;
699 
708  bool getHeightToItemInList(const LBItemList &itemList,
709  const TreeItem *treeItem,
710  int itemDepth,
711  float *height) const;
712 
721  bool clearAllSelections_impl(void);
722 
731  TreeItem* getItemAtPoint(const Vector2f& pt) const;
732  TreeItem* getItemFromListAtPoint(const LBItemList &itemList, float *bottomY,
733  const Vector2f& pt) const;
734 
746  bool resetList_impl(void);
747 
753  bool handle_scrollChange(const EventArgs& args);
754 
755  // overridden from Window base class.
756  virtual void populateGeometryBuffer();
757  bool handleFontRenderSizeChange(const EventArgs& args);
758 
759  void drawItemList(LBItemList& itemList, Rectf& itemsArea, float widest,
760  Vector2f& itemPos, GeometryBuffer& geometry, float alpha);
761 
762  /*************************************************************************
763  New event handlers
764  *************************************************************************/
769  virtual void onListContentsChanged(WindowEventArgs& e);
770 
776  virtual void onSelectionChanged(TreeEventArgs& e);
777 
782  virtual void onSortModeChanged(WindowEventArgs& e);
783 
788  virtual void onMultiselectModeChanged(WindowEventArgs& e);
789 
795  virtual void onVertScrollbarModeChanged(WindowEventArgs& e);
796 
802  virtual void onHorzScrollbarModeChanged(WindowEventArgs& e);
803 
808  virtual void onBranchOpened(TreeEventArgs& e);
809 
814  virtual void onBranchClosed(TreeEventArgs& e);
815 
816  /*************************************************************************
817  Overridden Event handlers
818  *************************************************************************/
819  virtual void onSized(ElementEventArgs& e);
820  virtual void onMouseButtonDown(MouseEventArgs& e);
821  virtual void onMouseWheel(MouseEventArgs& e);
822  virtual void onMouseMove(MouseEventArgs& e);
823 
824  /*************************************************************************
825  Implementation Data
826  *************************************************************************/
828  bool d_sorted;
842  LBItemList d_listItems;
845  const ImagerySection* d_openButtonImagery;
846  const ImagerySection* d_closeButtonImagery;
847 
848 private:
849  /*************************************************************************
850  Private methods
851  *************************************************************************/
852  void addTreeProperties(void);
853  Rectf d_itemArea;
854 };
855 
861 bool lbi_less(const TreeItem* a, const TreeItem* b);
862 
863 
869 bool lbi_greater(const TreeItem* a, const TreeItem* b);
870 
871 } // End of CEGUI namespace section
872 
873 
874 #if defined(_MSC_VER)
875 # pragma warning(pop)
876 #endif
877 
878 #endif // end of guard _CEGUITree_h_