summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColomban Wendling <ban@herbesfolles.org>2016-07-29 00:39:30 +0200
committerCarlos Garnacho <carlosg@gnome.org>2016-08-04 23:31:42 +0200
commit64521345b9480cce790e0b299ffa20b44d9461ff (patch)
tree66ff14d3455556da3f65995c3d653ffd3ecbaf38
parent41be1e7e1fec1d744e70b8c6bc21b2ca3812e4e0 (diff)
downloadgtk+-64521345b9480cce790e0b299ffa20b44d9461ff.tar.gz
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
-rw-r--r--gtk/gtkmenubutton.c27
1 files changed, 7 insertions, 20 deletions
diff --git a/gtk/gtkmenubutton.c b/gtk/gtkmenubutton.c
index 347cf25b6b..c27cff9b41 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
@@ -395,21 +394,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;
@@ -428,20 +421,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
@@ -474,7 +461,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;
@@ -485,7 +472,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: