comparison src/dispnew.c @ 53176:b246aabe1c49

(buffer_posn_from_coords): Calculate and return pixel coordinates relative to glyph at posn. If glyph is an image, return that as object at posn. Callers changed. (mode_line_string, marginal_area_string): Calculate and return pixel coordinates relative to glyph. Callers changed.
author Kim F. Storm <storm@cua.dk>
date Thu, 27 Nov 2003 21:15:53 +0000
parents bc14fd4782c3
children 053a4dfb6bd4
comparison
equal deleted inserted replaced
53175:83fb165444f9 53176:b246aabe1c49
5690 Return in *OBJECT the object (string or buffer) that's there. 5690 Return in *OBJECT the object (string or buffer) that's there.
5691 Return in *POS the position in that object. Adjust *X and *Y 5691 Return in *POS the position in that object. Adjust *X and *Y
5692 to character positions. */ 5692 to character positions. */
5693 5693
5694 void 5694 void
5695 buffer_posn_from_coords (w, x, y, object, pos) 5695 buffer_posn_from_coords (w, x, y, dx, dy, object, pos)
5696 struct window *w; 5696 struct window *w;
5697 int *x, *y; 5697 int *x, *y;
5698 int *dx, *dy;
5698 Lisp_Object *object; 5699 Lisp_Object *object;
5699 struct display_pos *pos; 5700 struct display_pos *pos;
5700 { 5701 {
5701 struct it it; 5702 struct it it;
5702 struct buffer *old_current_buffer = current_buffer; 5703 struct buffer *old_current_buffer = current_buffer;
5703 struct text_pos startp; 5704 struct text_pos startp;
5704 struct glyph_row *row; 5705 struct glyph_row *row;
5706 struct image *img;
5705 int x0, x1; 5707 int x0, x1;
5706 5708
5707 current_buffer = XBUFFER (w->buffer); 5709 current_buffer = XBUFFER (w->buffer);
5708 SET_TEXT_POS_FROM_MARKER (startp, w->start); 5710 SET_TEXT_POS_FROM_MARKER (startp, w->start);
5709 CHARPOS (startp) = min (ZV, max (BEGV, CHARPOS (startp))); 5711 CHARPOS (startp) = min (ZV, max (BEGV, CHARPOS (startp)));
5719 if (x0 > x1) 5721 if (x0 > x1)
5720 it.hpos += (x0 - x1) / WINDOW_FRAME_COLUMN_WIDTH (w); 5722 it.hpos += (x0 - x1) / WINDOW_FRAME_COLUMN_WIDTH (w);
5721 5723
5722 current_buffer = old_current_buffer; 5724 current_buffer = old_current_buffer;
5723 5725
5724 *object = STRINGP (it.string) ? it.string : w->buffer; 5726 *dx = x0 + it.first_visible_x - it.current_x;
5727 *dy = *y - it.current_y;
5728
5729 if (it.what == IT_IMAGE
5730 && (img = IMAGE_FROM_ID (it.f, it.image_id)) != NULL
5731 && !NILP (img->spec))
5732 *object = img->spec;
5733 else
5734 *object = STRINGP (it.string) ? it.string : w->buffer;
5725 *pos = it.current; 5735 *pos = it.current;
5726 *x = it.hpos; 5736 *x = it.hpos;
5727 *y = it.vpos; 5737 *y = it.vpos;
5728 } 5738 }
5729 5739
5732 mode or header line of window W, or nil if none. MODE_LINE_P non-zero 5742 mode or header line of window W, or nil if none. MODE_LINE_P non-zero
5733 means look at the mode line. *CHARPOS is set to the position in 5743 means look at the mode line. *CHARPOS is set to the position in
5734 the string returned. */ 5744 the string returned. */
5735 5745
5736 Lisp_Object 5746 Lisp_Object
5737 mode_line_string (w, x, y, part, charpos) 5747 mode_line_string (w, x, y, dx, dy, part, charpos)
5738 struct window *w; 5748 struct window *w;
5739 int *x, *y; 5749 int *x, *y;
5750 int *dx, *dy;
5740 enum window_part part; 5751 enum window_part part;
5741 int *charpos; 5752 int *charpos;
5742 { 5753 {
5743 struct glyph_row *row; 5754 struct glyph_row *row;
5744 struct glyph *glyph, *end; 5755 struct glyph *glyph, *end;
5745 int x0; 5756 int x0, y0;
5746 Lisp_Object string = Qnil; 5757 Lisp_Object string = Qnil;
5747 5758
5748 if (part == ON_MODE_LINE) 5759 if (part == ON_MODE_LINE)
5749 row = MATRIX_MODE_LINE_ROW (w->current_matrix); 5760 row = MATRIX_MODE_LINE_ROW (w->current_matrix);
5750 else 5761 else
5751 row = MATRIX_HEADER_LINE_ROW (w->current_matrix); 5762 row = MATRIX_HEADER_LINE_ROW (w->current_matrix);
5752 5763 y0 = *y - row->y;
5753 *y = row - MATRIX_FIRST_TEXT_ROW (w->current_matrix); 5764 *y = row - MATRIX_FIRST_TEXT_ROW (w->current_matrix);
5754 5765
5755 if (row->mode_line_p && row->enabled_p) 5766 if (row->mode_line_p && row->enabled_p)
5756 { 5767 {
5757 /* Find the glyph under X. If we find one with a string object, 5768 /* Find the glyph under X. If we find one with a string object,
5769 else 5780 else
5770 /* Add extra (default width) columns if clicked after EOL. */ 5781 /* Add extra (default width) columns if clicked after EOL. */
5771 *x += x0 / WINDOW_FRAME_COLUMN_WIDTH (w); 5782 *x += x0 / WINDOW_FRAME_COLUMN_WIDTH (w);
5772 } 5783 }
5773 else 5784 else
5774 *x = 0; 5785 {
5786 *x = 0;
5787 x0 = 0;
5788 }
5789
5790 if (dx)
5791 {
5792 *dx = x0;
5793 *dy = y0;
5794 }
5775 5795
5776 return string; 5796 return string;
5777 } 5797 }
5778 5798
5779 5799
5780 /* Value is the string under window-relative coordinates X/Y in either 5800 /* Value is the string under window-relative coordinates X/Y in either
5781 marginal area, or nil if none. *CHARPOS is set to the position in 5801 marginal area, or nil if none. *CHARPOS is set to the position in
5782 the string returned. */ 5802 the string returned. */
5783 5803
5784 Lisp_Object 5804 Lisp_Object
5785 marginal_area_string (w, x, y, part, charpos) 5805 marginal_area_string (w, x, y, dx, dy, part, charpos)
5786 struct window *w; 5806 struct window *w;
5787 int *x, *y; 5807 int *x, *y;
5808 int *dx, *dy;
5788 enum window_part part; 5809 enum window_part part;
5789 int *charpos; 5810 int *charpos;
5790 { 5811 {
5791 struct glyph_row *row = w->current_matrix->rows; 5812 struct glyph_row *row = w->current_matrix->rows;
5792 struct glyph *glyph, *end; 5813 struct glyph *glyph, *end;
5793 int x0, i, wy = *y; 5814 int x0, y0, i, wy = *y;
5794 int area; 5815 int area;
5795 Lisp_Object string = Qnil; 5816 Lisp_Object string = Qnil;
5796 5817
5797 if (part == ON_LEFT_MARGIN) 5818 if (part == ON_LEFT_MARGIN)
5798 area = LEFT_MARGIN_AREA; 5819 area = LEFT_MARGIN_AREA;
5802 abort (); 5823 abort ();
5803 5824
5804 for (i = 0; row->enabled_p && i < w->current_matrix->nrows; ++i, ++row) 5825 for (i = 0; row->enabled_p && i < w->current_matrix->nrows; ++i, ++row)
5805 if (wy >= row->y && wy < MATRIX_ROW_BOTTOM_Y (row)) 5826 if (wy >= row->y && wy < MATRIX_ROW_BOTTOM_Y (row))
5806 break; 5827 break;
5828 y0 = *y - row->y;
5807 *y = row - MATRIX_FIRST_TEXT_ROW (w->current_matrix); 5829 *y = row - MATRIX_FIRST_TEXT_ROW (w->current_matrix);
5808 5830
5809 if (row->enabled_p) 5831 if (row->enabled_p)
5810 { 5832 {
5811 /* Find the glyph under X. If we find one with a string object, 5833 /* Find the glyph under X. If we find one with a string object,
5834 else 5856 else
5835 /* Add extra (default width) columns if clicked after EOL. */ 5857 /* Add extra (default width) columns if clicked after EOL. */
5836 *x += x0 / WINDOW_FRAME_COLUMN_WIDTH (w); 5858 *x += x0 / WINDOW_FRAME_COLUMN_WIDTH (w);
5837 } 5859 }
5838 else 5860 else
5839 *x = 0; 5861 {
5862 x0 = 0;
5863 *x = 0;
5864 }
5865
5866 if (dx)
5867 {
5868 *dx = x0;
5869 *dy = y0;
5870 }
5840 5871
5841 return string; 5872 return string;
5842 } 5873 }
5843 5874
5844 5875