]>
git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_menu.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/xrc/xh_menu.cpp
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"
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
);
52 p_bar
->Append(menu
, title
);
56 wxMenu
*p_menu
= wxDynamicCast(m_parent
, wxMenu
);
59 p_menu
->Append(GetID(), title
, menu
, help
);
60 if (HasParam(wxT("enabled")))
61 p_menu
->Enable(GetID(), GetBool(wxT("enabled")));
70 wxMenu
*p_menu
= wxDynamicCast(m_parent
, wxMenu
);
72 if (m_class
== wxT("separator"))
73 p_menu
->AppendSeparator();
74 else if (m_class
== wxT("break"))
79 wxString label
= GetText(wxT("label"));
80 wxString accel
= GetText(wxT("accel"), false);
81 wxString fullLabel
= label
;
83 fullLabel
<< wxT("\t") << accel
;
85 wxItemKind kind
= wxITEM_NORMAL
;
86 if (GetBool(wxT("radio")))
88 if (GetBool(wxT("checkable")))
90 wxASSERT_MSG( kind
== wxITEM_NORMAL
, _T("can't have both checkable and radion button at once") );
94 wxMenuItem
*mitem
= new wxMenuItem(p_menu
, id
, fullLabel
,
95 GetText(wxT("help")), kind
);
97 #if (!defined(__WXMSW__) && !defined(__WXPM__)) || wxUSE_OWNER_DRAWN
98 if (HasParam(wxT("bitmap")))
99 mitem
->SetBitmap(GetBitmap(wxT("bitmap"), wxART_MENU
));
101 p_menu
->Append(mitem
);
102 mitem
->Enable(GetBool(wxT("enabled"), true));
103 if (kind
== wxITEM_CHECK
)
104 mitem
->Check(GetBool(wxT("checked")));
112 bool wxMenuXmlHandler::CanHandle(wxXmlNode
*node
)
114 return IsOfClass(node
, wxT("wxMenu")) ||
116 (IsOfClass(node
, wxT("wxMenuItem")) ||
117 IsOfClass(node
, wxT("break")) ||
118 IsOfClass(node
, wxT("separator")))
122 IMPLEMENT_DYNAMIC_CLASS(wxMenuBarXmlHandler
, wxXmlResourceHandler
)
124 wxMenuBarXmlHandler::wxMenuBarXmlHandler() : wxXmlResourceHandler()
126 XRC_ADD_STYLE(wxMB_DOCKABLE
);
129 wxObject
*wxMenuBarXmlHandler::DoCreateResource()
131 wxMenuBar
*menubar
= new wxMenuBar(GetStyle());
132 CreateChildren(menubar
);
134 if (m_parentAsWindow
)
136 wxFrame
*parentFrame
= wxDynamicCast(m_parent
, wxFrame
);
138 parentFrame
->SetMenuBar(menubar
);
146 bool wxMenuBarXmlHandler::CanHandle(wxXmlNode
*node
)
148 return IsOfClass(node
, wxT("wxMenuBar"));