]>
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 wxLogError(_("XRC syntax error: \"tool\" only allowed inside a "
65 wxItemKind kind
= wxITEM_NORMAL
;
66 if (GetBool(wxT("radio")))
69 if (GetBool(wxT("toggle")))
71 if ( kind
!= wxITEM_NORMAL
)
73 wxLogWarning(_("XRC syntax error: tool can't have both "
74 "\"radio\" and \"toggle\" properties, "
75 "ignoring the former."));
81 // check whether we have dropdown tag inside
82 wxMenu
*menu
= NULL
; // menu for drop down items
83 wxXmlNode
* const nodeDropdown
= GetParamNode("dropdown");
86 if ( kind
!= wxITEM_NORMAL
)
88 wxLogWarning(_("XRC syntax error: drop-down tool can't have "
89 "neither \"radio\" nor \"toggle\" properties, "
93 kind
= wxITEM_DROPDOWN
;
95 // also check for the menu specified inside dropdown (it is
96 // optional and may be absent for e.g. dynamically-created
98 wxXmlNode
* const nodeMenu
= nodeDropdown
->GetChildren();
101 wxObject
*res
= CreateResFromNode(nodeMenu
, NULL
);
102 menu
= wxDynamicCast(res
, wxMenu
);
105 wxLogError(_("XRC syntax error: invalid drop-down tool "
106 "contents (expected a menu)."));
109 if ( nodeMenu
->GetNext() )
111 wxLogWarning(_("XRC syntax error: unexpected extra "
112 "contents under drop-down tool."));
117 wxToolBarToolBase
* const
118 tool
= m_toolbar
->AddTool
121 GetText(wxT("label")),
122 GetBitmap(wxT("bitmap"), wxART_TOOLBAR
),
123 GetBitmap(wxT("bitmap2"), wxART_TOOLBAR
),
125 GetText(wxT("tooltip")),
126 GetText(wxT("longhelp"))
129 if ( GetBool(wxT("disabled")) )
130 m_toolbar
->EnableTool(GetID(), false);
133 tool
->SetDropdownMenu(menu
);
135 return m_toolbar
; // must return non-NULL
138 else if (m_class
== wxT("separator"))
142 wxLogError(_("XRC syntax error: \"separator\" only allowed inside a "
146 m_toolbar
->AddSeparator();
147 return m_toolbar
; // must return non-NULL
150 else /*<object class="wxToolBar">*/
152 int style
= GetStyle(wxT("style"), wxNO_BORDER
| wxTB_HORIZONTAL
);
154 if (!(style
& wxNO_BORDER
)) style
|= wxNO_BORDER
;
157 XRC_MAKE_INSTANCE(toolbar
, wxToolBar
)
159 toolbar
->Create(m_parentAsWindow
,
165 SetupWindow(toolbar
);
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);
175 toolbar
->SetToolPacking(packing
);
176 long separation
= GetLong(wxT("separation"), -1);
177 if (separation
!= -1)
178 toolbar
->SetToolSeparation(separation
);
180 wxXmlNode
*children_node
= GetParamNode(wxT("object"));
182 children_node
= GetParamNode(wxT("object_ref"));
184 if (children_node
== NULL
) return toolbar
;
189 wxXmlNode
*n
= children_node
;
193 if ((n
->GetType() == wxXML_ELEMENT_NODE
) &&
194 (n
->GetName() == wxT("object") || n
->GetName() == wxT("object_ref")))
196 wxObject
*created
= CreateResFromNode(n
, toolbar
, NULL
);
197 wxControl
*control
= wxDynamicCast(created
, wxControl
);
198 if (!IsOfClass(n
, wxT("tool")) &&
199 !IsOfClass(n
, wxT("separator")) &&
201 toolbar
->AddControl(control
);
211 if (m_parentAsWindow
&& !GetBool(wxT("dontattachtoframe")))
213 wxFrame
*parentFrame
= wxDynamicCast(m_parent
, wxFrame
);
215 parentFrame
->SetToolBar(toolbar
);
222 bool wxToolBarXmlHandler::CanHandle(wxXmlNode
*node
)
224 return ((!m_isInside
&& IsOfClass(node
, wxT("wxToolBar"))) ||
225 (m_isInside
&& IsOfClass(node
, wxT("tool"))) ||
226 (m_isInside
&& IsOfClass(node
, wxT("separator"))));
229 #endif // wxUSE_XRC && wxUSE_TOOLBAR