]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_menu.cpp
use GetFileAttributes() to check for readonly files under Win9x, the NT method doesn...
[wxWidgets.git] / src / xrc / xh_menu.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/xrc/xh_menu.cpp
3 // Purpose: XRC resource for menus and menubars
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 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #if wxUSE_XRC && wxUSE_MENUS
19
20 #include "wx/xrc/xh_menu.h"
21
22 #ifndef WX_PRECOMP
23 #include "wx/frame.h"
24 #include "wx/log.h"
25 #include "wx/menu.h"
26 #endif
27
28 IMPLEMENT_DYNAMIC_CLASS(wxMenuXmlHandler, wxXmlResourceHandler)
29
30 wxMenuXmlHandler::wxMenuXmlHandler() :
31 wxXmlResourceHandler(), m_insideMenu(false)
32 {
33 XRC_ADD_STYLE(wxMENU_TEAROFF);
34 }
35
36 wxObject *wxMenuXmlHandler::DoCreateResource()
37 {
38 if (m_class == wxT("wxMenu"))
39 {
40 wxMenu *menu = m_instance ? wxStaticCast(m_instance, wxMenu)
41 : new wxMenu(GetStyle());
42
43 wxString title = GetText(wxT("label"));
44 wxString help = GetText(wxT("help"));
45
46 bool oldins = m_insideMenu;
47 m_insideMenu = true;
48 CreateChildren(menu, true/*only this handler*/);
49 m_insideMenu = oldins;
50
51 wxMenuBar *p_bar = wxDynamicCast(m_parent, wxMenuBar);
52 if (p_bar)
53 {
54 p_bar->Append(menu, title);
55 }
56 else
57 {
58 wxMenu *p_menu = wxDynamicCast(m_parent, wxMenu);
59 if (p_menu)
60 {
61 p_menu->Append(GetID(), title, menu, help);
62 if (HasParam(wxT("enabled")))
63 p_menu->Enable(GetID(), GetBool(wxT("enabled")));
64 }
65 }
66
67 return menu;
68 }
69
70 else
71 {
72 wxMenu *p_menu = wxDynamicCast(m_parent, wxMenu);
73
74 if (m_class == wxT("separator"))
75 p_menu->AppendSeparator();
76 else if (m_class == wxT("break"))
77 p_menu->Break();
78 else /*wxMenuItem*/
79 {
80 int id = GetID();
81 wxString label = GetText(wxT("label"));
82 wxString accel = GetText(wxT("accel"), false);
83 wxString fullLabel = label;
84 if (!accel.empty())
85 fullLabel << wxT("\t") << accel;
86
87 wxItemKind kind = wxITEM_NORMAL;
88 if (GetBool(wxT("radio")))
89 kind = wxITEM_RADIO;
90 if (GetBool(wxT("checkable")))
91 {
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
99 kind = wxITEM_CHECK;
100 }
101
102 wxMenuItem *mitem = new wxMenuItem(p_menu, id, fullLabel,
103 GetText(wxT("help")), kind);
104
105 #if (!defined(__WXMSW__) && !defined(__WXPM__)) || wxUSE_OWNER_DRAWN
106 if (HasParam(wxT("bitmap")))
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 }
118 #endif
119 p_menu->Append(mitem);
120 mitem->Enable(GetBool(wxT("enabled"), true));
121 if (kind == wxITEM_CHECK)
122 mitem->Check(GetBool(wxT("checked")));
123 }
124 return NULL;
125 }
126 }
127
128
129
130 bool wxMenuXmlHandler::CanHandle(wxXmlNode *node)
131 {
132 return IsOfClass(node, wxT("wxMenu")) ||
133 (m_insideMenu &&
134 (IsOfClass(node, wxT("wxMenuItem")) ||
135 IsOfClass(node, wxT("break")) ||
136 IsOfClass(node, wxT("separator")))
137 );
138 }
139
140 IMPLEMENT_DYNAMIC_CLASS(wxMenuBarXmlHandler, wxXmlResourceHandler)
141
142 wxMenuBarXmlHandler::wxMenuBarXmlHandler() : wxXmlResourceHandler()
143 {
144 XRC_ADD_STYLE(wxMB_DOCKABLE);
145 }
146
147 wxObject *wxMenuBarXmlHandler::DoCreateResource()
148 {
149 wxMenuBar *menubar = new wxMenuBar(GetStyle());
150 CreateChildren(menubar);
151
152 if (m_parentAsWindow)
153 {
154 wxFrame *parentFrame = wxDynamicCast(m_parent, wxFrame);
155 if (parentFrame)
156 parentFrame->SetMenuBar(menubar);
157 }
158
159 return menubar;
160 }
161
162
163
164 bool wxMenuBarXmlHandler::CanHandle(wxXmlNode *node)
165 {
166 return IsOfClass(node, wxT("wxMenuBar"));
167 }
168
169 #endif // wxUSE_XRC && wxUSE_MENUS