]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_notbk.cpp
re-renamed DoCreate() to XmDoCreateTLW() to avoid virtual function hiding in other...
[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 // 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 #include "wx/log.h"
23 #include "wx/notebook.h"
24 #include "wx/imaglist.h"
25 #include "wx/sizer.h"
26
27 IMPLEMENT_DYNAMIC_CLASS(wxNotebookXmlHandler, wxXmlResourceHandler)
28
29 wxNotebookXmlHandler::wxNotebookXmlHandler()
30 : wxXmlResourceHandler(), m_isInside(false), m_notebook(NULL)
31 {
32 XRC_ADD_STYLE(wxNB_DEFAULT);
33 XRC_ADD_STYLE(wxNB_LEFT);
34 XRC_ADD_STYLE(wxNB_RIGHT);
35 XRC_ADD_STYLE(wxNB_TOP);
36 XRC_ADD_STYLE(wxNB_BOTTOM);
37
38 XRC_ADD_STYLE(wxNB_FIXEDWIDTH);
39 XRC_ADD_STYLE(wxNB_MULTILINE);
40 XRC_ADD_STYLE(wxNB_NOPAGETHEME);
41
42 AddWindowStyles();
43 }
44
45 wxObject *wxNotebookXmlHandler::DoCreateResource()
46 {
47 if (m_class == wxT("notebookpage"))
48 {
49 wxXmlNode *n = GetParamNode(wxT("object"));
50
51 if ( !n )
52 n = GetParamNode(wxT("object_ref"));
53
54 if (n)
55 {
56 bool old_ins = m_isInside;
57 m_isInside = false;
58 wxObject *item = CreateResFromNode(n, m_notebook, NULL);
59 m_isInside = old_ins;
60 wxWindow *wnd = wxDynamicCast(item, wxWindow);
61
62 if (wnd)
63 {
64 m_notebook->AddPage(wnd, GetText(wxT("label")),
65 GetBool(wxT("selected")));
66 if ( HasParam(wxT("bitmap")) )
67 {
68 wxBitmap bmp = GetBitmap(wxT("bitmap"), wxART_OTHER);
69 wxImageList *imgList = m_notebook->GetImageList();
70 if ( imgList == NULL )
71 {
72 imgList = new wxImageList( bmp.GetWidth(), bmp.GetHeight() );
73 m_notebook->AssignImageList( imgList );
74 }
75 int imgIndex = imgList->Add(bmp);
76 m_notebook->SetPageImage(m_notebook->GetPageCount()-1, imgIndex );
77 }
78 }
79 else
80 wxLogError(wxT("Error in resource."));
81 return wnd;
82 }
83 else
84 {
85 wxLogError(wxT("Error in resource: no control within notebook's <page> tag."));
86 return NULL;
87 }
88 }
89
90 else
91 {
92 XRC_MAKE_INSTANCE(nb, wxNotebook)
93
94 nb->Create(m_parentAsWindow,
95 GetID(),
96 GetPosition(), GetSize(),
97 GetStyle(wxT("style")),
98 GetName());
99
100 SetupWindow(nb);
101
102 wxNotebook *old_par = m_notebook;
103 m_notebook = nb;
104 bool old_ins = m_isInside;
105 m_isInside = true;
106 CreateChildren(m_notebook, true/*only this handler*/);
107 m_isInside = old_ins;
108 m_notebook = old_par;
109
110 return nb;
111 }
112 }
113
114 bool wxNotebookXmlHandler::CanHandle(wxXmlNode *node)
115 {
116 return ((!m_isInside && IsOfClass(node, wxT("wxNotebook"))) ||
117 (m_isInside && IsOfClass(node, wxT("notebookpage"))));
118 }
119
120 #endif // wxUSE_XRC && wxUSE_NOTEBOOK