]>
git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_menu.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: XRC resource for menus and menubars
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"
20 #include "wx/xrc/xh_menu.h"
24 IMPLEMENT_DYNAMIC_CLASS(wxMenuXmlHandler
, wxXmlResourceHandler
)
26 wxMenuXmlHandler::wxMenuXmlHandler() :
27 wxXmlResourceHandler(), m_insideMenu(false)
29 XRC_ADD_STYLE(wxMENU_TEAROFF
);
32 wxObject
*wxMenuXmlHandler::DoCreateResource()
34 if (m_class
== wxT("wxMenu"))
36 wxMenu
*menu
= new wxMenu(GetStyle());
37 wxString title
= GetText(wxT("label"));
38 wxString help
= GetText(wxT("help"));
40 bool oldins
= m_insideMenu
;
42 CreateChildren(menu
, true/*only this handler*/);
43 m_insideMenu
= oldins
;
45 wxMenuBar
*p_bar
= wxDynamicCast(m_parent
, wxMenuBar
);
48 p_bar
->Append(menu
, title
);
52 wxMenu
*p_menu
= wxDynamicCast(m_parent
, wxMenu
);
55 p_menu
->Append(GetID(), title
, menu
, help
);
56 if (HasParam(wxT("enabled")))
57 p_menu
->Enable(GetID(), GetBool(wxT("enabled")));
66 wxMenu
*p_menu
= wxDynamicCast(m_parent
, wxMenu
);
68 if (m_class
== wxT("separator"))
69 p_menu
->AppendSeparator();
70 else if (m_class
== wxT("break"))
75 wxString label
= GetText(wxT("label"));
76 wxString accel
= GetText(wxT("accel"), false);
77 wxString fullLabel
= label
;
79 fullLabel
<< wxT("\t") << accel
;
81 wxItemKind kind
= wxITEM_NORMAL
;
82 if (GetBool(wxT("radio")))
84 if (GetBool(wxT("checkable")))
86 wxASSERT_MSG( kind
== wxITEM_NORMAL
, _T("can't have both checkable and radion button at once") );
90 wxMenuItem
*mitem
= new wxMenuItem(p_menu
, id
, fullLabel
,
91 GetText(wxT("help")), kind
);
93 #if (!defined(__WXMSW__) && !defined(__WXPM__)) || wxUSE_OWNER_DRAWN
94 if (HasParam(wxT("bitmap")))
95 mitem
->SetBitmap(GetBitmap(wxT("bitmap"), wxART_MENU
));
97 p_menu
->Append(mitem
);
98 mitem
->Enable(GetBool(wxT("enabled"), true));
99 if (kind
== wxITEM_CHECK
)
100 mitem
->Check(GetBool(wxT("checked")));
108 bool wxMenuXmlHandler::CanHandle(wxXmlNode
*node
)
110 return IsOfClass(node
, wxT("wxMenu")) ||
112 (IsOfClass(node
, wxT("wxMenuItem")) ||
113 IsOfClass(node
, wxT("break")) ||
114 IsOfClass(node
, wxT("separator")))
118 IMPLEMENT_DYNAMIC_CLASS(wxMenuBarXmlHandler
, wxXmlResourceHandler
)
120 wxMenuBarXmlHandler::wxMenuBarXmlHandler() : wxXmlResourceHandler()
122 XRC_ADD_STYLE(wxMB_DOCKABLE
);
125 wxObject
*wxMenuBarXmlHandler::DoCreateResource()
127 wxMenuBar
*menubar
= new wxMenuBar(GetStyle());
128 CreateChildren(menubar
);
130 if (m_parentAsWindow
)
132 wxFrame
*parentFrame
= wxDynamicCast(m_parent
, wxFrame
);
134 parentFrame
->SetMenuBar(menubar
);
142 bool wxMenuBarXmlHandler::CanHandle(wxXmlNode
*node
)
144 return IsOfClass(node
, wxT("wxMenuBar"));