From 0e8458a1d23f6887fe72c6ee567de16f7502dfc0 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Fri, 21 Jan 2011 13:03:57 +0100 Subject: Cocoa/Alien: keep the scrolling within correct bounds --- src/gui/kernel/qt_cocoa_helpers_mac.mm | 2 ++ src/gui/kernel/qwidget_mac.mm | 35 +++++++++------------------------- 2 files changed, 11 insertions(+), 26 deletions(-) diff --git a/src/gui/kernel/qt_cocoa_helpers_mac.mm b/src/gui/kernel/qt_cocoa_helpers_mac.mm index 19e0996..35b9d52 100644 --- a/src/gui/kernel/qt_cocoa_helpers_mac.mm +++ b/src/gui/kernel/qt_cocoa_helpers_mac.mm @@ -93,9 +93,11 @@ QT_BEGIN_NAMESPACE +#ifdef QT_MAC_USE_COCOA // Cmd + left mousebutton should produce a right button // press (mainly for mac users with one-button mice): static bool qt_leftButtonIsRightButton = false; +#endif Q_GLOBAL_STATIC(QMacWindowFader, macwindowFader); diff --git a/src/gui/kernel/qwidget_mac.mm b/src/gui/kernel/qwidget_mac.mm index 4e488bf..5fe35db 100644 --- a/src/gui/kernel/qwidget_mac.mm +++ b/src/gui/kernel/qwidget_mac.mm @@ -4667,8 +4667,10 @@ void QWidgetPrivate::scroll_sys(int dx, int dy, const QRect &qscrollRect) accelEnv = qgetenv("QT_NO_FAST_SCROLL").toInt() == 0; } - // Scroll the whole widget instead if qscrollRect is not valid: + // Scroll the whole widget if qscrollRect is not valid: QRect validScrollRect = qscrollRect.isValid() ? qscrollRect : q->rect(); + validScrollRect &= clipRect(); + // If q is overlapped by other widgets, we cannot just blit pixels since // this will move overlapping widgets as well. In case we just update: const bool overlapped = isOverlapped(validScrollRect.translated(data.crect.topLeft())); @@ -4809,34 +4811,15 @@ void QWidgetPrivate::scroll_sys(int dx, int dy, const QRect &qscrollRect) // Adjust the scroll rect to the location as seen from the native parent: validScrollRect.moveTo(scrollTopLeftInsideNative); - - // Ensure that that the destination rect of the - // scroll doesn't draw outside of q's geometry: - if (dy != 0) { - if (scrollTopLeftInsideNative.y() + dy < widgetTopLeftInsideNative.y()) { - // Scrolling outside top - validScrollRect.setTop(widgetTopLeftInsideNative.y() - dy); - } else if (scrollBottomRightInsideNative.y() + dy > widgetBottomRightInsideNative.y()) { - // Scrolling outside bottom - validScrollRect.setBottom(widgetBottomRightInsideNative.y() - dy); - } - } - - if (dx != 0) { - if (scrollTopLeftInsideNative.x() + dx < widgetTopLeftInsideNative.x()) { - // Scrolling outside left edge - validScrollRect.setLeft(widgetTopLeftInsideNative.x() - dx); - } else if (scrollBottomRightInsideNative.x() + dx > widgetBottomRightInsideNative.x()) { - // Scrolling outside right edge - validScrollRect.setRight(widgetBottomRightInsideNative.x() - dx); - } - } } - // Now, scroll the pixels: + // Make the pixel copy rect within the validScrollRect bounds: NSRect nsscrollRect = NSMakeRect( - validScrollRect.x(), validScrollRect.y(), - validScrollRect.width(), validScrollRect.height()); + validScrollRect.x() + (dx < 0 ? -dx : 0), + validScrollRect.y() + (dy < 0 ? -dy : 0), + validScrollRect.width() + (dx > 0 ? -dx : 0), + validScrollRect.height() + (dy > 0 ? -dy : 0)); + NSSize deltaSize = NSMakeSize(dx, dy); [view scrollRect:nsscrollRect by:deltaSize]; -- cgit v0.12