]> git.saurik.com Git - wxWidgets.git/blob - utils/configtool/src/property.cpp
More details about the internal module name changes
[wxWidgets.git] / utils / configtool / src / property.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: property.cpp
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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
14 #pragma implementation "property.h"
15 #endif
16
17 #include "wx/wx.h"
18
19 #include "property.h"
20
21 IMPLEMENT_CLASS(ctProperty, wxObject)
22 IMPLEMENT_CLASS(ctProperties, wxObject)
23
24 void ctProperties::AddProperty(ctProperty* property, const wxString& insertAfter)
25 {
26 ctProperty* oldProp = FindProperty(property->GetName());
27 if (oldProp)
28 m_list.DeleteObject(oldProp);
29
30 wxNode* insertBeforeNode = NULL;
31 if (insertAfter)
32 {
33 ctProperty* insertAfterProp = FindProperty(insertAfter);
34 if (insertAfterProp)
35 {
36 wxNode* node = m_list.Member(insertAfterProp);
37 if (node)
38 insertBeforeNode = node->GetNext();
39 }
40 }
41 if (insertBeforeNode)
42 m_list.Insert(insertBeforeNode, property);
43 else
44 m_list.Append(property);
45
46 if (oldProp)
47 {
48 property->GetVariant() = oldProp->GetVariant();
49
50 delete oldProp;
51 }
52 }
53
54 void ctProperties::RemoveProperty(ctProperty* property)
55 {
56 m_list.DeleteObject(property);
57 }
58
59 void ctProperties::DeleteProperty(const wxString& name)
60 {
61 ctProperty* prop = FindProperty(name);
62 if (prop)
63 {
64 m_list.DeleteObject(prop);
65 delete prop;
66 }
67 }
68
69 ctProperty* ctProperties::FindProperty(const wxString& name) const
70 {
71 wxNode* node = m_list.GetFirst();
72 while (node)
73 {
74 ctProperty* prop = (ctProperty*) node->GetData();
75 if (prop->GetName() == name)
76 return prop;
77
78 node = node->GetNext();
79 }
80 return (ctProperty*) NULL;
81 }
82
83 wxVariant ctProperties::FindPropertyValue(const wxString& name) const
84 {
85 ctProperty* prop = FindProperty(name);
86 if (prop)
87 return prop->m_variant;
88 else
89 return wxEmptyString;
90 }
91
92 wxString ctProperties::FindPropertyValueString(const wxString& name) const
93 {
94 ctProperty* prop = FindProperty(name);
95 if (prop)
96 return prop->m_variant.GetString();
97 else
98 return wxEmptyString;
99 }
100
101 ctProperty* ctProperties::FindOrCreateProperty(const wxString& name)
102 {
103 ctProperty* prop = FindProperty(name);
104 if (!prop)
105 {
106 prop = new ctProperty(name);
107 AddProperty(prop);
108 }
109 return prop;
110 }
111
112 void ctProperties::Clear()
113 {
114 m_list.DeleteContents(TRUE);
115 m_list.Clear();
116 m_list.DeleteContents(FALSE);
117 }
118
119 void ctProperties::Copy(const ctProperties& properties)
120 {
121 wxNode* node = properties.m_list.GetFirst();
122 while (node)
123 {
124 ctProperty* prop = (ctProperty*) node->GetData();
125
126 AddProperty(new ctProperty(* prop));
127
128 node = node->GetNext();
129 }
130 }
131
132 void ctProperties::SetProperty(const wxString& name, const wxString& value)
133 {
134 ctProperty* prop = FindOrCreateProperty(name);
135 prop->SetValue(value);
136 }
137
138 void ctProperties::SetProperty(const wxString& name, long value)
139 {
140 ctProperty* prop = FindOrCreateProperty(name);
141 prop->GetVariant() = value;
142 }
143
144 void ctProperties::SetProperty(const wxString& name, bool value)
145 {
146 ctProperty* prop = FindOrCreateProperty(name);
147 prop->GetVariant() = (bool) value;
148 }
149
150 void ctProperties::SetProperty(const wxString& name, const wxVariant& value)
151 {
152 ctProperty* prop = FindOrCreateProperty(name);
153 prop->SetValue(value);
154 }
155
156 ctProperty* ctProperties::GetNth(int i) const
157 {
158 wxASSERT( i < (int) GetCount() );
159 if (i < (int) GetCount())
160 {
161 wxNode* node = m_list.Item(i);
162 return (ctProperty*) node->GetData();
163 }
164 return NULL;
165 }
166
167 #if 0
168 /// Combine the styles of all selected properties
169 /// with this group name.
170 long ctProperties::CombineStyles(const wxString& groupName)
171 {
172 long styleValue = 0;
173
174 wxNode* node = m_list.GetFirst();
175 while (node)
176 {
177 ctProperty* prop = (ctProperty*) node->GetData();
178
179 if (prop->GetGroupName() == groupName && prop->GetVariant().GetBool())
180 {
181 styleValue |= prop->GetStyleValue();
182 }
183
184 node = node->GetNext();
185 }
186 return styleValue;
187 }
188
189 /// Combine the styles of all selected properties
190 /// with this group name.
191 wxString ctProperties::CombineStylesString(const wxString& groupName)
192 {
193 wxString styleList;
194
195 wxNode* node = m_list.GetFirst();
196 while (node)
197 {
198 ctProperty* prop = (ctProperty*) node->GetData();
199
200 if (prop->GetGroupName() == groupName && prop->GetVariant().GetBool())
201 {
202 if (styleList.IsEmpty())
203 styleList = prop->GetName();
204 else
205 styleList = styleList + _T("|") + prop->GetName();
206 }
207
208 node = node->GetNext();
209 }
210 return styleList;
211 }
212
213 // Remove any spurious properties that need garbage
214 // collecting.
215 void ctProperties::RemoveHiddenProperties()
216 {
217 wxNode* node = m_list.GetFirst();
218 while (node)
219 {
220 ctProperty* prop = (ctProperty*) node->GetData();
221 wxNode* next = node->GetNext();
222
223 if (!prop->IsShown())
224 {
225 delete node;
226 delete prop;
227 }
228
229 node = next;
230 }
231 }
232 #endif