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