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