]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/menuitem.cpp
1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMenuItem implementation
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
21 #pragma implementation "menuitem.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
33 #include "wx/bitmap.h"
34 #include "wx/settings.h"
36 #include "wx/window.h"
39 #include "wx/string.h"
42 #include "wx/ownerdrw.h"
43 #include "wx/menuitem.h"
46 #include "wx/msw/private.h"
48 // ---------------------------------------------------------------------------
50 // ---------------------------------------------------------------------------
52 #define GetHMenuOf(menu) ((HMENU)menu->GetHMenu())
54 // ============================================================================
56 // ============================================================================
58 // ----------------------------------------------------------------------------
59 // dynamic classes implementation
60 // ----------------------------------------------------------------------------
62 #if !defined(USE_SHARED_LIBRARY) || !USE_SHARED_LIBRARY
64 IMPLEMENT_DYNAMIC_CLASS2(wxMenuItem
, wxObject
, wxOwnerDrawn
)
65 #else //!USE_OWNER_DRAWN
66 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem
, wxObject
)
67 #endif //USE_OWNER_DRAWN
69 #endif //USE_SHARED_LIBRARY
71 // ----------------------------------------------------------------------------
73 // ----------------------------------------------------------------------------
78 wxMenuItem::wxMenuItem(wxMenu
*pParentMenu
, int id
,
79 const wxString
& strName
, const wxString
& strHelp
,
83 wxOwnerDrawn(strName
, bCheckable
),
84 #else //no owner drawn support
85 m_bCheckable(bCheckable
),
90 wxASSERT_MSG( pParentMenu
!= NULL
, _T("a menu item should have a parent") );
93 // set default menu colors
94 #define SYS_COLOR(c) (wxSystemSettings::GetSystemColour(wxSYS_COLOUR_##c))
96 SetTextColour(SYS_COLOR(MENUTEXT
));
97 SetBackgroundColour(SYS_COLOR(MENU
));
99 // we don't want normal items be owner-drawn
105 m_pParentMenu
= pParentMenu
;
106 m_pSubMenu
= pSubMenu
;
112 wxMenuItem::~wxMenuItem()
119 // return the id for calling Win32 API functions
120 int wxMenuItem::GetRealId() const
122 return m_pSubMenu
? (int)m_pSubMenu
->GetHMenu() : GetId();
125 // delete the sub menu
126 // -------------------
127 void wxMenuItem::DeleteSubMenu()
136 void wxMenuItem::Enable(bool bDoEnable
)
138 if ( m_bEnabled
!= bDoEnable
) {
139 long rc
= EnableMenuItem(GetHMenuOf(m_pParentMenu
),
142 (bDoEnable
? MF_ENABLED
: MF_GRAYED
));
145 wxLogLastError("EnableMenuItem");
148 m_bEnabled
= bDoEnable
;
152 void wxMenuItem::Check(bool bDoCheck
)
154 wxCHECK_RET( IsCheckable(), _T("only checkable items may be checked") );
156 if ( m_bChecked
!= bDoCheck
) {
157 long rc
= CheckMenuItem(GetHMenuOf(m_pParentMenu
),
160 (bDoCheck
? MF_CHECKED
: MF_UNCHECKED
));
163 wxLogLastError("CheckMenuItem");
166 m_bChecked
= bDoCheck
;
170 void wxMenuItem::SetName(const wxString
& strName
)
172 // don't do anything if label didn't change
173 if ( m_strName
== strName
)
178 HMENU hMenu
= GetHMenuOf(m_pParentMenu
);
180 UINT id
= GetRealId();
181 UINT flagsOld
= ::GetMenuState(hMenu
, id
, MF_BYCOMMAND
);
182 if ( flagsOld
== 0xFFFFFFFF )
184 wxLogLastError("GetMenuState");
190 // high byte contains the number of items in a submenu for submenus
192 flagsOld
|= MF_POPUP
;
196 #if wxUSE_OWNER_DRAWN
197 if ( IsOwnerDrawn() )
199 flagsOld
|= MF_OWNERDRAW
;
200 data
= (LPCTSTR
)this;
205 flagsOld
|= MF_STRING
;
209 if ( ::ModifyMenu(hMenu
, id
,
210 MF_BYCOMMAND
| flagsOld
,
211 id
, data
) == 0xFFFFFFFF )
213 wxLogLastError(_T("ModifyMenu"));