]>
git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_menu.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/xrc/xh_menu.cpp
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"
18 #if wxUSE_XRC && wxUSE_MENUS
20 #include "wx/xrc/xh_menu.h"
28 IMPLEMENT_DYNAMIC_CLASS(wxMenuXmlHandler
, wxXmlResourceHandler
)
30 wxMenuXmlHandler::wxMenuXmlHandler() :
31 wxXmlResourceHandler(), m_insideMenu(false)
33 XRC_ADD_STYLE(wxMENU_TEAROFF
);
36 wxObject
*wxMenuXmlHandler::DoCreateResource()
38 if (m_class
== wxT("wxMenu"))
40 wxMenu
*menu
= m_instance
? wxStaticCast(m_instance
, wxMenu
)
41 : new wxMenu(GetStyle());
43 wxString title
= GetText(wxT("label"));
44 wxString help
= GetText(wxT("help"));
46 bool oldins
= m_insideMenu
;
48 CreateChildren(menu
, true/*only this handler*/);
49 m_insideMenu
= oldins
;
51 wxMenuBar
*p_bar
= wxDynamicCast(m_parent
, wxMenuBar
);
54 p_bar
->Append(menu
, title
);
58 wxMenu
*p_menu
= wxDynamicCast(m_parent
, wxMenu
);
61 p_menu
->Append(GetID(), title
, menu
, help
);
62 if (HasParam(wxT("enabled")))
63 p_menu
->Enable(GetID(), GetBool(wxT("enabled")));
72 wxMenu
*p_menu
= wxDynamicCast(m_parent
, wxMenu
);
74 if (m_class
== wxT("separator"))
75 p_menu
->AppendSeparator();
76 else if (m_class
== wxT("break"))
81 wxString label
= GetText(wxT("label"));
82 wxString accel
= GetText(wxT("accel"), false);
83 wxString fullLabel
= label
;
85 fullLabel
<< wxT("\t") << accel
;
87 wxItemKind kind
= wxITEM_NORMAL
;
88 if (GetBool(wxT("radio")))
90 if (GetBool(wxT("checkable")))
92 if ( kind
!= wxITEM_NORMAL
)
97 "menu item can't have both <radio> and <checkable> properties"
104 wxMenuItem
*mitem
= new wxMenuItem(p_menu
, id
, fullLabel
,
105 GetText(wxT("help")), kind
);
107 #if (!defined(__WXMSW__) && !defined(__WXPM__)) || wxUSE_OWNER_DRAWN
108 if (HasParam(wxT("bitmap")))
110 // currently only wxMSW has support for using different checked
111 // and unchecked bitmaps for menu items
113 if (HasParam(wxT("bitmap2")))
114 mitem
->SetBitmaps(GetBitmap(wxT("bitmap2"), wxART_MENU
),
115 GetBitmap(wxT("bitmap"), wxART_MENU
));
118 mitem
->SetBitmap(GetBitmap(wxT("bitmap"), wxART_MENU
));
121 p_menu
->Append(mitem
);
122 mitem
->Enable(GetBool(wxT("enabled"), true));
123 if (kind
== wxITEM_CHECK
)
124 mitem
->Check(GetBool(wxT("checked")));
132 bool wxMenuXmlHandler::CanHandle(wxXmlNode
*node
)
134 return IsOfClass(node
, wxT("wxMenu")) ||
136 (IsOfClass(node
, wxT("wxMenuItem")) ||
137 IsOfClass(node
, wxT("break")) ||
138 IsOfClass(node
, wxT("separator")))
142 IMPLEMENT_DYNAMIC_CLASS(wxMenuBarXmlHandler
, wxXmlResourceHandler
)
144 wxMenuBarXmlHandler::wxMenuBarXmlHandler() : wxXmlResourceHandler()
146 XRC_ADD_STYLE(wxMB_DOCKABLE
);
149 wxObject
*wxMenuBarXmlHandler::DoCreateResource()
151 wxMenuBar
*menubar
= NULL
;
153 const int style
= GetStyle();
154 wxASSERT_MSG(!style
|| !m_instance
,
155 "cannot use <style> with pre-created menubar");
158 menubar
= wxDynamicCast(m_instance
, wxMenuBar
);
160 menubar
= new wxMenuBar(style
);
162 CreateChildren(menubar
);
164 if (m_parentAsWindow
)
166 wxFrame
*parentFrame
= wxDynamicCast(m_parent
, wxFrame
);
168 parentFrame
->SetMenuBar(menubar
);
176 bool wxMenuBarXmlHandler::CanHandle(wxXmlNode
*node
)
178 return IsOfClass(node
, wxT("wxMenuBar"));
181 #endif // wxUSE_XRC && wxUSE_MENUS