comparison src/gui.c @ 384:bbff43aa5eb7 r21-2-7

Import from CVS: tag r21-2-7
author cvs
date Mon, 13 Aug 2007 11:08:24 +0200
parents 8626e4521993
children aabb7f5b1c81
comparison
equal deleted inserted replaced
383:6a50c6a581a5 384:bbff43aa5eb7
24 /* Synched up with: Not in FSF. */ 24 /* Synched up with: Not in FSF. */
25 25
26 #include <config.h> 26 #include <config.h>
27 #include "lisp.h" 27 #include "lisp.h"
28 #include "gui.h" 28 #include "gui.h"
29 #include "elhash.h"
29 #include "bytecode.h" 30 #include "bytecode.h"
30 31
31 Lisp_Object Q_active, Q_suffix, Q_keys, Q_style, Q_selected; 32 Lisp_Object Q_active, Q_suffix, Q_keys, Q_style, Q_selected;
32 Lisp_Object Q_filter, Q_config, Q_included, Q_key_sequence; 33 Lisp_Object Q_filter, Q_config, Q_included, Q_key_sequence;
33 Lisp_Object Q_accelerator, Q_label; 34 Lisp_Object Q_accelerator, Q_label;
44 */ 45 */
45 ()) 46 ())
46 { 47 {
47 return popup_up_p ? Qt : Qnil; 48 return popup_up_p ? Qt : Qnil;
48 } 49 }
50 #endif /* HAVE_POPUPS */
49 51
50 int 52 int
51 separator_string_p (CONST char *s) 53 separator_string_p (CONST char *s)
52 { 54 {
53 CONST char *p; 55 CONST char *p;
146 * structure. 148 * structure.
147 */ 149 */
148 void 150 void
149 gui_parse_item_keywords (Lisp_Object item, struct gui_item *pgui_item) 151 gui_parse_item_keywords (Lisp_Object item, struct gui_item *pgui_item)
150 { 152 {
151 int length, plist_p; 153 int length, plist_p, start;
152 Lisp_Object *contents; 154 Lisp_Object *contents;
153 155
154 CHECK_VECTOR (item); 156 CHECK_VECTOR (item);
155 length = XVECTOR_LENGTH (item); 157 length = XVECTOR_LENGTH (item);
156 contents = XVECTOR_DATA (item); 158 contents = XVECTOR_DATA (item);
157 159
158 if (length < 2) 160 if (length < 1)
159 signal_simple_error ("GUI item descriptors must be at least 2 elts long", item); 161 signal_simple_error ("GUI item descriptors must be at least 1 elts long", item);
160 162
161 /* length 2: [ "name" callback ] 163 /* length 1: [ "name" ]
164 length 2: [ "name" callback ]
162 length 3: [ "name" callback active-p ] 165 length 3: [ "name" callback active-p ]
166 or [ "name" keyword value ]
163 length 4: [ "name" callback active-p suffix ] 167 length 4: [ "name" callback active-p suffix ]
164 or [ "name" callback keyword value ] 168 or [ "name" callback keyword value ]
165 length 5+: [ "name" callback [ keyword value ]+ ] 169 length 5+: [ "name" callback [ keyword value ]+ ]
170 or [ "name" [ keyword value ]+ ]
166 */ 171 */
167 plist_p = (length >= 5 || (length > 2 && KEYWORDP (contents [2]))); 172 plist_p = (length > 2 && (KEYWORDP (contents [1])
173 || KEYWORDP (contents [2])));
168 174
169 pgui_item->name = contents [0]; 175 pgui_item->name = contents [0];
170 pgui_item->callback = contents [1]; 176 if (length > 1 && !KEYWORDP (contents [1]))
177 {
178 pgui_item->callback = contents [1];
179 start = 2;
180 }
181 else
182 start =1;
171 183
172 if (!plist_p && length > 2) 184 if (!plist_p && length > 2)
173 /* the old way */ 185 /* the old way */
174 { 186 {
175 pgui_item->active = contents [2]; 187 pgui_item->active = contents [2];
178 } 190 }
179 else 191 else
180 /* the new way */ 192 /* the new way */
181 { 193 {
182 int i; 194 int i;
183 if (length & 1) 195 if ((length - start) & 1)
184 signal_simple_error ( 196 signal_simple_error (
185 "GUI item descriptor has an odd number of keywords and values", 197 "GUI item descriptor has an odd number of keywords and values",
186 item); 198 item);
187 199
188 for (i = 2; i < length;) 200 for (i = start; i < length;)
189 { 201 {
190 Lisp_Object key = contents [i++]; 202 Lisp_Object key = contents [i++];
191 Lisp_Object val = contents [i++]; 203 Lisp_Object val = contents [i++];
192 gui_item_add_keyval_pair (pgui_item, key, val); 204 gui_item_add_keyval_pair (pgui_item, key, val);
193 } 205 }
207 return (EQ (pgui_item->active, Qt) 219 return (EQ (pgui_item->active, Qt)
208 || !NILP (Feval (pgui_item->active))); 220 || !NILP (Feval (pgui_item->active)));
209 } 221 }
210 222
211 /* 223 /*
224 * Decide whether a GUI item is selected by evaluating its :selected form
225 * if any
226 */
227 int
228 gui_item_selected_p (CONST struct gui_item *pgui_item)
229 {
230 /* This function can call lisp */
231
232 /* Shortcut to avoid evaluating Qt each time */
233 return (EQ (pgui_item->selected, Qt)
234 || !NILP (Feval (pgui_item->selected)));
235 }
236
237 /*
212 * Decide whether a GUI item is included by evaluating its :included 238 * Decide whether a GUI item is included by evaluating its :included
213 * form if given, and testing its :config form against supplied CONFLIST 239 * form if given, and testing its :config form against supplied CONFLIST
214 * configuration variable 240 * configuration variable
215 */ 241 */
216 int 242 int
235 signal_too_long_error (Lisp_Object name) 261 signal_too_long_error (Lisp_Object name)
236 { 262 {
237 signal_simple_error ("GUI item produces too long displayable string", name); 263 signal_simple_error ("GUI item produces too long displayable string", name);
238 } 264 }
239 265
266 #ifdef HAVE_WINDOW_SYSTEM
240 /* 267 /*
241 * Format "left flush" display portion of an item into BUF, guarded by 268 * Format "left flush" display portion of an item into BUF, guarded by
242 * maximum buffer size BUF_LEN. BUF_LEN does not count for terminating 269 * maximum buffer size BUF_LEN. BUF_LEN does not count for terminating
243 * null character, so actual maximum size of buffer consumed is 270 * null character, so actual maximum size of buffer consumed is
244 * BUF_LEN + 1 bytes. If buffer is not big enough, then error is 271 * BUF_LEN + 1 bytes. If buffer is not big enough, then error is
328 } 355 }
329 356
330 /* No keys - no right flush display */ 357 /* No keys - no right flush display */
331 return 0; 358 return 0;
332 } 359 }
333 360 #endif /* HAVE_WINDOW_SYSTEM */
334 #endif /* HAVE_POPUPS */ 361
362 Lisp_Object
363 mark_gui_item (struct gui_item* p, void (*markobj) (Lisp_Object))
364 {
365 markobj (p->name);
366 markobj (p->callback);
367 markobj (p->suffix);
368 markobj (p->active);
369 markobj (p->included);
370 markobj (p->config);
371 markobj (p->filter);
372 markobj (p->style);
373 markobj (p->selected);
374 markobj (p->keys);
375
376 return Qnil;
377 }
378
379 int
380 gui_item_hash (Lisp_Object hashtable, struct gui_item* g, int slot)
381 {
382 int hashid = HASH2 (internal_hash (g->callback, 0), internal_hash (g->name, 0));
383 int id = GUI_ITEM_ID_BITS (hashid, slot);
384 while (!NILP (Fgethash (make_int (id),
385 hashtable, Qnil)))
386 {
387 id = GUI_ITEM_ID_BITS (id + 1, slot);
388 }
389 return id;
390 }
335 391
336 void 392 void
337 syms_of_gui (void) 393 syms_of_gui (void)
338 { 394 {
339 defkeyword (&Q_active, ":active"); 395 defkeyword (&Q_active, ":active");