Mercurial > hg > xemacs-beta
comparison src/gui.c @ 272:c5d627a313b1 r21-0b34
Import from CVS: tag r21-0b34
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:28:48 +0200 |
parents | 11cf20601dec |
children | 57709be46d1b |
comparison
equal
deleted
inserted
replaced
271:c7b7086b0a39 | 272:c5d627a313b1 |
---|---|
55 if (!s || s[0] == '\0') | 55 if (!s || s[0] == '\0') |
56 return 0; | 56 return 0; |
57 first = s[0]; | 57 first = s[0]; |
58 if (first != '-' && first != '=') | 58 if (first != '-' && first != '=') |
59 return 0; | 59 return 0; |
60 for (p = s; *p == first; p++); | 60 for (p = s; *p == first; p++) |
61 | 61 ; |
62 if (*p == '!' || *p == ':' || *p == '\0') | 62 |
63 return 1; | 63 return (*p == '!' || *p == ':' || *p == '\0'); |
64 return 0; | 64 } |
65 } | 65 |
66 | 66 /* |
67 /* | |
68 * Initialize the gui_item structure by setting all (GC-protected) | 67 * Initialize the gui_item structure by setting all (GC-protected) |
69 * fields to their default values. The defaults are t for :active and | 68 * fields to their default values. The defaults are t for :active and |
70 * :included values, and nil for others. | 69 * :included values, and nil for others. |
71 */ | 70 */ |
72 void | 71 void |
73 gui_item_init (struct gui_item *pgui_item) | 72 gui_item_init (struct gui_item *pgui_item) |
74 { | 73 { |
75 pgui_item->name = Qnil; | 74 pgui_item->name = Qnil; |
76 pgui_item->callback = Qnil; | 75 pgui_item->callback = Qnil; |
77 pgui_item->suffix = Qnil; | 76 pgui_item->suffix = Qnil; |
78 pgui_item->active = Qt; | 77 pgui_item->active = Qt; |
79 pgui_item->included = Qt; | 78 pgui_item->included = Qt; |
80 pgui_item->config = Qunbound; | 79 pgui_item->config = Qunbound; |
81 pgui_item->filter = Qnil; | 80 pgui_item->filter = Qnil; |
82 pgui_item->style = Qnil; | 81 pgui_item->style = Qnil; |
83 pgui_item->selected = Qnil; | 82 pgui_item->selected = Qnil; |
84 pgui_item->keys = Qnil; | 83 pgui_item->keys = Qnil; |
85 } | 84 } |
86 | 85 |
87 /* | 86 /* |
88 * Add a value VAL associated with keyword KEY into PGUI_ITEM | 87 * 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 | 88 * structure. If KEY is not a keyword, or is an unknown keyword, then |
90 * error is signaled. | 89 * error is signaled. |
91 */ | 90 */ |
92 void | 91 void |
93 gui_item_add_keyval_pair (struct gui_item *pgui_item, | 92 gui_item_add_keyval_pair (struct gui_item *pgui_item, |
94 Lisp_Object key, Lisp_Object val) | 93 Lisp_Object key, Lisp_Object val) |
95 { | 94 { |
96 if (!KEYWORDP (key)) | 95 if (!KEYWORDP (key)) |
97 error ("Not a keyword %S in gui item %S", key, pgui_item->name); | 96 signal_simple_error_2 ("Non-keyword in gui item", key, pgui_item->name); |
98 | 97 |
99 if (EQ (key, Q_suffix)) | 98 if (EQ (key, Q_suffix)) pgui_item->suffix = val; |
100 pgui_item->suffix = val; | 99 else if (EQ (key, Q_active)) pgui_item->active = val; |
101 else if (EQ (key, Q_active)) | 100 else if (EQ (key, Q_included)) pgui_item->included = val; |
102 pgui_item->active = val; | 101 else if (EQ (key, Q_config)) pgui_item->config = val; |
103 else if (EQ (key, Q_included)) | 102 else if (EQ (key, Q_filter)) pgui_item->filter = val; |
104 pgui_item->included = val; | 103 else if (EQ (key, Q_style)) pgui_item->style = val; |
105 else if (EQ (key, Q_config)) | 104 else if (EQ (key, Q_selected)) pgui_item->selected = val; |
106 pgui_item->config = val; | 105 else if (EQ (key, Q_keys)) pgui_item->keys = 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 | 106 else |
116 error ("Unknown keyword %S in gui item %S", key, pgui_item->name); | 107 signal_simple_error_2 ("Unknown keyword in gui item", key, pgui_item->name); |
117 } | 108 } |
118 | 109 |
119 /* | 110 /* |
120 * ITEM is a lisp vector, describing a menu item or a button. The | 111 * 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 | 112 * function extracts the description of the item into the PGUI_ITEM |
165 { | 156 { |
166 Lisp_Object key = contents [i++]; | 157 Lisp_Object key = contents [i++]; |
167 Lisp_Object val = contents [i++]; | 158 Lisp_Object val = contents [i++]; |
168 gui_item_add_keyval_pair (pgui_item, key, val); | 159 gui_item_add_keyval_pair (pgui_item, key, val); |
169 } | 160 } |
170 } | 161 } |
171 } | 162 } |
172 | 163 |
173 /* | 164 /* |
174 * Decide whether a GUI item is active by evaluating its :active form | 165 * Decide whether a GUI item is active by evaluating its :active form |
175 * if any | 166 * if any |
176 */ | 167 */ |
177 int | 168 int |
178 gui_item_active_p (CONST struct gui_item *pgui_item) | 169 gui_item_active_p (CONST struct gui_item *pgui_item) |
179 { | 170 { |
180 /* This function can call lisp */ | 171 /* This function can call lisp */ |
181 | 172 |
182 /* Shortcut to avoid evaluating Qt each time */ | 173 /* Shortcut to avoid evaluating Qt each time */ |
183 return (EQ (pgui_item->active, Qt) | 174 return (EQ (pgui_item->active, Qt) |
184 || !NILP (Feval (pgui_item->active))); | 175 || !NILP (Feval (pgui_item->active))); |
185 } | 176 } |
186 | 177 |
208 } | 199 } |
209 | 200 |
210 static DOESNT_RETURN | 201 static DOESNT_RETURN |
211 signal_too_long_error (Lisp_Object name) | 202 signal_too_long_error (Lisp_Object name) |
212 { | 203 { |
213 error ("GUI item %s produces too long displayable string", name); | 204 signal_simple_error ("GUI item produces too long displayable string", name); |
214 } | 205 } |
215 | 206 |
216 /* | 207 /* |
217 * Format "left flush" display portion of an item into BUF, guarded by | 208 * 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 | 209 * maximum buffer size BUF_LEN. BUF_LEN does not count for terminating |
219 * null character, so actual maximum size of buffer consumed is | 210 * null character, so actual maximum size of buffer consumed is |
220 * BUF_LEN + 1 bytes. If buffer is not big enough, then error is | 211 * BUF_LEN + 1 bytes. If buffer is not big enough, then error is |
221 * signaled. | 212 * signaled. |
222 * Return value is the offset to the terminating null character into the | 213 * Return value is the offset to the terminating null character into the |
223 * buffer. | 214 * buffer. |
224 */ | 215 */ |
225 unsigned int | 216 unsigned int |
226 gui_item_display_flush_left (CONST struct gui_item *pgui_item, | 217 gui_item_display_flush_left (CONST struct gui_item *pgui_item, |
227 char* buf, unsigned int buf_len) | 218 char* buf, Bytecount buf_len) |
228 { | 219 { |
229 unsigned int consumed; | 220 char *p = buf; |
221 Bytecount len; | |
230 | 222 |
231 /* Copy item name first */ | 223 /* Copy item name first */ |
232 CHECK_STRING (pgui_item->name); | 224 CHECK_STRING (pgui_item->name); |
233 if (XSTRING_LENGTH (pgui_item->name) > buf_len) | 225 len = XSTRING_LENGTH (pgui_item->name); |
226 if (len > buf_len) | |
234 signal_too_long_error (pgui_item->name); | 227 signal_too_long_error (pgui_item->name); |
235 strcpy (buf, XSTRING_DATA (pgui_item->name)); | 228 memcpy (p, XSTRING_DATA (pgui_item->name), len); |
236 buf += (consumed = XSTRING_LENGTH (pgui_item->name)); | 229 p += len; |
237 buf_len -= consumed; | |
238 | 230 |
239 /* Add space and suffix, if there is a suffix. | 231 /* Add space and suffix, if there is a suffix. |
240 * If suffix is not string evaluate it */ | 232 * If suffix is not string evaluate it */ |
241 if (!NILP (pgui_item->suffix)) | 233 if (!NILP (pgui_item->suffix)) |
242 { | 234 { |
243 Lisp_Object suffix2; | 235 Lisp_Object suffix = pgui_item->suffix; |
244 | |
245 /* Shortcut to avoid evaluating suffix each time */ | 236 /* Shortcut to avoid evaluating suffix each time */ |
246 if (STRINGP (pgui_item->suffix)) | 237 if (!STRINGP (suffix)) |
247 suffix2 = pgui_item->suffix; | |
248 else | |
249 { | 238 { |
250 suffix2 = Feval (pgui_item->suffix); | 239 suffix = Feval (suffix); |
251 CHECK_STRING (suffix2); | 240 CHECK_STRING (suffix); |
252 } | 241 } |
253 | 242 |
254 if (XSTRING_LENGTH (suffix2) + 1 > buf_len) | 243 len = XSTRING_LENGTH (suffix); |
244 if (p + len + 1 > buf + buf_len) | |
255 signal_too_long_error (pgui_item->name); | 245 signal_too_long_error (pgui_item->name); |
256 *(buf++) = ' '; | 246 *(p++) = ' '; |
257 strcpy (buf, XSTRING_DATA (suffix2)); | 247 memcpy (p, XSTRING_DATA (suffix), len); |
258 consumed += XSTRING_LENGTH (suffix2) + 1; | 248 p += len; |
259 } | 249 } |
260 | 250 *p = '\0'; |
261 return consumed; | 251 return p - buf; |
262 } | 252 } |
263 | 253 |
264 /* | 254 /* |
265 * Format "right flush" display portion of an item into BUF, guarded by | 255 * 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 | 256 * maximum buffer size BUF_LEN. BUF_LEN does not count for terminating |
267 * null character, so actual maximum size of buffer consumed is | 257 * null character, so actual maximum size of buffer consumed is |
268 * BUF_LEN + 1 bytes. If buffer is not big enough, then error is | 258 * BUF_LEN + 1 bytes. If buffer is not big enough, then error is |
269 * signaled. | 259 * signaled. |
270 * Return value is the offset to the terminating null character into the | 260 * Return value is the offset to the terminating null character into the |
271 * buffer. | 261 * buffer. |
272 */ | 262 */ |
273 unsigned int | 263 unsigned int |
274 gui_item_display_flush_right (CONST struct gui_item *pgui_item, | 264 gui_item_display_flush_right (CONST struct gui_item *pgui_item, |
275 char* buf, unsigned int buf_len) | 265 char* buf, Bytecount buf_len) |
276 { | 266 { |
277 *buf = 0; | 267 *buf = 0; |
278 | 268 |
279 /* Have keys? */ | 269 /* Have keys? */ |
280 if (!menubar_show_keybindings) | 270 if (!menubar_show_keybindings) |
284 if (!NILP (pgui_item->keys)) | 274 if (!NILP (pgui_item->keys)) |
285 { | 275 { |
286 CHECK_STRING (pgui_item->keys); | 276 CHECK_STRING (pgui_item->keys); |
287 if (XSTRING_LENGTH (pgui_item->keys) > buf_len) | 277 if (XSTRING_LENGTH (pgui_item->keys) > buf_len) |
288 signal_too_long_error (pgui_item->name); | 278 signal_too_long_error (pgui_item->name); |
289 strcpy (buf, XSTRING_DATA (pgui_item->keys)); | 279 strcpy (buf, (CONST char *) XSTRING_DATA (pgui_item->keys)); |
290 return XSTRING_LENGTH (pgui_item->keys); | 280 return XSTRING_LENGTH (pgui_item->keys); |
291 } | 281 } |
292 | 282 |
293 /* See if we can derive keys out of callback symbol */ | 283 /* See if we can derive keys out of callback symbol */ |
294 if (SYMBOLP (pgui_item->callback)) | 284 if (SYMBOLP (pgui_item->callback)) |
295 { | 285 { |
296 char buf2 [1024]; | 286 char buf2 [1024]; |
297 unsigned int len; | 287 Bytecount len; |
298 | 288 |
299 where_is_to_char (pgui_item->callback, buf2); | 289 where_is_to_char (pgui_item->callback, buf2); |
300 len = strlen (buf2); | 290 len = strlen (buf2); |
301 if (len > buf_len) | 291 if (len > buf_len) |
302 signal_too_long_error (pgui_item->name); | 292 signal_too_long_error (pgui_item->name); |