added wxSplitterWindow to XRC
[wxWidgets.git] / src / xrc / xh_split.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: xh_split.cpp
3 // Purpose: XRC resource for wxSplitterWindow
4 // Author: panga@freemail.hu, Vaclav Slavik
5 // Created: 2003/01/26
6 // RCS-ID: $Id$
7 // Copyright: (c) 2003 panga@freemail.hu, Vaclav Slavik
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifdef __GNUG__
12 #pragma implementation "xh_split.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
22 #include "wx/xrc/xh_split.h"
23 #include "wx/splitter.h"
24 #include "wx/log.h"
25
26 wxSplitterWindowXmlHandler::wxSplitterWindowXmlHandler() : wxXmlResourceHandler()
27 {
28 XRC_ADD_STYLE(wxSP_3D);
29 XRC_ADD_STYLE(wxSP_3DSASH);
30 XRC_ADD_STYLE(wxSP_3DBORDER);
31 XRC_ADD_STYLE(wxSP_FULLSASH);
32 XRC_ADD_STYLE(wxSP_BORDER);
33 XRC_ADD_STYLE(wxSP_NOBORDER);
34 XRC_ADD_STYLE(wxSP_PERMIT_UNSPLIT);
35 XRC_ADD_STYLE(wxSP_LIVE_UPDATE);
36 AddWindowStyles();
37 }
38
39 wxObject *wxSplitterWindowXmlHandler::DoCreateResource()
40 {
41 XRC_MAKE_INSTANCE(splitter, wxSplitterWindow);
42
43 splitter->Create(m_parentAsWindow,
44 GetID(),
45 GetPosition(), GetSize(),
46 GetStyle(wxT("style"), wxSP_3D),
47 GetName());
48
49 SetupWindow(splitter);
50
51 long sashpos = GetLong(wxT("sashpos"), 0);
52 long minpanesize = GetLong(wxT("minsize"), -1);
53 if (minpanesize != -1)
54 splitter->SetMinimumPaneSize(minpanesize);
55
56 wxWindow *win1 = NULL, *win2 = NULL;
57 wxXmlNode *n = m_node->GetChildren();
58 while (n)
59 {
60 if ((n->GetType() == wxXML_ELEMENT_NODE) &&
61 (n->GetName() == wxT("object") ||
62 n->GetName() == wxT("object_ref")))
63 {
64 wxObject *created = CreateResFromNode(n, splitter, NULL);
65 wxWindow *win = wxDynamicCast(created, wxWindow);
66 if (win1 == NULL)
67 {
68 win1 = win;
69 }
70 else
71 {
72 win2 = win;
73 break;
74 }
75 }
76 n = n->GetNext();
77 }
78
79 if (win1 == NULL)
80 wxLogError(wxT("wxSplitterWindow node must contain at least one window."));
81
82 bool horizontal = (GetParamValue(wxT("orientation")) != wxT("vertical"));
83 if (win1 && win2)
84 {
85 if (horizontal)
86 splitter->SplitHorizontally(win1, win2, sashpos);
87 else
88 splitter->SplitVertically(win1, win2, sashpos);
89 }
90 else
91 {
92 splitter->Initialize(win1);
93 }
94
95 return splitter;
96 }
97
98 bool wxSplitterWindowXmlHandler::CanHandle(wxXmlNode *node)
99 {
100 return IsOfClass(node, wxT("wxSplitterWindow"));
101 }
102
103