[gnumeric] ODF: import/export list boxes



commit 237c46572b3f6c91318f53fdbd50ccba5b60e1f4
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Fri Sep 10 15:22:12 2010 -0600

    ODF: import/export list boxes
    
    2010-09-10  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* openoffice-read.c (od_draw_control_start): handle listboxes
    	(oo_control_free): free new source_cell_range field
    	(odf_form_control): handle new attributes
    	(odf_form_listbox): new
    	(opendoc_content_dtd): connect odf_form_listbox
    	* openoffice-write.c (odf_write_sheet_control_conten): new
    	(odf_write_sheet_control_list): new
    	(odf_write_sheet_controls): also write listboxes

 plugins/openoffice/ChangeLog          |   19 +++++++++-
 plugins/openoffice/openoffice-read.c  |   65 ++++++++++++++++++++++++++++++++-
 plugins/openoffice/openoffice-write.c |   49 +++++++++++++++++++++++++
 3 files changed, 130 insertions(+), 3 deletions(-)
---
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index e6ff56e..de88378 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,10 +1,25 @@
 2010-09-10  Andreas J. Guelzow <aguelzow pyrshep ca>
 
-	* openoffice-read.c (od_draw_control_start): handle spinbuttons and sliders
+	* openoffice-read.c (od_draw_control_start): handle listboxes
+	(oo_control_free): free new source_cell_range field
+	(odf_form_control): handle new attributes
+	(odf_form_listbox): new
+	(opendoc_content_dtd): connect odf_form_listbox
+	* openoffice-write.c (odf_write_sheet_control_conten): new
+	(odf_write_sheet_control_list): new
+	(odf_write_sheet_controls): also write listboxes
+	
+2010-09-10  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* openoffice-read.c (od_draw_control_start): handle spinbuttons 
+	  and sliders
 	(oo_control_free): free new implementation field
 	(odf_form_control): handle spinbuttons and sliders
 	(odf_form_value_range): ditto
-	* openoffice-write.c
+	* openoffice-write.c (odf_write_sheet_control_scrollbar): 
+	  write the form:control-implementation and add argument 
+	  indicating the control type
+	(odf_write_sheet_controls): also write sliders and spinbuttons
 
 2010-09-09  Andreas J. Guelzow <aguelzow pyrshep ca>
 
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index 0b8c0e1..e67a0d1 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -190,6 +190,7 @@ typedef struct {
 	char *linked_cell;
 	char *label;
 	char *implementation;
+	char *source_cell_range;
 } OOControl;
 
 typedef struct {
@@ -4671,6 +4672,7 @@ od_draw_control_start (GsfXMLIn *xin, xmlChar const **attrs)
 
 	if (name != NULL) {
 		OOControl *oc = g_hash_table_lookup (state->controls, name);
+		GnmExprTop const *result_texpr = NULL;
 		if (oc != NULL) {
 			SheetObject *so = NULL;
 			if (oc->t == sheet_widget_scrollbar_get_type () ||
@@ -4741,6 +4743,9 @@ od_draw_control_start (GsfXMLIn *xin, xmlChar const **attrs)
 			} else if (oc->t == sheet_widget_checkbox_get_type ()) {
 				so = state->chart.so = g_object_new 
 					(oc->t, "text", oc->label, NULL);
+			} else if (oc->t == sheet_widget_list_get_type ()) {
+				so = state->chart.so = g_object_new 
+					(oc->t, NULL);
 			}
 
 			od_draw_frame_end (xin, NULL);
@@ -4769,10 +4774,37 @@ od_draw_control_start (GsfXMLIn *xin, xmlChar const **attrs)
 						else if (oc->t == sheet_widget_radio_button_get_type ())
 							sheet_widget_radio_button_set_link
 								(so, texpr);
+						else if (oc->t == sheet_widget_list_get_type ()) {
+							gnm_expr_top_ref ((result_texpr = texpr));
+							sheet_widget_list_base_set_links (so, texpr, NULL);
+						}
 						gnm_expr_top_unref (texpr);
 					}
 				}
 			}
+			if (oc->t == sheet_widget_list_get_type ()) {
+				if (oc->source_cell_range) {
+					GnmParsePos pp;
+					GnmRangeRef ref;
+					char const *ptr = oo_rangeref_parse 
+						(&ref, oc->source_cell_range,
+						 parse_pos_init_sheet (&pp, state->pos.sheet));
+					if (ptr != oc->source_cell_range) {
+						GnmValue *v = value_new_cellrange 
+							(&ref.a, &ref.b, 0, 0);
+						GnmExprTop const *texpr 
+							= gnm_expr_top_new_constant (v);
+						if (texpr != NULL) {
+							sheet_widget_list_base_set_links 
+								(so, 
+								 result_texpr, texpr);
+							gnm_expr_top_unref (texpr);
+						}
+					}				
+				} 
+				if (result_texpr != NULL)
+					gnm_expr_top_unref (result_texpr);
+			}
 		}
 	} else 
 		od_draw_frame_end (xin, NULL);
@@ -6054,6 +6086,7 @@ oo_control_free (OOControl *ctrl)
 	g_free (ctrl->label);
 	g_free (ctrl->linked_cell);
 	g_free (ctrl->implementation);
+	g_free (ctrl->source_cell_range);
 	g_free (ctrl);
 }
 
@@ -6158,8 +6191,29 @@ odf_form_control (GsfXMLIn *xin, xmlChar const **attrs, GType t)
 					     OO_NS_FORM, "control-implementation")) {
 			g_free (oc->implementation);
 			oc->implementation =  g_strdup (CXML2C (attrs[1]));
+		} else if (gsf_xml_in_namecmp (xin, CXML2C (attrs[0]), 
+					       OO_NS_FORM, "list-linkage-type")) {
+			if (0 != strcmp (CXML2C (attrs[1]),"selection-indexes") &&
+			    0 != strcmp (CXML2C (attrs[1]),"selection-indices") ) 
+				oo_warning (xin, _("Attribute '%s' has "
+						   "the unsupported value '%s'."), 
+					    "form:list-linkage-type", CXML2C (attrs[1]));
+		} else if (gsf_xml_in_namecmp (xin, CXML2C (attrs[0]), 
+					     OO_NS_FORM, "source-cell-range")) {
+			g_free (oc->source_cell_range);
+			oc->source_cell_range =  g_strdup (CXML2C (attrs[1]));
+		} else if (gsf_xml_in_namecmp (xin, CXML2C (attrs[0]), 
+					     OO_GNUM_NS_EXT, "source-cell-range")) {
+			if (oc->source_cell_range == NULL)
+				oc->source_cell_range =  g_strdup (CXML2C (attrs[1]));
+		} else if (oo_attr_int (xin, attrs, OO_NS_FORM, "bound-column", 
+					&tmp)) {
+			if (tmp != 1)
+				oo_warning (xin, _("Attribute '%s' has "
+						   "the unsupported value '%s'."), 
+					    "form:bound-column", CXML2C (attrs[1]));
 		}
-
+		
 	if (name != NULL) {
 		if (oc->implementation != NULL && 
 		    t == sheet_widget_slider_get_type ()) {
@@ -6202,6 +6256,12 @@ odf_form_radio (GsfXMLIn *xin, xmlChar const **attrs)
 	odf_form_control (xin, attrs, sheet_widget_radio_button_get_type ());
 }
 
+static void
+odf_form_listbox (GsfXMLIn *xin, xmlChar const **attrs)
+{
+	odf_form_control (xin, attrs, sheet_widget_list_get_type ());
+}
+
 /****************************************************************************/
 /******************************** settings.xml ******************************/
 
@@ -6807,6 +6867,9 @@ static GsfXMLInNode const opendoc_content_dtd [] =
 	            GSF_XML_IN_NODE (FORM_CHECKBOX, FORM_PROPERTIES, OO_NS_FORM, "properties", GSF_XML_NO_CONTENT, NULL, NULL),			/* 2nd Def */
 	          GSF_XML_IN_NODE (FORM, FORM_RADIO, OO_NS_FORM, "radio", GSF_XML_NO_CONTENT, &odf_form_radio, NULL),
 	            GSF_XML_IN_NODE (FORM_RADIO, FORM_PROPERTIES, OO_NS_FORM, "properties", GSF_XML_NO_CONTENT, NULL, NULL),			/* 2nd Def */
+	          GSF_XML_IN_NODE (FORM, FORM_LISTBOX, OO_NS_FORM, "listbox", GSF_XML_NO_CONTENT, &odf_form_listbox, NULL),
+	            GSF_XML_IN_NODE (FORM_LISTBOX, FORM_PROPERTIES, OO_NS_FORM, "properties", GSF_XML_NO_CONTENT, NULL, NULL),			/* 2nd Def */
+	              GSF_XML_IN_NODE (FORM_PROPERTIES, FORM_LIST_PROPERTY, OO_NS_FORM, "list-property", GSF_XML_NO_CONTENT, NULL, NULL),
 	      GSF_XML_IN_NODE (TABLE, TABLE_ROWS, OO_NS_TABLE, "table-rows", GSF_XML_NO_CONTENT, NULL, NULL),
 	      GSF_XML_IN_NODE (TABLE, TABLE_COL, OO_NS_TABLE, "table-column", GSF_XML_NO_CONTENT, &oo_col_start, NULL),
 	      GSF_XML_IN_NODE (TABLE, TABLE_ROW, OO_NS_TABLE, "table-row", GSF_XML_NO_CONTENT, &oo_row_start, &oo_row_end),
diff --git a/plugins/openoffice/openoffice-write.c b/plugins/openoffice/openoffice-write.c
index 4a056d1..dd3b663 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -3084,6 +3084,28 @@ odf_write_sheet_controls_get_id (GnmOOExport *state, SheetObject *so)
 }
 
 static void
+odf_write_sheet_control_content (GnmOOExport *state, GnmExprTop const *texpr)
+{
+	if (texpr && gnm_expr_top_is_rangeref (texpr)) {
+		char *link = NULL;
+		GnmParsePos pp;
+
+		parse_pos_init_sheet (&pp, state->sheet);
+		link = gnm_expr_top_as_string (texpr, &pp, state->conv);
+		
+		if (get_gsf_odf_version () > 101)
+			gsf_xml_out_add_cstr (state->xml, 
+					      FORM "source-cell-range", 
+					      odf_strip_brackets (link));
+		else
+			gsf_xml_out_add_cstr (state->xml, 
+					      GNMSTYLE "source-cell-range", 
+					      odf_strip_brackets (link));
+		g_free (link);
+	}
+}
+
+static void
 odf_write_sheet_control_linked_cell (GnmOOExport *state, GnmExprTop const *texpr)
 {
 	if (texpr && gnm_expr_top_is_rangeref (texpr)) {
@@ -3165,6 +3187,31 @@ odf_write_sheet_control_checkbox (GnmOOExport *state, SheetObject *so)
 }
 
 static void
+odf_write_sheet_control_list (GnmOOExport *state, SheetObject *so)
+{
+	char const *id = odf_write_sheet_controls_get_id (state, so);
+	GnmExprTop const *texpr = sheet_widget_list_base_get_result_link (so);
+
+	gsf_xml_out_start_element (state->xml, FORM "listbox");
+	gsf_xml_out_add_cstr (state->xml, XML "id", id);
+	gsf_xml_out_add_cstr (state->xml, FORM "id", id);
+
+	odf_write_sheet_control_linked_cell (state, texpr);
+	gnm_expr_top_unref (texpr);
+
+	texpr = sheet_widget_list_base_get_content_link (so);
+	odf_write_sheet_control_content (state, texpr);
+	gnm_expr_top_unref (texpr);
+
+	if (get_gsf_odf_version () > 101)
+		gsf_xml_out_add_cstr_unchecked 
+			(state->xml, FORM "list-linkage-type", 
+			 "selection-indexes");
+	gsf_xml_out_add_int (state->xml, FORM "bound-column", 1);
+	gsf_xml_out_end_element (state->xml); /* form:checkbox */
+}
+
+static void
 odf_write_sheet_control_radio_button (GnmOOExport *state, SheetObject *so)
 {
 	char const *id = odf_write_sheet_controls_get_id (state, so);
@@ -3260,6 +3307,8 @@ odf_write_sheet_controls (GnmOOExport *state)
 			odf_write_sheet_control_checkbox (state, so);
 		else if (GNM_IS_SOW_RADIO_BUTTON (so))
 			odf_write_sheet_control_radio_button (state, so);
+		else if (GNM_IS_SOW_LIST (so))
+			odf_write_sheet_control_list (state, so);
 	}
 
 	gsf_xml_out_end_element (state->xml); /* form:form */



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