]>
Commit | Line | Data |
---|---|---|
84969af7 | 1 | ///////////////////////////////////////////////////////////////////////////// |
faa94f3e | 2 | // Name: src/mac/carbon/uma.cpp |
84969af7 JS |
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 | |
65571936 | 9 | // Licence: The wxWindows licence |
84969af7 JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
3d1a4878 | 12 | #include "wx/wxprec.h" |
2dbc444a | 13 | |
e17206f7 VS |
14 | #include "wx/mac/uma.h" |
15 | ||
2dbc444a RD |
16 | #if wxUSE_GUI |
17 | ||
0db43f1a | 18 | #include "wx/toplevel.h" |
5fde6fcc | 19 | #include "wx/dc.h" |
72e7876b | 20 | |
6239ee05 | 21 | #include "wx/mac/uma.h" |
9c3c5849 | 22 | |
72055702 SC |
23 | // since we have decided that we only support 8.6 upwards we are |
24 | // checking for these minimum requirements in the startup code of | |
77ffb593 | 25 | // the application so all wxWidgets code can safely assume that appearance 1.1 |
58751a86 | 26 | // windows manager, control manager, navigation services etc. are |
72055702 | 27 | // present |
e7b596fb | 28 | |
e6c3d3e6 | 29 | static SInt32 sUMASystemVersion = 0 ; |
0e5a4d20 | 30 | |
2b5f62a0 | 31 | long UMAGetSystemVersion() { return sUMASystemVersion ; } |
72e7876b | 32 | |
5b781a67 SC |
33 | void UMACleanupToolbox() |
34 | { | |
5b781a67 | 35 | } |
98af9c73 | 36 | |
89954433 VZ |
37 | void UMAInitToolbox( UInt16 WXUNUSED(inMoreMastersCalls), |
38 | bool WXUNUSED(isEmbedded) ) | |
72e7876b | 39 | { |
2b5f62a0 | 40 | if ( Gestalt(gestaltSystemVersion, &sUMASystemVersion) != noErr) |
e40298d5 | 41 | sUMASystemVersion = 0x0000 ; |
58751a86 | 42 | |
e6c3d3e6 | 43 | #ifndef __LP64__ |
564bf1ea | 44 | { |
98af9c73 DS |
45 | FontFamilyID fontId ; |
46 | Str255 fontName ; | |
47 | SInt16 fontSize ; | |
48 | Style fontStyle ; | |
4a6a2972 | 49 | |
98af9c73 DS |
50 | GetThemeFont(kThemeSmallSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ; |
51 | GetFNum( fontName, &fontId ); | |
4a6a2972 | 52 | |
98af9c73 DS |
53 | TXNMacOSPreferredFontDescription fontDescriptions[] = |
54 | { | |
55 | { fontId , (fontSize << 16) , kTXNDefaultFontStyle, kTXNSystemDefaultEncoding } | |
56 | } ; | |
57 | int noOfFontDescriptions = sizeof( fontDescriptions ) / sizeof(TXNMacOSPreferredFontDescription) ; | |
58 | ||
59 | OptionBits options = 0 ; | |
f8eebb95 | 60 | |
98af9c73 DS |
61 | if ( UMAGetSystemVersion() < 0x1000 ) |
62 | options |= kTXNAlwaysUseQuickDrawTextMask ; | |
ded4fa5b | 63 | |
98af9c73 DS |
64 | TXNInitTextension( fontDescriptions, noOfFontDescriptions, options ); |
65 | } | |
e6c3d3e6 | 66 | #endif |
66a09d47 | 67 | |
98af9c73 | 68 | UMASetSystemIsInitialized( true ); |
72e7876b SC |
69 | } |
70 | ||
71 | // process manager | |
58751a86 | 72 | long UMAGetProcessMode() |
72e7876b | 73 | { |
58751a86 | 74 | OSErr err ; |
e40298d5 JS |
75 | ProcessInfoRec processinfo; |
76 | ProcessSerialNumber procno ; | |
58751a86 | 77 | |
77eddfb7 | 78 | procno.highLongOfPSN = 0 ; |
e40298d5 JS |
79 | procno.lowLongOfPSN = kCurrentProcess ; |
80 | processinfo.processInfoLength = sizeof(ProcessInfoRec); | |
81 | processinfo.processName = NULL; | |
e6c3d3e6 | 82 | #ifndef __LP64__ |
e40298d5 | 83 | processinfo.processAppSpec = NULL; |
e6c3d3e6 | 84 | #endif |
72e7876b | 85 | |
e40298d5 JS |
86 | err = ::GetProcessInformation( &procno , &processinfo ) ; |
87 | wxASSERT( err == noErr ) ; | |
98af9c73 | 88 | |
e40298d5 | 89 | return processinfo.processMode ; |
72e7876b SC |
90 | } |
91 | ||
58751a86 | 92 | bool UMAGetProcessModeDoesActivateOnFGSwitch() |
72e7876b | 93 | { |
e40298d5 | 94 | return UMAGetProcessMode() & modeDoesActivateOnFGSwitch ; |
72e7876b SC |
95 | } |
96 | ||
97 | // menu manager | |
98 | ||
cd66beb3 SC |
99 | #if wxMAC_USE_COCOA == 0 |
100 | ||
908d407c | 101 | MenuRef UMANewMenu( SInt16 id , const wxString& title , wxFontEncoding encoding ) |
72e7876b | 102 | { |
e40298d5 JS |
103 | wxString str = wxStripMenuCodes( title ) ; |
104 | MenuRef menu ; | |
98af9c73 | 105 | |
e40298d5 | 106 | CreateNewMenu( id , 0 , &menu ) ; |
908d407c | 107 | SetMenuTitleWithCFString( menu , wxMacCFStringHolder(str , encoding ) ) ; |
98af9c73 | 108 | |
e40298d5 | 109 | return menu ; |
bf918b97 | 110 | } |
72e7876b | 111 | |
98af9c73 | 112 | void UMASetMenuTitle( MenuRef menu , const wxString& title , wxFontEncoding encoding ) |
bf918b97 | 113 | { |
e40298d5 | 114 | wxString str = wxStripMenuCodes( title ) ; |
98af9c73 | 115 | |
908d407c | 116 | SetMenuTitleWithCFString( menu , wxMacCFStringHolder(str , encoding) ) ; |
72e7876b SC |
117 | } |
118 | ||
98af9c73 | 119 | void UMASetMenuItemText( MenuRef menu, MenuItemIndex item, const wxString& title, wxFontEncoding encoding ) |
72e7876b | 120 | { |
43524b15 DS |
121 | // we don't strip the accels here anymore, must be done before |
122 | wxString str = title ; | |
98af9c73 | 123 | |
908d407c | 124 | SetMenuItemTextWithCFString( menu , item , wxMacCFStringHolder(str , encoding) ) ; |
72e7876b SC |
125 | } |
126 | ||
bf918b97 | 127 | UInt32 UMAMenuEvent( EventRecord *inEvent ) |
72e7876b | 128 | { |
98af9c73 | 129 | return MenuEvent( inEvent ) ; |
72e7876b SC |
130 | } |
131 | ||
58751a86 | 132 | void UMAEnableMenuItem( MenuRef inMenu , MenuItemIndex inItem , bool enable) |
72e7876b | 133 | { |
e40298d5 JS |
134 | if ( enable ) |
135 | EnableMenuItem( inMenu , inItem ) ; | |
136 | else | |
137 | DisableMenuItem( inMenu , inItem ) ; | |
72e7876b | 138 | } |
2f1ae414 | 139 | |
908d407c | 140 | void UMAAppendSubMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , SInt16 id ) |
2f1ae414 | 141 | { |
e6c3d3e6 | 142 | AppendMenuItemTextWithCFString( menu, |
31c1cbc7 | 143 | CFSTR("A"), 0, 0,NULL); |
98af9c73 | 144 | UMASetMenuItemText( menu, (SInt16) ::CountMenuItems(menu), title , encoding ); |
e40298d5 | 145 | SetMenuItemHierarchicalID( menu , CountMenuItems( menu ) , id ) ; |
2f1ae414 SC |
146 | } |
147 | ||
908d407c | 148 | void UMAInsertSubMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , MenuItemIndex item , SInt16 id ) |
2f1ae414 | 149 | { |
e6c3d3e6 | 150 | InsertMenuItemTextWithCFString( menu, |
31c1cbc7 VZ |
151 | CFSTR("A"), item, 0, 0); |
152 | ||
98af9c73 | 153 | UMASetMenuItemText( menu, item+1, title , encoding ); |
4da39c96 | 154 | SetMenuItemHierarchicalID( menu , item+1 , id ) ; |
2f1ae414 SC |
155 | } |
156 | ||
bf918b97 | 157 | void UMASetMenuItemShortcut( MenuRef menu , MenuItemIndex item , wxAcceleratorEntry *entry ) |
2f1ae414 | 158 | { |
e40298d5 JS |
159 | if ( !entry ) |
160 | return ; | |
58751a86 | 161 | |
e40298d5 JS |
162 | UInt8 modifiers = 0 ; |
163 | SInt16 key = entry->GetKeyCode() ; | |
164 | if ( key ) | |
165 | { | |
98af9c73 | 166 | bool explicitCommandKey = (entry->GetFlags() & wxACCEL_CTRL); |
e40298d5 | 167 | |
98af9c73 | 168 | if (entry->GetFlags() & wxACCEL_ALT) |
e40298d5 | 169 | modifiers |= kMenuOptionModifier ; |
e40298d5 | 170 | |
58751a86 | 171 | if (entry->GetFlags() & wxACCEL_SHIFT) |
e40298d5 | 172 | modifiers |= kMenuShiftModifier ; |
e40298d5 JS |
173 | |
174 | SInt16 glyph = 0 ; | |
175 | SInt16 macKey = key ; | |
176 | if ( key >= WXK_F1 && key <= WXK_F15 ) | |
177 | { | |
98af9c73 DS |
178 | if ( !explicitCommandKey ) |
179 | modifiers |= kMenuNoCommandModifier ; | |
180 | ||
a5c1f8ca SC |
181 | // for some reasons this must be 0 right now |
182 | // everything else leads to just the first function key item | |
183 | // to be selected. Thanks to Ryan Wilcox for finding out. | |
2dbc444a | 184 | macKey = 0 ; |
e40298d5 JS |
185 | glyph = kMenuF1Glyph + ( key - WXK_F1 ) ; |
186 | if ( key >= WXK_F13 ) | |
6239ee05 | 187 | glyph += 12 ; |
1bec2ee4 | 188 | } |
e40298d5 JS |
189 | else |
190 | { | |
98af9c73 | 191 | switch ( key ) |
e40298d5 JS |
192 | { |
193 | case WXK_BACK : | |
194 | macKey = kBackspaceCharCode ; | |
195 | glyph = kMenuDeleteLeftGlyph ; | |
196 | break ; | |
98af9c73 | 197 | |
e40298d5 JS |
198 | case WXK_TAB : |
199 | macKey = kTabCharCode ; | |
200 | glyph = kMenuTabRightGlyph ; | |
201 | break ; | |
98af9c73 | 202 | |
e40298d5 JS |
203 | case kEnterCharCode : |
204 | macKey = kEnterCharCode ; | |
205 | glyph = kMenuEnterGlyph ; | |
206 | break ; | |
98af9c73 | 207 | |
e40298d5 JS |
208 | case WXK_RETURN : |
209 | macKey = kReturnCharCode ; | |
210 | glyph = kMenuReturnGlyph ; | |
211 | break ; | |
98af9c73 | 212 | |
e40298d5 JS |
213 | case WXK_ESCAPE : |
214 | macKey = kEscapeCharCode ; | |
215 | glyph = kMenuEscapeGlyph ; | |
216 | break ; | |
98af9c73 | 217 | |
e40298d5 JS |
218 | case WXK_SPACE : |
219 | macKey = ' ' ; | |
220 | glyph = kMenuSpaceGlyph ; | |
221 | break ; | |
98af9c73 | 222 | |
e40298d5 JS |
223 | case WXK_DELETE : |
224 | macKey = kDeleteCharCode ; | |
225 | glyph = kMenuDeleteRightGlyph ; | |
226 | break ; | |
98af9c73 | 227 | |
e40298d5 JS |
228 | case WXK_CLEAR : |
229 | macKey = kClearCharCode ; | |
230 | glyph = kMenuClearGlyph ; | |
231 | break ; | |
98af9c73 | 232 | |
faa94f3e | 233 | case WXK_PAGEUP : |
e40298d5 JS |
234 | macKey = kPageUpCharCode ; |
235 | glyph = kMenuPageUpGlyph ; | |
236 | break ; | |
98af9c73 | 237 | |
faa94f3e | 238 | case WXK_PAGEDOWN : |
e40298d5 JS |
239 | macKey = kPageDownCharCode ; |
240 | glyph = kMenuPageDownGlyph ; | |
241 | break ; | |
98af9c73 | 242 | |
e40298d5 JS |
243 | case WXK_LEFT : |
244 | macKey = kLeftArrowCharCode ; | |
245 | glyph = kMenuLeftArrowGlyph ; | |
246 | break ; | |
98af9c73 | 247 | |
e40298d5 JS |
248 | case WXK_UP : |
249 | macKey = kUpArrowCharCode ; | |
250 | glyph = kMenuUpArrowGlyph ; | |
251 | break ; | |
98af9c73 | 252 | |
e40298d5 JS |
253 | case WXK_RIGHT : |
254 | macKey = kRightArrowCharCode ; | |
255 | glyph = kMenuRightArrowGlyph ; | |
256 | break ; | |
98af9c73 | 257 | |
e40298d5 JS |
258 | case WXK_DOWN : |
259 | macKey = kDownArrowCharCode ; | |
260 | glyph = kMenuDownArrowGlyph ; | |
261 | break ; | |
98af9c73 | 262 | |
4952771d JS |
263 | case WXK_HOME : |
264 | macKey = kHomeCharCode ; | |
265 | glyph = kMenuNorthwestArrowGlyph ; | |
266 | break ; | |
267 | ||
268 | case WXK_END : | |
269 | macKey = kEndCharCode ; | |
270 | glyph = kMenuSoutheastArrowGlyph ; | |
271 | break ; | |
1bec2ee4 SC |
272 | default : |
273 | macKey = toupper( key ) ; | |
274 | break ; | |
2b5f62a0 | 275 | } |
98af9c73 | 276 | |
1bec2ee4 SC |
277 | // we now allow non command key shortcuts |
278 | // remove in case this gives problems | |
279 | if ( !explicitCommandKey ) | |
280 | modifiers |= kMenuNoCommandModifier ; | |
2b5f62a0 | 281 | } |
bf918b97 | 282 | |
1a03b3e2 JS |
283 | // 1d and 1e have special meaning to SetItemCmd, so |
284 | // do not use for these character codes. | |
40cc34ec | 285 | if (key != WXK_UP && key != WXK_RIGHT && key != WXK_DOWN && key != WXK_LEFT) |
1a03b3e2 JS |
286 | SetItemCmd( menu, item , macKey ); |
287 | ||
98af9c73 | 288 | SetMenuItemModifiers( menu, item , modifiers ) ; |
2b5f62a0 VZ |
289 | |
290 | if ( glyph ) | |
98af9c73 | 291 | SetMenuItemKeyGlyph( menu, item , glyph ) ; |
e40298d5 | 292 | } |
2b5f62a0 VZ |
293 | } |
294 | ||
908d407c | 295 | void UMAAppendMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , wxAcceleratorEntry *entry ) |
2b5f62a0 | 296 | { |
e6c3d3e6 | 297 | AppendMenuItemTextWithCFString( menu, |
31c1cbc7 | 298 | CFSTR("A"), 0, 0,NULL); |
faa94f3e | 299 | // don't attempt to interpret metacharacters like a '-' at the beginning (would become a separator otherwise) |
a76342da | 300 | ChangeMenuItemAttributes( menu , ::CountMenuItems(menu), kMenuItemAttrIgnoreMeta , 0 ) ; |
908d407c | 301 | UMASetMenuItemText(menu, (SInt16) ::CountMenuItems(menu), title , encoding ); |
98af9c73 | 302 | UMASetMenuItemShortcut( menu , (SInt16) ::CountMenuItems(menu), entry ) ; |
2f1ae414 SC |
303 | } |
304 | ||
908d407c | 305 | void UMAInsertMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , MenuItemIndex item , wxAcceleratorEntry *entry ) |
2f1ae414 | 306 | { |
e6c3d3e6 | 307 | InsertMenuItemTextWithCFString( menu, |
31c1cbc7 | 308 | CFSTR("A"), item, 0, 0); |
98af9c73 | 309 | |
faa94f3e | 310 | // don't attempt to interpret metacharacters like a '-' at the beginning (would become a separator otherwise) |
a76342da | 311 | ChangeMenuItemAttributes( menu , item+1, kMenuItemAttrIgnoreMeta , 0 ) ; |
908d407c | 312 | UMASetMenuItemText(menu, item+1 , title , encoding ); |
58751a86 | 313 | UMASetMenuItemShortcut( menu , item+1 , entry ) ; |
2f1ae414 SC |
314 | } |
315 | ||
cd66beb3 SC |
316 | #endif |
317 | ||
318 | #if wxMAC_USE_COCOA == 0 | |
319 | ||
58751a86 | 320 | void UMAShowWatchCursor() |
72e7876b | 321 | { |
e6c3d3e6 | 322 | SetThemeCursor(kThemeWatchCursor); |
72e7876b SC |
323 | } |
324 | ||
98af9c73 | 325 | void UMAShowArrowCursor() |
72e7876b | 326 | { |
e6c3d3e6 | 327 | SetThemeCursor(kThemeArrowCursor); |
72e7876b SC |
328 | } |
329 | ||
cd66beb3 SC |
330 | static OSStatus UMAGetHelpMenu( |
331 | MenuRef * outHelpMenu, | |
332 | MenuItemIndex * outFirstCustomItemIndex, | |
333 | bool allowHelpMenuCreation); | |
334 | ||
335 | static OSStatus UMAGetHelpMenu( | |
336 | MenuRef * outHelpMenu, | |
337 | MenuItemIndex * outFirstCustomItemIndex, | |
338 | bool allowHelpMenuCreation) | |
339 | { | |
340 | static bool s_createdHelpMenu = false ; | |
341 | ||
342 | if ( !s_createdHelpMenu && !allowHelpMenuCreation ) | |
343 | { | |
344 | return paramErr ; | |
345 | } | |
346 | ||
347 | OSStatus status = HMGetHelpMenu( outHelpMenu , outFirstCustomItemIndex ) ; | |
348 | s_createdHelpMenu = ( status == noErr ) ; | |
349 | return status ; | |
350 | } | |
351 | ||
352 | OSStatus UMAGetHelpMenu( | |
353 | MenuRef * outHelpMenu, | |
354 | MenuItemIndex * outFirstCustomItemIndex) | |
355 | { | |
356 | return UMAGetHelpMenu( outHelpMenu , outFirstCustomItemIndex , true ); | |
357 | } | |
358 | ||
359 | OSStatus UMAGetHelpMenuDontCreate( | |
360 | MenuRef * outHelpMenu, | |
361 | MenuItemIndex * outFirstCustomItemIndex) | |
362 | { | |
363 | return UMAGetHelpMenu( outHelpMenu , outFirstCustomItemIndex , false ); | |
364 | } | |
365 | ||
366 | #endif | |
367 | ||
72e7876b SC |
368 | // window manager |
369 | ||
cd66beb3 SC |
370 | #if wxMAC_USE_QUICKDRAW |
371 | ||
98af9c73 | 372 | GrafPtr UMAGetWindowPort( WindowRef inWindowRef ) |
72e7876b | 373 | { |
e40298d5 | 374 | wxASSERT( inWindowRef != NULL ) ; |
98af9c73 | 375 | |
58751a86 | 376 | return (GrafPtr) GetWindowPort( inWindowRef ) ; |
72e7876b SC |
377 | } |
378 | ||
98af9c73 | 379 | void UMADisposeWindow( WindowRef inWindowRef ) |
72e7876b | 380 | { |
e40298d5 | 381 | wxASSERT( inWindowRef != NULL ) ; |
98af9c73 | 382 | |
e40298d5 | 383 | DisposeWindow( inWindowRef ) ; |
72e7876b SC |
384 | } |
385 | ||
98af9c73 | 386 | void UMASetWTitle( WindowRef inWindowRef , const wxString& title , wxFontEncoding encoding ) |
72e7876b | 387 | { |
908d407c | 388 | SetWindowTitleWithCFString( inWindowRef , wxMacCFStringHolder(title , encoding) ) ; |
72e7876b | 389 | } |
03e11df5 | 390 | |
72e7876b SC |
391 | // appearance additions |
392 | ||
98af9c73 | 393 | void UMASetControlTitle( ControlRef inControl , const wxString& title , wxFontEncoding encoding ) |
427ff662 | 394 | { |
908d407c | 395 | SetControlTitleWithCFString( inControl , wxMacCFStringHolder(title , encoding) ) ; |
427ff662 SC |
396 | } |
397 | ||
facd6764 | 398 | void UMAActivateControl( ControlRef inControl ) |
72e7876b | 399 | { |
98af9c73 | 400 | ::ActivateControl( inControl ) ; |
72e7876b SC |
401 | } |
402 | ||
facd6764 | 403 | void UMAMoveControl( ControlRef inControl , short x , short y ) |
72e7876b | 404 | { |
98af9c73 | 405 | ::MoveControl( inControl , x , y ) ; |
72e7876b SC |
406 | } |
407 | ||
facd6764 | 408 | void UMASizeControl( ControlRef inControl , short x , short y ) |
72e7876b | 409 | { |
98af9c73 | 410 | ::SizeControl( inControl , x , y ) ; |
72e7876b SC |
411 | } |
412 | ||
facd6764 | 413 | void UMADeactivateControl( ControlRef inControl ) |
72e7876b | 414 | { |
98af9c73 | 415 | ::DeactivateControl( inControl ) ; |
e40298d5 | 416 | } |
98af9c73 | 417 | |
e40298d5 | 418 | // shows the control and adds the region to the update region |
98af9c73 | 419 | void UMAShowControl( ControlRef inControl ) |
e40298d5 JS |
420 | { |
421 | SetControlVisibility( inControl , true , false ) ; | |
e6c3d3e6 | 422 | HIViewSetNeedsDisplay( inControl, true ); |
72e7876b SC |
423 | } |
424 | ||
facd6764 | 425 | // hides the control and adds the region to the update region |
98af9c73 | 426 | void UMAHideControl( ControlRef inControl ) |
22e751a5 | 427 | { |
e40298d5 | 428 | SetControlVisibility( inControl , false , false ) ; |
e6c3d3e6 | 429 | HIViewSetNeedsDisplay( inControl, true ); |
22e751a5 | 430 | } |
98af9c73 | 431 | |
72e7876b | 432 | // keyboard focus |
98af9c73 DS |
433 | OSErr UMASetKeyboardFocus( WindowPtr inWindow, |
434 | ControlRef inControl, | |
435 | ControlFocusPart inPart ) | |
72e7876b | 436 | { |
e40298d5 | 437 | OSErr err = noErr; |
e6c3d3e6 | 438 | #ifndef __LP64__ |
e40298d5 | 439 | GrafPtr port ; |
72055702 | 440 | |
98af9c73 | 441 | GetPort( &port ) ; |
e40298d5 | 442 | SetPortWindowPort( inWindow ) ; |
e6c3d3e6 | 443 | #endif |
72055702 | 444 | |
e40298d5 | 445 | err = SetKeyboardFocus( inWindow , inControl , inPart ) ; |
e6c3d3e6 | 446 | #ifndef __LP64__ |
e40298d5 | 447 | SetPort( port ) ; |
e6c3d3e6 | 448 | #endif |
98af9c73 | 449 | |
e40298d5 | 450 | return err ; |
72e7876b SC |
451 | } |
452 | ||
58751a86 | 453 | bool UMAIsWindowFloating( WindowRef inWindow ) |
72e7876b | 454 | { |
e40298d5 | 455 | WindowClass cl ; |
58751a86 | 456 | |
e40298d5 JS |
457 | GetWindowClass( inWindow , &cl ) ; |
458 | return cl == kFloatingWindowClass ; | |
72e7876b SC |
459 | } |
460 | ||
58751a86 | 461 | bool UMAIsWindowModal( WindowRef inWindow ) |
72e7876b | 462 | { |
e40298d5 | 463 | WindowClass cl ; |
58751a86 | 464 | |
e40298d5 JS |
465 | GetWindowClass( inWindow , &cl ) ; |
466 | return cl < kFloatingWindowClass ; | |
72e7876b SC |
467 | } |
468 | ||
469 | // others | |
470 | ||
471 | void UMAHighlightAndActivateWindow( WindowRef inWindowRef , bool inActivate ) | |
472 | { | |
e40298d5 JS |
473 | if ( inWindowRef ) |
474 | { | |
475 | // bool isHighlighted = IsWindowHighlited( inWindowRef ) ; | |
3103e8a9 | 476 | // if ( inActivate != isHighlighted ) |
e6c3d3e6 | 477 | #ifndef __LP64__ |
e40298d5 JS |
478 | GrafPtr port ; |
479 | GetPort( &port ) ; | |
480 | SetPortWindowPort( inWindowRef ) ; | |
e6c3d3e6 | 481 | #endif |
e40298d5 | 482 | HiliteWindow( inWindowRef , inActivate ) ; |
facd6764 | 483 | ControlRef control = NULL ; |
98af9c73 | 484 | ::GetRootControl( inWindowRef , &control ) ; |
e40298d5 JS |
485 | if ( control ) |
486 | { | |
487 | if ( inActivate ) | |
488 | UMAActivateControl( control ) ; | |
489 | else | |
490 | UMADeactivateControl( control ) ; | |
58751a86 | 491 | } |
e6c3d3e6 | 492 | #ifndef __LP64__ |
e40298d5 | 493 | SetPort( port ) ; |
e6c3d3e6 | 494 | #endif |
e40298d5 | 495 | } |
72e7876b | 496 | } |
e40298d5 | 497 | |
58751a86 | 498 | OSStatus UMADrawThemePlacard( const Rect *inRect , ThemeDrawState inState ) |
2f1ae414 | 499 | { |
e6c3d3e6 | 500 | #ifndef __LP64__ |
e40298d5 | 501 | return ::DrawThemePlacard( inRect , inState ) ; |
e6c3d3e6 SC |
502 | #else |
503 | return noErr; | |
504 | #endif | |
2f1ae414 | 505 | } |
72e7876b | 506 | |
cd66beb3 | 507 | Rect * UMAGetControlBoundsInWindowCoords( ControlRef theControl, Rect *bounds ) |
b03e4fcd | 508 | { |
cd66beb3 SC |
509 | GetControlBounds( theControl , bounds ) ; |
510 | ||
511 | WindowRef tlwref = GetControlOwner( theControl ) ; | |
512 | ||
513 | wxTopLevelWindowMac* tlwwx = wxFindWinFromMacWindow( tlwref ) ; | |
514 | if ( tlwwx != NULL ) | |
4dd25308 | 515 | { |
cd66beb3 SC |
516 | ControlRef rootControl = tlwwx->GetPeer()->GetControlRef() ; |
517 | HIPoint hiPoint = CGPointMake( 0 , 0 ) ; | |
518 | HIViewConvertPoint( &hiPoint , HIViewGetSuperview(theControl) , rootControl ) ; | |
519 | OffsetRect( bounds , (short) hiPoint.x , (short) hiPoint.y ) ; | |
4dd25308 | 520 | } |
cd66beb3 SC |
521 | |
522 | return bounds ; | |
4dd25308 VZ |
523 | } |
524 | ||
cd66beb3 | 525 | #endif |
4dd25308 | 526 | |
e6c3d3e6 SC |
527 | #ifndef __LP64__ |
528 | ||
98af9c73 | 529 | wxMacPortStateHelper::wxMacPortStateHelper( GrafPtr newport ) |
76a5e5d2 | 530 | { |
e40298d5 JS |
531 | m_clip = NULL ; |
532 | Setup( newport ) ; | |
76a5e5d2 SC |
533 | } |
534 | ||
535 | wxMacPortStateHelper::wxMacPortStateHelper() | |
536 | { | |
e40298d5 | 537 | m_clip = NULL ; |
76a5e5d2 SC |
538 | } |
539 | ||
540 | void wxMacPortStateHelper::Setup( GrafPtr newport ) | |
541 | { | |
e40298d5 JS |
542 | GetPort( &m_oldPort ) ; |
543 | SetPort( newport ) ; | |
98af9c73 DS |
544 | SetOrigin(0, 0); |
545 | ||
427ff662 | 546 | wxASSERT_MSG( m_clip == NULL , wxT("Cannot call setup twice") ) ; |
e40298d5 JS |
547 | m_clip = NewRgn() ; |
548 | GetClip( m_clip ); | |
98af9c73 DS |
549 | m_textFont = GetPortTextFont( (CGrafPtr) newport ); |
550 | m_textSize = GetPortTextSize( (CGrafPtr) newport ); | |
551 | m_textStyle = GetPortTextFace( (CGrafPtr) newport ); | |
552 | m_textMode = GetPortTextMode( (CGrafPtr) newport ); | |
e40298d5 JS |
553 | GetThemeDrawingState( &m_drawingState ) ; |
554 | m_currentPort = newport ; | |
76a5e5d2 | 555 | } |
98af9c73 | 556 | |
76a5e5d2 SC |
557 | void wxMacPortStateHelper::Clear() |
558 | { | |
e40298d5 JS |
559 | if ( m_clip ) |
560 | { | |
561 | DisposeRgn( m_clip ) ; | |
562 | DisposeThemeDrawingState( m_drawingState ) ; | |
563 | m_clip = NULL ; | |
564 | } | |
76a5e5d2 SC |
565 | } |
566 | ||
567 | wxMacPortStateHelper::~wxMacPortStateHelper() | |
568 | { | |
e40298d5 JS |
569 | if ( m_clip ) |
570 | { | |
571 | SetPort( m_currentPort ) ; | |
572 | SetClip( m_clip ) ; | |
573 | DisposeRgn( m_clip ) ; | |
574 | TextFont( m_textFont ); | |
575 | TextSize( m_textSize ); | |
576 | TextFace( m_textStyle ); | |
577 | TextMode( m_textMode ); | |
578 | SetThemeDrawingState( m_drawingState , true ) ; | |
579 | SetPort( m_oldPort ) ; | |
580 | } | |
76a5e5d2 SC |
581 | } |
582 | ||
e6c3d3e6 SC |
583 | #endif |
584 | ||
6239ee05 SC |
585 | size_t UMAPutBytesCFRefCallback( void *info, const void *bytes, size_t count ) |
586 | { | |
587 | CFMutableDataRef data = (CFMutableDataRef) info; | |
588 | if ( data ) | |
589 | { | |
590 | CFDataAppendBytes( data, (const UInt8*) bytes, count ); | |
591 | } | |
592 | return count; | |
593 | } | |
594 | ||
31c1cbc7 VZ |
595 | void UMAReleaseCFDataProviderCallback(void *info, |
596 | const void *WXUNUSED(data), | |
597 | size_t WXUNUSED(count)) | |
6239ee05 SC |
598 | { |
599 | if ( info ) | |
600 | CFRelease( (CFDataRef) info ); | |
601 | } | |
602 | ||
603 | void UMAReleaseCFDataConsumerCallback( void *info ) | |
604 | { | |
605 | if ( info ) | |
606 | CFRelease( (CFDataRef) info ); | |
607 | } | |
608 | ||
609 | CGDataProviderRef UMACGDataProviderCreateWithCFData( CFDataRef data ) | |
610 | { | |
611 | if ( data == NULL ) | |
612 | return NULL; | |
31c1cbc7 | 613 | |
e1673e52 | 614 | return CGDataProviderCreateWithCFData( data ); |
6239ee05 SC |
615 | } |
616 | ||
617 | CGDataConsumerRef UMACGDataConsumerCreateWithCFData( CFMutableDataRef data ) | |
618 | { | |
619 | if ( data == NULL ) | |
620 | return NULL; | |
31c1cbc7 | 621 | |
e1673e52 | 622 | return CGDataConsumerCreateWithCFData( data ); |
6239ee05 | 623 | } |
2dbc444a RD |
624 | #endif // wxUSE_GUI |
625 | ||
626 | #if wxUSE_BASE | |
627 | ||
628 | static bool sUMASystemInitialized = false ; | |
629 | ||
630 | bool UMASystemIsInitialized() | |
631 | { | |
632 | return sUMASystemInitialized ; | |
633 | } | |
634 | ||
635 | void UMASetSystemIsInitialized(bool val) | |
636 | { | |
637 | sUMASystemInitialized = val; | |
638 | } | |
639 | ||
2dbc444a | 640 | #endif // wxUSE_BASE |