]> code.delx.au - gnu-emacs/blob - src/fringe.c
Merged from miles@gnu.org--gnu-2005 (patch 133-141, 596-609)
[gnu-emacs] / src / fringe.c
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.
5
6 This file is part of GNU Emacs.
7
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)
11 any later version.
12
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.
17
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. */
22
23 #include <config.h>
24 #include <stdio.h>
25
26 #include "lisp.h"
27 #include "frame.h"
28 #include "window.h"
29 #include "dispextern.h"
30 #include "buffer.h"
31 #include "blockinput.h"
32 #include "termhooks.h"
33
34 #ifdef HAVE_WINDOW_SYSTEM
35
36 extern Lisp_Object Qfringe;
37 extern Lisp_Object Qtop, Qbottom, Qcenter;
38 extern Lisp_Object Qup, Qdown, Qleft, Qright;
39
40 /* Non-nil means that newline may flow into the right fringe. */
41
42 Lisp_Object Voverflow_newline_into_fringe;
43
44 /* List of known fringe bitmap symbols.
45
46 The fringe bitmap number is stored in the `fringe' property on
47 those symbols. Names for the built-in bitmaps are installed by
48 loading fringe.el.
49 */
50
51 Lisp_Object Vfringe_bitmaps;
52
53 enum fringe_bitmap_type
54 {
55 NO_FRINGE_BITMAP = 0,
56 UNDEF_FRINGE_BITMAP,
57 LEFT_TRUNCATION_BITMAP,
58 RIGHT_TRUNCATION_BITMAP,
59 UP_ARROW_BITMAP,
60 DOWN_ARROW_BITMAP,
61 CONTINUED_LINE_BITMAP,
62 CONTINUATION_LINE_BITMAP,
63 OVERLAY_ARROW_BITMAP,
64 TOP_LEFT_ANGLE_BITMAP,
65 TOP_RIGHT_ANGLE_BITMAP,
66 BOTTOM_LEFT_ANGLE_BITMAP,
67 BOTTOM_RIGHT_ANGLE_BITMAP,
68 LEFT_BRACKET_BITMAP,
69 RIGHT_BRACKET_BITMAP,
70 FILLED_BOX_CURSOR_BITMAP,
71 HOLLOW_BOX_CURSOR_BITMAP,
72 HOLLOW_SQUARE_BITMAP,
73 BAR_CURSOR_BITMAP,
74 HBAR_CURSOR_BITMAP,
75 ZV_LINE_BITMAP,
76 MAX_STANDARD_FRINGE_BITMAPS
77 };
78
79 enum fringe_bitmap_align
80 {
81 ALIGN_BITMAP_CENTER = 0,
82 ALIGN_BITMAP_TOP,
83 ALIGN_BITMAP_BOTTOM
84 };
85
86 struct fringe_bitmap
87 {
88 unsigned short *bits;
89 unsigned height : 8;
90 unsigned width : 8;
91 unsigned period : 8;
92 unsigned align : 2;
93 unsigned dynamic : 1;
94 };
95
96 \f
97 /***********************************************************************
98 Fringe bitmaps
99 ***********************************************************************/
100
101 /* Undefined bitmap. A question mark. */
102 /*
103 ..xxxx..
104 .xxxxxx.
105 xx....xx
106 xx....xx
107 ....xx..
108 ...xx...
109 ...xx...
110 ........
111 ...xx...
112 ...xx...
113 */
114 static unsigned short unknown_bits[] = {
115 0x3c, 0x7e, 0x7e, 0x0c, 0x18, 0x18, 0x00, 0x18, 0x18};
116
117 /* An arrow like this: `<-'. */
118 /*
119 ...xx...
120 ..xx....
121 .xx.....
122 xxxxxx..
123 xxxxxx..
124 .xx.....
125 ..xx....
126 ...xx...
127 */
128 static unsigned short left_arrow_bits[] = {
129 0x18, 0x30, 0x60, 0xfc, 0xfc, 0x60, 0x30, 0x18};
130
131
132 /* Right truncation arrow bitmap `->'. */
133 /*
134 ...xx...
135 ....xx..
136 .....xx.
137 ..xxxxxx
138 ..xxxxxx
139 .....xx.
140 ....xx..
141 ...xx...
142 */
143 static unsigned short right_arrow_bits[] = {
144 0x18, 0x0c, 0x06, 0x3f, 0x3f, 0x06, 0x0c, 0x18};
145
146
147 /* Up arrow bitmap. */
148 /*
149 ...xx...
150 ..xxxx..
151 .xxxxxx.
152 xxxxxxxx
153 ...xx...
154 ...xx...
155 ...xx...
156 ...xx...
157 */
158 static unsigned short up_arrow_bits[] = {
159 0x18, 0x3c, 0x7e, 0xff, 0x18, 0x18, 0x18, 0x18};
160
161
162 /* Down arrow bitmap. */
163 /*
164 ...xx...
165 ...xx...
166 ...xx...
167 ...xx...
168 xxxxxxxx
169 .xxxxxx.
170 ..xxxx..
171 ...xx...
172 */
173 static unsigned short down_arrow_bits[] = {
174 0x18, 0x18, 0x18, 0x18, 0xff, 0x7e, 0x3c, 0x18};
175
176 /* Marker for continued lines. */
177 /*
178 ..xxxx..
179 ..xxxxx.
180 ......xx
181 ..x..xxx
182 ..xxxxxx
183 ..xxxxx.
184 ..xxxx..
185 ..xxxxx.
186 */
187 static unsigned short continued_bits[] = {
188 0x3c, 0x3e, 0x03, 0x27, 0x3f, 0x3e, 0x3c, 0x3e};
189
190 /* Marker for continuation lines. */
191 /*
192 ..xxxx..
193 .xxxxx..
194 xx......
195 xxx..x..
196 xxxxxx..
197 .xxxxx..
198 ..xxxx..
199 .xxxxx..
200 */
201 static unsigned short continuation_bits[] = {
202 0x3c, 0x7c, 0xc0, 0xe4, 0xfc, 0x7c, 0x3c, 0x7c};
203
204 /* Overlay arrow bitmap. A triangular arrow. */
205 /*
206 xx......
207 xxxx....
208 xxxxx...
209 xxxxxx..
210 xxxxxx..
211 xxxxx...
212 xxxx....
213 xx......
214 */
215 static unsigned short ov_bits[] = {
216 0xc0, 0xf0, 0xf8, 0xfc, 0xfc, 0xf8, 0xf0, 0xc0};
217
218 #if 0
219 /* Reverse Overlay arrow bitmap. A triangular arrow. */
220 /*
221 ......xx
222 ....xxxx
223 ...xxxxx
224 ..xxxxxx
225 ..xxxxxx
226 ...xxxxx
227 ....xxxx
228 ......xx
229 */
230 static unsigned short rev_ov_bits[] = {
231 0x03, 0x0f, 0x1f, 0x3f, 0x3f, 0x1f, 0x0f, 0x03};
232 #endif
233
234 /* First line bitmap. An top-left angle. */
235 /*
236 xxxxxx..
237 xxxxxx..
238 xx......
239 xx......
240 xx......
241 xx......
242 xx......
243 ........
244 */
245 static unsigned short top_left_angle_bits[] = {
246 0xfc, 0xfc, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00};
247
248 /* First line bitmap. An right-up angle. */
249 /*
250 ..xxxxxx
251 ..xxxxxx
252 ......xx
253 ......xx
254 ......xx
255 ......xx
256 ......xx
257 ........
258 */
259 static unsigned short top_right_angle_bits[] = {
260 0x3f, 0x3f, 0x03, 0x03, 0x03, 0x03, 0x03, 0x00};
261
262 /* Last line bitmap. An left-down angle. */
263 /*
264 ........
265 xx......
266 xx......
267 xx......
268 xx......
269 xx......
270 xxxxxx..
271 xxxxxx..
272 */
273 static unsigned short bottom_left_angle_bits[] = {
274 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xfc, 0xfc};
275
276 /* Last line bitmap. An right-down angle. */
277 /*
278 ........
279 ......xx
280 ......xx
281 ......xx
282 ......xx
283 ......xx
284 ..xxxxxx
285 ..xxxxxx
286 */
287 static unsigned short bottom_right_angle_bits[] = {
288 0x00, 0x03, 0x03, 0x03, 0x03, 0x03, 0x3f, 0x3f};
289
290 /* First/last line bitmap. An left bracket. */
291 /*
292 xxxxxx..
293 xxxxxx..
294 xx......
295 xx......
296 xx......
297 xx......
298 xx......
299 xx......
300 xxxxxx..
301 xxxxxx..
302 */
303 static unsigned short left_bracket_bits[] = {
304 0xfc, 0xfc, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xfc, 0xfc};
305
306 /* First/last line bitmap. An right bracket. */
307 /*
308 ..xxxxxx
309 ..xxxxxx
310 ......xx
311 ......xx
312 ......xx
313 ......xx
314 ......xx
315 ......xx
316 ..xxxxxx
317 ..xxxxxx
318 */
319 static unsigned short right_bracket_bits[] = {
320 0x3f, 0x3f, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x3f, 0x3f};
321
322 /* Filled box cursor bitmap. A filled box; max 13 pixels high. */
323 /*
324 xxxxxxx.
325 xxxxxxx.
326 xxxxxxx.
327 xxxxxxx.
328 xxxxxxx.
329 xxxxxxx.
330 xxxxxxx.
331 xxxxxxx.
332 xxxxxxx.
333 xxxxxxx.
334 xxxxxxx.
335 xxxxxxx.
336 xxxxxxx.
337 */
338 static unsigned short filled_box_cursor_bits[] = {
339 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe};
340
341 /* Hollow box cursor bitmap. A hollow box; max 13 pixels high. */
342 /*
343 xxxxxxx.
344 x.....x.
345 x.....x.
346 x.....x.
347 x.....x.
348 x.....x.
349 x.....x.
350 x.....x.
351 x.....x.
352 x.....x.
353 x.....x.
354 x.....x.
355 xxxxxxx.
356 */
357 static unsigned short hollow_box_cursor_bits[] = {
358 0xfe, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0xfe};
359
360 /* Bar cursor bitmap. A vertical bar; max 13 pixels high. */
361 /*
362 xx......
363 xx......
364 xx......
365 xx......
366 xx......
367 xx......
368 xx......
369 xx......
370 xx......
371 xx......
372 xx......
373 xx......
374 xx......
375 */
376 static unsigned short bar_cursor_bits[] = {
377 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0};
378
379 /* HBar cursor bitmap. A horisontal bar; 2 pixels high. */
380 /*
381 xxxxxxx.
382 xxxxxxx.
383 */
384 static unsigned short hbar_cursor_bits[] = {
385 0xfe, 0xfe};
386
387
388 /* Bitmap drawn to indicate lines not displaying text if
389 `indicate-empty-lines' is non-nil. */
390 /*
391 ........
392 ..xxxx..
393 ........
394 ........
395 ..xxxx..
396 ........
397 */
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};
407
408 /* Hollow square bitmap. */
409 /*
410 .xxxxxx.
411 .x....x.
412 .x....x.
413 .x....x.
414 .x....x.
415 .xxxxxx.
416 */
417 static unsigned short hollow_square_bits[] = {
418 0x7e, 0x42, 0x42, 0x42, 0x42, 0x7e};
419
420
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)
424
425 struct fringe_bitmap standard_bitmaps[MAX_STANDARD_FRINGE_BITMAPS] =
426 {
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 },
448 };
449
450 static struct fringe_bitmap **fringe_bitmaps;
451 static Lisp_Object *fringe_faces;
452 static int max_fringe_bitmaps;
453
454 static int max_used_fringe_bitmap = MAX_STANDARD_FRINGE_BITMAPS;
455
456
457 /* Lookup bitmap number for symbol BITMAP.
458 Return 0 if not a bitmap. */
459
460 int
461 lookup_fringe_bitmap (bitmap)
462 Lisp_Object bitmap;
463 {
464 int bn;
465
466 bitmap = Fget (bitmap, Qfringe);
467 if (!INTEGERP (bitmap))
468 return 0;
469
470 bn = XINT (bitmap);
471 if (bn > NO_FRINGE_BITMAP
472 && bn < max_used_fringe_bitmap
473 && (bn < MAX_STANDARD_FRINGE_BITMAPS
474 || fringe_bitmaps[bn] != NULL))
475 return bn;
476
477 return 0;
478 }
479
480 /* Get fringe bitmap name for bitmap number BN.
481
482 Found by traversing Vfringe_bitmaps comparing BN to the
483 fringe property for each symbol.
484
485 Return BN if not found in Vfringe_bitmaps. */
486
487 static Lisp_Object
488 get_fringe_bitmap_name (bn)
489 int bn;
490 {
491 Lisp_Object bitmaps;
492 Lisp_Object num;
493
494 /* Zero means no bitmap -- return nil. */
495 if (bn <= 0)
496 return Qnil;
497
498 bitmaps = Vfringe_bitmaps;
499 num = make_number (bn);
500
501 while (CONSP (bitmaps))
502 {
503 Lisp_Object bitmap = XCAR (bitmaps);
504 if (EQ (num, Fget (bitmap, Qfringe)))
505 return bitmap;
506 bitmaps = XCDR (bitmaps);
507 }
508
509 return num;
510 }
511
512
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
516 drawn.
517 LEFT_P is 1 for left fringe, 0 for right fringe.
518 */
519
520 void
521 draw_fringe_bitmap_1 (w, row, left_p, overlay, which)
522 struct window *w;
523 struct glyph_row *row;
524 int left_p, overlay;
525 enum fringe_bitmap_type which;
526 {
527 struct frame *f = XFRAME (WINDOW_FRAME (w));
528 struct draw_fringe_bitmap_params p;
529 struct fringe_bitmap *fb;
530 int period;
531 int face_id = DEFAULT_FACE_ID;
532
533 p.cursor_p = 0;
534 p.overlay_p = (overlay & 1) == 1;
535 p.cursor_p = (overlay & 2) == 2;
536
537 if (which != NO_FRINGE_BITMAP)
538 {
539 }
540 else if (left_p)
541 {
542 which = row->left_fringe_bitmap;
543 face_id = row->left_fringe_face_id;
544 }
545 else
546 {
547 which = row->right_fringe_bitmap;
548 face_id = row->right_fringe_face_id;
549 }
550
551 if (face_id == DEFAULT_FACE_ID)
552 {
553 Lisp_Object face;
554
555 if ((face = fringe_faces[which], NILP (face))
556 || (face_id = lookup_derived_face (f, face, 'A', FRINGE_FACE_ID, 0),
557 face_id < 0))
558 face_id = FRINGE_FACE_ID;
559 }
560
561 fb = fringe_bitmaps[which];
562 if (fb == NULL)
563 fb = &standard_bitmaps[which < MAX_STANDARD_FRINGE_BITMAPS
564 ? which : UNDEF_FRINGE_BITMAP];
565
566 period = fb->period;
567
568 /* Convert row to frame coordinates. */
569 p.y = WINDOW_TO_FRAME_PIXEL_Y (w, row->y);
570
571 p.which = which;
572 p.bits = fb->bits;
573 p.wd = fb->width;
574
575 p.h = fb->height;
576 p.dh = (period > 0 ? (p.y % period) : 0);
577 p.h -= p.dh;
578 /* Clip bitmap if too high. */
579 if (p.h > row->height)
580 p.h = row->height;
581
582 p.face = FACE_FROM_ID (f, face_id);
583
584 if (p.face == NULL)
585 {
586 /* This could happen after clearing face cache.
587 But it shouldn't happen anymore. ++kfs */
588 return;
589 }
590
591 PREPARE_FACE_FOR_DISPLAY (f, p.face);
592
593 /* Clear left fringe if no bitmap to draw or if bitmap doesn't fill
594 the fringe. */
595 p.bx = -1;
596 if (left_p)
597 {
598 int wd = WINDOW_LEFT_FRINGE_WIDTH (w);
599 int x = window_box_left (w, (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w)
600 ? LEFT_MARGIN_AREA
601 : TEXT_AREA));
602 if (p.wd > wd)
603 p.wd = wd;
604 p.x = x - p.wd - (wd - p.wd) / 2;
605
606 if (p.wd < wd || row->height > p.h)
607 {
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))
611 ? 1 : 0);
612 p.bx = x - wd;
613 p.nx = wd;
614 }
615 }
616 else
617 {
618 int x = window_box_right (w,
619 (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w)
620 ? RIGHT_MARGIN_AREA
621 : TEXT_AREA));
622 int wd = WINDOW_RIGHT_FRINGE_WIDTH (w);
623 if (p.wd > wd)
624 p.wd = wd;
625 p.x = x + (wd - p.wd) / 2;
626 /* Clear right fringe if no bitmap to draw of if bitmap doesn't fill
627 the fringe. */
628 if (p.wd < wd || row->height > p.h)
629 {
630 p.bx = x;
631 p.nx = wd;
632 }
633 }
634
635 if (p.bx >= 0)
636 {
637 int header_line_height = WINDOW_HEADER_LINE_HEIGHT (w);
638
639 p.by = WINDOW_TO_FRAME_PIXEL_Y (w, max (header_line_height, row->y));
640 p.ny = row->visible_height;
641 }
642
643 /* Adjust y to the offset in the row to start drawing the bitmap. */
644 switch (fb->align)
645 {
646 case ALIGN_BITMAP_CENTER:
647 p.y += (row->height - p.h) / 2;
648 break;
649 case ALIGN_BITMAP_BOTTOM:
650 p.h = fb->height;
651 p.y += (row->visible_height - p.h);
652 break;
653 case ALIGN_BITMAP_TOP:
654 break;
655 }
656
657 FRAME_RIF (f)->draw_fringe_bitmap (w, row, &p);
658 }
659
660 void
661 draw_fringe_bitmap (w, row, left_p)
662 struct window *w;
663 struct glyph_row *row;
664 int left_p;
665 {
666 int overlay = 0;
667
668 if (!left_p && row->cursor_in_fringe_p)
669 {
670 int cursor = NO_FRINGE_BITMAP;
671
672 switch (w->phys_cursor_type)
673 {
674 case HOLLOW_BOX_CURSOR:
675 if (row->visible_height >= STANDARD_BITMAP_HEIGHT (hollow_box_cursor_bits))
676 cursor = HOLLOW_BOX_CURSOR_BITMAP;
677 else
678 cursor = HOLLOW_SQUARE_BITMAP;
679 break;
680 case FILLED_BOX_CURSOR:
681 cursor = FILLED_BOX_CURSOR_BITMAP;
682 break;
683 case BAR_CURSOR:
684 cursor = BAR_CURSOR_BITMAP;
685 break;
686 case HBAR_CURSOR:
687 cursor = HBAR_CURSOR_BITMAP;
688 break;
689 case NO_CURSOR:
690 default:
691 w->phys_cursor_on_p = 0;
692 row->cursor_in_fringe_p = 0;
693 break;
694 }
695 if (cursor != NO_FRINGE_BITMAP)
696 {
697 draw_fringe_bitmap_1 (w, row, 0, 2, cursor);
698 overlay = cursor == FILLED_BOX_CURSOR_BITMAP ? 3 : 1;
699 }
700 }
701
702 draw_fringe_bitmap_1 (w, row, left_p, overlay, NO_FRINGE_BITMAP);
703
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));
709 }
710
711
712 /* Draw fringe bitmaps for glyph row ROW on window W. Call this
713 function with input blocked. */
714
715 void
716 draw_row_fringe_bitmaps (w, row)
717 struct window *w;
718 struct glyph_row *row;
719 {
720 xassert (interrupt_input_blocked);
721
722 /* If row is completely invisible, because of vscrolling, we
723 don't have to draw anything. */
724 if (row->visible_height <= 0)
725 return;
726
727 if (WINDOW_LEFT_FRINGE_WIDTH (w) != 0)
728 draw_fringe_bitmap (w, row, 1);
729
730 if (WINDOW_RIGHT_FRINGE_WIDTH (w) != 0)
731 draw_fringe_bitmap (w, row, 0);
732 }
733
734 /* Draw the fringes of window W. Only fringes for rows marked for
735 update in redraw_fringe_bitmaps_p are drawn.
736
737 Return >0 if left or right fringe was redrawn in any way.
738
739 If NO_FRINGE is non-zero, also return >0 if either fringe has zero width.
740
741 A return value >0 indicates that the vertical line between windows
742 needs update (as it may be drawn in the fringe).
743 */
744
745 int
746 draw_window_fringes (w, no_fringe)
747 struct window *w;
748 int no_fringe;
749 {
750 struct glyph_row *row;
751 int yb = window_text_bottom_y (w);
752 int nrows = w->current_matrix->nrows;
753 int y = 0, rn;
754 int updated = 0;
755
756 if (w->pseudo_window_p)
757 return 0;
758
759 /* Must draw line if no fringe */
760 if (no_fringe
761 && (WINDOW_LEFT_FRINGE_WIDTH (w) == 0
762 || WINDOW_RIGHT_FRINGE_WIDTH (w) == 0))
763 updated++;
764
765 for (y = 0, rn = 0, row = w->current_matrix->rows;
766 y < yb && rn < nrows;
767 y += row->height, ++row, ++rn)
768 {
769 if (!row->redraw_fringe_bitmaps_p)
770 continue;
771 draw_row_fringe_bitmaps (w, row);
772 row->redraw_fringe_bitmaps_p = 0;
773 updated++;
774 }
775
776 return updated;
777 }
778
779
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.
782
783 If KEEP_CURRENT_P is 0, update current_matrix too. */
784
785 int
786 update_window_fringes (w, keep_current_p)
787 struct window *w;
788 int keep_current_p;
789 {
790 struct glyph_row *row, *cur = 0;
791 int yb = window_text_bottom_y (w);
792 int rn, nrows = w->current_matrix->nrows;
793 int y;
794 int redraw_p = 0;
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;
799
800 if (w->pseudo_window_p)
801 return 0;
802
803 if (!MINI_WINDOW_P (w)
804 && (ind = XBUFFER (w->buffer)->indicate_buffer_boundaries, !NILP (ind)))
805 {
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)))
809 {
810 Lisp_Object pos;
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);
821 }
822 else
823 /* Anything else means boundary on left and no arrows. */
824 boundary_top = boundary_bot = Qleft;
825 }
826
827 if (!NILP (ind))
828 {
829 int done_top = 0, done_bot = 0;
830
831 for (y = 0, rn = 0;
832 y < yb && rn < nrows;
833 y += row->height, ++rn)
834 {
835 unsigned indicate_bob_p, indicate_top_line_p;
836 unsigned indicate_eob_p, indicate_bottom_line_p;
837
838 row = w->desired_matrix->rows + rn;
839 if (!row->enabled_p)
840 row = w->current_matrix->rows + rn;
841
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;
846
847 row->indicate_bob_p = row->indicate_top_line_p = 0;
848 row->indicate_eob_p = row->indicate_bottom_line_p = 0;
849
850 if (!row->mode_line_p)
851 {
852 if (!done_top)
853 {
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);
857 else
858 row->indicate_top_line_p = !NILP (arrow_top);
859 done_top = 1;
860 }
861
862 if (!done_bot)
863 {
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;
869 }
870 }
871
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;
877 }
878 }
879
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;
883
884 for (y = 0, rn = 0;
885 y < yb && rn < nrows;
886 y += row->height, rn++)
887 {
888 enum fringe_bitmap_type left, right;
889 unsigned left_face_id, right_face_id;
890
891 row = w->desired_matrix->rows + rn;
892 cur = w->current_matrix->rows + rn;
893 if (!row->enabled_p)
894 row = cur;
895
896 left_face_id = right_face_id = DEFAULT_FACE_ID;
897
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)
902 {
903 left = row->left_user_fringe_bitmap;
904 left_face_id = row->left_user_fringe_face_id;
905 }
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))
910 ? LEFT_BRACKET_BITMAP : TOP_LEFT_ANGLE_BITMAP);
911 else if (row->indicate_eob_p && EQ (boundary_bot, Qleft))
912 left = BOTTOM_LEFT_ANGLE_BITMAP;
913 else if (MATRIX_ROW_CONTINUATION_LINE_P (row))
914 left = CONTINUATION_LINE_BITMAP;
915 else if (row->indicate_empty_line_p && EQ (empty_pos, Qleft))
916 left = ZV_LINE_BITMAP;
917 else if (row->indicate_top_line_p && EQ (arrow_top, Qleft))
918 left = UP_ARROW_BITMAP;
919 else if (row->indicate_bottom_line_p && EQ (arrow_bot, Qleft))
920 left = DOWN_ARROW_BITMAP;
921 else
922 left = NO_FRINGE_BITMAP;
923
924 /* Decide which bitmap to draw in the right fringe. */
925 if (WINDOW_RIGHT_FRINGE_WIDTH (w) == 0)
926 right = NO_FRINGE_BITMAP;
927 else if (row->right_user_fringe_bitmap != NO_FRINGE_BITMAP)
928 {
929 right = row->right_user_fringe_bitmap;
930 right_face_id = row->right_user_fringe_face_id;
931 }
932 else if (row->truncated_on_right_p)
933 right = RIGHT_TRUNCATION_BITMAP;
934 else if (row->indicate_bob_p && EQ (boundary_top, Qright))
935 right = ((row->indicate_eob_p && EQ (boundary_bot, Qright))
936 ? RIGHT_BRACKET_BITMAP : TOP_RIGHT_ANGLE_BITMAP);
937 else if (row->indicate_eob_p && EQ (boundary_bot, Qright))
938 right = BOTTOM_RIGHT_ANGLE_BITMAP;
939 else if (row->continued_p)
940 right = CONTINUED_LINE_BITMAP;
941 else if (row->indicate_top_line_p && EQ (arrow_top, Qright))
942 right = UP_ARROW_BITMAP;
943 else if (row->indicate_bottom_line_p && EQ (arrow_bot, Qright))
944 right = DOWN_ARROW_BITMAP;
945 else if (row->indicate_empty_line_p && EQ (empty_pos, Qright))
946 right = ZV_LINE_BITMAP;
947 else
948 right = NO_FRINGE_BITMAP;
949
950 if (row->y != cur->y
951 || row->visible_height != cur->visible_height
952 || row->ends_at_zv_p != cur->ends_at_zv_p
953 || left != cur->left_fringe_bitmap
954 || right != cur->right_fringe_bitmap
955 || left_face_id != cur->left_fringe_face_id
956 || right_face_id != cur->right_fringe_face_id
957 || cur->redraw_fringe_bitmaps_p)
958 {
959 redraw_p = row->redraw_fringe_bitmaps_p = 1;
960 if (!keep_current_p)
961 {
962 cur->redraw_fringe_bitmaps_p = 1;
963 cur->left_fringe_bitmap = left;
964 cur->right_fringe_bitmap = right;
965 cur->left_fringe_face_id = left_face_id;
966 cur->right_fringe_face_id = right_face_id;
967 }
968 }
969
970 if (row->overlay_arrow_bitmap != cur->overlay_arrow_bitmap)
971 {
972 redraw_p = row->redraw_fringe_bitmaps_p = cur->redraw_fringe_bitmaps_p = 1;
973 cur->overlay_arrow_bitmap = row->overlay_arrow_bitmap;
974 }
975
976 row->left_fringe_bitmap = left;
977 row->right_fringe_bitmap = right;
978 row->left_fringe_face_id = left_face_id;
979 row->right_fringe_face_id = right_face_id;
980
981 if (rn > 0 && row->redraw_fringe_bitmaps_p)
982 row[-1].redraw_fringe_bitmaps_p = cur[-1].redraw_fringe_bitmaps_p = 1;
983 }
984
985 return redraw_p && !keep_current_p;
986 }
987
988
989 /* Compute actual fringe widths for frame F.
990
991 If REDRAW is 1, redraw F if the fringe settings was actually
992 modified and F is visible.
993
994 Since the combined left and right fringe must occupy an integral
995 number of columns, we may need to add some pixels to each fringe.
996 Typically, we add an equal amount (+/- 1 pixel) to each fringe,
997 but a negative width value is taken literally (after negating it).
998
999 We never make the fringes narrower than specified.
1000 */
1001
1002 void
1003 compute_fringe_widths (f, redraw)
1004 struct frame *f;
1005 int redraw;
1006 {
1007 int o_left = FRAME_LEFT_FRINGE_WIDTH (f);
1008 int o_right = FRAME_RIGHT_FRINGE_WIDTH (f);
1009 int o_cols = FRAME_FRINGE_COLS (f);
1010
1011 Lisp_Object left_fringe = Fassq (Qleft_fringe, f->param_alist);
1012 Lisp_Object right_fringe = Fassq (Qright_fringe, f->param_alist);
1013 int left_fringe_width, right_fringe_width;
1014
1015 if (!NILP (left_fringe))
1016 left_fringe = Fcdr (left_fringe);
1017 if (!NILP (right_fringe))
1018 right_fringe = Fcdr (right_fringe);
1019
1020 left_fringe_width = ((NILP (left_fringe) || !INTEGERP (left_fringe)) ? 8 :
1021 XINT (left_fringe));
1022 right_fringe_width = ((NILP (right_fringe) || !INTEGERP (right_fringe)) ? 8 :
1023 XINT (right_fringe));
1024
1025 if (left_fringe_width || right_fringe_width)
1026 {
1027 int left_wid = left_fringe_width >= 0 ? left_fringe_width : -left_fringe_width;
1028 int right_wid = right_fringe_width >= 0 ? right_fringe_width : -right_fringe_width;
1029 int conf_wid = left_wid + right_wid;
1030 int font_wid = FRAME_COLUMN_WIDTH (f);
1031 int cols = (left_wid + right_wid + font_wid-1) / font_wid;
1032 int real_wid = cols * font_wid;
1033 if (left_wid && right_wid)
1034 {
1035 if (left_fringe_width < 0)
1036 {
1037 /* Left fringe width is fixed, adjust right fringe if necessary */
1038 FRAME_LEFT_FRINGE_WIDTH (f) = left_wid;
1039 FRAME_RIGHT_FRINGE_WIDTH (f) = real_wid - left_wid;
1040 }
1041 else if (right_fringe_width < 0)
1042 {
1043 /* Right fringe width is fixed, adjust left fringe if necessary */
1044 FRAME_LEFT_FRINGE_WIDTH (f) = real_wid - right_wid;
1045 FRAME_RIGHT_FRINGE_WIDTH (f) = right_wid;
1046 }
1047 else
1048 {
1049 /* Adjust both fringes with an equal amount.
1050 Note that we are doing integer arithmetic here, so don't
1051 lose a pixel if the total width is an odd number. */
1052 int fill = real_wid - conf_wid;
1053 FRAME_LEFT_FRINGE_WIDTH (f) = left_wid + fill/2;
1054 FRAME_RIGHT_FRINGE_WIDTH (f) = right_wid + fill - fill/2;
1055 }
1056 }
1057 else if (left_fringe_width)
1058 {
1059 FRAME_LEFT_FRINGE_WIDTH (f) = real_wid;
1060 FRAME_RIGHT_FRINGE_WIDTH (f) = 0;
1061 }
1062 else
1063 {
1064 FRAME_LEFT_FRINGE_WIDTH (f) = 0;
1065 FRAME_RIGHT_FRINGE_WIDTH (f) = real_wid;
1066 }
1067 FRAME_FRINGE_COLS (f) = cols;
1068 }
1069 else
1070 {
1071 FRAME_LEFT_FRINGE_WIDTH (f) = 0;
1072 FRAME_RIGHT_FRINGE_WIDTH (f) = 0;
1073 FRAME_FRINGE_COLS (f) = 0;
1074 }
1075
1076 if (redraw && FRAME_VISIBLE_P (f))
1077 if (o_left != FRAME_LEFT_FRINGE_WIDTH (f) ||
1078 o_right != FRAME_RIGHT_FRINGE_WIDTH (f) ||
1079 o_cols != FRAME_FRINGE_COLS (f))
1080 redraw_frame (f);
1081 }
1082
1083
1084 /* Free resources used by a user-defined bitmap. */
1085
1086 void
1087 destroy_fringe_bitmap (n)
1088 int n;
1089 {
1090 struct fringe_bitmap **fbp;
1091
1092 fringe_faces[n] = Qnil;
1093
1094 fbp = &fringe_bitmaps[n];
1095 if (*fbp && (*fbp)->dynamic)
1096 {
1097 /* XXX Is SELECTED_FRAME OK here? */
1098 struct redisplay_interface *rif = FRAME_RIF (SELECTED_FRAME ());
1099 if (rif && rif->destroy_fringe_bitmap)
1100 rif->destroy_fringe_bitmap (n);
1101 xfree (*fbp);
1102 *fbp = NULL;
1103 }
1104
1105 while (max_used_fringe_bitmap > MAX_STANDARD_FRINGE_BITMAPS
1106 && fringe_bitmaps[max_used_fringe_bitmap - 1] == NULL)
1107 max_used_fringe_bitmap--;
1108 }
1109
1110
1111 DEFUN ("destroy-fringe-bitmap", Fdestroy_fringe_bitmap, Sdestroy_fringe_bitmap,
1112 1, 1, 0,
1113 doc: /* Destroy fringe bitmap BITMAP.
1114 If BITMAP overrides a standard fringe bitmap, the original bitmap is restored. */)
1115 (bitmap)
1116 Lisp_Object bitmap;
1117 {
1118 int n;
1119
1120 CHECK_SYMBOL (bitmap);
1121 n = lookup_fringe_bitmap (bitmap);
1122 if (!n)
1123 return Qnil;
1124
1125 destroy_fringe_bitmap (n);
1126
1127 if (n >= MAX_STANDARD_FRINGE_BITMAPS)
1128 {
1129 Vfringe_bitmaps = Fdelq (bitmap, Vfringe_bitmaps);
1130 /* It would be better to remove the fringe property. */
1131 Fput (bitmap, Qfringe, Qnil);
1132 }
1133
1134 return Qnil;
1135 }
1136
1137
1138 /* Initialize bitmap bit.
1139
1140 On X, we bit-swap the built-in bitmaps and reduce bitmap
1141 from short to char array if width is <= 8 bits.
1142
1143 On MAC with big-endian CPU, we need to byte-swap each short.
1144
1145 On W32 and MAC (little endian), there's no need to do this.
1146 */
1147
1148 void
1149 init_fringe_bitmap (which, fb, once_p)
1150 enum fringe_bitmap_type which;
1151 struct fringe_bitmap *fb;
1152 int once_p;
1153 {
1154 if (once_p || fb->dynamic)
1155 {
1156 #if defined (HAVE_X_WINDOWS)
1157 static unsigned char swap_nibble[16]
1158 = { 0x0, 0x8, 0x4, 0xc, /* 0000 1000 0100 1100 */
1159 0x2, 0xa, 0x6, 0xe, /* 0010 1010 0110 1110 */
1160 0x1, 0x9, 0x5, 0xd, /* 0001 1001 0101 1101 */
1161 0x3, 0xb, 0x7, 0xf }; /* 0011 1011 0111 1111 */
1162 unsigned short *bits = fb->bits;
1163 int j;
1164
1165 if (fb->width <= 8)
1166 {
1167 unsigned char *cbits = (unsigned char *)fb->bits;
1168 for (j = 0; j < fb->height; j++)
1169 {
1170 unsigned short b = *bits++;
1171 unsigned char c;
1172 c = (unsigned char)((swap_nibble[b & 0xf] << 4)
1173 | (swap_nibble[(b>>4) & 0xf]));
1174 *cbits++ = (c >> (8 - fb->width));
1175 }
1176 }
1177 else
1178 {
1179 for (j = 0; j < fb->height; j++)
1180 {
1181 unsigned short b = *bits;
1182 b = (unsigned short)((swap_nibble[b & 0xf] << 12)
1183 | (swap_nibble[(b>>4) & 0xf] << 8)
1184 | (swap_nibble[(b>>8) & 0xf] << 4)
1185 | (swap_nibble[(b>>12) & 0xf]));
1186 *bits++ = (b >> (16 - fb->width));
1187 }
1188 }
1189 #endif /* HAVE_X_WINDOWS */
1190
1191 #if defined (MAC_OS) && defined (WORDS_BIG_ENDIAN)
1192 unsigned short *bits = fb->bits;
1193 int j;
1194 for (j = 0; j < fb->height; j++)
1195 {
1196 unsigned short b = *bits;
1197 *bits++ = ((b >> 8) & 0xff) | ((b & 0xff) << 8);
1198 }
1199 #endif /* MAC_OS && WORDS_BIG_ENDIAN */
1200 }
1201
1202 if (!once_p)
1203 {
1204 /* XXX Is SELECTED_FRAME OK here? */
1205 struct redisplay_interface *rif = FRAME_RIF (SELECTED_FRAME ());
1206
1207 destroy_fringe_bitmap (which);
1208
1209 if (rif && rif->define_fringe_bitmap)
1210 rif->define_fringe_bitmap (which, fb->bits, fb->height, fb->width);
1211
1212 fringe_bitmaps[which] = fb;
1213 if (which >= max_used_fringe_bitmap)
1214 max_used_fringe_bitmap = which + 1;
1215 }
1216 }
1217
1218
1219 DEFUN ("define-fringe-bitmap", Fdefine_fringe_bitmap, Sdefine_fringe_bitmap,
1220 2, 5, 0,
1221 doc: /* Define fringe bitmap BITMAP from BITS of size HEIGHT x WIDTH.
1222 BITMAP is a symbol or string naming the new fringe bitmap.
1223 BITS is either a string or a vector of integers.
1224 HEIGHT is height of bitmap. If HEIGHT is nil, use length of BITS.
1225 WIDTH must be an integer between 1 and 16, or nil which defaults to 8.
1226 Optional fifth arg ALIGN may be one of `top', `center', or `bottom',
1227 indicating the positioning of the bitmap relative to the rows where it
1228 is used; the default is to center the bitmap. Fourth arg may also be a
1229 list (ALIGN PERIODIC) where PERIODIC non-nil specifies that the bitmap
1230 should be repeated.
1231 If BITMAP already exists, the existing definition is replaced. */)
1232 (bitmap, bits, height, width, align)
1233 Lisp_Object bitmap, bits, height, width, align;
1234 {
1235 int n, h, i, j;
1236 unsigned short *b;
1237 struct fringe_bitmap fb, *xfb;
1238 int fill1 = 0, fill2 = 0;
1239
1240 CHECK_SYMBOL (bitmap);
1241
1242 if (STRINGP (bits))
1243 h = SCHARS (bits);
1244 else if (VECTORP (bits))
1245 h = XVECTOR (bits)->size;
1246 else
1247 bits = wrong_type_argument (Qsequencep, bits);
1248
1249 if (NILP (height))
1250 fb.height = h;
1251 else
1252 {
1253 CHECK_NUMBER (height);
1254 fb.height = min (XINT (height), 255);
1255 if (fb.height > h)
1256 {
1257 fill1 = (fb.height - h) / 2;
1258 fill2 = fb.height - h - fill1;
1259 }
1260 }
1261
1262 if (NILP (width))
1263 fb.width = 8;
1264 else
1265 {
1266 CHECK_NUMBER (width);
1267 fb.width = min (XINT (width), 255);
1268 }
1269
1270 fb.period = 0;
1271 fb.align = ALIGN_BITMAP_CENTER;
1272
1273 if (CONSP (align))
1274 {
1275 Lisp_Object period = XCDR (align);
1276 if (CONSP (period))
1277 {
1278 period = XCAR (period);
1279 if (!NILP (period))
1280 {
1281 fb.period = fb.height;
1282 fb.height = 255;
1283 }
1284 }
1285 align = XCAR (align);
1286 }
1287 if (EQ (align, Qtop))
1288 fb.align = ALIGN_BITMAP_TOP;
1289 else if (EQ (align, Qbottom))
1290 fb.align = ALIGN_BITMAP_BOTTOM;
1291 else if (!NILP (align) && !EQ (align, Qcenter))
1292 error ("Bad align argument");
1293
1294 n = lookup_fringe_bitmap (bitmap);
1295 if (!n)
1296 {
1297 if (max_used_fringe_bitmap < max_fringe_bitmaps)
1298 n = max_used_fringe_bitmap++;
1299 else
1300 {
1301 for (n = MAX_STANDARD_FRINGE_BITMAPS;
1302 n < max_fringe_bitmaps;
1303 n++)
1304 if (fringe_bitmaps[n] == NULL)
1305 break;
1306
1307 if (n == max_fringe_bitmaps)
1308 {
1309 if ((max_fringe_bitmaps + 20) > MAX_FRINGE_BITMAPS)
1310 error ("No free fringe bitmap slots");
1311
1312 i = max_fringe_bitmaps;
1313 max_fringe_bitmaps += 20;
1314 fringe_bitmaps
1315 = ((struct fringe_bitmap **)
1316 xrealloc (fringe_bitmaps, max_fringe_bitmaps * sizeof (struct fringe_bitmap *)));
1317 fringe_faces
1318 = (Lisp_Object *) xrealloc (fringe_faces, max_fringe_bitmaps * sizeof (Lisp_Object));
1319
1320 for (; i < max_fringe_bitmaps; i++)
1321 {
1322 fringe_bitmaps[i] = NULL;
1323 fringe_faces[i] = Qnil;
1324 }
1325 }
1326 }
1327
1328 Vfringe_bitmaps = Fcons (bitmap, Vfringe_bitmaps);
1329 Fput (bitmap, Qfringe, make_number (n));
1330 }
1331
1332 fb.dynamic = 1;
1333
1334 xfb = (struct fringe_bitmap *) xmalloc (sizeof fb
1335 + fb.height * BYTES_PER_BITMAP_ROW);
1336 fb.bits = b = (unsigned short *) (xfb + 1);
1337 bzero (b, fb.height);
1338
1339 j = 0;
1340 while (j < fb.height)
1341 {
1342 for (i = 0; i < fill1 && j < fb.height; i++)
1343 b[j++] = 0;
1344 for (i = 0; i < h && j < fb.height; i++)
1345 {
1346 Lisp_Object elt = Faref (bits, make_number (i));
1347 b[j++] = NUMBERP (elt) ? XINT (elt) : 0;
1348 }
1349 for (i = 0; i < fill2 && j < fb.height; i++)
1350 b[j++] = 0;
1351 }
1352
1353 *xfb = fb;
1354
1355 init_fringe_bitmap (n, xfb, 0);
1356
1357 return bitmap;
1358 }
1359
1360 DEFUN ("set-fringe-bitmap-face", Fset_fringe_bitmap_face, Sset_fringe_bitmap_face,
1361 1, 2, 0,
1362 doc: /* Set face for fringe bitmap BITMAP to FACE.
1363 If FACE is nil, reset face to default fringe face. */)
1364 (bitmap, face)
1365 Lisp_Object bitmap, face;
1366 {
1367 int n;
1368 int face_id;
1369
1370 CHECK_SYMBOL (bitmap);
1371 n = lookup_fringe_bitmap (bitmap);
1372 if (!n)
1373 error ("Undefined fringe bitmap");
1374
1375 if (!NILP (face))
1376 {
1377 face_id = lookup_derived_face (SELECTED_FRAME (), face,
1378 'A', FRINGE_FACE_ID, 1);
1379 if (face_id < 0)
1380 error ("No such face");
1381 }
1382
1383 fringe_faces[n] = face;
1384
1385 return Qnil;
1386 }
1387
1388 DEFUN ("fringe-bitmaps-at-pos", Ffringe_bitmaps_at_pos, Sfringe_bitmaps_at_pos,
1389 0, 2, 0,
1390 doc: /* Return fringe bitmaps of row containing position POS in window WINDOW.
1391 If WINDOW is nil, use selected window. If POS is nil, use value of point
1392 in that window. Return value is a list (LEFT RIGHT OV), where LEFT
1393 is the symbol for the bitmap in the left fringe (or nil if no bitmap),
1394 RIGHT is similar for the right fringe, and OV is non-nil if there is an
1395 overlay arrow in the left fringe.
1396 Return nil if POS is not visible in WINDOW. */)
1397 (pos, window)
1398 Lisp_Object pos, window;
1399 {
1400 struct window *w;
1401 struct glyph_row *row;
1402 int textpos;
1403
1404 if (NILP (window))
1405 window = selected_window;
1406 CHECK_WINDOW (window);
1407 w = XWINDOW (window);
1408
1409 if (!NILP (pos))
1410 {
1411 CHECK_NUMBER_COERCE_MARKER (pos);
1412 textpos = XINT (pos);
1413 }
1414 else if (w == XWINDOW (selected_window))
1415 textpos = PT;
1416 else
1417 textpos = XMARKER (w->pointm)->charpos;
1418
1419 row = MATRIX_FIRST_TEXT_ROW (w->current_matrix);
1420 row = row_containing_pos (w, textpos, row, NULL, 0);
1421 if (row)
1422 return list3 (get_fringe_bitmap_name (row->left_fringe_bitmap),
1423 get_fringe_bitmap_name (row->right_fringe_bitmap),
1424 (row->overlay_arrow_bitmap == 0 ? Qnil
1425 : row->overlay_arrow_bitmap < 0 ? Qt
1426 : get_fringe_bitmap_name (row->overlay_arrow_bitmap)));
1427 else
1428 return Qnil;
1429 }
1430
1431
1432 /***********************************************************************
1433 Initialization
1434 ***********************************************************************/
1435
1436 void
1437 syms_of_fringe ()
1438 {
1439 defsubr (&Sdestroy_fringe_bitmap);
1440 defsubr (&Sdefine_fringe_bitmap);
1441 defsubr (&Sfringe_bitmaps_at_pos);
1442 defsubr (&Sset_fringe_bitmap_face);
1443
1444 DEFVAR_LISP ("overflow-newline-into-fringe", &Voverflow_newline_into_fringe,
1445 doc: /* *Non-nil means that newline may flow into the right fringe.
1446 This means that display lines which are exactly as wide as the window
1447 (not counting the final newline) will only occupy one screen line, by
1448 showing (or hiding) the final newline in the right fringe; when point
1449 is at the final newline, the cursor is shown in the right fringe.
1450 If nil, also continue lines which are exactly as wide as the window. */);
1451 Voverflow_newline_into_fringe = Qt;
1452
1453 DEFVAR_LISP ("fringe-bitmaps", &Vfringe_bitmaps,
1454 doc: /* List of fringe bitmap symbols.
1455 You must (require 'fringe) to use fringe bitmap symbols in your programs." */);
1456 Vfringe_bitmaps = Qnil;
1457 }
1458
1459 /* Garbage collection hook */
1460
1461 void
1462 mark_fringe_data ()
1463 {
1464 int i;
1465
1466 for (i = 0; i < max_fringe_bitmaps; i++)
1467 if (!NILP (fringe_faces[i]))
1468 mark_object (fringe_faces[i]);
1469 }
1470
1471 /* Initialize this module when Emacs starts. */
1472
1473 void
1474 init_fringe_once ()
1475 {
1476 enum fringe_bitmap_type bt;
1477
1478 for (bt = NO_FRINGE_BITMAP + 1; bt < MAX_STANDARD_FRINGE_BITMAPS; bt++)
1479 init_fringe_bitmap(bt, &standard_bitmaps[bt], 1);
1480 }
1481
1482 void
1483 init_fringe ()
1484 {
1485 int i;
1486
1487 max_fringe_bitmaps = MAX_STANDARD_FRINGE_BITMAPS + 20;
1488
1489 fringe_bitmaps
1490 = (struct fringe_bitmap **) xmalloc (max_fringe_bitmaps * sizeof (struct fringe_bitmap *));
1491 fringe_faces
1492 = (Lisp_Object *) xmalloc (max_fringe_bitmaps * sizeof (Lisp_Object));
1493
1494 for (i = 0; i < max_fringe_bitmaps; i++)
1495 {
1496 fringe_bitmaps[i] = NULL;
1497 fringe_faces[i] = Qnil;
1498 }
1499 }
1500
1501 #ifdef HAVE_NTGUI
1502
1503 void
1504 w32_init_fringe ()
1505 {
1506 enum fringe_bitmap_type bt;
1507
1508 if (!rif)
1509 return;
1510
1511 for (bt = NO_FRINGE_BITMAP + 1; bt < MAX_STANDARD_FRINGE_BITMAPS; bt++)
1512 {
1513 struct fringe_bitmap *fb = &standard_bitmaps[bt];
1514 rif->define_fringe_bitmap (bt, fb->bits, fb->height, fb->width);
1515 }
1516 }
1517
1518 void
1519 w32_reset_fringes ()
1520 {
1521 /* Destroy row bitmaps. */
1522 int bt;
1523
1524 if (!rif)
1525 return;
1526
1527 for (bt = NO_FRINGE_BITMAP + 1; bt < max_used_fringe_bitmap; bt++)
1528 rif->destroy_fringe_bitmap (bt);
1529 }
1530
1531 #endif /* HAVE_NTGUI */
1532
1533 #endif /* HAVE_WINDOW_SYSTEM */
1534
1535 /* arch-tag: 04596920-43eb-473d-b319-82712338162d
1536 (do not change this comment) */