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"
33 #if defined(__WXMSW__) && !defined(__GNUWIN32__)
36 #include <strstream.h>
49 // Causes immediate feedback.
50 void wxResourcePropertyListView::OnPropertyChanged(wxProperty
*property
)
52 // Sets the value of the property back into the actual object,
53 // IF the property value was modified.
54 if (property
->GetValue().GetModified())
56 m_propertyInfo
->SetProperty(property
->GetName(), property
);
57 property
->GetValue().SetModified(FALSE
);
58 wxResourceManager::GetCurrentResourceManager()->Modify(TRUE
);
62 bool wxResourcePropertyListView::OnClose(void)
65 GetManagedWindow()->GetSize(& w
, & h
);
66 GetManagedWindow()->GetPosition(& x
, & y
);
68 wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().width
= w
;
69 wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().height
= h
;
70 wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().x
= x
;
71 wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().y
= y
;
73 return wxPropertyListView::OnClose();
76 wxWindow
*wxPropertyInfo::sm_propertyWindow
;
79 * wxDialogEditorPropertyListDialog
83 wxDialogEditorPropertyListDialog::wxDialogEditorPropertyListDialog(wxPropertyListView *v, wxWindow *parent, const wxString& title,
84 const wxPoint& pos, const wxSize& size,
85 long style, const wxString& name):
86 wxPropertyListDialog(v, parent, title, pos, size, style, name)
92 wxDialogEditorPropertyListDialog::~wxDialogEditorPropertyListDialog()
96 wxPropertyInfo::sm_propertyWindow = NULL;
100 wxDialogEditorPropertyListFrame::wxDialogEditorPropertyListFrame(wxPropertyListView
*v
, wxFrame
*parent
, const wxString
& title
,
101 const wxPoint
& pos
, const wxSize
& size
,
102 long style
, const wxString
& name
):
103 wxPropertyListFrame(v
, parent
, title
, pos
, size
, style
, name
)
109 wxDialogEditorPropertyListFrame::~wxDialogEditorPropertyListFrame()
113 wxPropertyInfo::sm_propertyWindow
= NULL
;
120 // Edit the information represented by this object, whatever that
122 bool wxPropertyInfo::Edit(wxWindow
*WXUNUSED(parent
), const wxString
& title
)
124 if (sm_propertyWindow
)
126 sm_propertyWindow
->Raise();
130 int width
= wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().width
;
131 int height
= wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().height
;
132 int x
= wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().x
;
133 int y
= wxResourceManager::GetCurrentResourceManager()->GetPropertyWindowSize().y
;
135 wxPropertySheet
*propSheet
= new wxPropertySheet
;
137 wxStringList propNames
;
138 GetPropertyNames(propNames
);
140 wxNode
*node
= propNames
.First();
143 wxString
name((char *)node
->Data());
144 wxProperty
*prop
= GetProperty(name
);
147 propSheet
->AddProperty(prop
);
152 // Reset 'modified' flags for all property values
153 propSheet
->SetAllModified(FALSE
);
155 wxResourcePropertyListView
*view
= new wxResourcePropertyListView(this, NULL
,
156 wxPROP_BUTTON_OK
| wxPROP_BUTTON_CANCEL
|
157 wxPROP_BUTTON_CHECK_CROSS
|wxPROP_DYNAMIC_VALUE_FIELD
|wxPROP_PULLDOWN
|wxPROP_SHOWVALUES
);
159 wxDialogEditorPropertyListFrame
*propWin
= new wxDialogEditorPropertyListFrame(view
,
160 wxResourceManager::GetCurrentResourceManager()->GetEditorFrame(), title
, wxPoint(x
, y
),
161 wxSize(width
, height
), wxDEFAULT_FRAME_STYLE
);
162 sm_propertyWindow
= propWin
;
164 propWin
->m_registry
.RegisterValidator(wxString("real"), new wxRealListValidator
);
165 propWin
->m_registry
.RegisterValidator(wxString("string"), new wxStringListValidator
);
166 propWin
->m_registry
.RegisterValidator(wxString("integer"), new wxIntegerListValidator
);
167 propWin
->m_registry
.RegisterValidator(wxString("bool"), new wxBoolListValidator
);
168 propWin
->m_registry
.RegisterValidator(wxString("filename"), new wxFilenameListValidator
);
169 propWin
->m_registry
.RegisterValidator(wxString("stringlist"), new wxListOfStringsListValidator
);
170 propWin
->m_registry
.RegisterValidator(wxString("window_id"), new wxResourceSymbolValidator
);
172 propWin
->m_propInfo
= this;
173 propWin
->m_propSheet
= propSheet
;
175 // view->m_propertyWindow = propWin;
176 view
->AddRegistry(&(propWin
->m_registry
));
178 propWin
->Initialize();
179 view
->ShowView(propSheet
, propWin
->GetPropertyPanel());
186 * wxWindowPropertyInfo
189 wxWindowPropertyInfo::wxWindowPropertyInfo(wxWindow
*win
, wxItemResource
*res
)
191 m_propertyWindow
= win
;
192 m_propertyResource
= res
;
195 wxWindowPropertyInfo::~wxWindowPropertyInfo(void)
199 wxProperty
*wxWindowPropertyInfo::GetFontProperty(wxString
& name
, wxFont
*font
)
204 if (name
.Contains("Points"))
205 return new wxProperty(name
, (long)font
->GetPointSize(), "integer", new wxIntegerListValidator(1, 100));
206 else if (name
.Contains("Family"))
207 return new wxProperty(name
, font
->GetFamilyString(), "string",
208 new wxStringListValidator(new wxStringList("wxDECORATIVE", "wxROMAN", "wxSCRIPT", "wxSWISS", "wxMODERN",
210 else if (name
.Contains("Style"))
211 return new wxProperty(name
, font
->GetStyleString(), "string",
212 new wxStringListValidator(new wxStringList("wxNORMAL", "wxITALIC", "wxSLANT", NULL
)));
213 else if (name
.Contains("Weight"))
214 return new wxProperty(name
, font
->GetWeightString(), "string",
215 new wxStringListValidator(new wxStringList("wxNORMAL", "wxBOLD", "wxLIGHT", NULL
)));
216 else if (name
.Contains("Underlined"))
217 return new wxProperty(name
, (bool)font
->GetUnderlined(), "bool");
222 wxFont
*wxWindowPropertyInfo::SetFontProperty(wxString
& name
, wxProperty
*property
, wxFont
*font
)
225 int fontFamily
= wxMODERN
;
226 int fontStyle
= wxNORMAL
;
227 int fontWeight
= wxNORMAL
;
228 bool fontUnderlined
= FALSE
;
230 if (name
.Contains("Points"))
232 pointSize
= (int)property
->GetValue().IntegerValue();
233 if (font
&& (pointSize
== font
->GetPointSize()))
234 return NULL
; // No change
236 else if (font
) pointSize
= font
->GetPointSize();
238 if (name
.Contains("Family"))
240 wxString val
= property
->GetValue().StringValue();
241 fontFamily
= wxStringToFontFamily(val
);
243 if (font
&& (fontFamily
== font
->GetFamily()))
244 return NULL
; // No change
246 else if (font
) fontFamily
= font
->GetFamily();
248 if (name
.Contains("Style"))
250 wxString val
= property
->GetValue().StringValue();
251 fontStyle
= wxStringToFontStyle(val
);
253 if (font
&& (fontStyle
== font
->GetStyle()))
254 return NULL
; // No change
256 else if (font
) fontStyle
= font
->GetStyle();
257 if (name
.Contains("Weight"))
259 wxString val
= property
->GetValue().StringValue();
260 fontWeight
= wxStringToFontWeight(val
);
262 if (font
&& (fontWeight
== font
->GetWeight()))
263 return NULL
; // No change
265 else if (font
) fontWeight
= font
->GetWeight();
267 if (name
.Contains("Underlined"))
269 fontUnderlined
= property
->GetValue().BoolValue();
271 if (font
&& (fontUnderlined
== font
->GetUnderlined()))
272 return NULL
; // No change
274 else if (font
) fontUnderlined
= font
->GetUnderlined();
276 wxFont
*newFont
= wxTheFontList
->FindOrCreateFont(pointSize
, fontFamily
, fontStyle
, fontWeight
, fontUnderlined
);
285 wxProperty
*wxWindowPropertyInfo::GetProperty(wxString
& name
)
287 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
289 wxFont
*font
= & m_propertyWindow
->GetFont();
290 if (name
== "fontPoints" || name
== "fontFamily" || name
== "fontStyle" || name
== "fontWeight" ||
291 name
== "fontUnderlined")
292 return GetFontProperty(name
, font
);
293 else if (name
== "name")
294 return new wxProperty("name", m_propertyWindow
->GetName(), "string");
295 else if (name
== "title")
296 return new wxProperty("title", m_propertyWindow
->GetTitle(), "string");
297 else if (name
== "x")
299 return new wxProperty("x", (long)resource
->GetX(), "integer");
301 else if (name
== "y")
303 return new wxProperty("y", (long)resource
->GetY(), "integer");
305 else if (name
== "width")
307 return new wxProperty("width", (long)resource
->GetWidth(), "integer");
309 else if (name
== "height")
311 return new wxProperty("height", (long)resource
->GetHeight(), "integer");
313 else if (name
== "id")
315 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
318 int id
= resource
->GetId();
320 idStr
.Printf("%d", id
);
321 wxString symbolName
= wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetSymbolForId(id
);
324 // symbolName is now e.g. "ID_PANEL21=105"
325 return new wxProperty("id", symbolName
, "window_id");
330 else if (name
== "border")
333 if (m_propertyWindow
->GetWindowStyleFlag() & wxSIMPLE_BORDER
)
334 border
= "wxSIMPLE_BORDER";
335 else if (m_propertyWindow
->GetWindowStyleFlag() & wxRAISED_BORDER
)
336 border
= "wxRAISED_BORDER";
337 else if (m_propertyWindow
->GetWindowStyleFlag() & wxSUNKEN_BORDER
)
338 border
= "wxSUNKEN_BORDER";
339 else if (m_propertyWindow
->GetWindowStyleFlag() & wxDOUBLE_BORDER
)
340 border
= "wxDOUBLE_BORDER";
341 else if (m_propertyWindow
->GetWindowStyleFlag() & wxSTATIC_BORDER
)
342 border
= "wxSTATIC_BORDER";
344 border
= "wxNO_BORDER";
346 return new wxProperty("border", border
, "string",
347 new wxStringListValidator(new wxStringList("wxSIMPLE_BORDER", "wxRAISED_BORDER",
348 "wxSUNKEN_BORDER", "wxDOUBLE_BORDER", "wxSTATIC_BORDER", "wxNO_BORDER", NULL
)));
354 bool wxWindowPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
356 wxFont
*font
= & m_propertyWindow
->GetFont();
357 if (font
&& (name
== "fontPoints" || name
== "fontFamily" || name
== "fontStyle" || name
== "fontWeight" || name
== "fontUnderlined" ))
359 wxFont
*newFont
= SetFontProperty(name
, property
, font
);
361 m_propertyWindow
->SetFont(* newFont
);
364 else if (name
== "name")
366 // Remove old name from resource table, if it's there.
367 wxItemResource
*oldResource
= (wxItemResource
*)wxResourceManager::GetCurrentResourceManager()->GetResourceTable().Delete(m_propertyWindow
->GetName());
370 // It's a top-level resource
371 m_propertyWindow
->SetName(property
->GetValue().StringValue());
372 oldResource
->SetName(property
->GetValue().StringValue());
373 wxResourceManager::GetCurrentResourceManager()->GetResourceTable().Put(m_propertyWindow
->GetName(), oldResource
);
377 // It's a child of something; just set the name of the resource and the window.
378 m_propertyWindow
->SetName(property
->GetValue().StringValue());
379 m_propertyResource
->SetName(property
->GetValue().StringValue());
381 // Refresh the resource manager list, because the name changed.
382 wxResourceManager::GetCurrentResourceManager()->UpdateResourceList();
385 else if (name
== "title")
387 m_propertyWindow
->SetTitle(property
->GetValue().StringValue());
390 else if (name
== "x")
393 m_propertyWindow
->GetPosition(&x
, &y
);
394 int newX
= (int)property
->GetValue().IntegerValue();
396 // We need to convert to pixels if this is not a dialog or panel, but
397 // the parent resource specifies dialog units.
398 if (m_propertyWindow
->GetParent() && m_propertyWindow
->IsKindOf(CLASSINFO(wxControl
)))
400 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
->GetParent());
401 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
403 wxPoint pt
= m_propertyWindow
->GetParent()->ConvertDialogToPixels(wxPoint(newX
, y
));
407 else if (m_propertyWindow
->IsKindOf(CLASSINFO(wxPanel
)))
409 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
410 if (resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
412 wxPoint pt
= m_propertyWindow
->ConvertDialogToPixels(wxPoint(newX
, y
));
418 m_propertyWindow
->Move(newX
, y
);
421 else if (name
== "y")
424 m_propertyWindow
->GetPosition(&x
, &y
);
425 int newY
= (int)property
->GetValue().IntegerValue();
427 // We need to convert to pixels if this is not a dialog or panel, but
428 // the parent resource specifies dialog units.
429 if (m_propertyWindow
->GetParent() && m_propertyWindow
->IsKindOf(CLASSINFO(wxControl
)))
431 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
->GetParent());
432 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
434 wxPoint pt
= m_propertyWindow
->GetParent()->ConvertDialogToPixels(wxPoint(x
, newY
));
438 else if (m_propertyWindow
->IsKindOf(CLASSINFO(wxPanel
)))
440 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
441 if (resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
443 wxPoint pt
= m_propertyWindow
->ConvertDialogToPixels(wxPoint(x
, newY
));
449 m_propertyWindow
->Move(x
, newY
);
452 else if (name
== "width")
455 m_propertyWindow
->GetSize(&width
, &height
);
456 int newWidth
= (int)property
->GetValue().IntegerValue();
458 // We need to convert to pixels if this is not a dialog or panel, but
459 // the parent resource specifies dialog units.
460 if (m_propertyWindow
->GetParent() && m_propertyWindow
->IsKindOf(CLASSINFO(wxControl
)))
462 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
->GetParent());
463 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
465 wxSize sz
= m_propertyWindow
->GetParent()->ConvertDialogToPixels(wxSize(newWidth
, height
));
469 else if (m_propertyWindow
->IsKindOf(CLASSINFO(wxPanel
)))
471 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
472 if (resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
474 wxSize sz
= m_propertyWindow
->ConvertDialogToPixels(wxSize(newWidth
, height
));
479 if (width
!= newWidth
)
481 m_propertyWindow
->SetSize(newWidth
, height
);
485 else if (name
== "height")
488 m_propertyWindow
->GetSize(&width
, &height
);
489 int newHeight
= (int)property
->GetValue().IntegerValue();
491 // We need to convert to pixels if this is not a dialog or panel, but
492 // the parent resource specifies dialog units.
493 if (m_propertyWindow
->GetParent() && m_propertyWindow
->IsKindOf(CLASSINFO(wxControl
)))
495 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
->GetParent());
496 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
498 wxSize sz
= m_propertyWindow
->GetParent()->ConvertDialogToPixels(wxSize(width
, newHeight
));
502 else if (m_propertyWindow
->IsKindOf(CLASSINFO(wxPanel
)))
504 wxItemResource
* resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
505 if (resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
507 wxSize sz
= m_propertyWindow
->ConvertDialogToPixels(wxSize(width
, newHeight
));
512 if (height
!= newHeight
)
514 m_propertyWindow
->SetSize(width
, newHeight
);
518 else if (name
== "id")
520 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
523 wxString value
= property
->GetValue().StringValue();
525 wxString strName
= value
.Before('=');
526 wxString strId
= value
.After('=');
527 int id
= atoi(strId
);
529 wxString oldSymbolName
= wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetSymbolForId(resource
->GetId());
530 int oldSymbolId
= resource
->GetId();
534 // If we change the id for an existing symbol, we need to:
535 // 1) Check if there are any other resources currently using the original id.
536 // If so, will need to change their id to the new id.
537 // 2) Remove the old symbol, add the new symbol.
538 // In this check, we don't have to do this, but we need to do it in SetProperty.
540 if (strName
== oldSymbolName
&& id
!= oldSymbolId
)
542 wxASSERT( (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(oldSymbolName
)) );
544 // It's OK to change just the id. But we'll need to change all matching ids in all resources,
545 // because ids are unique and changing one resource's id must change all identical ones.
546 wxResourceManager::GetCurrentResourceManager()->ChangeIds(oldSymbolId
, id
);
548 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().RemoveSymbol(oldSymbolName
);
549 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().AddSymbol(strName
, id
);
552 // If we change the name but not the id, we'll just need to remove and
553 // re-add the symbol/id pair.
554 if (strName
!= oldSymbolName
&& id
== oldSymbolId
)
556 wxASSERT( (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(oldSymbolName
)) );
558 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().RemoveSymbol(oldSymbolName
);
560 if (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().SymbolExists(strName
))
562 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().AddSymbol(strName
, id
);
566 // What if we're changing both the name and the id?
567 // - if there's no symbol of that name, just remove the old, add the new (in SetProperty)
568 // - if there is a symbol of that name, if id matches, do nothing. If not, veto.
570 if (strName
!= oldSymbolName
&& id
!= oldSymbolId
)
572 // Remove old symbol if it's not being used
573 if (!wxResourceManager::GetCurrentResourceManager()->IsSymbolUsed(resource
, oldSymbolId
) &&
574 !wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(oldSymbolName
))
576 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().RemoveSymbol(oldSymbolName
);
579 if (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().SymbolExists(strName
))
581 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().AddSymbol(strName
, id
);
592 else if (name
== "border")
594 long borderStyle
= wxNO_BORDER
;
595 wxString val
= property
->GetValue().StringValue();
597 if (val
== "wxSIMPLE_BORDER")
598 borderStyle
= wxSIMPLE_BORDER
;
599 else if (val
== "wxRAISED_BORDER")
600 borderStyle
= wxRAISED_BORDER
;
601 else if (val
== "wxSUNKEN_BORDER")
602 borderStyle
= wxSUNKEN_BORDER
;
603 else if (val
== "wxDOUBLE_BORDER")
604 borderStyle
= wxDOUBLE_BORDER
;
605 else if (val
== "wxSTATIC_BORDER")
606 borderStyle
= wxSTATIC_BORDER
;
608 borderStyle
= wxNO_BORDER
;
610 SetWindowStyle(m_propertyWindow
, wxSIMPLE_BORDER
, FALSE
);
611 SetWindowStyle(m_propertyWindow
, wxRAISED_BORDER
, FALSE
);
612 SetWindowStyle(m_propertyWindow
, wxSUNKEN_BORDER
, FALSE
);
613 SetWindowStyle(m_propertyWindow
, wxDOUBLE_BORDER
, FALSE
);
614 SetWindowStyle(m_propertyWindow
, wxSTATIC_BORDER
, FALSE
);
615 SetWindowStyle(m_propertyWindow
, wxNO_BORDER
, FALSE
);
617 SetWindowStyle(m_propertyWindow
, borderStyle
, TRUE
);
619 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
620 resource
->SetStyle(m_propertyWindow
->GetWindowStyleFlag());
627 void wxWindowPropertyInfo::GetPropertyNames(wxStringList
& names
)
636 if (!m_propertyWindow
->IsKindOf(CLASSINFO(wxControl
)))
638 names
.Add("fontPoints");
639 names
.Add("fontFamily");
640 names
.Add("fontStyle");
641 names
.Add("fontWeight");
642 names
.Add("fontUnderlined");
646 // Fill in the wxItemResource members to mirror the current window settings
647 bool wxWindowPropertyInfo::InstantiateResource(wxItemResource
*resource
)
649 // resource->SetType(m_propertyWindow->GetClassInfo()->GetClassName());
651 // resource->SetStyle(m_propertyWindow->GetWindowStyleFlag());
652 wxString
str(m_propertyWindow
->GetName());
653 resource
->SetName(str
);
658 if (m_propertyWindow
->IsKindOf(CLASSINFO(wxPanel
)))
659 m_propertyWindow
->GetClientSize(&w
, &h
);
661 m_propertyWindow
->GetSize(&w
, &h
);
663 m_propertyWindow
->GetPosition(&x
, &y
);
665 // We need to convert to dialog units if this is not a dialog or panel, but
666 // the parent resource specifies dialog units.
667 if (m_propertyWindow
->GetParent() && m_propertyWindow
->IsKindOf(CLASSINFO(wxControl
)))
669 wxItemResource
* parentResource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
->GetParent());
670 if (parentResource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
672 wxPoint pt
= m_propertyWindow
->GetParent()->ConvertPixelsToDialog(wxPoint(x
, y
));
674 wxSize sz
= m_propertyWindow
->GetParent()->ConvertPixelsToDialog(wxSize(w
, h
));
678 else if (m_propertyWindow
->IsKindOf(CLASSINFO(wxPanel
)))
680 if (resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
)
682 wxPoint pt
= m_propertyWindow
->ConvertPixelsToDialog(wxPoint(x
, y
));
684 wxSize sz
= m_propertyWindow
->ConvertPixelsToDialog(wxSize(w
, h
));
689 resource
->SetSize(x
, y
, w
, h
);
695 // Set the window style
696 void wxWindowPropertyInfo::SetWindowStyle(wxWindow
* win
, long style
, bool set
)
701 if ((win
->GetWindowStyleFlag() & style
) == style
)
705 win
->SetWindowStyleFlag(win
->GetWindowStyleFlag() - style
);
712 win
->SetWindowStyleFlag(win
->GetWindowStyleFlag() | style
);
721 wxProperty
*wxItemPropertyInfo::GetProperty(wxString
& name
)
723 wxControl
*itemWindow
= (wxControl
*)m_propertyWindow
;
724 wxFont
*font
= & itemWindow
->GetFont();
726 if (name
== "fontPoints" || name
== "fontFamily" || name
== "fontStyle" || name
== "fontWeight" ||
727 name
== "fontUnderlined")
728 return GetFontProperty(name
, font
);
729 else if (name
== "label" && itemWindow
->GetLabel())
730 return new wxProperty("label", m_propertyWindow
->GetLabel(), "string");
732 return wxWindowPropertyInfo::GetProperty(name
);
735 bool wxItemPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
737 wxControl
*itemWindow
= (wxControl
*)m_propertyWindow
;
738 wxFont
*font
= & itemWindow
->GetFont();
740 if (font
&& (name
== "fontPoints" || name
== "fontFamily" || name
== "fontStyle" || name
== "fontWeight" || name
== "fontUnderlined" ))
742 wxFont
*newFont
= SetFontProperty(name
, property
, font
);
744 itemWindow
->SetLabelFont(* newFont
);
747 else if (name
== "label")
749 itemWindow
->SetLabel(property
->GetValue().StringValue());
753 return wxWindowPropertyInfo::SetProperty(name
, property
);
756 void wxItemPropertyInfo::GetPropertyNames(wxStringList
& names
)
758 wxWindowPropertyInfo::GetPropertyNames(names
);
760 names
.Add("fontPoints");
761 names
.Add("fontFamily");
762 names
.Add("fontStyle");
763 names
.Add("fontWeight");
764 names
.Add("fontUnderlined");
767 bool wxItemPropertyInfo::InstantiateResource(wxItemResource
*resource
)
769 wxWindowPropertyInfo::InstantiateResource(resource
);
771 wxControl
*item
= (wxControl
*)m_propertyWindow
;
772 wxString
str(item
->GetLabel());
773 resource
->SetTitle(str
);
774 if (item
->GetFont().Ok())
775 resource
->SetFont(* wxTheFontList
->FindOrCreateFont(item
->GetFont().GetPointSize(),
776 item
->GetFont().GetFamily(), item
->GetFont().GetStyle(), item
->GetFont().GetWeight(),
777 item
->GetFont().GetUnderlined(), item
->GetFont().GetFaceName()));
785 wxProperty
*wxButtonPropertyInfo::GetProperty(wxString
& name
)
787 return wxItemPropertyInfo::GetProperty(name
);
790 bool wxButtonPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
792 return wxItemPropertyInfo::SetProperty(name
, property
);
795 void wxButtonPropertyInfo::GetPropertyNames(wxStringList
& names
)
797 wxItemPropertyInfo::GetPropertyNames(names
);
801 bool wxButtonPropertyInfo::InstantiateResource(wxItemResource
*resource
)
803 return wxItemPropertyInfo::InstantiateResource(resource
);
810 wxProperty
*wxBitmapButtonPropertyInfo::GetProperty(wxString
& name
)
812 wxBitmapButton
*button
= (wxBitmapButton
*)m_propertyWindow
;
813 if (name
== "bitmapFilename")
815 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(button
);
816 wxString
str("none.bmp");
820 str
= wxResourceManager::GetCurrentResourceManager()->FindBitmapFilenameForResource(resource
);
822 return new wxProperty("bitmapFilename", str
.GetData(), "string", new wxFilenameListValidator("Select a bitmap file", "*.bmp"));
825 return wxButtonPropertyInfo::GetProperty(name
);
828 bool wxBitmapButtonPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
830 wxBitmapButton
*button
= (wxBitmapButton
*)m_propertyWindow
;
831 if (name
== "bitmapFilename")
833 char *s
= property
->GetValue().StringValue();
834 if (s
&& wxFileExists(s
))
837 wxBitmap
*bitmap
= new wxBitmap(s
, wxBITMAP_TYPE_BMP
);
846 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(button
);
849 wxString
oldResource(resource
->GetValue4());
850 wxString resName
= wxResourceManager::GetCurrentResourceManager()->AddBitmapResource(s
);
851 resource
->SetValue4(resName
);
853 if (!oldResource
.IsNull())
854 wxResourceManager::GetCurrentResourceManager()->PossiblyDeleteBitmapResource(oldResource
);
857 button
->SetLabel(* bitmap
);
865 return wxButtonPropertyInfo::SetProperty(name
, property
);
868 void wxBitmapButtonPropertyInfo::GetPropertyNames(wxStringList
& names
)
870 wxButtonPropertyInfo::GetPropertyNames(names
);
871 names
.Delete("label");
872 names
.Add("bitmapFilename");
875 bool wxBitmapButtonPropertyInfo::InstantiateResource(wxItemResource
*resource
)
877 return wxItemPropertyInfo::InstantiateResource(resource
);
884 wxProperty
*wxStaticTextPropertyInfo::GetProperty(wxString
& name
)
886 return wxItemPropertyInfo::GetProperty(name
);
889 bool wxStaticTextPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
891 return wxItemPropertyInfo::SetProperty(name
, property
);
894 void wxStaticTextPropertyInfo::GetPropertyNames(wxStringList
& names
)
896 wxItemPropertyInfo::GetPropertyNames(names
);
900 bool wxStaticTextPropertyInfo::InstantiateResource(wxItemResource
*resource
)
902 return wxItemPropertyInfo::InstantiateResource(resource
);
909 wxProperty
*wxStaticBitmapPropertyInfo::GetProperty(wxString
& name
)
911 wxStaticBitmap
*message
= (wxStaticBitmap
*)m_propertyWindow
;
912 if (name
== "bitmapFilename")
914 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(message
);
915 wxString
str("none.bmp");
919 str
= wxResourceManager::GetCurrentResourceManager()->FindBitmapFilenameForResource(resource
);
921 return new wxProperty("bitmapFilename", str
.GetData(), "string", new wxFilenameListValidator("Select a bitmap file", "*.bmp"));
924 return wxItemPropertyInfo::GetProperty(name
);
927 bool wxStaticBitmapPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
929 wxStaticBitmap
*message
= (wxStaticBitmap
*)m_propertyWindow
;
930 if (name
== "bitmapFilename")
932 char *s
= property
->GetValue().StringValue();
933 if (s
&& wxFileExists(s
))
937 wxBitmap
*bitmap
= new wxBitmap(s
, wxBITMAP_TYPE_BMP
);
946 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(message
);
949 wxString
oldResource(resource
->GetValue4());
950 wxString resName
= wxResourceManager::GetCurrentResourceManager()->AddBitmapResource(s
);
951 resource
->SetValue4(resName
);
953 if (!oldResource
.IsNull())
954 wxResourceManager::GetCurrentResourceManager()->PossiblyDeleteBitmapResource(oldResource
);
957 message
->SetBitmap(* bitmap
);
965 return wxItemPropertyInfo::SetProperty(name
, property
);
968 void wxStaticBitmapPropertyInfo::GetPropertyNames(wxStringList
& names
)
970 wxItemPropertyInfo::GetPropertyNames(names
);
971 names
.Add("bitmapFilename");
974 bool wxStaticBitmapPropertyInfo::InstantiateResource(wxItemResource
*resource
)
976 return wxItemPropertyInfo::InstantiateResource(resource
);
983 wxProperty
*wxTextPropertyInfo::GetProperty(wxString
& name
)
985 wxTextCtrl
*text
= (wxTextCtrl
*)m_propertyWindow
;
987 return new wxProperty("value", text
->GetValue(), "string");
988 else if (name
== "password")
990 bool isPassword
= ((text
->GetWindowStyleFlag() & wxTE_PASSWORD
) == wxTE_PASSWORD
);
991 return new wxProperty("password", isPassword
, "bool");
993 else if (name
== "readonly")
995 bool isReadOnly
= ((text
->GetWindowStyleFlag() & wxTE_READONLY
) == wxTE_READONLY
);
996 return new wxProperty("readonly", isReadOnly
, "bool");
999 return wxItemPropertyInfo::GetProperty(name
);
1002 bool wxTextPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1004 wxTextCtrl
*text
= (wxTextCtrl
*)m_propertyWindow
;
1005 if (name
== "value")
1007 text
->SetValue(property
->GetValue().StringValue());
1010 else if (name
== "password")
1012 long flag
= text
->GetWindowStyleFlag();
1013 if (property
->GetValue().BoolValue())
1015 if ((flag
& wxTE_PASSWORD
) != wxTE_PASSWORD
)
1016 flag
|= wxTE_PASSWORD
;
1020 if ((flag
& wxTE_PASSWORD
) == wxTE_PASSWORD
)
1021 flag
-= wxTE_PASSWORD
;
1023 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(text
);
1024 resource
->SetStyle(flag
);
1026 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(text
, this);
1029 else if (name
== "readonly")
1031 long flag
= text
->GetWindowStyleFlag();
1032 if (property
->GetValue().BoolValue())
1034 if ((flag
& wxTE_READONLY
) != wxTE_READONLY
)
1035 flag
|= wxTE_READONLY
;
1039 if ((flag
& wxTE_READONLY
) == wxTE_READONLY
)
1040 flag
-= wxTE_READONLY
;
1042 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(text
);
1043 resource
->SetStyle(flag
);
1045 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(text
, this);
1049 return wxItemPropertyInfo::SetProperty(name
, property
);
1052 void wxTextPropertyInfo::GetPropertyNames(wxStringList
& names
)
1054 wxItemPropertyInfo::GetPropertyNames(names
);
1056 names
.Add("readonly");
1057 names
.Add("password");
1060 bool wxTextPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1062 wxTextCtrl
*text
= (wxTextCtrl
*)m_propertyWindow
;
1063 wxString
str(text
->GetValue());
1064 resource
->SetValue4(str
);
1066 return wxItemPropertyInfo::InstantiateResource(resource
);
1073 wxProperty
*wxListBoxPropertyInfo::GetProperty(wxString
& name
)
1075 wxListBox
*listBox
= (wxListBox
*)m_propertyWindow
;
1076 if (name
== "values")
1078 wxStringList
*stringList
= new wxStringList
;
1080 for (i
= 0; i
< listBox
->Number(); i
++)
1081 stringList
->Add(listBox
->GetString(i
));
1083 return new wxProperty(name
, stringList
, "stringlist");
1085 else if (name
== "multiple")
1087 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(listBox
);
1091 char *mult
= "wxLB_SINGLE";
1093 if ((listBox
->GetWindowStyleFlag() & wxLB_MULTIPLE
) != 0)
1094 mult
= "wxLB_MULTIPLE";
1095 else if ((listBox
->GetWindowStyleFlag() & wxLB_EXTENDED
) != 0)
1096 mult
= "wxLB_EXTENDED";
1098 mult
= "wxLB_SINGLE";
1100 return new wxProperty("multiple", mult
, "string",
1101 new wxStringListValidator(new wxStringList("wxLB_SINGLE", "wxLB_MULTIPLE", "wxLB_EXTENDED",
1105 return wxItemPropertyInfo::GetProperty(name
);
1108 bool wxListBoxPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1110 wxListBox
*listBox
= (wxListBox
*)m_propertyWindow
;
1111 if (name
== "values")
1114 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
1117 char *s
= expr
->StringValue();
1120 expr
= expr
->GetNext();
1124 else if (name
== "multiple")
1126 SetWindowStyle(m_propertyWindow
, wxLB_SINGLE
, FALSE
);
1127 SetWindowStyle(m_propertyWindow
, wxLB_MULTIPLE
, FALSE
);
1128 SetWindowStyle(m_propertyWindow
, wxLB_EXTENDED
, FALSE
);
1130 wxString
str(property
->GetValue().StringValue());
1131 if (str
== "wxLB_MULTIPLE")
1132 SetWindowStyle(m_propertyWindow
, wxLB_MULTIPLE
, TRUE
);
1133 else if (str
== "wxLB_EXTENDED")
1134 SetWindowStyle(m_propertyWindow
, wxLB_EXTENDED
, TRUE
);
1136 SetWindowStyle(m_propertyWindow
, wxLB_SINGLE
, TRUE
);
1138 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(listBox
);
1140 resource
->SetStyle(m_propertyWindow
->GetWindowStyleFlag());
1141 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(listBox
, this);
1145 return wxItemPropertyInfo::SetProperty(name
, property
);
1148 void wxListBoxPropertyInfo::GetPropertyNames(wxStringList
& names
)
1150 wxItemPropertyInfo::GetPropertyNames(names
);
1151 names
.Add("values");
1152 names
.Add("multiple");
1155 bool wxListBoxPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1157 wxListBox
*lbox
= (wxListBox
*)m_propertyWindow
;
1158 // This will be set for the wxItemResource on reading or in SetProperty
1159 // resource->SetValue1(lbox->GetSelectionMode());
1161 if (lbox
->Number() == 0)
1162 resource
->SetStringValues(NULL
);
1167 for (i
= 0; i
< lbox
->Number(); i
++)
1168 slist
.Add(lbox
->GetString(i
));
1170 resource
->SetStringValues(slist
);
1172 return wxItemPropertyInfo::InstantiateResource(resource
);
1179 wxProperty
*wxChoicePropertyInfo::GetProperty(wxString
& name
)
1181 wxChoice
*choice
= (wxChoice
*)m_propertyWindow
;
1182 if (name
== "values")
1184 wxStringList
* stringList
= new wxStringList
;
1186 for (i
= 0; i
< choice
->Number(); i
++)
1187 stringList
->Add(choice
->GetString(i
));
1189 return new wxProperty(name
, stringList
, "stringlist");
1192 return wxItemPropertyInfo::GetProperty(name
);
1195 bool wxChoicePropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1197 wxChoice
*choice
= (wxChoice
*)m_propertyWindow
;
1198 if (name
== "values")
1201 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
1204 char *s
= expr
->StringValue();
1207 expr
= expr
->GetNext();
1209 if (choice
->Number() > 0)
1210 choice
->SetSelection(0);
1214 return wxItemPropertyInfo::SetProperty(name
, property
);
1217 void wxChoicePropertyInfo::GetPropertyNames(wxStringList
& names
)
1219 wxItemPropertyInfo::GetPropertyNames(names
);
1220 names
.Add("values");
1223 bool wxChoicePropertyInfo::InstantiateResource(wxItemResource
*resource
)
1225 wxChoice
*choice
= (wxChoice
*)m_propertyWindow
;
1227 if (choice
->Number() == 0)
1228 resource
->SetStringValues(NULL
);
1233 for (i
= 0; i
< choice
->Number(); i
++)
1234 slist
.Add(choice
->GetString(i
));
1236 resource
->SetStringValues(slist
);
1238 return wxItemPropertyInfo::InstantiateResource(resource
);
1245 wxProperty
*wxComboBoxPropertyInfo::GetProperty(wxString
& name
)
1247 wxComboBox
*choice
= (wxComboBox
*)m_propertyWindow
;
1248 if (name
== "values")
1250 wxStringList
*stringList
= new wxStringList
;
1252 for (i
= 0; i
< choice
->Number(); i
++)
1253 stringList
->Add(choice
->GetString(i
));
1255 return new wxProperty(name
, stringList
, "stringlist");
1257 else if (name
== "sort")
1259 bool sort
= ((m_propertyWindow
->GetWindowStyleFlag() & wxCB_SORT
) == wxCB_SORT
);
1260 return new wxProperty(name
, sort
, "bool");
1262 else if (name
== "style")
1264 wxString
styleStr("dropdown");
1265 if (m_propertyWindow
->GetWindowStyleFlag() & wxCB_SIMPLE
)
1266 styleStr
= "simple";
1267 else if (m_propertyWindow
->GetWindowStyleFlag() & wxCB_READONLY
)
1268 styleStr
= "readonly";
1270 styleStr
= "dropdown";
1272 return new wxProperty(name
, styleStr
, "string",
1273 new wxStringListValidator(new wxStringList("simple", "dropdown", "readonly",
1277 return wxItemPropertyInfo::GetProperty(name
);
1280 bool wxComboBoxPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1282 wxComboBox
*choice
= (wxComboBox
*)m_propertyWindow
;
1283 if (name
== "values")
1286 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
1289 char *s
= expr
->StringValue();
1292 expr
= expr
->GetNext();
1294 if (choice
->Number() > 0)
1295 choice
->SetSelection(0);
1298 else if (name
== "sort")
1300 SetWindowStyle(m_propertyWindow
, wxCB_SORT
, property
->GetValue().BoolValue());
1302 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
1303 resource
->SetStyle(m_propertyWindow
->GetWindowStyleFlag());
1305 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(m_propertyWindow
, this);
1308 else if (name
== "style")
1310 SetWindowStyle(m_propertyWindow
, wxCB_SIMPLE
, FALSE
);
1311 SetWindowStyle(m_propertyWindow
, wxCB_DROPDOWN
, FALSE
);
1312 SetWindowStyle(m_propertyWindow
, wxCB_READONLY
, FALSE
);
1314 wxString
styleStr(property
->GetValue().StringValue());
1315 if (styleStr
== "simple")
1316 SetWindowStyle(m_propertyWindow
, wxCB_SIMPLE
, TRUE
);
1317 else if (styleStr
== "dropdown")
1318 SetWindowStyle(m_propertyWindow
, wxCB_DROPDOWN
, TRUE
);
1319 else if (styleStr
== "readonly")
1320 SetWindowStyle(m_propertyWindow
, wxCB_READONLY
, TRUE
);
1323 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
1324 resource
->SetStyle(m_propertyWindow
->GetWindowStyleFlag());
1326 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(m_propertyWindow
, this);
1331 return wxItemPropertyInfo::SetProperty(name
, property
);
1334 void wxComboBoxPropertyInfo::GetPropertyNames(wxStringList
& names
)
1336 wxItemPropertyInfo::GetPropertyNames(names
);
1337 names
.Add("values");
1342 bool wxComboBoxPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1344 wxComboBox
*choice
= (wxComboBox
*)m_propertyWindow
;
1346 if (choice
->Number() == 0)
1347 resource
->SetStringValues(NULL
);
1352 for (i
= 0; i
< choice
->Number(); i
++)
1353 slist
.Add(choice
->GetString(i
));
1355 resource
->SetStringValues(slist
);
1357 return wxItemPropertyInfo::InstantiateResource(resource
);
1364 wxProperty
*wxRadioBoxPropertyInfo::GetProperty(wxString
& name
)
1366 wxRadioBox
*radioBox
= (wxRadioBox
*)m_propertyWindow
;
1367 if (name
== "numberRowsOrCols")
1369 return new wxProperty("numberRowsOrCols", (long)radioBox
->GetNumberOfRowsOrCols(), "integer");
1371 if (name
== "orientation")
1374 if (m_propertyWindow
->GetWindowStyleFlag() & wxRA_SPECIFY_COLS
)
1375 orient
= "wxRA_SPECIFY_COLS";
1377 orient
= "wxRA_SPECIFY_ROWS";
1379 return new wxProperty("orientation", orient
, "string",
1380 new wxStringListValidator(new wxStringList("wxRA_SPECIFY_COLS", "wxRA_SPECIFY_ROWS",
1383 else if (name
== "values")
1385 wxStringList
*stringList
= new wxStringList
;
1387 for (i
= 0; i
< radioBox
->Number(); i
++)
1388 stringList
->Add(radioBox
->GetString(i
));
1390 return new wxProperty(name
, stringList
, "stringlist");
1392 return wxItemPropertyInfo::GetProperty(name
);
1395 bool wxRadioBoxPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1397 wxRadioBox
*radioBox
= (wxRadioBox
*)m_propertyWindow
;
1398 if (name
== "numberRowsOrCols")
1400 radioBox
->SetNumberOfRowsOrCols((int)property
->GetValue().IntegerValue());
1401 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox
, this);
1404 else if (name
== "orientation")
1406 long windowStyle
= radioBox
->GetWindowStyleFlag();
1407 wxString
val(property
->GetValue().StringValue());
1408 if (val
== "wxRA_SPECIFY_COLS")
1410 if (windowStyle
& wxRA_SPECIFY_ROWS
)
1411 windowStyle
-= wxRA_SPECIFY_ROWS
;
1412 windowStyle
|= wxRA_SPECIFY_COLS
;
1416 if (windowStyle
& wxRA_SPECIFY_COLS
)
1417 windowStyle
-= wxRA_SPECIFY_COLS
;
1418 windowStyle
|= wxRA_SPECIFY_ROWS
;
1420 radioBox
->SetWindowStyleFlag(windowStyle
);
1421 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(radioBox
);
1422 resource
->SetStyle(windowStyle
);
1424 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox
, this);
1427 else if (name
== "values")
1429 // Set property into *resource*, not wxRadioBox, and then recreate
1430 // the wxRadioBox. This is because we can't dynamically set the strings
1432 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
1436 wxStringList stringList
;
1437 wxPropertyValue
*expr
= property
->GetValue().GetFirst();
1440 char *s
= expr
->StringValue();
1443 expr
= expr
->GetNext();
1445 resource
->SetStringValues(stringList
);
1446 wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(radioBox
, this);
1449 return wxItemPropertyInfo::SetProperty(name
, property
);
1452 void wxRadioBoxPropertyInfo::GetPropertyNames(wxStringList
& names
)
1454 wxItemPropertyInfo::GetPropertyNames(names
);
1456 names
.Add("values");
1457 names
.Add("orientation");
1458 names
.Add("numberRowsOrCols");
1461 bool wxRadioBoxPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1463 wxRadioBox
*rbox
= (wxRadioBox
*)m_propertyWindow
;
1464 // Take strings from resource instead
1467 if (rbox->Number() == 0)
1468 resource->SetStringValues(NULL);
1471 wxStringList *slist = new wxStringList;
1473 for (i = 0; i < rbox->Number(); i++)
1474 slist->Add(rbox->GetString(i));
1476 resource->SetStringValues(slist);
1479 resource
->SetValue1(rbox
->GetNumberOfRowsOrCols());
1480 return wxItemPropertyInfo::InstantiateResource(resource
);
1487 wxProperty
*wxGroupBoxPropertyInfo::GetProperty(wxString
& name
)
1489 return wxItemPropertyInfo::GetProperty(name
);
1492 bool wxGroupBoxPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1494 return wxItemPropertyInfo::SetProperty(name
, property
);
1497 void wxGroupBoxPropertyInfo::GetPropertyNames(wxStringList
& names
)
1499 wxItemPropertyInfo::GetPropertyNames(names
);
1503 bool wxGroupBoxPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1505 return wxItemPropertyInfo::InstantiateResource(resource
);
1512 wxProperty
*wxCheckBoxPropertyInfo::GetProperty(wxString
& name
)
1514 wxCheckBox
*checkBox
= (wxCheckBox
*)m_propertyWindow
;
1515 if (name
== "value")
1516 return new wxProperty("value", checkBox
->GetValue(), "bool");
1518 return wxItemPropertyInfo::GetProperty(name
);
1521 bool wxCheckBoxPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1523 wxCheckBox
*checkBox
= (wxCheckBox
*)m_propertyWindow
;
1524 if (name
== "value")
1526 checkBox
->SetValue((bool)property
->GetValue().BoolValue());
1530 return wxItemPropertyInfo::SetProperty(name
, property
);
1533 void wxCheckBoxPropertyInfo::GetPropertyNames(wxStringList
& names
)
1535 wxItemPropertyInfo::GetPropertyNames(names
);
1540 bool wxCheckBoxPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1542 wxCheckBox
*cbox
= (wxCheckBox
*)m_propertyWindow
;
1543 resource
->SetValue1(cbox
->GetValue());
1544 return wxItemPropertyInfo::InstantiateResource(resource
);
1551 wxProperty
*wxRadioButtonPropertyInfo::GetProperty(wxString
& name
)
1553 wxRadioButton
*checkBox
= (wxRadioButton
*)m_propertyWindow
;
1554 if (name
== "value")
1555 return new wxProperty("value", checkBox
->GetValue(), "bool");
1557 return wxItemPropertyInfo::GetProperty(name
);
1560 bool wxRadioButtonPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1562 wxRadioButton
*checkBox
= (wxRadioButton
*)m_propertyWindow
;
1563 if (name
== "value")
1565 checkBox
->SetValue((bool)property
->GetValue().BoolValue());
1569 return wxItemPropertyInfo::SetProperty(name
, property
);
1572 void wxRadioButtonPropertyInfo::GetPropertyNames(wxStringList
& names
)
1574 wxItemPropertyInfo::GetPropertyNames(names
);
1579 bool wxRadioButtonPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1581 wxRadioButton
*cbox
= (wxRadioButton
*)m_propertyWindow
;
1582 resource
->SetValue1(cbox
->GetValue());
1583 return wxItemPropertyInfo::InstantiateResource(resource
);
1590 wxProperty
*wxSliderPropertyInfo::GetProperty(wxString
& name
)
1592 wxSlider
*slider
= (wxSlider
*)m_propertyWindow
;
1593 if (name
== "value")
1594 return new wxProperty("value", (long)slider
->GetValue(), "integer");
1595 else if (name
== "orientation")
1598 if (m_propertyWindow
->GetWindowStyleFlag() & wxHORIZONTAL
)
1599 pos
= "wxHORIZONTAL";
1603 return new wxProperty("orientation", pos
, "string",
1604 new wxStringListValidator(new wxStringList("wxHORIZONTAL", "wxVERTICAL",
1607 else if (name
== "minValue")
1608 return new wxProperty("minValue", (long)slider
->GetMin(), "integer");
1609 else if (name
== "maxValue")
1610 return new wxProperty("maxValue", (long)slider
->GetMax(), "integer");
1612 return wxItemPropertyInfo::GetProperty(name
);
1615 bool wxSliderPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1617 wxSlider
*slider
= (wxSlider
*)m_propertyWindow
;
1618 if (name
== "value")
1620 slider
->SetValue((int)property
->GetValue().IntegerValue());
1623 else if (name
== "orientation")
1625 long windowStyle
= slider
->GetWindowStyleFlag();
1626 long oldWindowStyle
= windowStyle
;
1627 wxString
val(property
->GetValue().StringValue());
1628 if (val
== "wxHORIZONTAL")
1630 if (windowStyle
& wxVERTICAL
)
1631 windowStyle
-= wxVERTICAL
;
1632 windowStyle
|= wxHORIZONTAL
;
1636 if (windowStyle
& wxHORIZONTAL
)
1637 windowStyle
-= wxHORIZONTAL
;
1638 windowStyle
|= wxVERTICAL
;
1641 if (oldWindowStyle
== windowStyle
)
1644 slider
->SetWindowStyleFlag(windowStyle
);
1646 // If the window style has changed, we swap the width and height parameters.
1648 slider
->GetSize(&w
, &h
);
1650 slider
= (wxSlider
*)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(slider
, this);
1651 slider
->SetSize(-1, -1, h
, w
);
1655 else if (name
== "minValue")
1657 slider
->SetRange((int)property
->GetValue().IntegerValue(), slider
->GetMax());
1660 else if (name
== "maxValue")
1662 slider
->SetRange(slider
->GetMin(), (int)property
->GetValue().IntegerValue());
1666 return wxItemPropertyInfo::SetProperty(name
, property
);
1669 void wxSliderPropertyInfo::GetPropertyNames(wxStringList
& names
)
1671 wxItemPropertyInfo::GetPropertyNames(names
);
1673 names
.Add("orientation");
1674 names
.Add("minValue");
1675 names
.Add("maxValue");
1678 bool wxSliderPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1680 wxSlider
*slider
= (wxSlider
*)m_propertyWindow
;
1681 resource
->SetValue1(slider
->GetValue());
1682 resource
->SetValue2(slider
->GetMin());
1683 resource
->SetValue3(slider
->GetMax());
1684 return wxItemPropertyInfo::InstantiateResource(resource
);
1691 wxProperty
*wxGaugePropertyInfo::GetProperty(wxString
& name
)
1693 wxGauge
*gauge
= (wxGauge
*)m_propertyWindow
;
1694 if (name
== "value")
1695 return new wxProperty("value", (long)gauge
->GetValue(), "integer");
1696 else if (name
== "maxValue")
1697 return new wxProperty("maxValue", (long)gauge
->GetRange(), "integer");
1699 return wxItemPropertyInfo::GetProperty(name
);
1702 bool wxGaugePropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1704 wxGauge
*gauge
= (wxGauge
*)m_propertyWindow
;
1705 if (name
== "value")
1707 gauge
->SetValue((int)property
->GetValue().IntegerValue());
1710 else if (name
== "maxValue")
1712 gauge
->SetRange((int)property
->GetValue().IntegerValue());
1716 return wxItemPropertyInfo::SetProperty(name
, property
);
1719 void wxGaugePropertyInfo::GetPropertyNames(wxStringList
& names
)
1721 wxItemPropertyInfo::GetPropertyNames(names
);
1723 names
.Add("maxValue");
1726 bool wxGaugePropertyInfo::InstantiateResource(wxItemResource
*resource
)
1728 wxGauge
*gauge
= (wxGauge
*)m_propertyWindow
;
1729 resource
->SetValue1(gauge
->GetValue());
1730 resource
->SetValue2(gauge
->GetRange());
1731 return wxItemPropertyInfo::InstantiateResource(resource
);
1738 wxProperty
*wxScrollBarPropertyInfo::GetProperty(wxString
& name
)
1740 wxScrollBar
*scrollBar
= (wxScrollBar
*)m_propertyWindow
;
1741 if (name
== "value")
1742 return new wxProperty("value", (long)scrollBar
->GetValue(), "integer");
1743 else if (name
== "orientation")
1746 if (m_propertyWindow
->GetWindowStyleFlag() & wxHORIZONTAL
)
1747 pos
= "wxHORIZONTAL";
1751 return new wxProperty("orientation", pos
, "string",
1752 new wxStringListValidator(new wxStringList("wxHORIZONTAL", "wxVERTICAL",
1755 else if (name
== "pageSize")
1757 int viewStart
, pageLength
, objectLength
, viewLength
;
1758 scrollBar
->GetValues(&viewStart
, &viewLength
, &objectLength
, &pageLength
);
1760 return new wxProperty("pageSize", (long)pageLength
, "integer");
1762 else if (name
== "viewLength")
1764 int viewStart
, pageLength
, objectLength
, viewLength
;
1765 scrollBar
->GetValues(&viewStart
, &viewLength
, &objectLength
, &pageLength
);
1767 return new wxProperty("viewLength", (long)viewLength
, "integer");
1769 else if (name
== "objectLength")
1771 int viewStart
, pageLength
, objectLength
, viewLength
;
1772 scrollBar
->GetValues(&viewStart
, &viewLength
, &objectLength
, &pageLength
);
1774 return new wxProperty("objectLength", (long)objectLength
, "integer");
1777 return wxItemPropertyInfo::GetProperty(name
);
1780 bool wxScrollBarPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1782 wxScrollBar
*scrollBar
= (wxScrollBar
*)m_propertyWindow
;
1783 if (name
== "value")
1785 scrollBar
->SetValue((int)property
->GetValue().IntegerValue());
1788 else if (name
== "orientation")
1790 long windowStyle
= scrollBar
->GetWindowStyleFlag();
1791 long oldWindowStyle
= windowStyle
;
1792 wxString
val(property
->GetValue().StringValue());
1793 if (val
== "wxHORIZONTAL")
1795 if (windowStyle
& wxVERTICAL
)
1796 windowStyle
-= wxVERTICAL
;
1797 windowStyle
|= wxHORIZONTAL
;
1801 if (windowStyle
& wxHORIZONTAL
)
1802 windowStyle
-= wxHORIZONTAL
;
1803 windowStyle
|= wxVERTICAL
;
1806 if (oldWindowStyle
== windowStyle
)
1809 scrollBar
->SetWindowStyleFlag(windowStyle
);
1811 // If the window style has changed, we swap the width and height parameters.
1813 scrollBar
->GetSize(&w
, &h
);
1815 scrollBar
= (wxScrollBar
*)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(scrollBar
, this);
1816 scrollBar
->SetSize(-1, -1, h
, w
);
1820 else if (name
== "pageSize")
1822 scrollBar
->SetPageSize((int)property
->GetValue().IntegerValue());
1825 else if (name
== "viewLength")
1827 scrollBar
->SetViewLength((int)property
->GetValue().IntegerValue());
1830 else if (name
== "objectLength")
1832 scrollBar
->SetObjectLength((int)property
->GetValue().IntegerValue());
1836 return wxItemPropertyInfo::SetProperty(name
, property
);
1839 void wxScrollBarPropertyInfo::GetPropertyNames(wxStringList
& names
)
1841 wxItemPropertyInfo::GetPropertyNames(names
);
1842 names
.Add("orientation");
1844 names
.Add("pageSize");
1845 names
.Add("viewLength");
1846 names
.Add("objectLength");
1848 // Remove some properties we don't inherit
1849 names
.Delete("fontPoints");
1850 names
.Delete("fontFamily");
1851 names
.Delete("fontStyle");
1852 names
.Delete("fontWeight");
1853 names
.Delete("fontUnderlined");
1856 bool wxScrollBarPropertyInfo::InstantiateResource(wxItemResource
*resource
)
1858 wxScrollBar
*sbar
= (wxScrollBar
*)m_propertyWindow
;
1860 resource
->SetValue1(sbar
->GetValue());
1862 int viewStart
, pageLength
, objectLength
, viewLength
;
1863 sbar
->GetValues(&viewStart
, &viewLength
, &objectLength
, &pageLength
);
1865 resource
->SetValue2(pageLength
);
1866 resource
->SetValue3(objectLength
);
1867 resource
->SetValue5(viewLength
);
1869 return wxItemPropertyInfo::InstantiateResource(resource
);
1876 wxProperty
*wxPanelPropertyInfo::GetProperty(wxString
& name
)
1878 wxPanel
*panelWindow
= (wxPanel
*)m_propertyWindow
;
1881 wxFont *labelFont = panelWindow->GetLabelFont();
1882 wxFont *buttonFont = panelWindow->GetButtonFont();
1884 if (name == "labelFontPoints" || name == "labelFontFamily" || name == "labelFontStyle" || name == "labelFontWeight" ||
1885 name == "labelFontUnderlined")
1886 return GetFontProperty(name, labelFont);
1887 else if (name == "buttonFontPoints" || name == "buttonFontFamily" || name == "buttonFontStyle" || name == "buttonFontWeight" ||
1888 name == "buttonFontUnderlined")
1889 return GetFontProperty(name, buttonFont);
1895 if (panelWindow
->GetWindowStyleFlag() & wxNO_3D
)
1898 userColours
= FALSE
;
1900 return new wxProperty(name
, (bool)userColours
, "bool");
1902 else if (name
== "backgroundColour")
1904 wxColour
col(panelWindow
->GetBackgroundColour());
1906 wxDecToHex(col
.Red(), buf
);
1907 wxDecToHex(col
.Green(), buf
+2);
1908 wxDecToHex(col
.Blue(), buf
+4);
1910 return new wxProperty(name
, buf
, "string", new wxColourListValidator
);
1912 else if (name
== "title")
1914 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
1916 return new wxProperty(name
, resource
->GetTitle(), "string");
1918 return new wxProperty(name
, "Could not get title", "string");
1920 else if (name
== "caption")
1922 return new wxProperty(name
, ((panelWindow
->GetWindowStyleFlag() & wxCAPTION
) == wxCAPTION
),
1925 else if (name
== "systemMenu")
1927 return new wxProperty(name
, ((panelWindow
->GetWindowStyleFlag() & wxSYSTEM_MENU
) == wxSYSTEM_MENU
),
1930 else if (name
== "thickFrame")
1932 return new wxProperty(name
, ((panelWindow
->GetWindowStyleFlag() & wxTHICK_FRAME
) == wxTHICK_FRAME
),
1935 else if (name
== "useSystemDefaults")
1937 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
1938 return new wxProperty(name
, ((resource
->GetResourceStyle() & wxRESOURCE_USE_DEFAULTS
) == wxRESOURCE_USE_DEFAULTS
),
1941 else if (name
== "useDialogUnits")
1943 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
1944 return new wxProperty(name
, ((resource
->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS
) == wxRESOURCE_DIALOG_UNITS
),
1948 return wxWindowPropertyInfo::GetProperty(name
);
1951 bool wxPanelPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
1953 wxPanel
*panelWindow
= (wxPanel
*)m_propertyWindow
;
1955 wxFont *labelFont = panelWindow->GetLabelFont();
1956 wxFont *buttonFont = panelWindow->GetButtonFont();
1958 if (labelFont && (name == "labelFontPoints" || name == "labelFontFamily" || name == "labelFontStyle" || name == "labelFontWeight" || name == "labelFontUnderlined" ))
1960 wxFont *newFont = SetFontProperty(name, property, labelFont);
1962 panelWindow->SetLabelFont(* newFont);
1965 else if (buttonFont && (name == "buttonFontPoints" || name == "buttonFontFamily" || name == "buttonFontStyle" || name == "buttonFontWeight" || name == "buttonFontUnderlined" ))
1967 wxFont *newFont = SetFontProperty(name, property, buttonFont);
1969 panelWindow->SetButtonFont(* newFont);
1976 bool userColours
= property
->GetValue().BoolValue();
1980 if ((panelWindow
->GetWindowStyleFlag() & wxNO_3D
) != wxNO_3D
)
1981 panelWindow
->SetWindowStyleFlag(panelWindow
->GetWindowStyleFlag() | wxNO_3D
);
1985 if ((panelWindow
->GetWindowStyleFlag() & wxNO_3D
) == wxNO_3D
)
1986 panelWindow
->SetWindowStyleFlag(panelWindow
->GetWindowStyleFlag() - wxNO_3D
);
1988 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
1989 resource
->SetStyle(panelWindow
->GetWindowStyleFlag());
1991 panelWindow
= (wxPanel
*)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(panelWindow
, this);
1994 else if (name
== "backgroundColour")
1996 char *hex
= property
->GetValue().StringValue();
1997 int r
= wxHexToDec(hex
);
1998 int g
= wxHexToDec(hex
+2);
1999 int b
= wxHexToDec(hex
+4);
2001 wxColour
col(r
,g
,b
);
2002 panelWindow
->SetBackgroundColour(col
);
2003 panelWindow
= (wxPanel
*)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(panelWindow
, this);
2006 else if (name
== "title")
2008 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
2011 resource
->SetTitle(property
->GetValue().StringValue());
2017 else if (name
== "caption")
2019 SetWindowStyle(panelWindow
, wxCAPTION
, property
->GetValue().BoolValue());
2021 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
2022 resource
->SetStyle(panelWindow
->GetWindowStyleFlag());
2025 else if (name
== "thickFrame")
2027 SetWindowStyle(panelWindow
, wxTHICK_FRAME
, property
->GetValue().BoolValue());
2029 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
2030 resource
->SetStyle(panelWindow
->GetWindowStyleFlag());
2033 else if (name
== "systemMenu")
2035 SetWindowStyle(panelWindow
, wxSYSTEM_MENU
, property
->GetValue().BoolValue());
2037 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
2038 resource
->SetStyle(panelWindow
->GetWindowStyleFlag());
2041 else if (name
== "useSystemDefaults")
2043 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
2044 bool useDefaults
= property
->GetValue().BoolValue();
2045 long style
= resource
->GetResourceStyle();
2048 if ((style
& wxRESOURCE_USE_DEFAULTS
) == 0)
2049 style
|= wxRESOURCE_USE_DEFAULTS
;
2053 if ((style
& wxRESOURCE_USE_DEFAULTS
) != 0)
2054 style
-= wxRESOURCE_USE_DEFAULTS
;
2056 resource
->SetResourceStyle(style
);
2057 panelWindow
= (wxPanel
*)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(panelWindow
, this);
2060 else if (name
== "useDialogUnits")
2062 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(panelWindow
);
2063 bool useDialogUnits
= property
->GetValue().BoolValue();
2064 long style
= resource
->GetResourceStyle();
2067 if ((style
& wxRESOURCE_DIALOG_UNITS
) == 0)
2069 style
|= wxRESOURCE_DIALOG_UNITS
;
2070 ConvertDialogUnits(TRUE
); // Convert all resources
2075 if ((style
& wxRESOURCE_DIALOG_UNITS
) != 0)
2077 style
-= wxRESOURCE_DIALOG_UNITS
;
2078 ConvertDialogUnits(FALSE
); // Convert all resources
2081 resource
->SetResourceStyle(style
);
2082 panelWindow
= (wxPanel
*)wxResourceManager::GetCurrentResourceManager()->RecreateWindowFromResource(panelWindow
, this);
2083 // TODO: need to regenerate the width and height properties else they'll be inconsistent.
2087 return wxWindowPropertyInfo::SetProperty(name
, property
);
2090 void wxPanelPropertyInfo::GetPropertyNames(wxStringList
& names
)
2092 wxWindowPropertyInfo::GetPropertyNames(names
);
2096 names
.Add("backgroundColour");
2097 names
.Add("caption");
2098 names
.Add("systemMenu");
2099 names
.Add("thickFrame");
2100 names
.Add("useSystemDefaults");
2101 names
.Add("useDialogUnits");
2104 bool wxPanelPropertyInfo::InstantiateResource(wxItemResource
*resource
)
2106 wxPanel
*panel
= (wxPanel
*)m_propertyWindow
;
2107 if (panel
->GetFont().Ok())
2108 resource
->SetFont(* wxTheFontList
->FindOrCreateFont(panel
->GetFont().GetPointSize(),
2109 panel
->GetFont().GetFamily(), panel
->GetFont().GetStyle(), panel
->GetFont().GetWeight(),
2110 panel
->GetFont().GetUnderlined(), panel
->GetFont().GetFaceName()));
2112 resource
->SetBackgroundColour(wxColour(panel
->GetBackgroundColour()));
2114 return wxWindowPropertyInfo::InstantiateResource(resource
);
2117 // Convert this dialog, and its children, to or from dialog units
2118 void wxPanelPropertyInfo::ConvertDialogUnits(bool toDialogUnits
)
2120 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(m_propertyWindow
);
2126 sz
= m_propertyWindow
->ConvertPixelsToDialog(wxSize(resource
->GetWidth(), resource
->GetHeight()));
2127 pt
= m_propertyWindow
->ConvertPixelsToDialog(wxPoint(resource
->GetX(), resource
->GetY()));
2131 sz
= m_propertyWindow
->ConvertDialogToPixels(wxSize(resource
->GetWidth(), resource
->GetHeight()));
2132 pt
= m_propertyWindow
->ConvertDialogToPixels(wxPoint(resource
->GetX(), resource
->GetY()));
2134 resource
->SetSize(pt
.x
, pt
.y
, sz
.x
, sz
.y
);
2136 wxNode
* node
= m_propertyWindow
->GetChildren().First();
2139 wxWindow
* child
= (wxWindow
*) node
->Data();
2140 if (child
->IsKindOf(CLASSINFO(wxControl
)))
2142 resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(child
);
2145 sz
= m_propertyWindow
->ConvertPixelsToDialog(wxSize(resource
->GetWidth(), resource
->GetHeight()));
2146 pt
= m_propertyWindow
->ConvertPixelsToDialog(wxPoint(resource
->GetX(), resource
->GetY()));
2150 sz
= m_propertyWindow
->ConvertDialogToPixels(wxSize(resource
->GetWidth(), resource
->GetHeight()));
2151 pt
= m_propertyWindow
->ConvertDialogToPixels(wxPoint(resource
->GetX(), resource
->GetY()));
2153 resource
->SetSize(pt
.x
, pt
.y
, sz
.x
, sz
.y
);
2155 node
= node
->Next();
2164 wxProperty
*wxDialogPropertyInfo::GetProperty(wxString
& name
)
2166 wxDialog
*dialogWindow
= (wxDialog
*)m_propertyWindow
;
2167 if (name
== "modal")
2169 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(dialogWindow
);
2173 bool modal
= (resource
->GetValue1() != 0);
2174 return new wxProperty(name
, modal
, "bool");
2177 return wxPanelPropertyInfo::GetProperty(name
);
2180 bool wxDialogPropertyInfo::SetProperty(wxString
& name
, wxProperty
*property
)
2182 wxDialog
*dialogWindow
= (wxDialog
*)m_propertyWindow
;
2184 if (name
== "modal")
2186 wxItemResource
*resource
= wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(dialogWindow
);
2190 resource
->SetValue1(property
->GetValue().BoolValue());
2194 return wxPanelPropertyInfo::SetProperty(name
, property
);
2197 void wxDialogPropertyInfo::GetPropertyNames(wxStringList
& names
)
2199 wxPanelPropertyInfo::GetPropertyNames(names
);
2204 bool wxDialogPropertyInfo::InstantiateResource(wxItemResource
*resource
)
2206 wxDialog
*dialog
= (wxDialog
*)m_propertyWindow
;
2207 wxString
str(dialog
->GetTitle());
2208 resource
->SetTitle(str
);
2210 return wxPanelPropertyInfo::InstantiateResource(resource
);
2218 int wxStringToFontWeight(wxString
& val
)
2220 if (val
== "wxBOLD") return wxBOLD
;
2221 else if (val
== "wxLIGHT") return wxLIGHT
;
2222 else return wxNORMAL
;
2225 int wxStringToFontStyle(wxString
& val
)
2227 if (val
== "wxITALIC") return wxITALIC
;
2228 else if (val
== "wxSLANT") return wxSLANT
;
2229 else return wxNORMAL
;
2232 int wxStringToFontFamily(wxString
& val
)
2234 if (val
== "wxDECORATIVE") return wxDECORATIVE
;
2235 else if (val
== "wxROMAN") return wxROMAN
;
2236 else if (val
== "wxSCRIPT") return wxSCRIPT
;
2237 else if (val
== "wxMODERN") return wxMODERN
;
2238 else if (val
== "wxTELETYPE") return wxTELETYPE
;
2239 else return wxSWISS
;
2243 /// Resource symbol validator
2245 IMPLEMENT_DYNAMIC_CLASS(wxResourceSymbolValidator
, wxPropertyListValidator
)
2247 wxResourceSymbolValidator::wxResourceSymbolValidator(long flags
):
2248 wxPropertyListValidator(flags
)
2252 wxResourceSymbolValidator::~wxResourceSymbolValidator(void)
2256 bool wxResourceSymbolValidator::OnCheckValue(wxProperty
*WXUNUSED(property
), wxPropertyListView
*WXUNUSED(view
), wxWindow
*WXUNUSED(parentWindow
))
2261 // Called when TICK is pressed or focus is lost or view wants to update
2262 // the property list.
2263 // Does the transferance from the property editing area to the property itself
2264 bool wxResourceSymbolValidator::OnRetrieveValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
2266 if (!view
->GetValueText())
2268 wxString
value(view
->GetValueText()->GetValue());
2269 property
->GetValue() = value
;
2273 // Called when TICK is pressed or focus is lost or view wants to update
2274 // the property list.
2275 // Does the transferance from the property editing area to the property itself
2276 bool wxResourceSymbolValidator::OnDisplayValue(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
2278 if (!view
->GetValueText())
2280 wxString
str(property
->GetValue().GetStringRepresentation());
2281 view
->GetValueText()->SetValue(str
);
2285 // Called when the property is double clicked. Extra functionality can be provided,
2286 // cycling through possible values.
2287 bool wxResourceSymbolValidator::OnDoubleClick(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
2289 if (!view
->GetValueText())
2291 OnEdit(property
, view
, parentWindow
);
2295 bool wxResourceSymbolValidator::OnPrepareControls(wxProperty
*WXUNUSED(property
), wxPropertyListView
*view
, wxWindow
*WXUNUSED(parentWindow
))
2297 if (view
->GetConfirmButton())
2298 view
->GetConfirmButton()->Enable(TRUE
);
2299 if (view
->GetCancelButton())
2300 view
->GetCancelButton()->Enable(TRUE
);
2301 if (view
->GetEditButton())
2302 view
->GetEditButton()->Enable(TRUE
);
2303 if (view
->GetValueText())
2304 view
->GetValueText()->Enable((GetFlags() & wxPROP_ALLOW_TEXT_EDITING
) == wxPROP_ALLOW_TEXT_EDITING
);
2308 void wxResourceSymbolValidator::OnEdit(wxProperty
*property
, wxPropertyListView
*view
, wxWindow
*parentWindow
)
2310 if (!view
->GetValueText())
2313 wxResourceSymbolDialog
* dialog
= new wxResourceSymbolDialog(parentWindow
, -1, "Edit Symbol");
2315 // Split name/id pair e.g. "IDC_TEXT=123"
2316 wxString
value(property
->GetValue().StringValue());
2318 wxString strName
= value
.Before('=');
2319 wxString strId
= value
.After('=');
2321 dialog
->SetSymbol(strName
);
2322 dialog
->SetId(atoi(strId
));
2326 if (dialog
->ShowModal() == wxID_OK
)
2328 wxString
symbolName(dialog
->GetSymbol());
2329 long id
= dialog
->GetId();
2333 str
.Printf("%d", id
);
2334 property
->GetValue() = symbolName
+ wxString("=") + str
;
2336 view
->DisplayProperty(property
);
2337 view
->UpdatePropertyDisplayInList(property
);
2338 view
->OnPropertyChanged(property
);
2342 BEGIN_EVENT_TABLE(wxResourceSymbolDialog
, wxDialog
)
2343 EVT_BUTTON(wxID_OK
, wxResourceSymbolDialog::OnOK
)
2344 EVT_COMBOBOX(ID_SYMBOLNAME_COMBOBOX
, wxResourceSymbolDialog::OnComboBoxSelect
)
2345 EVT_TEXT(ID_SYMBOLNAME_COMBOBOX
, wxResourceSymbolDialog::OnSymbolNameUpdate
)
2348 wxResourceSymbolDialog::wxResourceSymbolDialog(wxWindow
* parent
, const wxWindowID id
, const wxString
& title
, const wxPoint
& pos
,
2349 const wxSize
& size
, long style
):
2350 wxDialog(parent
, id
, title
, pos
, size
, style
)
2355 (void) new wxStaticText(this, -1, "Name: ", wxPoint(x
, y
));
2359 m_nameCtrl
= new wxComboBox(this, ID_SYMBOLNAME_COMBOBOX
, "",
2360 wxPoint(x
, y
), wxSize(200, -1), 0, NULL
, wxCB_DROPDOWN
|wxCB_SORT
);
2365 (void) new wxStaticText(this, -1, "Id: ", wxPoint(x
, y
));
2369 m_idCtrl
= new wxTextCtrl(this, ID_SYMBOLID_TEXTCTRL
, "",
2370 wxPoint(x
, y
), wxSize(200, -1));
2374 (void) new wxButton(this, wxID_OK
, "OK", wxPoint(x
, y
), wxSize(80, -1));
2377 (void) new wxButton(this, wxID_CANCEL
, "Cancel", wxPoint(x
, y
), wxSize(80, -1));
2383 void wxResourceSymbolDialog::Init()
2386 defaultId
.Printf("%ld", m_symbolId
);
2388 m_nameCtrl
->SetValue(m_symbolName
);
2389 m_idCtrl
->SetValue(defaultId
);
2391 wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().FillComboBox(m_nameCtrl
);
2394 void wxResourceSymbolDialog::OnOK(wxCommandEvent
& event
)
2398 wxDialog::OnOK(event
);
2402 bool wxResourceSymbolDialog::CheckValues()
2404 wxString
nameStr(m_nameCtrl
->GetValue());
2405 wxString
idStr(m_idCtrl
->GetValue());
2406 int id
= atoi(idStr
);
2410 wxMessageBox("Identifier cannot be missing or zero", "Dialog Editor", wxOK
|wxICON_EXCLAMATION
, this);
2415 wxMessageBox("Please enter a symbol name", "Dialog Editor", wxOK
|wxICON_EXCLAMATION
, this);
2418 if (nameStr
.Contains(" "))
2420 wxMessageBox("Symbol name cannot contain spaces.", "Dialog Editor", wxOK
|wxICON_EXCLAMATION
, this);
2423 if (nameStr
.Contains("="))
2425 wxMessageBox("Symbol name cannot contain =.", "Dialog Editor", wxOK
|wxICON_EXCLAMATION
, this);
2428 if (nameStr
.IsNumber())
2430 wxMessageBox("Symbol name cannot be a number.", "Dialog Editor", wxOK
|wxICON_EXCLAMATION
, this);
2433 // TODO: other checks on the name syntax.
2435 if (!wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(nameStr
))
2437 // If we change the id for an existing symbol, we need to:
2438 // 1) Check if there are any other resources currently using the original id.
2439 // If so, will need to change their id to the new id, in SetProperty.
2440 // 2) Remove the old symbol, add the new symbol.
2441 // In this check, we don't have to do this, but we need to do it in SetProperty.
2443 if (nameStr
== GetSymbol() && id
!= GetId())
2445 // It's OK to change the id. But we'll need to change all matching ids in all resources,
2449 // If we change the name but not the id... we'll just need to remove and
2450 // re-add the symbol/id pair, in SetProperty.
2451 if (nameStr
!= GetSymbol() && id
== GetId())
2455 // What if we're changing both the name and the id?
2456 // - if there's no symbol of that name, just remove the old, add the new (in SetProperty)
2457 // - if there is a symbol of that name, if id matches, do nothing. If not, veto.
2459 if (nameStr
!= GetSymbol() && id
!= GetId())
2461 if (!wxResourceManager::GetCurrentResourceManager()->IsIdentifierOK(nameStr
, id
))
2463 wxMessageBox("This integer id is already being used under a different name.\nPlease choose another.",
2464 "Dialog Editor", wxOK
|wxICON_EXCLAMATION
, this);
2477 void wxResourceSymbolDialog::OnComboBoxSelect(wxCommandEvent
& WXUNUSED(event
))
2479 wxString
str(m_nameCtrl
->GetStringSelection());
2480 if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(str
))
2482 int id
= wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str
);
2484 str2
.Printf("%d", id
);
2485 m_idCtrl
->SetValue(str2
);
2486 m_idCtrl
->Enable(FALSE
);
2490 if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().SymbolExists(str
))
2492 int id
= wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str
);
2494 str2
.Printf("%d", id
);
2495 m_idCtrl
->SetValue(str2
);
2497 m_idCtrl
->Enable(TRUE
);
2501 void wxResourceSymbolDialog::OnSymbolNameUpdate(wxCommandEvent
& WXUNUSED(event
))
2503 wxString
str(m_nameCtrl
->GetValue());
2504 if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().IsStandardSymbol(str
))
2506 int id
= wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str
);
2508 str2
.Printf("%d", id
);
2509 m_idCtrl
->SetValue(str2
);
2510 m_idCtrl
->Enable(FALSE
);
2514 if (wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().SymbolExists(str
))
2516 int id
= wxResourceManager::GetCurrentResourceManager()->GetSymbolTable().GetIdForSymbol(str
);
2518 str2
.Printf("%d", id
);
2519 m_idCtrl
->SetValue(str2
);
2521 m_idCtrl
->Enable(TRUE
);