]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/menuitem.cpp
f7822a730f66148b9ed004bfb9e26bb9eefc46f0
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 // ============================================================================
13 // headers & declarations
14 // ============================================================================
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
27 #include "wx/ownerdrw.h"
28 #include "wx/menuitem.h"
32 // ============================================================================
34 // ============================================================================
36 // ----------------------------------------------------------------------------
37 // dynamic classes implementation
38 // ----------------------------------------------------------------------------
40 #if !defined(USE_SHARED_LIBRARY) || !USE_SHARED_LIBRARY
42 IMPLEMENT_DYNAMIC_CLASS2(wxMenuItem
, wxObject
, wxOwnerDrawn
)
43 #else //!USE_OWNER_DRAWN
44 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem
, wxObject
)
45 #endif //USE_OWNER_DRAWN
47 #endif //USE_SHARED_LIBRARY
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
56 wxMenuItem::wxMenuItem(wxMenu
*pParentMenu
, int id
,
57 const wxString
& strName
, const wxString
& strHelp
,
61 wxOwnerDrawn(strName
, bCheckable
),
62 #else //no owner drawn support
63 m_bCheckable(bCheckable
),
68 wxASSERT( pParentMenu
!= NULL
);
71 // set default menu colors
72 #define SYS_COLOR(c) (wxSystemSettings::GetSystemColour(wxSYS_COLOUR_##c))
74 SetTextColour(SYS_COLOR(MENUTEXT
));
75 SetBackgroundColour(SYS_COLOR(MENU
));
77 // we don't want normal items be owner-drawn
83 m_pParentMenu
= pParentMenu
;
84 m_pSubMenu
= pSubMenu
;
89 wxMenuItem::~wxMenuItem()
96 // delete the sub menu
97 void wxMenuItem::DeleteSubMenu()
99 wxASSERT( m_pSubMenu
!= NULL
);
108 void wxMenuItem::Enable(bool bDoEnable
)
110 if ( m_bEnabled
!= bDoEnable
) {
111 if ( m_pSubMenu
== NULL
) { // normal menu item
112 EnableMenuItem((HMENU
)m_pParentMenu
->GetHMenu(), m_idItem
,
113 MF_BYCOMMAND
| (bDoEnable
? MF_ENABLED
: MF_GRAYED
));
117 wxMenu
*father
= m_pSubMenu
->m_topLevelMenu
;
118 wxNode
*node
= father
->m_menuItems
.First() ;
121 wxMenuItem
*matched
= (wxMenuItem
*)node
->Data();
122 if ( matched
== this)
127 EnableMenuItem((HMENU
)father
->m_savehMenu
, i
,
128 MF_BYPOSITION
| (bDoEnable
? MF_ENABLED
: MF_GRAYED
));
131 m_bEnabled
= bDoEnable
;
135 void wxMenuItem::Check(bool bDoCheck
)
137 wxCHECK_RET( IsCheckable(), "only checkable items may be checked" );
139 if ( m_bChecked
!= bDoCheck
) {
140 CheckMenuItem((HMENU
)m_pParentMenu
->GetHMenu(), m_idItem
,
141 MF_BYCOMMAND
| (bDoCheck
? MF_CHECKED
: MF_UNCHECKED
));
143 m_bChecked
= bDoCheck
;