X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b03e4fcd11071534f942a6c3b16bb86792c71e83..5eac771d0949d4696c7c29f2ead81a2d0b0b73c8:/src/mac/carbon/uma.cpp?ds=sidebyside diff --git a/src/mac/carbon/uma.cpp b/src/mac/carbon/uma.cpp index 00e22e0ffa..1c6afd4eb6 100644 --- a/src/mac/carbon/uma.cpp +++ b/src/mac/carbon/uma.cpp @@ -4,7 +4,15 @@ #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 @@ -13,19 +21,24 @@ // windows manager, control manager, navigation services etc. are // present -#define wxUSE_MLTE 0 - static bool sUMAHasAppearance = false ; static long sUMAAppearanceVersion = 0 ; +static long sUMASystemVersion = 0 ; +static bool sUMAHasAquaLayout = false ; +static bool sUMASystemInitialized = false ; + extern int gAGABackgroundColor ; bool UMAHasAppearance() { return sUMAHasAppearance ; } long UMAGetAppearanceVersion() { return sUMAAppearanceVersion ; } +long UMAGetSystemVersion() { return sUMASystemVersion ; } static bool sUMAHasWindowManager = false ; static long sUMAWindowManagerAttr = 0 ; bool UMAHasWindowManager() { return sUMAHasWindowManager ; } long UMAGetWindowManagerAttr() { return sUMAWindowManagerAttr ; } +bool UMAHasAquaLayout() { return sUMAHasAquaLayout ; } +bool UMASystemIsInitialized() { return sUMASystemInitialized ; } void UMACleanupToolbox() { @@ -37,9 +50,8 @@ void UMACleanupToolbox() { NavUnload() ; } -#if wxUSE_MLTE - TXNTerminateTextension( ) ; -#endif + if ( TXNTerminateTextension != (void*) kUnresolvedCFragSymbolAddress ) + TXNTerminateTextension( ) ; } void UMAInitToolbox( UInt16 inMoreMastersCalls ) { @@ -61,6 +73,9 @@ void UMAInitToolbox( UInt16 inMoreMastersCalls ) InitCursor(); #endif + if ( Gestalt(gestaltSystemVersion, &sUMASystemVersion) != noErr) + sUMASystemVersion = 0x0000 ; + long theAppearance ; if ( Gestalt( gestaltAppearanceAttr, &theAppearance ) == noErr ) { @@ -80,7 +95,6 @@ void UMAInitToolbox( UInt16 inMoreMastersCalls ) sUMAHasWindowManager = sUMAWindowManagerAttr & gestaltWindowMgrPresent ; } -#ifndef __DARWIN__ #if TARGET_CARBON // Call currently implicitely done : InitFloatingWindows() ; #else @@ -88,7 +102,6 @@ void UMAInitToolbox( UInt16 inMoreMastersCalls ) InitFloatingWindows() ; else InitWindows(); -#endif #endif if ( NavServicesAvailable() ) @@ -96,16 +109,52 @@ void UMAInitToolbox( UInt16 inMoreMastersCalls ) NavLoad() ; } -#if wxUSE_MLTE - TXNMacOSPreferredFontDescription defaults; - defaults.fontID = kFontIDGeneva ; - defaults.pointSize = (10 << 16) ; - defaults.fontStyle = kTXNDefaultFontStyle; - defaults.encoding = kTXNSystemDefaultEncoding; - TXNInitTextension(&defaults, 1, (kTXNAlwaysUseQuickDrawTextMask | kTXNWantMoviesMask | kTXNWantSoundMask | kTXNWantGraphicsMask)); + 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() { @@ -133,6 +182,7 @@ bool UMAGetProcessModeDoesActivateOnFGSwitch() void UMASetMenuTitle( MenuRef menu , StringPtr title ) { +/* #if !TARGET_CARBON long size = GetHandleSize( (Handle) menu ) ; const long headersize = 14 ; @@ -155,8 +205,9 @@ void UMASetMenuTitle( MenuRef menu , StringPtr title ) SetHandleSize( (Handle) menu , size + (newlen - oldlen ) ) ; } #else +*/ SetMenuTitle( menu , title ) ; -#endif +//#endif } UInt32 UMAMenuEvent( EventRecord *inEvent ) @@ -176,77 +227,174 @@ void UMADisableMenuItem( MenuRef inMenu , MenuItemIndex inItem ) void UMAAppendSubMenuItem( MenuRef menu , StringPtr l , SInt16 id ) { - Str255 label ; - memcpy( label , l , l[0]+1 ) ; - // hardcoded adding of the submenu combination for mac - - int theEnd = label[0] + 1; - if (theEnd > 251) - theEnd = 251; // mac allows only 255 characters - label[theEnd++] = '/'; - label[theEnd++] = hMenuCmd; - label[theEnd++] = '!'; - label[theEnd++] = id ; - label[theEnd] = 0x00; - label[0] = theEnd; - MacAppendMenu(menu, label); + MacAppendMenu(menu, l); + SetMenuItemHierarchicalID( menu , CountMenuItems( menu ) , id ) ; } void UMAInsertSubMenuItem( MenuRef menu , StringPtr l , MenuItemIndex item , SInt16 id ) { - Str255 label ; - memcpy( label , l , l[0]+1 ) ; - // hardcoded adding of the submenu combination for mac - - int theEnd = label[0] + 1; - if (theEnd > 251) - theEnd = 251; // mac allows only 255 characters - label[theEnd++] = '/'; - label[theEnd++] = hMenuCmd; - label[theEnd++] = '!'; - label[theEnd++] = id; - label[theEnd] = 0x00; - label[0] = theEnd; - MacInsertMenuItem(menu, label , item); + MacInsertMenuItem(menu, l , item); + SetMenuItemHierarchicalID( menu , item , id ) ; } -void UMAAppendMenuItem( MenuRef menu , StringPtr l , SInt16 key, UInt8 modifiers ) +void UMASetMenuItemShortcut( MenuRef menu , MenuItemIndex item , SInt16 key , UInt8 modifiers ) { - Str255 label ; - memcpy( label , l , l[0]+1 ) ; if ( key ) { - int pos = label[0] ; - label[++pos] = '/'; - label[++pos] = toupper( key ); - label[0] = pos ; + SInt16 glyph = 0 ; + SInt16 macKey = key ; + if ( key >= WXK_F1 && key <= WXK_F15 ) + { + macKey = kFunctionKeyCharCode ; + glyph = kMenuF1Glyph + ( key - WXK_F1 ) ; + if ( key >= WXK_F13 ) + glyph += 13 ; + switch( key ) + { + case WXK_F1 : + macKey += ( 0x7a << 8 ) ; + break ; + case WXK_F2 : + macKey += ( 0x78 << 8 ) ; + break ; + case WXK_F3 : + macKey += ( 0x63 << 8 ) ; + break ; + case WXK_F4 : + macKey += ( 0x76 << 8 ) ; + break ; + case WXK_F5 : + macKey += ( 0x60 << 8 ) ; + break ; + case WXK_F6 : + macKey += ( 0x61 << 8 ) ; + break ; + case WXK_F7 : + macKey += ( 0x62 << 8 ) ; + break ; + case WXK_F8 : + macKey += ( 0x64 << 8 ) ; + break ; + case WXK_F9 : + macKey += ( 0x65 << 8 ) ; + break ; + case WXK_F10 : + macKey += ( 0x6D << 8 ) ; + break ; + case WXK_F11 : + macKey += ( 0x67 << 8 ) ; + break ; + case WXK_F12 : + macKey += ( 0x6F << 8 ) ; + break ; + case WXK_F13 : + macKey += ( 0x69 << 8 ) ; + break ; + case WXK_F14 : + macKey += ( 0x6B << 8 ) ; + break ; + case WXK_F15 : + macKey += ( 0x71 << 8 ) ; + break ; + default : + break ; + } ; + // unfortunately this does not yet trigger the right key , + // for some reason mac justs picks the first function key menu + // defined, so we turn this off + macKey = 0 ; + glyph = 0 ; + } + else + { + switch( key ) + { + case WXK_BACK : + macKey = kBackspaceCharCode ; + glyph = kMenuDeleteLeftGlyph ; + break ; + case WXK_TAB : + macKey = kTabCharCode ; + glyph = kMenuTabRightGlyph ; + break ; + case kEnterCharCode : + macKey = kEnterCharCode ; + glyph = kMenuEnterGlyph ; + break ; + case WXK_RETURN : + macKey = kReturnCharCode ; + glyph = kMenuReturnGlyph ; + break ; + case WXK_ESCAPE : + macKey = kEscapeCharCode ; + glyph = kMenuEscapeGlyph ; + break ; + case WXK_SPACE : + macKey = ' ' ; + glyph = kMenuSpaceGlyph ; + break ; + case WXK_DELETE : + macKey = kDeleteCharCode ; + glyph = kMenuDeleteRightGlyph ; + break ; + case WXK_CLEAR : + macKey = kClearCharCode ; + glyph = kMenuClearGlyph ; + break ; + case WXK_PRIOR : // PAGE UP + macKey = kPageUpCharCode ; + glyph = kMenuPageUpGlyph ; + break ; + case WXK_NEXT : + macKey = kPageDownCharCode ; + glyph = kMenuPageDownGlyph ; + break ; + case WXK_LEFT : + macKey = kLeftArrowCharCode ; + glyph = kMenuLeftArrowGlyph ; + break ; + case WXK_UP : + macKey = kUpArrowCharCode ; + glyph = kMenuUpArrowGlyph ; + break ; + case WXK_RIGHT : + macKey = kRightArrowCharCode ; + glyph = kMenuRightArrowGlyph ; + break ; + case WXK_DOWN : + macKey = kDownArrowCharCode ; + glyph = kMenuDownArrowGlyph ; + break ; + } + } + + SetItemCmd( menu, item , macKey ); + SetMenuItemModifiers(menu, item , modifiers ) ; + + if ( glyph ) + SetMenuItemKeyGlyph(menu, item , glyph ) ; } - MacAppendMenu( menu , label ) ; +} + +void UMAAppendMenuItem( MenuRef menu , StringPtr l , SInt16 key, UInt8 modifiers ) +{ + MacAppendMenu(menu, "\pA"); + SetMenuItemText(menu, (SInt16) ::CountMenuItems(menu), l); + UMASetMenuItemShortcut( menu , (SInt16) ::CountMenuItems(menu), key , modifiers ) ; } void UMAInsertMenuItem( MenuRef menu , StringPtr l , MenuItemIndex item , SInt16 key, UInt8 modifiers ) { - Str255 label ; - memcpy( label , l , l[0]+1 ) ; - if ( key ) - { - int pos = label[0] ; - label[++pos] = '/'; - label[++pos] = toupper( key ); - label[0] = pos ; - } - MacInsertMenuItem( menu , label , item) ; + MacInsertMenuItem( menu , "\p" , item) ; + SetMenuItemText(menu, item , l); + UMASetMenuItemShortcut( menu , item , key , modifiers ) ; } // quickdraw 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 ; @@ -264,7 +412,7 @@ OSStatus UMAPrOpen() if ( gPrOpenCounter == 1 ) { #if PM_USE_SESSION_APIS - err = PMCreateSession(macPrintSession) ; + err = PMCreateSession((PMPrintSession *)macPrintSession) ; #else err = PMBegin() ; #endif @@ -274,11 +422,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 ; @@ -297,8 +441,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 @@ -357,7 +501,7 @@ GrafPtr UMAGetWindowPort( WindowRef inWindowRef ) { wxASSERT( inWindowRef != NULL ) ; #if TARGET_CARBON - return GetWindowPort( inWindowRef ) ; + return (GrafPtr) GetWindowPort( inWindowRef ) ; #else return (GrafPtr) inWindowRef ; #endif @@ -396,8 +540,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 ) ; @@ -407,7 +553,7 @@ void UMAActivateControl( ControlHandle inControl ) Rect ctrlBounds ; InvalWindowRect(GetControlOwner(inControl),GetControlBounds(inControl,&ctrlBounds) ) ; } - } + } } void UMADrawControl( ControlHandle inControl ) @@ -415,13 +561,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 ) @@ -458,8 +603,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 ) ; @@ -469,7 +614,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) @@ -479,6 +623,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, @@ -490,7 +641,6 @@ OSErr UMASetKeyboardFocus (WindowPtr inWindow, SetPortWindowPort( inWindow ) ; - SetOrigin( 0 , 0 ) ; err = SetKeyboardFocus( inWindow , inControl , inPart ) ; SetPort( port ) ; return err ; @@ -542,7 +692,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 ) ; @@ -561,9 +710,10 @@ OSStatus UMADrawThemePlacard( const Rect *inRect , ThemeDrawState inState ) return ::DrawThemePlacard( inRect , inState ) ; } +#if !TARGET_CARBON static OSStatus helpMenuStatus = noErr ; -static MenuRef helpMenuHandle = NULL ; static MenuItemIndex firstCustomItemIndex = 0 ; +#endif OSStatus UMAGetHelpMenu( MenuRef * outHelpMenu, @@ -572,13 +722,11 @@ OSStatus UMAGetHelpMenu( #if TARGET_CARBON return HMGetHelpMenu( outHelpMenu , outFirstCustomItemIndex ) ; #else - if ( helpMenuHandle == NULL ) + MenuRef helpMenuHandle ; + helpMenuStatus = HMGetHelpMenuHandle( &helpMenuHandle ) ; + if ( firstCustomItemIndex == 0 && helpMenuStatus == noErr ) { - helpMenuStatus = HMGetHelpMenuHandle( &helpMenuHandle ) ; - if ( helpMenuStatus == noErr ) - { - firstCustomItemIndex = CountMenuItems( helpMenuHandle ) + 1 ; - } + firstCustomItemIndex = CountMenuItems( helpMenuHandle ) + 1 ; } if ( outFirstCustomItemIndex ) { @@ -588,3 +736,55 @@ OSStatus UMAGetHelpMenu( 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 ) ; + } +} +