vcl/unx/gtk3/gtkinst.cxx |   28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

New commits:
commit 600780e9904958bf91585d5e232e0cfa0c95827a
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Wed Aug 10 13:11:05 2022 +0100
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Thu Aug 11 12:43:19 2022 +0200

    gtk3: silence 'invalid cast from 'GtkWindow' to 'GtkMenuShell' warning
    
    from the sidebar tab due to the accelerators in there
    
    its a bogus check in gtk3 in this case of a menu attached to a MenuButton
    
    Change-Id: Ie5216e749993f3d44bfc2e4560cd3b2f49aa8aec
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138086
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx
index 31e021140a0f..c434996c9552 100644
--- a/vcl/unx/gtk3/gtkinst.cxx
+++ b/vcl/unx/gtk3/gtkinst.cxx
@@ -23008,16 +23008,44 @@ bool IsAllowedBuiltInIcon(std::u16string_view 
iconName)
 
 namespace {
 
+#if !GTK_CHECK_VERSION(4, 0, 0)
+void silence_gwarning(const gchar* /*log_domain*/,
+                      GLogLevelFlags /*log_level*/,
+                      const gchar* /*message*/,
+                      gpointer /*user_data*/)
+{
+}
+#endif
+
 void load_ui_file(GtkBuilder* pBuilder, const OUString& rUri)
 {
 #if GTK_CHECK_VERSION(4, 0, 0)
     builder_add_from_gtk3_file(pBuilder, rUri);
 #else
+    guint nLogHandlerId = 0;
+    GLogLevelFlags 
nFatalMask(static_cast<GLogLevelFlags>(G_LOG_FLAG_RECURSION|G_LOG_LEVEL_ERROR));
+    if (rUri.endsWith("sfx/ui/tabbarcontents.ui"))
+    {
+        // gtk unhelpfully has a bogus warning for the accelerator in this .ui 
because it assumes menus with accelerators
+        // if attached to something are attached to a MenuShell, but it's a 
MenuButton in this case. Turn off warnings, and
+        // in the case of fatal-warnings temp disable fatal warnings, for this 
case.
+        nLogHandlerId = g_log_set_handler("GLib-GObject",
+                                          
static_cast<GLogLevelFlags>(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | 
G_LOG_FLAG_RECURSION),
+                                          silence_gwarning, nullptr);
+        nFatalMask = g_log_set_always_fatal(nFatalMask);
+    }
+
     OUString aPath;
     osl::FileBase::getSystemPathFromFileURL(rUri, aPath);
     GError *err = nullptr;
     auto rc = gtk_builder_add_from_file(pBuilder, OUStringToOString(aPath, 
RTL_TEXTENCODING_UTF8).getStr(), &err);
 
+    if (nLogHandlerId)
+    {
+        g_log_remove_handler("GLib-GObject", nLogHandlerId);
+        g_log_set_always_fatal(nFatalMask);
+    }
+
     if (!rc)
     {
         SAL_WARN( "vcl.gtk", "GtkInstanceBuilder: error when calling 
gtk_builder_add_from_file: " << err->message);

Reply via email to