include/vcl/weld.hxx          |    9 ++++++--
 vcl/inc/salvtables.hxx        |    5 ++++
 vcl/source/app/salvtables.cxx |   26 +++++++++++++++++++++++++
 vcl/unx/gtk3/gtkinst.cxx      |   43 +++++++++++++++++++++++-------------------
 4 files changed, 62 insertions(+), 21 deletions(-)

New commits:
commit dffde8403e0bb81d7eb3b7853cece187e1d36c62
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Thu Mar 16 09:50:19 2023 +0000
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Thu Mar 16 14:02:44 2023 +0000

    allow more than DrawingArea to report style updates
    
    Change-Id: I791e4ad45daeeb77ca25e36ae6520168b2ece044
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148980
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx
index e352c2e357f7..4acece25f052 100644
--- a/include/vcl/weld.hxx
+++ b/include/vcl/weld.hxx
@@ -87,6 +87,7 @@ protected:
     Link<Widget&, void> m_aFocusInHdl;
     Link<Widget&, void> m_aFocusOutHdl;
     Link<Widget&, bool> m_aMnemonicActivateHdl;
+    Link<Widget&, void> m_aStyleUpdatedHdl;
     Link<const Size&, void> m_aSizeAllocateHdl;
     Link<const KeyEvent&, bool> m_aKeyPressHdl;
     Link<const KeyEvent&, bool> m_aKeyReleaseHdl;
@@ -279,6 +280,12 @@ public:
         m_aMouseReleaseHdl = rLink;
     }
 
+    virtual void connect_style_updated(const Link<Widget&, void>& rLink)
+    {
+        assert(!m_aStyleUpdatedHdl.IsSet() || !rLink.IsSet());
+        m_aStyleUpdatedHdl = rLink;
+    }
+
     virtual void grab_add() = 0;
     virtual bool has_grab() const = 0;
     virtual void grab_remove() = 0;
@@ -2274,7 +2281,6 @@ public:
 
 protected:
     Link<draw_args, void> m_aDrawHdl;
-    Link<Widget&, void> m_aStyleUpdatedHdl;
     Link<const CommandEvent&, bool> m_aCommandHdl;
     Link<Widget&, tools::Rectangle> m_aGetFocusRectHdl;
     Link<tools::Rectangle&, OUString> m_aQueryTooltipHdl;
@@ -2304,7 +2310,6 @@ protected:
 
 public:
     void connect_draw(const Link<draw_args, void>& rLink) { m_aDrawHdl = 
rLink; }
-    void connect_style_updated(const Link<Widget&, void>& rLink) { 
m_aStyleUpdatedHdl = rLink; }
     void connect_command(const Link<const CommandEvent&, bool>& rLink) { 
m_aCommandHdl = rLink; }
     void connect_focus_rect(const Link<Widget&, tools::Rectangle>& rLink)
     {
diff --git a/vcl/inc/salvtables.hxx b/vcl/inc/salvtables.hxx
index 19f6b0adf91d..1bbf37b4f7fb 100644
--- a/vcl/inc/salvtables.hxx
+++ b/vcl/inc/salvtables.hxx
@@ -188,6 +188,7 @@ private:
     DECL_LINK(EventListener, VclWindowEvent&, void);
     DECL_LINK(KeyEventListener, VclWindowEvent&, bool);
     DECL_LINK(MouseEventListener, VclWindowEvent&, void);
+    DECL_LINK(SettingsChangedHdl, VclWindowEvent&, void);
     DECL_LINK(MnemonicActivateHdl, vcl::Window&, bool);
 
     static void DoRecursivePaint(vcl::Window* pWindow, const Point& rPos, 
OutputDevice& rOutput);
@@ -333,6 +334,8 @@ public:
 
     virtual void connect_key_release(const Link<const KeyEvent&, bool>& rLink) 
override;
 
+    virtual void connect_style_updated(const Link<Widget&, void>& rLink) 
override;
+
     virtual bool get_extents_relative_to(const Widget& rRelative, int& x, int& 
y, int& width,
                                          int& height) const override;
 
@@ -1311,6 +1314,8 @@ public:
 
     virtual void connect_key_release(const Link<const KeyEvent&, bool>& rLink) 
override;
 
+    virtual void connect_style_updated(const Link<Widget&, void>& rLink) 
override;
+
     virtual void set_cursor(PointerStyle ePointerStyle) override;
 
     virtual Point get_pointer_position() const override;
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index f9a6cfc75dc2..61fa56dd3223 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -580,6 +580,25 @@ void SalInstanceWidget::connect_key_release(const 
Link<const KeyEvent&, bool>& r
     weld::Widget::connect_key_release(rLink);
 }
 
+IMPL_LINK(SalInstanceWidget, SettingsChangedHdl, VclWindowEvent&, rEvent, void)
+{
+    if (rEvent.GetId() != VclEventId::WindowDataChanged)
+        return;
+
+    DataChangedEvent* pData = static_cast<DataChangedEvent*>(rEvent.GetData());
+    if (pData->GetType() == DataChangedEventType::SETTINGS)
+        m_aStyleUpdatedHdl.Call(*this);
+}
+
+void SalInstanceWidget::connect_style_updated(const Link<Widget&, void>& rLink)
+{
+    if (m_aStyleUpdatedHdl.IsSet())
+        m_xWidget->RemoveEventListener(LINK(this, SalInstanceWidget, 
SettingsChangedHdl));
+    weld::Widget::connect_style_updated(rLink);
+    if (m_aStyleUpdatedHdl.IsSet())
+        m_xWidget->AddEventListener(LINK(this, SalInstanceWidget, 
SettingsChangedHdl));
+}
+
 bool SalInstanceWidget::get_extents_relative_to(const Widget& rRelative, int& 
x, int& y, int& width,
                                                 int& height) const
 {
@@ -633,6 +652,8 @@ void SalInstanceWidget::queue_resize() { 
m_xWidget->queue_resize(); }
 
 SalInstanceWidget::~SalInstanceWidget()
 {
+    if (m_aStyleUpdatedHdl.IsSet())
+        m_xWidget->RemoveEventListener(LINK(this, SalInstanceWidget, 
SettingsChangedHdl));
     if (m_aMnemonicActivateHdl.IsSet())
         m_xWidget->SetMnemonicActivateHdl(Link<vcl::Window&, bool>());
     if (m_bMouseEventListener)
@@ -6233,6 +6254,11 @@ void SalInstanceDrawingArea::connect_key_release(const 
Link<const KeyEvent&, boo
     weld::Widget::connect_key_release(rLink);
 }
 
+void SalInstanceDrawingArea::connect_style_updated(const Link<Widget&, void>& 
rLink)
+{
+    weld::Widget::connect_style_updated(rLink);
+}
+
 void SalInstanceDrawingArea::set_cursor(PointerStyle ePointerStyle)
 {
     m_xDrawingArea->SetPointer(ePointerStyle);
diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx
index 6be688f06b93..3177ec5272d2 100644
--- a/vcl/unx/gtk3/gtkinst.cxx
+++ b/vcl/unx/gtk3/gtkinst.cxx
@@ -2681,6 +2681,15 @@ protected:
     }
 #endif
 
+    virtual void connect_style_updated(const Link<Widget&, void>& rLink) 
override
+    {
+        if (m_aStyleUpdatedHdl.IsSet())
+            ImplGetDefaultWindow()->RemoveEventListener(LINK(this, 
GtkInstanceWidget, SettingsChangedHdl));
+        weld::Widget::connect_style_updated(rLink);
+        if (m_aStyleUpdatedHdl.IsSet())
+            ImplGetDefaultWindow()->AddEventListener(LINK(this, 
GtkInstanceWidget, SettingsChangedHdl));
+    }
+
     bool SwapForRTL() const
     {
         return ::SwapForRTL(m_pWidget);
@@ -3382,6 +3391,8 @@ private:
                                        
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
     }
 
+    DECL_LINK(SettingsChangedHdl, VclWindowEvent&, void);
+
 #if !GTK_CHECK_VERSION(4, 0, 0)
     static void update_style(GtkWidget* pWidget, gpointer pData)
     {
@@ -4276,6 +4287,9 @@ public:
 
     virtual ~GtkInstanceWidget() override
     {
+        if (m_aStyleUpdatedHdl.IsSet())
+            ImplGetDefaultWindow()->RemoveEventListener(LINK(this, 
GtkInstanceWidget, SettingsChangedHdl));
+
         if (m_pDragCancelEvent)
             Application::RemoveUserEvent(m_pDragCancelEvent);
         if (m_nDragMotionSignalId)
@@ -4549,6 +4563,16 @@ public:
 
 }
 
+IMPL_LINK(GtkInstanceWidget, SettingsChangedHdl, VclWindowEvent&, rEvent, void)
+{
+    if (rEvent.GetId() != VclEventId::WindowDataChanged)
+        return;
+
+    DataChangedEvent* pData = static_cast<DataChangedEvent*>(rEvent.GetData());
+    if (pData->GetType() == DataChangedEventType::SETTINGS)
+        m_aStyleUpdatedHdl.Call(*this);
+}
+
 #if !GTK_CHECK_VERSION(4, 0, 0)
 IMPL_LINK(GtkInstanceWidget, async_drag_cancel, void*, arg, void)
 {
@@ -18303,10 +18327,6 @@ private:
         m_pSurface = get_underlying_cairo_surface(*m_xDevice);
         GtkInstanceWidget::signal_size_allocate(nWidth, nHeight);
     }
-    void signal_style_updated()
-    {
-        m_aStyleUpdatedHdl.Call(*this);
-    }
     static gboolean signalQueryTooltip(GtkWidget* pGtkWidget, gint x, gint y,
                                          gboolean /*keyboard_mode*/, 
GtkTooltip *tooltip,
                                          gpointer widget)
@@ -18407,7 +18427,6 @@ private:
     }
 #endif
 
-    DECL_LINK(SettingsChangedHdl, VclWindowEvent&, void);
 public:
     GtkInstanceDrawingArea(GtkDrawingArea* pDrawingArea, GtkInstanceBuilder* 
pBuilder, a11yref xA11y, bool bTakeOwnership)
         : GtkInstanceWidget(GTK_WIDGET(pDrawingArea), pBuilder, bTakeOwnership)
@@ -18449,8 +18468,6 @@ public:
         gtk_widget_set_has_tooltip(m_pWidget, true);
         g_object_set_data(G_OBJECT(m_pDrawingArea), 
"g-lo-GtkInstanceDrawingArea", this);
         m_xDevice->EnableRTL(get_direction());
-
-        ImplGetDefaultWindow()->AddEventListener(LINK(this, 
GtkInstanceDrawingArea, SettingsChangedHdl));
     }
 
 #if !GTK_CHECK_VERSION(4, 0, 0)
@@ -18640,8 +18657,6 @@ public:
         g_clear_object(&m_pZoomGesture);
 #endif
 
-        ImplGetDefaultWindow()->RemoveEventListener(LINK(this, 
GtkInstanceDrawingArea, SettingsChangedHdl));
-
         g_object_steal_data(G_OBJECT(m_pDrawingArea), 
"g-lo-GtkInstanceDrawingArea");
 #if !GTK_CHECK_VERSION(4, 0, 0)
         if (m_pAccessible)
@@ -18682,16 +18697,6 @@ public:
     }
 };
 
-IMPL_LINK(GtkInstanceDrawingArea, SettingsChangedHdl, VclWindowEvent&, rEvent, 
void)
-{
-    if (rEvent.GetId() != VclEventId::WindowDataChanged)
-        return;
-
-    DataChangedEvent* pData = static_cast<DataChangedEvent*>(rEvent.GetData());
-    if (pData->GetType() == DataChangedEventType::SETTINGS)
-        signal_style_updated();
-}
-
 IMHandler::IMHandler(GtkInstanceDrawingArea* pArea)
     : m_pArea(pArea)
     , m_pIMContext(gtk_im_multicontext_new())

Reply via email to