From 4c9eb38390b35ee3ec0dc966e0b5036cac5ac76b Mon Sep 17 00:00:00 2001 From: Andrew Knight Date: Fri, 16 May 2014 10:22:47 +0300 Subject: Support Windows Phone 8.1 in WinRT QPA - Unsupported code paths for WP8.0 are avoided, and new APIs are used where appropriate (virtual keyboard) - DirectWrite fonts are loaded on WP8.1 - Platform dialogs are used on WP8.1 Change-Id: I721006ac943ad4e248f0f1590ce247a03e40fbc0 Reviewed-by: Oliver Wolff --- src/plugins/platforms/winrt/qwinrtfontdatabase.cpp | 10 ++-- src/plugins/platforms/winrt/qwinrtfontdatabase.h | 6 +-- src/plugins/platforms/winrt/qwinrtinputcontext.cpp | 53 +++++++++++++++++++++- .../platforms/winrt/qwinrtplatformtheme.cpp | 10 ++-- src/plugins/platforms/winrt/winrt.pro | 8 ++-- 5 files changed, 69 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/plugins/platforms/winrt/qwinrtfontdatabase.cpp b/src/plugins/platforms/winrt/qwinrtfontdatabase.cpp index 70bb9469db..7de223bbed 100644 --- a/src/plugins/platforms/winrt/qwinrtfontdatabase.cpp +++ b/src/plugins/platforms/winrt/qwinrtfontdatabase.cpp @@ -44,13 +44,13 @@ #include #include -#ifndef Q_OS_WINPHONE +#ifdef QT_WINRT_USE_DWRITE #include #include #include #include using namespace Microsoft::WRL; -#endif // !Q_OS_WINPHONE +#endif // QT_WINRT_USE_DWRITE QT_BEGIN_NAMESPACE @@ -62,7 +62,7 @@ QString QWinRTFontDatabase::fontDir() const const QString applicationDirPath = QCoreApplication::applicationDirPath(); fontDirectory = applicationDirPath + QLatin1String("/fonts"); if (!QFile::exists(fontDirectory)) { -#ifndef Q_OS_WINPHONE +#ifdef QT_WINRT_USE_DWRITE if (m_fontFamilies.isEmpty()) #endif qWarning("No fonts directory found in application package."); @@ -72,7 +72,7 @@ QString QWinRTFontDatabase::fontDir() const return fontDirectory; } -#ifndef Q_OS_WINPHONE +#ifdef QT_WINRT_USE_DWRITE QWinRTFontDatabase::~QWinRTFontDatabase() { @@ -398,6 +398,6 @@ void QWinRTFontDatabase::releaseHandle(void *handle) QBasicFontDatabase::releaseHandle(handle); } -#endif // !Q_OS_WINPHONE +#endif // QT_WINRT_USE_DWRITE QT_END_NAMESPACE diff --git a/src/plugins/platforms/winrt/qwinrtfontdatabase.h b/src/plugins/platforms/winrt/qwinrtfontdatabase.h index b318a95502..19bf6fa9cf 100644 --- a/src/plugins/platforms/winrt/qwinrtfontdatabase.h +++ b/src/plugins/platforms/winrt/qwinrtfontdatabase.h @@ -46,7 +46,7 @@ QT_BEGIN_NAMESPACE -#ifndef Q_OS_WINPHONE +#ifdef QT_WINRT_USE_DWRITE struct IDWriteFontFile; struct IDWriteFontFamily; @@ -61,7 +61,7 @@ class QWinRTFontDatabase : public QBasicFontDatabase { public: QString fontDir() const; -#ifndef Q_OS_WINPHONE +#ifdef QT_WINRT_USE_DWRITE ~QWinRTFontDatabase(); QFont defaultFont() const Q_DECL_OVERRIDE; void populateFontDatabase() Q_DECL_OVERRIDE; @@ -71,7 +71,7 @@ public: private: QHash m_fonts; QHash m_fontFamilies; -#endif // !Q_OS_WINPHONE +#endif // QT_WINRT_USE_DWRITE }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/winrt/qwinrtinputcontext.cpp b/src/plugins/platforms/winrt/qwinrtinputcontext.cpp index bc15f1e448..8e1728dc04 100644 --- a/src/plugins/platforms/winrt/qwinrtinputcontext.cpp +++ b/src/plugins/platforms/winrt/qwinrtinputcontext.cpp @@ -52,7 +52,7 @@ using namespace ABI::Windows::Foundation; using namespace ABI::Windows::UI::ViewManagement; using namespace ABI::Windows::UI::Core; -#ifdef Q_OS_WINPHONE +#if defined(Q_OS_WINPHONE) && _MSC_VER==1700 #include using namespace ABI::Windows::Phone::UI::Core; #endif @@ -148,22 +148,73 @@ void QWinRTInputContext::setKeyboardRect(const QRectF rect) #ifdef Q_OS_WINPHONE +#if _MSC_VER>1700 // Windows Phone 8.1+ +static HRESULT getInputPane(ComPtr *inputPane2) +{ + ComPtr 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 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; +} +#endif // _MSC_VER>1700 + void QWinRTInputContext::showInputPanel() { +#if _MSC_VER<=1700 // Windows Phone 8.0 ICoreWindowKeyboardInput *input; if (SUCCEEDED(m_window->QueryInterface(IID_PPV_ARGS(&input)))) { input->put_IsKeyboardInputEnabled(true); input->Release(); } +#else // _MSC_VER<=1700 + ComPtr inputPane; + HRESULT hr = getInputPane(&inputPane); + if (FAILED(hr)) + return; + + boolean success; + hr = inputPane->TryShow(&success); + if (FAILED(hr)) + qErrnoWarning(hr, "Failed to show input panel."); +#endif // _MSC_VER>1700 } void QWinRTInputContext::hideInputPanel() { +#if _MSC_VER<=1700 // Windows Phone 8.0 ICoreWindowKeyboardInput *input; if (SUCCEEDED(m_window->QueryInterface(IID_PPV_ARGS(&input)))) { input->put_IsKeyboardInputEnabled(false); input->Release(); } +#else // _MSC_VER<=1700 + ComPtr inputPane; + HRESULT hr = getInputPane(&inputPane); + if (FAILED(hr)) + return; + + boolean success; + hr = inputPane->TryHide(&success); + if (FAILED(hr)) + qErrnoWarning(hr, "Failed to hide input panel."); +#endif // _MSC_VER>1700 } #else // Q_OS_WINPHONE diff --git a/src/plugins/platforms/winrt/qwinrtplatformtheme.cpp b/src/plugins/platforms/winrt/qwinrtplatformtheme.cpp index 2c8d33da84..e8f853e4b1 100644 --- a/src/plugins/platforms/winrt/qwinrtplatformtheme.cpp +++ b/src/plugins/platforms/winrt/qwinrtplatformtheme.cpp @@ -50,25 +50,25 @@ QWinRTPlatformTheme::QWinRTPlatformTheme() bool QWinRTPlatformTheme::usePlatformNativeDialog(QPlatformTheme::DialogType type) const { -#ifndef Q_OS_WINPHONE +#if !(defined(Q_OS_WINPHONE) && _MSC_VER<=1700) if (type == QPlatformTheme::MessageDialog) return true; -#endif // Q_OS_WINPHONE +#endif // !(Q_OS_WINPHONE && _MSC_VER<=1700) return false; } QPlatformDialogHelper *QWinRTPlatformTheme::createPlatformDialogHelper(QPlatformTheme::DialogType type) const { -#ifndef Q_OS_WINPHONE +#if !(defined(Q_OS_WINPHONE) && _MSC_VER<=1700) switch (type) { case QPlatformTheme::MessageDialog: return new QWinRTPlatformMessageDialogHelper(); default: return QPlatformTheme::createPlatformDialogHelper(type); } -#else +#else // !(Q_OS_WINPHONE && _MSC_VER<=1700) return QPlatformTheme::createPlatformDialogHelper(type); -#endif // Q_OS_WINPHONE +#endif // Q_OS_WINPHONE && _MSC_VER<=1700 } QT_END_NAMESPACE diff --git a/src/plugins/platforms/winrt/winrt.pro b/src/plugins/platforms/winrt/winrt.pro index 0122bf9475..349cdf11c9 100644 --- a/src/plugins/platforms/winrt/winrt.pro +++ b/src/plugins/platforms/winrt/winrt.pro @@ -3,8 +3,7 @@ CONFIG -= precompile_header # For Windows Phone 8 we have to deploy fonts together with the application as DirectWrite # is not supported here. -# TODO: Add a condition/remove this block if Windows Phone 8.1 supports DirectWrite -winphone { +winphone:equals(WINSDK_VER, 8.0): { fonts.path = $$[QT_INSTALL_LIBS]/fonts fonts.files = $$QT_SOURCE_TREE/lib/fonts/DejaVu*.ttf INSTALLS += fonts @@ -21,9 +20,10 @@ DEFINES *= QT_NO_CAST_FROM_ASCII __WRL_NO_DEFAULT_LIB__ GL_GLEXT_PROTOTYPES LIBS += $$QMAKE_LIBS_CORE -!winphone { +!if(winphone:equals(WINSDK_VER, 8.0)) { LIBS += -ldwrite INCLUDEPATH += $$QT_SOURCE_TREE/src/3rdparty/freetype/include + DEFINES += QT_WINRT_USE_DWRITE } SOURCES = \ @@ -70,7 +70,7 @@ fxc_blitvs.variable_out = HEADERS fxc_blitvs.CONFIG += target_predeps QMAKE_EXTRA_COMPILERS += fxc_blitps fxc_blitvs -winphone { +winphone:equals(WINSDK_VER, 8.0): { SOURCES -= qwinrtplatformmessagedialoghelper.cpp HEADERS -= qwinrtplatformmessagedialoghelper.h } -- cgit v1.2.3