PATCH for tab-scrolling



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;
  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
 * 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,
+                       GdkEventScroll *event)
+{
+  GtkNotebook *notebook = GTK_NOTEBOOK (widget);
+  //Directions are an enum, not a bitmask.
+  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]