aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/misc/e-dropdown-button.c
diff options
context:
space:
mode:
authorEttore Perazzoli <ettore@src.gnome.org>2001-01-28 17:58:37 +0800
committerEttore Perazzoli <ettore@src.gnome.org>2001-01-28 17:58:37 +0800
commit50fea9ab7e0038db89b5d24e86dc03171312b2d1 (patch)
treedf48c884ba44d1c3e2e1d6eb360fc7ab8d2b1f43 /widgets/misc/e-dropdown-button.c
parent426c551eeed2096cb0de0b451adc1d84b055034f (diff)
downloadgsoc2013-evolution-50fea9ab7e0038db89b5d24e86dc03171312b2d1.tar
gsoc2013-evolution-50fea9ab7e0038db89b5d24e86dc03171312b2d1.tar.gz
gsoc2013-evolution-50fea9ab7e0038db89b5d24e86dc03171312b2d1.tar.bz2
gsoc2013-evolution-50fea9ab7e0038db89b5d24e86dc03171312b2d1.tar.lz
gsoc2013-evolution-50fea9ab7e0038db89b5d24e86dc03171312b2d1.tar.xz
gsoc2013-evolution-50fea9ab7e0038db89b5d24e86dc03171312b2d1.tar.zst
gsoc2013-evolution-50fea9ab7e0038db89b5d24e86dc03171312b2d1.zip
Changed the EDropdownButton so that it works more like a standard menu
bar (i.e. the menu is popped up on button_press instead of button_release). Now it is also based on GtkToggleButton, so it stays pushed down when the menu is on the screen. svn path=/trunk/; revision=7869
Diffstat (limited to 'widgets/misc/e-dropdown-button.c')
-rw-r--r--widgets/misc/e-dropdown-button.c57
1 files changed, 44 insertions, 13 deletions
diff --git a/widgets/misc/e-dropdown-button.c b/widgets/misc/e-dropdown-button.c
index c9aba7048e..6696d0a134 100644
--- a/widgets/misc/e-dropdown-button.c
+++ b/widgets/misc/e-dropdown-button.c
@@ -39,8 +39,8 @@ struct _EDropdownButtonPrivate {
GtkWidget *menu;
};
-#define PARENT_TYPE gtk_button_get_type ()
-static GtkButtonClass *parent_class = NULL;
+#define PARENT_TYPE gtk_toggle_button_get_type ()
+static GtkToggleButtonClass *parent_class = NULL;
/* Callback to position the pop-up menu. */
@@ -72,6 +72,24 @@ menu_position_cb (GtkMenu *menu,
*y = CLAMP (*y, 0, max_y);
}
+/* Callback for the "deactivate" signal on the pop-up menu. This is used so
+ that we unset the state of the toggle button when the pop-up menu
+ disappears. */
+
+static int
+menu_deactivate_cb (GtkMenuShell *menu_shell,
+ void *data)
+{
+ EDropdownButton *dropdown_button;
+
+ puts (__FUNCTION__);
+
+ dropdown_button = E_DROPDOWN_BUTTON (data);
+
+ gtk_button_clicked (GTK_BUTTON (dropdown_button));
+ return TRUE;
+}
+
/* GtkObject methods. */
@@ -91,23 +109,32 @@ impl_destroy (GtkObject *object)
}
-/* GtkButton methods. */
+/* GtkWidget methods. */
-static void
-impl_clicked (GtkButton *button)
+static int
+impl_button_press_event (GtkWidget *widget,
+ GdkEventButton *event)
{
EDropdownButton *dropdown_button;
EDropdownButtonPrivate *priv;
+ GtkStateType new_state;
- dropdown_button = E_DROPDOWN_BUTTON (button);
+ dropdown_button = E_DROPDOWN_BUTTON (widget);
priv = dropdown_button->priv;
- if (GTK_BUTTON_CLASS (parent_class)->clicked != NULL)
- (* GTK_BUTTON_CLASS (parent_class)->clicked) (button);
-
gtk_menu_popup (GTK_MENU (priv->menu), NULL, NULL,
menu_position_cb, dropdown_button,
1, GDK_CURRENT_TIME);
+
+ gnome_popup_menu_do_popup (GTK_WIDGET (priv->menu), menu_position_cb, dropdown_button,
+ event, NULL);
+
+ if (! GTK_WIDGET_HAS_FOCUS (widget))
+ gtk_widget_grab_focus (widget);
+
+ gtk_button_clicked (GTK_BUTTON (widget));
+
+ return TRUE;
}
@@ -115,16 +142,16 @@ static void
class_init (EDropdownButtonClass *klass)
{
GtkObjectClass *object_class;
- GtkButtonClass *button_class;
+ GtkWidgetClass *widget_class;
object_class = GTK_OBJECT_CLASS (klass);
- button_class = GTK_BUTTON_CLASS (klass);
+ widget_class = GTK_WIDGET_CLASS (klass);
object_class->destroy = impl_destroy;
- button_class->clicked = impl_clicked;
+ widget_class->button_press_event = impl_button_press_event;
- parent_class = gtk_type_class (gtk_button_get_type ());
+ parent_class = gtk_type_class (PARENT_TYPE);
}
@@ -176,6 +203,10 @@ e_dropdown_button_construct (EDropdownButton *dropdown_button,
gtk_widget_show (arrow);
priv->menu = GTK_WIDGET (menu);
+
+ gtk_signal_connect_while_alive (GTK_OBJECT (priv->menu), "deactivate",
+ GTK_SIGNAL_FUNC (menu_deactivate_cb),
+ dropdown_button, GTK_OBJECT (dropdown_button));
}
/**