]>
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
)
94 wxLogWarning(_("XRC syntax error: a menu item can't have "
95 "both \"radio\" and \"checkable\" "
96 "properties, ignoring the former."));
102 wxMenuItem
*mitem
= new wxMenuItem(p_menu
, id
, fullLabel
,
103 GetText(wxT("help")), kind
);
105 #if (!defined(__WXMSW__) && !defined(__WXPM__)) || wxUSE_OWNER_DRAWN
106 if (HasParam(wxT("bitmap")))
108 // currently only wxMSW has support for using different checked
109 // and unchecked bitmaps for menu items
111 if (HasParam(wxT("bitmap2")))
112 mitem
->SetBitmaps(GetBitmap(wxT("bitmap2"), wxART_MENU
),
113 GetBitmap(wxT("bitmap"), wxART_MENU
));
116 mitem
->SetBitmap(GetBitmap(wxT("bitmap"), wxART_MENU
));
119 p_menu
->Append(mitem
);
120 mitem
->Enable(GetBool(wxT("enabled"), true));
121 if (kind
== wxITEM_CHECK
)
122 mitem
->Check(GetBool(wxT("checked")));
130 bool wxMenuXmlHandler::CanHandle(wxXmlNode
*node
)
132 return IsOfClass(node
, wxT("wxMenu")) ||
134 (IsOfClass(node
, wxT("wxMenuItem")) ||
135 IsOfClass(node
, wxT("break")) ||
136 IsOfClass(node
, wxT("separator")))
140 IMPLEMENT_DYNAMIC_CLASS(wxMenuBarXmlHandler
, wxXmlResourceHandler
)
142 wxMenuBarXmlHandler::wxMenuBarXmlHandler() : wxXmlResourceHandler()
144 XRC_ADD_STYLE(wxMB_DOCKABLE
);
147 wxObject
*wxMenuBarXmlHandler::DoCreateResource()
149 wxMenuBar
*menubar
= new wxMenuBar(GetStyle());
150 CreateChildren(menubar
);
152 if (m_parentAsWindow
)
154 wxFrame
*parentFrame
= wxDynamicCast(m_parent
, wxFrame
);
156 parentFrame
->SetMenuBar(menubar
);
164 bool wxMenuBarXmlHandler::CanHandle(wxXmlNode
*node
)
166 return IsOfClass(node
, wxT("wxMenuBar"));
169 #endif // wxUSE_XRC && wxUSE_MENUS