]> git.saurik.com Git - wxWidgets.git/blame - src/xrc/xh_toolbk.cpp
adding isFlipped to userpane
[wxWidgets.git] / src / xrc / xh_toolbk.cpp
CommitLineData
4689441b
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/xrc/xh_toolbk.cpp
3// Purpose: XRC resource for wxToolbook
4// Author: Andrea Zanellato
5// Created: 2009/12/12
6// Copyright: (c) 2010 wxWidgets development team
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 && wxUSE_TOOLBOOK
18
19#include "wx/xrc/xh_toolbk.h"
20
21#ifndef WX_PRECOMP
22 #include "wx/log.h"
23 #include "wx/sizer.h"
24#endif
25
26#include "wx/toolbook.h"
27#include "wx/imaglist.h"
28
df27f1dc
VZ
29#include "wx/xml/xml.h"
30
4689441b
VZ
31IMPLEMENT_DYNAMIC_CLASS(wxToolbookXmlHandler, wxXmlResourceHandler)
32
33wxToolbookXmlHandler::wxToolbookXmlHandler()
34 :wxXmlResourceHandler(),
35 m_isInside(false),
36 m_toolbook(NULL)
37{
38 XRC_ADD_STYLE(wxBK_DEFAULT);
39 XRC_ADD_STYLE(wxBK_TOP);
40 XRC_ADD_STYLE(wxBK_BOTTOM);
41 XRC_ADD_STYLE(wxBK_LEFT);
42 XRC_ADD_STYLE(wxBK_RIGHT);
43
44 XRC_ADD_STYLE(wxTBK_BUTTONBAR);
45 XRC_ADD_STYLE(wxTBK_HORZ_LAYOUT);
46
47 AddWindowStyles();
48}
49
50wxObject *wxToolbookXmlHandler::DoCreateResource()
51{
52 if (m_class == wxT("toolbookpage"))
53 {
54 wxXmlNode *n = GetParamNode(wxT("object"));
55
56 if ( !n )
57 n = GetParamNode(wxT("object_ref"));
58
59 if (n)
60 {
61 bool old_ins = m_isInside;
62 m_isInside = false;
63 wxObject *item = CreateResFromNode(n, m_toolbook, NULL);
64 m_isInside = old_ins;
65 wxWindow *wnd = wxDynamicCast(item, wxWindow);
66
67 if (wnd)
68 {
69 int imgId = -1;
70
71 if ( HasParam(wxT("bitmap")) )
72 {
73 wxBitmap bmp = GetBitmap(wxT("bitmap"), wxART_OTHER);
74 wxImageList *imgList = m_toolbook->GetImageList();
75 if ( imgList == NULL )
76 {
77 imgList = new wxImageList( bmp.GetWidth(), bmp.GetHeight() );
78 m_toolbook->AssignImageList( imgList );
79 }
80 imgId = imgList->Add(bmp);
81 }
82 else if ( HasParam(wxT("image")) )
83 {
84 if ( m_toolbook->GetImageList() )
85 {
86 imgId = (int)GetLong(wxT("image"));
87 }
88 else // image without image list?
89 {
90 ReportError(n, "image can only be used in conjunction "
91 "with imagelist");
92 }
93 }
94
95 m_toolbook->AddPage(wnd, GetText(wxT("label")),
96 GetBool(wxT("selected")), imgId );
97 }
98 else
99 {
100 ReportError(n, "toolbookpage child must be a window");
101 }
102 return wnd;
103 }
104 else
105 {
106 ReportError("toolbookpage must have a window child");
107 return NULL;
108 }
109 }
110
111 else
112 {
113 XRC_MAKE_INSTANCE(nb, wxToolbook)
114
115 nb->Create( m_parentAsWindow,
116 GetID(),
117 GetPosition(), GetSize(),
118 GetStyle(wxT("style")),
119 GetName() );
120
121 wxImageList *imagelist = GetImageList();
122 if ( imagelist )
123 nb->AssignImageList(imagelist);
124
125 wxToolbook *old_par = m_toolbook;
126 m_toolbook = nb;
127 bool old_ins = m_isInside;
128 m_isInside = true;
129 CreateChildren(m_toolbook, true/*only this handler*/);
130 m_isInside = old_ins;
131 m_toolbook = old_par;
132
133 return nb;
134 }
135}
136
137bool wxToolbookXmlHandler::CanHandle(wxXmlNode *node)
138{
139 return ((!m_isInside && IsOfClass(node, wxT("wxToolbook"))) ||
140 (m_isInside && IsOfClass(node, wxT("toolbookpage"))));
141}
142
143#endif // wxUSE_XRC && wxUSE_TOOLBOOK