comparison src/glyphs-widget.c @ 424:11054d720c21 r21-2-20

Import from CVS: tag r21-2-20
author cvs
date Mon, 13 Aug 2007 11:26:11 +0200
parents 95016f13131a
children
comparison
equal deleted inserted replaced
423:28d9c139be4c 424:11054d720c21
1 /* Widget-specific glyph objects. 1 /* Widget-specific glyph objects.
2 Copyright (C) 1998 Andy Piper 2 Copyright (C) 1998, 1999 Andy Piper.
3 3
4 This file is part of XEmacs. 4 This file is part of XEmacs.
5 5
6 XEmacs is free software; you can redistribute it and/or modify it 6 XEmacs is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the 7 under the terms of the GNU General Public License as published by the
43 DEFINE_IMAGE_INSTANTIATOR_FORMAT (edit_field); 43 DEFINE_IMAGE_INSTANTIATOR_FORMAT (edit_field);
44 Lisp_Object Qedit_field; 44 Lisp_Object Qedit_field;
45 DEFINE_IMAGE_INSTANTIATOR_FORMAT (scrollbar); 45 DEFINE_IMAGE_INSTANTIATOR_FORMAT (scrollbar);
46 Lisp_Object Qscrollbar; 46 Lisp_Object Qscrollbar;
47 DEFINE_IMAGE_INSTANTIATOR_FORMAT (widget); 47 DEFINE_IMAGE_INSTANTIATOR_FORMAT (widget);
48 #if 0
49 DEFINE_IMAGE_INSTANTIATOR_FORMAT (group);
50 Lisp_Object Qgroup;
51 #endif
52 DEFINE_IMAGE_INSTANTIATOR_FORMAT (label); 48 DEFINE_IMAGE_INSTANTIATOR_FORMAT (label);
53 Lisp_Object Qlabel; 49 Lisp_Object Qlabel;
54 DEFINE_IMAGE_INSTANTIATOR_FORMAT (progress_gauge); 50 DEFINE_IMAGE_INSTANTIATOR_FORMAT (progress_gauge);
55 Lisp_Object Qprogress_gauge; 51 Lisp_Object Qprogress_gauge;
56 DEFINE_IMAGE_INSTANTIATOR_FORMAT (tree_view); 52 DEFINE_IMAGE_INSTANTIATOR_FORMAT (tree_view);
57 Lisp_Object Qtree_view; 53 Lisp_Object Qtree_view;
58 DEFINE_IMAGE_INSTANTIATOR_FORMAT (tab_control); 54 DEFINE_IMAGE_INSTANTIATOR_FORMAT (tab_control);
59 Lisp_Object Qtab_control; 55 Lisp_Object Qtab_control;
56 DEFINE_IMAGE_INSTANTIATOR_FORMAT (layout);
57 Lisp_Object Qlayout;
60 58
61 Lisp_Object Q_descriptor, Q_height, Q_width, Q_properties, Q_items; 59 Lisp_Object Q_descriptor, Q_height, Q_width, Q_properties, Q_items;
62 Lisp_Object Q_image, Q_text, Q_percent; 60 Lisp_Object Q_image, Q_text, Q_percent, Q_orientation, Q_justify, Q_border;
63 61 Lisp_Object Qetched_in, Qetched_out, Qbevel_in, Qbevel_out;
64 #define WIDGET_BORDER_HEIGHT 2 62
63 #define WIDGET_BORDER_HEIGHT 4
65 #define WIDGET_BORDER_WIDTH 4 64 #define WIDGET_BORDER_WIDTH 4
65
66 #ifdef DEBUG_WIDGETS
67 int debug_widget_instances;
68 #endif
66 69
67 /* TODO: 70 /* TODO:
68 - more complex controls. 71 - more complex controls.
69 - tooltips for controls. 72 - tooltips for controls.
70 */ 73 */
94 int* height, int* width) 97 int* height, int* width)
95 { 98 {
96 int ch=0, cw=0; 99 int ch=0, cw=0;
97 widget_face_font_info (domain, face, &ch, &cw); 100 widget_face_font_info (domain, face, &ch, &cw);
98 if (height) 101 if (height)
99 *height = th * (ch + 2 * WIDGET_BORDER_HEIGHT); 102 *height = th * ch + 2 * WIDGET_BORDER_HEIGHT;
100 if (width) 103 if (width)
101 *width = tw * cw + 2 * WIDGET_BORDER_WIDTH; 104 *width = tw * cw + 2 * WIDGET_BORDER_WIDTH;
102 } 105 }
103 106
104 static int 107 static int
106 { 109 {
107 return IMAGE_WIDGET_MASK; 110 return IMAGE_WIDGET_MASK;
108 } 111 }
109 112
110 static void 113 static void
111 check_valid_glyph_or_image (Lisp_Object data) 114 check_valid_glyph_or_instantiator (Lisp_Object data)
112 { 115 {
113 Lisp_Object glyph = data; 116 Lisp_Object glyph = data;
114 if (SYMBOLP (data)) 117 if (SYMBOLP (data))
115 glyph = XSYMBOL (data)->value; 118 glyph = XSYMBOL (data)->value;
116 119
117 if (IMAGE_INSTANCEP (glyph)) 120 if (IMAGE_INSTANCEP (glyph))
118 CHECK_IMAGE_INSTANCE (glyph); 121 CHECK_IMAGE_INSTANCE (glyph);
119 else if (!CONSP (glyph)) 122 else if (!CONSP (glyph) && !VECTORP (glyph))
120 CHECK_BUFFER_GLYPH (glyph); 123 CHECK_BUFFER_GLYPH (glyph);
124 }
125
126 static void
127 check_valid_orientation (Lisp_Object data)
128 {
129 if (!EQ (data, Qhorizontal)
130 &&
131 !EQ (data, Qvertical))
132 signal_simple_error ("unknown orientation for layout", data);
133 }
134
135 static void
136 check_valid_justification (Lisp_Object data)
137 {
138 if (!EQ (data, Qleft) && !EQ (data, Qright) && !EQ (data, Qcenter))
139 signal_simple_error ("unknown justification for layout", data);
140 }
141
142 static void
143 check_valid_border (Lisp_Object data)
144 {
145 if (!EQ (data, Qt) && !EQ (data, Qetched_in) && !EQ (data, Qetched_out)
146 && !EQ (data, Qbevel_in) && !EQ (data, Qbevel_out)
147 && !GLYPHP (data) && !VECTORP (data))
148 signal_simple_error ("unknown border style for layout", data);
121 } 149 }
122 150
123 static void 151 static void
124 check_valid_anything (Lisp_Object data) 152 check_valid_anything (Lisp_Object data)
125 { 153 {
175 203
176 Fcheck_valid_plist (data); 204 Fcheck_valid_plist (data);
177 items = Fplist_get (data, Q_items, Qnil); 205 items = Fplist_get (data, Q_items, Qnil);
178 206
179 check_valid_item_list_1 (items); 207 check_valid_item_list_1 (items);
208 }
209
210 static void
211 check_valid_glyph_or_instantiator_list (Lisp_Object data)
212 {
213 Lisp_Object rest;
214
215 CHECK_LIST (data);
216 EXTERNAL_LIST_LOOP (rest, data)
217 {
218 check_valid_glyph_or_instantiator (XCAR (rest));
219 }
220 }
221
222 static Lisp_Object
223 glyph_instantiator_to_glyph (Lisp_Object sym)
224 {
225 /* This function calls lisp. */
226 Lisp_Object glyph = sym;
227 struct gcpro gcpro1;
228
229 GCPRO1 (glyph);
230 /* if we have a symbol get at the actual data */
231 if (SYMBOLP (glyph))
232 glyph = XSYMBOL (glyph)->value;
233
234 if (CONSP (glyph))
235 glyph = Feval (glyph);
236
237 /* Be really helpful to the user. */
238 if (VECTORP (glyph))
239 {
240 glyph = call1 (intern ("make-glyph"), glyph);
241 }
242
243 /* substitute the new glyph */
244 RETURN_UNGCPRO (glyph);
245 }
246
247 static void
248 substitute_keyword_value (Lisp_Object inst, Lisp_Object key, Lisp_Object val)
249 {
250 int i;
251 /* substitute the new glyph */
252 for (i = 0; i < XVECTOR_LENGTH (inst); i++)
253 {
254 if (EQ (key, XVECTOR_DATA (inst)[i]))
255 {
256 XVECTOR_DATA (inst)[i+1] = val;
257 break;
258 }
259 }
180 } 260 }
181 261
182 /* wire widget property invocations to specific widgets ... The 262 /* wire widget property invocations to specific widgets ... The
183 problem we are solving here is that when instantiators get converted 263 problem we are solving here is that when instantiators get converted
184 to instances they lose some type information (they just become 264 to instances they lose some type information (they just become
287 367
288 /* we need to eval glyph if its an expression, we do this for the 368 /* we need to eval glyph if its an expression, we do this for the
289 same reasons we normalize file to data. */ 369 same reasons we normalize file to data. */
290 if (!NILP (glyph)) 370 if (!NILP (glyph))
291 { 371 {
292 int i; 372 substitute_keyword_value (inst, Q_image, glyph_instantiator_to_glyph (glyph));
293 struct gcpro gcpro1; 373 }
294 if (SYMBOLP (glyph)) 374
295 glyph = XSYMBOL (glyph)->value;
296 GCPRO1 (glyph);
297
298 if (CONSP (glyph))
299 glyph = Feval (glyph);
300 /* substitute the new glyph */
301 for (i = 0; i < XVECTOR_LENGTH (inst); i++)
302 {
303 if (EQ (Q_image, XVECTOR_DATA (inst)[i]))
304 {
305 XVECTOR_DATA (inst)[i+1] = glyph;
306 break;
307 }
308 }
309 UNGCPRO;
310 }
311 return inst; 375 return inst;
312 } 376 }
313 377
314 static void 378 static void
315 initialize_widget_image_instance (struct Lisp_Image_Instance *ii, Lisp_Object type) 379 initialize_widget_image_instance (struct Lisp_Image_Instance *ii, Lisp_Object type)
316 { 380 {
317 /* initialize_subwindow_image_instance (ii);*/ 381 /* initialize_subwindow_image_instance (ii);*/
318 IMAGE_INSTANCE_WIDGET_TYPE (ii) = type; 382 IMAGE_INSTANCE_WIDGET_TYPE (ii) = type;
319 IMAGE_INSTANCE_WIDGET_PROPS (ii) = Qnil; 383 IMAGE_INSTANCE_WIDGET_PROPS (ii) = Qnil;
320 IMAGE_INSTANCE_WIDGET_FACE (ii) = Vwidget_face; 384 IMAGE_INSTANCE_WIDGET_FACE (ii) = Vwidget_face;
321 IMAGE_INSTANCE_WIDGET_ITEM (ii) = allocate_gui_item (); 385 IMAGE_INSTANCE_WIDGET_ITEMS (ii) = allocate_gui_item ();
322 } 386 }
323 387
324 /* Instantiate a button widget. Unfortunately instantiated widgets are 388 /* Instantiate a button widget. Unfortunately instantiated widgets are
325 particular to a frame since they need to have a parent. It's not 389 particular to a frame since they need to have a parent. It's not
326 like images where you just select the image into the context you 390 like images where you just select the image into the context you
327 want to display it in and BitBlt it. So image instances can have a 391 want to display it in and BitBlt it. So image instances can have a
328 many-to-one relationship with things you see, whereas widgets can 392 many-to-one relationship with things you see, whereas widgets can
329 only be one-to-one (i.e. per frame) */ 393 only be one-to-one (i.e. per frame) */
330 static void 394 void
331 widget_instantiate_1 (Lisp_Object image_instance, Lisp_Object instantiator, 395 widget_instantiate_1 (Lisp_Object image_instance, Lisp_Object instantiator,
332 Lisp_Object pointer_fg, Lisp_Object pointer_bg, 396 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
333 int dest_mask, Lisp_Object domain, int default_textheight, 397 int dest_mask, Lisp_Object domain, int default_textheight,
334 int default_pixheight, int default_textwidth) 398 int default_pixheight, int default_textwidth)
335 { 399 {
339 Lisp_Object width = find_keyword_in_vector (instantiator, Q_width); 403 Lisp_Object width = find_keyword_in_vector (instantiator, Q_width);
340 Lisp_Object pixwidth = find_keyword_in_vector (instantiator, Q_pixel_width); 404 Lisp_Object pixwidth = find_keyword_in_vector (instantiator, Q_pixel_width);
341 Lisp_Object pixheight = find_keyword_in_vector (instantiator, Q_pixel_height); 405 Lisp_Object pixheight = find_keyword_in_vector (instantiator, Q_pixel_height);
342 Lisp_Object desc = find_keyword_in_vector (instantiator, Q_descriptor); 406 Lisp_Object desc = find_keyword_in_vector (instantiator, Q_descriptor);
343 Lisp_Object glyph = find_keyword_in_vector (instantiator, Q_image); 407 Lisp_Object glyph = find_keyword_in_vector (instantiator, Q_image);
408 Lisp_Object props = find_keyword_in_vector (instantiator, Q_properties);
344 int pw=0, ph=0, tw=0, th=0; 409 int pw=0, ph=0, tw=0, th=0;
345 410
346 /* this just does pixel type sizing */ 411 /* this just does pixel type sizing */
347 subwindow_instantiate (image_instance, instantiator, pointer_fg, pointer_bg, 412 subwindow_instantiate (image_instance, instantiator, pointer_fg, pointer_bg,
348 dest_mask, domain); 413 dest_mask, domain);
355 /* retrieve the fg and bg colors */ 420 /* retrieve the fg and bg colors */
356 if (!NILP (face)) 421 if (!NILP (face))
357 IMAGE_INSTANCE_WIDGET_FACE (ii) = Fget_face (face); 422 IMAGE_INSTANCE_WIDGET_FACE (ii) = Fget_face (face);
358 423
359 /* data items for some widgets */ 424 /* data items for some widgets */
360 IMAGE_INSTANCE_WIDGET_PROPS (ii) = 425 IMAGE_INSTANCE_WIDGET_PROPS (ii) = props;
361 find_keyword_in_vector (instantiator, Q_properties);
362 426
363 /* retrieve the gui item information. This is easy if we have been 427 /* retrieve the gui item information. This is easy if we have been
364 provided with a vector, more difficult if we have just been given 428 provided with a vector, more difficult if we have just been given
365 keywords */ 429 keywords */
366 if (STRINGP (desc) || NILP (desc)) 430 if (STRINGP (desc) || NILP (desc))
367 { 431 {
368 /* big cheat - we rely on the fact that a gui item looks like an instantiator */ 432 /* big cheat - we rely on the fact that a gui item looks like an instantiator */
369 IMAGE_INSTANCE_WIDGET_ITEM (ii) = 433 IMAGE_INSTANCE_WIDGET_ITEMS (ii) =
370 gui_parse_item_keywords_no_errors (instantiator); 434 gui_parse_item_keywords_no_errors (instantiator);
371 IMAGE_INSTANCE_WIDGET_TEXT (ii) = desc; 435 IMAGE_INSTANCE_WIDGET_TEXT (ii) = desc;
372 } 436 }
373 else 437 else
374 IMAGE_INSTANCE_WIDGET_ITEM (ii) = 438 IMAGE_INSTANCE_WIDGET_ITEMS (ii) =
375 gui_parse_item_keywords_no_errors (desc); 439 gui_parse_item_keywords_no_errors (desc);
440
441 /* parse more gui items out of the properties */
442 if (!NILP (props))
443 {
444 Lisp_Object items = Fplist_get (props, Q_items, Qnil);
445 if (!NILP (items))
446 IMAGE_INSTANCE_WIDGET_ITEMS (ii) =
447 Fcons (IMAGE_INSTANCE_WIDGET_ITEMS (ii),
448 parse_gui_item_tree_children (items));
449 }
376 450
377 /* normalize size information */ 451 /* normalize size information */
378 if (!NILP (width)) 452 if (!NILP (width))
379 tw = XINT (width); 453 tw = XINT (width);
380 if (!NILP (height)) 454 if (!NILP (height))
419 IMAGE_INSTANCE_WIDGET_FACE (ii), 493 IMAGE_INSTANCE_WIDGET_FACE (ii),
420 th, tw, th ? &ph : 0, tw ? &pw : 0); 494 th, tw, th ? &ph : 0, tw ? &pw : 0);
421 495
422 IMAGE_INSTANCE_SUBWINDOW_WIDTH (ii) = pw; 496 IMAGE_INSTANCE_SUBWINDOW_WIDTH (ii) = pw;
423 IMAGE_INSTANCE_SUBWINDOW_HEIGHT (ii) = ph; 497 IMAGE_INSTANCE_SUBWINDOW_HEIGHT (ii) = ph;
498 #ifdef DEBUG_WIDGETS
499 debug_widget_instances++;
500 stderr_out ("instantiated ");
501 debug_print (instantiator);
502 stderr_out ("%d widgets instantiated\n", debug_widget_instances);
503 #endif
424 } 504 }
425 505
426 static void 506 static void
427 widget_instantiate (Lisp_Object image_instance, Lisp_Object instantiator, 507 widget_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
428 Lisp_Object pointer_fg, Lisp_Object pointer_bg, 508 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
430 { 510 {
431 widget_instantiate_1 (image_instance, instantiator, pointer_fg, 511 widget_instantiate_1 (image_instance, instantiator, pointer_fg,
432 pointer_bg, dest_mask, domain, 1, 0, 0); 512 pointer_bg, dest_mask, domain, 1, 0, 0);
433 } 513 }
434 514
435 /* combo-box generic instantiation - get he heigh right */ 515 /* tree-view generic instantiation - get the height right */
436 static void 516 static void
437 combo_box_instantiate (Lisp_Object image_instance, Lisp_Object instantiator, 517 tree_view_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
438 Lisp_Object pointer_fg, Lisp_Object pointer_bg, 518 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
439 int dest_mask, Lisp_Object domain) 519 int dest_mask, Lisp_Object domain)
440 { 520 {
441 Lisp_Object data = Fplist_get (find_keyword_in_vector (instantiator, Q_properties), 521 Lisp_Object data = Fplist_get (find_keyword_in_vector (instantiator, Q_properties),
442 Q_items, Qnil); 522 Q_items, Qnil);
443 int len; 523 int len;
444 GET_LIST_LENGTH (data, len); 524 GET_LIST_LENGTH (data, len);
481 widget_instantiate_1 (image_instance, instantiator, pointer_fg, 561 widget_instantiate_1 (image_instance, instantiator, pointer_fg,
482 pointer_bg, dest_mask, domain, 0, 4, 0); 562 pointer_bg, dest_mask, domain, 0, 4, 0);
483 } 563 }
484 564
485 565
566 /*****************************************************************************
567 * widget layout *
568 *****************************************************************************/
569 static int
570 layout_possible_dest_types (void)
571 {
572 return IMAGE_LAYOUT_MASK;
573 }
574
575 /* we need to convert things like glyphs to images, eval expressions
576 etc.*/
577 static Lisp_Object
578 layout_normalize (Lisp_Object inst, Lisp_Object console_type)
579 {
580 /* This function can call lisp */
581 Lisp_Object items = find_keyword_in_vector (inst, Q_items);
582 Lisp_Object border = find_keyword_in_vector (inst, Q_border);
583 /* we need to eval glyph if its an expression, we do this for the
584 same reasons we normalize file to data. */
585 if (!NILP (items))
586 {
587 Lisp_Object rest;
588 LIST_LOOP (rest, items)
589 {
590 /* substitute the new glyph */
591 Fsetcar (rest, glyph_instantiator_to_glyph (XCAR (rest)));
592 }
593 }
594 /* normalize the border spec. */
595 if (VECTORP (border) || CONSP (border))
596 {
597 substitute_keyword_value (inst, Q_border, glyph_instantiator_to_glyph (border));
598 }
599 return inst;
600 }
601
602 /* Instantiate a layout widget. */
603 static void
604 layout_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
605 Lisp_Object pointer_fg, Lisp_Object pointer_bg,
606 int dest_mask, Lisp_Object domain)
607 {
608 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
609 Lisp_Object rest, device = IMAGE_INSTANCE_DEVICE (ii);
610 Lisp_Object frame = FW_FRAME (domain);
611 Lisp_Object items = find_keyword_in_vector (instantiator, Q_items);
612 Lisp_Object width = find_keyword_in_vector (instantiator, Q_pixel_width);
613 Lisp_Object height = find_keyword_in_vector (instantiator, Q_pixel_height);
614 Lisp_Object orient = find_keyword_in_vector (instantiator, Q_orientation);
615 Lisp_Object justify = find_keyword_in_vector (instantiator, Q_justify);
616 Lisp_Object border = find_keyword_in_vector (instantiator, Q_border);
617 Lisp_Object children = Qnil;
618 int pw = 0, ph = 0, x, y, maxph = 0, maxpw = 0, nitems = 0,
619 horiz_spacing, vert_spacing, ph_adjust = 0;
620
621 if (NILP (frame))
622 signal_simple_error ("No selected frame", device);
623
624 if (!(dest_mask & IMAGE_LAYOUT_MASK))
625 incompatible_image_types (instantiator, dest_mask, IMAGE_LAYOUT_MASK);
626
627 if (NILP (orient))
628 orient = Qvertical;
629
630 if (EQ (border, Qt))
631 border = Qetched_in;
632
633 ii->data = 0;
634 IMAGE_INSTANCE_TYPE (ii) = IMAGE_LAYOUT;
635 IMAGE_INSTANCE_SUBWINDOW_ID (ii) = 0;
636 IMAGE_INSTANCE_SUBWINDOW_DISPLAYEDP (ii) = 0;
637 IMAGE_INSTANCE_SUBWINDOW_FRAME (ii) = frame;
638 IMAGE_INSTANCE_LAYOUT_BORDER (ii) = border;
639
640 /* normalize size information */
641 if (!NILP (width))
642 pw = XINT (width);
643 if (!NILP (height))
644 ph = XINT (height);
645
646 /* flip through the items to work out how much stuff we have to display */
647 LIST_LOOP (rest, items)
648 {
649 Lisp_Object glyph = XCAR (rest);
650 int gheight = glyph_height (glyph, Qnil, DEFAULT_INDEX, domain);
651 int gwidth = glyph_width (glyph, Qnil, DEFAULT_INDEX, domain);
652 nitems ++;
653 if (EQ (orient, Qhorizontal))
654 {
655 maxph = max (maxph, gheight);
656 maxpw += gwidth;
657 }
658 else if (EQ (orient, Qvertical))
659 {
660 maxpw = max (maxpw, gwidth);
661 maxph += gheight;
662 }
663 }
664
665 /* work out spacing between items and bounds of the layout */
666 if (!pw)
667 {
668 /* No user provided width so we just do default spacing. */
669 horiz_spacing = WIDGET_BORDER_WIDTH * 2;
670 if (EQ (orient, Qhorizontal))
671 pw = maxpw + (nitems + 1) * horiz_spacing;
672 else
673 pw = maxpw + 2 * horiz_spacing;
674 }
675 else if (pw < maxpw)
676 /* The user wants a smaller space than the largest item, so we
677 just provide default spacing and will let the output routines
678 clip.. */
679 horiz_spacing = WIDGET_BORDER_WIDTH * 2;
680 else if (EQ (orient, Qhorizontal))
681 /* We have a larger area to display in so distribute the space
682 evenly. */
683 horiz_spacing = (pw - maxpw) / (nitems + 1);
684 else
685 horiz_spacing = (pw - maxpw) / 2;
686
687 /* Do the border now so that we can adjust the layout. */
688 if (GLYPHP (border))
689 {
690 /* We are going to be sneaky here and add the border text as
691 just another child, the layout and output routines don't know
692 this and will just display at the offsets we prescribe. */
693 Lisp_Object bglyph = glyph_image_instance (border, domain, ERROR_ME, 1);
694
695 children = Fcons (bglyph, children);
696 XIMAGE_INSTANCE_XOFFSET (bglyph) = 10; /* Really, what should this be? */
697 XIMAGE_INSTANCE_YOFFSET (bglyph) = 0;
698
699 ph_adjust = (glyph_height (border, Qnil, DEFAULT_INDEX, domain) / 2);
700 IMAGE_INSTANCE_LAYOUT_BORDER (ii) = make_int (ph_adjust);
701 }
702
703 /* Work out vertical spacings. */
704 if (!ph)
705 {
706 vert_spacing = WIDGET_BORDER_HEIGHT * 2;
707 if (EQ (orient, Qvertical))
708 ph = maxph + (nitems + 1) * vert_spacing + ph_adjust;
709 else
710 ph = maxph + 2 * vert_spacing + ph_adjust;
711 }
712 else if (ph < maxph)
713 vert_spacing = WIDGET_BORDER_HEIGHT * 2;
714 else if (EQ (orient, Qvertical))
715 vert_spacing = (ph - (maxph + ph_adjust)) / (nitems + 1);
716 else
717 vert_spacing = (ph - (maxph + ph_adjust)) / 2;
718
719 y = vert_spacing + ph_adjust;
720 x = horiz_spacing;
721
722 /* Now flip through putting items where we want them, paying
723 attention to justification. */
724 LIST_LOOP (rest, items)
725 {
726 /* make sure the image is instantiated */
727 Lisp_Object glyph = XCAR (rest);
728 Lisp_Object gii = glyph_image_instance (glyph, domain, ERROR_ME, 1);
729 int gwidth = glyph_width (glyph, Qnil, DEFAULT_INDEX, domain);
730 int gheight = glyph_height (glyph, Qnil, DEFAULT_INDEX, domain);
731
732 children = Fcons (gii, children);
733
734 if (EQ (orient, Qhorizontal))
735 {
736 if (EQ (justify, Qright))
737 y = ph - (gheight + vert_spacing);
738 else if (EQ (justify, Qcenter))
739 y = (ph - gheight) / 2;
740 }
741 else if (EQ (orient, Qvertical))
742 {
743 if (EQ (justify, Qright))
744 x = pw - (gwidth + horiz_spacing);
745 else if (EQ (justify, Qcenter))
746 x = (pw - gwidth) / 2;
747 }
748
749 XIMAGE_INSTANCE_XOFFSET (gii) = x;
750 XIMAGE_INSTANCE_YOFFSET (gii) = y;
751
752 if (EQ (orient, Qhorizontal))
753 {
754 x += (gwidth + horiz_spacing);
755 }
756 else if (EQ (orient, Qvertical))
757 {
758 y += (gheight + vert_spacing);
759 }
760 }
761
762 IMAGE_INSTANCE_LAYOUT_CHILDREN (ii) = children;
763 assert (pw && ph);
764 IMAGE_INSTANCE_SUBWINDOW_WIDTH (ii) = pw;
765 IMAGE_INSTANCE_SUBWINDOW_HEIGHT (ii) = ph;
766 }
767
768
486 /************************************************************************/ 769 /************************************************************************/
487 /* initialization */ 770 /* initialization */
488 /************************************************************************/ 771 /************************************************************************/
489 772
490 void 773 void
496 defkeyword (&Q_properties, ":properties"); 779 defkeyword (&Q_properties, ":properties");
497 defkeyword (&Q_items, ":items"); 780 defkeyword (&Q_items, ":items");
498 defkeyword (&Q_image, ":image"); 781 defkeyword (&Q_image, ":image");
499 defkeyword (&Q_percent, ":percent"); 782 defkeyword (&Q_percent, ":percent");
500 defkeyword (&Q_text, ":text"); 783 defkeyword (&Q_text, ":text");
784 defkeyword (&Q_orientation, ":orientation");
785 defkeyword (&Q_justify, ":justify");
786 defkeyword (&Q_border, ":border");
787
788 defsymbol (&Qetched_in, "etched-in");
789 defsymbol (&Qetched_out, "etched-out");
790 defsymbol (&Qbevel_in, "bevel-in");
791 defsymbol (&Qbevel_out, "bevel-out");
501 } 792 }
502 793
503 void 794 void
504 image_instantiator_format_create_glyphs_widget (void) 795 image_instantiator_format_create_glyphs_widget (void)
505 { 796 {
534 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (button, "button"); 825 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (button, "button");
535 IIFORMAT_HAS_SHARED_METHOD (button, validate, widget); 826 IIFORMAT_HAS_SHARED_METHOD (button, validate, widget);
536 IIFORMAT_HAS_SHARED_METHOD (button, possible_dest_types, widget); 827 IIFORMAT_HAS_SHARED_METHOD (button, possible_dest_types, widget);
537 IIFORMAT_HAS_SHARED_METHOD (button, instantiate, widget); 828 IIFORMAT_HAS_SHARED_METHOD (button, instantiate, widget);
538 IIFORMAT_HAS_SHARED_METHOD (button, normalize, widget); 829 IIFORMAT_HAS_SHARED_METHOD (button, normalize, widget);
539 IIFORMAT_VALID_KEYWORD (button, Q_image, check_valid_glyph_or_image); 830 IIFORMAT_VALID_KEYWORD (button,
831 Q_image, check_valid_glyph_or_instantiator);
540 VALID_WIDGET_KEYWORDS (button); 832 VALID_WIDGET_KEYWORDS (button);
541 VALID_GUI_KEYWORDS (button); 833 VALID_GUI_KEYWORDS (button);
542 834
543 /* edit fields */ 835 /* edit fields */
544 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (edit_field, "edit-field"); 836 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (edit_field, "edit-field");
550 842
551 /* combo box */ 843 /* combo box */
552 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (combo_box, "combo-box"); 844 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (combo_box, "combo-box");
553 IIFORMAT_HAS_METHOD (combo_box, validate); 845 IIFORMAT_HAS_METHOD (combo_box, validate);
554 IIFORMAT_HAS_SHARED_METHOD (combo_box, possible_dest_types, widget); 846 IIFORMAT_HAS_SHARED_METHOD (combo_box, possible_dest_types, widget);
555 IIFORMAT_HAS_METHOD (combo_box, instantiate);
556 VALID_GUI_KEYWORDS (combo_box); 847 VALID_GUI_KEYWORDS (combo_box);
557 848
558 IIFORMAT_VALID_KEYWORD (combo_box, Q_width, check_valid_int); 849 IIFORMAT_VALID_KEYWORD (combo_box, Q_width, check_valid_int);
559 IIFORMAT_VALID_KEYWORD (combo_box, Q_height, check_valid_int); 850 IIFORMAT_VALID_KEYWORD (combo_box, Q_height, check_valid_int);
560 IIFORMAT_VALID_KEYWORD (combo_box, Q_pixel_width, check_valid_int); 851 IIFORMAT_VALID_KEYWORD (combo_box, Q_pixel_width, check_valid_int);
574 865
575 /* progress guage */ 866 /* progress guage */
576 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (progress_gauge, "progress-gauge"); 867 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (progress_gauge, "progress-gauge");
577 IIFORMAT_HAS_SHARED_METHOD (progress_gauge, validate, widget); 868 IIFORMAT_HAS_SHARED_METHOD (progress_gauge, validate, widget);
578 IIFORMAT_HAS_SHARED_METHOD (progress_gauge, possible_dest_types, widget); 869 IIFORMAT_HAS_SHARED_METHOD (progress_gauge, possible_dest_types, widget);
579 IIFORMAT_HAS_SHARED_METHOD (progress_gauge, instantiate, combo_box); 870 IIFORMAT_HAS_SHARED_METHOD (progress_gauge, instantiate, widget);
580 VALID_WIDGET_KEYWORDS (progress_gauge); 871 VALID_WIDGET_KEYWORDS (progress_gauge);
581 VALID_GUI_KEYWORDS (progress_gauge); 872 VALID_GUI_KEYWORDS (progress_gauge);
582 873
583 /* tree view */ 874 /* tree view */
584 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (tree_view, "tree-view"); 875 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (tree_view, "tree-view");
585 IIFORMAT_HAS_SHARED_METHOD (tree_view, validate, combo_box); 876 IIFORMAT_HAS_SHARED_METHOD (tree_view, validate, combo_box);
586 IIFORMAT_HAS_SHARED_METHOD (tree_view, possible_dest_types, widget); 877 IIFORMAT_HAS_SHARED_METHOD (tree_view, possible_dest_types, widget);
587 IIFORMAT_HAS_SHARED_METHOD (tree_view, instantiate, combo_box); 878 IIFORMAT_HAS_METHOD (tree_view, instantiate);
588 VALID_WIDGET_KEYWORDS (tree_view); 879 VALID_WIDGET_KEYWORDS (tree_view);
589 VALID_GUI_KEYWORDS (tree_view); 880 VALID_GUI_KEYWORDS (tree_view);
590 IIFORMAT_VALID_KEYWORD (tree_view, Q_properties, check_valid_item_list); 881 IIFORMAT_VALID_KEYWORD (tree_view, Q_properties, check_valid_item_list);
591 882
592 /* tab control */ 883 /* tab control */
603 IIFORMAT_HAS_SHARED_METHOD (label, possible_dest_types, widget); 894 IIFORMAT_HAS_SHARED_METHOD (label, possible_dest_types, widget);
604 IIFORMAT_HAS_SHARED_METHOD (label, instantiate, static); 895 IIFORMAT_HAS_SHARED_METHOD (label, instantiate, static);
605 VALID_WIDGET_KEYWORDS (label); 896 VALID_WIDGET_KEYWORDS (label);
606 IIFORMAT_VALID_KEYWORD (label, Q_descriptor, check_valid_string); 897 IIFORMAT_VALID_KEYWORD (label, Q_descriptor, check_valid_string);
607 898
608 #if 0 899 /* layout */
609 /* group */ 900 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (layout, "layout");
610 INITIALIZE_IMAGE_INSTANTIATOR_FORMAT (group, "group"); 901 IIFORMAT_HAS_METHOD (layout, possible_dest_types);
611 IIFORMAT_HAS_SHARED_METHOD (group, possible_dest_types, widget); 902 IIFORMAT_HAS_METHOD (layout, instantiate);
612 IIFORMAT_HAS_METHOD (group, instantiate); 903 IIFORMAT_HAS_METHOD (layout, normalize);
613 904 IIFORMAT_VALID_KEYWORD (layout, Q_pixel_width, check_valid_int);
614 IIFORMAT_VALID_KEYWORD (group, Q_width, check_valid_int); 905 IIFORMAT_VALID_KEYWORD (layout, Q_pixel_height, check_valid_int);
615 IIFORMAT_VALID_KEYWORD (group, Q_height, check_valid_int); 906 IIFORMAT_VALID_KEYWORD (layout, Q_orientation, check_valid_orientation);
616 IIFORMAT_VALID_KEYWORD (group, Q_pixel_width, check_valid_int); 907 IIFORMAT_VALID_KEYWORD (layout, Q_justify, check_valid_justification);
617 IIFORMAT_VALID_KEYWORD (group, Q_pixel_height, check_valid_int); 908 IIFORMAT_VALID_KEYWORD (layout, Q_border, check_valid_border);
618 IIFORMAT_VALID_KEYWORD (group, Q_face, check_valid_face); 909 IIFORMAT_VALID_KEYWORD (layout, Q_items,
619 IIFORMAT_VALID_KEYWORD (group, Q_background, check_valid_string); 910 check_valid_glyph_or_instantiator_list);
620 IIFORMAT_VALID_KEYWORD (group, Q_descriptor, check_valid_string); 911 }
912
913 void
914 reinit_vars_of_glyphs_widget (void)
915 {
916 #ifdef DEBUG_WIDGETS
917 debug_widget_instances = 0;
621 #endif 918 #endif
622 } 919 }
623 920
624 void 921 void
625 vars_of_glyphs_widget (void) 922 vars_of_glyphs_widget (void)
626 { 923 {
627 } 924 reinit_vars_of_glyphs_widget ();
925 }