]>
Commit | Line | Data |
---|---|---|
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 | #if wxUSE_PROPSHEET | |
20 | ||
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" | |
31 | #include "wx/sizer.h" | |
32 | ||
33 | class wxWindow; | |
34 | class wxProperty; | |
35 | class wxPropertyValue; | |
36 | class wxPropertySheet; | |
37 | class wxPropertyView; | |
38 | class wxPropertyValidator; | |
39 | class wxPropertyValidatorRegistry; | |
40 | ||
41 | #define wxPROPERTY_VERSION 2.0 | |
42 | ||
43 | // A storable sheet of values | |
44 | class WXDLLEXPORT wxPropertySheet: public wxObject | |
45 | { | |
46 | DECLARE_DYNAMIC_CLASS(wxPropertySheet) | |
47 | public: | |
48 | wxPropertySheet(const wxString& name = ""); | |
49 | ~wxPropertySheet(void); | |
50 | ||
51 | // Set the name of the sheet | |
52 | inline virtual void SetName(const wxString& name) { m_name=name; } | |
53 | inline virtual wxString GetName() const { return m_name; } | |
54 | // Does this sheet contain a property with this name | |
55 | virtual bool HasProperty(const wxString& name) const; | |
56 | ||
57 | // Set property name to value | |
58 | virtual bool SetProperty(const wxString& name, const wxPropertyValue& value); | |
59 | ||
60 | // Remove property from sheet by name, deleting it | |
61 | virtual void RemoveProperty(const wxString& name); | |
62 | ||
63 | // Get the name of the sheet | |
64 | // Add a property | |
65 | virtual void AddProperty(wxProperty *property); | |
66 | ||
67 | // Get property by name | |
68 | virtual wxProperty *GetProperty(const wxString& name) const; | |
69 | ||
70 | // Clear all properties | |
71 | virtual void Clear(void); | |
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 | /* | |
116 | virtual void OnOk(void) {}; | |
117 | virtual void OnCancel(void) {}; | |
118 | virtual void OnHelp(void) {}; | |
119 | */ | |
120 | ||
121 | inline virtual bool OnClose(void) { return FALSE; } | |
122 | inline long GetFlags(void) { return m_buttonFlags; } | |
123 | ||
124 | protected: | |
125 | long m_buttonFlags; | |
126 | wxPropertySheet* m_propertySheet; | |
127 | wxProperty* m_currentProperty; | |
128 | wxList m_validatorRegistryList; | |
129 | wxPropertyValidator* m_currentValidator; | |
130 | }; | |
131 | ||
132 | ||
133 | class WXDLLEXPORT wxPropertyValidator: public wxEvtHandler | |
134 | { | |
135 | DECLARE_DYNAMIC_CLASS(wxPropertyValidator) | |
136 | public: | |
137 | wxPropertyValidator(long flags = 0); | |
138 | ~wxPropertyValidator(void); | |
139 | ||
140 | inline long GetFlags(void) const { return m_validatorFlags; } | |
141 | inline void SetValidatorProperty(wxProperty *prop) { m_validatorProperty = prop; } | |
142 | inline wxProperty *GetValidatorProperty(void) const { return m_validatorProperty; } | |
143 | ||
144 | virtual bool StringToFloat (wxChar *s, float *number); | |
145 | virtual bool StringToDouble (wxChar *s, double *number); | |
146 | virtual bool StringToInt (wxChar *s, int *number); | |
147 | virtual bool StringToLong (wxChar *s, long *number); | |
148 | virtual wxChar *FloatToString (float number); | |
149 | virtual wxChar *DoubleToString (double number); | |
150 | virtual wxChar *IntToString (int number); | |
151 | virtual wxChar *LongToString (long number); | |
152 | ||
153 | protected: | |
154 | long m_validatorFlags; | |
155 | wxProperty* m_validatorProperty; | |
156 | }; | |
157 | ||
158 | ||
159 | // extern wxPropertyValidator *wxDefaultPropertyValidator; | |
160 | ||
161 | class WXDLLEXPORT wxPropertyValidatorRegistry: public wxHashTable | |
162 | { | |
163 | DECLARE_DYNAMIC_CLASS(wxPropertyValidatorRegistry) | |
164 | public: | |
165 | wxPropertyValidatorRegistry(void); | |
166 | ~wxPropertyValidatorRegistry(void); | |
167 | ||
168 | virtual void RegisterValidator(const wxString& roleName, wxPropertyValidator *validator); | |
169 | virtual wxPropertyValidator *GetValidator(const wxString& roleName); | |
170 | void ClearRegistry(void); | |
171 | }; | |
172 | ||
173 | /* | |
174 | * Property value class | |
175 | */ | |
176 | ||
177 | typedef enum { | |
178 | wxPropertyValueNull, | |
179 | wxPropertyValueInteger, | |
180 | wxPropertyValueReal, | |
181 | wxPropertyValuebool, | |
182 | wxPropertyValueString, | |
183 | wxPropertyValueList, | |
184 | wxPropertyValueIntegerPtr, | |
185 | wxPropertyValueRealPtr, | |
186 | wxPropertyValueboolPtr, | |
187 | wxPropertyValueStringPtr | |
188 | } wxPropertyValueType; | |
189 | ||
190 | class WXDLLEXPORT wxPropertyValue: public wxObject | |
191 | { | |
192 | DECLARE_DYNAMIC_CLASS(wxPropertyValue) | |
193 | ||
194 | wxPropertyValue(void); // Unknown type | |
195 | wxPropertyValue(const wxPropertyValue& copyFrom); // Copy constructor | |
196 | wxPropertyValue(const wxChar *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(wxChar **val); | |
206 | wxPropertyValue(long *val); | |
207 | wxPropertyValue(bool *val); | |
208 | wxPropertyValue(float *val); | |
209 | ||
210 | ~wxPropertyValue(void); | |
211 | ||
212 | virtual inline wxPropertyValueType Type(void) const { return m_type; } | |
213 | virtual inline void SetType(wxPropertyValueType typ) { m_type = typ; } | |
214 | virtual long IntegerValue(void) const; | |
215 | virtual float RealValue(void) const; | |
216 | virtual bool BoolValue(void) const; | |
217 | virtual wxChar *StringValue(void) const; | |
218 | virtual long *IntegerValuePtr(void) const; | |
219 | virtual float *RealValuePtr(void) const; | |
220 | virtual bool *BoolValuePtr(void) const; | |
221 | virtual wxChar **StringValuePtr(void) const; | |
222 | ||
223 | // Get nth arg of clause (starting from 1) | |
224 | virtual wxPropertyValue *Arg(wxPropertyValueType type, int arg) const; | |
225 | ||
226 | // Return nth argument of a list expression (starting from zero) | |
227 | virtual wxPropertyValue *Nth(int arg) const; | |
228 | // Returns the number of elements in a list expression | |
229 | virtual int Number(void) const; | |
230 | ||
231 | virtual wxPropertyValue *NewCopy(void) const; | |
232 | virtual void Copy(wxPropertyValue& copyFrom); | |
233 | ||
234 | virtual void WritePropertyClause(wxString &stream); // Write this expression as a top-level clause | |
235 | virtual void WritePropertyType(wxString &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) const | |
244 | { return ((m_type == wxPropertyValueList) ? m_value.first : (wxPropertyValue*)NULL); } | |
245 | ||
246 | // Get next expr if this is a node in a list | |
247 | virtual inline wxPropertyValue *GetNext(void) const | |
248 | { return m_next; } | |
249 | ||
250 | // Get last expr in list | |
251 | virtual inline wxPropertyValue *GetLast(void) const | |
252 | { return ((m_type == wxPropertyValueList) ? m_last : (wxPropertyValue*)NULL); } | |
253 | ||
254 | // Delete this node from the list | |
255 | virtual void Delete(wxPropertyValue *node); | |
256 | ||
257 | // Clear list | |
258 | virtual void ClearList(void); | |
259 | ||
260 | virtual inline void SetClientData(wxObject *data) { m_clientData = data; } | |
261 | virtual inline wxObject *GetClientData(void) { return m_clientData; } | |
262 | ||
263 | virtual wxString GetStringRepresentation(void); | |
264 | ||
265 | inline void SetModified(bool flag = TRUE) { m_modifiedFlag = flag; } | |
266 | inline bool GetModified(void) { return m_modifiedFlag; } | |
267 | ||
268 | // Operators | |
269 | void operator=(const wxPropertyValue& val); | |
270 | // void operator=(const char *val); | |
271 | void operator=(const wxString& val); | |
272 | void operator=(const long val); | |
273 | void operator=(const bool val); | |
274 | void operator=(const float val); | |
275 | void operator=(const wxChar **val); | |
276 | void operator=(const long *val); | |
277 | void operator=(const bool *val); | |
278 | void operator=(const float *val); | |
279 | ||
280 | public: | |
281 | wxObject* m_clientData; | |
282 | wxPropertyValueType m_type; | |
283 | bool m_modifiedFlag; | |
284 | ||
285 | union { | |
286 | long integer; // Also doubles as bool | |
287 | wxChar *string; | |
288 | float real; | |
289 | long *integerPtr; | |
290 | bool *boolPtr; | |
291 | wxChar **stringPtr; | |
292 | float *realPtr; | |
293 | wxPropertyValue *first; // If is a list expr, points to the first node | |
294 | } m_value; | |
295 | ||
296 | wxPropertyValue* m_next; // If this is a node in a list, points to the next node | |
297 | wxPropertyValue* m_last; // If is a list expr, points to the last node | |
298 | ||
299 | }; | |
300 | ||
301 | /* | |
302 | * Property class: contains a name and a value. | |
303 | */ | |
304 | ||
305 | class WXDLLEXPORT wxProperty: public wxObject | |
306 | { | |
307 | DECLARE_DYNAMIC_CLASS(wxProperty) | |
308 | protected: | |
309 | bool m_enabled; | |
310 | public: | |
311 | wxPropertyValue m_value; | |
312 | wxString m_name; | |
313 | wxString m_propertyRole; | |
314 | wxPropertyValidator* m_propertyValidator; | |
315 | wxWindow* m_propertyWindow; // Usually a panel item, if anything | |
316 | ||
317 | wxProperty(void); | |
318 | wxProperty(wxProperty& copyFrom); | |
319 | wxProperty(wxString name, wxString role, wxPropertyValidator *ed = NULL); | |
320 | wxProperty(wxString name, const wxPropertyValue& val, wxString role, wxPropertyValidator *ed = NULL); | |
321 | ~wxProperty(void); | |
322 | ||
323 | virtual wxPropertyValue& GetValue(void) const; | |
324 | virtual wxPropertyValidator *GetValidator(void) const; | |
325 | virtual wxString& GetName(void) const; | |
326 | virtual wxString& GetRole(void) const; | |
327 | virtual void SetValue(const wxPropertyValue& val); | |
328 | virtual void SetValidator(wxPropertyValidator *v); | |
329 | virtual void SetName(wxString& nm); | |
330 | virtual void SetRole(wxString& role); | |
331 | void operator=(const wxPropertyValue& val); | |
332 | virtual inline void SetWindow(wxWindow *win) { m_propertyWindow = win; } | |
333 | virtual inline wxWindow *GetWindow(void) const { return m_propertyWindow; } | |
334 | ||
335 | inline void Enable(bool en) { m_enabled = en; } | |
336 | inline bool IsEnabled(void) const { return m_enabled; } | |
337 | }; | |
338 | ||
339 | #endif | |
340 | // wxUSE_PROPSHEET | |
341 | ||
342 | #endif | |
343 | // _WX_PROP_H_ |