]> git.saurik.com Git - wxWidgets.git/blame - include/wx/prop.h
changed copyright to SciTech one
[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"
42b4e99e 29#include "wx/sizer.h"
e3a43801
JS
30
31class wxWindow;
32class wxProperty;
33class wxPropertyValue;
34class wxPropertySheet;
35class wxPropertyView;
36class wxPropertyValidator;
37class wxPropertyValidatorRegistry;
38
39#define wxPROPERTY_VERSION 2.0
40
41// A storable sheet of values
4040a396 42class WXDLLEXPORT wxPropertySheet: public wxObject
e3a43801
JS
43{
44 DECLARE_DYNAMIC_CLASS(wxPropertySheet)
45 public:
cba2db0c 46 wxPropertySheet(const wxString& name = "");
e3a43801
JS
47 ~wxPropertySheet(void);
48
f3a65071 49 // Set the name of the sheet
cba2db0c
JS
50 inline virtual void SetName(const wxString& name) { m_name=name; }
51 inline virtual wxString GetName() const { return m_name; }
f3a65071 52 // Does this sheet contain a property with this name
cba2db0c 53 virtual bool HasProperty(const wxString& name) const;
f3a65071
JS
54
55 // Set property name to value
cba2db0c 56 virtual bool SetProperty(const wxString& name, const wxPropertyValue& value);
f3a65071
JS
57
58 // Remove property from sheet by name, deleting it
cba2db0c 59 virtual void RemoveProperty(const wxString& name);
f3a65071
JS
60
61 // Get the name of the sheet
e3a43801
JS
62 // Add a property
63 virtual void AddProperty(wxProperty *property);
64
65 // Get property by name
cba2db0c 66 virtual wxProperty *GetProperty(const wxString& name) const;
e3a43801
JS
67
68 // Clear all properties
69 virtual void Clear(void);
70
e3a43801
JS
71 virtual void UpdateAllViews(wxPropertyView *thisView = NULL);
72 inline virtual wxList& GetProperties(void) const { return (wxList&) m_properties; }
73
74 // Sets/clears the modified flag for each property value
75 virtual void SetAllModified(bool flag = TRUE);
76
77 protected:
78 wxObject* m_viewedObject;
79 wxList m_properties;
80 wxPropertyView* m_propertyView;
f3a65071 81 wxString m_name;
e3a43801
JS
82};
83
84
85// Base class for property sheet views. There are currently two directly derived
86// classes: wxPropertyListView, and wxPropertyFormView.
4040a396 87class WXDLLEXPORT wxPropertyView: public wxEvtHandler
e3a43801
JS
88{
89 DECLARE_DYNAMIC_CLASS(wxPropertyView)
90 public:
91 wxPropertyView(long flags = 0);
92 ~wxPropertyView(void);
93
94 // Associates and shows the view
95 virtual void ShowView(wxPropertySheet *WXUNUSED(propertySheet), wxWindow *WXUNUSED(panel)) {}
96
97 // Update this view of the viewed object, called e.g. by
98 // the object itself.
99 virtual bool OnUpdateView(void) {return FALSE;};
100
101 // Override this to do something as soon as the property changed,
102 // if the view and validators support it.
103 virtual void OnPropertyChanged(wxProperty *WXUNUSED(property)) {}
104
105 virtual void AddRegistry(wxPropertyValidatorRegistry *registry);
106 inline virtual wxList& GetRegistryList(void) const
107 { return (wxList&) m_validatorRegistryList; }
108
109 virtual wxPropertyValidator *FindPropertyValidator(wxProperty *property);
110 inline virtual void SetPropertySheet(wxPropertySheet *sheet) { m_propertySheet = sheet; }
111 inline virtual wxPropertySheet *GetPropertySheet(void) const { return m_propertySheet; }
112
33b64e6f 113/*
e3a43801
JS
114 virtual void OnOk(void) {};
115 virtual void OnCancel(void) {};
116 virtual void OnHelp(void) {};
33b64e6f 117*/
e3a43801
JS
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
4040a396 131class WXDLLEXPORT wxPropertyValidator: public wxEvtHandler
e3a43801
JS
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
83a21afb
OK
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);
e3a43801
JS
150
151 protected:
152 long m_validatorFlags;
153 wxProperty* m_validatorProperty;
154};
155
156
157// extern wxPropertyValidator *wxDefaultPropertyValidator;
158
4040a396 159class WXDLLEXPORT wxPropertyValidatorRegistry: public wxHashTable
e3a43801
JS
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
175typedef enum {
176 wxPropertyValueNull,
177 wxPropertyValueInteger,
178 wxPropertyValueReal,
179 wxPropertyValuebool,
180 wxPropertyValueString,
181 wxPropertyValueList,
182 wxPropertyValueIntegerPtr,
183 wxPropertyValueRealPtr,
184 wxPropertyValueboolPtr,
185 wxPropertyValueStringPtr
186} wxPropertyValueType;
187
4040a396 188class WXDLLEXPORT wxPropertyValue: public wxObject
e3a43801
JS
189{
190 DECLARE_DYNAMIC_CLASS(wxPropertyValue)
191
192 wxPropertyValue(void); // Unknown type
193 wxPropertyValue(const wxPropertyValue& copyFrom); // Copy constructor
83a21afb 194 wxPropertyValue(const wxChar *val);
e3a43801
JS
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
83a21afb 203 wxPropertyValue(wxChar **val);
e3a43801
JS
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;
83a21afb 215 virtual wxChar *StringValue(void) const;
e3a43801
JS
216 virtual long *IntegerValuePtr(void) const;
217 virtual float *RealValuePtr(void) const;
218 virtual bool *BoolValuePtr(void) const;
83a21afb 219 virtual wxChar **StringValuePtr(void) const;
e3a43801
JS
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
c693edf3
RR
232 virtual void WritePropertyClause(wxString &stream); // Write this expression as a top-level clause
233 virtual void WritePropertyType(wxString &stream); // Write as any other subexpression
e3a43801
JS
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);
83a21afb 273 void operator=(const wxChar **val);
e3a43801
JS
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
83a21afb 285 wxChar *string;
e3a43801
JS
286 float real;
287 long *integerPtr;
288 bool *boolPtr;
83a21afb 289 wxChar **stringPtr;
e3a43801
JS
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
4040a396 303class WXDLLEXPORT wxProperty: public wxObject
e3a43801
JS
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_