Add missing styles support to wxWindow XRC handler.
[wxWidgets.git] / src / xrc / xh_collpane.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/xrc/xh_collpane.cpp
3 // Purpose: XML resource handler for wxCollapsiblePane
4 // Author: Francesco Montorsi
5 // Created: 2006-10-27
6 // RCS-ID: $Id$
7 // Copyright: (c) 2006 Francesco Montorsi
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #if wxUSE_XRC && wxUSE_COLLPANE
19
20 #ifndef WX_PRECOMP
21 #include "wx/log.h"
22 #endif
23
24 #include "wx/collpane.h"
25 #include "wx/xrc/xh_collpane.h"
26
27 IMPLEMENT_DYNAMIC_CLASS(wxCollapsiblePaneXmlHandler, wxXmlResourceHandler)
28
29 wxCollapsiblePaneXmlHandler::wxCollapsiblePaneXmlHandler()
30 : wxXmlResourceHandler(), m_isInside(false)
31 {
32 XRC_ADD_STYLE(wxCP_NO_TLW_RESIZE);
33 XRC_ADD_STYLE(wxCP_DEFAULT_STYLE);
34 AddWindowStyles();
35 }
36
37 wxObject *wxCollapsiblePaneXmlHandler::DoCreateResource()
38 {
39 if (m_class == wxT("panewindow")) // read the XRC for the pane window
40 {
41 wxXmlNode *n = GetParamNode(wxT("object"));
42
43 if ( !n )
44 n = GetParamNode(wxT("object_ref"));
45
46 if (n)
47 {
48 bool old_ins = m_isInside;
49 m_isInside = false;
50 wxObject *item = CreateResFromNode(n, m_collpane->GetPane(), NULL);
51 m_isInside = old_ins;
52
53 return item;
54 }
55 else
56 {
57 ReportError("no control within panewindow");
58 return NULL;
59 }
60 }
61 else
62 {
63 XRC_MAKE_INSTANCE(ctrl, wxCollapsiblePane)
64
65 wxString label = GetParamValue(wxT("label"));
66 if (label.empty())
67 {
68 ReportParamError("label", "label cannot be empty");
69 return NULL;
70 }
71
72 ctrl->Create(m_parentAsWindow,
73 GetID(),
74 label,
75 GetPosition(), GetSize(),
76 GetStyle(wxT("style"), wxCP_DEFAULT_STYLE),
77 wxDefaultValidator,
78 GetName());
79
80 ctrl->Collapse(GetBool(wxT("collapsed")));
81 SetupWindow(ctrl);
82
83 wxCollapsiblePane *old_par = m_collpane;
84 m_collpane = ctrl;
85 bool old_ins = m_isInside;
86 m_isInside = true;
87 CreateChildren(m_collpane, true/*only this handler*/);
88 m_isInside = old_ins;
89 m_collpane = old_par;
90
91 return ctrl;
92 }
93 }
94
95 bool wxCollapsiblePaneXmlHandler::CanHandle(wxXmlNode *node)
96 {
97 return IsOfClass(node, wxT("wxCollapsiblePane")) ||
98 (m_isInside && IsOfClass(node, wxT("panewindow")));
99 }
100
101 #endif // wxUSE_XRC && wxUSE_COLLPANE