summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorDaniel Arato (NISZ) <arato.daniel@nisz.hu>2020-11-16 11:53:47 +0100
committerLászló Németh <nemeth@numbertext.org>2020-11-26 14:41:53 +0100
commit59fec754a1523eede0f19a59e4eeeff593a4d688 (patch)
tree3a7b0792ad7f2f4d7cd06dd7722b2f018b826556 /sw
parentf83dd470eca2b09ed69510f54a801d109b51c997 (diff)
tdf#135198 tdf#138050 sw editing: fix text box position sync
Follow-up to commit c9eb53f200225f2ee6ca695e1326843a487aee51 (tdf#135198 sw editing: text box fell out of its shape) Every time a shape is repositioned, make sure the text box inside the shape follows the shape. The previous solution to this bug, the one implemented in SwObjectFormatterTextFrame::DoFormatObjs, was a little more cumbersome. This one should produce fewer regressions, I hope. Change-Id: I3e88eb8616cd299cabb7b74b188ab7220746ec89 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106421 Tested-by: Jenkins Tested-by: László Németh <nemeth@numbertext.org> Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/core/layout/data/textbox-phantom-change.docxbin0 -> 5092 bytes
-rw-r--r--sw/qa/core/layout/layout.cxx14
-rw-r--r--sw/source/core/draw/dcontact.cxx29
-rw-r--r--sw/source/core/layout/objectformattertxtfrm.cxx33
4 files changed, 42 insertions, 34 deletions
diff --git a/sw/qa/core/layout/data/textbox-phantom-change.docx b/sw/qa/core/layout/data/textbox-phantom-change.docx
new file mode 100644
index 000000000000..75ac039561f6
--- /dev/null
+++ b/sw/qa/core/layout/data/textbox-phantom-change.docx
Binary files differ
diff --git a/sw/qa/core/layout/layout.cxx b/sw/qa/core/layout/layout.cxx
index 15f2c4edb846..2151b870da13 100644
--- a/sw/qa/core/layout/layout.cxx
+++ b/sw/qa/core/layout/layout.cxx
@@ -16,6 +16,7 @@
#include <unotxdoc.hxx>
#include <drawdoc.hxx>
#include <IDocumentDrawModelAccess.hxx>
+#include <IDocumentState.hxx>
#include <svx/svdpage.hxx>
char const DATA_DIRECTORY[] = "/sw/qa/core/layout/data/";
@@ -180,6 +181,19 @@ CPPUNIT_TEST_FIXTURE(SwCoreLayoutTest, testTextBoxStaysInsideShape)
assertXPath(pXmlDoc, "//fly/infos/bounds", "bottom", "7184");
}
+CPPUNIT_TEST_FIXTURE(SwCoreLayoutTest, testTextBoxNotModifiedOnOpen)
+{
+ // tdf#138050: a freshly opened document containing a shape with a text box
+ // should not appear to be modified
+ load(DATA_DIRECTORY, "textbox-phantom-change.docx");
+ SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
+ SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+
+ // Without the fix in place this test would have shown that the document
+ // was modified due to a fix to tdf#135198
+ CPPUNIT_ASSERT(!pDoc->getIDocumentState().IsModified());
+}
+
CPPUNIT_TEST_FIXTURE(SwCoreLayoutTest, testTextBoxAutoGrowVertical)
{
load(DATA_DIRECTORY, "textbox-autogrow-vertical.docx");
diff --git a/sw/source/core/draw/dcontact.cxx b/sw/source/core/draw/dcontact.cxx
index eb406e418ac9..3ae40ccde5a2 100644
--- a/sw/source/core/draw/dcontact.cxx
+++ b/sw/source/core/draw/dcontact.cxx
@@ -49,6 +49,8 @@
#include <unodraw.hxx>
#include <IDocumentDrawModelAccess.hxx>
#include <IDocumentLayoutAccess.hxx>
+#include <IDocumentState.hxx>
+#include <IDocumentUndoRedo.hxx>
#include <doc.hxx>
#include <hints.hxx>
#include <txtfrm.hxx>
@@ -1260,7 +1262,6 @@ void SwDrawContact::Changed_( const SdrObject& rObj,
const SwFormatVertOrient& rVert = GetFormat()->GetVertOrient();
if ( nYPosDiff != 0 )
{
-
if ( rVert.GetRelationOrient() == text::RelOrientation::CHAR ||
rVert.GetRelationOrient() == text::RelOrientation::TEXT_LINE )
{
@@ -1313,6 +1314,32 @@ void SwDrawContact::Changed_( const SdrObject& rObj,
// may affect the size of the underlying textbox.
lcl_textBoxSizeNotify(GetFormat());
}
+
+ // tdf#135198: keep text box together with its shape
+ SwRect aObjRect(rObj.GetSnapRect());
+ const SwPageFrame* rPageFrame = pAnchoredDrawObj->GetPageFrame();
+ if (rPageFrame && rPageFrame->isFrameAreaPositionValid())
+ {
+ SwDoc* const pDoc = GetFormat()->GetDoc();
+
+ // avoid Undo creation
+ ::sw::UndoGuard const ug(pDoc->GetIDocumentUndoRedo());
+
+ // hide any artificial "changes" made by synchronizing the textbox position
+ const bool bEnableSetModified = pDoc->getIDocumentState().IsEnableSetModified();
+ pDoc->getIDocumentState().SetEnableSetModified(false);
+
+ SfxItemSet aSyncSet(pDoc->GetAttrPool(),
+ svl::Items<RES_VERT_ORIENT, RES_ANCHOR>{});
+ aSyncSet.Put(SwFormatVertOrient(aObjRect.Top() - rPageFrame->getFrameArea().Top(),
+ text::VertOrientation::NONE,
+ text::RelOrientation::PAGE_FRAME));
+ aSyncSet.Put(SwFormatAnchor(RndStdIds::FLY_AT_PAGE, pAnchoredDrawObj->GetPageFrame()->GetPhyPageNum()));
+
+ SwTextBoxHelper::syncFlyFrameAttr(*GetFormat(), aSyncSet);
+
+ pDoc->getIDocumentState().SetEnableSetModified(bEnableSetModified);
+ }
}
break;
case SdrUserCallType::ChangeAttr:
diff --git a/sw/source/core/layout/objectformattertxtfrm.cxx b/sw/source/core/layout/objectformattertxtfrm.cxx
index 5c4aa770b86e..96ea415070c5 100644
--- a/sw/source/core/layout/objectformattertxtfrm.cxx
+++ b/sw/source/core/layout/objectformattertxtfrm.cxx
@@ -344,39 +344,6 @@ bool SwObjectFormatterTextFrame::DoFormatObjs()
( !mrAnchorTextFrame.IsFollow() &&
AtLeastOneObjIsTmpConsiderWrapInfluence() ) ) )
{
- // tdf#135198: force text box to stay inside shape after layout changes
- if (SwSortedObjs* pDrawObjs = mrAnchorTextFrame.GetDrawObjs())
- {
- // N.B.: avoid using ranged for because the iterator might get invalidated
- for (size_t i = 0; i < pDrawObjs->size(); ++i)
- {
- SwAnchoredObject* const pObj = (*pDrawObjs)[i];
- SwFrameFormat& rFormat = pObj->GetFrameFormat();
- if (SwTextBoxHelper::isTextBox(&rFormat, RES_DRAWFRMFMT))
- {
- if (const SwPageFrame* pPageFrame = pObj->GetPageFrame())
- {
- SwDoc* pDoc = rFormat.GetDoc();
-
- // avoid Undo creation,
- ::sw::UndoGuard const ug(pDoc->GetIDocumentUndoRedo());
-
- SfxItemSet aSet(pDoc->GetAttrPool(),
- svl::Items<RES_VERT_ORIENT, RES_ANCHOR>{});
-
- const SwRect& rPageFrameArea = pPageFrame->getFrameArea();
- aSet.Put(SwFormatVertOrient(pObj->GetObjRect().Top() - rPageFrameArea.Top(),
- text::VertOrientation::NONE,
- text::RelOrientation::PAGE_FRAME));
-
- aSet.Put(SwFormatAnchor(RndStdIds::FLY_AT_PAGE, pObj->GetPageFrame()->GetPhyPageNum()));
-
- SwTextBoxHelper::syncFlyFrameAttr(rFormat, aSet);
- }
- }
- }
- }
-
const bool bDoesAnchorHadPrev = ( mrAnchorTextFrame.GetIndPrev() != nullptr );
// Format anchor text frame after its objects are formatted.