1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Property sheet classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "prop.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 WXDLLEXPORT wxPropertySheet
: public wxObject
44 DECLARE_DYNAMIC_CLASS(wxPropertySheet
)
46 wxPropertySheet(const wxString
& name
= "");
47 ~wxPropertySheet(void);
49 // Set the name of the sheet
50 inline virtual void SetName(const wxString
& name
) { m_name
=name
; }
51 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
69 virtual void Clear(void);
71 virtual void UpdateAllViews(wxPropertyView
*thisView
= NULL
);
72 inline virtual wxList
& GetProperties(void) 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
;
85 // Base class for property sheet views. There are currently two directly derived
86 // classes: wxPropertyListView, and wxPropertyFormView.
87 class WXDLLEXPORT wxPropertyView
: public wxEvtHandler
89 DECLARE_DYNAMIC_CLASS(wxPropertyView
)
91 wxPropertyView(long flags
= 0);
92 ~wxPropertyView(void);
94 // Associates and shows the view
95 virtual void ShowView(wxPropertySheet
*WXUNUSED(propertySheet
), wxWindow
*WXUNUSED(panel
)) {}
97 // Update this view of the viewed object, called e.g. by
99 virtual bool OnUpdateView(void) {return FALSE
;};
101 // Override this to do something as soon as the property changed,
102 // if the view and validators support it.
103 virtual void OnPropertyChanged(wxProperty
*WXUNUSED(property
)) {}
105 virtual void AddRegistry(wxPropertyValidatorRegistry
*registry
);
106 inline virtual wxList
& GetRegistryList(void) const
107 { return (wxList
&) m_validatorRegistryList
; }
109 virtual wxPropertyValidator
*FindPropertyValidator(wxProperty
*property
);
110 inline virtual void SetPropertySheet(wxPropertySheet
*sheet
) { m_propertySheet
= sheet
; }
111 inline virtual wxPropertySheet
*GetPropertySheet(void) const { return m_propertySheet
; }
114 virtual void OnOk(void) {};
115 virtual void OnCancel(void) {};
116 virtual void OnHelp(void) {};
119 inline virtual bool OnClose(void) { 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
;
131 class WXDLLEXPORT wxPropertyValidator
: public wxEvtHandler
133 DECLARE_DYNAMIC_CLASS(wxPropertyValidator
)
135 wxPropertyValidator(long flags
= 0);
136 ~wxPropertyValidator(void);
138 inline long GetFlags(void) 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
;
157 // extern wxPropertyValidator *wxDefaultPropertyValidator;
159 class WXDLLEXPORT wxPropertyValidatorRegistry
: public wxHashTable
161 DECLARE_DYNAMIC_CLASS(wxPropertyValidatorRegistry
)
163 wxPropertyValidatorRegistry(void);
164 ~wxPropertyValidatorRegistry(void);
166 virtual void RegisterValidator(const wxString
& roleName
, wxPropertyValidator
*validator
);
167 virtual wxPropertyValidator
*GetValidator(const wxString
& roleName
);
168 void ClearRegistry(void);
172 * Property value class
177 wxPropertyValueInteger
,
180 wxPropertyValueString
,
182 wxPropertyValueIntegerPtr
,
183 wxPropertyValueRealPtr
,
184 wxPropertyValueboolPtr
,
185 wxPropertyValueStringPtr
186 } wxPropertyValueType
;
188 class WXDLLEXPORT wxPropertyValue
: public wxObject
190 DECLARE_DYNAMIC_CLASS(wxPropertyValue
)
192 wxPropertyValue(void); // Unknown type
193 wxPropertyValue(const wxPropertyValue
& copyFrom
); // Copy constructor
194 wxPropertyValue(const wxChar
*val
);
195 wxPropertyValue(const wxString
& val
);
196 wxPropertyValue(long val
);
197 wxPropertyValue(bool val
);
198 wxPropertyValue(float val
);
199 wxPropertyValue(double the_real
);
200 wxPropertyValue(wxList
*val
);
201 wxPropertyValue(wxStringList
*val
);
203 wxPropertyValue(wxChar
**val
);
204 wxPropertyValue(long *val
);
205 wxPropertyValue(bool *val
);
206 wxPropertyValue(float *val
);
208 ~wxPropertyValue(void);
210 virtual inline wxPropertyValueType
Type(void) const { return m_type
; }
211 virtual inline void SetType(wxPropertyValueType typ
) { m_type
= typ
; }
212 virtual long IntegerValue(void) const;
213 virtual float RealValue(void) const;
214 virtual bool BoolValue(void) const;
215 virtual wxChar
*StringValue(void) const;
216 virtual long *IntegerValuePtr(void) const;
217 virtual float *RealValuePtr(void) const;
218 virtual bool *BoolValuePtr(void) const;
219 virtual wxChar
**StringValuePtr(void) const;
221 // Get nth arg of clause (starting from 1)
222 virtual wxPropertyValue
*Arg(wxPropertyValueType type
, int arg
) const;
224 // Return nth argument of a list expression (starting from zero)
225 virtual wxPropertyValue
*Nth(int arg
) const;
226 // Returns the number of elements in a list expression
227 virtual int Number(void) const;
229 virtual wxPropertyValue
*NewCopy(void) const;
230 virtual void Copy(wxPropertyValue
& copyFrom
);
232 virtual void WritePropertyClause(wxString
&stream
); // Write this expression as a top-level clause
233 virtual void WritePropertyType(wxString
&stream
); // Write as any other subexpression
235 // Append an expression to a list
236 virtual void Append(wxPropertyValue
*expr
);
237 // Insert at beginning of list
238 virtual void Insert(wxPropertyValue
*expr
);
240 // Get first expr in list
241 virtual inline wxPropertyValue
*GetFirst(void) const
242 { return ((m_type
== wxPropertyValueList
) ? m_value
.first
: (wxPropertyValue
*)NULL
); }
244 // Get next expr if this is a node in a list
245 virtual inline wxPropertyValue
*GetNext(void) const
248 // Get last expr in list
249 virtual inline wxPropertyValue
*GetLast(void) const
250 { return ((m_type
== wxPropertyValueList
) ? m_last
: (wxPropertyValue
*)NULL
); }
252 // Delete this node from the list
253 virtual void Delete(wxPropertyValue
*node
);
256 virtual void ClearList(void);
258 virtual inline void SetClientData(wxObject
*data
) { m_clientData
= data
; }
259 virtual inline wxObject
*GetClientData(void) { return m_clientData
; }
261 virtual wxString
GetStringRepresentation(void);
263 inline void SetModified(bool flag
= TRUE
) { m_modifiedFlag
= flag
; }
264 inline bool GetModified(void) { return m_modifiedFlag
; }
267 void operator=(const wxPropertyValue
& val
);
268 // void operator=(const char *val);
269 void operator=(const wxString
& val
);
270 void operator=(const long val
);
271 void operator=(const bool val
);
272 void operator=(const float val
);
273 void operator=(const wxChar
**val
);
274 void operator=(const long *val
);
275 void operator=(const bool *val
);
276 void operator=(const float *val
);
279 wxObject
* m_clientData
;
280 wxPropertyValueType m_type
;
284 long integer
; // Also doubles as bool
291 wxPropertyValue
*first
; // If is a list expr, points to the first node
294 wxPropertyValue
* m_next
; // If this is a node in a list, points to the next node
295 wxPropertyValue
* m_last
; // If is a list expr, points to the last node
300 * Property class: contains a name and a value.
303 class WXDLLEXPORT wxProperty
: public wxObject
305 DECLARE_DYNAMIC_CLASS(wxProperty
)
309 wxPropertyValue m_value
;
311 wxString m_propertyRole
;
312 wxPropertyValidator
* m_propertyValidator
;
313 wxWindow
* m_propertyWindow
; // Usually a panel item, if anything
316 wxProperty(wxProperty
& copyFrom
);
317 wxProperty(wxString name
, wxString role
, wxPropertyValidator
*ed
= NULL
);
318 wxProperty(wxString name
, const wxPropertyValue
& val
, wxString role
, wxPropertyValidator
*ed
= NULL
);
321 virtual wxPropertyValue
& GetValue(void) const;
322 virtual wxPropertyValidator
*GetValidator(void) const;
323 virtual wxString
& GetName(void) const;
324 virtual wxString
& GetRole(void) const;
325 virtual void SetValue(const wxPropertyValue
& val
);
326 virtual void SetValidator(wxPropertyValidator
*v
);
327 virtual void SetName(wxString
& nm
);
328 virtual void SetRole(wxString
& role
);
329 void operator=(const wxPropertyValue
& val
);
330 virtual inline void SetWindow(wxWindow
*win
) { m_propertyWindow
= win
; }
331 virtual inline wxWindow
*GetWindow(void) const { return m_propertyWindow
; }
333 inline void Enable(bool en
) { m_enabled
= en
; }
334 inline bool IsEnabled(void) const { return m_enabled
; }