Re: scrollwheel support in GtkOptionMenu.
- From: Owen Taylor <otaylor redhat com>
- To: Alex Larsson <alexl redhat com>
- Cc: <gtk-devel-list gnome org>
- Subject: Re: scrollwheel support in GtkOptionMenu.
- Date: 16 Sep 2001 19:10:26 -0400
Alex Larsson <alexl redhat com> writes:
> Here is a short patch that allows you to change the active GtkOptionMenu
> item by using the mouse scroll-wheel.
>
> Ok to commit this?
Hmm, I think you should to take care of the possibility of insensitive
and invisible items in the menu.
Regards,
Owen
> Index: gtkoptionmenu.c
> ===================================================================
> RCS file: /cvs/gnome/gtk+/gtk/gtkoptionmenu.c,v
> retrieving revision 1.51
> diff -u -p -r1.51 gtkoptionmenu.c
> --- gtkoptionmenu.c 2001/08/17 16:33:04 1.51
> +++ gtkoptionmenu.c 2001/09/16 21:44:05
> @@ -80,6 +80,8 @@ static void gtk_option_menu_position
> static void gtk_option_menu_show_all (GtkWidget *widget);
> static void gtk_option_menu_hide_all (GtkWidget *widget);
> static GtkType gtk_option_menu_child_type (GtkContainer *container);
> +static gint gtk_option_menu_scroll_event (GtkWidget *widget,
> + GdkEventScroll *event);
>
> enum
> {
> @@ -147,6 +149,7 @@ gtk_option_menu_class_init (GtkOptionMen
> widget_class->expose_event = gtk_option_menu_expose;
> widget_class->button_press_event = gtk_option_menu_button_press;
> widget_class->key_press_event = gtk_option_menu_key_press;
> + widget_class->scroll_event = gtk_option_menu_scroll_event;
> widget_class->show_all = gtk_option_menu_show_all;
> widget_class->hide_all = gtk_option_menu_hide_all;
>
> @@ -881,5 +884,33 @@ gtk_option_menu_hide_all (GtkWidget *wid
>
> gtk_widget_hide (widget);
> gtk_container_foreach (container, (GtkCallback) gtk_widget_hide_all, NULL);
> +}
> +
> +static gint
> +gtk_option_menu_scroll_event (GtkWidget *widget,
> + GdkEventScroll *event)
> +{
> + GtkOptionMenu *option_menu = GTK_OPTION_MENU (widget);
> + gint index;
> + gint n_children;
> +
> + index = gtk_option_menu_get_history (option_menu);
> +
> + if (index != -1)
> + {
> + n_children = g_list_length (GTK_MENU_SHELL (option_menu->menu)->children);
> +
> + if (event->direction == GDK_SCROLL_UP)
> + index--;
> + else
> + index++;
> +
> + index = MAX (index, 0);
> + index = MIN (index, n_children - 1);
> +
> + gtk_option_menu_set_history (option_menu, index);
> + }
> +
> + return TRUE;
> }
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]