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