1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Window properties
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "winprop.h"
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
32 #if defined(__WINDOWS__) && !defined(__GNUWIN32__)
35 #include <strstream.h>
46 // Causes immediate feedback.
47 void wxResourcePropertyListView::OnPropertyChanged(wxProperty
*property
)
49 // Sets the value of the property back into the actual object,
50 // IF the property value was modified.
51 if (property
->GetValue().GetModified())
53 propertyInfo
->SetProperty(property
->GetName(), property
);
54 property
->GetValue().SetModified(FALSE
);
58 bool wxResourcePropertyListView::OnClose(void)
61 GetManagedWindow()->GetSize(& w
, & h
);
62 GetManagedWindow()->GetPosition(& x
, & y
);
64 wxResourceManager::currentResourceManager
->propertyWindowSize
.width
= w
;
65 wxResourceManager::currentResourceManager
->propertyWindowSize
.height
= h
;
66 wxResourceManager::currentResourceManager
->propertyWindowSize
.x
= x
;
67 wxResourceManager::currentResourceManager
->propertyWindowSize
.y
= y
;
69 return wxPropertyListView::OnClose();
76 wxWindow
*wxPropertyInfo::sm_propertyWindow
;
78 // Edit the information represented by this object, whatever that
80 bool wxPropertyInfo::Edit(wxWindow
*parent
, char *title
)
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
;
87 wxPropertySheet
*propSheet
= new wxPropertySheet
;
89 wxStringList propNames
;
90 GetPropertyNames(propNames
);
92 wxNode
*node
= propNames
.First();
95 wxString
name((char *)node
->Data());
96 wxProperty
*prop
= GetProperty(name
);
99 propSheet
->AddProperty(prop
);
104 // Reset 'modified' flags for all property values
105 propSheet
->SetAllModified(FALSE
);
108 title
= "Properties";
109 wxResourcePropertyListView
*view
= new wxResourcePropertyListView(this, NULL
,
111 wxPROP_BUTTON_OK
| wxPROP_BUTTON_CANCEL
|
113 wxPROP_BUTTON_CHECK_CROSS
|wxPROP_DYNAMIC_VALUE_FIELD
|wxPROP_PULLDOWN
|wxPROP_SHOWVALUES
);
115 wxPropertyListDialog
*propDialog
= new wxPropertyListDialog(view
, NULL
, title
, wxPoint(x
, y
), wxSize(width
, height
), wxDIALOG_MODAL
|wxDEFAULT_DIALOG_STYLE
);
116 sm_propertyWindow
= propDialog
;
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
);
126 // view->propertyWindow = propDialog;
127 view
->AddRegistry(&theValidatorRegistry
);
128 view
->ShowView(propSheet
, propDialog
);
130 int ret
= propDialog
->ShowModal();
131 sm_propertyWindow
= NULL
;
134 if ( ret
== wxID_CANCEL
)
141 * wxWindowPropertyInfo
144 wxWindowPropertyInfo::wxWindowPropertyInfo(wxWindow
*win
, wxItemResource
*res
)
146 propertyWindow
= win
;
147 propertyResource
= res
;
150 wxWindowPropertyInfo::~wxWindowPropertyInfo(void)
154 wxProperty
*wxWindowPropertyInfo::GetFontProperty(wxString
& name
, wxFont
*font
)
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",
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");
177 wxFont
*wxWindowPropertyInfo::SetFontProperty(wxString
& name
, wxProperty
*property
, wxFont
*font
)
180 int fontFamily
= wxMODERN
;
181 int fontStyle
= wxNORMAL
;
182 int fontWeight
= wxNORMAL
;
183 bool fontUnderlined
= FALSE
;
185 if (name
.Contains("Points"))
187 pointSize
= (int)property
->GetValue().IntegerValue();
188 if (font
&& (pointSize
== font
->GetPointSize()))
189 return NULL
; // No change
191 else if (font
) pointSize
= font
->GetPointSize();
193 if (name
.Contains("Family"))
195 wxString val
= property
->GetValue().StringValue();
196 fontFamily
= wxStringToFontFamily(val
);
198 if (font
&& (fontFamily
== font
->GetFamily()))
199 return NULL
; // No change
201 else if (font
) fontFamily
= font
->GetFamily();
203 if (name
.Contains("Style"))
205 wxString val
= property
->GetValue().StringValue();
206 fontStyle
= wxStringToFontStyle(val
);
208 if (font
&& (fontStyle
== font
->GetStyle()))
209 return NULL
; // No change
211 else if (font
) fontStyle
= font
->GetStyle();
212 if (name
.Contains("Weight"))
214 wxString val
= property
->GetValue().StringValue();
215 fontWeight
= wxStringToFontWeight(val
);
217 if (font
&& (fontWeight
== font
->GetWeight()))
218 return NULL
; // No change
220 else if (font
) fontWeight
= font
->GetWeight();
222 if (name
.Contains("Underlined"))
224 fontUnderlined
= property
->GetValue().BoolValue();
226 if (font
&& (fontUnderlined
== font
->GetUnderlined()))
227 return NULL
; // No change
229 else if (font
) fontUnderlined
= font
->GetUnderlined();
231 wxFont
*newFont
= wxTheFontList
->FindOrCreateFont(pointSize
, fontFamily
, fontStyle
, fontWeight
, fontUnderlined
);
240 wxProperty
*wxWindowPropertyInfo::GetProperty(wxString
& name
)
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")
253 propertyWindow
->GetPosition(&x
, &y
);
254 return new wxProperty("x", (long)x
, "integer");
256 else if (name
== "y")
259 propertyWindow
->GetPosition(&x
, &y
);
260 return new wxProperty("y", (long)y
, "integer");
262 else if (name
== "width")
265 propertyWindow
->GetSize(&width
, &height
);
266 return new wxProperty("width", (long)width
, "integer");
268 else if (name
== "height")
271 propertyWindow
->GetSize(&width
, &height
);
272 return new wxProperty("height", (long)height
, "integer");
278 bool wxWindowPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
280 wxFont
*font
= propertyWindow
->GetFont();
281 if (font
&& (name
== "fontPoints" || name
== "fontFamily" || name
== "fontStyle" || name
== "fontWeight" || name
== "fontUnderlined" ))
283 wxFont
*newFont
= SetFontProperty(name
, property
, font
);
285 propertyWindow
->SetFont(newFont
);
288 else if (name
== "name")
290 // Remove old name from resource table, if it's there.
291 wxItemResource
*oldResource
= (wxItemResource
*)wxResourceManager::currentResourceManager
->GetResourceTable().Delete(propertyWindow
->GetName());
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
);
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());
305 // Refresh the resource manager list, because the name changed.
306 wxResourceManager::currentResourceManager
->UpdateResourceList();
309 else if (name
== "title")
311 propertyWindow
->SetTitle(property
->GetValue().StringValue());
314 else if (name
== "x")
317 propertyWindow
->GetPosition(&x
, &y
);
318 int newX
= (int)property
->GetValue().IntegerValue();
320 propertyWindow
->Move(newX
, y
);
323 else if (name
== "y")
326 propertyWindow
->GetPosition(&x
, &y
);
327 int newY
= (int)property
->GetValue().IntegerValue();
329 propertyWindow
->Move(x
, newY
);
332 else if (name
== "width")
335 propertyWindow
->GetSize(&width
, &height
);
336 int newWidth
= (int)property
->GetValue().IntegerValue();
337 if (width
!= newWidth
)
339 propertyWindow
->SetSize(newWidth
, height
);
340 if (propertyWindow
->IsKindOf(CLASSINFO(wxPanel
)) && !propertyWindow
->IsKindOf(CLASSINFO(wxDialog
)))
342 propertyWindow
->GetParent()->SetClientSize(newWidth
, height
);
347 else if (name
== "height")
350 propertyWindow
->GetSize(&width
, &height
);
351 int newHeight
= (int)property
->GetValue().IntegerValue();
352 if (height
!= newHeight
)
354 propertyWindow
->SetSize(width
, newHeight
);
355 if (propertyWindow
->IsKindOf(CLASSINFO(wxPanel
)) && !propertyWindow
->IsKindOf(CLASSINFO(wxDialog
)))
357 propertyWindow
->GetParent()->SetClientSize(width
, newHeight
);
366 void wxWindowPropertyInfo::GetPropertyNames(wxStringList
& names
)
373 if (!propertyWindow
->IsKindOf(CLASSINFO(wxControl
)))
375 names
.Add("fontPoints");
376 names
.Add("fontFamily");
377 names
.Add("fontStyle");
378 names
.Add("fontWeight");
379 names
.Add("fontUnderlined");
383 // Fill in the wxItemResource members to mirror the current window settings
384 bool wxWindowPropertyInfo::InstantiateResource(wxItemResource
*resource
)
386 resource
->SetType(propertyWindow
->GetClassInfo()->GetClassName());
388 // resource->SetStyle(propertyWindow->GetWindowStyleFlag());
389 wxString
str(propertyWindow
->GetName());
390 resource
->SetName(WXSTRINGCAST str
);
392 propertyWindow
->GetSize(&w
, &h
);
394 propertyWindow
->GetPosition(&x
, &y
);
395 resource
->SetSize(x
, y
, w
, h
);
404 wxProperty
*wxItemPropertyInfo::GetProperty(wxString
& name
)
406 wxControl
*itemWindow
= (wxControl
*)propertyWindow
;
407 wxFont
*font
= itemWindow
->GetFont();
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");
415 return wxWindowPropertyInfo::GetProperty(name
);
418 bool wxItemPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
420 wxControl
*itemWindow
= (wxControl
*)propertyWindow
;
421 wxFont
*font
= itemWindow
->GetFont();
423 if (font
&& (name
== "fontPoints" || name
== "fontFamily" || name
== "fontStyle" || name
== "fontWeight" || name
== "fontUnderlined" ))
425 wxFont
*newFont
= SetFontProperty(name
, property
, font
);
427 itemWindow
->SetLabelFont(newFont
);
430 else if (name
== "label")
432 itemWindow
->SetLabel(property
->GetValue().StringValue());
436 return wxWindowPropertyInfo::SetProperty(name
, property
);
439 void wxItemPropertyInfo::GetPropertyNames(wxStringList
& names
)
441 wxWindowPropertyInfo::GetPropertyNames(names
);
443 names
.Add("fontPoints");
444 names
.Add("fontFamily");
445 names
.Add("fontStyle");
446 names
.Add("fontWeight");
447 names
.Add("fontUnderlined");
450 bool wxItemPropertyInfo::InstantiateResource(wxItemResource
*resource
)
452 wxWindowPropertyInfo::InstantiateResource(resource
);
454 wxControl
*item
= (wxControl
*)propertyWindow
;
455 wxString
str(item
->GetLabel());
456 resource
->SetTitle(WXSTRINGCAST str
);
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()));
468 wxProperty
*wxButtonPropertyInfo::GetProperty(wxString
& name
)
470 wxButton
*button
= (wxButton
*)propertyWindow
;
472 if (name == "label" && isBitmapButton)
474 wxItemResource *resource = wxResourceManager::currentResourceManager->FindResourceForWindow(button);
475 wxString str("none.bmp");
479 char *filename = wxResourceManager::currentResourceManager->FindBitmapFilenameForResource(resource);
483 return new wxProperty("label", str.GetData(), "string", new wxFilenameListValidator("Select a bitmap file", "*.bmp"));
487 return wxItemPropertyInfo::GetProperty(name
);
490 bool wxButtonPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
492 wxButton
*button
= (wxButton
*)propertyWindow
;
494 if (name == "label" && isBitmapButton)
496 char *s = property->GetValue().StringValue();
497 if (s && wxFileExists(s))
500 wxBitmap *bitmap = new wxBitmap(s, wxBITMAP_TYPE_BMP);
509 wxItemResource *resource = wxResourceManager::currentResourceManager->FindResourceForWindow(button);
512 wxString oldResource(resource->GetValue4());
513 char *resName = wxResourceManager::currentResourceManager->AddBitmapResource(s);
514 resource->SetValue4(resName);
516 if (!oldResource.IsNull())
517 wxResourceManager::currentResourceManager->PossiblyDeleteBitmapResource(WXSTRINGCAST oldResource);
520 button->SetLabel(bitmap);
529 return wxItemPropertyInfo::SetProperty(name
, property
);
532 void wxButtonPropertyInfo::GetPropertyNames(wxStringList
& names
)
535 wxItemPropertyInfo::GetPropertyNames(names
);
538 bool wxButtonPropertyInfo::InstantiateResource(wxItemResource
*resource
)
540 return wxItemPropertyInfo::InstantiateResource(resource
);
547 wxProperty
*wxStaticTextPropertyInfo::GetProperty(wxString
& name
)
549 wxStaticText
*message
= (wxStaticText
*)propertyWindow
;
551 if (name == "label" && isBitmapMessage)
553 wxItemResource *resource = wxResourceManager::currentResourceManager->FindResourceForWindow(message);
554 wxString str("none.bmp");
558 char *filename = wxResourceManager::currentResourceManager->FindBitmapFilenameForResource(resource);
562 return new wxProperty("label", str.GetData(), "string", new wxFilenameListValidator("Select a bitmap file", "*.bmp"));
566 return wxItemPropertyInfo::GetProperty(name
);
569 bool wxStaticTextPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
571 wxStaticText
*message
= (wxStaticText
*)propertyWindow
;
573 if (name == "label" && isBitmapMessage)
575 char *s = property->GetValue().StringValue();
576 if (s && wxFileExists(s))
580 wxBitmap *bitmap = new wxBitmap(s, wxBITMAP_TYPE_BMP);
589 wxItemResource *resource = wxResourceManager::currentResourceManager->FindResourceForWindow(message);
592 wxString oldResource(resource->GetValue4());
593 char *resName = wxResourceManager::currentResourceManager->AddBitmapResource(s);
594 resource->SetValue4(resName);
596 if (!oldResource.IsNull())
597 wxResourceManager::currentResourceManager->PossiblyDeleteBitmapResource(WXSTRINGCAST oldResource);
600 message->SetLabel(bitmap);
609 return wxItemPropertyInfo::SetProperty(name
, property
);
612 void wxStaticTextPropertyInfo::GetPropertyNames(wxStringList
& names
)
615 wxItemPropertyInfo::GetPropertyNames(names
);
618 bool wxStaticTextPropertyInfo::InstantiateResource(wxItemResource
*resource
)
620 return wxItemPropertyInfo::InstantiateResource(resource
);
627 wxProperty
*wxTextPropertyInfo::GetProperty(wxString
& name
)
629 wxTextCtrl
*text
= (wxTextCtrl
*)propertyWindow
;
631 return new wxProperty("value", text
->GetValue(), "string");
632 else if (name
== "password")
634 bool isPassword
= ((text
->GetWindowStyleFlag() & wxTE_PASSWORD
) == wxTE_PASSWORD
);
635 return new wxProperty("password", isPassword
, "bool");
637 else if (name
== "readonly")
639 bool isReadOnly
= ((text
->GetWindowStyleFlag() & wxTE_READONLY
) == wxTE_READONLY
);
640 return new wxProperty("readonly", isReadOnly
, "bool");
643 return wxItemPropertyInfo::GetProperty(name
);
646 bool wxTextPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
648 wxTextCtrl
*text
= (wxTextCtrl
*)propertyWindow
;
651 text
->SetValue(property
->GetValue().StringValue());
654 else if (name
== "password")
656 long flag
= text
->GetWindowStyleFlag();
657 if (property
->GetValue().BoolValue())
659 if ((flag
& wxTE_PASSWORD
) != wxTE_PASSWORD
)
660 flag
|= wxTE_PASSWORD
;
664 if ((flag
& wxTE_PASSWORD
) == wxTE_PASSWORD
)
665 flag
-= wxTE_PASSWORD
;
667 wxItemResource
*resource
= wxResourceManager::currentResourceManager
->FindResourceForWindow(text
);
668 resource
->SetStyle(flag
);
670 wxResourceManager::currentResourceManager
->RecreateWindowFromResource(text
, this);
673 else if (name
== "readonly")
675 long flag
= text
->GetWindowStyleFlag();
676 if (property
->GetValue().BoolValue())
678 if ((flag
& wxTE_READONLY
) != wxTE_READONLY
)
679 flag
|= wxTE_READONLY
;
683 if ((flag
& wxTE_READONLY
) == wxTE_READONLY
)
684 flag
-= wxTE_READONLY
;
686 wxItemResource
*resource
= wxResourceManager::currentResourceManager
->FindResourceForWindow(text
);
687 resource
->SetStyle(flag
);
689 wxResourceManager::currentResourceManager
->RecreateWindowFromResource(text
, this);
693 return wxItemPropertyInfo::SetProperty(name
, property
);
696 void wxTextPropertyInfo::GetPropertyNames(wxStringList
& names
)
699 names
.Add("readonly");
700 names
.Add("password");
701 wxItemPropertyInfo::GetPropertyNames(names
);
704 bool wxTextPropertyInfo::InstantiateResource(wxItemResource
*resource
)
706 wxTextCtrl
*text
= (wxTextCtrl
*)propertyWindow
;
707 wxString
str(text
->GetValue());
708 resource
->SetValue4(WXSTRINGCAST str
);
710 return wxItemPropertyInfo::InstantiateResource(resource
);
717 wxProperty
*wxListBoxPropertyInfo::GetProperty(wxString
& name
)
719 wxListBox
*listBox
= (wxListBox
*)propertyWindow
;
720 if (name
== "values")
722 wxStringList
*stringList
= new wxStringList
;
724 for (i
= 0; i
< listBox
->Number(); i
++)
725 stringList
->Add(listBox
->GetString(i
));
727 return new wxProperty(name
, stringList
, "stringlist");
729 else if (name
== "multiple")
732 wxItemResource
*resource
= wxResourceManager::currentResourceManager
->FindResourceForWindow(listBox
);
736 char *mult
= "wxSINGLE";
738 switch (resource
->GetValue1())
741 mult
= "wxLB_MULTIPLE";
744 mult
= "wxLB_EXTENDED";
748 mult
= "wxLB_SINGLE";
751 return new wxProperty("multiple", mult
, "string",
752 new wxStringListValidator(new wxStringList("wxLB_SINGLE", "wxLB_MULTIPLE", "wxLB_EXTENDED",
756 return wxItemPropertyInfo::GetProperty(name
);
759 bool wxListBoxPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
761 wxListBox
*listBox
= (wxListBox
*)propertyWindow
;
762 if (name
== "values")
765 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
768 char *s
= expr
->StringValue();
771 expr
= expr
->GetNext();
775 else if (name
== "multiple")
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
;
785 wxItemResource
*resource
= wxResourceManager::currentResourceManager
->FindResourceForWindow(listBox
);
787 resource
->SetValue1(mult
);
788 wxResourceManager::currentResourceManager
->RecreateWindowFromResource(listBox
, this);
792 return wxItemPropertyInfo::SetProperty(name
, property
);
795 void wxListBoxPropertyInfo::GetPropertyNames(wxStringList
& names
)
798 names
.Add("multiple");
799 wxItemPropertyInfo::GetPropertyNames(names
);
802 bool wxListBoxPropertyInfo::InstantiateResource(wxItemResource
*resource
)
804 wxListBox
*lbox
= (wxListBox
*)propertyWindow
;
805 // This will be set for the wxItemResource on reading or in SetProperty
806 // resource->SetValue1(lbox->GetSelectionMode());
808 if (lbox
->Number() == 0)
809 resource
->SetStringValues(NULL
);
812 wxStringList
*slist
= new wxStringList
;
814 for (i
= 0; i
< lbox
->Number(); i
++)
815 slist
->Add(lbox
->GetString(i
));
817 resource
->SetStringValues(slist
);
819 return wxItemPropertyInfo::InstantiateResource(resource
);
826 wxProperty
*wxChoicePropertyInfo::GetProperty(wxString
& name
)
828 wxChoice
*choice
= (wxChoice
*)propertyWindow
;
829 if (name
== "values")
831 wxStringList
*stringList
= new wxStringList
;
833 for (i
= 0; i
< choice
->Number(); i
++)
834 stringList
->Add(choice
->GetString(i
));
836 return new wxProperty(name
, stringList
, "stringlist");
839 return wxItemPropertyInfo::GetProperty(name
);
842 bool wxChoicePropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
844 wxChoice
*choice
= (wxChoice
*)propertyWindow
;
845 if (name
== "values")
848 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
851 char *s
= expr
->StringValue();
854 expr
= expr
->GetNext();
856 if (choice
->Number() > 0)
857 choice
->SetSelection(0);
861 return wxItemPropertyInfo::SetProperty(name
, property
);
864 void wxChoicePropertyInfo::GetPropertyNames(wxStringList
& names
)
867 wxItemPropertyInfo::GetPropertyNames(names
);
870 bool wxChoicePropertyInfo::InstantiateResource(wxItemResource
*resource
)
872 wxChoice
*choice
= (wxChoice
*)propertyWindow
;
874 if (choice
->Number() == 0)
875 resource
->SetStringValues(NULL
);
878 wxStringList
*slist
= new wxStringList
;
880 for (i
= 0; i
< choice
->Number(); i
++)
881 slist
->Add(choice
->GetString(i
));
883 resource
->SetStringValues(slist
);
885 return wxItemPropertyInfo::InstantiateResource(resource
);
892 wxProperty
*wxRadioBoxPropertyInfo::GetProperty(wxString
& name
)
894 wxRadioBox
*radioBox
= (wxRadioBox
*)propertyWindow
;
895 if (name
== "numberRowsOrCols")
897 return new wxProperty("numberRowsOrCols", (long)radioBox
->GetNumberOfRowsOrCols(), "integer");
899 if (name
== "orientation")
902 if (propertyWindow
->GetWindowStyleFlag() & wxHORIZONTAL
)
903 pos
= "wxHORIZONTAL";
907 return new wxProperty("orientation", pos
, "string",
908 new wxStringListValidator(new wxStringList("wxHORIZONTAL", "wxVERTICAL",
911 else if (name
== "values")
913 wxStringList
*stringList
= new wxStringList
;
915 for (i
= 0; i
< radioBox
->Number(); i
++)
916 stringList
->Add(radioBox
->GetString(i
));
918 return new wxProperty(name
, stringList
, "stringlist");
920 return wxItemPropertyInfo::GetProperty(name
);
923 bool wxRadioBoxPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
925 wxRadioBox
*radioBox
= (wxRadioBox
*)propertyWindow
;
926 if (name
== "numberRowsOrCols")
928 radioBox
->SetNumberOfRowsOrCols((int)property
->GetValue().IntegerValue());
929 wxResourceManager::currentResourceManager
->RecreateWindowFromResource(radioBox
, this);
932 else if (name
== "orientation")
934 long windowStyle
= radioBox
->GetWindowStyleFlag();
935 wxString
val(property
->GetValue().StringValue());
936 if (val
== "wxHORIZONTAL")
938 if (windowStyle
& wxVERTICAL
)
939 windowStyle
-= wxVERTICAL
;
940 windowStyle
|= wxHORIZONTAL
;
944 if (windowStyle
& wxHORIZONTAL
)
945 windowStyle
-= wxHORIZONTAL
;
946 windowStyle
|= wxVERTICAL
;
948 radioBox
->SetWindowStyleFlag(windowStyle
);
950 wxResourceManager::currentResourceManager
->RecreateWindowFromResource(radioBox
, this);
953 else if (name
== "values")
955 // Set property into *resource*, not wxRadioBox, and then recreate
956 // the wxRadioBox. This is because we can't dynamically set the strings
958 wxItemResource
*resource
= wxResourceManager::currentResourceManager
->FindResourceForWindow(propertyWindow
);
962 wxStringList
*stringList
= resource
->GetStringValues();
965 stringList
= new wxStringList
;
966 resource
->SetStringValues(stringList
);
970 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
973 char *s
= expr
->StringValue();
976 expr
= expr
->GetNext();
978 wxResourceManager::currentResourceManager
->RecreateWindowFromResource(radioBox
, this);
981 return wxItemPropertyInfo::SetProperty(name
, property
);
984 void wxRadioBoxPropertyInfo::GetPropertyNames(wxStringList
& names
)
988 names
.Add("orientation");
989 names
.Add("numberRowsOrCols");
990 wxItemPropertyInfo::GetPropertyNames(names
);
993 bool wxRadioBoxPropertyInfo::InstantiateResource(wxItemResource
*resource
)
995 wxRadioBox
*rbox
= (wxRadioBox
*)propertyWindow
;
996 // Take strings from resource instead
999 if (rbox->Number() == 0)
1000 resource->SetStringValues(NULL);
1003 wxStringList *slist = new wxStringList;
1005 for (i = 0; i < rbox->Number(); i++)
1006 slist->Add(rbox->GetString(i));
1008 resource->SetStringValues(slist);
1011 resource
->SetValue1(rbox
->GetNumberOfRowsOrCols());
1012 return wxItemPropertyInfo::InstantiateResource(resource
);
1019 wxProperty
*wxGroupBoxPropertyInfo::GetProperty(wxString
& name
)
1021 wxStaticBox
*groupBox
= (wxStaticBox
*)propertyWindow
;
1022 return wxItemPropertyInfo::GetProperty(name
);
1025 bool wxGroupBoxPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1027 return wxItemPropertyInfo::SetProperty(name
, property
);
1030 void wxGroupBoxPropertyInfo::GetPropertyNames(wxStringList
& names
)
1033 wxItemPropertyInfo::GetPropertyNames(names
);
1036 bool wxGroupBoxPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1038 wxStaticBox
*gbox
= (wxStaticBox
*)propertyWindow
;
1039 return wxItemPropertyInfo::InstantiateResource(resource
);
1046 wxProperty
*wxCheckBoxPropertyInfo::GetProperty(wxString
& name
)
1048 wxCheckBox
*checkBox
= (wxCheckBox
*)propertyWindow
;
1049 if (name
== "value")
1050 return new wxProperty("value", checkBox
->GetValue(), "bool");
1052 return wxItemPropertyInfo::GetProperty(name
);
1055 bool wxCheckBoxPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1057 wxCheckBox
*checkBox
= (wxCheckBox
*)propertyWindow
;
1058 if (name
== "value")
1060 checkBox
->SetValue((bool)property
->GetValue().BoolValue());
1064 return wxItemPropertyInfo::SetProperty(name
, property
);
1067 void wxCheckBoxPropertyInfo::GetPropertyNames(wxStringList
& names
)
1071 wxItemPropertyInfo::GetPropertyNames(names
);
1074 bool wxCheckBoxPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1076 wxCheckBox
*cbox
= (wxCheckBox
*)propertyWindow
;
1077 resource
->SetValue1(cbox
->GetValue());
1078 return wxItemPropertyInfo::InstantiateResource(resource
);
1085 wxProperty
*wxSliderPropertyInfo::GetProperty(wxString
& name
)
1087 wxSlider
*slider
= (wxSlider
*)propertyWindow
;
1088 if (name
== "value")
1089 return new wxProperty("value", (long)slider
->GetValue(), "integer");
1090 else if (name
== "orientation")
1093 if (propertyWindow
->GetWindowStyleFlag() & wxHORIZONTAL
)
1094 pos
= "wxHORIZONTAL";
1098 return new wxProperty("orientation", pos
, "string",
1099 new wxStringListValidator(new wxStringList("wxHORIZONTAL", "wxVERTICAL",
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");
1107 return wxItemPropertyInfo::GetProperty(name
);
1110 bool wxSliderPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1112 wxSlider
*slider
= (wxSlider
*)propertyWindow
;
1113 if (name
== "value")
1115 slider
->SetValue((int)property
->GetValue().IntegerValue());
1118 else if (name
== "orientation")
1120 long windowStyle
= slider
->GetWindowStyleFlag();
1121 long oldWindowStyle
= windowStyle
;
1122 wxString
val(property
->GetValue().StringValue());
1123 if (val
== "wxHORIZONTAL")
1125 if (windowStyle
& wxVERTICAL
)
1126 windowStyle
-= wxVERTICAL
;
1127 windowStyle
|= wxHORIZONTAL
;
1131 if (windowStyle
& wxHORIZONTAL
)
1132 windowStyle
-= wxHORIZONTAL
;
1133 windowStyle
|= wxVERTICAL
;
1136 if (oldWindowStyle
== windowStyle
)
1139 slider
->SetWindowStyleFlag(windowStyle
);
1141 // If the window style has changed, we swap the width and height parameters.
1143 slider
->GetSize(&w
, &h
);
1145 slider
= (wxSlider
*)wxResourceManager::currentResourceManager
->RecreateWindowFromResource(slider
, this);
1146 slider
->SetSize(-1, -1, h
, w
);
1150 else if (name
== "min_value")
1152 slider
->SetRange((int)property
->GetValue().IntegerValue(), slider
->GetMax());
1155 else if (name
== "max_value")
1157 slider
->SetRange(slider
->GetMin(), (int)property
->GetValue().IntegerValue());
1161 return wxItemPropertyInfo::SetProperty(name
, property
);
1164 void wxSliderPropertyInfo::GetPropertyNames(wxStringList
& names
)
1167 names
.Add("orientation");
1168 names
.Add("min_value");
1169 names
.Add("max_value");
1170 wxItemPropertyInfo::GetPropertyNames(names
);
1173 bool wxSliderPropertyInfo::InstantiateResource(wxItemResource
*resource
)
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
);
1186 wxProperty
*wxGaugePropertyInfo::GetProperty(wxString
& name
)
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");
1194 return wxItemPropertyInfo::GetProperty(name
);
1197 bool wxGaugePropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1199 wxGauge
*gauge
= (wxGauge
*)propertyWindow
;
1200 if (name
== "value")
1202 gauge
->SetValue((int)property
->GetValue().IntegerValue());
1205 else if (name
== "max_value")
1207 gauge
->SetRange((int)property
->GetValue().IntegerValue());
1211 return wxItemPropertyInfo::SetProperty(name
, property
);
1214 void wxGaugePropertyInfo::GetPropertyNames(wxStringList
& names
)
1217 names
.Add("max_value");
1218 wxItemPropertyInfo::GetPropertyNames(names
);
1221 bool wxGaugePropertyInfo::InstantiateResource(wxItemResource
*resource
)
1223 wxGauge
*gauge
= (wxGauge
*)propertyWindow
;
1224 resource
->SetValue1(gauge
->GetValue());
1225 resource
->SetValue2(gauge
->GetRange());
1226 return wxItemPropertyInfo::InstantiateResource(resource
);
1233 wxProperty
*wxScrollBarPropertyInfo::GetProperty(wxString
& name
)
1235 wxScrollBar
*scrollBar
= (wxScrollBar
*)propertyWindow
;
1236 if (name
== "value")
1237 return new wxProperty("value", (long)scrollBar
->GetValue(), "integer");
1238 else if (name
== "orientation")
1241 if (propertyWindow
->GetWindowStyleFlag() & wxHORIZONTAL
)
1242 pos
= "wxHORIZONTAL";
1246 return new wxProperty("orientation", pos
, "string",
1247 new wxStringListValidator(new wxStringList("wxHORIZONTAL", "wxVERTICAL",
1250 else if (name
== "pageSize")
1252 int viewStart
, pageLength
, objectLength
, viewLength
;
1253 scrollBar
->GetValues(&viewStart
, &viewLength
, &objectLength
, &pageLength
);
1255 return new wxProperty("pageSize", (long)pageLength
, "integer");
1257 else if (name
== "viewLength")
1259 int viewStart
, pageLength
, objectLength
, viewLength
;
1260 scrollBar
->GetValues(&viewStart
, &viewLength
, &objectLength
, &pageLength
);
1262 return new wxProperty("viewLength", (long)viewLength
, "integer");
1264 else if (name
== "objectLength")
1266 int viewStart
, pageLength
, objectLength
, viewLength
;
1267 scrollBar
->GetValues(&viewStart
, &viewLength
, &objectLength
, &pageLength
);
1269 return new wxProperty("objectLength", (long)objectLength
, "integer");
1272 return wxItemPropertyInfo::GetProperty(name
);
1275 bool wxScrollBarPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1277 wxScrollBar
*scrollBar
= (wxScrollBar
*)propertyWindow
;
1278 if (name
== "value")
1280 scrollBar
->SetValue((int)property
->GetValue().IntegerValue());
1283 else if (name
== "orientation")
1285 long windowStyle
= scrollBar
->GetWindowStyleFlag();
1286 long oldWindowStyle
= windowStyle
;
1287 wxString
val(property
->GetValue().StringValue());
1288 if (val
== "wxHORIZONTAL")
1290 if (windowStyle
& wxVERTICAL
)
1291 windowStyle
-= wxVERTICAL
;
1292 windowStyle
|= wxHORIZONTAL
;
1296 if (windowStyle
& wxHORIZONTAL
)
1297 windowStyle
-= wxHORIZONTAL
;
1298 windowStyle
|= wxVERTICAL
;
1301 if (oldWindowStyle
== windowStyle
)
1304 scrollBar
->SetWindowStyleFlag(windowStyle
);
1306 // If the window style has changed, we swap the width and height parameters.
1308 scrollBar
->GetSize(&w
, &h
);
1310 scrollBar
= (wxScrollBar
*)wxResourceManager::currentResourceManager
->RecreateWindowFromResource(scrollBar
, this);
1311 scrollBar
->SetSize(-1, -1, h
, w
);
1315 else if (name
== "pageSize")
1317 scrollBar
->SetPageSize((int)property
->GetValue().IntegerValue());
1320 else if (name
== "viewLength")
1322 scrollBar
->SetViewLength((int)property
->GetValue().IntegerValue());
1325 else if (name
== "objectLength")
1327 scrollBar
->SetObjectLength((int)property
->GetValue().IntegerValue());
1331 return wxItemPropertyInfo::SetProperty(name
, property
);
1334 void wxScrollBarPropertyInfo::GetPropertyNames(wxStringList
& names
)
1336 names
.Add("orientation");
1338 names
.Add("pageSize");
1339 names
.Add("viewLength");
1340 names
.Add("objectLength");
1341 wxItemPropertyInfo::GetPropertyNames(names
);
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");
1351 bool wxScrollBarPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1353 wxScrollBar
*sbar
= (wxScrollBar
*)propertyWindow
;
1355 resource
->SetValue1(sbar
->GetValue());
1357 int viewStart
, pageLength
, objectLength
, viewLength
;
1358 sbar
->GetValues(&viewStart
, &viewLength
, &objectLength
, &pageLength
);
1360 resource
->SetValue2(pageLength
);
1361 resource
->SetValue3(objectLength
);
1362 resource
->SetValue5(viewLength
);
1364 return wxItemPropertyInfo::InstantiateResource(resource
);
1371 wxProperty
*wxPanelPropertyInfo::GetProperty(wxString
& name
)
1373 wxPanel
*panelWindow
= (wxPanel
*)propertyWindow
;
1374 wxFont
*labelFont
= panelWindow
->GetLabelFont();
1375 wxFont
*buttonFont
= panelWindow
->GetButtonFont();
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")
1386 if (panelWindow
->GetWindowStyleFlag() & wxUSER_COLOURS
)
1389 userColours
= FALSE
;
1391 return new wxProperty(name
, (bool)userColours
, "bool");
1393 else if (name
== "backgroundColour")
1395 wxColour
col(panelWindow
->GetBackgroundColour());
1397 wxDecToHex(col
.Red(), buf
);
1398 wxDecToHex(col
.Green(), buf
+2);
1399 wxDecToHex(col
.Blue(), buf
+4);
1401 return new wxProperty(name
, buf
, "string", new wxColourListValidator
);
1404 return wxWindowPropertyInfo::GetProperty(name
);
1407 bool wxPanelPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1409 wxPanel
*panelWindow
= (wxPanel
*)propertyWindow
;
1410 wxFont
*labelFont
= panelWindow
->GetLabelFont();
1411 wxFont
*buttonFont
= panelWindow
->GetButtonFont();
1413 if (labelFont
&& (name
== "labelFontPoints" || name
== "labelFontFamily" || name
== "labelFontStyle" || name
== "labelFontWeight" || name
== "labelFontUnderlined" ))
1415 wxFont
*newFont
= SetFontProperty(name
, property
, labelFont
);
1417 panelWindow
->SetLabelFont(newFont
);
1420 else if (buttonFont
&& (name
== "buttonFontPoints" || name
== "buttonFontFamily" || name
== "buttonFontStyle" || name
== "buttonFontWeight" || name
== "buttonFontUnderlined" ))
1422 wxFont
*newFont
= SetFontProperty(name
, property
, buttonFont
);
1424 panelWindow
->SetButtonFont(newFont
);
1427 else if (name
== "userColours")
1429 bool userColours
= property
->GetValue().BoolValue();
1430 long flag
= panelWindow
->GetWindowStyleFlag();
1434 if ((panelWindow
->GetWindowStyleFlag() & wxUSER_COLOURS
) != wxUSER_COLOURS
)
1435 panelWindow
->SetWindowStyleFlag(panelWindow
->GetWindowStyleFlag() | wxUSER_COLOURS
);
1439 if ((panelWindow
->GetWindowStyleFlag() & wxUSER_COLOURS
) == wxUSER_COLOURS
)
1440 panelWindow
->SetWindowStyleFlag(panelWindow
->GetWindowStyleFlag() - wxUSER_COLOURS
);
1442 wxItemResource
*resource
= wxResourceManager::currentResourceManager
->FindResourceForWindow(panelWindow
);
1443 resource
->SetStyle(panelWindow
->GetWindowStyleFlag());
1445 panelWindow
= (wxPanel
*)wxResourceManager::currentResourceManager
->RecreateWindowFromResource(panelWindow
, this);
1446 // panelWindow->SetUserEditMode(wxResourceManager::currentResourceManager->GetEditMode());
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());
1454 else if (name
== "backgroundColour")
1456 char *hex
= property
->GetValue().StringValue();
1457 int r
= wxHexToDec(hex
);
1458 int g
= wxHexToDec(hex
+2);
1459 int b
= wxHexToDec(hex
+4);
1461 wxColour
col(r
,g
,b
);
1462 panelWindow
->SetBackgroundColour(col
);
1463 panelWindow
= (wxPanel
*)wxResourceManager::currentResourceManager
->RecreateWindowFromResource(panelWindow
, this);
1464 // panelWindow->SetUserEditMode(wxResourceManager::currentResourceManager->GetEditMode());
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());
1473 return wxWindowPropertyInfo::SetProperty(name
, property
);
1476 void wxPanelPropertyInfo::GetPropertyNames(wxStringList
& names
)
1478 wxWindowPropertyInfo::GetPropertyNames(names
);
1480 // names.Add("orientation");
1481 names
.Add("userColours");
1482 names
.Add("backgroundColour");
1485 bool wxPanelPropertyInfo::InstantiateResource(wxItemResource
*resource
)
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()));
1493 resource
->SetBackgroundColour(new wxColour(panel
->GetBackgroundColour()));
1495 return wxWindowPropertyInfo::InstantiateResource(resource
);
1502 wxProperty
*wxDialogPropertyInfo::GetProperty(wxString
& name
)
1504 wxDialog
*dialogWindow
= (wxDialog
*)propertyWindow
;
1505 if (name
== "modal")
1507 wxItemResource
*resource
= wxResourceManager::currentResourceManager
->FindResourceForWindow(dialogWindow
);
1511 bool modal
= (resource
->GetValue1() != 0);
1512 return new wxProperty(name
, modal
, "bool");
1515 return wxPanelPropertyInfo::GetProperty(name
);
1518 bool wxDialogPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1520 wxDialog
*dialogWindow
= (wxDialog
*)propertyWindow
;
1522 if (name
== "modal")
1524 wxItemResource
*resource
= wxResourceManager::currentResourceManager
->FindResourceForWindow(dialogWindow
);
1528 resource
->SetValue1(property
->GetValue().BoolValue());
1532 return wxPanelPropertyInfo::SetProperty(name
, property
);
1535 void wxDialogPropertyInfo::GetPropertyNames(wxStringList
& names
)
1540 wxPanelPropertyInfo::GetPropertyNames(names
);
1543 bool wxDialogPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1545 wxDialog
*dialog
= (wxDialog
*)propertyWindow
;
1546 wxString
str(dialog
->GetTitle());
1547 resource
->SetTitle(WXSTRINGCAST str
);
1549 return wxPanelPropertyInfo::InstantiateResource(resource
);
1556 int wxStringToFontWeight(wxString
& val
)
1558 if (val
== "wxBOLD") return wxBOLD
;
1559 else if (val
== "wxLIGHT") return wxLIGHT
;
1560 else return wxNORMAL
;
1563 int wxStringToFontStyle(wxString
& val
)
1565 if (val
== "wxITALIC") return wxITALIC
;
1566 else if (val
== "wxSLANT") return wxSLANT
;
1567 else return wxNORMAL
;
1570 int wxStringToFontFamily(wxString
& val
)
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
;