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