/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
auto pColorSet = pTheme->getColorSet();
CPPUNIT_ASSERT(pColorSet);
CPPUNIT_ASSERT_EQUAL(u"Orange"_ustr, pColorSet->getName());
CPPUNIT_ASSERT_EQUAL(Color(0xE48312), pTheme->GetColor(model::ThemeColorType::Accent1));
}
// Change theme colors
{ autoconst& rColorSets = svx::ColorSets::get(); auto pNewColorSet
= std::make_shared<model::ColorSet>(*rColorSets.getColorSet(u"LibreOffice")); // check that the theme colors are as expected
CPPUNIT_ASSERT_EQUAL(u"LibreOffice"_ustr, pNewColorSet->getName());
// A simple transferable, that provides only EMBED_SOURCE and OBJECTDESCRIPTOR flavors, taking // data from an ODT file. This makes the transferable behave just like clipboard content created // by Writer in a different instance, taking SwTransferable::PasteOLE path. class TestSimpleFileTransferable : public cppu::WeakImplHelper<css::datatransfer::XTransferable>
{ public:
TestSimpleFileTransferable(const OUString& fileURL);
css::uno::Any SAL_CALL getTransferData(const css::datatransfer::DataFlavor& flavor) override;
css::uno::Sequence<css::datatransfer::DataFlavor> SAL_CALL getTransferDataFlavors() override;
sal_Bool SAL_CALL isDataFlavorSupported(const css::datatransfer::DataFlavor& flavor) override;
sal_Bool
TestSimpleFileTransferable::isDataFlavorSupported(const css::datatransfer::DataFlavor& flavor)
{ if (flavor.MimeType == SotExchange::GetFormatMimeType(SotClipboardFormatId::EMBED_SOURCE)) returntrue; if (flavor.MimeType == SotExchange::GetFormatMimeType(SotClipboardFormatId::OBJECTDESCRIPTOR)) returntrue; returnfalse;
}
CPPUNIT_TEST_FIXTURE(SwCoreThemeTest, testTdf162715_customTransferable)
{ // Given a document with a custom theme:
createSwDoc("theme_foo.fodt");
auto pDoc = getSwDoc();
auto pModel = pDoc->getIDocumentDrawModelAccess().GetDrawModel();
CPPUNIT_ASSERT(pModel); auto pTheme = pModel->getTheme().get();
CPPUNIT_ASSERT(pTheme);
CPPUNIT_ASSERT_EQUAL(u"foo"_ustr, pTheme->GetName());
CPPUNIT_ASSERT_EQUAL(u"colors_foo"_ustr, pTheme->getColorSet()->getName());
CPPUNIT_ASSERT_EQUAL(Color(0x000080), pTheme->GetColor(model::ThemeColorType::Dark1));
CPPUNIT_ASSERT_EQUAL(Color(0x008000), pTheme->GetColor(model::ThemeColorType::Dark2));
// Select all and check the original text in the document: auto pWrtShell = getSwDocShell()->GetWrtShell();
pWrtShell->SelAll();
CPPUNIT_ASSERT_EQUAL(u"Theme foo"_ustr, pWrtShell->GetSelText());
// Create a transferable from another document with another custom theme, // and insert (paste) its content over the selection:
css::uno::Reference<css::datatransfer::XTransferable> xTransferable( new TestSimpleFileTransferable(createFileURL(u"theme_bar.odt")));
css::uno::Reference<css::frame::XModel> xModel(mxComponent, css::uno::UNO_QUERY_THROW);
css::uno::Reference<css::datatransfer::XTransferableSupplier> xTS(
xModel->getCurrentController(), css::uno::UNO_QUERY_THROW);
xTS->insertTransferable(xTransferable);
// Check that the paste is successful (the text has been replaced):
pWrtShell->SelAll();
CPPUNIT_ASSERT_EQUAL(u"Theme bar"_ustr, pWrtShell->GetSelText());
// The original theme must not be replaced.
pTheme = pModel->getTheme().get();
CPPUNIT_ASSERT(pTheme); // Without the fix, this would fail, because the name was "bar":
CPPUNIT_ASSERT_EQUAL(u"foo"_ustr, pTheme->GetName());
CPPUNIT_ASSERT_EQUAL(u"colors_foo"_ustr, pTheme->getColorSet()->getName());
CPPUNIT_ASSERT_EQUAL(Color(0x000080), pTheme->GetColor(model::ThemeColorType::Dark1));
CPPUNIT_ASSERT_EQUAL(Color(0x008000), pTheme->GetColor(model::ThemeColorType::Dark2));
}
CPPUNIT_TEST_FIXTURE(SwCoreThemeTest, testTdf162715_ownTransferable)
{
css::uno::Reference<css::datatransfer::XTransferable> xTransferable;
{ // Given a document with a custom theme:
createSwDoc("theme_bar.odt");
auto pDoc = getSwDoc();
auto pModel = pDoc->getIDocumentDrawModelAccess().GetDrawModel();
CPPUNIT_ASSERT(pModel); auto pTheme = pModel->getTheme().get();
CPPUNIT_ASSERT(pTheme);
CPPUNIT_ASSERT_EQUAL(u"bar"_ustr, pTheme->GetName());
CPPUNIT_ASSERT_EQUAL(u"colors_bar"_ustr, pTheme->getColorSet()->getName());
CPPUNIT_ASSERT_EQUAL(Color(0x606000), pTheme->GetColor(model::ThemeColorType::Dark1));
CPPUNIT_ASSERT_EQUAL(Color(0x800000), pTheme->GetColor(model::ThemeColorType::Dark2));
// Select all and check the original text in the document: auto pWrtShell = getSwDocShell()->GetWrtShell();
pWrtShell->SelAll();
CPPUNIT_ASSERT_EQUAL(u"Theme bar"_ustr, pWrtShell->GetSelText());
// Create a normal Writer's transferable out of the selection:
css::uno::Reference<css::frame::XModel> xModel(mxComponent, css::uno::UNO_QUERY_THROW);
css::uno::Reference<css::datatransfer::XTransferableSupplier> xTS(
xModel->getCurrentController(), css::uno::UNO_QUERY_THROW);
xTransferable = xTS->getTransferable();
}
{ // Open another document with another custom theme:
createSwDoc("theme_foo.fodt");
auto pDoc = getSwDoc();
auto pModel = pDoc->getIDocumentDrawModelAccess().GetDrawModel();
CPPUNIT_ASSERT(pModel); auto pTheme = pModel->getTheme().get();
CPPUNIT_ASSERT(pTheme);
CPPUNIT_ASSERT_EQUAL(u"foo"_ustr, pTheme->GetName());
CPPUNIT_ASSERT_EQUAL(u"colors_foo"_ustr, pTheme->getColorSet()->getName());
CPPUNIT_ASSERT_EQUAL(Color(0x000080), pTheme->GetColor(model::ThemeColorType::Dark1));
CPPUNIT_ASSERT_EQUAL(Color(0x008000), pTheme->GetColor(model::ThemeColorType::Dark2));
// Select all and check the original text in the second document: auto pWrtShell = getSwDocShell()->GetWrtShell();
pWrtShell->SelAll();
CPPUNIT_ASSERT_EQUAL(u"Theme foo"_ustr, pWrtShell->GetSelText());
// Insert (paste) the previously created transferable's content over the selection:
css::uno::Reference<css::frame::XModel> xModel(mxComponent, css::uno::UNO_QUERY_THROW);
css::uno::Reference<css::datatransfer::XTransferableSupplier> xTS(
xModel->getCurrentController(), css::uno::UNO_QUERY_THROW);
xTS->insertTransferable(xTransferable);
// Check that the paste is successful (the text has been replaced):
pWrtShell->SelAll();
CPPUNIT_ASSERT_EQUAL(u"Theme bar"_ustr, pWrtShell->GetSelText());
// The original theme must not be replaced.
pTheme = pModel->getTheme().get();
CPPUNIT_ASSERT(pTheme);
CPPUNIT_ASSERT_EQUAL(u"foo"_ustr, pTheme->GetName());
CPPUNIT_ASSERT_EQUAL(u"colors_foo"_ustr, pTheme->getColorSet()->getName());
CPPUNIT_ASSERT_EQUAL(Color(0x000080), pTheme->GetColor(model::ThemeColorType::Dark1));
CPPUNIT_ASSERT_EQUAL(Color(0x008000), pTheme->GetColor(model::ThemeColorType::Dark2));
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.