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