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