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