]> git.saurik.com Git - wxWidgets.git/blame - src/os2/menuitem.cpp
*** empty log message ***
[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
c5fb56c0
DW
61 #if wxUSE_OWNER_DRAWN
62 IMPLEMENT_DYNAMIC_CLASS2(wxMenuItem, wxMenuItemBase, wxOwnerDrawn)
63 #else //!USE_OWNER_DRAWN
64 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxMenuItemBase)
65 #endif //USE_OWNER_DRAWN
0e320a79
DW
66
67// ----------------------------------------------------------------------------
68// wxMenuItem
69// ----------------------------------------------------------------------------
70
71// ctor & dtor
72// -----------
73
c5fb56c0
DW
74wxMenuItem::wxMenuItem(wxMenu *pParentMenu,
75 int id,
76 const wxString& text,
77 const wxString& strHelp,
0e320a79
DW
78 bool bCheckable,
79 wxMenu *pSubMenu) :
75f11ad7 80#if wxUSE_OWNER_DRAWN
c5fb56c0
DW
81 wxOwnerDrawn(text, bCheckable)
82#endif // owner drawn
0e320a79 83{
75f11ad7
DW
84 wxASSERT_MSG( pParentMenu != NULL, wxT("a menu item should have a parent") );
85
86#if wxUSE_OWNER_DRAWN
87 // set default menu colors
88 #define SYS_COLOR(c) (wxSystemSettings::GetSystemColour(wxSYS_COLOUR_##c))
89
90 SetTextColour(SYS_COLOR(MENUTEXT));
91 SetBackgroundColour(SYS_COLOR(MENU));
92
93 // we don't want normal items be owner-drawn
94 ResetOwnerDrawn();
95
96 #undef SYS_COLOR
c5fb56c0
DW
97#endif // wxUSE_OWNER_DRAWN
98
99 m_parentMenu = pParentMenu;
100 m_subMenu = pSubMenu;
101 m_isEnabled = TRUE;
102 m_isChecked = FALSE;
103 m_id = id;
104 m_text = text;
105 m_isCheckable = bCheckable;
106 m_help = strHelp;
0e320a79
DW
107}
108
75f11ad7 109wxMenuItem::~wxMenuItem()
0e320a79
DW
110{
111}
112
113// misc
114// ----
115
75f11ad7
DW
116// return the id for calling Win32 API functions
117int wxMenuItem::GetRealId() const
118{
c5fb56c0
DW
119 return m_subMenu ? (int)m_subMenu->GetHMenu() : GetId();
120}
121
122// get item state
123// --------------
124
125bool wxMenuItem::IsChecked() const
126{
127/*
128 int flag = ::GetMenuState(GetHMenuOf(m_parentMenu), GetId(), MF_BYCOMMAND);
129
130 // don't "and" with MF_ENABLED because its value is 0
131 return (flag & MF_DISABLED) == 0;
132*/
133 return FALSE;
134}
135
136wxString wxMenuItem::GetLabel() const
137{
138 return wxStripMenuCodes(m_text);
75f11ad7
DW
139}
140
c5fb56c0
DW
141// accelerators
142// ------------
143
144#if wxUSE_ACCEL
145
146wxAcceleratorEntry *wxMenuItem::GetAccel() const
0e320a79 147{
c5fb56c0 148 return wxGetAccelFromString(GetText());
0e320a79
DW
149}
150
c5fb56c0
DW
151#endif // wxUSE_ACCEL
152
0e320a79
DW
153// change item state
154// -----------------
155
c5fb56c0 156void wxMenuItem::Enable(bool enable)
0e320a79 157{
c5fb56c0
DW
158 if ( m_isEnabled == enable )
159 return;
75f11ad7 160/*
c5fb56c0
DW
161 long rc = EnableMenuItem(GetHMenuOf(m_parentMenu),
162 GetRealId(),
163 MF_BYCOMMAND |
164 (enable ? MF_ENABLED : MF_GRAYED));
75f11ad7 165
c5fb56c0
DW
166 if ( rc == -1 ) {
167 wxLogLastError("EnableMenuItem");
0e320a79 168 }
75f11ad7 169*/
c5fb56c0 170 wxMenuItemBase::Enable(enable);
0e320a79
DW
171}
172
c5fb56c0 173void wxMenuItem::Check(bool check)
0e320a79 174{
c5fb56c0 175 wxCHECK_RET( m_isCheckable, wxT("only checkable items may be checked") );
75f11ad7 176
c5fb56c0
DW
177 if ( m_isChecked == check )
178 return;
75f11ad7 179/*
c5fb56c0
DW
180 long rc = CheckMenuItem(GetHMenuOf(m_parentMenu),
181 GetRealId(),
182 MF_BYCOMMAND |
183 (check ? MF_CHECKED : MF_UNCHECKED));
75f11ad7 184
c5fb56c0
DW
185 if ( rc == -1 ) {
186 wxLogLastError("CheckMenuItem");
75f11ad7
DW
187 }
188*/
c5fb56c0 189 wxMenuItemBase::Check(check);
75f11ad7
DW
190}
191
c5fb56c0 192void wxMenuItem::SetText(const wxString& text)
75f11ad7
DW
193{
194 // don't do anything if label didn't change
c5fb56c0 195 if ( m_text == text )
75f11ad7
DW
196 return;
197
c5fb56c0
DW
198 wxMenuItemBase::SetText(text);
199 OWNER_DRAWN_ONLY( wxOwnerDrawn::SetName(text) );
200/*
201 HMENU hMenu = GetHMenuOf(m_parentMenu);
202 wxCHECK_RET( hMenu, wxT("menuitem without menu") );
75f11ad7 203
c5fb56c0
DW
204#if wxUSE_ACCEL
205 m_parentMenu->UpdateAccel(this);
206#endif // wxUSE_ACCEL
75f11ad7
DW
207
208 UINT id = GetRealId();
75f11ad7
DW
209 UINT flagsOld = ::GetMenuState(hMenu, id, MF_BYCOMMAND);
210 if ( flagsOld == 0xFFFFFFFF )
211 {
212 wxLogLastError("GetMenuState");
213 }
214 else
215 {
216 if ( IsSubMenu() )
217 {
218 // high byte contains the number of items in a submenu for submenus
219 flagsOld &= 0xFF;
220 flagsOld |= MF_POPUP;
221 }
222
223 LPCTSTR data;
c5fb56c0 224
75f11ad7
DW
225#if wxUSE_OWNER_DRAWN
226 if ( IsOwnerDrawn() )
227 {
228 flagsOld |= MF_OWNERDRAW;
229 data = (LPCTSTR)this;
230 }
231 else
232#endif //owner drawn
233 {
234 flagsOld |= MF_STRING;
c5fb56c0 235 data = (char*) text.c_str();
75f11ad7
DW
236 }
237
238 if ( ::ModifyMenu(hMenu, id,
239 MF_BYCOMMAND | flagsOld,
c5fb56c0 240 id, data) == (int)0xFFFFFFFF )
75f11ad7
DW
241 {
242 wxLogLastError(wxT("ModifyMenu"));
243 }
244 }
245*/
246}
0e320a79 247
c5fb56c0
DW
248void wxMenuItem::SetCheckable(bool checkable)
249{
250 wxMenuItemBase::SetCheckable(checkable);
251 OWNER_DRAWN_ONLY( wxOwnerDrawn::SetCheckable(checkable) );
252}
253
254// ----------------------------------------------------------------------------
255// wxMenuItemBase
256// ----------------------------------------------------------------------------
257
258wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu,
259 int id,
260 const wxString& name,
261 const wxString& help,
262 bool isCheckable,
263 wxMenu *subMenu)
264{
265 return new wxMenuItem(parentMenu, id, name, help, isCheckable, subMenu);
266}