]>
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"
34 #include "wx/bitmap.h"
35 #include "wx/settings.h"
39 #include "wx/ownerdrw.h"
40 #include "wx/menuitem.h"
52 // ---------------------------------------------------------------------------
54 // ---------------------------------------------------------------------------
56 #define GetHMenuOf(menu) ((HMENU)menu->GetHMenu())
58 // ============================================================================
60 // ============================================================================
62 // ----------------------------------------------------------------------------
63 // dynamic classes implementation
64 // ----------------------------------------------------------------------------
66 #if !defined(USE_SHARED_LIBRARY) || !USE_SHARED_LIBRARY
68 IMPLEMENT_DYNAMIC_CLASS2(wxMenuItem
, wxObject
, wxOwnerDrawn
)
69 #else //!USE_OWNER_DRAWN
70 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem
, wxObject
)
71 #endif //USE_OWNER_DRAWN
73 #endif //USE_SHARED_LIBRARY
75 // ----------------------------------------------------------------------------
77 // ----------------------------------------------------------------------------
82 wxMenuItem::wxMenuItem(wxMenu
*pParentMenu
, int id
,
83 const wxString
& strName
, const wxString
& strHelp
,
87 wxOwnerDrawn(strName
, bCheckable
),
88 #else //no owner drawn support
89 m_bCheckable(bCheckable
),
94 wxASSERT_MSG( pParentMenu
!= NULL
, "a menu item should have a parent" );
97 // set default menu colors
98 #define SYS_COLOR(c) (wxSystemSettings::GetSystemColour(wxSYS_COLOUR_##c))
100 SetTextColour(SYS_COLOR(MENUTEXT
));
101 SetBackgroundColour(SYS_COLOR(MENU
));
103 // we don't want normal items be owner-drawn
109 m_pParentMenu
= pParentMenu
;
110 m_pSubMenu
= pSubMenu
;
115 wxMenuItem::~wxMenuItem()
122 // return the id for calling Win32 API functions
123 int wxMenuItem::GetRealId() const
125 return m_pSubMenu
? (int)m_pSubMenu
->GetHMenu() : GetId();
128 // delete the sub menu
129 // -------------------
130 void wxMenuItem::DeleteSubMenu()
139 void wxMenuItem::Enable(bool bDoEnable
)
141 if ( m_bEnabled
!= bDoEnable
) {
142 long rc
= EnableMenuItem(GetHMenuOf(m_pParentMenu
),
145 (bDoEnable
? MF_ENABLED
: MF_GRAYED
));
148 wxLogLastError("EnableMenuItem");
151 m_bEnabled
= bDoEnable
;
155 void wxMenuItem::Check(bool bDoCheck
)
157 wxCHECK_RET( IsCheckable(), "only checkable items may be checked" );
159 if ( m_bChecked
!= bDoCheck
) {
160 long rc
= CheckMenuItem(GetHMenuOf(m_pParentMenu
),
163 (bDoCheck
? MF_CHECKED
: MF_UNCHECKED
));
166 wxLogLastError("CheckMenuItem");
169 m_bChecked
= bDoCheck
;
173 void wxMenuItem::SetName(const wxString
& strName
)
175 // don't do anything if label didn't change
176 if ( m_strName
== strName
)
181 HMENU hMenu
= GetHMenuOf(m_pParentMenu
);
183 UINT id
= GetRealId();
184 UINT flagsOld
= ::GetMenuState(hMenu
, id
, MF_BYCOMMAND
);
185 if ( flagsOld
== 0xFFFFFFFF )
187 wxLogLastError("GetMenuState");
193 // high byte contains the number of items in a submenu for submenus
195 flagsOld
|= MF_POPUP
;
199 #if wxUSE_OWNER_DRAWN
200 if ( IsOwnerDrawn() )
202 flagsOld
|= MF_OWNERDRAW
;
208 flagsOld
|= MF_STRING
;
212 if ( ::ModifyMenu(hMenu
, id
,
213 MF_BYCOMMAND
| flagsOld
,
214 id
, data
) == 0xFFFFFFFF )
216 wxLogLastError("ModifyMenu");