]>
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 IMPLEMENT_DYNAMIC_CLASS(wxMenuXmlHandler
, wxXmlResourceHandler
)
28 wxMenuXmlHandler::wxMenuXmlHandler() :
29 wxXmlResourceHandler(), m_insideMenu(FALSE
)
31 XRC_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 wxString label
= GetText(wxT("label"));
72 wxString accel
= GetText(wxT("accel"), FALSE
);
73 wxString fullLabel
= label
;
75 fullLabel
<< wxT("\t") << accel
;
77 wxItemKind kind
= wxITEM_NORMAL
;
78 if (GetBool(wxT("radio")))
80 if (GetBool(wxT("checkable")))
82 wxASSERT_MSG( kind
== wxITEM_NORMAL
, _T("can't have both checkable and radion button at once") );
86 wxMenuItem
*mitem
= new wxMenuItem(p_menu
, id
, fullLabel
,
87 GetText(wxT("help")), kind
);
89 #if wxCHECK_VERSION(2,3,0) || (defined(__WXMSW__) && wxUSE_OWNER_DRAWN)
90 if (HasParam(wxT("bitmap")))
91 mitem
->SetBitmap(GetBitmap(wxT("bitmap"), wxART_MENU
));
93 p_menu
->Append(mitem
);
94 mitem
->Enable(GetBool(wxT("enabled"), TRUE
));
95 if (kind
== wxITEM_CHECK
)
96 mitem
->Check(GetBool(wxT("checked")));
104 bool wxMenuXmlHandler::CanHandle(wxXmlNode
*node
)
106 return IsOfClass(node
, wxT("wxMenu")) ||
108 (IsOfClass(node
, wxT("wxMenuItem")) ||
109 IsOfClass(node
, wxT("break")) ||
110 IsOfClass(node
, wxT("separator")))
114 IMPLEMENT_DYNAMIC_CLASS(wxMenuBarXmlHandler
, wxXmlResourceHandler
)
116 wxMenuBarXmlHandler::wxMenuBarXmlHandler() : wxXmlResourceHandler()
118 XRC_ADD_STYLE(wxMB_DOCKABLE
);
121 wxObject
*wxMenuBarXmlHandler::DoCreateResource()
123 wxMenuBar
*menubar
= new wxMenuBar(GetStyle());
124 CreateChildren(menubar
);
126 if (m_parentAsWindow
)
128 wxFrame
*parentFrame
= wxDynamicCast(m_parent
, wxFrame
);
130 parentFrame
->SetMenuBar(menubar
);
138 bool wxMenuBarXmlHandler::CanHandle(wxXmlNode
*node
)
140 return IsOfClass(node
, wxT("wxMenuBar"));