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