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