1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMenuItem implementation
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
13 // headers & declarations
14 // ============================================================================
18 #include "wx/menuitem.h"
20 #include "wx/mac/uma.h"
21 // ============================================================================
23 // ============================================================================
25 // ----------------------------------------------------------------------------
26 // dynamic classes implementation
27 // ----------------------------------------------------------------------------
29 #if !USE_SHARED_LIBRARY
30 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem
, wxObject
)
31 #endif //USE_SHARED_LIBRARY
33 // ----------------------------------------------------------------------------
35 // ----------------------------------------------------------------------------
41 wxMenuItem::wxMenuItem(wxMenu
*pParentMenu
,
44 const wxString
& strHelp
,
47 : wxMenuItemBase(pParentMenu
, id
, text
, strHelp
, kind
, pSubMenu
)
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() == wxT("EXIT") )
53 m_text
=wxT("Quit\tCtrl+Q") ;
56 m_radioGroup
.start
= -1;
57 m_isRadioGroupStart
= FALSE
;
60 wxMenuItem::~wxMenuItem()
67 void wxMenuItem::SetBitmap(const wxBitmap
& bitmap
)
73 void wxMenuItem::UpdateItemBitmap()
78 MenuHandle mhandle
= MAC_WXHMENU(m_parentMenu
->GetHMenu()) ;
79 MenuItemIndex index
= m_parentMenu
->MacGetIndexFromItem( this ) ;
80 if( mhandle
== NULL
|| index
== 0)
85 ControlButtonContentInfo info
;
86 wxMacCreateBitmapButton( &info
, m_bitmap
, kControlContentCIconHandle
) ;
87 if ( info
.contentType
!= kControlNoContent
)
89 if ( info
.contentType
== kControlContentCIconHandle
)
90 SetMenuItemIconHandle( mhandle
, index
,
91 kMenuColorIconType
, (Handle
) info
.u
.cIconHandle
) ;
97 void wxMenuItem::UpdateItemStatus()
103 if ( UMAGetSystemVersion() >= 0x1000 && GetId() == wxApp::s_macPreferencesMenuItemId
)
106 DisableMenuCommand( NULL
, kHICommandPreferences
) ;
108 EnableMenuCommand( NULL
, kHICommandPreferences
) ;
110 if ( UMAGetSystemVersion() >= 0x1000 && GetId() == wxApp::s_macExitMenuItemId
)
113 DisableMenuCommand( NULL
, kHICommandQuit
) ;
115 EnableMenuCommand( NULL
, kHICommandQuit
) ;
119 MenuHandle mhandle
= MAC_WXHMENU(m_parentMenu
->GetHMenu()) ;
120 MenuItemIndex index
= m_parentMenu
->MacGetIndexFromItem( this ) ;
121 if( mhandle
== NULL
|| index
== 0)
124 UMAEnableMenuItem( mhandle
, index
, m_isEnabled
) ;
125 if ( IsCheckable() && IsChecked() )
126 ::SetItemMark( mhandle
, index
, 0x12 ) ; // checkmark
128 ::SetItemMark( mhandle
, index
, 0 ) ; // no mark
130 UMASetMenuItemText( mhandle
, index
, m_text
) ;
131 wxAcceleratorEntry
*entry
= wxGetAccelFromString( m_text
) ;
132 UMASetMenuItemShortcut( mhandle
, index
, entry
) ;
137 void wxMenuItem::UpdateItemText()
142 MenuHandle mhandle
= MAC_WXHMENU(m_parentMenu
->GetHMenu()) ;
143 MenuItemIndex index
= m_parentMenu
->MacGetIndexFromItem( this ) ;
144 if( mhandle
== NULL
|| index
== 0)
147 UMASetMenuItemText( mhandle
, index
, m_text
) ;
148 wxAcceleratorEntry
*entry
= wxGetAccelFromString( m_text
) ;
149 UMASetMenuItemShortcut( mhandle
, index
, entry
) ;
154 void wxMenuItem::Enable(bool bDoEnable
)
156 if ( m_isEnabled
!= bDoEnable
)
158 wxMenuItemBase::Enable( bDoEnable
) ;
162 void wxMenuItem::UncheckRadio()
166 wxMenuItemBase::Check( false ) ;
171 void wxMenuItem::Check(bool bDoCheck
)
173 wxCHECK_RET( IsCheckable(), wxT("only checkable items may be checked") );
175 if ( m_isChecked
!= bDoCheck
)
177 if ( GetKind() == wxITEM_RADIO
)
181 wxMenuItemBase::Check( bDoCheck
) ;
184 // get the index of this item in the menu
185 const wxMenuItemList
& items
= m_parentMenu
->GetMenuItems();
186 int pos
= items
.IndexOf(this);
187 wxCHECK_RET( pos
!= wxNOT_FOUND
,
188 _T("menuitem not found in the menu items list?") );
190 // get the radio group range
194 if ( m_isRadioGroupStart
)
196 // we already have all information we need
198 end
= m_radioGroup
.end
;
200 else // next radio group item
202 // get the radio group end from the start item
203 start
= m_radioGroup
.start
;
204 end
= items
.Item(start
)->GetData()->m_radioGroup
.end
;
207 // also uncheck all the other items in this radio group
208 wxMenuItemList::Node
*node
= items
.Item(start
);
209 for ( int n
= start
; n
<= end
&& node
; n
++ )
213 ((wxMenuItem
*)node
->GetData())->UncheckRadio();
215 node
= node
->GetNext();
221 wxMenuItemBase::Check( bDoCheck
) ;
227 void wxMenuItem::SetText(const wxString
& text
)
229 // don't do anything if label didn't change
230 if ( m_text
== text
)
233 wxMenuItemBase::SetText(text
);
241 void wxMenuItem::SetAsRadioGroupStart()
243 m_isRadioGroupStart
= TRUE
;
246 void wxMenuItem::SetRadioGroupStart(int start
)
248 wxASSERT_MSG( !m_isRadioGroupStart
,
249 _T("should only be called for the next radio items") );
251 m_radioGroup
.start
= start
;
254 void wxMenuItem::SetRadioGroupEnd(int end
)
256 wxASSERT_MSG( m_isRadioGroupStart
,
257 _T("should only be called for the first radio item") );
259 m_radioGroup
.end
= end
;
262 // ----------------------------------------------------------------------------
264 // ----------------------------------------------------------------------------
267 wxString
wxMenuItemBase::GetLabelFromText(const wxString
& text
)
269 return wxStripMenuCodes(text
);
272 wxMenuItem
*wxMenuItemBase::New(wxMenu
*parentMenu
,
274 const wxString
& name
,
275 const wxString
& help
,
279 return new wxMenuItem(parentMenu
, id
, name
, help
, kind
, subMenu
);