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/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* GtkMenuButton:
|
|
|
|
|
*
|
2021-02-28 00:48:14 +00:00
|
|
|
|
* The `GtkMenuButton` widget is used to display a popup when clicked.
|
2021-02-21 18:51:04 +00:00
|
|
|
|
*
|
|
|
|
|
* ![An example GtkMenuButton](menu-button.png)
|
|
|
|
|
*
|
|
|
|
|
* This popup can be provided either as a `GtkPopover` or as an abstract
|
|
|
|
|
* `GMenuModel`.
|
|
|
|
|
*
|
|
|
|
|
* The `GtkMenuButton` widget can show either an icon (set with the
|
|
|
|
|
* [property@Gtk.MenuButton:icon-name] property) or a label (set with the
|
|
|
|
|
* [property@Gtk.MenuButton:label] property). If neither is explicitly set,
|
|
|
|
|
* a [class@Gtk.Image] is automatically created, using an arrow image oriented
|
2021-02-25 17:23:28 +00:00
|
|
|
|
* according to [property@Gtk.MenuButton:direction] or the generic
|
|
|
|
|
* “open-menu-symbolic” icon if the direction is not set.
|
2012-08-07 02:26:13 +00:00
|
|
|
|
*
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* The positioning of the popup is determined by the
|
2021-02-22 00:09:57 +00:00
|
|
|
|
* [property@Gtk.MenuButton:direction] property of the menu button.
|
2014-02-08 00:21:49 +00:00
|
|
|
|
*
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* For menus, the [property@Gtk.Widget:halign] and [property@Gtk.Widget: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
|
2014-02-08 00:21:49 +00:00
|
|
|
|
* (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
|
|
|
|
*
|
2021-02-28 00:48:14 +00:00
|
|
|
|
* | | start | center | end |
|
|
|
|
|
* | - | --- | --- | --- |
|
|
|
|
|
* | **down** | ![](down-start.png) | ![](down-center.png) | ![](down-end.png) |
|
|
|
|
|
* | **up** | ![](up-start.png) | ![](up-center.png) | ![](up-end.png) |
|
|
|
|
|
* | **left** | ![](left-start.png) | ![](left-center.png) | ![](left-end.png) |
|
|
|
|
|
* | **right** | ![](right-start.png) | ![](right-center.png) | ![](right-end.png) |
|
2014-02-05 01:00:53 +00:00
|
|
|
|
*
|
2015-10-30 04:54:37 +00:00
|
|
|
|
* # CSS nodes
|
|
|
|
|
*
|
2021-02-28 00:48:14 +00:00
|
|
|
|
* ```
|
2020-12-23 13:45:51 +00:00
|
|
|
|
* menubutton
|
|
|
|
|
* ╰── button.toggle
|
2021-01-19 19:00:21 +00:00
|
|
|
|
* ╰── <content>
|
|
|
|
|
* ╰── [arrow]
|
2021-02-28 00:48:14 +00:00
|
|
|
|
* ```
|
2020-12-23 13:45:51 +00:00
|
|
|
|
*
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* `GtkMenuButton` has a single CSS node with name `menubutton`
|
|
|
|
|
* which contains a `button` node with a `.toggle` style class.
|
2020-10-21 20:27:23 +00:00
|
|
|
|
*
|
2021-09-03 11:18:06 +00:00
|
|
|
|
* If the button contains an icon, it will have the `.image-button` style class,
|
|
|
|
|
* if it contains text, it will have `.text-button` style class. If an arrow is
|
|
|
|
|
* visible in addition to an icon, text or a custom child, it will also have
|
2021-06-21 10:13:16 +00:00
|
|
|
|
* `.arrow-button` style class.
|
|
|
|
|
*
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* Inside the toggle button content, there is an `arrow` node for
|
|
|
|
|
* the indicator, which will carry one of the `.none`, `.up`, `.down`,
|
|
|
|
|
* `.left` or `.right` style classes to indicate the direction that
|
2021-01-19 19:00:21 +00:00
|
|
|
|
* the menu will appear in. The CSS is expected to provide a suitable
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* image for each of these cases using the `-gtk-icon-source` property.
|
2021-01-19 19:00:21 +00:00
|
|
|
|
*
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* Optionally, the `menubutton` node can carry the `.circular` style class
|
2021-01-26 05:17:08 +00:00
|
|
|
|
* to request a round appearance.
|
|
|
|
|
*
|
2020-10-21 20:27:23 +00:00
|
|
|
|
* # Accessibility
|
|
|
|
|
*
|
2021-05-20 13:17:04 +00:00
|
|
|
|
* `GtkMenuButton` uses the %GTK_ACCESSIBLE_ROLE_BUTTON role.
|
2012-05-29 17:39:37 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
2018-02-25 10:29:33 +00:00
|
|
|
|
#include "gtkactionable.h"
|
2021-09-03 11:18:06 +00:00
|
|
|
|
#include "gtkbuildable.h"
|
2021-01-19 19:00:21 +00:00
|
|
|
|
#include "gtkbuiltiniconprivate.h"
|
2021-06-21 10:13:16 +00:00
|
|
|
|
#include "gtkimage.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 "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"
|
2021-05-24 21:27:40 +00:00
|
|
|
|
#include "gtkwindow.h"
|
2019-03-16 03:48:26 +00:00
|
|
|
|
|
2019-05-27 03:10:57 +00:00
|
|
|
|
typedef struct _GtkMenuButtonClass GtkMenuButtonClass;
|
|
|
|
|
typedef struct _GtkMenuButtonPrivate GtkMenuButtonPrivate;
|
|
|
|
|
|
|
|
|
|
struct _GtkMenuButton
|
|
|
|
|
{
|
|
|
|
|
GtkWidget parent_instance;
|
|
|
|
|
|
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
|
|
|
|
|
2020-03-28 02:28:49 +00:00
|
|
|
|
GtkWidget *label_widget;
|
2021-06-21 10:13:16 +00:00
|
|
|
|
GtkWidget *image_widget;
|
2014-07-20 12:12:30 +00:00
|
|
|
|
GtkWidget *arrow_widget;
|
2021-09-03 11:18:06 +00:00
|
|
|
|
GtkWidget *child;
|
2013-09-22 03:37:48 +00:00
|
|
|
|
GtkArrowType arrow_type;
|
2021-06-21 10:13:16 +00:00
|
|
|
|
gboolean always_show_arrow;
|
2021-05-24 21:27:40 +00:00
|
|
|
|
|
|
|
|
|
gboolean primary;
|
2012-05-29 17:39:37 +00:00
|
|
|
|
};
|
|
|
|
|
|
2020-03-28 04:35:13 +00:00
|
|
|
|
struct _GtkMenuButtonClass
|
|
|
|
|
{
|
|
|
|
|
GtkWidgetClass parent_class;
|
2021-07-05 14:08:43 +00:00
|
|
|
|
|
|
|
|
|
void (* activate) (GtkMenuButton *self);
|
2020-03-28 04:35:13 +00:00
|
|
|
|
};
|
|
|
|
|
|
2012-05-29 17:39:37 +00:00
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
PROP_0,
|
2014-02-22 17:08:45 +00:00
|
|
|
|
PROP_MENU_MODEL,
|
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,
|
2021-06-21 10:13:16 +00:00
|
|
|
|
PROP_ALWAYS_SHOW_ARROW,
|
2019-05-18 04:56:30 +00:00
|
|
|
|
PROP_LABEL,
|
2020-03-28 02:28:49 +00:00
|
|
|
|
PROP_USE_UNDERLINE,
|
2020-04-17 04:31:50 +00:00
|
|
|
|
PROP_HAS_FRAME,
|
2021-05-24 21:27:40 +00:00
|
|
|
|
PROP_PRIMARY,
|
2021-09-03 11:18:06 +00:00
|
|
|
|
PROP_CHILD,
|
2015-09-06 20:10:48 +00:00
|
|
|
|
LAST_PROP
|
2012-05-29 17:39:37 +00:00
|
|
|
|
};
|
|
|
|
|
|
2021-07-05 14:08:43 +00:00
|
|
|
|
enum {
|
|
|
|
|
ACTIVATE,
|
|
|
|
|
LAST_SIGNAL
|
|
|
|
|
};
|
|
|
|
|
|
2015-09-06 20:10:48 +00:00
|
|
|
|
static GParamSpec *menu_button_props[LAST_PROP];
|
2021-07-05 14:08:43 +00:00
|
|
|
|
static guint signals[LAST_SIGNAL] = { 0 };
|
2015-09-06 20:10:48 +00:00
|
|
|
|
|
2021-09-03 11:18:06 +00:00
|
|
|
|
static void gtk_menu_button_buildable_iface_init (GtkBuildableIface *iface);
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkMenuButton, gtk_menu_button, GTK_TYPE_WIDGET,
|
|
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, gtk_menu_button_buildable_iface_init))
|
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_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;
|
2021-06-21 10:13:16 +00:00
|
|
|
|
case PROP_ALWAYS_SHOW_ARROW:
|
|
|
|
|
gtk_menu_button_set_always_show_arrow (self, g_value_get_boolean (value));
|
|
|
|
|
break;
|
2019-05-18 04:56:30 +00:00
|
|
|
|
case PROP_LABEL:
|
|
|
|
|
gtk_menu_button_set_label (self, g_value_get_string (value));
|
|
|
|
|
break;
|
2020-03-28 02:28:49 +00:00
|
|
|
|
case PROP_USE_UNDERLINE:
|
|
|
|
|
gtk_menu_button_set_use_underline (self, g_value_get_boolean (value));
|
|
|
|
|
break;
|
2020-04-17 04:31:50 +00:00
|
|
|
|
case PROP_HAS_FRAME:
|
|
|
|
|
gtk_menu_button_set_has_frame (self, g_value_get_boolean (value));
|
2019-05-21 22:39:03 +00:00
|
|
|
|
break;
|
2021-05-24 21:27:40 +00:00
|
|
|
|
case PROP_PRIMARY:
|
|
|
|
|
gtk_menu_button_set_primary (self, g_value_get_boolean (value));
|
|
|
|
|
break;
|
2021-09-03 11:18:06 +00:00
|
|
|
|
case PROP_CHILD:
|
|
|
|
|
gtk_menu_button_set_child (self, g_value_get_object (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
|
|
|
|
{
|
2020-03-28 04:35:13 +00:00
|
|
|
|
GtkMenuButton *self = 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:
|
2020-03-28 04:35:13 +00:00
|
|
|
|
g_value_set_object (value, self->model);
|
2012-05-29 17:39:37 +00:00
|
|
|
|
break;
|
|
|
|
|
case PROP_DIRECTION:
|
2020-03-28 04:35:13 +00:00
|
|
|
|
g_value_set_enum (value, self->arrow_type);
|
2012-05-29 17:39:37 +00:00
|
|
|
|
break;
|
2014-02-08 00:21:49 +00:00
|
|
|
|
case PROP_POPOVER:
|
2020-03-28 04:35:13 +00:00
|
|
|
|
g_value_set_object (value, self->popover);
|
2014-02-08 00:21:49 +00:00
|
|
|
|
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;
|
2021-06-21 10:13:16 +00:00
|
|
|
|
case PROP_ALWAYS_SHOW_ARROW:
|
|
|
|
|
g_value_set_boolean (value, gtk_menu_button_get_always_show_arrow (self));
|
|
|
|
|
break;
|
2019-05-18 04:56:30 +00:00
|
|
|
|
case PROP_LABEL:
|
|
|
|
|
g_value_set_string (value, gtk_menu_button_get_label (GTK_MENU_BUTTON (object)));
|
|
|
|
|
break;
|
2020-03-28 02:28:49 +00:00
|
|
|
|
case PROP_USE_UNDERLINE:
|
|
|
|
|
g_value_set_boolean (value, gtk_menu_button_get_use_underline (GTK_MENU_BUTTON (object)));
|
|
|
|
|
break;
|
2020-04-17 04:31:50 +00:00
|
|
|
|
case PROP_HAS_FRAME:
|
|
|
|
|
g_value_set_boolean (value, gtk_menu_button_get_has_frame (GTK_MENU_BUTTON (object)));
|
2019-05-21 22:39:03 +00:00
|
|
|
|
break;
|
2021-05-24 21:27:40 +00:00
|
|
|
|
case PROP_PRIMARY:
|
|
|
|
|
g_value_set_boolean (value, gtk_menu_button_get_primary (GTK_MENU_BUTTON (object)));
|
|
|
|
|
break;
|
2021-09-03 11:18:06 +00:00
|
|
|
|
case PROP_CHILD:
|
|
|
|
|
g_value_set_object (value, gtk_menu_button_get_child (self));
|
|
|
|
|
break;
|
2012-05-29 17:39:37 +00:00
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-11 19:22:00 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_menu_button_notify (GObject *object,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
if (strcmp (pspec->name, "focus-on-click") == 0)
|
|
|
|
|
{
|
|
|
|
|
GtkMenuButton *self = GTK_MENU_BUTTON (object);
|
|
|
|
|
|
|
|
|
|
gtk_widget_set_focus_on_click (self->button,
|
|
|
|
|
gtk_widget_get_focus_on_click (GTK_WIDGET (self)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (G_OBJECT_CLASS (gtk_menu_button_parent_class)->notify)
|
|
|
|
|
G_OBJECT_CLASS (gtk_menu_button_parent_class)->notify (object, pspec);
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-29 17:39:37 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_menu_button_state_flags_changed (GtkWidget *widget,
|
|
|
|
|
GtkStateFlags previous_state_flags)
|
|
|
|
|
{
|
2020-03-28 04:35:13 +00:00
|
|
|
|
GtkMenuButton *self = GTK_MENU_BUTTON (widget);
|
2012-05-29 17:39:37 +00:00
|
|
|
|
|
2014-02-08 00:21:49 +00:00
|
|
|
|
if (!gtk_widget_is_sensitive (widget))
|
|
|
|
|
{
|
2020-03-28 04:35:13 +00:00
|
|
|
|
if (self->popover)
|
|
|
|
|
gtk_widget_hide (self->popover);
|
2014-02-08 00:21:49 +00:00
|
|
|
|
}
|
2012-05-29 17:39:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-03-28 04:35:13 +00:00
|
|
|
|
gtk_menu_button_toggled (GtkMenuButton *self)
|
2012-05-29 17:39:37 +00:00
|
|
|
|
{
|
2020-03-28 04:35:13 +00:00
|
|
|
|
const gboolean active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->button));
|
2019-08-22 07:06:43 +00:00
|
|
|
|
|
|
|
|
|
/* Might set a new menu/popover */
|
2020-03-28 04:35:13 +00:00
|
|
|
|
if (active && self->create_popup_func)
|
2019-08-22 07:06:43 +00:00
|
|
|
|
{
|
2020-03-28 04:35:13 +00:00
|
|
|
|
self->create_popup_func (self, self->create_popup_user_data);
|
2019-08-22 07:06:43 +00:00
|
|
|
|
}
|
2015-07-23 12:26:25 +00:00
|
|
|
|
|
2020-03-28 04:35:13 +00:00
|
|
|
|
if (self->popover)
|
2015-06-15 23:42:47 +00:00
|
|
|
|
{
|
|
|
|
|
if (active)
|
2020-10-21 20:27:23 +00:00
|
|
|
|
{
|
|
|
|
|
gtk_popover_popup (GTK_POPOVER (self->popover));
|
|
|
|
|
gtk_accessible_update_state (GTK_ACCESSIBLE (self),
|
|
|
|
|
GTK_ACCESSIBLE_STATE_EXPANDED, TRUE,
|
|
|
|
|
-1);
|
|
|
|
|
}
|
2015-06-15 23:42:47 +00:00
|
|
|
|
else
|
2020-10-21 20:27:23 +00:00
|
|
|
|
{
|
|
|
|
|
gtk_popover_popdown (GTK_POPOVER (self->popover));
|
|
|
|
|
gtk_accessible_reset_state (GTK_ACCESSIBLE (self),
|
|
|
|
|
GTK_ACCESSIBLE_STATE_EXPANDED);
|
|
|
|
|
}
|
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
|
|
|
|
{
|
2020-03-28 04:35:13 +00:00
|
|
|
|
GtkMenuButton *self = GTK_MENU_BUTTON (widget);
|
2012-08-25 03:32:41 +00:00
|
|
|
|
|
2020-03-28 04:35:13 +00:00
|
|
|
|
gtk_widget_measure (self->button,
|
2019-05-18 04:56:30 +00:00
|
|
|
|
orientation,
|
|
|
|
|
for_size,
|
|
|
|
|
minimum, natural,
|
|
|
|
|
minimum_baseline, natural_baseline);
|
2020-02-24 12:21:46 +00:00
|
|
|
|
|
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
|
|
|
|
{
|
2020-03-28 04:35:13 +00:00
|
|
|
|
GtkMenuButton *self= GTK_MENU_BUTTON (widget);
|
2012-09-04 13:38:28 +00:00
|
|
|
|
|
2020-03-28 04:35:13 +00:00
|
|
|
|
gtk_widget_size_allocate (self->button,
|
2019-05-18 04:56:30 +00:00
|
|
|
|
&(GtkAllocation) { 0, 0, width, height },
|
|
|
|
|
baseline);
|
2020-03-28 04:35:13 +00:00
|
|
|
|
if (self->popover)
|
2020-12-04 08:20:50 +00:00
|
|
|
|
gtk_popover_present (GTK_POPOVER (self->popover));
|
2019-04-26 23:17:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
gtk_menu_button_focus (GtkWidget *widget,
|
|
|
|
|
GtkDirectionType direction)
|
|
|
|
|
{
|
2020-03-28 04:35:13 +00:00
|
|
|
|
GtkMenuButton *self = GTK_MENU_BUTTON (widget);
|
2019-04-26 23:17:37 +00:00
|
|
|
|
|
2020-03-28 04:35:13 +00:00
|
|
|
|
if (self->popover && gtk_widget_get_visible (self->popover))
|
|
|
|
|
return gtk_widget_child_focus (self->popover, direction);
|
2019-04-26 23:17:37 +00:00
|
|
|
|
else
|
2020-04-08 11:43:28 +00:00
|
|
|
|
return gtk_widget_child_focus (self->button, direction);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
gtk_menu_button_grab_focus (GtkWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
GtkMenuButton *self = GTK_MENU_BUTTON (widget);
|
|
|
|
|
|
|
|
|
|
return gtk_widget_grab_focus (self->button);
|
2012-09-04 13:38:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-05 14:08:43 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_menu_button_activate (GtkMenuButton *self)
|
|
|
|
|
{
|
|
|
|
|
gtk_widget_activate (self->button);
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-24 21:27:40 +00:00
|
|
|
|
static void gtk_menu_button_root (GtkWidget *widget);
|
|
|
|
|
static void gtk_menu_button_unroot (GtkWidget *widget);
|
|
|
|
|
|
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;
|
2021-04-11 19:22:00 +00:00
|
|
|
|
gobject_class->notify = gtk_menu_button_notify;
|
2012-07-29 16:43:26 +00:00
|
|
|
|
gobject_class->dispose = gtk_menu_button_dispose;
|
2012-05-29 17:39:37 +00:00
|
|
|
|
|
2021-05-24 21:27:40 +00:00
|
|
|
|
widget_class->root = gtk_menu_button_root;
|
|
|
|
|
widget_class->unroot = gtk_menu_button_unroot;
|
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;
|
2020-04-08 11:43:28 +00:00
|
|
|
|
widget_class->grab_focus = gtk_menu_button_grab_focus;
|
2012-05-29 17:39:37 +00:00
|
|
|
|
|
2021-07-05 14:08:43 +00:00
|
|
|
|
klass->activate = gtk_menu_button_activate;
|
|
|
|
|
|
2012-05-29 17:39:37 +00:00
|
|
|
|
/**
|
2021-02-25 17:23:28 +00:00
|
|
|
|
* GtkMenuButton:menu-model: (attributes org.gtk.Property.get=gtk_menu_button_get_menu_model org.gtk.Property.set=gtk_menu_button_set_menu_model)
|
2012-05-29 17:39:37 +00:00
|
|
|
|
*
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* The `GMenuModel` from which the popup will be created.
|
2014-02-08 00:21:49 +00:00
|
|
|
|
*
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* See [method@Gtk.MenuButton.set_menu_model] for the interaction
|
|
|
|
|
* with the [property@Gtk.MenuButton:popover] property.
|
2012-05-29 17:39:37 +00:00
|
|
|
|
*/
|
2015-09-06 20:10:48 +00:00
|
|
|
|
menu_button_props[PROP_MENU_MODEL] =
|
2022-05-11 12:19:39 +00:00
|
|
|
|
g_param_spec_object ("menu-model", NULL, NULL,
|
2015-09-06 20:10:48 +00:00
|
|
|
|
G_TYPE_MENU_MODEL,
|
|
|
|
|
GTK_PARAM_READWRITE);
|
|
|
|
|
|
2012-05-29 17:39:37 +00:00
|
|
|
|
/**
|
2021-02-25 17:23:28 +00:00
|
|
|
|
* GtkMenuButton:direction: (attributes org.gtk.Property.get=gtk_menu_button_get_direction org.gtk.Property.set=gtk_menu_button_set_direction)
|
2012-05-29 17:39:37 +00:00
|
|
|
|
*
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* 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] =
|
2022-05-11 12:19:39 +00:00
|
|
|
|
g_param_spec_enum ("direction", NULL, NULL,
|
2015-09-06 20:10:48 +00:00
|
|
|
|
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
|
|
|
|
/**
|
2021-02-25 17:23:28 +00:00
|
|
|
|
* GtkMenuButton:popover: (attributes org.gtk.Property.get=gtk_menu_button_get_popover org.gtk.Property.set=gtk_menu_button_set_popover)
|
2014-02-08 00:21:49 +00:00
|
|
|
|
*
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* The `GtkPopover` that will be popped up when the button is clicked.
|
2014-02-08 00:21:49 +00:00
|
|
|
|
*/
|
2015-09-06 20:10:48 +00:00
|
|
|
|
menu_button_props[PROP_POPOVER] =
|
2022-05-11 12:19:39 +00:00
|
|
|
|
g_param_spec_object ("popover", NULL, NULL,
|
2015-09-06 20:10:48 +00:00
|
|
|
|
GTK_TYPE_POPOVER,
|
|
|
|
|
G_PARAM_READWRITE);
|
2014-02-08 00:21:49 +00:00
|
|
|
|
|
2021-02-21 18:51:04 +00:00
|
|
|
|
/**
|
2021-02-25 17:23:28 +00:00
|
|
|
|
* GtkMenuButton:icon-name: (attributes org.gtk.Property.get=gtk_menu_button_get_icon_name org.gtk.Property.set=gtk_menu_button_set_icon_name)
|
2021-02-21 18:51:04 +00:00
|
|
|
|
*
|
|
|
|
|
* The name of the icon used to automatically populate the button.
|
|
|
|
|
*/
|
2019-05-18 04:56:30 +00:00
|
|
|
|
menu_button_props[PROP_ICON_NAME] =
|
2022-05-11 12:19:39 +00:00
|
|
|
|
g_param_spec_string ("icon-name", NULL, NULL,
|
2019-05-18 04:56:30 +00:00
|
|
|
|
NULL,
|
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
|
2021-06-21 10:13:16 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkMenuButton:always-show-arrow: (attributes org.gtk.Property.get=gtk_menu_button_get_always_show_arrow org.gtk.Property.set=gtk_menu_button_set_always_show_arrow)
|
|
|
|
|
*
|
2021-09-03 11:18:06 +00:00
|
|
|
|
* Whether to show a dropdown arrow even when using an icon or a custom child.
|
2021-06-21 10:13:16 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 4.4
|
|
|
|
|
*/
|
|
|
|
|
menu_button_props[PROP_ALWAYS_SHOW_ARROW] =
|
2022-05-11 12:19:39 +00:00
|
|
|
|
g_param_spec_boolean ("always-show-arrow", NULL, NULL,
|
2021-06-21 10:13:16 +00:00
|
|
|
|
FALSE,
|
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
|
2021-02-21 18:51:04 +00:00
|
|
|
|
/**
|
2021-02-25 17:23:28 +00:00
|
|
|
|
* GtkMenuButton:label: (attributes org.gtk.Property.get=gtk_menu_button_get_label org.gtk.Property.set=gtk_menu_button_set_label)
|
2021-02-21 18:51:04 +00:00
|
|
|
|
*
|
|
|
|
|
* The label for the button.
|
|
|
|
|
*/
|
2019-05-18 04:56:30 +00:00
|
|
|
|
menu_button_props[PROP_LABEL] =
|
2022-05-11 12:19:39 +00:00
|
|
|
|
g_param_spec_string ("label", NULL, NULL,
|
2019-05-18 04:56:30 +00:00
|
|
|
|
NULL,
|
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
|
2021-02-21 18:51:04 +00:00
|
|
|
|
/**
|
2021-02-25 17:23:28 +00:00
|
|
|
|
* GtkMenuButton:use-underline: (attributes org.gtk.Property.get=gtk_menu_button_get_use_underline org.gtk.Property.set=gtk_menu_button_set_use_underline)
|
2021-02-21 18:51:04 +00:00
|
|
|
|
*
|
|
|
|
|
* If set an underscore in the text indicates a mnemonic.
|
|
|
|
|
*/
|
2020-03-28 02:28:49 +00:00
|
|
|
|
menu_button_props[PROP_USE_UNDERLINE] =
|
2022-05-11 12:19:39 +00:00
|
|
|
|
g_param_spec_boolean ("use-underline", NULL, NULL,
|
2020-03-28 02:28:49 +00:00
|
|
|
|
FALSE,
|
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
|
2021-02-21 18:51:04 +00:00
|
|
|
|
/**
|
2021-02-25 17:23:28 +00:00
|
|
|
|
* GtkMenuButton:has-frame: (attributes org.gtk.Property.get=gtk_menu_button_get_has_frame org.gtk.Property.set=gtk_menu_button_set_has_frame)
|
2021-02-21 18:51:04 +00:00
|
|
|
|
*
|
|
|
|
|
* Whether the button has a frame.
|
|
|
|
|
*/
|
2020-04-17 04:31:50 +00:00
|
|
|
|
menu_button_props[PROP_HAS_FRAME] =
|
2022-05-11 12:19:39 +00:00
|
|
|
|
g_param_spec_boolean ("has-frame", NULL, NULL,
|
2020-04-17 04:31:50 +00:00
|
|
|
|
TRUE,
|
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
2019-05-21 22:39:03 +00:00
|
|
|
|
|
2021-05-24 21:27:40 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkMenuButton:primary: (attributes org.gtk.Property.get=gtk_menu_button_get_primary org.gtk.Property.set=gtk_menu_button_set_primary)
|
|
|
|
|
*
|
|
|
|
|
* Whether the menu button acts as a primary menu.
|
|
|
|
|
*
|
|
|
|
|
* Primary menus can be opened using the <kbd>F10</kbd> key
|
2021-07-13 07:31:00 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 4.4
|
2021-05-24 21:27:40 +00:00
|
|
|
|
*/
|
|
|
|
|
menu_button_props[PROP_PRIMARY] =
|
2022-05-11 12:19:39 +00:00
|
|
|
|
g_param_spec_boolean ("primary", NULL, NULL,
|
2021-05-24 21:27:40 +00:00
|
|
|
|
FALSE,
|
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
|
2021-09-03 11:18:06 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkMenuButton:child: (attributes org.gtk.Property.get=gtk_menu_button_get_child org.gtk.Property.set=gtk_menu_button_set_child)
|
|
|
|
|
*
|
|
|
|
|
* The child widget.
|
|
|
|
|
*
|
|
|
|
|
* Since: 4.6
|
|
|
|
|
*/
|
|
|
|
|
menu_button_props[PROP_CHILD] =
|
2022-05-11 12:19:39 +00:00
|
|
|
|
g_param_spec_object ("child", NULL, NULL,
|
2021-09-03 11:18:06 +00:00
|
|
|
|
GTK_TYPE_WIDGET,
|
|
|
|
|
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
|
|
|
|
|
2021-07-05 14:08:43 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkMenuButton::activate:
|
|
|
|
|
* @widget: the object which received the signal.
|
|
|
|
|
*
|
|
|
|
|
* Emitted to when the menu button is activated.
|
|
|
|
|
*
|
|
|
|
|
* The `::activate` signal on `GtkMenuButton` is an action signal and
|
|
|
|
|
* emitting it causes the button to pop up its menu.
|
|
|
|
|
*
|
|
|
|
|
* Since: 4.4
|
|
|
|
|
*/
|
|
|
|
|
signals[ACTIVATE] =
|
|
|
|
|
g_signal_new (I_ ("activate"),
|
|
|
|
|
G_OBJECT_CLASS_TYPE (gobject_class),
|
|
|
|
|
G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
|
|
|
|
|
G_STRUCT_OFFSET (GtkMenuButtonClass, activate),
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
|
|
|
|
|
gtk_widget_class_set_activate_signal (widget_class, signals[ACTIVATE]);
|
|
|
|
|
|
2019-05-18 04:56:30 +00:00
|
|
|
|
gtk_widget_class_set_css_name (widget_class, I_("menubutton"));
|
2020-10-21 20:27:23 +00:00
|
|
|
|
gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_BUTTON);
|
2012-05-29 17:39:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-13 03:49:28 +00:00
|
|
|
|
static void
|
2021-01-19 19:00:21 +00:00
|
|
|
|
set_arrow_type (GtkWidget *arrow,
|
2020-09-28 15:30:30 +00:00
|
|
|
|
GtkArrowType arrow_type,
|
|
|
|
|
gboolean visible)
|
2014-05-13 03:49:28 +00:00
|
|
|
|
{
|
2021-01-19 19:00:21 +00:00
|
|
|
|
gtk_widget_remove_css_class (arrow, "none");
|
|
|
|
|
gtk_widget_remove_css_class (arrow, "down");
|
|
|
|
|
gtk_widget_remove_css_class (arrow, "up");
|
|
|
|
|
gtk_widget_remove_css_class (arrow, "left");
|
|
|
|
|
gtk_widget_remove_css_class (arrow, "right");
|
2014-05-13 03:49:28 +00:00
|
|
|
|
switch (arrow_type)
|
|
|
|
|
{
|
|
|
|
|
case GTK_ARROW_NONE:
|
2021-01-19 19:00:21 +00:00
|
|
|
|
gtk_widget_add_css_class (arrow, "none");
|
2014-07-08 12:35:33 +00:00
|
|
|
|
break;
|
2014-05-13 03:49:28 +00:00
|
|
|
|
case GTK_ARROW_DOWN:
|
2021-01-19 19:00:21 +00:00
|
|
|
|
gtk_widget_add_css_class (arrow, "down");
|
2014-05-13 03:49:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_ARROW_UP:
|
2021-01-19 19:00:21 +00:00
|
|
|
|
gtk_widget_add_css_class (arrow, "up");
|
2014-05-13 03:49:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_ARROW_LEFT:
|
2021-01-19 19:00:21 +00:00
|
|
|
|
gtk_widget_add_css_class (arrow, "left");
|
2014-05-13 03:49:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_ARROW_RIGHT:
|
2021-01-19 19:00:21 +00:00
|
|
|
|
gtk_widget_add_css_class (arrow, "right");
|
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
|
|
|
|
}
|
2020-09-28 15:30:30 +00:00
|
|
|
|
|
|
|
|
|
if (visible)
|
2021-01-19 19:00:21 +00:00
|
|
|
|
gtk_widget_show (arrow);
|
2020-09-28 15:30:30 +00:00
|
|
|
|
else
|
2021-01-19 19:00:21 +00:00
|
|
|
|
gtk_widget_hide (arrow);
|
2014-05-13 03:49:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-21 10:13:16 +00:00
|
|
|
|
static void
|
|
|
|
|
update_style_classes (GtkMenuButton *menu_button)
|
|
|
|
|
{
|
2021-09-03 11:18:06 +00:00
|
|
|
|
gboolean has_icon = menu_button->image_widget != NULL;
|
|
|
|
|
gboolean has_label = menu_button->label_widget != NULL;
|
|
|
|
|
gboolean has_only_arrow = menu_button->arrow_widget == gtk_button_get_child (GTK_BUTTON (menu_button->button));
|
|
|
|
|
gboolean has_arrow = gtk_widget_get_visible (menu_button->arrow_widget);
|
|
|
|
|
|
|
|
|
|
if (has_only_arrow || has_icon)
|
2021-06-21 10:13:16 +00:00
|
|
|
|
gtk_widget_add_css_class (menu_button->button, "image-button");
|
|
|
|
|
else
|
|
|
|
|
gtk_widget_remove_css_class (menu_button->button, "image-button");
|
|
|
|
|
|
2021-09-03 11:18:06 +00:00
|
|
|
|
if (has_label)
|
|
|
|
|
gtk_widget_add_css_class (menu_button->button, "text-button");
|
|
|
|
|
else
|
|
|
|
|
gtk_widget_remove_css_class (menu_button->button, "text-button");
|
|
|
|
|
|
|
|
|
|
if (has_arrow && !has_only_arrow)
|
2021-06-21 10:13:16 +00:00
|
|
|
|
gtk_widget_add_css_class (menu_button->button, "arrow-button");
|
|
|
|
|
else
|
|
|
|
|
gtk_widget_remove_css_class (menu_button->button, "arrow-button");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
update_arrow (GtkMenuButton *menu_button)
|
|
|
|
|
{
|
|
|
|
|
gboolean has_only_arrow, is_text_button;
|
|
|
|
|
|
|
|
|
|
if (menu_button->arrow_widget == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
has_only_arrow = menu_button->arrow_widget == gtk_button_get_child (GTK_BUTTON (menu_button->button));
|
|
|
|
|
is_text_button = menu_button->label_widget != NULL;
|
|
|
|
|
|
|
|
|
|
set_arrow_type (menu_button->arrow_widget,
|
|
|
|
|
menu_button->arrow_type,
|
|
|
|
|
has_only_arrow ||
|
|
|
|
|
((is_text_button || menu_button->always_show_arrow) &&
|
|
|
|
|
(menu_button->arrow_type != GTK_ARROW_NONE)));
|
|
|
|
|
|
|
|
|
|
update_style_classes (menu_button);
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-29 17:39:37 +00:00
|
|
|
|
static void
|
2020-03-28 04:35:13 +00:00
|
|
|
|
add_arrow (GtkMenuButton *self)
|
2012-05-29 17:39:37 +00:00
|
|
|
|
{
|
|
|
|
|
GtkWidget *arrow;
|
2014-12-15 09:29:11 +00:00
|
|
|
|
|
2021-01-19 19:00:21 +00:00
|
|
|
|
arrow = gtk_builtin_icon_new ("arrow");
|
2021-06-21 10:13:16 +00:00
|
|
|
|
gtk_widget_set_halign (arrow, GTK_ALIGN_CENTER);
|
2021-01-19 19:00:21 +00:00
|
|
|
|
set_arrow_type (arrow, self->arrow_type, TRUE);
|
2020-05-02 07:05:19 +00:00
|
|
|
|
gtk_button_set_child (GTK_BUTTON (self->button), arrow);
|
2020-03-28 04:35:13 +00:00
|
|
|
|
self->arrow_widget = arrow;
|
2012-05-29 17:39:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2020-03-28 04:35:13 +00:00
|
|
|
|
gtk_menu_button_init (GtkMenuButton *self)
|
2012-05-29 17:39:37 +00:00
|
|
|
|
{
|
2020-03-28 04:35:13 +00:00
|
|
|
|
self->arrow_type = GTK_ARROW_DOWN;
|
2012-05-29 17:39:37 +00:00
|
|
|
|
|
2020-03-28 04:35:13 +00:00
|
|
|
|
self->button = gtk_toggle_button_new ();
|
|
|
|
|
gtk_widget_set_parent (self->button, GTK_WIDGET (self));
|
|
|
|
|
g_signal_connect_swapped (self->button, "toggled", G_CALLBACK (gtk_menu_button_toggled), self);
|
|
|
|
|
add_arrow (self);
|
2021-06-21 10:13:16 +00:00
|
|
|
|
update_style_classes (self);
|
2012-09-01 03:10:30 +00:00
|
|
|
|
|
2020-03-28 04:35:13 +00:00
|
|
|
|
gtk_widget_set_sensitive (self->button, FALSE);
|
2015-10-30 04:54:37 +00:00
|
|
|
|
|
2020-03-28 04:35:13 +00:00
|
|
|
|
gtk_widget_add_css_class (GTK_WIDGET (self), "popup");
|
2021-09-14 12:26:18 +00:00
|
|
|
|
|
2021-09-17 16:26:00 +00:00
|
|
|
|
gtk_accessible_update_relation (GTK_ACCESSIBLE (self->button),
|
|
|
|
|
GTK_ACCESSIBLE_RELATION_LABELLED_BY, self, NULL,
|
|
|
|
|
GTK_ACCESSIBLE_RELATION_DESCRIBED_BY, self, NULL,
|
2021-09-14 12:26:18 +00:00
|
|
|
|
-1);
|
2012-05-29 17:39:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-03 11:18:06 +00:00
|
|
|
|
static GtkBuildableIface *parent_buildable_iface;
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_menu_button_buildable_add_child (GtkBuildable *buildable,
|
|
|
|
|
GtkBuilder *builder,
|
|
|
|
|
GObject *child,
|
|
|
|
|
const char *type)
|
|
|
|
|
{
|
|
|
|
|
if (GTK_IS_WIDGET (child))
|
|
|
|
|
gtk_menu_button_set_child (GTK_MENU_BUTTON (buildable), GTK_WIDGET (child));
|
|
|
|
|
else
|
|
|
|
|
parent_buildable_iface->add_child (buildable, builder, child, type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_menu_button_buildable_iface_init (GtkBuildableIface *iface)
|
|
|
|
|
{
|
|
|
|
|
parent_buildable_iface = g_type_interface_peek_parent (iface);
|
|
|
|
|
|
|
|
|
|
iface->add_child = gtk_menu_button_buildable_add_child;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-29 17:39:37 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_menu_button_new:
|
|
|
|
|
*
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* 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.
|
2012-05-29 17:39:37 +00:00
|
|
|
|
*
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* Returns: The newly created `GtkMenuButton`
|
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
|
2020-03-28 04:35:13 +00:00
|
|
|
|
update_sensitivity (GtkMenuButton *self)
|
2014-10-09 19:30:52 +00:00
|
|
|
|
{
|
2020-10-21 20:27:23 +00:00
|
|
|
|
gboolean has_popup;
|
|
|
|
|
|
|
|
|
|
has_popup = self->popover != NULL || self->create_popup_func != NULL;
|
|
|
|
|
|
|
|
|
|
gtk_widget_set_sensitive (self->button, has_popup);
|
|
|
|
|
|
|
|
|
|
gtk_accessible_update_property (GTK_ACCESSIBLE (self),
|
|
|
|
|
GTK_ACCESSIBLE_PROPERTY_HAS_POPUP, has_popup,
|
|
|
|
|
-1);
|
|
|
|
|
if (self->popover != NULL)
|
|
|
|
|
gtk_accessible_update_relation (GTK_ACCESSIBLE (self),
|
2020-11-10 14:14:47 +00:00
|
|
|
|
GTK_ACCESSIBLE_RELATION_CONTROLS, self->popover, NULL,
|
2020-10-21 20:27:23 +00:00
|
|
|
|
-1);
|
|
|
|
|
else
|
|
|
|
|
gtk_accessible_reset_relation (GTK_ACCESSIBLE (self),
|
|
|
|
|
GTK_ACCESSIBLE_RELATION_CONTROLS);
|
2014-10-09 19:30:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-27 03:41:47 +00:00
|
|
|
|
static gboolean
|
2020-03-28 04:35:13 +00:00
|
|
|
|
menu_deactivate_cb (GtkMenuButton *self)
|
2012-05-29 17:39:37 +00:00
|
|
|
|
{
|
2020-03-28 04:35:13 +00:00
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->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
|
|
|
|
/**
|
2021-02-25 17:23:28 +00:00
|
|
|
|
* gtk_menu_button_set_menu_model: (attributes org.gtk.Method.set_property=menu-model)
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* @menu_button: a `GtkMenuButton`
|
|
|
|
|
* @menu_model: (nullable): a `GMenuModel`, or %NULL to unset and disable the
|
2018-04-22 15:02:55 +00:00
|
|
|
|
* button
|
2012-05-29 17:39:37 +00:00
|
|
|
|
*
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* Sets the `GMenuModel` from which the popup will be constructed.
|
2012-05-29 17:39:37 +00:00
|
|
|
|
*
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* If @menu_model is %NULL, the button is disabled.
|
2012-05-29 17:39:37 +00:00
|
|
|
|
*
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* A [class@Gtk.Popover] will be created from the menu model with
|
|
|
|
|
* [ctor@Gtk.PopoverMenu.new_from_model]. Actions will be connected
|
|
|
|
|
* as documented for this function.
|
|
|
|
|
*
|
2021-02-25 17:23:28 +00:00
|
|
|
|
* If [property@Gtk.MenuButton: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
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
2020-02-24 12:21:46 +00:00
|
|
|
|
popover = gtk_popover_menu_new_from_model (menu_model);
|
2019-12-27 03:41:47 +00:00
|
|
|
|
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
|
|
|
|
|
2020-03-28 04:35:13 +00:00
|
|
|
|
menu_button->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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-25 17:23:28 +00:00
|
|
|
|
* gtk_menu_button_get_menu_model: (attributes org.gtk.Method.get_property=menu-model)
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* @menu_button: a `GtkMenuButton`
|
2012-05-29 17:39:37 +00:00
|
|
|
|
*
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* Returns the `GMenuModel` used to generate the popup.
|
2012-05-29 17:39:37 +00:00
|
|
|
|
*
|
2021-05-21 00:45:06 +00:00
|
|
|
|
* Returns: (nullable) (transfer none): a `GMenuModel`
|
2012-05-29 17:39:37 +00:00
|
|
|
|
*/
|
|
|
|
|
GMenuModel *
|
|
|
|
|
gtk_menu_button_get_menu_model (GtkMenuButton *menu_button)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_MENU_BUTTON (menu_button), NULL);
|
|
|
|
|
|
2020-03-28 04:35:13 +00:00
|
|
|
|
return menu_button->model;
|
2012-05-29 17:39:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-08 00:21:49 +00:00
|
|
|
|
static void
|
2020-03-28 04:35:13 +00:00
|
|
|
|
update_popover_direction (GtkMenuButton *self)
|
2014-02-08 00:21:49 +00:00
|
|
|
|
{
|
2020-03-28 04:35:13 +00:00
|
|
|
|
if (!self->popover)
|
2014-02-08 00:21:49 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2020-03-28 04:35:13 +00:00
|
|
|
|
switch (self->arrow_type)
|
2014-02-08 00:21:49 +00:00
|
|
|
|
{
|
|
|
|
|
case GTK_ARROW_UP:
|
2020-03-28 04:35:13 +00:00
|
|
|
|
gtk_popover_set_position (GTK_POPOVER (self->popover), GTK_POS_TOP);
|
2014-02-08 00:21:49 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_ARROW_DOWN:
|
|
|
|
|
case GTK_ARROW_NONE:
|
2020-03-28 04:35:13 +00:00
|
|
|
|
gtk_popover_set_position (GTK_POPOVER (self->popover), GTK_POS_BOTTOM);
|
2014-02-08 00:21:49 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_ARROW_LEFT:
|
2020-03-28 04:35:13 +00:00
|
|
|
|
gtk_popover_set_position (GTK_POPOVER (self->popover), GTK_POS_LEFT);
|
2014-02-08 00:21:49 +00:00
|
|
|
|
break;
|
|
|
|
|
case GTK_ARROW_RIGHT:
|
2020-03-28 04:35:13 +00:00
|
|
|
|
gtk_popover_set_position (GTK_POPOVER (self->popover), GTK_POS_RIGHT);
|
2014-02-08 00:21:49 +00:00
|
|
|
|
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
|
|
|
|
/**
|
2021-02-25 17:23:28 +00:00
|
|
|
|
* gtk_menu_button_set_direction: (attributes org.gtk.Method.set_property=direction)
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* @menu_button: a `GtkMenuButton`
|
|
|
|
|
* @direction: a `GtkArrowType`
|
|
|
|
|
*
|
|
|
|
|
* Sets the direction in which the popup will be popped up.
|
2012-05-29 17:39:37 +00:00
|
|
|
|
*
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* If the button is automatically populated with an arrow icon,
|
|
|
|
|
* its direction will be changed to match.
|
2012-05-29 17:39:37 +00:00
|
|
|
|
*
|
2014-02-08 00:21:49 +00:00
|
|
|
|
* If the does not fit in the available space in the given direction,
|
2020-09-12 16:01:04 +00:00
|
|
|
|
* 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)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_MENU_BUTTON (menu_button));
|
|
|
|
|
|
2020-03-28 04:35:13 +00:00
|
|
|
|
if (menu_button->arrow_type == direction)
|
2012-05-29 17:39:37 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2020-03-28 04:35:13 +00:00
|
|
|
|
menu_button->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
|
|
|
|
|
2021-06-21 10:13:16 +00:00
|
|
|
|
update_arrow (menu_button);
|
2014-02-08 00:21:49 +00:00
|
|
|
|
update_popover_direction (menu_button);
|
2012-05-29 17:39:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-25 17:23:28 +00:00
|
|
|
|
* gtk_menu_button_get_direction: (attributes org.gtk.Method.get_property=direction)
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* @menu_button: a `GtkMenuButton`
|
2012-05-29 17:39:37 +00:00
|
|
|
|
*
|
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
|
|
|
|
*
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* Returns: a `GtkArrowType` value
|
2012-05-29 17:39:37 +00:00
|
|
|
|
*/
|
|
|
|
|
GtkArrowType
|
|
|
|
|
gtk_menu_button_get_direction (GtkMenuButton *menu_button)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_MENU_BUTTON (menu_button), GTK_ARROW_DOWN);
|
|
|
|
|
|
2020-03-28 04:35:13 +00:00
|
|
|
|
return menu_button->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
|
|
|
|
{
|
2020-03-28 04:35:13 +00:00
|
|
|
|
GtkMenuButton *self = GTK_MENU_BUTTON (object);
|
2012-05-29 17:39:37 +00:00
|
|
|
|
|
2020-03-28 04:35:13 +00:00
|
|
|
|
if (self->popover)
|
2014-02-08 00:21:49 +00:00
|
|
|
|
{
|
2020-03-28 04:35:13 +00:00
|
|
|
|
g_signal_handlers_disconnect_by_func (self->popover,
|
2018-04-22 15:25:54 +00:00
|
|
|
|
menu_deactivate_cb,
|
|
|
|
|
object);
|
2020-03-28 04:35:13 +00:00
|
|
|
|
g_signal_handlers_disconnect_by_func (self->popover,
|
2018-04-22 15:25:07 +00:00
|
|
|
|
popover_destroy_cb,
|
|
|
|
|
object);
|
2020-03-28 04:35:13 +00:00
|
|
|
|
gtk_widget_unparent (self->popover);
|
|
|
|
|
self->popover = NULL;
|
2012-05-29 17:39:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 04:35:13 +00:00
|
|
|
|
g_clear_object (&self->model);
|
|
|
|
|
g_clear_pointer (&self->button, gtk_widget_unparent);
|
2012-05-29 17:39:37 +00:00
|
|
|
|
|
2020-03-28 04:35:13 +00:00
|
|
|
|
if (self->create_popup_destroy_notify)
|
|
|
|
|
self->create_popup_destroy_notify (self->create_popup_user_data);
|
2019-08-22 07:06:43 +00:00
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
/**
|
2021-02-25 17:23:28 +00:00
|
|
|
|
* gtk_menu_button_set_popover: (attributes org.gtk.Method.set_property=popover)
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* @menu_button: a `GtkMenuButton`
|
|
|
|
|
* @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.
|
2018-04-22 15:02:55 +00:00
|
|
|
|
*
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* If @popover is %NULL, the button is disabled.
|
2014-02-08 00:21:49 +00:00
|
|
|
|
*
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* If [property@Gtk.MenuButton: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)
|
|
|
|
|
{
|
|
|
|
|
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));
|
|
|
|
|
|
2020-03-28 04:35:13 +00:00
|
|
|
|
g_clear_object (&menu_button->model);
|
2014-02-08 00:21:49 +00:00
|
|
|
|
|
2020-03-28 04:35:13 +00:00
|
|
|
|
if (menu_button->popover)
|
2014-02-08 00:21:49 +00:00
|
|
|
|
{
|
2020-03-28 04:35:13 +00:00
|
|
|
|
if (gtk_widget_get_visible (menu_button->popover))
|
|
|
|
|
gtk_widget_hide (menu_button->popover);
|
2014-02-08 00:21:49 +00:00
|
|
|
|
|
2020-03-28 04:35:13 +00:00
|
|
|
|
g_signal_handlers_disconnect_by_func (menu_button->popover,
|
2014-02-08 00:21:49 +00:00
|
|
|
|
menu_deactivate_cb,
|
|
|
|
|
menu_button);
|
2020-03-28 04:35:13 +00:00
|
|
|
|
g_signal_handlers_disconnect_by_func (menu_button->popover,
|
2018-04-22 15:25:07 +00:00
|
|
|
|
popover_destroy_cb,
|
|
|
|
|
menu_button);
|
2014-12-18 03:56:30 +00:00
|
|
|
|
|
2020-03-28 04:35:13 +00:00
|
|
|
|
gtk_widget_unparent (menu_button->popover);
|
2014-02-08 00:21:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 04:35:13 +00:00
|
|
|
|
menu_button->popover = popover;
|
2014-02-08 00:21:49 +00:00
|
|
|
|
|
|
|
|
|
if (popover)
|
|
|
|
|
{
|
2020-03-28 04:35:13 +00:00
|
|
|
|
gtk_widget_set_parent (menu_button->popover, GTK_WIDGET (menu_button));
|
|
|
|
|
g_signal_connect_swapped (menu_button->popover, "closed",
|
2014-02-08 00:21:49 +00:00
|
|
|
|
G_CALLBACK (menu_deactivate_cb), menu_button);
|
2020-03-28 04:35:13 +00:00
|
|
|
|
g_signal_connect_swapped (menu_button->popover, "destroy",
|
2018-04-22 13:52:27 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-25 17:23:28 +00:00
|
|
|
|
* gtk_menu_button_get_popover: (attributes org.gtk.Method.get_property=popover)
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* @menu_button: a `GtkMenuButton`
|
2014-02-08 00:21:49 +00:00
|
|
|
|
*
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* Returns the `GtkPopover` that pops out of the button.
|
|
|
|
|
*
|
|
|
|
|
* If the button is not using a `GtkPopover`, this function
|
2014-02-08 00:21:49 +00:00
|
|
|
|
* returns %NULL.
|
|
|
|
|
*
|
2021-02-21 18:51:04 +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)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_MENU_BUTTON (menu_button), NULL);
|
|
|
|
|
|
2020-03-28 04:35:13 +00:00
|
|
|
|
return GTK_POPOVER (menu_button->popover);
|
2014-02-08 00:21:49 +00:00
|
|
|
|
}
|
2019-05-18 04:56:30 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2021-02-25 17:23:28 +00:00
|
|
|
|
* gtk_menu_button_set_icon_name: (attributes org.gtk.Method.set_property=icon-name)
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* @menu_button: a `GtkMenuButton`
|
2019-05-18 04:56:30 +00:00
|
|
|
|
* @icon_name: the icon name
|
|
|
|
|
*
|
|
|
|
|
* Sets the name of an icon to show inside the menu button.
|
2021-09-03 11:18:06 +00:00
|
|
|
|
*
|
|
|
|
|
* Setting icon name resets [property@Gtk.MenuButton:label] and
|
|
|
|
|
* [property@Gtk.MenuButton:child].
|
|
|
|
|
*
|
|
|
|
|
* If [property@Gtk.MenuButton:always-show-arrow] is set to `TRUE` and
|
|
|
|
|
* [property@Gtk.MenuButton:direction] is not `GTK_ARROW_NONE`, a dropdown arrow
|
|
|
|
|
* will be shown next to the icon.
|
2019-05-18 04:56:30 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_menu_button_set_icon_name (GtkMenuButton *menu_button,
|
|
|
|
|
const char *icon_name)
|
|
|
|
|
{
|
2021-06-21 10:13:16 +00:00
|
|
|
|
GtkWidget *box, *image_widget, *arrow;
|
|
|
|
|
|
2019-05-18 04:56:30 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_MENU_BUTTON (menu_button));
|
|
|
|
|
|
2021-06-21 09:08:14 +00:00
|
|
|
|
g_object_freeze_notify (G_OBJECT (menu_button));
|
|
|
|
|
|
|
|
|
|
if (gtk_menu_button_get_label (menu_button))
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (menu_button), menu_button_props[PROP_LABEL]);
|
|
|
|
|
|
2021-09-03 11:18:06 +00:00
|
|
|
|
if (gtk_menu_button_get_child (menu_button))
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (menu_button), menu_button_props[PROP_CHILD]);
|
|
|
|
|
|
2021-06-21 10:13:16 +00:00
|
|
|
|
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
|
|
|
|
gtk_widget_set_halign (box, GTK_ALIGN_CENTER);
|
|
|
|
|
|
2021-09-17 16:26:00 +00:00
|
|
|
|
/* Because we are setting only an icon, let the inner button be labelled by us
|
|
|
|
|
* so the accessible label can be overridden from, for example, an UI file
|
|
|
|
|
* using GtkMenuButton as a child of something.
|
|
|
|
|
*/
|
|
|
|
|
gtk_accessible_update_relation (GTK_ACCESSIBLE (menu_button->button),
|
|
|
|
|
GTK_ACCESSIBLE_RELATION_LABELLED_BY, menu_button, NULL,
|
2022-01-02 00:35:53 +00:00
|
|
|
|
GTK_ACCESSIBLE_RELATION_DESCRIBED_BY, menu_button, NULL,
|
2021-09-17 16:26:00 +00:00
|
|
|
|
-1);
|
2021-09-14 12:26:18 +00:00
|
|
|
|
|
2021-06-21 10:13:16 +00:00
|
|
|
|
image_widget = g_object_new (GTK_TYPE_IMAGE,
|
|
|
|
|
"accessible-role", GTK_ACCESSIBLE_ROLE_PRESENTATION,
|
|
|
|
|
"icon-name", icon_name,
|
|
|
|
|
NULL);
|
|
|
|
|
menu_button->image_widget = image_widget;
|
|
|
|
|
|
|
|
|
|
arrow = gtk_builtin_icon_new ("arrow");
|
|
|
|
|
menu_button->arrow_widget = arrow;
|
|
|
|
|
|
|
|
|
|
gtk_box_append (GTK_BOX (box), image_widget);
|
|
|
|
|
gtk_box_append (GTK_BOX (box), arrow);
|
|
|
|
|
gtk_button_set_child (GTK_BUTTON (menu_button->button), box);
|
|
|
|
|
|
|
|
|
|
menu_button->label_widget = NULL;
|
2021-09-03 11:18:06 +00:00
|
|
|
|
menu_button->child = NULL;
|
2021-06-21 10:13:16 +00:00
|
|
|
|
|
|
|
|
|
update_arrow (menu_button);
|
2021-06-21 09:08:14 +00:00
|
|
|
|
|
2019-05-18 04:56:30 +00:00
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (menu_button), menu_button_props[PROP_ICON_NAME]);
|
2021-06-21 09:08:14 +00:00
|
|
|
|
|
|
|
|
|
g_object_thaw_notify (G_OBJECT (menu_button));
|
2019-05-18 04:56:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-25 17:23:28 +00:00
|
|
|
|
* gtk_menu_button_get_icon_name: (attributes org.gtk.Method.get_property=icon-name)
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* @menu_button: a `GtkMenuButton`
|
2019-05-18 04:56:30 +00:00
|
|
|
|
*
|
|
|
|
|
* Gets the name of the icon shown in the button.
|
|
|
|
|
*
|
2022-01-01 17:38:56 +00:00
|
|
|
|
* Returns: (nullable): the name of the icon shown in the button
|
2019-05-18 04:56:30 +00:00
|
|
|
|
*/
|
|
|
|
|
const char *
|
|
|
|
|
gtk_menu_button_get_icon_name (GtkMenuButton *menu_button)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_MENU_BUTTON (menu_button), NULL);
|
|
|
|
|
|
2021-06-21 10:13:16 +00:00
|
|
|
|
if (menu_button->image_widget)
|
|
|
|
|
return gtk_image_get_icon_name (GTK_IMAGE (menu_button->image_widget));
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_menu_button_set_always_show_arrow: (attributes org.gtk.Method.set_property=always-show-arrow)
|
|
|
|
|
* @menu_button: a `GtkMenuButton`
|
|
|
|
|
* @always_show_arrow: hether to show a dropdown arrow even when using an icon
|
|
|
|
|
*
|
2021-09-03 11:18:06 +00:00
|
|
|
|
* Sets whether to show a dropdown arrow even when using an icon or a custom
|
|
|
|
|
* child.
|
2021-06-21 10:13:16 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 4.4
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_menu_button_set_always_show_arrow (GtkMenuButton *menu_button,
|
|
|
|
|
gboolean always_show_arrow)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_MENU_BUTTON (menu_button));
|
|
|
|
|
|
|
|
|
|
always_show_arrow = !!always_show_arrow;
|
|
|
|
|
|
|
|
|
|
if (always_show_arrow == menu_button->always_show_arrow)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
menu_button->always_show_arrow = always_show_arrow;
|
|
|
|
|
|
|
|
|
|
update_arrow (menu_button);
|
|
|
|
|
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (menu_button), menu_button_props[PROP_ALWAYS_SHOW_ARROW]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_menu_button_get_always_show_arrow: (attributes org.gtk.Method.get_property=always-show-arrow)
|
|
|
|
|
* @menu_button: a `GtkMenuButton`
|
|
|
|
|
*
|
|
|
|
|
* Gets whether to show a dropdown arrow even when using an icon.
|
|
|
|
|
*
|
|
|
|
|
* Returns: whether to show a dropdown arrow even when using an icon
|
|
|
|
|
*
|
|
|
|
|
* Since: 4.4
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gtk_menu_button_get_always_show_arrow (GtkMenuButton *menu_button)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_MENU_BUTTON (menu_button), FALSE);
|
|
|
|
|
|
|
|
|
|
return menu_button->always_show_arrow;
|
2019-05-18 04:56:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-25 17:23:28 +00:00
|
|
|
|
* gtk_menu_button_set_label: (attributes org.gtk.Method.set_property=label)
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* @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.
|
2021-09-03 11:18:06 +00:00
|
|
|
|
*
|
|
|
|
|
* Setting a label resets [property@Gtk.MenuButton:icon-name] and
|
|
|
|
|
* [property@Gtk.MenuButton:child].
|
|
|
|
|
*
|
|
|
|
|
* If [property@Gtk.MenuButton:direction] is not `GTK_ARROW_NONE`, a dropdown
|
|
|
|
|
* arrow will be shown next to the label.
|
2019-05-18 04:56:30 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_menu_button_set_label (GtkMenuButton *menu_button,
|
|
|
|
|
const char *label)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *box;
|
2020-03-28 02:28:49 +00:00
|
|
|
|
GtkWidget *label_widget;
|
2020-09-28 15:30:30 +00:00
|
|
|
|
GtkWidget *arrow;
|
2019-05-18 04:56:30 +00:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_MENU_BUTTON (menu_button));
|
|
|
|
|
|
2021-06-21 09:08:14 +00:00
|
|
|
|
g_object_freeze_notify (G_OBJECT (menu_button));
|
|
|
|
|
|
|
|
|
|
if (gtk_menu_button_get_icon_name (menu_button))
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (menu_button), menu_button_props[PROP_ICON_NAME]);
|
2021-09-03 11:18:06 +00:00
|
|
|
|
if (gtk_menu_button_get_child (menu_button))
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (menu_button), menu_button_props[PROP_CHILD]);
|
2021-06-21 09:08:14 +00:00
|
|
|
|
|
2021-06-24 18:12:31 +00:00
|
|
|
|
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
2020-03-28 02:28:49 +00:00
|
|
|
|
label_widget = gtk_label_new (label);
|
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label_widget), 0);
|
|
|
|
|
gtk_label_set_use_underline (GTK_LABEL (label_widget),
|
2020-03-28 04:35:13 +00:00
|
|
|
|
gtk_button_get_use_underline (GTK_BUTTON (menu_button->button)));
|
2020-03-28 02:28:49 +00:00
|
|
|
|
gtk_widget_set_hexpand (label_widget, TRUE);
|
2020-09-28 15:30:30 +00:00
|
|
|
|
gtk_widget_set_halign (label_widget, GTK_ALIGN_CENTER);
|
2021-01-19 19:00:21 +00:00
|
|
|
|
arrow = gtk_builtin_icon_new ("arrow");
|
2020-09-28 15:30:30 +00:00
|
|
|
|
menu_button->arrow_widget = arrow;
|
2020-05-09 12:26:52 +00:00
|
|
|
|
gtk_box_append (GTK_BOX (box), label_widget);
|
2020-09-28 15:30:30 +00:00
|
|
|
|
gtk_box_append (GTK_BOX (box), arrow);
|
2020-05-02 07:05:19 +00:00
|
|
|
|
gtk_button_set_child (GTK_BUTTON (menu_button->button), box);
|
2020-03-28 04:35:13 +00:00
|
|
|
|
menu_button->label_widget = label_widget;
|
2019-05-18 04:56:30 +00:00
|
|
|
|
|
2021-09-17 16:26:00 +00:00
|
|
|
|
gtk_accessible_update_relation (GTK_ACCESSIBLE (menu_button->button),
|
|
|
|
|
GTK_ACCESSIBLE_RELATION_LABELLED_BY, menu_button->label_widget, NULL,
|
2022-01-02 00:35:53 +00:00
|
|
|
|
GTK_ACCESSIBLE_RELATION_DESCRIBED_BY, menu_button->label_widget, NULL,
|
2021-09-17 16:26:00 +00:00
|
|
|
|
-1);
|
2021-09-14 12:26:18 +00:00
|
|
|
|
|
2021-06-21 10:13:16 +00:00
|
|
|
|
menu_button->image_widget = NULL;
|
2021-09-03 11:18:06 +00:00
|
|
|
|
menu_button->child = NULL;
|
2021-06-21 10:13:16 +00:00
|
|
|
|
|
|
|
|
|
update_arrow (menu_button);
|
|
|
|
|
|
2019-05-18 04:56:30 +00:00
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (menu_button), menu_button_props[PROP_LABEL]);
|
2021-06-21 09:08:14 +00:00
|
|
|
|
|
|
|
|
|
g_object_thaw_notify (G_OBJECT (menu_button));
|
2019-05-18 04:56:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-25 17:23:28 +00:00
|
|
|
|
* gtk_menu_button_get_label: (attributes org.gtk.Method.get_property=label)
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* @menu_button: a `GtkMenuButton`
|
2019-05-18 04:56:30 +00:00
|
|
|
|
*
|
|
|
|
|
* Gets the label shown in the button
|
|
|
|
|
*
|
2022-01-01 17:38:56 +00:00
|
|
|
|
* Returns: (nullable): the label shown in the button
|
2019-05-18 04:56:30 +00:00
|
|
|
|
*/
|
|
|
|
|
const char *
|
|
|
|
|
gtk_menu_button_get_label (GtkMenuButton *menu_button)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_MENU_BUTTON (menu_button), NULL);
|
|
|
|
|
|
2021-06-21 10:13:16 +00:00
|
|
|
|
if (menu_button->label_widget)
|
|
|
|
|
return gtk_label_get_label (GTK_LABEL (menu_button->label_widget));
|
2019-05-18 04:56:30 +00:00
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2019-05-21 22:39:03 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2021-02-25 17:23:28 +00:00
|
|
|
|
* gtk_menu_button_set_has_frame: (attributes org.gtk.Method.set_property=has-frame)
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* @menu_button: a `GtkMenuButton`
|
2020-04-17 04:31:50 +00:00
|
|
|
|
* @has_frame: whether the button should have a visible frame
|
2019-05-21 22:39:03 +00:00
|
|
|
|
*
|
2020-04-17 04:31:50 +00:00
|
|
|
|
* Sets the style of the button.
|
2019-05-21 22:39:03 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
2020-04-17 04:31:50 +00:00
|
|
|
|
gtk_menu_button_set_has_frame (GtkMenuButton *menu_button,
|
|
|
|
|
gboolean has_frame)
|
2019-05-21 22:39:03 +00:00
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_MENU_BUTTON (menu_button));
|
|
|
|
|
|
2020-04-17 04:20:09 +00:00
|
|
|
|
if (gtk_button_get_has_frame (GTK_BUTTON (menu_button->button)) == has_frame)
|
2019-05-21 22:39:03 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2020-04-17 04:20:09 +00:00
|
|
|
|
gtk_button_set_has_frame (GTK_BUTTON (menu_button->button), has_frame);
|
2020-04-17 04:31:50 +00:00
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (menu_button), menu_button_props[PROP_HAS_FRAME]);
|
2019-05-21 22:39:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-02-25 17:23:28 +00:00
|
|
|
|
* gtk_menu_button_get_has_frame: (attributes org.gtk.Method.get_property=has-frame)
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* @menu_button: a `GtkMenuButton`
|
2019-05-21 22:39:03 +00:00
|
|
|
|
*
|
2020-04-17 04:31:50 +00:00
|
|
|
|
* Returns whether the button has a frame.
|
2019-05-21 22:39:03 +00:00
|
|
|
|
*
|
2020-04-17 04:31:50 +00:00
|
|
|
|
* Returns: %TRUE if the button has a frame
|
2019-05-21 22:39:03 +00:00
|
|
|
|
*/
|
2020-04-17 04:31:50 +00:00
|
|
|
|
gboolean
|
|
|
|
|
gtk_menu_button_get_has_frame (GtkMenuButton *menu_button)
|
2019-05-21 22:39:03 +00:00
|
|
|
|
{
|
2020-04-17 04:31:50 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_MENU_BUTTON (menu_button), TRUE);
|
2019-05-21 22:39:03 +00:00
|
|
|
|
|
2020-04-17 04:31:50 +00:00
|
|
|
|
return gtk_button_get_has_frame (GTK_BUTTON (menu_button->button));
|
2019-05-21 22:39:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-24 00:30:39 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_menu_button_popup:
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* @menu_button: a `GtkMenuButton`
|
2019-05-24 00:30:39 +00:00
|
|
|
|
*
|
|
|
|
|
* Pop up the menu.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_menu_button_popup (GtkMenuButton *menu_button)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_MENU_BUTTON (menu_button));
|
|
|
|
|
|
2020-03-28 04:35:13 +00:00
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (menu_button->button), TRUE);
|
2019-05-24 00:30:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_menu_button_popdown:
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* @menu_button: a `GtkMenuButton`
|
2019-05-24 00:30:39 +00:00
|
|
|
|
*
|
|
|
|
|
* Dismiss the menu.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_menu_button_popdown (GtkMenuButton *menu_button)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_MENU_BUTTON (menu_button));
|
|
|
|
|
|
2020-03-28 04:35:13 +00:00
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (menu_button->button), FALSE);
|
2019-05-24 00:30:39 +00:00
|
|
|
|
}
|
2019-06-13 19:31:48 +00:00
|
|
|
|
|
2019-08-22 07:06:43 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_menu_button_set_create_popup_func:
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* @menu_button: a `GtkMenuButton`
|
|
|
|
|
* @func: (nullable): function to call when a popup is about to
|
2019-08-22 07:06:43 +00:00
|
|
|
|
* 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.
|
2021-02-21 18:51:04 +00:00
|
|
|
|
*
|
2019-08-22 07:06:43 +00:00
|
|
|
|
* @func should use one of
|
|
|
|
|
*
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* - [method@Gtk.MenuButton.set_popover]
|
|
|
|
|
* - [method@Gtk.MenuButton.set_menu_model]
|
2019-08-22 07:06:43 +00:00
|
|
|
|
*
|
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.
|
|
|
|
|
*
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* Using this function will not reset the menu widget attached to
|
|
|
|
|
* @menu_button. Instead, this can be done manually in @func.
|
2019-08-22 07:06:43 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_menu_button_set_create_popup_func (GtkMenuButton *menu_button,
|
|
|
|
|
GtkMenuButtonCreatePopupFunc func,
|
|
|
|
|
gpointer user_data,
|
|
|
|
|
GDestroyNotify destroy_notify)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_MENU_BUTTON (menu_button));
|
|
|
|
|
|
2020-03-28 04:35:13 +00:00
|
|
|
|
if (menu_button->create_popup_destroy_notify)
|
|
|
|
|
menu_button->create_popup_destroy_notify (menu_button->create_popup_user_data);
|
2019-08-22 07:06:43 +00:00
|
|
|
|
|
2020-03-28 04:35:13 +00:00
|
|
|
|
menu_button->create_popup_func = func;
|
|
|
|
|
menu_button->create_popup_user_data = user_data;
|
|
|
|
|
menu_button->create_popup_destroy_notify = destroy_notify;
|
2019-08-22 07:06:43 +00:00
|
|
|
|
|
|
|
|
|
update_sensitivity (menu_button);
|
|
|
|
|
}
|
2020-03-28 02:28:49 +00:00
|
|
|
|
|
2020-04-20 02:50:35 +00:00
|
|
|
|
/**
|
2021-02-25 17:23:28 +00:00
|
|
|
|
* gtk_menu_button_set_use_underline: (attributes org.gtk.Method.set_property=use-underline)
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* @menu_button: a `GtkMenuButton`
|
2020-04-20 02:50:35 +00:00
|
|
|
|
* @use_underline: %TRUE if underlines in the text indicate mnemonics
|
|
|
|
|
*
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* If true, an underline in the text indicates a mnemonic.
|
2020-04-20 02:50:35 +00:00
|
|
|
|
*/
|
2020-03-28 02:28:49 +00:00
|
|
|
|
void
|
|
|
|
|
gtk_menu_button_set_use_underline (GtkMenuButton *menu_button,
|
|
|
|
|
gboolean use_underline)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_MENU_BUTTON (menu_button));
|
|
|
|
|
|
2020-03-28 04:35:13 +00:00
|
|
|
|
if (gtk_button_get_use_underline (GTK_BUTTON (menu_button->button)) == use_underline)
|
2020-03-28 02:28:49 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2020-03-28 04:35:13 +00:00
|
|
|
|
gtk_button_set_use_underline (GTK_BUTTON (menu_button->button), use_underline);
|
|
|
|
|
if (menu_button->label_widget)
|
|
|
|
|
gtk_label_set_use_underline (GTK_LABEL (menu_button->label_widget), use_underline);
|
2020-03-28 02:28:49 +00:00
|
|
|
|
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (menu_button), menu_button_props[PROP_USE_UNDERLINE]);
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-20 02:50:35 +00:00
|
|
|
|
/**
|
2021-02-25 17:23:28 +00:00
|
|
|
|
* gtk_menu_button_get_use_underline: (attributes org.gtk.Method.get_property=use-underline)
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* @menu_button: a `GtkMenuButton`
|
2020-04-20 02:50:35 +00:00
|
|
|
|
*
|
2021-02-25 17:23:28 +00:00
|
|
|
|
* Returns whether an embedded underline in the text indicates a
|
2021-02-21 18:51:04 +00:00
|
|
|
|
* mnemonic.
|
2020-04-20 02:50:35 +00:00
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE whether an embedded underline in the text indicates
|
2021-05-18 21:05:26 +00:00
|
|
|
|
* the mnemonic accelerator keys.
|
2020-04-20 02:50:35 +00:00
|
|
|
|
*/
|
2020-03-28 02:28:49 +00:00
|
|
|
|
gboolean
|
|
|
|
|
gtk_menu_button_get_use_underline (GtkMenuButton *menu_button)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_MENU_BUTTON (menu_button), FALSE);
|
|
|
|
|
|
2020-03-28 04:35:13 +00:00
|
|
|
|
return gtk_button_get_use_underline (GTK_BUTTON (menu_button->button));
|
2020-03-28 02:28:49 +00:00
|
|
|
|
}
|
2021-05-24 21:27:40 +00:00
|
|
|
|
|
|
|
|
|
static GList *
|
|
|
|
|
get_menu_bars (GtkWindow *window)
|
|
|
|
|
{
|
|
|
|
|
return g_object_get_data (G_OBJECT (window), "gtk-menu-bar-list");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
GtkMenuButton *button)
|
|
|
|
|
{
|
|
|
|
|
GList *menubars = get_menu_bars (window);
|
|
|
|
|
|
|
|
|
|
set_menu_bars (window, g_list_prepend (menubars, button));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
remove_from_window (GtkWindow *window,
|
|
|
|
|
GtkMenuButton *button)
|
|
|
|
|
{
|
|
|
|
|
GList *menubars = get_menu_bars (window);
|
|
|
|
|
|
|
|
|
|
menubars = g_list_remove (menubars, button);
|
|
|
|
|
set_menu_bars (window, menubars);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_menu_button_root (GtkWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
GtkMenuButton *button = GTK_MENU_BUTTON (widget);
|
|
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_menu_button_parent_class)->root (widget);
|
|
|
|
|
|
|
|
|
|
if (button->primary)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *toplevel = GTK_WIDGET (gtk_widget_get_root (widget));
|
|
|
|
|
add_to_window (GTK_WINDOW (toplevel), button);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_menu_button_unroot (GtkWidget *widget)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *toplevel;
|
|
|
|
|
|
|
|
|
|
toplevel = GTK_WIDGET (gtk_widget_get_root (widget));
|
|
|
|
|
remove_from_window (GTK_WINDOW (toplevel), GTK_MENU_BUTTON (widget));
|
|
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_menu_button_parent_class)->unroot (widget);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_menu_button_set_primary: (attributes org.gtk.Method.set_property=primary)
|
|
|
|
|
* @menu_button: a `GtkMenuButton`
|
|
|
|
|
* @primary: whether the menubutton should act as a primary menu
|
|
|
|
|
*
|
|
|
|
|
* Sets whether menu button acts as a primary menu.
|
|
|
|
|
*
|
|
|
|
|
* Primary menus can be opened with the <kbd>F10</kbd> key.
|
2021-07-13 07:31:00 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 4.4
|
2021-05-24 21:27:40 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_menu_button_set_primary (GtkMenuButton *menu_button,
|
|
|
|
|
gboolean primary)
|
|
|
|
|
{
|
|
|
|
|
GtkRoot *toplevel;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_MENU_BUTTON (menu_button));
|
|
|
|
|
|
|
|
|
|
if (menu_button->primary == primary)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
menu_button->primary = primary;
|
|
|
|
|
toplevel = gtk_widget_get_root (GTK_WIDGET (menu_button));
|
|
|
|
|
|
|
|
|
|
if (toplevel)
|
|
|
|
|
{
|
|
|
|
|
if (menu_button->primary)
|
|
|
|
|
add_to_window (GTK_WINDOW (toplevel), menu_button);
|
|
|
|
|
else
|
|
|
|
|
remove_from_window (GTK_WINDOW (toplevel), menu_button);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (menu_button), menu_button_props[PROP_PRIMARY]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_menu_button_get_primary: (attributes org.gtk.Method.get_property=primary)
|
|
|
|
|
* @menu_button: a `GtkMenuButton`
|
|
|
|
|
*
|
|
|
|
|
* Returns whether the menu button acts as a primary menu.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if the button is a primary menu
|
2021-07-07 16:18:28 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 4.4
|
2021-05-24 21:27:40 +00:00
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gtk_menu_button_get_primary (GtkMenuButton *menu_button)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_MENU_BUTTON (menu_button), FALSE);
|
|
|
|
|
|
|
|
|
|
return menu_button->primary;
|
|
|
|
|
}
|
2021-09-03 11:18:06 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_menu_button_set_child: (attributes org.gtk.Method.set_property=child)
|
|
|
|
|
* @menu_button: a `GtkMenuButton`
|
|
|
|
|
* @child: (nullable): the child widget
|
|
|
|
|
*
|
|
|
|
|
* Sets the child widget of @menu_button.
|
|
|
|
|
*
|
|
|
|
|
* Setting a child resets [property@Gtk.MenuButton:label] and
|
|
|
|
|
* [property@Gtk.MenuButton:icon-name].
|
|
|
|
|
*
|
|
|
|
|
* If [property@Gtk.MenuButton:always-show-arrow] is set to `TRUE` and
|
|
|
|
|
* [property@Gtk.MenuButton:direction] is not `GTK_ARROW_NONE`, a dropdown arrow
|
|
|
|
|
* will be shown next to the child.
|
|
|
|
|
*
|
|
|
|
|
* Since: 4.6
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_menu_button_set_child (GtkMenuButton *menu_button,
|
|
|
|
|
GtkWidget *child)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *box, *arrow;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_MENU_BUTTON (menu_button));
|
|
|
|
|
g_return_if_fail (child == NULL || GTK_IS_WIDGET (child));
|
|
|
|
|
|
|
|
|
|
g_object_freeze_notify (G_OBJECT (menu_button));
|
|
|
|
|
|
|
|
|
|
if (gtk_menu_button_get_label (menu_button))
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (menu_button), menu_button_props[PROP_LABEL]);
|
|
|
|
|
if (gtk_menu_button_get_icon_name (menu_button))
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (menu_button), menu_button_props[PROP_ICON_NAME]);
|
|
|
|
|
|
|
|
|
|
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
|
|
|
|
gtk_widget_set_halign (box, GTK_ALIGN_CENTER);
|
|
|
|
|
|
|
|
|
|
arrow = gtk_builtin_icon_new ("arrow");
|
|
|
|
|
menu_button->arrow_widget = arrow;
|
|
|
|
|
|
|
|
|
|
gtk_box_append (GTK_BOX (box), child);
|
|
|
|
|
gtk_box_append (GTK_BOX (box), arrow);
|
|
|
|
|
gtk_button_set_child (GTK_BUTTON (menu_button->button), box);
|
|
|
|
|
|
|
|
|
|
menu_button->child = child;
|
|
|
|
|
|
|
|
|
|
menu_button->image_widget = NULL;
|
|
|
|
|
menu_button->label_widget = NULL;
|
|
|
|
|
|
|
|
|
|
update_arrow (menu_button);
|
|
|
|
|
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (menu_button), menu_button_props[PROP_CHILD]);
|
|
|
|
|
|
|
|
|
|
g_object_thaw_notify (G_OBJECT (menu_button));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_menu_button_get_child: (attributes org.gtk.Method.get_property=child)
|
|
|
|
|
* @menu_button: a `GtkMenuButton`
|
|
|
|
|
*
|
|
|
|
|
* Gets the child widget of @menu_button.
|
|
|
|
|
*
|
|
|
|
|
* Returns: (nullable) (transfer none): the child widget of @menu_button
|
|
|
|
|
*
|
|
|
|
|
* Since: 4.6
|
|
|
|
|
*/
|
|
|
|
|
GtkWidget *
|
|
|
|
|
gtk_menu_button_get_child (GtkMenuButton *menu_button)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_MENU_BUTTON (menu_button), NULL);
|
|
|
|
|
|
|
|
|
|
return menu_button->child;
|
|
|
|
|
}
|