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