diff options
author | Caolán McNamara <caolanm@redhat.com> | 2021-06-17 10:04:22 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2021-06-17 14:00:33 +0200 |
commit | 013bbc129774686d959878fb27d851bf2ea129b4 (patch) | |
tree | af99ab83ff262d52ea492a7a85f8a09325ac8257 /vcl | |
parent | f252223140b040a1ad76f87fce27448bd24848b8 (diff) |
split NotifyingLayout out
Change-Id: Ib706331f9e6b3749559a0b78f1a07d442a674829
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117369
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/Library_vclplug_gtk4.mk | 1 | ||||
-rw-r--r-- | vcl/unx/gtk3/gtkinst.cxx | 96 | ||||
-rw-r--r-- | vcl/unx/gtk4/gtkinst.cxx | 1 | ||||
-rw-r--r-- | vcl/unx/gtk4/notifyinglayout.cxx | 88 | ||||
-rw-r--r-- | vcl/unx/gtk4/notifyinglayout.hxx | 36 |
5 files changed, 128 insertions, 94 deletions
diff --git a/vcl/Library_vclplug_gtk4.mk b/vcl/Library_vclplug_gtk4.mk index e3cc415be738..93f8d8c90673 100644 --- a/vcl/Library_vclplug_gtk4.mk +++ b/vcl/Library_vclplug_gtk4.mk @@ -96,6 +96,7 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_gtk4,\ vcl/unx/gtk4/glomenu \ vcl/unx/gtk4/gloactiongroup \ vcl/unx/gtk4/hudawareness \ + vcl/unx/gtk4/notifyinglayout \ )) ifeq ($(OS),LINUX) diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx index 830cb067ddd7..3aec591a6a7a 100644 --- a/vcl/unx/gtk3/gtkinst.cxx +++ b/vcl/unx/gtk3/gtkinst.cxx @@ -7785,98 +7785,6 @@ public: } -#if GTK_CHECK_VERSION(4, 0, 0) - -G_BEGIN_DECLS - -G_DECLARE_FINAL_TYPE(NotifyingLayout, notifying_layout, NOTIFYING, LAYOUT, GtkLayoutManager) - -struct _NotifyingLayout -{ - GtkLayoutManager parent_instance; - - GtkWidget* m_pWidget; - GtkLayoutManager* m_pOrigManager; - Link<void*, void> m_aLink; - - void StartWatch(GtkWidget* pWidget, const Link<void*, void>& rLink) - { - m_pWidget = pWidget; - m_aLink = rLink; - - m_pOrigManager = gtk_widget_get_layout_manager(m_pWidget); - g_object_ref(m_pOrigManager); - - gtk_widget_set_layout_manager(pWidget, GTK_LAYOUT_MANAGER(this)); - } - - void StopWatch() - { - gtk_widget_set_layout_manager(m_pWidget, m_pOrigManager); - } -}; - -struct _NotifyingLayoutClass -{ - GtkLayoutManagerClass parent_class; -}; - -G_DEFINE_TYPE(NotifyingLayout, notifying_layout, GTK_TYPE_LAYOUT_MANAGER) - -static void notifying_layout_measure(GtkLayoutManager* pLayoutManager, - GtkWidget* widget, - GtkOrientation orientation, - int for_size, - int *minimum, - int *natural, - int *minimum_baseline, - int *natural_baseline) -{ - NotifyingLayout* self = NOTIFYING_LAYOUT(pLayoutManager); - GtkLayoutManagerClass* pKlass = GTK_LAYOUT_MANAGER_CLASS(G_OBJECT_GET_CLASS(self->m_pOrigManager)); - pKlass->measure(self->m_pOrigManager, widget, orientation, for_size, - minimum, natural, minimum_baseline, natural_baseline); -} - -static void notifying_layout_allocate(GtkLayoutManager* pLayoutManager, - GtkWidget* widget, - int width, - int height, - int baseline) -{ - NotifyingLayout* self = NOTIFYING_LAYOUT(pLayoutManager); - GtkLayoutManagerClass* pKlass = GTK_LAYOUT_MANAGER_CLASS(G_OBJECT_GET_CLASS(self->m_pOrigManager)); - pKlass->allocate(self->m_pOrigManager, widget, width, height, baseline); - self->m_aLink.Call(nullptr); -} - -static GtkSizeRequestMode notifying_layout_get_request_mode(GtkLayoutManager* pLayoutManager, - GtkWidget* widget) -{ - NotifyingLayout* self = NOTIFYING_LAYOUT(pLayoutManager); - GtkLayoutManagerClass* pKlass = GTK_LAYOUT_MANAGER_CLASS(G_OBJECT_GET_CLASS(self->m_pOrigManager)); - return pKlass->get_request_mode(self->m_pOrigManager, widget); -} - -static void notifying_layout_class_init(NotifyingLayoutClass* klass) -{ - GtkLayoutManagerClass *layout_class = GTK_LAYOUT_MANAGER_CLASS(klass); - - layout_class->get_request_mode = notifying_layout_get_request_mode; - layout_class->measure = notifying_layout_measure; - layout_class->allocate = notifying_layout_allocate; -} - -static void notifying_layout_init(NotifyingLayout* self) -{ - self->m_pWidget = nullptr; - self->m_pOrigManager = nullptr; -} - -G_END_DECLS - -#endif - namespace { class GtkInstanceNotebook : public GtkInstanceWidget, public virtual weld::Notebook @@ -8364,7 +8272,7 @@ public: m_nNotebookSizeAllocateSignalId = g_signal_connect_after(pNotebook, "size-allocate", G_CALLBACK(signalSizeAllocate), this); #else m_pLayout = NOTIFYING_LAYOUT(g_object_new(notifying_layout_get_type(), nullptr)); - m_pLayout->StartWatch(GTK_WIDGET(pNotebook), LINK(this, GtkInstanceNotebook, SizeAllocateHdl)); + notifying_layout_start_watch(m_pLayout, GTK_WIDGET(pNotebook), LINK(this, GtkInstanceNotebook, SizeAllocateHdl)); #endif } gtk_notebook_set_show_border(m_pOverFlowNotebook, false); @@ -8641,7 +8549,7 @@ public: if (m_pLayout) { // put it back how we found it initially - m_pLayout->StopWatch(); + notifying_layout_stop_watch(m_pLayout); } #endif g_signal_handler_disconnect(m_pNotebook, m_nSwitchPageSignalId); diff --git a/vcl/unx/gtk4/gtkinst.cxx b/vcl/unx/gtk4/gtkinst.cxx index e166777412b0..4dc435a2bbf4 100644 --- a/vcl/unx/gtk4/gtkinst.cxx +++ b/vcl/unx/gtk4/gtkinst.cxx @@ -11,6 +11,7 @@ #define GTK_TOOLKIT_NAME "gtk4" #include "convert3to4.hxx" +#include "notifyinglayout.hxx" #include "../gtk3/gtkinst.cxx" diff --git a/vcl/unx/gtk4/notifyinglayout.cxx b/vcl/unx/gtk4/notifyinglayout.cxx new file mode 100644 index 000000000000..46b9a2d95f04 --- /dev/null +++ b/vcl/unx/gtk4/notifyinglayout.cxx @@ -0,0 +1,88 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "notifyinglayout.hxx" + +struct _NotifyingLayout +{ + GtkLayoutManager parent_instance; + + GtkWidget* m_pWidget; + GtkLayoutManager* m_pOrigManager; + Link<void*, void> m_aLink; +}; + +G_DEFINE_TYPE(NotifyingLayout, notifying_layout, GTK_TYPE_LAYOUT_MANAGER) + +static void notifying_layout_measure(GtkLayoutManager* pLayoutManager, GtkWidget* widget, + GtkOrientation orientation, int for_size, int* minimum, + int* natural, int* minimum_baseline, int* natural_baseline) +{ + NotifyingLayout* self = NOTIFYING_LAYOUT(pLayoutManager); + GtkLayoutManagerClass* pKlass + = GTK_LAYOUT_MANAGER_CLASS(G_OBJECT_GET_CLASS(self->m_pOrigManager)); + pKlass->measure(self->m_pOrigManager, widget, orientation, for_size, minimum, natural, + minimum_baseline, natural_baseline); +} + +static void notifying_layout_allocate(GtkLayoutManager* pLayoutManager, GtkWidget* widget, + int width, int height, int baseline) +{ + NotifyingLayout* self = NOTIFYING_LAYOUT(pLayoutManager); + GtkLayoutManagerClass* pKlass + = GTK_LAYOUT_MANAGER_CLASS(G_OBJECT_GET_CLASS(self->m_pOrigManager)); + pKlass->allocate(self->m_pOrigManager, widget, width, height, baseline); + self->m_aLink.Call(nullptr); +} + +static GtkSizeRequestMode notifying_layout_get_request_mode(GtkLayoutManager* pLayoutManager, + GtkWidget* widget) +{ + NotifyingLayout* self = NOTIFYING_LAYOUT(pLayoutManager); + GtkLayoutManagerClass* pKlass + = GTK_LAYOUT_MANAGER_CLASS(G_OBJECT_GET_CLASS(self->m_pOrigManager)); + return pKlass->get_request_mode(self->m_pOrigManager, widget); +} + +static void notifying_layout_class_init(NotifyingLayoutClass* klass) +{ + GtkLayoutManagerClass* layout_class = GTK_LAYOUT_MANAGER_CLASS(klass); + + layout_class->get_request_mode = notifying_layout_get_request_mode; + layout_class->measure = notifying_layout_measure; + layout_class->allocate = notifying_layout_allocate; +} + +static void notifying_layout_init(NotifyingLayout* self) +{ + self->m_pWidget = nullptr; + self->m_pOrigManager = nullptr; + + // prevent loplugin:unreffun firing on macro generated function + (void)notifying_layout_get_instance_private(self); +} + +void notifying_layout_start_watch(NotifyingLayout* self, GtkWidget* pWidget, + const Link<void*, void>& rLink) +{ + self->m_pWidget = pWidget; + self->m_aLink = rLink; + + self->m_pOrigManager = gtk_widget_get_layout_manager(self->m_pWidget); + g_object_ref(self->m_pOrigManager); + + gtk_widget_set_layout_manager(pWidget, GTK_LAYOUT_MANAGER(self)); +} + +void notifying_layout_stop_watch(NotifyingLayout* self) +{ + gtk_widget_set_layout_manager(self->m_pWidget, self->m_pOrigManager); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/unx/gtk4/notifyinglayout.hxx b/vcl/unx/gtk4/notifyinglayout.hxx new file mode 100644 index 000000000000..a717a3061310 --- /dev/null +++ b/vcl/unx/gtk4/notifyinglayout.hxx @@ -0,0 +1,36 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include <gtk/gtk.h> +#include <tools/link.hxx> + +G_BEGIN_DECLS + +G_DECLARE_FINAL_TYPE(NotifyingLayout, notifying_layout, NOTIFYING, LAYOUT, GtkLayoutManager) + +/* + Replace the existing GtkLayoutManager of pWidget with pLayout instead which will + forward all requests to the original GtkLayoutManager but additionally call + rLink when a size is allocated to the pWidget. + + This provides a workaround for the removal of the size-allocate signal in gtk4 +*/ +void notifying_layout_start_watch(NotifyingLayout* pLayout, GtkWidget* pWidget, + const Link<void*, void>& rLink); + +/* + Undo a previous notifying_layout_start_watch. +*/ +void notifying_layout_stop_watch(NotifyingLayout* pLayout); + +G_END_DECLS + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |