]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/xrc/xh_choicbk.cpp
Workaround for #15404: wxRichTextCtrl: caret does not disappear when focus is lost...
[wxWidgets.git] / src / xrc / xh_choicbk.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/xrc/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// 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_CHOICEBOOK
18
19#include "wx/xrc/xh_choicbk.h"
20
21#ifndef WX_PRECOMP
22 #include "wx/log.h"
23 #include "wx/sizer.h"
24#endif
25
26#include "wx/choicebk.h"
27#include "wx/imaglist.h"
28
29IMPLEMENT_DYNAMIC_CLASS(wxChoicebookXmlHandler, wxXmlResourceHandler)
30
31wxChoicebookXmlHandler::wxChoicebookXmlHandler()
32 :wxXmlResourceHandler(),
33 m_isInside(false),
34 m_choicebook(NULL)
35{
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
42 XRC_ADD_STYLE(wxCHB_DEFAULT);
43 XRC_ADD_STYLE(wxCHB_LEFT);
44 XRC_ADD_STYLE(wxCHB_RIGHT);
45 XRC_ADD_STYLE(wxCHB_TOP);
46 XRC_ADD_STYLE(wxCHB_BOTTOM);
47
48 AddWindowStyles();
49}
50
51wxObject *wxChoicebookXmlHandler::DoCreateResource()
52{
53 if (m_class == wxT("choicebookpage"))
54 {
55 wxXmlNode *n = GetParamNode(wxT("object"));
56
57 if ( !n )
58 n = GetParamNode(wxT("object_ref"));
59
60 if (n)
61 {
62 bool old_ins = m_isInside;
63 m_isInside = false;
64 wxObject *item = CreateResFromNode(n, m_choicebook, NULL);
65 m_isInside = old_ins;
66 wxWindow *wnd = wxDynamicCast(item, wxWindow);
67
68 if (wnd)
69 {
70 m_choicebook->AddPage(wnd, GetText(wxT("label")),
71 GetBool(wxT("selected")));
72 if ( HasParam(wxT("bitmap")) )
73 {
74 wxBitmap bmp = GetBitmap(wxT("bitmap"), wxART_OTHER);
75 wxImageList *imgList = m_choicebook->GetImageList();
76 if ( imgList == NULL )
77 {
78 imgList = new wxImageList( bmp.GetWidth(), bmp.GetHeight() );
79 m_choicebook->AssignImageList( imgList );
80 }
81 int imgIndex = imgList->Add(bmp);
82 m_choicebook->SetPageImage(m_choicebook->GetPageCount()-1, imgIndex );
83 }
84 else if ( HasParam(wxT("image")) )
85 {
86 if ( m_choicebook->GetImageList() )
87 {
88 m_choicebook->SetPageImage(m_choicebook->GetPageCount()-1,
89 GetLong(wxT("image")) );
90 }
91 else // image without image list?
92 {
93 ReportError(n, "image can only be used in conjunction "
94 "with imagelist");
95 }
96 }
97 }
98 else
99 {
100 ReportError(n, "choicebookpage child must be a window");
101 }
102 return wnd;
103 }
104 else
105 {
106 ReportError("choicebookpage must have a window child");
107 return NULL;
108 }
109 }
110
111 else
112 {
113 XRC_MAKE_INSTANCE(nb, wxChoicebook)
114
115 nb->Create(m_parentAsWindow,
116 GetID(),
117 GetPosition(), GetSize(),
118 GetStyle(wxT("style")),
119 GetName());
120
121 wxImageList *imagelist = GetImageList();
122 if ( imagelist )
123 nb->AssignImageList(imagelist);
124
125 wxChoicebook *old_par = m_choicebook;
126 m_choicebook = nb;
127 bool old_ins = m_isInside;
128 m_isInside = true;
129 CreateChildren(m_choicebook, true/*only this handler*/);
130 m_isInside = old_ins;
131 m_choicebook = old_par;
132
133 return nb;
134 }
135}
136
137bool wxChoicebookXmlHandler::CanHandle(wxXmlNode *node)
138{
139 return ((!m_isInside && IsOfClass(node, wxT("wxChoicebook"))) ||
140 (m_isInside && IsOfClass(node, wxT("choicebookpage"))));
141}
142
143#endif // wxUSE_XRC && wxUSE_CHOICEBOOK