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>
This commit is contained in:
parent
6dd9146938
commit
5e32bfa3e2
@ -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
|
||||
|
||||
QWinRTCursor::QWinRTCursor(ICoreWindow *window) : m_window(window), m_cursorFactory(nullptr)
|
||||
class QWinRTCursorPrivate
|
||||
{
|
||||
#ifndef Q_OS_WINPHONE
|
||||
GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_UI_Core_CoreCursor).Get(), &m_cursorFactory);
|
||||
#endif
|
||||
public:
|
||||
ComPtr<ICoreCursorFactory> cursorFactory;
|
||||
};
|
||||
|
||||
QWinRTCursor::QWinRTCursor()
|
||||
: d_ptr(new QWinRTCursorPrivate)
|
||||
{
|
||||
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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user