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