]> git.saurik.com Git - wxWidgets.git/blame - utils/configtool/src/property.cpp
blind compilation fix for daily builds error
[wxWidgets.git] / utils / configtool / src / property.cpp
CommitLineData
d7463f75
JS
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
4fe30bce 10// Licence:
d7463f75
JS
11/////////////////////////////////////////////////////////////////////////////
12
d9ab621e
WS
13// For compilers that support precompilation, includes "wx/wx.h".
14#include "wx/wxprec.h"
15
16#ifdef __BORLANDC__
17#pragma hdrstop
18#endif
d7463f75
JS
19
20#include "property.h"
21
22IMPLEMENT_CLASS(ctProperty, wxObject)
23IMPLEMENT_CLASS(ctProperties, wxObject)
24
25void ctProperties::AddProperty(ctProperty* property, const wxString& insertAfter)
26{
27 ctProperty* oldProp = FindProperty(property->GetName());
28 if (oldProp)
29 m_list.DeleteObject(oldProp);
30
d7463f75
JS
31 if (insertAfter)
32 {
33 ctProperty* insertAfterProp = FindProperty(insertAfter);
34 if (insertAfterProp)
35 {
d9ab621e 36 wxObjectList::compatibility_iterator node = m_list.Member(insertAfterProp);
d7463f75 37 if (node)
d9ab621e
WS
38 {
39 wxObjectList::compatibility_iterator insertBeforeNode = node->GetNext();
40 m_list.Insert(insertBeforeNode, property);
41 }
42 else
43 m_list.Append(property);
d7463f75 44 }
d9ab621e
WS
45 else
46 m_list.Append(property);
d7463f75 47 }
d7463f75
JS
48 else
49 m_list.Append(property);
50
51 if (oldProp)
52 {
53 property->GetVariant() = oldProp->GetVariant();
54
55 delete oldProp;
56 }
57}
58
59void ctProperties::RemoveProperty(ctProperty* property)
60{
61 m_list.DeleteObject(property);
62}
63
64void 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
74ctProperty* ctProperties::FindProperty(const wxString& name) const
75{
d9ab621e 76 wxObjectList::compatibility_iterator node = m_list.GetFirst();
d7463f75
JS
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
88wxVariant 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
97wxString 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
106ctProperty* 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
117void ctProperties::Clear()
118{
d9ab621e 119 WX_CLEAR_LIST(wxObjectList,m_list);
d7463f75
JS
120}
121
122void ctProperties::Copy(const ctProperties& properties)
123{
d9ab621e 124 wxObjectList::compatibility_iterator node = properties.m_list.GetFirst();
d7463f75
JS
125 while (node)
126 {
127 ctProperty* prop = (ctProperty*) node->GetData();
128
129 AddProperty(new ctProperty(* prop));
130
131 node = node->GetNext();
132 }
133}
134
135void ctProperties::SetProperty(const wxString& name, const wxString& value)
136{
137 ctProperty* prop = FindOrCreateProperty(name);
138 prop->SetValue(value);
139}
140
141void ctProperties::SetProperty(const wxString& name, long value)
142{
143 ctProperty* prop = FindOrCreateProperty(name);
144 prop->GetVariant() = value;
145}
146
147void ctProperties::SetProperty(const wxString& name, bool value)
148{
149 ctProperty* prop = FindOrCreateProperty(name);
4fe30bce 150 prop->GetVariant() = value;
d7463f75
JS
151}
152
153void ctProperties::SetProperty(const wxString& name, const wxVariant& value)
154{
155 ctProperty* prop = FindOrCreateProperty(name);
156 prop->SetValue(value);
157}
158
159ctProperty* ctProperties::GetNth(int i) const
160{
161 wxASSERT( i < (int) GetCount() );
162 if (i < (int) GetCount())
163 {
d9ab621e 164 wxObjectList::compatibility_iterator node = m_list.Item(i);
d7463f75
JS
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.
173long 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.
194wxString 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.
218void 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}
f8105809 235#endif