]>
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"
82 // check whether we have dropdown tag inside
83 wxMenu
*menu
= NULL
; // menu for drop down items
84 wxXmlNode
* const nodeDropdown
= GetParamNode("dropdown");
87 if ( kind
!= wxITEM_NORMAL
)
92 "drop-down tool can't have neither <radio> nor <toggle> properties"
96 kind
= wxITEM_DROPDOWN
;
98 // also check for the menu specified inside dropdown (it is
99 // optional and may be absent for e.g. dynamically-created
101 wxXmlNode
* const nodeMenu
= nodeDropdown
->GetChildren();
104 wxObject
*res
= CreateResFromNode(nodeMenu
, NULL
);
105 menu
= wxDynamicCast(res
, wxMenu
);
111 "drop-down tool contents can only be a wxMenu"
115 if ( nodeMenu
->GetNext() )
120 "unexpected extra contents under drop-down tool"
126 wxToolBarToolBase
* const
127 tool
= m_toolbar
->AddTool
130 GetText(wxT("label")),
131 GetBitmap(wxT("bitmap"), wxART_TOOLBAR
),
132 GetBitmap(wxT("bitmap2"), wxART_TOOLBAR
),
134 GetText(wxT("tooltip")),
135 GetText(wxT("longhelp"))
138 if ( GetBool(wxT("disabled")) )
139 m_toolbar
->EnableTool(GetID(), false);
142 tool
->SetDropdownMenu(menu
);
144 return m_toolbar
; // must return non-NULL
147 else if (m_class
== wxT("separator"))
151 ReportError("separator only allowed inside wxToolBar");
154 m_toolbar
->AddSeparator();
155 return m_toolbar
; // must return non-NULL
158 else /*<object class="wxToolBar">*/
160 int style
= GetStyle(wxT("style"), wxNO_BORDER
| wxTB_HORIZONTAL
);
162 if (!(style
& wxNO_BORDER
)) style
|= wxNO_BORDER
;
165 XRC_MAKE_INSTANCE(toolbar
, wxToolBar
)
167 toolbar
->Create(m_parentAsWindow
,
173 SetupWindow(toolbar
);
175 wxSize bmpsize
= GetSize(wxT("bitmapsize"));
176 if (!(bmpsize
== wxDefaultSize
))
177 toolbar
->SetToolBitmapSize(bmpsize
);
178 wxSize margins
= GetSize(wxT("margins"));
179 if (!(margins
== wxDefaultSize
))
180 toolbar
->SetMargins(margins
.x
, margins
.y
);
181 long packing
= GetLong(wxT("packing"), -1);
183 toolbar
->SetToolPacking(packing
);
184 long separation
= GetLong(wxT("separation"), -1);
185 if (separation
!= -1)
186 toolbar
->SetToolSeparation(separation
);
188 wxXmlNode
*children_node
= GetParamNode(wxT("object"));
190 children_node
= GetParamNode(wxT("object_ref"));
192 if (children_node
== NULL
) return toolbar
;
197 wxXmlNode
*n
= children_node
;
201 if ((n
->GetType() == wxXML_ELEMENT_NODE
) &&
202 (n
->GetName() == wxT("object") || n
->GetName() == wxT("object_ref")))
204 wxObject
*created
= CreateResFromNode(n
, toolbar
, NULL
);
205 wxControl
*control
= wxDynamicCast(created
, wxControl
);
206 if (!IsOfClass(n
, wxT("tool")) &&
207 !IsOfClass(n
, wxT("separator")) &&
209 toolbar
->AddControl(control
);
219 if (m_parentAsWindow
&& !GetBool(wxT("dontattachtoframe")))
221 wxFrame
*parentFrame
= wxDynamicCast(m_parent
, wxFrame
);
223 parentFrame
->SetToolBar(toolbar
);
230 bool wxToolBarXmlHandler::CanHandle(wxXmlNode
*node
)
232 return ((!m_isInside
&& IsOfClass(node
, wxT("wxToolBar"))) ||
233 (m_isInside
&& IsOfClass(node
, wxT("tool"))) ||
234 (m_isInside
&& IsOfClass(node
, wxT("separator"))));
237 #endif // wxUSE_XRC && wxUSE_TOOLBAR