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