annotate src/menubar-msw.c @ 245:51092a27c943 r20-5b21

Import from CVS: tag r20-5b21
author cvs
date Mon, 13 Aug 2007 10:17:54 +0200
parents 52952cbfc5b5
children 83b3d10dcba9
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"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
80
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
81 #include "buffer.h"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
82 #include "commands.h"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
83 #include "console-msw.h"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
84 #include "emacsfns.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 "event-msw.h"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
87 #include "events.h"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
88 #include "frame.h"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
89 #include "gui.h"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
90 #include "lisp.h"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
91 #include "menubar.h"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
92 #include "menubar-msw.h"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
93 #include "opaque.h"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
94 #include "window.h"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
95
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
96 #define EMPTY_ITEM_ID ((UINT)LISP_TO_VOID (Qunbound))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
97 #define EMPTY_ITEM_NAME "(empty)"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
98
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
99 /* Current menu (bar or popup) descriptor. gcpro'ed */
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
100 static Lisp_Object current_menudesc;
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
101
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
102 /* Current menubar or popup hashtable. gcpro'ed */
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
103 static Lisp_Object current_hashtable;
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
104
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
105 /* Bound by menubar.el */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
106 static Lisp_Object Qfind_menu_item;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
107
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
108 /* This is used to allocate unique ids to menu items.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
109 Items ids are in MENU_ITEM_ID_MIN to MENU_ITEM_ID_MAX.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
110 Allocation checks that the item is not already in
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
111 the TOP_LEVEL_MENU */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
112 /* #### defines go to gui-msw.h */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
113 #define MENU_ITEM_ID_MIN 0x8000
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
114 #define MENU_ITEM_ID_MAX 0xFFFF
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
115 #define MENU_ITEM_ID_BITS(x) ((x) & 0x7FFF | 0x8000)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
116 static HMENU top_level_menu;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
117
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
118 /* ============= THIS STUFF MIGHT GO SOMEWHERE ELSE ================= */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
119
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
120 /* All these functions are windows sys independent, and are candidates
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
121 to go to lisp code instead */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
122
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
123 /*
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
124 * DESCRIPTOR is a list in the form ({:keyword value}+ rest...).
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
125 * This function extracts all the key-value pairs into the newly
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
126 * created plist, and returns pointer to REST. Original list is not
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
127 * modified (heaven save!)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
128 */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
129 Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
130 gui_parse_menu_keywords (Lisp_Object descriptor, Lisp_Object *plist)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
131 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
132 Lisp_Object pair, key, val;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
133 *plist = Qnil;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
134 LIST_LOOP (pair, descriptor)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
135 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
136 if (!CONSP(pair))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
137 signal_simple_error ("Mailformed gui entity descriptor", descriptor);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
138 key = XCAR(pair);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
139 if (!KEYWORDP (key))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
140 return pair;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
141 pair = XCDR (pair);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
142 if (!CONSP(pair))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
143 signal_simple_error ("Mailformed gui entity descriptor", descriptor);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
144 val = XCAR (pair);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
145 internal_plist_put (plist, key, val);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
146 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
147 return pair;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
148 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
149
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
150 /*
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
151 * DESC is a vector describing a menu item. The function returns menu
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
152 * item name in NAME, callback form in CALLBACK, and all key-values
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
153 * pairs in PLIST. For old-style vectors, the plist is faked.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
154 */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
155 void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
156 gui_parse_button_descriptor (Lisp_Object desc, Lisp_Object *name,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
157 Lisp_Object *callback, Lisp_Object *plist)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
158 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
159 int length = XVECTOR_LENGTH (desc);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
160 Lisp_Object *contents = XVECTOR_DATA (desc);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
161 int plist_p;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
162
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
163 *name = Qnil;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
164 *callback = Qnil;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
165 *plist = Qnil;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
166
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
167 if (length < 3)
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
168 signal_simple_error ("Button descriptors must be at least 3 long", desc);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
169
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
170 /* length 3: [ "name" callback active-p ]
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
171 length 4: [ "name" callback active-p suffix ]
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
172 or [ "name" callback keyword value ]
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
173 length 5+: [ "name" callback [ keyword value ]+ ]
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
174 */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
175 plist_p = (length >= 5 || KEYWORDP (contents [2]));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
176
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
177 *name = contents [0];
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
178 *callback = contents [1];
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
179
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
180 if (!plist_p)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
181 /* the old way */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
182 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
183 internal_plist_put (plist, Q_active, contents [2]);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
184 if (length == 4)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
185 internal_plist_put (plist, Q_suffix, contents [3]);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
186 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
187 else
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
188 /* the new way */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
189 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
190 int i;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
191 if (length & 1)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
192 signal_simple_error (
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
193 "Button descriptor has an odd number of keywords and values",
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
194 desc);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
195
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
196 for (i = 2; i < length;)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
197 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
198 Lisp_Object key = contents [i++];
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
199 Lisp_Object val = contents [i++];
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
200 if (!KEYWORDP (key))
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
201 signal_simple_error_2 ("Not a keyword", key, desc);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
202 internal_plist_put (plist, key, val);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
203 }
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
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
207 /*
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
208 * Given PLIST of key-value pairs for a menu item or button, consult
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
209 * :included and :config properties (the latter against
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
210 * CONFLIST). Return value is non-zero when item should *not* appear.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
211 */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
212 int
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
213 gui_plist_says_item_excluded (Lisp_Object plist, Lisp_Object conflist)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
214 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
215 Lisp_Object tem;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
216 /* This function can call lisp */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
217
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
218 /* Evaluate :included first */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
219 tem = internal_plist_get (plist, Q_included);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
220 if (!UNBOUNDP (tem))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
221 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
222 tem = Feval (tem);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
223 if (NILP (tem))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
224 return 1;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
225 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
226
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
227 /* Do :config if conflist is given */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
228 if (!NILP (conflist))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
229 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
230 tem = internal_plist_get (plist, Q_config);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
231 if (!UNBOUNDP (tem))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
232 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
233 tem = Fmemq (tem, conflist);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
234 if (NILP (tem))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
235 return 1;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
236 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
237 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
238
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
239 return 0;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
240 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
241
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
242 /*
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
243 * Given PLIST of key-value pairs for a menu item or button, consult
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
244 * :active property. Return non-zero if the item is *inactive*
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
245 */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
246 int
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
247 gui_plist_says_item_inactive (Lisp_Object plist)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
248 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
249 Lisp_Object tem;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
250 /* This function can call lisp */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
251
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
252 tem = internal_plist_get (plist, Q_active);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
253 if (!UNBOUNDP (tem))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
254 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
255 tem = Feval (tem);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
256 if (NILP (tem))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
257 return 1;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
258 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
259
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
260 return 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
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
263 /*
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
264 * Given PLIST of key-value pairs for a menu item or button, evaluate
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
265 * the form which is the value of :filter property. Filter function
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
266 * given DESC as argument. If there's no :filter property, DESC is
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
267 * returned, otherwise the value returned by the filter function is
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
268 * returned.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
269 */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
270 Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
271 gui_plist_apply_filter (Lisp_Object plist, Lisp_Object desc)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
272 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
273 Lisp_Object tem;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
274 /* This function can call lisp */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
275
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
276 tem = internal_plist_get (plist, Q_filter);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
277 if (UNBOUNDP (tem))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
278 return desc;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
279 else
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
280 return call1 (tem, desc);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
281 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
282
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
283 /*
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
284 * This is tricky because there's no menu item styles in Windows, only
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
285 * states: Each item may be given no checkmark, radio or check
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
286 * mark. This function returns required mark style as determined by
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
287 * PLIST. Return value is the value of :style property if the item is
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
288 * :seleted, or nil otherwise
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
289 */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
290 Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
291 gui_plist_get_current_style (Lisp_Object plist)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
292 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
293 Lisp_Object style, selected;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
294 style = internal_plist_get (plist, Q_style);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
295 if (UNBOUNDP (style) || NILP(style))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
296 return Qnil;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
297
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
298 selected = internal_plist_get (plist, Q_selected);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
299 if (UNBOUNDP (selected) || NILP(Feval(selected)))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
300 return Qnil;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
301
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
302 return style;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
303 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
304
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
305 Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
306 current_frame_menubar (CONST struct frame* f)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
307 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
308 struct window *w = XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
309 return symbol_value_in_buffer (Qcurrent_menubar, w->buffer);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
310 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
311
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
312 /* ============ END IF STUFF THAT MIGHT GO SOMEWHERE ELSE =============== */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
313
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
314 /* Change these together */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
315 #define MAX_MENUITEM_LENGTH 128
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
316 #define DISPLAYABLE_MAX_MENUITEM_LENGTH "128"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
317
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
318 static void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
319 signal_item_too_long (Lisp_Object name)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
320 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
321 signal_simple_error ("Menu item is longer than "
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
322 DISPLAYABLE_MAX_MENUITEM_LENGTH
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
323 " characters", name);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
324 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
325
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
326 /* #### If this function returned (FLUSHLEFT . FLUSHRIGHT) it also
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
327 could be moved above that line - it becomes window system
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
328 independant */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
329 /*
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
330 * This returns Windows-style menu item string:
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
331 * "Left Flush\tRight Flush"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
332 */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
333 static CONST char*
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
334 plist_get_menu_item_name (Lisp_Object name, Lisp_Object callback, Lisp_Object plist)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
335 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
336 /* We construct the name in a static buffer. That's fine, beause
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
337 menu items longer than 128 chars are probably programming errors,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
338 and better be caught than displayed! */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
339
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
340 static char buf[MAX_MENUITEM_LENGTH];
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
341 char* p = buf;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
342 int buf_left = MAX_MENUITEM_LENGTH - 1;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
343 Lisp_Object tem;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
344
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
345 /* Get name first */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
346 buf_left -= XSTRING_LENGTH (name);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
347 if (buf_left < 0)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
348 signal_item_too_long (name);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
349 strcpy (p, XSTRING_DATA (name));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
350 p += XSTRING_LENGTH (name);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
351
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
352 /* Have suffix? */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
353 tem = internal_plist_get (plist, Q_suffix);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
354 if (!UNBOUNDP (tem))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
355 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
356 if (!STRINGP (tem))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
357 signal_simple_error (":suffix must be a string", tem);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
358 buf_left -= XSTRING_LENGTH (tem) + 1;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
359 if (buf_left < 0)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
360 signal_item_too_long (name);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
361 *p++ = ' ';
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
362 strcpy (p, XSTRING_DATA (tem));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
363 p += XSTRING_LENGTH (tem);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
364 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
365
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
366 /* Have keys? */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
367 if (menubar_show_keybindings)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
368 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
369 static char buf2 [1024];
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
370 buf2[0] = 0;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
371
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
372 tem = internal_plist_get (plist, Q_keys);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
373 if (!UNBOUNDP (tem))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
374 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
375 if (!STRINGP (tem))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
376 signal_simple_error (":keys must be a string", tem);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
377 if (XSTRING_LENGTH (tem) > sizeof (buf2) - 1)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
378 signal_item_too_long (name);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
379 strcpy (buf2, XSTRING_DATA (tem));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
380 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
381 else if (SYMBOLP (callback))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
382 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
383 /* #### Warning, dependency here on current_buffer and point */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
384 /* #### I've borrowed this warning along with this code from
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
385 menubar-x.c. What does that mean? -- kkm */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
386 where_is_to_char (callback, buf2);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
387 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
388
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
389 if (buf2 [0])
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
390 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
391 int n = strlen (buf2) + 1;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
392 buf_left -= n;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
393 if (buf_left < 0)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
394 signal_item_too_long (name);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
395 *p++ = '\t';
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
396 strcpy (p, buf2);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
397 p += n-1;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
398 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
399 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
400
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
401 *p = 0;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
402 return buf;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
403 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
404
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
405 /*
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
406 * hmenu_to_lisp_object() returns an opaque ptr given menu handle.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
407 */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
408 static Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
409 hmenu_to_lisp_object (HMENU hmenu)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
410 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
411 return make_opaque_ptr (hmenu);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
412 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
413
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
414 /*
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
415 * Allocation tries a hash based on item's path and name first. This
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
416 * almost guarantees that the same item will override its old value in
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
417 * the hashtable rather than abandon it.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
418 */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
419 static Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
420 allocate_menu_item_id (Lisp_Object path, Lisp_Object name)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
421 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
422 UINT id = MENU_ITEM_ID_BITS (HASH2 (internal_hash (path, 0),
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
423 internal_hash (name, 0)));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
424 do {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
425 id = MENU_ITEM_ID_BITS (id + 1);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
426 } while (GetMenuState (top_level_menu, id, MF_BYCOMMAND) != 0xFFFFFFFF);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
427 return make_int (id);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
428 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
429
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
430 static HMENU
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
431 create_empty_popup_menu (void)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
432 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
433 HMENU submenu = CreatePopupMenu ();
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
434 /* #### It seems that really we do not need "(empty)" at this stage */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
435 #if 0
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
436 AppendMenu (submenu, MF_STRING | MF_GRAYED, EMPTY_ITEM_ID, EMPTY_ITEM_NAME);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
437 #endif
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
438 return submenu;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
439 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
440
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
441 static void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
442 empty_menu (HMENU menu, int add_empty_p)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
443 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
444 while (DeleteMenu (menu, 0, MF_BYPOSITION));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
445 if (add_empty_p)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
446 AppendMenu (menu, MF_STRING | MF_GRAYED, EMPTY_ITEM_ID, EMPTY_ITEM_NAME);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
447 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
448
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
449 /*
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
450 * The idea of checksumming is that we must hash minimal object
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
451 * which is neccessarily changes when the item changes. For separator
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
452 * this is a constant, for grey strings and submenus these are hashes
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
453 * of names, since sumbenus are unpopulated until opened so always
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
454 * 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
455 * 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
456 * in depth.
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
457 */
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
458 static unsigned long
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
459 checksum_menu_item (Lisp_Object item)
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
460 {
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
461 if (STRINGP (item))
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
462 {
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
463 /* Separator or unselectable text - hash as a string + 13 */
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
464 if (separator_string_p (XSTRING_DATA (item)))
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
465 return 13;
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
466 else
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
467 return internal_hash (item, 0) + 13;
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
468 }
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
469 else if (CONSP (item))
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
470 {
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
471 /* Submenu - hash by its string name + 0 */
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
472 return internal_hash (XCAR(item), 0);
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
473 }
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
474 else if (VECTORP (item))
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
475 {
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
476 /* An ordinary item - hash its name and callback form. */
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
477 Lisp_Object plist, name, callback;
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
478 gui_parse_button_descriptor (item, &name, &callback, &plist);
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
479 return HASH2 (internal_hash (name, 0),
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
480 internal_hash (callback, 0));
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
481 }
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
482
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
483 /* An error - will be caught later */
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
484 return 0;
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
485 }
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
486
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
487 static void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
488 populate_menu_add_item (HMENU menu, Lisp_Object path,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
489 Lisp_Object hash_tab, Lisp_Object item, int flush_right)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
490 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
491 MENUITEMINFO item_info;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
492 struct gcpro gcpro1, gcpro2;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
493
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
494 item_info.cbSize = sizeof (item_info);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
495 item_info.fMask = MIIM_TYPE | MIIM_STATE | MIIM_ID;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
496 item_info.fState = 0;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
497 item_info.wID = 0;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
498 item_info.fType = 0;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
499
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
500 if (STRINGP (item))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
501 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
502 /* Separator or unselectable text */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
503 if (separator_string_p (XSTRING_DATA (item)))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
504 item_info.fType = MFT_SEPARATOR;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
505 else
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
506 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
507 item_info.fType = MFT_STRING;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
508 item_info.fState = MFS_DISABLED;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
509 item_info.dwTypeData = XSTRING_DATA (item);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
510 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
511 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
512 else if (CONSP (item))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
513 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
514 /* Submenu */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
515 Lisp_Object subname = XCAR (item);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
516 Lisp_Object plist;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
517 HMENU submenu;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
518
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
519 if (!STRINGP (subname))
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
520 signal_simple_error ("Menu name (first element) must be a string", item);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
521
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
522 item = gui_parse_menu_keywords (XCDR (item), &plist);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
523 GCPRO1 (plist);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
524
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
525 if (gui_plist_says_item_excluded (plist, Vmenubar_configuration))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
526 return;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
527
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
528 if (gui_plist_says_item_inactive (plist))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
529 item_info.fState = MFS_GRAYED;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
530 /* Temptation is to put 'else' right here. Although, the
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
531 displayed item won't have an arrow indicating that it is a
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
532 popup. So we go ahead a little bit more and create a popup */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
533 submenu = create_empty_popup_menu();
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
534
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
535 item_info.fMask |= MIIM_SUBMENU;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
536 item_info.dwTypeData = plist_get_menu_item_name (subname, Qnil, plist);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
537 item_info.hSubMenu = submenu;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
538
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
539 UNGCPRO; /* plist */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
540
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
541 if (!(item_info.fState & MFS_GRAYED))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
542 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
543 /* Now add the full submenu path as a value to the hash table,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
544 keyed by menu handle */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
545 if (NILP(path))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
546 path = list1 (subname);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
547 else {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
548 Lisp_Object arg[2];
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
549 arg[0] = path;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
550 arg[1] = list1 (subname);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
551 GCPRO1 (arg[1]);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
552 path = Fappend (2, arg);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
553 UNGCPRO; /* arg[1] */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
554 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
555
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
556 GCPRO1 (path);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
557 Fputhash (hmenu_to_lisp_object (submenu), path, hash_tab);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
558 UNGCPRO; /* path */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
559 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
560 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
561 else if (VECTORP (item))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
562 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
563 /* An ordinary item */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
564 Lisp_Object plist, name, callback, style, id;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
565
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
566 gui_parse_button_descriptor (item, &name, &callback, &plist);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
567 GCPRO2 (plist, callback);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
568
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
569 if (gui_plist_says_item_excluded (plist, Vmenubar_configuration))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
570 return;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
571
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
572 if (gui_plist_says_item_inactive (plist))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
573 item_info.fState |= MFS_GRAYED;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
574
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
575 style = gui_plist_get_current_style (plist);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
576 if (EQ (style, Qradio))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
577 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
578 item_info.fType |= MFT_RADIOCHECK;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
579 item_info.fState |= MFS_CHECKED;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
580 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
581 else if (EQ (style, Qtoggle))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
582 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
583 item_info.fState |= MFS_CHECKED;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
584 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
585
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
586 id = allocate_menu_item_id (path, name);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
587 Fputhash (id, callback, hash_tab);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
588
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
589 UNGCPRO; /* plist, callback */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
590
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
591 item_info.wID = (UINT) XINT(id);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
592 item_info.fType |= MFT_STRING;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
593 item_info.dwTypeData = plist_get_menu_item_name (name, callback, plist);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
594 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
595 else
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
596 {
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
597 signal_simple_error ("Ill-constructed menu descriptor", item);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
598 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
599
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
600 if (flush_right)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
601 item_info.fType |= MFT_RIGHTJUSTIFY;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
602
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
603 InsertMenuItem (menu, UINT_MAX, TRUE, &item_info);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
604 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
605
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
606 /*
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
607 * This function is called from populate_menu and checksum_menu.
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
608 * When called to populate, MENU is a menu handle, PATH is a
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
609 * list of strings representing menu path from root to this submenu,
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
610 * DESCRIPTOR is a menu descriptor, HASH_TAB is a hashtable associated
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
611 * 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
612 * 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
613 * When called to checksum, DESCRIPTOR has the same meaning, POPULATE_P
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
614 * 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
615 * Return value is the menu checksum.
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
616 */
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
617 static unsigned long
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
618 populate_or_checksum_helper (HMENU menu, Lisp_Object path, Lisp_Object descriptor,
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
619 Lisp_Object hash_tab, int bar_p, int populate_p)
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
620 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
621 Lisp_Object menu_name, plist, item_desc;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
622 int deep_p, flush_right;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
623 struct gcpro gcpro1;
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
624 unsigned long checksum = 0;
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
625
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
626 /* Will initially contain only "(empty)" */
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
627 if (populate_p)
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
628 empty_menu (menu, 1);
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 /* PATH set to nil indicates top-level popup or menubar */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
631 deep_p = !NILP (path);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
632
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
633 if (!deep_p)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
634 top_level_menu = menu;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
635
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
636 if (!CONSP(descriptor))
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
637 signal_simple_error ("Menu descriptor must be a list", descriptor);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
638
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
639 if (STRINGP (XCAR (descriptor)))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
640 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
641 menu_name = XCAR (descriptor);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
642 descriptor = XCDR (descriptor);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
643 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
644 else
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
645 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
646 menu_name = Qnil;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
647 if (deep_p) /* Not a popup or bar */
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
648 signal_simple_error ("Menu must have a name", descriptor);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
649 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
650
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
651 /* Fetch keywords prepending the item list */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
652 descriptor = gui_parse_menu_keywords (descriptor, &plist);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
653 GCPRO1 (plist);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
654 descriptor = gui_plist_apply_filter (plist, descriptor);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
655 UNGCPRO; /* plist */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
656
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
657 /* Loop thru the descriptor's CDR and add items for each entry */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
658 flush_right = 0;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
659 EXTERNAL_LIST_LOOP (item_desc, descriptor)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
660 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
661 if (NILP (XCAR (item_desc)))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
662 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
663 if (bar_p)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
664 flush_right = 1;
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
665 if (!populate_p)
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
666 checksum = HASH2 (checksum, Qnil);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
667 }
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
668 else if (populate_p)
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
669 populate_menu_add_item (menu, path, hash_tab,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
670 XCAR (item_desc), flush_right);
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
671 else
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
672 checksum = HASH2 (checksum,
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
673 checksum_menu_item (XCAR (item_desc)));
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
674 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
675
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
676 if (populate_p)
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
677 {
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
678 /* Remove the "(empty)" item, if there are other ones */
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
679 if (GetMenuItemCount (menu) > 1)
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
680 RemoveMenu (menu, EMPTY_ITEM_ID, MF_BYCOMMAND);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
681
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
682 /* 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
683 insensitive item, and a separator (Seems to me, there were
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
684 two separators in X... In Windows this looks ugly, anywats. */
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
685 if (!bar_p && !deep_p && popup_menu_titles && !NILP(menu_name))
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
686 {
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
687 InsertMenu (menu, 0, MF_BYPOSITION | MF_STRING | MF_DISABLED,
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
688 0, XSTRING_DATA(menu_name));
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
689 InsertMenu (menu, 1, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
690 SetMenuDefaultItem (menu, 0, MF_BYPOSITION);
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
691 }
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
692 }
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
693 return checksum;
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
694 }
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
695
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
696 static void
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
697 populate_menu (HMENU menu, Lisp_Object path, Lisp_Object descriptor,
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
698 Lisp_Object hash_tab, int bar_p)
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
699 {
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
700 populate_or_checksum_helper (menu, path, descriptor, hash_tab, bar_p, 1);
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
701 }
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
702
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
703 static unsigned long
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
704 checksum_menu (Lisp_Object descriptor)
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
705 {
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
706 return populate_or_checksum_helper (NULL, Qnil, descriptor, Qunbound, 0, 0);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
707 }
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 find_menu (Lisp_Object desc, Lisp_Object path)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
711 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
712 /* #### find-menu-item is not what's required here.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
713 Need to write this in C, or improve lisp */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
714 if (!NILP (path))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
715 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
716 desc = call2 (Qfind_menu_item, desc, path);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
717 /* desc is (supposed to be) (ITEM . PARENT). Supposed
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
718 to signal but sometimes manages to return nil */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
719 if (!NILP(desc))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
720 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
721 CHECK_CONS (desc);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
722 desc = XCAR (desc);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
723 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
724 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
725 return desc;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
726 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
727
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
728 static void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
729 update_frame_menubar_maybe (struct frame* f)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
730 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
731 HMENU menubar = GetMenu (FRAME_MSWINDOWS_HANDLE (f));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
732 struct window *w = XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
733 Lisp_Object desc = (!NILP (w->menubar_visible_p)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
734 ? symbol_value_in_buffer (Qcurrent_menubar, w->buffer)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
735 : Qnil);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
736
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
737 if (NILP (desc) && menubar != NULL)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
738 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
739 /* Menubar has gone */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
740 FRAME_MSWINDOWS_MENU_HASHTABLE(f) = Qnil;
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
741 SetMenu (FRAME_MSWINDOWS_HANDLE (f), NULL);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
742 DestroyMenu (menubar);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
743 DrawMenuBar (FRAME_MSWINDOWS_HANDLE (f));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
744 return;
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 if (!NILP (desc) && menubar == NULL)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
748 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
749 /* Menubar has appeared */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
750 menubar = CreateMenu ();
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
751 goto populate;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
752 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
753
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
754 if (NILP (desc))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
755 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
756 /* We did not have the bar and are not going to */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
757 return;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
758 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
759
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
760 /* Now we bail out if the menubar has not changed */
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
761 if (FRAME_MSWINDOWS_MENU_CHECKSUM(f) == checksum_menu (desc))
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
762 return;
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
763
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
764 populate:
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
765 /* Come with empty hash table */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
766 if (NILP (FRAME_MSWINDOWS_MENU_HASHTABLE(f)))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
767 FRAME_MSWINDOWS_MENU_HASHTABLE(f) = Fmake_hashtable (make_int (50), Qequal);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
768 else
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
769 Fclrhash (FRAME_MSWINDOWS_MENU_HASHTABLE(f));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
770
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
771 Fputhash (hmenu_to_lisp_object (menubar), Qnil,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
772 FRAME_MSWINDOWS_MENU_HASHTABLE(f));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
773 populate_menu (menubar, Qnil, desc,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
774 FRAME_MSWINDOWS_MENU_HASHTABLE(f), 1);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
775 SetMenu (FRAME_MSWINDOWS_HANDLE (f), menubar);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
776 DrawMenuBar (FRAME_MSWINDOWS_HANDLE (f));
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
777
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
778 FRAME_MSWINDOWS_MENU_CHECKSUM(f) = checksum_menu (desc);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
779 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
780
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
781 static void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
782 prune_menubar (struct frame *f)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
783 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
784 HMENU menubar = GetMenu (FRAME_MSWINDOWS_HANDLE (f));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
785 Lisp_Object desc = current_frame_menubar (f);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
786 if (menubar == NULL)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
787 return;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
788
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
789 /* #### If a filter function has set desc to Qnil, this abort()
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
790 triggers. To resolve, we must prevent filters explicitely from
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
791 mangling with the active menu. In apply_filter probably?
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
792 Is copy-tree on the whole menu too expensive? */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
793 if (NILP(desc))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
794 /* abort(); */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
795 return;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
796
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
797 /* We do the trick by removing all items and re-populating top level */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
798 empty_menu (menubar, 0);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
799
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
800 assert (HASHTABLEP (FRAME_MSWINDOWS_MENU_HASHTABLE(f)));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
801 Fclrhash (FRAME_MSWINDOWS_MENU_HASHTABLE(f));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
802
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
803 Fputhash (hmenu_to_lisp_object (menubar), Qnil,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
804 FRAME_MSWINDOWS_MENU_HASHTABLE(f));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
805 populate_menu (menubar, Qnil, desc,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
806 FRAME_MSWINDOWS_MENU_HASHTABLE(f), 1);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
807 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
808
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
809 /*
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
810 * This is called when cleanup is possible. It is better not to
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
811 * clean things up at all than do it too earaly!
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
812 */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
813 static void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
814 menu_cleanup (struct frame *f)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
815 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
816 /* This function can GC */
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
817 current_menudesc = Qnil;
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
818 current_hashtable = Qnil;
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
819 prune_menubar (f);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
820 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
821
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
822
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
823 /*------------------------------------------------------------------------*/
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
824 /* Message handlers */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
825 /*------------------------------------------------------------------------*/
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
826 static Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
827 unsafe_handle_wm_initmenupopup_1 (HMENU menu, struct frame* f)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
828 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
829 /* This function can call lisp, beat dogs and stick chewing gum to
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
830 everything! */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
831
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
832 Lisp_Object path, desc;
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
833 struct gcpro gcpro1;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
834
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
835 /* Find which guy is going to explode */
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
836 path = Fgethash (hmenu_to_lisp_object (menu), current_hashtable, Qunbound);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
837 assert (!UNBOUNDP (path));
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
838 #ifdef DEBUG_XEMACS
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
839 /* Allow to continue in a debugger after assert - not so fatal */
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
840 if (UNBOUNDP (path))
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
841 error ("internal menu error");
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
842 #endif
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
843
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
844 /* Now find a desc chunk for it. If none, then probably menu open
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
845 hook has played too much games around stuff */
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
846 desc = current_menudesc;
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
847 if (!NILP (path))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
848 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
849 desc = find_menu (desc, path);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
850 if (NILP (desc))
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
851 signal_simple_error ("This menu does not exist any more", path);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
852 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
853
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
854 /* Now, stuff it */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
855 /* DESC may be generated by filter, so we have to gcpro it */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
856 GCPRO1 (desc);
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
857 populate_menu (menu, path, desc, current_hashtable, 0);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
858 UNGCPRO;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
859 return Qt;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
860 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
861
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
862 static Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
863 unsafe_handle_wm_initmenu_1 (struct frame* f)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
864 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
865 /* This function can call lisp */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
866 /* #### - this menubar update mechanism is expensively anti-social and
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
867 the activate-menubar-hook is now mostly obsolete. */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
868
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
869 /* We simply ignore return value. In any case, we construct the bar
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
870 on the fly */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
871 run_hook (Vactivate_menubar_hook);
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
872
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
873 update_frame_menubar_maybe (f);
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
874
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
875 current_menudesc = current_frame_menubar (f);
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
876 current_hashtable = FRAME_MSWINDOWS_MENU_HASHTABLE(f);
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
877 assert (HASHTABLEP (current_hashtable));
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
878
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
879 return Qt;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
880 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
881
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
882 #ifdef KKM_DOES_NOT_LIKE_UNDOCS_SOMETIMES
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
883
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
884 /* #### This may become wrong in future Windows */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
885
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
886 static Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
887 unsafe_handle_wm_exitmenuloop_1 (struct frame* f)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
888 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
889 if (!NILP (current_tracking_popup))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
890 prune_menubar (f);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
891 return Qt;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
892 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
893
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
894 #endif
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
895
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
896 /*
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
897 * Return value is Qt if we have dispatched the command,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
898 * or Qnil if id has not been mapped to a callback.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
899 * Window procedure may try other targets to route the
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
900 * command if we return nil
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
901 */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
902 Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
903 mswindows_handle_wm_command (struct frame* f, WORD id)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
904 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
905 /* Try to map the command id through the proper hash table */
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
906 Lisp_Object command, funcsym, frame;
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
907 struct gcpro gcpro1;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
908
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
909 command = Fgethash (make_int (id), current_hashtable, Qunbound);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
910 if (UNBOUNDP (command))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
911 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
912 menu_cleanup (f);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
913 return Qnil;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
914 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
915
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
916 /* Need to gcpro because the hashtable may get destroyed
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
917 by menu_cleanup(), and will not gcpro the command
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
918 any more */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
919 GCPRO1 (command);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
920 menu_cleanup (f);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
921
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
922 /* Ok, this is our one. Enqueue it. */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
923 if (SYMBOLP (command))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
924 funcsym = Qcall_interactively;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
925 else if (CONSP (command))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
926 funcsym = Qeval;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
927 else
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
928 signal_simple_error ("Illegal callback", command);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
929
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
930 XSETFRAME (frame, f);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
931 enqueue_misc_user_event (frame, funcsym, command);
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
932
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
933 /* Needs good bump also, for WM_COMMAND may have been dispatched from
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
934 mswindows_need_event, which will block again despite new command
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
935 event has arrived */
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
936 mswindows_enqueue_magic_event (FRAME_MSWINDOWS_HANDLE(f),
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
937 XM_BUMPQUEUE);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
938
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
939 UNGCPRO; /* command */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
940 return Qt;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
941 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
942
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
943
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
944 /*------------------------------------------------------------------------*/
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
945 /* Message handling proxies */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
946 /*------------------------------------------------------------------------*/
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
947
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
948 static HMENU wm_initmenu_menu;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
949 static struct frame* wm_initmenu_frame;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
950
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
951 static Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
952 unsafe_handle_wm_initmenupopup (Lisp_Object u_n_u_s_e_d)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
953 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
954 return unsafe_handle_wm_initmenupopup_1 (wm_initmenu_menu, wm_initmenu_frame);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
955 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
956
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
957 static Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
958 unsafe_handle_wm_initmenu (Lisp_Object u_n_u_s_e_d)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
959 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
960 return unsafe_handle_wm_initmenu_1 (wm_initmenu_frame);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
961 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
962
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
963 #ifdef KKM_DOES_NOT_LIKE_UNDOCS_SOMETIMES
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
964 static Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
965 unsafe_handle_wm_exitmenuloop (Lisp_Object u_n_u_s_e_d)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
966 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
967 return unsafe_handle_wm_exitmenuloop_1 (wm_initmenu_frame);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
968 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
969 #endif
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
970
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
971 Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
972 mswindows_handle_wm_initmenupopup (HMENU hmenu, struct frame* frm)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
973 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
974 /* We cannot pass hmenu as a lisp object. Use static var */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
975 wm_initmenu_menu = hmenu;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
976 wm_initmenu_frame = frm;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
977 return mswindows_protect_modal_loop (unsafe_handle_wm_initmenupopup, Qnil);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
978 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
979
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
980 Lisp_Object
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
981 mswindows_handle_wm_initmenu (HMENU hmenu, struct frame* f)
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
982 {
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
983 /* Handle only frame menubar, ignore if from popup or system menu */
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
984 if (GetMenu (FRAME_MSWINDOWS_HANDLE(f)) == hmenu)
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
985 {
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
986 wm_initmenu_frame = f;
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
987 return mswindows_protect_modal_loop (unsafe_handle_wm_initmenu, Qnil);
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
988 }
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
989 return Qt;
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
990 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
991
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
992 Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
993 mswindows_handle_wm_exitmenuloop (struct frame* f)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
994 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
995 #ifdef KKM_DOES_NOT_LIKE_UNDOCS_SOMETIMES
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
996 wm_initmenu_frame = f;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
997 return mswindows_protect_modal_loop (unsafe_handle_wm_exitmenuloop, Qnil);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
998 #else
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
999 return Qt;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1000 #endif
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1001 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1002
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1003
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1004 /*------------------------------------------------------------------------*/
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1005 /* Methods */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1006 /*------------------------------------------------------------------------*/
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1007
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1008 static void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1009 mswindows_update_frame_menubars (struct frame* f)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1010 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1011 update_frame_menubar_maybe (f);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1012 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1013
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1014 static void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1015 mswindows_free_frame_menubars (struct frame* f)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1016 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1017 FRAME_MSWINDOWS_MENU_HASHTABLE(f) = Qnil;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1018 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1019
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1020 static void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1021 mswindows_popup_menu (Lisp_Object menu_desc, Lisp_Object event)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1022 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1023 struct frame *f = selected_frame ();
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1024 struct Lisp_Event *eev = NULL;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1025 HMENU menu;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1026 POINT pt;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1027 int ok;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1028
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1029 if (!NILP (event))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1030 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1031 CHECK_LIVE_EVENT (event);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1032 eev = XEVENT (event);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1033 if (eev->event_type != button_press_event
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1034 && eev->event_type != button_release_event)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1035 wrong_type_argument (Qmouse_event_p, event);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1036 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1037 else if (!NILP (Vthis_command_keys))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1038 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1039 /* 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
1040 currently being executed, if that event is a mouse event */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1041 eev = XEVENT (Vthis_command_keys); /* last event first */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1042 if (eev->event_type != button_press_event
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1043 && eev->event_type != button_release_event)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1044 eev = NULL;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1045 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1046
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1047 /* Default is to put the menu at the point (10, 10) in frame */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1048 if (eev)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1049 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1050 pt.x = eev->event.button.x;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1051 pt.y = eev->event.button.y;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1052 ClientToScreen (FRAME_MSWINDOWS_HANDLE (f), &pt);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1053 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1054 else
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1055 pt.x = pt.y = 10;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1056
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1057 if (SYMBOLP (menu_desc))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1058 menu_desc = Fsymbol_value (menu_desc);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1059
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
1060 current_menudesc = menu_desc;
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
1061 current_hashtable = Fmake_hashtable (make_int(10), Qequal);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1062 menu = create_empty_popup_menu();
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
1063 Fputhash (hmenu_to_lisp_object (menu), Qnil, current_hashtable);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1064
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
1065 ok = TrackPopupMenu (menu,
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
1066 TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1067 pt.x, pt.y, 0,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1068 FRAME_MSWINDOWS_HANDLE (f), NULL);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1069
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1070 DestroyMenu (menu);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1071
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1072 /* Signal a signal if caught by Track...() modal loop */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1073 mswindows_unmodalize_signal_maybe ();
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1074
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1075 /* This is probably the only real reason for failure */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1076 if (!ok) {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1077 menu_cleanup (f);
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
1078 signal_simple_error ("Cannot track popup menu while in menu",
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1079 menu_desc);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1080 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1081 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1082
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1083
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1084 /*------------------------------------------------------------------------*/
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1085 /* Initialization */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1086 /*------------------------------------------------------------------------*/
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1087 void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1088 syms_of_menubar_mswindows (void)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1089 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1090 defsymbol (&Qfind_menu_item, "find-menu-item");
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1091 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1092
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1093 void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1094 console_type_create_menubar_mswindows (void)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1095 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1096 CONSOLE_HAS_METHOD (mswindows, update_frame_menubars);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1097 CONSOLE_HAS_METHOD (mswindows, free_frame_menubars);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1098 CONSOLE_HAS_METHOD (mswindows, popup_menu);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1099 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1100
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1101 void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1102 vars_of_menubar_mswindows (void)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1103 {
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
1104 current_menudesc = Qnil;
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
1105 current_hashtable = Qnil;
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1106
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
1107 staticpro (&current_menudesc);
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 231
diff changeset
1108 staticpro (&current_hashtable);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1109
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1110 Fprovide (intern ("mswindows-menubars"));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1111 }