comparison src/dispnew.c @ 53514:db81ac8829b6

(buffer_posn_from_coords): Return both buffer/string object and image object. Return glyph width and height. (mode_line_string, marginal_area_string): Ditto.
author Kim F. Storm <storm@cua.dk>
date Tue, 06 Jan 2004 22:37:11 +0000
parents 9c540a878edf
children 7dfd96e25ec6 82554ed1aed8
comparison
equal deleted inserted replaced
53513:b37377020fd4 53514:db81ac8829b6
5685 /*********************************************************************** 5685 /***********************************************************************
5686 X/Y Position -> Buffer Position 5686 X/Y Position -> Buffer Position
5687 ***********************************************************************/ 5687 ***********************************************************************/
5688 5688
5689 /* Determine what's under window-relative pixel position (*X, *Y). 5689 /* Determine what's under window-relative pixel position (*X, *Y).
5690 Return in *OBJECT the object (string or buffer) that's there. 5690 Return 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.
5692 to character positions. */ 5692 Adjust *X and *Y to character positions. */
5693 5693
5694 void 5694 Lisp_Object
5695 buffer_posn_from_coords (w, x, y, dx, dy, object, pos) 5695 buffer_posn_from_coords (w, x, y, pos, object, dx, dy, width, height)
5696 struct window *w; 5696 struct window *w;
5697 int *x, *y; 5697 int *x, *y;
5698 struct display_pos *pos;
5699 Lisp_Object *object;
5698 int *dx, *dy; 5700 int *dx, *dy;
5699 Lisp_Object *object; 5701 int *width, *height;
5700 struct display_pos *pos;
5701 { 5702 {
5702 struct it it; 5703 struct it it;
5703 struct buffer *old_current_buffer = current_buffer; 5704 struct buffer *old_current_buffer = current_buffer;
5704 struct text_pos startp; 5705 struct text_pos startp;
5706 Lisp_Object string;
5707 struct glyph_row *row;
5705 int x0, x1; 5708 int x0, x1;
5706 5709
5707 current_buffer = XBUFFER (w->buffer); 5710 current_buffer = XBUFFER (w->buffer);
5708 SET_TEXT_POS_FROM_MARKER (startp, w->start); 5711 SET_TEXT_POS_FROM_MARKER (startp, w->start);
5709 CHARPOS (startp) = min (ZV, max (BEGV, CHARPOS (startp))); 5712 CHARPOS (startp) = min (ZV, max (BEGV, CHARPOS (startp)));
5717 current_buffer = old_current_buffer; 5720 current_buffer = old_current_buffer;
5718 5721
5719 *dx = x0 + it.first_visible_x - it.current_x; 5722 *dx = x0 + it.first_visible_x - it.current_x;
5720 *dy = *y - it.current_y; 5723 *dy = *y - it.current_y;
5721 5724
5722 *object = w->buffer; 5725 string = w->buffer;
5726 if (STRINGP (it.string))
5727 string = it.string;
5728 *pos = it.current;
5723 5729
5724 #ifdef HAVE_WINDOW_SYSTEM 5730 #ifdef HAVE_WINDOW_SYSTEM
5725 if (it.what == IT_IMAGE) 5731 if (it.what == IT_IMAGE)
5726 { 5732 {
5727 struct image *img; 5733 struct image *img;
5728 if ((img = IMAGE_FROM_ID (it.f, it.image_id)) != NULL 5734 if ((img = IMAGE_FROM_ID (it.f, it.image_id)) != NULL
5729 && !NILP (img->spec)) 5735 && !NILP (img->spec))
5730 { 5736 *object = img->spec;
5731 struct glyph_row *row = MATRIX_ROW (w->current_matrix, it.vpos); 5737 }
5732 struct glyph *glyph; 5738 #endif
5733 5739
5734 if (it.hpos < row->used[TEXT_AREA] 5740 row = MATRIX_ROW (w->current_matrix, it.vpos);
5735 && (glyph = row->glyphs[TEXT_AREA] + it.hpos, 5741 if (row->enabled_p)
5736 glyph->type == IMAGE_GLYPH)) 5742 {
5737 { 5743 if (it.hpos < row->used[TEXT_AREA])
5738 *dy -= row->ascent - glyph->ascent; 5744 {
5739 *object = img->spec; 5745 struct glyph *glyph = row->glyphs[TEXT_AREA] + it.hpos;
5740 } 5746 *width = glyph->pixel_width;
5747 *height = glyph->ascent + glyph->descent;
5748 #ifdef HAVE_WINDOW_SYSTEM
5749 if (glyph->type == IMAGE_GLYPH)
5750 *dy -= row->ascent - glyph->ascent;
5751 #endif
5752 }
5753 else
5754 {
5755 *width = 0;
5756 *height = row->height;
5741 } 5757 }
5742 } 5758 }
5743 else 5759 else
5744 #endif 5760 {
5745 if (STRINGP (it.string)) 5761 *width = *height = 0;
5746 *object = it.string; 5762 }
5747
5748 *pos = it.current;
5749 5763
5750 /* Add extra (default width) columns if clicked after EOL. */ 5764 /* Add extra (default width) columns if clicked after EOL. */
5751 x1 = max(0, it.current_x + it.pixel_width - it.first_visible_x); 5765 x1 = max(0, it.current_x + it.pixel_width - it.first_visible_x);
5752 if (x0 > x1) 5766 if (x0 > x1)
5753 it.hpos += (x0 - x1) / WINDOW_FRAME_COLUMN_WIDTH (w); 5767 it.hpos += (x0 - x1) / WINDOW_FRAME_COLUMN_WIDTH (w);
5754 5768
5755 *x = it.hpos; 5769 *x = it.hpos;
5756 *y = it.vpos; 5770 *y = it.vpos;
5771
5772 return string;
5757 } 5773 }
5758 5774
5759 5775
5760 /* Value is the string under window-relative coordinates X/Y in the 5776 /* Value is the string under window-relative coordinates X/Y in the
5761 mode or header line of window W, or nil if none. MODE_LINE_P non-zero 5777 mode line or header line (PART says which) of window W, or nil if none.
5762 means look at the mode line. *CHARPOS is set to the position in 5778 *CHARPOS is set to the position in the string returned. */
5763 the string returned. */
5764 5779
5765 Lisp_Object 5780 Lisp_Object
5766 mode_line_string (w, x, y, dx, dy, part, charpos) 5781 mode_line_string (w, part, x, y, charpos, object, dx, dy, width, height)
5767 struct window *w; 5782 struct window *w;
5783 enum window_part part;
5768 int *x, *y; 5784 int *x, *y;
5785 int *charpos;
5786 Lisp_Object *object;
5769 int *dx, *dy; 5787 int *dx, *dy;
5770 enum window_part part; 5788 int *width, *height;
5771 int *charpos;
5772 { 5789 {
5773 struct glyph_row *row; 5790 struct glyph_row *row;
5774 struct glyph *glyph, *end; 5791 struct glyph *glyph, *end;
5775 int x0, y0; 5792 int x0, y0;
5776 Lisp_Object string = Qnil; 5793 Lisp_Object string = Qnil;
5793 *x = glyph - row->glyphs[TEXT_AREA]; 5810 *x = glyph - row->glyphs[TEXT_AREA];
5794 if (glyph < end) 5811 if (glyph < end)
5795 { 5812 {
5796 string = glyph->object; 5813 string = glyph->object;
5797 *charpos = glyph->charpos; 5814 *charpos = glyph->charpos;
5815 *width = glyph->pixel_width;
5816 *height = glyph->ascent + glyph->descent;
5817 #ifdef HAVE_WINDOW_SYSTEM
5818 if (glyph->type == IMAGE_GLYPH)
5819 {
5820 struct image *img;
5821 img = IMAGE_FROM_ID (WINDOW_XFRAME (w), glyph->u.img_id);
5822 if (img != NULL)
5823 *object = img->spec;
5824 y0 -= row->ascent - glyph->ascent;
5825 }
5826 #endif
5798 } 5827 }
5799 else 5828 else
5800 /* Add extra (default width) columns if clicked after EOL. */ 5829 {
5801 *x += x0 / WINDOW_FRAME_COLUMN_WIDTH (w); 5830 /* Add extra (default width) columns if clicked after EOL. */
5831 *x += x0 / WINDOW_FRAME_COLUMN_WIDTH (w);
5832 *width = 0;
5833 *height = row->height;
5834 }
5802 } 5835 }
5803 else 5836 else
5804 { 5837 {
5805 *x = 0; 5838 *x = 0;
5806 x0 = 0; 5839 x0 = 0;
5807 } 5840 *width = *height = 0;
5808 5841 }
5809 if (dx) 5842
5810 { 5843 *dx = x0;
5811 *dx = x0; 5844 *dy = y0;
5812 *dy = y0;
5813 }
5814 5845
5815 return string; 5846 return string;
5816 } 5847 }
5817 5848
5818 5849
5819 /* Value is the string under window-relative coordinates X/Y in either 5850 /* Value is the string under window-relative coordinates X/Y in either
5820 marginal area, or nil if none. *CHARPOS is set to the position in 5851 marginal area, or nil if none. *CHARPOS is set to the position in
5821 the string returned. */ 5852 the string returned. */
5822 5853
5823 Lisp_Object 5854 Lisp_Object
5824 marginal_area_string (w, x, y, dx, dy, part, charpos) 5855 marginal_area_string (w, part, x, y, charpos, object, dx, dy, width, height)
5825 struct window *w; 5856 struct window *w;
5857 enum window_part part;
5826 int *x, *y; 5858 int *x, *y;
5859 int *charpos;
5860 Lisp_Object *object;
5827 int *dx, *dy; 5861 int *dx, *dy;
5828 enum window_part part; 5862 int *width, *height;
5829 int *charpos;
5830 { 5863 {
5831 struct glyph_row *row = w->current_matrix->rows; 5864 struct glyph_row *row = w->current_matrix->rows;
5832 struct glyph *glyph, *end; 5865 struct glyph *glyph, *end;
5833 int x0, y0, i, wy = *y; 5866 int x0, y0, i, wy = *y;
5834 int area; 5867 int area;
5869 *x = glyph - row->glyphs[area]; 5902 *x = glyph - row->glyphs[area];
5870 if (glyph < end) 5903 if (glyph < end)
5871 { 5904 {
5872 string = glyph->object; 5905 string = glyph->object;
5873 *charpos = glyph->charpos; 5906 *charpos = glyph->charpos;
5907 *width = glyph->pixel_width;
5908 *height = glyph->ascent + glyph->descent;
5874 #ifdef HAVE_WINDOW_SYSTEM 5909 #ifdef HAVE_WINDOW_SYSTEM
5875 if (glyph->type == IMAGE_GLYPH) 5910 if (glyph->type == IMAGE_GLYPH)
5876 { 5911 {
5877 struct image *img; 5912 struct image *img;
5878 img = IMAGE_FROM_ID (WINDOW_XFRAME (w), glyph->u.img_id); 5913 img = IMAGE_FROM_ID (WINDOW_XFRAME (w), glyph->u.img_id);
5879 if (img != NULL) 5914 if (img != NULL)
5880 string = img->spec; 5915 *object = img->spec;
5881 y0 -= row->ascent - glyph->ascent; 5916 y0 -= row->ascent - glyph->ascent;
5882 } 5917 }
5883 #endif 5918 #endif
5884 } 5919 }
5885 else 5920 else
5886 /* Add extra (default width) columns if clicked after EOL. */ 5921 {
5887 *x += x0 / WINDOW_FRAME_COLUMN_WIDTH (w); 5922 /* Add extra (default width) columns if clicked after EOL. */
5923 *x += x0 / WINDOW_FRAME_COLUMN_WIDTH (w);
5924 *width = 0;
5925 *height = row->height;
5926 }
5888 } 5927 }
5889 else 5928 else
5890 { 5929 {
5891 x0 = 0; 5930 x0 = 0;
5892 *x = 0; 5931 *x = 0;
5893 } 5932 *width = *height = 0;
5894 5933 }
5895 if (dx) 5934
5896 { 5935 *dx = x0;
5897 *dx = x0; 5936 *dy = y0;
5898 *dy = y0;
5899 }
5900 5937
5901 return string; 5938 return string;
5902 } 5939 }
5903 5940
5904 5941