[gtk+/gtk-3-20] GtkMenuButton: use :toggled instead of :clicked
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/gtk-3-20] GtkMenuButton: use :toggled instead of :clicked
- Date: Thu, 4 Aug 2016 21:44:36 +0000 (UTC)
commit 10c3a2483635d1c1bd140f5623ec0fee5970535a
Author: Colomban Wendling <ban herbesfolles org>
Date: Fri Jul 29 00:39:30 2016 +0200
GtkMenuButton: use :toggled instead of :clicked
:toggled is triggered on :clicked, so using :toggled lead to the menu
to be popped up at the same time, while allowing to use the toggle state
and avoiding any need to a hack to prevent recursion, which somehow
wasn't enough for double emission of GtkMenuToolButton:show-popup.
https://bugzilla.gnome.org/show_bug.cgi?id=769287
gtk/gtkmenubutton.c | 27 +++++++--------------------
1 files changed, 7 insertions(+), 20 deletions(-)
---
diff --git a/gtk/gtkmenubutton.c b/gtk/gtkmenubutton.c
index 79aece0..cd3d099 100644
--- a/gtk/gtkmenubutton.c
+++ b/gtk/gtkmenubutton.c
@@ -137,7 +137,6 @@ struct _GtkMenuButtonPrivate
GtkArrowType arrow_type;
gboolean use_popover;
guint press_handled : 1;
- guint in_click : 1;
};
enum
@@ -431,21 +430,15 @@ popup_menu (GtkMenuButton *menu_button,
}
static void
-gtk_menu_button_clicked (GtkButton *button)
+gtk_menu_button_toggled (GtkToggleButton *button)
{
GtkMenuButton *menu_button = GTK_MENU_BUTTON (button);
GtkMenuButtonPrivate *priv = menu_button->priv;
- gboolean active;
-
- if (priv->in_click)
- return;
-
- priv->in_click = TRUE;
+ gboolean active = gtk_toggle_button_get_active (button);
if (priv->menu)
{
- active = !gtk_widget_get_visible (priv->menu);
- if (active)
+ if (active && !gtk_widget_get_visible (priv->menu))
{
GdkEvent *event;
@@ -464,20 +457,14 @@ gtk_menu_button_clicked (GtkButton *button)
}
else if (priv->popover)
{
- active = !gtk_widget_get_visible (priv->popover);
if (active)
gtk_widget_show (priv->popover);
else
gtk_widget_hide (priv->popover);
}
- else
- active = FALSE;
-
- GTK_BUTTON_CLASS (gtk_menu_button_parent_class)->clicked (button);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), active);
- gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON (button));
- priv->in_click = FALSE;
+ if (GTK_TOGGLE_BUTTON_CLASS (gtk_menu_button_parent_class)->toggled)
+ GTK_TOGGLE_BUTTON_CLASS (gtk_menu_button_parent_class)->toggled (button);
}
static void
@@ -510,7 +497,7 @@ gtk_menu_button_class_init (GtkMenuButtonClass *klass)
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
- GtkButtonClass *button_class = GTK_BUTTON_CLASS (klass);
+ GtkToggleButtonClass *toggle_button_class = GTK_TOGGLE_BUTTON_CLASS (klass);
gobject_class->set_property = gtk_menu_button_set_property;
gobject_class->get_property = gtk_menu_button_get_property;
@@ -521,7 +508,7 @@ gtk_menu_button_class_init (GtkMenuButtonClass *klass)
container_class->add = gtk_menu_button_add;
container_class->remove = gtk_menu_button_remove;
- button_class->clicked = gtk_menu_button_clicked;
+ toggle_button_class->toggled = gtk_menu_button_toggled;
/**
* GtkMenuButton:popup:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]