]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/menuitem.cpp
mac adaptions
[wxWidgets.git] / src / mac / carbon / 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& text, const wxString& strHelp,
41 bool bCheckable,
42 wxMenu *pSubMenu)
43 {
44 wxASSERT( pParentMenu != NULL );
45
46 m_parentMenu = pParentMenu;
47 m_subMenu = pSubMenu;
48 m_isEnabled = TRUE;
49 m_isChecked = FALSE;
50 m_id = id;
51 m_text = text;
52 m_isCheckable = bCheckable;
53 m_help = strHelp;
54
55
56 if ( m_text == "E&xit" ||m_text == "Exit" )
57 {
58 m_text = "Quit\tCtrl+Q" ;
59 }
60 }
61
62 wxMenuItem::~wxMenuItem()
63 {
64 }
65
66 // misc
67 // ----
68
69 /*
70
71 // delete the sub menu
72 void wxMenuItem::DeleteSubMenu()
73 {
74 wxASSERT( m_subMenu != NULL );
75
76 delete m_subMenu;
77 m_subMenu = NULL;
78 }
79
80 */
81
82 // change item state
83 // -----------------
84
85 void wxMenuItem::Enable(bool bDoEnable)
86 {
87 if ( m_isEnabled != bDoEnable ) {
88 if ( m_subMenu == NULL )
89 {
90 // normal menu item
91 if ( m_parentMenu->GetHMenu() )
92 {
93 int index = m_parentMenu->MacGetIndexFromItem( this ) ;
94 if ( index >= 1 )
95 {
96 if ( bDoEnable )
97 UMAEnableMenuItem( m_parentMenu->GetHMenu() , index ) ;
98 else
99 UMADisableMenuItem( m_parentMenu->GetHMenu() , index ) ;
100 }
101 }
102 }
103 else
104 {
105 // submenu
106 if ( m_parentMenu->GetHMenu() )
107 {
108 int index = m_parentMenu->MacGetIndexFromItem( this ) ;
109 if ( index >= 1 )
110 {
111 if ( bDoEnable )
112 UMAEnableMenuItem( m_parentMenu->GetHMenu() , index ) ;
113 else
114 UMADisableMenuItem( m_parentMenu->GetHMenu() , index ) ;
115 }
116 }
117 }
118
119 m_isEnabled = bDoEnable;
120 }
121 }
122
123 void wxMenuItem::Check(bool bDoCheck)
124 {
125 wxCHECK_RET( IsCheckable(), "only checkable items may be checked" );
126
127 if ( m_isChecked != bDoCheck )
128 {
129 m_isChecked = bDoCheck;
130 if ( m_parentMenu->GetHMenu() )
131 {
132 int index = m_parentMenu->MacGetIndexFromItem( this ) ;
133 if ( index >= 1 )
134 {
135 if ( bDoCheck )
136 ::SetItemMark( m_parentMenu->GetHMenu() , index , 0x12 ) ; // checkmark
137 else
138 ::SetItemMark( m_parentMenu->GetHMenu() , index , 0 ) ; // no mark
139 }
140 }
141 }
142 }