More xmalloc and related cleanup.
[bpt/emacs.git] / src / fringe.c
CommitLineData
6b61353c 1/* Fringe handling (split from xdisp.c).
acaf905b 2 Copyright (C) 1985-1988, 1993-1995, 1997-2012 Free Software Foundation, Inc.
6b61353c
KH
3
4This file is part of GNU Emacs.
5
9ec0b715 6GNU Emacs is free software: you can redistribute it and/or modify
6b61353c 7it under the terms of the GNU General Public License as published by
9ec0b715
GM
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
6b61353c
KH
10
11GNU Emacs is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
9ec0b715 17along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
6b61353c
KH
18
19#include <config.h>
20#include <stdio.h>
d7306fe6 21#include <setjmp.h>
6b61353c
KH
22
23#include "lisp.h"
24#include "frame.h"
25#include "window.h"
26#include "dispextern.h"
e5560ff7 27#include "character.h"
6b61353c
KH
28#include "buffer.h"
29#include "blockinput.h"
e581a466 30#include "termhooks.h"
6b61353c
KH
31
32#ifdef HAVE_WINDOW_SYSTEM
33
7840b332
KS
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
e4920bc9 39 Physical bitmaps specify the visual appearance of the bitmap,
7840b332
KS
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
955cbe7b
PE
68static Lisp_Object Qtruncation, Qcontinuation, Qoverlay_arrow;
69static Lisp_Object Qempty_line, Qtop_bottom;
70static Lisp_Object Qhollow_small;
6b61353c
KH
71
72enum fringe_bitmap_align
73{
74 ALIGN_BITMAP_CENTER = 0,
75 ALIGN_BITMAP_TOP,
76 ALIGN_BITMAP_BOTTOM
77};
78
79struct 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*/
7840b332 107static unsigned short question_mark_bits[] = {
6b61353c
KH
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*/
121static 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*/
136static 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*/
151static 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*/
166static unsigned short down_arrow_bits[] = {
167 0x18, 0x18, 0x18, 0x18, 0xff, 0x7e, 0x3c, 0x18};
168
6b61353c
KH
169/* Marker for continuation lines. */
170/*
171 ..xxxx..
172 .xxxxx..
173 xx......
174 xxx..x..
175 xxxxxx..
176 .xxxxx..
177 ..xxxx..
178 .xxxxx..
179*/
7840b332 180static unsigned short left_curly_arrow_bits[] = {
6b61353c
KH
181 0x3c, 0x7c, 0xc0, 0xe4, 0xfc, 0x7c, 0x3c, 0x7c};
182
7840b332 183/* Marker for continued lines. */
6b61353c 184/*
7840b332
KS
185 ..xxxx..
186 ..xxxxx.
187 ......xx
188 ..x..xxx
189 ..xxxxxx
190 ..xxxxx.
191 ..xxxx..
192 ..xxxxx.
6b61353c 193*/
7840b332
KS
194static unsigned short right_curly_arrow_bits[] = {
195 0x3c, 0x3e, 0x03, 0x27, 0x3f, 0x3e, 0x3c, 0x3e};
6b61353c 196
6b61353c
KH
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*/
7840b332 208static unsigned short left_triangle_bits[] = {
6b61353c 209 0x03, 0x0f, 0x1f, 0x3f, 0x3f, 0x1f, 0x0f, 0x03};
7840b332
KS
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*/
222static unsigned short right_triangle_bits[] = {
223 0xc0, 0xf0, 0xf8, 0xfc, 0xfc, 0xf8, 0xf0, 0xc0};
6b61353c
KH
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*/
236static 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*/
250static 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*/
264static 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*/
278static 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*/
294static 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*/
310static 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*/
7840b332 329static unsigned short filled_rectangle_bits[] = {
6b61353c
KH
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*/
7840b332 348static unsigned short hollow_rectangle_bits[] = {
6b61353c
KH
349 0xfe, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0xfe};
350
7840b332
KS
351/* Hollow square bitmap. */
352/*
353 .xxxxxx.
354 .x....x.
355 .x....x.
356 .x....x.
357 .x....x.
358 .xxxxxx.
359*/
360static 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*/
372static unsigned short filled_square_bits[] = {
373 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e};
374
6b61353c
KH
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*/
7840b332 391static unsigned short vertical_bar_bits[] = {
6b61353c
KH
392 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0};
393
68a33afa 394/* HBar cursor bitmap. A horizontal bar; 2 pixels high. */
6b61353c
KH
395/*
396 xxxxxxx.
397 xxxxxxx.
398*/
68a33afa 399static unsigned short horizontal_bar_bits[] = {
6b61353c
KH
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*/
7840b332 413static unsigned short empty_line_bits[] = {
6b61353c
KH
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
6b61353c
KH
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
7840b332
KS
428/* NOTE: The order of these bitmaps must match the sequence
429 used in fringe.el to define the corresponding symbols. */
430
ad9a7a06 431static struct fringe_bitmap standard_bitmaps[] =
6b61353c
KH
432{
433 { NULL, 0, 0, 0, 0, 0 }, /* NO_FRINGE_BITMAP */
7840b332 434 { FRBITS (question_mark_bits), 8, 0, ALIGN_BITMAP_CENTER, 0 },
6b61353c
KH
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 },
7840b332
KS
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 },
6b61353c
KH
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 },
7840b332
KS
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 },
6b61353c 452 { FRBITS (hollow_square_bits), 8, 0, ALIGN_BITMAP_CENTER, 0 },
7840b332 453 { FRBITS (vertical_bar_bits), 8, 0, ALIGN_BITMAP_CENTER, 0 },
68a33afa 454 { FRBITS (horizontal_bar_bits), 8, 0, ALIGN_BITMAP_BOTTOM, 0 },
7840b332 455 { FRBITS (empty_line_bits), 8, 3, ALIGN_BITMAP_TOP, 0 },
6b61353c
KH
456};
457
7840b332
KS
458#define NO_FRINGE_BITMAP 0
459#define UNDEF_FRINGE_BITMAP 1
5e617bc2 460#define MAX_STANDARD_FRINGE_BITMAPS (sizeof (standard_bitmaps)/sizeof (standard_bitmaps[0]))
7840b332 461
ad67849e 462static struct fringe_bitmap **fringe_bitmaps;
49ce2dbd 463static Lisp_Object *fringe_faces;
ad67849e 464static int max_fringe_bitmaps;
6b61353c 465
ad9a7a06
PE
466#ifndef HAVE_NS
467static
468#endif
edfda783 469int max_used_fringe_bitmap = MAX_STANDARD_FRINGE_BITMAPS;
6b61353c 470
4cce0ab7
KS
471
472/* Lookup bitmap number for symbol BITMAP.
473 Return 0 if not a bitmap. */
6b61353c
KH
474
475int
971de7fb 476lookup_fringe_bitmap (Lisp_Object bitmap)
7a2a85be 477{
d311d28c 478 EMACS_INT bn;
7a2a85be 479
4cce0ab7 480 bitmap = Fget (bitmap, Qfringe);
7a2a85be
KS
481 if (!INTEGERP (bitmap))
482 return 0;
483
484 bn = XINT (bitmap);
4cce0ab7
KS
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;
7a2a85be
KS
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
501static Lisp_Object
971de7fb 502get_fringe_bitmap_name (int bn)
7a2a85be
KS
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
e61124cd
YM
525/* Get fringe bitmap data for bitmap number BN. */
526
527static struct fringe_bitmap *
528get_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}
7a2a85be 539
6b61353c
KH
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
7840b332 547static void
971de7fb 548draw_fringe_bitmap_1 (struct window *w, struct glyph_row *row, int left_p, int overlay, int which)
6b61353c
KH
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;
5a874e95 555 int offset, header_line_height;
6b61353c 556
6b61353c
KH
557 p.overlay_p = (overlay & 1) == 1;
558 p.cursor_p = (overlay & 2) == 2;
559
560 if (which != NO_FRINGE_BITMAP)
561 {
5a874e95 562 offset = 0;
6b61353c
KH
563 }
564 else if (left_p)
565 {
566 which = row->left_fringe_bitmap;
567 face_id = row->left_fringe_face_id;
5a874e95 568 offset = row->left_fringe_offset;
6b61353c
KH
569 }
570 else
571 {
572 which = row->right_fringe_bitmap;
573 face_id = row->right_fringe_face_id;
5a874e95 574 offset = row->right_fringe_offset;
6b61353c
KH
575 }
576
577 if (face_id == DEFAULT_FACE_ID)
49ce2dbd 578 {
67aecef9
CY
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)
49ce2dbd
KS
583 face_id = FRINGE_FACE_ID;
584 }
6b61353c 585
e61124cd 586 fb = get_fringe_bitmap_data (which);
6b61353c
KH
587
588 period = fb->period;
589
590 /* Convert row to frame coordinates. */
5a874e95 591 p.y = WINDOW_TO_FRAME_PIXEL_Y (w, row->y) + offset;
6b61353c
KH
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;
5a874e95
YM
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 }
6b61353c
KH
613
614 p.face = FACE_FROM_ID (f, face_id);
615
616 if (p.face == NULL)
617 {
49ce2dbd
KS
618 /* This could happen after clearing face cache.
619 But it shouldn't happen anymore. ++kfs */
6b61353c
KH
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;
5a874e95
YM
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;
6b61353c
KH
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
5a874e95 641 if (p.wd < wd || p.y > p.by || p.y + p.h < p.by + p.ny)
6b61353c
KH
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. */
5a874e95 663 if (p.wd < wd || p.y > p.by || p.y + p.h < p.by + p.ny)
6b61353c
KH
664 {
665 p.bx = x;
666 p.nx = wd;
667 }
668 }
669
e581a466 670 FRAME_RIF (f)->draw_fringe_bitmap (w, row, &p);
6b61353c
KH
671}
672
7840b332 673static int
971de7fb 674get_logical_cursor_bitmap (struct window *w, Lisp_Object cursor)
7840b332
KS
675{
676 Lisp_Object cmap, bm = Qnil;
677
4b4deea2 678 if ((cmap = BVAR (XBUFFER (w->buffer), fringe_cursor_alist)), !NILP (cmap))
7840b332
KS
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 }
4b4deea2 688 if (EQ (cmap, BVAR (&buffer_defaults, fringe_cursor_alist)))
7840b332 689 return NO_FRINGE_BITMAP;
4b4deea2 690 bm = Fassq (cursor, BVAR (&buffer_defaults, fringe_cursor_alist));
7840b332
KS
691 if (!CONSP (bm) || ((bm = XCDR (bm)), NILP (bm)))
692 return NO_FRINGE_BITMAP;
693 return lookup_fringe_bitmap (bm);
694}
695
696static int
971de7fb 697get_logical_fringe_bitmap (struct window *w, Lisp_Object bitmap, int right_p, int partial_p)
7840b332
KS
698{
699 Lisp_Object cmap, bm1 = Qnil, bm2 = Qnil, bm;
d311d28c 700 EMACS_INT ln1 = 0, ln2 = 0;
7840b332
KS
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)
78edd3b7 709 (L R PL PR) -- use for left right partial-left partial-right
7840b332
KS
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
4b4deea2 715 if ((cmap = BVAR (XBUFFER (w->buffer), fringe_indicator_alist)), !NILP (cmap))
7840b332
KS
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
4b4deea2
TT
749 if (!EQ (cmap, BVAR (&buffer_defaults, fringe_indicator_alist))
750 && !NILP (BVAR (&buffer_defaults, fringe_indicator_alist)))
7840b332 751 {
4b4deea2 752 bm2 = Fassq (bitmap, BVAR (&buffer_defaults, fringe_indicator_alist));
7840b332
KS
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
6b61353c 796void
971de7fb 797draw_fringe_bitmap (struct window *w, struct glyph_row *row, int left_p)
6b61353c
KH
798{
799 int overlay = 0;
800
f951a506 801 if (left_p == row->reversed_p && row->cursor_in_fringe_p)
6b61353c 802 {
7840b332 803 Lisp_Object cursor = Qnil;
6b61353c
KH
804
805 switch (w->phys_cursor_type)
806 {
807 case HOLLOW_BOX_CURSOR:
7840b332
KS
808 if (row->visible_height >= STANDARD_BITMAP_HEIGHT (hollow_rectangle_bits))
809 cursor = Qhollow;
6b61353c 810 else
7840b332 811 cursor = Qhollow_small;
6b61353c
KH
812 break;
813 case FILLED_BOX_CURSOR:
7840b332 814 cursor = Qbox;
6b61353c
KH
815 break;
816 case BAR_CURSOR:
7840b332 817 cursor = Qbar;
6b61353c
KH
818 break;
819 case HBAR_CURSOR:
7840b332 820 cursor = Qhbar;
6b61353c
KH
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 }
7840b332 828 if (!NILP (cursor))
6b61353c 829 {
7840b332
KS
830 int bm = get_logical_cursor_bitmap (w, cursor);
831 if (bm != NO_FRINGE_BITMAP)
832 {
f951a506 833 draw_fringe_bitmap_1 (w, row, left_p, 2, bm);
7840b332
KS
834 overlay = EQ (cursor, Qbox) ? 3 : 1;
835 }
6b61353c
KH
836 }
837 }
838
839 draw_fringe_bitmap_1 (w, row, left_p, overlay, NO_FRINGE_BITMAP);
840
a8b34fae 841 if (left_p && row->overlay_arrow_bitmap != NO_FRINGE_BITMAP)
7dfa5c49 842 draw_fringe_bitmap_1 (w, row, 1, 1, row->overlay_arrow_bitmap);
6b61353c
KH
843}
844
845
846/* Draw fringe bitmaps for glyph row ROW on window W. Call this
847 function with input blocked. */
848
849void
971de7fb 850draw_row_fringe_bitmaps (struct window *w, struct glyph_row *row)
6b61353c 851{
a54e2c05 852 eassert (interrupt_input_blocked);
6b61353c
KH
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
11491cbb 867 update in redraw_fringe_bitmaps_p are drawn.
6b61353c 868
11491cbb
KS
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
877int
971de7fb 878draw_window_fringes (struct window *w, int no_fringe)
6b61353c
KH
879{
880 struct glyph_row *row;
881 int yb = window_text_bottom_y (w);
882 int nrows = w->current_matrix->nrows;
5a874e95 883 int y, rn;
11491cbb 884 int updated = 0;
6b61353c
KH
885
886 if (w->pseudo_window_p)
11491cbb
KS
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++;
6b61353c 894
5a874e95 895 for (y = w->vscroll, rn = 0, row = w->current_matrix->rows;
6b61353c
KH
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;
11491cbb 903 updated++;
6b61353c 904 }
11491cbb
KS
905
906 return updated;
6b61353c
KH
907}
908
909
910/* Recalculate the bitmaps to show in the fringes of window W.
4dadc129
KS
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. */
6b61353c
KH
914
915int
971de7fb 916update_window_fringes (struct window *w, int keep_current_p)
6b61353c
KH
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;
5797a7a0
KS
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;
7840b332
KS
927#define MAX_BITMAP_CACHE (8*4)
928 int bitmap_cache[MAX_BITMAP_CACHE];
5a874e95
YM
929 int top_ind_rn, bot_ind_rn;
930 int top_ind_min_y, bot_ind_max_y;
40714c53 931
ee7683eb 932 /* top_ind_rn is set to a nonnegative value whenever
40714c53
PE
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. */
4b1ec863 936 int top_row_ends_at_zv_p IF_LINT (= 0), bot_row_ends_at_zv_p IF_LINT (= 0);
6b61353c
KH
937
938 if (w->pseudo_window_p)
939 return 0;
940
941 if (!MINI_WINDOW_P (w)
4b4deea2 942 && (ind = BVAR (XBUFFER (w->buffer), indicate_buffer_boundaries), !NILP (ind)))
6b61353c 943 {
5797a7a0
KS
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 }
6b61353c 960 else
a208b89c
KS
961 /* Anything else means boundary on left and no arrows. */
962 boundary_top = boundary_bot = Qleft;
5797a7a0 963 }
6b61353c 964
5a874e95 965 top_ind_rn = bot_ind_rn = -1;
5797a7a0
KS
966 if (!NILP (ind))
967 {
5a874e95 968 for (y = w->vscroll, rn = 0;
6b61353c
KH
969 y < yb && rn < nrows;
970 y += row->height, ++rn)
971 {
6b61353c
KH
972 row = w->desired_matrix->rows + rn;
973 if (!row->enabled_p)
974 row = w->current_matrix->rows + rn;
975
6b61353c
KH
976 row->indicate_bob_p = row->indicate_top_line_p = 0;
977 row->indicate_eob_p = row->indicate_bottom_line_p = 0;
978
26a5d440
KS
979 if (!row->mode_line_p)
980 {
5a874e95 981 if (top_ind_rn < 0 && row->visible_height > 0)
26a5d440 982 {
18e1c39a
KS
983 if (MATRIX_ROW_START_CHARPOS (row) <= BUF_BEGV (XBUFFER (w->buffer))
984 && !MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w, row))
26a5d440
KS
985 row->indicate_bob_p = !NILP (boundary_top);
986 else
987 row->indicate_top_line_p = !NILP (arrow_top);
5a874e95 988 top_ind_rn = rn;
26a5d440 989 }
6b61353c 990
5a874e95 991 if (bot_ind_rn < 0)
26a5d440 992 {
18e1c39a
KS
993 if (MATRIX_ROW_END_CHARPOS (row) >= BUF_ZV (XBUFFER (w->buffer))
994 && !MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row))
5a874e95 995 row->indicate_eob_p = !NILP (boundary_bot), bot_ind_rn = rn;
26a5d440 996 else if (y + row->height >= yb)
5a874e95 997 row->indicate_bottom_line_p = !NILP (arrow_bot), bot_ind_rn = rn;
26a5d440
KS
998 }
999 }
6b61353c
KH
1000 }
1001 }
1002
4b4deea2 1003 empty_pos = BVAR (XBUFFER (w->buffer), indicate_empty_lines);
5797a7a0
KS
1004 if (!NILP (empty_pos) && !EQ (empty_pos, Qright))
1005 empty_pos = WINDOW_LEFT_FRINGE_WIDTH (w) == 0 ? Qright : Qleft;
6b61353c 1006
7840b332
KS
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
5a874e95
YM
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 {
e61124cd 1056 struct fringe_bitmap *fb = get_fringe_bitmap_data (bn);
5a874e95 1057
5a874e95
YM
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 {
e61124cd 1111 struct fringe_bitmap *fb = get_fringe_bitmap_data (bn);
5a874e95 1112
5a874e95
YM
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;
6b61353c
KH
1142 y < yb && rn < nrows;
1143 y += row->height, rn++)
1144 {
7840b332 1145 int left, right;
6b61353c 1146 unsigned left_face_id, right_face_id;
5a874e95 1147 int left_offset, right_offset;
e61124cd 1148 int periodic_p;
6b61353c
KH
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;
5a874e95 1156 left_offset = right_offset = 0;
e61124cd 1157 periodic_p = 0;
6b61353c
KH
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 }
96d79611
EZ
1167 else if ((!row->reversed_p && row->truncated_on_left_p)
1168 || (row->reversed_p && row->truncated_on_right_p))
5e617bc2 1169 left = LEFT_FRINGE (0, Qtruncation, 0);
5797a7a0 1170 else if (row->indicate_bob_p && EQ (boundary_top, Qleft))
5a874e95
YM
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 }
5797a7a0 1178 else if (row->indicate_eob_p && EQ (boundary_bot, Qleft))
5a874e95
YM
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 }
c4affd2c
EZ
1184 else if ((!row->reversed_p && MATRIX_ROW_CONTINUATION_LINE_P (row))
1185 || (row->reversed_p && row->continued_p))
7840b332 1186 left = LEFT_FRINGE (4, Qcontinuation, 0);
5797a7a0 1187 else if (row->indicate_empty_line_p && EQ (empty_pos, Qleft))
7840b332 1188 left = LEFT_FRINGE (5, Qempty_line, 0);
5797a7a0 1189 else if (row->indicate_top_line_p && EQ (arrow_top, Qleft))
5a874e95
YM
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 }
5797a7a0 1195 else if (row->indicate_bottom_line_p && EQ (arrow_bot, Qleft))
5a874e95
YM
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 }
6b61353c
KH
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 }
96d79611
EZ
1212 else if ((!row->reversed_p && row->truncated_on_right_p)
1213 || (row->reversed_p && row->truncated_on_left_p))
7840b332 1214 right = RIGHT_FRINGE (0, Qtruncation, 0);
5797a7a0 1215 else if (row->indicate_bob_p && EQ (boundary_top, Qright))
5a874e95
YM
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 }
5797a7a0 1223 else if (row->indicate_eob_p && EQ (boundary_bot, Qright))
5a874e95
YM
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 }
c4affd2c
EZ
1229 else if ((!row->reversed_p && row->continued_p)
1230 || (row->reversed_p && MATRIX_ROW_CONTINUATION_LINE_P (row)))
7840b332 1231 right = RIGHT_FRINGE (4, Qcontinuation, 0);
5797a7a0 1232 else if (row->indicate_top_line_p && EQ (arrow_top, Qright))
5a874e95
YM
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 }
5797a7a0 1238 else if (row->indicate_bottom_line_p && EQ (arrow_bot, Qright))
5a874e95
YM
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 }
5797a7a0 1244 else if (row->indicate_empty_line_p && EQ (empty_pos, Qright))
7840b332 1245 right = RIGHT_FRINGE (5, Qempty_line, 0);
6b61353c
KH
1246 else
1247 right = NO_FRINGE_BITMAP;
1248
e61124cd
YM
1249 periodic_p = (get_fringe_bitmap_data (left)->period != 0
1250 || get_fringe_bitmap_data (right)->period != 0);
1251
4dadc129 1252 if (row->y != cur->y
6b61353c 1253 || row->visible_height != cur->visible_height
81544a1d 1254 || row->ends_at_zv_p != cur->ends_at_zv_p
6b61353c
KH
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
5a874e95
YM
1259 || left_offset != cur->left_fringe_offset
1260 || right_offset != cur->right_fringe_offset
e61124cd 1261 || periodic_p != cur->fringe_bitmap_periodic_p
6b61353c
KH
1262 || cur->redraw_fringe_bitmaps_p)
1263 {
4dadc129
KS
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;
5a874e95
YM
1272 cur->left_fringe_offset = left_offset;
1273 cur->right_fringe_offset = right_offset;
e61124cd 1274 cur->fringe_bitmap_periodic_p = periodic_p;
4dadc129 1275 }
6b61353c
KH
1276 }
1277
7dfa5c49
KS
1278 if (row->overlay_arrow_bitmap < 0)
1279 row->overlay_arrow_bitmap = get_logical_fringe_bitmap (w, Qoverlay_arrow, 0, 0);
1280
a8b34fae 1281 if (row->overlay_arrow_bitmap != cur->overlay_arrow_bitmap)
6b61353c 1282 {
14eca62f
YM
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 }
6b61353c
KH
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;
5a874e95
YM
1295 row->left_fringe_offset = left_offset;
1296 row->right_fringe_offset = right_offset;
e61124cd 1297 row->fringe_bitmap_periodic_p = periodic_p;
6b61353c
KH
1298 }
1299
4dadc129 1300 return redraw_p && !keep_current_p;
6b61353c
KH
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
11491cbb 1314 We never make the fringes narrower than specified.
6b61353c
KH
1315*/
1316
1317void
971de7fb 1318compute_fringe_widths (struct frame *f, int redraw)
6b61353c
KH
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
7a2a85be 1396
4cce0ab7
KS
1397/* Free resources used by a user-defined bitmap. */
1398
bf60f616 1399static void
971de7fb 1400destroy_fringe_bitmap (int n)
6b61353c 1401{
6b61353c
KH
1402 struct fringe_bitmap **fbp;
1403
49ce2dbd 1404 fringe_faces[n] = Qnil;
6b61353c
KH
1405
1406 fbp = &fringe_bitmaps[n];
1407 if (*fbp && (*fbp)->dynamic)
1408 {
e581a466 1409 /* XXX Is SELECTED_FRAME OK here? */
04ccca97 1410 struct redisplay_interface *rif = FRAME_RIF (SELECTED_FRAME ());
f2be4fd0 1411 if (rif && rif->destroy_fringe_bitmap)
6b61353c
KH
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--;
7a2a85be
KS
1420}
1421
6b61353c 1422
7a2a85be
KS
1423DEFUN ("destroy-fringe-bitmap", Fdestroy_fringe_bitmap, Sdestroy_fringe_bitmap,
1424 1, 1, 0,
1425 doc: /* Destroy fringe bitmap BITMAP.
1426If BITMAP overrides a standard fringe bitmap, the original bitmap is restored. */)
5842a27b 1427 (Lisp_Object bitmap)
7a2a85be
KS
1428{
1429 int n;
7a2a85be 1430
4cce0ab7
KS
1431 CHECK_SYMBOL (bitmap);
1432 n = lookup_fringe_bitmap (bitmap);
1433 if (!n)
7a2a85be
KS
1434 return Qnil;
1435
1436 destroy_fringe_bitmap (n);
2d05deef 1437
4cce0ab7 1438 if (n >= MAX_STANDARD_FRINGE_BITMAPS)
7a2a85be 1439 {
4cce0ab7 1440 Vfringe_bitmaps = Fdelq (bitmap, Vfringe_bitmaps);
7a2a85be 1441 /* It would be better to remove the fringe property. */
4cce0ab7 1442 Fput (bitmap, Qfringe, Qnil);
7a2a85be 1443 }
4cce0ab7 1444
6b61353c
KH
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
2e4e5023 1459#if defined (HAVE_X_WINDOWS)
91433552 1460static const unsigned char swap_nibble[16] = {
2e4e5023
GM
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
bf60f616 1467static void
971de7fb 1468init_fringe_bitmap (int which, struct fringe_bitmap *fb, int once_p)
6b61353c
KH
1469{
1470 if (once_p || fb->dynamic)
1471 {
1472#if defined (HAVE_X_WINDOWS)
6b61353c
KH
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]));
4e8231f3 1497 b >>= (16 - fb->width);
671d409f 1498#ifdef WORDS_BIGENDIAN
4e8231f3
YM
1499 b = ((b >> 8) | (b << 8));
1500#endif
1501 *bits++ = b;
6b61353c
KH
1502 }
1503 }
1504#endif /* HAVE_X_WINDOWS */
1505
6b61353c
KH
1506 }
1507
1508 if (!once_p)
1509 {
e581a466 1510 /* XXX Is SELECTED_FRAME OK here? */
04ccca97 1511 struct redisplay_interface *rif = FRAME_RIF (SELECTED_FRAME ());
a284b538 1512
7a2a85be 1513 destroy_fringe_bitmap (which);
6b61353c 1514
f2be4fd0 1515 if (rif && rif->define_fringe_bitmap)
6b61353c
KH
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
1525DEFUN ("define-fringe-bitmap", Fdefine_fringe_bitmap, Sdefine_fringe_bitmap,
7a2a85be
KS
1526 2, 5, 0,
1527 doc: /* Define fringe bitmap BITMAP from BITS of size HEIGHT x WIDTH.
2faacff7 1528BITMAP is a symbol identifying the new fringe bitmap.
6b61353c
KH
1529BITS is either a string or a vector of integers.
1530HEIGHT is height of bitmap. If HEIGHT is nil, use length of BITS.
1531WIDTH must be an integer between 1 and 16, or nil which defaults to 8.
7a2a85be 1532Optional fifth arg ALIGN may be one of `top', `center', or `bottom',
6b61353c 1533indicating the positioning of the bitmap relative to the rows where it
6b72791f 1534is used; the default is to center the bitmap. Fifth arg may also be a
6b61353c
KH
1535list (ALIGN PERIODIC) where PERIODIC non-nil specifies that the bitmap
1536should be repeated.
7a2a85be 1537If BITMAP already exists, the existing definition is replaced. */)
5842a27b 1538 (Lisp_Object bitmap, Lisp_Object bits, Lisp_Object height, Lisp_Object width, Lisp_Object align)
6b61353c 1539{
6b61353c
KH
1540 int n, h, i, j;
1541 unsigned short *b;
1542 struct fringe_bitmap fb, *xfb;
1543 int fill1 = 0, fill2 = 0;
7a2a85be 1544
4cce0ab7 1545 CHECK_SYMBOL (bitmap);
6b61353c 1546
11e04b2d
KS
1547 if (STRINGP (bits))
1548 h = SCHARS (bits);
1549 else if (VECTORP (bits))
77b37c05 1550 h = ASIZE (bits);
11e04b2d 1551 else
7fee0b51 1552 wrong_type_argument (Qsequencep, bits);
6b61353c
KH
1553
1554 if (NILP (height))
11e04b2d 1555 fb.height = h;
6b61353c
KH
1556 else
1557 {
1558 CHECK_NUMBER (height);
d311d28c 1559 fb.height = max (0, min (XINT (height), 255));
11e04b2d 1560 if (fb.height > h)
6b61353c 1561 {
6b61353c
KH
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);
d311d28c 1572 fb.width = max (0, min (XINT (width), 255));
6b61353c
KH
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
ad67849e 1599 n = lookup_fringe_bitmap (bitmap);
4cce0ab7 1600 if (!n)
6b61353c 1601 {
ad67849e 1602 if (max_used_fringe_bitmap < max_fringe_bitmaps)
6b61353c
KH
1603 n = max_used_fringe_bitmap++;
1604 else
1605 {
1606 for (n = MAX_STANDARD_FRINGE_BITMAPS;
ad67849e 1607 n < max_fringe_bitmaps;
6b61353c
KH
1608 n++)
1609 if (fringe_bitmaps[n] == NULL)
1610 break;
ad67849e
KS
1611
1612 if (n == max_fringe_bitmaps)
1613 {
483a9e21
PE
1614 int bitmaps = max_fringe_bitmaps + 20;
1615 if (MAX_FRINGE_BITMAPS < bitmaps)
ad67849e
KS
1616 error ("No free fringe bitmap slots");
1617
1618 i = max_fringe_bitmaps;
38182d90
PE
1619 fringe_bitmaps = xrealloc (fringe_bitmaps,
1620 bitmaps * sizeof *fringe_bitmaps);
1621 fringe_faces = xrealloc (fringe_faces,
1622 bitmaps * sizeof *fringe_faces);
ad67849e 1623
483a9e21 1624 for (i = max_fringe_bitmaps; i < bitmaps; i++)
ad67849e
KS
1625 {
1626 fringe_bitmaps[i] = NULL;
49ce2dbd 1627 fringe_faces[i] = Qnil;
ad67849e 1628 }
483a9e21
PE
1629
1630 max_fringe_bitmaps = bitmaps;
ad67849e 1631 }
6b61353c 1632 }
7a2a85be 1633
4cce0ab7
KS
1634 Vfringe_bitmaps = Fcons (bitmap, Vfringe_bitmaps);
1635 Fput (bitmap, Qfringe, make_number (n));
6b61353c
KH
1636 }
1637
1638 fb.dynamic = 1;
1639
23f86fce 1640 xfb = xmalloc (sizeof fb + fb.height * BYTES_PER_BITMAP_ROW);
6b61353c 1641 fb.bits = b = (unsigned short *) (xfb + 1);
72af86bd 1642 memset (b, 0, fb.height);
6b61353c
KH
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
4cce0ab7 1662 return bitmap;
6b61353c
KH
1663}
1664
1665DEFUN ("set-fringe-bitmap-face", Fset_fringe_bitmap_face, Sset_fringe_bitmap_face,
1666 1, 2, 0,
7a2a85be 1667 doc: /* Set face for fringe bitmap BITMAP to FACE.
6b61353c 1668If FACE is nil, reset face to default fringe face. */)
5842a27b 1669 (Lisp_Object bitmap, Lisp_Object face)
6b61353c 1670{
4cce0ab7 1671 int n;
6b61353c 1672
4cce0ab7
KS
1673 CHECK_SYMBOL (bitmap);
1674 n = lookup_fringe_bitmap (bitmap);
1675 if (!n)
7a2a85be 1676 error ("Undefined fringe bitmap");
6b61353c 1677
44286096
CY
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). */
6b61353c
KH
1683 if (!NILP (face))
1684 {
44286096
CY
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)
6b61353c
KH
1689 error ("No such face");
1690 }
6b61353c 1691
49ce2dbd 1692 fringe_faces[n] = face;
6b61353c
KH
1693 return Qnil;
1694}
1695
1696DEFUN ("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.
1699If WINDOW is nil, use selected window. If POS is nil, use value of point
d3848fe9
KS
1700in that window. Return value is a list (LEFT RIGHT OV), where LEFT
1701is the symbol for the bitmap in the left fringe (or nil if no bitmap),
1702RIGHT is similar for the right fringe, and OV is non-nil if there is an
1703overlay arrow in the left fringe.
5797a7a0 1704Return nil if POS is not visible in WINDOW. */)
5842a27b 1705 (Lisp_Object pos, Lisp_Object window)
6b61353c
KH
1706{
1707 struct window *w;
6b61353c 1708 struct glyph_row *row;
d311d28c 1709 ptrdiff_t textpos;
6b61353c
KH
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);
d311d28c
PE
1719 if (! (BEGV <= XINT (pos) && XINT (pos) <= ZV))
1720 args_out_of_range (window, pos);
6b61353c
KH
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)
d3848fe9
KS
1731 return list3 (get_fringe_bitmap_name (row->left_fringe_bitmap),
1732 get_fringe_bitmap_name (row->right_fringe_bitmap),
a8b34fae
KS
1733 (row->overlay_arrow_bitmap == 0 ? Qnil
1734 : row->overlay_arrow_bitmap < 0 ? Qt
1735 : get_fringe_bitmap_name (row->overlay_arrow_bitmap)));
6b61353c
KH
1736 else
1737 return Qnil;
1738}
1739
1740
1741/***********************************************************************
1742 Initialization
1743 ***********************************************************************/
1744
1745void
971de7fb 1746syms_of_fringe (void)
6b61353c 1747{
cd3520a4
JB
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");
7840b332 1754
6b61353c
KH
1755 defsubr (&Sdestroy_fringe_bitmap);
1756 defsubr (&Sdefine_fringe_bitmap);
1757 defsubr (&Sfringe_bitmaps_at_pos);
1758 defsubr (&Sset_fringe_bitmap_face);
1759
29208e82 1760 DEFVAR_LISP ("overflow-newline-into-fringe", Voverflow_newline_into_fringe,
fb7ada5f 1761 doc: /* Non-nil means that newline may flow into the right fringe.
6b61353c
KH
1762This 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
1764showing (or hiding) the final newline in the right fringe; when point
1765is at the final newline, the cursor is shown in the right fringe.
1766If nil, also continue lines which are exactly as wide as the window. */);
1767 Voverflow_newline_into_fringe = Qt;
1768
29208e82 1769 DEFVAR_LISP ("fringe-bitmaps", Vfringe_bitmaps,
a4b7b036 1770 doc: /* List of fringe bitmap symbols. */);
7a2a85be 1771 Vfringe_bitmaps = Qnil;
6b61353c
KH
1772}
1773
49ce2dbd
KS
1774/* Garbage collection hook */
1775
1776void
971de7fb 1777mark_fringe_data (void)
49ce2dbd
KS
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
6b61353c
KH
1786/* Initialize this module when Emacs starts. */
1787
1788void
971de7fb 1789init_fringe_once (void)
6b61353c 1790{
7840b332 1791 int bt;
6b61353c
KH
1792
1793 for (bt = NO_FRINGE_BITMAP + 1; bt < MAX_STANDARD_FRINGE_BITMAPS; bt++)
5e617bc2 1794 init_fringe_bitmap (bt, &standard_bitmaps[bt], 1);
6b61353c
KH
1795}
1796
1797void
971de7fb 1798init_fringe (void)
6b61353c
KH
1799{
1800 int i;
1801
ad67849e
KS
1802 max_fringe_bitmaps = MAX_STANDARD_FRINGE_BITMAPS + 20;
1803
38182d90
PE
1804 fringe_bitmaps = xzalloc (max_fringe_bitmaps * sizeof *fringe_bitmaps);
1805 fringe_faces = xmalloc (max_fringe_bitmaps * sizeof *fringe_faces);
ad67849e
KS
1806
1807 for (i = 0; i < max_fringe_bitmaps; i++)
23f86fce 1808 fringe_faces[i] = Qnil;
6b61353c
KH
1809}
1810
9e2a2647 1811#ifdef HAVE_NTGUI
6b61353c
KH
1812
1813void
9e2a2647 1814w32_init_fringe (struct redisplay_interface *rif)
6b61353c 1815{
7840b332 1816 int bt;
6b61353c 1817
f2be4fd0
KS
1818 if (!rif)
1819 return;
1820
6b61353c
KH
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
1828void
7c3320d8 1829w32_reset_fringes (void)
6b61353c
KH
1830{
1831 /* Destroy row bitmaps. */
1832 int bt;
5c217767 1833 struct redisplay_interface *rif = FRAME_RIF (SELECTED_FRAME ());
6b61353c 1834
f2be4fd0
KS
1835 if (!rif)
1836 return;
1837
6b61353c
KH
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 */