2012-05-29 17:39:37 +00:00
|
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2003 Ricardo Fernandez Pascual
|
|
|
|
|
* Copyright (C) 2004 Paolo Borelli
|
|
|
|
|
* Copyright (C) 2012 Bastien Nocera
|
|
|
|
|
*
|
|
|
|
|
* 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/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* SECTION:gtkmenubutton
|
2014-02-08 00:21:49 +00:00
|
|
|
|
* @short_description: A widget that shows a popup when clicked on
|
2012-07-14 03:05:36 +00:00
|
|
|
|
* @title: GtkMenuButton
|
2012-05-29 17:39:37 +00:00
|
|
|
|
*
|
2014-02-08 00:21:49 +00:00
|
|
|
|
* The #GtkMenuButton widget is used to display a popup when clicked on.
|
2019-12-30 01:16:52 +00:00
|
|
|
|
* This popup can be provided either as a #GtkPopover or as an abstract
|
|
|
|
|
* #GMenuModel.
|
2012-05-29 17:39:37 +00:00
|
|
|
|
*
|
2019-05-18 04:56:30 +00:00
|
|
|
|
* The #GtkMenuButton widget can show either an icon (set with the
|
|
|
|
|
* #GtkMenuButton:icon-name property) or a label (set with the
|
|
|
|
|
* #GtkMenuButton:label property). If neither is explicitly set,
|
2014-07-20 08:29:09 +00:00
|
|
|
|
* a #GtkImage is automatically created, using an arrow image oriented
|
2017-10-08 20:07:55 +00:00
|
|
|
|
* according to #GtkMenuButton:direction or the generic “open-menu-symbolic”
|
2014-07-20 08:29:09 +00:00
|
|
|
|
* icon if the direction is not set.
|
2012-08-07 02:26:13 +00:00
|
|
|
|
*
|
2014-02-08 00:21:49 +00:00
|
|
|
|
* The positioning of the popup is determined by the #GtkMenuButton:direction
|
|
|
|
|
* property of the menu button.
|
|
|
|
|
*
|
|
|
|
|
* For menus, the #GtkWidget:halign and #GtkWidget:valign properties of the
|
|
|
|
|
* menu are also taken into account. For example, when the direction is
|
|
|
|
|
* %GTK_ARROW_DOWN and the horizontal alignment is %GTK_ALIGN_START, the
|
|
|
|
|
* menu will be positioned below the button, with the starting edge
|
|
|
|
|
* (depending on the text direction) of the menu aligned with the starting
|
|
|
|
|
* edge of the button. If there is not enough space below the button, the
|
|
|
|
|
* menu is popped up above the button instead. If the alignment would move
|
|
|
|
|
* part of the menu offscreen, it is “pushed in”.
|
2012-08-07 02:26:13 +00:00
|
|
|
|
*
|
2014-02-05 01:00:53 +00:00
|
|
|
|
* ## Direction = Down
|
|
|
|
|
*
|
|
|
|
|
* - halign = start
|
|
|
|
|
*
|
|
|
|
|
* ![](down-start.png)
|
|
|
|
|
*
|
|
|
|
|
* - halign = center
|
|
|
|
|
*
|
|
|
|
|
* ![](down-center.png)
|
|
|
|
|
*
|
|
|
|
|
* - halign = end
|
|
|
|
|
*
|
|
|
|
|
* ![](down-end.png)
|
|
|
|
|
*
|
|
|
|
|
* ## Direction = Up
|
|
|
|
|
*
|
|
|
|
|
* - halign = start
|
|
|
|
|
*
|
|
|
|
|
* ![](up-start.png)
|
|
|
|
|
*
|
|
|
|
|
* - halign = center
|
|
|
|
|
*
|
|
|
|
|
* ![](up-center.png)
|
|
|
|
|
*
|
|
|
|
|
* - halign = end
|
|
|
|
|
*
|
|
|
|
|
* ![](up-end.png)
|
|
|
|
|
*
|
|
|
|
|
* ## Direction = Left
|
|
|
|
|
*
|
|
|
|
|
* - valign = start
|
|
|
|
|
*
|
|
|
|
|
* ![](left-start.png)
|
|
|
|
|
*
|
|
|
|
|
* - valign = center
|
|
|
|
|
*
|
|
|
|
|
* ![](left-center.png)
|
|
|
|
|
*
|
|
|
|
|
* - valign = end
|
|
|
|
|
*
|
|
|
|
|
* ![](left-end.png)
|
|
|
|
|
*
|
|
|
|
|
* ## Direction = Right
|
|
|
|
|
*
|
|
|
|
|
* - valign = start
|
|
|
|
|
*
|
|
|
|
|
* ![](right-start.png)
|
|
|
|
|
*
|
|
|
|
|
* - valign = center
|
|
|
|
|
*
|
|
|
|
|
* ![](right-center.png)
|
|
|
|
|
*
|
|
|
|
|
* - valign = end
|
|
|
|
|
*
|
|
|
|
|
* ![](right-end.png)
|
|
|
|
|
*
|
2015-10-30 04:54:37 +00:00
|
|
|
|
* # CSS nodes
|
|
|
|
|
*
|
|
|
|
|
* GtkMenuButton has a single CSS node with name button. To differentiate
|
2015-10-30 05:21:13 +00:00
|
|
|
|
* it from a plain #GtkButton, it gets the .popup style class.
|
2012-05-29 17:39:37 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
2019-03-16 03:48:26 +00:00
|
|
|
|
#include "gtkaccessible.h"
|
2018-02-25 10:29:33 +00:00
|
|
|
|
#include "gtkactionable.h"
|
2019-03-16 03:48:26 +00:00
|
|
|
|
#include "gtkimage.h"
|
|
|
|
|
#include "gtkintl.h"
|
2012-09-24 04:01:39 +00:00
|
|
|
|
#include "gtkmain.h"
|
2019-03-16 03:48:26 +00:00
|
|
|
|
#include "gtkmenubutton.h"
|
|
|
|
|
#include "gtkmenubuttonprivate.h"
|
2014-02-08 00:21:49 +00:00
|
|
|
|
#include "gtkpopover.h"
|
2019-06-07 17:05:48 +00:00
|
|
|
|
#include "gtkpopovermenu.h"
|
2012-05-29 17:39:37 +00:00
|
|
|
|
#include "gtkprivate.h"
|
2019-03-16 03:48:26 +00:00
|
|
|
|
#include "gtkstylecontext.h"
|
|
|
|
|
#include "gtktypebuiltins.h"
|
2019-05-18 04:56:30 +00:00
|
|
|
|
#include "gtklabel.h"
|
|
|
|
|
#include "gtkbox.h"
|
2019-04-26 23:17:37 +00:00
|
|
|
|
#include "gtkwidgetprivate.h"
|
|
|
|
|
#include "gtkbuttonprivate.h"
|
|
|
|
|
#include "gtknative.h"
|
2019-03-16 03:48:26 +00:00
|
|
|
|
|
|
|
|
|
#include "a11y/gtkmenubuttonaccessible.h"
|
2012-05-29 17:39:37 +00:00
|
|
|
|
|
2019-05-27 03:10:57 +00:00
|
|
|
|
typedef struct _GtkMenuButtonClass GtkMenuButtonClass;
|
|
|
|
|
typedef struct _GtkMenuButtonPrivate GtkMenuButtonPrivate;
|
|
|
|
|
|
|
|
|
|
struct _GtkMenuButton
|
|
|
|
|
{
|
|
|
|
|
GtkWidget parent_instance;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct _GtkMenuButtonClass
|
|
|
|
|
{
|
|
|
|
|
GtkWidgetClass parent_class;
|
|
|
|
|
};
|
|
|
|
|
|
2012-05-29 17:39:37 +00:00
|
|
|
|
struct _GtkMenuButtonPrivate
|
|
|
|
|
{
|
2019-05-18 04:56:30 +00:00
|
|
|
|
GtkWidget *button;
|
2014-02-08 00:21:49 +00:00
|
|
|
|
GtkWidget *popover; /* Only one at a time can be set */
|
2012-05-29 17:39:37 +00:00
|
|
|
|
GMenuModel *model;
|
|
|
|
|
|
2019-08-22 07:06:43 +00:00
|
|
|
|
GtkMenuButtonCreatePopupFunc create_popup_func;
|
|
|
|
|
gpointer create_popup_user_data;
|
|
|
|
|
GDestroyNotify create_popup_destroy_notify;
|
2012-05-29 17:39:37 +00:00
|
|
|
|
|
|
|
|
|
GtkWidget *align_widget;
|
2014-07-20 12:12:30 +00:00
|
|
|
|
GtkWidget *arrow_widget;
|
2013-09-22 03:37:48 +00:00
|
|
|
|
GtkArrowType arrow_type;
|
2012-05-29 17:39:37 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
PROP_0,
|
2014-02-22 17:08:45 +00:00
|
|
|
|
PROP_MENU_MODEL,
|
2012-05-29 17:39:37 +00:00
|
|
|
|
PROP_ALIGN_WIDGET,
|
2014-02-08 00:21:49 +00:00
|
|
|
|
PROP_DIRECTION,
|
2015-09-06 20:10:48 +00:00
|
|
|
|
PROP_POPOVER,
|
2019-05-18 04:56:30 +00:00
|
|
|
|
PROP_ICON_NAME,
|
|
|
|
|
PROP_LABEL,
|
2019-05-21 22:39:03 +00:00
|
|
|
|
PROP_RELIEF,
|
2015-09-06 20:10:48 +00:00
|
|
|
|
LAST_PROP
|
2012-05-29 17:39:37 +00:00
|
|
|
|
};
|
|
|
|
|
|
2015-09-06 20:10:48 +00:00
|
|
|
|
static GParamSpec *menu_button_props[LAST_PROP];
|
|
|
|
|
|
2019-05-18 04:56:30 +00:00
|
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GtkMenuButton, gtk_menu_button, GTK_TYPE_WIDGET)
|
2012-05-29 17:39:37 +00:00
|
|
|
|
|
2012-07-29 16:43:26 +00:00
|
|
|
|
static void gtk_menu_button_dispose (GObject *object);
|
2012-05-29 17:39:37 +00:00
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_menu_button_set_property (GObject *object,
|
2012-07-14 03:05:36 +00:00
|
|
|
|
guint property_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
2012-05-29 17:39:37 +00:00
|
|
|
|
{
|
|
|
|
|
GtkMenuButton *self = GTK_MENU_BUTTON (object);
|
|
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
|
{
|
2014-02-22 17:08:45 +00:00
|
|
|
|
case PROP_MENU_MODEL:
|
2012-05-29 17:39:37 +00:00
|
|
|
|
gtk_menu_button_set_menu_model (self, g_value_get_object (value));
|
|
|
|
|
break;
|
|
|
|
|
case PROP_ALIGN_WIDGET:
|
|
|
|
|
gtk_menu_button_set_align_widget (self, g_value_get_object (value));
|
|
|
|
|
break;
|
|
|
|
|
case PROP_DIRECTION:
|
|
|
|
|
gtk_menu_button_set_direction (self, g_value_get_enum (value));
|
|
|
|
|
break;
|
2014-02-08 00:21:49 +00:00
|
|
|
|
case PROP_POPOVER:
|
|
|
|
|
gtk_menu_button_set_popover (self, g_value_get_object (value));
|
|
|
|
|
break;
|
2019-05-18 04:56:30 +00:00
|
|
|
|
case PROP_ICON_NAME:
|
|
|
|
|
gtk_menu_button_set_icon_name (self, g_value_get_string (value));
|
|
|
|
|
break;
|
|
|
|
|
case PROP_LABEL:
|
|
|
|
|
gtk_menu_button_set_label (self, g_value_get_string (value));
|
|
|
|
|
break;
|
2019-05-21 22:39:03 +00:00
|
|
|
|
case PROP_RELIEF:
|
|
|
|
|
gtk_menu_button_set_relief (self, g_value_get_enum (value));
|
|
|
|
|
break;
|
2012-05-29 17:39:37 +00:00
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_menu_button_get_property (GObject *object,
|
2012-07-14 03:05:36 +00:00
|
|
|
|
guint property_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
2012-05-29 17:39:37 +00:00
|
|
|
|
{
|
2018-03-07 19:26:51 +00:00
|
|
|
|
GtkMenuButtonPrivate *priv = gtk_menu_button_get_instance_private (GTK_MENU_BUTTON (object));
|
2012-05-29 17:39:37 +00:00
|
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
|
{
|
2014-02-22 17:08:45 +00:00
|
|
|
|
case PROP_MENU_MODEL:
|
2012-05-29 17:39:37 +00:00
|
|
|
|
g_value_set_object (value, priv->model);
|
|
|
|
|
break;
|
|
|
|
|
case PROP_ALIGN_WIDGET:
|
|
|
|
|
g_value_set_object (value, priv->align_widget);
|
|
|
|
|
break;
|
|
|
|
|
case PROP_DIRECTION:
|
|
|
|
|
g_value_set_enum (value, priv->arrow_type);
|
|
|
|
|
break;
|
2014-02-08 00:21:49 +00:00
|
|
|
|
case PROP_POPOVER:
|
|
|
|
|
g_value_set_object (value, priv->popover);
|
|
|
|
|
break;
|
2019-05-18 04:56:30 +00:00
|
|
|
|
case PROP_ICON_NAME:
|
|
|
|
|
g_value_set_string (value, gtk_menu_button_get_icon_name (GTK_MENU_BUTTON (object)));
|
|
|
|
|
break;
|
|
|
|
|
case PROP_LABEL:
|
|
|
|
|
g_value_set_string (value, gtk_menu_button_get_label (GTK_MENU_BUTTON (object)));
|
|
|
|
|
break;
|
2019-05-21 22:39:03 +00:00
|
|
|
|
case PROP_RELIEF:
|
|
|
|
|
g_value_set_enum (value, gtk_menu_button_get_relief (GTK_MENU_BUTTON (object)));
|
|
|
|
|
break;
|
2012-05-29 17:39:37 +00:00
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_menu_button_state_flags_changed (GtkWidget *widget,
|
|
|
|
|
GtkStateFlags previous_state_flags)
|
|
|
|
|
{
|
|
|
|
|
GtkMenuButton *button = GTK_MENU_BUTTON (widget);
|
2018-03-07 19:26:51 +00:00
|
|
|
|
GtkMenuButtonPrivate *priv = gtk_menu_button_get_instance_private (button);
|
2012-05-29 17:39:37 +00:00
|
|
|
|
|
2014-02-08 00:21:49 +00:00
|
|
|
|
if (!gtk_widget_is_sensitive (widget))
|
|
|
|
|
{
|
2019-12-27 03:41:47 +00:00
|
|
|
|
if (priv->popover)
|
2014-02-08 00:21:49 +00:00
|
|
|
|
gtk_widget_hide (priv->popover);
|
|
|
|
|
}
|
2012-05-29 17:39:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2019-05-18 04:56:30 +00:00
|
|
|
|
gtk_menu_button_toggled (GtkMenuButton *menu_button)
|
2012-05-29 17:39:37 +00:00
|
|
|
|
{
|
2018-03-07 19:26:51 +00:00
|
|
|
|
GtkMenuButtonPrivate *priv = gtk_menu_button_get_instance_private (menu_button);
|
2019-08-22 07:06:43 +00:00
|
|
|
|
const gboolean active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->button));
|
|
|
|
|
|
|
|
|
|
/* Might set a new menu/popover */
|
|
|
|
|
if (active && priv->create_popup_func)
|
|
|
|
|
{
|
|
|
|
|
priv->create_popup_func (menu_button, priv->create_popup_user_data);
|
|
|
|
|
}
|
2015-07-23 12:26:25 +00:00
|
|
|
|
|
2019-12-27 03:41:47 +00:00
|
|
|
|
if (priv->popover)
|
2015-06-15 23:42:47 +00:00
|
|
|
|
{
|
|
|
|
|
if (active)
|
2016-08-10 17:18:27 +00:00
|
|
|
|
gtk_popover_popup (GTK_POPOVER (priv->popover));
|
2015-06-15 23:42:47 +00:00
|
|
|
|
else
|
2016-08-10 17:18:27 +00:00
|
|
|
|
gtk_popover_popdown (GTK_POPOVER (priv->popover));
|
2012-05-29 17:39:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-25 03:32:41 +00:00
|
|
|
|
static void
|
2019-05-18 04:56:30 +00:00
|
|
|
|
gtk_menu_button_measure (GtkWidget *widget,
|
|
|
|
|
GtkOrientation orientation,
|
|
|
|
|
int for_size,
|
|
|
|
|
int *minimum,
|
|
|
|
|
int *natural,
|
|
|
|
|
int *minimum_baseline,
|
|
|
|
|
int *natural_baseline)
|
2012-08-25 03:32:41 +00:00
|
|
|
|
{
|
2019-05-18 04:56:30 +00:00
|
|
|
|
GtkMenuButton *menu_button = GTK_MENU_BUTTON (widget);
|
|
|
|
|
GtkMenuButtonPrivate *priv = gtk_menu_button_get_instance_private (menu_button);
|
2012-08-25 03:32:41 +00:00
|
|
|
|
|
2019-05-18 04:56:30 +00:00
|
|
|
|
gtk_widget_measure (priv->button,
|
|
|
|
|
orientation,
|
|
|
|
|
for_size,
|
|
|
|
|
minimum, natural,
|
|
|
|
|
minimum_baseline, natural_baseline);
|
2012-08-25 03:32:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-04 13:38:28 +00:00
|
|
|
|
static void
|
2019-05-18 04:56:30 +00:00
|
|
|
|
gtk_menu_button_size_allocate (GtkWidget *widget,
|
|
|
|
|
int width,
|
|
|
|
|
int height,
|
|
|
|
|
int baseline)
|
2012-09-04 13:38:28 +00:00
|
|
|
|
{
|
2019-04-26 23:17:37 +00:00
|
|
|
|
GtkMenuButton *button = GTK_MENU_BUTTON (widget);
|
|
|
|
|
GtkMenuButtonPrivate *priv = gtk_menu_button_get_instance_private (button);
|
2012-09-04 13:38:28 +00:00
|
|
|
|
|
2019-05-18 04:56:30 +00:00
|
|
|
|
gtk_widget_size_allocate (priv->button,
|
|
|
|
|
&(GtkAllocation) { 0, 0, width, height },
|
|
|
|
|
baseline);
|
2019-04-26 23:17:37 +00:00
|
|
|
|
|
|
|
|
|
if (priv->popover)
|
|
|
|
|
gtk_native_check_resize (GTK_NATIVE (priv->popover));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
gtk_menu_button_focus (GtkWidget *widget,
|
|
|
|
|
GtkDirectionType direction)
|
|
|
|
|
{
|
|
|
|
|
GtkMenuButton *button = GTK_MENU_BUTTON (widget);
|
|
|
|
|
GtkMenuButtonPrivate *priv = gtk_menu_button_get_instance_private (button);
|
|
|
|
|
|
2019-12-27 03:41:47 +00:00
|
|
|
|
if (priv->popover && gtk_widget_get_visible (priv->popover))
|
2019-06-09 02:19:30 +00:00
|
|
|
|
return gtk_widget_child_focus (priv->popover, direction);
|
2019-04-26 23:17:37 +00:00
|
|
|
|
else
|
|
|
|
|
return GTK_WIDGET_CLASS (gtk_menu_button_parent_class)->focus (widget, direction);
|
2012-09-04 13:38:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-05-29 17:39:37 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_menu_button_class_init (GtkMenuButtonClass *klass)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
|
|
|
|
|
gobject_class->set_property = gtk_menu_button_set_property;
|
|
|
|
|
gobject_class->get_property = gtk_menu_button_get_property;
|
2012-07-29 16:43:26 +00:00
|
|
|
|
gobject_class->dispose = gtk_menu_button_dispose;
|
2012-05-29 17:39:37 +00:00
|
|
|
|
|
2019-05-18 04:56:30 +00:00
|
|
|
|
widget_class->measure = gtk_menu_button_measure;
|
|
|
|
|
widget_class->size_allocate = gtk_menu_button_size_allocate;
|
2019-04-26 23:17:37 +00:00
|
|
|
|
widget_class->state_flags_changed = gtk_menu_button_state_flags_changed;
|
|
|
|
|
widget_class->focus = gtk_menu_button_focus;
|
2012-05-29 17:39:37 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* GtkMenuButton:menu-model:
|
|
|
|
|
*
|
2014-02-08 00:21:49 +00:00
|
|
|
|
* The #GMenuModel from which the popup will be created.
|
|
|
|
|
*
|
2012-05-29 17:39:37 +00:00
|
|
|
|
* See gtk_menu_button_set_menu_model() for the interaction with the
|
2013-01-13 13:25:37 +00:00
|
|
|
|
* #GtkMenuButton:popup property.
|
2012-05-29 17:39:37 +00:00
|
|
|
|
*/
|
2015-09-06 20:10:48 +00:00
|
|
|
|
menu_button_props[PROP_MENU_MODEL] =
|
|
|
|
|
g_param_spec_object ("menu-model",
|
|
|
|
|
P_("Menu model"),
|
|
|
|
|
P_("The model from which the popup is made."),
|
|
|
|
|
G_TYPE_MENU_MODEL,
|
|
|
|
|
GTK_PARAM_READWRITE);
|
|
|
|
|
|
2012-05-29 17:39:37 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkMenuButton:align-widget:
|
|
|
|
|
*
|
2014-02-08 00:21:49 +00:00
|
|
|
|
* The #GtkWidget to use to align the menu with.
|
2012-05-29 17:39:37 +00:00
|
|
|
|
*/
|
2015-09-06 20:10:48 +00:00
|
|
|
|
menu_button_props[PROP_ALIGN_WIDGET] =
|
|
|
|
|
g_param_spec_object ("align-widget",
|
|
|
|
|
P_("Align with"),
|
|
|
|
|
P_("The parent widget which the menu should align with."),
|
|
|
|
|
GTK_TYPE_CONTAINER,
|
|
|
|
|
GTK_PARAM_READWRITE);
|
|
|
|
|
|
2012-05-29 17:39:37 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkMenuButton:direction:
|
|
|
|
|
*
|
|
|
|
|
* The #GtkArrowType representing the direction in which the
|
2014-02-08 00:21:49 +00:00
|
|
|
|
* menu or popover will be popped out.
|
2012-05-29 17:39:37 +00:00
|
|
|
|
*/
|
2015-09-06 20:10:48 +00:00
|
|
|
|
menu_button_props[PROP_DIRECTION] =
|
|
|
|
|
g_param_spec_enum ("direction",
|
|
|
|
|
P_("Direction"),
|
|
|
|
|
P_("The direction the arrow should point."),
|
|
|
|
|
GTK_TYPE_ARROW_TYPE,
|
|
|
|
|
GTK_ARROW_DOWN,
|
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
2014-06-09 13:06:49 +00:00
|
|
|
|
|
2014-02-08 00:21:49 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkMenuButton:popover:
|
|
|
|
|
*
|
|
|
|
|
* The #GtkPopover that will be popped up when the button is clicked.
|
|
|
|
|
*/
|
2015-09-06 20:10:48 +00:00
|
|
|
|
menu_button_props[PROP_POPOVER] =
|
|
|
|
|
g_param_spec_object ("popover",
|
|
|
|
|
P_("Popover"),
|
|
|
|
|
P_("The popover"),
|
|
|
|
|
GTK_TYPE_POPOVER,
|
|
|
|
|
G_PARAM_READWRITE);
|
2014-02-08 00:21:49 +00:00
|
|
|
|
|
2019-05-18 04:56:30 +00:00
|
|
|
|
menu_button_props[PROP_ICON_NAME] =
|
|
|
|
|
g_param_spec_string ("icon-name",
|
|
|
|
|
P_("Icon Name"),
|
|
|
|
|
P_("The name of the icon used to automatically populate the button"),
|
|
|
|
|
NULL,
|
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
|
|
|
|
|
menu_button_props[PROP_LABEL] =
|
|
|
|
|
g_param_spec_string ("label",
|
|
|
|
|
P_("Label"),
|
|
|
|
|
P_("The label for the button"),
|
|
|
|
|
NULL,
|
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
|
2019-05-21 22:39:03 +00:00
|
|
|
|
menu_button_props[PROP_RELIEF] =
|
|
|
|
|
g_param_spec_enum ("relief",
|
|
|
|
|
P_("Border relief"),
|
|
|
|
|
P_("The border relief style"),
|
|
|
|
|
GTK_TYPE_RELIEF_STYLE,
|
|
|
|
|
GTK_RELIEF_NORMAL,
|
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
|
2015-09-06 20:10:48 +00:00
|
|
|
|
g_object_class_install_properties (gobject_class, LAST_PROP, menu_button_props);
|
2013-12-20 15:58:32 +00:00
|
|
|
|
|
|
|
|
|
gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_MENU_BUTTON_ACCESSIBLE);
|
2019-05-18 04:56:30 +00:00
|
|
|
|
gtk_widget_class_set_css_name (widget_class, I_("menubutton"));
|
2012-05-29 17:39:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-13 03:49:28 +00:00
|
|
|
|
static void
|
|
|
|
|
set_arrow_type (GtkImage *image,
|
|
|
|
|
GtkArrowType arrow_type)
|
|
|
|
|
{
|
|
|
|
|
switch (arrow_type)
|
|
|
|
|
{
|
|
|
|
|
case GTK_ARROW_NONE:
|
2017-11-15 00:43:13 +00:00
|
|
|
|
gtk_image_set_from_icon_name (image, "open-menu-symbolic");
|
2014-07-08 12:35:33 +00:00
|
|
|
|
break;
|
2014-05-13 03:49:28 +00:00
|
|
|
|
case GTK_ARROW_DOWN:
|
2017-11-15 00:43:13 +00:00
|
|
|
|
gtk_image_set_from_icon_name (image, "pan-down-symbolic");
|
2014-05-13 03:49:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_ARROW_UP:
|
2017-11-15 00:43:13 +00:00
|
|
|
|
gtk_image_set_from_icon_name (image, "pan-up-symbolic");
|
2014-05-13 03:49:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_ARROW_LEFT:
|
2017-11-15 00:43:13 +00:00
|
|
|
|
gtk_image_set_from_icon_name (image, "pan-start-symbolic");
|
2014-05-13 03:49:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_ARROW_RIGHT:
|
2017-11-15 00:43:13 +00:00
|
|
|
|
gtk_image_set_from_icon_name (image, "pan-end-symbolic");
|
2014-05-13 03:49:28 +00:00
|
|
|
|
break;
|
2017-10-06 19:19:42 +00:00
|
|
|
|
default:
|
|
|
|
|
break;
|
2014-05-13 03:49:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-29 17:39:37 +00:00
|
|
|
|
static void
|
|
|
|
|
add_arrow (GtkMenuButton *menu_button)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *arrow;
|
2018-03-07 19:26:51 +00:00
|
|
|
|
GtkMenuButtonPrivate *priv = gtk_menu_button_get_instance_private (menu_button);
|
2014-12-15 09:29:11 +00:00
|
|
|
|
|
2014-05-13 03:49:28 +00:00
|
|
|
|
arrow = gtk_image_new ();
|
2018-03-07 19:26:51 +00:00
|
|
|
|
set_arrow_type (GTK_IMAGE (arrow), priv->arrow_type);
|
2019-05-18 04:56:30 +00:00
|
|
|
|
gtk_container_add (GTK_CONTAINER (priv->button), arrow);
|
2018-03-07 19:26:51 +00:00
|
|
|
|
priv->arrow_widget = arrow;
|
2012-05-29 17:39:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_menu_button_init (GtkMenuButton *menu_button)
|
|
|
|
|
{
|
2018-03-07 19:26:51 +00:00
|
|
|
|
GtkMenuButtonPrivate *priv = gtk_menu_button_get_instance_private (menu_button);
|
2012-05-29 17:39:37 +00:00
|
|
|
|
|
|
|
|
|
priv->arrow_type = GTK_ARROW_DOWN;
|
|
|
|
|
|
2019-05-18 04:56:30 +00:00
|
|
|
|
priv->button = gtk_toggle_button_new ();
|
|
|
|
|
gtk_widget_set_parent (priv->button, GTK_WIDGET (menu_button));
|
|
|
|
|
g_signal_connect_swapped (priv->button, "toggled", G_CALLBACK (gtk_menu_button_toggled), menu_button);
|
2012-09-01 03:10:30 +00:00
|
|
|
|
add_arrow (menu_button);
|
|
|
|
|
|
2019-08-25 12:15:12 +00:00
|
|
|
|
gtk_widget_set_sensitive (priv->button, FALSE);
|
2015-10-30 04:54:37 +00:00
|
|
|
|
|
2020-02-06 16:32:26 +00:00
|
|
|
|
gtk_widget_add_css_class (GTK_WIDGET (menu_button), "popup");
|
2012-05-29 17:39:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_menu_button_new:
|
|
|
|
|
*
|
|
|
|
|
* Creates a new #GtkMenuButton widget with downwards-pointing
|
|
|
|
|
* arrow as the only child. You can replace the child widget
|
|
|
|
|
* with another #GtkWidget should you wish to.
|
|
|
|
|
*
|
2014-02-08 00:21:49 +00:00
|
|
|
|
* Returns: The newly created #GtkMenuButton widget
|
2012-05-29 17:39:37 +00:00
|
|
|
|
*/
|
|
|
|
|
GtkWidget *
|
|
|
|
|
gtk_menu_button_new (void)
|
|
|
|
|
{
|
|
|
|
|
return g_object_new (GTK_TYPE_MENU_BUTTON, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-09 19:30:52 +00:00
|
|
|
|
static void
|
|
|
|
|
update_sensitivity (GtkMenuButton *menu_button)
|
|
|
|
|
{
|
2018-03-07 19:26:51 +00:00
|
|
|
|
GtkMenuButtonPrivate *priv = gtk_menu_button_get_instance_private (menu_button);
|
2014-10-09 19:30:52 +00:00
|
|
|
|
|
2019-08-25 12:15:12 +00:00
|
|
|
|
gtk_widget_set_sensitive (priv->button,
|
2019-08-22 07:06:43 +00:00
|
|
|
|
priv->popover != NULL ||
|
|
|
|
|
priv->create_popup_func != NULL);
|
2014-10-09 19:30:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-27 03:41:47 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
menu_deactivate_cb (GtkMenuButton *menu_button)
|
2012-05-29 17:39:37 +00:00
|
|
|
|
{
|
2018-03-07 19:26:51 +00:00
|
|
|
|
GtkMenuButtonPrivate *priv = gtk_menu_button_get_instance_private (menu_button);
|
|
|
|
|
|
2019-12-27 03:41:47 +00:00
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->button), FALSE);
|
2012-05-29 17:39:37 +00:00
|
|
|
|
|
2019-12-27 03:41:47 +00:00
|
|
|
|
return TRUE;
|
2012-08-20 21:03:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-05-29 17:39:37 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_menu_button_set_menu_model:
|
|
|
|
|
* @menu_button: a #GtkMenuButton
|
2018-04-22 15:02:55 +00:00
|
|
|
|
* @menu_model: (nullable): a #GMenuModel, or %NULL to unset and disable the
|
|
|
|
|
* button
|
2012-05-29 17:39:37 +00:00
|
|
|
|
*
|
2014-02-08 00:21:49 +00:00
|
|
|
|
* Sets the #GMenuModel from which the popup will be constructed,
|
2018-04-22 15:02:55 +00:00
|
|
|
|
* or %NULL to dissociate any existing menu model and disable the button.
|
2012-05-29 17:39:37 +00:00
|
|
|
|
*
|
2019-12-30 01:16:52 +00:00
|
|
|
|
* A #GtkPopover will be created from the menu model with gtk_popover_menu_new_from_model().
|
2019-12-27 03:41:47 +00:00
|
|
|
|
* Actions will be connected as documented for this function.
|
2012-05-29 17:39:37 +00:00
|
|
|
|
*
|
2019-12-27 03:41:47 +00:00
|
|
|
|
* If #GtkMenuButton:popover is already set, it will be dissociated from the @menu_button,
|
|
|
|
|
* and the property is set to %NULL.
|
2012-05-29 17:39:37 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_menu_button_set_menu_model (GtkMenuButton *menu_button,
|
2012-07-14 03:05:36 +00:00
|
|
|
|
GMenuModel *menu_model)
|
2012-05-29 17:39:37 +00:00
|
|
|
|
{
|
2018-03-07 19:26:51 +00:00
|
|
|
|
GtkMenuButtonPrivate *priv = gtk_menu_button_get_instance_private (menu_button);
|
2012-05-29 17:39:37 +00:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_MENU_BUTTON (menu_button));
|
|
|
|
|
g_return_if_fail (G_IS_MENU_MODEL (menu_model) || menu_model == NULL);
|
|
|
|
|
|
2014-02-22 17:36:55 +00:00
|
|
|
|
g_object_freeze_notify (G_OBJECT (menu_button));
|
2014-02-08 00:21:49 +00:00
|
|
|
|
|
2014-02-22 17:36:55 +00:00
|
|
|
|
if (menu_model)
|
|
|
|
|
g_object_ref (menu_model);
|
2014-02-08 00:21:49 +00:00
|
|
|
|
|
2014-02-22 17:36:55 +00:00
|
|
|
|
if (menu_model)
|
2012-05-29 17:39:37 +00:00
|
|
|
|
{
|
2019-12-27 03:41:47 +00:00
|
|
|
|
GtkWidget *popover;
|
2014-02-22 17:36:55 +00:00
|
|
|
|
|
2019-12-27 03:41:47 +00:00
|
|
|
|
popover = gtk_popover_menu_new_from_model (GTK_WIDGET (menu_button), menu_model);
|
|
|
|
|
gtk_menu_button_set_popover (menu_button, popover);
|
2012-05-29 17:39:37 +00:00
|
|
|
|
}
|
2014-02-08 00:21:49 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2014-02-22 17:36:55 +00:00
|
|
|
|
gtk_menu_button_set_popover (menu_button, NULL);
|
2014-02-08 00:21:49 +00:00
|
|
|
|
}
|
2014-02-22 17:36:55 +00:00
|
|
|
|
|
|
|
|
|
priv->model = menu_model;
|
2015-09-06 20:10:48 +00:00
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (menu_button), menu_button_props[PROP_MENU_MODEL]);
|
2014-02-22 17:36:55 +00:00
|
|
|
|
|
|
|
|
|
g_object_thaw_notify (G_OBJECT (menu_button));
|
2012-05-29 17:39:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_menu_button_get_menu_model:
|
|
|
|
|
* @menu_button: a #GtkMenuButton
|
|
|
|
|
*
|
2014-02-08 00:21:49 +00:00
|
|
|
|
* Returns the #GMenuModel used to generate the popup.
|
2012-05-29 17:39:37 +00:00
|
|
|
|
*
|
2015-12-28 20:14:08 +00:00
|
|
|
|
* Returns: (nullable) (transfer none): a #GMenuModel or %NULL
|
2012-05-29 17:39:37 +00:00
|
|
|
|
*/
|
|
|
|
|
GMenuModel *
|
|
|
|
|
gtk_menu_button_get_menu_model (GtkMenuButton *menu_button)
|
|
|
|
|
{
|
2018-03-07 19:26:51 +00:00
|
|
|
|
GtkMenuButtonPrivate *priv = gtk_menu_button_get_instance_private (menu_button);
|
|
|
|
|
|
2012-05-29 17:39:37 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_MENU_BUTTON (menu_button), NULL);
|
|
|
|
|
|
2018-03-07 19:26:51 +00:00
|
|
|
|
return priv->model;
|
2012-05-29 17:39:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-11-04 15:46:35 +00:00
|
|
|
|
static void
|
|
|
|
|
set_align_widget_pointer (GtkMenuButton *menu_button,
|
|
|
|
|
GtkWidget *align_widget)
|
|
|
|
|
{
|
2018-03-07 19:26:51 +00:00
|
|
|
|
GtkMenuButtonPrivate *priv = gtk_menu_button_get_instance_private (menu_button);
|
2012-11-04 15:46:35 +00:00
|
|
|
|
|
|
|
|
|
if (priv->align_widget)
|
|
|
|
|
g_object_remove_weak_pointer (G_OBJECT (priv->align_widget), (gpointer *) &priv->align_widget);
|
|
|
|
|
|
|
|
|
|
priv->align_widget = align_widget;
|
|
|
|
|
|
2015-03-22 15:44:37 +00:00
|
|
|
|
if (priv->align_widget)
|
2012-11-04 15:46:35 +00:00
|
|
|
|
g_object_add_weak_pointer (G_OBJECT (priv->align_widget), (gpointer *) &priv->align_widget);
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-29 17:39:37 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_menu_button_set_align_widget:
|
|
|
|
|
* @menu_button: a #GtkMenuButton
|
|
|
|
|
* @align_widget: (allow-none): a #GtkWidget
|
|
|
|
|
*
|
2014-02-08 00:21:49 +00:00
|
|
|
|
* Sets the #GtkWidget to use to line the menu with when popped up.
|
|
|
|
|
* Note that the @align_widget must contain the #GtkMenuButton itself.
|
2012-05-29 17:39:37 +00:00
|
|
|
|
*
|
2014-02-08 00:21:49 +00:00
|
|
|
|
* Setting it to %NULL means that the menu will be aligned with the
|
2012-05-29 17:39:37 +00:00
|
|
|
|
* button itself.
|
|
|
|
|
*
|
2014-02-08 00:21:49 +00:00
|
|
|
|
* Note that this property is only used with menus currently,
|
|
|
|
|
* and not for popovers.
|
2012-05-29 17:39:37 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_menu_button_set_align_widget (GtkMenuButton *menu_button,
|
2012-07-14 03:05:36 +00:00
|
|
|
|
GtkWidget *align_widget)
|
2012-05-29 17:39:37 +00:00
|
|
|
|
{
|
2018-03-07 19:26:51 +00:00
|
|
|
|
GtkMenuButtonPrivate *priv = gtk_menu_button_get_instance_private (menu_button);
|
2012-05-29 17:39:37 +00:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_MENU_BUTTON (menu_button));
|
|
|
|
|
g_return_if_fail (align_widget == NULL || gtk_widget_is_ancestor (GTK_WIDGET (menu_button), align_widget));
|
|
|
|
|
|
|
|
|
|
if (priv->align_widget == align_widget)
|
|
|
|
|
return;
|
|
|
|
|
|
2012-11-04 15:46:35 +00:00
|
|
|
|
set_align_widget_pointer (menu_button, align_widget);
|
2012-05-29 17:39:37 +00:00
|
|
|
|
|
2015-09-06 20:10:48 +00:00
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (menu_button), menu_button_props[PROP_ALIGN_WIDGET]);
|
2012-05-29 17:39:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_menu_button_get_align_widget:
|
|
|
|
|
* @menu_button: a #GtkMenuButton
|
|
|
|
|
*
|
|
|
|
|
* Returns the parent #GtkWidget to use to line up with menu.
|
|
|
|
|
*
|
2015-12-28 20:14:08 +00:00
|
|
|
|
* Returns: (nullable) (transfer none): a #GtkWidget value or %NULL
|
2012-05-29 17:39:37 +00:00
|
|
|
|
*/
|
|
|
|
|
GtkWidget *
|
|
|
|
|
gtk_menu_button_get_align_widget (GtkMenuButton *menu_button)
|
|
|
|
|
{
|
2018-03-07 19:26:51 +00:00
|
|
|
|
GtkMenuButtonPrivate *priv = gtk_menu_button_get_instance_private (menu_button);
|
|
|
|
|
|
2012-05-29 17:39:37 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_MENU_BUTTON (menu_button), NULL);
|
|
|
|
|
|
2018-03-07 19:26:51 +00:00
|
|
|
|
return priv->align_widget;
|
2012-05-29 17:39:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-08 00:21:49 +00:00
|
|
|
|
static void
|
|
|
|
|
update_popover_direction (GtkMenuButton *menu_button)
|
|
|
|
|
{
|
2018-03-07 19:26:51 +00:00
|
|
|
|
GtkMenuButtonPrivate *priv = gtk_menu_button_get_instance_private (menu_button);
|
2014-02-08 00:21:49 +00:00
|
|
|
|
|
|
|
|
|
if (!priv->popover)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
switch (priv->arrow_type)
|
|
|
|
|
{
|
|
|
|
|
case GTK_ARROW_UP:
|
|
|
|
|
gtk_popover_set_position (GTK_POPOVER (priv->popover), GTK_POS_TOP);
|
|
|
|
|
break;
|
|
|
|
|
case GTK_ARROW_DOWN:
|
|
|
|
|
case GTK_ARROW_NONE:
|
|
|
|
|
gtk_popover_set_position (GTK_POPOVER (priv->popover), GTK_POS_BOTTOM);
|
|
|
|
|
break;
|
|
|
|
|
case GTK_ARROW_LEFT:
|
|
|
|
|
gtk_popover_set_position (GTK_POPOVER (priv->popover), GTK_POS_LEFT);
|
|
|
|
|
break;
|
|
|
|
|
case GTK_ARROW_RIGHT:
|
|
|
|
|
gtk_popover_set_position (GTK_POPOVER (priv->popover), GTK_POS_RIGHT);
|
|
|
|
|
break;
|
2017-10-06 19:19:42 +00:00
|
|
|
|
default:
|
|
|
|
|
break;
|
2014-02-08 00:21:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-22 15:25:07 +00:00
|
|
|
|
static void
|
|
|
|
|
popover_destroy_cb (GtkMenuButton *menu_button)
|
|
|
|
|
{
|
|
|
|
|
gtk_menu_button_set_popover (menu_button, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-29 17:39:37 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_menu_button_set_direction:
|
|
|
|
|
* @menu_button: a #GtkMenuButton
|
|
|
|
|
* @direction: a #GtkArrowType
|
|
|
|
|
*
|
2014-02-08 00:21:49 +00:00
|
|
|
|
* Sets the direction in which the popup will be popped up, as
|
2014-02-07 18:01:26 +00:00
|
|
|
|
* well as changing the arrow’s direction. The child will not
|
2012-05-29 17:39:37 +00:00
|
|
|
|
* be changed to an arrow if it was customized.
|
|
|
|
|
*
|
2014-02-08 00:21:49 +00:00
|
|
|
|
* If the does not fit in the available space in the given direction,
|
|
|
|
|
* GTK+ will its best to keep it inside the screen and fully visible.
|
2012-05-29 17:39:37 +00:00
|
|
|
|
*
|
2014-02-08 00:21:49 +00:00
|
|
|
|
* If you pass %GTK_ARROW_NONE for a @direction, the popup will behave
|
2014-02-07 18:32:47 +00:00
|
|
|
|
* as if you passed %GTK_ARROW_DOWN (although you won’t see any arrows).
|
2012-05-29 17:39:37 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_menu_button_set_direction (GtkMenuButton *menu_button,
|
|
|
|
|
GtkArrowType direction)
|
|
|
|
|
{
|
2018-03-07 19:26:51 +00:00
|
|
|
|
GtkMenuButtonPrivate *priv = gtk_menu_button_get_instance_private (menu_button);
|
2012-05-29 17:39:37 +00:00
|
|
|
|
GtkWidget *child;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_MENU_BUTTON (menu_button));
|
|
|
|
|
|
|
|
|
|
if (priv->arrow_type == direction)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
priv->arrow_type = direction;
|
2015-09-06 20:10:48 +00:00
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (menu_button), menu_button_props[PROP_DIRECTION]);
|
2012-05-29 17:39:37 +00:00
|
|
|
|
|
2012-08-21 16:49:02 +00:00
|
|
|
|
/* Is it custom content? We don't change that */
|
2019-05-18 04:56:30 +00:00
|
|
|
|
child = gtk_bin_get_child (GTK_BIN (priv->button));
|
2012-05-29 17:39:37 +00:00
|
|
|
|
if (priv->arrow_widget != child)
|
|
|
|
|
return;
|
|
|
|
|
|
2014-05-13 03:49:28 +00:00
|
|
|
|
set_arrow_type (GTK_IMAGE (child), priv->arrow_type);
|
2014-02-08 00:21:49 +00:00
|
|
|
|
update_popover_direction (menu_button);
|
2012-05-29 17:39:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_menu_button_get_direction:
|
|
|
|
|
* @menu_button: a #GtkMenuButton
|
|
|
|
|
*
|
2014-02-08 00:21:49 +00:00
|
|
|
|
* Returns the direction the popup will be pointing at when popped up.
|
2012-05-29 17:39:37 +00:00
|
|
|
|
*
|
2014-02-08 00:21:49 +00:00
|
|
|
|
* Returns: a #GtkArrowType value
|
2012-05-29 17:39:37 +00:00
|
|
|
|
*/
|
|
|
|
|
GtkArrowType
|
|
|
|
|
gtk_menu_button_get_direction (GtkMenuButton *menu_button)
|
|
|
|
|
{
|
2018-03-07 19:26:51 +00:00
|
|
|
|
GtkMenuButtonPrivate *priv = gtk_menu_button_get_instance_private (menu_button);
|
|
|
|
|
|
2012-05-29 17:39:37 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_MENU_BUTTON (menu_button), GTK_ARROW_DOWN);
|
|
|
|
|
|
2018-03-07 19:26:51 +00:00
|
|
|
|
return priv->arrow_type;
|
2012-05-29 17:39:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2012-07-29 16:43:26 +00:00
|
|
|
|
gtk_menu_button_dispose (GObject *object)
|
2012-05-29 17:39:37 +00:00
|
|
|
|
{
|
2018-03-07 19:26:51 +00:00
|
|
|
|
GtkMenuButtonPrivate *priv = gtk_menu_button_get_instance_private (GTK_MENU_BUTTON (object));
|
2012-05-29 17:39:37 +00:00
|
|
|
|
|
2014-02-08 00:21:49 +00:00
|
|
|
|
if (priv->popover)
|
|
|
|
|
{
|
2018-04-22 15:25:54 +00:00
|
|
|
|
g_signal_handlers_disconnect_by_func (priv->popover,
|
|
|
|
|
menu_deactivate_cb,
|
|
|
|
|
object);
|
2018-04-22 15:25:07 +00:00
|
|
|
|
g_signal_handlers_disconnect_by_func (priv->popover,
|
|
|
|
|
popover_destroy_cb,
|
|
|
|
|
object);
|
2017-10-06 15:35:28 +00:00
|
|
|
|
gtk_popover_set_relative_to (GTK_POPOVER (priv->popover), NULL);
|
2014-02-08 00:21:49 +00:00
|
|
|
|
priv->popover = NULL;
|
2012-05-29 17:39:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-11-04 15:46:35 +00:00
|
|
|
|
set_align_widget_pointer (GTK_MENU_BUTTON (object), NULL);
|
|
|
|
|
|
2012-05-29 17:39:37 +00:00
|
|
|
|
g_clear_object (&priv->model);
|
2019-05-18 04:56:30 +00:00
|
|
|
|
g_clear_pointer (&priv->button, gtk_widget_unparent);
|
2012-05-29 17:39:37 +00:00
|
|
|
|
|
2019-08-22 07:06:43 +00:00
|
|
|
|
if (priv->create_popup_destroy_notify)
|
|
|
|
|
priv->create_popup_destroy_notify (priv->create_popup_user_data);
|
|
|
|
|
|
2012-07-29 16:43:26 +00:00
|
|
|
|
G_OBJECT_CLASS (gtk_menu_button_parent_class)->dispose (object);
|
2012-05-29 17:39:37 +00:00
|
|
|
|
}
|
2014-02-08 00:21:49 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_menu_button_set_popover:
|
|
|
|
|
* @menu_button: a #GtkMenuButton
|
2018-04-22 15:02:55 +00:00
|
|
|
|
* @popover: (nullable): a #GtkPopover, or %NULL to unset and disable the button
|
|
|
|
|
*
|
|
|
|
|
* Sets the #GtkPopover that will be popped up when the @menu_button is clicked,
|
|
|
|
|
* or %NULL to dissociate any existing popover and disable the button.
|
2014-02-08 00:21:49 +00:00
|
|
|
|
*
|
2019-12-30 01:16:52 +00:00
|
|
|
|
* If #GtkMenuButton:menu-model is set, the menu model is dissociated from the
|
|
|
|
|
* @menu_button, and the property is set to %NULL.
|
2014-02-08 00:21:49 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_menu_button_set_popover (GtkMenuButton *menu_button,
|
|
|
|
|
GtkWidget *popover)
|
|
|
|
|
{
|
2018-03-07 19:26:51 +00:00
|
|
|
|
GtkMenuButtonPrivate *priv = gtk_menu_button_get_instance_private (menu_button);
|
2014-02-08 00:21:49 +00:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_MENU_BUTTON (menu_button));
|
|
|
|
|
g_return_if_fail (GTK_IS_POPOVER (popover) || popover == NULL);
|
|
|
|
|
|
2014-02-22 17:36:55 +00:00
|
|
|
|
g_object_freeze_notify (G_OBJECT (menu_button));
|
|
|
|
|
|
2014-02-08 00:21:49 +00:00
|
|
|
|
g_clear_object (&priv->model);
|
|
|
|
|
|
|
|
|
|
if (priv->popover)
|
|
|
|
|
{
|
|
|
|
|
if (gtk_widget_get_visible (priv->popover))
|
|
|
|
|
gtk_widget_hide (priv->popover);
|
|
|
|
|
|
|
|
|
|
g_signal_handlers_disconnect_by_func (priv->popover,
|
|
|
|
|
menu_deactivate_cb,
|
|
|
|
|
menu_button);
|
2018-04-22 15:25:07 +00:00
|
|
|
|
g_signal_handlers_disconnect_by_func (priv->popover,
|
|
|
|
|
popover_destroy_cb,
|
|
|
|
|
menu_button);
|
2014-12-18 03:56:30 +00:00
|
|
|
|
|
|
|
|
|
gtk_popover_set_relative_to (GTK_POPOVER (priv->popover), NULL);
|
2014-02-08 00:21:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
priv->popover = popover;
|
|
|
|
|
|
|
|
|
|
if (popover)
|
|
|
|
|
{
|
|
|
|
|
gtk_popover_set_relative_to (GTK_POPOVER (priv->popover), GTK_WIDGET (menu_button));
|
|
|
|
|
g_signal_connect_swapped (priv->popover, "closed",
|
|
|
|
|
G_CALLBACK (menu_deactivate_cb), menu_button);
|
2018-04-22 13:52:27 +00:00
|
|
|
|
g_signal_connect_swapped (priv->popover, "destroy",
|
|
|
|
|
G_CALLBACK (popover_destroy_cb), menu_button);
|
2014-02-08 00:21:49 +00:00
|
|
|
|
update_popover_direction (menu_button);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-09 19:30:52 +00:00
|
|
|
|
update_sensitivity (menu_button);
|
2014-02-22 17:36:55 +00:00
|
|
|
|
|
2015-09-06 20:10:48 +00:00
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (menu_button), menu_button_props[PROP_POPOVER]);
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (menu_button), menu_button_props[PROP_MENU_MODEL]);
|
2014-12-15 09:29:11 +00:00
|
|
|
|
g_object_thaw_notify (G_OBJECT (menu_button));
|
2014-02-08 00:21:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_menu_button_get_popover:
|
|
|
|
|
* @menu_button: a #GtkMenuButton
|
|
|
|
|
*
|
|
|
|
|
* Returns the #GtkPopover that pops out of the button.
|
|
|
|
|
* If the button is not using a #GtkPopover, this function
|
|
|
|
|
* returns %NULL.
|
|
|
|
|
*
|
2015-12-28 20:14:08 +00:00
|
|
|
|
* Returns: (nullable) (transfer none): a #GtkPopover or %NULL
|
2014-02-08 00:21:49 +00:00
|
|
|
|
*/
|
|
|
|
|
GtkPopover *
|
|
|
|
|
gtk_menu_button_get_popover (GtkMenuButton *menu_button)
|
|
|
|
|
{
|
2018-03-07 19:26:51 +00:00
|
|
|
|
GtkMenuButtonPrivate *priv = gtk_menu_button_get_instance_private (menu_button);
|
|
|
|
|
|
2014-02-08 00:21:49 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_MENU_BUTTON (menu_button), NULL);
|
|
|
|
|
|
2018-03-07 19:26:51 +00:00
|
|
|
|
return GTK_POPOVER (priv->popover);
|
2014-02-08 00:21:49 +00:00
|
|
|
|
}
|
2019-05-18 04:56:30 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_menu_button_set_icon_name:
|
|
|
|
|
* @menu_button: a #GtkMenuButton
|
|
|
|
|
* @icon_name: the icon name
|
|
|
|
|
*
|
|
|
|
|
* Sets the name of an icon to show inside the menu button.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_menu_button_set_icon_name (GtkMenuButton *menu_button,
|
|
|
|
|
const char *icon_name)
|
|
|
|
|
{
|
|
|
|
|
GtkMenuButtonPrivate *priv = gtk_menu_button_get_instance_private (menu_button);
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_MENU_BUTTON (menu_button));
|
|
|
|
|
|
|
|
|
|
gtk_button_set_icon_name (GTK_BUTTON (priv->button), icon_name);
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (menu_button), menu_button_props[PROP_ICON_NAME]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_menu_button_get_icon_name:
|
|
|
|
|
* @menu_button: a #GtkMenuButton
|
|
|
|
|
*
|
|
|
|
|
* Gets the name of the icon shown in the button.
|
|
|
|
|
*
|
|
|
|
|
* Returns: the name of the icon shown in the button
|
|
|
|
|
*/
|
|
|
|
|
const char *
|
|
|
|
|
gtk_menu_button_get_icon_name (GtkMenuButton *menu_button)
|
|
|
|
|
{
|
|
|
|
|
GtkMenuButtonPrivate *priv = gtk_menu_button_get_instance_private (menu_button);
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_MENU_BUTTON (menu_button), NULL);
|
|
|
|
|
|
|
|
|
|
return gtk_button_get_icon_name (GTK_BUTTON (priv->button));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_menu_button_set_label:
|
|
|
|
|
* @menu_button: a #GtkMenuButton
|
2019-05-30 15:05:02 +00:00
|
|
|
|
* @label: the label
|
2019-05-18 04:56:30 +00:00
|
|
|
|
*
|
|
|
|
|
* Sets the label to show inside the menu button.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_menu_button_set_label (GtkMenuButton *menu_button,
|
|
|
|
|
const char *label)
|
|
|
|
|
{
|
|
|
|
|
GtkMenuButtonPrivate *priv = gtk_menu_button_get_instance_private (menu_button);
|
|
|
|
|
GtkWidget *child;
|
|
|
|
|
GtkWidget *box;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_MENU_BUTTON (menu_button));
|
|
|
|
|
|
|
|
|
|
child = gtk_bin_get_child (GTK_BIN (priv->button));
|
|
|
|
|
if (child)
|
|
|
|
|
gtk_container_remove (GTK_CONTAINER (priv->button), child);
|
|
|
|
|
|
|
|
|
|
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), gtk_label_new (label));
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), gtk_image_new_from_icon_name ("pan-down-symbolic"));
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (priv->button), box);
|
|
|
|
|
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (menu_button), menu_button_props[PROP_LABEL]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_menu_button_get_label:
|
|
|
|
|
* @menu_button: a #GtkMenuButton
|
|
|
|
|
*
|
|
|
|
|
* Gets the label shown in the button
|
|
|
|
|
*
|
|
|
|
|
* Returns: the label shown in the button
|
|
|
|
|
*/
|
|
|
|
|
const char *
|
|
|
|
|
gtk_menu_button_get_label (GtkMenuButton *menu_button)
|
|
|
|
|
{
|
|
|
|
|
GtkMenuButtonPrivate *priv = gtk_menu_button_get_instance_private (menu_button);
|
|
|
|
|
GtkWidget *child;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_MENU_BUTTON (menu_button), NULL);
|
|
|
|
|
|
|
|
|
|
child = gtk_bin_get_child (GTK_BIN (priv->button));
|
|
|
|
|
if (GTK_IS_BOX (child))
|
|
|
|
|
{
|
|
|
|
|
child = gtk_widget_get_first_child (child);
|
|
|
|
|
return gtk_label_get_label (GTK_LABEL (child));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2019-05-21 22:39:03 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_menu_button_set_relief:
|
|
|
|
|
* @menu_button: The #GtkMenuButton you want to set relief styles of
|
|
|
|
|
* @relief: The GtkReliefStyle as described above
|
|
|
|
|
*
|
|
|
|
|
* Sets the relief style of the edges of the given
|
|
|
|
|
* #GtkMenuButton widget.
|
|
|
|
|
*
|
|
|
|
|
* Two styles exist, %GTK_RELIEF_NORMAL and %GTK_RELIEF_NONE.
|
|
|
|
|
* The default style is, as one can guess, %GTK_RELIEF_NORMAL.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_menu_button_set_relief (GtkMenuButton *menu_button,
|
|
|
|
|
GtkReliefStyle relief)
|
|
|
|
|
{
|
|
|
|
|
GtkMenuButtonPrivate *priv = gtk_menu_button_get_instance_private (menu_button);
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_MENU_BUTTON (menu_button));
|
|
|
|
|
|
|
|
|
|
if (relief == gtk_button_get_relief (GTK_BUTTON (priv->button)))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
gtk_button_set_relief (GTK_BUTTON (priv->button), relief);
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (menu_button), menu_button_props[PROP_RELIEF]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_menu_button_get_relief:
|
|
|
|
|
* @menu_button: The #GtkMenuButton you want the #GtkReliefStyle from.
|
|
|
|
|
*
|
|
|
|
|
* Returns the current relief style of the given #GtkMenuButton.
|
|
|
|
|
*
|
|
|
|
|
* Returns: The current #GtkReliefStyle
|
|
|
|
|
*/
|
|
|
|
|
GtkReliefStyle
|
|
|
|
|
gtk_menu_button_get_relief (GtkMenuButton *menu_button)
|
|
|
|
|
{
|
|
|
|
|
GtkMenuButtonPrivate *priv = gtk_menu_button_get_instance_private (menu_button);
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_MENU_BUTTON (menu_button), GTK_RELIEF_NORMAL);
|
|
|
|
|
|
|
|
|
|
return gtk_button_get_relief (GTK_BUTTON (priv->button));
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-24 00:30:39 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_menu_button_popup:
|
|
|
|
|
* @menu_button: a #GtkMenuButton
|
|
|
|
|
*
|
|
|
|
|
* Pop up the menu.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_menu_button_popup (GtkMenuButton *menu_button)
|
|
|
|
|
{
|
|
|
|
|
GtkMenuButtonPrivate *priv = gtk_menu_button_get_instance_private (menu_button);
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_MENU_BUTTON (menu_button));
|
|
|
|
|
|
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->button), TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_menu_button_popdown:
|
|
|
|
|
* @menu_button: a #GtkMenuButton
|
|
|
|
|
*
|
|
|
|
|
* Dismiss the menu.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_menu_button_popdown (GtkMenuButton *menu_button)
|
|
|
|
|
{
|
|
|
|
|
GtkMenuButtonPrivate *priv = gtk_menu_button_get_instance_private (menu_button);
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_MENU_BUTTON (menu_button));
|
|
|
|
|
|
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->button), FALSE);
|
|
|
|
|
}
|
2019-06-13 19:31:48 +00:00
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
gtk_menu_button_add_child (GtkMenuButton *menu_button,
|
|
|
|
|
GtkWidget *new_child)
|
|
|
|
|
{
|
|
|
|
|
GtkMenuButtonPrivate *priv = gtk_menu_button_get_instance_private (menu_button);
|
|
|
|
|
GtkWidget *child;
|
|
|
|
|
|
|
|
|
|
child = gtk_bin_get_child (GTK_BIN (priv->button));
|
|
|
|
|
if (child)
|
|
|
|
|
gtk_container_remove (GTK_CONTAINER (priv->button), child);
|
|
|
|
|
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (priv->button), new_child);
|
|
|
|
|
}
|
2019-08-22 07:06:43 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_menu_button_set_create_popup_func:
|
|
|
|
|
* @menu_button: a #GtkMenuButton
|
|
|
|
|
* @func: (nullable): function to call when a popuop is about to
|
|
|
|
|
* be shown, but none has been provided via other means, or %NULL
|
|
|
|
|
* to reset to default behavior.
|
2020-01-13 01:26:50 +00:00
|
|
|
|
* @user_data: (closure): user data to pass to @func.
|
2019-08-22 07:06:43 +00:00
|
|
|
|
* @destroy_notify: (nullable): destroy notify for @user_data
|
|
|
|
|
*
|
|
|
|
|
* Sets @func to be called when a popup is about to be shown.
|
|
|
|
|
* @func should use one of
|
|
|
|
|
*
|
|
|
|
|
* - gtk_menu_button_set_popover()
|
|
|
|
|
* - gtk_menu_button_set_menu_model()
|
|
|
|
|
*
|
2019-12-27 03:41:47 +00:00
|
|
|
|
* to set a popup for @menu_button.
|
2019-08-22 07:06:43 +00:00
|
|
|
|
* If @func is non-%NULL, @menu_button will always be sensitive.
|
|
|
|
|
*
|
2019-12-30 01:16:52 +00:00
|
|
|
|
* Using this function will not reset the menu widget attached to @menu_button.
|
2019-08-22 07:06:43 +00:00
|
|
|
|
* Instead, this can be done manually in @func.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_menu_button_set_create_popup_func (GtkMenuButton *menu_button,
|
|
|
|
|
GtkMenuButtonCreatePopupFunc func,
|
|
|
|
|
gpointer user_data,
|
|
|
|
|
GDestroyNotify destroy_notify)
|
|
|
|
|
{
|
|
|
|
|
GtkMenuButtonPrivate *priv = gtk_menu_button_get_instance_private (menu_button);
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_MENU_BUTTON (menu_button));
|
|
|
|
|
|
|
|
|
|
if (priv->create_popup_destroy_notify)
|
|
|
|
|
priv->create_popup_destroy_notify (priv->create_popup_user_data);
|
|
|
|
|
|
|
|
|
|
priv->create_popup_func = func;
|
|
|
|
|
priv->create_popup_user_data = user_data;
|
|
|
|
|
priv->create_popup_destroy_notify = destroy_notify;
|
|
|
|
|
|
|
|
|
|
update_sensitivity (menu_button);
|
|
|
|
|
}
|