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