Try to use "gpg2" if "gpg" isn't available.
[emacs.git] / src / fringe.c
blobfce100b1463dee136bb3eb11295007958da153f4
1 /* Fringe handling (split from xdisp.c).
2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995, 1997,
3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
4 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21 #include <config.h>
22 #include <stdio.h>
23 #include <setjmp.h>
25 #include "lisp.h"
26 #include "frame.h"
27 #include "window.h"
28 #include "dispextern.h"
29 #include "buffer.h"
30 #include "blockinput.h"
31 #include "termhooks.h"
33 #ifdef HAVE_WINDOW_SYSTEM
35 /* Non-nil means that newline may flow into the right fringe. */
37 Lisp_Object Voverflow_newline_into_fringe;
39 /* List of known fringe bitmap symbols.
41 The fringe bitmap number is stored in the `fringe' property on
42 those symbols. Names for the built-in bitmaps are installed by
43 loading fringe.el.
46 Lisp_Object Vfringe_bitmaps;
48 /* Fringe bitmaps are represented in three different ways:
50 Logical bitmaps are used internally to denote things like
51 'end-of-buffer', 'left-truncation', 'overlay-arrow', etc.
53 Physical bitmaps specify the visual appearence of the bitmap,
54 e.g. 'bottom-left-angle', 'left-arrow', 'left-triangle', etc.
55 User defined bitmaps are physical bitmaps.
57 Internally, fringe bitmaps for a specific display row are
58 represented as a simple integer that is used as an index
59 into the table of all defined bitmaps. This index is stored
60 in the `fringe' property of the physical bitmap symbol.
62 Logical bitmaps are mapped to physical bitmaps through the
63 buffer-local `fringe-indicator-alist' variable.
65 Each element of this alist is a cons (LOGICAL . PHYSICAL)
66 mapping a logical bitmap to a physical bitmap.
67 PHYSICAL is either a symbol to use in both left and right fringe,
68 or a cons of two symbols (LEFT . RIGHT) denoting different
69 bitmaps to use in left and right fringe.
71 LOGICAL is first looked up in the window's buffer's buffer-local
72 value of the fringe-indicator-alist variable, and if not present,
73 in the global value of fringe-indicator-alist.
75 If LOGICAL is not present in either alist, or the PHYSICAL value
76 found is nil, no bitmap is shown for the logical bitmap.
78 The `left-fringe' and `right-fringe' display properties
79 must specify physical bitmap symbols.
82 Lisp_Object Qtruncation, Qcontinuation, Qoverlay_arrow;
83 Lisp_Object Qempty_line, Qtop_bottom;
84 Lisp_Object Qhollow_small;
86 enum fringe_bitmap_align
88 ALIGN_BITMAP_CENTER = 0,
89 ALIGN_BITMAP_TOP,
90 ALIGN_BITMAP_BOTTOM
93 struct fringe_bitmap
95 unsigned short *bits;
96 unsigned height : 8;
97 unsigned width : 8;
98 unsigned period : 8;
99 unsigned align : 2;
100 unsigned dynamic : 1;
104 /***********************************************************************
105 Fringe bitmaps
106 ***********************************************************************/
108 /* Undefined bitmap. A question mark. */
110 ..xxxx..
111 .xxxxxx.
112 xx....xx
113 xx....xx
114 ....xx..
115 ...xx...
116 ...xx...
117 ........
118 ...xx...
119 ...xx...
121 static unsigned short question_mark_bits[] = {
122 0x3c, 0x7e, 0x7e, 0x0c, 0x18, 0x18, 0x00, 0x18, 0x18};
124 /* An arrow like this: `<-'. */
126 ...xx...
127 ..xx....
128 .xx.....
129 xxxxxx..
130 xxxxxx..
131 .xx.....
132 ..xx....
133 ...xx...
135 static unsigned short left_arrow_bits[] = {
136 0x18, 0x30, 0x60, 0xfc, 0xfc, 0x60, 0x30, 0x18};
139 /* Right truncation arrow bitmap `->'. */
141 ...xx...
142 ....xx..
143 .....xx.
144 ..xxxxxx
145 ..xxxxxx
146 .....xx.
147 ....xx..
148 ...xx...
150 static unsigned short right_arrow_bits[] = {
151 0x18, 0x0c, 0x06, 0x3f, 0x3f, 0x06, 0x0c, 0x18};
154 /* Up arrow bitmap. */
156 ...xx...
157 ..xxxx..
158 .xxxxxx.
159 xxxxxxxx
160 ...xx...
161 ...xx...
162 ...xx...
163 ...xx...
165 static unsigned short up_arrow_bits[] = {
166 0x18, 0x3c, 0x7e, 0xff, 0x18, 0x18, 0x18, 0x18};
169 /* Down arrow bitmap. */
171 ...xx...
172 ...xx...
173 ...xx...
174 ...xx...
175 xxxxxxxx
176 .xxxxxx.
177 ..xxxx..
178 ...xx...
180 static unsigned short down_arrow_bits[] = {
181 0x18, 0x18, 0x18, 0x18, 0xff, 0x7e, 0x3c, 0x18};
183 /* Marker for continuation lines. */
185 ..xxxx..
186 .xxxxx..
187 xx......
188 xxx..x..
189 xxxxxx..
190 .xxxxx..
191 ..xxxx..
192 .xxxxx..
194 static unsigned short left_curly_arrow_bits[] = {
195 0x3c, 0x7c, 0xc0, 0xe4, 0xfc, 0x7c, 0x3c, 0x7c};
197 /* Marker for continued lines. */
199 ..xxxx..
200 ..xxxxx.
201 ......xx
202 ..x..xxx
203 ..xxxxxx
204 ..xxxxx.
205 ..xxxx..
206 ..xxxxx.
208 static unsigned short right_curly_arrow_bits[] = {
209 0x3c, 0x3e, 0x03, 0x27, 0x3f, 0x3e, 0x3c, 0x3e};
211 /* Reverse Overlay arrow bitmap. A triangular arrow. */
213 ......xx
214 ....xxxx
215 ...xxxxx
216 ..xxxxxx
217 ..xxxxxx
218 ...xxxxx
219 ....xxxx
220 ......xx
222 static unsigned short left_triangle_bits[] = {
223 0x03, 0x0f, 0x1f, 0x3f, 0x3f, 0x1f, 0x0f, 0x03};
225 /* Overlay arrow bitmap. A triangular arrow. */
227 xx......
228 xxxx....
229 xxxxx...
230 xxxxxx..
231 xxxxxx..
232 xxxxx...
233 xxxx....
234 xx......
236 static unsigned short right_triangle_bits[] = {
237 0xc0, 0xf0, 0xf8, 0xfc, 0xfc, 0xf8, 0xf0, 0xc0};
239 /* First line bitmap. An top-left angle. */
241 xxxxxx..
242 xxxxxx..
243 xx......
244 xx......
245 xx......
246 xx......
247 xx......
248 ........
250 static unsigned short top_left_angle_bits[] = {
251 0xfc, 0xfc, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00};
253 /* First line bitmap. An right-up angle. */
255 ..xxxxxx
256 ..xxxxxx
257 ......xx
258 ......xx
259 ......xx
260 ......xx
261 ......xx
262 ........
264 static unsigned short top_right_angle_bits[] = {
265 0x3f, 0x3f, 0x03, 0x03, 0x03, 0x03, 0x03, 0x00};
267 /* Last line bitmap. An left-down angle. */
269 ........
270 xx......
271 xx......
272 xx......
273 xx......
274 xx......
275 xxxxxx..
276 xxxxxx..
278 static unsigned short bottom_left_angle_bits[] = {
279 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xfc, 0xfc};
281 /* Last line bitmap. An right-down angle. */
283 ........
284 ......xx
285 ......xx
286 ......xx
287 ......xx
288 ......xx
289 ..xxxxxx
290 ..xxxxxx
292 static unsigned short bottom_right_angle_bits[] = {
293 0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x3f, 0x3f};
295 /* First/last line bitmap. An left bracket. */
297 xxxxxx..
298 xxxxxx..
299 xx......
300 xx......
301 xx......
302 xx......
303 xx......
304 xx......
305 xxxxxx..
306 xxxxxx..
308 static unsigned short left_bracket_bits[] = {
309 0xfc, 0xfc, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xfc, 0xfc};
311 /* First/last line bitmap. An right bracket. */
313 ..xxxxxx
314 ..xxxxxx
315 ......xx
316 ......xx
317 ......xx
318 ......xx
319 ......xx
320 ......xx
321 ..xxxxxx
322 ..xxxxxx
324 static unsigned short right_bracket_bits[] = {
325 0x3f, 0x3f, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x3f, 0x3f};
327 /* Filled box cursor bitmap. A filled box; max 13 pixels high. */
329 xxxxxxx.
330 xxxxxxx.
331 xxxxxxx.
332 xxxxxxx.
333 xxxxxxx.
334 xxxxxxx.
335 xxxxxxx.
336 xxxxxxx.
337 xxxxxxx.
338 xxxxxxx.
339 xxxxxxx.
340 xxxxxxx.
341 xxxxxxx.
343 static unsigned short filled_rectangle_bits[] = {
344 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe};
346 /* Hollow box cursor bitmap. A hollow box; max 13 pixels high. */
348 xxxxxxx.
349 x.....x.
350 x.....x.
351 x.....x.
352 x.....x.
353 x.....x.
354 x.....x.
355 x.....x.
356 x.....x.
357 x.....x.
358 x.....x.
359 x.....x.
360 xxxxxxx.
362 static unsigned short hollow_rectangle_bits[] = {
363 0xfe, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0xfe};
365 /* Hollow square bitmap. */
367 .xxxxxx.
368 .x....x.
369 .x....x.
370 .x....x.
371 .x....x.
372 .xxxxxx.
374 static unsigned short hollow_square_bits[] = {
375 0x7e, 0x42, 0x42, 0x42, 0x42, 0x7e};
377 /* Filled square bitmap. */
379 .xxxxxx.
380 .xxxxxx.
381 .xxxxxx.
382 .xxxxxx.
383 .xxxxxx.
384 .xxxxxx.
386 static unsigned short filled_square_bits[] = {
387 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e};
389 /* Bar cursor bitmap. A vertical bar; max 13 pixels high. */
391 xx......
392 xx......
393 xx......
394 xx......
395 xx......
396 xx......
397 xx......
398 xx......
399 xx......
400 xx......
401 xx......
402 xx......
403 xx......
405 static unsigned short vertical_bar_bits[] = {
406 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0};
408 /* HBar cursor bitmap. A horizontal bar; 2 pixels high. */
410 xxxxxxx.
411 xxxxxxx.
413 static unsigned short horizontal_bar_bits[] = {
414 0xfe, 0xfe};
417 /* Bitmap drawn to indicate lines not displaying text if
418 `indicate-empty-lines' is non-nil. */
420 ........
421 ..xxxx..
422 ........
423 ........
424 ..xxxx..
425 ........
427 static unsigned short empty_line_bits[] = {
428 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
429 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
430 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
431 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
432 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
433 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
434 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
435 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00};
438 #define BYTES_PER_BITMAP_ROW (sizeof (unsigned short))
439 #define STANDARD_BITMAP_HEIGHT(bits) (sizeof (bits)/BYTES_PER_BITMAP_ROW)
440 #define FRBITS(bits) bits, STANDARD_BITMAP_HEIGHT (bits)
442 /* NOTE: The order of these bitmaps must match the sequence
443 used in fringe.el to define the corresponding symbols. */
445 struct fringe_bitmap standard_bitmaps[] =
447 { NULL, 0, 0, 0, 0, 0 }, /* NO_FRINGE_BITMAP */
448 { FRBITS (question_mark_bits), 8, 0, ALIGN_BITMAP_CENTER, 0 },
449 { FRBITS (left_arrow_bits), 8, 0, ALIGN_BITMAP_CENTER, 0 },
450 { FRBITS (right_arrow_bits), 8, 0, ALIGN_BITMAP_CENTER, 0 },
451 { FRBITS (up_arrow_bits), 8, 0, ALIGN_BITMAP_TOP, 0 },
452 { FRBITS (down_arrow_bits), 8, 0, ALIGN_BITMAP_BOTTOM, 0 },
453 { FRBITS (left_curly_arrow_bits), 8, 0, ALIGN_BITMAP_CENTER, 0 },
454 { FRBITS (right_curly_arrow_bits), 8, 0, ALIGN_BITMAP_CENTER, 0 },
455 { FRBITS (left_triangle_bits), 8, 0, ALIGN_BITMAP_CENTER, 0 },
456 { FRBITS (right_triangle_bits), 8, 0, ALIGN_BITMAP_CENTER, 0 },
457 { FRBITS (top_left_angle_bits), 8, 0, ALIGN_BITMAP_TOP, 0 },
458 { FRBITS (top_right_angle_bits), 8, 0, ALIGN_BITMAP_TOP, 0 },
459 { FRBITS (bottom_left_angle_bits), 8, 0, ALIGN_BITMAP_BOTTOM, 0 },
460 { FRBITS (bottom_right_angle_bits), 8, 0, ALIGN_BITMAP_BOTTOM, 0 },
461 { FRBITS (left_bracket_bits), 8, 0, ALIGN_BITMAP_CENTER, 0 },
462 { FRBITS (right_bracket_bits), 8, 0, ALIGN_BITMAP_CENTER, 0 },
463 { FRBITS (filled_rectangle_bits), 8, 0, ALIGN_BITMAP_CENTER, 0 },
464 { FRBITS (hollow_rectangle_bits), 8, 0, ALIGN_BITMAP_CENTER, 0 },
465 { FRBITS (filled_square_bits), 8, 0, ALIGN_BITMAP_CENTER, 0 },
466 { FRBITS (hollow_square_bits), 8, 0, ALIGN_BITMAP_CENTER, 0 },
467 { FRBITS (vertical_bar_bits), 8, 0, ALIGN_BITMAP_CENTER, 0 },
468 { FRBITS (horizontal_bar_bits), 8, 0, ALIGN_BITMAP_BOTTOM, 0 },
469 { FRBITS (empty_line_bits), 8, 3, ALIGN_BITMAP_TOP, 0 },
472 #define NO_FRINGE_BITMAP 0
473 #define UNDEF_FRINGE_BITMAP 1
474 #define MAX_STANDARD_FRINGE_BITMAPS (sizeof(standard_bitmaps)/sizeof(standard_bitmaps[0]))
476 static struct fringe_bitmap **fringe_bitmaps;
477 static Lisp_Object *fringe_faces;
478 static int max_fringe_bitmaps;
480 int max_used_fringe_bitmap = MAX_STANDARD_FRINGE_BITMAPS;
483 /* Lookup bitmap number for symbol BITMAP.
484 Return 0 if not a bitmap. */
487 lookup_fringe_bitmap (Lisp_Object bitmap)
489 int bn;
491 bitmap = Fget (bitmap, Qfringe);
492 if (!INTEGERP (bitmap))
493 return 0;
495 bn = XINT (bitmap);
496 if (bn > NO_FRINGE_BITMAP
497 && bn < max_used_fringe_bitmap
498 && (bn < MAX_STANDARD_FRINGE_BITMAPS
499 || fringe_bitmaps[bn] != NULL))
500 return bn;
502 return 0;
505 /* Get fringe bitmap name for bitmap number BN.
507 Found by traversing Vfringe_bitmaps comparing BN to the
508 fringe property for each symbol.
510 Return BN if not found in Vfringe_bitmaps. */
512 static Lisp_Object
513 get_fringe_bitmap_name (int bn)
515 Lisp_Object bitmaps;
516 Lisp_Object num;
518 /* Zero means no bitmap -- return nil. */
519 if (bn <= 0)
520 return Qnil;
522 bitmaps = Vfringe_bitmaps;
523 num = make_number (bn);
525 while (CONSP (bitmaps))
527 Lisp_Object bitmap = XCAR (bitmaps);
528 if (EQ (num, Fget (bitmap, Qfringe)))
529 return bitmap;
530 bitmaps = XCDR (bitmaps);
533 return num;
537 /* Draw the bitmap WHICH in one of the left or right fringes of
538 window W. ROW is the glyph row for which to display the bitmap; it
539 determines the vertical position at which the bitmap has to be
540 drawn.
541 LEFT_P is 1 for left fringe, 0 for right fringe.
544 static void
545 draw_fringe_bitmap_1 (struct window *w, struct glyph_row *row, int left_p, int overlay, int which)
547 struct frame *f = XFRAME (WINDOW_FRAME (w));
548 struct draw_fringe_bitmap_params p;
549 struct fringe_bitmap *fb;
550 int period;
551 int face_id = DEFAULT_FACE_ID;
552 int offset, header_line_height;
554 p.overlay_p = (overlay & 1) == 1;
555 p.cursor_p = (overlay & 2) == 2;
557 if (which != NO_FRINGE_BITMAP)
559 offset = 0;
561 else if (left_p)
563 which = row->left_fringe_bitmap;
564 face_id = row->left_fringe_face_id;
565 offset = row->left_fringe_offset;
567 else
569 which = row->right_fringe_bitmap;
570 face_id = row->right_fringe_face_id;
571 offset = row->right_fringe_offset;
574 if (face_id == DEFAULT_FACE_ID)
576 Lisp_Object face = fringe_faces[which];
577 face_id = NILP (face) ? lookup_named_face (f, Qfringe, 0)
578 : lookup_derived_face (f, face, FRINGE_FACE_ID, 0);
579 if (face_id < 0)
580 face_id = FRINGE_FACE_ID;
583 fb = fringe_bitmaps[which];
584 if (fb == NULL)
585 fb = &standard_bitmaps[which < MAX_STANDARD_FRINGE_BITMAPS
586 ? which : UNDEF_FRINGE_BITMAP];
588 period = fb->period;
590 /* Convert row to frame coordinates. */
591 p.y = WINDOW_TO_FRAME_PIXEL_Y (w, row->y) + offset;
593 p.which = which;
594 p.bits = fb->bits;
595 p.wd = fb->width;
597 p.h = fb->height;
598 p.dh = (period > 0 ? (p.y % period) : 0);
599 p.h -= p.dh;
601 /* Adjust y to the offset in the row to start drawing the bitmap. */
602 switch (fb->align)
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;
614 p.face = FACE_FROM_ID (f, face_id);
616 if (p.face == NULL)
618 /* This could happen after clearing face cache.
619 But it shouldn't happen anymore. ++kfs */
620 return;
623 PREPARE_FACE_FOR_DISPLAY (f, p.face);
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)
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;
641 if (p.wd < wd || p.y > p.by || p.y + p.h < p.by + p.ny)
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;
651 else
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)
665 p.bx = x;
666 p.nx = wd;
670 FRAME_RIF (f)->draw_fringe_bitmap (w, row, &p);
673 static int
674 get_logical_cursor_bitmap (struct window *w, Lisp_Object cursor)
676 Lisp_Object cmap, bm = Qnil;
678 if ((cmap = XBUFFER (w->buffer)->fringe_cursor_alist), !NILP (cmap))
680 bm = Fassq (cursor, cmap);
681 if (CONSP (bm))
683 if ((bm = XCDR (bm)), NILP (bm))
684 return NO_FRINGE_BITMAP;
685 return lookup_fringe_bitmap (bm);
688 if (EQ (cmap, buffer_defaults.fringe_cursor_alist))
689 return NO_FRINGE_BITMAP;
690 bm = Fassq (cursor, 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);
696 static int
697 get_logical_fringe_bitmap (struct window *w, Lisp_Object bitmap, int right_p, int partial_p)
699 Lisp_Object cmap, bm1 = Qnil, bm2 = Qnil, bm;
700 int ln1 = 0, ln2 = 0;
701 int ix1 = right_p;
702 int ix2 = ix1 + (partial_p ? 2 : 0);
704 /* Lookup in buffer-local fringe-indicator-alist before global alist.
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.
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. */
715 if ((cmap = XBUFFER (w->buffer)->fringe_indicator_alist), !NILP (cmap))
717 bm1 = Fassq (bitmap, cmap);
718 if (CONSP (bm1))
720 if ((bm1 = XCDR (bm1)), NILP (bm1))
721 return NO_FRINGE_BITMAP;
722 if (CONSP (bm1))
724 ln1 = XINT (Flength (bm1));
725 if (partial_p)
727 if (ln1 > ix2)
729 bm = Fnth (make_number (ix2), bm1);
730 if (!EQ (bm, Qt))
731 goto found;
734 else
736 if (ln1 > ix1)
738 bm = Fnth (make_number (ix1), bm1);
739 if (!EQ (bm, Qt))
740 goto found;
744 else if ((bm = bm1, !EQ (bm, Qt)))
745 goto found;
749 if (!EQ (cmap, buffer_defaults.fringe_indicator_alist)
750 && !NILP (buffer_defaults.fringe_indicator_alist))
752 bm2 = Fassq (bitmap, buffer_defaults.fringe_indicator_alist);
753 if (CONSP (bm2))
755 if ((bm2 = XCDR (bm2)), !NILP (bm2))
757 if (CONSP (bm2))
759 ln2 = XINT (Flength (bm2));
760 if (partial_p)
762 if (ln2 > ix2)
764 bm = Fnth (make_number (ix2), bm2);
765 if (!EQ (bm, Qt))
766 goto found;
774 if (ln1 > ix1)
776 bm = Fnth (make_number (ix1), bm1);
777 if (!EQ (bm, Qt))
778 goto found;
781 if (ln2 > ix1)
783 bm = Fnth (make_number (ix1), bm2);
784 if (!EQ (bm, Qt))
785 goto found;
786 return NO_FRINGE_BITMAP;
788 else if ((bm = bm2, NILP (bm)))
789 return NO_FRINGE_BITMAP;
791 found:
792 return lookup_fringe_bitmap (bm);
796 void
797 draw_fringe_bitmap (struct window *w, struct glyph_row *row, int left_p)
799 int overlay = 0;
801 if (left_p == row->reversed_p && row->cursor_in_fringe_p)
803 Lisp_Object cursor = Qnil;
805 switch (w->phys_cursor_type)
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;
828 if (!NILP (cursor))
830 int bm = get_logical_cursor_bitmap (w, cursor);
831 if (bm != NO_FRINGE_BITMAP)
833 draw_fringe_bitmap_1 (w, row, left_p, 2, bm);
834 overlay = EQ (cursor, Qbox) ? 3 : 1;
839 draw_fringe_bitmap_1 (w, row, left_p, overlay, NO_FRINGE_BITMAP);
841 if (left_p && row->overlay_arrow_bitmap != NO_FRINGE_BITMAP)
842 draw_fringe_bitmap_1 (w, row, 1, 1, row->overlay_arrow_bitmap);
846 /* Draw fringe bitmaps for glyph row ROW on window W. Call this
847 function with input blocked. */
849 void
850 draw_row_fringe_bitmaps (struct window *w, struct glyph_row *row)
852 xassert (interrupt_input_blocked);
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;
859 if (WINDOW_LEFT_FRINGE_WIDTH (w) != 0)
860 draw_fringe_bitmap (w, row, 1);
862 if (WINDOW_RIGHT_FRINGE_WIDTH (w) != 0)
863 draw_fringe_bitmap (w, row, 0);
866 /* Draw the fringes of window W. Only fringes for rows marked for
867 update in redraw_fringe_bitmaps_p are drawn.
869 Return >0 if left or right fringe was redrawn in any way.
871 If NO_FRINGE is non-zero, also return >0 if either fringe has zero width.
873 A return value >0 indicates that the vertical line between windows
874 needs update (as it may be drawn in the fringe).
878 draw_window_fringes (struct window *w, int no_fringe)
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;
886 if (w->pseudo_window_p)
887 return 0;
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++;
895 for (y = w->vscroll, rn = 0, row = w->current_matrix->rows;
896 y < yb && rn < nrows;
897 y += row->height, ++row, ++rn)
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++;
906 return updated;
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.
913 If KEEP_CURRENT_P is 0, update current_matrix too. */
916 update_window_fringes (struct window *w, int keep_current_p)
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 int top_row_ends_at_zv_p, bot_row_ends_at_zv_p;
933 if (w->pseudo_window_p)
934 return 0;
936 if (!MINI_WINDOW_P (w)
937 && (ind = XBUFFER (w->buffer)->indicate_buffer_boundaries, !NILP (ind)))
939 if (EQ (ind, Qleft) || EQ (ind, Qright))
940 boundary_top = boundary_bot = arrow_top = arrow_bot = ind;
941 else if (CONSP (ind) && CONSP (XCAR (ind)))
943 Lisp_Object pos;
944 if (pos = Fassq (Qt, ind), !NILP (pos))
945 boundary_top = boundary_bot = arrow_top = arrow_bot = XCDR (pos);
946 if (pos = Fassq (Qtop, ind), !NILP (pos))
947 boundary_top = XCDR (pos);
948 if (pos = Fassq (Qbottom, ind), !NILP (pos))
949 boundary_bot = XCDR (pos);
950 if (pos = Fassq (Qup, ind), !NILP (pos))
951 arrow_top = XCDR (pos);
952 if (pos = Fassq (Qdown, ind), !NILP (pos))
953 arrow_bot = XCDR (pos);
955 else
956 /* Anything else means boundary on left and no arrows. */
957 boundary_top = boundary_bot = Qleft;
960 top_ind_rn = bot_ind_rn = -1;
961 if (!NILP (ind))
963 for (y = w->vscroll, rn = 0;
964 y < yb && rn < nrows;
965 y += row->height, ++rn)
967 unsigned indicate_bob_p, indicate_top_line_p;
968 unsigned indicate_eob_p, indicate_bottom_line_p;
970 row = w->desired_matrix->rows + rn;
971 if (!row->enabled_p)
972 row = w->current_matrix->rows + rn;
974 indicate_bob_p = row->indicate_bob_p;
975 indicate_top_line_p = row->indicate_top_line_p;
976 indicate_eob_p = row->indicate_eob_p;
977 indicate_bottom_line_p = row->indicate_bottom_line_p;
979 row->indicate_bob_p = row->indicate_top_line_p = 0;
980 row->indicate_eob_p = row->indicate_bottom_line_p = 0;
982 if (!row->mode_line_p)
984 if (top_ind_rn < 0 && row->visible_height > 0)
986 if (MATRIX_ROW_START_CHARPOS (row) <= BUF_BEGV (XBUFFER (w->buffer))
987 && !MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w, row))
988 row->indicate_bob_p = !NILP (boundary_top);
989 else
990 row->indicate_top_line_p = !NILP (arrow_top);
991 top_ind_rn = rn;
994 if (bot_ind_rn < 0)
996 if (MATRIX_ROW_END_CHARPOS (row) >= BUF_ZV (XBUFFER (w->buffer))
997 && !MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row))
998 row->indicate_eob_p = !NILP (boundary_bot), bot_ind_rn = rn;
999 else if (y + row->height >= yb)
1000 row->indicate_bottom_line_p = !NILP (arrow_bot), bot_ind_rn = rn;
1006 empty_pos = XBUFFER (w->buffer)->indicate_empty_lines;
1007 if (!NILP (empty_pos) && !EQ (empty_pos, Qright))
1008 empty_pos = WINDOW_LEFT_FRINGE_WIDTH (w) == 0 ? Qright : Qleft;
1010 for (y = 0; y < MAX_BITMAP_CACHE; y++)
1011 bitmap_cache[y] = -1;
1013 #define LEFT_FRINGE(cache, which, partial_p) \
1014 (bitmap_cache[cache*4+partial_p] >= 0 \
1015 ? bitmap_cache[cache*4+partial_p] \
1016 : (bitmap_cache[cache*4+partial_p] = \
1017 get_logical_fringe_bitmap (w, which, 0, partial_p)))
1019 #define RIGHT_FRINGE(cache, which, partial_p) \
1020 (bitmap_cache[cache*4+2+partial_p] >= 0 \
1021 ? bitmap_cache[cache*4+2+partial_p] \
1022 : (bitmap_cache[cache*4+2+partial_p] = \
1023 get_logical_fringe_bitmap (w, which, 1, partial_p)))
1026 /* Extend top-aligned top indicator (or bottom-aligned bottom
1027 indicator) to adjacent rows if it doesn't fit in one row. */
1028 top_ind_min_y = bot_ind_max_y = -1;
1029 if (top_ind_rn >= 0)
1031 int bn = NO_FRINGE_BITMAP;
1033 row = w->desired_matrix->rows + top_ind_rn;
1034 if (!row->enabled_p)
1035 row = w->current_matrix->rows + top_ind_rn;
1037 top_row_ends_at_zv_p = row->ends_at_zv_p;
1038 if (row->indicate_bob_p)
1040 if (EQ (boundary_top, Qleft))
1041 bn = ((row->indicate_eob_p && EQ (boundary_bot, Qleft))
1042 ? LEFT_FRINGE (1, Qtop_bottom, row->ends_at_zv_p)
1043 : LEFT_FRINGE (2, Qtop, 0));
1044 else
1045 bn = ((row->indicate_eob_p && EQ (boundary_bot, Qright))
1046 ? RIGHT_FRINGE (1, Qtop_bottom, row->ends_at_zv_p)
1047 : RIGHT_FRINGE (2, Qtop, 0));
1049 else if (row->indicate_top_line_p)
1051 if (EQ (arrow_top, Qleft))
1052 bn = LEFT_FRINGE (6, Qup, 0);
1053 else
1054 bn = RIGHT_FRINGE (6, Qup, 0);
1057 if (bn != NO_FRINGE_BITMAP)
1059 struct fringe_bitmap *fb;
1061 fb = fringe_bitmaps[bn];
1062 if (fb == NULL)
1063 fb = &standard_bitmaps[bn < MAX_STANDARD_FRINGE_BITMAPS
1064 ? bn : UNDEF_FRINGE_BITMAP];
1065 if (fb->align == ALIGN_BITMAP_TOP && fb->period == 0)
1067 struct glyph_row *row1;
1068 int top_ind_max_y;
1070 top_ind_min_y = WINDOW_HEADER_LINE_HEIGHT (w);
1071 top_ind_max_y = top_ind_min_y + fb->height;
1072 if (top_ind_max_y > yb)
1073 top_ind_max_y = yb;
1075 for (y = row->y + row->height, rn = top_ind_rn + 1;
1076 y < top_ind_max_y && rn < nrows;
1077 y += row1->height, rn++)
1079 if (bot_ind_rn >= 0 && rn >= bot_ind_rn)
1080 break;
1082 row1 = w->desired_matrix->rows + rn;
1083 if (!row1->enabled_p)
1084 row1 = w->current_matrix->rows + rn;
1086 row1->indicate_bob_p = row->indicate_bob_p;
1087 row1->indicate_top_line_p = row->indicate_top_line_p;
1092 if (bot_ind_rn >= 0)
1094 int bn = NO_FRINGE_BITMAP;
1096 row = w->desired_matrix->rows + bot_ind_rn;
1097 if (!row->enabled_p)
1098 row = w->current_matrix->rows + bot_ind_rn;
1100 bot_row_ends_at_zv_p = row->ends_at_zv_p;
1101 if (row->indicate_eob_p)
1103 if (EQ (boundary_bot, Qleft))
1104 bn = LEFT_FRINGE (3, Qbottom, row->ends_at_zv_p);
1105 else
1106 bn = RIGHT_FRINGE (3, Qbottom, row->ends_at_zv_p);
1108 else if (row->indicate_bottom_line_p)
1110 if (EQ (arrow_bot, Qleft))
1111 bn = LEFT_FRINGE (7, Qdown, 0);
1112 else
1113 bn = RIGHT_FRINGE (7, Qdown, 0);
1116 if (bn != NO_FRINGE_BITMAP)
1118 struct fringe_bitmap *fb;
1120 fb = fringe_bitmaps[bn];
1121 if (fb == NULL)
1122 fb = &standard_bitmaps[bn < MAX_STANDARD_FRINGE_BITMAPS
1123 ? bn : UNDEF_FRINGE_BITMAP];
1124 if (fb->align == ALIGN_BITMAP_BOTTOM && fb->period == 0)
1126 struct glyph_row *row1;
1127 int bot_ind_min_y;
1129 bot_ind_max_y = row->y + row->visible_height;
1130 bot_ind_min_y = bot_ind_max_y - fb->height;
1131 if (bot_ind_min_y < WINDOW_HEADER_LINE_HEIGHT (w))
1132 bot_ind_min_y = WINDOW_HEADER_LINE_HEIGHT (w);
1134 for (y = row->y, rn = bot_ind_rn - 1;
1135 y >= bot_ind_min_y && rn >= 0;
1136 y -= row1->height, rn--)
1138 if (top_ind_rn >= 0 && rn <= top_ind_rn)
1139 break;
1141 row1 = w->desired_matrix->rows + rn;
1142 if (!row1->enabled_p)
1143 row1 = w->current_matrix->rows + rn;
1145 row1->indicate_eob_p = row->indicate_eob_p;
1146 row1->indicate_bottom_line_p = row->indicate_bottom_line_p;
1152 for (y = w->vscroll, rn = 0;
1153 y < yb && rn < nrows;
1154 y += row->height, rn++)
1156 int left, right;
1157 unsigned left_face_id, right_face_id;
1158 int left_offset, right_offset;
1160 row = w->desired_matrix->rows + rn;
1161 cur = w->current_matrix->rows + rn;
1162 if (!row->enabled_p)
1163 row = cur;
1165 left_face_id = right_face_id = DEFAULT_FACE_ID;
1166 left_offset = right_offset = 0;
1168 /* Decide which bitmap to draw in the left fringe. */
1169 if (WINDOW_LEFT_FRINGE_WIDTH (w) == 0)
1170 left = NO_FRINGE_BITMAP;
1171 else if (row->left_user_fringe_bitmap != NO_FRINGE_BITMAP)
1173 left = row->left_user_fringe_bitmap;
1174 left_face_id = row->left_user_fringe_face_id;
1176 else if ((!row->reversed_p && row->truncated_on_left_p)
1177 || (row->reversed_p && row->truncated_on_right_p))
1178 left = LEFT_FRINGE(0, Qtruncation, 0);
1179 else if (row->indicate_bob_p && EQ (boundary_top, Qleft))
1181 left = ((row->indicate_eob_p && EQ (boundary_bot, Qleft))
1182 ? LEFT_FRINGE (1, Qtop_bottom, top_row_ends_at_zv_p)
1183 : LEFT_FRINGE (2, Qtop, 0));
1184 if (top_ind_min_y >= 0)
1185 left_offset = top_ind_min_y - row->y;
1187 else if (row->indicate_eob_p && EQ (boundary_bot, Qleft))
1189 left = LEFT_FRINGE (3, Qbottom, bot_row_ends_at_zv_p);
1190 if (bot_ind_max_y >= 0)
1191 left_offset = bot_ind_max_y - (row->y + row->visible_height);
1193 else if ((!row->reversed_p && MATRIX_ROW_CONTINUATION_LINE_P (row))
1194 || (row->reversed_p && row->continued_p))
1195 left = LEFT_FRINGE (4, Qcontinuation, 0);
1196 else if (row->indicate_empty_line_p && EQ (empty_pos, Qleft))
1197 left = LEFT_FRINGE (5, Qempty_line, 0);
1198 else if (row->indicate_top_line_p && EQ (arrow_top, Qleft))
1200 left = LEFT_FRINGE (6, Qup, 0);
1201 if (top_ind_min_y >= 0)
1202 left_offset = top_ind_min_y - row->y;
1204 else if (row->indicate_bottom_line_p && EQ (arrow_bot, Qleft))
1206 left = LEFT_FRINGE (7, Qdown, 0);
1207 if (bot_ind_max_y >= 0)
1208 left_offset = bot_ind_max_y - (row->y + row->visible_height);
1210 else
1211 left = NO_FRINGE_BITMAP;
1213 /* Decide which bitmap to draw in the right fringe. */
1214 if (WINDOW_RIGHT_FRINGE_WIDTH (w) == 0)
1215 right = NO_FRINGE_BITMAP;
1216 else if (row->right_user_fringe_bitmap != NO_FRINGE_BITMAP)
1218 right = row->right_user_fringe_bitmap;
1219 right_face_id = row->right_user_fringe_face_id;
1221 else if ((!row->reversed_p && row->truncated_on_right_p)
1222 || (row->reversed_p && row->truncated_on_left_p))
1223 right = RIGHT_FRINGE (0, Qtruncation, 0);
1224 else if (row->indicate_bob_p && EQ (boundary_top, Qright))
1226 right = ((row->indicate_eob_p && EQ (boundary_bot, Qright))
1227 ? RIGHT_FRINGE (1, Qtop_bottom, top_row_ends_at_zv_p)
1228 : RIGHT_FRINGE (2, Qtop, 0));
1229 if (top_ind_min_y >= 0)
1230 right_offset = top_ind_min_y - row->y;
1232 else if (row->indicate_eob_p && EQ (boundary_bot, Qright))
1234 right = RIGHT_FRINGE (3, Qbottom, bot_row_ends_at_zv_p);
1235 if (bot_ind_max_y >= 0)
1236 right_offset = bot_ind_max_y - (row->y + row->visible_height);
1238 else if ((!row->reversed_p && row->continued_p)
1239 || (row->reversed_p && MATRIX_ROW_CONTINUATION_LINE_P (row)))
1240 right = RIGHT_FRINGE (4, Qcontinuation, 0);
1241 else if (row->indicate_top_line_p && EQ (arrow_top, Qright))
1243 right = RIGHT_FRINGE (6, Qup, 0);
1244 if (top_ind_min_y >= 0)
1245 right_offset = top_ind_min_y - row->y;
1247 else if (row->indicate_bottom_line_p && EQ (arrow_bot, Qright))
1249 right = RIGHT_FRINGE (7, Qdown, 0);
1250 if (bot_ind_max_y >= 0)
1251 right_offset = bot_ind_max_y - (row->y + row->visible_height);
1253 else if (row->indicate_empty_line_p && EQ (empty_pos, Qright))
1254 right = RIGHT_FRINGE (5, Qempty_line, 0);
1255 else
1256 right = NO_FRINGE_BITMAP;
1258 if (row->y != cur->y
1259 || row->visible_height != cur->visible_height
1260 || row->ends_at_zv_p != cur->ends_at_zv_p
1261 || left != cur->left_fringe_bitmap
1262 || right != cur->right_fringe_bitmap
1263 || left_face_id != cur->left_fringe_face_id
1264 || right_face_id != cur->right_fringe_face_id
1265 || left_offset != cur->left_fringe_offset
1266 || right_offset != cur->right_fringe_offset
1267 || cur->redraw_fringe_bitmaps_p)
1269 redraw_p = row->redraw_fringe_bitmaps_p = 1;
1270 if (!keep_current_p)
1272 cur->redraw_fringe_bitmaps_p = 1;
1273 cur->left_fringe_bitmap = left;
1274 cur->right_fringe_bitmap = right;
1275 cur->left_fringe_face_id = left_face_id;
1276 cur->right_fringe_face_id = right_face_id;
1277 cur->left_fringe_offset = left_offset;
1278 cur->right_fringe_offset = right_offset;
1282 if (row->overlay_arrow_bitmap < 0)
1283 row->overlay_arrow_bitmap = get_logical_fringe_bitmap (w, Qoverlay_arrow, 0, 0);
1285 if (row->overlay_arrow_bitmap != cur->overlay_arrow_bitmap)
1287 redraw_p = row->redraw_fringe_bitmaps_p = cur->redraw_fringe_bitmaps_p = 1;
1288 cur->overlay_arrow_bitmap = row->overlay_arrow_bitmap;
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;
1299 return redraw_p && !keep_current_p;
1303 /* Compute actual fringe widths for frame F.
1305 If REDRAW is 1, redraw F if the fringe settings was actually
1306 modified and F is visible.
1308 Since the combined left and right fringe must occupy an integral
1309 number of columns, we may need to add some pixels to each fringe.
1310 Typically, we add an equal amount (+/- 1 pixel) to each fringe,
1311 but a negative width value is taken literally (after negating it).
1313 We never make the fringes narrower than specified.
1316 void
1317 compute_fringe_widths (struct frame *f, int redraw)
1319 int o_left = FRAME_LEFT_FRINGE_WIDTH (f);
1320 int o_right = FRAME_RIGHT_FRINGE_WIDTH (f);
1321 int o_cols = FRAME_FRINGE_COLS (f);
1323 Lisp_Object left_fringe = Fassq (Qleft_fringe, f->param_alist);
1324 Lisp_Object right_fringe = Fassq (Qright_fringe, f->param_alist);
1325 int left_fringe_width, right_fringe_width;
1327 if (!NILP (left_fringe))
1328 left_fringe = Fcdr (left_fringe);
1329 if (!NILP (right_fringe))
1330 right_fringe = Fcdr (right_fringe);
1332 left_fringe_width = ((NILP (left_fringe) || !INTEGERP (left_fringe)) ? 8 :
1333 XINT (left_fringe));
1334 right_fringe_width = ((NILP (right_fringe) || !INTEGERP (right_fringe)) ? 8 :
1335 XINT (right_fringe));
1337 if (left_fringe_width || right_fringe_width)
1339 int left_wid = left_fringe_width >= 0 ? left_fringe_width : -left_fringe_width;
1340 int right_wid = right_fringe_width >= 0 ? right_fringe_width : -right_fringe_width;
1341 int conf_wid = left_wid + right_wid;
1342 int font_wid = FRAME_COLUMN_WIDTH (f);
1343 int cols = (left_wid + right_wid + font_wid-1) / font_wid;
1344 int real_wid = cols * font_wid;
1345 if (left_wid && right_wid)
1347 if (left_fringe_width < 0)
1349 /* Left fringe width is fixed, adjust right fringe if necessary */
1350 FRAME_LEFT_FRINGE_WIDTH (f) = left_wid;
1351 FRAME_RIGHT_FRINGE_WIDTH (f) = real_wid - left_wid;
1353 else if (right_fringe_width < 0)
1355 /* Right fringe width is fixed, adjust left fringe if necessary */
1356 FRAME_LEFT_FRINGE_WIDTH (f) = real_wid - right_wid;
1357 FRAME_RIGHT_FRINGE_WIDTH (f) = right_wid;
1359 else
1361 /* Adjust both fringes with an equal amount.
1362 Note that we are doing integer arithmetic here, so don't
1363 lose a pixel if the total width is an odd number. */
1364 int fill = real_wid - conf_wid;
1365 FRAME_LEFT_FRINGE_WIDTH (f) = left_wid + fill/2;
1366 FRAME_RIGHT_FRINGE_WIDTH (f) = right_wid + fill - fill/2;
1369 else if (left_fringe_width)
1371 FRAME_LEFT_FRINGE_WIDTH (f) = real_wid;
1372 FRAME_RIGHT_FRINGE_WIDTH (f) = 0;
1374 else
1376 FRAME_LEFT_FRINGE_WIDTH (f) = 0;
1377 FRAME_RIGHT_FRINGE_WIDTH (f) = real_wid;
1379 FRAME_FRINGE_COLS (f) = cols;
1381 else
1383 FRAME_LEFT_FRINGE_WIDTH (f) = 0;
1384 FRAME_RIGHT_FRINGE_WIDTH (f) = 0;
1385 FRAME_FRINGE_COLS (f) = 0;
1388 if (redraw && FRAME_VISIBLE_P (f))
1389 if (o_left != FRAME_LEFT_FRINGE_WIDTH (f) ||
1390 o_right != FRAME_RIGHT_FRINGE_WIDTH (f) ||
1391 o_cols != FRAME_FRINGE_COLS (f))
1392 redraw_frame (f);
1396 /* Free resources used by a user-defined bitmap. */
1398 void
1399 destroy_fringe_bitmap (int n)
1401 struct fringe_bitmap **fbp;
1403 fringe_faces[n] = Qnil;
1405 fbp = &fringe_bitmaps[n];
1406 if (*fbp && (*fbp)->dynamic)
1408 /* XXX Is SELECTED_FRAME OK here? */
1409 struct redisplay_interface *rif = FRAME_RIF (SELECTED_FRAME ());
1410 if (rif && rif->destroy_fringe_bitmap)
1411 rif->destroy_fringe_bitmap (n);
1412 xfree (*fbp);
1413 *fbp = NULL;
1416 while (max_used_fringe_bitmap > MAX_STANDARD_FRINGE_BITMAPS
1417 && fringe_bitmaps[max_used_fringe_bitmap - 1] == NULL)
1418 max_used_fringe_bitmap--;
1422 DEFUN ("destroy-fringe-bitmap", Fdestroy_fringe_bitmap, Sdestroy_fringe_bitmap,
1423 1, 1, 0,
1424 doc: /* Destroy fringe bitmap BITMAP.
1425 If BITMAP overrides a standard fringe bitmap, the original bitmap is restored. */)
1426 (Lisp_Object bitmap)
1428 int n;
1430 CHECK_SYMBOL (bitmap);
1431 n = lookup_fringe_bitmap (bitmap);
1432 if (!n)
1433 return Qnil;
1435 destroy_fringe_bitmap (n);
1437 if (n >= MAX_STANDARD_FRINGE_BITMAPS)
1439 Vfringe_bitmaps = Fdelq (bitmap, Vfringe_bitmaps);
1440 /* It would be better to remove the fringe property. */
1441 Fput (bitmap, Qfringe, Qnil);
1444 return Qnil;
1448 /* Initialize bitmap bit.
1450 On X, we bit-swap the built-in bitmaps and reduce bitmap
1451 from short to char array if width is <= 8 bits.
1453 On MAC with big-endian CPU, we need to byte-swap each short.
1455 On W32 and MAC (little endian), there's no need to do this.
1458 #if defined (HAVE_X_WINDOWS)
1459 static const unsigned char swap_nibble[16] = {
1460 0x0, 0x8, 0x4, 0xc, /* 0000 1000 0100 1100 */
1461 0x2, 0xa, 0x6, 0xe, /* 0010 1010 0110 1110 */
1462 0x1, 0x9, 0x5, 0xd, /* 0001 1001 0101 1101 */
1463 0x3, 0xb, 0x7, 0xf}; /* 0011 1011 0111 1111 */
1464 #endif /* HAVE_X_WINDOWS */
1466 void
1467 init_fringe_bitmap (int which, struct fringe_bitmap *fb, int once_p)
1469 if (once_p || fb->dynamic)
1471 #if defined (HAVE_X_WINDOWS)
1472 unsigned short *bits = fb->bits;
1473 int j;
1475 if (fb->width <= 8)
1477 unsigned char *cbits = (unsigned char *)fb->bits;
1478 for (j = 0; j < fb->height; j++)
1480 unsigned short b = *bits++;
1481 unsigned char c;
1482 c = (unsigned char)((swap_nibble[b & 0xf] << 4)
1483 | (swap_nibble[(b>>4) & 0xf]));
1484 *cbits++ = (c >> (8 - fb->width));
1487 else
1489 for (j = 0; j < fb->height; j++)
1491 unsigned short b = *bits;
1492 b = (unsigned short)((swap_nibble[b & 0xf] << 12)
1493 | (swap_nibble[(b>>4) & 0xf] << 8)
1494 | (swap_nibble[(b>>8) & 0xf] << 4)
1495 | (swap_nibble[(b>>12) & 0xf]));
1496 b >>= (16 - fb->width);
1497 #ifdef WORDS_BIGENDIAN
1498 b = ((b >> 8) | (b << 8));
1499 #endif
1500 *bits++ = b;
1503 #endif /* HAVE_X_WINDOWS */
1507 if (!once_p)
1509 /* XXX Is SELECTED_FRAME OK here? */
1510 struct redisplay_interface *rif = FRAME_RIF (SELECTED_FRAME ());
1512 destroy_fringe_bitmap (which);
1514 if (rif && rif->define_fringe_bitmap)
1515 rif->define_fringe_bitmap (which, fb->bits, fb->height, fb->width);
1517 fringe_bitmaps[which] = fb;
1518 if (which >= max_used_fringe_bitmap)
1519 max_used_fringe_bitmap = which + 1;
1524 DEFUN ("define-fringe-bitmap", Fdefine_fringe_bitmap, Sdefine_fringe_bitmap,
1525 2, 5, 0,
1526 doc: /* Define fringe bitmap BITMAP from BITS of size HEIGHT x WIDTH.
1527 BITMAP is a symbol identifying the new fringe bitmap.
1528 BITS is either a string or a vector of integers.
1529 HEIGHT is height of bitmap. If HEIGHT is nil, use length of BITS.
1530 WIDTH must be an integer between 1 and 16, or nil which defaults to 8.
1531 Optional fifth arg ALIGN may be one of `top', `center', or `bottom',
1532 indicating the positioning of the bitmap relative to the rows where it
1533 is used; the default is to center the bitmap. Fifth arg may also be a
1534 list (ALIGN PERIODIC) where PERIODIC non-nil specifies that the bitmap
1535 should be repeated.
1536 If BITMAP already exists, the existing definition is replaced. */)
1537 (Lisp_Object bitmap, Lisp_Object bits, Lisp_Object height, Lisp_Object width, Lisp_Object align)
1539 int n, h, i, j;
1540 unsigned short *b;
1541 struct fringe_bitmap fb, *xfb;
1542 int fill1 = 0, fill2 = 0;
1544 CHECK_SYMBOL (bitmap);
1546 if (STRINGP (bits))
1547 h = SCHARS (bits);
1548 else if (VECTORP (bits))
1549 h = XVECTOR (bits)->size;
1550 else
1551 wrong_type_argument (Qsequencep, bits);
1553 if (NILP (height))
1554 fb.height = h;
1555 else
1557 CHECK_NUMBER (height);
1558 fb.height = min (XINT (height), 255);
1559 if (fb.height > h)
1561 fill1 = (fb.height - h) / 2;
1562 fill2 = fb.height - h - fill1;
1566 if (NILP (width))
1567 fb.width = 8;
1568 else
1570 CHECK_NUMBER (width);
1571 fb.width = min (XINT (width), 255);
1574 fb.period = 0;
1575 fb.align = ALIGN_BITMAP_CENTER;
1577 if (CONSP (align))
1579 Lisp_Object period = XCDR (align);
1580 if (CONSP (period))
1582 period = XCAR (period);
1583 if (!NILP (period))
1585 fb.period = fb.height;
1586 fb.height = 255;
1589 align = XCAR (align);
1591 if (EQ (align, Qtop))
1592 fb.align = ALIGN_BITMAP_TOP;
1593 else if (EQ (align, Qbottom))
1594 fb.align = ALIGN_BITMAP_BOTTOM;
1595 else if (!NILP (align) && !EQ (align, Qcenter))
1596 error ("Bad align argument");
1598 n = lookup_fringe_bitmap (bitmap);
1599 if (!n)
1601 if (max_used_fringe_bitmap < max_fringe_bitmaps)
1602 n = max_used_fringe_bitmap++;
1603 else
1605 for (n = MAX_STANDARD_FRINGE_BITMAPS;
1606 n < max_fringe_bitmaps;
1607 n++)
1608 if (fringe_bitmaps[n] == NULL)
1609 break;
1611 if (n == max_fringe_bitmaps)
1613 if ((max_fringe_bitmaps + 20) > MAX_FRINGE_BITMAPS)
1614 error ("No free fringe bitmap slots");
1616 i = max_fringe_bitmaps;
1617 max_fringe_bitmaps += 20;
1618 fringe_bitmaps
1619 = ((struct fringe_bitmap **)
1620 xrealloc (fringe_bitmaps, max_fringe_bitmaps * sizeof (struct fringe_bitmap *)));
1621 fringe_faces
1622 = (Lisp_Object *) xrealloc (fringe_faces, max_fringe_bitmaps * sizeof (Lisp_Object));
1624 for (; i < max_fringe_bitmaps; i++)
1626 fringe_bitmaps[i] = NULL;
1627 fringe_faces[i] = Qnil;
1632 Vfringe_bitmaps = Fcons (bitmap, Vfringe_bitmaps);
1633 Fput (bitmap, Qfringe, make_number (n));
1636 fb.dynamic = 1;
1638 xfb = (struct fringe_bitmap *) xmalloc (sizeof fb
1639 + fb.height * BYTES_PER_BITMAP_ROW);
1640 fb.bits = b = (unsigned short *) (xfb + 1);
1641 memset (b, 0, fb.height);
1643 j = 0;
1644 while (j < fb.height)
1646 for (i = 0; i < fill1 && j < fb.height; i++)
1647 b[j++] = 0;
1648 for (i = 0; i < h && j < fb.height; i++)
1650 Lisp_Object elt = Faref (bits, make_number (i));
1651 b[j++] = NUMBERP (elt) ? XINT (elt) : 0;
1653 for (i = 0; i < fill2 && j < fb.height; i++)
1654 b[j++] = 0;
1657 *xfb = fb;
1659 init_fringe_bitmap (n, xfb, 0);
1661 return bitmap;
1664 DEFUN ("set-fringe-bitmap-face", Fset_fringe_bitmap_face, Sset_fringe_bitmap_face,
1665 1, 2, 0,
1666 doc: /* Set face for fringe bitmap BITMAP to FACE.
1667 If FACE is nil, reset face to default fringe face. */)
1668 (Lisp_Object bitmap, Lisp_Object face)
1670 int n;
1671 int face_id;
1673 CHECK_SYMBOL (bitmap);
1674 n = lookup_fringe_bitmap (bitmap);
1675 if (!n)
1676 error ("Undefined fringe bitmap");
1678 if (!NILP (face))
1680 face_id = lookup_derived_face (SELECTED_FRAME (), face,
1681 FRINGE_FACE_ID, 1);
1682 if (face_id < 0)
1683 error ("No such face");
1686 fringe_faces[n] = face;
1688 return Qnil;
1691 DEFUN ("fringe-bitmaps-at-pos", Ffringe_bitmaps_at_pos, Sfringe_bitmaps_at_pos,
1692 0, 2, 0,
1693 doc: /* Return fringe bitmaps of row containing position POS in window WINDOW.
1694 If WINDOW is nil, use selected window. If POS is nil, use value of point
1695 in that window. Return value is a list (LEFT RIGHT OV), where LEFT
1696 is the symbol for the bitmap in the left fringe (or nil if no bitmap),
1697 RIGHT is similar for the right fringe, and OV is non-nil if there is an
1698 overlay arrow in the left fringe.
1699 Return nil if POS is not visible in WINDOW. */)
1700 (Lisp_Object pos, Lisp_Object window)
1702 struct window *w;
1703 struct glyph_row *row;
1704 int textpos;
1706 if (NILP (window))
1707 window = selected_window;
1708 CHECK_WINDOW (window);
1709 w = XWINDOW (window);
1711 if (!NILP (pos))
1713 CHECK_NUMBER_COERCE_MARKER (pos);
1714 textpos = XINT (pos);
1716 else if (w == XWINDOW (selected_window))
1717 textpos = PT;
1718 else
1719 textpos = XMARKER (w->pointm)->charpos;
1721 row = MATRIX_FIRST_TEXT_ROW (w->current_matrix);
1722 row = row_containing_pos (w, textpos, row, NULL, 0);
1723 if (row)
1724 return list3 (get_fringe_bitmap_name (row->left_fringe_bitmap),
1725 get_fringe_bitmap_name (row->right_fringe_bitmap),
1726 (row->overlay_arrow_bitmap == 0 ? Qnil
1727 : row->overlay_arrow_bitmap < 0 ? Qt
1728 : get_fringe_bitmap_name (row->overlay_arrow_bitmap)));
1729 else
1730 return Qnil;
1734 /***********************************************************************
1735 Initialization
1736 ***********************************************************************/
1738 void
1739 syms_of_fringe (void)
1741 Qtruncation = intern_c_string ("truncation");
1742 staticpro (&Qtruncation);
1743 Qcontinuation = intern_c_string ("continuation");
1744 staticpro (&Qcontinuation);
1745 Qoverlay_arrow = intern_c_string ("overlay-arrow");
1746 staticpro (&Qoverlay_arrow);
1747 Qempty_line = intern_c_string ("empty-line");
1748 staticpro (&Qempty_line);
1749 Qtop_bottom = intern_c_string ("top-bottom");
1750 staticpro (&Qtop_bottom);
1751 Qhollow_small = intern_c_string ("hollow-small");
1752 staticpro (&Qhollow_small);
1754 defsubr (&Sdestroy_fringe_bitmap);
1755 defsubr (&Sdefine_fringe_bitmap);
1756 defsubr (&Sfringe_bitmaps_at_pos);
1757 defsubr (&Sset_fringe_bitmap_face);
1759 DEFVAR_LISP ("overflow-newline-into-fringe", &Voverflow_newline_into_fringe,
1760 doc: /* *Non-nil means that newline may flow into the right fringe.
1761 This means that display lines which are exactly as wide as the window
1762 (not counting the final newline) will only occupy one screen line, by
1763 showing (or hiding) the final newline in the right fringe; when point
1764 is at the final newline, the cursor is shown in the right fringe.
1765 If nil, also continue lines which are exactly as wide as the window. */);
1766 Voverflow_newline_into_fringe = Qt;
1768 DEFVAR_LISP ("fringe-bitmaps", &Vfringe_bitmaps,
1769 doc: /* List of fringe bitmap symbols. */);
1770 Vfringe_bitmaps = Qnil;
1773 /* Garbage collection hook */
1775 void
1776 mark_fringe_data (void)
1778 int i;
1780 for (i = 0; i < max_fringe_bitmaps; i++)
1781 if (!NILP (fringe_faces[i]))
1782 mark_object (fringe_faces[i]);
1785 /* Initialize this module when Emacs starts. */
1787 void
1788 init_fringe_once (void)
1790 int bt;
1792 for (bt = NO_FRINGE_BITMAP + 1; bt < MAX_STANDARD_FRINGE_BITMAPS; bt++)
1793 init_fringe_bitmap(bt, &standard_bitmaps[bt], 1);
1796 void
1797 init_fringe (void)
1799 int i;
1801 max_fringe_bitmaps = MAX_STANDARD_FRINGE_BITMAPS + 20;
1803 fringe_bitmaps
1804 = (struct fringe_bitmap **) xmalloc (max_fringe_bitmaps * sizeof (struct fringe_bitmap *));
1805 fringe_faces
1806 = (Lisp_Object *) xmalloc (max_fringe_bitmaps * sizeof (Lisp_Object));
1808 for (i = 0; i < max_fringe_bitmaps; i++)
1810 fringe_bitmaps[i] = NULL;
1811 fringe_faces[i] = Qnil;
1815 #ifdef HAVE_NTGUI
1817 void
1818 w32_init_fringe (struct redisplay_interface *rif)
1820 int bt;
1822 if (!rif)
1823 return;
1825 for (bt = NO_FRINGE_BITMAP + 1; bt < MAX_STANDARD_FRINGE_BITMAPS; bt++)
1827 struct fringe_bitmap *fb = &standard_bitmaps[bt];
1828 rif->define_fringe_bitmap (bt, fb->bits, fb->height, fb->width);
1832 void
1833 w32_reset_fringes (void)
1835 /* Destroy row bitmaps. */
1836 int bt;
1837 struct redisplay_interface *rif = FRAME_RIF (SELECTED_FRAME ());
1839 if (!rif)
1840 return;
1842 for (bt = NO_FRINGE_BITMAP + 1; bt < max_used_fringe_bitmap; bt++)
1843 rif->destroy_fringe_bitmap (bt);
1846 #endif /* HAVE_NTGUI */
1848 #endif /* HAVE_WINDOW_SYSTEM */
1850 /* arch-tag: 04596920-43eb-473d-b319-82712338162d
1851 (do not change this comment) */