diff options
-rw-r--r-- | sd/inc/viewopt.hxx | 34 | ||||
-rw-r--r-- | sd/qa/unit/tiledrendering/tiledrendering.cxx | 114 | ||||
-rw-r--r-- | sd/source/ui/inc/DrawViewShell.hxx | 5 | ||||
-rw-r--r-- | sd/source/ui/inc/unomodel.hxx | 3 | ||||
-rw-r--r-- | sd/source/ui/unoidl/unomodel.cxx | 16 | ||||
-rw-r--r-- | sd/source/ui/view/drviews4.cxx | 2 | ||||
-rw-r--r-- | sd/source/ui/view/drviews5.cxx | 2 | ||||
-rw-r--r-- | sd/source/ui/view/drviewsa.cxx | 1 | ||||
-rw-r--r-- | sd/source/ui/view/drviewsk.cxx | 25 |
9 files changed, 196 insertions, 6 deletions
diff --git a/sd/inc/viewopt.hxx b/sd/inc/viewopt.hxx new file mode 100644 index 000000000000..03ebd2ada659 --- /dev/null +++ b/sd/inc/viewopt.hxx @@ -0,0 +1,34 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <rtl/ustring.hxx> +#include <tools/color.hxx> + +/// View options for the current view +struct SdViewOptions +{ + // The color of the area behind the slide (used to be called "Wiese") + Color mnAppBackgroundColor; + // The color of the document background + Color mnDocBackgroundColor; + // The name of the color scheme + OUString msColorSchemeName = "Default"; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx index 40eb72c1c098..91a929a11d07 100644 --- a/sd/qa/unit/tiledrendering/tiledrendering.cxx +++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx @@ -51,6 +51,8 @@ #include <vcl/cursor.hxx> #include <vcl/scheduler.hxx> #include <vcl/vclevent.hxx> +#include <vcl/BitmapReadAccess.hxx> +#include <vcl/virdev.hxx> #include <o3tl/string_view.hxx> #include <chrono> @@ -2391,6 +2393,118 @@ CPPUNIT_TEST_FIXTURE(SdTiledRenderingTest, testCutSelectionChange) CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(0), m_aSelection.size()); } +CPPUNIT_TEST_FIXTURE(SdTiledRenderingTest, testGetViewRenderState) +{ + SdXImpressDocument* pXImpressDocument = createDoc("dummy.odp"); + int nFirstViewId = SfxLokHelper::getView(); + ViewCallback aView1; + CPPUNIT_ASSERT_EQUAL(OString(";Default"), pXImpressDocument->getViewRenderState()); + // Create a second view + SfxLokHelper::createView(); + ViewCallback aView2; + CPPUNIT_ASSERT_EQUAL(OString(";Default"), pXImpressDocument->getViewRenderState()); + // Set to dark scheme + { + uno::Sequence<beans::PropertyValue> aPropertyValues = comphelper::InitPropertySequence( + { + { "NewTheme", uno::Any(OUString("Dark")) }, + } + ); + dispatchCommand(mxComponent, ".uno:ChangeTheme", aPropertyValues); + } + CPPUNIT_ASSERT_EQUAL(OString(";Dark"), pXImpressDocument->getViewRenderState()); + // Switch back to the first view, and check that the options string is the same + SfxLokHelper::setView(nFirstViewId); + CPPUNIT_ASSERT_EQUAL(OString(";Default"), pXImpressDocument->getViewRenderState()); +} + +// Helper function to get a tile to a bitmap and check the pixel color +static void assertTilePixelColor(SdXImpressDocument* pXImpressDocument, int nPixelX, int nPixelY, Color aColor) +{ + size_t nCanvasSize = 1024; + size_t nTileSize = 256; + std::vector<unsigned char> aPixmap(nCanvasSize * nCanvasSize * 4, 0); + ScopedVclPtrInstance<VirtualDevice> pDevice(DeviceFormat::WITHOUT_ALPHA); + pDevice->SetBackground(Wallpaper(COL_TRANSPARENT)); + pDevice->SetOutputSizePixelScaleOffsetAndLOKBuffer(Size(nCanvasSize, nCanvasSize), + Fraction(1.0), Point(), aPixmap.data()); + pXImpressDocument->paintTile(*pDevice, nCanvasSize, nCanvasSize, 0, 0, 15360, 7680); + pDevice->EnableMapMode(false); + Bitmap aBitmap = pDevice->GetBitmap(Point(0, 0), Size(nTileSize, nTileSize)); + Bitmap::ScopedReadAccess pAccess(aBitmap); + Color aActualColor(pAccess->GetPixel(nPixelX, nPixelY)); + CPPUNIT_ASSERT_EQUAL(aColor, aActualColor); +} + +// Test that changing the theme in one view doesn't change it in the other view +CPPUNIT_TEST_FIXTURE(SdTiledRenderingTest, testThemeViewSeparation) +{ + Color aDarkColor(0x1c, 0x1c, 0x1c); + // Add a minimal dark scheme + { + svtools::EditableColorConfig aColorConfig; + svtools::ColorConfigValue aValue; + aValue.bIsVisible = true; + aValue.nColor = aDarkColor; + aColorConfig.SetColorValue(svtools::DOCCOLOR, aValue); + aColorConfig.AddScheme(u"Dark"); + } + // Add a minimal light scheme + { + svtools::EditableColorConfig aColorConfig; + svtools::ColorConfigValue aValue; + aValue.bIsVisible = true; + aValue.nColor = COL_WHITE; + aColorConfig.SetColorValue(svtools::DOCCOLOR, aValue); + aColorConfig.AddScheme(u"Light"); + } + SdXImpressDocument* pXImpressDocument = createDoc("dummy.odp"); + int nFirstViewId = SfxLokHelper::getView(); + ViewCallback aView1; + // Switch first view to light scheme + { + uno::Sequence<beans::PropertyValue> aPropertyValues = comphelper::InitPropertySequence( + { + { "NewTheme", uno::Any(OUString("Light")) }, + } + ); + dispatchCommand(mxComponent, ".uno:ChangeTheme", aPropertyValues); + } + // First view is at light scheme + assertTilePixelColor(pXImpressDocument, 255, 255, COL_WHITE); + // Create second view + SfxLokHelper::createView(); + int nSecondViewId = SfxLokHelper::getView(); + ViewCallback aView2; + // Set second view to dark scheme + { + uno::Sequence<beans::PropertyValue> aPropertyValues = comphelper::InitPropertySequence( + { + { "NewTheme", uno::Any(OUString("Dark")) }, + } + ); + dispatchCommand(mxComponent, ".uno:ChangeTheme", aPropertyValues); + } + assertTilePixelColor(pXImpressDocument, 255, 255, aDarkColor); + // First view still in light scheme + SfxLokHelper::setView(nFirstViewId); + assertTilePixelColor(pXImpressDocument, 255, 255, COL_WHITE); + // Second view still in dark scheme + SfxLokHelper::setView(nSecondViewId); + assertTilePixelColor(pXImpressDocument, 255, 255, Color(0x1c, 0x1c, 0x1c)); + // Switch second view back to light scheme + { + uno::Sequence<beans::PropertyValue> aPropertyValues = comphelper::InitPropertySequence( + { + { "NewTheme", uno::Any(OUString("Light")) }, + } + ); + dispatchCommand(mxComponent, ".uno:ChangeTheme", aPropertyValues); + } + // Now in light scheme + assertTilePixelColor(pXImpressDocument, 255, 255, COL_WHITE); +} + CPPUNIT_TEST_FIXTURE(SdTiledRenderingTest, testRegenerateDiagram) { // Load the document. diff --git a/sd/source/ui/inc/DrawViewShell.hxx b/sd/source/ui/inc/DrawViewShell.hxx index 15f1dc9888c3..d3047cdeaf94 100644 --- a/sd/source/ui/inc/DrawViewShell.hxx +++ b/sd/source/ui/inc/DrawViewShell.hxx @@ -28,6 +28,7 @@ #include <unotools/caserotate.hxx> #include <unotools/options.hxx> #include <sddllapi.h> +#include <viewopt.hxx> namespace svx::sidebar { class SelectionChangeHandler; } namespace com::sun::star::lang { class XEventListener; } @@ -373,6 +374,7 @@ public: bool IsInSwitchPage() const { return mbIsInSwitchPage; } + const SdViewOptions& GetViewOptions() const { return maViewOptions; } //move this method to ViewShell. //void NotifyAccUpdate(); protected: @@ -498,8 +500,7 @@ private: ::std::unique_ptr< AnnotationManager > mpAnnotationManager; ::std::unique_ptr< ViewOverlayManager > mpViewOverlayManager; std::vector<std::unique_ptr<SdrExternalToolEdit>> m_ExternalEdits; - // The colour of the area behind the slide (used to be called "Wiese") - Color mnAppBackgroundColor; + SdViewOptions maViewOptions; }; /// Merge the background properties together and deposit the result in rMergeAttr diff --git a/sd/source/ui/inc/unomodel.hxx b/sd/source/ui/inc/unomodel.hxx index ba2602b86e60..f31d93b97420 100644 --- a/sd/source/ui/inc/unomodel.hxx +++ b/sd/source/ui/inc/unomodel.hxx @@ -284,6 +284,9 @@ public: /// @see vcl::ITiledRenderable::setPaintTextEdit(). virtual void setPaintTextEdit(bool bPaint) override { mbPaintTextEdit = bPaint; } + /// @see vcl::ITiledRenderable::getViewRenderState(). + OString getViewRenderState() override; + // XComponent /** This dispose implementation releases the resources held by the diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx index 37c650d4a465..f53144d14775 100644 --- a/sd/source/ui/unoidl/unomodel.cxx +++ b/sd/source/ui/unoidl/unomodel.cxx @@ -2233,6 +2233,7 @@ void SdXImpressDocument::paintTile( VirtualDevice& rDevice, { if(SdrPageView* pSdrPageView = pDrawView->GetSdrPageView()) { + pSdrPageView->SetApplicationDocumentColor(pViewSh->GetViewOptions().mnDocBackgroundColor); patchedPageWindow = pSdrPageView->FindPageWindow(*getDocWindow()->GetOutDev()); temporaryPaintWindow.reset(new SdrPaintWindow(*pDrawView, rDevice)); if (patchedPageWindow) @@ -2301,6 +2302,21 @@ void SdXImpressDocument::paintTile( VirtualDevice& rDevice, comphelper::LibreOfficeKit::setTiledPainting(false); } +OString SdXImpressDocument::getViewRenderState() +{ + OStringBuffer aState; + DrawViewShell* pView = GetViewShell(); + if (pView) + { + const SdViewOptions& pVOpt = pView->GetViewOptions(); + aState.append(';'); + + OString aThemeName = OUStringToOString(pVOpt.msColorSchemeName, RTL_TEXTENCODING_UTF8); + aState.append(aThemeName); + } + return aState.makeStringAndClear(); +} + void SdXImpressDocument::selectPart(int nPart, int nSelect) { DrawViewShell* pViewSh = GetViewShell(); diff --git a/sd/source/ui/view/drviews4.cxx b/sd/source/ui/view/drviews4.cxx index b21789c80137..8919a52d380f 100644 --- a/sd/source/ui/view/drviews4.cxx +++ b/sd/source/ui/view/drviews4.cxx @@ -401,7 +401,7 @@ void DrawViewShell::MouseMove(const MouseEvent& rMEvt, ::sd::Window* pWin) if (GetDoc()) { ConfigureAppBackgroundColor(); - mpDrawView->SetApplicationBackgroundColor( mnAppBackgroundColor ); + mpDrawView->SetApplicationBackgroundColor( GetViewOptions().mnAppBackgroundColor ); } ViewShell::MouseMove(rMEvt, pWin); diff --git a/sd/source/ui/view/drviews5.cxx b/sd/source/ui/view/drviews5.cxx index 0ad1a18a6c2c..4ca53557cac1 100644 --- a/sd/source/ui/view/drviews5.cxx +++ b/sd/source/ui/view/drviews5.cxx @@ -412,7 +412,7 @@ void DrawViewShell::Paint(const ::tools::Rectangle& rRect, ::sd::Window* pWin) GetDoc()->GetDrawOutliner().SetDefaultLanguage( GetDoc()->GetLanguage( EE_CHAR_LANGUAGE ) ); // Set Application Background color for usage in SdrPaintView(s) - mpDrawView->SetApplicationBackgroundColor( mnAppBackgroundColor ); + mpDrawView->SetApplicationBackgroundColor( GetViewOptions().mnAppBackgroundColor ); /* This is done before each text edit, so why not do it before every paint. The default language is only used if the outliner only contains one diff --git a/sd/source/ui/view/drviewsa.cxx b/sd/source/ui/view/drviewsa.cxx index dbc410ca2545..2868c38d6c90 100644 --- a/sd/source/ui/view/drviewsa.cxx +++ b/sd/source/ui/view/drviewsa.cxx @@ -129,6 +129,7 @@ DrawViewShell::DrawViewShell( ViewShellBase& rViewShellBase, vcl::Window* pParen ConfigureAppBackgroundColor(); SD_MOD()->GetColorConfig().AddListener(this); + maViewOptions.mnDocBackgroundColor = SD_MOD()->GetColorConfig().GetColorValue(svtools::DOCCOLOR).nColor; } DrawViewShell::~DrawViewShell() diff --git a/sd/source/ui/view/drviewsk.cxx b/sd/source/ui/view/drviewsk.cxx index 9daeecc02e4f..673416aff4f7 100644 --- a/sd/source/ui/view/drviewsk.cxx +++ b/sd/source/ui/view/drviewsk.cxx @@ -8,15 +8,36 @@ */ #include <DrawViewShell.hxx> +#include <ViewShellBase.hxx> #include <sdmod.hxx> #include <comphelper/lok.hxx> +#include <comphelper/servicehelper.hxx> +#include <sfx2/lokhelper.hxx> +#include <LibreOfficeKit/LibreOfficeKitEnums.h> +#include <unomodel.hxx> namespace sd { void DrawViewShell::ConfigurationChanged( utl::ConfigurationBroadcaster* pCb, ConfigurationHints ) { - ConfigureAppBackgroundColor( dynamic_cast<svtools::ColorConfig*>(pCb) ); + svtools::ColorConfig *pColorConfig = dynamic_cast<svtools::ColorConfig*>(pCb); + ConfigureAppBackgroundColor(pColorConfig); + SfxViewShell* pCurrentShell = SfxViewShell::Current(); + if (comphelper::LibreOfficeKit::isActive() && pCurrentShell) + { + DrawViewShell* pCurrentDrawShell = nullptr; + ViewShellBase* pShellBase = dynamic_cast<ViewShellBase*>(pCurrentShell); + if(pShellBase) + pCurrentDrawShell = dynamic_cast<DrawViewShell*>(pShellBase->GetMainViewShell().get()); + pCurrentDrawShell->maViewOptions.mnDocBackgroundColor = pColorConfig->GetColorValue(svtools::DOCCOLOR).nColor; + pCurrentDrawShell->maViewOptions.msColorSchemeName = pColorConfig->GetCurrentSchemeName(); + SdXImpressDocument* pDoc = comphelper::getFromUnoTunnel<SdXImpressDocument>(pCurrentShell->GetCurrentDocument()); + SfxLokHelper::notifyViewRenderState(pCurrentShell, pDoc); + Color aFillColor(pColorConfig->GetColorValue(svtools::APPBACKGROUND).nColor); + SfxViewShell::Current()->libreOfficeKitViewCallback(LOK_CALLBACK_APPLICATION_BACKGROUND_COLOR, + aFillColor.AsRGBHexString().toUtf8()); + } } void DrawViewShell::ConfigureAppBackgroundColor( svtools::ColorConfig *pColorConfig ) @@ -29,7 +50,7 @@ void DrawViewShell::ConfigureAppBackgroundColor( svtools::ColorConfig *pColorCon // tdf#87905 Use darker background color for master view if (meEditMode == EditMode::MasterPage) aFillColor.DecreaseLuminance( 64 ); - mnAppBackgroundColor = aFillColor; + maViewOptions.mnAppBackgroundColor = aFillColor; } } |