1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/xrc/xh_toolb.cpp
3 // Purpose: XRC resource for wxToolBar
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2000 Vaclav Slavik
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
18 #if wxUSE_XRC && wxUSE_TOOLBAR
20 #include "wx/xrc/xh_toolb.h"
24 #include "wx/toolbar.h"
27 IMPLEMENT_DYNAMIC_CLASS(wxToolBarXmlHandler
, wxXmlResourceHandler
)
29 wxToolBarXmlHandler
::wxToolBarXmlHandler()
30 : wxXmlResourceHandler(), m_isInside(false), m_toolbar(NULL
)
32 XRC_ADD_STYLE(wxTB_FLAT
);
33 XRC_ADD_STYLE(wxTB_DOCKABLE
);
34 XRC_ADD_STYLE(wxTB_VERTICAL
);
35 XRC_ADD_STYLE(wxTB_HORIZONTAL
);
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
);
41 XRC_ADD_STYLE(wxTB_HORZ_LAYOUT
);
42 XRC_ADD_STYLE(wxTB_HORZ_TEXT
);
44 XRC_ADD_STYLE(wxTB_TOP
);
45 XRC_ADD_STYLE(wxTB_LEFT
);
46 XRC_ADD_STYLE(wxTB_RIGHT
);
47 XRC_ADD_STYLE(wxTB_BOTTOM
);
52 wxObject
*wxToolBarXmlHandler
::DoCreateResource()
54 if (m_class
== wxT("tool"))
58 wxLogError(_("XRC syntax error: \"tool\" only allowed inside a "
63 wxItemKind kind
= wxITEM_NORMAL
;
64 if (GetBool(wxT("radio")))
67 if (GetBool(wxT("toggle")))
69 if ( kind
!= wxITEM_NORMAL
)
71 wxLogWarning(_("XRC syntax error: tool can't have both "
72 "\"radio\" and \"toggle\" properties, "
73 "ignoring the former."));
79 // check whether we have dropdown tag inside
80 wxMenu
*menu
= NULL
; // menu for drop down items
81 wxXmlNode
* const nodeDropdown
= GetParamNode("dropdown");
84 if ( kind
!= wxITEM_NORMAL
)
86 wxLogWarning(_("XRC syntax error: drop-down tool can't have "
87 "neither \"radio\" nor \"toggle\" properties, "
91 kind
= wxITEM_DROPDOWN
;
93 // also check for the menu specified inside dropdown (it is
94 // optional and may be absent for e.g. dynamically-created
96 wxXmlNode
* const nodeMenu
= nodeDropdown
->GetChildren();
99 wxObject
*res
= CreateResFromNode(nodeMenu
, NULL
);
100 menu
= wxDynamicCast(res
, wxMenu
);
103 wxLogError(_("XRC syntax error: invalid drop-down tool "
104 "contents (expected a menu)."));
107 if ( nodeMenu
->GetNext() )
109 wxLogWarning(_("XRC syntax error: unexpected extra "
110 "contents under drop-down tool."));
115 wxToolBarToolBase
* const
116 tool
= m_toolbar
->AddTool
119 GetText(wxT("label")),
120 GetBitmap(wxT("bitmap"), wxART_TOOLBAR
),
121 GetBitmap(wxT("bitmap2"), wxART_TOOLBAR
),
123 GetText(wxT("tooltip")),
124 GetText(wxT("longhelp"))
127 if ( GetBool(wxT("disabled")) )
128 m_toolbar
->EnableTool(GetID(), false);
131 tool
->SetDropdownMenu(menu
);
133 return m_toolbar
; // must return non-NULL
136 else if (m_class
== wxT("separator"))
140 wxLogError(_("XRC syntax error: \"separator\" only allowed inside a "
144 m_toolbar
->AddSeparator();
145 return m_toolbar
; // must return non-NULL
148 else /*<object class="wxToolBar">*/
150 int style
= GetStyle(wxT("style"), wxNO_BORDER
| wxTB_HORIZONTAL
);
152 if (!(style
& wxNO_BORDER
)) style
|= wxNO_BORDER
;
155 XRC_MAKE_INSTANCE(toolbar
, wxToolBar
)
157 toolbar
->Create(m_parentAsWindow
,
163 SetupWindow(toolbar
);
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);
173 toolbar
->SetToolPacking(packing
);
174 long separation
= GetLong(wxT("separation"), -1);
175 if (separation
!= -1)
176 toolbar
->SetToolSeparation(separation
);
178 wxXmlNode
*children_node
= GetParamNode(wxT("object"));
180 children_node
= GetParamNode(wxT("object_ref"));
182 if (children_node
== NULL
) return toolbar
;
187 wxXmlNode
*n
= children_node
;
191 if ((n
->GetType() == wxXML_ELEMENT_NODE
) &&
192 (n
->GetName() == wxT("object") || n
->GetName() == wxT("object_ref")))
194 wxObject
*created
= CreateResFromNode(n
, toolbar
, NULL
);
195 wxControl
*control
= wxDynamicCast(created
, wxControl
);
196 if (!IsOfClass(n
, wxT("tool")) &&
197 !IsOfClass(n
, wxT("separator")) &&
199 toolbar
->AddControl(control
);
209 if (m_parentAsWindow
&& !GetBool(wxT("dontattachtoframe")))
211 wxFrame
*parentFrame
= wxDynamicCast(m_parent
, wxFrame
);
213 parentFrame
->SetToolBar(toolbar
);
220 bool wxToolBarXmlHandler
::CanHandle(wxXmlNode
*node
)
222 return ((!m_isInside
&& IsOfClass(node
, wxT("wxToolBar"))) ||
223 (m_isInside
&& IsOfClass(node
, wxT("tool"))) ||
224 (m_isInside
&& IsOfClass(node
, wxT("separator"))));
227 #endif // wxUSE_XRC && wxUSE_TOOLBAR