]> git.saurik.com Git - wxWidgets.git/blame - src/xrc/xh_menu.cpp
warning about standard controls
[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
c575e45a 11#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
78d14f80
VS
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
621be1ec 22#if wxUSE_XRC
a1e4ec87 23
78d14f80
VS
24#include "wx/xrc/xh_menu.h"
25#include "wx/menu.h"
f2588180 26#include "wx/frame.h"
78d14f80 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)
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);
f80ea77b 65
78d14f80
VS
66 if (m_class == wxT("separator"))
67 p_menu->AppendSeparator();
68 else if (m_class == wxT("break"))
69 p_menu->Break();
70 else /*wxMenuItem*/
f80ea77b 71 {
78d14f80 72 int id = GetID();
78d14f80 73 wxString label = GetText(wxT("label"));
f80ea77b 74 wxString accel = GetText(wxT("accel"), false);
78d14f80
VS
75 wxString fullLabel = label;
76 if (!accel.IsEmpty())
77 fullLabel << wxT("\t") << accel;
78
65812490
VS
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
78d14f80 88 wxMenuItem *mitem = new wxMenuItem(p_menu, id, fullLabel,
65812490 89 GetText(wxT("help")), kind);
f80ea77b 90
200ab0bf 91#if (!defined(__WXMSW__) && !defined(__WXPM__)) || wxUSE_OWNER_DRAWN
84969af7
JS
92 if (HasParam(wxT("bitmap")))
93 mitem->SetBitmap(GetBitmap(wxT("bitmap"), wxART_MENU));
78d14f80
VS
94#endif
95 p_menu->Append(mitem);
f80ea77b 96 mitem->Enable(GetBool(wxT("enabled"), true));
65812490
VS
97 if (kind == wxITEM_CHECK)
98 mitem->Check(GetBool(wxT("checked")));
78d14f80
VS
99 }
100 return NULL;
101 }
102}
103
104
105
106bool wxMenuXmlHandler::CanHandle(wxXmlNode *node)
107{
108 return IsOfClass(node, wxT("wxMenu")) ||
f80ea77b 109 (m_insideMenu &&
78d14f80
VS
110 (IsOfClass(node, wxT("wxMenuItem")) ||
111 IsOfClass(node, wxT("break")) ||
112 IsOfClass(node, wxT("separator")))
113 );
114}
115
854e189f
VS
116IMPLEMENT_DYNAMIC_CLASS(wxMenuBarXmlHandler, wxXmlResourceHandler)
117
78d14f80
VS
118wxMenuBarXmlHandler::wxMenuBarXmlHandler() : wxXmlResourceHandler()
119{
544fee32 120 XRC_ADD_STYLE(wxMB_DOCKABLE);
78d14f80
VS
121}
122
78d14f80
VS
123wxObject *wxMenuBarXmlHandler::DoCreateResource()
124{
125 wxMenuBar *menubar = new wxMenuBar(GetStyle());
126 CreateChildren(menubar);
f2588180
VS
127
128 if (m_parentAsWindow)
129 {
130 wxFrame *parentFrame = wxDynamicCast(m_parent, wxFrame);
131 if (parentFrame)
132 parentFrame->SetMenuBar(menubar);
133 }
134
78d14f80
VS
135 return menubar;
136}
137
138
139
140bool wxMenuBarXmlHandler::CanHandle(wxXmlNode *node)
141{
142 return IsOfClass(node, wxT("wxMenuBar"));
143}
a1e4ec87 144
621be1ec 145#endif // wxUSE_XRC