sw/qa/uibase/shells/textsh.cxx      |   47 ++++++++++++++++++++++++++++++++++++
 sw/source/uibase/shells/textsh1.cxx |   15 ++++++++++-
 2 files changed, 61 insertions(+), 1 deletion(-)

New commits:
commit dfb6973c8ec841973d8e03ba304a8f58f894ae09
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Wed Aug 30 08:59:44 2023 +0200
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Thu Aug 31 17:11:41 2023 +0200

    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.
    
    (cherry picked from commit 739597df38dcaab0460482e3bc3f18f2471d43ab)
    
    Change-Id: Ib9bab7b29d1bea0c15f3d829d16c9edbf1455b6b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156336
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Tested-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/sw/qa/uibase/shells/textsh.cxx b/sw/qa/uibase/shells/textsh.cxx
index a97fc8bd7f5f..6ecf33025c18 100644
--- a/sw/qa/uibase/shells/textsh.cxx
+++ b/sw/qa/uibase/shells/textsh.cxx
@@ -12,8 +12,17 @@
 #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>
+#include <frameformats.hxx>
 
 namespace
 {
@@ -59,6 +68,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();
+    SwFrameFormats& rFlys = *pDoc->GetSpzFrameFormats();
+    SwFrameFormat* 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 4fd74802e01a..daad30d0a067 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;
@@ -2261,7 +2263,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() )

Reply via email to