]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_toolb.cpp
Invalid conversion compile error fix (GTK+ 2.12.9)
[wxWidgets.git] / src / xrc / xh_toolb.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/xrc/xh_toolb.cpp
3 // Purpose: XRC resource for wxToolBar
4 // Author: Vaclav Slavik
5 // Created: 2000/08/11
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_TOOLBAR
19
20 #include "wx/xrc/xh_toolb.h"
21
22 #ifndef WX_PRECOMP
23 #include "wx/frame.h"
24 #include "wx/log.h"
25 #include "wx/menu.h"
26 #include "wx/toolbar.h"
27 #endif
28
29 #include "wx/xml/xml.h"
30
31 IMPLEMENT_DYNAMIC_CLASS(wxToolBarXmlHandler, wxXmlResourceHandler)
32
33 wxToolBarXmlHandler::wxToolBarXmlHandler()
34 : wxXmlResourceHandler(), m_isInside(false), m_toolbar(NULL)
35 {
36 XRC_ADD_STYLE(wxTB_FLAT);
37 XRC_ADD_STYLE(wxTB_DOCKABLE);
38 XRC_ADD_STYLE(wxTB_VERTICAL);
39 XRC_ADD_STYLE(wxTB_HORIZONTAL);
40 XRC_ADD_STYLE(wxTB_3DBUTTONS);
41 XRC_ADD_STYLE(wxTB_TEXT);
42 XRC_ADD_STYLE(wxTB_NOICONS);
43 XRC_ADD_STYLE(wxTB_NODIVIDER);
44 XRC_ADD_STYLE(wxTB_NOALIGN);
45 XRC_ADD_STYLE(wxTB_HORZ_LAYOUT);
46 XRC_ADD_STYLE(wxTB_HORZ_TEXT);
47
48 XRC_ADD_STYLE(wxTB_TOP);
49 XRC_ADD_STYLE(wxTB_LEFT);
50 XRC_ADD_STYLE(wxTB_RIGHT);
51 XRC_ADD_STYLE(wxTB_BOTTOM);
52
53 AddWindowStyles();
54 }
55
56 wxObject *wxToolBarXmlHandler::DoCreateResource()
57 {
58 if (m_class == wxT("tool"))
59 {
60 if ( !m_toolbar )
61 {
62 ReportError("tool only allowed inside a wxToolBar");
63 return NULL;
64 }
65
66 wxItemKind kind = wxITEM_NORMAL;
67 if (GetBool(wxT("radio")))
68 kind = wxITEM_RADIO;
69
70 if (GetBool(wxT("toggle")))
71 {
72 if ( kind != wxITEM_NORMAL )
73 {
74 ReportParamError
75 (
76 "toggle",
77 "tool can't have both <radio> and <toggle> properties"
78 );
79 }
80
81 kind = wxITEM_CHECK;
82 }
83
84 #if wxUSE_MENUS
85 // check whether we have dropdown tag inside
86 wxMenu *menu = NULL; // menu for drop down items
87 wxXmlNode * const nodeDropdown = GetParamNode("dropdown");
88 if ( nodeDropdown )
89 {
90 if ( kind != wxITEM_NORMAL )
91 {
92 ReportParamError
93 (
94 "dropdown",
95 "drop-down tool can't have neither <radio> nor <toggle> properties"
96 );
97 }
98
99 kind = wxITEM_DROPDOWN;
100
101 // also check for the menu specified inside dropdown (it is
102 // optional and may be absent for e.g. dynamically-created
103 // menus)
104 wxXmlNode * const nodeMenu = nodeDropdown->GetChildren();
105 if ( nodeMenu )
106 {
107 wxObject *res = CreateResFromNode(nodeMenu, NULL);
108 menu = wxDynamicCast(res, wxMenu);
109 if ( !menu )
110 {
111 ReportError
112 (
113 nodeMenu,
114 "drop-down tool contents can only be a wxMenu"
115 );
116 }
117
118 if ( nodeMenu->GetNext() )
119 {
120 ReportError
121 (
122 nodeMenu->GetNext(),
123 "unexpected extra contents under drop-down tool"
124 );
125 }
126 }
127 }
128 #endif
129 wxToolBarToolBase * const tool =
130 m_toolbar->AddTool
131 (
132 GetID(),
133 GetText(wxT("label")),
134 GetBitmap(wxT("bitmap"), wxART_TOOLBAR, m_toolSize),
135 GetBitmap(wxT("bitmap2"), wxART_TOOLBAR, m_toolSize),
136 kind,
137 GetText(wxT("tooltip")),
138 GetText(wxT("longhelp"))
139 );
140
141 if ( GetBool(wxT("disabled")) )
142 m_toolbar->EnableTool(GetID(), false);
143
144 if ( GetBool(wxS("checked")) )
145 {
146 if ( kind == wxITEM_NORMAL )
147 {
148 ReportParamError
149 (
150 "checked",
151 "only <radio> nor <toggle> tools can be checked"
152 );
153 }
154 else
155 {
156 m_toolbar->ToggleTool(GetID(), true);
157 }
158 }
159
160 #if wxUSE_MENUS
161 if ( menu )
162 tool->SetDropdownMenu(menu);
163 #endif
164
165 return m_toolbar; // must return non-NULL
166 }
167
168 else if (m_class == wxT("separator") || m_class == wxT("space"))
169 {
170 if ( !m_toolbar )
171 {
172 ReportError("separators only allowed inside wxToolBar");
173 return NULL;
174 }
175
176 if ( m_class == wxT("separator") )
177 m_toolbar->AddSeparator();
178 else
179 m_toolbar->AddStretchableSpace();
180
181 return m_toolbar; // must return non-NULL
182 }
183
184 else /*<object class="wxToolBar">*/
185 {
186 int style = GetStyle(wxT("style"), wxNO_BORDER | wxTB_HORIZONTAL);
187 #ifdef __WXMSW__
188 if (!(style & wxNO_BORDER)) style |= wxNO_BORDER;
189 #endif
190
191 XRC_MAKE_INSTANCE(toolbar, wxToolBar)
192
193 toolbar->Create(m_parentAsWindow,
194 GetID(),
195 GetPosition(),
196 GetSize(),
197 style,
198 GetName());
199 SetupWindow(toolbar);
200
201 m_toolSize = GetSize(wxT("bitmapsize"));
202 if (!(m_toolSize == wxDefaultSize))
203 toolbar->SetToolBitmapSize(m_toolSize);
204 wxSize margins = GetSize(wxT("margins"));
205 if (!(margins == wxDefaultSize))
206 toolbar->SetMargins(margins.x, margins.y);
207 long packing = GetLong(wxT("packing"), -1);
208 if (packing != -1)
209 toolbar->SetToolPacking(packing);
210 long separation = GetLong(wxT("separation"), -1);
211 if (separation != -1)
212 toolbar->SetToolSeparation(separation);
213
214 wxXmlNode *children_node = GetParamNode(wxT("object"));
215 if (!children_node)
216 children_node = GetParamNode(wxT("object_ref"));
217
218 if (children_node == NULL) return toolbar;
219
220 m_isInside = true;
221 m_toolbar = toolbar;
222
223 wxXmlNode *n = children_node;
224
225 while (n)
226 {
227 if ((n->GetType() == wxXML_ELEMENT_NODE) &&
228 (n->GetName() == wxT("object") || n->GetName() == wxT("object_ref")))
229 {
230 wxObject *created = CreateResFromNode(n, toolbar, NULL);
231 wxControl *control = wxDynamicCast(created, wxControl);
232 if (!IsOfClass(n, wxT("tool")) &&
233 !IsOfClass(n, wxT("separator")) &&
234 !IsOfClass(n, wxT("space")) &&
235 control != NULL)
236 toolbar->AddControl(control);
237 }
238 n = n->GetNext();
239 }
240
241 m_isInside = false;
242 m_toolbar = NULL;
243
244 if (m_parentAsWindow && !GetBool(wxT("dontattachtoframe")))
245 {
246 wxFrame *parentFrame = wxDynamicCast(m_parent, wxFrame);
247 if (parentFrame)
248 parentFrame->SetToolBar(toolbar);
249 }
250
251 toolbar->Realize();
252
253 return toolbar;
254 }
255 }
256
257 bool wxToolBarXmlHandler::CanHandle(wxXmlNode *node)
258 {
259 return ((!m_isInside && IsOfClass(node, wxT("wxToolBar"))) ||
260 (m_isInside && IsOfClass(node, wxT("tool"))) ||
261 (m_isInside && IsOfClass(node, wxT("space"))) ||
262 (m_isInside && IsOfClass(node, wxT("separator"))));
263 }
264
265 #endif // wxUSE_XRC && wxUSE_TOOLBAR