annotate src/menubar-x.c @ 424:11054d720c21 r21-2-20

Import from CVS: tag r21-2-20
author cvs
date Mon, 13 Aug 2007 11:26:11 +0200
parents 41dbb7a9d5f2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* Implements an elisp-programmable menubar -- X interface.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Copyright (C) 1993, 1994 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 Copyright (C) 1995 Tinker Systems and INS Engineering Corp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 /* Synched up with: Not in FSF. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
24 /* created 16-dec-91 by jwz */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 #include "lisp.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 #include "console-x.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 #include "EmacsFrame.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 #include "gui-x.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 #include "buffer.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 #include "commands.h" /* zmacs_regions */
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
35 #include "gui.h"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 #include "events.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 #include "frame.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 #include "opaque.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 #include "window.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 static int set_frame_menubar (struct frame *f,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 int deep_p,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 int first_time_p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 #define FRAME_MENUBAR_DATA(frame) ((frame)->menubar_data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 #define XFRAME_MENUBAR_DATA(frame) XPOPUP_DATA ((frame)->menubar_data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 #define MENUBAR_TYPE 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 #define SUBMENU_TYPE 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 #define POPUP_TYPE 2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 /* Converting Lisp menu tree descriptions to lwlib's `widget_value' form.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 menu_item_descriptor_to_widget_value() converts a lisp description of a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 menubar into a tree of widget_value structures. It allocates widget_values
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 with malloc_widget_value() and allocates other storage only for the `key'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 slot. All other slots are filled with pointers to Lisp_String data. We
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 allocate a widget_value description of the menu or menubar, and hand it to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 lwlib, which then makes a copy of it, which it manages internally. We then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 immediately free our widget_value tree; it will not be referenced again.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 Incremental menu construction callbacks operate just a bit differently.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 They allocate widget_values and call replace_widget_value_tree() to tell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 lwlib to destructively modify the incremental stub (subtree) of its
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 separate widget_value tree.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 This function is highly recursive (it follows the menu trees) and may call
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 eval. The reason we keep pointers to lisp string data instead of copying
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 it and freeing it later is to avoid the speed penalty that would entail
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (since this needs to be fast, in the simple cases at least). (The reason
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 we malloc/free the keys slot is because there's not a lisp string around
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 for us to use in that case.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 Since we keep pointers to lisp strings, and we call eval, we could lose if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 GC relocates (or frees) those strings. It's not easy to gc protect the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 strings because of the recursive nature of this function, and the fact that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 it returns a data structure that gets freed later. So... we do the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 sleaziest thing possible and inhibit GC for the duration. This is probably
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 not a big deal...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 We do not have to worry about the pointers to Lisp_String data after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 this function successfully finishes. lwlib copies all such data with
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
84 strdup(). */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 static widget_value *
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
87 menu_item_descriptor_to_widget_value_1 (Lisp_Object desc,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 int menu_type, int deep_p,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 int filter_p,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 int depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 /* This function cannot GC.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 It is only called from menu_item_descriptor_to_widget_value, which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 prohibits GC. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 /* !!#### This function has not been Mule-ized */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 int menubar_root_p = (menu_type == MENUBAR_TYPE && depth == 0);
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
97 widget_value *wv;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
98 Lisp_Object wv_closure;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 int count = specpdl_depth ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 int partition_seen = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
102 wv = xmalloc_widget_value ();
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
103
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
104 wv_closure = make_opaque_ptr (wv);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 record_unwind_protect (widget_value_unwind, wv_closure);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 if (STRINGP (desc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 {
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
109 char *string_chars = (char *) XSTRING_DATA (desc);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 wv->type = (separator_string_p (string_chars) ? SEPARATOR_TYPE :
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 TEXT_TYPE);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 #if 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 /* #### - should internationalize with X resources instead.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 Not so! --ben */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 string_chars = GETTEXT (string_chars);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 if (wv->type == SEPARATOR_TYPE)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 wv->value = menu_separator_style (string_chars);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
120 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 {
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
123 wv->name = string_chars;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 wv->enabled = 1;
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
125 /* dverna Dec. 98: command_builder_operate_menu_accelerator will
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
126 manipulate the accel as a Lisp_Object if the widget has a name.
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
127 Since simple labels have a name, but no accel, we *must* set it
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
128 to nil */
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
129 wv->accel = LISP_TO_VOID (Qnil);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 else if (VECTORP (desc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 {
420
41dbb7a9d5f2 Import from CVS: tag r21-2-18
cvs
parents: 412
diff changeset
134 Lisp_Object gui_item = gui_parse_item_keywords (desc);
41dbb7a9d5f2 Import from CVS: tag r21-2-18
cvs
parents: 412
diff changeset
135 if (!button_item_to_widget_value (gui_item, wv, 1,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (menu_type == MENUBAR_TYPE
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
137 && depth <= 1)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 /* :included form was nil */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 wv = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 goto menu_item_done;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 else if (CONSP (desc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 Lisp_Object incremental_data = desc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 widget_value *prev = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 if (STRINGP (XCAR (desc)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 Lisp_Object key, val;
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
152 Lisp_Object include_p = Qnil, hook_fn = Qnil, config_tag = Qnil;
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
153 Lisp_Object active_p = Qt;
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
154 Lisp_Object accel;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 int included_spec = 0;
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
156 int active_spec = 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 wv->type = CASCADE_TYPE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 wv->enabled = 1;
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
159 wv->name = (char *) XSTRING_DATA (LISP_GETTEXT (XCAR (desc)));
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
160
420
41dbb7a9d5f2 Import from CVS: tag r21-2-18
cvs
parents: 412
diff changeset
161 accel = gui_name_accelerator (LISP_GETTEXT (XCAR (desc)));
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
162 wv->accel = LISP_TO_VOID (accel);
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
163
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 desc = Fcdr (desc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 while (key = Fcar (desc), KEYWORDP (key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 Lisp_Object cascade = desc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 desc = Fcdr (desc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 if (NILP (desc))
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
171 signal_simple_error ("Keyword in menu lacks a value",
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
172 cascade);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 val = Fcar (desc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 desc = Fcdr (desc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 if (EQ (key, Q_included))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 include_p = val, included_spec = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 else if (EQ (key, Q_config))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 config_tag = val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 else if (EQ (key, Q_filter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 hook_fn = val;
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
181 else if (EQ (key, Q_active))
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
182 active_p = val, active_spec = 1;
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
183 else if (EQ (key, Q_accelerator))
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
184 {
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
185 if ( SYMBOLP (val)
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
186 || CHARP (val))
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
187 wv->accel = LISP_TO_VOID (val);
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
188 else
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
189 signal_simple_error ("bad keyboard accelerator", val);
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
190 }
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
191 else if (EQ (key, Q_label))
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
192 {
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
193 /* implement in 21.2 */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
194 }
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
195 else
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
196 signal_simple_error ("Unknown menu cascade keyword", cascade);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 if ((!NILP (config_tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 && NILP (Fmemq (config_tag, Vmenubar_configuration)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 || (included_spec && NILP (Feval (include_p))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 wv = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 goto menu_item_done;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 }
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
206
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
207 if (active_spec)
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
208 active_p = Feval (active_p);
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
209
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
210 if (!NILP (hook_fn) && !NILP (active_p))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 {
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
212 #if defined LWLIB_MENUBARS_LUCID || defined LWLIB_MENUBARS_MOTIF
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 if (filter_p || depth == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
215 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 desc = call1_trapping_errors ("Error in menubar filter",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 hook_fn, desc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 if (UNBOUNDP (desc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 desc = Qnil;
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
220 #if defined LWLIB_MENUBARS_LUCID || defined LWLIB_MENUBARS_MOTIF
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 widget_value *incr_wv = xmalloc_widget_value ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 wv->contents = incr_wv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 incr_wv->type = INCREMENTAL_TYPE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 incr_wv->enabled = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 incr_wv->name = wv->name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 /* This is automatically GC protected through
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 the call to lw_map_widget_values(); no need
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 to worry. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 incr_wv->call_data = LISP_TO_VOID (incremental_data);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 goto menu_item_done;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 }
243
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 231
diff changeset
235 #endif /* LWLIB_MENUBARS_LUCID || LWLIB_MENUBARS_MOTIF */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 if (menu_type == POPUP_TYPE && popup_menu_titles && depth == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 /* Simply prepend three more widget values to the contents of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 the menu: a label, and two separators (to get a double
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 line). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 widget_value *title_wv = xmalloc_widget_value ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 widget_value *sep_wv = xmalloc_widget_value ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 title_wv->type = TEXT_TYPE;
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
245 title_wv->name = wv->name;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 title_wv->enabled = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 title_wv->next = sep_wv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 sep_wv->type = SEPARATOR_TYPE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 sep_wv->value = menu_separator_style ("==");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 sep_wv->next = 0;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
251
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 wv->contents = title_wv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 prev = sep_wv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 }
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
255 wv->enabled = ! NILP (active_p);
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
256 if (deep_p && !wv->enabled && !NILP (desc))
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
257 {
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
258 widget_value *dummy;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
259 /* Add a fake entry so the menus show up */
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
260 wv->contents = dummy = xmalloc_widget_value ();
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
261 dummy->name = "(inactive)";
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
262 dummy->accel = LISP_TO_VOID (Qnil);
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
263 dummy->enabled = 0;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
264 dummy->selected = 0;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
265 dummy->value = NULL;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
266 dummy->type = BUTTON_TYPE;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
267 dummy->call_data = NULL;
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
268 dummy->next = NULL;
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
269
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
270 goto menu_item_done;
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
271 }
377
d883f39b8495 Import from CVS: tag r21-2b4
cvs
parents: 373
diff changeset
272
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 else if (menubar_root_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 {
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
276 wv->name = (char *) "menubar";
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 wv->type = CASCADE_TYPE; /* Well, nothing else seems to fit and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 this is ignored anyway... */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
282 signal_simple_error ("Menu name (first element) must be a string",
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 desc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 }
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
285
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 if (deep_p || menubar_root_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 widget_value *next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 for (; !NILP (desc); desc = Fcdr (desc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 Lisp_Object child = Fcar (desc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 if (menubar_root_p && NILP (child)) /* the partition */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 if (partition_seen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 error (
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
296 "More than one partition (nil) in menubar description");
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 partition_seen = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 next = xmalloc_widget_value ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 next->type = PUSHRIGHT_TYPE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 {
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
303 next = menu_item_descriptor_to_widget_value_1
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
304 (child, menu_type, deep_p, filter_p, depth + 1);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 if (! next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 else if (prev)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 prev->next = next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 wv->contents = next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 prev = next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 if (deep_p && !wv->contents)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 wv = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 else if (NILP (desc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 error ("nil may not appear in menu descriptions");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 else
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
321 signal_simple_error ("Unrecognized menu descriptor", desc);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
323 menu_item_done:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 if (wv)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 /* Completed normally. Clear out the object that widget_value_unwind()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 will be called with to tell it not to free the wv (as we are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 returning it.) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 set_opaque_ptr (wv_closure, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 unbind_to (count, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 return wv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 static widget_value *
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
338 menu_item_descriptor_to_widget_value (Lisp_Object desc,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 int menu_type, /* if this is a menubar,
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
340 popup or sub menu */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 int deep_p, /* */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 int filter_p) /* if :filter forms
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
343 should run now */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 widget_value *wv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 int count = specpdl_depth ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 record_unwind_protect (restore_gc_inhibit,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 make_int (gc_currently_forbidden));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 gc_currently_forbidden = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 /* Can't GC! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 wv = menu_item_descriptor_to_widget_value_1 (desc, menu_type, deep_p,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 filter_p, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 unbind_to (count, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 return wv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 217
diff changeset
358 #if defined LWLIB_MENUBARS_LUCID || defined LWLIB_MENUBARS_MOTIF
138
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 114
diff changeset
359 int in_menu_callback;
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 114
diff changeset
360
169
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 165
diff changeset
361 static Lisp_Object
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 165
diff changeset
362 restore_in_menu_callback (Lisp_Object val)
138
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 114
diff changeset
363 {
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
364 in_menu_callback = XINT(val);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
365 return Qnil;
138
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 114
diff changeset
366 }
243
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 231
diff changeset
367 #endif /* LWLIB_MENUBARS_LUCID || LWLIB_MENUBARS_MOTIF */
138
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 114
diff changeset
368
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
369 #if 0
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
370 /* #### Sort of a hack needed to process Vactivate_menubar_hook
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
371 correctly wrt buffer-local values. A correct solution would
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
372 involve adding a callback mechanism to run_hook(). This function
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
373 is currently unused. */
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
374 static int
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
375 my_run_hook (Lisp_Object hooksym, int allow_global_p)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
376 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
377 /* This function can GC */
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
378 Lisp_Object tail;
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
379 Lisp_Object value = Fsymbol_value (hooksym);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
380 int changes = 0;
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
381
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
382 if (!NILP (value) && (!CONSP (value) || EQ (XCAR (value), Qlambda)))
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
383 return !EQ (call0 (value), Qt);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
384
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
385 EXTERNAL_LIST_LOOP (tail, value)
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
386 {
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
387 if (allow_global_p && EQ (XCAR (tail), Qt))
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
388 changes |= my_run_hook (Fdefault_value (hooksym), 0);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
389 if (!EQ (call0 (XCAR (tail)), Qt))
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
390 changes = 1;
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
391 }
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
392 return changes;
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
393 }
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
394 #endif
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
395
138
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 114
diff changeset
396
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 /* The order in which callbacks are run is funny to say the least.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 It's sometimes tricky to avoid running a callback twice, and to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 avoid returning prematurely. So, this function returns true
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 if the menu's callbacks are no longer gc protected. So long
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 as we unprotect them before allowing other callbacks to run,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 everything should be ok.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 The pre_activate_callback() *IS* intentionally called multiple times.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 If client_data == NULL, then it's being called before the menu is posted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 If client_data != NULL, then client_data is a (widget_value *) and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 client_data->data is a Lisp_Object pointing to a lisp submenu description
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 that must be converted into widget_values. *client_data is destructively
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
409 modified.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 #### Stig thinks that there may be a GC problem here due to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 fact that pre_activate_callback() is called multiple times, but I
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 think he's wrong.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 pre_activate_callback (Widget widget, LWLIB_ID id, XtPointer client_data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 struct device *d = get_device_from_display (XtDisplay (widget));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 struct frame *f = x_any_window_to_frame (d, XtWindow (widget));
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 70
diff changeset
423 Lisp_Object frame;
138
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 114
diff changeset
424 int count;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
426 /* set in lwlib to the time stamp associated with the most recent menu
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
427 operation */
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
428 extern Time x_focus_timestamp_really_sucks_fix_me_better;
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
429
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 if (!f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 f = x_any_window_to_frame (d, XtWindow (XtParent (widget)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 if (!f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 70
diff changeset
435 /* make sure f is the selected frame */
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 70
diff changeset
436 XSETFRAME (frame, f);
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 70
diff changeset
437 Fselect_frame (frame);
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 70
diff changeset
438
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 if (client_data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 /* this is an incremental menu construction callback */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 widget_value *hack_wv = (widget_value *) client_data;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 Lisp_Object submenu_desc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 widget_value *wv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 assert (hack_wv->type == INCREMENTAL_TYPE);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 VOID_TO_LISP (submenu_desc, hack_wv->call_data);
138
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 114
diff changeset
448
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 114
diff changeset
449 /*
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 114
diff changeset
450 * #### Fix the menu code so this isn't necessary.
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 114
diff changeset
451 *
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 114
diff changeset
452 * Protect against reentering the menu code otherwise we will
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 114
diff changeset
453 * crash later when the code gets confused at the state
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 114
diff changeset
454 * changes.
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 114
diff changeset
455 */
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 114
diff changeset
456 count = specpdl_depth ();
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 114
diff changeset
457 record_unwind_protect (restore_in_menu_callback,
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 114
diff changeset
458 make_int (in_menu_callback));
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 114
diff changeset
459 in_menu_callback = 1;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 wv = menu_item_descriptor_to_widget_value (submenu_desc, SUBMENU_TYPE,
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 102
diff changeset
461 1, 0);
138
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 114
diff changeset
462 unbind_to (count, Qnil);
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 114
diff changeset
463
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 if (!wv)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 wv = xmalloc_widget_value ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 wv->type = CASCADE_TYPE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 wv->next = NULL;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
469 wv->accel = LISP_TO_VOID (Qnil);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 wv->contents = xmalloc_widget_value ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 wv->contents->type = TEXT_TYPE;
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
472 wv->contents->name = (char *) "No menu";
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 wv->contents->next = NULL;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
474 wv->contents->accel = LISP_TO_VOID (Qnil);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 assert (wv && wv->type == CASCADE_TYPE && wv->contents);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 replace_widget_value_tree (hack_wv, wv->contents);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 free_popup_widget_value_tree (wv);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 }
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
480 else if (!POPUP_DATAP (FRAME_MENUBAR_DATA (f)))
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
481 return;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 {
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
484 #if 0 /* Unused, see comment below. */
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
485 int any_changes;
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
486
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 /* #### - this menubar update mechanism is expensively anti-social and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 the activate-menubar-hook is now mostly obsolete. */
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
489 any_changes = my_run_hook (Qactivate_menubar_hook, 1);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
490
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 /* #### - It is necessary to *ALWAYS* call set_frame_menubar() now that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 incremental menus are implemented. If a subtree of a menu has been
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 updated incrementally (a destructive operation), then that subtree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 must somehow be wiped.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 It is difficult to undo the destructive operation in lwlib because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 a pointer back to lisp data needs to be hidden away somewhere. So
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 that an INCREMENTAL_TYPE widget_value can be recreated... Hmmmmm. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 if (any_changes ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 !XFRAME_MENUBAR_DATA (f)->menubar_contents_up_to_date)
373
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
501 set_frame_menubar (f, 1, 0);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
502 #else
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
503 run_hook (Qactivate_menubar_hook);
6240c7796c7a Import from CVS: tag r21-2b2
cvs
parents: 371
diff changeset
504 set_frame_menubar (f, 1, 0);
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 359
diff changeset
505 #endif
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
506 DEVICE_X_MOUSE_TIMESTAMP (XDEVICE (FRAME_DEVICE (f))) =
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
507 DEVICE_X_GLOBAL_MOUSE_TIMESTAMP (XDEVICE (FRAME_DEVICE (f))) =
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 173
diff changeset
508 x_focus_timestamp_really_sucks_fix_me_better;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 static widget_value *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 compute_menubar_data (struct frame *f, Lisp_Object menubar, int deep_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 {
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
515 widget_value *data;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
516
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 if (NILP (menubar))
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
518 data = 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 {
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
521 Lisp_Object old_buffer;
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 70
diff changeset
522 int count = specpdl_depth ();
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 70
diff changeset
523
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
524 old_buffer = Fcurrent_buffer ();
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
525 record_unwind_protect (Fset_buffer, old_buffer);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
526 Fset_buffer ( XWINDOW (FRAME_SELECTED_WINDOW (f))->buffer);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 data = menu_item_descriptor_to_widget_value (menubar, MENUBAR_TYPE,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 deep_p, 0);
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
529 Fset_buffer (old_buffer);
82
6a378aca36af Import from CVS: tag r20-0b91
cvs
parents: 70
diff changeset
530 unbind_to (count, Qnil);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 }
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
532 return data;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 set_frame_menubar (struct frame *f, int deep_p, int first_time_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 widget_value *data;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 Lisp_Object menubar;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 int menubar_visible;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 long id;
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
542 /* As for the toolbar, the minibuffer does not have its own menubar. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 struct window *w = XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 if (! FRAME_X_P (f))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 /***** first compute the contents of the menubar *****/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 if (! first_time_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 /* evaluate `current-menubar' in the buffer of the selected window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 of the frame in question. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 menubar = symbol_value_in_buffer (Qcurrent_menubar, w->buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 /* That's a little tricky the first time since the frame isn't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 fully initialized yet. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 menubar = Fsymbol_value (Qcurrent_menubar);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 if (NILP (menubar))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 menubar = Vblank_menubar;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 menubar_visible = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 menubar_visible = !NILP (w->menubar_visible_p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 data = compute_menubar_data (f, menubar, deep_p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 if (!data || (!data->next && !data->contents))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 abort ();
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
574
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 if (NILP (FRAME_MENUBAR_DATA (f)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 struct popup_data *mdata =
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
578 alloc_lcrecord_type (struct popup_data, &lrecord_popup_data);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 mdata->id = new_lwlib_id ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 mdata->last_menubar_buffer = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 mdata->menubar_contents_up_to_date = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 XSETPOPUP_DATA (FRAME_MENUBAR_DATA (f), mdata);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 /***** now store into the menubar widget, creating it if necessary *****/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 id = XFRAME_MENUBAR_DATA (f)->id;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 if (!FRAME_X_MENUBAR_WIDGET (f))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 Widget parent = FRAME_X_CONTAINER_WIDGET (f);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 assert (first_time_p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 /* It's the first time we've mapped the menubar so compute its
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 contents completely once. This makes sure that the menubar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 components are created with the right type. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 if (!deep_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 free_popup_widget_value_tree (data);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 data = compute_menubar_data (f, menubar, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 FRAME_X_MENUBAR_WIDGET (f) =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 lw_create_widget ("menubar", "menubar", id, data, parent,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 0, pre_activate_callback,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 popup_selection_callback, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 lw_modify_all_widgets (id, data, deep_p ? True : False);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 free_popup_widget_value_tree (data);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
616
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 XFRAME_MENUBAR_DATA (f)->menubar_contents_up_to_date = deep_p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 XFRAME_MENUBAR_DATA (f)->last_menubar_buffer =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f))->buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 return menubar_visible;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
624 /* Called from x_create_widgets() to create the initial menubar of a frame
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 before it is mapped, so that the window is mapped with the menubar already
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 there instead of us tacking it on later and thrashing the window after it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 is visible. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 x_initialize_frame_menubar (struct frame *f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 return set_frame_menubar (f, 1, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 static LWLIB_ID last_popup_menu_selection_callback_id;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 popup_menu_selection_callback (Widget widget, LWLIB_ID id,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 XtPointer client_data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 last_popup_menu_selection_callback_id = id;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 popup_selection_callback (widget, id, client_data);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 /* lw_destroy_all_widgets() will be called from popup_down_callback() */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 popup_menu_down_callback (Widget widget, LWLIB_ID id, XtPointer client_data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 if (popup_handled_p (id))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 assert (popup_up_p != 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 ungcpro_popup_callbacks (id);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 popup_up_p--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 /* if this isn't called immediately after the selection callback, then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 there wasn't a menu selection. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 if (id != last_popup_menu_selection_callback_id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 popup_selection_callback (widget, id, (XtPointer) -1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 lw_destroy_all_widgets (id);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 static void
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
663 make_dummy_xbutton_event (XEvent *dummy,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
664 Widget daddy,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
665 struct Lisp_Event *eev)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 /* NULL for eev means query pointer */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 XButtonPressedEvent *btn = (XButtonPressedEvent *) dummy;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 btn->type = ButtonPress;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 btn->serial = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 btn->send_event = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 btn->display = XtDisplay (daddy);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 btn->window = XtWindow (daddy);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 if (eev)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 Position shellx, shelly, framex, framey;
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 163
diff changeset
678 Arg al [2];
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 btn->time = eev->timestamp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 btn->button = eev->event.button.button;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 btn->root = RootWindowOfScreen (XtScreen (daddy));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 btn->subwindow = (Window) NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 btn->x = eev->event.button.x;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 btn->y = eev->event.button.y;
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 420
diff changeset
685 shellx = shelly = 0;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 420
diff changeset
686 #ifndef HAVE_WMCOMMAND
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 420
diff changeset
687 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 420
diff changeset
688 Widget shell = XtParent (daddy);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 420
diff changeset
689
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 420
diff changeset
690 XtSetArg (al [0], XtNx, &shellx);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 420
diff changeset
691 XtSetArg (al [1], XtNy, &shelly);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 420
diff changeset
692 XtGetValues (shell, al, 2);
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 420
diff changeset
693 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 420
diff changeset
694 #endif
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 163
diff changeset
695 XtSetArg (al [0], XtNx, &framex);
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 163
diff changeset
696 XtSetArg (al [1], XtNy, &framey);
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 163
diff changeset
697 XtGetValues (daddy, al, 2);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 btn->x_root = shellx + framex + btn->x;
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 377
diff changeset
699 btn->y_root = shelly + framey + btn->y;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 btn->state = ButtonPressMask; /* all buttons pressed */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 /* CurrentTime is just ZERO, so it's worthless for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 determining relative click times. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 struct device *d = get_device_from_display (XtDisplay (daddy));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 btn->time = DEVICE_X_MOUSE_TIMESTAMP (d); /* event-Xt maintains this */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 btn->button = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 XQueryPointer (btn->display, btn->window, &btn->root,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 &btn->subwindow, &btn->x_root, &btn->y_root,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 &btn->x, &btn->y, &btn->state);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 x_update_frame_menubar_internal (struct frame *f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 /* We assume the menubar contents has changed if the global flag is set,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 or if the current buffer has changed, or if the menubar has never
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 been updated before.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 int menubar_contents_changed =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 (f->menubar_changed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 || NILP (FRAME_MENUBAR_DATA (f))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 || (!EQ (XFRAME_MENUBAR_DATA (f)->last_menubar_buffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f))->buffer)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
730 Boolean menubar_was_visible = XtIsManaged (FRAME_X_MENUBAR_WIDGET (f));
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
731 Boolean menubar_will_be_visible = menubar_was_visible;
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 82
diff changeset
732 Boolean menubar_visibility_changed;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
733
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 if (menubar_contents_changed)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 menubar_will_be_visible = set_frame_menubar (f, 0, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 menubar_visibility_changed = menubar_was_visible != menubar_will_be_visible;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 272
diff changeset
739 if (!menubar_visibility_changed)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 /* Set menubar visibility */
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 272
diff changeset
743 (menubar_will_be_visible ? XtManageChild : XtUnmanageChild)
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 272
diff changeset
744 (FRAME_X_MENUBAR_WIDGET (f));
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
745
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 272
diff changeset
746 MARK_FRAME_SIZE_SLIPPED (f);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 x_update_frame_menubars (struct frame *f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 assert (FRAME_X_P (f));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 x_update_frame_menubar_internal (f);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 /* #### This isn't going to work right now that this function works on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 a per-frame, not per-device basis. Guess what? I don't care. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 x_free_frame_menubars (struct frame *f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 Widget menubar_widget;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 assert (FRAME_X_P (f));
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
766
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 menubar_widget = FRAME_X_MENUBAR_WIDGET (f);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 if (menubar_widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 LWLIB_ID id = XFRAME_MENUBAR_DATA (f)->id;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 lw_destroy_all_widgets (id);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 XFRAME_MENUBAR_DATA (f)->id = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 x_popup_menu (Lisp_Object menu_desc, Lisp_Object event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 int menu_id;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 struct frame *f = selected_frame ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 widget_value *data;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 Widget parent;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 Widget menu;
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
784 struct Lisp_Event *eev = NULL;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 XEvent xev;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
786 Lisp_Object frame;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 XSETFRAME (frame, f);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 CHECK_X_FRAME (frame);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 parent = FRAME_X_SHELL_WIDGET (f);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 if (!NILP (event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 CHECK_LIVE_EVENT (event);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 eev= XEVENT (event);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 if (eev->event_type != button_press_event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 && eev->event_type != button_release_event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 wrong_type_argument (Qmouse_event_p, event);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 else if (!NILP (Vthis_command_keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 /* if an event wasn't passed, use the last event of the event sequence
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 currently being executed, if that event is a mouse event */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 eev = XEVENT (Vthis_command_keys); /* last event first */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 if (eev->event_type != button_press_event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 && eev->event_type != button_release_event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 eev = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 make_dummy_xbutton_event (&xev, parent, eev);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 if (SYMBOLP (menu_desc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 menu_desc = Fsymbol_value (menu_desc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 CHECK_CONS (menu_desc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 CHECK_STRING (XCAR (menu_desc));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 data = menu_item_descriptor_to_widget_value (menu_desc, POPUP_TYPE, 1, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 if (! data) error ("no menu");
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
818
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 menu_id = new_lwlib_id ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 menu = lw_create_widget ("popup", "popup" /* data->name */, menu_id, data,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 parent, 1, 0,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 popup_menu_selection_callback,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 popup_menu_down_callback);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 free_popup_widget_value_tree (data);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 gcpro_popup_callbacks (menu_id);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 /* Setting zmacs-region-stays is necessary here because executing a command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 from a menu is really a two-command process: the first command (bound to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 the button-click) simply pops up the menu, and returns. This causes a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 sequence of magic-events (destined for the popup-menu widget) to begin.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 Eventually, a menu item is selected, and a menu-event blip is pushed onto
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 the end of the input stream, which is then executed by the event loop.
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
834
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 So there are two command-events, with a bunch of magic-events between
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 them. We don't want the *first* command event to alter the state of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 region, so that the region can be available as an argument for the second
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 command.
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
839 */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 if (zmacs_regions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 zmacs_region_stays = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 popup_up_p++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 lw_popup_menu (menu, &xev);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 /* this speeds up display of pop-up menus */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 XFlush (XtDisplay (parent));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 syms_of_menubar_x (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 console_type_create_menubar_x (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 CONSOLE_HAS_METHOD (x, update_frame_menubars);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 CONSOLE_HAS_METHOD (x, free_frame_menubars);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 CONSOLE_HAS_METHOD (x, popup_menu);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 void
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 420
diff changeset
864 reinit_vars_of_menubar_x (void)
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 420
diff changeset
865 {
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 420
diff changeset
866 last_popup_menu_selection_callback_id = (LWLIB_ID) -1;
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 420
diff changeset
867 }
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 420
diff changeset
868
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 420
diff changeset
869 void
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
870 vars_of_menubar_x (void)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 384
diff changeset
871 {
424
11054d720c21 Import from CVS: tag r21-2-20
cvs
parents: 420
diff changeset
872 reinit_vars_of_menubar_x ();
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 #if defined (LWLIB_MENUBARS_LUCID)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 Fprovide (intern ("lucid-menubars"));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 #elif defined (LWLIB_MENUBARS_MOTIF)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 Fprovide (intern ("motif-menubars"));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 #elif defined (LWLIB_MENUBARS_ATHENA)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 Fprovide (intern ("athena-menubars"));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 }