diff options
Diffstat (limited to 'widgets')
-rw-r--r-- | widgets/misc/ChangeLog | 13 | ||||
-rw-r--r-- | widgets/misc/e-dropdown-button.c | 57 | ||||
-rw-r--r-- | widgets/misc/e-dropdown-button.h | 6 |
3 files changed, 60 insertions, 16 deletions
diff --git a/widgets/misc/ChangeLog b/widgets/misc/ChangeLog index 3a3cb1f9f0..ccd2c1828c 100644 --- a/widgets/misc/ChangeLog +++ b/widgets/misc/ChangeLog @@ -1,3 +1,16 @@ +2001-01-28 Ettore Perazzoli <ettore@ximian.com> + + * e-dropdown-button.c (menu_deactivate_cb): New function to change + the state of the toggle button when the pop-up menu disappears. + (impl_clicked): Removed. + (impl_button_press_event): New, implementation for + `::button_press_event'. Pop-up the menu, and toggle the button. + (class_init): Override `::button_press_event' with + `impl_button_press_event'; don't override `::clicked' anymore. + + * e-dropdown-button.h, e-dropdown-button.c: Derive from + `GtkToggleButton', instead of plain `GtkButton'. + 2001-01-27 Ettore Perazzoli <ettore@ximian.com> * e-search-bar.c (add_dropdown): Make the dropdown button 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)); } /** diff --git a/widgets/misc/e-dropdown-button.h b/widgets/misc/e-dropdown-button.h index 584cb0365b..6e3043f70e 100644 --- a/widgets/misc/e-dropdown-button.h +++ b/widgets/misc/e-dropdown-button.h @@ -28,7 +28,7 @@ #include <config.h> #endif -#include <gtk/gtkbutton.h> +#include <gtk/gtktogglebutton.h> #include <gtk/gtkmenu.h> #include <gnome.h> @@ -50,13 +50,13 @@ typedef struct _EDropdownButtonPrivate EDropdownButtonPrivate; typedef struct _EDropdownButtonClass EDropdownButtonClass; struct _EDropdownButton { - GtkButton parent; + GtkToggleButton parent; EDropdownButtonPrivate *priv; }; struct _EDropdownButtonClass { - GtkButtonClass parent_class; + GtkToggleButtonClass parent_class; }; |