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