Mercurial > hg > xemacs-beta
annotate src/redisplay.c @ 5313:5ed261fd2bd9
Unrool a load-time loop at macro expansion time, cl-macs.el
2010-12-29 Aidan Kehoe <kehoea@parhasard.net>
* cl-macs.el (inline-side-effect-free-compiler-macros):
Unroll a loop here at macro-expansion time, so these compiler
macros are compiled. Use #'eql instead of #'eq in a couple of
places for better style.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Wed, 29 Dec 2010 23:43:10 +0000 |
parents | bc3ede8f29a8 |
children | 39304a35b6b3 308d34e9f07d |
rev | line source |
---|---|
428 | 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. | |
4928
ea701c23ed84
change text_width method to take a window, in preparation for unicode-internal changes
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
4 Copyright (C) 1995, 1996, 2000, 2001, 2002, 2003, 2005, 2010 Ben Wing. |
428 | 5 Copyright (C) 1995 Sun Microsystems, Inc. |
6 Copyright (C) 1996 Chuck Thompson. | |
7 | |
8 This file is part of XEmacs. | |
9 | |
10 XEmacs is free software; you can redistribute it and/or modify it | |
11 under the terms of the GNU General Public License as published by the | |
12 Free Software Foundation; either version 2, or (at your option) any | |
13 later version. | |
14 | |
15 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
18 for more details. | |
19 | |
20 You should have received a copy of the GNU General Public License | |
21 along with XEmacs; see the file COPYING. If not, write to | |
22 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 Boston, MA 02111-1307, USA. */ | |
24 | |
25 /* Synched up with: Not in FSF. */ | |
26 | |
27 /* Author: Chuck Thompson */ | |
28 | |
29 /* Fixed up by Ben Wing for Mule */ | |
30 | |
31 /* This file has been Mule-ized. */ | |
32 | |
33 /***************************************************************************** | |
34 The Golden Rules of Redisplay | |
35 | |
853 | 36 First: It Is Better To Be Correct Than Fast |
37 Second: Thou Shalt Use Due Caution When Running Elisp From Within Redisplay | |
38 Third: It Is Better To Be Fast Than Not To Be | |
428 | 39 ****************************************************************************/ |
40 | |
1318 | 41 /* Note: The second rule used to prohibit running Elisp from within |
42 redisplay, but that's not correct any more -- use | |
43 call*_trapping_problems() or call_with_suspended_errors() instead. | |
853 | 44 |
45 --ben | |
46 */ | |
47 | |
428 | 48 #include <config.h> |
49 #include "lisp.h" | |
50 | |
51 #include "buffer.h" | |
52 #include "commands.h" | |
53 #include "debug.h" | |
872 | 54 #include "device-impl.h" |
428 | 55 #include "elhash.h" |
853 | 56 #include "events.h" |
872 | 57 #include "extents-impl.h" |
428 | 58 #include "faces.h" |
872 | 59 #include "frame-impl.h" |
428 | 60 #include "glyphs.h" |
61 #include "gutter.h" | |
62 #include "insdel.h" | |
63 #include "menubar.h" | |
5176
8b2f75cecb89
rename objects* (.c, .h and .el files) to fontcolor*
Ben Wing <ben@xemacs.org>
parents:
5049
diff
changeset
|
64 #include "fontcolor-impl.h" |
1318 | 65 #include "opaque.h" |
428 | 66 #include "process.h" |
1292 | 67 #include "profile.h" |
428 | 68 #include "redisplay.h" |
69 #include "toolbar.h" | |
872 | 70 #include "window-impl.h" |
428 | 71 #include "line-number.h" |
72 #include "file-coding.h" | |
73 | |
442 | 74 #include "sysfile.h" |
75 | |
428 | 76 #ifdef HAVE_TTY |
77 #include "console-tty.h" | |
78 #endif /* HAVE_TTY */ | |
79 | |
80 /* Note: We have to be careful throughout this code to properly handle | |
867 | 81 and differentiate between Ibytes and Ichars. |
82 | |
83 Since strings are generally composed of Ibytes, I've taken the tack | |
84 that any contiguous set of Ibytes is called a "string", while | |
85 any contiguous set of Ichars is called an "array". */ | |
428 | 86 |
87 /* Return value to indicate a failure by an add_*_rune routine to add | |
88 a rune, but no propagation information needs to be returned. */ | |
89 #define ADD_FAILED (prop_block_dynarr *) 1 | |
90 | |
91 #define BEGIN_GLYPHS 0 | |
92 #define END_GLYPHS 1 | |
93 #define LEFT_GLYPHS 2 | |
94 #define RIGHT_GLYPHS 3 | |
95 | |
96 #define VERTICAL_CLIP(w, display) \ | |
442 | 97 ((WINDOW_TTY_P (w) | (!display && scroll_on_clipped_lines)) \ |
428 | 98 ? INT_MAX \ |
442 | 99 : vertical_clip) |
428 | 100 |
101 /* The following structures are completely private to redisplay.c so | |
102 we put them here instead of in a header file, for modularity. */ | |
103 | |
826 | 104 /* NOTE: Bytexpos's not Charxpos's in this structure. */ |
428 | 105 |
106 typedef struct position_redisplay_data_type | |
107 { | |
108 /* This information is normally filled in by the create_*_block | |
109 routines and is used by the add_*_rune routines. */ | |
110 Lisp_Object window; | |
111 /* if we are working with strings rather than buffers we need a | |
112 handle to the string */ | |
113 Lisp_Object string; | |
114 struct device *d; | |
115 struct display_block *db; | |
116 struct display_line *dl; | |
867 | 117 Ichar ch; /* Character that is to be added. This is |
428 | 118 used to communicate this information to |
867 | 119 add_ichar_rune(). */ |
428 | 120 Lisp_Object last_charset; /* The charset of the previous character. |
121 Used to optimize some lookups -- we | |
122 only have to do some things when | |
123 the charset changes. */ | |
124 face_index last_findex; /* The face index of the previous character. | |
125 Needed to ensure the validity of the | |
126 last_charset optimization. */ | |
127 | |
128 int last_char_width; /* The width of the previous character. */ | |
129 int font_is_bogus; /* If true, it means we couldn't instantiate | |
130 the font for this charset, so we substitute | |
131 ~'s from the ASCII charset. */ | |
826 | 132 Bytexpos byte_charpos; /* Position of character we are processing. This |
133 is a Bytexpos, meaning it refers to bytes (not | |
134 chars) and can refer to either buffers (1-based) | |
135 or strings (0-based). We need to be careful | |
136 when doing anything that references the text in | |
137 the buffer or string. */ | |
138 Bytexpos byte_endpos; /* ????? Unknown, under-used. */ | |
428 | 139 int pixpos; |
140 int max_pixpos; | |
141 int blank_width; /* Width of the blank that is to be added. | |
142 This is used to communicate this information | |
143 to add_blank_rune(). | |
144 | |
145 This is also used rather cheesily to | |
146 communicate the width of the eol-cursor-size | |
147 blank that exists at the end of the line. | |
867 | 148 add_ichar_rune() is called cheesily with |
428 | 149 the non-printing char '\n', which is stuck |
150 in the output routines with its width being | |
151 BLANK_WIDTH. */ | |
826 | 152 Bytexpos byte_cursor_charpos; /* This stores the buffer position of the |
153 cursor. */ | |
428 | 154 unsigned int cursor_type :3; |
155 int cursor_x; /* rune block cursor is at */ | |
156 int start_col; /* Number of character columns (each column has | |
157 a width of the default char width) that still | |
158 need to be skipped. This is used for horizontal | |
159 scrolling, where a certain number of columns | |
160 (those off the left side of the screen) need | |
161 to be skipped before anything is displayed. */ | |
826 | 162 Bytexpos byte_start_col_enabled; |
428 | 163 int start_col_xoffset; /* Number of pixels that still need to |
4187 | 164 be skipped. This is used for |
165 horizontal scrolling of glyphs, where we want | |
166 to be able to scroll over part of the glyph. */ | |
428 | 167 |
168 int hscroll_glyph_width_adjust; /* how much the width of the hscroll | |
169 glyph differs from space_width (w). | |
170 0 if no hscroll glyph was used, | |
171 i.e. the window is not scrolled | |
172 horizontally. Used in tab | |
173 calculations. */ | |
174 | |
175 /* Information about the face the text should be displayed in and | |
176 any begin-glyphs and end-glyphs. */ | |
177 struct extent_fragment *ef; | |
178 face_index findex; | |
179 | |
819 | 180 /* The height of a pixmap may either be predetermined if the user has set a |
181 baseline value, or it may be dependent on whatever the line ascent and | |
182 descent values end up being, based just on font and pixmap-ascent | |
183 information. In the first case we can immediately update the values, thus | |
184 their inclusion here. In the last case we cannot determine the actual | |
185 contribution to the line height until we have finished laying out all text | |
186 on the line. Thus we propagate the max height of such pixmaps and do a | |
187 final calculation (in calculate_baseline()) after all text has been added | |
188 to the line. */ | |
428 | 189 int new_ascent; |
190 int new_descent; | |
191 int max_pixmap_height; | |
819 | 192 int need_baseline_computation; |
193 int end_glyph_width; /* Well, it is the kitchen sink after all ... */ | |
428 | 194 |
195 Lisp_Object result_str; /* String where we put the result of | |
196 generating a formatted string in the modeline. */ | |
197 int is_modeline; /* Non-zero if we're generating the modeline. */ | |
198 Charcount modeline_charpos; /* Number of chars used in result_str so far; | |
199 corresponds to bytepos. */ | |
200 Bytecount bytepos; /* Number of bytes used in result_str so far. | |
4187 | 201 We don't actually copy the bytes into result_str |
428 | 202 until the end because we don't know how big the |
203 string is going to be until then. */ | |
204 } pos_data; | |
205 | |
206 enum prop_type | |
207 { | |
208 PROP_STRING, | |
209 PROP_CHAR, | |
210 PROP_MINIBUF_PROMPT, | |
819 | 211 PROP_BLANK, |
212 PROP_GLYPH | |
428 | 213 }; |
214 | |
215 /* Data that should be propagated to the next line. Either a single | |
867 | 216 Ichar, a string of Ibyte's or a glyph. |
428 | 217 |
218 The actual data that is propagated ends up as a Dynarr of these | |
219 blocks. | |
220 | |
819 | 221 prop_blocks are used to indicate that data that was supposed to go |
222 on the previous line couldn't actually be displayed. Generally this | |
223 shouldn't happen if we are clipping the end of lines. If we are | |
224 wrapping then we need to display the propagation data before moving | |
225 on. Its questionable whether we should wrap or clip glyphs in this | |
226 instance. Most e-lisp relies on clipping so we preserve this | |
227 behavior. | |
228 | |
867 | 229 #### It's unclean that both Ichars and Ibytes are here. |
428 | 230 */ |
231 | |
232 typedef struct prop_block prop_block; | |
233 struct prop_block | |
234 { | |
235 enum prop_type type; | |
236 | |
237 union data | |
238 { | |
239 struct | |
240 { | |
867 | 241 Ibyte *str; |
428 | 242 Bytecount len; /* length of the string. */ |
243 } p_string; | |
244 | |
245 struct | |
246 { | |
867 | 247 Ichar ch; |
826 | 248 Bytebpos byte_cursor_charpos; /* NOTE: is in Bytebpos's */ |
428 | 249 unsigned int cursor_type :3; |
250 } p_char; | |
251 | |
252 struct | |
253 { | |
254 int width; | |
255 face_index findex; | |
256 } p_blank; | |
819 | 257 |
258 struct | |
259 { | |
260 /* Not used as yet, but could be used to wrap rather than clip glyphs. */ | |
4187 | 261 int width; |
819 | 262 Lisp_Object glyph; |
263 } p_glyph; | |
264 | |
428 | 265 } data; |
266 }; | |
267 | |
268 typedef struct | |
269 { | |
270 Dynarr_declare (prop_block); | |
271 } prop_block_dynarr; | |
272 | |
273 | |
274 static Charcount generate_fstring_runes (struct window *w, pos_data *data, | |
275 Charcount pos, Charcount min_pos, | |
276 Charcount max_pos, Lisp_Object elt, | |
277 int depth, int max_pixsize, | |
438 | 278 face_index findex, int type, |
279 Charcount *offset, | |
280 Lisp_Object cur_ext); | |
428 | 281 static prop_block_dynarr *add_glyph_rune (pos_data *data, |
282 struct glyph_block *gb, | |
283 int pos_type, int allow_cursor, | |
284 struct glyph_cachel *cachel); | |
665 | 285 static Bytebpos create_text_block (struct window *w, struct display_line *dl, |
826 | 286 Bytebpos byte_start_pos, |
287 prop_block_dynarr **prop, | |
288 int type); | |
428 | 289 static int create_overlay_glyph_block (struct window *w, |
290 struct display_line *dl); | |
291 static void create_left_glyph_block (struct window *w, | |
292 struct display_line *dl, | |
293 int overlay_width); | |
294 static void create_right_glyph_block (struct window *w, | |
295 struct display_line *dl); | |
296 static void redisplay_windows (Lisp_Object window, int skip_selected); | |
867 | 297 static void decode_mode_spec (struct window *w, Ichar spec, int type); |
428 | 298 static void free_display_line (struct display_line *dl); |
826 | 299 static void update_line_start_cache (struct window *w, Charbpos from, |
300 Charbpos to, Charbpos point, | |
301 int no_regen); | |
665 | 302 static int point_visible (struct window *w, Charbpos point, int type); |
819 | 303 static void calculate_yoffset (struct display_line *dl, |
4187 | 304 struct display_block *fixup); |
819 | 305 static void calculate_baseline (pos_data *data); |
428 | 306 |
1204 | 307 #ifdef ERROR_CHECK_DISPLAY |
800 | 308 static void sledgehammer_check_redisplay_structs (void); |
1204 | 309 #endif /* ERROR_CHECK_DISPLAY */ |
800 | 310 |
428 | 311 /* This used to be 10 but 30 seems to give much better performance. */ |
312 #define INIT_MAX_PREEMPTS 30 | |
1268 | 313 static Fixnum max_preempts; |
314 | |
315 #define QUEUED_EVENTS_REQUIRED_FOR_PREEMPTION 4 | |
428 | 316 |
1318 | 317 /* Note that doing this can call Lisp. */ |
428 | 318 #define REDISPLAY_PREEMPTION_CHECK \ |
319 ((void) \ | |
320 (preempted = \ | |
321 (!disable_preemption && \ | |
322 ((preemption_count < max_preempts) || !NILP (Vexecuting_macro)) && \ | |
4187 | 323 (!INTERACTIVE || \ |
1268 | 324 detect_input_pending (QUEUED_EVENTS_REQUIRED_FOR_PREEMPTION))))) |
428 | 325 |
326 /* | |
327 * Redisplay global variables. | |
328 */ | |
329 | |
330 /* We need a third set of display structures for the cursor motion | |
331 routines. We used to just give each window a third set. However, | |
332 we always fully regenerate the structures when needed so there | |
333 isn't any reason we need more than a single set. */ | |
334 display_line_dynarr *cmotion_display_lines; | |
335 | |
336 /* We store the extents that we need to generate in a Dynarr and then | |
337 frob them all on at the end of generating the string. We do it | |
338 this way rather than adding them as we generate the string because | |
339 we don't store the text into the resulting string until we're done | |
340 (to avoid having to resize the string multiple times), and we don't | |
341 want to go around adding extents to a string when the extents might | |
342 stretch off the end of the string. */ | |
343 static EXTENT_dynarr *formatted_string_extent_dynarr; | |
344 static Bytecount_dynarr *formatted_string_extent_start_dynarr; | |
345 static Bytecount_dynarr *formatted_string_extent_end_dynarr; | |
346 | |
347 | |
348 /* #### probably temporary */ | |
458 | 349 Fixnum cache_adjustment; |
428 | 350 |
351 /* This holds a string representing the text corresponding to a single | |
352 modeline % spec. */ | |
867 | 353 static Ibyte_dynarr *mode_spec_ibyte_string; |
428 | 354 |
355 int in_display; /* 1 if in redisplay. */ | |
356 | |
1318 | 357 /* Whether we should delay size changes. Broken out of |
358 enter_redisplay_critical_section(). */ | |
359 int hold_frame_size_changes; | |
360 | |
428 | 361 int disable_preemption; /* Used for debugging redisplay and for |
362 force-redisplay. */ | |
363 | |
364 /* We only allow max_preempts preemptions before we force a redisplay. */ | |
365 static int preemption_count; | |
366 | |
367 /* Minimum pixel height of clipped bottom display line. */ | |
458 | 368 Fixnum vertical_clip; |
428 | 369 |
370 /* Minimum visible pixel width of clipped glyphs at right margin. */ | |
458 | 371 Fixnum horizontal_clip; |
428 | 372 |
373 /* Nonzero means reading single-character input with prompt | |
374 so put cursor on minibuffer after the prompt. */ | |
375 int cursor_in_echo_area; | |
376 Lisp_Object Qcursor_in_echo_area; | |
377 | |
378 /* Nonzero means truncate lines in all windows less wide than the frame */ | |
379 int truncate_partial_width_windows; | |
380 | |
381 /* non-nil if a buffer has changed since the last time redisplay completed */ | |
382 int buffers_changed; | |
383 int buffers_changed_set; | |
384 | |
385 /* non-nil if hscroll has changed somewhere or a buffer has been | |
386 narrowed or widened */ | |
387 int clip_changed; | |
388 int clip_changed_set; | |
389 | |
390 /* non-nil if any extent has changed since the last time redisplay completed */ | |
391 int extents_changed; | |
392 int extents_changed_set; | |
393 | |
394 /* non-nil if any face has changed since the last time redisplay completed */ | |
395 int faces_changed; | |
396 | |
397 /* Nonzero means some frames have been marked as garbaged */ | |
398 int frame_changed; | |
399 | |
400 /* non-zero if any of the builtin display glyphs (continuation, | |
401 hscroll, control-arrow, etc) is in need of updating | |
402 somewhere. */ | |
403 int glyphs_changed; | |
404 int glyphs_changed_set; | |
405 | |
442 | 406 /* non-zero if any subwindow has been deleted. */ |
428 | 407 int subwindows_changed; |
408 int subwindows_changed_set; | |
409 | |
410 /* non-zero if any displayed subwindow is in need of updating | |
411 somewhere. */ | |
412 int subwindows_state_changed; | |
413 int subwindows_state_changed_set; | |
414 | |
415 /* This variable is 1 if the icon has to be updated. | |
416 It is set to 1 when `frame-icon-glyph' changes. */ | |
417 int icon_changed; | |
418 int icon_changed_set; | |
419 | |
420 /* This variable is 1 if the menubar widget has to be updated. | |
421 It is set to 1 by set-menubar-dirty-flag and cleared when the widget | |
422 has been updated. */ | |
423 int menubar_changed; | |
424 int menubar_changed_set; | |
425 | |
426 /* true iff we should redraw the modelines on the next redisplay */ | |
427 int modeline_changed; | |
428 int modeline_changed_set; | |
429 | |
430 /* non-nil if point has changed in some buffer since the last time | |
431 redisplay completed */ | |
432 int point_changed; | |
433 int point_changed_set; | |
434 | |
435 /* non-nil if some frame has changed its size */ | |
436 int size_changed; | |
437 | |
438 /* non-nil if some device has signaled that it wants to change size */ | |
439 int asynch_device_change_pending; | |
440 | |
441 /* non-nil if any toolbar has changed */ | |
442 int toolbar_changed; | |
443 int toolbar_changed_set; | |
444 | |
905 | 445 /* Nonzero if some frame has changed the layout of internal elements |
446 (gutters or toolbars). */ | |
447 int frame_layout_changed; | |
448 | |
428 | 449 /* non-nil if any gutter has changed */ |
450 int gutter_changed; | |
451 int gutter_changed_set; | |
452 | |
453 /* non-nil if any window has changed since the last time redisplay completed */ | |
454 int windows_changed; | |
455 | |
456 /* non-nil if any frame's window structure has changed since the last | |
457 time redisplay completed */ | |
458 int windows_structure_changed; | |
459 | |
460 /* If non-nil, use vertical bar cursor. */ | |
461 Lisp_Object Vbar_cursor; | |
462 Lisp_Object Qbar_cursor; | |
463 | |
442 | 464 Lisp_Object Vvisible_bell; /* If true and the terminal will support it |
465 then the frame will flash instead of | |
466 beeping when an error occurs */ | |
428 | 467 |
468 /* Nonzero means no need to redraw the entire frame on resuming | |
469 a suspended Emacs. This is useful on terminals with multiple pages, | |
470 where one page is used for Emacs and another for all else. */ | |
471 int no_redraw_on_reenter; | |
472 | |
3360 | 473 Lisp_Object Vwindow_system; /* #### this variable is deprecated |
474 nil or a symbol naming the window system | |
428 | 475 under which emacs is running |
3360 | 476 (`x', `gtk', `mswindows', and `tty' are |
477 supported -- yes, TTYs are window systems | |
478 for this purpose. */ | |
4477
e34711681f30
Don't determine whether to call general device-type code at startup,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4418
diff
changeset
|
479 Lisp_Object Vinitial_device_type; |
428 | 480 |
481 Lisp_Object Vglobal_mode_string; | |
482 | |
483 /* The number of lines scroll a window by when point leaves the window; if | |
484 it is <=0 then point is centered in the window */ | |
458 | 485 Fixnum scroll_step; |
428 | 486 |
487 /* Scroll up to this many lines, to bring point back on screen. */ | |
458 | 488 Fixnum scroll_conservatively; |
428 | 489 |
490 /* Marker for where to display an arrow on top of the buffer text. */ | |
491 Lisp_Object Voverlay_arrow_position; | |
492 /* String to display for the arrow. */ | |
493 Lisp_Object Voverlay_arrow_string; | |
494 | |
442 | 495 Lisp_Object Qbuffer_list_changed_hook, Vbuffer_list_changed_hook; |
496 | |
458 | 497 static Fixnum last_display_warning_tick; |
498 static Fixnum display_warning_tick; | |
428 | 499 Lisp_Object Qdisplay_warning_buffer; |
500 int inhibit_warning_display; | |
501 | |
502 Lisp_Object Vleft_margin_width, Vright_margin_width; | |
503 Lisp_Object Vminimum_line_ascent, Vminimum_line_descent; | |
504 Lisp_Object Vuse_left_overflow, Vuse_right_overflow; | |
505 Lisp_Object Vtext_cursor_visible_p; | |
506 | |
1292 | 507 static Lisp_Object QSin_redisplay; |
508 | |
1318 | 509 static Lisp_Object Vpost_redisplay_actions; |
510 | |
428 | 511 int column_number_start_at_one; |
512 | |
442 | 513 Lisp_Object Qtop_bottom; |
514 | |
444 | 515 #define WINDOW_SCROLLED(w) ((w)->hscroll > 0 || (w)->left_xoffset) |
428 | 516 |
1204 | 517 static const struct memory_description rune_dglyph_description_1[] = { |
518 { XD_LISP_OBJECT, offsetof (struct rune_dglyph, glyph) }, | |
519 { XD_LISP_OBJECT, offsetof (struct rune_dglyph, extent) }, | |
520 { XD_END } | |
521 }; | |
522 | |
523 static const struct sized_memory_description rune_dglyph_description = { | |
524 sizeof (struct rune_dglyph), rune_dglyph_description_1 | |
525 }; | |
526 | |
527 static const struct memory_description rune_object_description_1[] = { | |
2551 | 528 { XD_BLOCK_ARRAY, RUNE_DGLYPH, 1, { &rune_dglyph_description } }, |
1204 | 529 { XD_END } |
530 }; | |
531 | |
532 static const struct sized_memory_description rune_object_description = { | |
533 0, rune_object_description_1 | |
534 }; | |
535 | |
536 static const struct memory_description rune_description_1[] = { | |
537 { XD_INT, offsetof (rune, type) }, | |
538 { XD_UNION, offsetof (rune, object), | |
2551 | 539 XD_INDIRECT (0, 0), { &rune_object_description } }, |
1204 | 540 { XD_END } |
541 }; | |
542 | |
543 static const struct sized_memory_description rune_description = { | |
544 sizeof (rune), | |
545 rune_description_1 | |
546 }; | |
547 | |
548 static const struct memory_description rune_dynarr_description_1[] = { | |
549 XD_DYNARR_DESC (rune_dynarr, &rune_description), | |
550 { XD_END } | |
551 }; | |
552 | |
553 static const struct sized_memory_description rune_dynarr_description = { | |
554 sizeof (rune_dynarr), | |
555 rune_dynarr_description_1 | |
556 }; | |
557 | |
558 static const struct memory_description display_block_description_1[] = { | |
2367 | 559 { XD_BLOCK_PTR, offsetof (display_block, runes), |
2551 | 560 1, { &rune_dynarr_description } }, |
1204 | 561 { XD_END } |
562 }; | |
563 | |
564 static const struct sized_memory_description display_block_description = { | |
565 sizeof (display_block), | |
566 display_block_description_1 | |
567 }; | |
568 | |
569 static const struct memory_description display_block_dynarr_description_1[] = { | |
570 XD_DYNARR_DESC (display_block_dynarr, &display_block_description), | |
571 { XD_END } | |
572 }; | |
573 | |
574 static const struct sized_memory_description display_block_dynarr_description = { | |
575 sizeof (display_block_dynarr), | |
576 display_block_dynarr_description_1 | |
577 }; | |
578 | |
579 static const struct memory_description glyph_block_description_1[] = { | |
580 { XD_LISP_OBJECT, offsetof (glyph_block, glyph) }, | |
581 { XD_LISP_OBJECT, offsetof (glyph_block, extent) }, | |
582 { XD_END } | |
583 }; | |
584 | |
585 static const struct sized_memory_description glyph_block_description = { | |
586 sizeof (glyph_block), | |
587 glyph_block_description_1 | |
588 }; | |
589 | |
590 static const struct memory_description glyph_block_dynarr_description_1[] = { | |
591 XD_DYNARR_DESC (glyph_block_dynarr, &glyph_block_description), | |
592 { XD_END } | |
593 }; | |
594 | |
595 static const struct sized_memory_description glyph_block_dynarr_description = { | |
596 sizeof (glyph_block_dynarr), | |
597 glyph_block_dynarr_description_1 | |
598 }; | |
599 | |
600 static const struct memory_description display_line_description_1[] = { | |
2367 | 601 { XD_BLOCK_PTR, offsetof (display_line, display_blocks), |
2551 | 602 1, { &display_block_dynarr_description } }, |
2367 | 603 { XD_BLOCK_PTR, offsetof (display_line, left_glyphs), |
2551 | 604 1, { &glyph_block_dynarr_description } }, |
2367 | 605 { XD_BLOCK_PTR, offsetof (display_line, right_glyphs), |
2551 | 606 1, { &glyph_block_dynarr_description } }, |
1204 | 607 { XD_END } |
608 }; | |
609 | |
610 static const struct sized_memory_description display_line_description = { | |
611 sizeof (display_line), | |
612 display_line_description_1 | |
613 }; | |
614 | |
615 static const struct memory_description display_line_dynarr_description_1[] = { | |
616 XD_DYNARR_DESC (display_line_dynarr, &display_line_description), | |
617 { XD_END } | |
618 }; | |
619 | |
620 const struct sized_memory_description display_line_dynarr_description = { | |
621 sizeof (display_line_dynarr), | |
622 display_line_dynarr_description_1 | |
623 }; | |
624 | |
428 | 625 |
626 /***************************************************************************/ | |
627 /* */ | |
628 /* low-level interfaces onto device routines */ | |
629 /* */ | |
630 /***************************************************************************/ | |
631 | |
632 static int | |
4815
6540302eedf5
Fix query_string_geometry lookup domain
Didier Verna <didier@lrde.epita.fr>
parents:
4528
diff
changeset
|
633 redisplay_window_text_width_ichar_string (struct window *w, int findex, |
6540302eedf5
Fix query_string_geometry lookup domain
Didier Verna <didier@lrde.epita.fr>
parents:
4528
diff
changeset
|
634 Ichar *str, Charcount len) |
428 | 635 { |
636 unsigned char charsets[NUM_LEADING_BYTES]; | |
637 Lisp_Object window; | |
638 | |
867 | 639 find_charsets_in_ichar_string (charsets, str, len); |
793 | 640 window = wrap_window (w); |
428 | 641 ensure_face_cachel_complete (WINDOW_FACE_CACHEL (w, findex), window, |
642 charsets); | |
4928
ea701c23ed84
change text_width method to take a window, in preparation for unicode-internal changes
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
643 return DEVMETH (WINDOW_XDEVICE (w), |
ea701c23ed84
change text_width method to take a window, in preparation for unicode-internal changes
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
644 text_width, (w, WINDOW_FACE_CACHEL (w, findex), str, |
ea701c23ed84
change text_width method to take a window, in preparation for unicode-internal changes
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
645 len)); |
428 | 646 } |
647 | |
867 | 648 static Ichar_dynarr *rtw_ichar_dynarr; |
428 | 649 |
4815
6540302eedf5
Fix query_string_geometry lookup domain
Didier Verna <didier@lrde.epita.fr>
parents:
4528
diff
changeset
|
650 static int |
6540302eedf5
Fix query_string_geometry lookup domain
Didier Verna <didier@lrde.epita.fr>
parents:
4528
diff
changeset
|
651 redisplay_window_text_width_string (struct window *w, int findex, |
6540302eedf5
Fix query_string_geometry lookup domain
Didier Verna <didier@lrde.epita.fr>
parents:
4528
diff
changeset
|
652 Ibyte *nonreloc, Lisp_Object reloc, |
6540302eedf5
Fix query_string_geometry lookup domain
Didier Verna <didier@lrde.epita.fr>
parents:
4528
diff
changeset
|
653 Bytecount offset, Bytecount len) |
428 | 654 { |
867 | 655 if (!rtw_ichar_dynarr) |
656 rtw_ichar_dynarr = Dynarr_new (Ichar); | |
657 Dynarr_reset (rtw_ichar_dynarr); | |
428 | 658 |
659 fixup_internal_substring (nonreloc, reloc, offset, &len); | |
660 if (STRINGP (reloc)) | |
661 nonreloc = XSTRING_DATA (reloc); | |
867 | 662 convert_ibyte_string_into_ichar_dynarr (nonreloc, len, rtw_ichar_dynarr); |
4815
6540302eedf5
Fix query_string_geometry lookup domain
Didier Verna <didier@lrde.epita.fr>
parents:
4528
diff
changeset
|
663 return redisplay_window_text_width_ichar_string |
4967 | 664 (w, findex, Dynarr_begin (rtw_ichar_dynarr), |
867 | 665 Dynarr_length (rtw_ichar_dynarr)); |
428 | 666 } |
667 | |
668 int | |
4815
6540302eedf5
Fix query_string_geometry lookup domain
Didier Verna <didier@lrde.epita.fr>
parents:
4528
diff
changeset
|
669 redisplay_text_width_string (Lisp_Object domain, Lisp_Object face, |
6540302eedf5
Fix query_string_geometry lookup domain
Didier Verna <didier@lrde.epita.fr>
parents:
4528
diff
changeset
|
670 Ibyte *nonreloc, Lisp_Object reloc, |
6540302eedf5
Fix query_string_geometry lookup domain
Didier Verna <didier@lrde.epita.fr>
parents:
4528
diff
changeset
|
671 Bytecount offset, Bytecount len) |
6540302eedf5
Fix query_string_geometry lookup domain
Didier Verna <didier@lrde.epita.fr>
parents:
4528
diff
changeset
|
672 { |
6540302eedf5
Fix query_string_geometry lookup domain
Didier Verna <didier@lrde.epita.fr>
parents:
4528
diff
changeset
|
673 Lisp_Object window = DOMAIN_WINDOW (domain); |
6540302eedf5
Fix query_string_geometry lookup domain
Didier Verna <didier@lrde.epita.fr>
parents:
4528
diff
changeset
|
674 Lisp_Object frame = DOMAIN_FRAME (domain); |
428 | 675 unsigned char charsets[NUM_LEADING_BYTES]; |
676 struct face_cachel cachel; | |
677 | |
867 | 678 if (!rtw_ichar_dynarr) |
679 rtw_ichar_dynarr = Dynarr_new (Ichar); | |
680 Dynarr_reset (rtw_ichar_dynarr); | |
428 | 681 |
682 fixup_internal_substring (nonreloc, reloc, offset, &len); | |
683 if (STRINGP (reloc)) | |
684 nonreloc = XSTRING_DATA (reloc); | |
867 | 685 convert_ibyte_string_into_ichar_dynarr (nonreloc, len, rtw_ichar_dynarr); |
686 find_charsets_in_ibyte_string (charsets, nonreloc, len); | |
428 | 687 reset_face_cachel (&cachel); |
688 cachel.face = face; | |
4815
6540302eedf5
Fix query_string_geometry lookup domain
Didier Verna <didier@lrde.epita.fr>
parents:
4528
diff
changeset
|
689 ensure_face_cachel_complete (&cachel, |
6540302eedf5
Fix query_string_geometry lookup domain
Didier Verna <didier@lrde.epita.fr>
parents:
4528
diff
changeset
|
690 NILP (window) ? frame : window, |
6540302eedf5
Fix query_string_geometry lookup domain
Didier Verna <didier@lrde.epita.fr>
parents:
4528
diff
changeset
|
691 charsets); |
6540302eedf5
Fix query_string_geometry lookup domain
Didier Verna <didier@lrde.epita.fr>
parents:
4528
diff
changeset
|
692 return DEVMETH (XDEVICE (FRAME_DEVICE (XFRAME (frame))), |
4928
ea701c23ed84
change text_width method to take a window, in preparation for unicode-internal changes
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
693 /* #### Not clear if we're always passed a window, but |
ea701c23ed84
change text_width method to take a window, in preparation for unicode-internal changes
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
694 I think so. If not, we will get an abort here, |
ea701c23ed84
change text_width method to take a window, in preparation for unicode-internal changes
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
695 and then we need to either fix the callers to pass in |
ea701c23ed84
change text_width method to take a window, in preparation for unicode-internal changes
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
696 a window, or change *text_width() to take a domain |
ea701c23ed84
change text_width method to take a window, in preparation for unicode-internal changes
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
697 argument. */ |
ea701c23ed84
change text_width method to take a window, in preparation for unicode-internal changes
Ben Wing <ben@xemacs.org>
parents:
4844
diff
changeset
|
698 text_width, (XWINDOW (window), |
4815
6540302eedf5
Fix query_string_geometry lookup domain
Didier Verna <didier@lrde.epita.fr>
parents:
4528
diff
changeset
|
699 &cachel, |
4967 | 700 Dynarr_begin (rtw_ichar_dynarr), |
867 | 701 Dynarr_length (rtw_ichar_dynarr))); |
428 | 702 } |
703 | |
704 /* Return the display block from DL of the given TYPE. A display line | |
705 can have only one display block of each possible type. If DL does | |
706 not have a block of type TYPE, one will be created and added to DL. */ | |
707 | |
708 struct display_block * | |
709 get_display_block_from_line (struct display_line *dl, enum display_type type) | |
710 { | |
711 int elt; | |
712 struct display_block db; | |
713 | |
714 /* Check if this display line already has a block of the desired type and | |
715 if so, return it. */ | |
716 if (dl->display_blocks) | |
717 { | |
718 for (elt = 0; elt < Dynarr_length (dl->display_blocks); elt++) | |
719 { | |
720 if (Dynarr_at (dl->display_blocks, elt).type == type) | |
721 return Dynarr_atp (dl->display_blocks, elt); | |
722 } | |
723 | |
724 /* There isn't an active block of the desired type, but there | |
4187 | 725 might still be allocated blocks we need to reuse. */ |
428 | 726 if (elt < Dynarr_largest (dl->display_blocks)) |
727 { | |
728 struct display_block *dbp = Dynarr_atp (dl->display_blocks, elt); | |
729 | |
3025 | 730 /* "add" the block to the list */ |
5038 | 731 Dynarr_incrementr (dl->display_blocks); |
428 | 732 |
733 /* initialize and return */ | |
734 dbp->type = type; | |
735 return dbp; | |
736 } | |
737 } | |
738 else | |
739 { | |
740 /* This line doesn't have any display blocks, so initialize the display | |
4187 | 741 bock array. */ |
428 | 742 dl->display_blocks = Dynarr_new (display_block); |
743 } | |
744 | |
745 /* The line doesn't have a block of the desired type so go ahead and create | |
746 one and add it to the line. */ | |
747 xzero (db); | |
748 db.type = type; | |
749 db.runes = Dynarr_new (rune); | |
750 Dynarr_add (dl->display_blocks, db); | |
751 | |
752 /* Return the newly added display block. */ | |
753 elt = Dynarr_length (dl->display_blocks) - 1; | |
754 | |
755 return Dynarr_atp (dl->display_blocks, elt); | |
756 } | |
757 | |
758 static int | |
759 tab_char_width (struct window *w) | |
760 { | |
761 struct buffer *b = XBUFFER (w->buffer); | |
762 int char_tab_width = XINT (b->tab_width); | |
763 | |
764 if (char_tab_width <= 0 || char_tab_width > 1000) char_tab_width = 8; | |
765 | |
766 return char_tab_width; | |
767 } | |
768 | |
769 static int | |
770 space_width (struct window *w) | |
771 { | |
3659 | 772 /* While tabs are traditionally composed of spaces, for variable-width |
428 | 773 fonts the space character tends to give too narrow a value. So |
774 we use 'n' instead. Except that we don't. We use the default | |
775 character width for the default face. If this is actually | |
776 defined by the font then it is probably the best thing to | |
777 actually use. If it isn't, we have assumed it is 'n' and have | |
778 already calculated its width. Thus we can avoid a call to | |
779 XTextWidth on X frames by just querying the default width. */ | |
780 return XFONT_INSTANCE | |
781 (WINDOW_FACE_CACHEL_FONT (w, DEFAULT_INDEX, Vcharset_ascii))->width; | |
782 } | |
783 | |
784 static int | |
785 tab_pix_width (struct window *w) | |
786 { | |
787 return space_width (w) * tab_char_width (w); | |
788 } | |
789 | |
790 /* Given a pixel position in a window, return the pixel location of | |
791 the next tabstop. Tabs are calculated from the left window edge in | |
792 terms of spaces displayed in the default face. Formerly the space | |
793 width was determined using the currently active face. That method | |
794 leads to tabstops which do not line up. */ | |
795 | |
796 static int | |
797 next_tab_position (struct window *w, int start_pixpos, int left_pixpos) | |
798 { | |
799 int n_pos = left_pixpos; | |
800 int pix_tab_width = tab_pix_width (w); | |
801 | |
802 /* Adjust n_pos for any hscrolling which has happened. */ | |
803 if (WINDOW_SCROLLED (w)) | |
804 n_pos -= space_width (w) * (w->hscroll - 1) + w->left_xoffset; | |
805 | |
806 while (n_pos <= start_pixpos) | |
807 n_pos += pix_tab_width; | |
808 | |
809 return n_pos; | |
810 } | |
811 | |
812 /* For the given window, calculate the outside and margin boundaries for a | |
813 display line. The whitespace boundaries must be calculated by the text | |
814 layout routines. */ | |
815 | |
816 layout_bounds | |
817 calculate_display_line_boundaries (struct window *w, int modeline) | |
818 { | |
819 layout_bounds bounds; | |
820 | |
821 /* Set the outermost boundaries which are the boundaries of the | |
822 window itself minus the gutters (and minus the scrollbars if this | |
823 is for the modeline). */ | |
824 if (!modeline) | |
825 { | |
826 bounds.left_out = WINDOW_TEXT_LEFT (w); | |
827 bounds.right_out = WINDOW_TEXT_RIGHT (w); | |
828 } | |
829 else | |
830 { | |
831 bounds.left_out = WINDOW_MODELINE_LEFT (w); | |
832 bounds.right_out = WINDOW_MODELINE_RIGHT (w); | |
833 } | |
834 | |
835 /* The inner boundaries mark where the glyph margins are located. */ | |
836 bounds.left_in = bounds.left_out + window_left_margin_width (w); | |
837 bounds.right_in = bounds.right_out - window_right_margin_width (w); | |
838 | |
839 /* We cannot fully calculate the whitespace boundaries as they | |
840 depend on the contents of the line being displayed. */ | |
841 bounds.left_white = bounds.left_in; | |
842 bounds.right_white = bounds.right_in; | |
843 | |
844 return bounds; | |
845 } | |
846 | |
819 | 847 /* This takes a display_block and its containing line and corrects the yoffset |
848 of each glyph in the block to cater for the ascent of the line as a | |
849 whole. Must be called *after* the line-ascent is known! */ | |
850 | |
851 static void | |
852 calculate_yoffset (struct display_line *dl, struct display_block *fixup) | |
853 { | |
854 int i; | |
855 for (i=0; i<Dynarr_length (fixup->runes); i++) | |
856 { | |
857 struct rune *r = Dynarr_atp (fixup->runes,i); | |
858 if (r->type == RUNE_DGLYPH) | |
4187 | 859 { |
860 if (r->object.dglyph.ascent < dl->ascent) | |
861 r->object.dglyph.yoffset = dl->ascent - r->object.dglyph.ascent + | |
819 | 862 r->object.dglyph.descent; |
4187 | 863 } |
819 | 864 } |
865 } | |
866 | |
867 /* Calculate the textual baseline (the ascent and descent values for the | |
868 display_line as a whole). | |
869 | |
870 If the baseline is completely blank, or contains no manually positioned | |
871 glyphs, then the textual baseline is simply the baseline of the default font. | |
872 (The `contains no manually positioned glyphs' part is actually done for | |
867 | 873 us by `add_ichar_rune'.) |
819 | 874 |
875 If the baseline contains pixmaps, and they're all manually positioned, then | |
876 the textual baseline location is constrained that way, and we need do no | |
877 work. | |
878 | |
879 If the baseline contains pixmaps, and at least one is automatically | |
880 positioned, then the textual ascent is the largest ascent on the line, and | |
881 the textual descent is the largest descent (which is how things are set up at | |
882 entry to this function anyway): except that if the max_ascent + max_descent | |
883 is too small for the height of the line (say you've adjusted the baseline of | |
884 a short glyph, and there's a tall one next to it), then take the ascent and | |
885 descent for the line individually from the largest of the explicitly set | |
886 ascent/descent, and the rescaled ascent/descent of the default font, scaled | |
887 such that the largest glyph will fit. | |
888 | |
889 This means that if you have a short glyph (but taller than the default | |
890 font's descent) forced right under the baseline, and a really tall | |
891 automatically positioned glyph, that the descent for the line is just big | |
892 enough for the manually positioned short glyph, and the tall one uses as | |
893 much of that space as the default font would were it as tall as the tall | |
894 glyph; but that the ascent is big enough for the tall glyph to fit. | |
895 | |
896 This behaviour means that under no circumstances will changing the baseline | |
897 of a short glyph cause a tall glyph to move around; nor will it move the | |
898 textual baseline more than necessary. (Changing a tall glyph's baseline | |
899 might move the text's baseline arbitrarily, of course.) */ | |
900 | |
901 static void | |
902 calculate_baseline (pos_data *data) | |
903 { | |
904 /* Blank line: baseline is default font's baseline. */ | |
905 | |
906 if (!data->new_ascent && !data->new_descent) | |
907 { | |
908 /* We've got a blank line so initialize these values from the default | |
4187 | 909 face. */ |
819 | 910 default_face_font_info (data->window, &data->new_ascent, |
911 &data->new_descent, 0, 0, 0); | |
912 } | |
4187 | 913 |
819 | 914 /* No automatically positioned glyphs? Return at once. */ |
915 if (!data->need_baseline_computation) | |
916 return; | |
917 | |
918 /* Is the tallest glyph on the line automatically positioned? | |
919 If it's manually positioned, or it's automatically positioned | |
920 and there's enough room for it anyway, we need do no more work. */ | |
921 if (data->max_pixmap_height > data->new_ascent + data->new_descent) | |
922 { | |
923 int default_font_ascent, default_font_descent, default_font_height; | |
924 int scaled_default_font_ascent, scaled_default_font_descent; | |
4187 | 925 |
819 | 926 default_face_font_info (data->window, &default_font_ascent, |
5047
07dcc7000bbf
put width before height consistently, fix a real bug found in the process
Ben Wing <ben@xemacs.org>
parents:
5043
diff
changeset
|
927 &default_font_descent, 0, &default_font_height, |
07dcc7000bbf
put width before height consistently, fix a real bug found in the process
Ben Wing <ben@xemacs.org>
parents:
5043
diff
changeset
|
928 0); |
819 | 929 |
930 scaled_default_font_ascent = data->max_pixmap_height * | |
931 default_font_ascent / default_font_height; | |
932 | |
933 data->new_ascent = max (data->new_ascent, scaled_default_font_ascent); | |
934 | |
935 /* The ascent may have expanded now. Do we still need to grow the descent, | |
4187 | 936 or are things big enough? |
937 | |
938 The +1 caters for the baseline row itself. */ | |
819 | 939 if (data->max_pixmap_height > data->new_ascent + data->new_descent) |
4187 | 940 { |
941 scaled_default_font_descent = (data->max_pixmap_height * | |
819 | 942 default_font_descent / default_font_height) + 1; |
943 | |
4187 | 944 data->new_descent = max (data->new_descent, scaled_default_font_descent); |
945 } | |
819 | 946 } |
947 } | |
948 | |
428 | 949 /* Given a display line and a starting position, ensure that the |
950 contents of the display line accurately represent the visual | |
951 representation of the buffer contents starting from the given | |
952 position when displayed in the given window. The display line ends | |
953 when the contents of the line reach the right boundary of the given | |
954 window. */ | |
955 | |
665 | 956 static Charbpos |
428 | 957 generate_display_line (struct window *w, struct display_line *dl, int bounds, |
665 | 958 Charbpos start_pos, prop_block_dynarr **prop, |
428 | 959 int type) |
960 { | |
826 | 961 Charbpos ret_charpos; |
428 | 962 int overlay_width; |
963 struct buffer *b = XBUFFER (WINDOW_BUFFER (w)); | |
964 | |
965 /* If our caller hasn't already set the boundaries, then do so now. */ | |
966 if (!bounds) | |
967 dl->bounds = calculate_display_line_boundaries (w, 0); | |
968 | |
969 /* Reset what this line is using. */ | |
970 if (dl->display_blocks) | |
971 Dynarr_reset (dl->display_blocks); | |
972 if (dl->left_glyphs) | |
973 { | |
974 Dynarr_free (dl->left_glyphs); | |
975 dl->left_glyphs = 0; | |
976 } | |
977 if (dl->right_glyphs) | |
978 { | |
979 Dynarr_free (dl->right_glyphs); | |
980 dl->right_glyphs = 0; | |
981 } | |
982 | |
983 /* We aren't generating a modeline at the moment. */ | |
984 dl->modeline = 0; | |
985 | |
986 /* Create a display block for the text region of the line. */ | |
987 { | |
988 /* #### urk urk urk!!! Chuck fix this shit! */ | |
665 | 989 Bytebpos hacked_up_bytebpos = |
990 create_text_block (w, dl, charbpos_to_bytebpos (b, start_pos), | |
428 | 991 prop, type); |
826 | 992 if (hacked_up_bytebpos > BYTE_BUF_ZV (b)) |
993 ret_charpos = BUF_ZV (b) + 1; | |
428 | 994 else |
826 | 995 ret_charpos = bytebpos_to_charbpos (b, hacked_up_bytebpos); |
428 | 996 } |
826 | 997 dl->charpos = start_pos; |
998 if (dl->end_charpos < dl->charpos) | |
999 dl->end_charpos = dl->charpos; | |
428 | 1000 |
1001 if (MARKERP (Voverlay_arrow_position) | |
1002 && EQ (w->buffer, Fmarker_buffer (Voverlay_arrow_position)) | |
1003 && start_pos == marker_position (Voverlay_arrow_position) | |
1004 && (STRINGP (Voverlay_arrow_string) | |
1005 || GLYPHP (Voverlay_arrow_string))) | |
1006 { | |
1007 overlay_width = create_overlay_glyph_block (w, dl); | |
1008 } | |
1009 else | |
1010 overlay_width = 0; | |
1011 | |
1012 /* If there are left glyphs associated with any character in the | |
1013 text block, then create a display block to handle them. */ | |
1014 if (dl->left_glyphs != NULL && Dynarr_length (dl->left_glyphs)) | |
1015 create_left_glyph_block (w, dl, overlay_width); | |
1016 | |
1017 /* If there are right glyphs associated with any character in the | |
1018 text block, then create a display block to handle them. */ | |
1019 if (dl->right_glyphs != NULL && Dynarr_length (dl->right_glyphs)) | |
1020 create_right_glyph_block (w, dl); | |
1021 | |
1022 /* In the future additional types of display blocks may be generated | |
1023 here. */ | |
1024 | |
826 | 1025 w->last_redisplay_pos = ret_charpos; |
1026 | |
1027 return ret_charpos; | |
428 | 1028 } |
1029 | |
1030 /* Adds an hscroll glyph to a display block. If this is called, then | |
1031 the block had better be empty. | |
1032 | |
1033 Yes, there are multiple places where this function is called but | |
1034 that is the way it has to be. Each calling function has to deal | |
826 | 1035 with byte_start_col_enabled a little differently depending on the |
428 | 1036 object being worked with. */ |
1037 | |
1038 static prop_block_dynarr * | |
1039 add_hscroll_rune (pos_data *data) | |
1040 { | |
1041 struct glyph_block gb; | |
1042 prop_block_dynarr *retval; | |
826 | 1043 Bytebpos byte_old_cursor_charpos = data->byte_cursor_charpos; |
647 | 1044 int old_cursor_type = data->cursor_type; |
826 | 1045 Bytebpos byte_old_charpos = data->byte_charpos; |
428 | 1046 |
1047 if (data->cursor_type == CURSOR_ON | |
826 | 1048 && data->byte_cursor_charpos >= data->byte_start_col_enabled |
1049 && data->byte_cursor_charpos <= data->byte_charpos) | |
1050 { | |
1051 data->byte_cursor_charpos = data->byte_start_col_enabled; | |
428 | 1052 } |
1053 else | |
1054 { | |
1055 data->cursor_type = NO_CURSOR; | |
1056 } | |
1057 | |
826 | 1058 data->byte_endpos = data->byte_charpos; |
1059 data->byte_charpos = data->byte_start_col_enabled; | |
428 | 1060 |
1061 gb.extent = Qnil; | |
1062 gb.glyph = Vhscroll_glyph; | |
1063 { | |
1064 int oldpixpos = data->pixpos; | |
442 | 1065 retval = add_glyph_rune (data, &gb, BEGIN_GLYPHS, 0, |
428 | 1066 GLYPH_CACHEL (XWINDOW (data->window), |
1067 HSCROLL_GLYPH_INDEX)); | |
1068 data->hscroll_glyph_width_adjust = | |
1069 data->pixpos - oldpixpos - space_width (XWINDOW (data->window)); | |
1070 } | |
826 | 1071 data->byte_endpos = 0; |
1072 data->byte_cursor_charpos = byte_old_cursor_charpos; | |
428 | 1073 data->cursor_type = old_cursor_type; |
826 | 1074 data->byte_charpos = byte_old_charpos; |
1075 | |
1076 data->byte_start_col_enabled = 0; | |
428 | 1077 return retval; |
1078 } | |
1079 | |
793 | 1080 /* Adds a character rune to a display block. If there is not enough room |
1081 to fit the rune on the display block (as determined by the MAX_PIXPOS) | |
1082 then it adds nothing and returns ADD_FAILED. If | |
1083 NO_CONTRIBUTE_TO_LINE_HEIGHT is non-zero, don't allow the char's height | |
867 | 1084 to affect the total line height. (See add_ibyte_string_runes()). */ |
428 | 1085 |
1086 static prop_block_dynarr * | |
867 | 1087 add_ichar_rune_1 (pos_data *data, int no_contribute_to_line_height) |
428 | 1088 { |
1089 struct rune rb, *crb; | |
1090 int width, local; | |
1091 | |
1092 if (data->start_col) | |
1093 { | |
1094 data->start_col--; | |
1095 | |
1096 if (data->start_col) | |
1097 return NULL; | |
1098 } | |
1099 | |
826 | 1100 if (data->byte_start_col_enabled) |
428 | 1101 { |
1102 return add_hscroll_rune (data); | |
1103 } | |
1104 | |
1105 if (data->ch == '\n') | |
1106 { | |
1107 data->font_is_bogus = 0; | |
1108 /* Cheesy end-of-line pseudo-character. */ | |
1109 width = data->blank_width; | |
1110 } | |
1111 else | |
1112 { | |
867 | 1113 Lisp_Object charset = ichar_charset (data->ch); |
428 | 1114 if (!EQ (charset, data->last_charset) || |
1115 data->findex != data->last_findex) | |
1116 { | |
1117 /* OK, we need to do things the hard way. */ | |
1118 struct window *w = XWINDOW (data->window); | |
1119 struct face_cachel *cachel = WINDOW_FACE_CACHEL (w, data->findex); | |
1120 Lisp_Object font_instance = | |
1121 ensure_face_cachel_contains_charset (cachel, data->window, | |
1122 charset); | |
440 | 1123 Lisp_Font_Instance *fi; |
428 | 1124 |
1125 if (EQ (font_instance, Vthe_null_font_instance)) | |
1126 { | |
1127 font_instance = FACE_CACHEL_FONT (cachel, Vcharset_ascii); | |
1128 data->font_is_bogus = 1; | |
1129 } | |
1130 else | |
1131 data->font_is_bogus = 0; | |
1132 | |
1133 fi = XFONT_INSTANCE (font_instance); | |
771 | 1134 if (!fi->proportional_p || data->font_is_bogus) |
1135 { | |
867 | 1136 Ichar ch = data->font_is_bogus ? '~' : data->ch; |
771 | 1137 |
1138 data->last_char_width = | |
4815
6540302eedf5
Fix query_string_geometry lookup domain
Didier Verna <didier@lrde.epita.fr>
parents:
4528
diff
changeset
|
1139 redisplay_window_text_width_ichar_string |
6540302eedf5
Fix query_string_geometry lookup domain
Didier Verna <didier@lrde.epita.fr>
parents:
4528
diff
changeset
|
1140 (XWINDOW (data->window), data->findex, &ch, 1); |
771 | 1141 } |
428 | 1142 else |
1143 data->last_char_width = -1; | |
819 | 1144 |
793 | 1145 if (!no_contribute_to_line_height) |
1146 { | |
1147 data->new_ascent = max (data->new_ascent, (int) fi->ascent); | |
1148 data->new_descent = max (data->new_descent, (int) fi->descent); | |
1149 } | |
819 | 1150 |
428 | 1151 data->last_charset = charset; |
1152 data->last_findex = data->findex; | |
1153 } | |
1154 | |
1155 width = data->last_char_width; | |
771 | 1156 if (width < 0) /* proportional fonts */ |
4815
6540302eedf5
Fix query_string_geometry lookup domain
Didier Verna <didier@lrde.epita.fr>
parents:
4528
diff
changeset
|
1157 width = redisplay_window_text_width_ichar_string |
6540302eedf5
Fix query_string_geometry lookup domain
Didier Verna <didier@lrde.epita.fr>
parents:
4528
diff
changeset
|
1158 (XWINDOW (data->window), data->findex, &data->ch, 1); |
428 | 1159 } |
1160 | |
1161 if (data->max_pixpos != -1 && (data->pixpos + width > data->max_pixpos)) | |
1162 { | |
1163 return ADD_FAILED; | |
1164 } | |
1165 | |
1166 if (Dynarr_length (data->db->runes) < Dynarr_largest (data->db->runes)) | |
1167 { | |
4844
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4815
diff
changeset
|
1168 crb = Dynarr_past_lastp (data->db->runes); |
428 | 1169 local = 0; |
1170 } | |
1171 else | |
1172 { | |
1173 crb = &rb; | |
1174 local = 1; | |
1175 } | |
1176 | |
1177 crb->findex = data->findex; | |
1178 crb->xpos = data->pixpos; | |
1179 crb->width = width; | |
826 | 1180 if (data->byte_charpos) |
428 | 1181 { |
1182 if (NILP (data->string)) | |
826 | 1183 crb->charpos = |
793 | 1184 bytebpos_to_charbpos (XBUFFER (WINDOW_BUFFER |
1185 (XWINDOW (data->window))), | |
826 | 1186 data->byte_charpos); |
428 | 1187 else |
826 | 1188 crb->charpos = |
1189 string_index_byte_to_char (data->string, data->byte_charpos); | |
428 | 1190 } |
1191 else if (data->is_modeline) | |
826 | 1192 crb->charpos = data->modeline_charpos; |
428 | 1193 else |
442 | 1194 /* Text but not in buffer */ |
826 | 1195 crb->charpos = 0; |
428 | 1196 crb->type = RUNE_CHAR; |
1197 crb->object.chr.ch = data->font_is_bogus ? '~' : data->ch; | |
1198 crb->endpos = 0; | |
1199 | |
1200 if (data->cursor_type == CURSOR_ON) | |
1201 { | |
826 | 1202 if (data->byte_charpos == data->byte_cursor_charpos) |
428 | 1203 { |
1204 crb->cursor_type = CURSOR_ON; | |
1205 data->cursor_x = Dynarr_length (data->db->runes); | |
1206 } | |
1207 else | |
1208 crb->cursor_type = CURSOR_OFF; | |
1209 } | |
1210 else if (data->cursor_type == NEXT_CURSOR) | |
1211 { | |
1212 crb->cursor_type = CURSOR_ON; | |
1213 data->cursor_x = Dynarr_length (data->db->runes); | |
1214 data->cursor_type = NO_CURSOR; | |
1215 } | |
1216 else if (data->cursor_type == IGNORE_CURSOR) | |
1217 crb->cursor_type = IGNORE_CURSOR; | |
1218 else | |
1219 crb->cursor_type = CURSOR_OFF; | |
1220 | |
1221 if (local) | |
1222 Dynarr_add (data->db->runes, *crb); | |
1223 else | |
5038 | 1224 Dynarr_incrementr (data->db->runes); |
428 | 1225 |
1226 data->pixpos += width; | |
1227 | |
1228 return NULL; | |
1229 } | |
1230 | |
793 | 1231 static prop_block_dynarr * |
867 | 1232 add_ichar_rune (pos_data *data) |
1233 { | |
1234 return add_ichar_rune_1 (data, 0); | |
1235 } | |
1236 | |
1237 /* Given a string C_STRING of length C_LENGTH, call add_ichar_rune for | |
793 | 1238 each character in the string. Propagate any left-over data unless |
1239 NO_PROP is non-zero. If NO_CONTRIBUTE_TO_LINE_HEIGHT is non-zero, don't | |
1240 allow this character to increase the total height of the line. (This is | |
1241 used when the character is part of a text glyph. In that case, the | |
1242 glyph code itself adjusts the line height as necessary, depending on | |
1243 whether glyph-contrib-p is true.) */ | |
428 | 1244 |
1245 static prop_block_dynarr * | |
867 | 1246 add_ibyte_string_runes (pos_data *data, Ibyte *c_string, |
793 | 1247 Bytecount c_length, int no_prop, |
1248 int no_contribute_to_line_height) | |
428 | 1249 { |
867 | 1250 Ibyte *pos, *end = c_string + c_length; |
428 | 1251 prop_block_dynarr *prop; |
1252 | |
1253 /* #### This function is too simplistic. It needs to do the same | |
1254 sort of character interpretation (display-table lookup, | |
1255 ctl-arrow checking), etc. that create_text_block() does. | |
1256 The functionality to do this in that routine needs to be | |
1257 modularized. */ | |
1258 | |
1259 for (pos = c_string; pos < end;) | |
1260 { | |
867 | 1261 Ibyte *old_pos = pos; |
1262 | |
1263 data->ch = itext_ichar (pos); | |
1264 | |
1265 prop = add_ichar_rune_1 (data, no_contribute_to_line_height); | |
428 | 1266 |
1267 if (prop) | |
1268 { | |
1269 if (no_prop) | |
1270 return ADD_FAILED; | |
1271 else | |
1272 { | |
1273 struct prop_block pb; | |
1274 Bytecount len = end - pos; | |
1275 prop = Dynarr_new (prop_block); | |
1276 | |
1277 pb.type = PROP_STRING; | |
867 | 1278 pb.data.p_string.str = xnew_array (Ibyte, len); |
4970 | 1279 qxestrncpy (pb.data.p_string.str, pos, len); |
428 | 1280 pb.data.p_string.len = len; |
1281 | |
1282 Dynarr_add (prop, pb); | |
1283 return prop; | |
1284 } | |
1285 } | |
867 | 1286 INC_IBYTEPTR (pos); |
428 | 1287 assert (pos <= end); |
464 | 1288 /* #### Duplicate code from add_string_to_fstring_db_runes |
1289 should we do more?*/ | |
1290 data->bytepos += pos - old_pos; | |
428 | 1291 } |
1292 | |
1293 return NULL; | |
1294 } | |
1295 | |
1296 /* Add a single rune of the specified width. The area covered by this | |
1297 rune will be displayed in the foreground color of the associated | |
1298 face. */ | |
1299 | |
1300 static prop_block_dynarr * | |
1301 add_blank_rune (pos_data *data, struct window *w, int char_tab_width) | |
1302 { | |
1303 struct rune rb; | |
1304 | |
1305 /* If data->start_col is not 0 then this call to add_blank_rune must have | |
1306 been to add it as a tab. */ | |
1307 if (data->start_col) | |
1308 { | |
1309 /* assert (w != NULL) */ | |
1310 prop_block_dynarr *retval; | |
1311 | |
1312 /* If we have still not fully scrolled horizontally, subtract | |
4187 | 1313 the width of this tab and return. */ |
428 | 1314 if (char_tab_width < data->start_col) |
1315 { | |
1316 data->start_col -= char_tab_width; | |
1317 return NULL; | |
1318 } | |
1319 else if (char_tab_width == data->start_col) | |
1320 data->blank_width = 0; | |
1321 else | |
1322 { | |
1323 int spcwid = space_width (w); | |
1324 | |
1325 if (spcwid >= data->blank_width) | |
1326 data->blank_width = 0; | |
1327 else | |
1328 data->blank_width -= spcwid; | |
1329 } | |
1330 | |
1331 data->start_col = 0; | |
1332 retval = add_hscroll_rune (data); | |
1333 | |
1334 /* Could be caused by the handling of the hscroll rune. */ | |
1335 if (retval != NULL || !data->blank_width) | |
1336 return retval; | |
1337 } | |
1338 | |
1339 /* Blank runes are always calculated to fit. */ | |
1340 assert (data->pixpos + data->blank_width <= data->max_pixpos); | |
1341 | |
1342 rb.findex = data->findex; | |
1343 rb.xpos = data->pixpos; | |
1344 rb.width = data->blank_width; | |
826 | 1345 if (data->byte_charpos) |
1346 rb.charpos = | |
665 | 1347 bytebpos_to_charbpos (XBUFFER (WINDOW_BUFFER (XWINDOW (data->window))), |
826 | 1348 data->byte_charpos); |
428 | 1349 else |
1350 /* #### and this is really correct too? */ | |
826 | 1351 rb.charpos = 0; |
428 | 1352 rb.endpos = 0; |
1353 rb.type = RUNE_BLANK; | |
1354 | |
1355 if (data->cursor_type == CURSOR_ON) | |
1356 { | |
826 | 1357 if (data->byte_charpos == data->byte_cursor_charpos) |
428 | 1358 { |
1359 rb.cursor_type = CURSOR_ON; | |
1360 data->cursor_x = Dynarr_length (data->db->runes); | |
1361 } | |
1362 else | |
1363 rb.cursor_type = CURSOR_OFF; | |
1364 } | |
1365 else if (data->cursor_type == NEXT_CURSOR) | |
1366 { | |
1367 rb.cursor_type = CURSOR_ON; | |
1368 data->cursor_x = Dynarr_length (data->db->runes); | |
1369 data->cursor_type = NO_CURSOR; | |
1370 } | |
1371 else | |
1372 rb.cursor_type = CURSOR_OFF; | |
1373 | |
1374 Dynarr_add (data->db->runes, rb); | |
1375 data->pixpos += data->blank_width; | |
1376 | |
1377 return NULL; | |
1378 } | |
1379 | |
1380 /* Add runes representing a character in octal. */ | |
1381 | |
1382 #define ADD_NEXT_OCTAL_RUNE_CHAR do \ | |
1383 { \ | |
867 | 1384 if (add_failed || (add_failed = add_ichar_rune (data))) \ |
428 | 1385 { \ |
1386 struct prop_block pb; \ | |
1387 if (!prop) \ | |
1388 prop = Dynarr_new (prop_block); \ | |
1389 \ | |
1390 pb.type = PROP_CHAR; \ | |
1391 pb.data.p_char.ch = data->ch; \ | |
1392 pb.data.p_char.cursor_type = data->cursor_type; \ | |
1393 Dynarr_add (prop, pb); \ | |
1394 } \ | |
1395 } while (0) | |
1396 | |
1397 static prop_block_dynarr * | |
1398 add_octal_runes (pos_data *data) | |
1399 { | |
819 | 1400 prop_block_dynarr *add_failed, *prop = 0; |
867 | 1401 Ichar orig_char = data->ch; |
647 | 1402 int orig_cursor_type = data->cursor_type; |
428 | 1403 |
1404 /* Initialize */ | |
1405 add_failed = NULL; | |
1406 | |
1407 if (data->start_col) | |
1408 data->start_col--; | |
1409 | |
1410 if (!data->start_col) | |
1411 { | |
826 | 1412 if (data->byte_start_col_enabled) |
428 | 1413 { |
1414 add_failed = add_hscroll_rune (data); | |
1415 } | |
1416 else | |
1417 { | |
1418 struct glyph_block gb; | |
1419 struct window *w = XWINDOW (data->window); | |
1420 | |
1421 gb.extent = Qnil; | |
1422 gb.glyph = Voctal_escape_glyph; | |
1423 add_failed = | |
1424 add_glyph_rune (data, &gb, BEGIN_GLYPHS, 1, | |
1425 GLYPH_CACHEL (w, OCT_ESC_GLYPH_INDEX)); | |
1426 } | |
1427 } | |
1428 | |
1429 /* We only propagate information if the glyph was partially | |
1430 added. */ | |
1431 if (add_failed) | |
1432 return add_failed; | |
1433 | |
1434 data->cursor_type = IGNORE_CURSOR; | |
1435 | |
1436 if (data->ch >= 0x100) | |
1437 { | |
1438 /* If the character is an extended Mule character, it could have | |
3498 | 1439 up to 21 bits. For the moment, we treat it as a seven-digit |
428 | 1440 octal number. This is not that pretty, but whatever. */ |
1441 data->ch = (7 & (orig_char >> 18)) + '0'; | |
1442 ADD_NEXT_OCTAL_RUNE_CHAR; | |
1443 | |
1444 data->ch = (7 & (orig_char >> 15)) + '0'; | |
1445 ADD_NEXT_OCTAL_RUNE_CHAR; | |
1446 | |
1447 data->ch = (7 & (orig_char >> 12)) + '0'; | |
1448 ADD_NEXT_OCTAL_RUNE_CHAR; | |
1449 | |
1450 data->ch = (7 & (orig_char >> 9)) + '0'; | |
1451 ADD_NEXT_OCTAL_RUNE_CHAR; | |
1452 } | |
1453 | |
1454 data->ch = (7 & (orig_char >> 6)) + '0'; | |
1455 ADD_NEXT_OCTAL_RUNE_CHAR; | |
1456 | |
1457 data->ch = (7 & (orig_char >> 3)) + '0'; | |
1458 ADD_NEXT_OCTAL_RUNE_CHAR; | |
1459 | |
1460 data->ch = (7 & orig_char) + '0'; | |
1461 ADD_NEXT_OCTAL_RUNE_CHAR; | |
1462 | |
1463 data->cursor_type = orig_cursor_type; | |
819 | 1464 return NULL; |
428 | 1465 } |
1466 | |
1467 #undef ADD_NEXT_OCTAL_RUNE_CHAR | |
1468 | |
1469 /* Add runes representing a control character to a display block. */ | |
1470 | |
1471 static prop_block_dynarr * | |
1472 add_control_char_runes (pos_data *data, struct buffer *b) | |
1473 { | |
1474 if (!NILP (b->ctl_arrow)) | |
1475 { | |
1476 prop_block_dynarr *prop; | |
867 | 1477 Ichar orig_char = data->ch; |
647 | 1478 int old_cursor_type = data->cursor_type; |
428 | 1479 |
1480 /* Initialize */ | |
1481 prop = NULL; | |
1482 | |
1483 if (data->start_col) | |
1484 data->start_col--; | |
1485 | |
1486 if (!data->start_col) | |
1487 { | |
826 | 1488 if (data->byte_start_col_enabled) |
428 | 1489 { |
1490 prop_block_dynarr *retval; | |
1491 | |
1492 retval = add_hscroll_rune (data); | |
1493 if (retval) | |
1494 return retval; | |
1495 } | |
1496 else | |
1497 { | |
1498 struct glyph_block gb; | |
1499 struct window *w = XWINDOW (data->window); | |
1500 | |
1501 gb.extent = Qnil; | |
1502 gb.glyph = Vcontrol_arrow_glyph; | |
1503 | |
1504 /* We only propagate information if the glyph was partially | |
1505 added. */ | |
1506 if (add_glyph_rune (data, &gb, BEGIN_GLYPHS, 1, | |
1507 GLYPH_CACHEL (w, CONTROL_GLYPH_INDEX))) | |
1508 return ADD_FAILED; | |
1509 } | |
1510 } | |
1511 | |
1512 if (orig_char == 0177) | |
1513 data->ch = '?'; | |
1514 else | |
1515 data->ch = orig_char ^ 0100; | |
1516 data->cursor_type = IGNORE_CURSOR; | |
1517 | |
867 | 1518 if (add_ichar_rune (data)) |
428 | 1519 { |
1520 struct prop_block pb; | |
1521 if (!prop) | |
1522 prop = Dynarr_new (prop_block); | |
1523 | |
1524 pb.type = PROP_CHAR; | |
1525 pb.data.p_char.ch = data->ch; | |
1526 pb.data.p_char.cursor_type = data->cursor_type; | |
1527 Dynarr_add (prop, pb); | |
1528 } | |
1529 | |
1530 data->cursor_type = old_cursor_type; | |
1531 return prop; | |
1532 } | |
1533 else | |
1534 { | |
1535 return add_octal_runes (data); | |
1536 } | |
1537 } | |
1538 | |
1539 static prop_block_dynarr * | |
1540 add_disp_table_entry_runes_1 (pos_data *data, Lisp_Object entry) | |
1541 { | |
1542 prop_block_dynarr *prop = NULL; | |
1543 | |
1544 if (STRINGP (entry)) | |
1545 { | |
867 | 1546 prop = add_ibyte_string_runes (data, |
428 | 1547 XSTRING_DATA (entry), |
1548 XSTRING_LENGTH (entry), | |
793 | 1549 0, 0); |
428 | 1550 } |
1551 else if (GLYPHP (entry)) | |
1552 { | |
1553 if (data->start_col) | |
1554 data->start_col--; | |
1555 | |
826 | 1556 if (!data->start_col && data->byte_start_col_enabled) |
428 | 1557 { |
1558 prop = add_hscroll_rune (data); | |
1559 } | |
1560 else | |
1561 { | |
1562 struct glyph_block gb; | |
1563 | |
1564 gb.glyph = entry; | |
1565 gb.extent = Qnil; | |
1566 prop = add_glyph_rune (data, &gb, BEGIN_GLYPHS, 0, 0); | |
1567 } | |
1568 } | |
1569 else if (CHAR_OR_CHAR_INTP (entry)) | |
1570 { | |
1571 data->ch = XCHAR_OR_CHAR_INT (entry); | |
867 | 1572 prop = add_ichar_rune (data); |
428 | 1573 } |
1574 else if (CONSP (entry)) | |
1575 { | |
1576 if (EQ (XCAR (entry), Qformat) | |
1577 && CONSP (XCDR (entry)) | |
1578 && STRINGP (XCAR (XCDR (entry)))) | |
1579 { | |
1580 Lisp_Object format = XCAR (XCDR (entry)); | |
665 | 1581 Bytebpos len = XSTRING_LENGTH (format); |
867 | 1582 Ibyte *src = XSTRING_DATA (format), *end = src + len; |
2367 | 1583 Ibyte *result = alloca_ibytes (len); |
867 | 1584 Ibyte *dst = result; |
428 | 1585 |
1586 while (src < end) | |
1587 { | |
867 | 1588 Ichar c = itext_ichar (src); |
1589 INC_IBYTEPTR (src); | |
428 | 1590 if (c != '%' || src == end) |
867 | 1591 dst += set_itext_ichar (dst, c); |
428 | 1592 else |
1593 { | |
867 | 1594 c = itext_ichar (src); |
1595 INC_IBYTEPTR (src); | |
428 | 1596 switch (c) |
1597 { | |
1598 /*case 'x': | |
1599 dst += long_to_string_base ((char *)dst, data->ch, 16); | |
1600 break;*/ | |
1601 case '%': | |
867 | 1602 dst += set_itext_ichar (dst, '%'); |
428 | 1603 break; |
442 | 1604 /* #### unimplemented */ |
428 | 1605 } |
1606 } | |
1607 } | |
867 | 1608 prop = add_ibyte_string_runes (data, result, dst - result, 0, 0); |
428 | 1609 } |
1610 } | |
1611 | |
1612 /* Else blow it off because someone added a bad entry and we don't | |
1613 have any safe way of signaling an error. */ | |
1614 return prop; | |
1615 } | |
1616 | |
1617 /* Given a display table entry, call the appropriate functions to | |
1618 display each element of the entry. */ | |
1619 | |
1620 static prop_block_dynarr * | |
1621 add_disp_table_entry_runes (pos_data *data, Lisp_Object entry) | |
1622 { | |
1623 prop_block_dynarr *prop = NULL; | |
1624 if (VECTORP (entry)) | |
1625 { | |
440 | 1626 Lisp_Vector *de = XVECTOR (entry); |
428 | 1627 EMACS_INT len = vector_length (de); |
1628 int elt; | |
1629 | |
1630 for (elt = 0; elt < len; elt++) | |
1631 { | |
1632 if (NILP (vector_data (de)[elt])) | |
1633 continue; | |
1634 else | |
1635 prop = add_disp_table_entry_runes_1 (data, vector_data (de)[elt]); | |
1636 /* Else blow it off because someone added a bad entry and we | |
1637 don't have any safe way of signaling an error. Hey, this | |
1638 comment sounds familiar. */ | |
1639 | |
1640 /* #### Still need to add any remaining elements to the | |
4187 | 1641 propagation information. */ |
428 | 1642 if (prop) |
1643 return prop; | |
1644 } | |
1645 } | |
1646 else | |
1647 prop = add_disp_table_entry_runes_1 (data, entry); | |
1648 return prop; | |
1649 } | |
1650 | |
1651 /* Add runes which were propagated from the previous line. */ | |
1652 | |
1653 static prop_block_dynarr * | |
1654 add_propagation_runes (prop_block_dynarr **prop, pos_data *data) | |
1655 { | |
1656 /* #### Remember to handle start_col parameter of data when the rest of | |
1657 this is finished. */ | |
1658 /* #### Chuck -- I've redone this function a bit. It looked like the | |
1659 case of not all the propagation blocks being added was not handled | |
1660 well. */ | |
1661 /* #### Chuck -- I also think the double indirection of PROP is kind | |
1662 of bogus. A cleaner solution is just to check for | |
1663 Dynarr_length (prop) > 0. */ | |
1664 /* #### This function also doesn't even pay attention to ADD_FAILED! | |
1665 This is seriously fucked! Seven ####'s in 130 lines -- is that a | |
1666 record? */ | |
1667 int elt; | |
1668 prop_block_dynarr *add_failed; | |
826 | 1669 Bytebpos byte_old_cursor_charpos = data->byte_cursor_charpos; |
647 | 1670 int old_cursor_type = data->cursor_type; |
428 | 1671 |
1672 for (elt = 0; elt < Dynarr_length (*prop); elt++) | |
1673 { | |
1674 struct prop_block *pb = Dynarr_atp (*prop, elt); | |
1675 | |
1676 switch (pb->type) | |
1677 { | |
1678 case PROP_CHAR: | |
1679 data->ch = pb->data.p_char.ch; | |
826 | 1680 data->byte_cursor_charpos = pb->data.p_char.byte_cursor_charpos; |
428 | 1681 data->cursor_type = pb->data.p_char.cursor_type; |
867 | 1682 add_failed = add_ichar_rune (data); |
428 | 1683 |
1684 if (add_failed) | |
1685 goto oops_no_more_space; | |
1686 break; | |
1687 case PROP_STRING: | |
1688 if (pb->data.p_string.str) | |
5169
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
1689 { |
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
1690 xfree (pb->data.p_string.str); |
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
1691 pb->data.p_string.str = 0; |
6c6d78781d59
cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents:
5157
diff
changeset
|
1692 } |
428 | 1693 /* #### bogus bogus -- this doesn't do anything! |
867 | 1694 Should probably call add_ibyte_string_runes(), |
428 | 1695 once that function is fixed. */ |
1696 break; | |
1697 case PROP_MINIBUF_PROMPT: | |
1698 { | |
1699 face_index old_findex = data->findex; | |
826 | 1700 Bytebpos byte_old_charpos = data->byte_charpos; |
428 | 1701 |
1702 data->findex = DEFAULT_INDEX; | |
826 | 1703 data->byte_charpos = 0; |
428 | 1704 data->cursor_type = NO_CURSOR; |
1705 | |
1706 while (pb->data.p_string.len > 0) | |
1707 { | |
867 | 1708 data->ch = itext_ichar (pb->data.p_string.str); |
1709 add_failed = add_ichar_rune (data); | |
428 | 1710 |
1711 if (add_failed) | |
1712 { | |
1713 data->findex = old_findex; | |
826 | 1714 data->byte_charpos = byte_old_charpos; |
428 | 1715 goto oops_no_more_space; |
1716 } | |
1717 else | |
1718 { | |
1719 /* Complicated equivalent of ptr++, len-- */ | |
867 | 1720 Ibyte *oldpos = pb->data.p_string.str; |
1721 INC_IBYTEPTR (pb->data.p_string.str); | |
428 | 1722 pb->data.p_string.len -= pb->data.p_string.str - oldpos; |
1723 } | |
1724 } | |
1725 | |
1726 data->findex = old_findex; | |
1727 /* ##### FIXME FIXME FIXME -- Upon successful return from | |
826 | 1728 this function, data->byte_charpos is automatically incremented. |
428 | 1729 However, we don't want that to happen if we were adding |
1730 the minibuffer prompt. */ | |
1731 { | |
1732 struct buffer *buf = | |
1733 XBUFFER (WINDOW_BUFFER (XWINDOW (data->window))); | |
1734 /* #### Chuck fix this shit or I'm gonna scream! */ | |
826 | 1735 if (byte_old_charpos > BYTE_BUF_BEGV (buf)) |
4187 | 1736 data->byte_charpos = prev_bytebpos (buf, byte_old_charpos); |
1737 else | |
428 | 1738 /* #### is this correct? Does anyone know? |
1739 Does anyone care? Is this a cheesy hack or what? */ | |
4187 | 1740 data->byte_charpos = BYTE_BUF_BEGV (buf) - 1; |
428 | 1741 } |
1742 } | |
1743 break; | |
1744 case PROP_BLANK: | |
1745 { | |
1746 /* #### I think it's unnecessary and misleading to preserve | |
1747 the blank_width, as it implies that the value carries | |
1748 over from one rune to the next, which is wrong. */ | |
1749 int old_width = data->blank_width; | |
1750 face_index old_findex = data->findex; | |
1751 | |
1752 data->findex = pb->data.p_blank.findex; | |
1753 data->blank_width = pb->data.p_blank.width; | |
826 | 1754 data->byte_cursor_charpos = 0; |
428 | 1755 data->cursor_type = IGNORE_CURSOR; |
1756 | |
1757 if (data->pixpos + data->blank_width > data->max_pixpos) | |
1758 data->blank_width = data->max_pixpos - data->pixpos; | |
1759 | |
1760 /* We pass a bogus value of char_tab_width. It shouldn't | |
4187 | 1761 matter because unless something is really screwed up |
1762 this call won't cause that arg to be used. */ | |
428 | 1763 add_failed = add_blank_rune (data, XWINDOW (data->window), 0); |
1764 | |
1765 /* This can happen in the case where we have a tab which | |
4187 | 1766 is wider than the window. */ |
428 | 1767 if (data->blank_width != pb->data.p_blank.width) |
1768 { | |
1769 pb->data.p_blank.width -= data->blank_width; | |
1770 add_failed = ADD_FAILED; | |
1771 } | |
1772 | |
1773 data->findex = old_findex; | |
1774 data->blank_width = old_width; | |
1775 | |
1776 if (add_failed) | |
1777 goto oops_no_more_space; | |
1778 } | |
1779 break; | |
1780 default: | |
2500 | 1781 ABORT (); |
428 | 1782 } |
1783 } | |
1784 | |
1785 oops_no_more_space: | |
1786 | |
826 | 1787 data->byte_cursor_charpos = byte_old_cursor_charpos; |
428 | 1788 data->cursor_type = old_cursor_type; |
1789 if (elt < Dynarr_length (*prop)) | |
1790 { | |
1791 Dynarr_delete_many (*prop, 0, elt); | |
1792 return *prop; | |
1793 } | |
1794 else | |
1795 { | |
1796 Dynarr_free (*prop); | |
1797 return NULL; | |
1798 } | |
1799 } | |
1800 | |
3025 | 1801 /* Add `text' layout glyphs at position POS_TYPE that are contained to |
428 | 1802 the display block, but add all other types to the appropriate list |
1803 of the display line. They will be added later by different | |
1804 routines. */ | |
1805 | |
1806 static prop_block_dynarr * | |
1807 add_glyph_rune (pos_data *data, struct glyph_block *gb, int pos_type, | |
1808 int allow_cursor, struct glyph_cachel *cachel) | |
1809 { | |
1810 struct window *w = XWINDOW (data->window); | |
1811 | |
440 | 1812 /* If window faces changed, and glyph instance is text, then |
1813 glyph sizes might have changed too */ | |
1814 invalidate_glyph_geometry_maybe (gb->glyph, w); | |
1815 | |
442 | 1816 /* This makes sure the glyph is in the cachels. |
1817 | |
1818 #### We do this to make sure the glyph is in the glyph cachels, | |
1819 so that the dirty flag can be reset after redisplay has | |
1820 finished. We should do this some other way, maybe by iterating | |
1821 over the window cache of subwindows. */ | |
1822 get_glyph_cachel_index (w, gb->glyph); | |
1823 | |
428 | 1824 /* A nil extent indicates a special glyph (ex. truncator). */ |
1825 if (NILP (gb->extent) | |
1826 || (pos_type == BEGIN_GLYPHS && | |
1827 extent_begin_glyph_layout (XEXTENT (gb->extent)) == GL_TEXT) | |
1828 || (pos_type == END_GLYPHS && | |
442 | 1829 extent_end_glyph_layout (XEXTENT (gb->extent)) == GL_TEXT) |
1830 || pos_type == LEFT_GLYPHS || pos_type == RIGHT_GLYPHS) | |
428 | 1831 { |
1832 struct rune rb; | |
1833 int width; | |
1834 int xoffset = 0; | |
1835 int ascent, descent; | |
1836 Lisp_Object baseline; | |
1837 Lisp_Object face; | |
442 | 1838 Lisp_Object instance; |
1839 face_index findex; | |
819 | 1840 prop_block_dynarr *retval = 0; |
428 | 1841 |
1842 if (cachel) | |
1843 width = cachel->width; | |
1844 else | |
438 | 1845 width = glyph_width (gb->glyph, data->window); |
428 | 1846 |
1847 if (!width) | |
1848 return NULL; | |
1849 | |
1850 if (data->start_col || data->start_col_xoffset) | |
1851 { | |
1852 int glyph_char_width = width / space_width (w); | |
1853 | |
1854 /* If we still have not fully scrolled horizontally after | |
4187 | 1855 taking into account the width of the glyph, subtract its |
1856 width and return. */ | |
428 | 1857 if (glyph_char_width < data->start_col) |
1858 { | |
1859 data->start_col -= glyph_char_width; | |
1860 return NULL; | |
1861 } | |
1862 else if (glyph_char_width == data->start_col) | |
1863 width = 0; | |
1864 else | |
1865 { | |
1866 xoffset = space_width (w) * data->start_col; | |
1867 width -= xoffset; | |
1868 | |
1869 /* #### Can this happen? */ | |
1870 if (width < 0) | |
1871 width = 0; | |
1872 } | |
1873 | |
1874 data->start_col = 0; | |
1875 retval = add_hscroll_rune (data); | |
1876 | |
1877 /* Could be caused by the handling of the hscroll rune. */ | |
1878 if (retval != NULL || !width) | |
1879 return retval; | |
1880 } | |
1881 else | |
1882 xoffset = 0; | |
1883 | |
1884 if (data->pixpos + width > data->max_pixpos) | |
1885 { | |
1886 /* If this is the first object we are attempting to add to | |
819 | 1887 the line then we ignore the horizontal_clip threshold. |
1888 Otherwise we will loop until the bottom of the window | |
1889 continually failing to add this glyph because it is wider | |
1890 than the window. We could alternatively just completely | |
1891 ignore the glyph and proceed from there but I think that | |
1892 this is a better solution. | |
4187 | 1893 |
819 | 1894 This does, however, create a different problem in that we |
1895 can end up adding the object to every single line, never | |
1896 getting any further - for instance an extent with a long | |
1897 start-glyph that covers multitple following | |
1898 characters. */ | |
428 | 1899 if (Dynarr_length (data->db->runes) |
1900 && data->max_pixpos - data->pixpos < horizontal_clip) | |
1901 return ADD_FAILED; | |
819 | 1902 else { |
1903 struct prop_block pb; | |
1904 | |
1905 /* We need to account for the width of the end-of-line | |
1906 glyph if there is nothing more in the line to display, | |
1907 since we will not display it in this instance. It seems | |
1908 kind of gross doing it here, but otherwise we have to | |
1909 search the runes in create_text_block(). */ | |
1910 if (data->ch == '\n') | |
1911 data->max_pixpos += data->end_glyph_width; | |
428 | 1912 width = data->max_pixpos - data->pixpos; |
819 | 1913 /* Add the glyph we are displaying, but clipping, to the |
1914 propagation data so that we don't try and do it | |
4187 | 1915 again. */ |
819 | 1916 retval = Dynarr_new (prop_block); |
1917 pb.type = PROP_GLYPH; | |
1918 pb.data.p_glyph.glyph = gb->glyph; | |
1919 pb.data.p_glyph.width = width; | |
1920 Dynarr_add (retval, pb); | |
1921 } | |
428 | 1922 } |
1923 | |
1924 if (cachel) | |
1925 { | |
1926 ascent = cachel->ascent; | |
1927 descent = cachel->descent; | |
1928 } | |
1929 else | |
1930 { | |
438 | 1931 ascent = glyph_ascent (gb->glyph, data->window); |
1932 descent = glyph_descent (gb->glyph, data->window); | |
428 | 1933 } |
1934 | |
1935 baseline = glyph_baseline (gb->glyph, data->window); | |
1936 | |
819 | 1937 rb.object.dglyph.descent = 0; /* Gets reset lower down, if it is known. */ |
1938 | |
428 | 1939 if (glyph_contrib_p (gb->glyph, data->window)) |
1940 { | |
1941 /* A pixmap that has not had a baseline explicitly set. Its | |
1942 contribution will be determined later. */ | |
1943 if (NILP (baseline)) | |
1944 { | |
1945 int height = ascent + descent; | |
819 | 1946 data->need_baseline_computation = 1; |
428 | 1947 data->max_pixmap_height = max (data->max_pixmap_height, height); |
1948 } | |
1949 | |
1950 /* A string so determine contribution normally. */ | |
1951 else if (EQ (baseline, Qt)) | |
1952 { | |
1953 data->new_ascent = max (data->new_ascent, ascent); | |
1954 data->new_descent = max (data->new_descent, descent); | |
1955 } | |
1956 | |
1957 /* A pixmap with an explicitly set baseline. We determine the | |
1958 contribution here. */ | |
1959 else if (INTP (baseline)) | |
1960 { | |
1961 int height = ascent + descent; | |
1962 int pix_ascent, pix_descent; | |
1963 | |
1964 pix_ascent = height * XINT (baseline) / 100; | |
1965 pix_descent = height - pix_ascent; | |
1966 | |
1967 data->new_ascent = max (data->new_ascent, pix_ascent); | |
1968 data->new_descent = max (data->new_descent, pix_descent); | |
819 | 1969 data->max_pixmap_height = max (data->max_pixmap_height, height); |
4187 | 1970 |
819 | 1971 rb.object.dglyph.descent = pix_descent; |
428 | 1972 } |
1973 | |
1974 /* Otherwise something is screwed up. */ | |
1975 else | |
2500 | 1976 ABORT (); |
428 | 1977 } |
1978 | |
1979 face = glyph_face (gb->glyph, data->window); | |
1980 if (NILP (face)) | |
442 | 1981 findex = data->findex; |
428 | 1982 else |
442 | 1983 findex = get_builtin_face_cache_index (w, face); |
1984 | |
1985 instance = glyph_image_instance (gb->glyph, data->window, | |
793 | 1986 ERROR_ME_DEBUG_WARN, 1); |
442 | 1987 if (TEXT_IMAGE_INSTANCEP (instance)) |
1988 { | |
1989 Lisp_Object string = XIMAGE_INSTANCE_TEXT_STRING (instance); | |
1990 face_index orig_findex = data->findex; | |
826 | 1991 Bytebpos orig_charpos = data->byte_charpos; |
1992 Bytebpos orig_start_col_enabled = data->byte_start_col_enabled; | |
442 | 1993 |
1994 data->findex = findex; | |
826 | 1995 data->byte_start_col_enabled = 0; |
442 | 1996 if (!allow_cursor) |
826 | 1997 data->byte_charpos = 0; |
867 | 1998 add_ibyte_string_runes (data, XSTRING_DATA (string), |
793 | 1999 XSTRING_LENGTH (string), 0, 1); |
442 | 2000 data->findex = orig_findex; |
826 | 2001 data->byte_charpos = orig_charpos; |
2002 data->byte_start_col_enabled = orig_start_col_enabled; | |
819 | 2003 return retval; |
442 | 2004 } |
2005 | |
2006 rb.findex = findex; | |
428 | 2007 rb.xpos = data->pixpos; |
2008 rb.width = width; | |
826 | 2009 rb.charpos = 0; /* glyphs are never "at" anywhere */ |
2010 if (data->byte_endpos) | |
428 | 2011 /* #### is this necessary at all? */ |
665 | 2012 rb.endpos = bytebpos_to_charbpos (XBUFFER (WINDOW_BUFFER (w)), |
826 | 2013 data->byte_endpos); |
428 | 2014 else |
4187 | 2015 rb.endpos = 0; |
428 | 2016 rb.type = RUNE_DGLYPH; |
2017 rb.object.dglyph.glyph = gb->glyph; | |
2018 rb.object.dglyph.extent = gb->extent; | |
2019 rb.object.dglyph.xoffset = xoffset; | |
819 | 2020 rb.object.dglyph.ascent = ascent; |
2021 rb.object.dglyph.yoffset = 0; /* Until we know better, assume that it has | |
2022 a normal (textual) baseline. */ | |
428 | 2023 |
2024 if (allow_cursor) | |
2025 { | |
826 | 2026 rb.charpos = bytebpos_to_charbpos (XBUFFER (WINDOW_BUFFER (w)), |
2027 data->byte_charpos); | |
428 | 2028 |
2029 if (data->cursor_type == CURSOR_ON) | |
2030 { | |
826 | 2031 if (data->byte_charpos == data->byte_cursor_charpos) |
428 | 2032 { |
2033 rb.cursor_type = CURSOR_ON; | |
2034 data->cursor_x = Dynarr_length (data->db->runes); | |
2035 } | |
2036 else | |
2037 rb.cursor_type = CURSOR_OFF; | |
2038 } | |
2039 else if (data->cursor_type == NEXT_CURSOR) | |
2040 { | |
2041 rb.cursor_type = CURSOR_ON; | |
2042 data->cursor_x = Dynarr_length (data->db->runes); | |
2043 data->cursor_type = NO_CURSOR; | |
2044 } | |
2045 else if (data->cursor_type == IGNORE_CURSOR) | |
2046 rb.cursor_type = IGNORE_CURSOR; | |
2047 else if (data->cursor_type == NO_CURSOR) | |
2048 rb.cursor_type = NO_CURSOR; | |
2049 else | |
2050 rb.cursor_type = CURSOR_OFF; | |
2051 } | |
2052 else | |
2053 rb.cursor_type = CURSOR_OFF; | |
2054 | |
2055 Dynarr_add (data->db->runes, rb); | |
2056 data->pixpos += width; | |
2057 | |
819 | 2058 return retval; |
428 | 2059 } |
2060 else | |
2061 { | |
2062 if (!NILP (glyph_face (gb->glyph, data->window))) | |
2063 gb->findex = | |
2064 get_builtin_face_cache_index (w, glyph_face (gb->glyph, | |
2065 data->window)); | |
2066 else | |
2067 gb->findex = data->findex; | |
2068 | |
2069 if (pos_type == BEGIN_GLYPHS) | |
2070 { | |
2071 if (!data->dl->left_glyphs) | |
2072 data->dl->left_glyphs = Dynarr_new (glyph_block); | |
2073 Dynarr_add (data->dl->left_glyphs, *gb); | |
2074 return NULL; | |
2075 } | |
2076 else if (pos_type == END_GLYPHS) | |
2077 { | |
2078 if (!data->dl->right_glyphs) | |
2079 data->dl->right_glyphs = Dynarr_new (glyph_block); | |
2080 Dynarr_add (data->dl->right_glyphs, *gb); | |
2081 return NULL; | |
2082 } | |
2083 else | |
2500 | 2084 ABORT (); /* there are no unknown types */ |
428 | 2085 } |
2086 | |
819 | 2087 return NULL; |
428 | 2088 } |
2089 | |
2090 /* Add all glyphs at position POS_TYPE that are contained in the given | |
2091 data. */ | |
2092 | |
2093 static prop_block_dynarr * | |
2094 add_glyph_runes (pos_data *data, int pos_type) | |
2095 { | |
2096 /* #### This still needs to handle the start_col parameter. Duh, Chuck, | |
2097 why didn't you just modify add_glyph_rune in the first place? */ | |
2098 int elt; | |
2099 glyph_block_dynarr *glyph_arr = (pos_type == BEGIN_GLYPHS | |
2100 ? data->ef->begin_glyphs | |
2101 : data->ef->end_glyphs); | |
2102 prop_block_dynarr *prop; | |
2103 | |
2104 for (elt = 0; elt < Dynarr_length (glyph_arr); elt++) | |
2105 { | |
2106 prop = add_glyph_rune (data, Dynarr_atp (glyph_arr, elt), pos_type, 0, | |
2107 0); | |
2108 | |
2109 if (prop) | |
2110 { | |
2111 /* #### Add some propagation information. */ | |
2112 return prop; | |
2113 } | |
2114 } | |
2115 | |
2116 Dynarr_reset (glyph_arr); | |
2117 | |
2118 return NULL; | |
2119 } | |
2120 | |
2121 /* Given a position for a buffer in a window, ensure that the given | |
2122 display line DL accurately represents the text on a line starting | |
2123 at the given position. | |
2124 | |
826 | 2125 NOTE NOTE NOTE NOTE: This function works with and returns Bytebpos's. |
428 | 2126 You must do appropriate conversion. */ |
2127 | |
665 | 2128 static Bytebpos |
428 | 2129 create_text_block (struct window *w, struct display_line *dl, |
826 | 2130 Bytebpos byte_start_pos, prop_block_dynarr **prop, |
428 | 2131 int type) |
2132 { | |
2133 struct frame *f = XFRAME (w->frame); | |
2134 struct buffer *b = XBUFFER (w->buffer); | |
2135 struct device *d = XDEVICE (f->device); | |
2136 | |
2137 pos_data data; | |
2138 | |
2139 /* Don't display anything in the minibuffer if this window is not on | |
2140 a selected frame. We consider all other windows to be active | |
2141 minibuffers as it simplifies the coding. */ | |
2142 int active_minibuffer = (!MINI_WINDOW_P (w) || | |
2143 (f == device_selected_frame (d)) || | |
2144 is_surrogate_for_selected_frame (f)); | |
2145 | |
2146 int truncate_win = window_truncation_on (w); | |
2147 | |
2148 /* If the buffer's value of selective_display is an integer then | |
2149 only lines that start with less than selective_display columns of | |
2150 space will be displayed. If selective_display is t then all text | |
2151 after a ^M is invisible. */ | |
2152 int selective = (INTP (b->selective_display) | |
2153 ? XINT (b->selective_display) | |
434 | 2154 : (!NILP (b->selective_display) ? -1 : 0)); |
428 | 2155 |
2156 /* The variable ctl-arrow allows the user to specify what characters | |
2157 can actually be displayed and which octal should be used for. | |
2158 #### This variable should probably have some rethought done to | |
2159 it. | |
2160 | |
2367 | 2161 See also |
2162 | |
2163 (Info-goto-node "(internals)Future Work -- Display Tables") | |
2164 | |
2165 */ | |
867 | 2166 Ichar printable_min = (CHAR_OR_CHAR_INTP (b->ctl_arrow) |
428 | 2167 ? XCHAR_OR_CHAR_INT (b->ctl_arrow) |
2168 : ((EQ (b->ctl_arrow, Qt) || EQ (b->ctl_arrow, Qnil)) | |
2169 ? 255 : 160)); | |
2170 | |
2171 Lisp_Object face_dt, window_dt; | |
2172 | |
2173 /* The text display block for this display line. */ | |
2174 struct display_block *db = get_display_block_from_line (dl, TEXT); | |
2175 | |
2176 /* The first time through the main loop we need to force the glyph | |
2177 data to be updated. */ | |
2178 int initial = 1; | |
2179 | |
2180 /* Apparently the new extent_fragment_update returns an end position | |
2181 equal to the position passed in if there are no more runs to be | |
2182 displayed. */ | |
2183 int no_more_frags = 0; | |
2184 | |
2185 Lisp_Object synch_minibuffers_value = | |
2186 symbol_value_in_buffer (Qsynchronize_minibuffers, w->buffer); | |
2187 | |
2188 dl->used_prop_data = 0; | |
2189 dl->num_chars = 0; | |
442 | 2190 dl->line_continuation = 0; |
428 | 2191 |
2192 xzero (data); | |
2193 data.ef = extent_fragment_new (w->buffer, f); | |
2194 | |
2195 /* These values are used by all of the rune addition routines. We add | |
2196 them to this structure for ease of passing. */ | |
2197 data.d = d; | |
793 | 2198 data.window = wrap_window (w); |
428 | 2199 data.string = Qnil; |
2200 data.db = db; | |
2201 data.dl = dl; | |
2202 | |
826 | 2203 data.byte_charpos = byte_start_pos; |
428 | 2204 data.pixpos = dl->bounds.left_in; |
2205 data.last_charset = Qunbound; | |
2206 data.last_findex = DEFAULT_INDEX; | |
2207 data.result_str = Qnil; | |
2208 | |
2209 /* Set the right boundary adjusting it to take into account any end | |
2210 glyph. Save the width of the end glyph for later use. */ | |
2211 data.max_pixpos = dl->bounds.right_in; | |
2212 if (truncate_win) | |
819 | 2213 data.end_glyph_width = GLYPH_CACHEL_WIDTH (w, TRUN_GLYPH_INDEX); |
428 | 2214 else |
819 | 2215 data.end_glyph_width = GLYPH_CACHEL_WIDTH (w, CONT_GLYPH_INDEX); |
2216 data.max_pixpos -= data.end_glyph_width; | |
428 | 2217 |
2218 if (cursor_in_echo_area && MINI_WINDOW_P (w) && echo_area_active (f)) | |
2219 { | |
826 | 2220 data.byte_cursor_charpos = BYTE_BUF_ZV (b); |
428 | 2221 data.cursor_type = CURSOR_ON; |
2222 } | |
2223 else if (MINI_WINDOW_P (w) && !active_minibuffer) | |
2224 data.cursor_type = NO_CURSOR; | |
2225 else if (w == XWINDOW (FRAME_SELECTED_WINDOW (f)) && | |
5198 | 2226 EQ (DEVICE_CONSOLE (d), Vselected_console) && |
2227 d == XDEVICE (CONSOLE_SELECTED_DEVICE (XCONSOLE (DEVICE_CONSOLE (d))))&& | |
2228 f == XFRAME (DEVICE_SELECTED_FRAME (d))) | |
428 | 2229 { |
826 | 2230 data.byte_cursor_charpos = BYTE_BUF_PT (b); |
428 | 2231 data.cursor_type = CURSOR_ON; |
2232 } | |
2233 else if (w == XWINDOW (FRAME_SELECTED_WINDOW (f))) | |
2234 { | |
826 | 2235 data.byte_cursor_charpos = byte_marker_position (w->pointm[type]); |
428 | 2236 data.cursor_type = CURSOR_ON; |
2237 } | |
2238 else | |
2239 data.cursor_type = NO_CURSOR; | |
2240 data.cursor_x = -1; | |
2241 | |
2242 data.start_col = w->hscroll; | |
2243 data.start_col_xoffset = w->left_xoffset; | |
826 | 2244 data.byte_start_col_enabled = (w->hscroll ? byte_start_pos : 0); |
428 | 2245 data.hscroll_glyph_width_adjust = 0; |
2246 | |
2247 /* We regenerate the line from the very beginning. */ | |
2248 Dynarr_reset (db->runes); | |
2249 | |
2250 /* Why is this less than or equal and not just less than? If the | |
2251 starting position is already equal to the maximum we can't add | |
2252 anything else, right? Wrong. We might still have a newline to | |
2253 add. A newline can use the room allocated for an end glyph since | |
2254 if we add it we know we aren't going to be adding any end | |
2255 glyph. */ | |
2256 | |
2257 /* #### Chuck -- I think this condition should be while (1). | |
2258 Otherwise if (e.g.) there is one begin-glyph and one end-glyph | |
2259 and the begin-glyph ends exactly at the end of the window, the | |
2260 end-glyph and text might not be displayed. while (1) ensures | |
2261 that the loop terminates only when either (a) there is | |
2262 propagation data or (b) the end-of-line or end-of-buffer is hit. | |
2263 | |
2264 #### Also I think you need to ensure that the operation | |
2265 "add begin glyphs; add end glyphs; add text" is atomic and | |
2266 can't get interrupted in the middle. If you run off the end | |
2267 of the line during that operation, then you keep accumulating | |
2268 propagation data until you're done. Otherwise, if the (e.g.) | |
2269 there's a begin glyph at a particular position and attempting | |
2270 to display that glyph results in window-end being hit and | |
2271 propagation data being generated, then the character at that | |
2272 position won't be displayed. | |
2273 | |
2274 #### See also the comment after the end of this loop, below. | |
2275 */ | |
2276 while (data.pixpos <= data.max_pixpos | |
2277 && (active_minibuffer || !NILP (synch_minibuffers_value))) | |
2278 { | |
2279 /* #### This check probably should not be necessary. */ | |
826 | 2280 if (data.byte_charpos > BYTE_BUF_ZV (b)) |
428 | 2281 { |
2282 /* #### urk! More of this lossage! */ | |
826 | 2283 data.byte_charpos--; |
428 | 2284 goto done; |
2285 } | |
2286 | |
2287 /* If selective display was an integer and we aren't working on | |
4187 | 2288 a continuation line then find the next line we are actually |
2289 supposed to display. */ | |
428 | 2290 if (selective > 0 |
826 | 2291 && (data.byte_charpos == BYTE_BUF_BEGV (b) |
2292 || BUF_FETCH_CHAR (b, prev_bytebpos (b, data.byte_charpos)) == '\n')) | |
2293 { | |
2294 while (byte_spaces_at_point (b, data.byte_charpos) >= selective) | |
428 | 2295 { |
826 | 2296 data.byte_charpos = |
2297 byte_find_next_newline_no_quit (b, data.byte_charpos, 1); | |
2298 if (data.byte_charpos >= BYTE_BUF_ZV (b)) | |
428 | 2299 { |
826 | 2300 data.byte_charpos = BYTE_BUF_ZV (b); |
428 | 2301 goto done; |
2302 } | |
2303 } | |
2304 } | |
2305 | |
2306 /* Check for face changes. */ | |
826 | 2307 if (initial || (!no_more_frags && data.byte_charpos == data.ef->end)) |
428 | 2308 { |
819 | 2309 Lisp_Object last_glyph = Qnil; |
2310 | |
2311 /* Deal with glyphs that we have already displayed. The | |
2312 theory is that if we end up with a PROP_GLYPH in the | |
2313 propagation data then we are clipping the glyph and there | |
2314 can be no propagation data before that point. The theory | |
2315 works because we always recalculate the extent-fragments | |
2316 for propagated data, we never actually propagate the | |
2317 fragments that still need to be displayed. */ | |
4967 | 2318 if (*prop && Dynarr_begin (*prop)->type == PROP_GLYPH) |
2319 { | |
2320 last_glyph = Dynarr_begin (*prop)->data.p_glyph.glyph; | |
819 | 2321 Dynarr_free (*prop); |
2322 *prop = 0; | |
2323 } | |
428 | 2324 /* Now compute the face and begin/end-glyph information. */ |
2325 data.findex = | |
665 | 2326 /* Remember that the extent-fragment routines deal in Bytebpos's. */ |
826 | 2327 extent_fragment_update (w, data.ef, data.byte_charpos, last_glyph); |
428 | 2328 |
2329 get_display_tables (w, data.findex, &face_dt, &window_dt); | |
2330 | |
826 | 2331 if (data.byte_charpos == data.ef->end) |
428 | 2332 no_more_frags = 1; |
2333 } | |
2334 initial = 0; | |
2335 | |
2336 /* Determine what is next to be displayed. We first handle any | |
4187 | 2337 glyphs returned by glyphs_at_charbpos. If there are no glyphs to |
2338 display then we determine what to do based on the character at the | |
2339 current buffer position. */ | |
428 | 2340 |
2341 /* If the current position is covered by an invisible extent, do | |
4187 | 2342 nothing (except maybe add some ellipses). |
428 | 2343 |
2344 #### The behavior of begin and end-glyphs at the edge of an | |
2345 invisible extent should be investigated further. This is | |
2346 fairly low priority though. */ | |
2347 if (data.ef->invisible) | |
2348 { | |
2349 /* #### Chuck, perhaps you could look at this code? I don't | |
2350 really know what I'm doing. */ | |
2351 if (*prop) | |
2352 { | |
2353 Dynarr_free (*prop); | |
2354 *prop = 0; | |
2355 } | |
2356 | |
2357 /* The extent fragment code only sets this when we should | |
2358 really display the ellipses. It makes sure the ellipses | |
2359 don't get displayed more than once in a row. */ | |
2360 if (data.ef->invisible_ellipses) | |
2361 { | |
2362 struct glyph_block gb; | |
2363 | |
2364 data.ef->invisible_ellipses_already_displayed = 1; | |
2365 data.ef->invisible_ellipses = 0; | |
2366 gb.extent = Qnil; | |
2367 gb.glyph = Vinvisible_text_glyph; | |
2368 *prop = add_glyph_rune (&data, &gb, BEGIN_GLYPHS, 0, | |
2369 GLYPH_CACHEL (w, INVIS_GLYPH_INDEX)); | |
2370 /* Perhaps they shouldn't propagate if the very next thing | |
2371 is to display a newline (for compatibility with | |
2372 selective-display-ellipses)? Maybe that's too | |
2373 abstruse. */ | |
2374 if (*prop) | |
2375 goto done; | |
2376 } | |
2377 | |
2378 /* If point is in an invisible region we place it on the | |
4187 | 2379 next visible character. */ |
428 | 2380 if (data.cursor_type == CURSOR_ON |
826 | 2381 && data.byte_charpos == data.byte_cursor_charpos) |
428 | 2382 { |
2383 data.cursor_type = NEXT_CURSOR; | |
2384 } | |
2385 | |
2386 /* #### What if we we're dealing with a display table? */ | |
2387 if (data.start_col) | |
2388 data.start_col--; | |
2389 | |
826 | 2390 if (data.byte_charpos == BYTE_BUF_ZV (b)) |
428 | 2391 goto done; |
2392 else | |
826 | 2393 INC_BYTEBPOS (b, data.byte_charpos); |
428 | 2394 } |
2395 | |
2396 /* If there is propagation data, then it represents the current | |
819 | 2397 buffer position being displayed. Add them and advance the |
2398 position counter. This might also add the minibuffer | |
2399 prompt. */ | |
428 | 2400 else if (*prop) |
2401 { | |
2402 dl->used_prop_data = 1; | |
2403 *prop = add_propagation_runes (prop, &data); | |
2404 | |
2405 if (*prop) | |
2406 goto done; /* gee, a really narrow window */ | |
826 | 2407 else if (data.byte_charpos == BYTE_BUF_ZV (b)) |
428 | 2408 goto done; |
826 | 2409 else if (data.byte_charpos < BYTE_BUF_BEGV (b)) |
428 | 2410 /* #### urk urk urk! Aborts are not very fun! Fix this please! */ |
826 | 2411 data.byte_charpos = BYTE_BUF_BEGV (b); |
428 | 2412 else |
826 | 2413 INC_BYTEBPOS (b, data.byte_charpos); |
428 | 2414 } |
2415 | |
2416 /* If there are end glyphs, add them to the line. These are | |
2417 the end glyphs for the previous run of text. We add them | |
2418 here rather than doing them at the end of handling the | |
2419 previous run so that glyphs at the beginning and end of | |
2420 a line are handled correctly. */ | |
819 | 2421 else if (Dynarr_length (data.ef->end_glyphs) > 0 |
2422 || Dynarr_length (data.ef->begin_glyphs) > 0) | |
2423 { | |
2424 glyph_block_dynarr* tmpglyphs = 0; | |
2425 /* #### I think this is safe, but could be wrong. */ | |
826 | 2426 data.ch = BYTE_BUF_FETCH_CHAR (b, data.byte_charpos); |
819 | 2427 |
4187 | 2428 if (Dynarr_length (data.ef->end_glyphs) > 0) |
819 | 2429 { |
2430 *prop = add_glyph_runes (&data, END_GLYPHS); | |
2431 tmpglyphs = data.ef->end_glyphs; | |
2432 } | |
2433 | |
2434 /* If there are begin glyphs, add them to the line. */ | |
4187 | 2435 if (!*prop && Dynarr_length (data.ef->begin_glyphs) > 0) |
819 | 2436 { |
2437 *prop = add_glyph_runes (&data, BEGIN_GLYPHS); | |
2438 tmpglyphs = data.ef->begin_glyphs; | |
2439 } | |
2440 | |
4187 | 2441 if (*prop) |
819 | 2442 { |
2443 /* If we just clipped a glyph and we are at the end of a | |
2444 line and there are more glyphs to display then do | |
2445 appropriate processing to not get a continuation | |
2446 glyph. */ | |
4844
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4815
diff
changeset
|
2447 if (*prop != ADD_FAILED |
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4815
diff
changeset
|
2448 && Dynarr_begin (*prop)->type == PROP_GLYPH |
819 | 2449 && data.ch == '\n') |
4187 | 2450 { |
819 | 2451 /* If there are no more glyphs then do the normal |
4187 | 2452 processing. |
819 | 2453 |
2454 #### This doesn't actually work if the same glyph is | |
2455 present more than once in the block. To solve | |
2456 this we would have to carry the index around | |
2457 which might be problematic since the fragment is | |
2458 recalculated for each line. */ | |
4844
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4815
diff
changeset
|
2459 if (EQ (Dynarr_lastp (tmpglyphs)->glyph, |
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4815
diff
changeset
|
2460 Dynarr_begin (*prop)->data.p_glyph.glyph)) |
819 | 2461 { |
2462 Dynarr_free (*prop); | |
2463 *prop = 0; | |
2464 } | |
2465 else { | |
2466 data.blank_width = DEVMETH (d, eol_cursor_width, ()); | |
867 | 2467 add_ichar_rune (&data); /* discard prop data. */ |
819 | 2468 goto done; |
2469 } | |
2470 } | |
2471 else | |
2472 goto done; | |
2473 } | |
428 | 2474 } |
2475 | |
2476 /* If at end-of-buffer, we've already processed begin and | |
2477 end-glyphs at this point and there's no text to process, | |
2478 so we're done. */ | |
826 | 2479 else if (data.byte_charpos == BYTE_BUF_ZV (b)) |
428 | 2480 goto done; |
2481 | |
2482 else | |
2483 { | |
2484 Lisp_Object entry = Qnil; | |
2485 /* Get the character at the current buffer position. */ | |
826 | 2486 data.ch = BYTE_BUF_FETCH_CHAR (b, data.byte_charpos); |
428 | 2487 if (!NILP (face_dt) || !NILP (window_dt)) |
2488 entry = display_table_entry (data.ch, face_dt, window_dt); | |
2489 | |
2490 /* If there is a display table entry for it, hand it off to | |
4187 | 2491 add_disp_table_entry_runes and let it worry about it. */ |
428 | 2492 if (!NILP (entry) && !EQ (entry, make_char (data.ch))) |
2493 { | |
2494 *prop = add_disp_table_entry_runes (&data, entry); | |
2495 | |
2496 if (*prop) | |
2497 goto done; | |
2498 } | |
2499 | |
2500 /* Check if we have hit a newline character. If so, add a marker | |
4187 | 2501 to the line and end this loop. */ |
428 | 2502 else if (data.ch == '\n') |
2503 { | |
2504 /* We aren't going to be adding an end glyph so give its | |
4187 | 2505 space back in order to make sure that the cursor can |
2506 fit. */ | |
819 | 2507 data.max_pixpos += data.end_glyph_width; |
428 | 2508 |
2509 if (selective > 0 | |
826 | 2510 && (byte_spaces_at_point |
2511 (b, next_bytebpos (b, data.byte_charpos)) | |
428 | 2512 >= selective)) |
2513 { | |
2514 if (!NILP (b->selective_display_ellipses)) | |
2515 { | |
2516 struct glyph_block gb; | |
2517 | |
2518 gb.extent = Qnil; | |
2519 gb.glyph = Vinvisible_text_glyph; | |
2520 add_glyph_rune (&data, &gb, BEGIN_GLYPHS, 0, | |
2521 GLYPH_CACHEL (w, INVIS_GLYPH_INDEX)); | |
2522 } | |
2523 else | |
2524 { | |
2525 /* Cheesy, cheesy, cheesy. We mark the end of the | |
2526 line with a special "character rune" whose width | |
2527 is the EOL cursor width and whose character is | |
2528 the non-printing character '\n'. */ | |
2529 data.blank_width = DEVMETH (d, eol_cursor_width, ()); | |
867 | 2530 *prop = add_ichar_rune (&data); |
428 | 2531 } |
2532 | |
826 | 2533 /* We need to set data.byte_charpos to the start of the |
4187 | 2534 next visible region in order to make this line |
2535 appear to contain all of the invisible area. | |
2536 Otherwise, the line cache won't work | |
2537 correctly. */ | |
826 | 2538 INC_BYTEBPOS (b, data.byte_charpos); |
2539 while (byte_spaces_at_point (b, data.byte_charpos) >= selective) | |
428 | 2540 { |
826 | 2541 data.byte_charpos = |
2542 byte_find_next_newline_no_quit (b, data.byte_charpos, 1); | |
2543 if (data.byte_charpos >= BYTE_BUF_ZV (b)) | |
428 | 2544 { |
826 | 2545 data.byte_charpos = BYTE_BUF_ZV (b); |
428 | 2546 break; |
2547 } | |
2548 } | |
826 | 2549 if (BYTE_BUF_FETCH_CHAR |
2550 (b, prev_bytebpos (b, data.byte_charpos)) == '\n') | |
2551 DEC_BYTEBPOS (b, data.byte_charpos); | |
428 | 2552 } |
2553 else | |
2554 { | |
2555 data.blank_width = DEVMETH (d, eol_cursor_width, ()); | |
867 | 2556 *prop = add_ichar_rune (&data); |
428 | 2557 } |
2558 | |
2559 goto done; | |
2560 } | |
2561 | |
2562 /* If the current character is ^M, and selective display is | |
4187 | 2563 enabled, then add the invisible-text-glyph if |
2564 selective-display-ellipses is set. In any case, this | |
2565 line is done. */ | |
428 | 2566 else if (data.ch == (('M' & 037)) && selective == -1) |
2567 { | |
826 | 2568 Bytebpos byte_next_charpos; |
428 | 2569 |
2570 /* Find the buffer position at the end of the line. */ | |
826 | 2571 byte_next_charpos = |
2572 byte_find_next_newline_no_quit (b, data.byte_charpos, 1); | |
2573 if (BYTE_BUF_FETCH_CHAR (b, prev_bytebpos (b, byte_next_charpos)) | |
428 | 2574 == '\n') |
826 | 2575 DEC_BYTEBPOS (b, byte_next_charpos); |
428 | 2576 |
2577 /* If the cursor is somewhere in the elided text make | |
4187 | 2578 sure that the cursor gets drawn appropriately. */ |
428 | 2579 if (data.cursor_type == CURSOR_ON |
826 | 2580 && (data.byte_cursor_charpos >= data.byte_charpos && |
2581 data.byte_cursor_charpos < byte_next_charpos)) | |
428 | 2582 { |
2583 data.cursor_type = NEXT_CURSOR; | |
2584 } | |
2585 | |
2586 /* We won't be adding a truncation or continuation glyph | |
4187 | 2587 so give up the room allocated for them. */ |
819 | 2588 data.max_pixpos += data.end_glyph_width; |
428 | 2589 |
2590 if (!NILP (b->selective_display_ellipses)) | |
2591 { | |
2592 /* We don't propagate anything from the invisible | |
4187 | 2593 text glyph if it fails to fit. This is |
2594 intentional. */ | |
428 | 2595 struct glyph_block gb; |
2596 | |
2597 gb.extent = Qnil; | |
2598 gb.glyph = Vinvisible_text_glyph; | |
2599 add_glyph_rune (&data, &gb, BEGIN_GLYPHS, 1, | |
2600 GLYPH_CACHEL (w, INVIS_GLYPH_INDEX)); | |
2601 } | |
2602 | |
2603 /* Set the buffer position to the end of the line. We | |
4187 | 2604 need to do this before potentially adding a newline |
2605 so that the cursor flag will get set correctly (if | |
2606 needed). */ | |
826 | 2607 data.byte_charpos = byte_next_charpos; |
428 | 2608 |
2609 if (NILP (b->selective_display_ellipses) | |
826 | 2610 || data.byte_cursor_charpos == byte_next_charpos) |
428 | 2611 { |
2612 /* We have to at least add a newline character so | |
4187 | 2613 that the cursor shows up properly. */ |
428 | 2614 data.ch = '\n'; |
2615 data.blank_width = DEVMETH (d, eol_cursor_width, ()); | |
2616 data.findex = DEFAULT_INDEX; | |
2617 data.start_col = 0; | |
2618 data.start_col_xoffset = 0; | |
826 | 2619 data.byte_start_col_enabled = 0; |
428 | 2620 |
867 | 2621 add_ichar_rune (&data); |
428 | 2622 } |
2623 | |
2624 /* This had better be a newline but doing it this way | |
4187 | 2625 we'll see obvious incorrect results if it isn't. No |
2626 need to abort here. */ | |
826 | 2627 data.ch = BYTE_BUF_FETCH_CHAR (b, data.byte_charpos); |
428 | 2628 |
2629 goto done; | |
2630 } | |
2631 | |
2632 /* If the current character is considered to be printable, then | |
4187 | 2633 just add it. */ |
428 | 2634 else if (data.ch >= printable_min) |
2635 { | |
867 | 2636 *prop = add_ichar_rune (&data); |
428 | 2637 if (*prop) |
2638 goto done; | |
2639 } | |
2640 | |
2641 /* If the current character is a tab, determine the next tab | |
4187 | 2642 starting position and add a blank rune which extends from the |
2643 current pixel position to that starting position. */ | |
428 | 2644 else if (data.ch == '\t') |
2645 { | |
2646 int tab_start_pixpos = data.pixpos; | |
2647 int next_tab_start; | |
2648 int char_tab_width; | |
2649 int prop_width = 0; | |
2650 | |
2651 if (data.start_col > 1) | |
434 | 2652 tab_start_pixpos -= (space_width (w) * (data.start_col - 1)) |
428 | 2653 + data.start_col_xoffset; |
2654 | |
2655 next_tab_start = | |
2656 next_tab_position (w, tab_start_pixpos, | |
2657 dl->bounds.left_in + | |
2658 data.hscroll_glyph_width_adjust); | |
2659 if (next_tab_start > data.max_pixpos) | |
2660 { | |
2661 prop_width = next_tab_start - data.max_pixpos; | |
2662 next_tab_start = data.max_pixpos; | |
2663 } | |
2664 data.blank_width = next_tab_start - data.pixpos; | |
2665 char_tab_width = | |
2666 (next_tab_start - tab_start_pixpos) / space_width (w); | |
2667 | |
2668 *prop = add_blank_rune (&data, w, char_tab_width); | |
2669 | |
2670 /* add_blank_rune is only supposed to be called with | |
4187 | 2671 sizes guaranteed to fit in the available space. */ |
428 | 2672 assert (!(*prop)); |
2673 | |
2674 if (prop_width) | |
2675 { | |
2676 struct prop_block pb; | |
2677 *prop = Dynarr_new (prop_block); | |
2678 | |
2679 pb.type = PROP_BLANK; | |
2680 pb.data.p_blank.width = prop_width; | |
2681 pb.data.p_blank.findex = data.findex; | |
2682 Dynarr_add (*prop, pb); | |
2683 | |
2684 goto done; | |
2685 } | |
2686 } | |
2687 | |
2688 /* If character is a control character, pass it off to | |
4187 | 2689 add_control_char_runes. |
428 | 2690 |
2691 The is_*() routines have undefined results on | |
2692 arguments outside of the range [-1, 255]. (This | |
2693 often bites people who carelessly use `char' instead | |
2694 of `unsigned char'.) | |
2695 */ | |
867 | 2696 else if (data.ch < 0x100 && iscntrl ((Ibyte) data.ch)) |
428 | 2697 { |
2698 *prop = add_control_char_runes (&data, b); | |
2699 | |
2700 if (*prop) | |
2701 goto done; | |
2702 } | |
2703 | |
2704 /* If the character is above the ASCII range and we have not | |
4187 | 2705 already handled it, then print it as an octal number. */ |
428 | 2706 else if (data.ch >= 0200) |
2707 { | |
2708 *prop = add_octal_runes (&data); | |
2709 | |
2710 if (*prop) | |
2711 goto done; | |
2712 } | |
2713 | |
2714 /* Assume the current character is considered to be printable, | |
4187 | 2715 then just add it. */ |
428 | 2716 else |
2717 { | |
867 | 2718 *prop = add_ichar_rune (&data); |
428 | 2719 if (*prop) |
2720 goto done; | |
2721 } | |
2722 | |
826 | 2723 INC_BYTEBPOS (b, data.byte_charpos); |
428 | 2724 } |
2725 } | |
2726 | |
2727 done: | |
2728 | |
2729 /* Determine the starting point of the next line if we did not hit the | |
2730 end of the buffer. */ | |
826 | 2731 if (data.byte_charpos < BYTE_BUF_ZV (b) |
428 | 2732 && (active_minibuffer || !NILP (synch_minibuffers_value))) |
2733 { | |
2734 /* #### This check is not correct. If the line terminated | |
2735 due to a begin-glyph or end-glyph hitting window-end, then | |
826 | 2736 data.ch will not point to the character at data.byte_charpos. If |
428 | 2737 you make the two changes mentioned at the top of this loop, |
2738 you should be able to say '(if (*prop))'. That should also | |
826 | 2739 make it possible to eliminate the data.byte_charpos < BYTE_BUF_ZV (b) |
428 | 2740 check. */ |
2741 | |
2742 /* The common case is that the line ended because we hit a newline. | |
4187 | 2743 In that case, the next character is just the next buffer |
2744 position. */ | |
428 | 2745 if (data.ch == '\n') |
2746 { | |
2747 /* If data.start_col_enabled is still true, then the window is | |
4187 | 2748 scrolled far enough so that nothing on this line is visible. |
2749 We need to stick a truncation glyph at the beginning of the | |
2750 line in that case unless the line is completely blank. */ | |
826 | 2751 if (data.byte_start_col_enabled) |
428 | 2752 { |
2753 if (data.cursor_type == CURSOR_ON) | |
2754 { | |
826 | 2755 if (data.byte_cursor_charpos >= byte_start_pos |
2756 && data.byte_cursor_charpos <= data.byte_charpos) | |
2757 data.byte_cursor_charpos = data.byte_charpos; | |
428 | 2758 } |
2759 data.findex = DEFAULT_INDEX; | |
2760 data.start_col = 0; | |
826 | 2761 data.byte_start_col_enabled = 0; |
2762 | |
2763 if (data.byte_charpos != byte_start_pos) | |
428 | 2764 { |
2765 struct glyph_block gb; | |
2766 | |
2767 gb.extent = Qnil; | |
2768 gb.glyph = Vhscroll_glyph; | |
2769 add_glyph_rune (&data, &gb, BEGIN_GLYPHS, 0, | |
2770 GLYPH_CACHEL (w, HSCROLL_GLYPH_INDEX)); | |
2771 } | |
2772 else | |
2773 { | |
2774 /* This duplicates code down below to add a newline to | |
4187 | 2775 the end of an otherwise empty line.*/ |
428 | 2776 data.ch = '\n'; |
2777 data.blank_width = DEVMETH (d, eol_cursor_width, ()); | |
2778 | |
867 | 2779 add_ichar_rune (&data); |
428 | 2780 } |
2781 } | |
2782 | |
826 | 2783 INC_BYTEBPOS (b, data.byte_charpos); |
428 | 2784 } |
2785 | |
2786 /* Otherwise we have a buffer line which cannot fit on one display | |
4187 | 2787 line. */ |
428 | 2788 else |
2789 { | |
2790 struct glyph_block gb; | |
2791 struct glyph_cachel *cachel; | |
2792 | |
2793 /* If the line is to be truncated then we actually have to look | |
4187 | 2794 for the next newline. We also add the end-of-line glyph which |
2795 we know will fit because we adjusted the right border before | |
2796 we starting laying out the line. */ | |
819 | 2797 data.max_pixpos += data.end_glyph_width; |
428 | 2798 data.findex = DEFAULT_INDEX; |
2799 gb.extent = Qnil; | |
2800 | |
2801 if (truncate_win) | |
2802 { | |
826 | 2803 Bytebpos byte_pos; |
428 | 2804 |
2805 /* Now find the start of the next line. */ | |
826 | 2806 byte_pos = byte_find_next_newline_no_quit (b, data.byte_charpos, 1); |
428 | 2807 |
2808 /* If the cursor is past the truncation line then we | |
4187 | 2809 make it appear on the truncation glyph. If we've hit |
2810 the end of the buffer then we also make the cursor | |
2811 appear unless eob is immediately preceded by a | |
2812 newline. In that case the cursor should actually | |
2813 appear on the next line. */ | |
428 | 2814 if (data.cursor_type == CURSOR_ON |
826 | 2815 && data.byte_cursor_charpos >= data.byte_charpos |
2816 && (data.byte_cursor_charpos < byte_pos || | |
2817 (byte_pos == BYTE_BUF_ZV (b) | |
2818 && (byte_pos == BYTE_BUF_BEGV (b) | |
2819 || (BYTE_BUF_FETCH_CHAR (b, prev_bytebpos (b, byte_pos)) | |
428 | 2820 != '\n'))))) |
826 | 2821 data.byte_cursor_charpos = byte_pos; |
428 | 2822 else |
2823 data.cursor_type = NO_CURSOR; | |
2824 | |
826 | 2825 data.byte_charpos = byte_pos; |
428 | 2826 gb.glyph = Vtruncation_glyph; |
2827 cachel = GLYPH_CACHEL (w, TRUN_GLYPH_INDEX); | |
2828 } | |
2829 else | |
2830 { | |
2831 /* The cursor can never be on the continuation glyph. */ | |
2832 data.cursor_type = NO_CURSOR; | |
2833 | |
826 | 2834 /* data.byte_charpos is already at the start of the next line. */ |
428 | 2835 |
442 | 2836 dl->line_continuation = 1; |
428 | 2837 gb.glyph = Vcontinuation_glyph; |
2838 cachel = GLYPH_CACHEL (w, CONT_GLYPH_INDEX); | |
2839 } | |
2840 | |
442 | 2841 add_glyph_rune (&data, &gb, BEGIN_GLYPHS, 0, cachel); |
428 | 2842 |
826 | 2843 if (truncate_win && data.byte_charpos == BYTE_BUF_ZV (b) |
2844 && BYTE_BUF_FETCH_CHAR (b, prev_bytebpos (b, BYTE_BUF_ZV (b))) != '\n') | |
428 | 2845 /* #### Damn this losing shit. */ |
826 | 2846 data.byte_charpos++; |
428 | 2847 } |
2848 } | |
2849 else if ((active_minibuffer || !NILP (synch_minibuffers_value)) | |
826 | 2850 && (!echo_area_active (f) || data.byte_charpos == BYTE_BUF_ZV (b))) |
428 | 2851 { |
2852 /* We need to add a marker to the end of the line since there is no | |
4187 | 2853 newline character in order for the cursor to get drawn. We label |
2854 it as a newline so that it gets handled correctly by the | |
2855 whitespace routines below. */ | |
428 | 2856 |
2857 data.ch = '\n'; | |
2858 data.blank_width = DEVMETH (d, eol_cursor_width, ()); | |
2859 data.findex = DEFAULT_INDEX; | |
2860 data.start_col = 0; | |
2861 data.start_col_xoffset = 0; | |
826 | 2862 data.byte_start_col_enabled = 0; |
428 | 2863 |
2864 data.max_pixpos += data.blank_width; | |
867 | 2865 add_ichar_rune (&data); |
428 | 2866 data.max_pixpos -= data.blank_width; |
2867 | |
2868 /* #### urk! Chuck, this shit is bad news. Going around | |
2869 manipulating invalid positions is guaranteed to result in | |
2870 trouble sooner or later. */ | |
826 | 2871 data.byte_charpos = BYTE_BUF_ZV (b) + 1; |
428 | 2872 } |
2873 | |
2874 /* Calculate left whitespace boundary. */ | |
2875 { | |
2876 int elt = 0; | |
2877 | |
2878 /* Whitespace past a newline is considered right whitespace. */ | |
2879 while (elt < Dynarr_length (db->runes)) | |
2880 { | |
2881 struct rune *rb = Dynarr_atp (db->runes, elt); | |
2882 | |
2883 if ((rb->type == RUNE_CHAR && rb->object.chr.ch == ' ') | |
2884 || rb->type == RUNE_BLANK) | |
2885 { | |
2886 dl->bounds.left_white += rb->width; | |
2887 elt++; | |
2888 } | |
2889 else | |
2890 elt = Dynarr_length (db->runes); | |
2891 } | |
2892 } | |
2893 | |
2894 /* Calculate right whitespace boundary. */ | |
2895 { | |
2896 int elt = Dynarr_length (db->runes) - 1; | |
2897 int done = 0; | |
2898 | |
2899 while (!done && elt >= 0) | |
2900 { | |
2901 struct rune *rb = Dynarr_atp (db->runes, elt); | |
2902 | |
2903 if (!(rb->type == RUNE_CHAR && rb->object.chr.ch < 0x100 | |
2904 && isspace (rb->object.chr.ch)) | |
2905 && !rb->type == RUNE_BLANK) | |
2906 { | |
2907 dl->bounds.right_white = rb->xpos + rb->width; | |
2908 done = 1; | |
2909 } | |
2910 | |
2911 elt--; | |
2912 | |
2913 } | |
2914 | |
2915 /* The line is blank so everything is considered to be right | |
2916 whitespace. */ | |
2917 if (!done) | |
2918 dl->bounds.right_white = dl->bounds.left_in; | |
2919 } | |
2920 | |
2921 /* Set the display blocks bounds. */ | |
2922 db->start_pos = dl->bounds.left_in; | |
2923 if (Dynarr_length (db->runes)) | |
2924 { | |
4844
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4815
diff
changeset
|
2925 struct rune *rb = Dynarr_lastp (db->runes); |
428 | 2926 |
2927 db->end_pos = rb->xpos + rb->width; | |
2928 } | |
2929 else | |
2930 db->end_pos = dl->bounds.right_white; | |
2931 | |
819 | 2932 calculate_baseline (&data); |
428 | 2933 |
2934 dl->ascent = data.new_ascent; | |
2935 dl->descent = data.new_descent; | |
2936 | |
2937 { | |
2938 unsigned short ascent = (unsigned short) XINT (w->minimum_line_ascent); | |
2939 | |
2940 if (dl->ascent < ascent) | |
2941 dl->ascent = ascent; | |
2942 } | |
2943 { | |
2944 unsigned short descent = (unsigned short) XINT (w->minimum_line_descent); | |
2945 | |
2946 if (dl->descent < descent) | |
2947 dl->descent = descent; | |
2948 } | |
2949 | |
819 | 2950 calculate_yoffset (dl, db); |
2951 | |
428 | 2952 dl->cursor_elt = data.cursor_x; |
2953 /* #### lossage lossage lossage! Fix this shit! */ | |
826 | 2954 if (data.byte_charpos > BYTE_BUF_ZV (b)) |
2955 dl->end_charpos = BUF_ZV (b); | |
428 | 2956 else |
826 | 2957 dl->end_charpos = bytebpos_to_charbpos (b, data.byte_charpos) - 1; |
428 | 2958 if (truncate_win) |
826 | 2959 data.dl->num_chars = column_at_point (b, dl->end_charpos, 0); |
428 | 2960 else |
2961 /* This doesn't correctly take into account tabs and control | |
2962 characters but if the window isn't being truncated then this | |
2963 value isn't going to end up being used anyhow. */ | |
826 | 2964 data.dl->num_chars = dl->end_charpos - dl->charpos; |
428 | 2965 |
2966 /* #### handle horizontally scrolled line with text none of which | |
2967 was actually laid out. */ | |
2968 | |
2969 /* #### handle any remainder of overlay arrow */ | |
2970 | |
2971 if (*prop == ADD_FAILED) | |
2972 *prop = NULL; | |
2973 | |
2974 if (truncate_win && *prop) | |
2975 { | |
2976 Dynarr_free (*prop); | |
2977 *prop = NULL; | |
2978 } | |
2979 | |
2980 extent_fragment_delete (data.ef); | |
2981 | |
2982 /* #### If we started at EOB, then make sure we return a value past | |
2983 it so that regenerate_window will exit properly. This is bogus. | |
2984 The main loop should get fixed so that it isn't necessary to call | |
2985 this function if we are already at EOB. */ | |
2986 | |
826 | 2987 if (data.byte_charpos == BYTE_BUF_ZV (b) && byte_start_pos == BYTE_BUF_ZV (b)) |
2988 return data.byte_charpos + 1; /* Yuck! */ | |
428 | 2989 else |
826 | 2990 return data.byte_charpos; |
428 | 2991 } |
2992 | |
2993 /* Display the overlay arrow at the beginning of the given line. */ | |
2994 | |
2995 static int | |
2996 create_overlay_glyph_block (struct window *w, struct display_line *dl) | |
2997 { | |
2998 struct frame *f = XFRAME (w->frame); | |
2999 struct device *d = XDEVICE (f->device); | |
3000 pos_data data; | |
3001 | |
3002 /* If Voverlay_arrow_string isn't valid then just fail silently. */ | |
3003 if (!STRINGP (Voverlay_arrow_string) && !GLYPHP (Voverlay_arrow_string)) | |
3004 return 0; | |
3005 | |
3006 xzero (data); | |
3007 data.ef = NULL; | |
3008 data.d = d; | |
793 | 3009 data.window = wrap_window (w); |
428 | 3010 data.db = get_display_block_from_line (dl, OVERWRITE); |
3011 data.dl = dl; | |
3012 data.pixpos = dl->bounds.left_in; | |
3013 data.max_pixpos = dl->bounds.right_in; | |
3014 data.cursor_type = NO_CURSOR; | |
3015 data.cursor_x = -1; | |
3016 data.findex = DEFAULT_INDEX; | |
3017 data.last_charset = Qunbound; | |
3018 data.last_findex = DEFAULT_INDEX; | |
3019 data.result_str = Qnil; | |
3020 data.string = Qnil; | |
3021 | |
3022 Dynarr_reset (data.db->runes); | |
3023 | |
3024 if (STRINGP (Voverlay_arrow_string)) | |
3025 { | |
867 | 3026 add_ibyte_string_runes |
428 | 3027 (&data, |
3028 XSTRING_DATA (Voverlay_arrow_string), | |
3029 XSTRING_LENGTH (Voverlay_arrow_string), | |
793 | 3030 1, 0); |
428 | 3031 } |
3032 else if (GLYPHP (Voverlay_arrow_string)) | |
3033 { | |
3034 struct glyph_block gb; | |
3035 | |
3036 gb.glyph = Voverlay_arrow_string; | |
3037 gb.extent = Qnil; | |
3038 add_glyph_rune (&data, &gb, BEGIN_GLYPHS, 0, 0); | |
3039 } | |
4187 | 3040 |
428 | 3041 if (data.max_pixmap_height) |
3042 { | |
3043 int height = data.new_ascent + data.new_descent; | |
3044 int pix_ascent, pix_descent; | |
4187 | 3045 |
428 | 3046 pix_descent = data.max_pixmap_height * data.new_descent / height; |
3047 pix_ascent = data.max_pixmap_height - pix_descent; | |
819 | 3048 calculate_baseline (&data); |
428 | 3049 |
3050 data.new_ascent = max (data.new_ascent, pix_ascent); | |
3051 data.new_descent = max (data.new_descent, pix_descent); | |
3052 } | |
3053 | |
3054 dl->ascent = data.new_ascent; | |
3055 dl->descent = data.new_descent; | |
3056 | |
3057 data.db->start_pos = dl->bounds.left_in; | |
3058 data.db->end_pos = data.pixpos; | |
3059 | |
819 | 3060 calculate_yoffset (dl, data.db); |
3061 | |
428 | 3062 return data.pixpos - dl->bounds.left_in; |
3063 } | |
3064 | |
3065 /* Add a type of glyph to a margin display block. */ | |
3066 | |
3067 static int | |
3068 add_margin_runes (struct display_line *dl, struct display_block *db, int start, | |
3069 int count, enum glyph_layout layout, int side, Lisp_Object window) | |
3070 { | |
3071 glyph_block_dynarr *gbd = (side == LEFT_GLYPHS | |
3072 ? dl->left_glyphs | |
3073 : dl->right_glyphs); | |
3074 int elt, end; | |
3075 int reverse; | |
442 | 3076 struct window *w = XWINDOW (window); |
3077 struct frame *f = XFRAME (w->frame); | |
3078 struct device *d = XDEVICE (f->device); | |
3079 pos_data data; | |
3080 | |
3081 xzero (data); | |
3082 data.d = d; | |
3083 data.window = window; | |
3084 data.db = db; | |
3085 data.dl = dl; | |
3086 data.pixpos = start; | |
3087 data.cursor_type = NO_CURSOR; | |
3088 data.cursor_x = -1; | |
3089 data.last_charset = Qunbound; | |
3090 data.last_findex = DEFAULT_INDEX; | |
3091 data.result_str = Qnil; | |
3092 data.string = Qnil; | |
3093 data.new_ascent = dl->ascent; | |
3094 data.new_descent = dl->descent; | |
428 | 3095 |
3096 if ((layout == GL_WHITESPACE && side == LEFT_GLYPHS) | |
3097 || (layout == GL_INSIDE_MARGIN && side == RIGHT_GLYPHS)) | |
3098 { | |
3099 reverse = 1; | |
3100 elt = Dynarr_length (gbd) - 1; | |
3101 end = 0; | |
3102 } | |
3103 else | |
3104 { | |
3105 reverse = 0; | |
3106 elt = 0; | |
3107 end = Dynarr_length (gbd); | |
3108 } | |
3109 | |
3110 while (count && ((!reverse && elt < end) || (reverse && elt >= end))) | |
3111 { | |
3112 struct glyph_block *gb = Dynarr_atp (gbd, elt); | |
3113 | |
3114 if (NILP (gb->extent)) | |
2500 | 3115 ABORT (); /* these should have been handled in add_glyph_rune */ |
428 | 3116 |
3117 if (gb->active && | |
3118 ((side == LEFT_GLYPHS && | |
3119 extent_begin_glyph_layout (XEXTENT (gb->extent)) == layout) | |
3120 || (side == RIGHT_GLYPHS && | |
3121 extent_end_glyph_layout (XEXTENT (gb->extent)) == layout))) | |
3122 { | |
442 | 3123 data.findex = gb->findex; |
3124 data.max_pixpos = data.pixpos + gb->width; | |
3125 add_glyph_rune (&data, gb, side, 0, NULL); | |
428 | 3126 count--; |
3127 gb->active = 0; | |
3128 } | |
3129 | |
3130 (reverse ? elt-- : elt++); | |
3131 } | |
3132 | |
819 | 3133 calculate_baseline (&data); |
442 | 3134 |
3135 dl->ascent = data.new_ascent; | |
3136 dl->descent = data.new_descent; | |
3137 | |
819 | 3138 calculate_yoffset (dl, data.db); |
3139 | |
442 | 3140 return data.pixpos; |
428 | 3141 } |
3142 | |
3143 /* Add a blank to a margin display block. */ | |
3144 | |
3145 static void | |
2286 | 3146 add_margin_blank (struct display_line *UNUSED (dl), struct display_block *db, |
428 | 3147 struct window *w, int xpos, int width, int side) |
3148 { | |
3149 struct rune rb; | |
3150 | |
3151 rb.findex = (side == LEFT_GLYPHS | |
3152 ? get_builtin_face_cache_index (w, Vleft_margin_face) | |
3153 : get_builtin_face_cache_index (w, Vright_margin_face)); | |
3154 rb.xpos = xpos; | |
3155 rb.width = width; | |
826 | 3156 rb.charpos = -1; |
428 | 3157 rb.endpos = 0; |
3158 rb.type = RUNE_BLANK; | |
3159 rb.cursor_type = CURSOR_OFF; | |
3160 | |
3161 Dynarr_add (db->runes, rb); | |
3162 } | |
3163 | |
3164 /* Display glyphs in the left outside margin, left inside margin and | |
3165 left whitespace area. */ | |
3166 | |
3167 static void | |
3168 create_left_glyph_block (struct window *w, struct display_line *dl, | |
3169 int overlay_width) | |
3170 { | |
3171 Lisp_Object window; | |
3172 | |
3173 int use_overflow = (NILP (w->use_left_overflow) ? 0 : 1); | |
3174 int elt, end_xpos; | |
3175 int out_end, in_out_start, in_in_end, white_out_start, white_in_start; | |
3176 int out_cnt, in_out_cnt, in_in_cnt, white_out_cnt, white_in_cnt; | |
3177 int left_in_start = dl->bounds.left_in; | |
3178 int left_in_end = dl->bounds.left_in + overlay_width; | |
3179 | |
3180 struct display_block *odb, *idb; | |
3181 | |
793 | 3182 window = wrap_window (w); |
428 | 3183 |
3184 /* We have to add the glyphs to the line in the order outside, | |
3185 inside, whitespace. However the precedence dictates that we | |
3186 determine how many will fit in the reverse order. */ | |
3187 | |
3188 /* Determine how many whitespace glyphs we can display and where | |
3189 they should start. */ | |
3190 white_in_start = dl->bounds.left_white; | |
3191 white_out_start = left_in_start; | |
3192 white_out_cnt = white_in_cnt = 0; | |
3193 elt = 0; | |
3194 | |
3195 while (elt < Dynarr_length (dl->left_glyphs)) | |
3196 { | |
3197 struct glyph_block *gb = Dynarr_atp (dl->left_glyphs, elt); | |
3198 | |
3199 if (NILP (gb->extent)) | |
2500 | 3200 ABORT (); /* these should have been handled in add_glyph_rune */ |
428 | 3201 |
3202 if (extent_begin_glyph_layout (XEXTENT (gb->extent)) == GL_WHITESPACE) | |
3203 { | |
3204 int width; | |
3205 | |
438 | 3206 width = glyph_width (gb->glyph, window); |
428 | 3207 |
3208 if (white_in_start - width >= left_in_end) | |
3209 { | |
3210 white_in_cnt++; | |
3211 white_in_start -= width; | |
3212 gb->width = width; | |
3213 gb->active = 1; | |
3214 } | |
3215 else if (use_overflow | |
3216 && (white_out_start - width > dl->bounds.left_out)) | |
3217 { | |
3218 white_out_cnt++; | |
3219 white_out_start -= width; | |
3220 gb->width = width; | |
3221 gb->active = 1; | |
3222 } | |
3223 else | |
3224 gb->active = 0; | |
3225 } | |
3226 | |
3227 elt++; | |
3228 } | |
3229 | |
3230 /* Determine how many inside margin glyphs we can display and where | |
3231 they should start. The inside margin glyphs get whatever space | |
3232 is left after the whitespace glyphs have been displayed. These | |
3233 are tricky to calculate since if we decide to use the overflow | |
3234 area we basically have to start over. So for these we build up a | |
3235 list of just the inside margin glyphs and manipulate it to | |
3236 determine the needed info. */ | |
3237 { | |
3238 glyph_block_dynarr *ib; | |
3239 int avail_in, avail_out; | |
3240 int done = 0; | |
3241 int marker = 0; | |
3242 int used_in, used_out; | |
3243 | |
3244 elt = 0; | |
3245 used_in = used_out = 0; | |
3246 ib = Dynarr_new (glyph_block); | |
3247 while (elt < Dynarr_length (dl->left_glyphs)) | |
3248 { | |
3249 struct glyph_block *gb = Dynarr_atp (dl->left_glyphs, elt); | |
3250 | |
3251 if (NILP (gb->extent)) | |
2500 | 3252 ABORT (); /* these should have been handled in add_glyph_rune */ |
428 | 3253 |
3254 if (extent_begin_glyph_layout (XEXTENT (gb->extent)) == | |
3255 GL_INSIDE_MARGIN) | |
3256 { | |
438 | 3257 gb->width = glyph_width (gb->glyph, window); |
428 | 3258 used_in += gb->width; |
3259 Dynarr_add (ib, *gb); | |
3260 } | |
3261 | |
3262 elt++; | |
3263 } | |
3264 | |
3265 if (white_out_cnt) | |
3266 avail_in = 0; | |
3267 else | |
3268 { | |
3269 avail_in = white_in_start - left_in_end; | |
3270 if (avail_in < 0) | |
3271 avail_in = 0; | |
3272 } | |
3273 | |
3274 if (!use_overflow) | |
3275 avail_out = 0; | |
3276 else | |
3277 avail_out = white_out_start - dl->bounds.left_out; | |
3278 | |
3279 marker = 0; | |
3280 while (!done && marker < Dynarr_length (ib)) | |
3281 { | |
3282 int width = Dynarr_atp (ib, marker)->width; | |
3283 | |
3284 /* If everything now fits in the available inside margin | |
4187 | 3285 space, we're done. */ |
428 | 3286 if (used_in <= avail_in) |
3287 done = 1; | |
3288 else | |
3289 { | |
3290 /* Otherwise see if we have room to move a glyph to the | |
4187 | 3291 outside. */ |
428 | 3292 if (used_out + width <= avail_out) |
3293 { | |
3294 used_out += width; | |
3295 used_in -= width; | |
3296 } | |
3297 else | |
3298 done = 1; | |
3299 } | |
3300 | |
3301 if (!done) | |
3302 marker++; | |
3303 } | |
3304 | |
3305 /* At this point we now know that everything from marker on goes in | |
3306 the inside margin and everything before it goes in the outside | |
3307 margin. The stuff going into the outside margin is guaranteed | |
3308 to fit, but we may have to trim some stuff from the inside. */ | |
3309 | |
3310 in_in_end = left_in_end; | |
3311 in_out_start = white_out_start; | |
3312 in_out_cnt = in_in_cnt = 0; | |
3313 | |
3314 Dynarr_free (ib); | |
3315 elt = 0; | |
3316 while (elt < Dynarr_length (dl->left_glyphs)) | |
3317 { | |
3318 struct glyph_block *gb = Dynarr_atp (dl->left_glyphs, elt); | |
3319 | |
3320 if (NILP (gb->extent)) | |
2500 | 3321 ABORT (); /* these should have been handled in add_glyph_rune */ |
428 | 3322 |
3323 if (extent_begin_glyph_layout (XEXTENT (gb->extent)) == | |
3324 GL_INSIDE_MARGIN) | |
3325 { | |
438 | 3326 int width = glyph_width (gb->glyph, window); |
428 | 3327 |
3328 if (used_out) | |
3329 { | |
3330 in_out_cnt++; | |
3331 in_out_start -= width; | |
3332 gb->width = width; | |
3333 gb->active = 1; | |
3334 used_out -= width; | |
3335 } | |
3336 else if (in_in_end + width < white_in_start) | |
3337 { | |
3338 in_in_cnt++; | |
3339 in_in_end += width; | |
3340 gb->width = width; | |
3341 gb->active = 1; | |
3342 } | |
3343 else | |
3344 gb->active = 0; | |
3345 } | |
3346 | |
3347 elt++; | |
3348 } | |
3349 } | |
3350 | |
3351 /* Determine how many outside margin glyphs we can display. They | |
3352 always start at the left outside margin and can only use the | |
3353 outside margin space. */ | |
3354 out_end = dl->bounds.left_out; | |
3355 out_cnt = 0; | |
3356 elt = 0; | |
3357 | |
3358 while (elt < Dynarr_length (dl->left_glyphs)) | |
3359 { | |
3360 struct glyph_block *gb = Dynarr_atp (dl->left_glyphs, elt); | |
3361 | |
3362 if (NILP (gb->extent)) | |
2500 | 3363 ABORT (); /* these should have been handled in add_glyph_rune */ |
428 | 3364 |
3365 if (extent_begin_glyph_layout (XEXTENT (gb->extent)) == | |
3366 GL_OUTSIDE_MARGIN) | |
3367 { | |
438 | 3368 int width = glyph_width (gb->glyph, window); |
428 | 3369 |
3370 if (out_end + width <= in_out_start) | |
3371 { | |
3372 out_cnt++; | |
3373 out_end += width; | |
3374 gb->width = width; | |
3375 gb->active = 1; | |
3376 } | |
3377 else | |
3378 gb->active = 0; | |
3379 } | |
3380 | |
3381 elt++; | |
3382 } | |
3383 | |
3384 /* Now that we know where everything goes, we add the glyphs as | |
3385 runes to the appropriate display blocks. */ | |
3386 if (out_cnt || in_out_cnt || white_out_cnt) | |
3387 { | |
3388 odb = get_display_block_from_line (dl, LEFT_OUTSIDE_MARGIN); | |
3389 odb->start_pos = dl->bounds.left_out; | |
3390 /* #### We should stop adding a blank to account for the space | |
4187 | 3391 between the end of the glyphs and the margin and instead set |
3392 this accordingly. */ | |
428 | 3393 odb->end_pos = dl->bounds.left_in; |
3394 Dynarr_reset (odb->runes); | |
3395 } | |
3396 else | |
3397 odb = 0; | |
3398 | |
3399 if (in_in_cnt || white_in_cnt) | |
3400 { | |
3401 idb = get_display_block_from_line (dl, LEFT_INSIDE_MARGIN); | |
3402 idb->start_pos = dl->bounds.left_in; | |
3403 /* #### See above comment for odb->end_pos */ | |
3404 idb->end_pos = dl->bounds.left_white; | |
3405 Dynarr_reset (idb->runes); | |
3406 } | |
3407 else | |
3408 idb = 0; | |
3409 | |
3410 /* First add the outside margin glyphs. */ | |
3411 if (out_cnt) | |
3412 end_xpos = add_margin_runes (dl, odb, dl->bounds.left_out, out_cnt, | |
3413 GL_OUTSIDE_MARGIN, LEFT_GLYPHS, window); | |
3414 else | |
3415 end_xpos = dl->bounds.left_out; | |
3416 | |
3417 /* There may be blank space between the outside margin glyphs and | |
3418 the inside margin glyphs. If so, add a blank. */ | |
3419 if (in_out_cnt && (in_out_start - end_xpos)) | |
3420 { | |
3421 add_margin_blank (dl, odb, w, end_xpos, in_out_start - end_xpos, | |
3422 LEFT_GLYPHS); | |
3423 } | |
3424 | |
3425 /* Next add the inside margin glyphs which are actually in the | |
3426 outside margin. */ | |
3427 if (in_out_cnt) | |
3428 { | |
3429 end_xpos = add_margin_runes (dl, odb, in_out_start, in_out_cnt, | |
3430 GL_INSIDE_MARGIN, LEFT_GLYPHS, window); | |
3431 } | |
3432 | |
3433 /* If we didn't add any inside margin glyphs to the outside margin, | |
3434 but are adding whitespace glyphs, then we need to add a blank | |
3435 here. */ | |
3436 if (!in_out_cnt && white_out_cnt && (white_out_start - end_xpos)) | |
3437 { | |
3438 add_margin_blank (dl, odb, w, end_xpos, white_out_start - end_xpos, | |
3439 LEFT_GLYPHS); | |
3440 } | |
3441 | |
3442 /* Next add the whitespace margin glyphs which are actually in the | |
3443 outside margin. */ | |
3444 if (white_out_cnt) | |
3445 { | |
3446 end_xpos = add_margin_runes (dl, odb, white_out_start, white_out_cnt, | |
3447 GL_WHITESPACE, LEFT_GLYPHS, window); | |
3448 } | |
3449 | |
3450 /* We take care of clearing between the end of the glyphs and the | |
3451 start of the inside margin for lines which have glyphs. */ | |
3452 if (odb && (left_in_start - end_xpos)) | |
3453 { | |
3454 add_margin_blank (dl, odb, w, end_xpos, left_in_start - end_xpos, | |
3455 LEFT_GLYPHS); | |
3456 } | |
3457 | |
3458 /* Next add the inside margin glyphs which are actually in the | |
3459 inside margin. */ | |
3460 if (in_in_cnt) | |
3461 { | |
3462 end_xpos = add_margin_runes (dl, idb, left_in_end, in_in_cnt, | |
3463 GL_INSIDE_MARGIN, LEFT_GLYPHS, window); | |
3464 } | |
3465 else | |
3466 end_xpos = left_in_end; | |
3467 | |
3468 /* Make sure that the area between the end of the inside margin | |
3469 glyphs and the whitespace glyphs is cleared. */ | |
3470 if (idb && (white_in_start - end_xpos > 0)) | |
3471 { | |
3472 add_margin_blank (dl, idb, w, end_xpos, white_in_start - end_xpos, | |
3473 LEFT_GLYPHS); | |
3474 } | |
3475 | |
3476 /* Next add the whitespace margin glyphs which are actually in the | |
3477 inside margin. */ | |
3478 if (white_in_cnt) | |
3479 { | |
3480 add_margin_runes (dl, idb, white_in_start, white_in_cnt, GL_WHITESPACE, | |
3481 LEFT_GLYPHS, window); | |
3482 } | |
3483 | |
3484 /* Whitespace glyphs always end right next to the text block so | |
3485 there is nothing we have to make sure is cleared after them. */ | |
3486 } | |
3487 | |
3488 /* Display glyphs in the right outside margin, right inside margin and | |
3489 right whitespace area. */ | |
3490 | |
3491 static void | |
3492 create_right_glyph_block (struct window *w, struct display_line *dl) | |
3493 { | |
3494 Lisp_Object window; | |
3495 | |
3496 int use_overflow = (NILP (w->use_right_overflow) ? 0 : 1); | |
3497 int elt, end_xpos; | |
3498 int out_start, in_out_end, in_in_start, white_out_end, white_in_end; | |
3499 int out_cnt, in_out_cnt, in_in_cnt, white_out_cnt, white_in_cnt; | |
3500 | |
3501 struct display_block *odb, *idb; | |
3502 | |
793 | 3503 window = wrap_window (w); |
428 | 3504 |
3505 /* We have to add the glyphs to the line in the order outside, | |
3506 inside, whitespace. However the precedence dictates that we | |
3507 determine how many will fit in the reverse order. */ | |
3508 | |
3509 /* Determine how many whitespace glyphs we can display and where | |
3510 they should start. */ | |
3511 white_in_end = dl->bounds.right_white; | |
3512 white_out_end = dl->bounds.right_in; | |
3513 white_out_cnt = white_in_cnt = 0; | |
3514 elt = 0; | |
3515 | |
3516 while (elt < Dynarr_length (dl->right_glyphs)) | |
3517 { | |
3518 struct glyph_block *gb = Dynarr_atp (dl->right_glyphs, elt); | |
3519 | |
3520 if (NILP (gb->extent)) | |
2500 | 3521 ABORT (); /* these should have been handled in add_glyph_rune */ |
428 | 3522 |
3523 if (extent_end_glyph_layout (XEXTENT (gb->extent)) == GL_WHITESPACE) | |
3524 { | |
438 | 3525 int width = glyph_width (gb->glyph, window); |
428 | 3526 |
3527 if (white_in_end + width <= dl->bounds.right_in) | |
3528 { | |
3529 white_in_cnt++; | |
3530 white_in_end += width; | |
3531 gb->width = width; | |
3532 gb->active = 1; | |
3533 } | |
3534 else if (use_overflow | |
3535 && (white_out_end + width <= dl->bounds.right_out)) | |
3536 { | |
3537 white_out_cnt++; | |
3538 white_out_end += width; | |
3539 gb->width = width; | |
3540 gb->active = 1; | |
3541 } | |
3542 else | |
3543 gb->active = 0; | |
3544 } | |
3545 | |
3546 elt++; | |
3547 } | |
3548 | |
3549 /* Determine how many inside margin glyphs we can display and where | |
3550 they should start. The inside margin glyphs get whatever space | |
3551 is left after the whitespace glyphs have been displayed. These | |
3552 are tricky to calculate since if we decide to use the overflow | |
3553 area we basically have to start over. So for these we build up a | |
3554 list of just the inside margin glyphs and manipulate it to | |
3555 determine the needed info. */ | |
3556 { | |
3557 glyph_block_dynarr *ib; | |
3558 int avail_in, avail_out; | |
3559 int done = 0; | |
3560 int marker = 0; | |
3561 int used_in, used_out; | |
3562 | |
3563 elt = 0; | |
3564 used_in = used_out = 0; | |
3565 ib = Dynarr_new (glyph_block); | |
3566 while (elt < Dynarr_length (dl->right_glyphs)) | |
3567 { | |
3568 struct glyph_block *gb = Dynarr_atp (dl->right_glyphs, elt); | |
3569 | |
3570 if (NILP (gb->extent)) | |
2500 | 3571 ABORT (); /* these should have been handled in add_glyph_rune */ |
428 | 3572 |
3573 if (extent_end_glyph_layout (XEXTENT (gb->extent)) == GL_INSIDE_MARGIN) | |
3574 { | |
438 | 3575 gb->width = glyph_width (gb->glyph, window); |
428 | 3576 used_in += gb->width; |
3577 Dynarr_add (ib, *gb); | |
3578 } | |
3579 | |
3580 elt++; | |
3581 } | |
3582 | |
3583 if (white_out_cnt) | |
3584 avail_in = 0; | |
3585 else | |
3586 avail_in = dl->bounds.right_in - white_in_end; | |
3587 | |
3588 if (!use_overflow) | |
3589 avail_out = 0; | |
3590 else | |
3591 avail_out = dl->bounds.right_out - white_out_end; | |
3592 | |
3593 marker = 0; | |
3594 while (!done && marker < Dynarr_length (ib)) | |
3595 { | |
3596 int width = Dynarr_atp (ib, marker)->width; | |
3597 | |
3598 /* If everything now fits in the available inside margin | |
4187 | 3599 space, we're done. */ |
428 | 3600 if (used_in <= avail_in) |
3601 done = 1; | |
3602 else | |
3603 { | |
3604 /* Otherwise see if we have room to move a glyph to the | |
4187 | 3605 outside. */ |
428 | 3606 if (used_out + width <= avail_out) |
3607 { | |
3608 used_out += width; | |
3609 used_in -= width; | |
3610 } | |
3611 else | |
3612 done = 1; | |
3613 } | |
3614 | |
3615 if (!done) | |
3616 marker++; | |
3617 } | |
3618 | |
3619 /* At this point we now know that everything from marker on goes in | |
3620 the inside margin and everything before it goes in the outside | |
3621 margin. The stuff going into the outside margin is guaranteed | |
3622 to fit, but we may have to trim some stuff from the inside. */ | |
3623 | |
3624 in_in_start = dl->bounds.right_in; | |
3625 in_out_end = dl->bounds.right_in; | |
3626 in_out_cnt = in_in_cnt = 0; | |
3627 | |
3628 Dynarr_free (ib); | |
3629 elt = 0; | |
3630 while (elt < Dynarr_length (dl->right_glyphs)) | |
3631 { | |
3632 struct glyph_block *gb = Dynarr_atp (dl->right_glyphs, elt); | |
3633 | |
3634 if (NILP (gb->extent)) | |
2500 | 3635 ABORT (); /* these should have been handled in add_glyph_rune */ |
428 | 3636 |
3637 if (extent_end_glyph_layout (XEXTENT (gb->extent)) == GL_INSIDE_MARGIN) | |
3638 { | |
438 | 3639 int width = glyph_width (gb->glyph, window); |
428 | 3640 |
3641 if (used_out) | |
3642 { | |
3643 in_out_cnt++; | |
3644 in_out_end += width; | |
3645 gb->width = width; | |
3646 gb->active = 1; | |
3647 used_out -= width; | |
3648 } | |
3649 else if (in_in_start - width >= white_in_end) | |
3650 { | |
3651 in_in_cnt++; | |
3652 in_in_start -= width; | |
3653 gb->width = width; | |
3654 gb->active = 1; | |
3655 } | |
3656 else | |
3657 gb->active = 0; | |
3658 } | |
3659 | |
3660 elt++; | |
3661 } | |
3662 } | |
3663 | |
3664 /* Determine how many outside margin glyphs we can display. They | |
3665 always start at the right outside margin and can only use the | |
3666 outside margin space. */ | |
3667 out_start = dl->bounds.right_out; | |
3668 out_cnt = 0; | |
3669 elt = 0; | |
3670 | |
3671 while (elt < Dynarr_length (dl->right_glyphs)) | |
3672 { | |
3673 struct glyph_block *gb = Dynarr_atp (dl->right_glyphs, elt); | |
3674 | |
3675 if (NILP (gb->extent)) | |
2500 | 3676 ABORT (); /* these should have been handled in add_glyph_rune */ |
428 | 3677 |
3678 if (extent_end_glyph_layout (XEXTENT (gb->extent)) == GL_OUTSIDE_MARGIN) | |
3679 { | |
438 | 3680 int width = glyph_width (gb->glyph, window); |
428 | 3681 |
3682 if (out_start - width >= in_out_end) | |
3683 { | |
3684 out_cnt++; | |
3685 out_start -= width; | |
3686 gb->width = width; | |
3687 gb->active = 1; | |
3688 } | |
3689 else | |
3690 gb->active = 0; | |
3691 } | |
3692 | |
3693 elt++; | |
3694 } | |
3695 | |
3696 /* Now that we now where everything goes, we add the glyphs as runes | |
3697 to the appropriate display blocks. */ | |
3698 if (out_cnt || in_out_cnt || white_out_cnt) | |
3699 { | |
3700 odb = get_display_block_from_line (dl, RIGHT_OUTSIDE_MARGIN); | |
3701 /* #### See comments before odb->start_pos init in | |
4187 | 3702 create_left_glyph_block */ |
428 | 3703 odb->start_pos = dl->bounds.right_in; |
3704 odb->end_pos = dl->bounds.right_out; | |
3705 Dynarr_reset (odb->runes); | |
3706 } | |
3707 else | |
3708 odb = 0; | |
3709 | |
3710 if (in_in_cnt || white_in_cnt) | |
3711 { | |
3712 idb = get_display_block_from_line (dl, RIGHT_INSIDE_MARGIN); | |
3713 idb->start_pos = dl->bounds.right_white; | |
3714 /* #### See comments before odb->start_pos init in | |
4187 | 3715 create_left_glyph_block */ |
428 | 3716 idb->end_pos = dl->bounds.right_in; |
3717 Dynarr_reset (idb->runes); | |
3718 } | |
3719 else | |
3720 idb = 0; | |
3721 | |
3722 /* First add the whitespace margin glyphs which are actually in the | |
3723 inside margin. */ | |
3724 if (white_in_cnt) | |
3725 { | |
3726 end_xpos = add_margin_runes (dl, idb, dl->bounds.right_white, | |
3727 white_in_cnt, GL_WHITESPACE, RIGHT_GLYPHS, | |
3728 window); | |
3729 } | |
3730 else | |
3731 end_xpos = dl->bounds.right_white; | |
3732 | |
3733 /* Make sure that the area between the end of the whitespace glyphs | |
3734 and the inside margin glyphs is cleared. */ | |
3735 if (in_in_cnt && (in_in_start - end_xpos)) | |
3736 { | |
3737 add_margin_blank (dl, idb, w, end_xpos, in_in_start - end_xpos, | |
3738 RIGHT_GLYPHS); | |
3739 } | |
3740 | |
3741 /* Next add the inside margin glyphs which are actually in the | |
3742 inside margin. */ | |
3743 if (in_in_cnt) | |
3744 { | |
3745 end_xpos = add_margin_runes (dl, idb, in_in_start, in_in_cnt, | |
3746 GL_INSIDE_MARGIN, RIGHT_GLYPHS, window); | |
3747 } | |
3748 | |
3749 /* If we didn't add any inside margin glyphs then make sure the rest | |
3750 of the inside margin area gets cleared. */ | |
3751 if (idb && (dl->bounds.right_in - end_xpos)) | |
3752 { | |
3753 add_margin_blank (dl, idb, w, end_xpos, dl->bounds.right_in - end_xpos, | |
3754 RIGHT_GLYPHS); | |
3755 } | |
3756 | |
3757 /* Next add any whitespace glyphs in the outside margin. */ | |
3758 if (white_out_cnt) | |
3759 { | |
3760 end_xpos = add_margin_runes (dl, odb, dl->bounds.right_in, white_out_cnt, | |
3761 GL_WHITESPACE, RIGHT_GLYPHS, window); | |
3762 } | |
3763 else | |
3764 end_xpos = dl->bounds.right_in; | |
3765 | |
3766 /* Next add any inside margin glyphs in the outside margin. */ | |
3767 if (in_out_cnt) | |
3768 { | |
3769 end_xpos = add_margin_runes (dl, odb, end_xpos, in_out_cnt, | |
3770 GL_INSIDE_MARGIN, RIGHT_GLYPHS, window); | |
3771 } | |
3772 | |
3773 /* There may be space between any whitespace or inside margin glyphs | |
3774 in the outside margin and the actual outside margin glyphs. */ | |
3775 if (odb && (out_start - end_xpos)) | |
3776 { | |
3777 add_margin_blank (dl, odb, w, end_xpos, out_start - end_xpos, | |
3778 RIGHT_GLYPHS); | |
3779 } | |
3780 | |
3781 /* Finally, add the outside margin glyphs. */ | |
3782 if (out_cnt) | |
3783 { | |
3784 add_margin_runes (dl, odb, out_start, out_cnt, GL_OUTSIDE_MARGIN, | |
3785 RIGHT_GLYPHS, window); | |
3786 } | |
3787 } | |
3788 | |
3789 | |
3790 /***************************************************************************/ | |
3791 /* */ | |
3792 /* modeline routines */ | |
3793 /* */ | |
3794 /***************************************************************************/ | |
3795 | |
438 | 3796 /* This function is also used in frame.c by `generate_title_string' */ |
3797 void | |
3798 generate_formatted_string_db (Lisp_Object format_str, Lisp_Object result_str, | |
4187 | 3799 struct window *w, struct display_line *dl, |
3800 struct display_block *db, face_index findex, | |
3801 int min_pixpos, int max_pixpos, int type) | |
438 | 3802 { |
3803 struct frame *f = XFRAME (w->frame); | |
3804 struct device *d = XDEVICE (f->device); | |
3805 | |
3806 pos_data data; | |
3807 int c_pixpos; | |
3808 Charcount offset = 0; | |
3809 | |
3810 xzero (data); | |
3811 data.d = d; | |
3812 data.db = db; | |
3813 data.dl = dl; | |
3814 data.findex = findex; | |
3815 data.pixpos = min_pixpos; | |
3816 data.max_pixpos = max_pixpos; | |
3817 data.cursor_type = NO_CURSOR; | |
3818 data.last_charset = Qunbound; | |
3819 data.last_findex = DEFAULT_INDEX; | |
3820 data.result_str = result_str; | |
3821 data.is_modeline = 1; | |
3822 data.string = Qnil; | |
793 | 3823 data.window = wrap_window (w); |
438 | 3824 |
3825 Dynarr_reset (formatted_string_extent_dynarr); | |
3826 Dynarr_reset (formatted_string_extent_start_dynarr); | |
3827 Dynarr_reset (formatted_string_extent_end_dynarr); | |
3828 | |
3829 /* result_str is nil when we're building a frame or icon title. Otherwise, | |
3830 we're building a modeline, so the offset starts at the modeline | |
442 | 3831 horizontal scrolling amount */ |
438 | 3832 if (! NILP (result_str)) |
3833 offset = w->modeline_hscroll; | |
3834 generate_fstring_runes (w, &data, 0, 0, -1, format_str, 0, | |
4187 | 3835 max_pixpos - min_pixpos, findex, type, &offset, |
438 | 3836 Qnil); |
3837 | |
3838 if (Dynarr_length (db->runes)) | |
3839 { | |
4844
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4815
diff
changeset
|
3840 struct rune *rb = Dynarr_lastp (db->runes); |
438 | 3841 c_pixpos = rb->xpos + rb->width; |
3842 } | |
3843 else | |
3844 c_pixpos = min_pixpos; | |
3845 | |
3846 /* If we don't reach the right side of the window, add a blank rune | |
3847 to make up the difference. This usually only occurs if the | |
3848 modeline face is using a proportional width font or a fixed width | |
3849 font of a different size from the default face font. */ | |
3850 | |
3851 if (c_pixpos < max_pixpos) | |
3852 { | |
3853 data.pixpos = c_pixpos; | |
3854 data.blank_width = max_pixpos - data.pixpos; | |
3855 | |
3856 add_blank_rune (&data, NULL, 0); | |
3857 } | |
3858 | |
3859 /* Now create the result string and frob the extents into it. */ | |
3860 if (!NILP (result_str)) | |
3861 { | |
3862 int elt; | |
3863 Bytecount len; | |
867 | 3864 Ibyte *strdata; |
438 | 3865 struct buffer *buf = XBUFFER (WINDOW_BUFFER (w)); |
3866 | |
442 | 3867 in_modeline_generation = 1; |
3868 | |
771 | 3869 sledgehammer_check_ascii_begin (result_str); |
438 | 3870 detach_all_extents (result_str); |
793 | 3871 resize_string (result_str, -1, |
4187 | 3872 data.bytepos - XSTRING_LENGTH (result_str)); |
438 | 3873 |
3874 strdata = XSTRING_DATA (result_str); | |
3875 | |
3876 for (elt = 0, len = 0; elt < Dynarr_length (db->runes); elt++) | |
4844
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4815
diff
changeset
|
3877 { |
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4815
diff
changeset
|
3878 if (Dynarr_atp (db->runes, elt)->type == RUNE_CHAR) |
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4815
diff
changeset
|
3879 { |
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4815
diff
changeset
|
3880 len += (set_itext_ichar |
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4815
diff
changeset
|
3881 (strdata + len, Dynarr_atp (db->runes, |
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4815
diff
changeset
|
3882 elt)->object.chr.ch)); |
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4815
diff
changeset
|
3883 } |
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4815
diff
changeset
|
3884 } |
438 | 3885 |
771 | 3886 init_string_ascii_begin (result_str); |
3887 bump_string_modiff (result_str); | |
3888 sledgehammer_check_ascii_begin (result_str); | |
3889 | |
438 | 3890 for (elt = 0; elt < Dynarr_length (formatted_string_extent_dynarr); |
4187 | 3891 elt++) |
3892 { | |
3893 Lisp_Object extent = Qnil; | |
3894 Lisp_Object child; | |
3895 | |
3896 extent = wrap_extent (Dynarr_at (formatted_string_extent_dynarr, elt)); | |
3897 child = Fgethash (extent, buf->modeline_extent_table, Qnil); | |
3898 if (NILP (child)) | |
3899 { | |
3900 child = Fmake_extent (Qnil, Qnil, result_str); | |
3901 Fputhash (extent, child, buf->modeline_extent_table); | |
3902 } | |
3903 Fset_extent_parent (child, extent); | |
3904 set_extent_endpoints | |
3905 (XEXTENT (child), | |
3906 Dynarr_at (formatted_string_extent_start_dynarr, elt), | |
3907 Dynarr_at (formatted_string_extent_end_dynarr, elt), | |
3908 result_str); | |
3909 } | |
442 | 3910 |
3911 in_modeline_generation = 0; | |
438 | 3912 } |
3913 } | |
3914 | |
428 | 3915 /* Ensure that the given display line DL accurately represents the |
3916 modeline for the given window. */ | |
3917 static void | |
3918 generate_modeline (struct window *w, struct display_line *dl, int type) | |
3919 { | |
3920 struct buffer *b = XBUFFER (w->buffer); | |
3921 struct frame *f = XFRAME (w->frame); | |
3922 struct device *d = XDEVICE (f->device); | |
3923 | |
3924 /* Unlike display line and rune pointers, this one can't change underneath | |
3925 our feet. */ | |
3926 struct display_block *db = get_display_block_from_line (dl, TEXT); | |
3927 int max_pixpos, min_pixpos, ypos_adj; | |
3928 Lisp_Object font_inst; | |
3929 | |
3930 /* This will actually determine incorrect inside boundaries for the | |
3931 modeline since it ignores the margins. However being aware of this fact | |
3932 we never use those values anywhere so it doesn't matter. */ | |
3933 dl->bounds = calculate_display_line_boundaries (w, 1); | |
3934 | |
3935 /* We are generating a modeline. */ | |
3936 dl->modeline = 1; | |
3937 dl->cursor_elt = -1; | |
3938 | |
3939 /* Reset the runes on the modeline. */ | |
3940 Dynarr_reset (db->runes); | |
3941 | |
3942 if (!WINDOW_HAS_MODELINE_P (w)) | |
3943 { | |
3944 struct rune rb; | |
3945 | |
3946 /* If there is a horizontal scrollbar, don't add anything. */ | |
3947 if (window_scrollbar_height (w)) | |
3948 return; | |
3949 | |
3950 dl->ascent = DEVMETH (d, divider_height, ()); | |
3951 dl->descent = 0; | |
3952 /* The modeline is at the bottom of the gutters. */ | |
3953 dl->ypos = WINDOW_BOTTOM (w); | |
3954 | |
3955 rb.findex = MODELINE_INDEX; | |
3956 rb.xpos = dl->bounds.left_out; | |
3957 rb.width = dl->bounds.right_out - dl->bounds.left_out; | |
826 | 3958 rb.charpos = 0; |
428 | 3959 rb.endpos = 0; |
3960 rb.type = RUNE_HLINE; | |
3961 rb.object.hline.thickness = 1; | |
3962 rb.object.hline.yoffset = 0; | |
3963 rb.cursor_type = NO_CURSOR; | |
3964 | |
3965 if (!EQ (Qzero, w->modeline_shadow_thickness) | |
3966 && FRAME_WIN_P (f)) | |
3967 { | |
3968 int shadow_thickness = MODELINE_SHADOW_THICKNESS (w); | |
3969 | |
3970 dl->ypos -= shadow_thickness; | |
3971 rb.xpos += shadow_thickness; | |
3972 rb.width -= 2 * shadow_thickness; | |
3973 } | |
3974 | |
3975 Dynarr_add (db->runes, rb); | |
3976 return; | |
3977 } | |
3978 | |
3979 /* !!#### not right; needs to compute the max height of | |
3980 all the charsets */ | |
3981 font_inst = WINDOW_FACE_CACHEL_FONT (w, MODELINE_INDEX, Vcharset_ascii); | |
3982 | |
3983 dl->ascent = XFONT_INSTANCE (font_inst)->ascent; | |
3984 dl->descent = XFONT_INSTANCE (font_inst)->descent; | |
3985 | |
3986 min_pixpos = dl->bounds.left_out; | |
3987 max_pixpos = dl->bounds.right_out; | |
3988 | |
3989 if (!EQ (Qzero, w->modeline_shadow_thickness) && FRAME_WIN_P (f)) | |
3990 { | |
3991 int shadow_thickness = MODELINE_SHADOW_THICKNESS (w); | |
3992 | |
3993 ypos_adj = shadow_thickness; | |
3994 min_pixpos += shadow_thickness; | |
3995 max_pixpos -= shadow_thickness; | |
3996 } | |
3997 else | |
3998 ypos_adj = 0; | |
3999 | |
4000 generate_formatted_string_db (b->modeline_format, | |
4001 b->generated_modeline_string, w, dl, db, | |
4002 MODELINE_INDEX, min_pixpos, max_pixpos, type); | |
4003 | |
4004 /* The modeline is at the bottom of the gutters. We have to wait to | |
4005 set this until we've generated the modeline in order to account | |
4006 for any embedded faces. */ | |
4007 dl->ypos = WINDOW_BOTTOM (w) - dl->descent - ypos_adj; | |
4008 } | |
4009 | |
4010 static Charcount | |
867 | 4011 add_string_to_fstring_db_runes (pos_data *data, const Ibyte *str, |
4187 | 4012 Charcount pos, Charcount min_pos, |
771 | 4013 Charcount max_pos) |
428 | 4014 { |
4015 /* This function has been Mule-ized. */ | |
4016 Charcount end; | |
867 | 4017 const Ibyte *cur_pos = str; |
428 | 4018 struct display_block *db = data->db; |
4019 | |
4020 data->blank_width = space_width (XWINDOW (data->window)); | |
4021 while (Dynarr_length (db->runes) < pos) | |
4022 add_blank_rune (data, NULL, 0); | |
4023 | |
4024 end = (Dynarr_length (db->runes) + | |
4970 | 4025 bytecount_to_charcount (str, qxestrlen (str))); |
428 | 4026 if (max_pos != -1) |
4027 end = min (max_pos, end); | |
4028 | |
4029 while (pos < end && *cur_pos) | |
4030 { | |
867 | 4031 const Ibyte *old_cur_pos = cur_pos; |
428 | 4032 int succeeded; |
4033 | |
867 | 4034 data->ch = itext_ichar (cur_pos); |
4035 succeeded = (add_ichar_rune (data) != ADD_FAILED); | |
4036 INC_IBYTEPTR (cur_pos); | |
428 | 4037 if (succeeded) |
4187 | 4038 { |
4039 pos++; | |
4040 data->modeline_charpos++; | |
4041 data->bytepos += cur_pos - old_cur_pos; | |
4042 } | |
428 | 4043 } |
4044 | |
4045 while (Dynarr_length (db->runes) < min_pos && | |
4187 | 4046 (data->pixpos + data->blank_width <= data->max_pixpos)) |
428 | 4047 add_blank_rune (data, NULL, 0); |
4048 | |
4049 return Dynarr_length (db->runes); | |
4050 } | |
4051 | |
4052 /* #### Urk! Should also handle begin-glyphs and end-glyphs in | |
4053 modeline extents. */ | |
4054 static Charcount | |
4055 add_glyph_to_fstring_db_runes (pos_data *data, Lisp_Object glyph, | |
4187 | 4056 Charcount pos, Charcount UNUSED (min_pos), |
438 | 4057 Charcount max_pos, Lisp_Object extent) |
428 | 4058 { |
4059 /* This function has been Mule-ized. */ | |
4060 Charcount end; | |
4061 struct display_block *db = data->db; | |
4062 struct glyph_block gb; | |
4063 | |
4064 data->blank_width = space_width (XWINDOW (data->window)); | |
4065 while (Dynarr_length (db->runes) < pos) | |
4066 add_blank_rune (data, NULL, 0); | |
4067 | |
4068 end = Dynarr_length (db->runes) + 1; | |
4069 if (max_pos != -1) | |
4070 end = min (max_pos, end); | |
4071 | |
4072 gb.glyph = glyph; | |
438 | 4073 gb.extent = extent; |
428 | 4074 add_glyph_rune (data, &gb, BEGIN_GLYPHS, 0, 0); |
4075 pos++; | |
4076 | |
4077 while (Dynarr_length (db->runes) < pos && | |
4187 | 4078 (data->pixpos + data->blank_width <= data->max_pixpos)) |
428 | 4079 add_blank_rune (data, NULL, 0); |
4080 | |
4081 return Dynarr_length (db->runes); | |
4082 } | |
4083 | |
4084 /* If max_pos is == -1, it is considered to be infinite. The same is | |
4085 true of max_pixsize. */ | |
4086 #define SET_CURRENT_MODE_CHARS_PIXSIZE \ | |
4087 if (Dynarr_length (data->db->runes)) \ | |
4967 | 4088 cur_pixsize = data->pixpos - Dynarr_begin (data->db->runes)->xpos; \ |
428 | 4089 else \ |
4090 cur_pixsize = 0; | |
4091 | |
4092 /* Note that this function does "positions" in terms of characters and | |
4093 not in terms of columns. This is necessary to make the formatting | |
4094 work correctly when proportional width fonts are used in the | |
4095 modeline. */ | |
4096 static Charcount | |
4097 generate_fstring_runes (struct window *w, pos_data *data, Charcount pos, | |
4187 | 4098 Charcount min_pos, Charcount max_pos, |
4099 Lisp_Object elt, int depth, int max_pixsize, | |
4100 face_index findex, int type, Charcount *offset, | |
438 | 4101 Lisp_Object cur_ext) |
428 | 4102 { |
4103 /* This function has been Mule-ized. */ | |
4104 /* #### The other losing things in this function are: | |
4105 | |
4106 -- C zero-terminated-string lossage. | |
4107 -- Non-printable characters should be converted into something | |
4187 | 4108 appropriate (e.g. ^F) instead of blindly being printed anyway. |
428 | 4109 */ |
4110 | |
4111 tail_recurse: | |
4112 if (depth > 10) | |
4113 goto invalid; | |
4114 | |
4115 depth++; | |
4116 | |
4117 if (STRINGP (elt)) | |
4118 { | |
4119 /* A string. Add to the display line and check for %-constructs | |
4187 | 4120 within it. */ |
428 | 4121 |
2552 | 4122 Ibyte *this_str = XSTRING_DATA (elt); |
4123 | |
4124 while ((pos < max_pos || max_pos == -1) && *this_str) | |
4187 | 4125 { |
4126 Ibyte *last = this_str; | |
4127 | |
4128 while (*this_str && *this_str != '%') | |
4129 this_str++; | |
4130 | |
4131 if (this_str != last) | |
4132 { | |
4133 /* No %-construct */ | |
4134 Charcount size = | |
2552 | 4135 bytecount_to_charcount (last, this_str - last); |
438 | 4136 |
4137 if (size <= *offset) | |
4138 *offset -= size; | |
4139 else | |
4140 { | |
4141 Charcount tmp_max = (max_pos == -1 ? pos + size - *offset : | |
4142 min (pos + size - *offset, max_pos)); | |
867 | 4143 const Ibyte *tmp_last = itext_n_addr (last, *offset); |
438 | 4144 |
4145 pos = add_string_to_fstring_db_runes (data, tmp_last, | |
4146 pos, pos, tmp_max); | |
4147 *offset = 0; | |
4148 } | |
4187 | 4149 } |
4150 else /* *this_str == '%' */ | |
4151 { | |
4152 Charcount spec_width = 0; | |
4153 | |
4154 this_str++; /* skip over '%' */ | |
4155 | |
4156 /* We can't allow -ve args due to the "%-" construct. | |
4157 * Argument specifies minwidth but not maxwidth | |
4158 * (maxwidth can be specified by | |
4159 * (<negative-number> . <stuff>) modeline elements) | |
4160 */ | |
4161 while (isdigit (*this_str)) | |
4162 { | |
4163 spec_width = spec_width * 10 + (*this_str - '0'); | |
4164 this_str++; | |
4165 } | |
4166 spec_width += pos; | |
4167 | |
4168 if (*this_str == 'M') | |
4169 { | |
4170 pos = generate_fstring_runes (w, data, pos, spec_width, | |
4171 max_pos, Vglobal_mode_string, | |
4172 depth, max_pixsize, findex, | |
4173 type, offset, cur_ext); | |
4174 } | |
4175 else if (*this_str == '-') | |
4176 { | |
4177 Charcount num_to_add; | |
4178 | |
4179 if (max_pixsize < 0) | |
4180 num_to_add = 0; | |
4181 else if (max_pos != -1) | |
4182 num_to_add = max_pos - pos; | |
4183 else | |
4184 { | |
4185 int cur_pixsize; | |
4186 int dash_pixsize; | |
4187 Ibyte ch = '-'; | |
4188 SET_CURRENT_MODE_CHARS_PIXSIZE; | |
4189 | |
4190 dash_pixsize = | |
4815
6540302eedf5
Fix query_string_geometry lookup domain
Didier Verna <didier@lrde.epita.fr>
parents:
4528
diff
changeset
|
4191 redisplay_window_text_width_string |
6540302eedf5
Fix query_string_geometry lookup domain
Didier Verna <didier@lrde.epita.fr>
parents:
4528
diff
changeset
|
4192 (w, findex, &ch, Qnil, 0, 1); |
4187 | 4193 |
4194 if (dash_pixsize == 0) | |
3094 | 4195 num_to_add = 0; |
4196 else { | |
4197 num_to_add = (max_pixsize - cur_pixsize) / dash_pixsize; | |
4198 num_to_add++; | |
4199 } | |
4187 | 4200 } |
4201 | |
4202 while (num_to_add--) | |
4203 pos = add_string_to_fstring_db_runes | |
4204 (data, (const Ibyte *) "-", pos, pos, max_pos); | |
4205 } | |
4206 else if (*this_str != 0) | |
4207 { | |
4208 Ichar ch = itext_ichar (this_str); | |
4209 Ibyte *str; | |
438 | 4210 Charcount size; |
4211 | |
4187 | 4212 decode_mode_spec (w, ch, type); |
4213 | |
4967 | 4214 str = Dynarr_begin (mode_spec_ibyte_string); |
438 | 4215 size = bytecount_to_charcount |
4216 /* Skip the null character added by `decode_mode_spec' */ | |
867 | 4217 (str, Dynarr_length (mode_spec_ibyte_string)) - 1; |
438 | 4218 |
4219 if (size <= *offset) | |
4220 *offset -= size; | |
4221 else | |
4222 { | |
867 | 4223 const Ibyte *tmp_str = itext_n_addr (str, *offset); |
438 | 4224 |
440 | 4225 /* #### NOTE: I don't understand why a tmp_max is not |
438 | 4226 computed and used here as in the plain string case |
4227 above. -- dv */ | |
4228 pos = add_string_to_fstring_db_runes (data, tmp_str, | |
4229 pos, pos, | |
4230 max_pos); | |
4231 *offset = 0; | |
4232 } | |
4187 | 4233 } |
4234 | |
4235 /* NOT this_str++. There could be any sort of character at | |
4236 the current position. */ | |
4237 INC_IBYTEPTR (this_str); | |
4238 } | |
4239 | |
4240 if (max_pixsize > 0) | |
4241 { | |
4242 int cur_pixsize; | |
4243 SET_CURRENT_MODE_CHARS_PIXSIZE; | |
4244 | |
4245 if (cur_pixsize >= max_pixsize) | |
4246 break; | |
4247 } | |
4248 } | |
428 | 4249 } |
4250 else if (SYMBOLP (elt)) | |
4251 { | |
4252 /* A symbol: process the value of the symbol recursively | |
4187 | 4253 as if it appeared here directly. */ |
428 | 4254 Lisp_Object tem = symbol_value_in_buffer (elt, w->buffer); |
4255 | |
4256 if (!UNBOUNDP (tem)) | |
4187 | 4257 { |
438 | 4258 /* If value is a string, output that string literally: |
4187 | 4259 don't check for % within it. */ |
4260 if (STRINGP (tem)) | |
4261 { | |
867 | 4262 Ibyte *str = XSTRING_DATA (tem); |
826 | 4263 Charcount size = string_char_length (tem); |
438 | 4264 |
4265 if (size <= *offset) | |
4266 *offset -= size; | |
4267 else | |
4268 { | |
867 | 4269 const Ibyte *tmp_str = itext_n_addr (str, *offset); |
438 | 4270 |
440 | 4271 /* #### NOTE: I don't understand why a tmp_max is not |
438 | 4272 computed and used here as in the plain string case |
4273 above. -- dv */ | |
4274 pos = add_string_to_fstring_db_runes (data, tmp_str, pos, | |
4275 min_pos, max_pos); | |
4276 *offset = 0; | |
4277 } | |
4187 | 4278 } |
4279 /* Give up right away for nil or t. */ | |
4280 else if (!EQ (tem, elt)) | |
4281 { | |
4282 elt = tem; | |
4283 goto tail_recurse; | |
4284 } | |
4285 } | |
428 | 4286 } |
4287 else if (GENERIC_SPECIFIERP (elt)) | |
4288 { | |
4289 Lisp_Object window, tem; | |
793 | 4290 window = wrap_window (w); |
428 | 4291 tem = specifier_instance_no_quit (elt, Qunbound, window, |
793 | 4292 ERROR_ME_DEBUG_WARN, 0, Qzero); |
428 | 4293 if (!UNBOUNDP (tem)) |
4294 { | |
4295 elt = tem; | |
4296 goto tail_recurse; | |
4297 } | |
4298 } | |
4299 else if (CONSP (elt)) | |
4300 { | |
4301 /* A cons cell: four distinct cases. | |
438 | 4302 * - If first element is a string or a cons, process all the elements |
4303 * and effectively concatenate them. | |
4304 * - If first element is a negative number, truncate displaying cdr to | |
4305 * at most that many characters. If positive, pad (with spaces) | |
4306 * to at least that many characters. | |
771 | 4307 * - If first element is another symbol or a boolean specifier, process |
4308 * the cadr or caddr recursively according to whether the symbol's | |
4309 * value or specifier's instance is non-nil or nil. | |
4310 * - If first element is , process the cadr or caddr | |
4311 * recursively according to whether the instance of the specifier in | |
4312 * the modeline's window is non-nil or nil. | |
442 | 4313 * - If first element is an extent, process the cdr recursively |
4314 * and handle the extent's face. | |
428 | 4315 */ |
438 | 4316 |
428 | 4317 Lisp_Object car, tem; |
4318 | |
4319 car = XCAR (elt); | |
771 | 4320 if (SYMBOLP (car) || BOOLEAN_SPECIFIERP (car)) |
438 | 4321 { |
4322 elt = XCDR (elt); | |
4323 if (!CONSP (elt)) | |
4324 goto invalid; | |
4325 | |
771 | 4326 if (SYMBOLP (car)) |
4327 tem = symbol_value_in_buffer (car, w->buffer); | |
4328 else | |
4329 tem = specifier_instance_no_quit (car, Qunbound, wrap_window (w), | |
793 | 4330 ERROR_ME_DEBUG_WARN, 0, Qzero); |
438 | 4331 /* elt is now the cdr, and we know it is a cons cell. |
4332 Use its car if CAR has a non-nil value. */ | |
771 | 4333 if (!UNBOUNDP (tem) && !NILP (tem)) |
438 | 4334 { |
771 | 4335 elt = XCAR (elt); |
4336 goto tail_recurse; | |
438 | 4337 } |
771 | 4338 /* Symbol's value or specifier's instance is nil or unbound |
438 | 4339 * Get the cddr of the original list |
4340 * and if possible find the caddr and use that. | |
4341 */ | |
4342 elt = XCDR (elt); | |
4343 if (NILP (elt)) | |
4344 ; | |
4345 else if (!CONSP (elt)) | |
4346 goto invalid; | |
4347 else | |
4348 { | |
4349 elt = XCAR (elt); | |
4350 goto tail_recurse; | |
4351 } | |
4352 } | |
428 | 4353 else if (INTP (car)) |
4187 | 4354 { |
4355 Charcount lim = XINT (car); | |
4356 | |
4357 elt = XCDR (elt); | |
4358 | |
4359 if (lim < 0) | |
4360 { | |
4361 /* Negative int means reduce maximum width. | |
4362 * DO NOT change MIN_PIXPOS here! | |
4363 * (20 -10 . foo) should truncate foo to 10 col | |
4364 * and then pad to 20. | |
4365 */ | |
4366 if (max_pos == -1) | |
4367 max_pos = pos - lim; | |
4368 else | |
4369 max_pos = min (max_pos, pos - lim); | |
4370 } | |
4371 else if (lim > 0) | |
4372 { | |
4373 /* Padding specified. Don't let it be more than | |
4374 * current maximum. | |
4375 */ | |
4376 lim += pos; | |
4377 if (max_pos != -1 && lim > max_pos) | |
4378 lim = max_pos; | |
4379 /* If that's more padding than already wanted, queue it. | |
4380 * But don't reduce padding already specified even if | |
4381 * that is beyond the current truncation point. | |
4382 */ | |
4383 if (lim > min_pos) | |
4384 min_pos = lim; | |
4385 } | |
4386 goto tail_recurse; | |
4387 } | |
428 | 4388 else if (STRINGP (car) || CONSP (car)) |
4187 | 4389 { |
4390 int limit = 50; | |
4391 | |
4392 /* LIMIT is to protect against circular lists. */ | |
4393 while (CONSP (elt) && --limit > 0 | |
4394 && (pos < max_pos || max_pos == -1)) | |
4395 { | |
4396 pos = generate_fstring_runes (w, data, pos, pos, max_pos, | |
4397 XCAR (elt), depth, max_pixsize, | |
438 | 4398 findex, type, offset, cur_ext); |
4187 | 4399 elt = XCDR (elt); |
4400 } | |
4401 } | |
428 | 4402 else if (EXTENTP (car)) |
4187 | 4403 { |
4404 struct extent *ext = XEXTENT (car); | |
4405 | |
4406 if (EXTENT_LIVE_P (ext)) | |
4407 { | |
4408 face_index old_findex = data->findex; | |
4409 Lisp_Object face; | |
4410 Lisp_Object font_inst; | |
4411 face_index new_findex; | |
4412 Bytecount start = data->bytepos; | |
4413 | |
4414 face = extent_face (ext); | |
4415 if (FACEP (face)) | |
4416 { | |
4417 /* #### needs to merge faces, sigh */ | |
4418 /* #### needs to handle list of faces */ | |
4419 new_findex = get_builtin_face_cache_index (w, face); | |
4420 /* !!#### not right; needs to compute the max height of | |
4421 all the charsets */ | |
4422 font_inst = WINDOW_FACE_CACHEL_FONT (w, new_findex, | |
4423 Vcharset_ascii); | |
4424 | |
4425 data->dl->ascent = max (data->dl->ascent, | |
4426 XFONT_INSTANCE (font_inst)->ascent); | |
4427 data->dl->descent = max (data->dl->descent, | |
4428 XFONT_INSTANCE (font_inst)-> | |
4429 descent); | |
4430 } | |
4431 else | |
4432 new_findex = old_findex; | |
4433 | |
4434 data->findex = new_findex; | |
4435 pos = generate_fstring_runes (w, data, pos, pos, max_pos, | |
4436 XCDR (elt), depth - 1, | |
438 | 4437 max_pixsize, new_findex, type, |
4438 offset, car); | |
4187 | 4439 data->findex = old_findex; |
4440 Dynarr_add (formatted_string_extent_dynarr, ext); | |
4441 Dynarr_add (formatted_string_extent_start_dynarr, start); | |
4442 Dynarr_add (formatted_string_extent_end_dynarr, data->bytepos); | |
4443 } | |
4444 } | |
428 | 4445 } |
4446 else if (GLYPHP (elt)) | |
4447 { | |
438 | 4448 /* Glyphs are considered as one character with respect to the modeline |
4449 horizontal scrolling facility. -- dv */ | |
4450 if (*offset > 0) | |
4451 *offset -= 1; | |
4452 else | |
4453 pos = add_glyph_to_fstring_db_runes (data, elt, pos, pos, max_pos, | |
4454 cur_ext); | |
428 | 4455 } |
4456 else | |
4457 { | |
4458 invalid: | |
438 | 4459 { |
4970 | 4460 const Ascbyte *str = GETTEXT ("*invalid*"); |
438 | 4461 Charcount size = (Charcount) strlen (str); /* is this ok ?? -- dv */ |
4462 | |
4463 if (size <= *offset) | |
4464 *offset -= size; | |
4465 else | |
4466 { | |
867 | 4467 const Ibyte *tmp_str = |
4468 itext_n_addr ((const Ibyte *) str, *offset); | |
438 | 4469 |
440 | 4470 /* #### NOTE: I don't understand why a tmp_max is not computed and |
438 | 4471 used here as in the plain string case above. -- dv */ |
4472 pos = add_string_to_fstring_db_runes (data, tmp_str, pos, | |
4473 min_pos, max_pos); | |
4474 *offset = 0; | |
4475 } | |
4476 } | |
428 | 4477 } |
4478 | |
4479 if (min_pos > pos) | |
4480 { | |
867 | 4481 add_string_to_fstring_db_runes (data, (const Ibyte *) "", pos, |
438 | 4482 min_pos, -1); |
428 | 4483 } |
4484 | |
4485 return pos; | |
4486 } | |
4487 | |
4488 /* Update just the modeline. Assumes the desired display structs. If | |
4489 they do not have a modeline block, it does nothing. */ | |
4490 static void | |
4491 regenerate_modeline (struct window *w) | |
4492 { | |
4493 display_line_dynarr *dla = window_display_lines (w, DESIRED_DISP); | |
4494 | |
4967 | 4495 if (!Dynarr_length (dla) || !Dynarr_begin (dla)->modeline) |
428 | 4496 return; |
4497 else | |
4498 { | |
4967 | 4499 generate_modeline (w, Dynarr_begin (dla), DESIRED_DISP); |
428 | 4500 redisplay_update_line (w, 0, 0, 0); |
4501 } | |
4502 } | |
4503 | |
4504 /* Make sure that modeline display line is present in the given | |
4505 display structs if the window has a modeline and update that | |
4506 line. Returns true if a modeline was needed. */ | |
4507 static int | |
4508 ensure_modeline_generated (struct window *w, int type) | |
4509 { | |
4510 int need_modeline; | |
4511 | |
4512 /* minibuffer windows don't have modelines */ | |
4513 if (MINI_WINDOW_P (w)) | |
4514 need_modeline = 0; | |
4515 /* windows which haven't had it turned off do */ | |
4516 else if (WINDOW_HAS_MODELINE_P (w)) | |
4517 need_modeline = 1; | |
4518 /* windows which have it turned off don't have a divider if there is | |
4519 a horizontal scrollbar */ | |
4520 else if (window_scrollbar_height (w)) | |
4521 need_modeline = 0; | |
4522 /* and in this case there is none */ | |
4523 else | |
4524 need_modeline = 1; | |
4525 | |
4526 if (need_modeline) | |
4527 { | |
4528 display_line_dynarr *dla; | |
4529 | |
4530 dla = window_display_lines (w, type); | |
4531 | |
4532 /* We don't care if there is a display line which is not | |
4187 | 4533 currently a modeline because it is definitely going to become |
4534 one if we have gotten to this point. */ | |
428 | 4535 if (Dynarr_length (dla) == 0) |
4536 { | |
4537 if (Dynarr_largest (dla) > 0) | |
5038 | 4538 Dynarr_incrementr (dla); |
428 | 4539 else |
4540 { | |
4541 struct display_line modeline; | |
4207 | 4542 |
4543 DISPLAY_LINE_INIT (modeline); | |
428 | 4544 Dynarr_add (dla, modeline); |
4545 } | |
4546 } | |
4547 | |
4548 /* If we're adding a new place marker go ahead and generate the | |
4187 | 4549 modeline so that it is available for use by |
4550 window_modeline_height. */ | |
4967 | 4551 generate_modeline (w, Dynarr_begin (dla), type); |
428 | 4552 } |
4553 | |
4554 return need_modeline; | |
4555 } | |
4556 | |
4557 /* #### Kludge or not a kludge. I tend towards the former. */ | |
4558 int | |
4559 real_current_modeline_height (struct window *w) | |
4560 { | |
4561 Fset_marker (w->start[CMOTION_DISP], w->start[CURRENT_DISP], w->buffer); | |
4562 Fset_marker (w->pointm[CMOTION_DISP], w->pointm[CURRENT_DISP], w->buffer); | |
4563 | |
4564 if (ensure_modeline_generated (w, CMOTION_DISP)) | |
4565 { | |
4566 display_line_dynarr *dla = window_display_lines (w, CMOTION_DISP); | |
4567 | |
4568 if (Dynarr_length (dla)) | |
4569 { | |
4967 | 4570 if (Dynarr_begin (dla)->modeline) |
4571 return (Dynarr_begin (dla)->ascent + | |
4572 Dynarr_begin (dla)->descent); | |
428 | 4573 } |
4574 } | |
4575 return 0; | |
4576 } | |
4577 | |
4578 | |
4579 /***************************************************************************/ | |
819 | 4580 /* */ |
826 | 4581 /* displayable string routines */ |
819 | 4582 /* */ |
428 | 4583 /***************************************************************************/ |
4584 | |
4585 /* Given a position for a string in a window, ensure that the given | |
4586 display line DL accurately represents the text on a line starting | |
4587 at the given position. | |
4588 | |
4589 Yes, this is duplicating the code of create_text_block, but it | |
4590 looked just too hard to change create_text_block to handle strings | |
4591 *and* buffers. We already make a distinction between the two | |
4592 elsewhere in the code so I think unifying them would require a | |
4593 complete MULE rewrite. Besides, the other distinction is that these | |
4594 functions cover text that the user *cannot edit* so we can remove | |
4595 everything to do with cursors, minibuffers etc. Eventually the | |
4596 modeline routines should be modified to use this code as it copes | |
4597 with many more types of display situation. */ | |
4598 | |
665 | 4599 static Charbpos |
428 | 4600 create_string_text_block (struct window *w, Lisp_Object disp_string, |
4601 struct display_line *dl, | |
826 | 4602 Charcount start_pos, |
428 | 4603 prop_block_dynarr **prop, |
4604 face_index default_face) | |
4605 { | |
4606 struct frame *f = XFRAME (w->frame); | |
4607 /* Note that a lot of the buffer controlled stuff has been left in | |
4608 because you might well want to make use of it (selective display | |
4609 etc), its just the buffer text that we do not use. However, it | |
4610 seems to be possible for buffer to be nil sometimes so protect | |
4611 against this case. */ | |
4612 struct buffer *b = BUFFERP (w->buffer) ? XBUFFER (w->buffer) : 0; | |
4613 struct device *d = XDEVICE (f->device); | |
4614 | |
4615 /* we're working with these a lot so precalculate them */ | |
4616 Bytecount slen = XSTRING_LENGTH (disp_string); | |
826 | 4617 Bytecount byte_string_zv = slen; |
4618 Bytecount byte_start_pos = string_index_char_to_byte (disp_string, start_pos); | |
428 | 4619 |
4620 pos_data data; | |
4621 | |
4622 int truncate_win = b ? window_truncation_on (w) : 0; | |
4623 | |
442 | 4624 /* We're going to ditch selective display for static text, it's an |
4625 FSF thing and invisible extents are the way to go here. | |
4626 Implementing it also relies on a number of buffer-specific | |
428 | 4627 functions that we don't have the luxury of being able to use |
4628 here. */ | |
4629 | |
4630 /* The variable ctl-arrow allows the user to specify what characters | |
4631 can actually be displayed and which octal should be used for. | |
4632 #### This variable should probably have some rethought done to | |
4633 it. | |
4634 | |
4635 #### It would also be really nice if you could specify that | |
4636 the characters come out in hex instead of in octal. Mule | |
4637 does that by adding a ctl-hexa variable similar to ctl-arrow, | |
4638 but that's bogus -- we need a more general solution. I | |
4639 think you need to extend the concept of display tables | |
4640 into a more general conversion mechanism. Ideally you | |
4641 could specify a Lisp function that converts characters, | |
4642 but this violates the Second Golden Rule and besides would | |
4643 make things way way way way slow. | |
4644 | |
4645 So instead, we extend the display-table concept, which was | |
4646 historically limited to 256-byte vectors, to one of the | |
4647 following: | |
4648 | |
4649 a) A 256-entry vector, for backward compatibility; | |
4650 b) char-table, mapping characters to values; | |
4651 c) range-table, mapping ranges of characters to values; | |
4652 d) a list of the above. | |
4653 | |
4654 The (d) option allows you to specify multiple display tables | |
4655 instead of just one. Each display table can specify conversions | |
4656 for some characters and leave others unchanged. The way the | |
4657 character gets displayed is determined by the first display table | |
4658 with a binding for that character. This way, you could call a | |
4659 function `enable-hex-display' that adds a hex display-table to | |
4660 the list of display tables for the current buffer. | |
4661 | |
4662 #### ...not yet implemented... Also, we extend the concept of | |
4663 "mapping" to include a printf-like spec. Thus you can make all | |
4664 extended characters show up as hex with a display table like | |
4665 this: | |
4666 | |
4187 | 4667 #s(range-table data ((256 524288) (format "%x"))) |
428 | 4668 |
4669 Since more than one display table is possible, you have | |
4670 great flexibility in mapping ranges of characters. */ | |
867 | 4671 Ichar printable_min = b ? (CHAR_OR_CHAR_INTP (b->ctl_arrow) |
428 | 4672 ? XCHAR_OR_CHAR_INT (b->ctl_arrow) |
4673 : ((EQ (b->ctl_arrow, Qt) || EQ (b->ctl_arrow, Qnil)) | |
4674 ? 255 : 160)) : 255; | |
4675 | |
4676 Lisp_Object face_dt, window_dt; | |
4677 | |
4678 /* The text display block for this display line. */ | |
4679 struct display_block *db = get_display_block_from_line (dl, TEXT); | |
4680 | |
4681 /* The first time through the main loop we need to force the glyph | |
4682 data to be updated. */ | |
4683 int initial = 1; | |
4684 | |
4685 /* Apparently the new extent_fragment_update returns an end position | |
4686 equal to the position passed in if there are no more runs to be | |
4687 displayed. */ | |
4688 int no_more_frags = 0; | |
4689 | |
4690 dl->used_prop_data = 0; | |
4691 dl->num_chars = 0; | |
442 | 4692 dl->line_continuation = 0; |
428 | 4693 |
4187 | 4694 /* Set up faces to use for clearing areas, used by output_display_line. */ |
428 | 4695 dl->default_findex = default_face; |
4187 | 4696 if (default_face > DEFAULT_INDEX) |
428 | 4697 { |
4698 dl->left_margin_findex = default_face; | |
4699 dl->right_margin_findex = default_face; | |
4700 } | |
4701 else | |
4702 { | |
434 | 4703 dl->left_margin_findex = |
428 | 4704 get_builtin_face_cache_index (w, Vleft_margin_face); |
434 | 4705 dl->right_margin_findex = |
428 | 4706 get_builtin_face_cache_index (w, Vright_margin_face); |
4707 } | |
4708 | |
4709 xzero (data); | |
4710 data.ef = extent_fragment_new (disp_string, f); | |
4711 | |
4712 /* These values are used by all of the rune addition routines. We add | |
4713 them to this structure for ease of passing. */ | |
4714 data.d = d; | |
793 | 4715 data.window = wrap_window (w); |
428 | 4716 data.db = db; |
4717 data.dl = dl; | |
4718 | |
826 | 4719 data.byte_charpos = byte_start_pos; |
428 | 4720 data.pixpos = dl->bounds.left_in; |
4721 data.last_charset = Qunbound; | |
4722 data.last_findex = default_face; | |
4723 data.result_str = Qnil; | |
4724 data.string = disp_string; | |
4725 | |
4726 /* Set the right boundary adjusting it to take into account any end | |
4727 glyph. Save the width of the end glyph for later use. */ | |
4728 data.max_pixpos = dl->bounds.right_in; | |
819 | 4729 data.max_pixpos -= data.end_glyph_width; |
428 | 4730 |
4731 data.cursor_type = NO_CURSOR; | |
4732 data.cursor_x = -1; | |
4733 | |
4734 data.start_col = 0; | |
4735 /* I don't think we want this, string areas should not scroll with | |
434 | 4736 the window |
428 | 4737 data.start_col = w->hscroll; |
826 | 4738 data.byte_start_col_enabled = (w->hscroll ? byte_start_pos : 0); |
428 | 4739 */ |
826 | 4740 data.byte_start_col_enabled = 0; |
428 | 4741 data.hscroll_glyph_width_adjust = 0; |
4742 | |
4743 /* We regenerate the line from the very beginning. */ | |
4744 Dynarr_reset (db->runes); | |
4745 | |
4746 /* Why is this less than or equal and not just less than? If the | |
4747 starting position is already equal to the maximum we can't add | |
4748 anything else, right? Wrong. We might still have a newline to | |
4749 add. A newline can use the room allocated for an end glyph since | |
4750 if we add it we know we aren't going to be adding any end | |
4751 glyph. */ | |
4752 | |
4753 /* #### Chuck -- I think this condition should be while (1). | |
4754 Otherwise if (e.g.) there is one begin-glyph and one end-glyph | |
4755 and the begin-glyph ends exactly at the end of the window, the | |
4756 end-glyph and text might not be displayed. while (1) ensures | |
4757 that the loop terminates only when either (a) there is | |
4758 propagation data or (b) the end-of-line or end-of-buffer is hit. | |
4759 | |
4760 #### Also I think you need to ensure that the operation | |
4761 "add begin glyphs; add end glyphs; add text" is atomic and | |
4762 can't get interrupted in the middle. If you run off the end | |
4763 of the line during that operation, then you keep accumulating | |
4764 propagation data until you're done. Otherwise, if the (e.g.) | |
4765 there's a begin glyph at a particular position and attempting | |
4766 to display that glyph results in window-end being hit and | |
4767 propagation data being generated, then the character at that | |
4768 position won't be displayed. | |
4769 | |
4770 #### See also the comment after the end of this loop, below. | |
4771 */ | |
4772 while (data.pixpos <= data.max_pixpos) | |
4773 { | |
4774 /* #### This check probably should not be necessary. */ | |
826 | 4775 if (data.byte_charpos > byte_string_zv) |
428 | 4776 { |
4777 /* #### urk! More of this lossage! */ | |
826 | 4778 data.byte_charpos--; |
428 | 4779 goto done; |
4780 } | |
4781 | |
4782 /* Check for face changes. */ | |
826 | 4783 if (initial || (!no_more_frags && data.byte_charpos == data.ef->end)) |
428 | 4784 { |
819 | 4785 Lisp_Object last_glyph = Qnil; |
4786 /* Deal with clipped glyphs that we have already displayed. */ | |
4967 | 4787 if (*prop && Dynarr_begin (*prop)->type == PROP_GLYPH) |
4788 { | |
4789 last_glyph = Dynarr_begin (*prop)->data.p_glyph.glyph; | |
819 | 4790 Dynarr_free (*prop); |
4791 *prop = 0; | |
4792 } | |
428 | 4793 /* Now compute the face and begin/end-glyph information. */ |
4794 data.findex = | |
793 | 4795 /* Remember that the extent-fragment routines deal in |
4187 | 4796 Bytexpos's. */ |
826 | 4797 extent_fragment_update (w, data.ef, data.byte_charpos, last_glyph); |
428 | 4798 /* This is somewhat cheesy but the alternative is to |
4187 | 4799 propagate default_face into extent_fragment_update. */ |
428 | 4800 if (data.findex == DEFAULT_INDEX) |
4801 data.findex = default_face; | |
4802 | |
4803 get_display_tables (w, data.findex, &face_dt, &window_dt); | |
4804 | |
826 | 4805 if (data.byte_charpos == data.ef->end) |
428 | 4806 no_more_frags = 1; |
4807 } | |
4808 initial = 0; | |
4809 | |
4810 /* Determine what is next to be displayed. We first handle any | |
4187 | 4811 glyphs returned by glyphs_at_charbpos. If there are no glyphs to |
4812 display then we determine what to do based on the character at the | |
4813 current buffer position. */ | |
428 | 4814 |
4815 /* If the current position is covered by an invisible extent, do | |
4187 | 4816 nothing (except maybe add some ellipses). |
428 | 4817 |
4818 #### The behavior of begin and end-glyphs at the edge of an | |
4819 invisible extent should be investigated further. This is | |
4820 fairly low priority though. */ | |
4821 if (data.ef->invisible) | |
4822 { | |
4823 /* #### Chuck, perhaps you could look at this code? I don't | |
4824 really know what I'm doing. */ | |
4825 if (*prop) | |
4826 { | |
4827 Dynarr_free (*prop); | |
4828 *prop = 0; | |
4829 } | |
4830 | |
4831 /* The extent fragment code only sets this when we should | |
4832 really display the ellipses. It makes sure the ellipses | |
4833 don't get displayed more than once in a row. */ | |
4834 if (data.ef->invisible_ellipses) | |
4835 { | |
4836 struct glyph_block gb; | |
4837 | |
4838 data.ef->invisible_ellipses_already_displayed = 1; | |
4839 data.ef->invisible_ellipses = 0; | |
4840 gb.extent = Qnil; | |
4841 gb.glyph = Vinvisible_text_glyph; | |
4842 *prop = add_glyph_rune (&data, &gb, BEGIN_GLYPHS, 0, | |
4843 GLYPH_CACHEL (w, INVIS_GLYPH_INDEX)); | |
4844 /* Perhaps they shouldn't propagate if the very next thing | |
4845 is to display a newline (for compatibility with | |
4846 selective-display-ellipses)? Maybe that's too | |
4847 abstruse. */ | |
4848 if (*prop) | |
4849 goto done; | |
4850 } | |
4851 | |
638 | 4852 /* #### What if we're dealing with a display table? */ |
428 | 4853 if (data.start_col) |
4854 data.start_col--; | |
4855 | |
826 | 4856 if (data.byte_charpos == byte_string_zv) |
428 | 4857 goto done; |
4858 else | |
826 | 4859 INC_BYTECOUNT (XSTRING_DATA (disp_string), data.byte_charpos); |
428 | 4860 } |
4861 | |
4862 /* If there is propagation data, then it represents the current | |
4187 | 4863 buffer position being displayed. Add them and advance the |
4864 position counter. This might also add the minibuffer | |
4865 prompt. */ | |
428 | 4866 else if (*prop) |
4867 { | |
4868 dl->used_prop_data = 1; | |
4869 *prop = add_propagation_runes (prop, &data); | |
4870 | |
4871 if (*prop) | |
4872 goto done; /* gee, a really narrow window */ | |
826 | 4873 else if (data.byte_charpos == byte_string_zv) |
428 | 4874 goto done; |
826 | 4875 else if (data.byte_charpos < 0) |
428 | 4876 /* #### urk urk urk! Aborts are not very fun! Fix this please! */ |
826 | 4877 data.byte_charpos = 0; |
428 | 4878 else |
826 | 4879 INC_BYTECOUNT (XSTRING_DATA (disp_string), data.byte_charpos); |
428 | 4880 } |
4881 | |
4882 /* If there are end glyphs, add them to the line. These are | |
4883 the end glyphs for the previous run of text. We add them | |
4884 here rather than doing them at the end of handling the | |
4885 previous run so that glyphs at the beginning and end of | |
4886 a line are handled correctly. */ | |
4887 else if (Dynarr_length (data.ef->end_glyphs) > 0) | |
4888 { | |
867 | 4889 data.ch = string_ichar (disp_string, data.byte_charpos); |
428 | 4890 *prop = add_glyph_runes (&data, END_GLYPHS); |
819 | 4891 |
4892 if (*prop) { | |
428 | 4893 goto done; |
819 | 4894 } |
428 | 4895 } |
4896 | |
4897 /* If there are begin glyphs, add them to the line. */ | |
4898 else if (Dynarr_length (data.ef->begin_glyphs) > 0) | |
4899 { | |
867 | 4900 data.ch = string_ichar (disp_string, data.byte_charpos); |
428 | 4901 *prop = add_glyph_runes (&data, BEGIN_GLYPHS); |
819 | 4902 |
4903 if (*prop) { | |
428 | 4904 goto done; |
819 | 4905 } |
428 | 4906 } |
4907 | |
4908 /* If at end-of-buffer, we've already processed begin and | |
4909 end-glyphs at this point and there's no text to process, | |
4910 so we're done. */ | |
826 | 4911 else if (data.byte_charpos == byte_string_zv) |
428 | 4912 goto done; |
4913 | |
4914 else | |
4915 { | |
4916 Lisp_Object entry = Qnil; | |
4917 /* Get the character at the current buffer position. */ | |
867 | 4918 data.ch = string_ichar (disp_string, data.byte_charpos); |
428 | 4919 if (!NILP (face_dt) || !NILP (window_dt)) |
4920 entry = display_table_entry (data.ch, face_dt, window_dt); | |
4921 | |
4922 /* If there is a display table entry for it, hand it off to | |
4187 | 4923 add_disp_table_entry_runes and let it worry about it. */ |
428 | 4924 if (!NILP (entry) && !EQ (entry, make_char (data.ch))) |
4925 { | |
4926 *prop = add_disp_table_entry_runes (&data, entry); | |
4927 | |
4928 if (*prop) | |
4929 goto done; | |
4930 } | |
4931 | |
4932 /* Check if we have hit a newline character. If so, add a marker | |
4187 | 4933 to the line and end this loop. */ |
428 | 4934 else if (data.ch == '\n') |
4935 { | |
4936 /* We aren't going to be adding an end glyph so give its | |
4187 | 4937 space back in order to make sure that the cursor can |
4938 fit. */ | |
819 | 4939 data.max_pixpos += data.end_glyph_width; |
428 | 4940 goto done; |
4941 } | |
4942 | |
4943 /* If the current character is considered to be printable, then | |
4187 | 4944 just add it. */ |
428 | 4945 else if (data.ch >= printable_min) |
4946 { | |
867 | 4947 *prop = add_ichar_rune (&data); |
428 | 4948 if (*prop) |
4949 goto done; | |
4950 } | |
4951 | |
4952 /* If the current character is a tab, determine the next tab | |
4187 | 4953 starting position and add a blank rune which extends from the |
4954 current pixel position to that starting position. */ | |
428 | 4955 else if (data.ch == '\t') |
4956 { | |
4957 int tab_start_pixpos = data.pixpos; | |
4958 int next_tab_start; | |
4959 int char_tab_width; | |
4960 int prop_width = 0; | |
4961 | |
4962 if (data.start_col > 1) | |
4963 tab_start_pixpos -= (space_width (w) * (data.start_col - 1)); | |
4964 | |
4965 next_tab_start = | |
4966 next_tab_position (w, tab_start_pixpos, | |
4967 dl->bounds.left_in + | |
4968 data.hscroll_glyph_width_adjust); | |
4969 if (next_tab_start > data.max_pixpos) | |
4970 { | |
4971 prop_width = next_tab_start - data.max_pixpos; | |
4972 next_tab_start = data.max_pixpos; | |
4973 } | |
4974 data.blank_width = next_tab_start - data.pixpos; | |
4975 char_tab_width = | |
4976 (next_tab_start - tab_start_pixpos) / space_width (w); | |
4977 | |
4978 *prop = add_blank_rune (&data, w, char_tab_width); | |
4979 | |
4980 /* add_blank_rune is only supposed to be called with | |
819 | 4981 sizes guaranteed to fit in the available space. */ |
428 | 4982 assert (!(*prop)); |
4983 | |
4984 if (prop_width) | |
4985 { | |
4986 struct prop_block pb; | |
4987 *prop = Dynarr_new (prop_block); | |
4988 | |
4989 pb.type = PROP_BLANK; | |
4990 pb.data.p_blank.width = prop_width; | |
4991 pb.data.p_blank.findex = data.findex; | |
4992 Dynarr_add (*prop, pb); | |
4993 | |
4994 goto done; | |
4995 } | |
4996 } | |
4997 | |
4998 /* If character is a control character, pass it off to | |
4187 | 4999 add_control_char_runes. |
428 | 5000 |
5001 The is_*() routines have undefined results on | |
5002 arguments outside of the range [-1, 255]. (This | |
5003 often bites people who carelessly use `char' instead | |
5004 of `unsigned char'.) | |
5005 */ | |
867 | 5006 else if (data.ch < 0x100 && iscntrl ((Ibyte) data.ch)) |
428 | 5007 { |
5008 *prop = add_control_char_runes (&data, b); | |
5009 | |
5010 if (*prop) | |
5011 goto done; | |
5012 } | |
5013 | |
5014 /* If the character is above the ASCII range and we have not | |
4187 | 5015 already handled it, then print it as an octal number. */ |
428 | 5016 else if (data.ch >= 0200) |
5017 { | |
5018 *prop = add_octal_runes (&data); | |
5019 | |
5020 if (*prop) | |
5021 goto done; | |
5022 } | |
5023 | |
5024 /* Assume the current character is considered to be printable, | |
4187 | 5025 then just add it. */ |
428 | 5026 else |
5027 { | |
867 | 5028 *prop = add_ichar_rune (&data); |
428 | 5029 if (*prop) |
5030 goto done; | |
5031 } | |
5032 | |
826 | 5033 INC_BYTECOUNT (XSTRING_DATA (disp_string), data.byte_charpos); |
428 | 5034 } |
5035 } | |
5036 | |
819 | 5037 done: |
428 | 5038 |
5039 /* Determine the starting point of the next line if we did not hit the | |
5040 end of the buffer. */ | |
826 | 5041 if (data.byte_charpos < byte_string_zv) |
428 | 5042 { |
5043 /* #### This check is not correct. If the line terminated | |
5044 due to a begin-glyph or end-glyph hitting window-end, then | |
826 | 5045 data.ch will not point to the character at data.byte_charpos. If |
428 | 5046 you make the two changes mentioned at the top of this loop, |
5047 you should be able to say '(if (*prop))'. That should also | |
826 | 5048 make it possible to eliminate the data.byte_charpos < BYTE_BUF_ZV (b) |
428 | 5049 check. */ |
5050 | |
5051 /* The common case is that the line ended because we hit a newline. | |
4187 | 5052 In that case, the next character is just the next buffer |
5053 position. */ | |
428 | 5054 if (data.ch == '\n') |
5055 { | |
826 | 5056 INC_BYTECOUNT (XSTRING_DATA (disp_string), data.byte_charpos); |
428 | 5057 } |
5058 | |
5059 /* Otherwise we have a buffer line which cannot fit on one display | |
4187 | 5060 line. */ |
428 | 5061 else |
5062 { | |
5063 struct glyph_block gb; | |
5064 struct glyph_cachel *cachel; | |
5065 | |
5066 /* If the line is to be truncated then we actually have to look | |
4187 | 5067 for the next newline. We also add the end-of-line glyph which |
5068 we know will fit because we adjusted the right border before | |
5069 we starting laying out the line. */ | |
819 | 5070 data.max_pixpos += data.end_glyph_width; |
428 | 5071 data.findex = default_face; |
5072 gb.extent = Qnil; | |
5073 | |
5074 if (truncate_win) | |
5075 { | |
826 | 5076 Bytecount byte_pos; |
428 | 5077 |
5078 /* Now find the start of the next line. */ | |
867 | 5079 byte_pos = byte_find_next_ichar_in_string (disp_string, '\n', |
826 | 5080 data.byte_charpos, 1); |
428 | 5081 |
5082 data.cursor_type = NO_CURSOR; | |
826 | 5083 data.byte_charpos = byte_pos; |
428 | 5084 gb.glyph = Vtruncation_glyph; |
5085 cachel = GLYPH_CACHEL (w, TRUN_GLYPH_INDEX); | |
5086 } | |
5087 else | |
5088 { | |
5089 /* The cursor can never be on the continuation glyph. */ | |
5090 data.cursor_type = NO_CURSOR; | |
5091 | |
826 | 5092 /* data.byte_charpos is already at the start of the next line. */ |
428 | 5093 |
442 | 5094 dl->line_continuation = 1; |
428 | 5095 gb.glyph = Vcontinuation_glyph; |
5096 cachel = GLYPH_CACHEL (w, CONT_GLYPH_INDEX); | |
5097 } | |
5098 | |
819 | 5099 if (data.end_glyph_width) |
428 | 5100 add_glyph_rune (&data, &gb, BEGIN_GLYPHS, 0, cachel); |
5101 | |
826 | 5102 if (truncate_win && data.byte_charpos == byte_string_zv) |
428 | 5103 { |
867 | 5104 const Ibyte *endb = itext_n_addr (XSTRING_DATA (disp_string), |
826 | 5105 byte_string_zv); |
867 | 5106 DEC_IBYTEPTR (endb); |
5107 if (itext_ichar (endb) != '\n') | |
428 | 5108 { |
5109 /* #### Damn this losing shit. */ | |
826 | 5110 data.byte_charpos++; |
428 | 5111 } |
5112 } | |
5113 } | |
5114 } | |
826 | 5115 else if (data.byte_charpos == byte_string_zv) |
428 | 5116 { |
5117 /* create_text_block () adds a bogus \n marker here which screws | |
5118 up subwindow display. Since we never have a cursor in the | |
5119 gutter we can safely ignore it. */ | |
5120 } | |
5121 /* Calculate left whitespace boundary. */ | |
5122 { | |
5123 int elt = 0; | |
5124 | |
5125 /* Whitespace past a newline is considered right whitespace. */ | |
5126 while (elt < Dynarr_length (db->runes)) | |
5127 { | |
5128 struct rune *rb = Dynarr_atp (db->runes, elt); | |
5129 | |
5130 if ((rb->type == RUNE_CHAR && rb->object.chr.ch == ' ') | |
5131 || rb->type == RUNE_BLANK) | |
5132 { | |
5133 dl->bounds.left_white += rb->width; | |
5134 elt++; | |
5135 } | |
5136 else | |
5137 elt = Dynarr_length (db->runes); | |
5138 } | |
5139 } | |
5140 | |
5141 /* Calculate right whitespace boundary. */ | |
5142 { | |
5143 int elt = Dynarr_length (db->runes) - 1; | |
5144 int done = 0; | |
5145 | |
5146 while (!done && elt >= 0) | |
5147 { | |
5148 struct rune *rb = Dynarr_atp (db->runes, elt); | |
5149 | |
5150 if (!(rb->type == RUNE_CHAR && rb->object.chr.ch < 0x100 | |
5151 && isspace (rb->object.chr.ch)) | |
5152 && !rb->type == RUNE_BLANK) | |
5153 { | |
5154 dl->bounds.right_white = rb->xpos + rb->width; | |
5155 done = 1; | |
5156 } | |
5157 | |
5158 elt--; | |
5159 | |
5160 } | |
5161 | |
5162 /* The line is blank so everything is considered to be right | |
5163 whitespace. */ | |
5164 if (!done) | |
5165 dl->bounds.right_white = dl->bounds.left_in; | |
5166 } | |
5167 | |
5168 /* Set the display blocks bounds. */ | |
5169 db->start_pos = dl->bounds.left_in; | |
5170 if (Dynarr_length (db->runes)) | |
5171 { | |
4844
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4815
diff
changeset
|
5172 struct rune *rb = Dynarr_lastp (db->runes); |
428 | 5173 |
5174 db->end_pos = rb->xpos + rb->width; | |
5175 } | |
5176 else | |
5177 db->end_pos = dl->bounds.right_white; | |
5178 | |
819 | 5179 calculate_baseline (&data); |
428 | 5180 |
5181 dl->ascent = data.new_ascent; | |
5182 dl->descent = data.new_descent; | |
5183 | |
5184 { | |
5185 unsigned short ascent = (unsigned short) XINT (w->minimum_line_ascent); | |
5186 | |
5187 if (dl->ascent < ascent) | |
5188 dl->ascent = ascent; | |
5189 } | |
5190 { | |
5191 unsigned short descent = (unsigned short) XINT (w->minimum_line_descent); | |
5192 | |
5193 if (dl->descent < descent) | |
5194 dl->descent = descent; | |
5195 } | |
5196 | |
819 | 5197 calculate_yoffset (dl, db); |
5198 | |
428 | 5199 dl->cursor_elt = data.cursor_x; |
5200 /* #### lossage lossage lossage! Fix this shit! */ | |
826 | 5201 if (data.byte_charpos > byte_string_zv) |
5202 dl->end_charpos = buffer_or_string_bytexpos_to_charxpos (disp_string, | |
5203 byte_string_zv); | |
428 | 5204 else |
826 | 5205 dl->end_charpos = |
5206 buffer_or_string_bytexpos_to_charxpos (disp_string, | |
5207 data.byte_charpos) - 1; | |
428 | 5208 if (truncate_win) |
434 | 5209 data.dl->num_chars = |
826 | 5210 string_column_at_point (disp_string, dl->end_charpos, |
793 | 5211 b ? XINT (b->tab_width) : 8); |
428 | 5212 else |
5213 /* This doesn't correctly take into account tabs and control | |
5214 characters but if the window isn't being truncated then this | |
5215 value isn't going to end up being used anyhow. */ | |
826 | 5216 data.dl->num_chars = dl->end_charpos - dl->charpos; |
428 | 5217 |
5218 /* #### handle horizontally scrolled line with text none of which | |
5219 was actually laid out. */ | |
5220 | |
5221 /* #### handle any remainder of overlay arrow */ | |
5222 | |
5223 if (*prop == ADD_FAILED) | |
5224 *prop = NULL; | |
5225 | |
5226 if (truncate_win && *prop) | |
5227 { | |
5228 Dynarr_free (*prop); | |
5229 *prop = NULL; | |
5230 } | |
5231 | |
5232 extent_fragment_delete (data.ef); | |
5233 | |
5234 /* #### If we started at EOB, then make sure we return a value past | |
5235 it so that regenerate_window will exit properly. This is bogus. | |
5236 The main loop should get fixed so that it isn't necessary to call | |
5237 this function if we are already at EOB. */ | |
5238 | |
826 | 5239 if (data.byte_charpos == byte_string_zv && byte_start_pos == byte_string_zv) |
793 | 5240 return string_index_byte_to_char (disp_string, |
826 | 5241 data.byte_charpos) + 1; /* Yuck! */ |
428 | 5242 else |
826 | 5243 return string_index_byte_to_char (disp_string, data.byte_charpos); |
428 | 5244 } |
5245 | |
5246 /* Given a display line and a starting position, ensure that the | |
5247 contents of the display line accurately represent the visual | |
5248 representation of the buffer contents starting from the given | |
5249 position when displayed in the given window. The display line ends | |
5250 when the contents of the line reach the right boundary of the given | |
434 | 5251 window. |
5252 | |
428 | 5253 This is very similar to generate_display_line but with the same |
5254 limitations as create_string_text_block. I have taken the liberty | |
665 | 5255 of fixing the bytebpos stuff though.*/ |
5256 | |
5257 static Charbpos | |
428 | 5258 generate_string_display_line (struct window *w, Lisp_Object disp_string, |
5259 struct display_line *dl, | |
826 | 5260 Charcount start_pos, |
428 | 5261 prop_block_dynarr **prop, |
5262 face_index default_face) | |
5263 { | |
826 | 5264 Charcount ret_charcount; |
428 | 5265 |
5266 /* you must set bounds before calling this. */ | |
434 | 5267 |
428 | 5268 /* Reset what this line is using. */ |
5269 if (dl->display_blocks) | |
5270 Dynarr_reset (dl->display_blocks); | |
5271 if (dl->left_glyphs) | |
5272 { | |
5273 Dynarr_free (dl->left_glyphs); | |
5274 dl->left_glyphs = 0; | |
5275 } | |
5276 if (dl->right_glyphs) | |
5277 { | |
5278 Dynarr_free (dl->right_glyphs); | |
5279 dl->right_glyphs = 0; | |
5280 } | |
5281 | |
5282 /* We aren't generating a modeline at the moment. */ | |
5283 dl->modeline = 0; | |
5284 | |
5285 /* Create a display block for the text region of the line. */ | |
826 | 5286 ret_charcount = create_string_text_block (w, disp_string, dl, start_pos, |
5287 prop, default_face); | |
5288 dl->charpos = start_pos; | |
5289 if (dl->end_charpos < dl->charpos) | |
5290 dl->end_charpos = dl->charpos; | |
428 | 5291 |
5292 /* If there are left glyphs associated with any character in the | |
5293 text block, then create a display block to handle them. */ | |
5294 if (dl->left_glyphs != NULL && Dynarr_length (dl->left_glyphs)) | |
5295 create_left_glyph_block (w, dl, 0); | |
5296 | |
5297 /* If there are right glyphs associated with any character in the | |
5298 text block, then create a display block to handle them. */ | |
5299 if (dl->right_glyphs != NULL && Dynarr_length (dl->right_glyphs)) | |
5300 create_right_glyph_block (w, dl); | |
5301 | |
826 | 5302 return ret_charcount; |
428 | 5303 } |
5304 | |
2518 | 5305 /* |
5306 | |
5038 | 5307 Info on reentrancy crashes, with backtraces given: |
5308 | |
5309 (Info-goto-node "(internals)Critical Redisplay Sections") | |
5310 | |
1318 | 5311 */ |
5312 | |
5313 | |
428 | 5314 /* This is ripped off from regenerate_window. All we want to do is |
5315 loop through elements in the string creating display lines until we | |
5316 have covered the provided area. Simple really. */ | |
5317 void | |
5318 generate_displayable_area (struct window *w, Lisp_Object disp_string, | |
5319 int xpos, int ypos, int width, int height, | |
5320 display_line_dynarr* dla, | |
826 | 5321 Charcount start_pos, |
428 | 5322 face_index default_face) |
5323 { | |
5324 int yend = ypos + height; | |
5325 Charcount s_zv; | |
5326 prop_block_dynarr *prop = 0; | |
5327 layout_bounds bounds; | |
2518 | 5328 int depth = -1; |
5329 | |
428 | 5330 /* if there's nothing to do then do nothing. code after this assumes |
5331 there is something to do. */ | |
5332 if (NILP (disp_string)) | |
5333 return; | |
5334 | |
2518 | 5335 /* See comment in regenerate_window() */ |
5336 if (!in_display) | |
5337 depth = enter_redisplay_critical_section (); | |
5338 | |
5339 assert (dla); | |
5340 Dynarr_reset (dla); | |
5341 | |
826 | 5342 s_zv = string_char_length (disp_string); |
428 | 5343 |
5344 bounds.left_out = xpos; | |
5345 bounds.right_out = xpos + width; | |
5346 /* The inner boundaries mark where the glyph margins are located. */ | |
5347 bounds.left_in = bounds.left_out + window_left_margin_width (w); | |
5348 bounds.right_in = bounds.right_out - window_right_margin_width (w); | |
5349 /* We cannot fully calculate the whitespace boundaries as they | |
5350 depend on the contents of the line being displayed. */ | |
5351 bounds.left_white = bounds.left_in; | |
5352 bounds.right_white = bounds.right_in; | |
5353 | |
5354 while (ypos < yend) | |
5355 { | |
5356 struct display_line dl; | |
5357 struct display_line *dlp; | |
826 | 5358 Charcount next_pos; |
428 | 5359 int local; |
851 | 5360 int pos_of_dlp = -1; |
428 | 5361 |
5362 if (Dynarr_length (dla) < Dynarr_largest (dla)) | |
5363 { | |
851 | 5364 pos_of_dlp = Dynarr_length (dla); |
5365 dlp = Dynarr_atp (dla, pos_of_dlp); | |
428 | 5366 local = 0; |
5367 } | |
5368 else | |
5369 { | |
4207 | 5370 DISPLAY_LINE_INIT (dl); |
428 | 5371 dlp = &dl; |
5372 local = 1; | |
5373 } | |
5374 | |
5375 dlp->bounds = bounds; | |
5376 dlp->offset = 0; | |
1318 | 5377 Dynarr_lock (dla); |
428 | 5378 next_pos = generate_string_display_line (w, disp_string, dlp, start_pos, |
5379 &prop, default_face); | |
1318 | 5380 Dynarr_unlock (dla); |
428 | 5381 /* we need to make sure that we continue along the line if there |
4187 | 5382 is more left to display otherwise we just end up redisplaying |
5383 the same chunk over and over again. */ | |
428 | 5384 if (next_pos == start_pos && next_pos < s_zv) |
5385 start_pos++; | |
5386 else | |
5387 start_pos = next_pos; | |
5388 | |
5389 dlp->ypos = ypos + dlp->ascent; | |
5390 ypos = dlp->ypos + dlp->descent; | |
5391 | |
5392 if (ypos > yend) | |
5393 { | |
5394 int visible_height = dlp->ascent + dlp->descent; | |
5395 | |
5396 dlp->clip = (ypos - yend); | |
5397 visible_height -= dlp->clip; | |
5398 | |
5399 if (visible_height < VERTICAL_CLIP (w, 1)) | |
5400 { | |
5401 if (local) | |
5402 free_display_line (dlp); | |
5403 break; | |
5404 } | |
5405 } | |
5406 else | |
5407 dlp->clip = 0; | |
5408 | |
4418
9bcdf9a3a783
Use Dynarr_increment instead of Dynarr_add when building a line in place.
Jerry James <james@xemacs.org>
parents:
4207
diff
changeset
|
5409 if (pos_of_dlp < 0) |
9bcdf9a3a783
Use Dynarr_increment instead of Dynarr_add when building a line in place.
Jerry James <james@xemacs.org>
parents:
4207
diff
changeset
|
5410 Dynarr_add (dla, *dlp); |
9bcdf9a3a783
Use Dynarr_increment instead of Dynarr_add when building a line in place.
Jerry James <james@xemacs.org>
parents:
4207
diff
changeset
|
5411 else if (pos_of_dlp == Dynarr_length (dla)) |
5038 | 5412 Dynarr_incrementr (dla); |
4418
9bcdf9a3a783
Use Dynarr_increment instead of Dynarr_add when building a line in place.
Jerry James <james@xemacs.org>
parents:
4207
diff
changeset
|
5413 else |
9bcdf9a3a783
Use Dynarr_increment instead of Dynarr_add when building a line in place.
Jerry James <james@xemacs.org>
parents:
4207
diff
changeset
|
5414 ABORT (); |
428 | 5415 |
5416 /* #### This type of check needs to be done down in the | |
5417 generate_display_line call. */ | |
5418 if (start_pos >= s_zv) | |
5419 break; | |
5420 } | |
5421 | |
5422 if (prop) | |
5423 Dynarr_free (prop); | |
2518 | 5424 |
5425 if (depth >= 0) | |
5426 exit_redisplay_critical_section (depth); | |
428 | 5427 } |
5428 | |
5429 | |
5430 /***************************************************************************/ | |
5431 /* */ | |
5432 /* window-regeneration routines */ | |
5433 /* */ | |
5434 /***************************************************************************/ | |
5435 | |
5436 /* For a given window and starting position in the buffer it contains, | |
5437 ensure that the TYPE display lines accurately represent the | |
5438 presentation of the window. We pass the buffer instead of getting | |
5439 it from the window since redisplay_window may have temporarily | |
5440 changed it to the echo area buffer. */ | |
5441 | |
5442 static void | |
2518 | 5443 regenerate_window (struct window *w, Charbpos start_pos, Charbpos point, |
5444 int type) | |
428 | 5445 { |
5446 struct frame *f = XFRAME (w->frame); | |
5447 struct buffer *b = XBUFFER (w->buffer); | |
5448 int ypos = WINDOW_TEXT_TOP (w); | |
5449 int yend; /* set farther down */ | |
5450 int yclip = WINDOW_TEXT_TOP_CLIP (w); | |
442 | 5451 int force; |
2518 | 5452 int depth = -1; |
428 | 5453 |
5454 prop_block_dynarr *prop; | |
5455 layout_bounds bounds; | |
5456 display_line_dynarr *dla; | |
5457 int need_modeline; | |
5458 | |
5459 /* The lines had better exist by this point. */ | |
5460 if (!(dla = window_display_lines (w, type))) | |
2500 | 5461 ABORT (); |
2518 | 5462 |
5463 if (!in_display) | |
5464 depth = enter_redisplay_critical_section (); | |
5465 | |
5038 | 5466 /* This is one spot where a reentrancy crash will occur, due to a check |
2518 | 5467 in the dynarr to make sure it isn't "locked" */ |
5468 /* | |
5469 | |
5038 | 5470 Info on reentrancy crashes, with backtraces given: |
5471 | |
5472 (Info-goto-node "(internals)Critical Redisplay Sections") | |
2518 | 5473 */ |
5474 | |
428 | 5475 Dynarr_reset (dla); |
5476 w->max_line_len = 0; | |
5477 | |
4968 | 5478 /* Added 2-1-10 -- we should never have empty face or glyph cachels |
5479 because we initialized them at startup and the only way to reduce | |
5480 their number is through calling reset_face_cachels() or | |
5481 reset_glyph_cachels(), which as a side effect sets up a number of | |
5482 standard entries */ | |
5483 assert (Dynarr_length (w->face_cachels)); | |
5484 assert (Dynarr_length (w->glyph_cachels)); | |
5485 | |
5486 #if 0 | |
5487 /* #### Delete this code sometime later than 2-1-10 when we're sure it's | |
5488 not needed */ | |
428 | 5489 /* Normally these get updated in redisplay_window but it is possible |
5490 for this function to get called from some other points where that | |
5491 update may not have occurred. This acts as a safety check. */ | |
5492 if (!Dynarr_length (w->face_cachels)) | |
5493 reset_face_cachels (w); | |
5494 if (!Dynarr_length (w->glyph_cachels)) | |
5495 reset_glyph_cachels (w); | |
4968 | 5496 #endif |
428 | 5497 |
5498 Fset_marker (w->start[type], make_int (start_pos), w->buffer); | |
5499 Fset_marker (w->pointm[type], make_int (point), w->buffer); | |
5500 w->last_point_x[type] = -1; | |
5501 w->last_point_y[type] = -1; | |
5502 | |
5503 /* Make sure a modeline is in the structs if needed. */ | |
5504 need_modeline = ensure_modeline_generated (w, type); | |
5505 | |
5506 /* Wait until here to set this so that the structs have a modeline | |
5507 generated in the case where one didn't exist. */ | |
5508 yend = WINDOW_TEXT_BOTTOM (w); | |
5509 | |
5510 bounds = calculate_display_line_boundaries (w, 0); | |
5511 | |
5512 /* 97/3/14 jhod: stuff added here to support pre-prompts (used for input systems) */ | |
5513 if (MINI_WINDOW_P (w) | |
5514 && (!NILP (Vminibuf_prompt) || !NILP (Vminibuf_preprompt)) | |
5515 && !echo_area_active (f) | |
5516 && start_pos == BUF_BEGV (b)) | |
5517 { | |
5518 struct prop_block pb; | |
5519 Lisp_Object string; | |
5520 prop = Dynarr_new (prop_block); | |
5521 | |
5198 | 5522 string = concat2 (Vminibuf_preprompt, Vminibuf_prompt); |
428 | 5523 pb.type = PROP_MINIBUF_PROMPT; |
5198 | 5524 pb.data.p_string.str = XSTRING_DATA (string); |
5525 pb.data.p_string.len = XSTRING_LENGTH (string); | |
428 | 5526 Dynarr_add (prop, pb); |
5527 } | |
5528 else | |
5529 prop = 0; | |
5530 | |
442 | 5531 /* When we are computing things for scrolling purposes, make |
5532 sure at least one line is always generated */ | |
5533 force = (type == CMOTION_DISP); | |
5534 | |
5535 /* Make sure this is set always */ | |
5536 /* Note the conversion at end */ | |
5537 w->window_end_pos[type] = start_pos; | |
5538 while (ypos < yend || force) | |
428 | 5539 { |
5540 struct display_line dl; | |
5541 struct display_line *dlp; | |
5542 int local; | |
851 | 5543 int pos_of_dlp = -1; |
428 | 5544 |
5545 if (Dynarr_length (dla) < Dynarr_largest (dla)) | |
5546 { | |
851 | 5547 pos_of_dlp = Dynarr_length (dla); |
5548 dlp = Dynarr_atp (dla, pos_of_dlp); | |
428 | 5549 local = 0; |
5550 } | |
5551 else | |
5552 { | |
4207 | 5553 DISPLAY_LINE_INIT (dl); |
428 | 5554 dlp = &dl; |
5555 local = 1; | |
5556 } | |
5557 | |
5558 dlp->bounds = bounds; | |
5559 dlp->offset = 0; | |
1318 | 5560 Dynarr_lock (dla); |
428 | 5561 start_pos = generate_display_line (w, dlp, 1, start_pos, &prop, type); |
1318 | 5562 Dynarr_unlock (dla); |
428 | 5563 |
5564 if (yclip > dlp->ascent) | |
5565 { | |
5566 /* this should never happen, but if it does just display the | |
5567 whole line */ | |
5568 yclip = 0; | |
5569 } | |
5570 | |
5571 dlp->ypos = (ypos + dlp->ascent) - yclip; | |
5572 ypos = dlp->ypos + dlp->descent; | |
5573 | |
5574 /* See if we've been asked to start midway through a line, for | |
4187 | 5575 partial display line scrolling. */ |
434 | 5576 if (yclip) |
428 | 5577 { |
5578 dlp->top_clip = yclip; | |
5579 yclip = 0; | |
5580 } | |
5581 else | |
5582 dlp->top_clip = 0; | |
5583 | |
5584 if (ypos > yend) | |
5585 { | |
5586 int visible_height = dlp->ascent + dlp->descent; | |
5587 | |
5588 dlp->clip = (ypos - yend); | |
5589 /* Although this seems strange we could have a single very | |
5590 tall line visible for which we need to account for both | |
5591 the top clip and the bottom clip. */ | |
5592 visible_height -= (dlp->clip + dlp->top_clip); | |
5593 | |
442 | 5594 if (visible_height < VERTICAL_CLIP (w, 1) && !force) |
428 | 5595 { |
5596 if (local) | |
5597 free_display_line (dlp); | |
5598 break; | |
5599 } | |
5600 } | |
5601 else | |
5602 dlp->clip = 0; | |
5603 | |
5604 if (dlp->cursor_elt != -1) | |
5605 { | |
5606 /* #### This check is steaming crap. Have to get things | |
4187 | 5607 fixed so when create_text_block hits EOB, we're done, |
5608 period. */ | |
428 | 5609 if (w->last_point_x[type] == -1) |
5610 { | |
5611 w->last_point_x[type] = dlp->cursor_elt; | |
5612 w->last_point_y[type] = Dynarr_length (dla); | |
5613 } | |
5614 else | |
5615 { | |
5616 /* #### This means that we've added a cursor at EOB | |
4187 | 5617 twice. Yuck oh yuck. */ |
1318 | 5618 struct display_block *db; |
5619 | |
5620 Dynarr_lock (dla); | |
5621 db = get_display_block_from_line (dlp, TEXT); | |
5622 Dynarr_unlock (dla); | |
428 | 5623 |
5624 Dynarr_atp (db->runes, dlp->cursor_elt)->cursor_type = NO_CURSOR; | |
5625 dlp->cursor_elt = -1; | |
5626 } | |
5627 } | |
5628 | |
5629 if (dlp->num_chars > w->max_line_len) | |
5630 w->max_line_len = dlp->num_chars; | |
5631 | |
4418
9bcdf9a3a783
Use Dynarr_increment instead of Dynarr_add when building a line in place.
Jerry James <james@xemacs.org>
parents:
4207
diff
changeset
|
5632 if (pos_of_dlp < 0) |
9bcdf9a3a783
Use Dynarr_increment instead of Dynarr_add when building a line in place.
Jerry James <james@xemacs.org>
parents:
4207
diff
changeset
|
5633 Dynarr_add (dla, *dlp); |
9bcdf9a3a783
Use Dynarr_increment instead of Dynarr_add when building a line in place.
Jerry James <james@xemacs.org>
parents:
4207
diff
changeset
|
5634 else if (pos_of_dlp == Dynarr_length (dla)) |
5038 | 5635 Dynarr_incrementr (dla); |
4418
9bcdf9a3a783
Use Dynarr_increment instead of Dynarr_add when building a line in place.
Jerry James <james@xemacs.org>
parents:
4207
diff
changeset
|
5636 else |
9bcdf9a3a783
Use Dynarr_increment instead of Dynarr_add when building a line in place.
Jerry James <james@xemacs.org>
parents:
4207
diff
changeset
|
5637 ABORT (); |
428 | 5638 |
5639 /* #### This isn't right, but it is close enough for now. */ | |
5640 w->window_end_pos[type] = start_pos; | |
5641 | |
5642 /* #### This type of check needs to be done down in the | |
5643 generate_display_line call. */ | |
5644 if (start_pos > BUF_ZV (b)) | |
5645 break; | |
442 | 5646 |
5647 force = 0; | |
428 | 5648 } |
5649 | |
5650 if (prop) | |
5651 Dynarr_free (prop); | |
5652 | |
5653 /* #### More not quite right, but close enough. */ | |
442 | 5654 /* Ben sez: apparently window_end_pos[] is measured |
428 | 5655 as the number of characters between the window end and the |
5656 end of the buffer? This seems rather weirdo. What's | |
442 | 5657 the justification for this? |
5658 | |
5659 JV sez: Because BUF_Z (b) would be a good initial value, however | |
5660 that can change. This representation allows initalizing with 0. | |
5661 */ | |
428 | 5662 w->window_end_pos[type] = BUF_Z (b) - w->window_end_pos[type]; |
5663 | |
5664 if (need_modeline) | |
5665 { | |
5666 /* We know that this is the right thing to use because we put it | |
4187 | 5667 there when we first started working in this function. */ |
4967 | 5668 generate_modeline (w, Dynarr_begin (dla), type); |
428 | 5669 } |
2518 | 5670 |
5671 if (depth >= 0) | |
5672 exit_redisplay_critical_section (depth); | |
428 | 5673 } |
5674 | |
826 | 5675 #define REGEN_INC_FIND_START_END \ |
5676 do { \ | |
5677 /* Determine start and end of lines. */ \ | |
5678 if (!Dynarr_length (cdla)) \ | |
5679 return 0; \ | |
5680 else \ | |
5681 { \ | |
4967 | 5682 if (Dynarr_begin (cdla)->modeline && Dynarr_begin (ddla)->modeline) \ |
826 | 5683 { \ |
5684 dla_start = 1; \ | |
5685 } \ | |
4967 | 5686 else if (!Dynarr_begin (cdla)->modeline \ |
5687 && !Dynarr_begin (ddla)->modeline) \ | |
826 | 5688 { \ |
5689 dla_start = 0; \ | |
5690 } \ | |
5691 else \ | |
2500 | 5692 ABORT (); /* structs differ */ \ |
826 | 5693 \ |
5694 dla_end = Dynarr_length (cdla) - 1; \ | |
5695 } \ | |
5696 \ | |
5697 start_pos = (Dynarr_atp (cdla, dla_start)->charpos \ | |
5698 + Dynarr_atp (cdla, dla_start)->offset); \ | |
5699 /* If this isn't true, then startp has changed and we need to do a \ | |
5700 full regen. */ \ | |
5701 if (startp != start_pos) \ | |
5702 return 0; \ | |
5703 \ | |
5704 /* Point is outside the visible region so give up. */ \ | |
5705 if (pointm < start_pos) \ | |
5706 return 0; \ | |
5707 \ | |
428 | 5708 } while (0) |
5709 | |
5710 /* This attempts to incrementally update the display structures. It | |
5711 returns a boolean indicating success or failure. This function is | |
5712 very similar to regenerate_window_incrementally and is in fact only | |
5713 called from that function. However, because of the nature of the | |
5714 changes it deals with it sometimes makes different assumptions | |
5715 which can lead to success which are much more difficult to make | |
5716 when dealing with buffer changes. */ | |
5717 | |
5718 static int | |
665 | 5719 regenerate_window_extents_only_changed (struct window *w, Charbpos startp, |
5720 Charbpos pointm, | |
428 | 5721 Charcount beg_unchanged, |
5722 Charcount end_unchanged) | |
5723 { | |
5724 struct buffer *b = XBUFFER (w->buffer); | |
5725 display_line_dynarr *cdla = window_display_lines (w, CURRENT_DISP); | |
5726 display_line_dynarr *ddla = window_display_lines (w, DESIRED_DISP); | |
5727 | |
5728 int dla_start = 0; | |
5729 int dla_end, line; | |
5730 int first_line, last_line; | |
665 | 5731 Charbpos start_pos; |
428 | 5732 /* Don't define this in the loop where it is used because we |
5733 definitely want its value to survive between passes. */ | |
5734 prop_block_dynarr *prop = NULL; | |
5735 | |
5736 /* If we don't have any buffer change recorded but the modiff flag has | |
5737 been incremented, then fail. I'm not sure of the exact circumstances | |
5738 under which this can happen, but I believe that it is probably a | |
5739 reasonable happening. */ | |
5740 if (!point_visible (w, pointm, CURRENT_DISP) | |
5741 || XINT (w->last_modified[CURRENT_DISP]) < BUF_MODIFF (b)) | |
5742 return 0; | |
5743 | |
5744 /* If the cursor is moved we attempt to update it. If we succeed we | |
5745 go ahead and proceed with the optimization attempt. */ | |
5746 if (!EQ (Fmarker_buffer (w->last_point[CURRENT_DISP]), w->buffer) | |
5747 || pointm != marker_position (w->last_point[CURRENT_DISP])) | |
5748 { | |
5749 struct frame *f = XFRAME (w->frame); | |
5750 struct device *d = XDEVICE (f->device); | |
5751 struct frame *sel_f = device_selected_frame (d); | |
5752 int success = 0; | |
5753 | |
5754 if (w->last_point_x[CURRENT_DISP] != -1 | |
5755 && w->last_point_y[CURRENT_DISP] != -1) | |
5756 { | |
5757 | |
5758 if (redisplay_move_cursor (w, pointm, WINDOW_TTY_P (w))) | |
5759 { | |
5760 /* Always regenerate the modeline in case it is | |
4187 | 5761 displaying the current line or column. */ |
428 | 5762 regenerate_modeline (w); |
5763 success = 1; | |
5764 } | |
5765 } | |
5766 else if (w != XWINDOW (FRAME_SELECTED_WINDOW (sel_f))) | |
5767 { | |
5768 if (f->modeline_changed) | |
5769 regenerate_modeline (w); | |
5770 success = 1; | |
5771 } | |
5772 | |
5773 if (!success) | |
5774 return 0; | |
5775 } | |
5776 | |
5777 if (beg_unchanged == -1 && end_unchanged == -1) | |
5778 return 1; | |
5779 | |
5780 /* assert: There are no buffer modifications or they are all below the | |
5781 visible region. We assume that regenerate_window_incrementally has | |
5782 not called us unless this is true. */ | |
5783 | |
5784 REGEN_INC_FIND_START_END; | |
5785 | |
5786 /* If the changed are starts before the visible area, give up. */ | |
5787 if (beg_unchanged < startp) | |
5788 return 0; | |
5789 | |
5790 /* Find what display line the extent changes first affect. */ | |
5791 line = dla_start; | |
5792 while (line <= dla_end) | |
5793 { | |
5794 struct display_line *dl = Dynarr_atp (cdla, line); | |
826 | 5795 Charbpos lstart = dl->charpos + dl->offset; |
5796 Charbpos lend = dl->end_charpos + dl->offset; | |
428 | 5797 |
5798 if (beg_unchanged >= lstart && beg_unchanged <= lend) | |
5799 break; | |
5800 | |
5801 line++; | |
5802 } | |
5803 | |
5804 /* If the changes are below the visible area then if point hasn't | |
5805 moved return success otherwise fail in order to be safe. */ | |
5806 if (line > dla_end) | |
5807 { | |
5808 if (EQ (Fmarker_buffer (w->last_point[CURRENT_DISP]), w->buffer) | |
5809 && pointm == marker_position (w->last_point[CURRENT_DISP])) | |
5810 return 1; | |
5811 else | |
5812 return 0; | |
5813 } | |
5814 | |
5815 /* At this point we know what line the changes first affect. We now | |
5816 begin redrawing lines as long as we are still in the affected | |
5817 region and the line's size and positioning don't change. | |
5818 Otherwise we fail. If we fail we will have altered the desired | |
5819 structs which could lead to an assertion failure. However, if we | |
5820 fail the next thing that is going to happen is a full regen so we | |
5821 will actually end up being safe. */ | |
5822 w->last_modified[DESIRED_DISP] = make_int (BUF_MODIFF (b)); | |
5823 w->last_facechange[DESIRED_DISP] = make_int (BUF_FACECHANGE (b)); | |
5824 Fset_marker (w->last_start[DESIRED_DISP], make_int (startp), w->buffer); | |
5825 Fset_marker (w->last_point[DESIRED_DISP], make_int (pointm), w->buffer); | |
5826 | |
5827 first_line = last_line = line; | |
5828 while (line <= dla_end) | |
5829 { | |
2286 | 5830 Charbpos old_start, old_end; |
428 | 5831 struct display_line *cdl = Dynarr_atp (cdla, line); |
5832 struct display_line *ddl = Dynarr_atp (ddla, line); | |
5833 struct display_block *db; | |
5834 int initial_size; | |
5835 | |
826 | 5836 assert (cdl->charpos == ddl->charpos); |
5837 assert (cdl->end_charpos == ddl->end_charpos); | |
428 | 5838 assert (cdl->offset == ddl->offset); |
5839 | |
5840 db = get_display_block_from_line (ddl, TEXT); | |
5841 initial_size = Dynarr_length (db->runes); | |
826 | 5842 old_start = ddl->charpos + ddl->offset; |
5843 old_end = ddl->end_charpos + ddl->offset; | |
428 | 5844 |
5845 /* If this is the first line being updated and it used | |
4187 | 5846 propagation data, fail. Otherwise we'll be okay because |
5847 we'll have the necessary propagation data. */ | |
428 | 5848 if (line == first_line && ddl->used_prop_data) |
5849 return 0; | |
5850 | |
2286 | 5851 generate_display_line (w, ddl, 0, ddl->charpos + ddl->offset, |
5852 &prop, DESIRED_DISP); | |
428 | 5853 ddl->offset = 0; |
5854 | |
5855 /* #### If there is propagated stuff the fail. We could | |
4187 | 5856 probably actually deal with this if the line had propagated |
5857 information when originally created by a full | |
5858 regeneration. */ | |
428 | 5859 if (prop) |
5860 { | |
5861 Dynarr_free (prop); | |
5862 return 0; | |
5863 } | |
5864 | |
5865 /* If any line position parameters have changed or a | |
4187 | 5866 cursor has disappeared or disappeared, fail. */ |
428 | 5867 db = get_display_block_from_line (ddl, TEXT); |
5868 if (cdl->ypos != ddl->ypos | |
5869 || cdl->ascent != ddl->ascent | |
5870 || cdl->descent != ddl->descent | |
5871 || cdl->top_clip != ddl->top_clip | |
5872 || (cdl->cursor_elt != -1 && ddl->cursor_elt == -1) | |
5873 || (cdl->cursor_elt == -1 && ddl->cursor_elt != -1) | |
826 | 5874 || old_start != ddl->charpos |
5875 || old_end != ddl->end_charpos | |
428 | 5876 || initial_size != Dynarr_length (db->runes)) |
5877 { | |
5878 return 0; | |
5879 } | |
5880 | |
5881 if (ddl->cursor_elt != -1) | |
5882 { | |
5883 w->last_point_x[DESIRED_DISP] = ddl->cursor_elt; | |
5884 w->last_point_y[DESIRED_DISP] = line; | |
5885 } | |
5886 | |
5887 last_line = line; | |
5888 | |
5889 /* If the extent changes end on the line we just updated then | |
4187 | 5890 we're done. Otherwise go on to the next line. */ |
826 | 5891 if (end_unchanged <= ddl->end_charpos) |
428 | 5892 break; |
5893 else | |
5894 line++; | |
5895 } | |
5896 | |
5897 redisplay_update_line (w, first_line, last_line, 1); | |
5898 return 1; | |
5899 } | |
5900 | |
5901 /* Attempt to update the display data structures based on knowledge of | |
5902 the changed region in the buffer. Returns a boolean indicating | |
5903 success or failure. If this function returns a failure then a | |
5904 regenerate_window _must_ be performed next in order to maintain | |
5905 invariants located here. */ | |
5906 | |
5907 static int | |
665 | 5908 regenerate_window_incrementally (struct window *w, Charbpos startp, |
5909 Charbpos pointm) | |
428 | 5910 { |
5911 struct buffer *b = XBUFFER (w->buffer); | |
5912 display_line_dynarr *cdla = window_display_lines (w, CURRENT_DISP); | |
5913 display_line_dynarr *ddla = window_display_lines (w, DESIRED_DISP); | |
5914 Charcount beg_unchanged, end_unchanged; | |
5915 Charcount extent_beg_unchanged, extent_end_unchanged; | |
5916 | |
5917 int dla_start = 0; | |
5918 int dla_end, line; | |
665 | 5919 Charbpos start_pos; |
428 | 5920 |
5921 /* If this function is called, the current and desired structures | |
5922 had better be identical. If they are not, then that is a bug. */ | |
5923 assert (Dynarr_length (cdla) == Dynarr_length (ddla)); | |
5924 | |
5925 /* We don't handle minibuffer windows yet. The minibuffer prompt | |
5926 screws us up. */ | |
5927 if (MINI_WINDOW_P (w)) | |
5928 return 0; | |
5929 | |
5930 extent_beg_unchanged = BUF_EXTENT_BEGIN_UNCHANGED (b); | |
5931 extent_end_unchanged = (BUF_EXTENT_END_UNCHANGED (b) == -1 | |
5932 ? -1 | |
5933 : BUF_Z (b) - BUF_EXTENT_END_UNCHANGED (b)); | |
5934 | |
5935 /* If nothing has changed in the buffer, then make sure point is ok | |
5936 and succeed. */ | |
5937 if (BUF_BEGIN_UNCHANGED (b) == -1 && BUF_END_UNCHANGED (b) == -1) | |
5938 return regenerate_window_extents_only_changed (w, startp, pointm, | |
5939 extent_beg_unchanged, | |
5940 extent_end_unchanged); | |
5941 | |
5942 /* We can't deal with deleted newlines. */ | |
5943 if (BUF_NEWLINE_WAS_DELETED (b)) | |
5944 return 0; | |
5945 | |
5946 beg_unchanged = BUF_BEGIN_UNCHANGED (b); | |
5947 end_unchanged = (BUF_END_UNCHANGED (b) == -1 | |
5948 ? -1 | |
5949 : BUF_Z (b) - BUF_END_UNCHANGED (b)); | |
5950 | |
5951 REGEN_INC_FIND_START_END; | |
5952 | |
5953 /* If the changed area starts before the visible area, give up. */ | |
5954 if (beg_unchanged < startp) | |
5955 return 0; | |
5956 | |
5957 /* Find what display line the buffer changes first affect. */ | |
5958 line = dla_start; | |
5959 while (line <= dla_end) | |
5960 { | |
5961 struct display_line *dl = Dynarr_atp (cdla, line); | |
826 | 5962 Charbpos lstart = dl->charpos + dl->offset; |
5963 Charbpos lend = dl->end_charpos + dl->offset; | |
428 | 5964 |
5965 if (beg_unchanged >= lstart && beg_unchanged <= lend) | |
5966 break; | |
5967 | |
5968 line++; | |
5969 } | |
5970 | |
5971 /* If the changes are below the visible area then if point hasn't | |
5972 moved return success otherwise fail in order to be safe. */ | |
5973 if (line > dla_end) | |
5974 return regenerate_window_extents_only_changed (w, startp, pointm, | |
5975 extent_beg_unchanged, | |
5976 extent_end_unchanged); | |
5977 else | |
5978 /* At this point we know what line the changes first affect. We | |
5979 now redraw that line. If the changes are contained within it | |
5980 we are going to succeed and can update just that one line. | |
5981 Otherwise we fail. If we fail we will have altered the desired | |
5982 structs which could lead to an assertion failure. However, if | |
5983 we fail the next thing that is going to happen is a full regen | |
5984 so we will actually end up being safe. */ | |
5985 { | |
5986 prop_block_dynarr *prop = NULL; | |
5987 struct display_line *cdl = Dynarr_atp (cdla, line); | |
5988 struct display_line *ddl = Dynarr_atp (ddla, line); | |
5989 | |
826 | 5990 assert (cdl->charpos == ddl->charpos); |
5991 assert (cdl->end_charpos == ddl->end_charpos); | |
428 | 5992 assert (cdl->offset == ddl->offset); |
5993 | |
442 | 5994 /* If the line continues to next display line, fail. */ |
5995 if (ddl->line_continuation) | |
5996 return 0; | |
428 | 5997 |
5998 /* If the line was generated using propagation data, fail. */ | |
5999 if (ddl->used_prop_data) | |
6000 return 0; | |
6001 | |
2286 | 6002 generate_display_line (w, ddl, 0, ddl->charpos + ddl->offset, |
6003 &prop, DESIRED_DISP); | |
428 | 6004 ddl->offset = 0; |
6005 | |
6006 /* If there is propagated stuff then it is pretty much a | |
4187 | 6007 guarantee that more than just the one line is affected. */ |
428 | 6008 if (prop) |
6009 { | |
6010 Dynarr_free (prop); | |
6011 return 0; | |
6012 } | |
6013 | |
442 | 6014 /* If the line continues to next display line, fail. */ |
6015 if (ddl->line_continuation) | |
6016 return 0; | |
428 | 6017 |
6018 /* If any line position parameters have changed or a | |
4187 | 6019 cursor has disappeared or disappeared, fail. */ |
428 | 6020 if (cdl->ypos != ddl->ypos |
6021 || cdl->ascent != ddl->ascent | |
6022 || cdl->descent != ddl->descent | |
6023 || cdl->top_clip != ddl->top_clip | |
6024 || (cdl->cursor_elt != -1 && ddl->cursor_elt == -1) | |
6025 || (cdl->cursor_elt == -1 && ddl->cursor_elt != -1)) | |
6026 { | |
6027 return 0; | |
6028 } | |
6029 | |
6030 /* If the changed area also ends on this line, then we may be in | |
4187 | 6031 business. Update everything and return success. */ |
826 | 6032 if (end_unchanged >= ddl->charpos && end_unchanged <= ddl->end_charpos) |
428 | 6033 { |
6034 w->last_modified[DESIRED_DISP] = make_int (BUF_MODIFF (b)); | |
6035 w->last_facechange[DESIRED_DISP] = make_int (BUF_FACECHANGE (b)); | |
6036 Fset_marker (w->last_start[DESIRED_DISP], make_int (startp), | |
6037 w->buffer); | |
6038 Fset_marker (w->last_point[DESIRED_DISP], make_int (pointm), | |
6039 w->buffer); | |
6040 | |
6041 if (ddl->cursor_elt != -1) | |
6042 { | |
6043 w->last_point_x[DESIRED_DISP] = ddl->cursor_elt; | |
6044 w->last_point_y[DESIRED_DISP] = line; | |
6045 } | |
6046 | |
6047 redisplay_update_line (w, line, line, 1); | |
6048 regenerate_modeline (w); | |
6049 | |
6050 /* #### For now we just flush the cache until this has been | |
4187 | 6051 tested. After that is done, this should correct the |
6052 cache directly. */ | |
428 | 6053 Dynarr_reset (w->line_start_cache); |
6054 | |
6055 /* Adjust the extent changed boundaries to remove any | |
4187 | 6056 overlap with the buffer changes since we've just |
6057 successfully updated that area. */ | |
428 | 6058 if (extent_beg_unchanged != -1 |
6059 && extent_beg_unchanged >= beg_unchanged | |
6060 && extent_beg_unchanged < end_unchanged) | |
6061 extent_beg_unchanged = end_unchanged; | |
6062 | |
6063 if (extent_end_unchanged != -1 | |
6064 && extent_end_unchanged >= beg_unchanged | |
6065 && extent_end_unchanged < end_unchanged) | |
6066 extent_end_unchanged = beg_unchanged - 1; | |
6067 | |
6068 if (extent_end_unchanged <= extent_beg_unchanged) | |
6069 extent_beg_unchanged = extent_end_unchanged = -1; | |
6070 | |
6071 /* This could lead to odd results if it fails, but since the | |
4187 | 6072 buffer changes update succeeded this probably will to. |
6073 We already know that the extent changes start at or after | |
6074 the line because we checked before entering the loop. */ | |
428 | 6075 if (extent_beg_unchanged != -1 |
6076 && extent_end_unchanged != -1 | |
826 | 6077 && ((extent_beg_unchanged < ddl->charpos) |
6078 || (extent_end_unchanged > ddl->end_charpos))) | |
428 | 6079 return regenerate_window_extents_only_changed (w, startp, pointm, |
6080 extent_beg_unchanged, | |
6081 extent_end_unchanged); | |
6082 else | |
6083 return 1; | |
6084 } | |
6085 } | |
6086 | |
6087 /* Oh, well. */ | |
6088 return 0; | |
6089 } | |
6090 | |
6091 /* Given a window and a point, update the given display lines such | |
6092 that point is displayed in the middle of the window. | |
6093 Return the window's new start position. */ | |
6094 | |
665 | 6095 static Charbpos |
6096 regenerate_window_point_center (struct window *w, Charbpos point, int type) | |
428 | 6097 { |
665 | 6098 Charbpos startp; |
428 | 6099 |
6100 /* We need to make sure that the modeline is generated so that the | |
6101 window height can be calculated correctly. */ | |
6102 ensure_modeline_generated (w, type); | |
6103 | |
6104 startp = start_with_line_at_pixpos (w, point, window_half_pixpos (w)); | |
6105 regenerate_window (w, startp, point, type); | |
6106 Fset_marker (w->start[type], make_int (startp), w->buffer); | |
6107 | |
6108 return startp; | |
6109 } | |
6110 | |
6111 /* Given a window and a set of display lines, return a boolean | |
6112 indicating whether the given point is contained within. */ | |
6113 | |
6114 static int | |
665 | 6115 point_visible (struct window *w, Charbpos point, int type) |
428 | 6116 { |
6117 struct buffer *b = XBUFFER (w->buffer); | |
6118 display_line_dynarr *dla = window_display_lines (w, type); | |
6119 int first_line; | |
6120 | |
4967 | 6121 if (Dynarr_length (dla) && Dynarr_begin (dla)->modeline) |
428 | 6122 first_line = 1; |
6123 else | |
6124 first_line = 0; | |
6125 | |
6126 if (Dynarr_length (dla) > first_line) | |
6127 { | |
665 | 6128 Charbpos start, end; |
428 | 6129 struct display_line *dl = Dynarr_atp (dla, first_line); |
6130 | |
826 | 6131 start = dl->charpos; |
428 | 6132 end = BUF_Z (b) - w->window_end_pos[type] - 1; |
6133 | |
6134 if (point >= start && point <= end) | |
6135 { | |
6136 if (!MINI_WINDOW_P (w) && scroll_on_clipped_lines) | |
6137 { | |
4844
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4815
diff
changeset
|
6138 dl = Dynarr_lastp (dla); |
428 | 6139 |
826 | 6140 if (point >= (dl->charpos + dl->offset) |
6141 && point <= (dl->end_charpos + dl->offset)) | |
428 | 6142 return !dl->clip; |
6143 else | |
6144 return 1; | |
6145 } | |
6146 else | |
6147 return 1; | |
6148 } | |
6149 else | |
6150 return 0; | |
6151 } | |
6152 else | |
6153 return 0; | |
6154 } | |
6155 | |
6156 /* Return pixel position the middle of the window, not including the | |
6157 modeline and any potential horizontal scrollbar. */ | |
6158 | |
6159 int | |
6160 window_half_pixpos (struct window *w) | |
6161 { | |
6162 return WINDOW_TEXT_TOP (w) + (WINDOW_TEXT_HEIGHT (w) >> 1); | |
6163 } | |
6164 | |
6165 /* Return the display line which is currently in the middle of the | |
6166 window W for display lines TYPE. */ | |
6167 | |
6168 int | |
665 | 6169 line_at_center (struct window *w, int type, Charbpos start, Charbpos point) |
428 | 6170 { |
6171 display_line_dynarr *dla; | |
6172 int half; | |
6173 int elt; | |
6174 int first_elt = (MINI_WINDOW_P (w) ? 0 : 1); | |
6175 | |
6176 if (type == CMOTION_DISP) | |
6177 regenerate_window (w, start, point, type); | |
6178 | |
6179 dla = window_display_lines (w, type); | |
6180 half = window_half_pixpos (w); | |
6181 | |
6182 for (elt = first_elt; elt < Dynarr_length (dla); elt++) | |
6183 { | |
6184 struct display_line *dl = Dynarr_atp (dla, elt); | |
6185 int line_bot = dl->ypos + dl->descent; | |
6186 | |
6187 if (line_bot > half) | |
6188 return elt; | |
6189 } | |
6190 | |
6191 /* We may not have a line at the middle if the end of the buffer is | |
6192 being displayed. */ | |
6193 return -1; | |
6194 } | |
6195 | |
6196 /* Return a value for point that would place it at the beginning of | |
6197 the line which is in the middle of the window. */ | |
6198 | |
665 | 6199 Charbpos |
6200 point_at_center (struct window *w, int type, Charbpos start, Charbpos point) | |
428 | 6201 { |
6202 /* line_at_center will regenerate the display structures, if necessary. */ | |
6203 int line = line_at_center (w, type, start, point); | |
6204 | |
6205 if (line == -1) | |
6206 return BUF_ZV (XBUFFER (w->buffer)); | |
6207 else | |
6208 { | |
6209 display_line_dynarr *dla = window_display_lines (w, type); | |
6210 struct display_line *dl = Dynarr_atp (dla, line); | |
6211 | |
826 | 6212 return dl->charpos; |
428 | 6213 } |
6214 } | |
6215 | |
6216 /* For a given window, ensure that the current visual representation | |
6217 is accurate. */ | |
6218 | |
6219 static void | |
6220 redisplay_window (Lisp_Object window, int skip_selected) | |
6221 { | |
6222 struct window *w = XWINDOW (window); | |
6223 struct frame *f = XFRAME (w->frame); | |
6224 struct device *d = XDEVICE (f->device); | |
6225 Lisp_Object old_buffer = w->buffer; | |
6226 Lisp_Object the_buffer = w->buffer; | |
6227 struct buffer *b; | |
6228 int echo_active = 0; | |
6229 int startp = 1; | |
6230 int pointm; | |
6231 int old_startp = 1; | |
6232 int old_pointm = 1; | |
6233 int selected_in_its_frame; | |
6234 int selected_globally; | |
6235 int skip_output = 0; | |
6236 int truncation_changed; | |
6237 int inactive_minibuffer = | |
6238 (MINI_WINDOW_P (w) && | |
6239 (f != device_selected_frame (d)) && | |
6240 !is_surrogate_for_selected_frame (f)); | |
6241 | |
6242 /* #### In the new world this function actually does a bunch of | |
6243 optimizations such as buffer-based scrolling, but none of that is | |
6244 implemented yet. */ | |
6245 | |
6246 /* If this is a combination window, do its children; that's all. | |
6247 The selected window is always a leaf so we don't check for | |
6248 skip_selected here. */ | |
6249 if (!NILP (w->vchild)) | |
6250 { | |
6251 redisplay_windows (w->vchild, skip_selected); | |
6252 return; | |
6253 } | |
6254 if (!NILP (w->hchild)) | |
6255 { | |
6256 redisplay_windows (w->hchild, skip_selected); | |
6257 return; | |
6258 } | |
6259 | |
6260 /* Is this window the selected window on its frame? */ | |
6261 selected_in_its_frame = (w == XWINDOW (FRAME_SELECTED_WINDOW (f))); | |
6262 selected_globally = | |
6263 selected_in_its_frame && | |
5198 | 6264 EQ (DEVICE_CONSOLE (d), Vselected_console) && |
6265 XDEVICE (CONSOLE_SELECTED_DEVICE (XCONSOLE (DEVICE_CONSOLE (d)))) == d && | |
6266 XFRAME (DEVICE_SELECTED_FRAME (d)) == f; | |
428 | 6267 if (skip_selected && selected_in_its_frame) |
6268 return; | |
6269 | |
6270 /* It is possible that the window is not fully initialized yet. */ | |
6271 if (NILP (w->buffer)) | |
6272 return; | |
6273 | |
6274 if (MINI_WINDOW_P (w) && echo_area_active (f)) | |
6275 { | |
6276 w->buffer = the_buffer = Vecho_area_buffer; | |
6277 echo_active = 1; | |
6278 } | |
6279 | |
6280 b = XBUFFER (w->buffer); | |
6281 | |
6282 if (echo_active) | |
6283 { | |
6284 old_pointm = selected_globally | |
4187 | 6285 ? BUF_PT (b) |
6286 : marker_position (w->pointm[CURRENT_DISP]); | |
428 | 6287 pointm = 1; |
6288 } | |
6289 else | |
6290 { | |
6291 if (selected_globally) | |
6292 { | |
6293 pointm = BUF_PT (b); | |
6294 } | |
6295 else | |
6296 { | |
6297 pointm = marker_position (w->pointm[CURRENT_DISP]); | |
6298 | |
6299 if (pointm < BUF_BEGV (b)) | |
6300 pointm = BUF_BEGV (b); | |
6301 else if (pointm > BUF_ZV (b)) | |
6302 pointm = BUF_ZV (b); | |
6303 } | |
6304 } | |
6305 Fset_marker (w->pointm[DESIRED_DISP], make_int (pointm), the_buffer); | |
6306 | |
4968 | 6307 /* Added 2-1-10 -- we should never have empty face or glyph cachels |
6308 because we initialized them at startup and the only way to reduce | |
6309 their number is through calling reset_face_cachels() or | |
6310 reset_glyph_cachels(), which as a side effect sets up a number of | |
6311 standard entries */ | |
6312 assert (Dynarr_length (w->face_cachels)); | |
6313 assert (Dynarr_length (w->glyph_cachels)); | |
6314 | |
428 | 6315 /* If the buffer has changed we have to invalidate all of our face |
6316 cache elements. */ | |
6317 if ((!echo_active && b != window_display_buffer (w)) | |
4968 | 6318 #if 0 |
6319 /* #### Delete this code sometime later than 2-1-10 when we're sure it's | |
6320 not needed */ | |
428 | 6321 || !Dynarr_length (w->face_cachels) |
4968 | 6322 #endif |
428 | 6323 || f->faces_changed) |
6324 reset_face_cachels (w); | |
6325 else | |
6326 mark_face_cachels_as_not_updated (w); | |
6327 | |
6328 /* Ditto the glyph cache elements, although we do *not* invalidate | |
6329 the cache purely because glyphs have changed - this is now | |
6330 handled by the dirty flag.*/ | |
6331 if ((!echo_active && b != window_display_buffer (w)) | |
4968 | 6332 #if 0 |
6333 /* #### Delete this code sometime later than 2-1-10 when we're sure it's | |
6334 not needed */ | |
6335 || !Dynarr_length (w->glyph_cachels) | |
6336 #endif | |
6337 || f->faces_changed) | |
428 | 6338 reset_glyph_cachels (w); |
6339 else | |
6340 mark_glyph_cachels_as_not_updated (w); | |
6341 | |
6342 /* If the marker's buffer is not the window's buffer, then we need | |
6343 to find a new starting position. */ | |
6344 if (!MINI_WINDOW_P (w) | |
6345 && !EQ (Fmarker_buffer (w->start[CURRENT_DISP]), w->buffer)) | |
6346 { | |
6347 startp = regenerate_window_point_center (w, pointm, DESIRED_DISP); | |
6348 | |
6349 goto regeneration_done; | |
6350 } | |
6351 | |
6352 if (echo_active) | |
6353 { | |
6354 old_startp = marker_position (w->start[CURRENT_DISP]); | |
6355 startp = 1; | |
6356 } | |
6357 else | |
6358 { | |
6359 startp = marker_position (w->start[CURRENT_DISP]); | |
6360 if (startp < BUF_BEGV (b)) | |
6361 startp = BUF_BEGV (b); | |
6362 else if (startp > BUF_ZV (b)) | |
6363 startp = BUF_ZV (b); | |
6364 } | |
6365 Fset_marker (w->start[DESIRED_DISP], make_int (startp), the_buffer); | |
6366 | |
6367 truncation_changed = (find_window_mirror (w)->truncate_win != | |
647 | 6368 (unsigned int) window_truncation_on (w)); |
428 | 6369 |
6370 /* If w->force_start is set, then some function set w->start and we | |
6371 should display from there and change point, if necessary, to | |
6372 ensure that it is visible. */ | |
6373 if (w->force_start || inactive_minibuffer) | |
6374 { | |
6375 w->force_start = 0; | |
6376 w->last_modified[DESIRED_DISP] = Qzero; | |
6377 w->last_facechange[DESIRED_DISP] = Qzero; | |
6378 | |
6379 regenerate_window (w, startp, pointm, DESIRED_DISP); | |
6380 | |
6381 if (!point_visible (w, pointm, DESIRED_DISP) && !inactive_minibuffer) | |
6382 { | |
6383 pointm = point_at_center (w, DESIRED_DISP, 0, 0); | |
6384 | |
6385 if (selected_globally) | |
6386 BUF_SET_PT (b, pointm); | |
6387 | |
6388 Fset_marker (w->pointm[DESIRED_DISP], make_int (pointm), | |
6389 the_buffer); | |
6390 | |
6391 /* #### BUFU amounts of overkill just to get the cursor | |
4187 | 6392 location marked properly. FIX ME FIX ME FIX ME */ |
428 | 6393 regenerate_window (w, startp, pointm, DESIRED_DISP); |
6394 } | |
6395 | |
6396 goto regeneration_done; | |
6397 } | |
6398 | |
6399 /* If nothing has changed since the last redisplay, then we just | |
6400 need to make sure that point is still visible. */ | |
6401 if (XINT (w->last_modified[CURRENT_DISP]) >= BUF_MODIFF (b) | |
6402 && XINT (w->last_facechange[CURRENT_DISP]) >= BUF_FACECHANGE (b) | |
6403 && pointm >= startp | |
6404 /* This check is to make sure we restore the minibuffer after a | |
4187 | 6405 temporary change to the echo area. */ |
428 | 6406 && !(MINI_WINDOW_P (w) && f->buffers_changed) |
6407 && !f->frame_changed | |
6408 && !truncation_changed | |
442 | 6409 /* check whether start is really at the beginning of a line GE */ |
428 | 6410 && (!w->start_at_line_beg || beginning_of_line_p (b, startp)) |
6411 ) | |
6412 { | |
6413 /* Check if the cursor has actually moved. */ | |
6414 if (EQ (Fmarker_buffer (w->last_point[CURRENT_DISP]), w->buffer) | |
6415 && pointm == marker_position (w->last_point[CURRENT_DISP]) | |
6416 && selected_globally | |
6417 && !w->windows_changed | |
6418 && !f->clip_changed | |
6419 && !f->extents_changed | |
6420 && !f->faces_changed | |
6421 && !f->glyphs_changed | |
6422 && !f->subwindows_changed | |
442 | 6423 /* && !f->subwindows_state_changed*/ |
428 | 6424 && !f->point_changed |
6425 && !f->windows_structure_changed) | |
6426 { | |
6427 /* If not, we're done. */ | |
6428 if (f->modeline_changed) | |
6429 regenerate_modeline (w); | |
6430 | |
6431 skip_output = 1; | |
6432 goto regeneration_done; | |
6433 } | |
6434 else | |
6435 { | |
6436 /* If the new point is visible in the redisplay structures, | |
4187 | 6437 then let the output update routines handle it, otherwise |
6438 do things the hard way. */ | |
428 | 6439 if (!w->windows_changed |
6440 && !f->clip_changed | |
6441 && !f->extents_changed | |
6442 && !f->faces_changed | |
6443 && !f->glyphs_changed | |
6444 && !f->subwindows_changed | |
442 | 6445 /* && !f->subwindows_state_changed*/ |
428 | 6446 && !f->windows_structure_changed) |
6447 { | |
6448 if (point_visible (w, pointm, CURRENT_DISP) | |
6449 && w->last_point_x[CURRENT_DISP] != -1 | |
6450 && w->last_point_y[CURRENT_DISP] != -1) | |
6451 { | |
6452 if (redisplay_move_cursor (w, pointm, FRAME_TTY_P (f))) | |
6453 { | |
6454 /* Always regenerate in case it is displaying | |
4187 | 6455 the current line or column. */ |
428 | 6456 regenerate_modeline (w); |
6457 | |
6458 skip_output = 1; | |
6459 goto regeneration_done; | |
6460 } | |
6461 } | |
6462 else if (!selected_in_its_frame && !f->point_changed) | |
6463 { | |
6464 if (f->modeline_changed) | |
6465 regenerate_modeline (w); | |
6466 | |
6467 skip_output = 1; | |
6468 goto regeneration_done; | |
6469 } | |
6470 } | |
6471 | |
6472 /* If we weren't able to take the shortcut method, then use | |
4187 | 6473 the brute force method. */ |
428 | 6474 regenerate_window (w, startp, pointm, DESIRED_DISP); |
6475 | |
6476 if (point_visible (w, pointm, DESIRED_DISP)) | |
6477 goto regeneration_done; | |
6478 } | |
6479 } | |
6480 | |
6481 /* Check if the starting point is no longer at the beginning of a | |
6482 line, in which case find a new starting point. We also recenter | |
6483 if our start position is equal to point-max. Otherwise we'll end | |
6484 up with a blank window. */ | |
6485 else if (((w->start_at_line_beg || MINI_WINDOW_P (w)) | |
6486 && !(startp == BUF_BEGV (b) | |
6487 || BUF_FETCH_CHAR (b, startp - 1) == '\n')) | |
6488 || (pointm == startp && | |
6489 EQ (Fmarker_buffer (w->last_start[CURRENT_DISP]), w->buffer) && | |
6490 startp < marker_position (w->last_start[CURRENT_DISP])) | |
6491 || (startp == BUF_ZV (b))) | |
6492 { | |
6493 startp = regenerate_window_point_center (w, pointm, DESIRED_DISP); | |
6494 | |
6495 goto regeneration_done; | |
6496 } | |
6497 /* See if we can update the data structures locally based on | |
6498 knowledge of what changed in the buffer. */ | |
6499 else if (!w->windows_changed | |
6500 && !f->clip_changed | |
6501 && !f->faces_changed | |
6502 && !f->glyphs_changed | |
6503 && !f->subwindows_changed | |
442 | 6504 /* && !f->subwindows_state_changed*/ |
428 | 6505 && !f->windows_structure_changed |
6506 && !f->frame_changed | |
6507 && !truncation_changed | |
6508 && pointm >= startp | |
6509 && regenerate_window_incrementally (w, startp, pointm)) | |
6510 { | |
6511 if (f->modeline_changed | |
6512 || XINT (w->last_modified[CURRENT_DISP]) < BUF_MODIFF (b) | |
6513 || XINT (w->last_facechange[CURRENT_DISP]) < BUF_FACECHANGE (b)) | |
6514 regenerate_modeline (w); | |
6515 | |
6516 skip_output = 1; | |
6517 goto regeneration_done; | |
6518 } | |
6519 /* #### This is where a check for structure based scrolling would go. */ | |
6520 /* If all else fails, try just regenerating and see what happens. */ | |
6521 else | |
6522 { | |
6523 regenerate_window (w, startp, pointm, DESIRED_DISP); | |
6524 | |
6525 if (point_visible (w, pointm, DESIRED_DISP)) | |
6526 goto regeneration_done; | |
6527 } | |
6528 | |
6529 /* We still haven't gotten the window regenerated with point | |
6530 visible. Next we try scrolling a little and see if point comes | |
6531 back onto the screen. */ | |
6532 if (scroll_step > 0) | |
6533 { | |
6534 int scrolled = scroll_conservatively; | |
6535 for (; scrolled >= 0; scrolled -= scroll_step) | |
6536 { | |
6537 startp = vmotion (w, startp, | |
6538 (pointm < startp) ? -scroll_step : scroll_step, 0); | |
6539 regenerate_window (w, startp, pointm, DESIRED_DISP); | |
6540 | |
6541 if (point_visible (w, pointm, DESIRED_DISP)) | |
6542 goto regeneration_done; | |
6543 } | |
6544 } | |
6545 | |
6546 /* We still haven't managed to get the screen drawn with point on | |
6547 the screen, so just center it and be done with it. */ | |
6548 startp = regenerate_window_point_center (w, pointm, DESIRED_DISP); | |
6549 | |
6550 | |
6551 regeneration_done: | |
6552 | |
6553 /* If the window's frame is changed then reset the current display | |
6554 lines in order to force a full repaint. */ | |
6555 if (f->frame_changed) | |
6556 { | |
6557 display_line_dynarr *cla = window_display_lines (w, CURRENT_DISP); | |
6558 | |
6559 Dynarr_reset (cla); | |
6560 } | |
6561 | |
6562 /* Must do this before calling redisplay_output_window because it | |
6563 sets some markers on the window. */ | |
6564 if (echo_active) | |
6565 { | |
6566 w->buffer = old_buffer; | |
6567 Fset_marker (w->pointm[DESIRED_DISP], make_int (old_pointm), old_buffer); | |
6568 Fset_marker (w->start[DESIRED_DISP], make_int (old_startp), old_buffer); | |
6569 } | |
6570 | |
6571 /* These also have to be set before calling redisplay_output_window | |
6572 since it sets the CURRENT_DISP values based on them. */ | |
6573 w->last_modified[DESIRED_DISP] = make_int (BUF_MODIFF (b)); | |
6574 w->last_facechange[DESIRED_DISP] = make_int (BUF_FACECHANGE (b)); | |
6575 Fset_marker (w->last_start[DESIRED_DISP], make_int (startp), w->buffer); | |
6576 Fset_marker (w->last_point[DESIRED_DISP], make_int (pointm), w->buffer); | |
6577 | |
6578 if (!skip_output) | |
6579 { | |
665 | 6580 Charbpos start = marker_position (w->start[DESIRED_DISP]); |
6581 Charbpos end = (w->window_end_pos[DESIRED_DISP] == -1 | |
428 | 6582 ? BUF_ZV (b) |
6583 : BUF_Z (b) - w->window_end_pos[DESIRED_DISP] - 1); | |
6584 /* Don't pollute the cache if not sure if we are correct */ | |
6585 if (w->start_at_line_beg) | |
6586 update_line_start_cache (w, start, end, pointm, 1); | |
6587 redisplay_output_window (w); | |
6588 /* | |
6589 * If we just displayed the echo area, the line start cache is | |
6590 * no longer valid, because the minibuffer window is associated | |
6591 * with the window now. | |
6592 */ | |
6593 if (echo_active) | |
6594 w->line_cache_last_updated = make_int (-1); | |
6595 } | |
6596 | |
6597 /* #### This should be dependent on face changes and will need to be | |
6598 somewhere else once tty updates occur on a per-frame basis. */ | |
6599 mark_face_cachels_as_clean (w); | |
6600 | |
438 | 6601 /* The glyph cachels only get dirty if someone changed something. |
6602 Since redisplay has now effectively ended we can reset the dirty | |
6603 flag since everything must be up-to-date. */ | |
428 | 6604 if (glyphs_changed) |
6605 mark_glyph_cachels_as_clean (w); | |
6606 | |
6607 w->windows_changed = 0; | |
6608 } | |
6609 | |
6610 /* Call buffer_reset_changes for all buffers present in any window | |
6611 currently visible in all frames on all devices. #### There has to | |
6612 be a better way to do this. */ | |
6613 | |
6614 static int | |
2286 | 6615 reset_buffer_changes_mapfun (struct window *w, void *UNUSED (closure)) |
428 | 6616 { |
6617 buffer_reset_changes (XBUFFER (w->buffer)); | |
6618 return 0; | |
6619 } | |
6620 | |
6621 static void | |
6622 reset_buffer_changes (void) | |
6623 { | |
6624 Lisp_Object frmcons, devcons, concons; | |
6625 | |
6626 FRAME_LOOP_NO_BREAK (frmcons, devcons, concons) | |
6627 { | |
6628 struct frame *f = XFRAME (XCAR (frmcons)); | |
6629 | |
6630 if (FRAME_REPAINT_P (f)) | |
6631 map_windows (f, reset_buffer_changes_mapfun, 0); | |
6632 } | |
6633 } | |
6634 | |
6635 /* Ensure that all windows underneath the given window in the window | |
6636 hierarchy are correctly displayed. */ | |
6637 | |
6638 static void | |
6639 redisplay_windows (Lisp_Object window, int skip_selected) | |
6640 { | |
6641 for (; !NILP (window) ; window = XWINDOW (window)->next) | |
6642 { | |
6643 redisplay_window (window, skip_selected); | |
6644 } | |
6645 } | |
6646 | |
1318 | 6647 /* Register an action to be called at the end of redisplay. |
6648 in_display is 0 when this is called. | |
6649 This is used when it is discovered that an action needs to be taken, | |
6650 but it's during redisplay, so it's not safe. (Typically, it's an action | |
6651 that needs to enter redisplay, which can't happen reentrantly.) | |
6652 | |
6653 NEVER signal an error in these functions. | |
6654 */ | |
6655 | |
6656 void | |
6657 register_post_redisplay_action (void (*fun) (Lisp_Object), Lisp_Object arg) | |
6658 { | |
6659 Vpost_redisplay_actions = nconc2 (Vpost_redisplay_actions, | |
6660 list1 (Fcons (make_opaque_ptr | |
6661 ((void *) fun), arg))); | |
6662 } | |
6663 | |
1320 | 6664 static int running_post_redisplay_actions; |
6665 | |
1318 | 6666 static void |
6667 run_post_redisplay_actions (void) | |
6668 { | |
1320 | 6669 int depth; |
6670 | |
6671 if (running_post_redisplay_actions) | |
6672 return; | |
6673 | |
6674 depth = internal_bind_int (&running_post_redisplay_actions, 1); | |
6675 /* If the function pushes further actions, they will be tacked onto | |
6676 the end of the list, and we'll run them when we're done with the | |
6677 current ones. */ | |
1318 | 6678 while (!NILP (Vpost_redisplay_actions)) |
6679 { | |
6680 Lisp_Object car = XCAR (Vpost_redisplay_actions); | |
6681 void (*fun) (Lisp_Object) = | |
6682 (void (*)(Lisp_Object)) get_opaque_ptr (XCAR (car)); | |
6683 (*fun) (XCDR (car)); | |
6684 free_opaque_ptr (XCAR (car)); | |
6685 free_cons (car); | |
6686 Vpost_redisplay_actions = XCDR (Vpost_redisplay_actions); | |
6687 } | |
1320 | 6688 unbind_to (depth); |
1318 | 6689 } |
6690 | |
6691 #ifdef ERROR_CHECK_TRAPPING_PROBLEMS | |
6692 | |
6693 static Lisp_Object | |
2286 | 6694 commit_ritual_suicide (Lisp_Object UNUSED (ceci_nest_pas_une_pipe)) |
1318 | 6695 { |
6696 assert (!in_display); | |
6697 return Qnil; | |
6698 } | |
6699 | |
6700 #endif | |
6701 | |
6702 /* Within the guts of redisplay, we are defenseless and cannot allow any of | |
6703 the following to happen: | |
6704 | |
6705 1) garbage collection | |
6706 2) QUIT | |
6707 3) any non-local exits | |
6708 4) frame size changes | |
6709 5) deletion of any buffers, windows, frames, etc. | |
6710 6) modification of buffer text | |
6711 7) reentrant entry of redisplay (see the stack trace above | |
6712 generate_displayable_area()) | |
6713 | |
6714 The general reason is that the redisplay code is written to assume that | |
6715 it is the only code running, and thus (a) cannot tolerate structures | |
6716 changed out from under it (hence 1, 4, 5, 6, 7) and (b) at various points | |
6717 within redisplay the redisplay structures may be in an inconsistent | |
6718 state and there are no unwind-protects to clean the structures up in | |
6719 case of non-local exit (hence 2, 3). Fixing redisplay to address these | |
6720 issues is hard and perhaps not worth it (and might slow things down a | |
6721 fair amount). We address 1, 4, 5 and 6 ourselves inside of | |
6722 enter_redisplay_critical_section() by simply inhibiting them, but we | |
6723 cannot handle 2 and 3, which must be handled at the actual point where | |
6724 they may occur (especially, internal_equal() or any place that may call | |
6725 Lisp), by wrapping the code in call_trapping_problems() or | |
6726 call_with_suspended_errors(). [[ NOTE: We could address QUIT by inhibiting | |
6727 it but this would be anti-social because it would prevent the user from | |
6728 interrupting any Lisp code called within the critical section. With the | |
6729 call_*() wrapping, C-g will interrupt the Lisp code and throw back to | |
6730 the innermost wrapping. ]] In fact we do turn off QUIT handling, since | |
6731 it's just too dangerous otherwise. See below. | |
6732 | |
6733 Code calling enter_redisplay_critical_section() must check for reentrancy | |
6734 (#7) and take appropriate corrective action. | |
6735 | |
6736 To help debug potential problems, we arrange (when | |
6737 ERROR_CHECK_TRAPPING_PROBLEMS is set) to crash automatically every time | |
6738 we execute QUIT or call Lisp code unless proper wrapping is in place, as | |
6739 well as further checks when we actually Fsignal(), Fthrow(), | |
6740 garbage_collect_1(). | |
6741 | |
6742 #### If a frame-size change does occur we should probably actually be | |
6743 preempting redisplay. */ | |
6744 | |
6745 /* Count of number of recursive times we call | |
6746 enter_redisplay_critical_section() or | |
6747 enter_redisplay_critical_section_maybe(). | |
6748 enter_redisplay_critical_section() cannot occur reentrantly but we have | |
6749 to know in the *maybe() version whether to exit the section when we're | |
6750 done. */ | |
6751 static int in_display_nesting; | |
6752 | |
6753 static Lisp_Object | |
2286 | 6754 end_hold_frame_size_changes (Lisp_Object UNUSED (obj)) |
1318 | 6755 { |
6756 if (!hold_frame_size_changes) | |
6757 { | |
6758 /* we used to have a function to do this for only one frame, and | |
6759 it was typical to call it at the end of a critical section | |
6760 (which occurs once per frame); but what then happens if multiple | |
6761 frames have frame changes held up? | |
4187 | 6762 |
1318 | 6763 This means we are O(N^2) over frames. I seriously doubt it matters. |
6764 --ben */ | |
6765 Lisp_Object frmcons, devcons, concons; | |
4187 | 6766 |
1318 | 6767 FRAME_LOOP_NO_BREAK (frmcons, devcons, concons) |
6768 { | |
6769 struct frame *f = XFRAME (XCAR (frmcons)); | |
6770 if (f->size_change_pending) | |
5043 | 6771 change_frame_size (f, f->new_width, f->new_height, 0); |
1318 | 6772 } |
6773 } | |
6774 return Qnil; | |
6775 } | |
6776 | |
6777 /* Call this to temporarily prevent frame-size changes from being processed. | |
6778 To undo, use unbind_to(), passing it the value returned by this function. | |
6779 */ | |
6780 | |
6781 int | |
6782 begin_hold_frame_size_changes (void) | |
6783 { | |
6784 int depth = specpdl_depth (); | |
6785 record_unwind_protect (end_hold_frame_size_changes, Qnil); | |
6786 internal_bind_int (&hold_frame_size_changes, 1 + hold_frame_size_changes); | |
6787 return depth; | |
6788 } | |
6789 | |
6790 int | |
6791 enter_redisplay_critical_section (void) | |
6792 { | |
6793 int depth = specpdl_depth (); | |
6794 | |
6795 /* Reentrant entry is deadly. The calling function must check for this. */ | |
6796 assert (!in_display); | |
6797 begin_hold_frame_size_changes (); | |
6798 /* Make sure in_display gets reset, but don't set it yet so that | |
6799 commit_ritual_suicide() can be used. */ | |
6800 internal_bind_int (&in_display, 0); | |
6801 internal_bind_int (&in_display_nesting, 1 + in_display_nesting); | |
6802 #ifdef ERROR_CHECK_TRAPPING_PROBLEMS | |
6803 /* Force every call to QUIT to check for in_displayness. This will | |
6804 verify proper wrapping, as in the previous comment, aborting if not. */ | |
6805 something_happened++; | |
6806 /* Verify that no nonlocal exits blow past us. */ | |
6807 record_unwind_protect (commit_ritual_suicide, Qnil); | |
6808 #endif | |
6809 in_display++; | |
6810 | |
6811 set_trapping_problems_flags (INHIBIT_ANY_CHANGE_AFFECTING_REDISPLAY); | |
6812 /* Even checking for QUIT can cause arbitrary Lisp code to be executed, | |
6813 e.g. through a menu handler. We really don't want that happening | |
6814 inside of redisplay. Code that we `eval' is at least written with the | |
6815 expectation that it's inside of redisplay, and shouldn't try anything | |
6816 weird; but that's not the case for menu code (e.g. custom loads huge | |
6817 amounts of LISP FILES from a menu handler! FMH!). Safest just to turn | |
6818 this off. We could turn it on using UNINHIBIT_QUIT or | |
6819 begin_do_check_for_quit() in certain places if we want, if we know | |
6820 it's not in an especially tricky place. */ | |
6821 begin_dont_check_for_quit (); | |
6822 return depth; | |
6823 } | |
6824 | |
6825 void | |
6826 exit_redisplay_critical_section (int depth) | |
6827 { | |
6828 in_display--; | |
6829 assert (!in_display); | |
6830 unbind_to (depth); | |
6831 | |
6832 run_post_redisplay_actions (); | |
6833 } | |
6834 | |
6835 /* Enter the redisplay critical section if we're not already in it. This | |
6836 is for code that needs frame changes held up and other protections from | |
6837 being inside, but doesn't modify the redisplay structures, and doesn't | |
6838 look at them in a way that they will be confused by inconsistencies. */ | |
6839 | |
6840 int | |
6841 enter_redisplay_critical_section_maybe (void) | |
6842 { | |
6843 if (!in_display) | |
6844 return enter_redisplay_critical_section (); | |
6845 else | |
6846 return internal_bind_int (&in_display_nesting, 1 + in_display_nesting); | |
6847 } | |
6848 | |
6849 void | |
6850 exit_redisplay_critical_section_maybe (int depth) | |
6851 { | |
6852 if (in_display_nesting == 1) | |
6853 exit_redisplay_critical_section (depth); | |
6854 else | |
6855 unbind_to (depth); | |
6856 } | |
6857 | |
1279 | 6858 /* Ensure that all windows on the given frame are correctly displayed. |
6859 Return non-zero if pre-empted. */ | |
428 | 6860 |
442 | 6861 int |
428 | 6862 redisplay_frame (struct frame *f, int preemption_check) |
6863 { | |
6864 struct device *d = XDEVICE (f->device); | |
853 | 6865 int depth; |
428 | 6866 |
1279 | 6867 assert (f->init_finished); |
6868 | |
1318 | 6869 /* NOTE: Without sufficient checks for stream frames, we got weird |
6870 crashes in pdump. These came and went very easily -- adding the | |
6871 critical-section code for redisplay was enough to trigger them. | |
6872 Perhaps I should have debugged them but there didn't seem to be any | |
6873 point. --ben */ | |
1279 | 6874 if (FRAME_STREAM_P (f)) /* nothing to do */ |
6875 return 0; | |
6876 | |
1318 | 6877 /* Reentrancy into redisplay can be deadly. See stack trace above |
6878 generate_displayable_area(). */ | |
6879 if (in_display) | |
6880 return 1; | |
6881 | |
545 | 6882 if (preemption_check |
6883 && !DEVICE_IMPL_FLAG (d, XDEVIMPF_DONT_PREEMPT_REDISPLAY)) | |
428 | 6884 { |
6885 /* The preemption check itself takes a lot of time, | |
6886 so normally don't do it here. We do it if called | |
6887 from Lisp, though (`redisplay-frame'). */ | |
6888 int preempted; | |
6889 | |
6890 REDISPLAY_PREEMPTION_CHECK; | |
6891 if (preempted) | |
6892 return 1; | |
6893 } | |
6894 | |
442 | 6895 if (!internal_equal (f->old_buffer_alist, f->buffer_alist, 0)) |
6896 { | |
6897 Lisp_Object frame; | |
6898 | |
6899 f->old_buffer_alist = Freplace_list (f->old_buffer_alist, | |
6900 f->buffer_alist); | |
793 | 6901 frame = wrap_frame (f); |
442 | 6902 va_run_hook_with_args (Qbuffer_list_changed_hook, 1, frame); |
6903 } | |
6904 | |
428 | 6905 /* Before we put a hold on frame size changes, attempt to process |
6906 any which are already pending. */ | |
6907 if (f->size_change_pending) | |
5043 | 6908 change_frame_size (f, f->new_width, f->new_height, 0); |
428 | 6909 |
6910 /* If frame size might need to be changed, due to changed size | |
6911 of toolbars, scrollbars etc, change it now */ | |
6912 if (f->size_slipped) | |
6913 { | |
6914 adjust_frame_size (f); | |
6915 assert (!f->size_slipped); | |
6916 } | |
6917 | |
1318 | 6918 /* The menubar, toolbar, and icon updates should be done before |
853 | 6919 enter_redisplay_critical_section is called and we are officially |
3025 | 6920 `in_display'. They is because they tend to eval Lisp code, which |
1318 | 6921 needs to be carefully wrapped within the critical section (and hence |
6922 is difficult to debug). */ | |
428 | 6923 |
6924 #ifdef HAVE_MENUBARS | |
6925 /* Update the menubar. It is done first since it could change | |
6926 the menubar's visibility. This way we avoid having flashing | |
6927 caused by an Expose event generated by the visibility change | |
6928 being handled. */ | |
6929 update_frame_menubars (f); | |
6930 #endif /* HAVE_MENUBARS */ | |
6931 #ifdef HAVE_TOOLBARS | |
905 | 6932 /* Update the toolbars geometry. We don't update the toolbars |
6933 themselves at this point since the space they are trying to | |
6934 occupy may currently by occupied by gutter elements. Instead we | |
6935 update the geometry, then update the gutter geometry, then update | |
6936 the gutters - which will cause mapped windows to be repositioned | |
6937 - and finally update the toolbars. */ | |
6938 update_frame_toolbars_geometry (f); | |
428 | 6939 #endif /* HAVE_TOOLBARS */ |
442 | 6940 /* Gutter update proper has to be done inside display when no frame |
6941 size changes can occur, thus we separately update the gutter | |
6942 geometry here if it needs it. */ | |
6943 update_frame_gutter_geometry (f); | |
428 | 6944 |
6945 /* If we clear the frame we have to force its contents to be redrawn. */ | |
6946 if (f->clear) | |
6947 f->frame_changed = 1; | |
6948 | |
442 | 6949 /* Invalidate the subwindow caches. We use subwindows_changed here |
6950 to cause subwindows to get instantiated. This is because | |
428 | 6951 subwindows_state_changed is less strict - dealing with things |
6952 like the clicked state of button. We have to do this before | |
6953 redisplaying the gutters as subwindows get unmapped in the | |
6954 process.*/ | |
442 | 6955 if (f->frame_changed) |
6956 reset_frame_subwindow_instance_cache (f); | |
6957 | |
6958 if (f->frame_changed || f->subwindows_changed) | |
6959 { | |
428 | 6960 /* we have to do this so the gutter gets regenerated. */ |
6961 reset_gutter_display_lines (f); | |
6962 } | |
6963 | |
853 | 6964 depth = enter_redisplay_critical_section (); |
428 | 6965 |
6966 /* ----------------- BEGIN CRITICAL REDISPLAY SECTION ---------------- */ | |
1318 | 6967 |
6968 /* See comments in enter_redisplay_critical_section() */ | |
428 | 6969 |
442 | 6970 MAYBE_DEVMETH (d, frame_output_begin, (f)); |
6971 | |
6972 /* We can now update the gutters, safe in the knowledge that our | |
6973 efforts won't get undone. */ | |
6974 | |
6975 /* This can call lisp, but redisplay is protected by binding | |
6976 inhibit_quit. More importantly the code involving display lines | |
6977 *assumes* that GC will not happen and so does not GCPRO | |
6978 anything. Since we use this code the whole time with the gutters | |
1318 | 6979 we cannot allow GC to happen when manipulating the gutters. |
6980 | |
6981 This must be inside of the critical section for various reasons. | |
6982 For example, it messes with display structures, which be left in | |
6983 an inconsistent state. */ | |
442 | 6984 update_frame_gutters (f); |
6985 | |
428 | 6986 /* Erase the frame before outputting its contents. */ |
6987 if (f->clear) | |
6988 { | |
442 | 6989 MAYBE_DEVMETH (d, clear_frame, (f)); |
428 | 6990 } |
6991 | |
6992 /* Do the selected window first. */ | |
6993 redisplay_window (FRAME_SELECTED_WINDOW (f), 0); | |
6994 | |
6995 /* Then do the rest. */ | |
6996 redisplay_windows (f->root_window, 1); | |
6997 | |
442 | 6998 MAYBE_DEVMETH (d, frame_output_end, (f)); |
428 | 6999 |
7000 update_frame_title (f); | |
7001 | |
905 | 7002 #ifdef HAVE_TOOLBARS |
7003 /* Finally update the toolbars. It seems its possible to get in a | |
7004 cycle between updating the gutter and the toolbars. Basically we | |
7005 want to end up with both being up-to-date and this doesn't seem | |
7006 possible in a single pass. */ | |
7007 update_frame_toolbars (f); | |
7008 #endif /* HAVE_TOOLBARS */ | |
7009 | |
428 | 7010 CLASS_RESET_CHANGED_FLAGS (f); |
7011 f->window_face_cache_reset = 0; | |
7012 f->echo_area_garbaged = 0; | |
7013 f->clear = 0; | |
7014 | |
7015 if (!f->size_change_pending) | |
7016 f->size_changed = 0; | |
7017 | |
7018 /* ----------------- END CRITICAL REDISPLAY SECTION ---------------- */ | |
7019 | |
853 | 7020 /* Allow frame size changes to occur again. */ |
7021 exit_redisplay_critical_section (depth); | |
428 | 7022 |
7023 return 0; | |
7024 } | |
7025 | |
440 | 7026 /* Ensure that all frames on the given device are correctly displayed. |
7027 If AUTOMATIC is non-zero, and the device implementation indicates | |
7028 no automatic redisplay, as printers do, then the device is not | |
7029 redisplayed. AUTOMATIC is set to zero when called from lisp | |
7030 functions (redraw-device) and (redisplay-device), and to non-zero | |
7031 when called from "lazy" redisplay(); | |
7032 */ | |
428 | 7033 |
7034 static int | |
440 | 7035 redisplay_device (struct device *d, int automatic) |
428 | 7036 { |
7037 Lisp_Object frame, frmcons; | |
7038 int size_change_failed = 0; | |
7039 struct frame *f; | |
7040 | |
545 | 7041 if (automatic && DEVICE_IMPL_FLAG (d, XDEVIMPF_NO_AUTO_REDISPLAY)) |
440 | 7042 return 0; |
7043 | |
428 | 7044 if (DEVICE_STREAM_P (d)) /* nothing to do */ |
7045 return 0; | |
7046 | |
7047 /* It is possible that redisplay has been called before the | |
545 | 7048 device is fully initialized, or that the console implementation |
7049 allows frameless devices. If so then continue with the next | |
7050 device. */ | |
428 | 7051 if (NILP (DEVICE_SELECTED_FRAME (d))) |
7052 return 0; | |
7053 | |
545 | 7054 if (!DEVICE_IMPL_FLAG (d, XDEVIMPF_DONT_PREEMPT_REDISPLAY)) |
7055 { | |
7056 int preempted; | |
7057 REDISPLAY_PREEMPTION_CHECK; | |
7058 if (preempted) | |
7059 return 1; | |
7060 } | |
428 | 7061 |
7062 /* Always do the selected frame first. */ | |
7063 frame = DEVICE_SELECTED_FRAME (d); | |
7064 | |
7065 f = XFRAME (frame); | |
7066 | |
7067 if (f->icon_changed || f->windows_changed) | |
7068 update_frame_icon (f); | |
7069 | |
7070 if (FRAME_REPAINT_P (f)) | |
7071 { | |
5198 | 7072 if (CLASS_REDISPLAY_FLAGS_CHANGEDP (f)) |
428 | 7073 { |
588 | 7074 int preempted = redisplay_frame (f, 1); |
545 | 7075 if (preempted) |
7076 return 1; | |
7077 } | |
428 | 7078 |
7079 /* If the frame redisplay did not get preempted, then this flag | |
4187 | 7080 should have gotten set to 0. It might be possible for that |
7081 not to happen if a size change event were to occur at an odd | |
7082 time. To make sure we don't miss anything we simply don't | |
7083 reset the top level flags until the condition ends up being | |
7084 in the right state. */ | |
428 | 7085 if (f->size_changed) |
7086 size_change_failed = 1; | |
7087 } | |
7088 | |
7089 DEVICE_FRAME_LOOP (frmcons, d) | |
7090 { | |
7091 f = XFRAME (XCAR (frmcons)); | |
7092 | |
7093 if (f == XFRAME (DEVICE_SELECTED_FRAME (d))) | |
7094 continue; | |
7095 | |
7096 if (f->icon_changed || f->windows_changed) | |
7097 update_frame_icon (f); | |
7098 | |
7099 if (FRAME_REPAINT_P (f)) | |
7100 { | |
430 | 7101 if (CLASS_REDISPLAY_FLAGS_CHANGEDP (f)) |
428 | 7102 { |
588 | 7103 int preempted = redisplay_frame (f, 1); |
545 | 7104 if (preempted) |
7105 return 1; | |
428 | 7106 } |
7107 | |
7108 if (f->size_change_pending) | |
7109 size_change_failed = 1; | |
7110 } | |
7111 } | |
7112 | |
7113 /* If we get here then we redisplayed all of our frames without | |
7114 getting preempted so mark ourselves as clean. */ | |
7115 CLASS_RESET_CHANGED_FLAGS (d); | |
7116 | |
7117 if (!size_change_failed) | |
7118 d->size_changed = 0; | |
7119 | |
7120 return 0; | |
7121 } | |
7122 | |
7123 /* Ensure that all windows on all frames on all devices are displaying | |
7124 the current contents of their respective buffers. */ | |
7125 | |
7126 static void | |
7127 redisplay_without_hooks (void) | |
7128 { | |
7129 Lisp_Object devcons, concons; | |
7130 int size_change_failed = 0; | |
1292 | 7131 PROFILE_DECLARE (); |
7132 | |
7133 PROFILE_RECORD_ENTERING_SECTION (QSin_redisplay); | |
428 | 7134 |
7135 if (asynch_device_change_pending) | |
7136 handle_asynch_device_change (); | |
7137 | |
7138 if (!GLOBAL_REDISPLAY_FLAGS_CHANGEDP && | |
430 | 7139 !disable_preemption && preemption_count < max_preempts) |
428 | 7140 goto done; |
7141 | |
7142 DEVICE_LOOP_NO_BREAK (devcons, concons) | |
7143 { | |
7144 struct device *d = XDEVICE (XCAR (devcons)); | |
7145 int preempted; | |
7146 | |
430 | 7147 if (CLASS_REDISPLAY_FLAGS_CHANGEDP (d)) |
428 | 7148 { |
440 | 7149 preempted = redisplay_device (d, 1); |
428 | 7150 |
7151 if (preempted) | |
7152 { | |
7153 preemption_count++; | |
7154 RESET_CHANGED_SET_FLAGS; | |
7155 goto done; | |
7156 } | |
7157 | |
7158 /* See comment in redisplay_device. */ | |
7159 if (d->size_changed) | |
7160 size_change_failed = 1; | |
7161 } | |
7162 } | |
7163 preemption_count = 0; | |
7164 | |
7165 /* Mark redisplay as accurate */ | |
7166 GLOBAL_RESET_CHANGED_FLAGS; | |
7167 RESET_CHANGED_SET_FLAGS; | |
7168 | |
7169 if (faces_changed) | |
7170 { | |
7171 mark_all_faces_as_clean (); | |
7172 faces_changed = 0; | |
7173 } | |
7174 | |
7175 if (!size_change_failed) | |
7176 size_changed = 0; | |
7177 | |
7178 reset_buffer_changes (); | |
7179 | |
7180 done: | |
800 | 7181 #ifdef ERROR_CHECK_DISPLAY |
7182 sledgehammer_check_redisplay_structs (); | |
7183 #endif /* ERROR_CHECK_DISPLAY */ | |
1292 | 7184 |
7185 PROFILE_RECORD_EXITING_SECTION (QSin_redisplay); | |
428 | 7186 } |
7187 | |
1318 | 7188 /* Note: All places in the C code that call redisplay() are prepared to |
7189 handle GCing, which can happen from run_pre_idle_hook(). However, we | |
7190 can't currently handle GC inside the guts of redisplay; see | |
7191 enter_redisplay_critical_section(). | |
853 | 7192 |
7193 (#### What about other external entry points to the redisplay code? | |
7194 Someone should go through and make sure that all callers can handle | |
7195 GC there, too.) | |
7196 */ | |
7197 | |
428 | 7198 void |
7199 redisplay (void) | |
7200 { | |
853 | 7201 run_pre_idle_hook (); |
7202 redisplay_no_pre_idle_hook (); | |
7203 } | |
7204 | |
7205 void | |
7206 redisplay_no_pre_idle_hook (void) | |
7207 { | |
428 | 7208 if (last_display_warning_tick != display_warning_tick && |
7209 !inhibit_warning_display) | |
7210 { | |
7211 /* If an error occurs during this function, oh well. | |
4187 | 7212 If we report another warning, we could get stuck in an |
428 | 7213 infinite loop reporting warnings. */ |
853 | 7214 call0_trapping_problems |
7215 (0, Qdisplay_warning_buffer, | |
7216 INHIBIT_EXISTING_PERMANENT_DISPLAY_OBJECT_DELETION); | |
428 | 7217 last_display_warning_tick = display_warning_tick; |
7218 } | |
7219 | |
7220 redisplay_without_hooks (); | |
7221 } | |
7222 | |
853 | 7223 Lisp_Object |
7224 eval_within_redisplay (Lisp_Object dont_trust_this_damn_sucker) | |
7225 { | |
7226 return | |
7227 eval_in_buffer_trapping_problems | |
7228 ("Error calling function within redisplay", current_buffer, | |
1318 | 7229 dont_trust_this_damn_sucker, 0); |
853 | 7230 } |
428 | 7231 |
7232 /* Efficiently determine the window line number, and return a pointer | |
7233 to its printed representation. Do this regardless of whether | |
7234 line-number-mode is on. The first line in the buffer is counted as | |
7235 1. If narrowing is in effect, the lines are counted from the | |
7236 beginning of the visible portion of the buffer. */ | |
4970 | 7237 static Ascbyte * |
428 | 7238 window_line_number (struct window *w, int type) |
7239 { | |
7240 struct device *d = XDEVICE (XFRAME (w->frame)->device); | |
7241 struct buffer *b = XBUFFER (w->buffer); | |
7242 /* Be careful in the order of these tests. The first clause will | |
7243 fail if DEVICE_SELECTED_FRAME == Qnil (since w->frame cannot be). | |
7244 This can occur when the frame title is computed really early */ | |
665 | 7245 Charbpos pos = |
5198 | 7246 ((EQ (DEVICE_SELECTED_FRAME (d), w->frame) && |
7247 (w == XWINDOW (FRAME_SELECTED_WINDOW (device_selected_frame (d)))) && | |
7248 EQ (DEVICE_CONSOLE (d), Vselected_console) && | |
7249 XDEVICE (CONSOLE_SELECTED_DEVICE (XCONSOLE (DEVICE_CONSOLE (d)))) == d ) | |
428 | 7250 ? BUF_PT (b) |
7251 : marker_position (w->pointm[type])); | |
7252 EMACS_INT line; | |
7253 | |
7254 line = buffer_line_number (b, pos, 1); | |
7255 | |
603 | 7256 { |
4970 | 7257 static Ascbyte window_line_number_buf[DECIMAL_PRINT_SIZE (long)]; |
603 | 7258 |
7259 long_to_string (window_line_number_buf, line + 1); | |
7260 | |
7261 return window_line_number_buf; | |
7262 } | |
428 | 7263 } |
7264 | |
7265 | |
7266 /* Given a character representing an object in a modeline | |
7267 specification, return a string (stored into the global array | |
867 | 7268 `mode_spec_ibyte_string') with the information that object |
428 | 7269 represents. |
7270 | |
7271 This function is largely unchanged from previous versions of the | |
7272 redisplay engine. | |
7273 | |
7274 Warning! This code is also used for frame titles and can be called | |
7275 very early in the device/frame update process! JV | |
7276 */ | |
7277 | |
7278 static void | |
867 | 7279 decode_mode_spec (struct window *w, Ichar spec, int type) |
428 | 7280 { |
7281 Lisp_Object obj = Qnil; | |
4970 | 7282 const Ascbyte *str = NULL; |
428 | 7283 struct buffer *b = XBUFFER (w->buffer); |
7284 | |
867 | 7285 Dynarr_reset (mode_spec_ibyte_string); |
428 | 7286 |
7287 switch (spec) | |
7288 { | |
7289 /* print buffer name */ | |
7290 case 'b': | |
7291 obj = b->name; | |
7292 break; | |
7293 | |
7294 /* print visited file name */ | |
7295 case 'f': | |
7296 obj = b->filename; | |
7297 break; | |
7298 | |
7299 /* print the current column */ | |
7300 case 'c': | |
7301 { | |
4187 | 7302 Charbpos pt = (w == XWINDOW (Fselected_window (Qnil))) |
7303 ? BUF_PT (b) | |
7304 : marker_position (w->pointm[type]); | |
428 | 7305 int col = column_at_point (b, pt, 1) + !!column_number_start_at_one; |
4970 | 7306 Ascbyte buf[DECIMAL_PRINT_SIZE (long)]; |
428 | 7307 |
7308 long_to_string (buf, col); | |
7309 | |
867 | 7310 Dynarr_add_many (mode_spec_ibyte_string, |
7311 (const Ibyte *) buf, strlen (buf)); | |
428 | 7312 |
7313 goto decode_mode_spec_done; | |
7314 } | |
7315 /* print the file coding system */ | |
7316 case 'C': | |
7317 { | |
4187 | 7318 Lisp_Object codesys = b->buffer_file_coding_system; |
7319 /* Be very careful here not to get an error. */ | |
428 | 7320 if (NILP (codesys) || SYMBOLP (codesys) || CODING_SYSTEMP (codesys)) |
4187 | 7321 { |
7322 codesys = find_coding_system_for_text_file (codesys, 0); | |
428 | 7323 if (CODING_SYSTEMP (codesys)) |
4187 | 7324 obj = XCODING_SYSTEM_MNEMONIC (codesys); |
7325 } | |
428 | 7326 } |
7327 break; | |
7328 | |
7329 /* print the current line number */ | |
7330 case 'l': | |
7331 str = window_line_number (w, type); | |
7332 break; | |
7333 | |
7334 /* print value of mode-name (obsolete) */ | |
7335 case 'm': | |
7336 obj = b->mode_name; | |
7337 break; | |
7338 | |
7339 /* print hyphen and frame number, if != 1 */ | |
7340 case 'N': | |
7341 #ifdef HAVE_TTY | |
7342 { | |
7343 struct frame *f = XFRAME (w->frame); | |
7344 if (FRAME_TTY_P (f) && f->order_count > 1 && f->order_count <= 99999999) | |
7345 { | |
7346 /* Naughty, naughty */ | |
4970 | 7347 Ascbyte *writable_str = alloca_array (Ascbyte, 10); |
428 | 7348 sprintf (writable_str, "-%d", f->order_count); |
7349 str = writable_str; | |
7350 } | |
7351 } | |
7352 #endif /* HAVE_TTY */ | |
7353 break; | |
7354 | |
7355 /* print Narrow if appropriate */ | |
7356 case 'n': | |
7357 if (BUF_BEGV (b) > BUF_BEG (b) | |
7358 || BUF_ZV (b) < BUF_Z (b)) | |
7359 str = " Narrow"; | |
7360 break; | |
7361 | |
7362 /* print %, * or hyphen, if buffer is read-only, modified or neither */ | |
7363 case '*': | |
7364 str = (!NILP (b->read_only) | |
7365 ? "%" | |
7366 : ((BUF_MODIFF (b) > BUF_SAVE_MODIFF (b)) | |
7367 ? "*" | |
7368 : "-")); | |
7369 break; | |
7370 | |
7371 /* print * or hyphen -- XEmacs change to allow a buffer to be | |
4187 | 7372 read-only but still indicate whether it is modified. */ |
428 | 7373 case '+': |
7374 str = ((BUF_MODIFF (b) > BUF_SAVE_MODIFF (b)) | |
7375 ? "*" | |
7376 : (!NILP (b->read_only) | |
7377 ? "%" | |
7378 : "-")); | |
7379 break; | |
7380 | |
7381 /* #### defined in 19.29 decode_mode_spec, but not in | |
4187 | 7382 modeline-format doc string. */ |
428 | 7383 /* This differs from %* in that it ignores read-only-ness. */ |
7384 case '&': | |
7385 str = ((BUF_MODIFF (b) > BUF_SAVE_MODIFF (b)) | |
7386 ? "*" | |
7387 : "-"); | |
7388 break; | |
7389 | |
7390 /* print process status */ | |
7391 case 's': | |
7392 obj = Fget_buffer_process (w->buffer); | |
7393 if (NILP (obj)) | |
7394 str = GETTEXT ("no process"); | |
7395 else | |
7396 obj = Fsymbol_name (Fprocess_status (obj)); | |
7397 break; | |
7398 | |
7399 /* Print name of selected frame. */ | |
7400 case 'S': | |
7401 obj = XFRAME (w->frame)->name; | |
7402 break; | |
7403 | |
7404 /* indicate TEXT or BINARY */ | |
7405 case 't': | |
7406 /* #### NT does not use this any more. Now what? */ | |
7407 str = "T"; | |
7408 break; | |
7409 | |
7410 /* print percent of buffer above top of window, or Top, Bot or All */ | |
7411 case 'p': | |
7412 { | |
665 | 7413 Charbpos pos = marker_position (w->start[type]); |
428 | 7414 |
7415 /* This had better be while the desired lines are being done. */ | |
7416 if (w->window_end_pos[type] <= BUF_Z (b) - BUF_ZV (b)) | |
7417 { | |
7418 if (pos <= BUF_BEGV (b)) | |
7419 str = "All"; | |
7420 else | |
7421 str = "Bottom"; | |
7422 } | |
7423 else if (pos <= BUF_BEGV (b)) | |
7424 str = "Top"; | |
7425 else | |
7426 { | |
7427 /* This hard limit is ok since the string it will hold has a | |
4187 | 7428 fixed maximum length of 3. But just to be safe... */ |
4970 | 7429 Ascbyte buf[10]; |
428 | 7430 Charcount chars = pos - BUF_BEGV (b); |
7431 Charcount total = BUF_ZV (b) - BUF_BEGV (b); | |
7432 | |
7433 /* Avoid overflow on big buffers */ | |
7434 int percent = total > LONG_MAX/200 ? | |
7435 (chars + total/200) / (total / 100) : | |
7436 (chars * 100 + total/2) / total; | |
7437 | |
7438 /* We can't normally display a 3-digit number, so get us a | |
4187 | 7439 2-digit number that is close. */ |
428 | 7440 if (percent == 100) |
7441 percent = 99; | |
7442 | |
7443 sprintf (buf, "%d%%", percent); | |
867 | 7444 Dynarr_add_many (mode_spec_ibyte_string, (Ibyte *) buf, |
428 | 7445 strlen (buf)); |
7446 | |
7447 goto decode_mode_spec_done; | |
7448 } | |
7449 break; | |
7450 } | |
7451 | |
7452 /* print percent of buffer above bottom of window, perhaps plus | |
7453 Top, or print Bottom or All */ | |
7454 case 'P': | |
7455 { | |
665 | 7456 Charbpos toppos = marker_position (w->start[type]); |
7457 Charbpos botpos = BUF_Z (b) - w->window_end_pos[type]; | |
428 | 7458 |
7459 /* botpos is only accurate as of the last redisplay, so we can | |
4187 | 7460 only treat it as a hint. In particular, after erase-buffer, |
7461 botpos may be negative. */ | |
428 | 7462 if (botpos < toppos) |
7463 botpos = toppos; | |
7464 | |
7465 if (botpos >= BUF_ZV (b)) | |
7466 { | |
7467 if (toppos <= BUF_BEGV (b)) | |
7468 str = "All"; | |
7469 else | |
7470 str = "Bottom"; | |
7471 } | |
7472 else | |
7473 { | |
7474 /* This hard limit is ok since the string it will hold has a | |
4187 | 7475 fixed maximum length of around 6. But just to be safe... */ |
4970 | 7476 Ascbyte buf[10]; |
428 | 7477 Charcount chars = botpos - BUF_BEGV (b); |
7478 Charcount total = BUF_ZV (b) - BUF_BEGV (b); | |
7479 | |
7480 /* Avoid overflow on big buffers */ | |
7481 int percent = total > LONG_MAX/200 ? | |
7482 (chars + total/200) / (total / 100) : | |
7483 (chars * 100 + total/2) / max (total, 1); | |
7484 | |
7485 /* We can't normally display a 3-digit number, so get us a | |
4187 | 7486 2-digit number that is close. */ |
428 | 7487 if (percent == 100) |
7488 percent = 99; | |
7489 | |
7490 if (toppos <= BUF_BEGV (b)) | |
7491 sprintf (buf, "Top%d%%", percent); | |
7492 else | |
7493 sprintf (buf, "%d%%", percent); | |
7494 | |
867 | 7495 Dynarr_add_many (mode_spec_ibyte_string, (Ibyte *) buf, |
428 | 7496 strlen (buf)); |
7497 | |
7498 goto decode_mode_spec_done; | |
7499 } | |
7500 break; | |
7501 } | |
7502 | |
7503 /* print % */ | |
7504 case '%': | |
7505 str = "%"; | |
7506 break; | |
7507 | |
7508 /* print one [ for each recursive editing level. */ | |
7509 case '[': | |
7510 { | |
7511 int i; | |
7512 | |
7513 if (command_loop_level > 5) | |
7514 { | |
7515 str = "[[[... "; | |
7516 break; | |
7517 } | |
7518 | |
7519 for (i = 0; i < command_loop_level; i++) | |
867 | 7520 Dynarr_add (mode_spec_ibyte_string, '['); |
428 | 7521 |
7522 goto decode_mode_spec_done; | |
7523 } | |
7524 | |
7525 /* print one ] for each recursive editing level. */ | |
7526 case ']': | |
7527 { | |
7528 int i; | |
7529 | |
7530 if (command_loop_level > 5) | |
7531 { | |
7532 str = "...]]]"; | |
7533 break; | |
7534 } | |
7535 | |
7536 for (i = 0; i < command_loop_level; i++) | |
867 | 7537 Dynarr_add (mode_spec_ibyte_string, ']'); |
428 | 7538 |
7539 goto decode_mode_spec_done; | |
7540 } | |
7541 | |
7542 /* print infinitely many dashes -- handle at top level now */ | |
7543 case '-': | |
7544 break; | |
7545 | |
7546 } | |
7547 | |
7548 if (STRINGP (obj)) | |
867 | 7549 Dynarr_add_many (mode_spec_ibyte_string, |
428 | 7550 XSTRING_DATA (obj), |
7551 XSTRING_LENGTH (obj)); | |
7552 else if (str) | |
867 | 7553 Dynarr_add_many (mode_spec_ibyte_string, (Ibyte *) str, strlen (str)); |
428 | 7554 |
7555 decode_mode_spec_done: | |
867 | 7556 Dynarr_add (mode_spec_ibyte_string, '\0'); |
428 | 7557 } |
7558 | |
7559 /* Given a display line, free all of its data structures. */ | |
7560 | |
7561 static void | |
7562 free_display_line (struct display_line *dl) | |
7563 { | |
7564 int block; | |
7565 | |
7566 if (dl->display_blocks) | |
7567 { | |
7568 for (block = 0; block < Dynarr_largest (dl->display_blocks); block++) | |
4187 | 7569 { |
428 | 7570 struct display_block *db = Dynarr_atp (dl->display_blocks, block); |
7571 | |
7572 Dynarr_free (db->runes); | |
7573 } | |
7574 | |
7575 Dynarr_free (dl->display_blocks); | |
7576 dl->display_blocks = NULL; | |
7577 } | |
7578 | |
7579 if (dl->left_glyphs) | |
7580 { | |
7581 Dynarr_free (dl->left_glyphs); | |
7582 dl->left_glyphs = NULL; | |
7583 } | |
7584 | |
7585 if (dl->right_glyphs) | |
7586 { | |
7587 Dynarr_free (dl->right_glyphs); | |
7588 dl->right_glyphs = NULL; | |
7589 } | |
7590 } | |
7591 | |
7592 | |
7593 /* Given an array of display lines, free them and all data structures | |
7594 contained within them. */ | |
7595 | |
7596 void | |
7597 free_display_lines (display_line_dynarr *dla) | |
7598 { | |
7599 int line; | |
7600 | |
7601 for (line = 0; line < Dynarr_largest (dla); line++) | |
7602 { | |
7603 free_display_line (Dynarr_atp (dla, line)); | |
7604 } | |
7605 | |
7606 Dynarr_free (dla); | |
7607 } | |
7608 | |
7609 /* Call internal free routine for each set of display lines. */ | |
7610 | |
7611 void | |
7612 free_display_structs (struct window_mirror *mir) | |
7613 { | |
7614 if (mir->current_display_lines) | |
7615 { | |
7616 free_display_lines (mir->current_display_lines); | |
7617 mir->current_display_lines = 0; | |
7618 } | |
7619 | |
7620 if (mir->desired_display_lines) | |
7621 { | |
7622 free_display_lines (mir->desired_display_lines); | |
7623 mir->desired_display_lines = 0; | |
7624 } | |
7625 } | |
7626 | |
7627 | |
7628 static void | |
7629 mark_glyph_block_dynarr (glyph_block_dynarr *gba) | |
7630 { | |
7631 if (gba) | |
7632 { | |
4967 | 7633 glyph_block *gb = Dynarr_begin (gba); |
4844
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4815
diff
changeset
|
7634 glyph_block *gb_last = Dynarr_past_lastp (gba); |
428 | 7635 |
7636 for (; gb < gb_last; gb++) | |
7637 { | |
7638 if (!NILP (gb->glyph)) | |
7639 mark_object (gb->glyph); | |
7640 if (!NILP (gb->extent)) | |
7641 mark_object (gb->extent); | |
7642 } | |
7643 } | |
7644 } | |
7645 | |
442 | 7646 /* See the comment in image_instantiate_cache_result as to why marking |
7647 the glyph will also mark the image_instance. */ | |
7648 void | |
428 | 7649 mark_redisplay_structs (display_line_dynarr *dla) |
7650 { | |
4844
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4815
diff
changeset
|
7651 display_line *dl = Dynarr_begin (dla); |
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4815
diff
changeset
|
7652 display_line *dl_last = Dynarr_past_lastp (dla); |
428 | 7653 |
7654 for (; dl < dl_last; dl++) | |
7655 { | |
7656 display_block_dynarr *dba = dl->display_blocks; | |
4844
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4815
diff
changeset
|
7657 display_block *db = Dynarr_begin (dba); |
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4815
diff
changeset
|
7658 display_block *db_last = Dynarr_past_lastp (dba); |
428 | 7659 |
7660 for (; db < db_last; db++) | |
7661 { | |
7662 rune_dynarr *ra = db->runes; | |
4844
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4815
diff
changeset
|
7663 rune *r = Dynarr_begin (ra); |
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4815
diff
changeset
|
7664 rune *r_last = Dynarr_past_lastp (ra); |
428 | 7665 |
7666 for (; r < r_last; r++) | |
7667 { | |
7668 if (r->type == RUNE_DGLYPH) | |
7669 { | |
7670 if (!NILP (r->object.dglyph.glyph)) | |
7671 mark_object (r->object.dglyph.glyph); | |
7672 if (!NILP (r->object.dglyph.extent)) | |
7673 mark_object (r->object.dglyph.extent); | |
7674 } | |
7675 } | |
7676 } | |
7677 | |
7678 mark_glyph_block_dynarr (dl->left_glyphs); | |
7679 mark_glyph_block_dynarr (dl->right_glyphs); | |
7680 } | |
7681 } | |
7682 | |
7683 | |
2367 | 7684 |
7685 /* | |
7686 | |
7687 Info on line-start cache: | |
7688 | |
7689 (Info-goto-node "(internals)Line Start Cache") | |
7690 */ | |
428 | 7691 |
7692 /* This will get used quite a bit so we don't want to be constantly | |
7693 allocating and freeing it. */ | |
7694 static line_start_cache_dynarr *internal_cache; | |
7695 | |
7696 /* Makes internal_cache represent the TYPE display structs and only | |
7697 the TYPE display structs. */ | |
7698 | |
7699 static void | |
7700 update_internal_cache_list (struct window *w, int type) | |
7701 { | |
7702 int line; | |
7703 display_line_dynarr *dla = window_display_lines (w, type); | |
7704 | |
7705 Dynarr_reset (internal_cache); | |
7706 for (line = 0; line < Dynarr_length (dla); line++) | |
7707 { | |
7708 struct display_line *dl = Dynarr_atp (dla, line); | |
7709 | |
7710 if (dl->modeline) | |
7711 continue; | |
7712 else | |
7713 { | |
7714 struct line_start_cache lsc; | |
434 | 7715 |
826 | 7716 lsc.start = dl->charpos; |
7717 lsc.end = dl->end_charpos; | |
428 | 7718 lsc.height = dl->ascent + dl->descent; |
7719 | |
7720 Dynarr_add (internal_cache, lsc); | |
7721 } | |
7722 } | |
7723 } | |
7724 | |
7725 /* Reset the line cache if necessary. This should be run at the | |
7726 beginning of any function which access the cache. */ | |
7727 | |
7728 static void | |
7729 validate_line_start_cache (struct window *w) | |
7730 { | |
7731 struct buffer *b = XBUFFER (w->buffer); | |
7732 struct frame *f = XFRAME (w->frame); | |
7733 | |
7734 if (!w->line_cache_validation_override) | |
7735 { | |
7736 /* f->extents_changed used to be in here because extent face and | |
4187 | 7737 size changes can cause text shifting. However, the extent |
7738 covering the region is constantly having its face set and | |
7739 priority altered by the mouse code. This means that the line | |
7740 start cache is constantly being invalidated. This is bad | |
7741 since the mouse code also triggers heavy usage of the cache. | |
7742 Since it is an unlikely that f->extents being changed | |
7743 indicates that the cache really needs to be updated and if it | |
7744 does redisplay will catch it pretty quickly we no longer | |
7745 invalidate the cache if it is set. This greatly speeds up | |
7746 dragging out regions with the mouse. */ | |
428 | 7747 if (XINT (w->line_cache_last_updated) < BUF_MODIFF (b) |
7748 || f->faces_changed | |
7749 || f->clip_changed) | |
7750 { | |
7751 Dynarr_reset (w->line_start_cache); | |
7752 } | |
7753 } | |
7754 } | |
7755 | |
7756 /* Return the very first buffer position contained in the given | |
7757 window's cache, or -1 if the cache is empty. Assumes that the | |
7758 cache is valid. */ | |
7759 | |
665 | 7760 static Charbpos |
428 | 7761 line_start_cache_start (struct window *w) |
7762 { | |
7763 line_start_cache_dynarr *cache = w->line_start_cache; | |
7764 | |
7765 if (!Dynarr_length (cache)) | |
7766 return -1; | |
7767 else | |
4967 | 7768 return Dynarr_begin (cache)->start; |
428 | 7769 } |
7770 | |
7771 /* Return the very last buffer position contained in the given | |
7772 window's cache, or -1 if the cache is empty. Assumes that the | |
7773 cache is valid. */ | |
7774 | |
665 | 7775 static Charbpos |
428 | 7776 line_start_cache_end (struct window *w) |
7777 { | |
7778 line_start_cache_dynarr *cache = w->line_start_cache; | |
7779 | |
7780 if (!Dynarr_length (cache)) | |
7781 return -1; | |
7782 else | |
4844
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4815
diff
changeset
|
7783 return Dynarr_lastp (cache)->end; |
428 | 7784 } |
7785 | |
7786 /* Return the index of the line POINT is contained within in window | |
7787 W's line start cache. It will enlarge the cache or move the cache | |
7788 window in order to have POINT be present in the cache. MIN_PAST is | |
7789 a guarantee of the number of entries in the cache present on either | |
7790 side of POINT (unless a buffer boundary is hit). If MIN_PAST is -1 | |
7791 then it will be treated as 0, but the cache window will not be | |
7792 allowed to shift. Returns -1 if POINT cannot be found in the cache | |
7793 for any reason. */ | |
7794 | |
7795 int | |
665 | 7796 point_in_line_start_cache (struct window *w, Charbpos point, int min_past) |
428 | 7797 { |
7798 struct buffer *b = XBUFFER (w->buffer); | |
7799 line_start_cache_dynarr *cache = w->line_start_cache; | |
647 | 7800 int top, bottom, pos; |
428 | 7801 |
7802 validate_line_start_cache (w); | |
7803 w->line_cache_validation_override++; | |
7804 | |
7805 /* Let functions pass in negative values, but we still treat -1 | |
7806 specially. */ | |
7807 /* #### bogosity alert */ | |
7808 if (min_past < 0 && min_past != -1) | |
7809 min_past = -min_past; | |
7810 | |
7811 if (!Dynarr_length (cache) || line_start_cache_start (w) > point | |
7812 || line_start_cache_end (w) < point) | |
7813 { | |
7814 int loop; | |
7815 int win_char_height = window_char_height (w, 1); | |
7816 | |
7817 /* Occasionally we get here with a 0 height | |
4187 | 7818 window. find_next_newline_no_quit will abort if we pass it a |
7819 count of 0 so handle that case. */ | |
428 | 7820 if (!win_char_height) |
7821 win_char_height = 1; | |
7822 | |
7823 if (!Dynarr_length (cache)) | |
7824 { | |
665 | 7825 Charbpos from = find_next_newline_no_quit (b, point, -1); |
7826 Charbpos to = find_next_newline_no_quit (b, from, win_char_height); | |
428 | 7827 |
7828 update_line_start_cache (w, from, to, point, 0); | |
7829 | |
7830 if (!Dynarr_length (cache)) | |
7831 { | |
7832 w->line_cache_validation_override--; | |
7833 return -1; | |
7834 } | |
7835 } | |
7836 | |
7837 assert (Dynarr_length (cache)); | |
7838 | |
7839 loop = 0; | |
7840 while (line_start_cache_start (w) > point | |
7841 && (loop < cache_adjustment || min_past == -1)) | |
7842 { | |
665 | 7843 Charbpos from, to; |
428 | 7844 |
7845 from = line_start_cache_start (w); | |
7846 if (from <= BUF_BEGV (b)) | |
7847 break; | |
7848 | |
7849 from = find_next_newline_no_quit (b, from, -win_char_height); | |
7850 to = line_start_cache_end (w); | |
7851 | |
7852 update_line_start_cache (w, from, to, point, 0); | |
7853 loop++; | |
7854 } | |
7855 | |
7856 if (line_start_cache_start (w) > point) | |
7857 { | |
665 | 7858 Charbpos from, to; |
428 | 7859 |
7860 from = find_next_newline_no_quit (b, point, -1); | |
7861 if (from >= BUF_ZV (b)) | |
7862 { | |
7863 to = find_next_newline_no_quit (b, from, -win_char_height); | |
7864 from = to; | |
7865 to = BUF_ZV (b); | |
7866 } | |
7867 else | |
7868 to = find_next_newline_no_quit (b, from, win_char_height); | |
7869 | |
7870 update_line_start_cache (w, from, to, point, 0); | |
7871 } | |
7872 | |
7873 loop = 0; | |
7874 while (line_start_cache_end (w) < point | |
7875 && (loop < cache_adjustment || min_past == -1)) | |
7876 { | |
665 | 7877 Charbpos from, to; |
428 | 7878 |
7879 to = line_start_cache_end (w); | |
7880 if (to >= BUF_ZV (b)) | |
7881 break; | |
7882 | |
7883 from = line_start_cache_end (w); | |
7884 to = find_next_newline_no_quit (b, from, win_char_height); | |
7885 | |
7886 update_line_start_cache (w, from, to, point, 0); | |
7887 loop++; | |
7888 } | |
7889 | |
7890 if (line_start_cache_end (w) < point) | |
7891 { | |
665 | 7892 Charbpos from, to; |
428 | 7893 |
7894 from = find_next_newline_no_quit (b, point, -1); | |
7895 if (from >= BUF_ZV (b)) | |
7896 { | |
7897 to = find_next_newline_no_quit (b, from, -win_char_height); | |
7898 from = to; | |
7899 to = BUF_ZV (b); | |
7900 } | |
7901 else | |
7902 to = find_next_newline_no_quit (b, from, win_char_height); | |
7903 | |
7904 update_line_start_cache (w, from, to, point, 0); | |
7905 } | |
7906 } | |
7907 | |
7908 assert (Dynarr_length (cache)); | |
7909 | |
7910 if (min_past == -1) | |
7911 min_past = 0; | |
7912 | |
7913 /* This could happen if the buffer is narrowed. */ | |
7914 if (line_start_cache_start (w) > point | |
7915 || line_start_cache_end (w) < point) | |
7916 { | |
7917 w->line_cache_validation_override--; | |
7918 return -1; | |
7919 } | |
7920 | |
7921 find_point_loop: | |
7922 | |
7923 top = Dynarr_length (cache) - 1; | |
7924 bottom = 0; | |
7925 | |
7926 while (1) | |
7927 { | |
647 | 7928 int new_pos; |
665 | 7929 Charbpos start, end; |
428 | 7930 |
7931 pos = (bottom + top + 1) >> 1; | |
7932 start = Dynarr_atp (cache, pos)->start; | |
7933 end = Dynarr_atp (cache, pos)->end; | |
7934 | |
7935 if (point >= start && point <= end) | |
7936 { | |
7937 if (pos < min_past && line_start_cache_start (w) > BUF_BEGV (b)) | |
7938 { | |
665 | 7939 Charbpos from = |
428 | 7940 find_next_newline_no_quit (b, line_start_cache_start (w), |
7941 -min_past - 1); | |
665 | 7942 Charbpos to = line_start_cache_end (w); |
428 | 7943 |
7944 update_line_start_cache (w, from, to, point, 0); | |
7945 goto find_point_loop; | |
7946 } | |
7947 else if ((Dynarr_length (cache) - pos - 1) < min_past | |
7948 && line_start_cache_end (w) < BUF_ZV (b)) | |
7949 { | |
665 | 7950 Charbpos from = line_start_cache_end (w); |
7951 Charbpos to = find_next_newline_no_quit (b, from, | |
428 | 7952 (min_past |
7953 ? min_past | |
7954 : 1)); | |
7955 | |
7956 update_line_start_cache (w, from, to, point, 0); | |
7957 goto find_point_loop; | |
7958 } | |
7959 else | |
7960 { | |
7961 w->line_cache_validation_override--; | |
7962 return pos; | |
7963 } | |
7964 } | |
7965 else if (point > end) | |
7966 bottom = pos + 1; | |
7967 else if (point < start) | |
7968 top = pos - 1; | |
7969 else | |
2500 | 7970 ABORT (); |
428 | 7971 |
7972 new_pos = (bottom + top + 1) >> 1; | |
7973 if (pos == new_pos) | |
7974 { | |
7975 w->line_cache_validation_override--; | |
7976 return -1; | |
7977 } | |
7978 } | |
7979 } | |
7980 | |
7981 /* Return a boolean indicating if POINT would be visible in window W | |
1708 | 7982 if display of the window was to begin at STARTP. If PARTIALLY is |
7983 zero, then if POINT has fewer visible pixels than the window clip, | |
7984 0 is returned; otherwise, 1 is returned if POINT has any visible | |
7985 pixels. */ | |
428 | 7986 int |
1708 | 7987 point_would_be_visible (struct window *w, Charbpos startp, Charbpos point, |
7988 int partially) | |
428 | 7989 { |
7990 struct buffer *b = XBUFFER (w->buffer); | |
5198 | 7991 int pixpos = -WINDOW_TEXT_TOP_CLIP (w); |
428 | 7992 int bottom = WINDOW_TEXT_HEIGHT (w); |
7993 int start_elt; | |
7994 | |
7995 /* If point is before the intended start it obviously can't be visible. */ | |
7996 if (point < startp) | |
7997 return 0; | |
7998 | |
7999 /* If point or start are not in the accessible buffer range, then | |
8000 fail. */ | |
8001 if (startp < BUF_BEGV (b) || startp > BUF_ZV (b) | |
8002 || point < BUF_BEGV (b) || point > BUF_ZV (b)) | |
8003 return 0; | |
8004 | |
8005 validate_line_start_cache (w); | |
8006 w->line_cache_validation_override++; | |
8007 | |
8008 start_elt = point_in_line_start_cache (w, startp, 0); | |
8009 if (start_elt == -1) | |
8010 { | |
8011 w->line_cache_validation_override--; | |
8012 return 0; | |
8013 } | |
8014 | |
8015 assert (line_start_cache_start (w) <= startp | |
8016 && line_start_cache_end (w) >= startp); | |
8017 | |
8018 while (1) | |
8019 { | |
8020 int height; | |
8021 | |
8022 /* Expand the cache if necessary. */ | |
8023 if (start_elt == Dynarr_length (w->line_start_cache)) | |
8024 { | |
665 | 8025 Charbpos old_startp = |
428 | 8026 Dynarr_atp (w->line_start_cache, start_elt - 1)->start; |
8027 | |
8028 start_elt = point_in_line_start_cache (w, old_startp, | |
8029 window_char_height (w, 0)); | |
8030 | |
8031 /* We've already actually processed old_startp, so increment | |
4187 | 8032 immediately. */ |
428 | 8033 start_elt++; |
8034 | |
8035 /* If this happens we didn't add any extra elements. Bummer. */ | |
8036 if (start_elt == Dynarr_length (w->line_start_cache)) | |
8037 { | |
8038 w->line_cache_validation_override--; | |
8039 return 0; | |
8040 } | |
8041 } | |
8042 | |
8043 height = Dynarr_atp (w->line_start_cache, start_elt)->height; | |
8044 | |
8045 if (pixpos + height > bottom) | |
8046 { | |
1708 | 8047 if (bottom - pixpos < (partially ? 0 : VERTICAL_CLIP (w, 0))) |
428 | 8048 { |
8049 w->line_cache_validation_override--; | |
8050 return 0; | |
8051 } | |
8052 } | |
8053 | |
8054 pixpos += height; | |
8055 if (point <= Dynarr_atp (w->line_start_cache, start_elt)->end) | |
8056 { | |
8057 w->line_cache_validation_override--; | |
8058 return 1; | |
8059 } | |
8060 | |
8061 start_elt++; | |
8062 } | |
8063 } | |
8064 | |
8065 /* For the given window W, if display starts at STARTP, what will be | |
8066 the buffer position at the beginning or end of the last line | |
8067 displayed. The end of the last line is also know as the window end | |
8068 position. | |
8069 | |
442 | 8070 WARNING: It is possible that redisplay failed to layout any lines for the |
8071 windows. Under normal circumstances this is rare. However it seems that it | |
8072 does occur in the following situation: A mouse event has come in and we | |
8073 need to compute its location in a window. That code (in | |
8074 pixel_to_glyph_translation) already can handle 0 as an error return value. | |
8075 | |
428 | 8076 #### With a little work this could probably be reworked as just a |
8077 call to start_with_line_at_pixpos. */ | |
8078 | |
665 | 8079 static Charbpos |
8080 start_end_of_last_line (struct window *w, Charbpos startp, int end, | |
4187 | 8081 int may_error) |
428 | 8082 { |
8083 struct buffer *b = XBUFFER (w->buffer); | |
8084 line_start_cache_dynarr *cache = w->line_start_cache; | |
8085 int pixpos = 0; | |
8086 int bottom = WINDOW_TEXT_HEIGHT (w); | |
665 | 8087 Charbpos cur_start; |
428 | 8088 int start_elt; |
8089 | |
8090 validate_line_start_cache (w); | |
8091 w->line_cache_validation_override++; | |
8092 | |
8093 if (startp < BUF_BEGV (b)) | |
8094 startp = BUF_BEGV (b); | |
8095 else if (startp > BUF_ZV (b)) | |
8096 startp = BUF_ZV (b); | |
8097 cur_start = startp; | |
8098 | |
8099 start_elt = point_in_line_start_cache (w, cur_start, 0); | |
8100 if (start_elt == -1) | |
442 | 8101 return may_error ? 0 : startp; |
428 | 8102 |
8103 while (1) | |
8104 { | |
8105 int height = Dynarr_atp (cache, start_elt)->height; | |
8106 | |
8107 cur_start = Dynarr_atp (cache, start_elt)->start; | |
8108 | |
8109 if (pixpos + height > bottom) | |
8110 { | |
8111 /* Adjust for any possible clip. */ | |
8112 if (bottom - pixpos < VERTICAL_CLIP (w, 0)) | |
8113 start_elt--; | |
8114 | |
8115 if (start_elt < 0) | |
8116 { | |
8117 w->line_cache_validation_override--; | |
8118 if (end) | |
8119 return BUF_ZV (b); | |
8120 else | |
8121 return BUF_BEGV (b); | |
8122 } | |
8123 else | |
8124 { | |
8125 w->line_cache_validation_override--; | |
8126 if (end) | |
8127 return Dynarr_atp (cache, start_elt)->end; | |
8128 else | |
8129 return Dynarr_atp (cache, start_elt)->start; | |
8130 } | |
8131 } | |
8132 | |
8133 pixpos += height; | |
8134 start_elt++; | |
8135 if (start_elt == Dynarr_length (cache)) | |
8136 { | |
665 | 8137 Charbpos from = line_start_cache_end (w); |
428 | 8138 int win_char_height = window_char_height (w, 0); |
665 | 8139 Charbpos to = find_next_newline_no_quit (b, from, |
428 | 8140 (win_char_height |
8141 ? win_char_height | |
8142 : 1)); | |
8143 | |
8144 /* We've hit the end of the bottom so that's what it is. */ | |
8145 if (from >= BUF_ZV (b)) | |
8146 { | |
8147 w->line_cache_validation_override--; | |
8148 return BUF_ZV (b); | |
8149 } | |
8150 | |
8151 update_line_start_cache (w, from, to, BUF_PT (b), 0); | |
8152 | |
8153 /* Updating the cache invalidates any current indexes. */ | |
8154 start_elt = point_in_line_start_cache (w, cur_start, -1) + 1; | |
8155 } | |
8156 } | |
8157 } | |
8158 | |
8159 /* For the given window W, if display starts at STARTP, what will be | |
8160 the buffer position at the beginning of the last line displayed. */ | |
8161 | |
665 | 8162 Charbpos |
8163 start_of_last_line (struct window *w, Charbpos startp) | |
428 | 8164 { |
442 | 8165 return start_end_of_last_line (w, startp, 0 , 0); |
428 | 8166 } |
8167 | |
8168 /* For the given window W, if display starts at STARTP, what will be | |
8169 the buffer position at the end of the last line displayed. This is | |
8170 also know as the window end position. */ | |
8171 | |
665 | 8172 Charbpos |
8173 end_of_last_line (struct window *w, Charbpos startp) | |
428 | 8174 { |
442 | 8175 return start_end_of_last_line (w, startp, 1, 0); |
428 | 8176 } |
8177 | |
665 | 8178 static Charbpos |
8179 end_of_last_line_may_error (struct window *w, Charbpos startp) | |
442 | 8180 { |
8181 return start_end_of_last_line (w, startp, 1, 1); | |
8182 } | |
8183 | |
8184 | |
428 | 8185 /* For window W, what does the starting position have to be so that |
8186 the line containing POINT will cover pixel position PIXPOS. */ | |
8187 | |
665 | 8188 Charbpos |
8189 start_with_line_at_pixpos (struct window *w, Charbpos point, int pixpos) | |
428 | 8190 { |
8191 struct buffer *b = XBUFFER (w->buffer); | |
8192 int cur_elt; | |
665 | 8193 Charbpos cur_pos, prev_pos = point; |
428 | 8194 int point_line_height; |
8195 int pixheight = pixpos - WINDOW_TEXT_TOP (w); | |
8196 | |
8197 validate_line_start_cache (w); | |
8198 w->line_cache_validation_override++; | |
8199 | |
8200 cur_elt = point_in_line_start_cache (w, point, 0); | |
8201 /* #### See comment in update_line_start_cache about big minibuffers. */ | |
8202 if (cur_elt < 0) | |
8203 { | |
8204 w->line_cache_validation_override--; | |
8205 return point; | |
8206 } | |
8207 | |
8208 point_line_height = Dynarr_atp (w->line_start_cache, cur_elt)->height; | |
8209 | |
8210 while (1) | |
8211 { | |
8212 cur_pos = Dynarr_atp (w->line_start_cache, cur_elt)->start; | |
8213 | |
8214 pixheight -= Dynarr_atp (w->line_start_cache, cur_elt)->height; | |
8215 | |
8216 /* Do not take into account the value of vertical_clip here. | |
4187 | 8217 That is the responsibility of the calling functions. */ |
428 | 8218 if (pixheight < 0) |
8219 { | |
8220 w->line_cache_validation_override--; | |
8221 if (-pixheight > point_line_height) | |
8222 /* We can't make the target line cover pixpos, so put it | |
8223 above pixpos. That way it will at least be visible. */ | |
8224 return prev_pos; | |
8225 else | |
8226 return cur_pos; | |
8227 } | |
8228 | |
8229 cur_elt--; | |
8230 while (cur_elt < 0) | |
8231 { | |
665 | 8232 Charbpos from, to; |
428 | 8233 int win_char_height; |
8234 | |
8235 if (cur_pos <= BUF_BEGV (b)) | |
8236 { | |
8237 w->line_cache_validation_override--; | |
8238 return BUF_BEGV (b); | |
8239 } | |
8240 | |
8241 win_char_height = window_char_height (w, 0); | |
8242 if (!win_char_height) | |
8243 win_char_height = 1; | |
8244 | |
8245 from = find_next_newline_no_quit (b, cur_pos, -win_char_height); | |
8246 to = line_start_cache_end (w); | |
8247 update_line_start_cache (w, from, to, point, 0); | |
8248 | |
8249 cur_elt = point_in_line_start_cache (w, cur_pos, 2) - 1; | |
8250 assert (cur_elt >= -1); | |
8251 /* This used to be cur_elt>=0 under the assumption that if | |
8252 point is in the top line and not at BUF_BEGV, then | |
434 | 8253 setting the window_start to a newline before the start of |
428 | 8254 the first line will always cause scrolling. |
8255 | |
8256 However in my (jv) opinion this is wrong. That new line | |
8257 can be hidden in various ways: invisible extents, an | |
8258 explicit window-start not at a newline character etc. | |
8259 The existence of those are indeed known to create crashes | |
8260 on that assert. So we have no option but to continue the | |
8261 search if we found point at the top of the line_start_cache | |
8262 again. */ | |
4967 | 8263 cur_pos = Dynarr_begin (w->line_start_cache)->start; |
428 | 8264 } |
8265 prev_pos = cur_pos; | |
8266 } | |
8267 } | |
8268 | |
8269 /* For window W, what does the starting position have to be so that | |
8270 the line containing point is on display line LINE. If LINE is | |
8271 positive it is considered to be the number of lines from the top of | |
8272 the window (0 is the top line). If it is negative the number is | |
8273 considered to be the number of lines from the bottom (-1 is the | |
8274 bottom line). */ | |
8275 | |
665 | 8276 Charbpos |
8277 start_with_point_on_display_line (struct window *w, Charbpos point, int line) | |
428 | 8278 { |
8279 validate_line_start_cache (w); | |
8280 w->line_cache_validation_override++; | |
8281 | |
8282 if (line >= 0) | |
8283 { | |
8284 int cur_elt = point_in_line_start_cache (w, point, line); | |
8285 | |
8286 if (cur_elt - line < 0) | |
8287 cur_elt = 0; /* Hit the top */ | |
8288 else | |
8289 cur_elt -= line; | |
8290 | |
8291 w->line_cache_validation_override--; | |
8292 return Dynarr_atp (w->line_start_cache, cur_elt)->start; | |
8293 } | |
8294 else | |
8295 { | |
8296 /* The calculated value of pixpos is correct for the bottom line | |
4187 | 8297 or what we want when line is -1. Therefore we subtract one |
8298 because we have already handled one line. */ | |
428 | 8299 int new_line = -line - 1; |
8300 int cur_elt = point_in_line_start_cache (w, point, new_line); | |
8301 int pixpos = WINDOW_TEXT_BOTTOM (w); | |
665 | 8302 Charbpos retval, search_point; |
428 | 8303 |
8304 /* If scroll_on_clipped_lines is false, the last "visible" line of | |
4187 | 8305 the window covers the pixel at WINDOW_TEXT_BOTTOM (w) - 1. |
8306 If s_o_c_l is true, then we don't want to count a clipped | |
8307 line, so back up from the bottom by the height of the line | |
8308 containing point. */ | |
428 | 8309 if (scroll_on_clipped_lines) |
8310 pixpos -= Dynarr_atp (w->line_start_cache, cur_elt)->height; | |
8311 else | |
8312 pixpos -= 1; | |
8313 | |
8314 if (cur_elt + new_line >= Dynarr_length (w->line_start_cache)) | |
8315 { | |
8316 /* Hit the bottom of the buffer. */ | |
8317 int adjustment = | |
8318 (cur_elt + new_line) - Dynarr_length (w->line_start_cache) + 1; | |
8319 Lisp_Object window; | |
8320 int defheight; | |
8321 | |
793 | 8322 window = wrap_window (w); |
5047
07dcc7000bbf
put width before height consistently, fix a real bug found in the process
Ben Wing <ben@xemacs.org>
parents:
5043
diff
changeset
|
8323 default_face_width_and_height (window, 0, &defheight); |
428 | 8324 |
8325 cur_elt = Dynarr_length (w->line_start_cache) - 1; | |
8326 | |
8327 pixpos -= (adjustment * defheight); | |
8328 if (pixpos < WINDOW_TEXT_TOP (w)) | |
8329 pixpos = WINDOW_TEXT_TOP (w); | |
8330 } | |
8331 else | |
8332 cur_elt = cur_elt + new_line; | |
8333 | |
8334 search_point = Dynarr_atp (w->line_start_cache, cur_elt)->start; | |
8335 | |
8336 retval = start_with_line_at_pixpos (w, search_point, pixpos); | |
8337 w->line_cache_validation_override--; | |
8338 return retval; | |
8339 } | |
8340 } | |
8341 | |
8342 /* This is used to speed up vertical scrolling by caching the known | |
8343 buffer starting positions for display lines. This allows the | |
8344 scrolling routines to avoid costly calls to regenerate_window. If | |
8345 NO_REGEN is true then it will only add the values in the DESIRED | |
8346 display structs which are in the given range. | |
8347 | |
8348 Note also that the FROM/TO values are minimums. It is possible | |
8349 that this function will actually add information outside of the | |
8350 lines containing those positions. This can't hurt but it could | |
8351 possibly help. | |
8352 | |
8353 #### We currently force the cache to have only 1 contiguous region. | |
8354 It might help to make the cache a dynarr of caches so that we can | |
8355 cover more areas. This might, however, turn out to be a lot of | |
8356 overhead for too little gain. */ | |
8357 | |
8358 static void | |
665 | 8359 update_line_start_cache (struct window *w, Charbpos from, Charbpos to, |
8360 Charbpos point, int no_regen) | |
428 | 8361 { |
8362 struct buffer *b = XBUFFER (w->buffer); | |
8363 line_start_cache_dynarr *cache = w->line_start_cache; | |
665 | 8364 Charbpos low_bound, high_bound; |
428 | 8365 |
8366 validate_line_start_cache (w); | |
8367 w->line_cache_validation_override++; | |
8368 | |
8369 if (from < BUF_BEGV (b)) | |
8370 from = BUF_BEGV (b); | |
8371 if (to > BUF_ZV (b)) | |
8372 to = BUF_ZV (b); | |
8373 | |
8374 if (from > to) | |
8375 { | |
8376 w->line_cache_validation_override--; | |
8377 return; | |
8378 } | |
8379 | |
8380 if (Dynarr_length (cache)) | |
8381 { | |
8382 low_bound = line_start_cache_start (w); | |
8383 high_bound = line_start_cache_end (w); | |
8384 | |
8385 /* Check to see if the desired range is already in the cache. */ | |
8386 if (from >= low_bound && to <= high_bound) | |
8387 { | |
8388 w->line_cache_validation_override--; | |
8389 return; | |
8390 } | |
8391 | |
8392 /* Check to make sure that the desired range is adjacent to the | |
8393 current cache. If not, invalidate the cache. */ | |
8394 if (to < low_bound || from > high_bound) | |
8395 { | |
8396 Dynarr_reset (cache); | |
8397 low_bound = high_bound = -1; | |
8398 } | |
8399 } | |
8400 else | |
8401 { | |
8402 low_bound = high_bound = -1; | |
8403 } | |
8404 | |
8405 w->line_cache_last_updated = make_int (BUF_MODIFF (b)); | |
8406 | |
8407 /* This could be integrated into the next two sections, but it is easier | |
8408 to follow what's going on by having it separate. */ | |
8409 if (no_regen) | |
8410 { | |
665 | 8411 Charbpos start, end; |
428 | 8412 |
8413 update_internal_cache_list (w, DESIRED_DISP); | |
8414 if (!Dynarr_length (internal_cache)) | |
8415 { | |
8416 w->line_cache_validation_override--; | |
8417 return; | |
8418 } | |
8419 | |
4844
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4815
diff
changeset
|
8420 start = Dynarr_begin (internal_cache)->start; |
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4815
diff
changeset
|
8421 end = Dynarr_lastp (internal_cache)->end; |
428 | 8422 |
8423 /* We aren't allowed to generate additional information to fill in | |
4187 | 8424 gaps, so if the DESIRED structs don't overlap the cache, reset the |
8425 cache. */ | |
428 | 8426 if (Dynarr_length (cache)) |
8427 { | |
8428 if (end < low_bound || start > high_bound) | |
8429 Dynarr_reset (cache); | |
8430 | |
8431 /* #### What should really happen if what we are doing is | |
4187 | 8432 extending a line (the last line)? */ |
428 | 8433 if (Dynarr_length (cache) == 1 |
8434 && Dynarr_length (internal_cache) == 1) | |
8435 Dynarr_reset (cache); | |
8436 } | |
8437 | |
8438 if (!Dynarr_length (cache)) | |
8439 { | |
4967 | 8440 Dynarr_add_many (cache, Dynarr_begin (internal_cache), |
428 | 8441 Dynarr_length (internal_cache)); |
8442 w->line_cache_validation_override--; | |
8443 return; | |
8444 } | |
8445 | |
8446 /* An extra check just in case the calling function didn't pass in | |
4187 | 8447 the bounds of the DESIRED structs in the first place. */ |
428 | 8448 if (start >= low_bound && end <= high_bound) |
8449 { | |
8450 w->line_cache_validation_override--; | |
8451 return; | |
8452 } | |
8453 | |
8454 /* At this point we know that the internal cache partially overlaps | |
4187 | 8455 the main cache. */ |
428 | 8456 if (start < low_bound) |
8457 { | |
8458 int ic_elt = Dynarr_length (internal_cache) - 1; | |
8459 while (ic_elt >= 0) | |
8460 { | |
8461 if (Dynarr_atp (internal_cache, ic_elt)->start < low_bound) | |
8462 break; | |
8463 else | |
8464 ic_elt--; | |
8465 } | |
8466 | |
8467 if (!(ic_elt >= 0)) | |
8468 { | |
8469 Dynarr_reset (cache); | |
4967 | 8470 Dynarr_add_many (cache, Dynarr_begin (internal_cache), |
428 | 8471 Dynarr_length (internal_cache)); |
8472 w->line_cache_validation_override--; | |
8473 return; | |
8474 } | |
8475 | |
5038 | 8476 Dynarr_prepend_many (cache, Dynarr_begin (internal_cache), |
428 | 8477 ic_elt + 1); |
8478 } | |
8479 | |
8480 if (end > high_bound) | |
8481 { | |
8482 int ic_elt = 0; | |
8483 | |
8484 while (ic_elt < Dynarr_length (internal_cache)) | |
8485 { | |
8486 if (Dynarr_atp (internal_cache, ic_elt)->start > high_bound) | |
8487 break; | |
8488 else | |
8489 ic_elt++; | |
8490 } | |
8491 | |
8492 if (!(ic_elt < Dynarr_length (internal_cache))) | |
8493 { | |
8494 Dynarr_reset (cache); | |
4967 | 8495 Dynarr_add_many (cache, Dynarr_begin (internal_cache), |
428 | 8496 Dynarr_length (internal_cache)); |
8497 w->line_cache_validation_override--; | |
8498 return; | |
8499 } | |
8500 | |
8501 Dynarr_add_many (cache, Dynarr_atp (internal_cache, ic_elt), | |
8502 Dynarr_length (internal_cache) - ic_elt); | |
8503 } | |
8504 | |
8505 w->line_cache_validation_override--; | |
8506 return; | |
8507 } | |
8508 | |
8509 if (!Dynarr_length (cache) || from < low_bound) | |
8510 { | |
665 | 8511 Charbpos startp = find_next_newline_no_quit (b, from, -1); |
428 | 8512 int marker = 0; |
8513 int old_lb = low_bound; | |
8514 | |
8515 while (startp < old_lb || low_bound == -1) | |
8516 { | |
8517 int ic_elt; | |
4187 | 8518 Charbpos new_startp; |
428 | 8519 |
8520 regenerate_window (w, startp, point, CMOTION_DISP); | |
8521 update_internal_cache_list (w, CMOTION_DISP); | |
8522 | |
8523 /* If this assert is triggered then regenerate_window failed | |
4187 | 8524 to layout a single line. This is not possible since we |
442 | 8525 force at least a single line to be layout for CMOTION_DISP */ |
8526 assert (Dynarr_length (internal_cache)); | |
4967 | 8527 assert (startp == Dynarr_begin (internal_cache)->start); |
428 | 8528 |
8529 ic_elt = Dynarr_length (internal_cache) - 1; | |
8530 if (low_bound != -1) | |
8531 { | |
8532 while (ic_elt >= 0) | |
8533 { | |
8534 if (Dynarr_atp (internal_cache, ic_elt)->start < old_lb) | |
8535 break; | |
8536 else | |
8537 ic_elt--; | |
8538 } | |
8539 } | |
8540 assert (ic_elt >= 0); | |
8541 | |
8542 new_startp = Dynarr_atp (internal_cache, ic_elt)->end + 1; | |
8543 | |
4187 | 8544 /* |
8545 * Handle invisible text properly: | |
8546 * If the last line we're inserting has the same end as the | |
8547 * line before which it will be added, merge the two lines. | |
8548 */ | |
8549 if (Dynarr_length (cache) && | |
8550 Dynarr_atp (internal_cache, ic_elt)->end == | |
8551 Dynarr_atp (cache, marker)->end) | |
8552 { | |
8553 Dynarr_atp (cache, marker)->start | |
8554 = Dynarr_atp (internal_cache, ic_elt)->start; | |
8555 Dynarr_atp (cache, marker)->height | |
8556 = Dynarr_atp (internal_cache, ic_elt)->height; | |
8557 ic_elt--; | |
8558 } | |
8559 | |
8560 if (ic_elt >= 0) /* we still have lines to add.. */ | |
8561 { | |
4967 | 8562 Dynarr_insert_many (cache, Dynarr_begin (internal_cache), |
4187 | 8563 ic_elt + 1, marker); |
8564 marker += (ic_elt + 1); | |
8565 } | |
428 | 8566 |
8567 if (startp < low_bound || low_bound == -1) | |
8568 low_bound = startp; | |
8569 startp = new_startp; | |
8570 if (startp > BUF_ZV (b)) | |
8571 { | |
8572 w->line_cache_validation_override--; | |
8573 return; | |
8574 } | |
8575 } | |
8576 } | |
8577 | |
8578 assert (Dynarr_length (cache)); | |
8579 assert (from >= low_bound); | |
8580 | |
8581 /* Readjust the high_bound to account for any changes made while | |
8582 correcting the low_bound. */ | |
4844
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4815
diff
changeset
|
8583 high_bound = Dynarr_lastp (cache)->end; |
428 | 8584 |
8585 if (to > high_bound) | |
8586 { | |
4844
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4815
diff
changeset
|
8587 Charbpos startp = Dynarr_lastp (cache)->end + 1; |
428 | 8588 |
8589 do | |
8590 { | |
8591 regenerate_window (w, startp, point, CMOTION_DISP); | |
8592 update_internal_cache_list (w, CMOTION_DISP); | |
8593 | |
8594 /* See comment above about regenerate_window failing. */ | |
8595 assert (Dynarr_length (internal_cache)); | |
8596 | |
4967 | 8597 Dynarr_add_many (cache, Dynarr_begin (internal_cache), |
428 | 8598 Dynarr_length (internal_cache)); |
4844
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4815
diff
changeset
|
8599 high_bound = Dynarr_lastp (cache)->end; |
428 | 8600 startp = high_bound + 1; |
8601 } | |
8602 while (to > high_bound); | |
8603 } | |
8604 | |
8605 w->line_cache_validation_override--; | |
8606 assert (to <= high_bound); | |
8607 } | |
8608 | |
8609 | |
8610 /* Given x and y coordinates in characters, relative to a window, | |
8611 return the pixel location corresponding to those coordinates. The | |
8612 pixel location returned is the center of the given character | |
8613 position. The pixel values are generated relative to the window, | |
8614 not the frame. | |
8615 | |
8616 The modeline is considered to be part of the window. */ | |
8617 | |
8618 void | |
8619 glyph_to_pixel_translation (struct window *w, int char_x, int char_y, | |
8620 int *pix_x, int *pix_y) | |
8621 { | |
8622 display_line_dynarr *dla = window_display_lines (w, CURRENT_DISP); | |
8623 int num_disp_lines, modeline; | |
8624 Lisp_Object window; | |
8625 int defheight, defwidth; | |
8626 | |
793 | 8627 window = wrap_window (w); |
5047
07dcc7000bbf
put width before height consistently, fix a real bug found in the process
Ben Wing <ben@xemacs.org>
parents:
5043
diff
changeset
|
8628 default_face_width_and_height (window, &defwidth, &defheight); |
428 | 8629 |
8630 /* If we get a bogus value indicating somewhere above or to the left of | |
8631 the window, use the first window line or character position | |
8632 instead. */ | |
8633 if (char_y < 0) | |
8634 char_y = 0; | |
8635 if (char_x < 0) | |
8636 char_x = 0; | |
8637 | |
8638 num_disp_lines = Dynarr_length (dla); | |
8639 modeline = 0; | |
8640 if (num_disp_lines) | |
8641 { | |
4967 | 8642 if (Dynarr_begin (dla)->modeline) |
428 | 8643 { |
8644 num_disp_lines--; | |
8645 modeline = 1; | |
8646 } | |
8647 } | |
8648 | |
8649 /* First check if the y position intersects the display lines. */ | |
8650 if (char_y < num_disp_lines) | |
8651 { | |
8652 struct display_line *dl = Dynarr_atp (dla, char_y + modeline); | |
8653 struct display_block *db = get_display_block_from_line (dl, TEXT); | |
8654 | |
8655 *pix_y = (dl->ypos - dl->ascent + | |
647 | 8656 ((dl->ascent + dl->descent - dl->clip) >> 1)); |
428 | 8657 |
8658 if (char_x < Dynarr_length (db->runes)) | |
8659 { | |
8660 struct rune *rb = Dynarr_atp (db->runes, char_x); | |
8661 | |
8662 *pix_x = rb->xpos + (rb->width >> 1); | |
8663 } | |
8664 else | |
8665 { | |
8666 int last_rune = Dynarr_length (db->runes) - 1; | |
8667 struct rune *rb = Dynarr_atp (db->runes, last_rune); | |
8668 | |
8669 char_x -= last_rune; | |
8670 | |
8671 *pix_x = rb->xpos + rb->width; | |
8672 *pix_x += ((char_x - 1) * defwidth); | |
8673 *pix_x += (defwidth >> 1); | |
8674 } | |
8675 } | |
8676 else | |
8677 { | |
8678 /* It didn't intersect, so extrapolate. #### For now, we include the | |
8679 modeline in this since we don't have true character positions in | |
8680 it. */ | |
8681 | |
8682 if (!Dynarr_length (w->face_cachels)) | |
8683 reset_face_cachels (w); | |
8684 | |
8685 char_y -= num_disp_lines; | |
8686 | |
8687 if (Dynarr_length (dla)) | |
8688 { | |
4844
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4815
diff
changeset
|
8689 struct display_line *dl = Dynarr_lastp (dla); |
428 | 8690 *pix_y = dl->ypos + dl->descent - dl->clip; |
8691 } | |
8692 else | |
8693 *pix_y = WINDOW_TEXT_TOP (w); | |
8694 | |
8695 *pix_y += (char_y * defheight); | |
8696 *pix_y += (defheight >> 1); | |
8697 | |
8698 *pix_x = WINDOW_TEXT_LEFT (w); | |
8699 /* Don't adjust by one because this is still the unadjusted value. */ | |
8700 *pix_x += (char_x * defwidth); | |
8701 *pix_x += (defwidth >> 1); | |
8702 } | |
8703 | |
8704 if (*pix_x > w->pixel_left + w->pixel_width) | |
8705 *pix_x = w->pixel_left + w->pixel_width; | |
8706 if (*pix_y > w->pixel_top + w->pixel_height) | |
8707 *pix_y = w->pixel_top + w->pixel_height; | |
8708 | |
8709 *pix_x -= w->pixel_left; | |
8710 *pix_y -= w->pixel_top; | |
8711 } | |
8712 | |
8713 /* Given a display line and a position, determine if there is a glyph | |
8714 there and return information about it if there is. */ | |
8715 | |
8716 static void | |
8717 get_position_object (struct display_line *dl, Lisp_Object *obj1, | |
8718 Lisp_Object *obj2, int x_coord, int *low_x_coord, | |
8719 int *high_x_coord) | |
8720 { | |
8721 struct display_block *db; | |
8722 int elt; | |
8723 int block = | |
8724 get_next_display_block (dl->bounds, dl->display_blocks, x_coord, 0); | |
8725 | |
8726 /* We use get_next_display_block to get the actual display block | |
8727 that would be displayed at x_coord. */ | |
8728 | |
8729 if (block == NO_BLOCK) | |
8730 return; | |
8731 else | |
8732 db = Dynarr_atp (dl->display_blocks, block); | |
8733 | |
8734 for (elt = 0; elt < Dynarr_length (db->runes); elt++) | |
8735 { | |
8736 struct rune *rb = Dynarr_atp (db->runes, elt); | |
8737 | |
8738 if (rb->xpos <= x_coord && x_coord < (rb->xpos + rb->width)) | |
8739 { | |
8740 if (rb->type == RUNE_DGLYPH) | |
8741 { | |
8742 *obj1 = rb->object.dglyph.glyph; | |
8743 *obj2 = rb->object.dglyph.extent; | |
8744 } | |
8745 else | |
8746 { | |
8747 *obj1 = Qnil; | |
8748 *obj2 = Qnil; | |
8749 } | |
8750 | |
8751 if (low_x_coord) | |
8752 *low_x_coord = rb->xpos; | |
8753 if (high_x_coord) | |
8754 *high_x_coord = rb->xpos + rb->width; | |
8755 | |
8756 return; | |
8757 } | |
8758 } | |
8759 } | |
8760 | |
8761 #define UPDATE_CACHE_RETURN \ | |
8762 do { \ | |
8763 d->pixel_to_glyph_cache.valid = 1; \ | |
8764 d->pixel_to_glyph_cache.low_x_coord = low_x_coord; \ | |
8765 d->pixel_to_glyph_cache.high_x_coord = high_x_coord; \ | |
8766 d->pixel_to_glyph_cache.low_y_coord = low_y_coord; \ | |
8767 d->pixel_to_glyph_cache.high_y_coord = high_y_coord; \ | |
8768 d->pixel_to_glyph_cache.frame = f; \ | |
8769 d->pixel_to_glyph_cache.col = *col; \ | |
8770 d->pixel_to_glyph_cache.row = *row; \ | |
8771 d->pixel_to_glyph_cache.obj_x = *obj_x; \ | |
8772 d->pixel_to_glyph_cache.obj_y = *obj_y; \ | |
8773 d->pixel_to_glyph_cache.w = *w; \ | |
5090 | 8774 d->pixel_to_glyph_cache.charpos = *charpos; \ |
428 | 8775 d->pixel_to_glyph_cache.closest = *closest; \ |
8776 d->pixel_to_glyph_cache.modeline_closest = *modeline_closest; \ | |
8777 d->pixel_to_glyph_cache.obj1 = *obj1; \ | |
8778 d->pixel_to_glyph_cache.obj2 = *obj2; \ | |
8779 d->pixel_to_glyph_cache.retval = position; \ | |
8780 RETURN_SANS_WARNINGS position; \ | |
8781 } while (0) | |
8782 | |
8783 /* Given x and y coordinates in pixels relative to a frame, return | |
8784 information about what is located under those coordinates. | |
8785 | |
8786 The return value will be one of: | |
8787 | |
8788 OVER_TOOLBAR: over one of the 4 frame toolbars | |
8789 OVER_MODELINE: over a modeline | |
8790 OVER_BORDER: over an internal border | |
5090 | 8791 OVER_V_DIVIDER: over a vertical divider between windows (used as a |
8792 grab bar for resizing) | |
428 | 8793 OVER_NOTHING: over the text area, but not over text |
8794 OVER_OUTSIDE: outside of the frame border | |
8795 OVER_TEXT: over text in the text area | |
8796 | |
5090 | 8797 #### GEOM! We need to also have an OVER_GUTTER, OVER_SCROLLBAR and |
8798 OVER_DEAD_BOX. | |
8799 | |
428 | 8800 OBJ1 is one of |
8801 | |
8802 -- a toolbar button | |
8803 -- a glyph | |
8804 -- nil if the coordinates are not over a glyph or a toolbar button. | |
8805 | |
8806 OBJ2 is one of | |
8807 | |
8808 -- an extent, if the coordinates are over a glyph in the text area | |
8809 -- nil otherwise. | |
8810 | |
8811 If the coordinates are over a glyph, OBJ_X and OBJ_Y give the | |
8812 equivalent coordinates relative to the upper-left corner of the glyph. | |
8813 | |
8814 If the coordinates are over a character, OBJ_X and OBJ_Y give the | |
8815 equivalent coordinates relative to the upper-left corner of the character. | |
8816 | |
8817 Otherwise, OBJ_X and OBJ_Y are undefined. | |
8818 */ | |
8819 | |
8820 int | |
8821 pixel_to_glyph_translation (struct frame *f, int x_coord, int y_coord, | |
8822 int *col, int *row, int *obj_x, int *obj_y, | |
826 | 8823 struct window **w, Charbpos *charpos, |
665 | 8824 Charbpos *closest, Charcount *modeline_closest, |
428 | 8825 Lisp_Object *obj1, Lisp_Object *obj2) |
8826 { | |
8827 struct device *d; | |
8828 struct pixel_to_glyph_translation_cache *cache; | |
8829 Lisp_Object window; | |
8830 int frm_left, frm_right, frm_top, frm_bottom; | |
8831 int low_x_coord, high_x_coord, low_y_coord, high_y_coord; | |
8832 int position = OVER_NOTHING; | |
8833 int device_check_failed = 0; | |
8834 display_line_dynarr *dla; | |
8835 | |
8836 /* This is a safety valve in case this got called with a frame in | |
8837 the middle of being deleted. */ | |
8838 if (!DEVICEP (f->device) || !DEVICE_LIVE_P (XDEVICE (f->device))) | |
8839 { | |
8840 device_check_failed = 1; | |
8841 d = NULL, cache = NULL; /* Warning suppression */ | |
8842 } | |
8843 else | |
8844 { | |
8845 d = XDEVICE (f->device); | |
8846 cache = &d->pixel_to_glyph_cache; | |
8847 } | |
8848 | |
8849 if (!device_check_failed | |
8850 && cache->valid | |
8851 && cache->frame == f | |
8852 && cache->low_x_coord <= x_coord | |
8853 && cache->high_x_coord > x_coord | |
8854 && cache->low_y_coord <= y_coord | |
8855 && cache->high_y_coord > y_coord) | |
8856 { | |
8857 *col = cache->col; | |
8858 *row = cache->row; | |
8859 *obj_x = cache->obj_x; | |
8860 *obj_y = cache->obj_y; | |
8861 *w = cache->w; | |
826 | 8862 *charpos = cache->charpos; |
428 | 8863 *closest = cache->closest; |
8864 *modeline_closest = cache->modeline_closest; | |
8865 *obj1 = cache->obj1; | |
8866 *obj2 = cache->obj2; | |
8867 | |
8868 return cache->retval; | |
8869 } | |
8870 else | |
8871 { | |
8872 *col = 0; | |
8873 *row = 0; | |
8874 *obj_x = 0; | |
8875 *obj_y = 0; | |
8876 *w = 0; | |
826 | 8877 *charpos = 0; |
428 | 8878 *closest = 0; |
8879 *modeline_closest = -1; | |
8880 *obj1 = Qnil; | |
8881 *obj2 = Qnil; | |
8882 | |
8883 low_x_coord = x_coord; | |
8884 high_x_coord = x_coord + 1; | |
8885 low_y_coord = y_coord; | |
8886 high_y_coord = y_coord + 1; | |
8887 } | |
8888 | |
8889 if (device_check_failed) | |
8890 return OVER_NOTHING; | |
8891 | |
5090 | 8892 /* #### GEOM! The gutter is just inside of this. We should also have an |
8893 OVER_GUTTER return value to indicate that we're over a gutter. See | |
8894 above. */ | |
8895 frm_left = FRAME_LEFT_INTERNAL_BORDER_END (f); | |
8896 frm_right = FRAME_RIGHT_INTERNAL_BORDER_START (f); | |
8897 frm_top = FRAME_TOP_INTERNAL_BORDER_END (f); | |
8898 frm_bottom = FRAME_BOTTOM_INTERNAL_BORDER_START (f); | |
428 | 8899 |
8900 /* Check if the mouse is outside of the text area actually used by | |
8901 redisplay. */ | |
8902 if (y_coord < frm_top) | |
8903 { | |
5090 | 8904 if (y_coord >= FRAME_TOP_INTERNAL_BORDER_START (f)) |
8905 { | |
8906 low_y_coord = FRAME_TOP_INTERNAL_BORDER_START (f); | |
428 | 8907 high_y_coord = frm_top; |
8908 position = OVER_BORDER; | |
8909 } | |
8910 else if (y_coord >= 0) | |
8911 { | |
8912 low_y_coord = 0; | |
5090 | 8913 high_y_coord = FRAME_TOP_INTERNAL_BORDER_START (f); |
428 | 8914 position = OVER_TOOLBAR; |
8915 } | |
8916 else | |
8917 { | |
8918 low_y_coord = y_coord; | |
8919 high_y_coord = 0; | |
8920 position = OVER_OUTSIDE; | |
8921 } | |
8922 } | |
8923 else if (y_coord >= frm_bottom) | |
8924 { | |
5090 | 8925 if (y_coord < FRAME_BOTTOM_INTERNAL_BORDER_END (f)) |
428 | 8926 { |
8927 low_y_coord = frm_bottom; | |
5090 | 8928 high_y_coord = FRAME_BOTTOM_INTERNAL_BORDER_END (f); |
428 | 8929 position = OVER_BORDER; |
8930 } | |
8931 else if (y_coord < FRAME_PIXHEIGHT (f)) | |
8932 { | |
5090 | 8933 low_y_coord = FRAME_BOTTOM_INTERNAL_BORDER_END (f); |
428 | 8934 high_y_coord = FRAME_PIXHEIGHT (f); |
8935 position = OVER_TOOLBAR; | |
8936 } | |
8937 else | |
8938 { | |
8939 low_y_coord = FRAME_PIXHEIGHT (f); | |
8940 high_y_coord = y_coord; | |
8941 position = OVER_OUTSIDE; | |
8942 } | |
8943 } | |
8944 | |
8945 if (position != OVER_TOOLBAR && position != OVER_BORDER) | |
8946 { | |
8947 if (x_coord < frm_left) | |
8948 { | |
5090 | 8949 if (x_coord >= FRAME_LEFT_INTERNAL_BORDER_START (f)) |
8950 { | |
8951 low_x_coord = FRAME_LEFT_INTERNAL_BORDER_START (f); | |
428 | 8952 high_x_coord = frm_left; |
8953 position = OVER_BORDER; | |
8954 } | |
8955 else if (x_coord >= 0) | |
8956 { | |
8957 low_x_coord = 0; | |
5090 | 8958 high_x_coord = FRAME_LEFT_INTERNAL_BORDER_START (f); |
428 | 8959 position = OVER_TOOLBAR; |
8960 } | |
8961 else | |
8962 { | |
8963 low_x_coord = x_coord; | |
8964 high_x_coord = 0; | |
8965 position = OVER_OUTSIDE; | |
8966 } | |
8967 } | |
8968 else if (x_coord >= frm_right) | |
8969 { | |
5090 | 8970 if (x_coord < FRAME_RIGHT_INTERNAL_BORDER_END (f)) |
428 | 8971 { |
8972 low_x_coord = frm_right; | |
5090 | 8973 high_x_coord = FRAME_RIGHT_INTERNAL_BORDER_END (f); |
428 | 8974 position = OVER_BORDER; |
8975 } | |
8976 else if (x_coord < FRAME_PIXWIDTH (f)) | |
8977 { | |
5090 | 8978 low_x_coord = FRAME_RIGHT_INTERNAL_BORDER_END (f); |
428 | 8979 high_x_coord = FRAME_PIXWIDTH (f); |
8980 position = OVER_TOOLBAR; | |
8981 } | |
8982 else | |
8983 { | |
8984 low_x_coord = FRAME_PIXWIDTH (f); | |
8985 high_x_coord = x_coord; | |
8986 position = OVER_OUTSIDE; | |
8987 } | |
8988 } | |
8989 } | |
8990 | |
8991 #ifdef HAVE_TOOLBARS | |
8992 if (position == OVER_TOOLBAR) | |
8993 { | |
8994 *obj1 = toolbar_button_at_pixpos (f, x_coord, y_coord); | |
8995 *obj2 = Qnil; | |
8996 *w = 0; | |
8997 UPDATE_CACHE_RETURN; | |
8998 } | |
8999 #endif /* HAVE_TOOLBARS */ | |
9000 | |
9001 /* We still have to return the window the pointer is next to and its | |
9002 relative y position even if it is outside the x boundary. */ | |
9003 if (x_coord < frm_left) | |
9004 x_coord = frm_left; | |
9005 else if (x_coord > frm_right) | |
9006 x_coord = frm_right; | |
9007 | |
9008 /* Same in reverse. */ | |
9009 if (y_coord < frm_top) | |
9010 y_coord = frm_top; | |
9011 else if (y_coord > frm_bottom) | |
9012 y_coord = frm_bottom; | |
9013 | |
9014 /* Find what window the given coordinates are actually in. */ | |
9015 window = f->root_window; | |
9016 *w = find_window_by_pixel_pos (x_coord, y_coord, window); | |
9017 | |
9018 /* If we didn't find a window, we're done. */ | |
9019 if (!*w) | |
9020 { | |
9021 UPDATE_CACHE_RETURN; | |
9022 } | |
9023 else if (position != OVER_NOTHING) | |
9024 { | |
9025 *closest = 0; | |
9026 *modeline_closest = -1; | |
9027 | |
9028 if (high_y_coord <= frm_top || high_y_coord >= frm_bottom) | |
9029 { | |
9030 *w = 0; | |
9031 UPDATE_CACHE_RETURN; | |
9032 } | |
9033 } | |
9034 | |
9035 /* Check if the window is a minibuffer but isn't active. */ | |
9036 if (MINI_WINDOW_P (*w) && !minibuf_level) | |
9037 { | |
9038 /* Must reset the window value since some callers will ignore | |
4187 | 9039 the return value if it is set. */ |
428 | 9040 *w = 0; |
9041 UPDATE_CACHE_RETURN; | |
9042 } | |
9043 | |
9044 /* See if the point is over window vertical divider */ | |
9045 if (window_needs_vertical_divider (*w)) | |
9046 { | |
9047 int div_x_high = WINDOW_RIGHT (*w); | |
9048 int div_x_low = div_x_high - window_divider_width (*w); | |
9049 int div_y_high = WINDOW_BOTTOM (*w); | |
9050 int div_y_low = WINDOW_TOP (*w); | |
9051 | |
9052 if (div_x_low < x_coord && x_coord <= div_x_high && | |
9053 div_y_low < y_coord && y_coord <= div_y_high) | |
9054 { | |
9055 low_x_coord = div_x_low; | |
9056 high_x_coord = div_x_high; | |
9057 low_y_coord = div_y_low; | |
9058 high_y_coord = div_y_high; | |
9059 position = OVER_V_DIVIDER; | |
9060 UPDATE_CACHE_RETURN; | |
9061 } | |
9062 } | |
9063 | |
9064 dla = window_display_lines (*w, CURRENT_DISP); | |
9065 | |
9066 for (*row = 0; *row < Dynarr_length (dla); (*row)++) | |
9067 { | |
9068 int really_over_nothing = 0; | |
9069 struct display_line *dl = Dynarr_atp (dla, *row); | |
9070 | |
9071 if ((int) (dl->ypos - dl->ascent) <= y_coord | |
9072 && y_coord <= (int) (dl->ypos + dl->descent)) | |
9073 { | |
9074 int check_margin_glyphs = 0; | |
9075 struct display_block *db = get_display_block_from_line (dl, TEXT); | |
9076 struct rune *rb = 0; | |
9077 | |
9078 if (x_coord < dl->bounds.left_white | |
9079 || x_coord >= dl->bounds.right_white) | |
9080 check_margin_glyphs = 1; | |
9081 | |
9082 low_y_coord = dl->ypos - dl->ascent; | |
9083 high_y_coord = dl->ypos + dl->descent + 1; | |
9084 | |
9085 if (position == OVER_BORDER | |
9086 || position == OVER_OUTSIDE | |
9087 || check_margin_glyphs) | |
9088 { | |
9089 int x_check, left_bound; | |
9090 | |
9091 if (check_margin_glyphs) | |
9092 { | |
9093 x_check = x_coord; | |
9094 left_bound = dl->bounds.left_white; | |
9095 } | |
9096 else | |
9097 { | |
9098 x_check = high_x_coord; | |
9099 left_bound = frm_left; | |
9100 } | |
9101 | |
9102 if (Dynarr_length (db->runes)) | |
9103 { | |
9104 if (x_check <= left_bound) | |
9105 { | |
9106 if (dl->modeline) | |
4967 | 9107 *modeline_closest = Dynarr_begin (db->runes)->charpos; |
428 | 9108 else |
4967 | 9109 *closest = Dynarr_begin (db->runes)->charpos; |
428 | 9110 } |
9111 else | |
9112 { | |
9113 if (dl->modeline) | |
4844
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4815
diff
changeset
|
9114 *modeline_closest = Dynarr_lastp (db->runes)->charpos; |
428 | 9115 else |
4844
91b3d00e717f
Various cleanups for Dynarr code, from Unicode-internal ws
Ben Wing <ben@xemacs.org>
parents:
4815
diff
changeset
|
9116 *closest = Dynarr_lastp (db->runes)->charpos; |
428 | 9117 } |
9118 | |
9119 if (dl->modeline) | |
9120 *modeline_closest += dl->offset; | |
9121 else | |
9122 *closest += dl->offset; | |
9123 } | |
9124 else | |
9125 { | |
9126 /* #### What should be here. */ | |
9127 if (dl->modeline) | |
9128 *modeline_closest = 0; | |
9129 else | |
9130 *closest = 0; | |
9131 } | |
9132 | |
9133 if (check_margin_glyphs) | |
9134 { | |
9135 if (x_coord < dl->bounds.left_in | |
9136 || x_coord >= dl->bounds.right_in) | |
9137 { | |
9138 /* If we are over the outside margins then we | |
4187 | 9139 know the loop over the text block isn't going |
9140 to accomplish anything. So we go ahead and | |
9141 set what information we can right here and | |
9142 return. */ | |
428 | 9143 (*row)--; |
9144 *obj_y = y_coord - (dl->ypos - dl->ascent); | |
9145 get_position_object (dl, obj1, obj2, x_coord, | |
9146 &low_x_coord, &high_x_coord); | |
9147 | |
9148 UPDATE_CACHE_RETURN; | |
9149 } | |
9150 } | |
9151 else | |
9152 UPDATE_CACHE_RETURN; | |
9153 } | |
9154 | |
9155 for (*col = 0; *col <= Dynarr_length (db->runes); (*col)++) | |
9156 { | |
9157 int past_end = (*col == Dynarr_length (db->runes)); | |
9158 | |
9159 if (!past_end) | |
9160 rb = Dynarr_atp (db->runes, *col); | |
9161 | |
9162 if (past_end || | |
9163 (rb->xpos <= x_coord && x_coord < rb->xpos + rb->width)) | |
9164 { | |
9165 if (past_end) | |
9166 { | |
9167 (*col)--; | |
9168 rb = Dynarr_atp (db->runes, *col); | |
9169 } | |
9170 | |
826 | 9171 *charpos = rb->charpos + dl->offset; |
428 | 9172 low_x_coord = rb->xpos; |
9173 high_x_coord = rb->xpos + rb->width; | |
9174 | |
9175 if (rb->type == RUNE_DGLYPH) | |
9176 { | |
9177 int elt = *col + 1; | |
9178 | |
9179 /* Find the first character after the glyph. */ | |
9180 while (elt < Dynarr_length (db->runes)) | |
9181 { | |
9182 if (Dynarr_atp (db->runes, elt)->type != RUNE_DGLYPH) | |
9183 { | |
9184 if (dl->modeline) | |
9185 *modeline_closest = | |
826 | 9186 (Dynarr_atp (db->runes, elt)->charpos + |
428 | 9187 dl->offset); |
9188 else | |
9189 *closest = | |
826 | 9190 (Dynarr_atp (db->runes, elt)->charpos + |
428 | 9191 dl->offset); |
9192 break; | |
9193 } | |
9194 | |
9195 elt++; | |
9196 } | |
9197 | |
9198 /* In this case we failed to find a non-glyph | |
4187 | 9199 character so we return the last position |
9200 displayed on the line. */ | |
428 | 9201 if (elt == Dynarr_length (db->runes)) |
9202 { | |
9203 if (dl->modeline) | |
826 | 9204 *modeline_closest = dl->end_charpos + dl->offset; |
428 | 9205 else |
826 | 9206 *closest = dl->end_charpos + dl->offset; |
428 | 9207 really_over_nothing = 1; |
9208 } | |
9209 } | |
9210 else | |
9211 { | |
9212 if (dl->modeline) | |
826 | 9213 *modeline_closest = rb->charpos + dl->offset; |
428 | 9214 else |
826 | 9215 *closest = rb->charpos + dl->offset; |
428 | 9216 } |
9217 | |
9218 if (dl->modeline) | |
9219 { | |
9220 *row = window_displayed_height (*w); | |
9221 | |
9222 if (position == OVER_NOTHING) | |
9223 position = OVER_MODELINE; | |
9224 | |
9225 if (rb->type == RUNE_DGLYPH) | |
9226 { | |
9227 *obj1 = rb->object.dglyph.glyph; | |
9228 *obj2 = rb->object.dglyph.extent; | |
9229 } | |
9230 else if (rb->type == RUNE_CHAR) | |
9231 { | |
9232 *obj1 = Qnil; | |
9233 *obj2 = Qnil; | |
9234 } | |
9235 else | |
9236 { | |
9237 *obj1 = Qnil; | |
9238 *obj2 = Qnil; | |
9239 } | |
9240 | |
9241 UPDATE_CACHE_RETURN; | |
9242 } | |
9243 else if (past_end | |
9244 || (rb->type == RUNE_CHAR | |
9245 && rb->object.chr.ch == '\n')) | |
9246 { | |
9247 (*row)--; | |
9248 /* At this point we may have glyphs in the right | |
4187 | 9249 inside margin. */ |
428 | 9250 if (check_margin_glyphs) |
9251 get_position_object (dl, obj1, obj2, x_coord, | |
9252 &low_x_coord, &high_x_coord); | |
9253 UPDATE_CACHE_RETURN; | |
9254 } | |
9255 else | |
9256 { | |
9257 (*row)--; | |
9258 if (rb->type == RUNE_DGLYPH) | |
9259 { | |
9260 *obj1 = rb->object.dglyph.glyph; | |
9261 *obj2 = rb->object.dglyph.extent; | |
9262 } | |
9263 else if (rb->type == RUNE_CHAR) | |
9264 { | |
9265 *obj1 = Qnil; | |
9266 *obj2 = Qnil; | |
9267 } | |
9268 else | |
9269 { | |
9270 *obj1 = Qnil; | |
9271 *obj2 = Qnil; | |
9272 } | |
9273 | |
9274 *obj_x = x_coord - rb->xpos; | |
9275 *obj_y = y_coord - (dl->ypos - dl->ascent); | |
9276 | |
9277 /* At this point we may have glyphs in the left | |
4187 | 9278 inside margin. */ |
428 | 9279 if (check_margin_glyphs) |
9280 get_position_object (dl, obj1, obj2, x_coord, 0, 0); | |
9281 | |
9282 if (position == OVER_NOTHING && !really_over_nothing) | |
9283 position = OVER_TEXT; | |
9284 | |
9285 UPDATE_CACHE_RETURN; | |
9286 } | |
9287 } | |
9288 } | |
9289 } | |
9290 } | |
9291 | |
9292 *row = Dynarr_length (dla) - 1; | |
9293 if (FRAME_WIN_P (f)) | |
9294 { | |
9295 int bot_elt = Dynarr_length (dla) - 1; | |
9296 | |
9297 if (bot_elt >= 0) | |
9298 { | |
9299 struct display_line *dl = Dynarr_atp (dla, bot_elt); | |
9300 int adj_area = y_coord - (dl->ypos + dl->descent); | |
9301 Lisp_Object lwin; | |
9302 int defheight; | |
9303 | |
793 | 9304 lwin = wrap_window (*w); |
5047
07dcc7000bbf
put width before height consistently, fix a real bug found in the process
Ben Wing <ben@xemacs.org>
parents:
5043
diff
changeset
|
9305 default_face_width_and_height (lwin, 0, &defheight); |
428 | 9306 |
9307 *row += (adj_area / defheight); | |
9308 } | |
9309 } | |
9310 | |
9311 /* #### This should be checked out some more to determine what | |
9312 should really be going on. */ | |
9313 if (!MARKERP ((*w)->start[CURRENT_DISP])) | |
9314 *closest = 0; | |
9315 else | |
442 | 9316 *closest = end_of_last_line_may_error (*w, |
428 | 9317 marker_position ((*w)->start[CURRENT_DISP])); |
9318 *col = 0; | |
9319 UPDATE_CACHE_RETURN; | |
9320 } | |
9321 #undef UPDATE_CACHE_RETURN | |
9322 | |
9323 | |
9324 /***************************************************************************/ | |
9325 /* */ | |
9326 /* Lisp functions */ | |
9327 /* */ | |
9328 /***************************************************************************/ | |
9329 | |
9330 DEFUN ("redisplay-echo-area", Fredisplay_echo_area, 0, 0, 0, /* | |
9331 Ensure that all minibuffers are correctly showing the echo area. | |
9332 */ | |
9333 ()) | |
9334 { | |
9335 Lisp_Object devcons, concons; | |
9336 | |
1318 | 9337 if (in_display) |
9338 return Qnil; | |
9339 | |
428 | 9340 DEVICE_LOOP_NO_BREAK (devcons, concons) |
9341 { | |
9342 struct device *d = XDEVICE (XCAR (devcons)); | |
9343 Lisp_Object frmcons; | |
9344 | |
1279 | 9345 if (DEVICE_STREAM_P (d)) |
9346 continue; | |
9347 | |
428 | 9348 DEVICE_FRAME_LOOP (frmcons, d) |
9349 { | |
9350 struct frame *f = XFRAME (XCAR (frmcons)); | |
853 | 9351 int depth; |
428 | 9352 |
9353 if (FRAME_REPAINT_P (f) && FRAME_HAS_MINIBUF_P (f)) | |
9354 { | |
9355 Lisp_Object window = FRAME_MINIBUF_WINDOW (f); | |
442 | 9356 |
9357 MAYBE_DEVMETH (d, frame_output_begin, (f)); | |
9358 | |
428 | 9359 /* |
9360 * If the frame size has changed, there may be random | |
9361 * chud on the screen left from previous messages | |
9362 * because redisplay_frame hasn't been called yet. | |
9363 * Clear the screen to get rid of the potential mess. | |
9364 */ | |
9365 if (f->echo_area_garbaged) | |
9366 { | |
442 | 9367 MAYBE_DEVMETH (d, clear_frame, (f)); |
428 | 9368 f->echo_area_garbaged = 0; |
9369 } | |
853 | 9370 depth = enter_redisplay_critical_section (); |
428 | 9371 redisplay_window (window, 0); |
853 | 9372 exit_redisplay_critical_section (depth); |
442 | 9373 MAYBE_DEVMETH (d, frame_output_end, (f)); |
428 | 9374 } |
9375 } | |
9376 } | |
9377 | |
9378 return Qnil; | |
9379 } | |
9380 | |
9381 DEFUN ("redraw-frame", Fredraw_frame, 0, 2, 0, /* | |
9382 Clear frame FRAME and output again what is supposed to appear on it. | |
9383 FRAME defaults to the selected frame if omitted. | |
9384 Normally, redisplay is preempted as normal if input arrives. However, | |
9385 if optional second arg NO-PREEMPT is non-nil, redisplay will not stop for | |
9386 input and is guaranteed to proceed to completion. | |
9387 */ | |
9388 (frame, no_preempt)) | |
9389 { | |
9390 struct frame *f = decode_frame (frame); | |
9391 int count = specpdl_depth (); | |
9392 | |
9393 if (!NILP (no_preempt)) | |
853 | 9394 internal_bind_int (&disable_preemption, 1 + disable_preemption); |
428 | 9395 |
9396 f->clear = 1; | |
9397 redisplay_frame (f, 1); | |
9398 | |
442 | 9399 /* See the comment in Fredisplay_frame. */ |
9400 RESET_CHANGED_SET_FLAGS; | |
9401 | |
771 | 9402 return unbind_to (count); |
428 | 9403 } |
9404 | |
9405 DEFUN ("redisplay-frame", Fredisplay_frame, 0, 2, 0, /* | |
9406 Ensure that FRAME's contents are correctly displayed. | |
9407 This differs from `redraw-frame' in that it only redraws what needs to | |
9408 be updated, as opposed to unconditionally clearing and redrawing | |
9409 the frame. | |
9410 FRAME defaults to the selected frame if omitted. | |
9411 Normally, redisplay is preempted as normal if input arrives. However, | |
9412 if optional second arg NO-PREEMPT is non-nil, redisplay will not stop for | |
9413 input and is guaranteed to proceed to completion. | |
9414 */ | |
9415 (frame, no_preempt)) | |
9416 { | |
9417 struct frame *f = decode_frame (frame); | |
9418 int count = specpdl_depth (); | |
9419 | |
9420 if (!NILP (no_preempt)) | |
853 | 9421 internal_bind_int (&disable_preemption, 1 + disable_preemption); |
428 | 9422 |
9423 redisplay_frame (f, 1); | |
9424 | |
442 | 9425 /* If we don't reset the global redisplay flags here, subsequent |
9426 changes to the display will not get registered by redisplay | |
9427 because it thinks it already has registered changes. If you | |
9428 really knew what you were doing you could confuse redisplay by | |
9429 calling Fredisplay_frame while updating another frame. We assume | |
9430 that if you know what you are doing you will not be that | |
9431 stupid. */ | |
9432 RESET_CHANGED_SET_FLAGS; | |
9433 | |
771 | 9434 return unbind_to (count); |
428 | 9435 } |
9436 | |
9437 DEFUN ("redraw-device", Fredraw_device, 0, 2, 0, /* | |
9438 Clear device DEVICE and output again what is supposed to appear on it. | |
9439 DEVICE defaults to the selected device if omitted. | |
9440 Normally, redisplay is preempted as normal if input arrives. However, | |
9441 if optional second arg NO-PREEMPT is non-nil, redisplay will not stop for | |
9442 input and is guaranteed to proceed to completion. | |
9443 */ | |
9444 (device, no_preempt)) | |
9445 { | |
9446 struct device *d = decode_device (device); | |
9447 Lisp_Object frmcons; | |
9448 int count = specpdl_depth (); | |
9449 | |
9450 if (!NILP (no_preempt)) | |
853 | 9451 internal_bind_int (&disable_preemption, 1 + disable_preemption); |
428 | 9452 |
9453 DEVICE_FRAME_LOOP (frmcons, d) | |
9454 { | |
9455 XFRAME (XCAR (frmcons))->clear = 1; | |
9456 } | |
440 | 9457 redisplay_device (d, 0); |
428 | 9458 |
442 | 9459 /* See the comment in Fredisplay_frame. */ |
9460 RESET_CHANGED_SET_FLAGS; | |
9461 | |
771 | 9462 return unbind_to (count); |
428 | 9463 } |
9464 | |
9465 DEFUN ("redisplay-device", Fredisplay_device, 0, 2, 0, /* | |
9466 Ensure that DEVICE's contents are correctly displayed. | |
9467 This differs from `redraw-device' in that it only redraws what needs to | |
9468 be updated, as opposed to unconditionally clearing and redrawing | |
9469 the device. | |
9470 DEVICE defaults to the selected device if omitted. | |
9471 Normally, redisplay is preempted as normal if input arrives. However, | |
9472 if optional second arg NO-PREEMPT is non-nil, redisplay will not stop for | |
9473 input and is guaranteed to proceed to completion. | |
853 | 9474 |
9475 Note: If you simply want everything redisplayed, the current idiom is | |
9476 `(sit-for 0)'. | |
428 | 9477 */ |
9478 (device, no_preempt)) | |
9479 { | |
9480 struct device *d = decode_device (device); | |
9481 int count = specpdl_depth (); | |
9482 | |
9483 if (!NILP (no_preempt)) | |
853 | 9484 internal_bind_int (&disable_preemption, 1 + disable_preemption); |
428 | 9485 |
440 | 9486 redisplay_device (d, 0); |
428 | 9487 |
442 | 9488 /* See the comment in Fredisplay_frame. */ |
9489 RESET_CHANGED_SET_FLAGS; | |
9490 | |
771 | 9491 return unbind_to (count); |
428 | 9492 } |
9493 | |
9494 /* Big lie. Big lie. This will force all modelines to be updated | |
9495 regardless if the all flag is set or not. It remains in existence | |
9496 solely for backwards compatibility. */ | |
9497 DEFUN ("redraw-modeline", Fredraw_modeline, 0, 1, 0, /* | |
9498 Force the modeline of the current buffer to be redisplayed. | |
9499 With optional non-nil ALL, force redisplay of all modelines. | |
9500 */ | |
2286 | 9501 (UNUSED (all))) |
428 | 9502 { |
9503 MARK_MODELINE_CHANGED; | |
9504 return Qnil; | |
9505 } | |
9506 | |
9507 DEFUN ("force-cursor-redisplay", Fforce_cursor_redisplay, 0, 1, 0, /* | |
9508 Force an immediate update of the cursor on FRAME. | |
9509 FRAME defaults to the selected frame if omitted. | |
9510 */ | |
9511 (frame)) | |
9512 { | |
1279 | 9513 struct frame *f = decode_frame (frame); |
9514 | |
9515 if (!FRAME_STREAM_P (f)) | |
9516 redisplay_redraw_cursor (f, 1); | |
428 | 9517 return Qnil; |
9518 } | |
9519 | |
9520 | |
9521 /***************************************************************************/ | |
9522 /* */ | |
872 | 9523 /* Change flags */ |
428 | 9524 /* */ |
9525 /***************************************************************************/ | |
9526 | |
9527 static void | |
2286 | 9528 margin_width_changed_in_frame (Lisp_Object UNUSED (specifier), |
9529 struct frame *UNUSED (f), | |
9530 Lisp_Object UNUSED (oldval)) | |
428 | 9531 { |
9532 /* Nothing to be done? */ | |
9533 } | |
9534 | |
9535 int | |
2286 | 9536 redisplay_variable_changed (Lisp_Object UNUSED (sym), |
9537 Lisp_Object *UNUSED (val), | |
9538 Lisp_Object UNUSED (in_object), | |
9539 int UNUSED (flags)) | |
428 | 9540 { |
9541 /* #### clip_changed should really be renamed something like | |
9542 global_redisplay_change. */ | |
9543 MARK_CLIP_CHANGED; | |
9544 return 0; | |
9545 } | |
9546 | |
9547 /* This is called if the built-in glyphs have their properties | |
9548 changed. */ | |
9549 void | |
2286 | 9550 redisplay_glyph_changed (Lisp_Object UNUSED (glyph), |
9551 Lisp_Object UNUSED (property), Lisp_Object locale) | |
428 | 9552 { |
9553 if (WINDOWP (locale)) | |
9554 { | |
9555 MARK_FRAME_GLYPHS_CHANGED (XFRAME (WINDOW_FRAME (XWINDOW (locale)))); | |
9556 } | |
9557 else if (FRAMEP (locale)) | |
9558 { | |
9559 MARK_FRAME_GLYPHS_CHANGED (XFRAME (locale)); | |
9560 } | |
9561 else if (DEVICEP (locale)) | |
9562 { | |
9563 Lisp_Object frmcons; | |
9564 DEVICE_FRAME_LOOP (frmcons, XDEVICE (locale)) | |
9565 MARK_FRAME_GLYPHS_CHANGED (XFRAME (XCAR (frmcons))); | |
9566 } | |
9567 else if (CONSOLEP (locale)) | |
9568 { | |
9569 Lisp_Object frmcons, devcons; | |
9570 CONSOLE_FRAME_LOOP_NO_BREAK (frmcons, devcons, XCONSOLE (locale)) | |
9571 MARK_FRAME_GLYPHS_CHANGED (XFRAME (XCAR (frmcons))); | |
9572 } | |
9573 else /* global or buffer */ | |
9574 { | |
9575 Lisp_Object frmcons, devcons, concons; | |
9576 FRAME_LOOP_NO_BREAK (frmcons, devcons, concons) | |
9577 MARK_FRAME_GLYPHS_CHANGED (XFRAME (XCAR (frmcons))); | |
9578 } | |
9579 } | |
9580 | |
9581 static void | |
2286 | 9582 text_cursor_visible_p_changed (Lisp_Object UNUSED (specifier), |
9583 struct window *w, Lisp_Object UNUSED (oldval)) | |
428 | 9584 { |
9585 if (XFRAME (w->frame)->init_finished) | |
9586 Fforce_cursor_redisplay (w->frame); | |
9587 } | |
9588 | |
872 | 9589 void |
9590 mark_buffers_changed (void) | |
9591 { | |
9592 MARK_TYPE_CHANGED (buffers); | |
9593 } | |
9594 | |
9595 void | |
9596 mark_clip_changed (void) | |
9597 { | |
9598 MARK_TYPE_CHANGED (clip); | |
9599 } | |
9600 | |
9601 void | |
9602 mark_extents_changed (void) | |
9603 { | |
9604 MARK_TYPE_CHANGED (extents); | |
9605 } | |
9606 | |
9607 void | |
9608 mark_icon_changed (void) | |
9609 { | |
9610 MARK_TYPE_CHANGED (icon); | |
9611 } | |
9612 | |
9613 void | |
9614 mark_menubar_changed (void) | |
9615 { | |
9616 MARK_TYPE_CHANGED (menubar); | |
9617 } | |
9618 | |
9619 void | |
9620 mark_modeline_changed (void) | |
9621 { | |
9622 MARK_TYPE_CHANGED (modeline); | |
9623 } | |
9624 | |
9625 void | |
9626 mark_point_changed (void) | |
9627 { | |
9628 MARK_TYPE_CHANGED (point); | |
9629 } | |
9630 | |
9631 void | |
9632 mark_toolbar_changed (void) | |
9633 { | |
9634 MARK_TYPE_CHANGED (toolbar); | |
9635 } | |
9636 | |
9637 void | |
9638 mark_gutter_changed (void) | |
9639 { | |
9640 MARK_TYPE_CHANGED (gutter); | |
9641 } | |
9642 | |
9643 void | |
9644 mark_glyphs_changed (void) | |
9645 { | |
9646 MARK_TYPE_CHANGED (glyphs); | |
9647 } | |
9648 | |
9649 void | |
9650 mark_subwindows_changed (void) | |
9651 { | |
9652 MARK_TYPE_CHANGED (subwindows); | |
9653 } | |
9654 | |
9655 void | |
9656 mark_subwindows_state_changed (void) | |
9657 { | |
9658 MARK_TYPE_CHANGED (subwindows_state); | |
9659 } | |
9660 | |
428 | 9661 #ifdef MEMORY_USAGE_STATS |
9662 | |
9663 | |
9664 /***************************************************************************/ | |
9665 /* */ | |
9666 /* memory usage computation */ | |
9667 /* */ | |
9668 /***************************************************************************/ | |
9669 | |
9670 static int | |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5090
diff
changeset
|
9671 compute_rune_dynarr_usage (rune_dynarr *dyn, struct usage_stats *ustats) |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5090
diff
changeset
|
9672 { |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5090
diff
changeset
|
9673 return dyn ? Dynarr_memory_usage (dyn, ustats) : 0; |
428 | 9674 } |
9675 | |
9676 static int | |
9677 compute_display_block_dynarr_usage (display_block_dynarr *dyn, | |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5090
diff
changeset
|
9678 struct usage_stats *ustats) |
428 | 9679 { |
9680 int total, i; | |
9681 | |
9682 if (!dyn) | |
9683 return 0; | |
9684 | |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5090
diff
changeset
|
9685 total = Dynarr_memory_usage (dyn, ustats); |
428 | 9686 for (i = 0; i < Dynarr_largest (dyn); i++) |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5090
diff
changeset
|
9687 total += compute_rune_dynarr_usage (Dynarr_at (dyn, i).runes, ustats); |
428 | 9688 |
9689 return total; | |
9690 } | |
9691 | |
9692 static int | |
9693 compute_glyph_block_dynarr_usage (glyph_block_dynarr *dyn, | |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5090
diff
changeset
|
9694 struct usage_stats *ustats) |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5090
diff
changeset
|
9695 { |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5090
diff
changeset
|
9696 return dyn ? Dynarr_memory_usage (dyn, ustats) : 0; |
428 | 9697 } |
9698 | |
9699 int | |
9700 compute_display_line_dynarr_usage (display_line_dynarr *dyn, | |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5090
diff
changeset
|
9701 struct usage_stats *ustats) |
428 | 9702 { |
9703 int total, i; | |
9704 | |
9705 if (!dyn) | |
9706 return 0; | |
9707 | |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5090
diff
changeset
|
9708 total = Dynarr_memory_usage (dyn, ustats); |
428 | 9709 for (i = 0; i < Dynarr_largest (dyn); i++) |
9710 { | |
9711 struct display_line *dl = &Dynarr_at (dyn, i); | |
5198 | 9712 total += compute_display_block_dynarr_usage (dl->display_blocks, ustats); |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5090
diff
changeset
|
9713 total += compute_glyph_block_dynarr_usage (dl->left_glyphs, ustats); |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5090
diff
changeset
|
9714 total += compute_glyph_block_dynarr_usage (dl->right_glyphs, ustats); |
428 | 9715 } |
9716 | |
9717 return total; | |
9718 } | |
9719 | |
9720 int | |
9721 compute_line_start_cache_dynarr_usage (line_start_cache_dynarr *dyn, | |
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5090
diff
changeset
|
9722 struct usage_stats *ustats) |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5090
diff
changeset
|
9723 { |
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
5090
diff
changeset
|
9724 return dyn ? Dynarr_memory_usage (dyn, ustats) : 0; |
428 | 9725 } |
9726 | |
9727 #endif /* MEMORY_USAGE_STATS */ | |
9728 | |
1204 | 9729 #ifdef ERROR_CHECK_DISPLAY |
9730 | |
800 | 9731 static int |
2286 | 9732 sledgehammer_check_redisplay_structs_1 (struct window *w, |
9733 void *UNUSED (closure)) | |
800 | 9734 { |
9735 int i, j; | |
9736 display_line_dynarr *dl; | |
9737 | |
9738 dl = window_display_lines (w, CURRENT_DISP); | |
4187 | 9739 |
800 | 9740 for (i = 0; i < Dynarr_largest (dl); i++) |
9741 for (j = i + 1; j < Dynarr_largest (dl); j++) | |
9742 assert (Dynarr_atp (dl, i)->display_blocks != | |
9743 Dynarr_atp (dl, j)->display_blocks); | |
9744 | |
9745 dl = window_display_lines (w, DESIRED_DISP); | |
9746 | |
9747 for (i = 0; i < Dynarr_largest (dl); i++) | |
9748 for (j = i + 1; j < Dynarr_largest (dl); j++) | |
9749 assert (Dynarr_atp (dl, i)->display_blocks != | |
9750 Dynarr_atp (dl, j)->display_blocks); | |
9751 | |
9752 return 0; | |
9753 } | |
9754 | |
9755 static void | |
9756 sledgehammer_check_redisplay_structs (void) | |
9757 { | |
9758 map_windows (0, sledgehammer_check_redisplay_structs_1, NULL); | |
9759 } | |
9760 | |
1204 | 9761 #endif /* ERROR_CHECK_DISPLAY */ |
9762 | |
428 | 9763 |
9764 /***************************************************************************/ | |
9765 /* */ | |
9766 /* initialization */ | |
9767 /* */ | |
9768 /***************************************************************************/ | |
9769 | |
9770 void | |
9771 init_redisplay (void) | |
9772 { | |
9773 disable_preemption = 0; | |
9774 preemption_count = 0; | |
9775 | |
9776 #ifndef PDUMP | |
9777 if (!initialized) | |
9778 #endif | |
9779 { | |
440 | 9780 if (!cmotion_display_lines) |
9781 cmotion_display_lines = Dynarr_new (display_line); | |
867 | 9782 if (!mode_spec_ibyte_string) |
9783 mode_spec_ibyte_string = Dynarr_new (Ibyte); | |
440 | 9784 if (!formatted_string_extent_dynarr) |
9785 formatted_string_extent_dynarr = Dynarr_new (EXTENT); | |
9786 if (!formatted_string_extent_start_dynarr) | |
9787 formatted_string_extent_start_dynarr = Dynarr_new (Bytecount); | |
9788 if (!formatted_string_extent_end_dynarr) | |
9789 formatted_string_extent_end_dynarr = Dynarr_new (Bytecount); | |
9790 if (!internal_cache) | |
9791 internal_cache = Dynarr_new (line_start_cache); | |
428 | 9792 } |
9793 | |
4477
e34711681f30
Don't determine whether to call general device-type code at startup,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4418
diff
changeset
|
9794 if (!initialized) |
428 | 9795 return; |
9796 | |
4477
e34711681f30
Don't determine whether to call general device-type code at startup,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4418
diff
changeset
|
9797 if (noninteractive) |
e34711681f30
Don't determine whether to call general device-type code at startup,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4418
diff
changeset
|
9798 { |
e34711681f30
Don't determine whether to call general device-type code at startup,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4418
diff
changeset
|
9799 Vinitial_device_type = Qstream; |
e34711681f30
Don't determine whether to call general device-type code at startup,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4418
diff
changeset
|
9800 return; |
e34711681f30
Don't determine whether to call general device-type code at startup,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4418
diff
changeset
|
9801 } |
e34711681f30
Don't determine whether to call general device-type code at startup,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4418
diff
changeset
|
9802 |
428 | 9803 /* If the user wants to use a window system, we shouldn't bother |
9804 initializing the terminal. This is especially important when the | |
9805 terminal is so dumb that emacs gives up before and doesn't bother | |
9806 using the window system. | |
9807 | |
9808 If the DISPLAY environment variable is set, try to use X, and die | |
9809 with an error message if that doesn't work. */ | |
9810 | |
9811 #ifdef HAVE_X_WINDOWS | |
9812 if (!strcmp (display_use, "x")) | |
9813 { | |
9814 /* Some stuff checks this way early. */ | |
9815 Vwindow_system = Qx; | |
4477
e34711681f30
Don't determine whether to call general device-type code at startup,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4418
diff
changeset
|
9816 Vinitial_device_type = Qx; |
428 | 9817 return; |
9818 } | |
9819 #endif /* HAVE_X_WINDOWS */ | |
9820 | |
462 | 9821 #ifdef HAVE_GTK |
9822 if (!strcmp (display_use, "gtk")) | |
9823 { | |
9824 Vwindow_system = Qgtk; | |
4477
e34711681f30
Don't determine whether to call general device-type code at startup,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4418
diff
changeset
|
9825 Vinitial_device_type = Qgtk; |
462 | 9826 return; |
9827 } | |
9828 #endif | |
9829 | |
428 | 9830 #ifdef HAVE_MS_WINDOWS |
9831 if (!strcmp (display_use, "mswindows")) | |
9832 { | |
9833 /* Some stuff checks this way early. */ | |
9834 Vwindow_system = Qmswindows; | |
4477
e34711681f30
Don't determine whether to call general device-type code at startup,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4418
diff
changeset
|
9835 Vinitial_device_type = Qmswindows; |
428 | 9836 return; |
9837 } | |
9838 #endif /* HAVE_MS_WINDOWS */ | |
9839 | |
9840 #ifdef HAVE_TTY | |
9841 /* If no window system has been specified, try to use the terminal. */ | |
9842 if (!isatty (0)) | |
9843 { | |
9844 stderr_out ("XEmacs: standard input is not a tty\n"); | |
9845 exit (1); | |
9846 } | |
9847 | |
9848 /* Look at the TERM variable */ | |
771 | 9849 if (!egetenv ("TERM")) |
428 | 9850 { |
9851 stderr_out ("Please set the environment variable TERM; see tset(1).\n"); | |
9852 exit (1); | |
9853 } | |
9854 | |
4477
e34711681f30
Don't determine whether to call general device-type code at startup,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4418
diff
changeset
|
9855 Vinitial_device_type = Qtty; |
428 | 9856 return; |
9857 #else /* not HAVE_TTY */ | |
9858 /* No DISPLAY specified, and no TTY support. */ | |
9859 stderr_out ("XEmacs: Cannot open display.\n\ | |
9860 Please set the environmental variable DISPLAY to an appropriate value.\n"); | |
9861 exit (1); | |
9862 #endif | |
9863 /* Unreached. */ | |
9864 } | |
9865 | |
9866 void | |
9867 syms_of_redisplay (void) | |
9868 { | |
563 | 9869 DEFSYMBOL (Qcursor_in_echo_area); |
9870 DEFSYMBOL (Qdisplay_warning_buffer); | |
9871 DEFSYMBOL (Qbar_cursor); | |
9872 DEFSYMBOL (Qtop_bottom); | |
9873 DEFSYMBOL (Qbuffer_list_changed_hook); | |
428 | 9874 |
9875 DEFSUBR (Fredisplay_echo_area); | |
9876 DEFSUBR (Fredraw_frame); | |
9877 DEFSUBR (Fredisplay_frame); | |
9878 DEFSUBR (Fredraw_device); | |
9879 DEFSUBR (Fredisplay_device); | |
9880 DEFSUBR (Fredraw_modeline); | |
9881 DEFSUBR (Fforce_cursor_redisplay); | |
9882 } | |
9883 | |
9884 void | |
9885 vars_of_redisplay (void) | |
9886 { | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4928
diff
changeset
|
9887 QSin_redisplay = build_defer_string ("(in redisplay)"); |
1292 | 9888 staticpro (&QSin_redisplay); |
428 | 9889 |
1318 | 9890 Vpost_redisplay_actions = Qnil; |
9891 staticpro (&Vpost_redisplay_actions); | |
9892 | |
428 | 9893 #if 0 |
9894 staticpro (&last_arrow_position); | |
9895 staticpro (&last_arrow_string); | |
9896 last_arrow_position = Qnil; | |
9897 last_arrow_string = Qnil; | |
9898 #endif /* 0 */ | |
9899 | |
9900 /* #### Probably temporary */ | |
9901 DEFVAR_INT ("redisplay-cache-adjustment", &cache_adjustment /* | |
9902 \(Temporary) Setting this will impact the performance of the internal | |
9903 line start cache. | |
9904 */ ); | |
9905 cache_adjustment = 2; | |
9906 | |
1268 | 9907 DEFVAR_INT ("maximum-preempts", &max_preempts /* |
9908 Maximum number of times redisplay can be preempted by user input. | |
9909 */ ); | |
9910 max_preempts = INIT_MAX_PREEMPTS; | |
9911 | |
428 | 9912 DEFVAR_INT_MAGIC ("pixel-vertical-clip-threshold", &vertical_clip /* |
9913 Minimum pixel height for clipped bottom display line. | |
9914 A clipped line shorter than this won't be displayed. | |
9915 */ , | |
9916 redisplay_variable_changed); | |
9917 vertical_clip = 5; | |
9918 | |
9919 DEFVAR_INT_MAGIC ("pixel-horizontal-clip-threshold", &horizontal_clip /* | |
9920 Minimum visible area for clipped glyphs at right boundary. | |
9921 Clipped glyphs shorter than this won't be displayed. | |
9922 Only pixmap glyph instances are currently allowed to be clipped. | |
9923 */ , | |
9924 redisplay_variable_changed); | |
9925 horizontal_clip = 5; | |
9926 | |
9927 DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string /* | |
9928 String displayed by modeline-format's "%m" specification. | |
9929 */ ); | |
9930 Vglobal_mode_string = Qnil; | |
9931 | |
9932 DEFVAR_LISP_MAGIC ("overlay-arrow-position", &Voverlay_arrow_position /* | |
9933 Marker for where to display an arrow on top of the buffer text. | |
9934 This must be the beginning of a line in order to work. | |
9935 See also `overlay-arrow-string'. | |
9936 */ , | |
9937 redisplay_variable_changed); | |
9938 Voverlay_arrow_position = Qnil; | |
9939 | |
9940 DEFVAR_LISP_MAGIC ("overlay-arrow-string", &Voverlay_arrow_string /* | |
442 | 9941 String or glyph to display as an arrow. See also `overlay-arrow-position'. |
444 | 9942 \(Note that despite the name of this variable, it can be set to a glyph as |
442 | 9943 well as a string.) |
428 | 9944 */ , |
9945 redisplay_variable_changed); | |
9946 Voverlay_arrow_string = Qnil; | |
9947 | |
9948 DEFVAR_INT ("scroll-step", &scroll_step /* | |
9949 *The number of lines to try scrolling a window by when point moves out. | |
9950 If that fails to bring point back on frame, point is centered instead. | |
9951 If this is zero, point is always centered after it moves off screen. | |
9952 */ ); | |
9953 scroll_step = 0; | |
9954 | |
9955 DEFVAR_INT ("scroll-conservatively", &scroll_conservatively /* | |
9956 *Scroll up to this many lines, to bring point back on screen. | |
9957 */ ); | |
9958 scroll_conservatively = 0; | |
9959 | |
9960 DEFVAR_BOOL_MAGIC ("truncate-partial-width-windows", | |
9961 &truncate_partial_width_windows /* | |
9962 *Non-nil means truncate lines in all windows less than full frame wide. | |
9963 */ , | |
9964 redisplay_variable_changed); | |
9965 truncate_partial_width_windows = 1; | |
9966 | |
442 | 9967 DEFVAR_LISP ("visible-bell", &Vvisible_bell /* |
9968 *Non-nil substitutes a visual signal for the audible bell. | |
9969 | |
9970 Default behavior is to flash the whole screen. On some platforms, | |
9971 special effects are available using the following values: | |
9972 | |
3025 | 9973 `display' Flash the whole screen (ie, the default behavior). |
9974 `top-bottom' Flash only the top and bottom lines of the selected frame. | |
442 | 9975 |
9976 When effects are unavailable on a platform, the visual bell is the | |
9977 default, whole screen. (Currently only X supports any special effects.) | |
428 | 9978 */ ); |
442 | 9979 Vvisible_bell = Qnil; |
428 | 9980 |
9981 DEFVAR_BOOL ("no-redraw-on-reenter", &no_redraw_on_reenter /* | |
9982 *Non-nil means no need to redraw entire frame after suspending. | |
9983 A non-nil value is useful if the terminal can automatically preserve | |
9984 Emacs's frame display when you reenter Emacs. | |
9985 It is up to you to set this variable if your terminal can do that. | |
9986 */ ); | |
9987 no_redraw_on_reenter = 0; | |
9988 | |
9989 DEFVAR_LISP ("window-system", &Vwindow_system /* | |
9990 A symbol naming the window-system under which Emacs is running, | |
9991 such as `x', or nil if emacs is running on an ordinary terminal. | |
9992 | |
9993 Do not use this variable, except for GNU Emacs compatibility, as it | |
9994 gives wrong values in a multi-device environment. Use `console-type' | |
9995 instead. | |
9996 */ ); | |
9997 Vwindow_system = Qnil; | |
9998 | |
4477
e34711681f30
Don't determine whether to call general device-type code at startup,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4418
diff
changeset
|
9999 DEFVAR_CONST_LISP ("initial-device-type", &Vinitial_device_type /* |
e34711681f30
Don't determine whether to call general device-type code at startup,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4418
diff
changeset
|
10000 The type of the first XEmacs device to be created. |
e34711681f30
Don't determine whether to call general device-type code at startup,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4418
diff
changeset
|
10001 |
e34711681f30
Don't determine whether to call general device-type code at startup,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4418
diff
changeset
|
10002 This is constant; it's used by the command line handling code to communicate |
e34711681f30
Don't determine whether to call general device-type code at startup,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4418
diff
changeset
|
10003 to Lisp what type the initial device to be created should be. |
428 | 10004 */ ); |
4477
e34711681f30
Don't determine whether to call general device-type code at startup,
Aidan Kehoe <kehoea@parhasard.net>
parents:
4418
diff
changeset
|
10005 Vinitial_device_type = Qnil; |
428 | 10006 |
10007 DEFVAR_BOOL ("cursor-in-echo-area", &cursor_in_echo_area /* | |
10008 Non-nil means put cursor in minibuffer, at end of any message there. | |
10009 */ ); | |
10010 cursor_in_echo_area = 0; | |
10011 | |
10012 /* #### Shouldn't this be generalized as follows: | |
10013 | |
10014 if nil, use block cursor. | |
10015 if a number, use a bar cursor of that width. | |
10016 Otherwise, use a 1-pixel bar cursor. | |
10017 | |
10018 #### Or better yet, this variable should be trashed entirely | |
10019 (use a Lisp-magic variable to maintain compatibility) | |
10020 and a specifier `cursor-shape' added, which allows a block | |
10021 cursor, a bar cursor, a flashing block or bar cursor, | |
10022 maybe a caret cursor, etc. */ | |
10023 | |
10024 DEFVAR_LISP ("bar-cursor", &Vbar_cursor /* | |
448 | 10025 *Use vertical bar cursor if non-nil. If t width is 1 pixel, otherwise 2. |
428 | 10026 */ ); |
10027 Vbar_cursor = Qnil; | |
10028 | |
442 | 10029 DEFVAR_LISP ("buffer-list-changed-hook", &Vbuffer_list_changed_hook /* |
10030 Function or functions to call when a frame's buffer list has changed. | |
10031 This is called during redisplay, before redisplaying each frame. | |
10032 Functions on this hook are called with one argument, the frame. | |
10033 */ ); | |
10034 Vbuffer_list_changed_hook = Qnil; | |
10035 | |
428 | 10036 DEFVAR_INT ("display-warning-tick", &display_warning_tick /* |
10037 Bump this to tell the C code to call `display-warning-buffer' | |
10038 at next redisplay. You should not normally change this; the function | |
10039 `display-warning' automatically does this at appropriate times. | |
10040 */ ); | |
10041 display_warning_tick = 0; | |
10042 | |
10043 DEFVAR_BOOL ("inhibit-warning-display", &inhibit_warning_display /* | |
10044 Non-nil means inhibit display of warning messages. | |
10045 You should *bind* this, not set it. Any pending warning messages | |
10046 will be displayed when the binding no longer applies. | |
10047 */ ); | |
10048 /* reset to 0 by startup.el after the splash screen has displayed. | |
10049 This way, the warnings don't obliterate the splash screen. */ | |
10050 inhibit_warning_display = 1; | |
10051 | |
10052 DEFVAR_BOOL ("column-number-start-at-one", &column_number_start_at_one /* | |
10053 *Non-nil means column display number starts at 1. | |
10054 */ ); | |
10055 column_number_start_at_one = 0; | |
10056 } | |
10057 | |
10058 void | |
10059 specifier_vars_of_redisplay (void) | |
10060 { | |
10061 DEFVAR_SPECIFIER ("left-margin-width", &Vleft_margin_width /* | |
10062 *Width of left margin. | |
10063 This is a specifier; use `set-specifier' to change it. | |
10064 */ ); | |
10065 Vleft_margin_width = Fmake_specifier (Qnatnum); | |
10066 set_specifier_fallback (Vleft_margin_width, list1 (Fcons (Qnil, Qzero))); | |
10067 set_specifier_caching (Vleft_margin_width, | |
438 | 10068 offsetof (struct window, left_margin_width), |
428 | 10069 some_window_value_changed, |
438 | 10070 offsetof (struct frame, left_margin_width), |
444 | 10071 margin_width_changed_in_frame, 0); |
428 | 10072 |
10073 DEFVAR_SPECIFIER ("right-margin-width", &Vright_margin_width /* | |
10074 *Width of right margin. | |
10075 This is a specifier; use `set-specifier' to change it. | |
10076 */ ); | |
10077 Vright_margin_width = Fmake_specifier (Qnatnum); | |
10078 set_specifier_fallback (Vright_margin_width, list1 (Fcons (Qnil, Qzero))); | |
10079 set_specifier_caching (Vright_margin_width, | |
438 | 10080 offsetof (struct window, right_margin_width), |
428 | 10081 some_window_value_changed, |
438 | 10082 offsetof (struct frame, right_margin_width), |
444 | 10083 margin_width_changed_in_frame, 0); |
428 | 10084 |
10085 DEFVAR_SPECIFIER ("minimum-line-ascent", &Vminimum_line_ascent /* | |
10086 *Minimum ascent height of lines. | |
10087 This is a specifier; use `set-specifier' to change it. | |
10088 */ ); | |
10089 Vminimum_line_ascent = Fmake_specifier (Qnatnum); | |
10090 set_specifier_fallback (Vminimum_line_ascent, list1 (Fcons (Qnil, Qzero))); | |
10091 set_specifier_caching (Vminimum_line_ascent, | |
438 | 10092 offsetof (struct window, minimum_line_ascent), |
428 | 10093 some_window_value_changed, |
444 | 10094 0, 0, 0); |
428 | 10095 |
10096 DEFVAR_SPECIFIER ("minimum-line-descent", &Vminimum_line_descent /* | |
10097 *Minimum descent height of lines. | |
10098 This is a specifier; use `set-specifier' to change it. | |
10099 */ ); | |
10100 Vminimum_line_descent = Fmake_specifier (Qnatnum); | |
10101 set_specifier_fallback (Vminimum_line_descent, list1 (Fcons (Qnil, Qzero))); | |
10102 set_specifier_caching (Vminimum_line_descent, | |
438 | 10103 offsetof (struct window, minimum_line_descent), |
428 | 10104 some_window_value_changed, |
444 | 10105 0, 0, 0); |
428 | 10106 |
10107 DEFVAR_SPECIFIER ("use-left-overflow", &Vuse_left_overflow /* | |
10108 *Non-nil means use the left outside margin as extra whitespace when | |
3025 | 10109 displaying `whitespace' or `inside-margin' glyphs. |
428 | 10110 This is a specifier; use `set-specifier' to change it. |
10111 */ ); | |
10112 Vuse_left_overflow = Fmake_specifier (Qboolean); | |
10113 set_specifier_fallback (Vuse_left_overflow, list1 (Fcons (Qnil, Qnil))); | |
10114 set_specifier_caching (Vuse_left_overflow, | |
438 | 10115 offsetof (struct window, use_left_overflow), |
428 | 10116 some_window_value_changed, |
444 | 10117 0, 0, 0); |
428 | 10118 |
10119 DEFVAR_SPECIFIER ("use-right-overflow", &Vuse_right_overflow /* | |
10120 *Non-nil means use the right outside margin as extra whitespace when | |
3025 | 10121 displaying `whitespace' or `inside-margin' glyphs. |
428 | 10122 This is a specifier; use `set-specifier' to change it. |
10123 */ ); | |
10124 Vuse_right_overflow = Fmake_specifier (Qboolean); | |
10125 set_specifier_fallback (Vuse_right_overflow, list1 (Fcons (Qnil, Qnil))); | |
10126 set_specifier_caching (Vuse_right_overflow, | |
438 | 10127 offsetof (struct window, use_right_overflow), |
428 | 10128 some_window_value_changed, |
444 | 10129 0, 0, 0); |
428 | 10130 |
10131 DEFVAR_SPECIFIER ("text-cursor-visible-p", &Vtext_cursor_visible_p /* | |
10132 *Non-nil means the text cursor is visible (this is usually the case). | |
10133 This is a specifier; use `set-specifier' to change it. | |
10134 */ ); | |
10135 Vtext_cursor_visible_p = Fmake_specifier (Qboolean); | |
10136 set_specifier_fallback (Vtext_cursor_visible_p, list1 (Fcons (Qnil, Qt))); | |
10137 set_specifier_caching (Vtext_cursor_visible_p, | |
438 | 10138 offsetof (struct window, text_cursor_visible_p), |
428 | 10139 text_cursor_visible_p_changed, |
444 | 10140 0, 0, 0); |
428 | 10141 |
10142 } |