]> git.saurik.com Git - wxWidgets.git/blob - contrib/src/xrc/xh_notbk.cpp
implemented Alex's <object_ref> symlinks in XRC
[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 wxNotebookXmlHandler::wxNotebookXmlHandler()
31 : wxXmlResourceHandler(), m_isInside(FALSE), m_notebook(NULL)
32 {
33 XRC_ADD_STYLE(wxNB_FIXEDWIDTH);
34 XRC_ADD_STYLE(wxNB_LEFT);
35 XRC_ADD_STYLE(wxNB_RIGHT);
36 XRC_ADD_STYLE(wxNB_BOTTOM);
37 AddWindowStyles();
38 }
39
40 wxObject *wxNotebookXmlHandler::DoCreateResource()
41 {
42 if (m_class == wxT("notebookpage"))
43 {
44 wxXmlNode *n = GetParamNode(wxT("object"));
45
46 if ( !n )
47 n = GetParamNode(wxT("object_ref"));
48
49 if (n)
50 {
51 bool old_ins = m_isInside;
52 m_isInside = FALSE;
53 m_isInside = old_ins;
54 wxObject *item = CreateResFromNode(n, m_notebook, NULL);
55 wxWindow *wnd = wxDynamicCast(item, wxWindow);
56
57 if (wnd)
58 m_notebook->AddPage(wnd, GetText(wxT("label")),
59 GetBool(wxT("selected"), 0));
60 else
61 wxLogError(wxT("Error in resource."));
62 return wnd;
63 }
64 else
65 {
66 wxLogError(wxT("Error in resource: no control within notebook's <page> tag."));
67 return NULL;
68 }
69 }
70
71 else
72 {
73 XRC_MAKE_INSTANCE(nb, wxNotebook)
74
75 nb->Create(m_parentAsWindow,
76 GetID(),
77 GetPosition(), GetSize(),
78 GetStyle(wxT("style")),
79 GetName());
80
81 wxNotebook *old_par = m_notebook;
82 m_notebook = nb;
83 bool old_ins = m_isInside;
84 m_isInside = TRUE;
85 CreateChildren(m_notebook, TRUE/*only this handler*/);
86 m_isInside = old_ins;
87 m_notebook = old_par;
88
89 if (GetBool(wxT("usenotebooksizer"), FALSE))
90 return new wxNotebookSizer(nb);
91 else
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