From 992ef929dff21e079f7d8a207c07dbfd0c3c8f78 Mon Sep 17 00:00:00 2001 From: Olli Werwolff Date: Tue, 12 Jul 2011 13:02:54 +0200 Subject: Use PlatformNativeInterface to obtain backingStore's dc Change-Id: I6ec2fc0b8e7696fdfe4468920228df2d21c933fd Reviewed-on: http://codereview.qt.nokia.com/1501 Reviewed-by: Friedemann Kleint --- src/gui/kernel/qplatformnativeinterface_qpa.cpp | 7 +++++++ src/gui/kernel/qplatformnativeinterface_qpa.h | 2 ++ src/gui/painting/qbackingstore.cpp | 5 +++++ src/gui/painting/qbackingstore.h | 3 +++ src/widgets/dialogs/qwizard_win.cpp | 10 +++++++--- src/widgets/styles/qwindowsxpstyle.cpp | 19 ++++++++++++------- src/widgets/styles/qwindowsxpstyle_p.h | 2 +- 7 files changed, 37 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/gui/kernel/qplatformnativeinterface_qpa.cpp b/src/gui/kernel/qplatformnativeinterface_qpa.cpp index 82d6a97a47..18bef8a595 100644 --- a/src/gui/kernel/qplatformnativeinterface_qpa.cpp +++ b/src/gui/kernel/qplatformnativeinterface_qpa.cpp @@ -57,4 +57,11 @@ void *QPlatformNativeInterface::nativeResourceForContext(const QByteArray &resou return 0; } +void * QPlatformNativeInterface::nativeResourceForBackingStore(const QByteArray &resource, QBackingStore *backingStore) +{ + Q_UNUSED(resource); + Q_UNUSED(backingStore); + return 0; +} + QT_END_NAMESPACE diff --git a/src/gui/kernel/qplatformnativeinterface_qpa.h b/src/gui/kernel/qplatformnativeinterface_qpa.h index edc1a9d96e..136191e2aa 100644 --- a/src/gui/kernel/qplatformnativeinterface_qpa.h +++ b/src/gui/kernel/qplatformnativeinterface_qpa.h @@ -52,12 +52,14 @@ QT_MODULE(Gui) class QGuiGLContext; class QWindow; +class QBackingStore; class Q_GUI_EXPORT QPlatformNativeInterface { public: virtual void *nativeResourceForContext(const QByteArray &resource, QGuiGLContext *context); virtual void *nativeResourceForWindow(const QByteArray &resource, QWindow *window); + virtual void *nativeResourceForBackingStore(const QByteArray &resource, QBackingStore *backingStore); }; QT_END_NAMESPACE diff --git a/src/gui/painting/qbackingstore.cpp b/src/gui/painting/qbackingstore.cpp index 776e33a1a8..68dbb7d109 100644 --- a/src/gui/painting/qbackingstore.cpp +++ b/src/gui/painting/qbackingstore.cpp @@ -247,4 +247,9 @@ void Q_GUI_EXPORT qt_scrollRectInImage(QImage &img, const QRect &rect, const QPo } } +QPlatformBackingStore *QBackingStore::handle() const +{ + return d_ptr->platformBackingStore; +} + QT_END_NAMESPACE diff --git a/src/gui/painting/qbackingstore.h b/src/gui/painting/qbackingstore.h index 3ab0264b17..9f646f89ac 100644 --- a/src/gui/painting/qbackingstore.h +++ b/src/gui/painting/qbackingstore.h @@ -54,6 +54,7 @@ class QRect; class QPoint; class QImage; class QBackingStorePrivate; +class QPlatformBackingStore; class Q_GUI_EXPORT QBackingStore { @@ -81,6 +82,8 @@ public: QRegion staticContents() const; bool hasStaticContents() const; + QPlatformBackingStore *handle() const; + private: QScopedPointer d_ptr; }; diff --git a/src/widgets/dialogs/qwizard_win.cpp b/src/widgets/dialogs/qwizard_win.cpp index ab59e0109a..6c2a67639b 100644 --- a/src/widgets/dialogs/qwizard_win.cpp +++ b/src/widgets/dialogs/qwizard_win.cpp @@ -232,7 +232,9 @@ void QVistaBackButton::paintEvent(QPaintEvent *) else if (underMouse()) state = WIZ_NAV_BB_HOT; - pDrawThemeBackground(theme, p.paintEngine()->getDC(), WIZ_NAV_BACKBUTTON, state, &clipRect, &clipRect); + QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface(); + HDC hdc = static_cast(nativeInterface->nativeResourceForBackingStore("getDC", backingStore())); + pDrawThemeBackground(theme, hdc, WIZ_NAV_BACKBUTTON, state, &clipRect, &clipRect); } /****************************************************************************** @@ -318,12 +320,14 @@ bool QVistaHelper::setDWMTitleBar(TitleBarChangeType type) void QVistaHelper::drawTitleBar(QPainter *painter) { - HDC hdc = static_cast(painter->paintEngine())->getDC(); + Q_ASSERT(backButton_); + QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface(); + QBackingStore *backingStore = backButton_->backingStore(); + HDC hdc = static_cast(nativeInterface->nativeResourceForBackingStore("getDC", backingStore)); if (vistaState() == VistaAero) drawBlackRect(QRect(0, 0, wizard->width(), titleBarSize() + topOffset()), hdc); - Q_ASSERT(backButton_); const int btnTop = backButton_->mapToParent(QPoint()).y(); const int btnHeight = backButton_->size().height(); const int verticalCenter = (btnTop + btnHeight / 2) - 1; diff --git a/src/widgets/styles/qwindowsxpstyle.cpp b/src/widgets/styles/qwindowsxpstyle.cpp index 36e0852462..ce5694c181 100644 --- a/src/widgets/styles/qwindowsxpstyle.cpp +++ b/src/widgets/styles/qwindowsxpstyle.cpp @@ -190,17 +190,17 @@ RECT XPThemeData::toRECT(const QRect &qr) Returns the native region of a part, if the part is considered transparent. The region is scaled to the parts size (rect). */ -HRGN XPThemeData::mask() +HRGN XPThemeData::mask(QWidget *widget) { if (!pIsThemeBackgroundPartiallyTransparent(handle(), partId, stateId)) return 0; HRGN hrgn; - HDC dc = painter == 0 ? 0 : painter->paintEngine()->getDC(); + QBackingStore *backingStore = widget->backingStore(); + QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface(); + HDC dc = static_cast(nativeInterface->nativeResourceForBackingStore("getDC", backingStore)); RECT nativeRect = toRECT(rect); pGetThemeBackgroundRegion(handle(), dc, partId, stateId, &nativeRect, &hrgn); - if (dc) - painter->paintEngine()->releaseDC(dc); return hrgn; } @@ -505,7 +505,7 @@ QRegion QWindowsXPStylePrivate::region(XPThemeData &themeData) */ void QWindowsXPStylePrivate::setTransparency(QWidget *widget, XPThemeData &themeData) { - HRGN hrgn = themeData.mask(); + HRGN hrgn = themeData.mask(widget); if (hrgn && widget) SetWindowRgn(winId(widget), hrgn, true); } @@ -657,7 +657,10 @@ void QWindowsXPStylePrivate::drawBackground(XPThemeData &themeData) translucentToplevel = win->testAttribute(Qt::WA_TranslucentBackground); } - bool useFallback = painter->paintEngine()->getDC() == 0 + QBackingStore *backingStore = themeData.widget->backingStore(); + QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface(); + HDC dc = static_cast(nativeInterface->nativeResourceForBackingStore("getDC", backingStore )); + bool useFallback = dc == 0 || painter->opacity() != 1.0 || themeData.rotate || complexXForm @@ -681,7 +684,9 @@ void QWindowsXPStylePrivate::drawBackground(XPThemeData &themeData) void QWindowsXPStylePrivate::drawBackgroundDirectly(XPThemeData &themeData) { QPainter *painter = themeData.painter; - HDC dc = painter->paintEngine()->getDC(); + QBackingStore *backingStore= themeData.widget->backingStore(); + QPlatformNativeInterface *nativeInterface = QGuiApplication::platformNativeInterface(); + HDC dc = static_cast(nativeInterface->nativeResourceForBackingStore("getDC", backingStore)); QPoint redirectionDelta(int(painter->deviceMatrix().dx()), int(painter->deviceMatrix().dy())); diff --git a/src/widgets/styles/qwindowsxpstyle_p.h b/src/widgets/styles/qwindowsxpstyle_p.h index 73803607a1..05ab2ec2e4 100644 --- a/src/widgets/styles/qwindowsxpstyle_p.h +++ b/src/widgets/styles/qwindowsxpstyle_p.h @@ -216,7 +216,7 @@ public: noContent(false), rotate(0), rect(r) {} - HRGN mask(); + HRGN mask(QWidget *widget); HTHEME handle(); RECT toRECT(const QRect &qr); -- cgit v1.2.3