summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2021-11-18 17:25:06 +0000
committerCaolán McNamara <caolanm@redhat.com>2021-11-19 11:01:37 +0100
commit96d19777abfdf74c9776470e39ee3ec7e1b2e256 (patch)
treec458d3804341f984f3ab26358672f46edef1e1de
parentd9c6fa0c31e25268829ec83d8d7a304abceeaaba (diff)
refactor for potential reuse outside MenuButton
Change-Id: I36729364550dc7c505fdc396442f51809fc58073 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125489 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--vcl/unx/gtk3/gtkinst.cxx56
1 files changed, 29 insertions, 27 deletions
diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx
index 6ce18a346ac4..b05979834196 100644
--- a/vcl/unx/gtk3/gtkinst.cxx
+++ b/vcl/unx/gtk3/gtkinst.cxx
@@ -9800,6 +9800,33 @@ GtkPositionType show_menu(GtkWidget* pMenuButton, GtkWindow* pMenu)
namespace {
+#if !GTK_CHECK_VERSION(4, 0, 0)
+bool button_release_is_outside(GtkWidget* pWidget, GtkWidget* pMenuHack, GdkEventButton* pEvent)
+{
+ //we want to pop down if the button was released outside our popup
+ gdouble x = pEvent->x_root;
+ gdouble y = pEvent->y_root;
+ gint xoffset, yoffset;
+ gdk_window_get_root_origin(widget_get_surface(pWidget), &xoffset, &yoffset);
+
+ GtkAllocation alloc;
+ gtk_widget_get_allocation(pWidget, &alloc);
+ xoffset += alloc.x;
+ yoffset += alloc.y;
+
+ gtk_widget_get_allocation(pMenuHack, &alloc);
+ gint x1 = alloc.x + xoffset;
+ gint y1 = alloc.y + yoffset;
+ gint x2 = x1 + alloc.width;
+ gint y2 = y1 + alloc.height;
+
+ if (x > x1 && x < x2 && y > y1 && y < y2)
+ return false;
+
+ return true;
+}
+#endif
+
/* four types of uses of this
a) textual menubutton, always with pan-down symbol, e.g. math, format, font, modify
b) image + text, always with additional pan-down symbol, e.g. writer, format, watermark
@@ -9918,33 +9945,8 @@ private:
static gboolean signalButtonRelease(GtkWidget* pWidget, GdkEventButton* pEvent, gpointer widget)
{
GtkInstanceMenuButton* pThis = static_cast<GtkInstanceMenuButton*>(widget);
- return pThis->button_release(pWidget, pEvent);
- }
-
- bool button_release(GtkWidget* pWidget, GdkEventButton* pEvent)
- {
- //we want to pop down if the button was released outside our popup
- gdouble x = pEvent->x_root;
- gdouble y = pEvent->y_root;
- gint xoffset, yoffset;
- gdk_window_get_root_origin(widget_get_surface(pWidget), &xoffset, &yoffset);
-
- GtkAllocation alloc;
- gtk_widget_get_allocation(pWidget, &alloc);
- xoffset += alloc.x;
- yoffset += alloc.y;
-
- gtk_widget_get_allocation(GTK_WIDGET(m_pMenuHack), &alloc);
- gint x1 = alloc.x + xoffset;
- gint y1 = alloc.y + yoffset;
- gint x2 = x1 + alloc.width;
- gint y2 = y1 + alloc.height;
-
- if (x > x1 && x < x2 && y > y1 && y < y2)
- return false;
-
- set_active(false);
-
+ if (button_release_is_outside(pWidget, GTK_WIDGET(pThis->m_pMenuHack), pEvent))
+ pThis->set_active(false);
return false;
}