]> git.saurik.com Git - wxWidgets.git/blame - src/xrc/xh_unkwn.cpp
Reflect changes in stc.cpp in stc.cpp.in from which it's generated.
[wxWidgets.git] / src / xrc / xh_unkwn.cpp
CommitLineData
78d14f80 1/////////////////////////////////////////////////////////////////////////////
e4db172a 2// Name: src/xrc/xh_unkwn.cpp
b5d6954b 3// Purpose: XRC resource for unknown widget
78d14f80
VS
4// Author: Vaclav Slavik
5// Created: 2000/09/09
78d14f80
VS
6// Copyright: (c) 2000 Vaclav Slavik
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
cefd71d7 9
78d14f80
VS
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
13#ifdef __BORLANDC__
14 #pragma hdrstop
15#endif
16
621be1ec 17#if wxUSE_XRC
a1e4ec87 18
78d14f80 19#include "wx/xrc/xh_unkwn.h"
e4db172a
WS
20
21#ifndef WX_PRECOMP
22 #include "wx/log.h"
cdccdfab 23 #include "wx/window.h"
8e609c82 24 #include "wx/panel.h"
ed2fbeb8 25 #include "wx/sizer.h"
e4db172a
WS
26#endif
27
78d14f80
VS
28
29class wxUnknownControlContainer : public wxPanel
30{
31public:
32 wxUnknownControlContainer(wxWindow *parent,
33 const wxString& controlName,
f80ea77b 34 wxWindowID id = wxID_ANY,
78d14f80 35 const wxPoint& pos = wxDefaultPosition,
afe06a54 36 const wxSize& size = wxDefaultSize,
d1cc09bb
RD
37 long style = 0)
38 // Always add the wxTAB_TRAVERSAL and wxNO_BORDER styles to what comes
39 // from the XRC if anything.
40 : wxPanel(parent, id, pos, size, style | wxTAB_TRAVERSAL | wxNO_BORDER,
78d14f80 41 controlName + wxT("_container")),
5c451707 42 m_controlName(controlName), m_controlAdded(false)
78d14f80
VS
43 {
44 m_bg = GetBackgroundColour();
45 SetBackgroundColour(wxColour(255, 0, 255));
46 }
47
48 virtual void AddChild(wxWindowBase *child);
5c451707 49 virtual void RemoveChild(wxWindowBase *child);
cefd71d7 50
78d14f80
VS
51protected:
52 wxString m_controlName;
53 bool m_controlAdded;
54 wxColour m_bg;
55};
56
57void wxUnknownControlContainer::AddChild(wxWindowBase *child)
58{
63fd5f0b 59 wxASSERT_MSG( !m_controlAdded, wxT("Couldn't add two unknown controls to the same container!") );
78d14f80
VS
60
61 wxPanel::AddChild(child);
cefd71d7 62
78d14f80
VS
63 SetBackgroundColour(m_bg);
64 child->SetName(m_controlName);
5ed345b7 65 child->SetId(wxXmlResource::GetXRCID(m_controlName));
5c451707 66 m_controlAdded = true;
cefd71d7 67
78d14f80
VS
68 wxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
69 sizer->Add((wxWindow*)child, 1, wxEXPAND);
bc3863bd 70 SetSizerAndFit(sizer);
78d14f80
VS
71}
72
5c451707
VS
73void wxUnknownControlContainer::RemoveChild(wxWindowBase *child)
74{
75 wxPanel::RemoveChild(child);
76 m_controlAdded = false;
77 GetSizer()->Detach((wxWindow*)child);
78}
78d14f80
VS
79
80
854e189f
VS
81IMPLEMENT_DYNAMIC_CLASS(wxUnknownWidgetXmlHandler, wxXmlResourceHandler)
82
cefd71d7
RD
83wxUnknownWidgetXmlHandler::wxUnknownWidgetXmlHandler()
84: wxXmlResourceHandler()
78d14f80 85{
afe06a54 86 XRC_ADD_STYLE(wxNO_FULL_REPAINT_ON_RESIZE);
78d14f80
VS
87}
88
89wxObject *wxUnknownWidgetXmlHandler::DoCreateResource()
cefd71d7 90{
9f01cb29 91 wxASSERT_MSG( m_instance == NULL,
9a83f860 92 wxT("'unknown' controls can't be subclassed, use wxXmlResource::AttachUnknownControl") );
9f01cb29 93
cefd71d7 94 wxPanel *panel =
78d14f80 95 new wxUnknownControlContainer(m_parentAsWindow,
f80ea77b 96 GetName(), wxID_ANY,
afe06a54 97 GetPosition(), GetSize(),
d1cc09bb 98 GetStyle(wxT("style")));
78d14f80
VS
99 SetupWindow(panel);
100 return panel;
101}
102
103bool wxUnknownWidgetXmlHandler::CanHandle(wxXmlNode *node)
104{
105 return IsOfClass(node, wxT("unknown"));
106}
107
a1e4ec87 108#endif // wxUSE_XRC