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