]>
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"
22 #include "wx/xrc/xh_menu.h"
26 wxMenuXmlHandler::wxMenuXmlHandler() :
27 wxXmlResourceHandler(), m_insideMenu(FALSE
)
29 ADD_STYLE(wxMENU_TEAROFF
);
34 wxObject
*wxMenuXmlHandler::DoCreateResource()
36 if (m_class
== wxT("wxMenu"))
38 wxMenu
*menu
= new wxMenu(GetStyle());
39 wxString title
= GetText(wxT("label"));
40 wxString help
= GetText(wxT("help"));
42 bool oldins
= m_insideMenu
;
44 CreateChildren(menu
, TRUE
/*only this handler*/);
45 m_insideMenu
= oldins
;
47 wxMenuBar
*p_bar
= wxDynamicCast(m_parent
, wxMenuBar
);
49 p_bar
->Append(menu
, title
);
52 wxMenu
*p_menu
= wxDynamicCast(m_parent
, wxMenu
);
54 p_menu
->Append(GetID(), title
, menu
, help
);
62 wxMenu
*p_menu
= wxDynamicCast(m_parent
, wxMenu
);
64 if (m_class
== wxT("separator"))
65 p_menu
->AppendSeparator();
66 else if (m_class
== wxT("break"))
71 bool checkable
= GetBool(wxT("checkable"));
72 wxString label
= GetText(wxT("label"));
73 wxString accel
= GetText(wxT("accel"));
74 wxString fullLabel
= label
;
76 fullLabel
<< wxT("\t") << accel
;
78 wxMenuItem
*mitem
= new wxMenuItem(p_menu
, id
, fullLabel
,
79 GetText(wxT("help")), checkable
);
81 #if wxCHECK_VERSION(2,3,0) || defined(__WXMSW__)
82 if (HasParam(wxT("bitmap")))
83 mitem
->SetBitmap(GetBitmap(wxT("bitmap")));
85 p_menu
->Append(mitem
);
86 mitem
->Enable(GetBool(wxT("enabled"), TRUE
));
87 if (checkable
) mitem
->Check(GetBool(wxT("checked")));
95 bool wxMenuXmlHandler::CanHandle(wxXmlNode
*node
)
97 return IsOfClass(node
, wxT("wxMenu")) ||
99 (IsOfClass(node
, wxT("wxMenuItem")) ||
100 IsOfClass(node
, wxT("break")) ||
101 IsOfClass(node
, wxT("separator")))
115 wxMenuBarXmlHandler::wxMenuBarXmlHandler() : wxXmlResourceHandler()
117 ADD_STYLE(wxMB_DOCKABLE
);
122 wxObject
*wxMenuBarXmlHandler::DoCreateResource()
124 wxMenuBar
*menubar
= new wxMenuBar(GetStyle());
125 CreateChildren(menubar
);
131 bool wxMenuBarXmlHandler::CanHandle(wxXmlNode
*node
)
133 return IsOfClass(node
, wxT("wxMenuBar"));