]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/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
) ;
31 // ----------------------------------------------------------------------------
33 // ----------------------------------------------------------------------------
38 wxMenuItem::wxMenuItem(wxMenu
*pParentMenu
, int id
,
39 const wxString
& text
, const wxString
& strHelp
,
43 wxASSERT( pParentMenu
!= NULL
);
45 m_parentMenu
= pParentMenu
;
51 m_isCheckable
= bCheckable
;
55 if ( m_text
== "E&xit" ||m_text
== "Exit" )
57 m_text
= "Quit\tCtrl+Q" ;
61 wxMenuItem::~wxMenuItem()
65 bool wxMenuItem::IsChecked() const
67 return wxMenuItemBase::IsChecked() ;
70 wxString
wxMenuItem::GetLabel() const
72 return wxStripMenuCodes(m_text
);
80 wxAcceleratorEntry
*wxMenuItem::GetAccel() const
82 return wxGetAccelFromString(GetText());
92 // delete the sub menu
93 void wxMenuItem::DeleteSubMenu()
95 wxASSERT( m_subMenu != NULL );
106 void wxMenuItem::Enable(bool bDoEnable
)
108 if ( m_isEnabled
!= bDoEnable
) {
109 if ( m_subMenu
== NULL
)
112 if ( m_parentMenu
->GetHMenu() )
114 int index
= m_parentMenu
->MacGetIndexFromItem( this ) ;
118 UMAEnableMenuItem( m_parentMenu
->GetHMenu() , index
) ;
120 UMADisableMenuItem( m_parentMenu
->GetHMenu() , index
) ;
127 if ( m_parentMenu
->GetHMenu() )
129 int index
= m_parentMenu
->MacGetIndexFromItem( this ) ;
133 UMAEnableMenuItem( m_parentMenu
->GetHMenu() , index
) ;
135 UMADisableMenuItem( m_parentMenu
->GetHMenu() , index
) ;
140 m_isEnabled
= bDoEnable
;
144 void wxMenuItem::Check(bool bDoCheck
)
146 wxCHECK_RET( IsCheckable(), "only checkable items may be checked" );
148 if ( m_isChecked
!= bDoCheck
)
150 m_isChecked
= bDoCheck
;
151 if ( m_parentMenu
->GetHMenu() )
153 int index
= m_parentMenu
->MacGetIndexFromItem( this ) ;
157 ::SetItemMark( m_parentMenu
->GetHMenu() , index
, 0x12 ) ; // checkmark
159 ::SetItemMark( m_parentMenu
->GetHMenu() , index
, 0 ) ; // no mark
165 void wxMenuItem::SetText(const wxString
& text
)
167 // don't do anything if label didn't change
168 if ( m_text
== text
)
171 wxMenuItemBase::SetText(text
);
172 // OWNER_DRAWN_ONLY( wxOwnerDrawn::SetName(text) );
174 wxCHECK_RET( m_parentMenu
&& m_parentMenu
->GetHMenu(), wxT("menuitem without menu") );
175 if ( m_parentMenu
->GetHMenu() )
177 int index
= m_parentMenu
->MacGetIndexFromItem( this ) ;
181 wxMacBuildMenuString( label
, NULL
, NULL
, text
,false);
182 ::SetMenuItemText( m_parentMenu
->GetHMenu() , index
, label
) ; // checkmark
187 m_parentMenu
->UpdateAccel(this);
188 #endif // wxUSE_ACCEL
191 void wxMenuItem::SetCheckable(bool checkable
)
193 wxMenuItemBase::SetCheckable(checkable
);
194 // OWNER_DRAWN_ONLY( wxOwnerDrawn::SetCheckable(checkable) );
197 // ----------------------------------------------------------------------------
199 // ----------------------------------------------------------------------------
201 wxMenuItem
*wxMenuItemBase::New(wxMenu
*parentMenu
,
203 const wxString
& name
,
204 const wxString
& help
,
208 return new wxMenuItem(parentMenu
, id
, name
, help
, isCheckable
, subMenu
);