Re: PATCH for tab-scrolling



Hi Gabriel,

I cleaned up your patch a bit; hope you don't mind!  :-)

Since patches against patches just look silly, I put notes about what I
changed below and attached the modified patch.

Gabriel de Perthuis <Gabriel de-Perthuis laPoste net> writes:

> This allows to switch between tabs using the mouse-wheel, something I
> missed a lot.  It adds an event handler in gtknotebook.c, in
> gtk-src-dir/gtk. I made it on gtk+-2.4.0, but that shouldn't matter.
> Scrolling down means to the right.
>
> This is my first submission, so I hope this is the right place for it
> - tell me if my brainchild is going well!
>
>
> --- gtknotebook.c.orig  2004-06-28 20:46:22.000000000 +0200
> +++ gtknotebook.c       2004-06-30 15:08:30.000000000 +0200
> @@ -159,6 +159,8 @@
>                                               GtkAllocation    *allocation);
>  static gint gtk_notebook_expose              (GtkWidget        *widget,
>                                               GdkEventExpose   *event);
> +static gint gtk_notebook_scroll_event           (GtkWidget        *widget,
> +                GdkEventScroll   *event);
>  static gint gtk_notebook_button_press        (GtkWidget        *widget,
>                                               GdkEventButton   *event);
>  static gint gtk_notebook_button_release      (GtkWidget        *widget,
> @@ -364,6 +366,7 @@
>    widget_class->size_request = gtk_notebook_size_request;
>    widget_class->size_allocate = gtk_notebook_size_allocate;
>    widget_class->expose_event = gtk_notebook_expose;
> +  widget_class->scroll_event = gtk_notebook_scroll_event;

The other handlers don't have _event suffixes, so remove that.

>    widget_class->button_press_event = gtk_notebook_button_press;
>    widget_class->button_release_event = gtk_notebook_button_release;
>    widget_class->enter_notify_event = gtk_notebook_enter_notify;
> @@ -998,6 +1001,7 @@
>   * gtk_notebook_size_request
>   * gtk_notebook_size_allocate
>   * gtk_notebook_expose
> + * gtk_notebook_scroll_event

Likewise.

>   * gtk_notebook_button_press
>   * gtk_notebook_button_release
>   * gtk_notebook_enter_notify
> @@ -1146,7 +1150,8 @@
>    attributes.wclass = GDK_INPUT_ONLY;
>    attributes.event_mask = gtk_widget_get_events (widget);
>    attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
> -                           GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK);
> +                           GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK |
> +          GDK_SCROLL_MASK);
>   attributes_mask = GDK_WA_X | GDK_WA_Y;
>  @@ -1764,6 +1769,23 @@
>      return FALSE;
>  }
>  +static gint
> +gtk_notebook_scroll_event (GtkWidget      *widget,

Likewise.

> +                       GdkEventScroll *event)
> +{
> +  GtkNotebook *notebook = GTK_NOTEBOOK (widget);
> +  //Directions are an enum, not a bitmask.

This is obvious from the following code, so remove comment.

> +  switch(event->direction) {

This file uses the GNU C style, so spaces go after keywords and function
names, and braces go on separate lines.

> +    case GDK_SCROLL_RIGHT:
> +    case GDK_SCROLL_DOWN:
> +      gtk_notebook_next_page(notebook); break;

Don't put two statements on one line.

> +    case GDK_SCROLL_LEFT:
> +    case GDK_SCROLL_UP:
> +      gtk_notebook_prev_page(notebook); break;

Likewise.

> +  }
> +  return TRUE;

Put a blank line between a block statement and anything unrelated to it.

> +}
> +
>  static gboolean
>  gtk_notebook_button_press (GtkWidget      *widget,
>                            GdkEventButton *event)

I'm new to this list too, so please forgive me (and educate me) if this
is not how it works.  For instance, I wasn't sure whether these things
are too trivial to mention, but decided to go ahead since I had already
modified the patch anyway -- in fact originally to see what a meta-patch
looked like.  :-)

Regards,

--
Daniel Brockman
drlion deepwood net

PS:  I couldn't send this message with the patch attached properly (the
mailing list software said ``we don't need no steenking scr files'').
Here it is though:

--- gtknotebook.c.orig  2004-06-28 20:46:22.000000000 +0200
+++ gtknotebook.c       2004-06-30 15:08:30.000000000 +0200
@@ -159,6 +159,8 @@
                                              GtkAllocation    *allocation);
 static gint gtk_notebook_expose              (GtkWidget        *widget,
                                              GdkEventExpose   *event);
+static gint gtk_notebook_scroll              (GtkWidget        *widget,
+                                              GdkEventScroll   *event);
 static gint gtk_notebook_button_press        (GtkWidget        *widget,
                                              GdkEventButton   *event);
 static gint gtk_notebook_button_release      (GtkWidget        *widget,
@@ -364,6 +366,7 @@
   widget_class->size_request = gtk_notebook_size_request;
   widget_class->size_allocate = gtk_notebook_size_allocate;
   widget_class->expose_event = gtk_notebook_expose;
+  widget_class->scroll_event = gtk_notebook_scroll;
   widget_class->button_press_event = gtk_notebook_button_press;
   widget_class->button_release_event = gtk_notebook_button_release;
   widget_class->enter_notify_event = gtk_notebook_enter_notify;
@@ -998,6 +1001,7 @@
  * gtk_notebook_size_request
  * gtk_notebook_size_allocate
  * gtk_notebook_expose
+ * gtk_notebook_scroll
  * gtk_notebook_button_press
  * gtk_notebook_button_release
  * gtk_notebook_enter_notify
@@ -1146,12 +1150,33 @@
   attributes.wclass = GDK_INPUT_ONLY;
   attributes.event_mask = gtk_widget_get_events (widget);
   attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
-                           GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK);
+                           GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK |
+                           GDK_SCROLL_MASK);
  attributes_mask = GDK_WA_X | GDK_WA_Y;
 @@ -1764,6 +1769,23 @@
     return FALSE;
 }

+static gint
+gtk_notebook_scroll (GtkWidget      *widget,
+                     GdkEventScroll *event)
+{
+  GtkNotebook *notebook = GTK_NOTEBOOK (widget);
+
+  switch (event->direction)
+    {
+    case GDK_SCROLL_RIGHT:
+    case GDK_SCROLL_DOWN:
+      gtk_notebook_next_page (notebook);
+      break;
+    case GDK_SCROLL_LEFT:
+    case GDK_SCROLL_UP:
+      gtk_notebook_prev_page (notebook);
+      break;
+    }
+
+  return TRUE;
+}
+
 static gboolean
 gtk_notebook_button_press (GtkWidget      *widget,
                           GdkEventButton *event)




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]