1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/xrc/xh_unkwn.cpp
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"
24 #include "wx/window.h"
30 class wxUnknownControlContainer
: public wxPanel
33 wxUnknownControlContainer(wxWindow
*parent
,
34 const wxString
& controlName
,
35 wxWindowID id
= wxID_ANY
,
36 const wxPoint
& pos
= wxDefaultPosition
,
37 const wxSize
& size
= wxDefaultSize
,
39 // Always add the wxTAB_TRAVERSAL and wxNO_BORDER styles to what comes
40 // from the XRC if anything.
41 : wxPanel(parent
, id
, pos
, size
, style
| wxTAB_TRAVERSAL
| wxNO_BORDER
,
42 controlName
+ wxT("_container")),
43 m_controlName(controlName
), m_controlAdded(false)
45 m_bg
= GetBackgroundColour();
46 SetBackgroundColour(wxColour(255, 0, 255));
49 virtual void AddChild(wxWindowBase
*child
);
50 virtual void RemoveChild(wxWindowBase
*child
);
53 wxString m_controlName
;
58 void wxUnknownControlContainer::AddChild(wxWindowBase
*child
)
60 wxASSERT_MSG( !m_controlAdded
, wxT("Couldn't add two unknown controls to the same container!") );
62 wxPanel::AddChild(child
);
64 SetBackgroundColour(m_bg
);
65 child
->SetName(m_controlName
);
66 child
->SetId(wxXmlResource::GetXRCID(m_controlName
));
67 m_controlAdded
= true;
69 wxSizer
*sizer
= new wxBoxSizer(wxHORIZONTAL
);
70 sizer
->Add((wxWindow
*)child
, 1, wxEXPAND
);
71 SetSizerAndFit(sizer
);
74 void wxUnknownControlContainer::RemoveChild(wxWindowBase
*child
)
76 wxPanel::RemoveChild(child
);
77 m_controlAdded
= false;
78 GetSizer()->Detach((wxWindow
*)child
);
82 IMPLEMENT_DYNAMIC_CLASS(wxUnknownWidgetXmlHandler
, wxXmlResourceHandler
)
84 wxUnknownWidgetXmlHandler::wxUnknownWidgetXmlHandler()
85 : wxXmlResourceHandler()
87 XRC_ADD_STYLE(wxNO_FULL_REPAINT_ON_RESIZE
);
90 wxObject
*wxUnknownWidgetXmlHandler::DoCreateResource()
92 wxASSERT_MSG( m_instance
== NULL
,
93 wxT("'unknown' controls can't be subclassed, use wxXmlResource::AttachUnknownControl") );
96 new wxUnknownControlContainer(m_parentAsWindow
,
98 GetPosition(), GetSize(),
99 GetStyle(wxT("style")));
104 bool wxUnknownWidgetXmlHandler::CanHandle(wxXmlNode
*node
)
106 return IsOfClass(node
, wxT("unknown"));