tdf#144585 Qt5 restore old VCL popup handling

So while it works with X11, the Wayland situation seems much
worse. Eventually we want to use Qt::Popup as a window type,
because that implies special handling for Wayland, but the
additional private Qt mechanisms this implies conflict with VCL
handling, especially input + focus handling with ComboBox. I'll
re-check (again) how Qt itself implements this and maybe that
solution is adaptable to VCL.

This re-introduces the problem, that "DropDown/PopUp stays open
and in FG when changing app on Linux desktop (keyboard, ALT+TAB)",
original reported as part of tdf#143114, which is some kind of
kf5 catchall bug report.

Just revert for 7-2. Hope we find a better solution on master,
which can be backported later.

This revert includes:

- "tdf#144037 Qt5 just close popup with mouse outside"
  commit 7c1f4284562e905372b5c14b6017f1eb438f54b5
- "tdf#143580 Qt5 don't use Qt::Popup for FLOAT wins"
  commit ea2f19827db330a21c7962bdd13b1b838821bd4c
- "Qt5 fix Qt::Popup window handling"
  commit 7e6fee830116823b9cd8e46d6962df4ea2bc1ea6

Change-Id: Ibf56187e00232f6c75cdbbc82ce915f80214a136
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122356
Tested-by: Michael Weghorn <m.weghorn@posteo.de>
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
diff --git a/vcl/inc/qt5/Qt5Frame.hxx b/vcl/inc/qt5/Qt5Frame.hxx
index 01b93ad..ed82c2a 100644
--- a/vcl/inc/qt5/Qt5Frame.hxx
+++ b/vcl/inc/qt5/Qt5Frame.hxx
@@ -210,7 +210,6 @@
    inline bool CallCallback(SalEvent nEvent, const void* pEvent) const;

    void setInputLanguage(LanguageType);
    inline bool isPopup() const;
};

inline bool Qt5Frame::CallCallback(SalEvent nEvent, const void* pEvent) const
@@ -219,10 +218,4 @@
    return SalFrame::CallCallback(nEvent, pEvent);
}

inline bool Qt5Frame::isPopup() const
{
    return ((m_nStyle & SalFrameStyleFlags::FLOAT)
            && !(m_nStyle & SalFrameStyleFlags::OWNERDRAWDECORATION));
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/qt5/Qt5Widget.hxx b/vcl/inc/qt5/Qt5Widget.hxx
index 60db1a3..7bf7ead 100644
--- a/vcl/inc/qt5/Qt5Widget.hxx
+++ b/vcl/inc/qt5/Qt5Widget.hxx
@@ -75,7 +75,6 @@

    void inputMethodEvent(QInputMethodEvent*) override;
    QVariant inputMethodQuery(Qt::InputMethodQuery) const override;
    static void closePopup();

public:
    Qt5Widget(Qt5Frame& rFrame, Qt::WindowFlags f = Qt::WindowFlags());
diff --git a/vcl/qt5/Qt5Frame.cxx b/vcl/qt5/Qt5Frame.cxx
index a4c78d1..322f293 100644
--- a/vcl/qt5/Qt5Frame.cxx
+++ b/vcl/qt5/Qt5Frame.cxx
@@ -144,13 +144,11 @@
        else if ((nStyle & SalFrameStyleFlags::FLOAT)
                 && (nStyle & SalFrameStyleFlags::OWNERDRAWDECORATION))
            aWinFlags |= Qt::Tool | Qt::FramelessWindowHint;
        else if (nStyle & SalFrameStyleFlags::TOOLTIP)
        else if (nStyle & (SalFrameStyleFlags::FLOAT | SalFrameStyleFlags::TOOLTIP))
            aWinFlags |= Qt::ToolTip;
        // Can't use Qt::Popup, because it grabs the input focus and generates
        // a focus-out event, reaking the compbo box. This used to map to
        // Qt::ToolTip, which doesn't feel that correct...
        else if (isPopup())
            aWinFlags = Qt::Widget | Qt::FramelessWindowHint | Qt::BypassWindowManagerHint;
        else if ((nStyle & SalFrameStyleFlags::FLOAT)
                 && !(nStyle & SalFrameStyleFlags::OWNERDRAWDECORATION))
            aWinFlags |= Qt::Popup;
        else if (nStyle & SalFrameStyleFlags::TOOLWINDOW)
            aWinFlags |= Qt::Tool;
        // top level windows can't be transient in Qt, so make them dialogs, if they have a parent. At least
@@ -428,7 +426,7 @@
    pSalInst->RunInMainThread([this, bVisible, bNoActivate]() {
        asChild()->setVisible(bVisible);
        asChild()->raise();
        if (!bNoActivate && !isPopup())
        if (!bNoActivate)
        {
            asChild()->activateWindow();
            asChild()->setFocus();
diff --git a/vcl/qt5/Qt5Widget.cxx b/vcl/qt5/Qt5Widget.cxx
index ca23138..6cb548c 100644
--- a/vcl/qt5/Qt5Widget.cxx
+++ b/vcl/qt5/Qt5Widget.cxx
@@ -46,7 +46,6 @@
#include <cairo.h>
#include <vcl/commandevent.hxx>
#include <vcl/event.hxx>
#include <vcl/toolkit/floatwin.hxx>
#include <window.h>
#include <tools/diagnose_ex.h>

@@ -178,13 +177,7 @@
    rFrame.CallCallback(nEventType, &aEvent);
}

void Qt5Widget::mousePressEvent(QMouseEvent* pEvent)
{
    handleMousePressEvent(m_rFrame, pEvent);
    if (m_rFrame.isPopup()
        && !geometry().translated(geometry().topLeft() * -1).contains(pEvent->pos()))
        closePopup();
}
void Qt5Widget::mousePressEvent(QMouseEvent* pEvent) { handleMousePressEvent(m_rFrame, pEvent); }

void Qt5Widget::mouseReleaseEvent(QMouseEvent* pEvent)
{
@@ -598,22 +591,11 @@

void Qt5Widget::focusInEvent(QFocusEvent*) { m_rFrame.CallCallback(SalEvent::GetFocus, nullptr); }

void Qt5Widget::closePopup()
{
    VclPtr<FloatingWindow> pFirstFloat = ImplGetSVData()->mpWinData->mpFirstFloat;
    if (pFirstFloat && !(pFirstFloat->GetPopupModeFlags() & FloatWinPopupFlags::NoAppFocusClose))
    {
        SolarMutexGuard aGuard;
        pFirstFloat->EndPopupMode(FloatWinPopupEndFlags::Cancel | FloatWinPopupEndFlags::CloseAll);
    }
}

void Qt5Widget::focusOutEvent(QFocusEvent*)
{
    m_rFrame.m_nKeyModifiers = ModKeyFlags::NONE;
    endExtTextInput();
    m_rFrame.CallCallback(SalEvent::LoseFocus, nullptr);
    closePopup();
}

Qt5Widget::Qt5Widget(Qt5Frame& rFrame, Qt::WindowFlags f)