]> git.saurik.com Git - wxWidgets.git/blob - utils/configtool/src/configitem.h
Regenerate Makefile.in, configure and the VC++ project files after adding rcdefs.h
[wxWidgets.git] / utils / configtool / src / configitem.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: configitem.h
3 // Purpose: wxWidgets Configuration Tool config item class
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 2003-06-03
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence:
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _CT_CONFIGITEM_H_
13 #define _CT_CONFIGITEM_H_
14
15 #include "wx/wx.h"
16 #include "wx/treectrl.h"
17
18 #include "property.h"
19
20 class ctConfigToolDoc;
21
22 /*!
23 * The type of config item
24 */
25
26 enum ctConfigType
27 {
28 ctTypeUnknown,
29 ctTypeGroup, // A group with no checkbox
30 ctTypeCheckGroup, // A group that can be switched on/off (check)
31 ctTypeRadioGroup, // A group that can be switched on/off (radio)
32 ctTypeString, // An option with a string value
33 ctTypeInteger, // An option with an integer value
34 ctTypeBoolCheck, // An on/off option
35 ctTypeBoolRadio // An on/off mutually exclusive option
36 };
37
38 /*!
39 * ctConfigItem represents a configuration setting.
40 * Each setting has a number of properties, some of
41 * which may be specific to a particular kind of
42 * setting, so we make it quite generic and extensible
43 * by using a property list.
44 */
45
46 class ctConfigItem: public wxObject
47 {
48 public:
49 /// Ctor and dtor
50 ctConfigItem(ctConfigItem* parent, ctConfigType type, const wxString& name);
51 ctConfigItem();
52 ~ctConfigItem();
53
54 /// Copy constructor.
55 ctConfigItem(const ctConfigItem& item) : wxObject()
56 {
57 (*this) = item;
58 }
59
60 /// Operations
61
62 /// Assignment operator.
63 void operator= (const ctConfigItem& item);
64
65 /// Create a clone
66 ctConfigItem* Clone()
67 {
68 ctConfigItem* item = new ctConfigItem;
69 *item = *this;
70 return item;
71 }
72
73 /// Create a clone of this and children
74 ctConfigItem* DeepClone();
75
76 /// Do additional actions to apply the property to the internal
77 /// representation.
78 void ApplyProperty(ctProperty* prop, const wxVariant& oldValue);
79
80 /// Clear children
81 void Clear();
82
83 /// Add a child
84 void AddChild(ctConfigItem* item);
85
86 /// Remove (but don't delete) a child
87 void RemoveChild(ctConfigItem* item);
88
89 /// Initialise standard properties
90 void InitProperties();
91
92 /// Convert string containing config item names to
93 /// an array of config item names
94 static void StringToArray(const wxString& items, wxArrayString& itemsArray);
95
96 /// Convert array containing config item names to
97 /// a string
98 static void ArrayToString(const wxArrayString& itemsArray, wxString& items);
99
100 /// Populate a list of items found in the string.
101 static void StringToItems(ctConfigItem* topItem, const wxString& items, wxList& list);
102
103 /// Find an item in this hierarchy
104 ctConfigItem* FindItem(const wxString& name);
105
106 /// Find the next sibling
107 ctConfigItem* FindNextSibling();
108
109 /// Find the previous sibling
110 ctConfigItem* FindPreviousSibling();
111
112 /// Sync appearance
113 void Sync();
114
115 /// Detach: remove from parent, and remove tree items
116 void Detach();
117
118 /// Attach: insert before the given position
119 void Attach(ctConfigItem* parent, ctConfigItem* insertbefore);
120
121 /// Hide from tree: make sure tree deletions won't delete
122 /// the config items
123 void DetachFromTree();
124
125 /// Evaluate the depends-on properties:
126 /// if any of the depends-on items are disabled,
127 /// then this one is disabled (and inactive).
128 void EvaluateDependencies();
129
130 /// Propagate a change in enabled/disabled status
131 void PropagateChange(wxList& considered);
132
133 /// Process radio button selection
134 void PropagateRadioButton(wxList& considered);
135
136 // An item is in the active context if:
137 // The context field is empty; or
138 // The context field contains a symbol that is currently enabled.
139 bool IsInActiveContext();
140
141 /// Accessors
142
143 /// Returns the name property.
144 wxString GetName() const { return GetPropertyString(wxT("name")); }
145
146 /// Sets the name property.
147 void SetName(const wxString& name ) ;
148
149 /// Returns the value property.
150 wxVariant GetValue() const { return m_properties.FindPropertyValue(wxT("value")); }
151
152 /// Sets the value property.
153 void SetValue(const wxVariant& value ) ;
154
155 /// Returns the string for the given property.
156 wxString GetPropertyString(const wxString& propName) const { return m_properties.FindPropertyValueString(propName); }
157
158 /// Sets the string for the given property.
159 void SetPropertyString(const wxString& propName, const wxString& value) { m_properties.SetProperty(propName, value); }
160
161 /// Can we edit this property?
162 bool CanEditProperty(const wxString& propName) const ;
163
164 /// Returns the list of properties for
165 /// this item.
166 ctProperties& GetProperties() { return m_properties; }
167
168 /// Set the default property.
169 void SetDefaultProperty(const wxString& defaultProp) { m_defaultProperty = defaultProp; }
170
171 /// Get the default property.
172 wxString GetDefaultProperty() const { return m_defaultProperty; }
173
174 /// Is this item modified?
175 bool IsModified() const { return m_modified; }
176
177 /// Mark this as modified.
178 void Modify(bool modified = true) { m_modified = modified; }
179
180 /// Is this item enabled? (checked/unchecked)
181 bool IsEnabled() const { return m_enabled; }
182
183 /// Enable or disable (check/uncheck)
184 void Enable(bool enable = true) { m_enabled = enable; }
185
186 /// Is this item active? (sensitive to user input)
187 bool IsActive() const { return m_active; }
188
189 /// Make this (in)active
190 void SetActive(bool active = true) { m_active = active; }
191
192 /// Set the type
193 void SetType(ctConfigType type) { m_type = type; }
194
195 // Get the type
196 ctConfigType GetType() const { return m_type; }
197
198 /// Set the tree item id
199 void SetTreeItem(wxTreeItemId id) { m_treeItemId = id; }
200
201 // Get the type
202 wxTreeItemId GetTreeItemId() const { return m_treeItemId ; }
203
204 /// Get the list of children
205 wxList& GetChildren() { return m_children; }
206
207 /// Get the nth child
208 ctConfigItem* GetChild(int n) const;
209
210 /// Get the child count
211 int GetChildCount() const;
212
213 /// Get the list of dependents
214 wxList& GetDependents() { return m_dependents; }
215
216 /// Get the parent
217 ctConfigItem* GetParent() const { return m_parent; }
218
219 /// Set the parent
220 void SetParent(ctConfigItem* parent) { m_parent = parent; }
221
222 /// Get the associated document (currently, assumes
223 /// there's only ever one document active)
224 ctConfigToolDoc* GetDocument() ;
225
226 /// Can have children?
227 bool CanHaveChildren() const;
228
229 /// Get description, which may be dynamically
230 /// generated depending on the property.
231 wxString GetDescription(ctProperty* property);
232
233 /// Get the title for the property editor
234 wxString GetTitle();
235
236 protected:
237
238 /// The properties for this item.
239 ctProperties m_properties;
240
241 /// The default property, from the point of
242 /// of double-clicking the config item.
243 wxString m_defaultProperty;
244
245 /// Whether modified
246 bool m_modified;
247
248 /// The type of the config item
249 ctConfigType m_type;
250
251 /// The corresponding tree item
252 wxTreeItemId m_treeItemId;
253
254 /// Is this option enabled? (checked/unchecked)
255 bool m_enabled;
256
257 /// Is this option active? (i.e. sensitive to user input)
258 bool m_active;
259
260 /// The list of children.
261 wxList m_children;
262
263 /// The list of items that are dependent upon
264 // this one. This is refreshed when the configuration
265 // structurally changes, and is not saved to file.
266 wxList m_dependents;
267
268 /// The parent config item
269 ctConfigItem* m_parent;
270
271 DECLARE_CLASS(ctConfigItem)
272 };
273
274 #endif
275 // _CT_CONFIGITEM_H_