1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Property sheet classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 #if defined(__GNUG__) && !defined(__APPLE__)
16 #pragma interface "prop.h"
19 #include "wx/deprecated/setup.h"
24 #include "wx/string.h"
26 #include "wx/dialog.h"
28 #include "wx/button.h"
29 #include "wx/listbox.h"
30 #include "wx/textctrl.h"
31 #include "wx/gdicmn.h"
32 #include "wx/layout.h"
37 class wxPropertyValue
;
38 class wxPropertySheet
;
40 class wxPropertyValidator
;
41 class wxPropertyValidatorRegistry
;
43 #define wxPROPERTY_VERSION 2.0
45 // A storable sheet of values
46 class WXDLLIMPEXP_DEPRECATED wxPropertySheet
: public wxObject
49 wxPropertySheet(const wxString
& name
= wxT(""));
52 // Set the name of the sheet
53 inline virtual void SetName(const wxString
& name
) { m_name
=name
; }
54 inline virtual wxString
GetName() const { return m_name
; }
56 // Does this sheet contain a property with this name
57 virtual bool HasProperty(const wxString
& name
) const;
59 // Set property name to value
60 virtual bool SetProperty(const wxString
& name
, const wxPropertyValue
& value
);
62 // Remove property from sheet by name, deleting it
63 virtual void RemoveProperty(const wxString
& name
);
65 // Get the name of the sheet
67 virtual void AddProperty(wxProperty
*property
);
69 // Get property by name
70 virtual wxProperty
*GetProperty(const wxString
& name
) const;
72 // Clear all properties
75 virtual void UpdateAllViews(wxPropertyView
*thisView
= NULL
);
76 inline virtual wxList
& GetProperties() const { return (wxList
&) m_properties
; }
78 // Sets/clears the modified flag for each property value
79 virtual void SetAllModified(bool flag
= true);
82 wxObject
* m_viewedObject
;
84 wxPropertyView
* m_propertyView
;
88 DECLARE_DYNAMIC_CLASS(wxPropertySheet
)
92 // Base class for property sheet views. There are currently two directly derived
93 // classes: wxPropertyListView, and wxPropertyFormView.
94 class WXDLLIMPEXP_DEPRECATED wxPropertyView
: public wxEvtHandler
97 wxPropertyView(long flags
= 0);
100 // Associates and shows the view
101 virtual void ShowView(wxPropertySheet
*WXUNUSED(propertySheet
), wxWindow
*WXUNUSED(panel
)) {}
103 // Update this view of the viewed object, called e.g. by
104 // the object itself.
105 virtual bool OnUpdateView() {return false;};
107 // Override this to do something as soon as the property changed,
108 // if the view and validators support it.
109 virtual void OnPropertyChanged(wxProperty
*WXUNUSED(property
)) {}
111 virtual void AddRegistry(wxPropertyValidatorRegistry
*registry
);
112 inline virtual wxList
& GetRegistryList() const
113 { return (wxList
&) m_validatorRegistryList
; }
115 virtual wxPropertyValidator
*FindPropertyValidator(wxProperty
*property
);
116 inline virtual void SetPropertySheet(wxPropertySheet
*sheet
) { m_propertySheet
= sheet
; }
117 inline virtual wxPropertySheet
*GetPropertySheet() const { return m_propertySheet
; }
119 inline virtual bool OnClose() { return false; }
120 inline long GetFlags(void) { return m_buttonFlags
; }
124 wxPropertySheet
* m_propertySheet
;
125 wxProperty
* m_currentProperty
;
126 wxList m_validatorRegistryList
;
127 wxPropertyValidator
* m_currentValidator
;
130 DECLARE_DYNAMIC_CLASS(wxPropertyView
)
134 class WXDLLIMPEXP_DEPRECATED wxPropertyValidator
: public wxEvtHandler
137 wxPropertyValidator(long flags
= 0);
138 ~wxPropertyValidator();
140 inline long GetFlags() const { return m_validatorFlags
; }
141 inline void SetValidatorProperty(wxProperty
*prop
) { m_validatorProperty
= prop
; }
142 inline wxProperty
*GetValidatorProperty(void) const { return m_validatorProperty
; }
144 virtual bool StringToFloat (wxChar
*s
, float *number
);
145 virtual bool StringToDouble (wxChar
*s
, double *number
);
146 virtual bool StringToInt (wxChar
*s
, int *number
);
147 virtual bool StringToLong (wxChar
*s
, long *number
);
148 virtual wxChar
*FloatToString (float number
);
149 virtual wxChar
*DoubleToString (double number
);
150 virtual wxChar
*IntToString (int number
);
151 virtual wxChar
*LongToString (long number
);
154 long m_validatorFlags
;
155 wxProperty
* m_validatorProperty
;
158 DECLARE_DYNAMIC_CLASS(wxPropertyValidator
)
162 // extern wxPropertyValidator *wxDefaultPropertyValidator;
164 class WXDLLIMPEXP_DEPRECATED wxPropertyValidatorRegistry
: public wxHashTable
167 wxPropertyValidatorRegistry();
168 ~wxPropertyValidatorRegistry();
170 virtual void RegisterValidator(const wxString
& roleName
, wxPropertyValidator
*validator
);
171 virtual wxPropertyValidator
*GetValidator(const wxString
& roleName
);
172 void ClearRegistry();
175 DECLARE_DYNAMIC_CLASS(wxPropertyValidatorRegistry
)
179 * Property value class
184 wxPropertyValueInteger
,
187 wxPropertyValueString
,
189 wxPropertyValueIntegerPtr
,
190 wxPropertyValueRealPtr
,
191 wxPropertyValueboolPtr
,
192 wxPropertyValueStringPtr
193 } wxPropertyValueType
;
195 class WXDLLIMPEXP_DEPRECATED wxPropertyValue
: public wxObject
197 DECLARE_DYNAMIC_CLASS(wxPropertyValue
)
199 wxPropertyValue(void); // Unknown type
200 wxPropertyValue(const wxPropertyValue
& copyFrom
); // Copy constructor
201 wxPropertyValue(const wxChar
*val
);
202 wxPropertyValue(const wxString
& val
);
203 wxPropertyValue(long val
);
204 wxPropertyValue(bool val
);
205 wxPropertyValue(float val
);
206 wxPropertyValue(double the_real
);
207 wxPropertyValue(wxList
*val
);
208 wxPropertyValue(wxStringList
*val
);
210 wxPropertyValue(wxChar
**val
);
211 wxPropertyValue(long *val
);
212 wxPropertyValue(bool *val
);
213 wxPropertyValue(float *val
);
215 ~wxPropertyValue(void);
217 virtual inline wxPropertyValueType
Type(void) const { return m_type
; }
218 virtual inline void SetType(wxPropertyValueType typ
) { m_type
= typ
; }
219 virtual long IntegerValue(void) const;
220 virtual float RealValue(void) const;
221 virtual bool BoolValue(void) const;
222 virtual wxChar
*StringValue(void) const;
223 virtual long *IntegerValuePtr(void) const;
224 virtual float *RealValuePtr(void) const;
225 virtual bool *BoolValuePtr(void) const;
226 virtual wxChar
**StringValuePtr(void) const;
228 // Get nth arg of clause (starting from 1)
229 virtual wxPropertyValue
*Arg(wxPropertyValueType type
, int arg
) const;
231 // Return nth argument of a list expression (starting from zero)
232 virtual wxPropertyValue
*Nth(int arg
) const;
233 // Returns the number of elements in a list expression
234 virtual int Number(void) const;
236 virtual wxPropertyValue
*NewCopy(void) const;
237 virtual void Copy(wxPropertyValue
& copyFrom
);
239 virtual void WritePropertyClause(wxString
&stream
); // Write this expression as a top-level clause
240 virtual void WritePropertyType(wxString
&stream
); // Write as any other subexpression
242 // Append an expression to a list
243 virtual void Append(wxPropertyValue
*expr
);
244 // Insert at beginning of list
245 virtual void Insert(wxPropertyValue
*expr
);
247 // Get first expr in list
248 virtual inline wxPropertyValue
*GetFirst(void) const
249 { return ((m_type
== wxPropertyValueList
) ? m_value
.first
: (wxPropertyValue
*)NULL
); }
251 // Get next expr if this is a node in a list
252 virtual inline wxPropertyValue
*GetNext(void) const
255 // Get last expr in list
256 virtual inline wxPropertyValue
*GetLast(void) const
257 { return ((m_type
== wxPropertyValueList
) ? m_last
: (wxPropertyValue
*)NULL
); }
259 // Delete this node from the list
260 virtual void Delete(wxPropertyValue
*node
);
263 virtual void ClearList(void);
265 virtual inline void SetClientData(wxObject
*data
) { m_clientData
= data
; }
266 virtual inline wxObject
*GetClientData(void) { return m_clientData
; }
268 virtual wxString
GetStringRepresentation(void);
270 inline void SetModified(bool flag
= true) { m_modifiedFlag
= flag
; }
271 inline bool GetModified(void) { return m_modifiedFlag
; }
274 void operator=(const wxPropertyValue
& val
);
275 // void operator=(const char *val);
276 void operator=(const wxString
& val
);
277 void operator=(const long val
);
278 void operator=(const bool val
);
279 void operator=(const float val
);
280 void operator=(const wxChar
**val
);
281 void operator=(const long *val
);
282 void operator=(const bool *val
);
283 void operator=(const float *val
);
286 wxObject
* m_clientData
;
287 wxPropertyValueType m_type
;
291 long integer
; // Also doubles as bool
298 wxPropertyValue
*first
; // If is a list expr, points to the first node
301 wxPropertyValue
* m_next
; // If this is a node in a list, points to the next node
302 wxPropertyValue
* m_last
; // If is a list expr, points to the last node
307 * Property class: contains a name and a value.
310 class WXDLLIMPEXP_DEPRECATED wxProperty
: public wxObject
312 DECLARE_DYNAMIC_CLASS(wxProperty
)
316 wxPropertyValue m_value
;
318 wxString m_propertyRole
;
319 wxPropertyValidator
* m_propertyValidator
;
320 wxWindow
* m_propertyWindow
; // Usually a panel item, if anything
323 wxProperty(wxProperty
& copyFrom
);
324 wxProperty(wxString name
, wxString role
, wxPropertyValidator
*ed
= NULL
);
325 wxProperty(wxString name
, const wxPropertyValue
& val
, wxString role
, wxPropertyValidator
*ed
= NULL
);
328 virtual wxPropertyValue
& GetValue(void) const;
329 virtual wxPropertyValidator
*GetValidator(void) const;
330 virtual wxString
& GetName(void) const;
331 virtual wxString
& GetRole(void) const;
332 virtual void SetValue(const wxPropertyValue
& val
);
333 virtual void SetValidator(wxPropertyValidator
*v
);
334 virtual void SetName(wxString
& nm
);
335 virtual void SetRole(wxString
& role
);
336 void operator=(const wxPropertyValue
& val
);
337 virtual inline void SetWindow(wxWindow
*win
) { m_propertyWindow
= win
; }
338 virtual inline wxWindow
*GetWindow(void) const { return m_propertyWindow
; }
340 inline void Enable(bool en
) { m_enabled
= en
; }
341 inline bool IsEnabled(void) const { return m_enabled
; }