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