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