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