annotate src/menubar-msw.c @ 249:83b3d10dcba9 r20-5b23

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