]>
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 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 wxString label
= GetText(wxT("label"));
71 wxString accel
= GetText(wxT("accel"), FALSE
);
72 wxString fullLabel
= label
;
74 fullLabel
<< wxT("\t") << accel
;
76 wxItemKind kind
= wxITEM_NORMAL
;
77 if (GetBool(wxT("radio")))
79 if (GetBool(wxT("checkable")))
81 wxASSERT_MSG( kind
== wxITEM_NORMAL
, _T("can't have both checkable and radion button at once") );
85 wxMenuItem
*mitem
= new wxMenuItem(p_menu
, id
, fullLabel
,
86 GetText(wxT("help")), kind
);
88 #if wxCHECK_VERSION(2,3,0) || defined(__WXMSW__)
89 if (HasParam(wxT("bitmap")))
90 mitem
->SetBitmap(GetBitmap(wxT("bitmap")));
92 p_menu
->Append(mitem
);
93 mitem
->Enable(GetBool(wxT("enabled"), TRUE
));
94 if (kind
== wxITEM_CHECK
)
95 mitem
->Check(GetBool(wxT("checked")));
103 bool wxMenuXmlHandler::CanHandle(wxXmlNode
*node
)
105 return IsOfClass(node
, wxT("wxMenu")) ||
107 (IsOfClass(node
, wxT("wxMenuItem")) ||
108 IsOfClass(node
, wxT("break")) ||
109 IsOfClass(node
, wxT("separator")))
113 wxMenuBarXmlHandler::wxMenuBarXmlHandler() : wxXmlResourceHandler()
115 XRC_ADD_STYLE(wxMB_DOCKABLE
);
118 wxObject
*wxMenuBarXmlHandler::DoCreateResource()
120 wxMenuBar
*menubar
= new wxMenuBar(GetStyle());
121 CreateChildren(menubar
);
123 if (m_parentAsWindow
)
125 wxFrame
*parentFrame
= wxDynamicCast(m_parent
, wxFrame
);
127 parentFrame
->SetMenuBar(menubar
);
135 bool wxMenuBarXmlHandler::CanHandle(wxXmlNode
*node
)
137 return IsOfClass(node
, wxT("wxMenuBar"));