Mercurial > emacs
comparison src/xmenu.c @ 49302:17a9a82ad89f
(mouse_position_for_popup): New function.
(Fx_popup_menu): Call mouse_position_for_popup for X and
mouse_position_hook for others.
author | Jan Djärv <jan.h.d@swipnet.se> |
---|---|
date | Sat, 18 Jan 2003 09:55:37 +0000 |
parents | 8c37b25a7f02 |
children | 2cbb0b823e83 |
comparison
equal
deleted
inserted
replaced
49301:8d203a2bfdef | 49302:17a9a82ad89f |
---|---|
667 push_menu_item (item1, Qt, Fcdr (item), Qt, Qnil, Qnil, Qnil, Qnil); | 667 push_menu_item (item1, Qt, Fcdr (item), Qt, Qnil, Qnil, Qnil, Qnil); |
668 } | 668 } |
669 } | 669 } |
670 } | 670 } |
671 | 671 |
672 #ifdef HAVE_X_WINDOWS | |
673 /* Return the mouse position in *X and *Y. The coordinates are window | |
674 relative for the edit window in frame F. | |
675 This is for Fx_popup_menu. The mouse_position_hook can not | |
676 be used for X, as it returns window relative coordinates | |
677 for the window where the mouse is in. This could be the menu bar, | |
678 the scroll bar or the edit window. Fx_popup_menu needs to be | |
679 sure it is the edit window. */ | |
680 static void | |
681 mouse_position_for_popup(f, x, y) | |
682 FRAME_PTR f; | |
683 int *x; | |
684 int *y; | |
685 { | |
686 Window root, dummy_window; | |
687 int dummy; | |
688 | |
689 BLOCK_INPUT; | |
690 | |
691 XQueryPointer (FRAME_X_DISPLAY (f), | |
692 DefaultRootWindow (FRAME_X_DISPLAY (f)), | |
693 | |
694 /* The root window which contains the pointer. */ | |
695 &root, | |
696 | |
697 /* Window pointer is on, not used */ | |
698 &dummy_window, | |
699 | |
700 /* The position on that root window. */ | |
701 x, y, | |
702 | |
703 /* x/y in dummy_window coordinates, not used. */ | |
704 &dummy, &dummy, | |
705 | |
706 /* Modifier keys and pointer buttons, about which | |
707 we don't care. */ | |
708 (unsigned int *) &dummy); | |
709 | |
710 UNBLOCK_INPUT; | |
711 | |
712 /* xmenu_show expects window coordinates, not root window | |
713 coordinates. Translate. */ | |
714 *x -= f->output_data.x->left_pos | |
715 + FRAME_OUTER_TO_INNER_DIFF_X (f); | |
716 *y -= f->output_data.x->top_pos | |
717 + FRAME_OUTER_TO_INNER_DIFF_Y (f); | |
718 } | |
719 | |
720 #endif /* HAVE_X_WINDOWS */ | |
721 | |
672 DEFUN ("x-popup-menu", Fx_popup_menu, Sx_popup_menu, 2, 2, 0, | 722 DEFUN ("x-popup-menu", Fx_popup_menu, Sx_popup_menu, 2, 2, 0, |
673 doc: /* Pop up a deck-of-cards menu and return user's selection. | 723 doc: /* Pop up a deck-of-cards menu and return user's selection. |
674 POSITION is a position specification. This is either a mouse button event | 724 POSITION is a position specification. This is either a mouse button event |
675 or a list ((XOFFSET YOFFSET) WINDOW) | 725 or a list ((XOFFSET YOFFSET) WINDOW) |
676 where XOFFSET and YOFFSET are positions in pixels from the top left | 726 where XOFFSET and YOFFSET are positions in pixels from the top left |
728 || (CONSP (position) && (EQ (XCAR (position), Qmenu_bar) | 778 || (CONSP (position) && (EQ (XCAR (position), Qmenu_bar) |
729 || EQ (XCAR (position), Qtool_bar)))) | 779 || EQ (XCAR (position), Qtool_bar)))) |
730 { | 780 { |
731 /* Use the mouse's current position. */ | 781 /* Use the mouse's current position. */ |
732 FRAME_PTR new_f = SELECTED_FRAME (); | 782 FRAME_PTR new_f = SELECTED_FRAME (); |
733 Window root, dummy_window; | 783 #ifdef HAVE_X_WINDOWS |
734 int cur_x, cur_y, dummy; | 784 /* Can't use mouse_position_hook for X since it returns |
735 | 785 coordinates relative to the window the mouse is in, |
736 BLOCK_INPUT; | 786 we need coordinates relative to the edit widget always. */ |
787 if (new_f != 0) | |
788 { | |
789 int cur_x, cur_y; | |
790 | |
791 mouse_position_for_popup (new_f, &cur_x, &cur_y); | |
792 /* cur_x/y may be negative, so use make_number. */ | |
793 x = make_number (cur_x); | |
794 y = make_number (cur_y); | |
795 } | |
737 | 796 |
738 XQueryPointer (FRAME_X_DISPLAY (new_f), | 797 #else /* not HAVE_X_WINDOWS */ |
739 DefaultRootWindow (FRAME_X_DISPLAY (new_f)), | 798 Lisp_Object bar_window; |
740 | 799 enum scroll_bar_part part; |
741 /* The root window which contains the pointer. */ | 800 unsigned long time; |
742 &root, | 801 |
743 | 802 if (mouse_position_hook) |
744 /* Window pointer is on, not used */ | 803 (*mouse_position_hook) (&new_f, 1, &bar_window, |
745 &dummy_window, | 804 &part, &x, &y, &time); |
746 | 805 #endif /* not HAVE_X_WINDOWS */ |
747 /* The position on that root window. */ | 806 |
748 &cur_x, &cur_y, | 807 if (new_f != 0) |
749 | 808 XSETFRAME (window, new_f); |
750 /* x/y in dummy_window coordinates, not used. */ | 809 else |
751 &dummy, &dummy, | 810 { |
752 | 811 window = selected_window; |
753 /* Modifier keys and pointer buttons, about which | 812 XSETFASTINT (x, 0); |
754 we don't care. */ | 813 XSETFASTINT (y, 0); |
755 (unsigned int *) &dummy); | 814 } |
756 | |
757 UNBLOCK_INPUT; | |
758 | |
759 /* xmenu_show expects window coordinates, not root window | |
760 coordinates. Translate. */ | |
761 cur_x -= new_f->output_data.x->left_pos | |
762 + FRAME_OUTER_TO_INNER_DIFF_X (new_f); | |
763 cur_y -= new_f->output_data.x->top_pos | |
764 + FRAME_OUTER_TO_INNER_DIFF_Y (new_f); | |
765 | |
766 /* cur_x/y may be negative, so use make_number. */ | |
767 x = make_number (cur_x); | |
768 y = make_number (cur_y); | |
769 | |
770 XSETFRAME (window, new_f); | |
771 } | 815 } |
772 else | 816 else |
773 { | 817 { |
774 tem = Fcar (position); | 818 tem = Fcar (position); |
775 if (CONSP (tem)) | 819 if (CONSP (tem)) |