]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/menuitem.cpp
1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMenuItem implementation
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
13 // headers & declarations
14 // ============================================================================
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
21 #include "wx/bitmap.h"
22 #include "wx/settings.h"
24 #include "wx/window.h"
27 #include "wx/string.h"
30 #include "wx/ownerdrw.h"
31 #include "wx/menuitem.h"
34 #include "wx/os2/private.h"
36 // ---------------------------------------------------------------------------
38 // ---------------------------------------------------------------------------
40 #define GetHMenuOf(menu) ((HMENU)menu->GetHMenu())
42 // ============================================================================
44 // ============================================================================
46 // ----------------------------------------------------------------------------
47 // dynamic classes implementation
48 // ----------------------------------------------------------------------------
50 #if !defined(USE_SHARED_LIBRARY) || !USE_SHARED_LIBRARY
52 IMPLEMENT_DYNAMIC_CLASS2(wxMenuItem
, wxObject
, wxOwnerDrawn
)
53 #else //!USE_OWNER_DRAWN
54 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem
, wxObject
)
55 #endif //USE_OWNER_DRAWN
57 #endif //USE_SHARED_LIBRARY
59 // ----------------------------------------------------------------------------
61 // ----------------------------------------------------------------------------
66 wxMenuItem::wxMenuItem(wxMenu
*pParentMenu
, int id
,
67 const wxString
& strName
, const wxString
& strHelp
,
71 wxOwnerDrawn(strName
, bCheckable
),
72 #else //no owner drawn support
73 m_bCheckable(bCheckable
),
78 wxASSERT_MSG( pParentMenu
!= NULL
, wxT("a menu item should have a parent") );
81 // set default menu colors
82 #define SYS_COLOR(c) (wxSystemSettings::GetSystemColour(wxSYS_COLOUR_##c))
84 SetTextColour(SYS_COLOR(MENUTEXT
));
85 SetBackgroundColour(SYS_COLOR(MENU
));
87 // we don't want normal items be owner-drawn
93 m_pParentMenu
= pParentMenu
;
94 m_pSubMenu
= pSubMenu
;
100 wxMenuItem::~wxMenuItem()
107 // return the id for calling Win32 API functions
108 int wxMenuItem::GetRealId() const
110 return m_pSubMenu
? (int)m_pSubMenu
->GetHMenu() : GetId();
113 // delete the sub menu
114 // -------------------
115 void wxMenuItem::DeleteSubMenu()
124 void wxMenuItem::Enable(bool bDoEnable
)
128 if ( m_bEnabled != bDoEnable ) {
129 long rc = EnableMenuItem(GetHMenuOf(m_pParentMenu),
132 (bDoEnable ? MF_ENABLED : MF_GRAYED));
135 wxLogLastError("EnableMenuItem");
138 m_bEnabled = bDoEnable;
143 void wxMenuItem::Check(bool bDoCheck
)
145 wxCHECK_RET( IsCheckable(), wxT("only checkable items may be checked") );
149 if ( m_bChecked != bDoCheck ) {
150 long rc = CheckMenuItem(GetHMenuOf(m_pParentMenu),
153 (bDoCheck ? MF_CHECKED : MF_UNCHECKED));
156 wxLogLastError("CheckMenuItem");
159 m_bChecked = bDoCheck;
164 void wxMenuItem::SetName(const wxString
& strName
)
166 // don't do anything if label didn't change
167 if ( m_strName
== strName
)
172 HMENU hMenu
= GetHMenuOf(m_pParentMenu
);
174 UINT id
= GetRealId();
178 UINT flagsOld = ::GetMenuState(hMenu, id, MF_BYCOMMAND);
179 if ( flagsOld == 0xFFFFFFFF )
181 wxLogLastError("GetMenuState");
187 // high byte contains the number of items in a submenu for submenus
189 flagsOld |= MF_POPUP;
193 #if wxUSE_OWNER_DRAWN
194 if ( IsOwnerDrawn() )
196 flagsOld |= MF_OWNERDRAW;
197 data = (LPCTSTR)this;
202 flagsOld |= MF_STRING;
206 if ( ::ModifyMenu(hMenu, id,
207 MF_BYCOMMAND | flagsOld,
208 id, data) == 0xFFFFFFFF )
210 wxLogLastError(wxT("ModifyMenu"));