[gnumeric] xls: rearrange object code a bit.



commit 40564b0312e26d79a83fcc948bbbd0d6c751fc6d
Author: Morten Welinder <terra gnome org>
Date:   Tue Oct 13 09:19:33 2009 -0400

    xls: rearrange object code a bit.

 plugins/excel/ms-excel-write.c |   68 +++++++++++++++++++++-------------------
 plugins/excel/ms-obj.c         |   62 ++++++++++++++++++++++++++++++++----
 plugins/excel/ms-obj.h         |   22 ++++++------
 3 files changed, 102 insertions(+), 50 deletions(-)
---
diff --git a/plugins/excel/ms-excel-write.c b/plugins/excel/ms-excel-write.c
index d2fc23b..987274e 100644
--- a/plugins/excel/ms-excel-write.c
+++ b/plugins/excel/ms-excel-write.c
@@ -4256,7 +4256,6 @@ excel_write_textbox_v8 (ExcelWriteSheet *esheet, SheetObject *so)
 	guint32 id = excel_write_start_drawing (esheet);
 	SheetObjectAnchor const *real_anchor = sheet_object_get_anchor (so);
 	SheetObjectAnchor anchor = *real_anchor;
-	guint8 zero[4] = { 0, 0, 0, 0 };
 	gsf_off_t sppos;
 	guint32 splen;
 	gsize spmark, optmark;
@@ -4269,8 +4268,9 @@ excel_write_textbox_v8 (ExcelWriteSheet *esheet, SheetObject *so)
 	GOStyle *style = NULL;
 	GnmExprTop const *checkbox_texpr = NULL;
 	gboolean checkbox_active = FALSE;
-	gboolean is_button = FALSE;
+	gboolean is_widget = FALSE;
 	GnmNamedExpr *macro_nexpr = NULL;
+	guint8 zero[4] = { 0, 0, 0, 0 };
 
 	g_object_get (so,
 		      "name", &name,
@@ -4314,20 +4314,20 @@ excel_write_textbox_v8 (ExcelWriteSheet *esheet, SheetObject *so)
 		}
 	} else if (GNM_IS_SOW_CHECKBOX (so)) {
 		shape = 0xc9;
-		type = 11;
+		type = 0x0b;
 		flags = 0x0011;
 		checkbox_texpr = sheet_widget_checkbox_get_link (so);
 		g_object_get (so, "active", &checkbox_active, NULL);
-		is_button = TRUE;
+		is_widget = TRUE;
 
 		macro_nexpr = g_hash_table_lookup (esheet->widget_macroname, so);
 	} else if (GNM_IS_SOW_RADIO_BUTTON (so)) {
 		shape = 0xc9;
-		type = 12;
+		type = 0x0c;
 		flags = 0x0011;
 		checkbox_texpr = sheet_widget_radio_button_get_link (so);
 		g_object_get (so, "active", &checkbox_active, NULL);
-		is_button = TRUE;
+		is_widget = TRUE;
 
 		macro_nexpr = g_hash_table_lookup (esheet->widget_macroname, so);
 	} else {
@@ -4341,7 +4341,7 @@ excel_write_textbox_v8 (ExcelWriteSheet *esheet, SheetObject *so)
 
 	optmark = ms_escher_opt_start (escher);
 	extra = g_string_new (NULL);
-	if (is_button)
+	if (is_widget)
 		ms_escher_opt_add_bool (escher, optmark,
 					MSEP_LOCKROTATION, TRUE);
 	ms_escher_opt_add_simple (escher, optmark,
@@ -4351,7 +4351,7 @@ excel_write_textbox_v8 (ExcelWriteSheet *esheet, SheetObject *so)
 	ms_escher_opt_add_simple (escher, optmark,
 				  MSEP_TXDIR, 2);
 	ms_escher_opt_add_bool (escher, optmark, MSEP_SELECTTEXT, TRUE);
-	if (is_button) {
+	if (is_widget) {
 		ms_escher_opt_add_bool (escher, optmark, MSEP_AUTOTEXTMARGIN, FALSE);
 		ms_escher_opt_add_bool (escher, optmark, MSEP_SHADOWOK, TRUE);
 		ms_escher_opt_add_bool (escher, optmark, MSEP_LINEOK, TRUE);
@@ -4361,7 +4361,7 @@ excel_write_textbox_v8 (ExcelWriteSheet *esheet, SheetObject *so)
 				 style == NULL || style->fill.auto_back
 				 ? GO_COLOR_WHITE
 				 : style->fill.pattern.back);
-	if (is_button)
+	if (is_widget)
 		ms_escher_opt_add_bool (escher, optmark, MSEP_FILLED, FALSE);
 	ms_escher_opt_add_bool (escher, optmark, MSEP_NOFILLHITTEST, TRUE);
 	ms_escher_opt_add_color (escher, optmark, MSEP_LINECOLOR,
@@ -4372,7 +4372,7 @@ excel_write_textbox_v8 (ExcelWriteSheet *esheet, SheetObject *so)
 		gint32 w = CLAMP (12700 * style->line.width, 0, G_MAXINT32);
 		ms_escher_opt_add_simple (escher, optmark, MSEP_LINEWIDTH, w);
 	}
-	if (is_button)
+	if (is_widget)
 		ms_escher_opt_add_bool (escher, optmark, MSEP_LINE, FALSE);
 	if (name)
 		ms_escher_opt_add_str_wchar (escher, optmark, extra,
@@ -4400,36 +4400,40 @@ excel_write_textbox_v8 (ExcelWriteSheet *esheet, SheetObject *so)
 
 	g_string_free (escher, TRUE);
 
+	/* ---------------------------------------- */
+
 	ms_biff_put_var_next (bp, BIFF_OBJ);
 	ms_objv8_write_common (bp, esheet->cur_obj, type, flags);
-	if (IS_CELL_COMMENT (so))
-		ms_objv8_write_note (bp);
 
-	if (type == 11 || type == 12) {
-		ms_objv8_write_checkbox_link (bp, checkbox_active);
-		if (type == 12)
-			ms_objv8_write_radiobutton (bp);
-		if (checkbox_texpr)
-			ms_objv8_write_checkbox_fmla (bp, esheet,
-						      checkbox_texpr);
-		if (0 && macro_nexpr) {
-			GnmExprTop const *texpr =
-				gnm_expr_top_new
-				(gnm_expr_new_name (macro_nexpr,
-						    esheet->gnum_sheet,
-						    NULL));
-			ms_objv8_write_macro_fmla (bp, esheet, texpr);
-			gnm_expr_top_unref (texpr);
-		}
-		ms_objv8_write_checkbox_data (bp, checkbox_active);
-		if (type == 12)
-			ms_objv8_write_radiobutton_data (bp, 0, TRUE);
+	switch (type) {
+	case 0x0b:
+		ms_objv8_write_checkbox (bp,
+					 checkbox_active,
+					 esheet,
+					 checkbox_texpr,
+					 macro_nexpr);
+		break;
+	case 0x0c:
+		ms_objv8_write_radiobutton (bp,
+					    checkbox_active,
+					    esheet,
+					    checkbox_texpr,
+					    macro_nexpr);
+		break;
+	case 0x19:
+		/* Cell comment. */
+		ms_objv8_write_note (bp);
+		break;
+	default:
+		/* Nothing */
+		break;
 	}
 
 	ms_biff_put_var_write (bp, zero, 4);
-
 	ms_biff_put_commit (bp);
 
+	/* ---------------------------------------- */
+
 	if (do_textbox) {
 		gsize this_len = excel_write_ClientTextbox (ewb, so, label);
 		draw_len += this_len;
diff --git a/plugins/excel/ms-obj.c b/plugins/excel/ms-obj.c
index 12d20f6..ad33a2e 100644
--- a/plugins/excel/ms-obj.c
+++ b/plugins/excel/ms-obj.c
@@ -1381,13 +1381,13 @@ ms_objv8_write_note (BiffPut *bp)
 #endif
 		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
 	};
-
 	guint8 buf[sizeof data];
+
 	memcpy (buf, data, sizeof data);
 	ms_biff_put_var_write (bp, buf, sizeof data);
 }
 
-void
+static void
 ms_objv8_write_checkbox_data (BiffPut *bp, gboolean active)
 {
 	char cboxdata[12];
@@ -1401,7 +1401,7 @@ ms_objv8_write_checkbox_data (BiffPut *bp, gboolean active)
 	ms_biff_put_var_write (bp, cboxdata, sizeof cboxdata);
 }
 
-void
+static void
 ms_objv8_write_checkbox_link (BiffPut *bp, gboolean active)
 {
 	char data[16];
@@ -1417,7 +1417,7 @@ ms_objv8_write_checkbox_link (BiffPut *bp, gboolean active)
 	ms_biff_put_var_write (bp, data, sizeof data);
 }
 
-void
+static void
 ms_objv8_write_checkbox_fmla (BiffPut *bp,
 			      ExcelWriteSheet *esheet,
 			      GnmExprTop const *texpr)
@@ -1446,7 +1446,7 @@ ms_objv8_write_checkbox_fmla (BiffPut *bp,
 	ms_biff_put_var_seekto (bp, end_pos);
 }
 
-void
+static void
 ms_objv8_write_macro_fmla (BiffPut *bp,
 			   ExcelWriteSheet *esheet,
 			   GnmExprTop const *texpr)
@@ -1476,7 +1476,30 @@ ms_objv8_write_macro_fmla (BiffPut *bp,
 }
 
 void
-ms_objv8_write_radiobutton (BiffPut *bp)
+ms_objv8_write_checkbox (BiffPut *bp,
+			 gboolean active,
+			 ExcelWriteSheet *esheet,
+			 GnmExprTop const *link_texpr,
+			 GnmNamedExpr *macro_nexpr)
+{
+	ms_objv8_write_checkbox_link (bp, active);
+	if (link_texpr)
+		ms_objv8_write_checkbox_fmla (bp, esheet,
+					      link_texpr);
+	if (0 && macro_nexpr) {
+		GnmExprTop const *texpr =
+			gnm_expr_top_new
+			(gnm_expr_new_name (macro_nexpr,
+					    esheet->gnum_sheet,
+					    NULL));
+		ms_objv8_write_macro_fmla (bp, esheet, texpr);
+		gnm_expr_top_unref (texpr);
+	}
+	ms_objv8_write_checkbox_data (bp, active);
+}
+
+static void
+ms_objv8_write_radiobutton_rec (BiffPut *bp)
 {
 	char rb[10];
 
@@ -1487,7 +1510,7 @@ ms_objv8_write_radiobutton (BiffPut *bp)
 	ms_biff_put_var_write (bp, rb, sizeof rb);
 }
 
-void
+static void
 ms_objv8_write_radiobutton_data (BiffPut *bp, guint16 nobj, gboolean first)
 {
 	char rb[8];
@@ -1498,3 +1521,28 @@ ms_objv8_write_radiobutton_data (BiffPut *bp, guint16 nobj, gboolean first)
 	GSF_LE_SET_GUINT16 (rb + 6, !!first);
 	ms_biff_put_var_write (bp, rb, sizeof rb);
 }
+
+void
+ms_objv8_write_radiobutton (BiffPut *bp,
+			    gboolean active,
+			    ExcelWriteSheet *esheet,
+			    GnmExprTop const *link_texpr,
+			    GnmNamedExpr *macro_nexpr)
+{
+	ms_objv8_write_checkbox_link (bp, active);
+	ms_objv8_write_radiobutton_rec (bp);
+	if (link_texpr)
+		ms_objv8_write_checkbox_fmla (bp, esheet,
+					      link_texpr);
+	if (0 && macro_nexpr) {
+		GnmExprTop const *texpr =
+			gnm_expr_top_new
+			(gnm_expr_new_name (macro_nexpr,
+					    esheet->gnum_sheet,
+					    NULL));
+		ms_objv8_write_macro_fmla (bp, esheet, texpr);
+		gnm_expr_top_unref (texpr);
+	}
+	ms_objv8_write_checkbox_data (bp, active);
+	ms_objv8_write_radiobutton_data (bp, 0, TRUE);
+}
diff --git a/plugins/excel/ms-obj.h b/plugins/excel/ms-obj.h
index aef672b..db189aa 100644
--- a/plugins/excel/ms-obj.h
+++ b/plugins/excel/ms-obj.h
@@ -151,18 +151,18 @@ char  *ms_read_TXO   (BiffQuery *q, MSContainer *c, PangoAttrList **markup);
 void ms_objv8_write_common	(BiffPut *bp, int id, int type, guint16 flags);
 void ms_objv8_write_scrollbar	(BiffPut *bp);
 void ms_objv8_write_listbox	(BiffPut *bp, gboolean filtered);
+
 void ms_objv8_write_note	(BiffPut *bp);
 
-void ms_objv8_write_checkbox_data (BiffPut *bp, gboolean active);
-void ms_objv8_write_checkbox_link (BiffPut *bp, gboolean active);
-void ms_objv8_write_checkbox_fmla (BiffPut *bp,
-				   ExcelWriteSheet *esheet,
-				   GnmExprTop const *texpr);
-void ms_objv8_write_macro_fmla    (BiffPut *bp,
-				   ExcelWriteSheet *esheet,
-				   GnmExprTop const *texpr);
-void ms_objv8_write_radiobutton (BiffPut *bp);
-void ms_objv8_write_radiobutton_data (BiffPut *bp,
-				      guint16 nobj, gboolean first);
+void ms_objv8_write_checkbox (BiffPut *bp,
+			      gboolean active,
+			      ExcelWriteSheet *esheet,
+			      GnmExprTop const *link_texpr,
+			      GnmNamedExpr *macro_nexpr);
+void ms_objv8_write_radiobutton (BiffPut *bp,
+				 gboolean active,
+				 ExcelWriteSheet *esheet,
+				 GnmExprTop const *link_texpr,
+				 GnmNamedExpr *macro_nexpr);
 
 #endif /* GNM_MS_OBJ_H */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]