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_
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "configitem.cpp"
20 #include "wx/treectrl.h"
24 class ctConfigToolDoc
;
27 * The type of config item
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
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.
50 class ctConfigItem
: public wxObject
54 ctConfigItem(ctConfigItem
* parent
, ctConfigType type
, const wxString
& name
);
59 ctConfigItem(const ctConfigItem
& item
)
66 /// Assignment operator.
67 void operator= (const ctConfigItem
& item
);
72 ctConfigItem
* item
= new ctConfigItem
;
77 /// Create a clone of this and children
78 ctConfigItem
* DeepClone();
80 /// Do additional actions to apply the property to the internal
82 void ApplyProperty(ctProperty
* prop
, const wxVariant
& oldValue
);
88 void AddChild(ctConfigItem
* item
);
90 /// Remove (but don't delete) a child
91 void RemoveChild(ctConfigItem
* item
);
93 /// Initialise standard properties
94 void InitProperties();
96 /// Convert string containing config item names to
97 /// an array of config item names
98 static void StringToArray(const wxString
& items
, wxArrayString
& itemsArray
);
100 /// Convert array containing config item names to
102 static void ArrayToString(const wxArrayString
& itemsArray
, wxString
& items
);
104 /// Populate a list of items found in the string.
105 static void StringToItems(ctConfigItem
* topItem
, const wxString
& items
, wxList
& list
);
107 /// Find an item in this hierarchy
108 ctConfigItem
* FindItem(const wxString
& name
);
110 /// Find the next sibling
111 ctConfigItem
* FindNextSibling();
113 /// Find the previous sibling
114 ctConfigItem
* FindPreviousSibling();
119 /// Detach: remove from parent, and remove tree items
122 /// Attach: insert before the given position
123 void Attach(ctConfigItem
* parent
, ctConfigItem
* insertbefore
);
125 /// Hide from tree: make sure tree deletions won't delete
127 void DetachFromTree();
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();
134 /// Propagate a change in enabled/disabled status
135 void PropagateChange(wxList
& considered
);
137 /// Process radio button selection
138 void PropagateRadioButton(wxList
& considered
);
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();
147 /// Returns the name property.
148 wxString
GetName() const { return GetPropertyString(wxT("name")); }
150 /// Sets the name property.
151 void SetName(const wxString
& name
) ;
153 /// Returns the value property.
154 wxVariant
GetValue() const { return m_properties
.FindPropertyValue(wxT("value")); }
156 /// Sets the value property.
157 void SetValue(const wxVariant
& value
) ;
159 /// Returns the string for the given property.
160 wxString
GetPropertyString(const wxString
& propName
) const { return m_properties
.FindPropertyValueString(propName
); }
162 /// Sets the string for the given property.
163 void SetPropertyString(const wxString
& propName
, const wxString
& value
) { m_properties
.SetProperty(propName
, value
); }
165 /// Can we edit this property?
166 bool CanEditProperty(const wxString
& propName
) const ;
168 /// Returns the list of properties for
170 ctProperties
& GetProperties() { return m_properties
; }
172 /// Set the default property.
173 void SetDefaultProperty(const wxString
& defaultProp
) { m_defaultProperty
= defaultProp
; }
175 /// Get the default property.
176 wxString
GetDefaultProperty() const { return m_defaultProperty
; }
178 /// Is this item modified?
179 bool IsModified() const { return m_modified
; }
181 /// Mark this as modified.
182 void Modify(bool modified
= true) { m_modified
= modified
; }
184 /// Is this item enabled? (checked/unchecked)
185 bool IsEnabled() const { return m_enabled
; }
187 /// Enable or disable (check/uncheck)
188 void Enable(bool enable
= true) { m_enabled
= enable
; }
190 /// Is this item active? (sensitive to user input)
191 bool IsActive() const { return m_active
; }
193 /// Make this (in)active
194 void SetActive(bool active
= true) { m_active
= active
; }
197 void SetType(ctConfigType type
) { m_type
= type
; }
200 ctConfigType
GetType() const { return m_type
; }
202 /// Set the tree item id
203 void SetTreeItem(wxTreeItemId id
) { m_treeItemId
= id
; }
206 wxTreeItemId
GetTreeItemId() const { return m_treeItemId
; }
208 /// Get the list of children
209 wxList
& GetChildren() { return m_children
; }
211 /// Get the nth child
212 ctConfigItem
* GetChild(int n
) const;
214 /// Get the child count
215 int GetChildCount() const;
217 /// Get the list of dependents
218 wxList
& GetDependents() { return m_dependents
; }
221 ctConfigItem
* GetParent() const { return m_parent
; }
224 void SetParent(ctConfigItem
* parent
) { m_parent
= parent
; }
226 /// Get the associated document (currently, assumes
227 /// there's only ever one document active)
228 ctConfigToolDoc
* GetDocument() ;
230 /// Can have children?
231 bool CanHaveChildren() const;
233 /// Get description, which may be dynamically
234 /// generated depending on the property.
235 wxString
GetDescription(ctProperty
* property
);
237 /// Get the title for the property editor
242 /// The properties for this item.
243 ctProperties m_properties
;
245 /// The default property, from the point of
246 /// of double-clicking the config item.
247 wxString m_defaultProperty
;
252 /// The type of the config item
255 /// The corresponding tree item
256 wxTreeItemId m_treeItemId
;
258 /// Is this option enabled? (checked/unchecked)
261 /// Is this option active? (i.e. sensitive to user input)
264 /// The list of children.
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.
272 /// The parent config item
273 ctConfigItem
* m_parent
;
275 DECLARE_CLASS(ctConfigItem
)