IGUITreeView.h 11 KB

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