]> git.saurik.com Git - wxWidgets.git/blame - src/generic/proplist.cpp
Finished porting Robin's wxSizers
[wxWidgets.git] / src / generic / proplist.cpp
CommitLineData
e3a43801
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: proplist.cpp
3// Purpose: Property list classes
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
29006414 9// Licence: wxWindows licence
e3a43801
JS
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "proplist.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
c693edf3
RR
27#include "wx/colordlg.h"
28#include "wx/proplist.h"
29
e3a43801
JS
30#include <ctype.h>
31#include <stdlib.h>
32#include <math.h>
33#include <string.h>
34
e3a43801
JS
35
36/*
37 * Property text edit control
38 */
29006414 39
e3a43801
JS
40IMPLEMENT_CLASS(wxPropertyTextEdit, wxTextCtrl)
41
42wxPropertyTextEdit::wxPropertyTextEdit(wxPropertyListView *v, wxWindow *parent,
43 const wxWindowID id, const wxString& value,
29006414 44 const wxPoint& pos, const wxSize& size,
e3a43801
JS
45 long style, const wxString& name):
46 wxTextCtrl(parent, id, value, pos, size, style, wxDefaultValidator, name)
47{
48 m_view = v;
49}
50
51void wxPropertyTextEdit::OnSetFocus(void)
52{
53}
54
55void wxPropertyTextEdit::OnKillFocus(void)
56{
57}
58
59/*
60 * Property list view
61 */
62
63IMPLEMENT_DYNAMIC_CLASS(wxPropertyListView, wxPropertyView)
64
65BEGIN_EVENT_TABLE(wxPropertyListView, wxPropertyView)
29006414
VZ
66 EVT_BUTTON(wxID_OK, wxPropertyListView::OnOk)
67 EVT_BUTTON(wxID_CANCEL, wxPropertyListView::OnCancel)
68 EVT_BUTTON(wxID_HELP, wxPropertyListView::OnHelp)
69 EVT_BUTTON(wxID_PROP_CROSS, wxPropertyListView::OnCross)
70 EVT_BUTTON(wxID_PROP_CHECK, wxPropertyListView::OnCheck)
71 EVT_BUTTON(wxID_PROP_EDIT, wxPropertyListView::OnEdit)
72 EVT_TEXT_ENTER(wxID_PROP_TEXT, wxPropertyListView::OnText)
73 EVT_LISTBOX(wxID_PROP_SELECT, wxPropertyListView::OnPropertySelect)
74 EVT_COMMAND(wxID_PROP_SELECT, wxEVT_COMMAND_LISTBOX_DOUBLECLICKED,
75 wxPropertyListView::OnPropertyDoubleClick)
76 EVT_LISTBOX(wxID_PROP_VALUE_SELECT, wxPropertyListView::OnValueListSelect)
e3a43801
JS
77END_EVENT_TABLE()
78
79bool wxPropertyListView::sm_dialogCancelled = FALSE;
80wxBitmap *wxPropertyListView::sm_tickBitmap = NULL;
81wxBitmap *wxPropertyListView::sm_crossBitmap = NULL;
82
83wxPropertyListView::wxPropertyListView(wxPanel *propPanel, long flags):wxPropertyView(flags)
84{
85 m_propertyScrollingList = NULL;
86 m_valueList = NULL;
87 m_valueText = NULL;
88 m_editButton = NULL;
89 m_confirmButton = NULL;
90 m_cancelButton = NULL;
91 m_propertyWindow = propPanel;
92 m_managedWindow = NULL;
93
94 m_windowCloseButton = NULL;
95 m_windowCancelButton = NULL;
96 m_windowHelpButton = NULL;
97
98 m_detailedEditing = FALSE;
99}
100
101wxPropertyListView::~wxPropertyListView(void)
102{
103/*
104 if (m_tickBitmap)
105 delete m_tickBitmap;
106 if (m_crossBitmap)
107 delete m_crossBitmap;
108*/
109}
110
111void wxPropertyListView::ShowView(wxPropertySheet *ps, wxPanel *panel)
112{
113 m_propertySheet = ps;
114
115 AssociatePanel(panel);
116 CreateControls();
117
118 UpdatePropertyList();
119 panel->Layout();
120}
121
122// Update this view of the viewed object, called e.g. by
123// the object itself.
124bool wxPropertyListView::OnUpdateView(void)
125{
126 return TRUE;
127}
128
129bool wxPropertyListView::UpdatePropertyList(bool clearEditArea)
130{
131 if (!m_propertyScrollingList || !m_propertySheet)
132 return FALSE;
133
134 m_propertyScrollingList->Clear();
135 if (clearEditArea)
136 {
137 m_valueList->Clear();
138 m_valueText->SetValue("");
139 }
140 wxNode *node = m_propertySheet->GetProperties().First();
141
142 // Should sort them... later...
143 while (node)
144 {
145 wxProperty *property = (wxProperty *)node->Data();
146 wxString stringValueRepr(property->GetValue().GetStringRepresentation());
147 wxString paddedString(MakeNameValueString(property->GetName(), stringValueRepr));
ee0fc54a 148 m_propertyScrollingList->Append(paddedString.GetData(), (void *)property);
e3a43801
JS
149 node = node->Next();
150 }
151 return TRUE;
152}
153
154bool wxPropertyListView::UpdatePropertyDisplayInList(wxProperty *property)
155{
156 if (!m_propertyScrollingList || !m_propertySheet)
157 return FALSE;
158
8710cf5c 159#ifdef __WXMSW__
e3a43801 160 int currentlySelected = m_propertyScrollingList->GetSelection();
8710cf5c 161#endif
e3a43801
JS
162// #ifdef __WXMSW__
163 wxString stringValueRepr(property->GetValue().GetStringRepresentation());
164 wxString paddedString(MakeNameValueString(property->GetName(), stringValueRepr));
165 int sel = FindListIndexForProperty(property);
166
167 if (sel > -1)
168 {
169 // Don't update the listbox unnecessarily because it can cause
170 // ugly flashing.
29006414 171
e3a43801
JS
172 if (paddedString != m_propertyScrollingList->GetString(sel))
173 m_propertyScrollingList->SetString(sel, paddedString.GetData());
174 }
175//#else
176// UpdatePropertyList(FALSE);
177//#endif
178
179 // TODO: why is this necessary?
180#ifdef __WXMSW__
181 if (currentlySelected > -1)
182 m_propertyScrollingList->SetSelection(currentlySelected);
183#endif
184
185 return TRUE;
186}
187
188// Find the wxListBox index corresponding to this property
189int wxPropertyListView::FindListIndexForProperty(wxProperty *property)
190{
191 int n = m_propertyScrollingList->Number();
192 for (int i = 0; i < n; i++)
193 {
194 if (property == (wxProperty *)m_propertyScrollingList->wxListBox::GetClientData(i))
195 return i;
196 }
197 return -1;
198}
199
200wxString wxPropertyListView::MakeNameValueString(wxString name, wxString value)
201{
202 wxString theString(name);
203
204 int nameWidth = 25;
205 int padWith = nameWidth - theString.Length();
206 if (padWith < 0)
207 padWith = 0;
208
209 if (GetFlags() & wxPROP_SHOWVALUES)
210 {
211 // Want to pad with spaces
212 theString.Append(' ', padWith);
213 theString += value;
214 }
215
216 return theString;
217}
218
219// Select and show string representation in validator the given
220// property. NULL resets to show no property.
221bool wxPropertyListView::ShowProperty(wxProperty *property, bool select)
222{
223 if (m_currentProperty)
224 {
225 EndShowingProperty(m_currentProperty);
226 m_currentProperty = NULL;
227 }
228
229 m_valueList->Clear();
230 m_valueText->SetValue("");
231
232 if (property)
233 {
234 m_currentProperty = property;
235 BeginShowingProperty(property);
236 }
237 if (select)
238 {
239 int sel = FindListIndexForProperty(property);
240 if (sel > -1)
241 m_propertyScrollingList->SetSelection(sel);
242 }
243 return TRUE;
244}
245
246// Find appropriate validator and load property into value controls
247bool wxPropertyListView::BeginShowingProperty(wxProperty *property)
248{
249 m_currentValidator = FindPropertyValidator(property);
250 if (!m_currentValidator)
251 return FALSE;
252
253 if (!m_currentValidator->IsKindOf(CLASSINFO(wxPropertyListValidator)))
254 return FALSE;
255
256 wxPropertyListValidator *listValidator = (wxPropertyListValidator *)m_currentValidator;
257
258 listValidator->OnPrepareControls(property, this, m_propertyWindow);
259 DisplayProperty(property);
260 return TRUE;
261}
262
263// Find appropriate validator and unload property from value controls
264bool wxPropertyListView::EndShowingProperty(wxProperty *property)
265{
266 if (!m_currentValidator)
267 return FALSE;
268
269 RetrieveProperty(property);
270
271 if (!m_currentValidator->IsKindOf(CLASSINFO(wxPropertyListValidator)))
272 return FALSE;
273
274 wxPropertyListValidator *listValidator = (wxPropertyListValidator *)m_currentValidator;
275
276 listValidator->OnClearControls(property, this, m_propertyWindow);
277 if (m_detailedEditing)
278 {
279 listValidator->OnClearDetailControls(property, this, m_propertyWindow);
280 m_detailedEditing = FALSE;
281 }
282 return TRUE;
283}
284
285void wxPropertyListView::BeginDetailedEditing(void)
286{
287 if (!m_currentValidator)
288 return;
289 if (!m_currentProperty)
290 return;
291 if (m_detailedEditing)
292 return;
293 if (!m_currentValidator->IsKindOf(CLASSINFO(wxPropertyListValidator)))
294 return;
295 if (!m_currentProperty->IsEnabled())
296 return;
297
298 wxPropertyListValidator *listValidator = (wxPropertyListValidator *)m_currentValidator;
299
300 if (listValidator->OnPrepareDetailControls(m_currentProperty, this, m_propertyWindow))
301 m_detailedEditing = TRUE;
302}
303
304void wxPropertyListView::EndDetailedEditing(void)
305{
306 if (!m_currentValidator)
307 return;
308 if (!m_currentProperty)
309 return;
310
311 RetrieveProperty(m_currentProperty);
312
313 if (!m_currentValidator->IsKindOf(CLASSINFO(wxPropertyListValidator)))
314 return;
315
316 wxPropertyListValidator *listValidator = (wxPropertyListValidator *)m_currentValidator;
317
318 if (m_detailedEditing)
319 {
320 listValidator->OnClearDetailControls(m_currentProperty, this, m_propertyWindow);
321 m_detailedEditing = FALSE;
322 }
323}
324
325bool wxPropertyListView::DisplayProperty(wxProperty *property)
326{
327 if (!m_currentValidator)
328 return FALSE;
329
330 if (((m_currentValidator->GetFlags() & wxPROP_ALLOW_TEXT_EDITING) == 0) || !property->IsEnabled())
331 m_valueText->SetEditable(FALSE);
332 else
333 m_valueText->SetEditable(TRUE);
334
335 if (!m_currentValidator->IsKindOf(CLASSINFO(wxPropertyListValidator)))
336 return FALSE;
337
338 wxPropertyListValidator *listValidator = (wxPropertyListValidator *)m_currentValidator;
339
340 listValidator->OnDisplayValue(property, this, m_propertyWindow);
341 return TRUE;
342}
343
344bool wxPropertyListView::RetrieveProperty(wxProperty *property)
345{
346 if (!m_currentValidator)
347 return FALSE;
348 if (!property->IsEnabled())
349 return FALSE;
350
351 if (!m_currentValidator->IsKindOf(CLASSINFO(wxPropertyListValidator)))
352 return FALSE;
353
354 wxPropertyListValidator *listValidator = (wxPropertyListValidator *)m_currentValidator;
355
356 if (listValidator->OnCheckValue(property, this, m_propertyWindow))
357 {
358 if (listValidator->OnRetrieveValue(property, this, m_propertyWindow))
359 {
360 UpdatePropertyDisplayInList(property);
361 OnPropertyChanged(property);
362 }
363 }
364 else
365 {
366 // Revert to old value
367 listValidator->OnDisplayValue(property, this, m_propertyWindow);
368 }
369 return TRUE;
370}
371
372
373bool wxPropertyListView::EditProperty(wxProperty *WXUNUSED(property))
374{
375 return TRUE;
376}
377
378// Called by the listbox callback
379void wxPropertyListView::OnPropertySelect(wxCommandEvent& WXUNUSED(event))
380{
381 int sel = m_propertyScrollingList->GetSelection();
382 if (sel > -1)
383 {
384 wxProperty *newSel = (wxProperty *)m_propertyScrollingList->wxListBox::GetClientData(sel);
385 if (newSel && newSel != m_currentProperty)
386 {
387 ShowProperty(newSel, FALSE);
388 }
389 }
390}
391
392bool wxPropertyListView::CreateControls(void)
393{
394 wxPanel *panel = (wxPanel *)m_propertyWindow;
395
396 int largeButtonWidth = 60;
397 int largeButtonHeight = 25;
398
399 int smallButtonWidth = 25;
400 int smallButtonHeight = 20;
401
402 // XView must be allowed to choose its own sized buttons
403#ifdef __XVIEW__
404 largeButtonWidth = -1;
405 largeButtonHeight = -1;
406
407 smallButtonWidth = -1;
408 smallButtonHeight = -1;
409#endif
29006414 410
e3a43801
JS
411 if (m_valueText)
412 return TRUE;
29006414 413
e3a43801
JS
414 if (!panel)
415 return FALSE;
416
417 wxWindow *leftMostWindow = panel;
8710cf5c 418/*
e3a43801
JS
419 wxWindow *topMostWindow = panel;
420 wxWindow *rightMostWindow = panel;
8710cf5c 421*/
e3a43801
JS
422
423 wxSystemSettings settings;
424 wxFont guiFont = settings.GetSystemFont(wxSYS_DEFAULT_GUI_FONT);
425
426#ifdef __WXMSW__
427 wxFont *boringFont = wxTheFontList->FindOrCreateFont(guiFont.GetPointSize(), wxMODERN, wxNORMAL, wxNORMAL, FALSE, "Courier New");
428#else
429 wxFont *boringFont = wxTheFontList->FindOrCreateFont(guiFont.GetPointSize(), wxTELETYPE, wxNORMAL, wxNORMAL);
430#endif
431
432 // May need to be changed in future to eliminate clashes with app.
433 // WHAT WAS THIS FOR?
434// panel->SetClientData((char *)this);
435
436 // These buttons are at the bottom of the window, but create them now
437 // so the constraints are evaluated in the correct order
438 if (m_buttonFlags & wxPROP_BUTTON_OK)
439 {
440 m_windowCloseButton = new wxButton(panel, wxID_OK, "OK",
441 wxPoint(-1, -1), wxSize(largeButtonWidth, largeButtonHeight));
442 m_windowCloseButton->SetDefault();
443 m_windowCloseButton->SetFocus();
444 }
445 else if (m_buttonFlags & wxPROP_BUTTON_CLOSE)
446 {
447 m_windowCloseButton = new wxButton(panel, wxID_OK, "Close",
448 wxPoint(-1, -1), wxSize(largeButtonWidth, largeButtonHeight));
449 }
450 if (m_buttonFlags & wxPROP_BUTTON_CANCEL)
451 {
452 m_windowCancelButton = new wxButton(panel, wxID_CANCEL, "Cancel",
453 wxPoint(-1, -1), wxSize(largeButtonWidth, largeButtonHeight));
454 }
455 if (m_buttonFlags & wxPROP_BUTTON_HELP)
456 {
457 m_windowHelpButton = new wxButton(panel, wxID_HELP, "Help",
458 wxPoint(-1, -1), wxSize(largeButtonWidth, largeButtonHeight));
459 }
460
461 if (m_windowCloseButton)
462 {
463 wxLayoutConstraints *c1 = new wxLayoutConstraints;
464
465 c1->left.SameAs (panel, wxLeft, 2);
466 c1->bottom.SameAs (panel, wxBottom, 2);
467 c1->width.AsIs();
468 c1->height.AsIs();
469 m_windowCloseButton->SetConstraints(c1);
470 leftMostWindow = m_windowCloseButton;
471 }
472 if (m_windowCancelButton)
473 {
474 wxLayoutConstraints *c2 = new wxLayoutConstraints;
475
476 c2->right.SameAs (panel, wxRight, 2);
477 c2->bottom.SameAs (panel, wxBottom, 2);
478 c2->width.AsIs();
479 c2->height.AsIs();
480 m_windowCancelButton->SetConstraints(c2);
481 leftMostWindow = m_windowCancelButton;
482 }
483 if (m_windowHelpButton)
484 {
485 wxLayoutConstraints *c2 = new wxLayoutConstraints;
486 if (leftMostWindow == panel)
487 c2->left.SameAs (panel, wxLeft, 2);
488 else
489 c2->left.RightOf (leftMostWindow, 2);
29006414 490
e3a43801
JS
491 c2->bottom.SameAs (panel, wxBottom, 2);
492 c2->width.AsIs();
493 c2->height.AsIs();
494 m_windowHelpButton->SetConstraints(c2);
495 leftMostWindow = m_windowHelpButton;
496 }
497
498 if (m_buttonFlags & wxPROP_BUTTON_CHECK_CROSS)
499 {
500/*
501 if (!tickBitmap)
502 {
503#ifdef __WXMSW__
504 tickBitmap = new wxBitmap("tick_bmp", wxBITMAP_TYPE_RESOURCE);
505 crossBitmap = new wxBitmap("cross_bmp", wxBITMAP_TYPE_RESOURCE);
506 if (!tickBitmap || !crossBitmap || !tickBitmap->Ok() || !crossBitmap->Ok())
507 {
508 if (tickBitmap)
509 delete tickBitmap;
510 if (crossBitmap)
511 delete crossBitmap;
512 tickBitmap = NULL;
513 crossBitmap = NULL;
514 }
515#endif
516 }
517*/
518/*
519 if (tickBitmap && crossBitmap)
520 {
521 m_confirmButton = new wxBitmapButton(panel, wxID_PROP_CHECK, tickBitmap,
522 wxPoint(-1, -1), wxSize(smallButtonWidth-5, smallButtonHeight-5));
523 m_cancelButton = new wxBitmapButton(panel, wxID_PROP_CROSS, crossBitmap,
524 wxPoint(-1, -1), wxSize(smallButtonWidth-5, smallButtonHeight-5));
525 }
526 else
527*/
528 {
529 m_confirmButton = new wxButton(panel, wxID_PROP_CHECK, ":-)",
530 wxPoint(-1, -1), wxSize(smallButtonWidth, smallButtonHeight));
531 m_cancelButton = new wxButton(panel, wxID_PROP_CROSS, "X",
532 wxPoint(-1, -1), wxSize(smallButtonWidth, smallButtonHeight));
533 }
534
535 wxLayoutConstraints *c = new wxLayoutConstraints;
536 c->left.SameAs (panel, wxLeft, 2);
537/*
538 if (windowCloseButton)
539 c->top.Below (m_windowCloseButton, 2);
540 else
541*/
542 c->top.SameAs (panel, wxTop, 2);
543
544 c->width.AsIs();
545 c->height.AsIs();
546
547 m_cancelButton->SetConstraints(c);
548
549 c = new wxLayoutConstraints;
550 c->left.RightOf (m_cancelButton, 2);
551 c->top.SameAs (m_cancelButton, wxTop, 0);
552 c->width.AsIs();
553 c->height.AsIs();
554
555 m_confirmButton->SetConstraints(c);
556
557 m_cancelButton->Enable(FALSE);
558 m_confirmButton->Enable(FALSE);
559 }
560
561 if (m_buttonFlags & wxPROP_PULLDOWN)
562 {
563 m_editButton = new wxButton(panel, wxID_PROP_EDIT, "...",
564 wxPoint(-1, -1), wxSize(smallButtonWidth, smallButtonHeight));
565 m_editButton->Enable(FALSE);
566 wxLayoutConstraints *c = new wxLayoutConstraints;
567
568/*
569 if (m_windowCloseButton)
570 c->top.Below (m_windowCloseButton, 2);
571 else
572*/
573 c->top.SameAs (panel, wxTop, 2);
574
575 c->right.SameAs (panel, wxRight, 2);
576 c->width.AsIs();
577 c->height.AsIs();
578 m_editButton->SetConstraints(c);
579 }
580
581 m_valueText = new wxPropertyTextEdit(this, panel, wxID_PROP_TEXT, "", wxPoint(-1, -1), wxSize(-1, -1), wxPROCESS_ENTER);
582 m_valueText->Enable(FALSE);
29006414 583
e3a43801
JS
584 wxLayoutConstraints *c = new wxLayoutConstraints;
585
586 if (m_cancelButton)
587 c->left.RightOf (m_confirmButton, 2);
588 else
589 c->left.SameAs (panel, wxLeft, 2);
590/*
591 if (m_windowCloseButton)
592 c->top.Below (m_windowCloseButton, 2);
593 else
594*/
595 c->top.SameAs (panel, wxTop, 2);
596
597 if (m_editButton)
598 c->right.LeftOf (m_editButton, 2);
599 else
600 c->right.SameAs (panel, wxRight, 2);
601 c->height.AsIs();
602
603 m_valueText->SetConstraints(c);
604
605 m_valueList = new wxListBox(panel, wxID_PROP_VALUE_SELECT, wxPoint(-1, -1), wxSize(-1, 60));
606 m_valueList->Show(FALSE);
607
608 c = new wxLayoutConstraints;
609
610 c->left.SameAs (panel, wxLeft, 2);
611 c->top.Below (m_valueText, 2);
612 c->right.SameAs (panel, wxRight, 2);
613 c->height.Absolute(60);
614
615 m_valueList->SetConstraints(c);
616
617 m_propertyScrollingList = new wxListBox(panel, wxID_PROP_SELECT,
618 wxPoint(-1, -1), wxSize(300, 300));
619 m_propertyScrollingList->SetFont(* boringFont);
620
621 c = new wxLayoutConstraints;
622
623 c->left.SameAs (panel, wxLeft, 2);
624
625 if (m_buttonFlags & wxPROP_DYNAMIC_VALUE_FIELD)
626 c->top.Below (m_valueText, 2);
627 else
628 c->top.Below (m_valueList, 2);
629
630 c->right.SameAs (panel, wxRight, 2);
631
632 if (m_windowCloseButton)
633 c->bottom.Above (m_windowCloseButton, -2);
634 else
635 c->bottom.SameAs (panel, wxBottom, 2);
636
637 m_propertyScrollingList->SetConstraints(c);
638
639 // Note: if this is called now, it causes a GPF.
640 // Why?
641// panel->Layout();
642
643 return TRUE;
644}
645
646void wxPropertyListView::ShowTextControl(bool show)
647{
648 if (m_valueText)
649 m_valueText->Show(show);
650}
651
652void wxPropertyListView::ShowListBoxControl(bool show)
653{
654 if (m_valueList)
655 {
656 m_valueList->Show(show);
657 if (m_buttonFlags & wxPROP_DYNAMIC_VALUE_FIELD)
658 {
659 wxLayoutConstraints *constraints = m_propertyScrollingList->GetConstraints();
660 if (constraints)
661 {
662 if (show)
663 {
664 constraints->top.Below(m_valueList, 2);
665 // Maintain back-pointer so when valueList is deleted,
666 // any reference to it from this window is removed.
667 m_valueList->AddConstraintReference(m_propertyScrollingList);
668 }
669 else
670 {
671 constraints->top.Below(m_valueText, 2);
672 m_valueText->AddConstraintReference(m_propertyScrollingList);
673 }
674 m_propertyWindow->Layout();
675 }
676 }
677 }
678}
679
680void wxPropertyListView::EnableCheck(bool show)
681{
682 if (m_confirmButton)
683 m_confirmButton->Enable(show);
684}
685
686void wxPropertyListView::EnableCross(bool show)
687{
688 if (m_cancelButton)
689 m_cancelButton->Enable(show);
690}
691
692bool wxPropertyListView::OnClose(void)
693{
694 // Retrieve the value if any
695 wxCommandEvent event;
696 OnCheck(event);
29006414 697
e3a43801
JS
698 delete this;
699 return TRUE;
700}
701
702void wxPropertyListView::OnValueListSelect(wxCommandEvent& WXUNUSED(event))
703{
704 if (m_currentProperty && m_currentValidator)
705 {
706 if (!m_currentValidator->IsKindOf(CLASSINFO(wxPropertyListValidator)))
707 return;
708
709 wxPropertyListValidator *listValidator = (wxPropertyListValidator *)m_currentValidator;
710
711 listValidator->OnValueListSelect(m_currentProperty, this, m_propertyWindow);
712 }
713}
714
715void wxPropertyListView::OnOk(wxCommandEvent& event)
716{
717 // Retrieve the value if any
718 OnCheck(event);
29006414 719
e3a43801
JS
720 m_managedWindow->Close(TRUE);
721}
722
723void wxPropertyListView::OnCancel(wxCommandEvent& WXUNUSED(event))
724{
725// SetReturnCode(wxID_CANCEL);
726 m_managedWindow->Close(TRUE);
727 sm_dialogCancelled = TRUE;
728}
729
730void wxPropertyListView::OnHelp(wxCommandEvent& WXUNUSED(event))
731{
732}
733
734void wxPropertyListView::OnCheck(wxCommandEvent& WXUNUSED(event))
735{
736 if (m_currentProperty)
737 {
738 RetrieveProperty(m_currentProperty);
739 }
740}
741
742void wxPropertyListView::OnCross(wxCommandEvent& WXUNUSED(event))
743{
744 if (m_currentProperty && m_currentValidator)
745 {
746 if (!m_currentValidator->IsKindOf(CLASSINFO(wxPropertyListValidator)))
747 return;
748
749 wxPropertyListValidator *listValidator = (wxPropertyListValidator *)m_currentValidator;
750
751 // Revert to old value
752 listValidator->OnDisplayValue(m_currentProperty, this, m_propertyWindow);
753 }
754}
755
756void wxPropertyListView::OnPropertyDoubleClick(wxCommandEvent& WXUNUSED(event))
757{
758 if (m_currentProperty && m_currentValidator)
759 {
760 if (!m_currentValidator->IsKindOf(CLASSINFO(wxPropertyListValidator)))
761 return;
762
763 wxPropertyListValidator *listValidator = (wxPropertyListValidator *)m_currentValidator;
764
765 // Revert to old value
766 listValidator->OnDoubleClick(m_currentProperty, this, m_propertyWindow);
767 }
768}
769
770void wxPropertyListView::OnEdit(wxCommandEvent& WXUNUSED(event))
771{
772 if (m_currentProperty && m_currentValidator)
773 {
774 if (!m_currentValidator->IsKindOf(CLASSINFO(wxPropertyListValidator)))
775 return;
776
777 wxPropertyListValidator *listValidator = (wxPropertyListValidator *)m_currentValidator;
778
779 listValidator->OnEdit(m_currentProperty, this, m_propertyWindow);
780 }
781}
782
783void wxPropertyListView::OnText(wxCommandEvent& event)
784{
785 if (event.GetEventType() == wxEVT_COMMAND_TEXT_ENTER)
786 {
787 OnCheck(event);
788 }
789}
790
791/*
792 * Property dialog box
793 */
29006414 794
e3a43801
JS
795IMPLEMENT_CLASS(wxPropertyListDialog, wxDialog)
796
797BEGIN_EVENT_TABLE(wxPropertyListDialog, wxDialog)
29006414 798 EVT_BUTTON(wxID_CANCEL, wxPropertyListDialog::OnCancel)
e3065973 799 EVT_CLOSE(wxPropertyListDialog::OnCloseWindow)
e3a43801
JS
800END_EVENT_TABLE()
801
802wxPropertyListDialog::wxPropertyListDialog(wxPropertyListView *v, wxWindow *parent,
29006414 803 const wxString& title, const wxPoint& pos,
e3a43801
JS
804 const wxSize& size, long style, const wxString& name):
805 wxDialog(parent, -1, title, pos, size, style, name)
806{
807 m_view = v;
808 m_view->AssociatePanel( ((wxPanel*)this) );
809 m_view->SetManagedWindow(this);
810 SetAutoLayout(TRUE);
811}
812
e3065973 813void wxPropertyListDialog::OnCloseWindow(wxCloseEvent& event)
e3a43801
JS
814{
815 if (m_view)
816 {
29006414 817 SetReturnCode(wxID_CANCEL);
e3a43801 818 m_view->OnClose();
29006414
VZ
819 m_view = NULL;
820 this->Destroy();
e3a43801
JS
821 }
822 else
e3065973
JS
823 {
824 event.Veto();
825 }
e3a43801
JS
826}
827
828void wxPropertyListDialog::OnCancel(wxCommandEvent& WXUNUSED(event))
829{
29006414 830 SetReturnCode(wxID_CANCEL);
e3a43801
JS
831 this->Close();
832}
833
8710cf5c 834void wxPropertyListDialog::OnDefaultAction(wxControl *WXUNUSED(item))
e3a43801
JS
835{
836/*
837 if (item == m_view->GetPropertyScrollingList())
838 view->OnDoubleClick();
839*/
840}
841
842// Extend event processing to search the view's event table
843bool wxPropertyListDialog::ProcessEvent(wxEvent& event)
844{
29006414
VZ
845 if ( !m_view || ! m_view->ProcessEvent(event) )
846 return wxEvtHandler::ProcessEvent(event);
847 else
848 return TRUE;
e3a43801
JS
849}
850
851/*
852 * Property panel
853 */
29006414 854
e3a43801
JS
855IMPLEMENT_CLASS(wxPropertyListPanel, wxPanel)
856
857BEGIN_EVENT_TABLE(wxPropertyListPanel, wxPanel)
858 EVT_SIZE(wxPropertyListPanel::OnSize)
859END_EVENT_TABLE()
860
861wxPropertyListPanel::~wxPropertyListPanel()
862{
863}
864
8710cf5c 865void wxPropertyListPanel::OnDefaultAction(wxControl *WXUNUSED(item))
e3a43801
JS
866{
867/*
868 if (item == view->GetPropertyScrollingList())
869 view->OnDoubleClick();
870*/
871}
872
873// Extend event processing to search the view's event table
874bool wxPropertyListPanel::ProcessEvent(wxEvent& event)
875{
29006414
VZ
876 if ( !m_view || ! m_view->ProcessEvent(event) )
877 return wxEvtHandler::ProcessEvent(event);
878 else
879 return TRUE;
e3a43801
JS
880}
881
882void wxPropertyListPanel::OnSize(wxSizeEvent& WXUNUSED(event))
883{
884 Layout();
885}
886
887/*
888 * Property frame
889 */
29006414 890
e3a43801
JS
891IMPLEMENT_CLASS(wxPropertyListFrame, wxFrame)
892
e3065973
JS
893BEGIN_EVENT_TABLE(wxPropertyListFrame, wxFrame)
894 EVT_CLOSE(wxPropertyListFrame::OnCloseWindow)
895END_EVENT_TABLE()
896
897void wxPropertyListFrame::OnCloseWindow(wxCloseEvent& event)
e3a43801
JS
898{
899 if (m_view)
900 {
901 if (m_propertyPanel)
902 m_propertyPanel->SetView(NULL);
903 m_view->OnClose();
904 m_view = NULL;
e3065973 905 this->Destroy();
e3a43801
JS
906 }
907 else
e3065973
JS
908 {
909 event.Veto();
910 }
e3a43801
JS
911}
912
913wxPropertyListPanel *wxPropertyListFrame::OnCreatePanel(wxFrame *parent, wxPropertyListView *v)
914{
915 return new wxPropertyListPanel(v, parent);
916}
917
918bool wxPropertyListFrame::Initialize(void)
919{
920 m_propertyPanel = OnCreatePanel(this, m_view);
921 if (m_propertyPanel)
922 {
923 m_view->AssociatePanel(m_propertyPanel);
924 m_view->SetManagedWindow(this);
925 m_propertyPanel->SetAutoLayout(TRUE);
926 return TRUE;
927 }
928 else
929 return FALSE;
930}
931
932 /*
933 * Property list specific validator
934 */
29006414 935
e3a43801
JS
936IMPLEMENT_ABSTRACT_CLASS(wxPropertyListValidator, wxPropertyValidator)
937
938bool wxPropertyListValidator::OnSelect(bool select, wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow)
939{
940// view->GetValueText()->Show(TRUE);
941 if (select)
942 OnDisplayValue(property, view, parentWindow);
943
944 return TRUE;
945}
946
8710cf5c 947bool wxPropertyListValidator::OnValueListSelect(wxProperty *property, wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow))
e3a43801
JS
948{
949 wxString s(view->GetValueList()->GetStringSelection());
ee0fc54a 950 if (s != _T(""))
e3a43801
JS
951 {
952 view->GetValueText()->SetValue(s);
953 view->RetrieveProperty(property);
954 }
955 return TRUE;
956}
957
8710cf5c 958bool wxPropertyListValidator::OnDisplayValue(wxProperty *property, wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow))
e3a43801
JS
959{
960// view->GetValueText()->Show(TRUE);
961 wxString str(property->GetValue().GetStringRepresentation());
962
963 view->GetValueText()->SetValue(str);
964 return TRUE;
965}
966
967// Called when TICK is pressed or focus is lost or view wants to update
968// the property list.
969// Does the transferance from the property editing area to the property itself
8710cf5c 970bool wxPropertyListValidator::OnRetrieveValue(wxProperty *WXUNUSED(property), wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow))
e3a43801
JS
971{
972 if (!view->GetValueText())
973 return FALSE;
974 return FALSE;
975}
976
8710cf5c 977void wxPropertyListValidator::OnEdit(wxProperty *WXUNUSED(property), wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow))
e3a43801
JS
978{
979 if (view->GetDetailedEditing())
980 view->EndDetailedEditing();
981 else
982 view->BeginDetailedEditing();
983}
984
8710cf5c 985bool wxPropertyListValidator::OnClearControls(wxProperty *WXUNUSED(property), wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow))
e3a43801
JS
986{
987 if (view->GetConfirmButton())
988 view->GetConfirmButton()->Enable(FALSE);
989 if (view->GetCancelButton())
990 view->GetCancelButton()->Enable(FALSE);
991 if (view->GetEditButton())
992 view->GetEditButton()->Enable(FALSE);
993 return TRUE;
994}
995
996/*
997 * Default validators
998 */
999
1000IMPLEMENT_DYNAMIC_CLASS(wxRealListValidator, wxPropertyListValidator)
1001
1002///
1003/// Real number validator
29006414 1004///
8710cf5c 1005bool wxRealListValidator::OnCheckValue(wxProperty *WXUNUSED(property), wxPropertyListView *view, wxWindow *parentWindow)
e3a43801
JS
1006{
1007 if (m_realMin == 0.0 && m_realMax == 0.0)
1008 return TRUE;
29006414 1009
e3a43801
JS
1010 if (!view->GetValueText())
1011 return FALSE;
1012 wxString value(view->GetValueText()->GetValue());
1013
1014 float val = 0.0;
1015 if (!StringToFloat(WXSTRINGCAST value, &val))
1016 {
87138c52
OK
1017 wxChar buf[200];
1018 wxSprintf(buf, _T("Value %s is not a valid real number!"), value.GetData());
1019 wxMessageBox(buf, _T("Property value error"), wxOK | wxICON_EXCLAMATION, parentWindow);
e3a43801
JS
1020 return FALSE;
1021 }
29006414 1022
e3a43801
JS
1023 if (val < m_realMin || val > m_realMax)
1024 {
1025 char buf[200];
1026 sprintf(buf, "Value must be a real number between %.2f and %.2f!", m_realMin, m_realMax);
1027 wxMessageBox(buf, "Property value error", wxOK | wxICON_EXCLAMATION, parentWindow);
1028 return FALSE;
1029 }
1030 return TRUE;
1031}
1032
1033// Called when TICK is pressed or focus is lost or view wants to update
1034// the property list.
1035// Does the transferance from the property editing area to the property itself
8710cf5c 1036bool wxRealListValidator::OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow))
e3a43801
JS
1037{
1038 if (!view->GetValueText())
1039 return FALSE;
1040
87138c52 1041 if (wxStrlen(view->GetValueText()->GetValue()) == 0)
e3a43801 1042 return FALSE;
29006414 1043
e3a43801 1044 wxString value(view->GetValueText()->GetValue());
87138c52 1045 float f = (float)wxAtof(value.GetData());
e3a43801
JS
1046 property->GetValue() = f;
1047 return TRUE;
1048}
1049
8710cf5c 1050bool wxRealListValidator::OnPrepareControls(wxProperty *WXUNUSED(property), wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow))
e3a43801
JS
1051{
1052 if (view->GetConfirmButton())
1053 view->GetConfirmButton()->Enable(TRUE);
1054 if (view->GetCancelButton())
1055 view->GetCancelButton()->Enable(TRUE);
1056 if (view->GetEditButton())
1057 view->GetEditButton()->Enable(FALSE);
1058 if (view->GetValueText())
1059 view->GetValueText()->Enable(TRUE);
1060 return TRUE;
1061}
1062
1063///
1064/// Integer validator
29006414 1065///
e3a43801
JS
1066IMPLEMENT_DYNAMIC_CLASS(wxIntegerListValidator, wxPropertyListValidator)
1067
8710cf5c 1068bool wxIntegerListValidator::OnCheckValue(wxProperty *WXUNUSED(property), wxPropertyListView *view, wxWindow *parentWindow)
e3a43801
JS
1069{
1070 if (m_integerMin == 0 && m_integerMax == 0)
1071 return TRUE;
29006414 1072
e3a43801
JS
1073 if (!view->GetValueText())
1074 return FALSE;
1075 wxString value(view->GetValueText()->GetValue());
1076
1077 long val = 0;
1078 if (!StringToLong(WXSTRINGCAST value, &val))
1079 {
87138c52
OK
1080 wxChar buf[200];
1081 wxSprintf(buf, _T("Value %s is not a valid integer!"), value.GetData());
1082 wxMessageBox(buf, _T("Property value error"), wxOK | wxICON_EXCLAMATION, parentWindow);
e3a43801
JS
1083 return FALSE;
1084 }
1085 if (val < m_integerMin || val > m_integerMax)
1086 {
87138c52
OK
1087 wxChar buf[200];
1088 wxSprintf(buf, _T("Value must be an integer between %ld and %ld!"), m_integerMin, m_integerMax);
1089 wxMessageBox(buf, _T("Property value error"), wxOK | wxICON_EXCLAMATION, parentWindow);
e3a43801
JS
1090 return FALSE;
1091 }
1092 return TRUE;
1093}
1094
1095// Called when TICK is pressed or focus is lost or view wants to update
1096// the property list.
1097// Does the transferance from the property editing area to the property itself
8710cf5c 1098bool wxIntegerListValidator::OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow))
e3a43801
JS
1099{
1100 if (!view->GetValueText())
1101 return FALSE;
1102
87138c52 1103 if (wxStrlen(view->GetValueText()->GetValue()) == 0)
e3a43801 1104 return FALSE;
29006414 1105
e3a43801 1106 wxString value(view->GetValueText()->GetValue());
87138c52 1107 long val = (long)wxAtoi(value.GetData());
e3a43801
JS
1108 property->GetValue() = (long)val;
1109 return TRUE;
1110}
1111
8710cf5c 1112bool wxIntegerListValidator::OnPrepareControls(wxProperty *WXUNUSED(property), wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow))
e3a43801
JS
1113{
1114 if (view->GetConfirmButton())
1115 view->GetConfirmButton()->Enable(TRUE);
1116 if (view->GetCancelButton())
1117 view->GetCancelButton()->Enable(TRUE);
1118 if (view->GetEditButton())
1119 view->GetEditButton()->Enable(FALSE);
1120 if (view->GetValueText())
1121 view->GetValueText()->Enable(TRUE);
1122 return TRUE;
1123}
1124
1125///
1126/// boolean validator
1127///
1128IMPLEMENT_DYNAMIC_CLASS(wxBoolListValidator, wxPropertyListValidator)
1129
8710cf5c 1130bool wxBoolListValidator::OnCheckValue(wxProperty *WXUNUSED(property), wxPropertyListView *view, wxWindow *parentWindow)
e3a43801
JS
1131{
1132 if (!view->GetValueText())
1133 return FALSE;
1134 wxString value(view->GetValueText()->GetValue());
87138c52 1135 if (value != _T("True") && value != _T("False"))
e3a43801 1136 {
87138c52 1137 wxMessageBox(_T("Value must be True or False!"), _T("Property value error"), wxOK | wxICON_EXCLAMATION, parentWindow);
e3a43801
JS
1138 return FALSE;
1139 }
1140 return TRUE;
1141}
1142
1143// Called when TICK is pressed or focus is lost or view wants to update
1144// the property list.
1145// Does the transferance from the property editing area to the property itself
8710cf5c 1146bool wxBoolListValidator::OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow))
e3a43801
JS
1147{
1148 if (!view->GetValueText())
1149 return FALSE;
1150
87138c52 1151 if (wxStrlen(view->GetValueText()->GetValue()) == 0)
e3a43801 1152 return FALSE;
29006414 1153
e3a43801
JS
1154 wxString value(view->GetValueText()->GetValue());
1155 bool boolValue = FALSE;
87138c52 1156 if (value == _T("True"))
e3a43801
JS
1157 boolValue = TRUE;
1158 else
1159 boolValue = FALSE;
1160 property->GetValue() = (bool)boolValue;
1161 return TRUE;
1162}
1163
8710cf5c 1164bool wxBoolListValidator::OnDisplayValue(wxProperty *property, wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow))
e3a43801
JS
1165{
1166 if (!view->GetValueText())
1167 return FALSE;
1168 wxString str(property->GetValue().GetStringRepresentation());
1169
1170 view->GetValueText()->SetValue(str);
1171
1172 if (view->GetValueList()->IsShown())
1173 {
1174 view->GetValueList()->SetStringSelection(str);
1175 }
1176 return TRUE;
1177}
1178
8710cf5c 1179bool wxBoolListValidator::OnPrepareControls(wxProperty *WXUNUSED(property), wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow))
e3a43801
JS
1180{
1181 if (view->GetConfirmButton())
1182 view->GetConfirmButton()->Enable(FALSE);
1183 if (view->GetCancelButton())
1184 view->GetCancelButton()->Enable(FALSE);
1185 if (view->GetEditButton())
1186 view->GetEditButton()->Enable(TRUE);
1187 if (view->GetValueText())
1188 view->GetValueText()->Enable(FALSE);
1189 return TRUE;
1190}
1191
8710cf5c 1192bool wxBoolListValidator::OnPrepareDetailControls(wxProperty *WXUNUSED(property), wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow))
e3a43801
JS
1193{
1194 if (view->GetValueList())
1195 {
1196 view->ShowListBoxControl(TRUE);
1197 view->GetValueList()->Enable(TRUE);
29006414 1198
87138c52
OK
1199 view->GetValueList()->Append(_T("True"));
1200 view->GetValueList()->Append(_T("False"));
1201 wxChar *currentString = copystring(view->GetValueText()->GetValue());
e3a43801
JS
1202 view->GetValueList()->SetStringSelection(currentString);
1203 delete[] currentString;
1204 }
1205 return TRUE;
1206}
1207
8710cf5c 1208bool wxBoolListValidator::OnClearDetailControls(wxProperty *WXUNUSED(property), wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow))
e3a43801
JS
1209{
1210 if (view->GetValueList())
1211 {
1212 view->GetValueList()->Clear();
1213 view->ShowListBoxControl(FALSE);
1214 view->GetValueList()->Enable(FALSE);
1215 }
1216 return TRUE;
1217}
1218
1219// Called when the property is double clicked. Extra functionality can be provided,
1220// cycling through possible values.
8710cf5c 1221bool wxBoolListValidator::OnDoubleClick(wxProperty *property, wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow))
e3a43801
JS
1222{
1223 if (!view->GetValueText())
1224 return FALSE;
1225 if (property->GetValue().BoolValue())
1226 property->GetValue() = (bool)FALSE;
1227 else
1228 property->GetValue() = (bool)TRUE;
1229 view->DisplayProperty(property);
1230 view->UpdatePropertyDisplayInList(property);
1231 view->OnPropertyChanged(property);
1232 return TRUE;
1233}
1234
1235///
1236/// String validator
29006414 1237///
e3a43801
JS
1238IMPLEMENT_DYNAMIC_CLASS(wxStringListValidator, wxPropertyListValidator)
1239
1240wxStringListValidator::wxStringListValidator(wxStringList *list, long flags):
1241 wxPropertyListValidator(flags)
1242{
1243 m_strings = list;
1244 // If no constraint, we just allow the string to be edited.
1245 if (!m_strings && ((m_validatorFlags & wxPROP_ALLOW_TEXT_EDITING) == 0))
1246 m_validatorFlags |= wxPROP_ALLOW_TEXT_EDITING;
1247}
1248
8710cf5c 1249bool wxStringListValidator::OnCheckValue(wxProperty *WXUNUSED(property), wxPropertyListView *view, wxWindow *parentWindow)
e3a43801
JS
1250{
1251 if (!m_strings)
1252 return TRUE;
1253
1254 if (!view->GetValueText())
1255 return FALSE;
1256 wxString value(view->GetValueText()->GetValue());
1257
1258 if (!m_strings->Member(value.GetData()))
1259 {
1260 wxString s("Value ");
1261 s += value.GetData();
1262 s += " is not valid.";
1263 wxMessageBox(s.GetData(), "Property value error", wxOK | wxICON_EXCLAMATION, parentWindow);
1264 return FALSE;
1265 }
1266 return TRUE;
1267}
1268
1269// Called when TICK is pressed or focus is lost or view wants to update
1270// the property list.
1271// Does the transferance from the property editing area to the property itself
8710cf5c 1272bool wxStringListValidator::OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow))
e3a43801
JS
1273{
1274 if (!view->GetValueText())
1275 return FALSE;
1276 wxString value(view->GetValueText()->GetValue());
1277 property->GetValue() = value ;
1278 return TRUE;
1279}
1280
1281// Called when TICK is pressed or focus is lost or view wants to update
1282// the property list.
1283// Does the transferance from the property editing area to the property itself
8710cf5c 1284bool wxStringListValidator::OnDisplayValue(wxProperty *property, wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow))
e3a43801
JS
1285{
1286 if (!view->GetValueText())
1287 return FALSE;
1288 wxString str(property->GetValue().GetStringRepresentation());
1289 view->GetValueText()->SetValue(str);
1290 if (m_strings && view->GetValueList() && view->GetValueList()->IsShown() && view->GetValueList()->Number() > 0)
1291 {
1292 view->GetValueList()->SetStringSelection(str);
1293 }
1294 return TRUE;
1295}
1296
8710cf5c 1297bool wxStringListValidator::OnPrepareControls(wxProperty *WXUNUSED(property), wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow))
e3a43801
JS
1298{
1299 // Unconstrained
1300 if (!m_strings)
1301 {
1302 if (view->GetEditButton())
1303 view->GetEditButton()->Enable(FALSE);
1304 if (view->GetConfirmButton())
1305 view->GetConfirmButton()->Enable(TRUE);
1306 if (view->GetCancelButton())
1307 view->GetCancelButton()->Enable(TRUE);
1308 if (view->GetValueText())
1309 view->GetValueText()->Enable(TRUE);
1310 return TRUE;
1311 }
29006414 1312
e3a43801
JS
1313 // Constrained
1314 if (view->GetValueText())
1315 view->GetValueText()->Enable(FALSE);
1316
1317 if (view->GetEditButton())
1318 view->GetEditButton()->Enable(TRUE);
1319
1320 if (view->GetConfirmButton())
1321 view->GetConfirmButton()->Enable(FALSE);
1322 if (view->GetCancelButton())
1323 view->GetCancelButton()->Enable(FALSE);
1324 return TRUE;
1325}
1326
8710cf5c 1327bool wxStringListValidator::OnPrepareDetailControls(wxProperty *property, wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow))
e3a43801
JS
1328{
1329 if (view->GetValueList())
1330 {
1331 view->ShowListBoxControl(TRUE);
1332 view->GetValueList()->Enable(TRUE);
1333 wxNode *node = m_strings->First();
1334 while (node)
1335 {
87138c52 1336 wxChar *s = (wxChar *)node->Data();
e3a43801
JS
1337 view->GetValueList()->Append(s);
1338 node = node->Next();
1339 }
87138c52 1340 wxChar *currentString = property->GetValue().StringValue();
e3a43801
JS
1341 view->GetValueList()->SetStringSelection(currentString);
1342 }
1343 return TRUE;
1344}
1345
8710cf5c 1346bool wxStringListValidator::OnClearDetailControls(wxProperty *WXUNUSED(property), wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow))
e3a43801
JS
1347{
1348 if (!m_strings)
1349 {
1350 return TRUE;
1351 }
1352
1353 if (view->GetValueList())
1354 {
1355 view->GetValueList()->Clear();
1356 view->ShowListBoxControl(FALSE);
1357 view->GetValueList()->Enable(FALSE);
1358 }
1359 return TRUE;
1360}
1361
1362// Called when the property is double clicked. Extra functionality can be provided,
1363// cycling through possible values.
8710cf5c 1364bool wxStringListValidator::OnDoubleClick(wxProperty *property, wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow))
e3a43801
JS
1365{
1366 if (!view->GetValueText())
1367 return FALSE;
1368 if (!m_strings)
1369 return FALSE;
1370
1371 wxNode *node = m_strings->First();
87138c52 1372 wxChar *currentString = property->GetValue().StringValue();
e3a43801
JS
1373 while (node)
1374 {
87138c52
OK
1375 wxChar *s = (wxChar *)node->Data();
1376 if (wxStrcmp(s, currentString) == 0)
e3a43801 1377 {
87138c52 1378 wxChar *nextString = NULL;
e3a43801 1379 if (node->Next())
87138c52 1380 nextString = (wxChar *)node->Next()->Data();
e3a43801 1381 else
87138c52 1382 nextString = (wxChar *)m_strings->First()->Data();
e3a43801
JS
1383 property->GetValue() = wxString(nextString);
1384 view->DisplayProperty(property);
1385 view->UpdatePropertyDisplayInList(property);
1386 view->OnPropertyChanged(property);
1387 return TRUE;
1388 }
1389 else node = node->Next();
1390 }
1391 return TRUE;
1392}
1393
1394///
1395/// Filename validator
29006414 1396///
e3a43801
JS
1397IMPLEMENT_DYNAMIC_CLASS(wxFilenameListValidator, wxPropertyListValidator)
1398
1399wxFilenameListValidator::wxFilenameListValidator(wxString message , wxString wildcard, long flags):
1400 wxPropertyListValidator(flags), m_filenameWildCard(wildcard), m_filenameMessage(message)
1401{
1402}
1403
1404wxFilenameListValidator::~wxFilenameListValidator(void)
1405{
1406}
1407
8710cf5c 1408bool wxFilenameListValidator::OnCheckValue(wxProperty *WXUNUSED(property), wxPropertyListView *WXUNUSED(view), wxWindow *WXUNUSED(parentWindow))
e3a43801
JS
1409{
1410 return TRUE;
1411}
1412
1413// Called when TICK is pressed or focus is lost or view wants to update
1414// the property list.
1415// Does the transferance from the property editing area to the property itself
8710cf5c 1416bool wxFilenameListValidator::OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow))
e3a43801
JS
1417{
1418 if (!view->GetValueText())
1419 return FALSE;
1420 wxString value(view->GetValueText()->GetValue());
1421 property->GetValue() = value ;
1422 return TRUE;
1423}
1424
1425// Called when TICK is pressed or focus is lost or view wants to update
1426// the property list.
1427// Does the transferance from the property editing area to the property itself
8710cf5c 1428bool wxFilenameListValidator::OnDisplayValue(wxProperty *property, wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow))
e3a43801
JS
1429{
1430 if (!view->GetValueText())
1431 return FALSE;
1432 wxString str(property->GetValue().GetStringRepresentation());
1433 view->GetValueText()->SetValue(str);
1434 return TRUE;
1435}
1436
1437// Called when the property is double clicked. Extra functionality can be provided,
1438// cycling through possible values.
1439bool wxFilenameListValidator::OnDoubleClick(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow)
1440{
1441 if (!view->GetValueText())
1442 return FALSE;
1443 OnEdit(property, view, parentWindow);
1444 return TRUE;
1445}
1446
8710cf5c 1447bool wxFilenameListValidator::OnPrepareControls(wxProperty *WXUNUSED(property), wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow))
e3a43801
JS
1448{
1449 if (view->GetConfirmButton())
1450 view->GetConfirmButton()->Enable(TRUE);
1451 if (view->GetCancelButton())
1452 view->GetCancelButton()->Enable(TRUE);
1453 if (view->GetEditButton())
1454 view->GetEditButton()->Enable(TRUE);
1455 if (view->GetValueText())
1456 view->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING) == wxPROP_ALLOW_TEXT_EDITING);
1457 return TRUE;
1458}
1459
1460void wxFilenameListValidator::OnEdit(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow)
1461{
1462 if (!view->GetValueText())
1463 return;
1464
227869da 1465 wxString s = wxFileSelector(
e3a43801
JS
1466 m_filenameMessage.GetData(),
1467 wxPathOnly(property->GetValue().StringValue()),
1468 wxFileNameFromPath(property->GetValue().StringValue()),
1469 NULL,
1470 m_filenameWildCard.GetData(),
1471 0,
1472 parentWindow);
ee0fc54a 1473 if (s != _T(""))
e3a43801 1474 {
227869da 1475 property->GetValue() = s;
e3a43801
JS
1476 view->DisplayProperty(property);
1477 view->UpdatePropertyDisplayInList(property);
1478 view->OnPropertyChanged(property);
1479 }
1480}
1481
1482///
1483/// Colour validator
29006414 1484///
e3a43801
JS
1485IMPLEMENT_DYNAMIC_CLASS(wxColourListValidator, wxPropertyListValidator)
1486
1487wxColourListValidator::wxColourListValidator(long flags):
1488 wxPropertyListValidator(flags)
1489{
1490}
1491
1492wxColourListValidator::~wxColourListValidator(void)
1493{
1494}
1495
8710cf5c 1496bool wxColourListValidator::OnCheckValue(wxProperty *WXUNUSED(property), wxPropertyListView *WXUNUSED(view), wxWindow *WXUNUSED(parentWindow))
e3a43801
JS
1497{
1498 return TRUE;
1499}
1500
1501// Called when TICK is pressed or focus is lost or view wants to update
1502// the property list.
1503// Does the transferance from the property editing area to the property itself
8710cf5c 1504bool wxColourListValidator::OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow))
e3a43801
JS
1505{
1506 if (!view->GetValueText())
1507 return FALSE;
1508 wxString value(view->GetValueText()->GetValue());
29006414 1509
e3a43801
JS
1510 property->GetValue() = value ;
1511 return TRUE;
1512}
1513
1514// Called when TICK is pressed or focus is lost or view wants to update
1515// the property list.
1516// Does the transferance from the property editing area to the property itself
8710cf5c 1517bool wxColourListValidator::OnDisplayValue(wxProperty *property, wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow))
e3a43801
JS
1518{
1519 if (!view->GetValueText())
1520 return FALSE;
1521 wxString str(property->GetValue().GetStringRepresentation());
1522 view->GetValueText()->SetValue(str);
1523 return TRUE;
1524}
1525
1526// Called when the property is double clicked. Extra functionality can be provided,
1527// cycling through possible values.
1528bool wxColourListValidator::OnDoubleClick(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow)
1529{
1530 if (!view->GetValueText())
1531 return FALSE;
1532 OnEdit(property, view, parentWindow);
1533 return TRUE;
1534}
1535
8710cf5c 1536bool wxColourListValidator::OnPrepareControls(wxProperty *WXUNUSED(property), wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow))
e3a43801
JS
1537{
1538 if (view->GetConfirmButton())
1539 view->GetConfirmButton()->Enable(TRUE);
1540 if (view->GetCancelButton())
1541 view->GetCancelButton()->Enable(TRUE);
1542 if (view->GetEditButton())
1543 view->GetEditButton()->Enable(TRUE);
1544 if (view->GetValueText())
1545 view->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING) == wxPROP_ALLOW_TEXT_EDITING);
1546 return TRUE;
1547}
1548
1549void wxColourListValidator::OnEdit(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow)
1550{
1551 if (!view->GetValueText())
1552 return;
29006414 1553
87138c52 1554 wxChar *s = property->GetValue().StringValue();
e3a43801
JS
1555 int r = 0;
1556 int g = 0;
1557 int b = 0;
1558 if (s)
1559 {
1560 r = wxHexToDec(s);
1561 g = wxHexToDec(s+2);
1562 b = wxHexToDec(s+4);
1563 }
29006414 1564
e3a43801 1565 wxColour col(r,g,b);
29006414 1566
e3a43801
JS
1567 wxColourData data;
1568 data.SetChooseFull(TRUE);
1569 data.SetColour(col);
29006414 1570
e3a43801
JS
1571 for (int i = 0; i < 16; i++)
1572 {
1573 wxColour colour(i*16, i*16, i*16);
1574 data.SetCustomColour(i, colour);
1575 }
29006414 1576
e3a43801
JS
1577 wxColourDialog dialog(parentWindow, &data);
1578 if (dialog.ShowModal() != wxID_CANCEL)
1579 {
1580 wxColourData retData = dialog.GetColourData();
1581 col = retData.GetColour();
29006414 1582
87138c52 1583 wxChar buf[7];
e3a43801
JS
1584 wxDecToHex(col.Red(), buf);
1585 wxDecToHex(col.Green(), buf+2);
1586 wxDecToHex(col.Blue(), buf+4);
1587
1588 property->GetValue() = wxString(buf);
1589 view->DisplayProperty(property);
1590 view->UpdatePropertyDisplayInList(property);
1591 view->OnPropertyChanged(property);
1592 }
1593}
1594
1595///
1596/// List of strings validator. For this we need more user interface than
1597/// we get with a property list; so create a new dialog for editing the list.
1598///
1599IMPLEMENT_DYNAMIC_CLASS(wxListOfStringsListValidator, wxPropertyListValidator)
1600
1601wxListOfStringsListValidator::wxListOfStringsListValidator(long flags):
1602 wxPropertyListValidator(flags)
1603{
1604}
1605
8710cf5c 1606bool wxListOfStringsListValidator::OnCheckValue(wxProperty *WXUNUSED(property), wxPropertyListView *WXUNUSED(view), wxWindow *WXUNUSED(parentWindow))
e3a43801
JS
1607{
1608 // No constraints for an arbitrary, user-editable list of strings.
1609 return TRUE;
1610}
1611
1612// Called when TICK is pressed or focus is lost or view wants to update
1613// the property list.
1614// Does the transferance from the property editing area to the property itself.
1615// In this case, the user cannot directly edit the string list.
8710cf5c 1616bool wxListOfStringsListValidator::OnRetrieveValue(wxProperty *WXUNUSED(property), wxPropertyListView *WXUNUSED(view), wxWindow *WXUNUSED(parentWindow))
e3a43801
JS
1617{
1618 return TRUE;
1619}
1620
8710cf5c 1621bool wxListOfStringsListValidator::OnDisplayValue(wxProperty *property, wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow))
e3a43801
JS
1622{
1623 if (!view->GetValueText())
1624 return FALSE;
1625 wxString str(property->GetValue().GetStringRepresentation());
1626 view->GetValueText()->SetValue(str);
1627 return TRUE;
1628}
1629
8710cf5c 1630bool wxListOfStringsListValidator::OnPrepareControls(wxProperty *WXUNUSED(property), wxPropertyListView *view, wxWindow *WXUNUSED(parentWindow))
e3a43801
JS
1631{
1632 if (view->GetEditButton())
1633 view->GetEditButton()->Enable(TRUE);
1634 if (view->GetValueText())
1635 view->GetValueText()->Enable(FALSE);
1636
1637 if (view->GetConfirmButton())
1638 view->GetConfirmButton()->Enable(FALSE);
1639 if (view->GetCancelButton())
1640 view->GetCancelButton()->Enable(FALSE);
1641 return TRUE;
1642}
1643
1644// Called when the property is double clicked. Extra functionality can be provided,
1645// cycling through possible values.
1646bool wxListOfStringsListValidator::OnDoubleClick(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow)
1647{
1648 OnEdit(property, view, parentWindow);
1649 return TRUE;
1650}
1651
1652void wxListOfStringsListValidator::OnEdit(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow)
1653{
1654 // Convert property value to a list of strings for editing
1655 wxStringList *stringList = new wxStringList;
29006414 1656
e3a43801
JS
1657 wxPropertyValue *expr = property->GetValue().GetFirst();
1658 while (expr)
1659 {
87138c52 1660 wxChar *s = expr->StringValue();
e3a43801
JS
1661 if (s)
1662 stringList->Add(s);
1663 expr = expr->GetNext();
1664 }
29006414 1665
87138c52 1666 wxString title(_T("Editing "));
e3a43801 1667 title += property->GetName();
29006414 1668
e3a43801
JS
1669 if (EditStringList(parentWindow, stringList, title.GetData()))
1670 {
1671 wxPropertyValue& oldValue = property->GetValue();
1672 oldValue.ClearList();
1673 wxNode *node = stringList->First();
1674 while (node)
1675 {
87138c52 1676 wxChar *s = (wxChar *)node->Data();
e3a43801 1677 oldValue.Append(new wxPropertyValue(s));
29006414 1678
e3a43801
JS
1679 node = node->Next();
1680 }
29006414 1681
e3a43801
JS
1682 view->DisplayProperty(property);
1683 view->UpdatePropertyDisplayInList(property);
1684 view->OnPropertyChanged(property);
1685 }
1686 delete stringList;
1687}
1688
1689class wxPropertyStringListEditorDialog: public wxDialog
1690{
1691 public:
1692 wxPropertyStringListEditorDialog(wxWindow *parent, const wxString& title,
29006414
VZ
1693 const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
1694 long windowStyle = wxDEFAULT_DIALOG_STYLE, const wxString& name = "stringEditorDialogBox"):
1695 wxDialog(parent, -1, title, pos, size, windowStyle, name)
e3a43801
JS
1696 {
1697 m_stringList = NULL;
1698 m_stringText = NULL;
1699 m_listBox = NULL;
1700 sm_dialogCancelled = FALSE;
1701 m_currentSelection = -1;
1702 }
1703 ~wxPropertyStringListEditorDialog(void) {}
3b1e466c 1704 void OnCloseWindow(wxCloseEvent& event);
e3a43801
JS
1705 void SaveCurrentSelection(void);
1706 void ShowCurrentSelection(void);
1707
29006414
VZ
1708 void OnOK(wxCommandEvent& event);
1709 void OnCancel(wxCommandEvent& event);
1710 void OnAdd(wxCommandEvent& event);
1711 void OnDelete(wxCommandEvent& event);
1712 void OnStrings(wxCommandEvent& event);
1713 void OnText(wxCommandEvent& event);
e3a43801
JS
1714
1715public:
1716 wxStringList* m_stringList;
1717 wxListBox* m_listBox;
1718 wxTextCtrl* m_stringText;
1719 static bool sm_dialogCancelled;
1720 int m_currentSelection;
1721DECLARE_EVENT_TABLE()
1722};
1723
29006414
VZ
1724#define wxID_PROP_SL_ADD 3000
1725#define wxID_PROP_SL_DELETE 3001
1726#define wxID_PROP_SL_STRINGS 3002
1727#define wxID_PROP_SL_TEXT 3003
e3a43801
JS
1728
1729BEGIN_EVENT_TABLE(wxPropertyStringListEditorDialog, wxDialog)
29006414
VZ
1730 EVT_BUTTON(wxID_OK, wxPropertyStringListEditorDialog::OnOK)
1731 EVT_BUTTON(wxID_CANCEL, wxPropertyStringListEditorDialog::OnCancel)
1732 EVT_BUTTON(wxID_PROP_SL_ADD, wxPropertyStringListEditorDialog::OnAdd)
1733 EVT_BUTTON(wxID_PROP_SL_DELETE, wxPropertyStringListEditorDialog::OnDelete)
1734 EVT_LISTBOX(wxID_PROP_SL_STRINGS, wxPropertyStringListEditorDialog::OnStrings)
1735 EVT_TEXT_ENTER(wxID_PROP_SL_TEXT, wxPropertyStringListEditorDialog::OnText)
3b1e466c 1736 EVT_CLOSE(wxPropertyStringListEditorDialog::OnCloseWindow)
e3a43801
JS
1737END_EVENT_TABLE()
1738
1739class wxPropertyStringListEditorText: public wxTextCtrl
1740{
1741 public:
1742 wxPropertyStringListEditorText(wxWindow *parent, wxWindowID id, const wxString& val,
29006414 1743 const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
e3a43801
JS
1744 long windowStyle = 0, const wxString& name = "text"):
1745 wxTextCtrl(parent, id, val, pos, size, windowStyle, wxDefaultValidator, name)
1746 {
1747 }
1748 void OnKillFocus(void)
1749 {
1750 wxPropertyStringListEditorDialog *dialog = (wxPropertyStringListEditorDialog *)GetParent();
1751 dialog->SaveCurrentSelection();
1752 }
1753};
1754
1755bool wxPropertyStringListEditorDialog::sm_dialogCancelled = FALSE;
1756
1757// Edit the string list.
87138c52 1758bool wxListOfStringsListValidator::EditStringList(wxWindow *parent, wxStringList *stringList, const wxChar *title)
e3a43801
JS
1759{
1760 int largeButtonWidth = 60;
1761 int largeButtonHeight = 25;
1762
1763 wxBeginBusyCursor();
1764 wxPropertyStringListEditorDialog *dialog = new wxPropertyStringListEditorDialog(parent,
29006414
VZ
1765 title, wxPoint(10, 10), wxSize(400, 400), wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL);
1766
e3a43801 1767 dialog->m_stringList = stringList;
29006414 1768
e3a43801
JS
1769 dialog->m_listBox = new wxListBox(dialog, wxID_PROP_SL_STRINGS,
1770 wxPoint(-1, -1), wxSize(-1, -1), 0, NULL, wxLB_SINGLE);
1771
1772 dialog->m_stringText = new wxPropertyStringListEditorText(dialog,
1773 wxID_PROP_SL_TEXT, "", wxPoint(5, 240),
1774 wxSize(300, -1), wxPROCESS_ENTER);
1775 dialog->m_stringText->Enable(FALSE);
1776
1777 wxButton *addButton = new wxButton(dialog, wxID_PROP_SL_ADD, "Add", wxPoint(-1, -1), wxSize(largeButtonWidth, largeButtonHeight));
1778 wxButton *deleteButton = new wxButton(dialog, wxID_PROP_SL_DELETE, "Delete", wxPoint(-1, -1), wxSize(largeButtonWidth, largeButtonHeight));
1779 wxButton *cancelButton = new wxButton(dialog, wxID_CANCEL, "Cancel", wxPoint(-1, -1), wxSize(largeButtonWidth, largeButtonHeight));
1780 wxButton *okButton = new wxButton(dialog, wxID_OK, "OK", wxPoint(-1, -1), wxSize(largeButtonWidth, largeButtonHeight));
1781
1782 okButton->SetDefault();
1783
1784 wxLayoutConstraints *c = new wxLayoutConstraints;
1785
1786 c->top.SameAs (dialog, wxTop, 2);
1787 c->left.SameAs (dialog, wxLeft, 2);
1788 c->right.SameAs (dialog, wxRight, 2);
1789 c->bottom.SameAs (dialog->m_stringText, wxTop, 2);
1790 dialog->m_listBox->SetConstraints(c);
1791
1792 c = new wxLayoutConstraints;
1793 c->left.SameAs (dialog, wxLeft, 2);
1794 c->right.SameAs (dialog, wxRight, 2);
1795 c->bottom.SameAs (addButton, wxTop, 2);
1796 c->height.AsIs();
1797 dialog->m_stringText->SetConstraints(c);
1798
1799 c = new wxLayoutConstraints;
1800 c->bottom.SameAs (dialog, wxBottom, 2);
1801 c->left.SameAs (dialog, wxLeft, 2);
1802 c->width.AsIs();
1803 c->height.AsIs();
1804 addButton->SetConstraints(c);
1805
1806 c = new wxLayoutConstraints;
1807 c->bottom.SameAs (dialog, wxBottom, 2);
1808 c->left.SameAs (addButton, wxRight, 2);
1809 c->width.AsIs();
1810 c->height.AsIs();
1811 deleteButton->SetConstraints(c);
1812
1813 c = new wxLayoutConstraints;
1814 c->bottom.SameAs (dialog, wxBottom, 2);
1815 c->right.SameAs (dialog, wxRight, 2);
1816 c->width.AsIs();
1817 c->height.AsIs();
1818 cancelButton->SetConstraints(c);
1819
1820 c = new wxLayoutConstraints;
1821 c->bottom.SameAs (dialog, wxBottom, 2);
1822 c->right.SameAs (cancelButton, wxLeft, 2);
1823 c->width.AsIs();
1824 c->height.AsIs();
1825 okButton->SetConstraints(c);
1826
1827 wxNode *node = stringList->First();
1828 while (node)
1829 {
1830 char *str = (char *)node->Data();
1831 // Save node as client data for each listbox item
1832 dialog->m_listBox->Append(str, (char *)node);
1833 node = node->Next();
1834 }
1835
1836 dialog->SetClientSize(310, 305);
1837 dialog->Layout();
1838
1839 dialog->Centre(wxBOTH);
1840 wxEndBusyCursor();
1841 if (dialog->ShowModal() == wxID_CANCEL)
29006414 1842 return FALSE;
e3a43801 1843 else
29006414 1844 return TRUE;
e3a43801
JS
1845}
1846
1847/*
1848 * String list editor callbacks
1849 *
1850 */
1851
1852void wxPropertyStringListEditorDialog::OnStrings(wxCommandEvent& WXUNUSED(event))
1853{
1854 int sel = m_listBox->GetSelection();
1855 if (sel > -1)
1856 {
1857 m_currentSelection = sel;
1858
1859 ShowCurrentSelection();
1860 }
1861}
1862
1863void wxPropertyStringListEditorDialog::OnDelete(wxCommandEvent& WXUNUSED(event))
1864{
1865 int sel = m_listBox->GetSelection();
1866 if (sel == -1)
1867 return;
29006414 1868
e3a43801
JS
1869 wxNode *node = (wxNode *)m_listBox->wxListBox::GetClientData(sel);
1870 if (!node)
1871 return;
29006414 1872
e3a43801 1873 m_listBox->Delete(sel);
87138c52 1874 delete[] (wxChar *)node->Data();
e3a43801
JS
1875 delete node;
1876 m_currentSelection = -1;
1877 m_stringText->SetValue("");
1878}
1879
1880void wxPropertyStringListEditorDialog::OnAdd(wxCommandEvent& WXUNUSED(event))
1881{
1882 SaveCurrentSelection();
29006414 1883
87138c52 1884 wxChar *initialText = _T("");
e3a43801 1885 wxNode *node = m_stringList->Add(initialText);
ee0fc54a 1886 m_listBox->Append(initialText, (void *)node);
e3a43801
JS
1887 m_currentSelection = m_stringList->Number() - 1;
1888 m_listBox->SetSelection(m_currentSelection);
1889 ShowCurrentSelection();
1890 m_stringText->SetFocus();
1891}
1892
1893void wxPropertyStringListEditorDialog::OnOK(wxCommandEvent& WXUNUSED(event))
1894{
1895 SaveCurrentSelection();
1896 EndModal(wxID_OK);
3b1e466c
JS
1897 // Close(TRUE);
1898 this->Destroy();
e3a43801
JS
1899}
1900
1901void wxPropertyStringListEditorDialog::OnCancel(wxCommandEvent& WXUNUSED(event))
1902{
1903 sm_dialogCancelled = TRUE;
1904 EndModal(wxID_CANCEL);
3b1e466c
JS
1905// Close(TRUE);
1906 this->Destroy();
e3a43801
JS
1907}
1908
1909void wxPropertyStringListEditorDialog::OnText(wxCommandEvent& event)
1910{
2432b92d 1911 if (event.GetEventType() == wxEVT_COMMAND_TEXT_ENTER)
e3a43801
JS
1912 {
1913 SaveCurrentSelection();
1914 }
1915}
1916
3b1e466c 1917void wxPropertyStringListEditorDialog::OnCloseWindow(wxCloseEvent& event)
e3a43801
JS
1918{
1919 SaveCurrentSelection();
3b1e466c 1920 this->Destroy();
e3a43801
JS
1921}
1922
1923void wxPropertyStringListEditorDialog::SaveCurrentSelection(void)
1924{
1925 if (m_currentSelection == -1)
1926 return;
29006414 1927
e3a43801
JS
1928 wxNode *node = (wxNode *)m_listBox->wxListBox::GetClientData(m_currentSelection);
1929 if (!node)
1930 return;
29006414 1931
e3a43801
JS
1932 wxString txt(m_stringText->GetValue());
1933 if (node->Data())
1934 delete[] (char *)node->Data();
1935 node->SetData((wxObject *)copystring(txt));
29006414 1936
e3a43801
JS
1937 m_listBox->SetString(m_currentSelection, (char *)node->Data());
1938}
1939
1940void wxPropertyStringListEditorDialog::ShowCurrentSelection(void)
1941{
1942 if (m_currentSelection == -1)
1943 {
1944 m_stringText->SetValue("");
1945 return;
1946 }
1947 wxNode *node = (wxNode *)m_listBox->wxListBox::GetClientData(m_currentSelection);
1948 char *txt = (char *)node->Data();
1949 m_stringText->SetValue(txt);
1950 m_stringText->Enable(TRUE);
1951}
1952