]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/menuitem.cpp
Fixed Vadims fix.
[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 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject)
29
30 void wxMacBuildMenuString(StringPtr outMacItemText, char *outMacShortcutChar , short *outMacModifiers , const char *inItemName , bool useShortcuts ) ;
31
32 wxString wxMenuItemBase::GetLabelFromText(const wxString& text)
33 {
34 return wxStripMenuCodes(text);
35 }
36
37 // ----------------------------------------------------------------------------
38 // wxMenuItem
39 // ----------------------------------------------------------------------------
40
41 // ctor & dtor
42 // -----------
43
44 wxMenuItem::wxMenuItem(wxMenu *pParentMenu, int id,
45 const wxString& text, const wxString& strHelp,
46 bool bCheckable,
47 wxMenu *pSubMenu)
48 {
49 wxASSERT( pParentMenu != NULL );
50
51 m_parentMenu = pParentMenu;
52 m_subMenu = pSubMenu;
53 m_isEnabled = TRUE;
54 m_isChecked = FALSE;
55 m_id = id;
56 m_text = text;
57 m_isCheckable = bCheckable;
58 m_help = strHelp;
59
60
61 if ( m_text == "E&xit" ||m_text == "Exit" )
62 {
63 m_text = "Quit\tCtrl+Q" ;
64 }
65 }
66
67 wxMenuItem::~wxMenuItem()
68 {
69 }
70
71 bool wxMenuItem::IsChecked() const
72 {
73 return wxMenuItemBase::IsChecked() ;
74 }
75
76 wxString wxMenuItem::GetLabel() const
77 {
78 return wxStripMenuCodes(m_text);
79 }
80
81 // accelerators
82 // ------------
83
84 #if wxUSE_ACCEL
85
86 wxAcceleratorEntry *wxMenuItem::GetAccel() const
87 {
88 return wxGetAccelFromString(GetText());
89 }
90
91 #endif // wxUSE_ACCEL
92
93 // misc
94 // ----
95
96 /*
97
98 // delete the sub menu
99 void wxMenuItem::DeleteSubMenu()
100 {
101 wxASSERT( m_subMenu != NULL );
102
103 delete m_subMenu;
104 m_subMenu = NULL;
105 }
106
107 */
108
109 // change item state
110 // -----------------
111
112 void wxMenuItem::Enable(bool bDoEnable)
113 {
114 if ( m_isEnabled != bDoEnable ) {
115 if ( m_subMenu == NULL )
116 {
117 // normal menu item
118 if ( m_parentMenu->GetHMenu() )
119 {
120 int index = m_parentMenu->MacGetIndexFromItem( this ) ;
121 if ( index >= 1 )
122 {
123 if ( bDoEnable )
124 UMAEnableMenuItem( m_parentMenu->GetHMenu() , index ) ;
125 else
126 UMADisableMenuItem( m_parentMenu->GetHMenu() , index ) ;
127 }
128 }
129 }
130 else
131 {
132 // submenu
133 if ( m_parentMenu->GetHMenu() )
134 {
135 int index = m_parentMenu->MacGetIndexFromItem( this ) ;
136 if ( index >= 1 )
137 {
138 if ( bDoEnable )
139 UMAEnableMenuItem( m_parentMenu->GetHMenu() , index ) ;
140 else
141 UMADisableMenuItem( m_parentMenu->GetHMenu() , index ) ;
142 }
143 }
144 }
145
146 m_isEnabled = bDoEnable;
147 }
148 }
149
150 void wxMenuItem::Check(bool bDoCheck)
151 {
152 wxCHECK_RET( IsCheckable(), "only checkable items may be checked" );
153
154 if ( m_isChecked != bDoCheck )
155 {
156 m_isChecked = bDoCheck;
157 if ( m_parentMenu->GetHMenu() )
158 {
159 int index = m_parentMenu->MacGetIndexFromItem( this ) ;
160 if ( index >= 1 )
161 {
162 if ( bDoCheck )
163 ::SetItemMark( m_parentMenu->GetHMenu() , index , 0x12 ) ; // checkmark
164 else
165 ::SetItemMark( m_parentMenu->GetHMenu() , index , 0 ) ; // no mark
166 }
167 }
168 }
169 }
170
171 void wxMenuItem::SetText(const wxString& text)
172 {
173 // don't do anything if label didn't change
174 if ( m_text == text )
175 return;
176
177 wxMenuItemBase::SetText(text);
178 // OWNER_DRAWN_ONLY( wxOwnerDrawn::SetName(text) );
179
180 wxCHECK_RET( m_parentMenu && m_parentMenu->GetHMenu(), wxT("menuitem without menu") );
181 if ( m_parentMenu->GetHMenu() )
182 {
183 int index = m_parentMenu->MacGetIndexFromItem( this ) ;
184 if ( index >= 1 )
185 {
186 Str255 label;
187 wxMacBuildMenuString( label , NULL , NULL , text ,false);
188 ::SetMenuItemText( m_parentMenu->GetHMenu() , index , label ) ; // checkmark
189 }
190 }
191
192 #if wxUSE_ACCEL
193 m_parentMenu->UpdateAccel(this);
194 #endif // wxUSE_ACCEL
195
196 }
197 void wxMenuItem::SetCheckable(bool checkable)
198 {
199 wxMenuItemBase::SetCheckable(checkable);
200 // OWNER_DRAWN_ONLY( wxOwnerDrawn::SetCheckable(checkable) );
201 }
202
203 // ----------------------------------------------------------------------------
204 // wxMenuItemBase
205 // ----------------------------------------------------------------------------
206
207 wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu,
208 int id,
209 const wxString& name,
210 const wxString& help,
211 bool isCheckable,
212 wxMenu *subMenu)
213 {
214 return new wxMenuItem(parentMenu, id, name, help, isCheckable, subMenu);
215 }