]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_menu.cpp
generate key events for Space/Enter in addition to the activate events, as wxMSW...
[wxWidgets.git] / src / xrc / xh_menu.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: xh_menu.cpp
3 // Purpose: XRC resource for menus and menubars
4 // Author: Vaclav Slavik
5 // Created: 2000/03/05
6 // RCS-ID: $Id$
7 // Copyright: (c) 2000 Vaclav Slavik
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifdef __GNUG__
12 #pragma implementation "xh_menu.h"
13 #endif
14
15 // For compilers that support precompilation, includes "wx.h".
16 #include "wx/wxprec.h"
17
18 #ifdef __BORLANDC__
19 #pragma hdrstop
20 #endif
21
22 #include "wx/xrc/xh_menu.h"
23 #include "wx/menu.h"
24 #include "wx/frame.h"
25
26
27 wxMenuXmlHandler::wxMenuXmlHandler() :
28 wxXmlResourceHandler(), m_insideMenu(FALSE)
29 {
30 XRC_ADD_STYLE(wxMENU_TEAROFF);
31 }
32
33 wxObject *wxMenuXmlHandler::DoCreateResource()
34 {
35 if (m_class == wxT("wxMenu"))
36 {
37 wxMenu *menu = new wxMenu(GetStyle());
38 wxString title = GetText(wxT("label"));
39 wxString help = GetText(wxT("help"));
40
41 bool oldins = m_insideMenu;
42 m_insideMenu = TRUE;
43 CreateChildren(menu, TRUE/*only this handler*/);
44 m_insideMenu = oldins;
45
46 wxMenuBar *p_bar = wxDynamicCast(m_parent, wxMenuBar);
47 if (p_bar)
48 p_bar->Append(menu, title);
49 else
50 {
51 wxMenu *p_menu = wxDynamicCast(m_parent, wxMenu);
52 if (p_menu)
53 p_menu->Append(GetID(), title, menu, help);
54 }
55
56 return menu;
57 }
58
59 else
60 {
61 wxMenu *p_menu = wxDynamicCast(m_parent, wxMenu);
62
63 if (m_class == wxT("separator"))
64 p_menu->AppendSeparator();
65 else if (m_class == wxT("break"))
66 p_menu->Break();
67 else /*wxMenuItem*/
68 {
69 int id = GetID();
70 wxString label = GetText(wxT("label"));
71 wxString accel = GetText(wxT("accel"), FALSE);
72 wxString fullLabel = label;
73 if (!accel.IsEmpty())
74 fullLabel << wxT("\t") << accel;
75
76 wxItemKind kind = wxITEM_NORMAL;
77 if (GetBool(wxT("radio")))
78 kind = wxITEM_RADIO;
79 if (GetBool(wxT("checkable")))
80 {
81 wxASSERT_MSG( kind == wxITEM_NORMAL, _T("can't have both checkable and radion button at once") );
82 kind = wxITEM_CHECK;
83 }
84
85 wxMenuItem *mitem = new wxMenuItem(p_menu, id, fullLabel,
86 GetText(wxT("help")), kind);
87
88 #if wxCHECK_VERSION(2,3,0) || defined(__WXMSW__)
89 if (HasParam(wxT("bitmap")))
90 mitem->SetBitmap(GetBitmap(wxT("bitmap"), wxART_MENU));
91 #endif
92 p_menu->Append(mitem);
93 mitem->Enable(GetBool(wxT("enabled"), TRUE));
94 if (kind == wxITEM_CHECK)
95 mitem->Check(GetBool(wxT("checked")));
96 }
97 return NULL;
98 }
99 }
100
101
102
103 bool wxMenuXmlHandler::CanHandle(wxXmlNode *node)
104 {
105 return IsOfClass(node, wxT("wxMenu")) ||
106 (m_insideMenu &&
107 (IsOfClass(node, wxT("wxMenuItem")) ||
108 IsOfClass(node, wxT("break")) ||
109 IsOfClass(node, wxT("separator")))
110 );
111 }
112
113 wxMenuBarXmlHandler::wxMenuBarXmlHandler() : wxXmlResourceHandler()
114 {
115 XRC_ADD_STYLE(wxMB_DOCKABLE);
116 }
117
118 wxObject *wxMenuBarXmlHandler::DoCreateResource()
119 {
120 wxMenuBar *menubar = new wxMenuBar(GetStyle());
121 CreateChildren(menubar);
122
123 if (m_parentAsWindow)
124 {
125 wxFrame *parentFrame = wxDynamicCast(m_parent, wxFrame);
126 if (parentFrame)
127 parentFrame->SetMenuBar(menubar);
128 }
129
130 return menubar;
131 }
132
133
134
135 bool wxMenuBarXmlHandler::CanHandle(wxXmlNode *node)
136 {
137 return IsOfClass(node, wxT("wxMenuBar"));
138 }