]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_menu.cpp
Use wxMBConvUTF8 when G_FILENAME_ENCODING is UTF-8, and set
[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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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 #if wxUSE_XRC
23
24 #include "wx/xrc/xh_menu.h"
25 #include "wx/menu.h"
26 #include "wx/frame.h"
27
28 IMPLEMENT_DYNAMIC_CLASS(wxMenuXmlHandler, wxXmlResourceHandler)
29
30 wxMenuXmlHandler::wxMenuXmlHandler() :
31 wxXmlResourceHandler(), m_insideMenu(false)
32 {
33 XRC_ADD_STYLE(wxMENU_TEAROFF);
34 }
35
36 wxObject *wxMenuXmlHandler::DoCreateResource()
37 {
38 if (m_class == wxT("wxMenu"))
39 {
40 wxMenu *menu = new wxMenu(GetStyle());
41 wxString title = GetText(wxT("label"));
42 wxString help = GetText(wxT("help"));
43
44 bool oldins = m_insideMenu;
45 m_insideMenu = true;
46 CreateChildren(menu, true/*only this handler*/);
47 m_insideMenu = oldins;
48
49 wxMenuBar *p_bar = wxDynamicCast(m_parent, wxMenuBar);
50 if (p_bar)
51 p_bar->Append(menu, title);
52 else
53 {
54 wxMenu *p_menu = wxDynamicCast(m_parent, wxMenu);
55 if (p_menu)
56 p_menu->Append(GetID(), title, menu, help);
57 }
58
59 return menu;
60 }
61
62 else
63 {
64 wxMenu *p_menu = wxDynamicCast(m_parent, wxMenu);
65
66 if (m_class == wxT("separator"))
67 p_menu->AppendSeparator();
68 else if (m_class == wxT("break"))
69 p_menu->Break();
70 else /*wxMenuItem*/
71 {
72 int id = GetID();
73 wxString label = GetText(wxT("label"));
74 wxString accel = GetText(wxT("accel"), false);
75 wxString fullLabel = label;
76 if (!accel.IsEmpty())
77 fullLabel << wxT("\t") << accel;
78
79 wxItemKind kind = wxITEM_NORMAL;
80 if (GetBool(wxT("radio")))
81 kind = wxITEM_RADIO;
82 if (GetBool(wxT("checkable")))
83 {
84 wxASSERT_MSG( kind == wxITEM_NORMAL, _T("can't have both checkable and radion button at once") );
85 kind = wxITEM_CHECK;
86 }
87
88 wxMenuItem *mitem = new wxMenuItem(p_menu, id, fullLabel,
89 GetText(wxT("help")), kind);
90
91 #if (!defined(__WXMSW__) && !defined(__WXPM__)) || wxUSE_OWNER_DRAWN
92 if (HasParam(wxT("bitmap")))
93 mitem->SetBitmap(GetBitmap(wxT("bitmap"), wxART_MENU));
94 #endif
95 p_menu->Append(mitem);
96 mitem->Enable(GetBool(wxT("enabled"), true));
97 if (kind == wxITEM_CHECK)
98 mitem->Check(GetBool(wxT("checked")));
99 }
100 return NULL;
101 }
102 }
103
104
105
106 bool wxMenuXmlHandler::CanHandle(wxXmlNode *node)
107 {
108 return IsOfClass(node, wxT("wxMenu")) ||
109 (m_insideMenu &&
110 (IsOfClass(node, wxT("wxMenuItem")) ||
111 IsOfClass(node, wxT("break")) ||
112 IsOfClass(node, wxT("separator")))
113 );
114 }
115
116 IMPLEMENT_DYNAMIC_CLASS(wxMenuBarXmlHandler, wxXmlResourceHandler)
117
118 wxMenuBarXmlHandler::wxMenuBarXmlHandler() : wxXmlResourceHandler()
119 {
120 XRC_ADD_STYLE(wxMB_DOCKABLE);
121 }
122
123 wxObject *wxMenuBarXmlHandler::DoCreateResource()
124 {
125 wxMenuBar *menubar = new wxMenuBar(GetStyle());
126 CreateChildren(menubar);
127
128 if (m_parentAsWindow)
129 {
130 wxFrame *parentFrame = wxDynamicCast(m_parent, wxFrame);
131 if (parentFrame)
132 parentFrame->SetMenuBar(menubar);
133 }
134
135 return menubar;
136 }
137
138
139
140 bool wxMenuBarXmlHandler::CanHandle(wxXmlNode *node)
141 {
142 return IsOfClass(node, wxT("wxMenuBar"));
143 }
144
145 #endif // wxUSE_XRC