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