Buildchain fix from Nelson
[sxemacs] / src / ui / redisplay.c
1 /* Display generation from window structure and buffer text.
2    Copyright (C) 1994, 1995, 1996 Board of Trustees, University of Illinois.
3    Copyright (C) 1995 Free Software Foundation, Inc.
4    Copyright (C) 1995, 1996 Ben Wing.
5    Copyright (C) 1995 Sun Microsystems, Inc.
6    Copyright (C) 1996 Chuck Thompson.
7
8 This file is part of SXEmacs
9
10 SXEmacs is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14
15 SXEmacs is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program.  If not, see <http://www.gnu.org/licenses/>. */
22
23
24 /* Synched up with:  Not in FSF. */
25
26 /* Author: Chuck Thompson */
27
28 /* Fixed up by Ben Wing for Mule */
29
30 /* This file has been Mule-ized. */
31
32 /*****************************************************************************
33  The Golden Rules of Redisplay
34
35  First:         It Is Better To Be Correct Than Fast
36  Second:        Thou Shalt Not Run Elisp From Within Redisplay
37  Third:         It Is Better To Be Fast Than Not To Be
38  ****************************************************************************/
39
40 #include <config.h>
41 #include "lisp.h"
42
43 #include "buffer.h"
44 #include "commands.h"
45 #include "debug.h"
46 #include "device.h"
47 #include "elhash.h"
48 #include "extents.h"
49 #include "faces.h"
50 #include "frame.h"
51 #include "glyphs.h"
52 #include "gutter.h"
53 #include "insdel.h"
54 #include "menubar.h"
55 #include "objects.h"
56 #include "process.h"
57 #include "redisplay.h"
58 #include "toolbar.h"
59 #include "window.h"
60 #include "line-number.h"
61 #ifdef FILE_CODING
62 #include "mule/file-coding.h"
63 #endif
64
65 #include "sysfile.h"
66
67 /* Note: We have to be careful throughout this code to properly handle
68    and differentiate between Bufbytes and Emchars.
69
70    Since strings are generally composed of Bufbytes, I've taken the tack
71    that any contiguous set of Bufbytes is called a "string", while
72    any contiguous set of Emchars is called an "array". */
73
74 /* Return value to indicate a failure by an add_*_rune routine to add
75    a rune, but no propagation information needs to be returned. */
76 #define ADD_FAILED (prop_block_dynarr *) 1
77
78 #define BEGIN_GLYPHS    0
79 #define END_GLYPHS      1
80 #define LEFT_GLYPHS     2
81 #define RIGHT_GLYPHS    3
82
83 #define VERTICAL_CLIP(w, display)                                       \
84     ((WINDOW_TTY_P (w) | (!display && scroll_on_clipped_lines))         \
85       ? INT_MAX                                                         \
86       : vertical_clip)
87
88 /* The following structures are completely private to redisplay.c so
89    we put them here instead of in a header file, for modularity. */
90
91 /* NOTE: Bytinds not Bufpos's in this structure. */
92
93 typedef struct position_redisplay_data_type {
94         /* This information is normally filled in by the create_*_block
95            routines and is used by the add_*_rune routines. */
96         Lisp_Object window;
97         /* if we are working with strings rather than buffers we need a
98            handle to the string */
99         Lisp_Object string;
100         struct device *d;
101         struct display_block *db;
102         struct display_line *dl;
103         Emchar ch;              /* Character that is to be added.  This is
104                                    used to communicate this information to
105                                    add_emchar_rune(). */
106         Lisp_Object last_charset;       /* The charset of the previous character.
107                                            Used to optimize some lookups -- we
108                                            only have to do some things when
109                                            the charset changes. */
110         face_index last_findex; /* The face index of the previous character.
111                                    Needed to ensure the validity of the
112                                    last_charset optimization. */
113
114         int last_char_width;    /* The width of the previous character. */
115         int font_is_bogus;      /* If true, it means we couldn't instantiate
116                                    the font for this charset, so we substitute
117                                    ~'s from the ASCII charset. */
118         Bytind bi_bufpos;
119         Bytind bi_endpos;
120         int pixpos;
121         int max_pixpos;
122         int blank_width;        /* Width of the blank that is to be added.
123                                    This is used to communicate this information
124                                    to add_blank_rune().
125
126                                    This is also used rather cheesily to
127                                    communicate the width of the eol-cursor-size
128                                    blank that exists at the end of the line.
129                                    add_emchar_rune() is called cheesily with
130                                    the non-printing char '\n', which is stuck
131                                    in the output routines with its width being
132                                    BLANK_WIDTH. */
133         Bytind bi_cursor_bufpos;        /* This stores the buffer position of the cursor. */
134         unsigned int cursor_type:3;
135         int cursor_x;           /* rune block cursor is at */
136         int start_col;          /* Number of character columns (each column has
137                                    a width of the default char width) that still
138                                    need to be skipped.  This is used for horizontal
139                                    scrolling, where a certain number of columns
140                                    (those off the left side of the screen) need
141                                    to be skipped before anything is displayed. */
142         Bytind bi_start_col_enabled;
143         int start_col_xoffset;  /* Number of pixels that still need to
144                                    be skipped.  This is used for
145                                    horizontal scrolling of glyphs, where we want
146                                    to be able to scroll over part of the glyph. */
147
148         int hscroll_glyph_width_adjust; /* how much the width of the hscroll
149                                            glyph differs from space_width (w).
150                                            0 if no hscroll glyph was used,
151                                            i.e. the window is not scrolled
152                                            horizontally.  Used in tab
153                                            calculations. */
154
155         /* Information about the face the text should be displayed in and
156            any begin-glyphs and end-glyphs. */
157         struct extent_fragment *ef;
158         face_index findex;
159
160         /* The height of a pixmap may either be predetermined if the user has set a
161            baseline value, or it may be dependent on whatever the line ascent and
162            descent values end up being, based just on font and pixmap-ascent
163            information.  In the first case we can immediately update the values, thus
164            their inclusion here.  In the last case we cannot determine the actual
165            contribution to the line height until we have finished laying out all text
166            on the line.  Thus we propagate the max height of such pixmaps and do a
167            final calculation (in calculate_baseline()) after all text has been added
168            to the line. */
169         int new_ascent;
170         int new_descent;
171         int max_pixmap_height;
172         int need_baseline_computation;
173         int end_glyph_width;    /* Well, it is the kitchen sink after all ... */
174
175         Lisp_Object result_str; /* String where we put the result of
176                                    generating a formatted string in the modeline. */
177         int is_modeline;        /* Non-zero if we're generating the modeline. */
178         Charcount modeline_charpos;     /* Number of chars used in result_str so far;
179                                            corresponds to bytepos. */
180         Bytecount bytepos;      /* Number of bytes used in result_str so far.
181                                    We don't actually copy the bytes into result_str
182                                    until the end because we don't know how big the
183                                    string is going to be until then. */
184 } pos_data;
185
186 enum prop_type {
187         PROP_STRING,
188         PROP_CHAR,
189         PROP_MINIBUF_PROMPT,
190         PROP_BLANK,
191         PROP_GLYPH
192 };
193
194 /* Data that should be propagated to the next line.  Either a single
195    Emchar, a string of Bufbyte's or a glyph.
196
197    The actual data that is propagated ends up as a Dynarr of these
198    blocks.
199
200    prop_blocks are used to indicate that data that was supposed to go
201    on the previous line couldn't actually be displayed. Generally this
202    shouldn't happen if we are clipping the end of lines. If we are
203    wrapping then we need to display the propagation data before moving
204    on. Its questionable whether we should wrap or clip glyphs in this
205    instance. Most e-lisp relies on clipping so we preserve this
206    behavior.
207
208    #### It's unclean that both Emchars and Bufbytes are here.
209    */
210
211 typedef struct prop_block prop_block;
212 struct prop_block {
213         enum prop_type type;
214
215         union data {
216                 struct {
217                         Bufbyte *str;
218                         Bytecount len;  /* length of the string. */
219                 } p_string;
220
221                 struct {
222                         Emchar ch;
223                         Bytind bi_cursor_bufpos;        /* NOTE: is in Bytinds */
224                         unsigned int cursor_type:3;
225                 } p_char;
226
227                 struct {
228                         int width;