]> git.saurik.com Git - wxWidgets.git/blob - include/wx/prop.h
fixed memory leak
[wxWidgets.git] / include / wx / prop.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: prop.h
3 // Purpose: Property sheet classes
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_PROP_H_
13 #define _WX_PROP_H_
14
15 #if defined(__GNUG__) && !defined(__APPLE__)
16 #pragma interface "prop.h"
17 #endif
18
19 #if wxUSE_PROPSHEET
20
21 #include "wx/defs.h"
22 #include "wx/string.h"
23 #include "wx/hash.h"
24 #include "wx/dialog.h"
25 #include "wx/frame.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"
31 #include "wx/sizer.h"
32
33 class wxWindow;
34 class wxProperty;
35 class wxPropertyValue;
36 class wxPropertySheet;
37 class wxPropertyView;
38 class wxPropertyValidator;
39 class wxPropertyValidatorRegistry;
40
41 #define wxPROPERTY_VERSION 2.0
42
43 // A storable sheet of values
44 class WXDLLEXPORT wxPropertySheet: public wxObject
45 {
46 public:
47 wxPropertySheet(const wxString& name = wxT(""));
48 ~wxPropertySheet();
49
50 // Set the name of the sheet
51 inline virtual void SetName(const wxString& name) { m_name=name; }
52 inline virtual wxString GetName() const { return m_name; }
53
54 // Does this sheet contain a property with this name
55 virtual bool HasProperty(const wxString& name) const;
56
57 // Set property name to value
58 virtual bool SetProperty(const wxString& name, const wxPropertyValue& value);
59
60 // Remove property from sheet by name, deleting it
61 virtual void RemoveProperty(const wxString& name);
62
63 // Get the name of the sheet
64 // Add a property
65 virtual void AddProperty(wxProperty *property);
66
67 // Get property by name
68 virtual wxProperty *GetProperty(const wxString& name) const;
69
70 // Clear all properties
71 virtual void Clear();
72
73 virtual void UpdateAllViews(wxPropertyView *thisView = NULL);
74 inline virtual wxList& GetProperties() const { return (wxList&) m_properties; }
75
76 // Sets/clears the modified flag for each property value
77 virtual void SetAllModified(bool flag = TRUE);
78
79 protected:
80 wxObject* m_viewedObject;
81 wxList m_properties;
82 wxPropertyView* m_propertyView;
83 wxString m_name;
84
85 private:
86 DECLARE_DYNAMIC_CLASS(wxPropertySheet)
87 };
88
89
90 // Base class for property sheet views. There are currently two directly derived
91 // classes: wxPropertyListView, and wxPropertyFormView.
92 class WXDLLEXPORT wxPropertyView: public wxEvtHandler
93 {
94 public:
95 wxPropertyView(long flags = 0);
96 ~wxPropertyView();
97
98 // Associates and shows the view
99 virtual void ShowView(wxPropertySheet *WXUNUSED(propertySheet), wxWindow *WXUNUSED(panel)) {}
100
101 // Update this view of the viewed object, called e.g. by
102 // the object itself.
103 virtual bool OnUpdateView() {return FALSE;};
104
105 // Override this to do something as soon as the property changed,
106 // if the view and validators support it.
107 virtual void OnPropertyChanged(wxProperty *WXUNUSED(property)) {}
108
109 virtual void AddRegistry(wxPropertyValidatorRegistry *registry);
110 inline virtual wxList& GetRegistryList() const
111 { return (wxList&) m_validatorRegistryList; }
112
113 virtual wxPropertyValidator *FindPropertyValidator(wxProperty *property);
114 inline virtual void SetPropertySheet(wxPropertySheet *sheet) { m_propertySheet = sheet; }
115 inline virtual wxPropertySheet *GetPropertySheet() const { return m_propertySheet; }
116
117 inline virtual bool OnClose() { return FALSE; }
118 inline long GetFlags(void) { return m_buttonFlags; }
119
120 protected:
121 long m_buttonFlags;
122 wxPropertySheet* m_propertySheet;
123 wxProperty* m_currentProperty;
124 wxList m_validatorRegistryList;
125 wxPropertyValidator* m_currentValidator;
126
127 private:
128 DECLARE_DYNAMIC_CLASS(wxPropertyView)
129 };
130
131
132 class WXDLLEXPORT wxPropertyValidator: public wxEvtHandler
133 {
134 public:
135 wxPropertyValidator(long flags = 0);
136 ~wxPropertyValidator();
137
138 inline long GetFlags() const { return m_validatorFlags; }
139 inline void SetValidatorProperty(wxProperty *prop) { m_validatorProperty = prop; }
140 inline wxProperty *GetValidatorProperty(void) const { return m_validatorProperty; }
141
142 virtual bool StringToFloat (wxChar *s, float *number);
143 virtual bool StringToDouble (wxChar *s, double *number);
144 virtual bool StringToInt (wxChar *s, int *number);
145 virtual bool StringToLong (wxChar *s, long *number);
146 virtual wxChar *FloatToString (float number);
147 virtual wxChar *DoubleToString (double number);
148 virtual wxChar *IntToString (int number);
149 virtual wxChar *LongToString (long number);
150
151 protected:
152 long m_validatorFlags;
153 wxProperty* m_validatorProperty;
154
155 private:
156 DECLARE_DYNAMIC_CLASS(wxPropertyValidator)
157 };
158
159
160 // extern wxPropertyValidator *wxDefaultPropertyValidator;
161
162 class WXDLLEXPORT wxPropertyValidatorRegistry: public wxHashTable
163 {
164 public:
165 wxPropertyValidatorRegistry();
166 ~wxPropertyValidatorRegistry();
167
168 virtual void RegisterValidator(const wxString& roleName, wxPropertyValidator *validator);
169 virtual wxPropertyValidator *GetValidator(const wxString& roleName);
170 void ClearRegistry();
171
172 private:
173 DECLARE_DYNAMIC_CLASS(wxPropertyValidatorRegistry)
174 };
175
176 /*
177 * Property value class
178 */
179
180 typedef enum {
181 wxPropertyValueNull,
182 wxPropertyValueInteger,
183 wxPropertyValueReal,
184 wxPropertyValuebool,
185 wxPropertyValueString,
186 wxPropertyValueList,
187 wxPropertyValueIntegerPtr,
188 wxPropertyValueRealPtr,
189 wxPropertyValueboolPtr,
190 wxPropertyValueStringPtr
191 } wxPropertyValueType;
192
193 class WXDLLEXPORT wxPropertyValue: public wxObject
194 {
195 DECLARE_DYNAMIC_CLASS(wxPropertyValue)
196
197 wxPropertyValue(void); // Unknown type
198 wxPropertyValue(const wxPropertyValue& copyFrom); // Copy constructor
199 wxPropertyValue(const wxChar *val);
200 wxPropertyValue(const wxString& val);
201 wxPropertyValue(long val);
202 wxPropertyValue(bool val);
203 wxPropertyValue(float val);
204 wxPropertyValue(double the_real);
205 wxPropertyValue(wxList *val);
206 wxPropertyValue(wxStringList *val);
207 // Pointer versions
208 wxPropertyValue(wxChar **val);
209 wxPropertyValue(long *val);
210 wxPropertyValue(bool *val);
211 wxPropertyValue(float *val);
212
213 ~wxPropertyValue(void);
214
215 virtual inline wxPropertyValueType Type(void) const { return m_type; }
216 virtual inline void SetType(wxPropertyValueType typ) { m_type = typ; }
217 virtual long IntegerValue(void) const;
218 virtual float RealValue(void) const;
219 virtual bool BoolValue(void) const;
220 virtual wxChar *StringValue(void) const;
221 virtual long *IntegerValuePtr(void) const;
222 virtual float *RealValuePtr(void) const;
223 virtual bool *BoolValuePtr(void) const;
224 virtual wxChar **StringValuePtr(void) const;
225
226 // Get nth arg of clause (starting from 1)
227 virtual wxPropertyValue *Arg(wxPropertyValueType type, int arg) const;
228
229 // Return nth argument of a list expression (starting from zero)
230 virtual wxPropertyValue *Nth(int arg) const;
231 // Returns the number of elements in a list expression
232 virtual int Number(void) const;
233
234 virtual wxPropertyValue *NewCopy(void) const;
235 virtual void Copy(wxPropertyValue& copyFrom);
236
237 virtual void WritePropertyClause(wxString &stream); // Write this expression as a top-level clause
238 virtual void WritePropertyType(wxString &stream); // Write as any other subexpression
239
240 // Append an expression to a list
241 virtual void Append(wxPropertyValue *expr);
242 // Insert at beginning of list
243 virtual void Insert(wxPropertyValue *expr);
244
245 // Get first expr in list
246 virtual inline wxPropertyValue *GetFirst(void) const
247 { return ((m_type == wxPropertyValueList) ? m_value.first : (wxPropertyValue*)NULL); }
248
249 // Get next expr if this is a node in a list
250 virtual inline wxPropertyValue *GetNext(void) const
251 { return m_next; }
252
253 // Get last expr in list
254 virtual inline wxPropertyValue *GetLast(void) const
255 { return ((m_type == wxPropertyValueList) ? m_last : (wxPropertyValue*)NULL); }
256
257 // Delete this node from the list
258 virtual void Delete(wxPropertyValue *node);
259
260 // Clear list
261 virtual void ClearList(void);
262
263 virtual inline void SetClientData(wxObject *data) { m_clientData = data; }
264 virtual inline wxObject *GetClientData(void) { return m_clientData; }
265
266 virtual wxString GetStringRepresentation(void);
267
268 inline void SetModified(bool flag = TRUE) { m_modifiedFlag = flag; }
269 inline bool GetModified(void) { return m_modifiedFlag; }
270
271 // Operators
272 void operator=(const wxPropertyValue& val);
273 // void operator=(const char *val);
274 void operator=(const wxString& val);
275 void operator=(const long val);
276 void operator=(const bool val);
277 void operator=(const float val);
278 void operator=(const wxChar **val);
279 void operator=(const long *val);
280 void operator=(const bool *val);
281 void operator=(const float *val);
282
283 public:
284 wxObject* m_clientData;
285 wxPropertyValueType m_type;
286 bool m_modifiedFlag;
287
288 union {
289 long integer; // Also doubles as bool
290 wxChar *string;
291 float real;
292 long *integerPtr;
293 bool *boolPtr;
294 wxChar **stringPtr;
295 float *realPtr;
296 wxPropertyValue *first; // If is a list expr, points to the first node
297 } m_value;
298
299 wxPropertyValue* m_next; // If this is a node in a list, points to the next node
300 wxPropertyValue* m_last; // If is a list expr, points to the last node
301
302 };
303
304 /*
305 * Property class: contains a name and a value.
306 */
307
308 class WXDLLEXPORT wxProperty: public wxObject
309 {
310 DECLARE_DYNAMIC_CLASS(wxProperty)
311 protected:
312 bool m_enabled;
313 public:
314 wxPropertyValue m_value;
315 wxString m_name;
316 wxString m_propertyRole;
317 wxPropertyValidator* m_propertyValidator;
318 wxWindow* m_propertyWindow; // Usually a panel item, if anything
319
320 wxProperty(void);
321 wxProperty(wxProperty& copyFrom);
322 wxProperty(wxString name, wxString role, wxPropertyValidator *ed = NULL);
323 wxProperty(wxString name, const wxPropertyValue& val, wxString role, wxPropertyValidator *ed = NULL);
324 ~wxProperty(void);
325
326 virtual wxPropertyValue& GetValue(void) const;
327 virtual wxPropertyValidator *GetValidator(void) const;
328 virtual wxString& GetName(void) const;
329 virtual wxString& GetRole(void) const;
330 virtual void SetValue(const wxPropertyValue& val);
331 virtual void SetValidator(wxPropertyValidator *v);
332 virtual void SetName(wxString& nm);
333 virtual void SetRole(wxString& role);
334 void operator=(const wxPropertyValue& val);
335 virtual inline void SetWindow(wxWindow *win) { m_propertyWindow = win; }
336 virtual inline wxWindow *GetWindow(void) const { return m_propertyWindow; }
337
338 inline void Enable(bool en) { m_enabled = en; }
339 inline bool IsEnabled(void) const { return m_enabled; }
340 };
341
342 #endif
343 // wxUSE_PROPSHEET
344
345 #endif
346 // _WX_PROP_H_