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