1 /////////////////////////////////////////////////////////////////////////////
2 // Name: configtooldoc.h
3 // Purpose: Document class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _CT_CONFIGTOOLDOC_H_
13 #define _CT_CONFIGTOOLDOC_H_
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "configtooldoc.cpp"
19 #include "wx/docview.h"
20 #include "wx/cmdproc.h"
22 #include "configitem.h"
24 class wxSimpleHtmlTag
;
25 class ctConfiguration
;
31 class ctConfigToolDoc
: public wxDocument
33 DECLARE_DYNAMIC_CLASS(ctConfigToolDoc
)
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 wxWidgets, docview.cpp
48 /// Returns the top item.
49 ctConfigItem
* GetTopItem() const { return m_topItem
; }
51 /// Sets the top item.
52 void SetTopItem(ctConfigItem
* item
) { m_topItem
= item
; }
54 /// Returns the clipboard item.
55 ctConfigItem
* GetClipboardItem() const { return m_clipboardItem
; }
57 /// Sets the clipboard item.
58 void SetClipboardItem(ctConfigItem
* item
) ;
60 /// Clears the clipboard item.
61 void ClearClipboard() ;
63 /// Gets the current framework directory
64 wxString
GetFrameworkDir(bool makeUnix
);
74 /// Save the settings file
75 bool DoSave(const wxString
& filename
);
77 /// Recursive helper function for file saving
78 bool DoSave(ctConfigItem
* item
, wxOutputStream
& stream
, int indent
);
80 /// Open the settings file
81 bool DoOpen(const wxString
& filename
);
83 /// Helper for file opening.
84 bool DoOpen(wxSimpleHtmlTag
* tag
, ctConfigItem
* parent
);
86 /// Refresh dependencies
87 void RefreshDependencies();
88 void RefreshDependencies(ctConfigItem
* item
);
90 /// Clear dependencies
91 void ClearDependencies(ctConfigItem
* item
);
93 /// Generate the text of a setup.h
94 wxString
GenerateSetup();
97 void GenerateSetup(ctConfigItem
* item
, wxString
& str
);
99 /// Generate a configure command
100 wxString
GenerateConfigureCommand();
103 void GenerateConfigureCommand(ctConfigItem
* item
, wxString
& str
);
105 /// Finds the next item in the tree
106 ctConfigItem
* FindNextItem(ctConfigItem
* item
, bool wrap
);
108 /// Finds the next sibling in the tree
109 ctConfigItem
* FindNextSibling(ctConfigItem
* item
);
112 ctConfigItem
* m_topItem
;
113 ctConfigItem
* m_clipboardItem
;
117 * ctConfiguration is a configuration or a place-holder node within the
118 * hierarchy of configurations.
121 class ctConfiguration
: public wxObject
125 ctConfiguration(ctConfiguration
* parent
, const wxString
& name
);
129 /// Copy constructor.
130 ctConfiguration(const ctConfiguration
& configuration
)
132 (*this) = configuration
;
137 /// Assignment operator.
138 void operator= (const ctConfiguration
& configuration
);
141 ctConfiguration
* Clone()
143 ctConfiguration
* configuration
= new ctConfiguration
;
144 *configuration
= *this;
145 return configuration
;
148 /// Create a clone of this and children
149 ctConfiguration
* DeepClone();
155 void AddChild(ctConfiguration
* config
);
157 /// Remove (but don't delete) a child
158 void RemoveChild(ctConfiguration
* config
);
160 /// Find an item in this hierarchy
161 ctConfiguration
* FindConfiguration(const wxString
& name
);
163 /// Find the next sibling
164 ctConfiguration
* FindNextSibling();
166 /// Find the previous sibling
167 ctConfiguration
* FindPreviousSibling();
169 /// Detach: remove from parent, and remove tree items
172 /// Attach: insert before the given position
173 void Attach(ctConfiguration
* parent
, ctConfiguration
* insertbefore
);
175 void DetachFromTree();
179 /// Returns the top-level item.
180 ctConfigItem
* GetTopItem() const { return m_topItem
; }
182 /// Sets the top-level item.
183 void SetTopItem(ctConfigItem
* item
) { m_topItem
= item
; }
185 /// Returns the name.
186 wxString
GetName() const { return m_name
; }
189 void SetName(const wxString
& name
) { m_name
= name
; }
192 wxString
GetDescription() const { return m_description
; }
195 void SetDescription(const wxString
& descr
) { m_description
= descr
; }
197 /// Set the tree item id
198 void SetTreeItem(wxTreeItemId id
) { m_treeItemId
= id
; }
201 wxTreeItemId
GetTreeItemId() const { return m_treeItemId
; }
203 /// Get the list of children
204 wxList
& GetChildren() { return m_children
; }
206 /// Get the nth child
207 ctConfiguration
* GetChild(int n
) const;
209 /// Get the child count
210 int GetChildCount() const;
213 ctConfiguration
* GetParent() const { return m_parent
; }
216 void SetParent(ctConfiguration
* parent
) { m_parent
= parent
; }
218 /// Get the associated document (currently, assumes
219 /// there's only ever one document active)
220 ctConfigToolDoc
* GetDocument() ;
224 /// The corresponding tree item
225 wxTreeItemId m_treeItemId
;
227 /// The list of children.
230 /// The parent config item
231 ctConfiguration
* m_parent
;
237 wxString m_description
;
239 /// The top-level item of this description, if any
240 ctConfigItem
* m_topItem
;
242 DECLARE_CLASS(ctConfiguration
)
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.
252 #define ctCMD_NEW_ELEMENT 1
253 #define ctCMD_PASTE 2
255 #define ctCMD_APPLY_PROPERTY 4
257 class ctConfigCommand
: public wxCommand
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);
271 bool DoAndUndo(bool doCmd
); // Combine Do and Undo into one
274 ctConfigItem
* m_activeState
;
275 ctConfigItem
* m_savedState
;
276 ctProperties
* m_properties
;
277 bool m_ignoreThis
; // Ignore 1st Do because we already did it
279 ctConfigItem
* m_parent
;
280 ctConfigItem
* m_insertBefore
;
285 // _CT_CONFIGTOOLDOC_H_