diff --git a/sd/qa/unit/misc-tests.cxx b/sd/qa/unit/misc-tests.cxx index 81583a9498ea..a50461ec119c 100644 --- a/sd/qa/unit/misc-tests.cxx +++ b/sd/qa/unit/misc-tests.cxx @@ -25,7 +25,10 @@ #include #include #include +#include +#include +#include #include #include #include @@ -70,6 +73,7 @@ public: void testTdf99396(); void testTableObjectUndoTest(); + void testFillColor(); void testFillGradient(); void testTdf44774(); void testTdf38225(); @@ -96,6 +100,7 @@ public: CPPUNIT_TEST_SUITE(SdMiscTest); CPPUNIT_TEST(testTdf99396); CPPUNIT_TEST(testTableObjectUndoTest); + CPPUNIT_TEST(testFillColor); CPPUNIT_TEST(testFillGradient); CPPUNIT_TEST(testTdf44774); CPPUNIT_TEST(testTdf38225); @@ -264,6 +269,66 @@ void SdMiscTest::testTableObjectUndoTest() CPPUNIT_ASSERT_EQUAL(u"Format cell"_ustr, pDoc->GetUndoManager()->GetUndoActionComment(2)); } +void SdMiscTest::testFillColor() +{ + // Test if setting the shape fill color from color to transparent automatically turns off the fill style to none + createSdImpressDoc(); + uno::Reference xDrawPagesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xDrawPages = xDrawPagesSupplier->getDrawPages(); + // Insert a new page. + uno::Reference xDrawPage(xDrawPages->insertNewByIndex(0), + uno::UNO_SET_THROW); + uno::Reference xShapes(xDrawPage, uno::UNO_QUERY_THROW); + // Create a rectangle + uno::Reference xFactory(mxComponent, uno::UNO_QUERY); + CPPUNIT_ASSERT(xFactory.is()); + uno::Reference xShape1( + xFactory->createInstance(u"com.sun.star.drawing.RectangleShape"_ustr), + uno::UNO_QUERY_THROW); + uno::Reference xPropSet(xShape1, uno::UNO_QUERY_THROW); + // Set FillStyle and FillColor + xPropSet->setPropertyValue(u"FillStyle"_ustr, uno::Any(drawing::FillStyle_SOLID)); + xPropSet->setPropertyValue(u"FillColor"_ustr, uno::Any(COL_RED)); + // Add the rectangle to the page. + xShapes->add(xShape1); + + // Retrieve the shape and check FillStyle and FillGradient + uno::Reference xIndexAccess(xDrawPage, uno::UNO_QUERY_THROW); + uno::Reference xPropSet2(xIndexAccess->getByIndex(0), + uno::UNO_QUERY_THROW); + drawing::FillStyle eFillStyle; + Color aColor; + CPPUNIT_ASSERT(xPropSet2->getPropertyValue(u"FillStyle"_ustr) >>= eFillStyle); + CPPUNIT_ASSERT_EQUAL(int(drawing::FillStyle_SOLID), static_cast(eFillStyle)); + CPPUNIT_ASSERT(xPropSet2->getPropertyValue(u"FillColor"_ustr) >>= aColor); + + CPPUNIT_ASSERT_EQUAL(COL_RED, aColor); + + // Setup transparent color and check fill styles + uno::Reference xModel(mxComponent, uno::UNO_QUERY); + uno::Reference xSelectionSupplier(xModel->getCurrentController(), + uno::UNO_QUERY); + + xSelectionSupplier->select(uno::Any(xShape1)); + CPPUNIT_ASSERT(xSelectionSupplier->getSelection().hasValue()); + + const char arguments[] = "{" + "\"FillColor.Color\":{" + "\"type\":\"long\"," + "\"value\":-1" + "}}"; + + dispatchCommand(mxComponent, u".uno:FillColor"_ustr, + comphelper::containerToSequence(comphelper::JsonToPropertyValues(arguments))); + + uno::Reference xIndexAccess2(xDrawPage, uno::UNO_QUERY_THROW); + uno::Reference xPropSet3(xIndexAccess2->getByIndex(0), + uno::UNO_QUERY_THROW); + drawing::FillStyle eFillStyle2; + CPPUNIT_ASSERT(xPropSet3->getPropertyValue(u"FillStyle"_ustr) >>= eFillStyle2); + CPPUNIT_ASSERT_EQUAL(int(drawing::FillStyle_NONE), static_cast(eFillStyle2)); +} + void SdMiscTest::testFillGradient() { createSdImpressDoc(); diff --git a/sd/source/ui/view/drviews2.cxx b/sd/source/ui/view/drviews2.cxx index 78ec12e62f22..19ee05c1f48c 100644 --- a/sd/source/ui/view/drviews2.cxx +++ b/sd/source/ui/view/drviews2.cxx @@ -622,10 +622,29 @@ public: } }; - void lcl_convertStringArguments(const std::unique_ptr& pArgs) + void lcl_convertStringArguments(sal_uInt16 nSId, const std::unique_ptr& pArgs) { const SfxPoolItem* pItem = nullptr; + if (nSId == SID_ATTR_FILL_COLOR) + { + pItem = pArgs->GetItem(SID_ATTR_FILL_COLOR); + Color aColor = pItem ? static_cast(pItem)->GetColorValue() : COL_AUTO; + if (aColor.IsFullyTransparent()) + { + const XFillStyleItem aXFillStyleItem(drawing::FillStyle_NONE); + pArgs->Put(aXFillStyleItem); + } + else + { + SfxItemState eState = pArgs->GetItemState(SID_ATTR_FILL_STYLE, false, &pItem); + if (eState != SfxItemState::SET || static_cast(pItem)->GetValue() == drawing::FillStyle_NONE) + { + const XFillStyleItem aXFillStyleItem(drawing::FillStyle_SOLID); + pArgs->Put(aXFillStyleItem); + } + } + } if (SfxItemState::SET == pArgs->GetItemState(SID_ATTR_LINE_WIDTH_ARG, false, &pItem)) { double fValue = static_cast(pItem)->GetValue(); @@ -739,12 +758,7 @@ void DrawViewShell::FuTemporary(SfxRequest& rReq) if( rReq.GetArgs() ) { std::unique_ptr pNewArgs = rReq.GetArgs()->Clone(); - if (nSId == SID_ATTR_FILL_COLOR) - { - const XFillStyleItem aXFillStyleItem; - pNewArgs->Put(aXFillStyleItem); - } - lcl_convertStringArguments(pNewArgs); + lcl_convertStringArguments(nSId, pNewArgs); mpDrawView->SetAttributes(*pNewArgs); rReq.Done(); }