]> git.saurik.com Git - wxWidgets.git/blob - utils/wxprop/src/propform.h
Fixed various wxMSW compile problems that came down the telephone line...
[wxWidgets.git] / utils / wxprop / src / 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 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.
120 virtual bool OnCheckValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow)
121 { return TRUE; }
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
130 virtual void OnDoubleClick(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow) {};
131 virtual void OnSetFocus(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow) {};
132 virtual void OnKillFocus(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow) {};
133 virtual void OnCommand(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow, wxCommandEvent& event) {};
134
135 };
136
137 /*
138 * Some default validators
139 */
140
141 class wxRealFormValidator: public wxPropertyFormValidator
142 {
143 DECLARE_DYNAMIC_CLASS(wxRealFormValidator)
144 protected:
145 float realMin;
146 float realMax;
147 public:
148 // 0.0, 0.0 means no range
149 wxRealFormValidator(float min = 0.0, float max = 0.0, long flags = 0):wxPropertyFormValidator(flags)
150 {
151 realMin = min; realMax = max;
152 }
153 ~wxRealFormValidator(void) {}
154
155 bool OnCheckValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow);
156 bool OnRetrieveValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow);
157 // Called by the view to transfer the property to the window.
158 bool OnDisplayValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow);
159 };
160
161 class wxIntegerFormValidator: public wxPropertyFormValidator
162 {
163 DECLARE_DYNAMIC_CLASS(wxIntegerFormValidator)
164 protected:
165 long integerMin;
166 long integerMax;
167 public:
168 // 0, 0 means no range
169 wxIntegerFormValidator(long min = 0, long max = 0, long flags = 0):wxPropertyFormValidator(flags)
170 {
171 integerMin = min; integerMax = max;
172 }
173 ~wxIntegerFormValidator(void) {}
174
175 bool OnCheckValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow);
176 bool OnRetrieveValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow);
177 bool OnDisplayValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow);
178 };
179
180 class wxBoolFormValidator: public wxPropertyFormValidator
181 {
182 DECLARE_DYNAMIC_CLASS(wxBoolFormValidator)
183 protected:
184 public:
185 wxBoolFormValidator(long flags = 0):wxPropertyFormValidator(flags)
186 {
187 }
188 ~wxBoolFormValidator(void) {}
189
190 bool OnCheckValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow);
191 bool OnRetrieveValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow);
192 bool OnDisplayValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow);
193 };
194
195 class wxStringFormValidator: public wxPropertyFormValidator
196 {
197 DECLARE_DYNAMIC_CLASS(wxStringFormValidator)
198 protected:
199 wxStringList *strings;
200 public:
201 wxStringFormValidator(wxStringList *list = NULL, long flags = 0);
202
203 ~wxStringFormValidator(void)
204 {
205 if (strings)
206 delete strings;
207 }
208
209 bool OnCheckValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow);
210 bool OnRetrieveValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow);
211 bool OnDisplayValue(wxProperty *property, wxPropertyFormView *view, wxWindow *parentWindow);
212 };
213
214 /*
215 * A default dialog box class to use.
216 */
217
218 class wxPropertyFormDialog: public wxDialog
219 {
220 DECLARE_CLASS(wxPropertyFormDialog)
221 private:
222 wxPropertyFormView *view;
223 public:
224 wxPropertyFormDialog(wxPropertyFormView *v, wxWindow *parent, const wxString& title,
225 const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
226 long style = wxDEFAULT_DIALOG_STYLE, const wxString& name = "dialogBox");
227 bool OnClose(void);
228 void OnDefaultAction(wxControl *item);
229 void OnCommand(wxWindow& win, wxCommandEvent& event);
230
231 // Extend event processing to search the view's event table
232 virtual bool ProcessEvent(wxEvent& event);
233 };
234
235 /*
236 * A default panel class to use.
237 */
238
239 class wxPropertyFormPanel: public wxPanel
240 {
241 DECLARE_CLASS(wxPropertyFormPanel)
242 private:
243 wxPropertyFormView *view;
244 public:
245 wxPropertyFormPanel(wxPropertyFormView *v, wxWindow *parent, const wxPoint& pos = wxDefaultPosition,
246 const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = "panel"):
247 wxPanel(parent, -1, pos, size, style, name)
248 {
249 view = v;
250 }
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
258 /*
259 * A default frame class to use.
260 */
261
262 class wxPropertyFormFrame: public wxFrame
263 {
264 DECLARE_CLASS(wxPropertyFormFrame)
265 private:
266 wxPropertyFormView *view;
267 wxPanel *propertyPanel;
268 public:
269 wxPropertyFormFrame(wxPropertyFormView *v, wxFrame *parent, const wxString& title,
270 const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
271 long style = wxDEFAULT_FRAME, const wxString& name = "frame"):
272 wxFrame(parent, -1, title, pos, size, style, name)
273 {
274 view = v;
275 propertyPanel = NULL;
276 }
277 bool OnClose(void);
278
279 // Must call this to create panel and associate view
280 virtual bool Initialize(void);
281 virtual wxPanel *OnCreatePanel(wxFrame *parent, wxPropertyFormView *v);
282 inline virtual wxPanel *GetPropertyPanel(void) { return propertyPanel; }
283 };
284
285 #endif
286