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