comparison src/window.c @ 55027:91ab946dfd86

(Fpos_visible_in_window_p): Return pixel position if PARTIALLY arg is non-nil. Simplify. Doc fix. (Fwindow_vscroll, Fset_window_vscroll): Add optional PIXEL_P arg to return/set vscroll in pixels.
author Kim F. Storm <storm@cua.dk>
date Tue, 20 Apr 2004 22:18:33 +0000
parents 375346b8175c
children 5896445199fd 30dd490f06f2
comparison
equal deleted inserted replaced
55026:08e4e7c06ffc 55027:91ab946dfd86
320 Spos_visible_in_window_p, 0, 3, 0, 320 Spos_visible_in_window_p, 0, 3, 0,
321 doc: /* Return t if position POS is currently on the frame in WINDOW. 321 doc: /* Return t if position POS is currently on the frame in WINDOW.
322 Return nil if that position is scrolled vertically out of view. 322 Return nil if that position is scrolled vertically out of view.
323 If a character is only partially visible, nil is returned, unless the 323 If a character is only partially visible, nil is returned, unless the
324 optional argument PARTIALLY is non-nil. 324 optional argument PARTIALLY is non-nil.
325 POS defaults to point in WINDOW; WINDOW defaults to the selected window. */) 325 POS defaults to point in WINDOW; WINDOW defaults to the selected window.
326
327 If POS is visible, return t if PARTIALLY is nil; if PARTIALLY is non-nil,
328 return value is a list (X Y PARTIAL) where X and Y are the pixel relative
329 coordinate */)
326 (pos, window, partially) 330 (pos, window, partially)
327 Lisp_Object pos, window, partially; 331 Lisp_Object pos, window, partially;
328 { 332 {
329 register struct window *w; 333 register struct window *w;
330 register int posint; 334 register int posint;
331 register struct buffer *buf; 335 register struct buffer *buf;
332 struct text_pos top; 336 struct text_pos top;
333 Lisp_Object in_window; 337 Lisp_Object in_window = Qnil;
334 int fully_p; 338 int fully_p = 1;
339 int x, y;
335 340
336 w = decode_window (window); 341 w = decode_window (window);
337 buf = XBUFFER (w->buffer); 342 buf = XBUFFER (w->buffer);
338 SET_TEXT_POS_FROM_MARKER (top, w->start); 343 SET_TEXT_POS_FROM_MARKER (top, w->start);
339 344
345 else if (w == XWINDOW (selected_window)) 350 else if (w == XWINDOW (selected_window))
346 posint = PT; 351 posint = PT;
347 else 352 else
348 posint = XMARKER (w->pointm)->charpos; 353 posint = XMARKER (w->pointm)->charpos;
349 354
350 /* If position is above window start, it's not visible. */ 355 /* If position is above window start or outside buffer boundaries,
351 if (posint < CHARPOS (top)) 356 or if window start is out of range, position is not visible. */
352 in_window = Qnil; 357 if (posint >= CHARPOS (top)
353 else if (XFASTINT (w->last_modified) >= BUF_MODIFF (buf) 358 && posint <= BUF_ZV (buf)
354 && XFASTINT (w->last_overlay_modified) >= BUF_OVERLAY_MODIFF (buf) 359 && CHARPOS (top) >= BUF_BEGV (buf)
355 && posint < BUF_Z (buf) - XFASTINT (w->window_end_pos)) 360 && CHARPOS (top) <= BUF_ZV (buf)
356 { 361 && pos_visible_p (w, posint, &fully_p, &x, &y, NILP (partially))
357 /* If frame is up-to-date, and POSINT is < window end pos, use 362 && (!NILP (partially) || fully_p))
358 that info. This doesn't work for POSINT == end pos, because 363 in_window = Qt;
359 the window end pos is actually the position _after_ the last 364
360 char in the window. */ 365 if (!NILP (in_window) && !NILP (partially))
361 if (NILP (partially)) 366 in_window = Fcons (make_number (x),
362 { 367 Fcons (make_number (y),
363 pos_visible_p (w, posint, &fully_p, NILP (partially)); 368 Fcons (fully_p ? Qt : Qnil, Qnil)));
364 in_window = fully_p ? Qt : Qnil;
365 }
366 else
367 in_window = Qt;
368 }
369 else if (posint > BUF_ZV (buf))
370 in_window = Qnil;
371 else if (CHARPOS (top) < BUF_BEGV (buf) || CHARPOS (top) > BUF_ZV (buf))
372 /* If window start is out of range, do something reasonable. */
373 in_window = Qnil;
374 else
375 {
376 if (pos_visible_p (w, posint, &fully_p, NILP (partially)))
377 in_window = !NILP (partially) || fully_p ? Qt : Qnil;
378 else
379 in_window = Qnil;
380 }
381
382 return in_window; 369 return in_window;
383 } 370 }
384 371
385 372
386 static struct window * 373 static struct window *
3458 3445
3459 DEFUN ("force-window-update", Fforce_window_update, Sforce_window_update, 3446 DEFUN ("force-window-update", Fforce_window_update, Sforce_window_update,
3460 0, 1, 0, 3447 0, 1, 0,
3461 doc: /* Force redisplay of all windows. 3448 doc: /* Force redisplay of all windows.
3462 If optional arg OBJECT is a window, force redisplay of that window only. 3449 If optional arg OBJECT is a window, force redisplay of that window only.
3463 If OBJECT is a buffer or buffer name, force redisplay of all windows 3450 If OBJECT is a buffer or buffer name, force redisplay of all windows
3464 displaying that buffer. */) 3451 displaying that buffer. */)
3465 (object) 3452 (object)
3466 Lisp_Object object; 3453 Lisp_Object object;
3467 { 3454 {
3468 if (NILP (object)) 3455 if (NILP (object))
3480 if (BUFFERP (w->buffer)) 3467 if (BUFFERP (w->buffer))
3481 XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1; 3468 XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1;
3482 ++update_mode_lines; 3469 ++update_mode_lines;
3483 return Qt; 3470 return Qt;
3484 } 3471 }
3485 3472
3486 if (STRINGP (object)) 3473 if (STRINGP (object))
3487 object = Fget_buffer (object); 3474 object = Fget_buffer (object);
3488 if (BUFFERP (object) && !NILP (XBUFFER (object)->name)) 3475 if (BUFFERP (object) && !NILP (XBUFFER (object)->name))
3489 { 3476 {
3490 /* Walk all windows looking for buffer, and force update 3477 /* Walk all windows looking for buffer, and force update
3545 { 3532 {
3546 int count = SPECPDL_INDEX (); 3533 int count = SPECPDL_INDEX ();
3547 Lisp_Object prev_window, prev_buffer; 3534 Lisp_Object prev_window, prev_buffer;
3548 prev_window = selected_window; 3535 prev_window = selected_window;
3549 XSETBUFFER (prev_buffer, old); 3536 XSETBUFFER (prev_buffer, old);
3550 3537
3551 /* Select the window that was chosen, for running the hook. 3538 /* Select the window that was chosen, for running the hook.
3552 Note: Both Fselect_window and select_window_norecord may 3539 Note: Both Fselect_window and select_window_norecord may
3553 set-buffer to the buffer displayed in the window, 3540 set-buffer to the buffer displayed in the window,
3554 so we need to save the current buffer. --stef */ 3541 so we need to save the current buffer. --stef */
3555 record_unwind_protect (Fset_buffer, prev_buffer); 3542 record_unwind_protect (Fset_buffer, prev_buffer);
6065 6052
6066 if (XINT (width) == 0) 6053 if (XINT (width) == 0)
6067 vertical_type = Qnil; 6054 vertical_type = Qnil;
6068 6055
6069 if (!(EQ (vertical_type, Qnil) 6056 if (!(EQ (vertical_type, Qnil)
6070 || EQ (vertical_type, Qleft) 6057 || EQ (vertical_type, Qleft)
6071 || EQ (vertical_type, Qright) 6058 || EQ (vertical_type, Qright)
6072 || EQ (vertical_type, Qt))) 6059 || EQ (vertical_type, Qt)))
6073 error ("Invalid type of vertical scroll bar"); 6060 error ("Invalid type of vertical scroll bar");
6074 6061
6075 if (!EQ (w->scroll_bar_width, width) 6062 if (!EQ (w->scroll_bar_width, width)
6114 6101
6115 /*********************************************************************** 6102 /***********************************************************************
6116 Smooth scrolling 6103 Smooth scrolling
6117 ***********************************************************************/ 6104 ***********************************************************************/
6118 6105
6119 DEFUN ("window-vscroll", Fwindow_vscroll, Swindow_vscroll, 0, 1, 0, 6106 DEFUN ("window-vscroll", Fwindow_vscroll, Swindow_vscroll, 0, 2, 0,
6120 doc: /* Return the amount by which WINDOW is scrolled vertically. 6107 doc: /* Return the amount by which WINDOW is scrolled vertically.
6121 Use the selected window if WINDOW is nil or omitted. 6108 Use the selected window if WINDOW is nil or omitted.
6122 Value is a multiple of the canonical character height of WINDOW. */) 6109 Normally, value is a multiple of the canonical character height of WINDOW;
6123 (window) 6110 optional second arg PIXELS_P means value is measured in pixels. */)
6124 Lisp_Object window; 6111 (window, pixels_p)
6112 Lisp_Object window, pixels_p;
6125 { 6113 {
6126 Lisp_Object result; 6114 Lisp_Object result;
6127 struct frame *f; 6115 struct frame *f;
6128 struct window *w; 6116 struct window *w;
6129 6117
6133 CHECK_WINDOW (window); 6121 CHECK_WINDOW (window);
6134 w = XWINDOW (window); 6122 w = XWINDOW (window);
6135 f = XFRAME (w->frame); 6123 f = XFRAME (w->frame);
6136 6124
6137 if (FRAME_WINDOW_P (f)) 6125 if (FRAME_WINDOW_P (f))
6138 result = FRAME_CANON_Y_FROM_PIXEL_Y (f, -w->vscroll); 6126 result = (NILP (pixels_p)
6127 ? FRAME_CANON_Y_FROM_PIXEL_Y (f, -w->vscroll)
6128 : make_number (-w->vscroll));
6139 else 6129 else
6140 result = make_number (0); 6130 result = make_number (0);
6141 return result; 6131 return result;
6142 } 6132 }
6143 6133
6144 6134
6145 DEFUN ("set-window-vscroll", Fset_window_vscroll, Sset_window_vscroll, 6135 DEFUN ("set-window-vscroll", Fset_window_vscroll, Sset_window_vscroll,
6146 2, 2, 0, 6136 2, 3, 0,
6147 doc: /* Set amount by which WINDOW should be scrolled vertically to VSCROLL. 6137 doc: /* Set amount by which WINDOW should be scrolled vertically to VSCROLL.
6148 WINDOW nil means use the selected window. VSCROLL is a non-negative 6138 WINDOW nil means use the selected window. Normally, VSCROLL is a
6149 multiple of the canonical character height of WINDOW. */) 6139 non-negative multiple of the canonical character height of WINDOW;
6150 (window, vscroll) 6140 optional third arg PIXELS_P non-nil means that VSCROLL is in pixels. */)
6151 Lisp_Object window, vscroll; 6141 (window, vscroll, pixels_p)
6142 Lisp_Object window, vscroll, pixels_p;
6152 { 6143 {
6153 struct window *w; 6144 struct window *w;
6154 struct frame *f; 6145 struct frame *f;
6155 6146
6156 if (NILP (window)) 6147 if (NILP (window))
6164 6155
6165 if (FRAME_WINDOW_P (f)) 6156 if (FRAME_WINDOW_P (f))
6166 { 6157 {
6167 int old_dy = w->vscroll; 6158 int old_dy = w->vscroll;
6168 6159
6169 w->vscroll = - FRAME_LINE_HEIGHT (f) * XFLOATINT (vscroll); 6160 w->vscroll = - (NILP (pixels_p)
6161 ? FRAME_LINE_HEIGHT (f) * XFLOATINT (vscroll)
6162 : XFLOATINT (vscroll));
6170 w->vscroll = min (w->vscroll, 0); 6163 w->vscroll = min (w->vscroll, 0);
6171 6164
6172 /* Adjust glyph matrix of the frame if the virtual display 6165 /* Adjust glyph matrix of the frame if the virtual display
6173 area becomes larger than before. */ 6166 area becomes larger than before. */
6174 if (w->vscroll < 0 && w->vscroll < old_dy) 6167 if (w->vscroll < 0 && w->vscroll < old_dy)
6176 6169
6177 /* Prevent redisplay shortcuts. */ 6170 /* Prevent redisplay shortcuts. */
6178 XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1; 6171 XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1;
6179 } 6172 }
6180 6173
6181 return Fwindow_vscroll (window); 6174 return Fwindow_vscroll (window, pixels_p);
6182 } 6175 }
6183 6176
6184 6177
6185 /* Call FN for all leaf windows on frame F. FN is called with the 6178 /* Call FN for all leaf windows on frame F. FN is called with the
6186 first argument being a pointer to the leaf window, and with 6179 first argument being a pointer to the leaf window, and with