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