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