]>
git.saurik.com Git - wxWidgets.git/blob - contrib/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"
27 wxMenuXmlHandler::wxMenuXmlHandler() :
28 wxXmlResourceHandler(), m_insideMenu(FALSE
)
30 XRC_ADD_STYLE(wxMENU_TEAROFF
);
33 wxObject
*wxMenuXmlHandler::DoCreateResource()
35 if (m_class
== wxT("wxMenu"))
37 wxMenu
*menu
= new wxMenu(GetStyle());
38 wxString title
= GetText(wxT("label"));
39 wxString help
= GetText(wxT("help"));
41 bool oldins
= m_insideMenu
;
43 CreateChildren(menu
, TRUE
/*only this handler*/);
44 m_insideMenu
= oldins
;
46 wxMenuBar
*p_bar
= wxDynamicCast(m_parent
, wxMenuBar
);
48 p_bar
->Append(menu
, title
);
51 wxMenu
*p_menu
= wxDynamicCast(m_parent
, wxMenu
);
53 p_menu
->Append(GetID(), title
, menu
, help
);
61 wxMenu
*p_menu
= wxDynamicCast(m_parent
, wxMenu
);
63 if (m_class
== wxT("separator"))
64 p_menu
->AppendSeparator();
65 else if (m_class
== wxT("break"))
70 bool checkable
= GetBool(wxT("checkable"));
71 wxString label
= GetText(wxT("label"));
72 wxString accel
= GetText(wxT("accel"));
73 wxString fullLabel
= label
;
75 fullLabel
<< wxT("\t") << accel
;
77 wxMenuItem
*mitem
= new wxMenuItem(p_menu
, id
, fullLabel
,
78 GetText(wxT("help")), checkable
);
80 #if wxCHECK_VERSION(2,3,0) || defined(__WXMSW__)
81 if (HasParam(wxT("bitmap")))
82 mitem
->SetBitmap(GetBitmap(wxT("bitmap")));
84 p_menu
->Append(mitem
);
85 mitem
->Enable(GetBool(wxT("enabled"), TRUE
));
86 if (checkable
) mitem
->Check(GetBool(wxT("checked")));
94 bool wxMenuXmlHandler::CanHandle(wxXmlNode
*node
)
96 return IsOfClass(node
, wxT("wxMenu")) ||
98 (IsOfClass(node
, wxT("wxMenuItem")) ||
99 IsOfClass(node
, wxT("break")) ||
100 IsOfClass(node
, wxT("separator")))
104 wxMenuBarXmlHandler::wxMenuBarXmlHandler() : wxXmlResourceHandler()
106 XRC_ADD_STYLE(wxMB_DOCKABLE
);
109 wxObject
*wxMenuBarXmlHandler::DoCreateResource()
111 wxMenuBar
*menubar
= new wxMenuBar(GetStyle());
112 CreateChildren(menubar
);
114 if (m_parentAsWindow
)
116 wxFrame
*parentFrame
= wxDynamicCast(m_parent
, wxFrame
);
118 parentFrame
->SetMenuBar(menubar
);
126 bool wxMenuBarXmlHandler::CanHandle(wxXmlNode
*node
)
128 return IsOfClass(node
, wxT("wxMenuBar"));