]> git.lizzy.rs Git - irrlicht.git/blob - source/Irrlicht/CGUITreeView.h
Prefer static_cast to reinterpret_cast where possible.
[irrlicht.git] / source / Irrlicht / CGUITreeView.h
1 // This file is part of the "Irrlicht Engine".\r
2 // written by Reinhard Ostermeier, reinhard@nospam.r-ostermeier.de\r
3 \r
4 #ifndef __C_GUI_TREE_VIEW_H_INCLUDED__\r
5 #define __C_GUI_TREE_VIEW_H_INCLUDED__\r
6 \r
7 #include "IGUITreeView.h"\r
8 #include "irrList.h"\r
9 \r
10 \r
11 namespace irr\r
12 {\r
13 namespace gui\r
14 {\r
15         // forward declarations\r
16         class IGUIFont;\r
17         class IGUIScrollBar;\r
18         class CGUITreeView;\r
19 \r
20         //! Node for gui tree view\r
21         class CGUITreeViewNode : public IGUITreeViewNode\r
22         {\r
23         friend class CGUITreeView;\r
24 \r
25         public:\r
26                 //! constructor\r
27                 CGUITreeViewNode( CGUITreeView* owner, CGUITreeViewNode* parent );\r
28 \r
29                 //! destructor\r
30                 ~CGUITreeViewNode();\r
31 \r
32                 //! returns the owner (tree view) of this node\r
33                 virtual IGUITreeView* getOwner() const _IRR_OVERRIDE_;\r
34 \r
35                 //! Returns the parent node of this node.\r
36                 virtual IGUITreeViewNode* getParent() const _IRR_OVERRIDE_;\r
37 \r
38                 //! returns the text of the node\r
39                 virtual const wchar_t* getText() const _IRR_OVERRIDE_\r
40                 { return Text.c_str(); }\r
41 \r
42                 //! sets the text of the node\r
43                 virtual void setText( const wchar_t* text ) _IRR_OVERRIDE_;\r
44 \r
45                 //! returns the icon text of the node\r
46                 virtual const wchar_t* getIcon() const _IRR_OVERRIDE_\r
47                 { return Icon.c_str(); }\r
48 \r
49                 //! sets the icon text of the node\r
50                 virtual void setIcon( const wchar_t* icon ) _IRR_OVERRIDE_;\r
51 \r
52                 //! returns the image index of the node\r
53                 virtual u32 getImageIndex() const _IRR_OVERRIDE_\r
54                 { return ImageIndex; }\r
55 \r
56                 //! sets the image index of the node\r
57                 virtual void setImageIndex( u32 imageIndex ) _IRR_OVERRIDE_\r
58                 { ImageIndex = imageIndex; }\r
59 \r
60                 //! returns the image index of the node\r
61                 virtual u32 getSelectedImageIndex() const _IRR_OVERRIDE_\r
62                 { return SelectedImageIndex; }\r
63 \r
64                 //! sets the image index of the node\r
65                 virtual void setSelectedImageIndex( u32 imageIndex ) _IRR_OVERRIDE_\r
66                 { SelectedImageIndex = imageIndex; }\r
67 \r
68                 //! returns the user data (void*) of this node\r
69                 virtual void* getData() const _IRR_OVERRIDE_\r
70                 { return Data; }\r
71 \r
72                 //! sets the user data (void*) of this node\r
73                 virtual void setData( void* data ) _IRR_OVERRIDE_\r
74                 { Data = data; }\r
75 \r
76                 //! returns the user data2 (IReferenceCounted) of this node\r
77                 virtual IReferenceCounted* getData2() const _IRR_OVERRIDE_\r
78                 { return Data2; }\r
79 \r
80                 //! sets the user data2 (IReferenceCounted) of this node\r
81                 virtual void setData2( IReferenceCounted* data ) _IRR_OVERRIDE_\r
82                 {\r
83                         if( Data2 )\r
84                         {\r
85                                 Data2->drop();\r
86                         }\r
87                         Data2 = data;\r
88                         if( Data2 )\r
89                         {\r
90                                 Data2->grab();\r
91                         }\r
92                 }\r
93 \r
94                 //! returns the child item count\r
95                 virtual u32 getChildCount() const _IRR_OVERRIDE_\r
96                 { return Children.getSize(); }\r
97 \r
98                 //! removes all children (recursive) from this node\r
99                 virtual void clearChildren() _IRR_OVERRIDE_;\r
100 \r
101                 //! returns true if this node has child nodes\r
102                 virtual bool hasChildren() const _IRR_OVERRIDE_\r
103                 { return !Children.empty(); }\r
104 \r
105                 //! Adds a new node behind the last child node.\r
106                 //! \param text text of the new node\r
107                 //! \param icon icon text of the new node\r
108                 //! \param imageIndex index of the image for the new node (-1 = none)\r
109                 //! \param selectedImageIndex index of the selected image for the new node (-1 = same as imageIndex)\r
110                 //! \param data user data (void*) of the new node\r
111                 //! \param data2 user data2 (IReferenceCounted*) of the new node\r
112                 //! \return\r
113                 //! returns the new node\r
114                 virtual IGUITreeViewNode* addChildBack(\r
115                                 const wchar_t* text,\r
116                                 const wchar_t* icon = 0,\r
117                                 s32 imageIndex = -1,\r
118                                 s32 selectedImageIndex = -1,\r
119                                 void* data = 0,\r
120                                 IReferenceCounted* data2 = 0) _IRR_OVERRIDE_;\r
121 \r
122                 //! Adds a new node before the first child node.\r
123                 //! \param text text of the new node\r
124                 //! \param icon icon text of the new node\r
125                 //! \param imageIndex index of the image for the new node (-1 = none)\r
126                 //! \param selectedImageIndex index of the selected image for the new node (-1 = same as imageIndex)\r
127                 //! \param data user data (void*) of the new node\r
128                 //! \param data2 user data2 (IReferenceCounted*) of the new node\r
129                 //! \return\r
130                 //! returns the new node\r
131                 virtual IGUITreeViewNode* addChildFront(\r
132                                 const wchar_t*          text,\r
133                                 const wchar_t*          icon = 0,\r
134                                 s32                                     imageIndex = -1,\r
135                                 s32                                     selectedImageIndex = -1,\r
136                                 void*                                   data = 0,\r
137                                 IReferenceCounted*                      data2 = 0 ) _IRR_OVERRIDE_;\r
138 \r
139                 //! Adds a new node behind the other node.\r
140                 //! The other node has also te be a child node from this node.\r
141                 //! \param text text of the new node\r
142                 //! \param icon icon text of the new node\r
143                 //! \param imageIndex index of the image for the new node (-1 = none)\r
144                 //! \param selectedImageIndex index of the selected image for the new node (-1 = same as imageIndex)\r
145                 //! \param data user data (void*) of the new node\r
146                 //! \param data2 user data2 (IReferenceCounted*) of the new node\r
147                 //! \return\r
148                 //! returns the new node or 0 if other is no child node from this\r
149                 virtual IGUITreeViewNode* insertChildAfter(\r
150                                 IGUITreeViewNode*       other,\r
151                                 const wchar_t*          text,\r
152                                 const wchar_t*          icon = 0,\r
153                                 s32                                     imageIndex = -1,\r
154                                 s32                                     selectedImageIndex = -1,\r
155                                 void*                                   data = 0,\r
156                                 IReferenceCounted*                      data2 = 0 ) _IRR_OVERRIDE_;\r
157 \r
158                 //! Adds a new node before the other node.\r
159                 //! The other node has also te be a child node from this node.\r
160                 //! \param text text of the new node\r
161                 //! \param icon icon text of the new node\r
162                 //! \param imageIndex index of the image for the new node (-1 = none)\r
163                 //! \param selectedImageIndex index of the selected image for the new node (-1 = same as imageIndex)\r
164                 //! \param data user data (void*) of the new node\r
165                 //! \param data2 user data2 (IReferenceCounted*) of the new node\r
166                 //! \return\r
167                 //! returns the new node or 0 if other is no child node from this\r
168                 virtual IGUITreeViewNode* insertChildBefore(\r
169                                 IGUITreeViewNode*       other,\r
170                                 const wchar_t*          text,\r
171                                 const wchar_t*          icon = 0,\r
172                                 s32                                     imageIndex = -1,\r
173                                 s32                                     selectedImageIndex = -1,\r
174                                 void*                                   data = 0,\r
175                                 IReferenceCounted*                      data2 = 0 ) _IRR_OVERRIDE_;\r
176 \r
177                 //! Return the first child note from this node.\r
178                 virtual IGUITreeViewNode* getFirstChild() const _IRR_OVERRIDE_;\r
179 \r
180                 //! Return the last child note from this node.\r
181                 virtual IGUITreeViewNode* getLastChild() const _IRR_OVERRIDE_;\r
182 \r
183                 //! Returns the preverse sibling node from this node.\r
184                 virtual IGUITreeViewNode* getPrevSibling() const _IRR_OVERRIDE_;\r
185 \r
186                 //! Returns the next sibling node from this node.\r
187                 virtual IGUITreeViewNode* getNextSibling() const _IRR_OVERRIDE_;\r
188 \r
189                 //! Returns the next visible (expanded, may be out of scrolling) node from this node.\r
190                 virtual IGUITreeViewNode* getNextVisible() const _IRR_OVERRIDE_;\r
191 \r
192                 //! Deletes a child node.\r
193                 virtual bool deleteChild( IGUITreeViewNode* child ) _IRR_OVERRIDE_;\r
194 \r
195                 //! Moves a child node one position up.\r
196                 virtual bool moveChildUp( IGUITreeViewNode* child ) _IRR_OVERRIDE_;\r
197 \r
198                 //! Moves a child node one position down.\r
199                 virtual bool moveChildDown( IGUITreeViewNode* child ) _IRR_OVERRIDE_;\r
200 \r
201                 //! Returns true if the node is expanded (children are visible).\r
202                 virtual bool getExpanded() const _IRR_OVERRIDE_\r
203                 { return Expanded; }\r
204 \r
205                 //! Sets if the node is expanded.\r
206                 virtual void setExpanded( bool expanded ) _IRR_OVERRIDE_;\r
207 \r
208                 //! Returns true if the node is currently selected.\r
209                 virtual bool getSelected() const _IRR_OVERRIDE_;\r
210 \r
211                 //! Sets this node as selected.\r
212                 virtual void setSelected( bool selected ) _IRR_OVERRIDE_;\r
213 \r
214                 //! Returns true if this node is the root node.\r
215                 virtual bool isRoot() const _IRR_OVERRIDE_;\r
216 \r
217                 //! Returns the level of this node.\r
218                 virtual s32 getLevel() const _IRR_OVERRIDE_;\r
219 \r
220                 //! Returns true if this node is visible (all parents are expanded).\r
221                 virtual bool isVisible() const _IRR_OVERRIDE_;\r
222 \r
223         private:\r
224 \r
225                 CGUITreeView*                   Owner;\r
226                 CGUITreeViewNode*               Parent;\r
227                 core::stringw                   Text;\r
228                 core::stringw                   Icon;\r
229                 s32                             ImageIndex;\r
230                 s32                             SelectedImageIndex;\r
231                 void*                           Data;\r
232                 IReferenceCounted*              Data2;\r
233                 bool                            Expanded;\r
234                 core::list<CGUITreeViewNode*>   Children;\r
235         };\r
236 \r
237 \r
238         //! Default tree view GUI element.\r
239         class CGUITreeView : public IGUITreeView\r
240         {\r
241         friend class CGUITreeViewNode;\r
242 \r
243         public:\r
244                 //! constructor\r
245                 CGUITreeView( IGUIEnvironment* environment, IGUIElement* parent,\r
246                         s32 id, core::rect<s32> rectangle, bool clip = true,\r
247                         bool drawBack = false, bool scrollBarVertical = true, bool scrollBarHorizontal = true );\r
248 \r
249                 //! destructor\r
250                 virtual ~CGUITreeView();\r
251 \r
252                 //! returns the root node (not visible) from the tree.\r
253                 virtual IGUITreeViewNode* getRoot() const _IRR_OVERRIDE_\r
254                 { return Root; }\r
255 \r
256                 //! returns the selected node of the tree or 0 if none is selected\r
257                 virtual IGUITreeViewNode* getSelected() const _IRR_OVERRIDE_\r
258                 { return Selected; }\r
259 \r
260                 //! returns true if the tree lines are visible\r
261                 virtual bool getLinesVisible() const _IRR_OVERRIDE_\r
262                 { return LinesVisible; }\r
263 \r
264                 //! sets if the tree lines are visible\r
265                 virtual void setLinesVisible( bool visible ) _IRR_OVERRIDE_\r
266                 { LinesVisible = visible; }\r
267 \r
268                 //! called if an event happened.\r
269                 virtual bool OnEvent( const SEvent &event ) _IRR_OVERRIDE_;\r
270 \r
271                 //! draws the element and its children\r
272                 virtual void draw() _IRR_OVERRIDE_;\r
273 \r
274                 //! Sets the font which should be used as icon font. This font is set to the Irrlicht engine\r
275                 //! built-in-font by default. Icons can be displayed in front of every list item.\r
276                 //! An icon is a string, displayed with the icon font. When using the build-in-font of the\r
277                 //! Irrlicht engine as icon font, the icon strings defined in GUIIcons.h can be used.\r
278                 virtual void setIconFont( IGUIFont* font ) _IRR_OVERRIDE_;\r
279 \r
280                 //! Sets a skin independent font.\r
281                 /** \param font: New font to set or 0 to use the skin-font. */\r
282                 virtual void setOverrideFont(IGUIFont* font=0) _IRR_OVERRIDE_;\r
283 \r
284                 //! Gets the override font (if any)\r
285                 /** \return The override font (may be 0) */\r
286                 virtual IGUIFont* getOverrideFont(void) const _IRR_OVERRIDE_;\r
287 \r
288                 //! Get the font which is used for drawing\r
289                 /** This is the override font when one is set and the\r
290                 font of the skin otherwise. */\r
291                 virtual IGUIFont* getActiveFont() const _IRR_OVERRIDE_;\r
292 \r
293                 //! Sets the image list which should be used for the image and selected image of every node.\r
294                 //! The default is 0 (no images).\r
295                 virtual void setImageList( IGUIImageList* imageList ) _IRR_OVERRIDE_;\r
296 \r
297                 //! Returns the image list which is used for the nodes.\r
298                 virtual IGUIImageList* getImageList() const _IRR_OVERRIDE_\r
299                 { return ImageList; }\r
300 \r
301                 //! Sets if the image is left of the icon. Default is true.\r
302                 virtual void setImageLeftOfIcon( bool bLeftOf ) _IRR_OVERRIDE_\r
303                 { ImageLeftOfIcon = bLeftOf; }\r
304 \r
305                 //! Returns if the Image is left of the icon. Default is true.\r
306                 virtual bool getImageLeftOfIcon() const _IRR_OVERRIDE_\r
307                 { return ImageLeftOfIcon; }\r
308 \r
309                 //! Returns the node which is associated to the last event.\r
310                 virtual IGUITreeViewNode* getLastEventNode() const _IRR_OVERRIDE_\r
311                 { return LastEventNode; }\r
312 \r
313                 //! Access the vertical scrollbar\r
314                 virtual IGUIScrollBar* getVerticalScrollBar() const _IRR_OVERRIDE_;\r
315 \r
316                 //! Access the horizontal scrollbar\r
317                 virtual IGUIScrollBar* getHorizontalScrollBar() const _IRR_OVERRIDE_;\r
318 \r
319         private:\r
320                 //! calculates the heigth of an node and of all visible nodes.\r
321                 void recalculateItemHeight();\r
322 \r
323                 //! Resize scrollbars when their size in the skin has changed\r
324                 void updateScrollBarSize(s32 size);\r
325 \r
326                 //! executes an mouse action (like selectNew of CGUIListBox)\r
327                 void mouseAction( s32 xpos, s32 ypos, bool onlyHover = false );\r
328 \r
329                 CGUITreeViewNode*       Root;\r
330                 IGUITreeViewNode*       Selected;\r
331                 s32                     ItemHeight;\r
332                 s32                     IndentWidth;\r
333                 s32                     TotalItemHeight;\r
334                 s32                     TotalItemWidth;\r
335                 s32                     ScrollBarSize;\r
336                 IGUIFont*               Font;\r
337                 gui::IGUIFont*  OverrideFont;\r
338                 IGUIFont*               IconFont;\r
339                 IGUIScrollBar*          ScrollBarH;\r
340                 IGUIScrollBar*          ScrollBarV;\r
341                 IGUIImageList*          ImageList;\r
342                 IGUITreeViewNode*       LastEventNode;\r
343                 bool                    LinesVisible;\r
344                 bool                    Selecting;\r
345                 bool                    Clip;\r
346                 bool                    DrawBack;\r
347                 bool                    ImageLeftOfIcon;\r
348         };\r
349 \r
350 \r
351 } // end namespace gui\r
352 } // end namespace irr\r
353 \r
354 #endif\r
355 \r