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 bool Save(ostream
& str
);
71 virtual bool Load(ostream
& str
);
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 (char *s
, float *number
);
145 virtual bool StringToDouble (char *s
, double *number
);
146 virtual bool StringToInt (char *s
, int *number
);
147 virtual bool StringToLong (char *s
, long *number
);
148 virtual char *FloatToString (float number
);
149 virtual char *DoubleToString (double number
);
150 virtual char *IntToString (int number
);
151 virtual char *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 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) 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 char *StringValue(void) const;
218 virtual long *IntegerValuePtr(void) const;
219 virtual float *RealValuePtr(void) const;
220 virtual bool *BoolValuePtr(void) const;
221 virtual char **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(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) 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 char **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
; }