]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/menuitem.cpp
1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMenuItem implementation
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
13 // headers & declarations
14 // ============================================================================
17 #include "wx/menuitem.h"
19 #include <wx/mac/uma.h>
20 // ============================================================================
22 // ============================================================================
24 // ----------------------------------------------------------------------------
25 // dynamic classes implementation
26 // ----------------------------------------------------------------------------
28 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem
, wxObject
)
30 void wxMacBuildMenuString(StringPtr outMacItemText
, char *outMacShortcutChar
, short *outMacModifiers
, const char *inItemName
, bool useShortcuts
) ;
32 wxString
wxMenuItemBase::GetLabelFromText(const wxString
& text
)
34 return wxStripMenuCodes(text
);
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
44 wxMenuItem::wxMenuItem(wxMenu
*pParentMenu
, int id
,
45 const wxString
& text
, const wxString
& strHelp
,
49 wxASSERT( pParentMenu
!= NULL
);
51 m_parentMenu
= pParentMenu
;
57 m_isCheckable
= bCheckable
;
61 if ( m_text
== "E&xit" ||m_text
== "Exit" )
63 m_text
= "Quit\tCtrl+Q" ;
67 wxMenuItem::~wxMenuItem()
71 bool wxMenuItem::IsChecked() const
73 return wxMenuItemBase::IsChecked() ;
76 wxString
wxMenuItem::GetLabel() const
78 return wxStripMenuCodes(m_text
);
86 wxAcceleratorEntry
*wxMenuItem::GetAccel() const
88 return wxGetAccelFromString(GetText());
98 // delete the sub menu
99 void wxMenuItem::DeleteSubMenu()
101 wxASSERT( m_subMenu != NULL );
112 void wxMenuItem::Enable(bool bDoEnable
)
114 if ( m_isEnabled
!= bDoEnable
) {
115 if ( m_subMenu
== NULL
)
118 if ( m_parentMenu
->GetHMenu() )
120 int index
= m_parentMenu
->MacGetIndexFromItem( this ) ;
124 UMAEnableMenuItem( m_parentMenu
->GetHMenu() , index
) ;
126 UMADisableMenuItem( m_parentMenu
->GetHMenu() , index
) ;
133 if ( m_parentMenu
->GetHMenu() )
135 int index
= m_parentMenu
->MacGetIndexFromItem( this ) ;
139 UMAEnableMenuItem( m_parentMenu
->GetHMenu() , index
) ;
141 UMADisableMenuItem( m_parentMenu
->GetHMenu() , index
) ;
146 m_isEnabled
= bDoEnable
;
150 void wxMenuItem::Check(bool bDoCheck
)
152 wxCHECK_RET( IsCheckable(), "only checkable items may be checked" );
154 if ( m_isChecked
!= bDoCheck
)
156 m_isChecked
= bDoCheck
;
157 if ( m_parentMenu
->GetHMenu() )
159 int index
= m_parentMenu
->MacGetIndexFromItem( this ) ;
163 ::SetItemMark( m_parentMenu
->GetHMenu() , index
, 0x12 ) ; // checkmark
165 ::SetItemMark( m_parentMenu
->GetHMenu() , index
, 0 ) ; // no mark
171 void wxMenuItem::SetText(const wxString
& text
)
173 // don't do anything if label didn't change
174 if ( m_text
== text
)
177 wxMenuItemBase::SetText(text
);
178 // OWNER_DRAWN_ONLY( wxOwnerDrawn::SetName(text) );
180 wxCHECK_RET( m_parentMenu
&& m_parentMenu
->GetHMenu(), wxT("menuitem without menu") );
181 if ( m_parentMenu
->GetHMenu() )
183 int index
= m_parentMenu
->MacGetIndexFromItem( this ) ;
187 wxMacBuildMenuString( label
, NULL
, NULL
, text
,false);
188 ::SetMenuItemText( m_parentMenu
->GetHMenu() , index
, label
) ; // checkmark
193 m_parentMenu
->UpdateAccel(this);
194 #endif // wxUSE_ACCEL
197 void wxMenuItem::SetCheckable(bool checkable
)
199 wxMenuItemBase::SetCheckable(checkable
);
200 // OWNER_DRAWN_ONLY( wxOwnerDrawn::SetCheckable(checkable) );
203 // ----------------------------------------------------------------------------
205 // ----------------------------------------------------------------------------
207 wxMenuItem
*wxMenuItemBase::New(wxMenu
*parentMenu
,
209 const wxString
& name
,
210 const wxString
& help
,
214 return new wxMenuItem(parentMenu
, id
, name
, help
, isCheckable
, subMenu
);