tdf#130482 sw: fix text alignment in shape text
Regression from commit a3c7a8282d
(jsdialogs: apply .uno:Color and CharBackColor to floating text frames,
2019-11-08), the problem was that the original code populated aNewAttr, while
SetAttrToMarked() was only invoked in case there were arguments.
Fix this by making pNewAttrs a copy, so lcl_convertStringArguments() can
work on it in place, and then restore the old code that copied from
pNewAttrs to aNewAttr. This fixes the no-arguments case and keeps the
lcl_convertStringArguments() case working.
Change-Id: If7bf2d7b21e48d513a512ec6127b61ee74635ef5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88227
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
This commit is contained in:
@@ -21,9 +21,12 @@ $(eval $(call gb_CppunitTest_use_libraries,sw_uibase_shells, \
|
||||
comphelper \
|
||||
cppu \
|
||||
cppuhelper \
|
||||
editeng \
|
||||
sal \
|
||||
sfx \
|
||||
svl \
|
||||
svx \
|
||||
svxcore \
|
||||
sw \
|
||||
test \
|
||||
unotest \
|
||||
|
||||
@@ -13,12 +13,20 @@
|
||||
#include <sfx2/viewfrm.hxx>
|
||||
#include <vcl/GraphicObject.hxx>
|
||||
#include <vcl/gdimtf.hxx>
|
||||
#include <svx/svdpage.hxx>
|
||||
#include <svx/svdview.hxx>
|
||||
#include <editeng/eeitem.hxx>
|
||||
#include <editeng/adjustitem.hxx>
|
||||
#include <editeng/outlobj.hxx>
|
||||
#include <editeng/editobj.hxx>
|
||||
|
||||
#include <IDocumentContentOperations.hxx>
|
||||
#include <cmdid.h>
|
||||
#include <fmtanchr.hxx>
|
||||
#include <view.hxx>
|
||||
#include <wrtsh.hxx>
|
||||
#include <IDocumentDrawModelAccess.hxx>
|
||||
#include <drawdoc.hxx>
|
||||
|
||||
static char const DATA_DIRECTORY[] = "/sw/qa/uibase/shells/data/";
|
||||
|
||||
@@ -69,6 +77,48 @@ CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testTdf130179)
|
||||
CPPUNIT_ASSERT(!pItem);
|
||||
}
|
||||
|
||||
CPPUNIT_TEST_FIXTURE(SwUibaseShellsTest, testShapeTextAlignment)
|
||||
{
|
||||
// FIXME find out why this fails on macOS
|
||||
#ifndef MACOSX
|
||||
// Create a document with a rectangle in it.
|
||||
SwDoc* pDoc = createDoc();
|
||||
SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
|
||||
Point aStartPos(1000, 1000);
|
||||
pWrtShell->BeginCreate(static_cast<sal_uInt16>(OBJ_RECT), aStartPos);
|
||||
Point aMovePos(2000, 2000);
|
||||
pWrtShell->MoveCreate(aMovePos);
|
||||
pWrtShell->EndCreate(SdrCreateCmd::ForceEnd);
|
||||
|
||||
// Start shape text edit.
|
||||
SwView* pView = pDoc->GetDocShell()->GetView();
|
||||
// Select the shape.
|
||||
pView->GetViewFrame()->GetDispatcher()->Execute(FN_CNTNT_TO_NEXT_FRAME, SfxCallMode::SYNCHRON);
|
||||
pView->StopShellTimer();
|
||||
// Start the actual text edit.
|
||||
SdrPage* pPage = pWrtShell->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
|
||||
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pPage->GetObjCount());
|
||||
SdrObject* pObject = pPage->GetObj(0);
|
||||
pView->EnterShapeDrawTextMode(pObject);
|
||||
pView->AttrChangedNotify(nullptr);
|
||||
|
||||
// Change paragraph adjustment to center.
|
||||
pView->GetViewFrame()->GetDispatcher()->Execute(SID_ATTR_PARA_ADJUST_CENTER,
|
||||
SfxCallMode::SYNCHRON);
|
||||
|
||||
// End shape text edit.
|
||||
pWrtShell->EndTextEdit();
|
||||
|
||||
const OutlinerParaObject* pOutliner = pObject->GetOutlinerParaObject();
|
||||
// Without the accompanying fix in place, this test would have failed, because the shape had no
|
||||
// text or text formatting. In other words the paragraph adjustment command was ignored.
|
||||
CPPUNIT_ASSERT(pOutliner);
|
||||
const SfxItemSet& rParaAttribs = pOutliner->GetTextObject().GetParaAttribs(0);
|
||||
SvxAdjust eAdjust = rParaAttribs.GetItem(EE_PARA_JUST)->GetAdjust();
|
||||
CPPUNIT_ASSERT_EQUAL(SvxAdjust::Center, eAdjust);
|
||||
#endif
|
||||
}
|
||||
|
||||
CPPUNIT_PLUGIN_IMPLEMENT();
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
||||
@@ -132,7 +132,7 @@ void SwDrawTextShell::Execute( SfxRequest &rReq )
|
||||
const sal_uInt16 nSlot = rReq.GetSlot();
|
||||
|
||||
const sal_uInt16 nWhich = GetPool().GetWhich(nSlot);
|
||||
const SfxItemSet *pNewAttrs = rReq.GetArgs();
|
||||
std::unique_ptr<SfxItemSet> pNewAttrs(rReq.GetArgs() ? rReq.GetArgs()->Clone() : nullptr);
|
||||
|
||||
bool bRestoreSelection = false;
|
||||
ESelection aOldSelection;
|
||||
@@ -630,21 +630,15 @@ void SwDrawTextShell::Execute( SfxRequest &rReq )
|
||||
assert(false && "wrong dispatcher");
|
||||
return;
|
||||
}
|
||||
|
||||
std::unique_ptr<SfxItemSet> pNewArgs = pNewAttrs ? pNewAttrs->Clone() : nullptr;
|
||||
if (pNewArgs)
|
||||
if (nEEWhich && pNewAttrs)
|
||||
{
|
||||
lcl_convertStringArguments(nSlot, pNewArgs);
|
||||
lcl_convertStringArguments(nSlot, pNewAttrs);
|
||||
|
||||
if (nEEWhich)
|
||||
{
|
||||
std::unique_ptr<SfxPoolItem> pNewItem(pNewArgs->Get(nWhich).CloneSetWhich(nEEWhich));
|
||||
pNewArgs->Put(*pNewItem);
|
||||
}
|
||||
|
||||
SetAttrToMarked(*pNewArgs);
|
||||
aNewAttr.Put(pNewAttrs->Get(nWhich).CloneSetWhich(nEEWhich));
|
||||
}
|
||||
|
||||
SetAttrToMarked(aNewAttr);
|
||||
|
||||
GetView().GetViewFrame()->GetBindings().InvalidateAll(false);
|
||||
|
||||
if (IsTextEdit() && pOLV->GetOutliner()->IsModified())
|
||||
|
||||
Reference in New Issue
Block a user