sc/source/ui/inc/tabvwsh.hxx   |    2 +
 sc/source/ui/view/tabvwsh4.cxx |   65 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+)

New commits:
commit cad62803ba39c560a3e5bc3a51300cc1136b5afd
Author:     Sahil <me.sahilgau...@gmail.com>
AuthorDate: Sun Dec 3 05:48:20 2023 +0530
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Sat Dec 9 08:18:27 2023 +0100

    tdf#33210 Add Listener for ColumnRowHighlighting changes
    
    Listener updates Column/Row highlight if the expert
    configuration is changed
    
    Change-Id: Ibc220c4dd8f0b253029c7a0e54dd08f54f573114
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160152
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/sc/source/ui/inc/tabvwsh.hxx b/sc/source/ui/inc/tabvwsh.hxx
index b537af6900d2..dc05f235c990 100644
--- a/sc/source/ui/inc/tabvwsh.hxx
+++ b/sc/source/ui/inc/tabvwsh.hxx
@@ -91,8 +91,10 @@ enum ObjectSelectionType
 };
 
 class ScFormEditData;
+class ScViewOptiChangesListener;
 class SC_DLLPUBLIC ScTabViewShell : public SfxViewShell, public ScDBFunc
 {
+    rtl::Reference<ScViewOptiChangesListener> mChangesListener;
 private:
     struct SendFormulabarUpdate
     {
diff --git a/sc/source/ui/view/tabvwsh4.cxx b/sc/source/ui/view/tabvwsh4.cxx
index 345a33534d1c..986be06b4041 100644
--- a/sc/source/ui/view/tabvwsh4.cxx
+++ b/sc/source/ui/view/tabvwsh4.cxx
@@ -80,6 +80,8 @@
 #include <gridwin.hxx>
 
 #include <com/sun/star/document/XDocumentProperties.hpp>
+#include <com/sun/star/configuration/theDefaultProvider.hpp>
+#include <comphelper/processfactory.hxx>
 #include <sfx2/lokhelper.hxx>
 #include <comphelper/flagguard.hxx>
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
@@ -1687,6 +1689,65 @@ void ScTabViewShell::Construct( TriState 
nForceDesignMode )
     SetBorderPixel( aBorder );
 }
 
+class ScViewOptiChangesListener : public 
cppu::WeakImplHelper<util::XChangesListener>
+{
+public:
+    ScViewOptiChangesListener(ScTabViewShell&);
+    void stopListening();
+
+    virtual void SAL_CALL changesOccurred(const util::ChangesEvent& Event) 
override;
+    virtual void SAL_CALL disposing(const lang::EventObject& rEvent) override;
+
+private:
+    ScTabViewShell& mrViewShell;
+    uno::Reference<util::XChangesNotifier> m_xChangesNotifier;
+};
+
+void ScViewOptiChangesListener::stopListening()
+{
+    if (m_xChangesNotifier.is())
+        m_xChangesNotifier->removeChangesListener(this);
+}
+
+// virtual
+void SAL_CALL ScViewOptiChangesListener::changesOccurred(const 
util::ChangesEvent& rEvent)
+{
+    OUString sChangedEntry;
+    rEvent.Changes[0].Accessor >>= sChangedEntry;
+
+    if (sChangedEntry == "Display/ColumnRowHighlighting")
+        mrViewShell.GetViewData().GetView()->HighlightOverlay();
+}
+
+// virtual
+void SAL_CALL ScViewOptiChangesListener::disposing(const lang::EventObject& /* 
rEvent */)
+{
+    m_xChangesNotifier.clear();
+}
+
+ScViewOptiChangesListener::ScViewOptiChangesListener(ScTabViewShell& 
rViewShell)
+    : mrViewShell(rViewShell)
+{
+    // add a listener for configuration changes (ColumnRowHighlighting 
Checkbox)
+    uno::Reference<lang::XMultiServiceFactory> xConfigurationProvider(
+        
configuration::theDefaultProvider::get(comphelper::getProcessComponentContext()));
+
+    beans::NamedValue aProperty;
+    aProperty.Name = "nodepath";
+    aProperty.Value <<= OUString("/org.openoffice.Office.Calc/Content");
+
+    uno::Sequence<uno::Any> aArgumentList{ uno::Any(aProperty) };
+
+    uno::Reference<uno::XInterface> xConfigurationAccess
+        = xConfigurationProvider->createInstanceWithArguments(
+            "com.sun.star.configuration.ConfigurationAccess", aArgumentList);
+
+    m_xChangesNotifier.set(xConfigurationAccess, uno::UNO_QUERY);
+
+    if (m_xChangesNotifier.is())
+        m_xChangesNotifier->addChangesListener(this);
+}
+
 ScTabViewShell::ScTabViewShell( SfxViewFrame& rViewFrame,
                                 SfxViewShell* pOldSh ) :
     SfxViewShell(rViewFrame, SfxViewShellFlags::HAS_PRINTOPTIONS),
@@ -1772,6 +1833,8 @@ ScTabViewShell::ScTabViewShell( SfxViewFrame& rViewFrame,
     if (bInstalledScTabViewObjAsTempController)
         GetViewData().GetDocShell()->GetModel()->setCurrentController(nullptr);
 
+    mChangesListener.set(new ScViewOptiChangesListener(*this));
+
     // formula mode in online is not usable in collaborative mode,
     // this is a workaround for disabling formula mode in online
     // when there is more than a single view
@@ -1813,6 +1876,8 @@ ScTabViewShell::ScTabViewShell( SfxViewFrame& rViewFrame,
 ScTabViewShell::~ScTabViewShell()
 {
     bInDispose = true;
+    mChangesListener->stopListening();
+    mChangesListener.clear();
 
     // Notify other LOK views that we are going away.
     SfxLokHelper::notifyOtherViews(this, LOK_CALLBACK_VIEW_CURSOR_VISIBLE, 
"visible", "false"_ostr);

Reply via email to