Coverity fixes
[sxemacs] / src / ui / redisplay.h
1 /* Redisplay data structures.
2    Copyright (C) 1994, 1995 Board of Trustees, University of Illinois.
3    Copyright (C) 1996 Chuck Thompson.
4    Copyright (C) 1995, 1996 Ben Wing.
5
6 This file is part of SXEmacs
7
8 SXEmacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 SXEmacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program.  If not, see <http://www.gnu.org/licenses/>. */
20
21
22 /* Synched up with: Not in FSF. */
23
24 #ifndef INCLUDED_redisplay_h_
25 #define INCLUDED_redisplay_h_
26
27 /* Redisplay DASSERT types */
28 #define DB_DISP_POS             1
29 #define DB_DISP_TEXT_LAYOUT     2
30 #define DB_DISP_REDISPLAY       4
31
32 /* These are the possible return values from pixel_to_glyph_translation. */
33 #define OVER_MODELINE           0
34 #define OVER_TEXT               1
35 #define OVER_OUTSIDE            2
36 #define OVER_NOTHING            3
37 #define OVER_BORDER             4
38 #define OVER_TOOLBAR            5
39 #define OVER_V_DIVIDER          6
40
41 #define NO_BLOCK        -1
42
43 /* Imagine that the text in the buffer is displayed on a piece of paper
44    the width of the frame and very very tall.  The line start cache is
45    an array of struct line_start_cache's, describing the start and
46    end buffer positions for a contiguous set of lines on that piece
47    of paper. */
48
49 typedef struct line_start_cache line_start_cache;
50 struct line_start_cache {
51         Bufpos start, end;
52         int height;
53 };
54
55 typedef struct {
56         Dynarr_declare(line_start_cache);
57 } line_start_cache_dynarr;
58
59 /* The possible types of runes.
60
61    #### The Lisp_Glyph type is broken.  There should instead be a pixmap
62    type.  Currently the device-specific output routines have to worry
63    about whether the glyph is textual or not, etc.  For Mule this is
64    a big problem because you might need multiple fonts to display the
65    text.  It also eliminates optimizations that could come from glumping
66    the text of multiple text glyphs together -- this makes displaying
67    binary files (with lots of control chars, etc.) very very slow. */
68
69 #define RUNE_BLANK      0
70 #define RUNE_CHAR       1
71 #define RUNE_DGLYPH     2
72 #define RUNE_HLINE      3
73 #define RUNE_VLINE      4
74
75 #define CURSOR_ON       0
76 #define CURSOR_OFF      1
77 #define NO_CURSOR       2
78 #define NEXT_CURSOR     3
79 #define IGNORE_CURSOR   4
80
81 #define DEFAULT_INDEX   (face_index) 0
82 #define MODELINE_INDEX  (face_index) 1
83
84 /* A rune is a single display element, such as a printable character
85    or pixmap.  Any single character in a buffer has one or more runes
86    (or zero, if the character is invisible) corresponding to it.
87    (Printable characters typically have one rune associated with them,
88    but control characters have two -- a ^ and a letter -- and other
89    non-printing characters (those displayed in octal) have four. */
90
91 /* WARNING! In compare_runes (one of the most heavily used functions)
92    two runes are compared. So please be careful with changes to this
93    structure. See comments in compare_runes.
94
95    #### This should really be made smaller.
96 */
97
98 typedef struct rune rune;
99 struct rune {
100         face_index findex;      /* face rune is displayed with.  The
101                                    face_index is an index into a
102                                    window-specific array of face cache
103                                    elements.  Each face cache element
104                                    corresponds to one "merged face"
105                                    (the result of merging all the
106                                    faces that overlap the rune) and
107                                    contains the instance values for
108                                    each of the face properties in this
109                                    particular window. */
110
111         Bufpos bufpos;          /* buffer position this rune is displaying;
112                                    for the modeline, the value here is a
113                                    Charcount, but who's looking? */
114         Bufpos endpos;          /* if set this rune covers a range of pos */
115         /* #### Chuck, what does it mean for a rune
116            to cover a range of pos?  I don't get
117            this. */
118         /* #### This isn't used as an rvalue anywhere!
119            remove! */
120
121         short xpos;             /* horizontal starting position in pixels */
122         short width;            /* pixel width of rune */
123
124         unsigned char cursor_type;      /* is this rune covered by the cursor? */
125         unsigned char type;     /* type of rune object */
126         /* We used to do bitfields here, but if I
127            (JV) count correctly that doesn't matter
128            for the size of the structure. All the bit
129            fiddling _does_ slow down redisplay by
130            about 10%. So don't do that */
131
132         union {                 /* Information specific to the type of rune */
133                 /* #### Glyphs are rare. Is it really necessary to waste 8 bytes on every
134                    rune for that?! */
135                 /* DGLYPH */
136                 struct {
137                         Lisp_Object glyph;
138                         Lisp_Object extent;     /* extent rune is attached to, if any.
139                                                    If this is a rune in the modeline
140                                                    then this might be nil. */
141
142                         int ascent;     /* Ascent of this glyph, in pixels. */
143                         int descent;    /* Descent of this glyph, in pixels. */
144                         int yoffset;    /* Offset from line top to reach glyph top */
145                         int xoffset;    /* Number of pixels that need to be
146                                            chopped off the left of the glyph.
147                                            This has the effect of shifting the
148                                            glyph to the left while still clipping
149                                            at XPOS. */
150                 } dglyph;
151
152                 /* CHAR */
153                 struct {
154                         Emchar ch;      /* Character of this rune. */
155                 } chr;
156
157                 /* HLINE */
158                 struct {
159                         short thickness;        /* how thick to make hline */
160                         short yoffset;  /* how far down from top of line to put top */
161                 } hline;
162         } object;               /* actual rune object */
163 };
164
165 typedef struct {
166         Dynarr_declare(rune);
167 } rune_dynarr;
168
169 /* These must have distinct values.  Note that the ordering actually
170    represents priority levels.  TEXT has the lowest priority level. */
171 enum display_type {
172         TEXT,
173         LEFT_OUTSIDE_MARGIN,
174         LEFT_INSIDE_MARGIN,
175         RIGHT_INSIDE_MARGIN,
176         RIGHT_OUTSIDE_MARGIN,
177         OVERWRITE
178 };
179
180 /* A display block represents a run of text on a single line.
181    Apparently there is only one display block per line for each
182    of the types listed in `enum display_type'.
183
184    A display block consists mostly of an array of runes, one per
185    atomic display element (printable character, pixmap, etc.). */
186
187 /* #### Yuckity yuckity yuck yuck yuck yuck yuck!!
188
189    Chuck, I think you should redo this.  It should not be the
190    responsibility of the device-specific code to worry about
191    the different faces.  The generic stuff in redisplay-output.c
192    should glump things up into sub-blocks, each of which
193    corresponds to a single pixmap or a single run of text in
194    the same font.
195
196    It might still make sense for the device-specific output routine
197    to get passed an entire display line.  That way, it can make
198    calls to XDrawText() (which draws multiple runs of single-font
199    data) instead of XDrawString().  The reason for this is to
200    reduce the amount of X traffic, which will help things significantly
201    on a slow line. */
202
203 typedef struct display_block display_block;
204 struct display_block {
205         enum display_type type; /* type of display block */
206
207         int start_pos;          /* starting pixel position of block */
208         int end_pos;            /* ending pixel position of block */
209
210         rune_dynarr *runes;     /* Dynamic array of runes */
211 };
212
213 typedef struct {
214         Dynarr_declare(display_block);
215 } display_block_dynarr;
216
217 typedef struct layout_bounds_type {
218         int left_out;
219         int left_in;
220         int left_white;
221         int right_white;
222         int right_in;
223         int right_out;
224 } layout_bounds;
225
226 typedef struct glyph_block glyph_block;
227 struct glyph_block {
228         Lisp_Object glyph;
229         Lisp_Object extent;
230         
231         face_index findex; /* Only used by margin routines.  */
232         int active;        /* For begin/end glyph indicates type,
233                               otherwise for margin routines. */
234         int width;         /* Only used by margin routines.  */
235 };
236
237 typedef struct {
238         Dynarr_declare(glyph_block);
239 } glyph_block_dynarr;
240
241 /*************************************************************************/
242 /*                              display lines