annotate src/menubar-x.c @ 8:4b173ad71786 r19-15b5

Import from CVS: tag r19-15b5
author cvs
date Mon, 13 Aug 2007 08:47:35 +0200
parents ac2d302a0011
children 0293115a14e9
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 /* created 16-dec-91 by jwz */
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 "EmacsManager.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 #include "EmacsFrame.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 #include "EmacsShell.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 #include "gui-x.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 #include "buffer.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 #include "commands.h" /* zmacs_regions */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 #include "events.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 #include "frame.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 #include "opaque.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 #include "window.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 static int set_frame_menubar (struct frame *f,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 int deep_p,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 int first_time_p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 #define FRAME_MENUBAR_DATA(frame) ((frame)->menubar_data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 #define XFRAME_MENUBAR_DATA(frame) XPOPUP_DATA ((frame)->menubar_data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 #define MENUBAR_TYPE 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 #define SUBMENU_TYPE 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 #define POPUP_TYPE 2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 /* Converting Lisp menu tree descriptions to lwlib's `widget_value' form.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 menu_item_descriptor_to_widget_value() converts a lisp description of a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 menubar into a tree of widget_value structures. It allocates widget_values
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 with malloc_widget_value() and allocates other storage only for the `key'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 slot. All other slots are filled with pointers to Lisp_String data. We
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 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
61 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
62 immediately free our widget_value tree; it will not be referenced again.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 Incremental menu construction callbacks operate just a bit differently.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 They allocate widget_values and call replace_widget_value_tree() to tell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 lwlib to destructively modify the incremental stub (subtree) of its
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 separate widget_value tree.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 This function is highly recursive (it follows the menu trees) and may call
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 eval. The reason we keep pointers to lisp string data instead of copying
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 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
72 (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
73 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
74 for us to use in that case.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 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
77 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
78 strings because of the recursive nature of this function, and the fact that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 it returns a data structure that gets freed later. So... we do the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 sleaziest thing possible and inhibit GC for the duration. This is probably
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 not a big deal...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 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
84 this function successfully finishes. lwlib copies all such data with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 strdup().
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 static widget_value *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 menu_item_descriptor_to_widget_value_1 (Lisp_Object desc,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 int menu_type, int deep_p,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 int filter_p,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 int depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 /* This function cannot GC.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 It is only called from menu_item_descriptor_to_widget_value, which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 prohibits GC. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 /* !!#### This function has not been Mule-ized */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 int menubar_root_p = (menu_type == MENUBAR_TYPE && depth == 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 widget_value *wv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 Lisp_Object wv_closure;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 int count = specpdl_depth ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 int partition_seen = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 wv = xmalloc_widget_value ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 wv_closure = make_opaque_ptr (wv);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 record_unwind_protect (widget_value_unwind, wv_closure);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 if (STRINGP (desc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 char *string_chars = (char *) string_data (XSTRING (desc));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 wv->type = (separator_string_p (string_chars) ? SEPARATOR_TYPE :
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 TEXT_TYPE);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 #if 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 /* #### - should internationalize with X resources instead.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 Not so! --ben */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 string_chars = GETTEXT (string_chars);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 if (wv->type == SEPARATOR_TYPE)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 wv->value = menu_separator_style (string_chars);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 wv->name = string_chars;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 wv->enabled = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 else if (VECTORP (desc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 if (!button_item_to_widget_value (desc, wv, 1,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (menu_type == MENUBAR_TYPE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 && depth <= 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 /* :included form was nil */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 wv = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 goto menu_item_done;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 else if (CONSP (desc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 Lisp_Object incremental_data = desc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 widget_value *prev = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 if (STRINGP (XCAR (desc)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 Lisp_Object key, val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 Lisp_Object include_p, hook_fn = Qnil, config_tag = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 int included_spec = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 wv->type = CASCADE_TYPE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 wv->enabled = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 wv->name =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (char *) string_data (XSTRING (LISP_GETTEXT (XCAR (desc))));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 desc = Fcdr (desc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 while (key = Fcar (desc), KEYWORDP (key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 Lisp_Object cascade = desc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 desc = Fcdr (desc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 if (NILP (desc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 signal_simple_error ("keyword in menu lacks a value",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 cascade);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 val = Fcar (desc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 desc = Fcdr (desc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 if (EQ (key, Q_included))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 include_p = val, included_spec = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 else if (EQ (key, Q_config))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 config_tag = val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 else if (EQ (key, Q_filter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 hook_fn = val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 signal_simple_error ("unknown menu cascade keyword", cascade);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 if ((!NILP (config_tag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 && NILP (Fmemq (config_tag, Vmenubar_configuration)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 || (included_spec && NILP (Feval (include_p))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 wv = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 goto menu_item_done;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 if (!NILP (hook_fn))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 #ifdef LWLIB_MENUBARS_LUCID
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 if (filter_p || depth == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 desc = call1_trapping_errors ("Error in menubar filter",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 hook_fn, desc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 if (UNBOUNDP (desc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 desc = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 #ifdef LWLIB_MENUBARS_LUCID
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 widget_value *incr_wv = xmalloc_widget_value ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 wv->contents = incr_wv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 incr_wv->type = INCREMENTAL_TYPE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 incr_wv->enabled = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 incr_wv->name = wv->name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 /* This is automatically GC protected through
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 the call to lw_map_widget_values(); no need
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 to worry. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 incr_wv->call_data = LISP_TO_VOID (incremental_data);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 goto menu_item_done;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 if (menu_type == POPUP_TYPE && popup_menu_titles && depth == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 /* Simply prepend three more widget values to the contents of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 the menu: a label, and two separators (to get a double
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 line). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 widget_value *title_wv = xmalloc_widget_value ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 widget_value *sep_wv = xmalloc_widget_value ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 title_wv->type = TEXT_TYPE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 title_wv->name = wv->name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 title_wv->enabled = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 title_wv->next = sep_wv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 sep_wv->type = SEPARATOR_TYPE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 sep_wv->value = menu_separator_style ("==");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 sep_wv->next = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 wv->contents = title_wv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 prev = sep_wv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 else if (menubar_root_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 {
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
231 wv->name = (char *) "menubar";
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 wv->type = CASCADE_TYPE; /* Well, nothing else seems to fit and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 this is ignored anyway... */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 signal_simple_error ("menu name (first element) must be a string",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 desc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 wv->enabled = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 if (deep_p || menubar_root_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 widget_value *next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 for (; !NILP (desc); desc = Fcdr (desc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 Lisp_Object child = Fcar (desc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 if (menubar_root_p && NILP (child)) /* the partition */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 if (partition_seen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 error (
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 "more than one partition (nil) in menubar description");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 partition_seen = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 next = xmalloc_widget_value ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 next->type = PUSHRIGHT_TYPE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 next = menu_item_descriptor_to_widget_value_1 (child,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 menu_type,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 deep_p,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 filter_p,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 depth + 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 if (! next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 else if (prev)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 prev->next = next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 wv->contents = next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 prev = next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 if (deep_p && !wv->contents)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 wv = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 else if (NILP (desc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 error ("nil may not appear in menu descriptions");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 signal_simple_error ("unrecognized menu descriptor", desc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 menu_item_done:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 if (wv)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 /* Completed normally. Clear out the object that widget_value_unwind()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 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
288 returning it.) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 set_opaque_ptr (wv_closure, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 unbind_to (count, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 return wv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 static widget_value *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 menu_item_descriptor_to_widget_value (Lisp_Object desc,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 int menu_type, /* if this is a menubar,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 popup or sub menu */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 int deep_p, /* */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 int filter_p) /* if :filter forms
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 should run now */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 widget_value *wv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 int count = specpdl_depth ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 record_unwind_protect (restore_gc_inhibit,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 make_int (gc_currently_forbidden));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 gc_currently_forbidden = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 /* Can't GC! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 wv = menu_item_descriptor_to_widget_value_1 (desc, menu_type, deep_p,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 filter_p, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 unbind_to (count, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 return wv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 /* The order in which callbacks are run is funny to say the least.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 It's sometimes tricky to avoid running a callback twice, and to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 avoid returning prematurely. So, this function returns true
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 if the menu's callbacks are no longer gc protected. So long
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 as we unprotect them before allowing other callbacks to run,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 everything should be ok.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 The pre_activate_callback() *IS* intentionally called multiple times.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 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
326 If client_data != NULL, then client_data is a (widget_value *) and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 client_data->data is a Lisp_Object pointing to a lisp submenu description
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 that must be converted into widget_values. *client_data is destructively
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 modified.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 #### Stig thinks that there may be a GC problem here due to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 fact that pre_activate_callback() is called multiple times, but I
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 think he's wrong.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334
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 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 pre_activate_callback (Widget widget, LWLIB_ID id, XtPointer client_data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 struct gcpro gcpro1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 struct device *d = get_device_from_display (XtDisplay (widget));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 struct frame *f = x_any_window_to_frame (d, XtWindow (widget));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 Lisp_Object rest = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 int any_changes = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 if (!f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 f = x_any_window_to_frame (d, XtWindow (XtParent (widget)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 if (!f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 if (client_data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 /* this is an incremental menu construction callback */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 widget_value *hack_wv = (widget_value *) client_data;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 Lisp_Object submenu_desc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 widget_value *wv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 assert (hack_wv->type == INCREMENTAL_TYPE);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 VOID_TO_LISP (submenu_desc, hack_wv->call_data);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 wv = menu_item_descriptor_to_widget_value (submenu_desc, SUBMENU_TYPE,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 1, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 if (!wv)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 wv = xmalloc_widget_value ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 wv->type = CASCADE_TYPE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 wv->next = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 wv->contents = xmalloc_widget_value ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 wv->contents->type = TEXT_TYPE;
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
370 wv->contents->name = (char *) "No menu";
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 wv->contents->next = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 assert (wv && wv->type == CASCADE_TYPE && wv->contents);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 replace_widget_value_tree (hack_wv, wv->contents);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 free_popup_widget_value_tree (wv);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 if (!POPUP_DATAP (FRAME_MENUBAR_DATA (f)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 /* #### - this menubar update mechanism is expensively anti-social and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 the activate-menubar-hook is now mostly obsolete. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 /* make the activate-menubar-hook be a list of functions, not a single
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 function, just to simplify things. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 if (!NILP (Vactivate_menubar_hook) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 (!CONSP (Vactivate_menubar_hook) ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 EQ (XCAR (Vactivate_menubar_hook), Qlambda)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 Vactivate_menubar_hook = Fcons (Vactivate_menubar_hook, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 GCPRO1 (rest);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 for (rest = Vactivate_menubar_hook; !NILP (rest); rest = Fcdr (rest))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 if (!EQ (call0 (XCAR (rest)), Qt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 any_changes = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 /* #### - It is necessary to *ALWAYS* call set_frame_menubar() now that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 incremental menus are implemented. If a subtree of a menu has been
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 updated incrementally (a destructive operation), then that subtree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 must somehow be wiped.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 It is difficult to undo the destructive operation in lwlib because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 a pointer back to lisp data needs to be hidden away somewhere. So
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 that an INCREMENTAL_TYPE widget_value can be recreated... Hmmmmm. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 if (any_changes ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 !XFRAME_MENUBAR_DATA (f)->menubar_contents_up_to_date)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 set_frame_menubar (f, 1, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 #ifdef ENERGIZE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 extern int *get_psheets_for_buffer (Lisp_Object, int *);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 set_panel_button_sensitivity (struct frame *f, widget_value *data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 struct window *window = XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 int current_buffer_psheets_count = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 int *current_buffer_psheets =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 get_psheets_for_buffer (window->buffer, &current_buffer_psheets_count);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 int panel_enabled = FRAME_X_DESIRED_PSHEETS (f) ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 current_buffer_psheets_count;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 widget_value *val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 for (val = data->contents; val; val = val->next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 if (val->name && !strcmp (val->name, "sheet"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 val->enabled = panel_enabled;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 #endif /* ENERGIZE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 static widget_value *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 compute_menubar_data (struct frame *f, Lisp_Object menubar, int deep_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 widget_value *data;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 if (NILP (menubar))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 data = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 data = menu_item_descriptor_to_widget_value (menubar, MENUBAR_TYPE,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 deep_p, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 #ifdef ENERGIZE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 if (data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 set_panel_button_sensitivity (f, data);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 return data;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 set_frame_menubar (struct frame *f, int deep_p, int first_time_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 widget_value *data;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 Lisp_Object menubar;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 int menubar_visible;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 long id;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 /* As for the toolbar, the minibuffer does not have its own menubar. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 struct window *w = XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 if (! FRAME_X_P (f))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 /***** first compute the contents of the menubar *****/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 if (! first_time_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 /* evaluate `current-menubar' in the buffer of the selected window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 of the frame in question. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 menubar = symbol_value_in_buffer (Qcurrent_menubar, w->buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 /* That's a little tricky the first time since the frame isn't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 fully initialized yet. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 menubar = Fsymbol_value (Qcurrent_menubar);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 if (NILP (menubar))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 menubar = Vblank_menubar;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 menubar_visible = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 menubar_visible = !NILP (w->menubar_visible_p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 data = compute_menubar_data (f, menubar, deep_p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 if (!data || (!data->next && !data->contents))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 if (NILP (FRAME_MENUBAR_DATA (f)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 struct popup_data *mdata =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 alloc_lcrecord (sizeof (struct popup_data), lrecord_popup_data);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 mdata->id = new_lwlib_id ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 mdata->last_menubar_buffer = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 mdata->menubar_contents_up_to_date = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 XSETPOPUP_DATA (FRAME_MENUBAR_DATA (f), mdata);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 /***** now store into the menubar widget, creating it if necessary *****/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 id = XFRAME_MENUBAR_DATA (f)->id;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 if (!FRAME_X_MENUBAR_WIDGET (f))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 Widget parent = FRAME_X_CONTAINER_WIDGET (f);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 assert (first_time_p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 /* It's the first time we've mapped the menubar so compute its
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 contents completely once. This makes sure that the menubar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 components are created with the right type. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 if (!deep_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 free_popup_widget_value_tree (data);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 data = compute_menubar_data (f, menubar, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 FRAME_X_MENUBAR_WIDGET (f) =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 lw_create_widget ("menubar", "menubar", id, data, parent,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 0, pre_activate_callback,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 popup_selection_callback, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 lw_modify_all_widgets (id, data, deep_p ? True : False);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 free_popup_widget_value_tree (data);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 XFRAME_MENUBAR_DATA (f)->menubar_contents_up_to_date = deep_p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 XFRAME_MENUBAR_DATA (f)->last_menubar_buffer =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f))->buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 return menubar_visible;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 /* Called from x_create_widgets() to create the inital menubar of a frame
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 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
543 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
544 is visible. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 x_initialize_frame_menubar (struct frame *f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 return set_frame_menubar (f, 1, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 static LWLIB_ID last_popup_menu_selection_callback_id;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 popup_menu_selection_callback (Widget widget, LWLIB_ID id,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 XtPointer client_data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 last_popup_menu_selection_callback_id = id;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 popup_selection_callback (widget, id, client_data);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 /* lw_destroy_all_widgets() will be called from popup_down_callback() */
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 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 popup_menu_down_callback (Widget widget, LWLIB_ID id, XtPointer client_data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 if (popup_handled_p (id))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 assert (popup_up_p != 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 ungcpro_popup_callbacks (id);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 popup_up_p--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 /* if this isn't called immediately after the selection callback, then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 there wasn't a menu selection. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 if (id != last_popup_menu_selection_callback_id)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 popup_selection_callback (widget, id, (XtPointer) -1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 lw_destroy_all_widgets (id);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 make_dummy_xbutton_event (XEvent *dummy,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 Widget daddy,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 struct Lisp_Event *eev)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 /* NULL for eev means query pointer */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 XButtonPressedEvent *btn = (XButtonPressedEvent *) dummy;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 btn->type = ButtonPress;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 btn->serial = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 btn->send_event = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 btn->display = XtDisplay (daddy);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 btn->window = XtWindow (daddy);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 if (eev)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 Position shellx, shelly, framex, framey;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 Widget shell = XtParent (daddy);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 btn->time = eev->timestamp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 btn->button = eev->event.button.button;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 btn->root = RootWindowOfScreen (XtScreen (daddy));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 btn->subwindow = (Window) NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 btn->x = eev->event.button.x;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 btn->y = eev->event.button.y;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 XtVaGetValues (shell, XtNx, &shellx, XtNy, &shelly, NULL);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 XtVaGetValues (daddy, XtNx, &framex, XtNy, &framey, NULL);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 btn->x_root = shellx + framex + btn->x;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 btn->y_root = shelly + framey + btn->y;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 btn->state = ButtonPressMask; /* all buttons pressed */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 /* CurrentTime is just ZERO, so it's worthless for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 determining relative click times. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 struct device *d = get_device_from_display (XtDisplay (daddy));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 btn->time = DEVICE_X_MOUSE_TIMESTAMP (d); /* event-Xt maintains this */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 btn->button = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 XQueryPointer (btn->display, btn->window, &btn->root,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 &btn->subwindow, &btn->x_root, &btn->y_root,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 &btn->x, &btn->y, &btn->state);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 #ifdef ENERGIZE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 extern int desired_debuggerpanel_exposed_p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 extern int current_debuggerpanel_exposed_p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 extern int debuggerpanel_sheet;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 extern void notify_energize_sheet_hidden (unsigned long);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 x_update_frame_menubar_internal (struct frame *f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 /* We assume the menubar contents has changed if the global flag is set,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 or if the current buffer has changed, or if the menubar has never
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 been updated before.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 int menubar_contents_changed =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 (f->menubar_changed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 || NILP (FRAME_MENUBAR_DATA (f))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 || (!EQ (XFRAME_MENUBAR_DATA (f)->last_menubar_buffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 XWINDOW (FRAME_LAST_NONMINIBUF_WINDOW (f))->buffer)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 int menubar_was_visible = XtIsManaged (FRAME_X_MENUBAR_WIDGET (f));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 int menubar_will_be_visible = menubar_was_visible;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 int menubar_visibility_changed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 Cardinal new_num_top_widgets = 1; /* for the menubar */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 Widget container = FRAME_X_CONTAINER_WIDGET (f);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 #ifdef ENERGIZE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 int *old_sheets = FRAME_X_CURRENT_PSHEETS (f);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 int *new_sheets = FRAME_X_DESIRED_PSHEETS (f);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 int old_count = FRAME_X_CURRENT_PSHEET_COUNT (f);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 int new_count = FRAME_X_DESIRED_PSHEET_COUNT (f);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 Lisp_Object old_buf = FRAME_X_CURRENT_PSHEET_BUFFER (f);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 Lisp_Object new_buf = FRAME_X_DESIRED_PSHEET_BUFFER (f);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 int psheets_changed = (old_sheets != new_sheets
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 || old_count != new_count
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 || !EQ (old_buf, new_buf));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 int debuggerpanel_changed = (desired_debuggerpanel_exposed_p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 != current_debuggerpanel_exposed_p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 if (desired_debuggerpanel_exposed_p && FRAME_X_TOP_WIDGETS (f) [1] == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 /* This happens when the frame was just created. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 debuggerpanel_changed = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 FRAME_X_CURRENT_PSHEETS (f) = FRAME_X_DESIRED_PSHEETS (f);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 FRAME_X_CURRENT_PSHEET_COUNT (f) = FRAME_X_DESIRED_PSHEET_COUNT (f);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 FRAME_X_CURRENT_PSHEET_BUFFER (f) = FRAME_X_DESIRED_PSHEET_BUFFER (f);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 #endif /* ENERGIZE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 if (menubar_contents_changed)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 menubar_will_be_visible = set_frame_menubar (f, 0, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 menubar_visibility_changed = menubar_was_visible != menubar_will_be_visible;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 if (! (menubar_visibility_changed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 #ifdef ENERGIZE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 || psheets_changed || debuggerpanel_changed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 /* Set menubar visibility */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 if (menubar_visibility_changed)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 (menubar_will_be_visible ? XtManageChild : XtUnmanageChild)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 (FRAME_X_MENUBAR_WIDGET (f));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 #ifdef ENERGIZE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 /* Set debugger panel visibility */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 if (debuggerpanel_changed)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 Widget w;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 int sheet = debuggerpanel_sheet;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 w = lw_get_widget (sheet, container, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 if (desired_debuggerpanel_exposed_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 if (! w)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 w = lw_make_widget (sheet, container, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 FRAME_X_TOP_WIDGETS (f)[1] = w;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 XtManageChild (w);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 notify_energize_sheet_hidden (sheet);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 if (w)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 XtUnmanageChild (w);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 /* Set psheet visibility. For the moment we just unmanage all the old
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 ones, and then manage all the new ones. If the number of psheets
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 ever becomes a large number (i.e. > 1), then we can worry about a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 more sophisticated way of doing this. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 if (psheets_changed)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 Widget w;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 unsigned long sheet;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 for (i=0; i<old_count; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 sheet = old_sheets[i];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 w = lw_get_widget (sheet, container, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 notify_energize_sheet_hidden (sheet);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 if (w)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 XtUnmanageChild (w);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 for (i=0; i<new_count; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 sheet = new_sheets[i];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 /* #### This unconditional call to lw_make_widget() is a bad
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 idea. Doesn't it cause a memory leak if the widget
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 already exists?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 #### How does Energize know that a sheet just got displayed?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 #### Energize knows all. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 w = lw_make_widget (sheet, container, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 FRAME_X_TOP_WIDGETS (f)[2+i] = w;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 XtManageChild (w);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 new_num_top_widgets += 1+new_count;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 #endif /* ENERGIZE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 /* Note that new_num_top_widgets doesn't need to reflect the actual
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 number of top widgets, but just the limit of FRAME_X_TOP_WIDGETS (f)[]. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 FRAME_X_NUM_TOP_WIDGETS (f) = new_num_top_widgets;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 /* We want to end up as close in size as possible to what we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 were before. So, ask the EmacsManager what size it wants
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 to be (suggesting the current size), and resize it to that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 size. It in turn will call our query-geometry callback,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 which will round the size to something that exactly fits
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 the text widget. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 XtWidgetGeometry req, repl;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 req.request_mode = CWWidth | CWHeight;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 XtVaGetValues (container,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 XtNwidth, &req.width,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 XtNheight, &req.height,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 XtQueryGeometry (container, &req, &repl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 EmacsManagerChangeSize (container, repl.width,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 repl.height);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 /* The window size might not have changed but the text size
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 did; thus, the base size might be incorrect. So update
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 EmacsShellUpdateSizeHints (FRAME_X_SHELL_WIDGET (f));
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 #ifdef ENERGIZE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 /* Give back the focus to emacs if no psheets are displayed anymore */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 if (psheets_changed)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 Lisp_Object frame;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 XSETFRAME (frame, f);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 Fselect_frame (frame);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 #endif /* ENERGIZE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 x_update_frame_menubars (struct frame *f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 assert (FRAME_X_P (f));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 x_update_frame_menubar_internal (f);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 /* #### This isn't going to work right now that this function works on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 a per-frame, not per-device basis. Guess what? I don't care. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 #ifdef ENERGIZE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 current_debuggerpanel_exposed_p = desired_debuggerpanel_exposed_p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 x_free_frame_menubars (struct frame *f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 Widget menubar_widget;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 assert (FRAME_X_P (f));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 menubar_widget = FRAME_X_MENUBAR_WIDGET (f);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 if (menubar_widget)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 LWLIB_ID id = XFRAME_MENUBAR_DATA (f)->id;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 lw_destroy_all_widgets (id);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 XFRAME_MENUBAR_DATA (f)->id = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 #ifdef ENERGIZE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 /* Also destroy this frame's psheets */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 Widget parent = FRAME_X_CONTAINER_WIDGET (f);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 int *sheets = FRAME_X_CURRENT_PSHEETS (f);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 int i = FRAME_X_CURRENT_PSHEET_COUNT (f);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 while (i--)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 unsigned long sheet = sheets [i];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 Widget w = lw_get_widget (sheet, parent, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 if (w)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 lw_destroy_widget (w);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 FRAME_X_CURRENT_PSHEET_COUNT (f) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 /* Is this necessary? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 sheets = FRAME_X_DESIRED_PSHEETS (f);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 i = FRAME_X_DESIRED_PSHEET_COUNT (f);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 while (i--)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 unsigned long sheet = sheets [i];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 Widget w = lw_get_widget (sheet, parent, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 if (w)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 lw_destroy_widget (w);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 FRAME_X_DESIRED_PSHEET_COUNT (f) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 /* sigh... debugger panel is special... */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 if (debuggerpanel_sheet)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 Widget w = lw_get_widget (debuggerpanel_sheet, parent, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 if (w)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 lw_destroy_widget (w);
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 #endif /* ENERGIZE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 x_popup_menu (Lisp_Object menu_desc, Lisp_Object event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 int menu_id;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 struct frame *f = selected_frame ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 widget_value *data;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 Widget parent;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 Widget menu;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 struct Lisp_Event *eev = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 XEvent xev;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 Lisp_Object frame = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 XSETFRAME (frame, f);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 CHECK_X_FRAME (frame);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 parent = FRAME_X_SHELL_WIDGET (f);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 if (!NILP (event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 CHECK_LIVE_EVENT (event);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 eev= XEVENT (event);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 if (eev->event_type != button_press_event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 && eev->event_type != button_release_event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 wrong_type_argument (Qmouse_event_p, event);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 else if (!NILP (Vthis_command_keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 /* 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
880 currently being executed, if that event is a mouse event */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 eev = XEVENT (Vthis_command_keys); /* last event first */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 if (eev->event_type != button_press_event
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 && eev->event_type != button_release_event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 eev = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 make_dummy_xbutton_event (&xev, parent, eev);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 if (SYMBOLP (menu_desc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 menu_desc = Fsymbol_value (menu_desc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 CHECK_CONS (menu_desc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 CHECK_STRING (XCAR (menu_desc));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 data = menu_item_descriptor_to_widget_value (menu_desc, POPUP_TYPE, 1, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 if (! data) error ("no menu");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 menu_id = new_lwlib_id ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 menu = lw_create_widget ("popup", "popup" /* data->name */, menu_id, data,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 parent, 1, 0,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 popup_menu_selection_callback,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 popup_menu_down_callback);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 free_popup_widget_value_tree (data);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 gcpro_popup_callbacks (menu_id);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 /* Setting zmacs-region-stays is necessary here because executing a command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 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
907 the button-click) simply pops up the menu, and returns. This causes a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 sequence of magic-events (destined for the popup-menu widget) to begin.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 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
910 the end of the input stream, which is then executed by the event loop.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 So there are two command-events, with a bunch of magic-events between
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 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
914 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
915 command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 if (zmacs_regions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 zmacs_region_stays = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 popup_up_p++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 lw_popup_menu (menu, &xev);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 /* this speeds up display of pop-up menus */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 XFlush (XtDisplay (parent));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 syms_of_menubar_x (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 console_type_create_menubar_x (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 CONSOLE_HAS_METHOD (x, update_frame_menubars);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 CONSOLE_HAS_METHOD (x, free_frame_menubars);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 CONSOLE_HAS_METHOD (x, popup_menu);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 vars_of_menubar_x (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 last_popup_menu_selection_callback_id = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 #if defined (LWLIB_MENUBARS_LUCID)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 Fprovide (intern ("lucid-menubars"));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 #elif defined (LWLIB_MENUBARS_MOTIF)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 Fprovide (intern ("motif-menubars"));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 #elif defined (LWLIB_MENUBARS_ATHENA)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 Fprovide (intern ("athena-menubars"));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 }