Some updates (incomplete)
[wxWidgets.git] / utils / configtool / src / configtooldoc.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: configtooldoc.h
3 // Purpose: Document class
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 2003-06-04
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence:
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _CT_CONFIGTOOLDOC_H_
13 #define _CT_CONFIGTOOLDOC_H_
14
15 #ifdef __GNUG__
16 #pragma interface "configtooldoc.cpp"
17 #endif
18
19 #include "wx/docview.h"
20 #include "wx/cmdproc.h"
21
22 #include "configitem.h"
23
24 class wxSimpleHtmlTag;
25 class ctConfiguration;
26
27 /*!
28 * ctConfigToolDoc
29 */
30
31 class ctConfigToolDoc: public wxDocument
32 {
33 DECLARE_DYNAMIC_CLASS(ctConfigToolDoc)
34 public:
35 ctConfigToolDoc();
36 ~ctConfigToolDoc();
37
38 //// Overrides
39 virtual bool OnCreate(const wxString& path, long flags);
40 virtual bool OnOpenDocument(const wxString& filename);
41 virtual bool OnSaveDocument(const wxString& filename);
42 virtual bool OnNewDocument() { return TRUE; }
43 virtual bool OnCloseDocument() ;
44 virtual bool Save(); // Overridden only to correct bug in wxWindows, docview.cpp
45
46 //// Accessors
47
48 /// Returns the top item.
49 ctConfigItem* GetTopItem() const { return m_topItem; }
50
51 /// Sets the top item.
52 void SetTopItem(ctConfigItem* item) { m_topItem = item; }
53
54 /// Returns the clipboard item.
55 ctConfigItem* GetClipboardItem() const { return m_clipboardItem; }
56
57 /// Sets the clipboard item.
58 void SetClipboardItem(ctConfigItem* item) ;
59
60 /// Clears the clipboard item.
61 void ClearClipboard() ;
62
63 /// Gets the current framework directory
64 wxString GetFrameworkDir(bool makeUnix);
65
66 //// Operations
67
68 /// Add items
69 void AddItems();
70
71 /// Delete items
72 void DeleteItems();
73
74 /// Save the settings file
75 bool DoSave(const wxString& filename);
76
77 /// Recursive helper function for file saving
78 bool DoSave(ctConfigItem* item, wxOutputStream& stream, int indent);
79
80 /// Open the settings file
81 bool DoOpen(const wxString& filename);
82
83 /// Helper for file opening.
84 bool DoOpen(wxSimpleHtmlTag* tag, ctConfigItem* parent);
85
86 /// Refresh dependencies
87 void RefreshDependencies();
88 void RefreshDependencies(ctConfigItem* item);
89
90 /// Clear dependencies
91 void ClearDependencies(ctConfigItem* item);
92
93 /// Generate the text of a setup.h
94 wxString GenerateSetup();
95
96 /// Helper function
97 void GenerateSetup(ctConfigItem* item, wxString& str);
98
99 /// Generate a configure command
100 wxString GenerateConfigureCommand();
101
102 /// Helper function
103 void GenerateConfigureCommand(ctConfigItem* item, wxString& str);
104
105 /// Finds the next item in the tree
106 ctConfigItem* FindNextItem(ctConfigItem* item, bool wrap);
107
108 /// Finds the next sibling in the tree
109 ctConfigItem* FindNextSibling(ctConfigItem* item);
110
111 protected:
112 ctConfigItem* m_topItem;
113 ctConfigItem* m_clipboardItem;
114 };
115
116 /*!
117 * ctConfiguration is a configuration or a place-holder node within the
118 * hierarchy of configurations.
119 */
120
121 class ctConfiguration: public wxObject
122 {
123 public:
124 /// Ctor and dtor
125 ctConfiguration(ctConfiguration* parent, const wxString& name);
126 ctConfiguration();
127 ~ctConfiguration();
128
129 /// Copy constructor.
130 ctConfiguration(const ctConfiguration& configuration)
131 {
132 (*this) = configuration;
133 }
134
135 /// Operations
136
137 /// Assignment operator.
138 void operator= (const ctConfiguration& configuration);
139
140 /// Create a clone
141 ctConfiguration* Clone()
142 {
143 ctConfiguration* configuration = new ctConfiguration;
144 *configuration = *this;
145 return configuration;
146 }
147
148 /// Create a clone of this and children
149 ctConfiguration* DeepClone();
150
151 /// Clear children
152 void Clear();
153
154 /// Add a child
155 void AddChild(ctConfiguration* config);
156
157 /// Remove (but don't delete) a child
158 void RemoveChild(ctConfiguration* config);
159
160 /// Find an item in this hierarchy
161 ctConfiguration* FindConfiguration(const wxString& name);
162
163 /// Find the next sibling
164 ctConfiguration* FindNextSibling();
165
166 /// Find the previous sibling
167 ctConfiguration* FindPreviousSibling();
168
169 /// Detach: remove from parent, and remove tree items
170 void Detach();
171
172 /// Attach: insert before the given position
173 void Attach(ctConfiguration* parent, ctConfiguration* insertbefore);
174
175 void DetachFromTree();
176
177 /// Accessors
178
179 /// Returns the top-level item.
180 ctConfigItem* GetTopItem() const { return m_topItem; }
181
182 /// Sets the top-level item.
183 void SetTopItem(ctConfigItem* item) { m_topItem = item; }
184
185 /// Returns the name.
186 wxString GetName() const { return m_name; }
187
188 /// Sets the name.
189 void SetName(const wxString& name ) { m_name = name; }
190
191 /// Get description.
192 wxString GetDescription() const { return m_description; }
193
194 /// Set description.
195 void SetDescription(const wxString& descr) { m_description = descr; }
196
197 /// Set the tree item id
198 void SetTreeItem(wxTreeItemId id) { m_treeItemId = id; }
199
200 // Get the type
201 wxTreeItemId GetTreeItemId() const { return m_treeItemId ; }
202
203 /// Get the list of children
204 wxList& GetChildren() { return m_children; }
205
206 /// Get the nth child
207 ctConfiguration* GetChild(int n) const;
208
209 /// Get the child count
210 int GetChildCount() const;
211
212 /// Get the parent
213 ctConfiguration* GetParent() const { return m_parent; }
214
215 /// Set the parent
216 void SetParent(ctConfiguration* parent) { m_parent = parent; }
217
218 /// Get the associated document (currently, assumes
219 /// there's only ever one document active)
220 ctConfigToolDoc* GetDocument() ;
221
222 protected:
223
224 /// The corresponding tree item
225 wxTreeItemId m_treeItemId;
226
227 /// The list of children.
228 wxList m_children;
229
230 /// The parent config item
231 ctConfiguration* m_parent;
232
233 /// The name
234 wxString m_name;
235
236 /// The description
237 wxString m_description;
238
239 /// The top-level item of this description, if any
240 ctConfigItem* m_topItem;
241
242 DECLARE_CLASS(ctConfiguration)
243 };
244
245
246 /*!
247 * Implements a document editing command.
248 * We only need to store one state at a time,
249 * since we don't have (or need) multiple selection.
250 */
251
252 #define ctCMD_NEW_ELEMENT 1
253 #define ctCMD_PASTE 2
254 #define ctCMD_CUT 3
255 #define ctCMD_APPLY_PROPERTY 4
256
257 class ctConfigCommand: public wxCommand
258 {
259 public:
260 ctConfigCommand(const wxString& name, int cmdId,
261 ctConfigItem* activeState, ctConfigItem* savedState,
262 ctConfigItem* parent = NULL, ctConfigItem* insertBefore = NULL,
263 bool ignoreFirstTime = FALSE);
264 ctConfigCommand(const wxString& name, int cmdId,
265 ctConfigItem* activeState, ctProperties* properties,
266 bool ignoreFirstTime = FALSE);
267 ~ctConfigCommand();
268
269 bool Do();
270 bool Undo();
271 bool DoAndUndo(bool doCmd); // Combine Do and Undo into one
272
273 protected:
274 ctConfigItem* m_activeState;
275 ctConfigItem* m_savedState;
276 ctProperties* m_properties;
277 bool m_ignoreThis; // Ignore 1st Do because we already did it
278 int m_cmdId;
279 ctConfigItem* m_parent;
280 ctConfigItem* m_insertBefore;
281 };
282
283
284 #endif
285 // _CT_CONFIGTOOLDOC_H_