1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Property sheet classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
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 wxPropertySheet
: public wxObject
43 DECLARE_DYNAMIC_CLASS(wxPropertySheet
)
45 wxObject
*viewedObject
;
47 wxPropertyView
*propertyView
;
50 wxPropertySheet(void);
51 ~wxPropertySheet(void);
54 virtual void AddProperty(wxProperty
*property
);
56 // Get property by name
57 virtual wxProperty
*GetProperty(wxString name
);
59 // Clear all properties
60 virtual void Clear(void);
62 virtual bool Save(ostream
& str
);
63 virtual bool Load(ostream
& str
);
65 virtual void UpdateAllViews(wxPropertyView
*thisView
= NULL
);
66 inline virtual wxList
& GetProperties(void) { return properties
; }
68 // Sets/clears the modified flag for each property value
69 virtual void SetAllModified(bool flag
= TRUE
);
73 // Base class for property sheet views. There are currently two directly derived
74 // classes: wxPropertyListView, and wxPropertyFormView.
75 class wxPropertyView
: public wxEvtHandler
77 DECLARE_DYNAMIC_CLASS(wxPropertyView
)
80 wxPropertySheet
*propertySheet
;
81 wxProperty
*currentProperty
;
82 wxList validatorRegistryList
;
83 wxPropertyValidator
*currentValidator
;
85 wxPropertyView(long flags
= 0);
86 ~wxPropertyView(void);
88 // Associates and shows the view
89 virtual void ShowView(wxPropertySheet
*WXUNUSED(propertySheet
), wxWindow
*WXUNUSED(panel
)) {}
91 // Update this view of the viewed object, called e.g. by
93 virtual bool OnUpdateView(void) {return FALSE
;};
95 // Override this to do something as soon as the property changed,
96 // if the view and validators support it.
97 virtual void OnPropertyChanged(wxProperty
*WXUNUSED(property
)) {}
99 virtual void AddRegistry(wxPropertyValidatorRegistry
*registry
);
100 inline virtual wxList
& GetRegistryList(void)
101 { return validatorRegistryList
; }
103 virtual wxPropertyValidator
*FindPropertyValidator(wxProperty
*property
);
104 inline virtual void SetPropertySheet(wxPropertySheet
*sheet
) { propertySheet
= sheet
; }
105 inline virtual wxPropertySheet
*GetPropertySheet(void) { return propertySheet
; }
107 virtual void OnOk(void) {};
108 virtual void OnCancel(void) {};
109 virtual void OnHelp(void) {};
111 inline virtual bool OnClose(void) { return FALSE
; }
112 inline long GetFlags(void) { return buttonFlags
; }
116 class wxPropertyValidator
: public wxEvtHandler
118 DECLARE_DYNAMIC_CLASS(wxPropertyValidator
)
121 wxProperty
*validatorProperty
;
123 wxPropertyValidator(long flags
= 0);
124 ~wxPropertyValidator(void);
126 inline long GetFlags(void) { return validatorFlags
; }
127 inline void SetValidatorProperty(wxProperty
*prop
) { validatorProperty
= prop
; }
128 inline wxProperty
*GetValidatorProperty(void) { return validatorProperty
; }
130 virtual bool StringToFloat (char *s
, float *number
);
131 virtual bool StringToDouble (char *s
, double *number
);
132 virtual bool StringToInt (char *s
, int *number
);
133 virtual bool StringToLong (char *s
, long *number
);
134 virtual char *FloatToString (float number
);
135 virtual char *DoubleToString (double number
);
136 virtual char *IntToString (int number
);
137 virtual char *LongToString (long number
);
141 // extern wxPropertyValidator *wxDefaultPropertyValidator;
143 class wxPropertyValidatorRegistry
: public wxHashTable
145 DECLARE_DYNAMIC_CLASS(wxPropertyValidatorRegistry
)
147 wxPropertyValidatorRegistry(void);
148 ~wxPropertyValidatorRegistry(void);
150 virtual void RegisterValidator(wxString
& roleName
, wxPropertyValidator
*validator
);
151 virtual wxPropertyValidator
*GetValidator(wxString
& roleName
);
152 void ClearRegistry(void);
156 * Property value class
161 wxPropertyValueInteger
,
164 wxPropertyValueString
,
166 wxPropertyValueIntegerPtr
,
167 wxPropertyValueRealPtr
,
168 wxPropertyValueboolPtr
,
169 wxPropertyValueStringPtr
170 } wxPropertyValueType
;
172 class wxPropertyValue
: public wxObject
174 DECLARE_DYNAMIC_CLASS(wxPropertyValue
)
176 wxObject
*client_data
;
177 wxPropertyValueType type
;
181 long integer
; // Also doubles as bool
188 wxPropertyValue
*first
; // If is a list expr, points to the first node
191 wxPropertyValue
*next
; // If this is a node in a list, points to the next node
192 wxPropertyValue
*last
; // If is a list expr, points to the last node
194 wxPropertyValue(void); // Unknown type
195 wxPropertyValue(const wxPropertyValue
& copyFrom
); // Copy constructor
196 wxPropertyValue(const char *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(char **val
);
206 wxPropertyValue(long *val
);
207 wxPropertyValue(bool *val
);
208 wxPropertyValue(float *val
);
210 ~wxPropertyValue(void);
212 virtual inline wxPropertyValueType
Type(void) { return type
; }
213 virtual inline void SetType(wxPropertyValueType typ
) { type
= typ
; }
214 virtual long IntegerValue(void);
215 virtual float RealValue(void);
216 virtual bool BoolValue(void);
217 virtual char *StringValue(void);
218 virtual long *IntegerValuePtr(void);
219 virtual float *RealValuePtr(void);
220 virtual bool *BoolValuePtr(void);
221 virtual char **StringValuePtr(void);
223 // Get nth arg of clause (starting from 1)
224 virtual wxPropertyValue
*Arg(wxPropertyValueType type
, int arg
);
226 // Return nth argument of a list expression (starting from zero)
227 virtual wxPropertyValue
*Nth(int arg
);
228 // Returns the number of elements in a list expression
229 virtual int Number(void);
231 virtual wxPropertyValue
*NewCopy(void);
232 virtual void Copy(wxPropertyValue
& copyFrom
);
234 virtual void WritePropertyClause(ostream
& stream
); // Write this expression as a top-level clause
235 virtual void WritePropertyType(ostream
& 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)
244 { return ((type
== wxPropertyValueList
) ? value
.first
: (wxPropertyValue
*)NULL
); }
246 // Get next expr if this is a node in a list
247 virtual inline wxPropertyValue
*GetNext(void)
250 // Get last expr in list
251 virtual inline wxPropertyValue
*GetLast(void)
252 { return ((type
== wxPropertyValueList
) ? 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
) { client_data
= data
; }
261 virtual inline wxObject
*GetClientData(void) { return client_data
; }
263 virtual wxString
GetStringRepresentation(void);
265 inline void SetModified(bool flag
= TRUE
) { modifiedFlag
= flag
; }
266 inline bool GetModified(void) { return 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 char **val
);
276 void operator=(const long *val
);
277 void operator=(const bool *val
);
278 void operator=(const float *val
);
282 * Property class: contains a name and a value.
285 class wxProperty
: public wxObject
287 DECLARE_DYNAMIC_CLASS(wxProperty
)
291 wxPropertyValue value
;
293 wxString propertyRole
;
294 wxPropertyValidator
*propertyValidator
;
295 wxWindow
*propertyWindow
; // Usually a panel item, if anything
298 wxProperty(wxProperty
& copyFrom
);
299 wxProperty(wxString name
, wxString role
, wxPropertyValidator
*ed
= NULL
);
300 wxProperty(wxString name
, const wxPropertyValue
& val
, wxString role
, wxPropertyValidator
*ed
= NULL
);
303 virtual wxPropertyValue
& GetValue(void);
304 virtual wxPropertyValidator
*GetValidator(void);
305 virtual wxString
& GetName(void);
306 virtual wxString
& GetRole(void);
307 virtual void SetValue(const wxPropertyValue
& val
);
308 virtual void SetValidator(wxPropertyValidator
*v
);
309 virtual void SetName(wxString
& nm
);
310 virtual void SetRole(wxString
& role
);
311 void operator=(const wxPropertyValue
& val
);
312 virtual inline void SetWindow(wxWindow
*win
) { propertyWindow
= win
; }
313 virtual inline wxWindow
*GetWindow(void) { return propertyWindow
; }
315 inline void Enable(bool en
) { enabled
= en
; }
316 inline bool IsEnabled(void) { return enabled
; }