]>
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 #include "wx/xml/xml.h"
31 IMPLEMENT_DYNAMIC_CLASS(wxToolBarXmlHandler
, wxXmlResourceHandler
)
33 wxToolBarXmlHandler::wxToolBarXmlHandler()
34 : wxXmlResourceHandler(), m_isInside(false), m_toolbar(NULL
)
36 XRC_ADD_STYLE(wxTB_FLAT
);
37 XRC_ADD_STYLE(wxTB_DOCKABLE
);
38 XRC_ADD_STYLE(wxTB_VERTICAL
);
39 XRC_ADD_STYLE(wxTB_HORIZONTAL
);
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
);
45 XRC_ADD_STYLE(wxTB_HORZ_LAYOUT
);
46 XRC_ADD_STYLE(wxTB_HORZ_TEXT
);
48 XRC_ADD_STYLE(wxTB_TOP
);
49 XRC_ADD_STYLE(wxTB_LEFT
);
50 XRC_ADD_STYLE(wxTB_RIGHT
);
51 XRC_ADD_STYLE(wxTB_BOTTOM
);
56 wxObject
*wxToolBarXmlHandler::DoCreateResource()
58 if (m_class
== wxT("tool"))
62 ReportError("tool only allowed inside a wxToolBar");
66 wxItemKind kind
= wxITEM_NORMAL
;
67 if (GetBool(wxT("radio")))
70 if (GetBool(wxT("toggle")))
72 if ( kind
!= wxITEM_NORMAL
)
77 "tool can't have both <radio> and <toggle> properties"
85 // check whether we have dropdown tag inside
86 wxMenu
*menu
= NULL
; // menu for drop down items
87 wxXmlNode
* const nodeDropdown
= GetParamNode("dropdown");
90 if ( kind
!= wxITEM_NORMAL
)
95 "drop-down tool can't have neither <radio> nor <toggle> properties"
99 kind
= wxITEM_DROPDOWN
;
101 // also check for the menu specified inside dropdown (it is
102 // optional and may be absent for e.g. dynamically-created
104 wxXmlNode
* const nodeMenu
= nodeDropdown
->GetChildren();
107 wxObject
*res
= CreateResFromNode(nodeMenu
, NULL
);
108 menu
= wxDynamicCast(res
, wxMenu
);
114 "drop-down tool contents can only be a wxMenu"
118 if ( nodeMenu
->GetNext() )
123 "unexpected extra contents under drop-down tool"
129 wxToolBarToolBase
* const tool
=
133 GetText(wxT("label")),
134 GetBitmap(wxT("bitmap"), wxART_TOOLBAR
, m_toolSize
),
135 GetBitmap(wxT("bitmap2"), wxART_TOOLBAR
, m_toolSize
),
137 GetText(wxT("tooltip")),
138 GetText(wxT("longhelp"))
141 if ( GetBool(wxT("disabled")) )
142 m_toolbar
->EnableTool(GetID(), false);
144 if ( GetBool(wxS("checked")) )
146 if ( kind
== wxITEM_NORMAL
)
151 "only <radio> nor <toggle> tools can be checked"
156 m_toolbar
->ToggleTool(GetID(), true);
162 tool
->SetDropdownMenu(menu
);
165 return m_toolbar
; // must return non-NULL
168 else if (m_class
== wxT("separator") || m_class
== wxT("space"))
172 ReportError("separators only allowed inside wxToolBar");
176 if ( m_class
== wxT("separator") )
177 m_toolbar
->AddSeparator();
179 m_toolbar
->AddStretchableSpace();
181 return m_toolbar
; // must return non-NULL
184 else /*<object class="wxToolBar">*/
186 int style
= GetStyle(wxT("style"), wxNO_BORDER
| wxTB_HORIZONTAL
);
188 if (!(style
& wxNO_BORDER
)) style
|= wxNO_BORDER
;
191 XRC_MAKE_INSTANCE(toolbar
, wxToolBar
)
193 toolbar
->Create(m_parentAsWindow
,
199 SetupWindow(toolbar
);
201 m_toolSize
= GetSize(wxT("bitmapsize"));
202 if (!(m_toolSize
== wxDefaultSize
))
203 toolbar
->SetToolBitmapSize(m_toolSize
);
204 wxSize margins
= GetSize(wxT("margins"));
205 if (!(margins
== wxDefaultSize
))
206 toolbar
->SetMargins(margins
.x
, margins
.y
);
207 long packing
= GetLong(wxT("packing"), -1);
209 toolbar
->SetToolPacking(packing
);
210 long separation
= GetLong(wxT("separation"), -1);
211 if (separation
!= -1)
212 toolbar
->SetToolSeparation(separation
);
214 wxXmlNode
*children_node
= GetParamNode(wxT("object"));
216 children_node
= GetParamNode(wxT("object_ref"));
218 if (children_node
== NULL
) return toolbar
;
223 wxXmlNode
*n
= children_node
;
227 if ((n
->GetType() == wxXML_ELEMENT_NODE
) &&
228 (n
->GetName() == wxT("object") || n
->GetName() == wxT("object_ref")))
230 wxObject
*created
= CreateResFromNode(n
, toolbar
, NULL
);
231 wxControl
*control
= wxDynamicCast(created
, wxControl
);
232 if (!IsOfClass(n
, wxT("tool")) &&
233 !IsOfClass(n
, wxT("separator")) &&
234 !IsOfClass(n
, wxT("space")) &&
236 toolbar
->AddControl(control
);
244 if (m_parentAsWindow
&& !GetBool(wxT("dontattachtoframe")))
246 wxFrame
*parentFrame
= wxDynamicCast(m_parent
, wxFrame
);
248 parentFrame
->SetToolBar(toolbar
);
257 bool wxToolBarXmlHandler::CanHandle(wxXmlNode
*node
)
259 return ((!m_isInside
&& IsOfClass(node
, wxT("wxToolBar"))) ||
260 (m_isInside
&& IsOfClass(node
, wxT("tool"))) ||
261 (m_isInside
&& IsOfClass(node
, wxT("space"))) ||
262 (m_isInside
&& IsOfClass(node
, wxT("separator"))));
265 #endif // wxUSE_XRC && wxUSE_TOOLBAR