]>
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"
36 // ============================================================================
38 // ============================================================================
40 // ----------------------------------------------------------------------------
41 // dynamic classes implementation
42 // ----------------------------------------------------------------------------
44 #if !defined(USE_SHARED_LIBRARY) || !USE_SHARED_LIBRARY
46 IMPLEMENT_DYNAMIC_CLASS2(wxMenuItem
, wxObject
, wxOwnerDrawn
)
47 #else //!USE_OWNER_DRAWN
48 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem
, wxObject
)
49 #endif //USE_OWNER_DRAWN
51 #endif //USE_SHARED_LIBRARY
53 // ----------------------------------------------------------------------------
55 // ----------------------------------------------------------------------------
60 wxMenuItem::wxMenuItem(wxMenu
*pParentMenu
, int id
,
61 const wxString
& strName
, const wxString
& strHelp
,
65 wxOwnerDrawn(strName
, bCheckable
),
66 #else //no owner drawn support
67 m_bCheckable(bCheckable
),
72 wxASSERT( pParentMenu
!= NULL
);
75 // set default menu colors
76 #define SYS_COLOR(c) (wxSystemSettings::GetSystemColour(wxSYS_COLOUR_##c))
78 SetTextColour(SYS_COLOR(MENUTEXT
));
79 SetBackgroundColour(SYS_COLOR(MENU
));
81 // we don't want normal items be owner-drawn
87 m_pParentMenu
= pParentMenu
;
88 m_pSubMenu
= pSubMenu
;
93 wxMenuItem::~wxMenuItem()
100 // delete the sub menu
101 void wxMenuItem::DeleteSubMenu()
103 wxASSERT( m_pSubMenu
!= NULL
);
112 void wxMenuItem::Enable(bool bDoEnable
)
114 if ( m_bEnabled
!= bDoEnable
) {
115 if ( m_pSubMenu
== NULL
) { // normal menu item
116 EnableMenuItem((HMENU
)m_pParentMenu
->GetHMenu(), m_idItem
,
117 MF_BYCOMMAND
| (bDoEnable
? MF_ENABLED
: MF_GRAYED
));
121 wxMenu
*father
= m_pSubMenu
->m_topLevelMenu
;
122 wxNode
*node
= father
->m_menuItems
.First() ;
125 wxMenuItem
*matched
= (wxMenuItem
*)node
->Data();
126 if ( matched
== this)
131 EnableMenuItem((HMENU
)father
->m_savehMenu
, i
,
132 MF_BYPOSITION
| (bDoEnable
? MF_ENABLED
: MF_GRAYED
));
135 m_bEnabled
= bDoEnable
;
139 void wxMenuItem::Check(bool bDoCheck
)
141 wxCHECK_RET( IsCheckable(), "only checkable items may be checked" );
143 if ( m_bChecked
!= bDoCheck
) {
144 CheckMenuItem((HMENU
)m_pParentMenu
->GetHMenu(), m_idItem
,
145 MF_BYCOMMAND
| (bDoCheck
? MF_CHECKED
: MF_UNCHECKED
));
147 m_bChecked
= bDoCheck
;