]>
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 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
20 #include "wx/xrc/xh_menu.h"
24 IMPLEMENT_DYNAMIC_CLASS(wxMenuXmlHandler
, wxXmlResourceHandler
)
26 wxMenuXmlHandler::wxMenuXmlHandler() :
27 wxXmlResourceHandler(), m_insideMenu(false)
29 XRC_ADD_STYLE(wxMENU_TEAROFF
);
32 wxObject
*wxMenuXmlHandler::DoCreateResource()
34 if (m_class
== wxT("wxMenu"))
36 wxMenu
*menu
= new wxMenu(GetStyle());
37 wxString title
= GetText(wxT("label"));
38 wxString help
= GetText(wxT("help"));
40 bool oldins
= m_insideMenu
;
42 CreateChildren(menu
, true/*only this handler*/);
43 m_insideMenu
= oldins
;
45 wxMenuBar
*p_bar
= wxDynamicCast(m_parent
, wxMenuBar
);
47 p_bar
->Append(menu
, title
);
50 wxMenu
*p_menu
= wxDynamicCast(m_parent
, wxMenu
);
52 p_menu
->Append(GetID(), title
, menu
, help
);
60 wxMenu
*p_menu
= wxDynamicCast(m_parent
, wxMenu
);
62 if (m_class
== wxT("separator"))
63 p_menu
->AppendSeparator();
64 else if (m_class
== wxT("break"))
69 wxString label
= GetText(wxT("label"));
70 wxString accel
= GetText(wxT("accel"), false);
71 wxString fullLabel
= label
;
73 fullLabel
<< wxT("\t") << accel
;
75 wxItemKind kind
= wxITEM_NORMAL
;
76 if (GetBool(wxT("radio")))
78 if (GetBool(wxT("checkable")))
80 wxASSERT_MSG( kind
== wxITEM_NORMAL
, _T("can't have both checkable and radion button at once") );
84 wxMenuItem
*mitem
= new wxMenuItem(p_menu
, id
, fullLabel
,
85 GetText(wxT("help")), kind
);
87 #if (!defined(__WXMSW__) && !defined(__WXPM__)) || wxUSE_OWNER_DRAWN
88 if (HasParam(wxT("bitmap")))
89 mitem
->SetBitmap(GetBitmap(wxT("bitmap"), wxART_MENU
));
91 p_menu
->Append(mitem
);
92 mitem
->Enable(GetBool(wxT("enabled"), true));
93 if (kind
== wxITEM_CHECK
)
94 mitem
->Check(GetBool(wxT("checked")));
102 bool wxMenuXmlHandler::CanHandle(wxXmlNode
*node
)
104 return IsOfClass(node
, wxT("wxMenu")) ||
106 (IsOfClass(node
, wxT("wxMenuItem")) ||
107 IsOfClass(node
, wxT("break")) ||
108 IsOfClass(node
, wxT("separator")))
112 IMPLEMENT_DYNAMIC_CLASS(wxMenuBarXmlHandler
, wxXmlResourceHandler
)
114 wxMenuBarXmlHandler::wxMenuBarXmlHandler() : wxXmlResourceHandler()
116 XRC_ADD_STYLE(wxMB_DOCKABLE
);
119 wxObject
*wxMenuBarXmlHandler::DoCreateResource()
121 wxMenuBar
*menubar
= new wxMenuBar(GetStyle());
122 CreateChildren(menubar
);
124 if (m_parentAsWindow
)
126 wxFrame
*parentFrame
= wxDynamicCast(m_parent
, wxFrame
);
128 parentFrame
->SetMenuBar(menubar
);
136 bool wxMenuBarXmlHandler::CanHandle(wxXmlNode
*node
)
138 return IsOfClass(node
, wxT("wxMenuBar"));