sd/inc/viewopt.hxx                           |   34 ++++++++++++++
 sd/qa/unit/tiledrendering/tiledrendering.cxx |   63 +++++++++++++++++++++++++++
 sd/source/ui/inc/DrawViewShell.hxx           |    5 +-
 sd/source/ui/inc/unomodel.hxx                |    3 +
 sd/source/ui/unoidl/unomodel.cxx             |   14 ++++++
 sd/source/ui/view/drviews4.cxx               |    2 
 sd/source/ui/view/drviews5.cxx               |    2 
 sd/source/ui/view/drviewsa.cxx               |    1 
 sd/source/ui/view/drviewsk.cxx               |   24 +++++++++-
 9 files changed, 142 insertions(+), 6 deletions(-)

New commits:
commit fa2fdc90d5fba9420cbb475f8c88423124c158ec
Author:     Paris Oplopoios <[email protected]>
AuthorDate: Wed Apr 12 04:23:56 2023 +0300
Commit:     Miklos Vajna <[email protected]>
CommitDate: Fri Apr 28 10:07:39 2023 +0200

    Add view options class in Draw
    
    Add SdViewOptions class in Draw to hold the view state and
    manage view separation in tiled rendering mode
    
    Change-Id: I1546fa536555b3262217ff4be163a48b958b7a33
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150249
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Miklos Vajna <[email protected]>

diff --git a/sd/inc/viewopt.hxx b/sd/inc/viewopt.hxx
new file mode 100644
index 000000000000..0e12dc067427
--- /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;
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx 
b/sd/qa/unit/tiledrendering/tiledrendering.cxx
index 67f81fa7be04..5c3325ad42f0 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>
@@ -120,6 +122,7 @@ public:
     void testTdf115873();
     void testTdf115873Group();
     void testCutSelectionChange();
+    void testThemeViewSeparation();
     void testRegenerateDiagram();
     void testLanguageAllText();
     void testInsertDeletePageInvalidation();
@@ -179,6 +182,7 @@ public:
     CPPUNIT_TEST(testTdf115873);
     CPPUNIT_TEST(testTdf115873Group);
     CPPUNIT_TEST(testCutSelectionChange);
+    CPPUNIT_TEST(testThemeViewSeparation);
     CPPUNIT_TEST(testRegenerateDiagram);
     CPPUNIT_TEST(testLanguageAllText);
     CPPUNIT_TEST(testInsertDeletePageInvalidation);
@@ -2534,6 +2538,65 @@ void SdTiledRenderingTest::testCutSelectionChange()
     CPPUNIT_ASSERT_EQUAL(static_cast<std::size_t>(0), m_aSelection.size());
 }
 
+// Helper function to get a tile to a bitmap and check the pixel color
+static void assertTilePixelColor(SdXImpressDocument* pXTextDocument, 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::DEFAULT);
+    pDevice->SetBackground(Wallpaper(COL_TRANSPARENT));
+    pDevice->SetOutputSizePixelScaleOffsetAndLOKBuffer(Size(nCanvasSize, 
nCanvasSize),
+            Fraction(1.0), Point(), aPixmap.data());
+    pXTextDocument->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
+void SdTiledRenderingTest::testThemeViewSeparation()
+{
+    SdXImpressDocument* pXTextDocument = createDoc("dummy.odp");
+    int nFirstViewId = SfxLokHelper::getView();
+    ViewCallback aView1;
+    // First view is at light mode
+    assertTilePixelColor(pXTextDocument, 255, 255, COL_WHITE);
+    // Create second view
+    SfxLokHelper::createView();
+    int nSecondViewId = SfxLokHelper::getView();
+    ViewCallback aView2;
+    // Set second view to dark mode
+    {
+        uno::Sequence<beans::PropertyValue> aPropertyValues = 
comphelper::InitPropertySequence(
+            {
+                { "NewTheme", 
uno::Any(OUString("COLOR_SCHEME_LIBREOFFICE_DARK")) },
+            }
+        );
+        dispatchCommand(mxComponent, ".uno:ChangeTheme", aPropertyValues);
+    }
+    assertTilePixelColor(pXTextDocument, 255, 255, Color(0x1c, 0x1c, 0x1c));
+    // First view still in light mode
+    SfxLokHelper::setView(nFirstViewId);
+    assertTilePixelColor(pXTextDocument, 255, 255, COL_WHITE);
+    // Second view still in dark mode
+    SfxLokHelper::setView(nSecondViewId);
+    assertTilePixelColor(pXTextDocument, 255, 255, Color(0x1c, 0x1c, 0x1c));
+    // Switch second view back to light mode
+    {
+        uno::Sequence<beans::PropertyValue> aPropertyValues = 
comphelper::InitPropertySequence(
+            {
+                { "NewTheme", 
uno::Any(OUString("COLOR_SCHEME_LIBREOFFICE_AUTOMATIC")) },
+            }
+        );
+        dispatchCommand(mxComponent, ".uno:ChangeTheme", aPropertyValues);
+    }
+    // Now in light mode
+    assertTilePixelColor(pXTextDocument, 255, 255, COL_WHITE);
+}
+
 void SdTiledRenderingTest::testRegenerateDiagram()
 {
     // Load the document.
diff --git a/sd/source/ui/inc/DrawViewShell.hxx 
b/sd/source/ui/inc/DrawViewShell.hxx
index a8e48c723d2e..beb2bec08c0a 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:
@@ -496,8 +498,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 98d5c4473f9b..3ff9a5a75af7 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 135f924eb220..4653de535761 100644
--- a/sd/source/ui/unoidl/unomodel.cxx
+++ b/sd/source/ui/unoidl/unomodel.cxx
@@ -2232,6 +2232,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)
@@ -2300,6 +2301,19 @@ void SdXImpressDocument::paintTile( VirtualDevice& 
rDevice,
     comphelper::LibreOfficeKit::setTiledPainting(false);
 }
 
+OString SdXImpressDocument::getViewRenderState()
+{
+    OStringBuffer aState;
+    DrawViewShell* pView = GetViewShell();
+    if (pView)
+    {
+        const SdViewOptions& pVOpt = pView->GetViewOptions();
+        if (pVOpt.msColorSchemeName == u"COLOR_SCHEME_LIBREOFFICE_DARK")
+            aState.append('D');
+    }
+    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 3eb9f39c376f..c6774537cfea 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 a345af61331b..2716bd489ab1 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..541b69534123 100644
--- a/sd/source/ui/view/drviewsk.cxx
+++ b/sd/source/ui/view/drviewsk.cxx
@@ -8,15 +8,35 @@
  */
 
 #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;
+        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().getStr());
+    }
 }
 
 void DrawViewShell::ConfigureAppBackgroundColor( svtools::ColorConfig 
*pColorConfig )
@@ -29,7 +49,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;
 }
 
 }

Reply via email to