2014-10-24 03:38:09 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
* Copyright © 2014 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "gtkpopovermenu.h"
|
2019-06-13 00:13:21 +00:00
|
|
|
#include "gtkpopovermenuprivate.h"
|
|
|
|
|
2014-10-24 03:38:09 +00:00
|
|
|
#include "gtkstack.h"
|
2015-10-30 14:08:18 +00:00
|
|
|
#include "gtkstylecontext.h"
|
2014-10-24 03:38:09 +00:00
|
|
|
#include "gtkintl.h"
|
2019-06-10 03:10:13 +00:00
|
|
|
#include "gtkmenusectionboxprivate.h"
|
2019-06-07 17:05:48 +00:00
|
|
|
#include "gtkmenubutton.h"
|
|
|
|
#include "gtkactionmuxerprivate.h"
|
2019-06-10 03:10:13 +00:00
|
|
|
#include "gtkmenutrackerprivate.h"
|
2017-07-08 10:04:44 +00:00
|
|
|
#include "gtkpopoverprivate.h"
|
2019-06-07 17:05:48 +00:00
|
|
|
#include "gtkwidgetprivate.h"
|
2020-02-20 01:51:03 +00:00
|
|
|
#include "gtkeventcontrollerfocus.h"
|
2019-08-27 08:28:29 +00:00
|
|
|
#include "gtkeventcontrollermotion.h"
|
2019-06-09 14:08:18 +00:00
|
|
|
#include "gtkmain.h"
|
2019-06-12 16:35:36 +00:00
|
|
|
#include "gtktypebuiltins.h"
|
|
|
|
#include "gtkbindings.h"
|
2019-11-11 10:58:43 +00:00
|
|
|
#include "gtkmodelbuttonprivate.h"
|
2019-08-27 08:28:29 +00:00
|
|
|
#include "gtkpopovermenubar.h"
|
2014-10-24 03:38:09 +00:00
|
|
|
|
|
|
|
|
2014-10-26 23:04:28 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gtkpopovermenu
|
|
|
|
* @Short_description: Popovers to use as menus
|
|
|
|
* @Title: GtkPopoverMenu
|
|
|
|
*
|
|
|
|
* GtkPopoverMenu is a subclass of #GtkPopover that treats its
|
2019-12-30 00:44:31 +00:00
|
|
|
* children like menus and allows switching between them. It
|
|
|
|
* can open submenus as traditional, nested submenus, or in a
|
|
|
|
* more touch-friendly sliding fashion.
|
2014-10-26 23:04:28 +00:00
|
|
|
*
|
2019-12-30 00:44:31 +00:00
|
|
|
* GtkPopoverMenu is meant to be used primarily with menu models,
|
|
|
|
* using gtk_popover_menu_new_from_model(). If you need to put other
|
|
|
|
* widgets such as #GtkSpinButton or #GtkSwitch into a popover,
|
|
|
|
* use a #GtkPopover.
|
2019-03-27 22:37:57 +00:00
|
|
|
*
|
2019-12-30 00:44:31 +00:00
|
|
|
* In addition to all the regular menu model features, this function
|
|
|
|
* supports rendering sections in the model in a more compact form,
|
|
|
|
* as a row of image buttons instead of menu items.
|
2014-10-26 23:04:28 +00:00
|
|
|
*
|
2019-12-30 00:44:31 +00:00
|
|
|
* To use this rendering, set the ”display-hint” attribute of the
|
|
|
|
* section to ”horizontal-buttons” and set the icons of your items
|
|
|
|
* with the ”verb-icon” attribute.
|
2015-10-30 14:08:18 +00:00
|
|
|
*
|
2017-07-08 10:04:44 +00:00
|
|
|
* # CSS Nodes
|
|
|
|
*
|
|
|
|
* #GtkPopoverMenu is just a subclass of #GtkPopover that adds
|
|
|
|
* custom content to it, therefore it has the same CSS nodes.
|
2020-02-18 10:03:37 +00:00
|
|
|
* It is one of the cases that add a .menu style class to
|
|
|
|
* the popover's main node.
|
2014-10-26 23:04:28 +00:00
|
|
|
*/
|
|
|
|
|
2019-05-19 20:45:42 +00:00
|
|
|
typedef struct _GtkPopoverMenuClass GtkPopoverMenuClass;
|
|
|
|
|
2014-10-24 03:38:09 +00:00
|
|
|
struct _GtkPopoverMenu
|
|
|
|
{
|
|
|
|
GtkPopover parent_instance;
|
2019-06-13 00:13:21 +00:00
|
|
|
|
|
|
|
GtkWidget *active_item;
|
2019-08-27 08:28:29 +00:00
|
|
|
GtkWidget *open_submenu;
|
|
|
|
GtkWidget *parent_menu;
|
2019-11-11 10:58:43 +00:00
|
|
|
GMenuModel *model;
|
|
|
|
GtkPopoverMenuFlags flags;
|
2014-10-24 03:38:09 +00:00
|
|
|
};
|
|
|
|
|
2019-05-19 20:45:42 +00:00
|
|
|
struct _GtkPopoverMenuClass
|
|
|
|
{
|
|
|
|
GtkPopoverClass parent_class;
|
|
|
|
};
|
|
|
|
|
2014-10-24 03:38:09 +00:00
|
|
|
enum {
|
2019-11-11 10:58:43 +00:00
|
|
|
PROP_VISIBLE_SUBMENU = 1,
|
|
|
|
PROP_MENU_MODEL
|
2014-11-18 12:39:15 +00:00
|
|
|
};
|
|
|
|
|
2014-10-24 03:38:09 +00:00
|
|
|
G_DEFINE_TYPE (GtkPopoverMenu, gtk_popover_menu, GTK_TYPE_POPOVER)
|
|
|
|
|
2019-08-27 08:28:29 +00:00
|
|
|
GtkWidget *
|
|
|
|
gtk_popover_menu_get_parent_menu (GtkPopoverMenu *menu)
|
|
|
|
{
|
|
|
|
return menu->parent_menu;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_popover_menu_set_parent_menu (GtkPopoverMenu *menu,
|
|
|
|
GtkWidget *parent)
|
|
|
|
{
|
|
|
|
menu->parent_menu = parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
gtk_popover_menu_get_open_submenu (GtkPopoverMenu *menu)
|
|
|
|
{
|
|
|
|
return menu->open_submenu;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gtk_popover_menu_set_open_submenu (GtkPopoverMenu *menu,
|
|
|
|
GtkWidget *submenu)
|
|
|
|
{
|
|
|
|
menu->open_submenu = submenu;
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
gtk_popover_menu_get_active_item (GtkPopoverMenu *menu)
|
|
|
|
{
|
|
|
|
return menu->active_item;
|
|
|
|
}
|
|
|
|
|
2019-06-13 00:13:21 +00:00
|
|
|
void
|
|
|
|
gtk_popover_menu_set_active_item (GtkPopoverMenu *menu,
|
|
|
|
GtkWidget *item)
|
|
|
|
{
|
|
|
|
if (menu->active_item != item)
|
|
|
|
{
|
|
|
|
if (menu->active_item)
|
2019-12-27 06:31:25 +00:00
|
|
|
{
|
|
|
|
gtk_widget_unset_state_flags (menu->active_item, GTK_STATE_FLAG_SELECTED);
|
|
|
|
g_object_remove_weak_pointer (G_OBJECT (menu->active_item), (gpointer *)&menu->active_item);
|
|
|
|
}
|
2019-06-13 00:13:21 +00:00
|
|
|
|
|
|
|
menu->active_item = item;
|
|
|
|
|
|
|
|
if (menu->active_item)
|
|
|
|
{
|
2019-08-27 08:28:29 +00:00
|
|
|
GtkWidget *popover;
|
|
|
|
|
2019-12-27 06:31:25 +00:00
|
|
|
g_object_add_weak_pointer (G_OBJECT (menu->active_item), (gpointer *)&menu->active_item);
|
|
|
|
|
2019-06-13 00:13:21 +00:00
|
|
|
gtk_widget_set_state_flags (menu->active_item, GTK_STATE_FLAG_SELECTED, FALSE);
|
2019-08-27 08:28:29 +00:00
|
|
|
if (GTK_IS_MODEL_BUTTON (item))
|
|
|
|
g_object_get (item, "popover", &popover, NULL);
|
2020-02-12 22:58:41 +00:00
|
|
|
else
|
|
|
|
popover = NULL;
|
2019-08-27 08:28:29 +00:00
|
|
|
|
|
|
|
if (!popover || popover != menu->open_submenu)
|
|
|
|
gtk_widget_grab_focus (menu->active_item);
|
|
|
|
|
|
|
|
g_clear_object (&popover);
|
2019-06-13 00:13:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-19 08:26:25 +00:00
|
|
|
static void
|
|
|
|
visible_submenu_changed (GObject *object,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GtkPopoverMenu *popover)
|
|
|
|
{
|
|
|
|
g_object_notify (G_OBJECT (popover), "visible-submenu");
|
|
|
|
}
|
|
|
|
|
2019-06-09 14:08:18 +00:00
|
|
|
static void
|
2020-02-20 01:51:03 +00:00
|
|
|
focus_out (GtkEventController *controller,
|
|
|
|
GtkPopoverMenu *menu)
|
2019-06-09 14:08:18 +00:00
|
|
|
{
|
2019-10-06 10:50:22 +00:00
|
|
|
GtkWidget *new_focus = gtk_root_get_focus (gtk_widget_get_root (GTK_WIDGET (menu)));
|
|
|
|
|
2020-02-20 01:51:03 +00:00
|
|
|
if (!gtk_event_controller_focus_contains_focus (GTK_EVENT_CONTROLLER_FOCUS (controller)) &&
|
2019-10-06 10:50:22 +00:00
|
|
|
new_focus != NULL)
|
2019-08-27 08:28:29 +00:00
|
|
|
{
|
|
|
|
if (menu->parent_menu &&
|
2019-10-03 20:13:54 +00:00
|
|
|
GTK_POPOVER_MENU (menu->parent_menu)->open_submenu == (GtkWidget*) menu)
|
2019-08-27 08:28:29 +00:00
|
|
|
GTK_POPOVER_MENU (menu->parent_menu)->open_submenu = NULL;
|
|
|
|
gtk_popover_popdown (GTK_POPOVER (menu));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-20 03:04:28 +00:00
|
|
|
leave_cb (GtkEventController *controller,
|
|
|
|
GdkCrossingMode mode,
|
|
|
|
gpointer data)
|
2019-08-27 08:28:29 +00:00
|
|
|
{
|
|
|
|
GtkWidget *target;
|
|
|
|
|
2020-02-20 03:04:28 +00:00
|
|
|
target = gtk_event_controller_get_widget (controller);
|
2019-08-27 08:28:29 +00:00
|
|
|
|
2020-02-20 03:04:28 +00:00
|
|
|
gtk_popover_menu_set_active_item (GTK_POPOVER_MENU (target), NULL);
|
2019-06-09 14:08:18 +00:00
|
|
|
}
|
|
|
|
|
2014-10-24 03:38:09 +00:00
|
|
|
static void
|
2014-10-26 22:58:55 +00:00
|
|
|
gtk_popover_menu_init (GtkPopoverMenu *popover)
|
2014-10-24 03:38:09 +00:00
|
|
|
{
|
|
|
|
GtkWidget *stack;
|
2019-06-09 14:08:18 +00:00
|
|
|
GtkEventController *controller;
|
2014-10-24 03:38:09 +00:00
|
|
|
|
|
|
|
stack = gtk_stack_new ();
|
|
|
|
gtk_stack_set_vhomogeneous (GTK_STACK (stack), FALSE);
|
|
|
|
gtk_stack_set_transition_type (GTK_STACK (stack), GTK_STACK_TRANSITION_TYPE_SLIDE_LEFT_RIGHT);
|
2015-07-19 15:40:28 +00:00
|
|
|
gtk_stack_set_interpolate_size (GTK_STACK (stack), TRUE);
|
2014-10-24 03:38:09 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (popover), stack);
|
2014-11-19 08:26:25 +00:00
|
|
|
g_signal_connect (stack, "notify::visible-child-name",
|
|
|
|
G_CALLBACK (visible_submenu_changed), popover);
|
2015-10-30 14:08:18 +00:00
|
|
|
|
2020-02-06 16:32:26 +00:00
|
|
|
gtk_widget_add_css_class (GTK_WIDGET (popover), "menu");
|
2019-06-09 14:08:18 +00:00
|
|
|
|
2020-02-20 01:51:03 +00:00
|
|
|
controller = gtk_event_controller_focus_new ();
|
|
|
|
g_signal_connect (controller, "leave", G_CALLBACK (focus_out), popover);
|
2019-06-09 14:08:18 +00:00
|
|
|
gtk_widget_add_controller (GTK_WIDGET (popover), controller);
|
2019-08-27 08:28:29 +00:00
|
|
|
|
|
|
|
controller = gtk_event_controller_motion_new ();
|
2020-02-20 03:04:28 +00:00
|
|
|
g_signal_connect (controller, "leave", G_CALLBACK (leave_cb), popover);
|
2019-08-27 08:28:29 +00:00
|
|
|
gtk_widget_add_controller (GTK_WIDGET (popover), controller);
|
2014-10-24 03:38:09 +00:00
|
|
|
}
|
|
|
|
|
2019-11-11 10:58:43 +00:00
|
|
|
static void
|
|
|
|
gtk_popover_menu_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
GtkPopoverMenu *popover = GTK_POPOVER_MENU (object);
|
|
|
|
|
2019-12-27 06:31:25 +00:00
|
|
|
if (popover->active_item)
|
|
|
|
{
|
|
|
|
g_object_remove_weak_pointer (G_OBJECT (popover->active_item), (gpointer *)&popover->active_item);
|
|
|
|
popover->active_item = NULL;
|
|
|
|
}
|
|
|
|
|
2019-11-11 10:58:43 +00:00
|
|
|
g_clear_object (&popover->model);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_popover_menu_parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
2014-10-24 03:38:09 +00:00
|
|
|
static void
|
|
|
|
gtk_popover_menu_map (GtkWidget *widget)
|
|
|
|
{
|
2014-10-26 23:14:01 +00:00
|
|
|
gtk_popover_menu_open_submenu (GTK_POPOVER_MENU (widget), "main");
|
2019-10-06 10:52:11 +00:00
|
|
|
GTK_WIDGET_CLASS (gtk_popover_menu_parent_class)->map (widget);
|
2014-10-24 03:38:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_popover_menu_unmap (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GTK_WIDGET_CLASS (gtk_popover_menu_parent_class)->unmap (widget);
|
2019-10-06 10:13:42 +00:00
|
|
|
gtk_popover_menu_open_submenu (GTK_POPOVER_MENU (widget), "main");
|
2014-10-24 03:38:09 +00:00
|
|
|
}
|
|
|
|
|
2014-11-18 12:39:15 +00:00
|
|
|
static void
|
|
|
|
gtk_popover_menu_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkWidget *stack;
|
|
|
|
|
|
|
|
stack = gtk_bin_get_child (GTK_BIN (object));
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_VISIBLE_SUBMENU:
|
|
|
|
g_value_set_string (value, gtk_stack_get_visible_child_name (GTK_STACK (stack)));
|
|
|
|
break;
|
|
|
|
|
2019-11-11 10:58:43 +00:00
|
|
|
case PROP_MENU_MODEL:
|
|
|
|
g_value_set_object (value, gtk_popover_menu_get_menu_model (GTK_POPOVER_MENU (object)));
|
|
|
|
break;
|
|
|
|
|
2014-11-18 12:39:15 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_popover_menu_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkWidget *stack;
|
|
|
|
|
|
|
|
stack = gtk_bin_get_child (GTK_BIN (object));
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_VISIBLE_SUBMENU:
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (stack), g_value_get_string (value));
|
|
|
|
break;
|
|
|
|
|
2019-11-11 10:58:43 +00:00
|
|
|
case PROP_MENU_MODEL:
|
|
|
|
gtk_popover_menu_set_menu_model (GTK_POPOVER_MENU (object), g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
|
2014-11-18 12:39:15 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-09 02:25:12 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_popover_menu_focus (GtkWidget *widget,
|
|
|
|
GtkDirectionType direction)
|
|
|
|
{
|
|
|
|
if (gtk_widget_get_first_child (widget) == NULL)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-08-27 08:28:29 +00:00
|
|
|
if (GTK_POPOVER_MENU (widget)->open_submenu)
|
|
|
|
{
|
2019-12-28 03:52:08 +00:00
|
|
|
g_print ("open submenu\n");
|
2019-08-27 08:28:29 +00:00
|
|
|
if (gtk_widget_child_focus (GTK_POPOVER_MENU (widget)->open_submenu, direction))
|
|
|
|
return TRUE;
|
|
|
|
if (direction == GTK_DIR_LEFT)
|
|
|
|
{
|
|
|
|
gtk_widget_grab_focus (GTK_POPOVER_MENU (widget)->active_item);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-06-09 02:25:12 +00:00
|
|
|
if (gtk_widget_focus_move (widget, direction))
|
|
|
|
return TRUE;
|
|
|
|
|
2019-08-27 08:28:29 +00:00
|
|
|
if (direction == GTK_DIR_LEFT || direction == GTK_DIR_RIGHT)
|
|
|
|
{
|
|
|
|
/* If we are part of a menubar, we want to let the
|
|
|
|
* menubar use left/right arrows for cycling, else
|
|
|
|
* we eat them.
|
|
|
|
*/
|
|
|
|
if (gtk_widget_get_ancestor (widget, GTK_TYPE_POPOVER_MENU_BAR) ||
|
|
|
|
(gtk_popover_menu_get_parent_menu (GTK_POPOVER_MENU (widget)) &&
|
|
|
|
direction == GTK_DIR_LEFT))
|
|
|
|
return FALSE;
|
|
|
|
else
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else if (direction == GTK_DIR_UP || direction == GTK_DIR_DOWN)
|
2019-06-09 02:25:12 +00:00
|
|
|
{
|
|
|
|
GtkWidget *p;
|
|
|
|
|
|
|
|
/* cycle around */
|
|
|
|
for (p = gtk_window_get_focus (GTK_WINDOW (gtk_widget_get_root (widget)));
|
|
|
|
p != widget;
|
|
|
|
p = gtk_widget_get_parent (p))
|
|
|
|
{
|
|
|
|
gtk_widget_set_focus_child (p, NULL);
|
|
|
|
}
|
|
|
|
if (gtk_widget_focus_move (widget, direction))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-06-12 16:35:36 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
add_tab_bindings (GtkBindingSet *binding_set,
|
|
|
|
GdkModifierType modifiers,
|
|
|
|
GtkDirectionType direction)
|
|
|
|
{
|
|
|
|
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Tab, modifiers,
|
|
|
|
"move-focus", 1,
|
|
|
|
GTK_TYPE_DIRECTION_TYPE, direction);
|
|
|
|
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Tab, modifiers,
|
|
|
|
"move-focus", 1,
|
|
|
|
GTK_TYPE_DIRECTION_TYPE, direction);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_arrow_bindings (GtkBindingSet *binding_set,
|
|
|
|
guint keysym,
|
|
|
|
GtkDirectionType direction)
|
|
|
|
{
|
|
|
|
guint keypad_keysym = keysym - GDK_KEY_Left + GDK_KEY_KP_Left;
|
|
|
|
|
|
|
|
gtk_binding_entry_add_signal (binding_set, keysym, 0,
|
|
|
|
"move-focus", 1,
|
|
|
|
GTK_TYPE_DIRECTION_TYPE, direction);
|
|
|
|
gtk_binding_entry_add_signal (binding_set, keysym, GDK_CONTROL_MASK,
|
|
|
|
"move-focus", 1,
|
|
|
|
GTK_TYPE_DIRECTION_TYPE, direction);
|
|
|
|
gtk_binding_entry_add_signal (binding_set, keypad_keysym, 0,
|
|
|
|
"move-focus", 1,
|
|
|
|
GTK_TYPE_DIRECTION_TYPE, direction);
|
|
|
|
gtk_binding_entry_add_signal (binding_set, keypad_keysym, GDK_CONTROL_MASK,
|
|
|
|
"move-focus", 1,
|
|
|
|
GTK_TYPE_DIRECTION_TYPE, direction);
|
|
|
|
}
|
|
|
|
|
2019-12-28 03:52:08 +00:00
|
|
|
static void
|
|
|
|
gtk_popover_menu_show (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
gtk_popover_menu_set_open_submenu (GTK_POPOVER_MENU (widget), NULL);
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_popover_menu_parent_class)->show (widget);
|
|
|
|
}
|
|
|
|
|
2014-10-24 03:38:09 +00:00
|
|
|
static void
|
|
|
|
gtk_popover_menu_class_init (GtkPopoverMenuClass *klass)
|
|
|
|
{
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
2014-11-18 12:39:15 +00:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2019-06-12 16:35:36 +00:00
|
|
|
GtkBindingSet *binding_set;
|
2014-11-18 12:39:15 +00:00
|
|
|
|
2019-11-11 10:58:43 +00:00
|
|
|
object_class->dispose = gtk_popover_menu_dispose;
|
2014-11-18 12:39:15 +00:00
|
|
|
object_class->set_property = gtk_popover_menu_set_property;
|
|
|
|
object_class->get_property = gtk_popover_menu_get_property;
|
2014-10-24 03:38:09 +00:00
|
|
|
|
|
|
|
widget_class->map = gtk_popover_menu_map;
|
|
|
|
widget_class->unmap = gtk_popover_menu_unmap;
|
2019-06-09 02:25:12 +00:00
|
|
|
widget_class->focus = gtk_popover_menu_focus;
|
2019-12-28 03:52:08 +00:00
|
|
|
widget_class->show = gtk_popover_menu_show;
|
2014-10-24 03:38:09 +00:00
|
|
|
|
2014-11-18 12:39:15 +00:00
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_VISIBLE_SUBMENU,
|
|
|
|
g_param_spec_string ("visible-submenu",
|
|
|
|
P_("Visible submenu"),
|
|
|
|
P_("The name of the visible submenu"),
|
|
|
|
NULL,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2019-06-12 16:35:36 +00:00
|
|
|
|
2019-11-11 10:58:43 +00:00
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_MENU_MODEL,
|
|
|
|
g_param_spec_object ("menu-model",
|
|
|
|
P_("Menu model"),
|
|
|
|
P_("The model from which the menu is made."),
|
|
|
|
G_TYPE_MENU_MODEL,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2019-06-12 16:35:36 +00:00
|
|
|
binding_set = gtk_binding_set_by_class (klass);
|
|
|
|
|
|
|
|
add_arrow_bindings (binding_set, GDK_KEY_Up, GTK_DIR_UP);
|
|
|
|
add_arrow_bindings (binding_set, GDK_KEY_Down, GTK_DIR_DOWN);
|
|
|
|
add_arrow_bindings (binding_set, GDK_KEY_Left, GTK_DIR_LEFT);
|
|
|
|
add_arrow_bindings (binding_set, GDK_KEY_Right, GTK_DIR_RIGHT);
|
|
|
|
|
|
|
|
add_tab_bindings (binding_set, 0, GTK_DIR_TAB_FORWARD);
|
|
|
|
add_tab_bindings (binding_set, GDK_CONTROL_MASK, GTK_DIR_TAB_FORWARD);
|
|
|
|
add_tab_bindings (binding_set, GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
|
|
|
|
add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
|
2019-06-12 16:55:43 +00:00
|
|
|
|
|
|
|
gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0,
|
|
|
|
"activate-default", 0);
|
|
|
|
gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0,
|
|
|
|
"activate-default", 0);
|
|
|
|
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0,
|
|
|
|
"activate-default", 0);
|
|
|
|
gtk_binding_entry_add_signal (binding_set, GDK_KEY_space, 0,
|
|
|
|
"activate-default", 0);
|
|
|
|
gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Space, 0,
|
|
|
|
"activate-default", 0);
|
2014-10-24 03:38:09 +00:00
|
|
|
}
|
|
|
|
|
2014-10-26 23:04:28 +00:00
|
|
|
/**
|
|
|
|
* gtk_popover_menu_new:
|
|
|
|
*
|
|
|
|
* Creates a new popover menu.
|
|
|
|
*
|
|
|
|
* Returns: a new #GtkPopoverMenu
|
|
|
|
*/
|
2014-10-24 03:38:09 +00:00
|
|
|
GtkWidget *
|
2020-02-24 12:21:46 +00:00
|
|
|
gtk_popover_menu_new (void)
|
2014-10-24 03:38:09 +00:00
|
|
|
{
|
2019-06-07 17:05:48 +00:00
|
|
|
GtkWidget *popover;
|
|
|
|
|
2019-06-10 23:33:36 +00:00
|
|
|
popover = g_object_new (GTK_TYPE_POPOVER_MENU,
|
|
|
|
"autohide", TRUE,
|
|
|
|
NULL);
|
2019-06-07 17:05:48 +00:00
|
|
|
|
|
|
|
return popover;
|
2014-10-24 03:38:09 +00:00
|
|
|
}
|
2014-10-26 23:14:01 +00:00
|
|
|
|
2019-12-30 00:44:31 +00:00
|
|
|
/*<private>
|
2014-10-26 23:14:01 +00:00
|
|
|
* gtk_popover_menu_open_submenu:
|
|
|
|
* @popover: a #GtkPopoverMenu
|
|
|
|
* @name: the name of the menu to switch to
|
|
|
|
*
|
|
|
|
* Opens a submenu of the @popover. The @name
|
|
|
|
* must be one of the names given to the submenus
|
|
|
|
* of @popover with #GtkPopoverMenu:submenu, or
|
|
|
|
* "main" to switch back to the main menu.
|
|
|
|
*
|
|
|
|
* #GtkModelButton will open submenus automatically
|
|
|
|
* when the #GtkModelButton:menu-name property is set,
|
|
|
|
* so this function is only needed when you are using
|
|
|
|
* other kinds of widgets to initiate menu changes.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_popover_menu_open_submenu (GtkPopoverMenu *popover,
|
|
|
|
const gchar *name)
|
|
|
|
{
|
|
|
|
GtkWidget *stack;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_POPOVER_MENU (popover));
|
|
|
|
|
|
|
|
stack = gtk_bin_get_child (GTK_BIN (popover));
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (stack), name);
|
|
|
|
}
|
2019-03-27 21:52:51 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
gtk_popover_menu_add_submenu (GtkPopoverMenu *popover,
|
|
|
|
GtkWidget *submenu,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
GtkWidget *stack;
|
|
|
|
|
2019-03-27 22:37:57 +00:00
|
|
|
stack = gtk_bin_get_child (GTK_BIN (popover));
|
2019-03-27 21:52:51 +00:00
|
|
|
gtk_stack_add_named (GTK_STACK (stack), submenu, name);
|
2019-06-07 17:05:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_popover_menu_new_from_model:
|
2019-11-11 10:58:43 +00:00
|
|
|
* @model: (allow-none): a #GMenuModel, or %NULL
|
2019-06-07 17:05:48 +00:00
|
|
|
*
|
|
|
|
* Creates a #GtkPopoverMenu and populates it according to
|
2020-02-24 12:21:46 +00:00
|
|
|
* @model.
|
2019-06-07 17:05:48 +00:00
|
|
|
*
|
|
|
|
* The created buttons are connected to actions found in the
|
|
|
|
* #GtkApplicationWindow to which the popover belongs - typically
|
|
|
|
* by means of being attached to a widget that is contained within
|
|
|
|
* the #GtkApplicationWindows widget hierarchy.
|
|
|
|
*
|
|
|
|
* Actions can also be added using gtk_widget_insert_action_group()
|
|
|
|
* on the menus attach widget or on any of its parent widgets.
|
|
|
|
*
|
2019-08-27 08:28:29 +00:00
|
|
|
* This function creates menus with sliding submenus.
|
|
|
|
* See gtk_popover_menu_new_from_model_full() for a way
|
|
|
|
* to control this.
|
|
|
|
*
|
2019-06-07 17:05:48 +00:00
|
|
|
* Returns: the new #GtkPopoverMenu
|
|
|
|
*/
|
|
|
|
GtkWidget *
|
2020-02-24 12:21:46 +00:00
|
|
|
gtk_popover_menu_new_from_model (GMenuModel *model)
|
2019-08-27 08:28:29 +00:00
|
|
|
|
|
|
|
{
|
2020-02-24 12:21:46 +00:00
|
|
|
return gtk_popover_menu_new_from_model_full (model, 0);
|
2019-08-27 08:28:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_popover_menu_new_from_model_full:
|
|
|
|
* @model: a #GMenuModel
|
|
|
|
* @flags: flags that affect how the menu is created
|
|
|
|
*
|
|
|
|
* Creates a #GtkPopoverMenu and populates it according to
|
2020-02-24 12:21:46 +00:00
|
|
|
* @model.
|
2019-08-27 08:28:29 +00:00
|
|
|
*
|
|
|
|
* The created buttons are connected to actions found in the
|
2020-02-24 12:21:46 +00:00
|
|
|
* action groups that are accessible from the parent widget.
|
2019-12-30 00:44:31 +00:00
|
|
|
* This includes the #GtkApplicationWindow to which the popover
|
|
|
|
* belongs. Actions can also be added using gtk_widget_insert_action_group()
|
2020-02-24 12:21:46 +00:00
|
|
|
* on the parent widget or on any of its parent widgets.
|
2019-08-27 08:28:29 +00:00
|
|
|
*
|
|
|
|
* The only flag that is supported currently is
|
|
|
|
* #GTK_POPOVER_MENU_NESTED, which makes GTK create traditional,
|
|
|
|
* nested submenus instead of the default sliding submenus.
|
|
|
|
*
|
2019-11-11 10:58:43 +00:00
|
|
|
* Returns: (transfer full): the new #GtkPopoverMenu
|
2019-08-27 08:28:29 +00:00
|
|
|
*/
|
|
|
|
GtkWidget *
|
2020-02-24 12:21:46 +00:00
|
|
|
gtk_popover_menu_new_from_model_full (GMenuModel *model,
|
2019-08-27 08:28:29 +00:00
|
|
|
GtkPopoverMenuFlags flags)
|
2019-06-07 17:05:48 +00:00
|
|
|
{
|
|
|
|
GtkWidget *popover;
|
|
|
|
|
2019-11-11 10:58:43 +00:00
|
|
|
g_return_val_if_fail (model == NULL || G_IS_MENU_MODEL (model), NULL);
|
2019-06-07 17:05:48 +00:00
|
|
|
|
2020-02-24 12:21:46 +00:00
|
|
|
popover = gtk_popover_menu_new ();
|
2019-11-11 10:58:43 +00:00
|
|
|
GTK_POPOVER_MENU (popover)->flags = flags;
|
|
|
|
gtk_popover_menu_set_menu_model (GTK_POPOVER_MENU (popover), model);
|
2019-06-07 17:05:48 +00:00
|
|
|
|
|
|
|
return popover;
|
|
|
|
}
|
2019-08-27 08:28:29 +00:00
|
|
|
|
2019-12-30 00:44:31 +00:00
|
|
|
/**
|
|
|
|
* gtk_popover_menu_set_model:
|
|
|
|
* @popover: a #GtkPopoverMenu
|
|
|
|
* @model: (nullable): a #GtkMenuModel, or %NULL
|
|
|
|
*
|
|
|
|
* Sets a new menu model on @popover.
|
|
|
|
*
|
|
|
|
* The existing contents of @popover are removed, and
|
|
|
|
* the @popover is populated with new contents according
|
|
|
|
* to @model.
|
|
|
|
*/
|
2019-11-11 10:58:43 +00:00
|
|
|
void
|
|
|
|
gtk_popover_menu_set_menu_model (GtkPopoverMenu *popover,
|
|
|
|
GMenuModel *model)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_POPOVER_MENU (popover));
|
|
|
|
g_return_if_fail (model == NULL || G_IS_MENU_MODEL (model));
|
|
|
|
|
|
|
|
if (g_set_object (&popover->model, model))
|
|
|
|
{
|
|
|
|
GtkWidget *stack;
|
|
|
|
GtkWidget *child;
|
|
|
|
|
|
|
|
stack = gtk_bin_get_child (GTK_BIN (popover));
|
|
|
|
while ((child = gtk_widget_get_first_child (stack)))
|
2020-02-20 17:05:00 +00:00
|
|
|
gtk_container_remove (GTK_CONTAINER (stack), child);
|
2019-11-11 10:58:43 +00:00
|
|
|
|
|
|
|
if (model)
|
|
|
|
gtk_menu_section_box_new_toplevel (popover, model, popover->flags);
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (popover), "menu-model");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-30 00:44:31 +00:00
|
|
|
/**
|
|
|
|
* gtk_popover_menu_get_menu_model:
|
|
|
|
* @popover: a #GtkPopoverMenu
|
|
|
|
*
|
|
|
|
* Returns the menu model used to populate the popover.
|
|
|
|
*
|
2020-01-12 23:14:08 +00:00
|
|
|
* Returns: (transfer none): the menu model of @popover
|
2019-12-30 00:44:31 +00:00
|
|
|
*/
|
2019-11-11 10:58:43 +00:00
|
|
|
GMenuModel *
|
|
|
|
gtk_popover_menu_get_menu_model (GtkPopoverMenu *popover)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_POPOVER_MENU (popover), NULL);
|
|
|
|
|
|
|
|
return popover->model;
|
|
|
|
}
|