]> git.saurik.com Git - wxWidgets.git/blame - src/xrc/xh_choicbk.cpp
The mmedia contrib requires sys/soundcard.h on unix, so disable it on unix
[wxWidgets.git] / src / xrc / xh_choicbk.cpp
CommitLineData
9aaf1192
WS
1/////////////////////////////////////////////////////////////////////////////
2// Name: xh_choicbk.cpp
3// Purpose: XRC resource for wxChoicebook
4// Author: Vaclav Slavik
5// Created: 2000/03/21
6// Copyright: (c) 2000 Vaclav Slavik
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
11#pragma implementation "xh_choicbk.h"
12#endif
13
14// For compilers that support precompilation, includes "wx.h".
15#include "wx/wxprec.h"
16
17#ifdef __BORLANDC__
18 #pragma hdrstop
19#endif
20
21#if wxUSE_XRC && wxUSE_CHOICEBOOK
22
23#include "wx/xrc/xh_choicbk.h"
24
25#include "wx/log.h"
26#include "wx/choicebk.h"
27#include "wx/imaglist.h"
28#include "wx/sizer.h"
29
30IMPLEMENT_DYNAMIC_CLASS(wxChoicebookXmlHandler, wxXmlResourceHandler)
31
32wxChoicebookXmlHandler::wxChoicebookXmlHandler()
33: wxXmlResourceHandler(), m_isInside(false), m_choicebook(NULL)
34{
72f48155
WS
35 XRC_ADD_STYLE(wxCHB_DEFAULT);
36 XRC_ADD_STYLE(wxCHB_LEFT);
37 XRC_ADD_STYLE(wxCHB_RIGHT);
38 XRC_ADD_STYLE(wxCHB_TOP);
39 XRC_ADD_STYLE(wxCHB_BOTTOM);
5a439c1a 40
9aaf1192
WS
41 AddWindowStyles();
42}
43
44wxObject *wxChoicebookXmlHandler::DoCreateResource()
45{
46 if (m_class == wxT("choicebookpage"))
47 {
48 wxXmlNode *n = GetParamNode(wxT("object"));
49
50 if ( !n )
51 n = GetParamNode(wxT("object_ref"));
52
53 if (n)
54 {
55 bool old_ins = m_isInside;
56 m_isInside = false;
57 wxObject *item = CreateResFromNode(n, m_choicebook, NULL);
58 m_isInside = old_ins;
59 wxWindow *wnd = wxDynamicCast(item, wxWindow);
60
61 if (wnd)
62 {
63 m_choicebook->AddPage(wnd, GetText(wxT("label")),
64 GetBool(wxT("selected")));
65 if ( HasParam(wxT("bitmap")) )
66 {
67 wxBitmap bmp = GetBitmap(wxT("bitmap"), wxART_OTHER);
68 wxImageList *imgList = m_choicebook->GetImageList();
69 if ( imgList == NULL )
70 {
71 imgList = new wxImageList( bmp.GetWidth(), bmp.GetHeight() );
72 m_choicebook->AssignImageList( imgList );
73 }
74 int imgIndex = imgList->Add(bmp);
75 m_choicebook->SetPageImage(m_choicebook->GetPageCount()-1, imgIndex );
76 }
77 }
78 else
79 wxLogError(wxT("Error in resource."));
80 return wnd;
81 }
82 else
83 {
84 wxLogError(wxT("Error in resource: no control within choicebook's <page> tag."));
85 return NULL;
86 }
87 }
88
89 else
90 {
91 XRC_MAKE_INSTANCE(nb, wxChoicebook)
92
93 nb->Create(m_parentAsWindow,
94 GetID(),
95 GetPosition(), GetSize(),
96 GetStyle(wxT("style")),
97 GetName());
98
99 wxChoicebook *old_par = m_choicebook;
100 m_choicebook = nb;
101 bool old_ins = m_isInside;
102 m_isInside = true;
103 CreateChildren(m_choicebook, true/*only this handler*/);
104 m_isInside = old_ins;
105 m_choicebook = old_par;
106
107 return nb;
108 }
109}
110
111bool wxChoicebookXmlHandler::CanHandle(wxXmlNode *node)
112{
113 return ((!m_isInside && IsOfClass(node, wxT("wxChoicebook"))) ||
114 (m_isInside && IsOfClass(node, wxT("choicebookpage"))));
115}
116
117#endif // wxUSE_XRC && wxUSE_CHOICEBOOK