diff options
Diffstat (limited to 'src/plugins')
89 files changed, 13 insertions, 13844 deletions
diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt index 8d6516b0b5..9a6a8f1e39 100644 --- a/src/plugins/CMakeLists.txt +++ b/src/plugins/CMakeLists.txt @@ -17,6 +17,6 @@ endif() if(TARGET Qt::Widgets) add_subdirectory(styles) endif() -if(TARGET Qt::PrintSupport AND NOT WINRT) +if(TARGET Qt::PrintSupport) add_subdirectory(printsupport) endif() diff --git a/src/plugins/imageformats/jpeg/.prev_CMakeLists.txt b/src/plugins/imageformats/jpeg/.prev_CMakeLists.txt index bf9b12e703..b7e0c7cab7 100644 --- a/src/plugins/imageformats/jpeg/.prev_CMakeLists.txt +++ b/src/plugins/imageformats/jpeg/.prev_CMakeLists.txt @@ -85,10 +85,5 @@ qt_extend_target(QJpegPlugin CONDITION NOT QT_FEATURE_system_jpeg ../../../3rdparty/libjpeg/src ) -qt_extend_target(QJpegPlugin CONDITION WINRT AND NOT QT_FEATURE_system_jpeg - DEFINES - NO_GETENV -) - -#### Keys ignored in scope 6:.:../../../3rdparty:../../../3rdparty/libjpeg.pri:GCC: +#### Keys ignored in scope 5:.:../../../3rdparty:../../../3rdparty/libjpeg.pri:GCC: # QMAKE_CFLAGS_WARN_ON = "-Wno-unused-parameter" "-Wno-main" diff --git a/src/plugins/imageformats/jpeg/CMakeLists.txt b/src/plugins/imageformats/jpeg/CMakeLists.txt index 2542a86eed..2c45da7bbd 100644 --- a/src/plugins/imageformats/jpeg/CMakeLists.txt +++ b/src/plugins/imageformats/jpeg/CMakeLists.txt @@ -87,10 +87,5 @@ qt_extend_target(QJpegPlugin CONDITION NOT QT_FEATURE_system_jpeg ../../../3rdparty/libjpeg/src ) -qt_extend_target(QJpegPlugin CONDITION WINRT AND NOT QT_FEATURE_system_jpeg - DEFINES - NO_GETENV -) - -#### Keys ignored in scope 6:.:../../../3rdparty:../../../3rdparty/libjpeg.pri:GCC: +#### Keys ignored in scope 5:.:../../../3rdparty:../../../3rdparty/libjpeg.pri:GCC: # QMAKE_CFLAGS_WARN_ON = "-Wno-unused-parameter" "-Wno-main" diff --git a/src/plugins/platforms/.prev_CMakeLists.txt b/src/plugins/platforms/.prev_CMakeLists.txt index 947efaaf63..baded9525c 100644 --- a/src/plugins/platforms/.prev_CMakeLists.txt +++ b/src/plugins/platforms/.prev_CMakeLists.txt @@ -18,12 +18,9 @@ endif() if(MACOS) add_subdirectory(cocoa) endif() -if(WIN32 AND NOT WINRT) +if(WIN32) add_subdirectory(windows) endif() -if(WINRT) - add_subdirectory(winrt) -endif() if(QT_FEATURE_direct2d1_1 AND QT_FEATURE_directwrite1) add_subdirectory(direct2d) endif() diff --git a/src/plugins/platforms/CMakeLists.txt b/src/plugins/platforms/CMakeLists.txt index 83f3e2975b..a509cdfdc4 100644 --- a/src/plugins/platforms/CMakeLists.txt +++ b/src/plugins/platforms/CMakeLists.txt @@ -18,12 +18,9 @@ endif() if(MACOS) add_subdirectory(cocoa) endif() -if(WIN32 AND NOT WINRT) +if(WIN32) add_subdirectory(windows) endif() -if(WINRT) - # add_subdirectory(winrt) # special case TODO -endif() if(QT_FEATURE_direct2d1_1 AND QT_FEATURE_directwrite1) # add_subdirectory(direct2d) # special case TODO endif() diff --git a/src/plugins/platforms/minimal/qminimalintegration.cpp b/src/plugins/platforms/minimal/qminimalintegration.cpp index bfdcda1a84..a11012a81a 100644 --- a/src/plugins/platforms/minimal/qminimalintegration.cpp +++ b/src/plugins/platforms/minimal/qminimalintegration.cpp @@ -46,9 +46,7 @@ #include <qpa/qwindowsysteminterface.h> #include <QtGui/private/qfreetypefontdatabase_p.h> -#if defined(Q_OS_WINRT) -# include <QtFontDatabaseSupport/private/qwinrtfontdatabase_p.h> -#elif defined(Q_OS_WIN) +#if defined(Q_OS_WIN) # include <QtFontDatabaseSupport/private/qwindowsfontdatabase_p.h> # if QT_CONFIG(freetype) # include <QtFontDatabaseSupport/private/qwindowsfontdatabase_ft_p.h> @@ -68,8 +66,6 @@ #if !defined(Q_OS_WIN) #include <QtEventDispatcherSupport/private/qgenericunixeventdispatcher_p.h> -#elif defined(Q_OS_WINRT) -#include <QtCore/private/qeventdispatcher_winrt_p.h> #else #include <QtCore/private/qeventdispatcher_win_p.h> #endif @@ -139,9 +135,7 @@ public: QPlatformFontDatabase *QMinimalIntegration::fontDatabase() const { if (!m_fontDatabase && (m_options & EnableFonts)) { -#if defined(Q_OS_WINRT) - m_fontDatabase = new QWinRTFontDatabase; -#elif defined(Q_OS_WIN) +#if defined(Q_OS_WIN) if (m_options & FreeTypeFontDatabase) { # if QT_CONFIG(freetype) m_fontDatabase = new QWindowsFontDatabaseFT; @@ -190,11 +184,7 @@ QPlatformBackingStore *QMinimalIntegration::createPlatformBackingStore(QWindow * QAbstractEventDispatcher *QMinimalIntegration::createEventDispatcher() const { #ifdef Q_OS_WIN -#ifndef Q_OS_WINRT return new QEventDispatcherWin32; -#else // !Q_OS_WINRT - return new QEventDispatcherWinRT; -#endif // Q_OS_WINRT #else return createUnixEventDispatcher(); #endif diff --git a/src/plugins/platforms/minimalegl/qminimaleglintegration.cpp b/src/plugins/platforms/minimalegl/qminimaleglintegration.cpp index a0d35a80cd..10321cec83 100644 --- a/src/plugins/platforms/minimalegl/qminimaleglintegration.cpp +++ b/src/plugins/platforms/minimalegl/qminimaleglintegration.cpp @@ -47,9 +47,6 @@ #if defined(Q_OS_UNIX) # include <QtEventDispatcherSupport/private/qgenericunixeventdispatcher_p.h> -#elif defined(Q_OS_WINRT) -# include <QtCore/private/qeventdispatcher_winrt_p.h> -# include <QtGui/qpa/qwindowsysteminterface.h> #elif defined(Q_OS_WIN) # include <QtEventDispatcherSupport/private/qwindowsguieventdispatcher_p.h> #endif @@ -65,29 +62,6 @@ QT_BEGIN_NAMESPACE -#ifdef Q_OS_WINRT -namespace { -class QWinRTEventDispatcher : public QEventDispatcherWinRT { -public: - QWinRTEventDispatcher() {} - -protected: - bool hasPendingEvents() override - { - return QEventDispatcherWinRT::hasPendingEvents() || QWindowSystemInterface::windowSystemEventsQueued(); - } - - bool sendPostedEvents(QEventLoop::ProcessEventsFlags flags) - { - bool didProcess = QEventDispatcherWinRT::sendPostedEvents(flags); - if (!(flags & QEventLoop::ExcludeUserInputEvents)) - didProcess |= QWindowSystemInterface::sendWindowSystemEvents(flags); - return didProcess; - } -}; -} // anonymous namespace -#endif // Q_OS_WINRT - QMinimalEglIntegration::QMinimalEglIntegration() : mFontDb(new QGenericUnixFontDatabase()), mScreen(new QMinimalEglScreen(EGL_DEFAULT_DISPLAY)) { @@ -153,8 +127,6 @@ QAbstractEventDispatcher *QMinimalEglIntegration::createEventDispatcher() const { #if defined(Q_OS_UNIX) return createUnixEventDispatcher(); -#elif defined(Q_OS_WINRT) - return new QWinRTEventDispatcher; #elif defined(Q_OS_WIN) return new QWindowsGuiEventDispatcher; #else diff --git a/src/plugins/platforms/offscreen/qoffscreenintegration.cpp b/src/plugins/platforms/offscreen/qoffscreenintegration.cpp index 1d9a6ee2f7..849faeccb1 100644 --- a/src/plugins/platforms/offscreen/qoffscreenintegration.cpp +++ b/src/plugins/platforms/offscreen/qoffscreenintegration.cpp @@ -51,11 +51,7 @@ #endif #elif defined(Q_OS_WIN) #include <QtGui/private/qfreetypefontdatabase_p.h> -#ifndef Q_OS_WINRT #include <QtCore/private/qeventdispatcher_win_p.h> -#else -#include <QtCore/private/qeventdispatcher_winrt_p.h> -#endif #endif #include <QtGui/private/qpixmap_raster_p.h> @@ -166,11 +162,7 @@ QAbstractEventDispatcher *QOffscreenIntegration::createEventDispatcher() const #if defined(Q_OS_UNIX) return createUnixEventDispatcher(); #elif defined(Q_OS_WIN) -#ifndef Q_OS_WINRT return new QOffscreenEventDispatcher<QEventDispatcherWin32>(); -#else // !Q_OS_WINRT - return new QOffscreenEventDispatcher<QEventDispatcherWinRT>(); -#endif // Q_OS_WINRT #else return 0; #endif diff --git a/src/plugins/platforms/platforms.pro b/src/plugins/platforms/platforms.pro index 39665fa8ca..ab7ee395d7 100644 --- a/src/plugins/platforms/platforms.pro +++ b/src/plugins/platforms/platforms.pro @@ -14,8 +14,7 @@ qtConfig(xcb) { uikit:!watchos: SUBDIRS += ios osx: SUBDIRS += cocoa -win32:!winrt: SUBDIRS += windows -winrt: SUBDIRS += winrt +win32: SUBDIRS += windows qtConfig(direct2d1_1):qtConfig(directwrite1) { SUBDIRS += direct2d diff --git a/src/plugins/platforms/winrt/main.cpp b/src/plugins/platforms/winrt/main.cpp deleted file mode 100644 index a37bd1e3d8..0000000000 --- a/src/plugins/platforms/winrt/main.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwinrtintegration.h" - -#include <qpa/qplatformintegrationplugin.h> - -QT_BEGIN_NAMESPACE - -class QWinRTIntegrationPlugin : public QPlatformIntegrationPlugin -{ - Q_OBJECT - Q_PLUGIN_METADATA(IID QPlatformIntegrationFactoryInterface_iid FILE "winrt.json") - -public: - QPlatformIntegration *create(const QString&, const QStringList&) override; -}; - -QPlatformIntegration *QWinRTIntegrationPlugin::create(const QString& system, const QStringList& paramList) -{ - Q_UNUSED(paramList); - if (!system.compare(QLatin1String("winrt"), Qt::CaseInsensitive)) - return QWinRTIntegration::create(); - - return nullptr; -} - -QT_END_NAMESPACE - -#include "main.moc" diff --git a/src/plugins/platforms/winrt/qwinrtbackingstore.cpp b/src/plugins/platforms/winrt/qwinrtbackingstore.cpp deleted file mode 100644 index fbf611d7f7..0000000000 --- a/src/plugins/platforms/winrt/qwinrtbackingstore.cpp +++ /dev/null @@ -1,194 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwinrtbackingstore.h" - -#include "qwinrtscreen.h" -#include "qwinrtwindow.h" -#include "qwinrteglcontext.h" -#include <QtGui/QOpenGLContext> -#include <QtGui/QOpenGLFramebufferObject> - -#include <GLES3/gl3.h> - -QT_BEGIN_NAMESPACE - -class QWinRTBackingStorePrivate -{ -public: - bool initialized; - QSize size; - QScopedPointer<QOpenGLContext> context; - QScopedPointer<QOpenGLFramebufferObject> fbo; - QWinRTScreen *screen; - QImage paintDevice; -}; - -QWinRTBackingStore::QWinRTBackingStore(QWindow *window) - : QPlatformBackingStore(window), d_ptr(new QWinRTBackingStorePrivate) -{ - Q_D(QWinRTBackingStore); - qCInfo(lcQpaBackingStore) << __FUNCTION__ << this << window; - - d->initialized = false; - d->screen = static_cast<QWinRTScreen*>(window->screen()->handle()); - - if (window->surfaceType() == QSurface::RasterSurface) - window->setSurfaceType(QSurface::OpenGLSurface); -} - -bool QWinRTBackingStore::initialize() -{ - Q_D(QWinRTBackingStore); - qCDebug(lcQpaBackingStore) << __FUNCTION__ << d->initialized; - - if (d->initialized) - return true; - - d->context.reset(new QOpenGLContext); - QSurfaceFormat format = window()->format(); - d->context->setFormat(format); - d->context->setScreen(window()->screen()); - if (!d->context->create()) - return false; - - if (!d->context->makeCurrent(window())) - return false; - - d->context->doneCurrent(); - d->initialized = true; - return true; -} - -QWinRTBackingStore::~QWinRTBackingStore() -{ - qCInfo(lcQpaBackingStore) << __FUNCTION__ << this; -} - -QPaintDevice *QWinRTBackingStore::paintDevice() -{ - Q_D(QWinRTBackingStore); - return &d->paintDevice; -} - -void QWinRTBackingStore::flush(QWindow *window, const QRegion ®ion, const QPoint &offset) -{ - Q_D(QWinRTBackingStore); - Q_UNUSED(offset) - - qCDebug(lcQpaBackingStore) << __FUNCTION__ << this << window << region; - - if (d->size.isEmpty()) - return; - - const QRect bounds = region.boundingRect() & d->paintDevice.rect(); - if (bounds.isEmpty()) - return; - - const bool ok = d->context->makeCurrent(window); - if (!ok) - qWarning("unable to flush"); - - glBindTexture(GL_TEXTURE_2D, d->fbo->texture()); - // TODO: when ANGLE GLES3 support is finished, use the glPixelStorei functions to minimize upload - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, bounds.y(), d->size.width(), bounds.height(), - GL_RGBA, GL_UNSIGNED_BYTE, d->paintDevice.constScanLine(bounds.y())); - glBindTexture(GL_TEXTURE_2D, 0); - - glBindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, d->fbo->handle()); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, 0); - const int y1 = bounds.y(); - const int y2 = y1 + bounds.height(); - const int x1 = bounds.x(); - const int x2 = x1 + bounds.width(); - glBlitFramebuffer(x1, y1, x2, y2, - x1, d->size.height() - y1, x2, d->size.height() - y2, - GL_COLOR_BUFFER_BIT, GL_NEAREST); - - d->context->swapBuffers(window); - d->context->doneCurrent(); -} - -void QWinRTBackingStore::resize(const QSize &size, const QRegion &staticContents) -{ - Q_D(QWinRTBackingStore); - Q_UNUSED(staticContents) - - qCDebug(lcQpaBackingStore) << __FUNCTION__ << this << size; - - if (!initialize()) - return; - - if (d->size == size) - return; - - d->size = size; - if (d->size.isEmpty()) - return; - - d->paintDevice = QImage(d->size, QImage::Format_RGBA8888_Premultiplied); - - const bool ok = d->context->makeCurrent(window()); - if (!ok) - qWarning("unable to resize"); - - d->fbo.reset(new QOpenGLFramebufferObject(d->size)); - - d->context->doneCurrent(); -} - -QImage QWinRTBackingStore::toImage() const -{ - Q_D(const QWinRTBackingStore); - return d->paintDevice; -} - -void QWinRTBackingStore::beginPaint(const QRegion ®ion) -{ - qCDebug(lcQpaBackingStore) << __FUNCTION__ << this << region; - - resize(window()->size(), region); -} - -void QWinRTBackingStore::endPaint() -{ - qCDebug(lcQpaBackingStore) << __FUNCTION__ << this; -} - -QT_END_NAMESPACE diff --git a/src/plugins/platforms/winrt/qwinrtbackingstore.h b/src/plugins/platforms/winrt/qwinrtbackingstore.h deleted file mode 100644 index b62d340b82..0000000000 --- a/src/plugins/platforms/winrt/qwinrtbackingstore.h +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTBACKINGSTORE_H -#define QWINRTBACKINGSTORE_H - -#define GL_GLEXT_PROTOTYPES -#include <qpa/qplatformbackingstore.h> -#include <QtCore/QScopedPointer> -#include <QtCore/QLoggingCategory> - -QT_BEGIN_NAMESPACE - -class QWinRTScreen; - -class QWinRTBackingStorePrivate; -class QWinRTBackingStore : public QPlatformBackingStore -{ -public: - explicit QWinRTBackingStore(QWindow *window); - ~QWinRTBackingStore() override; - QPaintDevice *paintDevice() override; - void beginPaint(const QRegion &) override; - void endPaint() override; - void flush(QWindow *window, const QRegion ®ion, const QPoint &offset) override; - void resize(const QSize &size, const QRegion &staticContents) override; - QImage toImage() const override; - -private: - bool initialize(); - - QScopedPointer<QWinRTBackingStorePrivate> d_ptr; - Q_DECLARE_PRIVATE(QWinRTBackingStore) -}; - -QT_END_NAMESPACE - -#endif // QWINRTBACKINGSTORE_H diff --git a/src/plugins/platforms/winrt/qwinrtcanvas.cpp b/src/plugins/platforms/winrt/qwinrtcanvas.cpp deleted file mode 100644 index dd6b52d9cd..0000000000 --- a/src/plugins/platforms/winrt/qwinrtcanvas.cpp +++ /dev/null @@ -1,142 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwinrtcanvas.h" -#include "uiautomation/qwinrtuiaaccessibility.h" -#include "uiautomation/qwinrtuiamainprovider.h" -#include "uiautomation/qwinrtuiametadatacache.h" -#include "uiautomation/qwinrtuiautils.h" - -#include <QtCore/QLoggingCategory> -#include <QtCore/qfunctions_winrt.h> - -using namespace Microsoft::WRL; -using namespace Microsoft::WRL::Wrappers; -using namespace ABI::Windows::Foundation; -using namespace ABI::Windows::System; -using namespace ABI::Windows::UI; -using namespace ABI::Windows::UI::Core; -using namespace ABI::Windows::UI::Xaml; -using namespace ABI::Windows::Foundation; -using namespace ABI::Windows::Foundation::Collections; - -QT_BEGIN_NAMESPACE - -QWinRTCanvas::QWinRTCanvas(const std::function<QWindow*()> &delegateWindow) -{ - ComPtr<Xaml::Controls::ICanvasFactory> factory; - HRESULT hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_UI_Xaml_Controls_Canvas).Get(), IID_PPV_ARGS(&factory)); - Q_ASSERT_SUCCEEDED(hr); - - hr = factory->CreateInstance(this, &m_base, &m_core); - Q_ASSERT_SUCCEEDED(hr); - - delegate = delegateWindow; -} - -HRESULT STDMETHODCALLTYPE QWinRTCanvas::QueryInterface(REFIID iid, LPVOID *iface) -{ - if (!iface) - return E_POINTER; - *iface = nullptr; - - if (iid == IID_IUnknown) { - *iface = static_cast<Xaml::IUIElementOverrides *>(this); - AddRef(); - return S_OK; - } else if (iid == Xaml::IID_IUIElementOverrides) { - *iface = static_cast<Xaml::IUIElementOverrides *>(this); - AddRef(); - return S_OK; - } else { - return m_base.CopyTo(iid, iface); - } -} - -HRESULT STDMETHODCALLTYPE QWinRTCanvas::GetIids(ULONG *iidCount, IID **iids) -{ - *iidCount = 0; - *iids = nullptr; - return S_OK; -} - -HRESULT STDMETHODCALLTYPE QWinRTCanvas::GetRuntimeClassName(HSTRING *className) -{ - const wchar_t *name = L"QWinRTCanvas"; - return ::WindowsCreateString(name, static_cast<UINT32>(::wcslen(name)), className); -} - -HRESULT STDMETHODCALLTYPE QWinRTCanvas::GetTrustLevel(TrustLevel *trustLevel) -{ - *trustLevel = TrustLevel::BaseTrust; - return S_OK; -} - -HRESULT STDMETHODCALLTYPE QWinRTCanvas::OnCreateAutomationPeer(Xaml::Automation::Peers::IAutomationPeer **returnValue) -{ - if (!returnValue) - return E_INVALIDARG; - *returnValue = nullptr; - - if (delegate) { - if (QWindow *window = delegate()) { - QWinRTUiaAccessibility::activate(); - if (QAccessibleInterface *accessible = window->accessibleRoot()) { - QAccessible::Id accid = QWinRTUiAutomation::idForAccessible(accessible); - QWinRTUiaMetadataCache::instance()->load(accid); - if (ComPtr<QWinRTUiaMainProvider> provider = QWinRTUiaMainProvider::providerForAccessibleId(accid)) - return provider.CopyTo(returnValue); - } - } - } - return m_base->OnCreateAutomationPeer(returnValue); -} - -HRESULT STDMETHODCALLTYPE QWinRTCanvas::OnDisconnectVisualChildren() -{ - return m_base->OnDisconnectVisualChildren(); -} - -HRESULT STDMETHODCALLTYPE QWinRTCanvas::FindSubElementsForTouchTargeting(Point point, Rect boundingRect, IIterable<IIterable<ABI::Windows::Foundation::Point>*> **returnValue) -{ - return m_base->FindSubElementsForTouchTargeting(point, boundingRect, returnValue); -} - -QT_END_NAMESPACE - diff --git a/src/plugins/platforms/winrt/qwinrtcanvas.h b/src/plugins/platforms/winrt/qwinrtcanvas.h deleted file mode 100644 index bc3b708ac2..0000000000 --- a/src/plugins/platforms/winrt/qwinrtcanvas.h +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTCANVAS_H -#define QWINRTCANVAS_H - -#include <QtCore/qglobal.h> -#include <QtGui/QWindow> - -#include <wrl.h> -#include <windows.ui.xaml.h> -#include <functional> - -QT_BEGIN_NAMESPACE - -class QWinRTCanvas: - public Microsoft::WRL::RuntimeClass<ABI::Windows::UI::Xaml::IUIElementOverrides> -{ -public: - QWinRTCanvas(const std::function<QWindow*()> &delegateWindow); - ~QWinRTCanvas() override = default; - - HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, LPVOID *iface) override; - HRESULT STDMETHODCALLTYPE GetIids(ULONG *iidCount, IID **iids) override; - HRESULT STDMETHODCALLTYPE GetRuntimeClassName(HSTRING *className) override; - HRESULT STDMETHODCALLTYPE GetTrustLevel(TrustLevel *trustLevel) override; - HRESULT STDMETHODCALLTYPE OnCreateAutomationPeer(ABI::Windows::UI::Xaml::Automation::Peers::IAutomationPeer **returnValue) override; - HRESULT STDMETHODCALLTYPE OnDisconnectVisualChildren() override; - HRESULT STDMETHODCALLTYPE FindSubElementsForTouchTargeting(ABI::Windows::Foundation::Point point, ABI::Windows::Foundation::Rect boundingRect, ABI::Windows::Foundation::Collections::IIterable<ABI::Windows::Foundation::Collections::IIterable<ABI::Windows::Foundation::Point>*> **returnValue) override; - -private: - Microsoft::WRL::ComPtr<ABI::Windows::UI::Xaml::IUIElementOverrides> m_base; - Microsoft::WRL::ComPtr<ABI::Windows::UI::Xaml::Controls::ICanvas> m_core; - std::function<QWindow*()> delegate; -}; - -QT_END_NAMESPACE - -#endif // QWINRTCANVAS_H diff --git a/src/plugins/platforms/winrt/qwinrtclipboard.cpp b/src/plugins/platforms/winrt/qwinrtclipboard.cpp deleted file mode 100644 index fd0ed8aed2..0000000000 --- a/src/plugins/platforms/winrt/qwinrtclipboard.cpp +++ /dev/null @@ -1,188 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwinrtclipboard.h" - -#include <QtCore/QCoreApplication> -#include <QtCore/qfunctions_winrt.h> -#include <QtCore/private/qeventdispatcher_winrt_p.h> - -#include <Windows.ApplicationModel.datatransfer.h> - -#include <functional> - -using namespace ABI::Windows::ApplicationModel::DataTransfer; -using namespace ABI::Windows::Foundation; -using namespace Microsoft::WRL; -using namespace Microsoft::WRL::Wrappers; - -typedef IEventHandler<IInspectable *> ContentChangedHandler; - -#define RETURN_NULLPTR_IF_FAILED(msg) RETURN_IF_FAILED(msg, return nullptr) - -QT_BEGIN_NAMESPACE - -QWinRTClipboard::QWinRTClipboard() - : m_mimeData(nullptr) -{ - QEventDispatcherWinRT::runOnXamlThread([this]() { - HRESULT hr; - hr = GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_ApplicationModel_DataTransfer_Clipboard).Get(), - &m_nativeClipBoard); - Q_ASSERT_SUCCEEDED(hr); - - EventRegistrationToken tok; - hr = m_nativeClipBoard->add_ContentChanged(Callback<ContentChangedHandler>(this, &QWinRTClipboard::onContentChanged).Get(), &tok); - Q_ASSERT_SUCCEEDED(hr); - - return hr; - }); -} - -QMimeData *QWinRTClipboard::mimeData(QClipboard::Mode mode) -{ - if (!supportsMode(mode)) - return nullptr; - - ComPtr<IDataPackageView> view; - HRESULT hr; - hr = m_nativeClipBoard->GetContent(&view); - RETURN_NULLPTR_IF_FAILED("Could not get clipboard content."); - - ComPtr<IAsyncOperation<HSTRING>> op; - HString result; - // This throws a security exception (WinRT originate error / 0x40080201. - // Unfortunately there seems to be no way to avoid this, neither - // running on the XAML thread, nor some other way. Stack Overflow - // confirms this problem since Windows (Phone) 8.0. - hr = view->GetTextAsync(&op); - RETURN_NULLPTR_IF_FAILED("Could not get clipboard text."); - - hr = QWinRTFunctions::await(op, result.GetAddressOf()); - RETURN_NULLPTR_IF_FAILED("Could not get clipboard text content"); - - quint32 size; - const wchar_t *textStr = result.GetRawBuffer(&size); - QString text = QString::fromWCharArray(textStr, int(size)); - text.replace(QLatin1String("\r\n"), QLatin1String("\n")); - - if (m_mimeData) { - if (m_mimeData->text() == text) - return m_mimeData; - delete m_mimeData; - } - m_mimeData = new QMimeData(); - m_mimeData->setText(text); - - return m_mimeData; -} - -// Inspired by QWindowsMimeText::convertFromMime -inline QString convertToWindowsLineEnding(const QString &text) -{ - const QChar *u = text.unicode(); - QString res; - const int s = text.length(); - int maxsize = s + s / 40 + 3; - res.resize(maxsize); - int ri = 0; - bool cr = false; - for (int i = 0; i < s; ++i) { - if (*u == QLatin1Char('\r')) - cr = true; - else { - if (*u == QLatin1Char('\n') && !cr) - res[ri++] = QLatin1Char('\r'); - cr = false; - } - res[ri++] = *u; - if (ri+3 >= maxsize) { - maxsize += maxsize / 4; - res.resize(maxsize); - } - ++u; - } - res.truncate(ri); - return res; -} - -void QWinRTClipboard::setMimeData(QMimeData *data, QClipboard::Mode mode) -{ - if (!supportsMode(mode)) - return; - - const bool newData = !m_mimeData || m_mimeData != data; - if (newData) { - if (m_mimeData) - delete m_mimeData; - m_mimeData = data; - } - const QString text = data ? data->text() : QString(); - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([this, text]() { - HRESULT hr; - ComPtr<IDataPackage> package; - hr = RoActivateInstance(HString::MakeReference(RuntimeClass_Windows_ApplicationModel_DataTransfer_DataPackage).Get(), - &package); - - const QString nativeString = convertToWindowsLineEnding(text); - HStringReference textRef(reinterpret_cast<LPCWSTR>(nativeString.utf16()), - uint(nativeString.length())); - - hr = package->SetText(textRef.Get()); - RETURN_HR_IF_FAILED("Could not set text to clipboard data package."); - - hr = m_nativeClipBoard->SetContent(package.Get()); - RETURN_HR_IF_FAILED("Could not set clipboard content."); - return S_OK; - }); - RETURN_VOID_IF_FAILED("Could not set clipboard text."); -} - -bool QWinRTClipboard::supportsMode(QClipboard::Mode mode) const -{ - return mode == QClipboard::Clipboard; -} - -HRESULT QWinRTClipboard::onContentChanged(IInspectable *, IInspectable *) -{ - emitChanged(QClipboard::Clipboard); - return S_OK; -} - -QT_END_NAMESPACE diff --git a/src/plugins/platforms/winrt/qwinrtclipboard.h b/src/plugins/platforms/winrt/qwinrtclipboard.h deleted file mode 100644 index 899fcbe730..0000000000 --- a/src/plugins/platforms/winrt/qwinrtclipboard.h +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTPLATFORMCLIPBOARD_H -#define QWINRTPLATFORMCLIPBOARD_H - -#include <qpa/qplatformclipboard.h> -#include <QMimeData> - -#include <wrl.h> - -namespace ABI { - namespace Windows { - namespace ApplicationModel { - namespace DataTransfer { - struct IClipboardStatics; - } - } - } -} - -QT_BEGIN_NAMESPACE - -class QWinRTClipboard: public QPlatformClipboard -{ -public: - QWinRTClipboard(); - - QMimeData *mimeData(QClipboard::Mode mode = QClipboard::Clipboard) override; - void setMimeData(QMimeData *data, QClipboard::Mode mode = QClipboard::Clipboard) override; - bool supportsMode(QClipboard::Mode mode) const override; - - HRESULT onContentChanged(IInspectable *, IInspectable *); -private: - Microsoft::WRL::ComPtr<ABI::Windows::ApplicationModel::DataTransfer::IClipboardStatics> m_nativeClipBoard; - QMimeData *m_mimeData; -}; - -QT_END_NAMESPACE - -#endif // QWINRTPLATFORMCLIPBOARD_H diff --git a/src/plugins/platforms/winrt/qwinrtcursor.cpp b/src/plugins/platforms/winrt/qwinrtcursor.cpp deleted file mode 100644 index 180905945b..0000000000 --- a/src/plugins/platforms/winrt/qwinrtcursor.cpp +++ /dev/null @@ -1,230 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwinrtcursor.h" -#include "qwinrtscreen.h" -#include <private/qeventdispatcher_winrt_p.h> - -#include <QtCore/qfunctions_winrt.h> -#include <QtGui/QGuiApplication> -#include <QtGui/QScreen> - -#include <functional> -#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 - -static inline bool qIsPointInRect(const Point &p, const Rect &r) -{ - return (p.X >= r.X && p.Y >= r.Y && p.X < r.X + r.Width && p.Y < r.Y + r.Height); -} - -class QWinRTCursorPrivate -{ -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); -} - -#ifndef QT_NO_CURSOR -void QWinRTCursor::changeCursor(QCursor *windowCursor, QWindow *window) -{ - Q_D(QWinRTCursor); - - HRESULT hr; - ICoreWindow *coreWindow = static_cast<QWinRTScreen *>(window->screen()->handle())->coreWindow(); - - CoreCursorType type; - switch (windowCursor ? windowCursor->shape() : Qt::ArrowCursor) { - case Qt::BlankCursor: - hr = QEventDispatcherWinRT::runOnXamlThread([coreWindow]() { - coreWindow->put_PointerCursor(nullptr); - return S_OK; - }); - RETURN_VOID_IF_FAILED("Failed to set blank native cursor"); - return; - default: - case Qt::OpenHandCursor: - case Qt::ClosedHandCursor: - case Qt::DragCopyCursor: - case Qt::DragMoveCursor: - case Qt::DragLinkCursor: - // (unavailable) - case Qt::ArrowCursor: - type = CoreCursorType_Arrow; - break; - case Qt::UpArrowCursor: - type = CoreCursorType_UpArrow; - break; - case Qt::CrossCursor: - type = CoreCursorType_Cross; - break; - case Qt::WaitCursor: - case Qt::BusyCursor: - type = CoreCursorType_Wait; - break; - case Qt::IBeamCursor: - type = CoreCursorType_IBeam; - break; - case Qt::SizeVerCursor: - case Qt::SplitVCursor: - type = CoreCursorType_SizeNorthSouth; - break; - case Qt::SizeHorCursor: - case Qt::SplitHCursor: - type = CoreCursorType_SizeWestEast; - break; - case Qt::SizeBDiagCursor: - type = CoreCursorType_SizeNortheastSouthwest; - break; - case Qt::SizeFDiagCursor: - type = CoreCursorType_SizeNorthwestSoutheast; - break; - case Qt::SizeAllCursor: - type = CoreCursorType_SizeAll; - break; - case Qt::PointingHandCursor: - type = CoreCursorType_Hand; - break; - case Qt::ForbiddenCursor: - type = CoreCursorType_UniversalNo; - break; - case Qt::WhatsThisCursor: - type = CoreCursorType_Help; - break; - case Qt::BitmapCursor: - case Qt::CustomCursor: - // TODO: figure out if arbitrary bitmaps can be made into resource IDs - // For now, we don't get enough info from QCursor to set a custom cursor - type = CoreCursorType_Custom; - break; - } - - ComPtr<ICoreCursor> cursor; - hr = d->cursorFactory->CreateCursor(type, 0, &cursor); - RETURN_VOID_IF_FAILED("Failed to create native cursor."); - - hr = QEventDispatcherWinRT::runOnXamlThread([coreWindow, &cursor]() { - return coreWindow->put_PointerCursor(cursor.Get()); - }); - RETURN_VOID_IF_FAILED("Failed to set native cursor"); -} -#endif // QT_NO_CURSOR - -QPoint QWinRTCursor::pos() const -{ - const QWinRTScreen *screen = static_cast<QWinRTScreen *>(QGuiApplication::primaryScreen()->handle()); - Q_ASSERT(screen); - ICoreWindow *coreWindow = screen->coreWindow(); - Q_ASSERT(coreWindow); - Point point; - Rect bounds; - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([coreWindow, &point, &bounds]() { - HRESULT hr = coreWindow->get_PointerPosition(&point); - RETURN_HR_IF_FAILED("Failed to obtain pointer position."); - hr = coreWindow->get_Bounds(&bounds); - RETURN_HR_IF_FAILED("Failed to obtain window bounds."); - return hr; - }); - Q_ASSERT_SUCCEEDED(hr); - QPointF position(qreal(point.X), qreal(point.Y)); - // If no cursor get_PointerPosition returns SHRT_MIN for x and y - if ((int(position.x()) == SHRT_MIN && int(position.y()) == SHRT_MIN) - || FAILED(hr)) - return QPointF(Q_INFINITY, Q_INFINITY).toPoint(); - position.rx() -= qreal(bounds.X); - position.ry() -= qreal(bounds.Y); - position *= screen->scaleFactor(); - return position.toPoint(); -} - -void QWinRTCursor::setPos(const QPoint &pos) -{ - QWinRTScreen *screen = static_cast<QWinRTScreen *>(QGuiApplication::primaryScreen()->handle()); - Q_ASSERT(screen); - ComPtr<ICoreWindow> coreWindow = screen->coreWindow(); - Q_ASSERT(coreWindow); - const QPointF scaledPos = QPointF(pos) / screen->scaleFactor(); - QWinRTScreen::MousePositionTransition t; - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([coreWindow, scaledPos, &t]() { - ComPtr<ICoreWindow2> coreWindow2; - HRESULT hr = coreWindow.As(&coreWindow2); - RETURN_HR_IF_FAILED("Failed to cast core window."); - Rect bounds; - hr = coreWindow->get_Bounds(&bounds); - RETURN_HR_IF_FAILED("Failed to obtain window bounds."); - Point mousePos; - hr = coreWindow->get_PointerPosition(&mousePos); - RETURN_HR_IF_FAILED("Failed to obtain mouse position."); - const Point p = { FLOAT(scaledPos.x()) + bounds.X, - FLOAT(scaledPos.y()) + bounds.Y }; - const bool wasInWindow = qIsPointInRect(mousePos, bounds); - const bool willBeInWindow = qIsPointInRect(p, bounds); - if (wasInWindow && willBeInWindow) - t = QWinRTScreen::MousePositionTransition::StayedIn; - else if (wasInWindow && !willBeInWindow) - t = QWinRTScreen::MousePositionTransition::MovedOut; - else if (!wasInWindow && willBeInWindow) - t = QWinRTScreen::MousePositionTransition::MovedIn; - else - t = QWinRTScreen::MousePositionTransition::StayedOut; - return coreWindow2->put_PointerPosition(p); - }); - RETURN_VOID_IF_FAILED("Failed to set cursor position"); - screen->emulateMouseMove(scaledPos, t); -} - -QT_END_NAMESPACE - diff --git a/src/plugins/platforms/winrt/qwinrtcursor.h b/src/plugins/platforms/winrt/qwinrtcursor.h deleted file mode 100644 index eca3d8c7ca..0000000000 --- a/src/plugins/platforms/winrt/qwinrtcursor.h +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTCURSOR_H -#define QWINRTCURSOR_H - -#include <qpa/qplatformcursor.h> - -QT_BEGIN_NAMESPACE - -class QWinRTCursorPrivate; -class QWinRTCursor : public QPlatformCursor -{ -public: - explicit QWinRTCursor(); - ~QWinRTCursor() override = default; -#ifndef QT_NO_CURSOR - void changeCursor(QCursor * windowCursor, QWindow *window) override; -#endif - QPoint pos() const override; - void setPos(const QPoint &pos) override; - -private: - QScopedPointer<QWinRTCursorPrivate> d_ptr; - Q_DECLARE_PRIVATE(QWinRTCursor) -}; - -QT_END_NAMESPACE - -#endif // QWINRTCURSOR_H diff --git a/src/plugins/platforms/winrt/qwinrtdrag.cpp b/src/plugins/platforms/winrt/qwinrtdrag.cpp deleted file mode 100644 index 3ed4cd692d..0000000000 --- a/src/plugins/platforms/winrt/qwinrtdrag.cpp +++ /dev/null @@ -1,889 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "qwinrtdrag.h" - -#include <QtCore/qglobal.h> -#include <QtCore/QMimeData> -#include <QtCore/QStringList> -#include <QtGui/QGuiApplication> -#include <qpa/qwindowsysteminterface.h> - -#include <qfunctions_winrt.h> -#include <private/qeventdispatcher_winrt_p.h> - -#include <Windows.ApplicationModel.datatransfer.h> -#include <windows.ui.xaml.h> -#include <windows.foundation.collections.h> -#include <windows.graphics.imaging.h> -#include <windows.storage.streams.h> -#include <functional> -#include <robuffer.h> - -using namespace ABI::Windows::ApplicationModel::DataTransfer; -using namespace ABI::Windows::ApplicationModel::DataTransfer::DragDrop; -using namespace ABI::Windows::Foundation; -using namespace ABI::Windows::Foundation::Collections; -using namespace ABI::Windows::Graphics::Imaging; -using namespace ABI::Windows::Storage; -using namespace ABI::Windows::Storage::Streams; -using namespace ABI::Windows::UI::Xaml; -using namespace Microsoft::WRL; -using namespace Microsoft::WRL::Wrappers; - -QT_BEGIN_NAMESPACE - -Q_LOGGING_CATEGORY(lcQpaMime, "qt.qpa.mime") - -ComPtr<IBuffer> createIBufferFromData(const char *data, qint32 size) -{ - static ComPtr<IBufferFactory> bufferFactory; - HRESULT hr; - if (!bufferFactory) { - hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Storage_Streams_Buffer).Get(), - IID_PPV_ARGS(&bufferFactory)); - Q_ASSERT_SUCCEEDED(hr); - } - - ComPtr<IBuffer> buffer; - const UINT32 length = UINT32(size); - hr = bufferFactory->Create(length, &buffer); - Q_ASSERT_SUCCEEDED(hr); - hr = buffer->put_Length(length); - Q_ASSERT_SUCCEEDED(hr); - - ComPtr<Windows::Storage::Streams::IBufferByteAccess> byteArrayAccess; - hr = buffer.As(&byteArrayAccess); - Q_ASSERT_SUCCEEDED(hr); - - byte *bytes; - hr = byteArrayAccess->Buffer(&bytes); - Q_ASSERT_SUCCEEDED(hr); - memcpy(bytes, data, length); - return buffer; -} - -class DragThreadTransferData : public QObject -{ - Q_OBJECT -public slots: - void handleDrag(); -public: - explicit DragThreadTransferData(QObject *parent = nullptr); - QWindow *window; - QWinRTInternalMimeData *mime; - QPoint point; - Qt::DropActions actions; - bool dropAction; - ComPtr<IDragEventArgs> nativeArgs; - ComPtr<IDragOperationDeferral> deferral; -}; - -inline QString hStringToQString(const HString &hString) -{ - quint32 l; - const wchar_t *raw = hString.GetRawBuffer(&l); - return (QString::fromWCharArray(raw, int(l))); -} - -inline HString qStringToHString(const QString &qString) -{ - HString h; - h.Set(reinterpret_cast<const wchar_t*>(qString.utf16()), uint(qString.size())); - return h; -} - -namespace NativeFormatStrings { - static ComPtr<IStandardDataFormatsStatics> dataStatics; - static HSTRING text; // text/plain - static HSTRING html; // text/html - static HSTRING storage; // text/uri-list -} - -static inline DataPackageOperation translateFromQDragDropActions(const Qt::DropAction action) -{ - switch (action) { - case Qt::CopyAction: - return DataPackageOperation_Copy; - case Qt::MoveAction: - return DataPackageOperation_Move; - case Qt::LinkAction: - return DataPackageOperation_Link; - case Qt::IgnoreAction: - default: - return DataPackageOperation_None; - } -} - -static inline Qt::DropActions translateToQDragDropActions(const DataPackageOperation op) -{ - Qt::DropActions actions = Qt::IgnoreAction; - // None needs to be interpreted as the sender being able to handle - // anything and let the receiver decide - if (op == DataPackageOperation_None) - actions = Qt::LinkAction | Qt::CopyAction | Qt::MoveAction; - if (op & DataPackageOperation_Link) - actions |= Qt::LinkAction; - if (op & DataPackageOperation_Copy) - actions |= Qt::CopyAction; - if (op & DataPackageOperation_Move) - actions |= Qt::MoveAction; - return actions; -} - -QWinRTInternalMimeData::QWinRTInternalMimeData() - : QInternalMimeData() -{ - qCDebug(lcQpaMime) << __FUNCTION__; - if (!NativeFormatStrings::dataStatics) { - HRESULT hr; - hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_ApplicationModel_DataTransfer_StandardDataFormats).Get(), - IID_PPV_ARGS(&NativeFormatStrings::dataStatics)); - Q_ASSERT_SUCCEEDED(hr); - hr = NativeFormatStrings::dataStatics->get_Text(&NativeFormatStrings::text); - Q_ASSERT_SUCCEEDED(hr); - hr = NativeFormatStrings::dataStatics->get_Html(&NativeFormatStrings::html); - Q_ASSERT_SUCCEEDED(hr); - hr = NativeFormatStrings::dataStatics->get_StorageItems(&NativeFormatStrings::storage); - Q_ASSERT_SUCCEEDED(hr); - } -} - -bool QWinRTInternalMimeData::hasFormat_sys(const QString &mimetype) const -{ - qCDebug(lcQpaMime) << __FUNCTION__ << mimetype; - - if (!dataView) - return false; - - return formats_sys().contains(mimetype); -} - -QStringList QWinRTInternalMimeData::formats_sys() const -{ - qCDebug(lcQpaMime) << __FUNCTION__; - - if (!dataView) - return QStringList(); - - if (!formats.isEmpty()) - return formats; - - HRESULT hr; - hr = QEventDispatcherWinRT::runOnXamlThread([this]() { - boolean contains; - HRESULT hr; - hr = dataView->Contains(NativeFormatStrings::text, &contains); - if (SUCCEEDED(hr) && contains) - formats.append(QLatin1String("text/plain")); - - hr = dataView->Contains(NativeFormatStrings::html, &contains); - if (SUCCEEDED(hr) && contains) - formats.append(QLatin1String("text/html")); - - hr = dataView->Contains(NativeFormatStrings::storage, &contains); - if (SUCCEEDED(hr) && contains) - formats.append(QLatin1String("text/uri-list")); - - // We need to add any additional format as well, for legacy windows - // reasons, but also in case someone adds custom formats. - ComPtr<IVectorView<HSTRING>> availableFormats; - hr = dataView->get_AvailableFormats(&availableFormats); - RETURN_OK_IF_FAILED("Could not query available formats."); - - quint32 size; - hr = availableFormats->get_Size(&size); - RETURN_OK_IF_FAILED("Could not query format vector size."); - for (quint32 i = 0; i < size; ++i) { - HString str; - hr = availableFormats->GetAt(i, str.GetAddressOf()); - if (FAILED(hr)) - continue; - formats.append(hStringToQString(str)); - } - return S_OK; - }); - Q_ASSERT_SUCCEEDED(hr); - - return formats; -} - -QVariant QWinRTInternalMimeData::retrieveData_sys(const QString &mimetype, QVariant::Type preferredType) const -{ - qCDebug(lcQpaMime) << __FUNCTION__ << mimetype << preferredType; - - if (!dataView || !formats.contains(mimetype)) - return QVariant(); - - QVariant result; - HRESULT hr; - if (mimetype == QLatin1String("text/plain")) { - hr = QEventDispatcherWinRT::runOnXamlThread([this, &result]() { - HRESULT hr; - ComPtr<IAsyncOperation<HSTRING>> op; - HString res; - hr = dataView->GetTextAsync(&op); - Q_ASSERT_SUCCEEDED(hr); - hr = QWinRTFunctions::await(op, res.GetAddressOf()); - Q_ASSERT_SUCCEEDED(hr); - result.setValue(hStringToQString(res)); - return S_OK; - }); - } else if (mimetype == QLatin1String("text/uri-list")) { - hr = QEventDispatcherWinRT::runOnXamlThread([this, &result]() { - HRESULT hr; - ComPtr<IAsyncOperation<IVectorView<IStorageItem*>*>> op; - hr = dataView->GetStorageItemsAsync(&op); - Q_ASSERT_SUCCEEDED(hr); - ComPtr<IVectorView<IStorageItem*>> nativeItems; - hr = QWinRTFunctions::await(op, nativeItems.GetAddressOf()); - Q_ASSERT_SUCCEEDED(hr); - QList<QVariant> items; - quint32 count; - hr = nativeItems->get_Size(&count); - for (quint32 i = 0; i < count; ++i) { - ComPtr<IStorageItem> item; - hr = nativeItems->GetAt(i, &item); - Q_ASSERT_SUCCEEDED(hr); - HString path; - hr = item->get_Path(path.GetAddressOf()); - Q_ASSERT_SUCCEEDED(hr); - items.append(QUrl::fromLocalFile(hStringToQString(path))); - } - result.setValue(items); - return S_OK; - }); - } else if (mimetype == QLatin1String("text/html")) { - hr = QEventDispatcherWinRT::runOnXamlThread([this, &result]() { - HRESULT hr; - ComPtr<IAsyncOperation<HSTRING>> op; - HString res; - hr = dataView->GetHtmlFormatAsync(&op); - Q_ASSERT_SUCCEEDED(hr); - hr = QWinRTFunctions::await(op, res.GetAddressOf()); - Q_ASSERT_SUCCEEDED(hr); - result.setValue(hStringToQString(res)); - return S_OK; - }); - } else { - // Asking for custom data - hr = QEventDispatcherWinRT::runOnXamlThread([this, &result, mimetype]() { - HRESULT hr; - ComPtr<IAsyncOperation<IInspectable*>> op; - ComPtr<IInspectable> res; - HString type; - type.Set(reinterpret_cast<const wchar_t*>(mimetype.utf16()), uint(mimetype.size())); - hr = dataView->GetDataAsync(type.Get(), &op); - RETURN_OK_IF_FAILED("Could not query custom drag data."); - hr = QWinRTFunctions::await(op, res.GetAddressOf()); - if (FAILED(hr) || !res) { - qCDebug(lcQpaMime) << "Custom drop data operation returned no results or failed."; - return S_OK; - } - - // Test for properties - ComPtr<IPropertyValue> propertyValue; - hr = res.As(&propertyValue); - if (SUCCEEDED(hr)) { - // We need to check which type of custom data we are receiving - PropertyType propertyType; - propertyValue->get_Type(&propertyType); - switch (propertyType) { - case PropertyType_UInt8: { - quint8 v; - hr = propertyValue->GetUInt8(&v); - Q_ASSERT_SUCCEEDED(hr); - result.setValue(v); - return S_OK; - } - case PropertyType_Int16: { - qint16 v; - hr = propertyValue->GetInt16(&v); - Q_ASSERT_SUCCEEDED(hr); - result.setValue(v); - return S_OK; - } - case PropertyType_UInt16: { - quint16 v; - hr = propertyValue->GetUInt16(&v); - Q_ASSERT_SUCCEEDED(hr); - result.setValue(v); - return S_OK; - } - case PropertyType_Int32: { - qint32 v; - hr = propertyValue->GetInt32(&v); - Q_ASSERT_SUCCEEDED(hr); - result.setValue(v); - return S_OK; - } - case PropertyType_UInt32: { - quint32 v; - hr = propertyValue->GetUInt32(&v); - Q_ASSERT_SUCCEEDED(hr); - result.setValue(v); - return S_OK; - } - case PropertyType_Int64: { - qint64 v; - hr = propertyValue->GetInt64(&v); - Q_ASSERT_SUCCEEDED(hr); - result.setValue(v); - return S_OK; - } - case PropertyType_UInt64: { - quint64 v; - hr = propertyValue->GetUInt64(&v); - Q_ASSERT_SUCCEEDED(hr); - result.setValue(v); - return S_OK; - } - case PropertyType_Single: { - float v; - hr = propertyValue->GetSingle(&v); - Q_ASSERT_SUCCEEDED(hr); - result.setValue(v); - return S_OK; - } - case PropertyType_Double: { - double v; - hr = propertyValue->GetDouble(&v); - Q_ASSERT_SUCCEEDED(hr); - result.setValue(v); - return S_OK; - } - case PropertyType_Char16: { - wchar_t v; - hr = propertyValue->GetChar16(&v); - Q_ASSERT_SUCCEEDED(hr); - result.setValue(QString::fromWCharArray(&v, 1)); - return S_OK; - } - case PropertyType_Boolean: { - boolean v; - hr = propertyValue->GetBoolean(&v); - Q_ASSERT_SUCCEEDED(hr); - result.setValue(v); - return S_OK; - } - case PropertyType_String: { - HString stringProperty; - hr = propertyValue->GetString(stringProperty.GetAddressOf()); - Q_ASSERT_SUCCEEDED(hr); - result.setValue(hStringToQString(stringProperty)); - return S_OK; - } - default: - qCDebug(lcQpaMime) << "Unknown property type dropped:" << propertyType; - } - return S_OK; - } - - // Custom data can be read via input streams - ComPtr<IRandomAccessStream> randomAccessStream; - hr = res.As(&randomAccessStream); - if (SUCCEEDED(hr)) { - UINT64 size; - hr = randomAccessStream->get_Size(&size); - Q_ASSERT_SUCCEEDED(hr); - ComPtr<IInputStream> stream; - hr = randomAccessStream.As(&stream); - Q_ASSERT_SUCCEEDED(hr); - - ComPtr<IBufferFactory> bufferFactory; - hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Storage_Streams_Buffer).Get(), - IID_PPV_ARGS(&bufferFactory)); - Q_ASSERT_SUCCEEDED(hr); - - UINT32 length = UINT32(qBound(quint64(0), quint64(size), quint64(UINT_MAX))); - ComPtr<IBuffer> buffer; - hr = bufferFactory->Create(length, &buffer); - Q_ASSERT_SUCCEEDED(hr); - - ComPtr<IAsyncOperationWithProgress<IBuffer *, UINT32>> readOp; - hr = stream->ReadAsync(buffer.Get(), length, InputStreamOptions_None, &readOp); - - ComPtr<IBuffer> effectiveBuffer; - hr = QWinRTFunctions::await(readOp, effectiveBuffer.GetAddressOf()); - - hr = effectiveBuffer->get_Length(&length); - - ComPtr<Windows::Storage::Streams::IBufferByteAccess> byteArrayAccess; - hr = effectiveBuffer.As(&byteArrayAccess); - - byte *bytes; - hr = byteArrayAccess->Buffer(&bytes); - QByteArray array((char *)bytes, int(length)); - result.setValue(array); - return S_OK; - } - - HSTRING runtimeClass; - hr = res->GetRuntimeClassName(&runtimeClass); - Q_ASSERT_SUCCEEDED(hr); - HString converted; - converted.Set(runtimeClass); - qCDebug(lcQpaMime) << "Unknown drop data type received (" << hStringToQString(converted) - << "). Ignoring..."; - return S_OK; - }); - } - return result; -} - -void QWinRTInternalMimeData::setDataView(const Microsoft::WRL::ComPtr<IDataPackageView> &d) -{ - dataView = d; - formats.clear(); -} - -static HRESULT qt_drag_enter(IInspectable *sender, ABI::Windows::UI::Xaml::IDragEventArgs *e) -{ - QWinRTDrag::instance()->handleNativeDragEvent(sender, e); - return S_OK; -} - -static HRESULT qt_drag_over(IInspectable *sender, ABI::Windows::UI::Xaml::IDragEventArgs *e) -{ - QWinRTDrag::instance()->handleNativeDragEvent(sender, e); - return S_OK; -} - -static HRESULT qt_drag_leave(IInspectable *sender, ABI::Windows::UI::Xaml::IDragEventArgs *e) -{ - // Qt internally checks for new drags and auto sends leave events - // Also there is no QPA function for handling leave - Q_UNUSED(sender); - Q_UNUSED(e); - return S_OK; -} - -static HRESULT qt_drop(IInspectable *sender, ABI::Windows::UI::Xaml::IDragEventArgs *e) -{ - QWinRTDrag::instance()->handleNativeDragEvent(sender, e, true); - return S_OK; -} - -#define Q_DECLARE_DRAGHANDLER(name,func) \ -class QtDragEventHandler##name : public IDragEventHandler \ -{ \ -public: \ - virtual ~QtDragEventHandler##name() {\ - }\ - STDMETHODIMP Invoke(IInspectable *sender, \ - ABI::Windows::UI::Xaml::IDragEventArgs *e) \ - { \ - return qt_##func(sender, e);\ - } \ - \ - STDMETHODIMP \ - QueryInterface(REFIID riid, void FAR* FAR* ppvObj) \ - { \ - if (riid == IID_IUnknown || riid == IID_IDragEventHandler) { \ - *ppvObj = this; \ - AddRef(); \ - return NOERROR; \ - } \ - *ppvObj = NULL; \ - return ResultFromScode(E_NOINTERFACE); \ - } \ - \ - STDMETHODIMP_(ULONG) \ - AddRef(void) \ - { \ - return ++m_refs; \ - } \ - \ - STDMETHODIMP_(ULONG) \ - Release(void) \ - { \ - if (--m_refs == 0) { \ - delete this; \ - return 0; \ - } \ - return m_refs; \ - } \ -private: \ -ULONG m_refs{0}; \ -}; - -Q_DECLARE_DRAGHANDLER(Enter, drag_enter) -Q_DECLARE_DRAGHANDLER(Over, drag_over) -Q_DECLARE_DRAGHANDLER(Leave, drag_leave) -Q_DECLARE_DRAGHANDLER(Drop, drop) - -#define Q_INST_DRAGHANDLER(name) QtDragEventHandler##name() - -Q_GLOBAL_STATIC(QWinRTDrag, gDrag); - -extern ComPtr<ABI::Windows::UI::Input::IPointerPoint> qt_winrt_lastPointerPoint; // qwinrtscreen.cpp - -QWinRTDrag::QWinRTDrag() - : QPlatformDrag() - , m_dragTarget(nullptr) -{ - qCDebug(lcQpaMime) << __FUNCTION__; - m_enter = new Q_INST_DRAGHANDLER(Enter); - m_over = new Q_INST_DRAGHANDLER(Over); - m_leave = new Q_INST_DRAGHANDLER(Leave); - m_drop = new Q_INST_DRAGHANDLER(Drop); - m_mimeData = new QWinRTInternalMimeData; -} - -QWinRTDrag::~QWinRTDrag() -{ - qCDebug(lcQpaMime) << __FUNCTION__; - delete m_enter; - delete m_over; - delete m_leave; - delete m_drop; - delete m_mimeData; -} - -QWinRTDrag *QWinRTDrag::instance() -{ - return gDrag; -} - -inline HRESULT resetUiElementDrag(ComPtr<IUIElement3> &elem3, EventRegistrationToken startingToken) -{ - return QEventDispatcherWinRT::runOnXamlThread([elem3, startingToken]() { - HRESULT hr; - hr = elem3->put_CanDrag(false); - Q_ASSERT_SUCCEEDED(hr); - hr = elem3->remove_DragStarting(startingToken); - Q_ASSERT_SUCCEEDED(hr); - return S_OK; - }); -} - -Qt::DropAction QWinRTDrag::drag(QDrag *drag) -{ - qCDebug(lcQpaMime) << __FUNCTION__ << drag; - - if (!qt_winrt_lastPointerPoint) { - Q_ASSERT_X(qt_winrt_lastPointerPoint, Q_FUNC_INFO, "No pointerpoint known"); - return Qt::IgnoreAction; - } - - ComPtr<IUIElement3> elem3; - HRESULT hr = m_ui.As(&elem3); - Q_ASSERT_SUCCEEDED(hr); - - ComPtr<IAsyncOperation<ABI::Windows::ApplicationModel::DataTransfer::DataPackageOperation>> op; - EventRegistrationToken startingToken; - - hr = QEventDispatcherWinRT::runOnXamlThread([drag, &op, &hr, elem3, &startingToken]() { - - hr = elem3->put_CanDrag(true); - Q_ASSERT_SUCCEEDED(hr); - - auto startingCallback = Callback<ITypedEventHandler<UIElement*, DragStartingEventArgs*>> ([drag](IInspectable *, IDragStartingEventArgs *args) { - qCDebug(lcQpaMime) << "Drag starting" << args; - - ComPtr<IDataPackage> dataPackage; - HRESULT hr; - hr = args->get_Data(dataPackage.GetAddressOf()); - Q_ASSERT_SUCCEEDED(hr); - Qt::DropAction action = drag->defaultAction(); - hr = dataPackage->put_RequestedOperation(translateFromQDragDropActions(action)); - Q_ASSERT_SUCCEEDED(hr); - -#ifndef QT_WINRT_LIMITED_DRAGANDDROP - ComPtr<IDragStartingEventArgs2> args2; - hr = args->QueryInterface(IID_PPV_ARGS(&args2)); - Q_ASSERT_SUCCEEDED(hr); - - Qt::DropActions actions = drag->supportedActions(); - DataPackageOperation allowedOperations = DataPackageOperation_None; - if (actions & Qt::CopyAction) - allowedOperations |= DataPackageOperation_Copy; - if (actions & Qt::MoveAction) - allowedOperations |= DataPackageOperation_Move; - if (actions & Qt::LinkAction) - allowedOperations |= DataPackageOperation_Link; - hr = args2->put_AllowedOperations(allowedOperations); - Q_ASSERT_SUCCEEDED(hr); -#endif // QT_WINRT_LIMITED_DRAGANDDROP - QMimeData *mimeData = drag->mimeData(); - if (mimeData->hasText()) { - hr = dataPackage->SetText(qStringToHString(mimeData->text()).Get()); - Q_ASSERT_SUCCEEDED(hr); - } - if (mimeData->hasHtml()) { - hr = dataPackage->SetHtmlFormat(qStringToHString(mimeData->html()).Get()); - Q_ASSERT_SUCCEEDED(hr); - } - // ### TODO: Missing: weblink, image - - if (!drag->pixmap().isNull()) { - const QImage image2 = drag->pixmap().toImage(); - const QImage image = image2.convertToFormat(QImage::Format_ARGB32); - if (!image.isNull()) { - // Create IBuffer containing image - ComPtr<IBuffer> imageBuffer - = createIBufferFromData(reinterpret_cast<const char*>(image.bits()), int(image.sizeInBytes())); - - ComPtr<ISoftwareBitmapFactory> bitmapFactory; - hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Graphics_Imaging_SoftwareBitmap).Get(), - IID_PPV_ARGS(&bitmapFactory)); - Q_ASSERT_SUCCEEDED(hr); - - ComPtr<ISoftwareBitmap> bitmap; - hr = bitmapFactory->Create(BitmapPixelFormat_Rgba8, image.width(), image.height(), &bitmap); - Q_ASSERT_SUCCEEDED(hr); - - hr = bitmap->CopyFromBuffer(imageBuffer.Get()); - Q_ASSERT_SUCCEEDED(hr); - - ComPtr<IDragUI> dragUi; - hr = args->get_DragUI(dragUi.GetAddressOf()); - Q_ASSERT_SUCCEEDED(hr); - - hr = dragUi->SetContentFromSoftwareBitmap(bitmap.Get()); - Q_ASSERT_SUCCEEDED(hr); - } - } - - const QStringList formats = mimeData->formats(); - for (auto item : formats) { - QByteArray data = mimeData->data(item); - - ComPtr<IBuffer> buffer = createIBufferFromData(data.constData(), data.size()); - - // We cannot push the buffer to the data package as the result on - // recipient side is different from native events. It still sends a - // buffer, but that potentially cannot be parsed. Hence we need to create - // a IRandomAccessStream which gets forwarded as is to the drop side. - ComPtr<IRandomAccessStream> ras; - hr = RoActivateInstance(HString::MakeReference(RuntimeClass_Windows_Storage_Streams_InMemoryRandomAccessStream).Get(), &ras); - Q_ASSERT_SUCCEEDED(hr); - - hr = ras->put_Size(UINT64(data.size())); - ComPtr<IOutputStream> outputStream; - hr = ras->GetOutputStreamAt(0, &outputStream); - Q_ASSERT_SUCCEEDED(hr); - - ComPtr<IAsyncOperationWithProgress<UINT32,UINT32>> writeOp; - hr = outputStream->WriteAsync(buffer.Get(), &writeOp); - Q_ASSERT_SUCCEEDED(hr); - - UINT32 result; - hr = QWinRTFunctions::await(writeOp, &result); - Q_ASSERT_SUCCEEDED(hr); - - unsigned char flushResult; - ComPtr<IAsyncOperation<bool>> flushOp; - hr = outputStream->FlushAsync(&flushOp); - Q_ASSERT_SUCCEEDED(hr); - - hr = QWinRTFunctions::await(flushOp, &flushResult); - Q_ASSERT_SUCCEEDED(hr); - - hr = dataPackage->SetData(qStringToHString(item).Get(), ras.Get()); - Q_ASSERT_SUCCEEDED(hr); - } - return S_OK; - }); - - hr = elem3->add_DragStarting(startingCallback.Get(), &startingToken); - Q_ASSERT_SUCCEEDED(hr); - - hr = elem3->StartDragAsync(qt_winrt_lastPointerPoint.Get(), &op); - Q_ASSERT_SUCCEEDED(hr); - - return hr; - }); - if (!op || FAILED(hr)) { - qCDebug(lcQpaMime) << "Drag failed:" << hr; - hr = resetUiElementDrag(elem3, startingToken); - Q_ASSERT_SUCCEEDED(hr); - return Qt::IgnoreAction; - } - - DataPackageOperation nativeOperationType; - // Do not yield, as that can cause deadlocks when dropping inside the same app - hr = QWinRTFunctions::await(op, &nativeOperationType, QWinRTFunctions::ProcessThreadEvents); - Q_ASSERT_SUCCEEDED(hr); - - hr = resetUiElementDrag(elem3, startingToken); - Q_ASSERT_SUCCEEDED(hr); - - Qt::DropAction resultAction; - switch (nativeOperationType) { - case DataPackageOperation_Link: - resultAction = Qt::LinkAction; - break; - case DataPackageOperation_Copy: - resultAction = Qt::CopyAction; - break; - case DataPackageOperation_Move: - resultAction = Qt::MoveAction; - break; - case DataPackageOperation_None: - default: - resultAction = Qt::IgnoreAction; - break; - } - - return resultAction; -} - -void QWinRTDrag::setDropTarget(QWindow *target) -{ - qCDebug(lcQpaMime) << __FUNCTION__ << target; - m_dragTarget = target; -} - -void QWinRTDrag::setUiElement(ComPtr<ABI::Windows::UI::Xaml::IUIElement> &element) -{ - qCDebug(lcQpaMime) << __FUNCTION__; - m_ui = element; - // We set the element to always accept drops and then evaluate during - // runtime - HRESULT hr = element->put_AllowDrop(TRUE); - EventRegistrationToken tok; - hr = element->add_DragEnter(m_enter, &tok); - RETURN_VOID_IF_FAILED("Failed to add DragEnter handler."); - hr = element->add_DragOver(m_over, &tok); - RETURN_VOID_IF_FAILED("Failed to add DragOver handler."); - hr = element->add_DragLeave(m_leave, &tok); - RETURN_VOID_IF_FAILED("Failed to add DragLeave handler."); - hr = element->add_Drop(m_drop, &tok); - RETURN_VOID_IF_FAILED("Failed to add Drop handler."); -} - -void QWinRTDrag::handleNativeDragEvent(IInspectable *sender, ABI::Windows::UI::Xaml::IDragEventArgs *e, bool drop) -{ - Q_UNUSED(sender); - - if (!m_dragTarget) - return; - - HRESULT hr; - Point relativePoint; - hr = e->GetPosition(m_ui.Get(), &relativePoint); - RETURN_VOID_IF_FAILED("Could not query drag position."); - const QPoint p(int(relativePoint.X), int(relativePoint.Y)); - - ComPtr<IDragEventArgs2> e2; - hr = e->QueryInterface(IID_PPV_ARGS(&e2)); - RETURN_VOID_IF_FAILED("Could not convert drag event args"); - - DragDropModifiers modifiers; - hr = e2->get_Modifiers(&modifiers); - -#ifndef QT_WINRT_LIMITED_DRAGANDDROP - ComPtr<IDragEventArgs3> e3; - hr = e->QueryInterface(IID_PPV_ARGS(&e3)); - Q_ASSERT_SUCCEEDED(hr); - - DataPackageOperation dataOp; - hr = e3->get_AllowedOperations(&dataOp); - if (FAILED(hr)) - qCDebug(lcQpaMime) << __FUNCTION__ << "Could not query drag operations"; - - const Qt::DropActions actions = translateToQDragDropActions(dataOp); -#else // !QT_WINRT_LIMITED_DRAGANDDROP - const Qt::DropActions actions = Qt::LinkAction | Qt::CopyAction | Qt::MoveAction;; -#endif // !QT_WINRT_LIMITED_DRAGANDDROP - - ComPtr<IDataPackageView> dataView; - hr = e2->get_DataView(&dataView); - Q_ASSERT_SUCCEEDED(hr); - - m_mimeData->setDataView(dataView); - - // We use deferral as we need to jump to the Qt thread to handle - // the drag event - ComPtr<IDragOperationDeferral> deferral; - hr = e2->GetDeferral(&deferral); - Q_ASSERT_SUCCEEDED(hr); - - DragThreadTransferData *transferData = new DragThreadTransferData; - transferData->moveToThread(qGuiApp->thread()); - transferData->window = m_dragTarget; - transferData->point = p; - transferData->mime = m_mimeData; - transferData->actions = actions; - transferData->dropAction = drop; - transferData->nativeArgs = e; - transferData->deferral = deferral; - QMetaObject::invokeMethod(transferData, "handleDrag", Qt::QueuedConnection); -} - -DragThreadTransferData::DragThreadTransferData(QObject *parent) - : QObject(parent) - , dropAction(false) -{ -} - -void DragThreadTransferData::handleDrag() -{ - bool accepted = false; - Qt::DropAction acceptedAction; - if (dropAction) { - QPlatformDropQtResponse response = QWindowSystemInterface::handleDrop(window, mime, point, actions); - accepted = response.isAccepted(); - acceptedAction = response.acceptedAction(); - } else { - QPlatformDragQtResponse response = QWindowSystemInterface::handleDrag(window, mime, point, actions); - accepted = response.isAccepted(); - acceptedAction = response.acceptedAction(); - } - - HRESULT hr; - hr = QEventDispatcherWinRT::runOnXamlThread([accepted, acceptedAction, this]() { - HRESULT hr; - hr = nativeArgs->put_Handled(accepted); - if (acceptedAction != Qt::IgnoreAction) { - ComPtr<IDragEventArgs2> e2; - hr = nativeArgs.As(&e2); - if (SUCCEEDED(hr)) - hr = e2->put_AcceptedOperation(translateFromQDragDropActions(acceptedAction)); - } - deferral->Complete(); - return S_OK; - }); - Q_ASSERT_SUCCEEDED(hr); - deleteLater(); -} - -QT_END_NAMESPACE - -#include "qwinrtdrag.moc" diff --git a/src/plugins/platforms/winrt/qwinrtdrag.h b/src/plugins/platforms/winrt/qwinrtdrag.h deleted file mode 100644 index ab57999bba..0000000000 --- a/src/plugins/platforms/winrt/qwinrtdrag.h +++ /dev/null @@ -1,116 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <qpa/qplatformdrag.h> - -#include <QtCore/QLoggingCategory> -#include <QtCore/QMimeData> -#include <QtGui/private/qdnd_p.h> -#include <QtGui/private/qinternalmimedata_p.h> - -#include <wrl.h> - -namespace ABI { - namespace Windows { - namespace ApplicationModel { - namespace DataTransfer { - struct IDataPackageView; - } - } - namespace UI { - namespace Xaml { - struct IUIElement; - struct IDragEventArgs; - struct IDragOperationDeferral; - //struct IDataPackageView; - } - } - } -} - -QT_BEGIN_NAMESPACE - -Q_DECLARE_LOGGING_CATEGORY(lcQpaMime) - -class QtDragEventHandlerEnter; -class QtDragEventHandlerOver; -class QtDragEventHandlerLeave; -class QtDragEventHandlerDrop; -class QWinRTInternalMimeData; - -class QWinRTInternalMimeData : public QInternalMimeData { -public: - QWinRTInternalMimeData(); - ~QWinRTInternalMimeData() override = default; - - bool hasFormat_sys(const QString &mimetype) const override; - QStringList formats_sys() const override; - QVariant retrieveData_sys(const QString &mimetype, QVariant::Type preferredType) const override; - - void setDataView(const Microsoft::WRL::ComPtr<ABI::Windows::ApplicationModel::DataTransfer::IDataPackageView> &d); -private: - Microsoft::WRL::ComPtr<ABI::Windows::ApplicationModel::DataTransfer::IDataPackageView> dataView; - mutable QStringList formats; -}; - -class QWinRTDrag : public QPlatformDrag { -public: - QWinRTDrag(); - ~QWinRTDrag() override; - static QWinRTDrag *instance(); - - Qt::DropAction drag(QDrag *) override; - - void setDropTarget(QWindow *target); - - // Native integration and registration - void setUiElement(Microsoft::WRL::ComPtr<ABI::Windows::UI::Xaml::IUIElement> &element); - - void handleNativeDragEvent(IInspectable *sender, ABI::Windows::UI::Xaml::IDragEventArgs *e, bool drop = false); -private: - Microsoft::WRL::ComPtr<ABI::Windows::UI::Xaml::IUIElement> m_ui; - QWindow *m_dragTarget; - QtDragEventHandlerEnter *m_enter; - QtDragEventHandlerOver *m_over; - QtDragEventHandlerLeave *m_leave; - QtDragEventHandlerDrop *m_drop; - QWinRTInternalMimeData *m_mimeData; -}; - -QT_END_NAMESPACE diff --git a/src/plugins/platforms/winrt/qwinrteglcontext.cpp b/src/plugins/platforms/winrt/qwinrteglcontext.cpp deleted file mode 100644 index aa64ac1f99..0000000000 --- a/src/plugins/platforms/winrt/qwinrteglcontext.cpp +++ /dev/null @@ -1,371 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwinrteglcontext.h" -#include "qwinrtwindow.h" -#include <private/qeventdispatcher_winrt_p.h> - -#include <functional> - -#include <d3d11.h> - -#include <EGL/egl.h> -#define EGL_EGLEXT_PROTOTYPES -#include <EGL/eglext.h> - -#include <QOffscreenSurface> -#include <QOpenGLContext> -#include <QtEglSupport/private/qeglconvenience_p.h> -#include <QtEglSupport/private/qeglpbuffer_p.h> - -QT_BEGIN_NAMESPACE - -struct WinRTEGLDisplay -{ - WinRTEGLDisplay() { - } - ~WinRTEGLDisplay() { - eglTerminate(eglDisplay); - } - - EGLDisplay eglDisplay; -}; - -Q_GLOBAL_STATIC(WinRTEGLDisplay, g) - -class QWinRTEGLContextPrivate -{ -public: - QWinRTEGLContextPrivate() : eglContext(EGL_NO_CONTEXT), eglShareContext(EGL_NO_CONTEXT) { } - QSurfaceFormat format; - EGLConfig eglConfig; - EGLContext eglContext; - EGLContext eglShareContext; -}; - -QWinRTEGLContext::QWinRTEGLContext(QOpenGLContext *context) - : d_ptr(new QWinRTEGLContextPrivate) -{ - Q_D(QWinRTEGLContext); - d->format = context->format(); - d->format.setRenderableType(QSurfaceFormat::OpenGLES); - if (QPlatformOpenGLContext *shareHandle = context->shareHandle()) - d->eglShareContext = static_cast<QWinRTEGLContext *>(shareHandle)->d_ptr->eglContext; -} - -QWinRTEGLContext::~QWinRTEGLContext() -{ - Q_D(QWinRTEGLContext); - if (d->eglContext != EGL_NO_CONTEXT) - eglDestroyContext(g->eglDisplay, d->eglContext); -} - -void QWinRTEGLContext::initialize() -{ - Q_D(QWinRTEGLContext); - - // Test if the hardware supports at least level 9_3 - D3D_FEATURE_LEVEL featureLevels[] = { D3D_FEATURE_LEVEL_9_3 }; // minimum feature level - HRESULT hr = D3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, featureLevels, 1, - D3D11_SDK_VERSION, nullptr, nullptr, nullptr); - EGLint deviceType = SUCCEEDED(hr) ? EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE - : EGL_PLATFORM_ANGLE_DEVICE_TYPE_WARP_ANGLE; - - eglBindAPI(EGL_OPENGL_ES_API); - - const EGLint displayAttributes[] = { - EGL_PLATFORM_ANGLE_TYPE_ANGLE, EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, - EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE, deviceType, - EGL_PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE, true, - EGL_NONE, - }; - g->eglDisplay = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, EGL_DEFAULT_DISPLAY, displayAttributes); - if (Q_UNLIKELY(g->eglDisplay == EGL_NO_DISPLAY)) - qCritical("Failed to initialize EGL display: 0x%x", eglGetError()); - - // eglInitialize checks for EGL_PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE - // which adds a suspending handler. This needs to be added from the Xaml - // thread itself, otherwise it will not be invoked. add_Suspending does - // not return an error unfortunately, so it silently fails and causes - // applications to not quit when the system wants to terminate the app - // after suspend. - hr = QEventDispatcherWinRT::runOnXamlThread([]() { - if (!eglInitialize(g->eglDisplay, nullptr, nullptr)) - qCritical("Failed to initialize EGL: 0x%x", eglGetError()); - return S_OK; - }); - d->eglConfig = q_configFromGLFormat(g->eglDisplay, d->format); - - const EGLint flags = d->format.testOption(QSurfaceFormat::DebugContext) - ? EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR : 0; - const int major = d->format.majorVersion(); - const int minor = d->format.minorVersion(); - if (major > 3 || (major == 3 && minor > 0)) - qWarning("QWinRTEGLContext: ANGLE only partially supports OpenGL ES > 3.0"); - const EGLint attributes[] = { - EGL_CONTEXT_CLIENT_VERSION, d->format.majorVersion(), - EGL_CONTEXT_MINOR_VERSION_KHR, d->format.minorVersion(), - EGL_CONTEXT_FLAGS_KHR, flags, - EGL_NONE - }; - d->eglContext = eglCreateContext(g->eglDisplay, d->eglConfig, d->eglShareContext, attributes); - if (d->eglContext == EGL_NO_CONTEXT) { - qWarning("QEGLPlatformContext: Failed to create context: %x", eglGetError()); - return; - } -} - -bool QWinRTEGLContext::makeCurrent(QPlatformSurface *windowSurface) -{ - Q_D(QWinRTEGLContext); - Q_ASSERT(windowSurface->surface()->supportsOpenGL()); - - EGLSurface surface; - if (windowSurface->surface()->surfaceClass() == QSurface::Window) { - QWinRTWindow *window = static_cast<QWinRTWindow *>(windowSurface); - if (window->eglSurface() == EGL_NO_SURFACE) - window->createEglSurface(g->eglDisplay, d->eglConfig); - - surface = window->eglSurface(); - } else { // Offscreen - surface = static_cast<QEGLPbuffer *>(windowSurface)->pbuffer(); - } - - if (surface == EGL_NO_SURFACE) - return false; - - const bool ok = eglMakeCurrent(g->eglDisplay, surface, surface, d->eglContext); - if (!ok) { - qWarning("QEGLPlatformContext: eglMakeCurrent failed: %x", eglGetError()); - return false; - } - - eglSwapInterval(g->eglDisplay, d->format.swapInterval()); - return true; -} - -void QWinRTEGLContext::doneCurrent() -{ - const bool ok = eglMakeCurrent(g->eglDisplay, EGL_NO_SURFACE, - EGL_NO_SURFACE, EGL_NO_CONTEXT); - if (!ok) - qWarning("QEGLPlatformContext: eglMakeCurrent failed: %x", eglGetError()); -} - -void QWinRTEGLContext::swapBuffers(QPlatformSurface *windowSurface) -{ - Q_ASSERT(windowSurface->surface()->supportsOpenGL()); - - const QWinRTWindow *window = static_cast<QWinRTWindow *>(windowSurface); - eglSwapBuffers(g->eglDisplay, window->eglSurface()); -} - -QSurfaceFormat QWinRTEGLContext::format() const -{ - Q_D(const QWinRTEGLContext); - return d->format; -} - -QFunctionPointer QWinRTEGLContext::getProcAddress(const char *procName) -{ - static QHash<QByteArray, QFunctionPointer> standardFuncs; - if (standardFuncs.isEmpty()) { - standardFuncs.insert(QByteArrayLiteral("glBindTexture"), (QFunctionPointer)&glBindTexture); - standardFuncs.insert(QByteArrayLiteral("glBlendFunc"), (QFunctionPointer)&glBlendFunc); - standardFuncs.insert(QByteArrayLiteral("glClear"), (QFunctionPointer)&glClear); - standardFuncs.insert(QByteArrayLiteral("glClearColor"), (QFunctionPointer)&glClearColor); - standardFuncs.insert(QByteArrayLiteral("glClearStencil"), (QFunctionPointer)&glClearStencil); - standardFuncs.insert(QByteArrayLiteral("glColorMask"), (QFunctionPointer)&glColorMask); - standardFuncs.insert(QByteArrayLiteral("glCopyTexImage2D"), (QFunctionPointer)&glCopyTexImage2D); - standardFuncs.insert(QByteArrayLiteral("glCopyTexSubImage2D"), (QFunctionPointer)&glCopyTexSubImage2D); - standardFuncs.insert(QByteArrayLiteral("glCullFace"), (QFunctionPointer)&glCullFace); - standardFuncs.insert(QByteArrayLiteral("glDeleteTextures"), (QFunctionPointer)&glDeleteTextures); - standardFuncs.insert(QByteArrayLiteral("glDepthFunc"), (QFunctionPointer)&glDepthFunc); - standardFuncs.insert(QByteArrayLiteral("glDepthMask"), (QFunctionPointer)&glDepthMask); - standardFuncs.insert(QByteArrayLiteral("glDisable"), (QFunctionPointer)&glDisable); - standardFuncs.insert(QByteArrayLiteral("glDrawArrays"), (QFunctionPointer)&glDrawArrays); - standardFuncs.insert(QByteArrayLiteral("glDrawElements"), (QFunctionPointer)&glDrawElements); - standardFuncs.insert(QByteArrayLiteral("glEnable"), (QFunctionPointer)&glEnable); - standardFuncs.insert(QByteArrayLiteral("glFinish"), (QFunctionPointer)&glFinish); - standardFuncs.insert(QByteArrayLiteral("glFlush"), (QFunctionPointer)&glFlush); - standardFuncs.insert(QByteArrayLiteral("glFrontFace"), (QFunctionPointer)&glFrontFace); - standardFuncs.insert(QByteArrayLiteral("glGenTextures"), (QFunctionPointer)&glGenTextures); - standardFuncs.insert(QByteArrayLiteral("glGetBooleanv"), (QFunctionPointer)&glGetBooleanv); - standardFuncs.insert(QByteArrayLiteral("glGetError"), (QFunctionPointer)&glGetError); - standardFuncs.insert(QByteArrayLiteral("glGetFloatv"), (QFunctionPointer)&glGetFloatv); - standardFuncs.insert(QByteArrayLiteral("glGetIntegerv"), (QFunctionPointer)&glGetIntegerv); - standardFuncs.insert(QByteArrayLiteral("glGetString"), (QFunctionPointer)&glGetString); - standardFuncs.insert(QByteArrayLiteral("glGetTexParameterfv"), (QFunctionPointer)&glGetTexParameterfv); - standardFuncs.insert(QByteArrayLiteral("glGetTexParameteriv"), (QFunctionPointer)&glGetTexParameteriv); - standardFuncs.insert(QByteArrayLiteral("glHint"), (QFunctionPointer)&glHint); - standardFuncs.insert(QByteArrayLiteral("glIsEnabled"), (QFunctionPointer)&glIsEnabled); - standardFuncs.insert(QByteArrayLiteral("glIsTexture"), (QFunctionPointer)&glIsTexture); - standardFuncs.insert(QByteArrayLiteral("glLineWidth"), (QFunctionPointer)&glLineWidth); - standardFuncs.insert(QByteArrayLiteral("glPixelStorei"), (QFunctionPointer)&glPixelStorei); - standardFuncs.insert(QByteArrayLiteral("glPolygonOffset"), (QFunctionPointer)&glPolygonOffset); - standardFuncs.insert(QByteArrayLiteral("glReadPixels"), (QFunctionPointer)&glReadPixels); - standardFuncs.insert(QByteArrayLiteral("glScissor"), (QFunctionPointer)&glScissor); - standardFuncs.insert(QByteArrayLiteral("glStencilFunc"), (QFunctionPointer)&glStencilFunc); - standardFuncs.insert(QByteArrayLiteral("glStencilMask"), (QFunctionPointer)&glStencilMask); - standardFuncs.insert(QByteArrayLiteral("glStencilOp"), (QFunctionPointer)&glStencilOp); - standardFuncs.insert(QByteArrayLiteral("glTexImage2D"), (QFunctionPointer)&glTexImage2D); - standardFuncs.insert(QByteArrayLiteral("glTexParameterf"), (QFunctionPointer)&glTexParameterf); - standardFuncs.insert(QByteArrayLiteral("glTexParameterfv"), (QFunctionPointer)&glTexParameterfv); - standardFuncs.insert(QByteArrayLiteral("glTexParameteri"), (QFunctionPointer)&glTexParameteri); - standardFuncs.insert(QByteArrayLiteral("glTexParameteriv"), (QFunctionPointer)&glTexParameteriv); - standardFuncs.insert(QByteArrayLiteral("glTexSubImage2D"), (QFunctionPointer)&glTexSubImage2D); - standardFuncs.insert(QByteArrayLiteral("glViewport"), (QFunctionPointer)&glViewport); - standardFuncs.insert(QByteArrayLiteral("glActiveTexture"), (QFunctionPointer)&glActiveTexture); - standardFuncs.insert(QByteArrayLiteral("glAttachShader"), (QFunctionPointer)&glAttachShader); - standardFuncs.insert(QByteArrayLiteral("glBindAttribLocation"), (QFunctionPointer)&glBindAttribLocation); - standardFuncs.insert(QByteArrayLiteral("glBindBuffer"), (QFunctionPointer)&glBindBuffer); - standardFuncs.insert(QByteArrayLiteral("glBindFramebuffer"), (QFunctionPointer)&glBindFramebuffer); - standardFuncs.insert(QByteArrayLiteral("glBindRenderbuffer"), (QFunctionPointer)&glBindRenderbuffer); - standardFuncs.insert(QByteArrayLiteral("glBlendColor"), (QFunctionPointer)&glBlendColor); - standardFuncs.insert(QByteArrayLiteral("glBlendEquation"), (QFunctionPointer)&glBlendEquation); - standardFuncs.insert(QByteArrayLiteral("glBlendEquationSeparate"), (QFunctionPointer)&glBlendEquationSeparate); - standardFuncs.insert(QByteArrayLiteral("glBlendFuncSeparate"), (QFunctionPointer)&glBlendFuncSeparate); - standardFuncs.insert(QByteArrayLiteral("glBufferData"), (QFunctionPointer)&glBufferData); - standardFuncs.insert(QByteArrayLiteral("glBufferSubData"), (QFunctionPointer)&glBufferSubData); - standardFuncs.insert(QByteArrayLiteral("glCheckFramebufferStatus"), (QFunctionPointer)&glCheckFramebufferStatus); - standardFuncs.insert(QByteArrayLiteral("glCompileShader"), (QFunctionPointer)&glCompileShader); - standardFuncs.insert(QByteArrayLiteral("glCompressedTexImage2D"), (QFunctionPointer)&glCompressedTexImage2D); - standardFuncs.insert(QByteArrayLiteral("glCompressedTexSubImage2D"), (QFunctionPointer)&glCompressedTexSubImage2D); - standardFuncs.insert(QByteArrayLiteral("glCreateProgram"), (QFunctionPointer)&glCreateProgram); - standardFuncs.insert(QByteArrayLiteral("glCreateShader"), (QFunctionPointer)&glCreateShader); - standardFuncs.insert(QByteArrayLiteral("glDeleteBuffers"), (QFunctionPointer)&glDeleteBuffers); - standardFuncs.insert(QByteArrayLiteral("glDeleteFramebuffers"), (QFunctionPointer)&glDeleteFramebuffers); - standardFuncs.insert(QByteArrayLiteral("glDeleteProgram"), (QFunctionPointer)&glDeleteProgram); - standardFuncs.insert(QByteArrayLiteral("glDeleteRenderbuffers"), (QFunctionPointer)&glDeleteRenderbuffers); - standardFuncs.insert(QByteArrayLiteral("glDeleteShader"), (QFunctionPointer)&glDeleteShader); - standardFuncs.insert(QByteArrayLiteral("glDetachShader"), (QFunctionPointer)&glDetachShader); - standardFuncs.insert(QByteArrayLiteral("glDisableVertexAttribArray"), (QFunctionPointer)&glDisableVertexAttribArray); - standardFuncs.insert(QByteArrayLiteral("glEnableVertexAttribArray"), (QFunctionPointer)&glEnableVertexAttribArray); - standardFuncs.insert(QByteArrayLiteral("glFramebufferRenderbuffer"), (QFunctionPointer)&glFramebufferRenderbuffer); - standardFuncs.insert(QByteArrayLiteral("glFramebufferTexture2D"), (QFunctionPointer)&glFramebufferTexture2D); - standardFuncs.insert(QByteArrayLiteral("glGenBuffers"), (QFunctionPointer)&glGenBuffers); - standardFuncs.insert(QByteArrayLiteral("glGenerateMipmap"), (QFunctionPointer)&glGenerateMipmap); - standardFuncs.insert(QByteArrayLiteral("glGenFramebuffers"), (QFunctionPointer)&glGenFramebuffers); - standardFuncs.insert(QByteArrayLiteral("glGenRenderbuffers"), (QFunctionPointer)&glGenRenderbuffers); - standardFuncs.insert(QByteArrayLiteral("glGetActiveAttrib"), (QFunctionPointer)&glGetActiveAttrib); - standardFuncs.insert(QByteArrayLiteral("glGetActiveUniform"), (QFunctionPointer)&glGetActiveUniform); - standardFuncs.insert(QByteArrayLiteral("glGetAttachedShaders"), (QFunctionPointer)&glGetAttachedShaders); - standardFuncs.insert(QByteArrayLiteral("glGetAttribLocation"), (QFunctionPointer)&glGetAttribLocation); - standardFuncs.insert(QByteArrayLiteral("glGetBufferParameteriv"), (QFunctionPointer)&glGetBufferParameteriv); - standardFuncs.insert(QByteArrayLiteral("glGetFramebufferAttachmentParameteriv"), (QFunctionPointer)&glGetFramebufferAttachmentParameteriv); - standardFuncs.insert(QByteArrayLiteral("glGetProgramiv"), (QFunctionPointer)&glGetProgramiv); - standardFuncs.insert(QByteArrayLiteral("glGetProgramInfoLog"), (QFunctionPointer)&glGetProgramInfoLog); - standardFuncs.insert(QByteArrayLiteral("glGetRenderbufferParameteriv"), (QFunctionPointer)&glGetRenderbufferParameteriv); - standardFuncs.insert(QByteArrayLiteral("glGetShaderiv"), (QFunctionPointer)&glGetShaderiv); - standardFuncs.insert(QByteArrayLiteral("glGetShaderInfoLog"), (QFunctionPointer)&glGetShaderInfoLog); - standardFuncs.insert(QByteArrayLiteral("glGetShaderPrecisionFormat"), (QFunctionPointer)&glGetShaderPrecisionFormat); - standardFuncs.insert(QByteArrayLiteral("glGetShaderSource"), (QFunctionPointer)&glGetShaderSource); - standardFuncs.insert(QByteArrayLiteral("glGetUniformfv"), (QFunctionPointer)&glGetUniformfv); - standardFuncs.insert(QByteArrayLiteral("glGetUniformiv"), (QFunctionPointer)&glGetUniformiv); - standardFuncs.insert(QByteArrayLiteral("glGetUniformLocation"), (QFunctionPointer)&glGetUniformLocation); - standardFuncs.insert(QByteArrayLiteral("glGetVertexAttribfv"), (QFunctionPointer)&glGetVertexAttribfv); - standardFuncs.insert(QByteArrayLiteral("glGetVertexAttribiv"), (QFunctionPointer)&glGetVertexAttribiv); - standardFuncs.insert(QByteArrayLiteral("glGetVertexAttribPointerv"), (QFunctionPointer)&glGetVertexAttribPointerv); - standardFuncs.insert(QByteArrayLiteral("glIsBuffer"), (QFunctionPointer)&glIsBuffer); - standardFuncs.insert(QByteArrayLiteral("glIsFramebuffer"), (QFunctionPointer)&glIsFramebuffer); - standardFuncs.insert(QByteArrayLiteral("glIsProgram"), (QFunctionPointer)&glIsProgram); - standardFuncs.insert(QByteArrayLiteral("glIsRenderbuffer"), (QFunctionPointer)&glIsRenderbuffer); - standardFuncs.insert(QByteArrayLiteral("glIsShader"), (QFunctionPointer)&glIsShader); - standardFuncs.insert(QByteArrayLiteral("glLinkProgram"), (QFunctionPointer)&glLinkProgram); - standardFuncs.insert(QByteArrayLiteral("glReleaseShaderCompiler"), (QFunctionPointer)&glReleaseShaderCompiler); - standardFuncs.insert(QByteArrayLiteral("glRenderbufferStorage"), (QFunctionPointer)&glRenderbufferStorage); - standardFuncs.insert(QByteArrayLiteral("glSampleCoverage"), (QFunctionPointer)&glSampleCoverage); - standardFuncs.insert(QByteArrayLiteral("glShaderBinary"), (QFunctionPointer)&glShaderBinary); - standardFuncs.insert(QByteArrayLiteral("glShaderSource"), (QFunctionPointer)&glShaderSource); - standardFuncs.insert(QByteArrayLiteral("glStencilFuncSeparate"), (QFunctionPointer)&glStencilFuncSeparate); - standardFuncs.insert(QByteArrayLiteral("glStencilMaskSeparate"), (QFunctionPointer)&glStencilMaskSeparate); - standardFuncs.insert(QByteArrayLiteral("glStencilOpSeparate"), (QFunctionPointer)&glStencilOpSeparate); - standardFuncs.insert(QByteArrayLiteral("glUniform1f"), (QFunctionPointer)&glUniform1f); - standardFuncs.insert(QByteArrayLiteral("glUniform1fv"), (QFunctionPointer)&glUniform1fv); - standardFuncs.insert(QByteArrayLiteral("glUniform1i"), (QFunctionPointer)&glUniform1i); - standardFuncs.insert(QByteArrayLiteral("glUniform1iv"), (QFunctionPointer)&glUniform1iv); - standardFuncs.insert(QByteArrayLiteral("glUniform2f"), (QFunctionPointer)&glUniform2f); - standardFuncs.insert(QByteArrayLiteral("glUniform2fv"), (QFunctionPointer)&glUniform2fv); - standardFuncs.insert(QByteArrayLiteral("glUniform2i"), (QFunctionPointer)&glUniform2i); - standardFuncs.insert(QByteArrayLiteral("glUniform2iv"), (QFunctionPointer)&glUniform2iv); - standardFuncs.insert(QByteArrayLiteral("glUniform3f"), (QFunctionPointer)&glUniform3f); - standardFuncs.insert(QByteArrayLiteral("glUniform3fv"), (QFunctionPointer)&glUniform3fv); - standardFuncs.insert(QByteArrayLiteral("glUniform3i"), (QFunctionPointer)&glUniform3i); - standardFuncs.insert(QByteArrayLiteral("glUniform3iv"), (QFunctionPointer)&glUniform3iv); - standardFuncs.insert(QByteArrayLiteral("glUniform4f"), (QFunctionPointer)&glUniform4f); - standardFuncs.insert(QByteArrayLiteral("glUniform4fv"), (QFunctionPointer)&glUniform4fv); - standardFuncs.insert(QByteArrayLiteral("glUniform4i"), (QFunctionPointer)&glUniform4i); - standardFuncs.insert(QByteArrayLiteral("glUniform4iv"), (QFunctionPointer)&glUniform4iv); - standardFuncs.insert(QByteArrayLiteral("glUniformMatrix2fv"), (QFunctionPointer)&glUniformMatrix2fv); - standardFuncs.insert(QByteArrayLiteral("glUniformMatrix3fv"), (QFunctionPointer)&glUniformMatrix3fv); - standardFuncs.insert(QByteArrayLiteral("glUniformMatrix4fv"), (QFunctionPointer)&glUniformMatrix4fv); - standardFuncs.insert(QByteArrayLiteral("glUseProgram"), (QFunctionPointer)&glUseProgram); - standardFuncs.insert(QByteArrayLiteral("glValidateProgram"), (QFunctionPointer)&glValidateProgram); - standardFuncs.insert(QByteArrayLiteral("glVertexAttrib1f"), (QFunctionPointer)&glVertexAttrib1f); - standardFuncs.insert(QByteArrayLiteral("glVertexAttrib1fv"), (QFunctionPointer)&glVertexAttrib1fv); - standardFuncs.insert(QByteArrayLiteral("glVertexAttrib2f"), (QFunctionPointer)&glVertexAttrib2f); - standardFuncs.insert(QByteArrayLiteral("glVertexAttrib2fv"), (QFunctionPointer)&glVertexAttrib2fv); - standardFuncs.insert(QByteArrayLiteral("glVertexAttrib3f"), (QFunctionPointer)&glVertexAttrib3f); - standardFuncs.insert(QByteArrayLiteral("glVertexAttrib3fv"), (QFunctionPointer)&glVertexAttrib3fv); - standardFuncs.insert(QByteArrayLiteral("glVertexAttrib4f"), (QFunctionPointer)&glVertexAttrib4f); - standardFuncs.insert(QByteArrayLiteral("glVertexAttrib4fv"), (QFunctionPointer)&glVertexAttrib4fv); - standardFuncs.insert(QByteArrayLiteral("glVertexAttribPointer"), (QFunctionPointer)&glVertexAttribPointer); - standardFuncs.insert(QByteArrayLiteral("glClearDepthf"), (QFunctionPointer)&glClearDepthf); - standardFuncs.insert(QByteArrayLiteral("glDepthRangef"), (QFunctionPointer)&glDepthRangef); - }; - - QHash<QByteArray, QFunctionPointer>::const_iterator i = standardFuncs.find(procName); - if (i != standardFuncs.end()) - return i.value(); - - return eglGetProcAddress(procName); -} - -bool QWinRTEGLContext::isValid() const -{ - Q_D(const QWinRTEGLContext); - return d->eglContext != EGL_NO_CONTEXT; -} - -EGLDisplay QWinRTEGLContext::display() -{ - return g->eglDisplay; -} - -QT_END_NAMESPACE diff --git a/src/plugins/platforms/winrt/qwinrteglcontext.h b/src/plugins/platforms/winrt/qwinrteglcontext.h deleted file mode 100644 index 8dbd0fc7d0..0000000000 --- a/src/plugins/platforms/winrt/qwinrteglcontext.h +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINDOWSEGLCONTEXT_H -#define QWINDOWSEGLCONTEXT_H - -#include <qpa/qplatformopenglcontext.h> -#include <EGL/egl.h> - -QT_BEGIN_NAMESPACE - -class QWinRTEGLContextPrivate; -class QWinRTEGLContext : public QPlatformOpenGLContext -{ -public: - explicit QWinRTEGLContext(QOpenGLContext *context); - ~QWinRTEGLContext() override; - - void initialize() override; - - bool makeCurrent(QPlatformSurface *windowSurface) override; - void doneCurrent() override; - void swapBuffers(QPlatformSurface *windowSurface) override; - - QSurfaceFormat format() const override; - QFunctionPointer getProcAddress(const char *procName) override; - bool isValid() const override; - - static EGLDisplay display(); -private: - QScopedPointer<QWinRTEGLContextPrivate> d_ptr; - Q_DECLARE_PRIVATE(QWinRTEGLContext) -}; - -QT_END_NAMESPACE - -#endif // QWINDOWSEGLCONTEXT_H diff --git a/src/plugins/platforms/winrt/qwinrteventdispatcher.cpp b/src/plugins/platforms/winrt/qwinrteventdispatcher.cpp deleted file mode 100644 index eb59c22033..0000000000 --- a/src/plugins/platforms/winrt/qwinrteventdispatcher.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwinrteventdispatcher.h" -#include <qpa/qwindowsysteminterface.h> -#include <qpa/qplatformscreen.h> -#include <QtCore/QThread> -#include <QtGui/QGuiApplication> - -QT_BEGIN_NAMESPACE - -QWinRTEventDispatcher::QWinRTEventDispatcher(QObject *parent) - : QEventDispatcherWinRT(parent) -{ -} - -bool QWinRTEventDispatcher::hasPendingEvents() -{ - return QEventDispatcherWinRT::hasPendingEvents() || QWindowSystemInterface::windowSystemEventsQueued(); -} - -bool QWinRTEventDispatcher::sendPostedEvents(QEventLoop::ProcessEventsFlags flags) -{ - bool didProcess = QEventDispatcherWinRT::sendPostedEvents(flags); - if (!(flags & QEventLoop::ExcludeUserInputEvents)) - didProcess |= QWindowSystemInterface::sendWindowSystemEvents(flags); - return didProcess; -} - -QT_END_NAMESPACE diff --git a/src/plugins/platforms/winrt/qwinrteventdispatcher.h b/src/plugins/platforms/winrt/qwinrteventdispatcher.h deleted file mode 100644 index 61c824f0a9..0000000000 --- a/src/plugins/platforms/winrt/qwinrteventdispatcher.h +++ /dev/null @@ -1,60 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTEVENTDISPATCHER_H -#define QWINRTEVENTDISPATCHER_H - -#include <QtCore/private/qeventdispatcher_winrt_p.h> - -QT_BEGIN_NAMESPACE - -class QWinRTEventDispatcher : public QEventDispatcherWinRT -{ - Q_OBJECT -public: - explicit QWinRTEventDispatcher(QObject *parent = nullptr); - -protected: - bool hasPendingEvents() override; - bool sendPostedEvents(QEventLoop::ProcessEventsFlags flags) override; -}; - -QT_END_NAMESPACE - -#endif // QWINRTEVENTDISPATCHER_H diff --git a/src/plugins/platforms/winrt/qwinrtfiledialoghelper.cpp b/src/plugins/platforms/winrt/qwinrtfiledialoghelper.cpp deleted file mode 100644 index fee8063f13..0000000000 --- a/src/plugins/platforms/winrt/qwinrtfiledialoghelper.cpp +++ /dev/null @@ -1,596 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwinrtfiledialoghelper.h" -#include "qwinrtfileengine.h" - -#include <QtCore/qcoreapplication.h> -#include <QtCore/QEventLoop> -#include <QtCore/QMap> -#include <QtCore/QVector> -#include <QtCore/qfunctions_winrt.h> -#include <private/qeventdispatcher_winrt_p.h> - -#include <functional> -#include <wrl.h> -#include <windows.foundation.h> -#include <windows.storage.pickers.h> -#include <Windows.Applicationmodel.Activation.h> - -using namespace Microsoft::WRL; -using namespace Microsoft::WRL::Wrappers; -using namespace ABI::Windows::ApplicationModel::Activation; -using namespace ABI::Windows::Foundation; -using namespace ABI::Windows::Foundation::Collections; -using namespace ABI::Windows::Storage; -using namespace ABI::Windows::Storage::Pickers; - -typedef IAsyncOperationCompletedHandler<StorageFile *> SingleFileHandler; -typedef IAsyncOperationCompletedHandler<IVectorView<StorageFile *> *> MultipleFileHandler; -typedef IAsyncOperationCompletedHandler<StorageFolder *> SingleFolderHandler; - -QT_BEGIN_NAMESPACE - -// Required for save file picker -class WindowsStringVector : public RuntimeClass<IVector<HSTRING>> -{ -public: - HRESULT __stdcall GetAt(quint32 index, HSTRING *item) - { - *item = impl.at(int(index)); - return S_OK; - } - HRESULT __stdcall get_Size(quint32 *size) - { - *size = quint32(impl.size()); - return S_OK; - } - HRESULT __stdcall GetView(IVectorView<HSTRING> **view) - { - *view = nullptr; - return E_NOTIMPL; - } - HRESULT __stdcall IndexOf(HSTRING value, quint32 *index, boolean *found) - { - *found = false; - for (int i = 0; i < impl.size(); ++i) { - qint32 result; - HRESULT hr = WindowsCompareStringOrdinal(impl.at(i), value, &result); - if (FAILED(hr)) - return hr; - if (result == 0) { - *index = quint32(i); - *found = true; - break; - } - } - return S_OK; - } - HRESULT __stdcall SetAt(quint32 index, HSTRING item) - { - HSTRING newItem; - HRESULT hr = WindowsDuplicateString(item, &newItem); - if (FAILED(hr)) - return hr; - impl[int(index)] = newItem; - return S_OK; - } - HRESULT __stdcall InsertAt(quint32 index, HSTRING item) - { - HSTRING newItem; - HRESULT hr = WindowsDuplicateString(item, &newItem); - if (FAILED(hr)) - return hr; - impl.insert(int(index), newItem); - return S_OK; - } - HRESULT __stdcall RemoveAt(quint32 index) - { - WindowsDeleteString(impl.takeAt(int(index))); - return S_OK; - } - HRESULT __stdcall Append(HSTRING item) - { - HSTRING newItem; - HRESULT hr = WindowsDuplicateString(item, &newItem); - if (FAILED(hr)) - return hr; - impl.append(newItem); - return S_OK; - } - HRESULT __stdcall RemoveAtEnd() - { - WindowsDeleteString(impl.takeLast()); - return S_OK; - } - HRESULT __stdcall Clear() - { - foreach (const HSTRING &item, impl) - WindowsDeleteString(item); - impl.clear(); - return S_OK; - } -private: - QVector<HSTRING> impl; -}; - -template<typename T> -static bool initializePicker(HSTRING runtimeId, T **picker, const QSharedPointer<QFileDialogOptions> &options) -{ - HRESULT hr; - - ComPtr<IInspectable> basePicker; - hr = RoActivateInstance(runtimeId, &basePicker); - RETURN_FALSE_IF_FAILED("Failed to instantiate file picker"); - hr = basePicker.Get()->QueryInterface(IID_PPV_ARGS(picker)); - RETURN_FALSE_IF_FAILED("Failed to cast file picker"); - - if (options->isLabelExplicitlySet(QFileDialogOptions::Accept)) { - const QString labelText = options->labelText(QFileDialogOptions::Accept); - HStringReference labelTextRef(reinterpret_cast<const wchar_t *>(labelText.utf16()), - uint(labelText.length())); - hr = (*picker)->put_CommitButtonText(labelTextRef.Get()); - RETURN_FALSE_IF_FAILED("Failed to set commit button text"); - } - - return true; -} - -template<typename T> -static bool initializeOpenPickerOptions(T *picker, const QSharedPointer<QFileDialogOptions> &options) -{ - HRESULT hr; - hr = picker->put_ViewMode(options->viewMode() == QFileDialogOptions::Detail - ? PickerViewMode_Thumbnail : PickerViewMode_List); - RETURN_FALSE_IF_FAILED("Failed to set picker view mode"); - - ComPtr<IVector<HSTRING>> filters; - hr = picker->get_FileTypeFilter(&filters); - RETURN_FALSE_IF_FAILED("Failed to get file type filters list"); - for (const QString &namedFilter : options->nameFilters()) { - for (const QString &filter : QPlatformFileDialogHelper::cleanFilterList(namedFilter)) { - // Remove leading star - const int offset = (filter.length() > 1 && filter.startsWith(QLatin1Char('*'))) ? 1 : 0; - HStringReference filterRef(reinterpret_cast<const wchar_t *>(filter.utf16() + offset), - uint(filter.length() - offset)); - hr = filters->Append(filterRef.Get()); - if (FAILED(hr)) { - qWarning("Failed to add named file filter \"%s\": %s", - qPrintable(filter), qPrintable(qt_error_string(hr))); - } - } - } - // The file dialog won't open with an empty list - add a default wildcard - quint32 size; - hr = filters->get_Size(&size); - RETURN_FALSE_IF_FAILED("Failed to get file type filters list size"); - if (!size) { - hr = filters->Append(HString::MakeReference(L"*").Get()); - RETURN_FALSE_IF_FAILED("Failed to add default wildcard to file type filters list"); - } - - return true; -} - -static bool pickFiles(IFileOpenPicker *picker, QWinRTFileDialogHelper *helper, bool singleFile) -{ - Q_ASSERT(picker); - Q_ASSERT(helper); - HRESULT hr; - hr = QEventDispatcherWinRT::runOnXamlThread([picker, helper, singleFile]() { - HRESULT hr; - if (singleFile) { - ComPtr<IAsyncOperation<StorageFile *>> op; - hr = picker->PickSingleFileAsync(&op); - RETURN_HR_IF_FAILED("Failed to open single file picker"); - hr = op->put_Completed(Callback<SingleFileHandler>(helper, &QWinRTFileDialogHelper::onSingleFilePicked).Get()); - RETURN_HR_IF_FAILED("Failed to attach file picker callback"); - } else { - ComPtr<IAsyncOperation<IVectorView<StorageFile *> *>> op; - hr = picker->PickMultipleFilesAsync(&op); - RETURN_HR_IF_FAILED("Failed to open multi file picker"); - hr = op->put_Completed(Callback<MultipleFileHandler>(helper, &QWinRTFileDialogHelper::onMultipleFilesPicked).Get()); - RETURN_HR_IF_FAILED("Failed to attach multi file callback"); - } - return S_OK; - }); - return SUCCEEDED(hr); -} - -static bool pickFolder(IFolderPicker *picker, QWinRTFileDialogHelper *helper) -{ - Q_ASSERT(picker); - Q_ASSERT(helper); - HRESULT hr; - hr = QEventDispatcherWinRT::runOnXamlThread([picker, helper]() { - HRESULT hr; - ComPtr<IAsyncOperation<StorageFolder *>> op; - hr = picker->PickSingleFolderAsync(&op); - RETURN_HR_IF_FAILED("Failed to open folder picker"); - hr = op->put_Completed(Callback<SingleFolderHandler>(helper, &QWinRTFileDialogHelper::onSingleFolderPicked).Get()); - RETURN_HR_IF_FAILED("Failed to attach folder picker callback"); - return S_OK; - }); - return SUCCEEDED(hr); -} - -static bool pickSaveFile(IFileSavePicker *picker, QWinRTFileDialogHelper *helper) -{ - Q_ASSERT(picker); - Q_ASSERT(helper); - HRESULT hr; - hr = QEventDispatcherWinRT::runOnXamlThread([picker, helper]() { - HRESULT hr; - ComPtr<IAsyncOperation<StorageFile *>> op; - hr = picker->PickSaveFileAsync(&op); - RETURN_HR_IF_FAILED("Failed to open save file picker"); - hr = op->put_Completed(Callback<SingleFileHandler>(helper, &QWinRTFileDialogHelper::onSingleFilePicked).Get()); - RETURN_HR_IF_FAILED("Failed to attach save file picker callback"); - return S_OK; - }); - return SUCCEEDED(hr); -} - -class QWinRTFileDialogHelperPrivate -{ -public: - bool shown; - QEventLoop loop; - - // Input - QUrl directory; - QUrl saveFileName; - QString selectedNameFilter; - - // Output - QList<QUrl> selectedFiles; -}; - -QWinRTFileDialogHelper::QWinRTFileDialogHelper() - : QPlatformFileDialogHelper(), d_ptr(new QWinRTFileDialogHelperPrivate) -{ - Q_D(QWinRTFileDialogHelper); - - d->shown = false; -} - -void QWinRTFileDialogHelper::exec() -{ - Q_D(QWinRTFileDialogHelper); - - if (!d->shown) - show(Qt::Dialog, Qt::ApplicationModal, nullptr); - d->loop.exec(); -} - -bool QWinRTFileDialogHelper::show(Qt::WindowFlags windowFlags, Qt::WindowModality windowModality, QWindow *parent) -{ - Q_UNUSED(windowFlags) - Q_UNUSED(windowModality) - Q_UNUSED(parent) - Q_D(QWinRTFileDialogHelper); - - HRESULT hr; - const QSharedPointer<QFileDialogOptions> dialogOptions = options(); - switch (dialogOptions->acceptMode()) { - default: - case QFileDialogOptions::AcceptOpen: { - switch (dialogOptions->fileMode()) { - case QFileDialogOptions::AnyFile: - case QFileDialogOptions::ExistingFile: - case QFileDialogOptions::ExistingFiles: { - ComPtr<IFileOpenPicker> picker; - if (!initializePicker(HString::MakeReference(RuntimeClass_Windows_Storage_Pickers_FileOpenPicker).Get(), - picker.GetAddressOf(), dialogOptions)) { - return false; - } - if (!initializeOpenPickerOptions(picker.Get(), dialogOptions)) - return false; - - if (!pickFiles(picker.Get(), this, dialogOptions->fileMode() == QFileDialogOptions::ExistingFile)) - return false; - - break; - } - case QFileDialogOptions::Directory: - case QFileDialogOptions::DirectoryOnly: { - ComPtr<IFolderPicker> picker; - if (!initializePicker(HString::MakeReference(RuntimeClass_Windows_Storage_Pickers_FolderPicker).Get(), - picker.GetAddressOf(), dialogOptions)) { - return false; - } - if (!initializeOpenPickerOptions(picker.Get(), dialogOptions)) - return false; - - if (!pickFolder(picker.Get(), this)) - return false; - - break; - } - } - break; - } - case QFileDialogOptions::AcceptSave: { - ComPtr<IFileSavePicker> picker; - if (!initializePicker(HString::MakeReference(RuntimeClass_Windows_Storage_Pickers_FileSavePicker).Get(), - picker.GetAddressOf(), dialogOptions)) { - return false; - } - - if (!dialogOptions->nameFilters().isEmpty()) { - ComPtr<IMap<HSTRING, IVector<HSTRING> *>> choices; - hr = picker->get_FileTypeChoices(&choices); - RETURN_FALSE_IF_FAILED("Failed to get file extension choices"); - const QStringList nameFilters = dialogOptions->nameFilters(); - for (const QString &namedFilter : nameFilters) { - ComPtr<IVector<HSTRING>> entry = Make<WindowsStringVector>(); - const QStringList cleanFilter = QPlatformFileDialogHelper::cleanFilterList(namedFilter); - for (const QString &filter : cleanFilter) { - // Remove leading star - const int starOffset = (filter.length() > 1 && filter.startsWith(QLatin1Char('*'))) ? 1 : 0; - HStringReference filterRef(reinterpret_cast<const wchar_t *>(filter.utf16() + starOffset), - uint(filter.length() - starOffset)); - hr = entry->Append(filterRef.Get()); - if (FAILED(hr)) { - qWarning("Failed to add named file filter \"%s\": %s", - qPrintable(filter), qPrintable(qt_error_string(hr))); - } - } - const int offset = namedFilter.indexOf(QLatin1String(" (")); - const QString filterTitle = namedFilter.mid(0, offset); - HStringReference namedFilterRef(reinterpret_cast<const wchar_t *>(filterTitle.utf16()), - uint(filterTitle.length())); - boolean replaced; - hr = choices->Insert(namedFilterRef.Get(), entry.Get(), &replaced); - // Only print a warning as * or *.* is not a valid choice on Windows 10 - // but used on a regular basis on all other platforms - if (FAILED(hr)) { - qWarning("Failed to insert file extension choice entry: %s: %s", - qPrintable(filterTitle), qPrintable(qt_error_string(hr))); - } - } - } - - QString suffix = dialogOptions->defaultSuffix(); - if (!suffix.isEmpty()) { - if (!suffix.startsWith(QLatin1Char('.'))) - suffix.prepend(QLatin1Char('.')); - HStringReference nativeSuffix(reinterpret_cast<const wchar_t *>(suffix.utf16()), - uint(suffix.length())); - hr = picker->put_DefaultFileExtension(nativeSuffix.Get()); - RETURN_FALSE_IF_FAILED_WITH_ARGS("Failed to set default file extension \"%s\"", qPrintable(suffix)); - } - - QString suggestedName = QFileInfo(d->saveFileName.toLocalFile()).fileName(); - if (suggestedName.isEmpty() && dialogOptions->initiallySelectedFiles().size() > 0) - suggestedName = QFileInfo(dialogOptions->initiallySelectedFiles().first().toLocalFile()) - .fileName(); - if (suggestedName.isEmpty()) { - const auto fileInfo = QFileInfo(dialogOptions->initialDirectory().toLocalFile()); - if (!fileInfo.isDir()) - suggestedName = fileInfo.fileName(); - } - if (!suggestedName.isEmpty()) { - HStringReference nativeSuggestedName(reinterpret_cast<const wchar_t *>(suggestedName.utf16()), - uint(suggestedName.length())); - hr = picker->put_SuggestedFileName(nativeSuggestedName.Get()); - RETURN_FALSE_IF_FAILED("Failed to set suggested file name"); - } - - if (!pickSaveFile(picker.Get(), this)) - return false; - - break; - } - } - - d->shown = true; - return true; -} - -void QWinRTFileDialogHelper::hide() -{ - Q_D(QWinRTFileDialogHelper); - - if (!d->shown) - return; - - d->shown = false; -} - -void QWinRTFileDialogHelper::setDirectory(const QUrl &directory) -{ - Q_D(QWinRTFileDialogHelper); - d->directory = directory; -} - -QUrl QWinRTFileDialogHelper::directory() const -{ - Q_D(const QWinRTFileDialogHelper); - return d->directory; -} - -void QWinRTFileDialogHelper::selectFile(const QUrl &saveFileName) -{ - Q_D(QWinRTFileDialogHelper); - d->saveFileName = saveFileName; -} - -QList<QUrl> QWinRTFileDialogHelper::selectedFiles() const -{ - Q_D(const QWinRTFileDialogHelper); - return d->selectedFiles; -} - -void QWinRTFileDialogHelper::selectNameFilter(const QString &selectedNameFilter) -{ - Q_D(QWinRTFileDialogHelper); - d->selectedNameFilter = selectedNameFilter; -} - -QString QWinRTFileDialogHelper::selectedNameFilter() const -{ - Q_D(const QWinRTFileDialogHelper); - return d->selectedNameFilter; -} - -HRESULT QWinRTFileDialogHelper::onSingleFilePicked(IAsyncOperation<StorageFile *> *args, AsyncStatus status) -{ - Q_D(QWinRTFileDialogHelper); - - QEventLoopLocker locker(&d->loop); - d->shown = false; - d->selectedFiles.clear(); - if (status == Canceled || status == Error) { - emit reject(); - return S_OK; - } - - HRESULT hr; - ComPtr<IStorageFile> file; - hr = args->GetResults(&file); - Q_ASSERT_SUCCEEDED(hr); - return onFilePicked(file.Get()); -} - -HRESULT QWinRTFileDialogHelper::onMultipleFilesPicked(IAsyncOperation<IVectorView<StorageFile *> *> *args, AsyncStatus status) -{ - Q_D(QWinRTFileDialogHelper); - - QEventLoopLocker locker(&d->loop); - d->shown = false; - d->selectedFiles.clear(); - if (status == Canceled || status == Error) { - emit reject(); - return S_OK; - } - - HRESULT hr; - ComPtr<IVectorView<StorageFile *>> fileList; - hr = args->GetResults(&fileList); - RETURN_HR_IF_FAILED("Failed to get file list"); - return onFilesPicked(fileList.Get()); -} - -HRESULT QWinRTFileDialogHelper::onSingleFolderPicked(IAsyncOperation<StorageFolder *> *args, AsyncStatus status) -{ - Q_D(QWinRTFileDialogHelper); - - QEventLoopLocker locker(&d->loop); - d->shown = false; - d->selectedFiles.clear(); - if (status == Canceled || status == Error) { - emit reject(); - return S_OK; - } - - HRESULT hr; - ComPtr<IStorageFolder> folder; - hr = args->GetResults(&folder); - Q_ASSERT_SUCCEEDED(hr); - return onFolderPicked(folder.Get()); -} - -HRESULT QWinRTFileDialogHelper::onFilesPicked(IVectorView<StorageFile *> *files) -{ - HRESULT hr; - quint32 size; - hr = files->get_Size(&size); - Q_ASSERT_SUCCEEDED(hr); - if (!size) { - emit reject(); - return S_OK; - } - - for (quint32 i = 0; i < size; ++i) { - ComPtr<IStorageFile> file; - hr = files->GetAt(i, &file); - Q_ASSERT_SUCCEEDED(hr); - appendFile(file.Get()); - } - - emit accept(); - return S_OK; -} - -HRESULT QWinRTFileDialogHelper::onFolderPicked(IStorageFolder *folder) -{ - if (!folder) { - emit reject(); - return S_OK; - } - - appendFile(folder); - emit accept(); - return S_OK; -} - -HRESULT QWinRTFileDialogHelper::onFilePicked(IStorageFile *file) -{ - if (!file) { - emit reject(); - return S_OK; - } - - appendFile(file); - emit accept(); - return S_OK; -} - -void QWinRTFileDialogHelper::appendFile(IInspectable *file) -{ - Q_D(QWinRTFileDialogHelper); - - HRESULT hr; - ComPtr<IStorageItem> item; - hr = file->QueryInterface(IID_PPV_ARGS(&item)); - Q_ASSERT_SUCCEEDED(hr); - - HString path; - hr = item->get_Path(path.GetAddressOf()); - Q_ASSERT_SUCCEEDED(hr); - - quint32 pathLen; - const wchar_t *pathStr = path.GetRawBuffer(&pathLen); - const QString filePath = QString::fromWCharArray(pathStr, pathLen); - QWinRTFileEngineHandler::registerFile(filePath, item.Get()); - d->selectedFiles.append(QUrl::fromLocalFile(filePath)); -} - -QT_END_NAMESPACE diff --git a/src/plugins/platforms/winrt/qwinrtfiledialoghelper.h b/src/plugins/platforms/winrt/qwinrtfiledialoghelper.h deleted file mode 100644 index 994d099dcf..0000000000 --- a/src/plugins/platforms/winrt/qwinrtfiledialoghelper.h +++ /dev/null @@ -1,107 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTFILEDIALOGHELPER_H -#define QWINRTFILEDIALOGHELPER_H - -#include <qpa/qplatformdialoghelper.h> -#include <QtCore/qt_windows.h> - -struct IInspectable; -namespace ABI { - namespace Windows { - namespace Storage { - class StorageFile; - class StorageFolder; - struct IStorageFile; - struct IStorageFolder; - } - namespace Foundation { - enum class AsyncStatus; - template <typename T> struct IAsyncOperation; - namespace Collections { - template <typename T> struct IVectorView; - } - } - } -} - -QT_BEGIN_NAMESPACE - -class QWinRTFileDialogHelperPrivate; -class QWinRTFileDialogHelper : public QPlatformFileDialogHelper -{ - Q_OBJECT -public: - explicit QWinRTFileDialogHelper(); - ~QWinRTFileDialogHelper() override = default; - - void exec() override; - bool show(Qt::WindowFlags, Qt::WindowModality, QWindow *) override; - void hide() override; - - bool defaultNameFilterDisables() const override { return false; } - void setDirectory(const QUrl &directory) override; - QUrl directory() const override; - void selectFile(const QUrl &saveFileName) override; - QList<QUrl> selectedFiles() const override; - void setFilter() override { } - void selectNameFilter(const QString &selectedNameFilter) override; - QString selectedNameFilter() const override; - - HRESULT onSingleFilePicked(ABI::Windows::Foundation::IAsyncOperation<ABI::Windows::Storage::StorageFile *> *, - ABI::Windows::Foundation::AsyncStatus); - HRESULT onMultipleFilesPicked(ABI::Windows::Foundation::IAsyncOperation<ABI::Windows::Foundation::Collections::IVectorView<ABI::Windows::Storage::StorageFile *> *> *, - ABI::Windows::Foundation::AsyncStatus); - HRESULT onSingleFolderPicked(ABI::Windows::Foundation::IAsyncOperation<ABI::Windows::Storage::StorageFolder *> *, - ABI::Windows::Foundation::AsyncStatus); - -private: - HRESULT onFilesPicked(ABI::Windows::Foundation::Collections::IVectorView<ABI::Windows::Storage::StorageFile *> *files); - HRESULT onFolderPicked(ABI::Windows::Storage::IStorageFolder *folder); - HRESULT onFilePicked(ABI::Windows::Storage::IStorageFile *file); - void appendFile(IInspectable *); - - QScopedPointer<QWinRTFileDialogHelperPrivate> d_ptr; - Q_DECLARE_PRIVATE(QWinRTFileDialogHelper) -}; - -QT_END_NAMESPACE - -#endif // QWINRTFILEDIALOGHELPER_H diff --git a/src/plugins/platforms/winrt/qwinrtfileengine.cpp b/src/plugins/platforms/winrt/qwinrtfileengine.cpp deleted file mode 100644 index 962e4ab938..0000000000 --- a/src/plugins/platforms/winrt/qwinrtfileengine.cpp +++ /dev/null @@ -1,554 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwinrtfileengine.h" - -#include <QtCore/QDateTime> -#include <QtCore/QCoreApplication> -#include <QtCore/QHash> -#include <QtCore/qfunctions_winrt.h> -#include <QtCore/private/qfsfileengine_p.h> - -#include <wrl.h> -#include <windows.storage.h> -#include <robuffer.h> - -using namespace Microsoft::WRL; -using namespace Microsoft::WRL::Wrappers; -using namespace ABI::Windows::Foundation; -using namespace ABI::Windows::Storage; -using namespace ABI::Windows::Storage::Streams; - -typedef IAsyncOperationCompletedHandler<IRandomAccessStream *> StreamCompletedHandler; -typedef IAsyncOperationWithProgressCompletedHandler<IBuffer *, UINT32> StreamReadCompletedHandler; - -QT_BEGIN_NAMESPACE - -#define RETURN_AND_SET_ERROR_IF_FAILED(error, ret) \ - setError(error, qt_error_string(hr)); \ - if (FAILED(hr)) \ - return ret; - -Q_GLOBAL_STATIC(QWinRTFileEngineHandler, handlerInstance) - -class QWinRTFileEngineHandlerPrivate -{ -public: - QHash<QString, ComPtr<IStorageItem>> files; -}; - -class QWinRTFileEnginePrivate -{ -public: - QWinRTFileEnginePrivate(const QString &fileName, IStorageItem *file) - : fileName(fileName), file(file), openMode(QIODevice::NotOpen) - { - HRESULT hr; - hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Storage_Streams_Buffer).Get(), - IID_PPV_ARGS(&bufferFactory)); - Q_ASSERT_SUCCEEDED(hr); - - lastSeparator = fileName.size() - 1; - for (int i = lastSeparator; i >= 0; --i) { - if (fileName.at(i).unicode() == '/' || fileName.at(i).unicode() == '\\') { - lastSeparator = i; - break; - } - } - - firstDot = fileName.size(); - for (int i = lastSeparator; i < fileName.size(); ++i) { - if (fileName.at(i).unicode() == '.') { - firstDot = i; - break; - } - } - } - - ComPtr<IBufferFactory> bufferFactory; - - QString fileName; - int lastSeparator; - int firstDot; - ComPtr<IStorageItem> file; - ComPtr<IRandomAccessStream> stream; - QIODevice::OpenMode openMode; - - qint64 pos; - -private: - QWinRTFileEngineHandler *q_ptr; - Q_DECLARE_PUBLIC(QWinRTFileEngineHandler) -}; - - -QWinRTFileEngineHandler::QWinRTFileEngineHandler() - : d_ptr(new QWinRTFileEngineHandlerPrivate) -{ -} - -void QWinRTFileEngineHandler::registerFile(const QString &fileName, IStorageItem *file) -{ - handlerInstance->d_func()->files.insert(QDir::cleanPath(fileName), file); -} - -IStorageItem *QWinRTFileEngineHandler::registeredFile(const QString &fileName) -{ - return handlerInstance->d_func()->files.value(fileName).Get(); -} - -QAbstractFileEngine *QWinRTFileEngineHandler::create(const QString &fileName) const -{ - Q_D(const QWinRTFileEngineHandler); - - QHash<QString, ComPtr<IStorageItem>>::const_iterator file = d->files.find(fileName); - if (file != d->files.end()) - return new QWinRTFileEngine(fileName, file.value().Get()); - - return nullptr; -} - -static HRESULT getDestinationFolder(const QString &fileName, const QString &newFileName, - IStorageItem *file, IStorageFolder **folder) -{ - HRESULT hr; - ComPtr<IAsyncOperation<StorageFolder *>> op; - QFileInfo newFileInfo(newFileName); - QFileInfo fileInfo(fileName); - if (fileInfo.dir() == newFileInfo.dir()) { - ComPtr<IStorageItem2> item; - hr = file->QueryInterface(IID_PPV_ARGS(&item)); - Q_ASSERT_SUCCEEDED(hr); - - hr = item->GetParentAsync(&op); - } else { - ComPtr<IStorageFolderStatics> folderFactory; - hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Storage_StorageFolder).Get(), - IID_PPV_ARGS(&folderFactory)); - Q_ASSERT_SUCCEEDED(hr); - - const QString newFilePath = QDir::toNativeSeparators(newFileInfo.absolutePath()); - HStringReference nativeNewFilePath(reinterpret_cast<LPCWSTR>(newFilePath.utf16()), - uint(newFilePath.length())); - hr = folderFactory->GetFolderFromPathAsync(nativeNewFilePath.Get(), &op); - } - if (FAILED(hr)) - return hr; - return QWinRTFunctions::await(op, folder); -} - -QWinRTFileEngine::QWinRTFileEngine(const QString &fileName, IStorageItem *file) - : d_ptr(new QWinRTFileEnginePrivate(fileName, file)) -{ -} - -bool QWinRTFileEngine::open(QIODevice::OpenMode openMode) -{ - Q_D(QWinRTFileEngine); - - FileAccessMode fileAccessMode = (openMode & QIODevice::WriteOnly) - ? FileAccessMode_ReadWrite : FileAccessMode_Read; - - HRESULT hr; - ComPtr<IStorageFile> file; - hr = d->file.As(&file); - RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::OpenError, false); - - ComPtr<IAsyncOperation<IRandomAccessStream *>> op; - hr = file->OpenAsync(fileAccessMode, &op); - RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::OpenError, false); - - hr = QWinRTFunctions::await(op, d->stream.GetAddressOf()); - RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::OpenError, false); - - const ProcessOpenModeResult res = processOpenModeFlags(openMode); - if (!res.ok) { - setError(QFileDevice::OpenError, res.error); - return false; - } - d->openMode = res.openMode; - if (d->openMode & QIODevice::Truncate) { - if (!setSize(0)) { - close(); - setError(QFileDevice::OpenError, QLatin1String("Could not truncate file")); - return false; - } - } - - return SUCCEEDED(hr); -} - -bool QWinRTFileEngine::close() -{ - Q_D(QWinRTFileEngine); - - if (!d->stream) - return false; - - ComPtr<IClosable> closable; - HRESULT hr = d->stream.As(&closable); - Q_ASSERT_SUCCEEDED(hr); - - hr = closable->Close(); - RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::UnspecifiedError, false); - d->stream.Reset(); - d->openMode = QIODevice::NotOpen; - return SUCCEEDED(hr); -} - -bool QWinRTFileEngine::flush() -{ - Q_D(QWinRTFileEngine); - - if (!d->stream) - return false; - - if (!(d->openMode & QIODevice::WriteOnly)) - return true; - - ComPtr<IOutputStream> stream; - HRESULT hr = d->stream.As(&stream); - RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::WriteError, false); - ComPtr<IAsyncOperation<bool>> flushOp; - hr = stream->FlushAsync(&flushOp); - RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::WriteError, false); - boolean flushed; - hr = QWinRTFunctions::await(flushOp, &flushed); - RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::WriteError, false); - - return true; -} - -qint64 QWinRTFileEngine::size() const -{ - Q_D(const QWinRTFileEngine); - - if (!d->stream) - return 0; - - UINT64 size; - HRESULT hr; - hr = d->stream->get_Size(&size); - RETURN_IF_FAILED("Failed to get file size", return 0); - - return qint64(size); -} - -bool QWinRTFileEngine::setSize(qint64 size) -{ - Q_D(QWinRTFileEngine); - if (!d->stream) { - setError(QFileDevice::ResizeError, QLatin1String("File must be open to be resized")); - return false; - } - - if (size < 0) { - setError(QFileDevice::ResizeError, QLatin1String("File size cannot be negative")); - return false; - } - - HRESULT hr = d->stream->put_Size(static_cast<quint64>(size)); - RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::ResizeError, false); - if (!flush()) { - setError(QFileDevice::ResizeError, QLatin1String("Could not flush file")); - return false; - } - - return true; -} - -qint64 QWinRTFileEngine::pos() const -{ - Q_D(const QWinRTFileEngine); - return d->pos; -} - -bool QWinRTFileEngine::seek(qint64 pos) -{ - Q_D(QWinRTFileEngine); - - if (!d->stream) - return false; - - HRESULT hr = d->stream->Seek(UINT64(pos)); - RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::PositionError, false); - d->pos = pos; - return SUCCEEDED(hr); -} - -bool QWinRTFileEngine::remove() -{ - Q_D(QWinRTFileEngine); - - ComPtr<IAsyncAction> op; - HRESULT hr = d->file->DeleteAsync(StorageDeleteOption_Default, &op); - RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::RemoveError, false); - - hr = QWinRTFunctions::await(op); - RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::RemoveError, false); - return SUCCEEDED(hr); -} - -bool QWinRTFileEngine::copy(const QString &newName) -{ - Q_D(QWinRTFileEngine); - - HRESULT hr; - ComPtr<IStorageFolder> destinationFolder; - hr = getDestinationFolder(d->fileName, newName, d->file.Get(), destinationFolder.GetAddressOf()); - RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::CopyError, false); - - ComPtr<IStorageFile> file; - hr = d->file.As(&file); - RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::CopyError, false); - - const QString destinationName = QFileInfo(newName).fileName(); - HStringReference nativeDestinationName(reinterpret_cast<LPCWSTR>(destinationName.utf16()), - uint(destinationName.length())); - ComPtr<IAsyncOperation<StorageFile *>> op; - hr = file->CopyOverloadDefaultOptions(destinationFolder.Get(), nativeDestinationName.Get(), &op); - RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::CopyError, false); - - ComPtr<IStorageFile> newFile; - hr = QWinRTFunctions::await(op, newFile.GetAddressOf()); - RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::CopyError, false); - return SUCCEEDED(hr); -} - -bool QWinRTFileEngine::rename(const QString &newName) -{ - Q_D(QWinRTFileEngine); - - HRESULT hr; - ComPtr<IStorageFolder> destinationFolder; - hr = getDestinationFolder(d->fileName, newName, d->file.Get(), destinationFolder.GetAddressOf()); - RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::RenameError, false); - - const QString destinationName = QFileInfo(newName).fileName(); - HStringReference nativeDestinationName(reinterpret_cast<LPCWSTR>(destinationName.utf16()), - uint(destinationName.length())); - ComPtr<IAsyncAction> op; - hr = d->file->RenameAsyncOverloadDefaultOptions(nativeDestinationName.Get(), &op); - RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::RenameError, false); - return SUCCEEDED(hr); -} - -bool QWinRTFileEngine::renameOverwrite(const QString &newName) -{ - Q_D(QWinRTFileEngine); - - HRESULT hr; - ComPtr<IStorageFolder> destinationFolder; - hr = getDestinationFolder(d->fileName, newName, d->file.Get(), destinationFolder.GetAddressOf()); - RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::RenameError, false); - - const QString destinationName = QFileInfo(newName).fileName(); - HStringReference nativeDestinationName(reinterpret_cast<LPCWSTR>(destinationName.utf16()), - uint(destinationName.length())); - ComPtr<IAsyncAction> op; - hr = d->file->RenameAsync(nativeDestinationName.Get(), NameCollisionOption_ReplaceExisting, &op); - RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::RenameError, false); - return SUCCEEDED(hr); -} - -QAbstractFileEngine::FileFlags QWinRTFileEngine::fileFlags(FileFlags type) const -{ - Q_D(const QWinRTFileEngine); - - FileFlags flags = ExistsFlag|ReadOwnerPerm|ReadUserPerm|WriteOwnerPerm|WriteUserPerm; - - HRESULT hr; - FileAttributes attributes; - hr = d->file->get_Attributes(&attributes); - RETURN_IF_FAILED("Failed to get file attributes", return flags); - if (attributes & FileAttributes_ReadOnly) - flags ^= WriteUserPerm; - if (attributes & FileAttributes_Directory) - flags |= DirectoryType; - else - flags |= FileType; - - return type & flags; -} - -bool QWinRTFileEngine::setPermissions(uint perms) -{ - Q_UNUSED(perms); - Q_UNIMPLEMENTED(); - return false; -} - -QString QWinRTFileEngine::fileName(FileName type) const -{ - Q_D(const QWinRTFileEngine); - - switch (type) { - default: - case DefaultName: - case AbsoluteName: - case CanonicalName: - break; - case BaseName: - return d->lastSeparator < 0 - ? d->fileName : d->fileName.mid(d->lastSeparator, d->firstDot - d->lastSeparator); - case PathName: - case AbsolutePathName: - case CanonicalPathName: - return d->fileName.mid(0, d->lastSeparator); - case LinkName: - case BundleName: - return QString(); - } - return d->fileName; -} - -QDateTime QWinRTFileEngine::fileTime(FileTime type) const -{ - Q_D(const QWinRTFileEngine); - - HRESULT hr; - DateTime dateTime = { 0 }; - switch (type) { - case BirthTime: - hr = d->file->get_DateCreated(&dateTime); - RETURN_IF_FAILED("Failed to get file creation time", return QDateTime()); - break; - case MetadataChangeTime: - case ModificationTime: - case AccessTime: { - ComPtr<IAsyncOperation<FileProperties::BasicProperties *>> op; - hr = d->file->GetBasicPropertiesAsync(&op); - RETURN_IF_FAILED("Failed to initiate file properties", return QDateTime()); - ComPtr<FileProperties::IBasicProperties> properties; - hr = QWinRTFunctions::await(op, properties.GetAddressOf()); - RETURN_IF_FAILED("Failed to get file properties", return QDateTime()); - hr = properties->get_DateModified(&dateTime); - RETURN_IF_FAILED("Failed to get file date", return QDateTime()); - } - break; - } - - SYSTEMTIME systemTime; - FileTimeToSystemTime((const FILETIME *)&dateTime, &systemTime); - QDate date(systemTime.wYear, systemTime.wMonth, systemTime.wDay); - QTime time(systemTime.wHour, systemTime.wMinute, systemTime.wSecond, systemTime.wMilliseconds); - return QDateTime(date, time); -} - -qint64 QWinRTFileEngine::read(char *data, qint64 maxlen) -{ - Q_D(QWinRTFileEngine); - - if (!d->stream) - return -1; - - ComPtr<IInputStream> stream; - HRESULT hr = d->stream.As(&stream); - RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::ReadError, -1); - - UINT32 length = UINT32(qBound(quint64(0), quint64(maxlen), quint64(UINT32_MAX))); - ComPtr<IBuffer> buffer; - hr = d->bufferFactory->Create(length, &buffer); - RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::ReadError, -1); - - ComPtr<IAsyncOperationWithProgress<IBuffer *, UINT32>> op; - hr = stream->ReadAsync(buffer.Get(), length, InputStreamOptions_None, &op); - RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::ReadError, -1); - - // Quoting MSDN IInputStream::ReadAsync() documentation: - // "Depending on the implementation, the data that's read might be placed - // into the input buffer, or it might be returned in a different buffer." - // Using GetAddressOf can cause ref counting errors leaking the original - // buffer. - ComPtr<IBuffer> effectiveBuffer; - hr = QWinRTFunctions::await(op, effectiveBuffer.GetAddressOf()); - RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::ReadError, -1); - - hr = effectiveBuffer->get_Length(&length); - RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::ReadError, -1); - - ComPtr<Windows::Storage::Streams::IBufferByteAccess> byteArrayAccess; - hr = effectiveBuffer.As(&byteArrayAccess); - RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::ReadError, -1); - - byte *bytes; - hr = byteArrayAccess->Buffer(&bytes); - RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::ReadError, -1); - memcpy(data, bytes, length); - return qint64(length); -} - -qint64 QWinRTFileEngine::write(const char *data, qint64 maxlen) -{ - Q_D(QWinRTFileEngine); - - if (!d->stream) - return -1; - - ComPtr<IOutputStream> stream; - HRESULT hr = d->stream.As(&stream); - RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::WriteError, -1); - - UINT32 length = UINT32(qBound(quint64(0), quint64(maxlen), quint64(UINT_MAX))); - ComPtr<IBuffer> buffer; - hr = d->bufferFactory->Create(length, &buffer); - RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::WriteError, -1); - hr = buffer->put_Length(length); - RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::WriteError, -1); - - ComPtr<Windows::Storage::Streams::IBufferByteAccess> byteArrayAccess; - hr = buffer.As(&byteArrayAccess); - RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::WriteError, -1); - - byte *bytes; - hr = byteArrayAccess->Buffer(&bytes); - RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::WriteError, -1); - memcpy(bytes, data, length); - - ComPtr<IAsyncOperationWithProgress<UINT32, UINT32>> op; - hr = stream->WriteAsync(buffer.Get(), &op); - RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::WriteError, -1); - - hr = QWinRTFunctions::await(op, &length); - RETURN_AND_SET_ERROR_IF_FAILED(QFileDevice::WriteError, -1); - - return qint64(length); -} - -QT_END_NAMESPACE diff --git a/src/plugins/platforms/winrt/qwinrtfileengine.h b/src/plugins/platforms/winrt/qwinrtfileengine.h deleted file mode 100644 index 453565a95a..0000000000 --- a/src/plugins/platforms/winrt/qwinrtfileengine.h +++ /dev/null @@ -1,104 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTFILEENGINE_H -#define QWINRTFILEENGINE_H - -#include <private/qabstractfileengine_p.h> - -namespace ABI { - namespace Windows { - namespace Storage { - struct IStorageItem; - } - } -} - -QT_BEGIN_NAMESPACE - -class QWinRTFileEngineHandlerPrivate; -class QWinRTFileEngineHandler : public QAbstractFileEngineHandler -{ -public: - QWinRTFileEngineHandler(); - ~QWinRTFileEngineHandler() override = default; - QAbstractFileEngine *create(const QString &fileName) const override; - - static void registerFile(const QString &fileName, ABI::Windows::Storage::IStorageItem *file); - static ABI::Windows::Storage::IStorageItem *registeredFile(const QString &fileName); - -private: - QScopedPointer<QWinRTFileEngineHandlerPrivate> d_ptr; - Q_DECLARE_PRIVATE(QWinRTFileEngineHandler) -}; - -class QWinRTFileEnginePrivate; -class QWinRTFileEngine : public QAbstractFileEngine -{ -public: - QWinRTFileEngine(const QString &fileName, ABI::Windows::Storage::IStorageItem *file); - ~QWinRTFileEngine() override = default; - - bool open(QIODevice::OpenMode openMode) override; - bool close() override; - bool flush() override; - qint64 size() const override; - bool setSize(qint64 size) override; - qint64 pos() const override; - bool seek(qint64 pos) override; - bool remove() override; - bool copy(const QString &newName) override; - bool rename(const QString &newName) override; - bool renameOverwrite(const QString &newName) override; - FileFlags fileFlags(FileFlags type=FileInfoAll) const override; - bool setPermissions(uint perms) override; - QString fileName(FileName type=DefaultName) const override; - QDateTime fileTime(FileTime type) const override; - - qint64 read(char *data, qint64 maxlen) override; - qint64 write(const char *data, qint64 len) override; - -private: - QScopedPointer<QWinRTFileEnginePrivate> d_ptr; - Q_DECLARE_PRIVATE(QWinRTFileEngine) -}; - -QT_END_NAMESPACE - -#endif // QWINRTFILEENGINE_H diff --git a/src/plugins/platforms/winrt/qwinrtinputcontext.cpp b/src/plugins/platforms/winrt/qwinrtinputcontext.cpp deleted file mode 100644 index 5ae94ba613..0000000000 --- a/src/plugins/platforms/winrt/qwinrtinputcontext.cpp +++ /dev/null @@ -1,222 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwinrtinputcontext.h" -#include "qwinrtscreen.h" -#include <QtGui/QGuiApplication> -#include <QtGui/QWindow> -#include <private/qeventdispatcher_winrt_p.h> - -#include <functional> -#include <wrl.h> -#include <roapi.h> -#include <windows.ui.viewmanagement.h> -#include <windows.ui.core.h> -using namespace Microsoft::WRL; -using namespace Microsoft::WRL::Wrappers; -using namespace ABI::Windows::Foundation; -using namespace ABI::Windows::UI::ViewManagement; -using namespace ABI::Windows::UI::Core; - -typedef ITypedEventHandler<InputPane*, InputPaneVisibilityEventArgs*> InputPaneVisibilityHandler; - -QT_BEGIN_NAMESPACE - -Q_LOGGING_CATEGORY(lcQpaInputMethods, "qt.qpa.input.methods") - -inline QRectF getInputPaneRect(ComPtr<IInputPane> pane, qreal scaleFactor) -{ - Rect rect; - pane->get_OccludedRect(&rect); - return QRectF(qRound(qreal(rect.X) * scaleFactor), qRound(qreal(rect.Y) * scaleFactor), - qRound(qreal(rect.Width) * scaleFactor), qRound(qreal(rect.Height) * scaleFactor)); -} - -/*! - \class QWinRTInputContext - \brief Manages Input Method visibility - \internal - \ingroup qt-qpa-winrt - - Listens to the native virtual keyboard for hide/show events and provides - hints to the OS for showing/hiding. On WinRT, showInputPanel()/hideInputPanel() - have no effect because WinRT dictates that keyboard presence is user-driven: - (http://msdn.microsoft.com/en-us/library/windows/apps/hh465404.aspx) - Windows Phone, however, supports direct hiding/showing of the keyboard. -*/ - -QWinRTInputContext::QWinRTInputContext(QWinRTScreen *screen) - : m_screen(screen) -{ - qCDebug(lcQpaInputMethods) << __FUNCTION__ << screen; - - QEventDispatcherWinRT::runOnXamlThread([this]() { - ComPtr<IInputPaneStatics> statics; - if (FAILED(GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_UI_ViewManagement_InputPane).Get(), - &statics))) { - qWarning("failed to retrieve input pane statics."); - return S_OK; - } - - ComPtr<IInputPane> inputPane; - statics->GetForCurrentView(&inputPane); - if (inputPane) { - EventRegistrationToken showToken, hideToken; - inputPane->add_Showing(Callback<InputPaneVisibilityHandler>( - this, &QWinRTInputContext::onShowing).Get(), &showToken); - inputPane->add_Hiding(Callback<InputPaneVisibilityHandler>( - this, &QWinRTInputContext::onHiding).Get(), &hideToken); - - m_keyboardRect = getInputPaneRect(inputPane, m_screen->scaleFactor()); - m_isInputPanelVisible = !m_keyboardRect.isEmpty(); - } else { - qWarning("failed to retrieve InputPane."); - } - return S_OK; - }); - - connect(QGuiApplication::inputMethod(), &QInputMethod::cursorRectangleChanged, - this, &QWinRTInputContext::updateScreenCursorRect); -} - -QRectF QWinRTInputContext::keyboardRect() const -{ - return m_keyboardRect; -} - -bool QWinRTInputContext::isInputPanelVisible() const -{ - return m_isInputPanelVisible; -} - -void QWinRTInputContext::updateScreenCursorRect() -{ - m_screen->setCursorRect(QGuiApplication::inputMethod()->cursorRectangle()); -} - -HRESULT QWinRTInputContext::onShowing(IInputPane *pane, IInputPaneVisibilityEventArgs *) -{ - qCDebug(lcQpaInputMethods) << __FUNCTION__ << pane; - m_isInputPanelVisible = true; - emitInputPanelVisibleChanged(); - return handleVisibilityChange(pane); -} - -HRESULT QWinRTInputContext::onHiding(IInputPane *pane, IInputPaneVisibilityEventArgs *) -{ - qCDebug(lcQpaInputMethods) << __FUNCTION__ << pane; - m_isInputPanelVisible = false; - emitInputPanelVisibleChanged(); - return handleVisibilityChange(pane); -} - -HRESULT QWinRTInputContext::handleVisibilityChange(IInputPane *pane) -{ - qCDebug(lcQpaInputMethods) << __FUNCTION__ << pane; - const QRectF keyboardRect = getInputPaneRect(pane, m_screen->scaleFactor()); - if (m_keyboardRect != keyboardRect) { - m_keyboardRect = keyboardRect; - m_screen->setKeyboardRect(m_keyboardRect); - emitKeyboardRectChanged(); - } - return S_OK; -} - -static HRESULT getInputPane(ComPtr<IInputPane2> *inputPane2) -{ - ComPtr<IInputPaneStatics> factory; - HRESULT hr = GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_UI_ViewManagement_InputPane).Get(), - &factory); - if (FAILED(hr)) { - qErrnoWarning(hr, "Failed to get input pane factory."); - return hr; - } - - ComPtr<IInputPane> inputPane; - hr = factory->GetForCurrentView(&inputPane); - if (FAILED(hr)) { - qErrnoWarning(hr, "Failed to get input pane."); - return hr; - } - - hr = inputPane.As(inputPane2); - if (FAILED(hr)) { - qErrnoWarning(hr, "Failed to get extended input pane."); - return hr; - } - return hr; -} - -void QWinRTInputContext::showInputPanel() -{ - qCDebug(lcQpaInputMethods) << __FUNCTION__; - - QEventDispatcherWinRT::runOnXamlThread([&]() { - ComPtr<IInputPane2> inputPane; - HRESULT hr = getInputPane(&inputPane); - if (FAILED(hr)) - return S_OK; - boolean success; - hr = inputPane->TryShow(&success); - if (FAILED(hr) || !success) - qErrnoWarning(hr, "Failed to show input panel."); - return S_OK; - }); -} - -void QWinRTInputContext::hideInputPanel() -{ - qCDebug(lcQpaInputMethods) << __FUNCTION__; - if (!m_isInputPanelVisible) - return; - - QEventDispatcherWinRT::runOnXamlThread([&]() { - ComPtr<IInputPane2> inputPane; - HRESULT hr = getInputPane(&inputPane); - if (FAILED(hr)) - return S_OK; - boolean success; - hr = inputPane->TryHide(&success); - if (FAILED(hr) || !success) - qErrnoWarning(hr, "Failed to hide input panel."); - return S_OK; - }); -} - -QT_END_NAMESPACE diff --git a/src/plugins/platforms/winrt/qwinrtinputcontext.h b/src/plugins/platforms/winrt/qwinrtinputcontext.h deleted file mode 100644 index 59db90231f..0000000000 --- a/src/plugins/platforms/winrt/qwinrtinputcontext.h +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTINPUTCONTEXT_H -#define QWINRTINPUTCONTEXT_H - -#include <qpa/qplatforminputcontext.h> -#include <QtCore/QRectF> -#include <QtCore/QLoggingCategory> - -#include <wrl.h> - -namespace ABI { - namespace Windows { - namespace UI { - namespace Core { - struct ICoreWindow; - } - namespace ViewManagement { - struct IInputPane; - struct IInputPaneVisibilityEventArgs; - } - } - } -} - -QT_BEGIN_NAMESPACE - -Q_DECLARE_LOGGING_CATEGORY(lcQpaInputMethods) - -class QWinRTScreen; -class QWinRTInputContext : public QPlatformInputContext -{ -public: - explicit QWinRTInputContext(QWinRTScreen *); - - QRectF keyboardRect() const override; - - bool isInputPanelVisible() const override; - - void showInputPanel() override; - void hideInputPanel() override; - -private slots: - void updateScreenCursorRect(); - -private: - HRESULT onShowing(ABI::Windows::UI::ViewManagement::IInputPane *, - ABI::Windows::UI::ViewManagement::IInputPaneVisibilityEventArgs *); - HRESULT onHiding(ABI::Windows::UI::ViewManagement::IInputPane *, - ABI::Windows::UI::ViewManagement::IInputPaneVisibilityEventArgs *); - - HRESULT handleVisibilityChange(ABI::Windows::UI::ViewManagement::IInputPane *); - - QWinRTScreen *m_screen; - QRectF m_keyboardRect; - QRectF m_cursorRect; - bool m_isInputPanelVisible; -}; - -QT_END_NAMESPACE - -#endif // QWINRTINPUTCONTEXT_H diff --git a/src/plugins/platforms/winrt/qwinrtintegration.cpp b/src/plugins/platforms/winrt/qwinrtintegration.cpp deleted file mode 100644 index 0d87832176..0000000000 --- a/src/plugins/platforms/winrt/qwinrtintegration.cpp +++ /dev/null @@ -1,313 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwinrtintegration.h" -#include "qwinrtwindow.h" -#include "qwinrteventdispatcher.h" -#include "qwinrtbackingstore.h" -#include "qwinrtscreen.h" -#include "qwinrtinputcontext.h" -#include "qwinrtservices.h" -#include "qwinrteglcontext.h" -#include "qwinrttheme.h" -#include "qwinrtclipboard.h" -#if QT_CONFIG(draganddrop) -#include "qwinrtdrag.h" -#endif -#if QT_CONFIG(accessibility) -# include "uiautomation/qwinrtuiaaccessibility.h" -#endif -#if QT_CONFIG(opengl) -#include <QtOpenGL/qpa/qplatformbackingstoreopenglsupport.h> -#endif - -#include <QtGui/QOffscreenSurface> -#include <QtGui/QOpenGLContext> -#include <QtGui/QSurface> - -#include <QtFontDatabaseSupport/private/qwinrtfontdatabase_p.h> -#include <QtEglSupport/private/qeglpbuffer_p.h> -#include <qpa/qwindowsysteminterface.h> -#include <qpa/qplatformwindow.h> -#include <qpa/qplatformoffscreensurface.h> - -#include <qfunctions_winrt.h> - -#include <functional> -#include <wrl.h> -#include <windows.ui.xaml.h> -#include <windows.applicationmodel.h> -#include <windows.applicationmodel.core.h> -#include <windows.ui.core.h> -#include <windows.ui.viewmanagement.h> -#include <windows.graphics.display.h> - -using namespace Microsoft::WRL; -using namespace Microsoft::WRL::Wrappers; -using namespace ABI::Windows::Foundation; -using namespace ABI::Windows::ApplicationModel; -using namespace ABI::Windows::ApplicationModel::Core; -using namespace ABI::Windows::UI; -using namespace ABI::Windows::UI::Core; -using namespace ABI::Windows::UI::ViewManagement; -using namespace ABI::Windows::Graphics::Display; -using namespace ABI::Windows::ApplicationModel::Core; - -typedef IEventHandler<IInspectable *> ResumeHandler; -typedef IEventHandler<SuspendingEventArgs *> SuspendHandler; - -QT_BEGIN_NAMESPACE - -typedef HRESULT (__stdcall ICoreApplication::*CoreApplicationCallbackRemover)(EventRegistrationToken); -size_t qHash(CoreApplicationCallbackRemover key) { void *ptr = *(void **)(&key); return qHash(ptr); } - -class QWinRTIntegrationPrivate -{ -public: - QPlatformFontDatabase *fontDatabase; - QPlatformServices *platformServices; - QPlatformClipboard *clipboard; - QWinRTScreen *mainScreen; - QScopedPointer<QWinRTInputContext> inputContext; -#if QT_CONFIG(accessibility) - QWinRTUiaAccessibility *accessibility; -#endif - - ComPtr<ICoreApplication> application; - QHash<CoreApplicationCallbackRemover, EventRegistrationToken> applicationTokens; -}; - -QWinRTIntegration::QWinRTIntegration() : d_ptr(new QWinRTIntegrationPrivate) -{ - Q_D(QWinRTIntegration); - - d->fontDatabase = new QWinRTFontDatabase; - - HRESULT hr; - hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_ApplicationModel_Core_CoreApplication).Get(), - IID_PPV_ARGS(&d->application)); - Q_ASSERT_SUCCEEDED(hr); - hr = d->application->add_Suspending(Callback<SuspendHandler>(this, &QWinRTIntegration::onSuspended).Get(), - &d->applicationTokens[&ICoreApplication::remove_Suspending]); - Q_ASSERT_SUCCEEDED(hr); - hr = d->application->add_Resuming(Callback<ResumeHandler>(this, &QWinRTIntegration::onResume).Get(), - &d->applicationTokens[&ICoreApplication::remove_Resuming]); - Q_ASSERT_SUCCEEDED(hr); - - QEventDispatcherWinRT::runOnXamlThread([d]() { - d->mainScreen = new QWinRTScreen; - return S_OK; - }); - d->inputContext.reset(new QWinRTInputContext(d->mainScreen)); - - QWindowSystemInterface::handleScreenAdded(d->mainScreen); - d->platformServices = new QWinRTServices; - d->clipboard = new QWinRTClipboard; -#if QT_CONFIG(accessibility) - d->accessibility = new QWinRTUiaAccessibility; -#endif -} - -QWinRTIntegration::~QWinRTIntegration() -{ - Q_D(QWinRTIntegration); - HRESULT hr; - - // Do not execute this on Windows Phone as the application is already - // shutting down and trying to unregister suspending/resume handler will - // cause exceptions and assert in debug mode - for (QHash<CoreApplicationCallbackRemover, EventRegistrationToken>::const_iterator i = d->applicationTokens.begin(); i != d->applicationTokens.end(); ++i) { - hr = (d->application.Get()->*i.key())(i.value()); - Q_ASSERT_SUCCEEDED(hr); - } - - QWindowSystemInterface::handleScreenRemoved(d->mainScreen); - Windows::Foundation::Uninitialize(); -} - -bool QWinRTIntegration::succeeded() const -{ - Q_D(const QWinRTIntegration); - return d->mainScreen; -} - -QAbstractEventDispatcher *QWinRTIntegration::createEventDispatcher() const -{ - return new QWinRTEventDispatcher; -} - -void QWinRTIntegration::initialize() -{ - Q_D(const QWinRTIntegration); - QEventDispatcherWinRT::runOnXamlThread([d]() { - d->mainScreen->initialize(); - return S_OK; - }); -} - -bool QWinRTIntegration::hasCapability(QPlatformIntegration::Capability cap) const -{ - switch (cap) { - case ThreadedPixmaps: - case OpenGL: - case ApplicationState: - case NonFullScreenWindows: - case MultipleWindows: - case RasterGLSurface: - return true; - default: - return QPlatformIntegration::hasCapability(cap); - } -} - -QVariant QWinRTIntegration::styleHint(StyleHint hint) const -{ - return QWinRTTheme::styleHint(hint); -} - -QPlatformWindow *QWinRTIntegration::createPlatformWindow(QWindow *window) const -{ - return new QWinRTWindow(window); -} - -QPlatformBackingStore *QWinRTIntegration::createPlatformBackingStore(QWindow *window) const -{ - return new QWinRTBackingStore(window); -} - -QPlatformOpenGLContext *QWinRTIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const -{ - return new QWinRTEGLContext(context); -} - -QPlatformFontDatabase *QWinRTIntegration::fontDatabase() const -{ - Q_D(const QWinRTIntegration); - return d->fontDatabase; -} - -QPlatformInputContext *QWinRTIntegration::inputContext() const -{ - Q_D(const QWinRTIntegration); - return d->inputContext.data(); -} - -QPlatformServices *QWinRTIntegration::services() const -{ - Q_D(const QWinRTIntegration); - return d->platformServices; -} - -QPlatformClipboard *QWinRTIntegration::clipboard() const -{ - Q_D(const QWinRTIntegration); - return d->clipboard; -} - -#if QT_CONFIG(draganddrop) -QPlatformDrag *QWinRTIntegration::drag() const -{ - return QWinRTDrag::instance(); -} -#endif // QT_CONFIG(draganddrop) - -#if QT_CONFIG(accessibility) -QPlatformAccessibility *QWinRTIntegration::accessibility() const -{ - Q_D(const QWinRTIntegration); - return d->accessibility; -} -#endif // QT_CONFIG(accessibility) - -Qt::KeyboardModifiers QWinRTIntegration::queryKeyboardModifiers() const -{ - Q_D(const QWinRTIntegration); - return d->mainScreen->keyboardModifiers(); -} - -QStringList QWinRTIntegration::themeNames() const -{ - return QStringList(QLatin1String("winrt")); -} - -QPlatformTheme *QWinRTIntegration::createPlatformTheme(const QString &name) const -{ - if (name == QLatin1String("winrt")) - return new QWinRTTheme(); - - return 0; -} - -// System-level integration points - -HRESULT QWinRTIntegration::onSuspended(IInspectable *, ISuspendingEventArgs *) -{ - QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationSuspended); - QWindowSystemInterface::flushWindowSystemEvents(); - return S_OK; -} - -HRESULT QWinRTIntegration::onResume(IInspectable *, IInspectable *) -{ - // First the system invokes onResume and then changes - // the visibility of the screen to be active. - QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationHidden); - return S_OK; -} - -QPlatformOffscreenSurface *QWinRTIntegration::createPlatformOffscreenSurface(QOffscreenSurface *surface) const -{ - QEGLPbuffer *pbuffer = nullptr; - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([&pbuffer, surface]() { - pbuffer = new QEGLPbuffer(QWinRTEGLContext::display(), surface->requestedFormat(), surface); - return S_OK; - }); - if (hr == UI_E_WINDOW_CLOSED) { - // This is only used for shutdown of applications. - // In case we do not return an empty surface the scenegraph will try - // to create a new native window during application exit causing crashes - // or assertions. - return new QPlatformOffscreenSurface(surface); - } - - return pbuffer; -} - - -QT_END_NAMESPACE diff --git a/src/plugins/platforms/winrt/qwinrtintegration.h b/src/plugins/platforms/winrt/qwinrtintegration.h deleted file mode 100644 index e944ed5d79..0000000000 --- a/src/plugins/platforms/winrt/qwinrtintegration.h +++ /dev/null @@ -1,113 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTINTEGRATION_H -#define QWINRTINTEGRATION_H - -#include <qpa/qplatformintegration.h> - -namespace ABI { - namespace Windows { - namespace ApplicationModel { - struct ISuspendingEventArgs; - } - namespace Foundation { - struct IAsyncAction; - } - } -} -struct IAsyncInfo; -struct IInspectable; - -QT_BEGIN_NAMESPACE - -class QAbstractEventDispatcher; - -class QWinRTIntegrationPrivate; -class QWinRTIntegration : public QPlatformIntegration -{ -private: - explicit QWinRTIntegration(); -public: - ~QWinRTIntegration() override; - - static QWinRTIntegration *create() - { - QScopedPointer<QWinRTIntegration> integration(new QWinRTIntegration); - return integration->succeeded() ? integration.take() : nullptr; - } - - bool succeeded() const; - - bool hasCapability(QPlatformIntegration::Capability cap) const override; - QVariant styleHint(StyleHint hint) const override; - - QPlatformWindow *createPlatformWindow(QWindow *window) const override; - QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const override; - QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const override; - QAbstractEventDispatcher *createEventDispatcher() const override; - void initialize() override; - QPlatformFontDatabase *fontDatabase() const override; - QPlatformInputContext *inputContext() const override; - QPlatformServices *services() const override; - QPlatformClipboard *clipboard() const override; -#if QT_CONFIG(draganddrop) - QPlatformDrag *drag() const override; -#endif -#if QT_CONFIG(accessibility) - QPlatformAccessibility *accessibility() const override; -#endif - - Qt::KeyboardModifiers queryKeyboardModifiers() const override; - - QStringList themeNames() const override; - QPlatformTheme *createPlatformTheme(const QString &name) const override; - - QPlatformOffscreenSurface *createPlatformOffscreenSurface(QOffscreenSurface *surface) const override; -private: - HRESULT onSuspended(IInspectable *, ABI::Windows::ApplicationModel::ISuspendingEventArgs *); - HRESULT onResume(IInspectable *, IInspectable *); - - QScopedPointer<QWinRTIntegrationPrivate> d_ptr; - Q_DECLARE_PRIVATE(QWinRTIntegration) -}; - -QT_END_NAMESPACE - -#endif // QWINRTINTEGRATION_H diff --git a/src/plugins/platforms/winrt/qwinrtmessagedialoghelper.cpp b/src/plugins/platforms/winrt/qwinrtmessagedialoghelper.cpp deleted file mode 100644 index 7016b47f7e..0000000000 --- a/src/plugins/platforms/winrt/qwinrtmessagedialoghelper.cpp +++ /dev/null @@ -1,247 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwinrtmessagedialoghelper.h" -#include "qwinrttheme.h" - -#include <QtGui/QTextDocument> -#include <QtCore/qfunctions_winrt.h> -#include <private/qeventdispatcher_winrt_p.h> - -#include <functional> -#include <windows.ui.popups.h> -#include <windows.foundation.h> -#include <windows.foundation.collections.h> -#include <wrl.h> - -using namespace ABI::Windows::Foundation; -using namespace ABI::Windows::Foundation::Collections; -using namespace ABI::Windows::UI::Popups; -using namespace Microsoft::WRL; -using namespace Microsoft::WRL::Wrappers; - -typedef IAsyncOperationCompletedHandler<IUICommand *> DialogCompletedHandler; - -QT_BEGIN_NAMESPACE - -class CommandId : public RuntimeClass<IInspectable> -{ -public: - CommandId(QPlatformDialogHelper::StandardButton button) - : button(button) { } - QPlatformDialogHelper::StandardButton button; -}; - -class QWinRTMessageDialogHelperPrivate -{ -public: - const QWinRTTheme *theme; - bool shown; - ComPtr<IAsyncInfo> info; - QEventLoop loop; -}; - -QWinRTMessageDialogHelper::QWinRTMessageDialogHelper(const QWinRTTheme *theme) - : QPlatformMessageDialogHelper(), d_ptr(new QWinRTMessageDialogHelperPrivate) -{ - Q_D(QWinRTMessageDialogHelper); - - d->theme = theme; - d->shown = false; -} - -QWinRTMessageDialogHelper::~QWinRTMessageDialogHelper() -{ - Q_D(QWinRTMessageDialogHelper); - - if (d->shown) - hide(); -} - -void QWinRTMessageDialogHelper::exec() -{ - Q_D(QWinRTMessageDialogHelper); - - if (!d->shown) - show(Qt::Dialog, Qt::ApplicationModal, nullptr); - d->loop.exec(); -} - -bool QWinRTMessageDialogHelper::show(Qt::WindowFlags windowFlags, Qt::WindowModality windowModality, QWindow *parent) -{ - Q_UNUSED(windowFlags) - Q_UNUSED(windowModality) - Q_UNUSED(parent) - Q_D(QWinRTMessageDialogHelper); - - QSharedPointer<QMessageDialogOptions> options = this->options(); - if (!options.data()) - return false; - - const QString informativeText = options->informativeText(); - const QString title = options->windowTitle(); - const QString text = informativeText.isEmpty() ? options->text() : (options->text() + QLatin1Char('\n') + informativeText); - if (Qt::mightBeRichText(text)) { - qWarning("Rich text detected, defaulting to QtWidgets-based dialog."); - return false; - } - - HRESULT hr; - ComPtr<IMessageDialogFactory> dialogFactory; - hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_UI_Popups_MessageDialog).Get(), - IID_PPV_ARGS(&dialogFactory)); - RETURN_FALSE_IF_FAILED("Failed to create dialog factory"); - - ComPtr<IUICommandFactory> commandFactory; - hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_UI_Popups_UICommand).Get(), - IID_PPV_ARGS(&commandFactory)); - RETURN_FALSE_IF_FAILED("Failed to create command factory"); - - ComPtr<IMessageDialog> dialog; - HStringReference nativeText(reinterpret_cast<LPCWSTR>(text.utf16()), - uint(text.size())); - if (!title.isEmpty()) { - HStringReference nativeTitle(reinterpret_cast<LPCWSTR>(title.utf16()), - uint(title.size())); - hr = dialogFactory->CreateWithTitle(nativeText.Get(), nativeTitle.Get(), &dialog); - RETURN_FALSE_IF_FAILED("Failed to create dialog with title"); - } else { - hr = dialogFactory->Create(nativeText.Get(), &dialog); - RETURN_FALSE_IF_FAILED("Failed to create dialog"); - } - - hr = QEventDispatcherWinRT::runOnXamlThread([this, d, options, commandFactory, dialog]() { - HRESULT hr; - - // Add Buttons - ComPtr<IVector<IUICommand *>> dialogCommands; - hr = dialog->get_Commands(&dialogCommands); - RETURN_HR_IF_FAILED("Failed to get dialog commands"); - - // If no button is specified we need to create one to get close notification - int buttons = options->standardButtons(); - if (buttons == 0) - buttons = Ok; - - for (int i = FirstButton; i < LastButton; i<<=1) { - if (!(buttons & i)) - continue; - // Add native command - const QString label = d->theme->standardButtonText(i); - HStringReference nativeLabel(reinterpret_cast<LPCWSTR>(label.utf16()), - uint(label.size())); - ComPtr<IUICommand> command; - hr = commandFactory->Create(nativeLabel.Get(), &command); - RETURN_HR_IF_FAILED("Failed to create message box command"); - ComPtr<IInspectable> id = Make<CommandId>(static_cast<StandardButton>(i)); - hr = command->put_Id(id.Get()); - RETURN_HR_IF_FAILED("Failed to set command ID"); - hr = dialogCommands->Append(command.Get()); - if (hr == E_BOUNDS) { - qErrnoWarning(hr, "The WinRT message dialog supports a maximum of three buttons"); - continue; - } - RETURN_HR_IF_FAILED("Failed to append message box command"); - if (i == Abort || i == Cancel || i == Close) { - quint32 size; - hr = dialogCommands->get_Size(&size); - RETURN_HR_IF_FAILED("Failed to get command list size"); - hr = dialog->put_CancelCommandIndex(size - 1); - RETURN_HR_IF_FAILED("Failed to set cancel index"); - } - } - - ComPtr<IAsyncOperation<IUICommand *>> op; - hr = dialog->ShowAsync(&op); - RETURN_HR_IF_FAILED("Failed to show dialog"); - hr = op->put_Completed(Callback<DialogCompletedHandler>(this, &QWinRTMessageDialogHelper::onCompleted).Get()); - RETURN_HR_IF_FAILED("Failed to set dialog callback"); - d->shown = true; - hr = op.As(&d->info); - RETURN_HR_IF_FAILED("Failed to acquire AsyncInfo for MessageDialog"); - return hr; - }); - - RETURN_FALSE_IF_FAILED("Failed to show dialog") - return true; -} - -void QWinRTMessageDialogHelper::hide() -{ - Q_D(QWinRTMessageDialogHelper); - - if (!d->shown) - return; - - HRESULT hr = d->info->Cancel(); - if (FAILED(hr)) - qErrnoWarning(hr, "Failed to cancel dialog operation"); - - d->shown = false; -} - -HRESULT QWinRTMessageDialogHelper::onCompleted(IAsyncOperation<IUICommand *> *asyncInfo, AsyncStatus status) -{ - Q_UNUSED(status); - Q_D(QWinRTMessageDialogHelper); - - QEventLoopLocker locker(&d->loop); - - d->shown = false; - - if (status == Canceled) { - emit reject(); - return S_OK; - } - - HRESULT hr; - ComPtr<IUICommand> command; - hr = asyncInfo->GetResults(&command); - RETURN_OK_IF_FAILED("Failed to get command"); - - ComPtr<CommandId> id; - hr = command->get_Id(&id); - RETURN_OK_IF_FAILED("Failed to get command ID"); - - ButtonRole role = buttonRole(id->button); - emit clicked(id->button, role); - return S_OK; -} - -QT_END_NAMESPACE diff --git a/src/plugins/platforms/winrt/qwinrtmessagedialoghelper.h b/src/plugins/platforms/winrt/qwinrtmessagedialoghelper.h deleted file mode 100644 index ab704b1c7d..0000000000 --- a/src/plugins/platforms/winrt/qwinrtmessagedialoghelper.h +++ /dev/null @@ -1,88 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTMESSAGEDIALOGHELPER_H -#define QWINRTMESSAGEDIALOGHELPER_H - -#include <qpa/qplatformdialoghelper.h> -#include <QtCore/qt_windows.h> - -namespace ABI { - namespace Windows { - namespace UI { - namespace Popups { - struct IUICommand; - } - } - namespace Foundation { - enum class AsyncStatus; - template <typename T> struct IAsyncOperation; - } - } -} - -QT_BEGIN_NAMESPACE - -class QWinRTTheme; - -class QWinRTMessageDialogHelperPrivate; -class QWinRTMessageDialogHelper : public QPlatformMessageDialogHelper -{ - Q_OBJECT -public: - explicit QWinRTMessageDialogHelper(const QWinRTTheme *theme); - ~QWinRTMessageDialogHelper() override; - - void exec() override; - bool show(Qt::WindowFlags windowFlags, - Qt::WindowModality windowModality, - QWindow *parent) override; - void hide() override; - -private: - HRESULT onCompleted(ABI::Windows::Foundation::IAsyncOperation<ABI::Windows::UI::Popups::IUICommand *> *asyncInfo, - ABI::Windows::Foundation::AsyncStatus status); - - QScopedPointer<QWinRTMessageDialogHelperPrivate> d_ptr; - Q_DECLARE_PRIVATE(QWinRTMessageDialogHelper) -}; - -QT_END_NAMESPACE - -#endif // QWINRTMESSAGEDIALOGHELPER_H diff --git a/src/plugins/platforms/winrt/qwinrtscreen.cpp b/src/plugins/platforms/winrt/qwinrtscreen.cpp deleted file mode 100644 index 5db1459213..0000000000 --- a/src/plugins/platforms/winrt/qwinrtscreen.cpp +++ /dev/null @@ -1,1543 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwinrtscreen.h" - -#include "qwinrtbackingstore.h" -#include "qwinrtinputcontext.h" -#include "qwinrtcursor.h" -#if QT_CONFIG(draganddrop) -#include "qwinrtdrag.h" -#endif -#include "qwinrtwindow.h" -#include "qwinrtcanvas.h" -#include <private/qeventdispatcher_winrt_p.h> -#include <private/qhighdpiscaling_p.h> - -#include <QtCore/qdebug.h> -#include <QtCore/QLoggingCategory> -#include <QtGui/QSurfaceFormat> -#include <QtGui/QGuiApplication> -#include <qpa/qwindowsysteminterface.h> -#include <QtCore/qt_windows.h> -#include <QtCore/qfunctions_winrt.h> - -#include <functional> -#include <wrl.h> -#include <windows.system.h> -#include <Windows.ApplicationModel.h> -#include <Windows.ApplicationModel.core.h> -#include <windows.devices.input.h> -#include <windows.ui.h> -#include <windows.ui.core.h> -#include <windows.ui.input.h> -#include <windows.ui.xaml.h> -#include <windows.ui.viewmanagement.h> -#include <windows.graphics.display.h> -#include <windows.foundation.h> - -using namespace Microsoft::WRL; -using namespace Microsoft::WRL::Wrappers; -using namespace ABI::Windows::ApplicationModel; -using namespace ABI::Windows::ApplicationModel::Core; -using namespace ABI::Windows::Foundation; -using namespace ABI::Windows::System; -using namespace ABI::Windows::UI; -using namespace ABI::Windows::UI::Core; -using namespace ABI::Windows::UI::Input; -using namespace ABI::Windows::UI::ViewManagement; -using namespace ABI::Windows::Devices::Input; -using namespace ABI::Windows::Graphics::Display; - -typedef ITypedEventHandler<CoreWindow*, WindowActivatedEventArgs*> ActivatedHandler; -typedef ITypedEventHandler<CoreWindow*, CoreWindowEventArgs*> ClosedHandler; -typedef ITypedEventHandler<CoreWindow*, CharacterReceivedEventArgs*> CharacterReceivedHandler; -typedef ITypedEventHandler<CoreWindow*, InputEnabledEventArgs*> InputEnabledHandler; -typedef ITypedEventHandler<CoreWindow*, KeyEventArgs*> KeyHandler; -typedef ITypedEventHandler<CoreWindow*, PointerEventArgs*> PointerHandler; -typedef ITypedEventHandler<CoreWindow*, VisibilityChangedEventArgs*> VisibilityChangedHandler; -typedef ITypedEventHandler<DisplayInformation*, IInspectable*> DisplayInformationHandler; -typedef ITypedEventHandler<ICorePointerRedirector*, PointerEventArgs*> RedirectHandler; -typedef ITypedEventHandler<ApplicationView*, IInspectable*> VisibleBoundsChangedHandler; - -QT_BEGIN_NAMESPACE - -Q_LOGGING_CATEGORY(lcQpaEvents, "qt.qpa.events") - -#if !defined(QT_NO_DEBUG_STREAM) -QDebug operator<<(QDebug dbg, QWinRTScreen::MousePositionTransition transition) -{ - QDebugStateSaver saver(dbg); - dbg.nospace() << "QWinRTScreen::MousePositionTransition::"; - switch (transition) { - case QWinRTScreen::MousePositionTransition::MovedOut: - dbg << "MovedOut"; - break; - case QWinRTScreen::MousePositionTransition::MovedIn: - dbg << "MovedIn"; - break; - case QWinRTScreen::MousePositionTransition::StayedOut: - dbg << "StayedOut"; - break; - case QWinRTScreen::MousePositionTransition::StayedIn: - dbg << "StayedIn"; - break; - } - return dbg; -} -#endif - -struct KeyInfo { - KeyInfo() - { - } - - KeyInfo(quint32 virtualKey) - : virtualKey(virtualKey) - { - } - - QString text; - quint32 virtualKey{0}; - bool isAutoRepeat{false}; -}; - -static inline Qt::ScreenOrientations qtOrientationsFromNative(DisplayOrientations native) -{ - Qt::ScreenOrientations orientations = Qt::PrimaryOrientation; - if (native & DisplayOrientations_Portrait) - orientations |= Qt::PortraitOrientation; - if (native & DisplayOrientations_PortraitFlipped) - orientations |= Qt::InvertedPortraitOrientation; - if (native & DisplayOrientations_Landscape) - orientations |= Qt::LandscapeOrientation; - if (native & DisplayOrientations_LandscapeFlipped) - orientations |= Qt::InvertedLandscapeOrientation; - return orientations; -} - -static inline DisplayOrientations nativeOrientationsFromQt(Qt::ScreenOrientations orientation) -{ - DisplayOrientations native = DisplayOrientations_None; - if (orientation & Qt::PortraitOrientation) - native |= DisplayOrientations_Portrait; - if (orientation & Qt::InvertedPortraitOrientation) - native |= DisplayOrientations_PortraitFlipped; - if (orientation & Qt::LandscapeOrientation) - native |= DisplayOrientations_Landscape; - if (orientation & Qt::InvertedLandscapeOrientation) - native |= DisplayOrientations_LandscapeFlipped; - return native; -} - -static inline bool qIsNonPrintable(quint32 keyCode) -{ - switch (keyCode) { - case '\b': - case '\n': - case '\t': - case '\r': - case '\v': - case '\f': - return true; - default: - return false; - } -} - -// Return Qt meta key from VirtualKey -static inline Qt::Key qKeyFromVirtual(VirtualKey key) -{ - switch (key) { - - default: - return Qt::Key_unknown; - - // Non-printable characters - case VirtualKey_Enter: - return Qt::Key_Enter; - case VirtualKey_Tab: - return Qt::Key_Tab; - case VirtualKey_Back: - return Qt::Key_Backspace; - - // Modifiers - case VirtualKey_Shift: - case VirtualKey_LeftShift: - case VirtualKey_RightShift: - return Qt::Key_Shift; - case VirtualKey_Control: - case VirtualKey_LeftControl: - case VirtualKey_RightControl: - return Qt::Key_Control; - case VirtualKey_Menu: - case VirtualKey_LeftMenu: - case VirtualKey_RightMenu: - return Qt::Key_Alt; - case VirtualKey_LeftWindows: - case VirtualKey_RightWindows: - return Qt::Key_Meta; - - // Toggle keys - case VirtualKey_CapitalLock: - return Qt::Key_CapsLock; - case VirtualKey_NumberKeyLock: - return Qt::Key_NumLock; - case VirtualKey_Scroll: - return Qt::Key_ScrollLock; - - // East-Asian language keys - case VirtualKey_Kana: - //case VirtualKey_Hangul: // Same enum as Kana - return Qt::Key_Kana_Shift; - case VirtualKey_Junja: - return Qt::Key_Hangul_Jeonja; - case VirtualKey_Kanji: - //case VirtualKey_Hanja: // Same enum as Kanji - return Qt::Key_Kanji; - case VirtualKey_ModeChange: - return Qt::Key_Mode_switch; - case VirtualKey_Convert: - return Qt::Key_Henkan; - case VirtualKey_NonConvert: - return Qt::Key_Muhenkan; - - // Misc. keys - case VirtualKey_Cancel: - return Qt::Key_Cancel; - case VirtualKey_Clear: - return Qt::Key_Clear; - case VirtualKey_Application: - return Qt::Key_ApplicationLeft; - case VirtualKey_Sleep: - return Qt::Key_Sleep; - case VirtualKey_Pause: - return Qt::Key_Pause; - case VirtualKey_PageUp: - return Qt::Key_PageUp; - case VirtualKey_PageDown: - return Qt::Key_PageDown; - case VirtualKey_End: - return Qt::Key_End; - case VirtualKey_Home: - return Qt::Key_Home; - case VirtualKey_Left: - return Qt::Key_Left; - case VirtualKey_Up: - return Qt::Key_Up; - case VirtualKey_Right: - return Qt::Key_Right; - case VirtualKey_Down: - return Qt::Key_Down; - case VirtualKey_Select: - return Qt::Key_Select; - case VirtualKey_Print: - return Qt::Key_Print; - case VirtualKey_Execute: - return Qt::Key_Execute; - case VirtualKey_Insert: - return Qt::Key_Insert; - case VirtualKey_Delete: - return Qt::Key_Delete; - case VirtualKey_Help: - return Qt::Key_Help; - case VirtualKey_Snapshot: - return Qt::Key_Camera; - case VirtualKey_Escape: - return Qt::Key_Escape; - - // Function Keys - case VirtualKey_F1: - return Qt::Key_F1; - case VirtualKey_F2: - return Qt::Key_F2; - case VirtualKey_F3: - return Qt::Key_F3; - case VirtualKey_F4: - return Qt::Key_F4; - case VirtualKey_F5: - return Qt::Key_F5; - case VirtualKey_F6: - return Qt::Key_F6; - case VirtualKey_F7: - return Qt::Key_F7; - case VirtualKey_F8: - return Qt::Key_F8; - case VirtualKey_F9: - return Qt::Key_F9; - case VirtualKey_F10: - return Qt::Key_F10; - case VirtualKey_F11: - return Qt::Key_F11; - case VirtualKey_F12: - return Qt::Key_F12; - case VirtualKey_F13: - return Qt::Key_F13; - case VirtualKey_F14: - return Qt::Key_F14; - case VirtualKey_F15: - return Qt::Key_F15; - case VirtualKey_F16: - return Qt::Key_F16; - case VirtualKey_F17: - return Qt::Key_F17; - case VirtualKey_F18: - return Qt::Key_F18; - case VirtualKey_F19: - return Qt::Key_F19; - case VirtualKey_F20: - return Qt::Key_F20; - case VirtualKey_F21: - return Qt::Key_F21; - case VirtualKey_F22: - return Qt::Key_F22; - case VirtualKey_F23: - return Qt::Key_F23; - case VirtualKey_F24: - return Qt::Key_F24; - - // Character keys - case VirtualKey_Space: - return Qt::Key_Space; - case VirtualKey_Number0: - case VirtualKey_NumberPad0: - return Qt::Key_0; - case VirtualKey_Number1: - case VirtualKey_NumberPad1: - return Qt::Key_1; - case VirtualKey_Number2: - case VirtualKey_NumberPad2: - return Qt::Key_2; - case VirtualKey_Number3: - case VirtualKey_NumberPad3: - return Qt::Key_3; - case VirtualKey_Number4: - case VirtualKey_NumberPad4: - return Qt::Key_4; - case VirtualKey_Number5: - case VirtualKey_NumberPad5: - return Qt::Key_5; - case VirtualKey_Number6: - case VirtualKey_NumberPad6: - return Qt::Key_6; - case VirtualKey_Number7: - case VirtualKey_NumberPad7: - return Qt::Key_7; - case VirtualKey_Number8: - case VirtualKey_NumberPad8: - return Qt::Key_8; - case VirtualKey_Number9: - case VirtualKey_NumberPad9: - return Qt::Key_9; - case VirtualKey_A: - return Qt::Key_A; - case VirtualKey_B: - return Qt::Key_B; - case VirtualKey_C: - return Qt::Key_C; - case VirtualKey_D: - return Qt::Key_D; - case VirtualKey_E: - return Qt::Key_E; - case VirtualKey_F: - return Qt::Key_F; - case VirtualKey_G: - return Qt::Key_G; - case VirtualKey_H: - return Qt::Key_H; - case VirtualKey_I: - return Qt::Key_I; - case VirtualKey_J: - return Qt::Key_J; - case VirtualKey_K: - return Qt::Key_K; - case VirtualKey_L: - return Qt::Key_L; - case VirtualKey_M: - return Qt::Key_M; - case VirtualKey_N: - return Qt::Key_N; - case VirtualKey_O: - return Qt::Key_O; - case VirtualKey_P: - return Qt::Key_P; - case VirtualKey_Q: - return Qt::Key_Q; - case VirtualKey_R: - return Qt::Key_R; - case VirtualKey_S: - return Qt::Key_S; - case VirtualKey_T: - return Qt::Key_T; - case VirtualKey_U: - return Qt::Key_U; - case VirtualKey_V: - return Qt::Key_V; - case VirtualKey_W: - return Qt::Key_W; - case VirtualKey_X: - return Qt::Key_X; - case VirtualKey_Y: - return Qt::Key_Y; - case VirtualKey_Z: - return Qt::Key_Z; - case VirtualKey_Multiply: - return Qt::Key_9; - case VirtualKey_Add: - return Qt::Key_9; - case VirtualKey_Separator: - return Qt::Key_9; - case VirtualKey_Subtract: - return Qt::Key_9; - case VirtualKey_Decimal: - return Qt::Key_9; - case VirtualKey_Divide: - return Qt::Key_9; - - /* Keys with no matching Qt enum (?) - case VirtualKey_None: - case VirtualKey_LeftButton: - case VirtualKey_RightButton: - case VirtualKey_MiddleButton: - case VirtualKey_XButton1: - case VirtualKey_XButton2: - case VirtualKey_Final: - case VirtualKey_Accept:*/ - } -} - -// Some keys like modifiers, caps lock etc. should not be automatically repeated if the key is held down -static inline bool shouldAutoRepeat(Qt::Key key) -{ - switch (key) { - case Qt::Key_Shift: - case Qt::Key_Control: - case Qt::Key_Alt: - case Qt::Key_Meta: - case Qt::Key_CapsLock: - case Qt::Key_NumLock: - case Qt::Key_ScrollLock: - return false; - default: - return true; - } -} - -static inline Qt::Key qKeyFromCode(quint32 code, int mods) -{ - if (code >= 'a' && code <= 'z') - code = toupper(code); - if ((mods & Qt::ControlModifier) != 0) { - if (code >= 0 && code <= 31) // Ctrl+@..Ctrl+A..CTRL+Z..Ctrl+_ - code += '@'; // to @..A..Z.._ - } - return static_cast<Qt::Key>(code & 0xff); -} - -typedef HRESULT (__stdcall ICoreWindow::*CoreWindowCallbackRemover)(EventRegistrationToken); -size_t qHash(CoreWindowCallbackRemover key) { void *ptr = *(void **)(&key); return qHash(ptr); } -typedef HRESULT (__stdcall IDisplayInformation::*DisplayCallbackRemover)(EventRegistrationToken); -size_t qHash(DisplayCallbackRemover key) { void *ptr = *(void **)(&key); return qHash(ptr); } -typedef HRESULT (__stdcall ICorePointerRedirector::*RedirectorCallbackRemover)(EventRegistrationToken); -size_t qHash(RedirectorCallbackRemover key) { void *ptr = *(void **)(&key); return qHash(ptr); } -typedef HRESULT (__stdcall IApplicationView2::*ApplicationView2CallbackRemover)(EventRegistrationToken); -size_t qHash(ApplicationView2CallbackRemover key) { void *ptr = *(void **)(&key); return qHash(ptr); } - -class QWinRTScreenPrivate -{ -public: - QTouchDevice *touchDevice; - ComPtr<ICoreWindow> coreWindow; - ComPtr<ICorePointerRedirector> redirect; - ComPtr<QWinRTCanvas> canvas; - ComPtr<IApplicationView> view; - ComPtr<IDisplayInformation> displayInformation; - - QScopedPointer<QWinRTCursor> cursor; - QHash<quint32, QWindowSystemInterface::TouchPoint> touchPoints; - QRectF logicalRect; - QRectF visibleRect; - QSurfaceFormat surfaceFormat; - qreal logicalDpi; - QDpi physicalDpi; - qreal scaleFactor; - Qt::ScreenOrientation nativeOrientation; - Qt::ScreenOrientation orientation; - QList<QWindow *> visibleWindows; - QHash<Qt::Key, KeyInfo> activeKeys; - QHash<CoreWindowCallbackRemover, EventRegistrationToken> windowTokens; - QHash<DisplayCallbackRemover, EventRegistrationToken> displayTokens; - QHash<RedirectorCallbackRemover, EventRegistrationToken> redirectTokens; - QHash<ApplicationView2CallbackRemover, EventRegistrationToken> view2Tokens; - ComPtr<IApplicationView2> view2; - QAtomicPointer<QWinRTWindow> mouseGrabWindow; - QAtomicPointer<QWinRTWindow> keyboardGrabWindow; - QWindow *currentPressWindow = nullptr; - QWindow *currentTargetWindow = nullptr; - bool firstMouseMove = true; - bool resizePending = false; -}; - -// To be called from the XAML thread -QWinRTScreen::QWinRTScreen() - : d_ptr(new QWinRTScreenPrivate) -{ - Q_D(QWinRTScreen); - qCDebug(lcQpaWindows) << __FUNCTION__; - d->orientation = Qt::PrimaryOrientation; - d->touchDevice = nullptr; - - HRESULT hr; - ComPtr<Xaml::IWindowStatics> windowStatics; - hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_UI_Xaml_Window).Get(), - IID_PPV_ARGS(&windowStatics)); - Q_ASSERT_SUCCEEDED(hr); - ComPtr<Xaml::IWindow> window; - hr = windowStatics->get_Current(&window); - Q_ASSERT_SUCCEEDED(hr); - hr = window->Activate(); - Q_ASSERT_SUCCEEDED(hr); - - hr = window->get_CoreWindow(&d->coreWindow); - Q_ASSERT_SUCCEEDED(hr); - - hr = d->coreWindow.As(&d->redirect); - Q_ASSERT_SUCCEEDED(hr); - - hr = d->coreWindow->Activate(); - Q_ASSERT_SUCCEEDED(hr); - - Rect rect; - hr = d->coreWindow->get_Bounds(&rect); - Q_ASSERT_SUCCEEDED(hr); - d->logicalRect = QRectF(0.0f, 0.0f, rect.Width, rect.Height); - d->visibleRect = QRectF(0.0f, 0.0f, rect.Width, rect.Height); - - // Orientation handling - ComPtr<IDisplayInformationStatics> displayInformationStatics; - hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Graphics_Display_DisplayInformation).Get(), - IID_PPV_ARGS(&displayInformationStatics)); - Q_ASSERT_SUCCEEDED(hr); - - hr = displayInformationStatics->GetForCurrentView(&d->displayInformation); - Q_ASSERT_SUCCEEDED(hr); - - // Set native orientation - DisplayOrientations displayOrientation; - hr = d->displayInformation->get_NativeOrientation(&displayOrientation); - Q_ASSERT_SUCCEEDED(hr); - d->nativeOrientation = static_cast<Qt::ScreenOrientation>(static_cast<int>(qtOrientationsFromNative(displayOrientation))); - // Set initial pixel density - onDpiChanged(nullptr, nullptr); - d->orientation = d->nativeOrientation; - - ComPtr<IApplicationViewStatics2> applicationViewStatics; - hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_UI_ViewManagement_ApplicationView).Get(), - IID_PPV_ARGS(&applicationViewStatics)); - RETURN_VOID_IF_FAILED("Could not get ApplicationViewStatics"); - - hr = applicationViewStatics->GetForCurrentView(&d->view); - RETURN_VOID_IF_FAILED("Could not access currentView"); - - d->canvas = Make<QWinRTCanvas>([this]() { return topWindow(); }); - - ComPtr<Xaml::IFrameworkElement> frameworkElement; - hr = d->canvas.As(&frameworkElement); - Q_ASSERT_SUCCEEDED(hr); - hr = frameworkElement->put_Width(d->logicalRect.width()); - Q_ASSERT_SUCCEEDED(hr); - hr = frameworkElement->put_Height(d->logicalRect.height()); - Q_ASSERT_SUCCEEDED(hr); - - ComPtr<Xaml::IUIElement> uiElement; - hr = d->canvas.As(&uiElement); - Q_ASSERT_SUCCEEDED(hr); - -#if QT_CONFIG(draganddrop) - QWinRTDrag::instance()->setUiElement(uiElement); -#endif - hr = window->put_Content(uiElement.Get()); - Q_ASSERT_SUCCEEDED(hr); - - d->cursor.reset(new QWinRTCursor); - - hr = d->view.As(&d->view2); - Q_ASSERT_SUCCEEDED(hr); -} - -QWinRTScreen::~QWinRTScreen() -{ - Q_D(QWinRTScreen); - qCDebug(lcQpaWindows) << __FUNCTION__ << this; - - // Unregister callbacks - HRESULT hr; - hr = QEventDispatcherWinRT::runOnXamlThread([this, d]() { - HRESULT hr; - for (QHash<CoreWindowCallbackRemover, EventRegistrationToken>::const_iterator i = d->windowTokens.begin(); i != d->windowTokens.end(); ++i) { - hr = (d->coreWindow.Get()->*i.key())(i.value()); - Q_ASSERT_SUCCEEDED(hr); - } - for (QHash<DisplayCallbackRemover, EventRegistrationToken>::const_iterator i = d->displayTokens.begin(); i != d->displayTokens.end(); ++i) { - hr = (d->displayInformation.Get()->*i.key())(i.value()); - Q_ASSERT_SUCCEEDED(hr); - } - for (QHash<RedirectorCallbackRemover, EventRegistrationToken>::const_iterator i = d->redirectTokens.begin(); i != d->redirectTokens.end(); ++i) { - hr = (d->redirect.Get()->*i.key())(i.value()); - Q_ASSERT_SUCCEEDED(hr); - } - for (QHash<ApplicationView2CallbackRemover, EventRegistrationToken>::const_iterator i = d->view2Tokens.begin(); i != d->view2Tokens.end(); ++i) { - hr = (d->view2.Get()->*i.key())(i.value()); - Q_ASSERT_SUCCEEDED(hr); - } - return hr; - }); - RETURN_VOID_IF_FAILED("Failed to unregister screen event callbacks"); -} - -QRect QWinRTScreen::geometry() const -{ - Q_D(const QWinRTScreen); - return QRect(QPoint(), QSizeF(d->logicalRect.size() * d->scaleFactor).toSize()); -} - -QRect QWinRTScreen::availableGeometry() const -{ - Q_D(const QWinRTScreen); - return QRectF((d->visibleRect.x() - d->logicalRect.x())* d->scaleFactor, - (d->visibleRect.y() - d->logicalRect.y()) * d->scaleFactor, - d->visibleRect.width() * d->scaleFactor, - d->visibleRect.height() * d->scaleFactor).toRect(); -} - -int QWinRTScreen::depth() const -{ - return 32; -} - -QImage::Format QWinRTScreen::format() const -{ - return QImage::Format_RGB32; -} - -QSizeF QWinRTScreen::physicalSize() const -{ - Q_D(const QWinRTScreen); - return QSizeF(d->logicalRect.width() * d->scaleFactor / d->physicalDpi.first * qreal(25.4), - d->logicalRect.height() * d->scaleFactor / d->physicalDpi.second * qreal(25.4)); -} - -QDpi QWinRTScreen::logicalDpi() const -{ - Q_D(const QWinRTScreen); - return QDpi(d->logicalDpi, d->logicalDpi); -} - -qreal QWinRTScreen::scaleFactor() const -{ - Q_D(const QWinRTScreen); - return d->scaleFactor; -} - -QPlatformCursor *QWinRTScreen::cursor() const -{ - Q_D(const QWinRTScreen); - return d->cursor.data(); -} - -Qt::KeyboardModifiers QWinRTScreen::keyboardModifiers() const -{ - Q_D(const QWinRTScreen); - - Qt::KeyboardModifiers mods; - CoreVirtualKeyStates mod; - HRESULT hr = d->coreWindow->GetAsyncKeyState(VirtualKey_Shift, &mod); - Q_ASSERT_SUCCEEDED(hr); - if (mod & CoreVirtualKeyStates_Down) - mods |= Qt::ShiftModifier; - hr = d->coreWindow->GetAsyncKeyState(VirtualKey_Menu, &mod); - Q_ASSERT_SUCCEEDED(hr); - if (mod & CoreVirtualKeyStates_Down) - mods |= Qt::AltModifier; - hr = d->coreWindow->GetAsyncKeyState(VirtualKey_Control, &mod); - Q_ASSERT_SUCCEEDED(hr); - if (mod & CoreVirtualKeyStates_Down) - mods |= Qt::ControlModifier; - hr = d->coreWindow->GetAsyncKeyState(VirtualKey_LeftWindows, &mod); - Q_ASSERT_SUCCEEDED(hr); - if (mod & CoreVirtualKeyStates_Down) { - mods |= Qt::MetaModifier; - } else { - hr = d->coreWindow->GetAsyncKeyState(VirtualKey_RightWindows, &mod); - Q_ASSERT_SUCCEEDED(hr); - if (mod & CoreVirtualKeyStates_Down) - mods |= Qt::MetaModifier; - } - return mods; -} - -Qt::ScreenOrientation QWinRTScreen::nativeOrientation() const -{ - Q_D(const QWinRTScreen); - return d->nativeOrientation; -} - -Qt::ScreenOrientation QWinRTScreen::orientation() const -{ - Q_D(const QWinRTScreen); - return d->orientation; -} - -ICoreWindow *QWinRTScreen::coreWindow() const -{ - Q_D(const QWinRTScreen); - return d->coreWindow.Get(); -} - -Xaml::IDependencyObject *QWinRTScreen::canvas() const -{ - Q_D(const QWinRTScreen); - Xaml::IDependencyObject *depCanvas; - if (SUCCEEDED(d->canvas.CopyTo(&depCanvas))) - return depCanvas; - return nullptr; -} - -void QWinRTScreen::initialize() -{ - Q_D(QWinRTScreen); - HRESULT hr; - hr = d->coreWindow->add_KeyDown(Callback<KeyHandler>(this, &QWinRTScreen::onKeyDown).Get(), &d->windowTokens[&ICoreWindow::remove_KeyDown]); - Q_ASSERT_SUCCEEDED(hr); - hr = d->coreWindow->add_KeyUp(Callback<KeyHandler>(this, &QWinRTScreen::onKeyUp).Get(), &d->windowTokens[&ICoreWindow::remove_KeyUp]); - Q_ASSERT_SUCCEEDED(hr); - hr = d->coreWindow->add_CharacterReceived(Callback<CharacterReceivedHandler>(this, &QWinRTScreen::onCharacterReceived).Get(), &d->windowTokens[&ICoreWindow::remove_CharacterReceived]); - Q_ASSERT_SUCCEEDED(hr); - hr = d->coreWindow->add_PointerEntered(Callback<PointerHandler>(this, &QWinRTScreen::onPointerEntered).Get(), &d->windowTokens[&ICoreWindow::remove_PointerEntered]); - Q_ASSERT_SUCCEEDED(hr); - hr = d->coreWindow->add_PointerExited(Callback<PointerHandler>(this, &QWinRTScreen::onPointerExited).Get(), &d->windowTokens[&ICoreWindow::remove_PointerExited]); - Q_ASSERT_SUCCEEDED(hr); - hr = d->coreWindow->add_PointerMoved(Callback<PointerHandler>(this, &QWinRTScreen::onPointerUpdated).Get(), &d->windowTokens[&ICoreWindow::remove_PointerMoved]); - Q_ASSERT_SUCCEEDED(hr); - hr = d->coreWindow->add_PointerPressed(Callback<PointerHandler>(this, &QWinRTScreen::onPointerUpdated).Get(), &d->windowTokens[&ICoreWindow::remove_PointerPressed]); - Q_ASSERT_SUCCEEDED(hr); - hr = d->coreWindow->add_PointerReleased(Callback<PointerHandler>(this, &QWinRTScreen::onPointerUpdated).Get(), &d->windowTokens[&ICoreWindow::remove_PointerReleased]); - Q_ASSERT_SUCCEEDED(hr); - hr = d->coreWindow->add_PointerWheelChanged(Callback<PointerHandler>(this, &QWinRTScreen::onPointerUpdated).Get(), &d->windowTokens[&ICoreWindow::remove_PointerWheelChanged]); - Q_ASSERT_SUCCEEDED(hr); - hr = d->view2->add_VisibleBoundsChanged(Callback<VisibleBoundsChangedHandler>(this, &QWinRTScreen::onWindowSizeChanged).Get(), &d->view2Tokens[&IApplicationView2::remove_VisibleBoundsChanged]); - Q_ASSERT_SUCCEEDED(hr); - hr = d->coreWindow->add_Activated(Callback<ActivatedHandler>(this, &QWinRTScreen::onActivated).Get(), &d->windowTokens[&ICoreWindow::remove_Activated]); - Q_ASSERT_SUCCEEDED(hr); - hr = d->coreWindow->add_Closed(Callback<ClosedHandler>(this, &QWinRTScreen::onClosed).Get(), &d->windowTokens[&ICoreWindow::remove_Closed]); - Q_ASSERT_SUCCEEDED(hr); - hr = d->coreWindow->add_VisibilityChanged(Callback<VisibilityChangedHandler>(this, &QWinRTScreen::onVisibilityChanged).Get(), &d->windowTokens[&ICoreWindow::remove_VisibilityChanged]); - Q_ASSERT_SUCCEEDED(hr); - hr = d->displayInformation->add_OrientationChanged(Callback<DisplayInformationHandler>(this, &QWinRTScreen::onOrientationChanged).Get(), &d->displayTokens[&IDisplayInformation::remove_OrientationChanged]); - Q_ASSERT_SUCCEEDED(hr); - hr = d->displayInformation->add_DpiChanged(Callback<DisplayInformationHandler>(this, &QWinRTScreen::onDpiChanged).Get(), &d->displayTokens[&IDisplayInformation::remove_DpiChanged]); - Q_ASSERT_SUCCEEDED(hr); - onOrientationChanged(nullptr, nullptr); - onVisibilityChanged(nullptr, nullptr); - - hr = d->redirect->add_PointerRoutedReleased(Callback<RedirectHandler>(this, &QWinRTScreen::onRedirectReleased).Get(), &d->redirectTokens[&ICorePointerRedirector::remove_PointerRoutedReleased]); - Q_ASSERT_SUCCEEDED(hr); -} - -void QWinRTScreen::setCursorRect(const QRectF &cursorRect) -{ - mCursorRect = cursorRect; -} - -void QWinRTScreen::setKeyboardRect(const QRectF &keyboardRect) -{ - Q_D(QWinRTScreen); - QRectF visibleRectF; - HRESULT hr; - Rect windowSize; - - hr = d->coreWindow->get_Bounds(&windowSize); - if (FAILED(hr)) { - qErrnoWarning(hr, "Failed to get window bounds"); - return; - } - d->logicalRect = QRectF(windowSize.X, windowSize.Y, windowSize.Width, windowSize.Height); - Rect visibleRect; - hr = d->view2->get_VisibleBounds(&visibleRect); - if (FAILED(hr)) { - qErrnoWarning(hr, "Failed to get window visible bounds"); - return; - } - visibleRectF = QRectF(visibleRect.X, visibleRect.Y, visibleRect.Width, visibleRect.Height); - // if keyboard is snapped to the bottom of the screen and would cover the cursor the content is - // moved up to make it visible - if (keyboardRect.intersects(mCursorRect) - && qFuzzyCompare(geometry().height(), keyboardRect.y() + keyboardRect.height())) { - visibleRectF.moveTop(visibleRectF.top() - keyboardRect.height() / d->scaleFactor); - } - d->visibleRect = visibleRectF; - - qCDebug(lcQpaWindows) << __FUNCTION__ << d->visibleRect; - QWindowSystemInterface::handleScreenGeometryChange(screen(), geometry(), availableGeometry()); - QPlatformScreen::resizeMaximizedWindows(); - handleExpose(); -} - -QWindow *QWinRTScreen::topWindow() const -{ - Q_D(const QWinRTScreen); - return d->visibleWindows.isEmpty() ? 0 : d->visibleWindows.first(); -} - -QWindow *QWinRTScreen::windowAt(const QPoint &pos) -{ - Q_D(const QWinRTScreen); - for (auto w : qAsConst(d->visibleWindows)) { - if (w->geometry().contains(pos)) - return w; - } - qCDebug(lcQpaWindows) << __FUNCTION__ << ": No window found at:" << pos; - return nullptr; -} - -void QWinRTScreen::addWindow(QWindow *window) -{ - Q_D(QWinRTScreen); - qCDebug(lcQpaWindows) << __FUNCTION__ << window; - if (window == topWindow() || window->surfaceClass() == QSurface::Offscreen) - return; - - d->visibleWindows.prepend(window); - const Qt::WindowType type = window->type(); - if (type != Qt::Popup && type != Qt::ToolTip && type != Qt::Tool) { - updateWindowTitle(window->title()); - QWindowSystemInterface::handleWindowActivated(window, Qt::OtherFocusReason); - } - - handleExpose(); - d->firstMouseMove = true; - QWindowSystemInterface::flushWindowSystemEvents(QEventLoop::ExcludeUserInputEvents); - -#if QT_CONFIG(draganddrop) - QWinRTDrag::instance()->setDropTarget(window); -#endif -} - -void QWinRTScreen::removeWindow(QWindow *window) -{ - Q_D(QWinRTScreen); - qCDebug(lcQpaWindows) << __FUNCTION__ << window; - - handleExpose(); - - const bool wasTopWindow = window == topWindow(); - if (!d->visibleWindows.removeAll(window)) - return; - - const Qt::WindowType type = window->type(); - if (wasTopWindow && type != Qt::Popup && type != Qt::ToolTip && type != Qt::Tool) - QWindowSystemInterface::handleWindowActivated(nullptr, Qt::OtherFocusReason); - QWindowSystemInterface::flushWindowSystemEvents(QEventLoop::ExcludeUserInputEvents); -#if QT_CONFIG(draganddrop) - if (wasTopWindow) - QWinRTDrag::instance()->setDropTarget(topWindow()); -#endif -} - -void QWinRTScreen::raise(QWindow *window) -{ - Q_D(QWinRTScreen); - d->visibleWindows.removeAll(window); - addWindow(window); -} - -void QWinRTScreen::lower(QWindow *window) -{ - Q_D(QWinRTScreen); - const bool wasTopWindow = window == topWindow(); - if (wasTopWindow && d->visibleWindows.size() == 1) - return; - if (window->surfaceClass() == QSurface::Offscreen) - return; - d->visibleWindows.removeAll(window); - d->visibleWindows.append(window); - if (wasTopWindow) - QWindowSystemInterface::handleWindowActivated(window, Qt::OtherFocusReason); - handleExpose(); -} - -bool QWinRTScreen::setMouseGrabWindow(QWinRTWindow *window, bool grab) -{ - Q_D(QWinRTScreen); - qCDebug(lcQpaWindows) << __FUNCTION__ << window - << "(" << window->window()->objectName() << "):" << grab; - - if (!grab || window == nullptr) - d->mouseGrabWindow = nullptr; - else if (d->mouseGrabWindow != window) - d->mouseGrabWindow = window; - return grab; -} - -QWinRTWindow *QWinRTScreen::mouseGrabWindow() const -{ - Q_D(const QWinRTScreen); - return d->mouseGrabWindow; -} - -bool QWinRTScreen::setKeyboardGrabWindow(QWinRTWindow *window, bool grab) -{ - Q_D(QWinRTScreen); - qCDebug(lcQpaWindows) << __FUNCTION__ << window - << "(" << window->window()->objectName() << "):" << grab; - - if (!grab || window == nullptr) - d->keyboardGrabWindow = nullptr; - else if (d->keyboardGrabWindow != window) - d->keyboardGrabWindow = window; - return grab; -} - -QWinRTWindow *QWinRTScreen::keyboardGrabWindow() const -{ - Q_D(const QWinRTScreen); - return d->keyboardGrabWindow; -} - -void QWinRTScreen::updateWindowTitle(const QString &title) -{ - Q_D(QWinRTScreen); - - HStringReference titleRef(reinterpret_cast<LPCWSTR>(title.utf16()), title.length()); - HRESULT hr = d->view->put_Title(titleRef.Get()); - RETURN_VOID_IF_FAILED("Unable to set window title"); -} - -void QWinRTScreen::handleExpose() -{ - Q_D(QWinRTScreen); - if (d->visibleWindows.isEmpty()) - return; - QList<QWindow *>::const_iterator it = d->visibleWindows.constBegin(); - QWindowSystemInterface::handleExposeEvent(*it, geometry()); - while (++it != d->visibleWindows.constEnd()) - QWindowSystemInterface::handleExposeEvent(*it, QRegion()); -} - -HRESULT QWinRTScreen::onKeyDown(ABI::Windows::UI::Core::ICoreWindow *, ABI::Windows::UI::Core::IKeyEventArgs *args) -{ - Q_D(QWinRTScreen); - VirtualKey virtualKey; - HRESULT hr = args->get_VirtualKey(&virtualKey); - Q_ASSERT_SUCCEEDED(hr); - CorePhysicalKeyStatus status; - hr = args->get_KeyStatus(&status); - Q_ASSERT_SUCCEEDED(hr); - - Qt::Key key = qKeyFromVirtual(virtualKey); - - const bool wasPressed = d->activeKeys.contains(key); - if (wasPressed) { - if (!shouldAutoRepeat(key)) - return S_OK; - - d->activeKeys[key].isAutoRepeat = true; - // If the key was pressed before trigger a key release before the next key press - QWindowSystemInterface::handleExtendedKeyEvent( - topWindow(), - QEvent::KeyRelease, - key, - keyboardModifiers(), - !status.ScanCode ? -1 : status.ScanCode, - virtualKey, - 0, - QString(), - d->activeKeys.value(key).isAutoRepeat); - } else { - d->activeKeys.insert(key, KeyInfo(virtualKey)); - } - - // Defer character key presses to onCharacterReceived - if (key == Qt::Key_unknown || (key >= Qt::Key_Space && key <= Qt::Key_ydiaeresis)) - return S_OK; - - Qt::KeyboardModifiers modifiers = keyboardModifiers(); - // If the key actually pressed is a modifier key, then we remove its modifier key from the - // state, since a modifier-key can't have itself as a modifier (see qwindowskeymapper.cpp) - if (key == Qt::Key_Control) - modifiers = modifiers ^ Qt::ControlModifier; - else if (key == Qt::Key_Shift) - modifiers = modifiers ^ Qt::ShiftModifier; - else if (key == Qt::Key_Alt) - modifiers = modifiers ^ Qt::AltModifier; - - QWindowSystemInterface::handleExtendedKeyEvent( - topWindow(), - QEvent::KeyPress, - key, - modifiers, - !status.ScanCode ? -1 : status.ScanCode, - virtualKey, - 0, - QString(), - d->activeKeys.value(key).isAutoRepeat); - return S_OK; -} - -HRESULT QWinRTScreen::onKeyUp(ABI::Windows::UI::Core::ICoreWindow *, ABI::Windows::UI::Core::IKeyEventArgs *args) -{ - Q_D(QWinRTScreen); - VirtualKey virtualKey; - HRESULT hr = args->get_VirtualKey(&virtualKey); - Q_ASSERT_SUCCEEDED(hr); - CorePhysicalKeyStatus status; - hr = args->get_KeyStatus(&status); - Q_ASSERT_SUCCEEDED(hr); - - Qt::Key key = qKeyFromVirtual(virtualKey); - const KeyInfo info = d->activeKeys.take(key); - QWindowSystemInterface::handleExtendedKeyEvent( - topWindow(), - QEvent::KeyRelease, - key, - keyboardModifiers(), - !status.ScanCode ? -1 : status.ScanCode, - virtualKey, - 0, - info.text, - false); // The final key release does not have autoRepeat set on Windows - return S_OK; -} - -HRESULT QWinRTScreen::onCharacterReceived(ICoreWindow *, ICharacterReceivedEventArgs *args) -{ - Q_D(QWinRTScreen); - quint32 keyCode; - HRESULT hr = args->get_KeyCode(&keyCode); - Q_ASSERT_SUCCEEDED(hr); - CorePhysicalKeyStatus status; - hr = args->get_KeyStatus(&status); - Q_ASSERT_SUCCEEDED(hr); - - // Don't generate character events for non-printables; the meta key stage is enough - if (qIsNonPrintable(keyCode)) - return S_OK; - - const Qt::KeyboardModifiers modifiers = keyboardModifiers(); - const Qt::Key key = qKeyFromCode(keyCode, modifiers); - const QString text = QChar(keyCode); - KeyInfo &info = d->activeKeys[key]; - info.text = text; - QWindowSystemInterface::handleExtendedKeyEvent( - topWindow(), - QEvent::KeyPress, - key, - modifiers, - !status.ScanCode ? -1 : status.ScanCode, - info.virtualKey, - 0, - text, - info.isAutoRepeat); - return S_OK; -} - -HRESULT QWinRTScreen::onPointerEntered(ICoreWindow *, IPointerEventArgs *args) -{ - Q_D(QWinRTScreen); - qCDebug(lcQpaEvents) << __FUNCTION__; - - ComPtr<IPointerPoint> pointerPoint; - if (SUCCEEDED(args->get_CurrentPoint(&pointerPoint))) { - // Assumes full-screen window - Point point; - pointerPoint->get_Position(&point); - QPoint pos(point.X * d->scaleFactor, point.Y * d->scaleFactor); - - d->currentTargetWindow = topWindow(); - if (d->mouseGrabWindow) - d->currentTargetWindow = d->mouseGrabWindow.loadRelaxed()->window(); - - qCDebug(lcQpaEvents) << __FUNCTION__ << "handleEnterEvent" << d->currentTargetWindow << pos; - QWindowSystemInterface::handleEnterEvent(d->currentTargetWindow, pos, pos); - d->firstMouseMove = false; - } - return S_OK; -} - -HRESULT QWinRTScreen::onPointerExited(ICoreWindow *, IPointerEventArgs *args) -{ - Q_D(QWinRTScreen); - qCDebug(lcQpaEvents) << __FUNCTION__; - ComPtr<IPointerPoint> pointerPoint; - if (FAILED(args->get_CurrentPoint(&pointerPoint))) - return E_INVALIDARG; - - quint32 id; - if (FAILED(pointerPoint->get_PointerId(&id))) - return E_INVALIDARG; - - d->touchPoints.remove(id); - - if (d->mouseGrabWindow) - d->currentTargetWindow = d->mouseGrabWindow.loadRelaxed()->window(); - - qCDebug(lcQpaEvents) << __FUNCTION__ << "handleLeaveEvent" << d->currentTargetWindow; - QWindowSystemInterface::handleLeaveEvent(d->currentTargetWindow); - d->currentTargetWindow = nullptr; - return S_OK; -} - -// Required for qwinrtdrag.cpp -ComPtr<IPointerPoint> qt_winrt_lastPointerPoint; - -HRESULT QWinRTScreen::onPointerUpdated(ICoreWindow *, IPointerEventArgs *args) -{ - Q_D(QWinRTScreen); - qCDebug(lcQpaEvents) << __FUNCTION__; - ComPtr<IPointerPoint> pointerPoint; - if (FAILED(args->get_CurrentPoint(&pointerPoint))) - return E_INVALIDARG; - - qt_winrt_lastPointerPoint = pointerPoint; - // Common traits - point, modifiers, properties - Point point; - pointerPoint->get_Position(&point); - const QPointF pos(point.X * d->scaleFactor, point.Y * d->scaleFactor); - QPointF localPos = pos; - - const QPoint posPoint = pos.toPoint(); - QWindow *windowUnderPointer = windowAt(QHighDpiScaling::mapPositionFromNative(posPoint, this)); - d->currentTargetWindow = windowUnderPointer; - - if (d->mouseGrabWindow) - d->currentTargetWindow = d->mouseGrabWindow.loadRelaxed()->window(); - - if (d->currentTargetWindow) { - const QPointF globalPosDelta = pos - posPoint; - localPos = d->currentTargetWindow->mapFromGlobal(posPoint) + globalPosDelta; - } - - VirtualKeyModifiers modifiers; - args->get_KeyModifiers(&modifiers); - Qt::KeyboardModifiers mods; - if (modifiers & VirtualKeyModifiers_Control) - mods |= Qt::ControlModifier; - if (modifiers & VirtualKeyModifiers_Menu) - mods |= Qt::AltModifier; - if (modifiers & VirtualKeyModifiers_Shift) - mods |= Qt::ShiftModifier; - if (modifiers & VirtualKeyModifiers_Windows) - mods |= Qt::MetaModifier; - - ComPtr<IPointerPointProperties> properties; - if (FAILED(pointerPoint->get_Properties(&properties))) - return E_INVALIDARG; - - ComPtr<IPointerDevice> pointerDevice; - HRESULT hr = pointerPoint->get_PointerDevice(&pointerDevice); - RETURN_OK_IF_FAILED("Failed to get pointer device."); - - PointerDeviceType pointerDeviceType; - hr = pointerDevice->get_PointerDeviceType(&pointerDeviceType); - RETURN_OK_IF_FAILED("Failed to get pointer device type."); - - switch (pointerDeviceType) { - case PointerDeviceType_Mouse: { - qint32 delta; - properties->get_MouseWheelDelta(&delta); - if (delta) { - boolean isHorizontal; - properties->get_IsHorizontalMouseWheel(&isHorizontal); - QPoint angleDelta(isHorizontal ? delta : 0, isHorizontal ? 0 : delta); - qCDebug(lcQpaEvents) << __FUNCTION__ << "handleWheelEvent" << d->currentTargetWindow - << localPos << pos << angleDelta << mods; - QWindowSystemInterface::handleWheelEvent(d->currentTargetWindow, localPos, pos, QPoint(), angleDelta, mods); - break; - } - - boolean isPressed; - Qt::MouseButtons buttons = Qt::NoButton; - properties->get_IsLeftButtonPressed(&isPressed); - if (isPressed) - buttons |= Qt::LeftButton; - - properties->get_IsMiddleButtonPressed(&isPressed); - if (isPressed) - buttons |= Qt::MiddleButton; - - properties->get_IsRightButtonPressed(&isPressed); - if (isPressed) - buttons |= Qt::RightButton; - - properties->get_IsXButton1Pressed(&isPressed); - if (isPressed) - buttons |= Qt::XButton1; - - properties->get_IsXButton2Pressed(&isPressed); - if (isPressed) - buttons |= Qt::XButton2; - - // In case of a mouse grab we have to store the target of a press event - // to be able to send one additional release event to this target when the mouse - // button is released. This is a similar approach to AutoMouseCapture in the - // windows qpa backend. Otherwise the release might not be propagated and the original - // press event receiver considers a button to still be pressed, as in Qt Quick Controls 1 - // menus. - if (buttons != Qt::NoButton && d->currentPressWindow == nullptr && !d->mouseGrabWindow) - d->currentPressWindow = windowUnderPointer; - if (buttons == Qt::NoButton && d->currentPressWindow && d->mouseGrabWindow) { - const QPointF globalPosDelta = pos - posPoint; - const QPointF localPressPos = d->currentPressWindow->mapFromGlobal(posPoint) + globalPosDelta; - - qCDebug(lcQpaEvents) << __FUNCTION__ << "handleMouseEvent" << d->currentPressWindow - << localPressPos << pos << buttons << mods; - QWindowSystemInterface::handleMouseEvent(d->currentPressWindow, localPressPos, pos, buttons, mods); - d->currentPressWindow = nullptr; - } - // If the mouse button is released outside of a window, targetWindow is 0, but the event - // has to be delivered to the window, that initially received the mouse press. Do not reset - // d->currentTargetWindow though, as it is used (and reset) in onPointerExited. - if (buttons == Qt::NoButton && d->currentPressWindow && !d->currentTargetWindow) { - d->currentTargetWindow = d->currentPressWindow; - d->currentPressWindow = nullptr; - } - - qCDebug(lcQpaEvents) << __FUNCTION__ << "handleMouseEvent" << d->currentTargetWindow - << localPos << pos << buttons << mods; - QWindowSystemInterface::handleMouseEvent(d->currentTargetWindow, localPos, pos, buttons, mods); - - break; - } - case PointerDeviceType_Pen: - case PointerDeviceType_Touch: { - if (!d->touchDevice) { - d->touchDevice = new QTouchDevice; - d->touchDevice->setName(QStringLiteral("WinRTTouchScreen")); - d->touchDevice->setType(QTouchDevice::TouchScreen); - d->touchDevice->setCapabilities(QTouchDevice::Position | QTouchDevice::Area | QTouchDevice::Pressure | QTouchDevice::NormalizedPosition); - QWindowSystemInterface::registerTouchDevice(d->touchDevice); - } - - quint32 id; - pointerPoint->get_PointerId(&id); - - Rect area; - properties->get_ContactRect(&area); - - float pressure; - properties->get_Pressure(&pressure); - - boolean isPressed; - pointerPoint->get_IsInContact(&isPressed); - - // Devices like the Hololens set a static pressure of 0.0 or 0.5 - // (depending on the image) independent of the pressed state. - // In those cases we need to synthesize the pressure value. To our - // knowledge this does not apply to pens - if (pointerDeviceType == PointerDeviceType_Touch && (pressure == 0.0f || pressure == 0.5f)) - pressure = isPressed ? 1. : 0.; - - const QRectF areaRect(area.X * d->scaleFactor, area.Y * d->scaleFactor, - area.Width * d->scaleFactor, area.Height * d->scaleFactor); - - QHash<quint32, QWindowSystemInterface::TouchPoint>::iterator it = d->touchPoints.find(id); - if (it == d->touchPoints.end()) { - it = d->touchPoints.insert(id, QWindowSystemInterface::TouchPoint()); - it.value().id = id; - } - - const bool wasPressEvent = isPressed && it.value().pressure == 0.; - if (wasPressEvent) - it.value().state = Qt::TouchPointPressed; - else if (!isPressed && it.value().pressure > 0.) - it.value().state = Qt::TouchPointReleased; - else if (it.value().area == areaRect) - it.value().state = Qt::TouchPointStationary; - else - it.value().state = Qt::TouchPointMoved; - - it.value().area = areaRect; - it.value().normalPosition = QPointF(point.X/d->logicalRect.width(), point.Y/d->logicalRect.height()); - it.value().pressure = pressure; - - qCDebug(lcQpaEvents) << __FUNCTION__ << "handleTouchEvent" << d->currentTargetWindow - << d->touchDevice << d->touchPoints.values() << mods; - QWindowSystemInterface::handleTouchEvent(d->currentTargetWindow, d->touchDevice, d->touchPoints.values(), mods); - if (wasPressEvent) - it.value().state = Qt::TouchPointStationary; - - // Fall-through for pen to generate tablet event - if (pointerDeviceType != PointerDeviceType_Pen) - break; - - boolean isEraser; - properties->get_IsEraser(&isEraser); - int pointerType = isEraser ? 3 : 1; - - float xTilt; - properties->get_XTilt(&xTilt); - - float yTilt; - properties->get_YTilt(&yTilt); - - float rotation; - properties->get_Twist(&rotation); - - qCDebug(lcQpaEvents) << __FUNCTION__ << "handleTabletEvent" << d->currentTargetWindow - << isPressed << pos << pointerType << pressure << xTilt << yTilt - << rotation << id << mods; - QWindowSystemInterface::handleTabletEvent(d->currentTargetWindow, isPressed, pos, pos, 0, - pointerType, pressure, xTilt, yTilt, - 0, rotation, 0, id, mods); - - break; - } - } - - return S_OK; -} - -void QWinRTScreen::emulateMouseMove(const QPointF &point, MousePositionTransition transition) -{ - Q_D(QWinRTScreen); - qCDebug(lcQpaEvents) << __FUNCTION__ << point << transition; - if (transition == MousePositionTransition::StayedOut) - return; - qt_winrt_lastPointerPoint = nullptr; - const QPointF pos(point.x() * d->scaleFactor, point.y() * d->scaleFactor); - QPointF localPos = pos; - - const QPoint posPoint = pos.toPoint(); - QWindow *windowUnderPointer = windowAt(QHighDpiScaling::mapPositionFromNative(posPoint, this)); - d->currentTargetWindow = windowUnderPointer; - - if (d->mouseGrabWindow) - d->currentTargetWindow = d->mouseGrabWindow.loadRelaxed()->window(); - - if (d->currentTargetWindow) { - const QPointF globalPosDelta = pos - posPoint; - localPos = d->currentTargetWindow->mapFromGlobal(posPoint) + globalPosDelta; - } - - // In case of a mouse grab we have to store the target of a press event - // to be able to send one additional release event to this target when the mouse - // button is released. This is a similar approach to AutoMouseCapture in the - // windows qpa backend. Otherwise the release might not be propagated and the original - // press event receiver considers a button to still be pressed, as in Qt Quick Controls 1 - // menus. - if (d->currentPressWindow && d->mouseGrabWindow) { - const QPointF globalPosDelta = pos - posPoint; - const QPointF localPressPos = d->currentPressWindow->mapFromGlobal(posPoint) + globalPosDelta; - - qCDebug(lcQpaEvents) << __FUNCTION__ << "handleMouseEvent" << d->currentPressWindow - << localPressPos << pos << Qt::NoButton << Qt::NoModifier; - QWindowSystemInterface::handleMouseEvent(d->currentPressWindow, localPressPos, pos, - Qt::NoButton, Qt::NoModifier); - d->currentPressWindow = nullptr; - } - // If the mouse button is released outside of a window, targetWindow is 0, but the event - // has to be delivered to the window, that initially received the mouse press. Do not reset - // d->currentTargetWindow though, as it is used (and reset) in onPointerExited. - if (d->currentPressWindow && !d->currentTargetWindow) { - d->currentTargetWindow = d->currentPressWindow; - d->currentPressWindow = nullptr; - } - - if (transition == MousePositionTransition::MovedOut) { - qCDebug(lcQpaEvents) << __FUNCTION__ << "handleLeaveEvent" << d->currentTargetWindow; - QWindowSystemInterface::handleLeaveEvent(d->currentTargetWindow); - return; - } - - if (transition == MousePositionTransition::MovedIn || d->firstMouseMove) { - qCDebug(lcQpaEvents) << __FUNCTION__ << "handleEnterEvent" << d->currentTargetWindow - << localPos << pos; - QWindowSystemInterface::handleEnterEvent(d->currentTargetWindow, localPos, pos); - d->firstMouseMove = false; - } - qCDebug(lcQpaEvents) << __FUNCTION__ << "handleMouseEvent" << d->currentTargetWindow - << localPos << pos << Qt::NoButton << Qt::NoModifier; - QWindowSystemInterface::handleMouseEvent(d->currentTargetWindow, localPos, pos, Qt::NoButton, - Qt::NoModifier); -} - -void QWinRTScreen::setResizePending() -{ - Q_D(QWinRTScreen); - d->resizePending = true; -} - -bool QWinRTScreen::resizePending() const -{ - Q_D(const QWinRTScreen); - return d->resizePending; -} - -HRESULT QWinRTScreen::onActivated(ICoreWindow *, IWindowActivatedEventArgs *args) -{ - Q_D(QWinRTScreen); - qCDebug(lcQpaWindows) << __FUNCTION__; - - CoreWindowActivationState activationState; - args->get_WindowActivationState(&activationState); - if (activationState == CoreWindowActivationState_Deactivated) { - QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationInactive); - return S_OK; - } - - QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationActive); - - // Activate topWindow - if (!d->visibleWindows.isEmpty()) { - Qt::FocusReason focusReason = activationState == CoreWindowActivationState_PointerActivated - ? Qt::MouseFocusReason : Qt::ActiveWindowFocusReason; - QWindowSystemInterface::handleWindowActivated(topWindow(), focusReason); - } - return S_OK; -} - -HRESULT QWinRTScreen::onClosed(ICoreWindow *, ICoreWindowEventArgs *) -{ - qCDebug(lcQpaWindows) << __FUNCTION__; - - foreach (QWindow *w, QGuiApplication::topLevelWindows()) - QWindowSystemInterface::handleCloseEvent(w); - return S_OK; -} - -HRESULT QWinRTScreen::onVisibilityChanged(ICoreWindow *, IVisibilityChangedEventArgs *args) -{ - Q_D(QWinRTScreen); - boolean visible; - HRESULT hr = args ? args->get_Visible(&visible) : d->coreWindow->get_Visible(&visible); - RETURN_OK_IF_FAILED("Failed to get visibility."); - qCDebug(lcQpaWindows) << __FUNCTION__ << visible; - QWindowSystemInterface::handleApplicationStateChanged(visible ? Qt::ApplicationActive : Qt::ApplicationHidden); - if (visible) { - handleExpose(); - onWindowSizeChanged(nullptr, nullptr); - } - return S_OK; -} - -HRESULT QWinRTScreen::onOrientationChanged(IDisplayInformation *, IInspectable *) -{ - Q_D(QWinRTScreen); - qCDebug(lcQpaWindows) << __FUNCTION__; - DisplayOrientations displayOrientation; - HRESULT hr = d->displayInformation->get_CurrentOrientation(&displayOrientation); - RETURN_OK_IF_FAILED("Failed to get current orientations."); - - Qt::ScreenOrientation newOrientation = static_cast<Qt::ScreenOrientation>(static_cast<int>(qtOrientationsFromNative(displayOrientation))); - if (d->orientation != newOrientation) { - d->orientation = newOrientation; - qCDebug(lcQpaWindows) << " New orientation:" << newOrientation; - onWindowSizeChanged(nullptr, nullptr); - QWindowSystemInterface::handleScreenOrientationChange(screen(), d->orientation); - handleExpose(); // Clean broken frames caused by race between Qt and ANGLE - } - return S_OK; -} - -HRESULT QWinRTScreen::onDpiChanged(IDisplayInformation *, IInspectable *) -{ - Q_D(QWinRTScreen); - - HRESULT hr; - ResolutionScale resolutionScale; - hr = d->displayInformation->get_ResolutionScale(&resolutionScale); - d->scaleFactor = qreal(resolutionScale) / 100; - - qCDebug(lcQpaWindows) << __FUNCTION__ << "Scale Factor:" << d->scaleFactor; - - RETURN_OK_IF_FAILED("Failed to get scale factor"); - - FLOAT dpi; - hr = d->displayInformation->get_LogicalDpi(&dpi); - RETURN_OK_IF_FAILED("Failed to get logical DPI."); - d->logicalDpi = dpi; - - hr = d->displayInformation->get_RawDpiX(&dpi); - RETURN_OK_IF_FAILED("Failed to get x raw DPI."); - d->physicalDpi.first = dpi ? dpi : 96.0; - - hr = d->displayInformation->get_RawDpiY(&dpi); - RETURN_OK_IF_FAILED("Failed to get y raw DPI."); - d->physicalDpi.second = dpi ? dpi : 96.0; - qCDebug(lcQpaWindows) << __FUNCTION__ << "Logical DPI:" << d->logicalDpi - << "Physical DPI:" << d->physicalDpi; - - return S_OK; -} - -HRESULT QWinRTScreen::onRedirectReleased(ICorePointerRedirector *, IPointerEventArgs *args) -{ - // When dragging ends with a non-mouse input device then onRedirectRelease is invoked. - // QTBUG-58781 - qCDebug(lcQpaEvents) << __FUNCTION__; - return onPointerUpdated(nullptr, args); -} - -HRESULT QWinRTScreen::onWindowSizeChanged(IApplicationView *w, IInspectable *) -{ - Q_D(QWinRTScreen); - - HRESULT hr; - Rect windowSize; - - hr = d->coreWindow->get_Bounds(&windowSize); - RETURN_OK_IF_FAILED("Failed to get window bounds"); - d->logicalRect = QRectF(windowSize.X, windowSize.Y, windowSize.Width, windowSize.Height); - - Rect visibleRect; - hr = d->view2->get_VisibleBounds(&visibleRect); - RETURN_OK_IF_FAILED("Failed to get window visible bounds"); - d->visibleRect = QRectF(visibleRect.X, visibleRect.Y, visibleRect.Width, visibleRect.Height); - - qCDebug(lcQpaWindows) << __FUNCTION__ << d->logicalRect; - QWindowSystemInterface::handleScreenGeometryChange(screen(), geometry(), availableGeometry()); - QPlatformScreen::resizeMaximizedWindows(); - handleExpose(); - // If we "emulate" a resize, w will be nullptr.Checking w shows whether it's a real resize - if (w) - d->resizePending = false; - return S_OK; -} - -QT_END_NAMESPACE diff --git a/src/plugins/platforms/winrt/qwinrtscreen.h b/src/plugins/platforms/winrt/qwinrtscreen.h deleted file mode 100644 index 6b57780fa1..0000000000 --- a/src/plugins/platforms/winrt/qwinrtscreen.h +++ /dev/null @@ -1,168 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTSCREEN_H -#define QWINRTSCREEN_H - -#include <qpa/qplatformscreen.h> -#include <qpa/qwindowsysteminterface.h> - -namespace ABI { - namespace Windows { - namespace ApplicationModel { - struct ISuspendingEventArgs; - } - namespace UI { - namespace Core { - struct IAutomationProviderRequestedEventArgs; - struct ICharacterReceivedEventArgs; - struct ICorePointerRedirector; - struct ICoreWindow; - struct ICoreWindowEventArgs; - struct IKeyEventArgs; - struct IPointerEventArgs; - struct IVisibilityChangedEventArgs; - struct IWindowActivatedEventArgs; - } - namespace Xaml { - struct IDependencyObject; - struct IWindow; - } - namespace ViewManagement { - struct IApplicationView; - } - } - namespace Graphics { - namespace Display { - struct IDisplayInformation; - } - } - } -} -struct IInspectable; - -QT_BEGIN_NAMESPACE - -class QTouchDevice; -class QWinRTCursor; -class QWinRTInputContext; -class QWinRTScreenPrivate; -class QWinRTWindow; -class QWinRTScreen : public QPlatformScreen -{ -public: - explicit QWinRTScreen(); - ~QWinRTScreen() override; - - QRect geometry() const override; - QRect availableGeometry() const override; - int depth() const override; - QImage::Format format() const override; - QSizeF physicalSize() const override; - QDpi logicalDpi() const override; - qreal scaleFactor() const; - QPlatformCursor *cursor() const override; - Qt::KeyboardModifiers keyboardModifiers() const; - - Qt::ScreenOrientation nativeOrientation() const override; - Qt::ScreenOrientation orientation() const override; - - QWindow *topWindow() const; - QWindow *windowAt(const QPoint &pos); - void addWindow(QWindow *window); - void removeWindow(QWindow *window); - void raise(QWindow *window); - void lower(QWindow *window); - - bool setMouseGrabWindow(QWinRTWindow *window, bool grab); - QWinRTWindow* mouseGrabWindow() const; - - bool setKeyboardGrabWindow(QWinRTWindow *window, bool grab); - QWinRTWindow* keyboardGrabWindow() const; - - void updateWindowTitle(const QString &title); - - ABI::Windows::UI::Core::ICoreWindow *coreWindow() const; - ABI::Windows::UI::Xaml::IDependencyObject *canvas() const; - - void initialize(); - - void setCursorRect(const QRectF &cursorRect); - void setKeyboardRect(const QRectF &keyboardRect); - - enum class MousePositionTransition { - MovedOut, - MovedIn, - StayedIn, - StayedOut - }; - - void emulateMouseMove(const QPointF &point, MousePositionTransition transition); - - void setResizePending(); - bool resizePending() const; - -private: - void handleExpose(); - - HRESULT onKeyDown(ABI::Windows::UI::Core::ICoreWindow *, ABI::Windows::UI::Core::IKeyEventArgs *); - HRESULT onKeyUp(ABI::Windows::UI::Core::ICoreWindow *, ABI::Windows::UI::Core::IKeyEventArgs *); - HRESULT onCharacterReceived(ABI::Windows::UI::Core::ICoreWindow *, ABI::Windows::UI::Core::ICharacterReceivedEventArgs *); - HRESULT onPointerEntered(ABI::Windows::UI::Core::ICoreWindow *, ABI::Windows::UI::Core::IPointerEventArgs *); - HRESULT onPointerExited(ABI::Windows::UI::Core::ICoreWindow *, ABI::Windows::UI::Core::IPointerEventArgs *); - HRESULT onPointerUpdated(ABI::Windows::UI::Core::ICoreWindow *, ABI::Windows::UI::Core::IPointerEventArgs *); - - HRESULT onActivated(ABI::Windows::UI::Core::ICoreWindow *, ABI::Windows::UI::Core::IWindowActivatedEventArgs *); - - HRESULT onClosed(ABI::Windows::UI::Core::ICoreWindow *, ABI::Windows::UI::Core::ICoreWindowEventArgs *); - HRESULT onVisibilityChanged(ABI::Windows::UI::Core::ICoreWindow *, ABI::Windows::UI::Core::IVisibilityChangedEventArgs *); - - HRESULT onOrientationChanged(ABI::Windows::Graphics::Display::IDisplayInformation *, IInspectable *); - HRESULT onDpiChanged(ABI::Windows::Graphics::Display::IDisplayInformation *, IInspectable *); - HRESULT onWindowSizeChanged(ABI::Windows::UI::ViewManagement::IApplicationView *, IInspectable *); - HRESULT onRedirectReleased(ABI::Windows::UI::Core::ICorePointerRedirector *, ABI::Windows::UI::Core::IPointerEventArgs *); - - QScopedPointer<QWinRTScreenPrivate> d_ptr; - QRectF mCursorRect; - Q_DECLARE_PRIVATE(QWinRTScreen) -}; - -QT_END_NAMESPACE - -#endif // QWINRTSCREEN_H diff --git a/src/plugins/platforms/winrt/qwinrtservices.cpp b/src/plugins/platforms/winrt/qwinrtservices.cpp deleted file mode 100644 index 04d7417801..0000000000 --- a/src/plugins/platforms/winrt/qwinrtservices.cpp +++ /dev/null @@ -1,154 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwinrtservices.h" -#include "qwinrtfileengine.h" -#include <QtCore/QUrl> -#include <QtCore/QDir> -#include <QtCore/QCoreApplication> -#include <QtCore/qfunctions_winrt.h> -#include <private/qeventdispatcher_winrt_p.h> - -#include <wrl.h> -#include <windows.foundation.h> -#include <windows.storage.h> -#include <windows.system.h> -using namespace Microsoft::WRL; -using namespace Microsoft::WRL::Wrappers; -using namespace ABI::Windows::Foundation; -using namespace ABI::Windows::Storage; -using namespace ABI::Windows::System; - -QT_BEGIN_NAMESPACE - -class QWinRTServicesPrivate -{ -public: - ComPtr<IUriRuntimeClassFactory> uriFactory; - ComPtr<IStorageFileStatics> fileFactory; - ComPtr<ILauncherStatics> launcher; -}; - -QWinRTServices::QWinRTServices() - : d_ptr(new QWinRTServicesPrivate) -{ - Q_D(QWinRTServices); - - HRESULT hr; - hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Foundation_Uri).Get(), - IID_PPV_ARGS(&d->uriFactory)); - Q_ASSERT_X(SUCCEEDED(hr), Q_FUNC_INFO, qPrintable(qt_error_string(hr))); - - hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Storage_StorageFile).Get(), - IID_PPV_ARGS(&d->fileFactory)); - Q_ASSERT_X(SUCCEEDED(hr), Q_FUNC_INFO, qPrintable(qt_error_string(hr))); - - hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_System_Launcher).Get(), - IID_PPV_ARGS(&d->launcher)); - Q_ASSERT_X(SUCCEEDED(hr), Q_FUNC_INFO, qPrintable(qt_error_string(hr))); -} - -bool QWinRTServices::openUrl(const QUrl &url) -{ - Q_D(QWinRTServices); - - ComPtr<IUriRuntimeClass> uri; - QString urlString = url.toString(); - HStringReference uriString(reinterpret_cast<LPCWSTR>(urlString.utf16()), - uint(urlString.length())); - HRESULT hr = d->uriFactory->CreateUri(uriString.Get(), &uri); - RETURN_FALSE_IF_FAILED("Failed to create URI from QUrl."); - - boolean result; - hr = QEventDispatcherWinRT::runOnXamlThread([this, d, uri, &result]() { - ComPtr<IAsyncOperation<bool>> op; - HRESULT hr = d->launcher->LaunchUriAsync(uri.Get(), &op); - RETURN_HR_IF_FAILED("Failed to start URI launch."); - - hr = QWinRTFunctions::await(op, &result); - RETURN_HR_IF_FAILED("Failed to launch URI."); - return hr; - }); - RETURN_FALSE_IF_FAILED("Failed to launch URI from Xaml thread."); - - return result; -} - -bool QWinRTServices::openDocument(const QUrl &url) -{ - Q_D(QWinRTServices); - - HRESULT hr; - ComPtr<IStorageFile> file; - ComPtr<IStorageItem> item = QWinRTFileEngineHandler::registeredFile(url.toLocalFile()); - if (item) { - hr = item.As(&file); - if (FAILED(hr)) - qErrnoWarning(hr, "Failed to cast picked item to a file"); - } - if (!file) { - const QString pathString = QDir::toNativeSeparators(url.toLocalFile()); - HStringReference path(reinterpret_cast<LPCWSTR>(pathString.utf16()), - uint(pathString.length())); - ComPtr<IAsyncOperation<StorageFile *>> op; - hr = d->fileFactory->GetFileFromPathAsync(path.Get(), &op); - RETURN_FALSE_IF_FAILED("Failed to initialize file URI."); - - hr = QWinRTFunctions::await(op, file.GetAddressOf()); - RETURN_FALSE_IF_FAILED("Failed to get file URI."); - } - - boolean result; - { - hr = QEventDispatcherWinRT::runOnXamlThread([this, d, file, &result]() { - ComPtr<IAsyncOperation<bool>> op; - HRESULT hr = d->launcher->LaunchFileAsync(file.Get(), &op); - RETURN_HR_IF_FAILED("Failed to start file launch."); - - hr = QWinRTFunctions::await(op, &result); - RETURN_HR_IF_FAILED("Failed to launch file."); - return hr; - }); - RETURN_FALSE_IF_FAILED("Failed to launch file from Xaml thread."); - } - - return result; -} - -QT_END_NAMESPACE diff --git a/src/plugins/platforms/winrt/qwinrtservices.h b/src/plugins/platforms/winrt/qwinrtservices.h deleted file mode 100644 index 202ce722cf..0000000000 --- a/src/plugins/platforms/winrt/qwinrtservices.h +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTSERVICES_H -#define QWINRTSERVICES_H - -#include <qpa/qplatformservices.h> -#include <QtCore/QScopedPointer> - -QT_BEGIN_NAMESPACE - -class QWinRTServicesPrivate; -class QWinRTServices : public QPlatformServices -{ -public: - explicit QWinRTServices(); - ~QWinRTServices() override = default; - - bool openUrl(const QUrl &url) override; - bool openDocument(const QUrl &url) override; - -private: - QScopedPointer<QWinRTServicesPrivate> d_ptr; - Q_DECLARE_PRIVATE(QWinRTServices) -}; - -QT_END_NAMESPACE - -#endif // QWINRTSERVICES_H diff --git a/src/plugins/platforms/winrt/qwinrttheme.cpp b/src/plugins/platforms/winrt/qwinrttheme.cpp deleted file mode 100644 index 0e1504b1c1..0000000000 --- a/src/plugins/platforms/winrt/qwinrttheme.cpp +++ /dev/null @@ -1,342 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwinrttheme.h" -#include "qwinrtmessagedialoghelper.h" -#include "qwinrtfiledialoghelper.h" - -#include <QtCore/qfunctions_winrt.h> -#include <QtGui/QPalette> - -#include <QtFontDatabaseSupport/private/qwinrtfontdatabase_p.h> - -#include <wrl.h> -#include <windows.ui.h> -#include <windows.ui.viewmanagement.h> -#if _MSC_VER >= 1900 -#include <windows.foundation.metadata.h> -using namespace ABI::Windows::Foundation::Metadata; -#endif - -using namespace Microsoft::WRL; -using namespace Microsoft::WRL::Wrappers; -using namespace ABI::Windows::UI; -using namespace ABI::Windows::UI::ViewManagement; - -QT_BEGIN_NAMESPACE - -Q_LOGGING_CATEGORY(lcQpaTheme, "qt.qpa.theme") - -class QWinRTApiInformationHandler { -public: - QWinRTApiInformationHandler() - { - HRESULT hr; - hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Foundation_Metadata_ApiInformation).Get(), - IID_PPV_ARGS(&m_apiInformationStatics)); - Q_ASSERT_SUCCEEDED(hr); - } - - ComPtr<IApiInformationStatics> apiInformationStatics() const - { - return m_apiInformationStatics; - } - -private: - ComPtr<IApiInformationStatics> m_apiInformationStatics; -}; -Q_GLOBAL_STATIC(QWinRTApiInformationHandler, gApiHandler); - -static IUISettings *uiSettings() -{ - static ComPtr<IUISettings> settings; - if (!settings) { - HRESULT hr; - hr = RoActivateInstance(Wrappers::HString::MakeReference(RuntimeClass_Windows_UI_ViewManagement_UISettings).Get(), - &settings); - Q_ASSERT_SUCCEEDED(hr); - } - return settings.Get(); -} - -class QWinRTThemePrivate -{ -public: - QWinRTThemePrivate() - : monospaceFont(QWinRTFontDatabase::familyForStyleHint(QFont::Monospace)) - { - } - - QPalette palette; - QFont monospaceFont; -}; - -static inline QColor fromColor(const Color &color) -{ - return QColor(color.R, color.G, color.B, color.A); -} - -static bool uiColorSettings(const wchar_t *value, UIElementType type, Color *color) -{ - ComPtr<IApiInformationStatics> apiInformationStatics = gApiHandler->apiInformationStatics(); - if (!apiInformationStatics) { - qErrnoWarning("Could not get ApiInformationStatics"); - return false; - } - - static const HStringReference enumRef(L"Windows.UI.ViewManagement.UIElementType"); - HStringReference valueRef(value); - - HRESULT hr; - boolean exists; - hr = apiInformationStatics->IsEnumNamedValuePresent(enumRef.Get(), valueRef.Get(), &exists); - - if (hr != S_OK || !exists) - return false; - - return SUCCEEDED(uiSettings()->UIElementColor(type, color)); -} - -static void nativeColorSettings(QPalette &p) -{ - Color color; - - if (uiColorSettings(L"ActiveCaption", UIElementType_ActiveCaption, &color)) - p.setColor(QPalette::ToolTipBase, fromColor(color)); - - if (uiColorSettings(L"Background", UIElementType_Background, &color)) - p.setColor(QPalette::AlternateBase, fromColor(color)); - - if (uiColorSettings(L"ButtonFace", UIElementType_ButtonFace, &color)) { - p.setColor(QPalette::Button, fromColor(color)); - p.setColor(QPalette::Midlight, fromColor(color).lighter(110)); - p.setColor(QPalette::Light, fromColor(color).lighter(150)); - p.setColor(QPalette::Mid, fromColor(color).dark(130)); - p.setColor(QPalette::Dark, fromColor(color).dark(150)); - } - - if (uiColorSettings(L"ButtonText", UIElementType_ButtonText, &color)) { - p.setColor(QPalette::ButtonText, fromColor(color)); - p.setColor(QPalette::Text, fromColor(color)); - } - - if (uiColorSettings(L"CaptionText", UIElementType_CaptionText, &color)) - p.setColor(QPalette::ToolTipText, fromColor(color)); - - if (uiColorSettings(L"Highlight", UIElementType_Highlight, &color)) - p.setColor(QPalette::Highlight, fromColor(color)); - - if (uiColorSettings(L"HighlightText", UIElementType_HighlightText, &color)) - p.setColor(QPalette::HighlightedText, fromColor(color)); - - if (uiColorSettings(L"Window", UIElementType_Window, &color)) { - p.setColor(QPalette::Window, fromColor(color)); - p.setColor(QPalette::Base, fromColor(color)); - } - - if (uiColorSettings(L"Hotlight", UIElementType_Hotlight, &color)) - p.setColor(QPalette::BrightText, fromColor(color)); - - // Starting with SDK 15063 those have been removed. -#ifndef QT_WINRT_DISABLE_PHONE_COLORS - //Phone related - ComPtr<IApiInformationStatics> apiInformationStatics = gApiHandler->apiInformationStatics(); - boolean phoneApiPresent = false; - HRESULT hr; - HStringReference phoneRef(L"Windows.Phone.PhoneContract"); - hr = apiInformationStatics.Get()->IsApiContractPresentByMajor(phoneRef.Get(), 1, &phoneApiPresent); - if (FAILED(hr) || !phoneApiPresent) - return; - - if (uiColorSettings(L"PopupBackground", UIElementType_PopupBackground, &color)) { - p.setColor(QPalette::ToolTipBase, fromColor(color)); - p.setColor(QPalette::AlternateBase, fromColor(color)); - } - - if (uiColorSettings(L"NonTextMedium", UIElementType_NonTextMedium, &color)) - p.setColor(QPalette::Button, fromColor(color)); - - if (uiColorSettings(L"NonTextMediumHigh", UIElementType_NonTextMediumHigh, &color)) - p.setColor(QPalette::Midlight, fromColor(color)); - - if (uiColorSettings(L"NonTextHigh", UIElementType_NonTextHigh, &color)) - p.setColor(QPalette::Light, fromColor(color)); - - if (uiColorSettings(L"NonTextMediumLow", UIElementType_NonTextMediumLow, &color)) - p.setColor(QPalette::Mid, fromColor(color)); - - if (uiColorSettings(L"NonTextLow", UIElementType_NonTextLow, &color)) - p.setColor(QPalette::Dark, fromColor(color)); - - if (uiColorSettings(L"TextHigh", UIElementType_TextHigh, &color)) { - p.setColor(QPalette::ButtonText, fromColor(color)); - p.setColor(QPalette::Text, fromColor(color)); - p.setColor(QPalette::WindowText, fromColor(color)); - } - - if (uiColorSettings(L"TextMedium", UIElementType_TextMedium, &color)) - p.setColor(QPalette::ToolTipText, fromColor(color)); - - if (uiColorSettings(L"AccentColor", UIElementType_AccentColor, &color)) - p.setColor(QPalette::Highlight, fromColor(color)); - - if (uiColorSettings(L"PageBackground", UIElementType_PageBackground, &color)) { - p.setColor(QPalette::Window, fromColor(color)); - p.setColor(QPalette::Base, fromColor(color)); - } - - if (uiColorSettings(L"TextContrastWithHigh", UIElementType_TextContrastWithHigh, &color)) - p.setColor(QPalette::BrightText, fromColor(color)); -#endif // QT_WINRT_DISABLE_PHONE_COLORS -} - -QWinRTTheme::QWinRTTheme() - : d_ptr(new QWinRTThemePrivate) -{ - Q_D(QWinRTTheme); - qCDebug(lcQpaTheme) << __FUNCTION__; - - nativeColorSettings(d->palette); -} - -bool QWinRTTheme::usePlatformNativeDialog(DialogType type) const -{ - qCDebug(lcQpaTheme) << __FUNCTION__ << type; - static bool useNativeDialogs = qEnvironmentVariableIsSet("QT_USE_WINRT_NATIVE_DIALOGS") - ? qEnvironmentVariableIntValue("QT_USE_WINRT_NATIVE_DIALOGS") : true; - - if (type == FileDialog || type == MessageDialog) - return useNativeDialogs; - return false; -} - -QPlatformDialogHelper *QWinRTTheme::createPlatformDialogHelper(DialogType type) const -{ - qCDebug(lcQpaTheme) << __FUNCTION__ << type; - switch (type) { - case FileDialog: - return new QWinRTFileDialogHelper; - case MessageDialog: - return new QWinRTMessageDialogHelper(this); - default: - break; - } - return QPlatformTheme::createPlatformDialogHelper(type); -} - -QVariant QWinRTTheme::styleHint(QPlatformIntegration::StyleHint hint) -{ - qCDebug(lcQpaTheme) << __FUNCTION__ << hint; - HRESULT hr; - switch (hint) { - case QPlatformIntegration::CursorFlashTime: { - quint32 blinkRate; - hr = uiSettings()->get_CaretBlinkRate(&blinkRate); - RETURN_IF_FAILED("Failed to get caret blink rate", return defaultThemeHint(CursorFlashTime)); - return blinkRate; - } - case QPlatformIntegration::KeyboardInputInterval: - return defaultThemeHint(KeyboardInputInterval); - case QPlatformIntegration::MouseDoubleClickInterval: { - quint32 doubleClickTime; - hr = uiSettings()->get_DoubleClickTime(&doubleClickTime); - RETURN_IF_FAILED("Failed to get double click time", return defaultThemeHint(MouseDoubleClickInterval)); - return doubleClickTime; - } - case QPlatformIntegration::StartDragDistance: - return defaultThemeHint(StartDragDistance); - case QPlatformIntegration::StartDragTime: - return defaultThemeHint(StartDragTime); - case QPlatformIntegration::KeyboardAutoRepeatRate: - return defaultThemeHint(KeyboardAutoRepeatRate); - case QPlatformIntegration::ShowIsFullScreen: - return false; - case QPlatformIntegration::PasswordMaskDelay: - return defaultThemeHint(PasswordMaskDelay); - case QPlatformIntegration::FontSmoothingGamma: - return qreal(1.7); - case QPlatformIntegration::StartDragVelocity: - return defaultThemeHint(StartDragVelocity); - case QPlatformIntegration::UseRtlExtensions: - return false; - case QPlatformIntegration::PasswordMaskCharacter: - return defaultThemeHint(PasswordMaskCharacter); - case QPlatformIntegration::SetFocusOnTouchRelease: - return true; - case QPlatformIntegration::ShowIsMaximized: - return true; - case QPlatformIntegration::MousePressAndHoldInterval: - return defaultThemeHint(MousePressAndHoldInterval); - default: - break; - } - return QVariant(); -} - -QVariant QWinRTTheme::themeHint(ThemeHint hint) const -{ - qCDebug(lcQpaTheme) << __FUNCTION__ << hint; - switch (hint) { - case StyleNames: - return QStringList() << QStringLiteral("fusion") << QStringLiteral("windows"); - default: - return QPlatformTheme::themeHint(hint); - } -} - -const QPalette *QWinRTTheme::palette(Palette type) const -{ - Q_D(const QWinRTTheme); - qCDebug(lcQpaTheme) << __FUNCTION__ << type; - if (type == SystemPalette) - return &d->palette; - return QPlatformTheme::palette(type); -} - -const QFont *QWinRTTheme::font(QPlatformTheme::Font type) const -{ - Q_D(const QWinRTTheme); - qCDebug(lcQpaTheme) << __FUNCTION__ << type; - if (type == QPlatformTheme::FixedFont) - return &d->monospaceFont; - - return QPlatformTheme::font(type); -} - -QT_END_NAMESPACE diff --git a/src/plugins/platforms/winrt/qwinrttheme.h b/src/plugins/platforms/winrt/qwinrttheme.h deleted file mode 100644 index acf5a54a94..0000000000 --- a/src/plugins/platforms/winrt/qwinrttheme.h +++ /dev/null @@ -1,72 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTTHEME_H -#define QWINRTTHEME_H - -#include <qpa/qplatformtheme.h> -#include <qpa/qplatformintegration.h> -#include <QtCore/QLoggingCategory> - -QT_BEGIN_NAMESPACE - -Q_DECLARE_LOGGING_CATEGORY(lcQpaTheme) - -class QWinRTThemePrivate; -class QWinRTTheme : public QPlatformTheme -{ -public: - QWinRTTheme(); - - bool usePlatformNativeDialog(DialogType type) const override; - QPlatformDialogHelper *createPlatformDialogHelper(DialogType type) const override; - - const QPalette *palette(Palette type = SystemPalette) const override; - const QFont *font(Font type = SystemFont) const override; - - static QVariant styleHint(QPlatformIntegration::StyleHint hint); - QVariant themeHint(ThemeHint hint) const override; -private: - QScopedPointer<QWinRTThemePrivate> d_ptr; - Q_DECLARE_PRIVATE(QWinRTTheme) -}; - -QT_END_NAMESPACE - -#endif // QWINRTTHEME_H diff --git a/src/plugins/platforms/winrt/qwinrtwindow.cpp b/src/plugins/platforms/winrt/qwinrtwindow.cpp deleted file mode 100644 index 73816b6512..0000000000 --- a/src/plugins/platforms/winrt/qwinrtwindow.cpp +++ /dev/null @@ -1,438 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwinrtwindow.h" -#include "qwinrtscreen.h" -#include <private/qeventdispatcher_winrt_p.h> - -#include <EGL/egl.h> -#include <EGL/eglext.h> - -#include <qfunctions_winrt.h> -#include <qpa/qplatformscreen.h> -#include <qpa/qwindowsysteminterface.h> -#include <QtGui/QGuiApplication> -#include <QtGui/QOpenGLContext> -#include <QtGui/QWindow> -#include <QtEglSupport/private/qeglconvenience_p.h> - -#include <functional> -#include <wrl.h> -#include <windows.foundation.h> -#include <windows.foundation.collections.h> -#include <windows.ui.xaml.h> -#include <windows.ui.xaml.controls.h> -#include <windows.ui.viewmanagement.h> - -using namespace ABI::Windows::UI::ViewManagement; -using namespace Microsoft::WRL; -using namespace Microsoft::WRL::Wrappers; -using namespace ABI::Windows::Foundation; -using namespace ABI::Windows::Foundation::Collections; -using namespace ABI::Windows::UI; -using namespace ABI::Windows::UI::Xaml; -using namespace ABI::Windows::UI::Xaml::Controls; - -QT_BEGIN_NAMESPACE - -Q_LOGGING_CATEGORY(lcQpaWindows, "qt.qpa.windows"); - -static void setUIElementVisibility(IUIElement *uiElement, bool visibility) -{ - Q_ASSERT(uiElement); - QEventDispatcherWinRT::runOnXamlThread([uiElement, visibility]() { - HRESULT hr; - hr = uiElement->put_Visibility(visibility ? Visibility_Visible : Visibility_Collapsed); - Q_ASSERT_SUCCEEDED(hr); - return S_OK; - }); -} - -class QWinRTWindowPrivate -{ -public: - QWinRTScreen *screen; - - QSurfaceFormat surfaceFormat; - QString windowTitle; - Qt::WindowStates state; - EGLDisplay display; - EGLSurface surface; - - ComPtr<ISwapChainPanel> swapChainPanel; - ComPtr<ICanvasStatics> canvas; - ComPtr<IUIElement> uiElement; -}; - -QWinRTWindow::QWinRTWindow(QWindow *window) - : QPlatformWindow(window) - , d_ptr(new QWinRTWindowPrivate) -{ - Q_D(QWinRTWindow); - qCDebug(lcQpaWindows) << __FUNCTION__ << this; - - d->surface = EGL_NO_SURFACE; - d->display = EGL_NO_DISPLAY; - d->screen = static_cast<QWinRTScreen *>(screen()); - handleContentOrientationChange(window->contentOrientation()); - - d->surfaceFormat.setMajorVersion(3); - d->surfaceFormat.setMinorVersion(0); - d->surfaceFormat.setAlphaBufferSize(0); - d->surfaceFormat.setRedBufferSize(8); - d->surfaceFormat.setGreenBufferSize(8); - d->surfaceFormat.setBlueBufferSize(8); - d->surfaceFormat.setDepthBufferSize(24); - d->surfaceFormat.setStencilBufferSize(8); - d->surfaceFormat.setRenderableType(QSurfaceFormat::OpenGLES); - d->surfaceFormat.setSamples(1); - d->surfaceFormat.setSwapBehavior(QSurfaceFormat::DoubleBuffer); - - HRESULT hr; - hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_UI_Xaml_Controls_Canvas).Get(), - IID_PPV_ARGS(&d->canvas)); - Q_ASSERT_SUCCEEDED(hr); - hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - // Create a new swapchain and place it inside the canvas - HRESULT hr; - hr = RoActivateInstance(HString::MakeReference(RuntimeClass_Windows_UI_Xaml_Controls_SwapChainPanel).Get(), - &d->swapChainPanel); - Q_ASSERT_SUCCEEDED(hr); - hr = d->swapChainPanel.As(&d->uiElement); - Q_ASSERT_SUCCEEDED(hr); - - ComPtr<Xaml::IFrameworkElement> frameworkElement; - hr = d->swapChainPanel.As(&frameworkElement); - Q_ASSERT_SUCCEEDED(hr); - const QSizeF size = QSizeF(d->screen->geometry().size()) / d->screen->scaleFactor(); - hr = frameworkElement->put_Width(size.width()); - Q_ASSERT_SUCCEEDED(hr); - hr = frameworkElement->put_Height(size.height()); - Q_ASSERT_SUCCEEDED(hr); - - ComPtr<IDependencyObject> canvas = d->screen->canvas(); - ComPtr<IPanel> panel; - hr = canvas.As(&panel); - Q_ASSERT_SUCCEEDED(hr); - ComPtr<IVector<UIElement *>> children; - hr = panel->get_Children(&children); - Q_ASSERT_SUCCEEDED(hr); - hr = children->Append(d->uiElement.Get()); - Q_ASSERT_SUCCEEDED(hr); - return S_OK; - }); - Q_ASSERT_SUCCEEDED(hr); - - setWindowFlags(window->flags()); - setWindowState(window->windowStates()); - setWindowTitle(window->title()); - - setGeometry(window->geometry()); -} - -QWinRTWindow::~QWinRTWindow() -{ - Q_D(QWinRTWindow); - qCDebug(lcQpaWindows) << __FUNCTION__ << this; - - HRESULT hr; - hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - HRESULT hr; - ComPtr<IDependencyObject> canvas = d->screen->canvas(); - ComPtr<IPanel> panel; - hr = canvas.As(&panel); - Q_ASSERT_SUCCEEDED(hr); - ComPtr<IVector<UIElement *>> children; - hr = panel->get_Children(&children); - Q_ASSERT_SUCCEEDED(hr); - quint32 index; - boolean found; - hr = children->IndexOf(d->uiElement.Get(), &index, &found); - Q_ASSERT_SUCCEEDED(hr); - if (found) { - hr = children->RemoveAt(index); - Q_ASSERT_SUCCEEDED(hr); - } - return S_OK; - }); - RETURN_VOID_IF_FAILED("Failed to completely destroy window resources, likely because the application is shutting down"); - - if (d->screen->mouseGrabWindow() == this) - d->screen->setMouseGrabWindow(this, false); - if (d->screen->keyboardGrabWindow() == this) - d->screen->setKeyboardGrabWindow(this, false); - - d->screen->removeWindow(window()); - - if (!d->surface) - return; - - qCDebug(lcQpaWindows) << __FUNCTION__ << ": Destroying surface"; - - EGLBoolean value = eglDestroySurface(d->display, d->surface); - d->surface = EGL_NO_SURFACE; - if (Q_UNLIKELY(value == EGL_FALSE)) - qCritical("Failed to destroy EGL window surface: 0x%x", eglGetError()); -} - -QSurfaceFormat QWinRTWindow::format() const -{ - Q_D(const QWinRTWindow); - return d->surfaceFormat; -} - -bool QWinRTWindow::isActive() const -{ - Q_D(const QWinRTWindow); - return d->screen->topWindow() == window(); -} - -bool QWinRTWindow::isExposed() const -{ - Q_D(const QWinRTWindow); - const bool exposed = isActive() && !d->screen->resizePending(); - return exposed; -} - -void QWinRTWindow::setGeometry(const QRect &rect) -{ - Q_D(QWinRTWindow); - qCDebug(lcQpaWindows) << __FUNCTION__ << this << rect; - - const Qt::WindowFlags windowFlags = window()->flags(); - const Qt::WindowFlags windowType = windowFlags & Qt::WindowType_Mask; - if (window()->isTopLevel() && (windowType == Qt::Window || windowType == Qt::Dialog)) { - const QRect screenRect = windowFlags & Qt::MaximizeUsingFullscreenGeometryHint - ? d->screen->geometry() : d->screen->availableGeometry(); - qCDebug(lcQpaWindows) << __FUNCTION__ << "top-level, overwrite" << screenRect; - QPlatformWindow::setGeometry(screenRect); - QWindowSystemInterface::handleGeometryChange(window(), geometry()); - } else { - QPlatformWindow::setGeometry(rect); - QWindowSystemInterface::handleGeometryChange(window(), rect); - } - - HRESULT hr; - hr = QEventDispatcherWinRT::runOnXamlThread([this, d]() { - HRESULT hr; - const QRect windowGeometry = geometry(); - const QPointF topLeft= QPointF(windowGeometry.topLeft()) / d->screen->scaleFactor(); - hr = d->canvas->SetTop(d->uiElement.Get(), topLeft.y()); - Q_ASSERT_SUCCEEDED(hr); - hr = d->canvas->SetLeft(d->uiElement.Get(), topLeft.x()); - Q_ASSERT_SUCCEEDED(hr); - ComPtr<Xaml::IFrameworkElement> frameworkElement; - hr = d->swapChainPanel.As(&frameworkElement); - Q_ASSERT_SUCCEEDED(hr); - const QSizeF size = QSizeF(windowGeometry.size()) / d->screen->scaleFactor(); - hr = frameworkElement->put_Width(size.width()); - Q_ASSERT_SUCCEEDED(hr); - hr = frameworkElement->put_Height(size.height()); - Q_ASSERT_SUCCEEDED(hr); - qCDebug(lcQpaWindows) << __FUNCTION__ << "(setGeometry Xaml)" << this - << topLeft << size; - return S_OK; - }); - Q_ASSERT_SUCCEEDED(hr); -} - -void QWinRTWindow::setVisible(bool visible) -{ - Q_D(QWinRTWindow); - qCDebug(lcQpaWindows) << __FUNCTION__ << this << visible; - - if (!window()->isTopLevel()) - return; - if (visible) { - d->screen->addWindow(window()); - setUIElementVisibility(d->uiElement.Get(), d->state != Qt::WindowMinimized); - } else { - d->screen->removeWindow(window()); - setUIElementVisibility(d->uiElement.Get(), false); - } -} - -void QWinRTWindow::setWindowTitle(const QString &title) -{ - Q_D(QWinRTWindow); - d->windowTitle = title; - - if (d->screen->topWindow() == window()) - d->screen->updateWindowTitle(title); -} - -void QWinRTWindow::raise() -{ - Q_D(QWinRTWindow); - qCDebug(lcQpaWindows) << __FUNCTION__ << this; - if (!window()->isTopLevel()) - return; - d->screen->raise(window()); -} - -void QWinRTWindow::lower() -{ - Q_D(QWinRTWindow); - qCDebug(lcQpaWindows) << __FUNCTION__ << this; - if (!window()->isTopLevel()) - return; - d->screen->lower(window()); -} - -WId QWinRTWindow::winId() const -{ - Q_D(const QWinRTWindow); - return WId(d->swapChainPanel.Get()); -} - -qreal QWinRTWindow::devicePixelRatio() const -{ - return screen()->devicePixelRatio(); -} - -void QWinRTWindow::setWindowState(Qt::WindowStates state) -{ - Q_D(QWinRTWindow); - qCDebug(lcQpaWindows) << __FUNCTION__ << this << state; - - if (d->state == state) - return; - - if (state & Qt::WindowMinimized) { - setUIElementVisibility(d->uiElement.Get(), false); - d->state = state; - return; - } - - if (state & Qt::WindowFullScreen) { - HRESULT hr; - boolean success; - hr = QEventDispatcherWinRT::runOnXamlThread([&hr, &success]() { - ComPtr<IApplicationViewStatics2> applicationViewStatics; - hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_UI_ViewManagement_ApplicationView).Get(), - IID_PPV_ARGS(&applicationViewStatics)); - RETURN_HR_IF_FAILED("Could not access application view statics."); - ComPtr<IApplicationView> view; - hr = applicationViewStatics->GetForCurrentView(&view); - RETURN_HR_IF_FAILED("Could not access application view."); - ComPtr<IApplicationView3> view3; - hr = view.As(&view3); - Q_ASSERT_SUCCEEDED(hr); - hr = view3->TryEnterFullScreenMode(&success); - return hr; - }); - if (FAILED(hr) || !success) { - qCDebug(lcQpaWindows) << "Failed to enter full screen mode."; - return; - } - d->screen->setResizePending(); - d->state = state; - return; - } - - if (d->state & Qt::WindowFullScreen) { - HRESULT hr; - hr = QEventDispatcherWinRT::runOnXamlThread([&hr]() { - ComPtr<IApplicationViewStatics2> applicationViewStatics; - hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_UI_ViewManagement_ApplicationView).Get(), - IID_PPV_ARGS(&applicationViewStatics)); - RETURN_HR_IF_FAILED("Could not access application view statics."); - ComPtr<IApplicationView> view; - hr = applicationViewStatics->GetForCurrentView(&view); - RETURN_HR_IF_FAILED("Could not access application view."); - ComPtr<IApplicationView3> view3; - hr = view.As(&view3); - Q_ASSERT_SUCCEEDED(hr); - hr = view3->ExitFullScreenMode(); - return hr; - }); - if (FAILED(hr)) { - qCDebug(lcQpaWindows) << "Failed to exit full screen mode."; - return; - } - d->screen->setResizePending(); - } - - if (d->state & Qt::WindowMinimized || state == Qt::WindowNoState || state == Qt::WindowActive) - setUIElementVisibility(d->uiElement.Get(), true); - - d->state = state; -} - -bool QWinRTWindow::setMouseGrabEnabled(bool grab) -{ - Q_D(QWinRTWindow); - if (!isActive() && grab) { - qWarning("%s: Not setting mouse grab for invisible window %s/'%s'", - __FUNCTION__, window()->metaObject()->className(), - qPrintable(window()->objectName())); - return false; - } - return d->screen->setMouseGrabWindow(this, grab); -} - -bool QWinRTWindow::setKeyboardGrabEnabled(bool grab) -{ - Q_D(QWinRTWindow); - return d->screen->setKeyboardGrabWindow(this, grab); -} - -EGLSurface QWinRTWindow::eglSurface() const -{ - Q_D(const QWinRTWindow); - return d->surface; -} - -void QWinRTWindow::createEglSurface(EGLDisplay display, EGLConfig config) -{ - Q_D(QWinRTWindow); - if (d->surface == EGL_NO_SURFACE) { - d->display = display; - QEventDispatcherWinRT::runOnXamlThread([this, d, display, config]() { - d->surface = eglCreateWindowSurface(display, config, - reinterpret_cast<EGLNativeWindowType>(winId()), - nullptr); - if (Q_UNLIKELY(d->surface == EGL_NO_SURFACE)) - qCritical("Failed to create EGL window surface: 0x%x", eglGetError()); - return S_OK; - }); - } -} - -QT_END_NAMESPACE diff --git a/src/plugins/platforms/winrt/qwinrtwindow.h b/src/plugins/platforms/winrt/qwinrtwindow.h deleted file mode 100644 index 0445e6bf54..0000000000 --- a/src/plugins/platforms/winrt/qwinrtwindow.h +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTWINDOW_H -#define QWINRTWINDOW_H - -#include <QtCore/QLoggingCategory> -#include <qpa/qplatformwindow.h> -#include <qpa/qwindowsysteminterface.h> -#include <EGL/egl.h> - -QT_BEGIN_NAMESPACE - -Q_DECLARE_LOGGING_CATEGORY(lcQpaWindows) - -class QWinRTWindowPrivate; -class QWinRTWindow : public QPlatformWindow -{ -public: - QWinRTWindow(QWindow *window); - ~QWinRTWindow() override; - - QSurfaceFormat format() const override; - bool isActive() const override; - bool isExposed() const override; - void setGeometry(const QRect &rect) override; - void setVisible(bool visible) override; - void setWindowTitle(const QString &title) override; - void raise() override; - void lower() override; - - WId winId() const override; - - qreal devicePixelRatio() const override; - void setWindowState(Qt::WindowStates state) override; - - bool setMouseGrabEnabled(bool grab) override; - bool setKeyboardGrabEnabled(bool grab) override; - - EGLSurface eglSurface() const; - void createEglSurface(EGLDisplay display, EGLConfig config); - -private: - QScopedPointer<QWinRTWindowPrivate> d_ptr; - Q_DECLARE_PRIVATE(QWinRTWindow) -}; - -QT_END_NAMESPACE - -#endif // QWINRTWINDOW_H diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiaaccessibility.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiaaccessibility.cpp deleted file mode 100644 index 40274fb967..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiaaccessibility.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include "qwinrtuiaaccessibility.h" -#include "qwinrtuiamainprovider.h" - -#include <QtGui/QAccessible> -#include <QtGui/QWindow> -#include <QtGui/QGuiApplication> -#include <QtGui/private/qguiapplication_p.h> -#include <QtCore/qt_windows.h> -#include <qpa/qplatformintegration.h> - -QT_BEGIN_NAMESPACE - -QWinRTUiaAccessibility::QWinRTUiaAccessibility() -{ -} - -QWinRTUiaAccessibility::~QWinRTUiaAccessibility() -{ -} - -// Handles UI Automation window messages. -void QWinRTUiaAccessibility::activate() -{ - // Start handling accessibility internally - QGuiApplicationPrivate::platformIntegration()->accessibility()->setActive(true); -} - -// Handles accessibility update notifications. -void QWinRTUiaAccessibility::notifyAccessibilityUpdate(QAccessibleEvent *event) -{ - if (!event) - return; - - QAccessibleInterface *accessible = event->accessibleInterface(); - if (!isActive() || !accessible || !accessible->isValid()) - return; - - switch (event->type()) { - case QAccessible::Focus: - QWinRTUiaMainProvider::notifyFocusChange(event); - break; - case QAccessible::ObjectCreated: - case QAccessible::ObjectDestroyed: - case QAccessible::ObjectShow: - case QAccessible::ObjectHide: - case QAccessible::ObjectReorder: - QWinRTUiaMainProvider::notifyVisibilityChange(event); - break; - case QAccessible::StateChanged: - QWinRTUiaMainProvider::notifyStateChange(static_cast<QAccessibleStateChangeEvent *>(event)); - break; - case QAccessible::ValueChanged: - QWinRTUiaMainProvider::notifyValueChange(static_cast<QAccessibleValueChangeEvent *>(event)); - break; - case QAccessible::TextAttributeChanged: - case QAccessible::TextColumnChanged: - case QAccessible::TextInserted: - case QAccessible::TextRemoved: - case QAccessible::TextUpdated: - case QAccessible::TextSelectionChanged: - case QAccessible::TextCaretMoved: - QWinRTUiaMainProvider::notifyTextChange(event); - break; - default: - break; - } -} - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiaaccessibility.h b/src/plugins/platforms/winrt/uiautomation/qwinrtuiaaccessibility.h deleted file mode 100644 index b966271e21..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiaaccessibility.h +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTUIAACCESSIBILITY_H -#define QWINRTUIAACCESSIBILITY_H - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include <qpa/qplatformaccessibility.h> - -QT_BEGIN_NAMESPACE - -// WinRT platform accessibility implemented over UI Automation. -class QWinRTUiaAccessibility : public QPlatformAccessibility -{ -public: - explicit QWinRTUiaAccessibility(); - virtual ~QWinRTUiaAccessibility(); - static void activate(); - void notifyAccessibilityUpdate(QAccessibleEvent *event) override; -}; - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) - -#endif // QWINRTUIAACCESSIBILITY_H diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiabaseprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiabaseprovider.cpp deleted file mode 100644 index ee53714caa..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiabaseprovider.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include "qwinrtuiabaseprovider.h" - -#include <QtGui/QAccessible> -#include <QtGui/QAccessibleInterface> -#include <QtCore/QLoggingCategory> -#include <QtCore/QString> - -QT_BEGIN_NAMESPACE - -QWinRTUiaBaseProvider::QWinRTUiaBaseProvider(QAccessible::Id id) : - m_id(id) -{ -} - -QWinRTUiaBaseProvider::~QWinRTUiaBaseProvider() -{ -} - -QAccessibleInterface *QWinRTUiaBaseProvider::accessibleInterface() const -{ - QAccessibleInterface *accessible = QAccessible::accessibleInterface(m_id); - if (accessible && accessible->isValid()) - return accessible; - return nullptr; -} - -QAccessible::Id QWinRTUiaBaseProvider::id() const -{ - return m_id; -} - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiabaseprovider.h b/src/plugins/platforms/winrt/uiautomation/qwinrtuiabaseprovider.h deleted file mode 100644 index d8837354dc..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiabaseprovider.h +++ /dev/null @@ -1,72 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTUIABASEPROVIDER_H -#define QWINRTUIABASEPROVIDER_H - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include <QtGui/QAccessible> -#include <QtGui/QAccessibleInterface> -#include <QtCore/QPointer> - -QT_BEGIN_NAMESPACE - -// Base class for UI Automation providers. -class QWinRTUiaBaseProvider : public QObject -{ - Q_OBJECT - Q_DISABLE_COPY(QWinRTUiaBaseProvider) -public: - explicit QWinRTUiaBaseProvider(QAccessible::Id id); - virtual ~QWinRTUiaBaseProvider(); - - QAccessibleInterface *accessibleInterface() const; - QAccessible::Id id() const; - -private: - QAccessible::Id m_id; -}; - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) - -#endif // QWINRTUIABASEPROVIDER_H diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiacontrolmetadata.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiacontrolmetadata.cpp deleted file mode 100644 index 4e406a3545..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiacontrolmetadata.cpp +++ /dev/null @@ -1,182 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include "qwinrtuiacontrolmetadata.h" -#include "qwinrtuiautils.h" - -#include <QtCore/QLoggingCategory> -#include <QtCore/QString> - -QT_BEGIN_NAMESPACE - -using namespace QWinRTUiAutomation; - -QWinRTUiaControlMetadata::QWinRTUiaControlMetadata() -{ -} - -QWinRTUiaControlMetadata::QWinRTUiaControlMetadata(QAccessible::Id id) -{ - update(id); -} - -void QWinRTUiaControlMetadata::update(QAccessible::Id id) -{ - if (QAccessibleInterface *accessible = accessibleForId(id)) { - m_automationId = generateAutomationId(accessible); - m_className = generateClassName(accessible); - m_controlName = generateControlName(accessible); - m_role = generateRole(accessible); - m_state = accessible->state(); - m_accelerator = accessible->text(QAccessible::Accelerator); - m_access = accessible->text(QAccessible::Accelerator); - m_help = accessible->text(QAccessible::Help); - m_description = accessible->text(QAccessible::Description); - m_value = accessible->text(QAccessible::Value); - m_boundingRect = accessible->rect(); - updateValueData(accessible); - updateTableData(accessible); - updateTextData(accessible); - } -} - -QString QWinRTUiaControlMetadata::generateControlName(QAccessibleInterface *accessible) -{ - const bool clientTopLevel = (accessible->role() == QAccessible::Client) - && accessible->parent() && (accessible->parent()->role() == QAccessible::Application); - - QString name = accessible->text(QAccessible::Name); - if (name.isEmpty() && clientTopLevel) - name = QCoreApplication::applicationName(); - return name; -} - -QString QWinRTUiaControlMetadata::generateClassName(QAccessibleInterface *accessible) -{ - QString name; - - if (QObject *obj = accessible->object()) - name = QLatin1String(obj->metaObject()->className()); - return name; -} - -// Generates an ID based on the name of the controls and their parents. -QString QWinRTUiaControlMetadata::generateAutomationId(QAccessibleInterface *accessible) -{ - QString autid; - QObject *obj = accessible->object(); - while (obj) { - QString name = obj->objectName(); - if (name.isEmpty()) { - autid = QStringLiteral(""); - break; - } - if (!autid.isEmpty()) - autid.prepend(QLatin1Char('.')); - autid.prepend(name); - obj = obj->parent(); - } - return autid; -} - -QAccessible::Role QWinRTUiaControlMetadata::generateRole(QAccessibleInterface *accessible) -{ - const bool clientTopLevel = (accessible->role() == QAccessible::Client) - && accessible->parent() && (accessible->parent()->role() == QAccessible::Application); - - if (clientTopLevel) { - // Reports a top-level widget as a window. - return QAccessible::Window; - } else { - return accessible->role(); - } -} - -void QWinRTUiaControlMetadata::updateValueData(QAccessibleInterface *accessible) -{ - if (QAccessibleValueInterface *valueInterface = accessible->valueInterface()) { - m_minimumValue = valueInterface->minimumValue().toDouble(); - m_maximumValue = valueInterface->maximumValue().toDouble(); - m_currentValue = valueInterface->currentValue().toDouble(); - m_minimumStepSize = valueInterface->minimumStepSize().toDouble(); - } else { - m_minimumValue = 0.0; - m_maximumValue = 0.0; - m_currentValue = 0.0; - m_minimumStepSize = 0.0; - } -} - -void QWinRTUiaControlMetadata::updateTableData(QAccessibleInterface *accessible) -{ - if (QAccessibleTableInterface *tableInterface = accessible->tableInterface()) { - m_rowIndex = 0; - m_columnIndex = 0; - m_rowCount = tableInterface->rowCount(); - m_columnCount = tableInterface->columnCount(); - } else if (QAccessibleTableCellInterface *tableCellInterface = accessible->tableCellInterface()) { - m_rowIndex = tableCellInterface->rowIndex(); - m_columnIndex = tableCellInterface->columnIndex(); - m_rowCount = tableCellInterface->rowExtent(); - m_columnCount = tableCellInterface->columnExtent(); - } else { - m_rowIndex = 0; - m_columnIndex = 0; - m_rowCount = 0; - m_columnCount = 0; - } -} - -void QWinRTUiaControlMetadata::updateTextData(QAccessibleInterface *accessible) -{ - if (QAccessibleTextInterface *textInterface = accessible->textInterface()) { - m_cursorPosition = textInterface->cursorPosition(); - m_text = textInterface->text(0, textInterface->characterCount()); - } else { - m_cursorPosition = 0; - m_text = QStringLiteral(""); - } -} - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiacontrolmetadata.h b/src/plugins/platforms/winrt/uiautomation/qwinrtuiacontrolmetadata.h deleted file mode 100644 index 769f073a1b..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiacontrolmetadata.h +++ /dev/null @@ -1,117 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTUIACONTROLMETADATA_H -#define QWINRTUIACONTROLMETADATA_H - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include <QString> -#include <QtGui/QAccessible> -#include <QtGui/QAccessibleInterface> - -QT_BEGIN_NAMESPACE - -// Cacheable control metadata -class QWinRTUiaControlMetadata -{ -public: - QWinRTUiaControlMetadata(); - QWinRTUiaControlMetadata(QAccessible::Id id); - void update(QAccessible::Id id); - QString automationId() const { return m_automationId; } - QString className() const { return m_className; } - QString controlName() const { return m_controlName; } - QString accelerator() const { return m_accelerator; } - QString access() const { return m_access; } - QString help() const { return m_help; } - QString description() const { return m_description; } - QString value() const { return m_value; } - QString text() const { return m_text; } - QAccessible::Role role() const { return m_role; } - QAccessible::State state() const { return m_state; } - QRect boundingRect() const { return m_boundingRect; } - double minimumValue() const { return m_minimumValue; } - double maximumValue() const { return m_maximumValue; } - double currentValue() const { return m_currentValue; } - double minimumStepSize() const { return m_minimumStepSize; } - int rowIndex() const { return m_rowIndex; } - int columnIndex() const { return m_columnIndex; } - int rowCount() const { return m_rowCount; } - int columnCount() const { return m_columnCount; } - int characterCount() const { return m_text.length(); } - int cursorPosition() const { return m_cursorPosition; } - -private: - QString generateControlName(QAccessibleInterface *accessible); - QString generateClassName(QAccessibleInterface *accessible); - QString generateAutomationId(QAccessibleInterface *accessible); - QAccessible::Role generateRole(QAccessibleInterface *accessible); - void updateValueData(QAccessibleInterface *accessible); - void updateTableData(QAccessibleInterface *accessible); - void updateTextData(QAccessibleInterface *accessible); - QString m_automationId; - QString m_className; - QString m_controlName; - QString m_accelerator; - QString m_access; - QString m_help; - QString m_description; - QString m_value; - QString m_text; - QAccessible::Role m_role = QAccessible::NoRole; - QAccessible::State m_state; - QRect m_boundingRect; - double m_minimumValue = 0.0; - double m_maximumValue = 0.0; - double m_currentValue = 0.0; - double m_minimumStepSize = 0.0; - int m_rowIndex = 0; - int m_columnIndex = 0; - int m_rowCount = 0; - int m_columnCount = 0; - int m_cursorPosition = 0; -}; - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) - -#endif // QWINRTUIACONTROLMETADATA_H diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiaemptypropertyvalue.h b/src/plugins/platforms/winrt/uiautomation/qwinrtuiaemptypropertyvalue.h deleted file mode 100644 index 35e4df75fc..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiaemptypropertyvalue.h +++ /dev/null @@ -1,108 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTUIAEMPTYPROPERTYVALUE_H -#define QWINRTUIAEMPTYPROPERTYVALUE_H - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include <wrl.h> -#include <windows.ui.xaml.h> - -QT_BEGIN_NAMESPACE - -// Implements an empty property value. -class QWinRTUiaEmptyPropertyValue : - public Microsoft::WRL::RuntimeClass<ABI::Windows::Foundation::IPropertyValue> -{ - InspectableClass(L"QWinRTUiaEmptyPropertyValue", BaseTrust); -public: - - HRESULT STDMETHODCALLTYPE get_Type(ABI::Windows::Foundation::PropertyType *value) - { - *value = ABI::Windows::Foundation::PropertyType_Empty; - return S_OK; - } - - HRESULT STDMETHODCALLTYPE get_IsNumericScalar(boolean*) { return E_FAIL; } - HRESULT STDMETHODCALLTYPE GetUInt8(BYTE*) { return E_FAIL; } - HRESULT STDMETHODCALLTYPE GetInt16(INT16*) { return E_FAIL; } - HRESULT STDMETHODCALLTYPE GetUInt16(UINT16*) { return E_FAIL; } - HRESULT STDMETHODCALLTYPE GetInt32(INT32*) { return E_FAIL; } - HRESULT STDMETHODCALLTYPE GetUInt32(UINT32*) { return E_FAIL; } - HRESULT STDMETHODCALLTYPE GetInt64(INT64*) { return E_FAIL; } - HRESULT STDMETHODCALLTYPE GetUInt64(UINT64*) { return E_FAIL; } - HRESULT STDMETHODCALLTYPE GetSingle(FLOAT*) { return E_FAIL; } - HRESULT STDMETHODCALLTYPE GetDouble(DOUBLE*) { return E_FAIL; } - HRESULT STDMETHODCALLTYPE GetChar16(WCHAR*) { return E_FAIL; } - HRESULT STDMETHODCALLTYPE GetBoolean(boolean*) { return E_FAIL; } - HRESULT STDMETHODCALLTYPE GetString(HSTRING*) { return E_FAIL; } - HRESULT STDMETHODCALLTYPE GetGuid(GUID*) { return E_FAIL; } - HRESULT STDMETHODCALLTYPE GetDateTime(ABI::Windows::Foundation::DateTime*) { return E_FAIL; } - HRESULT STDMETHODCALLTYPE GetTimeSpan(ABI::Windows::Foundation::TimeSpan*) { return E_FAIL; } - HRESULT STDMETHODCALLTYPE GetPoint(ABI::Windows::Foundation::Point*) { return E_FAIL; } - HRESULT STDMETHODCALLTYPE GetSize(ABI::Windows::Foundation::Size*) { return E_FAIL; } - HRESULT STDMETHODCALLTYPE GetRect(ABI::Windows::Foundation::Rect*) { return E_FAIL; } - HRESULT STDMETHODCALLTYPE GetUInt8Array(UINT32*, BYTE**) { return E_FAIL; } - HRESULT STDMETHODCALLTYPE GetInt16Array(UINT32*, INT16**) { return E_FAIL; } - HRESULT STDMETHODCALLTYPE GetUInt16Array(UINT32*, UINT16**) { return E_FAIL; } - HRESULT STDMETHODCALLTYPE GetInt32Array(UINT32*, INT32**) { return E_FAIL; } - HRESULT STDMETHODCALLTYPE GetUInt32Array(UINT32*, UINT32**) { return E_FAIL; } - HRESULT STDMETHODCALLTYPE GetInt64Array(UINT32*, INT64**) { return E_FAIL; } - HRESULT STDMETHODCALLTYPE GetUInt64Array(UINT32*, UINT64**) { return E_FAIL; } - HRESULT STDMETHODCALLTYPE GetSingleArray(UINT32*, FLOAT**) { return E_FAIL; } - HRESULT STDMETHODCALLTYPE GetDoubleArray(UINT32*, DOUBLE**) { return E_FAIL; } - HRESULT STDMETHODCALLTYPE GetChar16Array(UINT32*, WCHAR**) { return E_FAIL; } - HRESULT STDMETHODCALLTYPE GetBooleanArray(UINT32*, boolean**) { return E_FAIL; } - HRESULT STDMETHODCALLTYPE GetStringArray(UINT32*, HSTRING**) { return E_FAIL; } - HRESULT STDMETHODCALLTYPE GetInspectableArray(UINT32*, IInspectable***) { return E_FAIL; } - HRESULT STDMETHODCALLTYPE GetGuidArray(UINT32*, GUID**) { return E_FAIL; } - HRESULT STDMETHODCALLTYPE GetDateTimeArray(UINT32*, ABI::Windows::Foundation::DateTime**) { return E_FAIL; } - HRESULT STDMETHODCALLTYPE GetTimeSpanArray(UINT32*, ABI::Windows::Foundation::TimeSpan**) { return E_FAIL; } - HRESULT STDMETHODCALLTYPE GetPointArray(UINT32*, ABI::Windows::Foundation::Point**) { return E_FAIL; } - HRESULT STDMETHODCALLTYPE GetSizeArray(UINT32*, ABI::Windows::Foundation::Size**) { return E_FAIL; } - HRESULT STDMETHODCALLTYPE GetRectArray(UINT32*, ABI::Windows::Foundation::Rect**) { return E_FAIL; } -}; - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) - -#endif // QWINRTUIAEMPTYPROPERTYVALUE_H diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiagriditemprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiagriditemprovider.cpp deleted file mode 100644 index 355dbf7d20..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiagriditemprovider.cpp +++ /dev/null @@ -1,160 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include "qwinrtuiagriditemprovider.h" -#include "qwinrtuiamainprovider.h" -#include "qwinrtuiametadatacache.h" -#include "qwinrtuiautils.h" - -#include <QtGui/QAccessible> -#include <QtGui/QAccessibleInterface> -#include <QtCore/QLoggingCategory> -#include <QtCore/QString> -#include <QtCore/private/qeventdispatcher_winrt_p.h> - -#include <memory> - -QT_BEGIN_NAMESPACE - -using namespace QWinRTUiAutomation; -using namespace ABI::Windows::UI::Xaml::Automation; -using namespace ABI::Windows::UI::Xaml::Automation::Provider; -using namespace ABI::Windows::UI::Xaml::Automation::Peers; - -QWinRTUiaGridItemProvider::QWinRTUiaGridItemProvider(QAccessible::Id id) : - QWinRTUiaBaseProvider(id) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; -} - -QWinRTUiaGridItemProvider::~QWinRTUiaGridItemProvider() -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; -} - -// Returns the column index of the item. -HRESULT STDMETHODCALLTYPE QWinRTUiaGridItemProvider::get_Column(INT32 *value) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!value) - return E_INVALIDARG; - - QSharedPointer<QWinRTUiaControlMetadata> metadata = QWinRTUiaMetadataCache::instance()->metadataForId(id()); - *value = metadata->columnIndex(); - return S_OK; -} - -// Returns the number of columns occupied by the item. -HRESULT STDMETHODCALLTYPE QWinRTUiaGridItemProvider::get_ColumnSpan(INT32 *value) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!value) - return E_INVALIDARG; - - QSharedPointer<QWinRTUiaControlMetadata> metadata = QWinRTUiaMetadataCache::instance()->metadataForId(id()); - *value = metadata->columnCount(); - return S_OK; -} - -// Returns the provider for the containing table/tree. -HRESULT STDMETHODCALLTYPE QWinRTUiaGridItemProvider::get_ContainingGrid(IIRawElementProviderSimple **value) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!value) - return E_INVALIDARG; - *value = nullptr; - - auto accid = id(); - auto elementId = std::make_shared<QAccessible::Id>(0); - - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementId]() { - if (QAccessibleInterface *accessible = accessibleForId(accid)) { - if (QAccessibleTableCellInterface *tableCellInterface = accessible->tableCellInterface()) { - if (QAccessibleInterface *table = tableCellInterface->table()) { - *elementId = idForAccessible(table); - QWinRTUiaMetadataCache::instance()->load(*elementId); - } - } - } - return S_OK; - }))) { - return E_FAIL; - } - - if (!*elementId) - return S_OK; - - return QWinRTUiaMainProvider::rawProviderForAccessibleId(*elementId, value); -} - -// Returns the row index of the item. -HRESULT STDMETHODCALLTYPE QWinRTUiaGridItemProvider::get_Row(INT32 *value) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!value) - return E_INVALIDARG; - - QSharedPointer<QWinRTUiaControlMetadata> metadata = QWinRTUiaMetadataCache::instance()->metadataForId(id()); - *value = metadata->rowIndex(); - return S_OK; -} - -// Returns the number of rows occupied by the item. -HRESULT STDMETHODCALLTYPE QWinRTUiaGridItemProvider::get_RowSpan(INT32 *value) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!value) - return E_INVALIDARG; - - QSharedPointer<QWinRTUiaControlMetadata> metadata = QWinRTUiaMetadataCache::instance()->metadataForId(id()); - *value = metadata->rowCount(); - return S_OK; -} - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiagriditemprovider.h b/src/plugins/platforms/winrt/uiautomation/qwinrtuiagriditemprovider.h deleted file mode 100644 index 70504fc555..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiagriditemprovider.h +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTUIAGRIDITEMPROVIDER_H -#define QWINRTUIAGRIDITEMPROVIDER_H - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include "qwinrtuiabaseprovider.h" - -#include <wrl.h> -#include <windows.ui.xaml.h> - -QT_BEGIN_NAMESPACE - -// Implements the Grid Item control pattern provider. Used by items within a table/tree. -class QWinRTUiaGridItemProvider : - public QWinRTUiaBaseProvider, - public Microsoft::WRL::RuntimeClass<ABI::Windows::UI::Xaml::Automation::Provider::IGridItemProvider> -{ - Q_OBJECT - Q_DISABLE_COPY(QWinRTUiaGridItemProvider) - InspectableClass(L"QWinRTUiaGridItemProvider", BaseTrust); - -public: - explicit QWinRTUiaGridItemProvider(QAccessible::Id id); - virtual ~QWinRTUiaGridItemProvider(); - - // IGridItemProvider - HRESULT STDMETHODCALLTYPE get_Column(INT32 *value) override; - HRESULT STDMETHODCALLTYPE get_ColumnSpan(INT32 *value) override; - HRESULT STDMETHODCALLTYPE get_ContainingGrid(ABI::Windows::UI::Xaml::Automation::Provider::IIRawElementProviderSimple **value) override; - HRESULT STDMETHODCALLTYPE get_Row(INT32 *value) override; - HRESULT STDMETHODCALLTYPE get_RowSpan(INT32 *value) override; -}; - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) - -#endif // QWINRTUIAGRIDITEMPROVIDER_H diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiagridprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiagridprovider.cpp deleted file mode 100644 index 3bd90f6850..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiagridprovider.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include "qwinrtuiagridprovider.h" -#include "qwinrtuiamainprovider.h" -#include "qwinrtuiametadatacache.h" -#include "qwinrtuiautils.h" - -#include <QtGui/QAccessible> -#include <QtGui/QAccessibleInterface> -#include <QtCore/QLoggingCategory> -#include <QtCore/QString> -#include <QtCore/private/qeventdispatcher_winrt_p.h> - -#include <memory> - -QT_BEGIN_NAMESPACE - -using namespace QWinRTUiAutomation; -using namespace ABI::Windows::UI::Xaml::Automation; -using namespace ABI::Windows::UI::Xaml::Automation::Provider; -using namespace ABI::Windows::UI::Xaml::Automation::Peers; - -QWinRTUiaGridProvider::QWinRTUiaGridProvider(QAccessible::Id id) : - QWinRTUiaBaseProvider(id) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; -} - -QWinRTUiaGridProvider::~QWinRTUiaGridProvider() -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; -} - -// Returns the number of columns. -HRESULT STDMETHODCALLTYPE QWinRTUiaGridProvider::get_ColumnCount(INT32 *value) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!value) - return E_INVALIDARG; - - QSharedPointer<QWinRTUiaControlMetadata> metadata = QWinRTUiaMetadataCache::instance()->metadataForId(id()); - *value = metadata->columnCount(); - return S_OK; -} - -// Returns the number of rows. -HRESULT STDMETHODCALLTYPE QWinRTUiaGridProvider::get_RowCount(INT32 *value) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!value) - return E_INVALIDARG; - - QSharedPointer<QWinRTUiaControlMetadata> metadata = QWinRTUiaMetadataCache::instance()->metadataForId(id()); - *value = metadata->rowCount(); - return S_OK; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaGridProvider::GetItem(INT32 row, INT32 column, IIRawElementProviderSimple **returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!returnValue) - return E_INVALIDARG; - *returnValue = nullptr; - - auto accid = id(); - auto elementId = std::make_shared<QAccessible::Id>(0); - - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, row, column, elementId]() { - if (QAccessibleInterface *accessible = accessibleForId(accid)) { - if (QAccessibleTableInterface *tableInterface = accessible->tableInterface()) { - if ((row >= 0) && (row < tableInterface->rowCount()) && (column >= 0) && (column < tableInterface->columnCount())) { - if (QAccessibleInterface *cell = tableInterface->cellAt(row, column)) { - *elementId = idForAccessible(cell); - QWinRTUiaMetadataCache::instance()->load(*elementId); - } - } - } - } - return S_OK; - }))) { - return E_FAIL; - } - - if (!*elementId) - return E_FAIL; - - return QWinRTUiaMainProvider::rawProviderForAccessibleId(*elementId, returnValue); -} - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiagridprovider.h b/src/plugins/platforms/winrt/uiautomation/qwinrtuiagridprovider.h deleted file mode 100644 index d6dfaed315..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiagridprovider.h +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTUIAGRIDPROVIDER_H -#define QWINRTUIAGRIDPROVIDER_H - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include "qwinrtuiabaseprovider.h" - -#include <wrl.h> -#include <windows.ui.xaml.h> - -QT_BEGIN_NAMESPACE - -// Implements the Grid control pattern provider. Used by tables/trees. -class QWinRTUiaGridProvider : - public QWinRTUiaBaseProvider, - public Microsoft::WRL::RuntimeClass<ABI::Windows::UI::Xaml::Automation::Provider::IGridProvider> -{ - Q_OBJECT - Q_DISABLE_COPY(QWinRTUiaGridProvider) - InspectableClass(L"QWinRTUiaGridProvider", BaseTrust); - -public: - explicit QWinRTUiaGridProvider(QAccessible::Id id); - virtual ~QWinRTUiaGridProvider(); - - // IGridProvider - HRESULT STDMETHODCALLTYPE get_ColumnCount(INT32 *value) override; - HRESULT STDMETHODCALLTYPE get_RowCount(INT32 *value) override; - HRESULT STDMETHODCALLTYPE GetItem(INT32 row, INT32 column, ABI::Windows::UI::Xaml::Automation::Provider::IIRawElementProviderSimple **returnValue) override; -}; - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) - -#endif // QWINRTUIAGRIDPROVIDER_H diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiainvokeprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiainvokeprovider.cpp deleted file mode 100644 index e2cf7bc107..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiainvokeprovider.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include "qwinrtuiainvokeprovider.h" -#include "qwinrtuiametadatacache.h" -#include "qwinrtuiautils.h" - -#include <QtGui/QAccessible> -#include <QtGui/QAccessibleInterface> -#include <QtCore/QLoggingCategory> -#include <QtCore/QString> -#include <QtCore/private/qeventdispatcher_winrt_p.h> - -QT_BEGIN_NAMESPACE - -using namespace QWinRTUiAutomation; -using namespace ABI::Windows::UI::Xaml::Automation; -using namespace ABI::Windows::UI::Xaml::Automation::Provider; - -QWinRTUiaInvokeProvider::QWinRTUiaInvokeProvider(QAccessible::Id id) : - QWinRTUiaBaseProvider(id) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; -} - -QWinRTUiaInvokeProvider::~QWinRTUiaInvokeProvider() -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaInvokeProvider::Invoke() -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - auto accid = id(); - - QEventDispatcherWinRT::runOnMainThread([accid]() { - if (QAccessibleInterface *accessible = accessibleForId(accid)) - if (QAccessibleActionInterface *actionInterface = accessible->actionInterface()) - actionInterface->doAction(QAccessibleActionInterface::pressAction()); - QWinRTUiaMetadataCache::instance()->load(accid); - return S_OK; - }, 0); - return S_OK; -} - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiainvokeprovider.h b/src/plugins/platforms/winrt/uiautomation/qwinrtuiainvokeprovider.h deleted file mode 100644 index dfe7917a16..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiainvokeprovider.h +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTUIAINVOKEPROVIDER_H -#define QWINRTUIAINVOKEPROVIDER_H - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include "qwinrtuiabaseprovider.h" - -#include <wrl.h> -#include <windows.ui.xaml.h> - -QT_BEGIN_NAMESPACE - -// Implements the Invoke control pattern provider. -class QWinRTUiaInvokeProvider : - public QWinRTUiaBaseProvider, - public Microsoft::WRL::RuntimeClass<ABI::Windows::UI::Xaml::Automation::Provider::IInvokeProvider> -{ - Q_OBJECT - Q_DISABLE_COPY(QWinRTUiaInvokeProvider) - InspectableClass(L"QWinRTUiaInvokeProvider", BaseTrust); - -public: - explicit QWinRTUiaInvokeProvider(QAccessible::Id id); - virtual ~QWinRTUiaInvokeProvider(); - - // IInvokeProvider - HRESULT STDMETHODCALLTYPE Invoke() override; -}; - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) - -#endif // QWINRTUIAINVOKEPROVIDER_H diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.cpp deleted file mode 100644 index 0b1db306bd..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.cpp +++ /dev/null @@ -1,787 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include "qwinrtuiamainprovider.h" -#include "qwinrtuiaprovidercache.h" -#include "qwinrtuiavalueprovider.h" -#include "qwinrtuiarangevalueprovider.h" -#include "qwinrtuiatextprovider.h" -#include "qwinrtuiatoggleprovider.h" -#include "qwinrtuiainvokeprovider.h" -#include "qwinrtuiaselectionprovider.h" -#include "qwinrtuiaselectionitemprovider.h" -#include "qwinrtuiatableprovider.h" -#include "qwinrtuiatableitemprovider.h" -#include "qwinrtuiagridprovider.h" -#include "qwinrtuiagriditemprovider.h" -#include "qwinrtuiapeervector.h" -#include "qwinrtuiametadatacache.h" -#include "qwinrtuiaemptypropertyvalue.h" -#include "qwinrtuiautils.h" - -#include <QCoreApplication> -#include <QSemaphore> -#include <QtCore/QLoggingCategory> -#include <QtCore/qfunctions_winrt.h> -#include <QtCore/private/qeventdispatcher_winrt_p.h> - -#include <memory> - -using namespace QWinRTUiAutomation; -using namespace Microsoft::WRL; -using namespace Microsoft::WRL::Wrappers; -using namespace ABI::Windows::System; -using namespace ABI::Windows::UI; -using namespace ABI::Windows::UI::Core; -using namespace ABI::Windows::UI::Xaml; -using namespace ABI::Windows::UI::Xaml::Automation; -using namespace ABI::Windows::UI::Xaml::Automation::Provider; -using namespace ABI::Windows::UI::Xaml::Automation::Peers; -using namespace ABI::Windows::Foundation; -using namespace ABI::Windows::Foundation::Collections; - -QT_BEGIN_NAMESPACE - -QWinRTUiaMainProvider::QWinRTUiaMainProvider(QAccessible::Id id) - : QWinRTUiaBaseProvider(id) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - ComPtr<IAutomationPeerFactory> factory; - HRESULT hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_UI_Xaml_Automation_Peers_AutomationPeer).Get(), IID_PPV_ARGS(&factory)); - Q_ASSERT_SUCCEEDED(hr); - - hr = factory->CreateInstance(this, &m_base, &m_core); - Q_ASSERT_SUCCEEDED(hr); -} - -QWinRTUiaMainProvider::~QWinRTUiaMainProvider() -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::QueryInterface(REFIID iid, LPVOID *iface) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!iface) - return E_POINTER; - *iface = nullptr; - - if (iid == IID_IUnknown) { - *iface = static_cast<IAutomationPeerOverrides *>(this); - AddRef(); - return S_OK; - } else if (iid == IID_IAutomationPeerOverrides) { - *iface = static_cast<IAutomationPeerOverrides *>(this); - AddRef(); - return S_OK; - } else { - return m_base.CopyTo(iid, iface); - } -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetIids(ULONG *iidCount, IID **iids) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - *iidCount = 0; - *iids = nullptr; - return S_OK; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetRuntimeClassName(HSTRING *className) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - return qHString(QStringLiteral("QWinRTUiaMainProvider"), className); -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetTrustLevel(TrustLevel *trustLevel) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - *trustLevel = TrustLevel::BaseTrust; - return S_OK; -} - -// Returns a cached instance of the provider for a specific accessible interface. -QWinRTUiaMainProvider *QWinRTUiaMainProvider::providerForAccessibleId(QAccessible::Id id) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - QWinRTUiaProviderCache *providerCache = QWinRTUiaProviderCache::instance(); - QWinRTUiaMainProvider *provider = qobject_cast<QWinRTUiaMainProvider *>(providerCache->providerForId(id)); - - if (provider) { - provider->AddRef(); - } else { - ComPtr<QWinRTUiaMainProvider> p = Make<QWinRTUiaMainProvider>(id); - provider = p.Get(); - provider->AddRef(); - providerCache->insert(id, provider); - } - return provider; -} - -// Returns an IIRawElementProviderSimple for a specific accessible interface. -HRESULT QWinRTUiaMainProvider::rawProviderForAccessibleId(QAccessible::Id elementId, - IIRawElementProviderSimple **returnValue) -{ - if (!returnValue) - return E_INVALIDARG; - *returnValue = nullptr; - - if (ComPtr<QWinRTUiaMainProvider> provider = providerForAccessibleId(elementId)) { - ComPtr<IAutomationPeer> automationPeer; - if (SUCCEEDED(provider.As(&automationPeer))) { - ComPtr<IAutomationPeerProtected> automationPeerProtected; - if (SUCCEEDED(provider.As(&automationPeerProtected))) { - return automationPeerProtected->ProviderFromPeer(automationPeer.Get(), returnValue); - } - } - } - return E_FAIL; -} - -// Returns an array of IIRawElementProviderSimple instances for a list of accessible interface ids. -HRESULT QWinRTUiaMainProvider::rawProviderArrayForAccessibleIdList(const QVarLengthArray<QAccessible::Id> &elementIds, - UINT32 *returnValueSize, - IIRawElementProviderSimple ***returnValue) -{ - if (!returnValueSize || !returnValue) - return E_INVALIDARG; - *returnValueSize = 0; - *returnValue = nullptr; - - QList<IIRawElementProviderSimple *> rawProviderList; - - for (auto elementId : elementIds) { - IIRawElementProviderSimple *rawProvider; - if (SUCCEEDED(rawProviderForAccessibleId(elementId, &rawProvider))) - rawProviderList.append(rawProvider); - } - - if (rawProviderList.size() == 0) - return S_OK; - - *returnValue = static_cast<IIRawElementProviderSimple **>(CoTaskMemAlloc(rawProviderList.size() * sizeof(IIRawElementProviderSimple *))); - if (!*returnValue) { - for (auto rawProvider : qAsConst(rawProviderList)) - rawProvider->Release(); - return E_OUTOFMEMORY; - } - - int index = 0; - for (auto rawProvider : qAsConst(rawProviderList)) - (*returnValue)[index++] = rawProvider; - *returnValueSize = rawProviderList.size(); - return S_OK; -} - -void QWinRTUiaMainProvider::notifyFocusChange(QAccessibleEvent *event) -{ - if (QAccessibleInterface *accessible = event->accessibleInterface()) { - QAccessible::Id accid = idForAccessible(accessible); - QWinRTUiaMetadataCache::instance()->load(accid); - QEventDispatcherWinRT::runOnXamlThread([accid]() { - if (ComPtr<QWinRTUiaMainProvider> provider = providerForAccessibleId(accid)) { - ComPtr<IAutomationPeer> automationPeer; - if (SUCCEEDED(provider->QueryInterface(IID_PPV_ARGS(&automationPeer)))) { - automationPeer->RaiseAutomationEvent(AutomationEvents_AutomationFocusChanged); - } - } - return S_OK; - }, false); - } -} - -void QWinRTUiaMainProvider::notifyVisibilityChange(QAccessibleEvent *event) -{ - if (QAccessibleInterface *accessible = event->accessibleInterface()) { - QAccessible::Id accid = idForAccessible(accessible); - QWinRTUiaMetadataCache::instance()->load(accid); - } -} - -void QWinRTUiaMainProvider::notifyStateChange(QAccessibleStateChangeEvent *event) -{ - if (QAccessibleInterface *accessible = event->accessibleInterface()) { - QAccessible::Id accid = idForAccessible(accessible); - QWinRTUiaMetadataCache::instance()->load(accid); - - if (event->changedStates().checked || event->changedStates().checkStateMixed) { - // Notifies states changes in checkboxes. - if (accessible->role() == QAccessible::CheckBox) { - QEventDispatcherWinRT::runOnXamlThread([accid]() { - if (ComPtr<QWinRTUiaMainProvider> provider = providerForAccessibleId(accid)) { - ComPtr<IAutomationPeer> automationPeer; - if (SUCCEEDED(provider->QueryInterface(IID_PPV_ARGS(&automationPeer)))) { - ComPtr<ITogglePatternIdentifiersStatics> toggleStatics; - if (SUCCEEDED(RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_UI_Xaml_Automation_TogglePatternIdentifiers).Get(), IID_PPV_ARGS(&toggleStatics)))) { - ComPtr<IAutomationProperty> toggleStateProperty; - if (SUCCEEDED(toggleStatics->get_ToggleStateProperty(&toggleStateProperty))) { - ComPtr<QWinRTUiaEmptyPropertyValue> emptyValue = Make<QWinRTUiaEmptyPropertyValue>(); - // by sending an event with an empty value we force ui automation to refresh its state - automationPeer->RaisePropertyChangedEvent(toggleStateProperty.Get(), emptyValue.Get(), emptyValue.Get()); - } - } - } - } - return S_OK; - }, false); - } - } - if (event->changedStates().active) { - if (accessible->role() == QAccessible::Window) { - // Notifies window opened/closed. - bool active = accessible->state().active; - QEventDispatcherWinRT::runOnXamlThread([accid, active]() { - if (ComPtr<QWinRTUiaMainProvider> provider = providerForAccessibleId(accid)) { - ComPtr<IAutomationPeer> automationPeer; - if (SUCCEEDED(provider->QueryInterface(IID_PPV_ARGS(&automationPeer)))) { - if (active) { - automationPeer->RaiseAutomationEvent(AutomationEvents_WindowOpened); - } else { - automationPeer->RaiseAutomationEvent(AutomationEvents_WindowClosed); - } - } - } - return S_OK; - }, false); - } - } - } -} - -void QWinRTUiaMainProvider::notifyValueChange(QAccessibleValueChangeEvent *event) -{ - if (QAccessibleInterface *accessible = event->accessibleInterface()) { - QAccessible::Id accid = idForAccessible(accessible); - QWinRTUiaMetadataCache::instance()->load(accid); - if (QAccessibleValueInterface *valueInterface = accessible->valueInterface()) { - // Notifies changes in values of controls supporting the value interface. - double value = valueInterface->currentValue().toDouble(); - QEventDispatcherWinRT::runOnXamlThread([accid, value]() { - // For some reason RaisePropertyChangedEvent() does not seem to be - // forwarding notifications for any property types except empty, - // which would do nothing here. ToDo: find a workaround. - return S_OK; - }, false); - } - } -} - -// Notifies changes in text content and selection state of text controls. -void QWinRTUiaMainProvider::notifyTextChange(QAccessibleEvent *event) -{ - if (QAccessibleInterface *accessible = event->accessibleInterface()) { - QAccessible::Id accid = idForAccessible(accessible); - QWinRTUiaMetadataCache::instance()->load(accid); - bool readOnly = accessible->state().readOnly; - QAccessible::Event eventType = event->type(); - if (accessible->textInterface()) { - QEventDispatcherWinRT::runOnXamlThread([accid, eventType, readOnly]() { - if (ComPtr<QWinRTUiaMainProvider> provider = providerForAccessibleId(accid)) { - ComPtr<IAutomationPeer> automationPeer; - if (SUCCEEDED(provider->QueryInterface(IID_PPV_ARGS(&automationPeer)))) { - if (eventType == QAccessible::TextSelectionChanged) { - automationPeer->RaiseAutomationEvent(AutomationEvents_TextPatternOnTextSelectionChanged); - } else if (eventType == QAccessible::TextCaretMoved) { - if (!readOnly) { - automationPeer->RaiseAutomationEvent(AutomationEvents_TextPatternOnTextSelectionChanged); - } - } else { - automationPeer->RaiseAutomationEvent(AutomationEvents_TextPatternOnTextChanged); - } - } - } - return S_OK; - }, false); - } - } -} - -// Return providers for specific control patterns -HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetPatternCore(PatternInterface patternInterface, IInspectable **returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__ << patternInterface; - - if (!returnValue) - return E_INVALIDARG; - *returnValue = nullptr; - - QAccessibleInterface *accessible = accessibleInterface(); - if (!accessible) - return E_FAIL; - - switch (patternInterface) { - case PatternInterface_Text: - case PatternInterface_Text2: { - // All text controls. - if (accessible->textInterface()) { - ComPtr<QWinRTUiaTextProvider> provider = Make<QWinRTUiaTextProvider>(id()); - return provider.CopyTo(returnValue); - } - break; - } - case PatternInterface_Value: { - // All accessible controls return text(QAccessible::Value) (which may be empty). - ComPtr<QWinRTUiaValueProvider> provider = Make<QWinRTUiaValueProvider>(id()); - return provider.CopyTo(returnValue); - } - case PatternInterface_RangeValue: { - // Controls providing a numeric value within a range (e.g., sliders, scroll bars, dials). - if (accessible->valueInterface()) { - ComPtr<QWinRTUiaRangeValueProvider> provider = Make<QWinRTUiaRangeValueProvider>(id()); - return provider.CopyTo(returnValue); - } - break; - } - case PatternInterface_Toggle: { - // Checkbox controls. - if (accessible->role() == QAccessible::CheckBox) { - ComPtr<QWinRTUiaToggleProvider> provider = Make<QWinRTUiaToggleProvider>(id()); - return provider.CopyTo(returnValue); - } - break; - } - case PatternInterface_Selection: { - // Lists of items. - if (accessible->role() == QAccessible::List) { - ComPtr<QWinRTUiaSelectionProvider> provider = Make<QWinRTUiaSelectionProvider>(id()); - return provider.CopyTo(returnValue); - } - break; - } - case PatternInterface_SelectionItem: { - // Items within a list and radio buttons. - if ((accessible->role() == QAccessible::RadioButton) - || (accessible->role() == QAccessible::ListItem)) { - ComPtr<QWinRTUiaSelectionItemProvider> provider = Make<QWinRTUiaSelectionItemProvider>(id()); - return provider.CopyTo(returnValue); - } - break; - } - case PatternInterface_Table: { - // Table/tree. - if (accessible->tableInterface() - && ((accessible->role() == QAccessible::Table) || (accessible->role() == QAccessible::Tree))) { - ComPtr<QWinRTUiaTableProvider> provider = Make<QWinRTUiaTableProvider>(id()); - return provider.CopyTo(returnValue); - } - break; - } - case PatternInterface_TableItem: { - // Item within a table/tree. - if (accessible->tableCellInterface() - && ((accessible->role() == QAccessible::Cell) || (accessible->role() == QAccessible::TreeItem))) { - ComPtr<QWinRTUiaTableItemProvider> provider = Make<QWinRTUiaTableItemProvider>(id()); - return provider.CopyTo(returnValue); - } - break; - } - case PatternInterface_Grid: { - // Table/tree. - if (accessible->tableInterface() - && ((accessible->role() == QAccessible::Table) || (accessible->role() == QAccessible::Tree))) { - ComPtr<QWinRTUiaGridProvider> provider = Make<QWinRTUiaGridProvider>(id()); - return provider.CopyTo(returnValue); - } - break; - } - case PatternInterface_GridItem: { - // Item within a table/tree. - if (accessible->tableCellInterface() - && ((accessible->role() == QAccessible::Cell) || (accessible->role() == QAccessible::TreeItem))) { - ComPtr<QWinRTUiaGridItemProvider> provider = Make<QWinRTUiaGridItemProvider>(id()); - return provider.CopyTo(returnValue); - } - break; - } - case PatternInterface_Invoke: { - // Things that have an invokable action (e.g., simple buttons). - if (accessible->actionInterface()) { - ComPtr<QWinRTUiaInvokeProvider> provider = Make<QWinRTUiaInvokeProvider>(id()); - return provider.CopyTo(returnValue); - } - break; - } - default: - break; - } - return S_OK; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetAcceleratorKeyCore(HSTRING *returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!returnValue) - return E_INVALIDARG; - QSharedPointer<QWinRTUiaControlMetadata> metadata = QWinRTUiaMetadataCache::instance()->metadataForId(id()); - return qHString(metadata->accelerator(), returnValue); -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetAccessKeyCore(HSTRING *returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!returnValue) - return E_INVALIDARG; - QSharedPointer<QWinRTUiaControlMetadata> metadata = QWinRTUiaMetadataCache::instance()->metadataForId(id()); - return qHString(metadata->access(), returnValue); -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetAutomationControlTypeCore(AutomationControlType *returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!returnValue) - return E_INVALIDARG; - QSharedPointer<QWinRTUiaControlMetadata> metadata = QWinRTUiaMetadataCache::instance()->metadataForId(id()); - *returnValue = roleToControlType(metadata->role()); - return S_OK; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetAutomationIdCore(HSTRING *returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!returnValue) - return E_INVALIDARG; - QSharedPointer<QWinRTUiaControlMetadata> metadata = QWinRTUiaMetadataCache::instance()->metadataForId(id()); - return qHString(metadata->automationId(), returnValue); -} - -// Returns the bounding rectangle for the accessible control. -HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetBoundingRectangleCore(ABI::Windows::Foundation::Rect *returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!returnValue) - return E_INVALIDARG; - - QSharedPointer<QWinRTUiaControlMetadata> metadata = QWinRTUiaMetadataCache::instance()->metadataForId(id()); - - QRect rect = metadata->boundingRect(); - returnValue->X = rect.x(); - returnValue->Y = rect.y(); - returnValue->Width = rect.width(); - returnValue->Height = rect.height(); - return S_OK; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetChildrenCore(IVector<AutomationPeer *> **returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!returnValue) - return E_INVALIDARG; - *returnValue = nullptr; - - auto accid = id(); - auto children = std::make_shared<QVarLengthArray<QAccessible::Id>>(); - - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, children]() { - if (QAccessibleInterface *accessible = accessibleForId(accid)) { - int childCount = accessible->childCount(); - for (int i = 0; i < childCount; ++i) { - if (QAccessibleInterface *childAcc = accessible->child(i)) { - QAccessible::Id childId = idForAccessible(childAcc); - QWinRTUiaMetadataCache::instance()->load(childId); - if (!childAcc->state().invisible) - children->append(childId); - } - } - } - return S_OK; - }))) { - return E_FAIL; - } - - ComPtr<IVector<AutomationPeer *>> peerVector = Make<QWinRTUiaPeerVector>(); - - for (auto childId : *children) { - if (ComPtr<QWinRTUiaMainProvider> provider = providerForAccessibleId(childId)) { - IAutomationPeer *peer; - if (SUCCEEDED(provider.CopyTo(&peer))) - peerVector->Append(peer); - } - } - return peerVector.CopyTo(returnValue); -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetClassNameCore(HSTRING *returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!returnValue) - return E_INVALIDARG; - QSharedPointer<QWinRTUiaControlMetadata> metadata = QWinRTUiaMetadataCache::instance()->metadataForId(id()); - return qHString(metadata->className(), returnValue); -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetClickablePointCore(ABI::Windows::Foundation::Point *returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!returnValue) - return E_INVALIDARG; - return E_NOTIMPL; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetHelpTextCore(HSTRING *returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!returnValue) - return E_INVALIDARG; - QSharedPointer<QWinRTUiaControlMetadata> metadata = QWinRTUiaMetadataCache::instance()->metadataForId(id()); - return qHString(metadata->help(), returnValue); -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetItemStatusCore(HSTRING *returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!returnValue) - return E_INVALIDARG; - return E_NOTIMPL; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetItemTypeCore(HSTRING *returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!returnValue) - return E_INVALIDARG; - return E_NOTIMPL; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetLabeledByCore(IAutomationPeer **returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!returnValue) - return E_INVALIDARG; - return E_NOTIMPL; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetLocalizedControlTypeCore(HSTRING *returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!returnValue) - return E_INVALIDARG; - return E_NOTIMPL; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetNameCore(HSTRING *returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!returnValue) - return E_INVALIDARG; - QSharedPointer<QWinRTUiaControlMetadata> metadata = QWinRTUiaMetadataCache::instance()->metadataForId(id()); - return qHString(metadata->controlName(), returnValue); -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetOrientationCore(AutomationOrientation *returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!returnValue) - return E_INVALIDARG; - *returnValue = AutomationOrientation_None; - return S_OK; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::HasKeyboardFocusCore(boolean *returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!returnValue) - return E_INVALIDARG; - QSharedPointer<QWinRTUiaControlMetadata> metadata = QWinRTUiaMetadataCache::instance()->metadataForId(id()); - *returnValue = (metadata->state().focused != 0); - return S_OK; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::IsContentElementCore(boolean *returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!returnValue) - return E_INVALIDARG; - *returnValue = true; - return S_OK; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::IsControlElementCore(boolean *returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!returnValue) - return E_INVALIDARG; - *returnValue = true; - return S_OK; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::IsEnabledCore(boolean *returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!returnValue) - return E_INVALIDARG; - QSharedPointer<QWinRTUiaControlMetadata> metadata = QWinRTUiaMetadataCache::instance()->metadataForId(id()); - *returnValue = (metadata->state().disabled == 0); - return S_OK; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::IsKeyboardFocusableCore(boolean *returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!returnValue) - return E_INVALIDARG; - QSharedPointer<QWinRTUiaControlMetadata> metadata = QWinRTUiaMetadataCache::instance()->metadataForId(id()); - *returnValue = (metadata->state().focusable != 0); - return S_OK; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::IsOffscreenCore(boolean *returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!returnValue) - return E_INVALIDARG; - QSharedPointer<QWinRTUiaControlMetadata> metadata = QWinRTUiaMetadataCache::instance()->metadataForId(id()); - *returnValue = (metadata->state().offscreen != 0); - return S_OK; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::IsPasswordCore(boolean *returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!returnValue) - return E_INVALIDARG; - QSharedPointer<QWinRTUiaControlMetadata> metadata = QWinRTUiaMetadataCache::instance()->metadataForId(id()); - *returnValue = (metadata->role() == QAccessible::EditableText) && (metadata->state().passwordEdit != 0); - return S_OK; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::IsRequiredForFormCore(boolean *returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!returnValue) - return E_INVALIDARG; - *returnValue = false; - return S_OK; -} - -// Sets focus to the control. -HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::SetFocusCore() -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - QAccessibleInterface *accessible = accessibleInterface(); - if (!accessible) - return E_FAIL; - - QAccessibleActionInterface *actionInterface = accessible->actionInterface(); - if (!actionInterface) - return E_FAIL; - - QEventDispatcherWinRT::runOnMainThread([actionInterface]() { - actionInterface->doAction(QAccessibleActionInterface::setFocusAction()); - return S_OK; - }); - return S_OK; -} - -// Returns a provider for the UI element present at the specified screen coordinates. -HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetPeerFromPointCore(ABI::Windows::Foundation::Point point, IAutomationPeer **returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!returnValue) - return E_INVALIDARG; - *returnValue = nullptr; - - // Scale coordinates from High DPI screens? - - auto accid = id(); - auto elementId = std::make_shared<QAccessible::Id>(0); - - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementId, point]() { - // Controls can be embedded within grouping elements. By default returns the innermost control. - QAccessibleInterface *target = accessibleForId(accid); - while (QAccessibleInterface *tmpacc = target->childAt(point.X, point.Y)) { - target = tmpacc; - // For accessibility tools it may be better to return the text element instead of its subcomponents. - if (target->textInterface()) break; - } - *elementId = idForAccessible(target); - QWinRTUiaMetadataCache::instance()->load(*elementId); - return S_OK; - }))) { - return E_FAIL; - } - - if (ComPtr<QWinRTUiaMainProvider> provider = providerForAccessibleId(*elementId)) - return provider.CopyTo(returnValue); - return E_FAIL; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaMainProvider::GetLiveSettingCore(AutomationLiveSetting *returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!returnValue) - return E_INVALIDARG; - return E_NOTIMPL; -} - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) - diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.h b/src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.h deleted file mode 100644 index 23a6e56ae7..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiamainprovider.h +++ /dev/null @@ -1,125 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTUIAMAINPROVIDER_H -#define QWINRTUIAMAINPROVIDER_H - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include "qwinrtuiabaseprovider.h" - -#include <QtCore/qglobal.h> -#include <QtCore/QPointer> -#include <QtCore/QSharedPointer> -#include <QtGui/QAccessible> -#include <QtGui/QAccessibleInterface> - -#include <wrl.h> -#include <windows.ui.xaml.h> - -QT_BEGIN_NAMESPACE - -// The main WinRT UI Automation class. -class QWinRTUiaMainProvider: - public QWinRTUiaBaseProvider, - public Microsoft::WRL::RuntimeClass<ABI::Windows::UI::Xaml::Automation::Peers::IAutomationPeerOverrides> -{ - Q_OBJECT - Q_DISABLE_COPY(QWinRTUiaMainProvider) - -public: - explicit QWinRTUiaMainProvider(QAccessible::Id id); - virtual ~QWinRTUiaMainProvider(); - static QWinRTUiaMainProvider *providerForAccessibleId(QAccessible::Id id); - static HRESULT rawProviderForAccessibleId(QAccessible::Id elementId, ABI::Windows::UI::Xaml::Automation::Provider::IIRawElementProviderSimple **returnValue); - static HRESULT rawProviderArrayForAccessibleIdList(const QVarLengthArray<QAccessible::Id> &elementIds, UINT32 *returnValueSize, ABI::Windows::UI::Xaml::Automation::Provider::IIRawElementProviderSimple ***returnValue); - static void notifyFocusChange(QAccessibleEvent *event); - static void notifyVisibilityChange(QAccessibleEvent *event); - static void notifyStateChange(QAccessibleStateChangeEvent *event); - static void notifyValueChange(QAccessibleValueChangeEvent *event); - static void notifyTextChange(QAccessibleEvent *event); - - // IUnknown - HRESULT STDMETHODCALLTYPE QueryInterface(REFIID id, LPVOID *iface) override; - - // IInspectable - HRESULT STDMETHODCALLTYPE GetIids(ULONG *iidCount, IID **iids) override; - HRESULT STDMETHODCALLTYPE GetRuntimeClassName(HSTRING *className) override; - HRESULT STDMETHODCALLTYPE GetTrustLevel(TrustLevel *trustLevel) override; - - // IAutomationPeerOverrides - HRESULT STDMETHODCALLTYPE GetPatternCore(ABI::Windows::UI::Xaml::Automation::Peers::PatternInterface patternInterface, IInspectable **returnValue) override; - HRESULT STDMETHODCALLTYPE GetAcceleratorKeyCore(HSTRING *returnValue) override; - HRESULT STDMETHODCALLTYPE GetAccessKeyCore(HSTRING *returnValue) override; - HRESULT STDMETHODCALLTYPE GetAutomationControlTypeCore(ABI::Windows::UI::Xaml::Automation::Peers::AutomationControlType *returnValue) override; - HRESULT STDMETHODCALLTYPE GetAutomationIdCore(HSTRING *returnValue) override; - HRESULT STDMETHODCALLTYPE GetBoundingRectangleCore(ABI::Windows::Foundation::Rect *returnValue) override; - HRESULT STDMETHODCALLTYPE GetChildrenCore(ABI::Windows::Foundation::Collections::IVector<ABI::Windows::UI::Xaml::Automation::Peers::AutomationPeer*> **returnValue) override; - HRESULT STDMETHODCALLTYPE GetClassNameCore(HSTRING *returnValue) override; - HRESULT STDMETHODCALLTYPE GetClickablePointCore(ABI::Windows::Foundation::Point *returnValue) override; - HRESULT STDMETHODCALLTYPE GetHelpTextCore(HSTRING *returnValue) override; - HRESULT STDMETHODCALLTYPE GetItemStatusCore(HSTRING *returnValue) override; - HRESULT STDMETHODCALLTYPE GetItemTypeCore(HSTRING *returnValue) override; - HRESULT STDMETHODCALLTYPE GetLabeledByCore(ABI::Windows::UI::Xaml::Automation::Peers::IAutomationPeer **returnValue) override; - HRESULT STDMETHODCALLTYPE GetLocalizedControlTypeCore(HSTRING *returnValue) override; - HRESULT STDMETHODCALLTYPE GetNameCore(HSTRING *returnValue) override; - HRESULT STDMETHODCALLTYPE GetOrientationCore(ABI::Windows::UI::Xaml::Automation::Peers::AutomationOrientation *returnValue) override; - HRESULT STDMETHODCALLTYPE HasKeyboardFocusCore(boolean *returnValue) override; - HRESULT STDMETHODCALLTYPE IsContentElementCore(boolean *returnValue) override; - HRESULT STDMETHODCALLTYPE IsControlElementCore(boolean *returnValue) override; - HRESULT STDMETHODCALLTYPE IsEnabledCore(boolean *returnValue) override; - HRESULT STDMETHODCALLTYPE IsKeyboardFocusableCore(boolean *returnValue) override; - HRESULT STDMETHODCALLTYPE IsOffscreenCore(boolean *returnValue) override; - HRESULT STDMETHODCALLTYPE IsPasswordCore(boolean *returnValue) override; - HRESULT STDMETHODCALLTYPE IsRequiredForFormCore(boolean *returnValue) override; - HRESULT STDMETHODCALLTYPE SetFocusCore() override; - HRESULT STDMETHODCALLTYPE GetPeerFromPointCore(ABI::Windows::Foundation::Point point, ABI::Windows::UI::Xaml::Automation::Peers::IAutomationPeer **returnValue) override; - HRESULT STDMETHODCALLTYPE GetLiveSettingCore(ABI::Windows::UI::Xaml::Automation::Peers::AutomationLiveSetting *returnValue) override; - -private: - Microsoft::WRL::ComPtr<ABI::Windows::UI::Xaml::Automation::Peers::IAutomationPeerOverrides> m_base; - Microsoft::WRL::ComPtr<ABI::Windows::UI::Xaml::Automation::Peers::IAutomationPeer> m_core; -}; - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) - -#endif // QWINRTUIAMAINPROVIDER_H diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiametadatacache.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiametadatacache.cpp deleted file mode 100644 index 442ff184a8..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiametadatacache.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include "qwinrtuiametadatacache.h" -#include "qwinrtuiautils.h" - -#include <QtCore/QLoggingCategory> -#include <QtCore/private/qeventdispatcher_winrt_p.h> - -QT_BEGIN_NAMESPACE - -using namespace QWinRTUiAutomation; - -// Private constructor -QWinRTUiaMetadataCache::QWinRTUiaMetadataCache() -{ -} - -// shared instance -QWinRTUiaMetadataCache *QWinRTUiaMetadataCache::instance() -{ - static QWinRTUiaMetadataCache metadataCache; - return &metadataCache; -} - -// Returns the cached metadata associated with the ID, or an instance with default values. -QSharedPointer<QWinRTUiaControlMetadata> QWinRTUiaMetadataCache::metadataForId(QAccessible::Id id) -{ - QSharedPointer<QWinRTUiaControlMetadata> metadata; - - m_mutex.lock(); - if (m_metadataTable.contains(id)) - metadata = m_metadataTable[id]; - else - metadata = QSharedPointer<QWinRTUiaControlMetadata>(new QWinRTUiaControlMetadata); - m_mutex.unlock(); - return metadata; -} - -// Caches metadata from the accessibility framework within the main thread. -bool QWinRTUiaMetadataCache::load(QAccessible::Id id) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([id]() { - QWinRTUiaMetadataCache::instance()->insert(id, QSharedPointer<QWinRTUiaControlMetadata>(new QWinRTUiaControlMetadata(id))); - return S_OK; - }))) { - return false; - } - return true; -} - -// Inserts metadata in the cache and associates it with an accessibility ID. -void QWinRTUiaMetadataCache::insert(QAccessible::Id id, const QSharedPointer<QWinRTUiaControlMetadata> &metadata) -{ - m_mutex.lock(); - m_metadataTable[id] = metadata; - m_mutex.unlock(); -} - -// Removes metadata with a given id from the cache. -void QWinRTUiaMetadataCache::remove(QAccessible::Id id) -{ - m_mutex.lock(); - m_metadataTable.remove(id); - m_mutex.unlock(); -} - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) - diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiametadatacache.h b/src/plugins/platforms/winrt/uiautomation/qwinrtuiametadatacache.h deleted file mode 100644 index 2d68d1b654..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiametadatacache.h +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTUIAMETADATACACHE_H -#define QWINRTUIAMETADATACACHE_H - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include "qwinrtuiacontrolmetadata.h" - -#include <QtCore/QHash> -#include <QtCore/QMutex> -#include <QtGui/QAccessible> -#include <QtGui/QAccessibleInterface> - -QT_BEGIN_NAMESPACE - -// Singleton used to cache metadata using the accessibility ID as the key. -class QWinRTUiaMetadataCache : public QObject -{ - QWinRTUiaMetadataCache(); - Q_OBJECT -public: - static QWinRTUiaMetadataCache *instance(); - QSharedPointer<QWinRTUiaControlMetadata> metadataForId(QAccessible::Id id); - void insert(QAccessible::Id id, const QSharedPointer<QWinRTUiaControlMetadata> &metadata); - void remove(QAccessible::Id id); - bool load(QAccessible::Id id); - -private: - QHash<QAccessible::Id, QSharedPointer<QWinRTUiaControlMetadata>> m_metadataTable; - QMutex m_mutex; -}; - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) - -#endif // QWINRTUIAMETADATACACHE_H diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiapeervector.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiapeervector.cpp deleted file mode 100644 index e3d6bcae4b..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiapeervector.cpp +++ /dev/null @@ -1,149 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include "qwinrtuiapeervector.h" -#include "qwinrtuiautils.h" - -using namespace ABI::Windows::UI::Xaml::Automation::Peers; -using namespace ABI::Windows::Foundation::Collections; - -QT_BEGIN_NAMESPACE - -HRESULT QWinRTUiaPeerVector::GetAt(quint32 index, IAutomationPeer **item) -{ - if (index >= quint32(m_impl.size())) - return E_FAIL; - if ((*item = m_impl.at(index))) - (*item)->AddRef(); - return S_OK; -} - -HRESULT QWinRTUiaPeerVector::get_Size(quint32 *size) -{ - *size = m_impl.size(); - return S_OK; -} - -HRESULT QWinRTUiaPeerVector::GetView(IVectorView<AutomationPeer *> **view) -{ - *view = nullptr; - return E_NOTIMPL; -} - -HRESULT QWinRTUiaPeerVector::IndexOf(IAutomationPeer *value, quint32 *index, boolean *found) -{ - int idx = m_impl.indexOf(value); - if (idx > -1) { - *index = quint32(idx); - *found = true; - } else { - *found = false; - } - return S_OK; -} - -HRESULT QWinRTUiaPeerVector::SetAt(quint32 index, IAutomationPeer *item) -{ - if (index >= quint32(m_impl.size())) - return E_FAIL; - if (IAutomationPeer *elem = m_impl.at(index)) { - if (elem == item) - return S_OK; - else - elem->Release(); - } - if (item) - item->AddRef(); - m_impl[index] = item; - return S_OK; -} - -HRESULT QWinRTUiaPeerVector::InsertAt(quint32 index, IAutomationPeer *item) -{ - if (index >= quint32(m_impl.size())) - return E_FAIL; - if (item) - item->AddRef(); - m_impl.insert(index, item); - return S_OK; -} - -HRESULT QWinRTUiaPeerVector::RemoveAt(quint32 index) -{ - if (index >= quint32(m_impl.size())) - return E_FAIL; - if (IAutomationPeer *elem = m_impl.at(index)) - elem->Release(); - m_impl.remove(index); - return S_OK; -} - -HRESULT QWinRTUiaPeerVector::Append(IAutomationPeer *item) -{ - if (item) - item->AddRef(); - m_impl.append(item); - return S_OK; -} - -HRESULT QWinRTUiaPeerVector::RemoveAtEnd() -{ - if (m_impl.size() == 0) - return E_FAIL; - if (IAutomationPeer *elem = m_impl.last()) - elem->Release(); - m_impl.removeLast(); - return S_OK; -} - -HRESULT QWinRTUiaPeerVector::Clear() -{ - for (auto elem : qAsConst(m_impl)) - if (elem) - elem->Release(); - m_impl.clear(); - return S_OK; -} - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiapeervector.h b/src/plugins/platforms/winrt/uiautomation/qwinrtuiapeervector.h deleted file mode 100644 index 265526de09..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiapeervector.h +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTUIAPEERVECTOR_H -#define QWINRTUIAPEERVECTOR_H - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include <QtCore/QString> -#include <QtCore/qt_windows.h> -#include <QtGui/QAccessible> -#include <QtGui/QAccessibleInterface> -#include <QtGui/QWindow> -#include <QVector> - -#include <wrl.h> -#include <windows.ui.xaml.h> - -QT_BEGIN_NAMESPACE - -// Implements IVector<AutomationPeer *> -class QWinRTUiaPeerVector : public Microsoft::WRL::RuntimeClass<ABI::Windows::Foundation::Collections::IVector<ABI::Windows::UI::Xaml::Automation::Peers::AutomationPeer *>> -{ -public: - HRESULT STDMETHODCALLTYPE GetAt(quint32 index, ABI::Windows::UI::Xaml::Automation::Peers::IAutomationPeer **item) override; - HRESULT STDMETHODCALLTYPE get_Size(quint32 *size) override; - HRESULT STDMETHODCALLTYPE GetView(ABI::Windows::Foundation::Collections::IVectorView<ABI::Windows::UI::Xaml::Automation::Peers::AutomationPeer *> **view) override; - HRESULT STDMETHODCALLTYPE IndexOf(ABI::Windows::UI::Xaml::Automation::Peers::IAutomationPeer *value, quint32 *index, boolean *found) override; - HRESULT STDMETHODCALLTYPE SetAt(quint32 index, ABI::Windows::UI::Xaml::Automation::Peers::IAutomationPeer *item) override; - HRESULT STDMETHODCALLTYPE InsertAt(quint32 index, ABI::Windows::UI::Xaml::Automation::Peers::IAutomationPeer *item) override; - HRESULT STDMETHODCALLTYPE RemoveAt(quint32 index) override; - HRESULT STDMETHODCALLTYPE Append(ABI::Windows::UI::Xaml::Automation::Peers::IAutomationPeer *item) override; - HRESULT STDMETHODCALLTYPE RemoveAtEnd() override; - HRESULT STDMETHODCALLTYPE Clear() override; -private: - QVector<ABI::Windows::UI::Xaml::Automation::Peers::IAutomationPeer *> m_impl; -}; - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) - -#endif // QWINRTUIAPEERVECTOR_H diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiaprovidercache.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiaprovidercache.cpp deleted file mode 100644 index 06ff094c45..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiaprovidercache.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include "qwinrtuiaprovidercache.h" - -QT_BEGIN_NAMESPACE - -// Private constructor -QWinRTUiaProviderCache::QWinRTUiaProviderCache() -{ -} - -// shared instance -QWinRTUiaProviderCache *QWinRTUiaProviderCache::instance() -{ - static QWinRTUiaProviderCache providerCache; - return &providerCache; -} - -// Returns the provider instance associated with the ID, or nullptr. -QWinRTUiaBaseProvider *QWinRTUiaProviderCache::providerForId(QAccessible::Id id) const -{ - return m_providerTable.value(id); -} - -// Inserts a provider in the cache and associates it with an accessibility ID. -void QWinRTUiaProviderCache::insert(QAccessible::Id id, QWinRTUiaBaseProvider *provider) -{ - remove(id); - if (provider) { - m_providerTable[id] = provider; - m_inverseTable[provider] = id; - // Connects the destroyed signal to our slot, to remove deleted objects from the cache. - QObject::connect(provider, &QObject::destroyed, this, &QWinRTUiaProviderCache::objectDestroyed); - } -} - -// Removes deleted provider objects from the cache. -void QWinRTUiaProviderCache::objectDestroyed(QObject *obj) -{ - // We have to use the inverse table to map the object address back to its ID, - // since at this point (called from QObject destructor), it has already been - // partially destroyed and we cannot treat it as a provider. - auto it = m_inverseTable.find(obj); - if (it != m_inverseTable.end()) { - m_providerTable.remove(*it); - m_inverseTable.remove(obj); - } -} - -// Removes a provider with a given id from the cache. -void QWinRTUiaProviderCache::remove(QAccessible::Id id) -{ - m_inverseTable.remove(m_providerTable.value(id)); - m_providerTable.remove(id); -} - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiaprovidercache.h b/src/plugins/platforms/winrt/uiautomation/qwinrtuiaprovidercache.h deleted file mode 100644 index 393ef7d562..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiaprovidercache.h +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTUIAPROVIDERCACHE_H -#define QWINRTUIAPROVIDERCACHE_H - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include "qwinrtuiabaseprovider.h" - -#include <QtCore/QHash> -#include <QtGui/QAccessible> -#include <QtGui/QAccessibleInterface> - -QT_BEGIN_NAMESPACE - -// Singleton used to cache provider instances using the accessibility ID as the key. -class QWinRTUiaProviderCache : public QObject -{ - QWinRTUiaProviderCache(); - Q_OBJECT -public: - static QWinRTUiaProviderCache *instance(); - QWinRTUiaBaseProvider *providerForId(QAccessible::Id id) const; - void insert(QAccessible::Id id, QWinRTUiaBaseProvider *provider); - void remove(QAccessible::Id id); - -private Q_SLOTS: - void objectDestroyed(QObject *obj); - -private: - QHash<QAccessible::Id, QWinRTUiaBaseProvider *> m_providerTable; - QHash<QObject *, QAccessible::Id> m_inverseTable; -}; - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) - -#endif // QWINRTUIAPROVIDERCACHE_H diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiarangevalueprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiarangevalueprovider.cpp deleted file mode 100644 index 4ac59c890a..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiarangevalueprovider.cpp +++ /dev/null @@ -1,167 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include "qwinrtuiarangevalueprovider.h" -#include "qwinrtuiametadatacache.h" -#include "qwinrtuiautils.h" - -#include <QtGui/QAccessible> -#include <QtGui/QAccessibleInterface> -#include <QtCore/QLoggingCategory> -#include <QtCore/QString> -#include <QtCore/private/qeventdispatcher_winrt_p.h> - -QT_BEGIN_NAMESPACE - -using namespace QWinRTUiAutomation; -using namespace ABI::Windows::UI::Xaml::Automation; -using namespace ABI::Windows::UI::Xaml::Automation::Provider; - -QWinRTUiaRangeValueProvider::QWinRTUiaRangeValueProvider(QAccessible::Id id) : - QWinRTUiaBaseProvider(id) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; -} - -QWinRTUiaRangeValueProvider::~QWinRTUiaRangeValueProvider() -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaRangeValueProvider::get_IsReadOnly(boolean *value) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!value) - return E_INVALIDARG; - - QSharedPointer<QWinRTUiaControlMetadata> metadata = QWinRTUiaMetadataCache::instance()->metadataForId(id()); - *value = (metadata->state().readOnly != 0); - return S_OK; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaRangeValueProvider::get_LargeChange(DOUBLE *value) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!value) - return E_INVALIDARG; - - QSharedPointer<QWinRTUiaControlMetadata> metadata = QWinRTUiaMetadataCache::instance()->metadataForId(id()); - *value = metadata->minimumStepSize(); - return S_OK; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaRangeValueProvider::get_Maximum(DOUBLE *value) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!value) - return E_INVALIDARG; - - QSharedPointer<QWinRTUiaControlMetadata> metadata = QWinRTUiaMetadataCache::instance()->metadataForId(id()); - *value = metadata->maximumValue(); - return S_OK; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaRangeValueProvider::get_Minimum(DOUBLE *value) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!value) - return E_INVALIDARG; - - QSharedPointer<QWinRTUiaControlMetadata> metadata = QWinRTUiaMetadataCache::instance()->metadataForId(id()); - *value = metadata->minimumValue(); - return S_OK; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaRangeValueProvider::get_SmallChange(DOUBLE *value) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!value) - return E_INVALIDARG; - - QSharedPointer<QWinRTUiaControlMetadata> metadata = QWinRTUiaMetadataCache::instance()->metadataForId(id()); - *value = metadata->minimumStepSize(); - return S_OK; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaRangeValueProvider::get_Value(DOUBLE *value) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!value) - return E_INVALIDARG; - - QSharedPointer<QWinRTUiaControlMetadata> metadata = QWinRTUiaMetadataCache::instance()->metadataForId(id()); - *value = metadata->currentValue(); - return S_OK; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaRangeValueProvider::SetValue(DOUBLE value) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - auto accid = id(); - - QEventDispatcherWinRT::runOnMainThread([accid, value]() { - if (QAccessibleInterface *accessible = accessibleForId(accid)) { - if (QAccessibleValueInterface *valueInterface = accessible->valueInterface()) { - double minimum = valueInterface->minimumValue().toDouble(); - double maximum = valueInterface->maximumValue().toDouble(); - if ((value >= minimum) && (value <= maximum)) { - valueInterface->setCurrentValue(QVariant(value)); - } - } - } - QWinRTUiaMetadataCache::instance()->load(accid); - return S_OK; - }, 0); - - return S_OK; -} - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiarangevalueprovider.h b/src/plugins/platforms/winrt/uiautomation/qwinrtuiarangevalueprovider.h deleted file mode 100644 index 4e98959526..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiarangevalueprovider.h +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTUIARANGEVALUEPROVIDER_H -#define QWINRTUIARANGEVALUEPROVIDER_H - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include "qwinrtuiabaseprovider.h" - -#include <wrl.h> -#include <windows.ui.xaml.h> - -QT_BEGIN_NAMESPACE - -// Implements the Range Value control pattern provider. -class QWinRTUiaRangeValueProvider : - public QWinRTUiaBaseProvider, - public Microsoft::WRL::RuntimeClass<ABI::Windows::UI::Xaml::Automation::Provider::IRangeValueProvider> -{ - Q_OBJECT - Q_DISABLE_COPY(QWinRTUiaRangeValueProvider) - InspectableClass(L"QWinRTUiaRangeValueProvider", BaseTrust); - -public: - explicit QWinRTUiaRangeValueProvider(QAccessible::Id id); - virtual ~QWinRTUiaRangeValueProvider(); - - // IRangeValueProvider - HRESULT STDMETHODCALLTYPE get_IsReadOnly(boolean *value) override; - HRESULT STDMETHODCALLTYPE get_LargeChange(DOUBLE *value) override; - HRESULT STDMETHODCALLTYPE get_Maximum(DOUBLE *value) override; - HRESULT STDMETHODCALLTYPE get_Minimum(DOUBLE *value) override; - HRESULT STDMETHODCALLTYPE get_SmallChange(DOUBLE *value) override; - HRESULT STDMETHODCALLTYPE get_Value(DOUBLE *value) override; - HRESULT STDMETHODCALLTYPE SetValue(DOUBLE value) override; -}; - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) - -#endif // QWINRTUIARANGEVALUEPROVIDER_H diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionitemprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionitemprovider.cpp deleted file mode 100644 index 2cb5aa685c..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionitemprovider.cpp +++ /dev/null @@ -1,214 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include "qwinrtuiaselectionitemprovider.h" -#include "qwinrtuiamainprovider.h" -#include "qwinrtuiametadatacache.h" -#include "qwinrtuiautils.h" - -#include <QtGui/QAccessible> -#include <QtGui/QAccessibleInterface> -#include <QtCore/QLoggingCategory> -#include <QtCore/QString> -#include <QtCore/private/qeventdispatcher_winrt_p.h> - -#include <memory> - -QT_BEGIN_NAMESPACE - -using namespace QWinRTUiAutomation; -using namespace ABI::Windows::UI::Xaml::Automation; -using namespace ABI::Windows::UI::Xaml::Automation::Provider; -using namespace ABI::Windows::UI::Xaml::Automation::Peers; - -QWinRTUiaSelectionItemProvider::QWinRTUiaSelectionItemProvider(QAccessible::Id id) : - QWinRTUiaBaseProvider(id) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; -} - -QWinRTUiaSelectionItemProvider::~QWinRTUiaSelectionItemProvider() -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; -} - -// Returns true if element is currently selected. -HRESULT STDMETHODCALLTYPE QWinRTUiaSelectionItemProvider::get_IsSelected(boolean *value) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!value) - return E_INVALIDARG; - QSharedPointer<QWinRTUiaControlMetadata> metadata = QWinRTUiaMetadataCache::instance()->metadataForId(id()); - if (metadata->role() == QAccessible::RadioButton) - *value = metadata->state().checked; - else - *value = metadata->state().selected; - return S_OK; -} - -// Returns the provider for the container element (e.g., the list for the list item). -HRESULT STDMETHODCALLTYPE QWinRTUiaSelectionItemProvider::get_SelectionContainer(IIRawElementProviderSimple **value) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!value) - return E_INVALIDARG; - *value = nullptr; - - auto accid = id(); - auto elementId = std::make_shared<QAccessible::Id>(0); - - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementId]() { - if (QAccessibleInterface *accessible = accessibleForId(accid)) { - // Radio buttons do not require a container. - if (accessible->role() == QAccessible::ListItem) { - if (QAccessibleInterface *parent = accessible->parent()) { - if (parent->role() == QAccessible::List) { - *elementId = idForAccessible(parent); - } - } - } - } - return S_OK; - }))) { - return E_FAIL; - } - - if (!*elementId) - return S_OK; - - return QWinRTUiaMainProvider::rawProviderForAccessibleId(*elementId, value); -} - -// Adds the element to the list of selected elements. -HRESULT STDMETHODCALLTYPE QWinRTUiaSelectionItemProvider::AddToSelection() -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - auto accid = id(); - - QEventDispatcherWinRT::runOnMainThread([accid]() { - if (QAccessibleInterface *accessible = accessibleForId(accid)) { - if (QAccessibleActionInterface *actionInterface = accessible->actionInterface()) { - if (accessible->role() == QAccessible::RadioButton) { - // For radio buttons we invoke the selection action. - actionInterface->doAction(QAccessibleActionInterface::pressAction()); - } else { - // Toggle list item if not already selected. - if (!accessible->state().selected) { - actionInterface->doAction(QAccessibleActionInterface::toggleAction()); - } - } - } - } - QWinRTUiaMetadataCache::instance()->load(accid); - return S_OK; - }, 0); - return S_OK; -} - -// Removes a list item from selection. -HRESULT STDMETHODCALLTYPE QWinRTUiaSelectionItemProvider::RemoveFromSelection() -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - auto accid = id(); - - QEventDispatcherWinRT::runOnMainThread([accid]() { - if (QAccessibleInterface *accessible = accessibleForId(accid)) { - if (QAccessibleActionInterface *actionInterface = accessible->actionInterface()) { - if (accessible->role() != QAccessible::RadioButton) { - if (accessible->state().selected) { - actionInterface->doAction(QAccessibleActionInterface::toggleAction()); - } - } - } - } - QWinRTUiaMetadataCache::instance()->load(accid); - return S_OK; - }, 0); - return S_OK; -} - -// Selects the element (deselecting all others). -HRESULT STDMETHODCALLTYPE QWinRTUiaSelectionItemProvider::Select() -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - auto accid = id(); - - QEventDispatcherWinRT::runOnMainThread([accid]() { - if (QAccessibleInterface *accessible = accessibleForId(accid)) { - if (QAccessibleActionInterface *actionInterface = accessible->actionInterface()) { - if (accessible->role() == QAccessible::RadioButton) { - // For radio buttons we just invoke the selection action; others are automatically deselected. - actionInterface->doAction(QAccessibleActionInterface::pressAction()); - } else { - // Toggle list item if not already selected. It must be done first to support all selection modes. - if (!accessible->state().selected) { - actionInterface->doAction(QAccessibleActionInterface::toggleAction()); - } - // Toggle selected siblings. - if (QAccessibleInterface *parent = accessible->parent()) { - for (int i = 0; i < parent->childCount(); ++i) { - if (QAccessibleInterface *sibling = parent->child(i)) { - if ((sibling != accessible) && (sibling->state().selected)) { - if (QAccessibleActionInterface *siblingAction = sibling->actionInterface()) { - siblingAction->doAction(QAccessibleActionInterface::toggleAction()); - } - } - } - } - } - } - } - } - QWinRTUiaMetadataCache::instance()->load(accid); - return S_OK; - }, 0); - return S_OK; -} - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionitemprovider.h b/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionitemprovider.h deleted file mode 100644 index 1b3cce7495..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionitemprovider.h +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTUIASELECTIONITEMPROVIDER_H -#define QWINRTUIASELECTIONITEMPROVIDER_H - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include "qwinrtuiabaseprovider.h" - -#include <wrl.h> -#include <windows.ui.xaml.h> - -QT_BEGIN_NAMESPACE - -// Implements the Selection Item control pattern provider. Used for List items and radio buttons. -class QWinRTUiaSelectionItemProvider : - public QWinRTUiaBaseProvider, - public Microsoft::WRL::RuntimeClass<ABI::Windows::UI::Xaml::Automation::Provider::ISelectionItemProvider> -{ - Q_OBJECT - Q_DISABLE_COPY(QWinRTUiaSelectionItemProvider) - InspectableClass(L"QWinRTUiaSelectionItemProvider", BaseTrust); - -public: - explicit QWinRTUiaSelectionItemProvider(QAccessible::Id id); - virtual ~QWinRTUiaSelectionItemProvider(); - - // ISelectionItemProvider - HRESULT STDMETHODCALLTYPE get_IsSelected(boolean *value) override; - HRESULT STDMETHODCALLTYPE get_SelectionContainer(ABI::Windows::UI::Xaml::Automation::Provider::IIRawElementProviderSimple **value) override; - HRESULT STDMETHODCALLTYPE AddToSelection() override; - HRESULT STDMETHODCALLTYPE RemoveFromSelection() override; - HRESULT STDMETHODCALLTYPE Select() override; -}; - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) - -#endif // QWINRTUIASELECTIONITEMPROVIDER_H diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionprovider.cpp deleted file mode 100644 index 4d825351c8..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionprovider.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include "qwinrtuiaselectionprovider.h" -#include "qwinrtuiametadatacache.h" -#include "qwinrtuiamainprovider.h" -#include "qwinrtuiautils.h" - -#include <QtGui/QAccessible> -#include <QtGui/QAccessibleInterface> -#include <QtCore/QLoggingCategory> -#include <QtCore/QString> -#include <QtCore/private/qeventdispatcher_winrt_p.h> - -#include <memory> - -QT_BEGIN_NAMESPACE - -using namespace QWinRTUiAutomation; -using namespace ABI::Windows::UI::Xaml::Automation; -using namespace ABI::Windows::UI::Xaml::Automation::Provider; -using namespace ABI::Windows::UI::Xaml::Automation::Peers; - -QWinRTUiaSelectionProvider::QWinRTUiaSelectionProvider(QAccessible::Id id) : - QWinRTUiaBaseProvider(id) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; -} - -QWinRTUiaSelectionProvider::~QWinRTUiaSelectionProvider() -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaSelectionProvider::get_CanSelectMultiple(boolean *value) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!value) - return E_INVALIDARG; - QSharedPointer<QWinRTUiaControlMetadata> metadata = QWinRTUiaMetadataCache::instance()->metadataForId(id()); - *value = (metadata->state().multiSelectable != 0); - return S_OK; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaSelectionProvider::get_IsSelectionRequired(boolean *value) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!value) - return E_INVALIDARG; - *value = false; - - auto accid = id(); - auto selectionRequired = std::make_shared<bool>(false); - - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, selectionRequired]() { - // Initially returns false if none are selected. After the first selection, it may be required. - bool anySelected = false; - if (QAccessibleInterface *accessible = accessibleForId(accid)) { - int childCount = accessible->childCount(); - for (int i = 0; i < childCount; ++i) { - if (QAccessibleInterface *childAcc = accessible->child(i)) { - if (childAcc->state().selected) { - anySelected = true; - break; - } - } - } - *selectionRequired = anySelected && !accessible->state().multiSelectable && !accessible->state().extSelectable; - } - return S_OK; - }))) { - return E_FAIL; - } - - *value = *selectionRequired; - return S_OK; -} - -// Returns an array of providers with the selected items. -HRESULT STDMETHODCALLTYPE QWinRTUiaSelectionProvider::GetSelection(UINT32 *returnValueSize, IIRawElementProviderSimple ***returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!returnValueSize || !returnValue) - return E_INVALIDARG; - *returnValueSize = 0; - *returnValue = nullptr; - - auto accid = id(); - auto elementIds = std::make_shared<QVarLengthArray<QAccessible::Id>>(); - - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementIds]() { - if (QAccessibleInterface *accessible = accessibleForId(accid)) { - int childCount = accessible->childCount(); - for (int i = 0; i < childCount; ++i) { - if (QAccessibleInterface *childAcc = accessible->child(i)) { - if (childAcc->state().selected) { - QAccessible::Id childId = idForAccessible(childAcc); - QWinRTUiaMetadataCache::instance()->load(childId); - elementIds->append(childId); - } - } - } - } - return S_OK; - }))) { - return E_FAIL; - } - - return QWinRTUiaMainProvider::rawProviderArrayForAccessibleIdList(*elementIds, returnValueSize, returnValue); -} - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionprovider.h b/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionprovider.h deleted file mode 100644 index dcd286800f..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiaselectionprovider.h +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTUIASELECTIONPROVIDER_H -#define QWINRTUIASELECTIONPROVIDER_H - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include "qwinrtuiabaseprovider.h" - -#include <wrl.h> -#include <windows.ui.xaml.h> - -QT_BEGIN_NAMESPACE - -// Implements the Selection control pattern provider. Used for Lists. -class QWinRTUiaSelectionProvider : - public QWinRTUiaBaseProvider, - public Microsoft::WRL::RuntimeClass<ABI::Windows::UI::Xaml::Automation::Provider::ISelectionProvider> -{ - Q_OBJECT - Q_DISABLE_COPY(QWinRTUiaSelectionProvider) - InspectableClass(L"QWinRTUiaSelectionProvider", BaseTrust); - -public: - explicit QWinRTUiaSelectionProvider(QAccessible::Id id); - virtual ~QWinRTUiaSelectionProvider(); - - // ISelectionProvider - HRESULT STDMETHODCALLTYPE get_CanSelectMultiple(boolean *value) override; - HRESULT STDMETHODCALLTYPE get_IsSelectionRequired(boolean *value) override; - HRESULT STDMETHODCALLTYPE GetSelection(UINT32 *returnValueSize, ABI::Windows::UI::Xaml::Automation::Provider::IIRawElementProviderSimple ***returnValue) override; -}; - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) - -#endif // QWINRTUIASELECTIONPROVIDER_H diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableitemprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableitemprovider.cpp deleted file mode 100644 index 7cd953de87..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableitemprovider.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include "qwinrtuiatableitemprovider.h" -#include "qwinrtuiamainprovider.h" -#include "qwinrtuiametadatacache.h" -#include "qwinrtuiautils.h" - -#include <QtGui/QAccessible> -#include <QtGui/QAccessibleInterface> -#include <QtCore/QLoggingCategory> -#include <QtCore/QString> -#include <QtCore/private/qeventdispatcher_winrt_p.h> - -#include <memory> - -QT_BEGIN_NAMESPACE - -using namespace QWinRTUiAutomation; -using namespace ABI::Windows::UI::Xaml::Automation; -using namespace ABI::Windows::UI::Xaml::Automation::Provider; - -QWinRTUiaTableItemProvider::QWinRTUiaTableItemProvider(QAccessible::Id id) : - QWinRTUiaBaseProvider(id) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; -} - -QWinRTUiaTableItemProvider::~QWinRTUiaTableItemProvider() -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; -} - -// Returns the providers for the column headers associated with the item. -HRESULT STDMETHODCALLTYPE QWinRTUiaTableItemProvider::GetColumnHeaderItems(UINT32 *returnValueSize, IIRawElementProviderSimple ***returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!returnValueSize || !returnValue) - return E_INVALIDARG; - *returnValueSize = 0; - *returnValue = nullptr; - - auto accid = id(); - auto elementIds = std::make_shared<QVarLengthArray<QAccessible::Id>>(); - - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementIds]() { - if (QAccessibleInterface *accessible = accessibleForId(accid)) { - if (QAccessibleTableCellInterface *tableCellInterface = accessible->tableCellInterface()) { - QList<QAccessibleInterface *> headers = tableCellInterface->columnHeaderCells(); - for (auto header : qAsConst(headers)) { - QAccessible::Id headerId = idForAccessible(header); - QWinRTUiaMetadataCache::instance()->load(headerId); - elementIds->append(headerId); - } - } - } - return S_OK; - }))) { - return E_FAIL; - } - - return QWinRTUiaMainProvider::rawProviderArrayForAccessibleIdList(*elementIds, returnValueSize, returnValue); -} - -// Returns the providers for the row headers associated with the item. -HRESULT STDMETHODCALLTYPE QWinRTUiaTableItemProvider::GetRowHeaderItems(UINT32 *returnValueSize, IIRawElementProviderSimple ***returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!returnValueSize || !returnValue) - return E_INVALIDARG; - *returnValueSize = 0; - *returnValue = nullptr; - - auto accid = id(); - auto elementIds = std::make_shared<QVarLengthArray<QAccessible::Id>>(); - - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementIds]() { - if (QAccessibleInterface *accessible = accessibleForId(accid)) { - if (QAccessibleTableCellInterface *tableCellInterface = accessible->tableCellInterface()) { - QList<QAccessibleInterface *> headers = tableCellInterface->rowHeaderCells(); - for (auto header : qAsConst(headers)) { - QAccessible::Id headerId = idForAccessible(header); - QWinRTUiaMetadataCache::instance()->load(headerId); - elementIds->append(headerId); - } - } - } - return S_OK; - }))) { - return E_FAIL; - } - - return QWinRTUiaMainProvider::rawProviderArrayForAccessibleIdList(*elementIds, returnValueSize, returnValue); -} - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableitemprovider.h b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableitemprovider.h deleted file mode 100644 index cb759864ae..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableitemprovider.h +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTUIATABLEITEMPROVIDER_H -#define QWINRTUIATABLEITEMPROVIDER_H - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include "qwinrtuiabaseprovider.h" - -#include <wrl.h> -#include <windows.ui.xaml.h> - -QT_BEGIN_NAMESPACE - -// Implements the Table Item control pattern provider. Used by items within a table/tree. -class QWinRTUiaTableItemProvider : - public QWinRTUiaBaseProvider, - public Microsoft::WRL::RuntimeClass<ABI::Windows::UI::Xaml::Automation::Provider::ITableItemProvider> -{ - Q_OBJECT - Q_DISABLE_COPY(QWinRTUiaTableItemProvider) - InspectableClass(L"QWinRTUiaTableItemProvider", BaseTrust); - -public: - explicit QWinRTUiaTableItemProvider(QAccessible::Id id); - virtual ~QWinRTUiaTableItemProvider(); - - // ITableItemProvider - HRESULT STDMETHODCALLTYPE GetColumnHeaderItems(UINT32 *returnValueSize, ABI::Windows::UI::Xaml::Automation::Provider::IIRawElementProviderSimple ***returnValue) override; - HRESULT STDMETHODCALLTYPE GetRowHeaderItems(UINT32 *returnValueSize, ABI::Windows::UI::Xaml::Automation::Provider::IIRawElementProviderSimple ***returnValue) override; -}; - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) - -#endif // QWINRTUIATABLEITEMPROVIDER_H diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableprovider.cpp deleted file mode 100644 index d763b320b1..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableprovider.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include "qwinrtuiatableprovider.h" -#include "qwinrtuiamainprovider.h" -#include "qwinrtuiametadatacache.h" -#include "qwinrtuiautils.h" - -#include <QtGui/QAccessible> -#include <QtGui/QAccessibleInterface> -#include <QtCore/QLoggingCategory> -#include <QtCore/QString> -#include <QtCore/private/qeventdispatcher_winrt_p.h> - -#include <memory> - -QT_BEGIN_NAMESPACE - -using namespace QWinRTUiAutomation; -using namespace ABI::Windows::UI::Xaml::Automation; -using namespace ABI::Windows::UI::Xaml::Automation::Provider; -using namespace ABI::Windows::UI::Xaml::Automation::Peers; - -QWinRTUiaTableProvider::QWinRTUiaTableProvider(QAccessible::Id id) : - QWinRTUiaBaseProvider(id) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; -} - -QWinRTUiaTableProvider::~QWinRTUiaTableProvider() -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; -} - -// Returns the primary direction of traversal for the table. -HRESULT STDMETHODCALLTYPE QWinRTUiaTableProvider::get_RowOrColumnMajor(RowOrColumnMajor *value) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!value) - return E_INVALIDARG; - *value = RowOrColumnMajor_Indeterminate; - return S_OK; -} - -// Gets the providers for all the column headers in the table. -HRESULT STDMETHODCALLTYPE QWinRTUiaTableProvider::GetColumnHeaders(UINT32 *returnValueSize, IIRawElementProviderSimple ***returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!returnValueSize || !returnValue) - return E_INVALIDARG; - *returnValueSize = 0; - *returnValue = nullptr; - - auto accid = id(); - auto elementIds = std::make_shared<QVarLengthArray<QAccessible::Id>>(); - - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementIds]() { - if (QAccessibleInterface *accessible = accessibleForId(accid)) { - if (QAccessibleTableInterface *tableInterface = accessible->tableInterface()) { - for (int i = 0; i < tableInterface->columnCount(); ++i) { - if (QAccessibleInterface *cell = tableInterface->cellAt(0, i)) { - QWinRTUiaMetadataCache::instance()->load(idForAccessible(cell)); - if (QAccessibleTableCellInterface *tableCellInterface = cell->tableCellInterface()) { - QList<QAccessibleInterface *> headers = tableCellInterface->columnHeaderCells(); - for (auto header : qAsConst(headers)) { - QAccessible::Id headerId = idForAccessible(header); - QWinRTUiaMetadataCache::instance()->load(headerId); - elementIds->append(headerId); - } - } - } - } - } - } - return S_OK; - }))) { - return E_FAIL; - } - - return QWinRTUiaMainProvider::rawProviderArrayForAccessibleIdList(*elementIds, returnValueSize, returnValue); -} - -// Gets the providers for all the row headers in the table. -HRESULT STDMETHODCALLTYPE QWinRTUiaTableProvider::GetRowHeaders(UINT32 *returnValueSize, IIRawElementProviderSimple ***returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!returnValueSize || !returnValue) - return E_INVALIDARG; - *returnValueSize = 0; - *returnValue = nullptr; - - auto accid = id(); - auto elementIds = std::make_shared<QVarLengthArray<QAccessible::Id>>(); - - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, elementIds]() { - if (QAccessibleInterface *accessible = accessibleForId(accid)) { - if (QAccessibleTableInterface *tableInterface = accessible->tableInterface()) { - for (int i = 0; i < tableInterface->rowCount(); ++i) { - if (QAccessibleInterface *cell = tableInterface->cellAt(i, 0)) { - QWinRTUiaMetadataCache::instance()->load(idForAccessible(cell)); - if (QAccessibleTableCellInterface *tableCellInterface = cell->tableCellInterface()) { - QList<QAccessibleInterface *> headers = tableCellInterface->rowHeaderCells(); - for (auto header : qAsConst(headers)) { - QAccessible::Id headerId = idForAccessible(header); - QWinRTUiaMetadataCache::instance()->load(headerId); - elementIds->append(headerId); - } - } - } - } - } - } - return S_OK; - }))) { - return E_FAIL; - } - - return QWinRTUiaMainProvider::rawProviderArrayForAccessibleIdList(*elementIds, returnValueSize, returnValue); -} - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableprovider.h b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableprovider.h deleted file mode 100644 index 0cd174e401..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatableprovider.h +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTUIATABLEPROVIDER_H -#define QWINRTUIATABLEPROVIDER_H - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include "qwinrtuiabaseprovider.h" - -#include <wrl.h> -#include <windows.ui.xaml.h> - -QT_BEGIN_NAMESPACE - -// Implements the Table control pattern provider. Used by tables/trees. -class QWinRTUiaTableProvider : - public QWinRTUiaBaseProvider, - public Microsoft::WRL::RuntimeClass<ABI::Windows::UI::Xaml::Automation::Provider::ITableProvider> -{ - Q_OBJECT - Q_DISABLE_COPY(QWinRTUiaTableProvider) - InspectableClass(L"QWinRTUiaTableProvider", BaseTrust); - -public: - explicit QWinRTUiaTableProvider(QAccessible::Id id); - virtual ~QWinRTUiaTableProvider(); - - // ITableProvider - HRESULT STDMETHODCALLTYPE get_RowOrColumnMajor(ABI::Windows::UI::Xaml::Automation::RowOrColumnMajor *value) override; - HRESULT STDMETHODCALLTYPE GetColumnHeaders(UINT32 *returnValueSize, ABI::Windows::UI::Xaml::Automation::Provider::IIRawElementProviderSimple ***returnValue) override; - HRESULT STDMETHODCALLTYPE GetRowHeaders(UINT32 *returnValueSize, ABI::Windows::UI::Xaml::Automation::Provider::IIRawElementProviderSimple ***returnValue) override; -}; - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) - -#endif // QWINRTUIATABLEPROVIDER_H diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextprovider.cpp deleted file mode 100644 index cd7420f360..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextprovider.cpp +++ /dev/null @@ -1,234 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include "qwinrtuiatextprovider.h" -#include "qwinrtuiametadatacache.h" -#include "qwinrtuiatextrangeprovider.h" -#include "qwinrtuiautils.h" - -#include <QtGui/QAccessible> -#include <QtGui/QAccessibleInterface> -#include <QtCore/QLoggingCategory> -#include <QtCore/QString> -#include <QtCore/private/qeventdispatcher_winrt_p.h> - -#include <memory> - -QT_BEGIN_NAMESPACE - -using namespace QWinRTUiAutomation; -using namespace Microsoft::WRL; -using namespace Microsoft::WRL::Wrappers; -using namespace ABI::Windows::UI::Xaml::Automation; -using namespace ABI::Windows::UI::Xaml::Automation::Provider; - -QWinRTUiaTextProvider::QWinRTUiaTextProvider(QAccessible::Id id) : - QWinRTUiaBaseProvider(id) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; -} - -QWinRTUiaTextProvider::~QWinRTUiaTextProvider() -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; -} - -// Returns a text range provider for the entire text. -HRESULT STDMETHODCALLTYPE QWinRTUiaTextProvider::get_DocumentRange(ITextRangeProvider **value) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!value) - return E_INVALIDARG; - - QSharedPointer<QWinRTUiaControlMetadata> metadata = QWinRTUiaMetadataCache::instance()->metadataForId(id()); - ComPtr<QWinRTUiaTextRangeProvider> textRangeProvider = Make<QWinRTUiaTextRangeProvider>(id(), 0, metadata->characterCount()); - return textRangeProvider.CopyTo(value); -} - -// Currently supporting single selection. -HRESULT STDMETHODCALLTYPE QWinRTUiaTextProvider::get_SupportedTextSelection(SupportedTextSelection *value) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - if (!value) - return E_INVALIDARG; - *value = SupportedTextSelection_Single; - return S_OK; - -} - -// Returns an array of providers for the selected text ranges. -HRESULT STDMETHODCALLTYPE QWinRTUiaTextProvider::GetSelection(UINT32 *returnValueSize, ITextRangeProvider ***returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!returnValueSize || !returnValue) - return E_INVALIDARG; - *returnValueSize = 0; - *returnValue = nullptr; - - struct Selection { int startOffset, endOffset; }; - - auto accid = id(); - auto selections = std::make_shared<QVarLengthArray<Selection>>(); - - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, selections]() { - if (QAccessibleInterface *accessible = accessibleForId(accid)) { - if (QAccessibleTextInterface *textInterface = accessible->textInterface()) { - for (int i = 0; i < textInterface->selectionCount(); ++i) { - int startOffset, endOffset; - textInterface->selection(i, &startOffset, &endOffset); - selections->append({startOffset, endOffset}); - } - if (selections->size() == 0) { - // If there is no selection, we return an array with a single degenerate (empty) text range at the cursor position. - auto cur = textInterface->cursorPosition(); - selections->append({cur, cur}); - } - } - } - return S_OK; - }))) { - return E_FAIL; - } - - int selCount = selections->size(); - if (selCount < 1) - return E_FAIL; - - ITextRangeProvider **providerArray = static_cast<ITextRangeProvider **>(CoTaskMemAlloc(selCount * sizeof(ITextRangeProvider *))); - if (!providerArray) - return E_OUTOFMEMORY; - - auto dst = providerArray; - for (auto sel : *selections) { - ComPtr<QWinRTUiaTextRangeProvider> textRangeProvider - = Make<QWinRTUiaTextRangeProvider>(id(), sel.startOffset, sel.endOffset); - textRangeProvider.CopyTo(dst++); - } - *returnValueSize = selCount; - *returnValue = providerArray; - return S_OK; -} - -// Returns an array of providers for the visible text ranges. -HRESULT STDMETHODCALLTYPE QWinRTUiaTextProvider::GetVisibleRanges(UINT32 *returnValueSize, ITextRangeProvider ***returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!returnValueSize || !returnValue) - return E_INVALIDARG; - - QSharedPointer<QWinRTUiaControlMetadata> metadata = QWinRTUiaMetadataCache::instance()->metadataForId(id()); - - // Considering the entire text as visible. - ComPtr<QWinRTUiaTextRangeProvider> textRangeProvider = Make<QWinRTUiaTextRangeProvider>(id(), 0, metadata->characterCount()); - textRangeProvider.CopyTo(*returnValue); - *returnValueSize = 1; - return S_OK; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaTextProvider::RangeFromChild(IIRawElementProviderSimple *childElement, ITextRangeProvider **returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - if (!childElement || !returnValue) - return E_INVALIDARG; - *returnValue = nullptr; - // No children supported. - return S_OK; -} - -// Returns a degenerate text range at the specified point. -HRESULT STDMETHODCALLTYPE QWinRTUiaTextProvider::RangeFromPoint(ABI::Windows::Foundation::Point screenLocation, ITextRangeProvider **returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!returnValue) - return E_INVALIDARG; - *returnValue = nullptr; - - const QPoint pt(screenLocation.X, screenLocation.Y); - auto accid = id(); - auto offset = std::make_shared<int>(); - - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, pt, offset]() { - if (QAccessibleInterface *accessible = accessibleForId(accid)) - if (QAccessibleTextInterface *textInterface = accessible->textInterface()) - *offset = qBound(0, textInterface->offsetAtPoint(pt), textInterface->characterCount() - 1); - return S_OK; - }))) { - return E_FAIL; - } - - ComPtr<QWinRTUiaTextRangeProvider> textRangeProvider = Make<QWinRTUiaTextRangeProvider>(id(), *offset, *offset); - textRangeProvider.CopyTo(returnValue); - return S_OK; -} - -// Not supporting annotations. -HRESULT STDMETHODCALLTYPE QWinRTUiaTextProvider::RangeFromAnnotation(IIRawElementProviderSimple *annotationElement, ITextRangeProvider **returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - if (!annotationElement || !returnValue) - return E_INVALIDARG; - *returnValue = nullptr; - return S_OK; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaTextProvider::GetCaretRange(boolean *isActive, ITextRangeProvider **returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!isActive || !returnValue) - return E_INVALIDARG; - - QSharedPointer<QWinRTUiaControlMetadata> metadata = QWinRTUiaMetadataCache::instance()->metadataForId(id()); - *isActive = metadata->state().focused; - - ComPtr<QWinRTUiaTextRangeProvider> textRangeProvider = Make<QWinRTUiaTextRangeProvider>(id(), metadata->cursorPosition(), metadata->cursorPosition()); - return textRangeProvider.CopyTo(returnValue); -} - - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextprovider.h b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextprovider.h deleted file mode 100644 index 80d88e4115..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextprovider.h +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTUIATEXTPROVIDER_H -#define QWINRTUIATEXTPROVIDER_H - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include "qwinrtuiabaseprovider.h" - -#include <wrl.h> -#include <windows.ui.xaml.h> - -QT_BEGIN_NAMESPACE - -// Implements the Text control pattern provider. Used for text controls. -class QWinRTUiaTextProvider : - public QWinRTUiaBaseProvider, - public Microsoft::WRL::RuntimeClass<ABI::Windows::UI::Xaml::Automation::Provider::ITextProvider, ABI::Windows::UI::Xaml::Automation::Provider::ITextProvider2> -{ - Q_OBJECT - Q_DISABLE_COPY(QWinRTUiaTextProvider) - InspectableClass(L"QWinRTUiaTextProvider", BaseTrust); - -public: - explicit QWinRTUiaTextProvider(QAccessible::Id id); - virtual ~QWinRTUiaTextProvider(); - - // ITextProvider - HRESULT STDMETHODCALLTYPE get_DocumentRange(ABI::Windows::UI::Xaml::Automation::Provider::ITextRangeProvider **value) override; - HRESULT STDMETHODCALLTYPE get_SupportedTextSelection(ABI::Windows::UI::Xaml::Automation::SupportedTextSelection *value) override; - HRESULT STDMETHODCALLTYPE GetSelection(UINT32 *returnValueSize, ABI::Windows::UI::Xaml::Automation::Provider::ITextRangeProvider ***returnValue) override; - HRESULT STDMETHODCALLTYPE GetVisibleRanges(UINT32 *returnValueSize, ABI::Windows::UI::Xaml::Automation::Provider::ITextRangeProvider ***returnValue) override; - HRESULT STDMETHODCALLTYPE RangeFromChild(ABI::Windows::UI::Xaml::Automation::Provider::IIRawElementProviderSimple *childElement, ABI::Windows::UI::Xaml::Automation::Provider::ITextRangeProvider **returnValue) override; - HRESULT STDMETHODCALLTYPE RangeFromPoint(ABI::Windows::Foundation::Point screenLocation, ABI::Windows::UI::Xaml::Automation::Provider::ITextRangeProvider **returnValue) override; - - // ITextProvider2 - HRESULT STDMETHODCALLTYPE RangeFromAnnotation(ABI::Windows::UI::Xaml::Automation::Provider::IIRawElementProviderSimple *annotationElement, ABI::Windows::UI::Xaml::Automation::Provider::ITextRangeProvider **returnValue) override; - HRESULT STDMETHODCALLTYPE GetCaretRange(boolean *isActive, ABI::Windows::UI::Xaml::Automation::Provider::ITextRangeProvider **returnValue) override; -}; - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) - -#endif // QWINRTUIATEXTPROVIDER_H diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextrangeprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextrangeprovider.cpp deleted file mode 100644 index ca15feaff9..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextrangeprovider.cpp +++ /dev/null @@ -1,498 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include "qwinrtuiatextrangeprovider.h" -#include "qwinrtuiametadatacache.h" -#include "qwinrtuiamainprovider.h" -#include "qwinrtuiautils.h" - -#include <QtGui/QAccessible> -#include <QtGui/QAccessibleInterface> -#include <QtCore/QLoggingCategory> -#include <QtCore/QString> -#include <QtCore/private/qeventdispatcher_winrt_p.h> - -#include <memory> - -QT_BEGIN_NAMESPACE - -using namespace QWinRTUiAutomation; -using namespace Microsoft::WRL; -using namespace Microsoft::WRL::Wrappers; -using namespace ABI::Windows::Foundation; -using namespace ABI::Windows::UI::Xaml; -using namespace ABI::Windows::UI::Xaml::Automation; -using namespace ABI::Windows::UI::Xaml::Automation::Provider; -using namespace ABI::Windows::UI::Xaml::Automation::Text; - -QWinRTUiaTextRangeProvider::QWinRTUiaTextRangeProvider(QAccessible::Id id, int startOffset, int endOffset) : - QWinRTUiaBaseProvider(id), - m_startOffset(startOffset), - m_endOffset(endOffset) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__ << startOffset << endOffset; -} - -QWinRTUiaTextRangeProvider::~QWinRTUiaTextRangeProvider() -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaTextRangeProvider::Clone(ITextRangeProvider **returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - if (!returnValue) - return E_INVALIDARG; - - ComPtr<QWinRTUiaTextRangeProvider> textRangeProvider = Make<QWinRTUiaTextRangeProvider>(id(), m_startOffset, m_endOffset); - textRangeProvider.CopyTo(returnValue); - return S_OK; -} - -// Two ranges are considered equal if their start/end points are the same. -HRESULT STDMETHODCALLTYPE QWinRTUiaTextRangeProvider::Compare(ITextRangeProvider *textRangeProvider, boolean *returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - if (!textRangeProvider || !returnValue) - return E_INVALIDARG; - - QWinRTUiaTextRangeProvider *targetProvider = static_cast<QWinRTUiaTextRangeProvider *>(textRangeProvider); - *returnValue = ((targetProvider->m_startOffset == m_startOffset) && (targetProvider->m_endOffset == m_endOffset)); - return S_OK; -} - -// Compare different endpoinds between two providers. -HRESULT STDMETHODCALLTYPE QWinRTUiaTextRangeProvider::CompareEndpoints(TextPatternRangeEndpoint endpoint, ITextRangeProvider *textRangeProvider, TextPatternRangeEndpoint targetEndpoint, INT32 *returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!textRangeProvider || !returnValue) - return E_INVALIDARG; - - QWinRTUiaTextRangeProvider *targetProvider = static_cast<QWinRTUiaTextRangeProvider *>(textRangeProvider); - - int point = (endpoint == TextPatternRangeEndpoint_Start) ? m_startOffset : m_endOffset; - int targetPoint = (targetEndpoint == TextPatternRangeEndpoint_Start) ? - targetProvider->m_startOffset : targetProvider->m_endOffset; - *returnValue = point - targetPoint; - return S_OK; -} - -// Expands/normalizes the range for a given text unit. -HRESULT STDMETHODCALLTYPE QWinRTUiaTextRangeProvider::ExpandToEnclosingUnit(TextUnit unit) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__ << "unit=" << unit << "this: " << this; - - QSharedPointer<QWinRTUiaControlMetadata> metadata = QWinRTUiaMetadataCache::instance()->metadataForId(id()); - - int len = metadata->characterCount(); - if (len < 1) { - m_startOffset = 0; - m_endOffset = 0; - } else { - if (unit == TextUnit_Character) { - m_startOffset = qBound(0, m_startOffset, len - 1); - m_endOffset = m_startOffset + 1; - } else { - QString text = metadata->text(); - for (int t = m_startOffset; t >= 0; --t) { - if (!isTextUnitSeparator(unit, text[t]) && ((t == 0) || isTextUnitSeparator(unit, text[t - 1]))) { - m_startOffset = t; - break; - } - } - for (int t = m_startOffset; t < len; ++t) { - if ((t == len - 1) || (isTextUnitSeparator(unit, text[t]) && ((unit == TextUnit_Word) || !isTextUnitSeparator(unit, text[t + 1])))) { - m_endOffset = t + 1; - break; - } - } - } - } - return S_OK; -} - -// Not supported. -HRESULT STDMETHODCALLTYPE QWinRTUiaTextRangeProvider::FindAttribute(INT32 /*attributeId*/, IInspectable * /*value*/, boolean /*backward*/, ITextRangeProvider **returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - if (!returnValue) - return E_INVALIDARG; - *returnValue = nullptr; - return S_OK; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaTextRangeProvider::FindText(HSTRING /*text*/, boolean /*backward*/, boolean /*ignoreCase*/, ITextRangeProvider **returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - if (!returnValue) - return E_INVALIDARG; - *returnValue = nullptr; - return S_OK; -} - -// Returns the value of a given attribute. -HRESULT STDMETHODCALLTYPE QWinRTUiaTextRangeProvider::GetAttributeValue(INT32 attributeId, IInspectable **returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__ << "attributeId=" << attributeId; - - if (!returnValue) - return E_INVALIDARG; - *returnValue = nullptr; - - ComPtr<IPropertyValueStatics> propertyValueStatics; - if (FAILED(RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Foundation_PropertyValue).Get(), IID_PPV_ARGS(&propertyValueStatics)))) - return E_FAIL; - - QSharedPointer<QWinRTUiaControlMetadata> metadata = QWinRTUiaMetadataCache::instance()->metadataForId(id()); - - switch (attributeId) { - case AutomationTextAttributesEnum_IsReadOnlyAttribute: - return propertyValueStatics->CreateBoolean(metadata->state().readOnly, returnValue); - case AutomationTextAttributesEnum_CaretPositionAttribute: - if (metadata->cursorPosition() == 0) - return propertyValueStatics->CreateInt32(AutomationCaretPosition_BeginningOfLine, returnValue); - else if (metadata->cursorPosition() == metadata->characterCount()) - return propertyValueStatics->CreateInt32(AutomationCaretPosition_EndOfLine, returnValue); - else - return propertyValueStatics->CreateInt32(AutomationCaretPosition_Unknown, returnValue); - default: - break; - } - return E_FAIL; -} - -// Returns an array of bounding rectangles for text lines within the range. -HRESULT STDMETHODCALLTYPE QWinRTUiaTextRangeProvider::GetBoundingRectangles(UINT32 *returnValueSize, DOUBLE **returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!returnValueSize || !returnValue) - return E_INVALIDARG; - *returnValueSize = 0; - *returnValue = nullptr; - - auto accid = id(); - auto startOffset = m_startOffset; - auto endOffset = m_endOffset; - auto rects = std::make_shared<QVarLengthArray<QRect>>(); - - if (!SUCCEEDED(QEventDispatcherWinRT::runOnMainThread([accid, startOffset, endOffset, rects]() { - if (QAccessibleInterface *accessible = accessibleForId(accid)) { - if (QAccessibleTextInterface *textInterface = accessible->textInterface()) { - int len = textInterface->characterCount(); - if ((startOffset >= 0) && (endOffset <= len) && (startOffset < endOffset)) { - int start, end; - textInterface->textAtOffset(startOffset, QAccessible::LineBoundary, &start, &end); - while ((start >= 0) && (end >= 0)) { - int startRange = qMax(start, startOffset); - int endRange = qMin(end, endOffset); - if (startRange < endRange) { - // Calculates a bounding rectangle for the line and adds it to the list. - const QRect startRect = textInterface->characterRect(startRange); - const QRect endRect = textInterface->characterRect(endRange - 1); - const QRect lineRect(qMin(startRect.x(), endRect.x()), - qMin(startRect.y(), endRect.y()), - qMax(startRect.x() + startRect.width(), endRect.x() + endRect.width()) - qMin(startRect.x(), endRect.x()), - qMax(startRect.y() + startRect.height(), endRect.y() + endRect.height()) - qMin(startRect.y(), endRect.y())); - rects->append(lineRect); - } - if (end >= len) break; - textInterface->textAfterOffset(end + 1, QAccessible::LineBoundary, &start, &end); - } - } - } - } - return S_OK; - }))) { - return E_FAIL; - } - - DOUBLE *doubleArray = static_cast<DOUBLE *>(CoTaskMemAlloc(4 * rects->size() * sizeof(DOUBLE))); - if (!doubleArray) - return E_OUTOFMEMORY; - - DOUBLE *dst = doubleArray; - for (auto rect : *rects) { - *dst++ = rect.left(); - *dst++ = rect.top(); - *dst++ = rect.width(); - *dst++ = rect.height(); - } - *returnValue = doubleArray; - *returnValueSize = 4 * rects->size(); - return S_OK; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaTextRangeProvider::GetEnclosingElement(IIRawElementProviderSimple **returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - if (!returnValue) - return E_INVALIDARG; - return QWinRTUiaMainProvider::rawProviderForAccessibleId(id(), returnValue); -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaTextRangeProvider::GetText(INT32 maxLength, HSTRING *returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - if (!returnValue) - return E_INVALIDARG; - *returnValue = nullptr; - - QSharedPointer<QWinRTUiaControlMetadata> metadata = QWinRTUiaMetadataCache::instance()->metadataForId(id()); - - QString rangeText = metadata->text().mid(m_startOffset, m_endOffset - m_startOffset); - - if ((maxLength > -1) && (rangeText.size() > maxLength)) - rangeText.truncate(maxLength); - return qHString(rangeText, returnValue); -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaTextRangeProvider::Move(TextUnit unit, INT32 count, INT32 *returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - if (!returnValue) - return E_INVALIDARG; - *returnValue = 0; - - QSharedPointer<QWinRTUiaControlMetadata> metadata = QWinRTUiaMetadataCache::instance()->metadataForId(id()); - - int len = metadata->characterCount(); - if (len < 1) - return S_OK; - - if (unit == TextUnit_Character) { - // Moves the start point, ensuring it lies within the bounds. - int start = qBound(0, m_startOffset + count, len - 1); - // If range was initially empty, leaves it as is; otherwise, normalizes it to one char. - m_endOffset = (m_endOffset > m_startOffset) ? start + 1 : start; - *returnValue = start - m_startOffset; // Returns the actually moved distance. - m_startOffset = start; - } else { - if (count > 0) { - MoveEndpointByUnit(TextPatternRangeEndpoint_End, unit, count, returnValue); - MoveEndpointByUnit(TextPatternRangeEndpoint_Start, unit, count, returnValue); - } else { - MoveEndpointByUnit(TextPatternRangeEndpoint_Start, unit, count, returnValue); - MoveEndpointByUnit(TextPatternRangeEndpoint_End, unit, count, returnValue); - } - } - return S_OK; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaTextRangeProvider::MoveEndpointByUnit(TextPatternRangeEndpoint endpoint, TextUnit unit, INT32 count, INT32 *returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - if (!returnValue) - return E_INVALIDARG; - *returnValue = 0; - - QSharedPointer<QWinRTUiaControlMetadata> metadata = QWinRTUiaMetadataCache::instance()->metadataForId(id()); - - int len = metadata->characterCount(); - if (len < 1) - return S_OK; - - if (unit == TextUnit_Character) { - if (endpoint == TextPatternRangeEndpoint_Start) { - int boundedValue = qBound(0, m_startOffset + count, len - 1); - *returnValue = boundedValue - m_startOffset; - m_startOffset = boundedValue; - m_endOffset = qBound(m_startOffset, m_endOffset, len); - } else { - int boundedValue = qBound(0, m_endOffset + count, len); - *returnValue = boundedValue - m_endOffset; - m_endOffset = boundedValue; - m_startOffset = qBound(0, m_startOffset, m_endOffset); - } - } else { - QString text = metadata->text(); - int moved = 0; - - if (endpoint == TextPatternRangeEndpoint_Start) { - if (count > 0) { - for (int t = m_startOffset; (t < len - 1) && (moved < count); ++t) { - if (isTextUnitSeparator(unit, text[t]) && !isTextUnitSeparator(unit, text[t + 1])) { - m_startOffset = t + 1; - ++moved; - } - } - m_endOffset = qBound(m_startOffset, m_endOffset, len); - } else { - for (int t = m_startOffset - 1; (t >= 0) && (moved > count); --t) { - if (!isTextUnitSeparator(unit, text[t]) && ((t == 0) || isTextUnitSeparator(unit, text[t - 1]))) { - m_startOffset = t; - --moved; - } - } - } - } else { - if (count > 0) { - for (int t = m_endOffset; (t < len) && (moved < count); ++t) { - if ((t == len - 1) || (isTextUnitSeparator(unit, text[t]) && ((unit == TextUnit_Word) || !isTextUnitSeparator(unit, text[t + 1])))) { - m_endOffset = t + 1; - ++moved; - } - } - } else { - int end = 0; - for (int t = m_endOffset - 2; (t > 0) && (moved > count); --t) { - if (isTextUnitSeparator(unit, text[t]) && ((unit == TextUnit_Word) || !isTextUnitSeparator(unit, text[t + 1]))) { - end = t + 1; - --moved; - } - } - m_endOffset = end; - m_startOffset = qBound(0, m_startOffset, m_endOffset); - } - } - *returnValue = moved; - } - return S_OK; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaTextRangeProvider::MoveEndpointByRange(TextPatternRangeEndpoint endpoint, ITextRangeProvider *textRangeProvider, TextPatternRangeEndpoint targetEndpoint) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - if (!textRangeProvider) - return E_INVALIDARG; - - QWinRTUiaTextRangeProvider *targetProvider = static_cast<QWinRTUiaTextRangeProvider *>(textRangeProvider); - - int targetPoint = (targetEndpoint == TextPatternRangeEndpoint_Start) ? - targetProvider->m_startOffset : targetProvider->m_endOffset; - - // If the moved endpoint crosses the other endpoint, that one is moved too. - if (endpoint == TextPatternRangeEndpoint_Start) { - m_startOffset = targetPoint; - if (m_endOffset < m_startOffset) - m_endOffset = m_startOffset; - } else { - m_endOffset = targetPoint; - if (m_endOffset < m_startOffset) - m_startOffset = m_endOffset; - } - return S_OK; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaTextRangeProvider::Select() -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - auto accid = id(); - auto startOffset = m_startOffset; - auto endOffset = m_endOffset; - - QEventDispatcherWinRT::runOnMainThread([accid, startOffset, endOffset]() { - if (QAccessibleInterface *accessible = accessibleForId(accid)) - if (QAccessibleTextInterface *textInterface = accessible->textInterface()) { - // unselects all and adds a new selection - for (int i = textInterface->selectionCount() - 1; i >= 0; --i) - textInterface->removeSelection(i); - textInterface->addSelection(startOffset, endOffset); - } - QWinRTUiaMetadataCache::instance()->load(accid); - return S_OK; - }, 0); - return S_OK; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaTextRangeProvider::AddToSelection() -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - return Select(); -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaTextRangeProvider::RemoveFromSelection() -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - auto accid = id(); - - QEventDispatcherWinRT::runOnMainThread([accid]() { - if (QAccessibleInterface *accessible = accessibleForId(accid)) - if (QAccessibleTextInterface *textInterface = accessible->textInterface()) { - // unselects all - for (int i = textInterface->selectionCount() - 1; i >= 0; --i) - textInterface->removeSelection(i); - } - QWinRTUiaMetadataCache::instance()->load(accid); - return S_OK; - }, 0); - return S_OK; -} - -HRESULT STDMETHODCALLTYPE QWinRTUiaTextRangeProvider::ScrollIntoView(boolean /*alignToTop*/) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - auto accid = id(); - auto startOffset = m_startOffset; - auto endOffset = m_endOffset; - - QEventDispatcherWinRT::runOnMainThread([accid, startOffset, endOffset]() { - if (QAccessibleInterface *accessible = accessibleForId(accid)) - if (QAccessibleTextInterface *textInterface = accessible->textInterface()) { - textInterface->scrollToSubstring(startOffset, endOffset); - } - QWinRTUiaMetadataCache::instance()->load(accid); - return S_OK; - }, 0); - return S_OK; -} - -// Returns an array of children elements embedded within the range. -HRESULT STDMETHODCALLTYPE QWinRTUiaTextRangeProvider::GetChildren(UINT32 *returnValueSize, IIRawElementProviderSimple ***returnValue) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!returnValue) - return E_INVALIDARG; - // Not supporting any children. - returnValueSize = 0; - *returnValue = nullptr; - return S_OK; -} - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextrangeprovider.h b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextrangeprovider.h deleted file mode 100644 index 81b5f0d400..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatextrangeprovider.h +++ /dev/null @@ -1,95 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTUIATEXTRANGEPROVIDER_H -#define QWINRTUIATEXTRANGEPROVIDER_H - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include "qwinrtuiabaseprovider.h" - -#include <wrl.h> -#include <windows.ui.xaml.h> - -QT_BEGIN_NAMESPACE - -// Implements the Text Range control pattern provider. Used for text controls. -class QWinRTUiaTextRangeProvider : - public QWinRTUiaBaseProvider, - public Microsoft::WRL::RuntimeClass<ABI::Windows::UI::Xaml::Automation::Provider::ITextRangeProvider> -{ - Q_OBJECT - Q_DISABLE_COPY(QWinRTUiaTextRangeProvider) - InspectableClass(L"QWinRTUiaTextRangeProvider", BaseTrust); - -public: - explicit QWinRTUiaTextRangeProvider(QAccessible::Id id, int startOffset, int endOffset); - virtual ~QWinRTUiaTextRangeProvider(); - - // ITextRangeProvider - HRESULT STDMETHODCALLTYPE Clone(ABI::Windows::UI::Xaml::Automation::Provider::ITextRangeProvider **returnValue) override; - HRESULT STDMETHODCALLTYPE Compare(ABI::Windows::UI::Xaml::Automation::Provider::ITextRangeProvider *textRangeProvider, boolean *returnValue) override; - HRESULT STDMETHODCALLTYPE CompareEndpoints(ABI::Windows::UI::Xaml::Automation::Text::TextPatternRangeEndpoint endpoint, ABI::Windows::UI::Xaml::Automation::Provider::ITextRangeProvider *textRangeProvider, ABI::Windows::UI::Xaml::Automation::Text::TextPatternRangeEndpoint targetEndpoint, INT32 *returnValue) override; - HRESULT STDMETHODCALLTYPE ExpandToEnclosingUnit(ABI::Windows::UI::Xaml::Automation::Text::TextUnit unit) override; - HRESULT STDMETHODCALLTYPE FindAttribute(INT32 attributeId, IInspectable *value, boolean backward, ABI::Windows::UI::Xaml::Automation::Provider::ITextRangeProvider **returnValue) override; - HRESULT STDMETHODCALLTYPE FindText(HSTRING text, boolean backward, boolean ignoreCase, ABI::Windows::UI::Xaml::Automation::Provider::ITextRangeProvider **returnValue) override; - HRESULT STDMETHODCALLTYPE GetAttributeValue(INT32 attributeId, IInspectable **returnValue) override; - HRESULT STDMETHODCALLTYPE GetBoundingRectangles(UINT32 *returnValueSize, DOUBLE **returnValue) override; - HRESULT STDMETHODCALLTYPE GetEnclosingElement(ABI::Windows::UI::Xaml::Automation::Provider::IIRawElementProviderSimple **returnValue) override; - HRESULT STDMETHODCALLTYPE GetText(INT32 maxLength, HSTRING *returnValue) override; - HRESULT STDMETHODCALLTYPE Move(ABI::Windows::UI::Xaml::Automation::Text::TextUnit unit, INT32 count, INT32 *returnValue) override; - HRESULT STDMETHODCALLTYPE MoveEndpointByUnit(ABI::Windows::UI::Xaml::Automation::Text::TextPatternRangeEndpoint endpoint, ABI::Windows::UI::Xaml::Automation::Text::TextUnit unit, INT32 count, INT32 *returnValue) override; - HRESULT STDMETHODCALLTYPE MoveEndpointByRange(ABI::Windows::UI::Xaml::Automation::Text::TextPatternRangeEndpoint endpoint, ABI::Windows::UI::Xaml::Automation::Provider::ITextRangeProvider *textRangeProvider, ABI::Windows::UI::Xaml::Automation::Text::TextPatternRangeEndpoint targetEndpoint) override; - HRESULT STDMETHODCALLTYPE Select() override; - HRESULT STDMETHODCALLTYPE AddToSelection() override; - HRESULT STDMETHODCALLTYPE RemoveFromSelection() override; - HRESULT STDMETHODCALLTYPE ScrollIntoView(boolean alignToTop) override; - HRESULT STDMETHODCALLTYPE GetChildren(UINT32 *returnValueSize, ABI::Windows::UI::Xaml::Automation::Provider::IIRawElementProviderSimple ***returnValue) override; - -private: - int m_startOffset; - int m_endOffset; -}; - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) - -#endif // QWINRTUIATEXTRANGEPROVIDER_H diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatoggleprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatoggleprovider.cpp deleted file mode 100644 index 59f55eb422..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatoggleprovider.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include "qwinrtuiatoggleprovider.h" -#include "qwinrtuiametadatacache.h" -#include "qwinrtuiautils.h" - -#include <QtGui/QAccessible> -#include <QtGui/QAccessibleInterface> -#include <QtCore/QLoggingCategory> -#include <QtCore/QString> -#include <QtCore/private/qeventdispatcher_winrt_p.h> - -QT_BEGIN_NAMESPACE - -using namespace QWinRTUiAutomation; -using namespace ABI::Windows::UI::Xaml::Automation; -using namespace ABI::Windows::UI::Xaml::Automation::Provider; - -QWinRTUiaToggleProvider::QWinRTUiaToggleProvider(QAccessible::Id id) : - QWinRTUiaBaseProvider(id) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; -} - -QWinRTUiaToggleProvider::~QWinRTUiaToggleProvider() -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; -} - -// Gets the current toggle state. -HRESULT STDMETHODCALLTYPE QWinRTUiaToggleProvider::get_ToggleState(ToggleState *value) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!value) - return E_INVALIDARG; - QSharedPointer<QWinRTUiaControlMetadata> metadata = QWinRTUiaMetadataCache::instance()->metadataForId(id()); - if (metadata->state().checked) - *value = metadata->state().checkStateMixed ? ToggleState_Indeterminate : ToggleState_On; - else - *value = ToggleState_Off; - return S_OK; -} - -// Toggles the state by invoking the toggle action. -HRESULT STDMETHODCALLTYPE QWinRTUiaToggleProvider::Toggle() -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - auto accid = id(); - - QEventDispatcherWinRT::runOnMainThread([accid]() { - if (QAccessibleInterface *accessible = accessibleForId(accid)) - if (QAccessibleActionInterface *actionInterface = accessible->actionInterface()) - actionInterface->doAction(QAccessibleActionInterface::toggleAction()); - QWinRTUiaMetadataCache::instance()->load(accid); - return S_OK; - }, 0); - return S_OK; -} - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatoggleprovider.h b/src/plugins/platforms/winrt/uiautomation/qwinrtuiatoggleprovider.h deleted file mode 100644 index 3d1740c0a1..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiatoggleprovider.h +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTUIATOGGLEPROVIDER_H -#define QWINRTUIATOGGLEPROVIDER_H - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include "qwinrtuiabaseprovider.h" - -#include <wrl.h> -#include <windows.ui.xaml.h> - -QT_BEGIN_NAMESPACE - -// Implements the Toggle control pattern provider. Used for checkboxes. -class QWinRTUiaToggleProvider : - public QWinRTUiaBaseProvider, - public Microsoft::WRL::RuntimeClass<ABI::Windows::UI::Xaml::Automation::Provider::IToggleProvider> -{ - Q_OBJECT - Q_DISABLE_COPY(QWinRTUiaToggleProvider) - InspectableClass(L"QWinRTUiaToggleProvider", BaseTrust); - -public: - explicit QWinRTUiaToggleProvider(QAccessible::Id id); - virtual ~QWinRTUiaToggleProvider(); - - // IToggleProvider - HRESULT STDMETHODCALLTYPE get_ToggleState(ABI::Windows::UI::Xaml::Automation::ToggleState *value) override; - HRESULT STDMETHODCALLTYPE Toggle() override; -}; - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) - -#endif // QWINRTUIATOGGLEPROVIDER_H diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiautils.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiautils.cpp deleted file mode 100644 index 16197c99b9..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiautils.cpp +++ /dev/null @@ -1,182 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include "qwinrtuiautils.h" - -using namespace ABI::Windows::UI::Xaml::Automation::Peers; -using namespace ABI::Windows::UI::Xaml::Automation::Text; -using namespace ABI::Windows::Foundation::Collections; - -QT_BEGIN_NAMESPACE - -Q_LOGGING_CATEGORY(lcQpaUiAutomation, "qt.qpa.uiautomation") - -namespace QWinRTUiAutomation { - -// Returns the window containing the element (usually the top window), -QWindow *windowForAccessible(const QAccessibleInterface *accessible) -{ - QWindow *window = accessible->window(); - if (!window) { - QAccessibleInterface *acc = accessible->parent(); - while (acc && acc->isValid() && !window) { - window = acc->window(); - QAccessibleInterface *par = acc->parent(); - acc = par; - } - } - return window; -} - -QAccessibleInterface *accessibleForId(QAccessible::Id id) -{ - QAccessibleInterface *accessible = QAccessible::accessibleInterface(id); - if (!accessible || !accessible->isValid()) - return nullptr; - return accessible; -} - -QAccessible::Id idForAccessible(QAccessibleInterface *accessible) -{ - if (!accessible) - return QAccessible::Id(0); - return QAccessible::uniqueId(accessible); -} - -// Maps an accessibility role ID to an UI Automation control type ID. -AutomationControlType roleToControlType(QAccessible::Role role) -{ - static const QHash<QAccessible::Role, AutomationControlType> mapping { - {QAccessible::TitleBar, AutomationControlType::AutomationControlType_TitleBar}, - {QAccessible::MenuBar, AutomationControlType::AutomationControlType_MenuBar}, - {QAccessible::ScrollBar, AutomationControlType::AutomationControlType_ScrollBar}, - {QAccessible::Grip, AutomationControlType::AutomationControlType_Thumb}, - {QAccessible::Sound, AutomationControlType::AutomationControlType_Custom}, - {QAccessible::Cursor, AutomationControlType::AutomationControlType_Custom}, - {QAccessible::Caret, AutomationControlType::AutomationControlType_Custom}, - {QAccessible::AlertMessage, AutomationControlType::AutomationControlType_Custom}, - {QAccessible::Window, AutomationControlType::AutomationControlType_Window}, - {QAccessible::Client, AutomationControlType::AutomationControlType_Custom}, - {QAccessible::PopupMenu, AutomationControlType::AutomationControlType_Menu}, - {QAccessible::MenuItem, AutomationControlType::AutomationControlType_MenuItem}, - {QAccessible::ToolTip, AutomationControlType::AutomationControlType_ToolTip}, - {QAccessible::Application, AutomationControlType::AutomationControlType_Custom}, - {QAccessible::Document, AutomationControlType::AutomationControlType_Document}, - {QAccessible::Pane, AutomationControlType::AutomationControlType_Pane}, - {QAccessible::Chart, AutomationControlType::AutomationControlType_Custom}, - {QAccessible::Dialog, AutomationControlType::AutomationControlType_Window}, - {QAccessible::Border, AutomationControlType::AutomationControlType_Custom}, - {QAccessible::Grouping, AutomationControlType::AutomationControlType_Group}, - {QAccessible::Separator, AutomationControlType::AutomationControlType_Separator}, - {QAccessible::ToolBar, AutomationControlType::AutomationControlType_ToolBar}, - {QAccessible::StatusBar, AutomationControlType::AutomationControlType_StatusBar}, - {QAccessible::Table, AutomationControlType::AutomationControlType_Table}, - {QAccessible::ColumnHeader, AutomationControlType::AutomationControlType_Header}, - {QAccessible::RowHeader, AutomationControlType::AutomationControlType_Header}, - {QAccessible::Column, AutomationControlType::AutomationControlType_HeaderItem}, - {QAccessible::Row, AutomationControlType::AutomationControlType_HeaderItem}, - {QAccessible::Cell, AutomationControlType::AutomationControlType_DataItem}, - {QAccessible::Link, AutomationControlType::AutomationControlType_Hyperlink}, - {QAccessible::HelpBalloon, AutomationControlType::AutomationControlType_ToolTip}, - {QAccessible::Assistant, AutomationControlType::AutomationControlType_Custom}, - {QAccessible::List, AutomationControlType::AutomationControlType_List}, - {QAccessible::ListItem, AutomationControlType::AutomationControlType_ListItem}, - {QAccessible::Tree, AutomationControlType::AutomationControlType_Tree}, - {QAccessible::TreeItem, AutomationControlType::AutomationControlType_TreeItem}, - {QAccessible::PageTab, AutomationControlType::AutomationControlType_TabItem}, - {QAccessible::PropertyPage, AutomationControlType::AutomationControlType_Custom}, - {QAccessible::Indicator, AutomationControlType::AutomationControlType_Custom}, - {QAccessible::Graphic, AutomationControlType::AutomationControlType_Image}, - {QAccessible::StaticText, AutomationControlType::AutomationControlType_Text}, - {QAccessible::EditableText, AutomationControlType::AutomationControlType_Edit}, - {QAccessible::Button, AutomationControlType::AutomationControlType_Button}, - {QAccessible::CheckBox, AutomationControlType::AutomationControlType_CheckBox}, - {QAccessible::RadioButton, AutomationControlType::AutomationControlType_RadioButton}, - {QAccessible::ComboBox, AutomationControlType::AutomationControlType_ComboBox}, - {QAccessible::ProgressBar, AutomationControlType::AutomationControlType_ProgressBar}, - {QAccessible::Dial, AutomationControlType::AutomationControlType_Custom}, - {QAccessible::HotkeyField, AutomationControlType::AutomationControlType_Custom}, - {QAccessible::Slider, AutomationControlType::AutomationControlType_Slider}, - {QAccessible::SpinBox, AutomationControlType::AutomationControlType_Spinner}, - {QAccessible::Canvas, AutomationControlType::AutomationControlType_Custom}, - {QAccessible::Animation, AutomationControlType::AutomationControlType_Custom}, - {QAccessible::Equation, AutomationControlType::AutomationControlType_Custom}, - {QAccessible::ButtonDropDown, AutomationControlType::AutomationControlType_Button}, - {QAccessible::ButtonMenu, AutomationControlType::AutomationControlType_Button}, - {QAccessible::ButtonDropGrid, AutomationControlType::AutomationControlType_Button}, - {QAccessible::Whitespace, AutomationControlType::AutomationControlType_Custom}, - {QAccessible::PageTabList, AutomationControlType::AutomationControlType_Tab}, - {QAccessible::Clock, AutomationControlType::AutomationControlType_Custom}, - {QAccessible::Splitter, AutomationControlType::AutomationControlType_Custom}, - }; - - return mapping.value(role, AutomationControlType::AutomationControlType_Custom); -} - -// True if a character can be a separator for a text unit. -bool isTextUnitSeparator(TextUnit unit, const QChar &ch) -{ - return (((unit == TextUnit_Word) || (unit == TextUnit_Format)) && ch.isSpace()) - || ((unit == TextUnit_Line) && (ch.toLatin1() == '\n')); -} - -HRESULT qHString(const QString &str, HSTRING *returnValue) -{ - if (!returnValue) - return E_INVALIDARG; - - const wchar_t *wstr = reinterpret_cast<const wchar_t *>(str.utf16()); - return ::WindowsCreateString(wstr, static_cast<UINT32>(::wcslen(wstr)), returnValue); -} - -QString hStrToQStr(const HSTRING &hStr) -{ - quint32 len; - const wchar_t *wstr = ::WindowsGetStringRawBuffer(hStr, &len); - return QString::fromWCharArray(wstr, len); -} - -} // namespace QWinRTUiAutomation - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiautils.h b/src/plugins/platforms/winrt/uiautomation/qwinrtuiautils.h deleted file mode 100644 index 9519cb4eb5..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiautils.h +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTUIAUTILS_H -#define QWINRTUIAUTILS_H - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include <QtCore/QString> -#include <QtCore/qt_windows.h> -#include <QtGui/QAccessible> -#include <QtGui/QAccessibleInterface> -#include <QtGui/QWindow> -#include <QtCore/QLoggingCategory> - -#include <wrl.h> -#include <windows.ui.xaml.h> -#include <functional> - -QT_BEGIN_NAMESPACE - -Q_DECLARE_LOGGING_CATEGORY(lcQpaUiAutomation) - -namespace QWinRTUiAutomation { - -QWindow *windowForAccessible(const QAccessibleInterface *accessible); - -QAccessibleInterface *accessibleForId(QAccessible::Id id); - -QAccessible::Id idForAccessible(QAccessibleInterface *accessible); - -ABI::Windows::UI::Xaml::Automation::Peers::AutomationControlType roleToControlType(QAccessible::Role role); - -bool isTextUnitSeparator(ABI::Windows::UI::Xaml::Automation::Text::TextUnit unit, const QChar &ch); - -HRESULT qHString(const QString &str, HSTRING *returnValue); - -QString hStrToQStr(const HSTRING &hStr); - -} // namespace QWinRTUiAutomation - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) - -#endif // QWINRTUIAUTILS_H diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiavalueprovider.cpp b/src/plugins/platforms/winrt/uiautomation/qwinrtuiavalueprovider.cpp deleted file mode 100644 index 255d8ee49e..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiavalueprovider.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include "qwinrtuiavalueprovider.h" -#include "qwinrtuiametadatacache.h" -#include "qwinrtuiautils.h" - -#include <QtGui/QAccessible> -#include <QtGui/QAccessibleInterface> -#include <QtCore/QLoggingCategory> -#include <QtCore/QString> -#include <QtCore/private/qeventdispatcher_winrt_p.h> - -QT_BEGIN_NAMESPACE - -using namespace QWinRTUiAutomation; -using namespace ABI::Windows::UI::Xaml::Automation; -using namespace ABI::Windows::UI::Xaml::Automation::Provider; - -QWinRTUiaValueProvider::QWinRTUiaValueProvider(QAccessible::Id id) : - QWinRTUiaBaseProvider(id) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; -} - -QWinRTUiaValueProvider::~QWinRTUiaValueProvider() -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; -} - -// True for read-only controls. -HRESULT STDMETHODCALLTYPE QWinRTUiaValueProvider::get_IsReadOnly(boolean *value) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!value) - return E_INVALIDARG; - QSharedPointer<QWinRTUiaControlMetadata> metadata = QWinRTUiaMetadataCache::instance()->metadataForId(id()); - *value = (metadata->state().readOnly != 0); - return S_OK; -} - -// Returns the value in text form. -HRESULT STDMETHODCALLTYPE QWinRTUiaValueProvider::get_Value(HSTRING *value) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - if (!value) - return E_INVALIDARG; - QSharedPointer<QWinRTUiaControlMetadata> metadata = QWinRTUiaMetadataCache::instance()->metadataForId(id()); - return qHString(metadata->value(), value); -} - -// Sets the value associated with the control. -HRESULT STDMETHODCALLTYPE QWinRTUiaValueProvider::SetValue(HSTRING value) -{ - qCDebug(lcQpaUiAutomation) << __FUNCTION__; - - auto accid = id(); - - QString tmpValue = hStrToQStr(value); - - QEventDispatcherWinRT::runOnMainThread([accid, tmpValue]() { - - if (QAccessibleInterface *accessible = accessibleForId(accid)) { - - // First sets the value as a text. - accessible->setText(QAccessible::Value, tmpValue); - - // Then, if the control supports the value interface (range value) - // and the supplied text can be converted to a number, and that number - // lies within the min/max limits, sets it as the control's current (numeric) value. - if (QAccessibleValueInterface *valueInterface = accessible->valueInterface()) { - bool ok = false; - double numval = tmpValue.toDouble(&ok); - if (ok) { - double minimum = valueInterface->minimumValue().toDouble(); - double maximum = valueInterface->maximumValue().toDouble(); - if ((numval >= minimum) && (numval <= maximum)) { - valueInterface->setCurrentValue(QVariant(numval)); - } - } - } - } - QWinRTUiaMetadataCache::instance()->load(accid); - return S_OK; - }, 0); - - return S_OK; -} - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) diff --git a/src/plugins/platforms/winrt/uiautomation/qwinrtuiavalueprovider.h b/src/plugins/platforms/winrt/uiautomation/qwinrtuiavalueprovider.h deleted file mode 100644 index d9cd5d200d..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/qwinrtuiavalueprovider.h +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTUIAVALUEPROVIDER_H -#define QWINRTUIAVALUEPROVIDER_H - -#include <QtGui/qtguiglobal.h> -#if QT_CONFIG(accessibility) - -#include "qwinrtuiabaseprovider.h" - -#include <wrl.h> -#include <windows.ui.xaml.h> - -QT_BEGIN_NAMESPACE - -// Implements the Value control pattern provider. -// Supported for all controls that can return text(QAccessible::Value). -class QWinRTUiaValueProvider : - public QWinRTUiaBaseProvider, - public Microsoft::WRL::RuntimeClass<ABI::Windows::UI::Xaml::Automation::Provider::IValueProvider> -{ - Q_OBJECT - Q_DISABLE_COPY(QWinRTUiaValueProvider) - InspectableClass(L"QWinRTUiaValueProvider", BaseTrust); - -public: - explicit QWinRTUiaValueProvider(QAccessible::Id id); - virtual ~QWinRTUiaValueProvider(); - - // IValueProvider - HRESULT STDMETHODCALLTYPE get_IsReadOnly(boolean *value) override; - HRESULT STDMETHODCALLTYPE get_Value(HSTRING *value) override; - HRESULT STDMETHODCALLTYPE SetValue(HSTRING value) override; -}; - -QT_END_NAMESPACE - -#endif // QT_CONFIG(accessibility) - -#endif // QWINRTUIAVALUEPROVIDER_H diff --git a/src/plugins/platforms/winrt/uiautomation/uiautomation.pri b/src/plugins/platforms/winrt/uiautomation/uiautomation.pri deleted file mode 100644 index ca0dfae53f..0000000000 --- a/src/plugins/platforms/winrt/uiautomation/uiautomation.pri +++ /dev/null @@ -1,45 +0,0 @@ - -SOURCES += \ - $$PWD/qwinrtuiaaccessibility.cpp \ - $$PWD/qwinrtuiabaseprovider.cpp \ - $$PWD/qwinrtuiacontrolmetadata.cpp \ - $$PWD/qwinrtuiagriditemprovider.cpp \ - $$PWD/qwinrtuiagridprovider.cpp \ - $$PWD/qwinrtuiainvokeprovider.cpp \ - $$PWD/qwinrtuiamainprovider.cpp \ - $$PWD/qwinrtuiametadatacache.cpp \ - $$PWD/qwinrtuiapeervector.cpp \ - $$PWD/qwinrtuiaprovidercache.cpp \ - $$PWD/qwinrtuiarangevalueprovider.cpp \ - $$PWD/qwinrtuiaselectionitemprovider.cpp \ - $$PWD/qwinrtuiaselectionprovider.cpp \ - $$PWD/qwinrtuiatableitemprovider.cpp \ - $$PWD/qwinrtuiatableprovider.cpp \ - $$PWD/qwinrtuiatextprovider.cpp \ - $$PWD/qwinrtuiatextrangeprovider.cpp \ - $$PWD/qwinrtuiatoggleprovider.cpp \ - $$PWD/qwinrtuiautils.cpp \ - $$PWD/qwinrtuiavalueprovider.cpp - -HEADERS += \ - $$PWD/qwinrtuiaaccessibility.h \ - $$PWD/qwinrtuiabaseprovider.h \ - $$PWD/qwinrtuiacontrolmetadata.h \ - $$PWD/qwinrtuiaemptypropertyvalue.h \ - $$PWD/qwinrtuiagriditemprovider.h \ - $$PWD/qwinrtuiagridprovider.h \ - $$PWD/qwinrtuiainvokeprovider.h \ - $$PWD/qwinrtuiamainprovider.h \ - $$PWD/qwinrtuiametadatacache.h \ - $$PWD/qwinrtuiapeervector.h \ - $$PWD/qwinrtuiaprovidercache.h \ - $$PWD/qwinrtuiarangevalueprovider.h \ - $$PWD/qwinrtuiaselectionitemprovider.h \ - $$PWD/qwinrtuiaselectionprovider.h \ - $$PWD/qwinrtuiatableitemprovider.h \ - $$PWD/qwinrtuiatableprovider.h \ - $$PWD/qwinrtuiatextprovider.h \ - $$PWD/qwinrtuiatextrangeprovider.h \ - $$PWD/qwinrtuiatoggleprovider.h \ - $$PWD/qwinrtuiautils.h \ - $$PWD/qwinrtuiavalueprovider.h diff --git a/src/plugins/platforms/winrt/winrt.json b/src/plugins/platforms/winrt/winrt.json deleted file mode 100644 index 962747b697..0000000000 --- a/src/plugins/platforms/winrt/winrt.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "Keys": [ "winrt" ] -} diff --git a/src/plugins/platforms/winrt/winrt.pro b/src/plugins/platforms/winrt/winrt.pro deleted file mode 100644 index 3d9f9a36d1..0000000000 --- a/src/plugins/platforms/winrt/winrt.pro +++ /dev/null @@ -1,68 +0,0 @@ -TARGET = qwinrt - -CONFIG -= precompile_header - -QT += \ - core-private gui-private \ - fontdatabase_support-private egl_support-private - -qtConfig(opengl): QT += opengl-private - -DEFINES *= QT_NO_CAST_FROM_ASCII __WRL_NO_DEFAULT_LIB__ - -QMAKE_USE_PRIVATE += d3d11 ws2_32 - -SOURCES = \ - main.cpp \ - qwinrtbackingstore.cpp \ - qwinrtcanvas.cpp \ - qwinrtclipboard.cpp \ - qwinrtcursor.cpp \ - qwinrteglcontext.cpp \ - qwinrteventdispatcher.cpp \ - qwinrtfiledialoghelper.cpp \ - qwinrtfileengine.cpp \ - qwinrtinputcontext.cpp \ - qwinrtintegration.cpp \ - qwinrtmessagedialoghelper.cpp \ - qwinrtscreen.cpp \ - qwinrtservices.cpp \ - qwinrttheme.cpp \ - qwinrtwindow.cpp - - -HEADERS = \ - qwinrtbackingstore.h \ - qwinrtcanvas.h \ - qwinrtclipboard.h \ - qwinrtcursor.h \ - qwinrteglcontext.h \ - qwinrteventdispatcher.h \ - qwinrtfiledialoghelper.h \ - qwinrtfileengine.h \ - qwinrtinputcontext.h \ - qwinrtintegration.h \ - qwinrtmessagedialoghelper.h \ - qwinrtscreen.h \ - qwinrtservices.h \ - qwinrttheme.h \ - qwinrtwindow.h - -OTHER_FILES += winrt.json - -WINRT_SDK_VERSION_STRING = $$(UCRTVersion) -WINRT_SDK_VERSION = $$member($$list($$split(WINRT_SDK_VERSION_STRING, .)), 2) -lessThan(WINRT_SDK_VERSION, 14322): DEFINES += QT_WINRT_LIMITED_DRAGANDDROP -greaterThan(WINRT_SDK_VERSION, 14393): DEFINES += QT_WINRT_DISABLE_PHONE_COLORS - -qtConfig(draganddrop) { - SOURCES += qwinrtdrag.cpp - HEADERS += qwinrtdrag.h -} - -qtConfig(accessibility): include($$PWD/uiautomation/uiautomation.pri) - -PLUGIN_TYPE = platforms -PLUGIN_CLASS_NAME = QWinRTIntegrationPlugin -!equals(TARGET, $$QT_DEFAULT_QPA_PLUGIN): PLUGIN_EXTENDS = - -load(qt_plugin) diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro index df738c419f..880bd1c631 100644 --- a/src/plugins/plugins.pro +++ b/src/plugins/plugins.pro @@ -9,5 +9,5 @@ qtHaveModule(gui) { } qtHaveModule(widgets): SUBDIRS += styles -!winrt:qtHaveModule(printsupport): \ +qtHaveModule(printsupport): \ SUBDIRS += printsupport diff --git a/src/plugins/sqldrivers/sqlite/.prev_CMakeLists.txt b/src/plugins/sqldrivers/sqlite/.prev_CMakeLists.txt index 6413515efe..25796d9bb5 100644 --- a/src/plugins/sqldrivers/sqlite/.prev_CMakeLists.txt +++ b/src/plugins/sqldrivers/sqlite/.prev_CMakeLists.txt @@ -61,20 +61,12 @@ qt_extend_target(QSQLiteDriverPlugin CONDITION QT_FEATURE_posix_fallocate AND NO HAVE_POSIX_FALLOCATE=1 ) -qt_extend_target(QSQLiteDriverPlugin CONDITION WINRT AND NOT QT_FEATURE_system_sqlite - DEFINES - SQLITE_OS_WINRT -) - -#### Keys ignored in scope 8:.:../../../3rdparty:../../../3rdparty/sqlite.pri:WINRT: -# QMAKE_CFLAGS = "-Gy" - qt_extend_target(QSQLiteDriverPlugin CONDITION QNX AND NOT QT_FEATURE_system_sqlite DEFINES _QNX_SOURCE ) -qt_extend_target(QSQLiteDriverPlugin CONDITION UNIX AND NOT QT_FEATURE_system_sqlite AND NOT WINRT AND NOT winphone +qt_extend_target(QSQLiteDriverPlugin CONDITION UNIX AND NOT QT_FEATURE_system_sqlite DEFINES HAVE_USLEEP=1 ) @@ -89,5 +81,5 @@ qt_extend_target(QSQLiteDriverPlugin CONDITION NOT QT_FEATURE_dlopen AND NOT QT_ SQLITE_OMIT_LOAD_EXTENSION ) -#### Keys ignored in scope 13:.:../../../3rdparty:../../../3rdparty/sqlite.pri:INTEGRITY: +#### Keys ignored in scope 12:.:../../../3rdparty:../../../3rdparty/sqlite.pri:INTEGRITY: # QMAKE_CFLAGS = "-include" "qplatformdefs.h" diff --git a/src/plugins/sqldrivers/sqlite/CMakeLists.txt b/src/plugins/sqldrivers/sqlite/CMakeLists.txt index 8f1faeef9e..5cc2791e7d 100644 --- a/src/plugins/sqldrivers/sqlite/CMakeLists.txt +++ b/src/plugins/sqldrivers/sqlite/CMakeLists.txt @@ -71,20 +71,12 @@ qt_extend_target(QSQLiteDriverPlugin CONDITION QT_FEATURE_posix_fallocate AND NO HAVE_POSIX_FALLOCATE=1 ) -qt_extend_target(QSQLiteDriverPlugin CONDITION WINRT AND NOT QT_FEATURE_system_sqlite - DEFINES - SQLITE_OS_WINRT -) - -#### Keys ignored in scope 8:.:../../../3rdparty:../../../3rdparty/sqlite.pri:WINRT: -# QMAKE_CFLAGS = "-Gy" - qt_extend_target(QSQLiteDriverPlugin CONDITION QNX AND NOT QT_FEATURE_system_sqlite DEFINES _QNX_SOURCE ) -qt_extend_target(QSQLiteDriverPlugin CONDITION UNIX AND NOT QT_FEATURE_system_sqlite AND NOT WINRT AND NOT winphone +qt_extend_target(QSQLiteDriverPlugin CONDITION UNIX AND NOT QT_FEATURE_system_sqlite DEFINES HAVE_USLEEP=1 ) @@ -99,5 +91,5 @@ qt_extend_target(QSQLiteDriverPlugin CONDITION NOT QT_FEATURE_dlopen AND NOT QT_ SQLITE_OMIT_LOAD_EXTENSION ) -#### Keys ignored in scope 13:.:../../../3rdparty:../../../3rdparty/sqlite.pri:INTEGRITY: +#### Keys ignored in scope 12:.:../../../3rdparty:../../../3rdparty/sqlite.pri:INTEGRITY: # QMAKE_CFLAGS = "-include" "qplatformdefs.h" |