vcl/unx/gtk3/gtkinst.cxx |   56 ++++++++++++++++++++++++-----------------------
 1 file changed, 29 insertions(+), 27 deletions(-)

New commits:
commit 96d19777abfdf74c9776470e39ee3ec7e1b2e256
Author:     Caolán McNamara <[email protected]>
AuthorDate: Thu Nov 18 17:25:06 2021 +0000
Commit:     Caolán McNamara <[email protected]>
CommitDate: Fri Nov 19 11:01:37 2021 +0100

    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 <[email protected]>

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;
     }
 

Reply via email to