428
|
1 /* General GUI code -- X-specific. (menubars, scrollbars, toolbars, dialogs)
|
|
2 Copyright (C) 1995 Board of Trustees, University of Illinois.
|
793
|
3 Copyright (C) 1995, 1996, 2000, 2001, 2002 Ben Wing.
|
428
|
4 Copyright (C) 1995 Sun Microsystems, Inc.
|
|
5 Copyright (C) 1998 Free Software Foundation, Inc.
|
|
6
|
|
7 This file is part of XEmacs.
|
|
8
|
|
9 XEmacs is free software; you can redistribute it and/or modify it
|
|
10 under the terms of the GNU General Public License as published by the
|
|
11 Free Software Foundation; either version 2, or (at your option) any
|
|
12 later version.
|
|
13
|
|
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
17 for more details.
|
|
18
|
|
19 You should have received a copy of the GNU General Public License
|
|
20 along with XEmacs; see the file COPYING. If not, write to
|
|
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 Boston, MA 02111-1307, USA. */
|
|
23
|
|
24 /* Synched up with: Not in FSF. */
|
|
25
|
442
|
26 /* This file Mule-ized by Ben Wing, 7-8-00. */
|
|
27
|
428
|
28 #include <config.h>
|
|
29 #include "lisp.h"
|
|
30
|
872
|
31 #include "buffer.h"
|
|
32 #include "device-impl.h"
|
|
33 #include "events.h"
|
|
34 #include "frame.h"
|
|
35 #include "glyphs.h"
|
|
36 #include "gui.h"
|
|
37 #include "menubar.h"
|
|
38 #include "opaque.h"
|
|
39 #include "redisplay.h"
|
|
40
|
|
41 #include "console-x-impl.h"
|
|
42 #include "gui-x.h"
|
|
43
|
428
|
44 #ifdef LWLIB_USES_MOTIF
|
|
45 #include <Xm/Xm.h> /* for XmVersion */
|
|
46 #endif
|
|
47
|
|
48 /* we need a unique id for each popup menu, dialog box, and scrollbar */
|
647
|
49 static LWLIB_ID lwlib_id_tick;
|
428
|
50
|
|
51 LWLIB_ID
|
|
52 new_lwlib_id (void)
|
|
53 {
|
|
54 return ++lwlib_id_tick;
|
|
55 }
|
|
56
|
|
57 widget_value *
|
|
58 xmalloc_widget_value (void)
|
|
59 {
|
|
60 widget_value *tmp = malloc_widget_value ();
|
|
61 if (!tmp) memory_full ();
|
|
62 return tmp;
|
|
63 }
|
|
64
|
|
65
|
|
66 static int
|
|
67 mark_widget_value_mapper (widget_value *val, void *closure)
|
|
68 {
|
|
69 Lisp_Object markee;
|
|
70 if (val->call_data)
|
|
71 {
|
826
|
72 markee = VOID_TO_LISP (val->call_data);
|
428
|
73 mark_object (markee);
|
|
74 }
|
|
75
|
|
76 if (val->accel)
|
|
77 {
|
826
|
78 markee = VOID_TO_LISP (val->accel);
|
428
|
79 mark_object (markee);
|
|
80 }
|
|
81 return 0;
|
|
82 }
|
|
83
|
|
84 static Lisp_Object
|
|
85 mark_popup_data (Lisp_Object obj)
|
|
86 {
|
|
87 struct popup_data *data = (struct popup_data *) XPOPUP_DATA (obj);
|
|
88
|
|
89 /* Now mark the callbacks and such that are hidden in the lwlib
|
|
90 call-data */
|
|
91
|
|
92 if (data->id)
|
|
93 lw_map_widget_values (data->id, mark_widget_value_mapper, 0);
|
|
94
|
|
95 return data->last_menubar_buffer;
|
|
96 }
|
|
97
|
934
|
98 #ifdef USE_KKCC
|
|
99 DEFINE_LRECORD_IMPLEMENTATION ("popup-data", popup_data,
|
|
100 0, /*dumpable-flag*/
|
|
101 mark_popup_data, internal_object_printer,
|
|
102 0, 0, 0, 0, struct popup_data);
|
|
103 #else /* not USE_KKCC */
|
428
|
104 DEFINE_LRECORD_IMPLEMENTATION ("popup-data", popup_data,
|
|
105 mark_popup_data, internal_object_printer,
|
|
106 0, 0, 0, 0, struct popup_data);
|
934
|
107 #endif /* not USE_KKCC */
|
428
|
108
|
|
109 /* This is like FRAME_MENUBAR_DATA (f), but contains an alist of
|
|
110 (id . popup-data) for GCPRO'ing the callbacks of the popup menus
|
|
111 and dialog boxes. */
|
|
112 static Lisp_Object Vpopup_callbacks;
|
|
113
|
|
114 void
|
|
115 gcpro_popup_callbacks (LWLIB_ID id)
|
|
116 {
|
|
117 struct popup_data *pdata;
|
|
118 Lisp_Object lid = make_int (id);
|
|
119 Lisp_Object lpdata;
|
|
120
|
|
121 assert (NILP (assq_no_quit (lid, Vpopup_callbacks)));
|
|
122 pdata = alloc_lcrecord_type (struct popup_data, &lrecord_popup_data);
|
|
123 pdata->id = id;
|
|
124 pdata->last_menubar_buffer = Qnil;
|
|
125 pdata->menubar_contents_up_to_date = 0;
|
793
|
126 lpdata = wrap_popup_data (pdata);
|
428
|
127 Vpopup_callbacks = Fcons (Fcons (lid, lpdata), Vpopup_callbacks);
|
|
128 }
|
|
129
|
|
130 void
|
|
131 ungcpro_popup_callbacks (LWLIB_ID id)
|
|
132 {
|
|
133 Lisp_Object lid = make_int (id);
|
|
134 Lisp_Object this = assq_no_quit (lid, Vpopup_callbacks);
|
|
135 assert (!NILP (this));
|
|
136 Vpopup_callbacks = delq_no_quit (this, Vpopup_callbacks);
|
|
137 }
|
|
138
|
|
139 int
|
|
140 popup_handled_p (LWLIB_ID id)
|
|
141 {
|
|
142 return NILP (assq_no_quit (make_int (id), Vpopup_callbacks));
|
|
143 }
|
|
144
|
|
145 /* menu_item_descriptor_to_widget_value() et al. mallocs a
|
|
146 widget_value, but then may signal lisp errors. If an error does
|
|
147 not occur, the opaque ptr we have here has had its pointer set to 0
|
|
148 to tell us not to do anything. Otherwise we free the widget value.
|
|
149 (This has nothing to do with GC, it's just about not dropping
|
|
150 pointers to malloc'd data when errors happen.) */
|
|
151
|
|
152 Lisp_Object
|
|
153 widget_value_unwind (Lisp_Object closure)
|
|
154 {
|
|
155 widget_value *wv = (widget_value *) get_opaque_ptr (closure);
|
|
156 free_opaque_ptr (closure);
|
|
157 if (wv)
|
436
|
158 free_widget_value_tree (wv);
|
428
|
159 return Qnil;
|
|
160 }
|
|
161
|
|
162 #if 0
|
|
163 static void
|
|
164 print_widget_value (widget_value *wv, int depth)
|
|
165 {
|
442
|
166 /* strings in wv are in external format; use printf not stdout_out
|
|
167 because the latter takes internal-format strings */
|
|
168 Extbyte d [200];
|
428
|
169 int i;
|
|
170 for (i = 0; i < depth; i++) d[i] = ' ';
|
|
171 d[depth]=0;
|
|
172 /* #### - print type field */
|
|
173 printf ("%sname: %s\n", d, (wv->name ? wv->name : "(null)"));
|
|
174 if (wv->value) printf ("%svalue: %s\n", d, wv->value);
|
|
175 if (wv->key) printf ("%skey: %s\n", d, wv->key);
|
|
176 printf ("%senabled: %d\n", d, wv->enabled);
|
|
177 if (wv->contents)
|
|
178 {
|
|
179 printf ("\n%scontents: \n", d);
|
|
180 print_widget_value (wv->contents, depth + 5);
|
|
181 }
|
|
182 if (wv->next)
|
|
183 {
|
|
184 printf ("\n");
|
|
185 print_widget_value (wv->next, depth);
|
|
186 }
|
|
187 }
|
|
188 #endif
|
|
189
|
|
190 /* This recursively calls free_widget_value() on the tree of widgets.
|
|
191 It must free all data that was malloc'ed for these widget_values.
|
|
192
|
|
193 It used to be that emacs only allocated new storage for the `key' slot.
|
|
194 All other slots are pointers into the data of Lisp_Strings, and must be
|
|
195 left alone. */
|
|
196 void
|
|
197 free_popup_widget_value_tree (widget_value *wv)
|
|
198 {
|
|
199 if (! wv) return;
|
|
200 if (wv->key) xfree (wv->key);
|
|
201 if (wv->value) xfree (wv->value);
|
436
|
202 if (wv->name) xfree (wv->name);
|
428
|
203
|
|
204 wv->name = wv->value = wv->key = (char *) 0xDEADBEEF;
|
|
205
|
|
206 if (wv->contents && (wv->contents != (widget_value*)1))
|
|
207 {
|
|
208 free_popup_widget_value_tree (wv->contents);
|
|
209 wv->contents = (widget_value *) 0xDEADBEEF;
|
|
210 }
|
|
211 if (wv->next)
|
|
212 {
|
|
213 free_popup_widget_value_tree (wv->next);
|
|
214 wv->next = (widget_value *) 0xDEADBEEF;
|
|
215 }
|
|
216 free_widget_value (wv);
|
|
217 }
|
|
218
|
|
219 /* The following is actually called from somewhere within XtDispatchEvent(),
|
|
220 called from XtAppProcessEvent() in event-Xt.c */
|
|
221
|
|
222 void
|
|
223 popup_selection_callback (Widget widget, LWLIB_ID ignored_id,
|
|
224 XtPointer client_data)
|
|
225 {
|
442
|
226 Lisp_Object data, image_instance, callback, callback_ex;
|
|
227 Lisp_Object frame, event;
|
|
228 int update_subwindows_p = 0;
|
428
|
229 struct device *d = get_device_from_display (XtDisplay (widget));
|
|
230 struct frame *f = x_any_widget_or_parent_to_frame (d, widget);
|
|
231
|
872
|
232 #ifdef HAVE_MENUBARS
|
428
|
233 /* set in lwlib to the time stamp associated with the most recent menu
|
|
234 operation */
|
|
235 extern Time x_focus_timestamp_really_sucks_fix_me_better;
|
872
|
236 #endif
|
428
|
237
|
|
238 if (!f)
|
|
239 return;
|
|
240 if (((EMACS_INT) client_data) == 0)
|
|
241 return;
|
826
|
242 data = VOID_TO_LISP (client_data);
|
793
|
243 frame = wrap_frame (f);
|
428
|
244
|
|
245 #if 0
|
|
246 /* #### What the hell? I can't understand why this call is here,
|
|
247 and doing it is really courting disaster in the new event
|
|
248 model, since popup_selection_callback is called from
|
|
249 within next_event_internal() and Faccept_process_output()
|
|
250 itself calls next_event_internal(). --Ben */
|
|
251
|
|
252 /* Flush the X and process input */
|
|
253 Faccept_process_output (Qnil, Qnil, Qnil);
|
|
254 #endif
|
|
255
|
|
256 if (((EMACS_INT) client_data) == -1)
|
|
257 {
|
442
|
258 event = Fmake_event (Qnil, Qnil);
|
|
259
|
934
|
260 #ifdef USE_KKCC
|
|
261 XSET_EVENT_TYPE (event, misc_user_event);
|
|
262 XSET_EVENT_CHANNEL (event, frame);
|
|
263 XSET_MISC_USER_DATA_FUNCTION (XEVENT_DATA (event), Qrun_hooks);
|
|
264 XSET_MISC_USER_DATA_OBJECT (XEVENT_DATA (event), Qmenu_no_selection_hook);
|
|
265 #else /* not USE_KKCC */
|
442
|
266 XEVENT (event)->event_type = misc_user_event;
|
|
267 XEVENT (event)->channel = frame;
|
|
268 XEVENT (event)->event.eval.function = Qrun_hooks;
|
|
269 XEVENT (event)->event.eval.object = Qmenu_no_selection_hook;
|
934
|
270 #endif /* not USE_KKCC */
|
428
|
271 }
|
|
272 else
|
|
273 {
|
442
|
274 image_instance = XCAR (data);
|
|
275 callback = XCAR (XCDR (data));
|
|
276 callback_ex = XCDR (XCDR (data));
|
|
277 update_subwindows_p = 1;
|
|
278 /* It is possible for a widget action to cause it to get out of
|
|
279 sync with its instantiator. Thus it is necessary to signal
|
|
280 this possibility. */
|
|
281 if (IMAGE_INSTANCEP (image_instance))
|
|
282 XIMAGE_INSTANCE_WIDGET_ACTION_OCCURRED (image_instance) = 1;
|
|
283
|
|
284 if (!NILP (callback_ex) && !UNBOUNDP (callback_ex))
|
|
285 {
|
|
286 event = Fmake_event (Qnil, Qnil);
|
|
287
|
934
|
288 #ifdef USE_KKCC
|
|
289 XSET_EVENT_TYPE (event, misc_user_event);
|
|
290 XSET_EVENT_CHANNEL (event, frame);
|
|
291 XSET_MISC_USER_DATA_FUNCTION (XEVENT_DATA (event), Qeval);
|
|
292 XSET_MISC_USER_DATA_OBJECT (XEVENT_DATA (event), list4 (Qfuncall, callback_ex, image_instance, event));
|
|
293 #else /* not USE_KKCC */
|
442
|
294 XEVENT (event)->event_type = misc_user_event;
|
|
295 XEVENT (event)->channel = frame;
|
|
296 XEVENT (event)->event.eval.function = Qeval;
|
|
297 XEVENT (event)->event.eval.object =
|
|
298 list4 (Qfuncall, callback_ex, image_instance, event);
|
934
|
299 #endif /* not USE_KKCC */
|
442
|
300 }
|
|
301 else if (NILP (callback) || UNBOUNDP (callback))
|
|
302 event = Qnil;
|
|
303 else
|
|
304 {
|
|
305 Lisp_Object fn, arg;
|
|
306
|
|
307 event = Fmake_event (Qnil, Qnil);
|
|
308
|
|
309 get_gui_callback (callback, &fn, &arg);
|
934
|
310 #ifdef USE_KKCC
|
|
311 XSET_EVENT_TYPE (event, misc_user_event);
|
|
312 XSET_EVENT_CHANNEL (event, frame);
|
|
313 XSET_MISC_USER_DATA_FUNCTION (XEVENT_DATA (event), fn);
|
|
314 XSET_MISC_USER_DATA_OBJECT (XEVENT_DATA (event), arg);
|
|
315 #else /* not USE_KKCC */
|
442
|
316 XEVENT (event)->event_type = misc_user_event;
|
|
317 XEVENT (event)->channel = frame;
|
|
318 XEVENT (event)->event.eval.function = fn;
|
|
319 XEVENT (event)->event.eval.object = arg;
|
934
|
320 #endif /* not USE_KKCC */
|
442
|
321 }
|
428
|
322 }
|
|
323
|
|
324 /* This is the timestamp used for asserting focus so we need to get an
|
444
|
325 up-to-date value event if no events have been dispatched to emacs
|
428
|
326 */
|
872
|
327 #ifdef HAVE_MENUBARS
|
428
|
328 DEVICE_X_MOUSE_TIMESTAMP (d) = x_focus_timestamp_really_sucks_fix_me_better;
|
|
329 #else
|
|
330 DEVICE_X_MOUSE_TIMESTAMP (d) = DEVICE_X_GLOBAL_MOUSE_TIMESTAMP (d);
|
|
331 #endif
|
442
|
332 if (!NILP (event))
|
|
333 enqueue_Xt_dispatch_event (event);
|
|
334 /* The result of this evaluation could cause other instances to change so
|
|
335 enqueue an update callback to check this. */
|
|
336 if (update_subwindows_p && !NILP (event))
|
|
337 enqueue_magic_eval_event (update_widget_instances, frame);
|
428
|
338 }
|
|
339
|
|
340 #if 1
|
|
341 /* Eval the activep slot of the menu item */
|
|
342 # define wv_set_evalable_slot(slot,form) do { \
|
|
343 Lisp_Object wses_form = (form); \
|
|
344 (slot) = (NILP (wses_form) ? 0 : \
|
|
345 EQ (wses_form, Qt) ? 1 : \
|
|
346 !NILP (Feval (wses_form))); \
|
|
347 } while (0)
|
|
348 #else
|
|
349 /* Treat the activep slot of the menu item as a boolean */
|
|
350 # define wv_set_evalable_slot(slot,form) \
|
|
351 ((void) (slot = (!NILP (form))))
|
|
352 #endif
|
|
353
|
442
|
354 Extbyte *
|
867
|
355 menu_separator_style_and_to_external (const Ibyte *s)
|
428
|
356 {
|
867
|
357 const Ibyte *p;
|
|
358 Ibyte first;
|
428
|
359
|
|
360 if (!s || s[0] == '\0')
|
|
361 return NULL;
|
|
362 first = s[0];
|
|
363 if (first != '-' && first != '=')
|
|
364 return NULL;
|
|
365 for (p = s; *p == first; p++)
|
|
366 DO_NOTHING;
|
|
367
|
|
368 /* #### - cannot currently specify a separator tag "--!tag" and a
|
|
369 separator style "--:style" at the same time. */
|
|
370 /* #### - Also, the motif menubar code doesn't deal with the
|
|
371 double etched style yet, so it's not good to get into the habit of
|
|
372 using "===" in menubars to get double-etched lines */
|
|
373 if (*p == '!' || *p == '\0')
|
|
374 return ((first == '-')
|
|
375 ? NULL /* single etched is the default */
|
|
376 : xstrdup ("shadowDoubleEtchedIn"));
|
|
377 else if (*p == ':')
|
442
|
378 {
|
|
379 Extbyte *retval;
|
|
380
|
|
381 C_STRING_TO_EXTERNAL_MALLOC (p + 1, retval, Qlwlib_encoding);
|
|
382 return retval;
|
|
383 }
|
428
|
384
|
|
385 return NULL;
|
|
386 }
|
|
387
|
442
|
388 Extbyte *
|
|
389 add_accel_and_to_external (Lisp_Object string)
|
|
390 {
|
|
391 int i;
|
|
392 int found_accel = 0;
|
|
393 Extbyte *retval;
|
867
|
394 Ibyte *name = XSTRING_DATA (string);
|
442
|
395
|
|
396 for (i = 0; name[i]; ++i)
|
|
397 if (name[i] == '%' && name[i+1] == '_')
|
|
398 {
|
|
399 found_accel = 1;
|
|
400 break;
|
|
401 }
|
|
402
|
|
403 if (found_accel)
|
|
404 LISP_STRING_TO_EXTERNAL_MALLOC (string, retval, Qlwlib_encoding);
|
|
405 else
|
|
406 {
|
647
|
407 Bytecount namelen = XSTRING_LENGTH (string);
|
867
|
408 Ibyte *chars = (Ibyte *) ALLOCA (namelen + 3);
|
442
|
409 chars[0] = '%';
|
|
410 chars[1] = '_';
|
|
411 memcpy (chars + 2, name, namelen + 1);
|
|
412 C_STRING_TO_EXTERNAL_MALLOC (chars, retval, Qlwlib_encoding);
|
|
413 }
|
|
414
|
|
415 return retval;
|
|
416 }
|
428
|
417
|
853
|
418 /* This does the dirty work. GC is inhibited when this is called.
|
|
419 */
|
428
|
420 int
|
442
|
421 button_item_to_widget_value (Lisp_Object gui_object_instance,
|
|
422 Lisp_Object gui_item, widget_value *wv,
|
|
423 int allow_text_field_p, int no_keys_p,
|
|
424 int menu_entry_p, int accel_p)
|
428
|
425 {
|
853
|
426 /* This function cannot GC because GC is inhibited when it's called */
|
440
|
427 Lisp_Gui_Item* pgui = 0;
|
428
|
428
|
|
429 /* degenerate case */
|
|
430 if (STRINGP (gui_item))
|
|
431 {
|
|
432 wv->type = TEXT_TYPE;
|
442
|
433 if (accel_p)
|
|
434 wv->name = add_accel_and_to_external (gui_item);
|
|
435 else
|
|
436 LISP_STRING_TO_EXTERNAL_MALLOC (gui_item, wv->name, Qlwlib_encoding);
|
428
|
437 return 1;
|
|
438 }
|
|
439 else if (!GUI_ITEMP (gui_item))
|
563
|
440 invalid_argument ("need a string or a gui_item here", gui_item);
|
428
|
441
|
|
442 pgui = XGUI_ITEM (gui_item);
|
|
443
|
|
444 if (!NILP (pgui->filter))
|
563
|
445 sferror (":filter keyword not permitted on leaf nodes", gui_item);
|
428
|
446
|
|
447 #ifdef HAVE_MENUBARS
|
442
|
448 if (menu_entry_p && !gui_item_included_p (gui_item, Vmenubar_configuration))
|
428
|
449 {
|
|
450 /* the include specification says to ignore this item. */
|
|
451 return 0;
|
|
452 }
|
|
453 #endif /* HAVE_MENUBARS */
|
|
454
|
442
|
455 if (!STRINGP (pgui->name))
|
|
456 pgui->name = Feval (pgui->name);
|
|
457
|
428
|
458 CHECK_STRING (pgui->name);
|
442
|
459 if (accel_p)
|
|
460 {
|
|
461 wv->name = add_accel_and_to_external (pgui->name);
|
|
462 wv->accel = LISP_TO_VOID (gui_item_accelerator (gui_item));
|
|
463 }
|
|
464 else
|
|
465 {
|
|
466 LISP_STRING_TO_EXTERNAL_MALLOC (pgui->name, wv->name, Qlwlib_encoding);
|
|
467 wv->accel = LISP_TO_VOID (Qnil);
|
|
468 }
|
428
|
469
|
|
470 if (!NILP (pgui->suffix))
|
|
471 {
|
|
472 Lisp_Object suffix2;
|
|
473
|
|
474 /* Shortcut to avoid evaluating suffix each time */
|
|
475 if (STRINGP (pgui->suffix))
|
|
476 suffix2 = pgui->suffix;
|
|
477 else
|
|
478 {
|
|
479 suffix2 = Feval (pgui->suffix);
|
|
480 CHECK_STRING (suffix2);
|
|
481 }
|
|
482
|
442
|
483 LISP_STRING_TO_EXTERNAL_MALLOC (suffix2, wv->value, Qlwlib_encoding);
|
428
|
484 }
|
|
485
|
|
486 wv_set_evalable_slot (wv->enabled, pgui->active);
|
|
487 wv_set_evalable_slot (wv->selected, pgui->selected);
|
|
488
|
442
|
489 if (!NILP (pgui->callback) || !NILP (pgui->callback_ex))
|
|
490 wv->call_data = LISP_TO_VOID (cons3 (gui_object_instance,
|
|
491 pgui->callback,
|
|
492 pgui->callback_ex));
|
428
|
493
|
|
494 if (no_keys_p
|
|
495 #ifdef HAVE_MENUBARS
|
442
|
496 || (menu_entry_p && !menubar_show_keybindings)
|
428
|
497 #endif
|
|
498 )
|
|
499 wv->key = 0;
|
|
500 else if (!NILP (pgui->keys)) /* Use this string to generate key bindings */
|
|
501 {
|
|
502 CHECK_STRING (pgui->keys);
|
|
503 pgui->keys = Fsubstitute_command_keys (pgui->keys);
|
|
504 if (XSTRING_LENGTH (pgui->keys) > 0)
|
442
|
505 LISP_STRING_TO_EXTERNAL_MALLOC (pgui->keys, wv->key, Qlwlib_encoding);
|
428
|
506 else
|
|
507 wv->key = 0;
|
|
508 }
|
|
509 else if (SYMBOLP (pgui->callback)) /* Show the binding of this command. */
|
|
510 {
|
793
|
511 DECLARE_EISTRING_MALLOC (buf);
|
428
|
512 /* #### Warning, dependency here on current_buffer and point */
|
|
513 where_is_to_char (pgui->callback, buf);
|
793
|
514 if (eilen (buf) > 0)
|
|
515 C_STRING_TO_EXTERNAL_MALLOC (eidata (buf), wv->key, Qlwlib_encoding);
|
428
|
516 else
|
|
517 wv->key = 0;
|
793
|
518 eifree (buf);
|
428
|
519 }
|
|
520
|
|
521 CHECK_SYMBOL (pgui->style);
|
|
522 if (NILP (pgui->style))
|
|
523 {
|
867
|
524 Ibyte *intname;
|
444
|
525 Bytecount intlen;
|
428
|
526 /* If the callback is nil, treat this item like unselectable text.
|
|
527 This way, dashes will show up as a separator. */
|
|
528 if (!wv->enabled)
|
|
529 wv->type = BUTTON_TYPE;
|
444
|
530 TO_INTERNAL_FORMAT (C_STRING, wv->name,
|
|
531 ALLOCA, (intname, intlen),
|
|
532 Qlwlib_encoding);
|
442
|
533 if (separator_string_p (intname))
|
428
|
534 {
|
|
535 wv->type = SEPARATOR_TYPE;
|
442
|
536 wv->value = menu_separator_style_and_to_external (intname);
|
428
|
537 }
|
|
538 else
|
|
539 {
|
|
540 #if 0
|
|
541 /* #### - this is generally desirable for menubars, but it breaks
|
|
542 a package that uses dialog boxes and next_command_event magic
|
|
543 to use the callback slot in dialog buttons for data instead of
|
|
544 a real callback.
|
|
545
|
|
546 Code is data, right? The beauty of LISP abuse. --Stig */
|
|
547 if (NILP (callback))
|
|
548 wv->type = TEXT_TYPE;
|
|
549 else
|
|
550 #endif
|
|
551 wv->type = BUTTON_TYPE;
|
|
552 }
|
|
553 }
|
|
554 else if (EQ (pgui->style, Qbutton))
|
|
555 wv->type = BUTTON_TYPE;
|
|
556 else if (EQ (pgui->style, Qtoggle))
|
|
557 wv->type = TOGGLE_TYPE;
|
|
558 else if (EQ (pgui->style, Qradio))
|
|
559 wv->type = RADIO_TYPE;
|
|
560 else if (EQ (pgui->style, Qtext))
|
|
561 {
|
|
562 wv->type = TEXT_TYPE;
|
|
563 #if 0
|
|
564 wv->value = wv->name;
|
|
565 wv->name = "value";
|
|
566 #endif
|
|
567 }
|
|
568 else
|
563
|
569 invalid_constant_2 ("Unknown style", pgui->style, gui_item);
|
428
|
570
|
|
571 if (!allow_text_field_p && (wv->type == TEXT_TYPE))
|
563
|
572 sferror ("Text field not allowed in this context", gui_item);
|
428
|
573
|
|
574 if (!NILP (pgui->selected) && EQ (pgui->style, Qtext))
|
563
|
575 sferror
|
442
|
576 (":selected only makes sense with :style toggle, radio or button",
|
|
577 gui_item);
|
428
|
578 return 1;
|
|
579 }
|
|
580
|
|
581 /* parse tree's of gui items into widget_value hierarchies */
|
442
|
582 static void gui_item_children_to_widget_values (Lisp_Object
|
|
583 gui_object_instance,
|
|
584 Lisp_Object items,
|
|
585 widget_value* parent,
|
|
586 int accel_p);
|
428
|
587
|
|
588 static widget_value *
|
442
|
589 gui_items_to_widget_values_1 (Lisp_Object gui_object_instance,
|
|
590 Lisp_Object items, widget_value* parent,
|
|
591 widget_value* prev, int accel_p)
|
428
|
592 {
|
|
593 widget_value* wv = 0;
|
|
594
|
|
595 assert ((parent || prev) && !(parent && prev));
|
|
596 /* now walk the tree creating widget_values as appropriate */
|
|
597 if (!CONSP (items))
|
|
598 {
|
442
|
599 wv = xmalloc_widget_value ();
|
428
|
600 if (parent)
|
|
601 parent->contents = wv;
|
440
|
602 else
|
428
|
603 prev->next = wv;
|
442
|
604 if (!button_item_to_widget_value (gui_object_instance,
|
|
605 items, wv, 0, 1, 0, accel_p))
|
428
|
606 {
|
436
|
607 free_widget_value_tree (wv);
|
428
|
608 if (parent)
|
|
609 parent->contents = 0;
|
440
|
610 else
|
428
|
611 prev->next = 0;
|
|
612 }
|
440
|
613 else
|
442
|
614 wv->value = xstrdup (wv->name); /* what a mess... */
|
428
|
615 }
|
|
616 else
|
|
617 {
|
|
618 /* first one is the parent */
|
|
619 if (CONSP (XCAR (items)))
|
563
|
620 sferror ("parent item must not be a list", XCAR (items));
|
428
|
621
|
|
622 if (parent)
|
442
|
623 wv = gui_items_to_widget_values_1 (gui_object_instance,
|
|
624 XCAR (items), parent, 0, accel_p);
|
428
|
625 else
|
442
|
626 wv = gui_items_to_widget_values_1 (gui_object_instance,
|
|
627 XCAR (items), 0, prev, accel_p);
|
428
|
628 /* the rest are the children */
|
442
|
629 gui_item_children_to_widget_values (gui_object_instance,
|
|
630 XCDR (items), wv, accel_p);
|
428
|
631 }
|
|
632 return wv;
|
|
633 }
|
|
634
|
|
635 static void
|
442
|
636 gui_item_children_to_widget_values (Lisp_Object gui_object_instance,
|
|
637 Lisp_Object items, widget_value* parent,
|
|
638 int accel_p)
|
428
|
639 {
|
|
640 widget_value* wv = 0, *prev = 0;
|
|
641 Lisp_Object rest;
|
|
642 CHECK_CONS (items);
|
|
643
|
|
644 /* first one is master */
|
442
|
645 prev = gui_items_to_widget_values_1 (gui_object_instance, XCAR (items),
|
|
646 parent, 0, accel_p);
|
428
|
647 /* the rest are the children */
|
|
648 LIST_LOOP (rest, XCDR (items))
|
|
649 {
|
|
650 Lisp_Object tab = XCAR (rest);
|
442
|
651 wv = gui_items_to_widget_values_1 (gui_object_instance, tab, 0, prev,
|
|
652 accel_p);
|
428
|
653 prev = wv;
|
|
654 }
|
|
655 }
|
|
656
|
|
657 widget_value *
|
442
|
658 gui_items_to_widget_values (Lisp_Object gui_object_instance, Lisp_Object items,
|
|
659 int accel_p)
|
428
|
660 {
|
|
661 /* This function can GC */
|
|
662 widget_value *control = 0, *tmp = 0;
|
771
|
663 int count;
|
428
|
664 Lisp_Object wv_closure;
|
|
665
|
|
666 if (NILP (items))
|
563
|
667 sferror ("must have some items", items);
|
428
|
668
|
|
669 /* Inhibit GC during this conversion. The reasons for this are
|
|
670 the same as in menu_item_descriptor_to_widget_value(); see
|
|
671 the large comment above that function. */
|
771
|
672 count = begin_gc_forbidden ();
|
428
|
673
|
|
674 /* Also make sure that we free the partially-created widget_value
|
|
675 tree on Lisp error. */
|
442
|
676 control = xmalloc_widget_value ();
|
428
|
677 wv_closure = make_opaque_ptr (control);
|
|
678 record_unwind_protect (widget_value_unwind, wv_closure);
|
|
679
|
442
|
680 gui_items_to_widget_values_1 (gui_object_instance, items, control, 0,
|
|
681 accel_p);
|
428
|
682
|
|
683 /* mess about getting the data we really want */
|
|
684 tmp = control;
|
|
685 control = control->contents;
|
|
686 tmp->next = 0;
|
|
687 tmp->contents = 0;
|
436
|
688 free_widget_value_tree (tmp);
|
428
|
689
|
|
690 /* No more need to free the half-filled-in structures. */
|
|
691 set_opaque_ptr (wv_closure, 0);
|
771
|
692 unbind_to (count);
|
428
|
693
|
|
694 return control;
|
|
695 }
|
|
696
|
|
697 void
|
|
698 syms_of_gui_x (void)
|
|
699 {
|
442
|
700 INIT_LRECORD_IMPLEMENTATION (popup_data);
|
428
|
701 }
|
|
702
|
|
703 void
|
|
704 reinit_vars_of_gui_x (void)
|
|
705 {
|
|
706 lwlib_id_tick = (1<<16); /* start big, to not conflict with Energize */
|
|
707 #ifdef HAVE_POPUPS
|
|
708 popup_up_p = 0;
|
|
709 #endif
|
|
710 }
|
|
711
|
|
712 void
|
|
713 vars_of_gui_x (void)
|
|
714 {
|
|
715 reinit_vars_of_gui_x ();
|
|
716
|
|
717 Vpopup_callbacks = Qnil;
|
|
718 staticpro (&Vpopup_callbacks);
|
|
719 }
|