[gtk+/wip/garnacho/window-dragging: 8/9] gtkmenubutton: Popup menu/popover on GtkButton:clicked
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/garnacho/window-dragging: 8/9] gtkmenubutton: Popup menu/popover on GtkButton:clicked
- Date: Thu, 26 Feb 2015 13:36:13 +0000 (UTC)
commit aca9651cddb7ff44e8d27c8e0dbca1d9df3fe98f
Author: Carlos Garnacho <carlosg gnome org>
Date: Wed Feb 25 20:31:09 2015 +0100
gtkmenubutton: Popup menu/popover on GtkButton:clicked
This happens on button release, which is more convenient if the gesture
can be consumed by something else (eg. window dragging), and already behaves
correctly wrt cancelled gestures, broken grabs, etc.
gtk/gtkmenubutton.c | 41 +++++++++++++++++++++--------------------
1 files changed, 21 insertions(+), 20 deletions(-)
---
diff --git a/gtk/gtkmenubutton.c b/gtk/gtkmenubutton.c
index de06bf1..e3935a8 100644
--- a/gtk/gtkmenubutton.c
+++ b/gtk/gtkmenubutton.c
@@ -132,6 +132,7 @@ struct _GtkMenuButtonPrivate
GtkWidget *arrow_widget;
GtkArrowType arrow_type;
gboolean use_popover;
+ guint press_handled : 1;
};
enum
@@ -433,32 +434,30 @@ gtk_menu_button_toggled (GtkToggleButton *button)
gtk_widget_set_visible (priv->popover, active);
}
-static gboolean
-gtk_menu_button_button_press_event (GtkWidget *widget,
- GdkEventButton *event)
+static void
+gtk_menu_button_clicked (GtkButton *button)
{
- GtkMenuButton *menu_button = GTK_MENU_BUTTON (widget);
+ GtkMenuButton *menu_button = GTK_MENU_BUTTON (button);
GtkMenuButtonPrivate *priv = menu_button->priv;
+ gboolean active = TRUE;
- if (event->button == GDK_BUTTON_PRIMARY)
+ if (priv->menu && !gtk_widget_get_visible (priv->menu))
{
- /* Filter out double/triple clicks */
- if (event->type != GDK_BUTTON_PRESS)
- return TRUE;
-
- if (priv->menu && !gtk_widget_get_visible (priv->menu))
- popup_menu (menu_button, event);
- else if (priv->popover && !gtk_widget_get_visible (priv->popover))
- gtk_widget_show (priv->popover);
- else
- return TRUE;
+ GdkEvent *event;
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
-
- return TRUE;
+ event = gtk_get_current_event ();
+ popup_menu (menu_button, &event->button);
+ gdk_event_free (event);
}
+ else if (priv->popover && !gtk_widget_get_visible (priv->popover))
+ gtk_widget_show (priv->popover);
+ else
+ active = FALSE;
- return GTK_WIDGET_CLASS (gtk_menu_button_parent_class)->button_press_event (widget, event);
+ 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));
}
static void
@@ -491,6 +490,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;
@@ -498,11 +498,12 @@ gtk_menu_button_class_init (GtkMenuButtonClass *klass)
gobject_class->dispose = gtk_menu_button_dispose;
widget_class->state_flags_changed = gtk_menu_button_state_flags_changed;
- widget_class->button_press_event = gtk_menu_button_button_press_event;
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;
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]