[gtk/kill-tree-menu: 17/52] window: Move F10 handling to popover menubars



commit 473d3ae72ead87468269d87514308ead9aa31ade
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Dec 27 08:45:21 2019 -0500

    window: Move F10 handling to popover menubars

 gtk/gtkpopovermenubar.c        | 97 +++++++++++++++++++++++++++++++++++++++++-
 gtk/gtkpopovermenubarprivate.h | 31 ++++++++++++++
 gtk/gtkwindow.c                |  9 ++--
 3 files changed, 130 insertions(+), 7 deletions(-)
---
diff --git a/gtk/gtkpopovermenubar.c b/gtk/gtkpopovermenubar.c
index f00c38960c..94f9dbe3d4 100644
--- a/gtk/gtkpopovermenubar.c
+++ b/gtk/gtkpopovermenubar.c
@@ -49,6 +49,7 @@
 #include "config.h"
 
 #include "gtkpopovermenubar.h"
+#include "gtkpopovermenubarprivate.h"
 #include "gtkpopovermenu.h"
 
 #include "gtkboxlayout.h"
@@ -470,7 +471,6 @@ gtk_popover_menu_bar_get_property (GObject    *object,
     }
 }
 
-
 static void
 gtk_popover_menu_bar_dispose (GObject *object)
 {
@@ -486,6 +486,90 @@ gtk_popover_menu_bar_dispose (GObject *object)
   G_OBJECT_CLASS (gtk_popover_menu_bar_parent_class)->dispose (object);
 }
 
+static GList *
+get_menu_bars (GtkWindow *window)
+{
+  return g_object_get_data (G_OBJECT (window), "gtk-menu-bar-list");
+}
+
+GList *
+gtk_popover_menu_bar_get_viewable_menu_bars (GtkWindow *window)
+{
+  GList *menu_bars;
+  GList *viewable_menu_bars = NULL;
+
+  for (menu_bars = get_menu_bars (window);
+       menu_bars;
+       menu_bars = menu_bars->next)
+    {
+      GtkWidget *widget = menu_bars->data;
+      gboolean viewable = TRUE;
+
+      while (widget)
+        {
+          if (!gtk_widget_get_mapped (widget))
+            viewable = FALSE;
+
+          widget = gtk_widget_get_parent (widget);
+        }
+
+      if (viewable)
+        viewable_menu_bars = g_list_prepend (viewable_menu_bars, menu_bars->data);
+    }
+
+  return g_list_reverse (viewable_menu_bars);
+}
+
+static void
+set_menu_bars (GtkWindow *window,
+               GList     *menubars)
+{
+  g_object_set_data (G_OBJECT (window), I_("gtk-menu-bar-list"), menubars);
+}
+
+static void
+add_to_window (GtkWindow         *window,
+               GtkPopoverMenuBar *bar)
+{
+  GList *menubars = get_menu_bars (window);
+
+  set_menu_bars (window, g_list_prepend (menubars, bar));
+}
+
+static void
+remove_from_window (GtkWindow         *window,
+                    GtkPopoverMenuBar *bar)
+{
+  GList *menubars = get_menu_bars (window);
+
+  menubars = g_list_remove (menubars, bar);
+  set_menu_bars (window, menubars);
+}
+
+static void
+gtk_popover_menu_bar_root (GtkWidget *widget)
+{
+  GtkPopoverMenuBar *bar = GTK_POPOVER_MENU_BAR (widget);
+  GtkWidget *toplevel;
+
+  GTK_WIDGET_CLASS (gtk_popover_menu_bar_parent_class)->root (widget);
+
+  toplevel = GTK_WIDGET (gtk_widget_get_root (widget));
+  add_to_window (GTK_WINDOW (toplevel), bar);
+}
+
+static void
+gtk_popover_menu_bar_unroot (GtkWidget *widget)
+{
+  GtkPopoverMenuBar *bar = GTK_POPOVER_MENU_BAR (widget);
+  GtkWidget *toplevel;
+
+  toplevel = GTK_WIDGET (gtk_widget_get_root (widget));
+  remove_from_window (GTK_WINDOW (toplevel), bar);
+
+  GTK_WIDGET_CLASS (gtk_popover_menu_bar_parent_class)->unroot (widget);
+}
+
 static void
 gtk_popover_menu_bar_class_init (GtkPopoverMenuBarClass *klass)
 {
@@ -496,6 +580,8 @@ gtk_popover_menu_bar_class_init (GtkPopoverMenuBarClass *klass)
   object_class->set_property = gtk_popover_menu_bar_set_property;
   object_class->get_property = gtk_popover_menu_bar_get_property;
 
+  widget_class->root = gtk_popover_menu_bar_root;
+  widget_class->unroot = gtk_popover_menu_bar_unroot;
   widget_class->focus = gtk_popover_menu_bar_focus;
 
   /**
@@ -604,3 +690,12 @@ gtk_popover_menu_bar_get_menu_model (GtkPopoverMenuBar *bar)
 
   return bar->model;
 }
+
+void
+gtk_popover_menu_bar_select_first (GtkPopoverMenuBar *bar)
+{
+  GtkPopoverMenuBarItem *item;
+
+  item = GTK_POPOVER_MENU_BAR_ITEM (gtk_widget_get_first_child (GTK_WIDGET (bar)));
+  set_active_item (bar, item, TRUE);
+}
diff --git a/gtk/gtkpopovermenubarprivate.h b/gtk/gtkpopovermenubarprivate.h
new file mode 100644
index 0000000000..a6462c8ac8
--- /dev/null
+++ b/gtk/gtkpopovermenubarprivate.h
@@ -0,0 +1,31 @@
+/* GTK - The GIMP Toolkit
+ * Copyright © 2019 Carlos Garnacho <carlosg gnome org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GTK_POPOVER_MENU_BAR_PRIVATE_H__
+#define __GTK_POPOVER_MENU_BAR_PRIVATE_H__
+
+#include "gtkpopovermenubar.h"
+
+G_BEGIN_DECLS
+
+void   gtk_popover_menu_bar_select_first           (GtkPopoverMenuBar *bar);
+GList* gtk_popover_menu_bar_get_viewable_menu_bars (GtkWindow         *window);
+
+
+G_END_DECLS
+
+#endif /* __GTK_POPOVER_PRIVATE_H__ */
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index c4e60524b9..408800268b 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -67,6 +67,7 @@
 #include "gtktypebuiltins.h"
 #include "gtkwidgetprivate.h"
 #include "gtkwindowgroup.h"
+#include "gtkpopovermenubarprivate.h"
 
 #include "a11y/gtkwindowaccessibleprivate.h"
 #include "a11y/gtkcontaineraccessibleprivate.h"
@@ -8262,7 +8263,6 @@ gtk_window_activate_menubar (GtkWindow   *window,
     {
       GList *tmp_menubars, *l;
       GPtrArray *menubars;
-      GtkMenuShell *menu_shell;
       GtkWidget *focus;
       GtkWidget *first;
 
@@ -8273,7 +8273,7 @@ gtk_window_activate_menubar (GtkWindow   *window,
           gtk_widget_child_focus (priv->title_box, GTK_DIR_TAB_FORWARD))
         return TRUE;
 
-      tmp_menubars = _gtk_menu_bar_get_viewable_menu_bars (window);
+      tmp_menubars = gtk_popover_menu_bar_get_viewable_menu_bars (window);
       if (tmp_menubars == NULL)
         return FALSE;
 
@@ -8286,10 +8286,7 @@ gtk_window_activate_menubar (GtkWindow   *window,
       gtk_widget_focus_sort (GTK_WIDGET (window), GTK_DIR_TAB_FORWARD, menubars);
 
       first = g_ptr_array_index (menubars, 0);
-      menu_shell = GTK_MENU_SHELL (first);
-
-      _gtk_menu_shell_set_keyboard_mode (menu_shell, TRUE);
-      gtk_menu_shell_select_first (menu_shell, FALSE);
+      gtk_popover_menu_bar_select_first (GTK_POPOVER_MENU_BAR (first));
 
       g_ptr_array_free (menubars, TRUE);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]