]>
git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_notbk.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/xrc/xh_notbk.cpp
3 // Purpose: XRC resource for wxNotebook
4 // Author: Vaclav Slavik
6 // Copyright: (c) 2000 Vaclav Slavik
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
17 #if wxUSE_XRC && wxUSE_NOTEBOOK
19 #include "wx/xrc/xh_notbk.h"
26 #include "wx/notebook.h"
27 #include "wx/imaglist.h"
29 IMPLEMENT_DYNAMIC_CLASS(wxNotebookXmlHandler
, wxXmlResourceHandler
)
31 wxNotebookXmlHandler::wxNotebookXmlHandler()
32 :wxXmlResourceHandler(),
36 XRC_ADD_STYLE(wxBK_DEFAULT
);
37 XRC_ADD_STYLE(wxBK_LEFT
);
38 XRC_ADD_STYLE(wxBK_RIGHT
);
39 XRC_ADD_STYLE(wxBK_TOP
);
40 XRC_ADD_STYLE(wxBK_BOTTOM
);
42 // provide the old synonyms for these fields as well
43 XRC_ADD_STYLE(wxNB_DEFAULT
);
44 XRC_ADD_STYLE(wxNB_LEFT
);
45 XRC_ADD_STYLE(wxNB_RIGHT
);
46 XRC_ADD_STYLE(wxNB_TOP
);
47 XRC_ADD_STYLE(wxNB_BOTTOM
);
49 XRC_ADD_STYLE(wxNB_FIXEDWIDTH
);
50 XRC_ADD_STYLE(wxNB_MULTILINE
);
51 XRC_ADD_STYLE(wxNB_NOPAGETHEME
);
56 wxObject
*wxNotebookXmlHandler::DoCreateResource()
58 if (m_class
== wxT("notebookpage"))
60 wxXmlNode
*n
= GetParamNode(wxT("object"));
63 n
= GetParamNode(wxT("object_ref"));
67 bool old_ins
= m_isInside
;
69 wxObject
*item
= CreateResFromNode(n
, m_notebook
, NULL
);
71 wxWindow
*wnd
= wxDynamicCast(item
, wxWindow
);
75 m_notebook
->AddPage(wnd
, GetText(wxT("label")),
76 GetBool(wxT("selected")));
77 if ( HasParam(wxT("bitmap")) )
79 wxBitmap bmp
= GetBitmap(wxT("bitmap"), wxART_OTHER
);
80 wxImageList
*imgList
= m_notebook
->GetImageList();
81 if ( imgList
== NULL
)
83 imgList
= new wxImageList( bmp
.GetWidth(), bmp
.GetHeight() );
84 m_notebook
->AssignImageList( imgList
);
86 int imgIndex
= imgList
->Add(bmp
);
87 m_notebook
->SetPageImage(m_notebook
->GetPageCount()-1, imgIndex
);
89 else if ( HasParam(wxT("image")) )
91 if ( m_notebook
->GetImageList() )
93 m_notebook
->SetPageImage(m_notebook
->GetPageCount()-1,
94 GetLong(wxT("image")) );
96 else // image without image list?
98 ReportError(n
, "image can only be used in conjunction "
105 ReportError(n
, "notebookpage child must be a window");
111 ReportError("notebookpage must have a window child");
118 XRC_MAKE_INSTANCE(nb
, wxNotebook
)
120 nb
->Create(m_parentAsWindow
,
122 GetPosition(), GetSize(),
123 GetStyle(wxT("style")),
126 wxImageList
*imagelist
= GetImageList();
128 nb
->AssignImageList(imagelist
);
132 wxNotebook
*old_par
= m_notebook
;
134 bool old_ins
= m_isInside
;
136 CreateChildren(m_notebook
, true/*only this handler*/);
137 m_isInside
= old_ins
;
138 m_notebook
= old_par
;
144 bool wxNotebookXmlHandler::CanHandle(wxXmlNode
*node
)
146 return ((!m_isInside
&& IsOfClass(node
, wxT("wxNotebook"))) ||
147 (m_isInside
&& IsOfClass(node
, wxT("notebookpage"))));
150 #endif // wxUSE_XRC && wxUSE_NOTEBOOK