]> git.saurik.com Git - wxWidgets.git/blob - src/xrc/xh_menu.cpp
Wait() doesn't cancel the thread any longer
[wxWidgets.git] / src / xrc / xh_menu.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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 #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"
24 #include "wx/frame.h"
25
26 IMPLEMENT_DYNAMIC_CLASS(wxMenuXmlHandler, wxXmlResourceHandler)
27
28 wxMenuXmlHandler::wxMenuXmlHandler() :
29 wxXmlResourceHandler(), m_insideMenu(FALSE)
30 {
31 XRC_ADD_STYLE(wxMENU_TEAROFF);
32 }
33
34 wxObject *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*/
69 {
70 int id = GetID();
71 wxString label = GetText(wxT("label"));
72 wxString accel = GetText(wxT("accel"), FALSE);
73 wxString fullLabel = label;
74 if (!accel.IsEmpty())
75 fullLabel << wxT("\t") << accel;
76
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
86 wxMenuItem *mitem = new wxMenuItem(p_menu, id, fullLabel,
87 GetText(wxT("help")), kind);
88
89 #if wxCHECK_VERSION(2,3,0) || (defined(__WXMSW__) && wxUSE_OWNER_DRAWN)
90 if (HasParam(wxT("bitmap")))
91 mitem->SetBitmap(GetBitmap(wxT("bitmap"), wxART_MENU));
92 #endif
93 p_menu->Append(mitem);
94 mitem->Enable(GetBool(wxT("enabled"), TRUE));
95 if (kind == wxITEM_CHECK)
96 mitem->Check(GetBool(wxT("checked")));
97 }
98 return NULL;
99 }
100 }
101
102
103
104 bool 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
114 IMPLEMENT_DYNAMIC_CLASS(wxMenuBarXmlHandler, wxXmlResourceHandler)
115
116 wxMenuBarXmlHandler::wxMenuBarXmlHandler() : wxXmlResourceHandler()
117 {
118 XRC_ADD_STYLE(wxMB_DOCKABLE);
119 }
120
121 wxObject *wxMenuBarXmlHandler::DoCreateResource()
122 {
123 wxMenuBar *menubar = new wxMenuBar(GetStyle());
124 CreateChildren(menubar);
125
126 if (m_parentAsWindow)
127 {
128 wxFrame *parentFrame = wxDynamicCast(m_parent, wxFrame);
129 if (parentFrame)
130 parentFrame->SetMenuBar(menubar);
131 }
132
133 return menubar;
134 }
135
136
137
138 bool wxMenuBarXmlHandler::CanHandle(wxXmlNode *node)
139 {
140 return IsOfClass(node, wxT("wxMenuBar"));
141 }