2019-06-07 23:27:24 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
* Copyright (C) 2019 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* - Matthias Clasen <mclasen@redhat.com>
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2019-06-09 16:53:59 +00:00
|
|
|
/**
|
2021-02-27 05:16:13 +00:00
|
|
|
* GtkPopoverMenuBar:
|
2019-06-09 16:53:59 +00:00
|
|
|
*
|
2021-02-27 05:16:13 +00:00
|
|
|
* `GtkPopoverMenuBar` presents a horizontal bar of items that pop
|
2019-12-30 00:44:31 +00:00
|
|
|
* up popover menus when clicked.
|
|
|
|
*
|
2021-02-27 05:16:13 +00:00
|
|
|
* ![An example GtkPopoverMenuBar](menubar.png)
|
|
|
|
*
|
|
|
|
* The only way to create instances of `GtkPopoverMenuBar` is
|
|
|
|
* from a `GMenuModel`.
|
2019-06-09 16:53:59 +00:00
|
|
|
*
|
|
|
|
* # CSS nodes
|
|
|
|
*
|
2021-02-28 01:04:19 +00:00
|
|
|
* ```
|
2019-06-09 16:53:59 +00:00
|
|
|
* menubar
|
|
|
|
* ├── item[.active]
|
|
|
|
* ┊ ╰── popover
|
|
|
|
* ╰── item
|
|
|
|
* ╰── popover
|
2021-02-28 01:04:19 +00:00
|
|
|
* ```
|
2019-06-09 16:53:59 +00:00
|
|
|
*
|
2021-02-27 05:16:13 +00:00
|
|
|
* `GtkPopoverMenuBar` has a single CSS node with name menubar, below which
|
2019-12-28 14:42:43 +00:00
|
|
|
* each item has its CSS node, and below that the corresponding popover.
|
2019-06-09 16:53:59 +00:00
|
|
|
*
|
|
|
|
* The item whose popover is currently open gets the .active
|
|
|
|
* style class.
|
2020-10-21 20:34:16 +00:00
|
|
|
*
|
|
|
|
* # Accessibility
|
|
|
|
*
|
2021-02-27 05:16:13 +00:00
|
|
|
* `GtkPopoverMenuBar` uses the %GTK_ACCESSIBLE_ROLE_MENU_BAR role,
|
|
|
|
* the menu items use the %GTK_ACCESSIBLE_ROLE_MENU_ITEM role and
|
|
|
|
* the menus use the %GTK_ACCESSIBLE_ROLE_MENU role.
|
2019-06-09 16:53:59 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2019-06-07 23:27:24 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2019-06-09 16:19:07 +00:00
|
|
|
#include "gtkpopovermenubar.h"
|
2019-12-27 13:45:21 +00:00
|
|
|
#include "gtkpopovermenubarprivate.h"
|
2019-06-07 23:27:24 +00:00
|
|
|
#include "gtkpopovermenu.h"
|
|
|
|
|
2021-03-08 05:46:30 +00:00
|
|
|
#include "gtkbinlayout.h"
|
2019-06-09 15:23:47 +00:00
|
|
|
#include "gtkboxlayout.h"
|
2019-06-07 23:27:24 +00:00
|
|
|
#include "gtklabel.h"
|
|
|
|
#include "gtkmenubutton.h"
|
|
|
|
#include "gtkprivate.h"
|
|
|
|
#include "gtkmarshalers.h"
|
|
|
|
#include "gtkgestureclick.h"
|
2019-06-08 03:23:22 +00:00
|
|
|
#include "gtkeventcontrollermotion.h"
|
2019-06-07 23:27:24 +00:00
|
|
|
#include "gtkactionmuxerprivate.h"
|
2019-06-10 03:10:13 +00:00
|
|
|
#include "gtkmenutrackerprivate.h"
|
2019-06-07 23:27:24 +00:00
|
|
|
#include "gtkwidgetprivate.h"
|
2019-06-08 03:23:22 +00:00
|
|
|
#include "gtkmain.h"
|
|
|
|
#include "gtknative.h"
|
2020-10-26 17:21:28 +00:00
|
|
|
#include "gtkbuildable.h"
|
2019-06-07 23:27:24 +00:00
|
|
|
|
2019-06-09 16:19:07 +00:00
|
|
|
#define GTK_TYPE_POPOVER_MENU_BAR_ITEM (gtk_popover_menu_bar_item_get_type ())
|
|
|
|
#define GTK_POPOVER_MENU_BAR_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_POPOVER_MENU_BAR_ITEM, GtkPopoverMenuBarItem))
|
|
|
|
#define GTK_IS_POPOVER_MENU_BAR_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_POPOVER_MENU_BAR_ITEM))
|
2019-06-08 13:42:18 +00:00
|
|
|
|
2019-06-09 16:19:07 +00:00
|
|
|
GType gtk_popover_menu_bar_item_get_type (void) G_GNUC_CONST;
|
2019-06-08 13:42:18 +00:00
|
|
|
|
2019-06-09 16:19:07 +00:00
|
|
|
typedef struct _GtkPopoverMenuBarItem GtkPopoverMenuBarItem;
|
2019-06-08 17:48:29 +00:00
|
|
|
|
2019-06-09 16:19:07 +00:00
|
|
|
struct _GtkPopoverMenuBar
|
2019-06-07 23:27:24 +00:00
|
|
|
{
|
|
|
|
GtkWidget parent;
|
|
|
|
|
2019-06-08 15:27:52 +00:00
|
|
|
GMenuModel *model;
|
2019-06-07 23:27:24 +00:00
|
|
|
GtkMenuTracker *tracker;
|
2019-06-08 17:48:29 +00:00
|
|
|
|
2019-06-09 16:19:07 +00:00
|
|
|
GtkPopoverMenuBarItem *active_item;
|
2019-06-07 23:27:24 +00:00
|
|
|
};
|
|
|
|
|
2019-06-09 16:19:07 +00:00
|
|
|
typedef struct _GtkPopoverMenuBarClass GtkPopoverMenuBarClass;
|
|
|
|
struct _GtkPopoverMenuBarClass
|
2019-06-07 23:27:24 +00:00
|
|
|
{
|
|
|
|
GtkWidgetClass parent_class;
|
|
|
|
};
|
|
|
|
|
2019-06-09 16:19:07 +00:00
|
|
|
struct _GtkPopoverMenuBarItem
|
2019-06-08 13:42:18 +00:00
|
|
|
{
|
|
|
|
GtkWidget parent;
|
|
|
|
|
|
|
|
GtkWidget *label;
|
2019-06-08 17:48:29 +00:00
|
|
|
GtkPopover *popover;
|
2021-03-08 05:46:30 +00:00
|
|
|
GtkMenuTrackerItem *tracker;
|
2019-06-08 13:42:18 +00:00
|
|
|
};
|
|
|
|
|
2019-06-09 16:19:07 +00:00
|
|
|
typedef struct _GtkPopoverMenuBarItemClass GtkPopoverMenuBarItemClass;
|
|
|
|
struct _GtkPopoverMenuBarItemClass
|
2019-06-08 13:42:18 +00:00
|
|
|
{
|
|
|
|
GtkWidgetClass parent_class;
|
|
|
|
|
2019-06-09 16:19:07 +00:00
|
|
|
void (* activate) (GtkPopoverMenuBarItem *item);
|
2019-06-08 13:42:18 +00:00
|
|
|
};
|
|
|
|
|
2019-06-09 16:19:07 +00:00
|
|
|
G_DEFINE_TYPE (GtkPopoverMenuBarItem, gtk_popover_menu_bar_item, GTK_TYPE_WIDGET)
|
2019-06-08 13:42:18 +00:00
|
|
|
|
2021-03-08 05:46:30 +00:00
|
|
|
static void
|
|
|
|
open_submenu (GtkPopoverMenuBarItem *item)
|
|
|
|
{
|
|
|
|
gtk_popover_popup (item->popover);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
close_submenu (GtkPopoverMenuBarItem *item)
|
|
|
|
{
|
|
|
|
gtk_popover_popdown (item->popover);
|
|
|
|
}
|
|
|
|
|
2019-06-08 17:48:29 +00:00
|
|
|
static void
|
2019-06-09 16:19:07 +00:00
|
|
|
set_active_item (GtkPopoverMenuBar *bar,
|
|
|
|
GtkPopoverMenuBarItem *item,
|
|
|
|
gboolean popup)
|
2019-06-08 17:48:29 +00:00
|
|
|
{
|
|
|
|
gboolean changed;
|
|
|
|
gboolean was_popup;
|
|
|
|
|
|
|
|
changed = item != bar->active_item;
|
|
|
|
|
|
|
|
if (bar->active_item)
|
|
|
|
was_popup = gtk_widget_get_mapped (GTK_WIDGET (bar->active_item->popover));
|
|
|
|
else
|
|
|
|
was_popup = FALSE;
|
|
|
|
|
|
|
|
if (was_popup && changed)
|
2021-03-08 05:46:30 +00:00
|
|
|
close_submenu (bar->active_item);
|
2019-06-08 17:48:29 +00:00
|
|
|
|
|
|
|
if (changed)
|
|
|
|
{
|
|
|
|
if (bar->active_item)
|
2019-06-13 00:12:33 +00:00
|
|
|
gtk_widget_unset_state_flags (GTK_WIDGET (bar->active_item), GTK_STATE_FLAG_SELECTED);
|
2019-06-08 17:48:29 +00:00
|
|
|
|
|
|
|
bar->active_item = item;
|
|
|
|
|
|
|
|
if (bar->active_item)
|
2019-06-13 00:12:33 +00:00
|
|
|
gtk_widget_set_state_flags (GTK_WIDGET (bar->active_item), GTK_STATE_FLAG_SELECTED, FALSE);
|
2019-06-08 17:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (bar->active_item)
|
|
|
|
{
|
|
|
|
if (popup || (was_popup && changed))
|
2021-03-08 05:46:30 +00:00
|
|
|
open_submenu (bar->active_item);
|
2019-06-09 14:03:40 +00:00
|
|
|
else if (changed)
|
2019-06-08 17:48:29 +00:00
|
|
|
gtk_widget_grab_focus (GTK_WIDGET (bar->active_item));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-08 13:42:18 +00:00
|
|
|
static void
|
|
|
|
clicked_cb (GtkGesture *gesture,
|
|
|
|
int n,
|
|
|
|
double x,
|
|
|
|
double y,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkWidget *target;
|
2019-06-09 16:19:07 +00:00
|
|
|
GtkPopoverMenuBar *bar;
|
2019-06-08 13:42:18 +00:00
|
|
|
|
|
|
|
target = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture));
|
2019-06-09 16:19:07 +00:00
|
|
|
bar = GTK_POPOVER_MENU_BAR (gtk_widget_get_ancestor (target, GTK_TYPE_POPOVER_MENU_BAR));
|
2019-06-08 13:42:18 +00:00
|
|
|
|
2019-06-09 16:19:07 +00:00
|
|
|
set_active_item (bar, GTK_POPOVER_MENU_BAR_ITEM (target), TRUE);
|
2019-06-08 13:42:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-02-20 03:04:28 +00:00
|
|
|
item_enter_cb (GtkEventController *controller,
|
|
|
|
double x,
|
|
|
|
double y,
|
|
|
|
gpointer data)
|
2019-06-08 13:42:18 +00:00
|
|
|
{
|
|
|
|
GtkWidget *target;
|
2019-06-09 16:19:07 +00:00
|
|
|
GtkPopoverMenuBar *bar;
|
2019-06-08 13:42:18 +00:00
|
|
|
|
|
|
|
target = gtk_event_controller_get_widget (controller);
|
2019-06-09 16:19:07 +00:00
|
|
|
bar = GTK_POPOVER_MENU_BAR (gtk_widget_get_ancestor (target, GTK_TYPE_POPOVER_MENU_BAR));
|
2019-06-08 13:42:18 +00:00
|
|
|
|
2020-02-20 03:04:28 +00:00
|
|
|
set_active_item (bar, GTK_POPOVER_MENU_BAR_ITEM (target), FALSE);
|
2019-06-08 17:48:29 +00:00
|
|
|
}
|
|
|
|
|
2019-06-12 19:54:26 +00:00
|
|
|
static void
|
2020-02-20 03:04:28 +00:00
|
|
|
bar_leave_cb (GtkEventController *controller,
|
|
|
|
gpointer data)
|
2019-06-12 19:54:26 +00:00
|
|
|
{
|
|
|
|
GtkWidget *target;
|
|
|
|
GtkPopoverMenuBar *bar;
|
|
|
|
|
|
|
|
target = gtk_event_controller_get_widget (controller);
|
|
|
|
bar = GTK_POPOVER_MENU_BAR (gtk_widget_get_ancestor (target, GTK_TYPE_POPOVER_MENU_BAR));
|
|
|
|
|
2020-02-20 03:04:28 +00:00
|
|
|
if (bar->active_item &&
|
|
|
|
!gtk_widget_get_mapped (GTK_WIDGET (bar->active_item->popover)))
|
|
|
|
set_active_item (bar, NULL, FALSE);
|
2019-06-12 19:54:26 +00:00
|
|
|
}
|
|
|
|
|
2019-06-08 17:48:29 +00:00
|
|
|
static gboolean
|
2019-06-09 16:19:07 +00:00
|
|
|
gtk_popover_menu_bar_focus (GtkWidget *widget,
|
|
|
|
GtkDirectionType direction)
|
2019-06-08 17:48:29 +00:00
|
|
|
{
|
2019-06-09 16:19:07 +00:00
|
|
|
GtkPopoverMenuBar *bar = GTK_POPOVER_MENU_BAR (widget);
|
2019-06-08 17:48:29 +00:00
|
|
|
GtkWidget *next;
|
2019-06-13 00:12:33 +00:00
|
|
|
|
2019-06-09 02:23:47 +00:00
|
|
|
if (bar->active_item &&
|
|
|
|
gtk_widget_get_mapped (GTK_WIDGET (bar->active_item->popover)))
|
|
|
|
{
|
|
|
|
if (gtk_widget_child_focus (GTK_WIDGET (bar->active_item->popover), direction))
|
|
|
|
return TRUE;
|
|
|
|
}
|
2019-06-08 17:48:29 +00:00
|
|
|
|
2019-06-09 02:23:47 +00:00
|
|
|
if (direction == GTK_DIR_LEFT)
|
2019-06-08 13:42:18 +00:00
|
|
|
{
|
2019-06-09 02:23:47 +00:00
|
|
|
if (bar->active_item)
|
|
|
|
next = gtk_widget_get_prev_sibling (GTK_WIDGET (bar->active_item));
|
|
|
|
else
|
|
|
|
next = NULL;
|
|
|
|
|
2019-06-08 17:48:29 +00:00
|
|
|
if (next == NULL)
|
2019-06-09 15:23:47 +00:00
|
|
|
next = gtk_widget_get_last_child (GTK_WIDGET (bar));
|
2019-06-08 13:42:18 +00:00
|
|
|
}
|
2019-06-09 02:23:47 +00:00
|
|
|
else if (direction == GTK_DIR_RIGHT)
|
2019-06-08 17:48:29 +00:00
|
|
|
{
|
2019-06-09 02:23:47 +00:00
|
|
|
if (bar->active_item)
|
|
|
|
next = gtk_widget_get_next_sibling (GTK_WIDGET (bar->active_item));
|
|
|
|
else
|
|
|
|
next = NULL;
|
|
|
|
|
2019-06-08 17:48:29 +00:00
|
|
|
if (next == NULL)
|
2019-06-09 15:23:47 +00:00
|
|
|
next = gtk_widget_get_first_child (GTK_WIDGET (bar));
|
2019-06-08 17:48:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
|
2019-06-09 16:19:07 +00:00
|
|
|
set_active_item (bar, GTK_POPOVER_MENU_BAR_ITEM (next), FALSE);
|
2019-06-08 17:48:29 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2019-06-08 13:42:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-06-09 16:19:07 +00:00
|
|
|
gtk_popover_menu_bar_item_init (GtkPopoverMenuBarItem *item)
|
2019-06-08 13:42:18 +00:00
|
|
|
{
|
|
|
|
GtkEventController *controller;
|
|
|
|
|
2020-05-05 18:57:21 +00:00
|
|
|
gtk_widget_set_focusable (GTK_WIDGET (item), TRUE);
|
2019-06-08 17:48:29 +00:00
|
|
|
|
2019-06-08 13:42:18 +00:00
|
|
|
item->label = g_object_new (GTK_TYPE_LABEL,
|
|
|
|
"use-underline", TRUE,
|
|
|
|
NULL);
|
|
|
|
gtk_widget_set_parent (item->label, GTK_WIDGET (item));
|
|
|
|
|
|
|
|
controller = GTK_EVENT_CONTROLLER (gtk_gesture_click_new ());
|
|
|
|
g_signal_connect (controller, "pressed", G_CALLBACK (clicked_cb), NULL);
|
|
|
|
gtk_widget_add_controller (GTK_WIDGET (item), controller);
|
|
|
|
|
|
|
|
controller = gtk_event_controller_motion_new ();
|
|
|
|
gtk_event_controller_set_propagation_limit (controller, GTK_LIMIT_NONE);
|
2020-02-20 03:04:28 +00:00
|
|
|
g_signal_connect (controller, "enter", G_CALLBACK (item_enter_cb), NULL);
|
2019-06-08 13:42:18 +00:00
|
|
|
gtk_widget_add_controller (GTK_WIDGET (item), controller);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-06-09 16:19:07 +00:00
|
|
|
gtk_popover_menu_bar_item_dispose (GObject *object)
|
2019-06-08 13:42:18 +00:00
|
|
|
{
|
2019-06-09 16:19:07 +00:00
|
|
|
GtkPopoverMenuBarItem *item = GTK_POPOVER_MENU_BAR_ITEM (object);
|
2019-06-08 13:42:18 +00:00
|
|
|
|
2021-03-08 05:46:30 +00:00
|
|
|
g_clear_object (&item->tracker);
|
2019-06-08 13:42:18 +00:00
|
|
|
g_clear_pointer (&item->label, gtk_widget_unparent);
|
2019-06-09 15:23:47 +00:00
|
|
|
g_clear_pointer ((GtkWidget **)&item->popover, gtk_widget_unparent);
|
2019-06-08 13:42:18 +00:00
|
|
|
|
2019-06-09 16:19:07 +00:00
|
|
|
G_OBJECT_CLASS (gtk_popover_menu_bar_item_parent_class)->dispose (object);
|
2019-06-08 13:42:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-06-09 16:19:07 +00:00
|
|
|
gtk_popover_menu_bar_item_finalize (GObject *object)
|
2019-06-08 13:42:18 +00:00
|
|
|
{
|
2019-06-09 16:19:07 +00:00
|
|
|
G_OBJECT_CLASS (gtk_popover_menu_bar_item_parent_class)->finalize (object);
|
2019-06-08 13:42:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-06-09 16:19:07 +00:00
|
|
|
gtk_popover_menu_bar_item_activate (GtkPopoverMenuBarItem *item)
|
2019-06-08 13:42:18 +00:00
|
|
|
{
|
2019-08-27 08:28:29 +00:00
|
|
|
GtkPopoverMenuBar *bar;
|
|
|
|
|
|
|
|
bar = GTK_POPOVER_MENU_BAR (gtk_widget_get_ancestor (GTK_WIDGET (item), GTK_TYPE_POPOVER_MENU_BAR));
|
|
|
|
|
|
|
|
set_active_item (bar, item, TRUE);
|
2019-06-08 13:42:18 +00:00
|
|
|
}
|
|
|
|
|
2020-10-21 20:34:16 +00:00
|
|
|
static void
|
|
|
|
gtk_popover_menu_bar_item_root (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkPopoverMenuBarItem *item = GTK_POPOVER_MENU_BAR_ITEM (widget);
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_popover_menu_bar_item_parent_class)->root (widget);
|
|
|
|
|
|
|
|
gtk_accessible_update_relation (GTK_ACCESSIBLE (widget),
|
2020-11-10 14:14:47 +00:00
|
|
|
GTK_ACCESSIBLE_RELATION_LABELLED_BY, item->label, NULL,
|
|
|
|
GTK_ACCESSIBLE_RELATION_CONTROLS, item->popover, NULL,
|
2020-10-21 20:34:16 +00:00
|
|
|
-1);
|
|
|
|
gtk_accessible_update_property (GTK_ACCESSIBLE (widget),
|
|
|
|
GTK_ACCESSIBLE_PROPERTY_HAS_POPUP, TRUE,
|
|
|
|
-1);
|
|
|
|
}
|
|
|
|
|
2019-06-08 13:42:18 +00:00
|
|
|
static void
|
2019-06-09 16:19:07 +00:00
|
|
|
gtk_popover_menu_bar_item_class_init (GtkPopoverMenuBarItemClass *klass)
|
2019-06-08 13:42:18 +00:00
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
2020-12-04 23:12:20 +00:00
|
|
|
guint activate_signal;
|
2019-06-08 13:42:18 +00:00
|
|
|
|
2019-06-09 16:19:07 +00:00
|
|
|
object_class->dispose = gtk_popover_menu_bar_item_dispose;
|
|
|
|
object_class->finalize = gtk_popover_menu_bar_item_finalize;
|
2019-06-08 13:42:18 +00:00
|
|
|
|
2020-10-21 20:34:16 +00:00
|
|
|
widget_class->root = gtk_popover_menu_bar_item_root;
|
2019-06-08 13:42:18 +00:00
|
|
|
|
2019-06-09 16:19:07 +00:00
|
|
|
klass->activate = gtk_popover_menu_bar_item_activate;
|
2019-06-08 13:42:18 +00:00
|
|
|
|
2020-12-04 23:12:20 +00:00
|
|
|
activate_signal =
|
2019-06-08 13:42:18 +00:00
|
|
|
g_signal_new (I_("activate"),
|
|
|
|
G_OBJECT_CLASS_TYPE (object_class),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
2019-06-09 16:19:07 +00:00
|
|
|
G_STRUCT_OFFSET (GtkPopoverMenuBarItemClass, activate),
|
2019-06-08 13:42:18 +00:00
|
|
|
NULL, NULL,
|
|
|
|
NULL,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
2019-06-08 17:48:29 +00:00
|
|
|
gtk_widget_class_set_css_name (widget_class, I_("item"));
|
2020-10-21 20:34:16 +00:00
|
|
|
gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_MENU_ITEM);
|
2020-12-04 23:12:20 +00:00
|
|
|
gtk_widget_class_set_activate_signal (widget_class, activate_signal);
|
2021-03-08 05:46:30 +00:00
|
|
|
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
|
2019-06-08 13:42:18 +00:00
|
|
|
}
|
2019-06-08 15:27:52 +00:00
|
|
|
enum
|
2019-06-07 23:27:24 +00:00
|
|
|
{
|
2019-06-08 15:27:52 +00:00
|
|
|
PROP_0,
|
|
|
|
PROP_MENU_MODEL,
|
|
|
|
LAST_PROP
|
|
|
|
};
|
2019-06-07 23:27:24 +00:00
|
|
|
|
2019-06-08 15:27:52 +00:00
|
|
|
static GParamSpec * bar_props[LAST_PROP];
|
2019-06-07 23:27:24 +00:00
|
|
|
|
2020-10-26 17:21:28 +00:00
|
|
|
static void gtk_popover_menu_bar_buildable_iface_init (GtkBuildableIface *iface);
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkPopoverMenuBar, gtk_popover_menu_bar, GTK_TYPE_WIDGET,
|
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
|
|
|
|
gtk_popover_menu_bar_buildable_iface_init))
|
2019-06-07 23:27:24 +00:00
|
|
|
|
|
|
|
static void
|
2020-07-24 13:54:49 +00:00
|
|
|
tracker_remove (int position,
|
2019-06-07 23:27:24 +00:00
|
|
|
gpointer user_data)
|
|
|
|
{
|
2019-06-09 15:23:47 +00:00
|
|
|
GtkWidget *bar = user_data;
|
2019-06-07 23:27:24 +00:00
|
|
|
GtkWidget *child;
|
|
|
|
int i;
|
|
|
|
|
2019-06-09 15:23:47 +00:00
|
|
|
for (child = gtk_widget_get_first_child (bar), i = 0;
|
2019-06-07 23:27:24 +00:00
|
|
|
child;
|
|
|
|
child = gtk_widget_get_next_sibling (child), i++)
|
|
|
|
{
|
|
|
|
if (i == position)
|
|
|
|
{
|
2020-02-20 18:26:44 +00:00
|
|
|
gtk_widget_unparent (child);
|
2019-06-07 23:27:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-08 03:23:22 +00:00
|
|
|
static void
|
2019-06-09 16:19:07 +00:00
|
|
|
popover_unmap (GtkPopover *popover,
|
|
|
|
GtkPopoverMenuBar *bar)
|
2019-06-08 03:23:22 +00:00
|
|
|
{
|
2019-06-08 17:48:29 +00:00
|
|
|
if (bar->active_item && bar->active_item->popover == popover)
|
|
|
|
set_active_item (bar, NULL, FALSE);
|
2019-06-08 03:23:22 +00:00
|
|
|
}
|
|
|
|
|
2021-03-08 05:46:30 +00:00
|
|
|
static void
|
|
|
|
popover_shown (GtkPopover *popover,
|
|
|
|
GtkPopoverMenuBarItem *item)
|
|
|
|
{
|
|
|
|
gtk_accessible_update_state (GTK_ACCESSIBLE (item),
|
|
|
|
GTK_ACCESSIBLE_STATE_EXPANDED, TRUE,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
if (gtk_menu_tracker_item_get_should_request_show (item->tracker))
|
|
|
|
gtk_menu_tracker_item_request_submenu_shown (item->tracker, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
popover_hidden (GtkPopover *popover,
|
|
|
|
GtkPopoverMenuBarItem *item)
|
|
|
|
{
|
|
|
|
gtk_accessible_update_state (GTK_ACCESSIBLE (item),
|
|
|
|
GTK_ACCESSIBLE_STATE_EXPANDED, FALSE,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
if (gtk_menu_tracker_item_get_should_request_show (item->tracker))
|
|
|
|
gtk_menu_tracker_item_request_submenu_shown (item->tracker, FALSE);
|
|
|
|
}
|
|
|
|
|
2019-06-07 23:27:24 +00:00
|
|
|
static void
|
|
|
|
tracker_insert (GtkMenuTrackerItem *item,
|
2020-07-24 13:54:49 +00:00
|
|
|
int position,
|
2019-06-07 23:27:24 +00:00
|
|
|
gpointer user_data)
|
|
|
|
{
|
2019-06-09 16:19:07 +00:00
|
|
|
GtkPopoverMenuBar *bar = user_data;
|
2019-06-07 23:27:24 +00:00
|
|
|
|
|
|
|
if (gtk_menu_tracker_item_get_has_link (item, G_MENU_LINK_SUBMENU))
|
|
|
|
{
|
2019-06-09 16:19:07 +00:00
|
|
|
GtkPopoverMenuBarItem *widget;
|
2019-06-07 23:27:24 +00:00
|
|
|
GMenuModel *model;
|
|
|
|
GtkWidget *sibling;
|
|
|
|
GtkWidget *child;
|
2019-06-08 17:48:29 +00:00
|
|
|
GtkPopover *popover;
|
2019-06-07 23:27:24 +00:00
|
|
|
int i;
|
2019-06-08 03:23:22 +00:00
|
|
|
|
2019-06-09 16:19:07 +00:00
|
|
|
widget = g_object_new (GTK_TYPE_POPOVER_MENU_BAR_ITEM, NULL);
|
2019-06-08 13:42:18 +00:00
|
|
|
g_object_bind_property (item, "label",
|
|
|
|
widget->label, "label",
|
|
|
|
G_BINDING_SYNC_CREATE);
|
2019-06-08 03:23:22 +00:00
|
|
|
|
2019-06-07 23:27:24 +00:00
|
|
|
model = _gtk_menu_tracker_item_get_link (item, G_MENU_LINK_SUBMENU);
|
2020-02-24 12:21:46 +00:00
|
|
|
popover = GTK_POPOVER (gtk_popover_menu_new_from_model_full (model, GTK_POPOVER_MENU_NESTED));
|
|
|
|
gtk_widget_set_parent (GTK_WIDGET (popover), GTK_WIDGET (widget));
|
2019-06-08 17:48:29 +00:00
|
|
|
gtk_popover_set_position (popover, GTK_POS_BOTTOM);
|
|
|
|
gtk_popover_set_has_arrow (popover, FALSE);
|
|
|
|
gtk_widget_set_halign (GTK_WIDGET (popover), GTK_ALIGN_START);
|
2019-06-08 03:23:22 +00:00
|
|
|
|
2019-06-08 13:42:18 +00:00
|
|
|
g_signal_connect (popover, "unmap", G_CALLBACK (popover_unmap), bar);
|
2021-03-08 05:46:30 +00:00
|
|
|
g_signal_connect (popover, "show", G_CALLBACK (popover_shown), widget);
|
|
|
|
g_signal_connect (popover, "hide", G_CALLBACK (popover_hidden), widget);
|
2019-06-08 13:42:18 +00:00
|
|
|
|
|
|
|
widget->popover = popover;
|
2021-03-08 05:46:30 +00:00
|
|
|
widget->tracker = g_object_ref (item);
|
2019-06-07 23:27:24 +00:00
|
|
|
|
|
|
|
sibling = NULL;
|
2019-06-09 15:23:47 +00:00
|
|
|
for (child = gtk_widget_get_first_child (GTK_WIDGET (bar)), i = 1;
|
2019-06-07 23:27:24 +00:00
|
|
|
child;
|
|
|
|
child = gtk_widget_get_next_sibling (child), i++)
|
|
|
|
{
|
|
|
|
if (i == position)
|
|
|
|
{
|
|
|
|
sibling = child;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-06-09 15:23:47 +00:00
|
|
|
gtk_widget_insert_after (GTK_WIDGET (widget), GTK_WIDGET (bar), sibling);
|
2019-06-07 23:27:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
g_warning ("Don't know how to handle this item");
|
|
|
|
}
|
|
|
|
|
2019-06-08 15:27:52 +00:00
|
|
|
static void
|
2019-06-09 16:19:07 +00:00
|
|
|
gtk_popover_menu_bar_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2019-06-08 15:27:52 +00:00
|
|
|
{
|
2019-06-09 16:19:07 +00:00
|
|
|
GtkPopoverMenuBar *bar = GTK_POPOVER_MENU_BAR (object);
|
2019-06-08 15:27:52 +00:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_MENU_MODEL:
|
2019-06-09 16:19:07 +00:00
|
|
|
gtk_popover_menu_bar_set_menu_model (bar, g_value_get_object (value));
|
2019-06-08 15:27:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-06-09 16:19:07 +00:00
|
|
|
gtk_popover_menu_bar_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2019-06-07 23:27:24 +00:00
|
|
|
{
|
2019-06-09 16:19:07 +00:00
|
|
|
GtkPopoverMenuBar *bar = GTK_POPOVER_MENU_BAR (object);
|
2019-06-08 15:27:52 +00:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_MENU_MODEL:
|
|
|
|
g_value_set_object (value, bar->model);
|
|
|
|
break;
|
2019-06-07 23:27:24 +00:00
|
|
|
|
2019-06-08 15:27:52 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
2019-06-07 23:27:24 +00:00
|
|
|
|
2019-06-08 15:27:52 +00:00
|
|
|
static void
|
2019-06-09 16:19:07 +00:00
|
|
|
gtk_popover_menu_bar_dispose (GObject *object)
|
2019-06-08 15:27:52 +00:00
|
|
|
{
|
2019-06-09 16:19:07 +00:00
|
|
|
GtkPopoverMenuBar *bar = GTK_POPOVER_MENU_BAR (object);
|
2019-06-09 15:23:47 +00:00
|
|
|
GtkWidget *child;
|
2019-06-07 23:27:24 +00:00
|
|
|
|
2019-06-08 15:27:52 +00:00
|
|
|
g_clear_pointer (&bar->tracker, gtk_menu_tracker_free);
|
|
|
|
g_clear_object (&bar->model);
|
|
|
|
|
2019-06-09 15:23:47 +00:00
|
|
|
while ((child = gtk_widget_get_first_child (GTK_WIDGET (bar))))
|
2020-02-20 18:26:44 +00:00
|
|
|
gtk_widget_unparent (child);
|
2019-06-08 15:27:52 +00:00
|
|
|
|
2019-06-09 15:23:47 +00:00
|
|
|
G_OBJECT_CLASS (gtk_popover_menu_bar_parent_class)->dispose (object);
|
2019-06-08 15:27:52 +00:00
|
|
|
}
|
|
|
|
|
2019-12-27 13:45:21 +00:00
|
|
|
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);
|
2020-10-21 20:34:16 +00:00
|
|
|
|
|
|
|
gtk_accessible_update_property (GTK_ACCESSIBLE (bar),
|
|
|
|
GTK_ACCESSIBLE_PROPERTY_ORIENTATION, GTK_ORIENTATION_HORIZONTAL,
|
|
|
|
-1);
|
2019-12-27 13:45:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-06-08 15:27:52 +00:00
|
|
|
static void
|
2019-06-09 16:19:07 +00:00
|
|
|
gtk_popover_menu_bar_class_init (GtkPopoverMenuBarClass *klass)
|
2019-06-08 15:27:52 +00:00
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
2019-06-09 15:23:47 +00:00
|
|
|
object_class->dispose = gtk_popover_menu_bar_dispose;
|
|
|
|
object_class->set_property = gtk_popover_menu_bar_set_property;
|
|
|
|
object_class->get_property = gtk_popover_menu_bar_get_property;
|
|
|
|
|
2019-12-27 13:45:21 +00:00
|
|
|
widget_class->root = gtk_popover_menu_bar_root;
|
|
|
|
widget_class->unroot = gtk_popover_menu_bar_unroot;
|
2019-06-09 15:23:47 +00:00
|
|
|
widget_class->focus = gtk_popover_menu_bar_focus;
|
|
|
|
|
|
|
|
/**
|
2021-02-27 05:16:13 +00:00
|
|
|
* GtkPopoverMenuBar:menu-model: (attributes org.gtk.Property.get=gtk_popover_menu_bar_get_menu_model org.gtk.Property.set=gtk_popover_menu_bar_set_menu_model)
|
2019-06-09 15:23:47 +00:00
|
|
|
*
|
2021-02-27 05:16:13 +00:00
|
|
|
* The `GMenuModel` from which the menu bar is created.
|
2019-06-09 15:23:47 +00:00
|
|
|
*
|
2019-12-30 00:44:31 +00:00
|
|
|
* The model should only contain submenus as toplevel elements.
|
2019-06-09 15:23:47 +00:00
|
|
|
*/
|
2019-06-08 15:27:52 +00:00
|
|
|
bar_props[PROP_MENU_MODEL] =
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_object ("menu-model", NULL, NULL,
|
2019-06-08 15:27:52 +00:00
|
|
|
G_TYPE_MENU_MODEL,
|
|
|
|
GTK_PARAM_READWRITE);
|
|
|
|
|
|
|
|
g_object_class_install_properties (object_class, LAST_PROP, bar_props);
|
|
|
|
|
2019-06-09 15:23:47 +00:00
|
|
|
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BOX_LAYOUT);
|
2019-06-08 15:27:52 +00:00
|
|
|
gtk_widget_class_set_css_name (widget_class, I_("menubar"));
|
2020-10-21 20:34:16 +00:00
|
|
|
gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_MENU_BAR);
|
2019-06-08 15:27:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-06-09 16:19:07 +00:00
|
|
|
gtk_popover_menu_bar_init (GtkPopoverMenuBar *bar)
|
2019-06-08 15:27:52 +00:00
|
|
|
{
|
2019-06-12 19:54:26 +00:00
|
|
|
GtkEventController *controller;
|
|
|
|
|
|
|
|
controller = gtk_event_controller_motion_new ();
|
|
|
|
gtk_event_controller_set_propagation_limit (controller, GTK_LIMIT_NONE);
|
2020-02-20 03:04:28 +00:00
|
|
|
g_signal_connect (controller, "leave", G_CALLBACK (bar_leave_cb), NULL);
|
2019-06-12 19:54:26 +00:00
|
|
|
gtk_widget_add_controller (GTK_WIDGET (bar), controller);
|
2019-06-08 15:27:52 +00:00
|
|
|
}
|
|
|
|
|
2020-10-26 17:21:28 +00:00
|
|
|
static GtkBuildableIface *parent_buildable_iface;
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_popover_menu_bar_buildable_add_child (GtkBuildable *buildable,
|
|
|
|
GtkBuilder *builder,
|
|
|
|
GObject *child,
|
|
|
|
const char *type)
|
|
|
|
{
|
|
|
|
if (GTK_IS_WIDGET (child))
|
|
|
|
{
|
|
|
|
if (!gtk_popover_menu_bar_add_child (GTK_POPOVER_MENU_BAR (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_bar_buildable_iface_init (GtkBuildableIface *iface)
|
|
|
|
{
|
|
|
|
parent_buildable_iface = g_type_interface_peek_parent (iface);
|
|
|
|
|
|
|
|
iface->add_child = gtk_popover_menu_bar_buildable_add_child;
|
|
|
|
}
|
|
|
|
|
2019-06-09 16:53:59 +00:00
|
|
|
/**
|
|
|
|
* gtk_popover_menu_bar_new_from_model:
|
2021-05-21 00:45:06 +00:00
|
|
|
* @model: (nullable): a `GMenuModel`
|
2019-06-09 16:53:59 +00:00
|
|
|
*
|
2021-02-27 05:16:13 +00:00
|
|
|
* Creates a `GtkPopoverMenuBar` from a `GMenuModel`.
|
2019-06-09 16:53:59 +00:00
|
|
|
*
|
2021-02-27 05:16:13 +00:00
|
|
|
* Returns: a new `GtkPopoverMenuBar`
|
2019-06-09 16:53:59 +00:00
|
|
|
*/
|
2019-06-08 15:27:52 +00:00
|
|
|
GtkWidget *
|
2019-06-09 16:19:07 +00:00
|
|
|
gtk_popover_menu_bar_new_from_model (GMenuModel *model)
|
2019-06-08 15:27:52 +00:00
|
|
|
{
|
2019-06-09 16:19:07 +00:00
|
|
|
return g_object_new (GTK_TYPE_POPOVER_MENU_BAR,
|
2019-06-08 15:27:52 +00:00
|
|
|
"menu-model", model,
|
|
|
|
NULL);
|
2019-06-07 23:27:24 +00:00
|
|
|
}
|
2019-06-09 16:04:12 +00:00
|
|
|
|
2019-06-09 16:53:59 +00:00
|
|
|
/**
|
2021-02-27 05:16:13 +00:00
|
|
|
* gtk_popover_menu_bar_set_menu_model: (attributes org.gtk.Method.set_property=menu-model)
|
|
|
|
* @bar: a `GtkPopoverMenuBar`
|
2021-05-21 00:45:06 +00:00
|
|
|
* @model: (nullable): a `GMenuModel`
|
2019-06-09 16:53:59 +00:00
|
|
|
*
|
|
|
|
* Sets a menu model from which @bar should take
|
|
|
|
* its contents.
|
|
|
|
*/
|
2019-06-09 16:04:12 +00:00
|
|
|
void
|
2019-06-09 16:19:07 +00:00
|
|
|
gtk_popover_menu_bar_set_menu_model (GtkPopoverMenuBar *bar,
|
|
|
|
GMenuModel *model)
|
2019-06-09 16:04:12 +00:00
|
|
|
{
|
2019-06-09 16:19:07 +00:00
|
|
|
g_return_if_fail (GTK_IS_POPOVER_MENU_BAR (bar));
|
2019-06-09 16:04:12 +00:00
|
|
|
g_return_if_fail (G_IS_MENU_MODEL (model));
|
|
|
|
|
|
|
|
if (g_set_object (&bar->model, model))
|
|
|
|
{
|
|
|
|
GtkWidget *child;
|
|
|
|
GtkActionMuxer *muxer;
|
|
|
|
|
|
|
|
while ((child = gtk_widget_get_first_child (GTK_WIDGET (bar))))
|
2020-02-20 18:26:44 +00:00
|
|
|
gtk_widget_unparent (child);
|
2019-06-09 16:04:12 +00:00
|
|
|
|
|
|
|
g_clear_pointer (&bar->tracker, gtk_menu_tracker_free);
|
|
|
|
|
2019-11-11 10:58:43 +00:00
|
|
|
if (model)
|
|
|
|
{
|
|
|
|
muxer = _gtk_widget_get_action_muxer (GTK_WIDGET (bar), TRUE);
|
|
|
|
bar->tracker = gtk_menu_tracker_new (GTK_ACTION_OBSERVABLE (muxer),
|
|
|
|
model,
|
|
|
|
FALSE,
|
|
|
|
TRUE,
|
|
|
|
FALSE,
|
|
|
|
NULL,
|
|
|
|
tracker_insert,
|
|
|
|
tracker_remove,
|
|
|
|
bar);
|
|
|
|
}
|
2019-06-09 16:04:12 +00:00
|
|
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (bar), bar_props[PROP_MENU_MODEL]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-09 16:53:59 +00:00
|
|
|
/**
|
2021-02-27 05:16:13 +00:00
|
|
|
* gtk_popover_menu_bar_get_menu_model: (attributes org.gtk.Method.get_property=menu-model)
|
|
|
|
* @bar: a `GtkPopoverMenuBar`
|
2019-06-09 16:53:59 +00:00
|
|
|
*
|
|
|
|
* Returns the model from which the contents of @bar are taken.
|
|
|
|
*
|
2022-01-01 16:45:08 +00:00
|
|
|
* Returns: (transfer none) (nullable): a `GMenuModel`
|
2019-06-09 16:53:59 +00:00
|
|
|
*/
|
2019-06-09 16:04:12 +00:00
|
|
|
GMenuModel *
|
2019-06-09 16:19:07 +00:00
|
|
|
gtk_popover_menu_bar_get_menu_model (GtkPopoverMenuBar *bar)
|
2019-06-09 16:04:12 +00:00
|
|
|
{
|
2019-06-09 16:19:07 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_POPOVER_MENU_BAR (bar), NULL);
|
2019-06-09 16:04:12 +00:00
|
|
|
|
|
|
|
return bar->model;
|
|
|
|
}
|
2019-12-27 13:45:21 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2020-10-20 18:26:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_popover_menu_bar_add_child:
|
2021-02-27 05:16:13 +00:00
|
|
|
* @bar: a `GtkPopoverMenuBar`
|
|
|
|
* @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 menubar.
|
|
|
|
*
|
|
|
|
* For this to work, the menu model of @bar must have an
|
|
|
|
* item with a `custom` attribute that matches @id.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if @id was found and the widget added
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gtk_popover_menu_bar_add_child (GtkPopoverMenuBar *bar,
|
|
|
|
GtkWidget *child,
|
|
|
|
const char *id)
|
|
|
|
{
|
|
|
|
GtkWidget *item;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_POPOVER_MENU_BAR (bar), FALSE);
|
|
|
|
g_return_val_if_fail (GTK_IS_WIDGET (child), FALSE);
|
|
|
|
g_return_val_if_fail (id != NULL, FALSE);
|
|
|
|
|
|
|
|
for (item = gtk_widget_get_first_child (GTK_WIDGET (bar));
|
|
|
|
item;
|
|
|
|
item = gtk_widget_get_next_sibling (item))
|
|
|
|
{
|
|
|
|
GtkPopover *popover = GTK_POPOVER_MENU_BAR_ITEM (item)->popover;
|
|
|
|
|
|
|
|
if (gtk_popover_menu_add_child (GTK_POPOVER_MENU (popover), child, id))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_popover_menu_bar_remove_child:
|
2021-02-27 05:16:13 +00:00
|
|
|
* @bar: a `GtkPopoverMenuBar`
|
2021-05-20 13:17:04 +00:00
|
|
|
* @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_bar_add_child().
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the widget was removed
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gtk_popover_menu_bar_remove_child (GtkPopoverMenuBar *bar,
|
|
|
|
GtkWidget *child)
|
|
|
|
{
|
|
|
|
GtkWidget *item;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_POPOVER_MENU_BAR (bar), FALSE);
|
|
|
|
g_return_val_if_fail (GTK_IS_WIDGET (child), FALSE);
|
|
|
|
|
|
|
|
for (item = gtk_widget_get_first_child (GTK_WIDGET (bar));
|
|
|
|
item;
|
|
|
|
item = gtk_widget_get_next_sibling (item))
|
|
|
|
{
|
|
|
|
GtkPopover *popover = GTK_POPOVER_MENU_BAR_ITEM (item)->popover;
|
|
|
|
|
|
|
|
if (gtk_popover_menu_remove_child (GTK_POPOVER_MENU (popover), child))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|