comparison 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
comparison
equal deleted inserted replaced
106558:3d091f151696 106559:bac7488df503
3083 static void 3083 static void
3084 xg_gtk_scroll_destroy (widget, data) 3084 xg_gtk_scroll_destroy (widget, data)
3085 GtkWidget *widget; 3085 GtkWidget *widget;
3086 gpointer data; 3086 gpointer data;
3087 { 3087 {
3088 gpointer p;
3089 int id = (int) (EMACS_INT) data; /* The EMACS_INT cast avoids a warning. */ 3088 int id = (int) (EMACS_INT) data; /* The EMACS_INT cast avoids a warning. */
3090
3091 p = g_object_get_data (G_OBJECT (widget), XG_LAST_SB_DATA);
3092 xfree (p);
3093 xg_remove_widget_from_map (id); 3089 xg_remove_widget_from_map (id);
3094 }
3095
3096 /* Callback for button release. Sets dragging to Qnil when dragging is done. */
3097
3098 static gboolean
3099 scroll_end_callback (GtkWidget *widget,
3100 GdkEventButton *event,
3101 gpointer user_data)
3102 {
3103 struct scroll_bar *bar = (struct scroll_bar *) user_data;
3104 bar->dragging = Qnil;
3105 return FALSE;
3106 } 3090 }
3107 3091
3108 /* Create a scroll bar widget for frame F. Store the scroll bar 3092 /* Create a scroll bar widget for frame F. Store the scroll bar
3109 in BAR. 3093 in BAR.
3110 SCROLL_CALLBACK is the callback to invoke when the value of the 3094 SCROLL_CALLBACK is the callback to invoke when the value of the
3111 bar changes. 3095 bar changes.
3096 END_CALLBACK is the callback to invoke when scrolling ends.
3112 SCROLL_BAR_NAME is the name we use for the scroll bar. Can be used 3097 SCROLL_BAR_NAME is the name we use for the scroll bar. Can be used
3113 to set resources for the widget. */ 3098 to set resources for the widget. */
3114 3099
3115 void 3100 void
3116 xg_create_scroll_bar (f, bar, scroll_callback, scroll_bar_name) 3101 xg_create_scroll_bar (f, bar, scroll_callback, end_callback, scroll_bar_name)
3117 FRAME_PTR f; 3102 FRAME_PTR f;
3118 struct scroll_bar *bar; 3103 struct scroll_bar *bar;
3119 GCallback scroll_callback; 3104 GCallback scroll_callback, end_callback;
3120 char *scroll_bar_name; 3105 char *scroll_bar_name;
3121 { 3106 {
3122 GtkWidget *wscroll; 3107 GtkWidget *wscroll;
3123 GtkWidget *webox; 3108 GtkWidget *webox;
3124 GtkObject *vadj; 3109 GtkObject *vadj;
3131 3116
3132 wscroll = gtk_vscrollbar_new (GTK_ADJUSTMENT (vadj)); 3117 wscroll = gtk_vscrollbar_new (GTK_ADJUSTMENT (vadj));
3133 webox = gtk_event_box_new (); 3118 webox = gtk_event_box_new ();
3134 gtk_widget_set_name (wscroll, scroll_bar_name); 3119 gtk_widget_set_name (wscroll, scroll_bar_name);
3135 gtk_range_set_update_policy (GTK_RANGE (wscroll), GTK_UPDATE_CONTINUOUS); 3120 gtk_range_set_update_policy (GTK_RANGE (wscroll), GTK_UPDATE_CONTINUOUS);
3121 g_object_set_data (G_OBJECT (wscroll), XG_FRAME_DATA, (gpointer)f);
3136 3122
3137 scroll_id = xg_store_widget_in_map (wscroll); 3123 scroll_id = xg_store_widget_in_map (wscroll);
3138 3124
3139 g_signal_connect (G_OBJECT (wscroll),
3140 "value-changed",
3141 scroll_callback,
3142 (gpointer) bar);
3143 /* The EMACS_INT cast avoids a warning. */ 3125 /* The EMACS_INT cast avoids a warning. */
3144 g_signal_connect (G_OBJECT (wscroll), 3126 g_signal_connect (G_OBJECT (wscroll),
3145 "destroy", 3127 "destroy",
3146 G_CALLBACK (xg_gtk_scroll_destroy), 3128 G_CALLBACK (xg_gtk_scroll_destroy),
3147 (gpointer) (EMACS_INT) scroll_id); 3129 (gpointer) (EMACS_INT) scroll_id);
3148 3130 g_signal_connect (G_OBJECT (wscroll),
3131 "change-value",
3132 scroll_callback,
3133 (gpointer) bar);
3149 g_signal_connect (G_OBJECT (wscroll), 3134 g_signal_connect (G_OBJECT (wscroll),
3150 "button-release-event", 3135 "button-release-event",
3151 G_CALLBACK (scroll_end_callback), 3136 end_callback,
3152 (gpointer) bar); 3137 (gpointer) bar);
3153 3138
3154 /* The scroll bar widget does not draw on a window of its own. Instead 3139 /* The scroll bar widget does not draw on a window of its own. Instead
3155 it draws on the parent window, in this case the edit widget. So 3140 it draws on the parent window, in this case the edit widget. So
3156 whenever the edit widget is cleared, the scroll bar needs to redraw 3141 whenever the edit widget is cleared, the scroll bar needs to redraw
3325 FRAME_PTR f; 3310 FRAME_PTR f;
3326 XEvent *event; 3311 XEvent *event;
3327 { 3312 {
3328 int retval = 0; 3313 int retval = 0;
3329 3314
3330 if (f && event->type == ButtonPress) 3315 if (f && event->type == ButtonPress && event->xbutton.button < 4)
3331 { 3316 {
3332 /* Check if press occurred outside the edit widget. */ 3317 /* Check if press occurred outside the edit widget. */
3333 GdkDisplay *gdpy = gdk_x11_lookup_xdisplay (FRAME_X_DISPLAY (f)); 3318 GdkDisplay *gdpy = gdk_x11_lookup_xdisplay (FRAME_X_DISPLAY (f));
3334 retval = gdk_display_get_window_at_pointer (gdpy, NULL, NULL) 3319 retval = gdk_display_get_window_at_pointer (gdpy, NULL, NULL)
3335 != f->output_data.x->edit_widget->window; 3320 != f->output_data.x->edit_widget->window;
3336 } 3321 }
3337 else if (f && (event->type == ButtonRelease || event->type == MotionNotify)) 3322 else if (f
3323 && ((event->type == ButtonRelease && event->xbutton.button < 4)
3324 || event->type == MotionNotify))
3338 { 3325 {
3339 /* If we are releasing or moving the scroll bar, it has the grab. */ 3326 /* If we are releasing or moving the scroll bar, it has the grab. */
3340 retval = gtk_grab_get_current () != 0 3327 retval = gtk_grab_get_current () != 0
3341 && gtk_grab_get_current () != f->output_data.x->edit_widget; 3328 && gtk_grab_get_current () != f->output_data.x->edit_widget;
3342 } 3329 }