[Libreoffice-commits] core.git: bridges/source vcl/inc vcl/unx

Caolán McNamara caolanm at redhat.com
Tue Jul 19 22:39:58 UTC 2016


 bridges/source/cpp_uno/gcc3_linux_intel/share.hxx    |   19 -
 bridges/source/cpp_uno/gcc3_linux_x86-64/except.cxx  |    4 
 bridges/source/cpp_uno/gcc3_linux_x86-64/share.hxx   |  172 +++++++++-------
 bridges/source/cpp_uno/gcc3_linux_x86-64/uno2cpp.cxx |   10 
 bridges/source/cpp_uno/msvc_win32_intel/except.cxx   |    1 
 vcl/inc/unx/gtk/gtkframe.hxx                         |    6 
 vcl/unx/gtk/gtksalmenu.cxx                           |  196 +++++++++++++++++++
 vcl/unx/gtk3/gtk3gtkframe.cxx                        |    9 
 8 files changed, 316 insertions(+), 101 deletions(-)

New commits:
commit f5f0758080b0da61e3d2088804cad0b0ed94d21d
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Tue Jul 19 23:37:54 2016 +0100

    Revert "hack for now"
    
    This reverts commit f5792667cafef77cc4c142f4261f8b64280bc0fe.
    
    it turns out it was the use of an intermediate GtkGrid which made a11y work
    a little differently under gtk3. Clearly not intended to be pushed.
    
    Change-Id: I6931163e07ea413acdd45ba1353f357d317fdfbd

diff --git a/bridges/source/cpp_uno/gcc3_linux_intel/share.hxx b/bridges/source/cpp_uno/gcc3_linux_intel/share.hxx
index 512ae6d..f97e81e 100644
--- a/bridges/source/cpp_uno/gcc3_linux_intel/share.hxx
+++ b/bridges/source/cpp_uno/gcc3_linux_intel/share.hxx
@@ -27,8 +27,9 @@
 #ifndef _GLIBCXX_CDTOR_CALLABI // new in GCC 4.7 cxxabi.h
 #define _GLIBCXX_CDTOR_CALLABI
 #endif
+#include <unwind.h>
 
-#include "config_gcc.h"
+#include "config_cxxabi.h"
 #include <uno/any2.h>
 #include "uno/mapping.h"
 
@@ -37,15 +38,7 @@ namespace CPPU_CURRENT_NAMESPACE
 
 void dummy_can_throw_anything( char const * );
 
-// ----- following decl from libstdc++-v3/libsupc++/unwind-cxx.h and unwind.h
-
-struct _Unwind_Exception
-{
-    unsigned exception_class __attribute__((__mode__(__DI__)));
-    void * exception_cleanup;
-    unsigned private_1 __attribute__((__mode__(__word__)));
-    unsigned private_2 __attribute__((__mode__(__word__)));
-} __attribute__((__aligned__));
+// ----- following decl from libstdc++-v3/libsupc++/unwind-cxx.h
 
 struct __cxa_exception
 {
@@ -87,17 +80,17 @@ struct __cxa_eh_globals
 // __cxa_allocate_exception and __cxa_throw, though they do not have the
 // additional problem of an incompletely declared return type:
 
-#if !HAVE_GCC_CXXABI_H_CXA_GET_GLOBALS
+#if !HAVE_CXXABI_H_CXA_GET_GLOBALS
 namespace __cxxabiv1 { extern "C" void * __cxa_get_globals() throw(); }
 #endif
 
-#if !HAVE_GCC_CXXABI_H_CXA_ALLOCATE_EXCEPTION
+#if !HAVE_CXXABI_H_CXA_ALLOCATE_EXCEPTION
 namespace __cxxabiv1 {
 extern "C" void * __cxa_allocate_exception(std::size_t thrown_size) throw();
 }
 #endif
 
-#if !HAVE_GCC_CXXABI_H_CXA_THROW
+#if !HAVE_CXXABI_H_CXA_THROW
 namespace __cxxabiv1 {
 extern "C" void __cxa_throw(
     void * thrown_exception, void * tinfo, void (* dest)(void *))
diff --git a/bridges/source/cpp_uno/gcc3_linux_x86-64/except.cxx b/bridges/source/cpp_uno/gcc3_linux_x86-64/except.cxx
index 5efd7cb..04d13e80 100644
--- a/bridges/source/cpp_uno/gcc3_linux_x86-64/except.cxx
+++ b/bridges/source/cpp_uno/gcc3_linux_x86-64/except.cxx
@@ -81,7 +81,7 @@ static OUString toUNOname( char const * p )
 extern "C" {
 static void _GLIBCXX_CDTOR_CALLABI deleteException( void * pExc )
 {
-    __cxa_exception const * header = (static_cast<__cxa_exception const *>(pExc) - 1);
+    __cxxabiv1::__cxa_exception const * header = (static_cast<__cxxabiv1::__cxa_exception const *>(pExc) - 1);
     typelib_TypeDescription * pTD = nullptr;
     OUString unoName( toUNOname( header->exceptionType->name() ) );
     ::typelib_typedescription_getByName( &pTD, unoName.pData );
@@ -138,7 +138,7 @@ void raiseException( uno_Any * pUnoExc, uno_Mapping * pUno2Cpp )
     __cxxabiv1::__cxa_throw( pCppExc, rtti, deleteException );
 }
 
-void fillUnoException( __cxa_exception * header, uno_Any * pUnoExc, uno_Mapping * pCpp2Uno )
+void fillUnoException( __cxxabiv1::__cxa_exception * header, uno_Any * pUnoExc, uno_Mapping * pCpp2Uno )
 {
     if (! header)
     {
diff --git a/bridges/source/cpp_uno/gcc3_linux_x86-64/share.hxx b/bridges/source/cpp_uno/gcc3_linux_x86-64/share.hxx
index 96ddfc0..bac7ef6 100644
--- a/bridges/source/cpp_uno/gcc3_linux_x86-64/share.hxx
+++ b/bridges/source/cpp_uno/gcc3_linux_x86-64/share.hxx
@@ -27,101 +27,129 @@
 #ifndef _GLIBCXX_CDTOR_CALLABI // new in GCC 4.7 cxxabi.h
 #define _GLIBCXX_CDTOR_CALLABI
 #endif
+#include <unwind.h>
 
-#include "config_gcc.h"
+#include "config_cxxabi.h"
 #include "uno/any2.h"
 #include "uno/mapping.h"
 
-#ifdef _LIBCPP_VERSION
-
-namespace __cxxabiv1
-{
-    struct __class_type_info : public std::type_info
-    {
-        explicit __class_type_info( const char *__n ) : type_info( __n ) { }
-        virtual ~__class_type_info();
-    };
-
-    struct __si_class_type_info : public __class_type_info
-    {
-        explicit __si_class_type_info( const char *__n, const __class_type_info *__b ) :
-            __class_type_info( __n ), __base_type( __b ) { }
-        virtual ~__si_class_type_info();
-        const __class_type_info *__base_type;
-    };
-
-extern "C" void *__cxa_allocate_exception( std::size_t thrown_size ) _NOEXCEPT;
+#if !HAVE_CXXABI_H_CLASS_TYPE_INFO
+// <https://mentorembedded.github.io/cxx-abi/abi.html>,
+// libstdc++-v3/libsupc++/cxxabi.h:
+namespace __cxxabiv1 {
+class __class_type_info: public std::type_info {
+public:
+    explicit __class_type_info(char const * n): type_info(n) {}
+    ~__class_type_info() override;
+};
+}
+#endif
 
-extern "C" _LIBCPP_NORETURN void __cxa_throw(
-    void *thrown_exception, std::type_info *tinfo, void (*dest) (void *) );
+#if !HAVE_CXXABI_H_SI_CLASS_TYPE_INFO
+// <https://mentorembedded.github.io/cxx-abi/abi.html>,
+// libstdc++-v3/libsupc++/cxxabi.h:
+namespace __cxxabiv1 {
+class __si_class_type_info: public __class_type_info {
+public:
+    __class_type_info const * __base_type;
+    explicit __si_class_type_info(
+        char const * n, __class_type_info const *base):
+        __class_type_info(n), __base_type(base) {}
+    ~__si_class_type_info() override;
+};
 }
+#endif
 
+#if !HAVE_CXXABI_H_BASE_CLASS_TYPE_INFO
+// <https://mentorembedded.github.io/cxx-abi/abi.html>,
+// libstdc++-v3/libsupc++/cxxabi.h:
+namespace __cxxabiv1 {
+struct __base_class_type_info {
+    __class_type_info const * __base_type;
+#if defined _GLIBCXX_LLP64
+    long long __offset_flags;
 #else
+    long __offset_flags;
+#endif
+    enum __offset_flags_masks {
+        __virtual_mask = 0x1,
+        __public_mask = 0x2,
+        __offset_shift = 8
+    };
+};
+}
+#endif
 
-namespace CPPU_CURRENT_NAMESPACE
-{
-
-// ----- following decl from libstdc++-v3/libsupc++/unwind-cxx.h and unwind.h
-
-struct _Unwind_Exception
-{
-    unsigned exception_class __attribute__((__mode__(__DI__)));
-    void * exception_cleanup;
-    unsigned private_1 __attribute__((__mode__(__word__)));
-    unsigned private_2 __attribute__((__mode__(__word__)));
-} __attribute__((__aligned__));
-
-struct __cxa_exception
-{
-    ::std::type_info *exceptionType;
-    void (*exceptionDestructor)(void *);
-
-    ::std::unexpected_handler unexpectedHandler;
-    ::std::terminate_handler terminateHandler;
-
-    __cxa_exception *nextException;
+#if !HAVE_CXXABI_H_VMI_CLASS_TYPE_INFO
+// <https://mentorembedded.github.io/cxx-abi/abi.html>,
+// libstdc++-v3/libsupc++/cxxabi.h:
+namespace __cxxabiv1 {
+class __vmi_class_type_info: public __class_type_info {
+public:
+    unsigned int __flags;
+    unsigned int __base_count;
+    __base_class_type_info __base_info[1];
+    enum __flags_masks {
+        __non_diamond_repeat_mask = 0x1,
+        __diamond_shaped_mask = 0x2,
+        __flags_unknown_mask = 0x10
+    };
+    explicit __vmi_class_type_info(char const * n, int flags):
+        __class_type_info(n), __flags(flags), __base_count(0) {}
+    ~__vmi_class_type_info() override;
+};
+}
+#endif
 
+#if !HAVE_CXXABI_H_CXA_EH_GLOBALS
+// <https://mentorembedded.github.io/cxx-abi/abi-eh.html>,
+// libcxxabi/src/cxa_exception.hpp:
+namespace __cxxabiv1 {
+struct __cxa_exception {
+#if defined _LIBCPPABI_VERSION // detect libc++abi
+#if defined __LP64__ || LIBCXXABI_ARM_EHABI
+    std::size_t referenceCount;
+#endif
+#endif
+    std::type_info * exceptionType;
+    void (* exceptionDestructor)(void *);
+    std::unexpected_handler unexpectedHandler;
+    std::terminate_handler terminateHandler;
+    __cxa_exception * nextException;
     int handlerCount;
-
     int handlerSwitchValue;
-    const unsigned char *actionRecord;
-    const unsigned char *languageSpecificData;
-    void *catchTemp;
-    void *adjustedPtr;
-
+    char const * actionRecord;
+    char const * languageSpecificData;
+    void * catchTemp;
+    void * adjustedPtr;
     _Unwind_Exception unwindHeader;
 };
+}
+#endif
 
-struct __cxa_eh_globals
-{
-    __cxa_exception *caughtExceptions;
+#if !HAVE_CXXABI_H_CXA_EH_GLOBALS
+// <https://mentorembedded.github.io/cxx-abi/abi-eh.html>:
+namespace __cxxabiv1 {
+struct __cxa_eh_globals {
+    __cxa_exception * caughtExceptions;
     unsigned int uncaughtExceptions;
 };
-
 }
+#endif
 
-// __cxa_get_globals is exported from libstdc++ since GCC 3.4.0 (CXXABI_1.3),
-// but it is only declared in cxxabi.h (in namespace __cxxabiv1) since
-// GCC 4.7.0.  It returns a pointer to a struct __cxa_eh_globals, but that
-// struct is only incompletely declared even in the GCC 4.7.0 cxxabi.h.
-// Therefore, provide a declaration here for old GCC (libstdc++, really) version
-// that returns a void pointer, and in the code calling it always cast to the
-// above fake definition of CPPU_CURRENT_NAMESPACE::__cxa_eh_globals (which
-// hopefully keeps matching the real definition in libstdc++); similarly for
-// __cxa_allocate_exception and __cxa_throw, though they do not have the
-// additional problem of an incompletely declared return type:
-
-#if !HAVE_GCC_CXXABI_H_CXA_GET_GLOBALS
-namespace __cxxabiv1 { extern "C" void * __cxa_get_globals() throw(); }
+#if !HAVE_CXXABI_H_CXA_GET_GLOBALS
+namespace __cxxabiv1 {
+extern "C" __cxa_eh_globals * __cxa_get_globals() throw();
+}
 #endif
 
-#if !HAVE_GCC_CXXABI_H_CXA_ALLOCATE_EXCEPTION
+#if !HAVE_CXXABI_H_CXA_ALLOCATE_EXCEPTION
 namespace __cxxabiv1 {
 extern "C" void * __cxa_allocate_exception(std::size_t thrown_size) throw();
 }
 #endif
 
-#if !HAVE_GCC_CXXABI_H_CXA_THROW
+#if !HAVE_CXXABI_H_CXA_THROW
 namespace __cxxabiv1 {
 extern "C" void __cxa_throw(
     void * thrown_exception, void * tinfo, void (* dest)(void *))
@@ -129,8 +157,6 @@ extern "C" void __cxa_throw(
 }
 #endif
 
-#endif
-
 extern "C" void privateSnippetExecutor( ... );
 
 namespace CPPU_CURRENT_NAMESPACE
@@ -140,11 +166,7 @@ void raiseException(
     uno_Any * pUnoExc, uno_Mapping * pUno2Cpp );
 
 void fillUnoException(
-#ifdef _LIBCPP_VERSION
     __cxxabiv1::__cxa_exception * header, uno_Any *, uno_Mapping * pCpp2Uno );
-#else
-    __cxa_exception * header, uno_Any *, uno_Mapping * pCpp2Uno );
-#endif
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/bridges/source/cpp_uno/gcc3_linux_x86-64/uno2cpp.cxx b/bridges/source/cpp_uno/gcc3_linux_x86-64/uno2cpp.cxx
index f65ac57..71e76a9 100644
--- a/bridges/source/cpp_uno/gcc3_linux_x86-64/uno2cpp.cxx
+++ b/bridges/source/cpp_uno/gcc3_linux_x86-64/uno2cpp.cxx
@@ -294,17 +294,9 @@ static void cpp_call(
      catch (...)
      {
          // fill uno exception
-#ifdef _LIBCPP_VERSION
          CPPU_CURRENT_NAMESPACE::fillUnoException(
-             reinterpret_cast< __cxxabiv1::__cxa_eh_globals * >(
-                 __cxxabiv1::__cxa_get_globals())->caughtExceptions,
+             __cxxabiv1::__cxa_get_globals()->caughtExceptions,
              *ppUnoExc, pThis->getBridge()->getCpp2Uno());
-#else
-         fillUnoException(
-             reinterpret_cast< CPPU_CURRENT_NAMESPACE::__cxa_eh_globals * >(
-                 __cxxabiv1::__cxa_get_globals())->caughtExceptions,
-             *ppUnoExc, pThis->getBridge()->getCpp2Uno());
-#endif
 
         // temporary params
         for ( ; nTempIndices--; )
diff --git a/bridges/source/cpp_uno/msvc_win32_intel/except.cxx b/bridges/source/cpp_uno/msvc_win32_intel/except.cxx
index 8dd8810..d6c6271 100644
--- a/bridges/source/cpp_uno/msvc_win32_intel/except.cxx
+++ b/bridges/source/cpp_uno/msvc_win32_intel/except.cxx
@@ -28,6 +28,7 @@
 #include "rtl/strbuf.hxx"
 #include "rtl/ustrbuf.hxx"
 #include <sal/log.hxx>
+#include <osl/mutex.hxx>
 
 #include "com/sun/star/uno/Any.hxx"
 #include <unordered_map>
diff --git a/vcl/inc/unx/gtk/gtkframe.hxx b/vcl/inc/unx/gtk/gtkframe.hxx
index b9514c0..3748847 100644
--- a/vcl/inc/unx/gtk/gtkframe.hxx
+++ b/vcl/inc/unx/gtk/gtkframe.hxx
@@ -171,6 +171,9 @@ class GtkSalFrame : public SalFrame
 
     SalX11Screen                    m_nXScreen;
     GtkWidget*                      m_pWindow;
+#if GTK_CHECK_VERSION(3,0,0)
+    GtkGrid*                        m_pTopLevelGrid;
+#endif
     GtkEventBox*                    m_pEventBox;
     GtkFixed*                       m_pFixedContainer;
     GdkWindow*                      m_pForeignParent;
@@ -369,6 +372,9 @@ public:
     GtkFixed*   getFixedContainer() const { return m_pFixedContainer; }
     GtkEventBox* getEventBox() const { return m_pEventBox; }
     GtkWidget*  getMouseEventWidget() const;
+#if GTK_CHECK_VERSION(3,0,0)
+    GtkGrid*    getTopLevelGridWidget() const { return m_pTopLevelGrid; }
+#endif
     GdkWindow*  getForeignParent() const { return m_pForeignParent; }
     GdkNativeWindow getForeignParentWindow() const { return m_aForeignParentWindow; }
     GdkWindow*  getForeignTopLevel() const { return m_pForeignTopLevel; }
diff --git a/vcl/unx/gtk/gtksalmenu.cxx b/vcl/unx/gtk/gtksalmenu.cxx
index 961d658..75c19c3 100644
--- a/vcl/unx/gtk/gtksalmenu.cxx
+++ b/vcl/unx/gtk/gtksalmenu.cxx
@@ -44,7 +44,11 @@ static gchar* GetCommandForItem(GtkSalMenuItem* pSalMenuItem)
 
 bool GtkSalMenu::PrepUpdate()
 {
+#if GTK_CHECK_VERSION(3,0,0)
+    return mpMenuModel && mpActionGroup;
+#else
     return bUnityMode && mpMenuModel && mpActionGroup;
+#endif
 }
 
 /*
@@ -321,13 +325,94 @@ void GtkSalMenu::Update()
     ImplUpdate(false, !pMenu->mbMenuBar);
 }
 
+#if GTK_CHECK_VERSION(3,0,0)
+static void MenuPositionFunc(GtkMenu* menu, gint* x, gint* y, gboolean* push_in, gpointer user_data)
+{
+    Point *pPos = static_cast<Point*>(user_data);
+    *x = pPos->X();
+    if (gtk_widget_get_default_direction() == GTK_TEXT_DIR_RTL)
+    {
+        GtkRequisition natural_size;
+        gtk_widget_get_preferred_size(GTK_WIDGET(menu), nullptr, &natural_size);
+        *x -= natural_size.width;
+    }
+    *y = pPos->Y();
+    *push_in = false;
+}
+#endif
+
 bool GtkSalMenu::ShowNativePopupMenu(FloatingWindow* pWin, const Rectangle& rRect,
                                      FloatWinPopupFlags nFlags)
 {
+#if GTK_CHECK_VERSION(3,0,0)
+    guint nButton;
+    guint32 nTime;
+
+    //typically there is an event, and we can then distinguish if this was
+    //launched from the keyboard (gets auto-mnemoniced) or the mouse (which
+    //doesn't)
+    GdkEvent *pEvent = gtk_get_current_event();
+    if (pEvent)
+    {
+        gdk_event_get_button(pEvent, &nButton);
+        nTime = gdk_event_get_time(pEvent);
+    }
+    else
+    {
+        nButton = 0;
+        nTime = GtkSalFrame::GetLastInputEventTime();
+    }
+
+    VclPtr<vcl::Window> xParent = pWin->ImplGetWindowImpl()->mpRealParent;
+    mpFrame = static_cast<GtkSalFrame*>(xParent->ImplGetFrame());
+
+    // do the same strange semantics as vcl popup windows to arrive at a frame geometry
+    // in mirrored UI case; best done by actually executing the same code
+    sal_uInt16 nArrangeIndex;
+    Point aPos = FloatingWindow::ImplCalcPos(pWin, rRect, nFlags, nArrangeIndex);
+    aPos = FloatingWindow::ImplConvertToAbsPos(xParent, aPos);
+
+    GLOActionGroup* pActionGroup = g_lo_action_group_new();
+    mpActionGroup = G_ACTION_GROUP(pActionGroup);
+    mpMenuModel = G_MENU_MODEL(g_lo_menu_new());
+    // Generate the main menu structure, populates mpMenuModel
+    UpdateFull();
+
+    GtkWidget *pWidget = gtk_menu_new_from_model(mpMenuModel);
+    gtk_menu_attach_to_widget(GTK_MENU(pWidget), mpFrame->getMouseEventWidget(), nullptr);
+
+    gtk_widget_insert_action_group(mpFrame->getMouseEventWidget(), "win", mpActionGroup);
+
+    //run in a sub main loop because we need to keep vcl PopupMenu alive to use
+    //it during DispatchCommand, returning now to the outer loop causes the
+    //launching PopupMenu to be destroyed, instead run the subloop here
+    //until the gtk menu is destroyed
+    GMainLoop* pLoop = g_main_loop_new(nullptr, true);
+    g_signal_connect_swapped(G_OBJECT(pWidget), "deactivate", G_CALLBACK(g_main_loop_quit), pLoop);
+    gtk_menu_popup(GTK_MENU(pWidget), nullptr, nullptr, MenuPositionFunc,
+                   &aPos, nButton, nTime);
+    if (g_main_loop_is_running(pLoop))
+    {
+        gdk_threads_leave();
+        g_main_loop_run(pLoop);
+        gdk_threads_enter();
+    }
+    g_main_loop_unref(pLoop);
+
+    gtk_widget_insert_action_group(mpFrame->getMouseEventWidget(), "win", nullptr);
+
+    gtk_widget_destroy(pWidget);
+
+    g_object_unref(mpActionGroup);
+    ClearActionGroupAndMenuModel();
+
+    return true;
+#else
     (void)pWin;
     (void)rRect;
     (void)nFlags;
     return false;
+#endif
 }
 
 /*
@@ -398,7 +483,11 @@ GtkSalMenu::~GtkSalMenu()
 
 bool GtkSalMenu::VisibleMenuBar()
 {
+#if GTK_CHECK_VERSION(3,0,0)
+    return mbMenuBar;
+#else
     return mbMenuBar && bUnityMode;
+#endif
 }
 
 void GtkSalMenu::InsertItem( SalMenuItem* pSalMenuItem, unsigned nPos )
@@ -438,11 +527,69 @@ void GtkSalMenu::SetSubMenu( SalMenuItem* pSalMenuItem, SalMenu* pSubMenu, unsig
     SetNeedsUpdate();
 }
 
+#if GTK_CHECK_VERSION(3,0,0)
+static void CloseMenuBar(GtkWidget *, gpointer pMenu)
+{
+    Application::PostUserEvent(static_cast<MenuBar*>(pMenu)->GetCloseButtonClickHdl());
+}
+#endif
+
 void GtkSalMenu::ShowCloseButton(bool bShow)
 {
+#if GTK_CHECK_VERSION(3,0,0)
+    assert(mbMenuBar);
+    MenuBar *pVclMenuBar = static_cast<MenuBar*>(mpVCLMenu.get());
+    if (!bShow)
+    {
+        if (mpCloseButton)
+            gtk_widget_destroy(mpCloseButton);
+        return;
+    }
+
+    mpCloseButton = gtk_button_new();
+    g_signal_connect(mpCloseButton, "clicked", G_CALLBACK(CloseMenuBar), pVclMenuBar);
+
+    gtk_button_set_relief(GTK_BUTTON(mpCloseButton), GTK_RELIEF_NONE);
+    gtk_button_set_focus_on_click(GTK_BUTTON(mpCloseButton), false);
+    gtk_widget_set_can_focus(mpCloseButton, false);
+
+    GtkStyleContext *pButtonContext = gtk_widget_get_style_context(GTK_WIDGET(mpCloseButton));
+
+    GtkCssProvider *pProvider = gtk_css_provider_new();
+    const gchar data[] = "* { "
+      "padding: 0;"
+      "margin-left: 8px;"
+      "margin-right: 8px;"
+      "min-width: 18px;"
+      "min-height: 18px;"
+      "}";
+    gtk_css_provider_load_from_data(pProvider, data, -1, nullptr);
+    gtk_style_context_add_provider(pButtonContext,
+                                   GTK_STYLE_PROVIDER(pProvider),
+                                   GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+
+    gtk_style_context_add_class(pButtonContext, "flat");
+    gtk_style_context_add_class(pButtonContext, "small-button");
+
+    GIcon* icon = g_themed_icon_new_with_default_fallbacks("window-close-symbolic");
+    GtkWidget* image = gtk_image_new_from_gicon(icon, GTK_ICON_SIZE_MENU);
+    gtk_widget_show(image);
+    g_object_unref(icon);
+
+    OUString sToolTip(VclResId(SV_HELPTEXT_CLOSEDOCUMENT));
+    gtk_widget_set_tooltip_text(mpCloseButton,
+        OUStringToOString(sToolTip, RTL_TEXTENCODING_UTF8).getStr());
+
+    gtk_widget_set_valign(mpCloseButton, GTK_ALIGN_CENTER);
+
+    gtk_container_add(GTK_CONTAINER(mpCloseButton), image);
+    gtk_grid_attach(GTK_GRID(mpMenuBarContainerWidget), GTK_WIDGET(mpCloseButton), 1, 0, 1, 1);
+    gtk_widget_show_all(mpCloseButton);
+#else
     (void)bShow;
     (void)mpMenuBarContainerWidget;
     (void)mpCloseButton;
+#endif
 }
 
 //Typically when the menubar is deactivated we want the focus to return
@@ -520,14 +667,56 @@ bool GtkSalMenu::TakeFocus()
     return true;
 }
 
+#if GTK_CHECK_VERSION(3,0,0)
+
+static void MenuBarReturnFocus(GtkMenuShell*, gpointer menu)
+{
+    GtkSalMenu* pMenu = static_cast<GtkSalMenu*>(menu);
+    pMenu->ReturnFocus();
+}
+
+static gboolean MenuBarSignalKey(GtkWidget*, GdkEventKey* pEvent, gpointer menu)
+{
+    GtkSalMenu* pMenu = static_cast<GtkSalMenu*>(menu);
+    return pMenu->SignalKey(pEvent);
+}
+
+#endif
+
 void GtkSalMenu::CreateMenuBarWidget()
 {
+#if GTK_CHECK_VERSION(3,0,0)
+    GtkGrid* pGrid = mpFrame->getTopLevelGridWidget();
+    mpMenuBarContainerWidget = gtk_grid_new();
+
+    gtk_widget_set_hexpand(GTK_WIDGET(mpMenuBarContainerWidget), true);
+    gtk_grid_insert_row(pGrid, 0);
+    gtk_grid_attach(pGrid, mpMenuBarContainerWidget, 0, 0, 1, 1);
+
+    mpMenuBarWidget = gtk_menu_bar_new_from_model(mpMenuModel);
+    gtk_widget_insert_action_group(mpMenuBarWidget, "win", mpActionGroup);
+    gtk_widget_set_hexpand(GTK_WIDGET(mpMenuBarWidget), true);
+    gtk_grid_attach(GTK_GRID(mpMenuBarContainerWidget), mpMenuBarWidget, 0, 0, 1, 1);
+    g_signal_connect(G_OBJECT(mpMenuBarWidget), "deactivate", G_CALLBACK(MenuBarReturnFocus), this);
+    g_signal_connect(G_OBJECT(mpMenuBarWidget), "key-press-event", G_CALLBACK(MenuBarSignalKey), this);
+
+    gtk_widget_show_all(mpMenuBarContainerWidget);
+#else
     (void)mpMenuBarContainerWidget;
+#endif
 }
 
 void GtkSalMenu::DestroyMenuBarWidget()
 {
+#if GTK_CHECK_VERSION(3,0,0)
+    if (mpMenuBarContainerWidget)
+    {
+        gtk_widget_destroy(mpMenuBarContainerWidget);
+        mpMenuBarContainerWidget = nullptr;
+    }
+#else
     (void)mpMenuBarContainerWidget;
+#endif
 }
 
 void GtkSalMenu::SetFrame(const SalFrame* pFrame)
@@ -570,6 +759,13 @@ void GtkSalMenu::SetFrame(const SalFrame* pFrame)
 
     g_lo_menu_insert_section( pMenuModel, 0, nullptr, mpMenuModel );
 
+#if GTK_CHECK_VERSION(3,0,0)
+    if (!bUnityMode)
+    {
+        DestroyMenuBarWidget();
+        CreateMenuBarWidget();
+    }
+#endif
 }
 
 const GtkSalFrame* GtkSalMenu::GetFrame() const
diff --git a/vcl/unx/gtk3/gtk3gtkframe.cxx b/vcl/unx/gtk3/gtk3gtkframe.cxx
index 4973c70..adafe8b 100644
--- a/vcl/unx/gtk3/gtk3gtkframe.cxx
+++ b/vcl/unx/gtk3/gtk3gtkframe.cxx
@@ -819,6 +819,8 @@ GtkSalFrame::~GtkSalFrame()
         gtk_widget_destroy( GTK_WIDGET( m_pFixedContainer ) );
     if( m_pEventBox )
         gtk_widget_destroy( GTK_WIDGET(m_pEventBox) );
+    if( m_pTopLevelGrid )
+        gtk_widget_destroy( GTK_WIDGET(m_pTopLevelGrid) );
     {
         SolarMutexGuard aGuard;
 #if defined ENABLE_GMENU_INTEGRATION
@@ -964,13 +966,15 @@ void GtkSalFrame::InitCommon()
     m_aDamageHandler.handle = this;
     m_aDamageHandler.damaged = ::damaged;
 
+    m_pTopLevelGrid = GTK_GRID(gtk_grid_new());
+    gtk_container_add(GTK_CONTAINER(m_pWindow), GTK_WIDGET(m_pTopLevelGrid));
 
     m_pEventBox = GTK_EVENT_BOX(gtk_event_box_new());
     gtk_widget_add_events( GTK_WIDGET(m_pEventBox),
                            GDK_ALL_EVENTS_MASK );
     gtk_widget_set_vexpand(GTK_WIDGET(m_pEventBox), true);
     gtk_widget_set_hexpand(GTK_WIDGET(m_pEventBox), true);
-    gtk_container_add(GTK_CONTAINER(m_pWindow), GTK_WIDGET(m_pEventBox));
+    gtk_grid_attach(m_pTopLevelGrid, GTK_WIDGET(m_pEventBox), 0, 0, 1, 1);
 
     // add the fixed container child,
     // fixed is needed since we have to position plugin windows
@@ -1070,7 +1074,7 @@ void GtkSalFrame::InitCommon()
                            );
 
     // show the widgets
-    gtk_widget_show_all(GTK_WIDGET(m_pEventBox));
+    gtk_widget_show_all(GTK_WIDGET(m_pTopLevelGrid));
 
     // realize the window, we need an XWindow id
     gtk_widget_realize( m_pWindow );
@@ -3458,6 +3462,7 @@ void GtkSalFrame::signalDestroy( GtkWidget* pObj, gpointer frame )
     {
         pThis->m_pFixedContainer = nullptr;
         pThis->m_pEventBox = nullptr;
+        pThis->m_pTopLevelGrid = nullptr;
         pThis->m_pWindow = nullptr;
         pThis->InvalidateGraphics();
     }


More information about the Libreoffice-commits mailing list