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