diff options
| author | Richard M. Stallman | 1994-03-20 07:05:38 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-03-20 07:05:38 +0000 |
| commit | 99fe880dc3e3e7d03db81657b76db196f9f2acfd (patch) | |
| tree | 71206b600b8358450d8505cb09f3cd0b5193cd61 /src | |
| parent | 6f4387dde1fb5ec85af13b1beb91ff525aedc4d6 (diff) | |
| download | emacs-99fe880dc3e3e7d03db81657b76db196f9f2acfd.tar.gz emacs-99fe880dc3e3e7d03db81657b76db196f9f2acfd.zip | |
(xdialog_show): Delete args x, y.
(Fx_popup_dialog): Don't pass those args; don't compute them.
Second arg is now just one pane. Lots of simplification.
Always start by decoding POSITION arg to get a frame.
[! USE_X_TOOLKIT]: Put the menu in middle of that frame.
Diffstat (limited to 'src')
| -rw-r--r-- | src/xmenu.c | 218 |
1 files changed, 77 insertions, 141 deletions
diff --git a/src/xmenu.c b/src/xmenu.c index 4a8fb70d221..354bf778f01 100644 --- a/src/xmenu.c +++ b/src/xmenu.c | |||
| @@ -836,166 +836,104 @@ cached information about equivalent key sequences.") | |||
| 836 | 836 | ||
| 837 | DEFUN ("x-popup-dialog", Fx_popup_dialog, Sx_popup_dialog, 2, 2, 0, | 837 | DEFUN ("x-popup-dialog", Fx_popup_dialog, Sx_popup_dialog, 2, 2, 0, |
| 838 | "Pop up a dialog box and return user's selection.\n\ | 838 | "Pop up a dialog box and return user's selection.\n\ |
| 839 | POSITION is a position specification. This is either a mouse button event\n\ | 839 | POSITION specifies which frame to use.\n\ |
| 840 | or a list ((XOFFSET YOFFSET) WINDOW)\n\ | 840 | This is normally a mouse button event or a window or frame.\n\ |
| 841 | where XOFFSET and YOFFSET are positions in characters from the top left\n\ | 841 | If POSITION is t, it means to use the frame the mouse is on.\n\ |
| 842 | corner of WINDOW's frame. (WINDOW may be a frame object instead of a window.)\n\ | 842 | The dialog box appears in the middle of the specified frame.\n\ |
| 843 | This controls the position of the center of the first line\n\ | ||
| 844 | in the first pane of the menu, not the top left of the menu as a whole.\n\ | ||
| 845 | If POSITION is t, it means to use the current mouse position.\n\ | ||
| 846 | \n\ | ||
| 847 | MENU is a specifier for a menu. For the simplest case, MENU is a keymap.\n\ | ||
| 848 | The menu items come from key bindings that have a menu string as well as\n\ | ||
| 849 | a definition; actually, the \"definition\" in such a key binding looks like\n\ | ||
| 850 | \(STRING . REAL-DEFINITION). To give the menu a title, put a string into\n\ | ||
| 851 | the keymap as a top-level element.\n\n\ | ||
| 852 | You can also use a list of keymaps as MENU.\n\ | ||
| 853 | Then each keymap makes a separate pane.\n\ | ||
| 854 | When MENU is a keymap or a list of keymaps, the return value\n\ | ||
| 855 | is a list of events.\n\n\ | ||
| 856 | Alternatively, you can specify a menu of multiple panes\n\ | ||
| 857 | with a list of the form (TITLE PANE),\n\ | ||
| 858 | where PANE is a list of form (TITLE ITEM1 ITEM2...).\n\ | ||
| 859 | Each ITEM is normally a cons cell (STRING . VALUE);\n\ | ||
| 860 | but a string can appear as an item--that makes a nonselectable line\n\ | ||
| 861 | in the menu.\n\ | ||
| 862 | Dialog boxes do not support multiple panes.\n\ | ||
| 863 | With this form of menu, the return value is VALUE from the chosen item.\n\ | ||
| 864 | \n\ | 843 | \n\ |
| 865 | If POSITION is nil, don't display the menu at all, just precalculate the\n\ | 844 | CONTENTS specifies the alternatives to display in the dialog box.\n\ |
| 866 | cached information about equivalent key sequences.") | 845 | It is a list of the form (TITLE ITEM1 ITEM2...).\n\ |
| 867 | (position, menu) | 846 | Each ITEM is a cons cell (STRING . VALUE).\n\ |
| 868 | Lisp_Object position, menu; | 847 | The return value is VALUE from the chosen item.") |
| 848 | (position, contents) | ||
| 849 | Lisp_Object position, contents; | ||
| 869 | { | 850 | { |
| 870 | #ifndef USE_X_TOOLKIT | ||
| 871 | return Fx_popup_menu (position, menu); | ||
| 872 | #else | ||
| 873 | int number_of_panes, panes; | ||
| 874 | Lisp_Object keymap, tem; | ||
| 875 | int xpos, ypos; | ||
| 876 | Lisp_Object title; | ||
| 877 | char *error_name; | ||
| 878 | Lisp_Object selection; | ||
| 879 | int i, j; | ||
| 880 | FRAME_PTR f; | 851 | FRAME_PTR f; |
| 881 | Lisp_Object x, y, window; | 852 | Lisp_Object window; |
| 882 | int keymaps = 0; | ||
| 883 | int menubarp = 0; | ||
| 884 | struct gcpro gcpro1; | ||
| 885 | 853 | ||
| 886 | check_x (); | 854 | check_x (); |
| 887 | 855 | ||
| 888 | if (! NILP (position)) | 856 | /* Decode the first argument: find the window or frame to use. */ |
| 857 | if (EQ (position, Qt)) | ||
| 889 | { | 858 | { |
| 890 | /* Decode the first argument: find the window and the coordinates. */ | 859 | /* Use the mouse's current position. */ |
| 891 | if (EQ (position, Qt)) | 860 | FRAME_PTR new_f = 0; |
| 892 | { | 861 | Lisp_Object bar_window; |
| 893 | /* Use the mouse's current position. */ | 862 | int part; |
| 894 | FRAME_PTR new_f = 0; | 863 | unsigned long time; |
| 895 | Lisp_Object bar_window; | 864 | Lisp_Object x, y; |
| 896 | int part; | ||
| 897 | unsigned long time; | ||
| 898 | 865 | ||
| 899 | (*mouse_position_hook) (&new_f, &bar_window, &part, &x, &y, &time); | 866 | (*mouse_position_hook) (&new_f, &bar_window, &part, &x, &y, &time); |
| 900 | 867 | ||
| 901 | if (new_f != 0) | 868 | if (new_f != 0) |
| 902 | XSET (window, Lisp_Frame, new_f); | 869 | XSET (window, Lisp_Frame, new_f); |
| 903 | else | 870 | else |
| 904 | { | 871 | window = selected_window; |
| 905 | window = selected_window; | 872 | } |
| 906 | XFASTINT (x) = 0; | 873 | else if (CONSP (position)) |
| 907 | XFASTINT (y) = 0; | 874 | { |
| 908 | } | 875 | Lisp_Object tem; |
| 909 | } | 876 | tem = Fcar (position); |
| 877 | if (XTYPE (tem) == Lisp_Cons) | ||
| 878 | window = Fcar (Fcdr (position)); | ||
| 910 | else | 879 | else |
| 911 | { | 880 | { |
| 912 | tem = Fcar (position); | 881 | tem = Fcar (Fcdr (position)); /* EVENT_START (position) */ |
| 913 | if (XTYPE (tem) == Lisp_Cons) | 882 | window = Fcar (tem); /* POSN_WINDOW (tem) */ |
| 914 | { | ||
| 915 | window = Fcar (Fcdr (position)); | ||
| 916 | x = Fcar (tem); | ||
| 917 | y = Fcar (Fcdr (tem)); | ||
| 918 | } | ||
| 919 | else | ||
| 920 | { | ||
| 921 | tem = Fcar (Fcdr (position)); /* EVENT_START (position) */ | ||
| 922 | window = Fcar (tem); /* POSN_WINDOW (tem) */ | ||
| 923 | tem = Fcar (Fcdr (Fcdr (tem))); /* POSN_WINDOW_POSN (tem) */ | ||
| 924 | x = Fcar (tem); | ||
| 925 | y = Fcdr (tem); | ||
| 926 | |||
| 927 | /* Determine whether this menu is handling a menu bar click. */ | ||
| 928 | tem = Fcar (Fcdr (Fcar (Fcdr (position)))); | ||
| 929 | if (XTYPE (Fcar (position)) != Lisp_Cons | ||
| 930 | && CONSP (tem) | ||
| 931 | && EQ (Fcar (tem), Qmenu_bar)) | ||
| 932 | menubarp = 1; | ||
| 933 | } | ||
| 934 | } | ||
| 935 | |||
| 936 | CHECK_NUMBER (x, 0); | ||
| 937 | CHECK_NUMBER (y, 0); | ||
| 938 | |||
| 939 | /* Decode where to put the menu. */ | ||
| 940 | |||
| 941 | if (XTYPE (window) == Lisp_Frame) | ||
| 942 | { | ||
| 943 | f = XFRAME (window); | ||
| 944 | |||
| 945 | xpos = 0; | ||
| 946 | ypos = 0; | ||
| 947 | } | ||
| 948 | else if (XTYPE (window) == Lisp_Window) | ||
| 949 | { | ||
| 950 | CHECK_LIVE_WINDOW (window, 0); | ||
| 951 | f = XFRAME (WINDOW_FRAME (XWINDOW (window))); | ||
| 952 | |||
| 953 | xpos = (FONT_WIDTH (f->display.x->font) * XWINDOW (window)->left); | ||
| 954 | ypos = (FONT_HEIGHT (f->display.x->font) * XWINDOW (window)->top); | ||
| 955 | } | 883 | } |
| 956 | else | ||
| 957 | /* ??? Not really clean; should be CHECK_WINDOW_OR_FRAME, | ||
| 958 | but I don't want to make one now. */ | ||
| 959 | CHECK_WINDOW (window, 0); | ||
| 960 | |||
| 961 | xpos += XINT (x); | ||
| 962 | ypos += XINT (y); | ||
| 963 | } | 884 | } |
| 885 | else if (WINDOWP (position) || FRAMEP (position)) | ||
| 886 | window = position; | ||
| 964 | 887 | ||
| 965 | title = Qnil; | 888 | /* Decode where to put the menu. */ |
| 966 | GCPRO1 (title); | ||
| 967 | 889 | ||
| 968 | /* Decode the dialog items from what was specified. */ | 890 | if (XTYPE (window) == Lisp_Frame) |
| 891 | f = XFRAME (window); | ||
| 892 | else if (XTYPE (window) == Lisp_Window) | ||
| 969 | { | 893 | { |
| 970 | /* We were given an old-fashioned menu. */ | 894 | CHECK_LIVE_WINDOW (window, 0); |
| 971 | title = Fcar (menu); | 895 | f = XFRAME (WINDOW_FRAME (XWINDOW (window))); |
| 972 | CHECK_STRING (title, 1); | ||
| 973 | |||
| 974 | list_of_panes (Fcdr (menu)); | ||
| 975 | |||
| 976 | keymaps = 0; | ||
| 977 | } | ||
| 978 | |||
| 979 | if (NILP (position)) | ||
| 980 | { | ||
| 981 | discard_menu_items (); | ||
| 982 | UNGCPRO; | ||
| 983 | return Qnil; | ||
| 984 | } | 896 | } |
| 897 | else | ||
| 898 | /* ??? Not really clean; should be CHECK_WINDOW_OR_FRAME, | ||
| 899 | but I don't want to make one now. */ | ||
| 900 | CHECK_WINDOW (window, 0); | ||
| 985 | 901 | ||
| 986 | /* Display them in a dialog box. */ | 902 | #ifndef USE_X_TOOLKIT |
| 987 | BLOCK_INPUT; | 903 | /* Display a menu with these alternatives |
| 904 | in the middle of frame F. */ | ||
| 905 | { | ||
| 906 | Lisp_Object x, y, frame, newpos; | ||
| 907 | XSET (frame, Lisp_Frame, f); | ||
| 908 | XSET (x, Lisp_Int, x_pixel_width (f) / 2); | ||
| 909 | XSET (y, Lisp_Int, x_pixel_height (f) / 2); | ||
| 910 | newpos = Fcons (Fcons (x, Fcons (y, Qnil)), Fcons (frame, Qnil)); | ||
| 911 | |||
| 912 | return Fx_popup_menu (newpos, | ||
| 913 | Fcons (Fcar (contents), Fcons (contents, Qnil))); | ||
| 914 | } | ||
| 915 | #else | ||
| 916 | { | ||
| 917 | Lisp_Object title; | ||
| 918 | char *error_name; | ||
| 919 | Lisp_Object selection; | ||
| 988 | 920 | ||
| 989 | selection = xdialog_show (f, xpos, ypos, menubarp, | 921 | /* Decode the dialog items from what was specified. */ |
| 990 | keymaps, title, &error_name); | 922 | title = Fcar (contents); |
| 991 | UNBLOCK_INPUT; | 923 | CHECK_STRING (title, 1); |
| 992 | 924 | ||
| 993 | discard_menu_items (); | 925 | list_of_panes (Fcons (contents, Qnil)); |
| 994 | 926 | ||
| 995 | UNGCPRO; | 927 | /* Display them in a dialog box. */ |
| 928 | BLOCK_INPUT; | ||
| 929 | selection = xdialog_show (f, 0, 0, title, &error_name); | ||
| 930 | UNBLOCK_INPUT; | ||
| 996 | 931 | ||
| 997 | if (error_name) error (error_name); | 932 | discard_menu_items (); |
| 998 | return selection; | 933 | |
| 934 | if (error_name) error (error_name); | ||
| 935 | return selection; | ||
| 936 | } | ||
| 999 | #endif | 937 | #endif |
| 1000 | } | 938 | } |
| 1001 | 939 | ||
| @@ -1753,10 +1691,8 @@ static char * button_names [] = { | |||
| 1753 | "button6", "button7", "button8", "button9", "button10" }; | 1691 | "button6", "button7", "button8", "button9", "button10" }; |
| 1754 | 1692 | ||
| 1755 | static Lisp_Object | 1693 | static Lisp_Object |
| 1756 | xdialog_show (f, x, y, menubarp, keymaps, title, error) | 1694 | xdialog_show (f, menubarp, keymaps, title, error) |
| 1757 | FRAME_PTR f; | 1695 | FRAME_PTR f; |
| 1758 | int x; | ||
| 1759 | int y; | ||
| 1760 | int menubarp; | 1696 | int menubarp; |
| 1761 | int keymaps; | 1697 | int keymaps; |
| 1762 | Lisp_Object title; | 1698 | Lisp_Object title; |