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