]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_notbk.cpp
Fixed bug: wxPropertyGridInterface::SetPropertyReadOnly() with wxPG_DONT_RECURSE...
[wxWidgets.git] / src / xrc / xh_notbk.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/xrc/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 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #if wxUSE_XRC && wxUSE_NOTEBOOK
19
20 #include "wx/xrc/xh_notbk.h"
21
22 #ifndef WX_PRECOMP
23 #include "wx/log.h"
24 #include "wx/sizer.h"
25 #endif
26
27 #include "wx/notebook.h"
28 #include "wx/imaglist.h"
29
30 IMPLEMENT_DYNAMIC_CLASS(wxNotebookXmlHandler, wxXmlResourceHandler)
31
32 wxNotebookXmlHandler::wxNotebookXmlHandler()
33 :wxXmlResourceHandler(),
34 m_isInside(false),
35 m_notebook(NULL)
36 {
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
43 // provide the old synonyms for these fields as well
44 XRC_ADD_STYLE(wxNB_DEFAULT);
45 XRC_ADD_STYLE(wxNB_LEFT);
46 XRC_ADD_STYLE(wxNB_RIGHT);
47 XRC_ADD_STYLE(wxNB_TOP);
48 XRC_ADD_STYLE(wxNB_BOTTOM);
49
50 XRC_ADD_STYLE(wxNB_FIXEDWIDTH);
51 XRC_ADD_STYLE(wxNB_MULTILINE);
52 XRC_ADD_STYLE(wxNB_NOPAGETHEME);
53
54 AddWindowStyles();
55 }
56
57 wxObject *wxNotebookXmlHandler::DoCreateResource()
58 {
59 if (m_class == wxT("notebookpage"))
60 {
61 wxXmlNode *n = GetParamNode(wxT("object"));
62
63 if ( !n )
64 n = GetParamNode(wxT("object_ref"));
65
66 if (n)
67 {
68 bool old_ins = m_isInside;
69 m_isInside = false;
70 wxObject *item = CreateResFromNode(n, m_notebook, NULL);
71 m_isInside = old_ins;
72 wxWindow *wnd = wxDynamicCast(item, wxWindow);
73
74 if (wnd)
75 {
76 m_notebook->AddPage(wnd, GetText(wxT("label")),
77 GetBool(wxT("selected")));
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 }
90 }
91 else
92 {
93 ReportError(n, "notebookpage child must be a window");
94 }
95 return wnd;
96 }
97 else
98 {
99 ReportError("notebookpage must have a window child");
100 return NULL;
101 }
102 }
103
104 else
105 {
106 XRC_MAKE_INSTANCE(nb, wxNotebook)
107
108 nb->Create(m_parentAsWindow,
109 GetID(),
110 GetPosition(), GetSize(),
111 GetStyle(wxT("style")),
112 GetName());
113
114 SetupWindow(nb);
115
116 wxNotebook *old_par = m_notebook;
117 m_notebook = nb;
118 bool old_ins = m_isInside;
119 m_isInside = true;
120 CreateChildren(m_notebook, true/*only this handler*/);
121 m_isInside = old_ins;
122 m_notebook = old_par;
123
124 return nb;
125 }
126 }
127
128 bool wxNotebookXmlHandler::CanHandle(wxXmlNode *node)
129 {
130 return ((!m_isInside && IsOfClass(node, wxT("wxNotebook"))) ||
131 (m_isInside && IsOfClass(node, wxT("notebookpage"))));
132 }
133
134 #endif // wxUSE_XRC && wxUSE_NOTEBOOK