]> git.saurik.com Git - wxWidgets.git/blob - include/wx/prop.h
no message
[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 #ifdef __GNUG__
16 #pragma interface "prop.h"
17 #endif
18
19 #include "wx/defs.h"
20 #include "wx/string.h"
21 #include "wx/hash.h"
22 #include "wx/dialog.h"
23 #include "wx/frame.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"
29
30 class wxWindow;
31 class wxProperty;
32 class wxPropertyValue;
33 class wxPropertySheet;
34 class wxPropertyView;
35 class wxPropertyValidator;
36 class wxPropertyValidatorRegistry;
37
38 #define wxPROPERTY_VERSION 2.0
39
40 // A storable sheet of values
41 class WXDLLEXPORT wxPropertySheet: public wxObject
42 {
43 DECLARE_DYNAMIC_CLASS(wxPropertySheet)
44 public:
45 wxPropertySheet(void);
46 ~wxPropertySheet(void);
47
48 // Add a property
49 virtual void AddProperty(wxProperty *property);
50
51 // Get property by name
52 virtual wxProperty *GetProperty(wxString name);
53
54 // Clear all properties
55 virtual void Clear(void);
56
57 virtual bool Save(ostream& str);
58 virtual bool Load(ostream& str);
59
60 virtual void UpdateAllViews(wxPropertyView *thisView = NULL);
61 inline virtual wxList& GetProperties(void) const { return (wxList&) m_properties; }
62
63 // Sets/clears the modified flag for each property value
64 virtual void SetAllModified(bool flag = TRUE);
65
66 protected:
67 wxObject* m_viewedObject;
68 wxList m_properties;
69 wxPropertyView* m_propertyView;
70
71 };
72
73
74 // Base class for property sheet views. There are currently two directly derived
75 // classes: wxPropertyListView, and wxPropertyFormView.
76 class WXDLLEXPORT wxPropertyView: public wxEvtHandler
77 {
78 DECLARE_DYNAMIC_CLASS(wxPropertyView)
79 public:
80 wxPropertyView(long flags = 0);
81 ~wxPropertyView(void);
82
83 // Associates and shows the view
84 virtual void ShowView(wxPropertySheet *WXUNUSED(propertySheet), wxWindow *WXUNUSED(panel)) {}
85
86 // Update this view of the viewed object, called e.g. by
87 // the object itself.
88 virtual bool OnUpdateView(void) {return FALSE;};
89
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)) {}
93
94 virtual void AddRegistry(wxPropertyValidatorRegistry *registry);
95 inline virtual wxList& GetRegistryList(void) const
96 { return (wxList&) m_validatorRegistryList; }
97
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; }
101
102 virtual void OnOk(void) {};
103 virtual void OnCancel(void) {};
104 virtual void OnHelp(void) {};
105
106 inline virtual bool OnClose(void) { return FALSE; }
107 inline long GetFlags(void) { return m_buttonFlags; }
108
109 protected:
110 long m_buttonFlags;
111 wxPropertySheet* m_propertySheet;
112 wxProperty* m_currentProperty;
113 wxList m_validatorRegistryList;
114 wxPropertyValidator* m_currentValidator;
115 };
116
117
118 class WXDLLEXPORT wxPropertyValidator: public wxEvtHandler
119 {
120 DECLARE_DYNAMIC_CLASS(wxPropertyValidator)
121 public:
122 wxPropertyValidator(long flags = 0);
123 ~wxPropertyValidator(void);
124
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; }
128
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);
137
138 protected:
139 long m_validatorFlags;
140 wxProperty* m_validatorProperty;
141 };
142
143
144 // extern wxPropertyValidator *wxDefaultPropertyValidator;
145
146 class WXDLLEXPORT wxPropertyValidatorRegistry: public wxHashTable
147 {
148 DECLARE_DYNAMIC_CLASS(wxPropertyValidatorRegistry)
149 public:
150 wxPropertyValidatorRegistry(void);
151 ~wxPropertyValidatorRegistry(void);
152
153 virtual void RegisterValidator(const wxString& roleName, wxPropertyValidator *validator);
154 virtual wxPropertyValidator *GetValidator(const wxString& roleName);
155 void ClearRegistry(void);
156 };
157
158 /*
159 * Property value class
160 */
161
162 typedef enum {
163 wxPropertyValueNull,
164 wxPropertyValueInteger,
165 wxPropertyValueReal,
166 wxPropertyValuebool,
167 wxPropertyValueString,
168 wxPropertyValueList,
169 wxPropertyValueIntegerPtr,
170 wxPropertyValueRealPtr,
171 wxPropertyValueboolPtr,
172 wxPropertyValueStringPtr
173 } wxPropertyValueType;
174
175 class WXDLLEXPORT wxPropertyValue: public wxObject
176 {
177 DECLARE_DYNAMIC_CLASS(wxPropertyValue)
178
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);
189 // Pointer versions
190 wxPropertyValue(char **val);
191 wxPropertyValue(long *val);
192 wxPropertyValue(bool *val);
193 wxPropertyValue(float *val);
194
195 ~wxPropertyValue(void);
196
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;
207
208 // Get nth arg of clause (starting from 1)
209 virtual wxPropertyValue *Arg(wxPropertyValueType type, int arg) const;
210
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;
215
216 virtual wxPropertyValue *NewCopy(void) const;
217 virtual void Copy(wxPropertyValue& copyFrom);
218
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
221
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);
226
227 // Get first expr in list
228 virtual inline wxPropertyValue *GetFirst(void) const
229 { return ((m_type == wxPropertyValueList) ? m_value.first : (wxPropertyValue*)NULL); }
230
231 // Get next expr if this is a node in a list
232 virtual inline wxPropertyValue *GetNext(void) const
233 { return m_next; }
234
235 // Get last expr in list
236 virtual inline wxPropertyValue *GetLast(void) const
237 { return ((m_type == wxPropertyValueList) ? m_last : (wxPropertyValue*)NULL); }
238
239 // Delete this node from the list
240 virtual void Delete(wxPropertyValue *node);
241
242 // Clear list
243 virtual void ClearList(void);
244
245 virtual inline void SetClientData(wxObject *data) { m_clientData = data; }
246 virtual inline wxObject *GetClientData(void) { return m_clientData; }
247
248 virtual wxString GetStringRepresentation(void);
249
250 inline void SetModified(bool flag = TRUE) { m_modifiedFlag = flag; }
251 inline bool GetModified(void) { return m_modifiedFlag; }
252
253 // Operators
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);
264
265 public:
266 wxObject* m_clientData;
267 wxPropertyValueType m_type;
268 bool m_modifiedFlag;
269
270 union {
271 long integer; // Also doubles as bool
272 char *string;
273 float real;
274 long *integerPtr;
275 bool *boolPtr;
276 char **stringPtr;
277 float *realPtr;
278 wxPropertyValue *first; // If is a list expr, points to the first node
279 } m_value;
280
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
283
284 };
285
286 /*
287 * Property class: contains a name and a value.
288 */
289
290 class WXDLLEXPORT wxProperty: public wxObject
291 {
292 DECLARE_DYNAMIC_CLASS(wxProperty)
293 protected:
294 bool m_enabled;
295 public:
296 wxPropertyValue m_value;
297 wxString m_name;
298 wxString m_propertyRole;
299 wxPropertyValidator* m_propertyValidator;
300 wxWindow* m_propertyWindow; // Usually a panel item, if anything
301
302 wxProperty(void);
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);
306 ~wxProperty(void);
307
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; }
319
320 inline void Enable(bool en) { m_enabled = en; }
321 inline bool IsEnabled(void) const { return m_enabled; }
322 };
323
324 #endif
325 // _WX_PROP_H_