Mercurial > emacs
annotate src/xmenu.c @ 2152:078737073080
Comment fix.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Fri, 12 Mar 1993 06:27:05 +0000 |
parents | 1b6e54507323 |
children | 42ceb87b43a1 |
rev | line source |
---|---|
118 | 1 /* X Communication module for terminals which understand the X protocol. |
1437
36ef55ecb265
* frame.c (make_frame_without_minibuffer, Fwindow_frame): Use
Jim Blandy <jimb@redhat.com>
parents:
1304
diff
changeset
|
2 Copyright (C) 1986, 1988, 1992 Free Software Foundation, Inc. |
118 | 3 |
4 This file is part of GNU Emacs. | |
5 | |
6 GNU Emacs is free software; you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
1437
36ef55ecb265
* frame.c (make_frame_without_minibuffer, Fwindow_frame): Use
Jim Blandy <jimb@redhat.com>
parents:
1304
diff
changeset
|
8 the Free Software Foundation; either version 2, or (at your option) |
118 | 9 any later version. |
10 | |
11 GNU Emacs is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with GNU Emacs; see the file COPYING. If not, write to | |
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | |
20 /* X pop-up deck-of-cards menu facility for gnuemacs. | |
21 * | |
22 * Written by Jon Arnold and Roman Budzianowski | |
23 * Mods and rewrite by Robert Krawitz | |
24 * | |
25 */ | |
26 | |
27 #ifdef XDEBUG | |
28 #include <stdio.h> | |
29 #endif | |
30 | |
31 /* On 4.3 this loses if it comes after xterm.h. */ | |
32 #include <signal.h> | |
33 #include "config.h" | |
34 #include "lisp.h" | |
770 | 35 #include "frame.h" |
118 | 36 #include "window.h" |
1304
93d55019750e
* xmenu.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1213
diff
changeset
|
37 #include "keyboard.h" |
118 | 38 |
39 /* This may include sys/types.h, and that somehow loses | |
40 if this is not done before the other system files. */ | |
41 #include "xterm.h" | |
42 | |
43 /* Load sys/types.h if not already loaded. | |
44 In some systems loading it twice is suicidal. */ | |
45 #ifndef makedev | |
46 #include <sys/types.h> | |
47 #endif | |
48 | |
49 #include "dispextern.h" | |
50 | |
51 #ifdef HAVE_X11 | |
52 #include "../oldXMenu/XMenu.h" | |
53 #else | |
54 #include <X/XMenu.h> | |
55 #endif | |
56 | |
57 #define min(x,y) (((x) < (y)) ? (x) : (y)) | |
58 #define max(x,y) (((x) > (y)) ? (x) : (y)) | |
59 | |
60 #define NUL 0 | |
61 | |
62 #ifndef TRUE | |
63 #define TRUE 1 | |
64 #define FALSE 0 | |
65 #endif TRUE | |
66 | |
67 #ifdef HAVE_X11 | |
68 extern Display *x_current_display; | |
69 #else | |
70 #define ButtonReleaseMask ButtonReleased | |
71 #endif /* not HAVE_X11 */ | |
72 | |
2135
0634d08c28d1
(syms_of_xmenu): Set up Qmenu_enable.
Richard M. Stallman <rms@gnu.org>
parents:
1933
diff
changeset
|
73 Lisp_Object Qmenu_enable; |
118 | 74 Lisp_Object xmenu_show (); |
75 extern int x_error_handler (); | |
76 | |
77 /*************************************************************/ | |
78 | |
79 #if 0 | |
80 /* Ignoring the args is easiest. */ | |
81 xmenu_quit () | |
82 { | |
83 error ("Unknown XMenu error"); | |
84 } | |
85 #endif | |
86 | |
87 DEFUN ("x-popup-menu",Fx_popup_menu, Sx_popup_menu, 1, 2, 0, | |
88 "Pop up a deck-of-cards menu and return user's selection.\n\ | |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
89 POSITION is a position specification. This is either a mouse button event\n\ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
90 or a list ((XOFFSET YOFFSET) WINDOW)\n\ |
118 | 91 where XOFFSET and YOFFSET are positions in characters from the top left\n\ |
2147
1b6e54507323
(Fx_popup_menu): Allow a frame instead of a window, in arg.
Richard M. Stallman <rms@gnu.org>
parents:
2135
diff
changeset
|
92 corner of WINDOW's frame. (WINDOW may be a frame object instead of a window.)\n\ |
118 | 93 This controls the position of the center of the first line\n\ |
94 in the first pane of the menu, not the top left of the menu as a whole.\n\ | |
95 \n\ | |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
96 MENU is a specifier for a menu. For the simplest case, MENU is a keymap.\n\ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
97 The menu items come from key bindings that have a menu string as well as\n\ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
98 a definition; actually, the \"definition\" in such a key binding looks like\n\ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
99 \(STRING . REAL-DEFINITION). To give the menu a title, put a string into\n\ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
100 the keymap as a top-level element.\n\n\ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
101 You can also use a list of keymaps as MENU.\n\ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
102 Then each keymap makes a separate pane.\n\n\ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
103 Alternatively, you can specify a menu of multiple panes\n\ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
104 with a list of the form\n\ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
105 \(TITLE PANE1 PANE2...), where each pane is a list of form\n\ |
118 | 106 \(TITLE (LINE ITEM)...). Each line should be a string, and item should\n\ |
1821
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1437
diff
changeset
|
107 be the return value for that line (i.e. if it is selected).") |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
108 (position, menu) |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
109 Lisp_Object position, menu; |
118 | 110 { |
111 int number_of_panes; | |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
112 Lisp_Object XMenu_return, keymap, tem; |
118 | 113 int XMenu_xpos, XMenu_ypos; |
114 char **menus; | |
115 char ***names; | |
116 Lisp_Object **obj_list; | |
117 int *items; | |
118 char *title; | |
119 char *error_name; | |
120 Lisp_Object ltitle, selection; | |
121 int i, j; | |
770 | 122 FRAME_PTR f; |
118 | 123 Lisp_Object x, y, window; |
124 | |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
125 /* Decode the first argument: find the window and the coordinates. */ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
126 tem = Fcar (position); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
127 if (XTYPE (tem) == Lisp_Cons) |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
128 { |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
129 window = Fcar (Fcdr (position)); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
130 x = Fcar (tem); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
131 y = Fcar (Fcdr (tem)); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
132 } |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
133 else |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
134 { |
1304
93d55019750e
* xmenu.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1213
diff
changeset
|
135 tem = EVENT_START (position); |
93d55019750e
* xmenu.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1213
diff
changeset
|
136 window = POSN_WINDOW (tem); |
93d55019750e
* xmenu.c: #include "keyboard.h".
Jim Blandy <jimb@redhat.com>
parents:
1213
diff
changeset
|
137 tem = POSN_WINDOW_POSN (tem); |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
138 x = Fcar (tem); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
139 y = Fcdr (tem); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
140 } |
118 | 141 CHECK_NUMBER (x, 0); |
142 CHECK_NUMBER (y, 0); | |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
143 |
2147
1b6e54507323
(Fx_popup_menu): Allow a frame instead of a window, in arg.
Richard M. Stallman <rms@gnu.org>
parents:
2135
diff
changeset
|
144 if (XTYPE (window) == Lisp_Frame) |
1b6e54507323
(Fx_popup_menu): Allow a frame instead of a window, in arg.
Richard M. Stallman <rms@gnu.org>
parents:
2135
diff
changeset
|
145 { |
1b6e54507323
(Fx_popup_menu): Allow a frame instead of a window, in arg.
Richard M. Stallman <rms@gnu.org>
parents:
2135
diff
changeset
|
146 f = XFRAME (window); |
118 | 147 |
2147
1b6e54507323
(Fx_popup_menu): Allow a frame instead of a window, in arg.
Richard M. Stallman <rms@gnu.org>
parents:
2135
diff
changeset
|
148 XMenu_xpos = 0; |
1b6e54507323
(Fx_popup_menu): Allow a frame instead of a window, in arg.
Richard M. Stallman <rms@gnu.org>
parents:
2135
diff
changeset
|
149 XMenu_ypos = 0; |
1b6e54507323
(Fx_popup_menu): Allow a frame instead of a window, in arg.
Richard M. Stallman <rms@gnu.org>
parents:
2135
diff
changeset
|
150 } |
1b6e54507323
(Fx_popup_menu): Allow a frame instead of a window, in arg.
Richard M. Stallman <rms@gnu.org>
parents:
2135
diff
changeset
|
151 else if (XTYPE (window) == Lisp_Window) |
1b6e54507323
(Fx_popup_menu): Allow a frame instead of a window, in arg.
Richard M. Stallman <rms@gnu.org>
parents:
2135
diff
changeset
|
152 { |
1b6e54507323
(Fx_popup_menu): Allow a frame instead of a window, in arg.
Richard M. Stallman <rms@gnu.org>
parents:
2135
diff
changeset
|
153 CHECK_LIVE_WINDOW (window, 0); |
1b6e54507323
(Fx_popup_menu): Allow a frame instead of a window, in arg.
Richard M. Stallman <rms@gnu.org>
parents:
2135
diff
changeset
|
154 f = XFRAME (WINDOW_FRAME (XWINDOW (window))); |
1b6e54507323
(Fx_popup_menu): Allow a frame instead of a window, in arg.
Richard M. Stallman <rms@gnu.org>
parents:
2135
diff
changeset
|
155 |
1b6e54507323
(Fx_popup_menu): Allow a frame instead of a window, in arg.
Richard M. Stallman <rms@gnu.org>
parents:
2135
diff
changeset
|
156 XMenu_xpos = FONT_WIDTH (f->display.x->font) * XWINDOW (window)->left; |
1b6e54507323
(Fx_popup_menu): Allow a frame instead of a window, in arg.
Richard M. Stallman <rms@gnu.org>
parents:
2135
diff
changeset
|
157 XMenu_ypos = FONT_HEIGHT (f->display.x->font) * XWINDOW (window)->top; |
1b6e54507323
(Fx_popup_menu): Allow a frame instead of a window, in arg.
Richard M. Stallman <rms@gnu.org>
parents:
2135
diff
changeset
|
158 } |
1b6e54507323
(Fx_popup_menu): Allow a frame instead of a window, in arg.
Richard M. Stallman <rms@gnu.org>
parents:
2135
diff
changeset
|
159 |
1b6e54507323
(Fx_popup_menu): Allow a frame instead of a window, in arg.
Richard M. Stallman <rms@gnu.org>
parents:
2135
diff
changeset
|
160 XMenu_xpos += FONT_WIDTH (f->display.x->font) * XINT (x); |
1b6e54507323
(Fx_popup_menu): Allow a frame instead of a window, in arg.
Richard M. Stallman <rms@gnu.org>
parents:
2135
diff
changeset
|
161 XMenu_ypos += FONT_HEIGHT (f->display.x->font) * XINT (y); |
1b6e54507323
(Fx_popup_menu): Allow a frame instead of a window, in arg.
Richard M. Stallman <rms@gnu.org>
parents:
2135
diff
changeset
|
162 |
770 | 163 XMenu_xpos += f->display.x->left_pos; |
164 XMenu_ypos += f->display.x->top_pos; | |
118 | 165 |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
166 keymap = Fkeymapp (menu); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
167 tem = Qnil; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
168 if (XTYPE (menu) == Lisp_Cons) |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
169 tem = Fkeymapp (Fcar (menu)); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
170 if (!NILP (keymap)) |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
171 { |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
172 /* We were given a keymap. Extract menu info from the keymap. */ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
173 Lisp_Object prompt; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
174 keymap = get_keymap (menu); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
175 |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
176 /* Search for a string appearing directly as an element of the keymap. |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
177 That string is the title of the menu. */ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
178 prompt = map_prompt (keymap); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
179 if (!NILP (prompt)) |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
180 title = (char *) XSTRING (prompt)->data; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
181 |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
182 /* Extract the detailed info to make one pane. */ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
183 number_of_panes = keymap_panes (&obj_list, &menus, &names, &items, |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
184 &menu, 1); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
185 /* The menu title seems to be ignored, |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
186 so put it in the pane title. */ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
187 if (menus[0] == 0) |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
188 menus[0] = title; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
189 } |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
190 else if (!NILP (tem)) |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
191 { |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
192 /* We were given a list of keymaps. */ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
193 Lisp_Object prompt; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
194 int nmaps = XFASTINT (Flength (menu)); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
195 Lisp_Object *maps |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
196 = (Lisp_Object *) alloca (nmaps * sizeof (Lisp_Object)); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
197 int i; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
198 title = 0; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
199 |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
200 /* The first keymap that has a prompt string |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
201 supplies the menu title. */ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
202 for (tem = menu, i = 0; XTYPE (tem) == Lisp_Cons; tem = Fcdr (tem)) |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
203 { |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
204 maps[i++] = keymap = get_keymap (Fcar (tem)); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
205 |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
206 prompt = map_prompt (keymap); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
207 if (title == 0 && !NILP (prompt)) |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
208 title = (char *) XSTRING (prompt)->data; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
209 } |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
210 |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
211 /* Extract the detailed info to make one pane. */ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
212 number_of_panes = keymap_panes (&obj_list, &menus, &names, &items, |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
213 maps, nmaps); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
214 /* The menu title seems to be ignored, |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
215 so put it in the pane title. */ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
216 if (menus[0] == 0) |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
217 menus[0] = title; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
218 } |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
219 else |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
220 { |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
221 /* We were given an old-fashioned menu. */ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
222 ltitle = Fcar (menu); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
223 CHECK_STRING (ltitle, 1); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
224 title = (char *) XSTRING (ltitle)->data; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
225 number_of_panes = list_of_panes (&obj_list, &menus, &names, &items, |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
226 Fcdr (menu)); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
227 } |
118 | 228 #ifdef XDEBUG |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
229 fprintf (stderr, "Panes = %d\n", number_of_panes); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
230 for (i = 0; i < number_of_panes; i++) |
118 | 231 { |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
232 fprintf (stderr, "Pane %d has lines %d title %s\n", |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
233 i, items[i], menus[i]); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
234 for (j = 0; j < items[i]; j++) |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
235 fprintf (stderr, " Item %d %s\n", j, names[i][j]); |
118 | 236 } |
237 #endif | |
238 BLOCK_INPUT; | |
1828
1463592a6463
* xmenu.c (Fx_popup_menu): Don't forget to turn the frame-relative
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
239 { |
1463592a6463
* xmenu.c (Fx_popup_menu): Don't forget to turn the frame-relative
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
240 Window root; |
1463592a6463
* xmenu.c (Fx_popup_menu): Don't forget to turn the frame-relative
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
241 int root_x, root_y; |
1463592a6463
* xmenu.c (Fx_popup_menu): Don't forget to turn the frame-relative
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
242 int dummy_int; |
1463592a6463
* xmenu.c (Fx_popup_menu): Don't forget to turn the frame-relative
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
243 unsigned int dummy_uint; |
1463592a6463
* xmenu.c (Fx_popup_menu): Don't forget to turn the frame-relative
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
244 Window dummy_window; |
1463592a6463
* xmenu.c (Fx_popup_menu): Don't forget to turn the frame-relative
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
245 |
1463592a6463
* xmenu.c (Fx_popup_menu): Don't forget to turn the frame-relative
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
246 /* Figure out which root window F is on. */ |
1463592a6463
* xmenu.c (Fx_popup_menu): Don't forget to turn the frame-relative
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
247 XGetGeometry (x_current_display, FRAME_X_WINDOW (f), &root, |
1463592a6463
* xmenu.c (Fx_popup_menu): Don't forget to turn the frame-relative
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
248 &dummy_int, &dummy_int, &dummy_uint, &dummy_uint, |
1463592a6463
* xmenu.c (Fx_popup_menu): Don't forget to turn the frame-relative
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
249 &dummy_uint, &dummy_uint); |
1463592a6463
* xmenu.c (Fx_popup_menu): Don't forget to turn the frame-relative
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
250 |
1463592a6463
* xmenu.c (Fx_popup_menu): Don't forget to turn the frame-relative
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
251 /* Translate the menu co-ordinates within f to menu co-ordinates |
1463592a6463
* xmenu.c (Fx_popup_menu): Don't forget to turn the frame-relative
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
252 on that root window. */ |
1463592a6463
* xmenu.c (Fx_popup_menu): Don't forget to turn the frame-relative
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
253 if (! XTranslateCoordinates (x_current_display, |
1463592a6463
* xmenu.c (Fx_popup_menu): Don't forget to turn the frame-relative
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
254 FRAME_X_WINDOW (f), root, |
1463592a6463
* xmenu.c (Fx_popup_menu): Don't forget to turn the frame-relative
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
255 XMenu_xpos, XMenu_ypos, &root_x, &root_y, |
1463592a6463
* xmenu.c (Fx_popup_menu): Don't forget to turn the frame-relative
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
256 &dummy_window)) |
1463592a6463
* xmenu.c (Fx_popup_menu): Don't forget to turn the frame-relative
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
257 /* But XGetGeometry said root was the root window of f's screen! */ |
1463592a6463
* xmenu.c (Fx_popup_menu): Don't forget to turn the frame-relative
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
258 abort (); |
1463592a6463
* xmenu.c (Fx_popup_menu): Don't forget to turn the frame-relative
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
259 |
1463592a6463
* xmenu.c (Fx_popup_menu): Don't forget to turn the frame-relative
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
260 selection = xmenu_show (root, XMenu_xpos, XMenu_ypos, names, menus, |
1463592a6463
* xmenu.c (Fx_popup_menu): Don't forget to turn the frame-relative
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
261 items, number_of_panes, obj_list, title, |
1463592a6463
* xmenu.c (Fx_popup_menu): Don't forget to turn the frame-relative
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
262 &error_name); |
1463592a6463
* xmenu.c (Fx_popup_menu): Don't forget to turn the frame-relative
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
263 } |
118 | 264 UNBLOCK_INPUT; |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
265 /* fprintf (stderr, "selection = %x\n", selection); */ |
118 | 266 if (selection != NUL) |
267 { /* selected something */ | |
268 XMenu_return = selection; | |
269 } | |
270 else | |
271 { /* nothing selected */ | |
272 XMenu_return = Qnil; | |
273 } | |
274 /* now free up the strings */ | |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
275 for (i = 0; i < number_of_panes; i++) |
118 | 276 { |
277 free (names[i]); | |
278 free (obj_list[i]); | |
279 } | |
280 free (menus); | |
281 free (obj_list); | |
282 free (names); | |
283 free (items); | |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
284 /* free (title); */ |
118 | 285 if (error_name) error (error_name); |
286 return XMenu_return; | |
287 } | |
288 | |
289 struct indices { | |
290 int pane; | |
291 int line; | |
292 }; | |
293 | |
294 Lisp_Object | |
295 xmenu_show (parent, startx, starty, line_list, pane_list, line_cnt, | |
296 pane_cnt, item_list, title, error) | |
297 Window parent; | |
298 int startx, starty; /* upper left corner position BROKEN */ | |
299 char **line_list[]; /* list of strings for items */ | |
300 char *pane_list[]; /* list of pane titles */ | |
301 char *title; | |
302 int pane_cnt; /* total number of panes */ | |
303 Lisp_Object *item_list[]; /* All items */ | |
304 int line_cnt[]; /* Lines in each pane */ | |
305 char **error; /* Error returned */ | |
306 { | |
307 XMenu *GXMenu; | |
308 int last, panes, selidx, lpane, status; | |
309 int lines, sofar; | |
310 Lisp_Object entry; | |
311 /* struct indices *datap, *datap_save; */ | |
312 char *datap; | |
313 int ulx, uly, width, height; | |
314 int dispwidth, dispheight; | |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
315 |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
316 if (pane_cnt == 0) |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
317 return 0; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
318 |
118 | 319 *error = (char *) 0; /* Initialize error pointer to null */ |
320 GXMenu = XMenuCreate (XDISPLAY parent, "emacs"); | |
321 if (GXMenu == NUL) | |
322 { | |
323 *error = "Can't create menu"; | |
324 return (0); | |
325 } | |
326 | |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
327 for (panes = 0, lines = 0; panes < pane_cnt; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
328 lines += line_cnt[panes], panes++) |
118 | 329 ; |
330 /* datap = (struct indices *) xmalloc (lines * sizeof (struct indices)); */ | |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
331 /* datap = (char *) xmalloc (lines * sizeof (char)); |
118 | 332 datap_save = datap;*/ |
333 | |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
334 for (panes = 0, sofar = 0; panes < pane_cnt; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
335 sofar += line_cnt[panes], panes++) |
118 | 336 { |
337 /* create all the necessary panes */ | |
338 lpane = XMenuAddPane (XDISPLAY GXMenu, pane_list[panes], TRUE); | |
339 if (lpane == XM_FAILURE) | |
340 { | |
341 XMenuDestroy (XDISPLAY GXMenu); | |
342 *error = "Can't create pane"; | |
343 return (0); | |
344 } | |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
345 for (selidx = 0; selidx < line_cnt[panes]; selidx++) |
118 | 346 { |
347 /* add the selection stuff to the menus */ | |
348 /* datap[selidx+sofar].pane = panes; | |
349 datap[selidx+sofar].line = selidx; */ | |
350 if (XMenuAddSelection (XDISPLAY GXMenu, lpane, 0, | |
351 line_list[panes][selidx], TRUE) | |
352 == XM_FAILURE) | |
353 { | |
354 XMenuDestroy (XDISPLAY GXMenu); | |
355 /* free (datap); */ | |
356 *error = "Can't add selection to menu"; | |
357 /* error ("Can't add selection to menu"); */ | |
358 return (0); | |
359 } | |
360 } | |
361 } | |
362 /* all set and ready to fly */ | |
363 XMenuRecompute (XDISPLAY GXMenu); | |
364 dispwidth = DisplayWidth (x_current_display, XDefaultScreen (x_current_display)); | |
365 dispheight = DisplayHeight (x_current_display, XDefaultScreen (x_current_display)); | |
366 startx = min (startx, dispwidth); | |
367 starty = min (starty, dispheight); | |
368 startx = max (startx, 1); | |
369 starty = max (starty, 1); | |
370 XMenuLocate (XDISPLAY GXMenu, 0, 0, startx, starty, | |
371 &ulx, &uly, &width, &height); | |
372 if (ulx+width > dispwidth) | |
373 { | |
374 startx -= (ulx + width) - dispwidth; | |
375 ulx = dispwidth - width; | |
376 } | |
377 if (uly+height > dispheight) | |
378 { | |
379 starty -= (uly + height) - dispheight; | |
380 uly = dispheight - height; | |
381 } | |
382 if (ulx < 0) startx -= ulx; | |
383 if (uly < 0) starty -= uly; | |
384 | |
385 XMenuSetFreeze (GXMenu, TRUE); | |
386 panes = selidx = 0; | |
387 | |
388 status = XMenuActivate (XDISPLAY GXMenu, &panes, &selidx, | |
389 startx, starty, ButtonReleaseMask, &datap); | |
390 switch (status) | |
391 { | |
392 case XM_SUCCESS: | |
393 #ifdef XDEBUG | |
394 fprintf (stderr, "pane= %d line = %d\n", panes, selidx); | |
395 #endif | |
396 entry = item_list[panes][selidx]; | |
397 break; | |
398 case XM_FAILURE: | |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
399 /* free (datap_save); */ |
118 | 400 XMenuDestroy (XDISPLAY GXMenu); |
401 *error = "Can't activate menu"; | |
402 /* error ("Can't activate menu"); */ | |
403 case XM_IA_SELECT: | |
404 case XM_NO_SELECT: | |
405 entry = Qnil; | |
406 break; | |
407 } | |
408 XMenuDestroy (XDISPLAY GXMenu); | |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
409 /* free (datap_save);*/ |
118 | 410 return (entry); |
411 } | |
412 | |
413 syms_of_xmenu () | |
414 { | |
2135
0634d08c28d1
(syms_of_xmenu): Set up Qmenu_enable.
Richard M. Stallman <rms@gnu.org>
parents:
1933
diff
changeset
|
415 Qmenu_enable = intern ("menu-enable"); |
0634d08c28d1
(syms_of_xmenu): Set up Qmenu_enable.
Richard M. Stallman <rms@gnu.org>
parents:
1933
diff
changeset
|
416 |
0634d08c28d1
(syms_of_xmenu): Set up Qmenu_enable.
Richard M. Stallman <rms@gnu.org>
parents:
1933
diff
changeset
|
417 staticpro (&Qmenu_enable); |
118 | 418 defsubr (&Sx_popup_menu); |
419 } | |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
420 |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
421 /* Construct the vectors that describe a menu |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
422 and store them in *VECTOR, *PANES, *NAMES and *ITEMS. |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
423 Each of those four values is a vector indexed by pane number. |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
424 Return the number of panes. |
118 | 425 |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
426 KEYMAPS is a vector of keymaps. NMAPS gives the length of KEYMAPS. */ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
427 |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
428 int |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
429 keymap_panes (vector, panes, names, items, keymaps, nmaps) |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
430 Lisp_Object ***vector; /* RETURN all menu objects */ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
431 char ***panes; /* RETURN pane names */ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
432 char ****names; /* RETURN all line names */ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
433 int **items; /* RETURN number of items per pane */ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
434 Lisp_Object *keymaps; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
435 int nmaps; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
436 { |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
437 /* Number of panes we have made. */ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
438 int p = 0; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
439 /* Number of panes we have space for. */ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
440 int npanes_allocated = nmaps; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
441 int mapno; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
442 |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
443 if (npanes_allocated < 4) |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
444 npanes_allocated = 4; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
445 |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
446 /* Make space for an estimated number of panes. */ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
447 *vector = (Lisp_Object **) xmalloc (npanes_allocated * sizeof (Lisp_Object *)); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
448 *panes = (char **) xmalloc (npanes_allocated * sizeof (char *)); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
449 *items = (int *) xmalloc (npanes_allocated * sizeof (int)); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
450 *names = (char ***) xmalloc (npanes_allocated * sizeof (char **)); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
451 |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
452 /* Loop over the given keymaps, making a pane for each map. |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
453 But don't make a pane that is empty--ignore that map instead. |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
454 P is the number of panes we have made so far. */ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
455 for (mapno = 0; mapno < nmaps; mapno++) |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
456 single_keymap_panes (keymaps[mapno], panes, vector, names, items, |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
457 &p, &npanes_allocated, ""); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
458 |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
459 /* Return the number of panes. */ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
460 return p; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
461 } |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
462 |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
463 /* This is a recursive subroutine of the previous function. |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
464 It handles one keymap, KEYMAP. |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
465 The other arguments are passed along |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
466 or point to local variables of the previous function. */ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
467 |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
468 single_keymap_panes (keymap, panes, vector, names, items, |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
469 p_ptr, npanes_allocated_ptr, pane_name) |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
470 Lisp_Object keymap; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
471 Lisp_Object ***vector; /* RETURN all menu objects */ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
472 char ***panes; /* RETURN pane names */ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
473 char ****names; /* RETURN all line names */ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
474 int **items; /* RETURN number of items per pane */ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
475 int *p_ptr; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
476 int *npanes_allocated_ptr; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
477 char *pane_name; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
478 { |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
479 int i; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
480 Lisp_Object pending_maps; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
481 Lisp_Object tail, item, item1, item2, table; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
482 |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
483 pending_maps = Qnil; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
484 |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
485 /* Make sure we have room for another pane. */ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
486 if (*p_ptr == *npanes_allocated_ptr) |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
487 { |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
488 *npanes_allocated_ptr *= 2; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
489 |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
490 *vector |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
491 = (Lisp_Object **) xrealloc (*vector, |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
492 *npanes_allocated_ptr * sizeof (Lisp_Object *)); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
493 *panes |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
494 = (char **) xrealloc (*panes, |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
495 *npanes_allocated_ptr * sizeof (char *)); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
496 *items |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
497 = (int *) xrealloc (*items, |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
498 *npanes_allocated_ptr * sizeof (int)); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
499 *names |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
500 = (char ***) xrealloc (*names, |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
501 *npanes_allocated_ptr * sizeof (char **)); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
502 } |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
503 |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
504 /* When a menu comes from keymaps, don't give names to the panes. */ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
505 (*panes)[*p_ptr] = pane_name; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
506 |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
507 /* Get the length of the list level of the keymap. */ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
508 i = XFASTINT (Flength (keymap)); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
509 |
1213
0901fe62d97b
(single_keymap_panes): Handle vectors properly.
Richard M. Stallman <rms@gnu.org>
parents:
1210
diff
changeset
|
510 /* Add in lengths of any arrays. */ |
0901fe62d97b
(single_keymap_panes): Handle vectors properly.
Richard M. Stallman <rms@gnu.org>
parents:
1210
diff
changeset
|
511 for (tail = keymap; XTYPE (tail) == Lisp_Cons; tail = XCONS (tail)->cdr) |
0901fe62d97b
(single_keymap_panes): Handle vectors properly.
Richard M. Stallman <rms@gnu.org>
parents:
1210
diff
changeset
|
512 if (XTYPE (XCONS (tail)->car) == Lisp_Vector) |
0901fe62d97b
(single_keymap_panes): Handle vectors properly.
Richard M. Stallman <rms@gnu.org>
parents:
1210
diff
changeset
|
513 i += XVECTOR (XCONS (tail)->car)->size; |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
514 |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
515 /* Create vectors for the names and values of the items in the pane. |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
516 I is an upper bound for the number of items. */ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
517 (*vector)[*p_ptr] = (Lisp_Object *) xmalloc (i * sizeof (Lisp_Object)); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
518 (*names)[*p_ptr] = (char **) xmalloc (i * sizeof (char *)); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
519 |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
520 /* I is now the index of the next unused slots. */ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
521 i = 0; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
522 for (tail = keymap; XTYPE (tail) == Lisp_Cons; tail = XCONS (tail)->cdr) |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
523 { |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
524 /* Look at each key binding, and if it has a menu string, |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
525 make a menu item from it. */ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
526 item = XCONS (tail)->car; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
527 if (XTYPE (item) == Lisp_Cons) |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
528 { |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
529 item1 = XCONS (item)->cdr; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
530 if (XTYPE (item1) == Lisp_Cons) |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
531 { |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
532 item2 = XCONS (item1)->car; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
533 if (XTYPE (item2) == Lisp_String) |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
534 { |
2135
0634d08c28d1
(syms_of_xmenu): Set up Qmenu_enable.
Richard M. Stallman <rms@gnu.org>
parents:
1933
diff
changeset
|
535 Lisp_Object def, tem; |
0634d08c28d1
(syms_of_xmenu): Set up Qmenu_enable.
Richard M. Stallman <rms@gnu.org>
parents:
1933
diff
changeset
|
536 Lisp_Object enabled; |
0634d08c28d1
(syms_of_xmenu): Set up Qmenu_enable.
Richard M. Stallman <rms@gnu.org>
parents:
1933
diff
changeset
|
537 |
0634d08c28d1
(syms_of_xmenu): Set up Qmenu_enable.
Richard M. Stallman <rms@gnu.org>
parents:
1933
diff
changeset
|
538 def = Fcdr (item1); |
0634d08c28d1
(syms_of_xmenu): Set up Qmenu_enable.
Richard M. Stallman <rms@gnu.org>
parents:
1933
diff
changeset
|
539 enabled = Qt; |
0634d08c28d1
(syms_of_xmenu): Set up Qmenu_enable.
Richard M. Stallman <rms@gnu.org>
parents:
1933
diff
changeset
|
540 if (XTYPE (def) == Lisp_Symbol) |
0634d08c28d1
(syms_of_xmenu): Set up Qmenu_enable.
Richard M. Stallman <rms@gnu.org>
parents:
1933
diff
changeset
|
541 { |
0634d08c28d1
(syms_of_xmenu): Set up Qmenu_enable.
Richard M. Stallman <rms@gnu.org>
parents:
1933
diff
changeset
|
542 /* No property, or nil, means enable. |
0634d08c28d1
(syms_of_xmenu): Set up Qmenu_enable.
Richard M. Stallman <rms@gnu.org>
parents:
1933
diff
changeset
|
543 Otherwise, enable if value is not nil. */ |
0634d08c28d1
(syms_of_xmenu): Set up Qmenu_enable.
Richard M. Stallman <rms@gnu.org>
parents:
1933
diff
changeset
|
544 tem = Fget (def, Qmenu_enable); |
0634d08c28d1
(syms_of_xmenu): Set up Qmenu_enable.
Richard M. Stallman <rms@gnu.org>
parents:
1933
diff
changeset
|
545 if (!NILP (tem)) |
0634d08c28d1
(syms_of_xmenu): Set up Qmenu_enable.
Richard M. Stallman <rms@gnu.org>
parents:
1933
diff
changeset
|
546 enabled = Feval (tem); |
0634d08c28d1
(syms_of_xmenu): Set up Qmenu_enable.
Richard M. Stallman <rms@gnu.org>
parents:
1933
diff
changeset
|
547 } |
0634d08c28d1
(syms_of_xmenu): Set up Qmenu_enable.
Richard M. Stallman <rms@gnu.org>
parents:
1933
diff
changeset
|
548 tem = Fkeymapp (def); |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
549 if (XSTRING (item2)->data[0] == '@' && !NILP (tem)) |
2135
0634d08c28d1
(syms_of_xmenu): Set up Qmenu_enable.
Richard M. Stallman <rms@gnu.org>
parents:
1933
diff
changeset
|
550 pending_maps = Fcons (Fcons (def, item2), |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
551 pending_maps); |
2135
0634d08c28d1
(syms_of_xmenu): Set up Qmenu_enable.
Richard M. Stallman <rms@gnu.org>
parents:
1933
diff
changeset
|
552 else if (!NILP (enabled)) |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
553 { |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
554 (*names)[*p_ptr][i] = (char *) XSTRING (item2)->data; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
555 /* The menu item "value" is the key bound here. */ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
556 (*vector)[*p_ptr][i] = XCONS (item)->car; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
557 i++; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
558 } |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
559 } |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
560 } |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
561 } |
1213
0901fe62d97b
(single_keymap_panes): Handle vectors properly.
Richard M. Stallman <rms@gnu.org>
parents:
1210
diff
changeset
|
562 else if (XTYPE (item) == Lisp_Vector) |
0901fe62d97b
(single_keymap_panes): Handle vectors properly.
Richard M. Stallman <rms@gnu.org>
parents:
1210
diff
changeset
|
563 { |
0901fe62d97b
(single_keymap_panes): Handle vectors properly.
Richard M. Stallman <rms@gnu.org>
parents:
1210
diff
changeset
|
564 /* Loop over the char values represented in the vector. */ |
0901fe62d97b
(single_keymap_panes): Handle vectors properly.
Richard M. Stallman <rms@gnu.org>
parents:
1210
diff
changeset
|
565 int len = XVECTOR (item)->size; |
0901fe62d97b
(single_keymap_panes): Handle vectors properly.
Richard M. Stallman <rms@gnu.org>
parents:
1210
diff
changeset
|
566 int c; |
0901fe62d97b
(single_keymap_panes): Handle vectors properly.
Richard M. Stallman <rms@gnu.org>
parents:
1210
diff
changeset
|
567 for (c = 0; c < len; c++) |
0901fe62d97b
(single_keymap_panes): Handle vectors properly.
Richard M. Stallman <rms@gnu.org>
parents:
1210
diff
changeset
|
568 { |
0901fe62d97b
(single_keymap_panes): Handle vectors properly.
Richard M. Stallman <rms@gnu.org>
parents:
1210
diff
changeset
|
569 Lisp_Object character; |
0901fe62d97b
(single_keymap_panes): Handle vectors properly.
Richard M. Stallman <rms@gnu.org>
parents:
1210
diff
changeset
|
570 XFASTINT (character) = c; |
0901fe62d97b
(single_keymap_panes): Handle vectors properly.
Richard M. Stallman <rms@gnu.org>
parents:
1210
diff
changeset
|
571 item1 = XVECTOR (item)->contents[c]; |
0901fe62d97b
(single_keymap_panes): Handle vectors properly.
Richard M. Stallman <rms@gnu.org>
parents:
1210
diff
changeset
|
572 if (XTYPE (item1) == Lisp_Cons) |
0901fe62d97b
(single_keymap_panes): Handle vectors properly.
Richard M. Stallman <rms@gnu.org>
parents:
1210
diff
changeset
|
573 { |
0901fe62d97b
(single_keymap_panes): Handle vectors properly.
Richard M. Stallman <rms@gnu.org>
parents:
1210
diff
changeset
|
574 item2 = XCONS (item1)->car; |
0901fe62d97b
(single_keymap_panes): Handle vectors properly.
Richard M. Stallman <rms@gnu.org>
parents:
1210
diff
changeset
|
575 if (XTYPE (item2) == Lisp_String) |
0901fe62d97b
(single_keymap_panes): Handle vectors properly.
Richard M. Stallman <rms@gnu.org>
parents:
1210
diff
changeset
|
576 { |
0901fe62d97b
(single_keymap_panes): Handle vectors properly.
Richard M. Stallman <rms@gnu.org>
parents:
1210
diff
changeset
|
577 Lisp_Object tem; |
2135
0634d08c28d1
(syms_of_xmenu): Set up Qmenu_enable.
Richard M. Stallman <rms@gnu.org>
parents:
1933
diff
changeset
|
578 Lisp_Object def; |
0634d08c28d1
(syms_of_xmenu): Set up Qmenu_enable.
Richard M. Stallman <rms@gnu.org>
parents:
1933
diff
changeset
|
579 Lisp_Object enabled; |
0634d08c28d1
(syms_of_xmenu): Set up Qmenu_enable.
Richard M. Stallman <rms@gnu.org>
parents:
1933
diff
changeset
|
580 |
0634d08c28d1
(syms_of_xmenu): Set up Qmenu_enable.
Richard M. Stallman <rms@gnu.org>
parents:
1933
diff
changeset
|
581 def = Fcdr (item1); |
0634d08c28d1
(syms_of_xmenu): Set up Qmenu_enable.
Richard M. Stallman <rms@gnu.org>
parents:
1933
diff
changeset
|
582 enabled = Qt; |
0634d08c28d1
(syms_of_xmenu): Set up Qmenu_enable.
Richard M. Stallman <rms@gnu.org>
parents:
1933
diff
changeset
|
583 if (XTYPE (def) == Lisp_Symbol) |
0634d08c28d1
(syms_of_xmenu): Set up Qmenu_enable.
Richard M. Stallman <rms@gnu.org>
parents:
1933
diff
changeset
|
584 { |
0634d08c28d1
(syms_of_xmenu): Set up Qmenu_enable.
Richard M. Stallman <rms@gnu.org>
parents:
1933
diff
changeset
|
585 tem = Fget (def, Qmenu_enable); |
0634d08c28d1
(syms_of_xmenu): Set up Qmenu_enable.
Richard M. Stallman <rms@gnu.org>
parents:
1933
diff
changeset
|
586 /* No property, or nil, means enable. |
0634d08c28d1
(syms_of_xmenu): Set up Qmenu_enable.
Richard M. Stallman <rms@gnu.org>
parents:
1933
diff
changeset
|
587 Otherwise, enable if value is not nil. */ |
0634d08c28d1
(syms_of_xmenu): Set up Qmenu_enable.
Richard M. Stallman <rms@gnu.org>
parents:
1933
diff
changeset
|
588 if (!NILP (tem)) |
0634d08c28d1
(syms_of_xmenu): Set up Qmenu_enable.
Richard M. Stallman <rms@gnu.org>
parents:
1933
diff
changeset
|
589 enabled = Feval (tem); |
0634d08c28d1
(syms_of_xmenu): Set up Qmenu_enable.
Richard M. Stallman <rms@gnu.org>
parents:
1933
diff
changeset
|
590 } |
0634d08c28d1
(syms_of_xmenu): Set up Qmenu_enable.
Richard M. Stallman <rms@gnu.org>
parents:
1933
diff
changeset
|
591 |
0634d08c28d1
(syms_of_xmenu): Set up Qmenu_enable.
Richard M. Stallman <rms@gnu.org>
parents:
1933
diff
changeset
|
592 tem = Fkeymapp (def); |
1213
0901fe62d97b
(single_keymap_panes): Handle vectors properly.
Richard M. Stallman <rms@gnu.org>
parents:
1210
diff
changeset
|
593 if (XSTRING (item2)->data[0] == '@' && !NILP (tem)) |
2135
0634d08c28d1
(syms_of_xmenu): Set up Qmenu_enable.
Richard M. Stallman <rms@gnu.org>
parents:
1933
diff
changeset
|
594 pending_maps = Fcons (Fcons (def, item2), |
1213
0901fe62d97b
(single_keymap_panes): Handle vectors properly.
Richard M. Stallman <rms@gnu.org>
parents:
1210
diff
changeset
|
595 pending_maps); |
2135
0634d08c28d1
(syms_of_xmenu): Set up Qmenu_enable.
Richard M. Stallman <rms@gnu.org>
parents:
1933
diff
changeset
|
596 else if (!NILP (enabled)) |
1213
0901fe62d97b
(single_keymap_panes): Handle vectors properly.
Richard M. Stallman <rms@gnu.org>
parents:
1210
diff
changeset
|
597 { |
0901fe62d97b
(single_keymap_panes): Handle vectors properly.
Richard M. Stallman <rms@gnu.org>
parents:
1210
diff
changeset
|
598 (*names)[*p_ptr][i] = (char *) XSTRING (item2)->data; |
0901fe62d97b
(single_keymap_panes): Handle vectors properly.
Richard M. Stallman <rms@gnu.org>
parents:
1210
diff
changeset
|
599 /* The menu item "value" is the key bound here. */ |
0901fe62d97b
(single_keymap_panes): Handle vectors properly.
Richard M. Stallman <rms@gnu.org>
parents:
1210
diff
changeset
|
600 (*vector)[*p_ptr][i] = character; |
0901fe62d97b
(single_keymap_panes): Handle vectors properly.
Richard M. Stallman <rms@gnu.org>
parents:
1210
diff
changeset
|
601 i++; |
0901fe62d97b
(single_keymap_panes): Handle vectors properly.
Richard M. Stallman <rms@gnu.org>
parents:
1210
diff
changeset
|
602 } |
0901fe62d97b
(single_keymap_panes): Handle vectors properly.
Richard M. Stallman <rms@gnu.org>
parents:
1210
diff
changeset
|
603 } |
0901fe62d97b
(single_keymap_panes): Handle vectors properly.
Richard M. Stallman <rms@gnu.org>
parents:
1210
diff
changeset
|
604 } |
0901fe62d97b
(single_keymap_panes): Handle vectors properly.
Richard M. Stallman <rms@gnu.org>
parents:
1210
diff
changeset
|
605 } |
0901fe62d97b
(single_keymap_panes): Handle vectors properly.
Richard M. Stallman <rms@gnu.org>
parents:
1210
diff
changeset
|
606 } |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
607 } |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
608 /* Record the number of items in the pane. */ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
609 (*items)[*p_ptr] = i; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
610 |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
611 /* If we just made an empty pane, get rid of it. */ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
612 if (i == 0) |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
613 { |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
614 free ((*vector)[*p_ptr]); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
615 free ((*names)[*p_ptr]); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
616 } |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
617 /* Otherwise, advance past it. */ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
618 else |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
619 (*p_ptr)++; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
620 |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
621 /* Process now any submenus which want to be panes at this level. */ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
622 while (!NILP (pending_maps)) |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
623 { |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
624 Lisp_Object elt; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
625 elt = Fcar (pending_maps); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
626 single_keymap_panes (Fcar (elt), panes, vector, names, items, |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
627 p_ptr, npanes_allocated_ptr, |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
628 /* Add 1 to discard the @. */ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
629 (char *) XSTRING (XCONS (elt)->cdr)->data + 1); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
630 pending_maps = Fcdr (pending_maps); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
631 } |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
632 } |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
633 |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
634 /* Construct the vectors that describe a menu |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
635 and store them in *VECTOR, *PANES, *NAMES and *ITEMS. |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
636 Each of those four values is a vector indexed by pane number. |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
637 Return the number of panes. |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
638 |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
639 MENU is the argument that was given to Fx_popup_menu. */ |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
640 |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
641 int |
118 | 642 list_of_panes (vector, panes, names, items, menu) |
643 Lisp_Object ***vector; /* RETURN all menu objects */ | |
644 char ***panes; /* RETURN pane names */ | |
645 char ****names; /* RETURN all line names */ | |
646 int **items; /* RETURN number of items per pane */ | |
647 Lisp_Object menu; | |
648 { | |
649 Lisp_Object tail, item, item1; | |
650 int i; | |
651 | |
652 if (XTYPE (menu) != Lisp_Cons) menu = wrong_type_argument (Qlistp, menu); | |
653 | |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
654 i = XFASTINT (Flength (menu)); |
118 | 655 |
656 *vector = (Lisp_Object **) xmalloc (i * sizeof (Lisp_Object *)); | |
657 *panes = (char **) xmalloc (i * sizeof (char *)); | |
658 *items = (int *) xmalloc (i * sizeof (int)); | |
659 *names = (char ***) xmalloc (i * sizeof (char **)); | |
660 | |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
661 for (i = 0, tail = menu; !NILP (tail); tail = Fcdr (tail), i++) |
118 | 662 { |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
663 item = Fcdr (Fcar (tail)); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
664 if (XTYPE (item) != Lisp_Cons) (void) wrong_type_argument (Qlistp, item); |
118 | 665 #ifdef XDEBUG |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
666 fprintf (stderr, "list_of_panes check tail, i=%d\n", i); |
118 | 667 #endif |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
668 item1 = Fcar (Fcar (tail)); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
669 CHECK_STRING (item1, 1); |
118 | 670 #ifdef XDEBUG |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
671 fprintf (stderr, "list_of_panes check pane, i=%d%s\n", i, |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
672 XSTRING (item1)->data); |
118 | 673 #endif |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
674 (*panes)[i] = (char *) XSTRING (item1)->data; |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
675 (*items)[i] = list_of_items ((*vector)+i, (*names)+i, item); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
676 /* (*panes)[i] = (char *) xmalloc ((XSTRING (item1)->size)+1); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
677 bcopy (XSTRING (item1)->data, (*panes)[i], XSTRING (item1)->size + 1) |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
678 ; */ |
118 | 679 } |
680 return i; | |
681 } | |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
682 |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
683 /* Construct the lists of values and names for a single pane, from the |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
684 alist PANE. Put them in *VECTOR and *NAMES. |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
685 Return the number of items. */ |
118 | 686 |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
687 int |
118 | 688 list_of_items (vector, names, pane) /* get list from emacs and put to vector */ |
689 Lisp_Object **vector; /* RETURN menu "objects" */ | |
690 char ***names; /* RETURN line names */ | |
691 Lisp_Object pane; | |
692 { | |
693 Lisp_Object tail, item, item1; | |
694 int i; | |
695 | |
696 if (XTYPE (pane) != Lisp_Cons) pane = wrong_type_argument (Qlistp, pane); | |
697 | |
1933
63ba4f555b90
* minibuf.c (Fdisplay_completion_list): Pass the proper number of
Jim Blandy <jimb@redhat.com>
parents:
1828
diff
changeset
|
698 i = XFASTINT (Flength (pane)); |
118 | 699 |
700 *vector = (Lisp_Object *) xmalloc (i * sizeof (Lisp_Object)); | |
701 *names = (char **) xmalloc (i * sizeof (char *)); | |
702 | |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
703 for (i = 0, tail = pane; !NILP (tail); tail = Fcdr (tail), i++) |
118 | 704 { |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
705 item = Fcar (tail); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
706 if (XTYPE (item) != Lisp_Cons) (void) wrong_type_argument (Qlistp, item); |
118 | 707 #ifdef XDEBUG |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
708 fprintf (stderr, "list_of_items check tail, i=%d\n", i); |
118 | 709 #endif |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
710 (*vector)[i] = Fcdr (item); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
711 item1 = Fcar (item); |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
712 CHECK_STRING (item1, 1); |
118 | 713 #ifdef XDEBUG |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
714 fprintf (stderr, "list_of_items check item, i=%d%s\n", i, |
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
715 XSTRING (item1)->data); |
118 | 716 #endif |
1082
d24afc1bef38
(xmenu_show): If no panes, just return.
Richard M. Stallman <rms@gnu.org>
parents:
975
diff
changeset
|
717 (*names)[i] = (char *) XSTRING (item1)->data; |
118 | 718 } |
719 return i; | |
720 } |