comparison src/glyphs-widget.c @ 418:e804706bfb8c r21-2-17

Import from CVS: tag r21-2-17
author cvs
date Mon, 13 Aug 2007 11:23:13 +0200
parents 697ef44129c6
children 41dbb7a9d5f2
comparison
equal deleted inserted replaced
417:43a18b32d56e 418:e804706bfb8c
51 #endif 51 #endif
52 DEFINE_IMAGE_INSTANTIATOR_FORMAT (label); 52 DEFINE_IMAGE_INSTANTIATOR_FORMAT (label);
53 Lisp_Object Qlabel; 53 Lisp_Object Qlabel;
54 DEFINE_IMAGE_INSTANTIATOR_FORMAT (progress); 54 DEFINE_IMAGE_INSTANTIATOR_FORMAT (progress);
55 Lisp_Object Qprogress; 55 Lisp_Object Qprogress;
56 DEFINE_IMAGE_INSTANTIATOR_FORMAT (tree);
57 Lisp_Object Qtree;
58 DEFINE_IMAGE_INSTANTIATOR_FORMAT (tab);
59 Lisp_Object Qtab;
56 60
57 Lisp_Object Q_descriptor, Q_height, Q_width, Q_properties, Q_items; 61 Lisp_Object Q_descriptor, Q_height, Q_width, Q_properties, Q_items;
58 Lisp_Object Q_image, Q_text, Q_percent; 62 Lisp_Object Q_image, Q_text, Q_percent;
59 63
60 #define WIDGET_BORDER_HEIGHT 2 64 #define WIDGET_BORDER_HEIGHT 2
144 if (!STRINGP (data) && !VECTORP (data)) 148 if (!STRINGP (data) && !VECTORP (data))
145 signal_simple_error (":descriptor must be a string or a vector", data); 149 signal_simple_error (":descriptor must be a string or a vector", data);
146 } 150 }
147 151
148 static void 152 static void
149 check_valid_item_list (Lisp_Object data) 153 check_valid_item_list_1 (Lisp_Object items)
150 { 154 {
151 Lisp_Object rest; 155 Lisp_Object rest;
152 Lisp_Object items;
153 Fcheck_valid_plist (data);
154
155 items = Fplist_get (data, Q_items, Qnil);
156 156
157 CHECK_LIST (items); 157 CHECK_LIST (items);
158 EXTERNAL_LIST_LOOP (rest, items) 158 EXTERNAL_LIST_LOOP (rest, items)
159 { 159 {
160 CHECK_STRING (XCAR (rest)); 160 if (STRINGP (XCAR (rest)))
161 } 161 CHECK_STRING (XCAR (rest));
162 else if (VECTORP (XCAR (rest)))
163 gui_parse_item_keywords (XCAR (rest));
164 else if (LISTP (XCAR (rest)))
165 check_valid_item_list_1 (XCAR (rest));
166 else
167 signal_simple_error ("Items must be vectors, lists or strings", items);
168 }
169 }
170
171 static void
172 check_valid_item_list (Lisp_Object data)
173 {
174 Lisp_Object items;
175
176 Fcheck_valid_plist (data);
177 items = Fplist_get (data, Q_items, Qnil);
178
179 check_valid_item_list_1 (items);
162 } 180 }
163 181
164 /* wire widget property invocations to specific widgets ... The 182 /* wire widget property invocations to specific widgets ... The
165 problem we are solving here is that when instantiators get converted 183 problem we are solving here is that when instantiators get converted
166 to instances they lose some type information (they just become 184 to instances they lose some type information (they just become
233 251
234 static void 252 static void
235 widget_validate (Lisp_Object instantiator) 253 widget_validate (Lisp_Object instantiator)
236 { 254 {
237 Lisp_Object desc = find_keyword_in_vector (instantiator, Q_descriptor); 255 Lisp_Object desc = find_keyword_in_vector (instantiator, Q_descriptor);
238 struct gui_item gui; 256
239 if (NILP (desc)) 257 if (NILP (desc))
240 signal_simple_error ("Must supply :descriptor", instantiator); 258 signal_simple_error ("Must supply :descriptor", instantiator);
241 259
242 if (VECTORP (desc)) 260 if (VECTORP (desc))
243 gui_parse_item_keywords (desc, &gui); 261 gui_parse_item_keywords (desc);
244 262
245 if (!NILP (find_keyword_in_vector (instantiator, Q_width)) 263 if (!NILP (find_keyword_in_vector (instantiator, Q_width))
246 && !NILP (find_keyword_in_vector (instantiator, Q_pixel_width))) 264 && !NILP (find_keyword_in_vector (instantiator, Q_pixel_width)))
247 signal_simple_error ("Must supply only one of :width and :pixel-width", instantiator); 265 signal_simple_error ("Must supply only one of :width and :pixel-width", instantiator);
248 266
249 if (!NILP (find_keyword_in_vector (instantiator, Q_height)) 267 if (!NILP (find_keyword_in_vector (instantiator, Q_height))
250 && !NILP (find_keyword_in_vector (instantiator, Q_pixel_height))) 268 && !NILP (find_keyword_in_vector (instantiator, Q_pixel_height)))
251 signal_simple_error ("Must supply only one of :height and :pixel-height", instantiator); 269 signal_simple_error ("Must supply only one of :height and :pixel-height", instantiator);
298 { 316 {
299 /* initialize_subwindow_image_instance (ii);*/ 317 /* initialize_subwindow_image_instance (ii);*/
300 IMAGE_INSTANCE_WIDGET_TYPE (ii) = type; 318 IMAGE_INSTANCE_WIDGET_TYPE (ii) = type;
301 IMAGE_INSTANCE_WIDGET_PROPS (ii) = Qnil; 319 IMAGE_INSTANCE_WIDGET_PROPS (ii) = Qnil;
302 IMAGE_INSTANCE_WIDGET_FACE (ii) = Vwidget_face; 320 IMAGE_INSTANCE_WIDGET_FACE (ii) = Vwidget_face;
303 gui_item_init (&IMAGE_INSTANCE_WIDGET_ITEM (ii)); 321 IMAGE_INSTANCE_WIDGET_ITEM (ii) = allocate_gui_item ();
304 } 322 }
305 323
306 /* Instantiate a button widget. Unfortunately instantiated widgets are 324 /* Instantiate a button widget. Unfortunately instantiated widgets are
307 particular to a frame since they need to have a parent. It's not 325 particular to a frame since they need to have a parent. It's not
308 like images where you just select the image into the context you 326 like images where you just select the image into the context you
309 want to display it in and BitBlt it. So images instances can have a 327 want to display it in and BitBlt it. So image instances can have a
310 many-to-one relationship with things you see, whereas widgets can 328 many-to-one relationship with things you see, whereas widgets can
311 only be one-to-one (i.e. per frame) */ 329 only be one-to-one (i.e. per frame) */
312 static void 330 static void
313 widget_instantiate_1 (Lisp_Object image_instance, Lisp_Object instantiator, 331 widget_instantiate_1 (Lisp_Object image_instance, Lisp_Object instantiator,
314 Lisp_Object pointer_fg, Lisp_Object pointer_bg, 332 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
315 int dest_mask, Lisp_Object domain, int default_textheight, 333 int dest_mask, Lisp_Object domain, int default_textheight,
316 int default_pixheight) 334 int default_pixheight, int default_textwidth)
317 { 335 {
318 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); 336 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
319 struct gui_item* pgui = &IMAGE_INSTANCE_WIDGET_ITEM (ii);
320 Lisp_Object face = find_keyword_in_vector (instantiator, Q_face); 337 Lisp_Object face = find_keyword_in_vector (instantiator, Q_face);
321 Lisp_Object height = find_keyword_in_vector (instantiator, Q_height); 338 Lisp_Object height = find_keyword_in_vector (instantiator, Q_height);
322 Lisp_Object width = find_keyword_in_vector (instantiator, Q_width); 339 Lisp_Object width = find_keyword_in_vector (instantiator, Q_width);
323 Lisp_Object pixwidth = find_keyword_in_vector (instantiator, Q_pixel_width); 340 Lisp_Object pixwidth = find_keyword_in_vector (instantiator, Q_pixel_width);
324 Lisp_Object pixheight = find_keyword_in_vector (instantiator, Q_pixel_height); 341 Lisp_Object pixheight = find_keyword_in_vector (instantiator, Q_pixel_height);
347 provided with a vector, more difficult if we have just been given 364 provided with a vector, more difficult if we have just been given
348 keywords */ 365 keywords */
349 if (STRINGP (desc) || NILP (desc)) 366 if (STRINGP (desc) || NILP (desc))
350 { 367 {
351 /* big cheat - we rely on the fact that a gui item looks like an instantiator */ 368 /* big cheat - we rely on the fact that a gui item looks like an instantiator */
352 gui_parse_item_keywords_no_errors (instantiator, pgui); 369 IMAGE_INSTANCE_WIDGET_ITEM (ii) =
370 gui_parse_item_keywords_no_errors (instantiator);
353 IMAGE_INSTANCE_WIDGET_TEXT (ii) = desc; 371 IMAGE_INSTANCE_WIDGET_TEXT (ii) = desc;
354 } 372 }
355 else 373 else
356 gui_parse_item_keywords_no_errors (desc, pgui); 374 IMAGE_INSTANCE_WIDGET_ITEM (ii) =
375 gui_parse_item_keywords_no_errors (desc);
357 376
358 /* normalize size information */ 377 /* normalize size information */
359 if (!NILP (width)) 378 if (!NILP (width))
360 tw = XINT (width); 379 tw = XINT (width);
361 if (!NILP (height)) 380 if (!NILP (height))
375 ph = glyph_height (glyph, Qnil, DEFAULT_INDEX, domain) 394 ph = glyph_height (glyph, Qnil, DEFAULT_INDEX, domain)
376 + 2 * WIDGET_BORDER_HEIGHT; 395 + 2 * WIDGET_BORDER_HEIGHT;
377 } 396 }
378 397
379 /* if we still don' t have sizes, guess from text size */ 398 /* if we still don' t have sizes, guess from text size */
380 if (!tw && !pw && !NILP (IMAGE_INSTANCE_WIDGET_TEXT (ii))) 399 if (!tw && !pw)
381 tw = XSTRING_LENGTH (IMAGE_INSTANCE_WIDGET_TEXT (ii)); 400 {
401 if (default_textwidth)
402 tw = default_textwidth;
403 else if (!NILP (IMAGE_INSTANCE_WIDGET_TEXT (ii)))
404 tw = XSTRING_LENGTH (IMAGE_INSTANCE_WIDGET_TEXT (ii));
405 }
406
382 if (!th && !ph) 407 if (!th && !ph)
383 { 408 {
384 if (default_textheight) 409 if (default_textheight)
385 th = default_textheight; 410 th = default_textheight;
386 else if (!NILP (IMAGE_INSTANCE_WIDGET_TEXT (ii))) 411 else if (!NILP (IMAGE_INSTANCE_WIDGET_TEXT (ii)))
402 widget_instantiate (Lisp_Object image_instance, Lisp_Object instantiator, 427 widget_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
403 Lisp_Object pointer_fg, Lisp_Object pointer_bg, 428 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
404 int dest_mask, Lisp_Object domain) 429 int dest_mask, Lisp_Object domain)
405 { 430 {
406 widget_instantiate_1 (image_instance, instantiator, pointer_fg, 431 widget_instantiate_1 (image_instance, instantiator, pointer_fg,
407 pointer_bg, dest_mask, domain, 1, 0); 432 pointer_bg, dest_mask, domain, 1, 0, 0);
408 } 433 }
409 434
435 /* combo-box generic instantiation - get he heigh right */
410 static void 436 static void
411 combo_instantiate (Lisp_Object image_instance, Lisp_Object instantiator, 437 combo_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
412 Lisp_Object pointer_fg, Lisp_Object pointer_bg, 438 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
413 int dest_mask, Lisp_Object domain) 439 int dest_mask, Lisp_Object domain)
414 { 440 {
415 Lisp_Object data = Fplist_get (find_keyword_in_vector (instantiator, Q_properties), 441 Lisp_Object data = Fplist_get (find_keyword_in_vector (instantiator, Q_properties),
416 Q_items, Qnil); 442 Q_items, Qnil);
417 int len; 443 int len;
418 GET_LIST_LENGTH (data, len); 444 GET_LIST_LENGTH (data, len);
419 widget_instantiate_1 (image_instance, instantiator, pointer_fg, 445 widget_instantiate_1 (image_instance, instantiator, pointer_fg,
420 pointer_bg, dest_mask, domain, len + 1, 0); 446 pointer_bg, dest_mask, domain, len + 1, 0, 0);
447 }
448
449 static void
450 tab_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
451 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
452 int dest_mask, Lisp_Object domain)
453 {
454 Lisp_Object data = Fplist_get (find_keyword_in_vector (instantiator, Q_properties),
455 Q_items, Qnil);
456 Lisp_Object rest;
457 int len = 0;
458
459 LIST_LOOP (rest, data)
460 {
461 len += 3; /* some bias */
462 if (STRINGP (XCAR (rest)))
463 len += XSTRING_LENGTH (XCAR (rest));
464 else if (VECTORP (XCAR (rest)))
465 {
466 Lisp_Object gui = gui_parse_item_keywords (XCAR (rest));
467 len += XSTRING_LENGTH (XGUI_ITEM (gui)->name);
468 }
469 }
470
471 widget_instantiate_1 (image_instance, instantiator, pointer_fg,
472 pointer_bg, dest_mask, domain, 0, 0, len);
421 } 473 }
422 474
423 /* Instantiate a static control */ 475 /* Instantiate a static control */
424 static void 476 static void
425 static_instantiate (Lisp_Object image_instance, Lisp_Object instantiator, 477 static_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
426 Lisp_Object pointer_fg, Lisp_Object pointer_bg, 478 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
427 int dest_mask, Lisp_Object domain) 479 int dest_mask, Lisp_Object domain)
428 { 480 {
429 widget_instantiate_1 (image_instance, instantiator, pointer_fg, 481 widget_instantiate_1 (image_instance, instantiator, pointer_fg,
430 pointer_bg, dest_mask, domain, 0, 4); 482 pointer_bg, dest_mask, domain, 0, 4, 0);
431 } 483 }
432 484
433 485
434 /************************************************************************/ 486 /************************************************************************/
435 /* initialization */ 487 /* initialization */
443 defkeyword (&Q_width, ":width"); 495 defkeyword (&Q_width, ":width");
444 defkeyword (&Q_properties, ":properties"); 496 defkeyword (&Q_properties, ":properties");
445 defkeyword (&Q_items, ":items"); 497 defkeyword (&Q_items, ":items");
446 defkeyword (&Q_image, ":image"); 498 defkeyword (&Q_image, ":image");
447 defkeyword (&Q_percent, ":percent"); 499 defkeyword (&Q_percent, ":percent");
448 defkeyword (&Q_text, "text"); 500 defkeyword (&Q_text, ":text");
449 } 501 }
450 502
451 void 503 void
452 image_instantiator_format_create_glyphs_widget (void) 504 image_instantiator_format_create_glyphs_widget (void)
453 { 505 {
522 574
523 /* progress guage */ 575 /* progress guage */
524 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (progress, "progress"); 576 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (progress, "progress");
525 IIFORMAT_HAS_SHARED_METHOD (progress, validate, widget); 577 IIFORMAT_HAS_SHARED_METHOD (progress, validate, widget);
526 IIFORMAT_HAS_SHARED_METHOD (progress, possible_dest_types, widget); 578 IIFORMAT_HAS_SHARED_METHOD (progress, possible_dest_types, widget);
527 IIFORMAT_HAS_SHARED_METHOD (progress, instantiate, widget); 579 IIFORMAT_HAS_SHARED_METHOD (progress, instantiate, combo);
528 VALID_WIDGET_KEYWORDS (progress); 580 VALID_WIDGET_KEYWORDS (progress);
529 VALID_GUI_KEYWORDS (progress); 581 VALID_GUI_KEYWORDS (progress);
582
583 /* tree view */
584 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (tree, "tree");
585 IIFORMAT_HAS_SHARED_METHOD (tree, validate, combo);
586 IIFORMAT_HAS_SHARED_METHOD (tree, possible_dest_types, widget);
587 IIFORMAT_HAS_SHARED_METHOD (tree, instantiate, combo);
588 VALID_WIDGET_KEYWORDS (tree);
589 VALID_GUI_KEYWORDS (tree);
590 IIFORMAT_VALID_KEYWORD (tree, Q_properties, check_valid_item_list);
591
592 /* tab control */
593 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (tab, "tab");
594 IIFORMAT_HAS_SHARED_METHOD (tab, validate, combo);
595 IIFORMAT_HAS_SHARED_METHOD (tab, possible_dest_types, widget);
596 IIFORMAT_HAS_METHOD (tab, instantiate);
597 VALID_WIDGET_KEYWORDS (tab);
598 VALID_GUI_KEYWORDS (tab);
599 IIFORMAT_VALID_KEYWORD (tab, Q_properties, check_valid_item_list);
530 600
531 /* labels */ 601 /* labels */
532 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (label, "label"); 602 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (label, "label");
533 IIFORMAT_HAS_SHARED_METHOD (label, possible_dest_types, widget); 603 IIFORMAT_HAS_SHARED_METHOD (label, possible_dest_types, widget);
534 IIFORMAT_HAS_SHARED_METHOD (label, instantiate, static); 604 IIFORMAT_HAS_SHARED_METHOD (label, instantiate, static);