X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7205570233ce8420b71fa5df368054c8953ff0e4..91c68292f64a7ca83480a639264f4369b80ea1e5:/src/mac/carbon/uma.cpp diff --git a/src/mac/carbon/uma.cpp b/src/mac/carbon/uma.cpp index 60b61374a0..f6bd01f91f 100644 --- a/src/mac/carbon/uma.cpp +++ b/src/mac/carbon/uma.cpp @@ -1,9 +1,18 @@ #include "wx/defs.h" #include "wx/dc.h" #include "wx/mac/uma.h" +#include #ifndef __DARWIN__ - #include +# include +# if defined(TARGET_CARBON) +# if PM_USE_SESSION_APIS +# include +# endif +# include +# else +# include +# endif #endif // since we have decided that we only support 8.6 upwards we are @@ -14,6 +23,9 @@ static bool sUMAHasAppearance = false ; static long sUMAAppearanceVersion = 0 ; +static bool sUMAHasAquaLayout = false ; +static bool sUMASystemInitialized = false ; + extern int gAGABackgroundColor ; bool UMAHasAppearance() { return sUMAHasAppearance ; } long UMAGetAppearanceVersion() { return sUMAAppearanceVersion ; } @@ -23,6 +35,8 @@ static long sUMAWindowManagerAttr = 0 ; bool UMAHasWindowManager() { return sUMAHasWindowManager ; } long UMAGetWindowManagerAttr() { return sUMAWindowManagerAttr ; } +bool UMAHasAquaLayout() { return sUMAHasAquaLayout ; } +bool UMASystemIsInitialized() { return sUMASystemInitialized ; } void UMACleanupToolbox() { @@ -34,6 +48,8 @@ void UMACleanupToolbox() { NavUnload() ; } + if ( TXNTerminateTextension != (void*) kUnresolvedCFragSymbolAddress ) + TXNTerminateTextension( ) ; } void UMAInitToolbox( UInt16 inMoreMastersCalls ) { @@ -74,7 +90,6 @@ void UMAInitToolbox( UInt16 inMoreMastersCalls ) sUMAHasWindowManager = sUMAWindowManagerAttr & gestaltWindowMgrPresent ; } -#ifndef __DARWIN__ #if TARGET_CARBON // Call currently implicitely done : InitFloatingWindows() ; #else @@ -82,15 +97,59 @@ void UMAInitToolbox( UInt16 inMoreMastersCalls ) InitFloatingWindows() ; else InitWindows(); -#endif #endif if ( NavServicesAvailable() ) { NavLoad() ; } + + long menuMgrAttr ; + Gestalt( gestaltMenuMgrAttr , &menuMgrAttr ) ; + if ( menuMgrAttr & gestaltMenuMgrAquaLayoutMask ) + sUMAHasAquaLayout = true ; + + if ( TXNInitTextension != (void*) kUnresolvedCFragSymbolAddress ) + { + FontFamilyID fontId ; + Str255 fontName ; + SInt16 fontSize ; + Style fontStyle ; + GetThemeFont(kThemeSmallSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ; + GetFNum( fontName, &fontId ); + + TXNMacOSPreferredFontDescription fontDescriptions[] = + { + { fontId , (fontSize << 16) ,kTXNDefaultFontStyle, kTXNSystemDefaultEncoding } , + } ; + int noOfFontDescriptions = sizeof( fontDescriptions ) / sizeof(TXNMacOSPreferredFontDescription) ; +#if 0 // TARGET_CARBON + --noOfFontDescriptions ; +#endif + // kTXNAlwaysUseQuickDrawTextMask might be desirable because of speed increases but it crashes the app under OS X upon key stroke + OptionBits options = kTXNWantMoviesMask | kTXNWantSoundMask | kTXNWantGraphicsMask ; +#if TARGET_CARBON + if ( !UMAHasAquaLayout() ) +#endif + { + options |= kTXNAlwaysUseQuickDrawTextMask ; + } + TXNInitTextension(fontDescriptions, noOfFontDescriptions, options ); + } + + + sUMASystemInitialized = true ; + } +/* +Boolean CanUseATSUI() + { + long result; + OSErr err = Gestalt(gestaltATSUVersion, &result); + return (err == noErr); + } +*/ // process manager long UMAGetProcessMode() { @@ -118,6 +177,7 @@ bool UMAGetProcessModeDoesActivateOnFGSwitch() void UMASetMenuTitle( MenuRef menu , StringPtr title ) { +/* #if !TARGET_CARBON long size = GetHandleSize( (Handle) menu ) ; const long headersize = 14 ; @@ -140,8 +200,9 @@ void UMASetMenuTitle( MenuRef menu , StringPtr title ) SetHandleSize( (Handle) menu , size + (newlen - oldlen ) ) ; } #else +*/ SetMenuTitle( menu , title ) ; -#endif +//#endif } UInt32 UMAMenuEvent( EventRecord *inEvent ) @@ -227,11 +288,7 @@ void UMAInsertMenuItem( MenuRef menu , StringPtr l , MenuItemIndex item , SInt16 int gPrOpenCounter = 0 ; -#if TARGET_CARBON && PM_USE_SESSION_APIS -OSStatus UMAPrOpen(PMPrintSession *macPrintSession) -#else -OSStatus UMAPrOpen() -#endif +OSStatus UMAPrOpen(void *macPrintSession) { #if !TARGET_CARBON OSErr err = noErr ; @@ -249,7 +306,7 @@ OSStatus UMAPrOpen() if ( gPrOpenCounter == 1 ) { #if PM_USE_SESSION_APIS - err = PMCreateSession(macPrintSession) ; + err = PMCreateSession((PMPrintSession *)macPrintSession) ; #else err = PMBegin() ; #endif @@ -259,11 +316,7 @@ OSStatus UMAPrOpen() #endif } -#if TARGET_CARBON && PM_USE_SESSION_APIS -OSStatus UMAPrClose(PMPrintSession *macPrintSession) -#else -OSStatus UMAPrClose() -#endif +OSStatus UMAPrClose(void *macPrintSession) { #if !TARGET_CARBON OSErr err = noErr ; @@ -282,8 +335,8 @@ OSStatus UMAPrClose() if ( gPrOpenCounter == 1 ) { #if PM_USE_SESSION_APIS - err = PMRelease(*macPrintSession) ; - *macPrintSession = kPMNoReference; + err = PMRelease(*(PMPrintSession *)macPrintSession) ; + *(PMPrintSession *)macPrintSession = kPMNoReference; #else err = PMEnd() ; #endif @@ -342,7 +395,7 @@ GrafPtr UMAGetWindowPort( WindowRef inWindowRef ) { wxASSERT( inWindowRef != NULL ) ; #if TARGET_CARBON - return GetWindowPort( inWindowRef ) ; + return (GrafPtr) GetWindowPort( inWindowRef ) ; #else return (GrafPtr) inWindowRef ; #endif @@ -381,8 +434,10 @@ void UMAGetWTitleC( WindowRef inWindowRef , char *title ) void UMAActivateControl( ControlHandle inControl ) { - if ( !IsControlActive( inControl ) ) - { + // we have to add the control after again to the update rgn + // otherwise updates get lost + if ( !IsControlActive( inControl ) ) + { bool visible = IsControlVisible( inControl ) ; if ( visible ) SetControlVisibility( inControl , false , false ) ; @@ -392,7 +447,7 @@ void UMAActivateControl( ControlHandle inControl ) Rect ctrlBounds ; InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; } - } + } } void UMADrawControl( ControlHandle inControl ) @@ -400,13 +455,12 @@ void UMADrawControl( ControlHandle inControl ) WindowRef theWindow = GetControlOwner(inControl) ; RgnHandle updateRgn = NewRgn() ; GetWindowUpdateRgn( theWindow , updateRgn ) ; - Point zero = { 0 , 0 } ; - LocalToGlobal( &zero ) ; - OffsetRgn( updateRgn , -zero.h , -zero.v ) ; - ::DrawControlInCurrentPort( inControl ) ; - InvalWindowRgn( theWindow, updateRgn) ; - DisposeRgn( updateRgn ) ; - + Point zero = { 0 , 0 } ; + LocalToGlobal( &zero ) ; + OffsetRgn( updateRgn , -zero.h , -zero.v ) ; + ::DrawControlInCurrentPort( inControl ) ; + InvalWindowRgn( theWindow, updateRgn) ; + DisposeRgn( updateRgn ) ; } void UMAMoveControl( ControlHandle inControl , short x , short y ) @@ -432,7 +486,7 @@ void UMASizeControl( ControlHandle inControl , short x , short y ) SetControlVisibility( inControl , false , false ) ; Rect ctrlBounds ; InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; - } + } ::SizeControl( inControl , x , y ) ; if ( visible ) { SetControlVisibility( inControl , true , false ) ; @@ -443,8 +497,8 @@ void UMASizeControl( ControlHandle inControl , short x , short y ) void UMADeactivateControl( ControlHandle inControl ) { - if ( IsControlActive( inControl ) ) - { + // we have to add the control after again to the update rgn + // otherwise updates get lost bool visible = IsControlVisible( inControl ) ; if ( visible ) SetControlVisibility( inControl , false , false ) ; @@ -454,7 +508,6 @@ void UMADeactivateControl( ControlHandle inControl ) Rect ctrlBounds ; InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; } - } } // shows the control and adds the region to the update region void UMAShowControl (ControlHandle inControl) @@ -464,6 +517,13 @@ void UMAShowControl (ControlHandle inControl) InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; } +// shows the control and adds the region to the update region +void UMAHideControl (ControlHandle inControl) +{ + SetControlVisibility( inControl , false , false ) ; + Rect ctrlBounds ; + InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; +} // keyboard focus OSErr UMASetKeyboardFocus (WindowPtr inWindow, ControlHandle inControl, @@ -475,7 +535,6 @@ OSErr UMASetKeyboardFocus (WindowPtr inWindow, SetPortWindowPort( inWindow ) ; - SetOrigin( 0 , 0 ) ; err = SetKeyboardFocus( inWindow , inControl , inPart ) ; SetPort( port ) ; return err ; @@ -527,7 +586,6 @@ void UMAHighlightAndActivateWindow( WindowRef inWindowRef , bool inActivate ) GrafPtr port ; GetPort( &port ) ; SetPortWindowPort( inWindowRef ) ; - SetOrigin( 0 , 0 ) ; HiliteWindow( inWindowRef , inActivate ) ; ControlHandle control = NULL ; ::GetRootControl( inWindowRef , & control ) ; @@ -546,3 +604,81 @@ OSStatus UMADrawThemePlacard( const Rect *inRect , ThemeDrawState inState ) return ::DrawThemePlacard( inRect , inState ) ; } +#if !TARGET_CARBON +static OSStatus helpMenuStatus = noErr ; +static MenuItemIndex firstCustomItemIndex = 0 ; +#endif + +OSStatus UMAGetHelpMenu( + MenuRef * outHelpMenu, + MenuItemIndex * outFirstCustomItemIndex) +{ +#if TARGET_CARBON + return HMGetHelpMenu( outHelpMenu , outFirstCustomItemIndex ) ; +#else + MenuRef helpMenuHandle ; + helpMenuStatus = HMGetHelpMenuHandle( &helpMenuHandle ) ; + if ( firstCustomItemIndex == 0 && helpMenuStatus == noErr ) + { + firstCustomItemIndex = CountMenuItems( helpMenuHandle ) + 1 ; + } + if ( outFirstCustomItemIndex ) + { + *outFirstCustomItemIndex = firstCustomItemIndex ; + } + *outHelpMenu = helpMenuHandle ; + return helpMenuStatus ; +#endif +} + +wxMacPortStateHelper::wxMacPortStateHelper( GrafPtr newport) +{ + m_clip = NULL ; + Setup( newport ) ; +} + +wxMacPortStateHelper::wxMacPortStateHelper() +{ + m_clip = NULL ; +} + +void wxMacPortStateHelper::Setup( GrafPtr newport ) +{ + GetPort( &m_oldPort ) ; + SetPort( newport ) ; + wxASSERT_MSG( m_clip == NULL , "Cannot call setup twice" ) ; + m_clip = NewRgn() ; + GetClip( m_clip ); + m_textFont = GetPortTextFont( (CGrafPtr) newport); + m_textSize = GetPortTextSize( (CGrafPtr) newport); + m_textStyle = GetPortTextFace( (CGrafPtr) newport); + m_textMode = GetPortTextMode( (CGrafPtr) newport); + GetThemeDrawingState( &m_drawingState ) ; + m_currentPort = newport ; +} +void wxMacPortStateHelper::Clear() +{ + if ( m_clip ) + { + DisposeRgn( m_clip ) ; + DisposeThemeDrawingState( m_drawingState ) ; + m_clip = NULL ; + } +} + +wxMacPortStateHelper::~wxMacPortStateHelper() +{ + if ( m_clip ) + { + SetPort( m_currentPort ) ; + SetClip( m_clip ) ; + DisposeRgn( m_clip ) ; + TextFont( m_textFont ); + TextSize( m_textSize ); + TextFace( m_textStyle ); + TextMode( m_textMode ); + SetThemeDrawingState( m_drawingState , true ) ; + SetPort( m_oldPort ) ; + } +} +