1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef TITANIC_TREE_ITEM_H
24 #define TITANIC_TREE_ITEM_H
25 
26 #include "titanic/core/message_target.h"
27 #include "titanic/support/simple_file.h"
28 
29 namespace Titanic {
30 
31 class CGameManager;
32 class CMovieClipList;
33 class CNamedItem;
34 class CProjectItem;
35 class CScreenManager;
36 class CViewItem;
37 
38 class CTreeItem: public CMessageTarget {
39 	friend class CMessage;
40 	DECLARE_MESSAGE_MAP;
41 private:
42 	CTreeItem *_parent;
43 	CTreeItem *_nextSibling;
44 	CTreeItem *_priorSibling;
45 	CTreeItem *_firstChild;
46 	int _field14;
47 public:
48 	CLASSDEF;
49 	CTreeItem();
50 
51 
52 	/**
53 	 * Dump the item and any of it's children
54 	 */
55 	void dump(int indent);
56 
57 	/**
58 	 * Dump the item
59 	 */
60 	virtual CString dumpItem(int indent) const;
61 
62 	/**
63 	 * Save the data for the class to file
64 	 */
65 	virtual void save(SimpleFile *file, int indent);
66 
67 	/**
68 	 * Load the data for the class from file
69 	 */
70 	virtual void load(SimpleFile *file);
71 
72 	/**
73 	 * Get the game manager for the project
74 	 */
75 	virtual CGameManager *getGameManager() const;
76 
77 	/**
78 	 * Returns true if the item is a file item
79 	 */
80 	virtual bool isFileItem() const;
81 
82 	/**
83 	 * Returns true if the item is a room item
84 	 */
85 	virtual bool isRoomItem() const;
86 
87 	/**
88 	 * Returns true if the item is a node item
89 	 */
90 	virtual bool isNodeItem() const;
91 
92 	/**
93 	 * Returns true if the item is a view item
94 	 */
95 	virtual bool isViewItem() const;
96 
97 	/**
98 	 * Returns true if the item is a link item
99 	 */
100 	virtual bool isLinkItem() const;
101 
102 	/**
103 	 * Returns true if the item is a placeholder item
104 	 */
105 	virtual bool isPlaceHolderItem() const;
106 
107 	/**
108 	 * Returns true if the item is a named item
109 	 */
110 	virtual bool isNamedItem() const;
111 
112 	/**
113 	 * Returns true if the item is a game object
114 	 */
115 	virtual bool isGameObject() const;
116 
117 	/**
118 	 * Returns true if the item is a game object desc item
119 	 */
120 	virtual bool isGameObjectDescItem() const;
121 
122 	/**
123 	 * Gets the name of the item, if any
124 	 */
getName()125 	virtual const CString getName() const { return CString(); }
126 
127 	/**
128 	 * Returns true if the item's name matches a passed name
129 	 */
130 	virtual bool isEquals(const CString &name, bool startsWith = false) const{ return false; }
131 
132 	/**
133 	 * Compares the name of the item to a passed name
134 	 */
135 	virtual int compareTo(const CString &name, int maxLen = 0) const { return false; }
136 
137 	/**
138 	 * Returns the clip list, if any, associated with the item
139 	 */
getMovieClips()140 	virtual const CMovieClipList *getMovieClips() const { return nullptr; }
141 
142 	/**
143 	 * Returns true if the given item connects to another specified view
144 	 */
connectsTo(CViewItem * destView)145 	virtual bool connectsTo(CViewItem *destView) const { return false; }
146 
147 	/**
148 	 * Allows the item to draw itself
149 	 */
draw(CScreenManager * screenManager)150 	virtual void draw(CScreenManager *screenManager) {}
151 
152 	/**
153 	 * Gets the bounds occupied by the item
154 	 */
getBounds()155 	virtual Rect getBounds() const { return Rect(); }
156 
157 	/**
158 	 * Free up any surface the object used
159 	 */
freeSurface()160 	virtual void freeSurface() {}
161 
162 	/**
163 	 * Get the parent for the given item
164 	 */
getParent()165 	CTreeItem *getParent() const { return _parent; }
166 
167 	/**
168 	 * Jumps up through the parents to find the root item
169 	 */
170 	CProjectItem *getRoot() const;
171 
172 	/**
173 	 * Get the next sibling
174 	 */
getNextSibling()175 	CTreeItem *getNextSibling() const { return _nextSibling; }
176 
177 	/**
178 	 * Get the prior sibling
179 	 */
getPriorSibling()180 	CTreeItem *getPriorSibling() const { return _priorSibling; }
181 
182 	/**
183 	 * Get the last sibling of this sibling
184 	 */
185 	CTreeItem *getLastSibling();
186 
187 	/**
188 	 * Get the first child of the item, if any
189 	 */
getFirstChild()190 	CTreeItem *getFirstChild() const { return _firstChild; }
191 
192 	/**
193 	 * Get the last child of the item, if any
194 	 */
195 	CTreeItem *getLastChild() const;
196 
197 	/**
198 	 * Given all the recursive children of the tree item, gives the next
199 	 * item in sequence to the passed starting item
200 	 */
201 	CTreeItem *scan(CTreeItem *item) const;
202 
203 	/**
204 	 * Find the first child item that is of a given type
205 	 */
206 	CTreeItem *findChildInstanceOf(ClassDef *classDef) const;
207 
208 	/**
209 	 * Find the next sibling item that is of the given type
210 	 */
211 	CTreeItem *findNextInstanceOf(ClassDef *classDef, CTreeItem *startItem) const;
212 
213 	/**
214 	 * Adds the item under another tree item
215 	 */
216 	void addUnder(CTreeItem *newParent);
217 
218 	/**
219 	 * Sets the parent for the item
220 	 */
221 	void setParent(CTreeItem *newParent);
222 
223 	/**
224 	 * Adds the item as a sibling of another item
225 	 */
226 	void addSibling(CTreeItem *item);
227 
228 	/**
229 	 * Moves the tree item to be under another parent
230 	 */
231 	void moveUnder(CTreeItem *newParent);
232 
233 	/**
234 	 * Destroys both the item as well as any of it's children
235 	 */
236 	void destroyAll();
237 
238 	/**
239 	 * Destroys all child tree items under this one.
240 	 * @returns		Total number of tree items recursively removed
241 	 */
242 	int destroyChildren();
243 
244 	/**
245 	 * Detach the tree item from any other associated tree items
246 	 */
247 	void detach();
248 
249 	/**
250 	 * Attaches a tree item to a new node
251 	 */
252 	void attach(CTreeItem *item);
253 
254 	/**
255 	 * Finds a tree item by name
256 	 * @param name		Name to find
257 	 * @param subMatch	If false, does an exact name match.
258 	 *		If false, matches any item that starts with the given name
259 	 */
260 	CNamedItem *findByName(const CString &name, bool subMatch = false);
261 };
262 
263 } // End of namespace Titanic
264 
265 #endif /* TITANIC_TREE_ITEM_H */
266