0
|
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.
|
259
|
5 Copyright (C) 1998 Free Software Foundation, Inc.
|
0
|
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
|
|
26 #include <config.h>
|
251
|
27 #include "lisp.h"
|
231
|
28 #include "gui.h"
|
0
|
29
|
|
30 Lisp_Object Q_active, Q_suffix, Q_keys, Q_style, Q_selected;
|
|
31 Lisp_Object Q_filter, Q_config, Q_included;
|
175
|
32 Lisp_Object Q_accelerator;
|
0
|
33 Lisp_Object Qtoggle, Qradio;
|
|
34
|
231
|
35 #ifdef HAVE_POPUPS
|
|
36
|
|
37 /* count of menus/dboxes currently up */
|
|
38 int popup_up_p;
|
|
39
|
|
40 DEFUN ("popup-up-p", Fpopup_up_p, 0, 0, 0, /*
|
|
41 Return t if a popup menu or dialog box is up, nil otherwise.
|
|
42 See `popup-menu' and `popup-dialog-box'.
|
|
43 */
|
|
44 ())
|
|
45 {
|
|
46 return popup_up_p ? Qt : Qnil;
|
|
47 }
|
|
48
|
|
49 int
|
|
50 separator_string_p (CONST char *s)
|
|
51 {
|
|
52 CONST char *p;
|
|
53 char first;
|
|
54
|
|
55 if (!s || s[0] == '\0')
|
|
56 return 0;
|
|
57 first = s[0];
|
|
58 if (first != '-' && first != '=')
|
|
59 return 0;
|
|
60 for (p = s; *p == first; p++);
|
|
61
|
|
62 if (*p == '!' || *p == ':' || *p == '\0')
|
|
63 return 1;
|
|
64 return 0;
|
|
65 }
|
|
66
|
251
|
67 /*
|
|
68 * Initialize the gui_item structure by setting all (GC-protected)
|
|
69 * fields to their default values. The defaults are t for :active and
|
|
70 * :included values, and nil for others.
|
|
71 */
|
|
72 void
|
|
73 gui_item_init (struct gui_item *pgui_item)
|
|
74 {
|
|
75 pgui_item->name = Qnil;
|
|
76 pgui_item->callback = Qnil;
|
|
77 pgui_item->suffix = Qnil;
|
|
78 pgui_item->active = Qt;
|
|
79 pgui_item->included = Qt;
|
|
80 pgui_item->config = Qunbound;
|
|
81 pgui_item->filter = Qnil;
|
|
82 pgui_item->style = Qnil;
|
|
83 pgui_item->selected = Qnil;
|
|
84 pgui_item->keys = Qnil;
|
|
85 }
|
|
86
|
|
87 /*
|
|
88 * Add a value VAL associated with keyword KEY into PGUI_ITEM
|
|
89 * structure. If KEY is not a keyword, or is an unknown keyword, then
|
|
90 * error is signaled.
|
|
91 */
|
|
92 void
|
|
93 gui_item_add_keyval_pair (struct gui_item *pgui_item,
|
|
94 Lisp_Object key, Lisp_Object val)
|
|
95 {
|
|
96 if (!KEYWORDP (key))
|
|
97 error ("Not a keyword %S in gui item %S", key, pgui_item->name);
|
|
98
|
|
99 if (EQ (key, Q_suffix))
|
|
100 pgui_item->suffix = val;
|
|
101 else if (EQ (key, Q_active))
|
|
102 pgui_item->active = val;
|
|
103 else if (EQ (key, Q_included))
|
|
104 pgui_item->included = val;
|
|
105 else if (EQ (key, Q_config))
|
|
106 pgui_item->config = val;
|
|
107 else if (EQ (key, Q_filter))
|
|
108 pgui_item->filter = val;
|
|
109 else if (EQ (key, Q_style))
|
|
110 pgui_item->style = val;
|
|
111 else if (EQ (key, Q_selected))
|
|
112 pgui_item->selected = val;
|
|
113 else if (EQ (key, Q_keys))
|
|
114 pgui_item->keys = val;
|
|
115 else
|
|
116 error ("Unknown keyword %S in gui item %S", key, pgui_item->name);
|
|
117 }
|
|
118
|
|
119 /*
|
|
120 * ITEM is a lisp vector, describing a menu item or a button. The
|
|
121 * function extracts the description of the item into the PGUI_ITEM
|
|
122 * structure.
|
|
123 */
|
|
124 void
|
|
125 gui_parse_item_keywords (Lisp_Object item, struct gui_item *pgui_item)
|
|
126 {
|
|
127 int length, plist_p;
|
|
128 Lisp_Object *contents;
|
|
129
|
|
130 CHECK_VECTOR (item);
|
|
131 length = XVECTOR_LENGTH (item);
|
|
132 contents = XVECTOR_DATA (item);
|
|
133
|
259
|
134 if (length < 2)
|
|
135 signal_simple_error ("GUI item descriptors must be at least 2 elts long", item);
|
251
|
136
|
259
|
137 /* length 2: [ "name" callback ]
|
|
138 length 3: [ "name" callback active-p ]
|
251
|
139 length 4: [ "name" callback active-p suffix ]
|
|
140 or [ "name" callback keyword value ]
|
|
141 length 5+: [ "name" callback [ keyword value ]+ ]
|
|
142 */
|
259
|
143 plist_p = (length >= 5 || (length > 2 && KEYWORDP (contents [2])));
|
251
|
144
|
|
145 pgui_item->name = contents [0];
|
|
146 pgui_item->callback = contents [1];
|
|
147
|
259
|
148 if (!plist_p && length > 2)
|
251
|
149 /* the old way */
|
|
150 {
|
|
151 pgui_item->active = contents [2];
|
|
152 if (length == 4)
|
|
153 pgui_item->suffix = contents [3];
|
|
154 }
|
|
155 else
|
|
156 /* the new way */
|
|
157 {
|
|
158 int i;
|
|
159 if (length & 1)
|
|
160 signal_simple_error (
|
|
161 "GUI item descriptor has an odd number of keywords and values",
|
|
162 item);
|
|
163
|
|
164 for (i = 2; i < length;)
|
|
165 {
|
|
166 Lisp_Object key = contents [i++];
|
|
167 Lisp_Object val = contents [i++];
|
|
168 gui_item_add_keyval_pair (pgui_item, key, val);
|
|
169 }
|
|
170 }
|
|
171 }
|
|
172
|
|
173 /*
|
|
174 * Decide whether a GUI item is active by evaluating its :active form
|
|
175 * if any
|
|
176 */
|
|
177 int
|
|
178 gui_item_active_p (CONST struct gui_item *pgui_item)
|
|
179 {
|
|
180 /* This function can call lisp */
|
|
181
|
|
182 /* Shortcut to avoid evaluating Qt each time */
|
|
183 return (EQ (pgui_item->active, Qt)
|
|
184 || !NILP (Feval (pgui_item->active)));
|
|
185 }
|
|
186
|
|
187 /*
|
|
188 * Decide whether a GUI item is included by evaluating its :included
|
|
189 * form if given, and testing its :config form against supplied CONFLIST
|
|
190 * configuration variable
|
|
191 */
|
|
192 int
|
|
193 gui_item_included_p (CONST struct gui_item *pgui_item, Lisp_Object conflist)
|
|
194 {
|
|
195 /* This function can call lisp */
|
|
196
|
|
197 /* Evaluate :included first. Shortcut to avoid evaluating Qt each time */
|
|
198 if (!EQ (pgui_item->included, Qt)
|
|
199 && NILP (Feval (pgui_item->included)))
|
|
200 return 0;
|
|
201
|
|
202 /* Do :config if conflist is given */
|
|
203 if (!NILP (conflist) && !NILP (pgui_item->config)
|
|
204 && NILP (Fmemq (pgui_item->config, conflist)))
|
|
205 return 0;
|
|
206
|
|
207 return 1;
|
|
208 }
|
|
209
|
|
210 static DOESNT_RETURN
|
|
211 signal_too_long_error (Lisp_Object name)
|
|
212 {
|
|
213 error ("GUI item %s produces too long displayable string", name);
|
|
214 }
|
|
215
|
|
216 /*
|
|
217 * Format "left flush" display portion of an item into BUF, guarded by
|
|
218 * maximum buffer size BUF_LEN. BUF_LEN does not count for terminating
|
|
219 * null character, so actual maximum size of buffer consumed is
|
|
220 * BUF_LEN + 1 bytes. If buffer is not big enough, then error is
|
|
221 * signaled.
|
|
222 * Return value is the offset to the terminating null character into the
|
|
223 * buffer.
|
|
224 */
|
|
225 unsigned int
|
|
226 gui_item_display_flush_left (CONST struct gui_item *pgui_item,
|
|
227 char* buf, unsigned int buf_len)
|
|
228 {
|
|
229 unsigned int consumed;
|
|
230
|
|
231 /* Copy item name first */
|
|
232 CHECK_STRING (pgui_item->name);
|
|
233 if (XSTRING_LENGTH (pgui_item->name) > buf_len)
|
|
234 signal_too_long_error (pgui_item->name);
|
|
235 strcpy (buf, XSTRING_DATA (pgui_item->name));
|
|
236 buf += (consumed = XSTRING_LENGTH (pgui_item->name));
|
|
237 buf_len -= consumed;
|
|
238
|
259
|
239 /* Add space and suffix, if there is a suffix.
|
|
240 * If suffix is not string evaluate it */
|
251
|
241 if (!NILP (pgui_item->suffix))
|
|
242 {
|
259
|
243 Lisp_Object suffix2;
|
|
244
|
|
245 /* Shortcut to avoid evaluating suffix each time */
|
|
246 if (STRINGP (pgui_item->suffix))
|
|
247 suffix2 = pgui_item->suffix;
|
|
248 else
|
|
249 {
|
|
250 suffix2 = Feval (pgui_item->suffix);
|
|
251 CHECK_STRING (suffix2);
|
|
252 }
|
|
253
|
|
254 if (XSTRING_LENGTH (suffix2) + 1 > buf_len)
|
251
|
255 signal_too_long_error (pgui_item->name);
|
|
256 *(buf++) = ' ';
|
259
|
257 strcpy (buf, XSTRING_DATA (suffix2));
|
|
258 consumed += XSTRING_LENGTH (suffix2) + 1;
|
251
|
259 }
|
|
260
|
|
261 return consumed;
|
|
262 }
|
|
263
|
|
264 /*
|
|
265 * Format "right flush" display portion of an item into BUF, guarded by
|
|
266 * maximum buffer size BUF_LEN. BUF_LEN does not count for terminating
|
|
267 * null character, so actual maximum size of buffer consumed is
|
|
268 * BUF_LEN + 1 bytes. If buffer is not big enough, then error is
|
|
269 * signaled.
|
|
270 * Return value is the offset to the terminating null character into the
|
|
271 * buffer.
|
|
272 */
|
|
273 unsigned int
|
|
274 gui_item_display_flush_right (CONST struct gui_item *pgui_item,
|
|
275 char* buf, unsigned int buf_len)
|
|
276 {
|
|
277 *buf = 0;
|
|
278
|
|
279 /* Have keys? */
|
|
280 if (!menubar_show_keybindings)
|
|
281 return 0;
|
|
282
|
|
283 /* Try :keys first */
|
|
284 if (!NILP (pgui_item->keys))
|
|
285 {
|
|
286 CHECK_STRING (pgui_item->keys);
|
|
287 if (XSTRING_LENGTH (pgui_item->keys) > buf_len)
|
|
288 signal_too_long_error (pgui_item->name);
|
|
289 strcpy (buf, XSTRING_DATA (pgui_item->keys));
|
|
290 return XSTRING_LENGTH (pgui_item->keys);
|
|
291 }
|
|
292
|
|
293 /* See if we can derive keys out of callback symbol */
|
|
294 if (SYMBOLP (pgui_item->callback))
|
|
295 {
|
|
296 char buf2 [1024];
|
|
297 unsigned int len;
|
|
298
|
|
299 where_is_to_char (pgui_item->callback, buf2);
|
|
300 len = strlen (buf2);
|
|
301 if (len > buf_len)
|
|
302 signal_too_long_error (pgui_item->name);
|
|
303 strcpy (buf, buf2);
|
|
304 return len;
|
|
305 }
|
|
306
|
|
307 /* No keys - no right flush display */
|
|
308 return 0;
|
|
309 }
|
|
310
|
231
|
311 #endif /* HAVE_POPUPS */
|
|
312
|
0
|
313 void
|
|
314 syms_of_gui (void)
|
|
315 {
|
|
316 defkeyword (&Q_active, ":active");
|
|
317 defkeyword (&Q_suffix, ":suffix");
|
|
318 defkeyword (&Q_keys, ":keys");
|
|
319 defkeyword (&Q_style, ":style");
|
|
320 defkeyword (&Q_selected, ":selected");
|
|
321 defkeyword (&Q_filter, ":filter");
|
|
322 defkeyword (&Q_config, ":config");
|
|
323 defkeyword (&Q_included, ":included");
|
175
|
324 defkeyword (&Q_accelerator, ":accelerator");
|
0
|
325
|
|
326 defsymbol (&Qtoggle, "toggle");
|
|
327 defsymbol (&Qradio, "radio");
|
231
|
328
|
|
329 #ifdef HAVE_POPUPS
|
|
330 DEFSUBR (Fpopup_up_p);
|
|
331 #endif
|
0
|
332 }
|
|
333
|
|
334 void
|
|
335 vars_of_gui (void)
|
|
336 {
|
|
337 }
|