]> git.saurik.com Git - wxWidgets.git/blob - src/osx/carbon/uma.cpp
Remove old workarounds to get cut, copy, and paste working in embedded wxTextCtrl
[wxWidgets.git] / src / osx / carbon / uma.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/uma.cpp
3 // Purpose: UMA support
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: The wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #include "wx/osx/uma.h"
15
16 #if wxUSE_GUI
17
18 #include "wx/toplevel.h"
19 #include "wx/dc.h"
20
21 #include "wx/osx/uma.h"
22
23 // menu manager
24
25 #if wxOSX_USE_CARBON
26
27 MenuRef UMANewMenu( SInt16 id , const wxString& title , wxFontEncoding encoding )
28 {
29 wxString str = wxStripMenuCodes( title ) ;
30 MenuRef menu ;
31
32 CreateNewMenu( id , 0 , &menu ) ;
33 SetMenuTitleWithCFString( menu , wxCFStringRef(str , encoding ) ) ;
34
35 return menu ;
36 }
37
38 void UMASetMenuTitle( MenuRef menu , const wxString& title , wxFontEncoding encoding )
39 {
40 wxString str = wxStripMenuCodes( title ) ;
41
42 SetMenuTitleWithCFString( menu , wxCFStringRef(str , encoding) ) ;
43 }
44
45 void UMASetMenuItemText( MenuRef menu, MenuItemIndex item, const wxString& title, wxFontEncoding encoding )
46 {
47 // we don't strip the accels here anymore, must be done before
48 wxString str = title ;
49
50 SetMenuItemTextWithCFString( menu , item , wxCFStringRef(str , encoding) ) ;
51 }
52
53 void UMAEnableMenuItem( MenuRef inMenu , MenuItemIndex inItem , bool enable)
54 {
55 if ( enable )
56 EnableMenuItem( inMenu , inItem ) ;
57 else
58 DisableMenuItem( inMenu , inItem ) ;
59 }
60
61 void UMAAppendSubMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , MenuRef submenu )
62 {
63 AppendMenuItemTextWithCFString( menu,
64 CFSTR("A"), 0, 0,NULL);
65 UMASetMenuItemText( menu, (SInt16) ::CountMenuItems(menu), title , encoding );
66 SetMenuItemHierarchicalMenu( menu , CountMenuItems( menu ) , submenu ) ;
67 SetMenuTitleWithCFString(submenu , wxCFStringRef(title , encoding) );
68 }
69
70 void UMAInsertSubMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , MenuItemIndex item , SInt16 id )
71 {
72 InsertMenuItemTextWithCFString( menu,
73 CFSTR("A"), item, 0, 0);
74
75 UMASetMenuItemText( menu, item+1, title , encoding );
76 SetMenuItemHierarchicalID( menu , item+1 , id ) ;
77 }
78
79 void UMASetMenuItemShortcut( MenuRef menu , MenuItemIndex item , wxAcceleratorEntry *entry )
80 {
81 if ( !entry )
82 return ;
83
84 UInt8 modifiers = 0 ;
85 SInt16 key = entry->GetKeyCode() ;
86 if ( key )
87 {
88 bool explicitCommandKey = (entry->GetFlags() & wxACCEL_CTRL);
89
90 if (entry->GetFlags() & wxACCEL_ALT)
91 modifiers |= kMenuOptionModifier ;
92
93 if (entry->GetFlags() & wxACCEL_SHIFT)
94 modifiers |= kMenuShiftModifier ;
95
96 SInt16 glyph = 0 ;
97 SInt16 macKey = key ;
98 if ( key >= WXK_F1 && key <= WXK_F15 )
99 {
100 if ( !explicitCommandKey )
101 modifiers |= kMenuNoCommandModifier ;
102
103 // for some reasons this must be 0 right now
104 // everything else leads to just the first function key item
105 // to be selected. Thanks to Ryan Wilcox for finding out.
106 macKey = 0 ;
107 glyph = kMenuF1Glyph + ( key - WXK_F1 ) ;
108 if ( key >= WXK_F13 )
109 glyph += 12 ;
110 }
111 else
112 {
113 switch ( key )
114 {
115 case WXK_BACK :
116 macKey = kBackspaceCharCode ;
117 glyph = kMenuDeleteLeftGlyph ;
118 break ;
119
120 case WXK_TAB :
121 macKey = kTabCharCode ;
122 glyph = kMenuTabRightGlyph ;
123 break ;
124
125 case kEnterCharCode :
126 macKey = kEnterCharCode ;
127 glyph = kMenuEnterGlyph ;
128 break ;
129
130 case WXK_RETURN :
131 macKey = kReturnCharCode ;
132 glyph = kMenuReturnGlyph ;
133 break ;
134
135 case WXK_ESCAPE :
136 macKey = kEscapeCharCode ;
137 glyph = kMenuEscapeGlyph ;
138 break ;
139
140 case WXK_SPACE :
141 macKey = ' ' ;
142 glyph = kMenuSpaceGlyph ;
143 break ;
144
145 case WXK_DELETE :
146 macKey = kDeleteCharCode ;
147 glyph = kMenuDeleteRightGlyph ;
148 break ;
149
150 case WXK_CLEAR :
151 macKey = kClearCharCode ;
152 glyph = kMenuClearGlyph ;
153 break ;
154
155 case WXK_PAGEUP :
156 macKey = kPageUpCharCode ;
157 glyph = kMenuPageUpGlyph ;
158 break ;
159
160 case WXK_PAGEDOWN :
161 macKey = kPageDownCharCode ;
162 glyph = kMenuPageDownGlyph ;
163 break ;
164
165 case WXK_LEFT :
166 macKey = kLeftArrowCharCode ;
167 glyph = kMenuLeftArrowGlyph ;
168 break ;
169
170 case WXK_UP :
171 macKey = kUpArrowCharCode ;
172 glyph = kMenuUpArrowGlyph ;
173 break ;
174
175 case WXK_RIGHT :
176 macKey = kRightArrowCharCode ;
177 glyph = kMenuRightArrowGlyph ;
178 break ;
179
180 case WXK_DOWN :
181 macKey = kDownArrowCharCode ;
182 glyph = kMenuDownArrowGlyph ;
183 break ;
184
185 case WXK_HOME :
186 macKey = kHomeCharCode ;
187 glyph = kMenuNorthwestArrowGlyph ;
188 break ;
189
190 case WXK_END :
191 macKey = kEndCharCode ;
192 glyph = kMenuSoutheastArrowGlyph ;
193 break ;
194 default :
195 macKey = toupper( key ) ;
196 break ;
197 }
198
199 // we now allow non command key shortcuts
200 // remove in case this gives problems
201 if ( !explicitCommandKey )
202 modifiers |= kMenuNoCommandModifier ;
203 }
204
205 // 1d and 1e have special meaning to SetItemCmd, so
206 // do not use for these character codes.
207 if (key != WXK_UP && key != WXK_RIGHT && key != WXK_DOWN && key != WXK_LEFT)
208 SetItemCmd( menu, item , macKey );
209
210 SetMenuItemModifiers( menu, item , modifiers ) ;
211
212 if ( glyph )
213 SetMenuItemKeyGlyph( menu, item , glyph ) ;
214 }
215 }
216
217 void UMAAppendMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , wxAcceleratorEntry *entry )
218 {
219 AppendMenuItemTextWithCFString( menu,
220 CFSTR("A"), 0, 0,NULL);
221 // don't attempt to interpret metacharacters like a '-' at the beginning (would become a separator otherwise)
222 ChangeMenuItemAttributes( menu , ::CountMenuItems(menu), kMenuItemAttrIgnoreMeta , 0 ) ;
223 UMASetMenuItemText(menu, (SInt16) ::CountMenuItems(menu), title , encoding );
224 UMASetMenuItemShortcut( menu , (SInt16) ::CountMenuItems(menu), entry ) ;
225 }
226
227 void UMAInsertMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , MenuItemIndex item , wxAcceleratorEntry *entry )
228 {
229 InsertMenuItemTextWithCFString( menu,
230 CFSTR("A"), item, 0, 0);
231
232 // don't attempt to interpret metacharacters like a '-' at the beginning (would become a separator otherwise)
233 ChangeMenuItemAttributes( menu , item+1, kMenuItemAttrIgnoreMeta , 0 ) ;
234 UMASetMenuItemText(menu, item+1 , title , encoding );
235 UMASetMenuItemShortcut( menu , item+1 , entry ) ;
236 }
237
238 static OSStatus UMAGetHelpMenu(
239 MenuRef * outHelpMenu,
240 MenuItemIndex * outFirstCustomItemIndex,
241 bool allowHelpMenuCreation);
242
243 static OSStatus UMAGetHelpMenu(
244 MenuRef * outHelpMenu,
245 MenuItemIndex * outFirstCustomItemIndex,
246 bool allowHelpMenuCreation)
247 {
248 static bool s_createdHelpMenu = false ;
249
250 if ( !s_createdHelpMenu && !allowHelpMenuCreation )
251 {
252 return paramErr ;
253 }
254
255 OSStatus status = HMGetHelpMenu( outHelpMenu , outFirstCustomItemIndex ) ;
256 s_createdHelpMenu = ( status == noErr ) ;
257 return status ;
258 }
259
260 OSStatus UMAGetHelpMenu(
261 MenuRef * outHelpMenu,
262 MenuItemIndex * outFirstCustomItemIndex)
263 {
264 return UMAGetHelpMenu( outHelpMenu , outFirstCustomItemIndex , true );
265 }
266
267 OSStatus UMAGetHelpMenuDontCreate(
268 MenuRef * outHelpMenu,
269 MenuItemIndex * outFirstCustomItemIndex)
270 {
271 return UMAGetHelpMenu( outHelpMenu , outFirstCustomItemIndex , false );
272 }
273
274 #endif
275
276 #endif // wxUSE_GUI