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