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