IGUITreeView.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. // written by Reinhard Ostermeier, reinhard@nospam.r-ostermeier.de
  2. // This file is part of the "Irrlicht Engine".
  3. // For conditions of distribution and use, see copyright notice in irrlicht.h
  4. #ifndef __I_GUI_TREE_VIEW_H_INCLUDED__
  5. #define __I_GUI_TREE_VIEW_H_INCLUDED__
  6. #include "IGUIElement.h"
  7. #include "IGUIImageList.h"
  8. #include "irrTypes.h"
  9. namespace irr
  10. {
  11. namespace gui
  12. {
  13. class IGUIFont;
  14. class IGUITreeView;
  15. //! Node for gui tree view
  16. /** \par This element can create the following events of type EGUI_EVENT_TYPE:
  17. \li EGET_TREEVIEW_NODE_EXPAND
  18. \li EGET_TREEVIEW_NODE_COLLAPS
  19. \li EGET_TREEVIEW_NODE_DESELECT
  20. \li EGET_TREEVIEW_NODE_SELECT
  21. */
  22. class IGUITreeViewNode : public IReferenceCounted
  23. {
  24. public:
  25. //! returns the owner (tree view) of this node
  26. virtual IGUITreeView* getOwner() const = 0;
  27. //! Returns the parent node of this node.
  28. /** For the root node this will return 0. */
  29. virtual IGUITreeViewNode* getParent() const = 0;
  30. //! returns the text of the node
  31. virtual const wchar_t* getText() const = 0;
  32. //! sets the text of the node
  33. virtual void setText( const wchar_t* text ) = 0;
  34. //! returns the icon text of the node
  35. virtual const wchar_t* getIcon() const = 0;
  36. //! sets the icon text of the node
  37. virtual void setIcon( const wchar_t* icon ) = 0;
  38. //! returns the image index of the node
  39. virtual u32 getImageIndex() const = 0;
  40. //! sets the image index of the node
  41. virtual void setImageIndex( u32 imageIndex ) = 0;
  42. //! returns the image index of the node
  43. virtual u32 getSelectedImageIndex() const = 0;
  44. //! sets the image index of the node
  45. virtual void setSelectedImageIndex( u32 imageIndex ) = 0;
  46. //! returns the user data (void*) of this node
  47. virtual void* getData() const = 0;
  48. //! sets the user data (void*) of this node
  49. virtual void setData( void* data ) = 0;
  50. //! returns the user data2 (IReferenceCounted) of this node
  51. virtual IReferenceCounted* getData2() const = 0;
  52. //! sets the user data2 (IReferenceCounted) of this node
  53. virtual void setData2( IReferenceCounted* data ) = 0;
  54. //! returns the child item count
  55. virtual u32 getChildCount() const = 0;
  56. //! removes all children (recursive) from this node
  57. virtual void clearChildren() = 0;
  58. //! removes all children (recursive) from this node
  59. /** \deprecated Deprecated in 1.8, use clearChildren() instead.
  60. This method may be removed by Irrlicht 1.9 */
  61. _IRR_DEPRECATED_ void clearChilds()
  62. {
  63. return clearChildren();
  64. }
  65. //! returns true if this node has child nodes
  66. virtual bool hasChildren() const = 0;
  67. //! returns true if this node has child nodes
  68. /** \deprecated Deprecated in 1.8, use hasChildren() instead.
  69. This method may be removed by Irrlicht 1.9 */
  70. _IRR_DEPRECATED_ bool hasChilds() const
  71. {
  72. return hasChildren();
  73. }
  74. //! Adds a new node behind the last child node.
  75. /** \param text text of the new node
  76. \param icon icon text of the new node
  77. \param imageIndex index of the image for the new node (-1 = none)
  78. \param selectedImageIndex index of the selected image for the new node (-1 = same as imageIndex)
  79. \param data user data (void*) of the new node
  80. \param data2 user data2 (IReferenceCounted*) of the new node
  81. \return The new node
  82. */
  83. virtual IGUITreeViewNode* addChildBack(
  84. const wchar_t* text, const wchar_t* icon = 0,
  85. s32 imageIndex=-1, s32 selectedImageIndex=-1,
  86. void* data=0, IReferenceCounted* data2=0) =0;
  87. //! Adds a new node before the first child node.
  88. /** \param text text of the new node
  89. \param icon icon text of the new node
  90. \param imageIndex index of the image for the new node (-1 = none)
  91. \param selectedImageIndex index of the selected image for the new node (-1 = same as imageIndex)
  92. \param data user data (void*) of the new node
  93. \param data2 user data2 (IReferenceCounted*) of the new node
  94. \return The new node
  95. */
  96. virtual IGUITreeViewNode* addChildFront(
  97. const wchar_t* text, const wchar_t* icon = 0,
  98. s32 imageIndex=-1, s32 selectedImageIndex=-1,
  99. void* data=0, IReferenceCounted* data2=0 ) =0;
  100. //! Adds a new node behind the other node.
  101. /** The other node has also te be a child node from this node.
  102. \param other Node to insert after
  103. \param text text of the new node
  104. \param icon icon text of the new node
  105. \param imageIndex index of the image for the new node (-1 = none)
  106. \param selectedImageIndex index of the selected image for the new node (-1 = same as imageIndex)
  107. \param data user data (void*) of the new node
  108. \param data2 user data2 (IReferenceCounted*) of the new node
  109. \return The new node or 0 if other is no child node from this
  110. */
  111. virtual IGUITreeViewNode* insertChildAfter(
  112. IGUITreeViewNode* other,
  113. const wchar_t* text, const wchar_t* icon = 0,
  114. s32 imageIndex=-1, s32 selectedImageIndex=-1,
  115. void* data=0, IReferenceCounted* data2=0) =0;
  116. //! Adds a new node before the other node.
  117. /** The other node has also te be a child node from this node.
  118. \param other Node to insert before
  119. \param text text of the new node
  120. \param icon icon text of the new node
  121. \param imageIndex index of the image for the new node (-1 = none)
  122. \param selectedImageIndex index of the selected image for the new node (-1 = same as imageIndex)
  123. \param data user data (void*) of the new node
  124. \param data2 user data2 (IReferenceCounted*) of the new node
  125. \return The new node or 0 if other is no child node from this
  126. */
  127. virtual IGUITreeViewNode* insertChildBefore(
  128. IGUITreeViewNode* other,
  129. const wchar_t* text, const wchar_t* icon = 0,
  130. s32 imageIndex=-1, s32 selectedImageIndex=-1,
  131. void* data=0, IReferenceCounted* data2=0) = 0;
  132. //! Return the first child node from this node.
  133. /** \return The first child node or 0 if this node has no children. */
  134. virtual IGUITreeViewNode* getFirstChild() const = 0;
  135. //! Return the last child node from this node.
  136. /** \return The last child node or 0 if this node has no children. */
  137. virtual IGUITreeViewNode* getLastChild() const = 0;
  138. //! Returns the previous sibling node from this node.
  139. /** \return The previous sibling node from this node or 0 if this is
  140. the first node from the parent node.
  141. */
  142. virtual IGUITreeViewNode* getPrevSibling() const = 0;
  143. //! Returns the next sibling node from this node.
  144. /** \return The next sibling node from this node or 0 if this is
  145. the last node from the parent node.
  146. */
  147. virtual IGUITreeViewNode* getNextSibling() const = 0;
  148. //! Returns the next visible (expanded, may be out of scrolling) node from this node.
  149. /** \return The next visible node from this node or 0 if this is
  150. the last visible node. */
  151. virtual IGUITreeViewNode* getNextVisible() const = 0;
  152. //! Deletes a child node.
  153. /** \return Returns true if the node was found as a child and is deleted. */
  154. virtual bool deleteChild( IGUITreeViewNode* child ) = 0;
  155. //! Moves a child node one position up.
  156. /** \return True if the node was found as achild node and was not already the first child. */
  157. virtual bool moveChildUp( IGUITreeViewNode* child ) = 0;
  158. //! Moves a child node one position down.
  159. /** \return True if the node was found as achild node and was not already the last child. */
  160. virtual bool moveChildDown( IGUITreeViewNode* child ) = 0;
  161. //! Returns true if the node is expanded (children are visible).
  162. virtual bool getExpanded() const = 0;
  163. //! Sets if the node is expanded.
  164. virtual void setExpanded( bool expanded ) = 0;
  165. //! Returns true if the node is currently selected.
  166. virtual bool getSelected() const = 0;
  167. //! Sets this node as selected.
  168. virtual void setSelected( bool selected ) = 0;
  169. //! Returns true if this node is the root node.
  170. virtual bool isRoot() const = 0;
  171. //! Returns the level of this node.
  172. /** The root node has level 0. Direct children of the root has level 1 ... */
  173. virtual s32 getLevel() const = 0;
  174. //! Returns true if this node is visible (all parents are expanded).
  175. virtual bool isVisible() const = 0;
  176. };
  177. //! Default tree view GUI element.
  178. /** Displays a windows like tree buttons to expand/collaps the child
  179. nodes of an node and optional tree lines. Each node consits of an
  180. text, an icon text and a void pointer for user data. */
  181. class IGUITreeView : public IGUIElement
  182. {
  183. public:
  184. //! constructor
  185. IGUITreeView(IGUIEnvironment* environment, IGUIElement* parent,
  186. s32 id, core::rect<s32> rectangle)
  187. : IGUIElement( EGUIET_TREE_VIEW, environment, parent, id, rectangle ) {}
  188. //! returns the root node (not visible) from the tree.
  189. virtual IGUITreeViewNode* getRoot() const = 0;
  190. //! returns the selected node of the tree or 0 if none is selected
  191. virtual IGUITreeViewNode* getSelected() const = 0;
  192. //! returns true if the tree lines are visible
  193. virtual bool getLinesVisible() const = 0;
  194. //! sets if the tree lines are visible
  195. /** \param visible true for visible, false for invisible */
  196. virtual void setLinesVisible( bool visible ) = 0;
  197. //! Sets the font which should be used as icon font.
  198. /** This font is set to the Irrlicht engine built-in-font by
  199. default. Icons can be displayed in front of every list item.
  200. An icon is a string, displayed with the icon font. When using
  201. the build-in-font of the Irrlicht engine as icon font, the icon
  202. strings defined in GUIIcons.h can be used.
  203. */
  204. virtual void setIconFont( IGUIFont* font ) = 0;
  205. //! Sets the image list which should be used for the image and selected image of every node.
  206. /** The default is 0 (no images). */
  207. virtual void setImageList( IGUIImageList* imageList ) = 0;
  208. //! Returns the image list which is used for the nodes.
  209. virtual IGUIImageList* getImageList() const = 0;
  210. //! Sets if the image is left of the icon. Default is true.
  211. virtual void setImageLeftOfIcon( bool bLeftOf ) = 0;
  212. //! Returns if the Image is left of the icon. Default is true.
  213. virtual bool getImageLeftOfIcon() const = 0;
  214. //! Returns the node which is associated to the last event.
  215. /** This pointer is only valid inside the OnEvent call! */
  216. virtual IGUITreeViewNode* getLastEventNode() const = 0;
  217. };
  218. } // end namespace gui
  219. } // end namespace irr
  220. #endif