1 /* Generic GUI code. (menubars, scrollbars, toolbars, dialogs)
2 Copyright (C) 1995 Board of Trustees, University of Illinois.
3 Copyright (C) 1995, 1996 Ben Wing.
4 Copyright (C) 1995 Sun Microsystems, Inc.
5 Copyright (C) 1998 Free Software Foundation, Inc.
7 This file is part of XEmacs.
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
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
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. */
24 /* Synched up with: Not in FSF. */
29 #include "bytecode.h" /* for struct Lisp_Compiled_Function */
31 Lisp_Object Q_active, Q_suffix, Q_keys, Q_style, Q_selected;
32 Lisp_Object Q_filter, Q_config, Q_included;
33 Lisp_Object Q_accelerator;
34 Lisp_Object Qtoggle, Qradio;
38 /* count of menus/dboxes currently up */
41 DEFUN ("popup-up-p", Fpopup_up_p, 0, 0, 0, /*
42 Return t if a popup menu or dialog box is up, nil otherwise.
43 See `popup-menu' and `popup-dialog-box'.
47 return popup_up_p ? Qt : Qnil;
51 separator_string_p (CONST char *s)
56 if (!s || s[0] == '\0')
59 if (first != '-' && first != '=')
61 for (p = s; *p == first; p++)
64 return (*p == '!' || *p == ':' || *p == '\0');
67 /* Massage DATA to find the correct function and argument. Used by
68 popup_selection_callback() and the msw code. */
70 get_gui_callback (Lisp_Object data, Lisp_Object *fn, Lisp_Object *arg)
73 || (COMPILED_FUNCTIONP (data)
74 && XCOMPILED_FUNCTION (data)->flags.interactivep)
75 || (EQ (XCAR (data), Qlambda)
76 && !NILP (Fassq (Qinteractive, Fcdr (Fcdr (data))))))
78 *fn = Qcall_interactively;
81 else if (CONSP (data))
89 *arg = list3 (Qsignal,
90 list2 (Qquote, Qerror),
91 list2 (Qquote, list2 (build_translated_string
98 * Initialize the gui_item structure by setting all (GC-protected)
99 * fields to their default values. The defaults are t for :active and
100 * :included values, and nil for others.
103 gui_item_init (struct gui_item *pgui_item)
105 pgui_item->name = Qnil;
106 pgui_item->callback = Qnil;
107 pgui_item->suffix = Qnil;
108 pgui_item->active = Qt;
109 pgui_item->included = Qt;
110 pgui_item->config = Qnil;
111 pgui_item->filter = Qnil;
112 pgui_item->style = Qnil;
113 pgui_item->selected = Qnil;
114 pgui_item->keys = Qnil;
118 * Add a value VAL associated with keyword KEY into PGUI_ITEM
119 * structure. If KEY is not a keyword, or is an unknown keyword, then
123 gui_item_add_keyval_pair (struct gui_item *pgui_item,
124 Lisp_Object key, Lisp_Object val)
127 signal_simple_error_2 ("Non-keyword in gui item", key, pgui_item->name);
129 if (EQ (key, Q_suffix)) pgui_item->suffix = val;
130 else if (EQ (key, Q_active)) pgui_item->active = val;
131 else if (EQ (key, Q_included)) pgui_item->included = val;
132 else if (EQ (key, Q_config)) pgui_item->config = val;
133 else if (EQ (key, Q_filter)) pgui_item->filter = val;
134 else if (EQ (key, Q_style)) pgui_item->style = val;
135 else if (EQ (key, Q_selected)) pgui_item->selected = val;
136 else if (EQ (key, Q_keys)) pgui_item->keys = val;
138 signal_simple_error_2 ("Unknown keyword in gui item", key, pgui_item->name);
142 * ITEM is a lisp vector, describing a menu item or a button. The
143 * function extracts the description of the item into the PGUI_ITEM
147 gui_parse_item_keywords (Lisp_Object item, struct gui_item *pgui_item)
150 Lisp_Object *contents;
153 length = XVECTOR_LENGTH (item);
154 contents = XVECTOR_DATA (item);
157 signal_simple_error ("GUI item descriptors must be at least 2 elts long", item);
159 /* length 2: [ "name" callback ]
160 length 3: [ "name" callback active-p ]
161 length 4: [ "name" callback active-p suffix ]
162 or [ "name" callback keyword value ]
163 length 5+: [ "name" callback [ keyword value ]+ ]
165 plist_p = (length >= 5 || (length > 2 && KEYWORDP (contents [2])));
167 pgui_item->name = contents [0];
168 pgui_item->callback = contents [1];
170 if (!plist_p && length > 2)
173 pgui_item->active = contents [2];
175 pgui_item->suffix = contents [3];
182 signal_simple_error (
183 "GUI item descriptor has an odd number of keywords and values",
186 for (i = 2; i < length;)
188 Lisp_Object key = contents [i++];
189 Lisp_Object val = contents [i++];
190 gui_item_add_keyval_pair (pgui_item, key, val);
196 * Decide whether a GUI item is active by evaluating its :active form
200 gui_item_active_p (CONST struct gui_item *pgui_item)
202 /* This function can call lisp */
204 /* Shortcut to avoid evaluating Qt each time */
205 return (EQ (pgui_item->active, Qt)
206 || !NILP (Feval (pgui_item->active)));
210 * Decide whether a GUI item is included by evaluating its :included
211 * form if given, and testing its :config form against supplied CONFLIST
212 * configuration variable
215 gui_item_included_p (CONST struct gui_item *pgui_item, Lisp_Object conflist)
217 /* This function can call lisp */
219 /* Evaluate :included first. Shortcut to avoid evaluating Qt each time */
220 if (!EQ (pgui_item->included, Qt)
221 && NILP (Feval (pgui_item->included)))
224 /* Do :config if conflist is given */
225 if (!NILP (conflist) && !NILP (pgui_item->config)
226 && NILP (Fmemq (pgui_item->config, conflist)))
233 signal_too_long_error (Lisp_Object name)
235 signal_simple_error ("GUI item produces too long displayable string", name);
239 * Format "left flush" display portion of an item into BUF, guarded by
240 * maximum buffer size BUF_LEN. BUF_LEN does not count for terminating
241 * null character, so actual maximum size of buffer consumed is
242 * BUF_LEN + 1 bytes. If buffer is not big enough, then error is
244 * Return value is the offset to the terminating null character into the
248 gui_item_display_flush_left (CONST struct gui_item *pgui_item,
249 char* buf, Bytecount buf_len)
254 /* Copy item name first */
255 CHECK_STRING (pgui_item->name);
256 len = XSTRING_LENGTH (pgui_item->name);
258 signal_too_long_error (pgui_item->name);
259 memcpy (p, XSTRING_DATA (pgui_item->name), len);
262 /* Add space and suffix, if there is a suffix.
263 * If suffix is not string evaluate it */
264 if (!NILP (pgui_item->suffix))
266 Lisp_Object suffix = pgui_item->suffix;
267 /* Shortcut to avoid evaluating suffix each time */
268 if (!STRINGP (suffix))
270 suffix = Feval (suffix);
271 CHECK_STRING (suffix);
274 len = XSTRING_LENGTH (suffix);
275 if (p + len + 1 > buf + buf_len)
276 signal_too_long_error (pgui_item->name);
278 memcpy (p, XSTRING_DATA (suffix), len);
286 * Format "right flush" display portion of an item into BUF, guarded by
287 * maximum buffer size BUF_LEN. BUF_LEN does not count for terminating
288 * null character, so actual maximum size of buffer consumed is
289 * BUF_LEN + 1 bytes. If buffer is not big enough, then error is
291 * Return value is the offset to the terminating null character into the
295 gui_item_display_flush_right (CONST struct gui_item *pgui_item,
296 char* buf, Bytecount buf_len)
301 if (!menubar_show_keybindings)
304 /* Try :keys first */
305 if (!NILP (pgui_item->keys))
307 CHECK_STRING (pgui_item->keys);
308 if (XSTRING_LENGTH (pgui_item->keys) > buf_len)
309 signal_too_long_error (pgui_item->name);
310 strcpy (buf, (CONST char *) XSTRING_DATA (pgui_item->keys));
311 return XSTRING_LENGTH (pgui_item->keys);
314 /* See if we can derive keys out of callback symbol */
315 if (SYMBOLP (pgui_item->callback))
320 where_is_to_char (pgui_item->callback, buf2);
323 signal_too_long_error (pgui_item->name);
328 /* No keys - no right flush display */
332 #endif /* HAVE_POPUPS */
337 defkeyword (&Q_active, ":active");
338 defkeyword (&Q_suffix, ":suffix");
339 defkeyword (&Q_keys, ":keys");
340 defkeyword (&Q_style, ":style");
341 defkeyword (&Q_selected, ":selected");
342 defkeyword (&Q_filter, ":filter");
343 defkeyword (&Q_config, ":config");
344 defkeyword (&Q_included, ":included");
345 defkeyword (&Q_accelerator, ":accelerator");
347 defsymbol (&Qtoggle, "toggle");
348 defsymbol (&Qradio, "radio");
351 DEFSUBR (Fpopup_up_p);