diff options
author | Jan-Marek Glogowski <glogow@fbihome.de> | 2022-05-24 18:14:16 +0200 |
---|---|---|
committer | Jan-Marek Glogowski <glogow@fbihome.de> | 2022-05-25 08:45:08 +0200 |
commit | 27fb97fbfe3da858cefb830614c90a496dfe3ad6 (patch) | |
tree | fece4cbea044e5b74f9355d27bc7a5db7fd06d1f | |
parent | 7bf9629d4f3e8504b5d09685d7721275b3287443 (diff) |
VCL SysEnvData: add Invalid Platform and Toolkit
I accidently almost introduced some subtle sytactic error in Qt,
because the default platform and toolkit values are actually valid.
So add an Invalid value to both enum classes and then sprinkle
some asserts, so these tests aren't working on invalid data.
Thanks Michael Weghorn for catching this in review.
Change-Id: Ic6a0764dfc5168181251023f4d1c66ffa32651d8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134882
Tested-by: Jenkins
Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
-rw-r--r-- | include/vcl/sysdata.hxx | 8 | ||||
-rw-r--r-- | vcl/qt5/QtFrame.cxx | 26 |
2 files changed, 24 insertions, 10 deletions
diff --git a/include/vcl/sysdata.hxx b/include/vcl/sysdata.hxx index 00cd5142c2e3..07ddea45dae3 100644 --- a/include/vcl/sysdata.hxx +++ b/include/vcl/sysdata.hxx @@ -50,7 +50,7 @@ typedef struct CGContext *CGContextRef; struct VCL_DLLPUBLIC SystemEnvData { - enum class Toolkit { Gen, Gtk, Qt }; + enum class Toolkit { Invalid, Gen, Gtk, Qt }; Toolkit toolkit; // the toolkit in use #if defined(_WIN32) HWND hWnd; // the window hwnd @@ -62,7 +62,7 @@ struct VCL_DLLPUBLIC SystemEnvData #elif defined( IOS ) // Nothing #elif defined( UNX ) - enum class Platform { Wayland, Xcb, WASM }; + enum class Platform { Invalid, Wayland, Xcb, WASM }; void* pDisplay; // the relevant display connection SalFrame* pSalFrame; // contains a salframe, if object has one @@ -89,7 +89,7 @@ public: #endif SystemEnvData() - : toolkit(Toolkit::Gen) + : toolkit(Toolkit::Invalid) #if defined(_WIN32) , hWnd(nullptr) #elif defined( MACOSX ) @@ -104,7 +104,7 @@ public: , pVisual(nullptr) , nScreen(0) , aShellWindow(0) - , platform(Platform()) + , platform(Platform::Invalid) , aWindow(0) #endif { diff --git a/vcl/qt5/QtFrame.cxx b/vcl/qt5/QtFrame.cxx index 6d65aaf6f386..0933bf33b029 100644 --- a/vcl/qt5/QtFrame.cxx +++ b/vcl/qt5/QtFrame.cxx @@ -183,6 +183,8 @@ QtFrame::QtFrame(QtFrame* pParent, SalFrameStyleFlags nStyle, bool bUseCairo) m_pQWidget->setAttribute(Qt::WA_AlwaysShowToolTips); } + FillSystemEnvData(m_aSystemData, reinterpret_cast<sal_IntPtr>(this), m_pQWidget); + QWindow* pChildWindow = windowHandle(); connect(pChildWindow, &QWindow::screenChanged, this, &QtFrame::screenChanged); @@ -193,8 +195,6 @@ QtFrame::QtFrame(QtFrame* pParent, SalFrameStyleFlags nStyle, bool bUseCairo) pChildWindow->setTransientParent(pParentWindow); } - FillSystemEnvData(m_aSystemData, reinterpret_cast<sal_IntPtr>(this), m_pQWidget); - SetIcon(SV_ICON_ID_OFFICE); fixICCCMwindowGroup(); @@ -204,6 +204,8 @@ void QtFrame::screenChanged(QScreen*) { m_pQWidget->fakeResize(); } void QtFrame::FillSystemEnvData(SystemEnvData& rData, sal_IntPtr pWindow, QWidget* pWidget) { + assert(rData.platform == SystemEnvData::Platform::Invalid); + assert(rData.toolkit == SystemEnvData::Toolkit::Invalid); if (QGuiApplication::platformName() == "wayland") rData.platform = SystemEnvData::Platform::Wayland; else if (QGuiApplication::platformName() == "xcb") @@ -233,6 +235,7 @@ void QtFrame::fixICCCMwindowGroup() return; g_bNeedsWmHintsWindowGroup = false; + assert(m_aSystemData.platform != SystemEnvData::Platform::Invalid); if (m_aSystemData.platform != SystemEnvData::Platform::Xcb) return; if (QVersionNumber::fromString(qVersion()) >= QVersionNumber(5, 12)) @@ -370,10 +373,19 @@ QWindow* QtFrame::windowHandle() const // set attribute 'Qt::WA_NativeWindow' first to make sure a window handle actually exists QWidget* pChild = asChild(); assert(pChild->window() == pChild); -#ifndef EMSCRIPTEN - // no idea, why this breaks the menubar for EMSCRIPTEN - pChild->setAttribute(Qt::WA_NativeWindow); -#endif + switch (m_aSystemData.platform) + { + case SystemEnvData::Platform::Wayland: + case SystemEnvData::Platform::Xcb: + pChild->setAttribute(Qt::WA_NativeWindow); + break; + case SystemEnvData::Platform::WASM: + // no idea, why Qt::WA_NativeWindow breaks the menubar for EMSCRIPTEN + break; + case SystemEnvData::Platform::Invalid: + std::abort(); + break; + } return pChild->windowHandle(); } @@ -1357,6 +1369,7 @@ void QtFrame::SetScreenNumber(unsigned int nScreen) void QtFrame::SetApplicationID(const OUString& rWMClass) { #if CHECK_QT5_USING_X11 + assert(m_aSystemData.platform != SystemEnvData::Platform::Invalid); if (m_aSystemData.platform != SystemEnvData::Platform::Xcb || !m_pTopLevel) return; @@ -1383,6 +1396,7 @@ void QtFrame::ResolveWindowHandle(SystemEnvData& rData) const { if (!rData.pWidget) return; + assert(rData.platform != SystemEnvData::Platform::Invalid); if (rData.platform != SystemEnvData::Platform::Wayland) rData.SetWindowHandle(static_cast<QWidget*>(rData.pWidget)->winId()); } |