]>
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 ///////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "menuitem.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
26 #include "wx/bitmap.h"
27 #include "wx/settings.h"
31 #include "wx/ownerdrw.h"
32 #include "wx/menuitem.h"
44 // ============================================================================
46 // ============================================================================
48 // ----------------------------------------------------------------------------
49 // dynamic classes implementation
50 // ----------------------------------------------------------------------------
52 #if !defined(USE_SHARED_LIBRARY) || !USE_SHARED_LIBRARY
54 IMPLEMENT_DYNAMIC_CLASS2(wxMenuItem
, wxObject
, wxOwnerDrawn
)
55 #else //!USE_OWNER_DRAWN
56 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem
, wxObject
)
57 #endif //USE_OWNER_DRAWN
59 #endif //USE_SHARED_LIBRARY
61 // ----------------------------------------------------------------------------
63 // ----------------------------------------------------------------------------
68 wxMenuItem::wxMenuItem(wxMenu
*pParentMenu
, int id
,
69 const wxString
& strName
, const wxString
& strHelp
,
73 wxOwnerDrawn(strName
, bCheckable
),
74 #else //no owner drawn support
75 m_bCheckable(bCheckable
),
80 wxASSERT( pParentMenu
!= NULL
);
83 // set default menu colors
84 #define SYS_COLOR(c) (wxSystemSettings::GetSystemColour(wxSYS_COLOUR_##c))
86 SetTextColour(SYS_COLOR(MENUTEXT
));
87 SetBackgroundColour(SYS_COLOR(MENU
));
89 // we don't want normal items be owner-drawn
95 m_pParentMenu
= pParentMenu
;
96 m_pSubMenu
= pSubMenu
;
101 wxMenuItem::~wxMenuItem()
108 // delete the sub menu
109 void wxMenuItem::DeleteSubMenu()
111 wxASSERT( m_pSubMenu
!= NULL
);
120 void wxMenuItem::Enable(bool bDoEnable
)
122 if ( m_bEnabled
!= bDoEnable
) {
123 if ( m_pSubMenu
== NULL
) { // normal menu item
124 EnableMenuItem((HMENU
)m_pParentMenu
->GetHMenu(), m_idItem
,
125 MF_BYCOMMAND
| (bDoEnable
? MF_ENABLED
: MF_GRAYED
));
129 wxMenu
*father
= m_pSubMenu
->m_topLevelMenu
;
130 wxNode
*node
= father
->m_menuItems
.First() ;
133 wxMenuItem
*matched
= (wxMenuItem
*)node
->Data();
134 if ( matched
== this)
139 EnableMenuItem((HMENU
)father
->m_savehMenu
, i
,
140 MF_BYPOSITION
| (bDoEnable
? MF_ENABLED
: MF_GRAYED
));
143 m_bEnabled
= bDoEnable
;
147 void wxMenuItem::Check(bool bDoCheck
)
149 wxCHECK_RET( IsCheckable(), "only checkable items may be checked" );
151 if ( m_bChecked
!= bDoCheck
) {
152 CheckMenuItem((HMENU
)m_pParentMenu
->GetHMenu(), m_idItem
,
153 MF_BYCOMMAND
| (bDoCheck
? MF_CHECKED
: MF_UNCHECKED
));
155 m_bChecked
= bDoCheck
;