]>
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() : | |
27 | wxXmlResourceHandler(), m_InsideMenu(FALSE) | |
28 | { | |
29 | ADD_STYLE(wxMENU_TEAROFF); | |
30 | } | |
31 | ||
32 | ||
33 | ||
34 | wxObject *wxMenuXmlHandler::DoCreateResource() | |
35 | { | |
36 | if (m_Node->GetName() == _T("menu")) | |
37 | { | |
38 | wxMenu *menu = new wxMenu(GetStyle()); | |
39 | wxString title = GetText(_T("label")); | |
40 | wxString help = GetText(_T("help")); | |
41 | ||
42 | bool oldins = m_InsideMenu; | |
43 | m_InsideMenu = TRUE; | |
44 | CreateChildren(menu, TRUE/*only this handler*/); | |
45 | m_InsideMenu = oldins; | |
46 | ||
47 | wxMenuBar *p_bar = wxDynamicCast(m_Parent, wxMenuBar); | |
48 | if (p_bar) | |
49 | p_bar->Append(menu, title); | |
50 | else | |
51 | { | |
52 | wxMenu *p_menu = wxDynamicCast(m_Parent, wxMenu); | |
53 | if (p_menu) | |
54 | p_menu->Append(GetID(), title, menu, help); | |
55 | } | |
56 | ||
57 | return menu; | |
58 | } | |
59 | ||
60 | else | |
61 | { | |
62 | wxMenu *p_menu = wxDynamicCast(m_Parent, wxMenu); | |
63 | ||
64 | if (m_Node->GetName() == _T("separator")) | |
65 | p_menu->AppendSeparator(); | |
66 | else if (m_Node->GetName() == _T("break")) | |
67 | p_menu->Break(); | |
3ad1cd4a | 68 | else /*menuitem*/ |
56d2f750 VS |
69 | { |
70 | int id = GetID(); | |
71 | bool checkable = GetBool(_T("checkable")); | |
3ad1cd4a | 72 | |
56d2f750 VS |
73 | p_menu->Append(id, GetText(_T("label")), |
74 | GetText(_T("help")), checkable); | |
75 | if (id != -1) | |
76 | { | |
77 | p_menu->Enable(id, GetBool(_T("enabled"), TRUE)); | |
78 | if (checkable) p_menu->Check(id, GetBool(_T("checked"))); | |
3ad1cd4a VS |
79 | |
80 | #if wxCHECK_VERSION(2,3,0) || defined(__WXMSW__) | |
81 | if (HasParam(_T("bitmap"))) | |
82 | { | |
83 | wxMenuItem *mitem = p_menu->FindItem(id); | |
84 | mitem->SetBitmap(GetBitmap(_T("bitmap"))); | |
85 | } | |
86 | #endif | |
56d2f750 VS |
87 | } |
88 | } | |
89 | return NULL; | |
90 | } | |
91 | } | |
92 | ||
93 | ||
94 | ||
95 | bool wxMenuXmlHandler::CanHandle(wxXmlNode *node) | |
96 | { | |
97 | return node->GetName() == _T("menu") || | |
98 | (m_InsideMenu && | |
99 | (node->GetName() == _T("menuitem") || | |
100 | node->GetName() == _T("break") || | |
101 | node->GetName() == _T("separator")) | |
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 | { | |
133 | return node->GetName() == _T("menubar"); | |
134 | } | |
135 |