]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/xrc/xh_listbk.cpp
Unified flags for orienting wxBookCtrls (with backward compatibility). Centralised...
[wxWidgets.git] / src / xrc / xh_listbk.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: xh_listbk.cpp
3// Purpose: XRC resource for wxListbook
4// Author: Vaclav Slavik
5// Created: 2000/03/21
6// Copyright: (c) 2000 Vaclav Slavik
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
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
17#if wxUSE_XRC && wxUSE_LISTBOOK
18
19#include "wx/xrc/xh_listbk.h"
20
21#include "wx/log.h"
22#include "wx/listbook.h"
23#include "wx/imaglist.h"
24#include "wx/sizer.h"
25
26IMPLEMENT_DYNAMIC_CLASS(wxListbookXmlHandler, wxXmlResourceHandler)
27
28wxListbookXmlHandler::wxListbookXmlHandler()
29: wxXmlResourceHandler(), m_isInside(false), m_listbook(NULL)
30{
31 XRC_ADD_STYLE(wxLB_DEFAULT);
32 XRC_ADD_STYLE(wxLB_LEFT);
33 XRC_ADD_STYLE(wxLB_RIGHT);
34 XRC_ADD_STYLE(wxLB_TOP);
35 XRC_ADD_STYLE(wxLB_BOTTOM);
36
37 AddWindowStyles();
38}
39
40wxObject *wxListbookXmlHandler::DoCreateResource()
41{
42 if (m_class == wxT("listbookpage"))
43 {
44 wxXmlNode *n = GetParamNode(wxT("object"));
45
46 if ( !n )
47 n = GetParamNode(wxT("object_ref"));
48
49 if (n)
50 {
51 bool old_ins = m_isInside;
52 m_isInside = false;
53 wxObject *item = CreateResFromNode(n, m_listbook, NULL);
54 m_isInside = old_ins;
55 wxWindow *wnd = wxDynamicCast(item, wxWindow);
56
57 if (wnd)
58 {
59 m_listbook->AddPage(wnd, GetText(wxT("label")),
60 GetBool(wxT("selected")));
61 if ( HasParam(wxT("bitmap")) )
62 {
63 wxBitmap bmp = GetBitmap(wxT("bitmap"), wxART_OTHER);
64 wxImageList *imgList = m_listbook->GetImageList();
65 if ( imgList == NULL )
66 {
67 imgList = new wxImageList( bmp.GetWidth(), bmp.GetHeight() );
68 m_listbook->AssignImageList( imgList );
69 }
70 int imgIndex = imgList->Add(bmp);
71 m_listbook->SetPageImage(m_listbook->GetPageCount()-1, imgIndex );
72 }
73 }
74 else
75 wxLogError(wxT("Error in resource."));
76 return wnd;
77 }
78 else
79 {
80 wxLogError(wxT("Error in resource: no control within listbook's <page> tag."));
81 return NULL;
82 }
83 }
84
85 else
86 {
87 XRC_MAKE_INSTANCE(nb, wxListbook)
88
89 nb->Create(m_parentAsWindow,
90 GetID(),
91 GetPosition(), GetSize(),
92 GetStyle(wxT("style")),
93 GetName());
94
95 wxListbook *old_par = m_listbook;
96 m_listbook = nb;
97 bool old_ins = m_isInside;
98 m_isInside = true;
99 CreateChildren(m_listbook, true/*only this handler*/);
100 m_isInside = old_ins;
101 m_listbook = old_par;
102
103 return nb;
104 }
105}
106
107bool wxListbookXmlHandler::CanHandle(wxXmlNode *node)
108{
109 return ((!m_isInside && IsOfClass(node, wxT("wxListbook"))) ||
110 (m_isInside && IsOfClass(node, wxT("listbookpage"))));
111}
112
113#endif // wxUSE_XRC && wxUSE_LISTBOOK