+ Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance);
+ Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii), pixel;
+ struct device* d = XDEVICE (device);
+ Lisp_Object frame = DOMAIN_FRAME (domain);
+ struct frame* f = XFRAME (frame);
+ char* nm=0;
+ Widget wid;
+ Arg al [32];
+ int ac = 0;
+ int id = new_lwlib_id ();
+ widget_value* clip_wv;
+ XColor fcolor, bcolor;
+
+ if (!DEVICE_X_P (d))
+ signal_simple_error ("Not an X device", device);
+
+ /* have to set the type this late in case there is no device
+ instantiation for a widget. But we can go ahead and do it without
+ checking because there is always a generic instantiator. */
+ IMAGE_INSTANCE_TYPE (ii) = IMAGE_WIDGET;
+
+ if (!NILP (IMAGE_INSTANCE_WIDGET_TEXT (ii)))
+ TO_EXTERNAL_FORMAT (LISP_STRING, IMAGE_INSTANCE_WIDGET_TEXT (ii),
+ C_STRING_ALLOCA, nm,
+ Qnative);
+
+ ii->data = xnew_and_zero (struct x_subwindow_data);
+
+ /* Create a clip window to contain the subwidget. Incredibly the
+ XEmacs manager seems to be the most appropriate widget for
+ this. Nothing else is simple enough and yet does what is
+ required. */
+ clip_wv = xmalloc_widget_value ();
+
+ lw_add_widget_value_arg (clip_wv, XtNresize, False);
+ lw_add_widget_value_arg (clip_wv, XtNwidth,
+ (Dimension)IMAGE_INSTANCE_WIDTH (ii));
+ lw_add_widget_value_arg (clip_wv, XtNheight,
+ (Dimension)IMAGE_INSTANCE_HEIGHT (ii));
+ clip_wv->enabled = True;
+
+ clip_wv->name = xstrdup ("clip-window");
+ clip_wv->value = xstrdup ("clip-window");
+
+ IMAGE_INSTANCE_X_CLIPWIDGET (ii)
+ = lw_create_widget ("clip-window", "clip-window", new_lwlib_id (),
+ clip_wv, FRAME_X_CONTAINER_WIDGET (f),
+ False, 0, 0, 0);
+
+ free_widget_value_tree (clip_wv);
+
+ /* copy any args we were given */
+ ac = 0;
+ lw_add_value_args_to_args (wv, al, &ac);
+
+ /* Fixup the colors. We have to do this *before* the widget gets
+ created so that Motif will fix up the shadow colors
+ correctly. Once the widget is created Motif won't do this
+ anymore...*/
+ pixel = FACE_FOREGROUND
+ (IMAGE_INSTANCE_WIDGET_FACE (ii),
+ IMAGE_INSTANCE_FRAME (ii));
+ fcolor = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (pixel));
+
+ pixel = FACE_BACKGROUND
+ (IMAGE_INSTANCE_WIDGET_FACE (ii),
+ IMAGE_INSTANCE_FRAME (ii));
+ bcolor = COLOR_INSTANCE_X_COLOR (XCOLOR_INSTANCE (pixel));
+
+ lw_add_widget_value_arg (wv, XtNbackground, bcolor.pixel);
+ lw_add_widget_value_arg (wv, XtNforeground, fcolor.pixel);
+ /* we cannot allow widgets to resize themselves */
+ lw_add_widget_value_arg (wv, XtNresize, False);
+ lw_add_widget_value_arg (wv, XtNwidth,
+ (Dimension)IMAGE_INSTANCE_WIDTH (ii));
+ lw_add_widget_value_arg (wv, XtNheight,
+ (Dimension)IMAGE_INSTANCE_HEIGHT (ii));
+ /* update the font. */
+ update_widget_face (wv, ii, domain);
+
+ wid = lw_create_widget (type, wv->name, id, wv, IMAGE_INSTANCE_X_CLIPWIDGET (ii),
+ False, 0, popup_selection_callback, 0);
+
+ IMAGE_INSTANCE_SUBWINDOW_ID (ii) = (void*)wid;
+ IMAGE_INSTANCE_X_WIDGET_LWID (ii) = id;
+ /* because the EmacsManager is the widgets parent we have to
+ offset the redisplay of the widget by the amount the text
+ widget is inside the manager. */
+ ac = 0;
+ XtSetArg (al [ac], XtNx, &IMAGE_INSTANCE_X_WIDGET_XOFFSET (ii)); ac++;
+ XtSetArg (al [ac], XtNy, &IMAGE_INSTANCE_X_WIDGET_YOFFSET (ii)); ac++;
+ XtGetValues (FRAME_X_TEXT_WIDGET (f), al, ac);
+
+ XtSetMappedWhenManaged (wid, TRUE);
+
+ free_widget_value_tree (wv);
+ /* A kludgy but simple way to make sure the callback for a widget
+ doesn't get deleted. */
+ gcpro_popup_callbacks (id);