]> git.saurik.com Git - wxWidgets.git/blame - src/mac/menuitem.cpp
Committing in .
[wxWidgets.git] / src / mac / menuitem.cpp
CommitLineData
e9576ca5
SC
1///////////////////////////////////////////////////////////////////////////////
2// Name: menuitem.cpp
3// Purpose: wxMenuItem implementation
4// Author: AUTHOR
5// Modified by:
6// Created: ??/??/98
7// RCS-ID: $Id$
8// Copyright: (c) AUTHOR
9// Licence: wxWindows licence
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// headers & declarations
14// ============================================================================
15
16#include "wx/menu.h"
17#include "wx/menuitem.h"
18
519cb848 19#include <wx/mac/uma.h>
e9576ca5
SC
20// ============================================================================
21// implementation
22// ============================================================================
23
24// ----------------------------------------------------------------------------
25// dynamic classes implementation
26// ----------------------------------------------------------------------------
27
e9576ca5 28 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject)
e9576ca5 29
51abe921 30void wxMacBuildMenuString(StringPtr outMacItemText, char *outMacShortcutChar , short *outMacModifiers , const char *inItemName , bool useShortcuts ) ;
37e2cb08
SC
31
32wxString wxMenuItemBase::GetLabelFromText(const wxString& text)
33{
34 return wxStripMenuCodes(text);
35}
36
e9576ca5
SC
37// ----------------------------------------------------------------------------
38// wxMenuItem
39// ----------------------------------------------------------------------------
40
41// ctor & dtor
42// -----------
43
44wxMenuItem::wxMenuItem(wxMenu *pParentMenu, int id,
e7549107 45 const wxString& text, const wxString& strHelp,
e9576ca5 46 bool bCheckable,
e7549107 47 wxMenu *pSubMenu)
e9576ca5 48{
e7549107 49 wxASSERT( pParentMenu != NULL );
e9576ca5 50
e7549107
SC
51 m_parentMenu = pParentMenu;
52 m_subMenu = pSubMenu;
53 m_isEnabled = TRUE;
54 m_isChecked = FALSE;
55 m_id = id;
56 m_text = text;
57 m_isCheckable = bCheckable;
58 m_help = strHelp;
519cb848 59
e7549107
SC
60
61 if ( m_text == "E&xit" ||m_text == "Exit" )
62 {
63 m_text = "Quit\tCtrl+Q" ;
64 }
e9576ca5
SC
65}
66
67wxMenuItem::~wxMenuItem()
68{
69}
70
51abe921
SC
71bool wxMenuItem::IsChecked() const
72{
73 return wxMenuItemBase::IsChecked() ;
74}
75
76wxString wxMenuItem::GetLabel() const
77{
78 return wxStripMenuCodes(m_text);
79}
80
81// accelerators
82// ------------
83
84#if wxUSE_ACCEL
85
86wxAcceleratorEntry *wxMenuItem::GetAccel() const
87{
88 return wxGetAccelFromString(GetText());
89}
90
91#endif // wxUSE_ACCEL
92
e9576ca5
SC
93// misc
94// ----
95
e7549107
SC
96/*
97
e9576ca5
SC
98// delete the sub menu
99void wxMenuItem::DeleteSubMenu()
100{
e7549107 101 wxASSERT( m_subMenu != NULL );
e9576ca5 102
e7549107
SC
103 delete m_subMenu;
104 m_subMenu = NULL;
e9576ca5
SC
105}
106
e7549107
SC
107*/
108
e9576ca5
SC
109// change item state
110// -----------------
111
112void wxMenuItem::Enable(bool bDoEnable)
113{
e7549107
SC
114 if ( m_isEnabled != bDoEnable ) {
115 if ( m_subMenu == NULL )
519cb848
SC
116 {
117 // normal menu item
e7549107 118 if ( m_parentMenu->GetHMenu() )
519cb848 119 {
e7549107 120 int index = m_parentMenu->MacGetIndexFromItem( this ) ;
519cb848
SC
121 if ( index >= 1 )
122 {
123 if ( bDoEnable )
e7549107 124 UMAEnableMenuItem( m_parentMenu->GetHMenu() , index ) ;
519cb848 125 else
e7549107 126 UMADisableMenuItem( m_parentMenu->GetHMenu() , index ) ;
519cb848
SC
127 }
128 }
e9576ca5 129 }
519cb848 130 else
e9576ca5 131 {
519cb848 132 // submenu
e7549107 133 if ( m_parentMenu->GetHMenu() )
519cb848 134 {
e7549107 135 int index = m_parentMenu->MacGetIndexFromItem( this ) ;
519cb848
SC
136 if ( index >= 1 )
137 {
138 if ( bDoEnable )
e7549107 139 UMAEnableMenuItem( m_parentMenu->GetHMenu() , index ) ;
519cb848 140 else
e7549107 141 UMADisableMenuItem( m_parentMenu->GetHMenu() , index ) ;
519cb848
SC
142 }
143 }
e9576ca5
SC
144 }
145
e7549107 146 m_isEnabled = bDoEnable;
e9576ca5
SC
147 }
148}
149
150void wxMenuItem::Check(bool bDoCheck)
151{
152 wxCHECK_RET( IsCheckable(), "only checkable items may be checked" );
153
e7549107 154 if ( m_isChecked != bDoCheck )
519cb848 155 {
e7549107
SC
156 m_isChecked = bDoCheck;
157 if ( m_parentMenu->GetHMenu() )
519cb848 158 {
e7549107 159 int index = m_parentMenu->MacGetIndexFromItem( this ) ;
519cb848
SC
160 if ( index >= 1 )
161 {
162 if ( bDoCheck )
e7549107 163 ::SetItemMark( m_parentMenu->GetHMenu() , index , 0x12 ) ; // checkmark
519cb848 164 else
e7549107 165 ::SetItemMark( m_parentMenu->GetHMenu() , index , 0 ) ; // no mark
519cb848
SC
166 }
167 }
e9576ca5 168 }
51abe921
SC
169}
170
171void wxMenuItem::SetText(const wxString& text)
172{
173 // don't do anything if label didn't change
174 if ( m_text == text )
175 return;
176
177 wxMenuItemBase::SetText(text);
178// OWNER_DRAWN_ONLY( wxOwnerDrawn::SetName(text) );
179
180 wxCHECK_RET( m_parentMenu && m_parentMenu->GetHMenu(), wxT("menuitem without menu") );
181 if ( m_parentMenu->GetHMenu() )
182 {
183 int index = m_parentMenu->MacGetIndexFromItem( this ) ;
184 if ( index >= 1 )
185 {
186 Str255 label;
187 wxMacBuildMenuString( label , NULL , NULL , text ,false);
188 ::SetMenuItemText( m_parentMenu->GetHMenu() , index , label ) ; // checkmark
189 }
190 }
191
192#if wxUSE_ACCEL
193 m_parentMenu->UpdateAccel(this);
194#endif // wxUSE_ACCEL
195
196}
197void wxMenuItem::SetCheckable(bool checkable)
198{
199 wxMenuItemBase::SetCheckable(checkable);
200 // OWNER_DRAWN_ONLY( wxOwnerDrawn::SetCheckable(checkable) );
201}
202
203// ----------------------------------------------------------------------------
204// wxMenuItemBase
205// ----------------------------------------------------------------------------
206
207wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu,
208 int id,
209 const wxString& name,
210 const wxString& help,
211 bool isCheckable,
212 wxMenu *subMenu)
213{
214 return new wxMenuItem(parentMenu, id, name, help, isCheckable, subMenu);
215}