462
|
1 /* scrollbar implementation -- X interface.
|
|
2 Copyright (C) 1994, 1995 Board of Trustees, University of Illinois.
|
|
3 Copyright (C) 1994 Amdhal Corporation.
|
|
4 Copyright (C) 1995 Sun Microsystems, Inc.
|
|
5 Copyright (C) 1995 Darrell Kindred <dkindred+@cmu.edu>.
|
|
6
|
|
7 This file is part of XEmacs.
|
|
8
|
|
9 XEmacs is free software; you can redistribute it and/or modify it
|
|
10 under the terms of the GNU General Public License as published by the
|
|
11 Free Software Foundation; either version 2, or (at your option) any
|
|
12 later version.
|
|
13
|
|
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
17 for more details.
|
|
18
|
|
19 You should have received a copy of the GNU General Public License
|
|
20 along with XEmacs; see the file COPYING. If not, write to
|
|
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 Boston, MA 02111-1307, USA. */
|
|
23
|
|
24 /* Synched up with: Not in FSF. */
|
|
25 /* Gtk version by William M. Perry */
|
|
26
|
|
27 #include <config.h>
|
|
28 #include "lisp.h"
|
|
29
|
872
|
30 #include "frame-impl.h"
|
|
31 #include "window.h"
|
|
32
|
|
33 #include "console-gtk-impl.h"
|
462
|
34 #include "glyphs-gtk.h"
|
|
35 #include "scrollbar-gtk.h"
|
|
36
|
|
37 static gboolean scrollbar_cb (GtkAdjustment *adj, gpointer user_data);
|
|
38
|
|
39 /* Used to prevent changing the size of the slider while drag
|
|
40 scrolling, under Motif. This is necessary because the Motif
|
|
41 scrollbar is incredibly stupid about updating the slider and causes
|
|
42 lots of flicker if it is done too often. */
|
|
43 static int inhibit_slider_size_change;
|
|
44
|
|
45 static int vertical_drag_in_progress;
|
|
46
|
|
47
|
|
48 /* A device method. */
|
|
49 static int
|
|
50 gtk_inhibit_scrollbar_slider_size_change (void)
|
|
51 {
|
|
52 return inhibit_slider_size_change;
|
|
53 }
|
|
54
|
|
55 /* A device method. */
|
|
56 static void
|
|
57 gtk_free_scrollbar_instance (struct scrollbar_instance *instance)
|
|
58 {
|
|
59 if (SCROLLBAR_GTK_WIDGET (instance))
|
|
60 {
|
|
61 gtk_widget_hide_all (SCROLLBAR_GTK_WIDGET (instance));
|
|
62 gtk_widget_destroy (SCROLLBAR_GTK_WIDGET (instance));
|
|
63 }
|
|
64
|
|
65 if (instance->scrollbar_data)
|
|
66 xfree (instance->scrollbar_data);
|
|
67 }
|
|
68
|
|
69 /* A device method. */
|
|
70 static void
|
|
71 gtk_release_scrollbar_instance (struct scrollbar_instance *instance)
|
|
72 {
|
|
73 /* It won't hurt to hide it all the time, will it? */
|
|
74 gtk_widget_hide_all (SCROLLBAR_GTK_WIDGET (instance));
|
|
75 }
|
|
76
|
|
77 static gboolean
|
|
78 scrollbar_drag_hack_cb (GtkWidget *w, GdkEventButton *ev, gpointer v)
|
|
79 {
|
|
80 vertical_drag_in_progress = (int) v;
|
|
81 inhibit_slider_size_change = (int) v;
|
|
82 return (FALSE);
|
|
83 }
|
|
84
|
|
85 /* A device method. */
|
|
86 static void
|
|
87 gtk_create_scrollbar_instance (struct frame *f, int vertical,
|
|
88 struct scrollbar_instance *instance)
|
|
89 {
|
|
90 GtkAdjustment *adj = GTK_ADJUSTMENT (gtk_adjustment_new (0,0,0,0,0,0));
|
|
91 GtkScrollbar *sb = NULL;
|
|
92
|
|
93 /* initialize the X specific data section. */
|
|
94 instance->scrollbar_data = xnew_and_zero (struct gtk_scrollbar_data);
|
|
95
|
|
96 SCROLLBAR_GTK_ID (instance) = new_gui_id ();
|
|
97 SCROLLBAR_GTK_VDRAG_ORIG_VALUE (instance) = -1;
|
|
98 SCROLLBAR_GTK_LAST_VALUE (instance) = adj->value;
|
|
99
|
|
100 gtk_object_set_data (GTK_OBJECT (adj), "xemacs::gui_id", (void *) SCROLLBAR_GTK_ID (instance));
|
|
101 gtk_object_set_data (GTK_OBJECT (adj), "xemacs::frame", f);
|
|
102
|
|
103 sb = GTK_SCROLLBAR (vertical ? gtk_vscrollbar_new (adj) : gtk_hscrollbar_new (adj));
|
|
104 SCROLLBAR_GTK_WIDGET (instance) = GTK_WIDGET (sb);
|
|
105
|
|
106 gtk_signal_connect (GTK_OBJECT (adj),"value-changed",
|
|
107 GTK_SIGNAL_FUNC (scrollbar_cb), (gpointer) vertical);
|
|
108
|
|
109 gtk_signal_connect (GTK_OBJECT (sb), "button-press-event",
|
|
110 GTK_SIGNAL_FUNC (scrollbar_drag_hack_cb), (gpointer) 1);
|
|
111 gtk_signal_connect (GTK_OBJECT (sb), "button-release-event",
|
|
112 GTK_SIGNAL_FUNC (scrollbar_drag_hack_cb), (gpointer) 0);
|
|
113
|
|
114 gtk_fixed_put (GTK_FIXED (FRAME_GTK_TEXT_WIDGET (f)), SCROLLBAR_GTK_WIDGET (instance), 0, 0);
|
525
|
115
|
|
116 /*
|
|
117 ** With gtk version > 1.2.8 the scrollbars in gtk-xemacs and xemacs
|
|
118 ** from CVS are invisible. In fact they are not invisible but very
|
|
119 ** thin (0 pixels wide). This is so, because the new gtk code does
|
|
120 ** not call gtk_widget_request_size() on the newly created
|
|
121 ** scrollbars anymore. this change was done to allow the theme
|
|
122 ** engines to manipulate the scrollbar width. This patch calls
|
|
123 ** gtk_widget_request_size with the newly created scollbars. Maybe
|
|
124 ** it is better to postpone this call just before the
|
|
125 ** gtk_widget_show() call is done on the scrolbar.
|
|
126 */
|
|
127 gtk_widget_size_request(GTK_WIDGET(sb), &(GTK_WIDGET(sb)->requisition));
|
|
128
|
462
|
129 gtk_widget_hide (SCROLLBAR_GTK_WIDGET (instance));
|
|
130 }
|
|
131
|
|
132 #define UPDATE_DATA_FIELD(field) \
|
|
133 if (new_##field >= 0 && \
|
|
134 SCROLLBAR_GTK_POS_DATA (inst).field != new_##field) { \
|
|
135 SCROLLBAR_GTK_POS_DATA (inst).field = new_##field; \
|
|
136 inst->scrollbar_instance_changed = 1; \
|
|
137 }
|
|
138
|
|
139 /* A device method. */
|
|
140 /* #### The -1 check is such a hack. */
|
|
141 static void
|
|
142 gtk_update_scrollbar_instance_values (struct window *w,
|
|
143 struct scrollbar_instance *inst,
|
|
144 int new_line_increment,
|
|
145 int new_page_increment,
|
|
146 int new_minimum, int new_maximum,
|
|
147 int new_slider_size,
|
|
148 int new_slider_position,
|
|
149 int new_scrollbar_width,
|
|
150 int new_scrollbar_height,
|
|
151 int new_scrollbar_x, int new_scrollbar_y)
|
|
152 {
|
|
153 UPDATE_DATA_FIELD (line_increment);
|
|
154 UPDATE_DATA_FIELD (page_increment);
|
|
155 UPDATE_DATA_FIELD (minimum);
|
|
156 UPDATE_DATA_FIELD (maximum);
|
|
157 UPDATE_DATA_FIELD (slider_size);
|
|
158 UPDATE_DATA_FIELD (slider_position);
|
|
159 UPDATE_DATA_FIELD (scrollbar_width);
|
|
160 UPDATE_DATA_FIELD (scrollbar_height);
|
|
161 UPDATE_DATA_FIELD (scrollbar_x);
|
|
162 UPDATE_DATA_FIELD (scrollbar_y);
|
|
163
|
|
164 if (w && !vertical_drag_in_progress)
|
|
165 {
|
|
166 int new_vov = SCROLLBAR_GTK_POS_DATA (inst).slider_position;
|
|
167 int new_vows = marker_position (w->start[CURRENT_DISP]);
|
|
168
|
|
169 if (SCROLLBAR_GTK_VDRAG_ORIG_VALUE (inst) != new_vov)
|
|
170 {
|
|
171 SCROLLBAR_GTK_VDRAG_ORIG_VALUE (inst) = new_vov;
|
|
172 inst->scrollbar_instance_changed = 1;
|
|
173 }
|
|
174 if (SCROLLBAR_GTK_VDRAG_ORIG_WINDOW_START (inst) != new_vows)
|
|
175 {
|
|
176 SCROLLBAR_GTK_VDRAG_ORIG_WINDOW_START (inst) = new_vows;
|
|
177 inst->scrollbar_instance_changed = 1;
|
|
178 }
|
|
179 }
|
|
180 }
|
|
181
|
|
182 /* Used by gtk_update_scrollbar_instance_status. */
|
|
183 static void
|
|
184 update_one_widget_scrollbar_pointer (struct window *w, GtkWidget *wid)
|
|
185 {
|
|
186 if (!wid->window)
|
|
187 gtk_widget_realize (wid);
|
|
188
|
|
189 if (POINTER_IMAGE_INSTANCEP (w->scrollbar_pointer))
|
|
190 {
|
|
191 gdk_window_set_cursor (GET_GTK_WIDGET_WINDOW (wid),
|
|
192 XIMAGE_INSTANCE_GTK_CURSOR (w->scrollbar_pointer));
|
|
193 gdk_flush ();
|
|
194 }
|
|
195 }
|
|
196
|
|
197 /* A device method. */
|
|
198 static void
|
|
199 gtk_update_scrollbar_instance_status (struct window *w, int active, int size,
|
|
200 struct scrollbar_instance *instance)
|
|
201 {
|
|
202 struct frame *f = XFRAME (w->frame);
|
|
203 GtkWidget *wid = SCROLLBAR_GTK_WIDGET (instance);
|
|
204 gboolean managed = GTK_WIDGET_MAPPED (wid);
|
|
205
|
|
206 if (active && size)
|
|
207 {
|
|
208 if (instance->scrollbar_instance_changed)
|
|
209 {
|
|
210 /* Need to set the height, width, and position of the widget */
|
|
211 GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (wid));
|
|
212 scrollbar_values *pos_data = & SCROLLBAR_GTK_POS_DATA (instance);
|
|
213 int modified_p = 0;
|
|
214
|
|
215 /* We do not want to update the size all the time if we can
|
|
216 help it. This cuts down on annoying flicker.
|
|
217 */
|
|
218 if ((wid->allocation.width != pos_data->scrollbar_width) ||
|
|
219 (wid->allocation.height != pos_data->scrollbar_height))
|
|
220 {
|
|
221 gtk_widget_set_usize (wid,
|
|
222 pos_data->scrollbar_width,
|
|
223 pos_data->scrollbar_height);
|
|
224 modified_p = 1;
|
|
225 }
|
|
226
|
|
227 /* Ditto for the x/y position. */
|
|
228 if ((wid->allocation.x != pos_data->scrollbar_x) ||
|
|
229 (wid->allocation.y != pos_data->scrollbar_y))
|
|
230 {
|
|
231 gtk_fixed_move (GTK_FIXED (FRAME_GTK_TEXT_WIDGET (f)),
|
|
232 wid,
|
|
233 pos_data->scrollbar_x,
|
|
234 pos_data->scrollbar_y);
|
|
235 modified_p = 1;
|
|
236 }
|
|
237
|
|
238 adj->lower = pos_data->minimum;
|
|
239 adj->upper = pos_data->maximum;
|
|
240 adj->page_increment = pos_data->slider_size + 1;
|
|
241 adj->step_increment = w->max_line_len - 1;
|
|
242 adj->page_size = pos_data->slider_size + 1;
|
|
243 adj->value = pos_data->slider_position;
|
|
244
|
|
245 /* But, if we didn't resize or move the scrollbar, the
|
|
246 widget will not get redrawn correctly when the user
|
|
247 scrolls around in the XEmacs frame manually. So we
|
|
248 update the slider manually here.
|
|
249 */
|
|
250 if (!modified_p)
|
|
251 gtk_range_slider_update (GTK_RANGE (wid));
|
|
252
|
|
253 instance->scrollbar_instance_changed = 0;
|
|
254 }
|
|
255
|
|
256 if (!managed)
|
|
257 {
|
|
258 gtk_widget_show (wid);
|
|
259 update_one_widget_scrollbar_pointer (w, wid);
|
|
260 }
|
|
261 }
|
|
262 else if (managed)
|
|
263 {
|
|
264 gtk_widget_hide (wid);
|
|
265 }
|
|
266 }
|
|
267
|
|
268 enum gtk_scrollbar_loop
|
|
269 {
|
|
270 GTK_FIND_SCROLLBAR_WINDOW_MIRROR,
|
|
271 GTK_SET_SCROLLBAR_POINTER,
|
|
272 GTK_WINDOW_IS_SCROLLBAR,
|
|
273 GTK_UPDATE_FRAME_SCROLLBARS
|
|
274 };
|
|
275
|
|
276 static struct window_mirror *
|
|
277 gtk_scrollbar_loop (enum gtk_scrollbar_loop type, Lisp_Object window,
|
|
278 struct window_mirror *mir,
|
|
279 GUI_ID id, GdkWindow *x_win)
|
|
280 {
|
|
281 struct window_mirror *retval = NULL;
|
|
282
|
|
283 while (mir)
|
|
284 {
|
|
285 struct scrollbar_instance *vinstance = mir->scrollbar_vertical_instance;
|
|
286 struct scrollbar_instance *hinstance = mir->scrollbar_horizontal_instance;
|
|
287 struct window *w = XWINDOW (window);
|
|
288
|
|
289 if (mir->vchild)
|
|
290 retval = gtk_scrollbar_loop (type, w->vchild, mir->vchild, id, x_win);
|
|
291 else if (mir->hchild)
|
|
292 retval = gtk_scrollbar_loop (type, w->hchild, mir->hchild, id, x_win);
|
|
293 if (retval)
|
|
294 return retval;
|
|
295
|
|
296 if (hinstance || vinstance)
|
|
297 {
|
|
298 switch (type)
|
|
299 {
|
|
300 case GTK_FIND_SCROLLBAR_WINDOW_MIRROR:
|
|
301 if ((vinstance && SCROLLBAR_GTK_ID (vinstance) == id) ||
|
|
302 (hinstance && SCROLLBAR_GTK_ID (hinstance) == id))
|
|
303 return mir;
|
|
304 break;
|
|
305 case GTK_UPDATE_FRAME_SCROLLBARS:
|
|
306 if (!mir->vchild && !mir->hchild)
|
|
307 update_window_scrollbars (w, mir, 1, 0);
|
|
308 break;
|
|
309 case GTK_SET_SCROLLBAR_POINTER:
|
|
310 if (!mir->vchild && !mir->hchild)
|
|
311 {
|
|
312 GtkWidget *widget;
|
|
313
|
|
314 widget = SCROLLBAR_GTK_WIDGET (hinstance);
|
|
315 if (widget && GTK_WIDGET_MAPPED (widget))
|
|
316 update_one_widget_scrollbar_pointer (w, widget);
|
|
317
|
|
318 widget = SCROLLBAR_GTK_WIDGET (vinstance);
|
|
319 if (widget && GTK_WIDGET_MAPPED (widget))
|
|
320 update_one_widget_scrollbar_pointer (w, widget);
|
|
321 }
|
|
322 break;
|
|
323 case GTK_WINDOW_IS_SCROLLBAR:
|
|
324 if (!mir->vchild && !mir->hchild)
|
|
325 {
|
|
326 GtkWidget *widget;
|
|
327
|
|
328 widget = SCROLLBAR_GTK_WIDGET (hinstance);
|
|
329 if (widget && GTK_WIDGET_MAPPED (widget) &&
|
|
330 GET_GTK_WIDGET_WINDOW (widget) == x_win)
|
|
331 return (struct window_mirror *) 1;
|
|
332
|
|
333 widget = SCROLLBAR_GTK_WIDGET (vinstance);
|
|
334 if (widget && GTK_WIDGET_MAPPED (widget) &&
|
|
335 GET_GTK_WIDGET_WINDOW (widget) == x_win)
|
|
336 return (struct window_mirror *) 1;
|
|
337 }
|
|
338 break;
|
|
339 default:
|
|
340 abort ();
|
|
341 }
|
|
342 }
|
|
343
|
|
344 mir = mir->next;
|
|
345 window = w->next;
|
|
346 }
|
|
347
|
|
348 return NULL;
|
|
349 }
|
|
350
|
|
351 /* Used by callbacks. */
|
|
352 static struct window_mirror *
|
|
353 find_scrollbar_window_mirror (struct frame *f, GUI_ID id)
|
|
354 {
|
|
355 if (f->mirror_dirty)
|
|
356 update_frame_window_mirror (f);
|
|
357 return gtk_scrollbar_loop (GTK_FIND_SCROLLBAR_WINDOW_MIRROR, f->root_window,
|
617
|
358 XWINDOW_MIRROR (f->root_mirror), id,
|
|
359 (GdkWindow *) NULL);
|
462
|
360 }
|
|
361
|
|
362 static gboolean
|
|
363 scrollbar_cb (GtkAdjustment *adj, gpointer user_data)
|
|
364 {
|
|
365 /* This function can GC */
|
|
366 int vertical = (int) user_data;
|
|
367 struct frame *f = gtk_object_get_data (GTK_OBJECT (adj), "xemacs::frame");
|
617
|
368 struct scrollbar_instance *instance;
|
462
|
369 GUI_ID id = (GUI_ID) gtk_object_get_data (GTK_OBJECT (adj), "xemacs::gui_id");
|
|
370 Lisp_Object win, frame;
|
|
371 struct window_mirror *mirror;
|
|
372 Lisp_Object event_type = Qnil;
|
|
373 Lisp_Object event_data = Qnil;
|
|
374
|
|
375 if (!f)
|
|
376 return(FALSE);
|
|
377
|
|
378 mirror = find_scrollbar_window_mirror (f, id);
|
|
379 if (!mirror)
|
|
380 return(FALSE);
|
|
381
|
|
382 win = real_window (mirror, 1);
|
|
383
|
|
384 if (NILP (win))
|
|
385 return(FALSE);
|
|
386 instance = vertical ? mirror->scrollbar_vertical_instance : mirror->scrollbar_horizontal_instance;
|
|
387 frame = WINDOW_FRAME (XWINDOW (win));
|
|
388
|
|
389 inhibit_slider_size_change = 0;
|
|
390 switch (GTK_RANGE (SCROLLBAR_GTK_WIDGET (instance))->scroll_type)
|
|
391 {
|
|
392 case GTK_SCROLL_PAGE_BACKWARD:
|
|
393 event_type = vertical ? Qscrollbar_page_up : Qscrollbar_page_left;
|
|
394 event_data = Fcons (win, Qnil);
|
|
395 break;
|
|
396 case GTK_SCROLL_PAGE_FORWARD:
|
|
397 event_type = vertical ? Qscrollbar_page_down : Qscrollbar_page_right;
|
|
398 event_data = Fcons (win, Qnil);
|
|
399 break;
|
|
400 case GTK_SCROLL_STEP_FORWARD:
|
|
401 event_type = vertical ? Qscrollbar_line_down : Qscrollbar_char_right;
|
|
402 event_data = win;
|
|
403 break;
|
|
404 case GTK_SCROLL_STEP_BACKWARD:
|
|
405 event_type = vertical ? Qscrollbar_line_up : Qscrollbar_char_left;
|
|
406 event_data = win;
|
|
407 break;
|
|
408 case GTK_SCROLL_NONE:
|
|
409 case GTK_SCROLL_JUMP:
|
|
410 inhibit_slider_size_change = 1;
|
|
411 event_type = vertical ? Qscrollbar_vertical_drag : Qscrollbar_horizontal_drag;
|
|
412 event_data = Fcons (win, make_int ((int)adj->value));
|
|
413 break;
|
|
414 default:
|
|
415 abort();
|
|
416 }
|
|
417
|
|
418 signal_special_gtk_user_event (frame, event_type, event_data);
|
|
419
|
|
420 return (TRUE);
|
|
421 }
|
|
422
|
|
423 static void
|
|
424 gtk_scrollbar_pointer_changed_in_window (struct window *w)
|
|
425 {
|
793
|
426 Lisp_Object window = wrap_window (w);
|
462
|
427
|
617
|
428 gtk_scrollbar_loop (GTK_SET_SCROLLBAR_POINTER, window,
|
|
429 find_window_mirror (w), 0, (GdkWindow *) NULL);
|
462
|
430 }
|
|
431
|
|
432 /* #### BILL!!! This comment is not true for Gtk - should it be? */
|
|
433 /* Make sure that all scrollbars on frame are up-to-date. Called
|
|
434 directly from gtk_set_frame_properties in frame-gtk.c*/
|
|
435 void
|
|
436 gtk_update_frame_scrollbars (struct frame *f)
|
|
437 {
|
617
|
438 gtk_scrollbar_loop (GTK_UPDATE_FRAME_SCROLLBARS, f->root_window,
|
|
439 XWINDOW_MIRROR (f->root_mirror),
|
462
|
440 0, (GdkWindow *) NULL);
|
|
441 }
|
|
442
|
|
443 #ifdef MEMORY_USAGE_STATS
|
|
444 static int
|
|
445 gtk_compute_scrollbar_instance_usage (struct device *d,
|
|
446 struct scrollbar_instance *inst,
|
|
447 struct overhead_stats *ovstats)
|
|
448 {
|
|
449 int total = 0;
|
|
450
|
|
451 while (inst)
|
|
452 {
|
|
453 struct gtk_scrollbar_data *data =
|
|
454 (struct gtk_scrollbar_data *) inst->scrollbar_data;
|
|
455
|
|
456 total += malloced_storage_size (data, sizeof (*data), ovstats);
|
|
457 inst = inst->next;
|
|
458 }
|
|
459
|
|
460 return total;
|
|
461 }
|
|
462
|
|
463 #endif /* MEMORY_USAGE_STATS */
|
|
464
|
|
465
|
|
466 /************************************************************************/
|
|
467 /* initialization */
|
|
468 /************************************************************************/
|
|
469
|
|
470 void
|
|
471 console_type_create_scrollbar_gtk (void)
|
|
472 {
|
|
473 CONSOLE_HAS_METHOD (gtk, inhibit_scrollbar_slider_size_change);
|
|
474 CONSOLE_HAS_METHOD (gtk, free_scrollbar_instance);
|
|
475 CONSOLE_HAS_METHOD (gtk, release_scrollbar_instance);
|
|
476 CONSOLE_HAS_METHOD (gtk, create_scrollbar_instance);
|
|
477 CONSOLE_HAS_METHOD (gtk, update_scrollbar_instance_values);
|
|
478 CONSOLE_HAS_METHOD (gtk, update_scrollbar_instance_status);
|
|
479 CONSOLE_HAS_METHOD (gtk, scrollbar_pointer_changed_in_window);
|
|
480 #ifdef MEMORY_USAGE_STATS
|
|
481 CONSOLE_HAS_METHOD (gtk, compute_scrollbar_instance_usage);
|
|
482 #endif /* MEMORY_USAGE_STATS */
|
|
483 }
|
|
484
|
|
485 void
|
|
486 vars_of_scrollbar_gtk (void)
|
|
487 {
|
|
488 Fprovide (intern ("gtk-scrollbars"));
|
|
489 }
|