]> git.saurik.com Git - wxWidgets.git/blob - src/mac/menuitem.cpp
fixed menu accelerators
[wxWidgets.git] / src / mac / menuitem.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: menuitem.cpp
3 // Purpose: wxMenuItem implementation
4 // Author: AUTHOR
5 // Modified by:
6 // Created: ??/??/98
7 // RCS-ID: $Id$
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // headers & declarations
14 // ============================================================================
15
16 #include "wx/menu.h"
17 #include "wx/menuitem.h"
18
19 #include <wx/mac/uma.h>
20 // ============================================================================
21 // implementation
22 // ============================================================================
23
24 // ----------------------------------------------------------------------------
25 // dynamic classes implementation
26 // ----------------------------------------------------------------------------
27
28 #if !USE_SHARED_LIBRARY
29 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject)
30 #endif //USE_SHARED_LIBRARY
31
32 // ----------------------------------------------------------------------------
33 // wxMenuItem
34 // ----------------------------------------------------------------------------
35
36 // ctor & dtor
37 // -----------
38
39 wxMenuItem::wxMenuItem(wxMenu *pParentMenu, int id,
40 const wxString& strName, const wxString& strHelp,
41 bool bCheckable,
42 wxMenu *pSubMenu) :
43 m_bCheckable(bCheckable),
44 m_strName(strName),
45 m_strHelp(strHelp)
46 {
47 wxASSERT( pParentMenu != NULL );
48
49 m_pParentMenu = pParentMenu;
50 m_pSubMenu = pSubMenu;
51 m_idItem = id;
52 m_bEnabled = TRUE;
53
54 if ( m_strName == "E&xit" ||m_strName == "Exit" )
55 {
56 m_strName = "Quit\tCtrl+Q" ;
57 }
58 }
59
60 wxMenuItem::~wxMenuItem()
61 {
62 }
63
64 // misc
65 // ----
66
67 // delete the sub menu
68 void wxMenuItem::DeleteSubMenu()
69 {
70 wxASSERT( m_pSubMenu != NULL );
71
72 delete m_pSubMenu;
73 m_pSubMenu = NULL;
74 }
75
76 // change item state
77 // -----------------
78
79 void wxMenuItem::Enable(bool bDoEnable)
80 {
81 if ( m_bEnabled != bDoEnable ) {
82 if ( m_pSubMenu == NULL )
83 {
84 // normal menu item
85 if ( m_pParentMenu->m_macMenuHandle )
86 {
87 int index = m_pParentMenu->MacGetIndexFromItem( this ) ;
88 if ( index >= 1 )
89 {
90 if ( bDoEnable )
91 UMAEnableMenuItem( m_pParentMenu->m_macMenuHandle , index ) ;
92 else
93 UMADisableMenuItem( m_pParentMenu->m_macMenuHandle , index ) ;
94 }
95 }
96 }
97 else
98 {
99 // submenu
100 if ( m_pParentMenu->m_macMenuHandle )
101 {
102 int index = m_pParentMenu->MacGetIndexFromItem( this ) ;
103 if ( index >= 1 )
104 {
105 if ( bDoEnable )
106 UMAEnableMenuItem( m_pParentMenu->m_macMenuHandle , index ) ;
107 else
108 UMADisableMenuItem( m_pParentMenu->m_macMenuHandle , index ) ;
109 }
110 }
111 }
112
113 m_bEnabled = bDoEnable;
114 }
115 }
116
117 void wxMenuItem::Check(bool bDoCheck)
118 {
119 wxCHECK_RET( IsCheckable(), "only checkable items may be checked" );
120
121 if ( m_bChecked != bDoCheck )
122 {
123 m_bChecked = bDoCheck;
124 if ( m_pParentMenu->m_macMenuHandle )
125 {
126 int index = m_pParentMenu->MacGetIndexFromItem( this ) ;
127 if ( index >= 1 )
128 {
129 if ( bDoCheck )
130 ::SetItemMark( m_pParentMenu->m_macMenuHandle , index , 0x12 ) ; // checkmark
131 else
132 ::SetItemMark( m_pParentMenu->m_macMenuHandle , index , 0 ) ; // no mark
133 }
134 }
135 }
136 }