]>
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
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"
26 #include "wx/toolbar.h"
29 IMPLEMENT_DYNAMIC_CLASS(wxToolBarXmlHandler
, wxXmlResourceHandler
)
31 wxToolBarXmlHandler::wxToolBarXmlHandler()
32 : wxXmlResourceHandler(), m_isInside(false), m_toolbar(NULL
)
34 XRC_ADD_STYLE(wxTB_FLAT
);
35 XRC_ADD_STYLE(wxTB_DOCKABLE
);
36 XRC_ADD_STYLE(wxTB_VERTICAL
);
37 XRC_ADD_STYLE(wxTB_HORIZONTAL
);
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
);
43 XRC_ADD_STYLE(wxTB_HORZ_LAYOUT
);
44 XRC_ADD_STYLE(wxTB_HORZ_TEXT
);
46 XRC_ADD_STYLE(wxTB_TOP
);
47 XRC_ADD_STYLE(wxTB_LEFT
);
48 XRC_ADD_STYLE(wxTB_RIGHT
);
49 XRC_ADD_STYLE(wxTB_BOTTOM
);
54 wxObject
*wxToolBarXmlHandler::DoCreateResource()
56 if (m_class
== wxT("tool"))
60 ReportError("tool only allowed inside a wxToolBar");
64 wxItemKind kind
= wxITEM_NORMAL
;
65 if (GetBool(wxT("radio")))
68 if (GetBool(wxT("toggle")))
70 if ( kind
!= wxITEM_NORMAL
)
75 "tool can't have both <radio> and <toggle> properties"
83 // check whether we have dropdown tag inside
84 wxMenu
*menu
= NULL
; // menu for drop down items
85 wxXmlNode
* const nodeDropdown
= GetParamNode("dropdown");
88 if ( kind
!= wxITEM_NORMAL
)
93 "drop-down tool can't have neither <radio> nor <toggle> properties"
97 kind
= wxITEM_DROPDOWN
;
99 // also check for the menu specified inside dropdown (it is
100 // optional and may be absent for e.g. dynamically-created
102 wxXmlNode
* const nodeMenu
= nodeDropdown
->GetChildren();
105 wxObject
*res
= CreateResFromNode(nodeMenu
, NULL
);
106 menu
= wxDynamicCast(res
, wxMenu
);
112 "drop-down tool contents can only be a wxMenu"
116 if ( nodeMenu
->GetNext() )
121 "unexpected extra contents under drop-down tool"
127 wxToolBarToolBase
* const tool
=
131 GetText(wxT("label")),
132 GetBitmap(wxT("bitmap"), wxART_TOOLBAR
, m_toolSize
),
133 GetBitmap(wxT("bitmap2"), wxART_TOOLBAR
, m_toolSize
),
135 GetText(wxT("tooltip")),
136 GetText(wxT("longhelp"))
139 if ( GetBool(wxT("disabled")) )
140 m_toolbar
->EnableTool(GetID(), false);
142 if ( GetBool(wxS("checked")) )
144 if ( kind
== wxITEM_NORMAL
)
149 "only <radio> nor <toggle> tools can be checked"
154 m_toolbar
->ToggleTool(GetID(), true);
160 tool
->SetDropdownMenu(menu
);
163 return m_toolbar
; // must return non-NULL
166 else if (m_class
== wxT("separator") || m_class
== wxT("space"))
170 ReportError("separators only allowed inside wxToolBar");
174 if ( m_class
== wxT("separator") )
175 m_toolbar
->AddSeparator();
177 m_toolbar
->AddStretchableSpace();
179 return m_toolbar
; // must return non-NULL
182 else /*<object class="wxToolBar">*/
184 int style
= GetStyle(wxT("style"), wxNO_BORDER
| wxTB_HORIZONTAL
);
186 if (!(style
& wxNO_BORDER
)) style
|= wxNO_BORDER
;
189 XRC_MAKE_INSTANCE(toolbar
, wxToolBar
)
191 toolbar
->Create(m_parentAsWindow
,
197 SetupWindow(toolbar
);
199 m_toolSize
= GetSize(wxT("bitmapsize"));
200 if (!(m_toolSize
== wxDefaultSize
))
201 toolbar
->SetToolBitmapSize(m_toolSize
);
202 wxSize margins
= GetSize(wxT("margins"));
203 if (!(margins
== wxDefaultSize
))
204 toolbar
->SetMargins(margins
.x
, margins
.y
);
205 long packing
= GetLong(wxT("packing"), -1);
207 toolbar
->SetToolPacking(packing
);
208 long separation
= GetLong(wxT("separation"), -1);
209 if (separation
!= -1)
210 toolbar
->SetToolSeparation(separation
);
212 wxXmlNode
*children_node
= GetParamNode(wxT("object"));
214 children_node
= GetParamNode(wxT("object_ref"));
216 if (children_node
== NULL
) return toolbar
;
221 wxXmlNode
*n
= children_node
;
225 if ((n
->GetType() == wxXML_ELEMENT_NODE
) &&
226 (n
->GetName() == wxT("object") || n
->GetName() == wxT("object_ref")))
228 wxObject
*created
= CreateResFromNode(n
, toolbar
, NULL
);
229 wxControl
*control
= wxDynamicCast(created
, wxControl
);
230 if (!IsOfClass(n
, wxT("tool")) &&
231 !IsOfClass(n
, wxT("separator")) &&
232 !IsOfClass(n
, wxT("space")) &&
234 toolbar
->AddControl(control
);
244 if (m_parentAsWindow
&& !GetBool(wxT("dontattachtoframe")))
246 wxFrame
*parentFrame
= wxDynamicCast(m_parent
, wxFrame
);
248 parentFrame
->SetToolBar(toolbar
);
255 bool wxToolBarXmlHandler::CanHandle(wxXmlNode
*node
)
257 return ((!m_isInside
&& IsOfClass(node
, wxT("wxToolBar"))) ||
258 (m_isInside
&& IsOfClass(node
, wxT("tool"))) ||
259 (m_isInside
&& IsOfClass(node
, wxT("space"))) ||
260 (m_isInside
&& IsOfClass(node
, wxT("separator"))));
263 #endif // wxUSE_XRC && wxUSE_TOOLBAR