]> git.saurik.com Git - wxWidgets.git/blame - src/xrc/xh_notbk.cpp
No changes, just factor our wxDirection parsing code in wxXRC.
[wxWidgets.git] / src / xrc / xh_notbk.cpp
CommitLineData
78d14f80 1/////////////////////////////////////////////////////////////////////////////
2ddb4d13 2// Name: src/xrc/xh_notbk.cpp
b5d6954b 3// Purpose: XRC resource for wxNotebook
78d14f80
VS
4// Author: Vaclav Slavik
5// Created: 2000/03/21
6// RCS-ID: $Id$
7// Copyright: (c) 2000 Vaclav Slavik
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
78d14f80
VS
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
621be1ec 18#if wxUSE_XRC && wxUSE_NOTEBOOK
78d14f80 19
a1e4ec87 20#include "wx/xrc/xh_notbk.h"
78d14f80 21
e4db172a
WS
22#ifndef WX_PRECOMP
23 #include "wx/log.h"
ed2fbeb8 24 #include "wx/sizer.h"
e4db172a
WS
25#endif
26
78d14f80 27#include "wx/notebook.h"
48414952 28#include "wx/imaglist.h"
78d14f80 29
854e189f
VS
30IMPLEMENT_DYNAMIC_CLASS(wxNotebookXmlHandler, wxXmlResourceHandler)
31
f80ea77b 32wxNotebookXmlHandler::wxNotebookXmlHandler()
ed2fbeb8
WS
33 :wxXmlResourceHandler(),
34 m_isInside(false),
35 m_notebook(NULL)
78d14f80 36{
2ddb4d13
WS
37 XRC_ADD_STYLE(wxBK_DEFAULT);
38 XRC_ADD_STYLE(wxBK_LEFT);
39 XRC_ADD_STYLE(wxBK_RIGHT);
40 XRC_ADD_STYLE(wxBK_TOP);
41 XRC_ADD_STYLE(wxBK_BOTTOM);
42
249259e7 43 // provide the old synonyms for these fields as well
5a439c1a 44 XRC_ADD_STYLE(wxNB_DEFAULT);
544fee32
VS
45 XRC_ADD_STYLE(wxNB_LEFT);
46 XRC_ADD_STYLE(wxNB_RIGHT);
2c12c792 47 XRC_ADD_STYLE(wxNB_TOP);
544fee32 48 XRC_ADD_STYLE(wxNB_BOTTOM);
5a439c1a
WS
49
50 XRC_ADD_STYLE(wxNB_FIXEDWIDTH);
51 XRC_ADD_STYLE(wxNB_MULTILINE);
52 XRC_ADD_STYLE(wxNB_NOPAGETHEME);
53
78d14f80
VS
54 AddWindowStyles();
55}
56
78d14f80 57wxObject *wxNotebookXmlHandler::DoCreateResource()
f80ea77b 58{
78d14f80
VS
59 if (m_class == wxT("notebookpage"))
60 {
61 wxXmlNode *n = GetParamNode(wxT("object"));
62
544fee32
VS
63 if ( !n )
64 n = GetParamNode(wxT("object_ref"));
f2588180 65
78d14f80
VS
66 if (n)
67 {
68 bool old_ins = m_isInside;
f80ea77b 69 m_isInside = false;
78d14f80 70 wxObject *item = CreateResFromNode(n, m_notebook, NULL);
71ff7c91 71 m_isInside = old_ins;
78d14f80
VS
72 wxWindow *wnd = wxDynamicCast(item, wxWindow);
73
74 if (wnd)
48414952 75 {
78d14f80 76 m_notebook->AddPage(wnd, GetText(wxT("label")),
9fbad34d 77 GetBool(wxT("selected")));
48414952
JS
78 if ( HasParam(wxT("bitmap")) )
79 {
80 wxBitmap bmp = GetBitmap(wxT("bitmap"), wxART_OTHER);
81 wxImageList *imgList = m_notebook->GetImageList();
82 if ( imgList == NULL )
83 {
84 imgList = new wxImageList( bmp.GetWidth(), bmp.GetHeight() );
85 m_notebook->AssignImageList( imgList );
86 }
87 int imgIndex = imgList->Add(bmp);
88 m_notebook->SetPageImage(m_notebook->GetPageCount()-1, imgIndex );
89 }
326462ae
VZ
90 else if ( HasParam(wxT("image")) )
91 {
92 if ( m_notebook->GetImageList() )
93 {
94 m_notebook->SetPageImage(m_notebook->GetPageCount()-1,
95 GetLong(wxT("image")) );
96 }
97 else // image without image list?
98 {
99 ReportError(n, "image can only be used in conjunction "
100 "with imagelist");
101 }
102 }
48414952 103 }
f80ea77b 104 else
819559b2
VS
105 {
106 ReportError(n, "notebookpage child must be a window");
107 }
78d14f80
VS
108 return wnd;
109 }
110 else
111 {
819559b2 112 ReportError("notebookpage must have a window child");
78d14f80
VS
113 return NULL;
114 }
115 }
f80ea77b
WS
116
117 else
544fee32
VS
118 {
119 XRC_MAKE_INSTANCE(nb, wxNotebook)
f2588180 120
f80ea77b 121 nb->Create(m_parentAsWindow,
544fee32
VS
122 GetID(),
123 GetPosition(), GetSize(),
124 GetStyle(wxT("style")),
125 GetName());
f2588180 126
326462ae
VZ
127 wxImageList *imagelist = GetImageList();
128 if ( imagelist )
129 nb->AssignImageList(imagelist);
130
311b2ea7
VS
131 SetupWindow(nb);
132
78d14f80
VS
133 wxNotebook *old_par = m_notebook;
134 m_notebook = nb;
135 bool old_ins = m_isInside;
f80ea77b
WS
136 m_isInside = true;
137 CreateChildren(m_notebook, true/*only this handler*/);
78d14f80
VS
138 m_isInside = old_ins;
139 m_notebook = old_par;
140
adbf2d73 141 return nb;
78d14f80
VS
142 }
143}
144
78d14f80
VS
145bool wxNotebookXmlHandler::CanHandle(wxXmlNode *node)
146{
147 return ((!m_isInside && IsOfClass(node, wxT("wxNotebook"))) ||
148 (m_isInside && IsOfClass(node, wxT("notebookpage"))));
149}
150
621be1ec 151#endif // wxUSE_XRC && wxUSE_NOTEBOOK