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()
102 MenuHandle mhandle
= MAC_WXHMENU(m_parentMenu
->GetHMenu()) ;
103 MenuItemIndex index
= m_parentMenu
->MacGetIndexFromItem( this ) ;
104 if( mhandle
== NULL
|| index
== 0)
107 UMAEnableMenuItem( mhandle
, index
, m_isEnabled
) ;
108 if ( IsCheckable() && IsChecked() )
109 ::SetItemMark( mhandle
, index
, 0x12 ) ; // checkmark
111 ::SetItemMark( mhandle
, index
, 0 ) ; // no mark
113 UMASetMenuItemText( mhandle
, index
, m_text
) ;
114 wxAcceleratorEntry
*entry
= wxGetAccelFromString( m_text
) ;
115 UMASetMenuItemShortcut( mhandle
, index
, entry
) ;
119 void wxMenuItem::UpdateItemText()
124 MenuHandle mhandle
= MAC_WXHMENU(m_parentMenu
->GetHMenu()) ;
125 MenuItemIndex index
= m_parentMenu
->MacGetIndexFromItem( this ) ;
126 if( mhandle
== NULL
|| index
== 0)
129 UMASetMenuItemText( mhandle
, index
, m_text
) ;
130 wxAcceleratorEntry
*entry
= wxGetAccelFromString( m_text
) ;
131 UMASetMenuItemShortcut( mhandle
, index
, entry
) ;
136 void wxMenuItem::Enable(bool bDoEnable
)
138 if ( m_isEnabled
!= bDoEnable
)
140 wxMenuItemBase::Enable( bDoEnable
) ;
144 void wxMenuItem::UncheckRadio()
148 wxMenuItemBase::Check( false ) ;
153 void wxMenuItem::Check(bool bDoCheck
)
155 wxCHECK_RET( IsCheckable(), wxT("only checkable items may be checked") );
157 if ( m_isChecked
!= bDoCheck
)
159 if ( GetKind() == wxITEM_RADIO
)
163 wxMenuItemBase::Check( bDoCheck
) ;
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?") );
172 // get the radio group range
176 if ( m_isRadioGroupStart
)
178 // we already have all information we need
180 end
= m_radioGroup
.end
;
182 else // next radio group item
184 // get the radio group end from the start item
185 start
= m_radioGroup
.start
;
186 end
= items
.Item(start
)->GetData()->m_radioGroup
.end
;
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
++ )
195 ((wxMenuItem
*)node
->GetData())->UncheckRadio();
197 node
= node
->GetNext();
203 wxMenuItemBase::Check( bDoCheck
) ;
209 void wxMenuItem::SetText(const wxString
& text
)
211 // don't do anything if label didn't change
212 if ( m_text
== text
)
215 wxMenuItemBase::SetText(text
);
223 void wxMenuItem::SetAsRadioGroupStart()
225 m_isRadioGroupStart
= TRUE
;
228 void wxMenuItem::SetRadioGroupStart(int start
)
230 wxASSERT_MSG( !m_isRadioGroupStart
,
231 _T("should only be called for the next radio items") );
233 m_radioGroup
.start
= start
;
236 void wxMenuItem::SetRadioGroupEnd(int end
)
238 wxASSERT_MSG( m_isRadioGroupStart
,
239 _T("should only be called for the first radio item") );
241 m_radioGroup
.end
= end
;
244 // ----------------------------------------------------------------------------
246 // ----------------------------------------------------------------------------
249 wxString
wxMenuItemBase::GetLabelFromText(const wxString
& text
)
251 return wxStripMenuCodes(text
);
254 wxMenuItem
*wxMenuItemBase::New(wxMenu
*parentMenu
,
256 const wxString
& name
,
257 const wxString
& help
,
261 return new wxMenuItem(parentMenu
, id
, name
, help
, kind
, subMenu
);