+static void
+layout_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
+ Lisp_Object pointer_fg, Lisp_Object pointer_bg,
+ int dest_mask, Lisp_Object domain)
+{
+ Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
+ Lisp_Object orient = find_keyword_in_vector (instantiator, Q_orientation);
+ Lisp_Object border = find_keyword_in_vector (instantiator, Q_border);
+
+ /* Do widget type instantiation first. */
+ widget_instantiate (image_instance, instantiator, pointer_fg, pointer_bg,
+ dest_mask, domain);
+
+ if (NILP (orient))
+ {
+ IMAGE_INSTANCE_SUBWINDOW_ORIENT (ii) = LAYOUT_VERTICAL;
+ }
+
+ if (EQ (border, Qt))
+ {
+ IMAGE_INSTANCE_LAYOUT_BORDER (ii) = Qetched_in;
+ }
+ else
+ {
+ IMAGE_INSTANCE_LAYOUT_BORDER (ii) = border;
+ }
+ /* We don't do the children yet as we might not have a containing
+ window. */
+}
+
+static void
+layout_post_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
+ Lisp_Object domain)
+{
+ Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
+ Lisp_Object items = find_keyword_in_vector (instantiator, Q_items);
+ Lisp_Object rest, children = Qnil;
+
+ if (GLYPHP (IMAGE_INSTANCE_LAYOUT_BORDER (ii)))
+ {
+ /* We are going to be sneaky here and add the border text as
+ just another child, the layout and output routines don't know
+ this and will just display at the offsets we prescribe. */
+ Lisp_Object gii = glyph_image_instance
+ (IMAGE_INSTANCE_LAYOUT_BORDER (ii),
+ image_instance, ERROR_ME, 1);
+
+ if (!IMAGE_INSTANCEP (gii))
+ return;
+ /* make sure we are designated as the parent. */
+ XIMAGE_INSTANCE_PARENT (gii) = image_instance;
+ children = Fcons (gii, children);
+ IMAGE_INSTANCE_LAYOUT_BORDER (ii) = make_int (0);
+ }
+
+ /* Pick up the sub-widgets. */
+ LIST_LOOP (rest, items)
+ {
+ /* make sure the image is instantiated */
+ Lisp_Object gii = glyph_image_instance (XCAR (rest),
+ image_instance, ERROR_ME, 1);
+ if (!IMAGE_INSTANCEP (gii))
+ return;
+ /* make sure we are designated as the parent. */
+ XIMAGE_INSTANCE_PARENT (gii) = image_instance;
+ children = Fcons (gii, children);
+ }
+ /* Make sure elements in the layout are in the order the
+ user expected. */
+ children = Fnreverse (children);
+ IMAGE_INSTANCE_LAYOUT_CHILDREN (ii) = children;
+}
+