aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim F. Storm2003-03-21 22:56:52 +0000
committerKim F. Storm2003-03-21 22:56:52 +0000
commite080d3ebbf5823a103ff1f9c7614f05e55d91793 (patch)
tree2289a36a54a56d6edf18cb0b8d983a31701cf0ad
parent1853f74c1cede3a355e61ee504ec6289e0c58833 (diff)
downloademacs-e080d3ebbf5823a103ff1f9c7614f05e55d91793.tar.gz
emacs-e080d3ebbf5823a103ff1f9c7614f05e55d91793.zip
* xdisp.c (pixel_to_glyph_coords, glyph_to_pixel_coords):
Add generic versions here. Remove system specific versions defined elsewhere.
-rw-r--r--src/macterm.c101
-rw-r--r--src/msdos.c24
-rw-r--r--src/msdos.h8
-rw-r--r--src/w32console.c17
-rw-r--r--src/w32term.c100
-rw-r--r--src/xdisp.c107
-rw-r--r--src/xterm.c93
7 files changed, 107 insertions, 343 deletions
diff --git a/src/macterm.c b/src/macterm.c
index 68c599caa3e..23ce917f282 100644
--- a/src/macterm.c
+++ b/src/macterm.c
@@ -3464,107 +3464,6 @@ x_get_keysym_name (keysym)
3464 3464
3465/* Mouse clicks and mouse movement. Rah. */ 3465/* Mouse clicks and mouse movement. Rah. */
3466 3466
3467/* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
3468 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
3469 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
3470 not force the value into range. */
3471
3472void
3473pixel_to_glyph_coords (f, pix_x, pix_y, x, y, bounds, noclip)
3474 FRAME_PTR f;
3475 register int pix_x, pix_y;
3476 register int *x, *y;
3477 Rect *bounds;
3478 int noclip;
3479{
3480 /* Support tty mode: if Vwindow_system is nil, behave correctly. */
3481 if (NILP (Vwindow_system))
3482 {
3483 *x = pix_x;
3484 *y = pix_y;
3485 return;
3486 }
3487
3488 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
3489 even for negative values. */
3490 if (pix_x < 0)
3491 pix_x -= FONT_WIDTH (FRAME_FONT (f)) - 1;
3492 if (pix_y < 0)
3493 pix_y -= (f)->output_data.mac->line_height - 1;
3494
3495 pix_x = PIXEL_TO_CHAR_COL (f, pix_x);
3496 pix_y = PIXEL_TO_CHAR_ROW (f, pix_y);
3497
3498 if (bounds)
3499 {
3500 bounds->left = CHAR_TO_PIXEL_COL (f, pix_x);
3501 bounds->top = CHAR_TO_PIXEL_ROW (f, pix_y);
3502 bounds->right = bounds->left + FONT_WIDTH (FRAME_FONT (f)) - 1;
3503 bounds->bottom = bounds->top + f->output_data.mac->line_height - 1;
3504 }
3505
3506 if (!noclip)
3507 {
3508 if (pix_x < 0)
3509 pix_x = 0;
3510 else if (pix_x > FRAME_WINDOW_WIDTH (f))
3511 pix_x = FRAME_WINDOW_WIDTH (f);
3512
3513 if (pix_y < 0)
3514 pix_y = 0;
3515 else if (pix_y > f->height)
3516 pix_y = f->height;
3517 }
3518
3519 *x = pix_x;
3520 *y = pix_y;
3521}
3522
3523
3524/* Given HPOS/VPOS in the current matrix of W, return corresponding
3525 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
3526 can't tell the positions because W's display is not up to date,
3527 return 0. */
3528
3529int
3530glyph_to_pixel_coords (w, hpos, vpos, frame_x, frame_y)
3531 struct window *w;
3532 int hpos, vpos;
3533 int *frame_x, *frame_y;
3534{
3535 int success_p;
3536
3537 xassert (hpos >= 0 && hpos < w->current_matrix->matrix_w);
3538 xassert (vpos >= 0 && vpos < w->current_matrix->matrix_h);
3539
3540 if (display_completed)
3541 {
3542 struct glyph_row *row = MATRIX_ROW (w->current_matrix, vpos);
3543 struct glyph *glyph = row->glyphs[TEXT_AREA];
3544 struct glyph *end = glyph + min (hpos, row->used[TEXT_AREA]);
3545
3546 *frame_y = row->y;
3547 *frame_x = row->x;
3548 while (glyph < end)
3549 {
3550 *frame_x += glyph->pixel_width;
3551 ++glyph;
3552 }
3553
3554 success_p = 1;
3555 }
3556 else
3557 {
3558 *frame_y = *frame_x = 0;
3559 success_p = 0;
3560 }
3561
3562 *frame_y = WINDOW_TO_FRAME_PIXEL_Y (w, *frame_y);
3563 *frame_x = WINDOW_TO_FRAME_PIXEL_X (w, *frame_x);
3564 return success_p;
3565}
3566
3567
3568/* Prepare a mouse-event in *RESULT for placement in the input queue. 3467/* Prepare a mouse-event in *RESULT for placement in the input queue.
3569 3468
3570 If the event is a button press, then note that we have grabbed 3469 If the event is a button press, then note that we have grabbed
diff --git a/src/msdos.c b/src/msdos.c
index 3ab3597b8ed..2c3d2837e4b 100644
--- a/src/msdos.c
+++ b/src/msdos.c
@@ -3500,31 +3500,7 @@ dos_keyread ()
3500} 3500}
3501 3501
3502#ifndef HAVE_X_WINDOWS 3502#ifndef HAVE_X_WINDOWS
3503/* See xterm.c for more info. */
3504void
3505pixel_to_glyph_coords (f, pix_x, pix_y, x, y, bounds, noclip)
3506 FRAME_PTR f;
3507 register int pix_x, pix_y, *x, *y;
3508 XRectangle *bounds;
3509 int noclip;
3510{
3511 if (bounds) abort ();
3512
3513 /* Ignore clipping. */
3514
3515 *x = pix_x;
3516 *y = pix_y;
3517}
3518 3503
3519void
3520glyph_to_pixel_coords (f, x, y, pix_x, pix_y)
3521 FRAME_PTR f;
3522 register int x, y, *pix_x, *pix_y;
3523{
3524 *pix_x = x;
3525 *pix_y = y;
3526}
3527
3528/* Simulation of X's menus. Nothing too fancy here -- just make it work 3504/* Simulation of X's menus. Nothing too fancy here -- just make it work
3529 for now. 3505 for now.
3530 3506
diff --git a/src/msdos.h b/src/msdos.h
index a919bf694ad..fa21d24650b 100644
--- a/src/msdos.h
+++ b/src/msdos.h
@@ -118,14 +118,6 @@ extern struct x_output the_only_x_display;
118struct frame; 118struct frame;
119struct window; 119struct window;
120 120
121/* From xterm.c; emulated on msdos.c */
122
123extern void pixel_to_glyph_coords P_ ((struct frame *f, int pix_x, int pix_y,
124 int *x, int *y, XRectangle *bounds,
125 int noclip));
126extern void glyph_to_pixel_coords P_ ((struct frame *f, int x, int y,
127 int *pix_x, int *pix_y));
128
129/* Defined in xfns.c; emulated on msdos.c */ 121/* Defined in xfns.c; emulated on msdos.c */
130 122
131extern int have_menus_p P_ ((void)); 123extern int have_menus_p P_ ((void));
diff --git a/src/w32console.c b/src/w32console.c
index c784f804630..5a66ae4af8d 100644
--- a/src/w32console.c
+++ b/src/w32console.c
@@ -705,23 +705,6 @@ DEFUN ("set-cursor-size", Fset_cursor_size, Sset_cursor_size, 1, 1, 0,
705 return Qt; 705 return Qt;
706} 706}
707 707
708#ifndef HAVE_NTGUI
709void
710pixel_to_glyph_coords (struct frame * f, int pix_x, int pix_y, int *x, int *y,
711 void *bounds, int noclip)
712{
713 *x = pix_x;
714 *y = pix_y;
715}
716
717void
718glyph_to_pixel_coords (struct window * f, int x, int y, int *pix_x, int *pix_y)
719{
720 *pix_x = x;
721 *pix_y = y;
722}
723#endif /* !HAVE_NTGUI */
724
725void 708void
726syms_of_ntterm () 709syms_of_ntterm ()
727{ 710{
diff --git a/src/w32term.c b/src/w32term.c
index d539d53e691..24167caa3a8 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -2800,106 +2800,6 @@ x_get_keysym_name (keysym)
2800 2800
2801/* Mouse clicks and mouse movement. Rah. */ 2801/* Mouse clicks and mouse movement. Rah. */
2802 2802
2803/* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
2804 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
2805 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
2806 not force the value into range. */
2807
2808void
2809pixel_to_glyph_coords (f, pix_x, pix_y, x, y, bounds, noclip)
2810 FRAME_PTR f;
2811 register int pix_x, pix_y;
2812 register int *x, *y;
2813 RECT *bounds;
2814 int noclip;
2815{
2816 /* Support tty mode: if Vwindow_system is nil, behave correctly. */
2817 if (NILP (Vwindow_system))
2818 {
2819 *x = pix_x;
2820 *y = pix_y;
2821 return;
2822 }
2823
2824 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
2825 even for negative values. */
2826 if (pix_x < 0)
2827 pix_x -= FONT_WIDTH (FRAME_FONT (f)) - 1;
2828 if (pix_y < 0)
2829 pix_y -= (f)->output_data.w32->line_height - 1;
2830
2831 pix_x = PIXEL_TO_CHAR_COL (f, pix_x);
2832 pix_y = PIXEL_TO_CHAR_ROW (f, pix_y);
2833
2834 if (bounds)
2835 {
2836 bounds->left = CHAR_TO_PIXEL_COL (f, pix_x);
2837 bounds->top = CHAR_TO_PIXEL_ROW (f, pix_y);
2838 bounds->right = bounds->left + FONT_WIDTH (FRAME_FONT (f)) - 1;
2839 bounds->bottom = bounds->top + f->output_data.w32->line_height - 1;
2840 }
2841
2842 if (!noclip)
2843 {
2844 if (pix_x < 0)
2845 pix_x = 0;
2846 else if (pix_x > FRAME_WINDOW_WIDTH (f))
2847 pix_x = FRAME_WINDOW_WIDTH (f);
2848
2849 if (pix_y < 0)
2850 pix_y = 0;
2851 else if (pix_y > f->height)
2852 pix_y = f->height;
2853 }
2854
2855 *x = pix_x;
2856 *y = pix_y;
2857}
2858
2859
2860/* Given HPOS/VPOS in the current matrix of W, return corresponding
2861 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
2862 can't tell the positions because W's display is not up to date,
2863 return 0. */
2864
2865int
2866glyph_to_pixel_coords (w, hpos, vpos, frame_x, frame_y)
2867 struct window *w;
2868 int hpos, vpos;
2869 int *frame_x, *frame_y;
2870{
2871 int success_p;
2872
2873 xassert (hpos >= 0 && hpos < w->current_matrix->matrix_w);
2874 xassert (vpos >= 0 && vpos < w->current_matrix->matrix_h);
2875
2876 if (display_completed)
2877 {
2878 struct glyph_row *row = MATRIX_ROW (w->current_matrix, vpos);
2879 struct glyph *glyph = row->glyphs[TEXT_AREA];
2880 struct glyph *end = glyph + min (hpos, row->used[TEXT_AREA]);
2881
2882 *frame_y = row->y;
2883 *frame_x = row->x;
2884 while (glyph < end)
2885 {
2886 *frame_x += glyph->pixel_width;
2887 ++glyph;
2888 }
2889
2890 success_p = 1;
2891 }
2892 else
2893 {
2894 *frame_y = *frame_x = 0;
2895 success_p = 0;
2896 }
2897
2898 *frame_y = WINDOW_TO_FRAME_PIXEL_Y (w, *frame_y);
2899 *frame_x = WINDOW_TO_FRAME_PIXEL_X (w, *frame_x);
2900 return success_p;
2901}
2902
2903/* Parse a button MESSAGE. The button index is returned in PBUTTON, and 2803/* Parse a button MESSAGE. The button index is returned in PBUTTON, and
2904 the state in PUP. XBUTTON provides extra information for extended mouse 2804 the state in PUP. XBUTTON provides extra information for extended mouse
2905 button messages. Returns FALSE if unable to parse the message. */ 2805 button messages. Returns FALSE if unable to parse the message. */
diff --git a/src/xdisp.c b/src/xdisp.c
index b15cea93d09..e7ea150b098 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -1402,6 +1402,113 @@ estimate_mode_line_height (f, face_id)
1402 return 1; 1402 return 1;
1403} 1403}
1404 1404
1405/* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
1406 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
1407 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
1408 not force the value into range. */
1409
1410void
1411pixel_to_glyph_coords (f, pix_x, pix_y, x, y, bounds, noclip)
1412 FRAME_PTR f;
1413 register int pix_x, pix_y;
1414 int *x, *y;
1415 NativeRectangle *bounds;
1416 int noclip;
1417{
1418
1419#ifdef HAVE_WINDOW_SYSTEM
1420 if (FRAME_WINDOW_P (f))
1421 {
1422 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
1423 even for negative values. */
1424 if (pix_x < 0)
1425 pix_x -= FONT_WIDTH (FRAME_FONT (f)) - 1;
1426 if (pix_y < 0)
1427 pix_y -= FRAME_X_OUTPUT(f)->line_height - 1;
1428
1429 pix_x = PIXEL_TO_CHAR_COL (f, pix_x);
1430 pix_y = PIXEL_TO_CHAR_ROW (f, pix_y);
1431
1432 if (bounds)
1433 STORE_NATIVE_RECT (*bounds,
1434 CHAR_TO_PIXEL_COL (f, pix_x),
1435 CHAR_TO_PIXEL_ROW (f, pix_y),
1436 FONT_WIDTH (FRAME_FONT (f)) - 1,
1437 FRAME_X_OUTPUT (f)->line_height - 1);
1438
1439 if (!noclip)
1440 {
1441 if (pix_x < 0)
1442 pix_x = 0;
1443 else if (pix_x > FRAME_WINDOW_WIDTH (f))
1444 pix_x = FRAME_WINDOW_WIDTH (f);
1445
1446 if (pix_y < 0)
1447 pix_y = 0;
1448 else if (pix_y > f->height)
1449 pix_y = f->height;
1450 }
1451 }
1452#endif
1453
1454 *x = pix_x;
1455 *y = pix_y;
1456}
1457
1458
1459/* Given HPOS/VPOS in the current matrix of W, return corresponding
1460 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
1461 can't tell the positions because W's display is not up to date,
1462 return 0. */
1463
1464int
1465glyph_to_pixel_coords (w, hpos, vpos, frame_x, frame_y)
1466 struct window *w;
1467 int hpos, vpos;
1468 int *frame_x, *frame_y;
1469{
1470#ifdef HAVE_WINDOW_SYSTEM
1471 if (FRAME_WINDOW_P (XFRAME (WINDOW_FRAME (w))))
1472 {
1473 int success_p;
1474
1475 xassert (hpos >= 0 && hpos < w->current_matrix->matrix_w);
1476 xassert (vpos >= 0 && vpos < w->current_matrix->matrix_h);
1477
1478 if (display_completed)
1479 {
1480 struct glyph_row *row = MATRIX_ROW (w->current_matrix, vpos);
1481 struct glyph *glyph = row->glyphs[TEXT_AREA];
1482 struct glyph *end = glyph + min (hpos, row->used[TEXT_AREA]);
1483
1484 hpos = row->x;
1485 vpos = row->y;
1486 while (glyph < end)
1487 {
1488 hpos += glyph->pixel_width;
1489 ++glyph;
1490 }
1491
1492 success_p = 1;
1493 }
1494 else
1495 {
1496 hpos = vpos = 0;
1497 success_p = 0;
1498 }
1499
1500 *frame_x = WINDOW_TO_FRAME_PIXEL_X (w, hpos);
1501 *frame_y = WINDOW_TO_FRAME_PIXEL_Y (w, vpos);
1502 return success_p;
1503 }
1504#endif
1505
1506 *frame_x = hpos;
1507 *frame_y = vpos;
1508 return 1;
1509}
1510
1511
1405#ifdef HAVE_WINDOW_SYSTEM 1512#ifdef HAVE_WINDOW_SYSTEM
1406 1513
1407/* Find the glyph under window-relative coordinates X/Y in window W. 1514/* Find the glyph under window-relative coordinates X/Y in window W.
diff --git a/src/xterm.c b/src/xterm.c
index b4fdd5c360e..c8baf8ffe35 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -3474,99 +3474,6 @@ x_get_keysym_name (keysym)
3474 3474
3475/* Mouse clicks and mouse movement. Rah. */ 3475/* Mouse clicks and mouse movement. Rah. */
3476 3476
3477/* Given a pixel position (PIX_X, PIX_Y) on frame F, return glyph
3478 co-ordinates in (*X, *Y). Set *BOUNDS to the rectangle that the
3479 glyph at X, Y occupies, if BOUNDS != 0. If NOCLIP is non-zero, do
3480 not force the value into range. */
3481
3482void
3483pixel_to_glyph_coords (f, pix_x, pix_y, x, y, bounds, noclip)
3484 FRAME_PTR f;
3485 register int pix_x, pix_y;
3486 register int *x, *y;
3487 XRectangle *bounds;
3488 int noclip;
3489{
3490 /* Arrange for the division in PIXEL_TO_CHAR_COL etc. to round down
3491 even for negative values. */
3492 if (pix_x < 0)
3493 pix_x -= FONT_WIDTH ((f)->output_data.x->font) - 1;
3494 if (pix_y < 0)
3495 pix_y -= (f)->output_data.x->line_height - 1;
3496
3497 pix_x = PIXEL_TO_CHAR_COL (f, pix_x);
3498 pix_y = PIXEL_TO_CHAR_ROW (f, pix_y);
3499
3500 if (bounds)
3501 {
3502 bounds->width = FONT_WIDTH (f->output_data.x->font);
3503 bounds->height = f->output_data.x->line_height;
3504 bounds->x = CHAR_TO_PIXEL_COL (f, pix_x);
3505 bounds->y = CHAR_TO_PIXEL_ROW (f, pix_y);
3506 }
3507
3508 if (!noclip)
3509 {
3510 if (pix_x < 0)
3511 pix_x = 0;
3512 else if (pix_x > FRAME_WINDOW_WIDTH (f))
3513 pix_x = FRAME_WINDOW_WIDTH (f);
3514
3515 if (pix_y < 0)
3516 pix_y = 0;
3517 else if (pix_y > f->height)
3518 pix_y = f->height;
3519 }
3520
3521 *x = pix_x;
3522 *y = pix_y;
3523}
3524
3525
3526/* Given HPOS/VPOS in the current matrix of W, return corresponding
3527 frame-relative pixel positions in *FRAME_X and *FRAME_Y. If we
3528 can't tell the positions because W's display is not up to date,
3529 return 0. */
3530
3531int
3532glyph_to_pixel_coords (w, hpos, vpos, frame_x, frame_y)
3533 struct window *w;
3534 int hpos, vpos;
3535 int *frame_x, *frame_y;
3536{
3537 int success_p;
3538
3539 xassert (hpos >= 0 && hpos < w->current_matrix->matrix_w);
3540 xassert (vpos >= 0 && vpos < w->current_matrix->matrix_h);
3541
3542 if (display_completed)
3543 {
3544 struct glyph_row *row = MATRIX_ROW (w->current_matrix, vpos);
3545 struct glyph *glyph = row->glyphs[TEXT_AREA];
3546 struct glyph *end = glyph + min (hpos, row->used[TEXT_AREA]);
3547
3548 *frame_y = row->y;
3549 *frame_x = row->x;
3550 while (glyph < end)
3551 {
3552 *frame_x += glyph->pixel_width;
3553 ++glyph;
3554 }
3555
3556 success_p = 1;
3557 }
3558 else
3559 {
3560 *frame_y = *frame_x = 0;
3561 success_p = 0;
3562 }
3563
3564 *frame_y = WINDOW_TO_FRAME_PIXEL_Y (w, *frame_y);
3565 *frame_x = WINDOW_TO_FRAME_PIXEL_X (w, *frame_x);
3566 return success_p;
3567}
3568
3569
3570/* Prepare a mouse-event in *RESULT for placement in the input queue. 3477/* Prepare a mouse-event in *RESULT for placement in the input queue.
3571 3478
3572 If the event is a button press, then note that we have grabbed 3479 If the event is a button press, then note that we have grabbed