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
*wxRadioBoxPropertyInfo::GetProperty(wxString
& name
)
1094 wxRadioBox
*radioBox
= (wxRadioBox
*)propertyWindow
;
1095 if (name
== "numberRowsOrCols")
1097 return new wxProperty("numberRowsOrCols", (long)radioBox
->GetNumberOfRowsOrCols(), "integer");
1099 if (name
== "orientation")
1102 if (propertyWindow
->GetWindowStyleFlag() & wxHORIZONTAL
)
1103 pos
= "wxHORIZONTAL";
1107 return new wxProperty("orientation", pos
, "string",
1108 new wxStringListValidator(new wxStringList("wxHORIZONTAL", "wxVERTICAL",
1111 else if (name
== "values")
1113 wxStringList
*stringList
= new wxStringList
;
1115 for (i
= 0; i
< radioBox
->Number(); i
++)
1116 stringList
->Add(radioBox
->GetString(i
));
1118 return new wxProperty(name
, stringList
, "stringlist");
1120 return wxItemPropertyInfo::GetProperty(name
);
1123 bool wxRadioBoxPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1125 wxRadioBox
*radioBox
= (wxRadioBox
*)propertyWindow
;
1126 if (name
== "numberRowsOrCols")
1128 radioBox
->SetNumberOfRowsOrCols((int)property
->GetValue().IntegerValue());
1129 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox
, this);
1132 else if (name
== "orientation")
1134 long windowStyle
= radioBox
->GetWindowStyleFlag();
1135 wxString
val(property
->GetValue().StringValue());
1136 if (val
== "wxHORIZONTAL")
1138 if (windowStyle
& wxVERTICAL
)
1139 windowStyle
-= wxVERTICAL
;
1140 windowStyle
|= wxHORIZONTAL
;
1144 if (windowStyle
& wxHORIZONTAL
)
1145 windowStyle
-= wxHORIZONTAL
;
1146 windowStyle
|= wxVERTICAL
;
1148 radioBox
->SetWindowStyleFlag(windowStyle
);
1150 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox
, this);
1153 else if (name
== "values")
1155 // Set property into *resource*, not wxRadioBox, and then recreate
1156 // the wxRadioBox. This is because we can't dynamically set the strings
1158 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(propertyWindow
);
1162 wxStringList
*stringList
= resource
->GetStringValues();
1165 stringList
= new wxStringList
;
1166 resource
->SetStringValues(stringList
);
1168 stringList
->Clear();
1170 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
1173 char *s
= expr
->StringValue();
1176 expr
= expr
->GetNext();
1178 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox
, this);
1181 return wxItemPropertyInfo::SetProperty(name
, property
);
1184 void wxRadioBoxPropertyInfo::GetPropertyNames(wxStringList
& names
)
1186 wxItemPropertyInfo::GetPropertyNames(names
);
1188 names
.Add("values");
1189 names
.Add("orientation");
1190 names
.Add("numberRowsOrCols");
1193 bool wxRadioBoxPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1195 wxRadioBox
*rbox
= (wxRadioBox
*)propertyWindow
;
1196 // Take strings from resource instead
1199 if (rbox->Number() == 0)
1200 resource->SetStringValues(NULL);
1203 wxStringList *slist = new wxStringList;
1205 for (i = 0; i < rbox->Number(); i++)
1206 slist->Add(rbox->GetString(i));
1208 resource->SetStringValues(slist);
1211 resource
->SetValue1(rbox
->GetNumberOfRowsOrCols());
1212 return wxItemPropertyInfo::InstantiateResource(resource
);
1219 wxProperty
*wxGroupBoxPropertyInfo::GetProperty(wxString
& name
)
1221 wxStaticBox
*groupBox
= (wxStaticBox
*)propertyWindow
;
1222 return wxItemPropertyInfo::GetProperty(name
);
1225 bool wxGroupBoxPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1227 return wxItemPropertyInfo::SetProperty(name
, property
);
1230 void wxGroupBoxPropertyInfo::GetPropertyNames(wxStringList
& names
)
1232 wxItemPropertyInfo::GetPropertyNames(names
);
1236 bool wxGroupBoxPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1238 wxStaticBox
*gbox
= (wxStaticBox
*)propertyWindow
;
1239 return wxItemPropertyInfo::InstantiateResource(resource
);
1246 wxProperty
*wxCheckBoxPropertyInfo::GetProperty(wxString
& name
)
1248 wxCheckBox
*checkBox
= (wxCheckBox
*)propertyWindow
;
1249 if (name
== "value")
1250 return new wxProperty("value", checkBox
->GetValue(), "bool");
1252 return wxItemPropertyInfo::GetProperty(name
);
1255 bool wxCheckBoxPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1257 wxCheckBox
*checkBox
= (wxCheckBox
*)propertyWindow
;
1258 if (name
== "value")
1260 checkBox
->SetValue((bool)property
->GetValue().BoolValue());
1264 return wxItemPropertyInfo::SetProperty(name
, property
);
1267 void wxCheckBoxPropertyInfo::GetPropertyNames(wxStringList
& names
)
1269 wxItemPropertyInfo::GetPropertyNames(names
);
1274 bool wxCheckBoxPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1276 wxCheckBox
*cbox
= (wxCheckBox
*)propertyWindow
;
1277 resource
->SetValue1(cbox
->GetValue());
1278 return wxItemPropertyInfo::InstantiateResource(resource
);
1285 wxProperty
*wxRadioButtonPropertyInfo::GetProperty(wxString
& name
)
1287 wxRadioButton
*checkBox
= (wxRadioButton
*)propertyWindow
;
1288 if (name
== "value")
1289 return new wxProperty("value", checkBox
->GetValue(), "bool");
1291 return wxItemPropertyInfo::GetProperty(name
);
1294 bool wxRadioButtonPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1296 wxRadioButton
*checkBox
= (wxRadioButton
*)propertyWindow
;
1297 if (name
== "value")
1299 checkBox
->SetValue((bool)property
->GetValue().BoolValue());
1303 return wxItemPropertyInfo::SetProperty(name
, property
);
1306 void wxRadioButtonPropertyInfo::GetPropertyNames(wxStringList
& names
)
1308 wxItemPropertyInfo::GetPropertyNames(names
);
1313 bool wxRadioButtonPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1315 wxRadioButton
*cbox
= (wxRadioButton
*)propertyWindow
;
1316 resource
->SetValue1(cbox
->GetValue());
1317 return wxItemPropertyInfo::InstantiateResource(resource
);
1324 wxProperty
*wxSliderPropertyInfo::GetProperty(wxString
& name
)
1326 wxSlider
*slider
= (wxSlider
*)propertyWindow
;
1327 if (name
== "value")
1328 return new wxProperty("value", (long)slider
->GetValue(), "integer");
1329 else if (name
== "orientation")
1332 if (propertyWindow
->GetWindowStyleFlag() & wxHORIZONTAL
)
1333 pos
= "wxHORIZONTAL";
1337 return new wxProperty("orientation", pos
, "string",
1338 new wxStringListValidator(new wxStringList("wxHORIZONTAL", "wxVERTICAL",
1341 else if (name
== "min_value")
1342 return new wxProperty("min_value", (long)slider
->GetMin(), "integer");
1343 else if (name
== "max_value")
1344 return new wxProperty("max_value", (long)slider
->GetMax(), "integer");
1346 return wxItemPropertyInfo::GetProperty(name
);
1349 bool wxSliderPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1351 wxSlider
*slider
= (wxSlider
*)propertyWindow
;
1352 if (name
== "value")
1354 slider
->SetValue((int)property
->GetValue().IntegerValue());
1357 else if (name
== "orientation")
1359 long windowStyle
= slider
->GetWindowStyleFlag();
1360 long oldWindowStyle
= windowStyle
;
1361 wxString
val(property
->GetValue().StringValue());
1362 if (val
== "wxHORIZONTAL")
1364 if (windowStyle
& wxVERTICAL
)
1365 windowStyle
-= wxVERTICAL
;
1366 windowStyle
|= wxHORIZONTAL
;
1370 if (windowStyle
& wxHORIZONTAL
)
1371 windowStyle
-= wxHORIZONTAL
;
1372 windowStyle
|= wxVERTICAL
;
1375 if (oldWindowStyle
== windowStyle
)
1378 slider
->SetWindowStyleFlag(windowStyle
);
1380 // If the window style has changed, we swap the width and height parameters.
1382 slider
->GetSize(&w
, &h
);
1384 slider
= (wxSlider
*)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(slider
, this);
1385 slider
->SetSize(-1, -1, h
, w
);
1389 else if (name
== "min_value")
1391 slider
->SetRange((int)property
->GetValue().IntegerValue(), slider
->GetMax());
1394 else if (name
== "max_value")
1396 slider
->SetRange(slider
->GetMin(), (int)property
->GetValue().IntegerValue());
1400 return wxItemPropertyInfo::SetProperty(name
, property
);
1403 void wxSliderPropertyInfo::GetPropertyNames(wxStringList
& names
)
1405 wxItemPropertyInfo::GetPropertyNames(names
);
1407 names
.Add("orientation");
1408 names
.Add("min_value");
1409 names
.Add("max_value");
1412 bool wxSliderPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1414 wxSlider
*slider
= (wxSlider
*)propertyWindow
;
1415 resource
->SetValue1(slider
->GetValue());
1416 resource
->SetValue2(slider
->GetMin());
1417 resource
->SetValue3(slider
->GetMax());
1418 return wxItemPropertyInfo::InstantiateResource(resource
);
1425 wxProperty
*wxGaugePropertyInfo::GetProperty(wxString
& name
)
1427 wxGauge
*gauge
= (wxGauge
*)propertyWindow
;
1428 if (name
== "value")
1429 return new wxProperty("value", (long)gauge
->GetValue(), "integer");
1430 else if (name
== "max_value")
1431 return new wxProperty("max_value", (long)gauge
->GetRange(), "integer");
1433 return wxItemPropertyInfo::GetProperty(name
);
1436 bool wxGaugePropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1438 wxGauge
*gauge
= (wxGauge
*)propertyWindow
;
1439 if (name
== "value")
1441 gauge
->SetValue((int)property
->GetValue().IntegerValue());
1444 else if (name
== "max_value")
1446 gauge
->SetRange((int)property
->GetValue().IntegerValue());
1450 return wxItemPropertyInfo::SetProperty(name
, property
);
1453 void wxGaugePropertyInfo::GetPropertyNames(wxStringList
& names
)
1455 wxItemPropertyInfo::GetPropertyNames(names
);
1457 names
.Add("max_value");
1460 bool wxGaugePropertyInfo::InstantiateResource(wxItemResource
*resource
)
1462 wxGauge
*gauge
= (wxGauge
*)propertyWindow
;
1463 resource
->SetValue1(gauge
->GetValue());
1464 resource
->SetValue2(gauge
->GetRange());
1465 return wxItemPropertyInfo::InstantiateResource(resource
);
1472 wxProperty
*wxScrollBarPropertyInfo::GetProperty(wxString
& name
)
1474 wxScrollBar
*scrollBar
= (wxScrollBar
*)propertyWindow
;
1475 if (name
== "value")
1476 return new wxProperty("value", (long)scrollBar
->GetValue(), "integer");
1477 else if (name
== "orientation")
1480 if (propertyWindow
->GetWindowStyleFlag() & wxHORIZONTAL
)
1481 pos
= "wxHORIZONTAL";
1485 return new wxProperty("orientation", pos
, "string",
1486 new wxStringListValidator(new wxStringList("wxHORIZONTAL", "wxVERTICAL",
1489 else if (name
== "pageSize")
1491 int viewStart
, pageLength
, objectLength
, viewLength
;
1492 scrollBar
->GetValues(&viewStart
, &viewLength
, &objectLength
, &pageLength
);
1494 return new wxProperty("pageSize", (long)pageLength
, "integer");
1496 else if (name
== "viewLength")
1498 int viewStart
, pageLength
, objectLength
, viewLength
;
1499 scrollBar
->GetValues(&viewStart
, &viewLength
, &objectLength
, &pageLength
);
1501 return new wxProperty("viewLength", (long)viewLength
, "integer");
1503 else if (name
== "objectLength")
1505 int viewStart
, pageLength
, objectLength
, viewLength
;
1506 scrollBar
->GetValues(&viewStart
, &viewLength
, &objectLength
, &pageLength
);
1508 return new wxProperty("objectLength", (long)objectLength
, "integer");
1511 return wxItemPropertyInfo::GetProperty(name
);
1514 bool wxScrollBarPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1516 wxScrollBar
*scrollBar
= (wxScrollBar
*)propertyWindow
;
1517 if (name
== "value")
1519 scrollBar
->SetValue((int)property
->GetValue().IntegerValue());
1522 else if (name
== "orientation")
1524 long windowStyle
= scrollBar
->GetWindowStyleFlag();
1525 long oldWindowStyle
= windowStyle
;
1526 wxString
val(property
->GetValue().StringValue());
1527 if (val
== "wxHORIZONTAL")
1529 if (windowStyle
& wxVERTICAL
)
1530 windowStyle
-= wxVERTICAL
;
1531 windowStyle
|= wxHORIZONTAL
;
1535 if (windowStyle
& wxHORIZONTAL
)
1536 windowStyle
-= wxHORIZONTAL
;
1537 windowStyle
|= wxVERTICAL
;
1540 if (oldWindowStyle
== windowStyle
)
1543 scrollBar
->SetWindowStyleFlag(windowStyle
);
1545 // If the window style has changed, we swap the width and height parameters.
1547 scrollBar
->GetSize(&w
, &h
);
1549 scrollBar
= (wxScrollBar
*)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(scrollBar
, this);
1550 scrollBar
->SetSize(-1, -1, h
, w
);
1554 else if (name
== "pageSize")
1556 scrollBar
->SetPageSize((int)property
->GetValue().IntegerValue());
1559 else if (name
== "viewLength")
1561 scrollBar
->SetViewLength((int)property
->GetValue().IntegerValue());
1564 else if (name
== "objectLength")
1566 scrollBar
->SetObjectLength((int)property
->GetValue().IntegerValue());
1570 return wxItemPropertyInfo::SetProperty(name
, property
);
1573 void wxScrollBarPropertyInfo::GetPropertyNames(wxStringList
& names
)
1575 wxItemPropertyInfo::GetPropertyNames(names
);
1576 names
.Add("orientation");
1578 names
.Add("pageSize");
1579 names
.Add("viewLength");
1580 names
.Add("objectLength");
1582 // Remove some properties we don't inherit
1583 names
.Delete("fontPoints");
1584 names
.Delete("fontFamily");
1585 names
.Delete("fontStyle");
1586 names
.Delete("fontWeight");
1587 names
.Delete("fontUnderlined");
1590 bool wxScrollBarPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1592 wxScrollBar
*sbar
= (wxScrollBar
*)propertyWindow
;
1594 resource
->SetValue1(sbar
->GetValue());
1596 int viewStart
, pageLength
, objectLength
, viewLength
;
1597 sbar
->GetValues(&viewStart
, &viewLength
, &objectLength
, &pageLength
);
1599 resource
->SetValue2(pageLength
);
1600 resource
->SetValue3(objectLength
);
1601 resource
->SetValue5(viewLength
);
1603 return wxItemPropertyInfo::InstantiateResource(resource
);
1610 wxProperty
*wxPanelPropertyInfo::GetProperty(wxString
& name
)
1612 wxPanel
*panelWindow
= (wxPanel
*)propertyWindow
;
1613 wxFont
*labelFont
= panelWindow
->GetLabelFont();
1614 wxFont
*buttonFont
= panelWindow
->GetButtonFont();
1616 if (name
== "labelFontPoints" || name
== "labelFontFamily" || name
== "labelFontStyle" || name
== "labelFontWeight" ||
1617 name
== "labelFontUnderlined")
1618 return GetFontProperty(name
, labelFont
);
1619 else if (name
== "buttonFontPoints" || name
== "buttonFontFamily" || name
== "buttonFontStyle" || name
== "buttonFontWeight" ||
1620 name
== "buttonFontUnderlined")
1621 return GetFontProperty(name
, buttonFont
);
1622 else if (name
== "no3D")
1625 if (panelWindow
->GetWindowStyleFlag() & wxNO_3D
)
1628 userColours
= FALSE
;
1630 return new wxProperty(name
, (bool)userColours
, "bool");
1632 else if (name
== "backgroundColour")
1634 wxColour
col(panelWindow
->GetBackgroundColour());
1636 wxDecToHex(col
.Red(), buf
);
1637 wxDecToHex(col
.Green(), buf
+2);
1638 wxDecToHex(col
.Blue(), buf
+4);
1640 return new wxProperty(name
, buf
, "string", new wxColourListValidator
);
1642 else if (name
== "title")
1644 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
1646 return new wxProperty(name
, resource
->GetTitle(), "string");
1648 return new wxProperty(name
, "Could not get title", "string");
1650 else if (name
== "caption")
1652 return new wxProperty(name
, ((panelWindow
->GetWindowStyleFlag() & wxCAPTION
) == wxCAPTION
),
1655 else if (name
== "systemMenu")
1657 return new wxProperty(name
, ((panelWindow
->GetWindowStyleFlag() & wxSYSTEM_MENU
) == wxSYSTEM_MENU
),
1660 else if (name
== "thickFrame")
1662 return new wxProperty(name
, ((panelWindow
->GetWindowStyleFlag() & wxTHICK_FRAME
) == wxTHICK_FRAME
),
1666 return wxWindowPropertyInfo::GetProperty(name
);
1669 bool wxPanelPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1671 wxPanel
*panelWindow
= (wxPanel
*)propertyWindow
;
1672 wxFont
*labelFont
= panelWindow
->GetLabelFont();
1673 wxFont
*buttonFont
= panelWindow
->GetButtonFont();
1675 if (labelFont
&& (name
== "labelFontPoints" || name
== "labelFontFamily" || name
== "labelFontStyle" || name
== "labelFontWeight" || name
== "labelFontUnderlined" ))
1677 wxFont
*newFont
= SetFontProperty(name
, property
, labelFont
);
1679 panelWindow
->SetLabelFont(newFont
);
1682 else if (buttonFont
&& (name
== "buttonFontPoints" || name
== "buttonFontFamily" || name
== "buttonFontStyle" || name
== "buttonFontWeight" || name
== "buttonFontUnderlined" ))
1684 wxFont
*newFont
= SetFontProperty(name
, property
, buttonFont
);
1686 panelWindow
->SetButtonFont(newFont
);
1689 else if (name
== "no3D")
1691 bool userColours
= property
->GetValue().BoolValue();
1692 long flag
= panelWindow
->GetWindowStyleFlag();
1696 if ((panelWindow
->GetWindowStyleFlag() & wxNO_3D
) != wxNO_3D
)
1697 panelWindow
->SetWindowStyleFlag(panelWindow
->GetWindowStyleFlag() | wxNO_3D
);
1701 if ((panelWindow
->GetWindowStyleFlag() & wxNO_3D
) == wxNO_3D
)
1702 panelWindow
->SetWindowStyleFlag(panelWindow
->GetWindowStyleFlag() - wxNO_3D
);
1704 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
1705 resource
->SetStyle(panelWindow
->GetWindowStyleFlag());
1707 panelWindow
= (wxPanel
*)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(panelWindow
, this);
1710 else if (name
== "backgroundColour")
1712 char *hex
= property
->GetValue().StringValue();
1713 int r
= wxHexToDec(hex
);
1714 int g
= wxHexToDec(hex
+2);
1715 int b
= wxHexToDec(hex
+4);
1717 wxColour
col(r
,g
,b
);
1718 panelWindow
->SetBackgroundColour(col
);
1719 panelWindow
= (wxPanel
*)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(panelWindow
, this);
1722 else if (name
== "title")
1724 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
1727 resource
->SetTitle(property
->GetValue().StringValue());
1733 else if (name
== "caption")
1735 SetWindowStyle(panelWindow
, wxCAPTION
, property
->GetValue().BoolValue());
1737 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
1738 resource
->SetStyle(panelWindow
->GetWindowStyleFlag());
1741 else if (name
== "thickFrame")
1743 SetWindowStyle(panelWindow
, wxTHICK_FRAME
, property
->GetValue().BoolValue());
1745 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
1746 resource
->SetStyle(panelWindow
->GetWindowStyleFlag());
1749 else if (name
== "systemMenu")
1751 SetWindowStyle(panelWindow
, wxSYSTEM_MENU
, property
->GetValue().BoolValue());
1753 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
1754 resource
->SetStyle(panelWindow
->GetWindowStyleFlag());
1758 return wxWindowPropertyInfo::SetProperty(name
, property
);
1761 void wxPanelPropertyInfo::GetPropertyNames(wxStringList
& names
)
1763 wxWindowPropertyInfo::GetPropertyNames(names
);
1767 names
.Add("backgroundColour");
1768 names
.Add("caption");
1769 names
.Add("systemMenu");
1770 names
.Add("thickFrame");
1773 bool wxPanelPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1775 wxPanel
*panel
= (wxPanel
*)propertyWindow
;
1776 if (panel
->GetFont())
1777 resource
->SetFont(wxTheFontList
->FindOrCreateFont(panel
->GetFont()->GetPointSize(),
1778 panel
->GetFont()->GetFamily(), panel
->GetFont()->GetStyle(), panel
->GetFont()->GetWeight(),
1779 panel
->GetFont()->GetUnderlined(), panel
->GetFont()->GetFaceName()));
1781 resource
->SetBackgroundColour(new wxColour(panel
->GetBackgroundColour()));
1783 return wxWindowPropertyInfo::InstantiateResource(resource
);
1791 wxProperty
*wxDialogPropertyInfo::GetProperty(wxString
& name
)
1793 wxDialog
*dialogWindow
= (wxDialog
*)propertyWindow
;
1794 if (name
== "modal")
1796 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(dialogWindow
);
1800 bool modal
= (resource
->GetValue1() != 0);
1801 return new wxProperty(name
, modal
, "bool");
1804 return wxPanelPropertyInfo::GetProperty(name
);
1807 bool wxDialogPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1809 wxDialog
*dialogWindow
= (wxDialog
*)propertyWindow
;
1811 if (name
== "modal")
1813 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(dialogWindow
);
1817 resource
->SetValue1(property
->GetValue().BoolValue());
1821 return wxPanelPropertyInfo::SetProperty(name
, property
);
1824 void wxDialogPropertyInfo::GetPropertyNames(wxStringList
& names
)
1826 wxPanelPropertyInfo::GetPropertyNames(names
);
1831 bool wxDialogPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1833 wxDialog
*dialog
= (wxDialog
*)propertyWindow
;
1834 wxString
str(dialog
->GetTitle());
1835 resource
->SetTitle(WXSTRINGCAST str
);
1837 return wxPanelPropertyInfo::InstantiateResource(resource
);
1845 int wxStringToFontWeight(wxString
& val
)
1847 if (val
== "wxBOLD") return wxBOLD
;
1848 else if (val
== "wxLIGHT") return wxLIGHT
;
1849 else return wxNORMAL
;
1852 int wxStringToFontStyle(wxString
& val
)
1854 if (val
== "wxITALIC") return wxITALIC
;
1855 else if (val
== "wxSLANT") return wxSLANT
;
1856 else return wxNORMAL
;
1859 int wxStringToFontFamily(wxString
& val
)
1861 if (val
== "wxDECORATIVE") return wxDECORATIVE
;
1862 else if (val
== "wxROMAN") return wxROMAN
;
1863 else if (val
== "wxSCRIPT") return wxSCRIPT
;
1864 else if (val
== "wxMODERN") return wxMODERN
;
1865 else if (val
== "wxTELETYPE") return wxTELETYPE
;
1866 else return wxSWISS
;
1870 /// Resource symbol validator
1872 IMPLEMENT_DYNAMIC_CLASS(wxResourceSymbolValidator
, wxPropertyListValidator
)
1874 wxResourceSymbolValidator::wxResourceSymbolValidator(long flags
):
1875 wxPropertyListValidator(flags
)
1879 wxResourceSymbolValidator::~wxResourceSymbolValidator(void)
1883 bool wxResourceSymbolValidator::OnCheckValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1888 // Called when TICK is pressed or focus is lost or view wants to update
1889 // the property list.
1890 // Does the transferance from the property editing area to the property itself
1891 bool wxResourceSymbolValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1893 if (!view
->GetValueText())
1895 wxString
value(view
->GetValueText()->GetValue());
1896 property
->GetValue() = value
;
1900 // Called when TICK is pressed or focus is lost or view wants to update
1901 // the property list.
1902 // Does the transferance from the property editing area to the property itself
1903 bool wxResourceSymbolValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1905 if (!view
->GetValueText())
1907 wxString
str(property
->GetValue().GetStringRepresentation());
1908 view
->GetValueText()->SetValue(str
);
1912 // Called when the property is double clicked. Extra functionality can be provided,
1913 // cycling through possible values.
1914 bool wxResourceSymbolValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1916 if (!view
->GetValueText())
1918 OnEdit(property
, view
, parentWindow
);
1922 bool wxResourceSymbolValidator::OnPrepareControls(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1924 if (view
->GetConfirmButton())
1925 view
->GetConfirmButton()->Enable(TRUE
);
1926 if (view
->GetCancelButton())
1927 view
->GetCancelButton()->Enable(TRUE
);
1928 if (view
->GetEditButton())
1929 view
->GetEditButton()->Enable(TRUE
);
1930 if (view
->GetValueText())
1931 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
1935 void wxResourceSymbolValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
1937 if (!view
->GetValueText())
1940 wxResourceSymbolDialog
* dialog
= new wxResourceSymbolDialog(parentWindow
, -1, "Edit Symbol");
1942 // Split name/id pair e.g. "IDC_TEXT=123"
1943 wxString
value(property
->GetValue().StringValue());
1945 wxString strName
= value
.Before('=');
1946 wxString strId
= value
.After('=');
1948 dialog
->SetSymbol(strName
);
1949 dialog
->SetId(atoi(strId
));
1953 if (dialog
->ShowModal() == wxID_OK
)
1955 wxString
symbolName(dialog
->GetSymbol());
1956 long id
= dialog
->GetId();
1960 str
.Printf("%d", id
);
1961 property
->GetValue() = symbolName
+ wxString("=") + str
;
1963 view
->DisplayProperty(property
);
1964 view
->UpdatePropertyDisplayInList(property
);
1965 view
->OnPropertyChanged(property
);
1969 BEGIN_EVENT_TABLE(wxResourceSymbolDialog
, wxDialog
)
1970 EVT_BUTTON(wxID_OK
, wxResourceSymbolDialog::OnOK
)
1971 EVT_COMBOBOX(ID_SYMBOLNAME_COMBOBOX
, wxResourceSymbolDialog::OnComboBoxSelect
)
1972 EVT_TEXT(ID_SYMBOLNAME_COMBOBOX
, wxResourceSymbolDialog::OnSymbolNameUpdate
)
1975 wxResourceSymbolDialog::wxResourceSymbolDialog(wxWindow
* parent
, const wxWindowID id
, const wxString
& title
, const wxPoint
& pos
,
1976 const wxSize
& size
, long style
):
1977 wxDialog(parent
, id
, title
, pos
, size
, style
)
1982 (void) new wxStaticText(this, -1, "Name: ", wxPoint(x
, y
));
1986 m_nameCtrl
= new wxComboBox(this, ID_SYMBOLNAME_COMBOBOX
, "",
1987 wxPoint(x
, y
), wxSize(200, -1), 0, NULL
, wxCB_DROPDOWN
|wxCB_SORT
);
1992 (void) new wxStaticText(this, -1, "Id: ", wxPoint(x
, y
));
1996 m_idCtrl
= new wxTextCtrl(this, ID_SYMBOLID_TEXTCTRL
, "",
1997 wxPoint(x
, y
), wxSize(200, -1));
2001 (void) new wxButton(this, wxID_OK
, "OK", wxPoint(x
, y
), wxSize(80, -1));
2004 (void) new wxButton(this, wxID_CANCEL
, "Cancel", wxPoint(x
, y
), wxSize(80, -1));
2010 void wxResourceSymbolDialog::Init()
2013 defaultId
.Printf("%ld", m_symbolId
);
2015 m_nameCtrl
->SetValue(m_symbolName
);
2016 m_idCtrl
->SetValue(defaultId
);
2018 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().FillComboBox(m_nameCtrl
);
2021 void wxResourceSymbolDialog::OnOK(wxCommandEvent
& event
)
2025 wxDialog::OnOK(event
);
2029 bool wxResourceSymbolDialog::CheckValues()
2031 wxString
nameStr(m_nameCtrl
->GetValue());
2032 wxString
idStr(m_idCtrl
->GetValue());
2033 int id
= atoi(idStr
);
2037 wxMessageBox("Identifier cannot be missing or zero", "Dialog Editor", wxOK
|wxICON_EXCLAMATION
, this);
2042 wxMessageBox("Please enter a symbol name", "Dialog Editor", wxOK
|wxICON_EXCLAMATION
, this);
2045 if (nameStr
.Contains(" "))
2047 wxMessageBox("Symbol name cannot contain spaces.", "Dialog Editor", wxOK
|wxICON_EXCLAMATION
, this);
2050 if (nameStr
.Contains("="))
2052 wxMessageBox("Symbol name cannot contain =.", "Dialog Editor", wxOK
|wxICON_EXCLAMATION
, this);
2055 if (nameStr
.IsNumber())
2057 wxMessageBox("Symbol name cannot be a number.", "Dialog Editor", wxOK
|wxICON_EXCLAMATION
, this);
2060 // TODO: other checks on the name syntax.
2062 if (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(nameStr
))
2064 // If we change the id for an existing symbol, we need to:
2065 // 1) Check if there are any other resources currently using the original id.
2066 // If so, will need to change their id to the new id, in SetProperty.
2067 // 2) Remove the old symbol, add the new symbol.
2068 // In this check, we don't have to do this, but we need to do it in SetProperty.
2070 if (nameStr
== GetSymbol() && id
!= GetId())
2072 // It's OK to change the id. But we'll need to change all matching ids in all resources,
2076 // If we change the name but not the id... we'll just need to remove and
2077 // re-add the symbol/id pair, in SetProperty.
2078 if (nameStr
!= GetSymbol() && id
== GetId())
2082 // What if we're changing both the name and the id?
2083 // - if there's no symbol of that name, just remove the old, add the new (in SetProperty)
2084 // - if there is a symbol of that name, if id matches, do nothing. If not, veto.
2086 if (nameStr
!= GetSymbol() && id
!= GetId())
2088 if (!wxResourceManager::GetCurrentResourceManager()->IsIdentifierOK(nameStr
, id
))
2090 wxMessageBox("This integer id is already being used under a different name.\nPlease choose another.",
2091 "Dialog Editor", wxOK
|wxICON_EXCLAMATION
, this);
2104 void wxResourceSymbolDialog::OnComboBoxSelect(wxCommandEvent
& event
)
2106 wxString
str(m_nameCtrl
->GetStringSelection());
2107 if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(str
))
2109 int id
= wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str
);
2111 str2
.Printf("%d", id
);
2112 m_idCtrl
->SetValue(str2
);
2113 m_idCtrl
->Enable(FALSE
);
2117 if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().SymbolExists(str
))
2119 int id
= wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str
);
2121 str2
.Printf("%d", id
);
2122 m_idCtrl
->SetValue(str2
);
2124 m_idCtrl
->Enable(TRUE
);
2128 void wxResourceSymbolDialog::OnSymbolNameUpdate(wxCommandEvent
& event
)
2130 wxString
str(m_nameCtrl
->GetValue());
2131 if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(str
))
2133 int id
= wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str
);
2135 str2
.Printf("%d", id
);
2136 m_idCtrl
->SetValue(str2
);
2137 m_idCtrl
->Enable(FALSE
);
2141 if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().SymbolExists(str
))
2143 int id
= wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str
);
2145 str2
.Printf("%d", id
);
2146 m_idCtrl
->SetValue(str2
);
2148 m_idCtrl
->Enable(TRUE
);