]> git.saurik.com Git - wxWidgets.git/blob - include/wx/propform.h
Added a const for CW compilation
[wxWidgets.git] / include / wx / propform.h
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
15 #if defined(__GNUG__) && !defined(__APPLE__)
16 #pragma interface "propform.h"
17 #endif
18
19 #if wxUSE_PROPSHEET
20
21 #include "wx/prop.h"
22 #include "wx/panel.h"
23
24 class WXDLLEXPORT wxPropertyFormView;
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
34 class WXDLLEXPORT wxPropertyFormView: public wxPropertyView
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
69 virtual bool OnClose();
70 virtual void OnDoubleClick(wxControl *item);
71
72 // TODO: does OnCommand still get called...??? No,
73 // make ProcessEvent do it.
74 virtual void OnCommand(wxWindow& win, wxCommandEvent& event);
75
76 // Extend event processing to process OnCommand
77 virtual bool ProcessEvent(wxEvent& event);
78
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
97
98 wxButton* m_windowCloseButton; // Or OK
99 wxButton* m_windowCancelButton;
100 wxButton* m_windowHelpButton;
101
102 DECLARE_EVENT_TABLE()
103
104 };
105
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
121 class WXDLLEXPORT wxPropertyFormValidator: public wxPropertyValidator
122 {
123 DECLARE_DYNAMIC_CLASS(wxPropertyFormValidator)
124 protected:
125 public:
126 wxPropertyFormValidator(long flags = 0): wxPropertyValidator(flags) { }
127 ~wxPropertyFormValidator(void) {}
128
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.
131 virtual bool OnCheckValue( wxProperty *WXUNUSED(property), wxPropertyFormView *WXUNUSED(view),
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
141 virtual void OnDoubleClick( wxProperty *WXUNUSED(property), wxPropertyFormView *WXUNUSED(view),
142 wxWindow *WXUNUSED(parentWindow) ) { }
143 virtual void OnSetFocus( wxProperty *WXUNUSED(property), wxPropertyFormView *WXUNUSED(view),
144 wxWindow *WXUNUSED(parentWindow) ) { }
145 virtual void OnKillFocus( wxProperty *WXUNUSED(property), wxPropertyFormView *WXUNUSED(view),
146 wxWindow *WXUNUSED(parentWindow) ) { }
147 virtual void OnCommand( wxProperty *WXUNUSED(property), wxPropertyFormView *WXUNUSED(view),
148 wxWindow *WXUNUSED(parentWindow), wxCommandEvent& WXUNUSED(event) ) {}
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
156 };
157
158 /*
159 * Some default validators
160 */
161
162 class WXDLLEXPORT wxRealFormValidator: public wxPropertyFormValidator
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
183 class WXDLLEXPORT wxIntegerFormValidator: public wxPropertyFormValidator
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
203 class WXDLLEXPORT wxBoolFormValidator: public wxPropertyFormValidator
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
218 class WXDLLEXPORT wxStringFormValidator: public wxPropertyFormValidator
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 */
241
242 class WXDLLEXPORT wxPropertyFormDialog: public wxDialog
243 {
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"));
252
253 void OnCloseWindow(wxCloseEvent& event);
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 private:
261 wxPropertyFormView* m_view;
262
263 DECLARE_EVENT_TABLE()
264 DECLARE_CLASS(wxPropertyFormDialog)
265 };
266
267 /*
268 * A default panel class to use.
269 */
270
271 class WXDLLEXPORT wxPropertyFormPanel: public wxPanel
272 {
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; }
291
292 private:
293 wxPropertyFormView* m_view;
294
295 DECLARE_CLASS(wxPropertyFormPanel)
296 };
297
298 /*
299 * A default frame class to use.
300 */
301
302 class WXDLLEXPORT wxPropertyFormFrame: public wxFrame
303 {
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; }
323
324 private:
325 wxPropertyFormView* m_view;
326 wxPanel* m_propertyPanel;
327
328 DECLARE_EVENT_TABLE()
329 DECLARE_CLASS(wxPropertyFormFrame)
330 };
331
332 #endif
333 // wxUSE_PROPSHEET
334
335 #endif
336 // _WX_PROPFORM_H_