summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorCaolán McNamara <caolan.mcnamara@collabora.com>2024-12-12 20:21:40 +0000
committerMiklos Vajna <vmiklos@collabora.com>2024-12-16 09:18:13 +0100
commit93c5737d5cd5fd243a61d37fcf846ff077516e05 (patch)
tree6f2a79f88b8910791de4660d171abaf840613fd3 /sfx2
parente7acfd7dea2f7c905595bd2f0f77201fef078dc3 (diff)
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 <szymon.klos@collabora.com> Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/source/dialog/StyleList.cxx84
1 files changed, 58 insertions, 26 deletions
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();