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 m_propertyInfo
->SetProperty(property
->GetName(), property
);
53 property
->GetValue().SetModified(FALSE
);
54 wxResourceManager::GetCurrentResourceManager()->Modify(TRUE
);
58 bool wxResourcePropertyListView::OnClose(void)
61 GetManagedWindow()->GetSize(& w
, & h
);
62 GetManagedWindow()->GetPosition(& x
, & y
);
64 wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().width
= w
;
65 wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().height
= h
;
66 wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().x
= x
;
67 wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().y
= y
;
69 return wxPropertyListView::OnClose();
72 wxWindow
*wxPropertyInfo::sm_propertyWindow
;
75 * wxDialogEditorPropertyListDialog
79 wxDialogEditorPropertyListDialog::wxDialogEditorPropertyListDialog(wxPropertyListView *v, wxWindow *parent, const wxString& title,
80 const wxPoint& pos, const wxSize& size,
81 long style, const wxString& name):
82 wxPropertyListDialog(v, parent, title, pos, size, style, name)
88 wxDialogEditorPropertyListDialog::~wxDialogEditorPropertyListDialog()
92 wxPropertyInfo::sm_propertyWindow = NULL;
96 wxDialogEditorPropertyListFrame::wxDialogEditorPropertyListFrame(wxPropertyListView
*v
, wxFrame
*parent
, const wxString
& title
,
97 const wxPoint
& pos
, const wxSize
& size
,
98 long style
, const wxString
& name
):
99 wxPropertyListFrame(v
, parent
, title
, pos
, size
, style
, name
)
105 wxDialogEditorPropertyListFrame::~wxDialogEditorPropertyListFrame()
109 wxPropertyInfo::sm_propertyWindow
= NULL
;
116 // Edit the information represented by this object, whatever that
118 bool wxPropertyInfo::Edit(wxWindow
*WXUNUSED(parent
), const wxString
& title
)
120 if (sm_propertyWindow
)
122 sm_propertyWindow
->Raise();
126 int width
= wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().width
;
127 int height
= wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().height
;
128 int x
= wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().x
;
129 int y
= wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().y
;
131 wxPropertySheet
*propSheet
= new wxPropertySheet
;
133 wxStringList propNames
;
134 GetPropertyNames(propNames
);
136 wxNode
*node
= propNames
.First();
139 wxString
name((char *)node
->Data());
140 wxProperty
*prop
= GetProperty(name
);
143 propSheet
->AddProperty(prop
);
148 // Reset 'modified' flags for all property values
149 propSheet
->SetAllModified(FALSE
);
151 wxResourcePropertyListView
*view
= new wxResourcePropertyListView(this, NULL
,
152 wxPROP_BUTTON_OK
| wxPROP_BUTTON_CANCEL
|
153 wxPROP_BUTTON_CHECK_CROSS
|wxPROP_DYNAMIC_VALUE_FIELD
|wxPROP_PULLDOWN
|wxPROP_SHOWVALUES
);
155 wxDialogEditorPropertyListFrame
*propWin
= new wxDialogEditorPropertyListFrame(view
,
156 wxResourceManager::GetCurrentResourceManager()->GetEditorFrame(), title
, wxPoint(x
, y
),
157 wxSize(width
, height
), wxDEFAULT_FRAME_STYLE
);
158 sm_propertyWindow
= propWin
;
160 propWin
->m_registry
.RegisterValidator(wxString("real"), new wxRealListValidator
);
161 propWin
->m_registry
.RegisterValidator(wxString("string"), new wxStringListValidator
);
162 propWin
->m_registry
.RegisterValidator(wxString("integer"), new wxIntegerListValidator
);
163 propWin
->m_registry
.RegisterValidator(wxString("bool"), new wxBoolListValidator
);
164 propWin
->m_registry
.RegisterValidator(wxString("filename"), new wxFilenameListValidator
);
165 propWin
->m_registry
.RegisterValidator(wxString("stringlist"), new wxListOfStringsListValidator
);
166 propWin
->m_registry
.RegisterValidator(wxString("window_id"), new wxResourceSymbolValidator
);
168 propWin
->m_propInfo
= this;
169 propWin
->m_propSheet
= propSheet
;
171 // view->m_propertyWindow = propWin;
172 view
->AddRegistry(&(propWin
->m_registry
));
174 propWin
->Initialize();
175 view
->ShowView(propSheet
, propWin
->GetPropertyPanel());
182 * wxWindowPropertyInfo
185 wxWindowPropertyInfo::wxWindowPropertyInfo(wxWindow
*win
, wxItemResource
*res
)
187 m_propertyWindow
= win
;
188 m_propertyResource
= res
;
191 wxWindowPropertyInfo::~wxWindowPropertyInfo(void)
195 wxProperty
*wxWindowPropertyInfo::GetFontProperty(wxString
& name
, wxFont
*font
)
200 if (name
.Contains("Points"))
201 return new wxProperty(name
, (long)font
->GetPointSize(), "integer", new wxIntegerListValidator(1, 100));
202 else if (name
.Contains("Family"))
203 return new wxProperty(name
, font
->GetFamilyString(), "string",
204 new wxStringListValidator(new wxStringList("wxDECORATIVE", "wxROMAN", "wxSCRIPT", "wxSWISS", "wxMODERN",
206 else if (name
.Contains("Style"))
207 return new wxProperty(name
, font
->GetStyleString(), "string",
208 new wxStringListValidator(new wxStringList("wxNORMAL", "wxITALIC", "wxSLANT", NULL
)));
209 else if (name
.Contains("Weight"))
210 return new wxProperty(name
, font
->GetWeightString(), "string",
211 new wxStringListValidator(new wxStringList("wxNORMAL", "wxBOLD", "wxLIGHT", NULL
)));
212 else if (name
.Contains("Underlined"))
213 return new wxProperty(name
, (bool)font
->GetUnderlined(), "bool");
218 wxFont
*wxWindowPropertyInfo::SetFontProperty(wxString
& name
, wxProperty
*property
, wxFont
*font
)
221 int fontFamily
= wxMODERN
;
222 int fontStyle
= wxNORMAL
;
223 int fontWeight
= wxNORMAL
;
224 bool fontUnderlined
= FALSE
;
226 if (name
.Contains("Points"))
228 pointSize
= (int)property
->GetValue().IntegerValue();
229 if (font
&& (pointSize
== font
->GetPointSize()))
230 return NULL
; // No change
232 else if (font
) pointSize
= font
->GetPointSize();
234 if (name
.Contains("Family"))
236 wxString val
= property
->GetValue().StringValue();
237 fontFamily
= wxStringToFontFamily(val
);
239 if (font
&& (fontFamily
== font
->GetFamily()))
240 return NULL
; // No change
242 else if (font
) fontFamily
= font
->GetFamily();
244 if (name
.Contains("Style"))
246 wxString val
= property
->GetValue().StringValue();
247 fontStyle
= wxStringToFontStyle(val
);
249 if (font
&& (fontStyle
== font
->GetStyle()))
250 return NULL
; // No change
252 else if (font
) fontStyle
= font
->GetStyle();
253 if (name
.Contains("Weight"))
255 wxString val
= property
->GetValue().StringValue();
256 fontWeight
= wxStringToFontWeight(val
);
258 if (font
&& (fontWeight
== font
->GetWeight()))
259 return NULL
; // No change
261 else if (font
) fontWeight
= font
->GetWeight();
263 if (name
.Contains("Underlined"))
265 fontUnderlined
= property
->GetValue().BoolValue();
267 if (font
&& (fontUnderlined
== font
->GetUnderlined()))
268 return NULL
; // No change
270 else if (font
) fontUnderlined
= font
->GetUnderlined();
272 wxFont
*newFont
= wxTheFontList
->FindOrCreateFont(pointSize
, fontFamily
, fontStyle
, fontWeight
, fontUnderlined
);
281 wxProperty
*wxWindowPropertyInfo::GetProperty(wxString
& name
)
283 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
285 wxFont
*font
= m_propertyWindow
->GetFont();
286 if (name
== "fontPoints" || name
== "fontFamily" || name
== "fontStyle" || name
== "fontWeight" ||
287 name
== "fontUnderlined")
288 return GetFontProperty(name
, font
);
289 else if (name
== "name")
290 return new wxProperty("name", m_propertyWindow
->GetName(), "string");
291 else if (name
== "title")
292 return new wxProperty("title", m_propertyWindow
->GetTitle(), "string");
293 else if (name
== "x")
295 return new wxProperty("x", (long)resource
->GetX(), "integer");
297 else if (name
== "y")
299 return new wxProperty("y", (long)resource
->GetY(), "integer");
301 else if (name
== "width")
303 return new wxProperty("width", (long)resource
->GetWidth(), "integer");
305 else if (name
== "height")
307 return new wxProperty("width", (long)resource
->GetHeight(), "integer");
309 else if (name
== "id")
311 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
314 int id
= resource
->GetId();
316 idStr
.Printf("%d", id
);
317 wxString symbolName
= wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetSymbolForId(id
);
320 // symbolName is now e.g. "ID_PANEL21=105"
321 return new wxProperty("id", symbolName
, "window_id");
326 else if (name
== "border")
329 if (m_propertyWindow
->GetWindowStyleFlag() & wxSIMPLE_BORDER
)
330 border
= "wxSIMPLE_BORDER";
331 else if (m_propertyWindow
->GetWindowStyleFlag() & wxRAISED_BORDER
)
332 border
= "wxRAISED_BORDER";
333 else if (m_propertyWindow
->GetWindowStyleFlag() & wxSUNKEN_BORDER
)
334 border
= "wxSUNKEN_BORDER";
335 else if (m_propertyWindow
->GetWindowStyleFlag() & wxDOUBLE_BORDER
)
336 border
= "wxDOUBLE_BORDER";
337 else if (m_propertyWindow
->GetWindowStyleFlag() & wxSTATIC_BORDER
)
338 border
= "wxSTATIC_BORDER";
340 border
= "wxNO_BORDER";
342 return new wxProperty("border", border
, "string",
343 new wxStringListValidator(new wxStringList("wxSIMPLE_BORDER", "wxRAISED_BORDER",
344 "wxSUNKEN_BORDER", "wxDOUBLE_BORDER", "wxSTATIC_BORDER", "wxNO_BORDER", NULL
)));
350 bool wxWindowPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
352 wxFont
*font
= m_propertyWindow
->GetFont();
353 if (font
&& (name
== "fontPoints" || name
== "fontFamily" || name
== "fontStyle" || name
== "fontWeight" || name
== "fontUnderlined" ))
355 wxFont
*newFont
= SetFontProperty(name
, property
, font
);
357 m_propertyWindow
->SetFont(newFont
);
360 else if (name
== "name")
362 // Remove old name from resource table, if it's there.
363 wxItemResource
*oldResource
= (wxItemResource
*)wxResourceManager::GetCurrentResourceManager()->GetResourceTable().Delete(m_propertyWindow
->GetName());
366 // It's a top-level resource
367 m_propertyWindow
->SetName(property
->GetValue().StringValue());
368 oldResource
->SetName(property
->GetValue().StringValue());
369 wxResourceManager::GetCurrentResourceManager()->GetResourceTable().Put(m_propertyWindow
->GetName(), oldResource
);
373 // It's a child of something; just set the name of the resource and the window.
374 m_propertyWindow
->SetName(property
->GetValue().StringValue());
375 m_propertyResource
->SetName(property
->GetValue().StringValue());
377 // Refresh the resource manager list, because the name changed.
378 wxResourceManager::GetCurrentResourceManager()->UpdateResourceList();
381 else if (name
== "title")
383 m_propertyWindow
->SetTitle(property
->GetValue().StringValue());
386 else if (name
== "x")
389 m_propertyWindow
->GetPosition(&x
, &y
);
390 int newX
= (int)property
->GetValue().IntegerValue();
392 // We need to convert to pixels if this is not a dialog or panel, but
393 // the parent resource specifies dialog units.
394 if (m_propertyWindow
->GetParent() && m_propertyWindow
->IsKindOf(CLASSINFO(wxControl
)))
396 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
->GetParent());
397 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
399 wxPoint pt
= m_propertyWindow
->GetParent()->ConvertDialogToPixels(wxPoint(newX
, y
));
403 else if (m_propertyWindow
->IsKindOf(CLASSINFO(wxPanel
)))
405 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
406 if (resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
408 wxPoint pt
= m_propertyWindow
->ConvertDialogToPixels(wxPoint(newX
, y
));
414 m_propertyWindow
->Move(newX
, y
);
417 else if (name
== "y")
420 m_propertyWindow
->GetPosition(&x
, &y
);
421 int newY
= (int)property
->GetValue().IntegerValue();
423 // We need to convert to pixels if this is not a dialog or panel, but
424 // the parent resource specifies dialog units.
425 if (m_propertyWindow
->GetParent() && m_propertyWindow
->IsKindOf(CLASSINFO(wxControl
)))
427 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
->GetParent());
428 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
430 wxPoint pt
= m_propertyWindow
->GetParent()->ConvertDialogToPixels(wxPoint(x
, newY
));
434 else if (m_propertyWindow
->IsKindOf(CLASSINFO(wxPanel
)))
436 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
437 if (resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
439 wxPoint pt
= m_propertyWindow
->ConvertDialogToPixels(wxPoint(x
, newY
));
445 m_propertyWindow
->Move(x
, newY
);
448 else if (name
== "width")
451 m_propertyWindow
->GetSize(&width
, &height
);
452 int newWidth
= (int)property
->GetValue().IntegerValue();
454 // We need to convert to pixels if this is not a dialog or panel, but
455 // the parent resource specifies dialog units.
456 if (m_propertyWindow
->GetParent() && m_propertyWindow
->IsKindOf(CLASSINFO(wxControl
)))
458 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
->GetParent());
459 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
461 wxSize sz
= m_propertyWindow
->GetParent()->ConvertDialogToPixels(wxSize(newWidth
, height
));
465 else if (m_propertyWindow
->IsKindOf(CLASSINFO(wxPanel
)))
467 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
468 if (resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
470 wxSize sz
= m_propertyWindow
->ConvertDialogToPixels(wxSize(newWidth
, height
));
475 if (width
!= newWidth
)
477 m_propertyWindow
->SetSize(newWidth
, height
);
481 else if (name
== "height")
484 m_propertyWindow
->GetSize(&width
, &height
);
485 int newHeight
= (int)property
->GetValue().IntegerValue();
487 // We need to convert to pixels if this is not a dialog or panel, but
488 // the parent resource specifies dialog units.
489 if (m_propertyWindow
->GetParent() && m_propertyWindow
->IsKindOf(CLASSINFO(wxControl
)))
491 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
->GetParent());
492 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
494 wxSize sz
= m_propertyWindow
->GetParent()->ConvertDialogToPixels(wxSize(width
, newHeight
));
498 else if (m_propertyWindow
->IsKindOf(CLASSINFO(wxPanel
)))
500 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
501 if (resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
503 wxSize sz
= m_propertyWindow
->ConvertDialogToPixels(wxSize(width
, newHeight
));
508 if (height
!= newHeight
)
510 m_propertyWindow
->SetSize(width
, newHeight
);
514 else if (name
== "id")
516 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
519 wxString value
= property
->GetValue().StringValue();
521 wxString strName
= value
.Before('=');
522 wxString strId
= value
.After('=');
523 int id
= atoi(strId
);
525 wxString oldSymbolName
= wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetSymbolForId(resource
->GetId());
526 int oldSymbolId
= resource
->GetId();
530 // If we change the id for an existing symbol, we need to:
531 // 1) Check if there are any other resources currently using the original id.
532 // If so, will need to change their id to the new id.
533 // 2) Remove the old symbol, add the new symbol.
534 // In this check, we don't have to do this, but we need to do it in SetProperty.
536 if (strName
== oldSymbolName
&& id
!= oldSymbolId
)
538 wxASSERT( (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(oldSymbolName
)) );
540 // It's OK to change just the id. But we'll need to change all matching ids in all resources,
541 // because ids are unique and changing one resource's id must change all identical ones.
542 wxResourceManager::GetCurrentResourceManager()->ChangeIds(oldSymbolId
, id
);
544 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().RemoveSymbol(oldSymbolName
);
545 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().AddSymbol(strName
, id
);
548 // If we change the name but not the id, we'll just need to remove and
549 // re-add the symbol/id pair.
550 if (strName
!= oldSymbolName
&& id
== oldSymbolId
)
552 wxASSERT( (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(oldSymbolName
)) );
554 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().RemoveSymbol(oldSymbolName
);
556 if (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().SymbolExists(strName
))
558 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().AddSymbol(strName
, id
);
562 // What if we're changing both the name and the id?
563 // - if there's no symbol of that name, just remove the old, add the new (in SetProperty)
564 // - if there is a symbol of that name, if id matches, do nothing. If not, veto.
566 if (strName
!= oldSymbolName
&& id
!= oldSymbolId
)
568 // Remove old symbol if it's not being used
569 if (!wxResourceManager::GetCurrentResourceManager()->IsSymbolUsed(resource
, oldSymbolId
) &&
570 !wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(oldSymbolName
))
572 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().RemoveSymbol(oldSymbolName
);
575 if (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().SymbolExists(strName
))
577 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().AddSymbol(strName
, id
);
588 else if (name
== "border")
590 long borderStyle
= wxNO_BORDER
;
591 wxString val
= property
->GetValue().StringValue();
593 if (val
== "wxSIMPLE_BORDER")
594 borderStyle
= wxSIMPLE_BORDER
;
595 else if (val
== "wxRAISED_BORDER")
596 borderStyle
= wxRAISED_BORDER
;
597 else if (val
== "wxSUNKEN_BORDER")
598 borderStyle
= wxSUNKEN_BORDER
;
599 else if (val
== "wxDOUBLE_BORDER")
600 borderStyle
= wxDOUBLE_BORDER
;
601 else if (val
== "wxSTATIC_BORDER")
602 borderStyle
= wxSTATIC_BORDER
;
604 borderStyle
= wxNO_BORDER
;
606 SetWindowStyle(m_propertyWindow
, wxSIMPLE_BORDER
, FALSE
);
607 SetWindowStyle(m_propertyWindow
, wxRAISED_BORDER
, FALSE
);
608 SetWindowStyle(m_propertyWindow
, wxSUNKEN_BORDER
, FALSE
);
609 SetWindowStyle(m_propertyWindow
, wxDOUBLE_BORDER
, FALSE
);
610 SetWindowStyle(m_propertyWindow
, wxSTATIC_BORDER
, FALSE
);
611 SetWindowStyle(m_propertyWindow
, wxNO_BORDER
, FALSE
);
613 SetWindowStyle(m_propertyWindow
, borderStyle
, TRUE
);
615 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
616 resource
->SetStyle(m_propertyWindow
->GetWindowStyleFlag());
623 void wxWindowPropertyInfo::GetPropertyNames(wxStringList
& names
)
632 if (!m_propertyWindow
->IsKindOf(CLASSINFO(wxControl
)))
634 names
.Add("fontPoints");
635 names
.Add("fontFamily");
636 names
.Add("fontStyle");
637 names
.Add("fontWeight");
638 names
.Add("fontUnderlined");
642 // Fill in the wxItemResource members to mirror the current window settings
643 bool wxWindowPropertyInfo::InstantiateResource(wxItemResource
*resource
)
645 // resource->SetType(m_propertyWindow->GetClassInfo()->GetClassName());
647 // resource->SetStyle(m_propertyWindow->GetWindowStyleFlag());
648 wxString
str(m_propertyWindow
->GetName());
649 resource
->SetName(str
);
654 if (m_propertyWindow
->IsKindOf(CLASSINFO(wxPanel
)))
655 m_propertyWindow
->GetClientSize(&w
, &h
);
657 m_propertyWindow
->GetSize(&w
, &h
);
659 m_propertyWindow
->GetPosition(&x
, &y
);
661 // We need to convert to dialog units if this is not a dialog or panel, but
662 // the parent resource specifies dialog units.
663 if (m_propertyWindow
->GetParent() && m_propertyWindow
->IsKindOf(CLASSINFO(wxControl
)))
665 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
->GetParent());
666 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
668 wxPoint pt
= m_propertyWindow
->GetParent()->ConvertPixelsToDialog(wxPoint(x
, y
));
670 wxSize sz
= m_propertyWindow
->GetParent()->ConvertPixelsToDialog(wxSize(w
, h
));
674 else if (m_propertyWindow
->IsKindOf(CLASSINFO(wxPanel
)))
676 if (resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
678 wxPoint pt
= m_propertyWindow
->ConvertPixelsToDialog(wxPoint(x
, y
));
680 wxSize sz
= m_propertyWindow
->ConvertPixelsToDialog(wxSize(w
, h
));
685 resource
->SetSize(x
, y
, w
, h
);
691 // Set the window style
692 void wxWindowPropertyInfo::SetWindowStyle(wxWindow
* win
, long style
, bool set
)
697 if ((win
->GetWindowStyleFlag() & style
) == style
)
701 win
->SetWindowStyleFlag(win
->GetWindowStyleFlag() - style
);
708 win
->SetWindowStyleFlag(win
->GetWindowStyleFlag() | style
);
717 wxProperty
*wxItemPropertyInfo::GetProperty(wxString
& name
)
719 wxControl
*itemWindow
= (wxControl
*)m_propertyWindow
;
720 wxFont
*font
= itemWindow
->GetFont();
722 if (name
== "fontPoints" || name
== "fontFamily" || name
== "fontStyle" || name
== "fontWeight" ||
723 name
== "fontUnderlined")
724 return GetFontProperty(name
, font
);
725 else if (name
== "label" && itemWindow
->GetLabel())
726 return new wxProperty("label", m_propertyWindow
->GetLabel(), "string");
728 return wxWindowPropertyInfo::GetProperty(name
);
731 bool wxItemPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
733 wxControl
*itemWindow
= (wxControl
*)m_propertyWindow
;
734 wxFont
*font
= itemWindow
->GetFont();
736 if (font
&& (name
== "fontPoints" || name
== "fontFamily" || name
== "fontStyle" || name
== "fontWeight" || name
== "fontUnderlined" ))
738 wxFont
*newFont
= SetFontProperty(name
, property
, font
);
740 itemWindow
->SetLabelFont(newFont
);
743 else if (name
== "label")
745 itemWindow
->SetLabel(property
->GetValue().StringValue());
749 return wxWindowPropertyInfo::SetProperty(name
, property
);
752 void wxItemPropertyInfo::GetPropertyNames(wxStringList
& names
)
754 wxWindowPropertyInfo::GetPropertyNames(names
);
756 names
.Add("fontPoints");
757 names
.Add("fontFamily");
758 names
.Add("fontStyle");
759 names
.Add("fontWeight");
760 names
.Add("fontUnderlined");
763 bool wxItemPropertyInfo::InstantiateResource(wxItemResource
*resource
)
765 wxWindowPropertyInfo::InstantiateResource(resource
);
767 wxControl
*item
= (wxControl
*)m_propertyWindow
;
768 wxString
str(item
->GetLabel());
769 resource
->SetTitle(str
);
770 if (item
->GetFont() && item
->GetFont()->Ok())
771 resource
->SetFont(wxTheFontList
->FindOrCreateFont(item
->GetFont()->GetPointSize(),
772 item
->GetFont()->GetFamily(), item
->GetFont()->GetStyle(), item
->GetFont()->GetWeight(),
773 item
->GetFont()->GetUnderlined(), item
->GetFont()->GetFaceName()));
781 wxProperty
*wxButtonPropertyInfo::GetProperty(wxString
& name
)
783 return wxItemPropertyInfo::GetProperty(name
);
786 bool wxButtonPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
788 return wxItemPropertyInfo::SetProperty(name
, property
);
791 void wxButtonPropertyInfo::GetPropertyNames(wxStringList
& names
)
793 wxItemPropertyInfo::GetPropertyNames(names
);
797 bool wxButtonPropertyInfo::InstantiateResource(wxItemResource
*resource
)
799 return wxItemPropertyInfo::InstantiateResource(resource
);
806 wxProperty
*wxBitmapButtonPropertyInfo::GetProperty(wxString
& name
)
808 wxBitmapButton
*button
= (wxBitmapButton
*)m_propertyWindow
;
811 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(button
);
812 wxString
str("none.bmp");
816 str
= wxResourceManager::GetCurrentResourceManager()->FindBitmapFilenameForResource(resource
);
818 return new wxProperty("label", str
.GetData(), "string", new wxFilenameListValidator("Select a bitmap file", "*.bmp"));
821 return wxButtonPropertyInfo::GetProperty(name
);
824 bool wxBitmapButtonPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
826 wxBitmapButton
*button
= (wxBitmapButton
*)m_propertyWindow
;
829 char *s
= property
->GetValue().StringValue();
830 if (s
&& wxFileExists(s
))
833 wxBitmap
*bitmap
= new wxBitmap(s
, wxBITMAP_TYPE_BMP
);
842 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(button
);
845 wxString
oldResource(resource
->GetValue4());
846 wxString resName
= wxResourceManager::GetCurrentResourceManager()->AddBitmapResource(s
);
847 resource
->SetValue4(resName
);
849 if (!oldResource
.IsNull())
850 wxResourceManager::GetCurrentResourceManager()->PossiblyDeleteBitmapResource(oldResource
);
853 button
->SetLabel(bitmap
);
861 return wxButtonPropertyInfo::SetProperty(name
, property
);
864 void wxBitmapButtonPropertyInfo::GetPropertyNames(wxStringList
& names
)
866 // names.Add("label");
867 wxButtonPropertyInfo::GetPropertyNames(names
);
870 bool wxBitmapButtonPropertyInfo::InstantiateResource(wxItemResource
*resource
)
872 return wxItemPropertyInfo::InstantiateResource(resource
);
879 wxProperty
*wxStaticTextPropertyInfo::GetProperty(wxString
& name
)
881 return wxItemPropertyInfo::GetProperty(name
);
884 bool wxStaticTextPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
886 return wxItemPropertyInfo::SetProperty(name
, property
);
889 void wxStaticTextPropertyInfo::GetPropertyNames(wxStringList
& names
)
891 wxItemPropertyInfo::GetPropertyNames(names
);
895 bool wxStaticTextPropertyInfo::InstantiateResource(wxItemResource
*resource
)
897 return wxItemPropertyInfo::InstantiateResource(resource
);
904 wxProperty
*wxStaticBitmapPropertyInfo::GetProperty(wxString
& name
)
906 wxStaticBitmap
*message
= (wxStaticBitmap
*)m_propertyWindow
;
909 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(message
);
910 wxString
str("none.bmp");
914 str
= wxResourceManager::GetCurrentResourceManager()->FindBitmapFilenameForResource(resource
);
916 return new wxProperty("label", str
.GetData(), "string", new wxFilenameListValidator("Select a bitmap file", "*.bmp"));
919 return wxItemPropertyInfo::GetProperty(name
);
922 bool wxStaticBitmapPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
924 wxStaticBitmap
*message
= (wxStaticBitmap
*)m_propertyWindow
;
927 char *s
= property
->GetValue().StringValue();
928 if (s
&& wxFileExists(s
))
932 wxBitmap
*bitmap
= new wxBitmap(s
, wxBITMAP_TYPE_BMP
);
941 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(message
);
944 wxString
oldResource(resource
->GetValue4());
945 wxString resName
= wxResourceManager::GetCurrentResourceManager()->AddBitmapResource(s
);
946 resource
->SetValue4(resName
);
948 if (!oldResource
.IsNull())
949 wxResourceManager::GetCurrentResourceManager()->PossiblyDeleteBitmapResource(oldResource
);
952 message
->SetBitmap(bitmap
);
960 return wxItemPropertyInfo::SetProperty(name
, property
);
963 void wxStaticBitmapPropertyInfo::GetPropertyNames(wxStringList
& names
)
965 wxItemPropertyInfo::GetPropertyNames(names
);
969 bool wxStaticBitmapPropertyInfo::InstantiateResource(wxItemResource
*resource
)
971 return wxItemPropertyInfo::InstantiateResource(resource
);
978 wxProperty
*wxTextPropertyInfo::GetProperty(wxString
& name
)
980 wxTextCtrl
*text
= (wxTextCtrl
*)m_propertyWindow
;
982 return new wxProperty("value", text
->GetValue(), "string");
983 else if (name
== "password")
985 bool isPassword
= ((text
->GetWindowStyleFlag() & wxTE_PASSWORD
) == wxTE_PASSWORD
);
986 return new wxProperty("password", isPassword
, "bool");
988 else if (name
== "readonly")
990 bool isReadOnly
= ((text
->GetWindowStyleFlag() & wxTE_READONLY
) == wxTE_READONLY
);
991 return new wxProperty("readonly", isReadOnly
, "bool");
994 return wxItemPropertyInfo::GetProperty(name
);
997 bool wxTextPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
999 wxTextCtrl
*text
= (wxTextCtrl
*)m_propertyWindow
;
1000 if (name
== "value")
1002 text
->SetValue(property
->GetValue().StringValue());
1005 else if (name
== "password")
1007 long flag
= text
->GetWindowStyleFlag();
1008 if (property
->GetValue().BoolValue())
1010 if ((flag
& wxTE_PASSWORD
) != wxTE_PASSWORD
)
1011 flag
|= wxTE_PASSWORD
;
1015 if ((flag
& wxTE_PASSWORD
) == wxTE_PASSWORD
)
1016 flag
-= wxTE_PASSWORD
;
1018 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(text
);
1019 resource
->SetStyle(flag
);
1021 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(text
, this);
1024 else if (name
== "readonly")
1026 long flag
= text
->GetWindowStyleFlag();
1027 if (property
->GetValue().BoolValue())
1029 if ((flag
& wxTE_READONLY
) != wxTE_READONLY
)
1030 flag
|= wxTE_READONLY
;
1034 if ((flag
& wxTE_READONLY
) == wxTE_READONLY
)
1035 flag
-= wxTE_READONLY
;
1037 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(text
);
1038 resource
->SetStyle(flag
);
1040 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(text
, this);
1044 return wxItemPropertyInfo::SetProperty(name
, property
);
1047 void wxTextPropertyInfo::GetPropertyNames(wxStringList
& names
)
1049 wxItemPropertyInfo::GetPropertyNames(names
);
1051 names
.Add("readonly");
1052 names
.Add("password");
1055 bool wxTextPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1057 wxTextCtrl
*text
= (wxTextCtrl
*)m_propertyWindow
;
1058 wxString
str(text
->GetValue());
1059 resource
->SetValue4(str
);
1061 return wxItemPropertyInfo::InstantiateResource(resource
);
1068 wxProperty
*wxListBoxPropertyInfo::GetProperty(wxString
& name
)
1070 wxListBox
*listBox
= (wxListBox
*)m_propertyWindow
;
1071 if (name
== "values")
1073 wxStringList
*stringList
= new wxStringList
;
1075 for (i
= 0; i
< listBox
->Number(); i
++)
1076 stringList
->Add(listBox
->GetString(i
));
1078 return new wxProperty(name
, stringList
, "stringlist");
1080 else if (name
== "multiple")
1082 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(listBox
);
1086 char *mult
= "wxSINGLE";
1088 switch (resource
->GetValue1())
1091 mult
= "wxLB_MULTIPLE";
1094 mult
= "wxLB_EXTENDED";
1098 mult
= "wxLB_SINGLE";
1101 return new wxProperty("multiple", mult
, "string",
1102 new wxStringListValidator(new wxStringList("wxLB_SINGLE", "wxLB_MULTIPLE", "wxLB_EXTENDED",
1106 return wxItemPropertyInfo::GetProperty(name
);
1109 bool wxListBoxPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1111 wxListBox
*listBox
= (wxListBox
*)m_propertyWindow
;
1112 if (name
== "values")
1115 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
1118 char *s
= expr
->StringValue();
1121 expr
= expr
->GetNext();
1125 else if (name
== "multiple")
1127 int mult
= wxLB_SINGLE
;
1128 wxString
str(property
->GetValue().StringValue());
1129 if (str
== "wxLB_MULTIPLE")
1130 mult
= wxLB_MULTIPLE
;
1131 else if (str
== "wxLB_EXTENDED")
1132 mult
= wxLB_EXTENDED
;
1135 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(listBox
);
1137 resource
->SetValue1(mult
);
1138 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(listBox
, this);
1142 return wxItemPropertyInfo::SetProperty(name
, property
);
1145 void wxListBoxPropertyInfo::GetPropertyNames(wxStringList
& names
)
1147 wxItemPropertyInfo::GetPropertyNames(names
);
1148 names
.Add("values");
1149 names
.Add("multiple");
1152 bool wxListBoxPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1154 wxListBox
*lbox
= (wxListBox
*)m_propertyWindow
;
1155 // This will be set for the wxItemResource on reading or in SetProperty
1156 // resource->SetValue1(lbox->GetSelectionMode());
1158 if (lbox
->Number() == 0)
1159 resource
->SetStringValues(NULL
);
1164 for (i
= 0; i
< lbox
->Number(); i
++)
1165 slist
.Add(lbox
->GetString(i
));
1167 resource
->SetStringValues(slist
);
1169 return wxItemPropertyInfo::InstantiateResource(resource
);
1176 wxProperty
*wxChoicePropertyInfo::GetProperty(wxString
& name
)
1178 wxChoice
*choice
= (wxChoice
*)m_propertyWindow
;
1179 if (name
== "values")
1181 wxStringList
* stringList
= new wxStringList
;
1183 for (i
= 0; i
< choice
->Number(); i
++)
1184 stringList
->Add(choice
->GetString(i
));
1186 return new wxProperty(name
, stringList
, "stringlist");
1189 return wxItemPropertyInfo::GetProperty(name
);
1192 bool wxChoicePropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1194 wxChoice
*choice
= (wxChoice
*)m_propertyWindow
;
1195 if (name
== "values")
1198 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
1201 char *s
= expr
->StringValue();
1204 expr
= expr
->GetNext();
1206 if (choice
->Number() > 0)
1207 choice
->SetSelection(0);
1211 return wxItemPropertyInfo::SetProperty(name
, property
);
1214 void wxChoicePropertyInfo::GetPropertyNames(wxStringList
& names
)
1216 wxItemPropertyInfo::GetPropertyNames(names
);
1217 names
.Add("values");
1220 bool wxChoicePropertyInfo::InstantiateResource(wxItemResource
*resource
)
1222 wxChoice
*choice
= (wxChoice
*)m_propertyWindow
;
1224 if (choice
->Number() == 0)
1225 resource
->SetStringValues(NULL
);
1230 for (i
= 0; i
< choice
->Number(); i
++)
1231 slist
.Add(choice
->GetString(i
));
1233 resource
->SetStringValues(slist
);
1235 return wxItemPropertyInfo::InstantiateResource(resource
);
1242 wxProperty
*wxComboBoxPropertyInfo::GetProperty(wxString
& name
)
1244 wxComboBox
*choice
= (wxComboBox
*)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");
1254 else if (name
== "sort")
1256 bool sort
= ((m_propertyWindow
->GetWindowStyleFlag() & wxCB_SORT
) == wxCB_SORT
);
1257 return new wxProperty(name
, sort
, "bool");
1259 else if (name
== "style")
1261 wxString
styleStr("dropdown");
1262 if (m_propertyWindow
->GetWindowStyleFlag() & wxCB_SIMPLE
)
1263 styleStr
= "simple";
1264 else if (m_propertyWindow
->GetWindowStyleFlag() & wxCB_READONLY
)
1265 styleStr
= "readonly";
1267 styleStr
= "dropdown";
1269 return new wxProperty(name
, styleStr
, "string",
1270 new wxStringListValidator(new wxStringList("simple", "dropdown", "readonly",
1274 return wxItemPropertyInfo::GetProperty(name
);
1277 bool wxComboBoxPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1279 wxComboBox
*choice
= (wxComboBox
*)m_propertyWindow
;
1280 if (name
== "values")
1283 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
1286 char *s
= expr
->StringValue();
1289 expr
= expr
->GetNext();
1291 if (choice
->Number() > 0)
1292 choice
->SetSelection(0);
1295 else if (name
== "sort")
1297 SetWindowStyle(m_propertyWindow
, wxCB_SORT
, property
->GetValue().BoolValue());
1299 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
1300 resource
->SetStyle(m_propertyWindow
->GetWindowStyleFlag());
1302 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(m_propertyWindow
, this);
1305 else if (name
== "style")
1307 SetWindowStyle(m_propertyWindow
, wxCB_SIMPLE
, FALSE
);
1308 SetWindowStyle(m_propertyWindow
, wxCB_DROPDOWN
, FALSE
);
1309 SetWindowStyle(m_propertyWindow
, wxCB_READONLY
, FALSE
);
1311 wxString
styleStr(property
->GetValue().StringValue());
1312 if (styleStr
== "simple")
1313 SetWindowStyle(m_propertyWindow
, wxCB_SIMPLE
, TRUE
);
1314 else if (styleStr
== "dropdown")
1315 SetWindowStyle(m_propertyWindow
, wxCB_DROPDOWN
, TRUE
);
1316 else if (styleStr
== "readonly")
1317 SetWindowStyle(m_propertyWindow
, wxCB_READONLY
, TRUE
);
1320 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
1321 resource
->SetStyle(m_propertyWindow
->GetWindowStyleFlag());
1323 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(m_propertyWindow
, this);
1328 return wxItemPropertyInfo::SetProperty(name
, property
);
1331 void wxComboBoxPropertyInfo::GetPropertyNames(wxStringList
& names
)
1333 wxItemPropertyInfo::GetPropertyNames(names
);
1334 names
.Add("values");
1339 bool wxComboBoxPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1341 wxComboBox
*choice
= (wxComboBox
*)m_propertyWindow
;
1343 if (choice
->Number() == 0)
1344 resource
->SetStringValues(NULL
);
1349 for (i
= 0; i
< choice
->Number(); i
++)
1350 slist
.Add(choice
->GetString(i
));
1352 resource
->SetStringValues(slist
);
1354 return wxItemPropertyInfo::InstantiateResource(resource
);
1361 wxProperty
*wxRadioBoxPropertyInfo::GetProperty(wxString
& name
)
1363 wxRadioBox
*radioBox
= (wxRadioBox
*)m_propertyWindow
;
1364 if (name
== "numberRowsOrCols")
1366 return new wxProperty("numberRowsOrCols", (long)radioBox
->GetNumberOfRowsOrCols(), "integer");
1368 if (name
== "orientation")
1371 if (m_propertyWindow
->GetWindowStyleFlag() & wxRA_HORIZONTAL
)
1372 orient
= "wxRA_HORIZONTAL";
1374 orient
= "wxRA_VERTICAL";
1376 return new wxProperty("orientation", orient
, "string",
1377 new wxStringListValidator(new wxStringList("wxRA_HORIZONTAL", "wxRA_VERTICAL",
1380 else if (name
== "values")
1382 wxStringList
*stringList
= new wxStringList
;
1384 for (i
= 0; i
< radioBox
->Number(); i
++)
1385 stringList
->Add(radioBox
->GetString(i
));
1387 return new wxProperty(name
, stringList
, "stringlist");
1389 return wxItemPropertyInfo::GetProperty(name
);
1392 bool wxRadioBoxPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1394 wxRadioBox
*radioBox
= (wxRadioBox
*)m_propertyWindow
;
1395 if (name
== "numberRowsOrCols")
1397 radioBox
->SetNumberOfRowsOrCols((int)property
->GetValue().IntegerValue());
1398 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox
, this);
1401 else if (name
== "orientation")
1403 long windowStyle
= radioBox
->GetWindowStyleFlag();
1404 wxString
val(property
->GetValue().StringValue());
1405 if (val
== "wxRA_HORIZONTAL")
1407 if (windowStyle
& wxRA_VERTICAL
)
1408 windowStyle
-= wxRA_VERTICAL
;
1409 windowStyle
|= wxRA_HORIZONTAL
;
1413 if (windowStyle
& wxRA_HORIZONTAL
)
1414 windowStyle
-= wxRA_HORIZONTAL
;
1415 windowStyle
|= wxRA_VERTICAL
;
1417 radioBox
->SetWindowStyleFlag(windowStyle
);
1418 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(radioBox
);
1419 resource
->SetStyle(windowStyle
);
1421 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox
, this);
1424 else if (name
== "values")
1426 // Set property into *resource*, not wxRadioBox, and then recreate
1427 // the wxRadioBox. This is because we can't dynamically set the strings
1429 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
1433 wxStringList stringList
;
1434 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
1437 char *s
= expr
->StringValue();
1440 expr
= expr
->GetNext();
1442 resource
->SetStringValues(stringList
);
1443 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox
, this);
1446 return wxItemPropertyInfo::SetProperty(name
, property
);
1449 void wxRadioBoxPropertyInfo::GetPropertyNames(wxStringList
& names
)
1451 wxItemPropertyInfo::GetPropertyNames(names
);
1453 names
.Add("values");
1454 names
.Add("orientation");
1455 names
.Add("numberRowsOrCols");
1458 bool wxRadioBoxPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1460 wxRadioBox
*rbox
= (wxRadioBox
*)m_propertyWindow
;
1461 // Take strings from resource instead
1464 if (rbox->Number() == 0)
1465 resource->SetStringValues(NULL);
1468 wxStringList *slist = new wxStringList;
1470 for (i = 0; i < rbox->Number(); i++)
1471 slist->Add(rbox->GetString(i));
1473 resource->SetStringValues(slist);
1476 resource
->SetValue1(rbox
->GetNumberOfRowsOrCols());
1477 return wxItemPropertyInfo::InstantiateResource(resource
);
1484 wxProperty
*wxGroupBoxPropertyInfo::GetProperty(wxString
& name
)
1486 return wxItemPropertyInfo::GetProperty(name
);
1489 bool wxGroupBoxPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1491 return wxItemPropertyInfo::SetProperty(name
, property
);
1494 void wxGroupBoxPropertyInfo::GetPropertyNames(wxStringList
& names
)
1496 wxItemPropertyInfo::GetPropertyNames(names
);
1500 bool wxGroupBoxPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1502 return wxItemPropertyInfo::InstantiateResource(resource
);
1509 wxProperty
*wxCheckBoxPropertyInfo::GetProperty(wxString
& name
)
1511 wxCheckBox
*checkBox
= (wxCheckBox
*)m_propertyWindow
;
1512 if (name
== "value")
1513 return new wxProperty("value", checkBox
->GetValue(), "bool");
1515 return wxItemPropertyInfo::GetProperty(name
);
1518 bool wxCheckBoxPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1520 wxCheckBox
*checkBox
= (wxCheckBox
*)m_propertyWindow
;
1521 if (name
== "value")
1523 checkBox
->SetValue((bool)property
->GetValue().BoolValue());
1527 return wxItemPropertyInfo::SetProperty(name
, property
);
1530 void wxCheckBoxPropertyInfo::GetPropertyNames(wxStringList
& names
)
1532 wxItemPropertyInfo::GetPropertyNames(names
);
1537 bool wxCheckBoxPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1539 wxCheckBox
*cbox
= (wxCheckBox
*)m_propertyWindow
;
1540 resource
->SetValue1(cbox
->GetValue());
1541 return wxItemPropertyInfo::InstantiateResource(resource
);
1548 wxProperty
*wxRadioButtonPropertyInfo::GetProperty(wxString
& name
)
1550 wxRadioButton
*checkBox
= (wxRadioButton
*)m_propertyWindow
;
1551 if (name
== "value")
1552 return new wxProperty("value", checkBox
->GetValue(), "bool");
1554 return wxItemPropertyInfo::GetProperty(name
);
1557 bool wxRadioButtonPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1559 wxRadioButton
*checkBox
= (wxRadioButton
*)m_propertyWindow
;
1560 if (name
== "value")
1562 checkBox
->SetValue((bool)property
->GetValue().BoolValue());
1566 return wxItemPropertyInfo::SetProperty(name
, property
);
1569 void wxRadioButtonPropertyInfo::GetPropertyNames(wxStringList
& names
)
1571 wxItemPropertyInfo::GetPropertyNames(names
);
1576 bool wxRadioButtonPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1578 wxRadioButton
*cbox
= (wxRadioButton
*)m_propertyWindow
;
1579 resource
->SetValue1(cbox
->GetValue());
1580 return wxItemPropertyInfo::InstantiateResource(resource
);
1587 wxProperty
*wxSliderPropertyInfo::GetProperty(wxString
& name
)
1589 wxSlider
*slider
= (wxSlider
*)m_propertyWindow
;
1590 if (name
== "value")
1591 return new wxProperty("value", (long)slider
->GetValue(), "integer");
1592 else if (name
== "orientation")
1595 if (m_propertyWindow
->GetWindowStyleFlag() & wxHORIZONTAL
)
1596 pos
= "wxHORIZONTAL";
1600 return new wxProperty("orientation", pos
, "string",
1601 new wxStringListValidator(new wxStringList("wxHORIZONTAL", "wxVERTICAL",
1604 else if (name
== "minValue")
1605 return new wxProperty("minValue", (long)slider
->GetMin(), "integer");
1606 else if (name
== "maxValue")
1607 return new wxProperty("maxValue", (long)slider
->GetMax(), "integer");
1609 return wxItemPropertyInfo::GetProperty(name
);
1612 bool wxSliderPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1614 wxSlider
*slider
= (wxSlider
*)m_propertyWindow
;
1615 if (name
== "value")
1617 slider
->SetValue((int)property
->GetValue().IntegerValue());
1620 else if (name
== "orientation")
1622 long windowStyle
= slider
->GetWindowStyleFlag();
1623 long oldWindowStyle
= windowStyle
;
1624 wxString
val(property
->GetValue().StringValue());
1625 if (val
== "wxHORIZONTAL")
1627 if (windowStyle
& wxVERTICAL
)
1628 windowStyle
-= wxVERTICAL
;
1629 windowStyle
|= wxHORIZONTAL
;
1633 if (windowStyle
& wxHORIZONTAL
)
1634 windowStyle
-= wxHORIZONTAL
;
1635 windowStyle
|= wxVERTICAL
;
1638 if (oldWindowStyle
== windowStyle
)
1641 slider
->SetWindowStyleFlag(windowStyle
);
1643 // If the window style has changed, we swap the width and height parameters.
1645 slider
->GetSize(&w
, &h
);
1647 slider
= (wxSlider
*)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(slider
, this);
1648 slider
->SetSize(-1, -1, h
, w
);
1652 else if (name
== "minValue")
1654 slider
->SetRange((int)property
->GetValue().IntegerValue(), slider
->GetMax());
1657 else if (name
== "maxValue")
1659 slider
->SetRange(slider
->GetMin(), (int)property
->GetValue().IntegerValue());
1663 return wxItemPropertyInfo::SetProperty(name
, property
);
1666 void wxSliderPropertyInfo::GetPropertyNames(wxStringList
& names
)
1668 wxItemPropertyInfo::GetPropertyNames(names
);
1670 names
.Add("orientation");
1671 names
.Add("minValue");
1672 names
.Add("maxValue");
1675 bool wxSliderPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1677 wxSlider
*slider
= (wxSlider
*)m_propertyWindow
;
1678 resource
->SetValue1(slider
->GetValue());
1679 resource
->SetValue2(slider
->GetMin());
1680 resource
->SetValue3(slider
->GetMax());
1681 return wxItemPropertyInfo::InstantiateResource(resource
);
1688 wxProperty
*wxGaugePropertyInfo::GetProperty(wxString
& name
)
1690 wxGauge
*gauge
= (wxGauge
*)m_propertyWindow
;
1691 if (name
== "value")
1692 return new wxProperty("value", (long)gauge
->GetValue(), "integer");
1693 else if (name
== "maxValue")
1694 return new wxProperty("maxValue", (long)gauge
->GetRange(), "integer");
1696 return wxItemPropertyInfo::GetProperty(name
);
1699 bool wxGaugePropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1701 wxGauge
*gauge
= (wxGauge
*)m_propertyWindow
;
1702 if (name
== "value")
1704 gauge
->SetValue((int)property
->GetValue().IntegerValue());
1707 else if (name
== "maxValue")
1709 gauge
->SetRange((int)property
->GetValue().IntegerValue());
1713 return wxItemPropertyInfo::SetProperty(name
, property
);
1716 void wxGaugePropertyInfo::GetPropertyNames(wxStringList
& names
)
1718 wxItemPropertyInfo::GetPropertyNames(names
);
1720 names
.Add("maxValue");
1723 bool wxGaugePropertyInfo::InstantiateResource(wxItemResource
*resource
)
1725 wxGauge
*gauge
= (wxGauge
*)m_propertyWindow
;
1726 resource
->SetValue1(gauge
->GetValue());
1727 resource
->SetValue2(gauge
->GetRange());
1728 return wxItemPropertyInfo::InstantiateResource(resource
);
1735 wxProperty
*wxScrollBarPropertyInfo::GetProperty(wxString
& name
)
1737 wxScrollBar
*scrollBar
= (wxScrollBar
*)m_propertyWindow
;
1738 if (name
== "value")
1739 return new wxProperty("value", (long)scrollBar
->GetValue(), "integer");
1740 else if (name
== "orientation")
1743 if (m_propertyWindow
->GetWindowStyleFlag() & wxHORIZONTAL
)
1744 pos
= "wxHORIZONTAL";
1748 return new wxProperty("orientation", pos
, "string",
1749 new wxStringListValidator(new wxStringList("wxHORIZONTAL", "wxVERTICAL",
1752 else if (name
== "pageSize")
1754 int viewStart
, pageLength
, objectLength
, viewLength
;
1755 scrollBar
->GetValues(&viewStart
, &viewLength
, &objectLength
, &pageLength
);
1757 return new wxProperty("pageSize", (long)pageLength
, "integer");
1759 else if (name
== "viewLength")
1761 int viewStart
, pageLength
, objectLength
, viewLength
;
1762 scrollBar
->GetValues(&viewStart
, &viewLength
, &objectLength
, &pageLength
);
1764 return new wxProperty("viewLength", (long)viewLength
, "integer");
1766 else if (name
== "objectLength")
1768 int viewStart
, pageLength
, objectLength
, viewLength
;
1769 scrollBar
->GetValues(&viewStart
, &viewLength
, &objectLength
, &pageLength
);
1771 return new wxProperty("objectLength", (long)objectLength
, "integer");
1774 return wxItemPropertyInfo::GetProperty(name
);
1777 bool wxScrollBarPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1779 wxScrollBar
*scrollBar
= (wxScrollBar
*)m_propertyWindow
;
1780 if (name
== "value")
1782 scrollBar
->SetValue((int)property
->GetValue().IntegerValue());
1785 else if (name
== "orientation")
1787 long windowStyle
= scrollBar
->GetWindowStyleFlag();
1788 long oldWindowStyle
= windowStyle
;
1789 wxString
val(property
->GetValue().StringValue());
1790 if (val
== "wxHORIZONTAL")
1792 if (windowStyle
& wxVERTICAL
)
1793 windowStyle
-= wxVERTICAL
;
1794 windowStyle
|= wxHORIZONTAL
;
1798 if (windowStyle
& wxHORIZONTAL
)
1799 windowStyle
-= wxHORIZONTAL
;
1800 windowStyle
|= wxVERTICAL
;
1803 if (oldWindowStyle
== windowStyle
)
1806 scrollBar
->SetWindowStyleFlag(windowStyle
);
1808 // If the window style has changed, we swap the width and height parameters.
1810 scrollBar
->GetSize(&w
, &h
);
1812 scrollBar
= (wxScrollBar
*)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(scrollBar
, this);
1813 scrollBar
->SetSize(-1, -1, h
, w
);
1817 else if (name
== "pageSize")
1819 scrollBar
->SetPageSize((int)property
->GetValue().IntegerValue());
1822 else if (name
== "viewLength")
1824 scrollBar
->SetViewLength((int)property
->GetValue().IntegerValue());
1827 else if (name
== "objectLength")
1829 scrollBar
->SetObjectLength((int)property
->GetValue().IntegerValue());
1833 return wxItemPropertyInfo::SetProperty(name
, property
);
1836 void wxScrollBarPropertyInfo::GetPropertyNames(wxStringList
& names
)
1838 wxItemPropertyInfo::GetPropertyNames(names
);
1839 names
.Add("orientation");
1841 names
.Add("pageSize");
1842 names
.Add("viewLength");
1843 names
.Add("objectLength");
1845 // Remove some properties we don't inherit
1846 names
.Delete("fontPoints");
1847 names
.Delete("fontFamily");
1848 names
.Delete("fontStyle");
1849 names
.Delete("fontWeight");
1850 names
.Delete("fontUnderlined");
1853 bool wxScrollBarPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1855 wxScrollBar
*sbar
= (wxScrollBar
*)m_propertyWindow
;
1857 resource
->SetValue1(sbar
->GetValue());
1859 int viewStart
, pageLength
, objectLength
, viewLength
;
1860 sbar
->GetValues(&viewStart
, &viewLength
, &objectLength
, &pageLength
);
1862 resource
->SetValue2(pageLength
);
1863 resource
->SetValue3(objectLength
);
1864 resource
->SetValue5(viewLength
);
1866 return wxItemPropertyInfo::InstantiateResource(resource
);
1873 wxProperty
*wxPanelPropertyInfo::GetProperty(wxString
& name
)
1875 wxPanel
*panelWindow
= (wxPanel
*)m_propertyWindow
;
1876 wxFont
*labelFont
= panelWindow
->GetLabelFont();
1877 wxFont
*buttonFont
= panelWindow
->GetButtonFont();
1879 if (name
== "labelFontPoints" || name
== "labelFontFamily" || name
== "labelFontStyle" || name
== "labelFontWeight" ||
1880 name
== "labelFontUnderlined")
1881 return GetFontProperty(name
, labelFont
);
1882 else if (name
== "buttonFontPoints" || name
== "buttonFontFamily" || name
== "buttonFontStyle" || name
== "buttonFontWeight" ||
1883 name
== "buttonFontUnderlined")
1884 return GetFontProperty(name
, buttonFont
);
1885 else if (name
== "no3D")
1888 if (panelWindow
->GetWindowStyleFlag() & wxNO_3D
)
1891 userColours
= FALSE
;
1893 return new wxProperty(name
, (bool)userColours
, "bool");
1895 else if (name
== "backgroundColour")
1897 wxColour
col(panelWindow
->GetBackgroundColour());
1899 wxDecToHex(col
.Red(), buf
);
1900 wxDecToHex(col
.Green(), buf
+2);
1901 wxDecToHex(col
.Blue(), buf
+4);
1903 return new wxProperty(name
, buf
, "string", new wxColourListValidator
);
1905 else if (name
== "title")
1907 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
1909 return new wxProperty(name
, resource
->GetTitle(), "string");
1911 return new wxProperty(name
, "Could not get title", "string");
1913 else if (name
== "caption")
1915 return new wxProperty(name
, ((panelWindow
->GetWindowStyleFlag() & wxCAPTION
) == wxCAPTION
),
1918 else if (name
== "systemMenu")
1920 return new wxProperty(name
, ((panelWindow
->GetWindowStyleFlag() & wxSYSTEM_MENU
) == wxSYSTEM_MENU
),
1923 else if (name
== "thickFrame")
1925 return new wxProperty(name
, ((panelWindow
->GetWindowStyleFlag() & wxTHICK_FRAME
) == wxTHICK_FRAME
),
1928 else if (name
== "useSystemDefaults")
1930 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
1931 return new wxProperty(name
, ((resource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) == wxRESOURCE_USE_DEFAULTS
),
1934 else if (name
== "useDialogUnits")
1936 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
1937 return new wxProperty(name
, ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) == wxRESOURCE_DIALOG_UNITS
),
1941 return wxWindowPropertyInfo::GetProperty(name
);
1944 bool wxPanelPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1946 wxPanel
*panelWindow
= (wxPanel
*)m_propertyWindow
;
1947 wxFont
*labelFont
= panelWindow
->GetLabelFont();
1948 wxFont
*buttonFont
= panelWindow
->GetButtonFont();
1950 if (labelFont
&& (name
== "labelFontPoints" || name
== "labelFontFamily" || name
== "labelFontStyle" || name
== "labelFontWeight" || name
== "labelFontUnderlined" ))
1952 wxFont
*newFont
= SetFontProperty(name
, property
, labelFont
);
1954 panelWindow
->SetLabelFont(newFont
);
1957 else if (buttonFont
&& (name
== "buttonFontPoints" || name
== "buttonFontFamily" || name
== "buttonFontStyle" || name
== "buttonFontWeight" || name
== "buttonFontUnderlined" ))
1959 wxFont
*newFont
= SetFontProperty(name
, property
, buttonFont
);
1961 panelWindow
->SetButtonFont(newFont
);
1964 else if (name
== "no3D")
1966 bool userColours
= property
->GetValue().BoolValue();
1970 if ((panelWindow
->GetWindowStyleFlag() & wxNO_3D
) != wxNO_3D
)
1971 panelWindow
->SetWindowStyleFlag(panelWindow
->GetWindowStyleFlag() | wxNO_3D
);
1975 if ((panelWindow
->GetWindowStyleFlag() & wxNO_3D
) == wxNO_3D
)
1976 panelWindow
->SetWindowStyleFlag(panelWindow
->GetWindowStyleFlag() - wxNO_3D
);
1978 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
1979 resource
->SetStyle(panelWindow
->GetWindowStyleFlag());
1981 panelWindow
= (wxPanel
*)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(panelWindow
, this);
1984 else if (name
== "backgroundColour")
1986 char *hex
= property
->GetValue().StringValue();
1987 int r
= wxHexToDec(hex
);
1988 int g
= wxHexToDec(hex
+2);
1989 int b
= wxHexToDec(hex
+4);
1991 wxColour
col(r
,g
,b
);
1992 panelWindow
->SetBackgroundColour(col
);
1993 panelWindow
= (wxPanel
*)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(panelWindow
, this);
1996 else if (name
== "title")
1998 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
2001 resource
->SetTitle(property
->GetValue().StringValue());
2007 else if (name
== "caption")
2009 SetWindowStyle(panelWindow
, wxCAPTION
, property
->GetValue().BoolValue());
2011 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
2012 resource
->SetStyle(panelWindow
->GetWindowStyleFlag());
2015 else if (name
== "thickFrame")
2017 SetWindowStyle(panelWindow
, wxTHICK_FRAME
, property
->GetValue().BoolValue());
2019 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
2020 resource
->SetStyle(panelWindow
->GetWindowStyleFlag());
2023 else if (name
== "systemMenu")
2025 SetWindowStyle(panelWindow
, wxSYSTEM_MENU
, property
->GetValue().BoolValue());
2027 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
2028 resource
->SetStyle(panelWindow
->GetWindowStyleFlag());
2031 else if (name
== "useSystemDefaults")
2033 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
2034 bool useDefaults
= property
->GetValue().BoolValue();
2035 long style
= resource
->GetResourceStyle();
2038 if ((style
& wxRESOURCE_USE_DEFAULTS
) == 0)
2039 style
|= wxRESOURCE_USE_DEFAULTS
;
2043 if ((style
& wxRESOURCE_USE_DEFAULTS
) != 0)
2044 style
-= wxRESOURCE_USE_DEFAULTS
;
2046 resource
->SetResourceStyle(style
);
2047 panelWindow
= (wxPanel
*)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(panelWindow
, this);
2050 else if (name
== "useDialogUnits")
2052 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
2053 bool useDialogUnits
= property
->GetValue().BoolValue();
2054 long style
= resource
->GetResourceStyle();
2057 if ((style
& wxRESOURCE_DIALOG_UNITS
) == 0)
2059 style
|= wxRESOURCE_DIALOG_UNITS
;
2060 ConvertDialogUnits(TRUE
); // Convert all resources
2065 if ((style
& wxRESOURCE_DIALOG_UNITS
) != 0)
2067 style
-= wxRESOURCE_DIALOG_UNITS
;
2068 ConvertDialogUnits(FALSE
); // Convert all resources
2071 resource
->SetResourceStyle(style
);
2072 panelWindow
= (wxPanel
*)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(panelWindow
, this);
2073 // TODO: need to regenerate the width and height properties else they'll be inconsistent.
2077 return wxWindowPropertyInfo::SetProperty(name
, property
);
2080 void wxPanelPropertyInfo::GetPropertyNames(wxStringList
& names
)
2082 wxWindowPropertyInfo::GetPropertyNames(names
);
2086 names
.Add("backgroundColour");
2087 names
.Add("caption");
2088 names
.Add("systemMenu");
2089 names
.Add("thickFrame");
2090 names
.Add("useSystemDefaults");
2091 names
.Add("useDialogUnits");
2094 bool wxPanelPropertyInfo::InstantiateResource(wxItemResource
*resource
)
2096 wxPanel
*panel
= (wxPanel
*)m_propertyWindow
;
2097 if (panel
->GetFont() && panel
->GetFont()->Ok())
2098 resource
->SetFont(wxTheFontList
->FindOrCreateFont(panel
->GetFont()->GetPointSize(),
2099 panel
->GetFont()->GetFamily(), panel
->GetFont()->GetStyle(), panel
->GetFont()->GetWeight(),
2100 panel
->GetFont()->GetUnderlined(), panel
->GetFont()->GetFaceName()));
2102 resource
->SetBackgroundColour(wxColour(panel
->GetBackgroundColour()));
2104 return wxWindowPropertyInfo::InstantiateResource(resource
);
2107 // Convert this dialog, and its children, to or from dialog units
2108 void wxPanelPropertyInfo::ConvertDialogUnits(bool toDialogUnits
)
2110 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
2116 sz
= m_propertyWindow
->ConvertPixelsToDialog(wxSize(resource
->GetWidth(), resource
->GetHeight()));
2117 pt
= m_propertyWindow
->ConvertPixelsToDialog(wxPoint(resource
->GetX(), resource
->GetY()));
2121 sz
= m_propertyWindow
->ConvertDialogToPixels(wxSize(resource
->GetWidth(), resource
->GetHeight()));
2122 pt
= m_propertyWindow
->ConvertDialogToPixels(wxPoint(resource
->GetX(), resource
->GetY()));
2124 resource
->SetSize(pt
.x
, pt
.y
, sz
.x
, sz
.y
);
2126 wxNode
* node
= m_propertyWindow
->GetChildren()->First();
2129 wxWindow
* child
= (wxWindow
*) node
->Data();
2130 if (child
->IsKindOf(CLASSINFO(wxControl
)))
2132 resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(child
);
2135 sz
= m_propertyWindow
->ConvertPixelsToDialog(wxSize(resource
->GetWidth(), resource
->GetHeight()));
2136 pt
= m_propertyWindow
->ConvertPixelsToDialog(wxPoint(resource
->GetX(), resource
->GetY()));
2140 sz
= m_propertyWindow
->ConvertDialogToPixels(wxSize(resource
->GetWidth(), resource
->GetHeight()));
2141 pt
= m_propertyWindow
->ConvertDialogToPixels(wxPoint(resource
->GetX(), resource
->GetY()));
2143 resource
->SetSize(pt
.x
, pt
.y
, sz
.x
, sz
.y
);
2145 node
= node
->Next();
2154 wxProperty
*wxDialogPropertyInfo::GetProperty(wxString
& name
)
2156 wxDialog
*dialogWindow
= (wxDialog
*)m_propertyWindow
;
2157 if (name
== "modal")
2159 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(dialogWindow
);
2163 bool modal
= (resource
->GetValue1() != 0);
2164 return new wxProperty(name
, modal
, "bool");
2167 return wxPanelPropertyInfo::GetProperty(name
);
2170 bool wxDialogPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
2172 wxDialog
*dialogWindow
= (wxDialog
*)m_propertyWindow
;
2174 if (name
== "modal")
2176 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(dialogWindow
);
2180 resource
->SetValue1(property
->GetValue().BoolValue());
2184 return wxPanelPropertyInfo::SetProperty(name
, property
);
2187 void wxDialogPropertyInfo::GetPropertyNames(wxStringList
& names
)
2189 wxPanelPropertyInfo::GetPropertyNames(names
);
2194 bool wxDialogPropertyInfo::InstantiateResource(wxItemResource
*resource
)
2196 wxDialog
*dialog
= (wxDialog
*)m_propertyWindow
;
2197 wxString
str(dialog
->GetTitle());
2198 resource
->SetTitle(str
);
2200 return wxPanelPropertyInfo::InstantiateResource(resource
);
2208 int wxStringToFontWeight(wxString
& val
)
2210 if (val
== "wxBOLD") return wxBOLD
;
2211 else if (val
== "wxLIGHT") return wxLIGHT
;
2212 else return wxNORMAL
;
2215 int wxStringToFontStyle(wxString
& val
)
2217 if (val
== "wxITALIC") return wxITALIC
;
2218 else if (val
== "wxSLANT") return wxSLANT
;
2219 else return wxNORMAL
;
2222 int wxStringToFontFamily(wxString
& val
)
2224 if (val
== "wxDECORATIVE") return wxDECORATIVE
;
2225 else if (val
== "wxROMAN") return wxROMAN
;
2226 else if (val
== "wxSCRIPT") return wxSCRIPT
;
2227 else if (val
== "wxMODERN") return wxMODERN
;
2228 else if (val
== "wxTELETYPE") return wxTELETYPE
;
2229 else return wxSWISS
;
2233 /// Resource symbol validator
2235 IMPLEMENT_DYNAMIC_CLASS(wxResourceSymbolValidator
, wxPropertyListValidator
)
2237 wxResourceSymbolValidator::wxResourceSymbolValidator(long flags
):
2238 wxPropertyListValidator(flags
)
2242 wxResourceSymbolValidator::~wxResourceSymbolValidator(void)
2246 bool wxResourceSymbolValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
2251 // Called when TICK is pressed or focus is lost or view wants to update
2252 // the property list.
2253 // Does the transferance from the property editing area to the property itself
2254 bool wxResourceSymbolValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
2256 if (!view
->GetValueText())
2258 wxString
value(view
->GetValueText()->GetValue());
2259 property
->GetValue() = value
;
2263 // Called when TICK is pressed or focus is lost or view wants to update
2264 // the property list.
2265 // Does the transferance from the property editing area to the property itself
2266 bool wxResourceSymbolValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
2268 if (!view
->GetValueText())
2270 wxString
str(property
->GetValue().GetStringRepresentation());
2271 view
->GetValueText()->SetValue(str
);
2275 // Called when the property is double clicked. Extra functionality can be provided,
2276 // cycling through possible values.
2277 bool wxResourceSymbolValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
2279 if (!view
->GetValueText())
2281 OnEdit(property
, view
, parentWindow
);
2285 bool wxResourceSymbolValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
2287 if (view
->GetConfirmButton())
2288 view
->GetConfirmButton()->Enable(TRUE
);
2289 if (view
->GetCancelButton())
2290 view
->GetCancelButton()->Enable(TRUE
);
2291 if (view
->GetEditButton())
2292 view
->GetEditButton()->Enable(TRUE
);
2293 if (view
->GetValueText())
2294 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
2298 void wxResourceSymbolValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
2300 if (!view
->GetValueText())
2303 wxResourceSymbolDialog
* dialog
= new wxResourceSymbolDialog(parentWindow
, -1, "Edit Symbol");
2305 // Split name/id pair e.g. "IDC_TEXT=123"
2306 wxString
value(property
->GetValue().StringValue());
2308 wxString strName
= value
.Before('=');
2309 wxString strId
= value
.After('=');
2311 dialog
->SetSymbol(strName
);
2312 dialog
->SetId(atoi(strId
));
2316 if (dialog
->ShowModal() == wxID_OK
)
2318 wxString
symbolName(dialog
->GetSymbol());
2319 long id
= dialog
->GetId();
2323 str
.Printf("%d", id
);
2324 property
->GetValue() = symbolName
+ wxString("=") + str
;
2326 view
->DisplayProperty(property
);
2327 view
->UpdatePropertyDisplayInList(property
);
2328 view
->OnPropertyChanged(property
);
2332 BEGIN_EVENT_TABLE(wxResourceSymbolDialog
, wxDialog
)
2333 EVT_BUTTON(wxID_OK
, wxResourceSymbolDialog::OnOK
)
2334 EVT_COMBOBOX(ID_SYMBOLNAME_COMBOBOX
, wxResourceSymbolDialog::OnComboBoxSelect
)
2335 EVT_TEXT(ID_SYMBOLNAME_COMBOBOX
, wxResourceSymbolDialog::OnSymbolNameUpdate
)
2338 wxResourceSymbolDialog::wxResourceSymbolDialog(wxWindow
* parent
, const wxWindowID id
, const wxString
& title
, const wxPoint
& pos
,
2339 const wxSize
& size
, long style
):
2340 wxDialog(parent
, id
, title
, pos
, size
, style
)
2345 (void) new wxStaticText(this, -1, "Name: ", wxPoint(x
, y
));
2349 m_nameCtrl
= new wxComboBox(this, ID_SYMBOLNAME_COMBOBOX
, "",
2350 wxPoint(x
, y
), wxSize(200, -1), 0, NULL
, wxCB_DROPDOWN
|wxCB_SORT
);
2355 (void) new wxStaticText(this, -1, "Id: ", wxPoint(x
, y
));
2359 m_idCtrl
= new wxTextCtrl(this, ID_SYMBOLID_TEXTCTRL
, "",
2360 wxPoint(x
, y
), wxSize(200, -1));
2364 (void) new wxButton(this, wxID_OK
, "OK", wxPoint(x
, y
), wxSize(80, -1));
2367 (void) new wxButton(this, wxID_CANCEL
, "Cancel", wxPoint(x
, y
), wxSize(80, -1));
2373 void wxResourceSymbolDialog::Init()
2376 defaultId
.Printf("%ld", m_symbolId
);
2378 m_nameCtrl
->SetValue(m_symbolName
);
2379 m_idCtrl
->SetValue(defaultId
);
2381 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().FillComboBox(m_nameCtrl
);
2384 void wxResourceSymbolDialog::OnOK(wxCommandEvent
& event
)
2388 wxDialog::OnOK(event
);
2392 bool wxResourceSymbolDialog::CheckValues()
2394 wxString
nameStr(m_nameCtrl
->GetValue());
2395 wxString
idStr(m_idCtrl
->GetValue());
2396 int id
= atoi(idStr
);
2400 wxMessageBox("Identifier cannot be missing or zero", "Dialog Editor", wxOK
|wxICON_EXCLAMATION
, this);
2405 wxMessageBox("Please enter a symbol name", "Dialog Editor", wxOK
|wxICON_EXCLAMATION
, this);
2408 if (nameStr
.Contains(" "))
2410 wxMessageBox("Symbol name cannot contain spaces.", "Dialog Editor", wxOK
|wxICON_EXCLAMATION
, this);
2413 if (nameStr
.Contains("="))
2415 wxMessageBox("Symbol name cannot contain =.", "Dialog Editor", wxOK
|wxICON_EXCLAMATION
, this);
2418 if (nameStr
.IsNumber())
2420 wxMessageBox("Symbol name cannot be a number.", "Dialog Editor", wxOK
|wxICON_EXCLAMATION
, this);
2423 // TODO: other checks on the name syntax.
2425 if (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(nameStr
))
2427 // If we change the id for an existing symbol, we need to:
2428 // 1) Check if there are any other resources currently using the original id.
2429 // If so, will need to change their id to the new id, in SetProperty.
2430 // 2) Remove the old symbol, add the new symbol.
2431 // In this check, we don't have to do this, but we need to do it in SetProperty.
2433 if (nameStr
== GetSymbol() && id
!= GetId())
2435 // It's OK to change the id. But we'll need to change all matching ids in all resources,
2439 // If we change the name but not the id... we'll just need to remove and
2440 // re-add the symbol/id pair, in SetProperty.
2441 if (nameStr
!= GetSymbol() && id
== GetId())
2445 // What if we're changing both the name and the id?
2446 // - if there's no symbol of that name, just remove the old, add the new (in SetProperty)
2447 // - if there is a symbol of that name, if id matches, do nothing. If not, veto.
2449 if (nameStr
!= GetSymbol() && id
!= GetId())
2451 if (!wxResourceManager::GetCurrentResourceManager()->IsIdentifierOK(nameStr
, id
))
2453 wxMessageBox("This integer id is already being used under a different name.\nPlease choose another.",
2454 "Dialog Editor", wxOK
|wxICON_EXCLAMATION
, this);
2467 void wxResourceSymbolDialog::OnComboBoxSelect(wxCommandEvent
& WXUNUSED(event
))
2469 wxString
str(m_nameCtrl
->GetStringSelection());
2470 if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(str
))
2472 int id
= wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str
);
2474 str2
.Printf("%d", id
);
2475 m_idCtrl
->SetValue(str2
);
2476 m_idCtrl
->Enable(FALSE
);
2480 if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().SymbolExists(str
))
2482 int id
= wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str
);
2484 str2
.Printf("%d", id
);
2485 m_idCtrl
->SetValue(str2
);
2487 m_idCtrl
->Enable(TRUE
);
2491 void wxResourceSymbolDialog::OnSymbolNameUpdate(wxCommandEvent
& WXUNUSED(event
))
2493 wxString
str(m_nameCtrl
->GetValue());
2494 if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(str
))
2496 int id
= wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str
);
2498 str2
.Printf("%d", id
);
2499 m_idCtrl
->SetValue(str2
);
2500 m_idCtrl
->Enable(FALSE
);
2504 if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().SymbolExists(str
))
2506 int id
= wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str
);
2508 str2
.Printf("%d", id
);
2509 m_idCtrl
->SetValue(str2
);
2511 m_idCtrl
->Enable(TRUE
);