annotate src/menubar-msw.c @ 440:8de8e3f6228a r21-2-28

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