0
|
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
|
|
26 #include <config.h>
|
|
27 #include "lisp.h"
|
|
28
|
|
29 #include "console-x.h"
|
|
30 #include "glyphs-x.h"
|
|
31 #include "EmacsFrame.h"
|
|
32 #include "EmacsManager.h"
|
|
33 #include "gui-x.h"
|
|
34 #include "scrollbar-x.h"
|
|
35
|
|
36 #include "frame.h"
|
|
37 #include "window.h"
|
|
38
|
|
39 static void x_update_vertical_scrollbar_callback (Widget widget, LWLIB_ID id,
|
|
40 XtPointer client_data);
|
|
41 static void x_update_horizontal_scrollbar_callback (Widget widget, LWLIB_ID id,
|
|
42 XtPointer client_data);
|
|
43
|
70
|
44 /* Used to prevent changing the size of the thumb while drag
|
0
|
45 scrolling, under Motif. This is necessary because the Motif
|
70
|
46 scrollbar is incredibly stupid about updating the thumb and causes
|
0
|
47 lots of flicker if it is done too often. */
|
70
|
48 static int inhibit_thumb_size_change;
|
86
|
49 int stupid_vertical_scrollbar_drag_hack;
|
0
|
50
|
82
|
51 /* Doesn't work with athena */
|
0
|
52 #if defined (LWLIB_SCROLLBARS_MOTIF) || defined (LWLIB_SCROLLBARS_LUCID)
|
|
53 static int vertical_drag_in_progress;
|
|
54 #endif
|
|
55
|
|
56
|
|
57 /* A device method. */
|
|
58 static int
|
70
|
59 x_inhibit_scrollbar_thumb_size_change (void)
|
0
|
60 {
|
84
|
61 /* Doesn't work with Athena */
|
0
|
62 #if defined (LWLIB_SCROLLBARS_MOTIF) || defined (LWLIB_SCROLLBARS_LUCID)
|
70
|
63 return inhibit_thumb_size_change;
|
0
|
64 #else
|
|
65 return 0;
|
|
66 #endif
|
|
67 }
|
|
68
|
|
69 /* A device method. */
|
|
70 static void
|
|
71 x_free_scrollbar_instance (struct scrollbar_instance *instance)
|
|
72 {
|
|
73 if (SCROLLBAR_X_NAME (instance))
|
|
74 xfree (SCROLLBAR_X_NAME (instance));
|
|
75
|
|
76 if (SCROLLBAR_X_WIDGET (instance))
|
|
77 {
|
|
78 if (XtIsManaged (SCROLLBAR_X_WIDGET (instance)))
|
|
79 XtUnmanageChild (SCROLLBAR_X_WIDGET (instance));
|
|
80
|
|
81 lw_destroy_all_widgets (SCROLLBAR_X_ID (instance));
|
|
82 }
|
|
83
|
|
84 if (instance->scrollbar_data)
|
|
85 xfree (instance->scrollbar_data);
|
|
86 }
|
|
87
|
|
88 /* A device method. */
|
|
89 static void
|
|
90 x_release_scrollbar_instance (struct scrollbar_instance *instance)
|
|
91 {
|
|
92 if (XtIsManaged (SCROLLBAR_X_WIDGET (instance)))
|
|
93 XtUnmanageChild (SCROLLBAR_X_WIDGET (instance));
|
|
94 }
|
|
95
|
|
96 /* A device method. */
|
|
97 static void
|
|
98 x_create_scrollbar_instance (struct frame *f, int vertical,
|
|
99 struct scrollbar_instance *instance)
|
|
100 {
|
|
101 char buffer[32];
|
|
102
|
|
103 /* initialize the X specific data section. */
|
|
104 instance->scrollbar_data = malloc_type_and_zero (struct x_scrollbar_data);
|
|
105
|
|
106 SCROLLBAR_X_ID (instance) = new_lwlib_id ();
|
|
107 sprintf (buffer, "scrollbar_%d", SCROLLBAR_X_ID (instance));
|
|
108 SCROLLBAR_X_NAME (instance) = xstrdup (buffer);
|
82
|
109 #if defined (LWLIB_SCROLLBARS_MOTIF) || defined (LWLIB_SCROLLBARS_LUCID) || \
|
|
110 defined (LWLIB_SCROLLBARS_ATHENA3D)
|
0
|
111 SCROLLBAR_X_VDRAG_ORIG_VALUE (instance) = -1;
|
|
112 #endif
|
|
113
|
|
114 if (vertical)
|
|
115 {
|
|
116 SCROLLBAR_X_WIDGET (instance) =
|
|
117 lw_create_widget ("vertical-scrollbar", SCROLLBAR_X_NAME (instance),
|
|
118 SCROLLBAR_X_ID (instance),
|
|
119 NULL, FRAME_X_CONTAINER_WIDGET (f), 0,
|
|
120 x_update_vertical_scrollbar_callback, NULL, NULL);
|
|
121 }
|
|
122 else
|
|
123 {
|
|
124 SCROLLBAR_X_WIDGET (instance) =
|
|
125 lw_create_widget ("horizontal-scrollbar", SCROLLBAR_X_NAME (instance),
|
|
126 SCROLLBAR_X_ID (instance),
|
|
127 NULL, FRAME_X_CONTAINER_WIDGET (f), 0,
|
|
128 x_update_horizontal_scrollbar_callback, NULL, NULL);
|
|
129 }
|
|
130 }
|
|
131
|
70
|
132 #define UPDATE_DATA_FIELD(field) \
|
|
133 if (new_##field >= 0 && \
|
|
134 SCROLLBAR_X_POS_DATA (inst).field != new_##field) { \
|
|
135 SCROLLBAR_X_POS_DATA (inst).field = new_##field; \
|
|
136 inst->scrollbar_instance_changed = 1; \
|
0
|
137 }
|
|
138
|
|
139 /* A device method. */
|
|
140 /* #### The -1 check is such a hack. */
|
|
141 static void
|
|
142 x_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
|
82
|
164 /* This doesn't work with Athena, why? */
|
0
|
165 #if defined (LWLIB_SCROLLBARS_MOTIF) || defined (LWLIB_SCROLLBARS_LUCID)
|
|
166 if (w && !vertical_drag_in_progress)
|
|
167 {
|
|
168 int new_vov = SCROLLBAR_X_POS_DATA (inst).slider_position;
|
|
169 int new_vows = marker_position (w->start[CURRENT_DISP]);
|
|
170
|
|
171 if (SCROLLBAR_X_VDRAG_ORIG_VALUE (inst) != new_vov)
|
|
172 {
|
|
173 SCROLLBAR_X_VDRAG_ORIG_VALUE (inst) = new_vov;
|
|
174 inst->scrollbar_instance_changed = 1;
|
|
175 }
|
|
176 if (SCROLLBAR_X_VDRAG_ORIG_WINDOW_START (inst) != new_vows)
|
|
177 {
|
|
178 SCROLLBAR_X_VDRAG_ORIG_WINDOW_START (inst) = new_vows;
|
|
179 inst->scrollbar_instance_changed = 1;
|
|
180 }
|
|
181 }
|
|
182 #endif
|
|
183 }
|
|
184
|
|
185 /* Used by x_update_scrollbar_instance_status. */
|
|
186 static void
|
|
187 update_one_scrollbar_bs (struct frame *f, Widget sb_widget)
|
|
188 {
|
|
189 Boolean use_backing_store;
|
|
190
|
|
191 XtVaGetValues (FRAME_X_TEXT_WIDGET (f),
|
|
192 XtNuseBackingStore, &use_backing_store, 0);
|
|
193
|
|
194 if (use_backing_store && sb_widget)
|
|
195 {
|
|
196 unsigned long mask = CWBackingStore;
|
|
197 XSetWindowAttributes attrs;
|
|
198
|
|
199 attrs.backing_store = Always;
|
|
200 XChangeWindowAttributes (XtDisplay (sb_widget),
|
|
201 XtWindow (sb_widget),
|
|
202 mask,
|
|
203 &attrs);
|
|
204 }
|
|
205 }
|
|
206
|
|
207 /* Create a widget value structure for passing down to lwlib so that
|
|
208 it can update the scrollbar widgets. Used by
|
|
209 x_update_scrollbar_instance_status. */
|
|
210 static widget_value *
|
|
211 scrollbar_instance_to_widget_value (struct scrollbar_instance *instance)
|
|
212 {
|
|
213 widget_value *wv;
|
|
214
|
|
215 wv = xmalloc_widget_value ();
|
|
216 /* #### maybe should add malloc_scrollbar_values to resource these? */
|
|
217 wv->scrollbar_data = (scrollbar_values *)
|
|
218 xmalloc (sizeof (scrollbar_values));
|
|
219
|
|
220 wv->name = SCROLLBAR_X_NAME (instance);
|
|
221 wv->value = 0;
|
|
222 wv->key = 0;
|
|
223 wv->enabled = instance->scrollbar_is_active;
|
|
224 wv->selected = 0;
|
|
225 wv->call_data = NULL;
|
|
226
|
|
227 *wv->scrollbar_data = SCROLLBAR_X_POS_DATA (instance);
|
|
228
|
|
229 wv->next = NULL;
|
|
230
|
|
231 return wv;
|
|
232 }
|
|
233
|
|
234 /* Used by x_update_scrollbar_instance_status. */
|
|
235 static void
|
|
236 update_one_widget_scrollbar_pointer (struct window *w, Widget wid)
|
|
237 {
|
|
238 if (POINTER_IMAGE_INSTANCEP (w->scrollbar_pointer))
|
|
239 {
|
|
240 XDefineCursor (XtDisplay (wid), XtWindow (wid),
|
|
241 XIMAGE_INSTANCE_X_CURSOR (w->scrollbar_pointer));
|
|
242 XSync (XtDisplay (wid), False);
|
|
243 }
|
|
244 }
|
|
245
|
|
246 /* A device method. */
|
|
247 static void
|
|
248 x_update_scrollbar_instance_status (struct window *w, int active, int size,
|
|
249 struct scrollbar_instance *instance)
|
|
250 {
|
|
251 struct frame *f = XFRAME (w->frame);
|
70
|
252 char managed = XtIsManaged (SCROLLBAR_X_WIDGET (instance));
|
0
|
253
|
|
254 if (active && size)
|
|
255 {
|
|
256 widget_value *wv = scrollbar_instance_to_widget_value (instance);
|
|
257
|
|
258 if (instance->scrollbar_instance_changed)
|
|
259 {
|
|
260 lw_modify_all_widgets (SCROLLBAR_X_ID (instance), wv, 0);
|
|
261 instance->scrollbar_instance_changed = 0;
|
|
262 }
|
|
263
|
|
264 if (!managed)
|
|
265 {
|
|
266 XtManageChild (SCROLLBAR_X_WIDGET (instance));
|
|
267 if (XtWindow (SCROLLBAR_X_WIDGET (instance)))
|
|
268 {
|
|
269 /* Raise this window so that it's visible on top of the
|
|
270 text window below it. */
|
|
271 XRaiseWindow (XtDisplay (SCROLLBAR_X_WIDGET (instance)),
|
|
272 XtWindow (SCROLLBAR_X_WIDGET (instance)));
|
|
273 update_one_widget_scrollbar_pointer
|
|
274 (w, SCROLLBAR_X_WIDGET (instance));
|
|
275 if (!SCROLLBAR_X_BACKING_STORE_INITIALIZED (instance))
|
|
276 {
|
|
277 update_one_scrollbar_bs (f, SCROLLBAR_X_WIDGET (instance));
|
|
278 SCROLLBAR_X_BACKING_STORE_INITIALIZED (instance) = 1;
|
|
279 }
|
|
280 }
|
|
281 }
|
|
282
|
|
283 if (!wv->scrollbar_data) abort ();
|
|
284 xfree (wv->scrollbar_data);
|
|
285 wv->scrollbar_data = 0;
|
|
286 free_widget_value (wv);
|
|
287 }
|
|
288 else if (managed)
|
|
289 {
|
|
290 XtUnmanageChild (SCROLLBAR_X_WIDGET (instance));
|
|
291 }
|
|
292 }
|
|
293
|
|
294 /* A device method. */
|
|
295 static void
|
|
296 x_scrollbar_width_changed_in_frame (Lisp_Object specifier, struct frame *f,
|
|
297 Lisp_Object oldval)
|
|
298 {
|
|
299 XtWidgetGeometry req, repl;
|
|
300 Lisp_Object newval = f->scrollbar_width;
|
|
301
|
|
302 in_specifier_change_function++;
|
|
303
|
|
304 /* We want the text area to stay the same size. So, we query the
|
|
305 current size and then adjust it for the change in the scrollbar
|
|
306 width. */
|
|
307
|
|
308 /* mirror the value in the frame resources, unless it was already
|
|
309 done. */
|
|
310 if (!in_resource_setting)
|
|
311 XtVaSetValues (FRAME_X_TEXT_WIDGET (f), XtNscrollBarWidth,
|
|
312 XINT (newval), 0);
|
|
313
|
|
314 if (XtIsRealized (FRAME_X_CONTAINER_WIDGET (f)))
|
|
315 {
|
|
316 req.request_mode = 0;
|
|
317
|
|
318 /* the query-geometry method looks at the current value of
|
|
319 f->scrollbar_width, so temporarily set it back to the old
|
|
320 one. */
|
|
321 f->scrollbar_width = oldval;
|
|
322 XtQueryGeometry (FRAME_X_CONTAINER_WIDGET (f), &req, &repl);
|
|
323 f->scrollbar_width = newval;
|
|
324
|
|
325 repl.width += XINT (newval) - XINT (oldval);
|
|
326 EmacsManagerChangeSize (FRAME_X_CONTAINER_WIDGET (f), repl.width,
|
|
327 repl.height);
|
|
328 }
|
|
329
|
|
330 in_specifier_change_function--;
|
|
331 }
|
|
332
|
|
333 /* A device method. */
|
|
334 static void
|
|
335 x_scrollbar_height_changed_in_frame (Lisp_Object specifier, struct frame *f,
|
|
336 Lisp_Object oldval)
|
|
337 {
|
|
338 XtWidgetGeometry req, repl;
|
|
339 Lisp_Object newval = f->scrollbar_height;
|
|
340
|
|
341 in_specifier_change_function++;
|
|
342
|
|
343 /* We want the text area to stay the same size. So, we query the
|
|
344 current size and then adjust it for the change in the scrollbar
|
|
345 height. */
|
|
346
|
|
347 /* mirror the value in the frame resources, unless it was already
|
|
348 done. Also don't do it if this is the when the frame is being
|
|
349 created -- the widgets don't even exist yet, and even if they
|
|
350 did, we wouldn't want to overwrite the resource information
|
|
351 (which might specify a user preference). */
|
|
352 if (!in_resource_setting)
|
|
353 XtVaSetValues (FRAME_X_TEXT_WIDGET (f), XtNscrollBarHeight,
|
|
354 XINT (newval), 0);
|
|
355
|
|
356 if (XtIsRealized (FRAME_X_CONTAINER_WIDGET (f)))
|
|
357 {
|
|
358 req.request_mode = 0;
|
|
359
|
|
360 /* the query-geometry method looks at the current value of
|
|
361 f->scrollbar_height, so temporarily set it back to the old
|
|
362 one. */
|
|
363 f->scrollbar_height = oldval;
|
|
364 XtQueryGeometry (FRAME_X_CONTAINER_WIDGET (f), &req, &repl);
|
|
365 f->scrollbar_height = newval;
|
|
366
|
|
367 repl.height += XINT (newval) - XINT (oldval);
|
|
368 EmacsManagerChangeSize (FRAME_X_CONTAINER_WIDGET (f), repl.width,
|
|
369 repl.height);
|
|
370 }
|
|
371
|
|
372 in_specifier_change_function--;
|
|
373 }
|
|
374
|
|
375 enum x_scrollbar_loop
|
|
376 {
|
|
377 X_FIND_SCROLLBAR_WINDOW_MIRROR,
|
|
378 X_SET_SCROLLBAR_POINTER,
|
|
379 X_WINDOW_IS_SCROLLBAR,
|
|
380 X_UPDATE_FRAME_SCROLLBARS
|
|
381 };
|
|
382
|
|
383 static struct window_mirror *
|
|
384 x_scrollbar_loop (enum x_scrollbar_loop type, Lisp_Object window,
|
|
385 struct window_mirror *mir,
|
|
386 LWLIB_ID id, Window x_win)
|
|
387 {
|
|
388 struct window_mirror *retval = NULL;
|
|
389
|
|
390 while (mir)
|
|
391 {
|
|
392 struct scrollbar_instance *vinstance = mir->scrollbar_vertical_instance;
|
|
393 struct scrollbar_instance *hinstance =
|
|
394 mir->scrollbar_horizontal_instance;
|
|
395 struct frame *f;
|
|
396
|
|
397 assert (!NILP (window));
|
|
398 f = XFRAME (XWINDOW (window)->frame);
|
|
399
|
|
400 if (mir->vchild)
|
|
401 {
|
|
402 retval = x_scrollbar_loop (type, XWINDOW (window)->vchild,
|
|
403 mir->vchild, id, x_win);
|
|
404 }
|
|
405 else if (mir->hchild)
|
|
406 {
|
|
407 retval = x_scrollbar_loop (type, XWINDOW (window)->hchild,
|
|
408 mir->hchild, id, x_win);
|
|
409 }
|
|
410
|
|
411 if (retval != NULL)
|
|
412 return retval;
|
|
413
|
|
414 if (hinstance || vinstance)
|
|
415 {
|
|
416 switch (type)
|
|
417 {
|
|
418 case X_FIND_SCROLLBAR_WINDOW_MIRROR:
|
|
419 if ((vinstance && SCROLLBAR_X_ID (vinstance) == id)
|
|
420 || (hinstance && SCROLLBAR_X_ID (hinstance) == id))
|
|
421 {
|
|
422 return mir;
|
|
423 }
|
|
424 break;
|
|
425 case X_UPDATE_FRAME_SCROLLBARS:
|
|
426 if (!mir->vchild && !mir->hchild)
|
|
427 update_window_scrollbars (XWINDOW (window), mir, 1, 0);
|
|
428 break;
|
|
429 case X_SET_SCROLLBAR_POINTER:
|
|
430 if (!mir->vchild && !mir->hchild)
|
|
431 {
|
|
432 int loop;
|
|
433
|
|
434 for (loop = 0; loop < 2; loop++)
|
|
435 {
|
|
436 Widget widget;
|
|
437
|
|
438 if (loop)
|
|
439 widget = SCROLLBAR_X_WIDGET (vinstance);
|
|
440 else
|
|
441 widget = SCROLLBAR_X_WIDGET (hinstance);
|
|
442
|
|
443 if (widget && XtIsManaged (widget))
|
|
444 {
|
|
445 update_one_widget_scrollbar_pointer
|
|
446 (XWINDOW (window), widget);
|
|
447 }
|
|
448 }
|
|
449 }
|
|
450 break;
|
|
451 case X_WINDOW_IS_SCROLLBAR:
|
|
452 if (!mir->vchild && !mir->hchild)
|
|
453 {
|
|
454 int loop;
|
|
455
|
|
456 for (loop = 0; loop < 2; loop++)
|
|
457 {
|
|
458 Widget widget;
|
|
459
|
|
460 if (loop)
|
|
461 widget = SCROLLBAR_X_WIDGET (vinstance);
|
|
462 else
|
|
463 widget = SCROLLBAR_X_WIDGET (hinstance);
|
|
464
|
|
465 if (widget && XtIsManaged (widget))
|
|
466 {
|
|
467 if (XtWindow (widget) == x_win)
|
|
468 return (struct window_mirror *) 1;
|
|
469 }
|
|
470 }
|
|
471 }
|
|
472 break;
|
|
473 default:
|
|
474 abort ();
|
|
475 }
|
|
476 }
|
|
477
|
|
478 mir = mir->next;
|
|
479 window = XWINDOW (window)->next;
|
|
480 }
|
|
481
|
|
482 return NULL;
|
|
483 }
|
|
484
|
|
485 /* Used by callbacks. */
|
|
486 static struct window_mirror *
|
|
487 find_scrollbar_window_mirror (struct frame *f, LWLIB_ID id)
|
|
488 {
|
|
489 if (f->mirror_dirty)
|
|
490 update_frame_window_mirror (f);
|
|
491 return x_scrollbar_loop (X_FIND_SCROLLBAR_WINDOW_MIRROR, f->root_window,
|
|
492 f->root_mirror, id, (Window) NULL);
|
|
493 }
|
|
494
|
|
495 /*
|
|
496 * This is the only callback provided for vertical scrollbars. It
|
|
497 * should be able to handle all of the scrollbar events in
|
|
498 * scroll_action (see lwlib.h). The client data will be of type
|
|
499 * scroll_event (see lwlib.h). */
|
|
500 static void
|
|
501 x_update_vertical_scrollbar_callback (Widget widget, LWLIB_ID id,
|
|
502 XtPointer client_data)
|
|
503 {
|
|
504 /* This function can GC */
|
|
505 scroll_event *data = (scroll_event *) client_data;
|
|
506 struct device *d = get_device_from_display (XtDisplay (widget));
|
|
507 struct frame *f = x_any_window_to_frame (d, XtWindow (widget));
|
|
508 Lisp_Object win;
|
|
509 struct scrollbar_instance *instance;
|
|
510 struct window_mirror *mirror;
|
|
511
|
|
512 if (!f)
|
|
513 return;
|
|
514
|
|
515 mirror = find_scrollbar_window_mirror (f, id);
|
|
516 win = real_window (mirror, 1);
|
|
517
|
|
518 if (NILP (win))
|
|
519 return;
|
|
520 instance = mirror->scrollbar_vertical_instance;
|
|
521
|
|
522 /* It seems that this is necessary whenever signal_special_Xt_user_event()
|
|
523 is called. #### Why??? */
|
|
524 DEVICE_X_MOUSE_TIMESTAMP (d) = DEVICE_X_GLOBAL_MOUSE_TIMESTAMP (d);
|
|
525
|
|
526 switch (data->action)
|
|
527 {
|
|
528 case SCROLLBAR_LINE_UP:
|
|
529 signal_special_Xt_user_event (win, Qscrollbar_line_up, win);
|
|
530 break;
|
|
531
|
|
532 case SCROLLBAR_LINE_DOWN:
|
|
533 signal_special_Xt_user_event (win, Qscrollbar_line_down, win);
|
|
534 break;
|
|
535
|
|
536 /* The Athena scrollbar paging behavior is that of xterms.
|
|
537 Depending on where you click the size of the page varies.
|
|
538 Motif always does a standard Emacs page. */
|
|
539 case SCROLLBAR_PAGE_UP:
|
82
|
540 #if !defined (LWLIB_SCROLLBARS_MOTIF) && !defined (LWLIB_SCROLLBARS_LUCID) && \
|
|
541 !defined (LWLIB_SCROLLBARS_ATHENA3D)
|
0
|
542 {
|
|
543 double tmp = ((double) data->slider_value /
|
|
544 (double) SCROLLBAR_X_POS_DATA(instance).scrollbar_height);
|
|
545 double line = tmp *
|
|
546 (double) window_displayed_height (XWINDOW (win));
|
|
547
|
|
548 if (line > -1.0)
|
|
549 line = -1.0;
|
|
550 signal_special_Xt_user_event (win, Qscrollbar_page_up,
|
|
551 Fcons (win, make_int ((int) line)));
|
|
552 }
|
|
553 #else
|
|
554 signal_special_Xt_user_event (win, Qscrollbar_page_up,
|
|
555 Fcons (win, Qnil));
|
|
556 #endif
|
|
557 break;
|
|
558
|
|
559 case SCROLLBAR_PAGE_DOWN:
|
82
|
560 #if !defined (LWLIB_SCROLLBARS_MOTIF) && !defined (LWLIB_SCROLLBARS_LUCID) && \
|
|
561 !defined (LWLIB_SCROLLBARS_ATHENA3D)
|
0
|
562 {
|
|
563 double tmp = ((double) data->slider_value /
|
|
564 (double) SCROLLBAR_X_POS_DATA(instance).scrollbar_height);
|
|
565 double line = tmp *
|
|
566 (double) window_displayed_height (XWINDOW (win));
|
|
567
|
|
568 if (SCROLLBAR_X_POS_DATA(instance).maximum >
|
|
569 (SCROLLBAR_X_POS_DATA(instance).slider_size + SCROLLBAR_X_POS_DATA(instance).slider_position))
|
|
570 {
|
|
571 if (line < 1.0)
|
|
572 line = 1.0;
|
|
573 signal_special_Xt_user_event (win, Qscrollbar_page_down,
|
|
574 Fcons (win,
|
|
575 make_int ((int) line)));
|
|
576 }
|
|
577 }
|
|
578 #else
|
|
579 signal_special_Xt_user_event (win, Qscrollbar_page_down,
|
|
580 Fcons (win, Qnil));
|
|
581 #endif
|
|
582 break;
|
|
583
|
|
584 case SCROLLBAR_TOP:
|
|
585 signal_special_Xt_user_event (win, Qscrollbar_to_top, win);
|
|
586 break;
|
|
587
|
|
588 case SCROLLBAR_BOTTOM:
|
|
589 signal_special_Xt_user_event (win, Qscrollbar_to_bottom, win);
|
|
590 break;
|
|
591
|
|
592
|
|
593 case SCROLLBAR_CHANGE:
|
70
|
594 inhibit_thumb_size_change = 0;
|
0
|
595 #if defined (LWLIB_SCROLLBARS_MOTIF) || defined (LWLIB_SCROLLBARS_LUCID)
|
|
596 vertical_drag_in_progress = 0;
|
|
597 SCROLLBAR_X_VDRAG_ORIG_VALUE (instance) = data->slider_value;
|
|
598 SCROLLBAR_X_VDRAG_ORIG_WINDOW_START (instance) =
|
|
599 XINT (Fwindow_start (win));
|
84
|
600 #else
|
|
601 stupid_vertical_scrollbar_drag_hack = 0;
|
0
|
602 #endif
|
|
603 break;
|
|
604
|
|
605 case SCROLLBAR_DRAG:
|
|
606 {
|
|
607 int value;
|
|
608
|
70
|
609 inhibit_thumb_size_change = 1;
|
0
|
610
|
|
611 #if defined (LWLIB_SCROLLBARS_MOTIF) || defined (LWLIB_SCROLLBARS_LUCID)
|
|
612 /* Doing drags with Motif-like scrollbars is a mess, since we
|
|
613 want to avoid having the window position jump when you
|
|
614 first grab the scrollbar, but we also want to ensure that
|
|
615 you can scroll all the way to the top or bottom of the
|
|
616 buffer. This can all be replaced with something sane when
|
|
617 we get line-based scrolling. */
|
|
618
|
|
619 vertical_drag_in_progress = 1;
|
|
620
|
|
621 if (SCROLLBAR_X_VDRAG_ORIG_VALUE (instance) < 0)
|
|
622 {
|
|
623 SCROLLBAR_X_VDRAG_ORIG_VALUE (instance) = data->slider_value;
|
|
624 SCROLLBAR_X_VDRAG_ORIG_WINDOW_START (instance) =
|
|
625 XINT (Fwindow_start (win));
|
|
626 }
|
|
627
|
|
628 /* Could replace this piecewise linear scrolling with a
|
|
629 quadratic through the three points, but I'm not sure that
|
|
630 would feel any nicer in practice. */
|
|
631 if (data->slider_value < SCROLLBAR_X_VDRAG_ORIG_VALUE (instance))
|
|
632 {
|
|
633 /* We've dragged up; slide linearly from original position to
|
|
634 window-start=data.minimum, slider-value=data.minimum. */
|
|
635
|
|
636 if (SCROLLBAR_X_VDRAG_ORIG_VALUE (instance)
|
|
637 <= SCROLLBAR_X_POS_DATA (instance).minimum)
|
|
638 {
|
|
639 /* shouldn't get here, but just in case */
|
|
640 value = SCROLLBAR_X_POS_DATA (instance).minimum;
|
|
641 }
|
|
642 else
|
|
643 {
|
|
644 value = (SCROLLBAR_X_POS_DATA (instance).minimum
|
|
645 + (((double)
|
|
646 (SCROLLBAR_X_VDRAG_ORIG_WINDOW_START (instance)
|
|
647 - SCROLLBAR_X_POS_DATA (instance).minimum)
|
|
648 * (data->slider_value -
|
|
649 SCROLLBAR_X_POS_DATA (instance).minimum))
|
|
650 / (SCROLLBAR_X_VDRAG_ORIG_VALUE (instance)
|
|
651 - SCROLLBAR_X_POS_DATA (instance).minimum)));
|
|
652 }
|
|
653 }
|
|
654 else
|
|
655 {
|
|
656 /* We've dragged down; slide linearly from original position to
|
|
657 window-start=data.maximum, slider-value=data.maximum. */
|
|
658
|
|
659 if (SCROLLBAR_X_VDRAG_ORIG_VALUE (instance)
|
|
660 >= (SCROLLBAR_X_POS_DATA (instance).maximum -
|
|
661 SCROLLBAR_X_POS_DATA (instance).slider_size))
|
|
662 {
|
|
663 /* avoid divide by zero */
|
|
664 value = SCROLLBAR_X_VDRAG_ORIG_WINDOW_START (instance);
|
|
665 }
|
|
666 else
|
|
667 {
|
|
668 value = (SCROLLBAR_X_VDRAG_ORIG_WINDOW_START (instance)
|
|
669 + (((double) (SCROLLBAR_X_POS_DATA (instance).maximum
|
|
670 - SCROLLBAR_X_VDRAG_ORIG_WINDOW_START (instance))
|
|
671 * (data->slider_value
|
|
672 - SCROLLBAR_X_VDRAG_ORIG_VALUE (instance)))
|
|
673 / (SCROLLBAR_X_POS_DATA (instance).maximum
|
|
674 - SCROLLBAR_X_POS_DATA (instance).slider_size
|
|
675 - SCROLLBAR_X_VDRAG_ORIG_VALUE (instance))));
|
|
676 }
|
|
677 }
|
|
678 #else
|
82
|
679 stupid_vertical_scrollbar_drag_hack = 0;
|
0
|
680 value = data->slider_value;
|
|
681 #endif
|
|
682
|
|
683 if (value >= SCROLLBAR_X_POS_DATA (instance).maximum)
|
|
684 value = SCROLLBAR_X_POS_DATA (instance).maximum - 1;
|
|
685 if (value < SCROLLBAR_X_POS_DATA (instance).minimum)
|
|
686 value = SCROLLBAR_X_POS_DATA (instance).minimum;
|
|
687
|
|
688 signal_special_Xt_user_event (win, Qscrollbar_vertical_drag,
|
|
689 Fcons (win, make_int (value)));
|
|
690 }
|
|
691 break;
|
|
692
|
|
693 }
|
|
694 }
|
|
695
|
|
696 /*
|
|
697 * This is the only callback provided for horizontal scrollbars. It
|
|
698 * should be able to handle all of the scrollbar events in
|
|
699 * scroll_action (see lwlib.h). The client data will be of type
|
|
700 * scroll_event (see lwlib.h). */
|
|
701 static void
|
|
702 x_update_horizontal_scrollbar_callback (Widget widget, LWLIB_ID id,
|
|
703 XtPointer client_data)
|
|
704 {
|
|
705 scroll_event *data = (scroll_event *) client_data;
|
|
706 struct device *d = get_device_from_display (XtDisplay (widget));
|
|
707 struct frame *f = x_any_window_to_frame (d, XtWindow (widget));
|
|
708 Lisp_Object win;
|
|
709 struct window_mirror *mirror;
|
|
710
|
|
711 if (!f)
|
|
712 return;
|
|
713
|
|
714 mirror = find_scrollbar_window_mirror (f, id);
|
|
715 win = real_window (mirror, 1);
|
|
716
|
|
717 if (NILP (win))
|
|
718 return;
|
|
719
|
|
720 /* It seems that this is necessary whenever signal_special_Xt_user_event()
|
|
721 is called. #### Why??? */
|
|
722 DEVICE_X_MOUSE_TIMESTAMP (d) = DEVICE_X_GLOBAL_MOUSE_TIMESTAMP (d);
|
|
723
|
|
724 switch (data->action)
|
|
725 {
|
|
726 case SCROLLBAR_LINE_UP:
|
|
727 signal_special_Xt_user_event (win, Qscrollbar_char_left, win);
|
|
728 break;
|
|
729 case SCROLLBAR_LINE_DOWN:
|
|
730 signal_special_Xt_user_event (win, Qscrollbar_char_right, win);
|
|
731 break;
|
|
732 case SCROLLBAR_PAGE_UP:
|
|
733 signal_special_Xt_user_event (win, Qscrollbar_page_left, win);
|
|
734 break;
|
|
735 case SCROLLBAR_PAGE_DOWN:
|
|
736 signal_special_Xt_user_event (win, Qscrollbar_page_right, win);
|
|
737 break;
|
|
738 case SCROLLBAR_TOP:
|
|
739 signal_special_Xt_user_event (win, Qscrollbar_to_left, win);
|
|
740 break;
|
|
741 case SCROLLBAR_BOTTOM:
|
|
742 signal_special_Xt_user_event (win, Qscrollbar_to_right, win);
|
|
743 break;
|
|
744 case SCROLLBAR_CHANGE:
|
70
|
745 inhibit_thumb_size_change = 0;
|
0
|
746 break;
|
|
747 case SCROLLBAR_DRAG:
|
70
|
748 inhibit_thumb_size_change = 1;
|
0
|
749 /* #### Fix the damn toolkit code so they all work the same way.
|
|
750 Lucid is the one mostly wrong.*/
|
82
|
751 #if defined (LWLIB_SCROLLBARS_LUCID) || defined (LWLIB_SCROLLBARS_ATHENA3D)
|
0
|
752 signal_special_Xt_user_event (win, Qscrollbar_horizontal_drag,
|
|
753 (Fcons
|
|
754 (win, make_int (data->slider_value))));
|
|
755 #else
|
|
756 signal_special_Xt_user_event (win, Qscrollbar_horizontal_drag,
|
|
757 (Fcons
|
|
758 (win,
|
|
759 make_int (data->slider_value - 1))));
|
|
760 #endif
|
|
761 break;
|
|
762 default:
|
|
763 break;
|
|
764 }
|
|
765 }
|
|
766
|
|
767 static void
|
|
768 x_scrollbar_pointer_changed_in_window (struct window *w)
|
|
769 {
|
|
770 Lisp_Object window = Qnil;
|
|
771
|
|
772 XSETWINDOW (window, w);
|
|
773 x_scrollbar_loop (X_SET_SCROLLBAR_POINTER, window, find_window_mirror (w),
|
|
774 0, (Window) NULL);
|
|
775 }
|
|
776
|
|
777 /* Called directly from x_any_window_to_frame in frame-x.c */
|
|
778 EMACS_INT
|
|
779 x_window_is_scrollbar (struct frame *f, Window win)
|
|
780 {
|
|
781 if (!FRAME_X_P (f))
|
|
782 return 0;
|
|
783
|
|
784 if (f->mirror_dirty)
|
|
785 update_frame_window_mirror (f);
|
|
786 return (EMACS_INT) x_scrollbar_loop (X_WINDOW_IS_SCROLLBAR, f->root_window,
|
|
787 f->root_mirror, 0, win);
|
|
788 }
|
|
789
|
|
790 /* Make sure that all scrollbars on frame are up-to-date. Called
|
|
791 directly from x_set_frame_properties in frame-x.c*/
|
|
792 void
|
|
793 x_update_frame_scrollbars (struct frame *f)
|
|
794 {
|
|
795 /* Consider this code to be "in_display" so that we abort() if Fsignal()
|
|
796 gets called. */
|
|
797 in_display++;
|
|
798 x_scrollbar_loop (X_UPDATE_FRAME_SCROLLBARS, f->root_window, f->root_mirror,
|
|
799 0, (Window) NULL);
|
|
800 in_display--;
|
|
801 if (in_display < 0) abort ();
|
|
802 }
|
|
803
|
|
804 #ifdef MEMORY_USAGE_STATS
|
|
805
|
|
806 static int
|
|
807 x_compute_scrollbar_instance_usage (struct device *d,
|
|
808 struct scrollbar_instance *inst,
|
|
809 struct overhead_stats *ovstats)
|
|
810 {
|
|
811 int total = 0;
|
|
812
|
|
813 while (inst)
|
|
814 {
|
|
815 struct x_scrollbar_data *data =
|
|
816 (struct x_scrollbar_data *) inst->scrollbar_data;
|
|
817
|
|
818 total += malloced_storage_size (data, sizeof (*data), ovstats);
|
|
819 total += malloced_storage_size (data->name, 1 + strlen (data->name),
|
|
820 ovstats);
|
|
821 inst = inst->next;
|
|
822 }
|
|
823
|
|
824 return total;
|
|
825 }
|
|
826
|
|
827 #endif /* MEMORY_USAGE_STATS */
|
|
828
|
|
829
|
|
830 /************************************************************************/
|
|
831 /* initialization */
|
|
832 /************************************************************************/
|
|
833
|
|
834 void
|
|
835 console_type_create_scrollbar_x (void)
|
|
836 {
|
70
|
837 CONSOLE_HAS_METHOD (x, inhibit_scrollbar_thumb_size_change);
|
0
|
838 CONSOLE_HAS_METHOD (x, free_scrollbar_instance);
|
|
839 CONSOLE_HAS_METHOD (x, release_scrollbar_instance);
|
|
840 CONSOLE_HAS_METHOD (x, create_scrollbar_instance);
|
|
841 CONSOLE_HAS_METHOD (x, update_scrollbar_instance_values);
|
|
842 CONSOLE_HAS_METHOD (x, update_scrollbar_instance_status);
|
|
843 CONSOLE_HAS_METHOD (x, scrollbar_width_changed_in_frame);
|
|
844 CONSOLE_HAS_METHOD (x, scrollbar_height_changed_in_frame);
|
|
845 CONSOLE_HAS_METHOD (x, scrollbar_pointer_changed_in_window);
|
|
846 #ifdef MEMORY_USAGE_STATS
|
|
847 CONSOLE_HAS_METHOD (x, compute_scrollbar_instance_usage);
|
|
848 #endif /* MEMORY_USAGE_STATS */
|
|
849 }
|
|
850
|
|
851 void
|
|
852 vars_of_scrollbar_x (void)
|
|
853 {
|
|
854 #if defined (LWLIB_SCROLLBARS_LUCID)
|
|
855 Fprovide (intern ("lucid-scrollbars"));
|
|
856 #elif defined (LWLIB_SCROLLBARS_MOTIF)
|
|
857 Fprovide (intern ("motif-scrollbars"));
|
|
858 #elif defined (LWLIB_SCROLLBARS_ATHENA)
|
|
859 Fprovide (intern ("athena-scrollbars"));
|
|
860 #endif
|
86
|
861 stupid_vertical_scrollbar_drag_hack = 1;
|
0
|
862 }
|