]>
git.saurik.com Git - wxWidgets.git/blob - utils/configtool/src/property.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: ctProperty objects represent name/value pairs,
4 // for properties of a configuration item.
5 // Author: Julian Smart
9 // Copyright: (c) Julian Smart
11 /////////////////////////////////////////////////////////////////////////////
13 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
14 #pragma implementation "property.h"
21 IMPLEMENT_CLASS(ctProperty
, wxObject
)
22 IMPLEMENT_CLASS(ctProperties
, wxObject
)
24 void ctProperties::AddProperty(ctProperty
* property
, const wxString
& insertAfter
)
26 ctProperty
* oldProp
= FindProperty(property
->GetName());
28 m_list
.DeleteObject(oldProp
);
30 wxNode
* insertBeforeNode
= NULL
;
33 ctProperty
* insertAfterProp
= FindProperty(insertAfter
);
36 wxNode
* node
= m_list
.Member(insertAfterProp
);
38 insertBeforeNode
= node
->GetNext();
42 m_list
.Insert(insertBeforeNode
, property
);
44 m_list
.Append(property
);
48 property
->GetVariant() = oldProp
->GetVariant();
54 void ctProperties::RemoveProperty(ctProperty
* property
)
56 m_list
.DeleteObject(property
);
59 void ctProperties::DeleteProperty(const wxString
& name
)
61 ctProperty
* prop
= FindProperty(name
);
64 m_list
.DeleteObject(prop
);
69 ctProperty
* ctProperties::FindProperty(const wxString
& name
) const
71 wxNode
* node
= m_list
.GetFirst();
74 ctProperty
* prop
= (ctProperty
*) node
->GetData();
75 if (prop
->GetName() == name
)
78 node
= node
->GetNext();
80 return (ctProperty
*) NULL
;
83 wxVariant
ctProperties::FindPropertyValue(const wxString
& name
) const
85 ctProperty
* prop
= FindProperty(name
);
87 return prop
->m_variant
;
92 wxString
ctProperties::FindPropertyValueString(const wxString
& name
) const
94 ctProperty
* prop
= FindProperty(name
);
96 return prop
->m_variant
.GetString();
101 ctProperty
* ctProperties::FindOrCreateProperty(const wxString
& name
)
103 ctProperty
* prop
= FindProperty(name
);
106 prop
= new ctProperty(name
);
112 void ctProperties::Clear()
114 m_list
.DeleteContents(TRUE
);
116 m_list
.DeleteContents(FALSE
);
119 void ctProperties::Copy(const ctProperties
& properties
)
121 wxNode
* node
= properties
.m_list
.GetFirst();
124 ctProperty
* prop
= (ctProperty
*) node
->GetData();
126 AddProperty(new ctProperty(* prop
));
128 node
= node
->GetNext();
132 void ctProperties::SetProperty(const wxString
& name
, const wxString
& value
)
134 ctProperty
* prop
= FindOrCreateProperty(name
);
135 prop
->SetValue(value
);
138 void ctProperties::SetProperty(const wxString
& name
, long value
)
140 ctProperty
* prop
= FindOrCreateProperty(name
);
141 prop
->GetVariant() = value
;
144 void ctProperties::SetProperty(const wxString
& name
, bool value
)
146 ctProperty
* prop
= FindOrCreateProperty(name
);
147 prop
->GetVariant() = (bool) value
;
150 void ctProperties::SetProperty(const wxString
& name
, const wxVariant
& value
)
152 ctProperty
* prop
= FindOrCreateProperty(name
);
153 prop
->SetValue(value
);
156 ctProperty
* ctProperties::GetNth(int i
) const
158 wxASSERT( i
< (int) GetCount() );
159 if (i
< (int) GetCount())
161 wxNode
* node
= m_list
.Item(i
);
162 return (ctProperty
*) node
->GetData();
168 /// Combine the styles of all selected properties
169 /// with this group name.
170 long ctProperties::CombineStyles(const wxString
& groupName
)
174 wxNode
* node
= m_list
.GetFirst();
177 ctProperty
* prop
= (ctProperty
*) node
->GetData();
179 if (prop
->GetGroupName() == groupName
&& prop
->GetVariant().GetBool())
181 styleValue
|= prop
->GetStyleValue();
184 node
= node
->GetNext();
189 /// Combine the styles of all selected properties
190 /// with this group name.
191 wxString
ctProperties::CombineStylesString(const wxString
& groupName
)
195 wxNode
* node
= m_list
.GetFirst();
198 ctProperty
* prop
= (ctProperty
*) node
->GetData();
200 if (prop
->GetGroupName() == groupName
&& prop
->GetVariant().GetBool())
202 if (styleList
.IsEmpty())
203 styleList
= prop
->GetName();
205 styleList
= styleList
+ _T("|") + prop
->GetName();
208 node
= node
->GetNext();
213 // Remove any spurious properties that need garbage
215 void ctProperties::RemoveHiddenProperties()
217 wxNode
* node
= m_list
.GetFirst();
220 ctProperty
* prop
= (ctProperty
*) node
->GetData();
221 wxNode
* next
= node
->GetNext();
223 if (!prop
->IsShown())