]>
Commit | Line | Data |
---|---|---|
457814b5 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: propform.h | |
3 | // Purpose: Property form 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 _PROPFORM_H_ | |
13 | #define _PROPFORM_H_ | |
14 | ||
15 | #ifdef __GNUG__ | |
16 | #pragma interface "propform.h" | |
17 | #endif | |
18 | ||
19 | #include "prop.h" | |
20 | ||
21 | //// | |
22 | //// Property form classes: for using an existing dialog or panel | |
23 | //// | |
24 | ||
25 | #define wxID_PROP_REVERT 3100 | |
26 | #define wxID_PROP_UPDATE 3101 | |
27 | ||
28 | // Mediates between a physical panel and the property sheet | |
29 | class wxPropertyFormView: public wxPropertyView | |
30 | { | |
31 | DECLARE_DYNAMIC_CLASS(wxPropertyFormView) | |
32 | protected: | |
33 | bool detailedEditing; // E.g. using listbox for choices | |
34 | ||
35 | wxWindow *propertyWindow; // Panel that the controls will appear on | |
36 | wxWindow *managedWindow; // Frame or dialog | |
37 | ||
38 | wxButton *windowCloseButton; // Or OK | |
39 | wxButton *windowCancelButton; | |
40 | wxButton *windowHelpButton; | |
41 | public: | |
42 | static bool dialogCancelled; | |
43 | ||
44 | wxPropertyFormView(wxWindow *propPanel = NULL, long flags = 0); | |
45 | ~wxPropertyFormView(void); | |
46 | ||
47 | // Associates and shows the view | |
48 | virtual void ShowView(wxPropertySheet *propertySheet, wxWindow *panel); | |
49 | ||
50 | // Update this view of the viewed object, called e.g. by | |
51 | // the object itself. | |
52 | virtual bool OnUpdateView(void); | |
53 | ||
54 | // Transfer values from property sheet to dialog | |
55 | virtual bool TransferToDialog(void); | |
56 | ||
57 | // Transfer values from dialog to property sheet | |
58 | virtual bool TransferToPropertySheet(void); | |
59 | ||
60 | // Check that all the values are valid | |
61 | virtual bool Check(void); | |
62 | ||
63 | // Give each property in the sheet a panel item, by matching | |
64 | // the name of the property to the name of the panel item. | |
65 | // The user doesn't always want to call this; sometimes, it | |
66 | // will have been done explicitly (e.g., no matching names). | |
67 | virtual bool AssociateNames(void); | |
68 | ||
69 | void OnOk(wxCommandEvent& event); | |
70 | void OnCancel(wxCommandEvent& event); | |
71 | void OnHelp(wxCommandEvent& event); | |
72 | void OnUpdate(wxCommandEvent& event); | |
73 | void OnRevert(wxCommandEvent& event); | |
74 | ||
75 | virtual bool OnClose(void); | |
76 | virtual void OnDoubleClick(wxControl *item); | |
77 | ||
78 | // TODO: does OnCommand still get called...??? | |
79 | virtual void OnCommand(wxWindow& win, wxCommandEvent& event); | |
80 | ||
81 | inline virtual void AssociatePanel(wxWindow *win) { propertyWindow = win; } | |
82 | inline virtual wxWindow *GetPanel(void) { return propertyWindow; } | |
83 | ||
84 | inline virtual void SetManagedWindow(wxWindow *win) { managedWindow = win; } | |
85 | inline virtual wxWindow *GetManagedWindow(void) { return managedWindow; } | |
86 | ||
87 | inline virtual wxButton *GetWindowCloseButton() { return windowCloseButton; } | |
88 | inline virtual wxButton *GetWindowCancelButton() { return windowCancelButton; } | |
89 | inline virtual wxButton *GetHelpButton() { return windowHelpButton; } | |
90 | ||
91 | DECLARE_EVENT_TABLE() | |
92 | ||
93 | }; | |
94 | ||
95 | /* | |
96 | * The type of validator used for forms (wxForm style but using an existing panel | |
97 | * or dialog box). | |
98 | * Classes derived from this know how to map from whatever widget they | |
99 | * find themselves paired with, to the wxProperty and vice versa. | |
100 | * Should the widget pointer be stored with the validator, or | |
101 | * the wxProperty? If with the property, we don't have to supply | |
102 | * a validator for every property. Otherwise, there ALWAYS needs | |
103 | * to be a validator. On the other hand, not storing a wxWindow pointer | |
104 | * in the wxProperty is more elegant. Perhaps. | |
105 | * I think on balance, should put wxWindow pointer into wxProperty. | |
106 | * After all, wxProperty will often be used to represent the data | |
107 | * assocated with a window. It's that kinda thing. | |
108 | */ | |
109 | ||
110 | class wxPropertyFormValidator: public wxPropertyValidator | |
111 | { | |
112 | DECLARE_DYNAMIC_CLASS(wxPropertyFormValidator) | |
113 | protected: | |
114 | public: | |
115 | wxPropertyFormValidator(long flags = 0): wxPropertyValidator(flags) { } | |
116 | ~wxPropertyFormValidator(void) {} | |
117 | ||
118 | // Called to check value is OK (e.g. when OK is pressed) | |
119 | // Return FALSE if value didn't check out; signal to restore old value. | |
8656024d RR |
120 | virtual bool OnCheckValue( wxProperty *WXUNUSED(property), wxPropertyFormView *WXUNUSED(view), |
121 | wxWindow *WXUNUSED(parentWindow) ) { return TRUE; } | |
457814b5 JS |
122 | |
123 | // Does the transferance from the property editing area to the property itself. | |
124 | // Called by the view, e.g. when closing the window. | |
125 | virtual bool OnRetrieveValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow) = 0; | |
126 | ||
127 | // Called by the view to transfer the property to the window. | |
128 | virtual bool OnDisplayValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow) = 0; | |
129 | ||
8656024d RR |
130 | virtual void OnDoubleClick( wxProperty *WXUNUSED(property), wxPropertyFormView *WXUNUSED(view), |
131 | wxWindow *WXUNUSED(parentWindow) ) { } | |
132 | virtual void OnSetFocus( wxProperty *WXUNUSED(property), wxPropertyFormView *WXUNUSED(view), | |
133 | wxWindow *WXUNUSED(parentWindow) ) { } | |
134 | virtual void OnKillFocus( wxProperty *WXUNUSED(property), wxPropertyFormView *WXUNUSED(view), | |
135 | wxWindow *WXUNUSED(parentWindow) ) { } | |
136 | virtual void OnCommand( wxProperty *WXUNUSED(property), wxPropertyFormView *WXUNUSED(view), | |
137 | wxWindow *WXUNUSED(parentWindow), wxCommandEvent& WXUNUSED(event) ) {} | |
457814b5 JS |
138 | }; |
139 | ||
140 | /* | |
141 | * Some default validators | |
142 | */ | |
143 | ||
144 | class wxRealFormValidator: public wxPropertyFormValidator | |
145 | { | |
146 | DECLARE_DYNAMIC_CLASS(wxRealFormValidator) | |
147 | protected: | |
148 | float realMin; | |
149 | float realMax; | |
150 | public: | |
151 | // 0.0, 0.0 means no range | |
152 | wxRealFormValidator(float min = 0.0, float max = 0.0, long flags = 0):wxPropertyFormValidator(flags) | |
153 | { | |
154 | realMin = min; realMax = max; | |
155 | } | |
156 | ~wxRealFormValidator(void) {} | |
157 | ||
158 | bool OnCheckValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow); | |
159 | bool OnRetrieveValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow); | |
160 | // Called by the view to transfer the property to the window. | |
161 | bool OnDisplayValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow); | |
162 | }; | |
163 | ||
164 | class wxIntegerFormValidator: public wxPropertyFormValidator | |
165 | { | |
166 | DECLARE_DYNAMIC_CLASS(wxIntegerFormValidator) | |
167 | protected: | |
168 | long integerMin; | |
169 | long integerMax; | |
170 | public: | |
171 | // 0, 0 means no range | |
172 | wxIntegerFormValidator(long min = 0, long max = 0, long flags = 0):wxPropertyFormValidator(flags) | |
173 | { | |
174 | integerMin = min; integerMax = max; | |
175 | } | |
176 | ~wxIntegerFormValidator(void) {} | |
177 | ||
178 | bool OnCheckValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow); | |
179 | bool OnRetrieveValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow); | |
180 | bool OnDisplayValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow); | |
181 | }; | |
182 | ||
183 | class wxBoolFormValidator: public wxPropertyFormValidator | |
184 | { | |
185 | DECLARE_DYNAMIC_CLASS(wxBoolFormValidator) | |
186 | protected: | |
187 | public: | |
188 | wxBoolFormValidator(long flags = 0):wxPropertyFormValidator(flags) | |
189 | { | |
190 | } | |
191 | ~wxBoolFormValidator(void) {} | |
192 | ||
193 | bool OnCheckValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow); | |
194 | bool OnRetrieveValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow); | |
195 | bool OnDisplayValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow); | |
196 | }; | |
197 | ||
198 | class wxStringFormValidator: public wxPropertyFormValidator | |
199 | { | |
200 | DECLARE_DYNAMIC_CLASS(wxStringFormValidator) | |
201 | protected: | |
202 | wxStringList *strings; | |
203 | public: | |
204 | wxStringFormValidator(wxStringList *list = NULL, long flags = 0); | |
205 | ||
206 | ~wxStringFormValidator(void) | |
207 | { | |
208 | if (strings) | |
209 | delete strings; | |
210 | } | |
211 | ||
212 | bool OnCheckValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow); | |
213 | bool OnRetrieveValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow); | |
214 | bool OnDisplayValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow); | |
215 | }; | |
216 | ||
217 | /* | |
218 | * A default dialog box class to use. | |
219 | */ | |
220 | ||
221 | class wxPropertyFormDialog: public wxDialog | |
222 | { | |
223 | DECLARE_CLASS(wxPropertyFormDialog) | |
224 | private: | |
225 | wxPropertyFormView *view; | |
226 | public: | |
227 | wxPropertyFormDialog(wxPropertyFormView *v, wxWindow *parent, const wxString& title, | |
228 | const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, | |
229 | long style = wxDEFAULT_DIALOG_STYLE, const wxString& name = "dialogBox"); | |
230 | bool OnClose(void); | |
231 | void OnDefaultAction(wxControl *item); | |
232 | void OnCommand(wxWindow& win, wxCommandEvent& event); | |
233 | ||
234 | // Extend event processing to search the view's event table | |
235 | virtual bool ProcessEvent(wxEvent& event); | |
236 | }; | |
237 | ||
238 | /* | |
239 | * A default panel class to use. | |
240 | */ | |
241 | ||
242 | class wxPropertyFormPanel: public wxPanel | |
243 | { | |
244 | DECLARE_CLASS(wxPropertyFormPanel) | |
245 | private: | |
246 | wxPropertyFormView *view; | |
247 | public: | |
248 | wxPropertyFormPanel(wxPropertyFormView *v, wxWindow *parent, const wxPoint& pos = wxDefaultPosition, | |
249 | const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = "panel"): | |
250 | wxPanel(parent, -1, pos, size, style, name) | |
251 | { | |
252 | view = v; | |
253 | } | |
254 | void OnDefaultAction(wxControl *item); | |
255 | void OnCommand(wxWindow& win, wxCommandEvent& event); | |
256 | ||
257 | // Extend event processing to search the view's event table | |
258 | virtual bool ProcessEvent(wxEvent& event); | |
259 | }; | |
260 | ||
261 | /* | |
262 | * A default frame class to use. | |
263 | */ | |
264 | ||
265 | class wxPropertyFormFrame: public wxFrame | |
266 | { | |
267 | DECLARE_CLASS(wxPropertyFormFrame) | |
268 | private: | |
269 | wxPropertyFormView *view; | |
270 | wxPanel *propertyPanel; | |
271 | public: | |
272 | wxPropertyFormFrame(wxPropertyFormView *v, wxFrame *parent, const wxString& title, | |
273 | const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, | |
274 | long style = wxDEFAULT_FRAME, const wxString& name = "frame"): | |
275 | wxFrame(parent, -1, title, pos, size, style, name) | |
276 | { | |
277 | view = v; | |
278 | propertyPanel = NULL; | |
279 | } | |
280 | bool OnClose(void); | |
281 | ||
282 | // Must call this to create panel and associate view | |
283 | virtual bool Initialize(void); | |
284 | virtual wxPanel *OnCreatePanel(wxFrame *parent, wxPropertyFormView *v); | |
285 | inline virtual wxPanel *GetPropertyPanel(void) { return propertyPanel; } | |
286 | }; | |
287 | ||
288 | #endif | |
289 |