]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/menuitem.cpp
32d2b0859a669c93583a995e68ccbd5614a8a41d
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"
53 // ---------------------------------------------------------------------------
55 // ---------------------------------------------------------------------------
57 #define GetHMenuOf(menu) ((HMENU)menu->GetHMenu())
59 // ============================================================================
61 // ============================================================================
63 // ----------------------------------------------------------------------------
64 // dynamic classes implementation
65 // ----------------------------------------------------------------------------
67 #if !defined(USE_SHARED_LIBRARY) || !USE_SHARED_LIBRARY
69 IMPLEMENT_DYNAMIC_CLASS2(wxMenuItem
, wxObject
, wxOwnerDrawn
)
70 #else //!USE_OWNER_DRAWN
71 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem
, wxObject
)
72 #endif //USE_OWNER_DRAWN
74 #endif //USE_SHARED_LIBRARY
76 // ----------------------------------------------------------------------------
78 // ----------------------------------------------------------------------------
83 wxMenuItem::wxMenuItem(wxMenu
*pParentMenu
, int id
,
84 const wxString
& strName
, const wxString
& strHelp
,
88 wxOwnerDrawn(strName
, bCheckable
),
89 #else //no owner drawn support
90 m_bCheckable(bCheckable
),
95 wxASSERT_MSG( pParentMenu
!= NULL
, "a menu item should have a parent" );
98 // set default menu colors
99 #define SYS_COLOR(c) (wxSystemSettings::GetSystemColour(wxSYS_COLOUR_##c))
101 SetTextColour(SYS_COLOR(MENUTEXT
));
102 SetBackgroundColour(SYS_COLOR(MENU
));
104 // we don't want normal items be owner-drawn
110 m_pParentMenu
= pParentMenu
;
111 m_pSubMenu
= pSubMenu
;
116 wxMenuItem::~wxMenuItem()
123 // return the id for calling Win32 API functions
124 int wxMenuItem::GetRealId() const
126 return m_pSubMenu
? (int)m_pSubMenu
->GetHMenu() : GetId();
129 // delete the sub menu
130 // -------------------
131 void wxMenuItem::DeleteSubMenu()
140 void wxMenuItem::Enable(bool bDoEnable
)
142 if ( m_bEnabled
!= bDoEnable
) {
143 long rc
= EnableMenuItem(GetHMenuOf(m_pParentMenu
),
146 (bDoEnable
? MF_ENABLED
: MF_GRAYED
));
149 wxLogLastError("EnableMenuItem");
152 m_bEnabled
= bDoEnable
;
156 void wxMenuItem::Check(bool bDoCheck
)
158 wxCHECK_RET( IsCheckable(), "only checkable items may be checked" );
160 if ( m_bChecked
!= bDoCheck
) {
161 long rc
= CheckMenuItem(GetHMenuOf(m_pParentMenu
),
164 (bDoCheck
? MF_CHECKED
: MF_UNCHECKED
));
167 wxLogLastError("CheckMenuItem");
170 m_bChecked
= bDoCheck
;
174 void wxMenuItem::SetName(const wxString
& strName
)
176 // don't do anything if label didn't change
177 if ( m_strName
== strName
)
182 HMENU hMenu
= GetHMenuOf(m_pParentMenu
);
184 UINT id
= GetRealId();
185 UINT flagsOld
= ::GetMenuState(hMenu
, id
, MF_BYCOMMAND
);
186 if ( flagsOld
== 0xFFFFFFFF )
188 wxLogLastError("GetMenuState");
194 // high byte contains the number of items in a submenu for submenus
196 flagsOld
|= MF_POPUP
;
200 #if wxUSE_OWNER_DRAWN
201 if ( IsOwnerDrawn() )
203 flagsOld
|= MF_OWNERDRAW
;
209 flagsOld
|= MF_STRING
;
213 if ( ::ModifyMenu(hMenu
, id
,
214 MF_BYCOMMAND
| flagsOld
,
215 id
, data
) == 0xFFFFFFFF )
217 wxLogLastError("ModifyMenu");