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