]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/menuitem.cpp
refreshed makefiles to be in sync with filelist.txt
[wxWidgets.git] / src / mac / carbon / 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 ) ;
e9576ca5
SC
31// ----------------------------------------------------------------------------
32// wxMenuItem
33// ----------------------------------------------------------------------------
34
35// ctor & dtor
36// -----------
37
38wxMenuItem::wxMenuItem(wxMenu *pParentMenu, int id,
e7549107 39 const wxString& text, const wxString& strHelp,
e9576ca5 40 bool bCheckable,
e7549107 41 wxMenu *pSubMenu)
e9576ca5 42{
e7549107 43 wxASSERT( pParentMenu != NULL );
e9576ca5 44
e7549107
SC
45 m_parentMenu = pParentMenu;
46 m_subMenu = pSubMenu;
47 m_isEnabled = TRUE;
48 m_isChecked = FALSE;
49 m_id = id;
50 m_text = text;
51 m_isCheckable = bCheckable;
52 m_help = strHelp;
519cb848 53
e7549107
SC
54
55 if ( m_text == "E&xit" ||m_text == "Exit" )
56 {
57 m_text = "Quit\tCtrl+Q" ;
58 }
e9576ca5
SC
59}
60
61wxMenuItem::~wxMenuItem()
62{
63}
64
51abe921
SC
65bool wxMenuItem::IsChecked() const
66{
67 return wxMenuItemBase::IsChecked() ;
68}
69
70wxString wxMenuItem::GetLabel() const
71{
72 return wxStripMenuCodes(m_text);
73}
74
75// accelerators
76// ------------
77
78#if wxUSE_ACCEL
79
80wxAcceleratorEntry *wxMenuItem::GetAccel() const
81{
82 return wxGetAccelFromString(GetText());
83}
84
85#endif // wxUSE_ACCEL
86
e9576ca5
SC
87// misc
88// ----
89
e7549107
SC
90/*
91
e9576ca5
SC
92// delete the sub menu
93void wxMenuItem::DeleteSubMenu()
94{
e7549107 95 wxASSERT( m_subMenu != NULL );
e9576ca5 96
e7549107
SC
97 delete m_subMenu;
98 m_subMenu = NULL;
e9576ca5
SC
99}
100
e7549107
SC
101*/
102
e9576ca5
SC
103// change item state
104// -----------------
105
106void wxMenuItem::Enable(bool bDoEnable)
107{
e7549107
SC
108 if ( m_isEnabled != bDoEnable ) {
109 if ( m_subMenu == NULL )
519cb848
SC
110 {
111 // normal menu item
e7549107 112 if ( m_parentMenu->GetHMenu() )
519cb848 113 {
e7549107 114 int index = m_parentMenu->MacGetIndexFromItem( this ) ;
519cb848
SC
115 if ( index >= 1 )
116 {
117 if ( bDoEnable )
e7549107 118 UMAEnableMenuItem( m_parentMenu->GetHMenu() , index ) ;
519cb848 119 else
e7549107 120 UMADisableMenuItem( m_parentMenu->GetHMenu() , index ) ;
519cb848
SC
121 }
122 }
e9576ca5 123 }
519cb848 124 else
e9576ca5 125 {
519cb848 126 // submenu
e7549107 127 if ( m_parentMenu->GetHMenu() )
519cb848 128 {
e7549107 129 int index = m_parentMenu->MacGetIndexFromItem( this ) ;
519cb848
SC
130 if ( index >= 1 )
131 {
132 if ( bDoEnable )
e7549107 133 UMAEnableMenuItem( m_parentMenu->GetHMenu() , index ) ;
519cb848 134 else
e7549107 135 UMADisableMenuItem( m_parentMenu->GetHMenu() , index ) ;
519cb848
SC
136 }
137 }
e9576ca5
SC
138 }
139
e7549107 140 m_isEnabled = bDoEnable;
e9576ca5
SC
141 }
142}
143
144void wxMenuItem::Check(bool bDoCheck)
145{
146 wxCHECK_RET( IsCheckable(), "only checkable items may be checked" );
147
e7549107 148 if ( m_isChecked != bDoCheck )
519cb848 149 {
e7549107
SC
150 m_isChecked = bDoCheck;
151 if ( m_parentMenu->GetHMenu() )
519cb848 152 {
e7549107 153 int index = m_parentMenu->MacGetIndexFromItem( this ) ;
519cb848
SC
154 if ( index >= 1 )
155 {
156 if ( bDoCheck )
e7549107 157 ::SetItemMark( m_parentMenu->GetHMenu() , index , 0x12 ) ; // checkmark
519cb848 158 else
e7549107 159 ::SetItemMark( m_parentMenu->GetHMenu() , index , 0 ) ; // no mark
519cb848
SC
160 }
161 }
e9576ca5 162 }
51abe921
SC
163}
164
165void wxMenuItem::SetText(const wxString& text)
166{
167 // don't do anything if label didn't change
168 if ( m_text == text )
169 return;
170
171 wxMenuItemBase::SetText(text);
172// OWNER_DRAWN_ONLY( wxOwnerDrawn::SetName(text) );
173
174 wxCHECK_RET( m_parentMenu && m_parentMenu->GetHMenu(), wxT("menuitem without menu") );
175 if ( m_parentMenu->GetHMenu() )
176 {
177 int index = m_parentMenu->MacGetIndexFromItem( this ) ;
178 if ( index >= 1 )
179 {
180 Str255 label;
181 wxMacBuildMenuString( label , NULL , NULL , text ,false);
182 ::SetMenuItemText( m_parentMenu->GetHMenu() , index , label ) ; // checkmark
183 }
184 }
185
186#if wxUSE_ACCEL
187 m_parentMenu->UpdateAccel(this);
188#endif // wxUSE_ACCEL
189
190}
191void wxMenuItem::SetCheckable(bool checkable)
192{
193 wxMenuItemBase::SetCheckable(checkable);
194 // OWNER_DRAWN_ONLY( wxOwnerDrawn::SetCheckable(checkable) );
195}
196
197// ----------------------------------------------------------------------------
198// wxMenuItemBase
199// ----------------------------------------------------------------------------
200
201wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu,
202 int id,
203 const wxString& name,
204 const wxString& help,
205 bool isCheckable,
206 wxMenu *subMenu)
207{
208 return new wxMenuItem(parentMenu, id, name, help, isCheckable, subMenu);
209}