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