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"
32 class wxPropertyValue
;
33 class wxPropertySheet
;
35 class wxPropertyValidator
;
36 class wxPropertyValidatorRegistry
;
38 #define wxPROPERTY_VERSION 2.0
40 // A storable sheet of values
41 class WXDLLEXPORT wxPropertySheet
: public wxObject
43 DECLARE_DYNAMIC_CLASS(wxPropertySheet
)
45 wxPropertySheet(const wxString
& name
= "");
46 ~wxPropertySheet(void);
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
; }
51 // Does this sheet contain a property with this name
52 virtual bool HasProperty(const wxString
& name
) const;
54 // Set property name to value
55 virtual bool SetProperty(const wxString
& name
, const wxPropertyValue
& value
);
57 // Remove property from sheet by name, deleting it
58 virtual void RemoveProperty(const wxString
& name
);
60 // Get the name of the sheet
62 virtual void AddProperty(wxProperty
*property
);
64 // Get property by name
65 virtual wxProperty
*GetProperty(const wxString
& name
) const;
67 // Clear all properties
68 virtual void Clear(void);
70 virtual void UpdateAllViews(wxPropertyView
*thisView
= NULL
);
71 inline virtual wxList
& GetProperties(void) const { return (wxList
&) m_properties
; }
73 // Sets/clears the modified flag for each property value
74 virtual void SetAllModified(bool flag
= TRUE
);
77 wxObject
* m_viewedObject
;
79 wxPropertyView
* m_propertyView
;
84 // Base class for property sheet views. There are currently two directly derived
85 // classes: wxPropertyListView, and wxPropertyFormView.
86 class WXDLLEXPORT wxPropertyView
: public wxEvtHandler
88 DECLARE_DYNAMIC_CLASS(wxPropertyView
)
90 wxPropertyView(long flags
= 0);
91 ~wxPropertyView(void);
93 // Associates and shows the view
94 virtual void ShowView(wxPropertySheet
*WXUNUSED(propertySheet
), wxWindow
*WXUNUSED(panel
)) {}
96 // Update this view of the viewed object, called e.g. by
98 virtual bool OnUpdateView(void) {return FALSE
;};
100 // Override this to do something as soon as the property changed,
101 // if the view and validators support it.
102 virtual void OnPropertyChanged(wxProperty
*WXUNUSED(property
)) {}
104 virtual void AddRegistry(wxPropertyValidatorRegistry
*registry
);
105 inline virtual wxList
& GetRegistryList(void) const
106 { return (wxList
&) m_validatorRegistryList
; }
108 virtual wxPropertyValidator
*FindPropertyValidator(wxProperty
*property
);
109 inline virtual void SetPropertySheet(wxPropertySheet
*sheet
) { m_propertySheet
= sheet
; }
110 inline virtual wxPropertySheet
*GetPropertySheet(void) const { return m_propertySheet
; }
113 virtual void OnOk(void) {};
114 virtual void OnCancel(void) {};
115 virtual void OnHelp(void) {};
118 inline virtual bool OnClose(void) { return FALSE
; }
119 inline long GetFlags(void) { return m_buttonFlags
; }
123 wxPropertySheet
* m_propertySheet
;
124 wxProperty
* m_currentProperty
;
125 wxList m_validatorRegistryList
;
126 wxPropertyValidator
* m_currentValidator
;
130 class WXDLLEXPORT wxPropertyValidator
: public wxEvtHandler
132 DECLARE_DYNAMIC_CLASS(wxPropertyValidator
)
134 wxPropertyValidator(long flags
= 0);
135 ~wxPropertyValidator(void);
137 inline long GetFlags(void) const { return m_validatorFlags
; }
138 inline void SetValidatorProperty(wxProperty
*prop
) { m_validatorProperty
= prop
; }
139 inline wxProperty
*GetValidatorProperty(void) const { return m_validatorProperty
; }
141 virtual bool StringToFloat (wxChar
*s
, float *number
);
142 virtual bool StringToDouble (wxChar
*s
, double *number
);
143 virtual bool StringToInt (wxChar
*s
, int *number
);
144 virtual bool StringToLong (wxChar
*s
, long *number
);
145 virtual wxChar
*FloatToString (float number
);
146 virtual wxChar
*DoubleToString (double number
);
147 virtual wxChar
*IntToString (int number
);
148 virtual wxChar
*LongToString (long number
);
151 long m_validatorFlags
;
152 wxProperty
* m_validatorProperty
;
156 // extern wxPropertyValidator *wxDefaultPropertyValidator;
158 class WXDLLEXPORT wxPropertyValidatorRegistry
: public wxHashTable
160 DECLARE_DYNAMIC_CLASS(wxPropertyValidatorRegistry
)
162 wxPropertyValidatorRegistry(void);
163 ~wxPropertyValidatorRegistry(void);
165 virtual void RegisterValidator(const wxString
& roleName
, wxPropertyValidator
*validator
);
166 virtual wxPropertyValidator
*GetValidator(const wxString
& roleName
);
167 void ClearRegistry(void);
171 * Property value class
176 wxPropertyValueInteger
,
179 wxPropertyValueString
,
181 wxPropertyValueIntegerPtr
,
182 wxPropertyValueRealPtr
,
183 wxPropertyValueboolPtr
,
184 wxPropertyValueStringPtr
185 } wxPropertyValueType
;
187 class WXDLLEXPORT wxPropertyValue
: public wxObject
189 DECLARE_DYNAMIC_CLASS(wxPropertyValue
)
191 wxPropertyValue(void); // Unknown type
192 wxPropertyValue(const wxPropertyValue
& copyFrom
); // Copy constructor
193 wxPropertyValue(const wxChar
*val
);
194 wxPropertyValue(const wxString
& val
);
195 wxPropertyValue(long val
);
196 wxPropertyValue(bool val
);
197 wxPropertyValue(float val
);
198 wxPropertyValue(double the_real
);
199 wxPropertyValue(wxList
*val
);
200 wxPropertyValue(wxStringList
*val
);
202 wxPropertyValue(wxChar
**val
);
203 wxPropertyValue(long *val
);
204 wxPropertyValue(bool *val
);
205 wxPropertyValue(float *val
);
207 ~wxPropertyValue(void);
209 virtual inline wxPropertyValueType
Type(void) const { return m_type
; }
210 virtual inline void SetType(wxPropertyValueType typ
) { m_type
= typ
; }
211 virtual long IntegerValue(void) const;
212 virtual float RealValue(void) const;
213 virtual bool BoolValue(void) const;
214 virtual wxChar
*StringValue(void) const;
215 virtual long *IntegerValuePtr(void) const;
216 virtual float *RealValuePtr(void) const;
217 virtual bool *BoolValuePtr(void) const;
218 virtual wxChar
**StringValuePtr(void) const;
220 // Get nth arg of clause (starting from 1)
221 virtual wxPropertyValue
*Arg(wxPropertyValueType type
, int arg
) const;
223 // Return nth argument of a list expression (starting from zero)
224 virtual wxPropertyValue
*Nth(int arg
) const;
225 // Returns the number of elements in a list expression
226 virtual int Number(void) const;
228 virtual wxPropertyValue
*NewCopy(void) const;
229 virtual void Copy(wxPropertyValue
& copyFrom
);
231 virtual void WritePropertyClause(wxString
&stream
); // Write this expression as a top-level clause
232 virtual void WritePropertyType(wxString
&stream
); // Write as any other subexpression
234 // Append an expression to a list
235 virtual void Append(wxPropertyValue
*expr
);
236 // Insert at beginning of list
237 virtual void Insert(wxPropertyValue
*expr
);
239 // Get first expr in list
240 virtual inline wxPropertyValue
*GetFirst(void) const
241 { return ((m_type
== wxPropertyValueList
) ? m_value
.first
: (wxPropertyValue
*)NULL
); }
243 // Get next expr if this is a node in a list
244 virtual inline wxPropertyValue
*GetNext(void) const
247 // Get last expr in list
248 virtual inline wxPropertyValue
*GetLast(void) const
249 { return ((m_type
== wxPropertyValueList
) ? m_last
: (wxPropertyValue
*)NULL
); }
251 // Delete this node from the list
252 virtual void Delete(wxPropertyValue
*node
);
255 virtual void ClearList(void);
257 virtual inline void SetClientData(wxObject
*data
) { m_clientData
= data
; }
258 virtual inline wxObject
*GetClientData(void) { return m_clientData
; }
260 virtual wxString
GetStringRepresentation(void);
262 inline void SetModified(bool flag
= TRUE
) { m_modifiedFlag
= flag
; }
263 inline bool GetModified(void) { return m_modifiedFlag
; }
266 void operator=(const wxPropertyValue
& val
);
267 // void operator=(const char *val);
268 void operator=(const wxString
& val
);
269 void operator=(const long val
);
270 void operator=(const bool val
);
271 void operator=(const float val
);
272 void operator=(const wxChar
**val
);
273 void operator=(const long *val
);
274 void operator=(const bool *val
);
275 void operator=(const float *val
);
278 wxObject
* m_clientData
;
279 wxPropertyValueType m_type
;
283 long integer
; // Also doubles as bool
290 wxPropertyValue
*first
; // If is a list expr, points to the first node
293 wxPropertyValue
* m_next
; // If this is a node in a list, points to the next node
294 wxPropertyValue
* m_last
; // If is a list expr, points to the last node
299 * Property class: contains a name and a value.
302 class WXDLLEXPORT wxProperty
: public wxObject
304 DECLARE_DYNAMIC_CLASS(wxProperty
)
308 wxPropertyValue m_value
;
310 wxString m_propertyRole
;
311 wxPropertyValidator
* m_propertyValidator
;
312 wxWindow
* m_propertyWindow
; // Usually a panel item, if anything
315 wxProperty(wxProperty
& copyFrom
);
316 wxProperty(wxString name
, wxString role
, wxPropertyValidator
*ed
= NULL
);
317 wxProperty(wxString name
, const wxPropertyValue
& val
, wxString role
, wxPropertyValidator
*ed
= NULL
);
320 virtual wxPropertyValue
& GetValue(void) const;
321 virtual wxPropertyValidator
*GetValidator(void) const;
322 virtual wxString
& GetName(void) const;
323 virtual wxString
& GetRole(void) const;
324 virtual void SetValue(const wxPropertyValue
& val
);
325 virtual void SetValidator(wxPropertyValidator
*v
);
326 virtual void SetName(wxString
& nm
);
327 virtual void SetRole(wxString
& role
);
328 void operator=(const wxPropertyValue
& val
);
329 virtual inline void SetWindow(wxWindow
*win
) { m_propertyWindow
= win
; }
330 virtual inline wxWindow
*GetWindow(void) const { return m_propertyWindow
; }
332 inline void Enable(bool en
) { m_enabled
= en
; }
333 inline bool IsEnabled(void) const { return m_enabled
; }