Mercurial > emacs
annotate src/w32menu.c @ 21647:9b009b58225f
Update copyright years.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sat, 18 Apr 1998 17:09:18 +0000 |
parents | 24a01af0cd38 |
children | 3d1ce72aa7b9 |
rev | line source |
---|---|
16884
36babc489b0c
Change all uses of win95, winnt, and win32
Geoff Voelker <voelker@cs.washington.edu>
parents:
16860
diff
changeset
|
1 /* Menu support for GNU Emacs on the Microsoft W32 API. |
13434 | 2 Copyright (C) 1986, 1988, 1993, 1994 Free Software Foundation, Inc. |
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 | |
8 the Free Software Foundation; either version 2, or (at your option) | |
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 | |
14186
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
ee40177f6c68
Update FSF's address in the preamble.
Erik Naggum <erik@naggum.no>
parents:
14036
diff
changeset
|
19 Boston, MA 02111-1307, USA. */ |
13434 | 20 |
21 /* Written by Kevin Gallo. */ | |
22 | |
23 #include <signal.h> | |
24 #include <config.h> | |
25 | |
26 #include <stdio.h> | |
27 #include "lisp.h" | |
28 #include "termhooks.h" | |
29 #include "frame.h" | |
30 #include "window.h" | |
31 #include "keyboard.h" | |
32 #include "blockinput.h" | |
15276 | 33 #include "buffer.h" |
13434 | 34 |
35 /* This may include sys/types.h, and that somehow loses | |
36 if this is not done before the other system files. */ | |
37 #include "w32term.h" | |
38 | |
39 /* Load sys/types.h if not already loaded. | |
40 In some systems loading it twice is suicidal. */ | |
41 #ifndef makedev | |
42 #include <sys/types.h> | |
43 #endif | |
44 | |
45 #include "dispextern.h" | |
46 | |
47 #define min(x, y) (((x) < (y)) ? (x) : (y)) | |
48 #define max(x, y) (((x) > (y)) ? (x) : (y)) | |
49 | |
21612
24a01af0cd38
(Vmenu_updating_frame): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21450
diff
changeset
|
50 Lisp_Object Vmenu_updating_frame; |
24a01af0cd38
(Vmenu_updating_frame): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21450
diff
changeset
|
51 |
13434 | 52 typedef struct menu_map |
53 { | |
54 Lisp_Object menu_items; | |
55 int menu_items_allocated; | |
56 int menu_items_used; | |
57 } menu_map; | |
58 | |
15276 | 59 Lisp_Object Qdebug_on_next_call; |
60 | |
13434 | 61 extern Lisp_Object Qmenu_enable; |
62 extern Lisp_Object Qmenu_bar; | |
63 | |
15276 | 64 extern Lisp_Object Voverriding_local_map; |
65 extern Lisp_Object Voverriding_local_map_menu_flag; | |
66 | |
67 extern Lisp_Object Qoverriding_local_map, Qoverriding_terminal_local_map; | |
68 | |
69 extern Lisp_Object Qmenu_bar_update_hook; | |
70 | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
71 void set_frame_menubar (); |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
72 |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
15276
diff
changeset
|
73 static Lisp_Object w32_dialog_show (); |
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
15276
diff
changeset
|
74 static Lisp_Object w32menu_show (); |
13434 | 75 |
76 static HMENU keymap_panes (); | |
77 static HMENU single_keymap_panes (); | |
78 static HMENU list_of_panes (); | |
79 static HMENU list_of_items (); | |
80 | |
81 static HMENU create_menu_items (); | |
82 | |
83 /* Initialize the menu_items structure if we haven't already done so. | |
84 Also mark it as currently empty. */ | |
85 | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
86 #if 0 |
13434 | 87 static void |
88 init_menu_items (lpmm) | |
89 menu_map * lpmm; | |
90 { | |
91 if (NILP (lpmm->menu_items)) | |
92 { | |
93 lpmm->menu_items_allocated = 60; | |
94 lpmm->menu_items = Fmake_vector (make_number (lpmm->menu_items_allocated), | |
95 Qnil); | |
96 } | |
97 | |
98 lpmm->menu_items_used = 0; | |
99 } | |
100 | |
101 /* Make the menu_items vector twice as large. */ | |
102 | |
103 static void | |
104 grow_menu_items (lpmm) | |
105 menu_map * lpmm; | |
106 { | |
107 Lisp_Object new; | |
108 int old_size = lpmm->menu_items_allocated; | |
109 | |
110 lpmm->menu_items_allocated *= 2; | |
111 new = Fmake_vector (make_number (lpmm->menu_items_allocated), Qnil); | |
112 bcopy (XVECTOR (lpmm->menu_items)->contents, XVECTOR (new)->contents, | |
113 old_size * sizeof (Lisp_Object)); | |
114 | |
115 lpmm->menu_items = new; | |
116 } | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
117 #endif |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
118 |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
119 /* Call when finished using the data for the current menu |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
120 in menu_items. */ |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
121 |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
122 static void |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
123 discard_menu_items (lpmm) |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
124 menu_map * lpmm; |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
125 { |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
126 #if 0 |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
127 lpmm->menu_items = Qnil; |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
128 #endif |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
129 lpmm->menu_items_allocated = lpmm->menu_items_used = 0; |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
130 } |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
131 |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
132 /* Is this item a separator? */ |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
133 static int |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
134 name_is_separator (name) |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
135 Lisp_Object name; |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
136 { |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
137 int isseparator = (((char *)XSTRING (name)->data)[0] == 0); |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
138 |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
139 if (!isseparator) |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
140 { |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
141 /* Check if name string consists of only dashes ('-') */ |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
142 char *string = (char *)XSTRING (name)->data; |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
143 while (*string == '-') string++; |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
144 isseparator = (*string == 0); |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
145 } |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
146 |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
147 return isseparator; |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
148 } |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
149 |
13434 | 150 |
151 /* Indicate boundary between left and right. */ | |
152 | |
153 static void | |
154 add_left_right_boundary (hmenu) | |
155 HMENU hmenu; | |
156 { | |
157 AppendMenu (hmenu, MF_MENUBARBREAK, 0, NULL); | |
158 } | |
159 | |
160 /* Push one menu item into the current pane. | |
161 NAME is the string to display. ENABLE if non-nil means | |
162 this item can be selected. KEY is the key generated by | |
163 choosing this item. EQUIV is the textual description | |
164 of the keyboard equivalent for this item (or nil if none). */ | |
165 | |
166 static void | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
167 add_menu_item (lpmm, hmenu, name, enable, key, equiv) |
13434 | 168 menu_map * lpmm; |
169 HMENU hmenu; | |
170 Lisp_Object name; | |
171 UINT enable; | |
172 Lisp_Object key; | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
173 Lisp_Object equiv; |
13434 | 174 { |
175 UINT fuFlags; | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
176 Lisp_Object out_string; |
13434 | 177 |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
178 if (NILP (name) || name_is_separator (name)) |
13434 | 179 fuFlags = MF_SEPARATOR; |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
180 else |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
181 { |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
182 if (enable) |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
183 fuFlags = MF_STRING; |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
184 else |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
185 fuFlags = MF_STRING | MF_GRAYED; |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
186 |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
187 if (!NILP (equiv)) |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
188 { |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
189 out_string = concat2 (name, make_string ("\t", 1)); |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
190 out_string = concat2 (out_string, equiv); |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
191 } |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
192 else |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
193 out_string = name; |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
194 } |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
195 |
13434 | 196 AppendMenu (hmenu, |
197 fuFlags, | |
198 lpmm->menu_items_used + 1, | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
199 (fuFlags == MF_SEPARATOR)?NULL: |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
200 (char *) XSTRING (out_string)->data); |
13434 | 201 |
202 lpmm->menu_items_used++; | |
203 #if 0 | |
204 if (lpmm->menu_items_used >= lpmm->menu_items_allocated) | |
205 grow_menu_items (lpmm); | |
206 | |
207 XSET (XVECTOR (lpmm->menu_items)->contents[lpmm->menu_items_used++], | |
208 Lisp_Cons, | |
209 key); | |
210 #endif | |
211 } | |
212 | |
213 /* Figure out the current keyboard equivalent of a menu item ITEM1. | |
214 The item string for menu display should be ITEM_STRING. | |
215 Store the equivalent keyboard key sequence's | |
216 textual description into *DESCRIP_PTR. | |
217 Also cache them in the item itself. | |
218 Return the real definition to execute. */ | |
219 | |
220 static Lisp_Object | |
221 menu_item_equiv_key (item_string, item1, descrip_ptr) | |
222 Lisp_Object item_string; | |
223 Lisp_Object item1; | |
224 Lisp_Object *descrip_ptr; | |
225 { | |
226 /* This is the real definition--the function to run. */ | |
227 Lisp_Object def; | |
228 /* This is the sublist that records cached equiv key data | |
229 so we can save time. */ | |
230 Lisp_Object cachelist; | |
231 /* These are the saved equivalent keyboard key sequence | |
232 and its key-description. */ | |
233 Lisp_Object savedkey, descrip; | |
234 Lisp_Object def1; | |
235 int changed = 0; | |
236 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; | |
237 | |
238 /* If a help string follows the item string, skip it. */ | |
239 if (CONSP (XCONS (item1)->cdr) | |
240 && STRINGP (XCONS (XCONS (item1)->cdr)->car)) | |
241 item1 = XCONS (item1)->cdr; | |
242 | |
243 def = Fcdr (item1); | |
244 | |
245 /* Get out the saved equivalent-keyboard-key info. */ | |
246 cachelist = savedkey = descrip = Qnil; | |
247 if (CONSP (def) && CONSP (XCONS (def)->car) | |
248 && (NILP (XCONS (XCONS (def)->car)->car) | |
249 || VECTORP (XCONS (XCONS (def)->car)->car))) | |
250 { | |
251 cachelist = XCONS (def)->car; | |
252 def = XCONS (def)->cdr; | |
253 savedkey = XCONS (cachelist)->car; | |
254 descrip = XCONS (cachelist)->cdr; | |
255 } | |
256 | |
257 GCPRO4 (def, def1, savedkey, descrip); | |
258 | |
259 /* Is it still valid? */ | |
260 def1 = Qnil; | |
261 if (!NILP (savedkey)) | |
262 def1 = Fkey_binding (savedkey, Qnil); | |
263 /* If not, update it. */ | |
264 if (! EQ (def1, def) | |
265 /* If the command is an alias for another | |
266 (such as easymenu.el and lmenu.el set it up), | |
267 check if the original command matches the cached command. */ | |
268 && !(SYMBOLP (def) && SYMBOLP (XSYMBOL (def)->function) | |
269 && EQ (def1, XSYMBOL (def)->function)) | |
270 /* If something had no key binding before, don't recheck it-- | |
271 doing that takes too much time and makes menus too slow. */ | |
272 && !(!NILP (cachelist) && NILP (savedkey))) | |
273 { | |
274 changed = 1; | |
275 descrip = Qnil; | |
276 savedkey = Fwhere_is_internal (def, Qnil, Qt, Qnil); | |
277 /* If the command is an alias for another | |
278 (such as easymenu.el and lmenu.el set it up), | |
279 see if the original command name has equivalent keys. */ | |
280 if (SYMBOLP (def) && SYMBOLP (XSYMBOL (def)->function)) | |
281 savedkey = Fwhere_is_internal (XSYMBOL (def)->function, | |
282 Qnil, Qt, Qnil); | |
283 | |
284 if (VECTORP (savedkey) | |
285 && EQ (XVECTOR (savedkey)->contents[0], Qmenu_bar)) | |
286 savedkey = Qnil; | |
287 if (!NILP (savedkey)) | |
288 { | |
289 descrip = Fkey_description (savedkey); | |
290 descrip = concat2 (make_string (" (", 3), descrip); | |
291 descrip = concat2 (descrip, make_string (")", 1)); | |
292 } | |
293 } | |
294 | |
295 /* Cache the data we just got in a sublist of the menu binding. */ | |
296 if (NILP (cachelist)) | |
297 XCONS (item1)->cdr = Fcons (Fcons (savedkey, descrip), def); | |
298 else if (changed) | |
299 { | |
300 XCONS (cachelist)->car = savedkey; | |
301 XCONS (cachelist)->cdr = descrip; | |
302 } | |
303 | |
304 UNGCPRO; | |
305 *descrip_ptr = descrip; | |
306 return def; | |
307 } | |
308 | |
309 /* This is used as the handler when calling internal_condition_case_1. */ | |
310 | |
311 static Lisp_Object | |
312 menu_item_enabled_p_1 (arg) | |
313 Lisp_Object arg; | |
314 { | |
315 return Qnil; | |
316 } | |
317 | |
318 /* Return non-nil if the command DEF is enabled when used as a menu item. | |
319 This is based on looking for a menu-enable property. | |
320 If NOTREAL is set, don't bother really computing this. */ | |
321 | |
322 static Lisp_Object | |
323 menu_item_enabled_p (def, notreal) | |
324 Lisp_Object def; | |
325 { | |
326 Lisp_Object enabled, tem; | |
327 | |
328 enabled = Qt; | |
329 if (notreal) | |
330 return enabled; | |
331 if (XTYPE (def) == Lisp_Symbol) | |
332 { | |
333 /* No property, or nil, means enable. | |
334 Otherwise, enable if value is not nil. */ | |
335 tem = Fget (def, Qmenu_enable); | |
336 if (!NILP (tem)) | |
337 /* (condition-case nil (eval tem) | |
338 (error nil)) */ | |
339 enabled = internal_condition_case_1 (Feval, tem, Qerror, | |
340 menu_item_enabled_p_1); | |
341 } | |
342 return enabled; | |
343 } | |
344 | |
345 /* Look through KEYMAPS, a vector of keymaps that is NMAPS long, | |
346 and generate menu panes for them in menu_items. | |
347 If NOTREAL is nonzero, | |
348 don't bother really computing whether an item is enabled. */ | |
349 | |
350 static HMENU | |
351 keymap_panes (lpmm, keymaps, nmaps, notreal) | |
352 menu_map * lpmm; | |
353 Lisp_Object *keymaps; | |
354 int nmaps; | |
355 int notreal; | |
356 { | |
357 int mapno; | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
358 |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
359 #if 0 |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
360 init_menu_items (lpmm); |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
361 #endif |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
362 |
13434 | 363 if (nmaps > 1) |
364 { | |
365 HMENU hmenu; | |
366 | |
367 if (!notreal) | |
368 { | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
369 hmenu = CreatePopupMenu (); |
13434 | 370 |
371 if (!hmenu) return (NULL); | |
372 } | |
373 else | |
374 { | |
375 hmenu = NULL; | |
376 } | |
377 | |
378 /* Loop over the given keymaps, making a pane for each map. | |
379 But don't make a pane that is empty--ignore that map instead. | |
380 P is the number of panes we have made so far. */ | |
381 for (mapno = 0; mapno < nmaps; mapno++) | |
382 { | |
383 HMENU new_hmenu; | |
384 | |
385 new_hmenu = single_keymap_panes (lpmm, keymaps[mapno], | |
386 Qnil, Qnil, notreal); | |
387 | |
388 if (!notreal && new_hmenu) | |
389 { | |
390 AppendMenu (hmenu, MF_POPUP, (UINT)new_hmenu, ""); | |
391 } | |
392 } | |
393 | |
394 return (hmenu); | |
395 } | |
396 else | |
397 { | |
398 return (single_keymap_panes (lpmm, keymaps[0], Qnil, Qnil, notreal)); | |
399 } | |
400 } | |
401 | |
402 /* This is a recursive subroutine of keymap_panes. | |
403 It handles one keymap, KEYMAP. | |
404 The other arguments are passed along | |
405 or point to local variables of the previous function. | |
406 If NOTREAL is nonzero, | |
407 don't bother really computing whether an item is enabled. */ | |
408 | |
409 HMENU | |
410 single_keymap_panes (lpmm, keymap, pane_name, prefix, notreal) | |
411 menu_map * lpmm; | |
412 Lisp_Object keymap; | |
413 Lisp_Object pane_name; | |
414 Lisp_Object prefix; | |
415 int notreal; | |
416 { | |
417 Lisp_Object pending_maps; | |
418 Lisp_Object tail, item, item1, item_string, table; | |
419 HMENU hmenu; | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
420 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; |
13434 | 421 |
422 if (!notreal) | |
423 { | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
424 hmenu = CreatePopupMenu (); |
13434 | 425 if (hmenu == NULL) return NULL; |
426 } | |
427 else | |
428 { | |
429 hmenu = NULL; | |
430 } | |
431 | |
432 pending_maps = Qnil; | |
433 | |
434 for (tail = keymap; XTYPE (tail) == Lisp_Cons; tail = XCONS (tail)->cdr) | |
435 { | |
436 /* Look at each key binding, and if it has a menu string, | |
437 make a menu item from it. */ | |
438 | |
439 item = XCONS (tail)->car; | |
440 | |
441 if (CONSP (item)) | |
442 { | |
443 item1 = XCONS (item)->cdr; | |
444 | |
445 if (XTYPE (item1) == Lisp_Cons) | |
446 { | |
447 item_string = XCONS (item1)->car; | |
448 if (XTYPE (item_string) == Lisp_String) | |
449 { | |
450 /* This is the real definition--the function to run. */ | |
451 | |
452 Lisp_Object def; | |
453 | |
454 /* These are the saved equivalent keyboard key sequence | |
455 and its key-description. */ | |
456 | |
457 Lisp_Object descrip; | |
458 Lisp_Object tem, enabled; | |
459 | |
460 /* GCPRO because ...enabled_p will call eval | |
461 and ..._equiv_key may autoload something. | |
462 Protecting KEYMAP preserves everything we use; | |
463 aside from that, must protect whatever might be | |
464 a string. Since there's no GCPRO5, we refetch | |
465 item_string instead of protecting it. */ | |
466 | |
467 descrip = def = Qnil; | |
468 GCPRO4 (keymap, pending_maps, def, prefix); | |
469 | |
470 def = menu_item_equiv_key (item_string, item1, &descrip); | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
471 { |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
472 struct gcpro gcpro1; |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
473 GCPRO1 (descrip); |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
474 enabled = menu_item_enabled_p (def, notreal); |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
475 UNGCPRO; |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
476 } |
13434 | 477 |
478 UNGCPRO; | |
479 | |
480 item_string = XCONS (item1)->car; | |
481 | |
482 tem = Fkeymapp (def); | |
483 if (XSTRING (item_string)->data[0] == '@' && !NILP (tem)) | |
484 { | |
485 pending_maps = Fcons (Fcons (def, | |
486 Fcons (item_string, | |
487 XCONS (item)->car)), | |
488 pending_maps); | |
489 } | |
490 else | |
491 { | |
492 Lisp_Object submap; | |
493 | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
494 GCPRO5 (keymap, pending_maps, item, item_string, descrip); |
13434 | 495 |
496 submap = get_keymap_1 (def, 0, 1); | |
497 | |
498 UNGCPRO; | |
499 | |
500 if (NILP (submap)) | |
501 { | |
502 if (!notreal) | |
503 { | |
504 add_menu_item (lpmm, | |
505 hmenu, | |
506 item_string, | |
507 !NILP (enabled), | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
508 Fcons (XCONS (item)->car, prefix), |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
509 descrip); |
13434 | 510 } |
511 } | |
512 else | |
513 /* Display a submenu. */ | |
514 { | |
515 HMENU new_hmenu = single_keymap_panes (lpmm, | |
516 submap, | |
517 item_string, | |
518 XCONS (item)->car, | |
519 notreal); | |
520 | |
521 if (!notreal) | |
522 { | |
523 AppendMenu (hmenu, MF_POPUP, | |
524 (UINT)new_hmenu, | |
525 (char *) XSTRING (item_string)->data); | |
526 } | |
527 } | |
528 } | |
529 } | |
530 } | |
531 } | |
532 else if (VECTORP (item)) | |
533 { | |
534 /* Loop over the char values represented in the vector. */ | |
535 int len = XVECTOR (item)->size; | |
536 int c; | |
537 for (c = 0; c < len; c++) | |
538 { | |
539 Lisp_Object character; | |
540 XSETFASTINT (character, c); | |
541 item1 = XVECTOR (item)->contents[c]; | |
542 if (CONSP (item1)) | |
543 { | |
544 item_string = XCONS (item1)->car; | |
545 if (STRINGP (item_string)) | |
546 { | |
547 Lisp_Object def; | |
548 | |
549 /* These are the saved equivalent keyboard key sequence | |
550 and its key-description. */ | |
551 Lisp_Object descrip; | |
552 Lisp_Object tem, enabled; | |
553 | |
554 /* GCPRO because ...enabled_p will call eval | |
555 and ..._equiv_key may autoload something. | |
556 Protecting KEYMAP preserves everything we use; | |
557 aside from that, must protect whatever might be | |
558 a string. Since there's no GCPRO5, we refetch | |
559 item_string instead of protecting it. */ | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
560 GCPRO3 (keymap, pending_maps, def); |
13434 | 561 descrip = def = Qnil; |
562 | |
563 def = menu_item_equiv_key (item_string, item1, &descrip); | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
564 { |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
565 struct gcpro gcpro1; |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
566 GCPRO1 (descrip); |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
567 enabled = menu_item_enabled_p (def, notreal); |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
568 UNGCPRO; |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
569 } |
13434 | 570 |
571 UNGCPRO; | |
572 | |
573 item_string = XCONS (item1)->car; | |
574 | |
575 tem = Fkeymapp (def); | |
576 if (XSTRING (item_string)->data[0] == '@' && !NILP (tem)) | |
577 pending_maps = Fcons (Fcons (def, Fcons (item_string, character)), | |
578 pending_maps); | |
579 else | |
580 { | |
581 Lisp_Object submap; | |
582 | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
583 GCPRO5 (keymap, pending_maps, descrip, item_string, descrip); |
13434 | 584 |
585 submap = get_keymap_1 (def, 0, 1); | |
586 | |
587 UNGCPRO; | |
588 | |
589 if (NILP (submap)) | |
590 { | |
591 if (!notreal) | |
592 { | |
593 add_menu_item (lpmm, | |
594 hmenu, | |
595 item_string, | |
596 !NILP (enabled), | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
597 character, |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
598 descrip); |
13434 | 599 } |
600 } | |
601 else | |
602 /* Display a submenu. */ | |
603 { | |
604 HMENU new_hmenu = single_keymap_panes (lpmm, | |
605 submap, | |
606 Qnil, | |
607 character, | |
608 notreal); | |
609 | |
610 if (!notreal) | |
611 { | |
612 AppendMenu (hmenu,MF_POPUP, | |
613 (UINT)new_hmenu, | |
614 (char *)XSTRING (item_string)->data); | |
615 } | |
616 } | |
617 } | |
618 } | |
619 } | |
620 } | |
621 } | |
622 } | |
623 | |
624 /* Process now any submenus which want to be panes at this level. */ | |
625 while (!NILP (pending_maps)) | |
626 { | |
627 Lisp_Object elt, eltcdr, string; | |
628 elt = Fcar (pending_maps); | |
629 eltcdr = XCONS (elt)->cdr; | |
630 string = XCONS (eltcdr)->car; | |
631 /* We no longer discard the @ from the beginning of the string here. | |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
15276
diff
changeset
|
632 Instead, we do this in w32menu_show. */ |
13434 | 633 { |
634 HMENU new_hmenu = single_keymap_panes (lpmm, | |
635 Fcar (elt), | |
636 string, | |
637 XCONS (eltcdr)->cdr, notreal); | |
638 | |
639 if (!notreal) | |
640 { | |
641 AppendMenu (hmenu, MF_POPUP, | |
642 (UINT)new_hmenu, | |
643 (char *) XSTRING (string)->data); | |
644 } | |
645 } | |
646 | |
647 pending_maps = Fcdr (pending_maps); | |
648 } | |
649 | |
650 return (hmenu); | |
651 } | |
652 | |
14036 | 653 /* Push all the panes and items of a menu described by the |
13434 | 654 alist-of-alists MENU. |
655 This handles old-fashioned calls to x-popup-menu. */ | |
656 | |
657 static HMENU | |
658 list_of_panes (lpmm, menu) | |
659 menu_map * lpmm; | |
660 Lisp_Object menu; | |
661 { | |
662 Lisp_Object tail; | |
663 HMENU hmenu; | |
664 | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
665 if (XFASTINT (Flength (menu)) > 1) |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
666 { |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
667 hmenu = CreatePopupMenu (); |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
668 if (hmenu == NULL) return NULL; |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
669 |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
670 /* init_menu_items (lpmm); */ |
13434 | 671 |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
672 for (tail = menu; !NILP (tail); tail = Fcdr (tail)) |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
673 { |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
674 Lisp_Object elt, pane_name, pane_data; |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
675 HMENU new_hmenu; |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
676 |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
677 elt = Fcar (tail); |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
678 pane_name = Fcar (elt); |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
679 CHECK_STRING (pane_name, 0); |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
680 pane_data = Fcdr (elt); |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
681 CHECK_CONS (pane_data, 0); |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
682 |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
683 if (XSTRING (pane_name)->data[0] == 0) |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
684 { |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
685 list_of_items (hmenu, lpmm, pane_data); |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
686 } |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
687 else |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
688 { |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
689 new_hmenu = list_of_items (NULL, lpmm, pane_data); |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
690 if (new_hmenu == NULL) goto error; |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
691 |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
692 AppendMenu (hmenu, MF_POPUP, (UINT)new_hmenu, |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
693 (char *) XSTRING (pane_name)->data); |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
694 } |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
695 } |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
696 } |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
697 else |
13434 | 698 { |
699 Lisp_Object elt, pane_name, pane_data; | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
700 |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
701 elt = Fcar (menu); |
13434 | 702 pane_name = Fcar (elt); |
703 CHECK_STRING (pane_name, 0); | |
704 pane_data = Fcdr (elt); | |
705 CHECK_CONS (pane_data, 0); | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
706 hmenu = list_of_items (NULL, lpmm, pane_data); |
13434 | 707 } |
708 return (hmenu); | |
709 | |
710 error: | |
711 DestroyMenu (hmenu); | |
712 | |
713 return (NULL); | |
714 } | |
715 | |
716 /* Push the items in a single pane defined by the alist PANE. */ | |
717 | |
718 static HMENU | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
719 list_of_items (hmenu, lpmm, pane) |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
720 HMENU hmenu; |
13434 | 721 menu_map * lpmm; |
722 Lisp_Object pane; | |
723 { | |
724 Lisp_Object tail, item, item1; | |
725 | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
726 if (hmenu == NULL) |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
727 { |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
728 hmenu = CreatePopupMenu (); |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
729 if (hmenu == NULL) return NULL; |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
730 } |
13434 | 731 |
732 for (tail = pane; !NILP (tail); tail = Fcdr (tail)) | |
733 { | |
734 item = Fcar (tail); | |
735 if (STRINGP (item)) | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
736 add_menu_item (lpmm, hmenu, item, 0, Qnil, Qnil); |
13434 | 737 else if (NILP (item)) |
738 add_left_right_boundary (); | |
739 else | |
740 { | |
741 CHECK_CONS (item, 0); | |
742 item1 = Fcar (item); | |
743 CHECK_STRING (item1, 1); | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
744 add_menu_item (lpmm, hmenu, item1, 1, Fcdr (item), Qnil); |
13434 | 745 } |
746 } | |
747 | |
748 return (hmenu); | |
749 } | |
750 | |
751 | |
752 HMENU | |
753 create_menu_items (lpmm, menu, notreal) | |
754 menu_map * lpmm; | |
755 Lisp_Object menu; | |
756 int notreal; | |
757 { | |
758 Lisp_Object title; | |
759 Lisp_Object keymap, tem; | |
760 HMENU hmenu; | |
761 | |
762 title = Qnil; | |
763 | |
764 /* Decode the menu items from what was specified. */ | |
765 | |
766 keymap = Fkeymapp (menu); | |
767 tem = Qnil; | |
768 if (XTYPE (menu) == Lisp_Cons) | |
769 tem = Fkeymapp (Fcar (menu)); | |
770 | |
771 if (!NILP (keymap)) | |
772 { | |
773 /* We were given a keymap. Extract menu info from the keymap. */ | |
774 Lisp_Object prompt; | |
775 keymap = get_keymap (menu); | |
776 | |
777 /* Extract the detailed info to make one pane. */ | |
778 hmenu = keymap_panes (lpmm, &keymap, 1, notreal); | |
779 | |
780 #if 0 | |
781 /* Search for a string appearing directly as an element of the keymap. | |
782 That string is the title of the menu. */ | |
783 prompt = map_prompt (keymap); | |
784 | |
785 /* Make that be the pane title of the first pane. */ | |
786 if (!NILP (prompt) && menu_items_n_panes >= 0) | |
787 XVECTOR (menu_items)->contents[MENU_ITEMS_PANE_NAME] = prompt; | |
788 #endif | |
789 } | |
790 else if (!NILP (tem)) | |
791 { | |
792 /* We were given a list of keymaps. */ | |
793 int nmaps = XFASTINT (Flength (menu)); | |
794 Lisp_Object *maps | |
795 = (Lisp_Object *) alloca (nmaps * sizeof (Lisp_Object)); | |
796 int i; | |
797 | |
798 title = Qnil; | |
799 | |
800 /* The first keymap that has a prompt string | |
801 supplies the menu title. */ | |
802 for (tem = menu, i = 0; XTYPE (tem) == Lisp_Cons; tem = Fcdr (tem)) | |
803 { | |
804 Lisp_Object prompt; | |
805 | |
806 maps[i++] = keymap = get_keymap (Fcar (tem)); | |
807 #if 0 | |
808 prompt = map_prompt (keymap); | |
809 if (NILP (title) && !NILP (prompt)) | |
810 title = prompt; | |
811 #endif | |
812 } | |
813 | |
814 /* Extract the detailed info to make one pane. */ | |
815 hmenu = keymap_panes (lpmm, maps, nmaps, notreal); | |
816 | |
817 #if 0 | |
818 /* Make the title be the pane title of the first pane. */ | |
819 if (!NILP (title) && menu_items_n_panes >= 0) | |
820 XVECTOR (menu_items)->contents[MENU_ITEMS_PANE_NAME] = title; | |
821 #endif | |
822 } | |
823 else | |
824 { | |
825 /* We were given an old-fashioned menu. */ | |
826 title = Fcar (menu); | |
827 CHECK_STRING (title, 1); | |
828 | |
829 hmenu = list_of_panes (lpmm, Fcdr (menu)); | |
830 } | |
831 | |
832 return (hmenu); | |
833 } | |
834 | |
835 /* This is a recursive subroutine of keymap_panes. | |
836 It handles one keymap, KEYMAP. | |
837 The other arguments are passed along | |
838 or point to local variables of the previous function. | |
839 If NOTREAL is nonzero, | |
840 don't bother really computing whether an item is enabled. */ | |
841 | |
842 Lisp_Object | |
843 get_single_keymap_event (keymap, lpnum) | |
844 Lisp_Object keymap; | |
845 int * lpnum; | |
846 { | |
847 Lisp_Object pending_maps; | |
848 Lisp_Object tail, item, item1, item_string, table; | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
849 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; |
13434 | 850 |
851 pending_maps = Qnil; | |
852 | |
853 for (tail = keymap; XTYPE (tail) == Lisp_Cons; tail = XCONS (tail)->cdr) | |
854 { | |
855 /* Look at each key binding, and if it has a menu string, | |
856 make a menu item from it. */ | |
857 | |
858 item = XCONS (tail)->car; | |
859 | |
860 if (XTYPE (item) == Lisp_Cons) | |
861 { | |
862 item1 = XCONS (item)->cdr; | |
863 | |
864 if (CONSP (item1)) | |
865 { | |
866 item_string = XCONS (item1)->car; | |
867 if (XTYPE (item_string) == Lisp_String) | |
868 { | |
869 /* This is the real definition--the function to run. */ | |
870 | |
871 Lisp_Object def; | |
872 | |
873 /* These are the saved equivalent keyboard key sequence | |
874 and its key-description. */ | |
875 | |
876 Lisp_Object descrip; | |
877 Lisp_Object tem, enabled; | |
878 | |
879 /* GCPRO because ...enabled_p will call eval | |
880 and ..._equiv_key may autoload something. | |
881 Protecting KEYMAP preserves everything we use; | |
882 aside from that, must protect whatever might be | |
883 a string. Since there's no GCPRO5, we refetch | |
884 item_string instead of protecting it. */ | |
885 | |
886 descrip = def = Qnil; | |
887 GCPRO3 (keymap, pending_maps, def); | |
888 | |
889 def = menu_item_equiv_key (item_string, item1, &descrip); | |
890 | |
891 UNGCPRO; | |
892 | |
893 item_string = XCONS (item1)->car; | |
894 | |
895 tem = Fkeymapp (def); | |
896 if (XSTRING (item_string)->data[0] == '@' && !NILP (tem)) | |
897 { | |
898 pending_maps = Fcons (Fcons (def, | |
899 Fcons (item_string, | |
900 XCONS (item)->car)), | |
901 pending_maps); | |
902 } | |
903 else | |
904 { | |
905 Lisp_Object submap; | |
906 | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
907 GCPRO5 (keymap, pending_maps, item, item_string, descrip); |
13434 | 908 |
909 submap = get_keymap_1 (def, 0, 1); | |
910 | |
911 UNGCPRO; | |
912 | |
913 if (NILP (submap)) | |
914 { | |
915 if (--(*lpnum) == 0) | |
916 { | |
917 return (Fcons (XCONS (item)->car, Qnil)); | |
918 } | |
919 } | |
920 else | |
921 /* Display a submenu. */ | |
922 { | |
923 Lisp_Object event = get_single_keymap_event (submap, | |
924 lpnum); | |
925 | |
926 if (*lpnum <= 0) | |
927 { | |
928 if (!NILP (XCONS (item)->car)) | |
929 event = Fcons (XCONS (item)->car, event); | |
930 | |
931 return (event); | |
932 } | |
933 } | |
934 } | |
935 } | |
936 } | |
937 } | |
938 else if (VECTORP (item)) | |
939 { | |
940 /* Loop over the char values represented in the vector. */ | |
941 int len = XVECTOR (item)->size; | |
942 int c; | |
943 for (c = 0; c < len; c++) | |
944 { | |
945 Lisp_Object character; | |
946 XSETFASTINT (character, c); | |
947 item1 = XVECTOR (item)->contents[c]; | |
948 if (XTYPE (item1) == Lisp_Cons) | |
949 { | |
950 item_string = XCONS (item1)->car; | |
951 if (XTYPE (item_string) == Lisp_String) | |
952 { | |
953 Lisp_Object def; | |
954 | |
955 /* These are the saved equivalent keyboard key sequence | |
956 and its key-description. */ | |
957 Lisp_Object descrip; | |
958 Lisp_Object tem, enabled; | |
959 | |
960 /* GCPRO because ...enabled_p will call eval | |
961 and ..._equiv_key may autoload something. | |
962 Protecting KEYMAP preserves everything we use; | |
963 aside from that, must protect whatever might be | |
964 a string. Since there's no GCPRO5, we refetch | |
965 item_string instead of protecting it. */ | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
966 GCPRO3 (keymap, pending_maps, def); |
13434 | 967 descrip = def = Qnil; |
968 | |
969 def = menu_item_equiv_key (item_string, item1, &descrip); | |
970 | |
971 UNGCPRO; | |
972 | |
973 item_string = XCONS (item1)->car; | |
974 | |
975 tem = Fkeymapp (def); | |
976 if (XSTRING (item_string)->data[0] == '@' && !NILP (tem)) | |
977 pending_maps = Fcons (Fcons (def, Fcons (item_string, character)), | |
978 pending_maps); | |
979 else | |
980 { | |
981 Lisp_Object submap; | |
982 | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
983 GCPRO5 (keymap, pending_maps, descrip, item_string, descrip); |
13434 | 984 |
985 submap = get_keymap_1 (def, 0, 1); | |
986 | |
987 UNGCPRO; | |
988 | |
989 if (NILP (submap)) | |
990 { | |
991 if (--(*lpnum) == 0) | |
992 { | |
993 return (Fcons (character, Qnil)); | |
994 } | |
995 } | |
996 else | |
997 /* Display a submenu. */ | |
998 { | |
999 Lisp_Object event = get_single_keymap_event (submap, | |
1000 lpnum); | |
1001 | |
1002 if (*lpnum <= 0) | |
1003 { | |
1004 if (!NILP (character)) | |
1005 event = Fcons (character, event); | |
1006 | |
1007 return (event); | |
1008 } | |
1009 } | |
1010 } | |
1011 } | |
1012 } | |
1013 } | |
1014 } | |
1015 } | |
1016 | |
1017 /* Process now any submenus which want to be panes at this level. */ | |
1018 while (!NILP (pending_maps)) | |
1019 { | |
1020 Lisp_Object elt, eltcdr, string; | |
1021 elt = Fcar (pending_maps); | |
1022 eltcdr = XCONS (elt)->cdr; | |
1023 string = XCONS (eltcdr)->car; | |
1024 /* We no longer discard the @ from the beginning of the string here. | |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
15276
diff
changeset
|
1025 Instead, we do this in w32menu_show. */ |
13434 | 1026 { |
1027 Lisp_Object event = get_single_keymap_event (Fcar (elt), lpnum); | |
1028 | |
1029 if (*lpnum <= 0) | |
1030 { | |
1031 if (!NILP (XCONS (eltcdr)->cdr)) | |
1032 event = Fcons (XCONS (eltcdr)->cdr, event); | |
1033 | |
1034 return (event); | |
1035 } | |
1036 } | |
1037 | |
1038 pending_maps = Fcdr (pending_maps); | |
1039 } | |
1040 | |
1041 return (Qnil); | |
1042 } | |
1043 | |
1044 /* Look through KEYMAPS, a vector of keymaps that is NMAPS long, | |
1045 and generate menu panes for them in menu_items. | |
1046 If NOTREAL is nonzero, | |
1047 don't bother really computing whether an item is enabled. */ | |
1048 | |
1049 static Lisp_Object | |
1050 get_keymap_event (keymaps, nmaps, lpnum) | |
1051 Lisp_Object *keymaps; | |
1052 int nmaps; | |
1053 int * lpnum; | |
1054 { | |
1055 int mapno; | |
1056 Lisp_Object event = Qnil; | |
1057 | |
1058 /* Loop over the given keymaps, making a pane for each map. | |
1059 But don't make a pane that is empty--ignore that map instead. | |
1060 P is the number of panes we have made so far. */ | |
1061 for (mapno = 0; mapno < nmaps; mapno++) | |
1062 { | |
1063 event = get_single_keymap_event (keymaps[mapno], lpnum); | |
1064 | |
1065 if (*lpnum <= 0) break; | |
1066 } | |
1067 | |
1068 return (event); | |
1069 } | |
1070 | |
1071 static Lisp_Object | |
1072 get_list_of_items_event (pane, lpnum) | |
1073 Lisp_Object pane; | |
1074 int * lpnum; | |
1075 { | |
1076 Lisp_Object tail, item, item1; | |
1077 | |
1078 for (tail = pane; !NILP (tail); tail = Fcdr (tail)) | |
1079 { | |
1080 item = Fcar (tail); | |
1081 if (STRINGP (item)) | |
1082 { | |
1083 if (-- (*lpnum) == 0) | |
1084 { | |
1085 return (Qnil); | |
1086 } | |
1087 } | |
1088 else if (!NILP (item)) | |
1089 { | |
1090 if (--(*lpnum) == 0) | |
1091 { | |
1092 CHECK_CONS (item, 0); | |
1093 return (Fcdr (item)); | |
1094 } | |
1095 } | |
1096 } | |
1097 | |
1098 return (Qnil); | |
1099 } | |
1100 | |
14036 | 1101 /* Push all the panes and items of a menu described by the |
13434 | 1102 alist-of-alists MENU. |
1103 This handles old-fashioned calls to x-popup-menu. */ | |
1104 | |
1105 static Lisp_Object | |
1106 get_list_of_panes_event (menu, lpnum) | |
1107 Lisp_Object menu; | |
1108 int * lpnum; | |
1109 { | |
1110 Lisp_Object tail; | |
1111 | |
1112 for (tail = menu; !NILP (tail); tail = Fcdr (tail)) | |
1113 { | |
1114 Lisp_Object elt, pane_name, pane_data; | |
1115 Lisp_Object event; | |
1116 | |
1117 elt = Fcar (tail); | |
1118 pane_data = Fcdr (elt); | |
1119 CHECK_CONS (pane_data, 0); | |
1120 | |
1121 event = get_list_of_items_event (pane_data, lpnum); | |
1122 | |
1123 if (*lpnum <= 0) | |
1124 { | |
1125 return (event); | |
1126 } | |
1127 } | |
1128 | |
1129 return (Qnil); | |
1130 } | |
1131 | |
1132 Lisp_Object | |
1133 get_menu_event (menu, lpnum) | |
1134 Lisp_Object menu; | |
1135 int * lpnum; | |
1136 { | |
1137 Lisp_Object keymap, tem; | |
1138 Lisp_Object event; | |
1139 | |
1140 /* Decode the menu items from what was specified. */ | |
1141 | |
1142 keymap = Fkeymapp (menu); | |
1143 tem = Qnil; | |
1144 if (XTYPE (menu) == Lisp_Cons) | |
1145 tem = Fkeymapp (Fcar (menu)); | |
1146 | |
1147 if (!NILP (keymap)) | |
1148 { | |
1149 keymap = get_keymap (menu); | |
1150 | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1151 event = get_keymap_event (&keymap, 1, lpnum); |
13434 | 1152 } |
1153 else if (!NILP (tem)) | |
1154 { | |
1155 /* We were given a list of keymaps. */ | |
1156 int nmaps = XFASTINT (Flength (menu)); | |
1157 Lisp_Object *maps | |
1158 = (Lisp_Object *) alloca (nmaps * sizeof (Lisp_Object)); | |
1159 int i; | |
1160 | |
1161 /* The first keymap that has a prompt string | |
1162 supplies the menu title. */ | |
1163 for (tem = menu, i = 0; XTYPE (tem) == Lisp_Cons; tem = Fcdr (tem)) | |
1164 { | |
1165 Lisp_Object prompt; | |
1166 | |
1167 maps[i++] = keymap = get_keymap (Fcar (tem)); | |
1168 } | |
1169 | |
1170 event = get_keymap_event (maps, nmaps, lpnum); | |
1171 } | |
1172 else | |
1173 { | |
1174 /* We were given an old-fashioned menu. */ | |
1175 event = get_list_of_panes_event (Fcdr (menu), lpnum); | |
1176 } | |
1177 | |
1178 return (event); | |
1179 } | |
1180 | |
1181 DEFUN ("x-popup-menu", Fx_popup_menu, Sx_popup_menu, 2, 2, 0, | |
1182 "Pop up a deck-of-cards menu and return user's selection.\n\ | |
1183 POSITION is a position specification. This is either a mouse button event\n\ | |
1184 or a list ((XOFFSET YOFFSET) WINDOW)\n\ | |
1185 where XOFFSET and YOFFSET are positions in pixels from the top left\n\ | |
1186 corner of WINDOW's frame. (WINDOW may be a frame object instead of a window.)\n\ | |
1187 This controls the position of the center of the first line\n\ | |
1188 in the first pane of the menu, not the top left of the menu as a whole.\n\ | |
1189 If POSITION is t, it means to use the current mouse position.\n\ | |
1190 \n\ | |
1191 MENU is a specifier for a menu. For the simplest case, MENU is a keymap.\n\ | |
1192 The menu items come from key bindings that have a menu string as well as\n\ | |
1193 a definition; actually, the \"definition\" in such a key binding looks like\n\ | |
1194 \(STRING . REAL-DEFINITION). To give the menu a title, put a string into\n\ | |
1195 the keymap as a top-level element.\n\n\ | |
1196 You can also use a list of keymaps as MENU.\n\ | |
1197 Then each keymap makes a separate pane.\n\ | |
1198 When MENU is a keymap or a list of keymaps, the return value\n\ | |
1199 is a list of events.\n\n\ | |
1200 Alternatively, you can specify a menu of multiple panes\n\ | |
1201 with a list of the form (TITLE PANE1 PANE2...),\n\ | |
1202 where each pane is a list of form (TITLE ITEM1 ITEM2...).\n\ | |
1203 Each ITEM is normally a cons cell (STRING . VALUE);\n\ | |
1204 but a string can appear as an item--that makes a nonselectable line\n\ | |
1205 in the menu.\n\ | |
1206 With this form of menu, the return value is VALUE from the chosen item.\n\ | |
1207 \n\ | |
1208 If POSITION is nil, don't display the menu at all, just precalculate the\n\ | |
1209 cached information about equivalent key sequences.") | |
1210 (position, menu) | |
1211 Lisp_Object position, menu; | |
1212 { | |
1213 int number_of_panes, panes; | |
1214 Lisp_Object keymap, tem; | |
1215 int xpos, ypos; | |
1216 Lisp_Object title; | |
1217 char *error_name; | |
1218 Lisp_Object selection; | |
1219 int i, j; | |
1220 FRAME_PTR f; | |
1221 Lisp_Object x, y, window; | |
1222 int keymaps = 0; | |
1223 int menubarp = 0; | |
1224 struct gcpro gcpro1; | |
1225 HMENU hmenu; | |
1226 menu_map mm; | |
1227 | |
1228 if (! NILP (position)) | |
1229 { | |
1230 /* Decode the first argument: find the window and the coordinates. */ | |
16860
247f0b107588
(x-popup-menu): Pass in insist flag to mouse_position_hook.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16729
diff
changeset
|
1231 if (EQ (position, Qt) |
247f0b107588
(x-popup-menu): Pass in insist flag to mouse_position_hook.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16729
diff
changeset
|
1232 || (CONSP (position) && EQ (XCONS (position)->car, Qmenu_bar))) |
13434 | 1233 { |
1234 /* Use the mouse's current position. */ | |
16860
247f0b107588
(x-popup-menu): Pass in insist flag to mouse_position_hook.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16729
diff
changeset
|
1235 FRAME_PTR new_f = selected_frame; |
13434 | 1236 Lisp_Object bar_window; |
1237 int part; | |
1238 unsigned long time; | |
1239 | |
1240 if (mouse_position_hook) | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1241 (*mouse_position_hook) (&new_f, 1, &bar_window, &part, &x, &y, |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1242 &time); |
13434 | 1243 if (new_f != 0) |
1244 XSETFRAME (window, new_f); | |
1245 else | |
1246 { | |
1247 window = selected_window; | |
1248 XSETFASTINT (x, 0); | |
1249 XSETFASTINT (y, 0); | |
1250 } | |
1251 } | |
1252 else | |
1253 { | |
1254 tem = Fcar (position); | |
1255 if (CONSP (tem)) | |
1256 { | |
1257 window = Fcar (Fcdr (position)); | |
1258 x = Fcar (tem); | |
1259 y = Fcar (Fcdr (tem)); | |
1260 } | |
1261 else | |
1262 { | |
1263 tem = Fcar (Fcdr (position)); /* EVENT_START (position) */ | |
1264 window = Fcar (tem); /* POSN_WINDOW (tem) */ | |
1265 tem = Fcar (Fcdr (Fcdr (tem))); /* POSN_WINDOW_POSN (tem) */ | |
1266 x = Fcar (tem); | |
1267 y = Fcdr (tem); | |
1268 | |
1269 /* Determine whether this menu is handling a menu bar click. */ | |
1270 tem = Fcar (Fcdr (Fcar (Fcdr (position)))); | |
1271 if (CONSP (tem) && EQ (Fcar (tem), Qmenu_bar)) | |
1272 menubarp = 1; | |
1273 } | |
1274 } | |
1275 | |
1276 CHECK_NUMBER (x, 0); | |
1277 CHECK_NUMBER (y, 0); | |
1278 | |
1279 /* Decode where to put the menu. */ | |
1280 | |
1281 if (FRAMEP (window)) | |
1282 { | |
1283 f = XFRAME (window); | |
1284 | |
1285 xpos = 0; | |
1286 ypos = 0; | |
1287 } | |
1288 else if (WINDOWP (window)) | |
1289 { | |
1290 CHECK_LIVE_WINDOW (window, 0); | |
1291 f = XFRAME (WINDOW_FRAME (XWINDOW (window))); | |
1292 | |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
15276
diff
changeset
|
1293 xpos = (FONT_WIDTH (f->output_data.w32->font) * XWINDOW (window)->left); |
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
15276
diff
changeset
|
1294 ypos = (f->output_data.w32->line_height * XWINDOW (window)->top); |
13434 | 1295 } |
1296 else | |
1297 /* ??? Not really clean; should be CHECK_WINDOW_OR_FRAME, | |
1298 but I don't want to make one now. */ | |
1299 CHECK_WINDOW (window, 0); | |
1300 | |
1301 xpos += XINT (x); | |
1302 ypos += XINT (y); | |
21612
24a01af0cd38
(Vmenu_updating_frame): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21450
diff
changeset
|
1303 |
24a01af0cd38
(Vmenu_updating_frame): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21450
diff
changeset
|
1304 XSETFRAME (Vmenu_updating_frame, f); |
13434 | 1305 } |
21612
24a01af0cd38
(Vmenu_updating_frame): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21450
diff
changeset
|
1306 Vmenu_updating_frame = Qnil; |
24a01af0cd38
(Vmenu_updating_frame): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21450
diff
changeset
|
1307 |
13434 | 1308 title = Qnil; |
1309 GCPRO1 (title); | |
1310 | |
1311 discard_menu_items (&mm); | |
1312 hmenu = create_menu_items (&mm, menu, NILP (position)); | |
1313 | |
1314 if (NILP (position)) | |
1315 { | |
1316 discard_menu_items (&mm); | |
1317 UNGCPRO; | |
1318 return Qnil; | |
1319 } | |
1320 | |
1321 /* Display them in a menu. */ | |
1322 BLOCK_INPUT; | |
1323 | |
20040
94f90d47cff1
Pass menu handle by value.
Andrew Innes <andrewi@gnu.org>
parents:
19711
diff
changeset
|
1324 selection = w32menu_show (f, xpos, ypos, menu, hmenu, &error_name); |
13434 | 1325 |
1326 UNBLOCK_INPUT; | |
1327 | |
1328 discard_menu_items (&mm); | |
1329 DestroyMenu (hmenu); | |
1330 | |
1331 UNGCPRO; | |
1332 | |
1333 if (error_name) error (error_name); | |
1334 return selection; | |
1335 } | |
1336 | |
1337 DEFUN ("x-popup-dialog", Fx_popup_dialog, Sx_popup_dialog, 2, 2, 0, | |
1338 "Pop up a dialog box and return user's selection.\n\ | |
1339 POSITION specifies which frame to use.\n\ | |
1340 This is normally a mouse button event or a window or frame.\n\ | |
1341 If POSITION is t, it means to use the frame the mouse is on.\n\ | |
1342 The dialog box appears in the middle of the specified frame.\n\ | |
1343 \n\ | |
1344 CONTENTS specifies the alternatives to display in the dialog box.\n\ | |
1345 It is a list of the form (TITLE ITEM1 ITEM2...).\n\ | |
1346 Each ITEM is a cons cell (STRING . VALUE).\n\ | |
1347 The return value is VALUE from the chosen item.\n\n\ | |
1348 An ITEM may also be just a string--that makes a nonselectable item.\n\ | |
1349 An ITEM may also be nil--that means to put all preceding items\n\ | |
1350 on the left of the dialog box and all following items on the right.\n\ | |
1351 \(By default, approximately half appear on each side.)") | |
1352 (position, contents) | |
1353 Lisp_Object position, contents; | |
1354 { | |
1355 FRAME_PTR f; | |
1356 Lisp_Object window; | |
1357 | |
1358 /* Decode the first argument: find the window or frame to use. */ | |
1359 if (EQ (position, Qt)) | |
1360 { | |
1361 /* Decode the first argument: find the window and the coordinates. */ | |
1362 if (EQ (position, Qt)) | |
1363 window = selected_window; | |
1364 } | |
1365 else if (CONSP (position)) | |
1366 { | |
1367 Lisp_Object tem; | |
1368 tem = Fcar (position); | |
1369 if (XTYPE (tem) == Lisp_Cons) | |
1370 window = Fcar (Fcdr (position)); | |
1371 else | |
1372 { | |
1373 tem = Fcar (Fcdr (position)); /* EVENT_START (position) */ | |
1374 window = Fcar (tem); /* POSN_WINDOW (tem) */ | |
1375 } | |
1376 } | |
1377 else if (WINDOWP (position) || FRAMEP (position)) | |
1378 window = position; | |
1379 | |
1380 /* Decode where to put the menu. */ | |
1381 | |
1382 if (FRAMEP (window)) | |
1383 f = XFRAME (window); | |
1384 else if (WINDOWP (window)) | |
1385 { | |
1386 CHECK_LIVE_WINDOW (window, 0); | |
1387 f = XFRAME (WINDOW_FRAME (XWINDOW (window))); | |
1388 } | |
1389 else | |
1390 /* ??? Not really clean; should be CHECK_WINDOW_OR_FRAME, | |
1391 but I don't want to make one now. */ | |
1392 CHECK_WINDOW (window, 0); | |
1393 | |
1394 #if 1 | |
1395 /* Display a menu with these alternatives | |
1396 in the middle of frame F. */ | |
1397 { | |
1398 Lisp_Object x, y, frame, newpos; | |
1399 XSETFRAME (frame, f); | |
1400 XSETINT (x, x_pixel_width (f) / 2); | |
1401 XSETINT (y, x_pixel_height (f) / 2); | |
1402 newpos = Fcons (Fcons (x, Fcons (y, Qnil)), Fcons (frame, Qnil)); | |
1403 | |
1404 return Fx_popup_menu (newpos, | |
1405 Fcons (Fcar (contents), Fcons (contents, Qnil))); | |
1406 } | |
1407 #else | |
1408 { | |
1409 Lisp_Object title; | |
1410 char *error_name; | |
1411 Lisp_Object selection; | |
1412 | |
1413 /* Decode the dialog items from what was specified. */ | |
1414 title = Fcar (contents); | |
1415 CHECK_STRING (title, 1); | |
1416 | |
1417 list_of_panes (Fcons (contents, Qnil)); | |
1418 | |
1419 /* Display them in a dialog box. */ | |
1420 BLOCK_INPUT; | |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
15276
diff
changeset
|
1421 selection = w32_dialog_show (f, 0, 0, title, &error_name); |
13434 | 1422 UNBLOCK_INPUT; |
1423 | |
1424 discard_menu_items (); | |
1425 | |
1426 if (error_name) error (error_name); | |
1427 return selection; | |
1428 } | |
1429 #endif | |
1430 } | |
1431 | |
1432 Lisp_Object | |
1433 get_frame_menubar_event (f, num) | |
1434 FRAME_PTR f; | |
1435 int num; | |
1436 { | |
1437 Lisp_Object tail, items; | |
1438 int i; | |
1439 struct gcpro gcpro1; | |
1440 | |
1441 BLOCK_INPUT; | |
1442 | |
1443 GCPRO1 (items); | |
1444 | |
1445 if (NILP (items = FRAME_MENU_BAR_ITEMS (f))) | |
1446 items = FRAME_MENU_BAR_ITEMS (f) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f)); | |
1447 | |
15110
5a9c77df2706
(get_frame_menubar_event, set_frame_menubar):
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
1448 for (i = 0; i < XVECTOR (items)->size; i += 4) |
13434 | 1449 { |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1450 Lisp_Object event, binding; |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1451 binding = XVECTOR (items)->contents[i + 2]; |
13434 | 1452 |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1453 /* Check to see if this might be a menubar button. It might be |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1454 if it is not a keymap, it is a cons cell, its car is not a |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1455 keymap, and its cdr is nil. */ |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1456 if (NILP (Fkeymapp (binding)) |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1457 && CONSP (binding) |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1458 && NILP (Fkeymapp (XCONS (binding)->car)) |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1459 && NILP (XCONS (binding)->cdr)) |
13434 | 1460 { |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1461 /* The fact that we have to check that this is a string here |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1462 is the reason we don't do all this rigamarole in |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1463 get_menu_event. */ |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1464 if (XTYPE (XVECTOR (items)->contents[i + 1]) == Lisp_String) |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1465 { |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1466 /* This was a menubar button. */ |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1467 if (--num <= 0) |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1468 { |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1469 UNGCPRO; |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1470 UNBLOCK_INPUT; |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1471 return (Fcons (XVECTOR (items)->contents[i], Qnil)); |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1472 } |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1473 } |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1474 } |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1475 else |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1476 { |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1477 event = get_menu_event (binding, &num); |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1478 |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1479 if (num <= 0) |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1480 { |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1481 UNGCPRO; |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1482 UNBLOCK_INPUT; |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1483 return (Fcons (XVECTOR (items)->contents[i], event)); |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1484 } |
13434 | 1485 } |
1486 } | |
1487 | |
1488 UNGCPRO; | |
1489 UNBLOCK_INPUT; | |
1490 | |
1491 return (Qnil); | |
1492 } | |
1493 | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1494 /* Activate the menu bar of frame F. |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1495 This is called from keyboard.c when it gets the |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1496 menu_bar_activate_event out of the Emacs event queue. |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1497 |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1498 To activate the menu bar, we signal to the input thread that it can |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1499 return from the WM_INITMENU message, allowing the normal Windows |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1500 processing of the menus. |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1501 |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1502 But first we recompute the menu bar contents (the whole tree). |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1503 |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1504 This way we can safely execute Lisp code. */ |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1505 |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1506 x_activate_menubar (f) |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1507 FRAME_PTR f; |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1508 { |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1509 set_frame_menubar (f, 0, 1); |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1510 |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1511 /* Lock out further menubar changes while active. */ |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1512 f->output_data.w32->menubar_active = 1; |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1513 |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1514 /* Signal input thread to return from WM_INITMENU. */ |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1515 complete_deferred_msg (FRAME_W32_WINDOW (f), WM_INITMENU, 0); |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1516 } |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1517 |
13434 | 1518 void |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1519 set_frame_menubar (f, first_time, deep_p) |
13434 | 1520 FRAME_PTR f; |
1521 int first_time; | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1522 int deep_p; |
13434 | 1523 { |
1524 Lisp_Object tail, items; | |
1525 HMENU hmenu; | |
1526 int i; | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1527 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
13434 | 1528 menu_map mm; |
15276 | 1529 int count = specpdl_ptr - specpdl; |
1530 | |
1531 struct buffer *prev = current_buffer; | |
1532 Lisp_Object buffer; | |
1533 | |
21612
24a01af0cd38
(Vmenu_updating_frame): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21450
diff
changeset
|
1534 XSETFRAME (Vmenu_updating_frame, f); |
24a01af0cd38
(Vmenu_updating_frame): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21450
diff
changeset
|
1535 |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1536 /* We must not change the menubar when actually in use. */ |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1537 if (f->output_data.w32->menubar_active) |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1538 return; |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1539 |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1540 #if 0 /* I don't see why this should be needed */ |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1541 /* Ensure menubar is up to date when about to be used. */ |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1542 if (f->output_data.w32->pending_menu_activation && !deep_p) |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1543 deep_p = 1; |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1544 #endif |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1545 |
15276 | 1546 buffer = XWINDOW (FRAME_SELECTED_WINDOW (f))->buffer; |
1547 specbind (Qinhibit_quit, Qt); | |
1548 /* Don't let the debugger step into this code | |
1549 because it is not reentrant. */ | |
1550 specbind (Qdebug_on_next_call, Qnil); | |
1551 | |
21450
408fb64bc0cb
(set_frame_menubar): Call Fset_match_data, not
Karl Heuer <kwzh@gnu.org>
parents:
20040
diff
changeset
|
1552 record_unwind_protect (Fset_match_data, Fmatch_data (Qnil, Qnil)); |
15276 | 1553 if (NILP (Voverriding_local_map_menu_flag)) |
1554 { | |
1555 specbind (Qoverriding_terminal_local_map, Qnil); | |
1556 specbind (Qoverriding_local_map, Qnil); | |
1557 } | |
1558 | |
1559 set_buffer_internal_1 (XBUFFER (buffer)); | |
1560 | |
1561 /* Run the Lucid hook. */ | |
1562 call1 (Vrun_hooks, Qactivate_menubar_hook); | |
1563 /* If it has changed current-menubar from previous value, | |
1564 really recompute the menubar from the value. */ | |
1565 if (! NILP (Vlucid_menu_bar_dirty_flag)) | |
1566 call0 (Qrecompute_lucid_menubar); | |
1567 safe_run_hooks (Qmenu_bar_update_hook); | |
13434 | 1568 |
1569 BLOCK_INPUT; | |
1570 | |
1571 GCPRO1 (items); | |
1572 | |
15276 | 1573 items = FRAME_MENU_BAR_ITEMS (f); |
1574 if (NILP (items)) | |
13434 | 1575 items = FRAME_MENU_BAR_ITEMS (f) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f)); |
1576 | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1577 hmenu = f->output_data.w32->menubar_widget; |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1578 if (!hmenu) |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1579 { |
13434 | 1580 hmenu = CreateMenu (); |
1581 if (!hmenu) goto error; | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1582 } |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1583 else |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1584 { |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1585 /* Delete current contents. */ |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1586 while (DeleteMenu (hmenu, 0, MF_BYPOSITION)) |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1587 ; |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1588 } |
13434 | 1589 |
1590 discard_menu_items (&mm); | |
15276 | 1591 UNBLOCK_INPUT; |
13434 | 1592 |
15110
5a9c77df2706
(get_frame_menubar_event, set_frame_menubar):
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
1593 for (i = 0; i < XVECTOR (items)->size; i += 4) |
13434 | 1594 { |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1595 Lisp_Object string, binding; |
13434 | 1596 int keymaps; |
1597 CHAR *error; | |
1598 HMENU new_hmenu; | |
1599 | |
1600 string = XVECTOR (items)->contents[i + 1]; | |
1601 if (NILP (string)) | |
1602 break; | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1603 |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1604 binding = XVECTOR (items)->contents[i + 2]; |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1605 |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1606 if (NILP (Fkeymapp (binding)) |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1607 && CONSP (binding) |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1608 && NILP (Fkeymapp (XCONS (binding)->car)) |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1609 && NILP (XCONS (binding)->cdr)) |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1610 { |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1611 /* This is a menubar button. */ |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1612 Lisp_Object descrip, def; |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1613 Lisp_Object enabled, item; |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1614 item = Fcons (string, Fcar (binding)); |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1615 descrip = def = Qnil; |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1616 UNGCPRO; |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1617 GCPRO4 (items, item, def, string); |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1618 |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1619 def = menu_item_equiv_key (string, item, &descrip); |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1620 enabled = menu_item_enabled_p (def, 0); |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1621 |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1622 UNGCPRO; |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1623 GCPRO1 (items); |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1624 |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1625 add_menu_item (&mm, hmenu, string, enabled, def, Qnil); |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1626 } |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1627 else |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1628 { |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1629 /* Input must not be blocked here because we call general |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1630 Lisp code and internal_condition_case_1. */ |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1631 new_hmenu = create_menu_items (&mm, binding, 0); |
13434 | 1632 |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1633 if (!new_hmenu) |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1634 continue; |
13434 | 1635 |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1636 BLOCK_INPUT; |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1637 AppendMenu (hmenu, MF_POPUP, (UINT)new_hmenu, |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1638 (char *) XSTRING (string)->data); |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1639 UNBLOCK_INPUT; |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1640 } |
13434 | 1641 } |
1642 | |
15276 | 1643 BLOCK_INPUT; |
13434 | 1644 { |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1645 HMENU old = f->output_data.w32->menubar_widget; |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
15276
diff
changeset
|
1646 SetMenu (FRAME_W32_WINDOW (f), hmenu); |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1647 f->output_data.w32->menubar_widget = hmenu; |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1648 /* Causes flicker when menu bar is updated |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1649 DrawMenuBar (FRAME_W32_WINDOW (f)); */ |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1650 |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1651 /* Force the window size to be recomputed so that the frame's text |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1652 area remains the same, if menubar has just been created. */ |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1653 if (old == NULL) |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1654 x_set_window_size (f, 0, FRAME_WIDTH (f), FRAME_HEIGHT (f)); |
13434 | 1655 } |
1656 | |
1657 error: | |
15276 | 1658 set_buffer_internal_1 (prev); |
13434 | 1659 UNGCPRO; |
1660 UNBLOCK_INPUT; | |
15276 | 1661 unbind_to (count, Qnil); |
13434 | 1662 } |
1663 | |
1664 void | |
1665 free_frame_menubar (f) | |
1666 FRAME_PTR f; | |
1667 { | |
1668 BLOCK_INPUT; | |
1669 | |
1670 { | |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
15276
diff
changeset
|
1671 HMENU old = GetMenu (FRAME_W32_WINDOW (f)); |
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
15276
diff
changeset
|
1672 SetMenu (FRAME_W32_WINDOW (f), NULL); |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1673 f->output_data.w32->menubar_widget = NULL; |
13434 | 1674 DestroyMenu (old); |
1675 } | |
1676 | |
1677 UNBLOCK_INPUT; | |
1678 } | |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
15276
diff
changeset
|
1679 /* Called from Fw32_create_frame to create the initial menubar of a frame |
13434 | 1680 before it is mapped, so that the window is mapped with the menubar already |
1681 there instead of us tacking it on later and thrashing the window after it | |
1682 is visible. */ | |
1683 void | |
1684 initialize_frame_menubar (f) | |
1685 FRAME_PTR f; | |
1686 { | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1687 set_frame_menubar (f, 1, 1); |
13434 | 1688 } |
1689 | |
1690 #if 0 | |
1691 /* If the mouse has moved to another menu bar item, | |
1692 return 1 and unread a button press event for that item. | |
1693 Otherwise return 0. */ | |
1694 | |
1695 static int | |
1696 check_mouse_other_menu_bar (f) | |
1697 FRAME_PTR f; | |
1698 { | |
1699 FRAME_PTR new_f; | |
1700 Lisp_Object bar_window; | |
1701 int part; | |
1702 Lisp_Object x, y; | |
1703 unsigned long time; | |
1704 | |
16860
247f0b107588
(x-popup-menu): Pass in insist flag to mouse_position_hook.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16729
diff
changeset
|
1705 (*mouse_position_hook) (&new_f, 1, &bar_window, &part, &x, &y, &time); |
13434 | 1706 |
1707 if (f == new_f && other_menu_bar_item_p (f, x, y)) | |
1708 { | |
1709 unread_menu_bar_button (f, x); | |
1710 return 1; | |
1711 } | |
1712 | |
1713 return 0; | |
1714 } | |
1715 #endif | |
1716 | |
1717 | |
1718 #if 0 | |
1719 static HMENU | |
1720 create_menu (keymaps, error) | |
1721 int keymaps; | |
1722 char **error; | |
1723 { | |
1724 HMENU hmenu = NULL; /* the menu we are currently working on */ | |
1725 HMENU first_hmenu = NULL; | |
1726 | |
1727 HMENU *submenu_stack = (HMENU *) alloca (menu_items_used * sizeof (HMENU)); | |
1728 Lisp_Object *subprefix_stack = (Lisp_Object *) alloca (menu_items_used * | |
1729 sizeof (Lisp_Object)); | |
1730 int submenu_depth = 0; | |
1731 int i; | |
1732 | |
1733 if (menu_items_used <= MENU_ITEMS_PANE_LENGTH) | |
1734 { | |
1735 *error = "Empty menu"; | |
1736 return NULL; | |
1737 } | |
1738 | |
1739 i = 0; | |
1740 | |
1741 /* Loop over all panes and items, filling in the tree. */ | |
1742 | |
1743 while (i < menu_items_used) | |
1744 { | |
1745 if (EQ (XVECTOR (menu_items)->contents[i], Qnil)) | |
1746 { | |
1747 submenu_stack[submenu_depth++] = hmenu; | |
1748 i++; | |
1749 } | |
1750 else if (EQ (XVECTOR (menu_items)->contents[i], Qlambda)) | |
1751 { | |
1752 hmenu = submenu_stack[--submenu_depth]; | |
1753 i++; | |
1754 } | |
1755 #if 0 | |
1756 else if (EQ (XVECTOR (menu_items)->contents[i], Qt) | |
1757 && submenu_depth != 0) | |
1758 i += MENU_ITEMS_PANE_LENGTH; | |
1759 #endif | |
1760 /* Ignore a nil in the item list. | |
1761 It's meaningful only for dialog boxes. */ | |
1762 else if (EQ (XVECTOR (menu_items)->contents[i], Qquote)) | |
1763 i += 1; | |
1764 else if (EQ (XVECTOR (menu_items)->contents[i], Qt)) | |
1765 { | |
1766 /* Create a new pane. */ | |
1767 | |
1768 Lisp_Object pane_name; | |
1769 char *pane_string; | |
1770 | |
1771 pane_name = XVECTOR (menu_items)->contents[i + MENU_ITEMS_PANE_NAME]; | |
1772 pane_string = (NILP (pane_name) ? "" : (char *) XSTRING (pane_name)->data); | |
1773 | |
1774 if (!hmenu || strcmp (pane_string, "")) | |
1775 { | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1776 HMENU new_hmenu = CreatePopupMenu (); |
13434 | 1777 |
1778 if (!new_hmenu) | |
1779 { | |
1780 *error = "Could not create menu pane"; | |
1781 goto error; | |
1782 } | |
1783 | |
1784 if (hmenu) | |
1785 { | |
1786 AppendMenu (hmenu, MF_POPUP, (UINT)new_hmenu, pane_string); | |
1787 } | |
1788 | |
1789 hmenu = new_hmenu; | |
1790 | |
1791 if (!first_hmenu) first_hmenu = hmenu; | |
1792 } | |
1793 i += MENU_ITEMS_PANE_LENGTH; | |
1794 } | |
1795 else | |
1796 { | |
1797 /* Create a new item within current pane. */ | |
1798 | |
1799 Lisp_Object item_name, enable, descrip; | |
1800 UINT fuFlags; | |
1801 | |
1802 item_name = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_NAME]; | |
1803 enable = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_ENABLE]; | |
1804 // descrip = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_EQUIV_KEY]; | |
1805 | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1806 if (name_is_separator (item_name)) |
13434 | 1807 fuFlags = MF_SEPARATOR; |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1808 else if (NILP (enable) || !XUINT (enable)) |
13434 | 1809 fuFlags = MF_STRING | MF_GRAYED; |
1810 else | |
1811 fuFlags = MF_STRING; | |
1812 | |
1813 AppendMenu (hmenu, | |
1814 fuFlags, | |
1815 i, | |
1816 (char *) XSTRING (item_name)->data); | |
1817 | |
1818 // if (!NILP (descrip)) | |
1819 // hmenu->key = (char *) XSTRING (descrip)->data; | |
1820 | |
1821 i += MENU_ITEMS_ITEM_LENGTH; | |
1822 } | |
1823 } | |
1824 | |
1825 return (first_hmenu); | |
1826 | |
1827 error: | |
1828 if (first_hmenu) DestroyMenu (first_hmenu); | |
1829 return (NULL); | |
1830 } | |
1831 | |
1832 #endif | |
1833 | |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
15276
diff
changeset
|
1834 /* w32menu_show actually displays a menu using the panes and items in |
13434 | 1835 menu_items and returns the value selected from it. |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
15276
diff
changeset
|
1836 There are two versions of w32menu_show, one for Xt and one for Xlib. |
13434 | 1837 Both assume input is blocked by the caller. */ |
1838 | |
1839 /* F is the frame the menu is for. | |
1840 X and Y are the frame-relative specified position, | |
1841 relative to the inside upper left corner of the frame F. | |
1842 MENUBARP is 1 if the click that asked for this menu came from the menu bar. | |
1843 KEYMAPS is 1 if this menu was specified with keymaps; | |
1844 in that case, we return a list containing the chosen item's value | |
1845 and perhaps also the pane's prefix. | |
1846 TITLE is the specified menu title. | |
1847 ERROR is a place to store an error message string in case of failure. | |
1848 (We return nil on failure, but the value doesn't actually matter.) */ | |
1849 | |
1850 | |
1851 static Lisp_Object | |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
15276
diff
changeset
|
1852 w32menu_show (f, x, y, menu, hmenu, error) |
13434 | 1853 FRAME_PTR f; |
1854 int x; | |
1855 int y; | |
1856 Lisp_Object menu; | |
1857 HMENU hmenu; | |
1858 char **error; | |
1859 { | |
1860 int i , menu_selection; | |
1861 POINT pos; | |
1862 | |
1863 *error = NULL; | |
1864 | |
1865 if (!hmenu) | |
1866 { | |
1867 *error = "Empty menu"; | |
1868 return Qnil; | |
1869 } | |
1870 | |
1871 pos.x = x; | |
1872 pos.y = y; | |
1873 | |
1874 /* Offset the coordinates to root-relative. */ | |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
15276
diff
changeset
|
1875 ClientToScreen (FRAME_W32_WINDOW (f), &pos); |
13434 | 1876 |
1877 #if 0 | |
1878 /* If the mouse moves out of the menu before we show the menu, | |
1879 don't show it at all. */ | |
1880 if (check_mouse_other_menu_bar (f)) | |
1881 { | |
1882 DestroyMenu (hmenu); | |
1883 return Qnil; | |
1884 } | |
1885 #endif | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1886 |
13434 | 1887 /* Display the menu. */ |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1888 menu_selection = SendMessage (FRAME_W32_WINDOW (f), |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1889 WM_EMACS_TRACKPOPUPMENU, |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1890 (WPARAM)hmenu, (LPARAM)&pos); |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1891 |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1892 /* Clean up extraneous mouse events which might have been generated |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1893 during the call. */ |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1894 discard_mouse_events (); |
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1895 |
13434 | 1896 if (menu_selection == -1) |
1897 { | |
1898 *error = "Invalid menu specification"; | |
1899 return Qnil; | |
1900 } | |
1901 | |
1902 /* Find the selected item, and its pane, to return | |
1903 the proper value. */ | |
1904 | |
1905 #if 1 | |
1906 if (menu_selection > 0) | |
1907 { | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1908 return get_menu_event (menu, &menu_selection); |
13434 | 1909 } |
1910 #else | |
1911 if (menu_selection > 0 && menu_selection <= lpmm->menu_items_used) | |
1912 { | |
1913 return (XVECTOR (lpmm->menu_items)->contents[menu_selection - 1]); | |
1914 } | |
1915 #endif | |
19711
dc9694ee3f70
(init_menu_items): Disable code.
Geoff Voelker <voelker@cs.washington.edu>
parents:
16884
diff
changeset
|
1916 |
13434 | 1917 return Qnil; |
1918 } | |
1919 | |
1920 #if 0 | |
1921 static char * button_names [] = | |
1922 { | |
1923 "button1", "button2", "button3", "button4", "button5", | |
1924 "button6", "button7", "button8", "button9", "button10" | |
1925 }; | |
1926 | |
1927 static Lisp_Object | |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
15276
diff
changeset
|
1928 w32_dialog_show (f, menubarp, keymaps, title, error) |
13434 | 1929 FRAME_PTR f; |
1930 int menubarp; | |
1931 int keymaps; | |
1932 Lisp_Object title; | |
1933 char **error; | |
1934 { | |
1935 int i, nb_buttons=0; | |
1936 HMENU hmenu; | |
1937 char dialog_name[6]; | |
1938 | |
1939 /* Number of elements seen so far, before boundary. */ | |
1940 int left_count = 0; | |
1941 /* 1 means we've seen the boundary between left-hand elts and right-hand. */ | |
1942 int boundary_seen = 0; | |
1943 | |
1944 *error = NULL; | |
1945 | |
1946 if (menu_items_n_panes > 1) | |
1947 { | |
1948 *error = "Multiple panes in dialog box"; | |
1949 return Qnil; | |
1950 } | |
1951 | |
1952 /* Create a tree of widget_value objects | |
1953 representing the text label and buttons. */ | |
1954 { | |
1955 Lisp_Object pane_name, prefix; | |
1956 char *pane_string; | |
1957 pane_name = XVECTOR (menu_items)->contents[MENU_ITEMS_PANE_NAME]; | |
1958 prefix = XVECTOR (menu_items)->contents[MENU_ITEMS_PANE_PREFIX]; | |
1959 pane_string = (NILP (pane_name) | |
1960 ? "" : (char *) XSTRING (pane_name)->data); | |
1961 prev_wv = malloc_widget_value (); | |
1962 prev_wv->value = pane_string; | |
1963 if (keymaps && !NILP (prefix)) | |
1964 prev_wv->name++; | |
1965 prev_wv->enabled = 1; | |
1966 prev_wv->name = "message"; | |
1967 first_wv = prev_wv; | |
1968 | |
1969 /* Loop over all panes and items, filling in the tree. */ | |
1970 i = MENU_ITEMS_PANE_LENGTH; | |
1971 while (i < menu_items_used) | |
1972 { | |
1973 | |
1974 /* Create a new item within current pane. */ | |
1975 Lisp_Object item_name, enable, descrip; | |
1976 item_name = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_NAME]; | |
1977 enable = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_ENABLE]; | |
1978 descrip | |
1979 = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_EQUIV_KEY]; | |
1980 | |
1981 if (NILP (item_name)) | |
1982 { | |
1983 free_menubar_widget_value_tree (first_wv); | |
1984 *error = "Submenu in dialog items"; | |
1985 return Qnil; | |
1986 } | |
1987 if (EQ (item_name, Qquote)) | |
1988 { | |
1989 /* This is the boundary between left-side elts | |
1990 and right-side elts. Stop incrementing right_count. */ | |
1991 boundary_seen = 1; | |
1992 i++; | |
1993 continue; | |
1994 } | |
1995 if (nb_buttons >= 10) | |
1996 { | |
1997 free_menubar_widget_value_tree (first_wv); | |
1998 *error = "Too many dialog items"; | |
1999 return Qnil; | |
2000 } | |
2001 | |
2002 wv = malloc_widget_value (); | |
2003 prev_wv->next = wv; | |
2004 wv->name = (char *) button_names[nb_buttons]; | |
2005 if (!NILP (descrip)) | |
2006 wv->key = (char *) XSTRING (descrip)->data; | |
2007 wv->value = (char *) XSTRING (item_name)->data; | |
2008 wv->call_data = (void *) &XVECTOR (menu_items)->contents[i]; | |
2009 wv->enabled = !NILP (enable); | |
2010 prev_wv = wv; | |
2011 | |
2012 if (! boundary_seen) | |
2013 left_count++; | |
2014 | |
2015 nb_buttons++; | |
2016 i += MENU_ITEMS_ITEM_LENGTH; | |
2017 } | |
2018 | |
2019 /* If the boundary was not specified, | |
2020 by default put half on the left and half on the right. */ | |
2021 if (! boundary_seen) | |
2022 left_count = nb_buttons - nb_buttons / 2; | |
2023 | |
2024 wv = malloc_widget_value (); | |
2025 wv->name = dialog_name; | |
2026 | |
2027 /* Dialog boxes use a really stupid name encoding | |
2028 which specifies how many buttons to use | |
2029 and how many buttons are on the right. | |
2030 The Q means something also. */ | |
2031 dialog_name[0] = 'Q'; | |
2032 dialog_name[1] = '0' + nb_buttons; | |
2033 dialog_name[2] = 'B'; | |
2034 dialog_name[3] = 'R'; | |
2035 /* Number of buttons to put on the right. */ | |
2036 dialog_name[4] = '0' + nb_buttons - left_count; | |
2037 dialog_name[5] = 0; | |
2038 wv->contents = first_wv; | |
2039 first_wv = wv; | |
2040 } | |
2041 | |
2042 /* Actually create the dialog. */ | |
2043 dialog_id = ++popup_id_tick; | |
2044 menu = lw_create_widget (first_wv->name, "dialog", dialog_id, first_wv, | |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
15276
diff
changeset
|
2045 f->output_data.w32->widget, 1, 0, |
13434 | 2046 dialog_selection_callback, 0); |
2047 #if 0 /* This causes crashes, and seems to be redundant -- rms. */ | |
2048 lw_modify_all_widgets (dialog_id, first_wv, True); | |
2049 #endif | |
2050 lw_modify_all_widgets (dialog_id, first_wv->contents, True); | |
2051 /* Free the widget_value objects we used to specify the contents. */ | |
2052 free_menubar_widget_value_tree (first_wv); | |
2053 | |
2054 /* No selection has been chosen yet. */ | |
2055 menu_item_selection = 0; | |
2056 | |
2057 /* Display the menu. */ | |
2058 lw_pop_up_all_widgets (dialog_id); | |
2059 | |
2060 /* Process events that apply to the menu. */ | |
2061 while (1) | |
2062 { | |
2063 XEvent event; | |
2064 | |
2065 XtAppNextEvent (Xt_app_con, &event); | |
2066 if (event.type == ButtonRelease) | |
2067 { | |
2068 XtDispatchEvent (&event); | |
2069 break; | |
2070 } | |
2071 else if (event.type == Expose) | |
2072 process_expose_from_menu (event); | |
2073 XtDispatchEvent (&event); | |
2074 if (XtWindowToWidget(XDISPLAY event.xany.window) != menu) | |
2075 { | |
2076 queue_tmp = (struct event_queue *) malloc (sizeof (struct event_queue)); | |
2077 | |
2078 if (queue_tmp != NULL) | |
2079 { | |
2080 queue_tmp->event = event; | |
2081 queue_tmp->next = queue; | |
2082 queue = queue_tmp; | |
2083 } | |
2084 } | |
2085 } | |
2086 pop_down: | |
2087 | |
2088 /* State that no mouse buttons are now held. | |
2089 That is not necessarily true, but the fiction leads to reasonable | |
2090 results, and it is a pain to ask which are actually held now | |
2091 or track this in the loop above. */ | |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
15276
diff
changeset
|
2092 w32_mouse_grabbed = 0; |
13434 | 2093 |
2094 /* Unread any events that we got but did not handle. */ | |
2095 while (queue != NULL) | |
2096 { | |
2097 queue_tmp = queue; | |
2098 XPutBackEvent (XDISPLAY &queue_tmp->event); | |
2099 queue = queue_tmp->next; | |
2100 free ((char *)queue_tmp); | |
2101 /* Cause these events to get read as soon as we UNBLOCK_INPUT. */ | |
2102 interrupt_input_pending = 1; | |
2103 } | |
2104 | |
2105 /* Find the selected item, and its pane, to return | |
2106 the proper value. */ | |
2107 if (menu_item_selection != 0) | |
2108 { | |
2109 Lisp_Object prefix; | |
2110 | |
2111 prefix = Qnil; | |
2112 i = 0; | |
2113 while (i < menu_items_used) | |
2114 { | |
2115 Lisp_Object entry; | |
2116 | |
2117 if (EQ (XVECTOR (menu_items)->contents[i], Qt)) | |
2118 { | |
2119 prefix | |
2120 = XVECTOR (menu_items)->contents[i + MENU_ITEMS_PANE_PREFIX]; | |
2121 i += MENU_ITEMS_PANE_LENGTH; | |
2122 } | |
2123 else | |
2124 { | |
2125 entry | |
2126 = XVECTOR (menu_items)->contents[i + MENU_ITEMS_ITEM_VALUE]; | |
2127 if (menu_item_selection == &XVECTOR (menu_items)->contents[i]) | |
2128 { | |
2129 if (keymaps != 0) | |
2130 { | |
2131 entry = Fcons (entry, Qnil); | |
2132 if (!NILP (prefix)) | |
2133 entry = Fcons (prefix, entry); | |
2134 } | |
2135 return entry; | |
2136 } | |
2137 i += MENU_ITEMS_ITEM_LENGTH; | |
2138 } | |
2139 } | |
2140 } | |
2141 | |
2142 return Qnil; | |
2143 } | |
2144 #endif | |
2145 | |
16588
481b7874a1e9
Change identifiers of the form win32* to w32*.
Geoff Voelker <voelker@cs.washington.edu>
parents:
15276
diff
changeset
|
2146 syms_of_w32menu () |
13434 | 2147 { |
15276 | 2148 Qdebug_on_next_call = intern ("debug-on-next-call"); |
2149 staticpro (&Qdebug_on_next_call); | |
2150 | |
21612
24a01af0cd38
(Vmenu_updating_frame): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21450
diff
changeset
|
2151 DEFVAR_LISP ("menu-updating-frame", &Vmenu_updating_frame, |
24a01af0cd38
(Vmenu_updating_frame): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21450
diff
changeset
|
2152 "Frame for which we are updating a menu\n\ |
24a01af0cd38
(Vmenu_updating_frame): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21450
diff
changeset
|
2153 The enable predicate for a menu command should check this variable."); |
24a01af0cd38
(Vmenu_updating_frame): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21450
diff
changeset
|
2154 Vmenu_updating_frame = Qnil; |
24a01af0cd38
(Vmenu_updating_frame): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
21450
diff
changeset
|
2155 |
13434 | 2156 defsubr (&Sx_popup_menu); |
2157 defsubr (&Sx_popup_dialog); | |
2158 } |