a better compilation fix
[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() : wxXmlResourceHandler()
30 {
31 XRC_ADD_STYLE(wxCP_NO_TLW_RESIZE);
32 XRC_ADD_STYLE(wxCP_DEFAULT_STYLE);
33 AddWindowStyles();
34 }
35
36 wxObject *wxCollapsiblePaneXmlHandler::DoCreateResource()
37 {
38 if (m_class == wxT("panewindow")) // read the XRC for the pane window
39 {
40 wxXmlNode *n = GetParamNode(wxT("object"));
41
42 if ( !n )
43 n = GetParamNode(wxT("object_ref"));
44
45 if (n)
46 {
47 bool old_ins = m_isInside;
48 m_isInside = false;
49 wxObject *item = CreateResFromNode(n, m_collpane->GetPane(), NULL);
50 m_isInside = old_ins;
51
52 return item;
53 }
54 else
55 {
56 wxLogError(wxT("Error in resource: no control within collapsible pane's <panewindow> tag."));
57 return NULL;
58 }
59 }
60 else
61 {
62 XRC_MAKE_INSTANCE(ctrl, wxCollapsiblePane)
63
64 wxString label = GetParamValue(wxT("label"));
65 if (label.empty())
66 {
67 wxLogError(wxT("Error in resource: empty label for wxCollapsiblePane"));
68 return NULL;
69 }
70
71 ctrl->Create(m_parentAsWindow,
72 GetID(),
73 label,
74 GetPosition(), GetSize(),
75 GetStyle(_T("style"), wxCP_DEFAULT_STYLE),
76 wxDefaultValidator,
77 GetName());
78
79 ctrl->Collapse(GetBool(_T("collapsed")));
80 SetupWindow(ctrl);
81
82 wxCollapsiblePane *old_par = m_collpane;
83 m_collpane = ctrl;
84 bool old_ins = m_isInside;
85 m_isInside = true;
86 CreateChildren(m_collpane, true/*only this handler*/);
87 m_isInside = old_ins;
88 m_collpane = old_par;
89
90 return ctrl;
91 }
92 }
93
94 bool wxCollapsiblePaneXmlHandler::CanHandle(wxXmlNode *node)
95 {
96 return IsOfClass(node, wxT("wxCollapsiblePane")) ||
97 (m_isInside && IsOfClass(node, wxT("panewindow")));
98 }
99
100 #endif // wxUSE_XRC && wxUSE_COLLPANE