1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <test/unoapixml_test.hxx>
12 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
13 #include <com/sun/star/drawing/XDrawPage.hpp>
15 #include <drawinglayer/tools/primitive2dxmldump.hxx>
16 #include <rtl/ustring.hxx>
17 #include <svx/sdr/contact/displayinfo.hxx>
18 #include <svx/sdr/contact/viewcontact.hxx>
19 #include <svx/sdr/contact/viewobjectcontact.hxx>
20 #include <svx/svdpage.hxx>
21 #include <svx/unopage.hxx>
22 #include <vcl/virdev.hxx>
23 #include <sdr/contact/objectcontactofobjlistpainter.hxx>
24 #include <comphelper/propertyvalue.hxx>
25 #include <sfx2/viewsh.hxx>
26 #include <svx/svdview.hxx>
27 #include <svx/sdr/table/tablecontroller.hxx>
28 #include <editeng/editobj.hxx>
30 using namespace ::com::sun::star
;
34 /// Tests for svx/source/table/ code.
35 class Test
: public UnoApiXmlTest
39 : UnoApiXmlTest("svx/qa/unit/data/")
43 drawinglayer::primitive2d::Primitive2DContainer
44 renderPageToPrimitives(const uno::Reference
<drawing::XDrawPage
>& xDrawPage
);
47 drawinglayer::primitive2d::Primitive2DContainer
48 Test::renderPageToPrimitives(const uno::Reference
<drawing::XDrawPage
>& xDrawPage
)
50 auto pDrawPage
= dynamic_cast<SvxDrawPage
*>(xDrawPage
.get());
51 CPPUNIT_ASSERT(pDrawPage
);
52 SdrPage
* pSdrPage
= pDrawPage
->GetSdrPage();
53 ScopedVclPtrInstance
<VirtualDevice
> aVirtualDevice
;
54 sdr::contact::ObjectContactOfObjListPainter
aObjectContact(*aVirtualDevice
,
55 { pSdrPage
->GetObj(0) }, nullptr);
56 const sdr::contact::ViewObjectContact
& rDrawPageVOContact
57 = pSdrPage
->GetViewContact().GetViewObjectContact(aObjectContact
);
58 sdr::contact::DisplayInfo aDisplayInfo
;
59 drawinglayer::primitive2d::Primitive2DContainer aContainer
;
60 rDrawPageVOContact
.getPrimitive2DSequenceHierarchy(aDisplayInfo
, aContainer
);
64 CPPUNIT_TEST_FIXTURE(Test
, testTableShadowBlur
)
66 // Given a document containing a table with a blurry shadow:
67 loadFromURL(u
"table-shadow-blur.pptx");
69 // When rendering the table shadow to primitives:
70 uno::Reference
<drawing::XDrawPagesSupplier
> xDrawPagesSupplier(mxComponent
, uno::UNO_QUERY
);
71 uno::Reference
<drawing::XDrawPage
> xDrawPage(xDrawPagesSupplier
->getDrawPages()->getByIndex(0),
73 drawinglayer::primitive2d::Primitive2DContainer xPrimitiveSequence
74 = renderPageToPrimitives(xDrawPage
);
76 // Then make sure that the cell fill part of the shadow has the expected transparency:
77 drawinglayer::Primitive2dXmlDump aDumper
;
78 xmlDocUniquePtr pDocument
= aDumper
.dumpAndParse(xPrimitiveSequence
);
79 // Without the accompanying fix in place, this test would have failed with:
82 //- In <>, XPath contents of child does not match
83 // i.e. the shadow's transparency was miscalculated.
84 assertXPathContent(pDocument
, "count(//objectinfo/unifiedtransparence)", "0");
87 CPPUNIT_TEST_FIXTURE(Test
, testSvxTableControllerSetAttrToSelectedShape
)
89 // Given a document with a table shape, editing cell text:
90 mxComponent
= loadFromDesktop("private:factory/simpress",
91 "com.sun.star.presentation.PresentationDocument");
92 uno::Sequence
<beans::PropertyValue
> aArgs
93 = { comphelper::makePropertyValue("Rows", sal_Int32(2)),
94 comphelper::makePropertyValue("Columns", sal_Int32(2)) };
95 dispatchCommand(mxComponent
, ".uno:InsertTable", aArgs
);
96 uno::Reference
<drawing::XDrawPagesSupplier
> xDrawPagesSupplier(mxComponent
, uno::UNO_QUERY
);
97 uno::Reference
<drawing::XDrawPage
> xDrawPage(xDrawPagesSupplier
->getDrawPages()->getByIndex(0),
99 auto pDrawPage
= dynamic_cast<SvxDrawPage
*>(xDrawPage
.get());
100 CPPUNIT_ASSERT(pDrawPage
);
101 SdrPage
* pSdrPage
= pDrawPage
->GetSdrPage();
103 = dynamic_cast<sdr::table::SdrTableObj
*>(pSdrPage
->GetObj(pSdrPage
->GetObjCount() - 1));
104 SfxViewShell
* pViewShell
= SfxViewShell::Current();
105 SdrView
* pSdrView
= pViewShell
->GetDrawView();
106 pSdrView
->SdrBeginTextEdit(pSdrObject
);
107 CPPUNIT_ASSERT(pSdrView
->IsTextEdit());
108 const EditTextObject
& rEdit
= pSdrObject
->getText(0)->GetOutlinerParaObject()->GetTextObject();
109 SfxItemSet
aSet(rEdit
.GetParaAttribs(0));
110 auto pTableController
111 = dynamic_cast<sdr::table::SvxTableController
*>(pSdrView
->getSelectionController().get());
113 // When applying attributes which only affect the cell text, not the table shape:
114 pTableController
->SetAttrToSelectedShape(aSet
);
116 // Then make sure the text edit is not ended:
117 CPPUNIT_ASSERT(pSdrView
->IsTextEdit());
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */