include/svl/hint.hxx             |    1 
 sfx2/source/dialog/StyleList.cxx |   84 ++++++++++++++++++++++++++-------------
 sw/source/uibase/uiview/view.cxx |    8 +++
 3 files changed, 67 insertions(+), 26 deletions(-)

New commits:
commit 93c5737d5cd5fd243a61d37fcf846ff077516e05
Author:     Caolán McNamara <[email protected]>
AuthorDate: Thu Dec 12 20:21:40 2024 +0000
Commit:     Miklos Vajna <[email protected]>
CommitDate: Mon Dec 16 09:18:13 2024 +0100

    Replace workaround of resize to invalidate with an explicit SfxHint
    
    Change-Id: Ic0c8ba5e5f65f7b1e472a667b69e737f4f1d9fbc
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178392
    Reviewed-by: Szymon Kłos <[email protected]>
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Miklos Vajna <[email protected]>

diff --git a/include/svl/hint.hxx b/include/svl/hint.hxx
index ec0c7b1d9872..02a38746ecfa 100644
--- a/include/svl/hint.hxx
+++ b/include/svl/hint.hxx
@@ -107,6 +107,7 @@ enum class SfxHintId {
     StyleSheetChanged,  // erased and re-created (replaced)
     StyleSheetErased,  // erased
     StyleSheetInDestruction,  // in the process of being destructed
+    StylesHighlighterModified,  // what styles to highlight in a document 
changed
 
 // STARMATH
     MathFormatChanged,
diff --git a/sfx2/source/dialog/StyleList.cxx b/sfx2/source/dialog/StyleList.cxx
index 0d23c4361f16..d241adb5127f 100644
--- a/sfx2/source/dialog/StyleList.cxx
+++ b/sfx2/source/dialog/StyleList.cxx
@@ -1000,6 +1000,54 @@ IMPL_LINK(StyleList, EnableTreeDrag, bool, m_bEnable, 
void)
     m_bTreeDrag = m_bEnable;
 }
 
+namespace
+{
+class StyleHighlightUpdateGuard
+{
+private:
+    bool m_bOrigMapHasEntries;
+    SfxViewShell* m_pViewShell;
+    StylesHighlighterColorMap* m_pHighlighterColorMap;
+    SfxStyleSheetBasePool& m_rStyleSheetPool;
+
+public:
+    StyleHighlightUpdateGuard(SfxViewShell* pViewShell, bool 
bModuleHasStylesHighlighterFeature,
+                              SfxStyleSheetBasePool& rStyleSheetPool, 
SfxStyleFamily eFam)
+        : m_bOrigMapHasEntries(false)
+        , m_pViewShell(pViewShell)
+        , m_pHighlighterColorMap(nullptr)
+        , m_rStyleSheetPool(rStyleSheetPool)
+    {
+        if (pViewShell && bModuleHasStylesHighlighterFeature)
+        {
+            if (eFam == SfxStyleFamily::Para)
+                m_pHighlighterColorMap = 
&pViewShell->GetStylesHighlighterParaColorMap();
+            else if (eFam == SfxStyleFamily::Char)
+                m_pHighlighterColorMap = 
&pViewShell->GetStylesHighlighterCharColorMap();
+        }
+
+        if (m_pHighlighterColorMap && !m_pHighlighterColorMap->empty())
+        {
+            m_bOrigMapHasEntries = true;
+            m_pHighlighterColorMap->clear();
+        }
+    }
+
+    ~StyleHighlightUpdateGuard()
+    {
+        if (!m_pViewShell)
+            return;
+        // make view update, but skip notify if before and after are both 
empty to skip
+        // unnecessary invalidates
+        if (m_pHighlighterColorMap && (!m_pHighlighterColorMap->empty() || 
m_bOrigMapHasEntries))
+        {
+            static_cast<SfxListener*>(m_pViewShell)
+                ->Notify(m_rStyleSheetPool, 
SfxHint(SfxHintId::StylesHighlighterModified));
+        }
+    }
+};
+}
+
 // Fill the treeview
 
 void StyleList::FillTreeBox(SfxStyleFamily eFam)
@@ -1032,13 +1080,9 @@ void StyleList::FillTreeBox(SfxStyleFamily eFam)
     const sal_uInt16 nCount = aArr.size();
 
     SfxViewShell* pViewShell = m_pCurObjShell->GetViewShell();
-    if (pViewShell && m_bModuleHasStylesHighlighterFeature)
-    {
-        if (eFam == SfxStyleFamily::Para)
-            pViewShell->GetStylesHighlighterParaColorMap().clear();
-        else if (eFam == SfxStyleFamily::Char)
-            pViewShell->GetStylesHighlighterCharColorMap().clear();
-    }
+
+    auto xUpdateGuard = std::make_unique<StyleHighlightUpdateGuard>(
+        pViewShell, m_bModuleHasStylesHighlighterFeature, *m_pStyleSheetPool, 
eFam);
 
     bool blcl_insert = pViewShell && m_bModuleHasStylesHighlighterFeature
                        && ((eFam == SfxStyleFamily::Para && 
m_bHighlightParaStyles)
@@ -1058,12 +1102,8 @@ void StyleList::FillTreeBox(SfxStyleFamily eFam)
 
     m_xTreeBox->thaw();
 
-    // hack for x11 to make view update
-    if (pViewShell && m_bModuleHasStylesHighlighterFeature)
-    {
-        SfxViewFrame* pViewFrame = 
m_pBindings->GetDispatcher_Impl()->GetFrame();
-        pViewFrame->Resize(true);
-    }
+    // make view update
+    xUpdateGuard.reset();
 
     std::unique_ptr<weld::TreeIter> xEntry = m_xTreeBox->make_iterator();
     bool bEntry = m_xTreeBox->get_iter_first(*xEntry);
@@ -1225,13 +1265,9 @@ void StyleList::UpdateStyles(StyleFlags nFlags)
     m_xFmtLb->clear();
 
     SfxViewShell* pViewShell = m_pCurObjShell->GetViewShell();
-    if (pViewShell && m_bModuleHasStylesHighlighterFeature)
-    {
-        if (eFam == SfxStyleFamily::Para)
-            pViewShell->GetStylesHighlighterParaColorMap().clear();
-        else if (eFam == SfxStyleFamily::Char)
-            pViewShell->GetStylesHighlighterCharColorMap().clear();
-    }
+
+    auto xUpdateGuard = std::make_unique<StyleHighlightUpdateGuard>(
+        pViewShell, m_bModuleHasStylesHighlighterFeature, *m_pStyleSheetPool, 
eFam);
 
     size_t nCount = aStrings.size();
     size_t nPos = 0;
@@ -1253,12 +1289,8 @@ void StyleList::UpdateStyles(StyleFlags nFlags)
 
     m_xFmtLb->thaw();
 
-    // hack for x11 to make view update
-    if (pViewShell && m_bModuleHasStylesHighlighterFeature)
-    {
-        SfxViewFrame* pViewFrame = 
m_pBindings->GetDispatcher_Impl()->GetFrame();
-        pViewFrame->Resize(true);
-    }
+    // make view update
+    xUpdateGuard.reset();
 
     // Selects the current style if any
     SfxTemplateItem* pState = m_pFamilyState[m_nActFamily - 1].get();
diff --git a/sw/source/uibase/uiview/view.cxx b/sw/source/uibase/uiview/view.cxx
index 9efc27622c15..4b4075c5d20e 100644
--- a/sw/source/uibase/uiview/view.cxx
+++ b/sw/source/uibase/uiview/view.cxx
@@ -1837,6 +1837,14 @@ void SwView::Notify( SfxBroadcaster& rBC, const SfxHint& 
rHint )
                     GetViewFrame().GetBindings().Invalidate(aSlotRedLine);
                 }
                 break;
+            case SfxHintId::StylesHighlighterModified:
+                {
+                    // we need to Invalidate to render with the new set of
+                    // highlighted styles
+                    if (vcl::Window *pMyWin = GetWrtShell().GetWin())
+                        pMyWin->Invalidate();
+                }
+                break;
             default: break;
         }
     }

Reply via email to