Skip to content

Commit

Permalink
winrt: Remove yet another Windows Phone leftover
Browse files Browse the repository at this point in the history
Hardware and camera button handling are phone specific APIs we no longer
support in Qt.

Change-Id: Ib11f894a426b8e4b71acf24876437ddab2cea548
Reviewed-by: Oliver Wolff <[email protected]>
Reviewed-by: Andre de la Rocha <[email protected]>
Reviewed-by: Oswald Buddenhagen <[email protected]>
  • Loading branch information
owolff authored and thomaslmiller committed Jan 2, 2019
1 parent 7ba16f4 commit f9d8762
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 156 deletions.
8 changes: 0 additions & 8 deletions qmake/generators/win32/msvc_nmake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,6 @@ NmakeMakefileGenerator::writeMakefile(QTextStream &t)
incDirs << crtInclude + QStringLiteral("/winrt");

if (winrtBuild) {
// Only use mobile-specific headers and link against store-specific libs for
// winrt builds.
incDirs << kitDir + QStringLiteral("Extension SDKs/WindowsMobile/")
+ crtVersion + QStringLiteral("/Include/WinRT");

libDirs << toolsInstallDir + QStringLiteral("lib/") + arch + QStringLiteral("/store");
} else {
// Desktop projects may require the atl headers and libs.
Expand Down Expand Up @@ -236,9 +231,6 @@ NmakeMakefileGenerator::writeMakefile(QTextStream &t)
incDirs << crtInclude + QStringLiteral("/shared");
incDirs << crtInclude + QStringLiteral("/winrt");

incDirs << kitDir + QStringLiteral("Extension SDKs/WindowsMobile/")
+ crtVersion + QStringLiteral("/Include/WinRT");

libDirs << vcInstallDir + QStringLiteral("lib/store/") + compilerArch;
libDirs << vcInstallDir + QStringLiteral("atlmfc/lib") + compilerArch;

Expand Down
132 changes: 0 additions & 132 deletions src/plugins/platforms/winrt/qwinrtintegration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,6 @@
#include <windows.ui.viewmanagement.h>
#include <windows.graphics.display.h>

#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP)
# include <windows.phone.ui.input.h>
# 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::Foundation;
Expand All @@ -92,27 +85,14 @@ using namespace ABI::Windows::UI::Core;
using namespace ABI::Windows::UI::ViewManagement;
using namespace ABI::Windows::Graphics::Display;
using namespace ABI::Windows::ApplicationModel::Core;
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP)
using namespace ABI::Windows::Phone::UI::Input;
#endif

typedef IEventHandler<IInspectable *> ResumeHandler;
typedef IEventHandler<SuspendingEventArgs *> SuspendHandler;
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP)
typedef IEventHandler<BackPressedEventArgs*> BackPressedHandler;
typedef IEventHandler<CameraEventArgs*> CameraButtonHandler;
#endif

QT_BEGIN_NAMESPACE

typedef HRESULT (__stdcall ICoreApplication::*CoreApplicationCallbackRemover)(EventRegistrationToken);
uint qHash(CoreApplicationCallbackRemover key) { void *ptr = *(void **)(&key); return qHash(ptr); }
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP)
typedef HRESULT (__stdcall IHardwareButtonsStatics::*HardwareButtonsCallbackRemover)(EventRegistrationToken);
uint qHash(HardwareButtonsCallbackRemover key) { void *ptr = *(void **)(&key); return qHash(ptr); }
typedef HRESULT (__stdcall IHardwareButtonsStatics2::*HardwareButtons2CallbackRemover)(EventRegistrationToken);
uint qHash(HardwareButtons2CallbackRemover key) { void *ptr = *(void **)(&key); return qHash(ptr); }
#endif

class QWinRTIntegrationPrivate
{
Expand All @@ -128,15 +108,6 @@ class QWinRTIntegrationPrivate

ComPtr<ICoreApplication> application;
QHash<CoreApplicationCallbackRemover, EventRegistrationToken> applicationTokens;
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP)
ComPtr<IHardwareButtonsStatics> hardwareButtons;
QHash<HardwareButtonsCallbackRemover, EventRegistrationToken> buttonsTokens;
ComPtr<IHardwareButtonsStatics2> cameraButtons;
QHash<HardwareButtons2CallbackRemover, EventRegistrationToken> cameraTokens;
boolean hasHardwareButtons;
bool cameraHalfPressed : 1;
bool cameraPressed : 1;
#endif
};

QWinRTIntegration::QWinRTIntegration() : d_ptr(new QWinRTIntegrationPrivate)
Expand All @@ -156,45 +127,6 @@ QWinRTIntegration::QWinRTIntegration() : d_ptr(new QWinRTIntegrationPrivate)
&d->applicationTokens[&ICoreApplication::remove_Resuming]);
Q_ASSERT_SUCCEEDED(hr);

#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP)
d->hasHardwareButtons = false;
ComPtr<IApiInformationStatics> apiInformationStatics;
hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Foundation_Metadata_ApiInformation).Get(),
IID_PPV_ARGS(&apiInformationStatics));

if (SUCCEEDED(hr)) {
const HStringReference valueRef(L"Windows.Phone.UI.Input.HardwareButtons");
hr = apiInformationStatics->IsTypePresent(valueRef.Get(), &d->hasHardwareButtons);
}

if (d->hasHardwareButtons) {
hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Phone_UI_Input_HardwareButtons).Get(),
IID_PPV_ARGS(&d->hardwareButtons));
Q_ASSERT_SUCCEEDED(hr);
hr = d->hardwareButtons->add_BackPressed(Callback<BackPressedHandler>(this, &QWinRTIntegration::onBackButtonPressed).Get(),
&d->buttonsTokens[&IHardwareButtonsStatics::remove_BackPressed]);
Q_ASSERT_SUCCEEDED(hr);

hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Phone_UI_Input_HardwareButtons).Get(),
IID_PPV_ARGS(&d->cameraButtons));
Q_ASSERT_SUCCEEDED(hr);
if (qEnvironmentVariableIntValue("QT_QPA_ENABLE_CAMERA_KEYS")) {
hr = d->cameraButtons->add_CameraPressed(Callback<CameraButtonHandler>(this, &QWinRTIntegration::onCameraPressed).Get(),
&d->cameraTokens[&IHardwareButtonsStatics2::remove_CameraPressed]);
Q_ASSERT_SUCCEEDED(hr);
hr = d->cameraButtons->add_CameraHalfPressed(Callback<CameraButtonHandler>(this, &QWinRTIntegration::onCameraHalfPressed).Get(),
&d->cameraTokens[&IHardwareButtonsStatics2::remove_CameraHalfPressed]);
Q_ASSERT_SUCCEEDED(hr);
hr = d->cameraButtons->add_CameraReleased(Callback<CameraButtonHandler>(this, &QWinRTIntegration::onCameraReleased).Get(),
&d->cameraTokens[&IHardwareButtonsStatics2::remove_CameraReleased]);
Q_ASSERT_SUCCEEDED(hr);
}
d->cameraPressed = false;
d->cameraHalfPressed = false;
}
#endif // WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP)


QEventDispatcherWinRT::runOnXamlThread([d]() {
d->mainScreen = new QWinRTScreen;
return S_OK;
Expand All @@ -214,18 +146,6 @@ QWinRTIntegration::~QWinRTIntegration()
Q_D(QWinRTIntegration);
HRESULT hr;

#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP)
if (d->hasHardwareButtons) {
for (QHash<HardwareButtonsCallbackRemover, EventRegistrationToken>::const_iterator i = d->buttonsTokens.begin(); i != d->buttonsTokens.end(); ++i) {
hr = (d->hardwareButtons.Get()->*i.key())(i.value());
Q_ASSERT_SUCCEEDED(hr);
}
for (QHash<HardwareButtons2CallbackRemover, EventRegistrationToken>::const_iterator i = d->cameraTokens.begin(); i != d->cameraTokens.end(); ++i) {
hr = (d->cameraButtons.Get()->*i.key())(i.value());
Q_ASSERT_SUCCEEDED(hr);
}
}
#endif
// 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
Expand Down Expand Up @@ -353,58 +273,6 @@ QPlatformTheme *QWinRTIntegration::createPlatformTheme(const QString &name) cons

// System-level integration points

#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP)
HRESULT QWinRTIntegration::onBackButtonPressed(IInspectable *, IBackPressedEventArgs *args)
{
Q_D(QWinRTIntegration);
QWindow *window = d->mainScreen->topWindow();
QWindowSystemInterface::setSynchronousWindowSystemEvents(true);
const bool pressed = QWindowSystemInterface::handleExtendedKeyEvent(window, QEvent::KeyPress, Qt::Key_Back, Qt::NoModifier,
0, 0, 0, QString(), false, 1, false);
const bool released = QWindowSystemInterface::handleExtendedKeyEvent(window, QEvent::KeyRelease, Qt::Key_Back, Qt::NoModifier,
0, 0, 0, QString(), false, 1, false);
QWindowSystemInterface::setSynchronousWindowSystemEvents(false);
args->put_Handled(pressed || released);
return S_OK;
}

HRESULT QWinRTIntegration::onCameraPressed(IInspectable *, ICameraEventArgs *)
{
Q_D(QWinRTIntegration);
QWindow *window = d->mainScreen->topWindow();
QWindowSystemInterface::handleExtendedKeyEvent(window, QEvent::KeyPress, Qt::Key_Camera, Qt::NoModifier,
0, 0, 0, QString(), false, 1, false);
d->cameraPressed = true;
return S_OK;
}

HRESULT QWinRTIntegration::onCameraHalfPressed(IInspectable *, ICameraEventArgs *)
{
Q_D(QWinRTIntegration);
QWindow *window = d->mainScreen->topWindow();
QWindowSystemInterface::handleExtendedKeyEvent(window, QEvent::KeyPress, Qt::Key_CameraFocus, Qt::NoModifier,
0, 0, 0, QString(), false, 1, false);
d->cameraHalfPressed = true;
return S_OK;
}

HRESULT QWinRTIntegration::onCameraReleased(IInspectable *, ICameraEventArgs *)
{
Q_D(QWinRTIntegration);
QWindow *window = d->mainScreen->topWindow();
if (d->cameraHalfPressed)
QWindowSystemInterface::handleExtendedKeyEvent(window, QEvent::KeyRelease, Qt::Key_CameraFocus, Qt::NoModifier,
0, 0, 0, QString(), false, 1, false);

if (d->cameraPressed)
QWindowSystemInterface::handleExtendedKeyEvent(window, QEvent::KeyRelease, Qt::Key_Camera, Qt::NoModifier,
0, 0, 0, QString(), false, 1, false);
d->cameraHalfPressed = false;
d->cameraPressed = false;
return S_OK;
}
#endif // WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP)

HRESULT QWinRTIntegration::onSuspended(IInspectable *, ISuspendingEventArgs *)
{
QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationSuspended);
Expand Down
16 changes: 0 additions & 16 deletions src/plugins/platforms/winrt/qwinrtintegration.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,6 @@ namespace ABI {
namespace Foundation {
struct IAsyncAction;
}
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP)
namespace Phone {
namespace UI {
namespace Input {
struct IBackPressedEventArgs;
struct ICameraEventArgs;
}
}
}
#endif
}
}
struct IAsyncInfo;
Expand Down Expand Up @@ -111,12 +101,6 @@ class QWinRTIntegration : public QPlatformIntegration

QPlatformOffscreenSurface *createPlatformOffscreenSurface(QOffscreenSurface *surface) const override;
private:
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP)
HRESULT onBackButtonPressed(IInspectable *, ABI::Windows::Phone::UI::Input::IBackPressedEventArgs *args);
HRESULT onCameraPressed(IInspectable *, ABI::Windows::Phone::UI::Input::ICameraEventArgs *);
HRESULT onCameraHalfPressed(IInspectable *, ABI::Windows::Phone::UI::Input::ICameraEventArgs *);
HRESULT onCameraReleased(IInspectable *, ABI::Windows::Phone::UI::Input::ICameraEventArgs *);
#endif
HRESULT onSuspended(IInspectable *, ABI::Windows::ApplicationModel::ISuspendingEventArgs *);
HRESULT onResume(IInspectable *, IInspectable *);

Expand Down

0 comments on commit f9d8762

Please sign in to comment.