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