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"
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
46 DECLARE_DYNAMIC_CLASS(wxPropertySheet
)
48 wxPropertySheet(const wxString
& name
= "");
49 ~wxPropertySheet(void);
51 // Set the name of the sheet
52 inline virtual void SetName(const wxString
& name
) { m_name
=name
; }
53 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
71 virtual void Clear(void);
73 virtual void UpdateAllViews(wxPropertyView
*thisView
= NULL
);
74 inline virtual wxList
& GetProperties(void) 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
;
87 // Base class for property sheet views. There are currently two directly derived
88 // classes: wxPropertyListView, and wxPropertyFormView.
89 class WXDLLEXPORT wxPropertyView
: public wxEvtHandler
91 DECLARE_DYNAMIC_CLASS(wxPropertyView
)
93 wxPropertyView(long flags
= 0);
94 ~wxPropertyView(void);
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(void) {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(void) 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(void) const { return m_propertySheet
; }
116 virtual void OnOk(void) {};
117 virtual void OnCancel(void) {};
118 virtual void OnHelp(void) {};
121 inline virtual bool OnClose(void) { return FALSE
; }
122 inline long GetFlags(void) { return m_buttonFlags
; }
126 wxPropertySheet
* m_propertySheet
;
127 wxProperty
* m_currentProperty
;
128 wxList m_validatorRegistryList
;
129 wxPropertyValidator
* m_currentValidator
;
133 class WXDLLEXPORT wxPropertyValidator
: public wxEvtHandler
135 DECLARE_DYNAMIC_CLASS(wxPropertyValidator
)
137 wxPropertyValidator(long flags
= 0);
138 ~wxPropertyValidator(void);
140 inline long GetFlags(void) 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
;
159 // extern wxPropertyValidator *wxDefaultPropertyValidator;
161 class WXDLLEXPORT wxPropertyValidatorRegistry
: public wxHashTable
163 DECLARE_DYNAMIC_CLASS(wxPropertyValidatorRegistry
)
165 wxPropertyValidatorRegistry(void);
166 ~wxPropertyValidatorRegistry(void);
168 virtual void RegisterValidator(const wxString
& roleName
, wxPropertyValidator
*validator
);
169 virtual wxPropertyValidator
*GetValidator(const wxString
& roleName
);
170 void ClearRegistry(void);
174 * Property value class
179 wxPropertyValueInteger
,
182 wxPropertyValueString
,
184 wxPropertyValueIntegerPtr
,
185 wxPropertyValueRealPtr
,
186 wxPropertyValueboolPtr
,
187 wxPropertyValueStringPtr
188 } wxPropertyValueType
;
190 class WXDLLEXPORT wxPropertyValue
: public wxObject
192 DECLARE_DYNAMIC_CLASS(wxPropertyValue
)
194 wxPropertyValue(void); // Unknown type
195 wxPropertyValue(const wxPropertyValue
& copyFrom
); // Copy constructor
196 wxPropertyValue(const wxChar
*val
);
197 wxPropertyValue(const wxString
& val
);
198 wxPropertyValue(long val
);
199 wxPropertyValue(bool val
);
200 wxPropertyValue(float val
);
201 wxPropertyValue(double the_real
);
202 wxPropertyValue(wxList
*val
);
203 wxPropertyValue(wxStringList
*val
);
205 wxPropertyValue(wxChar
**val
);
206 wxPropertyValue(long *val
);
207 wxPropertyValue(bool *val
);
208 wxPropertyValue(float *val
);
210 ~wxPropertyValue(void);
212 virtual inline wxPropertyValueType
Type(void) const { return m_type
; }
213 virtual inline void SetType(wxPropertyValueType typ
) { m_type
= typ
; }
214 virtual long IntegerValue(void) const;
215 virtual float RealValue(void) const;
216 virtual bool BoolValue(void) const;
217 virtual wxChar
*StringValue(void) const;
218 virtual long *IntegerValuePtr(void) const;
219 virtual float *RealValuePtr(void) const;
220 virtual bool *BoolValuePtr(void) const;
221 virtual wxChar
**StringValuePtr(void) const;
223 // Get nth arg of clause (starting from 1)
224 virtual wxPropertyValue
*Arg(wxPropertyValueType type
, int arg
) const;
226 // Return nth argument of a list expression (starting from zero)
227 virtual wxPropertyValue
*Nth(int arg
) const;
228 // Returns the number of elements in a list expression
229 virtual int Number(void) const;
231 virtual wxPropertyValue
*NewCopy(void) const;
232 virtual void Copy(wxPropertyValue
& copyFrom
);
234 virtual void WritePropertyClause(wxString
&stream
); // Write this expression as a top-level clause
235 virtual void WritePropertyType(wxString
&stream
); // Write as any other subexpression
237 // Append an expression to a list
238 virtual void Append(wxPropertyValue
*expr
);
239 // Insert at beginning of list
240 virtual void Insert(wxPropertyValue
*expr
);
242 // Get first expr in list
243 virtual inline wxPropertyValue
*GetFirst(void) const
244 { return ((m_type
== wxPropertyValueList
) ? m_value
.first
: (wxPropertyValue
*)NULL
); }
246 // Get next expr if this is a node in a list
247 virtual inline wxPropertyValue
*GetNext(void) const
250 // Get last expr in list
251 virtual inline wxPropertyValue
*GetLast(void) const
252 { return ((m_type
== wxPropertyValueList
) ? m_last
: (wxPropertyValue
*)NULL
); }
254 // Delete this node from the list
255 virtual void Delete(wxPropertyValue
*node
);
258 virtual void ClearList(void);
260 virtual inline void SetClientData(wxObject
*data
) { m_clientData
= data
; }
261 virtual inline wxObject
*GetClientData(void) { return m_clientData
; }
263 virtual wxString
GetStringRepresentation(void);
265 inline void SetModified(bool flag
= TRUE
) { m_modifiedFlag
= flag
; }
266 inline bool GetModified(void) { return m_modifiedFlag
; }
269 void operator=(const wxPropertyValue
& val
);
270 // void operator=(const char *val);
271 void operator=(const wxString
& val
);
272 void operator=(const long val
);
273 void operator=(const bool val
);
274 void operator=(const float val
);
275 void operator=(const wxChar
**val
);
276 void operator=(const long *val
);
277 void operator=(const bool *val
);
278 void operator=(const float *val
);
281 wxObject
* m_clientData
;
282 wxPropertyValueType m_type
;
286 long integer
; // Also doubles as bool
293 wxPropertyValue
*first
; // If is a list expr, points to the first node
296 wxPropertyValue
* m_next
; // If this is a node in a list, points to the next node
297 wxPropertyValue
* m_last
; // If is a list expr, points to the last node
302 * Property class: contains a name and a value.
305 class WXDLLEXPORT wxProperty
: public wxObject
307 DECLARE_DYNAMIC_CLASS(wxProperty
)
311 wxPropertyValue m_value
;
313 wxString m_propertyRole
;
314 wxPropertyValidator
* m_propertyValidator
;
315 wxWindow
* m_propertyWindow
; // Usually a panel item, if anything
318 wxProperty(wxProperty
& copyFrom
);
319 wxProperty(wxString name
, wxString role
, wxPropertyValidator
*ed
= NULL
);
320 wxProperty(wxString name
, const wxPropertyValue
& val
, wxString role
, wxPropertyValidator
*ed
= NULL
);
323 virtual wxPropertyValue
& GetValue(void) const;
324 virtual wxPropertyValidator
*GetValidator(void) const;
325 virtual wxString
& GetName(void) const;
326 virtual wxString
& GetRole(void) const;
327 virtual void SetValue(const wxPropertyValue
& val
);
328 virtual void SetValidator(wxPropertyValidator
*v
);
329 virtual void SetName(wxString
& nm
);
330 virtual void SetRole(wxString
& role
);
331 void operator=(const wxPropertyValue
& val
);
332 virtual inline void SetWindow(wxWindow
*win
) { m_propertyWindow
= win
; }
333 virtual inline wxWindow
*GetWindow(void) const { return m_propertyWindow
; }
335 inline void Enable(bool en
) { m_enabled
= en
; }
336 inline bool IsEnabled(void) const { return m_enabled
; }