]>
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 #if !USE_SHARED_LIBRARY
29 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem
, wxObject
)
30 #endif //USE_SHARED_LIBRARY
32 void wxMacBuildMenuString(StringPtr outMacItemText
, char *outMacShortcutChar
, short *outMacModifiers
, const char *inItemName
, bool useShortcuts
) ;
33 // ----------------------------------------------------------------------------
35 // ----------------------------------------------------------------------------
40 wxMenuItem::wxMenuItem(wxMenu
*pParentMenu
, int id
,
41 const wxString
& text
, const wxString
& strHelp
,
45 wxASSERT( pParentMenu
!= NULL
);
47 m_parentMenu
= pParentMenu
;
53 m_isCheckable
= bCheckable
;
57 if ( m_text
== "E&xit" ||m_text
== "Exit" )
59 m_text
= "Quit\tCtrl+Q" ;
63 wxMenuItem::~wxMenuItem()
67 bool wxMenuItem::IsChecked() const
69 return wxMenuItemBase::IsChecked() ;
72 wxString
wxMenuItem::GetLabel() const
74 return wxStripMenuCodes(m_text
);
82 wxAcceleratorEntry
*wxMenuItem::GetAccel() const
84 return wxGetAccelFromString(GetText());
94 // delete the sub menu
95 void wxMenuItem::DeleteSubMenu()
97 wxASSERT( m_subMenu != NULL );
108 void wxMenuItem::Enable(bool bDoEnable
)
110 if ( m_isEnabled
!= bDoEnable
) {
111 if ( m_subMenu
== NULL
)
114 if ( m_parentMenu
->GetHMenu() )
116 int index
= m_parentMenu
->MacGetIndexFromItem( this ) ;
120 UMAEnableMenuItem( m_parentMenu
->GetHMenu() , index
) ;
122 UMADisableMenuItem( m_parentMenu
->GetHMenu() , index
) ;
129 if ( m_parentMenu
->GetHMenu() )
131 int index
= m_parentMenu
->MacGetIndexFromItem( this ) ;
135 UMAEnableMenuItem( m_parentMenu
->GetHMenu() , index
) ;
137 UMADisableMenuItem( m_parentMenu
->GetHMenu() , index
) ;
142 m_isEnabled
= bDoEnable
;
146 void wxMenuItem::Check(bool bDoCheck
)
148 wxCHECK_RET( IsCheckable(), "only checkable items may be checked" );
150 if ( m_isChecked
!= bDoCheck
)
152 m_isChecked
= bDoCheck
;
153 if ( m_parentMenu
->GetHMenu() )
155 int index
= m_parentMenu
->MacGetIndexFromItem( this ) ;
159 ::SetItemMark( m_parentMenu
->GetHMenu() , index
, 0x12 ) ; // checkmark
161 ::SetItemMark( m_parentMenu
->GetHMenu() , index
, 0 ) ; // no mark
167 void wxMenuItem::SetText(const wxString
& text
)
169 // don't do anything if label didn't change
170 if ( m_text
== text
)
173 wxMenuItemBase::SetText(text
);
174 // OWNER_DRAWN_ONLY( wxOwnerDrawn::SetName(text) );
176 wxCHECK_RET( m_parentMenu
&& m_parentMenu
->GetHMenu(), wxT("menuitem without menu") );
177 if ( m_parentMenu
->GetHMenu() )
179 int index
= m_parentMenu
->MacGetIndexFromItem( this ) ;
183 wxMacBuildMenuString( label
, NULL
, NULL
, text
,false);
184 ::SetMenuItemText( m_parentMenu
->GetHMenu() , index
, label
) ; // checkmark
189 m_parentMenu
->UpdateAccel(this);
190 #endif // wxUSE_ACCEL
193 void wxMenuItem::SetCheckable(bool checkable
)
195 wxMenuItemBase::SetCheckable(checkable
);
196 // OWNER_DRAWN_ONLY( wxOwnerDrawn::SetCheckable(checkable) );
199 // ----------------------------------------------------------------------------
201 // ----------------------------------------------------------------------------
203 wxMenuItem
*wxMenuItemBase::New(wxMenu
*parentMenu
,
205 const wxString
& name
,
206 const wxString
& help
,
210 return new wxMenuItem(parentMenu
, id
, name
, help
, isCheckable
, subMenu
);