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 7a35f3dc74
"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 <nemeth@numbertext.org>
Tested-by: Jenkins
This commit is contained in:
László Németh
2024-12-03 21:13:54 +01:00
parent 7a12424df2
commit bfb8f9cae7
3 changed files with 19 additions and 8 deletions
+1 -1
View File
@@ -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
+7 -5
View File
@@ -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
+11 -2
View File
@@ -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 ) )