fixed shutdown crashes after recent handlers creation changes
[wxWidgets.git] / utils / configtool / src / property.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: property.h
3 // Purpose: ctProperty objects represent name/value pairs,
4 // for properties of a configuration item.
5 // Author: Julian Smart
6 // Modified by:
7 // Created: 2003-06-03
8 // RCS-ID: $Id$
9 // Copyright: (c) Julian Smart
10 // Licence:
11 /////////////////////////////////////////////////////////////////////////////
12
13 #ifndef _CT_PROPERTY_H_
14 #define _CT_PROPERTY_H_
15
16 #include "wx/variant.h"
17
18 /*!
19 * A property/name pair, with other specialised members for
20 * storing window/sizer information.
21 */
22
23 class ctProperty: public wxObject
24 {
25 DECLARE_CLASS(ctProperty)
26 public:
27 ctProperty()
28 {
29 m_readOnly = false;
30 m_custom = false;
31 m_show = true;
32 }
33 ctProperty(const ctProperty& property) : wxObject() { Copy(property); }
34 ctProperty(const wxString& descr, const wxVariant& variant,
35 const wxString& editorType = wxEmptyString,
36 bool readOnly = false)
37 {
38 m_description = descr;
39 m_variant = variant;
40 m_editorType = editorType;
41 m_show = true;
42 m_readOnly = readOnly;
43 m_custom = false;
44 }
45
46 ctProperty(const wxString& name, const wxString& value = wxEmptyString)
47 {
48 m_variant.SetName(name);
49 m_variant = value;
50 m_readOnly = false;
51 m_custom = false;
52 m_show = true;
53 }
54
55 void operator= (const ctProperty& property) { Copy(property); }
56 void Copy(const ctProperty& property)
57 {
58 m_variant = property.m_variant;
59 m_editorType = property.m_editorType;
60 m_description = property.m_description;
61 m_choices = property.m_choices;
62 m_show = property.m_show;
63 m_readOnly = property.m_readOnly;
64 m_custom = property.m_custom;
65 }
66
67 bool operator== (const ctProperty& property) const
68 {
69 return ((m_variant == property.m_variant) &&
70 (m_editorType == property.m_editorType) &&
71 (m_description == property.m_description) &&
72 (m_show == property.m_show) &&
73 (m_custom == property.m_custom) &&
74 (m_readOnly == property.m_readOnly) &&
75 (m_choices == property.m_choices));
76 }
77
78 bool operator!= (const ctProperty& property) const
79 {
80 return !((*this) == property);
81 }
82
83 inline const wxString& GetName() const { return m_variant.GetName(); }
84 inline wxString GetValue() const { return m_variant.GetString(); }
85 inline wxVariant& GetVariant() { return m_variant; }
86 inline const wxString& GetEditorType() const { return m_editorType; }
87 inline const wxArrayString& GetChoices() const { return m_choices; }
88 inline const wxString& GetDescription() const { return m_description; }
89 inline bool IsCustom() const { return m_custom; }
90
91 inline void SetName(const wxString& name) { m_variant.SetName(name); }
92 inline void SetValue(const wxString& value) { m_variant = value; }
93 inline void SetValue(const wxVariant& value) { m_variant = value; }
94 inline void SetEditorType(const wxString& type) { m_editorType = type; }
95 inline void SetChoices(const wxArrayString& choices) { m_choices = choices; }
96 inline void SetDescription(const wxString& descr) { m_description = descr; }
97 inline void Show(bool show) { m_show = show; }
98 inline bool IsShown() const { return m_show; }
99 inline bool GetReadOnly() const { return m_readOnly; }
100 inline void SetReadOnly(bool readOnly) { m_readOnly = readOnly; }
101 inline void SetCustom(bool custom) { m_custom = custom; }
102
103 // The name and value
104 wxVariant m_variant;
105
106 // The editor type name (e.g. "file")
107 // used to choose an editor.
108 wxString m_editorType;
109
110 // Array of choices
111 wxArrayString m_choices;
112
113 // Description
114 wxString m_description;
115
116 // Whether to show or hide (e.g. not properly initialized)
117 bool m_show;
118
119 // Read-only
120 bool m_readOnly;
121
122 // Whether it's a custom property (so save
123 // type/description)
124 bool m_custom;
125 };
126
127 // A class to manage properties
128 class ctProperties: public wxObject
129 {
130 DECLARE_CLASS(ctProperties)
131 public:
132 ctProperties() {}
133 ctProperties(const ctProperties& properties) : wxObject() { Copy(properties); }
134 virtual ~ctProperties() { Clear(); }
135
136 void operator = (const ctProperties& properties) { Clear(); Copy(properties); }
137 void Copy(const ctProperties& properties);
138
139 inline const wxList& GetList() const { return m_list; }
140
141 inline size_t GetCount() const { return m_list.GetCount(); }
142
143 void AddProperty(ctProperty* property, const wxString& insertAfter = wxEmptyString);
144 void SetProperty(const wxString& name, const wxString& value);
145 void SetProperty(const wxString& name, long value);
146 void SetProperty(const wxString& name, bool value);
147 void SetProperty(const wxString& name, const wxVariant& value);
148 void RemoveProperty(ctProperty* property);
149 void DeleteProperty(const wxString& name);
150 ctProperty* FindProperty(const wxString& name) const;
151 ctProperty* FindOrCreateProperty(const wxString& name);
152 wxString FindPropertyValueString(const wxString& name) const;
153 wxVariant FindPropertyValue(const wxString& name) const;
154 ctProperty* GetNth(int i) const;
155
156 void Clear();
157
158 private:
159 wxList m_list;
160 };
161
162 #endif
163 // _CT_PROPERTY_H_
164