1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: XRC resource for unknown widget
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2000 Vaclav Slavik
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
20 #include "wx/xrc/xh_unkwn.h"
21 #include "wx/window.h"
27 class wxUnknownControlContainer
: public wxPanel
30 wxUnknownControlContainer(wxWindow
*parent
,
31 const wxString
& controlName
,
32 wxWindowID id
= wxID_ANY
,
33 const wxPoint
& pos
= wxDefaultPosition
,
34 const wxSize
& size
= wxDefaultSize
,
36 // Always add the wxTAB_TRAVERSAL and wxNO_BORDER styles to what comes
37 // from the XRC if anything.
38 : wxPanel(parent
, id
, pos
, size
, style
| wxTAB_TRAVERSAL
| wxNO_BORDER
,
39 controlName
+ wxT("_container")),
40 m_controlName(controlName
), m_controlAdded(false)
42 m_bg
= GetBackgroundColour();
43 SetBackgroundColour(wxColour(255, 0, 255));
46 virtual void AddChild(wxWindowBase
*child
);
47 virtual void RemoveChild(wxWindowBase
*child
);
50 wxString m_controlName
;
55 void wxUnknownControlContainer::AddChild(wxWindowBase
*child
)
57 wxASSERT_MSG( !m_controlAdded
, wxT("Couldn't add two unknown controls to the same container!") );
59 wxPanel::AddChild(child
);
61 SetBackgroundColour(m_bg
);
62 child
->SetName(m_controlName
);
63 child
->SetId(wxXmlResource::GetXRCID(m_controlName
));
64 m_controlAdded
= true;
66 wxSizer
*sizer
= new wxBoxSizer(wxHORIZONTAL
);
67 sizer
->Add((wxWindow
*)child
, 1, wxEXPAND
);
72 void wxUnknownControlContainer::RemoveChild(wxWindowBase
*child
)
74 wxPanel::RemoveChild(child
);
75 m_controlAdded
= false;
76 GetSizer()->Detach((wxWindow
*)child
);
80 IMPLEMENT_DYNAMIC_CLASS(wxUnknownWidgetXmlHandler
, wxXmlResourceHandler
)
82 wxUnknownWidgetXmlHandler::wxUnknownWidgetXmlHandler()
83 : wxXmlResourceHandler()
85 XRC_ADD_STYLE(wxNO_FULL_REPAINT_ON_RESIZE
);
88 wxObject
*wxUnknownWidgetXmlHandler::DoCreateResource()
90 wxASSERT_MSG( m_instance
== NULL
,
91 _T("'unknown' controls can't be subclassed, use wxXmlResource::AttachUnknownControl") );
94 new wxUnknownControlContainer(m_parentAsWindow
,
96 GetPosition(), GetSize(),
97 GetStyle(wxT("style")));
102 bool wxUnknownWidgetXmlHandler::CanHandle(wxXmlNode
*node
)
104 return IsOfClass(node
, wxT("unknown"));