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