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