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