1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWidgets Configuration Tool config item class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _CT_CONFIGITEM_H_
13 #define _CT_CONFIGITEM_H_
16 #include "wx/treectrl.h"
20 class ctConfigToolDoc
;
23 * The type of config item
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
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.
46 class ctConfigItem
: public wxObject
50 ctConfigItem(ctConfigItem
* parent
, ctConfigType type
, const wxString
& name
);
55 ctConfigItem(const ctConfigItem
& item
) : wxObject()
62 /// Assignment operator.
63 void operator= (const ctConfigItem
& item
);
68 ctConfigItem
* item
= new ctConfigItem
;
73 /// Create a clone of this and children
74 ctConfigItem
* DeepClone();
76 /// Do additional actions to apply the property to the internal
78 void ApplyProperty(ctProperty
* prop
, const wxVariant
& oldValue
);
84 void AddChild(ctConfigItem
* item
);
86 /// Remove (but don't delete) a child
87 void RemoveChild(ctConfigItem
* item
);
89 /// Initialise standard properties
90 void InitProperties();
92 /// Convert string containing config item names to
93 /// an array of config item names
94 static void StringToArray(const wxString
& items
, wxArrayString
& itemsArray
);
96 /// Convert array containing config item names to
98 static void ArrayToString(const wxArrayString
& itemsArray
, wxString
& items
);
100 /// Populate a list of items found in the string.
101 static void StringToItems(ctConfigItem
* topItem
, const wxString
& items
, wxList
& list
);
103 /// Find an item in this hierarchy
104 ctConfigItem
* FindItem(const wxString
& name
);
106 /// Find the next sibling
107 ctConfigItem
* FindNextSibling();
109 /// Find the previous sibling
110 ctConfigItem
* FindPreviousSibling();
115 /// Detach: remove from parent, and remove tree items
118 /// Attach: insert before the given position
119 void Attach(ctConfigItem
* parent
, ctConfigItem
* insertbefore
);
121 /// Hide from tree: make sure tree deletions won't delete
123 void DetachFromTree();
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();
130 /// Propagate a change in enabled/disabled status
131 void PropagateChange(wxList
& considered
);
133 /// Process radio button selection
134 void PropagateRadioButton(wxList
& considered
);
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();
143 /// Returns the name property.
144 wxString
GetName() const { return GetPropertyString(wxT("name")); }
146 /// Sets the name property.
147 void SetName(const wxString
& name
) ;
149 /// Returns the value property.
150 wxVariant
GetValue() const { return m_properties
.FindPropertyValue(wxT("value")); }
152 /// Sets the value property.
153 void SetValue(const wxVariant
& value
) ;
155 /// Returns the string for the given property.
156 wxString
GetPropertyString(const wxString
& propName
) const { return m_properties
.FindPropertyValueString(propName
); }
158 /// Sets the string for the given property.
159 void SetPropertyString(const wxString
& propName
, const wxString
& value
) { m_properties
.SetProperty(propName
, value
); }
161 /// Can we edit this property?
162 bool CanEditProperty(const wxString
& propName
) const ;
164 /// Returns the list of properties for
166 ctProperties
& GetProperties() { return m_properties
; }
168 /// Set the default property.
169 void SetDefaultProperty(const wxString
& defaultProp
) { m_defaultProperty
= defaultProp
; }
171 /// Get the default property.
172 wxString
GetDefaultProperty() const { return m_defaultProperty
; }
174 /// Is this item modified?
175 bool IsModified() const { return m_modified
; }
177 /// Mark this as modified.
178 void Modify(bool modified
= true) { m_modified
= modified
; }
180 /// Is this item enabled? (checked/unchecked)
181 bool IsEnabled() const { return m_enabled
; }
183 /// Enable or disable (check/uncheck)
184 void Enable(bool enable
= true) { m_enabled
= enable
; }
186 /// Is this item active? (sensitive to user input)
187 bool IsActive() const { return m_active
; }
189 /// Make this (in)active
190 void SetActive(bool active
= true) { m_active
= active
; }
193 void SetType(ctConfigType type
) { m_type
= type
; }
196 ctConfigType
GetType() const { return m_type
; }
198 /// Set the tree item id
199 void SetTreeItem(wxTreeItemId id
) { m_treeItemId
= id
; }
202 wxTreeItemId
GetTreeItemId() const { return m_treeItemId
; }
204 /// Get the list of children
205 wxList
& GetChildren() { return m_children
; }
207 /// Get the nth child
208 ctConfigItem
* GetChild(int n
) const;
210 /// Get the child count
211 int GetChildCount() const;
213 /// Get the list of dependents
214 wxList
& GetDependents() { return m_dependents
; }
217 ctConfigItem
* GetParent() const { return m_parent
; }
220 void SetParent(ctConfigItem
* parent
) { m_parent
= parent
; }
222 /// Get the associated document (currently, assumes
223 /// there's only ever one document active)
224 ctConfigToolDoc
* GetDocument() ;
226 /// Can have children?
227 bool CanHaveChildren() const;
229 /// Get description, which may be dynamically
230 /// generated depending on the property.
231 wxString
GetDescription(ctProperty
* property
);
233 /// Get the title for the property editor
238 /// The properties for this item.
239 ctProperties m_properties
;
241 /// The default property, from the point of
242 /// of double-clicking the config item.
243 wxString m_defaultProperty
;
248 /// The type of the config item
251 /// The corresponding tree item
252 wxTreeItemId m_treeItemId
;
254 /// Is this option enabled? (checked/unchecked)
257 /// Is this option active? (i.e. sensitive to user input)
260 /// The list of children.
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.
268 /// The parent config item
269 ctConfigItem
* m_parent
;
271 DECLARE_CLASS(ctConfigItem
)