include/sfx2/thumbnailview.hxx              |    9 +++++++--
 sfx2/inc/recentdocsview.hxx                 |    3 +++
 sfx2/inc/templatedefaultview.hxx            |    3 +++
 sfx2/source/control/recentdocsview.cxx      |   20 ++++++++++++--------
 sfx2/source/control/templatedefaultview.cxx |   14 +++++++++-----
 sfx2/source/control/thumbnailview.cxx       |   26 ++++++++++++++++----------
 6 files changed, 50 insertions(+), 25 deletions(-)

New commits:
commit 92b013bdb4d567b98bfcf42a0831abe42117691c
Author:     Dan Williams <[email protected]>
AuthorDate: Wed Dec 10 11:05:47 2025 -0600
Commit:     Hossein <[email protected]>
CommitDate: Sat Dec 13 13:26:38 2025 +0100

    tdf#169727 update ThumbnailView colors for system theme changes
    
    The ThumbnailView never updated cached colors after creation, leading to
    wrong background colors when the system theme changed while LO was
    running (eg between Dark/Light mode). Since subclasses need to override
    the parent class colors, we must first let subclasses update internal
    cached colors then copy those to the item attributes. Then during
    Paint() requery style settings to ensure our colors are up to date.
    
    Change-Id: I19bbfb296ba213cf7ad53eff8bd24fe291679184
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195402
    Tested-by: Hossein <[email protected]>
    Tested-by: Jenkins
    Reviewed-by: Hossein <[email protected]>

diff --git a/include/sfx2/thumbnailview.hxx b/include/sfx2/thumbnailview.hxx
index 0035db9bd81e..6cdfb5f4d32b 100644
--- a/include/sfx2/thumbnailview.hxx
+++ b/include/sfx2/thumbnailview.hxx
@@ -17,6 +17,7 @@
 #include <vector>
 
 #include <vcl/customweld.hxx>
+#include <vcl/settings.hxx>
 
 class Bitmap;
 class ThumbnailViewItem;
@@ -260,8 +261,8 @@ protected:
 
     virtual void OnItemDblClicked (ThumbnailViewItem *pItem);
 
-    // Set Item colors from the ThumbnailView colors
-    SAL_DLLPRIVATE void UpdateColors();
+    // Update internal colors from system color scheme or other sources
+    SAL_DLLPRIVATE void UpdateColors(const StyleSettings& rSettings);
 
 protected:
 
@@ -282,6 +283,10 @@ protected:
     SAL_DLLPRIVATE bool ImplHasAccessibleListeners() const;
     DECL_DLLPRIVATE_LINK( ImplScrollHdl, weld::ScrolledWindow&, void );
 
+private:
+    // Update Item colors from internal colors
+    void updateItemAttrsFromColors();
+
 protected:
 
     std::vector< std::unique_ptr<ThumbnailViewItem> > mItemList;
diff --git a/sfx2/inc/recentdocsview.hxx b/sfx2/inc/recentdocsview.hxx
index 43a8049034b0..5063f7c56502 100644
--- a/sfx2/inc/recentdocsview.hxx
+++ b/sfx2/inc/recentdocsview.hxx
@@ -85,6 +85,9 @@ public:
 
     void setFilter(ApplicationType aFilter);
 
+protected:
+    void UpdateColors(const StyleSettings& rSettings);
+
 private:
     virtual bool MouseButtonDown( const MouseEvent& rMEvt ) override;
 
diff --git a/sfx2/inc/templatedefaultview.hxx b/sfx2/inc/templatedefaultview.hxx
index 1771ad3d8759..0bfd88c2c07e 100644
--- a/sfx2/inc/templatedefaultview.hxx
+++ b/sfx2/inc/templatedefaultview.hxx
@@ -24,6 +24,9 @@ public:
     virtual bool MouseButtonDown(const MouseEvent& rMEvt) override;
 
     void createContextMenu();
+
+protected:
+    void UpdateColors(const StyleSettings& rSettings);
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/source/control/recentdocsview.cxx 
b/sfx2/source/control/recentdocsview.cxx
index 67117f62c320..dc4f415acf4d 100644
--- a/sfx2/source/control/recentdocsview.cxx
+++ b/sfx2/source/control/recentdocsview.cxx
@@ -74,16 +74,9 @@ 
RecentDocsView::RecentDocsView(std::unique_ptr<weld::ScrolledWindow> xWindow, st
     setItemMaxTextLength( 30 );
     setItemDimensions( mnItemMaxSize, mnItemMaxSize, gnTextHeight, 
gnItemPadding );
 
-    maFillColor = Color(ColorTransparency, 
officecfg::Office::Common::Help::StartCenter::StartCenterThumbnailsBackgroundColor::get());
-    maTextColor = Color(ColorTransparency, 
officecfg::Office::Common::Help::StartCenter::StartCenterThumbnailsTextColor::get());
-
-    const StyleSettings& rSettings = 
Application::GetSettings().GetStyleSettings();
-    maHighlightColor = rSettings.GetHighlightColor();
-    maHighlightTextColor = rSettings.GetHighlightTextColor();
-
     mfHighlightTransparence = 0.75;
 
-    UpdateColors();
+    UpdateColors(Application::GetSettings().GetStyleSettings());
 }
 
 RecentDocsView::~RecentDocsView()
@@ -97,6 +90,17 @@ RecentDocsView::~RecentDocsView()
     }
 }
 
+void RecentDocsView::UpdateColors(const StyleSettings& rSettings)
+{
+    ThumbnailView::UpdateColors(rSettings);
+
+    maFillColor = Color(ColorTransparency, 
officecfg::Office::Common::Help::StartCenter::StartCenterThumbnailsBackgroundColor::get());
+    maTextColor = Color(ColorTransparency, 
officecfg::Office::Common::Help::StartCenter::StartCenterThumbnailsTextColor::get());
+
+    maHighlightColor = rSettings.GetHighlightColor();
+    maHighlightTextColor = rSettings.GetHighlightTextColor();
+}
+
 bool RecentDocsView::typeMatchesExtension(ApplicationType type, 
std::u16string_view rExt)
 {
     bool bRet = false;
diff --git a/sfx2/source/control/templatedefaultview.cxx 
b/sfx2/source/control/templatedefaultview.cxx
index ad7a935e72a0..656625d23e19 100644
--- a/sfx2/source/control/templatedefaultview.cxx
+++ b/sfx2/source/control/templatedefaultview.cxx
@@ -31,17 +31,21 @@ 
TemplateDefaultView::TemplateDefaultView(std::unique_ptr<weld::ScrolledWindow> x
     ThumbnailView::setItemDimensions( nItemMaxSize, nItemMaxSize, 
gnTextHeight, gnItemPadding );
     updateThumbnailDimensions(nItemMaxSize);
 
+    mfHighlightTransparence = 0.75;
+
+    UpdateColors(Application::GetSettings().GetStyleSettings());
+}
+
+void TemplateDefaultView::UpdateColors(const StyleSettings& rSettings)
+{
+    TemplateLocalView::UpdateColors(rSettings);
+
     // startcenter specific settings
     maFillColor = Color(ColorTransparency, 
officecfg::Office::Common::Help::StartCenter::StartCenterThumbnailsBackgroundColor::get());
     maTextColor = Color(ColorTransparency, 
officecfg::Office::Common::Help::StartCenter::StartCenterThumbnailsTextColor::get());
 
-    const StyleSettings& rSettings = 
Application::GetSettings().GetStyleSettings();
     maHighlightColor = rSettings.GetHighlightColor();
     maHighlightTextColor = rSettings.GetHighlightTextColor();
-
-    mfHighlightTransparence = 0.75;
-
-    UpdateColors();
 }
 
 void TemplateDefaultView::showAllTemplates()
diff --git a/sfx2/source/control/thumbnailview.cxx 
b/sfx2/source/control/thumbnailview.cxx
index b42cfeaf3267..d2ef71ea5bba 100644
--- a/sfx2/source/control/thumbnailview.cxx
+++ b/sfx2/source/control/thumbnailview.cxx
@@ -288,22 +288,24 @@ void ThumbnailView::ImplInit()
     mbAllowMultiSelection = true;
     maFilterFunc = ViewFilterAll();
 
-    const StyleSettings& rSettings = 
Application::GetSettings().GetStyleSettings();
-    maFillColor = rSettings.GetFieldColor();
-    maTextColor = rSettings.GetWindowTextColor();
-    maHighlightColor = rSettings.GetHighlightColor();
-    maHighlightTextColor = rSettings.GetHighlightTextColor();
+    mpStartSelRange = mFilteredItemList.end();
 
     mfHighlightTransparence = 
SvtOptionsDrawinglayer::GetTransparentSelectionPercent() * 0.01;
+    mpItemAttrs->nMaxTextLength = 0;
 
-    mpStartSelRange = mFilteredItemList.end();
-
-    UpdateColors();
+    UpdateColors(Application::GetSettings().GetStyleSettings());
+    updateItemAttrsFromColors();
+}
 
-    mpItemAttrs->nMaxTextLength = 0;
+void ThumbnailView::UpdateColors(const StyleSettings& rSettings)
+{
+    maFillColor = rSettings.GetFieldColor();
+    maTextColor = rSettings.GetWindowTextColor();
+    maHighlightColor = rSettings.GetHighlightColor();
+    maHighlightTextColor = rSettings.GetHighlightTextColor();
 }
 
-void ThumbnailView::UpdateColors()
+void ThumbnailView::updateItemAttrsFromColors()
 {
     mpItemAttrs->aFillColor = maFillColor.getBColor();
     mpItemAttrs->aTextColor = maTextColor.getBColor();
@@ -952,6 +954,10 @@ void ThumbnailView::Paint(vcl::RenderContext& 
rRenderContext, const ::tools::Rec
 {
     auto popIt = rRenderContext.ScopedPush(vcl::PushFlags::ALL);
 
+    // Re-read settings colors to handle system theme changes on-the-fly
+    UpdateColors(rRenderContext.GetSettings().GetStyleSettings());
+    updateItemAttrsFromColors();
+
     rRenderContext.SetTextFillColor();
     rRenderContext.SetBackground(maFillColor);
 

Reply via email to