don't add empty image to tabs
[wxWidgets.git] / src / xrc / xh_notbk.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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 #ifdef __GNUG__
12 #pragma implementation "xh_notbk.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 #if wxUSE_XRC && wxUSE_NOTEBOOK
23
24 #include "wx/xrc/xh_notbk.h"
25
26 #include "wx/log.h"
27 #include "wx/notebook.h"
28 #include "wx/sizer.h"
29
30 IMPLEMENT_DYNAMIC_CLASS(wxNotebookXmlHandler, wxXmlResourceHandler)
31
32 wxNotebookXmlHandler::wxNotebookXmlHandler()
33 : wxXmlResourceHandler(), m_isInside(false), m_notebook(NULL)
34 {
35 XRC_ADD_STYLE(wxNB_FIXEDWIDTH);
36 XRC_ADD_STYLE(wxNB_LEFT);
37 XRC_ADD_STYLE(wxNB_RIGHT);
38 XRC_ADD_STYLE(wxNB_TOP);
39 XRC_ADD_STYLE(wxNB_BOTTOM);
40 AddWindowStyles();
41 }
42
43 wxObject *wxNotebookXmlHandler::DoCreateResource()
44 {
45 if (m_class == wxT("notebookpage"))
46 {
47 wxXmlNode *n = GetParamNode(wxT("object"));
48
49 if ( !n )
50 n = GetParamNode(wxT("object_ref"));
51
52 if (n)
53 {
54 bool old_ins = m_isInside;
55 m_isInside = false;
56 wxObject *item = CreateResFromNode(n, m_notebook, NULL);
57 m_isInside = old_ins;
58 wxWindow *wnd = wxDynamicCast(item, wxWindow);
59
60 if (wnd)
61 m_notebook->AddPage(wnd, GetText(wxT("label")),
62 GetBool(wxT("selected")));
63 else
64 wxLogError(wxT("Error in resource."));
65 return wnd;
66 }
67 else
68 {
69 wxLogError(wxT("Error in resource: no control within notebook's <page> tag."));
70 return NULL;
71 }
72 }
73
74 else
75 {
76 XRC_MAKE_INSTANCE(nb, wxNotebook)
77
78 nb->Create(m_parentAsWindow,
79 GetID(),
80 GetPosition(), GetSize(),
81 GetStyle(wxT("style")),
82 GetName());
83
84 wxNotebook *old_par = m_notebook;
85 m_notebook = nb;
86 bool old_ins = m_isInside;
87 m_isInside = true;
88 CreateChildren(m_notebook, true/*only this handler*/);
89 m_isInside = old_ins;
90 m_notebook = old_par;
91
92 return nb;
93 }
94 }
95
96 bool wxNotebookXmlHandler::CanHandle(wxXmlNode *node)
97 {
98 return ((!m_isInside && IsOfClass(node, wxT("wxNotebook"))) ||
99 (m_isInside && IsOfClass(node, wxT("notebookpage"))));
100 }
101
102 #endif // wxUSE_XRC && wxUSE_NOTEBOOK