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"
22 #include "wx/string.h"
24 #include "wx/dialog.h"
26 #include "wx/button.h"
27 #include "wx/listbox.h"
28 #include "wx/textctrl.h"
29 #include "wx/gdicmn.h"
30 #include "wx/layout.h"
35 class wxPropertyValue
;
36 class wxPropertySheet
;
38 class wxPropertyValidator
;
39 class wxPropertyValidatorRegistry
;
41 #define wxPROPERTY_VERSION 2.0
43 // A storable sheet of values
44 class WXDLLEXPORT wxPropertySheet
: public wxObject
47 wxPropertySheet(const wxString
& name
= wxT(""));
50 // Set the name of the sheet
51 inline virtual void SetName(const wxString
& name
) { m_name
=name
; }
52 inline virtual wxString
GetName() const { return m_name
; }
54 // Does this sheet contain a property with this name
55 virtual bool HasProperty(const wxString
& name
) const;
57 // Set property name to value
58 virtual bool SetProperty(const wxString
& name
, const wxPropertyValue
& value
);
60 // Remove property from sheet by name, deleting it
61 virtual void RemoveProperty(const wxString
& name
);
63 // Get the name of the sheet
65 virtual void AddProperty(wxProperty
*property
);
67 // Get property by name
68 virtual wxProperty
*GetProperty(const wxString
& name
) const;
70 // Clear all properties
73 virtual void UpdateAllViews(wxPropertyView
*thisView
= NULL
);
74 inline virtual wxList
& GetProperties() const { return (wxList
&) m_properties
; }
76 // Sets/clears the modified flag for each property value
77 virtual void SetAllModified(bool flag
= TRUE
);
80 wxObject
* m_viewedObject
;
82 wxPropertyView
* m_propertyView
;
86 DECLARE_DYNAMIC_CLASS(wxPropertySheet
)
90 // Base class for property sheet views. There are currently two directly derived
91 // classes: wxPropertyListView, and wxPropertyFormView.
92 class WXDLLEXPORT wxPropertyView
: public wxEvtHandler
95 wxPropertyView(long flags
= 0);
98 // Associates and shows the view
99 virtual void ShowView(wxPropertySheet
*WXUNUSED(propertySheet
), wxWindow
*WXUNUSED(panel
)) {}
101 // Update this view of the viewed object, called e.g. by
102 // the object itself.
103 virtual bool OnUpdateView() {return FALSE
;};
105 // Override this to do something as soon as the property changed,
106 // if the view and validators support it.
107 virtual void OnPropertyChanged(wxProperty
*WXUNUSED(property
)) {}
109 virtual void AddRegistry(wxPropertyValidatorRegistry
*registry
);
110 inline virtual wxList
& GetRegistryList() const
111 { return (wxList
&) m_validatorRegistryList
; }
113 virtual wxPropertyValidator
*FindPropertyValidator(wxProperty
*property
);
114 inline virtual void SetPropertySheet(wxPropertySheet
*sheet
) { m_propertySheet
= sheet
; }
115 inline virtual wxPropertySheet
*GetPropertySheet() const { return m_propertySheet
; }
117 inline virtual bool OnClose() { return FALSE
; }
118 inline long GetFlags(void) { return m_buttonFlags
; }
122 wxPropertySheet
* m_propertySheet
;
123 wxProperty
* m_currentProperty
;
124 wxList m_validatorRegistryList
;
125 wxPropertyValidator
* m_currentValidator
;
128 DECLARE_DYNAMIC_CLASS(wxPropertyView
)
132 class WXDLLEXPORT wxPropertyValidator
: public wxEvtHandler
135 wxPropertyValidator(long flags
= 0);
136 ~wxPropertyValidator();
138 inline long GetFlags() const { return m_validatorFlags
; }
139 inline void SetValidatorProperty(wxProperty
*prop
) { m_validatorProperty
= prop
; }
140 inline wxProperty
*GetValidatorProperty(void) const { return m_validatorProperty
; }
142 virtual bool StringToFloat (wxChar
*s
, float *number
);
143 virtual bool StringToDouble (wxChar
*s
, double *number
);
144 virtual bool StringToInt (wxChar
*s
, int *number
);
145 virtual bool StringToLong (wxChar
*s
, long *number
);
146 virtual wxChar
*FloatToString (float number
);
147 virtual wxChar
*DoubleToString (double number
);
148 virtual wxChar
*IntToString (int number
);
149 virtual wxChar
*LongToString (long number
);
152 long m_validatorFlags
;
153 wxProperty
* m_validatorProperty
;
156 DECLARE_DYNAMIC_CLASS(wxPropertyValidator
)
160 // extern wxPropertyValidator *wxDefaultPropertyValidator;
162 class WXDLLEXPORT wxPropertyValidatorRegistry
: public wxHashTable
165 wxPropertyValidatorRegistry();
166 ~wxPropertyValidatorRegistry();
168 virtual void RegisterValidator(const wxString
& roleName
, wxPropertyValidator
*validator
);
169 virtual wxPropertyValidator
*GetValidator(const wxString
& roleName
);
170 void ClearRegistry();
173 DECLARE_DYNAMIC_CLASS(wxPropertyValidatorRegistry
)
177 * Property value class
182 wxPropertyValueInteger
,
185 wxPropertyValueString
,
187 wxPropertyValueIntegerPtr
,
188 wxPropertyValueRealPtr
,
189 wxPropertyValueboolPtr
,
190 wxPropertyValueStringPtr
191 } wxPropertyValueType
;
193 class WXDLLEXPORT wxPropertyValue
: public wxObject
195 DECLARE_DYNAMIC_CLASS(wxPropertyValue
)
197 wxPropertyValue(void); // Unknown type
198 wxPropertyValue(const wxPropertyValue
& copyFrom
); // Copy constructor
199 wxPropertyValue(const wxChar
*val
);
200 wxPropertyValue(const wxString
& val
);
201 wxPropertyValue(long val
);
202 wxPropertyValue(bool val
);
203 wxPropertyValue(float val
);
204 wxPropertyValue(double the_real
);
205 wxPropertyValue(wxList
*val
);
206 wxPropertyValue(wxStringList
*val
);
208 wxPropertyValue(wxChar
**val
);
209 wxPropertyValue(long *val
);
210 wxPropertyValue(bool *val
);
211 wxPropertyValue(float *val
);
213 ~wxPropertyValue(void);
215 virtual inline wxPropertyValueType
Type(void) const { return m_type
; }
216 virtual inline void SetType(wxPropertyValueType typ
) { m_type
= typ
; }
217 virtual long IntegerValue(void) const;
218 virtual float RealValue(void) const;
219 virtual bool BoolValue(void) const;
220 virtual wxChar
*StringValue(void) const;
221 virtual long *IntegerValuePtr(void) const;
222 virtual float *RealValuePtr(void) const;
223 virtual bool *BoolValuePtr(void) const;
224 virtual wxChar
**StringValuePtr(void) const;
226 // Get nth arg of clause (starting from 1)
227 virtual wxPropertyValue
*Arg(wxPropertyValueType type
, int arg
) const;
229 // Return nth argument of a list expression (starting from zero)
230 virtual wxPropertyValue
*Nth(int arg
) const;
231 // Returns the number of elements in a list expression
232 virtual int Number(void) const;
234 virtual wxPropertyValue
*NewCopy(void) const;
235 virtual void Copy(wxPropertyValue
& copyFrom
);
237 virtual void WritePropertyClause(wxString
&stream
); // Write this expression as a top-level clause
238 virtual void WritePropertyType(wxString
&stream
); // Write as any other subexpression
240 // Append an expression to a list
241 virtual void Append(wxPropertyValue
*expr
);
242 // Insert at beginning of list
243 virtual void Insert(wxPropertyValue
*expr
);
245 // Get first expr in list
246 virtual inline wxPropertyValue
*GetFirst(void) const
247 { return ((m_type
== wxPropertyValueList
) ? m_value
.first
: (wxPropertyValue
*)NULL
); }
249 // Get next expr if this is a node in a list
250 virtual inline wxPropertyValue
*GetNext(void) const
253 // Get last expr in list
254 virtual inline wxPropertyValue
*GetLast(void) const
255 { return ((m_type
== wxPropertyValueList
) ? m_last
: (wxPropertyValue
*)NULL
); }
257 // Delete this node from the list
258 virtual void Delete(wxPropertyValue
*node
);
261 virtual void ClearList(void);
263 virtual inline void SetClientData(wxObject
*data
) { m_clientData
= data
; }
264 virtual inline wxObject
*GetClientData(void) { return m_clientData
; }
266 virtual wxString
GetStringRepresentation(void);
268 inline void SetModified(bool flag
= TRUE
) { m_modifiedFlag
= flag
; }
269 inline bool GetModified(void) { return m_modifiedFlag
; }
272 void operator=(const wxPropertyValue
& val
);
273 // void operator=(const char *val);
274 void operator=(const wxString
& val
);
275 void operator=(const long val
);
276 void operator=(const bool val
);
277 void operator=(const float val
);
278 void operator=(const wxChar
**val
);
279 void operator=(const long *val
);
280 void operator=(const bool *val
);
281 void operator=(const float *val
);
284 wxObject
* m_clientData
;
285 wxPropertyValueType m_type
;
289 long integer
; // Also doubles as bool
296 wxPropertyValue
*first
; // If is a list expr, points to the first node
299 wxPropertyValue
* m_next
; // If this is a node in a list, points to the next node
300 wxPropertyValue
* m_last
; // If is a list expr, points to the last node
305 * Property class: contains a name and a value.
308 class WXDLLEXPORT wxProperty
: public wxObject
310 DECLARE_DYNAMIC_CLASS(wxProperty
)
314 wxPropertyValue m_value
;
316 wxString m_propertyRole
;
317 wxPropertyValidator
* m_propertyValidator
;
318 wxWindow
* m_propertyWindow
; // Usually a panel item, if anything
321 wxProperty(wxProperty
& copyFrom
);
322 wxProperty(wxString name
, wxString role
, wxPropertyValidator
*ed
= NULL
);
323 wxProperty(wxString name
, const wxPropertyValue
& val
, wxString role
, wxPropertyValidator
*ed
= NULL
);
326 virtual wxPropertyValue
& GetValue(void) const;
327 virtual wxPropertyValidator
*GetValidator(void) const;
328 virtual wxString
& GetName(void) const;
329 virtual wxString
& GetRole(void) const;
330 virtual void SetValue(const wxPropertyValue
& val
);
331 virtual void SetValidator(wxPropertyValidator
*v
);
332 virtual void SetName(wxString
& nm
);
333 virtual void SetRole(wxString
& role
);
334 void operator=(const wxPropertyValue
& val
);
335 virtual inline void SetWindow(wxWindow
*win
) { m_propertyWindow
= win
; }
336 virtual inline wxWindow
*GetWindow(void) const { return m_propertyWindow
; }
338 inline void Enable(bool en
) { m_enabled
= en
; }
339 inline bool IsEnabled(void) const { return m_enabled
; }