[Libreoffice-commits] core.git: Branch 'private/mst/sw_redlinehide_4a' - 18 commits - sw/qa sw/source sw/uiconfig
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Sat Dec 1 07:46:40 UTC 2018
Rebased ref, commits from common ancestor:
commit 856934c12e89c84bcf0ca67be0dd8dc03e45f95d
Author: Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Fri Nov 30 18:00:19 2018 +0100
Commit: Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Sat Dec 1 08:43:01 2018 +0100
HACK: ODF import: always hide redlines
Change-Id: I275c6738943ee0d74ccacea69af1c1f4c9ede1df
diff --git a/sw/source/filter/xml/swxml.cxx b/sw/source/filter/xml/swxml.cxx
index 138dc19981c8..5b10130d6e8f 100644
--- a/sw/source/filter/xml/swxml.cxx
+++ b/sw/source/filter/xml/swxml.cxx
@@ -889,8 +889,10 @@ ErrCode XMLReader::Read( SwDoc &rDoc, const OUString& rBaseURL, SwPaM &rPaM, con
// restore redline mode from import info property set
RedlineFlags nRedlineFlags = RedlineFlags::ShowInsert;
aAny = xInfoSet->getPropertyValue( sShowChanges );
+#if 0
if ( *o3tl::doAccess<bool>(aAny) )
nRedlineFlags |= RedlineFlags::ShowDelete;
+#endif
aAny = xInfoSet->getPropertyValue( sRecordChanges );
if ( *o3tl::doAccess<bool>(aAny) || (aKey.getLength() > 0) )
nRedlineFlags |= RedlineFlags::On;
commit a67261d125ba3ca3c456936c54f9bed17ed7510e
Author: Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Fri Nov 30 17:54:41 2018 +0100
Commit: Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Sat Dec 1 08:43:01 2018 +0100
sw_redlinehide: make layout based Show/Hide mode the default
remove ExperimentalMode checks
Change-Id: Ie098eda0840bbd3231696cae43cc572ad61379fc
diff --git a/sw/source/core/edit/autofmt.cxx b/sw/source/core/edit/autofmt.cxx
index 7089ce157de3..048706bbce41 100644
--- a/sw/source/core/edit/autofmt.cxx
+++ b/sw/source/core/edit/autofmt.cxx
@@ -2267,21 +2267,14 @@ SwAutoFormat::SwAutoFormat( SwEditShell* pEdShell, SvxSwAutoFormatFlags const &
m_nEndNdIdx = m_aEndNdIdx.GetIndex(),
m_pDoc->GetDocShell() );
- uno::Reference<uno::XComponentContext> const xContext(
- comphelper::getProcessComponentContext());
- bool const isExp(officecfg::Office::Common::Misc::ExperimentalMode::get(xContext));
RedlineFlags eRedlMode = m_pDoc->getIDocumentRedlineAccess().GetRedlineFlags(), eOldMode = eRedlMode;
if( m_aFlags.bWithRedlining )
{
m_pDoc->SetAutoFormatRedline( true );
- eRedlMode = isExp
- ? RedlineFlags::On | (eOldMode & RedlineFlags::ShowMask)
- : RedlineFlags::On | RedlineFlags::ShowInsert;
+ eRedlMode = RedlineFlags::On | (eOldMode & RedlineFlags::ShowMask);
}
else
- eRedlMode = isExp
- ? RedlineFlags::Ignore | (eOldMode & RedlineFlags::ShowMask)
- : RedlineFlags::ShowInsert | RedlineFlags::Ignore;
+ eRedlMode = RedlineFlags::Ignore | (eOldMode & RedlineFlags::ShowMask);
m_pDoc->getIDocumentRedlineAccess().SetRedlineFlags( eRedlMode );
// save undo state (might be turned off)
diff --git a/sw/source/filter/xml/XMLRedlineImportHelper.cxx b/sw/source/filter/xml/XMLRedlineImportHelper.cxx
index ce3573b7b946..f956bbd85953 100644
--- a/sw/source/filter/xml/XMLRedlineImportHelper.cxx
+++ b/sw/source/filter/xml/XMLRedlineImportHelper.cxx
@@ -343,19 +343,12 @@ XMLRedlineImportHelper::~XMLRedlineImportHelper()
aAny <<= bShowChanges;
if ( bHandleShowChanges )
{
- if (!utl::ConfigManager::IsFuzzing() && officecfg::Office::Common::Misc::ExperimentalMode::get(comphelper::getProcessComponentContext()))
- {
- aAny <<= true;
- xModelPropertySet->setPropertyValue( g_sShowChanges, aAny );
- // TODO maybe we need some property for the view-setting?
- SwDoc *const pDoc(SwImport::GetDocFromXMLImport(m_rImport));
- assert(pDoc);
- pDoc->GetDocumentRedlineManager().SetHideRedlines(!bShowChanges);
- }
- else
- {
- xModelPropertySet->setPropertyValue( g_sShowChanges, aAny );
- }
+ aAny <<= true;
+ xModelPropertySet->setPropertyValue( g_sShowChanges, aAny );
+ // TODO maybe we need some property for the view-setting?
+ SwDoc *const pDoc(SwImport::GetDocFromXMLImport(m_rImport));
+ assert(pDoc);
+ pDoc->GetDocumentRedlineManager().SetHideRedlines(!bShowChanges);
}
else
xImportInfoPropertySet->setPropertyValue( g_sShowChanges, aAny );
diff --git a/sw/source/filter/xml/swxml.cxx b/sw/source/filter/xml/swxml.cxx
index f36ffb47a147..138dc19981c8 100644
--- a/sw/source/filter/xml/swxml.cxx
+++ b/sw/source/filter/xml/swxml.cxx
@@ -856,8 +856,7 @@ ErrCode XMLReader::Read( SwDoc &rDoc, const OUString& rBaseURL, SwPaM &rPaM, con
if( !(IsOrganizerMode() || IsBlockMode() || m_bInsertMode ||
m_aOption.IsFormatsOnly() ||
// sw_redlinehide: disable layout cache for now
- (officecfg::Office::Common::Misc::ExperimentalMode::get(xContext) &&
- !*o3tl::doAccess<bool>(xInfoSet->getPropertyValue(sShowChanges)))))
+ !*o3tl::doAccess<bool>(xInfoSet->getPropertyValue(sShowChanges))))
{
try
{
@@ -905,14 +904,8 @@ ErrCode XMLReader::Read( SwDoc &rDoc, const OUString& rBaseURL, SwPaM &rPaM, con
// tdf#83260 ensure that the first call of CompressRedlines after loading
// the document is a no-op by calling it now
rDoc.getIDocumentRedlineAccess().CompressRedlines();
- if (officecfg::Office::Common::Misc::ExperimentalMode::get(xContext))
- { // can't set it on the layout or view shell because it doesn't exist yet
- rDoc.GetDocumentRedlineManager().SetHideRedlines(!(nRedlineFlags & RedlineFlags::ShowDelete));
- }
- else
- {
- rDoc.getIDocumentRedlineAccess().SetRedlineFlags(nRedlineFlags);
- }
+ // can't set it on the layout or view shell because it doesn't exist yet
+ rDoc.GetDocumentRedlineManager().SetHideRedlines(!(nRedlineFlags & RedlineFlags::ShowDelete));
lcl_EnsureValidPam( rPaM ); // move Pam into valid content
diff --git a/sw/source/filter/xml/wrtxml.cxx b/sw/source/filter/xml/wrtxml.cxx
index 0d5e53d4c319..ecdfd3fb3ba0 100644
--- a/sw/source/filter/xml/wrtxml.cxx
+++ b/sw/source/filter/xml/wrtxml.cxx
@@ -187,15 +187,9 @@ ErrCode SwXMLWriter::Write_( const uno::Reference < task::XStatusIndicator >& xS
const OUString sShowChanges("ShowChanges");
RedlineFlags nRedlineFlags = m_pDoc->getIDocumentRedlineAccess().GetRedlineFlags();
bool isShowChanges;
- if (officecfg::Office::Common::Misc::ExperimentalMode::get(xContext))
- { // TODO: ideally this would be stored per-view...
- SwRootFrame const*const pLayout(m_pDoc->getIDocumentLayoutAccess().GetCurrentLayout());
- isShowChanges = pLayout == nullptr || !pLayout->IsHideRedlines();
- }
- else
- {
- isShowChanges = IDocumentRedlineAccess::IsShowChanges(nRedlineFlags);
- }
+ // TODO: ideally this would be stored per-view...
+ SwRootFrame const*const pLayout(m_pDoc->getIDocumentLayoutAccess().GetCurrentLayout());
+ isShowChanges = pLayout == nullptr || !pLayout->IsHideRedlines();
xInfoSet->setPropertyValue(sShowChanges, makeAny(isShowChanges));
// ... and hide redlines for export
nRedlineFlags &= ~RedlineFlags::ShowMask;
@@ -418,15 +412,7 @@ ErrCode SwXMLWriter::Write_( const uno::Reference < task::XStatusIndicator >& xS
nRedlineFlags = m_pDoc->getIDocumentRedlineAccess().GetRedlineFlags();
nRedlineFlags &= ~RedlineFlags::ShowMask;
nRedlineFlags |= RedlineFlags::ShowInsert;
- if (officecfg::Office::Common::Misc::ExperimentalMode::get(xContext))
- {
- nRedlineFlags |= RedlineFlags::ShowDelete;
- }
- else
- {
- if (*o3tl::doAccess<bool>(aAny))
- nRedlineFlags |= RedlineFlags::ShowDelete;
- }
+ nRedlineFlags |= RedlineFlags::ShowDelete;
m_pDoc->getIDocumentRedlineAccess().SetRedlineFlags( nRedlineFlags );
if (xStatusIndicator.is())
diff --git a/sw/source/uibase/uiview/view2.cxx b/sw/source/uibase/uiview/view2.cxx
index d753b849b97b..1e4c2bcff5a3 100644
--- a/sw/source/uibase/uiview/view2.cxx
+++ b/sw/source/uibase/uiview/view2.cxx
@@ -638,17 +638,10 @@ void SwView::Execute(SfxRequest &rReq)
if( static_cast<const SfxBoolItem*>(pItem)->GetValue() )
nMode |= RedlineFlags::ShowDelete;
- uno::Reference<uno::XComponentContext> const xContext(
- comphelper::getProcessComponentContext());
- if (officecfg::Office::Common::Misc::ExperimentalMode::get(xContext))
- {
- m_pWrtShell->GetLayout()->SetHideRedlines(
- !static_cast<const SfxBoolItem*>(pItem)->GetValue());
- if (m_pWrtShell->IsRedlineOn())
- m_pWrtShell->SetInsMode();
- }
- else
- m_pWrtShell->SetRedlineFlagsAndCheckInsMode( nMode );
+ m_pWrtShell->GetLayout()->SetHideRedlines(
+ !static_cast<const SfxBoolItem*>(pItem)->GetValue());
+ if (m_pWrtShell->IsRedlineOn())
+ m_pWrtShell->SetInsMode();
}
break;
case FN_MAILMERGE_SENDMAIL_CHILDWINDOW:
diff --git a/sw/source/uibase/uiview/viewstat.cxx b/sw/source/uibase/uiview/viewstat.cxx
index 38ffb27df5da..909ba9a67225 100644
--- a/sw/source/uibase/uiview/viewstat.cxx
+++ b/sw/source/uibase/uiview/viewstat.cxx
@@ -284,12 +284,7 @@ void SwView::GetState(SfxItemSet &rSet)
{
uno::Reference<uno::XComponentContext> const xContext(
comphelper::getProcessComponentContext());
- if (officecfg::Office::Common::Misc::ExperimentalMode::get(xContext))
- {
- rSet.Put(SfxBoolItem(nWhich, !m_pWrtShell->GetLayout()->IsHideRedlines()));
- }
- else
- rSet.Put( SfxBoolItem( nWhich, IDocumentRedlineAccess::IsShowChanges(m_pWrtShell->GetRedlineFlags()) ));
+ rSet.Put(SfxBoolItem(nWhich, !m_pWrtShell->GetLayout()->IsHideRedlines()));
}
break;
case SID_AVMEDIA_PLAYER :
commit 799cd4c200139b15f104e6f3250000b68d23619a
Author: Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Fri Nov 30 16:28:04 2018 +0100
Commit: Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Sat Dec 1 08:43:01 2018 +0100
sw_redlinehide_4a: MoveDeletedPrevFrames() should only move
... frames from a layout with hidden redlines.
Change-Id: I8f5d5bbbc5bfd49a8a52579a1c34157b9c5c4515
diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx
index 8d721140cb37..a979650504e1 100644
--- a/sw/source/core/txtnode/ndtxt.cxx
+++ b/sw/source/core/txtnode/ndtxt.cxx
@@ -846,16 +846,22 @@ void MoveDeletedPrevFrames(SwTextNode & rDeletedPrev, SwTextNode & rNode)
SwIterator<SwTextFrame, SwTextNode, sw::IteratorMode::UnwrapMulti> aIter(rDeletedPrev);
for (SwTextFrame* pFrame = aIter.First(); pFrame; pFrame = aIter.Next())
{
- frames.push_back(pFrame);
+ if (pFrame->getRootFrame()->IsHideRedlines())
+ {
+ frames.push_back(pFrame);
+ }
}
{
auto frames2(frames);
SwIterator<SwTextFrame, SwTextNode, sw::IteratorMode::UnwrapMulti> aIt(rNode);
for (SwTextFrame* pFrame = aIt.First(); pFrame; pFrame = aIt.Next())
{
- auto const it(std::find(frames2.begin(), frames2.end(), pFrame));
- assert(it != frames2.end());
- frames2.erase(it);
+ if (pFrame->getRootFrame()->IsHideRedlines())
+ {
+ auto const it(std::find(frames2.begin(), frames2.end(), pFrame));
+ assert(it != frames2.end());
+ frames2.erase(it);
+ }
}
assert(frames2.empty());
}
commit 690b8f193f145353833660101f3cf07643316848
Author: Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Thu Nov 29 15:56:18 2018 +0100
Commit: Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Sat Dec 1 08:43:01 2018 +0100
sw_redlinehide_4a: fix infinite loop in SwAttrIter::Seek()
It's actually possible for Seek to be invoked with a position that is
neither 0 nor >= the current position:
lcl_CalcOptRepaint(), called from SwTextFormatter::FormatLine(), will
move backwards via some funny heuristic and call GetCharRect(), which
then seeks.
Change-Id: If061a768b9a0155d9a95b190c44e7048312f4ba3
diff --git a/sw/source/core/text/itratr.cxx b/sw/source/core/text/itratr.cxx
index 458212f8fd17..6809322c1fe1 100644
--- a/sw/source/core/text/itratr.cxx
+++ b/sw/source/core/text/itratr.cxx
@@ -350,7 +350,8 @@ bool SwAttrIter::Seek(TextFrameIndex const nNewPos)
// sw_redlinehide: Seek(0) must move before the first character, which
// has a special case where the first node starts with delete redline.
- if ((!nNewPos && (!m_pMergedPara || newPos.first != m_pTextNode))
+ if ((!nNewPos && !m_pMergedPara)
+ || newPos.first != m_pTextNode
|| newPos.second < m_nPosition)
{
if (m_pMergedPara)
commit 17fb4196146f168c4e08b895bfb079533cb71574
Author: Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Thu Nov 29 14:50:20 2018 +0100
Commit: Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Sat Dec 1 08:43:01 2018 +0100
sw_redlinehide_4a: fix asserts caused by invalid index in SwUpdateAttr
There is no reason for SwpHints::TryInsertHint() to add 1 to the end
index of an empty hint, which results in an invalid index when the end
of the hint is at the end of the node.
The only user of the indexes in SwUpdateAttr is
SwTextFrame::SwClientNotify() and it already extends a 0 range to 1.
Change-Id: I7355bac931cd8dd390f96d04546d73273f364cda
diff --git a/sw/source/core/text/txtfrm.cxx b/sw/source/core/text/txtfrm.cxx
index 104a657d1242..f2b2ed9acebf 100644
--- a/sw/source/core/text/txtfrm.cxx
+++ b/sw/source/core/text/txtfrm.cxx
@@ -2127,9 +2127,8 @@ void SwTextFrame::SwClientNotify(SwModify const& rModify, SfxHint const& rHint)
if( IsIdxInside( nPos, nLen ) )
{
// We need to reformat anyways, even if the invalidated
- // area is NULL.
+ // range is empty.
// E.g.: empty line, set 14 pt!
- // if( !nLen ) nLen = 1;
// FootnoteNumbers need to be formatted
if( !nLen )
diff --git a/sw/source/core/txtnode/thints.cxx b/sw/source/core/txtnode/thints.cxx
index 83aa88513688..1d6860f4d959 100644
--- a/sw/source/core/txtnode/thints.cxx
+++ b/sw/source/core/txtnode/thints.cxx
@@ -3253,10 +3253,7 @@ bool SwpHints::TryInsertHint(
// ... and notify listeners
if ( rNode.HasWriterListeners() )
{
- SwUpdateAttr aHint(
- nHtStart,
- nHtStart == nHintEnd ? nHintEnd + 1 : nHintEnd,
- nWhich);
+ SwUpdateAttr aHint(nHtStart, nHintEnd, nWhich);
rNode.ModifyNotification( nullptr, &aHint );
}
commit 71f90c9a52077f9d1bf55b3ffe818333153ac6ab
Author: Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Wed Nov 28 18:15:41 2018 +0100
Commit: Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Sat Dec 1 08:43:01 2018 +0100
sw_redlinehide_4a: stop toggling ShowDelete in SwAutoFormat
Change-Id: Ib6495d4248faa679d5a55642ac51baf419708287
diff --git a/sw/source/core/edit/autofmt.cxx b/sw/source/core/edit/autofmt.cxx
index 389fab10fa67..7089ce157de3 100644
--- a/sw/source/core/edit/autofmt.cxx
+++ b/sw/source/core/edit/autofmt.cxx
@@ -19,6 +19,10 @@
#include <hintids.hxx>
+#include <officecfg/Office/Common.hxx>
+
+#include <comphelper/processfactory.hxx>
+
#include <unotools/charclass.hxx>
#include <editeng/boxitem.hxx>
@@ -2263,14 +2267,21 @@ SwAutoFormat::SwAutoFormat( SwEditShell* pEdShell, SvxSwAutoFormatFlags const &
m_nEndNdIdx = m_aEndNdIdx.GetIndex(),
m_pDoc->GetDocShell() );
+ uno::Reference<uno::XComponentContext> const xContext(
+ comphelper::getProcessComponentContext());
+ bool const isExp(officecfg::Office::Common::Misc::ExperimentalMode::get(xContext));
RedlineFlags eRedlMode = m_pDoc->getIDocumentRedlineAccess().GetRedlineFlags(), eOldMode = eRedlMode;
if( m_aFlags.bWithRedlining )
{
m_pDoc->SetAutoFormatRedline( true );
- eRedlMode = RedlineFlags::On | RedlineFlags::ShowInsert;
+ eRedlMode = isExp
+ ? RedlineFlags::On | (eOldMode & RedlineFlags::ShowMask)
+ : RedlineFlags::On | RedlineFlags::ShowInsert;
}
else
- eRedlMode = RedlineFlags::ShowInsert | RedlineFlags::Ignore;
+ eRedlMode = isExp
+ ? RedlineFlags::Ignore | (eOldMode & RedlineFlags::ShowMask)
+ : RedlineFlags::ShowInsert | RedlineFlags::Ignore;
m_pDoc->getIDocumentRedlineAccess().SetRedlineFlags( eRedlMode );
// save undo state (might be turned off)
commit e9be771c25a2aa3d2c9724888ac33526c5347f77
Author: Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Wed Nov 28 17:41:09 2018 +0100
Commit: Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Sat Dec 1 08:43:01 2018 +0100
sw_redlinehide_4a: TextFrameIndex goes live
Change-Id: Ie59c09bdc57505e16022c43791d5e65cc233d5b9
diff --git a/sw/source/core/inc/TextFrameIndex.hxx b/sw/source/core/inc/TextFrameIndex.hxx
index d15fc7bf6691..3987bd5903fe 100644
--- a/sw/source/core/inc/TextFrameIndex.hxx
+++ b/sw/source/core/inc/TextFrameIndex.hxx
@@ -13,17 +13,13 @@
#include <sal/types.h>
#include <o3tl/strong_int.hxx>
-#if 0
-typedef o3tl::strong_int<sal_Int32, struct Tag_TextFrameIndex> TextFrameIndex;
-#else
/**
* Denotes a character index in a text frame at a layout level, after extent
* mapping from a text node at a document model level.
*
* @see SwTextFrame::MapViewToModelPos().
*/
-typedef sal_Int32 TextFrameIndex;
-#endif
+typedef o3tl::strong_int<sal_Int32, struct Tag_TextFrameIndex> TextFrameIndex;
#endif // INCLUDED_SW_SOURCE_CORE_INC_TEXTFRAMEINDEX_HXX
commit 7c6ce9a21b4bb5a89aedcefcb7cac145c52ab6c2
Author: Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Wed Nov 28 17:27:39 2018 +0100
Commit: Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Sat Dec 1 08:43:01 2018 +0100
sw_redlinehide_4a: SwEditShell::AutoCorrect() etc.
The hope is that the AutoCorrect never deletes nodes, hence never
deletes SwTextFrames, hence we can pass in the SwTextFrame::GetText()
result and it will be updated via the SwTextFrame::SwClientNotify()
on editing operations.
Change-Id: Ib644d0373963119b9f7fe6767b028fd89724feb3
diff --git a/sw/source/core/edit/edws.cxx b/sw/source/core/edit/edws.cxx
index 32770a346284..1b2e720d1821 100644
--- a/sw/source/core/edit/edws.cxx
+++ b/sw/source/core/edit/edws.cxx
@@ -30,6 +30,7 @@
#include <acorrect.hxx>
#include <swtable.hxx>
#include <ndtxt.hxx>
+#include <txtfrm.hxx>
#include <swundo.hxx>
#include <SwRewriter.hxx>
@@ -265,9 +266,11 @@ void SwEditShell::AutoCorrect( SvxAutoCorrect& rACorr, bool bInsert,
SwAutoCorrDoc aSwAutoCorrDoc( *this, *pCursor, cChar );
// FIXME: this _must_ be called with reference to the actual node text!
- OUString const& rNodeText(pTNd->GetText());
+ SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(pTNd->getLayoutFrame(GetLayout())));
+ TextFrameIndex const nPos(pFrame->MapModelToViewPos(*pCursor->GetPoint()));
+ OUString const& rMergedText(pFrame->GetText());
rACorr.DoAutoCorrect( aSwAutoCorrDoc,
- rNodeText, pCursor->GetPoint()->nContent.GetIndex(),
+ rMergedText, sal_Int32(nPos),
cChar, bInsert, m_bNbspRunNext, GetWin() );
if( cChar )
SaveTableBoxContent( pCursor->GetPoint() );
@@ -285,13 +288,14 @@ bool SwEditShell::GetPrevAutoCorrWord( SvxAutoCorrect const & rACorr, OUString&
bool bRet;
SwPaM* pCursor = getShellCursor( true );
- const sal_Int32 nPos = pCursor->GetPoint()->nContent.GetIndex();
SwTextNode* pTNd = pCursor->GetNode().GetTextNode();
- if( pTNd && nPos )
+ if (pTNd)
{
SwAutoCorrDoc aSwAutoCorrDoc( *this, *pCursor, 0 );
+ SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(pTNd->getLayoutFrame(GetLayout())));
+ TextFrameIndex const nPos(pFrame->MapModelToViewPos(*pCursor->GetPoint()));
bRet = rACorr.GetPrevAutoCorrWord( aSwAutoCorrDoc,
- pTNd->GetText(), nPos, rWord );
+ pFrame->GetText(), sal_Int32(nPos), rWord );
}
else
bRet = false;
commit 475cbccf665bd6b4c35a060e90a2f31cc127baad
Author: Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Wed Nov 28 17:09:22 2018 +0100
Commit: Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Sat Dec 1 08:43:01 2018 +0100
sw_redlinehide_4a: SwAutoFormat::AutoCorrect()
Change-Id: I0ab7665f8635d6716fce996408db1e2bedf54d0c
diff --git a/sw/source/core/edit/autofmt.cxx b/sw/source/core/edit/autofmt.cxx
index ea6a4dc797b1..389fab10fa67 100644
--- a/sw/source/core/edit/autofmt.cxx
+++ b/sw/source/core/edit/autofmt.cxx
@@ -187,7 +187,7 @@ class SwAutoFormat
/// join with the previous paragraph
void JoinPrevPara();
/// execute AutoCorrect on current TextNode
- void AutoCorrect( sal_Int32 nSttPos = 0 );
+ void AutoCorrect(TextFrameIndex nSttPos = TextFrameIndex(0));
bool CanJoin(const SwTextFrame * pNextFrame) const
{
@@ -1496,7 +1496,7 @@ void SwAutoFormat::BuildEnum( sal_uInt16 nLvl, sal_uInt16 nDigitLevel )
DeleteLeadingTrailingBlanks();
bool bChgBullet = false, bChgEnum = false;
- sal_Int32 nAutoCorrPos = 0;
+ TextFrameIndex nAutoCorrPos(0);
// if numbering is set, get the current one
SwNumRule aRule( m_pDoc->GetUniqueNumRuleName(),
@@ -1749,7 +1749,7 @@ void SwAutoFormat::BuildEnum( sal_uInt16 nLvl, sal_uInt16 nDigitLevel )
RES_CHRATR_FONT ) );
m_pDoc->SetFormatItemByAutoFormat( m_aDelPam, aSet );
m_aDelPam.DeleteMark();
- nAutoCorrPos = 2;
+ nAutoCorrPos = TextFrameIndex(2);
aSet.ClearItem();
}
SvxTabStopItem aTStops( RES_PARATR_TABSTOP );
@@ -1907,7 +1907,7 @@ void SwAutoFormat::BuildHeadLine( sal_uInt16 nLvl )
}
/// Start autocorrection for the current TextNode
-void SwAutoFormat::AutoCorrect( sal_Int32 nPos )
+void SwAutoFormat::AutoCorrect(TextFrameIndex nPos)
{
SvxAutoCorrect* pATst = SvxAutoCorrCfg::Get().GetAutoCorrect();
ACFlags aSvxFlags = pATst->GetFlags( );
@@ -1922,8 +1922,8 @@ void SwAutoFormat::AutoCorrect( sal_Int32 nPos )
!m_aFlags.bChgWeightUnderl && !m_aFlags.bAddNonBrkSpace) )
return;
- const OUString* pText = &m_pCurTextNd->GetText();
- if (nPos >= pText->getLength())
+ const OUString* pText = &m_pCurTextFrame->GetText();
+ if (TextFrameIndex(pText->getLength()) <= nPos)
return;
bool bGetLanguage = m_aFlags.bChgOrdinalNumber ||
@@ -1932,14 +1932,13 @@ void SwAutoFormat::AutoCorrect( sal_Int32 nPos )
m_aFlags.bAddNonBrkSpace;
m_aDelPam.DeleteMark();
- m_aDelPam.GetPoint()->nNode = m_aNdIdx;
- m_aDelPam.GetPoint()->nContent.Assign( m_pCurTextNd, 0 );
+ *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(TextFrameIndex(0));
SwAutoCorrDoc aACorrDoc( *m_pEditShell, m_aDelPam );
SwTextFrameInfo aFInfo( nullptr );
- sal_Int32 nSttPos, nLastBlank = nPos;
+ TextFrameIndex nSttPos, nLastBlank = nPos;
bool bFirst = m_aFlags.bCapitalStartSentence, bFirstSent = bFirst;
sal_Unicode cChar = 0;
bool bNbspRunNext = false;
@@ -1947,14 +1946,15 @@ void SwAutoFormat::AutoCorrect( sal_Int32 nPos )
CharClass& rAppCC = GetAppCharClass();
do {
- while (nPos < pText->getLength() && IsSpace(cChar = (*pText)[nPos]))
+ while (nPos < TextFrameIndex(pText->getLength())
+ && IsSpace(cChar = (*pText)[sal_Int32(nPos)]))
++nPos;
- if (nPos == pText->getLength())
+ if (nPos == TextFrameIndex(pText->getLength()))
break; // that's it
if( ( ( bReplaceQuote && '\"' == cChar ) ||
( bReplaceSglQuote && '\'' == cChar ) ) &&
- (!nPos || ' ' == (*pText)[nPos-1]))
+ (!nPos || ' ' == (*pText)[sal_Int32(nPos)-1]))
{
// note: special case symbol fonts !!!
@@ -1963,14 +1963,14 @@ void SwAutoFormat::AutoCorrect( sal_Int32 nPos )
if( !aFInfo.IsBullet( nPos ))
{
SetRedlineText( STR_AUTOFMTREDL_TYPO );
- m_aDelPam.GetPoint()->nContent = nPos;
+ *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(nPos);
bool bSetHardBlank = false;
OUString sReplace( pATst->GetQuote( aACorrDoc,
- nPos, cChar, true ));
+ sal_Int32(nPos), cChar, true ));
m_aDelPam.SetMark();
- m_aDelPam.GetPoint()->nContent = nPos+1;
+ m_aDelPam.GetPoint()->nContent = m_aDelPam.GetMark()->nContent.GetIndex() + 1;
if( 2 == sReplace.getLength() && ' ' == sReplace[ 1 ])
{
sReplace = sReplace.copy( 0, 1 );
@@ -1982,12 +1982,13 @@ void SwAutoFormat::AutoCorrect( sal_Int32 nPos )
{
m_aNdIdx = m_aDelPam.GetPoint()->nNode;
m_pCurTextNd = m_aNdIdx.GetNode().GetTextNode();
- pText = &m_pCurTextNd->GetText();
+ m_pCurTextFrame = GetFrame( *m_pCurTextNd );
+ pText = &m_pCurTextFrame->GetText();
m_aDelPam.SetMark();
aFInfo.SetFrame( nullptr );
}
- nPos += sReplace.getLength() - 1;
+ nPos += TextFrameIndex(sReplace.getLength() - 1);
m_aDelPam.DeleteMark();
if( bSetHardBlank )
{
@@ -1999,10 +2000,10 @@ void SwAutoFormat::AutoCorrect( sal_Int32 nPos )
bool bCallACorr = false;
int bBreak = 0;
- if (nPos && IsSpace((*pText)[nPos-1]))
+ if (nPos && IsSpace((*pText)[sal_Int32(nPos) - 1]))
nLastBlank = nPos;
- for (nSttPos = nPos; !bBreak && nPos < pText->getLength(); ++nPos)
- switch (cChar = (*pText)[nPos])
+ for (nSttPos = nPos; !bBreak && nPos < TextFrameIndex(pText->getLength()); ++nPos)
+ switch (cChar = (*pText)[sal_Int32(nPos)])
{
case '\"':
case '\'':
@@ -2015,9 +2016,9 @@ void SwAutoFormat::AutoCorrect( sal_Int32 nPos )
{
SetRedlineText( STR_AUTOFMTREDL_TYPO );
bool bSetHardBlank = false;
- m_aDelPam.GetPoint()->nContent = nPos;
+ *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(nPos);
OUString sReplace( pATst->GetQuote( aACorrDoc,
- nPos, cChar, false ));
+ sal_Int32(nPos), cChar, false) );
if( 2 == sReplace.getLength() && ' ' == sReplace[ 0 ])
{
@@ -2026,27 +2027,29 @@ void SwAutoFormat::AutoCorrect( sal_Int32 nPos )
}
m_aDelPam.SetMark();
- m_aDelPam.GetPoint()->nContent = nPos+1;
+ m_aDelPam.GetPoint()->nContent = m_aDelPam.GetMark()->nContent.GetIndex() + 1;
m_pDoc->getIDocumentContentOperations().ReplaceRange( m_aDelPam, sReplace, false );
if( m_aFlags.bWithRedlining )
{
m_aNdIdx = m_aDelPam.GetPoint()->nNode;
m_pCurTextNd = m_aNdIdx.GetNode().GetTextNode();
- pText = &m_pCurTextNd->GetText();
+ m_pCurTextFrame = GetFrame( *m_pCurTextNd );
+ pText = &m_pCurTextFrame->GetText();
m_aDelPam.SetMark();
m_aDelPam.DeleteMark();
aFInfo.SetFrame( nullptr );
}
- nPos += sReplace.getLength() - 1;
+ nPos += TextFrameIndex(sReplace.getLength() - 1);
m_aDelPam.DeleteMark();
if( bSetHardBlank )
{
- m_aDelPam.GetPoint()->nContent = nPos;
+ *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(nPos);
m_pDoc->getIDocumentContentOperations().InsertString( m_aDelPam, OUString(CHAR_HARDBLANK) );
- m_aDelPam.GetPoint()->nContent = ++nPos;
+ ++nPos;
+ *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(nPos);
}
}
}
@@ -2064,25 +2067,26 @@ void SwAutoFormat::AutoCorrect( sal_Int32 nPos )
? STR_AUTOFMTREDL_BOLD
: STR_AUTOFMTREDL_UNDER );
- sal_Unicode cBlank = nSttPos ? (*pText)[nSttPos - 1] : 0;
- m_aDelPam.GetPoint()->nContent = nPos;
+ sal_Unicode cBlank = nSttPos ? (*pText)[sal_Int32(nSttPos) - 1] : 0;
+ *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(nPos);
- if( pATst->FnChgWeightUnderl( aACorrDoc, *pText, nPos ))
+ if (pATst->FnChgWeightUnderl(aACorrDoc, *pText, sal_Int32(nPos)))
{
if( m_aFlags.bWithRedlining )
{
m_aNdIdx = m_aDelPam.GetPoint()->nNode;
m_pCurTextNd = m_aNdIdx.GetNode().GetTextNode();
- pText = &m_pCurTextNd->GetText();
+ m_pCurTextFrame = GetFrame( *m_pCurTextNd );
+ pText = &m_pCurTextFrame->GetText();
m_aDelPam.SetMark();
m_aDelPam.DeleteMark();
aFInfo.SetFrame( nullptr );
}
//#125102# in case of the mode RedlineFlags::ShowDelete the ** are still contained in pText
if(!(m_pDoc->getIDocumentRedlineAccess().GetRedlineFlags() & RedlineFlags::ShowDelete))
- nPos = m_aDelPam.GetPoint()->nContent.GetIndex() - 1;
+ nPos = m_pCurTextFrame->MapModelToViewPos(*m_aDelPam.GetPoint()) - TextFrameIndex(1);
// Was a character deleted before starting?
- if (cBlank && cBlank != (*pText)[nSttPos - 1])
+ if (cBlank && cBlank != (*pText)[sal_Int32(nSttPos) - 1])
--nSttPos;
}
}
@@ -2092,11 +2096,11 @@ void SwAutoFormat::AutoCorrect( sal_Int32 nPos )
if ( m_aFlags.bAddNonBrkSpace )
{
LanguageType eLang = bGetLanguage
- ? m_pCurTextNd->GetLang( nSttPos )
- : LANGUAGE_SYSTEM;
+ ? m_pCurTextFrame->GetLangOfChar(nSttPos, 0, true)
+ : LANGUAGE_SYSTEM;
SetRedlineText( STR_AUTOFMTREDL_NON_BREAK_SPACE );
- if ( pATst->FnAddNonBrkSpace( aACorrDoc, *pText, nPos, eLang, bNbspRunNext ) )
+ if (pATst->FnAddNonBrkSpace(aACorrDoc, *pText, sal_Int32(nPos), eLang, bNbspRunNext))
--nPos;
}
break;
@@ -2108,7 +2112,7 @@ void SwAutoFormat::AutoCorrect( sal_Int32 nPos )
bFirstSent = true;
SAL_FALLTHROUGH;
default:
- if( !( rAppCC.isLetterNumeric( *pText, nPos )
+ if (!(rAppCC.isLetterNumeric(*pText, sal_Int32(nPos))
|| '/' == cChar )) // '/' should not be a word separator (e.g. '1/2' needs to be handled as one word for replacement)
{
--nPos; // revert ++nPos which was decremented in for loop
@@ -2119,7 +2123,7 @@ void SwAutoFormat::AutoCorrect( sal_Int32 nPos )
if( nPos == nSttPos )
{
- if (++nPos == pText->getLength())
+ if (++nPos == TextFrameIndex(pText->getLength()))
bCallACorr = true;
}
else
@@ -2127,18 +2131,19 @@ void SwAutoFormat::AutoCorrect( sal_Int32 nPos )
if( bCallACorr )
{
- m_aDelPam.GetPoint()->nContent = nPos;
+ *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(nPos);
SetRedlineText( STR_AUTOFMTREDL_USE_REPLACE );
if( m_aFlags.bAutoCorrect &&
- aACorrDoc.ChgAutoCorrWord( nSttPos, nPos, *pATst, nullptr ) )
+ aACorrDoc.ChgAutoCorrWord(reinterpret_cast<sal_Int32&>(nSttPos), sal_Int32(nPos), *pATst, nullptr))
{
- nPos = m_aDelPam.GetPoint()->nContent.GetIndex();
+ nPos = m_pCurTextFrame->MapModelToViewPos(*m_aDelPam.GetPoint()) - TextFrameIndex(1);
if( m_aFlags.bWithRedlining )
{
m_aNdIdx = m_aDelPam.GetPoint()->nNode;
m_pCurTextNd = m_aNdIdx.GetNode().GetTextNode();
- pText = &m_pCurTextNd->GetText();
+ m_pCurTextFrame = GetFrame( *m_pCurTextNd );
+ pText = &m_pCurTextFrame->GetText();
m_aDelPam.SetMark();
m_aDelPam.DeleteMark();
}
@@ -2147,39 +2152,41 @@ void SwAutoFormat::AutoCorrect( sal_Int32 nPos )
}
LanguageType eLang = bGetLanguage
- ? m_pCurTextNd->GetLang( nSttPos )
- : LANGUAGE_SYSTEM;
+ ? m_pCurTextFrame->GetLangOfChar(nSttPos, 0, true)
+ : LANGUAGE_SYSTEM;
if ( m_aFlags.bAddNonBrkSpace )
{
SetRedlineText( STR_AUTOFMTREDL_NON_BREAK_SPACE );
- pATst->FnAddNonBrkSpace( aACorrDoc, *pText, nPos, eLang, bNbspRunNext );
+ pATst->FnAddNonBrkSpace(aACorrDoc, *pText, sal_Int32(nPos), eLang, bNbspRunNext);
}
if( ( m_aFlags.bChgOrdinalNumber &&
SetRedlineText( STR_AUTOFMTREDL_ORDINAL ) &&
- pATst->FnChgOrdinalNumber( aACorrDoc, *pText, nSttPos, nPos, eLang ) ) ||
+ pATst->FnChgOrdinalNumber(aACorrDoc, *pText, sal_Int32(nSttPos), sal_Int32(nPos), eLang)) ||
( m_aFlags.bChgToEnEmDash &&
SetRedlineText( STR_AUTOFMTREDL_DASH ) &&
- pATst->FnChgToEnEmDash( aACorrDoc, *pText, nSttPos, nPos, eLang ) ) ||
+ pATst->FnChgToEnEmDash(aACorrDoc, *pText, sal_Int32(nSttPos), sal_Int32(nPos), eLang)) ||
( m_aFlags.bSetINetAttr &&
- (nPos == pText->getLength() || IsSpace((*pText)[nPos])) &&
+ (nPos == TextFrameIndex(pText->getLength()) || IsSpace((*pText)[sal_Int32(nPos)])) &&
SetRedlineText( STR_AUTOFMTREDL_DETECT_URL ) &&
- pATst->FnSetINetAttr( aACorrDoc, *pText, nLastBlank, nPos, eLang ) ) )
- nPos = m_aDelPam.GetPoint()->nContent.GetIndex();
+ pATst->FnSetINetAttr(aACorrDoc, *pText, sal_Int32(nLastBlank), sal_Int32(nPos), eLang)))
+ {
+ nPos = m_pCurTextFrame->MapModelToViewPos(*m_aDelPam.GetPoint()) - TextFrameIndex(1);
+ }
else
{
// two capital letters at the beginning of a word?
if( m_aFlags.bCapitalStartWord )
{
SetRedlineText( STR_AUTOFMTREDL_CPTL_STT_WORD );
- pATst->FnCapitalStartWord( aACorrDoc, *pText, nSttPos, nPos, eLang );
+ pATst->FnCapitalStartWord(aACorrDoc, *pText, sal_Int32(nSttPos), sal_Int32(nPos), eLang);
}
// capital letter at the beginning of a sentence?
if( m_aFlags.bCapitalStartSentence && bFirst )
{
SetRedlineText( STR_AUTOFMTREDL_CPTL_STT_SENT );
- pATst->FnCapitalStartSentence( aACorrDoc, *pText, true, nSttPos, nPos, eLang);
+ pATst->FnCapitalStartSentence(aACorrDoc, *pText, true, sal_Int32(nSttPos), sal_Int32(nPos), eLang);
}
bFirst = bFirstSent;
@@ -2189,13 +2196,15 @@ void SwAutoFormat::AutoCorrect( sal_Int32 nPos )
{
m_aNdIdx = m_aDelPam.GetPoint()->nNode;
m_pCurTextNd = m_aNdIdx.GetNode().GetTextNode();
- pText = &m_pCurTextNd->GetText();
+ m_pCurTextFrame = GetFrame( *m_pCurTextNd );
+ pText = &m_pCurTextFrame->GetText();
m_aDelPam.SetMark();
m_aDelPam.DeleteMark();
}
}
}
- } while (nPos < pText->getLength());
+ }
+ while (nPos < TextFrameIndex(pText->getLength()));
ClearRedlineText();
}
commit dbfe996e39cf2834f62d5334046a997079950997
Author: Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Wed Nov 28 15:51:02 2018 +0100
Commit: Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Sat Dec 1 08:43:01 2018 +0100
sw_redlinehide_4a: SwAutoCorrDoc iterates frames, not nodes
Adapt this in a similar way, with a DeleteSel() that skips over
delete redlines.
The Replace functions fortunately only have callers that replace 1
character currently, but there is another ReplaceRange() call that
needs a litte more complicated handling.
Change-Id: Idd5c80e96c0f355d3dc965b2f70376258d23e1a3
diff --git a/sw/source/core/edit/acorrect.cxx b/sw/source/core/edit/acorrect.cxx
index a78c94942ec8..e5ca4d63c69b 100644
--- a/sw/source/core/edit/acorrect.cxx
+++ b/sw/source/core/edit/acorrect.cxx
@@ -27,6 +27,8 @@
#include <editsh.hxx>
#include <doc.hxx>
#include <pam.hxx>
+#include <unocrsr.hxx>
+#include <txtfrm.hxx>
#include <ndtxt.hxx>
#include <acorrect.hxx>
#include <shellio.hxx>
@@ -100,12 +102,32 @@ SwAutoCorrDoc::~SwAutoCorrDoc()
void SwAutoCorrDoc::DeleteSel( SwPaM& rDelPam )
{
+ // this should work with plain SwPaM as well because start and end
+ // are always in same node, but since there is GetRanges already...
+ std::vector<std::shared_ptr<SwUnoCursor>> ranges;
+ if (sw::GetRanges(ranges, *rEditSh.GetDoc(), rDelPam))
+ {
+ DeleteSelImpl(rDelPam);
+ }
+ else
+ {
+ for (auto const& pCursor : ranges)
+ {
+ DeleteSelImpl(*pCursor);
+ }
+ }
+}
+
+void SwAutoCorrDoc::DeleteSelImpl(SwPaM & rDelPam)
+{
SwDoc* pDoc = rEditSh.GetDoc();
if( pDoc->IsAutoFormatRedline() )
{
// so that also the DelPam be moved, include it in the
// Shell-Cursr-Ring !!
- PaMIntoCursorShellRing aTmp( rEditSh, rCursor, rDelPam );
+ // ??? is that really necessary - this should never join nodes, so Update should be enough?
+// PaMIntoCursorShellRing aTmp( rEditSh, rCursor, rDelPam );
+ assert(rDelPam.GetPoint()->nNode == rDelPam.GetMark()->nNode);
pDoc->getIDocumentContentOperations().DeleteAndJoin( rDelPam );
}
else
@@ -116,8 +138,12 @@ void SwAutoCorrDoc::DeleteSel( SwPaM& rDelPam )
bool SwAutoCorrDoc::Delete( sal_Int32 nStt, sal_Int32 nEnd )
{
- const SwNodeIndex& rNd = rCursor.GetPoint()->nNode;
- SwPaM aSel( rNd, nStt, rNd, nEnd );
+ SwTextNode const*const pTextNd = rCursor.GetNode().GetTextNode();
+ SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(
+ pTextNd->getLayoutFrame(rEditSh.GetLayout())));
+ assert(pFrame);
+ SwPaM aSel(pFrame->MapViewToModelPos(TextFrameIndex(nStt)),
+ pFrame->MapViewToModelPos(TextFrameIndex(nEnd)));
DeleteSel( aSel );
if( bUndoIdInitialized )
@@ -127,7 +153,11 @@ bool SwAutoCorrDoc::Delete( sal_Int32 nStt, sal_Int32 nEnd )
bool SwAutoCorrDoc::Insert( sal_Int32 nPos, const OUString& rText )
{
- SwPaM aPam( rCursor.GetPoint()->nNode.GetNode(), nPos );
+ SwTextNode const*const pTextNd = rCursor.GetNode().GetTextNode();
+ SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(
+ pTextNd->getLayoutFrame(rEditSh.GetLayout())));
+ assert(pFrame);
+ SwPaM aPam(pFrame->MapViewToModelPos(TextFrameIndex(nPos)));
rEditSh.GetDoc()->getIDocumentContentOperations().InsertString( aPam, rText );
if( !bUndoIdInitialized )
{
@@ -148,28 +178,43 @@ bool SwAutoCorrDoc::Replace( sal_Int32 nPos, const OUString& rText )
bool SwAutoCorrDoc::ReplaceRange( sal_Int32 nPos, sal_Int32 nSourceLength, const OUString& rText )
{
- SwPaM* pPam = &rCursor;
- if( pPam->GetPoint()->nContent.GetIndex() != nPos )
+ assert(nSourceLength == 1); // sw_redlinehide: this is currently the case,
+ // and ensures that the replace range cannot *contain* delete redlines,
+ // so we don't need something along the lines of:
+ // if (sw::GetRanges(ranges, *rEditSh.GetDoc(), aPam))
+ // ReplaceImpl(...)
+ // else
+ // ReplaceImpl(ranges.begin())
+ // for (ranges.begin() + 1; ranges.end(); )
+ // DeleteImpl(*it)
+
+ SwTextNode * const pNd = rCursor.GetNode().GetTextNode();
+ if ( !pNd )
{
- pPam = new SwPaM( *rCursor.GetPoint() );
- pPam->GetPoint()->nContent = nPos;
+ return false;
}
- SwTextNode * const pNd = pPam->GetNode().GetTextNode();
- if ( !pNd )
+ SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(
+ pNd->getLayoutFrame(rEditSh.GetLayout())));
+ assert(pFrame);
+ std::pair<SwTextNode *, sal_Int32> const pos(pFrame->MapViewToModel(TextFrameIndex(nPos)));
+
+ SwPaM* pPam = &rCursor;
+ if (pPam->GetPoint()->nNode != *pos.first
+ || pPam->GetPoint()->nContent != pos.second)
{
- return false;
+ pPam = new SwPaM(*pos.first, pos.second);
}
// text attributes with dummy characters must not be replaced!
bool bDoReplace = true;
sal_Int32 const nLen = rText.getLength();
- for ( sal_Int32 n = 0; n < nLen && n + nPos < pNd->GetText().getLength(); ++n )
+ for (sal_Int32 n = 0; n < nLen && n + nPos < pFrame->GetText().getLength(); ++n)
{
- sal_Unicode const Char = pNd->GetText()[n + nPos];
- if ( ( CH_TXTATR_BREAKWORD == Char || CH_TXTATR_INWORD == Char )
- && pNd->GetTextAttrForCharAt( n + nPos ) )
+ sal_Unicode const Char = pFrame->GetText()[n + nPos];
+ if (CH_TXTATR_BREAKWORD == Char || CH_TXTATR_INWORD == Char)
{
+ assert(pFrame->MapViewToModel(TextFrameIndex(n+nPos)).first->GetTextAttrForCharAt(pFrame->MapViewToModel(TextFrameIndex(n+nPos)).second));
bDoReplace = false;
break;
}
@@ -181,17 +226,18 @@ bool SwAutoCorrDoc::ReplaceRange( sal_Int32 nPos, sal_Int32 nSourceLength, const
if( pDoc->IsAutoFormatRedline() )
{
- if (nPos == pNd->GetText().getLength()) // at the End do an Insert
+ if (nPos == pFrame->GetText().getLength()) // at the End do an Insert
{
pDoc->getIDocumentContentOperations().InsertString( *pPam, rText );
}
else
{
+ assert(pos.second != pos.first->Len()); // must be _before_ char
PaMIntoCursorShellRing aTmp( rEditSh, rCursor, *pPam );
pPam->SetMark();
pPam->GetPoint()->nContent = std::min<sal_Int32>(
- pNd->GetText().getLength(), nPos + nSourceLength);
+ pos.first->GetText().getLength(), pos.second + nSourceLength);
pDoc->getIDocumentContentOperations().ReplaceRange( *pPam, rText, false );
pPam->Exchange();
pPam->DeleteMark();
@@ -203,7 +249,7 @@ bool SwAutoCorrDoc::ReplaceRange( sal_Int32 nPos, sal_Int32 nSourceLength, const
{
pPam->SetMark();
pPam->GetPoint()->nContent = std::min<sal_Int32>(
- pNd->GetText().getLength(), nPos + nSourceLength);
+ pos.first->GetText().getLength(), pos.second + nSourceLength);
pDoc->getIDocumentContentOperations().ReplaceRange( *pPam, rText, false );
pPam->Exchange();
pPam->DeleteMark();
@@ -232,8 +278,12 @@ bool SwAutoCorrDoc::ReplaceRange( sal_Int32 nPos, sal_Int32 nSourceLength, const
void SwAutoCorrDoc::SetAttr( sal_Int32 nStt, sal_Int32 nEnd, sal_uInt16 nSlotId,
SfxPoolItem& rItem )
{
- const SwNodeIndex& rNd = rCursor.GetPoint()->nNode;
- SwPaM aPam( rNd, nStt, rNd, nEnd );
+ SwTextNode const*const pTextNd = rCursor.GetNode().GetTextNode();
+ SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(
+ pTextNd->getLayoutFrame(rEditSh.GetLayout())));
+ assert(pFrame);
+ SwPaM aPam(pFrame->MapViewToModelPos(TextFrameIndex(nStt)),
+ pFrame->MapViewToModelPos(TextFrameIndex(nEnd)));
SfxItemPool& rPool = rEditSh.GetDoc()->GetAttrPool();
sal_uInt16 nWhich = rPool.GetWhich( nSlotId, false );
@@ -253,8 +303,12 @@ void SwAutoCorrDoc::SetAttr( sal_Int32 nStt, sal_Int32 nEnd, sal_uInt16 nSlotId,
bool SwAutoCorrDoc::SetINetAttr( sal_Int32 nStt, sal_Int32 nEnd, const OUString& rURL )
{
- const SwNodeIndex& rNd = rCursor.GetPoint()->nNode;
- SwPaM aPam( rNd, nStt, rNd, nEnd );
+ SwTextNode const*const pTextNd = rCursor.GetNode().GetTextNode();
+ SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(
+ pTextNd->getLayoutFrame(rEditSh.GetLayout())));
+ assert(pFrame);
+ SwPaM aPam(pFrame->MapViewToModelPos(TextFrameIndex(nStt)),
+ pFrame->MapViewToModelPos(TextFrameIndex(nEnd)));
SfxItemSet aSet( rEditSh.GetDoc()->GetAttrPool(),
svl::Items<RES_TXTATR_INETFMT, RES_TXTATR_INETFMT>{} );
@@ -276,18 +330,25 @@ OUString const* SwAutoCorrDoc::GetPrevPara(bool const bAtNormalPos)
OUString const* pStr(nullptr);
if( bAtNormalPos || !pIdx )
- pIdx.reset(new SwNodeIndex( rCursor.GetPoint()->nNode, -1 ));
- else
- --(*pIdx);
+ {
+ pIdx.reset(new SwNodeIndex(rCursor.GetPoint()->nNode));
+ }
+ sw::GotoPrevLayoutTextFrame(*pIdx, rEditSh.GetLayout());
- SwTextNode* pTNd = pIdx->GetNode().GetTextNode();
- while (pTNd && !pTNd->GetText().getLength())
+ SwTextFrame const* pFrame(nullptr);
+ for (SwTextNode * pTextNd = pIdx->GetNode().GetTextNode();
+ pTextNd; pTextNd = pIdx->GetNode().GetTextNode())
{
- --(*pIdx);
- pTNd = pIdx->GetNode().GetTextNode();
+ pFrame = static_cast<SwTextFrame const*>(
+ pTextNd->getLayoutFrame(rEditSh.GetLayout()));
+ if (pFrame && !pFrame->GetText().isEmpty())
+ {
+ break;
+ }
+ sw::GotoPrevLayoutTextFrame(*pIdx, rEditSh.GetLayout());
}
- if( pTNd && 0 == pTNd->GetAttrOutlineLevel() )
- pStr = & pTNd->GetText();
+ if (pFrame && 0 == pFrame->GetTextNodeForParaProps()->GetAttrOutlineLevel())
+ pStr = & pFrame->GetText();
if( bUndoIdInitialized )
bUndoIdInitialized = true;
@@ -316,20 +377,24 @@ bool SwAutoCorrDoc::ChgAutoCorrWord( sal_Int32& rSttPos, sal_Int32 nEndPos,
eLang = GetAppLanguage();
LanguageTag aLanguageTag( eLang);
+ SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(
+ pTextNd->getLayoutFrame(rEditSh.GetLayout())));
+ assert(pFrame);
+
//JP 22.04.99: Bug 63883 - Special treatment for dots.
- bool bLastCharIsPoint = nEndPos < pTextNd->GetText().getLength() &&
- ('.' == pTextNd->GetText()[nEndPos]);
+ bool bLastCharIsPoint = nEndPos < pFrame->GetText().getLength() &&
+ ('.' == pFrame->GetText()[nEndPos]);
const SvxAutocorrWord* pFnd = rACorrect.SearchWordsInList(
- pTextNd->GetText(), rSttPos, nEndPos, *this, aLanguageTag );
+ pFrame->GetText(), rSttPos, nEndPos, *this, aLanguageTag);
SwDoc* pDoc = rEditSh.GetDoc();
if( pFnd )
{
// replace also last colon of keywords surrounded by colons (for example, ":name:")
bool replaceLastChar = pFnd->GetShort()[0] == ':' && pFnd->GetShort().endsWith(":");
- const SwNodeIndex& rNd = rCursor.GetPoint()->nNode;
- SwPaM aPam( rNd, rSttPos, rNd, nEndPos + (replaceLastChar ? 1 : 0) );
+ SwPaM aPam(pFrame->MapViewToModelPos(TextFrameIndex(rSttPos)),
+ pFrame->MapViewToModelPos(TextFrameIndex(nEndPos + (replaceLastChar ? 1 : 0))));
if( pFnd->IsTextOnly() )
{
@@ -338,7 +403,23 @@ bool SwAutoCorrDoc::ChgAutoCorrWord( sal_Int32& rSttPos, sal_Int32 nEndPos,
'.' != pFnd->GetLong()[ pFnd->GetLong().getLength() - 1 ] )
{
// replace the selection
- pDoc->getIDocumentContentOperations().ReplaceRange( aPam, pFnd->GetLong(), false);
+ std::vector<std::shared_ptr<SwUnoCursor>> ranges;
+ if (sw::GetRanges(ranges, *rEditSh.GetDoc(), aPam))
+ {
+ pDoc->getIDocumentContentOperations().ReplaceRange(aPam, pFnd->GetLong(), false);
+ }
+ else
+ {
+ assert(!ranges.empty());
+ assert(ranges.front()->GetPoint()->nNode == ranges.front()->GetMark()->nNode);
+ pDoc->getIDocumentContentOperations().ReplaceRange(
+ *ranges.front(), pFnd->GetLong(), false);
+ for (auto it = ranges.begin() + 1; it != ranges.end(); ++it)
+ {
+ DeleteSel(**it);
+ }
+ }
+
// tdf#83260 After calling sw::DocumentContentOperationsManager::ReplaceRange
// pTextNd may become invalid when change tracking is on and Edit -> Track Changes -> Show == OFF.
// ReplaceRange shows changes, this moves deleted nodes from special section to document.
@@ -360,7 +441,8 @@ bool SwAutoCorrDoc::ChgAutoCorrWord( sal_Int32& rSttPos, sal_Int32 nEndPos,
if( pPara )
{
OSL_ENSURE( !pIdx, "who has not deleted his Index?" );
- pIdx.reset(new SwNodeIndex( rCursor.GetPoint()->nNode, -1 ));
+ pIdx.reset(new SwNodeIndex( rCursor.GetPoint()->nNode ));
+ sw::GotoPrevLayoutTextFrame(*pIdx, rEditSh.GetLayout());
}
SwDoc* pAutoDoc = aTBlks.GetDoc();
@@ -391,7 +473,7 @@ bool SwAutoCorrDoc::ChgAutoCorrWord( sal_Int32& rSttPos, sal_Int32 nEndPos,
if( pPara )
{
- ++(*pIdx);
+ sw::GotoNextLayoutTextFrame(*pIdx, rEditSh.GetLayout());
pTextNd = pIdx->GetNode().GetTextNode();
}
bRet = true;
@@ -401,7 +483,11 @@ bool SwAutoCorrDoc::ChgAutoCorrWord( sal_Int32& rSttPos, sal_Int32 nEndPos,
}
if( bRet && pPara && pTextNd )
- *pPara = pTextNd->GetText();
+ {
+ SwTextFrame const*const pNewFrame(static_cast<SwTextFrame const*>(
+ pTextNd->getLayoutFrame(rEditSh.GetLayout())));
+ *pPara = pNewFrame->GetText();
+ }
return bRet;
}
@@ -428,7 +514,12 @@ LanguageType SwAutoCorrDoc::GetLanguage( sal_Int32 nPos ) const
SwTextNode* pNd = rCursor.GetPoint()->nNode.GetNode().GetTextNode();
if( pNd )
- eRet = pNd->GetLang( nPos );
+ {
+ SwTextFrame const*const pFrame(static_cast<SwTextFrame const*>(
+ pNd->getLayoutFrame(rEditSh.GetLayout())));
+ assert(pFrame);
+ eRet = pFrame->GetLangOfChar(TextFrameIndex(nPos), 0, true);
+ }
if(LANGUAGE_SYSTEM == eRet)
eRet = GetAppLanguage();
return eRet;
diff --git a/sw/source/core/edit/autofmt.cxx b/sw/source/core/edit/autofmt.cxx
index 63abe15f4ca2..ea6a4dc797b1 100644
--- a/sw/source/core/edit/autofmt.cxx
+++ b/sw/source/core/edit/autofmt.cxx
@@ -1119,6 +1119,8 @@ void SwAutoFormat::DeleteLeadingTrailingBlanks(bool bStart, bool bEnd)
}
}
+namespace sw {
+
bool GetRanges(std::vector<std::shared_ptr<SwUnoCursor>> & rRanges,
SwDoc & rDoc, SwPaM const& rDelPam)
{
@@ -1164,6 +1166,8 @@ bool GetRanges(std::vector<std::shared_ptr<SwUnoCursor>> & rRanges,
return isNoRedline;
}
+} // namespace sw
+
void SwAutoFormat::DeleteSel(SwPaM & rDelPam)
{
std::vector<std::shared_ptr<SwUnoCursor>> ranges; // need correcting cursor
diff --git a/sw/source/core/inc/acorrect.hxx b/sw/source/core/inc/acorrect.hxx
index f14edf751681..73f63c1ebac8 100644
--- a/sw/source/core/inc/acorrect.hxx
+++ b/sw/source/core/inc/acorrect.hxx
@@ -21,10 +21,14 @@
#define INCLUDED_SW_SOURCE_CORE_INC_ACORRECT_HXX
#include <memory>
+#include <vector>
+
#include <tools/solar.h>
#include <editeng/svxacorr.hxx>
#include <swundo.hxx>
+class SwDoc;
+class SwUnoCursor;
class SwEditShell;
class SwPaM;
class SwNodeIndex;
@@ -53,6 +57,7 @@ class SwAutoCorrDoc : public SvxAutoCorrDoc
bool bUndoIdInitialized;
void DeleteSel( SwPaM& rDelPam );
+ void DeleteSelImpl(SwPaM & rDelPam);
public:
SwAutoCorrDoc( SwEditShell& rEditShell, SwPaM& rPam, sal_Unicode cIns = 0 );
@@ -111,6 +116,13 @@ public:
bool CheckDelChar(const SwPosition& rPos);
};
+namespace sw {
+
+bool GetRanges(std::vector<std::shared_ptr<SwUnoCursor>> & rRanges,
+ SwDoc & rDoc, SwPaM const& rDelPam);
+
+} // namespace sw
+
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 183c36bc26032fc5f0f89929b83357a2f899ba73
Author: Michael Stahl <Michael.Stahl at cib.de>
AuthorDate: Tue Nov 27 18:28:41 2018 +0100
Commit: Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Sat Dec 1 08:43:01 2018 +0100
sw_redlinehide_4a: SwAutoFormat iterates frames, not nodes
In order to not require moving the delete redlines out of the document
body, rely on the DeleteSel() implementation skipping over the redlines,
and also pass the shell's layout to the various SwDoc functions that
are called.
Previously, the redlines were not deleted by DeleteSel() due to
SwAutoFormat setting RedlineFlags::Ignore.
Change-Id: Ib05ecb534993368d81f66e70124617968b4c8e9a
diff --git a/sw/source/core/doc/docfmt.cxx b/sw/source/core/doc/docfmt.cxx
index 0b7d3a170ba1..253da644837f 100644
--- a/sw/source/core/doc/docfmt.cxx
+++ b/sw/source/core/doc/docfmt.cxx
@@ -1803,6 +1803,9 @@ void SwDoc::SetTextFormatCollByAutoFormat( const SwPosition& rPos, sal_uInt16 nP
{
aPam.SetMark();
aPam.GetMark()->nContent.Assign(pTNd, pTNd->GetText().getLength());
+ // sw_redlinehide: don't need layout currently because the only caller
+ // passes in the properties node
+ assert(static_cast<SwTextFrame const*>(pTNd->getLayoutFrame(nullptr))->GetTextNodeForParaProps() == pTNd);
getIDocumentContentOperations().InsertItemSet( aPam, *pSet );
}
}
diff --git a/sw/source/core/edit/autofmt.cxx b/sw/source/core/edit/autofmt.cxx
index 471bc982d674..63abe15f4ca2 100644
--- a/sw/source/core/edit/autofmt.cxx
+++ b/sw/source/core/edit/autofmt.cxx
@@ -135,34 +135,37 @@ class SwAutoFormat
{ return (' ' == c || '\t' == c || 0x0a == c|| 0x3000 == c /* Jap. space */); }
void SetColl( sal_uInt16 nId, bool bHdLineOrText = false );
- OUString GoNextPara();
- bool HasObjects( const SwNode& rNd );
+ void GoNextPara();
+ bool HasObjects(const SwTextFrame &);
// TextNode methods
- const SwTextNode* GetNextNode() const;
- static bool IsEmptyLine( const SwTextNode& rNd )
- { return rNd.GetText().isEmpty() ||
- rNd.GetText().getLength() == GetLeadingBlanks( rNd.GetText() ); }
-
- bool IsOneLine( const SwTextNode& ) const;
- bool IsFastFullLine( const SwTextNode& ) const;
- bool IsNoAlphaLine( const SwTextNode&) const;
- bool IsEnumericChar( const SwTextNode&) const;
- static bool IsBlanksInString( const SwTextNode&);
- sal_uInt16 CalcLevel( const SwTextNode&, sal_uInt16 *pDigitLvl = nullptr ) const;
- sal_Int32 GetBigIndent( sal_Int32& rCurrentSpacePos ) const;
+ const SwTextFrame * GetNextNode(bool isCheckEnd = true) const;
+ static bool IsEmptyLine(const SwTextFrame & rFrame)
+ {
+ return rFrame.GetText().isEmpty()
+ || rFrame.GetText().getLength() == GetLeadingBlanks(rFrame.GetText());
+ }
+
+ bool IsOneLine(const SwTextFrame &) const;
+ bool IsFastFullLine(const SwTextFrame &) const;
+ bool IsNoAlphaLine(const SwTextFrame &) const;
+ bool IsEnumericChar(const SwTextFrame &) const;
+ static bool IsBlanksInString(const SwTextFrame&);
+ sal_uInt16 CalcLevel(const SwTextFrame&, sal_uInt16 *pDigitLvl = nullptr) const;
+ sal_Int32 GetBigIndent(TextFrameIndex & rCurrentSpacePos) const;
static OUString DelLeadingBlanks(const OUString& rStr);
static OUString DelTrailingBlanks( const OUString& rStr );
static sal_Int32 GetLeadingBlanks( const OUString& rStr );
static sal_Int32 GetTrailingBlanks( const OUString& rStr );
- bool IsFirstCharCapital( const SwTextNode& rNd ) const;
- sal_uInt16 GetDigitLevel( const SwTextNode& rTextNd, sal_Int32& rPos,
+ bool IsFirstCharCapital(const SwTextFrame & rNd) const;
+ sal_uInt16 GetDigitLevel(const SwTextFrame& rFrame, TextFrameIndex& rPos,
OUString* pPrefix = nullptr, OUString* pPostfix = nullptr,
OUString* pNumTypes = nullptr ) const;
/// get the FORMATTED TextFrame
SwTextFrame* GetFrame( const SwTextNode& rTextNd ) const;
+ SwTextFrame * EnsureFormatted(SwTextFrame const&) const;
void BuildIndent();
void BuildText();
@@ -171,11 +174,10 @@ class SwAutoFormat
void BuildNegIndent( SwTwips nSpaces );
void BuildHeadLine( sal_uInt16 nLvl );
- static bool HasSelBlanks( SwPaM& rPam );
- static bool HasBreakAttr( const SwTextNode& );
+ static bool HasBreakAttr(const SwTextFrame &);
void DeleteSel( SwPaM& rPam );
void DeleteSelImpl(SwPaM & rDelPam, SwPaM & rPamToCorrect);
- bool DeleteJoinCurNextPara( const OUString& rNxtPara );
+ bool DeleteJoinCurNextPara(SwTextFrame const* pNextFrame, bool bIgnoreLeadingBlanks = false);
/// delete in the node start and/or end
void DeleteLeadingTrailingBlanks( bool bStart = true, bool bEnd = true );
void DelEmptyLine( bool bTstNextPara = true );
@@ -187,19 +189,22 @@ class SwAutoFormat
/// execute AutoCorrect on current TextNode
void AutoCorrect( sal_Int32 nSttPos = 0 );
- bool CanJoin( const SwTextNode* pTextNd ) const
+ bool CanJoin(const SwTextFrame * pNextFrame) const
{
- return !m_bEnd && pTextNd &&
- !IsEmptyLine( *pTextNd ) &&
- !IsNoAlphaLine( *pTextNd) &&
- !IsEnumericChar( *pTextNd ) &&
- ((COMPLETE_STRING - 50 - pTextNd->GetText().getLength()) >
- m_pCurTextNd->GetText().getLength()) &&
- !HasBreakAttr( *pTextNd );
+ return !m_bEnd && pNextFrame
+ && !IsEmptyLine(*pNextFrame)
+ && !IsNoAlphaLine(*pNextFrame)
+ && !IsEnumericChar(*pNextFrame)
+ // check the last / first nodes here...
+ && ((COMPLETE_STRING - 50 - pNextFrame->GetTextNodeFirst()->GetText().getLength())
+ > (m_pCurTextFrame->GetMergedPara()
+ ? m_pCurTextFrame->GetMergedPara()->pLastNode
+ : m_pCurTextNd)->GetText().getLength())
+ && !HasBreakAttr(*pNextFrame);
}
/// is a dot at the end ??
- static bool IsSentenceAtEnd( const SwTextNode& rTextNd );
+ static bool IsSentenceAtEnd(const SwTextFrame & rTextFrame);
bool DoUnderline();
bool DoTable();
@@ -231,23 +236,28 @@ SwTextFrame* SwAutoFormat::GetFrame( const SwTextNode& rTextNd ) const
{
// get the Frame
const SwContentFrame *pFrame = rTextNd.getLayoutFrame( m_pEditShell->GetLayout() );
- OSL_ENSURE( pFrame, "For Autoformat a Layout is needed" );
+ assert(pFrame && "For Autoformat a Layout is needed");
+ return EnsureFormatted(*static_cast<SwTextFrame const*>(pFrame));
+}
+SwTextFrame * SwAutoFormat::EnsureFormatted(SwTextFrame const& rFrame) const
+{
+ SwTextFrame *const pFrame(const_cast<SwTextFrame*>(&rFrame));
if( m_aFlags.bAFormatByInput && !pFrame->isFrameAreaDefinitionValid() )
{
- DisableCallbackAction a(const_cast<SwRootFrame&>(*pFrame->getRootFrame()));
+ DisableCallbackAction a(*pFrame->getRootFrame());
SwRect aTmpFrame( pFrame->getFrameArea() );
SwRect aTmpPrt( pFrame->getFramePrintArea() );
pFrame->Calc(pFrame->getRootFrame()->GetCurrShell()->GetOut());
if( pFrame->getFrameArea() != aTmpFrame || pFrame->getFramePrintArea() != aTmpPrt ||
- ( pFrame->IsTextFrame() && !const_cast<SwTextFrame*>(static_cast<const SwTextFrame*>(pFrame))->GetPaintSwRect().IsEmpty() ) )
+ !pFrame->GetPaintSwRect().IsEmpty())
{
pFrame->SetCompletePaint();
}
}
- return const_cast<SwTextFrame*>(static_cast<const SwTextFrame*>(pFrame))->GetFormatted();
+ return pFrame->GetFormatted();
}
void SwAutoFormat::SetRedlineText_( sal_uInt16 nActionId )
@@ -285,7 +295,7 @@ void SwAutoFormat::SetRedlineText_( sal_uInt16 nActionId )
m_pDoc->GetDocumentRedlineManager().SetAutoFormatRedlineComment( &sText, nSeqNo );
}
-OUString SwAutoFormat::GoNextPara()
+void SwAutoFormat::GoNextPara()
{
SwNode* pNewNd = nullptr;
do {
@@ -293,14 +303,14 @@ OUString SwAutoFormat::GoNextPara()
if( m_aNdIdx.GetIndex() >= m_aEndNdIdx.GetIndex() )
{
m_bEnd = true;
- return OUString();
+ return;
}
- ++m_aNdIdx;
+ sw::GotoNextLayoutTextFrame(m_aNdIdx, m_pEditShell->GetLayout());
if( m_aNdIdx.GetIndex() >= m_aEndNdIdx.GetIndex() )
{
m_bEnd = true;
- return OUString();
+ return;
}
else
pNewNd = &m_aNdIdx.GetNode();
@@ -312,7 +322,7 @@ OUString SwAutoFormat::GoNextPara()
if( pNewNd->IsEndNode() )
{
m_bEnd = true;
- return OUString();
+ return;
}
else if( pNewNd->IsTableNode() )
m_aNdIdx = *pNewNd->EndOfSectionNode();
@@ -330,10 +340,9 @@ OUString SwAutoFormat::GoNextPara()
m_pCurTextNd = static_cast<SwTextNode*>(pNewNd);
m_pCurTextFrame = GetFrame( *m_pCurTextNd );
- return m_pCurTextNd->GetText();
}
-bool SwAutoFormat::HasObjects( const SwNode& rNd )
+bool SwAutoFormat::HasObjects(const SwTextFrame & rFrame)
{
// Is there something bound to the paragraph in the paragraph
// like Frames, DrawObjects, ...
@@ -344,7 +353,7 @@ bool SwAutoFormat::HasObjects( const SwNode& rNd )
const SwFormatAnchor& rAnchor = pFrameFormat->GetAnchor();
if ((RndStdIds::FLY_AT_PAGE != rAnchor.GetAnchorId()) &&
rAnchor.GetContentAnchor() &&
- &rAnchor.GetContentAnchor()->nNode.GetNode() == &rNd )
+ sw::FrameContainsNode(rFrame, rAnchor.GetContentAnchor()->nNode.GetIndex()))
{
bRet = true;
break;
@@ -353,57 +362,61 @@ bool SwAutoFormat::HasObjects( const SwNode& rNd )
return bRet;
}
-const SwTextNode* SwAutoFormat::GetNextNode() const
+const SwTextFrame* SwAutoFormat::GetNextNode(bool const isCheckEnd) const
{
- if( m_aNdIdx.GetIndex()+1 >= m_aEndNdIdx.GetIndex() )
+ SwNodeIndex tmp(m_aNdIdx);
+ sw::GotoNextLayoutTextFrame(tmp, m_pEditShell->GetLayout());
+ if ((isCheckEnd && m_aEndNdIdx <= tmp) || !tmp.GetNode().IsTextNode())
return nullptr;
- return m_pDoc->GetNodes()[ m_aNdIdx.GetIndex() + 1 ]->GetTextNode();
+ // note: the returned frame is not necessarily formatted, have to call
+ // EnsureFormatted for that
+ return static_cast<SwTextFrame*>(tmp.GetNode().GetTextNode()->getLayoutFrame(m_pEditShell->GetLayout()));
}
-bool SwAutoFormat::IsOneLine( const SwTextNode& rNd ) const
+bool SwAutoFormat::IsOneLine(const SwTextFrame & rFrame) const
{
- SwTextFrameInfo aFInfo( GetFrame( rNd ) );
+ SwTextFrameInfo aFInfo( EnsureFormatted(rFrame) );
return aFInfo.IsOneLine();
}
-bool SwAutoFormat::IsFastFullLine( const SwTextNode& rNd ) const
+bool SwAutoFormat::IsFastFullLine(const SwTextFrame & rFrame) const
{
bool bRet = m_aFlags.bRightMargin;
if( bRet )
{
- SwTextFrameInfo aFInfo( GetFrame( rNd ) );
+ SwTextFrameInfo aFInfo( EnsureFormatted(rFrame) );
bRet = aFInfo.IsFilled( m_aFlags.nRightMargin );
}
return bRet;
}
-bool SwAutoFormat::IsEnumericChar( const SwTextNode& rNd ) const
+bool SwAutoFormat::IsEnumericChar(const SwTextFrame& rFrame) const
{
- const OUString& rText = rNd.GetText();
- sal_Int32 nBlnks = GetLeadingBlanks( rText );
- const sal_Int32 nLen = rText.getLength() - nBlnks;
+ const OUString& rText = rFrame.GetText();
+ TextFrameIndex nBlanks(GetLeadingBlanks(rText));
+ const TextFrameIndex nLen = TextFrameIndex(rText.getLength()) - nBlanks;
if( !nLen )
return false;
// -, +, * separated by blank ??
- if (2 < nLen && IsSpace(rText[nBlnks + 1]))
+ if (TextFrameIndex(2) < nLen && IsSpace(rText[sal_Int32(nBlanks) + 1]))
{
- if (StrChr(pBulletChar, rText[nBlnks]))
+ if (StrChr(pBulletChar, rText[sal_Int32(nBlanks)]))
return true;
// Should there be a symbol font at the position?
- SwTextFrameInfo aFInfo( GetFrame( rNd ) );
- if( aFInfo.IsBullet( nBlnks ))
+ SwTextFrameInfo aFInfo( EnsureFormatted(rFrame) );
+ if (aFInfo.IsBullet(nBlanks))
return true;
}
// 1.) / 1. / 1.1.1 / (1). / (1) / ....
- return USHRT_MAX != GetDigitLevel( rNd, nBlnks );
+ return USHRT_MAX != GetDigitLevel(rFrame, nBlanks);
}
-bool SwAutoFormat::IsBlanksInString( const SwTextNode& rNd )
+bool SwAutoFormat::IsBlanksInString(const SwTextFrame& rFrame)
{
// Search more than 5 consecutive blanks/tabs in the string.
- OUString sTmp( DelLeadingBlanks(rNd.GetText()) );
+ OUString sTmp( DelLeadingBlanks(rFrame.GetText()) );
const sal_Int32 nLen = sTmp.getLength();
sal_Int32 nIdx = 0;
while (nIdx < nLen)
@@ -422,14 +435,15 @@ bool SwAutoFormat::IsBlanksInString( const SwTextNode& rNd )
return false;
}
-sal_uInt16 SwAutoFormat::CalcLevel( const SwTextNode& rNd, sal_uInt16 *pDigitLvl ) const
+sal_uInt16 SwAutoFormat::CalcLevel(const SwTextFrame & rFrame,
+ sal_uInt16 *const pDigitLvl) const
{
sal_uInt16 nLvl = 0, nBlnk = 0;
- const OUString& rText = rNd.GetText();
+ const OUString& rText = rFrame.GetText();
if( pDigitLvl )
*pDigitLvl = USHRT_MAX;
- if( RES_POOLCOLL_TEXT_MOVE == rNd.GetTextColl()->GetPoolFormatId() )
+ if (RES_POOLCOLL_TEXT_MOVE == rFrame.GetTextNodeForParaProps()->GetTextColl()->GetPoolFormatId())
{
if( m_aFlags.bAFormatByInput )
{
@@ -440,17 +454,18 @@ sal_uInt16 SwAutoFormat::CalcLevel( const SwTextNode& rNd, sal_uInt16 *pDigitLvl
// on the *second* invocation of AutoFormat, CalcLevel() will
// retrieve the stored number, and it will be used by
// BuildHeadLine() to select the corresponding heading style.
- nLvl = rNd.GetAutoFormatLvl();
- const_cast<SwTextNode&>(rNd).SetAutoFormatLvl( 0 );
+ nLvl = rFrame.GetTextNodeForParaProps()->GetAutoFormatLvl();
+ const_cast<SwTextNode *>(rFrame.GetTextNodeForParaProps())->SetAutoFormatLvl(0);
if( nLvl )
return nLvl;
}
++nLvl;
}
- for (sal_Int32 n = 0, nEnd = rText.getLength(); n < nEnd; ++n)
+ for (TextFrameIndex n = TextFrameIndex(0),
+ nEnd = TextFrameIndex(rText.getLength()); n < nEnd; ++n)
{
- switch (rText[n])
+ switch (rText[sal_Int32(n)])
{
case ' ': if( 3 == ++nBlnk )
{
@@ -464,44 +479,49 @@ sal_uInt16 SwAutoFormat::CalcLevel( const SwTextNode& rNd, sal_uInt16 *pDigitLvl
default:
if( pDigitLvl )
// test 1.) / 1. / 1.1.1 / (1). / (1) / ....
- *pDigitLvl = GetDigitLevel( rNd, n );
+ *pDigitLvl = GetDigitLevel(rFrame, n);
return nLvl;
}
}
return nLvl;
}
-sal_Int32 SwAutoFormat::GetBigIndent( sal_Int32& rCurrentSpacePos ) const
+sal_Int32 SwAutoFormat::GetBigIndent(TextFrameIndex & rCurrentSpacePos) const
{
- SwTextFrameInfo aFInfo( GetFrame( *m_pCurTextNd ) );
- const SwTextFrame* pNxtFrame = nullptr;
+ SwTextFrameInfo aFInfo( m_pCurTextFrame );
+ const SwTextFrame* pNextFrame = nullptr;
if( !m_bMoreLines )
{
- const SwTextNode* pNxtNd = GetNextNode();
- if( !CanJoin( pNxtNd ) || !IsOneLine( *pNxtNd ) )
+ pNextFrame = GetNextNode();
+ if (!CanJoin(pNextFrame) || !IsOneLine(*pNextFrame))
return 0;
- pNxtFrame = GetFrame( *pNxtNd );
+ pNextFrame = EnsureFormatted(*pNextFrame);
}
- return aFInfo.GetBigIndent( rCurrentSpacePos, pNxtFrame );
+ return aFInfo.GetBigIndent( rCurrentSpacePos, pNextFrame );
}
-bool SwAutoFormat::IsNoAlphaLine( const SwTextNode& rNd ) const
+bool SwAutoFormat::IsNoAlphaLine(const SwTextFrame & rFrame) const
{
- const OUString& rStr = rNd.GetText();
+ const OUString& rStr = rFrame.GetText();
if( rStr.isEmpty() )
return false;
// or better: determine via number of AlphaNum and !AlphaNum characters
sal_Int32 nANChar = 0, nBlnk = 0;
- CharClass& rCC = GetCharClass( rNd.GetSwAttrSet().GetLanguage().GetLanguage() );
- for( sal_Int32 n = 0, nEnd = rStr.getLength(); n < nEnd; ++n )
- if( IsSpace( rStr[ n ] ) )
+ for (TextFrameIndex n = TextFrameIndex(0),
+ nEnd = TextFrameIndex(rStr.getLength()); n < nEnd; ++n)
+ if (IsSpace(rStr[sal_Int32(n)]))
++nBlnk;
- else if( rCC.isLetterNumeric( rStr, n ))
- ++nANChar;
+ else
+ {
+ auto const pair = rFrame.MapViewToModel(n);
+ CharClass& rCC = GetCharClass(pair.first->GetSwAttrSet().GetLanguage().GetLanguage());
+ if (rCC.isLetterNumeric(rStr, sal_Int32(n)))
+ ++nANChar;
+ }
// If there are 75% of non-alphanumeric characters, then true
sal_uLong nLen = rStr.getLength() - nBlnk;
@@ -514,7 +534,7 @@ bool SwAutoFormat::DoUnderline()
if( !m_aFlags.bSetBorder )
return false;
- OUString const& rText(m_pCurTextNd->GetText());
+ OUString const& rText(m_pCurTextFrame->GetText());
int eState = 0;
sal_Int32 nCnt = 0;
while (nCnt < rText.getLength())
@@ -541,8 +561,10 @@ bool SwAutoFormat::DoUnderline()
if( 2 < nCnt )
{
// then underline the previous paragraph if one exists
- DelEmptyLine( false );
+ DelEmptyLine( false ); // -> point will be on end of current paragraph
+ // WARNING: rText may be deleted now, m_pCurTextFrame may be nullptr
m_aDelPam.SetMark();
+ // apply to last node & rely on InsertItemSet to apply it to props-node
m_aDelPam.GetMark()->nContent = 0;
editeng::SvxBorderLine aLine;
@@ -581,7 +603,8 @@ bool SwAutoFormat::DoUnderline()
aBox.SetLine( &aLine, SvxBoxItemLine::BOTTOM );
aBox.SetDistance(42, SvxBoxItemLine::BOTTOM ); // ~0,75 mm
aSet.Put(aBox);
- m_pDoc->getIDocumentContentOperations().InsertItemSet( m_aDelPam, aSet );
+ m_pDoc->getIDocumentContentOperations().InsertItemSet(m_aDelPam, aSet,
+ SetAttrMode::DEFAULT, m_pEditShell->GetLayout());
m_aDelPam.DeleteMark();
}
@@ -594,24 +617,24 @@ bool SwAutoFormat::DoTable()
m_pCurTextNd->FindTableNode() )
return false;
- const OUString& rTmp = m_pCurTextNd->GetText();
- sal_Int32 nSttPlus = GetLeadingBlanks( rTmp );
- sal_Int32 nEndPlus = GetTrailingBlanks( rTmp );
+ const OUString& rTmp = m_pCurTextFrame->GetText();
+ TextFrameIndex nSttPlus(GetLeadingBlanks(rTmp));
+ TextFrameIndex nEndPlus(GetTrailingBlanks(rTmp));
sal_Unicode cChar;
- if( 2 > nEndPlus - nSttPlus ||
- ( '+' != ( cChar = rTmp[nSttPlus]) && '|' != cChar ) ||
- ( '+' != ( cChar = rTmp[nEndPlus - 1]) && '|' != cChar ))
+ if (TextFrameIndex(2) > nEndPlus - nSttPlus
+ || ('+' != (cChar = rTmp[sal_Int32(nSttPlus)]) && '|' != cChar)
+ || ('+' != (cChar = rTmp[sal_Int32(nEndPlus) - 1]) && '|' != cChar))
return false;
SwTextFrameInfo aInfo( m_pCurTextFrame );
- sal_Int32 n = nSttPlus;
+ TextFrameIndex n = nSttPlus;
std::vector<sal_uInt16> aPosArr;
- while (n < rTmp.getLength())
+ while (n < TextFrameIndex(rTmp.getLength()))
{
- switch (rTmp[n])
+ switch (rTmp[sal_Int32(n)])
{
case '-':
case '_':
@@ -638,7 +661,7 @@ bool SwAutoFormat::DoTable()
sal_uInt16 nColCnt = aPosArr.size() - 1;
SwTwips nSttPos = aPosArr[ 0 ];
sal_Int16 eHori;
- switch( m_pCurTextNd->GetSwAttrSet().GetAdjust().GetAdjust() )
+ switch (m_pCurTextFrame->GetTextNodeForParaProps()->GetSwAttrSet().GetAdjust().GetAdjust())
{
case SvxAdjust::Center: eHori = text::HoriOrientation::CENTER; break;
case SvxAdjust::Right: eHori = text::HoriOrientation::RIGHT; break;
@@ -657,6 +680,7 @@ bool SwAutoFormat::DoTable()
// then create a table that matches the character
DelEmptyLine();
+ // WARNING: rTmp may be deleted now, m_pCurTextFrame may be nullptr
SwNodeIndex aIdx( m_aDelPam.GetPoint()->nNode );
m_aDelPam.Move( fnMoveForward );
m_pDoc->InsertTable( SwInsertTableOptions( SwInsertTableFlags::All , 1 ),
@@ -711,15 +735,17 @@ sal_Int32 SwAutoFormat::GetTrailingBlanks( const OUString& rStr )
return ++n;
}
-bool SwAutoFormat::IsFirstCharCapital( const SwTextNode& rNd ) const
+bool SwAutoFormat::IsFirstCharCapital(const SwTextFrame& rFrame) const
{
- const OUString& rText = rNd.GetText();
- for( sal_Int32 n = 0, nEnd = rText.getLength(); n < nEnd; ++n )
- if (!IsSpace(rText[n]))
+ const OUString& rText = rFrame.GetText();
+ for (TextFrameIndex n = TextFrameIndex(0),
+ nEnd = TextFrameIndex(rText.getLength()); n < nEnd; ++n)
+ if (!IsSpace(rText[sal_Int32(n)]))
{
- CharClass& rCC = GetCharClass( rNd.GetSwAttrSet().
+ auto const pair = rFrame.MapViewToModel(n);
+ CharClass& rCC = GetCharClass( pair.first->GetSwAttrSet().
GetLanguage().GetLanguage() );
- sal_Int32 nCharType = rCC.getCharacterType( rText, n );
+ sal_Int32 nCharType = rCC.getCharacterType(rText, sal_Int32(n));
return CharClass::isLetterType( nCharType ) &&
0 != ( i18n::KCharacterType::UPPER &
nCharType );
@@ -727,12 +753,14 @@ bool SwAutoFormat::IsFirstCharCapital( const SwTextNode& rNd ) const
return false;
}
-sal_uInt16 SwAutoFormat::GetDigitLevel( const SwTextNode& rNd, sal_Int32& rPos,
+sal_uInt16
+SwAutoFormat::GetDigitLevel(const SwTextFrame& rFrame, TextFrameIndex& rPos,
OUString* pPrefix, OUString* pPostfix, OUString* pNumTypes ) const
{
+
// check for 1.) / 1. / 1.1.1 / (1). / (1) / ....
- const OUString& rText = rNd.GetText();
- sal_Int32 nPos = rPos;
+ const OUString& rText = rFrame.GetText();
+ sal_Int32 nPos(rPos);
int eScan = NONE;
sal_uInt16 nStart = 0;
@@ -741,10 +769,10 @@ sal_uInt16 SwAutoFormat::GetDigitLevel( const SwTextNode& rNd, sal_Int32& rPos,
sal_uInt16 nOpeningParentheses = 0;
sal_uInt16 nClosingParentheses = 0;
- CharClass& rCC = GetCharClass( rNd.GetSwAttrSet().GetLanguage().GetLanguage() );
-
while (nPos < rText.getLength() && nDigitLvl < MAXLEVEL - 1)
{
+ auto const pair = rFrame.MapViewToModel(TextFrameIndex(nPos));
+ CharClass& rCC = GetCharClass(pair.first->GetSwAttrSet().GetLanguage().GetLanguage());
const sal_Unicode cCurrentChar = rText[nPos];
if( ('0' <= cCurrentChar && '9' >= cCurrentChar) ||
(0xff10 <= cCurrentChar && 0xff19 >= cCurrentChar) )
@@ -963,7 +991,7 @@ CHECK_ROMAN_5:
break;
++nPos;
}
- if( !( CHG & eScan ) || rPos == nPos ||
+ if (!( CHG & eScan ) || rPos == TextFrameIndex(nPos) ||
nPos == rText.getLength() || !IsSpace(rText[nPos]) ||
(nOpeningParentheses > nClosingParentheses))
return USHRT_MAX;
@@ -971,15 +999,15 @@ CHECK_ROMAN_5:
if( (NO_DELIM & eScan) && pPrefix ) // do not forget the last one
*pPrefix += "\x01" + OUString::number( nStart );
- rPos = nPos;
+ rPos = TextFrameIndex(nPos);
return nDigitLvl; // 0 .. 9 (MAXLEVEL - 1)
}
void SwAutoFormat::SetColl( sal_uInt16 nId, bool bHdLineOrText )
{
m_aDelPam.DeleteMark();
- m_aDelPam.GetPoint()->nNode = m_aNdIdx;
- m_aDelPam.GetPoint()->nContent.Assign( m_pCurTextNd, 0 );
+ m_aDelPam.GetPoint()->nNode = *m_pCurTextFrame->GetTextNodeForParaProps();
+ m_aDelPam.GetPoint()->nContent.Assign(m_aDelPam.GetPoint()->nNode.GetNode().GetContentNode(), 0);
// keep hard tabs, alignment, language, hyphenation, DropCaps and nearly all frame attributes
SfxItemSet aSet(
@@ -990,9 +1018,9 @@ void SwAutoFormat::SetColl( sal_uInt16 nId, bool bHdLineOrText )
RES_PARATR_TABSTOP, RES_PARATR_DROP,
RES_BACKGROUND, RES_SHADOW>{});
- if( m_pCurTextNd->HasSwAttrSet() )
+ if (m_aDelPam.GetPoint()->nNode.GetNode().GetTextNode()->HasSwAttrSet())
{
- aSet.Put( *m_pCurTextNd->GetpSwAttrSet() );
+ aSet.Put(*m_aDelPam.GetPoint()->nNode.GetNode().GetTextNode()->GetpSwAttrSet());
// take HeaderLine/TextBody only if centered or right aligned, otherwise only justification
SvxAdjustItem const * pAdj;
if( SfxItemState::SET == aSet.GetItemState( RES_PARATR_ADJUST,
@@ -1009,33 +1037,29 @@ void SwAutoFormat::SetColl( sal_uInt16 nId, bool bHdLineOrText )
m_pDoc->SetTextFormatCollByAutoFormat( *m_aDelPam.GetPoint(), nId, &aSet );
}
-bool SwAutoFormat::HasSelBlanks( SwPaM& rPam )
+static bool HasSelBlanks(
+ SwTextFrame const*const pStartFrame, TextFrameIndex & rStartIndex,
+ SwTextFrame const*const pEndFrame, TextFrameIndex & rEndIndex)
{
- // Is there a Blank at the beginning or end?
- // Do not delete it, it will be inserted again.
- SwPosition * pPos = rPam.End();
- sal_Int32 nBlnkPos = pPos->nContent.GetIndex();
- SwTextNode* pTextNd = pPos->nNode.GetNode().GetTextNode();
- if (nBlnkPos && nBlnkPos-- < pTextNd->GetText().getLength() &&
- (' ' == pTextNd->GetText()[nBlnkPos]))
- --pPos->nContent;
- else
+ if (TextFrameIndex(0) < rEndIndex
+ && rEndIndex < TextFrameIndex(pEndFrame->GetText().getLength())
+ && ' ' == pEndFrame->GetText()[sal_Int32(rEndIndex) - 1])
{
- pPos = rPam.GetPoint() == pPos ? rPam.GetMark() : rPam.GetPoint();
- nBlnkPos = pPos->nContent.GetIndex();
- pTextNd = pPos->nNode.GetNode().GetTextNode();
- if (nBlnkPos < pTextNd->GetText().getLength() &&
- (' ' == pTextNd->GetText()[nBlnkPos]))
- ++pPos->nContent;
- else
- return false;
+ --rEndIndex;
+ return true;
+ }
+ if (rStartIndex < TextFrameIndex(pStartFrame->GetText().getLength())
+ && ' ' == pStartFrame->GetText()[sal_Int32(rStartIndex)])
+ {
+ ++rStartIndex;
+ return true;
}
- return true;
+ return false;
}
-bool SwAutoFormat::HasBreakAttr( const SwTextNode& rTextNd )
+bool SwAutoFormat::HasBreakAttr(const SwTextFrame& rTextFrame)
{
- const SfxItemSet* pSet = rTextNd.GetpSwAttrSet();
+ const SfxItemSet *const pSet = rTextFrame.GetTextNodeFirst()->GetpSwAttrSet();
if( !pSet )
return false;
@@ -1052,9 +1076,9 @@ bool SwAutoFormat::HasBreakAttr( const SwTextNode& rTextNd )
}
/// Is there a dot at the end?
-bool SwAutoFormat::IsSentenceAtEnd( const SwTextNode& rTextNd )
+bool SwAutoFormat::IsSentenceAtEnd(const SwTextFrame & rTextFrame)
{
- const OUString& rStr = rTextNd.GetText();
+ const OUString& rStr = rTextFrame.GetText();
sal_Int32 n = rStr.getLength();
if( !n )
return true;
@@ -1073,23 +1097,22 @@ void SwAutoFormat::DeleteLeadingTrailingBlanks(bool bStart, bool bEnd)
{
// delete blanks at the end of the current and at the beginning of the next one
m_aDelPam.DeleteMark();
- m_aDelPam.GetPoint()->nNode = m_aNdIdx;
- sal_Int32 nPos(0);
- if( bStart && 0 != ( nPos = GetLeadingBlanks( m_pCurTextNd->GetText() )))
+ TextFrameIndex nPos(GetLeadingBlanks(m_pCurTextFrame->GetText()));
+ if (bStart && TextFrameIndex(0) != nPos)
{
- m_aDelPam.GetPoint()->nContent.Assign( m_pCurTextNd, 0 );
+ *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(TextFrameIndex(0));
m_aDelPam.SetMark();
- m_aDelPam.GetPoint()->nContent = nPos;
+ *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(nPos);
DeleteSel( m_aDelPam );
m_aDelPam.DeleteMark();
}
- if (bEnd && m_pCurTextNd->GetText().getLength() !=
- ( nPos = GetTrailingBlanks( m_pCurTextNd->GetText() )) )
+ nPos = TextFrameIndex(GetTrailingBlanks(m_pCurTextFrame->GetText()));
+ if (bEnd && TextFrameIndex(m_pCurTextFrame->GetText().getLength()) != nPos)
{
- m_aDelPam.GetPoint()->nContent.Assign(
- m_pCurTextNd, m_pCurTextNd->GetText().getLength());
+ *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(
+ TextFrameIndex(m_pCurTextFrame->GetText().getLength()));
m_aDelPam.SetMark();
- m_aDelPam.GetPoint()->nContent = nPos;
+ *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(nPos);
DeleteSel( m_aDelPam );
m_aDelPam.DeleteMark();
}
@@ -1181,39 +1204,43 @@ void SwAutoFormat::DeleteSelImpl(SwPaM & rDelPam, SwPaM & rPamToCorrect)
m_aNdIdx = aTmp.GetPoint()->nNode;
m_pCurTextNd = m_aNdIdx.GetNode().GetTextNode();
+ m_pCurTextFrame = GetFrame(*m_pCurTextNd); // keep it up to date
}
else
m_pEditShell->DeleteSel( rDelPam );
}
-bool SwAutoFormat::DeleteJoinCurNextPara( const OUString& rNxtPara )
+bool SwAutoFormat::DeleteJoinCurNextPara(SwTextFrame const*const pNextFrame,
+ bool const bIgnoreLeadingBlanks)
{
// delete blanks at the end of the current and at the beginning of the next one
m_aDelPam.DeleteMark();
- m_aDelPam.GetPoint()->nNode = m_aNdIdx;
- m_aDelPam.GetPoint()->nContent.Assign( m_pCurTextNd,
- GetTrailingBlanks( m_pCurTextNd->GetText() ) );
- m_aDelPam.SetMark();
+ TextFrameIndex nTrailingPos(GetTrailingBlanks(m_pCurTextFrame->GetText()));
- ++m_aDelPam.GetPoint()->nNode;
- SwTextNode* pTNd = m_aDelPam.GetNode().GetTextNode();
- if( !pTNd )
+ SwTextFrame const*const pEndFrame(pNextFrame ? pNextFrame : m_pCurTextFrame);
+ TextFrameIndex nLeadingPos(0);
+ if (pNextFrame)
{
- // then delete only up to end of the paragraph
- --m_aDelPam.GetPoint()->nNode;
- m_aDelPam.GetPoint()->nContent = m_pCurTextNd->GetText().getLength();
+ nLeadingPos = TextFrameIndex(
+ bIgnoreLeadingBlanks ? 0 : GetLeadingBlanks(pNextFrame->GetText()));
}
else
- m_aDelPam.GetPoint()->nContent.Assign( pTNd,
- GetLeadingBlanks( rNxtPara ));
+ {
+ nLeadingPos = TextFrameIndex(m_pCurTextFrame->GetText().getLength());
+ }
// Is there a Blank at the beginning or end?
// Do not delete it, it will be inserted again.
- bool bHasBlnks = HasSelBlanks( m_aDelPam );
+ bool bHasBlnks = HasSelBlanks(m_pCurTextFrame, nTrailingPos, pEndFrame, nLeadingPos);
+
+ *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(nTrailingPos);
+ m_aDelPam.SetMark();
+ *m_aDelPam.GetPoint() = pEndFrame->MapViewToModelPos(nLeadingPos);
if( *m_aDelPam.GetPoint() != *m_aDelPam.GetMark() )
DeleteSel( m_aDelPam );
m_aDelPam.DeleteMark();
+ // note: keep m_aDelPam point at insert pos. for clients
return !bHasBlnks;
}
@@ -1223,31 +1250,32 @@ void SwAutoFormat::DelEmptyLine( bool bTstNextPara )
SetRedlineText( STR_AUTOFMTREDL_DEL_EMPTY_PARA );
// delete blanks in empty paragraph
m_aDelPam.DeleteMark();
- m_aDelPam.GetPoint()->nNode = m_aNdIdx;
- m_aDelPam.GetPoint()->nContent.Assign(
- m_pCurTextNd, m_pCurTextNd->GetText().getLength() );
+ *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(
+ TextFrameIndex(m_pCurTextFrame->GetText().getLength()));
m_aDelPam.SetMark();
- --m_aDelPam.GetMark()->nNode;
+ m_aDelPam.GetMark()->nNode = m_pCurTextFrame->GetTextNodeFirst()->GetIndex() - 1;
SwTextNode* pTNd = m_aDelPam.GetNode( false ).GetTextNode();
if( pTNd )
// first use the previous text node
m_aDelPam.GetMark()->nContent.Assign(pTNd, pTNd->GetText().getLength());
else if( bTstNextPara )
{
- // then try the next (at the beginning of a Doc, table cells, borders, ...)
- m_aDelPam.GetMark()->nNode += 2;
+ // then try the next (at the beginning of a Doc, table cells, frames, ...)
+ m_aDelPam.GetMark()->nNode = (m_pCurTextFrame->GetMergedPara()
+ ? m_pCurTextFrame->GetMergedPara()->pLastNode
+ : m_pCurTextNd
+ )->GetIndex() + 1;
pTNd = m_aDelPam.GetNode( false ).GetTextNode();
if( pTNd )
{
m_aDelPam.GetMark()->nContent.Assign( pTNd, 0 );
- m_aDelPam.GetPoint()->nContent = 0;
+ *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(TextFrameIndex(0));
}
}
else
{
- m_aDelPam.GetMark()->nNode = m_aNdIdx;
- m_aDelPam.GetMark()->nContent = 0;
+ *m_aDelPam.GetMark() = m_pCurTextFrame->MapViewToModelPos(TextFrameIndex(0));
pTNd = m_pCurTextNd;
}
if( pTNd )
@@ -1255,6 +1283,9 @@ void SwAutoFormat::DelEmptyLine( bool bTstNextPara )
m_aDelPam.DeleteMark();
ClearRedlineText();
+ // note: this likely has deleted m_pCurTextFrame - update it...
+ m_pCurTextNd = m_aNdIdx.GetNode().GetTextNode();
+ m_pCurTextFrame = m_pCurTextNd ? GetFrame( *m_pCurTextNd ) : nullptr;
}
void SwAutoFormat::DelMoreLinesBlanks( bool bWithLineBreaks )
@@ -1265,38 +1296,38 @@ void SwAutoFormat::DelMoreLinesBlanks( bool bWithLineBreaks )
{
// delete all blanks on the left and right of the indentation
m_aDelPam.DeleteMark();
- m_aDelPam.GetPoint()->nNode = m_aNdIdx;
- m_aDelPam.GetPoint()->nContent.Assign( m_pCurTextNd, 0 );
SwTextFrameInfo aFInfo( m_pCurTextFrame );
- aFInfo.GetSpaces( m_aDelPam, !m_aFlags.bAFormatByInput || bWithLineBreaks );
+ std::vector<std::pair<TextFrameIndex, TextFrameIndex>> spaces;
+ aFInfo.GetSpaces(spaces, !m_aFlags.bAFormatByInput || bWithLineBreaks);
- do {
- SwPaM* pNxt = m_aDelPam.GetNext();
- if( pNxt->HasMark() && *pNxt->GetPoint() != *pNxt->GetMark() )
+ for (auto & rSpaceRange : spaces)
+ {
+ assert(rSpaceRange.first != rSpaceRange.second);
+ bool const bHasBlanks = HasSelBlanks(
+ m_pCurTextFrame, rSpaceRange.first,
+ m_pCurTextFrame, rSpaceRange.second);
+ if (rSpaceRange.first != rSpaceRange.second)
{
- bool bHasBlnks = HasSelBlanks( *pNxt );
- DeleteSel( *pNxt );
- if( !bHasBlnks )
+ *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(rSpaceRange.first);
+ m_aDelPam.SetMark();
+ *m_aDelPam.GetPoint() = m_pCurTextFrame->MapViewToModelPos(rSpaceRange.second);
+ DeleteSel(m_aDelPam);
+ if (!bHasBlanks)
{
- m_pDoc->getIDocumentContentOperations().InsertString( *pNxt, OUString(' ') );
+ m_pDoc->getIDocumentContentOperations().InsertString(m_aDelPam, OUString(' '));
}
+ m_aDelPam.DeleteMark();
}
-
- if( pNxt == &m_aDelPam )
- break;
- delete pNxt;
- } while( true );
-
- m_aDelPam.DeleteMark();
+ }
}
}
void SwAutoFormat::JoinPrevPara()
{
m_aDelPam.DeleteMark();
- m_aDelPam.GetPoint()->nNode = m_aNdIdx;
- m_aDelPam.GetPoint()->nContent.Assign( m_pCurTextNd, 0 );
+ m_aDelPam.GetPoint()->nNode = *m_pCurTextFrame->GetTextNodeFirst();
+ m_aDelPam.GetPoint()->nContent.Assign(m_pCurTextFrame->GetTextNodeFirst(), 0);
m_aDelPam.SetMark();
--m_aDelPam.GetPoint()->nNode;
@@ -1319,29 +1350,30 @@ void SwAutoFormat::BuildIndent()
if( m_bMoreLines )
DelMoreLinesBlanks( true );
else
- bBreak = !IsFastFullLine( *m_pCurTextNd ) ||
- IsBlanksInString( *m_pCurTextNd ) ||
- IsSentenceAtEnd( *m_pCurTextNd );
+ bBreak = !IsFastFullLine(*m_pCurTextFrame)
+ || IsBlanksInString(*m_pCurTextFrame)
+ || IsSentenceAtEnd(*m_pCurTextFrame);
SetColl( RES_POOLCOLL_TEXT_IDENT );
if( !bBreak )
{
SetRedlineText( STR_AUTOFMTREDL_DEL_MORELINES );
- const SwTextNode* pNxtNd = GetNextNode();
- if( pNxtNd && !m_bEnd )
+ const SwTextFrame * pNextFrame = GetNextNode();
+ if (pNextFrame && !m_bEnd)
{
do {
- bBreak = !IsFastFullLine( *pNxtNd ) ||
- IsBlanksInString( *pNxtNd ) ||
- IsSentenceAtEnd( *pNxtNd );
- if (DeleteJoinCurNextPara(pNxtNd->GetText()))
+ bBreak = !IsFastFullLine(*pNextFrame)
+ || IsBlanksInString(*pNextFrame)
+ || IsSentenceAtEnd(*pNextFrame);
+ if (DeleteJoinCurNextPara(pNextFrame))
{
m_pDoc->getIDocumentContentOperations().InsertString( m_aDelPam, OUString(' ') );
}
if( bBreak )
break;
- pNxtNd = GetNextNode();
- } while( CanJoin( pNxtNd ) &&
- !CalcLevel( *pNxtNd ) );
+ pNextFrame = GetNextNode();
+ }
+ while (CanJoin(pNextFrame)
+ && !CalcLevel(*pNextFrame));
}
}
DeleteLeadingTrailingBlanks();
@@ -1356,30 +1388,34 @@ void SwAutoFormat::BuildTextIndent()
if( m_bMoreLines )
DelMoreLinesBlanks( true );
else
- bBreak = !IsFastFullLine( *m_pCurTextNd ) ||
- IsBlanksInString( *m_pCurTextNd ) ||
- IsSentenceAtEnd( *m_pCurTextNd );
+ bBreak = !IsFastFullLine(*m_pCurTextFrame)
+ || IsBlanksInString(*m_pCurTextFrame)
+ || IsSentenceAtEnd(*m_pCurTextFrame);
if( m_aFlags.bAFormatByInput )
- m_pCurTextNd->SetAutoFormatLvl( static_cast<sal_uInt8>(CalcLevel( *m_pCurTextNd )) );
+ {
+ const_cast<SwTextNode*>(m_pCurTextFrame->GetTextNodeForParaProps())->SetAutoFormatLvl(
+ static_cast<sal_uInt8>(CalcLevel(*m_pCurTextFrame)));
+ }
SetColl( RES_POOLCOLL_TEXT_MOVE );
if( !bBreak )
{
SetRedlineText( STR_AUTOFMTREDL_DEL_MORELINES );
- const SwTextNode* pNxtNd = GetNextNode();
- while( CanJoin( pNxtNd ) &&
- CalcLevel( *pNxtNd ) )
+ const SwTextFrame * pNextFrame = GetNextNode();
+ while (CanJoin(pNextFrame) &&
+ CalcLevel(*pNextFrame))
{
- bBreak = !IsFastFullLine( *pNxtNd ) || IsBlanksInString( *pNxtNd ) ||
- IsSentenceAtEnd( *pNxtNd );
- if (DeleteJoinCurNextPara(pNxtNd->GetText()))
+ bBreak = !IsFastFullLine(*pNextFrame)
+ || IsBlanksInString(*pNextFrame)
+ || IsSentenceAtEnd(*pNextFrame);
+ if (DeleteJoinCurNextPara(pNextFrame))
{
m_pDoc->getIDocumentContentOperations().InsertString( m_aDelPam, OUString(' ') );
}
if( bBreak )
break;
- pNxtNd = GetNextNode();
+ pNextFrame = GetNextNode();
}
}
DeleteLeadingTrailingBlanks();
@@ -1394,28 +1430,29 @@ void SwAutoFormat::BuildText()
if( m_bMoreLines )
DelMoreLinesBlanks();
else
- bBreak = !IsFastFullLine( *m_pCurTextNd ) ||
- IsBlanksInString( *m_pCurTextNd ) ||
- IsSentenceAtEnd( *m_pCurTextNd );
+ bBreak = !IsFastFullLine(*m_pCurTextFrame)
+ || IsBlanksInString(*m_pCurTextFrame)
+ || IsSentenceAtEnd(*m_pCurTextFrame);
SetColl( RES_POOLCOLL_TEXT, true );
if( !bBreak )
{
SetRedlineText( STR_AUTOFMTREDL_DEL_MORELINES );
- const SwTextNode* pNxtNd = GetNextNode();
- while( CanJoin( pNxtNd ) &&
- !CalcLevel( *pNxtNd ) )
+ const SwTextFrame * pNextFrame = GetNextNode();
+ while (CanJoin(pNextFrame) &&
+ !CalcLevel(*pNextFrame))
{
- bBreak = !IsFastFullLine( *pNxtNd ) || IsBlanksInString( *pNxtNd ) ||
- IsSentenceAtEnd( *pNxtNd );
- if (DeleteJoinCurNextPara(pNxtNd->GetText()))
+ bBreak = !IsFastFullLine(*pNextFrame)
+ || IsBlanksInString(*pNextFrame)
+ || IsSentenceAtEnd(*pNextFrame);
+ if (DeleteJoinCurNextPara(pNextFrame))
{
m_pDoc->getIDocumentContentOperations().InsertString( m_aDelPam, OUString(' ') );
}
if( bBreak )
break;
- const SwTextNode* pCurrNode = pNxtNd;
- pNxtNd = GetNextNode();
- if(!pNxtNd || pCurrNode == pNxtNd)
+ const SwTextFrame *const pCurrNode = pNextFrame;
+ pNextFrame = GetNextNode();
+ if (!pNextFrame || pCurrNode == pNextFrame)
break;
}
}
@@ -1433,24 +1470,24 @@ void SwAutoFormat::BuildEnum( sal_uInt16 nLvl, sal_uInt16 nDigitLevel )
SwTwips nFrameWidth = m_pCurTextFrame->getFramePrintArea().Width();
SwTwips nLeftTextPos;
{
- sal_Int32 nPos(0);
- while (nPos < m_pCurTextNd->GetText().getLength() &&
- IsSpace(m_pCurTextNd->GetText()[nPos]))
+ TextFrameIndex nPos(0);
+ while (nPos < TextFrameIndex(m_pCurTextFrame->GetText().getLength())
+ && IsSpace(m_pCurTextFrame->GetText()[sal_Int32(nPos)]))
{
++nPos;
}
SwTextFrameInfo aInfo( m_pCurTextFrame );
nLeftTextPos = aInfo.GetCharPos(nPos);
- nLeftTextPos -= m_pCurTextNd->GetSwAttrSet().GetLRSpace().GetLeft();
+ nLeftTextPos -= m_pCurTextFrame->GetTextNodeForParaProps()->GetSwAttrSet().GetLRSpace().GetLeft();
}
if( m_bMoreLines )
DelMoreLinesBlanks();
else
- bBreak = !IsFastFullLine( *m_pCurTextNd ) ||
- IsBlanksInString( *m_pCurTextNd ) ||
- IsSentenceAtEnd( *m_pCurTextNd );
+ bBreak = !IsFastFullLine(*m_pCurTextFrame)
+ || IsBlanksInString(*m_pCurTextFrame)
+ || IsSentenceAtEnd(*m_pCurTextFrame);
bool bRTL = m_pEditShell->IsInRightToLeftText();
DeleteLeadingTrailingBlanks();
@@ -1463,16 +1500,22 @@ void SwAutoFormat::BuildEnum( sal_uInt16 nLvl, sal_uInt16 nDigitLevel )
numfunc::GetDefaultPositionAndSpaceMode() );
const SwNumRule* pCur = nullptr;
- if( m_aFlags.bSetNumRule && nullptr != (pCur = m_pCurTextNd->GetNumRule()) )
- aRule = *pCur;
+ if (m_aFlags.bSetNumRule)
+ {
+ pCur = m_pCurTextFrame->GetTextNodeForParaProps()->GetNumRule();
+ if (pCur)
+ {
+ aRule = *pCur;
+ }
+ }
// replace bullet character with defined one
- const OUString& rStr = m_pCurTextNd->GetText();
- sal_Int32 nTextStt = 0;
+ const OUString& rStr = m_pCurTextFrame->GetText();
+ TextFrameIndex nTextStt(0);
const sal_Unicode* pFndBulletChr = nullptr;
if (m_aFlags.bChgEnumNum && 2 < rStr.getLength())
- pFndBulletChr = StrChr(pBulletChar, rStr[nTextStt]);
- if (nullptr != pFndBulletChr && IsSpace(rStr[nTextStt + 1]))
+ pFndBulletChr = StrChr(pBulletChar, rStr[sal_Int32(nTextStt)]);
+ if (nullptr != pFndBulletChr && IsSpace(rStr[sal_Int32(nTextStt) + 1]))
{
if( m_aFlags.bAFormatByInput )
{
@@ -1549,8 +1592,9 @@ void SwAutoFormat::BuildEnum( sal_uInt16 nLvl, sal_uInt16 nDigitLevel )
// it is determined by the indentation level.
OUString aPostfix, aPrefix, aNumTypes;
- if( USHRT_MAX != ( nDigitLevel = GetDigitLevel( *m_pCurTextNd, nTextStt,
- &aPrefix, &aPostfix, &aNumTypes )) )
+ nDigitLevel = GetDigitLevel(*m_pCurTextFrame, nTextStt,
... etc. - the rest is truncated
More information about the Libreoffice-commits
mailing list