]> git.saurik.com Git - wxWidgets.git/blob - utils/dialoged/src/winprop.cpp
*** empty log message ***
[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(__WINDOWS__) && !defined(__GNUWIN32__)
33 #include <strstrea.h>
34 #else
35 #include <strstream.h>
36 #endif
37
38 #ifdef __WINDOWS__
39 #include <windows.h>
40 #endif
41
42 #include "reseditr.h"
43 #include "editrpal.h"
44 #include "winprop.h"
45
46 // Causes immediate feedback.
47 void wxResourcePropertyListView::OnPropertyChanged(wxProperty *property)
48 {
49 // Sets the value of the property back into the actual object,
50 // IF the property value was modified.
51 if (property->GetValue().GetModified())
52 {
53 propertyInfo->SetProperty(property->GetName(), property);
54 property->GetValue().SetModified(FALSE);
55 }
56 }
57
58 bool wxResourcePropertyListView::OnClose(void)
59 {
60 int w, h, x, y;
61 GetManagedWindow()->GetSize(& w, & h);
62 GetManagedWindow()->GetPosition(& x, & y);
63
64 wxResourceManager::currentResourceManager->propertyWindowSize.width = w;
65 wxResourceManager::currentResourceManager->propertyWindowSize.height = h;
66 wxResourceManager::currentResourceManager->propertyWindowSize.x = x;
67 wxResourceManager::currentResourceManager->propertyWindowSize.y = y;
68
69 return wxPropertyListView::OnClose();
70 }
71
72 /*
73 * wxPropertyInfo
74 */
75
76 wxWindow *wxPropertyInfo::sm_propertyWindow;
77
78 // Edit the information represented by this object, whatever that
79 // might be.
80 bool wxPropertyInfo::Edit(wxWindow *parent, char *title)
81 {
82 int width = wxResourceManager::currentResourceManager->propertyWindowSize.width;
83 int height = wxResourceManager::currentResourceManager->propertyWindowSize.height;
84 int x = wxResourceManager::currentResourceManager->propertyWindowSize.x;
85 int y = wxResourceManager::currentResourceManager->propertyWindowSize.y;
86
87 wxPropertySheet *propSheet = new wxPropertySheet;
88
89 wxStringList propNames;
90 GetPropertyNames(propNames);
91
92 wxNode *node = propNames.First();
93 while (node)
94 {
95 wxString name((char *)node->Data());
96 wxProperty *prop = GetProperty(name);
97 if (prop)
98 {
99 propSheet->AddProperty(prop);
100 }
101 node = node->Next();
102 }
103
104 // Reset 'modified' flags for all property values
105 propSheet->SetAllModified(FALSE);
106
107 if (!title)
108 title = "Properties";
109 wxResourcePropertyListView *view = new wxResourcePropertyListView(this, NULL,
110 #ifdef __XVIEW__
111 wxPROP_BUTTON_OK | wxPROP_BUTTON_CANCEL |
112 #endif
113 wxPROP_BUTTON_CHECK_CROSS|wxPROP_DYNAMIC_VALUE_FIELD|wxPROP_PULLDOWN|wxPROP_SHOWVALUES);
114
115 wxPropertyListDialog *propDialog = new wxPropertyListDialog(view, NULL, title, wxPoint(x, y), wxSize(width, height), wxDIALOG_MODAL|wxDEFAULT_DIALOG_STYLE);
116 sm_propertyWindow = propDialog;
117
118 wxPropertyValidatorRegistry theValidatorRegistry;
119 theValidatorRegistry.RegisterValidator((wxString)"real", new wxRealListValidator);
120 theValidatorRegistry.RegisterValidator((wxString)"string", new wxStringListValidator);
121 theValidatorRegistry.RegisterValidator((wxString)"integer", new wxIntegerListValidator);
122 theValidatorRegistry.RegisterValidator((wxString)"bool", new wxBoolListValidator);
123 theValidatorRegistry.RegisterValidator((wxString)"filename", new wxFilenameListValidator);
124 theValidatorRegistry.RegisterValidator((wxString)"stringlist", new wxListOfStringsListValidator);
125
126 // view->propertyWindow = propDialog;
127 view->AddRegistry(&theValidatorRegistry);
128 view->ShowView(propSheet, propDialog);
129
130 int ret = propDialog->ShowModal();
131 sm_propertyWindow = NULL;
132 delete propSheet;
133
134 if ( ret == wxID_CANCEL )
135 return FALSE;
136 else
137 return TRUE;
138 }
139
140 /*
141 * wxWindowPropertyInfo
142 */
143
144 wxWindowPropertyInfo::wxWindowPropertyInfo(wxWindow *win, wxItemResource *res)
145 {
146 propertyWindow = win;
147 propertyResource = res;
148 }
149
150 wxWindowPropertyInfo::~wxWindowPropertyInfo(void)
151 {
152 }
153
154 wxProperty *wxWindowPropertyInfo::GetFontProperty(wxString& name, wxFont *font)
155 {
156 if (!font)
157 return NULL;
158
159 if (name.Contains("Points"))
160 return new wxProperty(name, (long)font->GetPointSize(), "integer", new wxIntegerListValidator(1, 100));
161 else if (name.Contains("Family"))
162 return new wxProperty(name, font->GetFamilyString(), "string",
163 new wxStringListValidator(new wxStringList("wxDECORATIVE", "wxROMAN", "wxSCRIPT", "wxSWISS", "wxMODERN",
164 NULL)));
165 else if (name.Contains("Style"))
166 return new wxProperty(name, font->GetStyleString(), "string",
167 new wxStringListValidator(new wxStringList("wxNORMAL", "wxITALIC", "wxSLANT", NULL)));
168 else if (name.Contains("Weight"))
169 return new wxProperty(name, font->GetWeightString(), "string",
170 new wxStringListValidator(new wxStringList("wxNORMAL", "wxBOLD", "wxLIGHT", NULL)));
171 else if (name.Contains("Underlined"))
172 return new wxProperty(name, (bool)font->GetUnderlined(), "bool");
173 else
174 return NULL;
175 }
176
177 wxFont *wxWindowPropertyInfo::SetFontProperty(wxString& name, wxProperty *property, wxFont *font)
178 {
179 int pointSize = 12;
180 int fontFamily = wxMODERN;
181 int fontStyle = wxNORMAL;
182 int fontWeight = wxNORMAL;
183 bool fontUnderlined = FALSE;
184
185 if (name.Contains("Points"))
186 {
187 pointSize = (int)property->GetValue().IntegerValue();
188 if (font && (pointSize == font->GetPointSize()))
189 return NULL; // No change
190 }
191 else if (font) pointSize = font->GetPointSize();
192
193 if (name.Contains("Family"))
194 {
195 wxString val = property->GetValue().StringValue();
196 fontFamily = wxStringToFontFamily(val);
197
198 if (font && (fontFamily == font->GetFamily()))
199 return NULL; // No change
200 }
201 else if (font) fontFamily = font->GetFamily();
202
203 if (name.Contains("Style"))
204 {
205 wxString val = property->GetValue().StringValue();
206 fontStyle = wxStringToFontStyle(val);
207
208 if (font && (fontStyle == font->GetStyle()))
209 return NULL; // No change
210 }
211 else if (font) fontStyle = font->GetStyle();
212 if (name.Contains("Weight"))
213 {
214 wxString val = property->GetValue().StringValue();
215 fontWeight = wxStringToFontWeight(val);
216
217 if (font && (fontWeight == font->GetWeight()))
218 return NULL; // No change
219 }
220 else if (font) fontWeight = font->GetWeight();
221
222 if (name.Contains("Underlined"))
223 {
224 fontUnderlined = property->GetValue().BoolValue();
225
226 if (font && (fontUnderlined == font->GetUnderlined()))
227 return NULL; // No change
228 }
229 else if (font) fontUnderlined = font->GetUnderlined();
230
231 wxFont *newFont = wxTheFontList->FindOrCreateFont(pointSize, fontFamily, fontStyle, fontWeight, fontUnderlined);
232 if (newFont)
233 {
234 return newFont;
235 }
236 else
237 return NULL;
238 }
239
240 wxProperty *wxWindowPropertyInfo::GetProperty(wxString& name)
241 {
242 wxFont *font = propertyWindow->GetFont();
243 if (name == "fontPoints" || name == "fontFamily" || name == "fontStyle" || name == "fontWeight" ||
244 name == "fontUnderlined")
245 return GetFontProperty(name, font);
246 else if (name == "name")
247 return new wxProperty("name", propertyWindow->GetName(), "string");
248 else if (name == "title")
249 return new wxProperty("title", propertyWindow->GetTitle(), "string");
250 else if (name == "x")
251 {
252 int x, y;
253 propertyWindow->GetPosition(&x, &y);
254 return new wxProperty("x", (long)x, "integer");
255 }
256 else if (name == "y")
257 {
258 int x, y;
259 propertyWindow->GetPosition(&x, &y);
260 return new wxProperty("y", (long)y, "integer");
261 }
262 else if (name == "width")
263 {
264 int width, height;
265 propertyWindow->GetSize(&width, &height);
266 return new wxProperty("width", (long)width, "integer");
267 }
268 else if (name == "height")
269 {
270 int width, height;
271 propertyWindow->GetSize(&width, &height);
272 return new wxProperty("height", (long)height, "integer");
273 }
274 else
275 return NULL;
276 }
277
278 bool wxWindowPropertyInfo::SetProperty(wxString& name, wxProperty *property)
279 {
280 wxFont *font = propertyWindow->GetFont();
281 if (font && (name == "fontPoints" || name == "fontFamily" || name == "fontStyle" || name == "fontWeight" || name == "fontUnderlined" ))
282 {
283 wxFont *newFont = SetFontProperty(name, property, font);
284 if (newFont)
285 propertyWindow->SetFont(newFont);
286 return TRUE;
287 }
288 else if (name == "name")
289 {
290 // Remove old name from resource table, if it's there.
291 wxItemResource *oldResource = (wxItemResource *)wxResourceManager::currentResourceManager->GetResourceTable().Delete(propertyWindow->GetName());
292 if (oldResource)
293 {
294 // It's a top-level resource
295 propertyWindow->SetName(property->GetValue().StringValue());
296 oldResource->SetName(property->GetValue().StringValue());
297 wxResourceManager::currentResourceManager->GetResourceTable().Put(propertyWindow->GetName(), oldResource);
298 }
299 else
300 {
301 // It's a child of something; just set the name of the resource and the window.
302 propertyWindow->SetName(property->GetValue().StringValue());
303 propertyResource->SetName(property->GetValue().StringValue());
304 }
305 // Refresh the resource manager list, because the name changed.
306 wxResourceManager::currentResourceManager->UpdateResourceList();
307 return TRUE;
308 }
309 else if (name == "title")
310 {
311 propertyWindow->SetTitle(property->GetValue().StringValue());
312 return TRUE;
313 }
314 else if (name == "x")
315 {
316 int x, y;
317 propertyWindow->GetPosition(&x, &y);
318 int newX = (int)property->GetValue().IntegerValue();
319 if (x != newX)
320 propertyWindow->Move(newX, y);
321 return TRUE;
322 }
323 else if (name == "y")
324 {
325 int x, y;
326 propertyWindow->GetPosition(&x, &y);
327 int newY = (int)property->GetValue().IntegerValue();
328 if (y != newY)
329 propertyWindow->Move(x, newY);
330 return TRUE;
331 }
332 else if (name == "width")
333 {
334 int width, height;
335 propertyWindow->GetSize(&width, &height);
336 int newWidth = (int)property->GetValue().IntegerValue();
337 if (width != newWidth)
338 {
339 propertyWindow->SetSize(newWidth, height);
340 if (propertyWindow->IsKindOf(CLASSINFO(wxPanel)) && !propertyWindow->IsKindOf(CLASSINFO(wxDialog)))
341 {
342 propertyWindow->GetParent()->SetClientSize(newWidth, height);
343 }
344 }
345 return TRUE;
346 }
347 else if (name == "height")
348 {
349 int width, height;
350 propertyWindow->GetSize(&width, &height);
351 int newHeight = (int)property->GetValue().IntegerValue();
352 if (height != newHeight)
353 {
354 propertyWindow->SetSize(width, newHeight);
355 if (propertyWindow->IsKindOf(CLASSINFO(wxPanel)) && !propertyWindow->IsKindOf(CLASSINFO(wxDialog)))
356 {
357 propertyWindow->GetParent()->SetClientSize(width, newHeight);
358 }
359 }
360 return TRUE;
361 }
362 else
363 return FALSE;
364 }
365
366 void wxWindowPropertyInfo::GetPropertyNames(wxStringList& names)
367 {
368 names.Add("name");
369 names.Add("x");
370 names.Add("y");
371 names.Add("width");
372 names.Add("height");
373 if (!propertyWindow->IsKindOf(CLASSINFO(wxControl)))
374 {
375 names.Add("fontPoints");
376 names.Add("fontFamily");
377 names.Add("fontStyle");
378 names.Add("fontWeight");
379 names.Add("fontUnderlined");
380 }
381 }
382
383 // Fill in the wxItemResource members to mirror the current window settings
384 bool wxWindowPropertyInfo::InstantiateResource(wxItemResource *resource)
385 {
386 resource->SetType(propertyWindow->GetClassInfo()->GetClassName());
387
388 // resource->SetStyle(propertyWindow->GetWindowStyleFlag());
389 wxString str(propertyWindow->GetName());
390 resource->SetName(WXSTRINGCAST str);
391 int x, y, w, h;
392 propertyWindow->GetSize(&w, &h);
393
394 propertyWindow->GetPosition(&x, &y);
395 resource->SetSize(x, y, w, h);
396 return TRUE;
397 }
398
399
400 /*
401 * Panel items
402 */
403
404 wxProperty *wxItemPropertyInfo::GetProperty(wxString& name)
405 {
406 wxControl *itemWindow = (wxControl *)propertyWindow;
407 wxFont *font = itemWindow->GetFont();
408
409 if (name == "fontPoints" || name == "fontFamily" || name == "fontStyle" || name == "fontWeight" ||
410 name == "fontUnderlined")
411 return GetFontProperty(name, font);
412 else if (name == "label" && itemWindow->GetLabel())
413 return new wxProperty("label", propertyWindow->GetLabel(), "string");
414 else
415 return wxWindowPropertyInfo::GetProperty(name);
416 }
417
418 bool wxItemPropertyInfo::SetProperty(wxString& name, wxProperty *property)
419 {
420 wxControl *itemWindow = (wxControl *)propertyWindow;
421 wxFont *font = itemWindow->GetFont();
422
423 if (font && (name == "fontPoints" || name == "fontFamily" || name == "fontStyle" || name == "fontWeight" || name == "fontUnderlined" ))
424 {
425 wxFont *newFont = SetFontProperty(name, property, font);
426 if (newFont)
427 itemWindow->SetLabelFont(newFont);
428 return TRUE;
429 }
430 else if (name == "label")
431 {
432 itemWindow->SetLabel(property->GetValue().StringValue());
433 return TRUE;
434 }
435 else
436 return wxWindowPropertyInfo::SetProperty(name, property);
437 }
438
439 void wxItemPropertyInfo::GetPropertyNames(wxStringList& names)
440 {
441 wxWindowPropertyInfo::GetPropertyNames(names);
442
443 names.Add("fontPoints");
444 names.Add("fontFamily");
445 names.Add("fontStyle");
446 names.Add("fontWeight");
447 names.Add("fontUnderlined");
448 }
449
450 bool wxItemPropertyInfo::InstantiateResource(wxItemResource *resource)
451 {
452 wxWindowPropertyInfo::InstantiateResource(resource);
453
454 wxControl *item = (wxControl *)propertyWindow;
455 wxString str(item->GetLabel());
456 resource->SetTitle(WXSTRINGCAST str);
457 if (item->GetFont())
458 resource->SetFont(wxTheFontList->FindOrCreateFont(item->GetFont()->GetPointSize(),
459 item->GetFont()->GetFamily(), item->GetFont()->GetStyle(), item->GetFont()->GetWeight(),
460 item->GetFont()->GetUnderlined(), item->GetFont()->GetFaceName()));
461 return TRUE;
462 }
463
464 /*
465 * Button
466 */
467
468 wxProperty *wxButtonPropertyInfo::GetProperty(wxString& name)
469 {
470 wxButton *button = (wxButton *)propertyWindow;
471 /*
472 if (name == "label" && isBitmapButton)
473 {
474 wxItemResource *resource = wxResourceManager::currentResourceManager->FindResourceForWindow(button);
475 wxString str("none.bmp");
476
477 if (resource)
478 {
479 char *filename = wxResourceManager::currentResourceManager->FindBitmapFilenameForResource(resource);
480 if (filename)
481 str = filename;
482 }
483 return new wxProperty("label", str.GetData(), "string", new wxFilenameListValidator("Select a bitmap file", "*.bmp"));
484 }
485 else
486 */
487 return wxItemPropertyInfo::GetProperty(name);
488 }
489
490 bool wxButtonPropertyInfo::SetProperty(wxString& name, wxProperty *property)
491 {
492 wxButton *button = (wxButton *)propertyWindow;
493 /*
494 if (name == "label" && isBitmapButton)
495 {
496 char *s = property->GetValue().StringValue();
497 if (s && wxFileExists(s))
498 {
499 s = copystring(s);
500 wxBitmap *bitmap = new wxBitmap(s, wxBITMAP_TYPE_BMP);
501 if (!bitmap->Ok())
502 {
503 delete bitmap;
504 delete[] s;
505 return FALSE;
506 }
507 else
508 {
509 wxItemResource *resource = wxResourceManager::currentResourceManager->FindResourceForWindow(button);
510 if (resource)
511 {
512 wxString oldResource(resource->GetValue4());
513 char *resName = wxResourceManager::currentResourceManager->AddBitmapResource(s);
514 resource->SetValue4(resName);
515
516 if (!oldResource.IsNull())
517 wxResourceManager::currentResourceManager->PossiblyDeleteBitmapResource(WXSTRINGCAST oldResource);
518 }
519
520 button->SetLabel(bitmap);
521 delete[] s;
522 return TRUE;
523 }
524 }
525 return FALSE;
526 }
527 else
528 */
529 return wxItemPropertyInfo::SetProperty(name, property);
530 }
531
532 void wxButtonPropertyInfo::GetPropertyNames(wxStringList& names)
533 {
534 names.Add("label");
535 wxItemPropertyInfo::GetPropertyNames(names);
536 }
537
538 bool wxButtonPropertyInfo::InstantiateResource(wxItemResource *resource)
539 {
540 return wxItemPropertyInfo::InstantiateResource(resource);
541 }
542
543 /*
544 * Message
545 */
546
547 wxProperty *wxStaticTextPropertyInfo::GetProperty(wxString& name)
548 {
549 wxStaticText *message = (wxStaticText *)propertyWindow;
550 /*
551 if (name == "label" && isBitmapMessage)
552 {
553 wxItemResource *resource = wxResourceManager::currentResourceManager->FindResourceForWindow(message);
554 wxString str("none.bmp");
555
556 if (resource)
557 {
558 char *filename = wxResourceManager::currentResourceManager->FindBitmapFilenameForResource(resource);
559 if (filename)
560 str = filename;
561 }
562 return new wxProperty("label", str.GetData(), "string", new wxFilenameListValidator("Select a bitmap file", "*.bmp"));
563 }
564 else
565 */
566 return wxItemPropertyInfo::GetProperty(name);
567 }
568
569 bool wxStaticTextPropertyInfo::SetProperty(wxString& name, wxProperty *property)
570 {
571 wxStaticText *message = (wxStaticText *)propertyWindow;
572 /*
573 if (name == "label" && isBitmapMessage)
574 {
575 char *s = property->GetValue().StringValue();
576 if (s && wxFileExists(s))
577 {
578 s = copystring(s);
579
580 wxBitmap *bitmap = new wxBitmap(s, wxBITMAP_TYPE_BMP);
581 if (!bitmap->Ok())
582 {
583 delete bitmap;
584 delete[] s;
585 return FALSE;
586 }
587 else
588 {
589 wxItemResource *resource = wxResourceManager::currentResourceManager->FindResourceForWindow(message);
590 if (resource)
591 {
592 wxString oldResource(resource->GetValue4());
593 char *resName = wxResourceManager::currentResourceManager->AddBitmapResource(s);
594 resource->SetValue4(resName);
595
596 if (!oldResource.IsNull())
597 wxResourceManager::currentResourceManager->PossiblyDeleteBitmapResource(WXSTRINGCAST oldResource);
598 }
599
600 message->SetLabel(bitmap);
601 delete[] s;
602 return TRUE;
603 }
604 }
605 return FALSE;
606 }
607 else
608 */
609 return wxItemPropertyInfo::SetProperty(name, property);
610 }
611
612 void wxStaticTextPropertyInfo::GetPropertyNames(wxStringList& names)
613 {
614 names.Add("label");
615 wxItemPropertyInfo::GetPropertyNames(names);
616 }
617
618 bool wxStaticTextPropertyInfo::InstantiateResource(wxItemResource *resource)
619 {
620 return wxItemPropertyInfo::InstantiateResource(resource);
621 }
622
623 /*
624 * Text item
625 */
626
627 wxProperty *wxTextPropertyInfo::GetProperty(wxString& name)
628 {
629 wxTextCtrl *text = (wxTextCtrl *)propertyWindow;
630 if (name == "value")
631 return new wxProperty("value", text->GetValue(), "string");
632 else if (name == "password")
633 {
634 bool isPassword = ((text->GetWindowStyleFlag() & wxTE_PASSWORD) == wxTE_PASSWORD);
635 return new wxProperty("password", isPassword, "bool");
636 }
637 else if (name == "readonly")
638 {
639 bool isReadOnly = ((text->GetWindowStyleFlag() & wxTE_READONLY) == wxTE_READONLY);
640 return new wxProperty("readonly", isReadOnly, "bool");
641 }
642 else
643 return wxItemPropertyInfo::GetProperty(name);
644 }
645
646 bool wxTextPropertyInfo::SetProperty(wxString& name, wxProperty *property)
647 {
648 wxTextCtrl *text = (wxTextCtrl *)propertyWindow;
649 if (name == "value")
650 {
651 text->SetValue(property->GetValue().StringValue());
652 return TRUE;
653 }
654 else if (name == "password")
655 {
656 long flag = text->GetWindowStyleFlag();
657 if (property->GetValue().BoolValue())
658 {
659 if ((flag & wxTE_PASSWORD) != wxTE_PASSWORD)
660 flag |= wxTE_PASSWORD;
661 }
662 else
663 {
664 if ((flag & wxTE_PASSWORD) == wxTE_PASSWORD)
665 flag -= wxTE_PASSWORD;
666 }
667 wxItemResource *resource = wxResourceManager::currentResourceManager->FindResourceForWindow(text);
668 resource->SetStyle(flag);
669
670 wxResourceManager::currentResourceManager->RecreateWindowFromResource(text, this);
671 return TRUE;
672 }
673 else if (name == "readonly")
674 {
675 long flag = text->GetWindowStyleFlag();
676 if (property->GetValue().BoolValue())
677 {
678 if ((flag & wxTE_READONLY) != wxTE_READONLY)
679 flag |= wxTE_READONLY;
680 }
681 else
682 {
683 if ((flag & wxTE_READONLY) == wxTE_READONLY)
684 flag -= wxTE_READONLY;
685 }
686 wxItemResource *resource = wxResourceManager::currentResourceManager->FindResourceForWindow(text);
687 resource->SetStyle(flag);
688
689 wxResourceManager::currentResourceManager->RecreateWindowFromResource(text, this);
690 return TRUE;
691 }
692 else
693 return wxItemPropertyInfo::SetProperty(name, property);
694 }
695
696 void wxTextPropertyInfo::GetPropertyNames(wxStringList& names)
697 {
698 names.Add("value");
699 names.Add("readonly");
700 names.Add("password");
701 wxItemPropertyInfo::GetPropertyNames(names);
702 }
703
704 bool wxTextPropertyInfo::InstantiateResource(wxItemResource *resource)
705 {
706 wxTextCtrl *text = (wxTextCtrl *)propertyWindow;
707 wxString str(text->GetValue());
708 resource->SetValue4(WXSTRINGCAST str);
709
710 return wxItemPropertyInfo::InstantiateResource(resource);
711 }
712
713 /*
714 * Listbox item
715 */
716
717 wxProperty *wxListBoxPropertyInfo::GetProperty(wxString& name)
718 {
719 wxListBox *listBox = (wxListBox *)propertyWindow;
720 if (name == "values")
721 {
722 wxStringList *stringList = new wxStringList;
723 int i;
724 for (i = 0; i < listBox->Number(); i++)
725 stringList->Add(listBox->GetString(i));
726
727 return new wxProperty(name, stringList, "stringlist");
728 }
729 else if (name == "multiple")
730 {
731 char *pos = NULL;
732 wxItemResource *resource = wxResourceManager::currentResourceManager->FindResourceForWindow(listBox);
733 if (!resource)
734 return NULL;
735
736 char *mult = "wxSINGLE";
737
738 switch (resource->GetValue1())
739 {
740 case wxLB_MULTIPLE:
741 mult = "wxLB_MULTIPLE";
742 break;
743 case wxLB_EXTENDED:
744 mult = "wxLB_EXTENDED";
745 break;
746 default:
747 case wxLB_SINGLE:
748 mult = "wxLB_SINGLE";
749 break;
750 }
751 return new wxProperty("multiple", mult, "string",
752 new wxStringListValidator(new wxStringList("wxLB_SINGLE", "wxLB_MULTIPLE", "wxLB_EXTENDED",
753 NULL)));
754 }
755 else
756 return wxItemPropertyInfo::GetProperty(name);
757 }
758
759 bool wxListBoxPropertyInfo::SetProperty(wxString& name, wxProperty *property)
760 {
761 wxListBox *listBox = (wxListBox *)propertyWindow;
762 if (name == "values")
763 {
764 listBox->Clear();
765 wxPropertyValue *expr = property->GetValue().GetFirst();
766 while (expr)
767 {
768 char *s = expr->StringValue();
769 if (s)
770 listBox->Append(s);
771 expr = expr->GetNext();
772 }
773 return TRUE;
774 }
775 else if (name == "multiple")
776 {
777 int mult = wxLB_SINGLE;
778 wxString str(property->GetValue().StringValue());
779 if (str == "wxLB_MULTIPLE")
780 mult = wxLB_MULTIPLE;
781 else if (str == "wxLB_EXTENDED")
782 mult = wxLB_EXTENDED;
783 else
784 mult = wxLB_SINGLE;
785 wxItemResource *resource = wxResourceManager::currentResourceManager->FindResourceForWindow(listBox);
786 if (resource)
787 resource->SetValue1(mult);
788 wxResourceManager::currentResourceManager->RecreateWindowFromResource(listBox, this);
789 return TRUE;
790 }
791 else
792 return wxItemPropertyInfo::SetProperty(name, property);
793 }
794
795 void wxListBoxPropertyInfo::GetPropertyNames(wxStringList& names)
796 {
797 names.Add("values");
798 names.Add("multiple");
799 wxItemPropertyInfo::GetPropertyNames(names);
800 }
801
802 bool wxListBoxPropertyInfo::InstantiateResource(wxItemResource *resource)
803 {
804 wxListBox *lbox = (wxListBox *)propertyWindow;
805 // This will be set for the wxItemResource on reading or in SetProperty
806 // resource->SetValue1(lbox->GetSelectionMode());
807 int i;
808 if (lbox->Number() == 0)
809 resource->SetStringValues(NULL);
810 else
811 {
812 wxStringList *slist = new wxStringList;
813
814 for (i = 0; i < lbox->Number(); i++)
815 slist->Add(lbox->GetString(i));
816
817 resource->SetStringValues(slist);
818 }
819 return wxItemPropertyInfo::InstantiateResource(resource);
820 }
821
822 /*
823 * Choice item
824 */
825
826 wxProperty *wxChoicePropertyInfo::GetProperty(wxString& name)
827 {
828 wxChoice *choice = (wxChoice *)propertyWindow;
829 if (name == "values")
830 {
831 wxStringList *stringList = new wxStringList;
832 int i;
833 for (i = 0; i < choice->Number(); i++)
834 stringList->Add(choice->GetString(i));
835
836 return new wxProperty(name, stringList, "stringlist");
837 }
838 else
839 return wxItemPropertyInfo::GetProperty(name);
840 }
841
842 bool wxChoicePropertyInfo::SetProperty(wxString& name, wxProperty *property)
843 {
844 wxChoice *choice = (wxChoice *)propertyWindow;
845 if (name == "values")
846 {
847 choice->Clear();
848 wxPropertyValue *expr = property->GetValue().GetFirst();
849 while (expr)
850 {
851 char *s = expr->StringValue();
852 if (s)
853 choice->Append(s);
854 expr = expr->GetNext();
855 }
856 if (choice->Number() > 0)
857 choice->SetSelection(0);
858 return TRUE;
859 }
860 else
861 return wxItemPropertyInfo::SetProperty(name, property);
862 }
863
864 void wxChoicePropertyInfo::GetPropertyNames(wxStringList& names)
865 {
866 names.Add("values");
867 wxItemPropertyInfo::GetPropertyNames(names);
868 }
869
870 bool wxChoicePropertyInfo::InstantiateResource(wxItemResource *resource)
871 {
872 wxChoice *choice = (wxChoice *)propertyWindow;
873 int i;
874 if (choice->Number() == 0)
875 resource->SetStringValues(NULL);
876 else
877 {
878 wxStringList *slist = new wxStringList;
879
880 for (i = 0; i < choice->Number(); i++)
881 slist->Add(choice->GetString(i));
882
883 resource->SetStringValues(slist);
884 }
885 return wxItemPropertyInfo::InstantiateResource(resource);
886 }
887
888 /*
889 * Radiobox item
890 */
891
892 wxProperty *wxRadioBoxPropertyInfo::GetProperty(wxString& name)
893 {
894 wxRadioBox *radioBox = (wxRadioBox *)propertyWindow;
895 if (name == "numberRowsOrCols")
896 {
897 return new wxProperty("numberRowsOrCols", (long)radioBox->GetNumberOfRowsOrCols(), "integer");
898 }
899 if (name == "orientation")
900 {
901 char *pos = NULL;
902 if (propertyWindow->GetWindowStyleFlag() & wxHORIZONTAL)
903 pos = "wxHORIZONTAL";
904 else
905 pos = "wxVERTICAL";
906
907 return new wxProperty("orientation", pos, "string",
908 new wxStringListValidator(new wxStringList("wxHORIZONTAL", "wxVERTICAL",
909 NULL)));
910 }
911 else if (name == "values")
912 {
913 wxStringList *stringList = new wxStringList;
914 int i;
915 for (i = 0; i < radioBox->Number(); i++)
916 stringList->Add(radioBox->GetString(i));
917
918 return new wxProperty(name, stringList, "stringlist");
919 }
920 return wxItemPropertyInfo::GetProperty(name);
921 }
922
923 bool wxRadioBoxPropertyInfo::SetProperty(wxString& name, wxProperty *property)
924 {
925 wxRadioBox *radioBox = (wxRadioBox *)propertyWindow;
926 if (name == "numberRowsOrCols")
927 {
928 radioBox->SetNumberOfRowsOrCols((int)property->GetValue().IntegerValue());
929 wxResourceManager::currentResourceManager->RecreateWindowFromResource(radioBox, this);
930 return TRUE;
931 }
932 else if (name == "orientation")
933 {
934 long windowStyle = radioBox->GetWindowStyleFlag();
935 wxString val(property->GetValue().StringValue());
936 if (val == "wxHORIZONTAL")
937 {
938 if (windowStyle & wxVERTICAL)
939 windowStyle -= wxVERTICAL;
940 windowStyle |= wxHORIZONTAL;
941 }
942 else
943 {
944 if (windowStyle & wxHORIZONTAL)
945 windowStyle -= wxHORIZONTAL;
946 windowStyle |= wxVERTICAL;
947 }
948 radioBox->SetWindowStyleFlag(windowStyle);
949
950 wxResourceManager::currentResourceManager->RecreateWindowFromResource(radioBox, this);
951 return TRUE;
952 }
953 else if (name == "values")
954 {
955 // Set property into *resource*, not wxRadioBox, and then recreate
956 // the wxRadioBox. This is because we can't dynamically set the strings
957 // of a wxRadioBox.
958 wxItemResource *resource = wxResourceManager::currentResourceManager->FindResourceForWindow(propertyWindow);
959 if (!resource)
960 return FALSE;
961
962 wxStringList *stringList = resource->GetStringValues();
963 if (!stringList)
964 {
965 stringList = new wxStringList;
966 resource->SetStringValues(stringList);
967 }
968 stringList->Clear();
969
970 wxPropertyValue *expr = property->GetValue().GetFirst();
971 while (expr)
972 {
973 char *s = expr->StringValue();
974 if (s)
975 stringList->Add(s);
976 expr = expr->GetNext();
977 }
978 wxResourceManager::currentResourceManager->RecreateWindowFromResource(radioBox, this);
979 return TRUE;
980 }
981 return wxItemPropertyInfo::SetProperty(name, property);
982 }
983
984 void wxRadioBoxPropertyInfo::GetPropertyNames(wxStringList& names)
985 {
986 names.Add("label");
987 names.Add("values");
988 names.Add("orientation");
989 names.Add("numberRowsOrCols");
990 wxItemPropertyInfo::GetPropertyNames(names);
991 }
992
993 bool wxRadioBoxPropertyInfo::InstantiateResource(wxItemResource *resource)
994 {
995 wxRadioBox *rbox = (wxRadioBox *)propertyWindow;
996 // Take strings from resource instead
997 /*
998 int i;
999 if (rbox->Number() == 0)
1000 resource->SetStringValues(NULL);
1001 else
1002 {
1003 wxStringList *slist = new wxStringList;
1004
1005 for (i = 0; i < rbox->Number(); i++)
1006 slist->Add(rbox->GetString(i));
1007
1008 resource->SetStringValues(slist);
1009 }
1010 */
1011 resource->SetValue1(rbox->GetNumberOfRowsOrCols());
1012 return wxItemPropertyInfo::InstantiateResource(resource);
1013 }
1014
1015 /*
1016 * Groupbox item
1017 */
1018
1019 wxProperty *wxGroupBoxPropertyInfo::GetProperty(wxString& name)
1020 {
1021 wxStaticBox *groupBox = (wxStaticBox *)propertyWindow;
1022 return wxItemPropertyInfo::GetProperty(name);
1023 }
1024
1025 bool wxGroupBoxPropertyInfo::SetProperty(wxString& name, wxProperty *property)
1026 {
1027 return wxItemPropertyInfo::SetProperty(name, property);
1028 }
1029
1030 void wxGroupBoxPropertyInfo::GetPropertyNames(wxStringList& names)
1031 {
1032 names.Add("label");
1033 wxItemPropertyInfo::GetPropertyNames(names);
1034 }
1035
1036 bool wxGroupBoxPropertyInfo::InstantiateResource(wxItemResource *resource)
1037 {
1038 wxStaticBox *gbox = (wxStaticBox *)propertyWindow;
1039 return wxItemPropertyInfo::InstantiateResource(resource);
1040 }
1041
1042 /*
1043 * Checkbox item
1044 */
1045
1046 wxProperty *wxCheckBoxPropertyInfo::GetProperty(wxString& name)
1047 {
1048 wxCheckBox *checkBox = (wxCheckBox *)propertyWindow;
1049 if (name == "value")
1050 return new wxProperty("value", checkBox->GetValue(), "bool");
1051 else
1052 return wxItemPropertyInfo::GetProperty(name);
1053 }
1054
1055 bool wxCheckBoxPropertyInfo::SetProperty(wxString& name, wxProperty *property)
1056 {
1057 wxCheckBox *checkBox = (wxCheckBox *)propertyWindow;
1058 if (name == "value")
1059 {
1060 checkBox->SetValue((bool)property->GetValue().BoolValue());
1061 return TRUE;
1062 }
1063 else
1064 return wxItemPropertyInfo::SetProperty(name, property);
1065 }
1066
1067 void wxCheckBoxPropertyInfo::GetPropertyNames(wxStringList& names)
1068 {
1069 names.Add("label");
1070 names.Add("value");
1071 wxItemPropertyInfo::GetPropertyNames(names);
1072 }
1073
1074 bool wxCheckBoxPropertyInfo::InstantiateResource(wxItemResource *resource)
1075 {
1076 wxCheckBox *cbox = (wxCheckBox *)propertyWindow;
1077 resource->SetValue1(cbox->GetValue());
1078 return wxItemPropertyInfo::InstantiateResource(resource);
1079 }
1080
1081 /*
1082 * Slider item
1083 */
1084
1085 wxProperty *wxSliderPropertyInfo::GetProperty(wxString& name)
1086 {
1087 wxSlider *slider = (wxSlider *)propertyWindow;
1088 if (name == "value")
1089 return new wxProperty("value", (long)slider->GetValue(), "integer");
1090 else if (name == "orientation")
1091 {
1092 char *pos = NULL;
1093 if (propertyWindow->GetWindowStyleFlag() & wxHORIZONTAL)
1094 pos = "wxHORIZONTAL";
1095 else
1096 pos = "wxVERTICAL";
1097
1098 return new wxProperty("orientation", pos, "string",
1099 new wxStringListValidator(new wxStringList("wxHORIZONTAL", "wxVERTICAL",
1100 NULL)));
1101 }
1102 else if (name == "min_value")
1103 return new wxProperty("min_value", (long)slider->GetMin(), "integer");
1104 else if (name == "max_value")
1105 return new wxProperty("max_value", (long)slider->GetMax(), "integer");
1106 else
1107 return wxItemPropertyInfo::GetProperty(name);
1108 }
1109
1110 bool wxSliderPropertyInfo::SetProperty(wxString& name, wxProperty *property)
1111 {
1112 wxSlider *slider = (wxSlider *)propertyWindow;
1113 if (name == "value")
1114 {
1115 slider->SetValue((int)property->GetValue().IntegerValue());
1116 return TRUE;
1117 }
1118 else if (name == "orientation")
1119 {
1120 long windowStyle = slider->GetWindowStyleFlag();
1121 long oldWindowStyle = windowStyle;
1122 wxString val(property->GetValue().StringValue());
1123 if (val == "wxHORIZONTAL")
1124 {
1125 if (windowStyle & wxVERTICAL)
1126 windowStyle -= wxVERTICAL;
1127 windowStyle |= wxHORIZONTAL;
1128 }
1129 else
1130 {
1131 if (windowStyle & wxHORIZONTAL)
1132 windowStyle -= wxHORIZONTAL;
1133 windowStyle |= wxVERTICAL;
1134 }
1135
1136 if (oldWindowStyle == windowStyle)
1137 return TRUE;
1138
1139 slider->SetWindowStyleFlag(windowStyle);
1140
1141 // If the window style has changed, we swap the width and height parameters.
1142 int w, h;
1143 slider->GetSize(&w, &h);
1144
1145 slider = (wxSlider *)wxResourceManager::currentResourceManager->RecreateWindowFromResource(slider, this);
1146 slider->SetSize(-1, -1, h, w);
1147
1148 return TRUE;
1149 }
1150 else if (name == "min_value")
1151 {
1152 slider->SetRange((int)property->GetValue().IntegerValue(), slider->GetMax());
1153 return TRUE;
1154 }
1155 else if (name == "max_value")
1156 {
1157 slider->SetRange(slider->GetMin(), (int)property->GetValue().IntegerValue());
1158 return TRUE;
1159 }
1160 else
1161 return wxItemPropertyInfo::SetProperty(name, property);
1162 }
1163
1164 void wxSliderPropertyInfo::GetPropertyNames(wxStringList& names)
1165 {
1166 names.Add("value");
1167 names.Add("orientation");
1168 names.Add("min_value");
1169 names.Add("max_value");
1170 wxItemPropertyInfo::GetPropertyNames(names);
1171 }
1172
1173 bool wxSliderPropertyInfo::InstantiateResource(wxItemResource *resource)
1174 {
1175 wxSlider *slider = (wxSlider *)propertyWindow;
1176 resource->SetValue1(slider->GetValue());
1177 resource->SetValue2(slider->GetMin());
1178 resource->SetValue3(slider->GetMax());
1179 return wxItemPropertyInfo::InstantiateResource(resource);
1180 }
1181
1182 /*
1183 * Gauge item
1184 */
1185
1186 wxProperty *wxGaugePropertyInfo::GetProperty(wxString& name)
1187 {
1188 wxGauge *gauge = (wxGauge *)propertyWindow;
1189 if (name == "value")
1190 return new wxProperty("value", (long)gauge->GetValue(), "integer");
1191 else if (name == "max_value")
1192 return new wxProperty("max_value", (long)gauge->GetRange(), "integer");
1193 else
1194 return wxItemPropertyInfo::GetProperty(name);
1195 }
1196
1197 bool wxGaugePropertyInfo::SetProperty(wxString& name, wxProperty *property)
1198 {
1199 wxGauge *gauge = (wxGauge *)propertyWindow;
1200 if (name == "value")
1201 {
1202 gauge->SetValue((int)property->GetValue().IntegerValue());
1203 return TRUE;
1204 }
1205 else if (name == "max_value")
1206 {
1207 gauge->SetRange((int)property->GetValue().IntegerValue());
1208 return TRUE;
1209 }
1210 else
1211 return wxItemPropertyInfo::SetProperty(name, property);
1212 }
1213
1214 void wxGaugePropertyInfo::GetPropertyNames(wxStringList& names)
1215 {
1216 names.Add("value");
1217 names.Add("max_value");
1218 wxItemPropertyInfo::GetPropertyNames(names);
1219 }
1220
1221 bool wxGaugePropertyInfo::InstantiateResource(wxItemResource *resource)
1222 {
1223 wxGauge *gauge = (wxGauge *)propertyWindow;
1224 resource->SetValue1(gauge->GetValue());
1225 resource->SetValue2(gauge->GetRange());
1226 return wxItemPropertyInfo::InstantiateResource(resource);
1227 }
1228
1229 /*
1230 * Scrollbar item
1231 */
1232
1233 wxProperty *wxScrollBarPropertyInfo::GetProperty(wxString& name)
1234 {
1235 wxScrollBar *scrollBar = (wxScrollBar *)propertyWindow;
1236 if (name == "value")
1237 return new wxProperty("value", (long)scrollBar->GetValue(), "integer");
1238 else if (name == "orientation")
1239 {
1240 char *pos = NULL;
1241 if (propertyWindow->GetWindowStyleFlag() & wxHORIZONTAL)
1242 pos = "wxHORIZONTAL";
1243 else
1244 pos = "wxVERTICAL";
1245
1246 return new wxProperty("orientation", pos, "string",
1247 new wxStringListValidator(new wxStringList("wxHORIZONTAL", "wxVERTICAL",
1248 NULL)));
1249 }
1250 else if (name == "pageSize")
1251 {
1252 int viewStart, pageLength, objectLength, viewLength;
1253 scrollBar->GetValues(&viewStart, &viewLength, &objectLength, &pageLength);
1254
1255 return new wxProperty("pageSize", (long)pageLength, "integer");
1256 }
1257 else if (name == "viewLength")
1258 {
1259 int viewStart, pageLength, objectLength, viewLength;
1260 scrollBar->GetValues(&viewStart, &viewLength, &objectLength, &pageLength);
1261
1262 return new wxProperty("viewLength", (long)viewLength, "integer");
1263 }
1264 else if (name == "objectLength")
1265 {
1266 int viewStart, pageLength, objectLength, viewLength;
1267 scrollBar->GetValues(&viewStart, &viewLength, &objectLength, &pageLength);
1268
1269 return new wxProperty("objectLength", (long)objectLength, "integer");
1270 }
1271 else
1272 return wxItemPropertyInfo::GetProperty(name);
1273 }
1274
1275 bool wxScrollBarPropertyInfo::SetProperty(wxString& name, wxProperty *property)
1276 {
1277 wxScrollBar *scrollBar = (wxScrollBar *)propertyWindow;
1278 if (name == "value")
1279 {
1280 scrollBar->SetValue((int)property->GetValue().IntegerValue());
1281 return TRUE;
1282 }
1283 else if (name == "orientation")
1284 {
1285 long windowStyle = scrollBar->GetWindowStyleFlag();
1286 long oldWindowStyle = windowStyle;
1287 wxString val(property->GetValue().StringValue());
1288 if (val == "wxHORIZONTAL")
1289 {
1290 if (windowStyle & wxVERTICAL)
1291 windowStyle -= wxVERTICAL;
1292 windowStyle |= wxHORIZONTAL;
1293 }
1294 else
1295 {
1296 if (windowStyle & wxHORIZONTAL)
1297 windowStyle -= wxHORIZONTAL;
1298 windowStyle |= wxVERTICAL;
1299 }
1300
1301 if (oldWindowStyle == windowStyle)
1302 return TRUE;
1303
1304 scrollBar->SetWindowStyleFlag(windowStyle);
1305
1306 // If the window style has changed, we swap the width and height parameters.
1307 int w, h;
1308 scrollBar->GetSize(&w, &h);
1309
1310 scrollBar = (wxScrollBar *)wxResourceManager::currentResourceManager->RecreateWindowFromResource(scrollBar, this);
1311 scrollBar->SetSize(-1, -1, h, w);
1312
1313 return TRUE;
1314 }
1315 else if (name == "pageSize")
1316 {
1317 scrollBar->SetPageSize((int)property->GetValue().IntegerValue());
1318 return TRUE;
1319 }
1320 else if (name == "viewLength")
1321 {
1322 scrollBar->SetViewLength((int)property->GetValue().IntegerValue());
1323 return TRUE;
1324 }
1325 else if (name == "objectLength")
1326 {
1327 scrollBar->SetObjectLength((int)property->GetValue().IntegerValue());
1328 return TRUE;
1329 }
1330 else
1331 return wxItemPropertyInfo::SetProperty(name, property);
1332 }
1333
1334 void wxScrollBarPropertyInfo::GetPropertyNames(wxStringList& names)
1335 {
1336 names.Add("orientation");
1337 names.Add("value");
1338 names.Add("pageSize");
1339 names.Add("viewLength");
1340 names.Add("objectLength");
1341 wxItemPropertyInfo::GetPropertyNames(names);
1342
1343 // Remove some properties we don't inherit
1344 names.Delete("fontPoints");
1345 names.Delete("fontFamily");
1346 names.Delete("fontStyle");
1347 names.Delete("fontWeight");
1348 names.Delete("fontUnderlined");
1349 }
1350
1351 bool wxScrollBarPropertyInfo::InstantiateResource(wxItemResource *resource)
1352 {
1353 wxScrollBar *sbar = (wxScrollBar *)propertyWindow;
1354
1355 resource->SetValue1(sbar->GetValue());
1356
1357 int viewStart, pageLength, objectLength, viewLength;
1358 sbar->GetValues(&viewStart, &viewLength, &objectLength, &pageLength);
1359
1360 resource->SetValue2(pageLength);
1361 resource->SetValue3(objectLength);
1362 resource->SetValue5(viewLength);
1363
1364 return wxItemPropertyInfo::InstantiateResource(resource);
1365 }
1366
1367 /*
1368 * Panels
1369 */
1370
1371 wxProperty *wxPanelPropertyInfo::GetProperty(wxString& name)
1372 {
1373 wxPanel *panelWindow = (wxPanel *)propertyWindow;
1374 wxFont *labelFont = panelWindow->GetLabelFont();
1375 wxFont *buttonFont = panelWindow->GetButtonFont();
1376
1377 if (name == "labelFontPoints" || name == "labelFontFamily" || name == "labelFontStyle" || name == "labelFontWeight" ||
1378 name == "labelFontUnderlined")
1379 return GetFontProperty(name, labelFont);
1380 else if (name == "buttonFontPoints" || name == "buttonFontFamily" || name == "buttonFontStyle" || name == "buttonFontWeight" ||
1381 name == "buttonFontUnderlined")
1382 return GetFontProperty(name, buttonFont);
1383 else if (name == "userColours")
1384 {
1385 bool userColours;
1386 if (panelWindow->GetWindowStyleFlag() & wxUSER_COLOURS)
1387 userColours = TRUE;
1388 else
1389 userColours = FALSE;
1390
1391 return new wxProperty(name, (bool)userColours, "bool");
1392 }
1393 else if (name == "backgroundColour")
1394 {
1395 wxColour col(panelWindow->GetBackgroundColour());
1396 char buf[7];
1397 wxDecToHex(col.Red(), buf);
1398 wxDecToHex(col.Green(), buf+2);
1399 wxDecToHex(col.Blue(), buf+4);
1400
1401 return new wxProperty(name, buf, "string", new wxColourListValidator);
1402 }
1403 else
1404 return wxWindowPropertyInfo::GetProperty(name);
1405 }
1406
1407 bool wxPanelPropertyInfo::SetProperty(wxString& name, wxProperty *property)
1408 {
1409 wxPanel *panelWindow = (wxPanel *)propertyWindow;
1410 wxFont *labelFont = panelWindow->GetLabelFont();
1411 wxFont *buttonFont = panelWindow->GetButtonFont();
1412
1413 if (labelFont && (name == "labelFontPoints" || name == "labelFontFamily" || name == "labelFontStyle" || name == "labelFontWeight" || name == "labelFontUnderlined" ))
1414 {
1415 wxFont *newFont = SetFontProperty(name, property, labelFont);
1416 if (newFont)
1417 panelWindow->SetLabelFont(newFont);
1418 return TRUE;
1419 }
1420 else if (buttonFont && (name == "buttonFontPoints" || name == "buttonFontFamily" || name == "buttonFontStyle" || name == "buttonFontWeight" || name == "buttonFontUnderlined" ))
1421 {
1422 wxFont *newFont = SetFontProperty(name, property, buttonFont);
1423 if (newFont)
1424 panelWindow->SetButtonFont(newFont);
1425 return TRUE;
1426 }
1427 else if (name == "userColours")
1428 {
1429 bool userColours = property->GetValue().BoolValue();
1430 long flag = panelWindow->GetWindowStyleFlag();
1431
1432 if (userColours)
1433 {
1434 if ((panelWindow->GetWindowStyleFlag() & wxUSER_COLOURS) != wxUSER_COLOURS)
1435 panelWindow->SetWindowStyleFlag(panelWindow->GetWindowStyleFlag() | wxUSER_COLOURS);
1436 }
1437 else
1438 {
1439 if ((panelWindow->GetWindowStyleFlag() & wxUSER_COLOURS) == wxUSER_COLOURS)
1440 panelWindow->SetWindowStyleFlag(panelWindow->GetWindowStyleFlag() - wxUSER_COLOURS);
1441 }
1442 wxItemResource *resource = wxResourceManager::currentResourceManager->FindResourceForWindow(panelWindow);
1443 resource->SetStyle(panelWindow->GetWindowStyleFlag());
1444
1445 panelWindow = (wxPanel *)wxResourceManager::currentResourceManager->RecreateWindowFromResource(panelWindow, this);
1446 // panelWindow->SetUserEditMode(wxResourceManager::currentResourceManager->GetEditMode());
1447 #ifdef __WINDOWS__
1448 // This window should not be enabled by being recreated: we're in a modal dialog (property editor)
1449 ::EnableWindow((HWND) panelWindow->GetHWND(), FALSE);
1450 ::BringWindowToTop((HWND) sm_propertyWindow->GetHWND());
1451 #endif
1452 return TRUE;
1453 }
1454 else if (name == "backgroundColour")
1455 {
1456 char *hex = property->GetValue().StringValue();
1457 int r = wxHexToDec(hex);
1458 int g = wxHexToDec(hex+2);
1459 int b = wxHexToDec(hex+4);
1460
1461 wxColour col(r,g,b);
1462 panelWindow->SetBackgroundColour(col);
1463 panelWindow = (wxPanel *)wxResourceManager::currentResourceManager->RecreateWindowFromResource(panelWindow, this);
1464 // panelWindow->SetUserEditMode(wxResourceManager::currentResourceManager->GetEditMode());
1465 #ifdef __WINDOWS__
1466 // This window should not be enabled by being recreated: we're in a modal dialog (property editor)
1467 ::EnableWindow((HWND) panelWindow->GetHWND(), FALSE);
1468 ::BringWindowToTop((HWND) sm_propertyWindow->GetHWND());
1469 #endif
1470 return TRUE;
1471 }
1472 else
1473 return wxWindowPropertyInfo::SetProperty(name, property);
1474 }
1475
1476 void wxPanelPropertyInfo::GetPropertyNames(wxStringList& names)
1477 {
1478 wxWindowPropertyInfo::GetPropertyNames(names);
1479
1480 // names.Add("orientation");
1481 names.Add("userColours");
1482 names.Add("backgroundColour");
1483 }
1484
1485 bool wxPanelPropertyInfo::InstantiateResource(wxItemResource *resource)
1486 {
1487 wxPanel *panel = (wxPanel *)propertyWindow;
1488 if (panel->GetFont())
1489 resource->SetFont(wxTheFontList->FindOrCreateFont(panel->GetFont()->GetPointSize(),
1490 panel->GetFont()->GetFamily(), panel->GetFont()->GetStyle(), panel->GetFont()->GetWeight(),
1491 panel->GetFont()->GetUnderlined(), panel->GetFont()->GetFaceName()));
1492
1493 resource->SetBackgroundColour(new wxColour(panel->GetBackgroundColour()));
1494
1495 return wxWindowPropertyInfo::InstantiateResource(resource);
1496 }
1497
1498 /*
1499 * Dialog boxes
1500 */
1501
1502 wxProperty *wxDialogPropertyInfo::GetProperty(wxString& name)
1503 {
1504 wxDialog *dialogWindow = (wxDialog *)propertyWindow;
1505 if (name == "modal")
1506 {
1507 wxItemResource *resource = wxResourceManager::currentResourceManager->FindResourceForWindow(dialogWindow);
1508 if (!resource)
1509 return NULL;
1510
1511 bool modal = (resource->GetValue1() != 0);
1512 return new wxProperty(name, modal, "bool");
1513 }
1514 else
1515 return wxPanelPropertyInfo::GetProperty(name);
1516 }
1517
1518 bool wxDialogPropertyInfo::SetProperty(wxString& name, wxProperty *property)
1519 {
1520 wxDialog *dialogWindow = (wxDialog *)propertyWindow;
1521
1522 if (name == "modal")
1523 {
1524 wxItemResource *resource = wxResourceManager::currentResourceManager->FindResourceForWindow(dialogWindow);
1525 if (!resource)
1526 return FALSE;
1527
1528 resource->SetValue1(property->GetValue().BoolValue());
1529 return TRUE;
1530 }
1531 else
1532 return wxPanelPropertyInfo::SetProperty(name, property);
1533 }
1534
1535 void wxDialogPropertyInfo::GetPropertyNames(wxStringList& names)
1536 {
1537 names.Add("title");
1538 names.Add("modal");
1539
1540 wxPanelPropertyInfo::GetPropertyNames(names);
1541 }
1542
1543 bool wxDialogPropertyInfo::InstantiateResource(wxItemResource *resource)
1544 {
1545 wxDialog *dialog = (wxDialog *)propertyWindow;
1546 wxString str(dialog->GetTitle());
1547 resource->SetTitle(WXSTRINGCAST str);
1548
1549 return wxPanelPropertyInfo::InstantiateResource(resource);
1550 }
1551
1552 /*
1553 * Utilities
1554 */
1555
1556 int wxStringToFontWeight(wxString& val)
1557 {
1558 if (val == "wxBOLD") return wxBOLD;
1559 else if (val == "wxLIGHT") return wxLIGHT;
1560 else return wxNORMAL;
1561 }
1562
1563 int wxStringToFontStyle(wxString& val)
1564 {
1565 if (val == "wxITALIC") return wxITALIC;
1566 else if (val == "wxSLANT") return wxSLANT;
1567 else return wxNORMAL;
1568 }
1569
1570 int wxStringToFontFamily(wxString& val)
1571 {
1572 if (val == "wxDECORATIVE") return wxDECORATIVE;
1573 else if (val == "wxROMAN") return wxROMAN;
1574 else if (val == "wxSCRIPT") return wxSCRIPT;
1575 else if (val == "wxMODERN") return wxMODERN;
1576 else if (val == "wxTELETYPE") return wxTELETYPE;
1577 else return wxSWISS;
1578 }