Related: tdf#117068 inform salframe that there's a modal dialog running

Change-Id: Ie95fbc1586e11396271fb43e6117f39f4f61cb0e
Reviewed-on: https://gerrit.libreoffice.org/53086
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/include/vcl/window.hxx b/include/vcl/window.hxx
index ddc9ae04..6b5dd1b 100644
--- a/include/vcl/window.hxx
+++ b/include/vcl/window.hxx
@@ -603,8 +603,8 @@ public:
    SAL_DLLPRIVATE void                 ImplCallResize();
    SAL_DLLPRIVATE void                 ImplCallMove();

    SAL_DLLPRIVATE void                 ImplIncModalCount();
    SAL_DLLPRIVATE void                 ImplDecModalCount();
                   void                 IncModalCount();
                   void                 DecModalCount();

    SAL_DLLPRIVATE static void          ImplCalcSymbolRect( tools::Rectangle& rRect );

diff --git a/vcl/source/window/dialog.cxx b/vcl/source/window/dialog.cxx
index 39c02f3..c29227d 100644
--- a/vcl/source/window/dialog.cxx
+++ b/vcl/source/window/dialog.cxx
@@ -1169,7 +1169,7 @@ void Dialog::ImplSetModalInputMode( bool bModal )
            // #115933# disable the whole frame hierarchy, useful if our parent
            // is a modeless dialog
            mpDialogParent = pParent->mpWindowImpl->mpFrameWindow;
            mpDialogParent->ImplIncModalCount();
            mpDialogParent->IncModalCount();
        }
    }
    else
@@ -1179,7 +1179,7 @@ void Dialog::ImplSetModalInputMode( bool bModal )
            // #115933# re-enable the whole frame hierarchy again (see above)
            // note that code in getfocus assures that we do not accidentally enable
            // windows that were disabled before
            mpDialogParent->ImplDecModalCount();
            mpDialogParent->DecModalCount();
        }

        // Enable the prev Modal Dialog
diff --git a/vcl/source/window/menufloatingwindow.cxx b/vcl/source/window/menufloatingwindow.cxx
index a2bc547..ea4cb3b 100644
--- a/vcl/source/window/menufloatingwindow.cxx
+++ b/vcl/source/window/menufloatingwindow.cxx
@@ -398,7 +398,7 @@ void MenuFloatingWindow::Start()
        return;
    bInExecute = true;
    if (GetParent())
        GetParent()->ImplIncModalCount();
        GetParent()->IncModalCount();
}

void MenuFloatingWindow::End()
@@ -407,7 +407,7 @@ void MenuFloatingWindow::End()
        return;

    if (GetParent() && !GetParent()->IsDisposed())
        GetParent()->ImplDecModalCount();
        GetParent()->DecModalCount();

    // restore focus to previous window if we still have the focus
    VclPtr<vcl::Window> xFocusId(xSaveFocusId);
diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx
index f554820..c4db4c9 100644
--- a/vcl/source/window/window.cxx
+++ b/vcl/source/window/window.cxx
@@ -3518,7 +3518,7 @@ bool Window::IsInModalMode() const
    return (mpWindowImpl->mpFrameWindow->mpWindowImpl->mpFrameData->mnModalMode != 0);
}

void Window::ImplIncModalCount()
void Window::IncModalCount()
{
    vcl::Window* pFrameWindow = mpWindowImpl->mpFrameWindow;
    vcl::Window* pParent = pFrameWindow;
@@ -3532,7 +3532,7 @@ void Window::ImplIncModalCount()
        pFrameWindow = pParent ? pParent->mpWindowImpl->mpFrameWindow.get() : nullptr;
    }
}
void Window::ImplDecModalCount()
void Window::DecModalCount()
{
    vcl::Window* pFrameWindow = mpWindowImpl->mpFrameWindow;
    vcl::Window* pParent = pFrameWindow;
diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx
index 921c579..4c27376 100644
--- a/vcl/unx/gtk3/gtk3gtkinst.cxx
+++ b/vcl/unx/gtk3/gtk3gtkinst.cxx
@@ -1947,9 +1947,16 @@ public:
    {
        sort_native_button_order(GTK_BOX(gtk_dialog_get_action_area(m_pDialog)));
        int ret;
        GtkWindow* pParent = gtk_window_get_transient_for(GTK_WINDOW(m_pDialog));
        GtkSalFrame* pFrame = GtkSalFrame::getFromWindow(pParent);
        vcl::Window* pFrameWindow = pFrame ? pFrame->GetWindow() : nullptr;
        while (true)
        {
            if (pFrameWindow)
                pFrameWindow->IncModalCount();
            ret = gtk_dialog_run(m_pDialog);
            if (pFrameWindow)
                pFrameWindow->DecModalCount();
            if (ret == GTK_RESPONSE_HELP)
            {
                help();
diff --git a/vcl/win/window/salframe.cxx b/vcl/win/window/salframe.cxx
index a15e692..a70262f 100644
--- a/vcl/win/window/salframe.cxx
+++ b/vcl/win/window/salframe.cxx
@@ -5647,7 +5647,7 @@ LRESULT CALLBACK SalFrameWndProc( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lP
                    if( pWin )
                    {
                        pWin->EnableInput( false, nullptr );
                        pWin->ImplIncModalCount();  // #106303# support frame based modal count
                        pWin->IncModalCount();  // #106303# support frame based modal count
                    }
                }
                else
@@ -5656,7 +5656,7 @@ LRESULT CALLBACK SalFrameWndProc( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lP
                    if( pWin )
                    {
                        pWin->EnableInput( true, nullptr );
                        pWin->ImplDecModalCount();  // #106303# support frame based modal count
                        pWin->DecModalCount();  // #106303# support frame based modal count
                    }
                }
            }