Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gnumeric/ChangeLog,v
retrieving revision 1.3659
diff -u -w -r1.3659 ChangeLog
--- ChangeLog	13 Nov 2004 20:34:48 -0000	1.3659
+++ ChangeLog	14 Nov 2004 06:35:43 -0000
@@ -1,3 +1,12 @@
+2004-11-14  Jody Goldberg <jody@gnome.org>
+
+	* src/sheet-object-image.c (sheet_object_image_set_image) : renamed
+	  from sheet_object_image_new to make the life cycle simpler for
+	  importers.
+	(soi_get_pixbuf) : No data == no pixbuf
+	* src/wbcg-actions.c (cb_insert_image) : adjust to the name and
+	  semantic change of sheet_object_image_set_image.
+
 2004-11-13  Francisco Javier F. Serrador  <serrador@cvs.gnome.org>
 
 	* src/dialogs/dialog-preferences.c: Fixed typo
Index: plugins/excel/ChangeLog
===================================================================
RCS file: /cvs/gnome/gnumeric/plugins/excel/ChangeLog,v
retrieving revision 1.897
diff -u -w -r1.897 ChangeLog
--- plugins/excel/ChangeLog	7 Nov 2004 07:32:02 -0000	1.897
+++ plugins/excel/ChangeLog	14 Nov 2004 06:35:46 -0000
@@ -1,3 +1,13 @@
+2004-11-13  Jody Goldberg <jody@gnome.org>
+
+	* ms-excel-read.c (ms_sheet_realize_obj) : We have a clear separation
+	  between create and realize now, we should use it.  This routine sets
+	  the content.
+	(ms_sheet_create_obj) : this one creates objects for use later.
+	  I am not entire happy with this split.  It no longer feels
+	  necessary but it is much too close to release to contemplate
+	  cleaning it up.
+
 2004-11-07  Jody Goldberg <jody@gnome.org>
 
 	* Release 1.3.93
Index: plugins/excel/ms-excel-read.c
===================================================================
RCS file: /cvs/gnome/gnumeric/plugins/excel/ms-excel-read.c,v
retrieving revision 1.624
diff -u -w -r1.624 ms-excel-read.c
--- plugins/excel/ms-excel-read.c	1 Nov 2004 22:25:31 -0000	1.624
+++ plugins/excel/ms-excel-read.c	14 Nov 2004 06:35:48 -0000
@@ -245,44 +245,6 @@
 	return RGBA_TO_UINT (r,g,b,0xff);
 }
 
-static SheetObject *
-ms_sheet_create_image (MSObj *obj, MSEscherBlip *blip)
-{
-	SheetObject *so;
-	MSObjAttr *crop_left_attr = ms_obj_attr_bag_lookup
-		(obj->attrs, MS_OBJ_ATTR_BLIP_CROP_LEFT);
-	MSObjAttr *crop_top_attr = ms_obj_attr_bag_lookup
-		(obj->attrs, MS_OBJ_ATTR_BLIP_CROP_TOP);
-	MSObjAttr *crop_right_attr = ms_obj_attr_bag_lookup
-		(obj->attrs, MS_OBJ_ATTR_BLIP_CROP_RIGHT);
-	MSObjAttr *crop_bottom_attr = ms_obj_attr_bag_lookup
-		(obj->attrs, MS_OBJ_ATTR_BLIP_CROP_BOTTOM);
-	double crop_left_val = 0.0;
-	double crop_top_val = 0.0;
-	double crop_right_val = 0.0;
-	double crop_bottom_val = 0.0;
-
-	so = sheet_object_image_new (blip->type, blip->data, blip->data_len,
-				     !blip->needs_free);
-
-	if (!so)
-		return NULL;
-
-	if (crop_left_attr)
-		crop_left_val   = (double) crop_left_attr->v.v_uint / 65536.;
-	if (crop_top_attr)
-		crop_top_val    = (double) crop_top_attr->v.v_uint / 65536.;
-	if (crop_right_attr)
-		crop_right_val  = (double) crop_right_attr->v.v_uint / 65536.;
-	if (crop_bottom_attr)
-		crop_bottom_val = (double) crop_bottom_attr->v.v_uint / 65536.;
-	sheet_object_image_set_crop (SHEET_OBJECT_IMAGE (so),
-				     crop_left_val, crop_top_val,
-				     crop_right_val, crop_bottom_val);
-
-	return so;
-}
-
 /**
  * ms_sheet_obj_anchor_to_pos:
  * @points	Array which receives anchor coordinates in points
@@ -465,24 +427,37 @@
 		break;
 
 	case 0x08: { /* Picture */
-		MSObjAttr *blip_id = ms_obj_attr_bag_lookup (obj->attrs,
-			MS_OBJ_ATTR_BLIP_ID);
+		double crop_left = 0.0;
+		double crop_top  = 0.0;
+		double crop_right = 0.0;
+		double crop_bottom = 0.0;
 
-		if (blip_id != NULL) {
+		if ((attr = ms_obj_attr_bag_lookup (obj->attrs,
+			MS_OBJ_ATTR_BLIP_ID)) != NULL) {
 			MSEscherBlip *blip = ms_container_get_blip (container,
-				blip_id->v.v_uint - 1);
+				attr->v.v_uint - 1);
 			if (blip != NULL) {
-				so = ms_sheet_create_image (obj, blip);
+				sheet_object_image_set_image (SHEET_OBJECT_IMAGE (so),
+					blip->type, blip->data, blip->data_len,
+					!blip->needs_free);
 				blip->needs_free = FALSE; /* image took over managing data */
 			}
 		}
+		if ((attr = ms_obj_attr_bag_lookup (obj->attrs,
+		     MS_OBJ_ATTR_BLIP_CROP_LEFT)) != NULL)
+			crop_left   = (double) attr->v.v_uint / 65536.;
+		if ((attr = ms_obj_attr_bag_lookup (obj->attrs,
+		     MS_OBJ_ATTR_BLIP_CROP_RIGHT)) != NULL)
+			crop_right  = (double) attr->v.v_uint / 65536.;
+		if ((attr = ms_obj_attr_bag_lookup (obj->attrs,
+		     MS_OBJ_ATTR_BLIP_CROP_TOP)) != NULL)
+			crop_top     = (double) attr->v.v_uint / 65536.;
+		if ((attr = ms_obj_attr_bag_lookup (obj->attrs,
+		     MS_OBJ_ATTR_BLIP_CROP_BOTTOM)) != NULL)
+			crop_bottom = (double) attr->v.v_uint / 65536.;
 
-		/* replace blips we don't know how to handle with rectangles */
-		if (so == NULL)
-			so = g_object_new (GNM_SO_FILLED_TYPE, NULL);  /* placeholder */
-
-#warning "Why do we create these here only to get rid of them?"
-		g_object_unref (so);
+		sheet_object_image_set_crop (SHEET_OBJECT_IMAGE (so),
+			crop_left, crop_top, crop_right, crop_bottom);
 		break;
 	}
 
@@ -570,24 +545,8 @@
 	/* Button */
 	case 0x07: so = g_object_new (sheet_widget_button_get_type (), NULL);
 		break;
-	case 0x08: { /* Picture */
-		MSObjAttr *blip_id = ms_obj_attr_bag_lookup (obj->attrs,
-			MS_OBJ_ATTR_BLIP_ID);
-
-		if (blip_id != NULL) {
-			MSEscherBlip *blip = ms_container_get_blip (container,
-				blip_id->v.v_uint - 1);
-			if (blip != NULL) {
-				so = ms_sheet_create_image (obj, blip);
-				blip->needs_free = FALSE; /* image took over managing data */
-			}
-		}
-
-		/* replace blips we don't know how to handle with rectangles */
-		if (so == NULL)
-			so = g_object_new (GNM_SO_FILLED_TYPE, NULL);  /* placeholder */
+	case 0x08: so = g_object_new (SHEET_OBJECT_IMAGE_TYPE, NULL); /* Picture */
 		break;
-	}
 	case 0x09: so = g_object_new (GNM_SO_POLYGON_TYPE, NULL);
 		break;
 	case 0x0B: so = g_object_new (sheet_widget_checkbox_get_type (), NULL);
Index: src/sheet-object-image.c
===================================================================
RCS file: /cvs/gnome/gnumeric/src/sheet-object-image.c,v
retrieving revision 1.47
diff -u -w -r1.47 sheet-object-image.c
--- src/sheet-object-image.c	17 Oct 2004 02:36:05 -0000	1.47
+++ src/sheet-object-image.c	14 Nov 2004 06:35:48 -0000
@@ -122,26 +122,29 @@
 };
 
 /**
- * sheet_object_image_new :
+ * sheet_object_image_set_image :
+ * @so : #SheetObjectImage
  * @type :
  * @data :
  * @data_len
  * @copy_data :
- */
-SheetObject *
-sheet_object_image_new (char const   *type,
+ *
+ * Assign raw data and type to @so assuming that it has not been initialized
+ * yet.
+ **/
+void
+sheet_object_image_set_image (SheetObjectImage *soi,
+			      char const   *type,
 			guint8       *data,
-			guint32	      data_len,
+			      unsigned      data_len,
 			gboolean      copy_data)
 {
-	SheetObjectImage *soi;
+	g_return_if_fail (IS_SHEET_OBJECT_IMAGE (soi));
+	g_return_if_fail (soi->bytes.data == NULL && soi->bytes.len == 0);
 
-	soi = g_object_new (SHEET_OBJECT_IMAGE_TYPE, NULL);
 	soi->type       = g_strdup (type);
 	soi->bytes.len  = data_len;
 	soi->bytes.data = copy_data ? g_memdup (data, data_len) : data;
-	
-	return SHEET_OBJECT (soi);
 }
 
 void
@@ -209,7 +212,7 @@
  * be sure to unref the result if it is non-NULL
  *
  * TODO : this is really overkill for now.
- * only wmf/emf will require regenerating the pixbug for different scale
+ * only wmf/emf will require regenerating the pixbuf for different scale
  * factors.  And even then we should cache them.
  */
 static GdkPixbuf *
@@ -226,6 +229,8 @@
 
 	data     = soi->bytes.data;
 	data_len = soi->bytes.len;
+	if (data == NULL || data_len == 0)
+		return pixbuf;
 
 	if (soi->type != NULL && !strcmp (soi->type, "wmf"))
 		loader = gdk_pixbuf_loader_new_with_type (soi->type, &err);
Index: src/sheet-object-image.h
===================================================================
RCS file: /cvs/gnome/gnumeric/src/sheet-object-image.h,v
retrieving revision 1.3
diff -u -w -r1.3 sheet-object-image.h
--- src/sheet-object-image.h	10 Sep 2002 21:32:32 -0000	1.3
+++ src/sheet-object-image.h	14 Nov 2004 06:35:48 -0000
@@ -10,9 +10,10 @@
 typedef struct _SheetObjectImage SheetObjectImage;
 
 GType	     sheet_object_image_get_type (void);
-SheetObject *sheet_object_image_new (char const   *type,
+void sheet_object_image_set_image (SheetObjectImage *soi,
+				   char const   *type,
 				     guint8       *data,
-				     guint32	   data_len,
+				   unsigned	 data_len,
 				     gboolean      copy_data);
 void sheet_object_image_set_crop (SheetObjectImage *soi,
 				  double crop_left,  double crop_top,
Index: src/sheet-object.c
===================================================================
RCS file: /cvs/gnome/gnumeric/src/sheet-object.c,v
retrieving revision 1.207
diff -u -w -r1.207 sheet-object.c
--- src/sheet-object.c	9 Oct 2004 09:26:23 -0000	1.207
+++ src/sheet-object.c	14 Nov 2004 06:35:48 -0000
@@ -294,6 +294,15 @@
 	return so->sheet;
 }
 
+static int
+cb_create_views (SheetObject *so)
+{
+	g_object_set_data (G_OBJECT (so), "create_view_handler", NULL);
+	SHEET_FOREACH_CONTROL (so->sheet, view, control,
+		sc_object_create_view (control, so););
+	sheet_object_update_bounds (so, NULL);
+	return FALSE;
+}
 
 /**
  * sheet_object_set_sheet :
@@ -321,13 +330,14 @@
 
 	g_object_ref (G_OBJECT (so));
 	sheet->sheet_objects = g_list_prepend (sheet->sheet_objects, so);
-	SHEET_FOREACH_CONTROL (so->sheet, view, control,
-		sc_object_create_view (control, so););
-	sheet_object_update_bounds (so, NULL);
-
 	/* FIXME : add a flag to sheet to have sheet_update do this */
 	sheet_objects_max_extent (sheet);
 
+	if (NULL == g_object_get_data (G_OBJECT (so), "create_view_handler")) {
+		guint id = g_idle_add ((GSourceFunc) cb_create_views, so);
+		g_object_set_data (G_OBJECT (so), "create_view_handler", GUINT_TO_POINTER (id));
+	}
+
 	return FALSE;
 }
 
@@ -344,12 +354,20 @@
 sheet_object_clear_sheet (SheetObject *so)
 {
 	GList *ptr;
+	gpointer view_handler;
 
 	g_return_val_if_fail (IS_SHEET_OBJECT (so), TRUE);
 	g_return_val_if_fail (IS_SHEET (so->sheet), TRUE);
 
 	ptr = g_list_find (so->sheet->sheet_objects, so);
 	g_return_val_if_fail (ptr != NULL, TRUE);
+
+	/* clear any pending attempts to create views */
+	view_handler = g_object_get_data (G_OBJECT (so), "create_view_handler");
+	if (NULL != view_handler) {
+		g_source_remove (GPOINTER_TO_UINT (view_handler));
+		g_object_set_data (G_OBJECT (so), "create_view_handler", NULL);
+	}
 
 	/* The views remove themselves from the list */
 	while (so->realized_list != NULL)
Index: src/wbcg-actions.c
===================================================================
RCS file: /cvs/gnome/gnumeric/src/wbcg-actions.c,v
retrieving revision 1.66
diff -u -w -r1.66 wbcg-actions.c
--- src/wbcg-actions.c	17 Oct 2004 00:33:48 -0000	1.66
+++ src/wbcg-actions.c	14 Nov 2004 06:35:49 -0000
@@ -935,8 +935,9 @@
 		if (input != NULL) {
 			unsigned len = gsf_input_size (input);
 			guint8 const *data = gsf_input_read (input, len, NULL);
-			scg_mode_create_object (wbcg_cur_scg (wbcg),
-				sheet_object_image_new ("", (guint8 *)data, len, TRUE));
+			SheetObjectImage *soi = g_object_new (SHEET_OBJECT_IMAGE_TYPE, NULL);
+			sheet_object_image_set_image (soi, "", (guint8 *)data, len, TRUE);
+			scg_mode_create_object (wbcg_cur_scg (wbcg), SHEET_OBJECT (soi));
 			g_object_unref (input);
 		} else
 			gnm_cmd_context_error (GNM_CMD_CONTEXT (wbcg), err);
