]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/uma.cpp
don't encode collons in file:// URLs under Windows as IE is incapable of opening...
[wxWidgets.git] / src / mac / carbon / uma.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/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/mac/uma.h"
15
16 #if wxUSE_GUI
17
18 #include "wx/toplevel.h"
19 #include "wx/dc.h"
20
21 #include "wx/mac/uma.h"
22
23 static SInt32 sUMASystemVersion = 0 ;
24
25 long UMAGetSystemVersion()
26 {
27 if ( sUMASystemVersion == 0 )
28 {
29 verify_noerr(Gestalt(gestaltSystemVersion, &sUMASystemVersion));
30 }
31 return sUMASystemVersion ;
32 }
33
34 void UMAInitToolbox( UInt16 WXUNUSED(inMoreMastersCalls),
35 bool WXUNUSED(isEmbedded) )
36 {
37 #if 0 // ndef __LP64__
38 {
39 FontFamilyID fontId ;
40 Str255 fontName ;
41 SInt16 fontSize ;
42 Style fontStyle ;
43
44 GetThemeFont(kThemeSmallSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ;
45 GetFNum( fontName, &fontId );
46
47 TXNMacOSPreferredFontDescription fontDescriptions[] =
48 {
49 { fontId , (fontSize << 16) , kTXNDefaultFontStyle, kTXNSystemDefaultEncoding }
50 } ;
51 int noOfFontDescriptions = sizeof( fontDescriptions ) / sizeof(TXNMacOSPreferredFontDescription) ;
52
53 OptionBits options = 0 ;
54
55 TXNInitTextension( fontDescriptions, noOfFontDescriptions, options );
56 }
57 #endif
58 }
59
60 // menu manager
61
62 #if wxMAC_USE_COCOA == 0
63
64 MenuRef UMANewMenu( SInt16 id , const wxString& title , wxFontEncoding encoding )
65 {
66 wxString str = wxStripMenuCodes( title ) ;
67 MenuRef menu ;
68
69 CreateNewMenu( id , 0 , &menu ) ;
70 SetMenuTitleWithCFString( menu , wxCFStringRef(str , encoding ) ) ;
71
72 return menu ;
73 }
74
75 void UMASetMenuTitle( MenuRef menu , const wxString& title , wxFontEncoding encoding )
76 {
77 wxString str = wxStripMenuCodes( title ) ;
78
79 SetMenuTitleWithCFString( menu , wxCFStringRef(str , encoding) ) ;
80 }
81
82 void UMASetMenuItemText( MenuRef menu, MenuItemIndex item, const wxString& title, wxFontEncoding encoding )
83 {
84 // we don't strip the accels here anymore, must be done before
85 wxString str = title ;
86
87 SetMenuItemTextWithCFString( menu , item , wxCFStringRef(str , encoding) ) ;
88 }
89
90 void UMAEnableMenuItem( MenuRef inMenu , MenuItemIndex inItem , bool enable)
91 {
92 if ( enable )
93 EnableMenuItem( inMenu , inItem ) ;
94 else
95 DisableMenuItem( inMenu , inItem ) ;
96 }
97
98 void UMAAppendSubMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , SInt16 id )
99 {
100 AppendMenuItemTextWithCFString( menu,
101 CFSTR("A"), 0, 0,NULL);
102 UMASetMenuItemText( menu, (SInt16) ::CountMenuItems(menu), title , encoding );
103 SetMenuItemHierarchicalID( menu , CountMenuItems( menu ) , id ) ;
104 }
105
106 void UMAInsertSubMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , MenuItemIndex item , SInt16 id )
107 {
108 InsertMenuItemTextWithCFString( menu,
109 CFSTR("A"), item, 0, 0);
110
111 UMASetMenuItemText( menu, item+1, title , encoding );
112 SetMenuItemHierarchicalID( menu , item+1 , id ) ;
113 }
114
115 void UMASetMenuItemShortcut( MenuRef menu , MenuItemIndex item , wxAcceleratorEntry *entry )
116 {
117 if ( !entry )
118 return ;
119
120 UInt8 modifiers = 0 ;
121 SInt16 key = entry->GetKeyCode() ;
122 if ( key )
123 {
124 bool explicitCommandKey = (entry->GetFlags() & wxACCEL_CTRL);
125
126 if (entry->GetFlags() & wxACCEL_ALT)
127 modifiers |= kMenuOptionModifier ;
128
129 if (entry->GetFlags() & wxACCEL_SHIFT)
130 modifiers |= kMenuShiftModifier ;
131
132 SInt16 glyph = 0 ;
133 SInt16 macKey = key ;
134 if ( key >= WXK_F1 && key <= WXK_F15 )
135 {
136 if ( !explicitCommandKey )
137 modifiers |= kMenuNoCommandModifier ;
138
139 // for some reasons this must be 0 right now
140 // everything else leads to just the first function key item
141 // to be selected. Thanks to Ryan Wilcox for finding out.
142 macKey = 0 ;
143 glyph = kMenuF1Glyph + ( key - WXK_F1 ) ;
144 if ( key >= WXK_F13 )
145 glyph += 12 ;
146 }
147 else
148 {
149 switch ( key )
150 {
151 case WXK_BACK :
152 macKey = kBackspaceCharCode ;
153 glyph = kMenuDeleteLeftGlyph ;
154 break ;
155
156 case WXK_TAB :
157 macKey = kTabCharCode ;
158 glyph = kMenuTabRightGlyph ;
159 break ;
160
161 case kEnterCharCode :
162 macKey = kEnterCharCode ;
163 glyph = kMenuEnterGlyph ;
164 break ;
165
166 case WXK_RETURN :
167 macKey = kReturnCharCode ;
168 glyph = kMenuReturnGlyph ;
169 break ;
170
171 case WXK_ESCAPE :
172 macKey = kEscapeCharCode ;
173 glyph = kMenuEscapeGlyph ;
174 break ;
175
176 case WXK_SPACE :
177 macKey = ' ' ;
178 glyph = kMenuSpaceGlyph ;
179 break ;
180
181 case WXK_DELETE :
182 macKey = kDeleteCharCode ;
183 glyph = kMenuDeleteRightGlyph ;
184 break ;
185
186 case WXK_CLEAR :
187 macKey = kClearCharCode ;
188 glyph = kMenuClearGlyph ;
189 break ;
190
191 case WXK_PAGEUP :
192 macKey = kPageUpCharCode ;
193 glyph = kMenuPageUpGlyph ;
194 break ;
195
196 case WXK_PAGEDOWN :
197 macKey = kPageDownCharCode ;
198 glyph = kMenuPageDownGlyph ;
199 break ;
200
201 case WXK_LEFT :
202 macKey = kLeftArrowCharCode ;
203 glyph = kMenuLeftArrowGlyph ;
204 break ;
205
206 case WXK_UP :
207 macKey = kUpArrowCharCode ;
208 glyph = kMenuUpArrowGlyph ;
209 break ;
210
211 case WXK_RIGHT :
212 macKey = kRightArrowCharCode ;
213 glyph = kMenuRightArrowGlyph ;
214 break ;
215
216 case WXK_DOWN :
217 macKey = kDownArrowCharCode ;
218 glyph = kMenuDownArrowGlyph ;
219 break ;
220
221 case WXK_HOME :
222 macKey = kHomeCharCode ;
223 glyph = kMenuNorthwestArrowGlyph ;
224 break ;
225
226 case WXK_END :
227 macKey = kEndCharCode ;
228 glyph = kMenuSoutheastArrowGlyph ;
229 break ;
230 default :
231 macKey = toupper( key ) ;
232 break ;
233 }
234
235 // we now allow non command key shortcuts
236 // remove in case this gives problems
237 if ( !explicitCommandKey )
238 modifiers |= kMenuNoCommandModifier ;
239 }
240
241 // 1d and 1e have special meaning to SetItemCmd, so
242 // do not use for these character codes.
243 if (key != WXK_UP && key != WXK_RIGHT && key != WXK_DOWN && key != WXK_LEFT)
244 SetItemCmd( menu, item , macKey );
245
246 SetMenuItemModifiers( menu, item , modifiers ) ;
247
248 if ( glyph )
249 SetMenuItemKeyGlyph( menu, item , glyph ) ;
250 }
251 }
252
253 void UMAAppendMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , wxAcceleratorEntry *entry )
254 {
255 AppendMenuItemTextWithCFString( menu,
256 CFSTR("A"), 0, 0,NULL);
257 // don't attempt to interpret metacharacters like a '-' at the beginning (would become a separator otherwise)
258 ChangeMenuItemAttributes( menu , ::CountMenuItems(menu), kMenuItemAttrIgnoreMeta , 0 ) ;
259 UMASetMenuItemText(menu, (SInt16) ::CountMenuItems(menu), title , encoding );
260 UMASetMenuItemShortcut( menu , (SInt16) ::CountMenuItems(menu), entry ) ;
261 }
262
263 void UMAInsertMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , MenuItemIndex item , wxAcceleratorEntry *entry )
264 {
265 InsertMenuItemTextWithCFString( menu,
266 CFSTR("A"), item, 0, 0);
267
268 // don't attempt to interpret metacharacters like a '-' at the beginning (would become a separator otherwise)
269 ChangeMenuItemAttributes( menu , item+1, kMenuItemAttrIgnoreMeta , 0 ) ;
270 UMASetMenuItemText(menu, item+1 , title , encoding );
271 UMASetMenuItemShortcut( menu , item+1 , entry ) ;
272 }
273
274 #endif
275
276 #if wxMAC_USE_COCOA == 0
277
278 static OSStatus UMAGetHelpMenu(
279 MenuRef * outHelpMenu,
280 MenuItemIndex * outFirstCustomItemIndex,
281 bool allowHelpMenuCreation);
282
283 static OSStatus UMAGetHelpMenu(
284 MenuRef * outHelpMenu,
285 MenuItemIndex * outFirstCustomItemIndex,
286 bool allowHelpMenuCreation)
287 {
288 static bool s_createdHelpMenu = false ;
289
290 if ( !s_createdHelpMenu && !allowHelpMenuCreation )
291 {
292 return paramErr ;
293 }
294
295 OSStatus status = HMGetHelpMenu( outHelpMenu , outFirstCustomItemIndex ) ;
296 s_createdHelpMenu = ( status == noErr ) ;
297 return status ;
298 }
299
300 OSStatus UMAGetHelpMenu(
301 MenuRef * outHelpMenu,
302 MenuItemIndex * outFirstCustomItemIndex)
303 {
304 return UMAGetHelpMenu( outHelpMenu , outFirstCustomItemIndex , true );
305 }
306
307 OSStatus UMAGetHelpMenuDontCreate(
308 MenuRef * outHelpMenu,
309 MenuItemIndex * outFirstCustomItemIndex)
310 {
311 return UMAGetHelpMenu( outHelpMenu , outFirstCustomItemIndex , false );
312 }
313
314 #endif
315
316 #endif // wxUSE_GUI