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