broadcast up/down of welded native modal dialogs like vcl ones

Change-Id: I61519f0ff92b912501f82e31d6cc3cae244208e6
Reviewed-on: https://gerrit.libreoffice.org/74028
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index 58d1422..33aea3f 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -1071,15 +1071,11 @@ public:

    virtual void set_modal(bool bModal) override
    {
        if (::Dialog* pDialog = dynamic_cast<::Dialog*>(m_xWindow.get()))
            return pDialog->SetModalInputMode(bModal);
        return m_xWindow->ImplGetFrame()->SetModal(bModal);
        m_xWindow->ImplGetFrame()->SetModal(bModal);
    }

    virtual bool get_modal() const override
    {
        if (const ::Dialog* pDialog = dynamic_cast<const ::Dialog*>(m_xWindow.get()))
            return pDialog->IsModalInputMode();
        return m_xWindow->ImplGetFrame()->GetModal();
    }

@@ -1331,6 +1327,18 @@ public:
        m_xDialog->add_button(xButton, nResponse, true);
    }

    virtual void set_modal(bool bModal) override
    {
        if (get_modal() == bModal)
            return;
        m_xDialog->SetModalInputMode(bModal);
    }

    virtual bool get_modal() const override
    {
        return m_xDialog->IsModalInputMode();
    }

    virtual weld::Button* get_widget_for_response(int nResponse) override;

    virtual void set_default_response(int nResponse) override
diff --git a/vcl/source/window/dialog.cxx b/vcl/source/window/dialog.cxx
index ce83520..ec660bf 100644
--- a/vcl/source/window/dialog.cxx
+++ b/vcl/source/window/dialog.cxx
@@ -964,12 +964,6 @@ bool Dialog::ImplStartExecute()
        if ( pSVData->maWinData.mpCaptureWin )
            pSVData->maWinData.mpCaptureWin->ReleaseMouse();
        EnableInput();

        if ( GetParent() )
        {
            SalFrame* pFrame = GetParent()->ImplGetFrame();
            pFrame->NotifyModalHierarchy(true);
        }
    }

    mbInExecute = true;
@@ -1159,12 +1153,6 @@ void Dialog::EndDialog( long nResult )
        }
    }

    if (bModal && GetParent())
    {
        SalFrame* pFrame = GetParent()->ImplGetFrame();
        pFrame->NotifyModalHierarchy(false);
    }

    mpDialogImpl->mnResult = nResult;

    if ( mpDialogImpl->mbStartedModal )
@@ -1222,6 +1210,13 @@ void Dialog::SetModalInputMode( bool bModal )
        return;

    ImplGetFrame()->SetModal(bModal);

    if (GetParent())
    {
        SalFrame* pFrame = GetParent()->ImplGetFrame();
        pFrame->NotifyModalHierarchy(bModal);
    }

    ImplSetModalInputMode(bModal);
}

diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx
index 42a66e6..d07207d 100644
--- a/vcl/unx/gtk3/gtk3gtkinst.cxx
+++ b/vcl/unx/gtk3/gtk3gtkinst.cxx
@@ -2938,6 +2938,7 @@ struct DialogRunner
        {
            m_xFrameWindow->IncModalCount();
            ++m_nModalDepth;
            m_xFrameWindow->ImplGetFrame()->NotifyModalHierarchy(true);
        }
    }

@@ -2947,6 +2948,7 @@ struct DialogRunner
        {
            m_xFrameWindow->DecModalCount();
            --m_nModalDepth;
            m_xFrameWindow->ImplGetFrame()->NotifyModalHierarchy(false);
        }
    }

@@ -2997,13 +2999,18 @@ struct DialogRunner

    ~DialogRunner()
    {
        if (m_xFrameWindow)
        if (m_xFrameWindow && m_nModalDepth)
        {
            // if, like the calc validation dialog does, the modality was
            // toggled off during execution ensure that on cleanup the parent
            // is left in the state it was found
            while (m_nModalDepth++ < 0)
            SalFrame* pFrame = m_xFrameWindow->ImplGetFrame();
            do
            {
                m_xFrameWindow->IncModalCount();
                pFrame->NotifyModalHierarchy(true);
            }
            while (++m_nModalDepth < 0);
        }
    }
};