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