1 /* Interface definitions for display code.
2
3 Copyright (C) 1985, 1993-1994, 1997-2023 Free Software Foundation, Inc.
4
5 This file is part of GNU Emacs.
6
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or (at
10 your option) any later version.
11
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
19
20 /* New redisplay written by Gerd Moellmann <gerd@gnu.org>. */
21
22 #ifndef DISPEXTERN_H_INCLUDED
23 #define DISPEXTERN_H_INCLUDED
24
25 #include "character.h"
26
27 #ifdef HAVE_X_WINDOWS
28
29 #include <X11/Xlib.h>
30 #ifdef USE_X_TOOLKIT
31 #include <X11/Intrinsic.h>
32 #endif /* USE_X_TOOLKIT */
33
34 #ifdef HAVE_XRENDER
35 # include <X11/extensions/Xrender.h>
36 #endif
37
38 typedef XColor Emacs_Color;
39 typedef Cursor Emacs_Cursor;
40 #define No_Cursor (None)
41 #ifndef USE_CAIRO
42 typedef Pixmap Emacs_Pixmap;
43 #endif
44 typedef XRectangle Emacs_Rectangle;
45 typedef XGCValues Emacs_GC;
46 #else /* !HAVE_X_WINDOWS */
47
48 /* XColor-like struct used by non-X code. */
49
50 typedef struct
51 {
52 unsigned long pixel;
53 unsigned short red, green, blue;
54 } Emacs_Color;
55
56 /* Accommodate X's usage of None as a null resource ID. */
57 #define No_Cursor (NULL)
58
59 /* XRectangle-like struct used by non-X GUI code. */
60 typedef struct
61 {
62 int x, y;
63 unsigned width, height;
64 } Emacs_Rectangle;
65
66 /* XGCValues-like struct used by non-X GUI code. */
67 typedef struct
68 {
69 unsigned long foreground;
70 unsigned long background;
71 } Emacs_GC;
72
73 /* Mask values to select foreground/background. */
74 /* FIXME: The GC handling in w32 really should be redesigned as to not
75 need these. */
76 #define GCForeground 0x01
77 #define GCBackground 0x02
78
79 #endif /* HAVE_X_WINDOWS */
80
81 #ifdef MSDOS
82 #include "msdos.h"
83 #endif
84
85 INLINE_HEADER_BEGIN
86
87 #include <c-strcase.h>
88 INLINE int
89 xstrcasecmp (char const *a, char const *b)
90 {
91 return c_strcasecmp (a, b);
92 }
93
94 #ifdef HAVE_X_WINDOWS
95 #include <X11/Xresource.h> /* for XrmDatabase */
96 typedef struct x_display_info Display_Info;
97 #ifndef USE_CAIRO
98 typedef XImage *Emacs_Pix_Container;
99 typedef XImage *Emacs_Pix_Context;
100 #endif /* !USE_CAIRO */
101 #define NativeRectangle XRectangle
102 #endif
103
104 #ifdef USE_CAIRO
105 /* Minimal version of XImage. */
106 typedef struct
107 {
108 int width, height; /* size of image */
109 char *data; /* pointer to image data */
110 int bytes_per_line; /* accelerator to next line */
111 int bits_per_pixel; /* bits per pixel (ZPixmap) */
112 } *Emacs_Pix_Container;
113 typedef Emacs_Pix_Container Emacs_Pixmap;
114 typedef Emacs_Pix_Container Emacs_Pix_Context;
115 #endif
116
117 #ifdef HAVE_NTGUI
118 #include "w32gui.h"
119 typedef struct w32_display_info Display_Info;
120 typedef XImage *Emacs_Pix_Container;
121 typedef HDC Emacs_Pix_Context;
122 #endif
123
124 #ifdef HAVE_NS
125 #include "nsgui.h"
126 /* Following typedef needed to accommodate the MSDOS port, believe it or not. */
127 typedef struct ns_display_info Display_Info;
128 typedef Emacs_Pixmap Emacs_Pix_Container;
129 typedef Emacs_Pixmap Emacs_Pix_Context;
130 #endif
131
132 #ifdef HAVE_PGTK
133 #include "pgtkgui.h"
134 /* Following typedef needed to accommodate the MSDOS port, believe it or not. */
135 typedef struct pgtk_display_info Display_Info;
136 typedef Emacs_Pixmap XImagePtr;
137 typedef XImagePtr XImagePtr_or_DC;
138 #endif /* HAVE_PGTK */
139
140 #ifdef HAVE_HAIKU
141 #include "haikugui.h"
142 typedef struct haiku_display_info Display_Info;
143 typedef Emacs_Pixmap Emacs_Pix_Container;
144 typedef Emacs_Pixmap Emacs_Pix_Context;
145 #endif
146
147 #ifdef HAVE_WINDOW_SYSTEM
148 # include <time.h>
149 # include "fontset.h"
150 #endif
151
152 #ifndef HAVE_WINDOW_SYSTEM
153 typedef void *Emacs_Cursor;
154 #endif
155
156 #ifndef NativeRectangle
157 #define NativeRectangle int
158 #endif
159
160 /* Text cursor types. */
161
162 enum text_cursor_kinds
163 {
164 DEFAULT_CURSOR = -2,
165 NO_CURSOR = -1,
166 FILLED_BOX_CURSOR,
167 HOLLOW_BOX_CURSOR,
168 BAR_CURSOR,
169 HBAR_CURSOR
170 };
171
172 /* Values returned from coordinates_in_window. */
173
174 enum window_part
175 {
176 ON_NOTHING,
177 ON_TEXT,
178 ON_MODE_LINE,
179 ON_VERTICAL_BORDER,
180 ON_HEADER_LINE,
181 ON_TAB_LINE,
182 ON_LEFT_FRINGE,
183 ON_RIGHT_FRINGE,
184 ON_LEFT_MARGIN,
185 ON_RIGHT_MARGIN,
186 ON_VERTICAL_SCROLL_BAR,
187 ON_HORIZONTAL_SCROLL_BAR,
188 ON_RIGHT_DIVIDER,
189 ON_BOTTOM_DIVIDER
190 };
191
192 /* Number of bits allocated to store fringe bitmap numbers. */
193 #define FRINGE_ID_BITS 16
194
195 /* Number of bits allocated to store fringe bitmap height. */
196 #define FRINGE_HEIGHT_BITS 8
197
198
199 /***********************************************************************
200 Debugging
201 ***********************************************************************/
202
203 /* If GLYPH_DEBUG is defined, additional checks are activated. */
204
205 /* Macros to include code only if GLYPH_DEBUG is defined. */
206
207 #ifdef GLYPH_DEBUG
208 #define IF_DEBUG(X) ((void) (X))
209 #else
210 #define IF_DEBUG(X) ((void) 0)
211 #endif
212
213 /***********************************************************************
214 Text positions
215 ***********************************************************************/
216
217 /* Starting with Emacs 20.3, characters from strings and buffers have
218 both a character and a byte position associated with them. The
219 following structure holds such a pair of positions. */
220
221 struct text_pos
222 {
223 /* Character position. */
224 ptrdiff_t charpos;
225
226 /* Corresponding byte position. */
227 ptrdiff_t bytepos;
228 };
229
230 /* Access character and byte position of POS in a functional form. */
231
232 #define BYTEPOS(POS) (POS).bytepos
233 #define CHARPOS(POS) (POS).charpos
234
235 /* Set character position of POS to CHARPOS, byte position to BYTEPOS. */
236
237 #define SET_TEXT_POS(POS, CHARPOS, BYTEPOS) \
238 ((POS).charpos = (CHARPOS), (POS).bytepos = BYTEPOS)
239
240 /* Increment text position POS. */
241
242 #define INC_TEXT_POS(POS, MULTIBYTE_P) \
243 do \
244 { \
245 ++(POS).charpos; \
246 if (MULTIBYTE_P) \
247 (POS).bytepos += next_char_len ((POS).bytepos); \
248 else \
249 ++(POS).bytepos; \
250 } \
251 while (false)
252
253 /* Decrement text position POS. */
254
255 #define DEC_TEXT_POS(POS, MULTIBYTE_P) \
256 do \
257 { \
258 --(POS).charpos; \
259 if (MULTIBYTE_P) \
260 (POS).bytepos -= prev_char_len ((POS).bytepos); \
261 else \
262 --(POS).bytepos; \
263 } \
264 while (false)
265
266 /* Set text position POS from marker MARKER. */
267
268 #define SET_TEXT_POS_FROM_MARKER(POS, MARKER) \
269 (CHARPOS (POS) = marker_position (MARKER), \
270 BYTEPOS (POS) = marker_byte_position (MARKER))
271
272 /* Like above, but clip POS within accessible range. */
273
274 #define CLIP_TEXT_POS_FROM_MARKER(POS, MARKER) \
275 (CHARPOS (POS) = clip_to_bounds \
276 (BEGV, marker_position (MARKER), ZV), \
277 BYTEPOS (POS) = clip_to_bounds \
278 (BEGV_BYTE, marker_byte_position (MARKER), ZV_BYTE))
279
280 /* Set marker MARKER from text position POS. */
281
282 #define SET_MARKER_FROM_TEXT_POS(MARKER, POS) \
283 set_marker_both ((MARKER), Qnil, CHARPOS ((POS)), BYTEPOS ((POS)))
284
285 /* Value is non-zero if character and byte positions of POS1 and POS2
286 are equal. */
287
288 #define TEXT_POS_EQUAL_P(POS1, POS2) \
289 ((POS1).charpos == (POS2).charpos \
290 && (POS1).bytepos == (POS2).bytepos)
291
292 /* When rendering glyphs, redisplay scans string or buffer text,
293 overlay strings in that text, and does display table or control
294 character translations. The following structure captures a
295 position taking all this into account. */
296
297 struct display_pos
298 {
299 /* Buffer or string position. */
300 struct text_pos pos;
301
302 /* If this is a position in an overlay string, overlay_string_index
303 is the index of that overlay string in the sequence of overlay
304 strings at `pos' in the order redisplay processes them. A value
305 < 0 means that this is not a position in an overlay string. */
306 ptrdiff_t overlay_string_index;
307
308 /* If this is a position in an overlay string, string_pos is the
309 position within that string. */
310 struct text_pos string_pos;
311
312 /* If the character at the position above is a control character or
313 has a display table entry, dpvec_index is an index in the display
314 table or control character translation of that character. A
315 value < 0 means this is not a position in such a translation. */
316 int dpvec_index;
317 };
318
319
320
321 /***********************************************************************
322 Glyphs
323 ***********************************************************************/
324
325 /* The glyph datatype, used to represent characters on the display.
326 It consists of a char code and a face id. */
327
328 typedef struct {
329 int ch;
330 int face_id;
331 } GLYPH;
332
333 /* Return a glyph's character code. */
334 INLINE int GLYPH_CHAR (GLYPH glyph) { return glyph.ch; }
335
336 /* Return a glyph's face ID. */
337 INLINE int GLYPH_FACE (GLYPH glyph) { return glyph.face_id; }
338
339 #define SET_GLYPH_CHAR(glyph, char) ((glyph).ch = (char))
340 #define SET_GLYPH_FACE(glyph, face) ((glyph).face_id = (face))
341 #define SET_GLYPH(glyph, char, face) \
342 ((glyph).ch = (char), (glyph).face_id = (face))
343
344 /* The following are valid only if GLYPH_CODE_P (gc). */
345
346 INLINE int
347 GLYPH_CODE_CHAR (Lisp_Object gc)
348 {
349 return (CONSP (gc)
350 ? XFIXNUM (XCAR (gc))
351 : XFIXNUM (gc) & MAX_CHAR);
352 }
353
354 INLINE int
355 GLYPH_CODE_FACE (Lisp_Object gc)
356 {
357 return CONSP (gc) ? XFIXNUM (XCDR (gc)) : XFIXNUM (gc) >> CHARACTERBITS;
358 }
359
360 #define SET_GLYPH_FROM_GLYPH_CODE(glyph, gc) \
361 do \
362 { \
363 if (CONSP (gc)) \
364 SET_GLYPH (glyph, XFIXNUM (XCAR (gc)), XFIXNUM (XCDR (gc))); \
365 else \
366 SET_GLYPH (glyph, (XFIXNUM (gc) & ((1 << CHARACTERBITS)-1)), \
367 (XFIXNUM (gc) >> CHARACTERBITS)); \
368 } \
369 while (false)
370
371 /* The ID of the mode line highlighting face. */
372 enum { GLYPH_MODE_LINE_FACE = 1 };
373
374 /* Enumeration of glyph types. Glyph structures contain a type field
375 containing one of the enumerators defined here. */
376
377 enum glyph_type
378 {
379 /* Glyph describes a character. */
380 CHAR_GLYPH,
381
382 /* Glyph describes a static or automatic composition. */
383 COMPOSITE_GLYPH,
384
385 /* Glyph describes a glyphless character. */
386 GLYPHLESS_GLYPH,
387
388 /* Glyph describes an image. */
389 IMAGE_GLYPH,
390
391 /* Glyph is a space of fractional width and/or height. */
392 STRETCH_GLYPH,
393
394 /* Glyph is an external widget drawn by the GUI toolkit. */
395 XWIDGET_GLYPH
396 };
397
398
399 /* Structure describing how to use partial glyphs (images slicing) */
400
401 struct glyph_slice
402 {
403 unsigned x : 16;
404 unsigned y : 16;
405 unsigned width : 16;
406 unsigned height : 16;
407 };
408
409
410 /* Glyphs.
411
412 Be extra careful when changing this structure! Esp. make sure that
413 functions producing glyphs, like append_glyph, fill ALL of the
414 glyph structure, and that GLYPH_EQUAL_P compares all
415 display-relevant members of glyphs (not to imply that these are the
416 only things to check when you add a member). */
417
418 struct glyph
419 {
420 /* Position from which this glyph was drawn. If `object' below is a
421 Lisp string, this is an index into that string. If it is a
422 buffer, this is a position in that buffer. In addition, some
423 special glyphs have special values for this:
424
425 glyph standing for newline at end of line 0
426 empty space after the end of the line -1
427 overlay arrow on a TTY -1
428 glyph displaying line number -1
429 glyph at EOB that ends in a newline -1
430 left truncation glyphs: -1
431 right truncation/continuation glyphs next buffer position
432 glyph standing for newline of an empty line buffer position of newline
433 stretch glyph at left edge of R2L lines buffer position of newline */
434 ptrdiff_t charpos;
435
436 /* Lisp object source of this glyph. Currently either a buffer or a
437 string, if the glyph was produced from characters which came from
438 a buffer or a string; or nil if the glyph was inserted by
439 redisplay for its own purposes, such as padding, truncation, or
440 continuation glyphs, or the overlay-arrow glyphs on TTYs. */
441 Lisp_Object object;
442
443 /* Width in pixels. */
444 short pixel_width;
445
446 /* Ascent and descent in pixels. */
447 short ascent, descent;
448
449 /* Vertical offset. If < 0, the glyph is displayed raised, if > 0
450 the glyph is displayed lowered. */
451 short voffset;
452
453 /* Which kind of glyph this is---character, image etc. Value
454 should be an enumerator of type enum glyph_type. */
455 unsigned type : 3;
456
457 /* True means this glyph was produced from multibyte text. False
458 means it was produced from unibyte text, i.e. charsets aren't
459 applicable, and encoding is not performed. */
460 bool_bf multibyte_p : 1;
461
462 /* True means draw a box line at the left or right side of this
463 glyph. This is part of the implementation of the face attribute
464 `:box'. */
465 bool_bf left_box_line_p : 1;
466 bool_bf right_box_line_p : 1;
467
468 /* True means this glyph's physical ascent or descent is greater
469 than its logical ascent/descent, i.e. it may potentially overlap
470 glyphs above or below it. */
471 bool_bf overlaps_vertically_p : 1;
472
473 /* For terminal frames, true means glyph is a padding glyph. Padding
474 glyphs are used for characters whose visual shape consists of
475 more than one glyph (e.g. Asian characters). All but the first
476 glyph of such a glyph sequence have the padding_p flag set. This
477 flag is used only to minimize code changes. A better way would
478 probably be to use the width field of glyphs to express padding.
479
480 For graphic frames, true means the pixel width of the glyph in a
481 font is 0, but 1-pixel is padded on displaying for correct cursor
482 displaying. The member `pixel_width' above is set to 1. */
483 bool_bf padding_p : 1;
484
485 /* True means the actual glyph is not available, draw using `struct
486 glyphless' below instead. This can happen when a font couldn't
487 be loaded, or a character doesn't have a glyph in a font. */
488 bool_bf glyph_not_available_p : 1;
489
490 /* True means don't display cursor here. */
491 bool_bf avoid_cursor_p : 1;
492
493 /* Resolved bidirectional level of this character [0..127]. */
494 unsigned resolved_level : 7;
495
496 /* Resolved bidirectional type of this character, see enum
497 bidi_type_t below. Note that according to UAX#9, only some
498 values (STRONG_L, STRONG_R, WEAK_AN, WEAK_EN, WEAK_BN, and
499 NEUTRAL_B) can appear in the resolved type, so we only reserve
500 space for those that can. */
501 unsigned bidi_type : 3;
502
503 #define FACE_ID_BITS 20
504
505 /* Face of the glyph. This is a realized face ID,
506 an index in the face cache of the frame. */
507 unsigned face_id : FACE_ID_BITS;
508
509 /* Type of font used to display the character glyph. May be used to
510 determine which set of functions to use to obtain font metrics
511 for the glyph. On W32, value should be an enumerator of the type
512 w32_char_font_type. Otherwise it equals FONT_TYPE_UNKNOWN. */
513 unsigned font_type : 3;
514
515 /* A union of sub-structures for different glyph types. */
516 union
517 {
518 /* Metrics of a partial glyph of an image (type == IMAGE_GLYPH). */
519 struct glyph_slice img;
520 /* Start and end indices of glyphs of a grapheme cluster of a
521 composition (type == COMPOSITE_GLYPH). */
522 struct { int from, to; } cmp;
523 /* Pixel offsets for upper and lower part of the acronym. */
524 struct {
525 short upper_xoff, upper_yoff;
526 short lower_xoff, lower_yoff;
527 } glyphless;
528 } slice;
529
530 /* A union of sub-structures for different glyph types. */
531 union
532 {
533 /* Character code for character glyphs (type == CHAR_GLYPH). */
534 unsigned ch;
535
536 /* Sub-structures for type == COMPOSITE_GLYPH. */
537 struct
538 {
539 /* Flag to tell if the composition is automatic or not. */
540 bool_bf automatic : 1;
541 /* ID of the composition. */
542 unsigned id : 31;
543 } cmp;
544
545 /* Image ID for image glyphs (type == IMAGE_GLYPH). */
546 int img_id;
547
548 #ifdef HAVE_XWIDGETS
549 /* Xwidget ID. */
550 uint32_t xwidget;
551 #endif
552
553 /* Sub-structure for type == STRETCH_GLYPH. */
554 struct
555 {
556 /* The height of the glyph. */
557 unsigned height : 16;
558
559 /* The ascent of the glyph. */
560 unsigned ascent : 16;
561 }
562 stretch;
563
564 /* Sub-stretch for type == GLYPHLESS_GLYPH. */
565 struct
566 {
567 /* Value is an enum of the type glyphless_display_method. */
568 unsigned method : 2;
569 /* True iff this glyph is for a character of no font. */
570 bool_bf for_no_font : 1;
571 /* Length of acronym or hexadecimal code string (at most 8). */
572 unsigned len : 4;
573 /* Character to display. Actually we need only 22 bits. */
574 unsigned ch : 25;
575 } glyphless;
576
577 /* Used to compare all bit-fields above in one step. */
578 unsigned val;
579 } u;
580 };
581
582
583 /* Default value of the glyph font_type field. */
584
585 #define FONT_TYPE_UNKNOWN 0
586
587 /* Is GLYPH a space? */
588
589 #define CHAR_GLYPH_SPACE_P(GLYPH) \
590 ((GLYPH).u.ch == SPACEGLYPH && (GLYPH).face_id == DEFAULT_FACE_ID)
591
592 /* Are glyph slices of glyphs *X and *Y equal? It assumes that both
593 glyphs have the same type.
594
595 Note: for composition glyphs, we don't have to compare slice.cmp.to
596 because they should be the same if and only if slice.cmp.from are
597 the same. */
598
599 #define GLYPH_SLICE_EQUAL_P(X, Y) \
600 ((X)->type == IMAGE_GLYPH \
601 ? ((X)->slice.img.x == (Y)->slice.img.x \
602 && (X)->slice.img.y == (Y)->slice.img.y \
603 && (X)->slice.img.width == (Y)->slice.img.width \
604 && (X)->slice.img.height == (Y)->slice.img.height) \
605 : ((X)->type != COMPOSITE_GLYPH \
606 || (X)->slice.cmp.from == (Y)->slice.cmp.from))
607
608 /* Are glyphs *X and *Y displayed equal? */
609
610 #define GLYPH_EQUAL_P(X, Y) \
611 ((X)->type == (Y)->type \
612 && (X)->u.val == (Y)->u.val \
613 && GLYPH_SLICE_EQUAL_P (X, Y) \
614 && (X)->face_id == (Y)->face_id \
615 && (X)->padding_p == (Y)->padding_p \
616 && (X)->left_box_line_p == (Y)->left_box_line_p \
617 && (X)->right_box_line_p == (Y)->right_box_line_p \
618 && (X)->voffset == (Y)->voffset \
619 && (X)->pixel_width == (Y)->pixel_width)
620
621 /* Are character codes, faces, padding_ps of glyphs *X and *Y equal? */
622
623 #define GLYPH_CHAR_AND_FACE_EQUAL_P(X, Y) \
624 ((X)->u.ch == (Y)->u.ch \
625 && (X)->face_id == (Y)->face_id \
626 && (X)->padding_p == (Y)->padding_p)
627
628 /* Fill a character glyph GLYPH. CODE, FACE_ID, PADDING_P correspond
629 to the bits defined for the typedef `GLYPH' in lisp.h. */
630
631 #define SET_CHAR_GLYPH(GLYPH, CODE, FACE_ID, PADDING_P) \
632 do \
633 { \
634 (GLYPH).u.ch = (CODE); \
635 (GLYPH).face_id = (FACE_ID); \
636 (GLYPH).padding_p = (PADDING_P); \
637 } \
638 while (false)
639
640 /* Fill a character type glyph GLYPH from a glyph typedef FROM as
641 defined in lisp.h. */
642
643 #define SET_CHAR_GLYPH_FROM_GLYPH(GLYPH, FROM) \
644 SET_CHAR_GLYPH ((GLYPH), \
645 GLYPH_CHAR ((FROM)), \
646 GLYPH_FACE ((FROM)), \
647 false)
648
649 /* Construct a glyph code from a character glyph GLYPH. If the
650 character is multibyte, return -1 as we can't use glyph table for a
651 multibyte character. */
652
653 #define SET_GLYPH_FROM_CHAR_GLYPH(G, GLYPH) \
654 do \
655 { \
656 if ((GLYPH).u.ch < 256) \
657 SET_GLYPH ((G), (GLYPH).u.ch, ((GLYPH).face_id)); \
658 else \
659 SET_GLYPH ((G), -1, 0); \
660 } \
661 while (false)
662
663 #define GLYPH_INVALID_P(GLYPH) (GLYPH_CHAR (GLYPH) < 0)
664
665 /* Is GLYPH a padding glyph? */
666
667 #define CHAR_GLYPH_PADDING_P(GLYPH) (GLYPH).padding_p
668
669
670
671
672 /***********************************************************************
673 Glyph Pools
674 ***********************************************************************/
675
676 /* Glyph Pool.
677
678 Glyph memory for frame-based redisplay is allocated from the heap
679 in one vector kept in a glyph pool structure which is stored with
680 the frame. The size of the vector is made large enough to cover
681 all windows on the frame.
682
683 Both frame and window glyph matrices reference memory from a glyph
684 pool in frame-based redisplay.
685
686 In window-based redisplay, no glyphs pools exist; windows allocate
687 and free their glyph memory themselves. */
688
689 struct glyph_pool
690 {
691 /* Vector of glyphs allocated from the heap. */
692 struct glyph *glyphs;
693
694 /* Allocated size of `glyphs'. */
695 ptrdiff_t nglyphs;
696
697 /* Number of rows and columns in a matrix. */
698 int nrows, ncolumns;
699 };
700
701
702
703 /***********************************************************************
704 Glyph Matrix
705 ***********************************************************************/
706
707 /* Glyph Matrix.
708
709 Three kinds of glyph matrices exist:
710
711 1. Frame glyph matrices. These are used for terminal frames whose
712 redisplay needs a view of the whole screen due to limited terminal
713 capabilities. Frame matrices are used only in the update phase
714 of redisplay. They are built in update_frame and not used after
715 the update has been performed.
716
717 2. Window glyph matrices on frames having frame glyph matrices.
718 Such matrices are sub-matrices of their corresponding frame matrix,
719 i.e., frame glyph matrices and window glyph matrices share the same
720 glyph memory, which is allocated in the form of a glyph_pool structure.
721 Glyph rows in such a window matrix are slices of frame matrix rows.
722
723 3. Free-standing window glyph matrices managing their own glyph
724 storage. This form is used in window-based redisplay which
725 includes variable width and height fonts etc.
726
727 The size of a window's row vector depends on the height of fonts
728 defined on its frame. It is chosen so that the vector is large
729 enough to describe all lines in a window when it is displayed in
730 the smallest possible character size. When new fonts are loaded,
731 or window sizes change, the row vector is adjusted accordingly. */
732
733 struct glyph_matrix
734 {
735 /* The pool from which glyph memory is allocated, if any. This is
736 null for frame matrices and for window matrices managing their
737 own storage. */
738 struct glyph_pool *pool;
739
740 /* Vector of glyph row structures. The row at nrows - 1 is reserved
741 for the mode line. */
742 struct glyph_row *rows;
743
744 /* Number of elements allocated for the vector rows above. */
745 ptrdiff_t rows_allocated;
746
747 /* The number of rows used by the window if all lines were displayed
748 with the smallest possible character height. */
749 int nrows;
750
751 /* Origin within the frame matrix if this is a window matrix on a
752 frame having a frame matrix. Both values are zero for
753 window-based redisplay. */
754 int matrix_x, matrix_y;
755
756 /* Width and height of the matrix in columns and rows. */
757 int matrix_w, matrix_h;
758
759 /* If this structure describes a window matrix of window W,
760 window_pixel_left is the value of W->pixel_left, window_pixel_top
761 the value of W->pixel_top, window_height and window_width are width
762 and height of W, as returned by window_box, and window_vscroll is
763 the value of W->vscroll at the time the matrix was last adjusted.
764 Only set for window-based redisplay. */
765 int window_pixel_left, window_pixel_top;
766 int window_height, window_width;
767 int window_vscroll;
768
769 /* Number of glyphs reserved for left and right marginal areas when
770 the matrix was last adjusted. */
771 int left_margin_glyphs, right_margin_glyphs;
772
773 /* Flag indicating that scrolling should not be tried in
774 update_window. This flag is set by functions like try_window_id
775 which do their own scrolling. */
776 bool_bf no_scrolling_p : 1;
777
778 /* True means window displayed in this matrix has a tab line. */
779 bool_bf tab_line_p : 1;
780
781 /* True means window displayed in this matrix has a header
782 line. */
783 bool_bf header_line_p : 1;
784
785 #ifdef GLYPH_DEBUG
786 /* A string identifying the method used to display the matrix. */
787 char method[512];
788 #endif
789
790 /* The buffer this matrix displays. Set in
791 mark_window_display_accurate_1. */
792 struct buffer *buffer;
793
794 /* Values of BEGV and ZV as of last redisplay. Set in
795 mark_window_display_accurate_1. */
796 ptrdiff_t begv, zv;
797 };
798
799
800 /* Check that glyph pointers stored in glyph rows of MATRIX are okay.
801 This aborts if any pointer is found twice. */
802
803 #ifdef GLYPH_DEBUG
804 void check_matrix_pointer_lossage (struct glyph_matrix *);
805 #define CHECK_MATRIX(MATRIX) check_matrix_pointer_lossage ((MATRIX))
806 #else
807 #define CHECK_MATRIX(MATRIX) ((void) 0)
808 #endif
809
810
811
812 /***********************************************************************
813 Glyph Rows
814 ***********************************************************************/
815
816 /* Area in window glyph matrix. If values are added or removed,
817 the function mark_glyph_matrix in alloc.c may need to be changed. */
818
819 enum glyph_row_area
820 {
821 ANY_AREA = -1,
822 LEFT_MARGIN_AREA,
823 TEXT_AREA,
824 RIGHT_MARGIN_AREA,
825 LAST_AREA
826 };
827
828
829 /* Rows of glyphs in a windows or frame glyph matrix.
830
831 Each row is partitioned into three areas. The start and end of
832 each area is recorded in a pointer as shown below.
833
834 +--------------------+-------------+---------------------+
835 | left margin area | text area | right margin area |
836 +--------------------+-------------+---------------------+
837 | | | |
838 glyphs[LEFT_MARGIN_AREA] glyphs[RIGHT_MARGIN_AREA]
839 | |
840 glyphs[TEXT_AREA] |
841 glyphs[LAST_AREA]
842
843 Rows in frame matrices reference glyph memory allocated in a frame
844 glyph pool (see the description of struct glyph_pool). Rows in
845 window matrices on frames having frame matrices reference slices of
846 the glyphs of corresponding rows in the frame matrix.
847
848 Rows in window matrices on frames having no frame matrices point to
849 glyphs allocated from the heap via xmalloc;
850 glyphs[LEFT_MARGIN_AREA] is the start address of the allocated
851 glyph structure array.
852
853 NOTE: layout of first four members of this structure is important,
854 see clear_glyph_row and copy_row_except_pointers to check why. */
855
856 struct glyph_row
857 {
858 /* Pointers to beginnings of areas. The end of an area A is found at
859 A + 1 in the vector. The last element of the vector is the end
860 of the whole row.
861
862 Kludge alert: Even if used[TEXT_AREA] == 0, glyphs[TEXT_AREA][0]'s
863 position field is used. It is -1 if this row does not correspond
864 to any text; it is some buffer position if the row corresponds to
865 an empty display line that displays a line end. This is what old
866 redisplay used to do. (Except in code for terminal frames, this
867 kludge is no longer used, I believe. --gerd).
868
869 See also start, end, displays_text_p and ends_at_zv_p for cleaner
870 ways to do it. The special meaning of positions 0 and -1 will be
871 removed some day, so don't use it in new code. */
872 struct glyph *glyphs[1 + LAST_AREA];
873
874 /* Number of glyphs actually filled in areas. This could have size
875 LAST_AREA, but it's 1 + LAST_AREA to simplify offset calculations. */
876 short used[1 + LAST_AREA];
877
878 /* Hash code. This hash code is available as soon as the row
879 is constructed, i.e. after a call to display_line. */
880 unsigned hash;
881
882 /* Window-relative x and y-position of the top-left corner of this
883 row. If y < 0, this means that eabs (y) pixels of the row are
884 invisible because it is partially visible at the top of a window.
885 If x < 0, this means that eabs (x) pixels of the first glyph of
886 the text area of the row are invisible because the glyph is
887 partially visible. */
888 int x, y;
889
890 /* Width of the row in pixels without taking face extension at the
891 end of the row into account, and without counting truncation
892 and continuation glyphs at the end of a row on ttys. */
893 int pixel_width;
894
895 /* Logical ascent/height of this line. The value of ascent is zero
896 and height is 1 on terminal frames. */
897 int ascent, height;
898
899 /* Physical ascent/height of this line. If max_ascent > ascent,
900 this line overlaps the line above it on the display. Otherwise,
901 if max_height > height, this line overlaps the line beneath it. */
902 int phys_ascent, phys_height;
903
904 /* Portion of row that is visible. Partially visible rows may be
905 found at the top and bottom of a window. This is 1 for tty
906 frames. It may be < 0 in case of completely invisible rows. */
907 int visible_height;
908
909 /* Extra line spacing added after this row. Do not consider this
910 in last row when checking if row is fully visible. */
911 int extra_line_spacing;
912
913 /* First position in this row. This is the text position, including
914 overlay position information etc, where the display of this row
915 started, and can thus be less than the position of the first
916 glyph (e.g. due to invisible text or horizontal scrolling).
917 BIDI Note: In R2L rows, that have its reversed_p flag set, this
918 position is at or beyond the right edge of the row. */
919 struct display_pos start;
920
921 /* Text position at the end of this row. This is the position after
922 the last glyph on this row. It can be greater than the last
923 glyph position + 1, due to a newline that ends the line,
924 truncation, invisible text etc. In an up-to-date display, this
925 should always be equal to the start position of the next row.
926 BIDI Note: In R2L rows, this position is at or beyond the left
927 edge of the row. */
928 struct display_pos end;
929
930 /* The smallest and the largest buffer positions that contributed to
931 glyphs in this row. Note that due to bidi reordering, these are
932 in general different from the text positions stored in `start'
933 and `end' members above, and also different from the buffer
934 positions recorded in the glyphs displayed the leftmost and
935 rightmost on the screen. */
936 struct text_pos minpos, maxpos;
937
938 /* Non-zero means the overlay arrow bitmap is on this line.
939 -1 means use default overlay arrow bitmap, else
940 it specifies actual fringe bitmap number. */
941 int overlay_arrow_bitmap;
942
943 /* Left fringe bitmap number (enum fringe_bitmap_type). */
944 unsigned left_user_fringe_bitmap : FRINGE_ID_BITS;
945
946 /* Right fringe bitmap number (enum fringe_bitmap_type). */
947 unsigned right_user_fringe_bitmap : FRINGE_ID_BITS;
948
949 /* Left fringe bitmap number (enum fringe_bitmap_type). */
950 unsigned left_fringe_bitmap : FRINGE_ID_BITS;
951
952 /* Right fringe bitmap number (enum fringe_bitmap_type). */
953 unsigned right_fringe_bitmap : FRINGE_ID_BITS;
954
955 /* Face of the left fringe glyph. */
956 unsigned left_user_fringe_face_id : FACE_ID_BITS;
957
958 /* Face of the right fringe glyph. */
959 unsigned right_user_fringe_face_id : FACE_ID_BITS;
960
961 /* Face of the left fringe glyph. */
962 unsigned left_fringe_face_id : FACE_ID_BITS;
963
964 /* Face of the right fringe glyph. */
965 unsigned right_fringe_face_id : FACE_ID_BITS;
966
967 /* Vertical offset of the left fringe bitmap. */
968 signed left_fringe_offset : FRINGE_HEIGHT_BITS;
969
970 /* Vertical offset of the right fringe bitmap. */
971 signed right_fringe_offset : FRINGE_HEIGHT_BITS;
972
973 /* True means that at least one of the left and right fringe bitmaps is
974 periodic and thus depends on the y-position of the row. */
975 bool_bf fringe_bitmap_periodic_p : 1;
976
977 /* True means that we must draw the bitmaps of this row. */
978 bool_bf redraw_fringe_bitmaps_p : 1;
979
980 /* In a desired matrix, true means that this row must be updated. In a
981 current matrix, false means that the row has been invalidated, i.e.
982 the row's contents do not agree with what is visible on the
983 screen. */
984 bool_bf enabled_p : 1;
985
986 /* True means row displays a text line that is truncated on the left or
987 right side. */
988 bool_bf truncated_on_left_p : 1;
989 bool_bf truncated_on_right_p : 1;
990
991 /* True means that this row displays a continued line, i.e. it has a
992 continuation mark at the right side. */
993 bool_bf continued_p : 1;
994
995 /* False means that this row does not contain any text, i.e., it is
996 a blank line at the window and buffer end. */
997 bool_bf displays_text_p : 1;
998
999 /* True means that this line ends at ZV. */
1000 bool_bf ends_at_zv_p : 1;
1001
1002 /* True means the face of the last glyph in the text area is drawn to
1003 the right end of the window. This flag is used in
1004 update_text_area to optimize clearing to the end of the area. */
1005 bool_bf fill_line_p : 1;
1006
1007 /* True means display a bitmap on X frames indicating that this
1008 line contains no text and ends in ZV. */
1009 bool_bf indicate_empty_line_p : 1;
1010
1011 /* True means this row contains glyphs that overlap each other because
1012 of lbearing or rbearing. */
1013 bool_bf contains_overlapping_glyphs_p : 1;
1014
1015 /* True means this row is as wide as the window it is displayed in, including
1016 scroll bars, fringes, and internal borders. This also
1017 implies that the row doesn't have marginal areas. */
1018 bool_bf full_width_p : 1;
1019
1020 /* True means row is a mode or header/tab-line. */
1021 bool_bf mode_line_p : 1;
1022
1023 /* True means row is a tab-line. */
1024 bool_bf tab_line_p : 1;
1025
1026 /* True in a current row means this row is overlapped by another row. */
1027 bool_bf overlapped_p : 1;
1028
1029 /* True means this line ends in the middle of a character consisting
1030 of more than one glyph. Some glyphs have been put in this row,
1031 the rest are put in rows below this one. */
1032 bool_bf ends_in_middle_of_char_p : 1;
1033
1034 /* True means this line starts in the middle of a character consisting
1035 of more than one glyph. Some glyphs have been put in the
1036 previous row, the rest are put in this row. */
1037 bool_bf starts_in_middle_of_char_p : 1;
1038
1039 /* True in a current row means this row overlaps others. */
1040 bool_bf overlapping_p : 1;
1041
1042 /* True means some glyphs in this row are displayed in mouse-face. */
1043 bool_bf mouse_face_p : 1;
1044
1045 /* True means this row was ended by a newline from a string. */
1046 bool_bf ends_in_newline_from_string_p : 1;
1047
1048 /* True means this row width is exactly the width of the window, and the
1049 final newline character is hidden in the right fringe. */
1050 bool_bf exact_window_width_line_p : 1;
1051
1052 /* True means this row currently shows the cursor in the right fringe. */
1053 bool_bf cursor_in_fringe_p : 1;
1054
1055 /* True means the last glyph in the row is part of an ellipsis. */
1056 bool_bf ends_in_ellipsis_p : 1;
1057
1058 /* True means display a bitmap on X frames indicating that this
1059 the first line of the buffer. */
1060 bool_bf indicate_bob_p : 1;
1061
1062 /* True means display a bitmap on X frames indicating that this
1063 the top line of the window, but not start of the buffer. */
1064 bool_bf indicate_top_line_p : 1;
1065
1066 /* True means display a bitmap on X frames indicating that this
1067 the last line of the buffer. */
1068 bool_bf indicate_eob_p : 1;
1069
1070 /* True means display a bitmap on X frames indicating that this
1071 the bottom line of the window, but not end of the buffer. */
1072 bool_bf indicate_bottom_line_p : 1;
1073
1074 /* True means the row was reversed to display text in a
1075 right-to-left paragraph. */
1076 bool_bf reversed_p : 1;
1077
1078 /* Whether or not a stipple was drawn in this row at some point. */
1079 bool_bf stipple_p : 1;
1080
1081 /* Continuation lines width at the start of the row. */
1082 int continuation_lines_width;
1083
1084 #ifdef HAVE_WINDOW_SYSTEM
1085 /* Non-NULL means the current clipping area. This is temporarily
1086 set while exposing a region. Coordinates are frame-relative. */
1087 const Emacs_Rectangle *clip;
1088 #endif
1089 };
1090
1091
1092 /* Get a pointer to row number ROW in matrix MATRIX. If GLYPH_DEBUG
1093 is defined, the function matrix_row checks that we don't try to
1094 access rows that are out of bounds. */
1095
1096 #ifdef GLYPH_DEBUG
1097 struct glyph_row *matrix_row (struct glyph_matrix *, int);
1098 #define MATRIX_ROW(MATRIX, ROW) matrix_row ((MATRIX), (ROW))
1099 #else
1100 #define MATRIX_ROW(MATRIX, ROW) ((MATRIX)->rows + (ROW))
1101 #endif
1102
1103 /* Return a pointer to the row reserved for the mode line in MATRIX.
1104 Row MATRIX->nrows - 1 is always reserved for the mode line. */
1105
1106 #define MATRIX_MODE_LINE_ROW(MATRIX) \
1107 ((MATRIX)->rows + (MATRIX)->nrows - 1)
1108
1109 /* Return a pointer to the row reserved for the tab line in MATRIX.
1110 This is always the first row in MATRIX because that's the only
1111 way that works in frame-based redisplay. */
1112
1113 #define MATRIX_TAB_LINE_ROW(MATRIX) (MATRIX)->rows
1114
1115 /* Return a pointer to the row reserved for the header line in MATRIX.
1116 This is always the second row in MATRIX because that's the only
1117 way that works in frame-based redisplay. */
1118
1119 #define MATRIX_HEADER_LINE_ROW(MATRIX) \
1120 ((MATRIX)->tab_line_p ? ((MATRIX)->rows + 1) : (MATRIX)->rows)
1121
1122 /* Return a pointer to first row in MATRIX used for text display. */
1123
1124 #define MATRIX_FIRST_TEXT_ROW(MATRIX) \
1125 ((MATRIX)->rows->mode_line_p ? \
1126 (((MATRIX)->rows + 1)->mode_line_p ? \
1127 (MATRIX)->rows + 2 : (MATRIX)->rows + 1) : (MATRIX)->rows)
1128
1129 /* Return a pointer to the first glyph in the text area of a row.
1130 MATRIX is the glyph matrix accessed, and ROW is the row index in
1131 MATRIX. */
1132
1133 #define MATRIX_ROW_GLYPH_START(MATRIX, ROW) \
1134 (MATRIX_ROW ((MATRIX), (ROW))->glyphs[TEXT_AREA])
1135
1136 /* Return the number of used glyphs in the text area of a row. */
1137
1138 #define MATRIX_ROW_USED(MATRIX, ROW) \
1139 (MATRIX_ROW ((MATRIX), (ROW))->used[TEXT_AREA])
1140
1141 /* Return the character/ byte position at which the display of ROW
1142 starts. BIDI Note: this is the smallest character/byte position
1143 among characters in ROW, i.e. the first logical-order character
1144 displayed by ROW, which is not necessarily the smallest horizontal
1145 position. */
1146
1147 #define MATRIX_ROW_START_CHARPOS(ROW) ((ROW)->minpos.charpos)
1148 #define MATRIX_ROW_START_BYTEPOS(ROW) ((ROW)->minpos.bytepos)
1149
1150 /* Return the character/ byte position at which ROW ends. BIDI Note:
1151 this is the largest character/byte position among characters in
1152 ROW, i.e. the last logical-order character displayed by ROW, which
1153 is not necessarily the largest horizontal position. */
1154
1155 #define MATRIX_ROW_END_CHARPOS(ROW) ((ROW)->maxpos.charpos)
1156 #define MATRIX_ROW_END_BYTEPOS(ROW) ((ROW)->maxpos.bytepos)
1157
1158 /* Return the vertical position of ROW in MATRIX. */
1159
1160 #define MATRIX_ROW_VPOS(ROW, MATRIX) ((ROW) - (MATRIX)->rows)
1161
1162 /* Return the last glyph row + 1 in MATRIX on window W reserved for
1163 text. If W has a mode line, the last row in the matrix is reserved
1164 for it. */
1165
1166 #define MATRIX_BOTTOM_TEXT_ROW(MATRIX, W) \
1167 ((MATRIX)->rows \
1168 + (MATRIX)->nrows \
1169 - (window_wants_mode_line ((W)) ? 1 : 0))
1170
1171 /* Non-zero if the face of the last glyph in ROW's text area has
1172 to be drawn to the end of the text area. */
1173
1174 #define MATRIX_ROW_EXTENDS_FACE_P(ROW) ((ROW)->fill_line_p)
1175
1176 /* Set and query the enabled_p flag of glyph row ROW in MATRIX. */
1177
1178 #define SET_MATRIX_ROW_ENABLED_P(MATRIX, ROW, VALUE) \
1179 (MATRIX_ROW (MATRIX, ROW)->enabled_p = (VALUE))
1180
1181 #define MATRIX_ROW_ENABLED_P(MATRIX, ROW) \
1182 (MATRIX_ROW (MATRIX, ROW)->enabled_p)
1183
1184 /* Non-zero if ROW displays text. Value is non-zero if the row is
1185 blank but displays a line end. */
1186
1187 #define MATRIX_ROW_DISPLAYS_TEXT_P(ROW) ((ROW)->displays_text_p)
1188
1189
1190 /* Helper macros */
1191
1192 #define MR_PARTIALLY_VISIBLE(ROW) \
1193 ((ROW)->height != (ROW)->visible_height)
1194
1195 #define MR_PARTIALLY_VISIBLE_AT_TOP(W, ROW) \
1196 ((ROW)->y < WINDOW_TAB_LINE_HEIGHT (W) + WINDOW_HEADER_LINE_HEIGHT (W))
1197
1198 #define MR_PARTIALLY_VISIBLE_AT_BOTTOM(W, ROW) \
1199 (((ROW)->y + (ROW)->height - (ROW)->extra_line_spacing) \
1200 > WINDOW_BOX_HEIGHT_NO_MODE_LINE ((W)))
1201
1202 /* Non-zero if ROW is not completely visible in window W. */
1203
1204 #define MATRIX_ROW_PARTIALLY_VISIBLE_P(W, ROW) \
1205 (MR_PARTIALLY_VISIBLE ((ROW)) \
1206 && (MR_PARTIALLY_VISIBLE_AT_TOP ((W), (ROW)) \
1207 || MR_PARTIALLY_VISIBLE_AT_BOTTOM ((W), (ROW))))
1208
1209
1210
1211 /* Non-zero if ROW is partially visible at the top of window W. */
1212
1213 #define MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P(W, ROW) \
1214 (MR_PARTIALLY_VISIBLE ((ROW)) \
1215 && MR_PARTIALLY_VISIBLE_AT_TOP ((W), (ROW)))
1216
1217 /* Non-zero if ROW is partially visible at the bottom of window W. */
1218
1219 #define MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P(W, ROW) \
1220 (MR_PARTIALLY_VISIBLE ((ROW)) \
1221 && MR_PARTIALLY_VISIBLE_AT_BOTTOM ((W), (ROW)))
1222
1223 /* Return the bottom Y + 1 of ROW. */
1224
1225 #define MATRIX_ROW_BOTTOM_Y(ROW) ((ROW)->y + (ROW)->height)
1226
1227 /* Is ROW the last visible one in the display described by the
1228 iterator structure pointed to by IT?. */
1229
1230 #define MATRIX_ROW_LAST_VISIBLE_P(ROW, IT) \
1231 (MATRIX_ROW_BOTTOM_Y ((ROW)) >= (IT)->last_visible_y)
1232
1233 /* Non-zero if ROW displays a continuation line. */
1234
1235 #define MATRIX_ROW_CONTINUATION_LINE_P(ROW) \
1236 ((ROW)->continuation_lines_width > 0)
1237
1238 /* Non-zero if ROW ends in the middle of a character. This is the
1239 case for continued lines showing only part of a display table entry
1240 or a control char, or an overlay string. */
1241
1242 #define MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P(ROW) \
1243 ((ROW)->end.dpvec_index > 0 \
1244 || (ROW)->end.overlay_string_index >= 0 \
1245 || (ROW)->ends_in_middle_of_char_p)
1246
1247 /* Non-zero if ROW ends in the middle of an overlay string. */
1248
1249 #define MATRIX_ROW_ENDS_IN_OVERLAY_STRING_P(ROW) \
1250 ((ROW)->end.overlay_string_index >= 0)
1251
1252 /* Non-zero if ROW starts in the middle of a character. See above. */
1253
1254 #define MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P(ROW) \
1255 ((ROW)->start.dpvec_index > 0 \
1256 || (ROW)->starts_in_middle_of_char_p \
1257 || ((ROW)->start.overlay_string_index >= 0 \
1258 && (ROW)->start.string_pos.charpos > 0))
1259
1260 /* True means ROW overlaps its predecessor. */
1261
1262 #define MATRIX_ROW_OVERLAPS_PRED_P(ROW) \
1263 ((ROW)->phys_ascent > (ROW)->ascent)
1264
1265 /* True means ROW overlaps its successor. */
1266
1267 #define MATRIX_ROW_OVERLAPS_SUCC_P(ROW) \
1268 ((ROW)->phys_height - (ROW)->phys_ascent \
1269 > (ROW)->height - (ROW)->ascent)
1270
1271 /* A glyph for a space. */
1272
1273 extern struct glyph space_glyph;
1274
1275 /* True means last display completed. False means it was preempted. */
1276
1277 extern bool display_completed;
1278
1279 /************************************************************************
1280 Glyph Strings
1281 ************************************************************************/
1282
1283 /* Enumeration for overriding/changing the face to use for drawing
1284 glyphs in draw_glyphs. */
1285
1286 enum draw_glyphs_face
1287 {
1288 DRAW_NORMAL_TEXT,
1289 DRAW_INVERSE_VIDEO,
1290 DRAW_CURSOR,
1291 DRAW_MOUSE_FACE,
1292 DRAW_IMAGE_RAISED,
1293 DRAW_IMAGE_SUNKEN
1294 };
1295
1296 #ifdef HAVE_WINDOW_SYSTEM
1297
1298 /* A sequence of glyphs to be drawn in the same face. */
1299
1300 struct glyph_string
1301 {
1302 /* X-origin of the string. */
1303 int x;
1304
1305 /* Y-origin and y-position of the base line of this string. */
1306 int y, ybase;
1307
1308 /* The width of the string, not including a face extension. */
1309 int width;
1310
1311 /* The width of the string, including a face extension. */
1312 int background_width;
1313
1314 /* The height of this string. This is the height of the line this
1315 string is drawn in, and can be different from the height of the
1316 font the string is drawn in. */
1317 int height;
1318
1319 /* Number of pixels this string overwrites in front of its x-origin.
1320 This number is zero if the string has an lbearing >= 0; it is
1321 -lbearing, if the string has an lbearing < 0. */
1322 int left_overhang;
1323
1324 /* Number of pixels this string overwrites past its right-most
1325 nominal x-position, i.e. x + width. Zero if the string's
1326 rbearing is <= its nominal width, rbearing - width otherwise. */
1327 int right_overhang;
1328
1329 /* The frame on which the glyph string is drawn. */
1330 struct frame *f;
1331
1332 /* The window on which the glyph string is drawn. */
1333 struct window *w;
1334
1335 /* The glyph row for which this string was built. It determines the
1336 y-origin and height of the string. */
1337 struct glyph_row *row;
1338
1339 /* The area within row. */
1340 enum glyph_row_area area;
1341
1342 /* Characters to be drawn, and number of characters. Note that
1343 NCHARS can be zero if this is a composition glyph string, as
1344 evidenced by FIRST_GLYPH->type. */
1345 unsigned *char2b;
1346 int nchars;
1347
1348 /* A face-override for drawing cursors, mouse face and similar. */
1349 enum draw_glyphs_face hl;
1350
1351 /* Face in which this string is to be drawn. */
1352 struct face *face;
1353
1354 /* Font in which this string is to be drawn. */
1355 struct font *font;
1356
1357 /* Non-null means this string describes (part of) a static
1358 composition. */
1359 struct composition *cmp;
1360
1361 /* If not negative, this string describes a compos. */
1362 ptrdiff_t cmp_id;
1363
1364 /* Start and end glyph indices in a glyph-string. */
1365 int cmp_from, cmp_to;
1366
1367 /* True means this glyph strings face has to be drawn to the right end
1368 of the window's drawing area. */
1369 bool_bf extends_to_end_of_line_p : 1;
1370
1371 /* True means the background of this string has been drawn. */
1372 bool_bf background_filled_p : 1;
1373
1374 /* True means that the original font determined for drawing this glyph
1375 string could not be loaded. The member `font' has been set to
1376 the frame's default font in this case. */
1377 bool_bf font_not_found_p : 1;
1378
1379 /* True means that the face in which this glyph string is drawn has a
1380 stipple pattern. */
1381 bool_bf stippled_p : 1;
1382
1383 #define OVERLAPS_PRED (1 << 0)
1384 #define OVERLAPS_SUCC (1 << 1)
1385 #define OVERLAPS_BOTH (OVERLAPS_PRED | OVERLAPS_SUCC)
1386 #define OVERLAPS_ERASED_CURSOR (1 << 2)
1387 /* Non-zero means only the foreground of this glyph string must be
1388 drawn, and we should use the physical height of the line this
1389 glyph string appears in as clip rect. If the value is
1390 OVERLAPS_ERASED_CURSOR, the clip rect is restricted to the rect
1391 of the erased cursor. OVERLAPS_PRED and OVERLAPS_SUCC mean we
1392 draw overlaps with the preceding and the succeeding rows,
1393 respectively. */
1394 unsigned for_overlaps : 3;
1395
1396 /* True means that all glyphs in this glyph string has the flag
1397 padding_p set, and thus must be drawn one by one to have 1-pixel
1398 width even though the logical width in the font is zero. */
1399 bool_bf padding_p : 1;
1400
1401 /* The GC to use for drawing this glyph string. */
1402 #if defined (HAVE_X_WINDOWS)
1403 GC gc;
1404 #endif
1405 #if defined (HAVE_NTGUI)
1406 Emacs_GC *gc;
1407 HDC hdc;
1408 #endif
1409 #if defined (HAVE_PGTK)
1410 Emacs_GC xgcv;
1411 #endif
1412
1413 /* A pointer to the first glyph in the string. This glyph
1414 corresponds to char2b[0]. Needed to draw rectangles if
1415 font_not_found_p is true. */
1416 struct glyph *first_glyph;
1417
1418 /* Image, if any. */
1419 struct image *img;
1420
1421 /* Xwidget. */
1422 struct xwidget *xwidget;
1423
1424 /* Slice */
1425 struct glyph_slice slice;
1426
1427 /* Non-null means the horizontal clipping region starts from the
1428 left edge of *clip_head, and ends with the right edge of
1429 *clip_tail, not including their overhangs. */
1430 struct glyph_string *clip_head, *clip_tail;
1431
1432 /* The current clipping areas. */
1433 NativeRectangle clip[2];
1434
1435 /* Number of clipping areas. */
1436 int num_clips;
1437
1438 int underline_position;
1439
1440 int underline_thickness;
1441
1442 struct glyph_string *next, *prev;
1443 };
1444
1445 #endif /* HAVE_WINDOW_SYSTEM */
1446
1447
1448 /************************************************************************
1449 Display Dimensions
1450 ************************************************************************/
1451
1452 /* Return the height of the mode line in glyph matrix MATRIX, or zero
1453 if not known. This macro is called under circumstances where
1454 MATRIX might not have been allocated yet. */
1455
1456 #define MATRIX_MODE_LINE_HEIGHT(MATRIX) \
1457 ((MATRIX) && (MATRIX)->rows \
1458 ? MATRIX_MODE_LINE_ROW (MATRIX)->height \
1459 : 0)
1460
1461 /* Return the height of the header line in glyph matrix MATRIX, or zero
1462 if not known. This macro is called under circumstances where
1463 MATRIX might not have been allocated yet. */
1464
1465 #define MATRIX_HEADER_LINE_HEIGHT(MATRIX) \
1466 ((MATRIX) && (MATRIX)->rows \
1467 ? MATRIX_HEADER_LINE_ROW (MATRIX)->height \
1468 : 0)
1469
1470 /* Return the height of the tab line in glyph matrix MATRIX, or zero
1471 if not known. This macro is called under circumstances where
1472 MATRIX might not have been allocated yet. */
1473
1474 #define MATRIX_TAB_LINE_HEIGHT(MATRIX) \
1475 ((MATRIX) && (MATRIX)->rows \
1476 ? MATRIX_TAB_LINE_ROW (MATRIX)->height \
1477 : 0)
1478
1479 /* Return the desired face id for the mode line of a window, depending
1480 on whether the window is selected or not, or if the window is the
1481 scrolling window for the currently active minibuffer window.
1482
1483 Due to the way display_mode_lines manipulates with the contents of
1484 selected_window, this macro needs three arguments: SELW which is
1485 compared against the current value of selected_window, MBW which is
1486 compared against minibuf_window (if SELW doesn't match), and SCRW
1487 which is compared against minibuf_selected_window (if MBW matches). */
1488
1489 #define CURRENT_MODE_LINE_ACTIVE_FACE_ID_3(SELW, MBW, SCRW) \
1490 ((!mode_line_in_non_selected_windows \
1491 || (SELW) == XWINDOW (selected_window) \
1492 || (minibuf_level > 0 \
1493 && !NILP (minibuf_selected_window) \
1494 && (MBW) == XWINDOW (minibuf_window) \
1495 && (SCRW) == XWINDOW (minibuf_selected_window))) \
1496 ? MODE_LINE_ACTIVE_FACE_ID \
1497 : MODE_LINE_INACTIVE_FACE_ID)
1498
1499
1500 /* Return the desired face id for the mode line of window W. */
1501
1502 #define CURRENT_MODE_LINE_ACTIVE_FACE_ID(W) \
1503 (CURRENT_MODE_LINE_ACTIVE_FACE_ID_3((W), \
1504 XWINDOW (selected_window), \
1505 (W)))
1506
1507 /* Return the current height of the mode line of window W. If not known
1508 from W->mode_line_height, look at W's current glyph matrix, or return
1509 a default based on the height of the font of the face `mode-line'. */
1510
1511 #define CURRENT_MODE_LINE_HEIGHT(W) \
1512 ((W)->mode_line_height >= 0 \
1513 ? (W)->mode_line_height \
1514 : ((W)->mode_line_height \
1515 = (MATRIX_MODE_LINE_HEIGHT ((W)->current_matrix) \
1516 ? MATRIX_MODE_LINE_HEIGHT ((W)->current_matrix) \
1517 : estimate_mode_line_height \
1518 (XFRAME ((W)->frame), CURRENT_MODE_LINE_ACTIVE_FACE_ID (W)))))
1519
1520 /* Return the current height of the header line of window W. If not known
1521 from W->header_line_height, look at W's current glyph matrix, or return
1522 an estimation based on the height of the font of the face `header-line'. */
1523
1524 #define CURRENT_HEADER_LINE_HEIGHT(W) \
1525 ((W)->header_line_height >= 0 \
1526 ? (W)->header_line_height \
1527 : ((W)->header_line_height \
1528 = (MATRIX_HEADER_LINE_HEIGHT ((W)->current_matrix) \
1529 ? MATRIX_HEADER_LINE_HEIGHT ((W)->current_matrix) \
1530 : estimate_mode_line_height \
1531 (XFRAME ((W)->frame), HEADER_LINE_FACE_ID))))
1532
1533 /* Return the current height of the tab line of window W. If not known
1534 from W->tab_line_height, look at W's current glyph matrix, or return
1535 an estimation based on the height of the font of the face `tab-line'. */
1536
1537 #define CURRENT_TAB_LINE_HEIGHT(W) \
1538 ((W)->tab_line_height >= 0 \
1539 ? (W)->tab_line_height \
1540 : ((W)->tab_line_height \
1541 = (MATRIX_TAB_LINE_HEIGHT ((W)->current_matrix) \
1542 ? MATRIX_TAB_LINE_HEIGHT ((W)->current_matrix) \
1543 : estimate_mode_line_height \
1544 (XFRAME ((W)->frame), TAB_LINE_FACE_ID))))
1545
1546 /* Return the height of the desired mode line of window W. */
1547
1548 #define DESIRED_MODE_LINE_HEIGHT(W) \
1549 MATRIX_MODE_LINE_HEIGHT ((W)->desired_matrix)
1550
1551 /* Return the height of the desired header line of window W. */
1552
1553 #define DESIRED_HEADER_LINE_HEIGHT(W) \
1554 MATRIX_HEADER_LINE_HEIGHT ((W)->desired_matrix)
1555
1556 /* Return the height of the desired tab line of window W. */
1557
1558 #define DESIRED_TAB_LINE_HEIGHT(W) \
1559 MATRIX_TAB_LINE_HEIGHT ((W)->desired_matrix)
1560
1561 /* Return proper value to be used as baseline offset of font that has
1562 ASCENT and DESCENT to draw characters by the font at the vertical
1563 center of the line of frame F.
1564
1565 Here, our task is to find the value of BOFF in the following figure;
1566
1567 -------------------------+-----------+-
1568 -+-+---------+-+ | |
1569 | | | | | |
1570 | | | | F_ASCENT F_HEIGHT
1571 | | | ASCENT | |
1572 HEIGHT | | | | |
1573 | | |-|-+------+-----------|------- baseline
1574 | | | | BOFF | |
1575 | |---------|-+-+ | |
1576 | | | DESCENT | |
1577 -+-+---------+-+ F_DESCENT |
1578 -------------------------+-----------+-
1579
1580 -BOFF + DESCENT + (F_HEIGHT - HEIGHT) / 2 = F_DESCENT
1581 BOFF = DESCENT + (F_HEIGHT - HEIGHT) / 2 - F_DESCENT
1582 DESCENT = FONT->descent
1583 HEIGHT = FONT_HEIGHT (FONT)
1584 F_DESCENT = (FRAME_FONT (F)->descent
1585 - F->terminal->output_data.x->baseline_offset)
1586 F_HEIGHT = FRAME_LINE_HEIGHT (F)
1587 */
1588
1589 #define VCENTER_BASELINE_OFFSET(FONT, F) \
1590 (FONT_DESCENT (FONT) \
1591 + (FRAME_LINE_HEIGHT ((F)) - FONT_HEIGHT ((FONT)) \
1592 + (FRAME_LINE_HEIGHT ((F)) > FONT_HEIGHT ((FONT)))) / 2 \
1593 - (FONT_DESCENT (FRAME_FONT (F)) - FRAME_BASELINE_OFFSET (F)))
1594
1595 /* A heuristic test for fonts that claim they need a preposterously
1596 large vertical space. The heuristics is in the factor of 3. We
1597 ignore the ascent and descent values reported by such fonts, and
1598 instead go by the values reported for individual glyphs. */
1599 #define FONT_TOO_HIGH(ft) \
1600 ((ft)->pixel_size > 0 && (ft)->ascent + (ft)->descent > 3*(ft)->pixel_size)
1601
1602
1603 /***********************************************************************
1604 Faces
1605 ***********************************************************************/
1606
1607 /* Indices of face attributes in Lisp face vectors. Slot zero is the
1608 symbol `face'. */
1609
1610 enum lface_attribute_index
1611 {
1612 LFACE_FAMILY_INDEX = 1,
1613 LFACE_FOUNDRY_INDEX,
1614 LFACE_SWIDTH_INDEX,
1615 LFACE_HEIGHT_INDEX,
1616 LFACE_WEIGHT_INDEX,
1617 LFACE_SLANT_INDEX,
1618 LFACE_UNDERLINE_INDEX,
1619 LFACE_INVERSE_INDEX,
1620 LFACE_FOREGROUND_INDEX,
1621 LFACE_BACKGROUND_INDEX,
1622 LFACE_STIPPLE_INDEX,
1623 LFACE_OVERLINE_INDEX,
1624 LFACE_STRIKE_THROUGH_INDEX,
1625 LFACE_BOX_INDEX,
1626 LFACE_FONT_INDEX,
1627 LFACE_INHERIT_INDEX,
1628 LFACE_FONTSET_INDEX,
1629 LFACE_DISTANT_FOREGROUND_INDEX,
1630 LFACE_EXTEND_INDEX,
1631 LFACE_VECTOR_SIZE
1632 };
1633
1634
1635 /* Box types of faces. */
1636
1637 enum face_box_type
1638 {
1639 /* No box around text. */
1640 FACE_NO_BOX,
1641
1642 /* Simple box of specified width and color. Default width is 1, and
1643 default color is the foreground color of the face. */
1644 FACE_SIMPLE_BOX,
1645
1646 /* Boxes with 3D shadows. Color equals the background color of the
1647 face. Width is specified. */
1648 FACE_RAISED_BOX,
1649 FACE_SUNKEN_BOX
1650 };
1651
1652 /* Underline type. */
1653
1654 enum face_underline_type
1655 {
1656 FACE_NO_UNDERLINE = 0,
1657 FACE_UNDER_LINE,
1658 FACE_UNDER_WAVE
1659 };
1660
1661 /* Structure describing a realized face.
1662
1663 For each Lisp face, 0..N realized faces can exist for different
1664 frames and different charsets. Realized faces are built from Lisp
1665 faces and text properties/overlays by merging faces and adding
1666 unspecified attributes from the `default' face. */
1667
1668 struct face
1669 {
1670 /* The Lisp face attributes this face realizes. All attributes
1671 in this vector are non-nil. */
1672 Lisp_Object lface[LFACE_VECTOR_SIZE];
1673
1674 /* The id of this face. The id equals the index of this face in the
1675 vector faces_by_id of its face cache. */
1676 int id;
1677
1678 #ifdef HAVE_WINDOW_SYSTEM
1679
1680 /* If non-zero, this is a GC that we can use without modification for
1681 drawing the characters in this face. */
1682 # ifdef HAVE_X_WINDOWS
1683 GC gc;
1684 # else
1685 Emacs_GC *gc;
1686 # endif
1687 /* Background stipple or bitmap used for this face. This is
1688 an id as returned from load_pixmap. */
1689 ptrdiff_t stipple;
1690
1691 #endif /* not HAVE_WINDOW_SYSTEM */
1692
1693 /* Pixel value of foreground color for X frames. Color index
1694 for tty frames. */
1695 unsigned long foreground;
1696
1697 /* Pixel value or color index of background color. */
1698 unsigned long background;
1699
1700 /* Pixel value or color index of underline, overlined,
1701 strike-through, or box color. */
1702 unsigned long underline_color;
1703 unsigned long overline_color;
1704 unsigned long strike_through_color;
1705 unsigned long box_color;
1706
1707 struct font *font;
1708
1709 /* Fontset ID if for this face's fontset. Non-ASCII faces derived
1710 from the same ASCII face have the same fontset. */
1711 int fontset;
1712
1713 /* Non-zero means characters in this face have a box of that
1714 thickness around them. Vertical (left and right) and horizontal
1715 (top and bottom) borders size can be set separately using an
1716 associated list of two ints in the form
1717 (vertical_size . horizontal_size). In case one of the value is
1718 negative, its absolute value indicates the thickness, and the
1719 borders of box are drawn inside of the character glyphs' area
1720 potentially over the glyph itself but the glyph drawing size is
1721 not increase. If a (signed) int N is use instead of a list, it
1722 is the same as setting ( abs(N) . N ) values. */
1723 int box_vertical_line_width;
1724 int box_horizontal_line_width;
1725
1726
1727 /* The amount of pixels above the descent line the underline should
1728 be displayed. It does not take effect unless
1729 `underline_at_descent_line_p` is t. */
1730 int underline_pixels_above_descent_line;
1731
1732 /* Type of box drawn. A value of FACE_NO_BOX means no box is drawn
1733 around text in this face. A value of FACE_SIMPLE_BOX means a box
1734 of width box_line_width is drawn in color box_color. A value of
1735 FACE_RAISED_BOX or FACE_SUNKEN_BOX means a 3D box is drawn with
1736 shadow colors derived from the background color of the face. */
1737 ENUM_BF (face_box_type) box : 2;
1738
1739 /* Style of underlining. */
1740 ENUM_BF (face_underline_type) underline : 2;
1741
1742 /* If `box' above specifies a 3D type, true means use box_color for
1743 drawing shadows. */
1744 bool_bf use_box_color_for_shadows_p : 1;
1745
1746 /* Non-zero if text in this face should be underlined, overlined,
1747 strike-through or have a box drawn around it. */
1748 bool_bf overline_p : 1;
1749 bool_bf strike_through_p : 1;
1750
1751 /* True means that the colors specified for this face could not be
1752 loaded, and were replaced by default colors, so they shouldn't be
1753 freed. */
1754 bool_bf foreground_defaulted_p : 1;
1755 bool_bf background_defaulted_p : 1;
1756
1757 /* True means that either no color is specified for the corresponding
1758 attribute or that the specified color couldn't be loaded.
1759 Use the foreground color when drawing in that case. */
1760 bool_bf underline_defaulted_p : 1;
1761 bool_bf overline_color_defaulted_p : 1;
1762 bool_bf strike_through_color_defaulted_p : 1;
1763 bool_bf box_color_defaulted_p : 1;
1764
1765 /* True means the underline should be drawn at the descent line. */
1766 bool_bf underline_at_descent_line_p : 1;
1767
1768 /* TTY appearances. Colors are found in `lface' with empty color
1769 string meaning the default color of the TTY. */
1770 bool_bf tty_bold_p : 1;
1771 bool_bf tty_italic_p : 1;
1772 bool_bf tty_underline_p : 1;
1773 bool_bf tty_reverse_p : 1;
1774 bool_bf tty_strike_through_p : 1;
1775
1776 /* True means that colors of this face may not be freed because they
1777 have been copied bitwise from a base face (see
1778 realize_gui_face). */
1779 bool_bf colors_copied_bitwise_p : 1;
1780
1781 /* If non-zero, use overstrike (to simulate bold-face). */
1782 bool_bf overstrike : 1;
1783
1784 /* NOTE: this is not used yet, but eventually this impl should be done
1785 similarly to overstrike */
1786 #ifdef HAVE_NS
1787 /* If non-zero, use geometric rotation (to simulate italic). */
1788 bool_bf synth_ital : 1;
1789 #endif
1790
1791 /* The hash value of this face. */
1792 uintptr_t hash;
1793
1794 /* Next and previous face in hash collision list of face cache. */
1795 struct face *next, *prev;
1796
1797 /* If this face is an ASCII face, this points to this face itself.
1798 Otherwise, this points to an ASCII face that has the same
1799 attributes except the font. */
1800 struct face *ascii_face;
1801
1802 #if defined HAVE_XFT || defined HAVE_FREETYPE
1803 /* Extra member that a font-driver uses privately. */
1804 void *extra;
1805 #endif
1806 };
1807
1808
1809 /* Color index indicating that face uses a terminal's default color. */
1810
1811 #define FACE_TTY_DEFAULT_COLOR ((unsigned long) -1)
1812
1813 /* Color index indicating that face uses an unknown foreground color. */
1814
1815 #define FACE_TTY_DEFAULT_FG_COLOR ((unsigned long) -2)
1816
1817 /* Color index indicating that face uses an unknown background color. */
1818
1819 #define FACE_TTY_DEFAULT_BG_COLOR ((unsigned long) -3)
1820
1821 /* True if COLOR is a specified (i.e., nondefault) foreground or
1822 background color for a tty face. */
1823
1824 INLINE bool
1825 face_tty_specified_color (unsigned long color)
1826 {
1827 return color < FACE_TTY_DEFAULT_BG_COLOR;
1828 }
1829
1830 /* Non-zero if FACE was realized for unibyte use. */
1831
1832 #define FACE_UNIBYTE_P(FACE) ((FACE)->charset < 0)
1833
1834
1835 /* IDs of important faces known by the C face code. These are the IDs
1836 of the faces for CHARSET_ASCII. */
1837
1838 enum face_id
1839 {
1840 DEFAULT_FACE_ID,
1841 MODE_LINE_ACTIVE_FACE_ID,
1842 MODE_LINE_INACTIVE_FACE_ID,
1843 TOOL_BAR_FACE_ID,
1844 FRINGE_FACE_ID,
1845 HEADER_LINE_FACE_ID,
1846 SCROLL_BAR_FACE_ID,
1847 BORDER_FACE_ID,
1848 CURSOR_FACE_ID,
1849 MOUSE_FACE_ID,
1850 MENU_FACE_ID,
1851 VERTICAL_BORDER_FACE_ID,
1852 WINDOW_DIVIDER_FACE_ID,
1853 WINDOW_DIVIDER_FIRST_PIXEL_FACE_ID,
1854 WINDOW_DIVIDER_LAST_PIXEL_FACE_ID,
1855 INTERNAL_BORDER_FACE_ID,
1856 CHILD_FRAME_BORDER_FACE_ID,
1857 TAB_BAR_FACE_ID,
1858 TAB_LINE_FACE_ID,
1859 BASIC_FACE_ID_SENTINEL
1860 };
1861
1862 #define MAX_FACE_ID ((1 << FACE_ID_BITS) - 1)
1863
1864 /* A cache of realized faces. Each frame has its own cache because
1865 Emacs allows different frame-local face definitions. */
1866
1867 struct face_cache
1868 {
1869 /* Hash table of cached realized faces. */
1870 struct face **buckets;
1871
1872 /* Back-pointer to the frame this cache belongs to. */
1873 struct frame *f;
1874
1875 /* A vector of faces so that faces can be referenced by an ID. */
1876 struct face **faces_by_id;
1877
1878 /* The allocated size, and number of used slots of faces_by_id. */
1879 ptrdiff_t size;
1880 int used;
1881
1882 /* Flag indicating that attributes of the `menu' face have been
1883 changed. */
1884 bool_bf menu_face_changed_p : 1;
1885 };
1886
1887 #define FACE_EXTENSIBLE_P(F) \
1888 (!NILP (F->lface[LFACE_EXTEND_INDEX]))
1889
1890 /* True if FACE is suitable for displaying ASCII characters. */
1891 INLINE bool
1892 FACE_SUITABLE_FOR_ASCII_CHAR_P (struct face *face)
1893 {
1894 #ifdef HAVE_WINDOW_SYSTEM
1895 return face == face->ascii_face;
1896 #else
1897 return true;
1898 #endif
1899 }
1900
1901 /* Return the id of the realized face on frame F that is like the face
1902 FACE, but is suitable for displaying character CHARACTER at buffer or
1903 string position POS. OBJECT is the string object, or nil for
1904 buffer. This macro is only meaningful for multibyte character
1905 CHAR. */
1906 INLINE int
1907 FACE_FOR_CHAR (struct frame *f, struct face *face, int character,
1908 ptrdiff_t pos, Lisp_Object object)
1909 {
1910 #ifdef HAVE_WINDOW_SYSTEM
1911 return face_for_char (f, face, character, pos, object);
1912 #else
1913 return face->id;
1914 #endif
1915 }
1916
1917 /* Return true if G contains a valid character code. */
1918 INLINE bool
1919 GLYPH_CHAR_VALID_P (GLYPH g)
1920 {
1921 return CHAR_VALID_P (GLYPH_CHAR (g));
1922 }
1923
1924 /* The glyph code from a display vector may either be an integer which
1925 encodes a char code in the lower CHARACTERBITS bits and a (very small)
1926 face-id in the upper bits, or it may be a cons (CHAR . FACE-ID). */
1927
1928 INLINE bool
1929 GLYPH_CODE_P (Lisp_Object gc)
1930 {
1931 return (CONSP (gc)
1932 ? (CHARACTERP (XCAR (gc))
1933 && RANGED_FIXNUMP (0, XCDR (gc), MAX_FACE_ID))
1934 : (RANGED_FIXNUMP
1935 (0, gc,
1936 (MAX_FACE_ID < TYPE_MAXIMUM (EMACS_INT) >> CHARACTERBITS
1937 ? ((EMACS_INT) MAX_FACE_ID << CHARACTERBITS) | MAX_CHAR
1938 : TYPE_MAXIMUM (EMACS_INT)))));
1939 }
1940
1941 /* True means face attributes have been changed since the last
1942 redisplay. Used in redisplay_internal. */
1943
1944 extern bool face_change;
1945
1946 /* For reordering of bidirectional text. */
1947
1948 /* UAX#9's max_depth value. */
1949 #define BIDI_MAXDEPTH 125
1950
1951 /* Data type for describing the bidirectional character types. The
1952 first 7 must be at the beginning, because they are the only values
1953 valid in the `bidi_type' member of `struct glyph'; we only reserve
1954 3 bits for it, so we cannot use there values larger than 7.
1955
1956 The order of members must be in sync with the 8th element of the
1957 member of unidata-prop-alist (in admin/unidata/unidata-gen.el) for
1958 Unicode character property `bidi-class'. */
1959 typedef enum {
1960 UNKNOWN_BT = 0,
1961 STRONG_L, /* strong left-to-right */
1962 STRONG_R, /* strong right-to-left */
1963 WEAK_EN, /* european number */
1964 WEAK_AN, /* arabic number */
1965 WEAK_BN, /* boundary neutral */
1966 NEUTRAL_B, /* paragraph separator */
1967 STRONG_AL, /* arabic right-to-left letter */
1968 LRE, /* left-to-right embedding */
1969 LRO, /* left-to-right override */
1970 RLE, /* right-to-left embedding */
1971 RLO, /* right-to-left override */
1972 PDF, /* pop directional format */
1973 LRI, /* left-to-right isolate */
1974 RLI, /* right-to-left isolate */
1975 FSI, /* first strong isolate */
1976 PDI, /* pop directional isolate */
1977 WEAK_ES, /* european number separator */
1978 WEAK_ET, /* european number terminator */
1979 WEAK_CS, /* common separator */
1980 WEAK_NSM, /* non-spacing mark */
1981 NEUTRAL_S, /* segment separator */
1982 NEUTRAL_WS, /* whitespace */
1983 NEUTRAL_ON /* other neutrals */
1984 } bidi_type_t;
1985
1986 /* Data type for describing the Bidi Paired Bracket Type of a character.
1987
1988 The order of members must be in sync with the 8th element of the
1989 member of unidata-prop-alist (in admin/unidata/unidata-gen.el) for
1990 Unicode character property `bracket-type'. */
1991 typedef enum {
1992 BIDI_BRACKET_NONE = 1,
1993 BIDI_BRACKET_OPEN,
1994 BIDI_BRACKET_CLOSE
1995 } bidi_bracket_type_t;
1996
1997 /* The basic directionality data type. */
1998 typedef enum { NEUTRAL_DIR = 0, L2R, R2L } bidi_dir_t;
1999
2000 /* Data type for storing information about characters we need to
2001 remember. */
2002 struct bidi_saved_info {
2003 ptrdiff_t charpos; /* character's buffer position */
2004 bidi_type_t type; /* character's resolved bidi type */
2005 bidi_type_t orig_type; /* bidi type as we found it in the buffer */
2006 };
2007
2008 /* Data type for keeping track of information about saved embedding
2009 levels, override status, isolate status, and isolating sequence
2010 runs. This should be as tightly packed as possible, because there
2011 are 127 such entries in each iterator state, and so the size of
2012 cache is directly affected by the size of this struct. */
2013 struct bidi_stack {
2014 ptrdiff_t next_for_neutral_pos;
2015 unsigned next_for_neutral_type : 3;
2016 unsigned last_strong_type : 3;
2017 unsigned prev_for_neutral_type : 3;
2018 unsigned char level;
2019 unsigned char flags; /* sos, override, isolate_status */
2020 };
2021
2022 /* Data type for storing information about a string being iterated on. */
2023 struct bidi_string_data {
2024 Lisp_Object lstring; /* Lisp string to reorder, or nil */
2025 const unsigned char *s; /* string data, or NULL if reordering buffer */
2026 ptrdiff_t schars; /* the number of characters in the string,
2027 excluding the terminating null */
2028 ptrdiff_t bufpos; /* buffer position of lstring, or 0 if N/A */
2029 bool_bf from_disp_str : 1; /* True means the string comes from a
2030 display property */
2031 bool_bf unibyte : 1; /* True means the string is unibyte */
2032 };
2033
2034 /* Data type for reordering bidirectional text. */
2035 struct bidi_it {
2036 ptrdiff_t bytepos; /* iterator's position in buffer/string */
2037 ptrdiff_t charpos;
2038 int ch; /* character at that position, or u+FFFC
2039 ("object replacement character") for a run
2040 of characters covered by a display string */
2041 ptrdiff_t nchars; /* its "length", usually 1; it's > 1 for a run
2042 of characters covered by a display string */
2043 ptrdiff_t ch_len; /* its length in bytes */
2044 bidi_type_t type; /* final bidi type of this character, after
2045 resolving weak and neutral types */
2046 bidi_type_t type_after_wn; /* bidi type after overrides and Wn */
2047 bidi_type_t orig_type; /* original bidi type, as found in the buffer */
2048 signed char resolved_level; /* final resolved level of this character */
2049 signed char isolate_level; /* count of isolate initiators unmatched by PDI */
2050 ptrdiff_t invalid_levels; /* how many PDFs to ignore */
2051 ptrdiff_t invalid_isolates; /* how many PDIs to ignore */
2052 struct bidi_saved_info prev; /* info about previous character */
2053 struct bidi_saved_info last_strong; /* last-seen strong directional char */
2054 struct bidi_saved_info next_for_neutral; /* surrounding characters for... */
2055 struct bidi_saved_info prev_for_neutral; /* ...resolving neutrals */
2056 struct bidi_saved_info next_for_ws; /* character after sequence of ws */
2057 ptrdiff_t bracket_pairing_pos; /* position of pairing bracket */
2058 bidi_type_t bracket_enclosed_type; /* type for bracket resolution */
2059 ptrdiff_t next_en_pos; /* pos. of next char for determining ET type */
2060 bidi_type_t next_en_type; /* type of char at next_en_pos */
2061 bidi_dir_t sos; /* direction of start-of-sequence in effect */
2062 int scan_dir; /* direction of text scan, 1: forw, -1: back */
2063 ptrdiff_t disp_pos; /* position of display string after ch */
2064 int disp_prop; /* if non-zero, there really is a
2065 `display' property/string at disp_pos;
2066 if 2, the property is a `space' spec */
2067 int stack_idx; /* index of current data on the stack */
2068 /* Note: Everything from here on is not copied/saved when the bidi
2069 iterator state is saved, pushed, or popped. So only put here
2070 stuff that is not part of the bidi iterator's state! */
2071 struct bidi_stack level_stack[BIDI_MAXDEPTH+2+1]; /* directional status stack */
2072 struct bidi_string_data string; /* string to reorder */
2073 struct window *w; /* the window being displayed */
2074 bidi_dir_t paragraph_dir; /* current paragraph direction */
2075 ptrdiff_t separator_limit; /* where paragraph separator should end */
2076 bool_bf first_elt : 1; /* if true, examine current char first */
2077 bool_bf new_paragraph : 1; /* if true, we expect a new paragraph */
2078 bool_bf frame_window_p : 1; /* true if displaying on a GUI frame */
2079 };
2080
2081 /* Value is non-zero when the bidi iterator is at base paragraph
2082 embedding level. */
2083 #define BIDI_AT_BASE_LEVEL(BIDI_IT) \
2084 ((BIDI_IT).resolved_level == (BIDI_IT).level_stack[0].level)
2085
2086
2087 /***********************************************************************
2088 Fringes
2089 ***********************************************************************/
2090
2091 /* Structure used to describe where and how to draw a fringe bitmap.
2092 WHICH is the fringe bitmap to draw. WD and H is the (adjusted)
2093 width and height of the bitmap, DH is the height adjustment (if
2094 bitmap is periodic). X and Y are frame coordinates of the area to
2095 display the bitmap, DY is relative offset of the bitmap into that
2096 area. BX, NX, BY, NY specifies the area to clear if the bitmap
2097 does not fill the entire area. FACE is the fringe face. */
2098
2099 struct draw_fringe_bitmap_params
2100 {
2101 int which; /* enum fringe_bitmap_type */
2102 unsigned short *bits;
2103 int wd, h, dh;
2104 int x, y;
2105 int bx, nx, by, ny;
2106 bool_bf cursor_p : 1;
2107 bool_bf overlay_p : 1;
2108 struct face *face;
2109 };
2110
2111 #define MAX_FRINGE_BITMAPS (1<<FRINGE_ID_BITS)
2112
2113
2114 /***********************************************************************
2115 Display Iterator
2116 ***********************************************************************/
2117
2118 /* Iteration over things to display in current_buffer or in a string.
2119
2120 The iterator handles:
2121
2122 1. Overlay strings (after-string, before-string).
2123 2. Face properties.
2124 3. Invisible text properties.
2125 4. Selective display.
2126 5. Translation of characters via display tables.
2127 6. Translation of control characters to the forms `\003' or `^C'.
2128 7. `glyph' and `space-width' properties.
2129
2130 Iterators are initialized by calling init_iterator or one of the
2131 equivalent functions below. A call to get_next_display_element
2132 loads the iterator structure with information about what next to
2133 display. A call to set_iterator_to_next increments the iterator's
2134 position.
2135
2136 Characters from overlay strings, display table entries or control
2137 character translations are returned one at a time. For example, if
2138 we have a text of `a\x01' where `a' has a display table definition
2139 of `cd' and the control character is displayed with a leading
2140 arrow, then the iterator will return:
2141
2142 Call Return Source Call next
2143 -----------------------------------------------------------------
2144 next c display table move
2145 next d display table move
2146 next ^ control char move
2147 next A control char move
2148
2149 The same mechanism is also used to return characters for ellipses
2150 displayed at the end of invisible text.
2151
2152 CAVEAT: Under some circumstances, move_.* functions can be called
2153 asynchronously, e.g. when computing a buffer position from an x and
2154 y pixel position. This means that these functions and functions
2155 called from them SHOULD NOT USE xmalloc and alike. See also the
2156 comment at the start of xdisp.c. */
2157
2158 /* Enumeration describing what kind of display element an iterator is
2159 loaded with after a call to get_next_display_element. */
2160
2161 enum display_element_type
2162 {
2163 /* A normal character. */
2164 IT_CHARACTER,
2165
2166 /* A composition (static and automatic). */
2167 IT_COMPOSITION,
2168
2169 /* A glyphless character (e.g. ZWNJ, LRE). */
2170 IT_GLYPHLESS,
2171
2172 /* An image. */
2173 IT_IMAGE,
2174
2175 /* A flexible width and height space. */
2176 IT_STRETCH,
2177
2178 /* End of buffer or string. */
2179 IT_EOB,
2180
2181 /* Truncation glyphs. Never returned by get_next_display_element.
2182 Used to get display information about truncation glyphs via
2183 produce_glyphs. */
2184 IT_TRUNCATION,
2185
2186 /* Continuation glyphs. See the comment for IT_TRUNCATION. */
2187 IT_CONTINUATION,
2188
2189 /* Xwidget. */
2190 IT_XWIDGET
2191 };
2192
2193
2194 /* An enumerator for each text property that has a meaning for display
2195 purposes. */
2196
2197 enum prop_idx
2198 {
2199 FONTIFIED_PROP_IDX,
2200 FACE_PROP_IDX,
2201 INVISIBLE_PROP_IDX,
2202 DISPLAY_PROP_IDX,
2203 COMPOSITION_PROP_IDX,
2204
2205 /* Not a property. Used to indicate changes in overlays. */
2206 OVERLAY_PROP_IDX,
2207
2208 /* Sentinel. */
2209 LAST_PROP_IDX
2210 };
2211
2212 /* An enumerator for the method of wrapping long lines. */
2213
2214 enum line_wrap_method
2215 {
2216 TRUNCATE,
2217 WORD_WRAP,
2218 WINDOW_WRAP
2219 };
2220
2221 /* An enumerator for the method of displaying glyphless characters. */
2222
2223 enum glyphless_display_method
2224 {
2225 /* Display a thin (1-pixel width) space. On a TTY, display a
2226 1-character width space. */
2227 GLYPHLESS_DISPLAY_THIN_SPACE,
2228 /* Display an empty box of proper width. */
2229 GLYPHLESS_DISPLAY_EMPTY_BOX,
2230 /* Display an acronym string in a box. */
2231 GLYPHLESS_DISPLAY_ACRONYM,
2232 /* Display the hexadecimal code of the character in a box. */
2233 GLYPHLESS_DISPLAY_HEX_CODE
2234 };
2235
2236 struct it_slice
2237 {
2238 Lisp_Object x;
2239 Lisp_Object y;
2240 Lisp_Object width;
2241 Lisp_Object height;
2242 };
2243
2244 /* Input sources for fetching characters or data to display.
2245 The input source is found in the `method' field. */
2246
2247 enum it_method {
2248 GET_FROM_BUFFER = 0,
2249 GET_FROM_DISPLAY_VECTOR,
2250 GET_FROM_STRING,
2251 GET_FROM_C_STRING,
2252 GET_FROM_IMAGE,
2253 GET_FROM_STRETCH,
2254 GET_FROM_XWIDGET,
2255 NUM_IT_METHODS
2256 };
2257
2258 /* FIXME: What is this? Why 5? */
2259 #define IT_STACK_SIZE 5
2260
2261 /* Iterator for composition (both for static and automatic). */
2262 struct composition_it
2263 {
2264 /* Next position at which to check the composition. */
2265 ptrdiff_t stop_pos;
2266 /* ID number of the composition or glyph-string. If negative, we
2267 are not iterating over a composition now. */
2268 ptrdiff_t id;
2269 /* If non-negative, character that triggers the automatic
2270 composition at `stop_pos', and this is an automatic composition.
2271 If negative, this is a static composition. This is set to -2
2272 temporarily if searching of composition reach a limit or a
2273 newline. */
2274 int ch;
2275 /* If this is an automatic composition, index of a rule for making
2276 the automatic composition. Provided that ELT is an element of
2277 Vcomposition_function_table for CH, (nth ELT RULE_IDX) is the
2278 rule for the composition. */
2279 EMACS_INT rule_idx;
2280 /* If this is an automatic composition, how many characters to look
2281 back from the position where a character triggering the
2282 composition exists. */
2283 ptrdiff_t lookback;
2284 /* If non-negative, number of glyphs of the glyph-string. */
2285 int nglyphs;
2286 /* True iff the composition is created while buffer is scanned in
2287 reverse order, and thus the grapheme clusters must be rendered
2288 from the last to the first. */
2289 bool reversed_p;
2290 /* Parent iterator. */
2291 struct it *parent_it;
2292
2293 /** The following members contain information about the current
2294 grapheme cluster. */
2295 /* Position of the first character of the current grapheme cluster. */
2296 ptrdiff_t charpos;
2297 /* Number of characters and bytes of the current grapheme cluster. */
2298 int nchars, nbytes;
2299 /* Indices of the glyphs for the current grapheme cluster. */
2300 int from, to;
2301 /* Width of the current grapheme cluster in units of columns it will
2302 occupy on display; see CHARACTER_WIDTH. */
2303 int width;
2304 };
2305
2306 struct it
2307 {
2308 /* The window in which we iterate over current_buffer (or a string). */
2309 Lisp_Object window;
2310 struct window *w;
2311
2312 /* The window's frame. */
2313 struct frame *f;
2314
2315 /* Method to use to load this structure with the next display element. */
2316 enum it_method method;
2317
2318 /* The next position at which to check for face changes, invisible
2319 text, overlay strings, end of text etc., which see. */
2320 ptrdiff_t stop_charpos;
2321
2322 /* Previous stop position, i.e. the last one before the current
2323 iterator position in `current'. */
2324 ptrdiff_t prev_stop;
2325
2326 /* Last stop position iterated across whose bidi embedding level is
2327 equal to the current paragraph's base embedding level. */
2328 ptrdiff_t base_level_stop;
2329
2330 /* Maximum string or buffer position + 1. ZV when iterating over
2331 current_buffer. When iterating over a string in display_string,
2332 this can be smaller or greater than the number of string
2333 characters, depending on the values of PRECISION and FIELD_WIDTH
2334 with which display_string was called. */
2335 ptrdiff_t end_charpos;
2336
2337 /* Alternate begin and end positions of the buffer that are used to
2338 optimize display of buffers with long lines. These two fields
2339 hold the return value of the 'get_medium_narrowing_begv' and
2340 'get_medium_narrowing_zv' functions. */
2341 ptrdiff_t medium_narrowing_begv;
2342 ptrdiff_t medium_narrowing_zv;
2343
2344 /* Alternate begin and end positions of the buffer that are used for
2345 labeled narrowings around low-level hooks in buffers with long
2346 lines. These two fields hold the return value of the
2347 'get_large_narrowing_begv' and 'get_large_narrowing_zv'
2348 functions. */
2349 ptrdiff_t large_narrowing_begv;
2350 ptrdiff_t large_narrowing_zv;
2351
2352 /* C string to iterate over. Non-null means get characters from
2353 this string, otherwise characters are read from current_buffer
2354 or it->string. */
2355 const unsigned char *s;
2356
2357 /* Number of characters in the string (s, or it->string) we iterate
2358 over. Used only in display_string and its subroutines; never
2359 used for overlay strings and strings from display properties. */
2360 ptrdiff_t string_nchars;
2361
2362 /* True means multibyte characters are enabled. */
2363 bool_bf multibyte_p : 1;
2364
2365 /* True means window has a tab line at its top. */
2366 bool_bf tab_line_p : 1;
2367
2368 /* True means window has a mode line at its top. */
2369 bool_bf header_line_p : 1;
2370
2371 /* True means `string' is the value of a `display' property.
2372 Don't handle some `display' properties in these strings. */
2373 bool_bf string_from_display_prop_p : 1;
2374
2375 /* True means `string' comes from a `line-prefix' or `wrap-prefix'
2376 property. */
2377 bool_bf string_from_prefix_prop_p : 1;
2378
2379 /* True means we are iterating an object that came from a value of a
2380 `display' property. */
2381 bool_bf from_disp_prop_p : 1;
2382
2383 /* When METHOD == next_element_from_display_vector,
2384 this is true if we're doing an ellipsis. Otherwise meaningless. */
2385 bool_bf ellipsis_p : 1;
2386
2387 /* True means cursor shouldn't be displayed here. */
2388 bool_bf avoid_cursor_p : 1;
2389
2390 /* Display table in effect or null for none. */
2391 struct Lisp_Char_Table *dp;
2392
2393 /* Current display table vector to return characters from and its
2394 end. dpvec null means we are not returning characters from a
2395 display table entry; current.dpvec_index gives the current index
2396 into dpvec. This same mechanism is also used to return
2397 characters from translated control characters, i.e. `\003' or
2398 `^C'. */
2399 Lisp_Object *dpvec, *dpend;
2400
2401 /* Length in bytes of the char that filled dpvec. A value of zero
2402 means that no such character is involved. A negative value means
2403 the rest of the line from the current iterator position onwards
2404 is hidden by selective display or ellipsis. */
2405 int dpvec_char_len;
2406
2407 /* Face id to use for all characters in display vector. -1 if unused. */
2408 int dpvec_face_id;
2409
2410 /* Face id of the iterator saved in case a glyph from dpvec contains
2411 a face. The face is restored when all glyphs from dpvec have
2412 been delivered. */
2413 int saved_face_id;
2414
2415 /* Vector of glyphs for control character translation. The pointer
2416 dpvec is set to ctl_chars when a control character is translated.
2417 This vector is also used for incomplete multibyte character
2418 translation (e.g \222\244). Such a character is at most 4 bytes,
2419 thus we need at most 16 bytes here. */
2420 Lisp_Object ctl_chars[16];
2421
2422 /* Initial buffer or string position of the iterator, before skipping
2423 over display properties and invisible text. */
2424 struct display_pos start;
2425
2426 /* Current buffer or string position of the iterator, including
2427 position in overlay strings etc. */
2428 struct display_pos current;
2429
2430 /* Total number of overlay strings to process. This can be >
2431 OVERLAY_STRING_CHUNK_SIZE. Value is dependable only when
2432 current.overlay_string_index >= 0. Use the latter to determine
2433 whether an overlay string is being iterated over, because
2434 n_overlay_strings can be positive even when we are not rendering
2435 an overlay string. */
2436 ptrdiff_t n_overlay_strings;
2437
2438 /* The charpos where n_overlay_strings was calculated. This should
2439 be set at the same time as n_overlay_strings. It is needed
2440 because we show before-strings at the start of invisible text;
2441 see handle_invisible_prop in xdisp.c. */
2442 ptrdiff_t overlay_strings_charpos;
2443
2444 /* Vector of overlays to process. Overlay strings are processed
2445 OVERLAY_STRING_CHUNK_SIZE at a time. */
2446 #define OVERLAY_STRING_CHUNK_SIZE 16
2447 Lisp_Object overlay_strings[OVERLAY_STRING_CHUNK_SIZE];
2448
2449 /* For each overlay string, the overlay it came from. */
2450 Lisp_Object string_overlays[OVERLAY_STRING_CHUNK_SIZE];
2451
2452 /* If non-nil, a Lisp string being processed. If
2453 current.overlay_string_index >= 0, this is an overlay string from
2454 pos. Use STRINGP (it.string) to test whether we are rendering a
2455 string or something else; do NOT use BUFFERP (it.object). */
2456 Lisp_Object string;
2457
2458 /* If non-nil, we are processing a string that came
2459 from a `display' property given by an overlay. */
2460 Lisp_Object from_overlay;
2461
2462 /* Stack of saved values. New entries are pushed when we begin to
2463 process an overlay string or a string from a `glyph' property.
2464 Entries are popped when we return to deliver display elements
2465 from what we previously had. */
2466 struct iterator_stack_entry
2467 {
2468 Lisp_Object string;
2469 int string_nchars;
2470 ptrdiff_t end_charpos;
2471 ptrdiff_t stop_charpos;
2472 ptrdiff_t prev_stop;
2473 ptrdiff_t base_level_stop;
2474 struct composition_it cmp_it;
2475 int face_id;
2476
2477 /* Save values specific to a given method. */
2478 union {
2479 /* method == GET_FROM_IMAGE */
2480 struct {
2481 Lisp_Object object;
2482 struct it_slice slice;
2483 ptrdiff_t image_id;
2484 } image;
2485 /* method == GET_FROM_STRETCH */
2486 struct {
2487 Lisp_Object object;
2488 } stretch;
2489 /* method == GET_FROM_XWIDGET */
2490 struct {
2491 Lisp_Object object;
2492 } xwidget;
2493 } u;
2494
2495 /* Current text and display positions. */
2496 struct text_pos position;
2497 struct display_pos current;
2498 Lisp_Object from_overlay;
2499 enum glyph_row_area area;
2500 enum it_method method;
2501 bidi_dir_t paragraph_embedding;
2502 bool_bf multibyte_p : 1;
2503 bool_bf string_from_display_prop_p : 1;
2504 bool_bf string_from_prefix_prop_p : 1;
2505 bool_bf display_ellipsis_p : 1;
2506 bool_bf avoid_cursor_p : 1;
2507 bool_bf bidi_p : 1;
2508 bool_bf from_disp_prop_p : 1;
2509 enum line_wrap_method line_wrap;
2510
2511 /* Properties from display property that are reset by another display
2512 property. */
2513 short voffset;
2514 Lisp_Object space_width;
2515 Lisp_Object font_height;
2516 }
2517 stack[IT_STACK_SIZE];
2518
2519 /* Stack pointer. */
2520 int sp;
2521
2522 /* -1 means selective display hides everything between a \r and the
2523 next newline; > 0 means hide lines indented more than that value. */
2524 ptrdiff_t selective;
2525
2526 /* An enumeration describing what the next display element is
2527 after a call to get_next_display_element. */
2528 enum display_element_type what;
2529
2530 /* Face to use. */
2531 int face_id;
2532
2533 /* Setting of buffer-local variable selective-display-ellipses. */
2534 bool_bf selective_display_ellipsis_p : 1;
2535
2536 /* True means control characters are translated into the form `^C'
2537 where the `^' can be replaced by a display table entry. */
2538 bool_bf ctl_arrow_p : 1;
2539
2540 /* True means that the current face has a box. */
2541 bool_bf face_box_p : 1;
2542
2543 /* Non-null means that the current character is the first in a run
2544 of characters with box face. */
2545 bool_bf start_of_box_run_p : 1;
2546
2547 /* True means that the current character is the last in a run
2548 of characters with box face. */
2549 bool_bf end_of_box_run_p : 1;
2550
2551 /* True means overlay strings at end_charpos have been processed. */
2552 bool_bf overlay_strings_at_end_processed_p : 1;
2553
2554 /* True means to ignore overlay strings at current pos, as they have
2555 already been processed. */
2556 bool_bf ignore_overlay_strings_at_pos_p : 1;
2557
2558 /* True means the actual glyph is not available in the current
2559 system. */
2560 bool_bf glyph_not_available_p : 1;
2561
2562 /* True means the next line in display_line continues a character
2563 consisting of more than one glyph, and some glyphs of this
2564 character have been put on the previous line. */
2565 bool_bf starts_in_middle_of_char_p : 1;
2566
2567 /* If true, saved_face_id contains the id of the face in front of text
2568 skipped due to selective display. */
2569 bool_bf face_before_selective_p : 1;
2570
2571 /* If true, adjust current glyph so it does not increase current row
2572 descent/ascent (line-height property). Reset after this glyph. */
2573 bool_bf constrain_row_ascent_descent_p : 1;
2574
2575 /* If true, glyphs for line number display were already produced for
2576 the current row. */
2577 bool_bf line_number_produced_p : 1;
2578
2579 enum line_wrap_method line_wrap;
2580
2581 /* The ID of the default face to use. One of DEFAULT_FACE_ID,
2582 MODE_LINE_ACTIVE_FACE_ID, etc, depending on what we are
2583 displaying. */
2584 int base_face_id;
2585
2586 /* If `what' == IT_CHARACTER, the character and the length in bytes
2587 of its multibyte sequence. The character comes from a buffer or
2588 a string. It may be different from the character displayed in
2589 case that unibyte_display_via_language_environment is set.
2590
2591 If `what' == IT_COMPOSITION, the first component of a composition
2592 and length in bytes of the composition.
2593
2594 If `what' is anything else, these two are undefined (will
2595 probably hold values for the last IT_CHARACTER or IT_COMPOSITION
2596 traversed by the iterator).
2597
2598 The values are updated by get_next_display_element, so they are
2599 out of sync with the value returned by IT_CHARPOS between the
2600 time set_iterator_to_next advances the position and the time
2601 get_next_display_element loads the new values into c and len. */
2602 int c, len;
2603
2604 /* If what == IT_COMPOSITION, iterator substructure for the
2605 composition. */
2606 struct composition_it cmp_it;
2607
2608 /* The character to display, possibly translated to multibyte if
2609 multibyte_p is zero or unibyte_display_via_language_environment
2610 is set. This is set after get_next_display_element has been
2611 called. If we are setting it->C directly before calling
2612 PRODUCE_GLYPHS, this should be set beforehand too. */
2613 int char_to_display;
2614
2615 /* If what == IT_GLYPHLESS, the method to display such a
2616 character. */
2617 enum glyphless_display_method glyphless_method;
2618
2619 /* If what == IT_IMAGE, the id of the image to display. */
2620 ptrdiff_t image_id;
2621
2622 /* If what == IT_XWIDGET. */
2623 struct xwidget *xwidget;
2624
2625 /* Values from `slice' property. */
2626 struct it_slice slice;
2627
2628 /* Value of the `space-width' property, if any; nil if none. */
2629 Lisp_Object space_width;
2630
2631 /* Computed from the value of the `raise' property. */
2632 short voffset;
2633
2634 /* Number of columns per \t. */
2635 short tab_width;
2636
2637 /* Value of the `height' property, if any; nil if none. */
2638 Lisp_Object font_height;
2639
2640 /* Object and position where the current display element came from.
2641 Object is normally the buffer which is being rendered, but it can
2642 also be a Lisp string in case the current display element comes
2643 from an overlay string or from a display string (before- or
2644 after-string). It may also be a zero-valued Lisp integer when a
2645 C string is being rendered, e.g., during mode-line or header-line
2646 update. It can also be a cons cell of the form `(space ...)',
2647 when we produce a stretch glyph from a `display' specification.
2648 Finally, it can be nil, but only temporarily, when we are
2649 producing special glyphs for display purposes, like truncation
2650 and continuation glyphs, or blanks that extend each line to the
2651 edge of the window on a TTY.
2652
2653 Do NOT use !BUFFERP (it.object) as a test whether we are
2654 iterating over a string; use STRINGP (it.string) instead.
2655
2656 Position is the current iterator position in object.
2657
2658 The 'position's CHARPOS is copied to glyph->charpos of the glyph
2659 produced by PRODUCE_GLYPHS, so any artificial value documented
2660 under 'struct glyph's 'charpos' member can also be found in the
2661 'position' member here. */
2662 Lisp_Object object;
2663 struct text_pos position;
2664
2665 /* Width in pixels of truncation and continuation glyphs. */
2666 short truncation_pixel_width, continuation_pixel_width;
2667
2668 /* First and last visible x-position in the display area. If window
2669 is hscrolled by n columns, first_visible_x == n * FRAME_COLUMN_WIDTH
2670 (f), and last_visible_x == pixel width of W + first_visible_x.
2671 When truncation or continuation glyphs are produced due to lack of
2672 fringes, last_visible_x excludes the space required for these glyphs. */
2673 int first_visible_x, last_visible_x;
2674
2675 /* Last visible y-position + 1 in the display area without a mode
2676 line, if the window has one. */
2677 int last_visible_y;
2678
2679 /* Default amount of additional space in pixels between lines (for
2680 window systems only.) */
2681 int extra_line_spacing;
2682
2683 /* Max extra line spacing added in this row. */
2684 int max_extra_line_spacing;
2685
2686 /* Override font height information for this glyph.
2687 Used if override_ascent >= 0. Cleared after this glyph. */
2688 int override_ascent, override_descent, override_boff;
2689
2690 /* If non-null, glyphs are produced in glyph_row with each call to
2691 produce_glyphs. */
2692 struct glyph_row *glyph_row;
2693
2694 /* The area of glyph_row to which glyphs are added. */
2695 enum glyph_row_area area;
2696
2697 /* Number of glyphs needed for the last character requested via
2698 produce_glyphs. This is 1 except for tabs. */
2699 int nglyphs;
2700
2701 /* Width of the display element in pixels. Result of
2702 produce_glyphs. */
2703 int pixel_width;
2704
2705 /* Current, maximum logical, and maximum physical line height
2706 information. Result of produce_glyphs. */
2707 int ascent, descent, max_ascent, max_descent;
2708 int phys_ascent, phys_descent, max_phys_ascent, max_phys_descent;
2709
2710 /* Current x pixel position within the display line. This value
2711 does not include the width of continuation lines in front of the
2712 line. The value of current_x is automatically incremented by
2713 pixel_width with each call to produce_glyphs. */
2714 int current_x;
2715
2716 /* Accumulated width of continuation lines. If > 0, this means we
2717 are currently in a continuation line. This is initially zero and
2718 incremented/reset by display_line, move_it_to etc. */
2719 int continuation_lines_width;
2720
2721 /* Buffer position that ends the buffer text line being iterated.
2722 This is normally the position after the newline at EOL. If this
2723 is the last line of the buffer and it doesn't have a newline,
2724 value is ZV/ZV_BYTE. Set and used only if IT->bidi_p, for
2725 setting the end position of glyph rows produced for continuation
2726 lines, see display_line. */
2727 struct text_pos eol_pos;
2728
2729 /* Current y-position. Automatically incremented by the height of
2730 glyph_row in move_it_to and display_line. */
2731 int current_y;
2732
2733 /* Vertical matrix position of first text line in window. */
2734 int first_vpos;
2735
2736 /* Current vertical matrix position, or line number. Automatically
2737 incremented by move_it_to and display_line. */
2738 int vpos;
2739
2740 /* Horizontal matrix position reached in move_it_in_display_line.
2741 Only set there, not in display_line, and only when the X
2742 coordinate is past first_visible_x. */
2743 int hpos;
2744
2745 /* Current line number, zero-based. */
2746 ptrdiff_t lnum;
2747
2748 /* The byte position corresponding to lnum. */
2749 ptrdiff_t lnum_bytepos;
2750
2751 /* The width, in columns and in pixels, needed for display of the
2752 line numbers, or zero if not computed. */
2753 int lnum_width;
2754 int lnum_pixel_width;
2755
2756 /* The line number of point's line, or zero if not computed yet. */
2757 ptrdiff_t pt_lnum;
2758
2759 /* Number of pixels to adjust tab stops and stretch glyphs due to
2760 width fixup of the first stretch glyph that crosses first_visible_x.
2761 This is only needed on GUI frames, only when display-line-numbers
2762 is in effect, and only in hscrolled windows. */
2763 int stretch_adjust;
2764
2765 /* Left fringe bitmap number (enum fringe_bitmap_type). */
2766 unsigned left_user_fringe_bitmap : FRINGE_ID_BITS;
2767
2768 /* Right fringe bitmap number (enum fringe_bitmap_type). */
2769 unsigned right_user_fringe_bitmap : FRINGE_ID_BITS;
2770
2771 /* Face of the left fringe glyph. */
2772 unsigned left_user_fringe_face_id : FACE_ID_BITS;
2773
2774 /* Face of the right fringe glyph. */
2775 unsigned right_user_fringe_face_id : FACE_ID_BITS;
2776
2777 /* True means we need to reorder bidirectional text for display
2778 in the visual order. */
2779 bool_bf bidi_p : 1;
2780
2781 /* For iterating over bidirectional text. */
2782 struct bidi_it bidi_it;
2783 bidi_dir_t paragraph_embedding;
2784
2785 /* For handling the :min-width property. The object is the text
2786 property we're testing the `eq' of (nil if none), and the integer
2787 is the x position of the start of the run of glyphs. */
2788 Lisp_Object min_width_property;
2789 int min_width_start;
2790 };
2791
2792
2793 /* Access to positions of iterator IT. */
2794
2795 #define IT_CHARPOS(IT) CHARPOS ((IT).current.pos)
2796 #define IT_BYTEPOS(IT) BYTEPOS ((IT).current.pos)
2797 #define IT_STRING_CHARPOS(IT) CHARPOS ((IT).current.string_pos)
2798 #define IT_STRING_BYTEPOS(IT) BYTEPOS ((IT).current.string_pos)
2799
2800 /* Test if IT has reached the end of its buffer or string. This will
2801 only work after get_next_display_element has been called. */
2802
2803 #define ITERATOR_AT_END_P(IT) ((IT)->what == IT_EOB)
2804
2805 /* True means IT is at the end of a line. This is the case if it
2806 is either on a newline or on a carriage return and selective
2807 display hides the rest of the line. */
2808
2809 #define ITERATOR_AT_END_OF_LINE_P(IT) \
2810 ((IT)->what == IT_CHARACTER \
2811 && ((IT)->c == '\n' \
2812 || ((IT)->c == '\r' && (IT)->selective)))
2813
2814 /* Call produce_glyphs or FRAME_RIF->produce_glyphs, if set. Shortcut
2815 to avoid the function call overhead. */
2816
2817 #define PRODUCE_GLYPHS(IT) \
2818 do { \
2819 if ((IT)->glyph_row != NULL && (IT)->bidi_p) \
2820 (IT)->glyph_row->reversed_p = (IT)->bidi_it.paragraph_dir == R2L; \
2821 if (FRAME_RIF ((IT)->f) != NULL) \
2822 FRAME_RIF ((IT)->f)->produce_glyphs ((IT)); \
2823 else \
2824 produce_glyphs ((IT)); \
2825 if ((IT)->glyph_row != NULL) \
2826 inhibit_free_realized_faces =true; \
2827 reset_box_start_end_flags ((IT)); \
2828 } while (false)
2829
2830 /* Bit-flags indicating what operation move_it_to should perform. */
2831
2832 enum move_operation_enum
2833 {
2834 /* Stop if specified x-position is reached. */
2835 MOVE_TO_X = 0x01,
2836
2837 /* Stop if specified y-position is reached. */
2838 MOVE_TO_Y = 0x02,
2839
2840 /* Stop if specified vpos is reached. */
2841 MOVE_TO_VPOS = 0x04,
2842
2843 /* Stop if specified buffer or string position is reached. */
2844 MOVE_TO_POS = 0x08
2845 };
2846
2847 /***********************************************************************
2848 Mouse Highlight
2849 ***********************************************************************/
2850
2851 /* Structure to hold mouse highlight data. */
2852
2853 typedef struct {
2854 /* These variables describe the range of text currently shown in its
2855 mouse-face, together with the window they apply to. As long as
2856 the mouse stays within this range, we need not redraw anything on
2857 its account. Rows and columns are glyph matrix positions in
2858 MOUSE_FACE_WINDOW. */
2859 int mouse_face_beg_row, mouse_face_beg_col, mouse_face_beg_x;
2860 int mouse_face_end_row, mouse_face_end_col, mouse_face_end_x;
2861 Lisp_Object mouse_face_window;
2862 int mouse_face_face_id;
2863 Lisp_Object mouse_face_overlay;
2864
2865 /* FRAME and X, Y position of mouse when last checked for
2866 highlighting. X and Y can be negative or out of range for the frame. */
2867 struct frame *mouse_face_mouse_frame;
2868 int mouse_face_mouse_x, mouse_face_mouse_y;
2869
2870 /* Nonzero if part of the text currently shown in
2871 its mouse-face is beyond the window end. */
2872 bool_bf mouse_face_past_end : 1;
2873
2874 /* True means defer mouse-motion highlighting. */
2875 bool_bf mouse_face_defer : 1;
2876
2877 /* True means that the mouse highlight should not be shown. */
2878 bool_bf mouse_face_hidden : 1;
2879 } Mouse_HLInfo;
2880
2881 INLINE void
2882 reset_mouse_highlight (Mouse_HLInfo *hlinfo)
2883 {
2884 hlinfo->mouse_face_beg_row = hlinfo->mouse_face_beg_col = -1;
2885 hlinfo->mouse_face_end_row = hlinfo->mouse_face_end_col = -1;
2886 hlinfo->mouse_face_mouse_x = hlinfo->mouse_face_mouse_y = 0;
2887 hlinfo->mouse_face_beg_x = hlinfo->mouse_face_end_x = 0;
2888 hlinfo->mouse_face_face_id = DEFAULT_FACE_ID;
2889 hlinfo->mouse_face_mouse_frame = NULL;
2890 hlinfo->mouse_face_window = Qnil;
2891 hlinfo->mouse_face_overlay = Qnil;
2892 hlinfo->mouse_face_past_end = false;
2893 hlinfo->mouse_face_hidden = false;
2894 hlinfo->mouse_face_defer = false;
2895 }
2896
2897 /***********************************************************************
2898 Window-based redisplay interface
2899 ***********************************************************************/
2900
2901 /* Structure used to describe runs of lines that must be scrolled. */
2902
2903 struct run
2904 {
2905 /* Source and destination y pixel position. */
2906 int desired_y, current_y;
2907
2908 /* Source and destination vpos in matrix. */
2909 int desired_vpos, current_vpos;
2910
2911 /* Height in pixels, number of glyph rows. */
2912 int height, nrows;
2913 };
2914
2915
2916 /* Handlers for setting frame parameters. */
2917
2918 typedef void (*frame_parm_handler) (struct frame *, Lisp_Object, Lisp_Object);
2919
2920
2921 /* Structure holding system-dependent interface functions needed
2922 for window-based redisplay. */
2923
2924 struct redisplay_interface
2925 {
2926 /* Handlers for setting frame parameters. */
2927 frame_parm_handler *frame_parm_handlers;
2928
2929 /* Produce glyphs/get display metrics for the display element IT is
2930 loaded with. */
2931 void (*produce_glyphs) (struct it *it);
2932
2933 /* Write or insert LEN glyphs from STRING at the nominal output
2934 position. */
2935 void (*write_glyphs) (struct window *w, struct glyph_row *row,
2936 struct glyph *string, enum glyph_row_area area,
2937 int len);
2938 void (*insert_glyphs) (struct window *w, struct glyph_row *row,
2939 struct glyph *start, enum glyph_row_area area,
2940 int len);
2941
2942 /* Clear from nominal output position to X. X < 0 means clear
2943 to right end of display. */
2944 void (*clear_end_of_line) (struct window *w, struct glyph_row *row,
2945 enum glyph_row_area area, int x);
2946
2947 /* Function to call to scroll the display as described by RUN on
2948 window W. */
2949 void (*scroll_run_hook) (struct window *w, struct run *run);
2950
2951 /* Function to call after a line in a display has been completely
2952 updated. Used to draw truncation marks and alike. DESIRED_ROW
2953 is the desired row which has been updated. */
2954 void (*after_update_window_line_hook) (struct window *w,
2955 struct glyph_row *desired_row);
2956
2957 /* Function to call before beginning to update window W in
2958 window-based redisplay. */
2959 void (*update_window_begin_hook) (struct window *w);
2960
2961 /* Function to call after window W has been updated in window-based
2962 redisplay. CURSOR_ON_P true means switch cursor on.
2963 MOUSE_FACE_OVERWRITTEN_P true means that some lines in W
2964 that contained glyphs in mouse-face were overwritten, so we
2965 have to update the mouse highlight. */
2966 void (*update_window_end_hook) (struct window *w, bool cursor_on_p,
2967 bool mouse_face_overwritten_p);
2968
2969 /* Flush the display of frame F. For X, this is XFlush. */
2970 void (*flush_display) (struct frame *f);
2971
2972 /* Clear the mouse highlight in window W, if there is any. */
2973 void (*clear_window_mouse_face) (struct window *w);
2974
2975 /* Set *LEFT and *RIGHT to the left and right overhang of GLYPH on
2976 frame F. */
2977 void (*get_glyph_overhangs) (struct glyph *glyph, struct frame *f,
2978 int *left, int *right);
2979
2980 /* Fix the display of AREA of ROW in window W for overlapping rows.
2981 This function is called from redraw_overlapping_rows after
2982 desired rows have been made current. */
2983 void (*fix_overlapping_area) (struct window *w, struct glyph_row *row,
2984 enum glyph_row_area area, int);
2985
2986 #ifdef HAVE_WINDOW_SYSTEM
2987
2988 /* Draw a fringe bitmap in window W of row ROW using parameters P. */
2989 void (*draw_fringe_bitmap) (struct window *w, struct glyph_row *row,
2990 struct draw_fringe_bitmap_params *p);
2991
2992 /* Define and destroy fringe bitmap no. WHICH. */
2993 void (*define_fringe_bitmap) (int which, unsigned short *bits,
2994 int h, int wd);
2995 void (*destroy_fringe_bitmap) (int which);
2996
2997 /* Compute left and right overhang of glyph string S.
2998 A NULL pointer if platform does not support this. */
2999 void (*compute_glyph_string_overhangs) (struct glyph_string *s);
3000
3001 /* Draw a glyph string S. */
3002 void (*draw_glyph_string) (struct glyph_string *s);
3003
3004 /* Define cursor CURSOR on frame F. */
3005 void (*define_frame_cursor) (struct frame *f, Emacs_Cursor cursor);
3006
3007 /* Clear the area at (X,Y,WIDTH,HEIGHT) of frame F. */
3008 void (*clear_frame_area) (struct frame *f, int x, int y,
3009 int width, int height);
3010
3011 /* Clear area of frame F's internal border. If the internal border
3012 face of F has been specified (is not null), fill the area with
3013 that face. */
3014 void (*clear_under_internal_border) (struct frame *f);
3015
3016 /* Draw specified cursor CURSOR_TYPE of width CURSOR_WIDTH
3017 at row GLYPH_ROW on window W if ON_P is true. If ON_P is
3018 false, don't draw cursor. If ACTIVE_P is true, system caret
3019 should track this cursor (when applicable). */
3020 void (*draw_window_cursor) (struct window *w,
3021 struct glyph_row *glyph_row,
3022 int x, int y,
3023 enum text_cursor_kinds cursor_type,
3024 int cursor_width, bool on_p, bool active_p);
3025
3026 /* Draw vertical border for window W from (X,Y_0) to (X,Y_1). */
3027 void (*draw_vertical_window_border) (struct window *w,
3028 int x, int y_0, int y_1);
3029
3030 /* Draw window divider for window W from (X_0, Y_0) to (X_1, ,Y_1). */
3031 void (*draw_window_divider) (struct window *w,
3032 int x_0, int x_1, int y_0, int y_1);
3033
3034 /* Shift display of frame F to make room for inserted glyphs.
3035 The area at pixel (X,Y) of width WIDTH and height HEIGHT is
3036 shifted right by SHIFT_BY pixels. */
3037 void (*shift_glyphs_for_insert) (struct frame *f,
3038 int x, int y, int width,
3039 int height, int shift_by);
3040
3041 /* Start display hourglass cursor on frame F. */
3042 void (*show_hourglass) (struct frame *f);
3043
3044 /* Cancel hourglass cursor on frame F. */
3045 void (*hide_hourglass) (struct frame *f);
3046
3047 /* Called to (re)calculate the default face when changing the font
3048 backend. */
3049 void (*default_font_parameter) (struct frame *f, Lisp_Object parms);
3050 #endif /* HAVE_WINDOW_SYSTEM */
3051 };
3052
3053
3054 /***********************************************************************
3055 Images
3056 ***********************************************************************/
3057
3058 #ifdef HAVE_WINDOW_SYSTEM
3059
3060 # if (defined USE_CAIRO || defined HAVE_XRENDER \
3061 || defined HAVE_NS || defined HAVE_NTGUI || defined HAVE_HAIKU)
3062 # define HAVE_NATIVE_TRANSFORMS
3063 # endif
3064
3065 /* Structure describing an image. Specific image formats like XBM are
3066 converted into this form, so that display only has to deal with
3067 this type of image. */
3068
3069 struct image
3070 {
3071 /* The time in seconds at which the image was last displayed. Set
3072 in prepare_image_for_display. */
3073 struct timespec timestamp;
3074
3075 /* Pixmaps of the image. */
3076 Emacs_Pixmap pixmap, mask;
3077
3078 #ifdef USE_CAIRO
3079 void *cr_data;
3080 #endif
3081 #ifdef HAVE_X_WINDOWS
3082 /* X images of the image, corresponding to the above Pixmaps.
3083 Non-NULL means it and its Pixmap counterpart may be out of sync
3084 and the latter is outdated. NULL means the X image has been
3085 synchronized to Pixmap. */
3086 XImage *ximg, *mask_img;
3087
3088 # if !defined USE_CAIRO && defined HAVE_XRENDER
3089 /* Picture versions of pixmap and mask for compositing. */
3090 Picture picture, mask_picture;
3091
3092 /* We need to store the original image dimensions in case we have to
3093 call XGetImage. */
3094 int original_width, original_height;
3095 # endif
3096 #endif /* HAVE_X_WINDOWS */
3097 #ifdef HAVE_NTGUI
3098 XFORM xform;
3099 #endif
3100 #ifdef HAVE_HAIKU
3101 /* The affine transformation to apply to this image. */
3102 double transform[3][3];
3103
3104 /* The original width and height of the image. */
3105 int original_width, original_height;
3106
3107 /* Whether or not bilinear filtering should be used to "smooth" the
3108 image. */
3109 bool use_bilinear_filtering;
3110 #endif
3111
3112 /* Colors allocated for this image, if any. Allocated via xmalloc. */
3113 unsigned long *colors;
3114 int ncolors;
3115
3116 /* A single `background color' for this image, for the use of anyone that
3117 cares about such a thing. Only valid if the `background_valid' field
3118 is true. This should generally be accessed by calling the accessor
3119 macro `IMAGE_BACKGROUND', which will heuristically calculate a value
3120 if necessary. */
3121 unsigned long background;
3122
3123 /* Foreground and background colors of the face on which the image
3124 is created. */
3125 unsigned long face_foreground, face_background;
3126
3127 /* Details of the font, only really relevant for types like SVG that
3128 allow us to draw text. */
3129 int face_font_size;
3130 char *face_font_family;
3131
3132 /* True if this image has a `transparent' background -- that is, is
3133 uses an image mask. The accessor macro for this is
3134 `IMAGE_BACKGROUND_TRANSPARENT'. */
3135 bool_bf background_transparent : 1;
3136
3137 /* True if the `background' and `background_transparent' fields are
3138 valid, respectively. */
3139 bool_bf background_valid : 1, background_transparent_valid : 1;
3140
3141 /* Width and height of the image. */
3142 int width, height;
3143
3144 /* These values are used for the rectangles displayed for images
3145 that can't be loaded. */
3146 #define DEFAULT_IMAGE_WIDTH 30
3147 #define DEFAULT_IMAGE_HEIGHT 30
3148
3149 /* Top/left and bottom/right corner pixel of actual image data.
3150 Used by four_corners_best to consider the real image data,
3151 rather than looking at the optional image margin. */
3152 int corners[4];
3153 #define TOP_CORNER 0
3154 #define LEFT_CORNER 1
3155 #define BOT_CORNER 2
3156 #define RIGHT_CORNER 3
3157
3158 /* Percent of image height used as ascent. A value of
3159 CENTERED_IMAGE_ASCENT means draw the image centered on the
3160 line. */
3161 int ascent;
3162 #define DEFAULT_IMAGE_ASCENT 50
3163 #define CENTERED_IMAGE_ASCENT -1
3164
3165 /* Lisp specification of this image. */
3166 Lisp_Object spec;
3167
3168 /* List of "references" followed to build the image.
3169 Typically will just contain the name of the image file.
3170 Used to allow fine-grained cache flushing. */
3171 Lisp_Object dependencies;
3172
3173 /* Relief to draw around the image. */
3174 int relief;
3175
3176 /* Optional margins around the image. This includes the relief. */
3177 int hmargin, vmargin;
3178
3179 /* Reference to the type of the image. */
3180 struct image_type const *type;
3181
3182 /* True means that loading the image failed. Don't try again. */
3183 bool load_failed_p;
3184
3185 /* A place for image types to store additional data. It is marked
3186 during GC. */
3187 Lisp_Object lisp_data;
3188
3189 /* Hash value of image specification to speed up comparisons. */
3190 EMACS_UINT hash;
3191
3192 /* Image id of this image. */
3193 ptrdiff_t id;
3194
3195 /* Hash collision chain. */
3196 struct image *next, *prev;
3197 };
3198
3199
3200 /* Cache of images. Each frame has a cache. X frames with the same
3201 x_display_info share their caches. */
3202
3203 struct image_cache
3204 {
3205 /* Hash table of images. */
3206 struct image **buckets;
3207
3208 /* Vector mapping image ids to images. */
3209 struct image **images;
3210
3211 /* Allocated size of `images'. */
3212 ptrdiff_t size;
3213
3214 /* Number of images in the cache. */
3215 ptrdiff_t used;
3216
3217 /* Reference count (number of frames sharing this cache). */
3218 ptrdiff_t refcount;
3219 };
3220
3221 /* Size of bucket vector of image caches. Should be prime. */
3222
3223 #define IMAGE_CACHE_BUCKETS_SIZE 1009
3224
3225 #endif /* HAVE_WINDOW_SYSTEM */
3226
3227
3228
3229 /***********************************************************************
3230 Tab-bars
3231 ***********************************************************************/
3232
3233 /* Enumeration defining where to find tab-bar item information in
3234 tab-bar items vectors stored with frames. Each tab-bar item
3235 occupies TAB_BAR_ITEM_NSLOTS elements in such a vector. */
3236
3237 enum tab_bar_item_idx
3238 {
3239 /* The key of the tab-bar item. Used to remove items when a binding
3240 for `undefined' is found. */
3241 TAB_BAR_ITEM_KEY,
3242
3243 /* Non-nil if item is enabled. */
3244 TAB_BAR_ITEM_ENABLED_P,
3245
3246 /* Non-nil if item is selected (pressed). */
3247 TAB_BAR_ITEM_SELECTED_P,
3248
3249 /* Caption. */
3250 TAB_BAR_ITEM_CAPTION,
3251
3252 /* The binding. */
3253 TAB_BAR_ITEM_BINDING,
3254
3255 /* Help string. */
3256 TAB_BAR_ITEM_HELP,
3257
3258 /* Sentinel = number of slots in tab_bar_items occupied by one
3259 tab-bar item. */
3260 TAB_BAR_ITEM_NSLOTS
3261 };
3262
3263 /* Default values of the above variables. */
3264
3265 #define DEFAULT_TAB_BAR_BUTTON_MARGIN 1
3266 #define DEFAULT_TAB_BAR_BUTTON_RELIEF 1
3267
3268 /* The height in pixels of the default tab-bar images. */
3269
3270 #define DEFAULT_TAB_BAR_IMAGE_HEIGHT 18
3271
3272
3273 /***********************************************************************
3274 Tool-bars
3275 ***********************************************************************/
3276
3277 /* Enumeration defining where to find tool-bar item information in
3278 tool-bar items vectors stored with frames. Each tool-bar item
3279 occupies TOOL_BAR_ITEM_NSLOTS elements in such a vector. */
3280
3281 enum tool_bar_item_idx
3282 {
3283 /* The key of the tool-bar item. Used to remove items when a binding
3284 for `undefined' is found. */
3285 TOOL_BAR_ITEM_KEY,
3286
3287 /* Non-nil if item is enabled. */
3288 TOOL_BAR_ITEM_ENABLED_P,
3289
3290 /* Non-nil if item is selected (pressed). */
3291 TOOL_BAR_ITEM_SELECTED_P,
3292
3293 /* Caption. */
3294 TOOL_BAR_ITEM_CAPTION,
3295
3296 /* Image(s) to display. This is either a single image specification
3297 or a vector of specifications. */
3298 TOOL_BAR_ITEM_IMAGES,
3299
3300 /* The binding. */
3301 TOOL_BAR_ITEM_BINDING,
3302
3303 /* Button type. One of nil (default button), t (a separator),
3304 `:radio', or `:toggle'. The latter two currently do nothing. */
3305 TOOL_BAR_ITEM_TYPE,
3306
3307 /* Help string. */
3308 TOOL_BAR_ITEM_HELP,
3309
3310 /* Icon file name of right to left image when an RTL locale is used. */
3311 TOOL_BAR_ITEM_RTL_IMAGE,
3312
3313 /* Label to show when text labels are enabled. */
3314 TOOL_BAR_ITEM_LABEL,
3315
3316 /* If we shall show the label only below the icon and not beside it. */
3317 TOOL_BAR_ITEM_VERT_ONLY,
3318
3319 /* Sentinel = number of slots in tool_bar_items occupied by one
3320 tool-bar item. */
3321 TOOL_BAR_ITEM_NSLOTS
3322 };
3323
3324
3325 /* An enumeration for the different images that can be specified
3326 for a tool-bar item. */
3327
3328 enum tool_bar_item_image
3329 {
3330 TOOL_BAR_IMAGE_ENABLED_SELECTED,
3331 TOOL_BAR_IMAGE_ENABLED_DESELECTED,
3332 TOOL_BAR_IMAGE_DISABLED_SELECTED,
3333 TOOL_BAR_IMAGE_DISABLED_DESELECTED
3334 };
3335
3336 #define DEFAULT_TOOL_BAR_LABEL_SIZE 14
3337
3338 /* Default values of the above variables. */
3339
3340 #define DEFAULT_TOOL_BAR_BUTTON_MARGIN 4
3341 #define DEFAULT_TOOL_BAR_BUTTON_RELIEF 1
3342
3343 /* The height in pixels of the default tool-bar images. */
3344
3345 #define DEFAULT_TOOL_BAR_IMAGE_HEIGHT 24
3346
3347
3348 /***********************************************************************
3349 Terminal Capabilities
3350 ***********************************************************************/
3351
3352 /* Each of these is a bit representing a terminal `capability' (bold,
3353 inverse, etc). They are or'd together to specify the set of
3354 capabilities being queried for when calling `tty_capable_p' (which
3355 returns true if the terminal supports all of them). */
3356
3357 #define TTY_CAP_INVERSE 0x01
3358 #define TTY_CAP_UNDERLINE 0x02
3359 #define TTY_CAP_BOLD 0x04
3360 #define TTY_CAP_DIM 0x08
3361 #define TTY_CAP_ITALIC 0x10
3362 #define TTY_CAP_STRIKE_THROUGH 0x20
3363
3364
3365 /***********************************************************************
3366 Function Prototypes
3367 ***********************************************************************/
3368
3369 /* Defined in bidi.c */
3370
3371 extern void bidi_init_it (ptrdiff_t, ptrdiff_t, bool, struct bidi_it *);
3372 extern void bidi_move_to_visually_next (struct bidi_it *);
3373 extern void bidi_paragraph_init (bidi_dir_t, struct bidi_it *, bool);
3374 extern int bidi_mirror_char (int);
3375 extern void bidi_push_it (struct bidi_it *);
3376 extern void bidi_pop_it (struct bidi_it *);
3377 extern void *bidi_shelve_cache (void);
3378 extern void bidi_unshelve_cache (void *, bool);
3379 extern ptrdiff_t bidi_find_first_overridden (struct bidi_it *);
3380
3381 /* Defined in xdisp.c */
3382
3383 struct glyph_row *row_containing_pos (struct window *, ptrdiff_t,
3384 struct glyph_row *,
3385 struct glyph_row *, int);
3386 int line_bottom_y (struct it *);
3387 int default_line_pixel_height (struct window *);
3388 bool display_prop_intangible_p (Lisp_Object, Lisp_Object, ptrdiff_t, ptrdiff_t);
3389 void resize_echo_area_exactly (void);
3390 bool resize_mini_window (struct window *, bool);
3391 void set_vertical_scroll_bar (struct window *);
3392 void set_horizontal_scroll_bar (struct window *);
3393 int try_window (Lisp_Object, struct text_pos, int);
3394 void window_box (struct window *, enum glyph_row_area,
3395 int *, int *, int *, int *);
3396 int window_box_height (struct window *);
3397 int window_text_bottom_y (struct window *);
3398 int window_box_width (struct window *, enum glyph_row_area);
3399 int window_box_left (struct window *, enum glyph_row_area);
3400 int window_box_left_offset (struct window *, enum glyph_row_area);
3401 int window_box_right (struct window *, enum glyph_row_area);
3402 int estimate_mode_line_height (struct frame *, enum face_id);
3403 int move_it_to (struct it *, ptrdiff_t, int, int, int, int);
3404 void pixel_to_glyph_coords (struct frame *, int, int, int *, int *,
3405 NativeRectangle *, bool);
3406 void remember_mouse_glyph (struct frame *, int, int, NativeRectangle *);
3407
3408 void mark_window_display_accurate (Lisp_Object, bool);
3409 void redisplay_preserve_echo_area (int);
3410 void init_iterator (struct it *, struct window *, ptrdiff_t,
3411 ptrdiff_t, struct glyph_row *, enum face_id);
3412 ptrdiff_t get_small_narrowing_begv (struct window *, ptrdiff_t);
3413 ptrdiff_t get_large_narrowing_begv (ptrdiff_t);
3414 ptrdiff_t get_large_narrowing_zv (ptrdiff_t);
3415 void init_iterator_to_row_start (struct it *, struct window *,
3416 struct glyph_row *);
3417 void start_display (struct it *, struct window *, struct text_pos);
3418 void move_it_vertically (struct it *, int);
3419 void move_it_vertically_backward (struct it *, int);
3420 void move_it_by_lines (struct it *, ptrdiff_t);
3421 void move_it_past_eol (struct it *);
3422 void move_it_in_display_line (struct it *it,
3423 ptrdiff_t to_charpos, int to_x,
3424 enum move_operation_enum op);
3425 int partial_line_height (struct it *it_origin);
3426 bool in_display_vector_p (struct it *);
3427 int frame_mode_line_height (struct frame *);
3428 extern bool redisplaying_p;
3429 extern bool display_working_on_window_p;
3430 extern void unwind_display_working_on_window (void);
3431 extern bool help_echo_showing_p;
3432 extern Lisp_Object help_echo_string, help_echo_window;
3433 extern Lisp_Object help_echo_object, previous_help_echo_string;
3434 extern ptrdiff_t help_echo_pos;
3435 extern int last_tab_bar_item;
3436 extern int last_tool_bar_item;
3437 extern void reseat_at_previous_visible_line_start (struct it *);
3438 extern Lisp_Object lookup_glyphless_char_display (int, struct it *);
3439 extern ptrdiff_t compute_display_string_pos (struct text_pos *,
3440 struct bidi_string_data *,
3441 struct window *, bool, int *);
3442 extern ptrdiff_t compute_display_string_end (ptrdiff_t,
3443 struct bidi_string_data *);
3444 extern void produce_stretch_glyph (struct it *);
3445 extern int merge_glyphless_glyph_face (struct it *);
3446 extern void forget_escape_and_glyphless_faces (void);
3447
3448 extern void get_font_ascent_descent (struct font *, int *, int *);
3449
3450 #ifdef HAVE_WINDOW_SYSTEM
3451
3452 extern void gui_get_glyph_overhangs (struct glyph *, struct frame *,
3453 int *, int *);
3454 extern struct font *font_for_underline_metrics (struct glyph_string *);
3455 extern void gui_produce_glyphs (struct it *);
3456
3457 extern void gui_write_glyphs (struct window *, struct glyph_row *,
3458 struct glyph *, enum glyph_row_area, int);
3459 extern void gui_insert_glyphs (struct window *, struct glyph_row *,
3460 struct glyph *, enum glyph_row_area, int);
3461 extern void gui_clear_end_of_line (struct window *, struct glyph_row *,
3462 enum glyph_row_area, int);
3463 extern void gui_fix_overlapping_area (struct window *, struct glyph_row *,
3464 enum glyph_row_area, int);
3465 extern void draw_phys_cursor_glyph (struct window *,
3466 struct glyph_row *,
3467 enum draw_glyphs_face);
3468 extern void get_phys_cursor_geometry (struct window *, struct glyph_row *,
3469 struct glyph *, int *, int *, int *);
3470 extern void erase_phys_cursor (struct window *);
3471 extern void display_and_set_cursor (struct window *, bool, int, int, int, int);
3472 extern void gui_update_cursor (struct frame *, bool);
3473 extern void gui_clear_cursor (struct window *);
3474 extern void gui_draw_vertical_border (struct window *w);
3475 extern void gui_draw_right_divider (struct window *w);
3476
3477 extern int get_glyph_string_clip_rects (struct glyph_string *,
3478 NativeRectangle *, int);
3479 extern void get_glyph_string_clip_rect (struct glyph_string *,
3480 NativeRectangle *nr);
3481 extern Lisp_Object find_hot_spot (Lisp_Object, int, int);
3482
3483 extern Lisp_Object handle_tab_bar_click (struct frame *,
3484 int, int, bool, int);
3485 extern void handle_tool_bar_click (struct frame *,
3486 int, int, bool, int);
3487 extern void handle_tool_bar_click_with_device (struct frame *, int, int, bool,
3488 int, Lisp_Object);
3489
3490 extern void expose_frame (struct frame *, int, int, int, int);
3491 extern bool gui_intersect_rectangles (const Emacs_Rectangle *,
3492 const Emacs_Rectangle *,
3493 Emacs_Rectangle *);
3494 extern void gui_consider_frame_title (Lisp_Object);
3495 #endif /* HAVE_WINDOW_SYSTEM */
3496
3497 extern void note_mouse_highlight (struct frame *, int, int);
3498 extern void gui_clear_window_mouse_face (struct window *);
3499 extern void cancel_mouse_face (struct frame *);
3500 extern bool clear_mouse_face (Mouse_HLInfo *);
3501 extern bool cursor_in_mouse_face_p (struct window *w);
3502 extern void tty_draw_row_with_mouse_face (struct window *, struct glyph_row *,
3503 int, int, enum draw_glyphs_face);
3504 extern void display_tty_menu_item (const char *, int, int, int, int, bool);
3505 extern struct glyph *x_y_to_hpos_vpos (struct window *, int, int, int *, int *,
3506 int *, int *, int *);
3507 /* Flags passed to try_window. */
3508 #define TRY_WINDOW_CHECK_MARGINS (1 << 0)
3509 #define TRY_WINDOW_IGNORE_FONTS_CHANGE (1 << 1)
3510
3511 int lookup_fringe_bitmap (Lisp_Object);
3512 void draw_fringe_bitmap (struct window *, struct glyph_row *, int);
3513 void draw_row_fringe_bitmaps (struct window *, struct glyph_row *);
3514 bool draw_window_fringes (struct window *, bool);
3515 bool update_window_fringes (struct window *, bool);
3516
3517 void gui_init_fringe (struct redisplay_interface *);
3518
3519 extern int max_used_fringe_bitmap;
3520 void gui_define_fringe_bitmap (struct frame *, int);
3521
3522 #ifdef HAVE_NTGUI
3523 void w32_reset_fringes (void);
3524 #endif
3525
3526 extern unsigned row_hash (struct glyph_row *);
3527
3528 extern bool buffer_flipping_blocked_p (void);
3529
3530 extern void update_redisplay_ticks (int, struct window *);
3531
3532 /* Defined in image.c */
3533
3534 #ifdef HAVE_WINDOW_SYSTEM
3535
3536 extern ptrdiff_t image_bitmap_pixmap (struct frame *, ptrdiff_t);
3537 extern void image_reference_bitmap (struct frame *, ptrdiff_t);
3538 extern ptrdiff_t image_create_bitmap_from_data (struct frame *, char *,
3539 unsigned int, unsigned int);
3540 extern ptrdiff_t image_create_bitmap_from_file (struct frame *, Lisp_Object);
3541 #if defined HAVE_XPM && defined HAVE_X_WINDOWS && !defined USE_GTK
3542 extern ptrdiff_t x_create_bitmap_from_xpm_data (struct frame *, const char **);
3543 #endif
3544 #ifndef image_destroy_bitmap
3545 extern void image_destroy_bitmap (struct frame *, ptrdiff_t);
3546 #endif
3547 extern void image_destroy_all_bitmaps (Display_Info *);
3548 #ifdef HAVE_X_WINDOWS
3549 extern void x_create_bitmap_mask (struct frame *, ptrdiff_t);
3550 #ifndef USE_CAIRO
3551 extern void x_kill_gs_process (Pixmap, struct frame *);
3552 #endif /* !USE_CAIRO */
3553 #endif
3554 extern Lisp_Object image_find_image_file (Lisp_Object);
3555
3556 struct image_cache *make_image_cache (void);
3557 void free_image_cache (struct frame *);
3558 void clear_image_caches (Lisp_Object);
3559 void mark_image_cache (struct image_cache *);
3560 void image_prune_animation_caches (bool);
3561 bool valid_image_p (Lisp_Object);
3562 void prepare_image_for_display (struct frame *, struct image *);
3563 ptrdiff_t lookup_image (struct frame *, Lisp_Object, int);
3564
3565 #if defined HAVE_X_WINDOWS || defined USE_CAIRO || defined HAVE_NS \
3566 || defined HAVE_HAIKU
3567 #define RGB_PIXEL_COLOR unsigned long
3568 #endif
3569
3570 #ifdef HAVE_NTGUI
3571 #define RGB_PIXEL_COLOR COLORREF
3572 #endif
3573
3574 RGB_PIXEL_COLOR image_background (struct image *, struct frame *,
3575 Emacs_Pix_Context img);
3576 int image_background_transparent (struct image *, struct frame *,
3577 Emacs_Pix_Context mask);
3578
3579 int image_ascent (struct image *, struct face *, struct glyph_slice *);
3580
3581 #endif
3582
3583 /* Defined in sysdep.c */
3584
3585 void get_tty_size (int, int *, int *);
3586 void request_sigio (void);
3587 void unrequest_sigio (void);
3588 bool tabs_safe_p (int);
3589 void init_baud_rate (int);
3590 void init_sigio (int);
3591
3592 /* Defined in xfaces.c. */
3593
3594 #ifdef HAVE_X_WINDOWS
3595 void unload_color (struct frame *, unsigned long);
3596 void x_free_colors (struct frame *, unsigned long *, int);
3597 #endif
3598
3599 void update_face_from_frame_parameter (struct frame *, Lisp_Object,
3600 Lisp_Object);
3601 extern bool tty_defined_color (struct frame *, const char *, Emacs_Color *,
3602 bool, bool);
3603 bool parse_color_spec (const char *,
3604 unsigned short *, unsigned short *, unsigned short *);
3605
3606 Lisp_Object tty_color_name (struct frame *, int);
3607 void clear_face_cache (bool);
3608 unsigned long load_color (struct frame *, struct face *, Lisp_Object,
3609 enum lface_attribute_index);
3610 char *choose_face_font (struct frame *, Lisp_Object *, Lisp_Object,
3611 int *);
3612 #ifdef HAVE_WINDOW_SYSTEM
3613 void prepare_face_for_display (struct frame *, struct face *);
3614 #endif
3615 int lookup_named_face (struct window *, struct frame *, Lisp_Object, bool);
3616 int lookup_basic_face (struct window *, struct frame *, int);
3617 int smaller_face (struct frame *, int, int);
3618 int face_with_height (struct frame *, int, int);
3619 int lookup_derived_face (struct window *, struct frame *,
3620 Lisp_Object, int, bool);
3621 void init_frame_faces (struct frame *);
3622 void free_frame_faces (struct frame *);
3623 void recompute_basic_faces (struct frame *);
3624 int face_at_buffer_position (struct window *, ptrdiff_t, ptrdiff_t *,
3625 ptrdiff_t, bool, int, enum lface_attribute_index);
3626 int face_for_overlay_string (struct window *, ptrdiff_t, ptrdiff_t *, ptrdiff_t,
3627 bool, Lisp_Object, enum lface_attribute_index);
3628 int face_at_string_position (struct window *, Lisp_Object, ptrdiff_t, ptrdiff_t,
3629 ptrdiff_t *, enum face_id, bool,
3630 enum lface_attribute_index);
3631 int merge_faces (struct window *, Lisp_Object, int, int);
3632 int compute_char_face (struct frame *, int, Lisp_Object);
3633 void free_all_realized_faces (Lisp_Object);
3634 extern char unspecified_fg[], unspecified_bg[];
3635
3636 /* Defined in xfns.c. */
3637
3638 #ifdef HAVE_X_WINDOWS
3639 void gamma_correct (struct frame *, XColor *);
3640 #endif
3641 #ifdef HAVE_NTGUI
3642 void gamma_correct (struct frame *, COLORREF *);
3643 #endif
3644 #ifdef HAVE_HAIKU
3645 void gamma_correct (struct frame *, Emacs_Color *);
3646 #endif
3647
3648 #ifdef HAVE_WINDOW_SYSTEM
3649
3650 extern void start_hourglass (void);
3651 extern void cancel_hourglass (void);
3652
3653 /* Returns the background color of IMG, calculating one heuristically if
3654 necessary. If non-zero, XIMG is an existing XImage object to use for
3655 the heuristic. */
3656
3657 #define IMAGE_BACKGROUND(img, f, ximg) \
3658 ((img)->background_valid \
3659 ? (img)->background \
3660 : image_background (img, f, ximg))
3661
3662 /* Returns true if IMG has a `transparent' background, using heuristics
3663 to decide if necessary. If non-zero, MASK is an existing XImage
3664 object to use for the heuristic. */
3665
3666 #define IMAGE_BACKGROUND_TRANSPARENT(img, f, mask) \
3667 ((img)->background_transparent_valid \
3668 ? (img)->background_transparent \
3669 : image_background_transparent (img, f, mask))
3670
3671 #endif /* HAVE_WINDOW_SYSTEM */
3672
3673
3674 /* Defined in xmenu.c. */
3675
3676 int popup_activated (void);
3677
3678 /* Defined in dispnew.c. */
3679
3680 extern Lisp_Object buffer_posn_from_coords (struct window *,
3681 int *, int *,
3682 struct display_pos *,
3683 Lisp_Object *,
3684 int *, int *, int *, int *);
3685 extern Lisp_Object mode_line_string (struct window *, enum window_part,
3686 int *, int *, ptrdiff_t *,
3687 Lisp_Object *,
3688 int *, int *, int *, int *);
3689 extern Lisp_Object marginal_area_string (struct window *, enum window_part,
3690 int *, int *, ptrdiff_t *,
3691 Lisp_Object *,
3692 int *, int *, int *, int *);
3693 extern void redraw_frame (struct frame *);
3694 extern bool update_frame (struct frame *, bool, bool);
3695 extern void update_frame_with_menu (struct frame *, int, int);
3696 extern int update_mouse_position (struct frame *, int, int);
3697 extern void bitch_at_user (void);
3698 extern void adjust_frame_glyphs (struct frame *);
3699 void free_glyphs (struct frame *);
3700 void free_window_matrices (struct window *);
3701 void check_glyph_memory (void);
3702 void mirrored_line_dance (struct glyph_matrix *, int, int, int *, char *);
3703 void clear_glyph_matrix (struct glyph_matrix *);
3704 void clear_current_matrices (struct frame *f);
3705 void clear_desired_matrices (struct frame *);
3706 void shift_glyph_matrix (struct window *, struct glyph_matrix *,
3707 int, int, int);
3708 void rotate_matrix (struct glyph_matrix *, int, int, int);
3709 void increment_matrix_positions (struct glyph_matrix *,
3710 int, int, ptrdiff_t, ptrdiff_t);
3711 void blank_row (struct window *, struct glyph_row *, int);
3712 void clear_glyph_matrix_rows (struct glyph_matrix *, int, int);
3713 void clear_glyph_row (struct glyph_row *);
3714 void prepare_desired_row (struct window *, struct glyph_row *, bool);
3715 void update_single_window (struct window *);
3716 #ifdef HAVE_WINDOW_SYSTEM
3717 extern void gui_update_window_begin (struct window *);
3718 extern void gui_update_window_end (struct window *, bool, bool);
3719 #endif
3720 void do_pending_window_change (bool);
3721 void change_frame_size (struct frame *, int, int, bool, bool, bool);
3722 void init_display (void);
3723 void syms_of_display (void);
3724 extern void spec_glyph_lookup_face (struct window *, GLYPH *);
3725 extern void fill_up_frame_row_with_spaces (struct glyph_row *, int);
3726
3727 /* Defined in terminal.c. */
3728
3729 extern void ring_bell (struct frame *);
3730 extern void update_begin (struct frame *);
3731 extern void update_end (struct frame *);
3732 extern void set_terminal_window (struct frame *, int);
3733 extern void cursor_to (struct frame *, int, int);
3734 extern void raw_cursor_to (struct frame *, int, int);
3735 extern void clear_to_end (struct frame *);
3736 extern void clear_frame (struct frame *);
3737 extern void clear_end_of_line (struct frame *, int);
3738 extern void write_glyphs (struct frame *, struct glyph *, int);
3739 extern void insert_glyphs (struct frame *, struct glyph *, int);
3740 extern void delete_glyphs (struct frame *, int);
3741 extern void ins_del_lines (struct frame *, int, int);
3742
3743 extern struct terminal *init_initial_terminal (void);
3744
3745
3746 /* Defined in term.c */
3747
3748 extern void tty_turn_off_insert (struct tty_display_info *);
3749 extern int string_cost (const char *);
3750 extern int per_line_cost (const char *);
3751 extern void calculate_costs (struct frame *);
3752 extern void produce_glyphs (struct it *);
3753 extern bool tty_capable_p (struct tty_display_info *, unsigned);
3754 extern void set_tty_color_mode (struct tty_display_info *, struct frame *);
3755 extern void create_tty_output (struct frame *);
3756 extern struct terminal *init_tty (const char *, const char *, bool);
3757 extern void tty_append_glyph (struct it *);
3758
3759 /* All scrolling costs measured in characters.
3760 So no cost can exceed the area of a frame, measured in characters.
3761 Let's hope this is never more than 1000000 characters. */
3762 enum { SCROLL_INFINITY = 1000000 };
3763
3764 /* Defined in scroll.c */
3765
3766 extern int scrolling_max_lines_saved (int, int, unsigned *, unsigned *, int *);
3767 extern void do_line_insertion_deletion_costs (struct frame *, const char *,
3768 const char *, const char *,
3769 const char *, const char *,
3770 const char *, int);
3771 void scrolling_1 (struct frame *, int, int, int, int *, int *, unsigned *,
3772 unsigned *, int);
3773
3774 /* Defined in frame.c */
3775
3776 #ifdef HAVE_WINDOW_SYSTEM
3777
3778 /* Types we might convert a resource string into. */
3779 enum resource_types
3780 {
3781 RES_TYPE_NUMBER,
3782 RES_TYPE_FLOAT,
3783 RES_TYPE_BOOLEAN,
3784 RES_TYPE_STRING,
3785 RES_TYPE_SYMBOL,
3786 RES_TYPE_BOOLEAN_NUMBER
3787 };
3788
3789 extern Display_Info *check_x_display_info (Lisp_Object);
3790 extern Lisp_Object gui_display_get_arg (Display_Info *, Lisp_Object,
3791 Lisp_Object, const char *, const char *,
3792 enum resource_types);
3793 extern Lisp_Object gui_frame_get_and_record_arg (struct frame *, Lisp_Object,
3794 Lisp_Object,
3795 const char *, const char *,
3796 enum resource_types);
3797 extern Lisp_Object gui_default_parameter (struct frame *, Lisp_Object,
3798 Lisp_Object, Lisp_Object,
3799 const char *, const char *,
3800 enum resource_types);
3801
3802 extern bool gui_mouse_grabbed (Display_Info *);
3803 extern void gui_redo_mouse_highlight (Display_Info *);
3804
3805 #endif /* HAVE_WINDOW_SYSTEM */
3806
3807 INLINE_HEADER_END
3808
3809 #endif /* not DISPEXTERN_H_INCLUDED */