]>
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"
27 wxMenuXmlHandler::wxMenuXmlHandler() :
28 wxXmlResourceHandler(), m_insideMenu(FALSE
)
30 ADD_STYLE(wxMENU_TEAROFF
);
35 wxObject
*wxMenuXmlHandler::DoCreateResource()
37 if (m_class
== wxT("wxMenu"))
39 wxMenu
*menu
= new wxMenu(GetStyle());
40 wxString title
= GetText(wxT("label"));
41 wxString help
= GetText(wxT("help"));
43 bool oldins
= m_insideMenu
;
45 CreateChildren(menu
, TRUE
/*only this handler*/);
46 m_insideMenu
= oldins
;
48 wxMenuBar
*p_bar
= wxDynamicCast(m_parent
, wxMenuBar
);
50 p_bar
->Append(menu
, title
);
53 wxMenu
*p_menu
= wxDynamicCast(m_parent
, wxMenu
);
55 p_menu
->Append(GetID(), title
, menu
, help
);
63 wxMenu
*p_menu
= wxDynamicCast(m_parent
, wxMenu
);
65 if (m_class
== wxT("separator"))
66 p_menu
->AppendSeparator();
67 else if (m_class
== wxT("break"))
72 bool checkable
= GetBool(wxT("checkable"));
73 wxString label
= GetText(wxT("label"));
74 wxString accel
= GetText(wxT("accel"));
75 wxString fullLabel
= label
;
77 fullLabel
<< wxT("\t") << accel
;
79 wxMenuItem
*mitem
= new wxMenuItem(p_menu
, id
, fullLabel
,
80 GetText(wxT("help")), checkable
);
82 #if wxCHECK_VERSION(2,3,0) || defined(__WXMSW__)
83 if (HasParam(wxT("bitmap")))
84 mitem
->SetBitmap(GetBitmap(wxT("bitmap")));
86 p_menu
->Append(mitem
);
87 mitem
->Enable(GetBool(wxT("enabled"), TRUE
));
88 if (checkable
) mitem
->Check(GetBool(wxT("checked")));
96 bool wxMenuXmlHandler::CanHandle(wxXmlNode
*node
)
98 return IsOfClass(node
, wxT("wxMenu")) ||
100 (IsOfClass(node
, wxT("wxMenuItem")) ||
101 IsOfClass(node
, wxT("break")) ||
102 IsOfClass(node
, wxT("separator")))
109 wxMenuBarXmlHandler::wxMenuBarXmlHandler() : wxXmlResourceHandler()
111 ADD_STYLE(wxMB_DOCKABLE
);
116 wxObject
*wxMenuBarXmlHandler::DoCreateResource()
118 wxMenuBar
*menubar
= new wxMenuBar(GetStyle());
119 CreateChildren(menubar
);
121 if (m_parentAsWindow
)
123 wxFrame
*parentFrame
= wxDynamicCast(m_parent
, wxFrame
);
125 parentFrame
->SetMenuBar(menubar
);
133 bool wxMenuBarXmlHandler::CanHandle(wxXmlNode
*node
)
135 return IsOfClass(node
, wxT("wxMenuBar"));