X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/716d0327363e81485eb6dd13b62d6f83c9dd4bab..c2c87924e7e3906b8cf1f93ebbd362eab17f6857:/src/mac/carbon/toplevel.cpp diff --git a/src/mac/carbon/toplevel.cpp b/src/mac/carbon/toplevel.cpp index 8d279e9599..d45476496a 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"); @@ -130,7 +133,7 @@ static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , Event UInt32 when = EventTimeToTicks( GetEventTime( event ) ) ; #if wxUSE_UNICODE - UInt32 dataSize = 0 ; + ByteCount dataSize = 0 ; if ( GetEventParameter( event, kEventParamKeyUnicodes, typeUnicodeText, NULL, 0 , &dataSize, NULL ) == noErr ) { UniChar buf[2] ; @@ -248,9 +251,10 @@ static pascal OSStatus KeyboardEventHandler( EventHandlerCallRef handler , Event wxWindow* g_MacLastWindow = NULL ; -static EventMouseButton lastButton = 0 ; +EventMouseButton g_lastButton = 0 ; +bool g_lastButtonWasFakeRight = false ; -static void SetupMouseEvent( wxMouseEvent &wxevent , wxMacCarbonEvent &cEvent ) +void SetupMouseEvent( wxMouseEvent &wxevent , wxMacCarbonEvent &cEvent ) { UInt32 modifiers = cEvent.GetParameter(kEventParamKeyModifiers, typeUInt32) ; Point screenMouseLocation = cEvent.GetParameter(kEventParamMouseLocation) ; @@ -269,24 +273,33 @@ static void SetupMouseEvent( wxMouseEvent &wxevent , wxMacCarbonEvent &cEvent ) wxevent.m_metaDown = modifiers & cmdKey; wxevent.SetTimestamp( cEvent.GetTicks() ) ; - // a control click is interpreted as a right click + // a control click is interpreted as a right click + bool thisButtonIsFakeRight = false ; if ( button == kEventMouseButtonPrimary && (modifiers & controlKey) ) + { button = kEventMouseButtonSecondary ; - + thisButtonIsFakeRight = true ; + } // otherwise we report double clicks by connecting a left click with a ctrl-left click - if ( clickCount > 1 && button != lastButton ) + if ( clickCount > 1 && button != g_lastButton ) clickCount = 1 ; // we must make sure that our synthetic 'right' button corresponds in // mouse down, moved and mouse up, and does not deliver a right down and left up if ( cEvent.GetKind() == kEventMouseDown ) - lastButton = button ; + { + g_lastButton = button ; + g_lastButtonWasFakeRight = thisButtonIsFakeRight ; + } if ( button == 0 ) - lastButton = 0 ; - else if ( lastButton ) - button = lastButton ; + { + g_lastButton = 0 ; + g_lastButtonWasFakeRight = false ; + } + else if ( g_lastButton == kEventMouseButtonSecondary && g_lastButtonWasFakeRight ) + button = g_lastButton ; // determine the correct down state, wx does not want a 'down' for a mouseUp event, // while mac delivers this button @@ -358,12 +371,14 @@ static void SetupMouseEvent( wxMouseEvent &wxevent , wxMacCarbonEvent &cEvent ) { wxevent.SetEventType( wxEVT_MOUSEWHEEL ) ; - // EventMouseWheelAxis axis = cEvent.GetParameter(kEventParamMouseWheelAxis, typeMouseWheelAxis) ; - SInt32 delta = cEvent.GetParameter(kEventParamMouseWheelDelta, typeLongInteger) ; + EventMouseWheelAxis axis = cEvent.GetParameter(kEventParamMouseWheelAxis, typeMouseWheelAxis) ; + SInt32 delta = cEvent.GetParameter(kEventParamMouseWheelDelta, typeSInt32) ; wxevent.m_wheelRotation = delta; wxevent.m_wheelDelta = 1; wxevent.m_linesPerAction = 1; + if ( axis == kEventMouseWheelAxisX ) + wxevent.m_wheelAxis = 1; } break ; @@ -467,7 +482,7 @@ pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , Ev if ( window ) { - QDGlobalToLocalPoint( UMAGetWindowPort(window ) , &windowMouseLocation ) ; + wxMacGlobalToLocal( window, &windowMouseLocation ) ; if ( wxApp::s_captureWindow #if !NEW_CAPTURE_HANDLING @@ -589,7 +604,7 @@ pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , Ev if ( wxevent.GetEventType() == wxEVT_LEFT_DOWN ) { // ... that is set focus to this window - if (currentMouseWindow->AcceptsFocus() && wxWindow::FindFocus()!=currentMouseWindow) + if (currentMouseWindow->CanAcceptFocus() && wxWindow::FindFocus()!=currentMouseWindow) currentMouseWindow->SetFocus(); } @@ -929,7 +944,7 @@ bool wxTopLevelWindowMac::Create(wxWindow *parent, m_windowId = id == -1 ? NewControlId() : id; wxWindow::SetLabel( title ) ; - MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ; + MacCreateRealWindow( title, pos , size , style , name ) ; SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)); @@ -968,6 +983,10 @@ wxTopLevelWindowMac::~wxTopLevelWindowMac() FullScreenData *data = (FullScreenData *) m_macFullScreenData ; delete data ; m_macFullScreenData = NULL ; + + // avoid dangling refs + if ( s_macDeactivateWindow == this ) + s_macDeactivateWindow = NULL; } @@ -980,10 +999,18 @@ void wxTopLevelWindowMac::Maximize(bool maximize) Point idealSize = { 0 , 0 } ; if ( maximize ) { +#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 + HIRect bounds ; + HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay,kHICoordSpace72DPIGlobal, + &bounds); + idealSize.h = bounds.size.width; + idealSize.v = bounds.size.height; +#else Rect rect ; GetAvailableWindowPositioningBounds(GetMainDevice(),&rect) ; idealSize.h = rect.right - rect.left ; idealSize.v = rect.bottom - rect.top ; +#endif } ZoomWindowIdeal( (WindowRef)m_macWindow , maximize ? inZoomOut : inZoomIn , &idealSize ) ; } @@ -1021,12 +1048,6 @@ wxPoint wxTopLevelWindowMac::GetClientAreaOrigin() const return wxPoint(0, 0) ; } -void wxTopLevelWindowMac::SetIcon(const wxIcon& icon) -{ - // this sets m_icon - wxTopLevelWindowBase::SetIcon(icon); -} - void wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush &brush ) { wxTopLevelWindowBase::MacSetBackgroundBrush( brush ) ; @@ -1102,6 +1123,20 @@ void wxTopLevelWindowMac::MacCreateRealWindow( wclass = kPlainWindowClass ; } } + else if ( HasFlag( wxPOPUP_WINDOW ) ) + { + // TEMPORARY HACK! + // Until we've got a real wxPopupWindow class on wxMac make it a + // little easier for wxFrame to be used to emulate it and workaround + // the lack of wxPopupWindow. + if ( HasFlag( wxBORDER_NONE ) ) + wclass = kHelpWindowClass ; // has no border + else + wclass = kPlainWindowClass ; // has a single line border, it will have to do for now + //attr |= kWindowNoShadowAttribute; // turn off the shadow Should we?? + group = GetWindowGroupOfClass( // float above other windows + kFloatingWindowClass) ; + } else if ( HasFlag( wxCAPTION ) ) { wclass = kDocumentWindowClass ; @@ -1148,6 +1183,9 @@ void wxTopLevelWindowMac::MacCreateRealWindow( if ( HasFlag(wxSTAY_ON_TOP) ) group = GetWindowGroupOfClass(kUtilityWindowClass) ; + if ( HasFlag( wxFRAME_FLOAT_ON_PARENT ) ) + group = GetWindowGroupOfClass(kFloatingWindowClass) ; + attr |= kWindowCompositingAttribute; #if 0 // wxMAC_USE_CORE_GRAPHICS ; TODO : decide on overall handling of high dpi screens (pixel vs userscale) attr |= kWindowFrameworkScaledAttribute; @@ -1157,8 +1195,12 @@ void wxTopLevelWindowMac::MacCreateRealWindow( { WindowDefSpec customWindowDefSpec; customWindowDefSpec.defType = kWindowDefProcPtr; - customWindowDefSpec.u.defProc = NewWindowDefUPP(wxShapedMacWindowDef); - + customWindowDefSpec.u.defProc = +#ifdef __LP64__ + (WindowDefUPP) wxShapedMacWindowDef; +#else + NewWindowDefUPP(wxShapedMacWindowDef); +#endif err = ::CreateCustomWindow( &customWindowDefSpec, wclass, attr, &theBoundsRect, (WindowRef*) &m_macWindow); @@ -1173,6 +1215,11 @@ void wxTopLevelWindowMac::MacCreateRealWindow( wxCHECK_RET( err == noErr, wxT("Mac OS error when trying to create new window") ); + // setup a separate group for each window, so that overlays can be handled easily + verify_noerr( CreateWindowGroup( kWindowGroupAttrMoveTogether | kWindowGroupAttrLayerTogether | kWindowGroupAttrHideOnCollapse, &group )); + verify_noerr( SetWindowGroupParent( group, GetWindowGroup( (WindowRef) m_macWindow ))); + verify_noerr( SetWindowGroup( (WindowRef) m_macWindow , group )); + // the create commands are only for content rect, // so we have to set the size again as structure bounds SetWindowBounds( (WindowRef) m_macWindow , kWindowStructureRgn , &theBoundsRect ) ; @@ -1204,6 +1251,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() ; @@ -1416,8 +1470,14 @@ 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 } @@ -1485,6 +1545,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 @@ -1495,10 +1558,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 ) ; @@ -1599,7 +1693,7 @@ bool wxTopLevelWindowMac::SetShape(const wxRegion& region) DisposeRgn(oldRgn); // Save the region so we can use it later - SetWRefCon((WindowRef)MacGetWindowRef(), (SInt32)shapeRegion); + SetWRefCon((WindowRef)MacGetWindowRef(), (URefCon)shapeRegion); // inform the window manager that the window has changed shape ReshapeCustomWindow((WindowRef)MacGetWindowRef()); @@ -1615,13 +1709,12 @@ bool wxTopLevelWindowMac::SetShape(const wxRegion& region) static void wxShapedMacWindowGetPos(WindowRef window, Rect* inRect) { GetWindowPortBounds(window, inRect); - Point pt = { inRect->left, inRect->top }; - - QDLocalToGlobalPoint( GetWindowPort(window), &pt ) ; + Point pt = { inRect->top ,inRect->left }; + wxMacLocalToGlobal( window, &pt ) ; + inRect->bottom += pt.v - inRect->top; + inRect->right += pt.h - inRect->left; inRect->top = pt.v; inRect->left = pt.h; - inRect->bottom += pt.v; - inRect->right += pt.h; } static SInt32 wxShapedMacWindowGetFeatures(WindowRef window, SInt32 param)