0
|
1 /* Generic scrollbar implementation.
|
|
2 Copyright (C) 1994, 1995 Board of Trustees, University of Illinois.
|
|
3 Copyright (C) 1995 Free Software Foundation, Inc.
|
|
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 /* This file has been Mule-ized. */
|
|
27
|
|
28 #include <config.h>
|
|
29 #include "lisp.h"
|
|
30
|
|
31 #include "buffer.h"
|
|
32 #include "commands.h"
|
|
33 #include "scrollbar.h"
|
|
34 #include "device.h"
|
|
35 #include "frame.h"
|
|
36 #include "glyphs.h"
|
|
37 #include "window.h"
|
|
38
|
|
39 Lisp_Object Qinit_scrollbar_from_resources;
|
|
40
|
|
41 Lisp_Object Qscrollbar_line_up;
|
|
42 Lisp_Object Qscrollbar_line_down;
|
|
43 Lisp_Object Qscrollbar_page_up;
|
|
44 Lisp_Object Qscrollbar_page_down;
|
|
45 Lisp_Object Qscrollbar_to_top;
|
|
46 Lisp_Object Qscrollbar_to_bottom;
|
|
47 Lisp_Object Qscrollbar_vertical_drag;
|
|
48
|
|
49 Lisp_Object Qscrollbar_char_left;
|
|
50 Lisp_Object Qscrollbar_char_right;
|
|
51 Lisp_Object Qscrollbar_page_left;
|
|
52 Lisp_Object Qscrollbar_page_right;
|
|
53 Lisp_Object Qscrollbar_to_left;
|
|
54 Lisp_Object Qscrollbar_to_right;
|
|
55 Lisp_Object Qscrollbar_horizontal_drag;
|
|
56
|
|
57 #define DEFAULT_SCROLLBAR_WIDTH 15
|
|
58 #define DEFAULT_SCROLLBAR_HEIGHT 15
|
|
59
|
|
60 /* Width of the scrollbar. */
|
|
61 Lisp_Object Vscrollbar_width;
|
|
62
|
|
63 /* Height of the scrollbar. */
|
|
64 Lisp_Object Vscrollbar_height;
|
|
65
|
|
66 Lisp_Object Vscrollbar_pointer_glyph;
|
|
67
|
|
68 static void update_scrollbar_instance (struct window *w, int vertical,
|
|
69 struct scrollbar_instance *instance);
|
|
70
|
|
71
|
|
72 static void
|
|
73 free_scrollbar_instance (struct scrollbar_instance *instance,
|
|
74 struct frame *frame)
|
|
75 {
|
|
76 if (!instance)
|
|
77 return;
|
|
78 else
|
|
79 {
|
|
80 struct device *d = XDEVICE (frame->device);
|
|
81
|
|
82 MAYBE_DEVMETH (d, free_scrollbar_instance, (instance));
|
|
83 xfree (instance);
|
|
84 }
|
|
85 }
|
|
86
|
|
87 static void
|
|
88 free_window_mirror_scrollbars (struct window_mirror *mir)
|
|
89 {
|
|
90 struct frame *f = mir->frame;
|
|
91 free_scrollbar_instance (mir->scrollbar_vertical_instance, f);
|
|
92 mir->scrollbar_vertical_instance = 0;
|
|
93 free_scrollbar_instance (mir->scrollbar_horizontal_instance, f);
|
|
94 mir->scrollbar_horizontal_instance = 0;
|
|
95 }
|
|
96
|
|
97 static struct window_mirror *
|
|
98 free_scrollbars_loop (Lisp_Object window, struct window_mirror *mir)
|
|
99 {
|
|
100 struct window_mirror *retval = NULL;
|
|
101
|
|
102 while (mir)
|
|
103 {
|
|
104 struct scrollbar_instance *vinst = mir->scrollbar_vertical_instance;
|
|
105 struct scrollbar_instance *hinst = mir->scrollbar_horizontal_instance;
|
|
106 struct frame *f;
|
|
107
|
|
108 assert (!NILP (window));
|
|
109 f = XFRAME (XWINDOW (window)->frame);
|
|
110
|
|
111 if (mir->vchild)
|
|
112 {
|
|
113 retval = free_scrollbars_loop (XWINDOW (window)->vchild,
|
|
114 mir->vchild);
|
|
115 }
|
|
116 else if (mir->hchild)
|
|
117 {
|
|
118 retval = free_scrollbars_loop (XWINDOW (window)->hchild,
|
|
119 mir->hchild);
|
|
120 }
|
|
121
|
|
122 if (retval != NULL)
|
|
123 return retval;
|
|
124
|
|
125 if (hinst || vinst)
|
|
126 free_window_mirror_scrollbars (mir);
|
|
127
|
|
128 mir = mir->next;
|
|
129 window = XWINDOW (window)->next;
|
|
130 }
|
|
131
|
|
132 return NULL;
|
|
133 }
|
|
134
|
|
135 /* Destroy all scrollbars associated with FRAME. Only called from
|
|
136 delete_frame_internal.
|
|
137 */
|
|
138 #define FREE_FRAME_SCROLLBARS_INTERNAL(cache) \
|
|
139 do { \
|
|
140 while (FRAME_SB_##cache (f)) \
|
|
141 { \
|
|
142 struct scrollbar_instance *tofree = FRAME_SB_##cache (f); \
|
|
143 FRAME_SB_##cache (f) = FRAME_SB_##cache (f)->next; \
|
|
144 tofree->next = NULL; \
|
|
145 free_scrollbar_instance (tofree, f); \
|
|
146 } \
|
|
147 } while (0)
|
|
148
|
|
149 void
|
|
150 free_frame_scrollbars (struct frame *f)
|
|
151 {
|
|
152 if (!HAS_FRAMEMETH_P (f, create_scrollbar_instance))
|
|
153 return;
|
|
154
|
|
155 if (f->mirror_dirty)
|
|
156 update_frame_window_mirror (f);
|
|
157
|
|
158 free_scrollbars_loop (f->root_window, f->root_mirror);
|
|
159
|
|
160 FREE_FRAME_SCROLLBARS_INTERNAL (VCACHE);
|
|
161 FREE_FRAME_SCROLLBARS_INTERNAL (HCACHE);
|
|
162 }
|
|
163 #undef FREE_FRAME_SCROLLBARS_INTERNAL
|
|
164
|
|
165
|
|
166 static struct scrollbar_instance *
|
|
167 create_scrollbar_instance (struct frame *f, int vertical)
|
|
168 {
|
|
169 struct device *d = XDEVICE (f->device);
|
|
170 struct scrollbar_instance *instance =
|
185
|
171 xnew_and_zero (struct scrollbar_instance);
|
0
|
172
|
|
173 MAYBE_DEVMETH (d, create_scrollbar_instance, (f, vertical, instance));
|
|
174
|
|
175 return instance;
|
|
176 }
|
|
177
|
|
178
|
|
179 #define GET_SCROLLBAR_INSTANCE_INTERNAL(cache) \
|
|
180 do { \
|
|
181 if (FRAME_SB_##cache (f)) \
|
|
182 { \
|
|
183 struct scrollbar_instance *retval = FRAME_SB_##cache (f); \
|
|
184 FRAME_SB_##cache (f) = FRAME_SB_##cache (f)->next; \
|
|
185 retval->next = NULL; \
|
|
186 return retval; \
|
|
187 } \
|
|
188 } while (0)
|
|
189
|
|
190 static struct scrollbar_instance *
|
|
191 get_scrollbar_instance (struct frame *f, int vertical)
|
|
192 {
|
|
193 /* Check if there are any available scrollbars already in existence. */
|
|
194 if (vertical)
|
|
195 GET_SCROLLBAR_INSTANCE_INTERNAL (VCACHE);
|
|
196 else
|
|
197 GET_SCROLLBAR_INSTANCE_INTERNAL (HCACHE);
|
|
198
|
|
199 return create_scrollbar_instance (f, vertical);
|
|
200 }
|
|
201 #undef GET_SCROLLBAR_INSTANCE_INTERNAL
|
|
202
|
|
203 #define RELEASE_SCROLLBAR_INSTANCE_INTERNAL(cache) \
|
|
204 do { \
|
|
205 if (!FRAME_SB_##cache (f)) \
|
|
206 { \
|
|
207 instance->next = NULL; \
|
|
208 FRAME_SB_##cache (f) = instance; \
|
|
209 } \
|
|
210 else \
|
|
211 { \
|
|
212 instance->next = FRAME_SB_##cache (f); \
|
|
213 FRAME_SB_##cache (f) = instance; \
|
|
214 } \
|
|
215 } while (0)
|
|
216
|
|
217 static void
|
|
218 release_scrollbar_instance (struct frame *f, int vertical,
|
|
219 struct scrollbar_instance *instance)
|
|
220 {
|
|
221 /* #### should we do "instance->mir = 0;" for safety? */
|
|
222 if (vertical)
|
|
223 RELEASE_SCROLLBAR_INSTANCE_INTERNAL (VCACHE);
|
|
224 else
|
|
225 RELEASE_SCROLLBAR_INSTANCE_INTERNAL (HCACHE);
|
|
226 }
|
|
227 #undef RELEASE_SCROLLBAR_INSTANCE_INTERNAL
|
|
228
|
|
229 #ifdef MEMORY_USAGE_STATS
|
|
230
|
|
231 int
|
|
232 compute_scrollbar_instance_usage (struct device *d,
|
|
233 struct scrollbar_instance *inst,
|
|
234 struct overhead_stats *ovstats)
|
|
235 {
|
|
236 int total = 0;
|
|
237
|
|
238 total += DEVMETH (d, compute_scrollbar_instance_usage, (d, inst, ovstats));
|
|
239
|
|
240 while (inst)
|
|
241 {
|
|
242 total += malloced_storage_size (inst, sizeof (*inst), ovstats);
|
|
243 inst = inst->next;
|
|
244 }
|
|
245
|
|
246 return total;
|
|
247 }
|
|
248
|
|
249 #endif /* MEMORY_USAGE_STATS */
|
|
250
|
|
251 void
|
|
252 update_window_scrollbars (struct window *w, struct window_mirror *mirror,
|
|
253 int active, int horiz_only)
|
|
254 {
|
|
255 struct frame *f = XFRAME (w->frame);
|
|
256 struct device *d = XDEVICE (f->device);
|
|
257
|
|
258 if (!HAS_DEVMETH_P (d, create_scrollbar_instance))
|
|
259 return;
|
|
260
|
|
261 in_display++;
|
|
262
|
|
263 /* It is possible for this to get called from the mirror update
|
|
264 routines. In that case the structure is in an indeterminate
|
|
265 state but we know exactly what struct we are working with. So we
|
|
266 pass it in in that case. We also take advantage of it at some
|
|
267 other points where we know what the mirror struct is. */
|
|
268 if (!mirror)
|
|
269 mirror = find_window_mirror (w);
|
|
270
|
|
271 if (!mirror->scrollbar_vertical_instance && active)
|
|
272 mirror->scrollbar_vertical_instance = get_scrollbar_instance (f, 1);
|
|
273
|
|
274 if (!mirror->scrollbar_horizontal_instance && active)
|
|
275 mirror->scrollbar_horizontal_instance = get_scrollbar_instance (f, 0);
|
|
276
|
|
277 if (!horiz_only && mirror->scrollbar_vertical_instance)
|
|
278 {
|
|
279 int size = (active ? window_scrollbar_width (w) : 0);
|
|
280 struct scrollbar_instance *instance;
|
|
281
|
|
282 instance = mirror->scrollbar_vertical_instance;
|
|
283 instance->scrollbar_is_active = active;
|
|
284 instance->mirror = mirror;
|
|
285
|
|
286 if (active && size)
|
|
287 update_scrollbar_instance (w, 1, instance);
|
|
288 MAYBE_DEVMETH (d, update_scrollbar_instance_status,
|
|
289 (w, active, size, instance));
|
|
290
|
|
291 if (!active)
|
|
292 {
|
|
293 release_scrollbar_instance (f, 1, instance);
|
|
294 mirror->scrollbar_vertical_instance = NULL;
|
|
295 }
|
|
296 }
|
|
297
|
|
298 if (mirror->scrollbar_horizontal_instance)
|
|
299 {
|
|
300 int size = (active ? window_scrollbar_height (w) : 0);
|
|
301 struct scrollbar_instance *instance;
|
|
302
|
|
303 instance = mirror->scrollbar_horizontal_instance;
|
|
304 instance->scrollbar_is_active = active;
|
|
305 instance->mirror = mirror;
|
|
306
|
|
307 if (active && size)
|
|
308 update_scrollbar_instance (w, 0, instance);
|
|
309 MAYBE_DEVMETH (d, update_scrollbar_instance_status,
|
|
310 (w, active, size, instance));
|
|
311
|
|
312 if (!active)
|
|
313 {
|
|
314 release_scrollbar_instance (f, 0, instance);
|
|
315 mirror->scrollbar_horizontal_instance = NULL;
|
|
316 }
|
|
317 }
|
|
318
|
|
319 in_display--;
|
|
320 }
|
|
321
|
|
322 void
|
|
323 release_window_mirror_scrollbars (struct window_mirror *mir)
|
|
324 {
|
|
325 struct device *d = XDEVICE (mir->frame->device);
|
|
326
|
|
327 if (!HAS_DEVMETH_P (d, create_scrollbar_instance))
|
|
328 return;
|
|
329
|
|
330 if (mir->scrollbar_vertical_instance)
|
|
331 {
|
|
332 release_scrollbar_instance (mir->frame, 1,
|
|
333 mir->scrollbar_vertical_instance);
|
|
334 MAYBE_DEVMETH (d, release_scrollbar_instance,
|
|
335 (mir->scrollbar_vertical_instance));
|
|
336 }
|
|
337 mir->scrollbar_vertical_instance = 0;
|
|
338
|
|
339 if (mir->scrollbar_horizontal_instance)
|
|
340 {
|
|
341 release_scrollbar_instance (mir->frame, 0,
|
|
342 mir->scrollbar_horizontal_instance);
|
|
343 MAYBE_DEVMETH (d, release_scrollbar_instance,
|
|
344 (mir->scrollbar_horizontal_instance));
|
|
345 }
|
|
346 mir->scrollbar_horizontal_instance = 0;
|
|
347 }
|
|
348
|
|
349 /* This check needs to be done in the device-specific side. */
|
|
350 #define UPDATE_DATA_FIELD(field, value) \
|
|
351 if (instance->field != value) {\
|
|
352 instance->field = value;\
|
|
353 instance->scrollbar_instance_changed = 1;\
|
|
354 }\
|
|
355
|
|
356 /*
|
|
357 * If w->sb_point is on the top line then return w->sb_point else
|
|
358 * return w->start. If flag, then return beginning point of line
|
|
359 * which w->sb_point lies on.
|
|
360 */
|
|
361 static Bufpos
|
|
362 scrollbar_point (struct window *w, int flag)
|
|
363 {
|
|
364 Bufpos start_pos, end_pos, sb_pos;
|
|
365 Lisp_Object buf;
|
|
366 struct buffer *b;
|
|
367
|
|
368 if (NILP (w->buffer)) /* non-leaf window */
|
|
369 return 0;
|
|
370
|
|
371 start_pos = marker_position (w->start[CURRENT_DISP]);
|
|
372 sb_pos = marker_position (w->sb_point);
|
|
373
|
|
374 if (!flag && sb_pos < start_pos)
|
|
375 return start_pos;
|
|
376
|
|
377 buf = get_buffer (w->buffer, 0);
|
|
378 if (!NILP (buf))
|
|
379 b = XBUFFER (buf);
|
|
380 else
|
|
381 return start_pos;
|
|
382
|
|
383 if (flag)
|
|
384 end_pos = find_next_newline_no_quit (b, sb_pos, -1);
|
|
385 else
|
|
386 end_pos = find_next_newline_no_quit (b, start_pos, 1);
|
|
387
|
|
388 if (flag)
|
|
389 return end_pos;
|
|
390 else if (sb_pos > end_pos)
|
|
391 return start_pos;
|
|
392 else
|
|
393 return sb_pos;
|
|
394 }
|
|
395
|
|
396 /*
|
|
397 * Update a window's horizontal or vertical scrollbar.
|
|
398 */
|
|
399 static void
|
|
400 update_scrollbar_instance (struct window *w, int vertical,
|
|
401 struct scrollbar_instance *instance)
|
|
402 {
|
|
403 struct frame *f = XFRAME (w->frame);
|
|
404 struct device *d = XDEVICE (f->device);
|
|
405 struct buffer *b = XBUFFER (w->buffer);
|
|
406 Bufpos start_pos, end_pos, sb_pos;
|
102
|
407 int scrollbar_width = window_scrollbar_width (w);
|
0
|
408 int scrollbar_height = window_scrollbar_height (w);
|
|
409
|
|
410 int new_line_increment = -1, new_page_increment = -1;
|
|
411 int new_minimum = -1, new_maximum = -1;
|
|
412 int new_slider_size = -1, new_slider_position = -1;
|
|
413 int new_width = -1, new_height = -1, new_x = -1, new_y = -1;
|
|
414 struct window *new_window = 0; /* kludge city */
|
|
415
|
|
416 end_pos = BUF_Z (b) - w->window_end_pos[CURRENT_DISP];
|
|
417 sb_pos = scrollbar_point (w, 0);
|
|
418 start_pos = sb_pos;
|
|
419
|
|
420 /* The end position must be strictly greater than the start
|
|
421 position, at least for the Motify scrollbar. It shouldn't hurt
|
|
422 anything for other scrollbar implementations. */
|
|
423 if (end_pos <= start_pos)
|
|
424 end_pos = start_pos + 1;
|
|
425
|
|
426 if (vertical)
|
|
427 {
|
|
428 new_height = WINDOW_TEXT_HEIGHT (w);
|
|
429 new_width = scrollbar_width;
|
|
430 }
|
|
431 else
|
|
432 {
|
|
433 new_height = scrollbar_height;
|
|
434 new_width = WINDOW_TEXT_WIDTH (w);
|
|
435 }
|
|
436
|
|
437 /* If the height and width are not greater than 0, then later on the
|
|
438 Motif widgets will bitch and moan. */
|
|
439 if (new_height <= 0)
|
|
440 new_height = 1;
|
|
441 if (new_width <= 0)
|
|
442 new_width = 1;
|
|
443
|
|
444 assert (instance->mirror && XWINDOW (real_window(instance->mirror, 0)) == w);
|
|
445
|
|
446 /* Only character-based scrollbars are implemented at the moment.
|
|
447 Line-based will be implemented in the future. */
|
|
448
|
|
449 instance->scrollbar_is_active = 1;
|
|
450 new_line_increment = 1;
|
|
451 new_page_increment = 1;
|
|
452
|
102
|
453 /* We used to check for inhibit_scrollbar_slider_size_change here,
|
|
454 but that seems bogus. */
|
|
455 {
|
|
456 int x_offset, y_offset;
|
0
|
457
|
102
|
458 /* Scrollbars are always the farthest from the text area. */
|
|
459 if (vertical)
|
|
460 {
|
|
461 x_offset = (f->scrollbar_on_left
|
|
462 ? WINDOW_LEFT (w)
|
|
463 : WINDOW_RIGHT (w) - scrollbar_width);
|
|
464 y_offset = WINDOW_TEXT_TOP (w) + f->scrollbar_y_offset;
|
|
465 }
|
|
466 else
|
|
467 {
|
|
468 x_offset = WINDOW_TEXT_LEFT (w);
|
|
469 y_offset = f->scrollbar_y_offset +
|
|
470 (f->scrollbar_on_top
|
|
471 ? WINDOW_TOP (w)
|
|
472 : WINDOW_TEXT_BOTTOM (w) + window_bottom_toolbar_height (w));
|
|
473 }
|
0
|
474
|
102
|
475 new_x = x_offset;
|
|
476 new_y = y_offset;
|
|
477 }
|
0
|
478
|
|
479 /* A disabled scrollbar has its slider sized to the entire height of
|
|
480 the scrollbar. Currently the minibuffer scrollbar is
|
|
481 disabled. */
|
|
482 if (!MINI_WINDOW_P (w) && vertical)
|
|
483 {
|
102
|
484 if (!DEVMETH_OR_GIVEN (d, inhibit_scrollbar_slider_size_change, (), 0))
|
0
|
485 {
|
|
486 new_minimum = BUF_BEGV (b);
|
|
487 new_maximum = max (BUF_ZV (b), new_minimum + 1);
|
|
488 new_slider_size = min ((end_pos - start_pos),
|
|
489 (new_maximum - new_minimum));
|
|
490 new_slider_position = sb_pos;
|
|
491 new_window = w;
|
|
492 }
|
|
493 }
|
|
494 else if (!MINI_WINDOW_P (w))
|
|
495 {
|
|
496 /* The minus one is to account for the truncation glyph. */
|
|
497 int wcw = window_char_width (w, 0) - 1;
|
|
498 int max_width, max_slide;
|
|
499
|
|
500 if (w->max_line_len < wcw)
|
|
501 {
|
|
502 max_width = 1;
|
|
503 max_slide = 1;
|
|
504 wcw = 1;
|
|
505 }
|
|
506 else
|
|
507 {
|
|
508 max_width = w->max_line_len + 2;
|
|
509 max_slide = max_width - wcw;
|
|
510 }
|
|
511
|
|
512 new_minimum = 0;
|
|
513 new_maximum = max_width;
|
|
514 new_slider_size = wcw;
|
|
515 new_slider_position = min (w->hscroll, max_slide);
|
|
516 }
|
102
|
517 else /* MINI_WINDOW_P (w) */
|
0
|
518 {
|
|
519 new_minimum = 1;
|
|
520 new_maximum = 2;
|
|
521 new_slider_size = 1;
|
|
522 new_slider_position = 1;
|
|
523 instance->scrollbar_is_active = 0;
|
|
524 }
|
|
525
|
|
526 DEVMETH (d, update_scrollbar_instance_values, (w, instance,
|
|
527 new_line_increment,
|
|
528 new_page_increment,
|
|
529 new_minimum,
|
|
530 new_maximum,
|
|
531 new_slider_size,
|
|
532 new_slider_position,
|
|
533 new_width, new_height,
|
|
534 new_x, new_y));
|
|
535 }
|
|
536
|
|
537 void
|
|
538 init_frame_scrollbars (struct frame *f)
|
|
539 {
|
|
540 struct device *d = XDEVICE (f->device);
|
|
541
|
|
542 if (HAS_DEVMETH_P (d, create_scrollbar_instance))
|
|
543 {
|
276
|
544 int depth = reveal_ghost_specifiers_protected ();
|
272
|
545 Lisp_Object frame;
|
0
|
546 XSETFRAME (frame, f);
|
|
547 call_critical_lisp_code (XDEVICE (FRAME_DEVICE (f)),
|
|
548 Qinit_scrollbar_from_resources,
|
|
549 frame);
|
276
|
550 unbind_to (depth, Qnil);
|
0
|
551 }
|
|
552 }
|
|
553
|
|
554 void
|
|
555 init_device_scrollbars (struct device *d)
|
|
556 {
|
|
557 if (HAS_DEVMETH_P (d, create_scrollbar_instance))
|
|
558 {
|
276
|
559 int depth = reveal_ghost_specifiers_protected ();
|
272
|
560 Lisp_Object device;
|
0
|
561 XSETDEVICE (device, d);
|
|
562 call_critical_lisp_code (d,
|
|
563 Qinit_scrollbar_from_resources,
|
|
564 device);
|
276
|
565 unbind_to (depth, Qnil);
|
0
|
566 }
|
|
567 }
|
|
568
|
|
569 void
|
|
570 init_global_scrollbars (struct device *d)
|
|
571 {
|
|
572 if (HAS_DEVMETH_P (d, create_scrollbar_instance))
|
|
573 {
|
276
|
574 int depth = reveal_ghost_specifiers_protected ();
|
0
|
575 call_critical_lisp_code (d,
|
|
576 Qinit_scrollbar_from_resources,
|
|
577 Qglobal);
|
276
|
578 unbind_to (depth, Qnil);
|
0
|
579 }
|
|
580 }
|
|
581
|
|
582
|
|
583 /* This function is called as a result of a change to the
|
|
584 `scrollbar-width' specifier. */
|
|
585 static void
|
|
586 scrollbar_width_changed_in_frame (Lisp_Object specifier, struct frame *f,
|
|
587 Lisp_Object oldval)
|
|
588 {
|
|
589 MAYBE_FRAMEMETH (f, scrollbar_width_changed_in_frame,
|
|
590 (specifier, f, oldval));
|
|
591 }
|
|
592
|
|
593 /* This function is called as a result of a change to the
|
|
594 `scrollbar-height' specifier. */
|
|
595 static void
|
|
596 scrollbar_height_changed_in_frame (Lisp_Object specifier, struct frame *f,
|
|
597 Lisp_Object oldval)
|
|
598 {
|
|
599 MAYBE_FRAMEMETH (f, scrollbar_height_changed_in_frame,
|
|
600 (specifier, f, oldval));
|
|
601 }
|
|
602
|
|
603 /* This function is called as a result of a change to the
|
|
604 `scrollbar-pointer' glyph. */
|
|
605 static void
|
|
606 scrollbar_pointer_changed_in_window (Lisp_Object specifier, struct window *w,
|
|
607 Lisp_Object oldval)
|
|
608 {
|
|
609 struct frame *f = XFRAME (WINDOW_FRAME (w));
|
|
610
|
|
611 if (f->init_finished)
|
|
612 MAYBE_FRAMEMETH (f, scrollbar_pointer_changed_in_window, (w));
|
|
613 }
|
|
614
|
|
615 /* ####
|
|
616
|
|
617 All of the following stuff is functions that handle scrollbar
|
|
618 actions. All of it should be moved into Lisp. This may require
|
|
619 adding some badly-needed primitives. */
|
|
620
|
|
621 /********** vertical scrollbar stuff **********/
|
|
622
|
|
623 /*
|
|
624 * If the original point is still visible, put the cursor back there.
|
|
625 * Otherwise, when scrolling down stick it at the beginning of the
|
|
626 * first visible line and when scrolling up stick it at the beginning
|
|
627 * of the last visible line.
|
|
628 */
|
|
629
|
|
630 /* #### This function should be moved into Lisp */
|
|
631 static void
|
|
632 scrollbar_reset_cursor (Lisp_Object win, Lisp_Object orig_pt)
|
|
633 {
|
|
634 /* When this function is called we know that start is already
|
|
635 accurate. We know this because either set-window-start or
|
|
636 recenter was called immediately prior to it being called. */
|
|
637 Lisp_Object buf;
|
|
638 Bufpos start_pos = XINT (Fwindow_start (win));
|
|
639 Bufpos ptint = XINT (orig_pt);
|
|
640 struct window *w = XWINDOW (win);
|
|
641 int selected = ((w == XWINDOW (Fselected_window (XFRAME (w->frame)->device)))
|
|
642 ? 1
|
|
643 : 0);
|
|
644
|
|
645 buf = Fwindow_buffer (win);
|
|
646 if (NILP (buf))
|
|
647 return; /* the window was deleted out from under us */
|
|
648
|
|
649 if (ptint < XINT (Fwindow_start (win)))
|
|
650 {
|
|
651 if (selected)
|
|
652 Fgoto_char (make_int (start_pos), buf);
|
|
653 else
|
|
654 Fset_window_point (win, make_int (start_pos));
|
|
655 }
|
|
656 else if (!point_would_be_visible (XWINDOW (win), start_pos, ptint))
|
|
657 {
|
|
658 Fmove_to_window_line (make_int (-1), win);
|
|
659
|
|
660 if (selected)
|
|
661 Fbeginning_of_line (Qnil, buf);
|
|
662 else
|
|
663 {
|
|
664 /* #### Taken from forward-line. */
|
|
665 Bufpos pos;
|
|
666
|
|
667 pos = find_next_newline (XBUFFER (buf),
|
|
668 marker_position (w->pointm[CURRENT_DISP]),
|
|
669 -1);
|
|
670 Fset_window_point (win, make_int (pos));
|
|
671 }
|
|
672 }
|
|
673 else
|
|
674 {
|
|
675 if (selected)
|
|
676 Fgoto_char (orig_pt, buf);
|
|
677 else
|
|
678 Fset_window_point (win, orig_pt);
|
|
679 }
|
|
680 }
|
|
681
|
20
|
682 DEFUN ("scrollbar-line-up", Fscrollbar_line_up, 1, 1, 0, /*
|
0
|
683 Function called when the line-up arrow on the scrollbar is clicked.
|
|
684 This is the little arrow at the top of the scrollbar. One argument, the
|
|
685 scrollbar's window. You can advise this function to change the scrollbar
|
|
686 behavior.
|
20
|
687 */
|
|
688 (window))
|
0
|
689 {
|
|
690 CHECK_LIVE_WINDOW (window);
|
|
691 window_scroll (window, make_int (1), -1, ERROR_ME_NOT);
|
|
692 zmacs_region_stays = 1;
|
|
693 return Qnil;
|
|
694 }
|
|
695
|
20
|
696 DEFUN ("scrollbar-line-down", Fscrollbar_line_down, 1, 1, 0, /*
|
0
|
697 Function called when the line-down arrow on the scrollbar is clicked.
|
|
698 This is the little arrow at the bottom of the scrollbar. One argument, the
|
|
699 scrollbar's window. You can advise this function to change the scrollbar
|
|
700 behavior.
|
20
|
701 */
|
|
702 (window))
|
0
|
703 {
|
|
704 CHECK_LIVE_WINDOW (window);
|
|
705 window_scroll (window, make_int (1), 1, ERROR_ME_NOT);
|
|
706 zmacs_region_stays = 1;
|
|
707 return Qnil;
|
|
708 }
|
|
709
|
20
|
710 DEFUN ("scrollbar-page-up", Fscrollbar_page_up, 1, 1, 0, /*
|
185
|
711 Function called when the user gives the "page-up" scrollbar action.
|
272
|
712 \(The way this is done can vary from scrollbar to scrollbar.) One argument,
|
0
|
713 a cons containing the scrollbar's window and a value (#### document me!
|
|
714 This value is nil for Motif/Lucid scrollbars and a number for Athena
|
|
715 scrollbars). You can advise this function to change the scrollbar
|
|
716 behavior.
|
20
|
717 */
|
|
718 (object))
|
0
|
719 {
|
|
720 Lisp_Object window = Fcar (object);
|
|
721
|
|
722 CHECK_LIVE_WINDOW (window);
|
|
723 /* Motif and Athena scrollbars behave differently, but in accordance
|
|
724 with their standard behaviors. It is not possible to hide the
|
|
725 differences down in lwlib because knowledge of XEmacs buffer and
|
|
726 cursor motion routines is necessary. */
|
82
|
727 #if defined (LWLIB_SCROLLBARS_MOTIF) || defined (LWLIB_SCROLLBARS_LUCID) || \
|
225
|
728 defined (LWLIB_SCROLLBARS_ATHENA3D) || defined(HAVE_MS_WINDOWS)
|
0
|
729 window_scroll (window, Qnil, -1, ERROR_ME_NOT);
|
|
730 #else /* Athena */
|
|
731 {
|
|
732 Bufpos bufpos;
|
|
733 Lisp_Object value = Fcdr (object);
|
|
734
|
|
735 CHECK_INT (value);
|
|
736 Fmove_to_window_line (Qzero, window);
|
|
737 /* can't use Fvertical_motion() because it moves the buffer point
|
|
738 rather than the window's point.
|
|
739
|
|
740 #### It does? Why does it take a window argument then? */
|
|
741 bufpos = vmotion (XWINDOW (window), XINT (Fwindow_point (window)),
|
|
742 XINT (value), 0);
|
|
743 Fset_window_point (window, make_int (bufpos));
|
|
744 Frecenter (Qzero, window);
|
|
745 }
|
|
746 #endif /* Athena */
|
|
747 zmacs_region_stays = 1;
|
|
748 return Qnil;
|
|
749 }
|
|
750
|
20
|
751 DEFUN ("scrollbar-page-down", Fscrollbar_page_down, 1, 1, 0, /*
|
185
|
752 Function called when the user gives the "page-down" scrollbar action.
|
272
|
753 \(The way this is done can vary from scrollbar to scrollbar.) One argument,
|
0
|
754 a cons containing the scrollbar's window and a value (#### document me!
|
|
755 This value is nil for Motif/Lucid scrollbars and a number for Athena
|
|
756 scrollbars). You can advise this function to change the scrollbar
|
|
757 behavior.
|
20
|
758 */
|
|
759 (object))
|
0
|
760 {
|
|
761 Lisp_Object window = Fcar (object);
|
|
762
|
|
763 CHECK_LIVE_WINDOW (window);
|
|
764 /* Motif and Athena scrollbars behave differently, but in accordance
|
|
765 with their standard behaviors. It is not possible to hide the
|
|
766 differences down in lwlib because knowledge of XEmacs buffer and
|
|
767 cursor motion routines is necessary. */
|
82
|
768 #if defined (LWLIB_SCROLLBARS_MOTIF) || defined (LWLIB_SCROLLBARS_LUCID) || \
|
225
|
769 defined (LWLIB_SCROLLBARS_ATHENA3D) || defined (HAVE_MS_WINDOWS)
|
0
|
770 window_scroll (window, Qnil, 1, ERROR_ME_NOT);
|
|
771 #else /* Athena */
|
|
772 {
|
|
773 Lisp_Object value = Fcdr (object);
|
|
774 CHECK_INT (value);
|
|
775 Fmove_to_window_line (value, window);
|
|
776 Frecenter (Qzero, window);
|
|
777 }
|
|
778 #endif /* Athena */
|
|
779 zmacs_region_stays = 1;
|
|
780 return Qnil;
|
|
781 }
|
|
782
|
20
|
783 DEFUN ("scrollbar-to-top", Fscrollbar_to_top, 1, 1, 0, /*
|
185
|
784 Function called when the user invokes the "to-top" scrollbar action.
|
102
|
785 The way this is done can vary from scrollbar to scrollbar, but
|
|
786 C-button1 on the up-arrow is very common. One argument, the
|
|
787 scrollbar's window. You can advise this function to change the
|
0
|
788 scrollbar behavior.
|
20
|
789 */
|
|
790 (window))
|
0
|
791 {
|
102
|
792 Lisp_Object orig_pt = Fwindow_point (window);
|
0
|
793 Fset_window_point (window, Fpoint_min (Fwindow_buffer (window)));
|
|
794 Frecenter (Qzero, window);
|
|
795 scrollbar_reset_cursor (window, orig_pt);
|
|
796 zmacs_region_stays = 1;
|
|
797 return Qnil;
|
|
798 }
|
|
799
|
20
|
800 DEFUN ("scrollbar-to-bottom", Fscrollbar_to_bottom, 1, 1, 0, /*
|
185
|
801 Function called when the user invokes the "to-bottom" scrollbar action.
|
102
|
802 The way this is done can vary from scrollbar to scrollbar, but
|
|
803 C-button1 on the down-arrow is very common. One argument, the
|
|
804 scrollbar's window. You can advise this function to change the
|
0
|
805 scrollbar behavior.
|
20
|
806 */
|
|
807 (window))
|
0
|
808 {
|
102
|
809 Lisp_Object orig_pt = Fwindow_point (window);
|
0
|
810 Fset_window_point (window, Fpoint_max (Fwindow_buffer (window)));
|
102
|
811 Frecenter (make_int (-3), window);
|
0
|
812 scrollbar_reset_cursor (window, orig_pt);
|
|
813 zmacs_region_stays = 1;
|
|
814 return Qnil;
|
|
815 }
|
|
816
|
20
|
817 DEFUN ("scrollbar-vertical-drag", Fscrollbar_vertical_drag, 1, 1, 0, /*
|
102
|
818 Function called when the user drags the vertical scrollbar slider.
|
0
|
819 One argument, a cons containing the scrollbar's window and a value
|
2
|
820 between point-min and point-max. You can advise this function to
|
|
821 change the scrollbar behavior.
|
20
|
822 */
|
|
823 (object))
|
0
|
824 {
|
|
825 Bufpos start_pos;
|
|
826 Lisp_Object orig_pt;
|
|
827 Lisp_Object window = Fcar (object);
|
|
828 Lisp_Object value = Fcdr (object);
|
|
829
|
|
830 orig_pt = Fwindow_point (window);
|
|
831 Fset_marker (XWINDOW (window)->sb_point, value, Fwindow_buffer (window));
|
|
832 start_pos = scrollbar_point (XWINDOW (window), 1);
|
|
833 Fset_window_start (window, make_int (start_pos), Qnil);
|
|
834 scrollbar_reset_cursor (window, orig_pt);
|
82
|
835 Fsit_for(Qzero, Qnil);
|
0
|
836 zmacs_region_stays = 1;
|
|
837 return Qnil;
|
|
838 }
|
|
839
|
20
|
840 DEFUN ("scrollbar-set-hscroll", Fscrollbar_set_hscroll, 2, 2, 0, /*
|
272
|
841 Set WINDOW's hscroll position to VALUE.
|
0
|
842 This ensures that VALUE is in the proper range for the horizontal scrollbar.
|
20
|
843 */
|
|
844 (window, value))
|
0
|
845 {
|
|
846 struct window *w;
|
|
847 int hscroll, wcw, max_len;
|
|
848
|
|
849 CHECK_LIVE_WINDOW (window);
|
|
850 if (!EQ (value, Qmax))
|
|
851 CHECK_INT (value);
|
|
852
|
|
853 w = XWINDOW (window);
|
|
854 wcw = window_char_width (w, 0) - 1;
|
102
|
855 /* ### We should be able to scroll further right as long as there is
|
|
856 a visible truncation glyph. This calculation for max is bogus. */
|
|
857 max_len = w->max_line_len + 2;
|
0
|
858
|
|
859 if (EQ (value, Qmax) || (XINT (value) > (max_len - wcw)))
|
|
860 hscroll = max_len - wcw;
|
|
861 else
|
|
862 hscroll = XINT (value);
|
|
863
|
|
864 /* Can't allow this out of set-window-hscroll's acceptable range. */
|
227
|
865 /* #### What hell on the earth this code limits scroll size to the
|
|
866 machine-dependant SHORT size? -- kkm */
|
0
|
867 if (hscroll < 0)
|
|
868 hscroll = 0;
|
227
|
869 else if (hscroll >= (1 << (SHORTBITS - 1)) - 1)
|
0
|
870 hscroll = (1 << (SHORTBITS - 1)) - 1;
|
|
871
|
|
872 if (hscroll != w->hscroll)
|
|
873 Fset_window_hscroll (window, make_int (hscroll));
|
|
874
|
|
875 return Qnil;
|
|
876 }
|
|
877
|
|
878
|
|
879 /************************************************************************/
|
|
880 /* initialization */
|
|
881 /************************************************************************/
|
|
882
|
|
883 void
|
|
884 syms_of_scrollbar (void)
|
|
885 {
|
|
886 defsymbol (&Qscrollbar_line_up, "scrollbar-line-up");
|
|
887 defsymbol (&Qscrollbar_line_down, "scrollbar-line-down");
|
|
888 defsymbol (&Qscrollbar_page_up, "scrollbar-page-up");
|
|
889 defsymbol (&Qscrollbar_page_down, "scrollbar-page-down");
|
|
890 defsymbol (&Qscrollbar_to_top, "scrollbar-to-top");
|
|
891 defsymbol (&Qscrollbar_to_bottom, "scrollbar-to-bottom");
|
|
892 defsymbol (&Qscrollbar_vertical_drag, "scrollbar-vertical-drag");
|
185
|
893
|
0
|
894 defsymbol (&Qscrollbar_char_left, "scrollbar-char-left");
|
|
895 defsymbol (&Qscrollbar_char_right, "scrollbar-char-right");
|
|
896 defsymbol (&Qscrollbar_page_left, "scrollbar-page-left");
|
|
897 defsymbol (&Qscrollbar_page_right, "scrollbar-page-right");
|
|
898 defsymbol (&Qscrollbar_to_left, "scrollbar-to-left");
|
|
899 defsymbol (&Qscrollbar_to_right, "scrollbar-to-right");
|
|
900 defsymbol (&Qscrollbar_horizontal_drag, "scrollbar-horizontal-drag");
|
|
901
|
|
902 defsymbol (&Qinit_scrollbar_from_resources, "init-scrollbar-from-resources");
|
|
903
|
|
904 /* #### All these functions should be moved into Lisp.
|
|
905 See comment above. */
|
20
|
906 DEFSUBR (Fscrollbar_line_up);
|
|
907 DEFSUBR (Fscrollbar_line_down);
|
|
908 DEFSUBR (Fscrollbar_page_up);
|
|
909 DEFSUBR (Fscrollbar_page_down);
|
|
910 DEFSUBR (Fscrollbar_to_top);
|
|
911 DEFSUBR (Fscrollbar_to_bottom);
|
|
912 DEFSUBR (Fscrollbar_vertical_drag);
|
0
|
913
|
20
|
914 DEFSUBR (Fscrollbar_set_hscroll);
|
0
|
915 }
|
|
916
|
|
917 void
|
|
918 vars_of_scrollbar (void)
|
|
919 {
|
|
920 DEFVAR_LISP ("scrollbar-pointer-glyph", &Vscrollbar_pointer_glyph /*
|
|
921 *The shape of the mouse-pointer when over a scrollbar.
|
|
922 This is a glyph; use `set-glyph-image' to change it.
|
|
923 If unspecified in a particular domain, the window-system-provided
|
|
924 default pointer is used.
|
|
925 */ );
|
|
926
|
|
927 Fprovide (intern ("scrollbar"));
|
|
928 }
|
|
929
|
|
930 void
|
|
931 specifier_vars_of_scrollbar (void)
|
|
932 {
|
|
933 DEFVAR_SPECIFIER ("scrollbar-width", &Vscrollbar_width /*
|
|
934 *Width of vertical scrollbars.
|
|
935 This is a specifier; use `set-specifier' to change it.
|
|
936 */ );
|
276
|
937 Vscrollbar_width = make_magic_specifier (Qnatnum);
|
0
|
938 set_specifier_fallback
|
|
939 (Vscrollbar_width,
|
|
940 list1 (Fcons (Qnil, make_int (DEFAULT_SCROLLBAR_WIDTH))));
|
|
941 set_specifier_caching (Vscrollbar_width,
|
|
942 slot_offset (struct window,
|
|
943 scrollbar_width),
|
|
944 some_window_value_changed,
|
|
945 slot_offset (struct frame,
|
|
946 scrollbar_width),
|
|
947 scrollbar_width_changed_in_frame);
|
|
948
|
|
949 DEFVAR_SPECIFIER ("scrollbar-height", &Vscrollbar_height /*
|
|
950 *Height of horizontal scrollbars.
|
|
951 This is a specifier; use `set-specifier' to change it.
|
|
952 */ );
|
276
|
953 Vscrollbar_height = make_magic_specifier (Qnatnum);
|
0
|
954 set_specifier_fallback
|
|
955 (Vscrollbar_height,
|
|
956 list1 (Fcons (Qnil, make_int (DEFAULT_SCROLLBAR_HEIGHT))));
|
|
957 set_specifier_caching (Vscrollbar_height,
|
|
958 slot_offset (struct window,
|
|
959 scrollbar_height),
|
|
960 some_window_value_changed,
|
|
961 slot_offset (struct frame,
|
|
962 scrollbar_height),
|
|
963 scrollbar_height_changed_in_frame);
|
|
964 }
|
|
965
|
|
966 void
|
|
967 complex_vars_of_scrollbar (void)
|
|
968 {
|
|
969 Vscrollbar_pointer_glyph = Fmake_glyph_internal (Qpointer);
|
|
970
|
|
971 set_specifier_caching (XGLYPH (Vscrollbar_pointer_glyph)->image,
|
|
972 slot_offset (struct window,
|
|
973 scrollbar_pointer),
|
|
974 scrollbar_pointer_changed_in_window,
|
|
975 0, 0);
|
|
976 }
|