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
|
26
|
44 /* Used to prevent changing the size of the slider while drag
|
0
|
45 scrolling, under Motif. This is necessary because the Motif
|
26
|
46 scrollbar is incredibly stupid about updating the slider and causes
|
0
|
47 lots of flicker if it is done too often. */
|
26
|
48 static int inhibit_slider_size_change;
|
20
|
49 int stupid_vertical_scrollbar_drag_hack;
|
0
|
50
|
16
|
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
|
26
|
59 x_inhibit_scrollbar_slider_size_change (void)
|
0
|
60 {
|
16
|
61 /* Doesn't work with Athena */
|
0
|
62 #if defined (LWLIB_SCROLLBARS_MOTIF) || defined (LWLIB_SCROLLBARS_LUCID)
|
26
|
63 return inhibit_slider_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);
|
16
|
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
|
26
|
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
|
16
|
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);
|
26
|
252 Boolean 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 {
|
62
|
290 #if defined (LWLIB_SCROLLBARS_MOTIF) || defined (LWLIB_SCROLLBARS_LUCID)
|
|
291 /* This isn't needed with Athena Scrollbars. It might not be needed */
|
|
292 /* with Motif scrollbars (it is apparently needed with Lesstif). */
|
|
293 XtUngrabKeyboard (SCROLLBAR_X_WIDGET (instance), CurrentTime);
|
|
294 #endif
|
0
|
295 XtUnmanageChild (SCROLLBAR_X_WIDGET (instance));
|
|
296 }
|
|
297 }
|
|
298
|
|
299 /* A device method. */
|
|
300 static void
|
|
301 x_scrollbar_width_changed_in_frame (Lisp_Object specifier, struct frame *f,
|
|
302 Lisp_Object oldval)
|
|
303 {
|
|
304 XtWidgetGeometry req, repl;
|
|
305 Lisp_Object newval = f->scrollbar_width;
|
|
306
|
|
307 in_specifier_change_function++;
|
|
308
|
|
309 /* We want the text area to stay the same size. So, we query the
|
|
310 current size and then adjust it for the change in the scrollbar
|
|
311 width. */
|
|
312
|
|
313 /* mirror the value in the frame resources, unless it was already
|
|
314 done. */
|
|
315 if (!in_resource_setting)
|
|
316 XtVaSetValues (FRAME_X_TEXT_WIDGET (f), XtNscrollBarWidth,
|
|
317 XINT (newval), 0);
|
|
318
|
|
319 if (XtIsRealized (FRAME_X_CONTAINER_WIDGET (f)))
|
|
320 {
|
|
321 req.request_mode = 0;
|
|
322
|
|
323 /* the query-geometry method looks at the current value of
|
|
324 f->scrollbar_width, so temporarily set it back to the old
|
|
325 one. */
|
|
326 f->scrollbar_width = oldval;
|
|
327 XtQueryGeometry (FRAME_X_CONTAINER_WIDGET (f), &req, &repl);
|
|
328 f->scrollbar_width = newval;
|
|
329
|
|
330 repl.width += XINT (newval) - XINT (oldval);
|
|
331 EmacsManagerChangeSize (FRAME_X_CONTAINER_WIDGET (f), repl.width,
|
|
332 repl.height);
|
|
333 }
|
|
334
|
|
335 in_specifier_change_function--;
|
|
336 }
|
|
337
|
|
338 /* A device method. */
|
|
339 static void
|
|
340 x_scrollbar_height_changed_in_frame (Lisp_Object specifier, struct frame *f,
|
|
341 Lisp_Object oldval)
|
|
342 {
|
|
343 XtWidgetGeometry req, repl;
|
|
344 Lisp_Object newval = f->scrollbar_height;
|
|
345
|
|
346 in_specifier_change_function++;
|
|
347
|
|
348 /* We want the text area to stay the same size. So, we query the
|
|
349 current size and then adjust it for the change in the scrollbar
|
|
350 height. */
|
|
351
|
|
352 /* mirror the value in the frame resources, unless it was already
|
|
353 done. Also don't do it if this is the when the frame is being
|
|
354 created -- the widgets don't even exist yet, and even if they
|
|
355 did, we wouldn't want to overwrite the resource information
|
|
356 (which might specify a user preference). */
|
|
357 if (!in_resource_setting)
|
|
358 XtVaSetValues (FRAME_X_TEXT_WIDGET (f), XtNscrollBarHeight,
|
|
359 XINT (newval), 0);
|
|
360
|
|
361 if (XtIsRealized (FRAME_X_CONTAINER_WIDGET (f)))
|
|
362 {
|
|
363 req.request_mode = 0;
|
|
364
|
|
365 /* the query-geometry method looks at the current value of
|
|
366 f->scrollbar_height, so temporarily set it back to the old
|
|
367 one. */
|
|
368 f->scrollbar_height = oldval;
|
|
369 XtQueryGeometry (FRAME_X_CONTAINER_WIDGET (f), &req, &repl);
|
|
370 f->scrollbar_height = newval;
|
|
371
|
|
372 repl.height += XINT (newval) - XINT (oldval);
|
|
373 EmacsManagerChangeSize (FRAME_X_CONTAINER_WIDGET (f), repl.width,
|
|
374 repl.height);
|
|
375 }
|
|
376
|
|
377 in_specifier_change_function--;
|
|
378 }
|
|
379
|
|
380 enum x_scrollbar_loop
|
|
381 {
|
|
382 X_FIND_SCROLLBAR_WINDOW_MIRROR,
|
|
383 X_SET_SCROLLBAR_POINTER,
|
|
384 X_WINDOW_IS_SCROLLBAR,
|
|
385 X_UPDATE_FRAME_SCROLLBARS
|
|
386 };
|
|
387
|
|
388 static struct window_mirror *
|
|
389 x_scrollbar_loop (enum x_scrollbar_loop type, Lisp_Object window,
|
|
390 struct window_mirror *mir,
|
|
391 LWLIB_ID id, Window x_win)
|
|
392 {
|
|
393 struct window_mirror *retval = NULL;
|
|
394
|
|
395 while (mir)
|
|
396 {
|
|
397 struct scrollbar_instance *vinstance = mir->scrollbar_vertical_instance;
|
|
398 struct scrollbar_instance *hinstance =
|
|
399 mir->scrollbar_horizontal_instance;
|
|
400 struct frame *f;
|
|
401
|
|
402 assert (!NILP (window));
|
|
403 f = XFRAME (XWINDOW (window)->frame);
|
|
404
|
|
405 if (mir->vchild)
|
|
406 {
|
|
407 retval = x_scrollbar_loop (type, XWINDOW (window)->vchild,
|
|
408 mir->vchild, id, x_win);
|
|
409 }
|
|
410 else if (mir->hchild)
|
|
411 {
|
|
412 retval = x_scrollbar_loop (type, XWINDOW (window)->hchild,
|
|
413 mir->hchild, id, x_win);
|
|
414 }
|
|
415
|
|
416 if (retval != NULL)
|
|
417 return retval;
|
|
418
|
|
419 if (hinstance || vinstance)
|
|
420 {
|
|
421 switch (type)
|
|
422 {
|
|
423 case X_FIND_SCROLLBAR_WINDOW_MIRROR:
|
|
424 if ((vinstance && SCROLLBAR_X_ID (vinstance) == id)
|
|
425 || (hinstance && SCROLLBAR_X_ID (hinstance) == id))
|
|
426 {
|
|
427 return mir;
|
|
428 }
|
|
429 break;
|
|
430 case X_UPDATE_FRAME_SCROLLBARS:
|
|
431 if (!mir->vchild && !mir->hchild)
|
|
432 update_window_scrollbars (XWINDOW (window), mir, 1, 0);
|
|
433 break;
|
|
434 case X_SET_SCROLLBAR_POINTER:
|
|
435 if (!mir->vchild && !mir->hchild)
|
|
436 {
|
|
437 int loop;
|
|
438
|
|
439 for (loop = 0; loop < 2; loop++)
|
|
440 {
|
|
441 Widget widget;
|
|
442
|
|
443 if (loop)
|
|
444 widget = SCROLLBAR_X_WIDGET (vinstance);
|
|
445 else
|
|
446 widget = SCROLLBAR_X_WIDGET (hinstance);
|
|
447
|
|
448 if (widget && XtIsManaged (widget))
|
|
449 {
|
|
450 update_one_widget_scrollbar_pointer
|
|
451 (XWINDOW (window), widget);
|
|
452 }
|
|
453 }
|
|
454 }
|
|
455 break;
|
|
456 case X_WINDOW_IS_SCROLLBAR:
|
|
457 if (!mir->vchild && !mir->hchild)
|
|
458 {
|
|
459 int loop;
|
|
460
|
|
461 for (loop = 0; loop < 2; loop++)
|
|
462 {
|
|
463 Widget widget;
|
|
464
|
|
465 if (loop)
|
|
466 widget = SCROLLBAR_X_WIDGET (vinstance);
|
|
467 else
|
|
468 widget = SCROLLBAR_X_WIDGET (hinstance);
|
|
469
|
|
470 if (widget && XtIsManaged (widget))
|
|
471 {
|
|
472 if (XtWindow (widget) == x_win)
|
|
473 return (struct window_mirror *) 1;
|
|
474 }
|
|
475 }
|
|
476 }
|
|
477 break;
|
|
478 default:
|
|
479 abort ();
|
|
480 }
|
|
481 }
|
|
482
|
|
483 mir = mir->next;
|
|
484 window = XWINDOW (window)->next;
|
|
485 }
|
|
486
|
|
487 return NULL;
|
|
488 }
|
|
489
|
|
490 /* Used by callbacks. */
|
|
491 static struct window_mirror *
|
|
492 find_scrollbar_window_mirror (struct frame *f, LWLIB_ID id)
|
|
493 {
|
|
494 if (f->mirror_dirty)
|
|
495 update_frame_window_mirror (f);
|
|
496 return x_scrollbar_loop (X_FIND_SCROLLBAR_WINDOW_MIRROR, f->root_window,
|
|
497 f->root_mirror, id, (Window) NULL);
|
|
498 }
|
|
499
|
|
500 /*
|
|
501 * This is the only callback provided for vertical scrollbars. It
|
|
502 * should be able to handle all of the scrollbar events in
|
|
503 * scroll_action (see lwlib.h). The client data will be of type
|
|
504 * scroll_event (see lwlib.h). */
|
|
505 static void
|
|
506 x_update_vertical_scrollbar_callback (Widget widget, LWLIB_ID id,
|
|
507 XtPointer client_data)
|
|
508 {
|
|
509 /* This function can GC */
|
|
510 scroll_event *data = (scroll_event *) client_data;
|
|
511 struct device *d = get_device_from_display (XtDisplay (widget));
|
|
512 struct frame *f = x_any_window_to_frame (d, XtWindow (widget));
|
|
513 Lisp_Object win;
|
|
514 struct scrollbar_instance *instance;
|
|
515 struct window_mirror *mirror;
|
|
516
|
|
517 if (!f)
|
|
518 return;
|
|
519
|
|
520 mirror = find_scrollbar_window_mirror (f, id);
|
|
521 win = real_window (mirror, 1);
|
|
522
|
|
523 if (NILP (win))
|
|
524 return;
|
|
525 instance = mirror->scrollbar_vertical_instance;
|
|
526
|
|
527 /* It seems that this is necessary whenever signal_special_Xt_user_event()
|
|
528 is called. #### Why??? */
|
|
529 DEVICE_X_MOUSE_TIMESTAMP (d) = DEVICE_X_GLOBAL_MOUSE_TIMESTAMP (d);
|
|
530
|
|
531 switch (data->action)
|
|
532 {
|
|
533 case SCROLLBAR_LINE_UP:
|
|
534 signal_special_Xt_user_event (win, Qscrollbar_line_up, win);
|
|
535 break;
|
|
536
|
|
537 case SCROLLBAR_LINE_DOWN:
|
|
538 signal_special_Xt_user_event (win, Qscrollbar_line_down, win);
|
|
539 break;
|
|
540
|
|
541 /* The Athena scrollbar paging behavior is that of xterms.
|
|
542 Depending on where you click the size of the page varies.
|
|
543 Motif always does a standard Emacs page. */
|
|
544 case SCROLLBAR_PAGE_UP:
|
16
|
545 #if !defined (LWLIB_SCROLLBARS_MOTIF) && !defined (LWLIB_SCROLLBARS_LUCID) && \
|
|
546 !defined (LWLIB_SCROLLBARS_ATHENA3D)
|
0
|
547 {
|
|
548 double tmp = ((double) data->slider_value /
|
|
549 (double) SCROLLBAR_X_POS_DATA(instance).scrollbar_height);
|
|
550 double line = tmp *
|
|
551 (double) window_displayed_height (XWINDOW (win));
|
|
552
|
|
553 if (line > -1.0)
|
|
554 line = -1.0;
|
|
555 signal_special_Xt_user_event (win, Qscrollbar_page_up,
|
|
556 Fcons (win, make_int ((int) line)));
|
|
557 }
|
|
558 #else
|
|
559 signal_special_Xt_user_event (win, Qscrollbar_page_up,
|
|
560 Fcons (win, Qnil));
|
|
561 #endif
|
|
562 break;
|
|
563
|
|
564 case SCROLLBAR_PAGE_DOWN:
|
16
|
565 #if !defined (LWLIB_SCROLLBARS_MOTIF) && !defined (LWLIB_SCROLLBARS_LUCID) && \
|
|
566 !defined (LWLIB_SCROLLBARS_ATHENA3D)
|
0
|
567 {
|
|
568 double tmp = ((double) data->slider_value /
|
|
569 (double) SCROLLBAR_X_POS_DATA(instance).scrollbar_height);
|
|
570 double line = tmp *
|
|
571 (double) window_displayed_height (XWINDOW (win));
|
|
572
|
|
573 if (SCROLLBAR_X_POS_DATA(instance).maximum >
|
|
574 (SCROLLBAR_X_POS_DATA(instance).slider_size + SCROLLBAR_X_POS_DATA(instance).slider_position))
|
|
575 {
|
|
576 if (line < 1.0)
|
|
577 line = 1.0;
|
|
578 signal_special_Xt_user_event (win, Qscrollbar_page_down,
|
|
579 Fcons (win,
|
|
580 make_int ((int) line)));
|
|
581 }
|
|
582 }
|
|
583 #else
|
|
584 signal_special_Xt_user_event (win, Qscrollbar_page_down,
|
|
585 Fcons (win, Qnil));
|
|
586 #endif
|
|
587 break;
|
|
588
|
|
589 case SCROLLBAR_TOP:
|
|
590 signal_special_Xt_user_event (win, Qscrollbar_to_top, win);
|
|
591 break;
|
|
592
|
|
593 case SCROLLBAR_BOTTOM:
|
|
594 signal_special_Xt_user_event (win, Qscrollbar_to_bottom, win);
|
|
595 break;
|
|
596
|
|
597
|
|
598 case SCROLLBAR_CHANGE:
|
26
|
599 inhibit_slider_size_change = 0;
|
0
|
600 #if defined (LWLIB_SCROLLBARS_MOTIF) || defined (LWLIB_SCROLLBARS_LUCID)
|
|
601 vertical_drag_in_progress = 0;
|
|
602 SCROLLBAR_X_VDRAG_ORIG_VALUE (instance) = data->slider_value;
|
|
603 SCROLLBAR_X_VDRAG_ORIG_WINDOW_START (instance) =
|
|
604 XINT (Fwindow_start (win));
|
20
|
605 #else
|
|
606 stupid_vertical_scrollbar_drag_hack = 0;
|
0
|
607 #endif
|
|
608 break;
|
|
609
|
|
610 case SCROLLBAR_DRAG:
|
|
611 {
|
|
612 int value;
|
|
613
|
26
|
614 inhibit_slider_size_change = 1;
|
0
|
615
|
|
616 #if defined (LWLIB_SCROLLBARS_MOTIF) || defined (LWLIB_SCROLLBARS_LUCID)
|
|
617 /* Doing drags with Motif-like scrollbars is a mess, since we
|
|
618 want to avoid having the window position jump when you
|
|
619 first grab the scrollbar, but we also want to ensure that
|
|
620 you can scroll all the way to the top or bottom of the
|
|
621 buffer. This can all be replaced with something sane when
|
|
622 we get line-based scrolling. */
|
|
623
|
|
624 vertical_drag_in_progress = 1;
|
|
625
|
|
626 if (SCROLLBAR_X_VDRAG_ORIG_VALUE (instance) < 0)
|
|
627 {
|
|
628 SCROLLBAR_X_VDRAG_ORIG_VALUE (instance) = data->slider_value;
|
|
629 SCROLLBAR_X_VDRAG_ORIG_WINDOW_START (instance) =
|
|
630 XINT (Fwindow_start (win));
|
|
631 }
|
|
632
|
|
633 /* Could replace this piecewise linear scrolling with a
|
|
634 quadratic through the three points, but I'm not sure that
|
|
635 would feel any nicer in practice. */
|
|
636 if (data->slider_value < SCROLLBAR_X_VDRAG_ORIG_VALUE (instance))
|
|
637 {
|
|
638 /* We've dragged up; slide linearly from original position to
|
|
639 window-start=data.minimum, slider-value=data.minimum. */
|
|
640
|
|
641 if (SCROLLBAR_X_VDRAG_ORIG_VALUE (instance)
|
|
642 <= SCROLLBAR_X_POS_DATA (instance).minimum)
|
|
643 {
|
|
644 /* shouldn't get here, but just in case */
|
|
645 value = SCROLLBAR_X_POS_DATA (instance).minimum;
|
|
646 }
|
|
647 else
|
|
648 {
|
|
649 value = (SCROLLBAR_X_POS_DATA (instance).minimum
|
|
650 + (((double)
|
|
651 (SCROLLBAR_X_VDRAG_ORIG_WINDOW_START (instance)
|
|
652 - SCROLLBAR_X_POS_DATA (instance).minimum)
|
|
653 * (data->slider_value -
|
|
654 SCROLLBAR_X_POS_DATA (instance).minimum))
|
|
655 / (SCROLLBAR_X_VDRAG_ORIG_VALUE (instance)
|
|
656 - SCROLLBAR_X_POS_DATA (instance).minimum)));
|
|
657 }
|
|
658 }
|
|
659 else
|
|
660 {
|
|
661 /* We've dragged down; slide linearly from original position to
|
|
662 window-start=data.maximum, slider-value=data.maximum. */
|
|
663
|
|
664 if (SCROLLBAR_X_VDRAG_ORIG_VALUE (instance)
|
|
665 >= (SCROLLBAR_X_POS_DATA (instance).maximum -
|
|
666 SCROLLBAR_X_POS_DATA (instance).slider_size))
|
|
667 {
|
|
668 /* avoid divide by zero */
|
|
669 value = SCROLLBAR_X_VDRAG_ORIG_WINDOW_START (instance);
|
|
670 }
|
|
671 else
|
|
672 {
|
|
673 value = (SCROLLBAR_X_VDRAG_ORIG_WINDOW_START (instance)
|
|
674 + (((double) (SCROLLBAR_X_POS_DATA (instance).maximum
|
|
675 - SCROLLBAR_X_VDRAG_ORIG_WINDOW_START (instance))
|
|
676 * (data->slider_value
|
|
677 - SCROLLBAR_X_VDRAG_ORIG_VALUE (instance)))
|
|
678 / (SCROLLBAR_X_POS_DATA (instance).maximum
|
|
679 - SCROLLBAR_X_POS_DATA (instance).slider_size
|
|
680 - SCROLLBAR_X_VDRAG_ORIG_VALUE (instance))));
|
|
681 }
|
|
682 }
|
|
683 #else
|
16
|
684 stupid_vertical_scrollbar_drag_hack = 0;
|
0
|
685 value = data->slider_value;
|
|
686 #endif
|
|
687
|
|
688 if (value >= SCROLLBAR_X_POS_DATA (instance).maximum)
|
|
689 value = SCROLLBAR_X_POS_DATA (instance).maximum - 1;
|
|
690 if (value < SCROLLBAR_X_POS_DATA (instance).minimum)
|
|
691 value = SCROLLBAR_X_POS_DATA (instance).minimum;
|
|
692
|
|
693 signal_special_Xt_user_event (win, Qscrollbar_vertical_drag,
|
|
694 Fcons (win, make_int (value)));
|
|
695 }
|
|
696 break;
|
|
697
|
|
698 }
|
|
699 }
|
|
700
|
|
701 /*
|
|
702 * This is the only callback provided for horizontal scrollbars. It
|
|
703 * should be able to handle all of the scrollbar events in
|
|
704 * scroll_action (see lwlib.h). The client data will be of type
|
|
705 * scroll_event (see lwlib.h). */
|
|
706 static void
|
|
707 x_update_horizontal_scrollbar_callback (Widget widget, LWLIB_ID id,
|
|
708 XtPointer client_data)
|
|
709 {
|
|
710 scroll_event *data = (scroll_event *) client_data;
|
|
711 struct device *d = get_device_from_display (XtDisplay (widget));
|
|
712 struct frame *f = x_any_window_to_frame (d, XtWindow (widget));
|
|
713 Lisp_Object win;
|
|
714 struct window_mirror *mirror;
|
|
715
|
|
716 if (!f)
|
|
717 return;
|
|
718
|
|
719 mirror = find_scrollbar_window_mirror (f, id);
|
|
720 win = real_window (mirror, 1);
|
|
721
|
|
722 if (NILP (win))
|
|
723 return;
|
|
724
|
|
725 /* It seems that this is necessary whenever signal_special_Xt_user_event()
|
|
726 is called. #### Why??? */
|
|
727 DEVICE_X_MOUSE_TIMESTAMP (d) = DEVICE_X_GLOBAL_MOUSE_TIMESTAMP (d);
|
|
728
|
|
729 switch (data->action)
|
|
730 {
|
|
731 case SCROLLBAR_LINE_UP:
|
|
732 signal_special_Xt_user_event (win, Qscrollbar_char_left, win);
|
|
733 break;
|
|
734 case SCROLLBAR_LINE_DOWN:
|
|
735 signal_special_Xt_user_event (win, Qscrollbar_char_right, win);
|
|
736 break;
|
|
737 case SCROLLBAR_PAGE_UP:
|
|
738 signal_special_Xt_user_event (win, Qscrollbar_page_left, win);
|
|
739 break;
|
|
740 case SCROLLBAR_PAGE_DOWN:
|
|
741 signal_special_Xt_user_event (win, Qscrollbar_page_right, win);
|
|
742 break;
|
|
743 case SCROLLBAR_TOP:
|
|
744 signal_special_Xt_user_event (win, Qscrollbar_to_left, win);
|
|
745 break;
|
|
746 case SCROLLBAR_BOTTOM:
|
|
747 signal_special_Xt_user_event (win, Qscrollbar_to_right, win);
|
|
748 break;
|
|
749 case SCROLLBAR_CHANGE:
|
26
|
750 inhibit_slider_size_change = 0;
|
0
|
751 break;
|
|
752 case SCROLLBAR_DRAG:
|
26
|
753 inhibit_slider_size_change = 1;
|
0
|
754 /* #### Fix the damn toolkit code so they all work the same way.
|
|
755 Lucid is the one mostly wrong.*/
|
16
|
756 #if defined (LWLIB_SCROLLBARS_LUCID) || defined (LWLIB_SCROLLBARS_ATHENA3D)
|
0
|
757 signal_special_Xt_user_event (win, Qscrollbar_horizontal_drag,
|
|
758 (Fcons
|
|
759 (win, make_int (data->slider_value))));
|
|
760 #else
|
|
761 signal_special_Xt_user_event (win, Qscrollbar_horizontal_drag,
|
|
762 (Fcons
|
|
763 (win,
|
|
764 make_int (data->slider_value - 1))));
|
|
765 #endif
|
|
766 break;
|
|
767 default:
|
|
768 break;
|
|
769 }
|
|
770 }
|
|
771
|
|
772 static void
|
|
773 x_scrollbar_pointer_changed_in_window (struct window *w)
|
|
774 {
|
|
775 Lisp_Object window = Qnil;
|
|
776
|
|
777 XSETWINDOW (window, w);
|
|
778 x_scrollbar_loop (X_SET_SCROLLBAR_POINTER, window, find_window_mirror (w),
|
|
779 0, (Window) NULL);
|
|
780 }
|
|
781
|
|
782 /* Called directly from x_any_window_to_frame in frame-x.c */
|
|
783 EMACS_INT
|
|
784 x_window_is_scrollbar (struct frame *f, Window win)
|
|
785 {
|
|
786 if (!FRAME_X_P (f))
|
|
787 return 0;
|
|
788
|
|
789 if (f->mirror_dirty)
|
|
790 update_frame_window_mirror (f);
|
|
791 return (EMACS_INT) x_scrollbar_loop (X_WINDOW_IS_SCROLLBAR, f->root_window,
|
|
792 f->root_mirror, 0, win);
|
|
793 }
|
|
794
|
|
795 /* Make sure that all scrollbars on frame are up-to-date. Called
|
|
796 directly from x_set_frame_properties in frame-x.c*/
|
|
797 void
|
|
798 x_update_frame_scrollbars (struct frame *f)
|
|
799 {
|
|
800 /* Consider this code to be "in_display" so that we abort() if Fsignal()
|
|
801 gets called. */
|
|
802 in_display++;
|
|
803 x_scrollbar_loop (X_UPDATE_FRAME_SCROLLBARS, f->root_window, f->root_mirror,
|
|
804 0, (Window) NULL);
|
|
805 in_display--;
|
|
806 if (in_display < 0) abort ();
|
|
807 }
|
|
808
|
|
809 #ifdef MEMORY_USAGE_STATS
|
|
810
|
|
811 static int
|
|
812 x_compute_scrollbar_instance_usage (struct device *d,
|
|
813 struct scrollbar_instance *inst,
|
|
814 struct overhead_stats *ovstats)
|
|
815 {
|
|
816 int total = 0;
|
|
817
|
|
818 while (inst)
|
|
819 {
|
|
820 struct x_scrollbar_data *data =
|
|
821 (struct x_scrollbar_data *) inst->scrollbar_data;
|
|
822
|
|
823 total += malloced_storage_size (data, sizeof (*data), ovstats);
|
|
824 total += malloced_storage_size (data->name, 1 + strlen (data->name),
|
|
825 ovstats);
|
|
826 inst = inst->next;
|
|
827 }
|
|
828
|
|
829 return total;
|
|
830 }
|
|
831
|
|
832 #endif /* MEMORY_USAGE_STATS */
|
|
833
|
|
834
|
|
835 /************************************************************************/
|
|
836 /* initialization */
|
|
837 /************************************************************************/
|
|
838
|
|
839 void
|
|
840 console_type_create_scrollbar_x (void)
|
|
841 {
|
26
|
842 CONSOLE_HAS_METHOD (x, inhibit_scrollbar_slider_size_change);
|
0
|
843 CONSOLE_HAS_METHOD (x, free_scrollbar_instance);
|
|
844 CONSOLE_HAS_METHOD (x, release_scrollbar_instance);
|
|
845 CONSOLE_HAS_METHOD (x, create_scrollbar_instance);
|
|
846 CONSOLE_HAS_METHOD (x, update_scrollbar_instance_values);
|
|
847 CONSOLE_HAS_METHOD (x, update_scrollbar_instance_status);
|
|
848 CONSOLE_HAS_METHOD (x, scrollbar_width_changed_in_frame);
|
|
849 CONSOLE_HAS_METHOD (x, scrollbar_height_changed_in_frame);
|
|
850 CONSOLE_HAS_METHOD (x, scrollbar_pointer_changed_in_window);
|
|
851 #ifdef MEMORY_USAGE_STATS
|
|
852 CONSOLE_HAS_METHOD (x, compute_scrollbar_instance_usage);
|
|
853 #endif /* MEMORY_USAGE_STATS */
|
|
854 }
|
|
855
|
|
856 void
|
|
857 vars_of_scrollbar_x (void)
|
|
858 {
|
|
859 #if defined (LWLIB_SCROLLBARS_LUCID)
|
|
860 Fprovide (intern ("lucid-scrollbars"));
|
|
861 #elif defined (LWLIB_SCROLLBARS_MOTIF)
|
|
862 Fprovide (intern ("motif-scrollbars"));
|
|
863 #elif defined (LWLIB_SCROLLBARS_ATHENA)
|
|
864 Fprovide (intern ("athena-scrollbars"));
|
|
865 #endif
|
20
|
866 stupid_vertical_scrollbar_drag_hack = 1;
|
0
|
867 }
|