sd/inc/viewopt.hxx                  |    4 ++
 sd/source/ui/inc/DrawViewShell.hxx  |    4 +-
 sd/source/ui/inc/ViewShellBase.hxx  |    4 ++
 sd/source/ui/view/ViewShellBase.cxx |   50 +++++++++++++++++++++++-------------
 sd/source/ui/view/drviewsa.cxx      |    1 
 sd/source/ui/view/drviewsj.cxx      |   11 +++++++
 sd/source/ui/view/drviewsk.cxx      |   19 ++++++++-----
 7 files changed, 65 insertions(+), 28 deletions(-)

New commits:
commit 2bacb30059ae87142a95abe191ea888a155024bc
Author:     Caolán McNamara <[email protected]>
AuthorDate: Wed Nov 20 09:49:55 2024 +0000
Commit:     Miklos Vajna <[email protected]>
CommitDate: Mon Nov 25 13:10:56 2024 +0100

    move SdViewOptions options down to ViewShellBase
    
    ViewShellBase is the SfxViewShell and is the analogue of the equivalent
    writer/calc SfxViewShell's, while a DrawViewShell is one of multiple
    sd::ViewShells that can exist inside that SfxViewShell
    
    Issue:
    * When creating new shell instances, background color is fetched from 
application configuration.
    * When multiple users are active on an Impress document, if one switches to 
notes view, a new shell is created.
    * Background color for the new shell is fetched from app colors.
    * If another user has switched to dark mode, the user which just switched 
to notes view, will see dark mode for their background.
    
    Moving the SdViewOptions options down the ViewShellBase means that
    multiple sd::ViewShells hosted within that ViewShellBase share the same
    view settings.
    
    Change-Id: Id875260dda89311ab8029ead08b47f80fd14604f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176827
    Reviewed-by: Miklos Vajna <[email protected]>
    Tested-by: Jenkins CollaboraOffice <[email protected]>

diff --git a/sd/inc/viewopt.hxx b/sd/inc/viewopt.hxx
index 03ebd2ada659..cf75d6f06156 100644
--- a/sd/inc/viewopt.hxx
+++ b/sd/inc/viewopt.hxx
@@ -23,12 +23,14 @@
 /// View options for the current view
 struct SdViewOptions
 {
+    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";
+    OUString msColorSchemeName;
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sd/source/ui/inc/DrawViewShell.hxx 
b/sd/source/ui/inc/DrawViewShell.hxx
index 8c91f4d6f0ff..e0750b6cecc0 100644
--- a/sd/source/ui/inc/DrawViewShell.hxx
+++ b/sd/source/ui/inc/DrawViewShell.hxx
@@ -376,7 +376,8 @@ public:
 
     bool IsInSwitchPage() const { return mbIsInSwitchPage; }
 
-    const SdViewOptions& GetViewOptions() const { return maViewOptions; }
+    const SdViewOptions& GetViewOptions() const;
+    void SetViewOptions(const SdViewOptions& rOptions);
     //move this method to ViewShell.
     //void  NotifyAccUpdate();
 
@@ -501,7 +502,6 @@ private:
     ::std::unique_ptr< AnnotationManager > mpAnnotationManager;
     ::std::unique_ptr< ViewOverlayManager > mpViewOverlayManager;
     std::vector<std::unique_ptr<SdrExternalToolEdit>> m_ExternalEdits;
-    SdViewOptions maViewOptions;
 
     css::uno::Reference<com::sun::star::presentation::XSlideShow> mxSlideShow;
 };
diff --git a/sd/source/ui/inc/ViewShellBase.hxx 
b/sd/source/ui/inc/ViewShellBase.hxx
index e31429f6e41a..be346f2c1452 100644
--- a/sd/source/ui/inc/ViewShellBase.hxx
+++ b/sd/source/ui/inc/ViewShellBase.hxx
@@ -24,6 +24,7 @@
 #include <memory>
 
 class SdDrawDocument;
+struct SdViewOptions;
 class SfxRequest;
 
 namespace sd::tools {
@@ -227,6 +228,9 @@ public:
     void setLOKVisibleArea(const ::tools::Rectangle& rArea) { maLOKVisibleArea 
= rArea; }
     virtual ::tools::Rectangle getLOKVisibleArea() const override { return 
maLOKVisibleArea; }
 
+    const SdViewOptions& GetViewOptions() const;
+    void SetViewOptions(const SdViewOptions& rOptions) const;
+
 protected:
 
     virtual void Notify(SfxBroadcaster& rBC, const SfxHint& rHint) override;
diff --git a/sd/source/ui/view/ViewShellBase.cxx 
b/sd/source/ui/view/ViewShellBase.cxx
index 4dbf0f20653a..ebe795676be6 100644
--- a/sd/source/ui/view/ViewShellBase.cxx
+++ b/sd/source/ui/view/ViewShellBase.cxx
@@ -113,6 +113,8 @@ namespace sd {
 class ViewShellBase::Implementation
 {
 public:
+    SdViewOptions maViewOptions;
+
     /** Main controller of the view shell.  During the switching from one
         stacked shell to another this pointer may be NULL.
     */
@@ -913,6 +915,16 @@ OUString ViewShellBase::GetInitialViewShellType() const
     return sRequestedView;
 }
 
+const SdViewOptions& ViewShellBase::GetViewOptions() const
+{
+    return mpImpl->maViewOptions;
+}
+
+void ViewShellBase::SetViewOptions(const SdViewOptions& rOptions) const
+{
+    mpImpl->maViewOptions = rOptions;
+}
+
 std::shared_ptr<tools::EventMultiplexer> const & 
ViewShellBase::GetEventMultiplexer() const
 {
     OSL_ASSERT(mpImpl != nullptr);
@@ -1129,28 +1141,24 @@ void ViewShellBase::NotifyCursor(SfxViewShell* 
pOtherShell) const
 
 ::Color ViewShellBase::GetColorConfigColor(svtools::ColorConfigEntry 
nColorType) const
 {
-    if (DrawViewShell* pCurrentDrawShell = 
dynamic_cast<DrawViewShell*>(GetMainViewShell().get()))
+    Color aColor;
+
+    const SdViewOptions& rViewOptions = GetViewOptions();
+    switch (nColorType)
     {
-        const SdViewOptions& rViewOptions = 
pCurrentDrawShell->GetViewOptions();
-        switch (nColorType)
+        case svtools::ColorConfigEntry::DOCCOLOR:
         {
-            case svtools::ColorConfigEntry::DOCCOLOR:
-            {
-                return rViewOptions.mnDocBackgroundColor;
-            }
-            // Should never be called for an unimplemented color type
-            default:
-            {
-                O3TL_UNREACHABLE;
-            }
+            aColor = rViewOptions.mnDocBackgroundColor;
+            break;
+        }
+        // Should never be called for an unimplemented color type
+        default:
+        {
+            O3TL_UNREACHABLE;
         }
-    }
-    else
-    {
-        SAL_WARN("sd", "dynamic_cast to DrawViewShell failed");
     }
 
-    return {};
+    return aColor;
 }
 
 //===== ViewShellBase::Implementation =========================================
@@ -1527,6 +1535,14 @@ void CurrentPageSetter::operator() (bool)
 
 } // end of anonymous namespace
 
+SdViewOptions::SdViewOptions()
+    : msColorSchemeName("Default")
+{
+    const svtools::ColorConfig& rColorConfig = SD_MOD()->GetColorConfig();
+    mnAppBackgroundColor = 
rColorConfig.GetColorValue(svtools::APPBACKGROUND).nColor;
+    mnDocBackgroundColor = 
rColorConfig.GetColorValue(svtools::DOCCOLOR).nColor;
+}
+
 //===== FocusForwardingWindow =================================================
 
 namespace sd {
diff --git a/sd/source/ui/view/drviewsa.cxx b/sd/source/ui/view/drviewsa.cxx
index df068e72c665..428ff561b0bf 100644
--- a/sd/source/ui/view/drviewsa.cxx
+++ b/sd/source/ui/view/drviewsa.cxx
@@ -133,7 +133,6 @@ DrawViewShell::DrawViewShell( ViewShellBase& 
rViewShellBase, vcl::Window* pParen
 
     ConfigureAppBackgroundColor();
     SD_MOD()->GetColorConfig().AddListener(this);
-    maViewOptions.mnDocBackgroundColor = 
SD_MOD()->GetColorConfig().GetColorValue(svtools::DOCCOLOR).nColor;
 
     if (comphelper::LibreOfficeKit::isActive())
     {
diff --git a/sd/source/ui/view/drviewsj.cxx b/sd/source/ui/view/drviewsj.cxx
index 55103bf67573..ebe8a9955891 100644
--- a/sd/source/ui/view/drviewsj.cxx
+++ b/sd/source/ui/view/drviewsj.cxx
@@ -38,6 +38,7 @@
 #include <anminfo.hxx>
 #include <drawdoc.hxx>
 #include <drawview.hxx>
+#include <ViewShellBase.hxx>
 
 using namespace com::sun::star;
 
@@ -562,6 +563,16 @@ void DrawViewShell::GetMenuStateSel( SfxItemSet &rSet )
     }
 }
 
+const SdViewOptions& DrawViewShell::GetViewOptions() const
+{
+    return GetViewShellBase().GetViewOptions();
+}
+
+void DrawViewShell::SetViewOptions(const SdViewOptions& rOptions)
+{
+    GetViewShellBase().SetViewOptions(rOptions);
+}
+
 } // end of namespace sd
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sd/source/ui/view/drviewsk.cxx b/sd/source/ui/view/drviewsk.cxx
index cb40d8398f04..b4d7f673c2fd 100644
--- a/sd/source/ui/view/drviewsk.cxx
+++ b/sd/source/ui/view/drviewsk.cxx
@@ -30,18 +30,21 @@ void DrawViewShell::ConfigurationChanged( 
utl::ConfigurationBroadcaster* pCb, Co
     svtools::ColorConfig *pColorConfig = 
dynamic_cast<svtools::ColorConfig*>(pCb);
     ConfigureAppBackgroundColor(pColorConfig);
     if (!comphelper::LibreOfficeKit::isActive())
-        maViewOptions.mnDocBackgroundColor = 
pColorConfig->GetColorValue(svtools::DOCCOLOR).nColor;
+    {
+        SdViewOptions aViewOptions = GetViewOptions();
+        aViewOptions.mnDocBackgroundColor = 
pColorConfig->GetColorValue(svtools::DOCCOLOR).nColor;
+        SetViewOptions(aViewOptions);
+    }
     else
     {
         SfxViewShell* pCurrentShell = SfxViewShell::Current();
         ViewShellBase* pShellBase = 
dynamic_cast<ViewShellBase*>(pCurrentShell);
         if (!pShellBase)
             return;
-        if (DrawViewShell* pCurrentDrawShell = 
dynamic_cast<DrawViewShell*>(pShellBase->GetMainViewShell().get()))
-        {
-            pCurrentDrawShell->maViewOptions.mnDocBackgroundColor = 
pColorConfig->GetColorValue(svtools::DOCCOLOR).nColor;
-            pCurrentDrawShell->maViewOptions.msColorSchemeName = 
svtools::ColorConfig::GetCurrentSchemeName();
-        }
+        SdViewOptions aViewOptions = pShellBase->GetViewOptions();
+        aViewOptions.mnDocBackgroundColor = 
pColorConfig->GetColorValue(svtools::DOCCOLOR).nColor;
+        aViewOptions.msColorSchemeName = 
svtools::ColorConfig::GetCurrentSchemeName();
+        pShellBase->SetViewOptions(aViewOptions);
         SdXImpressDocument* pDoc = 
comphelper::getFromUnoTunnel<SdXImpressDocument>(pCurrentShell->GetCurrentDocument());
         SfxLokHelper::notifyViewRenderState(pCurrentShell, pDoc);
         Color 
aFillColor(pColorConfig->GetColorValue(svtools::APPBACKGROUND).nColor);
@@ -60,7 +63,9 @@ void DrawViewShell::ConfigureAppBackgroundColor( 
svtools::ColorConfig *pColorCon
     // tdf#87905 Use darker background color for master view
     if (meEditMode == EditMode::MasterPage)
         aFillColor.DecreaseLuminance( 64 );
-    maViewOptions.mnAppBackgroundColor = aFillColor;
+    SdViewOptions aViewOptions = GetViewOptions();
+    aViewOptions.mnAppBackgroundColor = aFillColor;
+    SetViewOptions(aViewOptions);
 }
 
 void DrawViewShell::destroyXSlideShowInstance()

Reply via email to