]> git.saurik.com Git - wxWidgets.git/blame - include/wx/prop.h
(hopefully) fixed make install
[wxWidgets.git] / include / wx / prop.h
CommitLineData
e3a43801
JS
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
30class wxWindow;
31class wxProperty;
32class wxPropertyValue;
33class wxPropertySheet;
34class wxPropertyView;
35class wxPropertyValidator;
36class wxPropertyValidatorRegistry;
37
38#define wxPROPERTY_VERSION 2.0
39
40// A storable sheet of values
4040a396 41class WXDLLEXPORT wxPropertySheet: public wxObject
e3a43801
JS
42{
43 DECLARE_DYNAMIC_CLASS(wxPropertySheet)
44 public:
cba2db0c 45 wxPropertySheet(const wxString& name = "");
e3a43801
JS
46 ~wxPropertySheet(void);
47
f3a65071 48 // Set the name of the sheet
cba2db0c
JS
49 inline virtual void SetName(const wxString& name) { m_name=name; }
50 inline virtual wxString GetName() const { return m_name; }
f3a65071 51 // Does this sheet contain a property with this name
cba2db0c 52 virtual bool HasProperty(const wxString& name) const;
f3a65071
JS
53
54 // Set property name to value
cba2db0c 55 virtual bool SetProperty(const wxString& name, const wxPropertyValue& value);
f3a65071
JS
56
57 // Remove property from sheet by name, deleting it
cba2db0c 58 virtual void RemoveProperty(const wxString& name);
f3a65071
JS
59
60 // Get the name of the sheet
e3a43801
JS
61 // Add a property
62 virtual void AddProperty(wxProperty *property);
63
64 // Get property by name
cba2db0c 65 virtual wxProperty *GetProperty(const wxString& name) const;
e3a43801
JS
66
67 // Clear all properties
68 virtual void Clear(void);
69
e3a43801
JS
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;
f3a65071 80 wxString m_name;
e3a43801
JS
81};
82
83
84// Base class for property sheet views. There are currently two directly derived
85// classes: wxPropertyListView, and wxPropertyFormView.
4040a396 86class WXDLLEXPORT wxPropertyView: public wxEvtHandler
e3a43801
JS
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
33b64e6f 112/*
e3a43801
JS
113 virtual void OnOk(void) {};
114 virtual void OnCancel(void) {};
115 virtual void OnHelp(void) {};
33b64e6f 116*/
e3a43801
JS
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
4040a396 130class WXDLLEXPORT wxPropertyValidator: public wxEvtHandler
e3a43801
JS
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
83a21afb
OK
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);
e3a43801
JS
149
150 protected:
151 long m_validatorFlags;
152 wxProperty* m_validatorProperty;
153};
154
155
156// extern wxPropertyValidator *wxDefaultPropertyValidator;
157
4040a396 158class WXDLLEXPORT wxPropertyValidatorRegistry: public wxHashTable
e3a43801
JS
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
174typedef enum {
175 wxPropertyValueNull,
176 wxPropertyValueInteger,
177 wxPropertyValueReal,
178 wxPropertyValuebool,
179 wxPropertyValueString,
180 wxPropertyValueList,
181 wxPropertyValueIntegerPtr,
182 wxPropertyValueRealPtr,
183 wxPropertyValueboolPtr,
184 wxPropertyValueStringPtr
185} wxPropertyValueType;
186
4040a396 187class WXDLLEXPORT wxPropertyValue: public wxObject
e3a43801
JS
188{
189 DECLARE_DYNAMIC_CLASS(wxPropertyValue)
190
191 wxPropertyValue(void); // Unknown type
192 wxPropertyValue(const wxPropertyValue& copyFrom); // Copy constructor
83a21afb 193 wxPropertyValue(const wxChar *val);
e3a43801
JS
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
83a21afb 202 wxPropertyValue(wxChar **val);
e3a43801
JS
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;
83a21afb 214 virtual wxChar *StringValue(void) const;
e3a43801
JS
215 virtual long *IntegerValuePtr(void) const;
216 virtual float *RealValuePtr(void) const;
217 virtual bool *BoolValuePtr(void) const;
83a21afb 218 virtual wxChar **StringValuePtr(void) const;
e3a43801
JS
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
c693edf3
RR
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
e3a43801
JS
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);
83a21afb 272 void operator=(const wxChar **val);
e3a43801
JS
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
83a21afb 284 wxChar *string;
e3a43801
JS
285 float real;
286 long *integerPtr;
287 bool *boolPtr;
83a21afb 288 wxChar **stringPtr;
e3a43801
JS
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
4040a396 302class WXDLLEXPORT wxProperty: public wxObject
e3a43801
JS
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_