]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_notbk.cpp
non-PCH build fix (according to Tinderbox).
[wxWidgets.git] / src / xrc / xh_notbk.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/xrc/xh_notbk.cpp
3 // Purpose: XRC resource for wxNotebook
4 // Author: Vaclav Slavik
5 // Created: 2000/03/21
6 // RCS-ID: $Id$
7 // Copyright: (c) 2000 Vaclav Slavik
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_NOTEBOOK
19
20 #include "wx/xrc/xh_notbk.h"
21
22 #ifndef WX_PRECOMP
23 #include "wx/log.h"
24 #include "wx/sizer.h"
25 #endif
26
27 #include "wx/notebook.h"
28 #include "wx/imaglist.h"
29
30 IMPLEMENT_DYNAMIC_CLASS(wxNotebookXmlHandler, wxXmlResourceHandler)
31
32 wxNotebookXmlHandler::wxNotebookXmlHandler()
33 :wxXmlResourceHandler(),
34 m_isInside(false),
35 m_notebook(NULL)
36 {
37 XRC_ADD_STYLE(wxBK_DEFAULT);
38 XRC_ADD_STYLE(wxBK_LEFT);
39 XRC_ADD_STYLE(wxBK_RIGHT);
40 XRC_ADD_STYLE(wxBK_TOP);
41 XRC_ADD_STYLE(wxBK_BOTTOM);
42
43 #if WXWIN_COMPATIBILITY_2_6
44 XRC_ADD_STYLE(wxNB_DEFAULT);
45 XRC_ADD_STYLE(wxNB_LEFT);
46 XRC_ADD_STYLE(wxNB_RIGHT);
47 XRC_ADD_STYLE(wxNB_TOP);
48 XRC_ADD_STYLE(wxNB_BOTTOM);
49 #endif
50
51 XRC_ADD_STYLE(wxNB_FIXEDWIDTH);
52 XRC_ADD_STYLE(wxNB_MULTILINE);
53 XRC_ADD_STYLE(wxNB_NOPAGETHEME);
54
55 AddWindowStyles();
56 }
57
58 wxObject *wxNotebookXmlHandler::DoCreateResource()
59 {
60 if (m_class == wxT("notebookpage"))
61 {
62 wxXmlNode *n = GetParamNode(wxT("object"));
63
64 if ( !n )
65 n = GetParamNode(wxT("object_ref"));
66
67 if (n)
68 {
69 bool old_ins = m_isInside;
70 m_isInside = false;
71 wxObject *item = CreateResFromNode(n, m_notebook, NULL);
72 m_isInside = old_ins;
73 wxWindow *wnd = wxDynamicCast(item, wxWindow);
74
75 if (wnd)
76 {
77 m_notebook->AddPage(wnd, GetText(wxT("label")),
78 GetBool(wxT("selected")));
79 if ( HasParam(wxT("bitmap")) )
80 {
81 wxBitmap bmp = GetBitmap(wxT("bitmap"), wxART_OTHER);
82 wxImageList *imgList = m_notebook->GetImageList();
83 if ( imgList == NULL )
84 {
85 imgList = new wxImageList( bmp.GetWidth(), bmp.GetHeight() );
86 m_notebook->AssignImageList( imgList );
87 }
88 int imgIndex = imgList->Add(bmp);
89 m_notebook->SetPageImage(m_notebook->GetPageCount()-1, imgIndex );
90 }
91 }
92 else
93 wxLogError(wxT("Error in resource."));
94 return wnd;
95 }
96 else
97 {
98 wxLogError(wxT("Error in resource: no control within notebook's <page> tag."));
99 return NULL;
100 }
101 }
102
103 else
104 {
105 XRC_MAKE_INSTANCE(nb, wxNotebook)
106
107 nb->Create(m_parentAsWindow,
108 GetID(),
109 GetPosition(), GetSize(),
110 GetStyle(wxT("style")),
111 GetName());
112
113 SetupWindow(nb);
114
115 wxNotebook *old_par = m_notebook;
116 m_notebook = nb;
117 bool old_ins = m_isInside;
118 m_isInside = true;
119 CreateChildren(m_notebook, true/*only this handler*/);
120 m_isInside = old_ins;
121 m_notebook = old_par;
122
123 return nb;
124 }
125 }
126
127 bool wxNotebookXmlHandler::CanHandle(wxXmlNode *node)
128 {
129 return ((!m_isInside && IsOfClass(node, wxT("wxNotebook"))) ||
130 (m_isInside && IsOfClass(node, wxT("notebookpage"))));
131 }
132
133 #endif // wxUSE_XRC && wxUSE_NOTEBOOK