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"
|
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"
|
2019-11-11 10:58:43 +00:00
|
|
|
#include "gtkmodelbuttonprivate.h"
|
2019-08-27 08:28:29 +00:00
|
|
|
#include "gtkpopovermenubar.h"
|
2020-03-24 04:00:43 +00:00
|
|
|
#include "gtkshortcutmanager.h"
|
|
|
|
#include "gtkshortcutcontroller.h"
|
2020-10-26 17:21:28 +00:00
|
|
|
#include "gtkbuildable.h"
|
2021-07-02 17:19:02 +00:00
|
|
|
#include "gtkscrolledwindow.h"
|
|
|
|
#include "gtkviewport.h"
|
2014-10-24 03:38:09 +00:00
|
|
|
|
|
|
|
|
2014-10-26 23:04:28 +00:00
|
|
|
/**
|
2021-02-27 05:16:04 +00:00
|
|
|
* GtkPopoverMenu:
|
2014-10-26 23:04:28 +00:00
|
|
|
*
|
2021-02-27 05:16:04 +00:00
|
|
|
* `GtkPopoverMenu` is a subclass of `GtkPopover` that implements menu
|
|
|
|
* behavior.
|
2014-10-26 23:04:28 +00:00
|
|
|
*
|
2021-02-27 05:16:04 +00:00
|
|
|
* ![An example GtkPopoverMenu](menu.png)
|
|
|
|
*
|
|
|
|
* `GtkPopoverMenu` treats its children like menus and allows switching
|
|
|
|
* between them. It can open submenus as traditional, nested submenus,
|
|
|
|
* or in a more touch-friendly sliding fashion.
|
|
|
|
*
|
|
|
|
* `GtkPopoverMenu` is meant to be used primarily with menu models,
|
|
|
|
* using [ctor@Gtk.PopoverMenu.new_from_model]. If you need to put
|
|
|
|
* other widgets such as a `GtkSpinButton` or a `GtkSwitch` into a popover,
|
|
|
|
* you can use [method@Gtk.PopoverMenu.add_child].
|
|
|
|
*
|
|
|
|
* For more dialog-like behavior, use a plain `GtkPopover`.
|
2019-03-27 22:37:57 +00:00
|
|
|
*
|
2020-04-30 00:27:32 +00:00
|
|
|
* ## Menu models
|
2014-10-26 23:04:28 +00:00
|
|
|
*
|
2021-02-27 05:16:04 +00:00
|
|
|
* The XML format understood by `GtkBuilder` for `GMenuModel` consists
|
2020-04-30 00:27:32 +00:00
|
|
|
* of a toplevel `<menu>` element, which contains one or more `<item>`
|
|
|
|
* elements. Each `<item>` element contains `<attribute>` and `<link>`
|
|
|
|
* elements with a mandatory name attribute. `<link>` elements have the
|
2021-06-05 21:19:39 +00:00
|
|
|
* same content model as `<menu>`. Instead of `<link name="submenu">`
|
|
|
|
* or `<link name="section">`, you can use `<submenu>` or `<section>`
|
2020-04-30 00:27:32 +00:00
|
|
|
* elements.
|
|
|
|
*
|
2021-02-27 05:16:04 +00:00
|
|
|
* ```xml
|
2020-04-30 00:27:32 +00:00
|
|
|
* <menu id='app-menu'>
|
|
|
|
* <section>
|
|
|
|
* <item>
|
|
|
|
* <attribute name='label' translatable='yes'>_New Window</attribute>
|
|
|
|
* <attribute name='action'>app.new</attribute>
|
|
|
|
* </item>
|
|
|
|
* <item>
|
|
|
|
* <attribute name='label' translatable='yes'>_About Sunny</attribute>
|
|
|
|
* <attribute name='action'>app.about</attribute>
|
|
|
|
* </item>
|
|
|
|
* <item>
|
|
|
|
* <attribute name='label' translatable='yes'>_Quit</attribute>
|
|
|
|
* <attribute name='action'>app.quit</attribute>
|
|
|
|
* </item>
|
|
|
|
* </section>
|
|
|
|
* </menu>
|
2021-02-27 05:16:04 +00:00
|
|
|
* ```
|
2020-04-30 00:27:32 +00:00
|
|
|
*
|
2021-02-27 05:16:04 +00:00
|
|
|
* Attribute values can be translated using gettext, like other `GtkBuilder`
|
2020-04-30 00:27:32 +00:00
|
|
|
* content. `<attribute>` elements can be marked for translation with a
|
|
|
|
* `translatable="yes"` attribute. It is also possible to specify message
|
|
|
|
* context and translator comments, using the context and comments attributes.
|
2021-05-20 13:17:04 +00:00
|
|
|
* To make use of this, the `GtkBuilder` must have been given the gettext
|
2020-04-30 00:27:32 +00:00
|
|
|
* domain to use.
|
|
|
|
*
|
|
|
|
* The following attributes are used when constructing menu items:
|
2021-02-27 05:16:04 +00:00
|
|
|
*
|
2020-04-30 00:27:32 +00:00
|
|
|
* - "label": a user-visible string to display
|
2021-10-07 09:32:31 +00:00
|
|
|
* - "use-markup": whether the text in the menu item includes [Pango markup](https://docs.gtk.org/Pango/pango_markup.html)
|
2020-04-30 00:27:32 +00:00
|
|
|
* - "action": the prefixed name of the action to trigger
|
|
|
|
* - "target": the parameter to use when activating the action
|
|
|
|
* - "icon" and "verb-icon": names of icons that may be displayed
|
2021-06-05 21:19:39 +00:00
|
|
|
* - "submenu-action": name of an action that may be used to track
|
|
|
|
* whether a submenu is open
|
2020-04-30 00:27:32 +00:00
|
|
|
* - "hidden-when": a string used to determine when the item will be hidden.
|
|
|
|
* Possible values include "action-disabled", "action-missing", "macos-menubar".
|
2021-02-27 05:16:04 +00:00
|
|
|
* This is mainly useful for exported menus, see [method@Gtk.Application.set_menubar].
|
|
|
|
* - "custom": a string used to match against the ID of a custom child added with
|
|
|
|
* [method@Gtk.PopoverMenu.add_child], [method@Gtk.PopoverMenuBar.add_child],
|
|
|
|
* or in the ui file with `<child type="ID">`.
|
2020-04-30 00:27:32 +00:00
|
|
|
*
|
|
|
|
* The following attributes are used when constructing sections:
|
2021-02-27 05:16:04 +00:00
|
|
|
*
|
2020-04-30 00:27:32 +00:00
|
|
|
* - "label": a user-visible string to use as section heading
|
|
|
|
* - "display-hint": a string used to determine special formatting for the section.
|
2021-02-27 05:16:04 +00:00
|
|
|
* Possible values include "horizontal-buttons", "circular-buttons" and
|
|
|
|
* "inline-buttons". They all indicate that section should be
|
2020-04-30 00:27:32 +00:00
|
|
|
* displayed as a horizontal row of buttons.
|
2021-02-27 05:16:04 +00:00
|
|
|
* - "text-direction": a string used to determine the `GtkTextDirection` to use
|
2020-04-30 00:27:32 +00:00
|
|
|
* when "display-hint" is set to "horizontal-buttons". Possible values
|
|
|
|
* include "rtl", "ltr", and "none".
|
|
|
|
*
|
|
|
|
* The following attributes are used when constructing submenus:
|
2021-02-27 05:16:04 +00:00
|
|
|
*
|
2020-04-30 00:27:32 +00:00
|
|
|
* - "label": a user-visible string to display
|
|
|
|
* - "icon": icon name to display
|
|
|
|
*
|
|
|
|
* Menu items will also show accelerators, which are usually associated
|
2021-02-27 05:16:04 +00:00
|
|
|
* with actions via [method@Gtk.Application.set_accels_for_action],
|
|
|
|
* [id@gtk_widget_class_add_binding_action] or
|
|
|
|
* [method@Gtk.ShortcutController.add_shortcut].
|
2015-10-30 14:08:18 +00:00
|
|
|
*
|
2017-07-08 10:04:44 +00:00
|
|
|
* # CSS Nodes
|
|
|
|
*
|
2021-02-27 05:16:04 +00:00
|
|
|
* `GtkPopoverMenu` is just a subclass of `GtkPopover` that adds custom content
|
|
|
|
* to it, therefore it has the same CSS nodes. It is one of the cases that add
|
|
|
|
* a .menu style class to the popover's main node.
|
2020-10-21 20:30:04 +00:00
|
|
|
*
|
|
|
|
* # Accessibility
|
|
|
|
*
|
2021-02-27 05:16:04 +00:00
|
|
|
* `GtkPopoverMenu` uses the %GTK_ACCESSIBLE_ROLE_MENU role, and its
|
|
|
|
* items use the %GTK_ACCESSIBLE_ROLE_MENU_ITEM,
|
|
|
|
* %GTK_ACCESSIBLE_ROLE_MENU_ITEM_CHECKBOX or
|
|
|
|
* %GTK_ACCESSIBLE_ROLE_MENU_ITEM_RADIO roles, depending on the
|
2020-10-21 20:30:04 +00:00
|
|
|
* action they are connected to.
|
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
|
|
|
};
|
|
|
|
|
2020-10-26 17:21:28 +00:00
|
|
|
static void gtk_popover_menu_buildable_iface_init (GtkBuildableIface *iface);
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkPopoverMenu, gtk_popover_menu, GTK_TYPE_POPOVER,
|
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
|
|
|
|
gtk_popover_menu_buildable_iface_init))
|
2014-10-24 03:38:09 +00:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-11-17 02:27:15 +00:00
|
|
|
void
|
|
|
|
gtk_popover_menu_close_submenus (GtkPopoverMenu *menu)
|
|
|
|
{
|
|
|
|
GtkWidget *submenu;
|
|
|
|
|
|
|
|
submenu = menu->open_submenu;
|
|
|
|
if (submenu)
|
|
|
|
{
|
|
|
|
gtk_popover_menu_close_submenus (GTK_POPOVER_MENU (submenu));
|
|
|
|
gtk_widget_hide (submenu);
|
|
|
|
gtk_popover_menu_set_open_submenu (menu, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-27 08:28:29 +00:00
|
|
|
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
|
|
|
{
|
2020-08-02 17:09:00 +00:00
|
|
|
GtkRoot *root;
|
|
|
|
GtkWidget *new_focus;
|
|
|
|
|
|
|
|
root = gtk_widget_get_root (GTK_WIDGET (menu));
|
|
|
|
if (!root)
|
|
|
|
return;
|
|
|
|
|
|
|
|
new_focus = gtk_root_get_focus (root);
|
2019-10-06 10:50:22 +00:00
|
|
|
|
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-11-29 07:41:44 +00:00
|
|
|
leave_cb (GtkEventController *controller,
|
|
|
|
gpointer data)
|
2019-08-27 08:28:29 +00:00
|
|
|
{
|
2020-05-24 15:47:53 +00:00
|
|
|
if (!gtk_event_controller_motion_contains_pointer (GTK_EVENT_CONTROLLER_MOTION (controller)))
|
2020-11-29 07:41:44 +00:00
|
|
|
{
|
|
|
|
GtkWidget *target = gtk_event_controller_get_widget (controller);
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2021-07-02 17:19:02 +00:00
|
|
|
GtkWidget *sw;
|
2014-10-24 03:38:09 +00:00
|
|
|
GtkWidget *stack;
|
2019-06-09 14:08:18 +00:00
|
|
|
GtkEventController *controller;
|
2020-03-28 19:37:29 +00:00
|
|
|
GtkEventController **controllers;
|
|
|
|
guint n_controllers, i;
|
2014-10-24 03:38:09 +00:00
|
|
|
|
2021-07-02 17:19:02 +00:00
|
|
|
sw = gtk_scrolled_window_new ();
|
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
|
|
|
|
gtk_scrolled_window_set_propagate_natural_width (GTK_SCROLLED_WINDOW (sw), TRUE);
|
|
|
|
gtk_scrolled_window_set_propagate_natural_height (GTK_SCROLLED_WINDOW (sw), TRUE);
|
|
|
|
gtk_popover_set_child (GTK_POPOVER (popover), sw);
|
|
|
|
|
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);
|
2021-07-02 17:19:02 +00:00
|
|
|
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), 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-11-29 08:42:18 +00:00
|
|
|
g_signal_connect (controller, "notify::contains-pointer", G_CALLBACK (leave_cb), popover);
|
2019-08-27 08:28:29 +00:00
|
|
|
gtk_widget_add_controller (GTK_WIDGET (popover), controller);
|
2020-03-24 04:00:43 +00:00
|
|
|
|
2020-03-28 19:37:29 +00:00
|
|
|
controllers = gtk_widget_list_controllers (GTK_WIDGET (popover), GTK_PHASE_CAPTURE, &n_controllers);
|
|
|
|
for (i = 0; i < n_controllers; i ++)
|
2020-03-24 04:00:43 +00:00
|
|
|
{
|
2020-03-28 19:37:29 +00:00
|
|
|
controller = controllers[i];
|
2020-03-24 04:00:43 +00:00
|
|
|
if (GTK_IS_SHORTCUT_CONTROLLER (controller) &&
|
|
|
|
strcmp (gtk_event_controller_get_name (controller), "gtk-shortcut-manager-capture") == 0)
|
|
|
|
gtk_shortcut_controller_set_mnemonics_modifiers (GTK_SHORTCUT_CONTROLLER (controller), 0);
|
|
|
|
}
|
2020-03-28 19:37:29 +00:00
|
|
|
g_free (controllers);
|
2020-03-24 16:45:12 +00:00
|
|
|
|
|
|
|
gtk_popover_disable_auto_mnemonics (GTK_POPOVER (popover));
|
2020-11-03 15:23:34 +00:00
|
|
|
gtk_popover_set_cascade_popdown (GTK_POPOVER (popover), TRUE);
|
2014-10-24 03:38:09 +00:00
|
|
|
}
|
|
|
|
|
2021-07-02 17:19:02 +00:00
|
|
|
GtkWidget *
|
|
|
|
gtk_popover_menu_get_stack (GtkPopoverMenu *menu)
|
|
|
|
{
|
|
|
|
GtkWidget *sw = gtk_popover_get_child (GTK_POPOVER (menu));
|
|
|
|
GtkWidget *vp = gtk_scrolled_window_get_child (GTK_SCROLLED_WINDOW (sw));
|
|
|
|
GtkWidget *stack = gtk_viewport_get_child (GTK_VIEWPORT (vp));
|
|
|
|
|
|
|
|
return stack;
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2021-07-02 17:19:02 +00:00
|
|
|
GtkPopoverMenu *menu = GTK_POPOVER_MENU (object);
|
2014-11-18 12:39:15 +00:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_VISIBLE_SUBMENU:
|
2021-07-02 17:19:02 +00:00
|
|
|
g_value_set_string (value, gtk_stack_get_visible_child_name (GTK_STACK (gtk_popover_menu_get_stack (menu))));
|
2014-11-18 12:39:15 +00:00
|
|
|
break;
|
|
|
|
|
2019-11-11 10:58:43 +00:00
|
|
|
case PROP_MENU_MODEL:
|
2021-07-02 17:19:02 +00:00
|
|
|
g_value_set_object (value, gtk_popover_menu_get_menu_model (menu));
|
2019-11-11 10:58:43 +00:00
|
|
|
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)
|
|
|
|
{
|
2021-07-02 17:19:02 +00:00
|
|
|
GtkPopoverMenu *menu = GTK_POPOVER_MENU (object);
|
2014-11-18 12:39:15 +00:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_VISIBLE_SUBMENU:
|
2021-07-02 17:19:02 +00:00
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (gtk_popover_menu_get_stack (menu)), g_value_get_string (value));
|
2014-11-18 12:39:15 +00:00
|
|
|
break;
|
|
|
|
|
2019-11-11 10:58:43 +00:00
|
|
|
case PROP_MENU_MODEL:
|
2021-07-02 17:19:02 +00:00
|
|
|
gtk_popover_menu_set_menu_model (menu, g_value_get_object (value));
|
2019-11-11 10:58:43 +00:00
|
|
|
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)
|
|
|
|
{
|
2020-04-25 15:54:29 +00:00
|
|
|
GtkPopoverMenu *menu = GTK_POPOVER_MENU (widget);
|
|
|
|
|
2019-06-09 02:25:12 +00:00
|
|
|
if (gtk_widget_get_first_child (widget) == NULL)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-04-25 15:54:29 +00:00
|
|
|
if (menu->open_submenu)
|
2019-08-27 08:28:29 +00:00
|
|
|
{
|
2020-04-25 15:54:29 +00:00
|
|
|
if (gtk_widget_child_focus (menu->open_submenu, direction))
|
2019-08-27 08:28:29 +00:00
|
|
|
return TRUE;
|
|
|
|
if (direction == GTK_DIR_LEFT)
|
|
|
|
{
|
2020-04-25 16:14:04 +00:00
|
|
|
if (menu->open_submenu)
|
|
|
|
{
|
|
|
|
gtk_popover_popdown (GTK_POPOVER (menu->open_submenu));
|
|
|
|
menu->open_submenu = NULL;
|
|
|
|
}
|
|
|
|
|
2020-04-25 15:54:29 +00:00
|
|
|
gtk_widget_grab_focus (menu->active_item);
|
|
|
|
|
2019-08-27 08:28:29 +00:00
|
|
|
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) ||
|
2020-04-25 15:54:29 +00:00
|
|
|
(gtk_popover_menu_get_parent_menu (menu) &&
|
2019-08-27 08:28:29 +00:00
|
|
|
direction == GTK_DIR_LEFT))
|
|
|
|
return FALSE;
|
|
|
|
else
|
|
|
|
return TRUE;
|
|
|
|
}
|
2021-07-05 17:20:58 +00:00
|
|
|
/* Cycle around with up/down arrows and (Shift+)Tab when modal */
|
|
|
|
else if (gtk_popover_get_autohide (GTK_POPOVER (menu)))
|
2019-06-09 02:25:12 +00:00
|
|
|
{
|
2021-07-05 17:20:58 +00:00
|
|
|
GtkWidget *p = gtk_root_get_focus (gtk_widget_get_root (widget));
|
|
|
|
|
|
|
|
/* In the case where the popover doesn't have any focusable child, if
|
|
|
|
* the menu doesn't have any item for example, then the focus will end
|
|
|
|
* up out of the popover, hence creating an infinite loop below. To
|
|
|
|
* avoid this, just say we had focus and stop here.
|
|
|
|
*/
|
|
|
|
if (!gtk_widget_is_ancestor (p, widget) && p != widget)
|
|
|
|
return TRUE;
|
2019-06-09 02:25:12 +00:00
|
|
|
|
|
|
|
/* cycle around */
|
2021-07-05 17:20:58 +00:00
|
|
|
for (;
|
2019-06-09 02:25:12 +00:00
|
|
|
p != widget;
|
|
|
|
p = gtk_widget_get_parent (p))
|
|
|
|
{
|
|
|
|
gtk_widget_set_focus_child (p, NULL);
|
|
|
|
}
|
|
|
|
if (gtk_widget_focus_move (widget, direction))
|
|
|
|
return TRUE;
|
2021-07-05 17:20:58 +00:00
|
|
|
}
|
2019-06-09 02:25:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-06-12 16:35:36 +00:00
|
|
|
|
|
|
|
static void
|
2020-02-06 15:00:31 +00:00
|
|
|
add_tab_bindings (GtkWidgetClass *widget_class,
|
2019-06-12 16:35:36 +00:00
|
|
|
GdkModifierType modifiers,
|
|
|
|
GtkDirectionType direction)
|
|
|
|
{
|
2020-02-06 15:00:31 +00:00
|
|
|
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_Tab, modifiers,
|
|
|
|
"move-focus",
|
|
|
|
"(i)", direction);
|
|
|
|
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_KP_Tab, modifiers,
|
|
|
|
"move-focus",
|
|
|
|
"(i)", direction);
|
2019-06-12 16:35:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-06 15:00:31 +00:00
|
|
|
add_arrow_bindings (GtkWidgetClass *widget_class,
|
2019-06-12 16:35:36 +00:00
|
|
|
guint keysym,
|
|
|
|
GtkDirectionType direction)
|
|
|
|
{
|
|
|
|
guint keypad_keysym = keysym - GDK_KEY_Left + GDK_KEY_KP_Left;
|
|
|
|
|
2020-02-06 15:00:31 +00:00
|
|
|
gtk_widget_class_add_binding_signal (widget_class, keysym, 0,
|
|
|
|
"move-focus",
|
|
|
|
"(i)", direction);
|
|
|
|
gtk_widget_class_add_binding_signal (widget_class, keysym, GDK_CONTROL_MASK,
|
|
|
|
"move-focus",
|
|
|
|
"(i)", direction);
|
|
|
|
gtk_widget_class_add_binding_signal (widget_class, keypad_keysym, 0,
|
|
|
|
"move-focus",
|
|
|
|
"(i)", direction);
|
|
|
|
gtk_widget_class_add_binding_signal (widget_class, keypad_keysym, GDK_CONTROL_MASK,
|
|
|
|
"move-focus",
|
|
|
|
"(i)", direction);
|
2019-06-12 16:35:36 +00:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2020-03-24 16:45:12 +00:00
|
|
|
static void
|
|
|
|
gtk_popover_menu_move_focus (GtkWidget *widget,
|
|
|
|
GtkDirectionType direction)
|
|
|
|
{
|
|
|
|
gtk_popover_set_mnemonics_visible (GTK_POPOVER (widget), TRUE);
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_popover_menu_parent_class)->move_focus (widget, direction);
|
|
|
|
}
|
|
|
|
|
2020-10-21 20:30:04 +00:00
|
|
|
static void
|
|
|
|
gtk_popover_menu_root (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GTK_WIDGET_CLASS (gtk_popover_menu_parent_class)->root (widget);
|
|
|
|
|
|
|
|
gtk_accessible_update_property (GTK_ACCESSIBLE (widget),
|
|
|
|
GTK_ACCESSIBLE_PROPERTY_ORIENTATION, GTK_ORIENTATION_VERTICAL,
|
|
|
|
-1);
|
|
|
|
}
|
|
|
|
|
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-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
|
|
|
|
2020-10-21 20:30:04 +00:00
|
|
|
widget_class->root = gtk_popover_menu_root;
|
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;
|
2020-03-24 16:45:12 +00:00
|
|
|
widget_class->move_focus = gtk_popover_menu_move_focus;
|
2014-10-24 03:38:09 +00:00
|
|
|
|
2021-02-27 05:16:04 +00:00
|
|
|
/**
|
|
|
|
* GtkPopoverMenu:visible-submenu:
|
|
|
|
*
|
|
|
|
* The name of the visible submenu.
|
|
|
|
*/
|
2014-11-18 12:39:15 +00:00
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_VISIBLE_SUBMENU,
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_string ("visible-submenu", NULL, NULL,
|
2014-11-18 12:39:15 +00:00
|
|
|
NULL,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2019-06-12 16:35:36 +00:00
|
|
|
|
2021-02-27 05:16:04 +00:00
|
|
|
/**
|
|
|
|
* GtkPopoverMenu:menu-model: (attributes org.gtk.Property.get=gtk_popover_menu_get_menu_model org.gtk.Property.set=gtk_popover_menu_set_menu_model)
|
|
|
|
*
|
|
|
|
* The model from which the menu is made.
|
|
|
|
*/
|
2019-11-11 10:58:43 +00:00
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_MENU_MODEL,
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_object ("menu-model", NULL, NULL,
|
2019-11-11 10:58:43 +00:00
|
|
|
G_TYPE_MENU_MODEL,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2020-02-06 15:00:31 +00:00
|
|
|
add_arrow_bindings (widget_class, GDK_KEY_Up, GTK_DIR_UP);
|
|
|
|
add_arrow_bindings (widget_class, GDK_KEY_Down, GTK_DIR_DOWN);
|
|
|
|
add_arrow_bindings (widget_class, GDK_KEY_Left, GTK_DIR_LEFT);
|
|
|
|
add_arrow_bindings (widget_class, GDK_KEY_Right, GTK_DIR_RIGHT);
|
|
|
|
|
|
|
|
add_tab_bindings (widget_class, 0, GTK_DIR_TAB_FORWARD);
|
|
|
|
add_tab_bindings (widget_class, GDK_CONTROL_MASK, GTK_DIR_TAB_FORWARD);
|
|
|
|
add_tab_bindings (widget_class, GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
|
|
|
|
add_tab_bindings (widget_class, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
|
|
|
|
|
|
|
|
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_Return, 0,
|
|
|
|
"activate-default", NULL);
|
|
|
|
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_ISO_Enter, 0,
|
|
|
|
"activate-default", NULL);
|
|
|
|
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_KP_Enter, 0,
|
|
|
|
"activate-default", NULL);
|
|
|
|
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_space, 0,
|
|
|
|
"activate-default", NULL);
|
|
|
|
gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_KP_Space, 0,
|
|
|
|
"activate-default", NULL);
|
2020-10-21 20:30:04 +00:00
|
|
|
|
|
|
|
gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_MENU);
|
2014-10-24 03:38:09 +00:00
|
|
|
}
|
|
|
|
|
2020-10-26 17:21:28 +00:00
|
|
|
static GtkBuildableIface *parent_buildable_iface;
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_popover_menu_buildable_add_child (GtkBuildable *buildable,
|
|
|
|
GtkBuilder *builder,
|
|
|
|
GObject *child,
|
|
|
|
const char *type)
|
|
|
|
{
|
|
|
|
if (GTK_IS_WIDGET (child))
|
|
|
|
{
|
|
|
|
if (!gtk_popover_menu_add_child (GTK_POPOVER_MENU (buildable), GTK_WIDGET (child), type))
|
|
|
|
g_warning ("No such custom attribute: %s", type);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
parent_buildable_iface->add_child (buildable, builder, child, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_popover_menu_buildable_iface_init (GtkBuildableIface *iface)
|
|
|
|
{
|
|
|
|
parent_buildable_iface = g_type_interface_peek_parent (iface);
|
|
|
|
|
|
|
|
iface->add_child = gtk_popover_menu_buildable_add_child;
|
|
|
|
}
|
|
|
|
|
2014-10-26 23:04:28 +00:00
|
|
|
/**
|
|
|
|
* gtk_popover_menu_new:
|
|
|
|
*
|
|
|
|
* Creates a new popover menu.
|
|
|
|
*
|
2021-02-27 05:16:04 +00:00
|
|
|
* Returns: a new `GtkPopoverMenu`
|
2014-10-26 23:04:28 +00:00
|
|
|
*/
|
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:
|
2021-05-20 13:17:04 +00:00
|
|
|
* @popover: a `GtkPopoverMenu`
|
2014-10-26 23:14:01 +00:00
|
|
|
* @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
|
2021-05-20 13:17:04 +00:00
|
|
|
* of @popover with `GtkPopoverMenu:submenu`, or
|
2014-10-26 23:14:01 +00:00
|
|
|
* "main" to switch back to the main menu.
|
|
|
|
*
|
2021-05-20 13:17:04 +00:00
|
|
|
* `GtkModelButton` will open submenus automatically
|
|
|
|
* when the `GtkModelButton:menu-name` property is set,
|
2014-10-26 23:14:01 +00:00
|
|
|
* 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,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *name)
|
2014-10-26 23:14:01 +00:00
|
|
|
{
|
|
|
|
GtkWidget *stack;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_POPOVER_MENU (popover));
|
|
|
|
|
2021-07-02 17:19:02 +00:00
|
|
|
stack = gtk_popover_menu_get_stack (popover);
|
2014-10-26 23:14:01 +00:00
|
|
|
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)
|
|
|
|
{
|
2021-07-02 17:19:02 +00:00
|
|
|
GtkWidget *stack = gtk_popover_menu_get_stack (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:
|
2021-05-21 00:45:06 +00:00
|
|
|
* @model: (nullable): a `GMenuModel`
|
2019-06-07 17:05:48 +00:00
|
|
|
*
|
2021-02-27 05:16:04 +00:00
|
|
|
* Creates a `GtkPopoverMenu` and populates it according to @model.
|
2019-06-07 17:05:48 +00:00
|
|
|
*
|
|
|
|
* The created buttons are connected to actions found in the
|
2021-02-27 05:16:04 +00:00
|
|
|
* `GtkApplicationWindow` to which the popover belongs - typically
|
2019-06-07 17:05:48 +00:00
|
|
|
* by means of being attached to a widget that is contained within
|
2021-02-27 05:16:04 +00:00
|
|
|
* the `GtkApplicationWindow`s widget hierarchy.
|
2019-06-07 17:05:48 +00:00
|
|
|
*
|
2021-02-27 05:16:04 +00:00
|
|
|
* Actions can also be added using [method@Gtk.Widget.insert_action_group]
|
2019-06-07 17:05:48 +00:00
|
|
|
* 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.
|
2021-02-27 05:16:04 +00:00
|
|
|
* See [ctor@Gtk.PopoverMenu.new_from_model_full] for a way
|
2019-08-27 08:28:29 +00:00
|
|
|
* to control this.
|
|
|
|
*
|
2021-02-27 05:16:04 +00:00
|
|
|
* Returns: the new `GtkPopoverMenu`
|
2019-06-07 17:05:48 +00:00
|
|
|
*/
|
|
|
|
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:
|
2021-02-27 05:16:04 +00:00
|
|
|
* @model: a `GMenuModel`
|
2019-08-27 08:28:29 +00:00
|
|
|
* @flags: flags that affect how the menu is created
|
|
|
|
*
|
2021-02-27 05:16:04 +00:00
|
|
|
* Creates a `GtkPopoverMenu` and populates it according to @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.
|
2021-02-27 05:16:04 +00:00
|
|
|
* This includes the `GtkApplicationWindow` to which the popover
|
|
|
|
* belongs. Actions can also be added using [method@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
|
2021-02-27 05:16:04 +00:00
|
|
|
* %GTK_POPOVER_MENU_NESTED, which makes GTK create traditional,
|
2019-08-27 08:28:29 +00:00
|
|
|
* nested submenus instead of the default sliding submenus.
|
|
|
|
*
|
2022-04-26 12:25:15 +00:00
|
|
|
* Returns: 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
|
|
|
/**
|
2021-02-27 05:16:04 +00:00
|
|
|
* gtk_popover_menu_set_menu_model: (attributes org.gtk.Method.set_property=menu-model)
|
|
|
|
* @popover: a `GtkPopoverMenu`
|
2021-05-21 00:45:06 +00:00
|
|
|
* @model: (nullable): a `GMenuModel`
|
2019-12-30 00:44:31 +00:00
|
|
|
*
|
|
|
|
* 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;
|
|
|
|
|
2021-07-02 17:19:02 +00:00
|
|
|
stack = gtk_popover_menu_get_stack (popover);
|
2019-11-11 10:58:43 +00:00
|
|
|
while ((child = gtk_widget_get_first_child (stack)))
|
2020-05-10 01:01:24 +00:00
|
|
|
gtk_stack_remove (GTK_STACK (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
|
|
|
/**
|
2021-02-27 05:16:04 +00:00
|
|
|
* gtk_popover_menu_get_menu_model: (attributes org.gtk.Method.get_property=menu-model)
|
|
|
|
* @popover: a `GtkPopoverMenu`
|
2019-12-30 00:44:31 +00:00
|
|
|
*
|
|
|
|
* Returns the menu model used to populate the popover.
|
|
|
|
*
|
2022-01-01 16:45:08 +00:00
|
|
|
* Returns: (transfer none) (nullable): 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;
|
|
|
|
}
|
2020-10-20 18:26:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_popover_menu_add_child:
|
2021-02-27 05:16:04 +00:00
|
|
|
* @popover: a `GtkPopoverMenu`
|
|
|
|
* @child: the `GtkWidget` to add
|
2020-10-20 18:26:45 +00:00
|
|
|
* @id: the ID to insert @child at
|
|
|
|
*
|
|
|
|
* Adds a custom widget to a generated menu.
|
|
|
|
*
|
2021-02-27 05:16:04 +00:00
|
|
|
* For this to work, the menu model of @popover must have
|
|
|
|
* an item with a `custom` attribute that matches @id.
|
2020-10-20 18:26:45 +00:00
|
|
|
*
|
|
|
|
* Returns: %TRUE if @id was found and the widget added
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gtk_popover_menu_add_child (GtkPopoverMenu *popover,
|
|
|
|
GtkWidget *child,
|
|
|
|
const char *id)
|
|
|
|
{
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_POPOVER_MENU (popover), FALSE);
|
|
|
|
g_return_val_if_fail (GTK_IS_WIDGET (child), FALSE);
|
|
|
|
g_return_val_if_fail (id != NULL, FALSE);
|
|
|
|
|
|
|
|
return gtk_menu_section_box_add_custom (popover, child, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_popover_menu_remove_child:
|
2021-02-27 05:16:04 +00:00
|
|
|
* @popover: a `GtkPopoverMenu`
|
|
|
|
* @child: the `GtkWidget` to remove
|
2020-10-20 18:26:45 +00:00
|
|
|
*
|
|
|
|
* Removes a widget that has previously been added with
|
|
|
|
* gtk_popover_menu_add_child().
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the widget was removed
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gtk_popover_menu_remove_child (GtkPopoverMenu *popover,
|
|
|
|
GtkWidget *child)
|
|
|
|
{
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_POPOVER_MENU (popover), FALSE);
|
|
|
|
g_return_val_if_fail (GTK_IS_WIDGET (child), FALSE);
|
|
|
|
|
|
|
|
return gtk_menu_section_box_remove_custom (popover, child);
|
|
|
|
}
|