]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/uma.cpp
cleanup
[wxWidgets.git] / src / mac / carbon / uma.cpp
CommitLineData
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
f5c6eb5c 21#ifndef __DARWIN__
768c6e8b 22# include <MacTextEditor.h>
a3d3d3bf
GD
23# include <Navigation.h>
24# if defined(TARGET_CARBON)
25# if PM_USE_SESSION_APIS
26# include <PMCore.h>
27# endif
28# include <PMApplication.h>
66a09d47
SC
29# else
30# include <Printing.h>
a3d3d3bf 31# endif
03e11df5 32#endif
5b781a67 33
6239ee05 34#include "wx/mac/uma.h"
9c3c5849 35
72055702
SC
36// since we have decided that we only support 8.6 upwards we are
37// checking for these minimum requirements in the startup code of
77ffb593 38// the application so all wxWidgets code can safely assume that appearance 1.1
58751a86 39// windows manager, control manager, navigation services etc. are
72055702 40// present
e7b596fb 41
e6c3d3e6 42static SInt32 sUMASystemVersion = 0 ;
0e5a4d20 43
2b5f62a0 44long UMAGetSystemVersion() { return sUMASystemVersion ; }
72e7876b 45
5b781a67
SC
46void UMACleanupToolbox()
47{
5b781a67 48}
98af9c73 49
89954433
VZ
50void UMAInitToolbox( UInt16 WXUNUSED(inMoreMastersCalls),
51 bool WXUNUSED(isEmbedded) )
72e7876b 52{
e128397f
DS
53 ::InitCursor();
54
2b5f62a0 55 if ( Gestalt(gestaltSystemVersion, &sUMASystemVersion) != noErr)
e40298d5 56 sUMASystemVersion = 0x0000 ;
58751a86 57
e6c3d3e6 58#ifndef __LP64__
564bf1ea 59 {
98af9c73
DS
60 FontFamilyID fontId ;
61 Str255 fontName ;
62 SInt16 fontSize ;
63 Style fontStyle ;
4a6a2972 64
98af9c73
DS
65 GetThemeFont(kThemeSmallSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ;
66 GetFNum( fontName, &fontId );
4a6a2972 67
98af9c73
DS
68 TXNMacOSPreferredFontDescription fontDescriptions[] =
69 {
70 { fontId , (fontSize << 16) , kTXNDefaultFontStyle, kTXNSystemDefaultEncoding }
71 } ;
72 int noOfFontDescriptions = sizeof( fontDescriptions ) / sizeof(TXNMacOSPreferredFontDescription) ;
73
74 OptionBits options = 0 ;
f8eebb95 75
98af9c73
DS
76 if ( UMAGetSystemVersion() < 0x1000 )
77 options |= kTXNAlwaysUseQuickDrawTextMask ;
ded4fa5b 78
98af9c73
DS
79 TXNInitTextension( fontDescriptions, noOfFontDescriptions, options );
80 }
e6c3d3e6 81#endif
66a09d47 82
98af9c73 83 UMASetSystemIsInitialized( true );
72e7876b
SC
84}
85
86// process manager
58751a86 87long UMAGetProcessMode()
72e7876b 88{
58751a86 89 OSErr err ;
e40298d5
JS
90 ProcessInfoRec processinfo;
91 ProcessSerialNumber procno ;
58751a86 92
77eddfb7 93 procno.highLongOfPSN = 0 ;
e40298d5
JS
94 procno.lowLongOfPSN = kCurrentProcess ;
95 processinfo.processInfoLength = sizeof(ProcessInfoRec);
96 processinfo.processName = NULL;
e6c3d3e6 97#ifndef __LP64__
e40298d5 98 processinfo.processAppSpec = NULL;
e6c3d3e6 99#endif
72e7876b 100
e40298d5
JS
101 err = ::GetProcessInformation( &procno , &processinfo ) ;
102 wxASSERT( err == noErr ) ;
98af9c73 103
e40298d5 104 return processinfo.processMode ;
72e7876b
SC
105}
106
58751a86 107bool UMAGetProcessModeDoesActivateOnFGSwitch()
72e7876b 108{
e40298d5 109 return UMAGetProcessMode() & modeDoesActivateOnFGSwitch ;
72e7876b
SC
110}
111
112// menu manager
113
908d407c 114MenuRef UMANewMenu( SInt16 id , const wxString& title , wxFontEncoding encoding )
72e7876b 115{
e40298d5
JS
116 wxString str = wxStripMenuCodes( title ) ;
117 MenuRef menu ;
98af9c73 118
bf918b97 119#if TARGET_CARBON
e40298d5 120 CreateNewMenu( id , 0 , &menu ) ;
908d407c 121 SetMenuTitleWithCFString( menu , wxMacCFStringHolder(str , encoding ) ) ;
bf918b97 122#else
e40298d5
JS
123 Str255 ptitle ;
124 wxMacStringToPascal( str , ptitle ) ;
125 menu = ::NewMenu( id , ptitle ) ;
bf918b97 126#endif
98af9c73 127
e40298d5 128 return menu ;
bf918b97 129}
72e7876b 130
98af9c73 131void UMASetMenuTitle( MenuRef menu , const wxString& title , wxFontEncoding encoding )
bf918b97 132{
e40298d5 133 wxString str = wxStripMenuCodes( title ) ;
98af9c73 134
bf918b97 135#if TARGET_CARBON
908d407c 136 SetMenuTitleWithCFString( menu , wxMacCFStringHolder(str , encoding) ) ;
98af9c73 137
72e7876b 138#else
e40298d5
JS
139 Str255 ptitle ;
140 wxMacStringToPascal( str , ptitle ) ;
141 SetMenuTitle( menu , ptitle ) ;
bf918b97 142#endif
72e7876b
SC
143}
144
98af9c73 145void UMASetMenuItemText( MenuRef menu, MenuItemIndex item, const wxString& title, wxFontEncoding encoding )
72e7876b 146{
43524b15
DS
147 // we don't strip the accels here anymore, must be done before
148 wxString str = title ;
98af9c73 149
bf918b97 150#if TARGET_CARBON
908d407c 151 SetMenuItemTextWithCFString( menu , item , wxMacCFStringHolder(str , encoding) ) ;
98af9c73 152
bf918b97 153#else
e40298d5
JS
154 Str255 ptitle ;
155 wxMacStringToPascal( str , ptitle ) ;
156 SetMenuItemText( menu , item , ptitle ) ;
bf918b97 157#endif
72e7876b
SC
158}
159
bf918b97 160UInt32 UMAMenuEvent( EventRecord *inEvent )
72e7876b 161{
98af9c73 162 return MenuEvent( inEvent ) ;
72e7876b
SC
163}
164
58751a86 165void UMAEnableMenuItem( MenuRef inMenu , MenuItemIndex inItem , bool enable)
72e7876b 166{
e40298d5
JS
167 if ( enable )
168 EnableMenuItem( inMenu , inItem ) ;
169 else
170 DisableMenuItem( inMenu , inItem ) ;
72e7876b 171}
2f1ae414 172
908d407c 173void UMAAppendSubMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , SInt16 id )
2f1ae414 174{
e6c3d3e6
SC
175 AppendMenuItemTextWithCFString( menu,
176 CFSTR("A"), 0, 0,NULL);
98af9c73 177 UMASetMenuItemText( menu, (SInt16) ::CountMenuItems(menu), title , encoding );
e40298d5 178 SetMenuItemHierarchicalID( menu , CountMenuItems( menu ) , id ) ;
2f1ae414
SC
179}
180
908d407c 181void UMAInsertSubMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , MenuItemIndex item , SInt16 id )
2f1ae414 182{
e6c3d3e6
SC
183 InsertMenuItemTextWithCFString( menu,
184 CFSTR("A"), item, 0, 0);
185
98af9c73 186 UMASetMenuItemText( menu, item+1, title , encoding );
4da39c96 187 SetMenuItemHierarchicalID( menu , item+1 , id ) ;
2f1ae414
SC
188}
189
bf918b97 190void UMASetMenuItemShortcut( MenuRef menu , MenuItemIndex item , wxAcceleratorEntry *entry )
2f1ae414 191{
e40298d5
JS
192 if ( !entry )
193 return ;
58751a86 194
e40298d5
JS
195 UInt8 modifiers = 0 ;
196 SInt16 key = entry->GetKeyCode() ;
197 if ( key )
198 {
98af9c73 199 bool explicitCommandKey = (entry->GetFlags() & wxACCEL_CTRL);
e40298d5 200
98af9c73 201 if (entry->GetFlags() & wxACCEL_ALT)
e40298d5 202 modifiers |= kMenuOptionModifier ;
e40298d5 203
58751a86 204 if (entry->GetFlags() & wxACCEL_SHIFT)
e40298d5 205 modifiers |= kMenuShiftModifier ;
e40298d5
JS
206
207 SInt16 glyph = 0 ;
208 SInt16 macKey = key ;
209 if ( key >= WXK_F1 && key <= WXK_F15 )
210 {
98af9c73
DS
211 if ( !explicitCommandKey )
212 modifiers |= kMenuNoCommandModifier ;
213
a5c1f8ca
SC
214 // for some reasons this must be 0 right now
215 // everything else leads to just the first function key item
216 // to be selected. Thanks to Ryan Wilcox for finding out.
2dbc444a 217 macKey = 0 ;
e40298d5
JS
218 glyph = kMenuF1Glyph + ( key - WXK_F1 ) ;
219 if ( key >= WXK_F13 )
6239ee05 220 glyph += 12 ;
1bec2ee4 221 }
e40298d5
JS
222 else
223 {
98af9c73 224 switch ( key )
e40298d5
JS
225 {
226 case WXK_BACK :
227 macKey = kBackspaceCharCode ;
228 glyph = kMenuDeleteLeftGlyph ;
229 break ;
98af9c73 230
e40298d5
JS
231 case WXK_TAB :
232 macKey = kTabCharCode ;
233 glyph = kMenuTabRightGlyph ;
234 break ;
98af9c73 235
e40298d5
JS
236 case kEnterCharCode :
237 macKey = kEnterCharCode ;
238 glyph = kMenuEnterGlyph ;
239 break ;
98af9c73 240
e40298d5
JS
241 case WXK_RETURN :
242 macKey = kReturnCharCode ;
243 glyph = kMenuReturnGlyph ;
244 break ;
98af9c73 245
e40298d5
JS
246 case WXK_ESCAPE :
247 macKey = kEscapeCharCode ;
248 glyph = kMenuEscapeGlyph ;
249 break ;
98af9c73 250
e40298d5
JS
251 case WXK_SPACE :
252 macKey = ' ' ;
253 glyph = kMenuSpaceGlyph ;
254 break ;
98af9c73 255
e40298d5
JS
256 case WXK_DELETE :
257 macKey = kDeleteCharCode ;
258 glyph = kMenuDeleteRightGlyph ;
259 break ;
98af9c73 260
e40298d5
JS
261 case WXK_CLEAR :
262 macKey = kClearCharCode ;
263 glyph = kMenuClearGlyph ;
264 break ;
98af9c73 265
faa94f3e 266 case WXK_PAGEUP :
e40298d5
JS
267 macKey = kPageUpCharCode ;
268 glyph = kMenuPageUpGlyph ;
269 break ;
98af9c73 270
faa94f3e 271 case WXK_PAGEDOWN :
e40298d5
JS
272 macKey = kPageDownCharCode ;
273 glyph = kMenuPageDownGlyph ;
274 break ;
98af9c73 275
e40298d5
JS
276 case WXK_LEFT :
277 macKey = kLeftArrowCharCode ;
278 glyph = kMenuLeftArrowGlyph ;
279 break ;
98af9c73 280
e40298d5
JS
281 case WXK_UP :
282 macKey = kUpArrowCharCode ;
283 glyph = kMenuUpArrowGlyph ;
284 break ;
98af9c73 285
e40298d5
JS
286 case WXK_RIGHT :
287 macKey = kRightArrowCharCode ;
288 glyph = kMenuRightArrowGlyph ;
289 break ;
98af9c73 290
e40298d5
JS
291 case WXK_DOWN :
292 macKey = kDownArrowCharCode ;
293 glyph = kMenuDownArrowGlyph ;
294 break ;
98af9c73 295
4952771d
JS
296 case WXK_HOME :
297 macKey = kHomeCharCode ;
298 glyph = kMenuNorthwestArrowGlyph ;
299 break ;
300
301 case WXK_END :
302 macKey = kEndCharCode ;
303 glyph = kMenuSoutheastArrowGlyph ;
304 break ;
1bec2ee4
SC
305 default :
306 macKey = toupper( key ) ;
307 break ;
2b5f62a0 308 }
98af9c73 309
1bec2ee4
SC
310 // we now allow non command key shortcuts
311 // remove in case this gives problems
312 if ( !explicitCommandKey )
313 modifiers |= kMenuNoCommandModifier ;
2b5f62a0 314 }
bf918b97 315
1a03b3e2
JS
316 // 1d and 1e have special meaning to SetItemCmd, so
317 // do not use for these character codes.
40cc34ec 318 if (key != WXK_UP && key != WXK_RIGHT && key != WXK_DOWN && key != WXK_LEFT)
1a03b3e2
JS
319 SetItemCmd( menu, item , macKey );
320
98af9c73 321 SetMenuItemModifiers( menu, item , modifiers ) ;
2b5f62a0
VZ
322
323 if ( glyph )
98af9c73 324 SetMenuItemKeyGlyph( menu, item , glyph ) ;
e40298d5 325 }
2b5f62a0
VZ
326}
327
908d407c 328void UMAAppendMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , wxAcceleratorEntry *entry )
2b5f62a0 329{
e6c3d3e6
SC
330 AppendMenuItemTextWithCFString( menu,
331 CFSTR("A"), 0, 0,NULL);
faa94f3e 332 // don't attempt to interpret metacharacters like a '-' at the beginning (would become a separator otherwise)
a76342da 333 ChangeMenuItemAttributes( menu , ::CountMenuItems(menu), kMenuItemAttrIgnoreMeta , 0 ) ;
908d407c 334 UMASetMenuItemText(menu, (SInt16) ::CountMenuItems(menu), title , encoding );
98af9c73 335 UMASetMenuItemShortcut( menu , (SInt16) ::CountMenuItems(menu), entry ) ;
2f1ae414
SC
336}
337
908d407c 338void UMAInsertMenuItem( MenuRef menu , const wxString& title, wxFontEncoding encoding , MenuItemIndex item , wxAcceleratorEntry *entry )
2f1ae414 339{
e6c3d3e6
SC
340 InsertMenuItemTextWithCFString( menu,
341 CFSTR("A"), item, 0, 0);
98af9c73 342
faa94f3e 343 // don't attempt to interpret metacharacters like a '-' at the beginning (would become a separator otherwise)
a76342da 344 ChangeMenuItemAttributes( menu , item+1, kMenuItemAttrIgnoreMeta , 0 ) ;
908d407c 345 UMASetMenuItemText(menu, item+1 , title , encoding );
58751a86 346 UMASetMenuItemShortcut( menu , item+1 , entry ) ;
2f1ae414
SC
347}
348
72e7876b
SC
349// quickdraw
350
7052b16d
SC
351#if !TARGET_CARBON
352
2f1ae414
SC
353int gPrOpenCounter = 0 ;
354
7052b16d 355OSStatus UMAPrOpen()
2f1ae414 356{
e40298d5 357 OSErr err = noErr ;
98af9c73 358
e40298d5 359 ++gPrOpenCounter ;
98af9c73 360
e40298d5
JS
361 if ( gPrOpenCounter == 1 )
362 {
363 PrOpen() ;
364 err = PrError() ;
365 wxASSERT( err == noErr ) ;
366 }
98af9c73 367
e40298d5 368 return err ;
2f1ae414
SC
369}
370
7052b16d 371OSStatus UMAPrClose()
2f1ae414 372{
e40298d5 373 OSErr err = noErr ;
98af9c73 374
e40298d5 375 wxASSERT( gPrOpenCounter >= 1 ) ;
98af9c73 376
e40298d5
JS
377 if ( gPrOpenCounter == 1 )
378 {
379 PrClose() ;
380 err = PrError() ;
381 wxASSERT( err == noErr ) ;
382 }
98af9c73 383
e40298d5 384 --gPrOpenCounter ;
98af9c73 385
e40298d5 386 return err ;
2f1ae414
SC
387}
388
98af9c73
DS
389pascal QDGlobalsPtr GetQDGlobalsPtr() ;
390pascal QDGlobalsPtr GetQDGlobalsPtr()
72e7876b 391{
e40298d5 392 return QDGlobalsPtr (* (Ptr*) LMGetCurrentA5 ( ) - 0xCA);
72e7876b
SC
393}
394
395#endif
396
58751a86 397void UMAShowWatchCursor()
72e7876b 398{
e6c3d3e6 399 SetThemeCursor(kThemeWatchCursor);
72e7876b
SC
400}
401
98af9c73 402void UMAShowArrowCursor()
72e7876b 403{
e6c3d3e6 404 SetThemeCursor(kThemeArrowCursor);
72e7876b
SC
405}
406
407// window manager
408
98af9c73 409GrafPtr UMAGetWindowPort( WindowRef inWindowRef )
72e7876b 410{
e40298d5 411 wxASSERT( inWindowRef != NULL ) ;
98af9c73 412
58751a86
RD
413#if TARGET_CARBON
414 return (GrafPtr) GetWindowPort( inWindowRef ) ;
72e7876b 415#else
e40298d5 416 return (GrafPtr) inWindowRef ;
72e7876b
SC
417#endif
418}
419
98af9c73 420void UMADisposeWindow( WindowRef inWindowRef )
72e7876b 421{
e40298d5 422 wxASSERT( inWindowRef != NULL ) ;
98af9c73 423
e40298d5 424 DisposeWindow( inWindowRef ) ;
72e7876b
SC
425}
426
98af9c73 427void UMASetWTitle( WindowRef inWindowRef , const wxString& title , wxFontEncoding encoding )
72e7876b 428{
03e11df5 429#if TARGET_CARBON
908d407c 430 SetWindowTitleWithCFString( inWindowRef , wxMacCFStringHolder(title , encoding) ) ;
98af9c73 431
03e11df5 432#else
427ff662
SC
433 Str255 ptitle ;
434 wxMacStringToPascal( title , ptitle ) ;
e40298d5 435 SetWTitle( inWindowRef , ptitle ) ;
427ff662 436#endif
72e7876b 437}
03e11df5 438
72e7876b
SC
439// appearance additions
440
98af9c73 441void UMASetControlTitle( ControlRef inControl , const wxString& title , wxFontEncoding encoding )
427ff662
SC
442{
443#if TARGET_CARBON
908d407c 444 SetControlTitleWithCFString( inControl , wxMacCFStringHolder(title , encoding) ) ;
98af9c73 445
427ff662
SC
446#else
447 Str255 ptitle ;
448 wxMacStringToPascal( title , ptitle ) ;
449 SetControlTitle( inControl , ptitle ) ;
450#endif
451}
452
facd6764 453void UMAActivateControl( ControlRef inControl )
72e7876b 454{
98af9c73
DS
455#if TARGET_API_MAC_OSX
456 ::ActivateControl( inControl ) ;
457
458#else
22e751a5
SC
459 // we have to add the control after again to the update rgn
460 // otherwise updates get lost
e40298d5
JS
461 if ( !IsControlActive( inControl ) )
462 {
fdaf613a
SC
463 bool visible = IsControlVisible( inControl ) ;
464 if ( visible )
e40298d5 465 SetControlVisibility( inControl , false , false ) ;
98af9c73 466
3f4902f5 467 ::ActivateControl( inControl ) ;
98af9c73
DS
468
469 if ( visible )
470 {
e40298d5 471 SetControlVisibility( inControl , true , false ) ;
98af9c73 472
e40298d5 473 Rect ctrlBounds ;
98af9c73 474 InvalWindowRect( GetControlOwner(inControl), UMAGetControlBoundsInWindowCoords(inControl, &ctrlBounds) ) ;
fdaf613a 475 }
e40298d5 476 }
faa94f3e 477#endif
72e7876b
SC
478}
479
facd6764 480void UMAMoveControl( ControlRef inControl , short x , short y )
72e7876b 481{
98af9c73
DS
482#if TARGET_API_MAC_OSX
483 ::MoveControl( inControl , x , y ) ;
484
485#else
e40298d5 486 bool visible = IsControlVisible( inControl ) ;
98af9c73
DS
487 if ( visible )
488 {
e40298d5
JS
489 SetControlVisibility( inControl , false , false ) ;
490 Rect ctrlBounds ;
98af9c73 491 InvalWindowRect( GetControlOwner(inControl), GetControlBounds(inControl, &ctrlBounds) ) ;
e40298d5 492 }
98af9c73 493
e40298d5 494 ::MoveControl( inControl , x , y ) ;
98af9c73
DS
495
496 if ( visible )
497 {
e40298d5
JS
498 SetControlVisibility( inControl , true , false ) ;
499 Rect ctrlBounds ;
98af9c73 500 InvalWindowRect( GetControlOwner(inControl), GetControlBounds(inControl, &ctrlBounds) ) ;
e40298d5 501 }
facd6764 502#endif
72e7876b
SC
503}
504
facd6764 505void UMASizeControl( ControlRef inControl , short x , short y )
72e7876b 506{
98af9c73
DS
507#if TARGET_API_MAC_OSX
508 ::SizeControl( inControl , x , y ) ;
509
510#else
e40298d5 511 bool visible = IsControlVisible( inControl ) ;
98af9c73
DS
512 if ( visible )
513 {
e40298d5
JS
514 SetControlVisibility( inControl , false , false ) ;
515 Rect ctrlBounds ;
98af9c73 516 InvalWindowRect( GetControlOwner(inControl), GetControlBounds(inControl, &ctrlBounds) ) ;
58751a86 517 }
98af9c73 518
e40298d5 519 ::SizeControl( inControl , x , y ) ;
98af9c73
DS
520
521 if ( visible )
522 {
e40298d5
JS
523 SetControlVisibility( inControl , true , false ) ;
524 Rect ctrlBounds ;
98af9c73 525 InvalWindowRect( GetControlOwner(inControl), GetControlBounds(inControl, &ctrlBounds) ) ;
e40298d5 526 }
facd6764 527#endif
72e7876b
SC
528}
529
facd6764 530void UMADeactivateControl( ControlRef inControl )
72e7876b 531{
98af9c73
DS
532#if TARGET_API_MAC_OSX
533 ::DeactivateControl( inControl ) ;
534
535#else
22e751a5
SC
536 // we have to add the control after again to the update rgn
537 // otherwise updates get lost
e40298d5
JS
538 bool visible = IsControlVisible( inControl ) ;
539 if ( visible )
540 SetControlVisibility( inControl , false , false ) ;
98af9c73 541
e40298d5 542 ::DeactivateControl( inControl ) ;
98af9c73
DS
543
544 if ( visible )
545 {
fdaf613a 546 SetControlVisibility( inControl , true , false ) ;
c36f0244 547 Rect ctrlBounds ;
98af9c73 548 InvalWindowRect( GetControlOwner(inControl), UMAGetControlBoundsInWindowCoords(inControl, &ctrlBounds) ) ;
e40298d5 549 }
facd6764 550#endif
e40298d5 551}
98af9c73 552
e40298d5 553// shows the control and adds the region to the update region
98af9c73 554void UMAShowControl( ControlRef inControl )
e40298d5
JS
555{
556 SetControlVisibility( inControl , true , false ) ;
e6c3d3e6 557 HIViewSetNeedsDisplay( inControl, true );
72e7876b
SC
558}
559
facd6764 560// hides the control and adds the region to the update region
98af9c73 561void UMAHideControl( ControlRef inControl )
22e751a5 562{
e40298d5 563 SetControlVisibility( inControl , false , false ) ;
e6c3d3e6 564 HIViewSetNeedsDisplay( inControl, true );
22e751a5 565}
98af9c73 566
72e7876b 567// keyboard focus
98af9c73
DS
568OSErr UMASetKeyboardFocus( WindowPtr inWindow,
569 ControlRef inControl,
570 ControlFocusPart inPart )
72e7876b 571{
e40298d5 572 OSErr err = noErr;
e6c3d3e6 573#ifndef __LP64__
e40298d5 574 GrafPtr port ;
72055702 575
98af9c73 576 GetPort( &port ) ;
e40298d5 577 SetPortWindowPort( inWindow ) ;
e6c3d3e6 578#endif
72055702 579
e40298d5 580 err = SetKeyboardFocus( inWindow , inControl , inPart ) ;
e6c3d3e6 581#ifndef __LP64__
e40298d5 582 SetPort( port ) ;
e6c3d3e6 583#endif
98af9c73 584
e40298d5 585 return err ;
72e7876b
SC
586}
587
58751a86 588bool UMAIsWindowFloating( WindowRef inWindow )
72e7876b 589{
e40298d5 590 WindowClass cl ;
58751a86 591
e40298d5
JS
592 GetWindowClass( inWindow , &cl ) ;
593 return cl == kFloatingWindowClass ;
72e7876b
SC
594}
595
58751a86 596bool UMAIsWindowModal( WindowRef inWindow )
72e7876b 597{
e40298d5 598 WindowClass cl ;
58751a86 599
e40298d5
JS
600 GetWindowClass( inWindow , &cl ) ;
601 return cl < kFloatingWindowClass ;
72e7876b
SC
602}
603
604// others
605
606void UMAHighlightAndActivateWindow( WindowRef inWindowRef , bool inActivate )
607{
e40298d5
JS
608 if ( inWindowRef )
609 {
610// bool isHighlighted = IsWindowHighlited( inWindowRef ) ;
3103e8a9 611// if ( inActivate != isHighlighted )
e6c3d3e6 612#ifndef __LP64__
e40298d5
JS
613 GrafPtr port ;
614 GetPort( &port ) ;
615 SetPortWindowPort( inWindowRef ) ;
e6c3d3e6 616#endif
e40298d5 617 HiliteWindow( inWindowRef , inActivate ) ;
facd6764 618 ControlRef control = NULL ;
98af9c73 619 ::GetRootControl( inWindowRef , &control ) ;
e40298d5
JS
620 if ( control )
621 {
622 if ( inActivate )
623 UMAActivateControl( control ) ;
624 else
625 UMADeactivateControl( control ) ;
58751a86 626 }
e6c3d3e6 627#ifndef __LP64__
e40298d5 628 SetPort( port ) ;
e6c3d3e6 629#endif
e40298d5 630 }
72e7876b 631}
e40298d5 632
58751a86 633OSStatus UMADrawThemePlacard( const Rect *inRect , ThemeDrawState inState )
2f1ae414 634{
e6c3d3e6 635#ifndef __LP64__
e40298d5 636 return ::DrawThemePlacard( inRect , inState ) ;
e6c3d3e6
SC
637#else
638 return noErr;
639#endif
2f1ae414 640}
72e7876b 641
2f056c85 642#if !TARGET_CARBON
b03e4fcd 643static OSStatus helpMenuStatus = noErr ;
b03e4fcd 644static MenuItemIndex firstCustomItemIndex = 0 ;
2f056c85 645#endif
b03e4fcd 646
4dd25308 647static OSStatus UMAGetHelpMenu(
98af9c73 648 MenuRef * outHelpMenu,
4dd25308
VZ
649 MenuItemIndex * outFirstCustomItemIndex,
650 bool allowHelpMenuCreation);
651
652static OSStatus UMAGetHelpMenu(
653 MenuRef * outHelpMenu,
654 MenuItemIndex * outFirstCustomItemIndex,
655 bool allowHelpMenuCreation)
b03e4fcd
SC
656{
657#if TARGET_CARBON
4dd25308 658 static bool s_createdHelpMenu = false ;
98af9c73 659
4dd25308
VZ
660 if ( !s_createdHelpMenu && !allowHelpMenuCreation )
661 {
662 return paramErr ;
663 }
664
665 OSStatus status = HMGetHelpMenu( outHelpMenu , outFirstCustomItemIndex ) ;
666 s_createdHelpMenu = ( status == noErr ) ;
667 return status ;
b03e4fcd 668#else
4dd25308 669 wxUnusedVar( allowHelpMenuCreation ) ;
e40298d5 670 MenuRef helpMenuHandle ;
98af9c73 671
e40298d5
JS
672 helpMenuStatus = HMGetHelpMenuHandle( &helpMenuHandle ) ;
673 if ( firstCustomItemIndex == 0 && helpMenuStatus == noErr )
e40298d5 674 firstCustomItemIndex = CountMenuItems( helpMenuHandle ) + 1 ;
98af9c73 675
e40298d5 676 if ( outFirstCustomItemIndex )
e40298d5 677 *outFirstCustomItemIndex = firstCustomItemIndex ;
98af9c73 678
e40298d5 679 *outHelpMenu = helpMenuHandle ;
98af9c73 680
e40298d5 681 return helpMenuStatus ;
b03e4fcd
SC
682#endif
683}
76a5e5d2 684
4dd25308
VZ
685OSStatus UMAGetHelpMenu(
686 MenuRef * outHelpMenu,
687 MenuItemIndex * outFirstCustomItemIndex)
688{
689 return UMAGetHelpMenu( outHelpMenu , outFirstCustomItemIndex , true );
690}
691
692OSStatus UMAGetHelpMenuDontCreate(
693 MenuRef * outHelpMenu,
694 MenuItemIndex * outFirstCustomItemIndex)
695{
696 return UMAGetHelpMenu( outHelpMenu , outFirstCustomItemIndex , false );
697}
698
e6c3d3e6
SC
699#ifndef __LP64__
700
98af9c73 701wxMacPortStateHelper::wxMacPortStateHelper( GrafPtr newport )
76a5e5d2 702{
e40298d5
JS
703 m_clip = NULL ;
704 Setup( newport ) ;
76a5e5d2
SC
705}
706
707wxMacPortStateHelper::wxMacPortStateHelper()
708{
e40298d5 709 m_clip = NULL ;
76a5e5d2
SC
710}
711
712void wxMacPortStateHelper::Setup( GrafPtr newport )
713{
e40298d5
JS
714 GetPort( &m_oldPort ) ;
715 SetPort( newport ) ;
98af9c73
DS
716 SetOrigin(0, 0);
717
427ff662 718 wxASSERT_MSG( m_clip == NULL , wxT("Cannot call setup twice") ) ;
e40298d5
JS
719 m_clip = NewRgn() ;
720 GetClip( m_clip );
98af9c73
DS
721 m_textFont = GetPortTextFont( (CGrafPtr) newport );
722 m_textSize = GetPortTextSize( (CGrafPtr) newport );
723 m_textStyle = GetPortTextFace( (CGrafPtr) newport );
724 m_textMode = GetPortTextMode( (CGrafPtr) newport );
e40298d5
JS
725 GetThemeDrawingState( &m_drawingState ) ;
726 m_currentPort = newport ;
76a5e5d2 727}
98af9c73 728
76a5e5d2
SC
729void wxMacPortStateHelper::Clear()
730{
e40298d5
JS
731 if ( m_clip )
732 {
733 DisposeRgn( m_clip ) ;
734 DisposeThemeDrawingState( m_drawingState ) ;
735 m_clip = NULL ;
736 }
76a5e5d2
SC
737}
738
739wxMacPortStateHelper::~wxMacPortStateHelper()
740{
e40298d5
JS
741 if ( m_clip )
742 {
743 SetPort( m_currentPort ) ;
744 SetClip( m_clip ) ;
745 DisposeRgn( m_clip ) ;
746 TextFont( m_textFont );
747 TextSize( m_textSize );
748 TextFace( m_textStyle );
749 TextMode( m_textMode );
750 SetThemeDrawingState( m_drawingState , true ) ;
751 SetPort( m_oldPort ) ;
752 }
76a5e5d2
SC
753}
754
e6c3d3e6
SC
755#endif
756
98af9c73 757Rect * UMAGetControlBoundsInWindowCoords( ControlRef theControl, Rect *bounds )
facd6764 758{
facd6764 759 GetControlBounds( theControl , bounds ) ;
98af9c73 760
facd6764 761#if TARGET_API_MAC_OSX
37d0bfa8 762 WindowRef tlwref = GetControlOwner( theControl ) ;
37d0bfa8 763
789ae0cf 764 wxTopLevelWindowMac* tlwwx = wxFindWinFromMacWindow( tlwref ) ;
e779b609 765 if ( tlwwx != NULL )
789ae0cf
SC
766 {
767 ControlRef rootControl = tlwwx->GetPeer()->GetControlRef() ;
98af9c73
DS
768 HIPoint hiPoint = CGPointMake( 0 , 0 ) ;
769 HIViewConvertPoint( &hiPoint , HIViewGetSuperview(theControl) , rootControl ) ;
789ae0cf
SC
770 OffsetRect( bounds , (short) hiPoint.x , (short) hiPoint.y ) ;
771 }
facd6764 772#endif
98af9c73 773
facd6764
SC
774 return bounds ;
775}
776
6239ee05
SC
777size_t UMAPutBytesCFRefCallback( void *info, const void *bytes, size_t count )
778{
779 CFMutableDataRef data = (CFMutableDataRef) info;
780 if ( data )
781 {
782 CFDataAppendBytes( data, (const UInt8*) bytes, count );
783 }
784 return count;
785}
786
787void UMAReleaseCFDataProviderCallback( void *info, const void *data, size_t count )
788{
789 if ( info )
790 CFRelease( (CFDataRef) info );
791}
792
793void UMAReleaseCFDataConsumerCallback( void *info )
794{
795 if ( info )
796 CFRelease( (CFDataRef) info );
797}
798
799CGDataProviderRef UMACGDataProviderCreateWithCFData( CFDataRef data )
800{
801 if ( data == NULL )
802 return NULL;
803
804#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
805 if( &CGDataProviderCreateWithCFData != NULL )
806 {
807 return CGDataProviderCreateWithCFData( data );
808 }
809#endif
810
811 // make sure we keep it until done
812 CFRetain( data );
813 CGDataProviderRef provider = CGDataProviderCreateWithData( (void*) data , CFDataGetBytePtr( data ) ,
814 CFDataGetLength( data ), UMAReleaseCFDataProviderCallback );
815 // if provider couldn't be created, release the data again
816 if ( provider == NULL )
817 CFRelease( data );
818 return provider;
819}
820
821CGDataConsumerRef UMACGDataConsumerCreateWithCFData( CFMutableDataRef data )
822{
823 if ( data == NULL )
824 return NULL;
825
826#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
827 if( &CGDataConsumerCreateWithCFData != NULL )
828 {
829 return CGDataConsumerCreateWithCFData( data );
830 }
831#endif
832 // make sure we keep it until done
833 CFRetain( data );
834 CGDataConsumerCallbacks callbacks;
835 callbacks.putBytes = UMAPutBytesCFRefCallback;
836 callbacks.releaseConsumer = UMAReleaseCFDataConsumerCallback;
837 CGDataConsumerRef consumer = CGDataConsumerCreate( data , &callbacks );
838 // if consumer couldn't be created, release the data again
839 if ( consumer == NULL )
840 CFRelease( data );
841 return consumer;
842}
2dbc444a
RD
843#endif // wxUSE_GUI
844
845#if wxUSE_BASE
846
847static bool sUMASystemInitialized = false ;
848
849bool UMASystemIsInitialized()
850{
851 return sUMASystemInitialized ;
852}
853
854void UMASetSystemIsInitialized(bool val)
855{
856 sUMASystemInitialized = val;
857}
858
2dbc444a 859#endif // wxUSE_BASE