diff options
| author | Kim F. Storm | 2004-01-06 22:37:11 +0000 |
|---|---|---|
| committer | Kim F. Storm | 2004-01-06 22:37:11 +0000 |
| commit | 6a3d9c9ff43c38fbfc5d63e3026b76356ea97c62 (patch) | |
| tree | 59095d82f0e266952e366839c534a421b2726cf3 /src | |
| parent | 0a0c9ab0e43c703da758197828aeb7b5ca19fc66 (diff) | |
| download | emacs-6a3d9c9ff43c38fbfc5d63e3026b76356ea97c62.tar.gz emacs-6a3d9c9ff43c38fbfc5d63e3026b76356ea97c62.zip | |
(buffer_posn_from_coords): Return both buffer/string
object and image object. Return glyph width and height.
(mode_line_string, marginal_area_string): Ditto.
Diffstat (limited to 'src')
| -rw-r--r-- | src/dispnew.c | 131 |
1 files changed, 84 insertions, 47 deletions
diff --git a/src/dispnew.c b/src/dispnew.c index 09a651d5d7c..c65fefaa20c 100644 --- a/src/dispnew.c +++ b/src/dispnew.c | |||
| @@ -5687,21 +5687,24 @@ update_frame_line (f, vpos) | |||
| 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 | int *dx, *dy; | ||
| 5699 | Lisp_Object *object; | ||
| 5700 | struct display_pos *pos; | 5698 | struct display_pos *pos; |
| 5699 | Lisp_Object *object; | ||
| 5700 | int *dx, *dy; | ||
| 5701 | int *width, *height; | ||
| 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); |
| @@ -5719,7 +5722,10 @@ buffer_posn_from_coords (w, x, y, dx, dy, object, pos) | |||
| 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) |
| @@ -5727,25 +5733,33 @@ buffer_posn_from_coords (w, x, y, dx, dy, object, pos) | |||
| 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); |
| @@ -5754,21 +5768,24 @@ buffer_posn_from_coords (w, x, y, dx, dy, object, pos) | |||
| 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; |
| 5768 | int *x, *y; | ||
| 5769 | int *dx, *dy; | ||
| 5770 | enum window_part part; | 5783 | enum window_part part; |
| 5784 | int *x, *y; | ||
| 5771 | int *charpos; | 5785 | int *charpos; |
| 5786 | Lisp_Object *object; | ||
| 5787 | int *dx, *dy; | ||
| 5788 | int *width, *height; | ||
| 5772 | { | 5789 | { |
| 5773 | struct glyph_row *row; | 5790 | struct glyph_row *row; |
| 5774 | struct glyph *glyph, *end; | 5791 | struct glyph *glyph, *end; |
| @@ -5795,22 +5812,36 @@ mode_line_string (w, x, y, dx, dy, part, charpos) | |||
| 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; |
| 5840 | *width = *height = 0; | ||
| 5807 | } | 5841 | } |
| 5808 | 5842 | ||
| 5809 | if (dx) | 5843 | *dx = x0; |
| 5810 | { | 5844 | *dy = y0; |
| 5811 | *dx = x0; | ||
| 5812 | *dy = y0; | ||
| 5813 | } | ||
| 5814 | 5845 | ||
| 5815 | return string; | 5846 | return string; |
| 5816 | } | 5847 | } |
| @@ -5821,12 +5852,14 @@ mode_line_string (w, x, y, dx, dy, part, charpos) | |||
| 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; |
| 5826 | int *x, *y; | ||
| 5827 | int *dx, *dy; | ||
| 5828 | enum window_part part; | 5857 | enum window_part part; |
| 5858 | int *x, *y; | ||
| 5829 | int *charpos; | 5859 | int *charpos; |
| 5860 | Lisp_Object *object; | ||
| 5861 | int *dx, *dy; | ||
| 5862 | int *width, *height; | ||
| 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; |
| @@ -5871,32 +5904,36 @@ marginal_area_string (w, x, y, dx, dy, part, charpos) | |||
| 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; |
| 5932 | *width = *height = 0; | ||
| 5893 | } | 5933 | } |
| 5894 | 5934 | ||
| 5895 | if (dx) | 5935 | *dx = x0; |
| 5896 | { | 5936 | *dy = y0; |
| 5897 | *dx = x0; | ||
| 5898 | *dy = y0; | ||
| 5899 | } | ||
| 5900 | 5937 | ||
| 5901 | return string; | 5938 | return string; |
| 5902 | } | 5939 | } |