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