]> git.saurik.com Git - wxWidgets.git/blame - src/xrc/xh_menu.cpp
Always use active wxTranslations instance via wxLocale.
[wxWidgets.git] / src / xrc / xh_menu.cpp
CommitLineData
78d14f80 1/////////////////////////////////////////////////////////////////////////////
76b49cf4 2// Name: src/xrc/xh_menu.cpp
b5d6954b 3// Purpose: XRC resource for menus and menubars
78d14f80
VS
4// Author: Vaclav Slavik
5// Created: 2000/03/05
6// RCS-ID: $Id$
7// Copyright: (c) 2000 Vaclav Slavik
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
f80ea77b 10
78d14f80
VS
11// For compilers that support precompilation, includes "wx.h".
12#include "wx/wxprec.h"
13
14#ifdef __BORLANDC__
15 #pragma hdrstop
16#endif
17
dd47af27 18#if wxUSE_XRC && wxUSE_MENUS
a1e4ec87 19
78d14f80 20#include "wx/xrc/xh_menu.h"
76b49cf4
WS
21
22#ifndef WX_PRECOMP
23 #include "wx/frame.h"
b935c45d 24 #include "wx/log.h"
3b3dc801 25 #include "wx/menu.h"
76b49cf4
WS
26#endif
27
854e189f 28IMPLEMENT_DYNAMIC_CLASS(wxMenuXmlHandler, wxXmlResourceHandler)
78d14f80 29
f80ea77b
WS
30wxMenuXmlHandler::wxMenuXmlHandler() :
31 wxXmlResourceHandler(), m_insideMenu(false)
78d14f80 32{
544fee32 33 XRC_ADD_STYLE(wxMENU_TEAROFF);
78d14f80
VS
34}
35
78d14f80
VS
36wxObject *wxMenuXmlHandler::DoCreateResource()
37{
38 if (m_class == wxT("wxMenu"))
39 {
c01d5de8
VZ
40 wxMenu *menu = m_instance ? wxStaticCast(m_instance, wxMenu)
41 : new wxMenu(GetStyle());
42
78d14f80
VS
43 wxString title = GetText(wxT("label"));
44 wxString help = GetText(wxT("help"));
f80ea77b 45
78d14f80 46 bool oldins = m_insideMenu;
f80ea77b
WS
47 m_insideMenu = true;
48 CreateChildren(menu, true/*only this handler*/);
78d14f80
VS
49 m_insideMenu = oldins;
50
51 wxMenuBar *p_bar = wxDynamicCast(m_parent, wxMenuBar);
52 if (p_bar)
b71e9003 53 {
78d14f80 54 p_bar->Append(menu, title);
b71e9003 55 }
78d14f80
VS
56 else
57 {
58 wxMenu *p_menu = wxDynamicCast(m_parent, wxMenu);
59 if (p_menu)
b71e9003 60 {
78d14f80 61 p_menu->Append(GetID(), title, menu, help);
b71e9003
JS
62 if (HasParam(wxT("enabled")))
63 p_menu->Enable(GetID(), GetBool(wxT("enabled")));
64 }
78d14f80
VS
65 }
66
67 return menu;
68 }
69
70 else
71 {
72 wxMenu *p_menu = wxDynamicCast(m_parent, wxMenu);
f80ea77b 73
78d14f80
VS
74 if (m_class == wxT("separator"))
75 p_menu->AppendSeparator();
76 else if (m_class == wxT("break"))
77 p_menu->Break();
78 else /*wxMenuItem*/
f80ea77b 79 {
78d14f80 80 int id = GetID();
78d14f80 81 wxString label = GetText(wxT("label"));
f80ea77b 82 wxString accel = GetText(wxT("accel"), false);
78d14f80 83 wxString fullLabel = label;
76b49cf4 84 if (!accel.empty())
78d14f80
VS
85 fullLabel << wxT("\t") << accel;
86
65812490
VS
87 wxItemKind kind = wxITEM_NORMAL;
88 if (GetBool(wxT("radio")))
89 kind = wxITEM_RADIO;
90 if (GetBool(wxT("checkable")))
91 {
07acc3cc
VZ
92 if ( kind != wxITEM_NORMAL )
93 {
819559b2
VS
94 ReportParamError
95 (
96 "checkable",
97 "menu item can't have both <radio> and <checkable> properties"
98 );
07acc3cc
VZ
99 }
100
65812490
VS
101 kind = wxITEM_CHECK;
102 }
103
78d14f80 104 wxMenuItem *mitem = new wxMenuItem(p_menu, id, fullLabel,
65812490 105 GetText(wxT("help")), kind);
f80ea77b 106
200ab0bf 107#if (!defined(__WXMSW__) && !defined(__WXPM__)) || wxUSE_OWNER_DRAWN
84969af7 108 if (HasParam(wxT("bitmap")))
d2ffaf16
VZ
109 {
110 // currently only wxMSW has support for using different checked
111 // and unchecked bitmaps for menu items
112#ifdef __WXMSW__
113 if (HasParam(wxT("bitmap2")))
114 mitem->SetBitmaps(GetBitmap(wxT("bitmap2"), wxART_MENU),
115 GetBitmap(wxT("bitmap"), wxART_MENU));
116 else
117#endif // __WXMSW__
118 mitem->SetBitmap(GetBitmap(wxT("bitmap"), wxART_MENU));
119 }
78d14f80
VS
120#endif
121 p_menu->Append(mitem);
f80ea77b 122 mitem->Enable(GetBool(wxT("enabled"), true));
65812490
VS
123 if (kind == wxITEM_CHECK)
124 mitem->Check(GetBool(wxT("checked")));
78d14f80
VS
125 }
126 return NULL;
127 }
128}
129
130
131
132bool wxMenuXmlHandler::CanHandle(wxXmlNode *node)
133{
134 return IsOfClass(node, wxT("wxMenu")) ||
f80ea77b 135 (m_insideMenu &&
78d14f80
VS
136 (IsOfClass(node, wxT("wxMenuItem")) ||
137 IsOfClass(node, wxT("break")) ||
138 IsOfClass(node, wxT("separator")))
139 );
140}
141
854e189f
VS
142IMPLEMENT_DYNAMIC_CLASS(wxMenuBarXmlHandler, wxXmlResourceHandler)
143
78d14f80
VS
144wxMenuBarXmlHandler::wxMenuBarXmlHandler() : wxXmlResourceHandler()
145{
544fee32 146 XRC_ADD_STYLE(wxMB_DOCKABLE);
78d14f80
VS
147}
148
78d14f80
VS
149wxObject *wxMenuBarXmlHandler::DoCreateResource()
150{
10ff1452
VS
151 wxMenuBar *menubar = NULL;
152
153 const int style = GetStyle();
154 wxASSERT_MSG(!style || !m_instance,
155 "cannot use <style> with pre-created menubar");
156
157 if ( m_instance )
158 menubar = wxDynamicCast(m_instance, wxMenuBar);
159 if ( !menubar )
160 menubar = new wxMenuBar(style);
161
78d14f80 162 CreateChildren(menubar);
f2588180
VS
163
164 if (m_parentAsWindow)
165 {
166 wxFrame *parentFrame = wxDynamicCast(m_parent, wxFrame);
167 if (parentFrame)
168 parentFrame->SetMenuBar(menubar);
169 }
170
78d14f80
VS
171 return menubar;
172}
173
174
175
176bool wxMenuBarXmlHandler::CanHandle(wxXmlNode *node)
177{
178 return IsOfClass(node, wxT("wxMenuBar"));
179}
a1e4ec87 180
dd47af27 181#endif // wxUSE_XRC && wxUSE_MENUS