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