]> git.saurik.com Git - wxWidgets.git/blame - src/mac/menuitem.cpp
not neede anymore
[wxWidgets.git] / src / mac / menuitem.cpp
CommitLineData
e9576ca5
SC
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
03e11df5 16#include "wx/app.h"
e9576ca5
SC
17#include "wx/menu.h"
18#include "wx/menuitem.h"
19
d497dca4 20#include "wx/mac/uma.h"
e9576ca5
SC
21// ============================================================================
22// implementation
23// ============================================================================
24
25// ----------------------------------------------------------------------------
26// dynamic classes implementation
27// ----------------------------------------------------------------------------
28
2f1ae414 29#if !USE_SHARED_LIBRARY
e9576ca5 30 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject)
2f1ae414 31#endif //USE_SHARED_LIBRARY
37e2cb08 32
e9576ca5
SC
33// ----------------------------------------------------------------------------
34// wxMenuItem
35// ----------------------------------------------------------------------------
36
2f1ae414 37//
e9576ca5
SC
38// ctor & dtor
39// -----------
40
d65c269b
VZ
41wxMenuItem::wxMenuItem(wxMenu *pParentMenu,
42 int id,
43 const wxString& text,
44 const wxString& strHelp,
45 wxItemKind kind,
e7549107 46 wxMenu *pSubMenu)
d65c269b 47 : wxMenuItemBase(pParentMenu, id, text, strHelp, kind, pSubMenu)
e9576ca5 48{
bf918b97
SC
49 // In other languages there is no difference in naming the Exit/Quit menu item between MacOS and Windows guidelines
50 // therefore these item must not be translated
51 if ( wxStripMenuCodes(m_text).Upper() == "EXIT" )
e7549107
SC
52 {
53 m_text = "Quit\tCtrl+Q" ;
54 }
bf918b97
SC
55
56 m_radioGroup.start = -1;
57 m_isRadioGroupStart = FALSE;
e9576ca5
SC
58}
59
60wxMenuItem::~wxMenuItem()
61{
62}
63
bf918b97
SC
64// change item state
65// -----------------
51abe921 66
bf918b97
SC
67void wxMenuItem::SetBitmap(const wxBitmap& bitmap)
68{
69 m_bitmap = bitmap;
70 UpdateItemBitmap() ;
51abe921
SC
71}
72
bf918b97 73void wxMenuItem::UpdateItemBitmap()
51abe921 74{
bf918b97
SC
75 if ( !m_parentMenu )
76 return ;
77
78 MenuHandle mhandle = MAC_WXHMENU(m_parentMenu->GetHMenu()) ;
79 MenuItemIndex index = m_parentMenu->MacGetIndexFromItem( this ) ;
80 if( mhandle == NULL || index == 0)
81 return ;
82
83 if ( m_bitmap.Ok() )
84 {
85 ControlButtonContentInfo info ;
86 wxMacCreateBitmapButton( &info , m_bitmap , kControlContentCIconHandle ) ;
87 if ( info.contentType != kControlNoContent )
88 {
89 if ( info.contentType == kControlContentCIconHandle )
90 SetMenuItemIconHandle( mhandle , index ,
91 kMenuColorIconType , (Handle) info.u.cIconHandle ) ;
92 }
93
94 }
51abe921
SC
95}
96
bf918b97 97void wxMenuItem::UpdateItemStatus()
e9576ca5 98{
bf918b97
SC
99 if ( !m_parentMenu )
100 return ;
101
102 MenuHandle mhandle = MAC_WXHMENU(m_parentMenu->GetHMenu()) ;
103 MenuItemIndex index = m_parentMenu->MacGetIndexFromItem( this ) ;
104 if( mhandle == NULL || index == 0)
105 return ;
106
107 UMAEnableMenuItem( mhandle , index , m_isEnabled ) ;
108 if ( IsCheckable() && IsChecked() )
109 ::SetItemMark( mhandle , index , 0x12 ) ; // checkmark
110 else
111 ::SetItemMark( mhandle , index , 0 ) ; // no mark
e9576ca5 112
bf918b97
SC
113 UMASetMenuItemText( mhandle , index , m_text ) ;
114 wxAcceleratorEntry *entry = wxGetAccelFromString( m_text ) ;
115 UMASetMenuItemShortcut( mhandle , index , entry ) ;
116 delete entry ;
e9576ca5
SC
117}
118
bf918b97
SC
119void wxMenuItem::UpdateItemText()
120{
121 if ( !m_parentMenu )
122 return ;
123
124 MenuHandle mhandle = MAC_WXHMENU(m_parentMenu->GetHMenu()) ;
125 MenuItemIndex index = m_parentMenu->MacGetIndexFromItem( this ) ;
126 if( mhandle == NULL || index == 0)
127 return ;
128
129 UMASetMenuItemText( mhandle , index , m_text ) ;
130 wxAcceleratorEntry *entry = wxGetAccelFromString( m_text ) ;
131 UMASetMenuItemShortcut( mhandle , index , entry ) ;
132 delete entry ;
133}
e7549107 134
e9576ca5
SC
135
136void wxMenuItem::Enable(bool bDoEnable)
137{
bf918b97
SC
138 if ( m_isEnabled != bDoEnable )
139 {
140 wxMenuItemBase::Enable( bDoEnable ) ;
141 UpdateItemStatus() ;
142 }
143}
144void wxMenuItem::UncheckRadio()
145{
146 if ( m_isChecked )
147 {
148 wxMenuItemBase::Check( false ) ;
149 UpdateItemStatus() ;
150 }
e9576ca5
SC
151}
152
153void wxMenuItem::Check(bool bDoCheck)
154{
bf918b97 155 wxCHECK_RET( IsCheckable(), "only checkable items may be checked" );
e9576ca5 156
bf918b97
SC
157 if ( m_isChecked != bDoCheck )
158 {
159 if ( GetKind() == wxITEM_RADIO )
160 {
161 if ( bDoCheck )
162 {
163 wxMenuItemBase::Check( bDoCheck ) ;
164 UpdateItemStatus() ;
165
166 // get the index of this item in the menu
167 const wxMenuItemList& items = m_parentMenu->GetMenuItems();
168 int pos = items.IndexOf(this);
169 wxCHECK_RET( pos != wxNOT_FOUND,
170 _T("menuitem not found in the menu items list?") );
171
172 // get the radio group range
173 int start,
174 end;
175
176 if ( m_isRadioGroupStart )
177 {
178 // we already have all information we need
179 start = pos;
180 end = m_radioGroup.end;
181 }
182 else // next radio group item
183 {
184 // get the radio group end from the start item
185 start = m_radioGroup.start;
186 end = items.Item(start)->GetData()->m_radioGroup.end;
187 }
188
189 // also uncheck all the other items in this radio group
190 wxMenuItemList::Node *node = items.Item(start);
191 for ( int n = start; n <= end && node; n++ )
192 {
193 if ( n != pos )
194 {
195 ((wxMenuItem*)node->GetData())->UncheckRadio();
196 }
197 node = node->GetNext();
198 }
199 }
200 }
201 else
202 {
203 wxMenuItemBase::Check( bDoCheck ) ;
204 UpdateItemStatus() ;
205 }
206 }
51abe921
SC
207}
208
209void wxMenuItem::SetText(const wxString& text)
210{
211 // don't do anything if label didn't change
212 if ( m_text == text )
213 return;
214
215 wxMenuItemBase::SetText(text);
bf918b97
SC
216
217 UpdateItemText() ;
218}
51abe921 219
bf918b97
SC
220// radio group stuff
221// -----------------
51abe921 222
bf918b97
SC
223void wxMenuItem::SetAsRadioGroupStart()
224{
225 m_isRadioGroupStart = TRUE;
51abe921 226}
bf918b97
SC
227
228void wxMenuItem::SetRadioGroupStart(int start)
51abe921 229{
bf918b97
SC
230 wxASSERT_MSG( !m_isRadioGroupStart,
231 _T("should only be called for the next radio items") );
232
233 m_radioGroup.start = start;
234}
235
236void wxMenuItem::SetRadioGroupEnd(int end)
237{
238 wxASSERT_MSG( m_isRadioGroupStart,
239 _T("should only be called for the first radio item") );
240
241 m_radioGroup.end = end;
51abe921
SC
242}
243
244// ----------------------------------------------------------------------------
245// wxMenuItemBase
246// ----------------------------------------------------------------------------
247
2f1ae414
SC
248/* static */
249wxString wxMenuItemBase::GetLabelFromText(const wxString& text)
250{
251 return wxStripMenuCodes(text);
252}
253
51abe921
SC
254wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu,
255 int id,
256 const wxString& name,
257 const wxString& help,
d65c269b 258 wxItemKind kind,
51abe921
SC
259 wxMenu *subMenu)
260{
d65c269b 261 return new wxMenuItem(parentMenu, id, name, help, kind, subMenu);
51abe921 262}