comparison src/window.c @ 5118:e0db3c197671 ben-lisp-object

merge up to latest default branch, doesn't compile yet
author Ben Wing <ben@xemacs.org>
date Sat, 26 Dec 2009 21:18:49 -0600
parents 3742ea8250b5 1d61580e0cf7
children d1247f3cc363
comparison
equal deleted inserted replaced
5117:3742ea8250b5 5118:e0db3c197671
179 { XD_LISP_OBJECT, offsetof (face_cachel, display_table) }, 179 { XD_LISP_OBJECT, offsetof (face_cachel, display_table) },
180 { XD_LISP_OBJECT, offsetof (face_cachel, background_pixmap) }, 180 { XD_LISP_OBJECT, offsetof (face_cachel, background_pixmap) },
181 { XD_END } 181 { XD_END }
182 }; 182 };
183 183
184 #ifdef NEW_GC
185 DEFINE_DUMPABLE_INTERNAL_LISP_OBJECT ("face-cachel", face_cachel,
186 0, face_cachel_description_1,
187 Lisp_Face_Cachel);
188 #endif /* NEW_GC */
189
184 static const struct sized_memory_description face_cachel_description = { 190 static const struct sized_memory_description face_cachel_description = {
185 sizeof (face_cachel), 191 sizeof (face_cachel),
186 face_cachel_description_1 192 face_cachel_description_1
187 }; 193 };
188 194
189 static const struct memory_description face_cachel_dynarr_description_1[] = { 195 static const struct memory_description face_cachel_dynarr_description_1[] = {
196 #ifdef NEW_GC
197 XD_LISP_DYNARR_DESC (face_cachel_dynarr, &face_cachel_description),
198 #else /* not NEW_GC */
190 XD_DYNARR_DESC (face_cachel_dynarr, &face_cachel_description), 199 XD_DYNARR_DESC (face_cachel_dynarr, &face_cachel_description),
200 #endif /* not NEW_GC */
191 { XD_END } 201 { XD_END }
192 }; 202 };
193 203
204 #ifdef NEW_GC
205 DEFINE_DUMPABLE_INTERNAL_LISP_OBJECT ("face-cachel-dynarr", face_cachel_dynarr,
206 0, face_cachel_dynarr_description_1,
207 face_cachel_dynarr);
208 #else /* not NEW_GC */
194 static const struct sized_memory_description face_cachel_dynarr_description = { 209 static const struct sized_memory_description face_cachel_dynarr_description = {
195 sizeof (face_cachel_dynarr), 210 sizeof (face_cachel_dynarr),
196 face_cachel_dynarr_description_1 211 face_cachel_dynarr_description_1
197 }; 212 };
213 #endif /* not NEW_GC */
198 214
199 static const struct memory_description glyph_cachel_description_1[] = { 215 static const struct memory_description glyph_cachel_description_1[] = {
200 { XD_LISP_OBJECT, offsetof (glyph_cachel, glyph) }, 216 { XD_LISP_OBJECT, offsetof (glyph_cachel, glyph) },
201 { XD_END } 217 { XD_END }
202 }; 218 };
203 219
220 #ifdef NEW_GC
221 DEFINE_DUMPABLE_INTERNAL_LISP_OBJECT ("glyph-cachel", glyph_cachel,
222 0, glyph_cachel_description_1,
223 Lisp_Glyph_Cachel);
224 #endif /* NEW_GC */
225
204 static const struct sized_memory_description glyph_cachel_description = { 226 static const struct sized_memory_description glyph_cachel_description = {
205 sizeof (glyph_cachel), 227 sizeof (glyph_cachel),
206 glyph_cachel_description_1 228 glyph_cachel_description_1
207 }; 229 };
208 230
209 static const struct memory_description glyph_cachel_dynarr_description_1[] = { 231 static const struct memory_description glyph_cachel_dynarr_description_1[] = {
232 #ifdef NEW_GC
233 XD_LISP_DYNARR_DESC (glyph_cachel_dynarr, &glyph_cachel_description),
234 #else /* not NEW_GC */
210 XD_DYNARR_DESC (glyph_cachel_dynarr, &glyph_cachel_description), 235 XD_DYNARR_DESC (glyph_cachel_dynarr, &glyph_cachel_description),
236 #endif /* not NEW_GC */
211 { XD_END } 237 { XD_END }
212 }; 238 };
213 239
240 #ifdef NEW_GC
241 DEFINE_DUMPABLE_INTERNAL_LISP_OBJECT ("glyph-cachel-dynarr",
242 glyph_cachel_dynarr, 0,
243 glyph_cachel_dynarr_description_1,
244 glyph_cachel_dynarr);
245 #else /* not NEW_GC */
214 static const struct sized_memory_description glyph_cachel_dynarr_description = { 246 static const struct sized_memory_description glyph_cachel_dynarr_description = {
215 sizeof (glyph_cachel_dynarr), 247 sizeof (glyph_cachel_dynarr),
216 glyph_cachel_dynarr_description_1 248 glyph_cachel_dynarr_description_1
217 }; 249 };
250 #endif /* not NEW_GC */
218 251
219 static const struct memory_description line_start_cache_description_1[] = { 252 static const struct memory_description line_start_cache_description_1[] = {
220 { XD_END } 253 { XD_END }
221 }; 254 };
222 255
239 #define WINDOW_SLOT(slot) { XD_LISP_OBJECT, offsetof (struct window, slot) }, 272 #define WINDOW_SLOT(slot) { XD_LISP_OBJECT, offsetof (struct window, slot) },
240 #define WINDOW_SLOT_ARRAY(slot, size) \ 273 #define WINDOW_SLOT_ARRAY(slot, size) \
241 { XD_LISP_OBJECT_ARRAY, offsetof (struct window, slot), size }, 274 { XD_LISP_OBJECT_ARRAY, offsetof (struct window, slot), size },
242 #include "winslots.h" 275 #include "winslots.h"
243 276
277 #ifdef NEW_GC
278 { XD_LISP_OBJECT, offsetof (struct window, face_cachels) },
279 { XD_LISP_OBJECT, offsetof (struct window, glyph_cachels) },
280 #else /* not NEW_GC */
244 { XD_BLOCK_PTR, offsetof (struct window, face_cachels), 281 { XD_BLOCK_PTR, offsetof (struct window, face_cachels),
245 1, { &face_cachel_dynarr_description } }, 282 1, { &face_cachel_dynarr_description } },
246 { XD_BLOCK_PTR, offsetof (struct window, glyph_cachels), 283 { XD_BLOCK_PTR, offsetof (struct window, glyph_cachels),
247 1, { &glyph_cachel_dynarr_description } }, 284 1, { &glyph_cachel_dynarr_description } },
285 #endif /* not NEW_GC */
248 { XD_BLOCK_PTR, offsetof (struct window, line_start_cache), 286 { XD_BLOCK_PTR, offsetof (struct window, line_start_cache),
249 1, { &line_start_cache_dynarr_description }, XD_FLAG_NO_KKCC }, 287 1, { &line_start_cache_dynarr_description }, XD_FLAG_NO_KKCC },
250 { XD_END } 288 { XD_END }
251 }; 289 };
252 290
322 make_saved_buffer_point_cache (void) 360 make_saved_buffer_point_cache (void)
323 { 361 {
324 return make_lisp_hash_table (20, HASH_TABLE_KEY_WEAK, HASH_TABLE_EQ); 362 return make_lisp_hash_table (20, HASH_TABLE_KEY_WEAK, HASH_TABLE_EQ);
325 } 363 }
326 364
327 DEFINE_NONDUMPABLE_LISP_OBJECT ("window", window, 365 DEFINE_NODUMP_LISP_OBJECT ("window", window,
328 mark_window, print_window, finalize_window, 366 mark_window, print_window, finalize_window,
329 0, 0, window_description, struct window); 367 0, 0, window_description, struct window);
330 368
331 #define INIT_DISP_VARIABLE(field, initialization) \ 369 #define INIT_DISP_VARIABLE(field, initialization) \
332 p->field[CURRENT_DISP] = initialization; \ 370 p->field[CURRENT_DISP] = initialization; \
359 p->use_time = Qzero; 397 p->use_time = Qzero;
360 INIT_DISP_VARIABLE (last_modified, Qzero); 398 INIT_DISP_VARIABLE (last_modified, Qzero);
361 INIT_DISP_VARIABLE (last_point, Fmake_marker ()); 399 INIT_DISP_VARIABLE (last_point, Fmake_marker ());
362 INIT_DISP_VARIABLE (last_start, Fmake_marker ()); 400 INIT_DISP_VARIABLE (last_start, Fmake_marker ());
363 INIT_DISP_VARIABLE (last_facechange, Qzero); 401 INIT_DISP_VARIABLE (last_facechange, Qzero);
402 #ifdef NEW_GC
403 p->face_cachels = Dynarr_lisp_new (face_cachel,
404 &lrecord_face_cachel_dynarr,
405 &lrecord_face_cachel);
406 p->glyph_cachels = Dynarr_lisp_new (glyph_cachel,
407 &lrecord_glyph_cachel_dynarr,
408 &lrecord_glyph_cachel);
409 #else /* not NEW_GC */
364 p->face_cachels = Dynarr_new (face_cachel); 410 p->face_cachels = Dynarr_new (face_cachel);
365 p->glyph_cachels = Dynarr_new (glyph_cachel); 411 p->glyph_cachels = Dynarr_new (glyph_cachel);
412 #endif /* not NEW_GC */
366 p->line_start_cache = Dynarr_new (line_start_cache); 413 p->line_start_cache = Dynarr_new (line_start_cache);
367 p->subwindow_instance_cache = make_image_instance_cache_hash_table (); 414 p->subwindow_instance_cache = make_image_instance_cache_hash_table ();
368 415
369 p->line_cache_last_updated = Qzero; 416 p->line_cache_last_updated = Qzero;
370 417
468 return wrap_window_mirror (mir->next); 515 return wrap_window_mirror (mir->next);
469 else 516 else
470 return Qnil; 517 return Qnil;
471 } 518 }
472 519
473 DEFINE_NONDUMPABLE_LISP_OBJECT ("window-mirror", window_mirror, 520 DEFINE_NODUMP_LISP_OBJECT ("window-mirror", window_mirror,
474 mark_window_mirror, 0, 521 mark_window_mirror, 0,
475 0, 0, 0, window_mirror_description, 522 0, 0, 0, window_mirror_description,
476 struct window_mirror); 523 struct window_mirror);
477 524
478 /* Create a new window mirror structure and associated redisplay 525 /* Create a new window mirror structure and associated redisplay
3462 Lisp_Object child, minor_kid, major_kid; 3509 Lisp_Object child, minor_kid, major_kid;
3463 int minsize; 3510 int minsize;
3464 int line_size; 3511 int line_size;
3465 int defheight, defwidth; 3512 int defheight, defwidth;
3466 3513
3467 /* #### This is very likely incorrect and instead the char_to_pixel_
3468 functions should be called. */
3469 default_face_height_and_width (window, &defheight, &defwidth); 3514 default_face_height_and_width (window, &defheight, &defwidth);
3470 line_size = (set_height ? defheight : defwidth); 3515 line_size = (set_height ? defheight : defwidth);
3471 3516
3472 check_min_window_sizes (); 3517 check_min_window_sizes ();
3473 3518
3474 minsize = (set_height ? window_min_height : window_min_width); 3519 minsize = (set_height ? window_min_height : window_min_width);
3475 minsize *= line_size; 3520 minsize *= line_size;
3476 3521
3477 if (!nodelete 3522 if (!nodelete
3478 && !TOP_LEVEL_WINDOW_P (w) 3523 && !TOP_LEVEL_WINDOW_P (w)
3479 && new_pixsize < minsize) 3524 && (new_pixsize + window_modeline_height (w)) < minsize)
3480 { 3525 {
3481 Fdelete_window (window, Qnil); 3526 Fdelete_window (window, Qnil);
3482 return; 3527 return;
3483 } 3528 }
3484 3529
3545 3590
3546 pos = (((old_pos * new_pixsize) << 1) + old_pixsize) / div_val; 3591 pos = (((old_pos * new_pixsize) << 1) + old_pixsize) / div_val;
3547 /* All but the last window should have a height which is 3592 /* All but the last window should have a height which is
3548 a multiple of the default line height. */ 3593 a multiple of the default line height. */
3549 if (!NILP (c->next)) 3594 if (!NILP (c->next))
3550 pos = (pos / line_size) * line_size; 3595 {
3596 /*
3597 * Round up when we're shrinking, down when we're growing
3598 * to make sure that pairs of grow / shrink meant to
3599 * cancel out actually do cancel out.
3600 */
3601 if (pixel_adj_left < 0)
3602 pos = ((pos + line_size -1) / line_size) * line_size;
3603 else
3604 pos = (pos / line_size) * line_size;
3605 }
3551 3606
3552 /* Avoid confusion: don't delete child if it becomes too small */ 3607 /* Avoid confusion: don't delete child if it becomes too small */
3553 set_window_pixsize (child, pos + first - last_pos, 1, set_height); 3608 set_window_pixsize (child, pos + first - last_pos, 1, set_height);
3554 3609
3555 last_pos = pos + first; 3610 last_pos = pos + first;
3805 COPY_LCRECORD (p, o); 3860 COPY_LCRECORD (p, o);
3806 3861
3807 /* Don't copy the pointers to the line start cache or the face 3862 /* Don't copy the pointers to the line start cache or the face
3808 instances. */ 3863 instances. */
3809 p->line_start_cache = Dynarr_new (line_start_cache); 3864 p->line_start_cache = Dynarr_new (line_start_cache);
3865 #ifdef NEW_GC
3866 p->face_cachels = Dynarr_lisp_new (face_cachel,
3867 &lrecord_face_cachel_dynarr,
3868 &lrecord_face_cachel);
3869 p->glyph_cachels = Dynarr_lisp_new (glyph_cachel,
3870 &lrecord_glyph_cachel_dynarr,
3871 &lrecord_glyph_cachel);
3872 #else /* not NEW_GC */
3810 p->face_cachels = Dynarr_new (face_cachel); 3873 p->face_cachels = Dynarr_new (face_cachel);
3811 p->glyph_cachels = Dynarr_new (glyph_cachel); 3874 p->glyph_cachels = Dynarr_new (glyph_cachel);
3875 #endif /* not NEW_GC */
3812 p->subwindow_instance_cache = 3876 p->subwindow_instance_cache =
3813 make_image_instance_cache_hash_table (); 3877 make_image_instance_cache_hash_table ();
3814 3878
3815 /* Put new into window structure in place of window */ 3879 /* Put new into window structure in place of window */
3816 replace_window (window, obj); 3880 replace_window (window, obj);
4039 window_pixel_height_to_char_height (struct window *w, int pixel_height, 4103 window_pixel_height_to_char_height (struct window *w, int pixel_height,
4040 int include_gutters_p) 4104 int include_gutters_p)
4041 { 4105 {
4042 int avail_height; 4106 int avail_height;
4043 int defheight, defwidth; 4107 int defheight, defwidth;
4044 int char_height; 4108 int char_height = 0;
4045 Lisp_Object window = wrap_window (w); 4109 Lisp_Object window = wrap_window (w);
4046 4110
4047 4111
4048 avail_height = (pixel_height - 4112 avail_height = (pixel_height -
4049 (include_gutters_p ? 0 : 4113 (include_gutters_p ? 0 :
4050 window_top_window_gutter_height (w) + 4114 window_top_window_gutter_height (w) +
4051 window_bottom_window_gutter_height (w))); 4115 window_bottom_window_gutter_height (w)));
4052 4116
4053 default_face_height_and_width (window, &defheight, &defwidth); 4117 default_face_height_and_width (window, &defheight, &defwidth);
4054 4118
4055 char_height = avail_height / defheight; 4119 if (defheight)
4120 char_height = avail_height / defheight;
4056 4121
4057 /* It's the calling function's responsibility to check these values 4122 /* It's the calling function's responsibility to check these values
4058 and make sure they're not out of range. 4123 and make sure they're not out of range.
4059 4124
4060 #### We need to go through the calling functions and actually 4125 #### We need to go through the calling functions and actually
4154 } 4219 }
4155 4220
4156 default_face_height_and_width (window, &defheight, &defwidth); 4221 default_face_height_and_width (window, &defheight, &defwidth);
4157 /* #### This probably needs to know about the clipping area once a 4222 /* #### This probably needs to know about the clipping area once a
4158 final definition is decided on. */ 4223 final definition is decided on. */
4159 num_lines += ((ypos2 - ypos1) / defheight); 4224 if (defheight)
4225 num_lines += ((ypos2 - ypos1) / defheight);
4160 } 4226 }
4161 else 4227 else
4162 { 4228 {
4163 if (num_lines > 1 && Dynarr_atp (dla, 0)->modeline) 4229 if (num_lines > 1 && Dynarr_atp (dla, 0)->modeline)
4164 num_lines--; 4230 num_lines--;
4182 static int 4248 static int
4183 window_pixel_width_to_char_width (struct window *w, int pixel_width, 4249 window_pixel_width_to_char_width (struct window *w, int pixel_width,
4184 int include_margins_p) 4250 int include_margins_p)
4185 { 4251 {
4186 int avail_width; 4252 int avail_width;
4187 int char_width; 4253 int char_width = 0;
4188 int defheight, defwidth; 4254 int defheight, defwidth;
4189 Lisp_Object window = wrap_window (w); 4255 Lisp_Object window = wrap_window (w);
4190 4256
4191 4257
4192 avail_width = (pixel_width - 4258 avail_width = (pixel_width -
4195 (include_margins_p ? 0 : window_left_margin_width (w)) - 4261 (include_margins_p ? 0 : window_left_margin_width (w)) -
4196 (include_margins_p ? 0 : window_right_margin_width (w))); 4262 (include_margins_p ? 0 : window_right_margin_width (w)));
4197 4263
4198 default_face_height_and_width (window, &defheight, &defwidth); 4264 default_face_height_and_width (window, &defheight, &defwidth);
4199 4265
4200 char_width = (avail_width / defwidth); 4266 if (defwidth)
4267 char_width = (avail_width / defwidth);
4201 4268
4202 /* It's the calling function's responsibility to check these values 4269 /* It's the calling function's responsibility to check these values
4203 and make sure they're not out of range. 4270 and make sure they're not out of range.
4204 4271
4205 #### We need to go through the calling functions and actually 4272 #### We need to go through the calling functions and actually
4298 window = wrap_window (win); 4365 window = wrap_window (win);
4299 f = XFRAME (win->frame); 4366 f = XFRAME (win->frame);
4300 if (EQ (window, FRAME_ROOT_WINDOW (f))) 4367 if (EQ (window, FRAME_ROOT_WINDOW (f)))
4301 invalid_operation ("Won't change only window", Qunbound); 4368 invalid_operation ("Won't change only window", Qunbound);
4302 4369
4303 /* #### This is very likely incorrect and instead the char_to_pixel_
4304 functions should be called. */
4305 default_face_height_and_width (window, &defheight, &defwidth); 4370 default_face_height_and_width (window, &defheight, &defwidth);
4306 4371
4307 while (1) 4372 while (1)
4308 { 4373 {
4309 w = XWINDOW (window); 4374 w = XWINDOW (window);
5190 if (!NILP (w->hchild)) delete_all_subwindows (XWINDOW (w->hchild)); 5255 if (!NILP (w->hchild)) delete_all_subwindows (XWINDOW (w->hchild));
5191 5256
5192 mark_window_as_deleted (w); 5257 mark_window_as_deleted (w);
5193 } 5258 }
5194 5259
5195 Lisp_Object
5196 save_window_excursion_unwind (Lisp_Object window_config)
5197 {
5198 Lisp_Object val = call1 (Qset_window_configuration, window_config);
5199 return val;
5200 }
5201
5202 DEFUN ("save-window-excursion", Fsave_window_excursion, 0, UNEVALLED, 0, /*
5203 Execute body, preserving window sizes and contents.
5204 Restores which buffer appears in which window, where display starts,
5205 as well as the current buffer.
5206 Does not restore the value of point in current buffer.
5207 */
5208 (args))
5209 {
5210 /* This function can GC */
5211 int speccount = specpdl_depth ();
5212
5213 record_unwind_protect (save_window_excursion_unwind,
5214 call1 (Qcurrent_window_configuration, Qnil));
5215 return unbind_to_1 (speccount, Fprogn (args));
5216 }
5217 5260
5218 static int 5261 static int
5219 get_current_pixel_pos (Lisp_Object window, Lisp_Object pos, 5262 get_current_pixel_pos (Lisp_Object window, Lisp_Object pos,
5220 struct window **w, 5263 struct window **w,
5221 struct rune **rb, struct display_line **dl) 5264 struct rune **rb, struct display_line **dl)
5379 void 5422 void
5380 syms_of_window (void) 5423 syms_of_window (void)
5381 { 5424 {
5382 INIT_LISP_OBJECT (window); 5425 INIT_LISP_OBJECT (window);
5383 INIT_LISP_OBJECT (window_mirror); 5426 INIT_LISP_OBJECT (window_mirror);
5427 #ifdef NEW_GC
5428 INIT_LISP_OBJECT (face_cachel);
5429 INIT_LISP_OBJECT (face_cachel_dynarr);
5430 INIT_LISP_OBJECT (glyph_cachel);
5431 INIT_LISP_OBJECT (glyph_cachel_dynarr);
5432 #endif /* NEW_GC */
5384 5433
5385 DEFSYMBOL (Qwindowp); 5434 DEFSYMBOL (Qwindowp);
5386 DEFSYMBOL (Qwindow_live_p); 5435 DEFSYMBOL (Qwindow_live_p);
5387 DEFSYMBOL (Qdisplay_buffer); 5436 DEFSYMBOL (Qdisplay_buffer);
5388 5437
5473 DEFSUBR (Fcenter_to_window_line); 5522 DEFSUBR (Fcenter_to_window_line);
5474 DEFSUBR (Fmove_to_window_line); 5523 DEFSUBR (Fmove_to_window_line);
5475 #ifdef MEMORY_USAGE_STATS 5524 #ifdef MEMORY_USAGE_STATS
5476 DEFSUBR (Fwindow_memory_usage); 5525 DEFSUBR (Fwindow_memory_usage);
5477 #endif 5526 #endif
5478 DEFSUBR (Fsave_window_excursion);
5479 DEFSUBR (Fcurrent_pixel_column); 5527 DEFSUBR (Fcurrent_pixel_column);
5480 DEFSUBR (Fcurrent_pixel_row); 5528 DEFSUBR (Fcurrent_pixel_row);
5481 } 5529 }
5482 5530
5483 void 5531 void