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