]> git.saurik.com Git - wxWidgets.git/blob - contrib/src/xml/xh_notbk.cpp
notebooksizer is now property of notebook, not special kind of sizer
[wxWidgets.git] / contrib / src / xml / xh_notbk.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: xh_notbk.cpp
3 // Purpose: XML 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/xml/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 wxNotebookXmlHandler::wxNotebookXmlHandler()
31 : wxXmlResourceHandler(), m_IsInside(FALSE), m_Notebook(NULL)
32 {
33 ADD_STYLE(wxNB_FIXEDWIDTH);
34 ADD_STYLE(wxNB_LEFT);
35 ADD_STYLE(wxNB_RIGHT);
36 ADD_STYLE(wxNB_BOTTOM);
37 }
38
39
40
41 wxObject *wxNotebookXmlHandler::DoCreateResource()
42 {
43 if (m_Node->GetName() == _T("notebookpage"))
44 {
45 wxXmlNode *n = GetParamNode(_T("window"))->GetChildren();
46 while (n)
47 {
48 if (n->GetType() == wxXML_ELEMENT_NODE)
49 {
50 bool old_ins = m_IsInside;
51 m_IsInside = FALSE;
52 m_IsInside = old_ins;
53 wxObject *item = CreateResFromNode(n, m_Notebook, NULL);
54 wxWindow *wnd = wxDynamicCast(item, wxWindow);
55
56 if (wnd)
57 m_Notebook->AddPage(wnd, GetText(_T("label")),
58 GetBool(_T("selected"), 0));
59 else
60 wxLogError(_T("Error in resource."));
61 return wnd;
62 }
63 n = n->GetNext();
64 }
65 wxLogError(_T("Error in resource: no control within notebook's <page> tag."));
66 return NULL;
67 }
68
69 else {
70 wxNotebook *nb = new wxNotebook(m_ParentAsWindow,
71 GetID(),
72 GetPosition(), GetSize(),
73 GetStyle( _T("style" )),
74 GetName());
75
76 wxNotebook *old_par = m_Notebook;
77 m_Notebook = nb;
78 bool old_ins = m_IsInside;
79 m_IsInside = TRUE;
80 CreateChildren(m_Notebook, TRUE/*only this handler*/);
81 m_IsInside = old_ins;
82 m_Notebook = old_par;
83
84 if (GetBool(_T("usenotebooksizer"), FALSE))
85 return new wxNotebookSizer(nb);
86 else
87 return nb;
88 }
89 }
90
91
92
93 bool wxNotebookXmlHandler::CanHandle(wxXmlNode *node)
94 {
95 return ((!m_IsInside && node->GetName() == _T("notebook")) ||
96 (m_IsInside && node->GetName() == _T("notebookpage")));
97 }
98
99 #endif