1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Property sheet classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 #include "wx/deprecated/setup.h"
20 #include "wx/string.h"
22 #include "wx/dialog.h"
24 #include "wx/button.h"
25 #include "wx/listbox.h"
26 #include "wx/textctrl.h"
27 #include "wx/gdicmn.h"
28 #include "wx/layout.h"
33 class wxPropertyValue
;
34 class wxPropertySheet
;
36 class wxPropertyValidator
;
37 class wxPropertyValidatorRegistry
;
39 #define wxPROPERTY_VERSION 2.0
41 // A storable sheet of values
42 class WXDLLIMPEXP_DEPRECATED wxPropertySheet
: public wxObject
45 wxPropertySheet(const wxString
& name
= wxT(""));
48 // Set the name of the sheet
49 inline virtual void SetName(const wxString
& name
) { m_name
=name
; }
50 inline virtual wxString
GetName() const { return m_name
; }
52 // Does this sheet contain a property with this name
53 virtual bool HasProperty(const wxString
& name
) const;
55 // Set property name to value
56 virtual bool SetProperty(const wxString
& name
, const wxPropertyValue
& value
);
58 // Remove property from sheet by name, deleting it
59 virtual void RemoveProperty(const wxString
& name
);
61 // Get the name of the sheet
63 virtual void AddProperty(wxProperty
*property
);
65 // Get property by name
66 virtual wxProperty
*GetProperty(const wxString
& name
) const;
68 // Clear all properties
71 virtual void UpdateAllViews(wxPropertyView
*thisView
= NULL
);
72 inline virtual wxList
& GetProperties() const { return (wxList
&) m_properties
; }
74 // Sets/clears the modified flag for each property value
75 virtual void SetAllModified(bool flag
= true);
78 wxObject
* m_viewedObject
;
80 wxPropertyView
* m_propertyView
;
84 DECLARE_DYNAMIC_CLASS(wxPropertySheet
)
88 // Base class for property sheet views. There are currently two directly derived
89 // classes: wxPropertyListView, and wxPropertyFormView.
90 class WXDLLIMPEXP_DEPRECATED wxPropertyView
: public wxEvtHandler
93 wxPropertyView(long flags
= 0);
96 // Associates and shows the view
97 virtual void ShowView(wxPropertySheet
*WXUNUSED(propertySheet
), wxWindow
*WXUNUSED(panel
)) {}
99 // Update this view of the viewed object, called e.g. by
100 // the object itself.
101 virtual bool OnUpdateView() {return false;};
103 // Override this to do something as soon as the property changed,
104 // if the view and validators support it.
105 virtual void OnPropertyChanged(wxProperty
*WXUNUSED(property
)) {}
107 virtual void AddRegistry(wxPropertyValidatorRegistry
*registry
);
108 inline virtual wxList
& GetRegistryList() const
109 { return (wxList
&) m_validatorRegistryList
; }
111 virtual wxPropertyValidator
*FindPropertyValidator(wxProperty
*property
);
112 inline virtual void SetPropertySheet(wxPropertySheet
*sheet
) { m_propertySheet
= sheet
; }
113 inline virtual wxPropertySheet
*GetPropertySheet() const { return m_propertySheet
; }
115 inline virtual bool OnClose() { return false; }
116 inline long GetFlags(void) { return m_buttonFlags
; }
120 wxPropertySheet
* m_propertySheet
;
121 wxProperty
* m_currentProperty
;
122 wxList m_validatorRegistryList
;
123 wxPropertyValidator
* m_currentValidator
;
126 DECLARE_DYNAMIC_CLASS(wxPropertyView
)
130 class WXDLLIMPEXP_DEPRECATED wxPropertyValidator
: public wxEvtHandler
133 wxPropertyValidator(long flags
= 0);
134 ~wxPropertyValidator();
136 inline long GetFlags() const { return m_validatorFlags
; }
137 inline void SetValidatorProperty(wxProperty
*prop
) { m_validatorProperty
= prop
; }
138 inline wxProperty
*GetValidatorProperty(void) const { return m_validatorProperty
; }
140 virtual bool StringToFloat (wxChar
*s
, float *number
);
141 virtual bool StringToDouble (wxChar
*s
, double *number
);
142 virtual bool StringToInt (wxChar
*s
, int *number
);
143 virtual bool StringToLong (wxChar
*s
, long *number
);
144 virtual wxChar
*FloatToString (float number
);
145 virtual wxChar
*DoubleToString (double number
);
146 virtual wxChar
*IntToString (int number
);
147 virtual wxChar
*LongToString (long number
);
150 long m_validatorFlags
;
151 wxProperty
* m_validatorProperty
;
154 DECLARE_DYNAMIC_CLASS(wxPropertyValidator
)
158 // extern wxPropertyValidator *wxDefaultPropertyValidator;
160 class WXDLLIMPEXP_DEPRECATED wxPropertyValidatorRegistry
: public wxHashTable
163 wxPropertyValidatorRegistry();
164 ~wxPropertyValidatorRegistry();
166 virtual void RegisterValidator(const wxString
& roleName
, wxPropertyValidator
*validator
);
167 virtual wxPropertyValidator
*GetValidator(const wxString
& roleName
);
168 void ClearRegistry();
171 DECLARE_DYNAMIC_CLASS(wxPropertyValidatorRegistry
)
175 * Property value class
180 wxPropertyValueInteger
,
183 wxPropertyValueString
,
185 wxPropertyValueIntegerPtr
,
186 wxPropertyValueRealPtr
,
187 wxPropertyValueboolPtr
,
188 wxPropertyValueStringPtr
189 } wxPropertyValueType
;
191 class WXDLLIMPEXP_DEPRECATED wxPropertyValue
: public wxObject
193 DECLARE_DYNAMIC_CLASS(wxPropertyValue
)
195 wxPropertyValue(void); // Unknown type
196 wxPropertyValue(const wxPropertyValue
& copyFrom
); // Copy constructor
197 wxPropertyValue(const wxChar
*val
);
198 wxPropertyValue(const wxString
& val
);
199 wxPropertyValue(long val
);
200 wxPropertyValue(bool val
);
201 wxPropertyValue(float val
);
202 wxPropertyValue(double the_real
);
203 wxPropertyValue(wxList
*val
);
204 wxPropertyValue(wxStringList
*val
);
206 wxPropertyValue(wxChar
**val
);
207 wxPropertyValue(long *val
);
208 wxPropertyValue(bool *val
);
209 wxPropertyValue(float *val
);
211 ~wxPropertyValue(void);
213 virtual inline wxPropertyValueType
Type(void) const { return m_type
; }
214 virtual inline void SetType(wxPropertyValueType typ
) { m_type
= typ
; }
215 virtual long IntegerValue(void) const;
216 virtual float RealValue(void) const;
217 virtual bool BoolValue(void) const;
218 virtual wxChar
*StringValue(void) const;
219 virtual long *IntegerValuePtr(void) const;
220 virtual float *RealValuePtr(void) const;
221 virtual bool *BoolValuePtr(void) const;
222 virtual wxChar
**StringValuePtr(void) const;
224 // Get nth arg of clause (starting from 1)
225 virtual wxPropertyValue
*Arg(wxPropertyValueType type
, int arg
) const;
227 // Return nth argument of a list expression (starting from zero)
228 virtual wxPropertyValue
*Nth(int arg
) const;
229 // Returns the number of elements in a list expression
230 virtual int Number(void) const;
232 virtual wxPropertyValue
*NewCopy(void) const;
233 virtual void Copy(wxPropertyValue
& copyFrom
);
235 virtual void WritePropertyClause(wxString
&stream
); // Write this expression as a top-level clause
236 virtual void WritePropertyType(wxString
&stream
); // Write as any other subexpression
238 // Append an expression to a list
239 virtual void Append(wxPropertyValue
*expr
);
240 // Insert at beginning of list
241 virtual void Insert(wxPropertyValue
*expr
);
243 // Get first expr in list
244 virtual inline wxPropertyValue
*GetFirst(void) const
245 { return ((m_type
== wxPropertyValueList
) ? m_value
.first
: (wxPropertyValue
*)NULL
); }
247 // Get next expr if this is a node in a list
248 virtual inline wxPropertyValue
*GetNext(void) const
251 // Get last expr in list
252 virtual inline wxPropertyValue
*GetLast(void) const
253 { return ((m_type
== wxPropertyValueList
) ? m_last
: (wxPropertyValue
*)NULL
); }
255 // Delete this node from the list
256 virtual void Delete(wxPropertyValue
*node
);
259 virtual void ClearList(void);
261 virtual inline void SetClientData(wxObject
*data
) { m_clientData
= data
; }
262 virtual inline wxObject
*GetClientData(void) { return m_clientData
; }
264 virtual wxString
GetStringRepresentation(void);
266 inline void SetModified(bool flag
= true) { m_modifiedFlag
= flag
; }
267 inline bool GetModified(void) { return m_modifiedFlag
; }
270 void operator=(const wxPropertyValue
& val
);
271 // void operator=(const char *val);
272 void operator=(const wxString
& val
);
273 void operator=(const long val
);
274 void operator=(const bool val
);
275 void operator=(const float val
);
276 void operator=(const wxChar
**val
);
277 void operator=(const long *val
);
278 void operator=(const bool *val
);
279 void operator=(const float *val
);
282 wxObject
* m_clientData
;
283 wxPropertyValueType m_type
;
287 long integer
; // Also doubles as bool
294 wxPropertyValue
*first
; // If is a list expr, points to the first node
297 wxPropertyValue
* m_next
; // If this is a node in a list, points to the next node
298 wxPropertyValue
* m_last
; // If is a list expr, points to the last node
303 * Property class: contains a name and a value.
306 class WXDLLIMPEXP_DEPRECATED wxProperty
: public wxObject
308 DECLARE_DYNAMIC_CLASS(wxProperty
)
312 wxPropertyValue m_value
;
314 wxString m_propertyRole
;
315 wxPropertyValidator
* m_propertyValidator
;
316 wxWindow
* m_propertyWindow
; // Usually a panel item, if anything
319 wxProperty(wxProperty
& copyFrom
);
320 wxProperty(wxString name
, wxString role
, wxPropertyValidator
*ed
= NULL
);
321 wxProperty(wxString name
, const wxPropertyValue
& val
, wxString role
, wxPropertyValidator
*ed
= NULL
);
324 virtual wxPropertyValue
& GetValue(void) const;
325 virtual wxPropertyValidator
*GetValidator(void) const;
326 virtual wxString
& GetName(void) const;
327 virtual wxString
& GetRole(void) const;
328 virtual void SetValue(const wxPropertyValue
& val
);
329 virtual void SetValidator(wxPropertyValidator
*v
);
330 virtual void SetName(wxString
& nm
);
331 virtual void SetRole(wxString
& role
);
332 void operator=(const wxPropertyValue
& val
);
333 virtual inline void SetWindow(wxWindow
*win
) { m_propertyWindow
= win
; }
334 virtual inline wxWindow
*GetWindow(void) const { return m_propertyWindow
; }
336 inline void Enable(bool en
) { m_enabled
= en
; }
337 inline bool IsEnabled(void) const { return m_enabled
; }