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