X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8736cc485b94318d9c5d1e4bb443f16de9b8c9b4..f53c8638250a66a3721eff864fbc89ab6e9dfd35:/src/mac/carbon/toplevel.cpp diff --git a/src/mac/carbon/toplevel.cpp b/src/mac/carbon/toplevel.cpp index b0930420a0..dec6597956 100644 --- a/src/mac/carbon/toplevel.cpp +++ b/src/mac/carbon/toplevel.cpp @@ -57,6 +57,9 @@ // constants // ---------------------------------------------------------------------------- +// unified title and toolbar constant - not in Tiger headers, so we duplicate it here +#define kWindowUnifiedTitleAndToolbarAttribute (1 << 7) + // trace mask for activation tracing messages static const wxChar *TRACE_ACTIVATE = _T("activation"); @@ -99,6 +102,7 @@ static const EventTypeSpec eventList[] = { kEventClassWindow , kEventWindowBoundsChanging } , { kEventClassWindow , kEventWindowBoundsChanged } , { kEventClassWindow , kEventWindowClose } , + { kEventClassWindow , kEventWindowGetRegion } , // we have to catch these events on the toplevel window level, // as controls don't get the raw mouse events anymore @@ -801,6 +805,36 @@ static pascal OSStatus wxMacTopLevelWindowEventHandler( EventHandlerCallRef hand } break ; + case kEventWindowGetRegion : + { + if ( toplevelWindow->GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT ) + { + WindowRegionCode windowRegionCode ; + + // Fetch the region code that is being queried + GetEventParameter( event, + kEventParamWindowRegionCode, + typeWindowRegionCode, NULL, + sizeof windowRegionCode, NULL, + &windowRegionCode ) ; + + // If it is the opaque region code then set the + // region to empty and return noErr to stop event + // propagation + if ( windowRegionCode == kWindowOpaqueRgn ) { + RgnHandle region; + GetEventParameter( event, + kEventParamRgnHandle, + typeQDRgnHandle, NULL, + sizeof region, NULL, + ®ion) ; + SetEmptyRgn(region) ; + result = noErr ; + } + } + } + break ; + default : break ; } @@ -1248,6 +1282,13 @@ void wxTopLevelWindowMac::MacCreateRealWindow( } #endif +#if TARGET_API_MAC_OSX + if ( m_macWindow != NULL ) + { + MacSetUnifiedAppearance( true ) ; + } +#endif + // the frame window event handler InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow)) ) ; MacInstallTopLevelWindowEventHandler() ; @@ -1460,12 +1501,36 @@ void wxTopLevelWindowMac::SetExtraStyle(long exStyle) if ( m_macWindow != NULL ) { bool metal = GetExtraStyle() & wxFRAME_EX_METAL ; + if ( MacGetMetalAppearance() != metal ) + { + if ( MacGetUnifiedAppearance() ) + MacSetUnifiedAppearance( !metal ) ; + MacSetMetalAppearance( metal ) ; + } } #endif } +bool wxTopLevelWindowMac::SetBackgroundStyle(wxBackgroundStyle style) +{ + if ( !wxTopLevelWindowBase::SetBackgroundStyle(style) ) + return false ; + + WindowRef windowRef = HIViewGetWindow( (HIViewRef)GetHandle() ); + + if ( GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT ) + { + OSStatus err = HIWindowChangeFeatures( windowRef, 0, kWindowIsOpaque ); + verify_noerr( err ); + err = ReshapeCustomWindow( windowRef ); + verify_noerr( err ); + } + + return true ; +} + // TODO: switch to structure bounds - // we are still using coordinates of the content view // @@ -1529,6 +1594,9 @@ void wxTopLevelWindowMac::DoGetClientSize( int *width, int *height ) const void wxTopLevelWindowMac::MacSetMetalAppearance( bool set ) { #if TARGET_API_MAC_OSX + if ( MacGetUnifiedAppearance() ) + MacSetUnifiedAppearance( false ) ; + MacChangeWindowAttributes( set ? kWindowMetalAttribute : kWindowNoAttributes , set ? kWindowNoAttributes : kWindowMetalAttribute ) ; #endif @@ -1539,10 +1607,41 @@ bool wxTopLevelWindowMac::MacGetMetalAppearance() const #if TARGET_API_MAC_OSX return MacGetWindowAttributes() & kWindowMetalAttribute ; #else - return false ; + return false; #endif } +void wxTopLevelWindowMac::MacSetUnifiedAppearance( bool set ) +{ +#if TARGET_API_MAC_OSX + if ( UMAGetSystemVersion() >= 0x1040 ) + { + if ( MacGetMetalAppearance() ) + MacSetMetalAppearance( false ) ; + + MacChangeWindowAttributes( set ? kWindowUnifiedTitleAndToolbarAttribute : kWindowNoAttributes , + set ? kWindowNoAttributes : kWindowUnifiedTitleAndToolbarAttribute) ; + + // For some reason, Tiger uses white as the background color for this appearance, + // while most apps using it use the typical striped background. Restore that behavior + // for wx. + // TODO: Determine if we need this on Leopard as well. (should be harmless either way, + // though) + SetBackgroundColour( wxSYS_COLOUR_WINDOW ) ; + } +#endif +} + +bool wxTopLevelWindowMac::MacGetUnifiedAppearance() const +{ +#if TARGET_API_MAC_OSX + if ( UMAGetSystemVersion() >= 0x1040 ) + return MacGetWindowAttributes() & kWindowUnifiedTitleAndToolbarAttribute ; + else +#endif + return false; +} + void wxTopLevelWindowMac::MacChangeWindowAttributes( wxUint32 attributesToSet , wxUint32 attributesToClear ) { ChangeWindowAttributes( (WindowRef)m_macWindow, attributesToSet, attributesToClear ) ;