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"
17 // For compilers that support precompilation, includes "wx/wx.h".
18 #include "wx/wxprec.h"
26 IMPLEMENT_CLASS(ctProperty
, wxObject
)
27 IMPLEMENT_CLASS(ctProperties
, wxObject
)
29 void ctProperties::AddProperty(ctProperty
* property
, const wxString
& insertAfter
)
31 ctProperty
* oldProp
= FindProperty(property
->GetName());
33 m_list
.DeleteObject(oldProp
);
37 ctProperty
* insertAfterProp
= FindProperty(insertAfter
);
40 wxObjectList::compatibility_iterator node
= m_list
.Member(insertAfterProp
);
43 wxObjectList::compatibility_iterator insertBeforeNode
= node
->GetNext();
44 m_list
.Insert(insertBeforeNode
, property
);
47 m_list
.Append(property
);
50 m_list
.Append(property
);
53 m_list
.Append(property
);
57 property
->GetVariant() = oldProp
->GetVariant();
63 void ctProperties::RemoveProperty(ctProperty
* property
)
65 m_list
.DeleteObject(property
);
68 void ctProperties::DeleteProperty(const wxString
& name
)
70 ctProperty
* prop
= FindProperty(name
);
73 m_list
.DeleteObject(prop
);
78 ctProperty
* ctProperties::FindProperty(const wxString
& name
) const
80 wxObjectList::compatibility_iterator node
= m_list
.GetFirst();
83 ctProperty
* prop
= (ctProperty
*) node
->GetData();
84 if (prop
->GetName() == name
)
87 node
= node
->GetNext();
89 return (ctProperty
*) NULL
;
92 wxVariant
ctProperties::FindPropertyValue(const wxString
& name
) const
94 ctProperty
* prop
= FindProperty(name
);
96 return prop
->m_variant
;
101 wxString
ctProperties::FindPropertyValueString(const wxString
& name
) const
103 ctProperty
* prop
= FindProperty(name
);
105 return prop
->m_variant
.GetString();
107 return wxEmptyString
;
110 ctProperty
* ctProperties::FindOrCreateProperty(const wxString
& name
)
112 ctProperty
* prop
= FindProperty(name
);
115 prop
= new ctProperty(name
);
121 void ctProperties::Clear()
123 WX_CLEAR_LIST(wxObjectList
,m_list
);
126 void ctProperties::Copy(const ctProperties
& properties
)
128 wxObjectList::compatibility_iterator node
= properties
.m_list
.GetFirst();
131 ctProperty
* prop
= (ctProperty
*) node
->GetData();
133 AddProperty(new ctProperty(* prop
));
135 node
= node
->GetNext();
139 void ctProperties::SetProperty(const wxString
& name
, const wxString
& value
)
141 ctProperty
* prop
= FindOrCreateProperty(name
);
142 prop
->SetValue(value
);
145 void ctProperties::SetProperty(const wxString
& name
, long value
)
147 ctProperty
* prop
= FindOrCreateProperty(name
);
148 prop
->GetVariant() = value
;
151 void ctProperties::SetProperty(const wxString
& name
, bool value
)
153 ctProperty
* prop
= FindOrCreateProperty(name
);
154 prop
->GetVariant() = value
;
157 void ctProperties::SetProperty(const wxString
& name
, const wxVariant
& value
)
159 ctProperty
* prop
= FindOrCreateProperty(name
);
160 prop
->SetValue(value
);
163 ctProperty
* ctProperties::GetNth(int i
) const
165 wxASSERT( i
< (int) GetCount() );
166 if (i
< (int) GetCount())
168 wxObjectList::compatibility_iterator node
= m_list
.Item(i
);
169 return (ctProperty
*) node
->GetData();
175 /// Combine the styles of all selected properties
176 /// with this group name.
177 long ctProperties::CombineStyles(const wxString
& groupName
)
181 wxNode
* node
= m_list
.GetFirst();
184 ctProperty
* prop
= (ctProperty
*) node
->GetData();
186 if (prop
->GetGroupName() == groupName
&& prop
->GetVariant().GetBool())
188 styleValue
|= prop
->GetStyleValue();
191 node
= node
->GetNext();
196 /// Combine the styles of all selected properties
197 /// with this group name.
198 wxString
ctProperties::CombineStylesString(const wxString
& groupName
)
202 wxNode
* node
= m_list
.GetFirst();
205 ctProperty
* prop
= (ctProperty
*) node
->GetData();
207 if (prop
->GetGroupName() == groupName
&& prop
->GetVariant().GetBool())
209 if (styleList
.IsEmpty())
210 styleList
= prop
->GetName();
212 styleList
= styleList
+ _T("|") + prop
->GetName();
215 node
= node
->GetNext();
220 // Remove any spurious properties that need garbage
222 void ctProperties::RemoveHiddenProperties()
224 wxNode
* node
= m_list
.GetFirst();
227 ctProperty
* prop
= (ctProperty
*) node
->GetData();
228 wxNode
* next
= node
->GetNext();
230 if (!prop
->IsShown())