]> git.saurik.com Git - wxWidgets.git/blob - contrib/src/xrc/xh_notbk.cpp
Check for empty "widths"
[wxWidgets.git] / contrib / 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 #include "wx/xrc/xh_notbk.h"
23
24 #if wxUSE_NOTEBOOK
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_BOTTOM);
39 AddWindowStyles();
40 }
41
42 wxObject *wxNotebookXmlHandler::DoCreateResource()
43 {
44 if (m_class == wxT("notebookpage"))
45 {
46 wxXmlNode *n = GetParamNode(wxT("object"));
47
48 if ( !n )
49 n = GetParamNode(wxT("object_ref"));
50
51 if (n)
52 {
53 bool old_ins = m_isInside;
54 m_isInside = FALSE;
55 wxObject *item = CreateResFromNode(n, m_notebook, NULL);
56 m_isInside = old_ins;
57 wxWindow *wnd = wxDynamicCast(item, wxWindow);
58
59 if (wnd)
60 m_notebook->AddPage(wnd, GetText(wxT("label")),
61 GetBool(wxT("selected"), 0));
62 else
63 wxLogError(wxT("Error in resource."));
64 return wnd;
65 }
66 else
67 {
68 wxLogError(wxT("Error in resource: no control within notebook's <page> tag."));
69 return NULL;
70 }
71 }
72
73 else
74 {
75 XRC_MAKE_INSTANCE(nb, wxNotebook)
76
77 nb->Create(m_parentAsWindow,
78 GetID(),
79 GetPosition(), GetSize(),
80 GetStyle(wxT("style")),
81 GetName());
82
83 wxNotebook *old_par = m_notebook;
84 m_notebook = nb;
85 bool old_ins = m_isInside;
86 m_isInside = TRUE;
87 CreateChildren(m_notebook, TRUE/*only this handler*/);
88 m_isInside = old_ins;
89 m_notebook = old_par;
90
91 if (GetBool(wxT("usenotebooksizer"), FALSE))
92 return new wxNotebookSizer(nb);
93 else
94 return nb;
95 }
96 }
97
98 bool wxNotebookXmlHandler::CanHandle(wxXmlNode *node)
99 {
100 return ((!m_isInside && IsOfClass(node, wxT("wxNotebook"))) ||
101 (m_isInside && IsOfClass(node, wxT("notebookpage"))));
102 }
103
104 #endif