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>
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/include/vcl/toolkit/dialog.hxx b/include/vcl/toolkit/dialog.hxx
index 5e11d2f..640204a 100644
--- a/include/vcl/toolkit/dialog.hxx
+++ b/include/vcl/toolkit/dialog.hxx
@@ -58,6 +58,8 @@ private:
    bool            mbModalMode;
    InitFlag        mnInitFlag; // used for deferred init

    const int nCloseResponseToJustHide = -42;

    VclPtr<VclButtonBox> mpActionArea;
    VclPtr<VclBox>       mpContentArea;

diff --git a/sc/source/ui/dbgui/validate.cxx b/sc/source/ui/dbgui/validate.cxx
index 4445f68..f8565e9 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