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 // For compilers that support precompilation, includes "wx/wx.h".
14 #include "wx/wxprec.h"
22 IMPLEMENT_CLASS(ctProperty
, wxObject
)
23 IMPLEMENT_CLASS(ctProperties
, wxObject
)
25 void ctProperties::AddProperty(ctProperty
* property
, const wxString
& insertAfter
)
27 ctProperty
* oldProp
= FindProperty(property
->GetName());
29 m_list
.DeleteObject(oldProp
);
33 ctProperty
* insertAfterProp
= FindProperty(insertAfter
);
36 wxObjectList::compatibility_iterator node
= m_list
.Member(insertAfterProp
);
39 wxObjectList::compatibility_iterator insertBeforeNode
= node
->GetNext();
40 m_list
.Insert(insertBeforeNode
, property
);
43 m_list
.Append(property
);
46 m_list
.Append(property
);
49 m_list
.Append(property
);
53 property
->GetVariant() = oldProp
->GetVariant();
59 void ctProperties::RemoveProperty(ctProperty
* property
)
61 m_list
.DeleteObject(property
);
64 void ctProperties::DeleteProperty(const wxString
& name
)
66 ctProperty
* prop
= FindProperty(name
);
69 m_list
.DeleteObject(prop
);
74 ctProperty
* ctProperties::FindProperty(const wxString
& name
) const
76 wxObjectList::compatibility_iterator node
= m_list
.GetFirst();
79 ctProperty
* prop
= (ctProperty
*) node
->GetData();
80 if (prop
->GetName() == name
)
83 node
= node
->GetNext();
85 return (ctProperty
*) NULL
;
88 wxVariant
ctProperties::FindPropertyValue(const wxString
& name
) const
90 ctProperty
* prop
= FindProperty(name
);
92 return prop
->m_variant
;
97 wxString
ctProperties::FindPropertyValueString(const wxString
& name
) const
99 ctProperty
* prop
= FindProperty(name
);
101 return prop
->m_variant
.GetString();
103 return wxEmptyString
;
106 ctProperty
* ctProperties::FindOrCreateProperty(const wxString
& name
)
108 ctProperty
* prop
= FindProperty(name
);
111 prop
= new ctProperty(name
);
117 void ctProperties::Clear()
119 WX_CLEAR_LIST(wxObjectList
,m_list
);
122 void ctProperties::Copy(const ctProperties
& properties
)
124 wxObjectList::compatibility_iterator node
= properties
.m_list
.GetFirst();
127 ctProperty
* prop
= (ctProperty
*) node
->GetData();
129 AddProperty(new ctProperty(* prop
));
131 node
= node
->GetNext();
135 void ctProperties::SetProperty(const wxString
& name
, const wxString
& value
)
137 ctProperty
* prop
= FindOrCreateProperty(name
);
138 prop
->SetValue(value
);
141 void ctProperties::SetProperty(const wxString
& name
, long value
)
143 ctProperty
* prop
= FindOrCreateProperty(name
);
144 prop
->GetVariant() = value
;
147 void ctProperties::SetProperty(const wxString
& name
, bool value
)
149 ctProperty
* prop
= FindOrCreateProperty(name
);
150 prop
->GetVariant() = value
;
153 void ctProperties::SetProperty(const wxString
& name
, const wxVariant
& value
)
155 ctProperty
* prop
= FindOrCreateProperty(name
);
156 prop
->SetValue(value
);
159 ctProperty
* ctProperties::GetNth(int i
) const
161 wxASSERT( i
< (int) GetCount() );
162 if (i
< (int) GetCount())
164 wxObjectList::compatibility_iterator node
= m_list
.Item(i
);
165 return (ctProperty
*) node
->GetData();
171 /// Combine the styles of all selected properties
172 /// with this group name.
173 long ctProperties::CombineStyles(const wxString
& groupName
)
177 wxNode
* node
= m_list
.GetFirst();
180 ctProperty
* prop
= (ctProperty
*) node
->GetData();
182 if (prop
->GetGroupName() == groupName
&& prop
->GetVariant().GetBool())
184 styleValue
|= prop
->GetStyleValue();
187 node
= node
->GetNext();
192 /// Combine the styles of all selected properties
193 /// with this group name.
194 wxString
ctProperties::CombineStylesString(const wxString
& groupName
)
198 wxNode
* node
= m_list
.GetFirst();
201 ctProperty
* prop
= (ctProperty
*) node
->GetData();
203 if (prop
->GetGroupName() == groupName
&& prop
->GetVariant().GetBool())
205 if (styleList
.IsEmpty())
206 styleList
= prop
->GetName();
208 styleList
= styleList
+ _T("|") + prop
->GetName();
211 node
= node
->GetNext();
216 // Remove any spurious properties that need garbage
218 void ctProperties::RemoveHiddenProperties()
220 wxNode
* node
= m_list
.GetFirst();
223 ctProperty
* prop
= (ctProperty
*) node
->GetData();
224 wxNode
* next
= node
->GetNext();
226 if (!prop
->IsShown())