tdf#77760 sw floattable: add support for footnotes, UI

Import filters could already create footnotes in floating tables, allow
the same from the UI.

Use IsFlySplitAllowed() as the check, because that already knows
rejecting special anchor locations like footnotes/headers/footers in
addition to actually decide if this is a split fly or not.

Change-Id: Ib9bab7b29d1bea0c15f3d829d16c9edbf1455b6b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156275
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
diff --git a/sw/qa/uibase/shells/textsh.cxx b/sw/qa/uibase/shells/textsh.cxx
index a97fc8b..f4c63ad5 100644
--- a/sw/qa/uibase/shells/textsh.cxx
+++ b/sw/qa/uibase/shells/textsh.cxx
@@ -12,8 +12,16 @@
#include <comphelper/propertyvalue.hxx>
#include <comphelper/propertysequence.hxx>
#include <comphelper/sequence.hxx>
#include <sfx2/viewfrm.hxx>
#include <sfx2/bindings.hxx>

#include <docary.hxx>
#include <docsh.hxx>
#include <frmmgr.hxx>
#include <wrtsh.hxx>
#include <formatflysplit.hxx>
#include <view.hxx>
#include <cmdid.h>

namespace
{
@@ -59,6 +67,44 @@ CPPUNIT_TEST_FIXTURE(Test, testDeleteSections)
    // i.e. the section was not deleted.
    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), pDoc->GetSections().size());
}

CPPUNIT_TEST_FIXTURE(Test, testSplitFlyFootnoteUI)
{
    // Given a document with a split fly (to host a table):
    createSwDoc();
    SwDoc* pDoc = getSwDoc();
    SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
    SwFlyFrameAttrMgr aMgr(true, pWrtShell, Frmmgr_Type::TEXT, nullptr);
    RndStdIds eAnchor = RndStdIds::FLY_AT_PARA;
    pWrtShell->StartAllAction();
    aMgr.InsertFlyFrame(eAnchor, aMgr.GetPos(), aMgr.GetSize());
    pWrtShell->EndAllAction();
    pWrtShell->StartAllAction();
    sw::FrameFormats<sw::SpzFrameFormat*>& rFlys = *pDoc->GetSpzFrameFormats();
    sw::SpzFrameFormat* pFly = rFlys[0];
    {
        SwAttrSet aSet(pFly->GetAttrSet());
        aSet.Put(SwFormatFlySplit(true));
        pDoc->SetAttr(aSet, *pFly);
    }
    pWrtShell->EndAllAction();
    pWrtShell->UnSelectFrame();
    pWrtShell->LeaveSelFrameMode();
    pWrtShell->GetView().AttrChangedNotify(nullptr);
    pWrtShell->MoveSection(GoCurrSection, fnSectionEnd);

    // When checking if we can insert a footnote inside the split fly:
    SwView& rView = pWrtShell->GetView();
    std::unique_ptr<SfxPoolItem> pItem;
    SfxItemState eState = rView.GetViewFrame().GetBindings().QueryState(FN_INSERT_FOOTNOTE, pItem);

    // Then make sure that the insertion is allowed:
    // Without the accompanying fix in place, this test would have failed with:
    // - Expected: 32 (DEFAULT)
    // - Actual  : 1 (DISABLED)
    // i.e. the insertion was denied.
    CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT, eState);
}
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/shells/textsh1.cxx b/sw/source/uibase/shells/textsh1.cxx
index abf5cae..5ba3d0a 100644
--- a/sw/source/uibase/shells/textsh1.cxx
+++ b/sw/source/uibase/shells/textsh1.cxx
@@ -118,6 +118,8 @@
#include <IDocumentUndoRedo.hxx>
#include <fmtcntnt.hxx>
#include <fmtrfmrk.hxx>
#include <cntfrm.hxx>
#include <flyfrm.hxx>

using namespace ::com::sun::star;
using namespace com::sun::star::beans;
@@ -2278,7 +2280,18 @@ void SwTextShell::GetState( SfxItemSet &rSet )
            {
                const FrameTypeFlags nNoType =
                    FrameTypeFlags::FLY_ANY | FrameTypeFlags::HEADER | FrameTypeFlags::FOOTER | FrameTypeFlags::FOOTNOTE;
                if ( rSh.GetFrameType(nullptr,true) & nNoType )
                FrameTypeFlags eType = rSh.GetFrameType(nullptr, true);
                bool bSplitFly = false;
                if (eType & FrameTypeFlags::FLY_ATCNT)
                {
                    SwContentFrame* pContentFrame = rSh.GetCurrFrame(/*bCalcFrame=*/false);
                    if (pContentFrame)
                    {
                        SwFlyFrame* pFlyFrame = pContentFrame->FindFlyFrame();
                        bSplitFly = pFlyFrame && pFlyFrame->IsFlySplitAllowed();
                    }
                }
                if (eType & nNoType && !bSplitFly)
                    rSet.DisableItem(nWhich);

                if ( rSh.CursorInsideInputField() )