tdf#155708 Fix validity dialog closes when moving focus to another window

Do not close Validation window if click on another Calc sheet.

Change-Id: I75569cbb91ebd445ac57f7a52d914297c21349e3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153930
Tested-by: Balazs Varga <balazs.varga.extern@allotropia.de>
Reviewed-by: Balazs Varga <balazs.varga.extern@allotropia.de>
(cherry picked from commit a5c61b143d53bb10430b8a486874856c16a2d86c)
and
(cherry picked from commit efaa065eb7053954242c83760f897e7dba2e9fe8)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154033
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Tested-by: Jenkins
diff --git a/include/sfx2/childwin.hxx b/include/sfx2/childwin.hxx
index 57c2369..6e4b200 100644
--- a/include/sfx2/childwin.hxx
+++ b/include/sfx2/childwin.hxx
@@ -156,6 +156,8 @@ public:
};

const int nCloseResponseToJustHide = -42;
// sc.hrc --> SID_VALIDITY_REFERENCE: 26161
const sal_uInt16 nScValidityWindowSlotID = 26161;

#define SFX_DECL_CHILDWINDOW(Class) \
    public  :   \
diff --git a/sc/source/ui/dbgui/validate.cxx b/sc/source/ui/dbgui/validate.cxx
index f202d8a..c0f62d4 100644
--- a/sc/source/ui/dbgui/validate.cxx
+++ b/sc/source/ui/dbgui/validate.cxx
@@ -104,6 +104,12 @@ ScValidationDlg::ScValidationDlg(weld::Window* pParent, const SfxItemSet* pArgSe

void ScValidationDlg::EndDialog(int nResponse)
{
    // tdf#155708 - do not close, just hide validation window if we click in another sheet
    if (nResponse == nCloseResponseToJustHide && getDialog()->get_visible())
    {
        getDialog()->hide();
        return;
    }
    // tdf#137215 ensure original modality of true is restored before dialog loop ends
    if (m_bOwnRefHdlr)
        RemoveRefDlg(true);
diff --git a/sc/source/ui/inc/validate.hxx b/sc/source/ui/inc/validate.hxx
index c8ed444..c58ae53 100644
--- a/sc/source/ui/inc/validate.hxx
+++ b/sc/source/ui/inc/validate.hxx
@@ -154,6 +154,8 @@ class ScValidationDlg
    bool    m_bOwnRefHdlr:1;
    bool    m_bRefInputting:1;

    const int nCloseResponseToJustHide = -42;

    std::unique_ptr<weld::Container> m_xHBox;

    bool    EnterRefStatus();
diff --git a/sfx2/source/appl/childwin.cxx b/sfx2/source/appl/childwin.cxx
index 1fe6c39..633c33b 100644
--- a/sfx2/source/appl/childwin.cxx
+++ b/sfx2/source/appl/childwin.cxx
@@ -522,12 +522,21 @@ void SfxChildWindow::Show( ShowFlags nFlags )
    {
        if (!xController->getDialog()->get_visible())
        {
            weld::DialogController::runAsync(xController,
                [this](sal_Int32 nResult) {
                    if (nResult == nCloseResponseToJustHide)
                        return;
                    xController->Close();
                });
            if (nScValidityWindowSlotID == GetType())
            {
                // tdf#155708 - do not run a new (Async) validation window,
                // because we already have one in sync mode, just show the running one
                xController->getDialog()->show();
            }
            else
            {
                weld::DialogController::runAsync(xController,
                    [this](sal_Int32 nResult) {
                        if (nResult == nCloseResponseToJustHide)
                            return;
                        xController->Close();
                    });
            }
        }
    }
    else