+}
+
+/* Query for a widgets desired geometry. If no type specific method is
+ provided then use the widget text to calculate sizes. */
+static void
+widget_query_geometry (Lisp_Object image_instance,
+ int* width, int* height,
+ enum image_instance_geometry disp, Lisp_Object domain)
+{
+ Lisp_Image_Instance* ii = XIMAGE_INSTANCE (image_instance);
+ struct image_instantiator_methods* meths;
+ Lisp_Object dynamic_width = Qnil;
+ Lisp_Object dynamic_height = Qnil;
+
+ /* First just set up what we already have. */
+ if (width) *width = IMAGE_INSTANCE_WIDTH (ii);
+ if (height) *height = IMAGE_INSTANCE_HEIGHT (ii);
+
+ if (IMAGE_INSTANCE_SUBWINDOW_V_RESIZEP (ii)
+ ||
+ IMAGE_INSTANCE_SUBWINDOW_H_RESIZEP (ii))
+ {
+ /* .. then try device specific methods ... */
+ meths = decode_device_ii_format (image_instance_device (image_instance),
+ IMAGE_INSTANCE_WIDGET_TYPE (ii),
+ ERROR_ME_NOT);
+ if (meths && HAS_IIFORMAT_METH_P (meths, query_geometry))
+ IIFORMAT_METH (meths, query_geometry, (image_instance,
+ width, height, disp,
+ domain));
+ else
+ {
+ /* ... then format specific methods ... */
+ meths = decode_device_ii_format (Qnil, IMAGE_INSTANCE_WIDGET_TYPE (ii),
+ ERROR_ME_NOT);
+ if (meths && HAS_IIFORMAT_METH_P (meths, query_geometry))
+ IIFORMAT_METH (meths, query_geometry, (image_instance,
+ width, height, disp,
+ domain));
+ else
+ {
+ int w, h;
+
+ /* Then if we are allowed to resize the widget, make the
+ size the same as the text dimensions. */
+ query_string_geometry (IMAGE_INSTANCE_WIDGET_TEXT (ii),
+ IMAGE_INSTANCE_WIDGET_FACE (ii),
+ &w, &h, 0, domain);
+ /* Adjust the size for borders. */
+ if (IMAGE_INSTANCE_SUBWINDOW_H_RESIZEP (ii))
+ *width = w + 2 * WIDGET_BORDER_WIDTH;
+ if (IMAGE_INSTANCE_SUBWINDOW_V_RESIZEP (ii))
+ *height = h + 2 * WIDGET_BORDER_HEIGHT;
+ }
+ }
+ /* Finish off with dynamic sizing. */
+ if (!NILP (IMAGE_INSTANCE_WIDGET_WIDTH_SUBR (ii)))
+ {
+ dynamic_width = Feval (IMAGE_INSTANCE_WIDGET_WIDTH_SUBR (ii));
+ if (INTP (dynamic_width))
+ *width = XINT (dynamic_width);
+ }
+ if (!NILP (IMAGE_INSTANCE_WIDGET_HEIGHT_SUBR (ii)))
+ {
+ dynamic_height = Feval (IMAGE_INSTANCE_WIDGET_HEIGHT_SUBR (ii));
+ if (INTP (dynamic_height))
+ *height = XINT (dynamic_height);
+ }
+ }
+}
+
+static int
+widget_layout (Lisp_Object image_instance,
+ int width, int height, int xoffset, int yoffset,
+ Lisp_Object domain)
+{
+ Lisp_Image_Instance* ii = XIMAGE_INSTANCE (image_instance);
+ struct image_instantiator_methods* meths;
+
+ /* .. then try device specific methods ... */
+ meths = decode_device_ii_format (image_instance_device (image_instance),
+ IMAGE_INSTANCE_WIDGET_TYPE (ii),