diff src/gtkutil.c @ 106559:bac7488df503

Bug 5177: Scroll bar thumb did not move when scrolling with mouse wheel. * xterm.c (xg_scroll_callback): Parameter list changed, use parameter GtkScrollType to determine scroll/line/page. Only allow dragging if a button < 4 is grabbed (bug #5177). (xg_end_scroll_callback): New function. (x_create_toolkit_scroll_bar): Pass xg_end_scroll_callback to xg_create_scroll_bar. * gtkutil.c (xg_gtk_scroll_destroy): Remove XG_LAST_SB_DATA handling. (scroll_end_callback): Remove. (xg_create_scroll_bar): Add parameter end_callback, bind it to button-release-event. Replace value-changed event with change-value, bug #5177, (xg_event_is_for_scrollbar): Only return true if button is less than 4, bug #5177. * gtkutil.h (XG_LAST_SB_DATA): Remove. (xg_create_scroll_bar): Add GCallback end_callback.
author Jan Djärv <jan.h.d@swipnet.se>
date Sun, 13 Dec 2009 13:31:35 +0000
parents 3acd32c3e0ac
children 3db7e57ee4e9
line wrap: on
line diff
--- a/src/gtkutil.c	Sun Dec 13 13:16:17 2009 +0000
+++ b/src/gtkutil.c	Sun Dec 13 13:31:35 2009 +0000
@@ -3085,38 +3085,23 @@
      GtkWidget *widget;
      gpointer data;
 {
-  gpointer p;
   int id = (int) (EMACS_INT) data; /* The EMACS_INT cast avoids a warning. */
-
-  p = g_object_get_data (G_OBJECT (widget), XG_LAST_SB_DATA);
-  xfree (p);
   xg_remove_widget_from_map (id);
 }
 
-/* Callback for button release. Sets dragging to Qnil when dragging is done.  */
-
-static gboolean
-scroll_end_callback (GtkWidget *widget,
-                     GdkEventButton *event,
-                     gpointer user_data)
-{
-  struct scroll_bar *bar = (struct scroll_bar *) user_data;
-  bar->dragging = Qnil;
-  return FALSE;
-}
-
 /* Create a scroll bar widget for frame F.  Store the scroll bar
    in BAR.
    SCROLL_CALLBACK is the callback to invoke when the value of the
    bar changes.
+   END_CALLBACK is the callback to invoke when scrolling ends.
    SCROLL_BAR_NAME is the name we use for the scroll bar.  Can be used
    to set resources for the widget.  */
 
 void
-xg_create_scroll_bar (f, bar, scroll_callback, scroll_bar_name)
+xg_create_scroll_bar (f, bar, scroll_callback, end_callback, scroll_bar_name)
      FRAME_PTR f;
      struct scroll_bar *bar;
-     GCallback scroll_callback;
+     GCallback scroll_callback, end_callback;
      char *scroll_bar_name;
 {
   GtkWidget *wscroll;
@@ -3133,22 +3118,22 @@
   webox = gtk_event_box_new ();
   gtk_widget_set_name (wscroll, scroll_bar_name);
   gtk_range_set_update_policy (GTK_RANGE (wscroll), GTK_UPDATE_CONTINUOUS);
+  g_object_set_data (G_OBJECT (wscroll), XG_FRAME_DATA, (gpointer)f);
 
   scroll_id = xg_store_widget_in_map (wscroll);
 
-  g_signal_connect (G_OBJECT (wscroll),
-                    "value-changed",
-                    scroll_callback,
-                    (gpointer) bar);
   /* The EMACS_INT cast avoids a warning. */
   g_signal_connect (G_OBJECT (wscroll),
                     "destroy",
                     G_CALLBACK (xg_gtk_scroll_destroy),
                     (gpointer) (EMACS_INT) scroll_id);
-
+  g_signal_connect (G_OBJECT (wscroll),
+                    "change-value",
+                    scroll_callback,
+                    (gpointer) bar);
   g_signal_connect (G_OBJECT (wscroll),
                     "button-release-event",
-                    G_CALLBACK (scroll_end_callback),
+                    end_callback,
                     (gpointer) bar);
   
   /* The scroll bar widget does not draw on a window of its own.  Instead
@@ -3327,14 +3312,16 @@
 {
   int retval = 0;
 
-  if (f && event->type == ButtonPress)
+  if (f && event->type == ButtonPress && event->xbutton.button < 4)
     {
       /* Check if press occurred outside the edit widget.  */
       GdkDisplay *gdpy = gdk_x11_lookup_xdisplay (FRAME_X_DISPLAY (f));
       retval = gdk_display_get_window_at_pointer (gdpy, NULL, NULL)
         != f->output_data.x->edit_widget->window;
     }
-  else if (f && (event->type == ButtonRelease || event->type == MotionNotify))
+  else if (f
+           && ((event->type == ButtonRelease && event->xbutton.button < 4)
+               || event->type == MotionNotify))
     {
       /* If we are releasing or moving the scroll bar, it has the grab.  */
       retval = gtk_grab_get_current () != 0