sw/inc/ndarr.hxx                 |    2 +-
 sw/source/core/docnode/ndnum.cxx |   12 +++++++-----
 sw/source/uibase/app/docst.cxx   |   13 +++++++++++--
 3 files changed, 19 insertions(+), 8 deletions(-)

New commits:
commit bfb8f9cae715efb5fe2b0120924aa333ce2bd4d2
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Tue Dec 3 14:52:33 2024 +0100
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Tue Dec 3 21:13:54 2024 +0100

    tdf#48459 sw inline heading: don't apply inside frames or over 120 chars
    
    Don't apply inline heading 1) in a text frame
    2) or if the selected text is over 120 characters.
    
    1) It would be enough to limit this for inline heading
    frames, but the recent FN_INSERT_FRAME – which is used
    for creating the Inline Heading frame, cannot handle the
    insertion inside a frame: the new frame is anchored outside
    of the frame, not inside the actual paragraph, resulting
    bad layout.
    
    2) Increase also the limit of applying the inline heading
    to 120 characters (very upper limit for a long line) from 75.
    
    Follow-up to commit 7a35f3dc7419d833b8f47069c4df63e900ccb880
    "tdf#48459 sw inline heading: apply it on the selected words",
    
    Change-Id: I05de4be3a08926fdabad2e601d4bbe57ae25f7c1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177739
    Reviewed-by: László Németh <nem...@numbertext.org>
    Tested-by: Jenkins

diff --git a/sw/inc/ndarr.hxx b/sw/inc/ndarr.hxx
index 5c423e11378c..fdf0eec7849b 100644
--- a/sw/inc/ndarr.hxx
+++ b/sw/inc/ndarr.hxx
@@ -81,7 +81,7 @@ public:
     static constexpr auto npos = std::numeric_limits<size_type>::max();
 
     bool Seek_Entry(const SwNode* rP, size_type* pnPos) const;
-    static const SwNode* GetRootNode(const SwNode* pNode);
+    static const SwNode* GetRootNode(const SwNode* pNode, bool 
bCheckInlineHeading = true);
 };
 
 struct CompareSwOutlineNodesInline
diff --git a/sw/source/core/docnode/ndnum.cxx b/sw/source/core/docnode/ndnum.cxx
index 89e8cc186311..095bfaa60b56 100644
--- a/sw/source/core/docnode/ndnum.cxx
+++ b/sw/source/core/docnode/ndnum.cxx
@@ -27,18 +27,20 @@
 #include <fmtanchr.hxx>
 #include <poolfmt.hxx>
 
-static const SwNode* getNodeOrAnchorNode(const SwNode* pNode)
+static const SwNode* getNodeOrAnchorNode(const SwNode* pNode, bool 
bCheckInlineHeading = true)
 {
     // if pNode is an inline heading in an Inline Heading
     // text frame, return its anchor node instead of pNode
+    // if bCheckInlineHeading == false, it's enough to be in an
+    // arbitrary text frame to return its anchor node
     if (const auto pFlyFormat = pNode->GetFlyFormat())
     {
         SwFormatAnchor const*const pAnchor = &pFlyFormat->GetAnchor();
         SwNode const*const pAnchorNode = pAnchor->GetAnchorNode();
         const SwFormat* pParent = pFlyFormat->DerivedFrom();
-        if ( pAnchorNode && pParent &&
+        if ( pAnchorNode && pParent && ( !bCheckInlineHeading || (
                 RndStdIds::FLY_AS_CHAR == pAnchor->GetAnchorId() &&
-                pParent->GetPoolFormatId() == RES_POOLFRM_INLINE_HEADING )
+                pParent->GetPoolFormatId() == RES_POOLFRM_INLINE_HEADING ) ) )
         {
             return pAnchorNode;
         }
@@ -58,9 +60,9 @@ bool SwOutlineNodes::Seek_Entry(const SwNode* rP, size_type* 
pnPos) const
     return it != end() && rP->GetIndex() == (*it)->GetIndex();
 }
 
-const SwNode* SwOutlineNodes::GetRootNode(const SwNode* pNode)
+const SwNode* SwOutlineNodes::GetRootNode(const SwNode* pNode, bool 
bCheckInlineHeading)
 {
-    return getNodeOrAnchorNode(pNode);
+    return getNodeOrAnchorNode(pNode, bCheckInlineHeading);
 }
 
 bool CompareSwOutlineNodesInline::operator()(const SwNode* lhs, const SwNode* 
rhs) const
diff --git a/sw/source/uibase/app/docst.cxx b/sw/source/uibase/app/docst.cxx
index ecdb14726e37..c9b9a74d730c 100644
--- a/sw/source/uibase/app/docst.cxx
+++ b/sw/source/uibase/app/docst.cxx
@@ -1174,7 +1174,7 @@ void SwDocShell::Hide(const OUString &rName, 
SfxStyleFamily nFamily, bool bHidde
     }
 }
 
-#define MAX_CHAR_IN_INLINE_HEADING 75
+#define MAX_CHAR_IN_INLINE_HEADING 120
 bool SwDocShell::MakeInlineHeading(SwWrtShell *pSh, SwTextFormatColl* pColl, 
const sal_uInt16 nMode)
 {
     // insert an inline heading frame, if only MAX_CHAR_IN_INLINE_HEADING or 
less
@@ -1185,6 +1185,15 @@ bool SwDocShell::MakeInlineHeading(SwWrtShell *pSh, 
SwTextFormatColl* pColl, con
             0 < GetView()->GetSelectionText().getLength() )
     {
         SwTextFormatColl *pLocal = pColl? pColl: 
(*GetDoc()->GetTextFormatColls())[0];
+        // don't put inline heading in a frame (it would be enough to limit 
for inline heading
+        // frames, but the recent FN_INSERT_FRAME cannot handle the insertion 
inside a frame
+        // correctly)
+        // TODO: allow to insert inline headings in a (not an Inline Heading) 
text frame
+        if ( pSh->GetCursor()->GetPointNode() !=
+                *SwOutlineNodes::GetRootNode( 
&pSh->GetCursor()->GetPointNode(), /*bInlineHeading=*/false ) )
+        {
+            return false;
+        }
 
         // put inside a single Undo
         SwRewriter aRewriter;
@@ -1271,7 +1280,7 @@ SfxStyleFamily SwDocShell::ApplyStyles(const OUString 
&rName, SfxStyleFamily nFa
                 // outline node's content is folded.
                 MakeAllOutlineContentTemporarilyVisible a(GetDoc());
 
-                // if the first 75 or less characters are selected, but not 
the full paragraph,
+                // if the first 120 or less characters are selected, but not 
the full paragraph,
                 // create an inline heading from the selected text
                 SwTextFormatColl* pColl = pStyle->GetCollection();
                 if ( MakeInlineHeading( pSh, pColl, nMode ) )

Reply via email to