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