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"
39 // Causes immediate feedback.
40 void wxResourcePropertyListView::OnPropertyChanged(wxProperty
*property
)
42 // Sets the value of the property back into the actual object,
43 // IF the property value was modified.
44 if (property
->GetValue().GetModified())
46 m_propertyInfo
->SetProperty(property
->GetName(), property
);
47 property
->GetValue().SetModified(FALSE
);
48 wxResourceManager::GetCurrentResourceManager()->Modify(TRUE
);
52 bool wxResourcePropertyListView::OnClose(void)
55 GetManagedWindow()->GetSize(& w
, & h
);
56 GetManagedWindow()->GetPosition(& x
, & y
);
58 wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().width
= w
;
59 wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().height
= h
;
60 wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().x
= x
;
61 wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().y
= y
;
63 return wxPropertyListView::OnClose();
66 wxWindow
*wxPropertyInfo::sm_propertyWindow
;
69 * wxDialogEditorPropertyListDialog
73 wxDialogEditorPropertyListDialog::wxDialogEditorPropertyListDialog(wxPropertyListView *v, wxWindow *parent, const wxString& title,
74 const wxPoint& pos, const wxSize& size,
75 long style, const wxString& name):
76 wxPropertyListDialog(v, parent, title, pos, size, style, name)
82 wxDialogEditorPropertyListDialog::~wxDialogEditorPropertyListDialog()
86 wxPropertyInfo::sm_propertyWindow = NULL;
90 wxDialogEditorPropertyListFrame::wxDialogEditorPropertyListFrame(wxPropertyListView
*v
, wxFrame
*parent
, const wxString
& title
,
91 const wxPoint
& pos
, const wxSize
& size
,
92 long style
, const wxString
& name
):
93 wxPropertyListFrame(v
, parent
, title
, pos
, size
, style
, name
)
99 wxDialogEditorPropertyListFrame::~wxDialogEditorPropertyListFrame()
103 if (wxPropertyInfo::sm_propertyWindow
== this)
104 wxPropertyInfo::sm_propertyWindow
= NULL
;
111 // Edit the information represented by this object, whatever that
113 bool wxPropertyInfo::Edit(wxWindow
*WXUNUSED(parent
), const wxString
& title
)
115 if (sm_propertyWindow
)
117 wxWindowPropertyInfo
* thisProp
= (wxWindowPropertyInfo
*) this;
118 wxWindowPropertyInfo
* oldProp
= (wxWindowPropertyInfo
*) (((wxDialogEditorPropertyListFrame
*) sm_propertyWindow
)->GetInfo());
119 if (oldProp
->GetWindow() == thisProp
->GetWindow())
121 sm_propertyWindow
->Raise();
127 sm_propertyWindow
->GetSize(& w
, & h
);
128 sm_propertyWindow
->GetPosition(& x
, & y
);
130 wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().width
= w
;
131 wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().height
= h
;
132 wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().x
= x
;
133 wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().y
= y
;
135 // Close the window, so we can create a new one for the different window
136 sm_propertyWindow
->Destroy();
137 sm_propertyWindow
= (wxDialogEditorPropertyListFrame
*) NULL
;
141 int width
= wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().width
;
142 int height
= wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().height
;
143 int x
= wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().x
;
144 int y
= wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().y
;
146 wxPropertySheet
*propSheet
= new wxPropertySheet
;
148 wxStringList propNames
;
149 GetPropertyNames(propNames
);
151 wxNode
*node
= propNames
.First();
154 wxString
name((char *)node
->Data());
155 wxProperty
*prop
= GetProperty(name
);
158 propSheet
->AddProperty(prop
);
163 // Reset 'modified' flags for all property values
164 propSheet
->SetAllModified(FALSE
);
166 wxResourcePropertyListView
*view
= new wxResourcePropertyListView(this, NULL
,
167 wxPROP_BUTTON_OK
| wxPROP_BUTTON_CANCEL
|
168 wxPROP_BUTTON_CHECK_CROSS
|wxPROP_DYNAMIC_VALUE_FIELD
|wxPROP_PULLDOWN
|wxPROP_SHOWVALUES
);
170 wxDialogEditorPropertyListFrame
*propWin
= new wxDialogEditorPropertyListFrame(view
,
171 wxResourceManager::GetCurrentResourceManager()->GetEditorFrame(), title
, wxPoint(x
, y
),
172 wxSize(width
, height
), wxDEFAULT_FRAME_STYLE
);
173 sm_propertyWindow
= propWin
;
175 propWin
->m_registry
.RegisterValidator(wxString("real"), new wxRealListValidator
);
176 propWin
->m_registry
.RegisterValidator(wxString("string"), new wxStringListValidator
);
177 propWin
->m_registry
.RegisterValidator(wxString("integer"), new wxIntegerListValidator
);
178 propWin
->m_registry
.RegisterValidator(wxString("bool"), new wxBoolListValidator
);
179 propWin
->m_registry
.RegisterValidator(wxString("filename"), new wxFilenameListValidator
);
180 propWin
->m_registry
.RegisterValidator(wxString("stringlist"), new wxListOfStringsListValidator
);
181 propWin
->m_registry
.RegisterValidator(wxString("window_id"), new wxResourceSymbolValidator
);
183 propWin
->m_propInfo
= this;
184 propWin
->m_propSheet
= propSheet
;
186 // view->m_propertyWindow = propWin;
187 view
->AddRegistry(&(propWin
->m_registry
));
189 propWin
->Initialize();
190 view
->ShowView(propSheet
, propWin
->GetPropertyPanel());
194 // Otherwise doesn't show itself
196 wxNoOptimize noOptimize
;
197 propWin
->SetSize(-1, -1, width
, height
);
204 * wxWindowPropertyInfo
207 wxWindowPropertyInfo::wxWindowPropertyInfo(wxWindow
*win
, wxItemResource
*res
)
209 m_propertyWindow
= win
;
210 m_propertyResource
= res
;
213 wxWindowPropertyInfo::~wxWindowPropertyInfo(void)
217 wxProperty
*wxWindowPropertyInfo::GetFontProperty(wxString
& name
, wxFont
*font
)
222 if (name
.Contains("Points"))
223 return new wxProperty(name
, (long)font
->GetPointSize(), "integer", new wxIntegerListValidator(1, 100));
224 else if (name
.Contains("Family"))
225 return new wxProperty(name
, font
->GetFamilyString(), "string",
226 new wxStringListValidator(new wxStringList("wxDECORATIVE", "wxROMAN", "wxSCRIPT", "wxSWISS", "wxMODERN",
228 else if (name
.Contains("Style"))
229 return new wxProperty(name
, font
->GetStyleString(), "string",
230 new wxStringListValidator(new wxStringList("wxNORMAL", "wxITALIC", "wxSLANT", NULL
)));
231 else if (name
.Contains("Weight"))
232 return new wxProperty(name
, font
->GetWeightString(), "string",
233 new wxStringListValidator(new wxStringList("wxNORMAL", "wxBOLD", "wxLIGHT", NULL
)));
234 else if (name
.Contains("Underlined"))
235 return new wxProperty(name
, (bool)font
->GetUnderlined(), "bool");
240 wxFont
*wxWindowPropertyInfo::SetFontProperty(wxString
& name
, wxProperty
*property
, wxFont
*font
)
243 int fontFamily
= wxMODERN
;
244 int fontStyle
= wxNORMAL
;
245 int fontWeight
= wxNORMAL
;
246 bool fontUnderlined
= FALSE
;
248 if (name
.Contains("Points"))
250 pointSize
= (int)property
->GetValue().IntegerValue();
251 if (font
&& (pointSize
== font
->GetPointSize()))
252 return NULL
; // No change
254 else if (font
) pointSize
= font
->GetPointSize();
256 if (name
.Contains("Family"))
258 wxString val
= property
->GetValue().StringValue();
259 fontFamily
= wxStringToFontFamily(val
);
261 if (font
&& (fontFamily
== font
->GetFamily()))
262 return NULL
; // No change
264 else if (font
) fontFamily
= font
->GetFamily();
266 if (name
.Contains("Style"))
268 wxString val
= property
->GetValue().StringValue();
269 fontStyle
= wxStringToFontStyle(val
);
271 if (font
&& (fontStyle
== font
->GetStyle()))
272 return NULL
; // No change
274 else if (font
) fontStyle
= font
->GetStyle();
275 if (name
.Contains("Weight"))
277 wxString val
= property
->GetValue().StringValue();
278 fontWeight
= wxStringToFontWeight(val
);
280 if (font
&& (fontWeight
== font
->GetWeight()))
281 return NULL
; // No change
283 else if (font
) fontWeight
= font
->GetWeight();
285 if (name
.Contains("Underlined"))
287 fontUnderlined
= property
->GetValue().BoolValue();
289 if (font
&& (fontUnderlined
== font
->GetUnderlined()))
290 return NULL
; // No change
292 else if (font
) fontUnderlined
= font
->GetUnderlined();
294 wxFont
*newFont
= wxTheFontList
->FindOrCreateFont(pointSize
, fontFamily
, fontStyle
, fontWeight
, fontUnderlined
);
303 wxProperty
*wxWindowPropertyInfo::GetProperty(wxString
& name
)
305 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
307 wxFont
*font
= & m_propertyWindow
->GetFont();
308 if (name
== "fontPoints" || name
== "fontFamily" || name
== "fontStyle" || name
== "fontWeight" ||
309 name
== "fontUnderlined")
310 return GetFontProperty(name
, font
);
311 else if (name
== "name")
312 return new wxProperty("name", m_propertyWindow
->GetName(), "string");
313 else if (name
== "title")
314 return new wxProperty("title", m_propertyWindow
->GetTitle(), "string");
315 else if (name
== "x")
317 return new wxProperty("x", (long)resource
->GetX(), "integer");
319 else if (name
== "y")
321 return new wxProperty("y", (long)resource
->GetY(), "integer");
323 else if (name
== "width")
325 return new wxProperty("width", (long)resource
->GetWidth(), "integer");
327 else if (name
== "height")
329 return new wxProperty("height", (long)resource
->GetHeight(), "integer");
331 else if (name
== "id")
333 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
336 int id
= resource
->GetId();
338 idStr
.Printf("%d", id
);
339 wxString symbolName
= wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetSymbolForId(id
);
342 // symbolName is now e.g. "ID_PANEL21=105"
343 return new wxProperty("id", symbolName
, "window_id");
348 else if (name
== "border")
351 if (m_propertyWindow
->GetWindowStyleFlag() & wxSIMPLE_BORDER
)
352 border
= "wxSIMPLE_BORDER";
353 else if (m_propertyWindow
->GetWindowStyleFlag() & wxRAISED_BORDER
)
354 border
= "wxRAISED_BORDER";
355 else if (m_propertyWindow
->GetWindowStyleFlag() & wxSUNKEN_BORDER
)
356 border
= "wxSUNKEN_BORDER";
357 else if (m_propertyWindow
->GetWindowStyleFlag() & wxDOUBLE_BORDER
)
358 border
= "wxDOUBLE_BORDER";
359 else if (m_propertyWindow
->GetWindowStyleFlag() & wxSTATIC_BORDER
)
360 border
= "wxSTATIC_BORDER";
362 border
= "wxNO_BORDER";
364 return new wxProperty("border", border
, "string",
365 new wxStringListValidator(new wxStringList("wxSIMPLE_BORDER", "wxRAISED_BORDER",
366 "wxSUNKEN_BORDER", "wxDOUBLE_BORDER", "wxSTATIC_BORDER", "wxNO_BORDER", NULL
)));
372 bool wxWindowPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
374 wxFont
*font
= & m_propertyWindow
->GetFont();
375 if (font
&& (name
== "fontPoints" || name
== "fontFamily" || name
== "fontStyle" || name
== "fontWeight" || name
== "fontUnderlined" ))
377 wxFont
*newFont
= SetFontProperty(name
, property
, font
);
379 m_propertyWindow
->SetFont(* newFont
);
382 else if (name
== "name")
384 // Remove old name from resource table, if it's there.
385 wxItemResource
*oldResource
= (wxItemResource
*)wxResourceManager::GetCurrentResourceManager()->GetResourceTable().Delete(m_propertyWindow
->GetName());
388 // It's a top-level resource
389 m_propertyWindow
->SetName(property
->GetValue().StringValue());
390 oldResource
->SetName(property
->GetValue().StringValue());
391 wxResourceManager::GetCurrentResourceManager()->GetResourceTable().Put(m_propertyWindow
->GetName(), oldResource
);
395 // It's a child of something; just set the name of the resource and the window.
396 m_propertyWindow
->SetName(property
->GetValue().StringValue());
397 m_propertyResource
->SetName(property
->GetValue().StringValue());
399 // Refresh the resource manager list, because the name changed.
400 wxResourceManager::GetCurrentResourceManager()->UpdateResourceList();
403 else if (name
== "title")
405 m_propertyWindow
->SetTitle(property
->GetValue().StringValue());
408 else if (name
== "x")
410 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
412 m_propertyWindow
->GetPosition(&x
, &y
);
413 int newX
= (int)property
->GetValue().IntegerValue();
416 // We need to convert to pixels if this is not a dialog or panel, but
417 // the parent resource specifies dialog units.
418 if (m_propertyWindow
->GetParent() && m_propertyWindow
->IsKindOf(CLASSINFO(wxControl
)))
420 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
->GetParent());
421 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
423 wxPoint pt
= m_propertyWindow
->GetParent()->ConvertDialogToPixels(wxPoint(newX
, y
));
427 else if (m_propertyWindow
->IsKindOf(CLASSINFO(wxPanel
)))
429 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
430 if (resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
432 wxPoint pt
= m_propertyWindow
->ConvertDialogToPixels(wxPoint(newX
, y
));
439 m_propertyWindow
->Move(pixelX
, y
);
440 resource
->SetSize(newX
, resource
->GetY(), resource
->GetWidth(), resource
->GetHeight());
444 else if (name
== "y")
446 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
448 m_propertyWindow
->GetPosition(&x
, &y
);
449 int newY
= (int)property
->GetValue().IntegerValue();
452 // We need to convert to pixels if this is not a dialog or panel, but
453 // the parent resource specifies dialog units.
454 if (m_propertyWindow
->GetParent() && m_propertyWindow
->IsKindOf(CLASSINFO(wxControl
)))
456 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
->GetParent());
457 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
459 wxPoint pt
= m_propertyWindow
->GetParent()->ConvertDialogToPixels(wxPoint(x
, newY
));
463 else if (m_propertyWindow
->IsKindOf(CLASSINFO(wxPanel
)))
465 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
466 if (resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
468 wxPoint pt
= m_propertyWindow
->ConvertDialogToPixels(wxPoint(x
, newY
));
475 m_propertyWindow
->Move(x
, pixelY
);
476 resource
->SetSize(resource
->GetX(), newY
, resource
->GetWidth(), resource
->GetHeight());
480 else if (name
== "width")
482 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
484 m_propertyWindow
->GetSize(&width
, &height
);
485 int newWidth
= (int)property
->GetValue().IntegerValue();
486 int pixelWidth
= newWidth
;
488 // We need to convert to pixels if this is not a dialog or panel, but
489 // the parent resource specifies dialog units.
490 if (m_propertyWindow
->GetParent() && m_propertyWindow
->IsKindOf(CLASSINFO(wxControl
)))
492 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
->GetParent());
493 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
495 wxSize sz
= m_propertyWindow
->GetParent()->ConvertDialogToPixels(wxSize(newWidth
, height
));
499 else if (m_propertyWindow
->IsKindOf(CLASSINFO(wxPanel
)))
501 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
502 if (resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
504 wxSize sz
= m_propertyWindow
->ConvertDialogToPixels(wxSize(newWidth
, height
));
509 if (width
!= pixelWidth
)
511 m_propertyWindow
->SetSize(pixelWidth
, height
);
512 resource
->SetSize(resource
->GetX(), resource
->GetY(), newWidth
, resource
->GetHeight());
516 else if (name
== "height")
518 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
520 m_propertyWindow
->GetSize(&width
, &height
);
521 int newHeight
= (int)property
->GetValue().IntegerValue();
522 int pixelHeight
= newHeight
;
524 // We need to convert to pixels if this is not a dialog or panel, but
525 // the parent resource specifies dialog units.
526 if (m_propertyWindow
->GetParent() && m_propertyWindow
->IsKindOf(CLASSINFO(wxControl
)))
528 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
->GetParent());
529 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
531 wxSize sz
= m_propertyWindow
->GetParent()->ConvertDialogToPixels(wxSize(width
, newHeight
));
535 else if (m_propertyWindow
->IsKindOf(CLASSINFO(wxPanel
)))
537 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
538 if (resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
540 wxSize sz
= m_propertyWindow
->ConvertDialogToPixels(wxSize(width
, newHeight
));
545 if (height
!= pixelHeight
)
547 m_propertyWindow
->SetSize(width
, pixelHeight
);
548 resource
->SetSize(resource
->GetX(), resource
->GetY(), resource
->GetWidth(), newHeight
);
552 else if (name
== "id")
554 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
557 wxString value
= property
->GetValue().StringValue();
559 wxString strName
= value
.Before('=');
560 wxString strId
= value
.After('=');
561 int id
= atoi(strId
);
563 wxString oldSymbolName
= wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetSymbolForId(resource
->GetId());
564 int oldSymbolId
= resource
->GetId();
568 // If we change the id for an existing symbol, we need to:
569 // 1) Check if there are any other resources currently using the original id.
570 // If so, will need to change their id to the new id.
571 // 2) Remove the old symbol, add the new symbol.
572 // In this check, we don't have to do this, but we need to do it in SetProperty.
574 if (strName
== oldSymbolName
&& id
!= oldSymbolId
)
576 wxASSERT( (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(oldSymbolName
)) );
578 // It's OK to change just the id. But we'll need to change all matching ids in all resources,
579 // because ids are unique and changing one resource's id must change all identical ones.
580 wxResourceManager::GetCurrentResourceManager()->ChangeIds(oldSymbolId
, id
);
582 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().RemoveSymbol(oldSymbolName
);
583 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().AddSymbol(strName
, id
);
586 // If we change the name but not the id, we'll just need to remove and
587 // re-add the symbol/id pair.
588 if (strName
!= oldSymbolName
&& id
== oldSymbolId
)
590 wxASSERT( (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(oldSymbolName
)) );
592 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().RemoveSymbol(oldSymbolName
);
594 if (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().SymbolExists(strName
))
596 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().AddSymbol(strName
, id
);
600 // What if we're changing both the name and the id?
601 // - if there's no symbol of that name, just remove the old, add the new (in SetProperty)
602 // - if there is a symbol of that name, if id matches, do nothing. If not, veto.
604 if (strName
!= oldSymbolName
&& id
!= oldSymbolId
)
606 // Remove old symbol if it's not being used
607 if (!wxResourceManager::GetCurrentResourceManager()->IsSymbolUsed(resource
, oldSymbolId
) &&
608 !wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(oldSymbolName
))
610 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().RemoveSymbol(oldSymbolName
);
613 if (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().SymbolExists(strName
))
615 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().AddSymbol(strName
, id
);
626 else if (name
== "border")
628 long borderStyle
= wxNO_BORDER
;
629 wxString val
= property
->GetValue().StringValue();
631 if (val
== "wxSIMPLE_BORDER")
632 borderStyle
= wxSIMPLE_BORDER
;
633 else if (val
== "wxRAISED_BORDER")
634 borderStyle
= wxRAISED_BORDER
;
635 else if (val
== "wxSUNKEN_BORDER")
636 borderStyle
= wxSUNKEN_BORDER
;
637 else if (val
== "wxDOUBLE_BORDER")
638 borderStyle
= wxDOUBLE_BORDER
;
639 else if (val
== "wxSTATIC_BORDER")
640 borderStyle
= wxSTATIC_BORDER
;
642 borderStyle
= wxNO_BORDER
;
644 SetWindowStyle(m_propertyWindow
, wxSIMPLE_BORDER
, FALSE
);
645 SetWindowStyle(m_propertyWindow
, wxRAISED_BORDER
, FALSE
);
646 SetWindowStyle(m_propertyWindow
, wxSUNKEN_BORDER
, FALSE
);
647 SetWindowStyle(m_propertyWindow
, wxDOUBLE_BORDER
, FALSE
);
648 SetWindowStyle(m_propertyWindow
, wxSTATIC_BORDER
, FALSE
);
649 SetWindowStyle(m_propertyWindow
, wxNO_BORDER
, FALSE
);
651 SetWindowStyle(m_propertyWindow
, borderStyle
, TRUE
);
653 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
654 resource
->SetStyle(m_propertyWindow
->GetWindowStyleFlag());
661 void wxWindowPropertyInfo::GetPropertyNames(wxStringList
& names
)
670 if (!m_propertyWindow
->IsKindOf(CLASSINFO(wxControl
)))
672 names
.Add("fontPoints");
673 names
.Add("fontFamily");
674 names
.Add("fontStyle");
675 names
.Add("fontWeight");
676 names
.Add("fontUnderlined");
680 // Fill in the wxItemResource members to mirror the current window settings
681 bool wxWindowPropertyInfo::InstantiateResource(wxItemResource
*resource
)
683 // resource->SetType(m_propertyWindow->GetClassInfo()->GetClassName());
685 // resource->SetStyle(m_propertyWindow->GetWindowStyleFlag());
686 wxString
str(m_propertyWindow
->GetName());
687 resource
->SetName(str
);
689 #if 0 // Why did we comment this out? Possibly because of rounding errors
690 // that will build up as the conversion is repeatedly done.
691 // so only do the conversion when a resize happens.
694 if (m_propertyWindow
->IsKindOf(CLASSINFO(wxPanel
)))
695 m_propertyWindow
->GetClientSize(&w
, &h
);
697 m_propertyWindow
->GetSize(&w
, &h
);
699 m_propertyWindow
->GetPosition(&x
, &y
);
701 // We need to convert to dialog units if this is not a dialog or panel, but
702 // the parent resource specifies dialog units.
703 if (m_propertyWindow
->GetParent() && m_propertyWindow
->IsKindOf(CLASSINFO(wxControl
)))
705 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
->GetParent());
706 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
708 wxPoint pt
= m_propertyWindow
->GetParent()->ConvertPixelsToDialog(wxPoint(x
, y
));
710 wxSize sz
= m_propertyWindow
->GetParent()->ConvertPixelsToDialog(wxSize(w
, h
));
714 else if (m_propertyWindow
->IsKindOf(CLASSINFO(wxPanel
)))
716 if (resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
718 wxPoint pt
= m_propertyWindow
->ConvertPixelsToDialog(wxPoint(x
, y
));
720 wxSize sz
= m_propertyWindow
->ConvertPixelsToDialog(wxSize(w
, h
));
725 resource
->SetSize(x
, y
, w
, h
);
731 // Set the window style
732 void wxWindowPropertyInfo::SetWindowStyle(wxWindow
* win
, long style
, bool set
)
737 if ((win
->GetWindowStyleFlag() & style
) == style
)
741 win
->SetWindowStyleFlag(win
->GetWindowStyleFlag() - style
);
748 win
->SetWindowStyleFlag(win
->GetWindowStyleFlag() | style
);
757 wxProperty
*wxItemPropertyInfo::GetProperty(wxString
& name
)
759 wxControl
*itemWindow
= (wxControl
*)m_propertyWindow
;
760 wxFont
*font
= & itemWindow
->GetFont();
762 if (name
== "fontPoints" || name
== "fontFamily" || name
== "fontStyle" || name
== "fontWeight" ||
763 name
== "fontUnderlined")
764 return GetFontProperty(name
, font
);
765 else if (name
== "label" && itemWindow
->GetLabel())
766 return new wxProperty("label", m_propertyWindow
->GetLabel(), "string");
768 return wxWindowPropertyInfo::GetProperty(name
);
771 bool wxItemPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
773 wxControl
*itemWindow
= (wxControl
*)m_propertyWindow
;
774 wxFont
*font
= & itemWindow
->GetFont();
776 if (font
&& (name
== "fontPoints" || name
== "fontFamily" || name
== "fontStyle" || name
== "fontWeight" || name
== "fontUnderlined" ))
778 wxFont
*newFont
= SetFontProperty(name
, property
, font
);
780 itemWindow
->SetFont(* newFont
);
783 else if (name
== "label")
785 itemWindow
->SetLabel(property
->GetValue().StringValue());
789 return wxWindowPropertyInfo::SetProperty(name
, property
);
792 void wxItemPropertyInfo::GetPropertyNames(wxStringList
& names
)
794 wxWindowPropertyInfo::GetPropertyNames(names
);
796 names
.Add("fontPoints");
797 names
.Add("fontFamily");
798 names
.Add("fontStyle");
799 names
.Add("fontWeight");
800 names
.Add("fontUnderlined");
803 bool wxItemPropertyInfo::InstantiateResource(wxItemResource
*resource
)
805 wxWindowPropertyInfo::InstantiateResource(resource
);
807 wxControl
*item
= (wxControl
*)m_propertyWindow
;
808 wxString
str(item
->GetLabel());
809 resource
->SetTitle(str
);
811 if (item
->GetFont().Ok())
812 resource
->SetFont(* wxTheFontList
->FindOrCreateFont(item
->GetFont().GetPointSize(),
813 item
->GetFont().GetFamily(), item
->GetFont().GetStyle(), item
->GetFont().GetWeight(),
814 item
->GetFont().GetUnderlined(), item
->GetFont().GetFaceName()));
822 wxProperty
*wxButtonPropertyInfo::GetProperty(wxString
& name
)
824 return wxItemPropertyInfo::GetProperty(name
);
827 bool wxButtonPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
829 return wxItemPropertyInfo::SetProperty(name
, property
);
832 void wxButtonPropertyInfo::GetPropertyNames(wxStringList
& names
)
834 wxItemPropertyInfo::GetPropertyNames(names
);
838 bool wxButtonPropertyInfo::InstantiateResource(wxItemResource
*resource
)
840 return wxItemPropertyInfo::InstantiateResource(resource
);
847 wxProperty
*wxBitmapButtonPropertyInfo::GetProperty(wxString
& name
)
849 wxBitmapButton
*button
= (wxBitmapButton
*)m_propertyWindow
;
850 if (name
== "bitmapFilename")
852 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(button
);
853 wxString
str("none.bmp");
857 str
= wxResourceManager::GetCurrentResourceManager()->FindBitmapFilenameForResource(resource
);
859 return new wxProperty("bitmapFilename", str
.GetData(), "string", new wxFilenameListValidator("Select a bitmap file", "*.bmp"));
862 return wxButtonPropertyInfo::GetProperty(name
);
865 bool wxBitmapButtonPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
867 wxBitmapButton
*button
= (wxBitmapButton
*)m_propertyWindow
;
868 if (name
== "bitmapFilename")
870 char *s
= property
->GetValue().StringValue();
871 if (s
&& wxFileExists(s
))
874 wxBitmap
*bitmap
= new wxBitmap(str
, wxBITMAP_TYPE_BMP
);
882 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(button
);
885 wxString
oldResource(resource
->GetValue4());
886 wxString resName
= wxResourceManager::GetCurrentResourceManager()->AddBitmapResource(str
);
887 resource
->SetValue4(resName
);
889 if (!oldResource
.IsNull())
890 wxResourceManager::GetCurrentResourceManager()->PossiblyDeleteBitmapResource(oldResource
);
893 button
->SetLabel(* bitmap
);
900 return wxButtonPropertyInfo::SetProperty(name
, property
);
903 void wxBitmapButtonPropertyInfo::GetPropertyNames(wxStringList
& names
)
905 wxButtonPropertyInfo::GetPropertyNames(names
);
906 names
.Delete("label");
907 names
.Add("bitmapFilename");
910 bool wxBitmapButtonPropertyInfo::InstantiateResource(wxItemResource
*resource
)
912 return wxItemPropertyInfo::InstantiateResource(resource
);
919 wxProperty
*wxStaticTextPropertyInfo::GetProperty(wxString
& name
)
921 return wxItemPropertyInfo::GetProperty(name
);
924 bool wxStaticTextPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
926 wxStaticText
* itemWindow
= (wxStaticText
*) m_propertyWindow
;
929 // Because setting a wxStaticText control's label may change the
930 // size, we must get the size and instantiate the resource immediately.
931 itemWindow
->SetLabel(property
->GetValue().StringValue());
934 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(itemWindow
);
936 m_propertyWindow
->GetSize(&w
, &h
);
937 // m_propertyWindow->GetPosition(&x, &y);
939 // We need to convert to dialog units if
940 // the parent resource specifies dialog units.
941 if (m_propertyWindow
->GetParent())
943 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
->GetParent());
944 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
946 // wxPoint pt = m_propertyWindow->GetParent()->ConvertPixelsToDialog(wxPoint(x, y));
947 // x = pt.x; y = pt.y;
948 wxSize sz
= m_propertyWindow
->GetParent()->ConvertPixelsToDialog(wxSize(w
, h
));
952 resource
->SetSize(resource
->GetX(), resource
->GetY(), w
, h
);
956 return wxItemPropertyInfo::SetProperty(name
, property
);
959 void wxStaticTextPropertyInfo::GetPropertyNames(wxStringList
& names
)
961 wxItemPropertyInfo::GetPropertyNames(names
);
965 bool wxStaticTextPropertyInfo::InstantiateResource(wxItemResource
*resource
)
967 return wxItemPropertyInfo::InstantiateResource(resource
);
974 wxProperty
*wxStaticBitmapPropertyInfo::GetProperty(wxString
& name
)
976 wxStaticBitmap
*message
= (wxStaticBitmap
*)m_propertyWindow
;
977 if (name
== "bitmapFilename")
979 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(message
);
980 wxString
str("none.bmp");
984 str
= wxResourceManager::GetCurrentResourceManager()->FindBitmapFilenameForResource(resource
);
986 return new wxProperty("bitmapFilename", str
.GetData(), "string", new wxFilenameListValidator("Select a bitmap file", "*.bmp"));
989 return wxItemPropertyInfo::GetProperty(name
);
992 bool wxStaticBitmapPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
994 wxStaticBitmap
*message
= (wxStaticBitmap
*)m_propertyWindow
;
995 if (name
== "bitmapFilename")
997 char *s
= property
->GetValue().StringValue();
998 if (s
&& wxFileExists(s
))
1002 wxBitmap
*bitmap
= new wxBitmap(str
, wxBITMAP_TYPE_BMP
);
1010 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(message
);
1013 wxString
oldResource(resource
->GetValue4());
1014 wxString resName
= wxResourceManager::GetCurrentResourceManager()->AddBitmapResource(str
);
1015 resource
->SetValue4(resName
);
1017 if (!oldResource
.IsNull())
1018 wxResourceManager::GetCurrentResourceManager()->PossiblyDeleteBitmapResource(oldResource
);
1021 message
->SetBitmap(* bitmap
);
1028 return wxItemPropertyInfo::SetProperty(name
, property
);
1031 void wxStaticBitmapPropertyInfo::GetPropertyNames(wxStringList
& names
)
1033 wxItemPropertyInfo::GetPropertyNames(names
);
1034 names
.Add("bitmapFilename");
1037 bool wxStaticBitmapPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1039 return wxItemPropertyInfo::InstantiateResource(resource
);
1046 wxProperty
*wxTextPropertyInfo::GetProperty(wxString
& name
)
1048 wxTextCtrl
*text
= (wxTextCtrl
*)m_propertyWindow
;
1049 if (name
== "value")
1050 return new wxProperty("value", text
->GetValue(), "string");
1051 else if (name
== "password")
1053 bool isPassword
= ((text
->GetWindowStyleFlag() & wxTE_PASSWORD
) == wxTE_PASSWORD
);
1054 return new wxProperty("password", isPassword
, "bool");
1056 else if (name
== "readonly")
1058 bool isReadOnly
= ((text
->GetWindowStyleFlag() & wxTE_READONLY
) == wxTE_READONLY
);
1059 return new wxProperty("readonly", isReadOnly
, "bool");
1062 return wxItemPropertyInfo::GetProperty(name
);
1065 bool wxTextPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1067 wxTextCtrl
*text
= (wxTextCtrl
*)m_propertyWindow
;
1068 if (name
== "value")
1070 text
->SetValue(property
->GetValue().StringValue());
1073 else if (name
== "password")
1075 long flag
= text
->GetWindowStyleFlag();
1076 if (property
->GetValue().BoolValue())
1078 if ((flag
& wxTE_PASSWORD
) != wxTE_PASSWORD
)
1079 flag
|= wxTE_PASSWORD
;
1083 if ((flag
& wxTE_PASSWORD
) == wxTE_PASSWORD
)
1084 flag
-= wxTE_PASSWORD
;
1086 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(text
);
1087 resource
->SetStyle(flag
);
1089 m_propertyWindow
= wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(text
, this);
1092 else if (name
== "readonly")
1094 long flag
= text
->GetWindowStyleFlag();
1095 if (property
->GetValue().BoolValue())
1097 if ((flag
& wxTE_READONLY
) != wxTE_READONLY
)
1098 flag
|= wxTE_READONLY
;
1102 if ((flag
& wxTE_READONLY
) == wxTE_READONLY
)
1103 flag
-= wxTE_READONLY
;
1105 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(text
);
1106 resource
->SetStyle(flag
);
1108 m_propertyWindow
= wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(text
, this);
1112 return wxItemPropertyInfo::SetProperty(name
, property
);
1115 void wxTextPropertyInfo::GetPropertyNames(wxStringList
& names
)
1117 wxItemPropertyInfo::GetPropertyNames(names
);
1119 names
.Add("readonly");
1120 names
.Add("password");
1123 bool wxTextPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1125 wxTextCtrl
*text
= (wxTextCtrl
*)m_propertyWindow
;
1126 wxString
str(text
->GetValue());
1127 resource
->SetValue4(str
);
1129 return wxItemPropertyInfo::InstantiateResource(resource
);
1136 wxProperty
*wxListBoxPropertyInfo::GetProperty(wxString
& name
)
1138 wxListBox
*listBox
= (wxListBox
*)m_propertyWindow
;
1139 if (name
== "values")
1141 wxStringList
*stringList
= new wxStringList
;
1143 for (i
= 0; i
< listBox
->Number(); i
++)
1144 stringList
->Add(listBox
->GetString(i
));
1146 return new wxProperty(name
, stringList
, "stringlist");
1148 else if (name
== "multiple")
1150 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(listBox
);
1154 char *mult
= "wxLB_SINGLE";
1156 if ((listBox
->GetWindowStyleFlag() & wxLB_MULTIPLE
) != 0)
1157 mult
= "wxLB_MULTIPLE";
1158 else if ((listBox
->GetWindowStyleFlag() & wxLB_EXTENDED
) != 0)
1159 mult
= "wxLB_EXTENDED";
1161 mult
= "wxLB_SINGLE";
1163 return new wxProperty("multiple", mult
, "string",
1164 new wxStringListValidator(new wxStringList("wxLB_SINGLE", "wxLB_MULTIPLE", "wxLB_EXTENDED",
1168 return wxItemPropertyInfo::GetProperty(name
);
1171 bool wxListBoxPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1173 wxListBox
*listBox
= (wxListBox
*)m_propertyWindow
;
1174 if (name
== "values")
1177 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
1180 char *s
= expr
->StringValue();
1183 expr
= expr
->GetNext();
1187 else if (name
== "multiple")
1189 SetWindowStyle(m_propertyWindow
, wxLB_SINGLE
, FALSE
);
1190 SetWindowStyle(m_propertyWindow
, wxLB_MULTIPLE
, FALSE
);
1191 SetWindowStyle(m_propertyWindow
, wxLB_EXTENDED
, FALSE
);
1193 wxString
str(property
->GetValue().StringValue());
1194 if (str
== "wxLB_MULTIPLE")
1195 SetWindowStyle(m_propertyWindow
, wxLB_MULTIPLE
, TRUE
);
1196 else if (str
== "wxLB_EXTENDED")
1197 SetWindowStyle(m_propertyWindow
, wxLB_EXTENDED
, TRUE
);
1199 SetWindowStyle(m_propertyWindow
, wxLB_SINGLE
, TRUE
);
1201 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(listBox
);
1203 resource
->SetStyle(m_propertyWindow
->GetWindowStyleFlag());
1204 m_propertyWindow
= wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(listBox
, this);
1208 return wxItemPropertyInfo::SetProperty(name
, property
);
1211 void wxListBoxPropertyInfo::GetPropertyNames(wxStringList
& names
)
1213 wxItemPropertyInfo::GetPropertyNames(names
);
1214 names
.Add("values");
1215 names
.Add("multiple");
1218 bool wxListBoxPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1220 wxListBox
*lbox
= (wxListBox
*)m_propertyWindow
;
1221 // This will be set for the wxItemResource on reading or in SetProperty
1222 // resource->SetValue1(lbox->GetSelectionMode());
1224 if (lbox
->Number() == 0)
1225 resource
->SetStringValues(NULL
);
1230 for (i
= 0; i
< lbox
->Number(); i
++)
1231 slist
.Add(lbox
->GetString(i
));
1233 resource
->SetStringValues(slist
);
1235 return wxItemPropertyInfo::InstantiateResource(resource
);
1242 wxProperty
*wxChoicePropertyInfo::GetProperty(wxString
& name
)
1244 wxChoice
*choice
= (wxChoice
*)m_propertyWindow
;
1245 if (name
== "values")
1247 wxStringList
* stringList
= new wxStringList
;
1249 for (i
= 0; i
< choice
->Number(); i
++)
1250 stringList
->Add(choice
->GetString(i
));
1252 return new wxProperty(name
, stringList
, "stringlist");
1255 return wxItemPropertyInfo::GetProperty(name
);
1258 bool wxChoicePropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1260 wxChoice
*choice
= (wxChoice
*)m_propertyWindow
;
1261 if (name
== "values")
1264 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
1267 char *s
= expr
->StringValue();
1270 expr
= expr
->GetNext();
1272 if (choice
->Number() > 0)
1273 choice
->SetSelection(0);
1277 return wxItemPropertyInfo::SetProperty(name
, property
);
1280 void wxChoicePropertyInfo::GetPropertyNames(wxStringList
& names
)
1282 wxItemPropertyInfo::GetPropertyNames(names
);
1283 names
.Add("values");
1286 bool wxChoicePropertyInfo::InstantiateResource(wxItemResource
*resource
)
1288 wxChoice
*choice
= (wxChoice
*)m_propertyWindow
;
1290 if (choice
->Number() == 0)
1291 resource
->SetStringValues(NULL
);
1296 for (i
= 0; i
< choice
->Number(); i
++)
1297 slist
.Add(choice
->GetString(i
));
1299 resource
->SetStringValues(slist
);
1301 return wxItemPropertyInfo::InstantiateResource(resource
);
1308 wxProperty
*wxComboBoxPropertyInfo::GetProperty(wxString
& name
)
1310 wxComboBox
*choice
= (wxComboBox
*)m_propertyWindow
;
1311 if (name
== "values")
1313 wxStringList
*stringList
= new wxStringList
;
1315 for (i
= 0; i
< choice
->Number(); i
++)
1316 stringList
->Add(choice
->GetString(i
));
1318 return new wxProperty(name
, stringList
, "stringlist");
1320 else if (name
== "sort")
1322 bool sort
= ((m_propertyWindow
->GetWindowStyleFlag() & wxCB_SORT
) == wxCB_SORT
);
1323 return new wxProperty(name
, sort
, "bool");
1325 else if (name
== "style")
1327 wxString
styleStr("dropdown");
1328 if (m_propertyWindow
->GetWindowStyleFlag() & wxCB_SIMPLE
)
1329 styleStr
= "simple";
1330 else if (m_propertyWindow
->GetWindowStyleFlag() & wxCB_READONLY
)
1331 styleStr
= "readonly";
1333 styleStr
= "dropdown";
1335 return new wxProperty(name
, styleStr
, "string",
1336 new wxStringListValidator(new wxStringList("simple", "dropdown", "readonly",
1340 return wxItemPropertyInfo::GetProperty(name
);
1343 bool wxComboBoxPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1345 wxComboBox
*choice
= (wxComboBox
*)m_propertyWindow
;
1346 if (name
== "values")
1349 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
1352 char *s
= expr
->StringValue();
1355 expr
= expr
->GetNext();
1357 if (choice
->Number() > 0)
1358 choice
->SetSelection(0);
1361 else if (name
== "sort")
1363 SetWindowStyle(m_propertyWindow
, wxCB_SORT
, property
->GetValue().BoolValue());
1365 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
1366 resource
->SetStyle(m_propertyWindow
->GetWindowStyleFlag());
1368 m_propertyWindow
= wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(m_propertyWindow
, this);
1371 else if (name
== "style")
1373 SetWindowStyle(m_propertyWindow
, wxCB_SIMPLE
, FALSE
);
1374 SetWindowStyle(m_propertyWindow
, wxCB_DROPDOWN
, FALSE
);
1375 SetWindowStyle(m_propertyWindow
, wxCB_READONLY
, FALSE
);
1377 wxString
styleStr(property
->GetValue().StringValue());
1378 if (styleStr
== "simple")
1379 SetWindowStyle(m_propertyWindow
, wxCB_SIMPLE
, TRUE
);
1380 else if (styleStr
== "dropdown")
1381 SetWindowStyle(m_propertyWindow
, wxCB_DROPDOWN
, TRUE
);
1382 else if (styleStr
== "readonly")
1383 SetWindowStyle(m_propertyWindow
, wxCB_READONLY
, TRUE
);
1386 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
1387 resource
->SetStyle(m_propertyWindow
->GetWindowStyleFlag());
1389 m_propertyWindow
= wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(m_propertyWindow
, this);
1394 return wxItemPropertyInfo::SetProperty(name
, property
);
1397 void wxComboBoxPropertyInfo::GetPropertyNames(wxStringList
& names
)
1399 wxItemPropertyInfo::GetPropertyNames(names
);
1400 names
.Add("values");
1405 bool wxComboBoxPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1407 wxComboBox
*choice
= (wxComboBox
*)m_propertyWindow
;
1409 if (choice
->Number() == 0)
1410 resource
->SetStringValues(NULL
);
1415 for (i
= 0; i
< choice
->Number(); i
++)
1416 slist
.Add(choice
->GetString(i
));
1418 resource
->SetStringValues(slist
);
1420 return wxItemPropertyInfo::InstantiateResource(resource
);
1427 wxProperty
*wxRadioBoxPropertyInfo::GetProperty(wxString
& name
)
1429 wxRadioBox
*radioBox
= (wxRadioBox
*)m_propertyWindow
;
1430 if (name
== "numberRowsOrCols")
1432 return new wxProperty("numberRowsOrCols", (long)radioBox
->GetNumberOfRowsOrCols(), "integer");
1434 if (name
== "orientation")
1437 if (m_propertyWindow
->GetWindowStyleFlag() & wxRA_SPECIFY_COLS
)
1438 orient
= "wxRA_SPECIFY_COLS";
1440 orient
= "wxRA_SPECIFY_ROWS";
1442 return new wxProperty("orientation", orient
, "string",
1443 new wxStringListValidator(new wxStringList("wxRA_SPECIFY_COLS", "wxRA_SPECIFY_ROWS",
1446 else if (name
== "values")
1448 wxStringList
*stringList
= new wxStringList
;
1450 for (i
= 0; i
< radioBox
->Number(); i
++)
1451 stringList
->Add(radioBox
->GetString(i
));
1453 return new wxProperty(name
, stringList
, "stringlist");
1455 return wxItemPropertyInfo::GetProperty(name
);
1458 bool wxRadioBoxPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1460 wxRadioBox
*radioBox
= (wxRadioBox
*)m_propertyWindow
;
1461 if (name
== "numberRowsOrCols")
1463 radioBox
->SetNumberOfRowsOrCols((int)property
->GetValue().IntegerValue());
1464 m_propertyWindow
= wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox
, this);
1467 else if (name
== "orientation")
1469 long windowStyle
= radioBox
->GetWindowStyleFlag();
1470 wxString
val(property
->GetValue().StringValue());
1471 if (val
== "wxRA_SPECIFY_COLS")
1473 if (windowStyle
& wxRA_SPECIFY_ROWS
)
1474 windowStyle
-= wxRA_SPECIFY_ROWS
;
1475 windowStyle
|= wxRA_SPECIFY_COLS
;
1479 if (windowStyle
& wxRA_SPECIFY_COLS
)
1480 windowStyle
-= wxRA_SPECIFY_COLS
;
1481 windowStyle
|= wxRA_SPECIFY_ROWS
;
1483 radioBox
->SetWindowStyleFlag(windowStyle
);
1484 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(radioBox
);
1485 resource
->SetStyle(windowStyle
);
1487 m_propertyWindow
= wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox
, this);
1490 else if (name
== "values")
1492 // Set property into *resource*, not wxRadioBox, and then recreate
1493 // the wxRadioBox. This is because we can't dynamically set the strings
1495 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
1499 wxStringList stringList
;
1500 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
1503 char *s
= expr
->StringValue();
1506 expr
= expr
->GetNext();
1508 resource
->SetStringValues(stringList
);
1509 m_propertyWindow
= wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox
, this);
1512 return wxItemPropertyInfo::SetProperty(name
, property
);
1515 void wxRadioBoxPropertyInfo::GetPropertyNames(wxStringList
& names
)
1517 wxItemPropertyInfo::GetPropertyNames(names
);
1519 names
.Add("values");
1520 names
.Add("orientation");
1521 names
.Add("numberRowsOrCols");
1524 bool wxRadioBoxPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1526 wxRadioBox
*rbox
= (wxRadioBox
*)m_propertyWindow
;
1527 // Take strings from resource instead
1530 if (rbox->Number() == 0)
1531 resource->SetStringValues(NULL);
1534 wxStringList *slist = new wxStringList;
1536 for (i = 0; i < rbox->Number(); i++)
1537 slist->Add(rbox->GetString(i));
1539 resource->SetStringValues(slist);
1542 resource
->SetValue1(rbox
->GetNumberOfRowsOrCols());
1543 return wxItemPropertyInfo::InstantiateResource(resource
);
1550 wxProperty
*wxGroupBoxPropertyInfo::GetProperty(wxString
& name
)
1552 return wxItemPropertyInfo::GetProperty(name
);
1555 bool wxGroupBoxPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1557 return wxItemPropertyInfo::SetProperty(name
, property
);
1560 void wxGroupBoxPropertyInfo::GetPropertyNames(wxStringList
& names
)
1562 wxItemPropertyInfo::GetPropertyNames(names
);
1566 bool wxGroupBoxPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1568 return wxItemPropertyInfo::InstantiateResource(resource
);
1575 wxProperty
*wxCheckBoxPropertyInfo::GetProperty(wxString
& name
)
1577 wxCheckBox
*checkBox
= (wxCheckBox
*)m_propertyWindow
;
1578 if (name
== "value")
1579 return new wxProperty("value", checkBox
->GetValue(), "bool");
1581 return wxItemPropertyInfo::GetProperty(name
);
1584 bool wxCheckBoxPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1586 wxCheckBox
*checkBox
= (wxCheckBox
*)m_propertyWindow
;
1587 if (name
== "value")
1589 checkBox
->SetValue((bool)property
->GetValue().BoolValue());
1593 return wxItemPropertyInfo::SetProperty(name
, property
);
1596 void wxCheckBoxPropertyInfo::GetPropertyNames(wxStringList
& names
)
1598 wxItemPropertyInfo::GetPropertyNames(names
);
1603 bool wxCheckBoxPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1605 wxCheckBox
*cbox
= (wxCheckBox
*)m_propertyWindow
;
1606 resource
->SetValue1(cbox
->GetValue());
1607 return wxItemPropertyInfo::InstantiateResource(resource
);
1614 wxProperty
*wxRadioButtonPropertyInfo::GetProperty(wxString
& name
)
1616 wxRadioButton
*checkBox
= (wxRadioButton
*)m_propertyWindow
;
1617 if (name
== "value")
1618 return new wxProperty("value", checkBox
->GetValue(), "bool");
1620 return wxItemPropertyInfo::GetProperty(name
);
1623 bool wxRadioButtonPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1625 wxRadioButton
*checkBox
= (wxRadioButton
*)m_propertyWindow
;
1626 if (name
== "value")
1628 checkBox
->SetValue((bool)property
->GetValue().BoolValue());
1632 return wxItemPropertyInfo::SetProperty(name
, property
);
1635 void wxRadioButtonPropertyInfo::GetPropertyNames(wxStringList
& names
)
1637 wxItemPropertyInfo::GetPropertyNames(names
);
1642 bool wxRadioButtonPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1644 wxRadioButton
*cbox
= (wxRadioButton
*)m_propertyWindow
;
1645 resource
->SetValue1(cbox
->GetValue());
1646 return wxItemPropertyInfo::InstantiateResource(resource
);
1653 wxProperty
*wxSliderPropertyInfo::GetProperty(wxString
& name
)
1655 wxSlider
*slider
= (wxSlider
*)m_propertyWindow
;
1656 if (name
== "value")
1657 return new wxProperty("value", (long)slider
->GetValue(), "integer");
1658 else if (name
== "orientation")
1661 if (m_propertyWindow
->GetWindowStyleFlag() & wxHORIZONTAL
)
1662 pos
= "wxHORIZONTAL";
1666 return new wxProperty("orientation", pos
, "string",
1667 new wxStringListValidator(new wxStringList("wxHORIZONTAL", "wxVERTICAL",
1670 else if (name
== "minValue")
1671 return new wxProperty("minValue", (long)slider
->GetMin(), "integer");
1672 else if (name
== "maxValue")
1673 return new wxProperty("maxValue", (long)slider
->GetMax(), "integer");
1675 return wxItemPropertyInfo::GetProperty(name
);
1678 bool wxSliderPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1680 wxSlider
*slider
= (wxSlider
*)m_propertyWindow
;
1681 if (name
== "value")
1683 slider
->SetValue((int)property
->GetValue().IntegerValue());
1686 else if (name
== "orientation")
1688 long windowStyle
= slider
->GetWindowStyleFlag();
1689 long oldWindowStyle
= windowStyle
;
1690 wxString
val(property
->GetValue().StringValue());
1691 if (val
== "wxHORIZONTAL")
1693 if (windowStyle
& wxVERTICAL
)
1694 windowStyle
-= wxVERTICAL
;
1695 windowStyle
|= wxHORIZONTAL
;
1699 if (windowStyle
& wxHORIZONTAL
)
1700 windowStyle
-= wxHORIZONTAL
;
1701 windowStyle
|= wxVERTICAL
;
1704 if (oldWindowStyle
== windowStyle
)
1707 slider
->SetWindowStyleFlag(windowStyle
);
1709 // If the window style has changed, we swap the width and height parameters.
1711 slider
->GetSize(&w
, &h
);
1713 slider
= (wxSlider
*)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(slider
, this);
1714 slider
->SetSize(-1, -1, h
, w
);
1715 m_propertyWindow
= slider
;
1719 else if (name
== "minValue")
1721 slider
->SetRange((int)property
->GetValue().IntegerValue(), slider
->GetMax());
1724 else if (name
== "maxValue")
1726 slider
->SetRange(slider
->GetMin(), (int)property
->GetValue().IntegerValue());
1730 return wxItemPropertyInfo::SetProperty(name
, property
);
1733 void wxSliderPropertyInfo::GetPropertyNames(wxStringList
& names
)
1735 wxItemPropertyInfo::GetPropertyNames(names
);
1737 names
.Add("orientation");
1738 names
.Add("minValue");
1739 names
.Add("maxValue");
1742 bool wxSliderPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1744 wxSlider
*slider
= (wxSlider
*)m_propertyWindow
;
1745 resource
->SetValue1(slider
->GetValue());
1746 resource
->SetValue2(slider
->GetMin());
1747 resource
->SetValue3(slider
->GetMax());
1748 return wxItemPropertyInfo::InstantiateResource(resource
);
1755 wxProperty
*wxGaugePropertyInfo::GetProperty(wxString
& name
)
1757 wxGauge
*gauge
= (wxGauge
*)m_propertyWindow
;
1758 if (name
== "value")
1759 return new wxProperty("value", (long)gauge
->GetValue(), "integer");
1760 else if (name
== "maxValue")
1761 return new wxProperty("maxValue", (long)gauge
->GetRange(), "integer");
1763 return wxItemPropertyInfo::GetProperty(name
);
1766 bool wxGaugePropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1768 wxGauge
*gauge
= (wxGauge
*)m_propertyWindow
;
1769 if (name
== "value")
1771 gauge
->SetValue((int)property
->GetValue().IntegerValue());
1774 else if (name
== "maxValue")
1776 gauge
->SetRange((int)property
->GetValue().IntegerValue());
1780 return wxItemPropertyInfo::SetProperty(name
, property
);
1783 void wxGaugePropertyInfo::GetPropertyNames(wxStringList
& names
)
1785 wxItemPropertyInfo::GetPropertyNames(names
);
1787 names
.Add("maxValue");
1790 bool wxGaugePropertyInfo::InstantiateResource(wxItemResource
*resource
)
1792 wxGauge
*gauge
= (wxGauge
*)m_propertyWindow
;
1793 resource
->SetValue1(gauge
->GetValue());
1794 resource
->SetValue2(gauge
->GetRange());
1795 return wxItemPropertyInfo::InstantiateResource(resource
);
1802 wxProperty
*wxScrollBarPropertyInfo::GetProperty(wxString
& name
)
1804 wxScrollBar
*scrollBar
= (wxScrollBar
*)m_propertyWindow
;
1805 if (name
== "thumbPosition")
1806 return new wxProperty("value", (long)scrollBar
->GetThumbPosition(), "integer");
1807 else if (name
== "orientation")
1810 if (m_propertyWindow
->GetWindowStyleFlag() & wxHORIZONTAL
)
1811 pos
= "wxHORIZONTAL";
1815 return new wxProperty("orientation", pos
, "string",
1816 new wxStringListValidator(new wxStringList("wxHORIZONTAL", "wxVERTICAL",
1819 else if (name
== "pageSize")
1821 int pageLength
= scrollBar
->GetPageSize();
1823 return new wxProperty("pageSize", (long)pageLength
, "integer");
1825 else if (name
== "thumbSize")
1827 int thumbSize
= scrollBar
->GetThumbSize();
1829 return new wxProperty("thumbSize", (long)thumbSize
, "integer");
1831 else if (name
== "range")
1833 int range
= scrollBar
->GetRange();
1834 return new wxProperty("range", (long)range
, "integer");
1837 return wxItemPropertyInfo::GetProperty(name
);
1840 bool wxScrollBarPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1842 wxScrollBar
*scrollBar
= (wxScrollBar
*)m_propertyWindow
;
1843 if (name
== "thumbPosition")
1845 scrollBar
->SetThumbPosition((int)property
->GetValue().IntegerValue());
1848 else if (name
== "orientation")
1850 long windowStyle
= scrollBar
->GetWindowStyleFlag();
1851 long oldWindowStyle
= windowStyle
;
1852 wxString
val(property
->GetValue().StringValue());
1853 if (val
== "wxHORIZONTAL")
1855 if (windowStyle
& wxVERTICAL
)
1856 windowStyle
-= wxVERTICAL
;
1857 windowStyle
|= wxHORIZONTAL
;
1861 if (windowStyle
& wxHORIZONTAL
)
1862 windowStyle
-= wxHORIZONTAL
;
1863 windowStyle
|= wxVERTICAL
;
1866 if (oldWindowStyle
== windowStyle
)
1869 scrollBar
->SetWindowStyleFlag(windowStyle
);
1871 // If the window style has changed, we swap the width and height parameters.
1873 // scrollBar->GetSize(&w, &h);
1874 wxItemResource
*item
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(scrollBar
);
1876 item
->SetSize(item
->GetX(), item
->GetY(), item
->GetHeight(), item
->GetWidth());
1877 item
->SetStyle(windowStyle
);
1880 scrollBar
= (wxScrollBar
*)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(scrollBar
, this);
1881 m_propertyWindow
= scrollBar
;
1885 else if (name
== "pageSize")
1887 int pos
= scrollBar
->GetThumbPosition();
1888 int range
= scrollBar
->GetRange();
1889 int thumbSize
= scrollBar
->GetThumbSize();
1890 scrollBar
->SetScrollbar(pos
, thumbSize
, range
, (int)property
->GetValue().IntegerValue());
1893 else if (name
== "thumbSize")
1895 int pos
= scrollBar
->GetThumbPosition();
1896 int range
= scrollBar
->GetRange();
1897 int pageSize
= scrollBar
->GetPageSize();
1898 scrollBar
->SetScrollbar(pos
, (int)property
->GetValue().IntegerValue(), range
, pageSize
);
1901 else if (name
== "range")
1903 int pos
= scrollBar
->GetThumbPosition();
1904 int thumbSize
= scrollBar
->GetThumbSize();
1905 int pageSize
= scrollBar
->GetPageSize();
1906 scrollBar
->SetScrollbar(pos
, thumbSize
, (int)property
->GetValue().IntegerValue(), pageSize
);
1910 return wxItemPropertyInfo::SetProperty(name
, property
);
1913 void wxScrollBarPropertyInfo::GetPropertyNames(wxStringList
& names
)
1915 wxItemPropertyInfo::GetPropertyNames(names
);
1916 names
.Add("orientation");
1917 names
.Add("thumbPosition");
1918 names
.Add("thumbSize");
1919 names
.Add("pageSize");
1922 // Remove some properties we don't inherit
1923 names
.Delete("fontPoints");
1924 names
.Delete("fontFamily");
1925 names
.Delete("fontStyle");
1926 names
.Delete("fontWeight");
1927 names
.Delete("fontUnderlined");
1930 bool wxScrollBarPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1932 wxScrollBar
*sbar
= (wxScrollBar
*)m_propertyWindow
;
1934 int thumbPosition
= sbar
->GetThumbPosition();
1935 int thumbSize
= sbar
->GetThumbSize();
1936 int pageSize
= sbar
->GetPageSize();
1937 int range
= sbar
->GetRange();
1939 resource
->SetValue1(thumbPosition
);
1940 resource
->SetValue2(thumbSize
);
1941 resource
->SetValue3(range
);
1942 resource
->SetValue5(pageSize
);
1944 return wxItemPropertyInfo::InstantiateResource(resource
);
1951 wxProperty
*wxPanelPropertyInfo::GetProperty(wxString
& name
)
1953 wxPanel
*panelWindow
= (wxPanel
*)m_propertyWindow
;
1956 wxFont *labelFont = panelWindow->GetLabelFont();
1957 wxFont *buttonFont = panelWindow->GetButtonFont();
1959 if (name == "labelFontPoints" || name == "labelFontFamily" || name == "labelFontStyle" || name == "labelFontWeight" ||
1960 name == "labelFontUnderlined")
1961 return GetFontProperty(name, labelFont);
1962 else if (name == "buttonFontPoints" || name == "buttonFontFamily" || name == "buttonFontStyle" || name == "buttonFontWeight" ||
1963 name == "buttonFontUnderlined")
1964 return GetFontProperty(name, buttonFont);
1970 if (panelWindow
->GetWindowStyleFlag() & wxNO_3D
)
1973 userColours
= FALSE
;
1975 return new wxProperty(name
, (bool)userColours
, "bool");
1977 else if (name
== "backgroundColour")
1979 wxColour
col(panelWindow
->GetBackgroundColour());
1981 wxDecToHex(col
.Red(), buf
);
1982 wxDecToHex(col
.Green(), buf
+2);
1983 wxDecToHex(col
.Blue(), buf
+4);
1985 return new wxProperty(name
, buf
, "string", new wxColourListValidator
);
1987 else if (name
== "title")
1989 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
1991 return new wxProperty(name
, resource
->GetTitle(), "string");
1993 return new wxProperty(name
, "Could not get title", "string");
1995 else if (name
== "caption")
1997 return new wxProperty(name
, ((panelWindow
->GetWindowStyleFlag() & wxCAPTION
) == wxCAPTION
),
2000 else if (name
== "systemMenu")
2002 return new wxProperty(name
, ((panelWindow
->GetWindowStyleFlag() & wxSYSTEM_MENU
) == wxSYSTEM_MENU
),
2005 else if (name
== "thickFrame")
2007 return new wxProperty(name
, ((panelWindow
->GetWindowStyleFlag() & wxTHICK_FRAME
) == wxTHICK_FRAME
),
2010 else if (name
== "useSystemDefaults")
2012 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
2013 return new wxProperty(name
, ((resource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) == wxRESOURCE_USE_DEFAULTS
),
2016 else if (name
== "useDialogUnits")
2018 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
2019 return new wxProperty(name
, ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) == wxRESOURCE_DIALOG_UNITS
),
2023 return wxWindowPropertyInfo::GetProperty(name
);
2026 bool wxPanelPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
2028 wxPanel
*panelWindow
= (wxPanel
*)m_propertyWindow
;
2030 wxFont *labelFont = panelWindow->GetLabelFont();
2031 wxFont *buttonFont = panelWindow->GetButtonFont();
2033 if (labelFont && (name == "labelFontPoints" || name == "labelFontFamily" || name == "labelFontStyle" || name == "labelFontWeight" || name == "labelFontUnderlined" ))
2035 wxFont *newFont = SetFontProperty(name, property, labelFont);
2037 panelWindow->SetLabelFont(* newFont);
2040 else if (buttonFont && (name == "buttonFontPoints" || name == "buttonFontFamily" || name == "buttonFontStyle" || name == "buttonFontWeight" || name == "buttonFontUnderlined" ))
2042 wxFont *newFont = SetFontProperty(name, property, buttonFont);
2044 panelWindow->SetButtonFont(* newFont);
2051 bool userColours
= property
->GetValue().BoolValue();
2055 if ((panelWindow
->GetWindowStyleFlag() & wxNO_3D
) != wxNO_3D
)
2056 panelWindow
->SetWindowStyleFlag(panelWindow
->GetWindowStyleFlag() | wxNO_3D
);
2060 if ((panelWindow
->GetWindowStyleFlag() & wxNO_3D
) == wxNO_3D
)
2061 panelWindow
->SetWindowStyleFlag(panelWindow
->GetWindowStyleFlag() - wxNO_3D
);
2063 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
2064 resource
->SetStyle(panelWindow
->GetWindowStyleFlag());
2066 panelWindow
= (wxPanel
*)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(panelWindow
, this);
2069 else if (name
== "backgroundColour")
2071 char *hex
= property
->GetValue().StringValue();
2072 int r
= wxHexToDec(hex
);
2073 int g
= wxHexToDec(hex
+2);
2074 int b
= wxHexToDec(hex
+4);
2076 wxColour
col(r
,g
,b
);
2077 panelWindow
->SetBackgroundColour(col
);
2078 panelWindow
= (wxPanel
*)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(panelWindow
, this);
2079 m_propertyWindow
= panelWindow
;
2082 else if (name
== "title")
2084 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
2087 resource
->SetTitle(property
->GetValue().StringValue());
2093 else if (name
== "caption")
2095 SetWindowStyle(panelWindow
, wxCAPTION
, property
->GetValue().BoolValue());
2097 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
2098 resource
->SetStyle(panelWindow
->GetWindowStyleFlag());
2101 else if (name
== "thickFrame")
2103 SetWindowStyle(panelWindow
, wxTHICK_FRAME
, property
->GetValue().BoolValue());
2105 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
2106 resource
->SetStyle(panelWindow
->GetWindowStyleFlag());
2109 else if (name
== "systemMenu")
2111 SetWindowStyle(panelWindow
, wxSYSTEM_MENU
, property
->GetValue().BoolValue());
2113 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
2114 resource
->SetStyle(panelWindow
->GetWindowStyleFlag());
2117 else if (name
== "useSystemDefaults")
2119 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
2120 bool useDefaults
= property
->GetValue().BoolValue();
2121 long style
= resource
->GetResourceStyle();
2124 if ((style
& wxRESOURCE_USE_DEFAULTS
) == 0)
2125 style
|= wxRESOURCE_USE_DEFAULTS
;
2129 if ((style
& wxRESOURCE_USE_DEFAULTS
) != 0)
2130 style
-= wxRESOURCE_USE_DEFAULTS
;
2132 resource
->SetResourceStyle(style
);
2133 panelWindow
= (wxPanel
*)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(panelWindow
, this);
2136 else if (name
== "useDialogUnits")
2138 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
2139 bool useDialogUnits
= property
->GetValue().BoolValue();
2140 long style
= resource
->GetResourceStyle();
2143 if ((style
& wxRESOURCE_DIALOG_UNITS
) == 0)
2145 style
|= wxRESOURCE_DIALOG_UNITS
;
2146 ConvertDialogUnits(TRUE
); // Convert all resources
2151 if ((style
& wxRESOURCE_DIALOG_UNITS
) != 0)
2153 style
-= wxRESOURCE_DIALOG_UNITS
;
2154 ConvertDialogUnits(FALSE
); // Convert all resources
2157 resource
->SetResourceStyle(style
);
2158 panelWindow
= (wxPanel
*)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(panelWindow
, this);
2159 m_propertyWindow
= panelWindow
;
2160 // TODO: need to regenerate the width and height properties else they'll be inconsistent.
2164 return wxWindowPropertyInfo::SetProperty(name
, property
);
2167 void wxPanelPropertyInfo::GetPropertyNames(wxStringList
& names
)
2169 wxWindowPropertyInfo::GetPropertyNames(names
);
2173 names
.Add("backgroundColour");
2174 names
.Add("caption");
2175 names
.Add("systemMenu");
2176 names
.Add("thickFrame");
2177 names
.Add("useSystemDefaults");
2178 names
.Add("useDialogUnits");
2181 bool wxPanelPropertyInfo::InstantiateResource(wxItemResource
*resource
)
2183 wxPanel
*panel
= (wxPanel
*)m_propertyWindow
;
2184 if (panel
->GetFont().Ok())
2185 resource
->SetFont(* wxTheFontList
->FindOrCreateFont(panel
->GetFont().GetPointSize(),
2186 panel
->GetFont().GetFamily(), panel
->GetFont().GetStyle(), panel
->GetFont().GetWeight(),
2187 panel
->GetFont().GetUnderlined(), panel
->GetFont().GetFaceName()));
2189 resource
->SetBackgroundColour(wxColour(panel
->GetBackgroundColour()));
2191 return wxWindowPropertyInfo::InstantiateResource(resource
);
2194 // Convert this dialog, and its children, to or from dialog units
2195 void wxPanelPropertyInfo::ConvertDialogUnits(bool toDialogUnits
)
2197 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
2203 sz
= m_propertyWindow
->ConvertPixelsToDialog(wxSize(resource
->GetWidth(), resource
->GetHeight()));
2204 pt
= m_propertyWindow
->ConvertPixelsToDialog(wxPoint(resource
->GetX(), resource
->GetY()));
2208 sz
= m_propertyWindow
->ConvertDialogToPixels(wxSize(resource
->GetWidth(), resource
->GetHeight()));
2209 pt
= m_propertyWindow
->ConvertDialogToPixels(wxPoint(resource
->GetX(), resource
->GetY()));
2211 resource
->SetSize(pt
.x
, pt
.y
, sz
.x
, sz
.y
);
2213 wxNode
* node
= m_propertyWindow
->GetChildren().First();
2216 wxWindow
* child
= (wxWindow
*) node
->Data();
2217 if (child
->IsKindOf(CLASSINFO(wxControl
)))
2219 resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(child
);
2222 sz
= m_propertyWindow
->ConvertPixelsToDialog(wxSize(resource
->GetWidth(), resource
->GetHeight()));
2223 pt
= m_propertyWindow
->ConvertPixelsToDialog(wxPoint(resource
->GetX(), resource
->GetY()));
2227 sz
= m_propertyWindow
->ConvertDialogToPixels(wxSize(resource
->GetWidth(), resource
->GetHeight()));
2228 pt
= m_propertyWindow
->ConvertDialogToPixels(wxPoint(resource
->GetX(), resource
->GetY()));
2230 resource
->SetSize(pt
.x
, pt
.y
, sz
.x
, sz
.y
);
2232 node
= node
->Next();
2241 wxProperty
*wxDialogPropertyInfo::GetProperty(wxString
& name
)
2243 wxDialog
*dialogWindow
= (wxDialog
*)m_propertyWindow
;
2244 if (name
== "modal")
2246 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(dialogWindow
);
2250 bool modal
= (resource
->GetValue1() != 0);
2251 return new wxProperty(name
, modal
, "bool");
2254 return wxPanelPropertyInfo::GetProperty(name
);
2257 bool wxDialogPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
2259 wxDialog
*dialogWindow
= (wxDialog
*)m_propertyWindow
;
2261 if (name
== "modal")
2263 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(dialogWindow
);
2267 resource
->SetValue1(property
->GetValue().BoolValue());
2271 return wxPanelPropertyInfo::SetProperty(name
, property
);
2274 void wxDialogPropertyInfo::GetPropertyNames(wxStringList
& names
)
2276 wxPanelPropertyInfo::GetPropertyNames(names
);
2281 bool wxDialogPropertyInfo::InstantiateResource(wxItemResource
*resource
)
2283 wxDialog
*dialog
= (wxDialog
*)m_propertyWindow
;
2284 wxString
str(dialog
->GetTitle());
2285 resource
->SetTitle(str
);
2287 return wxPanelPropertyInfo::InstantiateResource(resource
);
2295 int wxStringToFontWeight(wxString
& val
)
2297 if (val
== "wxBOLD") return wxBOLD
;
2298 else if (val
== "wxLIGHT") return wxLIGHT
;
2299 else return wxNORMAL
;
2302 int wxStringToFontStyle(wxString
& val
)
2304 if (val
== "wxITALIC") return wxITALIC
;
2305 else if (val
== "wxSLANT") return wxSLANT
;
2306 else return wxNORMAL
;
2309 int wxStringToFontFamily(wxString
& val
)
2311 if (val
== "wxDECORATIVE") return wxDECORATIVE
;
2312 else if (val
== "wxROMAN") return wxROMAN
;
2313 else if (val
== "wxSCRIPT") return wxSCRIPT
;
2314 else if (val
== "wxMODERN") return wxMODERN
;
2315 else if (val
== "wxTELETYPE") return wxTELETYPE
;
2316 else return wxSWISS
;
2320 /// Resource symbol validator
2322 IMPLEMENT_DYNAMIC_CLASS(wxResourceSymbolValidator
, wxPropertyListValidator
)
2324 wxResourceSymbolValidator::wxResourceSymbolValidator(long flags
):
2325 wxPropertyListValidator(flags
)
2329 wxResourceSymbolValidator::~wxResourceSymbolValidator(void)
2333 bool wxResourceSymbolValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
2338 // Called when TICK is pressed or focus is lost or view wants to update
2339 // the property list.
2340 // Does the transferance from the property editing area to the property itself
2341 bool wxResourceSymbolValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
2343 if (!view
->GetValueText())
2345 wxString
value(view
->GetValueText()->GetValue());
2346 property
->GetValue() = value
;
2350 // Called when TICK is pressed or focus is lost or view wants to update
2351 // the property list.
2352 // Does the transferance from the property editing area to the property itself
2353 bool wxResourceSymbolValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
2355 if (!view
->GetValueText())
2357 wxString
str(property
->GetValue().GetStringRepresentation());
2358 view
->GetValueText()->SetValue(str
);
2362 // Called when the property is double clicked. Extra functionality can be provided,
2363 // cycling through possible values.
2364 bool wxResourceSymbolValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
2366 if (!view
->GetValueText())
2368 OnEdit(property
, view
, parentWindow
);
2372 bool wxResourceSymbolValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
2374 if (view
->GetConfirmButton())
2375 view
->GetConfirmButton()->Enable(TRUE
);
2376 if (view
->GetCancelButton())
2377 view
->GetCancelButton()->Enable(TRUE
);
2378 if (view
->GetEditButton())
2379 view
->GetEditButton()->Enable(TRUE
);
2380 if (view
->GetValueText())
2381 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
2385 void wxResourceSymbolValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
2387 if (!view
->GetValueText())
2390 wxResourceSymbolDialog
* dialog
= new wxResourceSymbolDialog(parentWindow
, -1, "Edit Symbol");
2392 // Split name/id pair e.g. "IDC_TEXT=123"
2393 wxString
value(property
->GetValue().StringValue());
2395 wxString strName
= value
.Before('=');
2396 wxString strId
= value
.After('=');
2398 dialog
->SetSymbol(strName
);
2399 dialog
->SetId(atoi(strId
));
2403 if (dialog
->ShowModal() == wxID_OK
)
2405 wxString
symbolName(dialog
->GetSymbol());
2406 long id
= dialog
->GetId();
2409 str
.Printf("%d", id
);
2410 property
->GetValue() = symbolName
+ wxString("=") + str
;
2412 view
->DisplayProperty(property
);
2413 view
->UpdatePropertyDisplayInList(property
);
2414 view
->OnPropertyChanged(property
);
2416 // Moved from the 'if' branch on suggestion of Roman Pavlov
2420 BEGIN_EVENT_TABLE(wxResourceSymbolDialog
, wxDialog
)
2421 EVT_BUTTON(wxID_OK
, wxResourceSymbolDialog::OnOK
)
2422 EVT_COMBOBOX(ID_SYMBOLNAME_COMBOBOX
, wxResourceSymbolDialog::OnComboBoxSelect
)
2423 EVT_TEXT(ID_SYMBOLNAME_COMBOBOX
, wxResourceSymbolDialog::OnSymbolNameUpdate
)
2426 wxResourceSymbolDialog::wxResourceSymbolDialog(wxWindow
* parent
, const wxWindowID id
, const wxString
& title
, const wxPoint
& pos
,
2427 const wxSize
& size
, long style
):
2428 wxDialog(parent
, id
, title
, pos
, size
, style
)
2433 (void) new wxStaticText(this, -1, "Name: ", wxPoint(x
, y
));
2437 m_nameCtrl
= new wxComboBox(this, ID_SYMBOLNAME_COMBOBOX
, "",
2438 wxPoint(x
, y
), wxSize(200, -1), 0, NULL
, wxCB_DROPDOWN
|wxCB_SORT
);
2443 (void) new wxStaticText(this, -1, "Id: ", wxPoint(x
, y
));
2447 m_idCtrl
= new wxTextCtrl(this, ID_SYMBOLID_TEXTCTRL
, "",
2448 wxPoint(x
, y
), wxSize(200, -1));
2452 (void) new wxButton(this, wxID_OK
, "OK", wxPoint(x
, y
), wxSize(80, -1));
2455 (void) new wxButton(this, wxID_CANCEL
, "Cancel", wxPoint(x
, y
), wxSize(80, -1));
2461 void wxResourceSymbolDialog::Init()
2464 defaultId
.Printf("%ld", m_symbolId
);
2466 m_nameCtrl
->SetValue(m_symbolName
);
2467 m_idCtrl
->SetValue(defaultId
);
2469 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().FillComboBox(m_nameCtrl
);
2472 void wxResourceSymbolDialog::OnOK(wxCommandEvent
& event
)
2476 wxDialog::OnOK(event
);
2480 bool wxResourceSymbolDialog::CheckValues()
2482 wxString
nameStr(m_nameCtrl
->GetValue());
2483 wxString
idStr(m_idCtrl
->GetValue());
2484 int id
= atoi(idStr
);
2488 wxMessageBox("Identifier cannot be missing or zero", "Dialog Editor", wxOK
|wxICON_EXCLAMATION
, this);
2493 wxMessageBox("Please enter a symbol name", "Dialog Editor", wxOK
|wxICON_EXCLAMATION
, this);
2496 if (nameStr
.Contains(" "))
2498 wxMessageBox("Symbol name cannot contain spaces.", "Dialog Editor", wxOK
|wxICON_EXCLAMATION
, this);
2501 if (nameStr
.Contains("="))
2503 wxMessageBox("Symbol name cannot contain =.", "Dialog Editor", wxOK
|wxICON_EXCLAMATION
, this);
2506 if (nameStr
.IsNumber())
2508 wxMessageBox("Symbol name cannot be a number.", "Dialog Editor", wxOK
|wxICON_EXCLAMATION
, this);
2511 // TODO: other checks on the name syntax.
2513 if (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(nameStr
))
2515 // If we change the id for an existing symbol, we need to:
2516 // 1) Check if there are any other resources currently using the original id.
2517 // If so, will need to change their id to the new id, in SetProperty.
2518 // 2) Remove the old symbol, add the new symbol.
2519 // In this check, we don't have to do this, but we need to do it in SetProperty.
2521 if (nameStr
== GetSymbol() && id
!= GetId())
2523 // It's OK to change the id. But we'll need to change all matching ids in all resources,
2527 // If we change the name but not the id... we'll just need to remove and
2528 // re-add the symbol/id pair, in SetProperty.
2529 if (nameStr
!= GetSymbol() && id
== GetId())
2533 // What if we're changing both the name and the id?
2534 // - if there's no symbol of that name, just remove the old, add the new (in SetProperty)
2535 // - if there is a symbol of that name, if id matches, do nothing. If not, veto.
2537 if (nameStr
!= GetSymbol() && id
!= GetId())
2539 if (!wxResourceManager::GetCurrentResourceManager()->IsIdentifierOK(nameStr
, id
))
2541 wxMessageBox("This integer id is already being used under a different name.\nPlease choose another.",
2542 "Dialog Editor", wxOK
|wxICON_EXCLAMATION
, this);
2555 void wxResourceSymbolDialog::OnComboBoxSelect(wxCommandEvent
& WXUNUSED(event
))
2557 wxString
str(m_nameCtrl
->GetStringSelection());
2558 if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(str
))
2560 int id
= wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str
);
2562 str2
.Printf("%d", id
);
2563 m_idCtrl
->SetValue(str2
);
2564 m_idCtrl
->Enable(FALSE
);
2568 if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().SymbolExists(str
))
2570 int id
= wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str
);
2572 str2
.Printf("%d", id
);
2573 m_idCtrl
->SetValue(str2
);
2575 m_idCtrl
->Enable(TRUE
);
2579 void wxResourceSymbolDialog::OnSymbolNameUpdate(wxCommandEvent
& WXUNUSED(event
))
2581 wxString
str(m_nameCtrl
->GetValue());
2582 if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(str
))
2584 int id
= wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str
);
2586 str2
.Printf("%d", id
);
2587 m_idCtrl
->SetValue(str2
);
2588 m_idCtrl
->Enable(FALSE
);
2592 if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().SymbolExists(str
))
2594 int id
= wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str
);
2596 str2
.Printf("%d", id
);
2597 m_idCtrl
->SetValue(str2
);
2599 m_idCtrl
->Enable(TRUE
);