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
77 wxDialogEditorPropertyListDialog::wxDialogEditorPropertyListDialog(wxPropertyListView
*v
, wxWindow
*parent
, const wxString
& title
,
78 const wxPoint
& pos
, const wxSize
& size
,
79 long style
, const wxString
& name
):
80 wxPropertyListDialog(v
, parent
, title
, pos
, size
, style
, name
)
86 wxDialogEditorPropertyListDialog::~wxDialogEditorPropertyListDialog()
90 wxPropertyInfo::sm_propertyWindow
= NULL
;
97 // Edit the information represented by this object, whatever that
99 bool wxPropertyInfo::Edit(wxWindow
*parent
, const wxString
& title
)
101 if (sm_propertyWindow
)
104 int width
= wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().width
;
105 int height
= wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().height
;
106 int x
= wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().x
;
107 int y
= wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().y
;
109 wxPropertySheet
*propSheet
= new wxPropertySheet
;
111 wxStringList propNames
;
112 GetPropertyNames(propNames
);
114 wxNode
*node
= propNames
.First();
117 wxString
name((char *)node
->Data());
118 wxProperty
*prop
= GetProperty(name
);
121 propSheet
->AddProperty(prop
);
126 // Reset 'modified' flags for all property values
127 propSheet
->SetAllModified(FALSE
);
129 wxResourcePropertyListView
*view
= new wxResourcePropertyListView(this, NULL
,
131 wxPROP_BUTTON_OK
| wxPROP_BUTTON_CANCEL
|
133 wxPROP_BUTTON_CHECK_CROSS
|wxPROP_DYNAMIC_VALUE_FIELD
|wxPROP_PULLDOWN
|wxPROP_SHOWVALUES
);
135 wxDialogEditorPropertyListDialog
*propDialog
= new wxDialogEditorPropertyListDialog(view
,
136 wxResourceManager::GetCurrentResourceManager()->GetEditorFrame(), title
, wxPoint(x
, y
),
137 wxSize(width
, height
), wxDEFAULT_DIALOG_STYLE
);
138 sm_propertyWindow
= propDialog
;
140 propDialog
->m_registry
.RegisterValidator((wxString
)"real", new wxRealListValidator
);
141 propDialog
->m_registry
.RegisterValidator((wxString
)"string", new wxStringListValidator
);
142 propDialog
->m_registry
.RegisterValidator((wxString
)"integer", new wxIntegerListValidator
);
143 propDialog
->m_registry
.RegisterValidator((wxString
)"bool", new wxBoolListValidator
);
144 propDialog
->m_registry
.RegisterValidator((wxString
)"filename", new wxFilenameListValidator
);
145 propDialog
->m_registry
.RegisterValidator((wxString
)"stringlist", new wxListOfStringsListValidator
);
146 propDialog
->m_registry
.RegisterValidator((wxString
)"window_id", new wxResourceSymbolValidator
);
148 propDialog
->m_propInfo
= this;
149 propDialog
->m_propSheet
= propSheet
;
151 // view->propertyWindow = propDialog;
152 view
->AddRegistry(&(propDialog
->m_registry
));
153 view
->ShowView(propSheet
, propDialog
);
155 propDialog
->Show(TRUE
);
160 * wxWindowPropertyInfo
163 wxWindowPropertyInfo::wxWindowPropertyInfo(wxWindow
*win
, wxItemResource
*res
)
165 propertyWindow
= win
;
166 propertyResource
= res
;
169 wxWindowPropertyInfo::~wxWindowPropertyInfo(void)
173 wxProperty
*wxWindowPropertyInfo::GetFontProperty(wxString
& name
, wxFont
*font
)
178 if (name
.Contains("Points"))
179 return new wxProperty(name
, (long)font
->GetPointSize(), "integer", new wxIntegerListValidator(1, 100));
180 else if (name
.Contains("Family"))
181 return new wxProperty(name
, font
->GetFamilyString(), "string",
182 new wxStringListValidator(new wxStringList("wxDECORATIVE", "wxROMAN", "wxSCRIPT", "wxSWISS", "wxMODERN",
184 else if (name
.Contains("Style"))
185 return new wxProperty(name
, font
->GetStyleString(), "string",
186 new wxStringListValidator(new wxStringList("wxNORMAL", "wxITALIC", "wxSLANT", NULL
)));
187 else if (name
.Contains("Weight"))
188 return new wxProperty(name
, font
->GetWeightString(), "string",
189 new wxStringListValidator(new wxStringList("wxNORMAL", "wxBOLD", "wxLIGHT", NULL
)));
190 else if (name
.Contains("Underlined"))
191 return new wxProperty(name
, (bool)font
->GetUnderlined(), "bool");
196 wxFont
*wxWindowPropertyInfo::SetFontProperty(wxString
& name
, wxProperty
*property
, wxFont
*font
)
199 int fontFamily
= wxMODERN
;
200 int fontStyle
= wxNORMAL
;
201 int fontWeight
= wxNORMAL
;
202 bool fontUnderlined
= FALSE
;
204 if (name
.Contains("Points"))
206 pointSize
= (int)property
->GetValue().IntegerValue();
207 if (font
&& (pointSize
== font
->GetPointSize()))
208 return NULL
; // No change
210 else if (font
) pointSize
= font
->GetPointSize();
212 if (name
.Contains("Family"))
214 wxString val
= property
->GetValue().StringValue();
215 fontFamily
= wxStringToFontFamily(val
);
217 if (font
&& (fontFamily
== font
->GetFamily()))
218 return NULL
; // No change
220 else if (font
) fontFamily
= font
->GetFamily();
222 if (name
.Contains("Style"))
224 wxString val
= property
->GetValue().StringValue();
225 fontStyle
= wxStringToFontStyle(val
);
227 if (font
&& (fontStyle
== font
->GetStyle()))
228 return NULL
; // No change
230 else if (font
) fontStyle
= font
->GetStyle();
231 if (name
.Contains("Weight"))
233 wxString val
= property
->GetValue().StringValue();
234 fontWeight
= wxStringToFontWeight(val
);
236 if (font
&& (fontWeight
== font
->GetWeight()))
237 return NULL
; // No change
239 else if (font
) fontWeight
= font
->GetWeight();
241 if (name
.Contains("Underlined"))
243 fontUnderlined
= property
->GetValue().BoolValue();
245 if (font
&& (fontUnderlined
== font
->GetUnderlined()))
246 return NULL
; // No change
248 else if (font
) fontUnderlined
= font
->GetUnderlined();
250 wxFont
*newFont
= wxTheFontList
->FindOrCreateFont(pointSize
, fontFamily
, fontStyle
, fontWeight
, fontUnderlined
);
259 wxProperty
*wxWindowPropertyInfo::GetProperty(wxString
& name
)
261 wxFont
*font
= propertyWindow
->GetFont();
262 if (name
== "fontPoints" || name
== "fontFamily" || name
== "fontStyle" || name
== "fontWeight" ||
263 name
== "fontUnderlined")
264 return GetFontProperty(name
, font
);
265 else if (name
== "name")
266 return new wxProperty("name", propertyWindow
->GetName(), "string");
267 else if (name
== "title")
268 return new wxProperty("title", propertyWindow
->GetTitle(), "string");
269 else if (name
== "x")
272 propertyWindow
->GetPosition(&x
, &y
);
273 return new wxProperty("x", (long)x
, "integer");
275 else if (name
== "y")
278 propertyWindow
->GetPosition(&x
, &y
);
279 return new wxProperty("y", (long)y
, "integer");
281 else if (name
== "width")
284 propertyWindow
->GetSize(&width
, &height
);
285 return new wxProperty("width", (long)width
, "integer");
287 else if (name
== "height")
290 propertyWindow
->GetSize(&width
, &height
);
291 return new wxProperty("height", (long)height
, "integer");
293 else if (name
== "id")
295 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(propertyWindow
);
298 int id
= resource
->GetId();
300 idStr
.Printf("%d", id
);
301 wxString symbolName
= wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetSymbolForId(id
);
304 // symbolName is now e.g. "ID_PANEL21=105"
305 return new wxProperty("id", symbolName
, "window_id");
314 bool wxWindowPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
316 wxFont
*font
= propertyWindow
->GetFont();
317 if (font
&& (name
== "fontPoints" || name
== "fontFamily" || name
== "fontStyle" || name
== "fontWeight" || name
== "fontUnderlined" ))
319 wxFont
*newFont
= SetFontProperty(name
, property
, font
);
321 propertyWindow
->SetFont(newFont
);
324 else if (name
== "name")
326 // Remove old name from resource table, if it's there.
327 wxItemResource
*oldResource
= (wxItemResource
*)wxResourceManager::GetCurrentResourceManager()->GetResourceTable().Delete(propertyWindow
->GetName());
330 // It's a top-level resource
331 propertyWindow
->SetName(property
->GetValue().StringValue());
332 oldResource
->SetName(property
->GetValue().StringValue());
333 wxResourceManager::GetCurrentResourceManager()->GetResourceTable().Put(propertyWindow
->GetName(), oldResource
);
337 // It's a child of something; just set the name of the resource and the window.
338 propertyWindow
->SetName(property
->GetValue().StringValue());
339 propertyResource
->SetName(property
->GetValue().StringValue());
341 // Refresh the resource manager list, because the name changed.
342 wxResourceManager::GetCurrentResourceManager()->UpdateResourceList();
345 else if (name
== "title")
347 propertyWindow
->SetTitle(property
->GetValue().StringValue());
350 else if (name
== "x")
353 propertyWindow
->GetPosition(&x
, &y
);
354 int newX
= (int)property
->GetValue().IntegerValue();
356 propertyWindow
->Move(newX
, y
);
359 else if (name
== "y")
362 propertyWindow
->GetPosition(&x
, &y
);
363 int newY
= (int)property
->GetValue().IntegerValue();
365 propertyWindow
->Move(x
, newY
);
368 else if (name
== "width")
371 propertyWindow
->GetSize(&width
, &height
);
372 int newWidth
= (int)property
->GetValue().IntegerValue();
373 if (width
!= newWidth
)
375 propertyWindow
->SetSize(newWidth
, height
);
377 if (propertyWindow->IsKindOf(CLASSINFO(wxPanel)) && !propertyWindow->IsKindOf(CLASSINFO(wxDialog)))
379 propertyWindow->GetParent()->SetClientSize(newWidth, height);
385 else if (name
== "height")
388 propertyWindow
->GetSize(&width
, &height
);
389 int newHeight
= (int)property
->GetValue().IntegerValue();
390 if (height
!= newHeight
)
392 propertyWindow
->SetSize(width
, newHeight
);
394 if (propertyWindow->IsKindOf(CLASSINFO(wxPanel)) && !propertyWindow->IsKindOf(CLASSINFO(wxDialog)))
396 propertyWindow->GetParent()->SetClientSize(width, newHeight);
402 else if (name
== "id")
404 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(propertyWindow
);
407 wxString value
= property
->GetValue().StringValue();
409 wxString strName
= value
.Before('=');
410 wxString strId
= value
.After('=');
411 int id
= atoi(strId
);
413 wxString oldSymbolName
= wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetSymbolForId(resource
->GetId());
414 int oldSymbolId
= resource
->GetId();
418 // If we change the id for an existing symbol, we need to:
419 // 1) Check if there are any other resources currently using the original id.
420 // If so, will need to change their id to the new id.
421 // 2) Remove the old symbol, add the new symbol.
422 // In this check, we don't have to do this, but we need to do it in SetProperty.
424 if (strName
== oldSymbolName
&& id
!= oldSymbolId
)
426 wxASSERT( (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(oldSymbolName
)) );
428 // It's OK to change just the id. But we'll need to change all matching ids in all resources,
429 // because ids are unique and changing one resource's id must change all identical ones.
430 wxResourceManager::GetCurrentResourceManager()->ChangeIds(oldSymbolId
, id
);
432 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().RemoveSymbol(oldSymbolName
);
433 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().AddSymbol(strName
, id
);
436 // If we change the name but not the id, we'll just need to remove and
437 // re-add the symbol/id pair.
438 if (strName
!= oldSymbolName
&& id
== oldSymbolId
)
440 wxASSERT( (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(oldSymbolName
)) );
442 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().RemoveSymbol(oldSymbolName
);
444 if (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().SymbolExists(strName
))
446 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().AddSymbol(strName
, id
);
450 // What if we're changing both the name and the id?
451 // - if there's no symbol of that name, just remove the old, add the new (in SetProperty)
452 // - if there is a symbol of that name, if id matches, do nothing. If not, veto.
454 if (strName
!= oldSymbolName
&& id
!= oldSymbolId
)
456 // Remove old symbol if it's not being used
457 if (!wxResourceManager::GetCurrentResourceManager()->IsSymbolUsed(resource
, oldSymbolId
) &&
458 !wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(oldSymbolName
))
460 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().RemoveSymbol(oldSymbolName
);
463 if (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().SymbolExists(strName
))
465 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().AddSymbol(strName
, id
);
480 void wxWindowPropertyInfo::GetPropertyNames(wxStringList
& names
)
488 if (!propertyWindow
->IsKindOf(CLASSINFO(wxControl
)))
490 names
.Add("fontPoints");
491 names
.Add("fontFamily");
492 names
.Add("fontStyle");
493 names
.Add("fontWeight");
494 names
.Add("fontUnderlined");
498 // Fill in the wxItemResource members to mirror the current window settings
499 bool wxWindowPropertyInfo::InstantiateResource(wxItemResource
*resource
)
501 resource
->SetType(propertyWindow
->GetClassInfo()->GetClassName());
503 // resource->SetStyle(propertyWindow->GetWindowStyleFlag());
504 wxString
str(propertyWindow
->GetName());
505 resource
->SetName(WXSTRINGCAST str
);
507 propertyWindow
->GetSize(&w
, &h
);
509 propertyWindow
->GetPosition(&x
, &y
);
510 resource
->SetSize(x
, y
, w
, h
);
519 wxProperty
*wxItemPropertyInfo::GetProperty(wxString
& name
)
521 wxControl
*itemWindow
= (wxControl
*)propertyWindow
;
522 wxFont
*font
= itemWindow
->GetFont();
524 if (name
== "fontPoints" || name
== "fontFamily" || name
== "fontStyle" || name
== "fontWeight" ||
525 name
== "fontUnderlined")
526 return GetFontProperty(name
, font
);
527 else if (name
== "label" && itemWindow
->GetLabel())
528 return new wxProperty("label", propertyWindow
->GetLabel(), "string");
530 return wxWindowPropertyInfo::GetProperty(name
);
533 bool wxItemPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
535 wxControl
*itemWindow
= (wxControl
*)propertyWindow
;
536 wxFont
*font
= itemWindow
->GetFont();
538 if (font
&& (name
== "fontPoints" || name
== "fontFamily" || name
== "fontStyle" || name
== "fontWeight" || name
== "fontUnderlined" ))
540 wxFont
*newFont
= SetFontProperty(name
, property
, font
);
542 itemWindow
->SetLabelFont(newFont
);
545 else if (name
== "label")
547 itemWindow
->SetLabel(property
->GetValue().StringValue());
551 return wxWindowPropertyInfo::SetProperty(name
, property
);
554 void wxItemPropertyInfo::GetPropertyNames(wxStringList
& names
)
556 wxWindowPropertyInfo::GetPropertyNames(names
);
558 names
.Add("fontPoints");
559 names
.Add("fontFamily");
560 names
.Add("fontStyle");
561 names
.Add("fontWeight");
562 names
.Add("fontUnderlined");
565 bool wxItemPropertyInfo::InstantiateResource(wxItemResource
*resource
)
567 wxWindowPropertyInfo::InstantiateResource(resource
);
569 wxControl
*item
= (wxControl
*)propertyWindow
;
570 wxString
str(item
->GetLabel());
571 resource
->SetTitle(WXSTRINGCAST str
);
572 if (item
->GetFont() && item
->GetFont()->Ok())
573 resource
->SetFont(wxTheFontList
->FindOrCreateFont(item
->GetFont()->GetPointSize(),
574 item
->GetFont()->GetFamily(), item
->GetFont()->GetStyle(), item
->GetFont()->GetWeight(),
575 item
->GetFont()->GetUnderlined(), item
->GetFont()->GetFaceName()));
583 wxProperty
*wxButtonPropertyInfo::GetProperty(wxString
& name
)
585 wxButton
*button
= (wxButton
*)propertyWindow
;
586 return wxItemPropertyInfo::GetProperty(name
);
589 bool wxButtonPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
591 wxButton
*button
= (wxButton
*)propertyWindow
;
592 return wxItemPropertyInfo::SetProperty(name
, property
);
595 void wxButtonPropertyInfo::GetPropertyNames(wxStringList
& names
)
598 wxItemPropertyInfo::GetPropertyNames(names
);
601 bool wxButtonPropertyInfo::InstantiateResource(wxItemResource
*resource
)
603 return wxItemPropertyInfo::InstantiateResource(resource
);
610 wxProperty
*wxBitmapButtonPropertyInfo::GetProperty(wxString
& name
)
612 wxBitmapButton
*button
= (wxBitmapButton
*)propertyWindow
;
615 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(button
);
616 wxString
str("none.bmp");
620 char *filename
= wxResourceManager::GetCurrentResourceManager()->FindBitmapFilenameForResource(resource
);
624 return new wxProperty("label", str
.GetData(), "string", new wxFilenameListValidator("Select a bitmap file", "*.bmp"));
627 return wxButtonPropertyInfo::GetProperty(name
);
630 bool wxBitmapButtonPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
632 wxBitmapButton
*button
= (wxBitmapButton
*)propertyWindow
;
635 char *s
= property
->GetValue().StringValue();
636 if (s
&& wxFileExists(s
))
639 wxBitmap
*bitmap
= new wxBitmap(s
, wxBITMAP_TYPE_BMP
);
648 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(button
);
651 wxString
oldResource(resource
->GetValue4());
652 char *resName
= wxResourceManager::GetCurrentResourceManager()->AddBitmapResource(s
);
653 resource
->SetValue4(resName
);
655 if (!oldResource
.IsNull())
656 wxResourceManager::GetCurrentResourceManager()->PossiblyDeleteBitmapResource(WXSTRINGCAST oldResource
);
659 button
->SetLabel(bitmap
);
667 return wxButtonPropertyInfo::SetProperty(name
, property
);
670 void wxBitmapButtonPropertyInfo::GetPropertyNames(wxStringList
& names
)
672 // names.Add("label");
673 wxButtonPropertyInfo::GetPropertyNames(names
);
676 bool wxBitmapButtonPropertyInfo::InstantiateResource(wxItemResource
*resource
)
678 return wxItemPropertyInfo::InstantiateResource(resource
);
685 wxProperty
*wxStaticTextPropertyInfo::GetProperty(wxString
& name
)
687 wxStaticText
*message
= (wxStaticText
*)propertyWindow
;
688 return wxItemPropertyInfo::GetProperty(name
);
691 bool wxStaticTextPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
693 wxStaticText
*message
= (wxStaticText
*)propertyWindow
;
694 return wxItemPropertyInfo::SetProperty(name
, property
);
697 void wxStaticTextPropertyInfo::GetPropertyNames(wxStringList
& names
)
700 wxItemPropertyInfo::GetPropertyNames(names
);
703 bool wxStaticTextPropertyInfo::InstantiateResource(wxItemResource
*resource
)
705 return wxItemPropertyInfo::InstantiateResource(resource
);
712 wxProperty
*wxStaticBitmapPropertyInfo::GetProperty(wxString
& name
)
714 wxStaticBitmap
*message
= (wxStaticBitmap
*)propertyWindow
;
717 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(message
);
718 wxString
str("none.bmp");
722 char *filename
= wxResourceManager::GetCurrentResourceManager()->FindBitmapFilenameForResource(resource
);
726 return new wxProperty("label", str
.GetData(), "string", new wxFilenameListValidator("Select a bitmap file", "*.bmp"));
729 return wxItemPropertyInfo::GetProperty(name
);
732 bool wxStaticBitmapPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
734 wxStaticBitmap
*message
= (wxStaticBitmap
*)propertyWindow
;
737 char *s
= property
->GetValue().StringValue();
738 if (s
&& wxFileExists(s
))
742 wxBitmap
*bitmap
= new wxBitmap(s
, wxBITMAP_TYPE_BMP
);
751 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(message
);
754 wxString
oldResource(resource
->GetValue4());
755 char *resName
= wxResourceManager::GetCurrentResourceManager()->AddBitmapResource(s
);
756 resource
->SetValue4(resName
);
758 if (!oldResource
.IsNull())
759 wxResourceManager::GetCurrentResourceManager()->PossiblyDeleteBitmapResource(WXSTRINGCAST oldResource
);
762 message
->SetBitmap(bitmap
);
770 return wxItemPropertyInfo::SetProperty(name
, property
);
773 void wxStaticBitmapPropertyInfo::GetPropertyNames(wxStringList
& names
)
776 wxItemPropertyInfo::GetPropertyNames(names
);
779 bool wxStaticBitmapPropertyInfo::InstantiateResource(wxItemResource
*resource
)
781 return wxItemPropertyInfo::InstantiateResource(resource
);
788 wxProperty
*wxTextPropertyInfo::GetProperty(wxString
& name
)
790 wxTextCtrl
*text
= (wxTextCtrl
*)propertyWindow
;
792 return new wxProperty("value", text
->GetValue(), "string");
793 else if (name
== "password")
795 bool isPassword
= ((text
->GetWindowStyleFlag() & wxTE_PASSWORD
) == wxTE_PASSWORD
);
796 return new wxProperty("password", isPassword
, "bool");
798 else if (name
== "readonly")
800 bool isReadOnly
= ((text
->GetWindowStyleFlag() & wxTE_READONLY
) == wxTE_READONLY
);
801 return new wxProperty("readonly", isReadOnly
, "bool");
804 return wxItemPropertyInfo::GetProperty(name
);
807 bool wxTextPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
809 wxTextCtrl
*text
= (wxTextCtrl
*)propertyWindow
;
812 text
->SetValue(property
->GetValue().StringValue());
815 else if (name
== "password")
817 long flag
= text
->GetWindowStyleFlag();
818 if (property
->GetValue().BoolValue())
820 if ((flag
& wxTE_PASSWORD
) != wxTE_PASSWORD
)
821 flag
|= wxTE_PASSWORD
;
825 if ((flag
& wxTE_PASSWORD
) == wxTE_PASSWORD
)
826 flag
-= wxTE_PASSWORD
;
828 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(text
);
829 resource
->SetStyle(flag
);
831 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(text
, this);
834 else if (name
== "readonly")
836 long flag
= text
->GetWindowStyleFlag();
837 if (property
->GetValue().BoolValue())
839 if ((flag
& wxTE_READONLY
) != wxTE_READONLY
)
840 flag
|= wxTE_READONLY
;
844 if ((flag
& wxTE_READONLY
) == wxTE_READONLY
)
845 flag
-= wxTE_READONLY
;
847 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(text
);
848 resource
->SetStyle(flag
);
850 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(text
, this);
854 return wxItemPropertyInfo::SetProperty(name
, property
);
857 void wxTextPropertyInfo::GetPropertyNames(wxStringList
& names
)
860 names
.Add("readonly");
861 names
.Add("password");
862 wxItemPropertyInfo::GetPropertyNames(names
);
865 bool wxTextPropertyInfo::InstantiateResource(wxItemResource
*resource
)
867 wxTextCtrl
*text
= (wxTextCtrl
*)propertyWindow
;
868 wxString
str(text
->GetValue());
869 resource
->SetValue4(WXSTRINGCAST str
);
871 return wxItemPropertyInfo::InstantiateResource(resource
);
878 wxProperty
*wxListBoxPropertyInfo::GetProperty(wxString
& name
)
880 wxListBox
*listBox
= (wxListBox
*)propertyWindow
;
881 if (name
== "values")
883 wxStringList
*stringList
= new wxStringList
;
885 for (i
= 0; i
< listBox
->Number(); i
++)
886 stringList
->Add(listBox
->GetString(i
));
888 return new wxProperty(name
, stringList
, "stringlist");
890 else if (name
== "multiple")
893 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(listBox
);
897 char *mult
= "wxSINGLE";
899 switch (resource
->GetValue1())
902 mult
= "wxLB_MULTIPLE";
905 mult
= "wxLB_EXTENDED";
909 mult
= "wxLB_SINGLE";
912 return new wxProperty("multiple", mult
, "string",
913 new wxStringListValidator(new wxStringList("wxLB_SINGLE", "wxLB_MULTIPLE", "wxLB_EXTENDED",
917 return wxItemPropertyInfo::GetProperty(name
);
920 bool wxListBoxPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
922 wxListBox
*listBox
= (wxListBox
*)propertyWindow
;
923 if (name
== "values")
926 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
929 char *s
= expr
->StringValue();
932 expr
= expr
->GetNext();
936 else if (name
== "multiple")
938 int mult
= wxLB_SINGLE
;
939 wxString
str(property
->GetValue().StringValue());
940 if (str
== "wxLB_MULTIPLE")
941 mult
= wxLB_MULTIPLE
;
942 else if (str
== "wxLB_EXTENDED")
943 mult
= wxLB_EXTENDED
;
946 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(listBox
);
948 resource
->SetValue1(mult
);
949 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(listBox
, this);
953 return wxItemPropertyInfo::SetProperty(name
, property
);
956 void wxListBoxPropertyInfo::GetPropertyNames(wxStringList
& names
)
959 names
.Add("multiple");
960 wxItemPropertyInfo::GetPropertyNames(names
);
963 bool wxListBoxPropertyInfo::InstantiateResource(wxItemResource
*resource
)
965 wxListBox
*lbox
= (wxListBox
*)propertyWindow
;
966 // This will be set for the wxItemResource on reading or in SetProperty
967 // resource->SetValue1(lbox->GetSelectionMode());
969 if (lbox
->Number() == 0)
970 resource
->SetStringValues(NULL
);
973 wxStringList
*slist
= new wxStringList
;
975 for (i
= 0; i
< lbox
->Number(); i
++)
976 slist
->Add(lbox
->GetString(i
));
978 resource
->SetStringValues(slist
);
980 return wxItemPropertyInfo::InstantiateResource(resource
);
987 wxProperty
*wxChoicePropertyInfo::GetProperty(wxString
& name
)
989 wxChoice
*choice
= (wxChoice
*)propertyWindow
;
990 if (name
== "values")
992 wxStringList
*stringList
= new wxStringList
;
994 for (i
= 0; i
< choice
->Number(); i
++)
995 stringList
->Add(choice
->GetString(i
));
997 return new wxProperty(name
, stringList
, "stringlist");
1000 return wxItemPropertyInfo::GetProperty(name
);
1003 bool wxChoicePropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1005 wxChoice
*choice
= (wxChoice
*)propertyWindow
;
1006 if (name
== "values")
1009 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
1012 char *s
= expr
->StringValue();
1015 expr
= expr
->GetNext();
1017 if (choice
->Number() > 0)
1018 choice
->SetSelection(0);
1022 return wxItemPropertyInfo::SetProperty(name
, property
);
1025 void wxChoicePropertyInfo::GetPropertyNames(wxStringList
& names
)
1027 names
.Add("values");
1028 wxItemPropertyInfo::GetPropertyNames(names
);
1031 bool wxChoicePropertyInfo::InstantiateResource(wxItemResource
*resource
)
1033 wxChoice
*choice
= (wxChoice
*)propertyWindow
;
1035 if (choice
->Number() == 0)
1036 resource
->SetStringValues(NULL
);
1039 wxStringList
*slist
= new wxStringList
;
1041 for (i
= 0; i
< choice
->Number(); i
++)
1042 slist
->Add(choice
->GetString(i
));
1044 resource
->SetStringValues(slist
);
1046 return wxItemPropertyInfo::InstantiateResource(resource
);
1053 wxProperty
*wxRadioBoxPropertyInfo::GetProperty(wxString
& name
)
1055 wxRadioBox
*radioBox
= (wxRadioBox
*)propertyWindow
;
1056 if (name
== "numberRowsOrCols")
1058 return new wxProperty("numberRowsOrCols", (long)radioBox
->GetNumberOfRowsOrCols(), "integer");
1060 if (name
== "orientation")
1063 if (propertyWindow
->GetWindowStyleFlag() & wxHORIZONTAL
)
1064 pos
= "wxHORIZONTAL";
1068 return new wxProperty("orientation", pos
, "string",
1069 new wxStringListValidator(new wxStringList("wxHORIZONTAL", "wxVERTICAL",
1072 else if (name
== "values")
1074 wxStringList
*stringList
= new wxStringList
;
1076 for (i
= 0; i
< radioBox
->Number(); i
++)
1077 stringList
->Add(radioBox
->GetString(i
));
1079 return new wxProperty(name
, stringList
, "stringlist");
1081 return wxItemPropertyInfo::GetProperty(name
);
1084 bool wxRadioBoxPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1086 wxRadioBox
*radioBox
= (wxRadioBox
*)propertyWindow
;
1087 if (name
== "numberRowsOrCols")
1089 radioBox
->SetNumberOfRowsOrCols((int)property
->GetValue().IntegerValue());
1090 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox
, this);
1093 else if (name
== "orientation")
1095 long windowStyle
= radioBox
->GetWindowStyleFlag();
1096 wxString
val(property
->GetValue().StringValue());
1097 if (val
== "wxHORIZONTAL")
1099 if (windowStyle
& wxVERTICAL
)
1100 windowStyle
-= wxVERTICAL
;
1101 windowStyle
|= wxHORIZONTAL
;
1105 if (windowStyle
& wxHORIZONTAL
)
1106 windowStyle
-= wxHORIZONTAL
;
1107 windowStyle
|= wxVERTICAL
;
1109 radioBox
->SetWindowStyleFlag(windowStyle
);
1111 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox
, this);
1114 else if (name
== "values")
1116 // Set property into *resource*, not wxRadioBox, and then recreate
1117 // the wxRadioBox. This is because we can't dynamically set the strings
1119 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(propertyWindow
);
1123 wxStringList
*stringList
= resource
->GetStringValues();
1126 stringList
= new wxStringList
;
1127 resource
->SetStringValues(stringList
);
1129 stringList
->Clear();
1131 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
1134 char *s
= expr
->StringValue();
1137 expr
= expr
->GetNext();
1139 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox
, this);
1142 return wxItemPropertyInfo::SetProperty(name
, property
);
1145 void wxRadioBoxPropertyInfo::GetPropertyNames(wxStringList
& names
)
1148 names
.Add("values");
1149 names
.Add("orientation");
1150 names
.Add("numberRowsOrCols");
1151 wxItemPropertyInfo::GetPropertyNames(names
);
1154 bool wxRadioBoxPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1156 wxRadioBox
*rbox
= (wxRadioBox
*)propertyWindow
;
1157 // Take strings from resource instead
1160 if (rbox->Number() == 0)
1161 resource->SetStringValues(NULL);
1164 wxStringList *slist = new wxStringList;
1166 for (i = 0; i < rbox->Number(); i++)
1167 slist->Add(rbox->GetString(i));
1169 resource->SetStringValues(slist);
1172 resource
->SetValue1(rbox
->GetNumberOfRowsOrCols());
1173 return wxItemPropertyInfo::InstantiateResource(resource
);
1180 wxProperty
*wxGroupBoxPropertyInfo::GetProperty(wxString
& name
)
1182 wxStaticBox
*groupBox
= (wxStaticBox
*)propertyWindow
;
1183 return wxItemPropertyInfo::GetProperty(name
);
1186 bool wxGroupBoxPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1188 return wxItemPropertyInfo::SetProperty(name
, property
);
1191 void wxGroupBoxPropertyInfo::GetPropertyNames(wxStringList
& names
)
1194 wxItemPropertyInfo::GetPropertyNames(names
);
1197 bool wxGroupBoxPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1199 wxStaticBox
*gbox
= (wxStaticBox
*)propertyWindow
;
1200 return wxItemPropertyInfo::InstantiateResource(resource
);
1207 wxProperty
*wxCheckBoxPropertyInfo::GetProperty(wxString
& name
)
1209 wxCheckBox
*checkBox
= (wxCheckBox
*)propertyWindow
;
1210 if (name
== "value")
1211 return new wxProperty("value", checkBox
->GetValue(), "bool");
1213 return wxItemPropertyInfo::GetProperty(name
);
1216 bool wxCheckBoxPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1218 wxCheckBox
*checkBox
= (wxCheckBox
*)propertyWindow
;
1219 if (name
== "value")
1221 checkBox
->SetValue((bool)property
->GetValue().BoolValue());
1225 return wxItemPropertyInfo::SetProperty(name
, property
);
1228 void wxCheckBoxPropertyInfo::GetPropertyNames(wxStringList
& names
)
1232 wxItemPropertyInfo::GetPropertyNames(names
);
1235 bool wxCheckBoxPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1237 wxCheckBox
*cbox
= (wxCheckBox
*)propertyWindow
;
1238 resource
->SetValue1(cbox
->GetValue());
1239 return wxItemPropertyInfo::InstantiateResource(resource
);
1246 wxProperty
*wxRadioButtonPropertyInfo::GetProperty(wxString
& name
)
1248 wxRadioButton
*checkBox
= (wxRadioButton
*)propertyWindow
;
1249 if (name
== "value")
1250 return new wxProperty("value", checkBox
->GetValue(), "bool");
1252 return wxItemPropertyInfo::GetProperty(name
);
1255 bool wxRadioButtonPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1257 wxRadioButton
*checkBox
= (wxRadioButton
*)propertyWindow
;
1258 if (name
== "value")
1260 checkBox
->SetValue((bool)property
->GetValue().BoolValue());
1264 return wxItemPropertyInfo::SetProperty(name
, property
);
1267 void wxRadioButtonPropertyInfo::GetPropertyNames(wxStringList
& names
)
1271 wxItemPropertyInfo::GetPropertyNames(names
);
1274 bool wxRadioButtonPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1276 wxRadioButton
*cbox
= (wxRadioButton
*)propertyWindow
;
1277 resource
->SetValue1(cbox
->GetValue());
1278 return wxItemPropertyInfo::InstantiateResource(resource
);
1285 wxProperty
*wxSliderPropertyInfo::GetProperty(wxString
& name
)
1287 wxSlider
*slider
= (wxSlider
*)propertyWindow
;
1288 if (name
== "value")
1289 return new wxProperty("value", (long)slider
->GetValue(), "integer");
1290 else if (name
== "orientation")
1293 if (propertyWindow
->GetWindowStyleFlag() & wxHORIZONTAL
)
1294 pos
= "wxHORIZONTAL";
1298 return new wxProperty("orientation", pos
, "string",
1299 new wxStringListValidator(new wxStringList("wxHORIZONTAL", "wxVERTICAL",
1302 else if (name
== "min_value")
1303 return new wxProperty("min_value", (long)slider
->GetMin(), "integer");
1304 else if (name
== "max_value")
1305 return new wxProperty("max_value", (long)slider
->GetMax(), "integer");
1307 return wxItemPropertyInfo::GetProperty(name
);
1310 bool wxSliderPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1312 wxSlider
*slider
= (wxSlider
*)propertyWindow
;
1313 if (name
== "value")
1315 slider
->SetValue((int)property
->GetValue().IntegerValue());
1318 else if (name
== "orientation")
1320 long windowStyle
= slider
->GetWindowStyleFlag();
1321 long oldWindowStyle
= windowStyle
;
1322 wxString
val(property
->GetValue().StringValue());
1323 if (val
== "wxHORIZONTAL")
1325 if (windowStyle
& wxVERTICAL
)
1326 windowStyle
-= wxVERTICAL
;
1327 windowStyle
|= wxHORIZONTAL
;
1331 if (windowStyle
& wxHORIZONTAL
)
1332 windowStyle
-= wxHORIZONTAL
;
1333 windowStyle
|= wxVERTICAL
;
1336 if (oldWindowStyle
== windowStyle
)
1339 slider
->SetWindowStyleFlag(windowStyle
);
1341 // If the window style has changed, we swap the width and height parameters.
1343 slider
->GetSize(&w
, &h
);
1345 slider
= (wxSlider
*)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(slider
, this);
1346 slider
->SetSize(-1, -1, h
, w
);
1350 else if (name
== "min_value")
1352 slider
->SetRange((int)property
->GetValue().IntegerValue(), slider
->GetMax());
1355 else if (name
== "max_value")
1357 slider
->SetRange(slider
->GetMin(), (int)property
->GetValue().IntegerValue());
1361 return wxItemPropertyInfo::SetProperty(name
, property
);
1364 void wxSliderPropertyInfo::GetPropertyNames(wxStringList
& names
)
1367 names
.Add("orientation");
1368 names
.Add("min_value");
1369 names
.Add("max_value");
1370 wxItemPropertyInfo::GetPropertyNames(names
);
1373 bool wxSliderPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1375 wxSlider
*slider
= (wxSlider
*)propertyWindow
;
1376 resource
->SetValue1(slider
->GetValue());
1377 resource
->SetValue2(slider
->GetMin());
1378 resource
->SetValue3(slider
->GetMax());
1379 return wxItemPropertyInfo::InstantiateResource(resource
);
1386 wxProperty
*wxGaugePropertyInfo::GetProperty(wxString
& name
)
1388 wxGauge
*gauge
= (wxGauge
*)propertyWindow
;
1389 if (name
== "value")
1390 return new wxProperty("value", (long)gauge
->GetValue(), "integer");
1391 else if (name
== "max_value")
1392 return new wxProperty("max_value", (long)gauge
->GetRange(), "integer");
1394 return wxItemPropertyInfo::GetProperty(name
);
1397 bool wxGaugePropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1399 wxGauge
*gauge
= (wxGauge
*)propertyWindow
;
1400 if (name
== "value")
1402 gauge
->SetValue((int)property
->GetValue().IntegerValue());
1405 else if (name
== "max_value")
1407 gauge
->SetRange((int)property
->GetValue().IntegerValue());
1411 return wxItemPropertyInfo::SetProperty(name
, property
);
1414 void wxGaugePropertyInfo::GetPropertyNames(wxStringList
& names
)
1417 names
.Add("max_value");
1418 wxItemPropertyInfo::GetPropertyNames(names
);
1421 bool wxGaugePropertyInfo::InstantiateResource(wxItemResource
*resource
)
1423 wxGauge
*gauge
= (wxGauge
*)propertyWindow
;
1424 resource
->SetValue1(gauge
->GetValue());
1425 resource
->SetValue2(gauge
->GetRange());
1426 return wxItemPropertyInfo::InstantiateResource(resource
);
1433 wxProperty
*wxScrollBarPropertyInfo::GetProperty(wxString
& name
)
1435 wxScrollBar
*scrollBar
= (wxScrollBar
*)propertyWindow
;
1436 if (name
== "value")
1437 return new wxProperty("value", (long)scrollBar
->GetValue(), "integer");
1438 else if (name
== "orientation")
1441 if (propertyWindow
->GetWindowStyleFlag() & wxHORIZONTAL
)
1442 pos
= "wxHORIZONTAL";
1446 return new wxProperty("orientation", pos
, "string",
1447 new wxStringListValidator(new wxStringList("wxHORIZONTAL", "wxVERTICAL",
1450 else if (name
== "pageSize")
1452 int viewStart
, pageLength
, objectLength
, viewLength
;
1453 scrollBar
->GetValues(&viewStart
, &viewLength
, &objectLength
, &pageLength
);
1455 return new wxProperty("pageSize", (long)pageLength
, "integer");
1457 else if (name
== "viewLength")
1459 int viewStart
, pageLength
, objectLength
, viewLength
;
1460 scrollBar
->GetValues(&viewStart
, &viewLength
, &objectLength
, &pageLength
);
1462 return new wxProperty("viewLength", (long)viewLength
, "integer");
1464 else if (name
== "objectLength")
1466 int viewStart
, pageLength
, objectLength
, viewLength
;
1467 scrollBar
->GetValues(&viewStart
, &viewLength
, &objectLength
, &pageLength
);
1469 return new wxProperty("objectLength", (long)objectLength
, "integer");
1472 return wxItemPropertyInfo::GetProperty(name
);
1475 bool wxScrollBarPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1477 wxScrollBar
*scrollBar
= (wxScrollBar
*)propertyWindow
;
1478 if (name
== "value")
1480 scrollBar
->SetValue((int)property
->GetValue().IntegerValue());
1483 else if (name
== "orientation")
1485 long windowStyle
= scrollBar
->GetWindowStyleFlag();
1486 long oldWindowStyle
= windowStyle
;
1487 wxString
val(property
->GetValue().StringValue());
1488 if (val
== "wxHORIZONTAL")
1490 if (windowStyle
& wxVERTICAL
)
1491 windowStyle
-= wxVERTICAL
;
1492 windowStyle
|= wxHORIZONTAL
;
1496 if (windowStyle
& wxHORIZONTAL
)
1497 windowStyle
-= wxHORIZONTAL
;
1498 windowStyle
|= wxVERTICAL
;
1501 if (oldWindowStyle
== windowStyle
)
1504 scrollBar
->SetWindowStyleFlag(windowStyle
);
1506 // If the window style has changed, we swap the width and height parameters.
1508 scrollBar
->GetSize(&w
, &h
);
1510 scrollBar
= (wxScrollBar
*)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(scrollBar
, this);
1511 scrollBar
->SetSize(-1, -1, h
, w
);
1515 else if (name
== "pageSize")
1517 scrollBar
->SetPageSize((int)property
->GetValue().IntegerValue());
1520 else if (name
== "viewLength")
1522 scrollBar
->SetViewLength((int)property
->GetValue().IntegerValue());
1525 else if (name
== "objectLength")
1527 scrollBar
->SetObjectLength((int)property
->GetValue().IntegerValue());
1531 return wxItemPropertyInfo::SetProperty(name
, property
);
1534 void wxScrollBarPropertyInfo::GetPropertyNames(wxStringList
& names
)
1536 names
.Add("orientation");
1538 names
.Add("pageSize");
1539 names
.Add("viewLength");
1540 names
.Add("objectLength");
1541 wxItemPropertyInfo::GetPropertyNames(names
);
1543 // Remove some properties we don't inherit
1544 names
.Delete("fontPoints");
1545 names
.Delete("fontFamily");
1546 names
.Delete("fontStyle");
1547 names
.Delete("fontWeight");
1548 names
.Delete("fontUnderlined");
1551 bool wxScrollBarPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1553 wxScrollBar
*sbar
= (wxScrollBar
*)propertyWindow
;
1555 resource
->SetValue1(sbar
->GetValue());
1557 int viewStart
, pageLength
, objectLength
, viewLength
;
1558 sbar
->GetValues(&viewStart
, &viewLength
, &objectLength
, &pageLength
);
1560 resource
->SetValue2(pageLength
);
1561 resource
->SetValue3(objectLength
);
1562 resource
->SetValue5(viewLength
);
1564 return wxItemPropertyInfo::InstantiateResource(resource
);
1571 wxProperty
*wxPanelPropertyInfo::GetProperty(wxString
& name
)
1573 wxPanel
*panelWindow
= (wxPanel
*)propertyWindow
;
1574 wxFont
*labelFont
= panelWindow
->GetLabelFont();
1575 wxFont
*buttonFont
= panelWindow
->GetButtonFont();
1577 if (name
== "labelFontPoints" || name
== "labelFontFamily" || name
== "labelFontStyle" || name
== "labelFontWeight" ||
1578 name
== "labelFontUnderlined")
1579 return GetFontProperty(name
, labelFont
);
1580 else if (name
== "buttonFontPoints" || name
== "buttonFontFamily" || name
== "buttonFontStyle" || name
== "buttonFontWeight" ||
1581 name
== "buttonFontUnderlined")
1582 return GetFontProperty(name
, buttonFont
);
1583 else if (name
== "no3D")
1586 if (panelWindow
->GetWindowStyleFlag() & wxNO_3D
)
1589 userColours
= FALSE
;
1591 return new wxProperty(name
, (bool)userColours
, "bool");
1593 else if (name
== "backgroundColour")
1595 wxColour
col(panelWindow
->GetBackgroundColour());
1597 wxDecToHex(col
.Red(), buf
);
1598 wxDecToHex(col
.Green(), buf
+2);
1599 wxDecToHex(col
.Blue(), buf
+4);
1601 return new wxProperty(name
, buf
, "string", new wxColourListValidator
);
1603 else if (name
== "title")
1605 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
1607 return new wxProperty(name
, resource
->GetTitle(), "string");
1609 return new wxProperty(name
, "Could not get title", "string");
1612 return wxWindowPropertyInfo::GetProperty(name
);
1615 bool wxPanelPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1617 wxPanel
*panelWindow
= (wxPanel
*)propertyWindow
;
1618 wxFont
*labelFont
= panelWindow
->GetLabelFont();
1619 wxFont
*buttonFont
= panelWindow
->GetButtonFont();
1621 if (labelFont
&& (name
== "labelFontPoints" || name
== "labelFontFamily" || name
== "labelFontStyle" || name
== "labelFontWeight" || name
== "labelFontUnderlined" ))
1623 wxFont
*newFont
= SetFontProperty(name
, property
, labelFont
);
1625 panelWindow
->SetLabelFont(newFont
);
1628 else if (buttonFont
&& (name
== "buttonFontPoints" || name
== "buttonFontFamily" || name
== "buttonFontStyle" || name
== "buttonFontWeight" || name
== "buttonFontUnderlined" ))
1630 wxFont
*newFont
= SetFontProperty(name
, property
, buttonFont
);
1632 panelWindow
->SetButtonFont(newFont
);
1635 else if (name
== "no3D")
1637 bool userColours
= property
->GetValue().BoolValue();
1638 long flag
= panelWindow
->GetWindowStyleFlag();
1642 if ((panelWindow
->GetWindowStyleFlag() & wxNO_3D
) != wxNO_3D
)
1643 panelWindow
->SetWindowStyleFlag(panelWindow
->GetWindowStyleFlag() | wxNO_3D
);
1647 if ((panelWindow
->GetWindowStyleFlag() & wxNO_3D
) == wxNO_3D
)
1648 panelWindow
->SetWindowStyleFlag(panelWindow
->GetWindowStyleFlag() - wxNO_3D
);
1650 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
1651 resource
->SetStyle(panelWindow
->GetWindowStyleFlag());
1653 panelWindow
= (wxPanel
*)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(panelWindow
, this);
1656 else if (name
== "backgroundColour")
1658 char *hex
= property
->GetValue().StringValue();
1659 int r
= wxHexToDec(hex
);
1660 int g
= wxHexToDec(hex
+2);
1661 int b
= wxHexToDec(hex
+4);
1663 wxColour
col(r
,g
,b
);
1664 panelWindow
->SetBackgroundColour(col
);
1665 panelWindow
= (wxPanel
*)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(panelWindow
, this);
1668 else if (name
== "title")
1670 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
1673 resource
->SetTitle(property
->GetValue().StringValue());
1680 return wxWindowPropertyInfo::SetProperty(name
, property
);
1683 void wxPanelPropertyInfo::GetPropertyNames(wxStringList
& names
)
1685 wxWindowPropertyInfo::GetPropertyNames(names
);
1689 names
.Add("backgroundColour");
1692 bool wxPanelPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1694 wxPanel
*panel
= (wxPanel
*)propertyWindow
;
1695 if (panel
->GetFont())
1696 resource
->SetFont(wxTheFontList
->FindOrCreateFont(panel
->GetFont()->GetPointSize(),
1697 panel
->GetFont()->GetFamily(), panel
->GetFont()->GetStyle(), panel
->GetFont()->GetWeight(),
1698 panel
->GetFont()->GetUnderlined(), panel
->GetFont()->GetFaceName()));
1700 resource
->SetBackgroundColour(new wxColour(panel
->GetBackgroundColour()));
1702 return wxWindowPropertyInfo::InstantiateResource(resource
);
1710 wxProperty
*wxDialogPropertyInfo::GetProperty(wxString
& name
)
1712 wxDialog
*dialogWindow
= (wxDialog
*)propertyWindow
;
1713 if (name
== "modal")
1715 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(dialogWindow
);
1719 bool modal
= (resource
->GetValue1() != 0);
1720 return new wxProperty(name
, modal
, "bool");
1723 return wxPanelPropertyInfo::GetProperty(name
);
1726 bool wxDialogPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1728 wxDialog
*dialogWindow
= (wxDialog
*)propertyWindow
;
1730 if (name
== "modal")
1732 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(dialogWindow
);
1736 resource
->SetValue1(property
->GetValue().BoolValue());
1740 return wxPanelPropertyInfo::SetProperty(name
, property
);
1743 void wxDialogPropertyInfo::GetPropertyNames(wxStringList
& names
)
1748 wxPanelPropertyInfo::GetPropertyNames(names
);
1751 bool wxDialogPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1753 wxDialog
*dialog
= (wxDialog
*)propertyWindow
;
1754 wxString
str(dialog
->GetTitle());
1755 resource
->SetTitle(WXSTRINGCAST str
);
1757 return wxPanelPropertyInfo::InstantiateResource(resource
);
1765 int wxStringToFontWeight(wxString
& val
)
1767 if (val
== "wxBOLD") return wxBOLD
;
1768 else if (val
== "wxLIGHT") return wxLIGHT
;
1769 else return wxNORMAL
;
1772 int wxStringToFontStyle(wxString
& val
)
1774 if (val
== "wxITALIC") return wxITALIC
;
1775 else if (val
== "wxSLANT") return wxSLANT
;
1776 else return wxNORMAL
;
1779 int wxStringToFontFamily(wxString
& val
)
1781 if (val
== "wxDECORATIVE") return wxDECORATIVE
;
1782 else if (val
== "wxROMAN") return wxROMAN
;
1783 else if (val
== "wxSCRIPT") return wxSCRIPT
;
1784 else if (val
== "wxMODERN") return wxMODERN
;
1785 else if (val
== "wxTELETYPE") return wxTELETYPE
;
1786 else return wxSWISS
;
1790 /// Resource symbol validator
1792 IMPLEMENT_DYNAMIC_CLASS(wxResourceSymbolValidator
, wxPropertyListValidator
)
1794 wxResourceSymbolValidator::wxResourceSymbolValidator(long flags
):
1795 wxPropertyListValidator(flags
)
1799 wxResourceSymbolValidator::~wxResourceSymbolValidator(void)
1803 bool wxResourceSymbolValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1808 // Called when TICK is pressed or focus is lost or view wants to update
1809 // the property list.
1810 // Does the transferance from the property editing area to the property itself
1811 bool wxResourceSymbolValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1813 if (!view
->GetValueText())
1815 wxString
value(view
->GetValueText()->GetValue());
1816 property
->GetValue() = value
;
1820 // Called when TICK is pressed or focus is lost or view wants to update
1821 // the property list.
1822 // Does the transferance from the property editing area to the property itself
1823 bool wxResourceSymbolValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1825 if (!view
->GetValueText())
1827 wxString
str(property
->GetValue().GetStringRepresentation());
1828 view
->GetValueText()->SetValue(str
);
1832 // Called when the property is double clicked. Extra functionality can be provided,
1833 // cycling through possible values.
1834 bool wxResourceSymbolValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1836 if (!view
->GetValueText())
1838 OnEdit(property
, view
, parentWindow
);
1842 bool wxResourceSymbolValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1844 if (view
->GetConfirmButton())
1845 view
->GetConfirmButton()->Enable(TRUE
);
1846 if (view
->GetCancelButton())
1847 view
->GetCancelButton()->Enable(TRUE
);
1848 if (view
->GetEditButton())
1849 view
->GetEditButton()->Enable(TRUE
);
1850 if (view
->GetValueText())
1851 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1855 void wxResourceSymbolValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1857 if (!view
->GetValueText())
1860 wxResourceSymbolDialog
* dialog
= new wxResourceSymbolDialog(parentWindow
, -1, "Edit Symbol");
1862 // Split name/id pair e.g. "IDC_TEXT=123"
1863 wxString
value(property
->GetValue().StringValue());
1865 wxString strName
= value
.Before('=');
1866 wxString strId
= value
.After('=');
1868 dialog
->SetSymbol(strName
);
1869 dialog
->SetId(atoi(strId
));
1873 if (dialog
->ShowModal() == wxID_OK
)
1875 wxString
symbolName(dialog
->GetSymbol());
1876 long id
= dialog
->GetId();
1880 str
.Printf("%d", id
);
1881 property
->GetValue() = symbolName
+ wxString("=") + str
;
1883 view
->DisplayProperty(property
);
1884 view
->UpdatePropertyDisplayInList(property
);
1885 view
->OnPropertyChanged(property
);
1889 char *s
= wxFileSelector(
1890 filenameMessage
.GetData(),
1891 wxPathOnly(property
->GetValue().StringValue()),
1892 wxFileNameFromPath(property
->GetValue().StringValue()),
1894 filenameWildCard
.GetData(),
1899 property
->GetValue() = wxString(s
);
1900 view
->DisplayProperty(property
);
1901 view
->UpdatePropertyDisplayInList(property
);
1902 view
->OnPropertyChanged(property
);
1907 BEGIN_EVENT_TABLE(wxResourceSymbolDialog
, wxDialog
)
1908 EVT_BUTTON(wxID_OK
, wxResourceSymbolDialog::OnOK
)
1909 EVT_COMBOBOX(ID_SYMBOLNAME_COMBOBOX
, wxResourceSymbolDialog::OnComboBoxSelect
)
1910 EVT_TEXT(ID_SYMBOLNAME_COMBOBOX
, wxResourceSymbolDialog::OnSymbolNameUpdate
)
1913 wxResourceSymbolDialog::wxResourceSymbolDialog(wxWindow
* parent
, const wxWindowID id
, const wxString
& title
, const wxPoint
& pos
,
1914 const wxSize
& size
, long style
):
1915 wxDialog(parent
, id
, title
, pos
, size
, style
)
1920 (void) new wxStaticText(this, -1, "Name: ", wxPoint(x
, y
));
1924 m_nameCtrl
= new wxComboBox(this, ID_SYMBOLNAME_COMBOBOX
, "",
1925 wxPoint(x
, y
), wxSize(200, -1), 0, NULL
, wxCB_DROPDOWN
);
1930 (void) new wxStaticText(this, -1, "Id: ", wxPoint(x
, y
));
1934 m_idCtrl
= new wxTextCtrl(this, ID_SYMBOLID_TEXTCTRL
, "",
1935 wxPoint(x
, y
), wxSize(200, -1));
1939 (void) new wxButton(this, wxID_OK
, "OK", wxPoint(x
, y
), wxSize(80, -1));
1942 (void) new wxButton(this, wxID_CANCEL
, "Cancel", wxPoint(x
, y
), wxSize(80, -1));
1948 void wxResourceSymbolDialog::Init()
1951 defaultId
.Printf("%ld", m_symbolId
);
1953 m_nameCtrl
->SetValue(m_symbolName
);
1954 m_idCtrl
->SetValue(defaultId
);
1956 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().FillComboBox(m_nameCtrl
);
1959 void wxResourceSymbolDialog::OnOK(wxCommandEvent
& event
)
1963 wxDialog::OnOK(event
);
1967 bool wxResourceSymbolDialog::CheckValues()
1969 wxString
nameStr(m_nameCtrl
->GetValue());
1970 wxString
idStr(m_idCtrl
->GetValue());
1971 int id
= atoi(idStr
);
1975 wxMessageBox("Identifier cannot be missing or zero", "Dialog Editor", wxOK
|wxICON_EXCLAMATION
, this);
1980 wxMessageBox("Please enter a symbol name", "Dialog Editor", wxOK
|wxICON_EXCLAMATION
, this);
1983 if (nameStr
.Contains(" "))
1985 wxMessageBox("Symbol name cannot contain spaces.", "Dialog Editor", wxOK
|wxICON_EXCLAMATION
, this);
1988 if (nameStr
.Contains("="))
1990 wxMessageBox("Symbol name cannot contain =.", "Dialog Editor", wxOK
|wxICON_EXCLAMATION
, this);
1993 if (nameStr
.IsNumber())
1995 wxMessageBox("Symbol name cannot be a number.", "Dialog Editor", wxOK
|wxICON_EXCLAMATION
, this);
1998 // TODO: other checks on the name syntax.
2000 if (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(nameStr
))
2002 // If we change the id for an existing symbol, we need to:
2003 // 1) Check if there are any other resources currently using the original id.
2004 // If so, will need to change their id to the new id, in SetProperty.
2005 // 2) Remove the old symbol, add the new symbol.
2006 // In this check, we don't have to do this, but we need to do it in SetProperty.
2008 if (nameStr
== GetSymbol() && id
!= GetId())
2010 // It's OK to change the id. But we'll need to change all matching ids in all resources,
2014 // If we change the name but not the id... we'll just need to remove and
2015 // re-add the symbol/id pair, in SetProperty.
2016 if (nameStr
!= GetSymbol() && id
== GetId())
2020 // What if we're changing both the name and the id?
2021 // - if there's no symbol of that name, just remove the old, add the new (in SetProperty)
2022 // - if there is a symbol of that name, if id matches, do nothing. If not, veto.
2024 if (nameStr
!= GetSymbol() && id
!= GetId())
2026 if (!wxResourceManager::GetCurrentResourceManager()->IsIdentifierOK(nameStr
, id
))
2028 wxMessageBox("This integer id is already being used under a different name.\nPlease choose another.",
2029 "Dialog Editor", wxOK
|wxICON_EXCLAMATION
, this);
2042 void wxResourceSymbolDialog::OnComboBoxSelect(wxCommandEvent
& event
)
2044 wxString
str(m_nameCtrl
->GetValue());
2045 if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(str
))
2047 int id
= wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str
);
2049 str2
.Printf("%d", id
);
2050 m_idCtrl
->SetValue(str2
);
2051 m_idCtrl
->Enable(FALSE
);
2055 if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().SymbolExists(str
))
2057 int id
= wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str
);
2059 str2
.Printf("%d", id
);
2060 m_idCtrl
->SetValue(str2
);
2062 m_idCtrl
->Enable(TRUE
);
2066 void wxResourceSymbolDialog::OnSymbolNameUpdate(wxCommandEvent
& event
)
2068 wxString
str(m_nameCtrl
->GetValue());
2069 if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(str
))
2071 int id
= wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str
);
2073 str2
.Printf("%d", id
);
2074 m_idCtrl
->SetValue(str2
);
2075 m_idCtrl
->Enable(FALSE
);
2079 if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().SymbolExists(str
))
2081 int id
= wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str
);
2083 str2
.Printf("%d", id
);
2084 m_idCtrl
->SetValue(str2
);
2086 m_idCtrl
->Enable(TRUE
);