annotate src/menubar-msw.c @ 231:557eaa0339bf r20-5b14

Import from CVS: tag r20-5b14
author cvs
date Mon, 13 Aug 2007 10:13:48 +0200
parents
children 52952cbfc5b5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1 /* Implements an elisp-programmable menubar -- Win32
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
2 Copyright (C) 1993, 1994 Free Software Foundation, Inc.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
3 Copyright (C) 1995 Tinker Systems and INS Engineering Corp.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
4 Copyright (C) 1997 Kirill M. Katsnelson <kkm@kis.ru>
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
5
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
6 This file is part of XEmacs.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
7
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
8 XEmacs is free software; you can redistribute it and/or modify it
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
10 Free Software Foundation; either version 2, or (at your option) any
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
11 later version.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
12
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
16 for more details.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
17
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
19 along with XEmacs; see the file COPYING. If not, write to
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
21 Boston, MA 02111-1307, USA. */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
22
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
23 /* Synched up with: Not in FSF. */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
24
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
25 /* Autorship:
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
26 Initially written by kkm 12/24/97,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
27 peeking into and copying stuff from menubar-x.c
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
28 */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
29
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
30 /* Algotirhm for handling menus is as follows. When window's menubar
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
31 * is created, current-menubar is not traversed in depth. Rather, only
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
32 * top level items, both items and pulldowns, are added to the
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
33 * menubar. Each pulldown is initially empty. When a pulldown is
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
34 * selected and about to open, corresponding element of
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
35 * current-menubar is found, and the newly open pulldown is
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
36 * populated. This is made again in the same non-recursive manner.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
37 *
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
38 * This algorithm uses hash tables to find out element of the menu
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
39 * descriptor list given menu handle. The key is an opaque ptr data
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
40 * type, keeping menu handle, and the value is a list of strings
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
41 * representing the path from the root of the menu to the item
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
42 * descriptor. Each frame has an associated hashtable.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
43 *
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
44 * Leaf items are assigned a unique id based on item's hash. When an
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
45 * item is selected, Windows sends back the id. Unfortunately, only
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
46 * low 16 bit of the ID are sent, and there's no way to get the 32-bit
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
47 * value. Yes, Win32 is just a different set of bugs than X! Aside
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
48 * from this blame, another hasing mechanism is required to map menu
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
49 * ids to commands (which are actually Lisp_Object's). This mapping is
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
50 * performed in the same hashtable, as the lifetime of both maps is
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
51 * exactly the same. This is unabmigous, as menu handles are
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
52 * represented by lisp opaques, while command ids are by lisp
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
53 * integers. The additional advantage for this is that command forms
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
54 * are automatically GC-protected, which is important because these
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
55 * may be transient forms generated by :filter functions.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
56 *
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
57 * The hashtable is not allowed to grow too much; it is pruned
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
58 * whenever this is safe to do. This is done by re-creating the menu
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
59 * bar, and clearing and refilling the hash table from scratch.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
60 *
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
61 * Popup menus are handled identially to pulldowns. A static hash
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
62 * table is used for popup menus, and lookup is made not in
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
63 * current-menubar but in a lisp form supplied to the `popup'
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
64 * function.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
65 *
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
66 * Another Windows weirdness is that there's no way to tell that a
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
67 * popup has been dismissed without making selection. We need to know
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
68 * that to cleanup the popup menu hashtable, but this is not honestly
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
69 * doable using *documented* sequence of messages. Sticking to
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
70 * particular knowledge is bad because this may break in Windows NT
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
71 * 5.0, or Windows 98, or other future version. Instead, I allow the
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
72 * hashtables to hang around, and not clear them, unless WM_COMMAND is
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
73 * received. This is worthy some memory but more safe. Hacks welcome,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
74 * anyways!
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
75 *
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
76 */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
77
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
78 #include <config.h>
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
79 #include "lisp.h"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
80
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
81 #include "buffer.h"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
82 #include "commands.h"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
83 #include "console-msw.h"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
84 #include "emacsfns.h"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
85 #include "elhash.h"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
86 #include "event-msw.h"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
87 #include "events.h"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
88 #include "frame.h"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
89 #include "gui.h"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
90 #include "lisp.h"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
91 #include "menubar.h"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
92 #include "menubar-msw.h"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
93 #include "opaque.h"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
94 #include "window.h"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
95
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
96 #define EMPTY_ITEM_ID ((UINT)LISP_TO_VOID (Qunbound))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
97 #define EMPTY_ITEM_NAME "(empty)"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
98
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
99 /* Qnil when there's no popup being tracked, or a descriptor
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
100 for the popup. gcpro'ed */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
101 static Lisp_Object current_tracking_popup;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
102
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
103 /* Current popup has table. Qnil when no popup. gcpro'ed */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
104 static Lisp_Object current_popup_hash_table;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
105
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
106 /* Bound by menubar.el */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
107 static Lisp_Object Qfind_menu_item;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
108
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
109 /* This is used to allocate unique ids to menu items.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
110 Items ids are in MENU_ITEM_ID_MIN to MENU_ITEM_ID_MAX.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
111 Allocation checks that the item is not already in
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
112 the TOP_LEVEL_MENU */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
113 /* #### defines go to gui-msw.h */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
114 #define MENU_ITEM_ID_MIN 0x8000
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
115 #define MENU_ITEM_ID_MAX 0xFFFF
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
116 #define MENU_ITEM_ID_BITS(x) ((x) & 0x7FFF | 0x8000)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
117 static HMENU top_level_menu;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
118
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
119 /* ============= THIS STUFF MIGHT GO SOMEWHERE ELSE ================= */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
120
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
121 /* All these functions are windows sys independent, and are candidates
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
122 to go to lisp code instead */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
123
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
124 /*
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
125 * DESCRIPTOR is a list in the form ({:keyword value}+ rest...).
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
126 * This function extracts all the key-value pairs into the newly
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
127 * created plist, and returns pointer to REST. Original list is not
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
128 * modified (heaven save!)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
129 */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
130 Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
131 gui_parse_menu_keywords (Lisp_Object descriptor, Lisp_Object *plist)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
132 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
133 Lisp_Object pair, key, val;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
134 *plist = Qnil;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
135 LIST_LOOP (pair, descriptor)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
136 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
137 if (!CONSP(pair))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
138 signal_simple_error ("Mailformed gui entity descriptor", descriptor);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
139 key = XCAR(pair);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
140 if (!KEYWORDP (key))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
141 return pair;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
142 pair = XCDR (pair);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
143 if (!CONSP(pair))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
144 signal_simple_error ("Mailformed gui entity descriptor", descriptor);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
145 val = XCAR (pair);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
146 internal_plist_put (plist, key, val);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
147 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
148 return pair;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
149 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
150
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
151 /*
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
152 * DESC is a vector describing a menu item. The function returns menu
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
153 * item name in NAME, callback form in CALLBACK, and all key-values
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
154 * pairs in PLIST. For old-style vectors, the plist is faked.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
155 */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
156 void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
157 gui_parse_button_descriptor (Lisp_Object desc, Lisp_Object *name,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
158 Lisp_Object *callback, Lisp_Object *plist)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
159 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
160 int length = XVECTOR_LENGTH (desc);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
161 Lisp_Object *contents = XVECTOR_DATA (desc);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
162 int plist_p;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
163
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
164 *name = Qnil;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
165 *callback = Qnil;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
166 *plist = Qnil;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
167
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
168 if (length < 3)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
169 signal_simple_error ("button descriptors must be at least 3 long", desc);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
170
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
171 /* length 3: [ "name" callback active-p ]
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
172 length 4: [ "name" callback active-p suffix ]
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
173 or [ "name" callback keyword value ]
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
174 length 5+: [ "name" callback [ keyword value ]+ ]
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
175 */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
176 plist_p = (length >= 5 || KEYWORDP (contents [2]));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
177
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
178 *name = contents [0];
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
179 *callback = contents [1];
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
180
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
181 if (!plist_p)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
182 /* the old way */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
183 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
184 internal_plist_put (plist, Q_active, contents [2]);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
185 if (length == 4)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
186 internal_plist_put (plist, Q_suffix, contents [3]);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
187 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
188 else
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
189 /* the new way */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
190 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
191 int i;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
192 if (length & 1)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
193 signal_simple_error (
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
194 "button descriptor has an odd number of keywords and values",
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
195 desc);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
196
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
197 for (i = 2; i < length;)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
198 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
199 Lisp_Object key = contents [i++];
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
200 Lisp_Object val = contents [i++];
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
201 if (!KEYWORDP (key))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
202 signal_simple_error_2 ("not a keyword", key, desc);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
203 internal_plist_put (plist, key, val);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
204 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
205 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
206 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
207
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
208 /*
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
209 * Given PLIST of key-value pairs for a menu item or button, consult
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
210 * :included and :config properties (the latter against
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
211 * CONFLIST). Return value is non-zero when item should *not* appear.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
212 */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
213 int
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
214 gui_plist_says_item_excluded (Lisp_Object plist, Lisp_Object conflist)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
215 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
216 Lisp_Object tem;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
217 /* This function can call lisp */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
218
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
219 /* Evaluate :included first */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
220 tem = internal_plist_get (plist, Q_included);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
221 if (!UNBOUNDP (tem))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
222 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
223 tem = Feval (tem);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
224 if (NILP (tem))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
225 return 1;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
226 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
227
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
228 /* Do :config if conflist is given */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
229 if (!NILP (conflist))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
230 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
231 tem = internal_plist_get (plist, Q_config);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
232 if (!UNBOUNDP (tem))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
233 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
234 tem = Fmemq (tem, conflist);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
235 if (NILP (tem))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
236 return 1;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
237 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
238 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
239
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
240 return 0;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
241 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
242
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
243 /*
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
244 * Given PLIST of key-value pairs for a menu item or button, consult
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
245 * :active property. Return non-zero if the item is *inactive*
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
246 */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
247 int
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
248 gui_plist_says_item_inactive (Lisp_Object plist)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
249 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
250 Lisp_Object tem;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
251 /* This function can call lisp */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
252
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
253 tem = internal_plist_get (plist, Q_active);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
254 if (!UNBOUNDP (tem))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
255 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
256 tem = Feval (tem);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
257 if (NILP (tem))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
258 return 1;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
259 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
260
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
261 return 0;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
262 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
263
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
264 /*
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
265 * Given PLIST of key-value pairs for a menu item or button, evaluate
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
266 * the form which is the value of :filter property. Filter function
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
267 * given DESC as argument. If there's no :filter property, DESC is
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
268 * returned, otherwise the value returned by the filter function is
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
269 * returned.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
270 */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
271 Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
272 gui_plist_apply_filter (Lisp_Object plist, Lisp_Object desc)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
273 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
274 Lisp_Object tem;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
275 /* This function can call lisp */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
276
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
277 tem = internal_plist_get (plist, Q_filter);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
278 if (UNBOUNDP (tem))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
279 return desc;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
280 else
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
281 return call1 (tem, desc);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
282 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
283
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
284 /*
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
285 * This is tricky because there's no menu item styles in Windows, only
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
286 * states: Each item may be given no checkmark, radio or check
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
287 * mark. This function returns required mark style as determined by
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
288 * PLIST. Return value is the value of :style property if the item is
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
289 * :seleted, or nil otherwise
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
290 */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
291 Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
292 gui_plist_get_current_style (Lisp_Object plist)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
293 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
294 Lisp_Object style, selected;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
295 style = internal_plist_get (plist, Q_style);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
296 if (UNBOUNDP (style) || NILP(style))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
297 return Qnil;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
298
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
299 selected = internal_plist_get (plist, Q_selected);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
300 if (UNBOUNDP (selected) || NILP(Feval(selected)))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
301 return Qnil;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
302
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
303 return style;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
304 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
305
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
306 Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
307 current_frame_menubar (CONST struct frame* f)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
308 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
309 struct window *w = XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
310 return symbol_value_in_buffer (Qcurrent_menubar, w->buffer);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
311 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
312
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
313 /* ============ END IF STUFF THAT MIGHT GO SOMEWHERE ELSE =============== */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
314
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
315 /* Change these together */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
316 #define MAX_MENUITEM_LENGTH 128
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
317 #define DISPLAYABLE_MAX_MENUITEM_LENGTH "128"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
318
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
319 static void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
320 signal_item_too_long (Lisp_Object name)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
321 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
322 signal_simple_error ("Menu item is longer than "
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
323 DISPLAYABLE_MAX_MENUITEM_LENGTH
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
324 " characters", name);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
325 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
326
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
327 /* #### If this function returned (FLUSHLEFT . FLUSHRIGHT) it also
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
328 could be moved above that line - it becomes window system
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
329 independant */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
330 /*
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
331 * This returns Windows-style menu item string:
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
332 * "Left Flush\tRight Flush"
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
333 */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
334 static CONST char*
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
335 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
336 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
337 /* We construct the name in a static buffer. That's fine, beause
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
338 menu items longer than 128 chars are probably programming errors,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
339 and better be caught than displayed! */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
340
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
341 static char buf[MAX_MENUITEM_LENGTH];
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
342 char* p = buf;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
343 int buf_left = MAX_MENUITEM_LENGTH - 1;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
344 Lisp_Object tem;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
345
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
346 /* Get name first */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
347 buf_left -= XSTRING_LENGTH (name);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
348 if (buf_left < 0)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
349 signal_item_too_long (name);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
350 strcpy (p, XSTRING_DATA (name));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
351 p += XSTRING_LENGTH (name);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
352
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
353 /* Have suffix? */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
354 tem = internal_plist_get (plist, Q_suffix);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
355 if (!UNBOUNDP (tem))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
356 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
357 if (!STRINGP (tem))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
358 signal_simple_error (":suffix must be a string", tem);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
359 buf_left -= XSTRING_LENGTH (tem) + 1;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
360 if (buf_left < 0)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
361 signal_item_too_long (name);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
362 *p++ = ' ';
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
363 strcpy (p, XSTRING_DATA (tem));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
364 p += XSTRING_LENGTH (tem);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
365 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
366
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
367 /* Have keys? */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
368 if (menubar_show_keybindings)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
369 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
370 static char buf2 [1024];
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
371 buf2[0] = 0;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
372
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
373 tem = internal_plist_get (plist, Q_keys);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
374 if (!UNBOUNDP (tem))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
375 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
376 if (!STRINGP (tem))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
377 signal_simple_error (":keys must be a string", tem);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
378 if (XSTRING_LENGTH (tem) > sizeof (buf2) - 1)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
379 signal_item_too_long (name);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
380 strcpy (buf2, XSTRING_DATA (tem));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
381 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
382 else if (SYMBOLP (callback))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
383 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
384 /* #### Warning, dependency here on current_buffer and point */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
385 /* #### I've borrowed this warning along with this code from
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
386 menubar-x.c. What does that mean? -- kkm */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
387 where_is_to_char (callback, buf2);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
388 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
389
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
390 if (buf2 [0])
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
391 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
392 int n = strlen (buf2) + 1;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
393 buf_left -= n;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
394 if (buf_left < 0)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
395 signal_item_too_long (name);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
396 *p++ = '\t';
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
397 strcpy (p, buf2);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
398 p += n-1;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
399 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
400 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
401
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
402 *p = 0;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
403 return buf;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
404 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
405
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
406 /*
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
407 * hmenu_to_lisp_object() returns an opaque ptr given menu handle.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
408 */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
409 static Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
410 hmenu_to_lisp_object (HMENU 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 return make_opaque_ptr (hmenu);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
413 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
414
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
415 /*
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
416 * Allocation tries a hash based on item's path and name first. This
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
417 * almost guarantees that the same item will override its old value in
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
418 * the hashtable rather than abandon it.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
419 */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
420 static Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
421 allocate_menu_item_id (Lisp_Object path, Lisp_Object name)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
422 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
423 UINT id = MENU_ITEM_ID_BITS (HASH2 (internal_hash (path, 0),
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
424 internal_hash (name, 0)));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
425 do {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
426 id = MENU_ITEM_ID_BITS (id + 1);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
427 } while (GetMenuState (top_level_menu, id, MF_BYCOMMAND) != 0xFFFFFFFF);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
428 return make_int (id);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
429 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
430
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
431 static HMENU
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
432 create_empty_popup_menu (void)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
433 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
434 HMENU submenu = CreatePopupMenu ();
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
435 /* #### It seems that really we do not need "(empty)" at this stage */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
436 #if 0
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
437 AppendMenu (submenu, MF_STRING | MF_GRAYED, EMPTY_ITEM_ID, EMPTY_ITEM_NAME);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
438 #endif
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
439 return submenu;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
440 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
441
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
442 static void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
443 empty_menu (HMENU menu, int add_empty_p)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
444 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
445 while (DeleteMenu (menu, 0, MF_BYPOSITION));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
446 if (add_empty_p)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
447 AppendMenu (menu, MF_STRING | MF_GRAYED, EMPTY_ITEM_ID, EMPTY_ITEM_NAME);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
448 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
449
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
450 static void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
451 populate_menu_add_item (HMENU menu, Lisp_Object path,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
452 Lisp_Object hash_tab, Lisp_Object item, int flush_right)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
453 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
454 MENUITEMINFO item_info;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
455 struct gcpro gcpro1, gcpro2;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
456
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
457 item_info.cbSize = sizeof (item_info);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
458 item_info.fMask = MIIM_TYPE | MIIM_STATE | MIIM_ID;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
459 item_info.fState = 0;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
460 item_info.wID = 0;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
461 item_info.fType = 0;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
462
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
463 if (STRINGP (item))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
464 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
465 /* Separator or unselectable text */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
466 if (separator_string_p (XSTRING_DATA (item)))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
467 item_info.fType = MFT_SEPARATOR;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
468 else
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
469 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
470 item_info.fType = MFT_STRING;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
471 item_info.fState = MFS_DISABLED;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
472 item_info.dwTypeData = XSTRING_DATA (item);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
473 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
474 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
475 else if (CONSP (item))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
476 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
477 /* Submenu */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
478 Lisp_Object subname = XCAR (item);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
479 Lisp_Object plist;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
480 HMENU submenu;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
481
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
482 if (!STRINGP (subname))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
483 signal_simple_error ("menu name (first element) must be a string", item);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
484
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
485 item = gui_parse_menu_keywords (XCDR (item), &plist);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
486 GCPRO1 (plist);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
487
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
488 if (gui_plist_says_item_excluded (plist, Vmenubar_configuration))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
489 return;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
490
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
491 if (gui_plist_says_item_inactive (plist))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
492 item_info.fState = MFS_GRAYED;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
493 /* Temptation is to put 'else' right here. Although, the
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
494 displayed item won't have an arrow indicating that it is a
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
495 popup. So we go ahead a little bit more and create a popup */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
496 submenu = create_empty_popup_menu();
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
497
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
498 item_info.fMask |= MIIM_SUBMENU;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
499 item_info.dwTypeData = plist_get_menu_item_name (subname, Qnil, plist);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
500 item_info.hSubMenu = submenu;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
501
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
502 UNGCPRO; /* plist */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
503
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
504 if (!(item_info.fState & MFS_GRAYED))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
505 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
506 /* Now add the full submenu path as a value to the hash table,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
507 keyed by menu handle */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
508 if (NILP(path))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
509 path = list1 (subname);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
510 else {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
511 Lisp_Object arg[2];
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
512 arg[0] = path;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
513 arg[1] = list1 (subname);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
514 GCPRO1 (arg[1]);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
515 path = Fappend (2, arg);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
516 UNGCPRO; /* arg[1] */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
517 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
518
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
519 GCPRO1 (path);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
520 Fputhash (hmenu_to_lisp_object (submenu), path, hash_tab);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
521 UNGCPRO; /* path */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
522 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
523 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
524 else if (VECTORP (item))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
525 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
526 /* An ordinary item */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
527 Lisp_Object plist, name, callback, style, id;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
528
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
529 gui_parse_button_descriptor (item, &name, &callback, &plist);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
530 GCPRO2 (plist, callback);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
531
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
532 if (gui_plist_says_item_excluded (plist, Vmenubar_configuration))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
533 return;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
534
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
535 if (gui_plist_says_item_inactive (plist))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
536 item_info.fState |= MFS_GRAYED;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
537
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
538 style = gui_plist_get_current_style (plist);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
539 if (EQ (style, Qradio))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
540 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
541 item_info.fType |= MFT_RADIOCHECK;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
542 item_info.fState |= MFS_CHECKED;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
543 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
544 else if (EQ (style, Qtoggle))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
545 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
546 item_info.fState |= MFS_CHECKED;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
547 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
548
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
549 id = allocate_menu_item_id (path, name);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
550 Fputhash (id, callback, hash_tab);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
551
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
552 UNGCPRO; /* plist, callback */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
553
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
554 item_info.wID = (UINT) XINT(id);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
555 item_info.fType |= MFT_STRING;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
556 item_info.dwTypeData = plist_get_menu_item_name (name, callback, plist);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
557 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
558 else
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
559 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
560 signal_simple_error ("ill-constructed menu descriptor", 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
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
563 if (flush_right)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
564 item_info.fType |= MFT_RIGHTJUSTIFY;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
565
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
566 InsertMenuItem (menu, UINT_MAX, TRUE, &item_info);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
567 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
568
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
569 static void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
570 populate_menu (HMENU menu, Lisp_Object path, Lisp_Object descriptor,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
571 Lisp_Object hash_tab, int bar_p)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
572 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
573 Lisp_Object menu_name, plist, item_desc;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
574 int deep_p, flush_right;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
575 struct gcpro gcpro1;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
576
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
577 /* Will initially contain only "(empty)" */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
578 empty_menu (menu, 1);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
579
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
580 /* PATH set to nil indicates top-level popup or menubar */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
581 deep_p = !NILP (path);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
582
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
583 if (!deep_p)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
584 top_level_menu = menu;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
585
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
586 if (!CONSP(descriptor))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
587 signal_simple_error ("menu descriptor must be a list", descriptor);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
588
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
589 if (STRINGP (XCAR (descriptor)))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
590 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
591 menu_name = XCAR (descriptor);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
592 descriptor = XCDR (descriptor);
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 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
596 menu_name = Qnil;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
597 if (deep_p) /* Not a popup or bar */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
598 signal_simple_error ("menu must have a name", descriptor);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
599 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
600
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
601 /* Fetch keywords prepending the item list */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
602 descriptor = gui_parse_menu_keywords (descriptor, &plist);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
603 GCPRO1 (plist);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
604 descriptor = gui_plist_apply_filter (plist, descriptor);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
605 UNGCPRO; /* plist */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
606
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
607 /* Loop thru the descriptor's CDR and add items for each entry */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
608 flush_right = 0;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
609 EXTERNAL_LIST_LOOP (item_desc, descriptor)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
610 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
611 if (NILP (XCAR (item_desc)))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
612 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
613 if (bar_p)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
614 flush_right = 1;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
615 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
616 else
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
617 populate_menu_add_item (menu, path, hash_tab,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
618 XCAR (item_desc), flush_right);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
619 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
620
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
621 /* Remove the "(empty)" item, if there are other ones */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
622 if (GetMenuItemCount (menu) > 1)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
623 RemoveMenu (menu, EMPTY_ITEM_ID, MF_BYCOMMAND);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
624
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
625 /* Add the header to the popup, if told so. The same as in X - an
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
626 insensitive item, and a separator (Seems to me, there were
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
627 two separators in X... In Windows this looks ugly, anywats. */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
628 if (!bar_p && !deep_p && popup_menu_titles && !NILP(menu_name))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
629 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
630 InsertMenu (menu, 0, MF_BYPOSITION | MF_STRING | MF_DISABLED,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
631 0, XSTRING_DATA(menu_name));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
632 InsertMenu (menu, 1, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
633 SetMenuDefaultItem (menu, 0, MF_BYPOSITION);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
634 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
635 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
636
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
637 static Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
638 find_menu (Lisp_Object desc, Lisp_Object path)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
639 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
640 /* #### find-menu-item is not what's required here.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
641 Need to write this in C, or improve lisp */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
642 if (!NILP (path))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
643 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
644 desc = call2 (Qfind_menu_item, desc, path);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
645 /* desc is (supposed to be) (ITEM . PARENT). Supposed
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
646 to signal but sometimes manages to return nil */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
647 if (!NILP(desc))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
648 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
649 CHECK_CONS (desc);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
650 desc = XCAR (desc);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
651 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
652 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
653 return desc;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
654 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
655
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
656 static void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
657 update_frame_menubar_maybe (struct frame* f)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
658 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
659 HMENU menubar = GetMenu (FRAME_MSWINDOWS_HANDLE (f));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
660 struct window *w = XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
661 Lisp_Object desc = (!NILP (w->menubar_visible_p)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
662 ? symbol_value_in_buffer (Qcurrent_menubar, w->buffer)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
663 : Qnil);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
664
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
665 if (NILP (desc) && menubar != NULL)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
666 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
667 /* Menubar has gone */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
668 FRAME_MSWINDOWS_MENU_HASHTABLE(f) = Qnil;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
669 DestroyMenu (menubar);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
670 DrawMenuBar (FRAME_MSWINDOWS_HANDLE (f));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
671 return;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
672 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
673
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
674 if (!NILP (desc) && menubar == NULL)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
675 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
676 /* Menubar has appeared */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
677 menubar = CreateMenu ();
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
678 goto populate;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
679 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
680
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
681 if (NILP (desc))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
682 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
683 /* We did not have the bar and are not going to */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
684 return;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
685 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
686
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
687 /* Now we have to check if the menubar has really changed */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
688 /* #### For now we do not though */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
689
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
690 /* We cannot re-create the menu, cause WM_INITMENU does not like that.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
691 We'll clear it instead. */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
692 empty_menu (menubar, 0);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
693
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
694 populate:
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
695 /* Come with empty hash table */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
696 if (NILP (FRAME_MSWINDOWS_MENU_HASHTABLE(f)))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
697 FRAME_MSWINDOWS_MENU_HASHTABLE(f) = Fmake_hashtable (make_int (50), Qequal);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
698 else
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
699 Fclrhash (FRAME_MSWINDOWS_MENU_HASHTABLE(f));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
700
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
701 Fputhash (hmenu_to_lisp_object (menubar), Qnil,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
702 FRAME_MSWINDOWS_MENU_HASHTABLE(f));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
703 populate_menu (menubar, Qnil, desc,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
704 FRAME_MSWINDOWS_MENU_HASHTABLE(f), 1);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
705 SetMenu (FRAME_MSWINDOWS_HANDLE (f), menubar);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
706 DrawMenuBar (FRAME_MSWINDOWS_HANDLE (f));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
707 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
708
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
709 static void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
710 prune_menubar (struct frame *f)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
711 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
712 HMENU menubar = GetMenu (FRAME_MSWINDOWS_HANDLE (f));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
713 Lisp_Object desc = current_frame_menubar (f);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
714 if (menubar == NULL)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
715 return;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
716
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
717 /* #### If a filter function has set desc to Qnil, this abort()
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
718 triggers. To resolve, we must prevent explicitely filters from
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
719 mangling with te active menu. In apply_filter probably?
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
720 Is copy-tree on the whole menu too expensive? */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
721 if (NILP(desc))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
722 /* abort(); */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
723 return;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
724
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
725 /* We do the trick by removing all items and re-populating top level */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
726 empty_menu (menubar, 0);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
727
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
728 assert (HASHTABLEP (FRAME_MSWINDOWS_MENU_HASHTABLE(f)));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
729 Fclrhash (FRAME_MSWINDOWS_MENU_HASHTABLE(f));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
730
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
731 Fputhash (hmenu_to_lisp_object (menubar), Qnil,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
732 FRAME_MSWINDOWS_MENU_HASHTABLE(f));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
733 populate_menu (menubar, Qnil, desc,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
734 FRAME_MSWINDOWS_MENU_HASHTABLE(f), 1);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
735 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
736
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
737 /*
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
738 * This is called when cleanup is possible. It is better not to
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
739 * clean things up at all than do it too earaly!
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
740 */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
741 static void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
742 menu_cleanup (struct frame *f)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
743 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
744 /* This function can GC */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
745 if (!NILP (current_tracking_popup))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
746 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
747 current_tracking_popup = Qnil;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
748 current_popup_hash_table = Qnil;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
749 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
750 else
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
751 prune_menubar (f);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
752 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
753
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
754
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
755 /*------------------------------------------------------------------------*/
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
756 /* Message handlers */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
757 /*------------------------------------------------------------------------*/
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
758 static Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
759 unsafe_handle_wm_initmenupopup_1 (HMENU menu, struct frame* f)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
760 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
761 /* This function can call lisp, beat dogs and stick chewing gum to
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
762 everything! */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
763
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
764 Lisp_Object path, desc, hash_tab;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
765 struct gcpro gcpro1;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
766
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
767 if (!NILP (current_tracking_popup))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
768 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
769 desc = current_tracking_popup;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
770 hash_tab = current_popup_hash_table;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
771 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
772 else
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
773 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
774 desc = current_frame_menubar (f);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
775 hash_tab = FRAME_MSWINDOWS_MENU_HASHTABLE(f);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
776 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
777
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
778 /* Find which guy is going to explode */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
779 path = Fgethash (hmenu_to_lisp_object (menu), hash_tab, Qunbound);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
780 assert (!UNBOUNDP (path));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
781
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
782 /* Now find a desc chunk for it. If none, then probably menu open
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
783 hook has played too much games around stuff */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
784 if (!NILP (path))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
785 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
786 desc = find_menu (desc, path);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
787 if (NILP (desc))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
788 signal_simple_error ("this menu does not exist any more", path);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
789 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
790
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
791 /* Now, stuff it */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
792 /* DESC may be generated by filter, so we have to gcpro it */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
793 GCPRO1 (desc);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
794 populate_menu (menu, path, desc, hash_tab, 0);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
795 UNGCPRO;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
796 return Qt;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
797 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
798
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
799 static Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
800 unsafe_handle_wm_initmenu_1 (struct frame* 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 /* This function can call lisp */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
803 /* #### - this menubar update mechanism is expensively anti-social and
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
804 the activate-menubar-hook is now mostly obsolete. */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
805
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
806 /* We simply ignore return value. In any case, we construct the bar
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
807 on the fly */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
808 run_hook (Vactivate_menubar_hook);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
809
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
810 update_frame_menubar_maybe (f);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
811 return Qt;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
812 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
813
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
814
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
815 #ifdef KKM_DOES_NOT_LIKE_UNDOCS_SOMETIMES
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
816
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
817 /* #### This may become wrong in future Windows */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
818
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
819 static Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
820 unsafe_handle_wm_exitmenuloop_1 (struct frame* f)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
821 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
822 if (!NILP (current_tracking_popup))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
823 prune_menubar (f);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
824 return Qt;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
825 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
826
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
827 #endif
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
828
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
829 /*
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
830 * Return value is Qt if we have dispatched the command,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
831 * or Qnil if id has not been mapped to a callback.
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
832 * Window procedure may try other targets to route the
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
833 * command if we return nil
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
834 */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
835 Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
836 mswindows_handle_wm_command (struct frame* f, WORD id)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
837 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
838 /* Try to map the command id through the proper hash table */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
839 Lisp_Object hash_tab, command, funcsym, frame;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
840 struct gcpro gcpro1;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
841
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
842 if (!NILP (current_tracking_popup))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
843 hash_tab = current_popup_hash_table;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
844 else
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
845 hash_tab = FRAME_MSWINDOWS_MENU_HASHTABLE(f);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
846
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
847 command = Fgethash (make_int (id), hash_tab, Qunbound);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
848 if (UNBOUNDP (command))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
849 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
850 menu_cleanup (f);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
851 return Qnil;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
852 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
853
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
854 /* Need to gcpro because the hashtable may get destroyed
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
855 by menu_cleanup(), and will not gcpro the command
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
856 any more */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
857 GCPRO1 (command);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
858 menu_cleanup (f);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
859
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
860 /* Ok, this is our one. Enqueue it. */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
861 #if 0
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
862 if (SYMBOLP (command))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
863 Fcall_interactively (command, Qnil, Qnil);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
864 else if (CONSP (command))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
865 Feval (command);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
866 else
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
867 signal_simple_error ("illegal callback", command);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
868 #endif
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
869 if (SYMBOLP (command))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
870 funcsym = Qcall_interactively;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
871 else if (CONSP (command))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
872 funcsym = Qeval;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
873 else
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
874 signal_simple_error ("illegal callback", command);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
875
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
876 XSETFRAME (frame, f);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
877 enqueue_misc_user_event (frame, funcsym, command);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
878
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
879 UNGCPRO; /* command */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
880 return Qt;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
881 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
882
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
883
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
884 /*------------------------------------------------------------------------*/
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
885 /* Message handling proxies */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
886 /*------------------------------------------------------------------------*/
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
887
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
888 static HMENU wm_initmenu_menu;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
889 static struct frame* wm_initmenu_frame;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
890
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
891 static Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
892 unsafe_handle_wm_initmenupopup (Lisp_Object u_n_u_s_e_d)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
893 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
894 return unsafe_handle_wm_initmenupopup_1 (wm_initmenu_menu, wm_initmenu_frame);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
895 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
896
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
897 static Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
898 unsafe_handle_wm_initmenu (Lisp_Object u_n_u_s_e_d)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
899 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
900 return unsafe_handle_wm_initmenu_1 (wm_initmenu_frame);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
901 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
902
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
903 #ifdef KKM_DOES_NOT_LIKE_UNDOCS_SOMETIMES
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
904 static Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
905 unsafe_handle_wm_exitmenuloop (Lisp_Object u_n_u_s_e_d)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
906 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
907 return unsafe_handle_wm_exitmenuloop_1 (wm_initmenu_frame);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
908 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
909 #endif
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
910
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
911 Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
912 mswindows_handle_wm_initmenupopup (HMENU hmenu, struct frame* frm)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
913 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
914 /* We cannot pass hmenu as a lisp object. Use static var */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
915 wm_initmenu_menu = hmenu;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
916 wm_initmenu_frame = frm;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
917 return mswindows_protect_modal_loop (unsafe_handle_wm_initmenupopup, Qnil);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
918 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
919
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
920 Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
921 mswindows_handle_wm_initmenu (struct frame* f)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
922 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
923 wm_initmenu_frame = f;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
924 return mswindows_protect_modal_loop (unsafe_handle_wm_initmenu, Qnil);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
925 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
926
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
927 Lisp_Object
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
928 mswindows_handle_wm_exitmenuloop (struct frame* f)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
929 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
930 #ifdef KKM_DOES_NOT_LIKE_UNDOCS_SOMETIMES
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
931 wm_initmenu_frame = f;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
932 return mswindows_protect_modal_loop (unsafe_handle_wm_exitmenuloop, Qnil);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
933 #else
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
934 return Qt;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
935 #endif
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
936 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
937
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
938
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
939 /*------------------------------------------------------------------------*/
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
940 /* Methods */
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 static void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
944 mswindows_update_frame_menubars (struct frame* f)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
945 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
946 update_frame_menubar_maybe (f);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
947 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
948
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
949 static void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
950 mswindows_free_frame_menubars (struct frame* f)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
951 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
952 FRAME_MSWINDOWS_MENU_HASHTABLE(f) = Qnil;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
953 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
954
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
955 static void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
956 mswindows_popup_menu (Lisp_Object menu_desc, Lisp_Object event)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
957 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
958 struct frame *f = selected_frame ();
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
959 struct Lisp_Event *eev = NULL;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
960 HMENU menu;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
961 POINT pt;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
962 int ok;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
963
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
964 if (!NILP (event))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
965 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
966 CHECK_LIVE_EVENT (event);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
967 eev = XEVENT (event);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
968 if (eev->event_type != button_press_event
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
969 && eev->event_type != button_release_event)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
970 wrong_type_argument (Qmouse_event_p, event);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
971 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
972 else if (!NILP (Vthis_command_keys))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
973 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
974 /* 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
975 currently being executed, if that event is a mouse event */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
976 eev = XEVENT (Vthis_command_keys); /* last event first */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
977 if (eev->event_type != button_press_event
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
978 && eev->event_type != button_release_event)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
979 eev = NULL;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
980 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
981
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
982 /* Default is to put the menu at the point (10, 10) in frame */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
983 if (eev)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
984 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
985 pt.x = eev->event.button.x;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
986 pt.y = eev->event.button.y;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
987 ClientToScreen (FRAME_MSWINDOWS_HANDLE (f), &pt);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
988 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
989 else
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
990 pt.x = pt.y = 10;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
991
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
992 if (SYMBOLP (menu_desc))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
993 menu_desc = Fsymbol_value (menu_desc);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
994
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
995 current_tracking_popup = menu_desc;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
996 current_popup_hash_table = Fmake_hashtable (make_int(10), Qequal);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
997 menu = create_empty_popup_menu();
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
998 Fputhash (hmenu_to_lisp_object (menu), Qnil, current_popup_hash_table);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
999
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1000 ok = TrackPopupMenu (menu, TPM_LEFTALIGN | TPM_LEFTBUTTON,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1001 pt.x, pt.y, 0,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1002 FRAME_MSWINDOWS_HANDLE (f), NULL);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1003
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1004 DestroyMenu (menu);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1005
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1006 /* Signal a signal if caught by Track...() modal loop */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1007 mswindows_unmodalize_signal_maybe ();
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1008
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1009 /* This is probably the only real reason for failure */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1010 if (!ok) {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1011 menu_cleanup (f);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1012 signal_simple_error ("cannot track popup menu while in menu",
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1013 menu_desc);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1014 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1015 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1016
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 /* Initialization */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1020 /*------------------------------------------------------------------------*/
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1021 void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1022 syms_of_menubar_mswindows (void)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1023 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1024 defsymbol (&Qfind_menu_item, "find-menu-item");
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1025 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1026
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1027 void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1028 console_type_create_menubar_mswindows (void)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1029 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1030 CONSOLE_HAS_METHOD (mswindows, update_frame_menubars);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1031 CONSOLE_HAS_METHOD (mswindows, free_frame_menubars);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1032 CONSOLE_HAS_METHOD (mswindows, popup_menu);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1033 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1034
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1035 void
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1036 vars_of_menubar_mswindows (void)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1037 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1038 current_tracking_popup = Qnil;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1039 current_popup_hash_table = Qnil;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1040
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1041 staticpro (&current_tracking_popup);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1042 staticpro (&current_popup_hash_table);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1043
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1044 Fprovide (intern ("mswindows-menubars"));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents:
diff changeset
1045 }