]>
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 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "xh_menu.h"
15 // For compilers that support precompilation, includes "wx.h".
16 #include "wx/wxprec.h"
24 #include "wx/xrc/xh_menu.h"
28 IMPLEMENT_DYNAMIC_CLASS(wxMenuXmlHandler
, wxXmlResourceHandler
)
30 wxMenuXmlHandler::wxMenuXmlHandler() :
31 wxXmlResourceHandler(), m_insideMenu(false)
33 XRC_ADD_STYLE(wxMENU_TEAROFF
);
36 wxObject
*wxMenuXmlHandler::DoCreateResource()
38 if (m_class
== wxT("wxMenu"))
40 wxMenu
*menu
= new wxMenu(GetStyle());
41 wxString title
= GetText(wxT("label"));
42 wxString help
= GetText(wxT("help"));
44 bool oldins
= m_insideMenu
;
46 CreateChildren(menu
, true/*only this handler*/);
47 m_insideMenu
= oldins
;
49 wxMenuBar
*p_bar
= wxDynamicCast(m_parent
, wxMenuBar
);
51 p_bar
->Append(menu
, title
);
54 wxMenu
*p_menu
= wxDynamicCast(m_parent
, wxMenu
);
56 p_menu
->Append(GetID(), title
, menu
, help
);
64 wxMenu
*p_menu
= wxDynamicCast(m_parent
, wxMenu
);
66 if (m_class
== wxT("separator"))
67 p_menu
->AppendSeparator();
68 else if (m_class
== wxT("break"))
73 wxString label
= GetText(wxT("label"));
74 wxString accel
= GetText(wxT("accel"), false);
75 wxString fullLabel
= label
;
77 fullLabel
<< wxT("\t") << accel
;
79 wxItemKind kind
= wxITEM_NORMAL
;
80 if (GetBool(wxT("radio")))
82 if (GetBool(wxT("checkable")))
84 wxASSERT_MSG( kind
== wxITEM_NORMAL
, _T("can't have both checkable and radion button at once") );
88 wxMenuItem
*mitem
= new wxMenuItem(p_menu
, id
, fullLabel
,
89 GetText(wxT("help")), kind
);
91 #if (!defined(__WXMSW__) && !defined(__WXPM__)) || wxUSE_OWNER_DRAWN
92 if (HasParam(wxT("bitmap")))
93 mitem
->SetBitmap(GetBitmap(wxT("bitmap"), wxART_MENU
));
95 p_menu
->Append(mitem
);
96 mitem
->Enable(GetBool(wxT("enabled"), true));
97 if (kind
== wxITEM_CHECK
)
98 mitem
->Check(GetBool(wxT("checked")));
106 bool wxMenuXmlHandler::CanHandle(wxXmlNode
*node
)
108 return IsOfClass(node
, wxT("wxMenu")) ||
110 (IsOfClass(node
, wxT("wxMenuItem")) ||
111 IsOfClass(node
, wxT("break")) ||
112 IsOfClass(node
, wxT("separator")))
116 IMPLEMENT_DYNAMIC_CLASS(wxMenuBarXmlHandler
, wxXmlResourceHandler
)
118 wxMenuBarXmlHandler::wxMenuBarXmlHandler() : wxXmlResourceHandler()
120 XRC_ADD_STYLE(wxMB_DOCKABLE
);
123 wxObject
*wxMenuBarXmlHandler::DoCreateResource()
125 wxMenuBar
*menubar
= new wxMenuBar(GetStyle());
126 CreateChildren(menubar
);
128 if (m_parentAsWindow
)
130 wxFrame
*parentFrame
= wxDynamicCast(m_parent
, wxFrame
);
132 parentFrame
->SetMenuBar(menubar
);
140 bool wxMenuBarXmlHandler::CanHandle(wxXmlNode
*node
)
142 return IsOfClass(node
, wxT("wxMenuBar"));