]> git.saurik.com Git - wxWidgets.git/blame - src/xrc/xh_toolb.cpp
When selecting the bitmap bullet style, the name can now be edited since it could...
[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"
b935c45d
VZ
24 #include "wx/log.h"
25 #include "wx/menu.h"
4e3e485b 26 #include "wx/toolbar.h"
76b49cf4
WS
27#endif
28
df27f1dc
VZ
29#include "wx/xml/xml.h"
30
854e189f
VS
31IMPLEMENT_DYNAMIC_CLASS(wxToolBarXmlHandler, wxXmlResourceHandler)
32
f80ea77b
WS
33wxToolBarXmlHandler::wxToolBarXmlHandler()
34: wxXmlResourceHandler(), m_isInside(false), m_toolbar(NULL)
78d14f80 35{
544fee32
VS
36 XRC_ADD_STYLE(wxTB_FLAT);
37 XRC_ADD_STYLE(wxTB_DOCKABLE);
38 XRC_ADD_STYLE(wxTB_VERTICAL);
39 XRC_ADD_STYLE(wxTB_HORIZONTAL);
c37ffc1f
VS
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);
b29c9f3b 45 XRC_ADD_STYLE(wxTB_HORZ_LAYOUT);
61b52e46 46 XRC_ADD_STYLE(wxTB_HORZ_TEXT);
9583e4f4
VZ
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
ace1785b 53 AddWindowStyles();
78d14f80
VS
54}
55
78d14f80 56wxObject *wxToolBarXmlHandler::DoCreateResource()
f80ea77b 57{
78d14f80
VS
58 if (m_class == wxT("tool"))
59 {
07acc3cc
VZ
60 if ( !m_toolbar )
61 {
819559b2 62 ReportError("tool only allowed inside a wxToolBar");
07acc3cc
VZ
63 return NULL;
64 }
f80ea77b 65
e13edb66
VZ
66 wxItemKind kind = wxITEM_NORMAL;
67 if (GetBool(wxT("radio")))
68 kind = wxITEM_RADIO;
e2517f17 69
e13edb66 70 if (GetBool(wxT("toggle")))
c37ffc1f 71 {
07acc3cc
VZ
72 if ( kind != wxITEM_NORMAL )
73 {
819559b2
VS
74 ReportParamError
75 (
76 "toggle",
77 "tool can't have both <radio> and <toggle> properties"
78 );
07acc3cc
VZ
79 }
80
e13edb66 81 kind = wxITEM_CHECK;
c37ffc1f 82 }
f72ed385 83
073e1041 84#if wxUSE_MENUS
e2517f17
VZ
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 {
07acc3cc
VZ
90 if ( kind != wxITEM_NORMAL )
91 {
819559b2
VS
92 ReportParamError
93 (
94 "dropdown",
95 "drop-down tool can't have neither <radio> nor <toggle> properties"
96 );
07acc3cc 97 }
e2517f17
VZ
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);
07acc3cc
VZ
109 if ( !menu )
110 {
819559b2
VS
111 ReportError
112 (
113 nodeMenu,
114 "drop-down tool contents can only be a wxMenu"
115 );
07acc3cc
VZ
116 }
117
118 if ( nodeMenu->GetNext() )
119 {
819559b2
VS
120 ReportError
121 (
122 nodeMenu->GetNext(),
123 "unexpected extra contents under drop-down tool"
124 );
07acc3cc 125 }
e2517f17
VZ
126 }
127 }
073e1041 128#endif
d0f06302
VS
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 );
e13edb66
VZ
140
141 if ( GetBool(wxT("disabled")) )
142 m_toolbar->EnableTool(GetID(), false);
f72ed385
VZ
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
073e1041 160#if wxUSE_MENUS
e2517f17
VZ
161 if ( menu )
162 tool->SetDropdownMenu(menu);
073e1041 163#endif
ce00f59b 164
78d14f80
VS
165 return m_toolbar; // must return non-NULL
166 }
f80ea77b 167
5852e62f 168 else if (m_class == wxT("separator") || m_class == wxT("space"))
78d14f80 169 {
07acc3cc
VZ
170 if ( !m_toolbar )
171 {
5852e62f 172 ReportError("separators only allowed inside wxToolBar");
07acc3cc
VZ
173 return NULL;
174 }
5852e62f
VZ
175
176 if ( m_class == wxT("separator") )
177 m_toolbar->AddSeparator();
178 else
179 m_toolbar->AddStretchableSpace();
180
78d14f80
VS
181 return m_toolbar; // must return non-NULL
182 }
f80ea77b 183
78d14f80
VS
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
f2588180 190
544fee32 191 XRC_MAKE_INSTANCE(toolbar, wxToolBar)
f80ea77b 192
f2588180
VS
193 toolbar->Create(m_parentAsWindow,
194 GetID(),
195 GetPosition(),
196 GetSize(),
197 style,
198 GetName());
62311405 199 SetupWindow(toolbar);
78d14f80 200
d0f06302
VS
201 m_toolSize = GetSize(wxT("bitmapsize"));
202 if (!(m_toolSize == wxDefaultSize))
203 toolbar->SetToolBitmapSize(m_toolSize);
78d14f80
VS
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"));
f2588180
VS
215 if (!children_node)
216 children_node = GetParamNode(wxT("object_ref"));
217
78d14f80
VS
218 if (children_node == NULL) return toolbar;
219
f80ea77b 220 m_isInside = true;
78d14f80
VS
221 m_toolbar = toolbar;
222
223 wxXmlNode *n = children_node;
224
225 while (n)
226 {
f80ea77b 227 if ((n->GetType() == wxXML_ELEMENT_NODE) &&
f2588180 228 (n->GetName() == wxT("object") || n->GetName() == wxT("object_ref")))
78d14f80
VS
229 {
230 wxObject *created = CreateResFromNode(n, toolbar, NULL);
231 wxControl *control = wxDynamicCast(created, wxControl);
a42aa5d7
VS
232 if (!IsOfClass(n, wxT("tool")) &&
233 !IsOfClass(n, wxT("separator")) &&
5852e62f 234 !IsOfClass(n, wxT("space")) &&
78d14f80
VS
235 control != NULL)
236 toolbar->AddControl(control);
237 }
238 n = n->GetNext();
239 }
240
f80ea77b 241 m_isInside = false;
78d14f80
VS
242 m_toolbar = NULL;
243
017b6a0d 244 if (m_parentAsWindow && !GetBool(wxT("dontattachtoframe")))
f2588180
VS
245 {
246 wxFrame *parentFrame = wxDynamicCast(m_parent, wxFrame);
247 if (parentFrame)
248 parentFrame->SetToolBar(toolbar);
249 }
250
5c413e62
VS
251 toolbar->Realize();
252
78d14f80
VS
253 return toolbar;
254 }
255}
256
78d14f80
VS
257bool wxToolBarXmlHandler::CanHandle(wxXmlNode *node)
258{
259 return ((!m_isInside && IsOfClass(node, wxT("wxToolBar"))) ||
f80ea77b 260 (m_isInside && IsOfClass(node, wxT("tool"))) ||
5852e62f 261 (m_isInside && IsOfClass(node, wxT("space"))) ||
78d14f80
VS
262 (m_isInside && IsOfClass(node, wxT("separator"))));
263}
264
a1e4ec87 265#endif // wxUSE_XRC && wxUSE_TOOLBAR