]> git.saurik.com Git - wxWidgets.git/blame - src/os2/menuitem.cpp
VTK wrapper of vtkRenderWindow for wxPython. Tested on MSW so far.
[wxWidgets.git] / src / os2 / menuitem.cpp
CommitLineData
0e320a79
DW
1///////////////////////////////////////////////////////////////////////////////
2// Name: menuitem.cpp
3// Purpose: wxMenuItem implementation
75f11ad7
DW
4// Author: David Webster
5// Modified by:
6// Created: 10/10/98
0e320a79 7// RCS-ID: $Id$
75f11ad7 8// Copyright: (c) David Webster
0e320a79
DW
9// Licence: wxWindows licence
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// headers & declarations
14// ============================================================================
15
75f11ad7
DW
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifndef WX_PRECOMP
20 #include "wx/font.h"
21 #include "wx/bitmap.h"
22 #include "wx/settings.h"
23 #include "wx/font.h"
24 #include "wx/window.h"
25 #include "wx/accel.h"
26 #include "wx/menu.h"
27 #include "wx/string.h"
28#endif
29
0e320a79 30#include "wx/menuitem.h"
75f11ad7
DW
31#include "wx/log.h"
32
c5fb56c0
DW
33#if wxUSE_ACCEL
34 #include "wx/accel.h"
35#endif // wxUSE_ACCEL
36
75f11ad7
DW
37#include "wx/os2/private.h"
38
39// ---------------------------------------------------------------------------
c5fb56c0 40// macro
75f11ad7
DW
41// ---------------------------------------------------------------------------
42
c5fb56c0 43// hide the ugly cast
75f11ad7 44#define GetHMenuOf(menu) ((HMENU)menu->GetHMenu())
0e320a79 45
c5fb56c0
DW
46// conditional compilation
47#if wxUSE_OWNER_DRAWN
48 #define OWNER_DRAWN_ONLY( code ) if ( IsOwnerDrawn() ) code
49#else // !wxUSE_OWNER_DRAWN
50 #define OWNER_DRAWN_ONLY( code )
51#endif // wxUSE_OWNER_DRAWN/!wxUSE_OWNER_DRAWN
52
0e320a79
DW
53// ============================================================================
54// implementation
55// ============================================================================
56
57// ----------------------------------------------------------------------------
58// dynamic classes implementation
59// ----------------------------------------------------------------------------
60
75f11ad7 61#if !defined(USE_SHARED_LIBRARY) || !USE_SHARED_LIBRARY
c5fb56c0
DW
62 #if wxUSE_OWNER_DRAWN
63 IMPLEMENT_DYNAMIC_CLASS2(wxMenuItem, wxMenuItemBase, wxOwnerDrawn)
64 #else //!USE_OWNER_DRAWN
65 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxMenuItemBase)
66 #endif //USE_OWNER_DRAWN
0e320a79
DW
67#endif //USE_SHARED_LIBRARY
68
69// ----------------------------------------------------------------------------
70// wxMenuItem
71// ----------------------------------------------------------------------------
72
73// ctor & dtor
74// -----------
75
c5fb56c0
DW
76wxMenuItem::wxMenuItem(wxMenu *pParentMenu,
77 int id,
78 const wxString& text,
79 const wxString& strHelp,
0e320a79
DW
80 bool bCheckable,
81 wxMenu *pSubMenu) :
75f11ad7 82#if wxUSE_OWNER_DRAWN
c5fb56c0
DW
83 wxOwnerDrawn(text, bCheckable)
84#endif // owner drawn
0e320a79 85{
75f11ad7
DW
86 wxASSERT_MSG( pParentMenu != NULL, wxT("a menu item should have a parent") );
87
88#if wxUSE_OWNER_DRAWN
89 // set default menu colors
90 #define SYS_COLOR(c) (wxSystemSettings::GetSystemColour(wxSYS_COLOUR_##c))
91
92 SetTextColour(SYS_COLOR(MENUTEXT));
93 SetBackgroundColour(SYS_COLOR(MENU));
94
95 // we don't want normal items be owner-drawn
96 ResetOwnerDrawn();
97
98 #undef SYS_COLOR
c5fb56c0
DW
99#endif // wxUSE_OWNER_DRAWN
100
101 m_parentMenu = pParentMenu;
102 m_subMenu = pSubMenu;
103 m_isEnabled = TRUE;
104 m_isChecked = FALSE;
105 m_id = id;
106 m_text = text;
107 m_isCheckable = bCheckable;
108 m_help = strHelp;
0e320a79
DW
109}
110
75f11ad7 111wxMenuItem::~wxMenuItem()
0e320a79
DW
112{
113}
114
115// misc
116// ----
117
75f11ad7
DW
118// return the id for calling Win32 API functions
119int wxMenuItem::GetRealId() const
120{
c5fb56c0
DW
121 return m_subMenu ? (int)m_subMenu->GetHMenu() : GetId();
122}
123
124// get item state
125// --------------
126
127bool wxMenuItem::IsChecked() const
128{
129/*
130 int flag = ::GetMenuState(GetHMenuOf(m_parentMenu), GetId(), MF_BYCOMMAND);
131
132 // don't "and" with MF_ENABLED because its value is 0
133 return (flag & MF_DISABLED) == 0;
134*/
135 return FALSE;
136}
137
138wxString wxMenuItem::GetLabel() const
139{
140 return wxStripMenuCodes(m_text);
75f11ad7
DW
141}
142
c5fb56c0
DW
143// accelerators
144// ------------
145
146#if wxUSE_ACCEL
147
148wxAcceleratorEntry *wxMenuItem::GetAccel() const
0e320a79 149{
c5fb56c0 150 return wxGetAccelFromString(GetText());
0e320a79
DW
151}
152
c5fb56c0
DW
153#endif // wxUSE_ACCEL
154
0e320a79
DW
155// change item state
156// -----------------
157
c5fb56c0 158void wxMenuItem::Enable(bool enable)
0e320a79 159{
c5fb56c0
DW
160 if ( m_isEnabled == enable )
161 return;
75f11ad7 162/*
c5fb56c0
DW
163 long rc = EnableMenuItem(GetHMenuOf(m_parentMenu),
164 GetRealId(),
165 MF_BYCOMMAND |
166 (enable ? MF_ENABLED : MF_GRAYED));
75f11ad7 167
c5fb56c0
DW
168 if ( rc == -1 ) {
169 wxLogLastError("EnableMenuItem");
0e320a79 170 }
75f11ad7 171*/
c5fb56c0 172 wxMenuItemBase::Enable(enable);
0e320a79
DW
173}
174
c5fb56c0 175void wxMenuItem::Check(bool check)
0e320a79 176{
c5fb56c0 177 wxCHECK_RET( m_isCheckable, wxT("only checkable items may be checked") );
75f11ad7 178
c5fb56c0
DW
179 if ( m_isChecked == check )
180 return;
75f11ad7 181/*
c5fb56c0
DW
182 long rc = CheckMenuItem(GetHMenuOf(m_parentMenu),
183 GetRealId(),
184 MF_BYCOMMAND |
185 (check ? MF_CHECKED : MF_UNCHECKED));
75f11ad7 186
c5fb56c0
DW
187 if ( rc == -1 ) {
188 wxLogLastError("CheckMenuItem");
75f11ad7
DW
189 }
190*/
c5fb56c0 191 wxMenuItemBase::Check(check);
75f11ad7
DW
192}
193
c5fb56c0 194void wxMenuItem::SetText(const wxString& text)
75f11ad7
DW
195{
196 // don't do anything if label didn't change
c5fb56c0 197 if ( m_text == text )
75f11ad7
DW
198 return;
199
c5fb56c0
DW
200 wxMenuItemBase::SetText(text);
201 OWNER_DRAWN_ONLY( wxOwnerDrawn::SetName(text) );
202/*
203 HMENU hMenu = GetHMenuOf(m_parentMenu);
204 wxCHECK_RET( hMenu, wxT("menuitem without menu") );
75f11ad7 205
c5fb56c0
DW
206#if wxUSE_ACCEL
207 m_parentMenu->UpdateAccel(this);
208#endif // wxUSE_ACCEL
75f11ad7
DW
209
210 UINT id = GetRealId();
75f11ad7
DW
211 UINT flagsOld = ::GetMenuState(hMenu, id, MF_BYCOMMAND);
212 if ( flagsOld == 0xFFFFFFFF )
213 {
214 wxLogLastError("GetMenuState");
215 }
216 else
217 {
218 if ( IsSubMenu() )
219 {
220 // high byte contains the number of items in a submenu for submenus
221 flagsOld &= 0xFF;
222 flagsOld |= MF_POPUP;
223 }
224
225 LPCTSTR data;
c5fb56c0 226
75f11ad7
DW
227#if wxUSE_OWNER_DRAWN
228 if ( IsOwnerDrawn() )
229 {
230 flagsOld |= MF_OWNERDRAW;
231 data = (LPCTSTR)this;
232 }
233 else
234#endif //owner drawn
235 {
236 flagsOld |= MF_STRING;
c5fb56c0 237 data = (char*) text.c_str();
75f11ad7
DW
238 }
239
240 if ( ::ModifyMenu(hMenu, id,
241 MF_BYCOMMAND | flagsOld,
c5fb56c0 242 id, data) == (int)0xFFFFFFFF )
75f11ad7
DW
243 {
244 wxLogLastError(wxT("ModifyMenu"));
245 }
246 }
247*/
248}
0e320a79 249
c5fb56c0
DW
250void wxMenuItem::SetCheckable(bool checkable)
251{
252 wxMenuItemBase::SetCheckable(checkable);
253 OWNER_DRAWN_ONLY( wxOwnerDrawn::SetCheckable(checkable) );
254}
255
256// ----------------------------------------------------------------------------
257// wxMenuItemBase
258// ----------------------------------------------------------------------------
259
260wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu,
261 int id,
262 const wxString& name,
263 const wxString& help,
264 bool isCheckable,
265 wxMenu *subMenu)
266{
267 return new wxMenuItem(parentMenu, id, name, help, isCheckable, subMenu);
268}