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(__WXMSW__) && !defined(__GNUWIN32__)
35 #include <strstream.h>
45 // Causes immediate feedback.
46 void wxResourcePropertyListView::OnPropertyChanged(wxProperty
*property
)
48 // Sets the value of the property back into the actual object,
49 // IF the property value was modified.
50 if (property
->GetValue().GetModified())
52 propertyInfo
->SetProperty(property
->GetName(), property
);
53 property
->GetValue().SetModified(FALSE
);
57 bool wxResourcePropertyListView::OnClose(void)
60 GetManagedWindow()->GetSize(& w
, & h
);
61 GetManagedWindow()->GetPosition(& x
, & y
);
63 wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().width
= w
;
64 wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().height
= h
;
65 wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().x
= x
;
66 wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().y
= y
;
68 return wxPropertyListView::OnClose();
71 wxWindow
*wxPropertyInfo::sm_propertyWindow
;
74 * wxDialogEditorPropertyListDialog
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)
87 wxDialogEditorPropertyListDialog::~wxDialogEditorPropertyListDialog()
91 wxPropertyInfo::sm_propertyWindow = NULL;
95 wxDialogEditorPropertyListFrame::wxDialogEditorPropertyListFrame(wxPropertyListView
*v
, wxFrame
*parent
, const wxString
& title
,
96 const wxPoint
& pos
, const wxSize
& size
,
97 long style
, const wxString
& name
):
98 wxPropertyListFrame(v
, parent
, title
, pos
, size
, style
, name
)
104 wxDialogEditorPropertyListFrame::~wxDialogEditorPropertyListFrame()
108 wxPropertyInfo::sm_propertyWindow
= NULL
;
115 // Edit the information represented by this object, whatever that
117 bool wxPropertyInfo::Edit(wxWindow
*parent
, const wxString
& title
)
119 if (sm_propertyWindow
)
122 int width
= wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().width
;
123 int height
= wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().height
;
124 int x
= wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().x
;
125 int y
= wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().y
;
127 wxPropertySheet
*propSheet
= new wxPropertySheet
;
129 wxStringList propNames
;
130 GetPropertyNames(propNames
);
132 wxNode
*node
= propNames
.First();
135 wxString
name((char *)node
->Data());
136 wxProperty
*prop
= GetProperty(name
);
139 propSheet
->AddProperty(prop
);
144 // Reset 'modified' flags for all property values
145 propSheet
->SetAllModified(FALSE
);
147 wxResourcePropertyListView
*view
= new wxResourcePropertyListView(this, NULL
,
148 wxPROP_BUTTON_OK
| wxPROP_BUTTON_CANCEL
|
149 wxPROP_BUTTON_CHECK_CROSS
|wxPROP_DYNAMIC_VALUE_FIELD
|wxPROP_PULLDOWN
|wxPROP_SHOWVALUES
);
151 wxDialogEditorPropertyListFrame
*propWin
= new wxDialogEditorPropertyListFrame(view
,
152 wxResourceManager::GetCurrentResourceManager()->GetEditorFrame(), title
, wxPoint(x
, y
),
153 wxSize(width
, height
), wxDEFAULT_FRAME_STYLE
);
154 sm_propertyWindow
= propWin
;
156 propWin
->m_registry
.RegisterValidator((wxString
)"real", new wxRealListValidator
);
157 propWin
->m_registry
.RegisterValidator((wxString
)"string", new wxStringListValidator
);
158 propWin
->m_registry
.RegisterValidator((wxString
)"integer", new wxIntegerListValidator
);
159 propWin
->m_registry
.RegisterValidator((wxString
)"bool", new wxBoolListValidator
);
160 propWin
->m_registry
.RegisterValidator((wxString
)"filename", new wxFilenameListValidator
);
161 propWin
->m_registry
.RegisterValidator((wxString
)"stringlist", new wxListOfStringsListValidator
);
162 propWin
->m_registry
.RegisterValidator((wxString
)"window_id", new wxResourceSymbolValidator
);
164 propWin
->m_propInfo
= this;
165 propWin
->m_propSheet
= propSheet
;
167 // view->propertyWindow = propWin;
168 view
->AddRegistry(&(propWin
->m_registry
));
170 propWin
->Initialize();
171 view
->ShowView(propSheet
, propWin
->GetPropertyPanel());
178 * wxWindowPropertyInfo
181 wxWindowPropertyInfo::wxWindowPropertyInfo(wxWindow
*win
, wxItemResource
*res
)
183 propertyWindow
= win
;
184 propertyResource
= res
;
187 wxWindowPropertyInfo::~wxWindowPropertyInfo(void)
191 wxProperty
*wxWindowPropertyInfo::GetFontProperty(wxString
& name
, wxFont
*font
)
196 if (name
.Contains("Points"))
197 return new wxProperty(name
, (long)font
->GetPointSize(), "integer", new wxIntegerListValidator(1, 100));
198 else if (name
.Contains("Family"))
199 return new wxProperty(name
, font
->GetFamilyString(), "string",
200 new wxStringListValidator(new wxStringList("wxDECORATIVE", "wxROMAN", "wxSCRIPT", "wxSWISS", "wxMODERN",
202 else if (name
.Contains("Style"))
203 return new wxProperty(name
, font
->GetStyleString(), "string",
204 new wxStringListValidator(new wxStringList("wxNORMAL", "wxITALIC", "wxSLANT", NULL
)));
205 else if (name
.Contains("Weight"))
206 return new wxProperty(name
, font
->GetWeightString(), "string",
207 new wxStringListValidator(new wxStringList("wxNORMAL", "wxBOLD", "wxLIGHT", NULL
)));
208 else if (name
.Contains("Underlined"))
209 return new wxProperty(name
, (bool)font
->GetUnderlined(), "bool");
214 wxFont
*wxWindowPropertyInfo::SetFontProperty(wxString
& name
, wxProperty
*property
, wxFont
*font
)
217 int fontFamily
= wxMODERN
;
218 int fontStyle
= wxNORMAL
;
219 int fontWeight
= wxNORMAL
;
220 bool fontUnderlined
= FALSE
;
222 if (name
.Contains("Points"))
224 pointSize
= (int)property
->GetValue().IntegerValue();
225 if (font
&& (pointSize
== font
->GetPointSize()))
226 return NULL
; // No change
228 else if (font
) pointSize
= font
->GetPointSize();
230 if (name
.Contains("Family"))
232 wxString val
= property
->GetValue().StringValue();
233 fontFamily
= wxStringToFontFamily(val
);
235 if (font
&& (fontFamily
== font
->GetFamily()))
236 return NULL
; // No change
238 else if (font
) fontFamily
= font
->GetFamily();
240 if (name
.Contains("Style"))
242 wxString val
= property
->GetValue().StringValue();
243 fontStyle
= wxStringToFontStyle(val
);
245 if (font
&& (fontStyle
== font
->GetStyle()))
246 return NULL
; // No change
248 else if (font
) fontStyle
= font
->GetStyle();
249 if (name
.Contains("Weight"))
251 wxString val
= property
->GetValue().StringValue();
252 fontWeight
= wxStringToFontWeight(val
);
254 if (font
&& (fontWeight
== font
->GetWeight()))
255 return NULL
; // No change
257 else if (font
) fontWeight
= font
->GetWeight();
259 if (name
.Contains("Underlined"))
261 fontUnderlined
= property
->GetValue().BoolValue();
263 if (font
&& (fontUnderlined
== font
->GetUnderlined()))
264 return NULL
; // No change
266 else if (font
) fontUnderlined
= font
->GetUnderlined();
268 wxFont
*newFont
= wxTheFontList
->FindOrCreateFont(pointSize
, fontFamily
, fontStyle
, fontWeight
, fontUnderlined
);
277 wxProperty
*wxWindowPropertyInfo::GetProperty(wxString
& name
)
279 wxFont
*font
= propertyWindow
->GetFont();
280 if (name
== "fontPoints" || name
== "fontFamily" || name
== "fontStyle" || name
== "fontWeight" ||
281 name
== "fontUnderlined")
282 return GetFontProperty(name
, font
);
283 else if (name
== "name")
284 return new wxProperty("name", propertyWindow
->GetName(), "string");
285 else if (name
== "title")
286 return new wxProperty("title", propertyWindow
->GetTitle(), "string");
287 else if (name
== "x")
290 propertyWindow
->GetPosition(&x
, &y
);
291 return new wxProperty("x", (long)x
, "integer");
293 else if (name
== "y")
296 propertyWindow
->GetPosition(&x
, &y
);
297 return new wxProperty("y", (long)y
, "integer");
299 else if (name
== "width")
302 propertyWindow
->GetSize(&width
, &height
);
303 return new wxProperty("width", (long)width
, "integer");
305 else if (name
== "height")
308 propertyWindow
->GetSize(&width
, &height
);
309 return new wxProperty("height", (long)height
, "integer");
311 else if (name
== "id")
313 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(propertyWindow
);
316 int id
= resource
->GetId();
318 idStr
.Printf("%d", id
);
319 wxString symbolName
= wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetSymbolForId(id
);
322 // symbolName is now e.g. "ID_PANEL21=105"
323 return new wxProperty("id", symbolName
, "window_id");
332 bool wxWindowPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
334 wxFont
*font
= propertyWindow
->GetFont();
335 if (font
&& (name
== "fontPoints" || name
== "fontFamily" || name
== "fontStyle" || name
== "fontWeight" || name
== "fontUnderlined" ))
337 wxFont
*newFont
= SetFontProperty(name
, property
, font
);
339 propertyWindow
->SetFont(newFont
);
342 else if (name
== "name")
344 // Remove old name from resource table, if it's there.
345 wxItemResource
*oldResource
= (wxItemResource
*)wxResourceManager::GetCurrentResourceManager()->GetResourceTable().Delete(propertyWindow
->GetName());
348 // It's a top-level resource
349 propertyWindow
->SetName(property
->GetValue().StringValue());
350 oldResource
->SetName(property
->GetValue().StringValue());
351 wxResourceManager::GetCurrentResourceManager()->GetResourceTable().Put(propertyWindow
->GetName(), oldResource
);
355 // It's a child of something; just set the name of the resource and the window.
356 propertyWindow
->SetName(property
->GetValue().StringValue());
357 propertyResource
->SetName(property
->GetValue().StringValue());
359 // Refresh the resource manager list, because the name changed.
360 wxResourceManager::GetCurrentResourceManager()->UpdateResourceList();
363 else if (name
== "title")
365 propertyWindow
->SetTitle(property
->GetValue().StringValue());
368 else if (name
== "x")
371 propertyWindow
->GetPosition(&x
, &y
);
372 int newX
= (int)property
->GetValue().IntegerValue();
374 propertyWindow
->Move(newX
, y
);
377 else if (name
== "y")
380 propertyWindow
->GetPosition(&x
, &y
);
381 int newY
= (int)property
->GetValue().IntegerValue();
383 propertyWindow
->Move(x
, newY
);
386 else if (name
== "width")
389 propertyWindow
->GetSize(&width
, &height
);
390 int newWidth
= (int)property
->GetValue().IntegerValue();
391 if (width
!= newWidth
)
393 propertyWindow
->SetSize(newWidth
, height
);
395 if (propertyWindow->IsKindOf(CLASSINFO(wxPanel)) && !propertyWindow->IsKindOf(CLASSINFO(wxDialog)))
397 propertyWindow->GetParent()->SetClientSize(newWidth, height);
403 else if (name
== "height")
406 propertyWindow
->GetSize(&width
, &height
);
407 int newHeight
= (int)property
->GetValue().IntegerValue();
408 if (height
!= newHeight
)
410 propertyWindow
->SetSize(width
, newHeight
);
412 if (propertyWindow->IsKindOf(CLASSINFO(wxPanel)) && !propertyWindow->IsKindOf(CLASSINFO(wxDialog)))
414 propertyWindow->GetParent()->SetClientSize(width, newHeight);
420 else if (name
== "id")
422 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(propertyWindow
);
425 wxString value
= property
->GetValue().StringValue();
427 wxString strName
= value
.Before('=');
428 wxString strId
= value
.After('=');
429 int id
= atoi(strId
);
431 wxString oldSymbolName
= wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetSymbolForId(resource
->GetId());
432 int oldSymbolId
= resource
->GetId();
436 // If we change the id for an existing symbol, we need to:
437 // 1) Check if there are any other resources currently using the original id.
438 // If so, will need to change their id to the new id.
439 // 2) Remove the old symbol, add the new symbol.
440 // In this check, we don't have to do this, but we need to do it in SetProperty.
442 if (strName
== oldSymbolName
&& id
!= oldSymbolId
)
444 wxASSERT( (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(oldSymbolName
)) );
446 // It's OK to change just the id. But we'll need to change all matching ids in all resources,
447 // because ids are unique and changing one resource's id must change all identical ones.
448 wxResourceManager::GetCurrentResourceManager()->ChangeIds(oldSymbolId
, id
);
450 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().RemoveSymbol(oldSymbolName
);
451 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().AddSymbol(strName
, id
);
454 // If we change the name but not the id, we'll just need to remove and
455 // re-add the symbol/id pair.
456 if (strName
!= oldSymbolName
&& id
== oldSymbolId
)
458 wxASSERT( (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(oldSymbolName
)) );
460 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().RemoveSymbol(oldSymbolName
);
462 if (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().SymbolExists(strName
))
464 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().AddSymbol(strName
, id
);
468 // What if we're changing both the name and the id?
469 // - if there's no symbol of that name, just remove the old, add the new (in SetProperty)
470 // - if there is a symbol of that name, if id matches, do nothing. If not, veto.
472 if (strName
!= oldSymbolName
&& id
!= oldSymbolId
)
474 // Remove old symbol if it's not being used
475 if (!wxResourceManager::GetCurrentResourceManager()->IsSymbolUsed(resource
, oldSymbolId
) &&
476 !wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(oldSymbolName
))
478 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().RemoveSymbol(oldSymbolName
);
481 if (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().SymbolExists(strName
))
483 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().AddSymbol(strName
, id
);
498 void wxWindowPropertyInfo::GetPropertyNames(wxStringList
& names
)
506 if (!propertyWindow
->IsKindOf(CLASSINFO(wxControl
)))
508 names
.Add("fontPoints");
509 names
.Add("fontFamily");
510 names
.Add("fontStyle");
511 names
.Add("fontWeight");
512 names
.Add("fontUnderlined");
516 // Fill in the wxItemResource members to mirror the current window settings
517 bool wxWindowPropertyInfo::InstantiateResource(wxItemResource
*resource
)
519 // resource->SetType(propertyWindow->GetClassInfo()->GetClassName());
521 // resource->SetStyle(propertyWindow->GetWindowStyleFlag());
522 wxString
str(propertyWindow
->GetName());
523 resource
->SetName(WXSTRINGCAST str
);
525 propertyWindow
->GetSize(&w
, &h
);
527 propertyWindow
->GetPosition(&x
, &y
);
528 resource
->SetSize(x
, y
, w
, h
);
532 // Set the window style
533 void wxWindowPropertyInfo::SetWindowStyle(wxWindow
* win
, long style
, bool set
)
538 if ((win
->GetWindowStyleFlag() & style
) == style
)
542 win
->SetWindowStyleFlag(win
->GetWindowStyleFlag() - style
);
549 win
->SetWindowStyleFlag(win
->GetWindowStyleFlag() | style
);
558 wxProperty
*wxItemPropertyInfo::GetProperty(wxString
& name
)
560 wxControl
*itemWindow
= (wxControl
*)propertyWindow
;
561 wxFont
*font
= itemWindow
->GetFont();
563 if (name
== "fontPoints" || name
== "fontFamily" || name
== "fontStyle" || name
== "fontWeight" ||
564 name
== "fontUnderlined")
565 return GetFontProperty(name
, font
);
566 else if (name
== "label" && itemWindow
->GetLabel())
567 return new wxProperty("label", propertyWindow
->GetLabel(), "string");
569 return wxWindowPropertyInfo::GetProperty(name
);
572 bool wxItemPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
574 wxControl
*itemWindow
= (wxControl
*)propertyWindow
;
575 wxFont
*font
= itemWindow
->GetFont();
577 if (font
&& (name
== "fontPoints" || name
== "fontFamily" || name
== "fontStyle" || name
== "fontWeight" || name
== "fontUnderlined" ))
579 wxFont
*newFont
= SetFontProperty(name
, property
, font
);
581 itemWindow
->SetLabelFont(newFont
);
584 else if (name
== "label")
586 itemWindow
->SetLabel(property
->GetValue().StringValue());
590 return wxWindowPropertyInfo::SetProperty(name
, property
);
593 void wxItemPropertyInfo::GetPropertyNames(wxStringList
& names
)
595 wxWindowPropertyInfo::GetPropertyNames(names
);
597 names
.Add("fontPoints");
598 names
.Add("fontFamily");
599 names
.Add("fontStyle");
600 names
.Add("fontWeight");
601 names
.Add("fontUnderlined");
604 bool wxItemPropertyInfo::InstantiateResource(wxItemResource
*resource
)
606 wxWindowPropertyInfo::InstantiateResource(resource
);
608 wxControl
*item
= (wxControl
*)propertyWindow
;
609 wxString
str(item
->GetLabel());
610 resource
->SetTitle(WXSTRINGCAST str
);
611 if (item
->GetFont() && item
->GetFont()->Ok())
612 resource
->SetFont(wxTheFontList
->FindOrCreateFont(item
->GetFont()->GetPointSize(),
613 item
->GetFont()->GetFamily(), item
->GetFont()->GetStyle(), item
->GetFont()->GetWeight(),
614 item
->GetFont()->GetUnderlined(), item
->GetFont()->GetFaceName()));
622 wxProperty
*wxButtonPropertyInfo::GetProperty(wxString
& name
)
624 wxButton
*button
= (wxButton
*)propertyWindow
;
625 return wxItemPropertyInfo::GetProperty(name
);
628 bool wxButtonPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
630 wxButton
*button
= (wxButton
*)propertyWindow
;
631 return wxItemPropertyInfo::SetProperty(name
, property
);
634 void wxButtonPropertyInfo::GetPropertyNames(wxStringList
& names
)
636 wxItemPropertyInfo::GetPropertyNames(names
);
640 bool wxButtonPropertyInfo::InstantiateResource(wxItemResource
*resource
)
642 return wxItemPropertyInfo::InstantiateResource(resource
);
649 wxProperty
*wxBitmapButtonPropertyInfo::GetProperty(wxString
& name
)
651 wxBitmapButton
*button
= (wxBitmapButton
*)propertyWindow
;
654 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(button
);
655 wxString
str("none.bmp");
659 char *filename
= wxResourceManager::GetCurrentResourceManager()->FindBitmapFilenameForResource(resource
);
663 return new wxProperty("label", str
.GetData(), "string", new wxFilenameListValidator("Select a bitmap file", "*.bmp"));
666 return wxButtonPropertyInfo::GetProperty(name
);
669 bool wxBitmapButtonPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
671 wxBitmapButton
*button
= (wxBitmapButton
*)propertyWindow
;
674 char *s
= property
->GetValue().StringValue();
675 if (s
&& wxFileExists(s
))
678 wxBitmap
*bitmap
= new wxBitmap(s
, wxBITMAP_TYPE_BMP
);
687 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(button
);
690 wxString
oldResource(resource
->GetValue4());
691 char *resName
= wxResourceManager::GetCurrentResourceManager()->AddBitmapResource(s
);
692 resource
->SetValue4(resName
);
694 if (!oldResource
.IsNull())
695 wxResourceManager::GetCurrentResourceManager()->PossiblyDeleteBitmapResource(WXSTRINGCAST oldResource
);
698 button
->SetLabel(bitmap
);
706 return wxButtonPropertyInfo::SetProperty(name
, property
);
709 void wxBitmapButtonPropertyInfo::GetPropertyNames(wxStringList
& names
)
711 // names.Add("label");
712 wxButtonPropertyInfo::GetPropertyNames(names
);
715 bool wxBitmapButtonPropertyInfo::InstantiateResource(wxItemResource
*resource
)
717 return wxItemPropertyInfo::InstantiateResource(resource
);
724 wxProperty
*wxStaticTextPropertyInfo::GetProperty(wxString
& name
)
726 wxStaticText
*message
= (wxStaticText
*)propertyWindow
;
727 return wxItemPropertyInfo::GetProperty(name
);
730 bool wxStaticTextPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
732 wxStaticText
*message
= (wxStaticText
*)propertyWindow
;
733 return wxItemPropertyInfo::SetProperty(name
, property
);
736 void wxStaticTextPropertyInfo::GetPropertyNames(wxStringList
& names
)
738 wxItemPropertyInfo::GetPropertyNames(names
);
742 bool wxStaticTextPropertyInfo::InstantiateResource(wxItemResource
*resource
)
744 return wxItemPropertyInfo::InstantiateResource(resource
);
751 wxProperty
*wxStaticBitmapPropertyInfo::GetProperty(wxString
& name
)
753 wxStaticBitmap
*message
= (wxStaticBitmap
*)propertyWindow
;
756 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(message
);
757 wxString
str("none.bmp");
761 char *filename
= wxResourceManager::GetCurrentResourceManager()->FindBitmapFilenameForResource(resource
);
765 return new wxProperty("label", str
.GetData(), "string", new wxFilenameListValidator("Select a bitmap file", "*.bmp"));
768 return wxItemPropertyInfo::GetProperty(name
);
771 bool wxStaticBitmapPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
773 wxStaticBitmap
*message
= (wxStaticBitmap
*)propertyWindow
;
776 char *s
= property
->GetValue().StringValue();
777 if (s
&& wxFileExists(s
))
781 wxBitmap
*bitmap
= new wxBitmap(s
, wxBITMAP_TYPE_BMP
);
790 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(message
);
793 wxString
oldResource(resource
->GetValue4());
794 char *resName
= wxResourceManager::GetCurrentResourceManager()->AddBitmapResource(s
);
795 resource
->SetValue4(resName
);
797 if (!oldResource
.IsNull())
798 wxResourceManager::GetCurrentResourceManager()->PossiblyDeleteBitmapResource(WXSTRINGCAST oldResource
);
801 message
->SetBitmap(bitmap
);
809 return wxItemPropertyInfo::SetProperty(name
, property
);
812 void wxStaticBitmapPropertyInfo::GetPropertyNames(wxStringList
& names
)
814 wxItemPropertyInfo::GetPropertyNames(names
);
818 bool wxStaticBitmapPropertyInfo::InstantiateResource(wxItemResource
*resource
)
820 return wxItemPropertyInfo::InstantiateResource(resource
);
827 wxProperty
*wxTextPropertyInfo::GetProperty(wxString
& name
)
829 wxTextCtrl
*text
= (wxTextCtrl
*)propertyWindow
;
831 return new wxProperty("value", text
->GetValue(), "string");
832 else if (name
== "password")
834 bool isPassword
= ((text
->GetWindowStyleFlag() & wxTE_PASSWORD
) == wxTE_PASSWORD
);
835 return new wxProperty("password", isPassword
, "bool");
837 else if (name
== "readonly")
839 bool isReadOnly
= ((text
->GetWindowStyleFlag() & wxTE_READONLY
) == wxTE_READONLY
);
840 return new wxProperty("readonly", isReadOnly
, "bool");
843 return wxItemPropertyInfo::GetProperty(name
);
846 bool wxTextPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
848 wxTextCtrl
*text
= (wxTextCtrl
*)propertyWindow
;
851 text
->SetValue(property
->GetValue().StringValue());
854 else if (name
== "password")
856 long flag
= text
->GetWindowStyleFlag();
857 if (property
->GetValue().BoolValue())
859 if ((flag
& wxTE_PASSWORD
) != wxTE_PASSWORD
)
860 flag
|= wxTE_PASSWORD
;
864 if ((flag
& wxTE_PASSWORD
) == wxTE_PASSWORD
)
865 flag
-= wxTE_PASSWORD
;
867 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(text
);
868 resource
->SetStyle(flag
);
870 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(text
, this);
873 else if (name
== "readonly")
875 long flag
= text
->GetWindowStyleFlag();
876 if (property
->GetValue().BoolValue())
878 if ((flag
& wxTE_READONLY
) != wxTE_READONLY
)
879 flag
|= wxTE_READONLY
;
883 if ((flag
& wxTE_READONLY
) == wxTE_READONLY
)
884 flag
-= wxTE_READONLY
;
886 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(text
);
887 resource
->SetStyle(flag
);
889 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(text
, this);
893 return wxItemPropertyInfo::SetProperty(name
, property
);
896 void wxTextPropertyInfo::GetPropertyNames(wxStringList
& names
)
898 wxItemPropertyInfo::GetPropertyNames(names
);
900 names
.Add("readonly");
901 names
.Add("password");
904 bool wxTextPropertyInfo::InstantiateResource(wxItemResource
*resource
)
906 wxTextCtrl
*text
= (wxTextCtrl
*)propertyWindow
;
907 wxString
str(text
->GetValue());
908 resource
->SetValue4(WXSTRINGCAST str
);
910 return wxItemPropertyInfo::InstantiateResource(resource
);
917 wxProperty
*wxListBoxPropertyInfo::GetProperty(wxString
& name
)
919 wxListBox
*listBox
= (wxListBox
*)propertyWindow
;
920 if (name
== "values")
922 wxStringList
*stringList
= new wxStringList
;
924 for (i
= 0; i
< listBox
->Number(); i
++)
925 stringList
->Add(listBox
->GetString(i
));
927 return new wxProperty(name
, stringList
, "stringlist");
929 else if (name
== "multiple")
932 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(listBox
);
936 char *mult
= "wxSINGLE";
938 switch (resource
->GetValue1())
941 mult
= "wxLB_MULTIPLE";
944 mult
= "wxLB_EXTENDED";
948 mult
= "wxLB_SINGLE";
951 return new wxProperty("multiple", mult
, "string",
952 new wxStringListValidator(new wxStringList("wxLB_SINGLE", "wxLB_MULTIPLE", "wxLB_EXTENDED",
956 return wxItemPropertyInfo::GetProperty(name
);
959 bool wxListBoxPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
961 wxListBox
*listBox
= (wxListBox
*)propertyWindow
;
962 if (name
== "values")
965 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
968 char *s
= expr
->StringValue();
971 expr
= expr
->GetNext();
975 else if (name
== "multiple")
977 int mult
= wxLB_SINGLE
;
978 wxString
str(property
->GetValue().StringValue());
979 if (str
== "wxLB_MULTIPLE")
980 mult
= wxLB_MULTIPLE
;
981 else if (str
== "wxLB_EXTENDED")
982 mult
= wxLB_EXTENDED
;
985 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(listBox
);
987 resource
->SetValue1(mult
);
988 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(listBox
, this);
992 return wxItemPropertyInfo::SetProperty(name
, property
);
995 void wxListBoxPropertyInfo::GetPropertyNames(wxStringList
& names
)
997 wxItemPropertyInfo::GetPropertyNames(names
);
999 names
.Add("multiple");
1002 bool wxListBoxPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1004 wxListBox
*lbox
= (wxListBox
*)propertyWindow
;
1005 // This will be set for the wxItemResource on reading or in SetProperty
1006 // resource->SetValue1(lbox->GetSelectionMode());
1008 if (lbox
->Number() == 0)
1009 resource
->SetStringValues(NULL
);
1012 wxStringList
*slist
= new wxStringList
;
1014 for (i
= 0; i
< lbox
->Number(); i
++)
1015 slist
->Add(lbox
->GetString(i
));
1017 resource
->SetStringValues(slist
);
1019 return wxItemPropertyInfo::InstantiateResource(resource
);
1026 wxProperty
*wxChoicePropertyInfo::GetProperty(wxString
& name
)
1028 wxChoice
*choice
= (wxChoice
*)propertyWindow
;
1029 if (name
== "values")
1031 wxStringList
*stringList
= new wxStringList
;
1033 for (i
= 0; i
< choice
->Number(); i
++)
1034 stringList
->Add(choice
->GetString(i
));
1036 return new wxProperty(name
, stringList
, "stringlist");
1039 return wxItemPropertyInfo::GetProperty(name
);
1042 bool wxChoicePropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1044 wxChoice
*choice
= (wxChoice
*)propertyWindow
;
1045 if (name
== "values")
1048 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
1051 char *s
= expr
->StringValue();
1054 expr
= expr
->GetNext();
1056 if (choice
->Number() > 0)
1057 choice
->SetSelection(0);
1061 return wxItemPropertyInfo::SetProperty(name
, property
);
1064 void wxChoicePropertyInfo::GetPropertyNames(wxStringList
& names
)
1066 wxItemPropertyInfo::GetPropertyNames(names
);
1067 names
.Add("values");
1070 bool wxChoicePropertyInfo::InstantiateResource(wxItemResource
*resource
)
1072 wxChoice
*choice
= (wxChoice
*)propertyWindow
;
1074 if (choice
->Number() == 0)
1075 resource
->SetStringValues(NULL
);
1078 wxStringList
*slist
= new wxStringList
;
1080 for (i
= 0; i
< choice
->Number(); i
++)
1081 slist
->Add(choice
->GetString(i
));
1083 resource
->SetStringValues(slist
);
1085 return wxItemPropertyInfo::InstantiateResource(resource
);
1092 wxProperty
*wxComboBoxPropertyInfo::GetProperty(wxString
& name
)
1094 wxComboBox
*choice
= (wxComboBox
*)propertyWindow
;
1095 if (name
== "values")
1097 wxStringList
*stringList
= new wxStringList
;
1099 for (i
= 0; i
< choice
->Number(); i
++)
1100 stringList
->Add(choice
->GetString(i
));
1102 return new wxProperty(name
, stringList
, "stringlist");
1104 else if (name
== "sort")
1106 bool sort
= ((propertyWindow
->GetWindowStyleFlag() & wxCB_SORT
) == wxCB_SORT
);
1107 return new wxProperty(name
, sort
, "bool");
1109 else if (name
== "style")
1111 wxString
styleStr("dropdown");
1112 if (propertyWindow
->GetWindowStyleFlag() & wxCB_SIMPLE
)
1113 styleStr
= "simple";
1114 else if (propertyWindow
->GetWindowStyleFlag() & wxCB_READONLY
)
1115 styleStr
= "readonly";
1117 styleStr
= "dropdown";
1119 return new wxProperty(name
, styleStr
, "string",
1120 new wxStringListValidator(new wxStringList("simple", "dropdown", "readonly",
1124 return wxItemPropertyInfo::GetProperty(name
);
1127 bool wxComboBoxPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1129 wxComboBox
*choice
= (wxComboBox
*)propertyWindow
;
1130 if (name
== "values")
1133 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
1136 char *s
= expr
->StringValue();
1139 expr
= expr
->GetNext();
1141 if (choice
->Number() > 0)
1142 choice
->SetSelection(0);
1145 else if (name
== "sort")
1147 SetWindowStyle(propertyWindow
, wxCB_SORT
, property
->GetValue().BoolValue());
1149 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(propertyWindow
);
1150 resource
->SetStyle(propertyWindow
->GetWindowStyleFlag());
1152 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(propertyWindow
, this);
1155 else if (name
== "style")
1157 SetWindowStyle(propertyWindow
, wxCB_SIMPLE
, FALSE
);
1158 SetWindowStyle(propertyWindow
, wxCB_DROPDOWN
, FALSE
);
1159 SetWindowStyle(propertyWindow
, wxCB_READONLY
, FALSE
);
1161 wxString
styleStr(property
->GetValue().StringValue());
1162 if (styleStr
== "simple")
1163 SetWindowStyle(propertyWindow
, wxCB_SIMPLE
, TRUE
);
1164 else if (styleStr
== "dropdown")
1165 SetWindowStyle(propertyWindow
, wxCB_DROPDOWN
, TRUE
);
1166 else if (styleStr
== "readonly")
1167 SetWindowStyle(propertyWindow
, wxCB_READONLY
, TRUE
);
1170 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(propertyWindow
);
1171 resource
->SetStyle(propertyWindow
->GetWindowStyleFlag());
1173 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(propertyWindow
, this);
1178 return wxItemPropertyInfo::SetProperty(name
, property
);
1181 void wxComboBoxPropertyInfo::GetPropertyNames(wxStringList
& names
)
1183 wxItemPropertyInfo::GetPropertyNames(names
);
1184 names
.Add("values");
1189 bool wxComboBoxPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1191 wxComboBox
*choice
= (wxComboBox
*)propertyWindow
;
1193 if (choice
->Number() == 0)
1194 resource
->SetStringValues(NULL
);
1197 wxStringList
*slist
= new wxStringList
;
1199 for (i
= 0; i
< choice
->Number(); i
++)
1200 slist
->Add(choice
->GetString(i
));
1202 resource
->SetStringValues(slist
);
1204 return wxItemPropertyInfo::InstantiateResource(resource
);
1211 wxProperty
*wxRadioBoxPropertyInfo::GetProperty(wxString
& name
)
1213 wxRadioBox
*radioBox
= (wxRadioBox
*)propertyWindow
;
1214 if (name
== "numberRowsOrCols")
1216 return new wxProperty("numberRowsOrCols", (long)radioBox
->GetNumberOfRowsOrCols(), "integer");
1218 if (name
== "orientation")
1221 if (propertyWindow
->GetWindowStyleFlag() & wxHORIZONTAL
)
1222 pos
= "wxHORIZONTAL";
1226 return new wxProperty("orientation", pos
, "string",
1227 new wxStringListValidator(new wxStringList("wxHORIZONTAL", "wxVERTICAL",
1230 else if (name
== "values")
1232 wxStringList
*stringList
= new wxStringList
;
1234 for (i
= 0; i
< radioBox
->Number(); i
++)
1235 stringList
->Add(radioBox
->GetString(i
));
1237 return new wxProperty(name
, stringList
, "stringlist");
1239 return wxItemPropertyInfo::GetProperty(name
);
1242 bool wxRadioBoxPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1244 wxRadioBox
*radioBox
= (wxRadioBox
*)propertyWindow
;
1245 if (name
== "numberRowsOrCols")
1247 radioBox
->SetNumberOfRowsOrCols((int)property
->GetValue().IntegerValue());
1248 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox
, this);
1251 else if (name
== "orientation")
1253 long windowStyle
= radioBox
->GetWindowStyleFlag();
1254 wxString
val(property
->GetValue().StringValue());
1255 if (val
== "wxHORIZONTAL")
1257 if (windowStyle
& wxVERTICAL
)
1258 windowStyle
-= wxVERTICAL
;
1259 windowStyle
|= wxHORIZONTAL
;
1263 if (windowStyle
& wxHORIZONTAL
)
1264 windowStyle
-= wxHORIZONTAL
;
1265 windowStyle
|= wxVERTICAL
;
1267 radioBox
->SetWindowStyleFlag(windowStyle
);
1269 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox
, this);
1272 else if (name
== "values")
1274 // Set property into *resource*, not wxRadioBox, and then recreate
1275 // the wxRadioBox. This is because we can't dynamically set the strings
1277 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(propertyWindow
);
1281 wxStringList
*stringList
= resource
->GetStringValues();
1284 stringList
= new wxStringList
;
1285 resource
->SetStringValues(stringList
);
1287 stringList
->Clear();
1289 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
1292 char *s
= expr
->StringValue();
1295 expr
= expr
->GetNext();
1297 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox
, this);
1300 return wxItemPropertyInfo::SetProperty(name
, property
);
1303 void wxRadioBoxPropertyInfo::GetPropertyNames(wxStringList
& names
)
1305 wxItemPropertyInfo::GetPropertyNames(names
);
1307 names
.Add("values");
1308 names
.Add("orientation");
1309 names
.Add("numberRowsOrCols");
1312 bool wxRadioBoxPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1314 wxRadioBox
*rbox
= (wxRadioBox
*)propertyWindow
;
1315 // Take strings from resource instead
1318 if (rbox->Number() == 0)
1319 resource->SetStringValues(NULL);
1322 wxStringList *slist = new wxStringList;
1324 for (i = 0; i < rbox->Number(); i++)
1325 slist->Add(rbox->GetString(i));
1327 resource->SetStringValues(slist);
1330 resource
->SetValue1(rbox
->GetNumberOfRowsOrCols());
1331 return wxItemPropertyInfo::InstantiateResource(resource
);
1338 wxProperty
*wxGroupBoxPropertyInfo::GetProperty(wxString
& name
)
1340 wxStaticBox
*groupBox
= (wxStaticBox
*)propertyWindow
;
1341 return wxItemPropertyInfo::GetProperty(name
);
1344 bool wxGroupBoxPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1346 return wxItemPropertyInfo::SetProperty(name
, property
);
1349 void wxGroupBoxPropertyInfo::GetPropertyNames(wxStringList
& names
)
1351 wxItemPropertyInfo::GetPropertyNames(names
);
1355 bool wxGroupBoxPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1357 wxStaticBox
*gbox
= (wxStaticBox
*)propertyWindow
;
1358 return wxItemPropertyInfo::InstantiateResource(resource
);
1365 wxProperty
*wxCheckBoxPropertyInfo::GetProperty(wxString
& name
)
1367 wxCheckBox
*checkBox
= (wxCheckBox
*)propertyWindow
;
1368 if (name
== "value")
1369 return new wxProperty("value", checkBox
->GetValue(), "bool");
1371 return wxItemPropertyInfo::GetProperty(name
);
1374 bool wxCheckBoxPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1376 wxCheckBox
*checkBox
= (wxCheckBox
*)propertyWindow
;
1377 if (name
== "value")
1379 checkBox
->SetValue((bool)property
->GetValue().BoolValue());
1383 return wxItemPropertyInfo::SetProperty(name
, property
);
1386 void wxCheckBoxPropertyInfo::GetPropertyNames(wxStringList
& names
)
1388 wxItemPropertyInfo::GetPropertyNames(names
);
1393 bool wxCheckBoxPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1395 wxCheckBox
*cbox
= (wxCheckBox
*)propertyWindow
;
1396 resource
->SetValue1(cbox
->GetValue());
1397 return wxItemPropertyInfo::InstantiateResource(resource
);
1404 wxProperty
*wxRadioButtonPropertyInfo::GetProperty(wxString
& name
)
1406 wxRadioButton
*checkBox
= (wxRadioButton
*)propertyWindow
;
1407 if (name
== "value")
1408 return new wxProperty("value", checkBox
->GetValue(), "bool");
1410 return wxItemPropertyInfo::GetProperty(name
);
1413 bool wxRadioButtonPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1415 wxRadioButton
*checkBox
= (wxRadioButton
*)propertyWindow
;
1416 if (name
== "value")
1418 checkBox
->SetValue((bool)property
->GetValue().BoolValue());
1422 return wxItemPropertyInfo::SetProperty(name
, property
);
1425 void wxRadioButtonPropertyInfo::GetPropertyNames(wxStringList
& names
)
1427 wxItemPropertyInfo::GetPropertyNames(names
);
1432 bool wxRadioButtonPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1434 wxRadioButton
*cbox
= (wxRadioButton
*)propertyWindow
;
1435 resource
->SetValue1(cbox
->GetValue());
1436 return wxItemPropertyInfo::InstantiateResource(resource
);
1443 wxProperty
*wxSliderPropertyInfo::GetProperty(wxString
& name
)
1445 wxSlider
*slider
= (wxSlider
*)propertyWindow
;
1446 if (name
== "value")
1447 return new wxProperty("value", (long)slider
->GetValue(), "integer");
1448 else if (name
== "orientation")
1451 if (propertyWindow
->GetWindowStyleFlag() & wxHORIZONTAL
)
1452 pos
= "wxHORIZONTAL";
1456 return new wxProperty("orientation", pos
, "string",
1457 new wxStringListValidator(new wxStringList("wxHORIZONTAL", "wxVERTICAL",
1460 else if (name
== "minValue")
1461 return new wxProperty("minValue", (long)slider
->GetMin(), "integer");
1462 else if (name
== "maxValue")
1463 return new wxProperty("maxValue", (long)slider
->GetMax(), "integer");
1465 return wxItemPropertyInfo::GetProperty(name
);
1468 bool wxSliderPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1470 wxSlider
*slider
= (wxSlider
*)propertyWindow
;
1471 if (name
== "value")
1473 slider
->SetValue((int)property
->GetValue().IntegerValue());
1476 else if (name
== "orientation")
1478 long windowStyle
= slider
->GetWindowStyleFlag();
1479 long oldWindowStyle
= windowStyle
;
1480 wxString
val(property
->GetValue().StringValue());
1481 if (val
== "wxHORIZONTAL")
1483 if (windowStyle
& wxVERTICAL
)
1484 windowStyle
-= wxVERTICAL
;
1485 windowStyle
|= wxHORIZONTAL
;
1489 if (windowStyle
& wxHORIZONTAL
)
1490 windowStyle
-= wxHORIZONTAL
;
1491 windowStyle
|= wxVERTICAL
;
1494 if (oldWindowStyle
== windowStyle
)
1497 slider
->SetWindowStyleFlag(windowStyle
);
1499 // If the window style has changed, we swap the width and height parameters.
1501 slider
->GetSize(&w
, &h
);
1503 slider
= (wxSlider
*)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(slider
, this);
1504 slider
->SetSize(-1, -1, h
, w
);
1508 else if (name
== "minValue")
1510 slider
->SetRange((int)property
->GetValue().IntegerValue(), slider
->GetMax());
1513 else if (name
== "maxValue")
1515 slider
->SetRange(slider
->GetMin(), (int)property
->GetValue().IntegerValue());
1519 return wxItemPropertyInfo::SetProperty(name
, property
);
1522 void wxSliderPropertyInfo::GetPropertyNames(wxStringList
& names
)
1524 wxItemPropertyInfo::GetPropertyNames(names
);
1526 names
.Add("orientation");
1527 names
.Add("minValue");
1528 names
.Add("maxValue");
1531 bool wxSliderPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1533 wxSlider
*slider
= (wxSlider
*)propertyWindow
;
1534 resource
->SetValue1(slider
->GetValue());
1535 resource
->SetValue2(slider
->GetMin());
1536 resource
->SetValue3(slider
->GetMax());
1537 return wxItemPropertyInfo::InstantiateResource(resource
);
1544 wxProperty
*wxGaugePropertyInfo::GetProperty(wxString
& name
)
1546 wxGauge
*gauge
= (wxGauge
*)propertyWindow
;
1547 if (name
== "value")
1548 return new wxProperty("value", (long)gauge
->GetValue(), "integer");
1549 else if (name
== "maxValue")
1550 return new wxProperty("maxValue", (long)gauge
->GetRange(), "integer");
1552 return wxItemPropertyInfo::GetProperty(name
);
1555 bool wxGaugePropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1557 wxGauge
*gauge
= (wxGauge
*)propertyWindow
;
1558 if (name
== "value")
1560 gauge
->SetValue((int)property
->GetValue().IntegerValue());
1563 else if (name
== "maxValue")
1565 gauge
->SetRange((int)property
->GetValue().IntegerValue());
1569 return wxItemPropertyInfo::SetProperty(name
, property
);
1572 void wxGaugePropertyInfo::GetPropertyNames(wxStringList
& names
)
1574 wxItemPropertyInfo::GetPropertyNames(names
);
1576 names
.Add("maxValue");
1579 bool wxGaugePropertyInfo::InstantiateResource(wxItemResource
*resource
)
1581 wxGauge
*gauge
= (wxGauge
*)propertyWindow
;
1582 resource
->SetValue1(gauge
->GetValue());
1583 resource
->SetValue2(gauge
->GetRange());
1584 return wxItemPropertyInfo::InstantiateResource(resource
);
1591 wxProperty
*wxScrollBarPropertyInfo::GetProperty(wxString
& name
)
1593 wxScrollBar
*scrollBar
= (wxScrollBar
*)propertyWindow
;
1594 if (name
== "value")
1595 return new wxProperty("value", (long)scrollBar
->GetValue(), "integer");
1596 else if (name
== "orientation")
1599 if (propertyWindow
->GetWindowStyleFlag() & wxHORIZONTAL
)
1600 pos
= "wxHORIZONTAL";
1604 return new wxProperty("orientation", pos
, "string",
1605 new wxStringListValidator(new wxStringList("wxHORIZONTAL", "wxVERTICAL",
1608 else if (name
== "pageSize")
1610 int viewStart
, pageLength
, objectLength
, viewLength
;
1611 scrollBar
->GetValues(&viewStart
, &viewLength
, &objectLength
, &pageLength
);
1613 return new wxProperty("pageSize", (long)pageLength
, "integer");
1615 else if (name
== "viewLength")
1617 int viewStart
, pageLength
, objectLength
, viewLength
;
1618 scrollBar
->GetValues(&viewStart
, &viewLength
, &objectLength
, &pageLength
);
1620 return new wxProperty("viewLength", (long)viewLength
, "integer");
1622 else if (name
== "objectLength")
1624 int viewStart
, pageLength
, objectLength
, viewLength
;
1625 scrollBar
->GetValues(&viewStart
, &viewLength
, &objectLength
, &pageLength
);
1627 return new wxProperty("objectLength", (long)objectLength
, "integer");
1630 return wxItemPropertyInfo::GetProperty(name
);
1633 bool wxScrollBarPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1635 wxScrollBar
*scrollBar
= (wxScrollBar
*)propertyWindow
;
1636 if (name
== "value")
1638 scrollBar
->SetValue((int)property
->GetValue().IntegerValue());
1641 else if (name
== "orientation")
1643 long windowStyle
= scrollBar
->GetWindowStyleFlag();
1644 long oldWindowStyle
= windowStyle
;
1645 wxString
val(property
->GetValue().StringValue());
1646 if (val
== "wxHORIZONTAL")
1648 if (windowStyle
& wxVERTICAL
)
1649 windowStyle
-= wxVERTICAL
;
1650 windowStyle
|= wxHORIZONTAL
;
1654 if (windowStyle
& wxHORIZONTAL
)
1655 windowStyle
-= wxHORIZONTAL
;
1656 windowStyle
|= wxVERTICAL
;
1659 if (oldWindowStyle
== windowStyle
)
1662 scrollBar
->SetWindowStyleFlag(windowStyle
);
1664 // If the window style has changed, we swap the width and height parameters.
1666 scrollBar
->GetSize(&w
, &h
);
1668 scrollBar
= (wxScrollBar
*)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(scrollBar
, this);
1669 scrollBar
->SetSize(-1, -1, h
, w
);
1673 else if (name
== "pageSize")
1675 scrollBar
->SetPageSize((int)property
->GetValue().IntegerValue());
1678 else if (name
== "viewLength")
1680 scrollBar
->SetViewLength((int)property
->GetValue().IntegerValue());
1683 else if (name
== "objectLength")
1685 scrollBar
->SetObjectLength((int)property
->GetValue().IntegerValue());
1689 return wxItemPropertyInfo::SetProperty(name
, property
);
1692 void wxScrollBarPropertyInfo::GetPropertyNames(wxStringList
& names
)
1694 wxItemPropertyInfo::GetPropertyNames(names
);
1695 names
.Add("orientation");
1697 names
.Add("pageSize");
1698 names
.Add("viewLength");
1699 names
.Add("objectLength");
1701 // Remove some properties we don't inherit
1702 names
.Delete("fontPoints");
1703 names
.Delete("fontFamily");
1704 names
.Delete("fontStyle");
1705 names
.Delete("fontWeight");
1706 names
.Delete("fontUnderlined");
1709 bool wxScrollBarPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1711 wxScrollBar
*sbar
= (wxScrollBar
*)propertyWindow
;
1713 resource
->SetValue1(sbar
->GetValue());
1715 int viewStart
, pageLength
, objectLength
, viewLength
;
1716 sbar
->GetValues(&viewStart
, &viewLength
, &objectLength
, &pageLength
);
1718 resource
->SetValue2(pageLength
);
1719 resource
->SetValue3(objectLength
);
1720 resource
->SetValue5(viewLength
);
1722 return wxItemPropertyInfo::InstantiateResource(resource
);
1729 wxProperty
*wxPanelPropertyInfo::GetProperty(wxString
& name
)
1731 wxPanel
*panelWindow
= (wxPanel
*)propertyWindow
;
1732 wxFont
*labelFont
= panelWindow
->GetLabelFont();
1733 wxFont
*buttonFont
= panelWindow
->GetButtonFont();
1735 if (name
== "labelFontPoints" || name
== "labelFontFamily" || name
== "labelFontStyle" || name
== "labelFontWeight" ||
1736 name
== "labelFontUnderlined")
1737 return GetFontProperty(name
, labelFont
);
1738 else if (name
== "buttonFontPoints" || name
== "buttonFontFamily" || name
== "buttonFontStyle" || name
== "buttonFontWeight" ||
1739 name
== "buttonFontUnderlined")
1740 return GetFontProperty(name
, buttonFont
);
1741 else if (name
== "no3D")
1744 if (panelWindow
->GetWindowStyleFlag() & wxNO_3D
)
1747 userColours
= FALSE
;
1749 return new wxProperty(name
, (bool)userColours
, "bool");
1751 else if (name
== "backgroundColour")
1753 wxColour
col(panelWindow
->GetBackgroundColour());
1755 wxDecToHex(col
.Red(), buf
);
1756 wxDecToHex(col
.Green(), buf
+2);
1757 wxDecToHex(col
.Blue(), buf
+4);
1759 return new wxProperty(name
, buf
, "string", new wxColourListValidator
);
1761 else if (name
== "title")
1763 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
1765 return new wxProperty(name
, resource
->GetTitle(), "string");
1767 return new wxProperty(name
, "Could not get title", "string");
1769 else if (name
== "caption")
1771 return new wxProperty(name
, ((panelWindow
->GetWindowStyleFlag() & wxCAPTION
) == wxCAPTION
),
1774 else if (name
== "systemMenu")
1776 return new wxProperty(name
, ((panelWindow
->GetWindowStyleFlag() & wxSYSTEM_MENU
) == wxSYSTEM_MENU
),
1779 else if (name
== "thickFrame")
1781 return new wxProperty(name
, ((panelWindow
->GetWindowStyleFlag() & wxTHICK_FRAME
) == wxTHICK_FRAME
),
1785 return wxWindowPropertyInfo::GetProperty(name
);
1788 bool wxPanelPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1790 wxPanel
*panelWindow
= (wxPanel
*)propertyWindow
;
1791 wxFont
*labelFont
= panelWindow
->GetLabelFont();
1792 wxFont
*buttonFont
= panelWindow
->GetButtonFont();
1794 if (labelFont
&& (name
== "labelFontPoints" || name
== "labelFontFamily" || name
== "labelFontStyle" || name
== "labelFontWeight" || name
== "labelFontUnderlined" ))
1796 wxFont
*newFont
= SetFontProperty(name
, property
, labelFont
);
1798 panelWindow
->SetLabelFont(newFont
);
1801 else if (buttonFont
&& (name
== "buttonFontPoints" || name
== "buttonFontFamily" || name
== "buttonFontStyle" || name
== "buttonFontWeight" || name
== "buttonFontUnderlined" ))
1803 wxFont
*newFont
= SetFontProperty(name
, property
, buttonFont
);
1805 panelWindow
->SetButtonFont(newFont
);
1808 else if (name
== "no3D")
1810 bool userColours
= property
->GetValue().BoolValue();
1811 long flag
= panelWindow
->GetWindowStyleFlag();
1815 if ((panelWindow
->GetWindowStyleFlag() & wxNO_3D
) != wxNO_3D
)
1816 panelWindow
->SetWindowStyleFlag(panelWindow
->GetWindowStyleFlag() | wxNO_3D
);
1820 if ((panelWindow
->GetWindowStyleFlag() & wxNO_3D
) == wxNO_3D
)
1821 panelWindow
->SetWindowStyleFlag(panelWindow
->GetWindowStyleFlag() - wxNO_3D
);
1823 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
1824 resource
->SetStyle(panelWindow
->GetWindowStyleFlag());
1826 panelWindow
= (wxPanel
*)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(panelWindow
, this);
1829 else if (name
== "backgroundColour")
1831 char *hex
= property
->GetValue().StringValue();
1832 int r
= wxHexToDec(hex
);
1833 int g
= wxHexToDec(hex
+2);
1834 int b
= wxHexToDec(hex
+4);
1836 wxColour
col(r
,g
,b
);
1837 panelWindow
->SetBackgroundColour(col
);
1838 panelWindow
= (wxPanel
*)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(panelWindow
, this);
1841 else if (name
== "title")
1843 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
1846 resource
->SetTitle(property
->GetValue().StringValue());
1852 else if (name
== "caption")
1854 SetWindowStyle(panelWindow
, wxCAPTION
, property
->GetValue().BoolValue());
1856 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
1857 resource
->SetStyle(panelWindow
->GetWindowStyleFlag());
1860 else if (name
== "thickFrame")
1862 SetWindowStyle(panelWindow
, wxTHICK_FRAME
, property
->GetValue().BoolValue());
1864 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
1865 resource
->SetStyle(panelWindow
->GetWindowStyleFlag());
1868 else if (name
== "systemMenu")
1870 SetWindowStyle(panelWindow
, wxSYSTEM_MENU
, property
->GetValue().BoolValue());
1872 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
1873 resource
->SetStyle(panelWindow
->GetWindowStyleFlag());
1877 return wxWindowPropertyInfo::SetProperty(name
, property
);
1880 void wxPanelPropertyInfo::GetPropertyNames(wxStringList
& names
)
1882 wxWindowPropertyInfo::GetPropertyNames(names
);
1886 names
.Add("backgroundColour");
1887 names
.Add("caption");
1888 names
.Add("systemMenu");
1889 names
.Add("thickFrame");
1892 bool wxPanelPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1894 wxPanel
*panel
= (wxPanel
*)propertyWindow
;
1895 if (panel
->GetFont())
1896 resource
->SetFont(wxTheFontList
->FindOrCreateFont(panel
->GetFont()->GetPointSize(),
1897 panel
->GetFont()->GetFamily(), panel
->GetFont()->GetStyle(), panel
->GetFont()->GetWeight(),
1898 panel
->GetFont()->GetUnderlined(), panel
->GetFont()->GetFaceName()));
1900 resource
->SetBackgroundColour(new wxColour(panel
->GetBackgroundColour()));
1902 return wxWindowPropertyInfo::InstantiateResource(resource
);
1910 wxProperty
*wxDialogPropertyInfo::GetProperty(wxString
& name
)
1912 wxDialog
*dialogWindow
= (wxDialog
*)propertyWindow
;
1913 if (name
== "modal")
1915 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(dialogWindow
);
1919 bool modal
= (resource
->GetValue1() != 0);
1920 return new wxProperty(name
, modal
, "bool");
1923 return wxPanelPropertyInfo::GetProperty(name
);
1926 bool wxDialogPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1928 wxDialog
*dialogWindow
= (wxDialog
*)propertyWindow
;
1930 if (name
== "modal")
1932 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(dialogWindow
);
1936 resource
->SetValue1(property
->GetValue().BoolValue());
1940 return wxPanelPropertyInfo::SetProperty(name
, property
);
1943 void wxDialogPropertyInfo::GetPropertyNames(wxStringList
& names
)
1945 wxPanelPropertyInfo::GetPropertyNames(names
);
1950 bool wxDialogPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1952 wxDialog
*dialog
= (wxDialog
*)propertyWindow
;
1953 wxString
str(dialog
->GetTitle());
1954 resource
->SetTitle(WXSTRINGCAST str
);
1956 return wxPanelPropertyInfo::InstantiateResource(resource
);
1964 int wxStringToFontWeight(wxString
& val
)
1966 if (val
== "wxBOLD") return wxBOLD
;
1967 else if (val
== "wxLIGHT") return wxLIGHT
;
1968 else return wxNORMAL
;
1971 int wxStringToFontStyle(wxString
& val
)
1973 if (val
== "wxITALIC") return wxITALIC
;
1974 else if (val
== "wxSLANT") return wxSLANT
;
1975 else return wxNORMAL
;
1978 int wxStringToFontFamily(wxString
& val
)
1980 if (val
== "wxDECORATIVE") return wxDECORATIVE
;
1981 else if (val
== "wxROMAN") return wxROMAN
;
1982 else if (val
== "wxSCRIPT") return wxSCRIPT
;
1983 else if (val
== "wxMODERN") return wxMODERN
;
1984 else if (val
== "wxTELETYPE") return wxTELETYPE
;
1985 else return wxSWISS
;
1989 /// Resource symbol validator
1991 IMPLEMENT_DYNAMIC_CLASS(wxResourceSymbolValidator
, wxPropertyListValidator
)
1993 wxResourceSymbolValidator::wxResourceSymbolValidator(long flags
):
1994 wxPropertyListValidator(flags
)
1998 wxResourceSymbolValidator::~wxResourceSymbolValidator(void)
2002 bool wxResourceSymbolValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
2007 // Called when TICK is pressed or focus is lost or view wants to update
2008 // the property list.
2009 // Does the transferance from the property editing area to the property itself
2010 bool wxResourceSymbolValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
2012 if (!view
->GetValueText())
2014 wxString
value(view
->GetValueText()->GetValue());
2015 property
->GetValue() = value
;
2019 // Called when TICK is pressed or focus is lost or view wants to update
2020 // the property list.
2021 // Does the transferance from the property editing area to the property itself
2022 bool wxResourceSymbolValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
2024 if (!view
->GetValueText())
2026 wxString
str(property
->GetValue().GetStringRepresentation());
2027 view
->GetValueText()->SetValue(str
);
2031 // Called when the property is double clicked. Extra functionality can be provided,
2032 // cycling through possible values.
2033 bool wxResourceSymbolValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
2035 if (!view
->GetValueText())
2037 OnEdit(property
, view
, parentWindow
);
2041 bool wxResourceSymbolValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
2043 if (view
->GetConfirmButton())
2044 view
->GetConfirmButton()->Enable(TRUE
);
2045 if (view
->GetCancelButton())
2046 view
->GetCancelButton()->Enable(TRUE
);
2047 if (view
->GetEditButton())
2048 view
->GetEditButton()->Enable(TRUE
);
2049 if (view
->GetValueText())
2050 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
2054 void wxResourceSymbolValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
2056 if (!view
->GetValueText())
2059 wxResourceSymbolDialog
* dialog
= new wxResourceSymbolDialog(parentWindow
, -1, "Edit Symbol");
2061 // Split name/id pair e.g. "IDC_TEXT=123"
2062 wxString
value(property
->GetValue().StringValue());
2064 wxString strName
= value
.Before('=');
2065 wxString strId
= value
.After('=');
2067 dialog
->SetSymbol(strName
);
2068 dialog
->SetId(atoi(strId
));
2072 if (dialog
->ShowModal() == wxID_OK
)
2074 wxString
symbolName(dialog
->GetSymbol());
2075 long id
= dialog
->GetId();
2079 str
.Printf("%d", id
);
2080 property
->GetValue() = symbolName
+ wxString("=") + str
;
2082 view
->DisplayProperty(property
);
2083 view
->UpdatePropertyDisplayInList(property
);
2084 view
->OnPropertyChanged(property
);
2088 BEGIN_EVENT_TABLE(wxResourceSymbolDialog
, wxDialog
)
2089 EVT_BUTTON(wxID_OK
, wxResourceSymbolDialog::OnOK
)
2090 EVT_COMBOBOX(ID_SYMBOLNAME_COMBOBOX
, wxResourceSymbolDialog::OnComboBoxSelect
)
2091 EVT_TEXT(ID_SYMBOLNAME_COMBOBOX
, wxResourceSymbolDialog::OnSymbolNameUpdate
)
2094 wxResourceSymbolDialog::wxResourceSymbolDialog(wxWindow
* parent
, const wxWindowID id
, const wxString
& title
, const wxPoint
& pos
,
2095 const wxSize
& size
, long style
):
2096 wxDialog(parent
, id
, title
, pos
, size
, style
)
2101 (void) new wxStaticText(this, -1, "Name: ", wxPoint(x
, y
));
2105 m_nameCtrl
= new wxComboBox(this, ID_SYMBOLNAME_COMBOBOX
, "",
2106 wxPoint(x
, y
), wxSize(200, -1), 0, NULL
, wxCB_DROPDOWN
|wxCB_SORT
);
2111 (void) new wxStaticText(this, -1, "Id: ", wxPoint(x
, y
));
2115 m_idCtrl
= new wxTextCtrl(this, ID_SYMBOLID_TEXTCTRL
, "",
2116 wxPoint(x
, y
), wxSize(200, -1));
2120 (void) new wxButton(this, wxID_OK
, "OK", wxPoint(x
, y
), wxSize(80, -1));
2123 (void) new wxButton(this, wxID_CANCEL
, "Cancel", wxPoint(x
, y
), wxSize(80, -1));
2129 void wxResourceSymbolDialog::Init()
2132 defaultId
.Printf("%ld", m_symbolId
);
2134 m_nameCtrl
->SetValue(m_symbolName
);
2135 m_idCtrl
->SetValue(defaultId
);
2137 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().FillComboBox(m_nameCtrl
);
2140 void wxResourceSymbolDialog::OnOK(wxCommandEvent
& event
)
2144 wxDialog::OnOK(event
);
2148 bool wxResourceSymbolDialog::CheckValues()
2150 wxString
nameStr(m_nameCtrl
->GetValue());
2151 wxString
idStr(m_idCtrl
->GetValue());
2152 int id
= atoi(idStr
);
2156 wxMessageBox("Identifier cannot be missing or zero", "Dialog Editor", wxOK
|wxICON_EXCLAMATION
, this);
2161 wxMessageBox("Please enter a symbol name", "Dialog Editor", wxOK
|wxICON_EXCLAMATION
, this);
2164 if (nameStr
.Contains(" "))
2166 wxMessageBox("Symbol name cannot contain spaces.", "Dialog Editor", wxOK
|wxICON_EXCLAMATION
, this);
2169 if (nameStr
.Contains("="))
2171 wxMessageBox("Symbol name cannot contain =.", "Dialog Editor", wxOK
|wxICON_EXCLAMATION
, this);
2174 if (nameStr
.IsNumber())
2176 wxMessageBox("Symbol name cannot be a number.", "Dialog Editor", wxOK
|wxICON_EXCLAMATION
, this);
2179 // TODO: other checks on the name syntax.
2181 if (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(nameStr
))
2183 // If we change the id for an existing symbol, we need to:
2184 // 1) Check if there are any other resources currently using the original id.
2185 // If so, will need to change their id to the new id, in SetProperty.
2186 // 2) Remove the old symbol, add the new symbol.
2187 // In this check, we don't have to do this, but we need to do it in SetProperty.
2189 if (nameStr
== GetSymbol() && id
!= GetId())
2191 // It's OK to change the id. But we'll need to change all matching ids in all resources,
2195 // If we change the name but not the id... we'll just need to remove and
2196 // re-add the symbol/id pair, in SetProperty.
2197 if (nameStr
!= GetSymbol() && id
== GetId())
2201 // What if we're changing both the name and the id?
2202 // - if there's no symbol of that name, just remove the old, add the new (in SetProperty)
2203 // - if there is a symbol of that name, if id matches, do nothing. If not, veto.
2205 if (nameStr
!= GetSymbol() && id
!= GetId())
2207 if (!wxResourceManager::GetCurrentResourceManager()->IsIdentifierOK(nameStr
, id
))
2209 wxMessageBox("This integer id is already being used under a different name.\nPlease choose another.",
2210 "Dialog Editor", wxOK
|wxICON_EXCLAMATION
, this);
2223 void wxResourceSymbolDialog::OnComboBoxSelect(wxCommandEvent
& event
)
2225 wxString
str(m_nameCtrl
->GetStringSelection());
2226 if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(str
))
2228 int id
= wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str
);
2230 str2
.Printf("%d", id
);
2231 m_idCtrl
->SetValue(str2
);
2232 m_idCtrl
->Enable(FALSE
);
2236 if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().SymbolExists(str
))
2238 int id
= wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str
);
2240 str2
.Printf("%d", id
);
2241 m_idCtrl
->SetValue(str2
);
2243 m_idCtrl
->Enable(TRUE
);
2247 void wxResourceSymbolDialog::OnSymbolNameUpdate(wxCommandEvent
& event
)
2249 wxString
str(m_nameCtrl
->GetValue());
2250 if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(str
))
2252 int id
= wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str
);
2254 str2
.Printf("%d", id
);
2255 m_idCtrl
->SetValue(str2
);
2256 m_idCtrl
->Enable(FALSE
);
2260 if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().SymbolExists(str
))
2262 int id
= wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str
);
2264 str2
.Printf("%d", id
);
2265 m_idCtrl
->SetValue(str2
);
2267 m_idCtrl
->Enable(TRUE
);