1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: XRC resource for unknown widget
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2000 Vaclav Slavik
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "xh_unkwn.h"
15 // For compilers that support precompilation, includes "wx.h".
16 #include "wx/wxprec.h"
24 #include "wx/xrc/xh_unkwn.h"
25 #include "wx/window.h"
31 class wxUnknownControlContainer
: public wxPanel
34 wxUnknownControlContainer(wxWindow
*parent
,
35 const wxString
& controlName
,
36 wxWindowID id
= wxID_ANY
,
37 const wxPoint
& pos
= wxDefaultPosition
,
38 const wxSize
& size
= wxDefaultSize
,
40 // Always add the wxTAB_TRAVERSAL and wxNO_BORDER styles to what comes
41 // from the XRC if anything.
42 : wxPanel(parent
, id
, pos
, size
, style
| wxTAB_TRAVERSAL
| wxNO_BORDER
,
43 controlName
+ wxT("_container")),
44 m_controlName(controlName
), m_controlAdded(false)
46 m_bg
= GetBackgroundColour();
47 SetBackgroundColour(wxColour(255, 0, 255));
50 virtual void AddChild(wxWindowBase
*child
);
51 virtual void RemoveChild(wxWindowBase
*child
);
54 wxString m_controlName
;
59 void wxUnknownControlContainer::AddChild(wxWindowBase
*child
)
61 wxASSERT_MSG( !m_controlAdded
, wxT("Couldn't add two unknown controls to the same container!") );
63 wxPanel::AddChild(child
);
65 SetBackgroundColour(m_bg
);
66 child
->SetName(m_controlName
);
67 child
->SetId(wxXmlResource::GetXRCID(m_controlName
));
68 m_controlAdded
= true;
70 wxSizer
*sizer
= new wxBoxSizer(wxHORIZONTAL
);
71 sizer
->Add((wxWindow
*)child
, 1, wxEXPAND
);
76 void wxUnknownControlContainer::RemoveChild(wxWindowBase
*child
)
78 wxPanel::RemoveChild(child
);
79 m_controlAdded
= false;
80 GetSizer()->Detach((wxWindow
*)child
);
84 IMPLEMENT_DYNAMIC_CLASS(wxUnknownWidgetXmlHandler
, wxXmlResourceHandler
)
86 wxUnknownWidgetXmlHandler::wxUnknownWidgetXmlHandler()
87 : wxXmlResourceHandler()
89 XRC_ADD_STYLE(wxNO_FULL_REPAINT_ON_RESIZE
);
92 wxObject
*wxUnknownWidgetXmlHandler::DoCreateResource()
94 wxASSERT_MSG( m_instance
== NULL
,
95 _T("'unknown' controls can't be subclassed, use wxXmlResource::AttachUnknownControl") );
98 new wxUnknownControlContainer(m_parentAsWindow
,
100 GetPosition(), GetSize(),
101 GetStyle(wxT("style")));
106 bool wxUnknownWidgetXmlHandler::CanHandle(wxXmlNode
*node
)
108 return IsOfClass(node
, wxT("unknown"));