Mercurial > hg > xemacs-beta
comparison src/window.c @ 2289:7fa4bc78a35d
[xemacs-hg @ 2004-09-21 02:59:59 by james]
Darryl Okahata's patch to add current-pixel-row.
author | james |
---|---|
date | Tue, 21 Sep 2004 03:00:27 +0000 |
parents | 04bc9d2f42c7 |
children | 21f73f4563a7 |
comparison
equal
deleted
inserted
replaced
2288:63d767a4650c | 2289:7fa4bc78a35d |
---|---|
5210 record_unwind_protect (save_window_excursion_unwind, | 5210 record_unwind_protect (save_window_excursion_unwind, |
5211 call1 (Qcurrent_window_configuration, Qnil)); | 5211 call1 (Qcurrent_window_configuration, Qnil)); |
5212 return unbind_to_1 (speccount, Fprogn (args)); | 5212 return unbind_to_1 (speccount, Fprogn (args)); |
5213 } | 5213 } |
5214 | 5214 |
5215 DEFUN ("current-pixel-column", Fcurrent_pixel_column, 0, 2, 0, /* | 5215 static int |
5216 Return the horizontal pixel position of POS in window. | 5216 get_current_pixel_pos (Lisp_Object window, Lisp_Object pos, |
5217 Beginning of line is column 0. This is calculated using the redisplay | 5217 struct window **w, |
5218 display tables. If WINDOW is nil, the current window is assumed. | 5218 struct rune **rb, struct display_line **dl) |
5219 If POS is nil, point is assumed. Note that POS must be visible for | 5219 { |
5220 a non-nil result to be returned. | 5220 display_line_dynarr *dla; |
5221 */ | 5221 struct display_block *db = NULL; |
5222 (window, pos)) | 5222 int x, y; |
5223 { | 5223 |
5224 struct window* w = decode_window (window); | 5224 *rb = NULL; |
5225 display_line_dynarr *dla = window_display_lines (w, CURRENT_DISP); | 5225 *dl = NULL; |
5226 | 5226 *w = decode_window (window); |
5227 struct display_line *dl = 0; | 5227 dla = window_display_lines (*w, CURRENT_DISP); |
5228 struct display_block *db = 0; | 5228 x = (*w)->last_point_x[CURRENT_DISP]; |
5229 struct rune* rb = 0; | 5229 y = (*w)->last_point_y[CURRENT_DISP]; |
5230 int y = w->last_point_y[CURRENT_DISP]; | 5230 if (MINI_WINDOW_P (*w)) |
5231 int x = w->last_point_x[CURRENT_DISP]; | 5231 return 0; |
5232 | |
5233 if (MINI_WINDOW_P (w)) | |
5234 return Qnil; | |
5235 | 5232 |
5236 if (y<0 || x<0 || y >= Dynarr_length (dla) || !NILP (pos)) | 5233 if (y<0 || x<0 || y >= Dynarr_length (dla) || !NILP (pos)) |
5237 { | 5234 { |
5238 int first_line, i; | 5235 int first_line, i; |
5239 Charbpos point; | 5236 Charbpos point; |
5249 else | 5246 else |
5250 first_line = 0; | 5247 first_line = 0; |
5251 | 5248 |
5252 for (i = first_line; i < Dynarr_length (dla); i++) | 5249 for (i = first_line; i < Dynarr_length (dla); i++) |
5253 { | 5250 { |
5254 dl = Dynarr_atp (dla, i); | 5251 *dl = Dynarr_atp (dla, i); |
5255 /* find the vertical location first */ | 5252 /* find the vertical location first */ |
5256 if (point >= dl->charpos && point <= dl->end_charpos) | 5253 if (point >= (*dl)->charpos && point <= (*dl)->end_charpos) |
5257 { | 5254 { |
5258 db = get_display_block_from_line (dl, TEXT); | 5255 db = get_display_block_from_line (*dl, TEXT); |
5259 for (i = 0; i < Dynarr_length (db->runes); i++) | 5256 for (i = 0; i < Dynarr_length (db->runes); i++) |
5260 { | 5257 { |
5261 rb = Dynarr_atp (db->runes, i); | 5258 *rb = Dynarr_atp (db->runes, i); |
5262 if (point <= rb->charpos) | 5259 if (point <= *rb->charpos) |
5263 goto found_charpos; | 5260 goto found_charpos; |
5264 } | 5261 } |
5265 return Qnil; | 5262 return 0; |
5266 } | 5263 } |
5267 } | 5264 } |
5268 return Qnil; | 5265 return 0; |
5269 found_charpos: | 5266 found_charpos: |
5270 ; | 5267 ; |
5271 } | 5268 } |
5272 else | 5269 else |
5273 { | 5270 { |
5274 /* optimized case */ | 5271 /* optimized case */ |
5275 dl = Dynarr_atp (dla, y); | 5272 *dl = Dynarr_atp (dla, y); |
5276 db = get_display_block_from_line (dl, TEXT); | 5273 db = get_display_block_from_line (*dl, TEXT); |
5277 | 5274 |
5278 if (x >= Dynarr_length (db->runes)) | 5275 if (x >= Dynarr_length (db->runes)) |
5279 return Qnil; | 5276 return 0; |
5280 | 5277 |
5281 rb = Dynarr_atp (db->runes, x); | 5278 *rb = Dynarr_atp (db->runes, x); |
5282 } | 5279 } |
5280 | |
5281 return 1; | |
5282 } | |
5283 | |
5284 DEFUN ("current-pixel-column", Fcurrent_pixel_column, 0, 2, 0, /* | |
5285 Return the horizontal pixel position of point POS in window. | |
5286 Beginning of line is column 0. If WINDOW is nil, the current window | |
5287 is assumed. If POS is nil, point is assumed. Note that POS must be | |
5288 visible for a non-nil result to be returned. This is calculated using | |
5289 the redisplay display tables; because of this, the returned value will | |
5290 only be correct if the redisplay tables are up-to-date. Use | |
5291 \"(sit-for 0)\" to insure that they are; however, if WINDOW is part of | |
5292 a new frame, use the following instead: | |
5293 (while (not (frame-visible-p frame)) (sleep-for .5)) | |
5294 */ | |
5295 (window, pos)) | |
5296 { | |
5297 struct window* w; | |
5298 struct display_line *dl; | |
5299 struct rune* rb; | |
5300 | |
5301 if (!get_current_pixel_pos(window, pos, &w, &rb, &dl)) | |
5302 return Qnil; | |
5283 | 5303 |
5284 return make_int (rb->xpos - WINDOW_LEFT (w)); | 5304 return make_int (rb->xpos - WINDOW_LEFT (w)); |
5305 } | |
5306 | |
5307 DEFUN ("current-pixel-row", Fcurrent_pixel_row, 0, 2, 0, /* | |
5308 Return the vertical pixel position of point POS in window. Top of | |
5309 window is row 0. If WINDOW is nil, the current window is assumed. If | |
5310 POS is nil, point is assumed. Note that POS must be visible for a | |
5311 non-nil result to be returned. This is calculated using the redisplay | |
5312 display tables; because of this, the returned value will only be | |
5313 correct if the redisplay tables are up-to-date. Use \"(sit-for 0)\" | |
5314 to insure that they are; however, if WINDOW is part of a new frame, | |
5315 use the following instead: | |
5316 (while (not (frame-visible-p frame)) (sleep-for .5)) | |
5317 */ | |
5318 (window, pos)) | |
5319 { | |
5320 struct window* w; | |
5321 struct display_line *dl; | |
5322 struct rune* rb; | |
5323 | |
5324 if (!get_current_pixel_pos(window, pos, &w, &rb, &dl)) | |
5325 return Qnil; | |
5326 | |
5327 return make_int (dl->ypos - dl->ascent - WINDOW_TOP (w)); | |
5285 } | 5328 } |
5286 | 5329 |
5287 | 5330 |
5288 #ifdef DEBUG_XEMACS | 5331 #ifdef DEBUG_XEMACS |
5289 /* This is short and simple in elisp, but... it was written to debug | 5332 /* This is short and simple in elisp, but... it was written to debug |
5429 #ifdef MEMORY_USAGE_STATS | 5472 #ifdef MEMORY_USAGE_STATS |
5430 DEFSUBR (Fwindow_memory_usage); | 5473 DEFSUBR (Fwindow_memory_usage); |
5431 #endif | 5474 #endif |
5432 DEFSUBR (Fsave_window_excursion); | 5475 DEFSUBR (Fsave_window_excursion); |
5433 DEFSUBR (Fcurrent_pixel_column); | 5476 DEFSUBR (Fcurrent_pixel_column); |
5477 DEFSUBR (Fcurrent_pixel_row); | |
5434 } | 5478 } |
5435 | 5479 |
5436 void | 5480 void |
5437 reinit_vars_of_window (void) | 5481 reinit_vars_of_window (void) |
5438 { | 5482 { |