]>
Commit | Line | Data |
---|---|---|
e3a43801 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: propform.cpp | |
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 | |
1e6feb95 | 9 | // Licence: wxWindows licence |
e3a43801 JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "propform.h" | |
14 | #endif | |
15 | ||
16 | // For compilers that support precompilation, includes "wx/wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
1e6feb95 VZ |
23 | #if wxUSE_PROPSHEET |
24 | ||
e3a43801 | 25 | #ifndef WX_PRECOMP |
00dd3b18 MB |
26 | #include "wx/choice.h" |
27 | #include "wx/checkbox.h" | |
28 | #include "wx/slider.h" | |
29 | #include "wx/msgdlg.h" | |
e3a43801 JS |
30 | #endif |
31 | ||
c693edf3 RR |
32 | #include "wx/propform.h" |
33 | ||
e3a43801 JS |
34 | #include <ctype.h> |
35 | #include <stdlib.h> | |
36 | #include <math.h> | |
37 | #include <string.h> | |
38 | ||
e3a43801 JS |
39 | |
40 | /* | |
f6bcfd97 BP |
41 | * Property view |
42 | */ | |
e3a43801 JS |
43 | |
44 | IMPLEMENT_DYNAMIC_CLASS(wxPropertyFormView, wxPropertyView) | |
45 | ||
46 | BEGIN_EVENT_TABLE(wxPropertyFormView, wxPropertyView) | |
1e6feb95 VZ |
47 | EVT_BUTTON(wxID_OK, wxPropertyFormView::OnOk) |
48 | EVT_BUTTON(wxID_CANCEL, wxPropertyFormView::OnCancel) | |
49 | EVT_BUTTON(wxID_HELP, wxPropertyFormView::OnHelp) | |
50 | EVT_BUTTON(wxID_PROP_REVERT, wxPropertyFormView::OnRevert) | |
51 | EVT_BUTTON(wxID_PROP_UPDATE, wxPropertyFormView::OnUpdate) | |
e3a43801 JS |
52 | END_EVENT_TABLE() |
53 | ||
54 | bool wxPropertyFormView::sm_dialogCancelled = FALSE; | |
55 | ||
56 | wxPropertyFormView::wxPropertyFormView(wxWindow *propPanel, long flags):wxPropertyView(flags) | |
57 | { | |
f6bcfd97 BP |
58 | m_propertyWindow = propPanel; |
59 | m_managedWindow = NULL; | |
1e6feb95 | 60 | |
f6bcfd97 BP |
61 | m_windowCloseButton = NULL; |
62 | m_windowCancelButton = NULL; | |
63 | m_windowHelpButton = NULL; | |
1e6feb95 | 64 | |
f6bcfd97 | 65 | m_detailedEditing = FALSE; |
e3a43801 JS |
66 | } |
67 | ||
68 | wxPropertyFormView::~wxPropertyFormView(void) | |
69 | { | |
70 | } | |
71 | ||
72 | void wxPropertyFormView::ShowView(wxPropertySheet *ps, wxWindow *panel) | |
73 | { | |
f6bcfd97 | 74 | m_propertySheet = ps; |
1e6feb95 | 75 | |
f6bcfd97 BP |
76 | AssociatePanel(panel); |
77 | // CreateControls(); | |
78 | // UpdatePropertyList(); | |
e3a43801 JS |
79 | } |
80 | ||
81 | // Update this view of the viewed object, called e.g. by | |
82 | // the object itself. | |
83 | bool wxPropertyFormView::OnUpdateView(void) | |
84 | { | |
f6bcfd97 | 85 | return TRUE; |
e3a43801 JS |
86 | } |
87 | ||
88 | bool wxPropertyFormView::Check(void) | |
89 | { | |
f6bcfd97 BP |
90 | if (!m_propertySheet) |
91 | return FALSE; | |
1e6feb95 | 92 | |
b1d4dd7a | 93 | wxNode *node = m_propertySheet->GetProperties().GetFirst(); |
f6bcfd97 | 94 | while (node) |
e3a43801 | 95 | { |
b1d4dd7a | 96 | wxProperty *prop = (wxProperty *)node->GetData(); |
f6bcfd97 BP |
97 | wxPropertyValidator *validator = FindPropertyValidator(prop); |
98 | if (validator && validator->IsKindOf(CLASSINFO(wxPropertyFormValidator))) | |
99 | { | |
100 | wxPropertyFormValidator *formValidator = (wxPropertyFormValidator *)validator; | |
101 | if (!formValidator->OnCheckValue(prop, this, m_propertyWindow)) | |
102 | return FALSE; | |
103 | } | |
b1d4dd7a | 104 | node = node->GetNext(); |
e3a43801 | 105 | } |
f6bcfd97 | 106 | return TRUE; |
e3a43801 JS |
107 | } |
108 | ||
109 | bool wxPropertyFormView::TransferToPropertySheet(void) | |
110 | { | |
f6bcfd97 BP |
111 | if (!m_propertySheet) |
112 | return FALSE; | |
1e6feb95 | 113 | |
b1d4dd7a | 114 | wxNode *node = m_propertySheet->GetProperties().GetFirst(); |
f6bcfd97 | 115 | while (node) |
e3a43801 | 116 | { |
b1d4dd7a | 117 | wxProperty *prop = (wxProperty *)node->GetData(); |
f6bcfd97 BP |
118 | wxPropertyValidator *validator = FindPropertyValidator(prop); |
119 | if (validator && validator->IsKindOf(CLASSINFO(wxPropertyFormValidator))) | |
120 | { | |
121 | wxPropertyFormValidator *formValidator = (wxPropertyFormValidator *)validator; | |
122 | formValidator->OnRetrieveValue(prop, this, m_propertyWindow); | |
123 | } | |
b1d4dd7a | 124 | node = node->GetNext(); |
e3a43801 | 125 | } |
f6bcfd97 | 126 | return TRUE; |
e3a43801 JS |
127 | } |
128 | ||
129 | bool wxPropertyFormView::TransferToDialog(void) | |
130 | { | |
f6bcfd97 BP |
131 | if (!m_propertySheet) |
132 | return FALSE; | |
1e6feb95 | 133 | |
b1d4dd7a | 134 | wxNode *node = m_propertySheet->GetProperties().GetFirst(); |
f6bcfd97 | 135 | while (node) |
e3a43801 | 136 | { |
b1d4dd7a | 137 | wxProperty *prop = (wxProperty *)node->GetData(); |
f6bcfd97 BP |
138 | wxPropertyValidator *validator = FindPropertyValidator(prop); |
139 | if (validator && validator->IsKindOf(CLASSINFO(wxPropertyFormValidator))) | |
140 | { | |
141 | wxPropertyFormValidator *formValidator = (wxPropertyFormValidator *)validator; | |
142 | formValidator->OnDisplayValue(prop, this, m_propertyWindow); | |
143 | } | |
b1d4dd7a | 144 | node = node->GetNext(); |
e3a43801 | 145 | } |
f6bcfd97 | 146 | return TRUE; |
e3a43801 JS |
147 | } |
148 | ||
149 | bool wxPropertyFormView::AssociateNames(void) | |
150 | { | |
f6bcfd97 BP |
151 | if (!m_propertySheet || !m_propertyWindow) |
152 | return FALSE; | |
1e6feb95 | 153 | |
b1d4dd7a | 154 | wxWindowList::Node *node = m_propertyWindow->GetChildren().GetFirst(); |
f6bcfd97 | 155 | while (node) |
e3a43801 | 156 | { |
b1d4dd7a RL |
157 | wxWindow *win = node->GetData(); |
158 | if ( win->GetName() != wxEmptyString ) | |
f6bcfd97 BP |
159 | { |
160 | wxProperty *prop = m_propertySheet->GetProperty(win->GetName()); | |
161 | if (prop) | |
162 | prop->SetWindow(win); | |
163 | } | |
b1d4dd7a | 164 | node = node->GetNext(); |
e3a43801 | 165 | } |
f6bcfd97 | 166 | return TRUE; |
e3a43801 JS |
167 | } |
168 | ||
169 | ||
170 | bool wxPropertyFormView::OnClose(void) | |
171 | { | |
f6bcfd97 BP |
172 | if (m_propertyWindow->IsKindOf(CLASSINFO(wxPropertyFormPanel))) |
173 | { | |
174 | ((wxPropertyFormPanel*)m_propertyWindow)->SetView(NULL); | |
175 | } | |
176 | delete this; | |
177 | return TRUE; | |
e3a43801 JS |
178 | } |
179 | ||
180 | void wxPropertyFormView::OnOk(wxCommandEvent& WXUNUSED(event)) | |
181 | { | |
f6bcfd97 BP |
182 | // Retrieve the value if any |
183 | if (!Check()) | |
184 | return; | |
1e6feb95 | 185 | |
f6bcfd97 BP |
186 | sm_dialogCancelled = FALSE; |
187 | TransferToPropertySheet(); | |
1e6feb95 | 188 | |
f6bcfd97 | 189 | m_managedWindow->Close(TRUE); |
e3a43801 JS |
190 | } |
191 | ||
192 | void wxPropertyFormView::OnCancel(wxCommandEvent& WXUNUSED(event)) | |
193 | { | |
f6bcfd97 | 194 | sm_dialogCancelled = TRUE; |
1e6feb95 | 195 | |
f6bcfd97 | 196 | m_managedWindow->Close(TRUE); |
e3a43801 JS |
197 | } |
198 | ||
199 | void wxPropertyFormView::OnHelp(wxCommandEvent& WXUNUSED(event)) | |
200 | { | |
201 | } | |
202 | ||
203 | void wxPropertyFormView::OnUpdate(wxCommandEvent& WXUNUSED(event)) | |
204 | { | |
205 | if (Check()) | |
206 | TransferToPropertySheet(); | |
207 | } | |
208 | ||
209 | void wxPropertyFormView::OnRevert(wxCommandEvent& WXUNUSED(event)) | |
210 | { | |
f6bcfd97 | 211 | TransferToDialog(); |
e3a43801 JS |
212 | } |
213 | ||
214 | void wxPropertyFormView::OnCommand(wxWindow& win, wxCommandEvent& event) | |
215 | { | |
f6bcfd97 BP |
216 | if (!m_propertySheet) |
217 | return; | |
1e6feb95 | 218 | |
f6bcfd97 BP |
219 | if (win.GetName() == wxT("")) |
220 | return; | |
1e6feb95 | 221 | |
f6bcfd97 BP |
222 | if (wxStrcmp(win.GetName(), wxT("ok")) == 0) |
223 | OnOk(event); | |
224 | else if (wxStrcmp(win.GetName(), wxT("cancel")) == 0) | |
225 | OnCancel(event); | |
226 | else if (wxStrcmp(win.GetName(), wxT("help")) == 0) | |
227 | OnHelp(event); | |
228 | else if (wxStrcmp(win.GetName(), wxT("update")) == 0) | |
229 | OnUpdate(event); | |
230 | else if (wxStrcmp(win.GetName(), wxT("revert")) == 0) | |
231 | OnRevert(event); | |
232 | else | |
e3a43801 | 233 | { |
f6bcfd97 | 234 | // Find a validator to route the command to. |
b1d4dd7a | 235 | wxNode *node = m_propertySheet->GetProperties().GetFirst(); |
f6bcfd97 | 236 | while (node) |
e3a43801 | 237 | { |
b1d4dd7a | 238 | wxProperty *prop = (wxProperty *)node->GetData(); |
f6bcfd97 BP |
239 | if (prop->GetWindow() && (prop->GetWindow() == &win)) |
240 | { | |
241 | wxPropertyValidator *validator = FindPropertyValidator(prop); | |
242 | if (validator && validator->IsKindOf(CLASSINFO(wxPropertyFormValidator))) | |
243 | { | |
244 | wxPropertyFormValidator *formValidator = (wxPropertyFormValidator *)validator; | |
245 | formValidator->OnCommand(prop, this, m_propertyWindow, event); | |
246 | return; | |
247 | } | |
248 | } | |
b1d4dd7a | 249 | node = node->GetNext(); |
e3a43801 | 250 | } |
e3a43801 | 251 | } |
e3a43801 JS |
252 | } |
253 | ||
1b9315eb JS |
254 | // Extend event processing to call OnCommand |
255 | bool wxPropertyFormView::ProcessEvent(wxEvent& event) | |
256 | { | |
257 | if (wxEvtHandler::ProcessEvent(event)) | |
258 | return TRUE; | |
259 | else if (event.IsCommandEvent() && !event.IsKindOf(CLASSINFO(wxUpdateUIEvent)) && event.GetEventObject()) | |
260 | { | |
261 | OnCommand(* ((wxWindow*) event.GetEventObject()), (wxCommandEvent&) event); | |
262 | return TRUE; | |
263 | } | |
264 | else | |
265 | return FALSE; | |
266 | } | |
267 | ||
e3a43801 JS |
268 | void wxPropertyFormView::OnDoubleClick(wxControl *item) |
269 | { | |
f6bcfd97 BP |
270 | if (!m_propertySheet) |
271 | return; | |
1e6feb95 | 272 | |
f6bcfd97 | 273 | // Find a validator to route the command to. |
b1d4dd7a | 274 | wxNode *node = m_propertySheet->GetProperties().GetFirst(); |
f6bcfd97 | 275 | while (node) |
e3a43801 | 276 | { |
b1d4dd7a | 277 | wxProperty *prop = (wxProperty *)node->GetData(); |
f6bcfd97 BP |
278 | if (prop->GetWindow() && ((wxControl *)prop->GetWindow() == item)) |
279 | { | |
280 | wxPropertyValidator *validator = FindPropertyValidator(prop); | |
281 | if (validator && validator->IsKindOf(CLASSINFO(wxPropertyFormValidator))) | |
282 | { | |
283 | wxPropertyFormValidator *formValidator = (wxPropertyFormValidator *)validator; | |
284 | formValidator->OnDoubleClick(prop, this, m_propertyWindow); | |
285 | return; | |
286 | } | |
287 | } | |
b1d4dd7a | 288 | node = node->GetNext(); |
e3a43801 | 289 | } |
e3a43801 JS |
290 | } |
291 | ||
292 | /* | |
f6bcfd97 BP |
293 | * Property form dialog box |
294 | */ | |
295 | ||
296 | IMPLEMENT_DYNAMIC_CLASS(wxPropertyFormDialog, wxDialog) | |
e3a43801 | 297 | |
e3065973 | 298 | BEGIN_EVENT_TABLE(wxPropertyFormDialog, wxDialog) |
f6bcfd97 | 299 | EVT_CLOSE(wxPropertyFormDialog::OnCloseWindow) |
e3065973 JS |
300 | END_EVENT_TABLE() |
301 | ||
e3a43801 | 302 | wxPropertyFormDialog::wxPropertyFormDialog(wxPropertyFormView *v, wxWindow *parent, const wxString& title, |
f6bcfd97 BP |
303 | const wxPoint& pos, const wxSize& size, long style, const wxString& name): |
304 | wxDialog(parent, -1, title, pos, size, style, name) | |
e3a43801 | 305 | { |
f6bcfd97 BP |
306 | m_view = v; |
307 | m_view->AssociatePanel(this); | |
308 | m_view->SetManagedWindow(this); | |
309 | // SetAutoLayout(TRUE); | |
e3a43801 JS |
310 | } |
311 | ||
e3065973 | 312 | void wxPropertyFormDialog::OnCloseWindow(wxCloseEvent& event) |
e3a43801 | 313 | { |
f6bcfd97 BP |
314 | if (m_view) |
315 | { | |
316 | m_view->OnClose(); | |
317 | m_view = NULL; | |
318 | this->Destroy(); | |
319 | } | |
320 | else | |
321 | event.Veto(); | |
e3a43801 JS |
322 | } |
323 | ||
324 | void wxPropertyFormDialog::OnDefaultAction(wxControl *item) | |
325 | { | |
f6bcfd97 | 326 | m_view->OnDoubleClick(item); |
e3a43801 JS |
327 | } |
328 | ||
329 | void wxPropertyFormDialog::OnCommand(wxWindow& win, wxCommandEvent& event) | |
330 | { | |
f6bcfd97 BP |
331 | if ( m_view ) |
332 | m_view->OnCommand(win, event); | |
e3a43801 JS |
333 | } |
334 | ||
335 | // Extend event processing to search the view's event table | |
336 | bool wxPropertyFormDialog::ProcessEvent(wxEvent& event) | |
337 | { | |
f6bcfd97 BP |
338 | if ( !m_view || ! m_view->ProcessEvent(event) ) |
339 | return wxEvtHandler::ProcessEvent(event); | |
340 | else | |
341 | return TRUE; | |
e3a43801 JS |
342 | } |
343 | ||
344 | ||
345 | /* | |
f6bcfd97 BP |
346 | * Property form panel |
347 | */ | |
348 | ||
349 | IMPLEMENT_DYNAMIC_CLASS(wxPropertyFormPanel, wxPanel) | |
e3a43801 JS |
350 | |
351 | void wxPropertyFormPanel::OnDefaultAction(wxControl *item) | |
352 | { | |
f6bcfd97 | 353 | m_view->OnDoubleClick(item); |
e3a43801 JS |
354 | } |
355 | ||
356 | void wxPropertyFormPanel::OnCommand(wxWindow& win, wxCommandEvent& event) | |
357 | { | |
f6bcfd97 | 358 | m_view->OnCommand(win, event); |
e3a43801 JS |
359 | } |
360 | ||
361 | // Extend event processing to search the view's event table | |
362 | bool wxPropertyFormPanel::ProcessEvent(wxEvent& event) | |
363 | { | |
f6bcfd97 BP |
364 | if ( !m_view || ! m_view->ProcessEvent(event) ) |
365 | return wxEvtHandler::ProcessEvent(event); | |
366 | else | |
367 | return TRUE; | |
e3a43801 JS |
368 | } |
369 | ||
370 | /* | |
f6bcfd97 BP |
371 | * Property frame |
372 | */ | |
373 | ||
374 | IMPLEMENT_DYNAMIC_CLASS(wxPropertyFormFrame, wxFrame) | |
e3a43801 | 375 | |
e3065973 | 376 | BEGIN_EVENT_TABLE(wxPropertyFormFrame, wxFrame) |
f6bcfd97 | 377 | EVT_CLOSE(wxPropertyFormFrame::OnCloseWindow) |
e3065973 JS |
378 | END_EVENT_TABLE() |
379 | ||
380 | void wxPropertyFormFrame::OnCloseWindow(wxCloseEvent& event) | |
e3a43801 | 381 | { |
f6bcfd97 BP |
382 | if (m_view && m_view->OnClose()) |
383 | this->Destroy(); | |
384 | else | |
385 | event.Veto(); | |
e3a43801 JS |
386 | } |
387 | ||
388 | wxPanel *wxPropertyFormFrame::OnCreatePanel(wxFrame *parent, wxPropertyFormView *v) | |
389 | { | |
f6bcfd97 | 390 | return new wxPropertyFormPanel(v, parent); |
e3a43801 JS |
391 | } |
392 | ||
393 | bool wxPropertyFormFrame::Initialize(void) | |
394 | { | |
f6bcfd97 BP |
395 | m_propertyPanel = OnCreatePanel(this, m_view); |
396 | if (m_propertyPanel) | |
397 | { | |
398 | m_view->AssociatePanel(m_propertyPanel); | |
399 | m_view->SetManagedWindow(this); | |
400 | return TRUE; | |
401 | } | |
402 | else | |
403 | return FALSE; | |
e3a43801 JS |
404 | } |
405 | ||
f6bcfd97 BP |
406 | /* |
407 | * Property form specific validator | |
408 | */ | |
409 | ||
e3a43801 JS |
410 | IMPLEMENT_ABSTRACT_CLASS(wxPropertyFormValidator, wxPropertyValidator) |
411 | ||
412 | ||
413 | /* | |
f6bcfd97 BP |
414 | * Default validators |
415 | */ | |
e3a43801 JS |
416 | |
417 | IMPLEMENT_DYNAMIC_CLASS(wxRealFormValidator, wxPropertyFormValidator) | |
418 | ||
419 | /// | |
420 | /// Real number form validator | |
1e6feb95 VZ |
421 | /// |
422 | bool wxRealFormValidator::OnCheckValue( wxProperty *property, wxPropertyFormView *WXUNUSED(view), | |
f6bcfd97 | 423 | wxWindow *parentWindow) |
e3a43801 | 424 | { |
f6bcfd97 BP |
425 | if (m_realMin == 0.0 && m_realMax == 0.0) |
426 | return TRUE; | |
1e6feb95 | 427 | |
f6bcfd97 BP |
428 | // The item used for viewing the real number: should be a text item. |
429 | wxWindow *m_propertyWindow = property->GetWindow(); | |
430 | if (!m_propertyWindow || !m_propertyWindow->IsKindOf(CLASSINFO(wxTextCtrl))) | |
431 | return FALSE; | |
1e6feb95 | 432 | |
f6bcfd97 | 433 | wxString value(((wxTextCtrl *)m_propertyWindow)->GetValue()); |
1e6feb95 | 434 | |
f6bcfd97 BP |
435 | float val = 0.0; |
436 | if (!StringToFloat(WXSTRINGCAST value, &val)) | |
437 | { | |
438 | wxChar buf[200]; | |
439 | wxSprintf(buf, wxT("Value %s is not a valid real number!"), (const wxChar *)value); | |
440 | wxMessageBox(buf, wxT("Property value error"), wxOK | wxICON_EXCLAMATION, parentWindow); | |
441 | return FALSE; | |
442 | } | |
1e6feb95 | 443 | |
f6bcfd97 BP |
444 | if (val < m_realMin || val > m_realMax) |
445 | { | |
446 | wxChar buf[200]; | |
447 | wxSprintf(buf, wxT("Value must be a real number between %.2f and %.2f!"), m_realMin, m_realMax); | |
448 | wxMessageBox(buf, wxT("Property value error"), wxOK | wxICON_EXCLAMATION, parentWindow); | |
449 | return FALSE; | |
450 | } | |
451 | return TRUE; | |
e3a43801 JS |
452 | } |
453 | ||
1e6feb95 | 454 | bool wxRealFormValidator::OnRetrieveValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view), |
f6bcfd97 | 455 | wxWindow *WXUNUSED(parentWindow) ) |
e3a43801 | 456 | { |
f6bcfd97 BP |
457 | // The item used for viewing the real number: should be a text item. |
458 | wxWindow *m_propertyWindow = property->GetWindow(); | |
459 | if (!m_propertyWindow || !m_propertyWindow->IsKindOf(CLASSINFO(wxTextCtrl))) | |
460 | return FALSE; | |
1e6feb95 | 461 | |
f6bcfd97 | 462 | wxString value(((wxTextCtrl *)m_propertyWindow)->GetValue()); |
1e6feb95 | 463 | |
f6bcfd97 BP |
464 | if (value.Length() == 0) |
465 | return FALSE; | |
1e6feb95 | 466 | |
f6bcfd97 BP |
467 | float f = (float)wxAtof((const wxChar *)value); |
468 | property->GetValue() = f; | |
469 | return TRUE; | |
e3a43801 JS |
470 | } |
471 | ||
1e6feb95 | 472 | bool wxRealFormValidator::OnDisplayValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view), |
f6bcfd97 | 473 | wxWindow *WXUNUSED(parentWindow) ) |
e3a43801 | 474 | { |
f6bcfd97 BP |
475 | // The item used for viewing the real number: should be a text item. |
476 | wxWindow *m_propertyWindow = property->GetWindow(); | |
477 | if (!m_propertyWindow || !m_propertyWindow->IsKindOf(CLASSINFO(wxTextCtrl))) | |
478 | return FALSE; | |
1e6feb95 | 479 | |
f6bcfd97 BP |
480 | wxTextCtrl *textItem = (wxTextCtrl *)m_propertyWindow; |
481 | textItem->SetValue(FloatToString(property->GetValue().RealValue())); | |
482 | return TRUE; | |
e3a43801 JS |
483 | } |
484 | ||
485 | /// | |
486 | /// Integer validator | |
1e6feb95 | 487 | /// |
e3a43801 JS |
488 | IMPLEMENT_DYNAMIC_CLASS(wxIntegerFormValidator, wxPropertyFormValidator) |
489 | ||
1e6feb95 | 490 | bool wxIntegerFormValidator::OnCheckValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view), |
f6bcfd97 | 491 | wxWindow *parentWindow) |
e3a43801 | 492 | { |
f6bcfd97 BP |
493 | if (m_integerMin == 0.0 && m_integerMax == 0.0) |
494 | return TRUE; | |
1e6feb95 | 495 | |
f6bcfd97 BP |
496 | // The item used for viewing the real number: should be a text item or a slider |
497 | wxWindow *m_propertyWindow = property->GetWindow(); | |
498 | if (!m_propertyWindow) | |
499 | return FALSE; | |
1e6feb95 | 500 | |
f6bcfd97 | 501 | long val = 0; |
1e6feb95 | 502 | |
f6bcfd97 BP |
503 | if (m_propertyWindow->IsKindOf(CLASSINFO(wxTextCtrl))) |
504 | { | |
505 | wxString value(((wxTextCtrl *)m_propertyWindow)->GetValue()); | |
1e6feb95 | 506 | |
f6bcfd97 BP |
507 | if (!StringToLong(WXSTRINGCAST value, &val)) |
508 | { | |
509 | wxChar buf[200]; | |
510 | wxSprintf(buf, wxT("Value %s is not a valid integer!"), (const wxChar *)value); | |
511 | wxMessageBox(buf, wxT("Property value error"), wxOK | wxICON_EXCLAMATION, parentWindow); | |
512 | return FALSE; | |
513 | } | |
514 | } | |
515 | else if (m_propertyWindow->IsKindOf(CLASSINFO(wxSlider))) | |
e3a43801 | 516 | { |
f6bcfd97 BP |
517 | val = (long)((wxSlider *)m_propertyWindow)->GetValue(); |
518 | } | |
519 | else | |
520 | return FALSE; | |
1e6feb95 | 521 | |
f6bcfd97 BP |
522 | if (val < m_integerMin || val > m_integerMax) |
523 | { | |
2b5f62a0 VZ |
524 | wxChar buf[200]; |
525 | wxSprintf(buf, wxT("Value must be an integer between %ld and %ld!"), m_integerMin, m_integerMax); | |
526 | wxMessageBox(buf, wxT("Property value error"), wxOK | wxICON_EXCLAMATION, parentWindow); | |
f6bcfd97 | 527 | return FALSE; |
e3a43801 | 528 | } |
f6bcfd97 | 529 | return TRUE; |
e3a43801 JS |
530 | } |
531 | ||
1e6feb95 | 532 | bool wxIntegerFormValidator::OnRetrieveValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view), |
f6bcfd97 | 533 | wxWindow *WXUNUSED(parentWindow)) |
e3a43801 | 534 | { |
f6bcfd97 BP |
535 | // The item used for viewing the real number: should be a text item or a slider |
536 | wxWindow *m_propertyWindow = property->GetWindow(); | |
537 | if (!m_propertyWindow) | |
538 | return FALSE; | |
1e6feb95 | 539 | |
f6bcfd97 BP |
540 | if (m_propertyWindow->IsKindOf(CLASSINFO(wxTextCtrl))) |
541 | { | |
542 | wxString value(((wxTextCtrl *)m_propertyWindow)->GetValue()); | |
1e6feb95 | 543 | |
f6bcfd97 BP |
544 | if (value.Length() == 0) |
545 | return FALSE; | |
1e6feb95 | 546 | |
f6bcfd97 BP |
547 | long i = wxAtol((const wxChar *)value); |
548 | property->GetValue() = i; | |
549 | } | |
550 | else if (m_propertyWindow->IsKindOf(CLASSINFO(wxSlider))) | |
551 | { | |
552 | property->GetValue() = (long)((wxSlider *)m_propertyWindow)->GetValue(); | |
553 | } | |
554 | else | |
555 | return FALSE; | |
1e6feb95 | 556 | |
f6bcfd97 | 557 | return TRUE; |
e3a43801 JS |
558 | } |
559 | ||
1e6feb95 | 560 | bool wxIntegerFormValidator::OnDisplayValue( wxProperty *property, wxPropertyFormView *WXUNUSED(view), |
f6bcfd97 | 561 | wxWindow *WXUNUSED(parentWindow)) |
e3a43801 | 562 | { |
f6bcfd97 BP |
563 | // The item used for viewing the real number: should be a text item or a slider |
564 | wxWindow *m_propertyWindow = property->GetWindow(); | |
565 | if (!m_propertyWindow) | |
566 | return FALSE; | |
1e6feb95 | 567 | |
f6bcfd97 BP |
568 | if (m_propertyWindow->IsKindOf(CLASSINFO(wxTextCtrl))) |
569 | { | |
570 | wxTextCtrl *textItem = (wxTextCtrl *)m_propertyWindow; | |
571 | textItem->SetValue(LongToString(property->GetValue().IntegerValue())); | |
572 | } | |
573 | else if (m_propertyWindow->IsKindOf(CLASSINFO(wxSlider))) | |
574 | { | |
575 | ((wxSlider *)m_propertyWindow)->SetValue((int)property->GetValue().IntegerValue()); | |
576 | } | |
577 | else | |
578 | return FALSE; | |
579 | return TRUE; | |
e3a43801 JS |
580 | } |
581 | ||
582 | /// | |
583 | /// Boolean validator | |
1e6feb95 | 584 | /// |
e3a43801 JS |
585 | IMPLEMENT_DYNAMIC_CLASS(wxBoolFormValidator, wxPropertyFormValidator) |
586 | ||
1e6feb95 | 587 | bool wxBoolFormValidator::OnCheckValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view), |
f6bcfd97 | 588 | wxWindow *WXUNUSED(parentWindow)) |
e3a43801 | 589 | { |
f6bcfd97 BP |
590 | // The item used for viewing the boolean: should be a checkbox |
591 | wxWindow *m_propertyWindow = property->GetWindow(); | |
592 | if (!m_propertyWindow || !m_propertyWindow->IsKindOf(CLASSINFO(wxCheckBox))) | |
593 | return FALSE; | |
1e6feb95 | 594 | |
f6bcfd97 | 595 | return TRUE; |
e3a43801 JS |
596 | } |
597 | ||
1e6feb95 | 598 | bool wxBoolFormValidator::OnRetrieveValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view), |
f6bcfd97 | 599 | wxWindow *WXUNUSED(parentWindow) ) |
e3a43801 | 600 | { |
f6bcfd97 BP |
601 | // The item used for viewing the boolean: should be a checkbox. |
602 | wxWindow *m_propertyWindow = property->GetWindow(); | |
603 | if (!m_propertyWindow || !m_propertyWindow->IsKindOf(CLASSINFO(wxCheckBox))) | |
604 | return FALSE; | |
1e6feb95 | 605 | |
f6bcfd97 | 606 | wxCheckBox *checkBox = (wxCheckBox *)m_propertyWindow; |
1e6feb95 | 607 | |
f6bcfd97 BP |
608 | property->GetValue() = (bool)checkBox->GetValue(); |
609 | return TRUE; | |
e3a43801 JS |
610 | } |
611 | ||
1e6feb95 | 612 | bool wxBoolFormValidator::OnDisplayValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view), |
f6bcfd97 | 613 | wxWindow *WXUNUSED(parentWindow)) |
e3a43801 | 614 | { |
f6bcfd97 BP |
615 | // The item used for viewing the boolean: should be a checkbox. |
616 | wxWindow *m_propertyWindow = property->GetWindow(); | |
617 | if (!m_propertyWindow || !m_propertyWindow->IsKindOf(CLASSINFO(wxCheckBox))) | |
618 | return FALSE; | |
1e6feb95 | 619 | |
f6bcfd97 BP |
620 | wxCheckBox *checkBox = (wxCheckBox *)m_propertyWindow; |
621 | checkBox->SetValue((bool)property->GetValue().BoolValue()); | |
622 | return TRUE; | |
e3a43801 JS |
623 | } |
624 | ||
625 | /// | |
626 | /// String validator | |
1e6feb95 | 627 | /// |
e3a43801 JS |
628 | IMPLEMENT_DYNAMIC_CLASS(wxStringFormValidator, wxPropertyFormValidator) |
629 | ||
630 | wxStringFormValidator::wxStringFormValidator(wxStringList *list, long flags): | |
f6bcfd97 | 631 | wxPropertyFormValidator(flags) |
e3a43801 | 632 | { |
f6bcfd97 | 633 | m_strings = list; |
e3a43801 JS |
634 | } |
635 | ||
1e6feb95 | 636 | bool wxStringFormValidator::OnCheckValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view), |
f6bcfd97 | 637 | wxWindow *parentWindow ) |
e3a43801 | 638 | { |
f6bcfd97 BP |
639 | if (!m_strings) |
640 | return TRUE; | |
1e6feb95 | 641 | |
f6bcfd97 BP |
642 | // The item used for viewing the string: should be a text item, choice item or listbox. |
643 | wxWindow *m_propertyWindow = property->GetWindow(); | |
644 | if (!m_propertyWindow) | |
645 | return FALSE; | |
646 | if (m_propertyWindow->IsKindOf(CLASSINFO(wxTextCtrl))) | |
e3a43801 | 647 | { |
f6bcfd97 BP |
648 | wxTextCtrl *text = (wxTextCtrl *)m_propertyWindow; |
649 | if (!m_strings->Member(text->GetValue())) | |
650 | { | |
2b5f62a0 VZ |
651 | wxString str( wxT("Value ") ); |
652 | str += text->GetValue(); | |
653 | str += wxT(" is not valid."); | |
654 | wxMessageBox(str, wxT("Property value error"), wxOK | wxICON_EXCLAMATION, parentWindow); | |
f6bcfd97 BP |
655 | return FALSE; |
656 | } | |
e3a43801 | 657 | } |
f6bcfd97 BP |
658 | else |
659 | { | |
660 | // Any other item constrains the string value, | |
661 | // so we don't have to check it. | |
662 | } | |
663 | return TRUE; | |
e3a43801 JS |
664 | } |
665 | ||
1e6feb95 | 666 | bool wxStringFormValidator::OnRetrieveValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view), |
f6bcfd97 BP |
667 | wxWindow *WXUNUSED(parentWindow) ) |
668 | { | |
669 | // The item used for viewing the string: should be a text item, choice item or listbox. | |
670 | wxWindow *m_propertyWindow = property->GetWindow(); | |
671 | if (!m_propertyWindow) | |
672 | return FALSE; | |
673 | if (m_propertyWindow->IsKindOf(CLASSINFO(wxTextCtrl))) | |
674 | { | |
675 | wxTextCtrl *text = (wxTextCtrl *)m_propertyWindow; | |
676 | property->GetValue() = text->GetValue(); | |
677 | } | |
678 | else if (m_propertyWindow->IsKindOf(CLASSINFO(wxListBox))) | |
679 | { | |
680 | wxListBox *lbox = (wxListBox *)m_propertyWindow; | |
681 | if (lbox->GetSelection() > -1) | |
682 | property->GetValue() = lbox->GetStringSelection(); | |
683 | } | |
684 | /* | |
685 | else if (m_propertyWindow->IsKindOf(CLASSINFO(wxRadioBox))) | |
686 | { | |
e3a43801 JS |
687 | wxRadioBox *rbox = (wxRadioBox *)m_propertyWindow; |
688 | int n = 0; | |
689 | if ((n = rbox->GetSelection()) > -1) | |
f6bcfd97 BP |
690 | property->GetValue() = rbox->GetString(n); |
691 | } | |
692 | */ | |
693 | else if (m_propertyWindow->IsKindOf(CLASSINFO(wxChoice))) | |
694 | { | |
695 | wxChoice *choice = (wxChoice *)m_propertyWindow; | |
696 | if (choice->GetSelection() > -1) | |
697 | property->GetValue() = choice->GetStringSelection(); | |
698 | } | |
699 | else | |
700 | return FALSE; | |
701 | return TRUE; | |
e3a43801 JS |
702 | } |
703 | ||
1e6feb95 | 704 | bool wxStringFormValidator::OnDisplayValue(wxProperty *property, wxPropertyFormView *WXUNUSED(view), |
f6bcfd97 BP |
705 | wxWindow *WXUNUSED(parentWindow) ) |
706 | { | |
707 | // The item used for viewing the string: should be a text item, choice item or listbox. | |
708 | wxWindow *m_propertyWindow = property->GetWindow(); | |
709 | if (!m_propertyWindow) | |
710 | return FALSE; | |
711 | if (m_propertyWindow->IsKindOf(CLASSINFO(wxTextCtrl))) | |
e3a43801 | 712 | { |
f6bcfd97 BP |
713 | wxTextCtrl *text = (wxTextCtrl *)m_propertyWindow; |
714 | text->SetValue(property->GetValue().StringValue()); | |
e3a43801 | 715 | } |
f6bcfd97 BP |
716 | else if (m_propertyWindow->IsKindOf(CLASSINFO(wxListBox))) |
717 | { | |
718 | wxListBox *lbox = (wxListBox *)m_propertyWindow; | |
6326010c | 719 | if (lbox->GetCount() == 0 && m_strings) |
f6bcfd97 BP |
720 | { |
721 | // Try to initialize the listbox from 'strings' | |
b1d4dd7a | 722 | wxStringList::Node *node = m_strings->GetFirst(); |
f6bcfd97 BP |
723 | while (node) |
724 | { | |
b1d4dd7a | 725 | wxChar *s = node->GetData(); |
f6bcfd97 | 726 | lbox->Append(s); |
b1d4dd7a | 727 | node = node->GetNext(); |
f6bcfd97 BP |
728 | } |
729 | } | |
730 | lbox->SetStringSelection(property->GetValue().StringValue()); | |
731 | } | |
732 | /* | |
733 | else if (m_propertyWindow->IsKindOf(CLASSINFO(wxRadioBox))) | |
734 | { | |
e3a43801 JS |
735 | wxRadioBox *rbox = (wxRadioBox *)m_propertyWindow; |
736 | rbox->SetStringSelection(property->GetValue().StringValue()); | |
e3a43801 | 737 | } |
f6bcfd97 BP |
738 | */ |
739 | else if (m_propertyWindow->IsKindOf(CLASSINFO(wxChoice))) | |
740 | { | |
741 | wxChoice *choice = (wxChoice *)m_propertyWindow; | |
6326010c | 742 | if (choice->GetCount() == 0 && m_strings) |
f6bcfd97 BP |
743 | { |
744 | // Try to initialize the choice item from 'strings' | |
745 | // XView doesn't allow this kind of thing. | |
b1d4dd7a | 746 | wxStringList::Node *node = m_strings->GetFirst(); |
f6bcfd97 BP |
747 | while (node) |
748 | { | |
b1d4dd7a | 749 | wxChar *s = node->GetData(); |
f6bcfd97 | 750 | choice->Append(s); |
b1d4dd7a | 751 | node = node->GetNext(); |
f6bcfd97 BP |
752 | } |
753 | } | |
f6bcfd97 BP |
754 | choice->SetStringSelection(property->GetValue().StringValue()); |
755 | } | |
756 | else | |
757 | return FALSE; | |
758 | return TRUE; | |
e3a43801 JS |
759 | } |
760 | ||
1e6feb95 | 761 | #endif // wxUSE_PROPSHEET |