3 #include <MacTextEditor.h>
6 # include <Navigation.h>
7 # if defined(TARGET_CARBON)
8 # if PM_USE_SESSION_APIS
11 # include <PMApplication.h>
13 # include <Printing.h>
20 #include "wx/mac/uma.h"
22 // since we have decided that we only support 8.6 upwards we are
23 // checking for these minimum requirements in the startup code of
24 // the application so all wxWindows code can safely assume that appearance 1.1
25 // windows manager, control manager, navigation services etc. are
28 static bool sUMAHasAppearance
= false ;
29 static long sUMAAppearanceVersion
= 0 ;
30 static long sUMASystemVersion
= 0 ;
31 static bool sUMAHasAquaLayout
= false ;
32 static bool sUMASystemInitialized
= false ;
34 extern int gAGABackgroundColor
;
35 bool UMAHasAppearance() { return sUMAHasAppearance
; }
36 long UMAGetAppearanceVersion() { return sUMAAppearanceVersion
; }
37 long UMAGetSystemVersion() { return sUMASystemVersion
; }
39 static bool sUMAHasWindowManager
= false ;
40 static long sUMAWindowManagerAttr
= 0 ;
42 bool UMAHasWindowManager() { return sUMAHasWindowManager
; }
43 long UMAGetWindowManagerAttr() { return sUMAWindowManagerAttr
; }
44 bool UMAHasAquaLayout() { return sUMAHasAquaLayout
; }
45 bool UMASystemIsInitialized() { return sUMASystemInitialized
; }
47 void UMACleanupToolbox()
49 if ( sUMAHasAppearance
)
51 UnregisterAppearanceClient() ;
53 if ( NavServicesAvailable() )
57 if ( TXNTerminateTextension
!= (void*) kUnresolvedCFragSymbolAddress
)
58 TXNTerminateTextension( ) ;
60 void UMAInitToolbox( UInt16 inMoreMastersCalls
)
64 for (long i
= 1; i
<= inMoreMastersCalls
; i
++)
67 ::InitGraf(&qd
.thePort
);
72 ::FlushEvents(everyEvent
, 0);
75 PurgeSpace(&total
, &contig
);
80 if ( Gestalt(gestaltSystemVersion
, &sUMASystemVersion
) != noErr
)
81 sUMASystemVersion
= 0x0000 ;
84 if ( Gestalt( gestaltAppearanceAttr
, &theAppearance
) == noErr
)
86 sUMAHasAppearance
= true ;
87 RegisterAppearanceClient();
88 if ( Gestalt( gestaltAppearanceVersion
, &theAppearance
) == noErr
)
90 sUMAAppearanceVersion
= theAppearance
;
94 sUMAAppearanceVersion
= 0x0100 ;
97 if ( Gestalt( gestaltWindowMgrAttr
, &sUMAWindowManagerAttr
) == noErr
)
99 sUMAHasWindowManager
= sUMAWindowManagerAttr
& gestaltWindowMgrPresent
;
103 // Call currently implicitely done : InitFloatingWindows() ;
105 if ( sUMAHasWindowManager
)
106 InitFloatingWindows() ;
111 if ( NavServicesAvailable() )
117 Gestalt( gestaltMenuMgrAttr
, &menuMgrAttr
) ;
118 if ( menuMgrAttr
& gestaltMenuMgrAquaLayoutMask
)
119 sUMAHasAquaLayout
= true ;
121 if ( TXNInitTextension
!= (void*) kUnresolvedCFragSymbolAddress
)
123 FontFamilyID fontId
;
127 GetThemeFont(kThemeSmallSystemFont
, GetApplicationScript() , fontName
, &fontSize
, &fontStyle
) ;
128 GetFNum( fontName
, &fontId
);
130 TXNMacOSPreferredFontDescription fontDescriptions
[] =
132 { fontId
, (fontSize
<< 16) ,kTXNDefaultFontStyle
, kTXNSystemDefaultEncoding
} ,
134 int noOfFontDescriptions
= sizeof( fontDescriptions
) / sizeof(TXNMacOSPreferredFontDescription
) ;
135 #if 0 // TARGET_CARBON
136 --noOfFontDescriptions
;
138 // kTXNAlwaysUseQuickDrawTextMask might be desirable because of speed increases but it crashes the app under OS X upon key stroke
139 OptionBits options
= kTXNWantMoviesMask
| kTXNWantSoundMask
| kTXNWantGraphicsMask
;
141 if ( !UMAHasAquaLayout() )
144 options
|= kTXNAlwaysUseQuickDrawTextMask
;
146 TXNInitTextension(fontDescriptions
, noOfFontDescriptions
, options
);
150 sUMASystemInitialized
= true ;
155 Boolean CanUseATSUI()
158 OSErr err = Gestalt(gestaltATSUVersion, &result);
159 return (err == noErr);
163 long UMAGetProcessMode()
166 ProcessInfoRec processinfo
;
167 ProcessSerialNumber procno
;
169 procno
.highLongOfPSN
= NULL
;
170 procno
.lowLongOfPSN
= kCurrentProcess
;
171 processinfo
.processInfoLength
= sizeof(ProcessInfoRec
);
172 processinfo
.processName
= NULL
;
173 processinfo
.processAppSpec
= NULL
;
175 err
= ::GetProcessInformation( &procno
, &processinfo
) ;
176 wxASSERT( err
== noErr
) ;
177 return processinfo
.processMode
;
180 bool UMAGetProcessModeDoesActivateOnFGSwitch()
182 return UMAGetProcessMode() & modeDoesActivateOnFGSwitch
;
187 MenuRef
UMANewMenu( SInt16 id
, const wxString
& title
)
189 wxString str
= wxStripMenuCodes( title
) ;
192 CFStringRef cfs
= wxMacCreateCFString( str
) ;
193 CreateNewMenu( id
, 0 , &menu
) ;
194 SetMenuTitleWithCFString( menu
, cfs
) ;
198 wxMacStringToPascal( str
, ptitle
) ;
199 menu
= ::NewMenu( id
, ptitle
) ;
204 void UMASetMenuTitle( MenuRef menu
, const wxString
& title
)
206 wxString str
= wxStripMenuCodes( title
) ;
208 CFStringRef cfs
= wxMacCreateCFString( str
) ;
209 SetMenuTitleWithCFString( menu
, cfs
) ;
213 wxMacStringToPascal( str
, ptitle
) ;
214 SetMenuTitle( menu
, ptitle
) ;
218 void UMASetMenuItemText( MenuRef menu
, MenuItemIndex item
, const wxString
& title
)
220 wxString str
= wxStripMenuCodes( title
) ;
222 CFStringRef cfs
= wxMacCreateCFString( str
) ;
223 SetMenuItemTextWithCFString( menu
, item
, cfs
) ;
227 wxMacStringToPascal( str
, ptitle
) ;
228 SetMenuItemText( menu
, item
, ptitle
) ;
233 UInt32
UMAMenuEvent( EventRecord
*inEvent
)
235 return MenuEvent( inEvent
) ;
238 void UMAEnableMenuItem( MenuRef inMenu
, MenuItemIndex inItem
, bool enable
)
241 EnableMenuItem( inMenu
, inItem
) ;
243 DisableMenuItem( inMenu
, inItem
) ;
246 void UMAAppendSubMenuItem( MenuRef menu
, const wxString
& title
, SInt16 id
)
248 MacAppendMenu(menu
, "\pA");
249 UMASetMenuItemText(menu
, (SInt16
) ::CountMenuItems(menu
), title
);
250 SetMenuItemHierarchicalID( menu
, CountMenuItems( menu
) , id
) ;
253 void UMAInsertSubMenuItem( MenuRef menu
, const wxString
& title
, MenuItemIndex item
, SInt16 id
)
255 MacInsertMenuItem(menu
, "\pA" , item
);
256 UMASetMenuItemText(menu
, item
, title
);
257 SetMenuItemHierarchicalID( menu
, item
, id
) ;
260 void UMASetMenuItemShortcut( MenuRef menu
, MenuItemIndex item
, wxAcceleratorEntry
*entry
)
265 UInt8 modifiers
= 0 ;
266 SInt16 key
= entry
->GetKeyCode() ;
269 bool explicitCommandKey
= false ;
271 if ( entry
->GetFlags() & wxACCEL_CTRL
)
273 explicitCommandKey
= true ;
276 if (entry
->GetFlags() & wxACCEL_ALT
)
278 modifiers
|= kMenuOptionModifier
;
281 if (entry
->GetFlags() & wxACCEL_SHIFT
)
283 modifiers
|= kMenuShiftModifier
;
287 SInt16 macKey
= key
;
288 if ( key
>= WXK_F1
&& key
<= WXK_F15
)
290 macKey
= kFunctionKeyCharCode
;
291 glyph
= kMenuF1Glyph
+ ( key
- WXK_F1
) ;
292 if ( key
>= WXK_F13
)
294 if ( !explicitCommandKey
)
295 modifiers
|= kMenuNoCommandModifier
;
300 macKey
+= ( 0x7a << 8 ) ;
303 macKey
+= ( 0x78 << 8 ) ;
306 macKey
+= ( 0x63 << 8 ) ;
309 macKey
+= ( 0x76 << 8 ) ;
312 macKey
+= ( 0x60 << 8 ) ;
315 macKey
+= ( 0x61 << 8 ) ;
318 macKey
+= ( 0x62 << 8 ) ;
321 macKey
+= ( 0x64 << 8 ) ;
324 macKey
+= ( 0x65 << 8 ) ;
327 macKey
+= ( 0x6D << 8 ) ;
330 macKey
+= ( 0x67 << 8 ) ;
333 macKey
+= ( 0x6F << 8 ) ;
336 macKey
+= ( 0x69 << 8 ) ;
339 macKey
+= ( 0x6B << 8 ) ;
342 macKey
+= ( 0x71 << 8 ) ;
347 // unfortunately this does not yet trigger the right key ,
348 // for some reason mac justs picks the first function key menu
349 // defined, so we turn this off
358 macKey
= kBackspaceCharCode
;
359 glyph
= kMenuDeleteLeftGlyph
;
362 macKey
= kTabCharCode
;
363 glyph
= kMenuTabRightGlyph
;
365 case kEnterCharCode
:
366 macKey
= kEnterCharCode
;
367 glyph
= kMenuEnterGlyph
;
370 macKey
= kReturnCharCode
;
371 glyph
= kMenuReturnGlyph
;
374 macKey
= kEscapeCharCode
;
375 glyph
= kMenuEscapeGlyph
;
379 glyph
= kMenuSpaceGlyph
;
382 macKey
= kDeleteCharCode
;
383 glyph
= kMenuDeleteRightGlyph
;
386 macKey
= kClearCharCode
;
387 glyph
= kMenuClearGlyph
;
389 case WXK_PRIOR
: // PAGE UP
390 macKey
= kPageUpCharCode
;
391 glyph
= kMenuPageUpGlyph
;
394 macKey
= kPageDownCharCode
;
395 glyph
= kMenuPageDownGlyph
;
398 macKey
= kLeftArrowCharCode
;
399 glyph
= kMenuLeftArrowGlyph
;
402 macKey
= kUpArrowCharCode
;
403 glyph
= kMenuUpArrowGlyph
;
406 macKey
= kRightArrowCharCode
;
407 glyph
= kMenuRightArrowGlyph
;
410 macKey
= kDownArrowCharCode
;
411 glyph
= kMenuDownArrowGlyph
;
416 SetItemCmd( menu
, item
, macKey
);
417 SetMenuItemModifiers(menu
, item
, modifiers
) ;
420 SetMenuItemKeyGlyph(menu
, item
, glyph
) ;
424 void UMAAppendMenuItem( MenuRef menu
, const wxString
& title
, wxAcceleratorEntry
*entry
)
426 MacAppendMenu(menu
, "\pA");
427 UMASetMenuItemText(menu
, (SInt16
) ::CountMenuItems(menu
), title
);
428 UMASetMenuItemShortcut( menu
, (SInt16
) ::CountMenuItems(menu
), entry
) ;
431 void UMAInsertMenuItem( MenuRef menu
, const wxString
& title
, MenuItemIndex item
, wxAcceleratorEntry
*entry
)
433 MacInsertMenuItem( menu
, "\p" , item
) ;
434 UMASetMenuItemText(menu
, item
, title
);
435 UMASetMenuItemShortcut( menu
, item
, entry
) ;
440 int gPrOpenCounter
= 0 ;
442 OSStatus
UMAPrOpen(void *macPrintSession
)
447 if ( gPrOpenCounter
== 1 )
451 wxASSERT( err
== noErr
) ;
455 OSStatus err
= noErr
;
457 if ( gPrOpenCounter
== 1 )
459 #if PM_USE_SESSION_APIS
460 err
= PMCreateSession((PMPrintSession
*)macPrintSession
) ;
464 wxASSERT( err
== noErr
) ;
470 OSStatus
UMAPrClose(void *macPrintSession
)
474 wxASSERT( gPrOpenCounter
>= 1 ) ;
475 if ( gPrOpenCounter
== 1 )
479 wxASSERT( err
== noErr
) ;
484 OSStatus err
= noErr
;
485 wxASSERT( gPrOpenCounter
>= 1 ) ;
486 if ( gPrOpenCounter
== 1 )
488 #if PM_USE_SESSION_APIS
489 err
= PMRelease(*(PMPrintSession
*)macPrintSession
) ;
490 *(PMPrintSession
*)macPrintSession
= kPMNoReference
;
502 pascal QDGlobalsPtr
GetQDGlobalsPtr (void) ;
503 pascal QDGlobalsPtr
GetQDGlobalsPtr (void)
505 return QDGlobalsPtr (* (Ptr
*) LMGetCurrentA5 ( ) - 0xCA);
510 void UMAShowWatchCursor()
514 CursHandle watchFob
= GetCursor (watchCursor
);
521 // Cursor preservedArrow;
522 // GetQDGlobalsArrow (&preservedArrow);
523 // SetQDGlobalsArrow (*watchFob);
525 // SetQDGlobalsArrow (&preservedArrow);
526 SetCursor (*watchFob
);
528 SetCursor (*watchFob
);
533 void UMAShowArrowCursor()
537 SetCursor (GetQDGlobalsArrow (&arrow
));
539 SetCursor (&(qd
.arrow
));
545 GrafPtr
UMAGetWindowPort( WindowRef inWindowRef
)
547 wxASSERT( inWindowRef
!= NULL
) ;
549 return (GrafPtr
) GetWindowPort( inWindowRef
) ;
551 return (GrafPtr
) inWindowRef
;
555 void UMADisposeWindow( WindowRef inWindowRef
)
557 wxASSERT( inWindowRef
!= NULL
) ;
558 DisposeWindow( inWindowRef
) ;
561 void UMASetWTitleC( WindowRef inWindowRef
, const char *title
)
564 strncpy( (char*)ptitle
, title
, 96 ) ;
567 c2pstrcpy( ptitle
, (char *)ptitle
) ;
569 c2pstr( (char*)ptitle
) ;
571 SetWTitle( inWindowRef
, ptitle
) ;
574 void UMAGetWTitleC( WindowRef inWindowRef
, char *title
)
576 GetWTitle( inWindowRef
, (unsigned char*)title
) ;
578 p2cstrcpy( title
, (unsigned char *)title
) ;
580 p2cstr( (unsigned char*)title
) ;
584 // appearance additions
586 void UMAActivateControl( ControlHandle inControl
)
588 // we have to add the control after again to the update rgn
589 // otherwise updates get lost
590 if ( !IsControlActive( inControl
) )
592 bool visible
= IsControlVisible( inControl
) ;
594 SetControlVisibility( inControl
, false , false ) ;
595 ::ActivateControl( inControl
) ;
597 SetControlVisibility( inControl
, true , false ) ;
599 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
604 void UMADrawControl( ControlHandle inControl
)
606 WindowRef theWindow
= GetControlOwner(inControl
) ;
607 RgnHandle updateRgn
= NewRgn() ;
608 GetWindowUpdateRgn( theWindow
, updateRgn
) ;
609 Point zero
= { 0 , 0 } ;
610 LocalToGlobal( &zero
) ;
611 OffsetRgn( updateRgn
, -zero
.h
, -zero
.v
) ;
612 ::DrawControlInCurrentPort( inControl
) ;
613 InvalWindowRgn( theWindow
, updateRgn
) ;
614 DisposeRgn( updateRgn
) ;
617 void UMAMoveControl( ControlHandle inControl
, short x
, short y
)
619 bool visible
= IsControlVisible( inControl
) ;
621 SetControlVisibility( inControl
, false , false ) ;
623 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
625 ::MoveControl( inControl
, x
, y
) ;
627 SetControlVisibility( inControl
, true , false ) ;
629 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
633 void UMASizeControl( ControlHandle inControl
, short x
, short y
)
635 bool visible
= IsControlVisible( inControl
) ;
637 SetControlVisibility( inControl
, false , false ) ;
639 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
641 ::SizeControl( inControl
, x
, y
) ;
643 SetControlVisibility( inControl
, true , false ) ;
645 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
649 void UMADeactivateControl( ControlHandle inControl
)
651 // we have to add the control after again to the update rgn
652 // otherwise updates get lost
653 bool visible
= IsControlVisible( inControl
) ;
655 SetControlVisibility( inControl
, false , false ) ;
656 ::DeactivateControl( inControl
) ;
658 SetControlVisibility( inControl
, true , false ) ;
660 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
663 // shows the control and adds the region to the update region
664 void UMAShowControl (ControlHandle inControl
)
666 SetControlVisibility( inControl
, true , false ) ;
668 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
671 // shows the control and adds the region to the update region
672 void UMAHideControl (ControlHandle inControl
)
674 SetControlVisibility( inControl
, false , false ) ;
676 InvalWindowRect(GetControlOwner(inControl
),GetControlBounds(inControl
,&ctrlBounds
) ) ;
679 OSErr
UMASetKeyboardFocus (WindowPtr inWindow
,
680 ControlHandle inControl
,
681 ControlFocusPart inPart
)
687 SetPortWindowPort( inWindow
) ;
689 err
= SetKeyboardFocus( inWindow
, inControl
, inPart
) ;
696 void UMAUpdateControls( WindowPtr inWindow
, RgnHandle inRgn
)
698 RgnHandle updateRgn
= NewRgn() ;
699 GetWindowUpdateRgn( inWindow
, updateRgn
) ;
701 Point zero
= { 0 , 0 } ;
702 LocalToGlobal( &zero
) ;
703 OffsetRgn( updateRgn
, -zero
.h
, -zero
.v
) ;
705 UpdateControls( inWindow
, inRgn
) ;
706 InvalWindowRgn( inWindow
, updateRgn
) ;
707 DisposeRgn( updateRgn
) ;
710 bool UMAIsWindowFloating( WindowRef inWindow
)
714 GetWindowClass( inWindow
, &cl
) ;
715 return cl
== kFloatingWindowClass
;
718 bool UMAIsWindowModal( WindowRef inWindow
)
722 GetWindowClass( inWindow
, &cl
) ;
723 return cl
< kFloatingWindowClass
;
728 void UMAHighlightAndActivateWindow( WindowRef inWindowRef
, bool inActivate
)
732 // bool isHighlighted = IsWindowHighlited( inWindowRef ) ;
733 // if ( inActivate != isHightlited )
736 SetPortWindowPort( inWindowRef
) ;
737 HiliteWindow( inWindowRef
, inActivate
) ;
738 ControlHandle control
= NULL
;
739 ::GetRootControl( inWindowRef
, & control
) ;
743 UMAActivateControl( control
) ;
745 UMADeactivateControl( control
) ;
751 OSStatus
UMADrawThemePlacard( const Rect
*inRect
, ThemeDrawState inState
)
753 return ::DrawThemePlacard( inRect
, inState
) ;
757 static OSStatus helpMenuStatus
= noErr
;
758 static MenuItemIndex firstCustomItemIndex
= 0 ;
761 OSStatus
UMAGetHelpMenu(
762 MenuRef
* outHelpMenu
,
763 MenuItemIndex
* outFirstCustomItemIndex
)
766 return HMGetHelpMenu( outHelpMenu
, outFirstCustomItemIndex
) ;
768 MenuRef helpMenuHandle
;
769 helpMenuStatus
= HMGetHelpMenuHandle( &helpMenuHandle
) ;
770 if ( firstCustomItemIndex
== 0 && helpMenuStatus
== noErr
)
772 firstCustomItemIndex
= CountMenuItems( helpMenuHandle
) + 1 ;
774 if ( outFirstCustomItemIndex
)
776 *outFirstCustomItemIndex
= firstCustomItemIndex
;
778 *outHelpMenu
= helpMenuHandle
;
779 return helpMenuStatus
;
783 wxMacPortStateHelper::wxMacPortStateHelper( GrafPtr newport
)
789 wxMacPortStateHelper::wxMacPortStateHelper()
794 void wxMacPortStateHelper::Setup( GrafPtr newport
)
796 GetPort( &m_oldPort
) ;
798 wxASSERT_MSG( m_clip
== NULL
, "Cannot call setup twice" ) ;
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
;
808 void wxMacPortStateHelper::Clear()
812 DisposeRgn( m_clip
) ;
813 DisposeThemeDrawingState( m_drawingState
) ;
818 wxMacPortStateHelper::~wxMacPortStateHelper()
822 SetPort( m_currentPort
) ;
824 DisposeRgn( m_clip
) ;
825 TextFont( m_textFont
);
826 TextSize( m_textSize
);
827 TextFace( m_textStyle
);
828 TextMode( m_textMode
);
829 SetThemeDrawingState( m_drawingState
, true ) ;
830 SetPort( m_oldPort
) ;
834 OSStatus
UMAPutScrap( Size size
, OSType type
, void *data
)
836 OSStatus err
= noErr
;
838 err
= PutScrap( size
, type
, data
) ;
841 err
= GetCurrentScrap (&scrap
);
844 err
= PutScrapFlavor (scrap
, type
, 0, size
, data
);