[gnumeric] xls: export current setting of checkboxes.



commit c6905c51f3914fe945eb26bc218e09705b8cf6f9
Author: Morten Welinder <terra gnome org>
Date:   Wed Oct 7 16:32:44 2009 -0400

    xls: export current setting of checkboxes.

 plugins/excel/ChangeLog        |    5 +++-
 plugins/excel/ms-excel-write.c |   35 +++++++++-----------------------
 plugins/excel/ms-obj.c         |   43 ++++++++++++++++++++++++++++++++++++++++
 plugins/excel/ms-obj.h         |    6 +++++
 4 files changed, 63 insertions(+), 26 deletions(-)
---
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index ced1014..5e4d77c 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,7 +1,10 @@
 2009-10-07  Morten Welinder  <terra gnome org>
 
 	* ms-excel-write.c (excel_write_textbox_v8): Export
-	checkbox/radiobutton link.
+	checkbox/radiobutton link and current value.
+
+	* ms-obj.c (ms_objv8_write_checkbox_fmla,
+	ms_objv8_write_checkbox_data): New functions.
 
 	* ms-escher.c (ms_escher_opt_add_color): New function.
 
diff --git a/plugins/excel/ms-excel-write.c b/plugins/excel/ms-excel-write.c
index 53cccaa..6fc6139 100644
--- a/plugins/excel/ms-excel-write.c
+++ b/plugins/excel/ms-excel-write.c
@@ -4270,6 +4270,8 @@ excel_write_textbox_v8 (ExcelWriteSheet *esheet, SheetObject *so)
 	char *name, *label;
 	GOStyle *style = NULL;
 	GnmExprTop const *checkbox_texpr = NULL;
+	gboolean checkbox_active = FALSE;
+	gboolean is_button = FALSE;
 
 	g_object_get (so,
 		      "name", &name,
@@ -4316,11 +4318,15 @@ excel_write_textbox_v8 (ExcelWriteSheet *esheet, SheetObject *so)
 		type = 11;
 		flags = 0x0011;
 		checkbox_texpr = sheet_widget_checkbox_get_link (so);
+		g_object_get (so, "active", &checkbox_active, NULL);
+		is_button = TRUE;
 	} else if (GNM_IS_SOW_RADIO_BUTTON (so)) {
 		shape = 0xc9;
 		type = 12;
 		flags = 0x0011;
 		checkbox_texpr = sheet_widget_radio_button_get_link (so);
+		g_object_get (so, "active", &checkbox_active, NULL);
+		is_button = TRUE;
 	} else {
 		g_assert_not_reached ();
 		return 0;
@@ -4356,7 +4362,8 @@ excel_write_textbox_v8 (ExcelWriteSheet *esheet, SheetObject *so)
 		ms_escher_opt_add_str_wchar (escher, optmark, extra,
 					     MSEP_NAME, name);
 	ms_escher_opt_add_simple (escher, optmark,
-				  0x03bf, 0x00080000); /* fPrint */
+				  0x03bf,
+				  is_button ? 0x00080008 : 0x00080000);
 	go_string_append_gstring (escher, extra);
 	ms_escher_opt_end (escher, optmark);
 	g_string_free (extra, TRUE);
@@ -4385,30 +4392,8 @@ excel_write_textbox_v8 (ExcelWriteSheet *esheet, SheetObject *so)
 		ms_objv8_write_note (bp);
 
 	if (checkbox_texpr) {
-		char data[10];
-		unsigned pos, end_pos;
-		guint16 fmla_len;
-
-		pos = bp->curpos;
-		GSF_LE_SET_GUINT16 (data, 20);
-		GSF_LE_SET_GUINT16 (data + 2, 0);  /* record len */
-		GSF_LE_SET_GUINT16 (data + 4, 0);  /* formula len */
-		GSF_LE_SET_GUINT32 (data + 6, 0);  /* calcid? */
-		ms_biff_put_var_write (bp, data, sizeof data);
-
-		fmla_len = excel_write_formula (esheet->ewb,
-						checkbox_texpr,
-						esheet->gnum_sheet, 0, 0,
-						/* eh?  */
-						EXCEL_CALLED_FROM_VALIDATION);
-		end_pos = bp->curpos;
-
-		ms_biff_put_var_seekto (bp, pos);
-		GSF_LE_SET_GUINT16 (data + 2, fmla_len + 6);
-		GSF_LE_SET_GUINT16 (data + 4, fmla_len);
-		ms_biff_put_var_write (bp, data, sizeof data);
-
-		ms_biff_put_var_seekto (bp, end_pos);
+		ms_objv8_write_checkbox_fmla (bp, esheet, checkbox_texpr);
+		ms_objv8_write_checkbox_data (bp, checkbox_active);
 	}
 
 	ms_biff_put_var_write (bp, zero, 4);
diff --git a/plugins/excel/ms-obj.c b/plugins/excel/ms-obj.c
index 32b084d..0589ad2 100644
--- a/plugins/excel/ms-obj.c
+++ b/plugins/excel/ms-obj.c
@@ -35,6 +35,7 @@
 #include "ms-chart.h"
 #include "ms-escher.h"
 #include "ms-excel-util.h"
+#include "ms-formula-write.h"
 
 #include <expr.h>
 #include <parse-util.h>
@@ -1383,3 +1384,45 @@ ms_objv8_write_note (BiffPut *bp)
 	memcpy (buf, data, sizeof data);
 	ms_biff_put_var_write (bp, buf, sizeof data);
 }
+
+void
+ms_objv8_write_checkbox_data (BiffPut *bp, gboolean active)
+{
+	char cboxdata[12];
+
+	GSF_LE_SET_GUINT16 (cboxdata, GR_CHECKBOX_DATA);
+	GSF_LE_SET_GUINT16 (cboxdata + 2, sizeof (cboxdata) - 4);
+	GSF_LE_SET_GUINT16 (cboxdata + 4, active);
+	GSF_LE_SET_GUINT16 (cboxdata + 6, 0);
+	GSF_LE_SET_GUINT16 (cboxdata + 8, 0);
+	GSF_LE_SET_GUINT16 (cboxdata + 10, 2);  /* ??? */
+	ms_biff_put_var_write (bp, cboxdata, sizeof cboxdata);
+}
+
+void
+ms_objv8_write_checkbox_fmla (BiffPut *bp,
+			      ExcelWriteSheet *esheet,
+			      GnmExprTop const *texpr)
+{
+	char hfmla[10];
+	unsigned pos, end_pos;
+	guint16 fmla_len;
+
+	pos = bp->curpos;
+	GSF_LE_SET_GUINT16 (hfmla, 20);
+	GSF_LE_SET_GUINT16 (hfmla + 2, 0);  /* record len */
+	GSF_LE_SET_GUINT16 (hfmla + 4, 0);  /* formula len */
+	GSF_LE_SET_GUINT32 (hfmla + 6, 0);  /* calcid? */
+	ms_biff_put_var_write (bp, hfmla, sizeof hfmla);
+	fmla_len = excel_write_formula (esheet->ewb,
+					texpr,
+					esheet->gnum_sheet, 0, 0,
+					/* eh?  */
+					EXCEL_CALLED_FROM_VALIDATION);
+	end_pos = bp->curpos;
+	ms_biff_put_var_seekto (bp, pos);
+	GSF_LE_SET_GUINT16 (hfmla + 2, fmla_len + 6);
+	GSF_LE_SET_GUINT16 (hfmla + 4, fmla_len);
+	ms_biff_put_var_write (bp, hfmla, sizeof hfmla);
+	ms_biff_put_var_seekto (bp, end_pos);
+}
diff --git a/plugins/excel/ms-obj.h b/plugins/excel/ms-obj.h
index b8201e5..e8fc93c 100644
--- a/plugins/excel/ms-obj.h
+++ b/plugins/excel/ms-obj.h
@@ -13,6 +13,7 @@
  **/
 
 #include "ms-excel-read.h"
+#include "ms-excel-write.h"
 
 #define MS_ANCHOR_SIZE	18
 
@@ -151,4 +152,9 @@ 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_fmla (BiffPut *bp,
+				   ExcelWriteSheet *esheet,
+				   GnmExprTop const *texpr);
+
 #endif /* GNM_MS_OBJ_H */



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