]> git.saurik.com Git - wxWidgets.git/blob - src/mac/menuitem.cpp
added wxUSE_NOTEBOOK to include/wx/msw/setup0.h, removed wxUSE_RADIOBUTTON (we
[wxWidgets.git] / src / mac / menuitem.cpp
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
19 #include <wx/mac/uma.h>
20 // ============================================================================
21 // implementation
22 // ============================================================================
23
24 // ----------------------------------------------------------------------------
25 // dynamic classes implementation
26 // ----------------------------------------------------------------------------
27
28 IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject)
29
30 void wxMacBuildMenuString(StringPtr outMacItemText, char *outMacShortcutChar , short *outMacModifiers , const char *inItemName , bool useShortcuts ) ;
31 // ----------------------------------------------------------------------------
32 // wxMenuItem
33 // ----------------------------------------------------------------------------
34
35 // ctor & dtor
36 // -----------
37
38 wxMenuItem::wxMenuItem(wxMenu *pParentMenu, int id,
39 const wxString& text, const wxString& strHelp,
40 bool bCheckable,
41 wxMenu *pSubMenu)
42 {
43 wxASSERT( pParentMenu != NULL );
44
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;
53
54
55 if ( m_text == "E&xit" ||m_text == "Exit" )
56 {
57 m_text = "Quit\tCtrl+Q" ;
58 }
59 }
60
61 wxMenuItem::~wxMenuItem()
62 {
63 }
64
65 bool wxMenuItem::IsChecked() const
66 {
67 return wxMenuItemBase::IsChecked() ;
68 }
69
70 wxString wxMenuItem::GetLabel() const
71 {
72 return wxStripMenuCodes(m_text);
73 }
74
75 // accelerators
76 // ------------
77
78 #if wxUSE_ACCEL
79
80 wxAcceleratorEntry *wxMenuItem::GetAccel() const
81 {
82 return wxGetAccelFromString(GetText());
83 }
84
85 #endif // wxUSE_ACCEL
86
87 // misc
88 // ----
89
90 /*
91
92 // delete the sub menu
93 void wxMenuItem::DeleteSubMenu()
94 {
95 wxASSERT( m_subMenu != NULL );
96
97 delete m_subMenu;
98 m_subMenu = NULL;
99 }
100
101 */
102
103 // change item state
104 // -----------------
105
106 void wxMenuItem::Enable(bool bDoEnable)
107 {
108 if ( m_isEnabled != bDoEnable ) {
109 if ( m_subMenu == NULL )
110 {
111 // normal menu item
112 if ( m_parentMenu->GetHMenu() )
113 {
114 int index = m_parentMenu->MacGetIndexFromItem( this ) ;
115 if ( index >= 1 )
116 {
117 if ( bDoEnable )
118 UMAEnableMenuItem( m_parentMenu->GetHMenu() , index ) ;
119 else
120 UMADisableMenuItem( m_parentMenu->GetHMenu() , index ) ;
121 }
122 }
123 }
124 else
125 {
126 // submenu
127 if ( m_parentMenu->GetHMenu() )
128 {
129 int index = m_parentMenu->MacGetIndexFromItem( this ) ;
130 if ( index >= 1 )
131 {
132 if ( bDoEnable )
133 UMAEnableMenuItem( m_parentMenu->GetHMenu() , index ) ;
134 else
135 UMADisableMenuItem( m_parentMenu->GetHMenu() , index ) ;
136 }
137 }
138 }
139
140 m_isEnabled = bDoEnable;
141 }
142 }
143
144 void wxMenuItem::Check(bool bDoCheck)
145 {
146 wxCHECK_RET( IsCheckable(), "only checkable items may be checked" );
147
148 if ( m_isChecked != bDoCheck )
149 {
150 m_isChecked = bDoCheck;
151 if ( m_parentMenu->GetHMenu() )
152 {
153 int index = m_parentMenu->MacGetIndexFromItem( this ) ;
154 if ( index >= 1 )
155 {
156 if ( bDoCheck )
157 ::SetItemMark( m_parentMenu->GetHMenu() , index , 0x12 ) ; // checkmark
158 else
159 ::SetItemMark( m_parentMenu->GetHMenu() , index , 0 ) ; // no mark
160 }
161 }
162 }
163 }
164
165 void 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 }
191 void wxMenuItem::SetCheckable(bool checkable)
192 {
193 wxMenuItemBase::SetCheckable(checkable);
194 // OWNER_DRAWN_ONLY( wxOwnerDrawn::SetCheckable(checkable) );
195 }
196
197 // ----------------------------------------------------------------------------
198 // wxMenuItemBase
199 // ----------------------------------------------------------------------------
200
201 wxMenuItem *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 }