diff options
author | Oliver Wolff <oliver.wolff@qt.io> | 2017-07-26 13:54:14 +0200 |
---|---|---|
committer | Oliver Wolff <oliver.wolff@qt.io> | 2017-07-27 06:51:45 +0000 |
commit | 0fcc7ea02a327219ae4b870079221cd962ae03f7 (patch) | |
tree | 16de3f67f8727c49996bb28d9cfebb667f1221a9 /src/plugins/platforms/winrt | |
parent | be93d2de031fb870a1ff244304311e07536a13b9 (diff) |
winrt: Fix platform theme for non-phone devices
When running on a desktop machine (using Windws SDK 10.0.14393) the
palette had fully transparent text colors which were assigned in the
"phone only" part of the theme's initialization. By checking the API
contract we can avoid that part of the initialization and thus return
proper values.
Change-Id: Id770a686c1c7e447a9594830fd7670352116eb21
Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
Diffstat (limited to 'src/plugins/platforms/winrt')
-rw-r--r-- | src/plugins/platforms/winrt/qwinrttheme.cpp | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/src/plugins/platforms/winrt/qwinrttheme.cpp b/src/plugins/platforms/winrt/qwinrttheme.cpp index 5696ae7a10..283825a880 100644 --- a/src/plugins/platforms/winrt/qwinrttheme.cpp +++ b/src/plugins/platforms/winrt/qwinrttheme.cpp @@ -61,6 +61,26 @@ 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; @@ -86,17 +106,16 @@ static inline QColor fromColor(const Color &color) static bool uiColorSettings(const wchar_t *value, UIElementType type, Color *color) { - static ComPtr<IApiInformationStatics> apiInformationStatics; - HRESULT hr; + ComPtr<IApiInformationStatics> apiInformationStatics = gApiHandler->apiInformationStatics(); if (!apiInformationStatics) { - hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Foundation_Metadata_ApiInformation).Get(), - IID_PPV_ARGS(&apiInformationStatics)); - RETURN_FALSE_IF_FAILED("Could not get 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); @@ -149,6 +168,14 @@ static void nativeColorSettings(QPalette &p) // 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)); |