]>
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"
27 IMPLEMENT_DYNAMIC_CLASS(wxMenuXmlHandler
, wxXmlResourceHandler
)
29 wxMenuXmlHandler::wxMenuXmlHandler() :
30 wxXmlResourceHandler(), m_insideMenu(false)
32 XRC_ADD_STYLE(wxMENU_TEAROFF
);
35 wxObject
*wxMenuXmlHandler::DoCreateResource()
37 if (m_class
== wxT("wxMenu"))
39 wxMenu
*menu
= m_instance
? wxStaticCast(m_instance
, wxMenu
)
40 : new wxMenu(GetStyle());
42 wxString title
= GetText(wxT("label"));
43 wxString help
= GetText(wxT("help"));
45 bool oldins
= m_insideMenu
;
47 CreateChildren(menu
, true/*only this handler*/);
48 m_insideMenu
= oldins
;
50 wxMenuBar
*p_bar
= wxDynamicCast(m_parent
, wxMenuBar
);
53 p_bar
->Append(menu
, title
);
57 wxMenu
*p_menu
= wxDynamicCast(m_parent
, wxMenu
);
60 p_menu
->Append(GetID(), title
, menu
, help
);
61 if (HasParam(wxT("enabled")))
62 p_menu
->Enable(GetID(), GetBool(wxT("enabled")));
71 wxMenu
*p_menu
= wxDynamicCast(m_parent
, wxMenu
);
73 if (m_class
== wxT("separator"))
74 p_menu
->AppendSeparator();
75 else if (m_class
== wxT("break"))
80 wxString label
= GetText(wxT("label"));
81 wxString accel
= GetText(wxT("accel"), false);
82 wxString fullLabel
= label
;
84 fullLabel
<< wxT("\t") << accel
;
86 wxItemKind kind
= wxITEM_NORMAL
;
87 if (GetBool(wxT("radio")))
89 if (GetBool(wxT("checkable")))
91 wxASSERT_MSG( kind
== wxITEM_NORMAL
, _T("can't have both checkable and radio button at once") );
95 wxMenuItem
*mitem
= new wxMenuItem(p_menu
, id
, fullLabel
,
96 GetText(wxT("help")), kind
);
98 #if (!defined(__WXMSW__) && !defined(__WXPM__)) || wxUSE_OWNER_DRAWN
99 if (HasParam(wxT("bitmap")))
101 // currently only wxMSW has support for using different checked
102 // and unchecked bitmaps for menu items
104 if (HasParam(wxT("bitmap2")))
105 mitem
->SetBitmaps(GetBitmap(wxT("bitmap2"), wxART_MENU
),
106 GetBitmap(wxT("bitmap"), wxART_MENU
));
109 mitem
->SetBitmap(GetBitmap(wxT("bitmap"), wxART_MENU
));
112 p_menu
->Append(mitem
);
113 mitem
->Enable(GetBool(wxT("enabled"), true));
114 if (kind
== wxITEM_CHECK
)
115 mitem
->Check(GetBool(wxT("checked")));
123 bool wxMenuXmlHandler::CanHandle(wxXmlNode
*node
)
125 return IsOfClass(node
, wxT("wxMenu")) ||
127 (IsOfClass(node
, wxT("wxMenuItem")) ||
128 IsOfClass(node
, wxT("break")) ||
129 IsOfClass(node
, wxT("separator")))
133 IMPLEMENT_DYNAMIC_CLASS(wxMenuBarXmlHandler
, wxXmlResourceHandler
)
135 wxMenuBarXmlHandler::wxMenuBarXmlHandler() : wxXmlResourceHandler()
137 XRC_ADD_STYLE(wxMB_DOCKABLE
);
140 wxObject
*wxMenuBarXmlHandler::DoCreateResource()
142 wxMenuBar
*menubar
= new wxMenuBar(GetStyle());
143 CreateChildren(menubar
);
145 if (m_parentAsWindow
)
147 wxFrame
*parentFrame
= wxDynamicCast(m_parent
, wxFrame
);
149 parentFrame
->SetMenuBar(menubar
);
157 bool wxMenuBarXmlHandler::CanHandle(wxXmlNode
*node
)
159 return IsOfClass(node
, wxT("wxMenuBar"));
162 #endif // wxUSE_XRC && wxUSE_MENUS