Merge from emacs-24; up to 2012-05-01T00:16:02Z!rgm@gnu.org
[bpt/emacs.git] / src / fringe.c
1 /* Fringe handling (split from xdisp.c).
2 Copyright (C) 1985-1988, 1993-1995, 1997-2012 Free Software Foundation, Inc.
3
4 This file is part of GNU Emacs.
5
6 GNU Emacs is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
18
19 #include <config.h>
20 #include <stdio.h>
21 #include <setjmp.h>
22
23 #include "lisp.h"
24 #include "frame.h"
25 #include "window.h"
26 #include "dispextern.h"
27 #include "character.h"
28 #include "buffer.h"
29 #include "blockinput.h"
30 #include "termhooks.h"
31
32 #ifdef HAVE_WINDOW_SYSTEM
33
34 /* Fringe bitmaps are represented in three different ways:
35
36 Logical bitmaps are used internally to denote things like
37 'end-of-buffer', 'left-truncation', 'overlay-arrow', etc.
38
39 Physical bitmaps specify the visual appearance of the bitmap,
40 e.g. 'bottom-left-angle', 'left-arrow', 'left-triangle', etc.
41 User defined bitmaps are physical bitmaps.
42
43 Internally, fringe bitmaps for a specific display row are
44 represented as a simple integer that is used as an index
45 into the table of all defined bitmaps. This index is stored
46 in the `fringe' property of the physical bitmap symbol.
47
48 Logical bitmaps are mapped to physical bitmaps through the
49 buffer-local `fringe-indicator-alist' variable.
50
51 Each element of this alist is a cons (LOGICAL . PHYSICAL)
52 mapping a logical bitmap to a physical bitmap.
53 PHYSICAL is either a symbol to use in both left and right fringe,
54 or a cons of two symbols (LEFT . RIGHT) denoting different
55 bitmaps to use in left and right fringe.
56
57 LOGICAL is first looked up in the window's buffer's buffer-local
58 value of the fringe-indicator-alist variable, and if not present,
59 in the global value of fringe-indicator-alist.
60
61 If LOGICAL is not present in either alist, or the PHYSICAL value
62 found is nil, no bitmap is shown for the logical bitmap.
63
64 The `left-fringe' and `right-fringe' display properties
65 must specify physical bitmap symbols.
66 */
67
68 static Lisp_Object Qtruncation, Qcontinuation, Qoverlay_arrow;
69 static Lisp_Object Qempty_line, Qtop_bottom;
70 static Lisp_Object Qhollow_small;
71
72 enum fringe_bitmap_align
73 {
74 ALIGN_BITMAP_CENTER = 0,
75 ALIGN_BITMAP_TOP,
76 ALIGN_BITMAP_BOTTOM
77 };
78
79 struct fringe_bitmap
80 {
81 unsigned short *bits;
82 unsigned height : 8;
83 unsigned width : 8;
84 unsigned period : 8;
85 unsigned align : 2;
86 unsigned dynamic : 1;
87 };
88
89 \f
90 /***********************************************************************
91 Fringe bitmaps
92 ***********************************************************************/
93
94 /* Undefined bitmap. A question mark. */
95 /*
96 ..xxxx..
97 .xxxxxx.
98 xx....xx
99 xx....xx
100 ....xx..
101 ...xx...
102 ...xx...
103 ........
104 ...xx...
105 ...xx...
106 */
107 static unsigned short question_mark_bits[] = {
108 0x3c, 0x7e, 0x7e, 0x0c, 0x18, 0x18, 0x00, 0x18, 0x18};
109
110 /* An arrow like this: `<-'. */
111 /*
112 ...xx...
113 ..xx....
114 .xx.....
115 xxxxxx..
116 xxxxxx..
117 .xx.....
118 ..xx....
119 ...xx...
120 */
121 static unsigned short left_arrow_bits[] = {
122 0x18, 0x30, 0x60, 0xfc, 0xfc, 0x60, 0x30, 0x18};
123
124
125 /* Right truncation arrow bitmap `->'. */
126 /*
127 ...xx...
128 ....xx..
129 .....xx.
130 ..xxxxxx
131 ..xxxxxx
132 .....xx.
133 ....xx..
134 ...xx...
135 */
136 static unsigned short right_arrow_bits[] = {
137 0x18, 0x0c, 0x06, 0x3f, 0x3f, 0x06, 0x0c, 0x18};
138
139
140 /* Up arrow bitmap. */
141 /*
142 ...xx...
143 ..xxxx..
144 .xxxxxx.
145 xxxxxxxx
146 ...xx...
147 ...xx...
148 ...xx...
149 ...xx...
150 */
151 static unsigned short up_arrow_bits[] = {
152 0x18, 0x3c, 0x7e, 0xff, 0x18, 0x18, 0x18, 0x18};
153
154
155 /* Down arrow bitmap. */
156 /*
157 ...xx...
158 ...xx...
159 ...xx...
160 ...xx...
161 xxxxxxxx
162 .xxxxxx.
163 ..xxxx..
164 ...xx...
165 */
166 static unsigned short down_arrow_bits[] = {
167 0x18, 0x18, 0x18, 0x18, 0xff, 0x7e, 0x3c, 0x18};
168
169 /* Marker for continuation lines. */
170 /*
171 ..xxxx..
172 .xxxxx..
173 xx......
174 xxx..x..
175 xxxxxx..
176 .xxxxx..
177 ..xxxx..
178 .xxxxx..
179 */
180 static unsigned short left_curly_arrow_bits[] = {
181 0x3c, 0x7c, 0xc0, 0xe4, 0xfc, 0x7c, 0x3c, 0x7c};
182
183 /* Marker for continued lines. */
184 /*
185 ..xxxx..
186 ..xxxxx.
187 ......xx
188 ..x..xxx
189 ..xxxxxx
190 ..xxxxx.
191 ..xxxx..
192 ..xxxxx.
193 */
194 static unsigned short right_curly_arrow_bits[] = {
195 0x3c, 0x3e, 0x03, 0x27, 0x3f, 0x3e, 0x3c, 0x3e};
196
197 /* Reverse Overlay arrow bitmap. A triangular arrow. */
198 /*
199 ......xx
200 ....xxxx
201 ...xxxxx
202 ..xxxxxx
203 ..xxxxxx
204 ...xxxxx
205 ....xxxx
206 ......xx
207 */
208 static unsigned short left_triangle_bits[] = {
209 0x03, 0x0f, 0x1f, 0x3f, 0x3f, 0x1f, 0x0f, 0x03};
210
211 /* Overlay arrow bitmap. A triangular arrow. */
212 /*
213 xx......
214 xxxx....
215 xxxxx...
216 xxxxxx..
217 xxxxxx..
218 xxxxx...
219 xxxx....
220 xx......
221 */
222 static unsigned short right_triangle_bits[] = {
223 0xc0, 0xf0, 0xf8, 0xfc, 0xfc, 0xf8, 0xf0, 0xc0};
224
225 /* First line bitmap. An top-left angle. */
226 /*
227 xxxxxx..
228 xxxxxx..
229 xx......
230 xx......
231 xx......
232 xx......
233 xx......
234 ........
235 */
236 static unsigned short top_left_angle_bits[] = {
237 0xfc, 0xfc, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00};
238
239 /* First line bitmap. An right-up angle. */
240 /*
241 ..xxxxxx
242 ..xxxxxx
243 ......xx
244 ......xx
245 ......xx
246 ......xx
247 ......xx
248 ........
249 */
250 static unsigned short top_right_angle_bits[] = {
251 0x3f, 0x3f, 0x03, 0x03, 0x03, 0x03, 0x03, 0x00};
252
253 /* Last line bitmap. An left-down angle. */
254 /*
255 ........
256 xx......
257 xx......
258 xx......
259 xx......
260 xx......
261 xxxxxx..
262 xxxxxx..
263 */
264 static unsigned short bottom_left_angle_bits[] = {
265 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xfc, 0xfc};
266
267 /* Last line bitmap. An right-down angle. */
268 /*
269 ........
270 ......xx
271 ......xx
272 ......xx
273 ......xx
274 ......xx
275 ..xxxxxx
276 ..xxxxxx
277 */
278 static unsigned short bottom_right_angle_bits[] = {
279 0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x3f, 0x3f};
280
281 /* First/last line bitmap. An left bracket. */
282 /*
283 xxxxxx..
284 xxxxxx..
285 xx......
286 xx......
287 xx......
288 xx......
289 xx......
290 xx......
291 xxxxxx..
292 xxxxxx..
293 */
294 static unsigned short left_bracket_bits[] = {
295 0xfc, 0xfc, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xfc, 0xfc};
296
297 /* First/last line bitmap. An right bracket. */
298 /*
299 ..xxxxxx
300 ..xxxxxx
301 ......xx
302 ......xx
303 ......xx
304 ......xx
305 ......xx
306 ......xx
307 ..xxxxxx
308 ..xxxxxx
309 */
310 static unsigned short right_bracket_bits[] = {
311 0x3f, 0x3f, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x3f, 0x3f};
312
313 /* Filled box cursor bitmap. A filled box; max 13 pixels high. */
314 /*
315 xxxxxxx.
316 xxxxxxx.
317 xxxxxxx.
318 xxxxxxx.
319 xxxxxxx.
320 xxxxxxx.
321 xxxxxxx.
322 xxxxxxx.
323 xxxxxxx.
324 xxxxxxx.
325 xxxxxxx.
326 xxxxxxx.
327 xxxxxxx.
328 */
329 static unsigned short filled_rectangle_bits[] = {
330 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe};
331
332 /* Hollow box cursor bitmap. A hollow box; max 13 pixels high. */
333 /*
334 xxxxxxx.
335 x.....x.
336 x.....x.
337 x.....x.
338 x.....x.
339 x.....x.
340 x.....x.
341 x.....x.
342 x.....x.
343 x.....x.
344 x.....x.
345 x.....x.
346 xxxxxxx.
347 */
348 static unsigned short hollow_rectangle_bits[] = {
349 0xfe, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0xfe};
350
351 /* Hollow square bitmap. */
352 /*
353 .xxxxxx.
354 .x....x.
355 .x....x.
356 .x....x.
357 .x....x.
358 .xxxxxx.
359 */
360 static unsigned short hollow_square_bits[] = {
361 0x7e, 0x42, 0x42, 0x42, 0x42, 0x7e};
362
363 /* Filled square bitmap. */
364 /*
365 .xxxxxx.
366 .xxxxxx.
367 .xxxxxx.
368 .xxxxxx.
369 .xxxxxx.
370 .xxxxxx.
371 */
372 static unsigned short filled_square_bits[] = {
373 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e};
374
375 /* Bar cursor bitmap. A vertical bar; max 13 pixels high. */
376 /*
377 xx......
378 xx......
379 xx......
380 xx......
381 xx......
382 xx......
383 xx......
384 xx......
385 xx......
386 xx......
387 xx......
388 xx......
389 xx......
390 */
391 static unsigned short vertical_bar_bits[] = {
392 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0};
393
394 /* HBar cursor bitmap. A horizontal bar; 2 pixels high. */
395 /*
396 xxxxxxx.
397 xxxxxxx.
398 */
399 static unsigned short horizontal_bar_bits[] = {
400 0xfe, 0xfe};
401
402
403 /* Bitmap drawn to indicate lines not displaying text if
404 `indicate-empty-lines' is non-nil. */
405 /*
406 ........
407 ..xxxx..
408 ........
409 ........
410 ..xxxx..
411 ........
412 */
413 static unsigned short empty_line_bits[] = {
414 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
415 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
416 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
417 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
418 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
419 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
420 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
421 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00};
422
423
424 #define BYTES_PER_BITMAP_ROW (sizeof (unsigned short))
425 #define STANDARD_BITMAP_HEIGHT(bits) (sizeof (bits)/BYTES_PER_BITMAP_ROW)
426 #define FRBITS(bits) bits, STANDARD_BITMAP_HEIGHT (bits)
427
428 /* NOTE: The order of these bitmaps must match the sequence
429 used in fringe.el to define the corresponding symbols. */
430
431 static struct fringe_bitmap standard_bitmaps[] =
432 {
433 { NULL, 0, 0, 0, 0, 0 }, /* NO_FRINGE_BITMAP */
434 { FRBITS (question_mark_bits), 8, 0, ALIGN_BITMAP_CENTER, 0 },
435 { FRBITS (left_arrow_bits), 8, 0, ALIGN_BITMAP_CENTER, 0 },
436 { FRBITS (right_arrow_bits), 8, 0, ALIGN_BITMAP_CENTER, 0 },
437 { FRBITS (up_arrow_bits), 8, 0, ALIGN_BITMAP_TOP, 0 },
438 { FRBITS (down_arrow_bits), 8, 0, ALIGN_BITMAP_BOTTOM, 0 },
439 { FRBITS (left_curly_arrow_bits), 8, 0, ALIGN_BITMAP_CENTER, 0 },
440 { FRBITS (right_curly_arrow_bits), 8, 0, ALIGN_BITMAP_CENTER, 0 },
441 { FRBITS (left_triangle_bits), 8, 0, ALIGN_BITMAP_CENTER, 0 },
442 { FRBITS (right_triangle_bits), 8, 0, ALIGN_BITMAP_CENTER, 0 },
443 { FRBITS (top_left_angle_bits), 8, 0, ALIGN_BITMAP_TOP, 0 },
444 { FRBITS (top_right_angle_bits), 8, 0, ALIGN_BITMAP_TOP, 0 },
445 { FRBITS (bottom_left_angle_bits), 8, 0, ALIGN_BITMAP_BOTTOM, 0 },
446 { FRBITS (bottom_right_angle_bits), 8, 0, ALIGN_BITMAP_BOTTOM, 0 },
447 { FRBITS (left_bracket_bits), 8, 0, ALIGN_BITMAP_CENTER, 0 },
448 { FRBITS (right_bracket_bits), 8, 0, ALIGN_BITMAP_CENTER, 0 },
449 { FRBITS (filled_rectangle_bits), 8, 0, ALIGN_BITMAP_CENTER, 0 },
450 { FRBITS (hollow_rectangle_bits), 8, 0, ALIGN_BITMAP_CENTER, 0 },
451 { FRBITS (filled_square_bits), 8, 0, ALIGN_BITMAP_CENTER, 0 },
452 { FRBITS (hollow_square_bits), 8, 0, ALIGN_BITMAP_CENTER, 0 },
453 { FRBITS (vertical_bar_bits), 8, 0, ALIGN_BITMAP_CENTER, 0 },
454 { FRBITS (horizontal_bar_bits), 8, 0, ALIGN_BITMAP_BOTTOM, 0 },
455 { FRBITS (empty_line_bits), 8, 3, ALIGN_BITMAP_TOP, 0 },
456 };
457
458 #define NO_FRINGE_BITMAP 0
459 #define UNDEF_FRINGE_BITMAP 1
460 #define MAX_STANDARD_FRINGE_BITMAPS (sizeof (standard_bitmaps)/sizeof (standard_bitmaps[0]))
461
462 static struct fringe_bitmap **fringe_bitmaps;
463 static Lisp_Object *fringe_faces;
464 static int max_fringe_bitmaps;
465
466 #ifndef HAVE_NS
467 static
468 #endif
469 int max_used_fringe_bitmap = MAX_STANDARD_FRINGE_BITMAPS;
470
471
472 /* Lookup bitmap number for symbol BITMAP.
473 Return 0 if not a bitmap. */
474
475 int
476 lookup_fringe_bitmap (Lisp_Object bitmap)
477 {
478 EMACS_INT bn;
479
480 bitmap = Fget (bitmap, Qfringe);
481 if (!INTEGERP (bitmap))
482 return 0;
483
484 bn = XINT (bitmap);
485 if (bn > NO_FRINGE_BITMAP
486 && bn < max_used_fringe_bitmap
487 && (bn < MAX_STANDARD_FRINGE_BITMAPS
488 || fringe_bitmaps[bn] != NULL))
489 return bn;
490
491 return 0;
492 }
493
494 /* Get fringe bitmap name for bitmap number BN.
495
496 Found by traversing Vfringe_bitmaps comparing BN to the
497 fringe property for each symbol.
498
499 Return BN if not found in Vfringe_bitmaps. */
500
501 static Lisp_Object
502 get_fringe_bitmap_name (int bn)
503 {
504 Lisp_Object bitmaps;
505 Lisp_Object num;
506
507 /* Zero means no bitmap -- return nil. */
508 if (bn <= 0)
509 return Qnil;
510
511 bitmaps = Vfringe_bitmaps;
512 num = make_number (bn);
513
514 while (CONSP (bitmaps))
515 {
516 Lisp_Object bitmap = XCAR (bitmaps);
517 if (EQ (num, Fget (bitmap, Qfringe)))
518 return bitmap;
519 bitmaps = XCDR (bitmaps);
520 }
521
522 return num;
523 }
524
525 /* Get fringe bitmap data for bitmap number BN. */
526
527 static struct fringe_bitmap *
528 get_fringe_bitmap_data (int bn)
529 {
530 struct fringe_bitmap *fb;
531
532 fb = fringe_bitmaps[bn];
533 if (fb == NULL)
534 fb = &standard_bitmaps[bn < MAX_STANDARD_FRINGE_BITMAPS
535 ? bn : UNDEF_FRINGE_BITMAP];
536
537 return fb;
538 }
539
540 /* Draw the bitmap WHICH in one of the left or right fringes of
541 window W. ROW is the glyph row for which to display the bitmap; it
542 determines the vertical position at which the bitmap has to be
543 drawn.
544 LEFT_P is 1 for left fringe, 0 for right fringe.
545 */
546
547 static void
548 draw_fringe_bitmap_1 (struct window *w, struct glyph_row *row, int left_p, int overlay, int which)
549 {
550 struct frame *f = XFRAME (WINDOW_FRAME (w));
551 struct draw_fringe_bitmap_params p;
552 struct fringe_bitmap *fb;
553 int period;
554 int face_id = DEFAULT_FACE_ID;
555 int offset, header_line_height;
556
557 p.overlay_p = (overlay & 1) == 1;
558 p.cursor_p = (overlay & 2) == 2;
559
560 if (which != NO_FRINGE_BITMAP)
561 {
562 offset = 0;
563 }
564 else if (left_p)
565 {
566 which = row->left_fringe_bitmap;
567 face_id = row->left_fringe_face_id;
568 offset = row->left_fringe_offset;
569 }
570 else
571 {
572 which = row->right_fringe_bitmap;
573 face_id = row->right_fringe_face_id;
574 offset = row->right_fringe_offset;
575 }
576
577 if (face_id == DEFAULT_FACE_ID)
578 {
579 Lisp_Object face = fringe_faces[which];
580 face_id = NILP (face) ? lookup_named_face (f, Qfringe, 0)
581 : lookup_derived_face (f, face, FRINGE_FACE_ID, 0);
582 if (face_id < 0)
583 face_id = FRINGE_FACE_ID;
584 }
585
586 fb = get_fringe_bitmap_data (which);
587
588 period = fb->period;
589
590 /* Convert row to frame coordinates. */
591 p.y = WINDOW_TO_FRAME_PIXEL_Y (w, row->y) + offset;
592
593 p.which = which;
594 p.bits = fb->bits;
595 p.wd = fb->width;
596
597 p.h = fb->height;
598 p.dh = (period > 0 ? (p.y % period) : 0);
599 p.h -= p.dh;
600
601 /* Adjust y to the offset in the row to start drawing the bitmap. */
602 switch (fb->align)
603 {
604 case ALIGN_BITMAP_CENTER:
605 p.y += (row->height - p.h) / 2;
606 break;
607 case ALIGN_BITMAP_BOTTOM:
608 p.y += (row->visible_height - p.h);
609 break;
610 case ALIGN_BITMAP_TOP:
611 break;
612 }
613
614 p.face = FACE_FROM_ID (f, face_id);
615
616 if (p.face == NULL)
617 {
618 /* This could happen after clearing face cache.
619 But it shouldn't happen anymore. ++kfs */
620 return;
621 }
622
623 PREPARE_FACE_FOR_DISPLAY (f, p.face);
624
625 /* Clear left fringe if no bitmap to draw or if bitmap doesn't fill
626 the fringe. */
627 p.bx = -1;
628 header_line_height = WINDOW_HEADER_LINE_HEIGHT (w);
629 p.by = WINDOW_TO_FRAME_PIXEL_Y (w, max (header_line_height, row->y));
630 p.ny = row->visible_height;
631 if (left_p)
632 {
633 int wd = WINDOW_LEFT_FRINGE_WIDTH (w);
634 int x = window_box_left (w, (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w)
635 ? LEFT_MARGIN_AREA
636 : TEXT_AREA));
637 if (p.wd > wd)
638 p.wd = wd;
639 p.x = x - p.wd - (wd - p.wd) / 2;
640
641 if (p.wd < wd || p.y > p.by || p.y + p.h < p.by + p.ny)
642 {
643 /* If W has a vertical border to its left, don't draw over it. */
644 wd -= ((!WINDOW_LEFTMOST_P (w)
645 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w))
646 ? 1 : 0);
647 p.bx = x - wd;
648 p.nx = wd;
649 }
650 }
651 else
652 {
653 int x = window_box_right (w,
654 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w)
655 ? RIGHT_MARGIN_AREA
656 : TEXT_AREA));
657 int wd = WINDOW_RIGHT_FRINGE_WIDTH (w);
658 if (p.wd > wd)
659 p.wd = wd;
660 p.x = x + (wd - p.wd) / 2;
661 /* Clear right fringe if no bitmap to draw of if bitmap doesn't fill
662 the fringe. */
663 if (p.wd < wd || p.y > p.by || p.y + p.h < p.by + p.ny)
664 {
665 p.bx = x;
666 p.nx = wd;
667 }
668 }
669
670 FRAME_RIF (f)->draw_fringe_bitmap (w, row, &p);
671 }
672
673 static int
674 get_logical_cursor_bitmap (struct window *w, Lisp_Object cursor)
675 {
676 Lisp_Object cmap, bm = Qnil;
677
678 if ((cmap = BVAR (XBUFFER (w->buffer), fringe_cursor_alist)), !NILP (cmap))
679 {
680 bm = Fassq (cursor, cmap);
681 if (CONSP (bm))
682 {
683 if ((bm = XCDR (bm)), NILP (bm))
684 return NO_FRINGE_BITMAP;
685 return lookup_fringe_bitmap (bm);
686 }
687 }
688 if (EQ (cmap, BVAR (&buffer_defaults, fringe_cursor_alist)))
689 return NO_FRINGE_BITMAP;
690 bm = Fassq (cursor, BVAR (&buffer_defaults, fringe_cursor_alist));
691 if (!CONSP (bm) || ((bm = XCDR (bm)), NILP (bm)))
692 return NO_FRINGE_BITMAP;
693 return lookup_fringe_bitmap (bm);
694 }
695
696 static int
697 get_logical_fringe_bitmap (struct window *w, Lisp_Object bitmap, int right_p, int partial_p)
698 {
699 Lisp_Object cmap, bm1 = Qnil, bm2 = Qnil, bm;
700 EMACS_INT ln1 = 0, ln2 = 0;
701 int ix1 = right_p;
702 int ix2 = ix1 + (partial_p ? 2 : 0);
703
704 /* Lookup in buffer-local fringe-indicator-alist before global alist.
705
706 Elements are:
707 BITMAP -- use for all
708 (L R) -- use for left right (whether partial or not)
709 (L R PL PR) -- use for left right partial-left partial-right
710 If any value in local binding is not present or t, use global value.
711
712 If partial, lookup partial bitmap in default value if not found here.
713 If not partial, or no partial spec is present, use non-partial bitmap. */
714
715 if ((cmap = BVAR (XBUFFER (w->buffer), fringe_indicator_alist)), !NILP (cmap))
716 {
717 bm1 = Fassq (bitmap, cmap);
718 if (CONSP (bm1))
719 {
720 if ((bm1 = XCDR (bm1)), NILP (bm1))
721 return NO_FRINGE_BITMAP;
722 if (CONSP (bm1))
723 {
724 ln1 = XINT (Flength (bm1));
725 if (partial_p)
726 {
727 if (ln1 > ix2)
728 {
729 bm = Fnth (make_number (ix2), bm1);
730 if (!EQ (bm, Qt))
731 goto found;
732 }
733 }
734 else
735 {
736 if (ln1 > ix1)
737 {
738 bm = Fnth (make_number (ix1), bm1);
739 if (!EQ (bm, Qt))
740 goto found;
741 }
742 }
743 }
744 else if ((bm = bm1, !EQ (bm, Qt)))
745 goto found;
746 }
747 }
748
749 if (!EQ (cmap, BVAR (&buffer_defaults, fringe_indicator_alist))
750 && !NILP (BVAR (&buffer_defaults, fringe_indicator_alist)))
751 {
752 bm2 = Fassq (bitmap, BVAR (&buffer_defaults, fringe_indicator_alist));
753 if (CONSP (bm2))
754 {
755 if ((bm2 = XCDR (bm2)), !NILP (bm2))
756 {
757 if (CONSP (bm2))
758 {
759 ln2 = XINT (Flength (bm2));
760 if (partial_p)
761 {
762 if (ln2 > ix2)
763 {
764 bm = Fnth (make_number (ix2), bm2);
765 if (!EQ (bm, Qt))
766 goto found;
767 }
768 }
769 }
770 }
771 }
772 }
773
774 if (ln1 > ix1)
775 {
776 bm = Fnth (make_number (ix1), bm1);
777 if (!EQ (bm, Qt))
778 goto found;
779 }
780
781 if (ln2 > ix1)
782 {
783 bm = Fnth (make_number (ix1), bm2);
784 if (!EQ (bm, Qt))
785 goto found;
786 return NO_FRINGE_BITMAP;
787 }
788 else if ((bm = bm2, NILP (bm)))
789 return NO_FRINGE_BITMAP;
790
791 found:
792 return lookup_fringe_bitmap (bm);
793 }
794
795
796 void
797 draw_fringe_bitmap (struct window *w, struct glyph_row *row, int left_p)
798 {
799 int overlay = 0;
800
801 if (left_p == row->reversed_p && row->cursor_in_fringe_p)
802 {
803 Lisp_Object cursor = Qnil;
804
805 switch (w->phys_cursor_type)
806 {
807 case HOLLOW_BOX_CURSOR:
808 if (row->visible_height >= STANDARD_BITMAP_HEIGHT (hollow_rectangle_bits))
809 cursor = Qhollow;
810 else
811 cursor = Qhollow_small;
812 break;
813 case FILLED_BOX_CURSOR:
814 cursor = Qbox;
815 break;
816 case BAR_CURSOR:
817 cursor = Qbar;
818 break;
819 case HBAR_CURSOR:
820 cursor = Qhbar;
821 break;
822 case NO_CURSOR:
823 default:
824 w->phys_cursor_on_p = 0;
825 row->cursor_in_fringe_p = 0;
826 break;
827 }
828 if (!NILP (cursor))
829 {
830 int bm = get_logical_cursor_bitmap (w, cursor);
831 if (bm != NO_FRINGE_BITMAP)
832 {
833 draw_fringe_bitmap_1 (w, row, left_p, 2, bm);
834 overlay = EQ (cursor, Qbox) ? 3 : 1;
835 }
836 }
837 }
838
839 draw_fringe_bitmap_1 (w, row, left_p, overlay, NO_FRINGE_BITMAP);
840
841 if (left_p && row->overlay_arrow_bitmap != NO_FRINGE_BITMAP)
842 draw_fringe_bitmap_1 (w, row, 1, 1, row->overlay_arrow_bitmap);
843 }
844
845
846 /* Draw fringe bitmaps for glyph row ROW on window W. Call this
847 function with input blocked. */
848
849 void
850 draw_row_fringe_bitmaps (struct window *w, struct glyph_row *row)
851 {
852 eassert (interrupt_input_blocked);
853
854 /* If row is completely invisible, because of vscrolling, we
855 don't have to draw anything. */
856 if (row->visible_height <= 0)
857 return;
858
859 if (WINDOW_LEFT_FRINGE_WIDTH (w) != 0)
860 draw_fringe_bitmap (w, row, 1);
861
862 if (WINDOW_RIGHT_FRINGE_WIDTH (w) != 0)
863 draw_fringe_bitmap (w, row, 0);
864 }
865
866 /* Draw the fringes of window W. Only fringes for rows marked for
867 update in redraw_fringe_bitmaps_p are drawn.
868
869 Return >0 if left or right fringe was redrawn in any way.
870
871 If NO_FRINGE is non-zero, also return >0 if either fringe has zero width.
872
873 A return value >0 indicates that the vertical line between windows
874 needs update (as it may be drawn in the fringe).
875 */
876
877 int
878 draw_window_fringes (struct window *w, int no_fringe)
879 {
880 struct glyph_row *row;
881 int yb = window_text_bottom_y (w);
882 int nrows = w->current_matrix->nrows;
883 int y, rn;
884 int updated = 0;
885
886 if (w->pseudo_window_p)
887 return 0;
888
889 /* Must draw line if no fringe */
890 if (no_fringe
891 && (WINDOW_LEFT_FRINGE_WIDTH (w) == 0
892 || WINDOW_RIGHT_FRINGE_WIDTH (w) == 0))
893 updated++;
894
895 for (y = w->vscroll, rn = 0, row = w->current_matrix->rows;
896 y < yb && rn < nrows;
897 y += row->height, ++row, ++rn)
898 {
899 if (!row->redraw_fringe_bitmaps_p)
900 continue;
901 draw_row_fringe_bitmaps (w, row);
902 row->redraw_fringe_bitmaps_p = 0;
903 updated++;
904 }
905
906 return updated;
907 }
908
909
910 /* Recalculate the bitmaps to show in the fringes of window W.
911 Only mark rows with modified bitmaps for update in redraw_fringe_bitmaps_p.
912
913 If KEEP_CURRENT_P is 0, update current_matrix too. */
914
915 int
916 update_window_fringes (struct window *w, int keep_current_p)
917 {
918 struct glyph_row *row, *cur = 0;
919 int yb = window_text_bottom_y (w);
920 int rn, nrows = w->current_matrix->nrows;
921 int y;
922 int redraw_p = 0;
923 Lisp_Object boundary_top = Qnil, boundary_bot = Qnil;
924 Lisp_Object arrow_top = Qnil, arrow_bot = Qnil;
925 Lisp_Object empty_pos;
926 Lisp_Object ind = Qnil;
927 #define MAX_BITMAP_CACHE (8*4)
928 int bitmap_cache[MAX_BITMAP_CACHE];
929 int top_ind_rn, bot_ind_rn;
930 int top_ind_min_y, bot_ind_max_y;
931
932 /* top_ind_rn is set to a nonnegative value whenever
933 row->indicate_bob_p is set, so it's OK that top_row_ends_at_zv_p
934 is not initialized here. Similarly for bot_ind_rn,
935 row->indicate_eob_p and bot_row_ends_at_zv_p. */
936 int top_row_ends_at_zv_p IF_LINT (= 0), bot_row_ends_at_zv_p IF_LINT (= 0);
937
938 if (w->pseudo_window_p)
939 return 0;
940
941 if (!MINI_WINDOW_P (w)
942 && (ind = BVAR (XBUFFER (w->buffer), indicate_buffer_boundaries), !NILP (ind)))
943 {
944 if (EQ (ind, Qleft) || EQ (ind, Qright))
945 boundary_top = boundary_bot = arrow_top = arrow_bot = ind;
946 else if (CONSP (ind) && CONSP (XCAR (ind)))
947 {
948 Lisp_Object pos;
949 if (pos = Fassq (Qt, ind), !NILP (pos))
950 boundary_top = boundary_bot = arrow_top = arrow_bot = XCDR (pos);
951 if (pos = Fassq (Qtop, ind), !NILP (pos))
952 boundary_top = XCDR (pos);
953 if (pos = Fassq (Qbottom, ind), !NILP (pos))
954 boundary_bot = XCDR (pos);
955 if (pos = Fassq (Qup, ind), !NILP (pos))
956 arrow_top = XCDR (pos);
957 if (pos = Fassq (Qdown, ind), !NILP (pos))
958 arrow_bot = XCDR (pos);
959 }
960 else
961 /* Anything else means boundary on left and no arrows. */
962 boundary_top = boundary_bot = Qleft;
963 }
964
965 top_ind_rn = bot_ind_rn = -1;
966 if (!NILP (ind))
967 {
968 for (y = w->vscroll, rn = 0;
969 y < yb && rn < nrows;
970 y += row->height, ++rn)
971 {
972 row = w->desired_matrix->rows + rn;
973 if (!row->enabled_p)
974 row = w->current_matrix->rows + rn;
975
976 row->indicate_bob_p = row->indicate_top_line_p = 0;
977 row->indicate_eob_p = row->indicate_bottom_line_p = 0;
978
979 if (!row->mode_line_p)
980 {
981 if (top_ind_rn < 0 && row->visible_height > 0)
982 {
983 if (MATRIX_ROW_START_CHARPOS (row) <= BUF_BEGV (XBUFFER (w->buffer))
984 && !MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w, row))
985 row->indicate_bob_p = !NILP (boundary_top);
986 else
987 row->indicate_top_line_p = !NILP (arrow_top);
988 top_ind_rn = rn;
989 }
990
991 if (bot_ind_rn < 0)
992 {
993 if (MATRIX_ROW_END_CHARPOS (row) >= BUF_ZV (XBUFFER (w->buffer))
994 && !MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row))
995 row->indicate_eob_p = !NILP (boundary_bot), bot_ind_rn = rn;
996 else if (y + row->height >= yb)
997 row->indicate_bottom_line_p = !NILP (arrow_bot), bot_ind_rn = rn;
998 }
999 }
1000 }
1001 }
1002
1003 empty_pos = BVAR (XBUFFER (w->buffer), indicate_empty_lines);
1004 if (!NILP (empty_pos) && !EQ (empty_pos, Qright))
1005 empty_pos = WINDOW_LEFT_FRINGE_WIDTH (w) == 0 ? Qright : Qleft;
1006
1007 for (y = 0; y < MAX_BITMAP_CACHE; y++)
1008 bitmap_cache[y] = -1;
1009
1010 #define LEFT_FRINGE(cache, which, partial_p) \
1011 (bitmap_cache[cache*4+partial_p] >= 0 \
1012 ? bitmap_cache[cache*4+partial_p] \
1013 : (bitmap_cache[cache*4+partial_p] = \
1014 get_logical_fringe_bitmap (w, which, 0, partial_p)))
1015
1016 #define RIGHT_FRINGE(cache, which, partial_p) \
1017 (bitmap_cache[cache*4+2+partial_p] >= 0 \
1018 ? bitmap_cache[cache*4+2+partial_p] \
1019 : (bitmap_cache[cache*4+2+partial_p] = \
1020 get_logical_fringe_bitmap (w, which, 1, partial_p)))
1021
1022
1023 /* Extend top-aligned top indicator (or bottom-aligned bottom
1024 indicator) to adjacent rows if it doesn't fit in one row. */
1025 top_ind_min_y = bot_ind_max_y = -1;
1026 if (top_ind_rn >= 0)
1027 {
1028 int bn = NO_FRINGE_BITMAP;
1029
1030 row = w->desired_matrix->rows + top_ind_rn;
1031 if (!row->enabled_p)
1032 row = w->current_matrix->rows + top_ind_rn;
1033
1034 top_row_ends_at_zv_p = row->ends_at_zv_p;
1035 if (row->indicate_bob_p)
1036 {
1037 if (EQ (boundary_top, Qleft))
1038 bn = ((row->indicate_eob_p && EQ (boundary_bot, Qleft))
1039 ? LEFT_FRINGE (1, Qtop_bottom, row->ends_at_zv_p)
1040 : LEFT_FRINGE (2, Qtop, 0));
1041 else
1042 bn = ((row->indicate_eob_p && EQ (boundary_bot, Qright))
1043 ? RIGHT_FRINGE (1, Qtop_bottom, row->ends_at_zv_p)
1044 : RIGHT_FRINGE (2, Qtop, 0));
1045 }
1046 else if (row->indicate_top_line_p)
1047 {
1048 if (EQ (arrow_top, Qleft))
1049 bn = LEFT_FRINGE (6, Qup, 0);
1050 else
1051 bn = RIGHT_FRINGE (6, Qup, 0);
1052 }
1053
1054 if (bn != NO_FRINGE_BITMAP)
1055 {
1056 struct fringe_bitmap *fb = get_fringe_bitmap_data (bn);
1057
1058 if (fb->align == ALIGN_BITMAP_TOP && fb->period == 0)
1059 {
1060 struct glyph_row *row1;
1061 int top_ind_max_y;
1062
1063 top_ind_min_y = WINDOW_HEADER_LINE_HEIGHT (w);
1064 top_ind_max_y = top_ind_min_y + fb->height;
1065 if (top_ind_max_y > yb)
1066 top_ind_max_y = yb;
1067
1068 for (y = row->y + row->height, rn = top_ind_rn + 1;
1069 y < top_ind_max_y && rn < nrows;
1070 y += row1->height, rn++)
1071 {
1072 if (bot_ind_rn >= 0 && rn >= bot_ind_rn)
1073 break;
1074
1075 row1 = w->desired_matrix->rows + rn;
1076 if (!row1->enabled_p)
1077 row1 = w->current_matrix->rows + rn;
1078
1079 row1->indicate_bob_p = row->indicate_bob_p;
1080 row1->indicate_top_line_p = row->indicate_top_line_p;
1081 }
1082 }
1083 }
1084 }
1085 if (bot_ind_rn >= 0)
1086 {
1087 int bn = NO_FRINGE_BITMAP;
1088
1089 row = w->desired_matrix->rows + bot_ind_rn;
1090 if (!row->enabled_p)
1091 row = w->current_matrix->rows + bot_ind_rn;
1092
1093 bot_row_ends_at_zv_p = row->ends_at_zv_p;
1094 if (row->indicate_eob_p)
1095 {
1096 if (EQ (boundary_bot, Qleft))
1097 bn = LEFT_FRINGE (3, Qbottom, row->ends_at_zv_p);
1098 else
1099 bn = RIGHT_FRINGE (3, Qbottom, row->ends_at_zv_p);
1100 }
1101 else if (row->indicate_bottom_line_p)
1102 {
1103 if (EQ (arrow_bot, Qleft))
1104 bn = LEFT_FRINGE (7, Qdown, 0);
1105 else
1106 bn = RIGHT_FRINGE (7, Qdown, 0);
1107 }
1108
1109 if (bn != NO_FRINGE_BITMAP)
1110 {
1111 struct fringe_bitmap *fb = get_fringe_bitmap_data (bn);
1112
1113 if (fb->align == ALIGN_BITMAP_BOTTOM && fb->period == 0)
1114 {
1115 struct glyph_row *row1;
1116 int bot_ind_min_y;
1117
1118 bot_ind_max_y = row->y + row->visible_height;
1119 bot_ind_min_y = bot_ind_max_y - fb->height;
1120 if (bot_ind_min_y < WINDOW_HEADER_LINE_HEIGHT (w))
1121 bot_ind_min_y = WINDOW_HEADER_LINE_HEIGHT (w);
1122
1123 for (y = row->y, rn = bot_ind_rn - 1;
1124 y >= bot_ind_min_y && rn >= 0;
1125 y -= row1->height, rn--)
1126 {
1127 if (top_ind_rn >= 0 && rn <= top_ind_rn)
1128 break;
1129
1130 row1 = w->desired_matrix->rows + rn;
1131 if (!row1->enabled_p)
1132 row1 = w->current_matrix->rows + rn;
1133
1134 row1->indicate_eob_p = row->indicate_eob_p;
1135 row1->indicate_bottom_line_p = row->indicate_bottom_line_p;
1136 }
1137 }
1138 }
1139 }
1140
1141 for (y = w->vscroll, rn = 0;
1142 y < yb && rn < nrows;
1143 y += row->height, rn++)
1144 {
1145 int left, right;
1146 unsigned left_face_id, right_face_id;
1147 int left_offset, right_offset;
1148 int periodic_p;
1149
1150 row = w->desired_matrix->rows + rn;
1151 cur = w->current_matrix->rows + rn;
1152 if (!row->enabled_p)
1153 row = cur;
1154
1155 left_face_id = right_face_id = DEFAULT_FACE_ID;
1156 left_offset = right_offset = 0;
1157 periodic_p = 0;
1158
1159 /* Decide which bitmap to draw in the left fringe. */
1160 if (WINDOW_LEFT_FRINGE_WIDTH (w) == 0)
1161 left = NO_FRINGE_BITMAP;
1162 else if (row->left_user_fringe_bitmap != NO_FRINGE_BITMAP)
1163 {
1164 left = row->left_user_fringe_bitmap;
1165 left_face_id = row->left_user_fringe_face_id;
1166 }
1167 else if ((!row->reversed_p && row->truncated_on_left_p)
1168 || (row->reversed_p && row->truncated_on_right_p))
1169 left = LEFT_FRINGE (0, Qtruncation, 0);
1170 else if (row->indicate_bob_p && EQ (boundary_top, Qleft))
1171 {
1172 left = ((row->indicate_eob_p && EQ (boundary_bot, Qleft))
1173 ? LEFT_FRINGE (1, Qtop_bottom, top_row_ends_at_zv_p)
1174 : LEFT_FRINGE (2, Qtop, 0));
1175 if (top_ind_min_y >= 0)
1176 left_offset = top_ind_min_y - row->y;
1177 }
1178 else if (row->indicate_eob_p && EQ (boundary_bot, Qleft))
1179 {
1180 left = LEFT_FRINGE (3, Qbottom, bot_row_ends_at_zv_p);
1181 if (bot_ind_max_y >= 0)
1182 left_offset = bot_ind_max_y - (row->y + row->visible_height);
1183 }
1184 else if ((!row->reversed_p && MATRIX_ROW_CONTINUATION_LINE_P (row))
1185 || (row->reversed_p && row->continued_p))
1186 left = LEFT_FRINGE (4, Qcontinuation, 0);
1187 else if (row->indicate_empty_line_p && EQ (empty_pos, Qleft))
1188 left = LEFT_FRINGE (5, Qempty_line, 0);
1189 else if (row->indicate_top_line_p && EQ (arrow_top, Qleft))
1190 {
1191 left = LEFT_FRINGE (6, Qup, 0);
1192 if (top_ind_min_y >= 0)
1193 left_offset = top_ind_min_y - row->y;
1194 }
1195 else if (row->indicate_bottom_line_p && EQ (arrow_bot, Qleft))
1196 {
1197 left = LEFT_FRINGE (7, Qdown, 0);
1198 if (bot_ind_max_y >= 0)
1199 left_offset = bot_ind_max_y - (row->y + row->visible_height);
1200 }
1201 else
1202 left = NO_FRINGE_BITMAP;
1203
1204 /* Decide which bitmap to draw in the right fringe. */
1205 if (WINDOW_RIGHT_FRINGE_WIDTH (w) == 0)
1206 right = NO_FRINGE_BITMAP;
1207 else if (row->right_user_fringe_bitmap != NO_FRINGE_BITMAP)
1208 {
1209 right = row->right_user_fringe_bitmap;
1210 right_face_id = row->right_user_fringe_face_id;
1211 }
1212 else if ((!row->reversed_p && row->truncated_on_right_p)
1213 || (row->reversed_p && row->truncated_on_left_p))
1214 right = RIGHT_FRINGE (0, Qtruncation, 0);
1215 else if (row->indicate_bob_p && EQ (boundary_top, Qright))
1216 {
1217 right = ((row->indicate_eob_p && EQ (boundary_bot, Qright))
1218 ? RIGHT_FRINGE (1, Qtop_bottom, top_row_ends_at_zv_p)
1219 : RIGHT_FRINGE (2, Qtop, 0));
1220 if (top_ind_min_y >= 0)
1221 right_offset = top_ind_min_y - row->y;
1222 }
1223 else if (row->indicate_eob_p && EQ (boundary_bot, Qright))
1224 {
1225 right = RIGHT_FRINGE (3, Qbottom, bot_row_ends_at_zv_p);
1226 if (bot_ind_max_y >= 0)
1227 right_offset = bot_ind_max_y - (row->y + row->visible_height);
1228 }
1229 else if ((!row->reversed_p && row->continued_p)
1230 || (row->reversed_p && MATRIX_ROW_CONTINUATION_LINE_P (row)))
1231 right = RIGHT_FRINGE (4, Qcontinuation, 0);
1232 else if (row->indicate_top_line_p && EQ (arrow_top, Qright))
1233 {
1234 right = RIGHT_FRINGE (6, Qup, 0);
1235 if (top_ind_min_y >= 0)
1236 right_offset = top_ind_min_y - row->y;
1237 }
1238 else if (row->indicate_bottom_line_p && EQ (arrow_bot, Qright))
1239 {
1240 right = RIGHT_FRINGE (7, Qdown, 0);
1241 if (bot_ind_max_y >= 0)
1242 right_offset = bot_ind_max_y - (row->y + row->visible_height);
1243 }
1244 else if (row->indicate_empty_line_p && EQ (empty_pos, Qright))
1245 right = RIGHT_FRINGE (5, Qempty_line, 0);
1246 else
1247 right = NO_FRINGE_BITMAP;
1248
1249 periodic_p = (get_fringe_bitmap_data (left)->period != 0
1250 || get_fringe_bitmap_data (right)->period != 0);
1251
1252 if (row->y != cur->y
1253 || row->visible_height != cur->visible_height
1254 || row->ends_at_zv_p != cur->ends_at_zv_p
1255 || left != cur->left_fringe_bitmap
1256 || right != cur->right_fringe_bitmap
1257 || left_face_id != cur->left_fringe_face_id
1258 || right_face_id != cur->right_fringe_face_id
1259 || left_offset != cur->left_fringe_offset
1260 || right_offset != cur->right_fringe_offset
1261 || periodic_p != cur->fringe_bitmap_periodic_p
1262 || cur->redraw_fringe_bitmaps_p)
1263 {
1264 redraw_p = row->redraw_fringe_bitmaps_p = 1;
1265 if (!keep_current_p)
1266 {
1267 cur->redraw_fringe_bitmaps_p = 1;
1268 cur->left_fringe_bitmap = left;
1269 cur->right_fringe_bitmap = right;
1270 cur->left_fringe_face_id = left_face_id;
1271 cur->right_fringe_face_id = right_face_id;
1272 cur->left_fringe_offset = left_offset;
1273 cur->right_fringe_offset = right_offset;
1274 cur->fringe_bitmap_periodic_p = periodic_p;
1275 }
1276 }
1277
1278 if (row->overlay_arrow_bitmap < 0)
1279 row->overlay_arrow_bitmap = get_logical_fringe_bitmap (w, Qoverlay_arrow, 0, 0);
1280
1281 if (row->overlay_arrow_bitmap != cur->overlay_arrow_bitmap)
1282 {
1283 redraw_p = row->redraw_fringe_bitmaps_p = 1;
1284 if (!keep_current_p)
1285 {
1286 cur->redraw_fringe_bitmaps_p = 1;
1287 cur->overlay_arrow_bitmap = row->overlay_arrow_bitmap;
1288 }
1289 }
1290
1291 row->left_fringe_bitmap = left;
1292 row->right_fringe_bitmap = right;
1293 row->left_fringe_face_id = left_face_id;
1294 row->right_fringe_face_id = right_face_id;
1295 row->left_fringe_offset = left_offset;
1296 row->right_fringe_offset = right_offset;
1297 row->fringe_bitmap_periodic_p = periodic_p;
1298 }
1299
1300 return redraw_p && !keep_current_p;
1301 }
1302
1303
1304 /* Compute actual fringe widths for frame F.
1305
1306 If REDRAW is 1, redraw F if the fringe settings was actually
1307 modified and F is visible.
1308
1309 Since the combined left and right fringe must occupy an integral
1310 number of columns, we may need to add some pixels to each fringe.
1311 Typically, we add an equal amount (+/- 1 pixel) to each fringe,
1312 but a negative width value is taken literally (after negating it).
1313
1314 We never make the fringes narrower than specified.
1315 */
1316
1317 void
1318 compute_fringe_widths (struct frame *f, int redraw)
1319 {
1320 int o_left = FRAME_LEFT_FRINGE_WIDTH (f);
1321 int o_right = FRAME_RIGHT_FRINGE_WIDTH (f);
1322 int o_cols = FRAME_FRINGE_COLS (f);
1323
1324 Lisp_Object left_fringe = Fassq (Qleft_fringe, f->param_alist);
1325 Lisp_Object right_fringe = Fassq (Qright_fringe, f->param_alist);
1326 int left_fringe_width, right_fringe_width;
1327
1328 if (!NILP (left_fringe))
1329 left_fringe = Fcdr (left_fringe);
1330 if (!NILP (right_fringe))
1331 right_fringe = Fcdr (right_fringe);
1332
1333 left_fringe_width = ((NILP (left_fringe) || !INTEGERP (left_fringe)) ? 8 :
1334 XINT (left_fringe));
1335 right_fringe_width = ((NILP (right_fringe) || !INTEGERP (right_fringe)) ? 8 :
1336 XINT (right_fringe));
1337
1338 if (left_fringe_width || right_fringe_width)
1339 {
1340 int left_wid = left_fringe_width >= 0 ? left_fringe_width : -left_fringe_width;
1341 int right_wid = right_fringe_width >= 0 ? right_fringe_width : -right_fringe_width;
1342 int conf_wid = left_wid + right_wid;
1343 int font_wid = FRAME_COLUMN_WIDTH (f);
1344 int cols = (left_wid + right_wid + font_wid-1) / font_wid;
1345 int real_wid = cols * font_wid;
1346 if (left_wid && right_wid)
1347 {
1348 if (left_fringe_width < 0)
1349 {
1350 /* Left fringe width is fixed, adjust right fringe if necessary */
1351 FRAME_LEFT_FRINGE_WIDTH (f) = left_wid;
1352 FRAME_RIGHT_FRINGE_WIDTH (f) = real_wid - left_wid;
1353 }
1354 else if (right_fringe_width < 0)
1355 {
1356 /* Right fringe width is fixed, adjust left fringe if necessary */
1357 FRAME_LEFT_FRINGE_WIDTH (f) = real_wid - right_wid;
1358 FRAME_RIGHT_FRINGE_WIDTH (f) = right_wid;
1359 }
1360 else
1361 {
1362 /* Adjust both fringes with an equal amount.
1363 Note that we are doing integer arithmetic here, so don't
1364 lose a pixel if the total width is an odd number. */
1365 int fill = real_wid - conf_wid;
1366 FRAME_LEFT_FRINGE_WIDTH (f) = left_wid + fill/2;
1367 FRAME_RIGHT_FRINGE_WIDTH (f) = right_wid + fill - fill/2;
1368 }
1369 }
1370 else if (left_fringe_width)
1371 {
1372 FRAME_LEFT_FRINGE_WIDTH (f) = real_wid;
1373 FRAME_RIGHT_FRINGE_WIDTH (f) = 0;
1374 }
1375 else
1376 {
1377 FRAME_LEFT_FRINGE_WIDTH (f) = 0;
1378 FRAME_RIGHT_FRINGE_WIDTH (f) = real_wid;
1379 }
1380 FRAME_FRINGE_COLS (f) = cols;
1381 }
1382 else
1383 {
1384 FRAME_LEFT_FRINGE_WIDTH (f) = 0;
1385 FRAME_RIGHT_FRINGE_WIDTH (f) = 0;
1386 FRAME_FRINGE_COLS (f) = 0;
1387 }
1388
1389 if (redraw && FRAME_VISIBLE_P (f))
1390 if (o_left != FRAME_LEFT_FRINGE_WIDTH (f) ||
1391 o_right != FRAME_RIGHT_FRINGE_WIDTH (f) ||
1392 o_cols != FRAME_FRINGE_COLS (f))
1393 redraw_frame (f);
1394 }
1395
1396
1397 /* Free resources used by a user-defined bitmap. */
1398
1399 static void
1400 destroy_fringe_bitmap (int n)
1401 {
1402 struct fringe_bitmap **fbp;
1403
1404 fringe_faces[n] = Qnil;
1405
1406 fbp = &fringe_bitmaps[n];
1407 if (*fbp && (*fbp)->dynamic)
1408 {
1409 /* XXX Is SELECTED_FRAME OK here? */
1410 struct redisplay_interface *rif = FRAME_RIF (SELECTED_FRAME ());
1411 if (rif && rif->destroy_fringe_bitmap)
1412 rif->destroy_fringe_bitmap (n);
1413 xfree (*fbp);
1414 *fbp = NULL;
1415 }
1416
1417 while (max_used_fringe_bitmap > MAX_STANDARD_FRINGE_BITMAPS
1418 && fringe_bitmaps[max_used_fringe_bitmap - 1] == NULL)
1419 max_used_fringe_bitmap--;
1420 }
1421
1422
1423 DEFUN ("destroy-fringe-bitmap", Fdestroy_fringe_bitmap, Sdestroy_fringe_bitmap,
1424 1, 1, 0,
1425 doc: /* Destroy fringe bitmap BITMAP.
1426 If BITMAP overrides a standard fringe bitmap, the original bitmap is restored. */)
1427 (Lisp_Object bitmap)
1428 {
1429 int n;
1430
1431 CHECK_SYMBOL (bitmap);
1432 n = lookup_fringe_bitmap (bitmap);
1433 if (!n)
1434 return Qnil;
1435
1436 destroy_fringe_bitmap (n);
1437
1438 if (n >= MAX_STANDARD_FRINGE_BITMAPS)
1439 {
1440 Vfringe_bitmaps = Fdelq (bitmap, Vfringe_bitmaps);
1441 /* It would be better to remove the fringe property. */
1442 Fput (bitmap, Qfringe, Qnil);
1443 }
1444
1445 return Qnil;
1446 }
1447
1448
1449 /* Initialize bitmap bit.
1450
1451 On X, we bit-swap the built-in bitmaps and reduce bitmap
1452 from short to char array if width is <= 8 bits.
1453
1454 On MAC with big-endian CPU, we need to byte-swap each short.
1455
1456 On W32 and MAC (little endian), there's no need to do this.
1457 */
1458
1459 #if defined (HAVE_X_WINDOWS)
1460 static const unsigned char swap_nibble[16] = {
1461 0x0, 0x8, 0x4, 0xc, /* 0000 1000 0100 1100 */
1462 0x2, 0xa, 0x6, 0xe, /* 0010 1010 0110 1110 */
1463 0x1, 0x9, 0x5, 0xd, /* 0001 1001 0101 1101 */
1464 0x3, 0xb, 0x7, 0xf}; /* 0011 1011 0111 1111 */
1465 #endif /* HAVE_X_WINDOWS */
1466
1467 static void
1468 init_fringe_bitmap (int which, struct fringe_bitmap *fb, int once_p)
1469 {
1470 if (once_p || fb->dynamic)
1471 {
1472 #if defined (HAVE_X_WINDOWS)
1473 unsigned short *bits = fb->bits;
1474 int j;
1475
1476 if (fb->width <= 8)
1477 {
1478 unsigned char *cbits = (unsigned char *)fb->bits;
1479 for (j = 0; j < fb->height; j++)
1480 {
1481 unsigned short b = *bits++;
1482 unsigned char c;
1483 c = (unsigned char)((swap_nibble[b & 0xf] << 4)
1484 | (swap_nibble[(b>>4) & 0xf]));
1485 *cbits++ = (c >> (8 - fb->width));
1486 }
1487 }
1488 else
1489 {
1490 for (j = 0; j < fb->height; j++)
1491 {
1492 unsigned short b = *bits;
1493 b = (unsigned short)((swap_nibble[b & 0xf] << 12)
1494 | (swap_nibble[(b>>4) & 0xf] << 8)
1495 | (swap_nibble[(b>>8) & 0xf] << 4)
1496 | (swap_nibble[(b>>12) & 0xf]));
1497 b >>= (16 - fb->width);
1498 #ifdef WORDS_BIGENDIAN
1499 b = ((b >> 8) | (b << 8));
1500 #endif
1501 *bits++ = b;
1502 }
1503 }
1504 #endif /* HAVE_X_WINDOWS */
1505
1506 }
1507
1508 if (!once_p)
1509 {
1510 /* XXX Is SELECTED_FRAME OK here? */
1511 struct redisplay_interface *rif = FRAME_RIF (SELECTED_FRAME ());
1512
1513 destroy_fringe_bitmap (which);
1514
1515 if (rif && rif->define_fringe_bitmap)
1516 rif->define_fringe_bitmap (which, fb->bits, fb->height, fb->width);
1517
1518 fringe_bitmaps[which] = fb;
1519 if (which >= max_used_fringe_bitmap)
1520 max_used_fringe_bitmap = which + 1;
1521 }
1522 }
1523
1524
1525 DEFUN ("define-fringe-bitmap", Fdefine_fringe_bitmap, Sdefine_fringe_bitmap,
1526 2, 5, 0,
1527 doc: /* Define fringe bitmap BITMAP from BITS of size HEIGHT x WIDTH.
1528 BITMAP is a symbol identifying the new fringe bitmap.
1529 BITS is either a string or a vector of integers.
1530 HEIGHT is height of bitmap. If HEIGHT is nil, use length of BITS.
1531 WIDTH must be an integer between 1 and 16, or nil which defaults to 8.
1532 Optional fifth arg ALIGN may be one of `top', `center', or `bottom',
1533 indicating the positioning of the bitmap relative to the rows where it
1534 is used; the default is to center the bitmap. Fifth arg may also be a
1535 list (ALIGN PERIODIC) where PERIODIC non-nil specifies that the bitmap
1536 should be repeated.
1537 If BITMAP already exists, the existing definition is replaced. */)
1538 (Lisp_Object bitmap, Lisp_Object bits, Lisp_Object height, Lisp_Object width, Lisp_Object align)
1539 {
1540 int n, h, i, j;
1541 unsigned short *b;
1542 struct fringe_bitmap fb, *xfb;
1543 int fill1 = 0, fill2 = 0;
1544
1545 CHECK_SYMBOL (bitmap);
1546
1547 if (STRINGP (bits))
1548 h = SCHARS (bits);
1549 else if (VECTORP (bits))
1550 h = ASIZE (bits);
1551 else
1552 wrong_type_argument (Qsequencep, bits);
1553
1554 if (NILP (height))
1555 fb.height = h;
1556 else
1557 {
1558 CHECK_NUMBER (height);
1559 fb.height = max (0, min (XINT (height), 255));
1560 if (fb.height > h)
1561 {
1562 fill1 = (fb.height - h) / 2;
1563 fill2 = fb.height - h - fill1;
1564 }
1565 }
1566
1567 if (NILP (width))
1568 fb.width = 8;
1569 else
1570 {
1571 CHECK_NUMBER (width);
1572 fb.width = max (0, min (XINT (width), 255));
1573 }
1574
1575 fb.period = 0;
1576 fb.align = ALIGN_BITMAP_CENTER;
1577
1578 if (CONSP (align))
1579 {
1580 Lisp_Object period = XCDR (align);
1581 if (CONSP (period))
1582 {
1583 period = XCAR (period);
1584 if (!NILP (period))
1585 {
1586 fb.period = fb.height;
1587 fb.height = 255;
1588 }
1589 }
1590 align = XCAR (align);
1591 }
1592 if (EQ (align, Qtop))
1593 fb.align = ALIGN_BITMAP_TOP;
1594 else if (EQ (align, Qbottom))
1595 fb.align = ALIGN_BITMAP_BOTTOM;
1596 else if (!NILP (align) && !EQ (align, Qcenter))
1597 error ("Bad align argument");
1598
1599 n = lookup_fringe_bitmap (bitmap);
1600 if (!n)
1601 {
1602 if (max_used_fringe_bitmap < max_fringe_bitmaps)
1603 n = max_used_fringe_bitmap++;
1604 else
1605 {
1606 for (n = MAX_STANDARD_FRINGE_BITMAPS;
1607 n < max_fringe_bitmaps;
1608 n++)
1609 if (fringe_bitmaps[n] == NULL)
1610 break;
1611
1612 if (n == max_fringe_bitmaps)
1613 {
1614 int bitmaps = max_fringe_bitmaps + 20;
1615 if (MAX_FRINGE_BITMAPS < bitmaps)
1616 error ("No free fringe bitmap slots");
1617
1618 i = max_fringe_bitmaps;
1619 fringe_bitmaps = xrealloc (fringe_bitmaps,
1620 bitmaps * sizeof *fringe_bitmaps);
1621 fringe_faces = xrealloc (fringe_faces,
1622 bitmaps * sizeof *fringe_faces);
1623
1624 for (i = max_fringe_bitmaps; i < bitmaps; i++)
1625 {
1626 fringe_bitmaps[i] = NULL;
1627 fringe_faces[i] = Qnil;
1628 }
1629
1630 max_fringe_bitmaps = bitmaps;
1631 }
1632 }
1633
1634 Vfringe_bitmaps = Fcons (bitmap, Vfringe_bitmaps);
1635 Fput (bitmap, Qfringe, make_number (n));
1636 }
1637
1638 fb.dynamic = 1;
1639
1640 xfb = xmalloc (sizeof fb + fb.height * BYTES_PER_BITMAP_ROW);
1641 fb.bits = b = (unsigned short *) (xfb + 1);
1642 memset (b, 0, fb.height);
1643
1644 j = 0;
1645 while (j < fb.height)
1646 {
1647 for (i = 0; i < fill1 && j < fb.height; i++)
1648 b[j++] = 0;
1649 for (i = 0; i < h && j < fb.height; i++)
1650 {
1651 Lisp_Object elt = Faref (bits, make_number (i));
1652 b[j++] = NUMBERP (elt) ? XINT (elt) : 0;
1653 }
1654 for (i = 0; i < fill2 && j < fb.height; i++)
1655 b[j++] = 0;
1656 }
1657
1658 *xfb = fb;
1659
1660 init_fringe_bitmap (n, xfb, 0);
1661
1662 return bitmap;
1663 }
1664
1665 DEFUN ("set-fringe-bitmap-face", Fset_fringe_bitmap_face, Sset_fringe_bitmap_face,
1666 1, 2, 0,
1667 doc: /* Set face for fringe bitmap BITMAP to FACE.
1668 If FACE is nil, reset face to default fringe face. */)
1669 (Lisp_Object bitmap, Lisp_Object face)
1670 {
1671 int n;
1672
1673 CHECK_SYMBOL (bitmap);
1674 n = lookup_fringe_bitmap (bitmap);
1675 if (!n)
1676 error ("Undefined fringe bitmap");
1677
1678 /* The purpose of the following code is to signal an error if FACE
1679 is not a face. This is for the caller's convenience only; the
1680 redisplay code should be able to fail gracefully. Skip the check
1681 if FRINGE_FACE_ID is unrealized (as in batch mode and during
1682 daemon startup). */
1683 if (!NILP (face))
1684 {
1685 struct frame *f = SELECTED_FRAME ();
1686
1687 if (FACE_FROM_ID (f, FRINGE_FACE_ID)
1688 && lookup_derived_face (f, face, FRINGE_FACE_ID, 1) < 0)
1689 error ("No such face");
1690 }
1691
1692 fringe_faces[n] = face;
1693 return Qnil;
1694 }
1695
1696 DEFUN ("fringe-bitmaps-at-pos", Ffringe_bitmaps_at_pos, Sfringe_bitmaps_at_pos,
1697 0, 2, 0,
1698 doc: /* Return fringe bitmaps of row containing position POS in window WINDOW.
1699 If WINDOW is nil, use selected window. If POS is nil, use value of point
1700 in that window. Return value is a list (LEFT RIGHT OV), where LEFT
1701 is the symbol for the bitmap in the left fringe (or nil if no bitmap),
1702 RIGHT is similar for the right fringe, and OV is non-nil if there is an
1703 overlay arrow in the left fringe.
1704 Return nil if POS is not visible in WINDOW. */)
1705 (Lisp_Object pos, Lisp_Object window)
1706 {
1707 struct window *w;
1708 struct glyph_row *row;
1709 ptrdiff_t textpos;
1710
1711 if (NILP (window))
1712 window = selected_window;
1713 CHECK_WINDOW (window);
1714 w = XWINDOW (window);
1715
1716 if (!NILP (pos))
1717 {
1718 CHECK_NUMBER_COERCE_MARKER (pos);
1719 if (! (BEGV <= XINT (pos) && XINT (pos) <= ZV))
1720 args_out_of_range (window, pos);
1721 textpos = XINT (pos);
1722 }
1723 else if (w == XWINDOW (selected_window))
1724 textpos = PT;
1725 else
1726 textpos = XMARKER (w->pointm)->charpos;
1727
1728 row = MATRIX_FIRST_TEXT_ROW (w->current_matrix);
1729 row = row_containing_pos (w, textpos, row, NULL, 0);
1730 if (row)
1731 return list3 (get_fringe_bitmap_name (row->left_fringe_bitmap),
1732 get_fringe_bitmap_name (row->right_fringe_bitmap),
1733 (row->overlay_arrow_bitmap == 0 ? Qnil
1734 : row->overlay_arrow_bitmap < 0 ? Qt
1735 : get_fringe_bitmap_name (row->overlay_arrow_bitmap)));
1736 else
1737 return Qnil;
1738 }
1739
1740
1741 /***********************************************************************
1742 Initialization
1743 ***********************************************************************/
1744
1745 void
1746 syms_of_fringe (void)
1747 {
1748 DEFSYM (Qtruncation, "truncation");
1749 DEFSYM (Qcontinuation, "continuation");
1750 DEFSYM (Qoverlay_arrow, "overlay-arrow");
1751 DEFSYM (Qempty_line, "empty-line");
1752 DEFSYM (Qtop_bottom, "top-bottom");
1753 DEFSYM (Qhollow_small, "hollow-small");
1754
1755 defsubr (&Sdestroy_fringe_bitmap);
1756 defsubr (&Sdefine_fringe_bitmap);
1757 defsubr (&Sfringe_bitmaps_at_pos);
1758 defsubr (&Sset_fringe_bitmap_face);
1759
1760 DEFVAR_LISP ("overflow-newline-into-fringe", Voverflow_newline_into_fringe,
1761 doc: /* Non-nil means that newline may flow into the right fringe.
1762 This means that display lines which are exactly as wide as the window
1763 (not counting the final newline) will only occupy one screen line, by
1764 showing (or hiding) the final newline in the right fringe; when point
1765 is at the final newline, the cursor is shown in the right fringe.
1766 If nil, also continue lines which are exactly as wide as the window. */);
1767 Voverflow_newline_into_fringe = Qt;
1768
1769 DEFVAR_LISP ("fringe-bitmaps", Vfringe_bitmaps,
1770 doc: /* List of fringe bitmap symbols. */);
1771 Vfringe_bitmaps = Qnil;
1772 }
1773
1774 /* Garbage collection hook */
1775
1776 void
1777 mark_fringe_data (void)
1778 {
1779 int i;
1780
1781 for (i = 0; i < max_fringe_bitmaps; i++)
1782 if (!NILP (fringe_faces[i]))
1783 mark_object (fringe_faces[i]);
1784 }
1785
1786 /* Initialize this module when Emacs starts. */
1787
1788 void
1789 init_fringe_once (void)
1790 {
1791 int bt;
1792
1793 for (bt = NO_FRINGE_BITMAP + 1; bt < MAX_STANDARD_FRINGE_BITMAPS; bt++)
1794 init_fringe_bitmap (bt, &standard_bitmaps[bt], 1);
1795 }
1796
1797 void
1798 init_fringe (void)
1799 {
1800 int i;
1801
1802 max_fringe_bitmaps = MAX_STANDARD_FRINGE_BITMAPS + 20;
1803
1804 fringe_bitmaps = xzalloc (max_fringe_bitmaps * sizeof *fringe_bitmaps);
1805 fringe_faces = xmalloc (max_fringe_bitmaps * sizeof *fringe_faces);
1806
1807 for (i = 0; i < max_fringe_bitmaps; i++)
1808 fringe_faces[i] = Qnil;
1809 }
1810
1811 #ifdef HAVE_NTGUI
1812
1813 void
1814 w32_init_fringe (struct redisplay_interface *rif)
1815 {
1816 int bt;
1817
1818 if (!rif)
1819 return;
1820
1821 for (bt = NO_FRINGE_BITMAP + 1; bt < MAX_STANDARD_FRINGE_BITMAPS; bt++)
1822 {
1823 struct fringe_bitmap *fb = &standard_bitmaps[bt];
1824 rif->define_fringe_bitmap (bt, fb->bits, fb->height, fb->width);
1825 }
1826 }
1827
1828 void
1829 w32_reset_fringes (void)
1830 {
1831 /* Destroy row bitmaps. */
1832 int bt;
1833 struct redisplay_interface *rif = FRAME_RIF (SELECTED_FRAME ());
1834
1835 if (!rif)
1836 return;
1837
1838 for (bt = NO_FRINGE_BITMAP + 1; bt < max_used_fringe_bitmap; bt++)
1839 rif->destroy_fringe_bitmap (bt);
1840 }
1841
1842 #endif /* HAVE_NTGUI */
1843
1844 #endif /* HAVE_WINDOW_SYSTEM */