]> git.saurik.com Git - wxWidgets.git/blob - utils/dialoged/src/winprop.cpp
0bb93c4a27fd12362ec813c46e398bbffdd599b2
[wxWidgets.git] / utils / dialoged / src / winprop.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: winprop.cpp
3 // Purpose: Window properties
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "winprop.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/wx.h"
25 #endif
26
27 #include <ctype.h>
28 #include <stdlib.h>
29 #include <math.h>
30 #include <string.h>
31
32 #if defined(__WXMSW__) && !defined(__GNUWIN32__)
33 #include <strstrea.h>
34 #else
35 #include <strstream.h>
36 #endif
37
38 #ifdef __WXMSW__
39 #include <windows.h>
40 #endif
41
42 #include "reseditr.h"
43 #include "winprop.h"
44
45 // Causes immediate feedback.
46 void wxResourcePropertyListView::OnPropertyChanged(wxProperty *property)
47 {
48 // Sets the value of the property back into the actual object,
49 // IF the property value was modified.
50 if (property->GetValue().GetModified())
51 {
52 propertyInfo->SetProperty(property->GetName(), property);
53 property->GetValue().SetModified(FALSE);
54 }
55 }
56
57 bool wxResourcePropertyListView::OnClose(void)
58 {
59 int w, h, x, y;
60 GetManagedWindow()->GetSize(& w, & h);
61 GetManagedWindow()->GetPosition(& x, & y);
62
63 wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().width = w;
64 wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().height = h;
65 wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().x = x;
66 wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().y = y;
67
68 return wxPropertyListView::OnClose();
69 }
70
71 wxWindow *wxPropertyInfo::sm_propertyWindow;
72
73 /*
74 * wxDialogEditorPropertyListDialog
75 */
76
77 wxDialogEditorPropertyListDialog::wxDialogEditorPropertyListDialog(wxPropertyListView *v, wxWindow *parent, const wxString& title,
78 const wxPoint& pos, const wxSize& size,
79 long style, const wxString& name):
80 wxPropertyListDialog(v, parent, title, pos, size, style, name)
81 {
82 m_propSheet = NULL;
83 m_propInfo = NULL;
84 }
85
86 wxDialogEditorPropertyListDialog::~wxDialogEditorPropertyListDialog()
87 {
88 delete m_propSheet;
89 delete m_propInfo;
90 wxPropertyInfo::sm_propertyWindow = NULL;
91 }
92
93 /*
94 * wxPropertyInfo
95 */
96
97 // Edit the information represented by this object, whatever that
98 // might be.
99 bool wxPropertyInfo::Edit(wxWindow *parent, const wxString& title)
100 {
101 if (sm_propertyWindow)
102 return FALSE;
103
104 int width = wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().width;
105 int height = wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().height;
106 int x = wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().x;
107 int y = wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().y;
108
109 wxPropertySheet *propSheet = new wxPropertySheet;
110
111 wxStringList propNames;
112 GetPropertyNames(propNames);
113
114 wxNode *node = propNames.First();
115 while (node)
116 {
117 wxString name((char *)node->Data());
118 wxProperty *prop = GetProperty(name);
119 if (prop)
120 {
121 propSheet->AddProperty(prop);
122 }
123 node = node->Next();
124 }
125
126 // Reset 'modified' flags for all property values
127 propSheet->SetAllModified(FALSE);
128
129 wxResourcePropertyListView *view = new wxResourcePropertyListView(this, NULL,
130 #ifdef __XVIEW__
131 wxPROP_BUTTON_OK | wxPROP_BUTTON_CANCEL |
132 #endif
133 wxPROP_BUTTON_CHECK_CROSS|wxPROP_DYNAMIC_VALUE_FIELD|wxPROP_PULLDOWN|wxPROP_SHOWVALUES);
134
135 wxDialogEditorPropertyListDialog *propDialog = new wxDialogEditorPropertyListDialog(view,
136 wxResourceManager::GetCurrentResourceManager()->GetEditorFrame(), title, wxPoint(x, y),
137 wxSize(width, height), wxDEFAULT_DIALOG_STYLE);
138 sm_propertyWindow = propDialog;
139
140 propDialog->m_registry.RegisterValidator((wxString)"real", new wxRealListValidator);
141 propDialog->m_registry.RegisterValidator((wxString)"string", new wxStringListValidator);
142 propDialog->m_registry.RegisterValidator((wxString)"integer", new wxIntegerListValidator);
143 propDialog->m_registry.RegisterValidator((wxString)"bool", new wxBoolListValidator);
144 propDialog->m_registry.RegisterValidator((wxString)"filename", new wxFilenameListValidator);
145 propDialog->m_registry.RegisterValidator((wxString)"stringlist", new wxListOfStringsListValidator);
146 propDialog->m_registry.RegisterValidator((wxString)"window_id", new wxResourceSymbolValidator);
147
148 propDialog->m_propInfo = this;
149 propDialog->m_propSheet = propSheet;
150
151 // view->propertyWindow = propDialog;
152 view->AddRegistry(&(propDialog->m_registry));
153 view->ShowView(propSheet, propDialog);
154
155 propDialog->Show(TRUE);
156 return TRUE;
157 }
158
159 /*
160 * wxWindowPropertyInfo
161 */
162
163 wxWindowPropertyInfo::wxWindowPropertyInfo(wxWindow *win, wxItemResource *res)
164 {
165 propertyWindow = win;
166 propertyResource = res;
167 }
168
169 wxWindowPropertyInfo::~wxWindowPropertyInfo(void)
170 {
171 }
172
173 wxProperty *wxWindowPropertyInfo::GetFontProperty(wxString& name, wxFont *font)
174 {
175 if (!font)
176 return NULL;
177
178 if (name.Contains("Points"))
179 return new wxProperty(name, (long)font->GetPointSize(), "integer", new wxIntegerListValidator(1, 100));
180 else if (name.Contains("Family"))
181 return new wxProperty(name, font->GetFamilyString(), "string",
182 new wxStringListValidator(new wxStringList("wxDECORATIVE", "wxROMAN", "wxSCRIPT", "wxSWISS", "wxMODERN",
183 NULL)));
184 else if (name.Contains("Style"))
185 return new wxProperty(name, font->GetStyleString(), "string",
186 new wxStringListValidator(new wxStringList("wxNORMAL", "wxITALIC", "wxSLANT", NULL)));
187 else if (name.Contains("Weight"))
188 return new wxProperty(name, font->GetWeightString(), "string",
189 new wxStringListValidator(new wxStringList("wxNORMAL", "wxBOLD", "wxLIGHT", NULL)));
190 else if (name.Contains("Underlined"))
191 return new wxProperty(name, (bool)font->GetUnderlined(), "bool");
192 else
193 return NULL;
194 }
195
196 wxFont *wxWindowPropertyInfo::SetFontProperty(wxString& name, wxProperty *property, wxFont *font)
197 {
198 int pointSize = 12;
199 int fontFamily = wxMODERN;
200 int fontStyle = wxNORMAL;
201 int fontWeight = wxNORMAL;
202 bool fontUnderlined = FALSE;
203
204 if (name.Contains("Points"))
205 {
206 pointSize = (int)property->GetValue().IntegerValue();
207 if (font && (pointSize == font->GetPointSize()))
208 return NULL; // No change
209 }
210 else if (font) pointSize = font->GetPointSize();
211
212 if (name.Contains("Family"))
213 {
214 wxString val = property->GetValue().StringValue();
215 fontFamily = wxStringToFontFamily(val);
216
217 if (font && (fontFamily == font->GetFamily()))
218 return NULL; // No change
219 }
220 else if (font) fontFamily = font->GetFamily();
221
222 if (name.Contains("Style"))
223 {
224 wxString val = property->GetValue().StringValue();
225 fontStyle = wxStringToFontStyle(val);
226
227 if (font && (fontStyle == font->GetStyle()))
228 return NULL; // No change
229 }
230 else if (font) fontStyle = font->GetStyle();
231 if (name.Contains("Weight"))
232 {
233 wxString val = property->GetValue().StringValue();
234 fontWeight = wxStringToFontWeight(val);
235
236 if (font && (fontWeight == font->GetWeight()))
237 return NULL; // No change
238 }
239 else if (font) fontWeight = font->GetWeight();
240
241 if (name.Contains("Underlined"))
242 {
243 fontUnderlined = property->GetValue().BoolValue();
244
245 if (font && (fontUnderlined == font->GetUnderlined()))
246 return NULL; // No change
247 }
248 else if (font) fontUnderlined = font->GetUnderlined();
249
250 wxFont *newFont = wxTheFontList->FindOrCreateFont(pointSize, fontFamily, fontStyle, fontWeight, fontUnderlined);
251 if (newFont)
252 {
253 return newFont;
254 }
255 else
256 return NULL;
257 }
258
259 wxProperty *wxWindowPropertyInfo::GetProperty(wxString& name)
260 {
261 wxFont *font = propertyWindow->GetFont();
262 if (name == "fontPoints" || name == "fontFamily" || name == "fontStyle" || name == "fontWeight" ||
263 name == "fontUnderlined")
264 return GetFontProperty(name, font);
265 else if (name == "name")
266 return new wxProperty("name", propertyWindow->GetName(), "string");
267 else if (name == "title")
268 return new wxProperty("title", propertyWindow->GetTitle(), "string");
269 else if (name == "x")
270 {
271 int x, y;
272 propertyWindow->GetPosition(&x, &y);
273 return new wxProperty("x", (long)x, "integer");
274 }
275 else if (name == "y")
276 {
277 int x, y;
278 propertyWindow->GetPosition(&x, &y);
279 return new wxProperty("y", (long)y, "integer");
280 }
281 else if (name == "width")
282 {
283 int width, height;
284 propertyWindow->GetSize(&width, &height);
285 return new wxProperty("width", (long)width, "integer");
286 }
287 else if (name == "height")
288 {
289 int width, height;
290 propertyWindow->GetSize(&width, &height);
291 return new wxProperty("height", (long)height, "integer");
292 }
293 else if (name == "id")
294 {
295 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(propertyWindow);
296 if (resource)
297 {
298 int id = resource->GetId();
299 wxString idStr;
300 idStr.Printf("%d", id);
301 wxString symbolName = wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetSymbolForId(id);
302 symbolName += "=";
303 symbolName += idStr;
304 // symbolName is now e.g. "ID_PANEL21=105"
305 return new wxProperty("id", symbolName, "window_id");
306 }
307 else
308 return NULL;
309 }
310 else
311 return NULL;
312 }
313
314 bool wxWindowPropertyInfo::SetProperty(wxString& name, wxProperty *property)
315 {
316 wxFont *font = propertyWindow->GetFont();
317 if (font && (name == "fontPoints" || name == "fontFamily" || name == "fontStyle" || name == "fontWeight" || name == "fontUnderlined" ))
318 {
319 wxFont *newFont = SetFontProperty(name, property, font);
320 if (newFont)
321 propertyWindow->SetFont(newFont);
322 return TRUE;
323 }
324 else if (name == "name")
325 {
326 // Remove old name from resource table, if it's there.
327 wxItemResource *oldResource = (wxItemResource *)wxResourceManager::GetCurrentResourceManager()->GetResourceTable().Delete(propertyWindow->GetName());
328 if (oldResource)
329 {
330 // It's a top-level resource
331 propertyWindow->SetName(property->GetValue().StringValue());
332 oldResource->SetName(property->GetValue().StringValue());
333 wxResourceManager::GetCurrentResourceManager()->GetResourceTable().Put(propertyWindow->GetName(), oldResource);
334 }
335 else
336 {
337 // It's a child of something; just set the name of the resource and the window.
338 propertyWindow->SetName(property->GetValue().StringValue());
339 propertyResource->SetName(property->GetValue().StringValue());
340 }
341 // Refresh the resource manager list, because the name changed.
342 wxResourceManager::GetCurrentResourceManager()->UpdateResourceList();
343 return TRUE;
344 }
345 else if (name == "title")
346 {
347 propertyWindow->SetTitle(property->GetValue().StringValue());
348 return TRUE;
349 }
350 else if (name == "x")
351 {
352 int x, y;
353 propertyWindow->GetPosition(&x, &y);
354 int newX = (int)property->GetValue().IntegerValue();
355 if (x != newX)
356 propertyWindow->Move(newX, y);
357 return TRUE;
358 }
359 else if (name == "y")
360 {
361 int x, y;
362 propertyWindow->GetPosition(&x, &y);
363 int newY = (int)property->GetValue().IntegerValue();
364 if (y != newY)
365 propertyWindow->Move(x, newY);
366 return TRUE;
367 }
368 else if (name == "width")
369 {
370 int width, height;
371 propertyWindow->GetSize(&width, &height);
372 int newWidth = (int)property->GetValue().IntegerValue();
373 if (width != newWidth)
374 {
375 propertyWindow->SetSize(newWidth, height);
376 /*
377 if (propertyWindow->IsKindOf(CLASSINFO(wxPanel)) && !propertyWindow->IsKindOf(CLASSINFO(wxDialog)))
378 {
379 propertyWindow->GetParent()->SetClientSize(newWidth, height);
380 }
381 */
382 }
383 return TRUE;
384 }
385 else if (name == "height")
386 {
387 int width, height;
388 propertyWindow->GetSize(&width, &height);
389 int newHeight = (int)property->GetValue().IntegerValue();
390 if (height != newHeight)
391 {
392 propertyWindow->SetSize(width, newHeight);
393 /*
394 if (propertyWindow->IsKindOf(CLASSINFO(wxPanel)) && !propertyWindow->IsKindOf(CLASSINFO(wxDialog)))
395 {
396 propertyWindow->GetParent()->SetClientSize(width, newHeight);
397 }
398 */
399 }
400 return TRUE;
401 }
402 else if (name == "id")
403 {
404 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(propertyWindow);
405 if (resource)
406 {
407 wxString value = property->GetValue().StringValue();
408
409 wxString strName = value.Before('=');
410 wxString strId = value.After('=');
411 int id = atoi(strId);
412
413 wxString oldSymbolName = wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetSymbolForId(resource->GetId());
414 int oldSymbolId = resource->GetId();
415
416 if (strName != "")
417 {
418 // If we change the id for an existing symbol, we need to:
419 // 1) Check if there are any other resources currently using the original id.
420 // If so, will need to change their id to the new id.
421 // 2) Remove the old symbol, add the new symbol.
422 // In this check, we don't have to do this, but we need to do it in SetProperty.
423
424 if (strName == oldSymbolName && id != oldSymbolId)
425 {
426 wxASSERT( (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(oldSymbolName)) );
427
428 // It's OK to change just the id. But we'll need to change all matching ids in all resources,
429 // because ids are unique and changing one resource's id must change all identical ones.
430 wxResourceManager::GetCurrentResourceManager()->ChangeIds(oldSymbolId, id);
431
432 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().RemoveSymbol(oldSymbolName);
433 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().AddSymbol(strName, id);
434 }
435
436 // If we change the name but not the id, we'll just need to remove and
437 // re-add the symbol/id pair.
438 if (strName != oldSymbolName && id == oldSymbolId)
439 {
440 wxASSERT( (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(oldSymbolName)) );
441
442 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().RemoveSymbol(oldSymbolName);
443
444 if (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().SymbolExists(strName))
445 {
446 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().AddSymbol(strName, id);
447 }
448 }
449
450 // What if we're changing both the name and the id?
451 // - if there's no symbol of that name, just remove the old, add the new (in SetProperty)
452 // - if there is a symbol of that name, if id matches, do nothing. If not, veto.
453
454 if (strName != oldSymbolName && id != oldSymbolId)
455 {
456 // Remove old symbol if it's not being used
457 if (!wxResourceManager::GetCurrentResourceManager()->IsSymbolUsed(resource, oldSymbolId) &&
458 !wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(oldSymbolName))
459 {
460 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().RemoveSymbol(oldSymbolName);
461 }
462
463 if (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().SymbolExists(strName))
464 {
465 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().AddSymbol(strName, id);
466 }
467 }
468 resource->SetId(id);
469 }
470
471 return TRUE;
472 }
473 else
474 return FALSE;
475 }
476 else
477 return FALSE;
478 }
479
480 void wxWindowPropertyInfo::GetPropertyNames(wxStringList& names)
481 {
482 names.Add("id");
483 names.Add("name");
484 names.Add("x");
485 names.Add("y");
486 names.Add("width");
487 names.Add("height");
488 if (!propertyWindow->IsKindOf(CLASSINFO(wxControl)))
489 {
490 names.Add("fontPoints");
491 names.Add("fontFamily");
492 names.Add("fontStyle");
493 names.Add("fontWeight");
494 names.Add("fontUnderlined");
495 }
496 }
497
498 // Fill in the wxItemResource members to mirror the current window settings
499 bool wxWindowPropertyInfo::InstantiateResource(wxItemResource *resource)
500 {
501 resource->SetType(propertyWindow->GetClassInfo()->GetClassName());
502
503 // resource->SetStyle(propertyWindow->GetWindowStyleFlag());
504 wxString str(propertyWindow->GetName());
505 resource->SetName(WXSTRINGCAST str);
506 int x, y, w, h;
507 propertyWindow->GetSize(&w, &h);
508
509 propertyWindow->GetPosition(&x, &y);
510 resource->SetSize(x, y, w, h);
511 return TRUE;
512 }
513
514
515 /*
516 * Controls
517 */
518
519 wxProperty *wxItemPropertyInfo::GetProperty(wxString& name)
520 {
521 wxControl *itemWindow = (wxControl *)propertyWindow;
522 wxFont *font = itemWindow->GetFont();
523
524 if (name == "fontPoints" || name == "fontFamily" || name == "fontStyle" || name == "fontWeight" ||
525 name == "fontUnderlined")
526 return GetFontProperty(name, font);
527 else if (name == "label" && itemWindow->GetLabel())
528 return new wxProperty("label", propertyWindow->GetLabel(), "string");
529 else
530 return wxWindowPropertyInfo::GetProperty(name);
531 }
532
533 bool wxItemPropertyInfo::SetProperty(wxString& name, wxProperty *property)
534 {
535 wxControl *itemWindow = (wxControl *)propertyWindow;
536 wxFont *font = itemWindow->GetFont();
537
538 if (font && (name == "fontPoints" || name == "fontFamily" || name == "fontStyle" || name == "fontWeight" || name == "fontUnderlined" ))
539 {
540 wxFont *newFont = SetFontProperty(name, property, font);
541 if (newFont)
542 itemWindow->SetLabelFont(newFont);
543 return TRUE;
544 }
545 else if (name == "label")
546 {
547 itemWindow->SetLabel(property->GetValue().StringValue());
548 return TRUE;
549 }
550 else
551 return wxWindowPropertyInfo::SetProperty(name, property);
552 }
553
554 void wxItemPropertyInfo::GetPropertyNames(wxStringList& names)
555 {
556 wxWindowPropertyInfo::GetPropertyNames(names);
557
558 names.Add("fontPoints");
559 names.Add("fontFamily");
560 names.Add("fontStyle");
561 names.Add("fontWeight");
562 names.Add("fontUnderlined");
563 }
564
565 bool wxItemPropertyInfo::InstantiateResource(wxItemResource *resource)
566 {
567 wxWindowPropertyInfo::InstantiateResource(resource);
568
569 wxControl *item = (wxControl *)propertyWindow;
570 wxString str(item->GetLabel());
571 resource->SetTitle(WXSTRINGCAST str);
572 if (item->GetFont() && item->GetFont()->Ok())
573 resource->SetFont(wxTheFontList->FindOrCreateFont(item->GetFont()->GetPointSize(),
574 item->GetFont()->GetFamily(), item->GetFont()->GetStyle(), item->GetFont()->GetWeight(),
575 item->GetFont()->GetUnderlined(), item->GetFont()->GetFaceName()));
576 return TRUE;
577 }
578
579 /*
580 * Button
581 */
582
583 wxProperty *wxButtonPropertyInfo::GetProperty(wxString& name)
584 {
585 wxButton *button = (wxButton *)propertyWindow;
586 return wxItemPropertyInfo::GetProperty(name);
587 }
588
589 bool wxButtonPropertyInfo::SetProperty(wxString& name, wxProperty *property)
590 {
591 wxButton *button = (wxButton *)propertyWindow;
592 return wxItemPropertyInfo::SetProperty(name, property);
593 }
594
595 void wxButtonPropertyInfo::GetPropertyNames(wxStringList& names)
596 {
597 names.Add("label");
598 wxItemPropertyInfo::GetPropertyNames(names);
599 }
600
601 bool wxButtonPropertyInfo::InstantiateResource(wxItemResource *resource)
602 {
603 return wxItemPropertyInfo::InstantiateResource(resource);
604 }
605
606 /*
607 * wxBitmapButton
608 */
609
610 wxProperty *wxBitmapButtonPropertyInfo::GetProperty(wxString& name)
611 {
612 wxBitmapButton *button = (wxBitmapButton *)propertyWindow;
613 if (name == "label")
614 {
615 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(button);
616 wxString str("none.bmp");
617
618 if (resource)
619 {
620 char *filename = wxResourceManager::GetCurrentResourceManager()->FindBitmapFilenameForResource(resource);
621 if (filename)
622 str = filename;
623 }
624 return new wxProperty("label", str.GetData(), "string", new wxFilenameListValidator("Select a bitmap file", "*.bmp"));
625 }
626 else
627 return wxButtonPropertyInfo::GetProperty(name);
628 }
629
630 bool wxBitmapButtonPropertyInfo::SetProperty(wxString& name, wxProperty *property)
631 {
632 wxBitmapButton *button = (wxBitmapButton *)propertyWindow;
633 if (name == "label")
634 {
635 char *s = property->GetValue().StringValue();
636 if (s && wxFileExists(s))
637 {
638 s = copystring(s);
639 wxBitmap *bitmap = new wxBitmap(s, wxBITMAP_TYPE_BMP);
640 if (!bitmap->Ok())
641 {
642 delete bitmap;
643 delete[] s;
644 return FALSE;
645 }
646 else
647 {
648 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(button);
649 if (resource)
650 {
651 wxString oldResource(resource->GetValue4());
652 char *resName = wxResourceManager::GetCurrentResourceManager()->AddBitmapResource(s);
653 resource->SetValue4(resName);
654
655 if (!oldResource.IsNull())
656 wxResourceManager::GetCurrentResourceManager()->PossiblyDeleteBitmapResource(WXSTRINGCAST oldResource);
657 }
658
659 button->SetLabel(bitmap);
660 delete[] s;
661 return TRUE;
662 }
663 }
664 return FALSE;
665 }
666 else
667 return wxButtonPropertyInfo::SetProperty(name, property);
668 }
669
670 void wxBitmapButtonPropertyInfo::GetPropertyNames(wxStringList& names)
671 {
672 // names.Add("label");
673 wxButtonPropertyInfo::GetPropertyNames(names);
674 }
675
676 bool wxBitmapButtonPropertyInfo::InstantiateResource(wxItemResource *resource)
677 {
678 return wxItemPropertyInfo::InstantiateResource(resource);
679 }
680
681 /*
682 * wxStaticText
683 */
684
685 wxProperty *wxStaticTextPropertyInfo::GetProperty(wxString& name)
686 {
687 wxStaticText *message = (wxStaticText *)propertyWindow;
688 return wxItemPropertyInfo::GetProperty(name);
689 }
690
691 bool wxStaticTextPropertyInfo::SetProperty(wxString& name, wxProperty *property)
692 {
693 wxStaticText *message = (wxStaticText *)propertyWindow;
694 return wxItemPropertyInfo::SetProperty(name, property);
695 }
696
697 void wxStaticTextPropertyInfo::GetPropertyNames(wxStringList& names)
698 {
699 names.Add("label");
700 wxItemPropertyInfo::GetPropertyNames(names);
701 }
702
703 bool wxStaticTextPropertyInfo::InstantiateResource(wxItemResource *resource)
704 {
705 return wxItemPropertyInfo::InstantiateResource(resource);
706 }
707
708 /*
709 * wxStaticBitmap
710 */
711
712 wxProperty *wxStaticBitmapPropertyInfo::GetProperty(wxString& name)
713 {
714 wxStaticBitmap *message = (wxStaticBitmap *)propertyWindow;
715 if (name == "label")
716 {
717 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(message);
718 wxString str("none.bmp");
719
720 if (resource)
721 {
722 char *filename = wxResourceManager::GetCurrentResourceManager()->FindBitmapFilenameForResource(resource);
723 if (filename)
724 str = filename;
725 }
726 return new wxProperty("label", str.GetData(), "string", new wxFilenameListValidator("Select a bitmap file", "*.bmp"));
727 }
728 else
729 return wxItemPropertyInfo::GetProperty(name);
730 }
731
732 bool wxStaticBitmapPropertyInfo::SetProperty(wxString& name, wxProperty *property)
733 {
734 wxStaticBitmap *message = (wxStaticBitmap *)propertyWindow;
735 if (name == "label")
736 {
737 char *s = property->GetValue().StringValue();
738 if (s && wxFileExists(s))
739 {
740 s = copystring(s);
741
742 wxBitmap *bitmap = new wxBitmap(s, wxBITMAP_TYPE_BMP);
743 if (!bitmap->Ok())
744 {
745 delete bitmap;
746 delete[] s;
747 return FALSE;
748 }
749 else
750 {
751 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(message);
752 if (resource)
753 {
754 wxString oldResource(resource->GetValue4());
755 char *resName = wxResourceManager::GetCurrentResourceManager()->AddBitmapResource(s);
756 resource->SetValue4(resName);
757
758 if (!oldResource.IsNull())
759 wxResourceManager::GetCurrentResourceManager()->PossiblyDeleteBitmapResource(WXSTRINGCAST oldResource);
760 }
761
762 message->SetBitmap(bitmap);
763 delete[] s;
764 return TRUE;
765 }
766 }
767 return FALSE;
768 }
769 else
770 return wxItemPropertyInfo::SetProperty(name, property);
771 }
772
773 void wxStaticBitmapPropertyInfo::GetPropertyNames(wxStringList& names)
774 {
775 names.Add("label");
776 wxItemPropertyInfo::GetPropertyNames(names);
777 }
778
779 bool wxStaticBitmapPropertyInfo::InstantiateResource(wxItemResource *resource)
780 {
781 return wxItemPropertyInfo::InstantiateResource(resource);
782 }
783
784 /*
785 * Text item
786 */
787
788 wxProperty *wxTextPropertyInfo::GetProperty(wxString& name)
789 {
790 wxTextCtrl *text = (wxTextCtrl *)propertyWindow;
791 if (name == "value")
792 return new wxProperty("value", text->GetValue(), "string");
793 else if (name == "password")
794 {
795 bool isPassword = ((text->GetWindowStyleFlag() & wxTE_PASSWORD) == wxTE_PASSWORD);
796 return new wxProperty("password", isPassword, "bool");
797 }
798 else if (name == "readonly")
799 {
800 bool isReadOnly = ((text->GetWindowStyleFlag() & wxTE_READONLY) == wxTE_READONLY);
801 return new wxProperty("readonly", isReadOnly, "bool");
802 }
803 else
804 return wxItemPropertyInfo::GetProperty(name);
805 }
806
807 bool wxTextPropertyInfo::SetProperty(wxString& name, wxProperty *property)
808 {
809 wxTextCtrl *text = (wxTextCtrl *)propertyWindow;
810 if (name == "value")
811 {
812 text->SetValue(property->GetValue().StringValue());
813 return TRUE;
814 }
815 else if (name == "password")
816 {
817 long flag = text->GetWindowStyleFlag();
818 if (property->GetValue().BoolValue())
819 {
820 if ((flag & wxTE_PASSWORD) != wxTE_PASSWORD)
821 flag |= wxTE_PASSWORD;
822 }
823 else
824 {
825 if ((flag & wxTE_PASSWORD) == wxTE_PASSWORD)
826 flag -= wxTE_PASSWORD;
827 }
828 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(text);
829 resource->SetStyle(flag);
830
831 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(text, this);
832 return TRUE;
833 }
834 else if (name == "readonly")
835 {
836 long flag = text->GetWindowStyleFlag();
837 if (property->GetValue().BoolValue())
838 {
839 if ((flag & wxTE_READONLY) != wxTE_READONLY)
840 flag |= wxTE_READONLY;
841 }
842 else
843 {
844 if ((flag & wxTE_READONLY) == wxTE_READONLY)
845 flag -= wxTE_READONLY;
846 }
847 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(text);
848 resource->SetStyle(flag);
849
850 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(text, this);
851 return TRUE;
852 }
853 else
854 return wxItemPropertyInfo::SetProperty(name, property);
855 }
856
857 void wxTextPropertyInfo::GetPropertyNames(wxStringList& names)
858 {
859 names.Add("value");
860 names.Add("readonly");
861 names.Add("password");
862 wxItemPropertyInfo::GetPropertyNames(names);
863 }
864
865 bool wxTextPropertyInfo::InstantiateResource(wxItemResource *resource)
866 {
867 wxTextCtrl *text = (wxTextCtrl *)propertyWindow;
868 wxString str(text->GetValue());
869 resource->SetValue4(WXSTRINGCAST str);
870
871 return wxItemPropertyInfo::InstantiateResource(resource);
872 }
873
874 /*
875 * Listbox item
876 */
877
878 wxProperty *wxListBoxPropertyInfo::GetProperty(wxString& name)
879 {
880 wxListBox *listBox = (wxListBox *)propertyWindow;
881 if (name == "values")
882 {
883 wxStringList *stringList = new wxStringList;
884 int i;
885 for (i = 0; i < listBox->Number(); i++)
886 stringList->Add(listBox->GetString(i));
887
888 return new wxProperty(name, stringList, "stringlist");
889 }
890 else if (name == "multiple")
891 {
892 char *pos = NULL;
893 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(listBox);
894 if (!resource)
895 return NULL;
896
897 char *mult = "wxSINGLE";
898
899 switch (resource->GetValue1())
900 {
901 case wxLB_MULTIPLE:
902 mult = "wxLB_MULTIPLE";
903 break;
904 case wxLB_EXTENDED:
905 mult = "wxLB_EXTENDED";
906 break;
907 default:
908 case wxLB_SINGLE:
909 mult = "wxLB_SINGLE";
910 break;
911 }
912 return new wxProperty("multiple", mult, "string",
913 new wxStringListValidator(new wxStringList("wxLB_SINGLE", "wxLB_MULTIPLE", "wxLB_EXTENDED",
914 NULL)));
915 }
916 else
917 return wxItemPropertyInfo::GetProperty(name);
918 }
919
920 bool wxListBoxPropertyInfo::SetProperty(wxString& name, wxProperty *property)
921 {
922 wxListBox *listBox = (wxListBox *)propertyWindow;
923 if (name == "values")
924 {
925 listBox->Clear();
926 wxPropertyValue *expr = property->GetValue().GetFirst();
927 while (expr)
928 {
929 char *s = expr->StringValue();
930 if (s)
931 listBox->Append(s);
932 expr = expr->GetNext();
933 }
934 return TRUE;
935 }
936 else if (name == "multiple")
937 {
938 int mult = wxLB_SINGLE;
939 wxString str(property->GetValue().StringValue());
940 if (str == "wxLB_MULTIPLE")
941 mult = wxLB_MULTIPLE;
942 else if (str == "wxLB_EXTENDED")
943 mult = wxLB_EXTENDED;
944 else
945 mult = wxLB_SINGLE;
946 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(listBox);
947 if (resource)
948 resource->SetValue1(mult);
949 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(listBox, this);
950 return TRUE;
951 }
952 else
953 return wxItemPropertyInfo::SetProperty(name, property);
954 }
955
956 void wxListBoxPropertyInfo::GetPropertyNames(wxStringList& names)
957 {
958 names.Add("values");
959 names.Add("multiple");
960 wxItemPropertyInfo::GetPropertyNames(names);
961 }
962
963 bool wxListBoxPropertyInfo::InstantiateResource(wxItemResource *resource)
964 {
965 wxListBox *lbox = (wxListBox *)propertyWindow;
966 // This will be set for the wxItemResource on reading or in SetProperty
967 // resource->SetValue1(lbox->GetSelectionMode());
968 int i;
969 if (lbox->Number() == 0)
970 resource->SetStringValues(NULL);
971 else
972 {
973 wxStringList *slist = new wxStringList;
974
975 for (i = 0; i < lbox->Number(); i++)
976 slist->Add(lbox->GetString(i));
977
978 resource->SetStringValues(slist);
979 }
980 return wxItemPropertyInfo::InstantiateResource(resource);
981 }
982
983 /*
984 * Choice item
985 */
986
987 wxProperty *wxChoicePropertyInfo::GetProperty(wxString& name)
988 {
989 wxChoice *choice = (wxChoice *)propertyWindow;
990 if (name == "values")
991 {
992 wxStringList *stringList = new wxStringList;
993 int i;
994 for (i = 0; i < choice->Number(); i++)
995 stringList->Add(choice->GetString(i));
996
997 return new wxProperty(name, stringList, "stringlist");
998 }
999 else
1000 return wxItemPropertyInfo::GetProperty(name);
1001 }
1002
1003 bool wxChoicePropertyInfo::SetProperty(wxString& name, wxProperty *property)
1004 {
1005 wxChoice *choice = (wxChoice *)propertyWindow;
1006 if (name == "values")
1007 {
1008 choice->Clear();
1009 wxPropertyValue *expr = property->GetValue().GetFirst();
1010 while (expr)
1011 {
1012 char *s = expr->StringValue();
1013 if (s)
1014 choice->Append(s);
1015 expr = expr->GetNext();
1016 }
1017 if (choice->Number() > 0)
1018 choice->SetSelection(0);
1019 return TRUE;
1020 }
1021 else
1022 return wxItemPropertyInfo::SetProperty(name, property);
1023 }
1024
1025 void wxChoicePropertyInfo::GetPropertyNames(wxStringList& names)
1026 {
1027 names.Add("values");
1028 wxItemPropertyInfo::GetPropertyNames(names);
1029 }
1030
1031 bool wxChoicePropertyInfo::InstantiateResource(wxItemResource *resource)
1032 {
1033 wxChoice *choice = (wxChoice *)propertyWindow;
1034 int i;
1035 if (choice->Number() == 0)
1036 resource->SetStringValues(NULL);
1037 else
1038 {
1039 wxStringList *slist = new wxStringList;
1040
1041 for (i = 0; i < choice->Number(); i++)
1042 slist->Add(choice->GetString(i));
1043
1044 resource->SetStringValues(slist);
1045 }
1046 return wxItemPropertyInfo::InstantiateResource(resource);
1047 }
1048
1049 /*
1050 * Radiobox item
1051 */
1052
1053 wxProperty *wxRadioBoxPropertyInfo::GetProperty(wxString& name)
1054 {
1055 wxRadioBox *radioBox = (wxRadioBox *)propertyWindow;
1056 if (name == "numberRowsOrCols")
1057 {
1058 return new wxProperty("numberRowsOrCols", (long)radioBox->GetNumberOfRowsOrCols(), "integer");
1059 }
1060 if (name == "orientation")
1061 {
1062 char *pos = NULL;
1063 if (propertyWindow->GetWindowStyleFlag() & wxHORIZONTAL)
1064 pos = "wxHORIZONTAL";
1065 else
1066 pos = "wxVERTICAL";
1067
1068 return new wxProperty("orientation", pos, "string",
1069 new wxStringListValidator(new wxStringList("wxHORIZONTAL", "wxVERTICAL",
1070 NULL)));
1071 }
1072 else if (name == "values")
1073 {
1074 wxStringList *stringList = new wxStringList;
1075 int i;
1076 for (i = 0; i < radioBox->Number(); i++)
1077 stringList->Add(radioBox->GetString(i));
1078
1079 return new wxProperty(name, stringList, "stringlist");
1080 }
1081 return wxItemPropertyInfo::GetProperty(name);
1082 }
1083
1084 bool wxRadioBoxPropertyInfo::SetProperty(wxString& name, wxProperty *property)
1085 {
1086 wxRadioBox *radioBox = (wxRadioBox *)propertyWindow;
1087 if (name == "numberRowsOrCols")
1088 {
1089 radioBox->SetNumberOfRowsOrCols((int)property->GetValue().IntegerValue());
1090 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox, this);
1091 return TRUE;
1092 }
1093 else if (name == "orientation")
1094 {
1095 long windowStyle = radioBox->GetWindowStyleFlag();
1096 wxString val(property->GetValue().StringValue());
1097 if (val == "wxHORIZONTAL")
1098 {
1099 if (windowStyle & wxVERTICAL)
1100 windowStyle -= wxVERTICAL;
1101 windowStyle |= wxHORIZONTAL;
1102 }
1103 else
1104 {
1105 if (windowStyle & wxHORIZONTAL)
1106 windowStyle -= wxHORIZONTAL;
1107 windowStyle |= wxVERTICAL;
1108 }
1109 radioBox->SetWindowStyleFlag(windowStyle);
1110
1111 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox, this);
1112 return TRUE;
1113 }
1114 else if (name == "values")
1115 {
1116 // Set property into *resource*, not wxRadioBox, and then recreate
1117 // the wxRadioBox. This is because we can't dynamically set the strings
1118 // of a wxRadioBox.
1119 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(propertyWindow);
1120 if (!resource)
1121 return FALSE;
1122
1123 wxStringList *stringList = resource->GetStringValues();
1124 if (!stringList)
1125 {
1126 stringList = new wxStringList;
1127 resource->SetStringValues(stringList);
1128 }
1129 stringList->Clear();
1130
1131 wxPropertyValue *expr = property->GetValue().GetFirst();
1132 while (expr)
1133 {
1134 char *s = expr->StringValue();
1135 if (s)
1136 stringList->Add(s);
1137 expr = expr->GetNext();
1138 }
1139 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox, this);
1140 return TRUE;
1141 }
1142 return wxItemPropertyInfo::SetProperty(name, property);
1143 }
1144
1145 void wxRadioBoxPropertyInfo::GetPropertyNames(wxStringList& names)
1146 {
1147 names.Add("label");
1148 names.Add("values");
1149 names.Add("orientation");
1150 names.Add("numberRowsOrCols");
1151 wxItemPropertyInfo::GetPropertyNames(names);
1152 }
1153
1154 bool wxRadioBoxPropertyInfo::InstantiateResource(wxItemResource *resource)
1155 {
1156 wxRadioBox *rbox = (wxRadioBox *)propertyWindow;
1157 // Take strings from resource instead
1158 /*
1159 int i;
1160 if (rbox->Number() == 0)
1161 resource->SetStringValues(NULL);
1162 else
1163 {
1164 wxStringList *slist = new wxStringList;
1165
1166 for (i = 0; i < rbox->Number(); i++)
1167 slist->Add(rbox->GetString(i));
1168
1169 resource->SetStringValues(slist);
1170 }
1171 */
1172 resource->SetValue1(rbox->GetNumberOfRowsOrCols());
1173 return wxItemPropertyInfo::InstantiateResource(resource);
1174 }
1175
1176 /*
1177 * Groupbox item
1178 */
1179
1180 wxProperty *wxGroupBoxPropertyInfo::GetProperty(wxString& name)
1181 {
1182 wxStaticBox *groupBox = (wxStaticBox *)propertyWindow;
1183 return wxItemPropertyInfo::GetProperty(name);
1184 }
1185
1186 bool wxGroupBoxPropertyInfo::SetProperty(wxString& name, wxProperty *property)
1187 {
1188 return wxItemPropertyInfo::SetProperty(name, property);
1189 }
1190
1191 void wxGroupBoxPropertyInfo::GetPropertyNames(wxStringList& names)
1192 {
1193 names.Add("label");
1194 wxItemPropertyInfo::GetPropertyNames(names);
1195 }
1196
1197 bool wxGroupBoxPropertyInfo::InstantiateResource(wxItemResource *resource)
1198 {
1199 wxStaticBox *gbox = (wxStaticBox *)propertyWindow;
1200 return wxItemPropertyInfo::InstantiateResource(resource);
1201 }
1202
1203 /*
1204 * Checkbox item
1205 */
1206
1207 wxProperty *wxCheckBoxPropertyInfo::GetProperty(wxString& name)
1208 {
1209 wxCheckBox *checkBox = (wxCheckBox *)propertyWindow;
1210 if (name == "value")
1211 return new wxProperty("value", checkBox->GetValue(), "bool");
1212 else
1213 return wxItemPropertyInfo::GetProperty(name);
1214 }
1215
1216 bool wxCheckBoxPropertyInfo::SetProperty(wxString& name, wxProperty *property)
1217 {
1218 wxCheckBox *checkBox = (wxCheckBox *)propertyWindow;
1219 if (name == "value")
1220 {
1221 checkBox->SetValue((bool)property->GetValue().BoolValue());
1222 return TRUE;
1223 }
1224 else
1225 return wxItemPropertyInfo::SetProperty(name, property);
1226 }
1227
1228 void wxCheckBoxPropertyInfo::GetPropertyNames(wxStringList& names)
1229 {
1230 names.Add("label");
1231 names.Add("value");
1232 wxItemPropertyInfo::GetPropertyNames(names);
1233 }
1234
1235 bool wxCheckBoxPropertyInfo::InstantiateResource(wxItemResource *resource)
1236 {
1237 wxCheckBox *cbox = (wxCheckBox *)propertyWindow;
1238 resource->SetValue1(cbox->GetValue());
1239 return wxItemPropertyInfo::InstantiateResource(resource);
1240 }
1241
1242 /*
1243 * Radiobutton item
1244 */
1245
1246 wxProperty *wxRadioButtonPropertyInfo::GetProperty(wxString& name)
1247 {
1248 wxRadioButton *checkBox = (wxRadioButton *)propertyWindow;
1249 if (name == "value")
1250 return new wxProperty("value", checkBox->GetValue(), "bool");
1251 else
1252 return wxItemPropertyInfo::GetProperty(name);
1253 }
1254
1255 bool wxRadioButtonPropertyInfo::SetProperty(wxString& name, wxProperty *property)
1256 {
1257 wxRadioButton *checkBox = (wxRadioButton *)propertyWindow;
1258 if (name == "value")
1259 {
1260 checkBox->SetValue((bool)property->GetValue().BoolValue());
1261 return TRUE;
1262 }
1263 else
1264 return wxItemPropertyInfo::SetProperty(name, property);
1265 }
1266
1267 void wxRadioButtonPropertyInfo::GetPropertyNames(wxStringList& names)
1268 {
1269 names.Add("label");
1270 names.Add("value");
1271 wxItemPropertyInfo::GetPropertyNames(names);
1272 }
1273
1274 bool wxRadioButtonPropertyInfo::InstantiateResource(wxItemResource *resource)
1275 {
1276 wxRadioButton *cbox = (wxRadioButton *)propertyWindow;
1277 resource->SetValue1(cbox->GetValue());
1278 return wxItemPropertyInfo::InstantiateResource(resource);
1279 }
1280
1281 /*
1282 * Slider item
1283 */
1284
1285 wxProperty *wxSliderPropertyInfo::GetProperty(wxString& name)
1286 {
1287 wxSlider *slider = (wxSlider *)propertyWindow;
1288 if (name == "value")
1289 return new wxProperty("value", (long)slider->GetValue(), "integer");
1290 else if (name == "orientation")
1291 {
1292 char *pos = NULL;
1293 if (propertyWindow->GetWindowStyleFlag() & wxHORIZONTAL)
1294 pos = "wxHORIZONTAL";
1295 else
1296 pos = "wxVERTICAL";
1297
1298 return new wxProperty("orientation", pos, "string",
1299 new wxStringListValidator(new wxStringList("wxHORIZONTAL", "wxVERTICAL",
1300 NULL)));
1301 }
1302 else if (name == "min_value")
1303 return new wxProperty("min_value", (long)slider->GetMin(), "integer");
1304 else if (name == "max_value")
1305 return new wxProperty("max_value", (long)slider->GetMax(), "integer");
1306 else
1307 return wxItemPropertyInfo::GetProperty(name);
1308 }
1309
1310 bool wxSliderPropertyInfo::SetProperty(wxString& name, wxProperty *property)
1311 {
1312 wxSlider *slider = (wxSlider *)propertyWindow;
1313 if (name == "value")
1314 {
1315 slider->SetValue((int)property->GetValue().IntegerValue());
1316 return TRUE;
1317 }
1318 else if (name == "orientation")
1319 {
1320 long windowStyle = slider->GetWindowStyleFlag();
1321 long oldWindowStyle = windowStyle;
1322 wxString val(property->GetValue().StringValue());
1323 if (val == "wxHORIZONTAL")
1324 {
1325 if (windowStyle & wxVERTICAL)
1326 windowStyle -= wxVERTICAL;
1327 windowStyle |= wxHORIZONTAL;
1328 }
1329 else
1330 {
1331 if (windowStyle & wxHORIZONTAL)
1332 windowStyle -= wxHORIZONTAL;
1333 windowStyle |= wxVERTICAL;
1334 }
1335
1336 if (oldWindowStyle == windowStyle)
1337 return TRUE;
1338
1339 slider->SetWindowStyleFlag(windowStyle);
1340
1341 // If the window style has changed, we swap the width and height parameters.
1342 int w, h;
1343 slider->GetSize(&w, &h);
1344
1345 slider = (wxSlider *)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(slider, this);
1346 slider->SetSize(-1, -1, h, w);
1347
1348 return TRUE;
1349 }
1350 else if (name == "min_value")
1351 {
1352 slider->SetRange((int)property->GetValue().IntegerValue(), slider->GetMax());
1353 return TRUE;
1354 }
1355 else if (name == "max_value")
1356 {
1357 slider->SetRange(slider->GetMin(), (int)property->GetValue().IntegerValue());
1358 return TRUE;
1359 }
1360 else
1361 return wxItemPropertyInfo::SetProperty(name, property);
1362 }
1363
1364 void wxSliderPropertyInfo::GetPropertyNames(wxStringList& names)
1365 {
1366 names.Add("value");
1367 names.Add("orientation");
1368 names.Add("min_value");
1369 names.Add("max_value");
1370 wxItemPropertyInfo::GetPropertyNames(names);
1371 }
1372
1373 bool wxSliderPropertyInfo::InstantiateResource(wxItemResource *resource)
1374 {
1375 wxSlider *slider = (wxSlider *)propertyWindow;
1376 resource->SetValue1(slider->GetValue());
1377 resource->SetValue2(slider->GetMin());
1378 resource->SetValue3(slider->GetMax());
1379 return wxItemPropertyInfo::InstantiateResource(resource);
1380 }
1381
1382 /*
1383 * Gauge item
1384 */
1385
1386 wxProperty *wxGaugePropertyInfo::GetProperty(wxString& name)
1387 {
1388 wxGauge *gauge = (wxGauge *)propertyWindow;
1389 if (name == "value")
1390 return new wxProperty("value", (long)gauge->GetValue(), "integer");
1391 else if (name == "max_value")
1392 return new wxProperty("max_value", (long)gauge->GetRange(), "integer");
1393 else
1394 return wxItemPropertyInfo::GetProperty(name);
1395 }
1396
1397 bool wxGaugePropertyInfo::SetProperty(wxString& name, wxProperty *property)
1398 {
1399 wxGauge *gauge = (wxGauge *)propertyWindow;
1400 if (name == "value")
1401 {
1402 gauge->SetValue((int)property->GetValue().IntegerValue());
1403 return TRUE;
1404 }
1405 else if (name == "max_value")
1406 {
1407 gauge->SetRange((int)property->GetValue().IntegerValue());
1408 return TRUE;
1409 }
1410 else
1411 return wxItemPropertyInfo::SetProperty(name, property);
1412 }
1413
1414 void wxGaugePropertyInfo::GetPropertyNames(wxStringList& names)
1415 {
1416 names.Add("value");
1417 names.Add("max_value");
1418 wxItemPropertyInfo::GetPropertyNames(names);
1419 }
1420
1421 bool wxGaugePropertyInfo::InstantiateResource(wxItemResource *resource)
1422 {
1423 wxGauge *gauge = (wxGauge *)propertyWindow;
1424 resource->SetValue1(gauge->GetValue());
1425 resource->SetValue2(gauge->GetRange());
1426 return wxItemPropertyInfo::InstantiateResource(resource);
1427 }
1428
1429 /*
1430 * Scrollbar item
1431 */
1432
1433 wxProperty *wxScrollBarPropertyInfo::GetProperty(wxString& name)
1434 {
1435 wxScrollBar *scrollBar = (wxScrollBar *)propertyWindow;
1436 if (name == "value")
1437 return new wxProperty("value", (long)scrollBar->GetValue(), "integer");
1438 else if (name == "orientation")
1439 {
1440 char *pos = NULL;
1441 if (propertyWindow->GetWindowStyleFlag() & wxHORIZONTAL)
1442 pos = "wxHORIZONTAL";
1443 else
1444 pos = "wxVERTICAL";
1445
1446 return new wxProperty("orientation", pos, "string",
1447 new wxStringListValidator(new wxStringList("wxHORIZONTAL", "wxVERTICAL",
1448 NULL)));
1449 }
1450 else if (name == "pageSize")
1451 {
1452 int viewStart, pageLength, objectLength, viewLength;
1453 scrollBar->GetValues(&viewStart, &viewLength, &objectLength, &pageLength);
1454
1455 return new wxProperty("pageSize", (long)pageLength, "integer");
1456 }
1457 else if (name == "viewLength")
1458 {
1459 int viewStart, pageLength, objectLength, viewLength;
1460 scrollBar->GetValues(&viewStart, &viewLength, &objectLength, &pageLength);
1461
1462 return new wxProperty("viewLength", (long)viewLength, "integer");
1463 }
1464 else if (name == "objectLength")
1465 {
1466 int viewStart, pageLength, objectLength, viewLength;
1467 scrollBar->GetValues(&viewStart, &viewLength, &objectLength, &pageLength);
1468
1469 return new wxProperty("objectLength", (long)objectLength, "integer");
1470 }
1471 else
1472 return wxItemPropertyInfo::GetProperty(name);
1473 }
1474
1475 bool wxScrollBarPropertyInfo::SetProperty(wxString& name, wxProperty *property)
1476 {
1477 wxScrollBar *scrollBar = (wxScrollBar *)propertyWindow;
1478 if (name == "value")
1479 {
1480 scrollBar->SetValue((int)property->GetValue().IntegerValue());
1481 return TRUE;
1482 }
1483 else if (name == "orientation")
1484 {
1485 long windowStyle = scrollBar->GetWindowStyleFlag();
1486 long oldWindowStyle = windowStyle;
1487 wxString val(property->GetValue().StringValue());
1488 if (val == "wxHORIZONTAL")
1489 {
1490 if (windowStyle & wxVERTICAL)
1491 windowStyle -= wxVERTICAL;
1492 windowStyle |= wxHORIZONTAL;
1493 }
1494 else
1495 {
1496 if (windowStyle & wxHORIZONTAL)
1497 windowStyle -= wxHORIZONTAL;
1498 windowStyle |= wxVERTICAL;
1499 }
1500
1501 if (oldWindowStyle == windowStyle)
1502 return TRUE;
1503
1504 scrollBar->SetWindowStyleFlag(windowStyle);
1505
1506 // If the window style has changed, we swap the width and height parameters.
1507 int w, h;
1508 scrollBar->GetSize(&w, &h);
1509
1510 scrollBar = (wxScrollBar *)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(scrollBar, this);
1511 scrollBar->SetSize(-1, -1, h, w);
1512
1513 return TRUE;
1514 }
1515 else if (name == "pageSize")
1516 {
1517 scrollBar->SetPageSize((int)property->GetValue().IntegerValue());
1518 return TRUE;
1519 }
1520 else if (name == "viewLength")
1521 {
1522 scrollBar->SetViewLength((int)property->GetValue().IntegerValue());
1523 return TRUE;
1524 }
1525 else if (name == "objectLength")
1526 {
1527 scrollBar->SetObjectLength((int)property->GetValue().IntegerValue());
1528 return TRUE;
1529 }
1530 else
1531 return wxItemPropertyInfo::SetProperty(name, property);
1532 }
1533
1534 void wxScrollBarPropertyInfo::GetPropertyNames(wxStringList& names)
1535 {
1536 names.Add("orientation");
1537 names.Add("value");
1538 names.Add("pageSize");
1539 names.Add("viewLength");
1540 names.Add("objectLength");
1541 wxItemPropertyInfo::GetPropertyNames(names);
1542
1543 // Remove some properties we don't inherit
1544 names.Delete("fontPoints");
1545 names.Delete("fontFamily");
1546 names.Delete("fontStyle");
1547 names.Delete("fontWeight");
1548 names.Delete("fontUnderlined");
1549 }
1550
1551 bool wxScrollBarPropertyInfo::InstantiateResource(wxItemResource *resource)
1552 {
1553 wxScrollBar *sbar = (wxScrollBar *)propertyWindow;
1554
1555 resource->SetValue1(sbar->GetValue());
1556
1557 int viewStart, pageLength, objectLength, viewLength;
1558 sbar->GetValues(&viewStart, &viewLength, &objectLength, &pageLength);
1559
1560 resource->SetValue2(pageLength);
1561 resource->SetValue3(objectLength);
1562 resource->SetValue5(viewLength);
1563
1564 return wxItemPropertyInfo::InstantiateResource(resource);
1565 }
1566
1567 /*
1568 * Panels
1569 */
1570
1571 wxProperty *wxPanelPropertyInfo::GetProperty(wxString& name)
1572 {
1573 wxPanel *panelWindow = (wxPanel *)propertyWindow;
1574 wxFont *labelFont = panelWindow->GetLabelFont();
1575 wxFont *buttonFont = panelWindow->GetButtonFont();
1576
1577 if (name == "labelFontPoints" || name == "labelFontFamily" || name == "labelFontStyle" || name == "labelFontWeight" ||
1578 name == "labelFontUnderlined")
1579 return GetFontProperty(name, labelFont);
1580 else if (name == "buttonFontPoints" || name == "buttonFontFamily" || name == "buttonFontStyle" || name == "buttonFontWeight" ||
1581 name == "buttonFontUnderlined")
1582 return GetFontProperty(name, buttonFont);
1583 else if (name == "no3D")
1584 {
1585 bool userColours;
1586 if (panelWindow->GetWindowStyleFlag() & wxNO_3D)
1587 userColours = TRUE;
1588 else
1589 userColours = FALSE;
1590
1591 return new wxProperty(name, (bool)userColours, "bool");
1592 }
1593 else if (name == "backgroundColour")
1594 {
1595 wxColour col(panelWindow->GetBackgroundColour());
1596 char buf[7];
1597 wxDecToHex(col.Red(), buf);
1598 wxDecToHex(col.Green(), buf+2);
1599 wxDecToHex(col.Blue(), buf+4);
1600
1601 return new wxProperty(name, buf, "string", new wxColourListValidator);
1602 }
1603 else if (name == "title")
1604 {
1605 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow);
1606 if (resource)
1607 return new wxProperty(name, resource->GetTitle(), "string");
1608 else
1609 return new wxProperty(name, "Could not get title", "string");
1610 }
1611 else
1612 return wxWindowPropertyInfo::GetProperty(name);
1613 }
1614
1615 bool wxPanelPropertyInfo::SetProperty(wxString& name, wxProperty *property)
1616 {
1617 wxPanel *panelWindow = (wxPanel *)propertyWindow;
1618 wxFont *labelFont = panelWindow->GetLabelFont();
1619 wxFont *buttonFont = panelWindow->GetButtonFont();
1620
1621 if (labelFont && (name == "labelFontPoints" || name == "labelFontFamily" || name == "labelFontStyle" || name == "labelFontWeight" || name == "labelFontUnderlined" ))
1622 {
1623 wxFont *newFont = SetFontProperty(name, property, labelFont);
1624 if (newFont)
1625 panelWindow->SetLabelFont(newFont);
1626 return TRUE;
1627 }
1628 else if (buttonFont && (name == "buttonFontPoints" || name == "buttonFontFamily" || name == "buttonFontStyle" || name == "buttonFontWeight" || name == "buttonFontUnderlined" ))
1629 {
1630 wxFont *newFont = SetFontProperty(name, property, buttonFont);
1631 if (newFont)
1632 panelWindow->SetButtonFont(newFont);
1633 return TRUE;
1634 }
1635 else if (name == "no3D")
1636 {
1637 bool userColours = property->GetValue().BoolValue();
1638 long flag = panelWindow->GetWindowStyleFlag();
1639
1640 if (userColours)
1641 {
1642 if ((panelWindow->GetWindowStyleFlag() & wxNO_3D) != wxNO_3D)
1643 panelWindow->SetWindowStyleFlag(panelWindow->GetWindowStyleFlag() | wxNO_3D);
1644 }
1645 else
1646 {
1647 if ((panelWindow->GetWindowStyleFlag() & wxNO_3D) == wxNO_3D)
1648 panelWindow->SetWindowStyleFlag(panelWindow->GetWindowStyleFlag() - wxNO_3D);
1649 }
1650 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow);
1651 resource->SetStyle(panelWindow->GetWindowStyleFlag());
1652
1653 panelWindow = (wxPanel *)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(panelWindow, this);
1654 return TRUE;
1655 }
1656 else if (name == "backgroundColour")
1657 {
1658 char *hex = property->GetValue().StringValue();
1659 int r = wxHexToDec(hex);
1660 int g = wxHexToDec(hex+2);
1661 int b = wxHexToDec(hex+4);
1662
1663 wxColour col(r,g,b);
1664 panelWindow->SetBackgroundColour(col);
1665 panelWindow = (wxPanel *)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(panelWindow, this);
1666 return TRUE;
1667 }
1668 else if (name == "title")
1669 {
1670 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow);
1671 if (resource)
1672 {
1673 resource->SetTitle(property->GetValue().StringValue());
1674 return TRUE;
1675 }
1676 else
1677 return FALSE;
1678 }
1679 else
1680 return wxWindowPropertyInfo::SetProperty(name, property);
1681 }
1682
1683 void wxPanelPropertyInfo::GetPropertyNames(wxStringList& names)
1684 {
1685 wxWindowPropertyInfo::GetPropertyNames(names);
1686
1687 names.Add("title");
1688 names.Add("no3D");
1689 names.Add("backgroundColour");
1690 }
1691
1692 bool wxPanelPropertyInfo::InstantiateResource(wxItemResource *resource)
1693 {
1694 wxPanel *panel = (wxPanel *)propertyWindow;
1695 if (panel->GetFont())
1696 resource->SetFont(wxTheFontList->FindOrCreateFont(panel->GetFont()->GetPointSize(),
1697 panel->GetFont()->GetFamily(), panel->GetFont()->GetStyle(), panel->GetFont()->GetWeight(),
1698 panel->GetFont()->GetUnderlined(), panel->GetFont()->GetFaceName()));
1699
1700 resource->SetBackgroundColour(new wxColour(panel->GetBackgroundColour()));
1701
1702 return wxWindowPropertyInfo::InstantiateResource(resource);
1703 }
1704
1705 #if 0
1706 /*
1707 * Dialog boxes
1708 */
1709
1710 wxProperty *wxDialogPropertyInfo::GetProperty(wxString& name)
1711 {
1712 wxDialog *dialogWindow = (wxDialog *)propertyWindow;
1713 if (name == "modal")
1714 {
1715 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(dialogWindow);
1716 if (!resource)
1717 return NULL;
1718
1719 bool modal = (resource->GetValue1() != 0);
1720 return new wxProperty(name, modal, "bool");
1721 }
1722 else
1723 return wxPanelPropertyInfo::GetProperty(name);
1724 }
1725
1726 bool wxDialogPropertyInfo::SetProperty(wxString& name, wxProperty *property)
1727 {
1728 wxDialog *dialogWindow = (wxDialog *)propertyWindow;
1729
1730 if (name == "modal")
1731 {
1732 wxItemResource *resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(dialogWindow);
1733 if (!resource)
1734 return FALSE;
1735
1736 resource->SetValue1(property->GetValue().BoolValue());
1737 return TRUE;
1738 }
1739 else
1740 return wxPanelPropertyInfo::SetProperty(name, property);
1741 }
1742
1743 void wxDialogPropertyInfo::GetPropertyNames(wxStringList& names)
1744 {
1745 names.Add("title");
1746 names.Add("modal");
1747
1748 wxPanelPropertyInfo::GetPropertyNames(names);
1749 }
1750
1751 bool wxDialogPropertyInfo::InstantiateResource(wxItemResource *resource)
1752 {
1753 wxDialog *dialog = (wxDialog *)propertyWindow;
1754 wxString str(dialog->GetTitle());
1755 resource->SetTitle(WXSTRINGCAST str);
1756
1757 return wxPanelPropertyInfo::InstantiateResource(resource);
1758 }
1759 #endif
1760
1761 /*
1762 * Utilities
1763 */
1764
1765 int wxStringToFontWeight(wxString& val)
1766 {
1767 if (val == "wxBOLD") return wxBOLD;
1768 else if (val == "wxLIGHT") return wxLIGHT;
1769 else return wxNORMAL;
1770 }
1771
1772 int wxStringToFontStyle(wxString& val)
1773 {
1774 if (val == "wxITALIC") return wxITALIC;
1775 else if (val == "wxSLANT") return wxSLANT;
1776 else return wxNORMAL;
1777 }
1778
1779 int wxStringToFontFamily(wxString& val)
1780 {
1781 if (val == "wxDECORATIVE") return wxDECORATIVE;
1782 else if (val == "wxROMAN") return wxROMAN;
1783 else if (val == "wxSCRIPT") return wxSCRIPT;
1784 else if (val == "wxMODERN") return wxMODERN;
1785 else if (val == "wxTELETYPE") return wxTELETYPE;
1786 else return wxSWISS;
1787 }
1788
1789 ///
1790 /// Resource symbol validator
1791 ///
1792 IMPLEMENT_DYNAMIC_CLASS(wxResourceSymbolValidator, wxPropertyListValidator)
1793
1794 wxResourceSymbolValidator::wxResourceSymbolValidator(long flags):
1795 wxPropertyListValidator(flags)
1796 {
1797 }
1798
1799 wxResourceSymbolValidator::~wxResourceSymbolValidator(void)
1800 {
1801 }
1802
1803 bool wxResourceSymbolValidator::OnCheckValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow)
1804 {
1805 return TRUE;
1806 }
1807
1808 // Called when TICK is pressed or focus is lost or view wants to update
1809 // the property list.
1810 // Does the transferance from the property editing area to the property itself
1811 bool wxResourceSymbolValidator::OnRetrieveValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow)
1812 {
1813 if (!view->GetValueText())
1814 return FALSE;
1815 wxString value(view->GetValueText()->GetValue());
1816 property->GetValue() = value ;
1817 return TRUE;
1818 }
1819
1820 // Called when TICK is pressed or focus is lost or view wants to update
1821 // the property list.
1822 // Does the transferance from the property editing area to the property itself
1823 bool wxResourceSymbolValidator::OnDisplayValue(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow)
1824 {
1825 if (!view->GetValueText())
1826 return FALSE;
1827 wxString str(property->GetValue().GetStringRepresentation());
1828 view->GetValueText()->SetValue(str);
1829 return TRUE;
1830 }
1831
1832 // Called when the property is double clicked. Extra functionality can be provided,
1833 // cycling through possible values.
1834 bool wxResourceSymbolValidator::OnDoubleClick(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow)
1835 {
1836 if (!view->GetValueText())
1837 return FALSE;
1838 OnEdit(property, view, parentWindow);
1839 return TRUE;
1840 }
1841
1842 bool wxResourceSymbolValidator::OnPrepareControls(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow)
1843 {
1844 if (view->GetConfirmButton())
1845 view->GetConfirmButton()->Enable(TRUE);
1846 if (view->GetCancelButton())
1847 view->GetCancelButton()->Enable(TRUE);
1848 if (view->GetEditButton())
1849 view->GetEditButton()->Enable(TRUE);
1850 if (view->GetValueText())
1851 view->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING) == wxPROP_ALLOW_TEXT_EDITING);
1852 return TRUE;
1853 }
1854
1855 void wxResourceSymbolValidator::OnEdit(wxProperty *property, wxPropertyListView *view, wxWindow *parentWindow)
1856 {
1857 if (!view->GetValueText())
1858 return;
1859
1860 wxResourceSymbolDialog* dialog = new wxResourceSymbolDialog(parentWindow, -1, "Edit Symbol");
1861
1862 // Split name/id pair e.g. "IDC_TEXT=123"
1863 wxString value(property->GetValue().StringValue());
1864
1865 wxString strName = value.Before('=');
1866 wxString strId = value.After('=');
1867
1868 dialog->SetSymbol(strName);
1869 dialog->SetId(atoi(strId));
1870
1871 dialog->Init();
1872
1873 if (dialog->ShowModal() == wxID_OK)
1874 {
1875 wxString symbolName(dialog->GetSymbol());
1876 long id = dialog->GetId();
1877 dialog->Destroy();
1878
1879 wxString str;
1880 str.Printf("%d", id);
1881 property->GetValue() = symbolName + wxString("=") + str;
1882
1883 view->DisplayProperty(property);
1884 view->UpdatePropertyDisplayInList(property);
1885 view->OnPropertyChanged(property);
1886 }
1887
1888 #if 0
1889 char *s = wxFileSelector(
1890 filenameMessage.GetData(),
1891 wxPathOnly(property->GetValue().StringValue()),
1892 wxFileNameFromPath(property->GetValue().StringValue()),
1893 NULL,
1894 filenameWildCard.GetData(),
1895 0,
1896 parentWindow);
1897 if (s)
1898 {
1899 property->GetValue() = wxString(s);
1900 view->DisplayProperty(property);
1901 view->UpdatePropertyDisplayInList(property);
1902 view->OnPropertyChanged(property);
1903 }
1904 #endif
1905 }
1906
1907 BEGIN_EVENT_TABLE(wxResourceSymbolDialog, wxDialog)
1908 EVT_BUTTON(wxID_OK, wxResourceSymbolDialog::OnOK)
1909 EVT_COMBOBOX(ID_SYMBOLNAME_COMBOBOX, wxResourceSymbolDialog::OnComboBoxSelect)
1910 EVT_TEXT(ID_SYMBOLNAME_COMBOBOX, wxResourceSymbolDialog::OnSymbolNameUpdate)
1911 END_EVENT_TABLE()
1912
1913 wxResourceSymbolDialog::wxResourceSymbolDialog(wxWindow* parent, const wxWindowID id, const wxString& title, const wxPoint& pos,
1914 const wxSize& size, long style):
1915 wxDialog(parent, id, title, pos, size, style)
1916 {
1917 int x = 5;
1918 int y = 5;
1919
1920 (void) new wxStaticText(this, -1, "Name: ", wxPoint(x, y));
1921
1922 x += 80;
1923
1924 m_nameCtrl = new wxComboBox(this, ID_SYMBOLNAME_COMBOBOX, "",
1925 wxPoint(x, y), wxSize(200, -1), 0, NULL, wxCB_DROPDOWN);
1926
1927 y += 30;
1928 x = 5;
1929
1930 (void) new wxStaticText(this, -1, "Id: ", wxPoint(x, y));
1931
1932 x += 80;
1933
1934 m_idCtrl = new wxTextCtrl(this, ID_SYMBOLID_TEXTCTRL, "",
1935 wxPoint(x, y), wxSize(200, -1));
1936
1937 y += 30;
1938 x = 5;
1939 (void) new wxButton(this, wxID_OK, "OK", wxPoint(x, y), wxSize(80, -1));
1940
1941 x += 100;
1942 (void) new wxButton(this, wxID_CANCEL, "Cancel", wxPoint(x, y), wxSize(80, -1));
1943
1944 Fit();
1945 Centre();
1946 }
1947
1948 void wxResourceSymbolDialog::Init()
1949 {
1950 wxString defaultId;
1951 defaultId.Printf("%ld", m_symbolId);
1952
1953 m_nameCtrl->SetValue(m_symbolName);
1954 m_idCtrl->SetValue(defaultId);
1955
1956 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().FillComboBox(m_nameCtrl);
1957 }
1958
1959 void wxResourceSymbolDialog::OnOK(wxCommandEvent& event)
1960 {
1961 if (CheckValues())
1962 {
1963 wxDialog::OnOK(event);
1964 }
1965 }
1966
1967 bool wxResourceSymbolDialog::CheckValues()
1968 {
1969 wxString nameStr(m_nameCtrl->GetValue());
1970 wxString idStr(m_idCtrl->GetValue());
1971 int id = atoi(idStr);
1972
1973 if (id <= 0 )
1974 {
1975 wxMessageBox("Identifier cannot be missing or zero", "Dialog Editor", wxOK|wxICON_EXCLAMATION, this);
1976 return FALSE;
1977 }
1978 if (nameStr == "")
1979 {
1980 wxMessageBox("Please enter a symbol name", "Dialog Editor", wxOK|wxICON_EXCLAMATION, this);
1981 return FALSE;
1982 }
1983 if (nameStr.Contains(" "))
1984 {
1985 wxMessageBox("Symbol name cannot contain spaces.", "Dialog Editor", wxOK|wxICON_EXCLAMATION, this);
1986 return FALSE;
1987 }
1988 if (nameStr.Contains("="))
1989 {
1990 wxMessageBox("Symbol name cannot contain =.", "Dialog Editor", wxOK|wxICON_EXCLAMATION, this);
1991 return FALSE;
1992 }
1993 if (nameStr.IsNumber())
1994 {
1995 wxMessageBox("Symbol name cannot be a number.", "Dialog Editor", wxOK|wxICON_EXCLAMATION, this);
1996 return FALSE;
1997 }
1998 // TODO: other checks on the name syntax.
1999
2000 if (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(nameStr))
2001 {
2002 // If we change the id for an existing symbol, we need to:
2003 // 1) Check if there are any other resources currently using the original id.
2004 // If so, will need to change their id to the new id, in SetProperty.
2005 // 2) Remove the old symbol, add the new symbol.
2006 // In this check, we don't have to do this, but we need to do it in SetProperty.
2007
2008 if (nameStr == GetSymbol() && id != GetId())
2009 {
2010 // It's OK to change the id. But we'll need to change all matching ids in all resources,
2011 // in SetProperty.
2012 }
2013
2014 // If we change the name but not the id... we'll just need to remove and
2015 // re-add the symbol/id pair, in SetProperty.
2016 if (nameStr != GetSymbol() && id == GetId())
2017 {
2018 }
2019
2020 // What if we're changing both the name and the id?
2021 // - if there's no symbol of that name, just remove the old, add the new (in SetProperty)
2022 // - if there is a symbol of that name, if id matches, do nothing. If not, veto.
2023
2024 if (nameStr != GetSymbol() && id != GetId())
2025 {
2026 if (!wxResourceManager::GetCurrentResourceManager()->IsIdentifierOK(nameStr, id))
2027 {
2028 wxMessageBox("This integer id is already being used under a different name.\nPlease choose another.",
2029 "Dialog Editor", wxOK|wxICON_EXCLAMATION, this);
2030 return FALSE;
2031 }
2032 }
2033
2034 }
2035
2036 SetSymbol(nameStr);
2037 SetId(id);
2038
2039 return TRUE;
2040 }
2041
2042 void wxResourceSymbolDialog::OnComboBoxSelect(wxCommandEvent& event)
2043 {
2044 wxString str(m_nameCtrl->GetValue());
2045 if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(str))
2046 {
2047 int id = wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str);
2048 wxString str2;
2049 str2.Printf("%d", id);
2050 m_idCtrl->SetValue(str2);
2051 m_idCtrl->Enable(FALSE);
2052 }
2053 else
2054 {
2055 if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().SymbolExists(str))
2056 {
2057 int id = wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str);
2058 wxString str2;
2059 str2.Printf("%d", id);
2060 m_idCtrl->SetValue(str2);
2061 }
2062 m_idCtrl->Enable(TRUE);
2063 }
2064 }
2065
2066 void wxResourceSymbolDialog::OnSymbolNameUpdate(wxCommandEvent& event)
2067 {
2068 wxString str(m_nameCtrl->GetValue());
2069 if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(str))
2070 {
2071 int id = wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str);
2072 wxString str2;
2073 str2.Printf("%d", id);
2074 m_idCtrl->SetValue(str2);
2075 m_idCtrl->Enable(FALSE);
2076 }
2077 else
2078 {
2079 if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().SymbolExists(str))
2080 {
2081 int id = wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str);
2082 wxString str2;
2083 str2.Printf("%d", id);
2084 m_idCtrl->SetValue(str2);
2085 }
2086 m_idCtrl->Enable(TRUE);
2087 }
2088 }
2089