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