]> git.saurik.com Git - wxWidgets.git/blame - src/xrc/xh_toolb.cpp
Switch off the tests on Windows and switch back on the email notifications.
[wxWidgets.git] / src / xrc / xh_toolb.cpp
CommitLineData
78d14f80 1/////////////////////////////////////////////////////////////////////////////
76b49cf4 2// Name: src/xrc/xh_toolb.cpp
dd47af27 3// Purpose: XRC resource for wxToolBar
78d14f80
VS
4// Author: Vaclav Slavik
5// Created: 2000/08/11
6// RCS-ID: $Id$
7// Copyright: (c) 2000 Vaclav Slavik
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
f80ea77b 10
78d14f80
VS
11// For compilers that support precompilation, includes "wx.h".
12#include "wx/wxprec.h"
13
14#ifdef __BORLANDC__
15 #pragma hdrstop
16#endif
17
621be1ec 18#if wxUSE_XRC && wxUSE_TOOLBAR
a1e4ec87 19
78d14f80 20#include "wx/xrc/xh_toolb.h"
76b49cf4
WS
21
22#ifndef WX_PRECOMP
23 #include "wx/frame.h"
4e3e485b 24 #include "wx/toolbar.h"
76b49cf4
WS
25#endif
26
854e189f
VS
27IMPLEMENT_DYNAMIC_CLASS(wxToolBarXmlHandler, wxXmlResourceHandler)
28
f80ea77b
WS
29wxToolBarXmlHandler::wxToolBarXmlHandler()
30: wxXmlResourceHandler(), m_isInside(false), m_toolbar(NULL)
78d14f80 31{
544fee32
VS
32 XRC_ADD_STYLE(wxTB_FLAT);
33 XRC_ADD_STYLE(wxTB_DOCKABLE);
34 XRC_ADD_STYLE(wxTB_VERTICAL);
35 XRC_ADD_STYLE(wxTB_HORIZONTAL);
c37ffc1f
VS
36 XRC_ADD_STYLE(wxTB_3DBUTTONS);
37 XRC_ADD_STYLE(wxTB_TEXT);
38 XRC_ADD_STYLE(wxTB_NOICONS);
39 XRC_ADD_STYLE(wxTB_NODIVIDER);
40 XRC_ADD_STYLE(wxTB_NOALIGN);
b29c9f3b 41 XRC_ADD_STYLE(wxTB_HORZ_LAYOUT);
61b52e46 42 XRC_ADD_STYLE(wxTB_HORZ_TEXT);
9583e4f4
VZ
43
44 XRC_ADD_STYLE(wxTB_TOP);
45 XRC_ADD_STYLE(wxTB_LEFT);
46 XRC_ADD_STYLE(wxTB_RIGHT);
47 XRC_ADD_STYLE(wxTB_BOTTOM);
48
ace1785b 49 AddWindowStyles();
78d14f80
VS
50}
51
78d14f80 52wxObject *wxToolBarXmlHandler::DoCreateResource()
f80ea77b 53{
78d14f80
VS
54 if (m_class == wxT("tool"))
55 {
07acc3cc
VZ
56 if ( !m_toolbar )
57 {
58 wxLogError(_("XRC syntax error: \"tool\" only allowed inside a "
59 "toolbar"));
60 return NULL;
61 }
f80ea77b 62
e13edb66
VZ
63 wxItemKind kind = wxITEM_NORMAL;
64 if (GetBool(wxT("radio")))
65 kind = wxITEM_RADIO;
e2517f17 66
e13edb66 67 if (GetBool(wxT("toggle")))
c37ffc1f 68 {
07acc3cc
VZ
69 if ( kind != wxITEM_NORMAL )
70 {
71 wxLogWarning(_("XRC syntax error: tool can't have both "
72 "\"radio\" and \"toggle\" properties, "
73 "ignoring the former."));
74 }
75
e13edb66 76 kind = wxITEM_CHECK;
c37ffc1f 77 }
e2517f17
VZ
78
79 // check whether we have dropdown tag inside
80 wxMenu *menu = NULL; // menu for drop down items
81 wxXmlNode * const nodeDropdown = GetParamNode("dropdown");
82 if ( nodeDropdown )
83 {
07acc3cc
VZ
84 if ( kind != wxITEM_NORMAL )
85 {
86 wxLogWarning(_("XRC syntax error: drop-down tool can't have "
87 "neither \"radio\" nor \"toggle\" properties, "
88 "ignoring them."));
89 }
e2517f17
VZ
90
91 kind = wxITEM_DROPDOWN;
92
93 // also check for the menu specified inside dropdown (it is
94 // optional and may be absent for e.g. dynamically-created
95 // menus)
96 wxXmlNode * const nodeMenu = nodeDropdown->GetChildren();
97 if ( nodeMenu )
98 {
99 wxObject *res = CreateResFromNode(nodeMenu, NULL);
100 menu = wxDynamicCast(res, wxMenu);
07acc3cc
VZ
101 if ( !menu )
102 {
103 wxLogError(_("XRC syntax error: invalid drop-down tool "
104 "contents (expected a menu)."));
105 }
106
107 if ( nodeMenu->GetNext() )
108 {
109 wxLogWarning(_("XRC syntax error: unexpected extra "
110 "contents under drop-down tool."));
111 }
e2517f17
VZ
112 }
113 }
114
115 wxToolBarToolBase * const
116 tool = m_toolbar->AddTool
117 (
118 GetID(),
119 GetText(wxT("label")),
120 GetBitmap(wxT("bitmap"), wxART_TOOLBAR),
121 GetBitmap(wxT("bitmap2"), wxART_TOOLBAR),
122 kind,
123 GetText(wxT("tooltip")),
124 GetText(wxT("longhelp"))
125 );
e13edb66
VZ
126
127 if ( GetBool(wxT("disabled")) )
128 m_toolbar->EnableTool(GetID(), false);
129
e2517f17
VZ
130 if ( menu )
131 tool->SetDropdownMenu(menu);
132
78d14f80
VS
133 return m_toolbar; // must return non-NULL
134 }
f80ea77b 135
78d14f80
VS
136 else if (m_class == wxT("separator"))
137 {
07acc3cc
VZ
138 if ( !m_toolbar )
139 {
140 wxLogError(_("XRC syntax error: \"separator\" only allowed inside a "
141 "toolbar"));
142 return NULL;
143 }
78d14f80
VS
144 m_toolbar->AddSeparator();
145 return m_toolbar; // must return non-NULL
146 }
f80ea77b 147
78d14f80
VS
148 else /*<object class="wxToolBar">*/
149 {
150 int style = GetStyle(wxT("style"), wxNO_BORDER | wxTB_HORIZONTAL);
151#ifdef __WXMSW__
152 if (!(style & wxNO_BORDER)) style |= wxNO_BORDER;
153#endif
f2588180 154
544fee32 155 XRC_MAKE_INSTANCE(toolbar, wxToolBar)
f80ea77b 156
f2588180
VS
157 toolbar->Create(m_parentAsWindow,
158 GetID(),
159 GetPosition(),
160 GetSize(),
161 style,
162 GetName());
62311405 163 SetupWindow(toolbar);
78d14f80
VS
164
165 wxSize bmpsize = GetSize(wxT("bitmapsize"));
166 if (!(bmpsize == wxDefaultSize))
167 toolbar->SetToolBitmapSize(bmpsize);
168 wxSize margins = GetSize(wxT("margins"));
169 if (!(margins == wxDefaultSize))
170 toolbar->SetMargins(margins.x, margins.y);
171 long packing = GetLong(wxT("packing"), -1);
172 if (packing != -1)
173 toolbar->SetToolPacking(packing);
174 long separation = GetLong(wxT("separation"), -1);
175 if (separation != -1)
176 toolbar->SetToolSeparation(separation);
177
178 wxXmlNode *children_node = GetParamNode(wxT("object"));
f2588180
VS
179 if (!children_node)
180 children_node = GetParamNode(wxT("object_ref"));
181
78d14f80
VS
182 if (children_node == NULL) return toolbar;
183
f80ea77b 184 m_isInside = true;
78d14f80
VS
185 m_toolbar = toolbar;
186
187 wxXmlNode *n = children_node;
188
189 while (n)
190 {
f80ea77b 191 if ((n->GetType() == wxXML_ELEMENT_NODE) &&
f2588180 192 (n->GetName() == wxT("object") || n->GetName() == wxT("object_ref")))
78d14f80
VS
193 {
194 wxObject *created = CreateResFromNode(n, toolbar, NULL);
195 wxControl *control = wxDynamicCast(created, wxControl);
a42aa5d7
VS
196 if (!IsOfClass(n, wxT("tool")) &&
197 !IsOfClass(n, wxT("separator")) &&
78d14f80
VS
198 control != NULL)
199 toolbar->AddControl(control);
200 }
201 n = n->GetNext();
202 }
203
f80ea77b 204 m_isInside = false;
78d14f80
VS
205 m_toolbar = NULL;
206
207 toolbar->Realize();
f2588180 208
017b6a0d 209 if (m_parentAsWindow && !GetBool(wxT("dontattachtoframe")))
f2588180
VS
210 {
211 wxFrame *parentFrame = wxDynamicCast(m_parent, wxFrame);
212 if (parentFrame)
213 parentFrame->SetToolBar(toolbar);
214 }
215
78d14f80
VS
216 return toolbar;
217 }
218}
219
78d14f80
VS
220bool wxToolBarXmlHandler::CanHandle(wxXmlNode *node)
221{
222 return ((!m_isInside && IsOfClass(node, wxT("wxToolBar"))) ||
f80ea77b 223 (m_isInside && IsOfClass(node, wxT("tool"))) ||
78d14f80
VS
224 (m_isInside && IsOfClass(node, wxT("separator"))));
225}
226
a1e4ec87 227#endif // wxUSE_XRC && wxUSE_TOOLBAR