1 /* Fringe handling (split from xdisp.c).
2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995, 1997,
3 1998, 1999, 2000, 2000, 2001, 2002, 2003, 2004,
4 2005 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 2, or (at your option)
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; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
29 #include "dispextern.h"
31 #include "blockinput.h"
32 #include "termhooks.h"
34 #ifdef HAVE_WINDOW_SYSTEM
36 extern Lisp_Object Qfringe
;
37 extern Lisp_Object Qtop
, Qbottom
, Qcenter
;
38 extern Lisp_Object Qup
, Qdown
, Qleft
, Qright
;
40 /* Non-nil means that newline may flow into the right fringe. */
42 Lisp_Object Voverflow_newline_into_fringe
;
44 /* List of known fringe bitmap symbols.
46 The fringe bitmap number is stored in the `fringe' property on
47 those symbols. Names for the built-in bitmaps are installed by
51 Lisp_Object Vfringe_bitmaps
;
53 enum fringe_bitmap_type
57 LEFT_TRUNCATION_BITMAP
,
58 RIGHT_TRUNCATION_BITMAP
,
61 CONTINUED_LINE_BITMAP
,
62 CONTINUATION_LINE_BITMAP
,
64 TOP_LEFT_ANGLE_BITMAP
,
65 TOP_RIGHT_ANGLE_BITMAP
,
66 BOTTOM_LEFT_ANGLE_BITMAP
,
67 BOTTOM_RIGHT_ANGLE_BITMAP
,
70 FILLED_BOX_CURSOR_BITMAP
,
71 HOLLOW_BOX_CURSOR_BITMAP
,
76 MAX_STANDARD_FRINGE_BITMAPS
79 enum fringe_bitmap_align
81 ALIGN_BITMAP_CENTER
= 0,
97 /***********************************************************************
99 ***********************************************************************/
101 /* Undefined bitmap. A question mark. */
114 static unsigned short unknown_bits
[] = {
115 0x3c, 0x7e, 0x7e, 0x0c, 0x18, 0x18, 0x00, 0x18, 0x18};
117 /* An arrow like this: `<-'. */
128 static unsigned short left_arrow_bits
[] = {
129 0x18, 0x30, 0x60, 0xfc, 0xfc, 0x60, 0x30, 0x18};
132 /* Right truncation arrow bitmap `->'. */
143 static unsigned short right_arrow_bits
[] = {
144 0x18, 0x0c, 0x06, 0x3f, 0x3f, 0x06, 0x0c, 0x18};
147 /* Up arrow bitmap. */
158 static unsigned short up_arrow_bits
[] = {
159 0x18, 0x3c, 0x7e, 0xff, 0x18, 0x18, 0x18, 0x18};
162 /* Down arrow bitmap. */
173 static unsigned short down_arrow_bits
[] = {
174 0x18, 0x18, 0x18, 0x18, 0xff, 0x7e, 0x3c, 0x18};
176 /* Marker for continued lines. */
187 static unsigned short continued_bits
[] = {
188 0x3c, 0x3e, 0x03, 0x27, 0x3f, 0x3e, 0x3c, 0x3e};
190 /* Marker for continuation lines. */
201 static unsigned short continuation_bits
[] = {
202 0x3c, 0x7c, 0xc0, 0xe4, 0xfc, 0x7c, 0x3c, 0x7c};
204 /* Overlay arrow bitmap. A triangular arrow. */
215 static unsigned short ov_bits
[] = {
216 0xc0, 0xf0, 0xf8, 0xfc, 0xfc, 0xf8, 0xf0, 0xc0};
219 /* Reverse Overlay arrow bitmap. A triangular arrow. */
230 static unsigned short rev_ov_bits
[] = {
231 0x03, 0x0f, 0x1f, 0x3f, 0x3f, 0x1f, 0x0f, 0x03};
234 /* First line bitmap. An top-left angle. */
245 static unsigned short top_left_angle_bits
[] = {
246 0xfc, 0xfc, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00};
248 /* First line bitmap. An right-up angle. */
259 static unsigned short top_right_angle_bits
[] = {
260 0x3f, 0x3f, 0x03, 0x03, 0x03, 0x03, 0x03, 0x00};
262 /* Last line bitmap. An left-down angle. */
273 static unsigned short bottom_left_angle_bits
[] = {
274 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xfc, 0xfc};
276 /* Last line bitmap. An right-down angle. */
287 static unsigned short bottom_right_angle_bits
[] = {
288 0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x3f, 0x3f};
290 /* First/last line bitmap. An left bracket. */
303 static unsigned short left_bracket_bits
[] = {
304 0xfc, 0xfc, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xfc, 0xfc};
306 /* First/last line bitmap. An right bracket. */
319 static unsigned short right_bracket_bits
[] = {
320 0x3f, 0x3f, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x3f, 0x3f};
322 /* Filled box cursor bitmap. A filled box; max 13 pixels high. */
338 static unsigned short filled_box_cursor_bits
[] = {
339 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe};
341 /* Hollow box cursor bitmap. A hollow box; max 13 pixels high. */
357 static unsigned short hollow_box_cursor_bits
[] = {
358 0xfe, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0xfe};
360 /* Bar cursor bitmap. A vertical bar; max 13 pixels high. */
376 static unsigned short bar_cursor_bits
[] = {
377 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0};
379 /* HBar cursor bitmap. A horisontal bar; 2 pixels high. */
384 static unsigned short hbar_cursor_bits
[] = {
388 /* Bitmap drawn to indicate lines not displaying text if
389 `indicate-empty-lines' is non-nil. */
398 static unsigned short zv_bits
[] = {
399 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
400 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
401 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
402 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
403 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
404 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
405 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00,
406 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x3c, 0x00};
408 /* Hollow square bitmap. */
417 static unsigned short hollow_square_bits
[] = {
418 0x7e, 0x42, 0x42, 0x42, 0x42, 0x7e};
421 #define BYTES_PER_BITMAP_ROW (sizeof (unsigned short))
422 #define STANDARD_BITMAP_HEIGHT(bits) (sizeof (bits)/BYTES_PER_BITMAP_ROW)
423 #define FRBITS(bits) bits, STANDARD_BITMAP_HEIGHT (bits)
425 struct fringe_bitmap standard_bitmaps
[MAX_STANDARD_FRINGE_BITMAPS
] =
427 { NULL
, 0, 0, 0, 0, 0 }, /* NO_FRINGE_BITMAP */
428 { FRBITS (unknown_bits
), 8, 0, ALIGN_BITMAP_CENTER
, 0 },
429 { FRBITS (left_arrow_bits
), 8, 0, ALIGN_BITMAP_CENTER
, 0 },
430 { FRBITS (right_arrow_bits
), 8, 0, ALIGN_BITMAP_CENTER
, 0 },
431 { FRBITS (up_arrow_bits
), 8, 0, ALIGN_BITMAP_TOP
, 0 },
432 { FRBITS (down_arrow_bits
), 8, 0, ALIGN_BITMAP_BOTTOM
, 0 },
433 { FRBITS (continued_bits
), 8, 0, ALIGN_BITMAP_CENTER
, 0 },
434 { FRBITS (continuation_bits
), 8, 0, ALIGN_BITMAP_CENTER
, 0 },
435 { FRBITS (ov_bits
), 8, 0, ALIGN_BITMAP_CENTER
, 0 },
436 { FRBITS (top_left_angle_bits
), 8, 0, ALIGN_BITMAP_TOP
, 0 },
437 { FRBITS (top_right_angle_bits
), 8, 0, ALIGN_BITMAP_TOP
, 0 },
438 { FRBITS (bottom_left_angle_bits
), 8, 0, ALIGN_BITMAP_BOTTOM
, 0 },
439 { FRBITS (bottom_right_angle_bits
), 8, 0, ALIGN_BITMAP_BOTTOM
, 0 },
440 { FRBITS (left_bracket_bits
), 8, 0, ALIGN_BITMAP_CENTER
, 0 },
441 { FRBITS (right_bracket_bits
), 8, 0, ALIGN_BITMAP_CENTER
, 0 },
442 { FRBITS (filled_box_cursor_bits
), 8, 0, ALIGN_BITMAP_CENTER
, 0 },
443 { FRBITS (hollow_box_cursor_bits
), 8, 0, ALIGN_BITMAP_CENTER
, 0 },
444 { FRBITS (hollow_square_bits
), 8, 0, ALIGN_BITMAP_CENTER
, 0 },
445 { FRBITS (bar_cursor_bits
), 8, 0, ALIGN_BITMAP_CENTER
, 0 },
446 { FRBITS (hbar_cursor_bits
), 8, 0, ALIGN_BITMAP_BOTTOM
, 0 },
447 { FRBITS (zv_bits
), 8, 3, ALIGN_BITMAP_TOP
, 0 },
450 static struct fringe_bitmap
**fringe_bitmaps
;
451 static Lisp_Object
*fringe_faces
;
452 static int max_fringe_bitmaps
;
454 static int max_used_fringe_bitmap
= MAX_STANDARD_FRINGE_BITMAPS
;
457 /* Lookup bitmap number for symbol BITMAP.
458 Return 0 if not a bitmap. */
461 lookup_fringe_bitmap (bitmap
)
466 bitmap
= Fget (bitmap
, Qfringe
);
467 if (!INTEGERP (bitmap
))
471 if (bn
> NO_FRINGE_BITMAP
472 && bn
< max_used_fringe_bitmap
473 && (bn
< MAX_STANDARD_FRINGE_BITMAPS
474 || fringe_bitmaps
[bn
] != NULL
))
480 /* Get fringe bitmap name for bitmap number BN.
482 Found by traversing Vfringe_bitmaps comparing BN to the
483 fringe property for each symbol.
485 Return BN if not found in Vfringe_bitmaps. */
488 get_fringe_bitmap_name (bn
)
494 /* Zero means no bitmap -- return nil. */
498 bitmaps
= Vfringe_bitmaps
;
499 num
= make_number (bn
);
501 while (CONSP (bitmaps
))
503 Lisp_Object bitmap
= XCAR (bitmaps
);
504 if (EQ (num
, Fget (bitmap
, Qfringe
)))
506 bitmaps
= XCDR (bitmaps
);
513 /* Draw the bitmap WHICH in one of the left or right fringes of
514 window W. ROW is the glyph row for which to display the bitmap; it
515 determines the vertical position at which the bitmap has to be
517 LEFT_P is 1 for left fringe, 0 for right fringe.
521 draw_fringe_bitmap_1 (w
, row
, left_p
, overlay
, which
)
523 struct glyph_row
*row
;
525 enum fringe_bitmap_type which
;
527 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
528 struct draw_fringe_bitmap_params p
;
529 struct fringe_bitmap
*fb
;
531 int face_id
= DEFAULT_FACE_ID
;
534 p
.overlay_p
= (overlay
& 1) == 1;
535 p
.cursor_p
= (overlay
& 2) == 2;
537 if (which
!= NO_FRINGE_BITMAP
)
542 which
= row
->left_fringe_bitmap
;
543 face_id
= row
->left_fringe_face_id
;
547 which
= row
->right_fringe_bitmap
;
548 face_id
= row
->right_fringe_face_id
;
551 if (face_id
== DEFAULT_FACE_ID
)
555 if ((face
= fringe_faces
[which
], NILP (face
))
556 || (face_id
= lookup_derived_face (f
, face
, 'A', FRINGE_FACE_ID
, 0),
558 face_id
= FRINGE_FACE_ID
;
561 fb
= fringe_bitmaps
[which
];
563 fb
= &standard_bitmaps
[which
< MAX_STANDARD_FRINGE_BITMAPS
564 ? which
: UNDEF_FRINGE_BITMAP
];
568 /* Convert row to frame coordinates. */
569 p
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
576 p
.dh
= (period
> 0 ? (p
.y
% period
) : 0);
578 /* Clip bitmap if too high. */
579 if (p
.h
> row
->height
)
582 p
.face
= FACE_FROM_ID (f
, face_id
);
586 /* This could happen after clearing face cache.
587 But it shouldn't happen anymore. ++kfs */
591 PREPARE_FACE_FOR_DISPLAY (f
, p
.face
);
593 /* Clear left fringe if no bitmap to draw or if bitmap doesn't fill
598 int wd
= WINDOW_LEFT_FRINGE_WIDTH (w
);
599 int x
= window_box_left (w
, (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
604 p
.x
= x
- p
.wd
- (wd
- p
.wd
) / 2;
606 if (p
.wd
< wd
|| row
->height
> p
.h
)
608 /* If W has a vertical border to its left, don't draw over it. */
609 wd
-= ((!WINDOW_LEFTMOST_P (w
)
610 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
618 int x
= window_box_right (w
,
619 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
622 int wd
= WINDOW_RIGHT_FRINGE_WIDTH (w
);
625 p
.x
= x
+ (wd
- p
.wd
) / 2;
626 /* Clear right fringe if no bitmap to draw of if bitmap doesn't fill
628 if (p
.wd
< wd
|| row
->height
> p
.h
)
637 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
639 p
.by
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
, row
->y
));
640 p
.ny
= row
->visible_height
;
643 /* Adjust y to the offset in the row to start drawing the bitmap. */
646 case ALIGN_BITMAP_CENTER
:
647 p
.y
+= (row
->height
- p
.h
) / 2;
649 case ALIGN_BITMAP_BOTTOM
:
651 p
.y
+= (row
->visible_height
- p
.h
);
653 case ALIGN_BITMAP_TOP
:
657 FRAME_RIF (f
)->draw_fringe_bitmap (w
, row
, &p
);
661 draw_fringe_bitmap (w
, row
, left_p
)
663 struct glyph_row
*row
;
668 if (!left_p
&& row
->cursor_in_fringe_p
)
670 int cursor
= NO_FRINGE_BITMAP
;
672 switch (w
->phys_cursor_type
)
674 case HOLLOW_BOX_CURSOR
:
675 if (row
->visible_height
>= STANDARD_BITMAP_HEIGHT (hollow_box_cursor_bits
))
676 cursor
= HOLLOW_BOX_CURSOR_BITMAP
;
678 cursor
= HOLLOW_SQUARE_BITMAP
;
680 case FILLED_BOX_CURSOR
:
681 cursor
= FILLED_BOX_CURSOR_BITMAP
;
684 cursor
= BAR_CURSOR_BITMAP
;
687 cursor
= HBAR_CURSOR_BITMAP
;
691 w
->phys_cursor_on_p
= 0;
692 row
->cursor_in_fringe_p
= 0;
695 if (cursor
!= NO_FRINGE_BITMAP
)
697 draw_fringe_bitmap_1 (w
, row
, 0, 2, cursor
);
698 overlay
= cursor
== FILLED_BOX_CURSOR_BITMAP
? 3 : 1;
702 draw_fringe_bitmap_1 (w
, row
, left_p
, overlay
, NO_FRINGE_BITMAP
);
704 if (left_p
&& row
->overlay_arrow_bitmap
!= NO_FRINGE_BITMAP
)
705 draw_fringe_bitmap_1 (w
, row
, 1, 1,
706 (row
->overlay_arrow_bitmap
< 0
707 ? OVERLAY_ARROW_BITMAP
708 : row
->overlay_arrow_bitmap
));
712 /* Draw fringe bitmaps for glyph row ROW on window W. Call this
713 function with input blocked. */
716 draw_row_fringe_bitmaps (w
, row
)
718 struct glyph_row
*row
;
720 xassert (interrupt_input_blocked
);
722 /* If row is completely invisible, because of vscrolling, we
723 don't have to draw anything. */
724 if (row
->visible_height
<= 0)
727 if (WINDOW_LEFT_FRINGE_WIDTH (w
) != 0)
728 draw_fringe_bitmap (w
, row
, 1);
730 if (WINDOW_RIGHT_FRINGE_WIDTH (w
) != 0)
731 draw_fringe_bitmap (w
, row
, 0);
734 /* Draw the fringes of window W. Only fringes for rows marked for
735 update in redraw_fringe_bitmaps_p are drawn.
737 Return >0 if left or right fringe was redrawn in any way.
739 If NO_FRINGE is non-zero, also return >0 if either fringe has zero width.
741 A return value >0 indicates that the vertical line between windows
742 needs update (as it may be drawn in the fringe).
746 draw_window_fringes (w
, no_fringe
)
750 struct glyph_row
*row
;
751 int yb
= window_text_bottom_y (w
);
752 int nrows
= w
->current_matrix
->nrows
;
756 if (w
->pseudo_window_p
)
759 /* Must draw line if no fringe */
761 && (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0
762 || WINDOW_RIGHT_FRINGE_WIDTH (w
) == 0))
765 for (y
= 0, rn
= 0, row
= w
->current_matrix
->rows
;
766 y
< yb
&& rn
< nrows
;
767 y
+= row
->height
, ++row
, ++rn
)
769 if (!row
->redraw_fringe_bitmaps_p
)
771 draw_row_fringe_bitmaps (w
, row
);
772 row
->redraw_fringe_bitmaps_p
= 0;
780 /* Recalculate the bitmaps to show in the fringes of window W.
781 Only mark rows with modified bitmaps for update in redraw_fringe_bitmaps_p.
783 If KEEP_CURRENT_P is 0, update current_matrix too. */
786 update_window_fringes (w
, keep_current_p
)
790 struct glyph_row
*row
, *cur
= 0;
791 int yb
= window_text_bottom_y (w
);
792 int rn
, nrows
= w
->current_matrix
->nrows
;
795 Lisp_Object boundary_top
= Qnil
, boundary_bot
= Qnil
;
796 Lisp_Object arrow_top
= Qnil
, arrow_bot
= Qnil
;
797 Lisp_Object empty_pos
;
798 Lisp_Object ind
= Qnil
;
800 if (w
->pseudo_window_p
)
803 if (!MINI_WINDOW_P (w
)
804 && (ind
= XBUFFER (w
->buffer
)->indicate_buffer_boundaries
, !NILP (ind
)))
806 if (EQ (ind
, Qleft
) || EQ (ind
, Qright
))
807 boundary_top
= boundary_bot
= arrow_top
= arrow_bot
= ind
;
808 else if (CONSP (ind
) && CONSP (XCAR (ind
)))
811 if (pos
= Fassq (Qt
, ind
), !NILP (pos
))
812 boundary_top
= boundary_bot
= arrow_top
= arrow_bot
= XCDR (pos
);
813 if (pos
= Fassq (Qtop
, ind
), !NILP (pos
))
814 boundary_top
= XCDR (pos
);
815 if (pos
= Fassq (Qbottom
, ind
), !NILP (pos
))
816 boundary_bot
= XCDR (pos
);
817 if (pos
= Fassq (Qup
, ind
), !NILP (pos
))
818 arrow_top
= XCDR (pos
);
819 if (pos
= Fassq (Qdown
, ind
), !NILP (pos
))
820 arrow_bot
= XCDR (pos
);
823 /* Anything else means boundary on left and no arrows. */
824 boundary_top
= boundary_bot
= Qleft
;
829 int done_top
= 0, done_bot
= 0;
832 y
< yb
&& rn
< nrows
;
833 y
+= row
->height
, ++rn
)
835 unsigned indicate_bob_p
, indicate_top_line_p
;
836 unsigned indicate_eob_p
, indicate_bottom_line_p
;
838 row
= w
->desired_matrix
->rows
+ rn
;
840 row
= w
->current_matrix
->rows
+ rn
;
842 indicate_bob_p
= row
->indicate_bob_p
;
843 indicate_top_line_p
= row
->indicate_top_line_p
;
844 indicate_eob_p
= row
->indicate_eob_p
;
845 indicate_bottom_line_p
= row
->indicate_bottom_line_p
;
847 row
->indicate_bob_p
= row
->indicate_top_line_p
= 0;
848 row
->indicate_eob_p
= row
->indicate_bottom_line_p
= 0;
850 if (!row
->mode_line_p
)
854 if (MATRIX_ROW_START_CHARPOS (row
) <= BUF_BEGV (XBUFFER (w
->buffer
))
855 && !MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w
, row
))
856 row
->indicate_bob_p
= !NILP (boundary_top
);
858 row
->indicate_top_line_p
= !NILP (arrow_top
);
864 if (MATRIX_ROW_END_CHARPOS (row
) >= BUF_ZV (XBUFFER (w
->buffer
))
865 && !MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w
, row
))
866 row
->indicate_eob_p
= !NILP (boundary_bot
), done_bot
= 1;
867 else if (y
+ row
->height
>= yb
)
868 row
->indicate_bottom_line_p
= !NILP (arrow_bot
), done_bot
= 1;
872 if (indicate_bob_p
!= row
->indicate_bob_p
873 || indicate_top_line_p
!= row
->indicate_top_line_p
874 || indicate_eob_p
!= row
->indicate_eob_p
875 || indicate_bottom_line_p
!= row
->indicate_bottom_line_p
)
876 row
->redraw_fringe_bitmaps_p
= 1;
880 empty_pos
= XBUFFER (w
->buffer
)->indicate_empty_lines
;
881 if (!NILP (empty_pos
) && !EQ (empty_pos
, Qright
))
882 empty_pos
= WINDOW_LEFT_FRINGE_WIDTH (w
) == 0 ? Qright
: Qleft
;
885 y
< yb
&& rn
< nrows
;
886 y
+= row
->height
, rn
++)
888 enum fringe_bitmap_type left
, right
;
889 unsigned left_face_id
, right_face_id
;
891 row
= w
->desired_matrix
->rows
+ rn
;
892 cur
= w
->current_matrix
->rows
+ rn
;
896 left_face_id
= right_face_id
= DEFAULT_FACE_ID
;
898 /* Decide which bitmap to draw in the left fringe. */
899 if (WINDOW_LEFT_FRINGE_WIDTH (w
) == 0)
900 left
= NO_FRINGE_BITMAP
;
901 else if (row
->left_user_fringe_bitmap
!= NO_FRINGE_BITMAP
)
903 left
= row
->left_user_fringe_bitmap
;
904 left_face_id
= row
->left_user_fringe_face_id
;
906 else if (row
->truncated_on_left_p
)
907 left
= LEFT_TRUNCATION_BITMAP
;
908 else if (row
->indicate_bob_p
&& EQ (boundary_top
, Qleft
))
909 left
= ((row
->indicate_eob_p
&& EQ (boundary_bot
, Qleft
))
911 ? TOP_RIGHT_ANGLE_BITMAP
: LEFT_BRACKET_BITMAP
)
912 : TOP_LEFT_ANGLE_BITMAP
);
913 else if (row
->indicate_eob_p
&& EQ (boundary_bot
, Qleft
))
914 left
= (row
->ends_at_zv_p
915 ? TOP_RIGHT_ANGLE_BITMAP
: BOTTOM_LEFT_ANGLE_BITMAP
);
916 else if (MATRIX_ROW_CONTINUATION_LINE_P (row
))
917 left
= CONTINUATION_LINE_BITMAP
;
918 else if (row
->indicate_empty_line_p
&& EQ (empty_pos
, Qleft
))
919 left
= ZV_LINE_BITMAP
;
920 else if (row
->indicate_top_line_p
&& EQ (arrow_top
, Qleft
))
921 left
= UP_ARROW_BITMAP
;
922 else if (row
->indicate_bottom_line_p
&& EQ (arrow_bot
, Qleft
))
923 left
= DOWN_ARROW_BITMAP
;
925 left
= NO_FRINGE_BITMAP
;
927 /* Decide which bitmap to draw in the right fringe. */
928 if (WINDOW_RIGHT_FRINGE_WIDTH (w
) == 0)
929 right
= NO_FRINGE_BITMAP
;
930 else if (row
->right_user_fringe_bitmap
!= NO_FRINGE_BITMAP
)
932 right
= row
->right_user_fringe_bitmap
;
933 right_face_id
= row
->right_user_fringe_face_id
;
935 else if (row
->truncated_on_right_p
)
936 right
= RIGHT_TRUNCATION_BITMAP
;
937 else if (row
->indicate_bob_p
&& EQ (boundary_top
, Qright
))
938 right
= ((row
->indicate_eob_p
&& EQ (boundary_bot
, Qright
))
940 ? TOP_LEFT_ANGLE_BITMAP
: RIGHT_BRACKET_BITMAP
)
941 : TOP_RIGHT_ANGLE_BITMAP
);
942 else if (row
->indicate_eob_p
&& EQ (boundary_bot
, Qright
))
943 right
= (row
->ends_at_zv_p
944 ? TOP_LEFT_ANGLE_BITMAP
: BOTTOM_RIGHT_ANGLE_BITMAP
);
945 else if (row
->continued_p
)
946 right
= CONTINUED_LINE_BITMAP
;
947 else if (row
->indicate_top_line_p
&& EQ (arrow_top
, Qright
))
948 right
= UP_ARROW_BITMAP
;
949 else if (row
->indicate_bottom_line_p
&& EQ (arrow_bot
, Qright
))
950 right
= DOWN_ARROW_BITMAP
;
951 else if (row
->indicate_empty_line_p
&& EQ (empty_pos
, Qright
))
952 right
= ZV_LINE_BITMAP
;
954 right
= NO_FRINGE_BITMAP
;
957 || row
->visible_height
!= cur
->visible_height
958 || row
->ends_at_zv_p
!= cur
->ends_at_zv_p
959 || left
!= cur
->left_fringe_bitmap
960 || right
!= cur
->right_fringe_bitmap
961 || left_face_id
!= cur
->left_fringe_face_id
962 || right_face_id
!= cur
->right_fringe_face_id
963 || cur
->redraw_fringe_bitmaps_p
)
965 redraw_p
= row
->redraw_fringe_bitmaps_p
= 1;
968 cur
->redraw_fringe_bitmaps_p
= 1;
969 cur
->left_fringe_bitmap
= left
;
970 cur
->right_fringe_bitmap
= right
;
971 cur
->left_fringe_face_id
= left_face_id
;
972 cur
->right_fringe_face_id
= right_face_id
;
976 if (row
->overlay_arrow_bitmap
!= cur
->overlay_arrow_bitmap
)
978 redraw_p
= row
->redraw_fringe_bitmaps_p
= cur
->redraw_fringe_bitmaps_p
= 1;
979 cur
->overlay_arrow_bitmap
= row
->overlay_arrow_bitmap
;
982 row
->left_fringe_bitmap
= left
;
983 row
->right_fringe_bitmap
= right
;
984 row
->left_fringe_face_id
= left_face_id
;
985 row
->right_fringe_face_id
= right_face_id
;
987 if (rn
> 0 && row
->redraw_fringe_bitmaps_p
)
988 row
[-1].redraw_fringe_bitmaps_p
= cur
[-1].redraw_fringe_bitmaps_p
= 1;
991 return redraw_p
&& !keep_current_p
;
995 /* Compute actual fringe widths for frame F.
997 If REDRAW is 1, redraw F if the fringe settings was actually
998 modified and F is visible.
1000 Since the combined left and right fringe must occupy an integral
1001 number of columns, we may need to add some pixels to each fringe.
1002 Typically, we add an equal amount (+/- 1 pixel) to each fringe,
1003 but a negative width value is taken literally (after negating it).
1005 We never make the fringes narrower than specified.
1009 compute_fringe_widths (f
, redraw
)
1013 int o_left
= FRAME_LEFT_FRINGE_WIDTH (f
);
1014 int o_right
= FRAME_RIGHT_FRINGE_WIDTH (f
);
1015 int o_cols
= FRAME_FRINGE_COLS (f
);
1017 Lisp_Object left_fringe
= Fassq (Qleft_fringe
, f
->param_alist
);
1018 Lisp_Object right_fringe
= Fassq (Qright_fringe
, f
->param_alist
);
1019 int left_fringe_width
, right_fringe_width
;
1021 if (!NILP (left_fringe
))
1022 left_fringe
= Fcdr (left_fringe
);
1023 if (!NILP (right_fringe
))
1024 right_fringe
= Fcdr (right_fringe
);
1026 left_fringe_width
= ((NILP (left_fringe
) || !INTEGERP (left_fringe
)) ? 8 :
1027 XINT (left_fringe
));
1028 right_fringe_width
= ((NILP (right_fringe
) || !INTEGERP (right_fringe
)) ? 8 :
1029 XINT (right_fringe
));
1031 if (left_fringe_width
|| right_fringe_width
)
1033 int left_wid
= left_fringe_width
>= 0 ? left_fringe_width
: -left_fringe_width
;
1034 int right_wid
= right_fringe_width
>= 0 ? right_fringe_width
: -right_fringe_width
;
1035 int conf_wid
= left_wid
+ right_wid
;
1036 int font_wid
= FRAME_COLUMN_WIDTH (f
);
1037 int cols
= (left_wid
+ right_wid
+ font_wid
-1) / font_wid
;
1038 int real_wid
= cols
* font_wid
;
1039 if (left_wid
&& right_wid
)
1041 if (left_fringe_width
< 0)
1043 /* Left fringe width is fixed, adjust right fringe if necessary */
1044 FRAME_LEFT_FRINGE_WIDTH (f
) = left_wid
;
1045 FRAME_RIGHT_FRINGE_WIDTH (f
) = real_wid
- left_wid
;
1047 else if (right_fringe_width
< 0)
1049 /* Right fringe width is fixed, adjust left fringe if necessary */
1050 FRAME_LEFT_FRINGE_WIDTH (f
) = real_wid
- right_wid
;
1051 FRAME_RIGHT_FRINGE_WIDTH (f
) = right_wid
;
1055 /* Adjust both fringes with an equal amount.
1056 Note that we are doing integer arithmetic here, so don't
1057 lose a pixel if the total width is an odd number. */
1058 int fill
= real_wid
- conf_wid
;
1059 FRAME_LEFT_FRINGE_WIDTH (f
) = left_wid
+ fill
/2;
1060 FRAME_RIGHT_FRINGE_WIDTH (f
) = right_wid
+ fill
- fill
/2;
1063 else if (left_fringe_width
)
1065 FRAME_LEFT_FRINGE_WIDTH (f
) = real_wid
;
1066 FRAME_RIGHT_FRINGE_WIDTH (f
) = 0;
1070 FRAME_LEFT_FRINGE_WIDTH (f
) = 0;
1071 FRAME_RIGHT_FRINGE_WIDTH (f
) = real_wid
;
1073 FRAME_FRINGE_COLS (f
) = cols
;
1077 FRAME_LEFT_FRINGE_WIDTH (f
) = 0;
1078 FRAME_RIGHT_FRINGE_WIDTH (f
) = 0;
1079 FRAME_FRINGE_COLS (f
) = 0;
1082 if (redraw
&& FRAME_VISIBLE_P (f
))
1083 if (o_left
!= FRAME_LEFT_FRINGE_WIDTH (f
) ||
1084 o_right
!= FRAME_RIGHT_FRINGE_WIDTH (f
) ||
1085 o_cols
!= FRAME_FRINGE_COLS (f
))
1090 /* Free resources used by a user-defined bitmap. */
1093 destroy_fringe_bitmap (n
)
1096 struct fringe_bitmap
**fbp
;
1098 fringe_faces
[n
] = Qnil
;
1100 fbp
= &fringe_bitmaps
[n
];
1101 if (*fbp
&& (*fbp
)->dynamic
)
1103 /* XXX Is SELECTED_FRAME OK here? */
1104 struct redisplay_interface
*rif
= FRAME_RIF (SELECTED_FRAME ());
1105 if (rif
&& rif
->destroy_fringe_bitmap
)
1106 rif
->destroy_fringe_bitmap (n
);
1111 while (max_used_fringe_bitmap
> MAX_STANDARD_FRINGE_BITMAPS
1112 && fringe_bitmaps
[max_used_fringe_bitmap
- 1] == NULL
)
1113 max_used_fringe_bitmap
--;
1117 DEFUN ("destroy-fringe-bitmap", Fdestroy_fringe_bitmap
, Sdestroy_fringe_bitmap
,
1119 doc
: /* Destroy fringe bitmap BITMAP.
1120 If BITMAP overrides a standard fringe bitmap, the original bitmap is restored. */)
1126 CHECK_SYMBOL (bitmap
);
1127 n
= lookup_fringe_bitmap (bitmap
);
1131 destroy_fringe_bitmap (n
);
1133 if (n
>= MAX_STANDARD_FRINGE_BITMAPS
)
1135 Vfringe_bitmaps
= Fdelq (bitmap
, Vfringe_bitmaps
);
1136 /* It would be better to remove the fringe property. */
1137 Fput (bitmap
, Qfringe
, Qnil
);
1144 /* Initialize bitmap bit.
1146 On X, we bit-swap the built-in bitmaps and reduce bitmap
1147 from short to char array if width is <= 8 bits.
1149 On MAC with big-endian CPU, we need to byte-swap each short.
1151 On W32 and MAC (little endian), there's no need to do this.
1155 init_fringe_bitmap (which
, fb
, once_p
)
1156 enum fringe_bitmap_type which
;
1157 struct fringe_bitmap
*fb
;
1160 if (once_p
|| fb
->dynamic
)
1162 #if defined (HAVE_X_WINDOWS)
1163 static unsigned char swap_nibble
[16]
1164 = { 0x0, 0x8, 0x4, 0xc, /* 0000 1000 0100 1100 */
1165 0x2, 0xa, 0x6, 0xe, /* 0010 1010 0110 1110 */
1166 0x1, 0x9, 0x5, 0xd, /* 0001 1001 0101 1101 */
1167 0x3, 0xb, 0x7, 0xf }; /* 0011 1011 0111 1111 */
1168 unsigned short *bits
= fb
->bits
;
1173 unsigned char *cbits
= (unsigned char *)fb
->bits
;
1174 for (j
= 0; j
< fb
->height
; j
++)
1176 unsigned short b
= *bits
++;
1178 c
= (unsigned char)((swap_nibble
[b
& 0xf] << 4)
1179 | (swap_nibble
[(b
>>4) & 0xf]));
1180 *cbits
++ = (c
>> (8 - fb
->width
));
1185 for (j
= 0; j
< fb
->height
; j
++)
1187 unsigned short b
= *bits
;
1188 b
= (unsigned short)((swap_nibble
[b
& 0xf] << 12)
1189 | (swap_nibble
[(b
>>4) & 0xf] << 8)
1190 | (swap_nibble
[(b
>>8) & 0xf] << 4)
1191 | (swap_nibble
[(b
>>12) & 0xf]));
1192 *bits
++ = (b
>> (16 - fb
->width
));
1195 #endif /* HAVE_X_WINDOWS */
1197 #if defined (MAC_OS) && defined (WORDS_BIG_ENDIAN)
1198 unsigned short *bits
= fb
->bits
;
1200 for (j
= 0; j
< fb
->height
; j
++)
1202 unsigned short b
= *bits
;
1203 *bits
++ = ((b
>> 8) & 0xff) | ((b
& 0xff) << 8);
1205 #endif /* MAC_OS && WORDS_BIG_ENDIAN */
1210 /* XXX Is SELECTED_FRAME OK here? */
1211 struct redisplay_interface
*rif
= FRAME_RIF (SELECTED_FRAME ());
1213 destroy_fringe_bitmap (which
);
1215 if (rif
&& rif
->define_fringe_bitmap
)
1216 rif
->define_fringe_bitmap (which
, fb
->bits
, fb
->height
, fb
->width
);
1218 fringe_bitmaps
[which
] = fb
;
1219 if (which
>= max_used_fringe_bitmap
)
1220 max_used_fringe_bitmap
= which
+ 1;
1225 DEFUN ("define-fringe-bitmap", Fdefine_fringe_bitmap
, Sdefine_fringe_bitmap
,
1227 doc
: /* Define fringe bitmap BITMAP from BITS of size HEIGHT x WIDTH.
1228 BITMAP is a symbol or string naming the new fringe bitmap.
1229 BITS is either a string or a vector of integers.
1230 HEIGHT is height of bitmap. If HEIGHT is nil, use length of BITS.
1231 WIDTH must be an integer between 1 and 16, or nil which defaults to 8.
1232 Optional fifth arg ALIGN may be one of `top', `center', or `bottom',
1233 indicating the positioning of the bitmap relative to the rows where it
1234 is used; the default is to center the bitmap. Fourth arg may also be a
1235 list (ALIGN PERIODIC) where PERIODIC non-nil specifies that the bitmap
1237 If BITMAP already exists, the existing definition is replaced. */)
1238 (bitmap
, bits
, height
, width
, align
)
1239 Lisp_Object bitmap
, bits
, height
, width
, align
;
1243 struct fringe_bitmap fb
, *xfb
;
1244 int fill1
= 0, fill2
= 0;
1246 CHECK_SYMBOL (bitmap
);
1250 else if (VECTORP (bits
))
1251 h
= XVECTOR (bits
)->size
;
1253 bits
= wrong_type_argument (Qsequencep
, bits
);
1259 CHECK_NUMBER (height
);
1260 fb
.height
= min (XINT (height
), 255);
1263 fill1
= (fb
.height
- h
) / 2;
1264 fill2
= fb
.height
- h
- fill1
;
1272 CHECK_NUMBER (width
);
1273 fb
.width
= min (XINT (width
), 255);
1277 fb
.align
= ALIGN_BITMAP_CENTER
;
1281 Lisp_Object period
= XCDR (align
);
1284 period
= XCAR (period
);
1287 fb
.period
= fb
.height
;
1291 align
= XCAR (align
);
1293 if (EQ (align
, Qtop
))
1294 fb
.align
= ALIGN_BITMAP_TOP
;
1295 else if (EQ (align
, Qbottom
))
1296 fb
.align
= ALIGN_BITMAP_BOTTOM
;
1297 else if (!NILP (align
) && !EQ (align
, Qcenter
))
1298 error ("Bad align argument");
1300 n
= lookup_fringe_bitmap (bitmap
);
1303 if (max_used_fringe_bitmap
< max_fringe_bitmaps
)
1304 n
= max_used_fringe_bitmap
++;
1307 for (n
= MAX_STANDARD_FRINGE_BITMAPS
;
1308 n
< max_fringe_bitmaps
;
1310 if (fringe_bitmaps
[n
] == NULL
)
1313 if (n
== max_fringe_bitmaps
)
1315 if ((max_fringe_bitmaps
+ 20) > MAX_FRINGE_BITMAPS
)
1316 error ("No free fringe bitmap slots");
1318 i
= max_fringe_bitmaps
;
1319 max_fringe_bitmaps
+= 20;
1321 = ((struct fringe_bitmap
**)
1322 xrealloc (fringe_bitmaps
, max_fringe_bitmaps
* sizeof (struct fringe_bitmap
*)));
1324 = (Lisp_Object
*) xrealloc (fringe_faces
, max_fringe_bitmaps
* sizeof (Lisp_Object
));
1326 for (; i
< max_fringe_bitmaps
; i
++)
1328 fringe_bitmaps
[i
] = NULL
;
1329 fringe_faces
[i
] = Qnil
;
1334 Vfringe_bitmaps
= Fcons (bitmap
, Vfringe_bitmaps
);
1335 Fput (bitmap
, Qfringe
, make_number (n
));
1340 xfb
= (struct fringe_bitmap
*) xmalloc (sizeof fb
1341 + fb
.height
* BYTES_PER_BITMAP_ROW
);
1342 fb
.bits
= b
= (unsigned short *) (xfb
+ 1);
1343 bzero (b
, fb
.height
);
1346 while (j
< fb
.height
)
1348 for (i
= 0; i
< fill1
&& j
< fb
.height
; i
++)
1350 for (i
= 0; i
< h
&& j
< fb
.height
; i
++)
1352 Lisp_Object elt
= Faref (bits
, make_number (i
));
1353 b
[j
++] = NUMBERP (elt
) ? XINT (elt
) : 0;
1355 for (i
= 0; i
< fill2
&& j
< fb
.height
; i
++)
1361 init_fringe_bitmap (n
, xfb
, 0);
1366 DEFUN ("set-fringe-bitmap-face", Fset_fringe_bitmap_face
, Sset_fringe_bitmap_face
,
1368 doc
: /* Set face for fringe bitmap BITMAP to FACE.
1369 If FACE is nil, reset face to default fringe face. */)
1371 Lisp_Object bitmap
, face
;
1376 CHECK_SYMBOL (bitmap
);
1377 n
= lookup_fringe_bitmap (bitmap
);
1379 error ("Undefined fringe bitmap");
1383 face_id
= lookup_derived_face (SELECTED_FRAME (), face
,
1384 'A', FRINGE_FACE_ID
, 1);
1386 error ("No such face");
1389 fringe_faces
[n
] = face
;
1394 DEFUN ("fringe-bitmaps-at-pos", Ffringe_bitmaps_at_pos
, Sfringe_bitmaps_at_pos
,
1396 doc
: /* Return fringe bitmaps of row containing position POS in window WINDOW.
1397 If WINDOW is nil, use selected window. If POS is nil, use value of point
1398 in that window. Return value is a list (LEFT RIGHT OV), where LEFT
1399 is the symbol for the bitmap in the left fringe (or nil if no bitmap),
1400 RIGHT is similar for the right fringe, and OV is non-nil if there is an
1401 overlay arrow in the left fringe.
1402 Return nil if POS is not visible in WINDOW. */)
1404 Lisp_Object pos
, window
;
1407 struct glyph_row
*row
;
1411 window
= selected_window
;
1412 CHECK_WINDOW (window
);
1413 w
= XWINDOW (window
);
1417 CHECK_NUMBER_COERCE_MARKER (pos
);
1418 textpos
= XINT (pos
);
1420 else if (w
== XWINDOW (selected_window
))
1423 textpos
= XMARKER (w
->pointm
)->charpos
;
1425 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
1426 row
= row_containing_pos (w
, textpos
, row
, NULL
, 0);
1428 return list3 (get_fringe_bitmap_name (row
->left_fringe_bitmap
),
1429 get_fringe_bitmap_name (row
->right_fringe_bitmap
),
1430 (row
->overlay_arrow_bitmap
== 0 ? Qnil
1431 : row
->overlay_arrow_bitmap
< 0 ? Qt
1432 : get_fringe_bitmap_name (row
->overlay_arrow_bitmap
)));
1438 /***********************************************************************
1440 ***********************************************************************/
1445 defsubr (&Sdestroy_fringe_bitmap
);
1446 defsubr (&Sdefine_fringe_bitmap
);
1447 defsubr (&Sfringe_bitmaps_at_pos
);
1448 defsubr (&Sset_fringe_bitmap_face
);
1450 DEFVAR_LISP ("overflow-newline-into-fringe", &Voverflow_newline_into_fringe
,
1451 doc
: /* *Non-nil means that newline may flow into the right fringe.
1452 This means that display lines which are exactly as wide as the window
1453 (not counting the final newline) will only occupy one screen line, by
1454 showing (or hiding) the final newline in the right fringe; when point
1455 is at the final newline, the cursor is shown in the right fringe.
1456 If nil, also continue lines which are exactly as wide as the window. */);
1457 Voverflow_newline_into_fringe
= Qt
;
1459 DEFVAR_LISP ("fringe-bitmaps", &Vfringe_bitmaps
,
1460 doc
: /* List of fringe bitmap symbols.
1461 You must (require 'fringe) to use fringe bitmap symbols in your programs." */);
1462 Vfringe_bitmaps
= Qnil
;
1465 /* Garbage collection hook */
1472 for (i
= 0; i
< max_fringe_bitmaps
; i
++)
1473 if (!NILP (fringe_faces
[i
]))
1474 mark_object (fringe_faces
[i
]);
1477 /* Initialize this module when Emacs starts. */
1482 enum fringe_bitmap_type bt
;
1484 for (bt
= NO_FRINGE_BITMAP
+ 1; bt
< MAX_STANDARD_FRINGE_BITMAPS
; bt
++)
1485 init_fringe_bitmap(bt
, &standard_bitmaps
[bt
], 1);
1493 max_fringe_bitmaps
= MAX_STANDARD_FRINGE_BITMAPS
+ 20;
1496 = (struct fringe_bitmap
**) xmalloc (max_fringe_bitmaps
* sizeof (struct fringe_bitmap
*));
1498 = (Lisp_Object
*) xmalloc (max_fringe_bitmaps
* sizeof (Lisp_Object
));
1500 for (i
= 0; i
< max_fringe_bitmaps
; i
++)
1502 fringe_bitmaps
[i
] = NULL
;
1503 fringe_faces
[i
] = Qnil
;
1512 enum fringe_bitmap_type bt
;
1517 for (bt
= NO_FRINGE_BITMAP
+ 1; bt
< MAX_STANDARD_FRINGE_BITMAPS
; bt
++)
1519 struct fringe_bitmap
*fb
= &standard_bitmaps
[bt
];
1520 rif
->define_fringe_bitmap (bt
, fb
->bits
, fb
->height
, fb
->width
);
1525 w32_reset_fringes ()
1527 /* Destroy row bitmaps. */
1533 for (bt
= NO_FRINGE_BITMAP
+ 1; bt
< max_used_fringe_bitmap
; bt
++)
1534 rif
->destroy_fringe_bitmap (bt
);
1537 #endif /* HAVE_NTGUI */
1539 #endif /* HAVE_WINDOW_SYSTEM */
1541 /* arch-tag: 04596920-43eb-473d-b319-82712338162d
1542 (do not change this comment) */