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