]> git.saurik.com Git - wxWidgets.git/blame - src/xrc/xh_menu.cpp
letting the peer declare whether it wants to draw its borders itself (eg the search...
[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 {
94 wxLogWarning(_("XRC syntax error: a menu item can't have "
95 "both \"radio\" and \"checkable\" "
96 "properties, ignoring the former."));
97 }
98
65812490
VS
99 kind = wxITEM_CHECK;
100 }
101
78d14f80 102 wxMenuItem *mitem = new wxMenuItem(p_menu, id, fullLabel,
65812490 103 GetText(wxT("help")), kind);
f80ea77b 104
200ab0bf 105#if (!defined(__WXMSW__) && !defined(__WXPM__)) || wxUSE_OWNER_DRAWN
84969af7 106 if (HasParam(wxT("bitmap")))
d2ffaf16
VZ
107 {
108 // currently only wxMSW has support for using different checked
109 // and unchecked bitmaps for menu items
110#ifdef __WXMSW__
111 if (HasParam(wxT("bitmap2")))
112 mitem->SetBitmaps(GetBitmap(wxT("bitmap2"), wxART_MENU),
113 GetBitmap(wxT("bitmap"), wxART_MENU));
114 else
115#endif // __WXMSW__
116 mitem->SetBitmap(GetBitmap(wxT("bitmap"), wxART_MENU));
117 }
78d14f80
VS
118#endif
119 p_menu->Append(mitem);
f80ea77b 120 mitem->Enable(GetBool(wxT("enabled"), true));
65812490
VS
121 if (kind == wxITEM_CHECK)
122 mitem->Check(GetBool(wxT("checked")));
78d14f80
VS
123 }
124 return NULL;
125 }
126}
127
128
129
130bool wxMenuXmlHandler::CanHandle(wxXmlNode *node)
131{
132 return IsOfClass(node, wxT("wxMenu")) ||
f80ea77b 133 (m_insideMenu &&
78d14f80
VS
134 (IsOfClass(node, wxT("wxMenuItem")) ||
135 IsOfClass(node, wxT("break")) ||
136 IsOfClass(node, wxT("separator")))
137 );
138}
139
854e189f
VS
140IMPLEMENT_DYNAMIC_CLASS(wxMenuBarXmlHandler, wxXmlResourceHandler)
141
78d14f80
VS
142wxMenuBarXmlHandler::wxMenuBarXmlHandler() : wxXmlResourceHandler()
143{
544fee32 144 XRC_ADD_STYLE(wxMB_DOCKABLE);
78d14f80
VS
145}
146
78d14f80
VS
147wxObject *wxMenuBarXmlHandler::DoCreateResource()
148{
149 wxMenuBar *menubar = new wxMenuBar(GetStyle());
150 CreateChildren(menubar);
f2588180
VS
151
152 if (m_parentAsWindow)
153 {
154 wxFrame *parentFrame = wxDynamicCast(m_parent, wxFrame);
155 if (parentFrame)
156 parentFrame->SetMenuBar(menubar);
157 }
158
78d14f80
VS
159 return menubar;
160}
161
162
163
164bool wxMenuBarXmlHandler::CanHandle(wxXmlNode *node)
165{
166 return IsOfClass(node, wxT("wxMenuBar"));
167}
a1e4ec87 168
dd47af27 169#endif // wxUSE_XRC && wxUSE_MENUS