]>
Commit | Line | Data |
---|---|---|
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 | // For compilers that support precompilation, includes "wx/wx.h". | |
18 | #include "wx/wxprec.h" | |
19 | ||
20 | #ifdef __BORLANDC__ | |
21 | #pragma hdrstop | |
22 | #endif | |
23 | ||
24 | #include "property.h" | |
25 | ||
26 | IMPLEMENT_CLASS(ctProperty, wxObject) | |
27 | IMPLEMENT_CLASS(ctProperties, wxObject) | |
28 | ||
29 | void ctProperties::AddProperty(ctProperty* property, const wxString& insertAfter) | |
30 | { | |
31 | ctProperty* oldProp = FindProperty(property->GetName()); | |
32 | if (oldProp) | |
33 | m_list.DeleteObject(oldProp); | |
34 | ||
35 | if (insertAfter) | |
36 | { | |
37 | ctProperty* insertAfterProp = FindProperty(insertAfter); | |
38 | if (insertAfterProp) | |
39 | { | |
40 | wxObjectList::compatibility_iterator node = m_list.Member(insertAfterProp); | |
41 | if (node) | |
42 | { | |
43 | wxObjectList::compatibility_iterator insertBeforeNode = node->GetNext(); | |
44 | m_list.Insert(insertBeforeNode, property); | |
45 | } | |
46 | else | |
47 | m_list.Append(property); | |
48 | } | |
49 | else | |
50 | m_list.Append(property); | |
51 | } | |
52 | else | |
53 | m_list.Append(property); | |
54 | ||
55 | if (oldProp) | |
56 | { | |
57 | property->GetVariant() = oldProp->GetVariant(); | |
58 | ||
59 | delete oldProp; | |
60 | } | |
61 | } | |
62 | ||
63 | void ctProperties::RemoveProperty(ctProperty* property) | |
64 | { | |
65 | m_list.DeleteObject(property); | |
66 | } | |
67 | ||
68 | void 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 | ||
78 | ctProperty* ctProperties::FindProperty(const wxString& name) const | |
79 | { | |
80 | wxObjectList::compatibility_iterator node = m_list.GetFirst(); | |
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 | ||
92 | wxVariant 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 | ||
101 | wxString 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 | ||
110 | ctProperty* 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 | ||
121 | void ctProperties::Clear() | |
122 | { | |
123 | WX_CLEAR_LIST(wxObjectList,m_list); | |
124 | } | |
125 | ||
126 | void ctProperties::Copy(const ctProperties& properties) | |
127 | { | |
128 | wxObjectList::compatibility_iterator node = properties.m_list.GetFirst(); | |
129 | while (node) | |
130 | { | |
131 | ctProperty* prop = (ctProperty*) node->GetData(); | |
132 | ||
133 | AddProperty(new ctProperty(* prop)); | |
134 | ||
135 | node = node->GetNext(); | |
136 | } | |
137 | } | |
138 | ||
139 | void ctProperties::SetProperty(const wxString& name, const wxString& value) | |
140 | { | |
141 | ctProperty* prop = FindOrCreateProperty(name); | |
142 | prop->SetValue(value); | |
143 | } | |
144 | ||
145 | void ctProperties::SetProperty(const wxString& name, long value) | |
146 | { | |
147 | ctProperty* prop = FindOrCreateProperty(name); | |
148 | prop->GetVariant() = value; | |
149 | } | |
150 | ||
151 | void ctProperties::SetProperty(const wxString& name, bool value) | |
152 | { | |
153 | ctProperty* prop = FindOrCreateProperty(name); | |
154 | prop->GetVariant() = value; | |
155 | } | |
156 | ||
157 | void ctProperties::SetProperty(const wxString& name, const wxVariant& value) | |
158 | { | |
159 | ctProperty* prop = FindOrCreateProperty(name); | |
160 | prop->SetValue(value); | |
161 | } | |
162 | ||
163 | ctProperty* ctProperties::GetNth(int i) const | |
164 | { | |
165 | wxASSERT( i < (int) GetCount() ); | |
166 | if (i < (int) GetCount()) | |
167 | { | |
168 | wxObjectList::compatibility_iterator node = m_list.Item(i); | |
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. | |
177 | long 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. | |
198 | wxString 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. | |
222 | void 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 | } | |
239 | #endif |