Qt refactor SystemEnvData setup

Change-Id: I900d1079c9a832a9b5170e58ce4e7a8b81d7d01b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125393
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Tested-by: Jenkins
diff --git a/vcl/inc/qt5/QtFrame.hxx b/vcl/inc/qt5/QtFrame.hxx
index a338b10..965ecba 100644
--- a/vcl/inc/qt5/QtFrame.hxx
+++ b/vcl/inc/qt5/QtFrame.hxx
@@ -215,6 +215,7 @@ public:

    void setInputLanguage(LanguageType);
    inline bool isPopup() const;
    static void FillSystemEnvData(SystemEnvData&, sal_IntPtr pWindow, QWidget* pWidget);
};

inline bool QtFrame::CallCallback(SalEvent nEvent, const void* pEvent) const
diff --git a/vcl/qt5/QtFrame.cxx b/vcl/qt5/QtFrame.cxx
index db91e48a..ce504c1 100644
--- a/vcl/qt5/QtFrame.cxx
+++ b/vcl/qt5/QtFrame.cxx
@@ -183,39 +183,34 @@ QtFrame::QtFrame(QtFrame* pParent, SalFrameStyleFlags nStyle, bool bUseCairo)
            pChildWindow->setTransientParent(pParentWindow);
    }

    // Calling 'QWidget::winId()' implicitly enables native windows to be used
    // rather than "alien widgets" that are unknown to the windowing system,
    // s. https://doc.qt.io/qt-5/qwidget.html#native-widgets-vs-alien-widgets
    // Avoid this on Wayland due to problems with missing 'mouseMoveEvent's,
    // s. tdf#122293/QTBUG-75766
    const bool bWayland = QGuiApplication::platformName() == "wayland";
    if (!bWayland)
    FillSystemEnvData(m_aSystemData, reinterpret_cast<sal_IntPtr>(this), m_pQWidget);
    if (m_aSystemData.platform != SystemEnvData::Platform::Wayland)
        m_aSystemData.SetWindowHandle(m_pQWidget->winId());
    else
    {
        // TODO implement as needed for Wayland,
        // s.a. commit c0d4f3ad3307c which did this for gtk3
        // QPlatformNativeInterface* native = QGuiApplication::platformNativeInterface();
        // m_aSystemData.pDisplay = native->nativeResourceForWindow("display", nullptr);
        // m_aSystemData.aWindow = reinterpret_cast<unsigned long>(
        //     native->nativeResourceForWindow("surface", m_pQWidget->windowHandle()));
    }

    m_aSystemData.aShellWindow = reinterpret_cast<sal_IntPtr>(this);
    //m_aSystemData.pSalFrame = this;
    m_aSystemData.pWidget = m_pQWidget;
    //m_aSystemData.nScreen = m_nXScreen.getXScreen();
    m_aSystemData.toolkit = SystemEnvData::Toolkit::Qt;
    if (!bWayland)
        m_aSystemData.platform = SystemEnvData::Platform::Xcb;
    else
        m_aSystemData.platform = SystemEnvData::Platform::Wayland;

    SetIcon(SV_ICON_ID_OFFICE);

    fixICCCMwindowGroup();
}

void QtFrame::FillSystemEnvData(SystemEnvData& rData, sal_IntPtr pWindow, QWidget* pWidget)
{
    if (QGuiApplication::platformName() == "wayland")
        rData.platform = SystemEnvData::Platform::Wayland;
    else if (QGuiApplication::platformName() == "xcb")
        rData.platform = SystemEnvData::Platform::Xcb;
    else
    {
        // maybe add a SystemEnvData::Platform::Unsupported to avoid special cases and not abort?
        SAL_WARN("vcl.qt",
                 "Unsupported qt VCL platform: " << toOUString(QGuiApplication::platformName()));
        std::abort();
    }

    rData.toolkit = SystemEnvData::Toolkit::Qt;
    rData.aShellWindow = pWindow;
    rData.pWidget = pWidget;
}

void QtFrame::fixICCCMwindowGroup()
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) && QT5_USING_X11 && QT5_HAVE_XCB_ICCCM
@@ -226,7 +221,7 @@ void QtFrame::fixICCCMwindowGroup()
        return;
    g_bNeedsWmHintsWindowGroup = false;

    if (QGuiApplication::platformName() != "xcb")
    if (m_aSystemData.platform != SystemEnvData::Platform::Xcb)
        return;
    if (QVersionNumber::fromString(qVersion()) >= QVersionNumber(5, 12))
        return;
@@ -1327,7 +1322,7 @@ void QtFrame::SetScreenNumber(unsigned int nScreen)
void QtFrame::SetApplicationID(const OUString& rWMClass)
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) && QT5_USING_X11
    if (QGuiApplication::platformName() != "xcb" || !m_pTopLevel)
    if (m_aSystemData.platform != SystemEnvData::Platform::Xcb || !m_pTopLevel)
        return;

    OString aResClass = OUStringToOString(rWMClass, RTL_TEXTENCODING_ASCII_US);
diff --git a/vcl/qt5/QtObject.cxx b/vcl/qt5/QtObject.cxx
index 155a78d..b8c30af 100644
--- a/vcl/qt5/QtObject.cxx
+++ b/vcl/qt5/QtObject.cxx
@@ -41,28 +41,9 @@ QtObject::QtObject(QtFrame* pParent, bool bShow)
    if (bShow)
        m_pQWidget->show();

    m_aSystemData.aShellWindow = reinterpret_cast<sal_IntPtr>(this);
    //m_aSystemData.pSalFrame = this;
    m_aSystemData.pWidget = m_pQWidget;
    //m_aSystemData.nScreen = m_nXScreen.getXScreen();
    m_aSystemData.toolkit = SystemEnvData::Toolkit::Qt;
    m_aSystemData.platform = SystemEnvData::Platform::Xcb;
    const bool bWayland = QGuiApplication::platformName() == "wayland";
    if (!bWayland)
    {
        m_aSystemData.platform = SystemEnvData::Platform::Xcb;
        m_aSystemData.SetWindowHandle(m_pQWindow->winId()); // ID of the embedded window
    }
    else
    {
        m_aSystemData.platform = SystemEnvData::Platform::Wayland;
        // TODO implement as needed for Wayland,
        // s.a. commit c0d4f3ad3307c which did this for gtk3
        // QPlatformNativeInterface* native = QGuiApplication::platformNativeInterface();
        // m_aSystemData.pDisplay = native->nativeResourceForWindow("display", nullptr);
        // m_aSystemData.aWindow = reinterpret_cast<unsigned long>(
        //     native->nativeResourceForWindow("surface", m_pQWidget->windowHandle()));
    }
    QtFrame::FillSystemEnvData(m_aSystemData, reinterpret_cast<sal_IntPtr>(this), m_pQWidget);
    if (m_aSystemData.platform != SystemEnvData::Platform::Wayland)
        m_aSystemData.SetWindowHandle(m_pQWidget->winId());
}

QtObject::~QtObject()