]>
git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_toolb.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/xrc/xh_toolb.cpp
3 // Purpose: XRC resource for wxToolBar
4 // Author: Vaclav Slavik
6 // Copyright: (c) 2000 Vaclav Slavik
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
17 #if wxUSE_XRC && wxUSE_TOOLBAR
19 #include "wx/xrc/xh_toolb.h"
25 #include "wx/toolbar.h"
28 #include "wx/xml/xml.h"
30 IMPLEMENT_DYNAMIC_CLASS(wxToolBarXmlHandler
, wxXmlResourceHandler
)
32 wxToolBarXmlHandler::wxToolBarXmlHandler()
33 : wxXmlResourceHandler(), m_isInside(false), m_toolbar(NULL
)
35 XRC_ADD_STYLE(wxTB_FLAT
);
36 XRC_ADD_STYLE(wxTB_DOCKABLE
);
37 XRC_ADD_STYLE(wxTB_VERTICAL
);
38 XRC_ADD_STYLE(wxTB_HORIZONTAL
);
39 XRC_ADD_STYLE(wxTB_3DBUTTONS
);
40 XRC_ADD_STYLE(wxTB_TEXT
);
41 XRC_ADD_STYLE(wxTB_NOICONS
);
42 XRC_ADD_STYLE(wxTB_NODIVIDER
);
43 XRC_ADD_STYLE(wxTB_NOALIGN
);
44 XRC_ADD_STYLE(wxTB_HORZ_LAYOUT
);
45 XRC_ADD_STYLE(wxTB_HORZ_TEXT
);
47 XRC_ADD_STYLE(wxTB_TOP
);
48 XRC_ADD_STYLE(wxTB_LEFT
);
49 XRC_ADD_STYLE(wxTB_RIGHT
);
50 XRC_ADD_STYLE(wxTB_BOTTOM
);
55 wxObject
*wxToolBarXmlHandler::DoCreateResource()
57 if (m_class
== wxT("tool"))
61 ReportError("tool only allowed inside a wxToolBar");
65 wxItemKind kind
= wxITEM_NORMAL
;
66 if (GetBool(wxT("radio")))
69 if (GetBool(wxT("toggle")))
71 if ( kind
!= wxITEM_NORMAL
)
76 "tool can't have both <radio> and <toggle> properties"
84 // check whether we have dropdown tag inside
85 wxMenu
*menu
= NULL
; // menu for drop down items
86 wxXmlNode
* const nodeDropdown
= GetParamNode("dropdown");
89 if ( kind
!= wxITEM_NORMAL
)
94 "drop-down tool can't have neither <radio> nor <toggle> properties"
98 kind
= wxITEM_DROPDOWN
;
100 // also check for the menu specified inside dropdown (it is
101 // optional and may be absent for e.g. dynamically-created
103 wxXmlNode
* const nodeMenu
= nodeDropdown
->GetChildren();
106 wxObject
*res
= CreateResFromNode(nodeMenu
, NULL
);
107 menu
= wxDynamicCast(res
, wxMenu
);
113 "drop-down tool contents can only be a wxMenu"
117 if ( nodeMenu
->GetNext() )
122 "unexpected extra contents under drop-down tool"
128 wxToolBarToolBase
* const tool
=
132 GetText(wxT("label")),
133 GetBitmap(wxT("bitmap"), wxART_TOOLBAR
, m_toolSize
),
134 GetBitmap(wxT("bitmap2"), wxART_TOOLBAR
, m_toolSize
),
136 GetText(wxT("tooltip")),
137 GetText(wxT("longhelp"))
140 if ( GetBool(wxT("disabled")) )
141 m_toolbar
->EnableTool(GetID(), false);
143 if ( GetBool(wxS("checked")) )
145 if ( kind
== wxITEM_NORMAL
)
150 "only <radio> nor <toggle> tools can be checked"
155 m_toolbar
->ToggleTool(GetID(), true);
161 tool
->SetDropdownMenu(menu
);
164 return m_toolbar
; // must return non-NULL
167 else if (m_class
== wxT("separator") || m_class
== wxT("space"))
171 ReportError("separators only allowed inside wxToolBar");
175 if ( m_class
== wxT("separator") )
176 m_toolbar
->AddSeparator();
178 m_toolbar
->AddStretchableSpace();
180 return m_toolbar
; // must return non-NULL
183 else /*<object class="wxToolBar">*/
185 int style
= GetStyle(wxT("style"), wxNO_BORDER
| wxTB_HORIZONTAL
);
187 if (!(style
& wxNO_BORDER
)) style
|= wxNO_BORDER
;
190 XRC_MAKE_INSTANCE(toolbar
, wxToolBar
)
192 toolbar
->Create(m_parentAsWindow
,
198 SetupWindow(toolbar
);
200 m_toolSize
= GetSize(wxT("bitmapsize"));
201 if (!(m_toolSize
== wxDefaultSize
))
202 toolbar
->SetToolBitmapSize(m_toolSize
);
203 wxSize margins
= GetSize(wxT("margins"));
204 if (!(margins
== wxDefaultSize
))
205 toolbar
->SetMargins(margins
.x
, margins
.y
);
206 long packing
= GetLong(wxT("packing"), -1);
208 toolbar
->SetToolPacking(packing
);
209 long separation
= GetLong(wxT("separation"), -1);
210 if (separation
!= -1)
211 toolbar
->SetToolSeparation(separation
);
213 wxXmlNode
*children_node
= GetParamNode(wxT("object"));
215 children_node
= GetParamNode(wxT("object_ref"));
217 if (children_node
== NULL
) return toolbar
;
222 wxXmlNode
*n
= children_node
;
226 if ((n
->GetType() == wxXML_ELEMENT_NODE
) &&
227 (n
->GetName() == wxT("object") || n
->GetName() == wxT("object_ref")))
229 wxObject
*created
= CreateResFromNode(n
, toolbar
, NULL
);
230 wxControl
*control
= wxDynamicCast(created
, wxControl
);
231 if (!IsOfClass(n
, wxT("tool")) &&
232 !IsOfClass(n
, wxT("separator")) &&
233 !IsOfClass(n
, wxT("space")) &&
235 toolbar
->AddControl(control
);
243 if (m_parentAsWindow
&& !GetBool(wxT("dontattachtoframe")))
245 wxFrame
*parentFrame
= wxDynamicCast(m_parent
, wxFrame
);
247 parentFrame
->SetToolBar(toolbar
);
256 bool wxToolBarXmlHandler::CanHandle(wxXmlNode
*node
)
258 return ((!m_isInside
&& IsOfClass(node
, wxT("wxToolBar"))) ||
259 (m_isInside
&& IsOfClass(node
, wxT("tool"))) ||
260 (m_isInside
&& IsOfClass(node
, wxT("space"))) ||
261 (m_isInside
&& IsOfClass(node
, wxT("separator"))));
264 #endif // wxUSE_XRC && wxUSE_TOOLBAR