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