annotate src/menubar-msw.c @ 367:a4f53d9b3154 r21-1-13

Import from CVS: tag r21-1-13
author cvs
date Mon, 13 Aug 2007 11:01:07 +0200
parents 972bbb6d6ca2
children cc15677e0335
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1 /* Implements an elisp-programmable menubar -- Win32
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
2 Copyright (C) 1993, 1994 Free Software Foundation, Inc.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
3 Copyright (C) 1995 Tinker Systems and INS Engineering Corp.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
4 Copyright (C) 1997 Kirill M. Katsnelson <kkm@kis.ru>
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
5
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
6 This file is part of XEmacs.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
7
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
8 XEmacs is free software; you can redistribute it and/or modify it
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
10 Free Software Foundation; either version 2, or (at your option) any
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
11 later version.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
12
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
16 for more details.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
17
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
19 along with XEmacs; see the file COPYING. If not, write to
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
21 Boston, MA 02111-1307, USA. */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
22
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
23 /* Synched up with: Not in FSF. */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
24
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
25 /* Autorship:
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
26 Initially written by kkm 12/24/97,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
27 peeking into and copying stuff from menubar-x.c
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
28 */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
29
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
30 /* Algotirhm for handling menus is as follows. When window's menubar
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
31 * is created, current-menubar is not traversed in depth. Rather, only
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
32 * top level items, both items and pulldowns, are added to the
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
33 * menubar. Each pulldown is initially empty. When a pulldown is
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
34 * selected and about to open, corresponding element of
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
35 * current-menubar is found, and the newly open pulldown is
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
36 * populated. This is made again in the same non-recursive manner.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
37 *
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
38 * This algorithm uses hash tables to find out element of the menu
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
39 * descriptor list given menu handle. The key is an opaque ptr data
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
40 * type, keeping menu handle, and the value is a list of strings
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
41 * representing the path from the root of the menu to the item
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
42 * descriptor. Each frame has an associated hashtable.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
43 *
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
44 * Leaf items are assigned a unique id based on item's hash. When an
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
45 * item is selected, Windows sends back the id. Unfortunately, only
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
46 * low 16 bit of the ID are sent, and there's no way to get the 32-bit
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
47 * value. Yes, Win32 is just a different set of bugs than X! Aside
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
48 * from this blame, another hasing mechanism is required to map menu
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
49 * ids to commands (which are actually Lisp_Object's). This mapping is
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
50 * performed in the same hashtable, as the lifetime of both maps is
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
51 * exactly the same. This is unabmigous, as menu handles are
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
52 * represented by lisp opaques, while command ids are by lisp
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
53 * integers. The additional advantage for this is that command forms
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
54 * are automatically GC-protected, which is important because these
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
55 * may be transient forms generated by :filter functions.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
56 *
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
57 * The hashtable is not allowed to grow too much; it is pruned
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
58 * whenever this is safe to do. This is done by re-creating the menu
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
59 * bar, and clearing and refilling the hash table from scratch.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
60 *
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
61 * Popup menus are handled identially to pulldowns. A static hash
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
62 * table is used for popup menus, and lookup is made not in
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
63 * current-menubar but in a lisp form supplied to the `popup'
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
64 * function.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
65 *
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
66 * Another Windows weirdness is that there's no way to tell that a
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
67 * popup has been dismissed without making selection. We need to know
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
68 * that to cleanup the popup menu hashtable, but this is not honestly
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
69 * doable using *documented* sequence of messages. Sticking to
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
70 * particular knowledge is bad because this may break in Windows NT
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
71 * 5.0, or Windows 98, or other future version. Instead, I allow the
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
72 * hashtables to hang around, and not clear them, unless WM_COMMAND is
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
73 * received. This is worthy some memory but more safe. Hacks welcome,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
74 * anyways!
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
75 *
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
76 */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
77
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
78 #include <config.h>
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
79 #include "lisp.h"
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 269
diff changeset
80 #include <limits.h>
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
81
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
82 #include "buffer.h"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
83 #include "commands.h"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
84 #include "console-msw.h"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
85 #include "elhash.h"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
86 #include "events.h"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
87 #include "frame.h"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
88 #include "gui.h"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
89 #include "lisp.h"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
90 #include "menubar.h"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
91 #include "menubar-msw.h"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
92 #include "opaque.h"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
93 #include "window.h"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
94
269
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 255
diff changeset
95 /* #### */
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 255
diff changeset
96 #define REPLACE_ME_WITH_GLOBAL_VARIABLE_WHICH_CONTROLS_RIHGT_FLUSH 0
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 255
diff changeset
97
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
98 #define EMPTY_ITEM_ID ((UINT)LISP_TO_VOID (Qunbound))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
99 #define EMPTY_ITEM_NAME "(empty)"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
100
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
101 /* Current menu (bar or popup) descriptor. gcpro'ed */
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
102 static Lisp_Object current_menudesc;
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
103
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
104 /* Current menubar or popup hashtable. gcpro'ed */
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
105 static Lisp_Object current_hashtable;
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
106
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
107 /* This is used to allocate unique ids to menu items.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
108 Items ids are in MENU_ITEM_ID_MIN to MENU_ITEM_ID_MAX.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
109 Allocation checks that the item is not already in
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
110 the TOP_LEVEL_MENU */
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
111
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
112 /* #### defines go to gui-msw.h, as the range is shared with toolbars
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
113 (If only toolbars will be implemented as common controls) */
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
114 #define MENU_ITEM_ID_MIN 0x8000
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
115 #define MENU_ITEM_ID_MAX 0xFFFF
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 272
diff changeset
116 #define MENU_ITEM_ID_BITS(x) (((x) & 0x7FFF) | 0x8000)
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
117 static HMENU top_level_menu;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
118
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
119 #define MAX_MENUITEM_LENGTH 128
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
120
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
121 /*
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
122 * This returns Windows-style menu item string:
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
123 * "Left Flush\tRight Flush"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
124 */
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
125 static char*
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
126 displayable_menu_item (struct gui_item* pgui_item)
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
127 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
128 /* We construct the name in a static buffer. That's fine, beause
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
129 menu items longer than 128 chars are probably programming errors,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
130 and better be caught than displayed! */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
131
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
132 static char buf[MAX_MENUITEM_LENGTH+2];
327
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents: 298
diff changeset
133 char *ptr;
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
134 unsigned int ll, lr;
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
135
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
136 /* Left flush part of the string */
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
137 ll = gui_item_display_flush_left (pgui_item, buf, MAX_MENUITEM_LENGTH);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
138
327
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents: 298
diff changeset
139 /* Escape '&' as '&&' */
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents: 298
diff changeset
140 ptr = buf;
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents: 298
diff changeset
141 while ((ptr=memchr (ptr, '&', ll-(ptr-buf))) != NULL)
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents: 298
diff changeset
142 {
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents: 298
diff changeset
143 if (ll+2 >= MAX_MENUITEM_LENGTH)
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents: 298
diff changeset
144 signal_simple_error ("Menu item produces too long displayable string",
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents: 298
diff changeset
145 pgui_item->name);
337
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 327
diff changeset
146 memmove (ptr+1, ptr, (ll-(ptr-buf))+1);
327
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents: 298
diff changeset
147 ll++;
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents: 298
diff changeset
148 ptr+=2;
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents: 298
diff changeset
149 }
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents: 298
diff changeset
150
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents: 298
diff changeset
151 /* Replace XEmacs accelerator '%_' with Windows accelerator '&' */
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents: 298
diff changeset
152 ptr = buf;
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents: 298
diff changeset
153 while ((ptr=memchr (ptr, '%', ll-(ptr-buf))) != NULL)
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents: 298
diff changeset
154 {
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents: 298
diff changeset
155 if (*(ptr+1) == '_')
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents: 298
diff changeset
156 {
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents: 298
diff changeset
157 *ptr = '&';
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents: 298
diff changeset
158 memmove (ptr+1, ptr+2, ll-(ptr-buf+2));
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents: 298
diff changeset
159 ll--;
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents: 298
diff changeset
160 }
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents: 298
diff changeset
161 ptr++;
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents: 298
diff changeset
162 }
03446687b7cc Import from CVS: tag r21-0-61
cvs
parents: 298
diff changeset
163
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
164 /* Right flush part */
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
165 assert (MAX_MENUITEM_LENGTH > ll + 1);
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
166 lr = gui_item_display_flush_right (pgui_item, buf + ll + 1,
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
167 MAX_MENUITEM_LENGTH - ll - 1);
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
168 if (lr)
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
169 buf [ll] = '\t';
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
170
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
171 return buf;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
172 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
173
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
174 /*
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
175 * hmenu_to_lisp_object() returns an opaque ptr given menu handle.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
176 */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
177 static Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
178 hmenu_to_lisp_object (HMENU hmenu)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
179 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
180 return make_opaque_ptr (hmenu);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
181 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
182
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
183 /*
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
184 * Allocation tries a hash based on item's path and name first. This
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
185 * almost guarantees that the same item will override its old value in
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
186 * the hashtable rather than abandon it.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
187 */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
188 static Lisp_Object
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
189 allocate_menu_item_id (Lisp_Object path, Lisp_Object name, Lisp_Object suffix)
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
190 {
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
191 UINT id = MENU_ITEM_ID_BITS (HASH3 (internal_hash (path, 0),
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
192 internal_hash (name, 0),
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
193 internal_hash (suffix, 0)));
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
194 do {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
195 id = MENU_ITEM_ID_BITS (id + 1);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
196 } while (GetMenuState (top_level_menu, id, MF_BYCOMMAND) != 0xFFFFFFFF);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
197 return make_int (id);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
198 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
199
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
200 static HMENU
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
201 create_empty_popup_menu (void)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
202 {
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
203 return CreatePopupMenu ();
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
204 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
205
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
206 static void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
207 empty_menu (HMENU menu, int add_empty_p)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
208 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
209 while (DeleteMenu (menu, 0, MF_BYPOSITION));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
210 if (add_empty_p)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
211 AppendMenu (menu, MF_STRING | MF_GRAYED, EMPTY_ITEM_ID, EMPTY_ITEM_NAME);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
212 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
213
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
214 /*
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
215 * The idea of checksumming is that we must hash minimal object
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
216 * which is neccessarily changes when the item changes. For separator
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
217 * this is a constant, for grey strings and submenus these are hashes
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
218 * of names, since sumbenus are unpopulated until opened so always
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
219 * equal otherwise. For items, this is a full hash value of a callback,
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
220 * because a callback may me a form which can be changed only somewhere
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
221 * in depth.
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
222 */
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
223 static unsigned long
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
224 checksum_menu_item (Lisp_Object item)
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
225 {
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
226 if (STRINGP (item))
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
227 {
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
228 /* Separator or unselectable text - hash as a string + 13 */
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
229 if (separator_string_p (XSTRING_DATA (item)))
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
230 return 13;
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
231 else
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
232 return internal_hash (item, 0) + 13;
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
233 }
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
234 else if (CONSP (item))
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
235 {
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
236 /* Submenu - hash by its string name + 0 */
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
237 return internal_hash (XCAR(item), 0);
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
238 }
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
239 else if (VECTORP (item))
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
240 {
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
241 /* An ordinary item - hash its name and callback form. */
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
242 return HASH2 (internal_hash (XVECTOR_DATA(item)[0], 0),
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
243 internal_hash (XVECTOR_DATA(item)[1], 0));
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
244 }
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
245
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
246 /* An error - will be caught later */
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
247 return 0;
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
248 }
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
249
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
250 static void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
251 populate_menu_add_item (HMENU menu, Lisp_Object path,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
252 Lisp_Object hash_tab, Lisp_Object item, int flush_right)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
253 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
254 MENUITEMINFO item_info;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
255
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
256 item_info.cbSize = sizeof (item_info);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
257 item_info.fMask = MIIM_TYPE | MIIM_STATE | MIIM_ID;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
258 item_info.fState = 0;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
259 item_info.wID = 0;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
260 item_info.fType = 0;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
261
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
262 if (STRINGP (item))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
263 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
264 /* Separator or unselectable text */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
265 if (separator_string_p (XSTRING_DATA (item)))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
266 item_info.fType = MFT_SEPARATOR;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
267 else
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
268 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
269 item_info.fType = MFT_STRING;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
270 item_info.fState = MFS_DISABLED;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
271 item_info.dwTypeData = XSTRING_DATA (item);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
272 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
273 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
274 else if (CONSP (item))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
275 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
276 /* Submenu */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
277 HMENU submenu;
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
278 struct gui_item gui_item;
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
279 struct gcpro gcpro1;
363
972bbb6d6ca2 Import from CVS: tag r21-1-11
cvs
parents: 337
diff changeset
280 struct gcpro ngcpro1;
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
281
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
282 gui_item_init (&gui_item);
269
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 255
diff changeset
283 GCPRO_GUI_ITEM (&gui_item);
363
972bbb6d6ca2 Import from CVS: tag r21-1-11
cvs
parents: 337
diff changeset
284 NGCPRO1 (path);
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
285
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
286 menu_parse_submenu_keywords (item, &gui_item);
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
287
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
288 if (!STRINGP (gui_item.name))
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
289 signal_simple_error ("Menu name (first element) must be a string", item);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
290
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
291 if (!gui_item_included_p (&gui_item, Vmenubar_configuration))
363
972bbb6d6ca2 Import from CVS: tag r21-1-11
cvs
parents: 337
diff changeset
292 {
972bbb6d6ca2 Import from CVS: tag r21-1-11
cvs
parents: 337
diff changeset
293 NUNGCPRO;
972bbb6d6ca2 Import from CVS: tag r21-1-11
cvs
parents: 337
diff changeset
294 UNGCPRO;
972bbb6d6ca2 Import from CVS: tag r21-1-11
cvs
parents: 337
diff changeset
295 return;
972bbb6d6ca2 Import from CVS: tag r21-1-11
cvs
parents: 337
diff changeset
296 }
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
297
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
298 if (!gui_item_active_p (&gui_item))
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
299 item_info.fState = MFS_GRAYED;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
300 /* Temptation is to put 'else' right here. Although, the
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
301 displayed item won't have an arrow indicating that it is a
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
302 popup. So we go ahead a little bit more and create a popup */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
303 submenu = create_empty_popup_menu();
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
304
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
305 item_info.fMask |= MIIM_SUBMENU;
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
306 item_info.dwTypeData = displayable_menu_item (&gui_item);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
307 item_info.hSubMenu = submenu;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
308
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
309 if (!(item_info.fState & MFS_GRAYED))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
310 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
311 /* Now add the full submenu path as a value to the hash table,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
312 keyed by menu handle */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
313 if (NILP(path))
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
314 /* list1 cannot GC */
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
315 path = list1 (gui_item.name);
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
316 else
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
317 {
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 278
diff changeset
318 Lisp_Object arg[2];
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 278
diff changeset
319 arg[0] = path;
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 278
diff changeset
320 arg[1] = list1 (gui_item.name);
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
321 /* Fappend gcpro'es its arg */
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
322 path = Fappend (2, arg);
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
323 }
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
324
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
325 /* Fputhash GCPRO'es PATH */
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
326 Fputhash (hmenu_to_lisp_object (submenu), path, hash_tab);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
327 }
363
972bbb6d6ca2 Import from CVS: tag r21-1-11
cvs
parents: 337
diff changeset
328 NUNGCPRO;
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
329 UNGCPRO; /* gui_item */
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
330 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
331 else if (VECTORP (item))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
332 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
333 /* An ordinary item */
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
334 Lisp_Object style, id;
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
335 struct gui_item gui_item;
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
336 struct gcpro gcpro1;
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
337
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
338 gui_item_init (&gui_item);
269
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 255
diff changeset
339 GCPRO_GUI_ITEM (&gui_item);
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
340
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
341 gui_parse_item_keywords (item, &gui_item);
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
342
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
343 if (!gui_item_included_p (&gui_item, Vmenubar_configuration))
367
a4f53d9b3154 Import from CVS: tag r21-1-13
cvs
parents: 363
diff changeset
344 {
a4f53d9b3154 Import from CVS: tag r21-1-13
cvs
parents: 363
diff changeset
345 UNGCPRO;
a4f53d9b3154 Import from CVS: tag r21-1-13
cvs
parents: 363
diff changeset
346 return;
a4f53d9b3154 Import from CVS: tag r21-1-13
cvs
parents: 363
diff changeset
347 }
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
348
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
349 if (!gui_item_active_p (&gui_item))
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
350 item_info.fState = MFS_GRAYED;
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
351
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
352 style = (NILP (gui_item.selected) || NILP (Feval (gui_item.selected))
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
353 ? Qnil : gui_item.style);
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
354
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
355 if (EQ (style, Qradio))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
356 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
357 item_info.fType |= MFT_RADIOCHECK;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
358 item_info.fState |= MFS_CHECKED;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
359 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
360 else if (EQ (style, Qtoggle))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
361 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
362 item_info.fState |= MFS_CHECKED;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
363 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
364
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
365 id = allocate_menu_item_id (path, gui_item.name,
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
366 gui_item.suffix);
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
367 Fputhash (id, gui_item.callback, hash_tab);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
368
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
369 item_info.wID = (UINT) XINT(id);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
370 item_info.fType |= MFT_STRING;
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
371 item_info.dwTypeData = displayable_menu_item (&gui_item);
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
372
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
373 UNGCPRO; /* gui_item */
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
374 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
375 else
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
376 {
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
377 signal_simple_error ("Mailformed menu item descriptor", item);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
378 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
379
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
380 if (flush_right)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
381 item_info.fType |= MFT_RIGHTJUSTIFY;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
382
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
383 InsertMenuItem (menu, UINT_MAX, TRUE, &item_info);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
384 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
385
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
386 /*
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
387 * This function is called from populate_menu and checksum_menu.
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
388 * When called to populate, MENU is a menu handle, PATH is a
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
389 * list of strings representing menu path from root to this submenu,
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
390 * DESCRIPTOR is a menu descriptor, HASH_TAB is a hashtable associated
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
391 * with root menu, BAR_P indicates whether this called for a menubar or
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
392 * a popup, and POPULATE_P is non-zero. Return value must be ignored.
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
393 * When called to checksum, DESCRIPTOR has the same meaning, POPULATE_P
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
394 * is zero, PATH must be Qnil, and the rest of parameters is ignored.
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
395 * Return value is the menu checksum.
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
396 */
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
397 static unsigned long
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
398 populate_or_checksum_helper (HMENU menu, Lisp_Object path, Lisp_Object desc,
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
399 Lisp_Object hash_tab, int bar_p, int populate_p)
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
400 {
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
401 Lisp_Object item_desc;
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
402 int deep_p, flush_right;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
403 struct gcpro gcpro1;
269
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 255
diff changeset
404 unsigned long checksum;
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
405 struct gui_item gui_item;
363
972bbb6d6ca2 Import from CVS: tag r21-1-11
cvs
parents: 337
diff changeset
406 struct gcpro ngcpro1;
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
407
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
408 gui_item_init (&gui_item);
269
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 255
diff changeset
409 GCPRO_GUI_ITEM (&gui_item);
363
972bbb6d6ca2 Import from CVS: tag r21-1-11
cvs
parents: 337
diff changeset
410 NGCPRO1 (desc);
269
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 255
diff changeset
411
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 255
diff changeset
412 /* We are sometimes called with the menubar unchanged, and with changed
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 255
diff changeset
413 right flush. We have to update the menubar in ths case,
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 255
diff changeset
414 so account for the compliance setting in the hash value */
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 255
diff changeset
415 checksum = REPLACE_ME_WITH_GLOBAL_VARIABLE_WHICH_CONTROLS_RIHGT_FLUSH;
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
416
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
417 /* Will initially contain only "(empty)" */
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
418 if (populate_p)
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
419 empty_menu (menu, 1);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
420
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
421 /* PATH set to nil indicates top-level popup or menubar */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
422 deep_p = !NILP (path);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
423
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
424 /* Fetch keywords prepending the item list */
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
425 desc = menu_parse_submenu_keywords (desc, &gui_item);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
426
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
427 /* Check that menu name is specified when expected */
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
428 if (NILP (gui_item.name) && deep_p)
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
429 signal_simple_error ("Menu must have a name", desc);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
430
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
431 /* Apply filter if specified */
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
432 if (!NILP (gui_item.filter))
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
433 desc = call1 (gui_item.filter, desc);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
434
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
435 /* Loop thru the desc's CDR and add items for each entry */
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
436 flush_right = 0;
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
437 EXTERNAL_LIST_LOOP (item_desc, desc)
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
438 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
439 if (NILP (XCAR (item_desc)))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
440 {
269
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 255
diff changeset
441 /* Do not flush right menubar items when MS style compiant */
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 255
diff changeset
442 if (bar_p && !REPLACE_ME_WITH_GLOBAL_VARIABLE_WHICH_CONTROLS_RIHGT_FLUSH)
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
443 flush_right = 1;
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
444 if (!populate_p)
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 276
diff changeset
445 checksum = HASH2 (checksum, LISP_HASH (Qnil));
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
446 }
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
447 else if (populate_p)
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
448 populate_menu_add_item (menu, path, hash_tab,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
449 XCAR (item_desc), flush_right);
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
450 else
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
451 checksum = HASH2 (checksum,
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
452 checksum_menu_item (XCAR (item_desc)));
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
453 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
454
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
455 if (populate_p)
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
456 {
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
457 /* Remove the "(empty)" item, if there are other ones */
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
458 if (GetMenuItemCount (menu) > 1)
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
459 RemoveMenu (menu, EMPTY_ITEM_ID, MF_BYCOMMAND);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
460
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
461 /* Add the header to the popup, if told so. The same as in X - an
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
462 insensitive item, and a separator (Seems to me, there were
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
463 two separators in X... In Windows this looks ugly, anywats. */
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
464 if (!bar_p && !deep_p && popup_menu_titles && !NILP(gui_item.name))
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
465 {
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
466 CHECK_STRING (gui_item.name);
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
467 InsertMenu (menu, 0, MF_BYPOSITION | MF_STRING | MF_DISABLED,
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
468 0, XSTRING_DATA(gui_item.name));
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
469 InsertMenu (menu, 1, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
470 SetMenuDefaultItem (menu, 0, MF_BYPOSITION);
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
471 }
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
472 }
363
972bbb6d6ca2 Import from CVS: tag r21-1-11
cvs
parents: 337
diff changeset
473 NUNGCPRO;
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
474 UNGCPRO; /* gui_item */
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
475 return checksum;
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
476 }
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
477
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
478 static void
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
479 populate_menu (HMENU menu, Lisp_Object path, Lisp_Object desc,
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
480 Lisp_Object hash_tab, int bar_p)
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
481 {
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
482 populate_or_checksum_helper (menu, path, desc, hash_tab, bar_p, 1);
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
483 }
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
484
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
485 static unsigned long
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
486 checksum_menu (Lisp_Object desc)
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
487 {
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
488 return populate_or_checksum_helper (NULL, Qnil, desc, Qunbound, 0, 0);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
489 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
490
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
491 static void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
492 update_frame_menubar_maybe (struct frame* f)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
493 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
494 HMENU menubar = GetMenu (FRAME_MSWINDOWS_HANDLE (f));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
495 struct window *w = XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
496 Lisp_Object desc = (!NILP (w->menubar_visible_p)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
497 ? symbol_value_in_buffer (Qcurrent_menubar, w->buffer)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
498 : Qnil);
363
972bbb6d6ca2 Import from CVS: tag r21-1-11
cvs
parents: 337
diff changeset
499 struct gcpro gcpro1;
972bbb6d6ca2 Import from CVS: tag r21-1-11
cvs
parents: 337
diff changeset
500
972bbb6d6ca2 Import from CVS: tag r21-1-11
cvs
parents: 337
diff changeset
501 GCPRO1 (desc); /* it's safest to do this, just in case some filter
972bbb6d6ca2 Import from CVS: tag r21-1-11
cvs
parents: 337
diff changeset
502 or something changes the value of current-menubar */
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
503
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
504 top_level_menu = menubar;
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
505
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
506 if (NILP (desc) && menubar != NULL)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
507 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
508 /* Menubar has gone */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
509 FRAME_MSWINDOWS_MENU_HASHTABLE(f) = Qnil;
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
510 SetMenu (FRAME_MSWINDOWS_HANDLE (f), NULL);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
511 DestroyMenu (menubar);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
512 DrawMenuBar (FRAME_MSWINDOWS_HANDLE (f));
363
972bbb6d6ca2 Import from CVS: tag r21-1-11
cvs
parents: 337
diff changeset
513 UNGCPRO;
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
514 return;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
515 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
516
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
517 if (!NILP (desc) && menubar == NULL)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
518 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
519 /* Menubar has appeared */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
520 menubar = CreateMenu ();
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
521 goto populate;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
522 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
523
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
524 if (NILP (desc))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
525 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
526 /* We did not have the bar and are not going to */
363
972bbb6d6ca2 Import from CVS: tag r21-1-11
cvs
parents: 337
diff changeset
527 UNGCPRO;
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
528 return;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
529 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
530
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
531 /* Now we bail out if the menubar has not changed */
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
532 if (FRAME_MSWINDOWS_MENU_CHECKSUM(f) == checksum_menu (desc))
363
972bbb6d6ca2 Import from CVS: tag r21-1-11
cvs
parents: 337
diff changeset
533 {
972bbb6d6ca2 Import from CVS: tag r21-1-11
cvs
parents: 337
diff changeset
534 UNGCPRO;
972bbb6d6ca2 Import from CVS: tag r21-1-11
cvs
parents: 337
diff changeset
535 return;
972bbb6d6ca2 Import from CVS: tag r21-1-11
cvs
parents: 337
diff changeset
536 }
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
537
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
538 populate:
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
539 /* Come with empty hash table */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
540 if (NILP (FRAME_MSWINDOWS_MENU_HASHTABLE(f)))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
541 FRAME_MSWINDOWS_MENU_HASHTABLE(f) = Fmake_hashtable (make_int (50), Qequal);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
542 else
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
543 Fclrhash (FRAME_MSWINDOWS_MENU_HASHTABLE(f));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
544
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
545 Fputhash (hmenu_to_lisp_object (menubar), Qnil,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
546 FRAME_MSWINDOWS_MENU_HASHTABLE(f));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
547 populate_menu (menubar, Qnil, desc,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
548 FRAME_MSWINDOWS_MENU_HASHTABLE(f), 1);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
549 SetMenu (FRAME_MSWINDOWS_HANDLE (f), menubar);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
550 DrawMenuBar (FRAME_MSWINDOWS_HANDLE (f));
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
551
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
552 FRAME_MSWINDOWS_MENU_CHECKSUM(f) = checksum_menu (desc);
363
972bbb6d6ca2 Import from CVS: tag r21-1-11
cvs
parents: 337
diff changeset
553
972bbb6d6ca2 Import from CVS: tag r21-1-11
cvs
parents: 337
diff changeset
554 UNGCPRO;
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
555 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
556
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
557 static void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
558 prune_menubar (struct frame *f)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
559 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
560 HMENU menubar = GetMenu (FRAME_MSWINDOWS_HANDLE (f));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
561 Lisp_Object desc = current_frame_menubar (f);
363
972bbb6d6ca2 Import from CVS: tag r21-1-11
cvs
parents: 337
diff changeset
562 struct gcpro gcpro1;
972bbb6d6ca2 Import from CVS: tag r21-1-11
cvs
parents: 337
diff changeset
563
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
564 if (menubar == NULL)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
565 return;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
566
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
567 /* #### If a filter function has set desc to Qnil, this abort()
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
568 triggers. To resolve, we must prevent filters explicitely from
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
569 mangling with the active menu. In apply_filter probably?
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
570 Is copy-tree on the whole menu too expensive? */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
571 if (NILP(desc))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
572 /* abort(); */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
573 return;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
574
363
972bbb6d6ca2 Import from CVS: tag r21-1-11
cvs
parents: 337
diff changeset
575 GCPRO1 (desc); /* just to be safe -- see above */
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
576 /* We do the trick by removing all items and re-populating top level */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
577 empty_menu (menubar, 0);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
578
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
579 assert (HASHTABLEP (FRAME_MSWINDOWS_MENU_HASHTABLE(f)));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
580 Fclrhash (FRAME_MSWINDOWS_MENU_HASHTABLE(f));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
581
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
582 Fputhash (hmenu_to_lisp_object (menubar), Qnil,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
583 FRAME_MSWINDOWS_MENU_HASHTABLE(f));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
584 populate_menu (menubar, Qnil, desc,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
585 FRAME_MSWINDOWS_MENU_HASHTABLE(f), 1);
363
972bbb6d6ca2 Import from CVS: tag r21-1-11
cvs
parents: 337
diff changeset
586 UNGCPRO;
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
587 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
588
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
589 /*
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
590 * This is called when cleanup is possible. It is better not to
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
591 * clean things up at all than do it too earaly!
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
592 */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
593 static void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
594 menu_cleanup (struct frame *f)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
595 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
596 /* This function can GC */
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
597 current_menudesc = Qnil;
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
598 current_hashtable = Qnil;
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
599 prune_menubar (f);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
600 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
601
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
602
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
603 /*------------------------------------------------------------------------*/
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
604 /* Message handlers */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
605 /*------------------------------------------------------------------------*/
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
606 static Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
607 unsafe_handle_wm_initmenupopup_1 (HMENU menu, struct frame* f)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
608 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
609 /* This function can call lisp, beat dogs and stick chewing gum to
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
610 everything! */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
611
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
612 Lisp_Object path, desc;
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
613 struct gcpro gcpro1;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
614
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
615 /* Find which guy is going to explode */
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
616 path = Fgethash (hmenu_to_lisp_object (menu), current_hashtable, Qunbound);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
617 assert (!UNBOUNDP (path));
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
618 #ifdef DEBUG_XEMACS
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
619 /* Allow to continue in a debugger after assert - not so fatal */
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
620 if (UNBOUNDP (path))
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
621 error ("internal menu error");
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
622 #endif
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
623
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
624 /* Now find a desc chunk for it. If none, then probably menu open
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
625 hook has played too much games around stuff */
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
626 desc = Fmenu_find_real_submenu (current_menudesc, path);
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
627 if (NILP (desc))
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
628 signal_simple_error ("This menu does not exist any more", path);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
629
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
630 /* Now, stuff it */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
631 /* DESC may be generated by filter, so we have to gcpro it */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
632 GCPRO1 (desc);
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
633 populate_menu (menu, path, desc, current_hashtable, 0);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
634 UNGCPRO;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
635 return Qt;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
636 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
637
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
638 static Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
639 unsafe_handle_wm_initmenu_1 (struct frame* f)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
640 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
641 /* This function can call lisp */
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
642
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
643 /* NOTE: This is called for the bar only, WM_INITMENU
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
644 for popups is filtered out */
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
645
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
646 /* #### - this menubar update mechanism is expensively anti-social and
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
647 the activate-menubar-hook is now mostly obsolete. */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
648
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
649 /* We simply ignore return value. In any case, we construct the bar
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
650 on the fly */
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
651 run_hook (Qactivate_menubar_hook);
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
652
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
653 update_frame_menubar_maybe (f);
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
654
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
655 current_menudesc = current_frame_menubar (f);
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
656 current_hashtable = FRAME_MSWINDOWS_MENU_HASHTABLE(f);
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
657 assert (HASHTABLEP (current_hashtable));
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
658
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
659 return Qt;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
660 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
661
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
662 /*
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
663 * Return value is Qt if we have dispatched the command,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
664 * or Qnil if id has not been mapped to a callback.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
665 * Window procedure may try other targets to route the
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
666 * command if we return nil
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
667 */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
668 Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
669 mswindows_handle_wm_command (struct frame* f, WORD id)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
670 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
671 /* Try to map the command id through the proper hash table */
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
672 Lisp_Object data, fn, arg, frame;
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
673 struct gcpro gcpro1;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
674
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
675 data = Fgethash (make_int (id), current_hashtable, Qunbound);
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
676 if (UNBOUNDP (data))
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
677 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
678 menu_cleanup (f);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
679 return Qnil;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
680 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
681
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
682 /* Need to gcpro because the hashtable may get destroyed by
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
683 menu_cleanup(), and will not gcpro the data any more */
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
684 GCPRO1 (data);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
685 menu_cleanup (f);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
686
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
687 /* Ok, this is our one. Enqueue it. */
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
688 get_gui_callback (data, &fn, &arg);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
689 XSETFRAME (frame, f);
298
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 288
diff changeset
690 /* this used to call mswindows_enqueue_misc_user_event but that
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 288
diff changeset
691 breaks customize because the misc_event gets eval'ed in some
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 288
diff changeset
692 cicumstances. Don't change it back unless you can fix the
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 288
diff changeset
693 customize problem also.*/
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 288
diff changeset
694 enqueue_misc_user_event (frame, fn, arg);
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 288
diff changeset
695 mswindows_enqueue_magic_event (NULL, XM_BUMPQUEUE);
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 272
diff changeset
696
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 282
diff changeset
697 UNGCPRO; /* data */
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
698 return Qt;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
699 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
700
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
701
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
702 /*------------------------------------------------------------------------*/
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
703 /* Message handling proxies */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
704 /*------------------------------------------------------------------------*/
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
705
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
706 static HMENU wm_initmenu_menu;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
707 static struct frame* wm_initmenu_frame;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
708
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
709 static Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
710 unsafe_handle_wm_initmenupopup (Lisp_Object u_n_u_s_e_d)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
711 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
712 return unsafe_handle_wm_initmenupopup_1 (wm_initmenu_menu, wm_initmenu_frame);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
713 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
714
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
715 static Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
716 unsafe_handle_wm_initmenu (Lisp_Object u_n_u_s_e_d)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
717 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
718 return unsafe_handle_wm_initmenu_1 (wm_initmenu_frame);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
719 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
720
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
721 Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
722 mswindows_handle_wm_initmenupopup (HMENU hmenu, struct frame* frm)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
723 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
724 /* We cannot pass hmenu as a lisp object. Use static var */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
725 wm_initmenu_menu = hmenu;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
726 wm_initmenu_frame = frm;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
727 return mswindows_protect_modal_loop (unsafe_handle_wm_initmenupopup, Qnil);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
728 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
729
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
730 Lisp_Object
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
731 mswindows_handle_wm_initmenu (HMENU hmenu, struct frame* f)
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
732 {
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
733 /* Handle only frame menubar, ignore if from popup or system menu */
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
734 if (GetMenu (FRAME_MSWINDOWS_HANDLE(f)) == hmenu)
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
735 {
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
736 wm_initmenu_frame = f;
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
737 return mswindows_protect_modal_loop (unsafe_handle_wm_initmenu, Qnil);
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
738 }
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
739 return Qt;
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
740 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
741
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
742
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
743 /*------------------------------------------------------------------------*/
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
744 /* Methods */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
745 /*------------------------------------------------------------------------*/
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
746
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
747 static void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
748 mswindows_update_frame_menubars (struct frame* f)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
749 {
269
b2472a1930f2 Import from CVS: tag r20-5b33
cvs
parents: 255
diff changeset
750 update_frame_menubar_maybe (f);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
751 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
752
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
753 static void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
754 mswindows_free_frame_menubars (struct frame* f)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
755 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
756 FRAME_MSWINDOWS_MENU_HASHTABLE(f) = Qnil;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
757 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
758
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
759 static void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
760 mswindows_popup_menu (Lisp_Object menu_desc, Lisp_Object event)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
761 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
762 struct frame *f = selected_frame ();
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
763 struct Lisp_Event *eev = NULL;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
764 HMENU menu;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
765 POINT pt;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
766 int ok;
363
972bbb6d6ca2 Import from CVS: tag r21-1-11
cvs
parents: 337
diff changeset
767 struct gcpro gcpro1;
972bbb6d6ca2 Import from CVS: tag r21-1-11
cvs
parents: 337
diff changeset
768
972bbb6d6ca2 Import from CVS: tag r21-1-11
cvs
parents: 337
diff changeset
769 GCPRO1 (menu_desc); /* to be safe -- see above */
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
770
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
771 if (!NILP (event))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
772 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
773 CHECK_LIVE_EVENT (event);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
774 eev = XEVENT (event);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
775 if (eev->event_type != button_press_event
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
776 && eev->event_type != button_release_event)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
777 wrong_type_argument (Qmouse_event_p, event);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
778 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
779 else if (!NILP (Vthis_command_keys))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
780 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
781 /* if an event wasn't passed, use the last event of the event sequence
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
782 currently being executed, if that event is a mouse event */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
783 eev = XEVENT (Vthis_command_keys); /* last event first */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
784 if (eev->event_type != button_press_event
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
785 && eev->event_type != button_release_event)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
786 eev = NULL;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
787 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
788
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
789 /* Default is to put the menu at the point (10, 10) in frame */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
790 if (eev)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
791 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
792 pt.x = eev->event.button.x;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
793 pt.y = eev->event.button.y;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
794 ClientToScreen (FRAME_MSWINDOWS_HANDLE (f), &pt);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
795 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
796 else
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
797 pt.x = pt.y = 10;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
798
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
799 if (SYMBOLP (menu_desc))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
800 menu_desc = Fsymbol_value (menu_desc);
298
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 288
diff changeset
801 CHECK_CONS (menu_desc);
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 288
diff changeset
802 CHECK_STRING (XCAR (menu_desc));
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
803
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
804 current_menudesc = menu_desc;
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
805 current_hashtable = Fmake_hashtable (make_int(10), Qequal);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
806 menu = create_empty_popup_menu();
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
807 Fputhash (hmenu_to_lisp_object (menu), Qnil, current_hashtable);
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
808 top_level_menu = menu;
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
809
298
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 288
diff changeset
810 /* see comments in menubar-x.c */
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 288
diff changeset
811 if (zmacs_regions)
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 288
diff changeset
812 zmacs_region_stays = 1;
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 288
diff changeset
813
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
814 ok = TrackPopupMenu (menu,
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
815 TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
816 pt.x, pt.y, 0,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
817 FRAME_MSWINDOWS_HANDLE (f), NULL);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
818
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
819 DestroyMenu (menu);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
820
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
821 /* Signal a signal if caught by Track...() modal loop */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
822 mswindows_unmodalize_signal_maybe ();
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
823
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
824 /* This is probably the only real reason for failure */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
825 if (!ok) {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
826 menu_cleanup (f);
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
827 signal_simple_error ("Cannot track popup menu while in menu",
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
828 menu_desc);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
829 }
363
972bbb6d6ca2 Import from CVS: tag r21-1-11
cvs
parents: 337
diff changeset
830 UNGCPRO;
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
831 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
832
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
833
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
834 /*------------------------------------------------------------------------*/
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
835 /* Initialization */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
836 /*------------------------------------------------------------------------*/
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
837 void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
838 syms_of_menubar_mswindows (void)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
839 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
840 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
841
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
842 void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
843 console_type_create_menubar_mswindows (void)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
844 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
845 CONSOLE_HAS_METHOD (mswindows, update_frame_menubars);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
846 CONSOLE_HAS_METHOD (mswindows, free_frame_menubars);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
847 CONSOLE_HAS_METHOD (mswindows, popup_menu);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
848 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
849
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
850 void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
851 vars_of_menubar_mswindows (void)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
852 {
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
853 current_menudesc = Qnil;
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
854 current_hashtable = Qnil;
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
855
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
856 staticpro (&current_menudesc);
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
857 staticpro (&current_hashtable);
253
157b30c96d03 Import from CVS: tag r20-5b25
cvs
parents: 251
diff changeset
858 }