]> git.saurik.com Git - wxWidgets.git/blame - src/xrc/xh_menu.cpp
Font (possible) fix
[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)
b71e9003 47 {
78d14f80 48 p_bar->Append(menu, title);
b71e9003 49 }
78d14f80
VS
50 else
51 {
52 wxMenu *p_menu = wxDynamicCast(m_parent, wxMenu);
53 if (p_menu)
b71e9003 54 {
78d14f80 55 p_menu->Append(GetID(), title, menu, help);
b71e9003
JS
56 if (HasParam(wxT("enabled")))
57 p_menu->Enable(GetID(), GetBool(wxT("enabled")));
58 }
78d14f80
VS
59 }
60
61 return menu;
62 }
63
64 else
65 {
66 wxMenu *p_menu = wxDynamicCast(m_parent, wxMenu);
f80ea77b 67
78d14f80
VS
68 if (m_class == wxT("separator"))
69 p_menu->AppendSeparator();
70 else if (m_class == wxT("break"))
71 p_menu->Break();
72 else /*wxMenuItem*/
f80ea77b 73 {
78d14f80 74 int id = GetID();
78d14f80 75 wxString label = GetText(wxT("label"));
f80ea77b 76 wxString accel = GetText(wxT("accel"), false);
78d14f80
VS
77 wxString fullLabel = label;
78 if (!accel.IsEmpty())
79 fullLabel << wxT("\t") << accel;
80
65812490
VS
81 wxItemKind kind = wxITEM_NORMAL;
82 if (GetBool(wxT("radio")))
83 kind = wxITEM_RADIO;
84 if (GetBool(wxT("checkable")))
85 {
86 wxASSERT_MSG( kind == wxITEM_NORMAL, _T("can't have both checkable and radion button at once") );
87 kind = wxITEM_CHECK;
88 }
89
78d14f80 90 wxMenuItem *mitem = new wxMenuItem(p_menu, id, fullLabel,
65812490 91 GetText(wxT("help")), kind);
f80ea77b 92
200ab0bf 93#if (!defined(__WXMSW__) && !defined(__WXPM__)) || wxUSE_OWNER_DRAWN
84969af7
JS
94 if (HasParam(wxT("bitmap")))
95 mitem->SetBitmap(GetBitmap(wxT("bitmap"), wxART_MENU));
78d14f80
VS
96#endif
97 p_menu->Append(mitem);
f80ea77b 98 mitem->Enable(GetBool(wxT("enabled"), true));
65812490
VS
99 if (kind == wxITEM_CHECK)
100 mitem->Check(GetBool(wxT("checked")));
78d14f80
VS
101 }
102 return NULL;
103 }
104}
105
106
107
108bool wxMenuXmlHandler::CanHandle(wxXmlNode *node)
109{
110 return IsOfClass(node, wxT("wxMenu")) ||
f80ea77b 111 (m_insideMenu &&
78d14f80
VS
112 (IsOfClass(node, wxT("wxMenuItem")) ||
113 IsOfClass(node, wxT("break")) ||
114 IsOfClass(node, wxT("separator")))
115 );
116}
117
854e189f
VS
118IMPLEMENT_DYNAMIC_CLASS(wxMenuBarXmlHandler, wxXmlResourceHandler)
119
78d14f80
VS
120wxMenuBarXmlHandler::wxMenuBarXmlHandler() : wxXmlResourceHandler()
121{
544fee32 122 XRC_ADD_STYLE(wxMB_DOCKABLE);
78d14f80
VS
123}
124
78d14f80
VS
125wxObject *wxMenuBarXmlHandler::DoCreateResource()
126{
127 wxMenuBar *menubar = new wxMenuBar(GetStyle());
128 CreateChildren(menubar);
f2588180
VS
129
130 if (m_parentAsWindow)
131 {
132 wxFrame *parentFrame = wxDynamicCast(m_parent, wxFrame);
133 if (parentFrame)
134 parentFrame->SetMenuBar(menubar);
135 }
136
78d14f80
VS
137 return menubar;
138}
139
140
141
142bool wxMenuBarXmlHandler::CanHandle(wxXmlNode *node)
143{
144 return IsOfClass(node, wxT("wxMenuBar"));
145}
a1e4ec87 146
621be1ec 147#endif // wxUSE_XRC