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 wxPropertySheet
: public wxObject
43 DECLARE_DYNAMIC_CLASS(wxPropertySheet
)
45 wxPropertySheet(void);
46 ~wxPropertySheet(void);
49 virtual void AddProperty(wxProperty
*property
);
51 // Get property by name
52 virtual wxProperty
*GetProperty(wxString name
);
54 // Clear all properties
55 virtual void Clear(void);
57 virtual bool Save(ostream
& str
);
58 virtual bool Load(ostream
& str
);
60 virtual void UpdateAllViews(wxPropertyView
*thisView
= NULL
);
61 inline virtual wxList
& GetProperties(void) const { return (wxList
&) m_properties
; }
63 // Sets/clears the modified flag for each property value
64 virtual void SetAllModified(bool flag
= TRUE
);
67 wxObject
* m_viewedObject
;
69 wxPropertyView
* m_propertyView
;
74 // Base class for property sheet views. There are currently two directly derived
75 // classes: wxPropertyListView, and wxPropertyFormView.
76 class wxPropertyView
: public wxEvtHandler
78 DECLARE_DYNAMIC_CLASS(wxPropertyView
)
80 wxPropertyView(long flags
= 0);
81 ~wxPropertyView(void);
83 // Associates and shows the view
84 virtual void ShowView(wxPropertySheet
*WXUNUSED(propertySheet
), wxWindow
*WXUNUSED(panel
)) {}
86 // Update this view of the viewed object, called e.g. by
88 virtual bool OnUpdateView(void) {return FALSE
;};
90 // Override this to do something as soon as the property changed,
91 // if the view and validators support it.
92 virtual void OnPropertyChanged(wxProperty
*WXUNUSED(property
)) {}
94 virtual void AddRegistry(wxPropertyValidatorRegistry
*registry
);
95 inline virtual wxList
& GetRegistryList(void) const
96 { return (wxList
&) m_validatorRegistryList
; }
98 virtual wxPropertyValidator
*FindPropertyValidator(wxProperty
*property
);
99 inline virtual void SetPropertySheet(wxPropertySheet
*sheet
) { m_propertySheet
= sheet
; }
100 inline virtual wxPropertySheet
*GetPropertySheet(void) const { return m_propertySheet
; }
102 virtual void OnOk(void) {};
103 virtual void OnCancel(void) {};
104 virtual void OnHelp(void) {};
106 inline virtual bool OnClose(void) { return FALSE
; }
107 inline long GetFlags(void) { return m_buttonFlags
; }
111 wxPropertySheet
* m_propertySheet
;
112 wxProperty
* m_currentProperty
;
113 wxList m_validatorRegistryList
;
114 wxPropertyValidator
* m_currentValidator
;
118 class wxPropertyValidator
: public wxEvtHandler
120 DECLARE_DYNAMIC_CLASS(wxPropertyValidator
)
122 wxPropertyValidator(long flags
= 0);
123 ~wxPropertyValidator(void);
125 inline long GetFlags(void) const { return m_validatorFlags
; }
126 inline void SetValidatorProperty(wxProperty
*prop
) { m_validatorProperty
= prop
; }
127 inline wxProperty
*GetValidatorProperty(void) const { return m_validatorProperty
; }
129 virtual bool StringToFloat (char *s
, float *number
);
130 virtual bool StringToDouble (char *s
, double *number
);
131 virtual bool StringToInt (char *s
, int *number
);
132 virtual bool StringToLong (char *s
, long *number
);
133 virtual char *FloatToString (float number
);
134 virtual char *DoubleToString (double number
);
135 virtual char *IntToString (int number
);
136 virtual char *LongToString (long number
);
139 long m_validatorFlags
;
140 wxProperty
* m_validatorProperty
;
144 // extern wxPropertyValidator *wxDefaultPropertyValidator;
146 class wxPropertyValidatorRegistry
: public wxHashTable
148 DECLARE_DYNAMIC_CLASS(wxPropertyValidatorRegistry
)
150 wxPropertyValidatorRegistry(void);
151 ~wxPropertyValidatorRegistry(void);
153 virtual void RegisterValidator(const wxString
& roleName
, wxPropertyValidator
*validator
);
154 virtual wxPropertyValidator
*GetValidator(const wxString
& roleName
);
155 void ClearRegistry(void);
159 * Property value class
164 wxPropertyValueInteger
,
167 wxPropertyValueString
,
169 wxPropertyValueIntegerPtr
,
170 wxPropertyValueRealPtr
,
171 wxPropertyValueboolPtr
,
172 wxPropertyValueStringPtr
173 } wxPropertyValueType
;
175 class wxPropertyValue
: public wxObject
177 DECLARE_DYNAMIC_CLASS(wxPropertyValue
)
179 wxPropertyValue(void); // Unknown type
180 wxPropertyValue(const wxPropertyValue
& copyFrom
); // Copy constructor
181 wxPropertyValue(const char *val
);
182 wxPropertyValue(const wxString
& val
);
183 wxPropertyValue(long val
);
184 wxPropertyValue(bool val
);
185 wxPropertyValue(float val
);
186 wxPropertyValue(double the_real
);
187 wxPropertyValue(wxList
*val
);
188 wxPropertyValue(wxStringList
*val
);
190 wxPropertyValue(char **val
);
191 wxPropertyValue(long *val
);
192 wxPropertyValue(bool *val
);
193 wxPropertyValue(float *val
);
195 ~wxPropertyValue(void);
197 virtual inline wxPropertyValueType
Type(void) const { return m_type
; }
198 virtual inline void SetType(wxPropertyValueType typ
) { m_type
= typ
; }
199 virtual long IntegerValue(void) const;
200 virtual float RealValue(void) const;
201 virtual bool BoolValue(void) const;
202 virtual char *StringValue(void) const;
203 virtual long *IntegerValuePtr(void) const;
204 virtual float *RealValuePtr(void) const;
205 virtual bool *BoolValuePtr(void) const;
206 virtual char **StringValuePtr(void) const;
208 // Get nth arg of clause (starting from 1)
209 virtual wxPropertyValue
*Arg(wxPropertyValueType type
, int arg
) const;
211 // Return nth argument of a list expression (starting from zero)
212 virtual wxPropertyValue
*Nth(int arg
) const;
213 // Returns the number of elements in a list expression
214 virtual int Number(void) const;
216 virtual wxPropertyValue
*NewCopy(void) const;
217 virtual void Copy(wxPropertyValue
& copyFrom
);
219 virtual void WritePropertyClause(ostream
& stream
); // Write this expression as a top-level clause
220 virtual void WritePropertyType(ostream
& stream
); // Write as any other subexpression
222 // Append an expression to a list
223 virtual void Append(wxPropertyValue
*expr
);
224 // Insert at beginning of list
225 virtual void Insert(wxPropertyValue
*expr
);
227 // Get first expr in list
228 virtual inline wxPropertyValue
*GetFirst(void) const
229 { return ((m_type
== wxPropertyValueList
) ? m_value
.first
: (wxPropertyValue
*)NULL
); }
231 // Get next expr if this is a node in a list
232 virtual inline wxPropertyValue
*GetNext(void) const
235 // Get last expr in list
236 virtual inline wxPropertyValue
*GetLast(void) const
237 { return ((m_type
== wxPropertyValueList
) ? m_last
: (wxPropertyValue
*)NULL
); }
239 // Delete this node from the list
240 virtual void Delete(wxPropertyValue
*node
);
243 virtual void ClearList(void);
245 virtual inline void SetClientData(wxObject
*data
) { m_clientData
= data
; }
246 virtual inline wxObject
*GetClientData(void) { return m_clientData
; }
248 virtual wxString
GetStringRepresentation(void);
250 inline void SetModified(bool flag
= TRUE
) { m_modifiedFlag
= flag
; }
251 inline bool GetModified(void) { return m_modifiedFlag
; }
254 void operator=(const wxPropertyValue
& val
);
255 // void operator=(const char *val);
256 void operator=(const wxString
& val
);
257 void operator=(const long val
);
258 void operator=(const bool val
);
259 void operator=(const float val
);
260 void operator=(const char **val
);
261 void operator=(const long *val
);
262 void operator=(const bool *val
);
263 void operator=(const float *val
);
266 wxObject
* m_clientData
;
267 wxPropertyValueType m_type
;
271 long integer
; // Also doubles as bool
278 wxPropertyValue
*first
; // If is a list expr, points to the first node
281 wxPropertyValue
* m_next
; // If this is a node in a list, points to the next node
282 wxPropertyValue
* m_last
; // If is a list expr, points to the last node
287 * Property class: contains a name and a value.
290 class wxProperty
: public wxObject
292 DECLARE_DYNAMIC_CLASS(wxProperty
)
296 wxPropertyValue m_value
;
298 wxString m_propertyRole
;
299 wxPropertyValidator
* m_propertyValidator
;
300 wxWindow
* m_propertyWindow
; // Usually a panel item, if anything
303 wxProperty(wxProperty
& copyFrom
);
304 wxProperty(wxString name
, wxString role
, wxPropertyValidator
*ed
= NULL
);
305 wxProperty(wxString name
, const wxPropertyValue
& val
, wxString role
, wxPropertyValidator
*ed
= NULL
);
308 virtual wxPropertyValue
& GetValue(void) const;
309 virtual wxPropertyValidator
*GetValidator(void) const;
310 virtual wxString
& GetName(void) const;
311 virtual wxString
& GetRole(void) const;
312 virtual void SetValue(const wxPropertyValue
& val
);
313 virtual void SetValidator(wxPropertyValidator
*v
);
314 virtual void SetName(wxString
& nm
);
315 virtual void SetRole(wxString
& role
);
316 void operator=(const wxPropertyValue
& val
);
317 virtual inline void SetWindow(wxWindow
*win
) { m_propertyWindow
= win
; }
318 virtual inline wxWindow
*GetWindow(void) const { return m_propertyWindow
; }
320 inline void Enable(bool en
) { m_enabled
= en
; }
321 inline bool IsEnabled(void) const { return m_enabled
; }