]>
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"
43 #include "wx/msw/private.h"
45 // ---------------------------------------------------------------------------
47 // ---------------------------------------------------------------------------
49 #define GetHMenuOf(menu) ((HMENU)menu->GetHMenu())
51 // ============================================================================
53 // ============================================================================
55 // ----------------------------------------------------------------------------
56 // dynamic classes implementation
57 // ----------------------------------------------------------------------------
59 #if !defined(USE_SHARED_LIBRARY) || !USE_SHARED_LIBRARY
61 IMPLEMENT_DYNAMIC_CLASS2(wxMenuItem
, wxObject
, wxOwnerDrawn
)
62 #else //!USE_OWNER_DRAWN
63 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem
, wxObject
)
64 #endif //USE_OWNER_DRAWN
66 #endif //USE_SHARED_LIBRARY
68 // ----------------------------------------------------------------------------
70 // ----------------------------------------------------------------------------
75 wxMenuItem::wxMenuItem(wxMenu
*pParentMenu
, int id
,
76 const wxString
& strName
, const wxString
& strHelp
,
80 wxOwnerDrawn(strName
, bCheckable
),
81 #else //no owner drawn support
82 m_bCheckable(bCheckable
),
87 wxASSERT_MSG( pParentMenu
!= NULL
, "a menu item should have a parent" );
90 // set default menu colors
91 #define SYS_COLOR(c) (wxSystemSettings::GetSystemColour(wxSYS_COLOUR_##c))
93 SetTextColour(SYS_COLOR(MENUTEXT
));
94 SetBackgroundColour(SYS_COLOR(MENU
));
96 // we don't want normal items be owner-drawn
102 m_pParentMenu
= pParentMenu
;
103 m_pSubMenu
= pSubMenu
;
108 wxMenuItem::~wxMenuItem()
115 // return the id for calling Win32 API functions
116 int wxMenuItem::GetRealId() const
118 return m_pSubMenu
? (int)m_pSubMenu
->GetHMenu() : GetId();
121 // delete the sub menu
122 // -------------------
123 void wxMenuItem::DeleteSubMenu()
132 void wxMenuItem::Enable(bool bDoEnable
)
134 if ( m_bEnabled
!= bDoEnable
) {
135 long rc
= EnableMenuItem(GetHMenuOf(m_pParentMenu
),
138 (bDoEnable
? MF_ENABLED
: MF_GRAYED
));
141 wxLogLastError("EnableMenuItem");
144 m_bEnabled
= bDoEnable
;
148 void wxMenuItem::Check(bool bDoCheck
)
150 wxCHECK_RET( IsCheckable(), "only checkable items may be checked" );
152 if ( m_bChecked
!= bDoCheck
) {
153 long rc
= CheckMenuItem(GetHMenuOf(m_pParentMenu
),
156 (bDoCheck
? MF_CHECKED
: MF_UNCHECKED
));
159 wxLogLastError("CheckMenuItem");
162 m_bChecked
= bDoCheck
;
166 void wxMenuItem::SetName(const wxString
& strName
)
168 // don't do anything if label didn't change
169 if ( m_strName
== strName
)
174 HMENU hMenu
= GetHMenuOf(m_pParentMenu
);
176 UINT id
= GetRealId();
177 UINT flagsOld
= ::GetMenuState(hMenu
, id
, MF_BYCOMMAND
);
178 if ( flagsOld
== 0xFFFFFFFF )
180 wxLogLastError("GetMenuState");
186 // high byte contains the number of items in a submenu for submenus
188 flagsOld
|= MF_POPUP
;
192 #if wxUSE_OWNER_DRAWN
193 if ( IsOwnerDrawn() )
195 flagsOld
|= MF_OWNERDRAW
;
201 flagsOld
|= MF_STRING
;
205 if ( ::ModifyMenu(hMenu
, id
,
206 MF_BYCOMMAND
| flagsOld
,
207 id
, data
) == 0xFFFFFFFF )
209 wxLogLastError("ModifyMenu");