]>
Commit | Line | Data |
---|---|---|
78d14f80 VS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: 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 VS |
21 | |
22 | #include "wx/log.h" | |
23 | #include "wx/notebook.h" | |
48414952 | 24 | #include "wx/imaglist.h" |
78d14f80 VS |
25 | #include "wx/sizer.h" |
26 | ||
854e189f VS |
27 | IMPLEMENT_DYNAMIC_CLASS(wxNotebookXmlHandler, wxXmlResourceHandler) |
28 | ||
f80ea77b WS |
29 | wxNotebookXmlHandler::wxNotebookXmlHandler() |
30 | : wxXmlResourceHandler(), m_isInside(false), m_notebook(NULL) | |
78d14f80 | 31 | { |
5a439c1a | 32 | XRC_ADD_STYLE(wxNB_DEFAULT); |
544fee32 VS |
33 | XRC_ADD_STYLE(wxNB_LEFT); |
34 | XRC_ADD_STYLE(wxNB_RIGHT); | |
2c12c792 | 35 | XRC_ADD_STYLE(wxNB_TOP); |
544fee32 | 36 | XRC_ADD_STYLE(wxNB_BOTTOM); |
5a439c1a WS |
37 | |
38 | XRC_ADD_STYLE(wxNB_FIXEDWIDTH); | |
39 | XRC_ADD_STYLE(wxNB_MULTILINE); | |
40 | XRC_ADD_STYLE(wxNB_NOPAGETHEME); | |
41 | ||
78d14f80 VS |
42 | AddWindowStyles(); |
43 | } | |
44 | ||
78d14f80 | 45 | wxObject *wxNotebookXmlHandler::DoCreateResource() |
f80ea77b | 46 | { |
78d14f80 VS |
47 | if (m_class == wxT("notebookpage")) |
48 | { | |
49 | wxXmlNode *n = GetParamNode(wxT("object")); | |
50 | ||
544fee32 VS |
51 | if ( !n ) |
52 | n = GetParamNode(wxT("object_ref")); | |
f2588180 | 53 | |
78d14f80 VS |
54 | if (n) |
55 | { | |
56 | bool old_ins = m_isInside; | |
f80ea77b | 57 | m_isInside = false; |
78d14f80 | 58 | wxObject *item = CreateResFromNode(n, m_notebook, NULL); |
71ff7c91 | 59 | m_isInside = old_ins; |
78d14f80 VS |
60 | wxWindow *wnd = wxDynamicCast(item, wxWindow); |
61 | ||
62 | if (wnd) | |
48414952 | 63 | { |
78d14f80 | 64 | m_notebook->AddPage(wnd, GetText(wxT("label")), |
9fbad34d | 65 | GetBool(wxT("selected"))); |
48414952 JS |
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 | } | |
f80ea77b WS |
79 | else |
80 | wxLogError(wxT("Error in resource.")); | |
78d14f80 VS |
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 | } | |
f80ea77b WS |
89 | |
90 | else | |
544fee32 VS |
91 | { |
92 | XRC_MAKE_INSTANCE(nb, wxNotebook) | |
f2588180 | 93 | |
f80ea77b | 94 | nb->Create(m_parentAsWindow, |
544fee32 VS |
95 | GetID(), |
96 | GetPosition(), GetSize(), | |
97 | GetStyle(wxT("style")), | |
98 | GetName()); | |
f2588180 | 99 | |
311b2ea7 VS |
100 | SetupWindow(nb); |
101 | ||
78d14f80 VS |
102 | wxNotebook *old_par = m_notebook; |
103 | m_notebook = nb; | |
104 | bool old_ins = m_isInside; | |
f80ea77b WS |
105 | m_isInside = true; |
106 | CreateChildren(m_notebook, true/*only this handler*/); | |
78d14f80 VS |
107 | m_isInside = old_ins; |
108 | m_notebook = old_par; | |
109 | ||
adbf2d73 | 110 | return nb; |
78d14f80 VS |
111 | } |
112 | } | |
113 | ||
78d14f80 VS |
114 | bool wxNotebookXmlHandler::CanHandle(wxXmlNode *node) |
115 | { | |
116 | return ((!m_isInside && IsOfClass(node, wxT("wxNotebook"))) || | |
117 | (m_isInside && IsOfClass(node, wxT("notebookpage")))); | |
118 | } | |
119 | ||
621be1ec | 120 | #endif // wxUSE_XRC && wxUSE_NOTEBOOK |