summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorAndrew Knight <andrew.knight@digia.com>2014-06-25 09:39:58 +0300
committerAndrew Knight <andrew.knight@digia.com>2014-06-25 16:34:18 +0200
commit5e32bfa3e2ee226f8ef056a1d559ba508ea512b8 (patch)
tree5792b709aa5bd4f19def8666fd5a4520eb3652fe /src/plugins
parent6dd9146938bbf619af711d13a56100dbd7990390 (diff)
winrt: Clean up QWinRTCursor
- Remove WinRT types from the header - Remove WP8.0 code paths - Use convenience methods for HRESULT handling Task-number: QTBUG-38115 Change-Id: I05e77d75a7975a783d0f0714e6bab014231a406c Reviewed-by: Oliver Wolff <oliver.wolff@digia.com>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/platforms/winrt/qwinrtcursor.cpp60
-rw-r--r--src/plugins/platforms/winrt/qwinrtcursor.h24
-rw-r--r--src/plugins/platforms/winrt/qwinrtscreen.cpp2
3 files changed, 42 insertions, 44 deletions
diff --git a/src/plugins/platforms/winrt/qwinrtcursor.cpp b/src/plugins/platforms/winrt/qwinrtcursor.cpp
index f09454ebc3..d2d87bde0b 100644
--- a/src/plugins/platforms/winrt/qwinrtcursor.cpp
+++ b/src/plugins/platforms/winrt/qwinrtcursor.cpp
@@ -40,40 +40,54 @@
****************************************************************************/
#include "qwinrtcursor.h"
+#include "qwinrtscreen.h"
+
+#include <QtCore/qfunctions_winrt.h>
+#include <QtGui/QGuiApplication>
+#include <QtGui/QScreen>
#include <wrl.h>
#include <windows.ui.core.h>
#include <windows.foundation.h>
+using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;
using namespace ABI::Windows::UI::Core;
using namespace ABI::Windows::Foundation;
-QT_BEGIN_NAMESPACE
+QT_USE_NAMESPACE
+
+class QWinRTCursorPrivate
+{
+public:
+ ComPtr<ICoreCursorFactory> cursorFactory;
+};
-QWinRTCursor::QWinRTCursor(ICoreWindow *window) : m_window(window), m_cursorFactory(nullptr)
+QWinRTCursor::QWinRTCursor()
+ : d_ptr(new QWinRTCursorPrivate)
{
-#ifndef Q_OS_WINPHONE
- GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_UI_Core_CoreCursor).Get(), &m_cursorFactory);
-#endif
+ Q_D(QWinRTCursor);
+
+ HRESULT hr;
+ hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_UI_Core_CoreCursor).Get(),
+ IID_PPV_ARGS(&d->cursorFactory));
+ Q_ASSERT_SUCCEEDED(hr);
}
QWinRTCursor::~QWinRTCursor()
{
- if (m_cursorFactory)
- m_cursorFactory->Release();
}
#ifndef QT_NO_CURSOR
-void QWinRTCursor::changeCursor(QCursor *windowCursor, QWindow *)
+void QWinRTCursor::changeCursor(QCursor *windowCursor, QWindow *window)
{
-#ifndef Q_OS_WINPHONE
- if (!m_cursorFactory)
- return;
+ Q_D(QWinRTCursor);
+
+ ICoreWindow *coreWindow = static_cast<QWinRTScreen *>(window->screen()->handle())->coreWindow();
CoreCursorType type;
switch (windowCursor ? windowCursor->shape() : Qt::ArrowCursor) {
case Qt::BlankCursor:
- m_window->put_PointerCursor(nullptr);
+ coreWindow->put_PointerCursor(Q_NULLPTR);
return;
default:
case Qt::OpenHandCursor:
@@ -132,24 +146,20 @@ void QWinRTCursor::changeCursor(QCursor *windowCursor, QWindow *)
break;
}
- ICoreCursor *cursor;
- if (SUCCEEDED(m_cursorFactory->CreateCursor(type, 0, &cursor)))
- m_window->put_PointerCursor(cursor);
-#else // Q_OS_WINPHONE
- Q_UNUSED(windowCursor)
-#endif // Q_OS_WINPHONE
+ ComPtr<ICoreCursor> cursor;
+ HRESULT hr = d->cursorFactory->CreateCursor(type, 0, &cursor);
+ RETURN_VOID_IF_FAILED("Failed to create native cursor.");
+
+ hr = coreWindow->put_PointerCursor(cursor.Get());
+ RETURN_VOID_IF_FAILED("Failed to set native cursor.");
}
#endif // QT_NO_CURSOR
QPoint QWinRTCursor::pos() const
{
-#ifdef Q_OS_WINPHONE
- return QPlatformCursor::pos();
-#else
+ ICoreWindow *coreWindow =
+ static_cast<QWinRTScreen *>(QGuiApplication::primaryScreen()->handle())->coreWindow();
Point point;
- m_window->get_PointerPosition(&point);
+ coreWindow->get_PointerPosition(&point);
return QPoint(point.X, point.Y);
-#endif
}
-
-QT_END_NAMESPACE
diff --git a/src/plugins/platforms/winrt/qwinrtcursor.h b/src/plugins/platforms/winrt/qwinrtcursor.h
index f7b301a98b..a08002f34c 100644
--- a/src/plugins/platforms/winrt/qwinrtcursor.h
+++ b/src/plugins/platforms/winrt/qwinrtcursor.h
@@ -44,34 +44,22 @@
#include <qpa/qplatformcursor.h>
-namespace ABI {
- namespace Windows {
- namespace UI {
- namespace Core {
- struct ICoreWindow;
- struct ICoreCursorFactory;
- }
- }
- }
-}
-
-QT_BEGIN_NAMESPACE
+QT_USE_NAMESPACE
+class QWinRTCursorPrivate;
class QWinRTCursor : public QPlatformCursor
{
public:
- explicit QWinRTCursor(ABI::Windows::UI::Core::ICoreWindow *window);
+ explicit QWinRTCursor();
~QWinRTCursor();
#ifndef QT_NO_CURSOR
- void changeCursor(QCursor * windowCursor, QWindow *);
+ void changeCursor(QCursor * windowCursor, QWindow *window);
#endif
QPoint pos() const;
private:
- ABI::Windows::UI::Core::ICoreWindow *m_window;
- ABI::Windows::UI::Core::ICoreCursorFactory *m_cursorFactory;
+ QScopedPointer<QWinRTCursorPrivate> d_ptr;
+ Q_DECLARE_PRIVATE(QWinRTCursor)
};
-QT_END_NAMESPACE
-
#endif // QWINRTCURSOR_H
diff --git a/src/plugins/platforms/winrt/qwinrtscreen.cpp b/src/plugins/platforms/winrt/qwinrtscreen.cpp
index f948cf9924..3d966a1f18 100644
--- a/src/plugins/platforms/winrt/qwinrtscreen.cpp
+++ b/src/plugins/platforms/winrt/qwinrtscreen.cpp
@@ -428,7 +428,7 @@ QWinRTScreen::QWinRTScreen(ICoreWindow *window)
#else
, m_inputContext(Make<QWinRTInputContext>(m_coreWindow).Detach())
#endif
- , m_cursor(new QWinRTCursor(window))
+ , m_cursor(new QWinRTCursor)
, m_devicePixelRatio(1.0)
, m_orientation(Qt::PrimaryOrientation)
, m_touchDevice(Q_NULLPTR)