[gnumeric] Import/export radio buttons from and to ODF files.



commit 64634d154fd9619e6b8bbdd4f01f47c788b90848
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date:   Thu Sep 9 14:04:40 2010 -0600

    Import/export radio buttons from and to ODF files.
    
    2010-09-09  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* openoffice-read.c (od_draw_control_start): use gnm:value-type
    	  if available
    	(oo_control_free): free value_type field
    	(odf_form_control): read gnm:value-type
    	* openoffice-write.c (odf_write_sheet_control_radio_button): new
    	(odf_write_sheet_controls): connect odf_write_sheet_control_radio_button
    
    2010-09-09  Andreas J. Guelzow <aguelzow pyrshep ca>
    
    	* src/sheet-object-widget.c: add "value" property to radio_button
    	  widget

 ChangeLog                             |    5 ++
 NEWS                                  |    6 +-
 plugins/openoffice/ChangeLog          |    9 ++++
 plugins/openoffice/openoffice-read.c  |   33 ++++++++++++++-
 plugins/openoffice/openoffice-write.c |   71 ++++++++++++++++++++++++++++++++-
 src/sheet-object-widget.c             |   14 ++++++-
 6 files changed, 131 insertions(+), 7 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index f0d1d5d..e0bb7ce 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2010-09-09  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* src/sheet-object-widget.c: add "value" property to radio_button
+	  widget
+
 2010-09-04  Morten Welinder <terra gnome org>
 
 	* configure.in: Post-release bump.
diff --git a/NEWS b/NEWS
index 74c1bd8..89d902f 100644
--- a/NEWS
+++ b/NEWS
@@ -4,9 +4,9 @@ Andreas:
 	* Fix image-fill, pattern and gradient export. [#628762]
 	* Read tab colors from OOo config in ODF files.
 	* Improve some ODF chart import/export.
-	* Import/export scrollbars and checkboxes from and to ODF files.
-	* Import radio buttons from ODF files.
-
+	* Import/export scrollbars, checkboxes and radio buttons from and 
+	  to ODF files.
+\
 --------------------------------------------------------------------------
 Gnumeric 1.10.10
 
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index c38c252..ff905a7 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,3 +1,12 @@
+2010-09-09  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+	* openoffice-read.c (od_draw_control_start): use gnm:value-type
+	  if available
+	(oo_control_free): free value_type field
+	(odf_form_control): read gnm:value-type
+	* openoffice-write.c (odf_write_sheet_control_radio_button): new
+	(odf_write_sheet_controls): connect odf_write_sheet_control_radio_button
+	
 2010-09-08  Andreas J. Guelzow <aguelzow pyrshep ca>
 
 	* openoffice-read.c (od_draw_control_start): oc->value must be a 
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index 41462a3..d98ee79 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -186,6 +186,7 @@ typedef struct {
 	int step;
 	int page_step;
 	char *value;
+	char *value_type;
 	char *linked_cell;
 	char *label;
 } OOControl;
@@ -4685,6 +4686,11 @@ od_draw_control_start (GsfXMLIn *xin, xmlChar const **attrs)
 							   "expected number, received '%s'"), oc->value);
 						value_real = 0.;
 					}
+					if (oc->value_type != NULL && 0 != strcmp (oc->value_type, "float"))
+						oo_warning (xin, _("Invalid value-type '%s' advertised for "
+								   "'form:value' attribute in 'form:value-range' "
+								   "element."), 
+							    oc->value_type);
 				} else value_real = 0.;
 
 				if (value_real < (gnm_float)min_real)
@@ -4707,9 +4713,27 @@ od_draw_control_start (GsfXMLIn *xin, xmlChar const **attrs)
 				so = state->chart.so = g_object_new 
 					(oc->t, "text", oc->label, NULL);
 				if (oc->value != NULL) {
-					GnmValue *val = value_new_string (oc->value);
+					GnmValue *val = NULL;
+					if (oc->value_type == NULL || 
+					    0 == strcmp (oc->value_type, "string"))
+						val = value_new_string (oc->value);
+					else if (0 == strcmp (oc->value_type, "float")) {
+						char *end;
+						gnm_float value_real = gnm_strto (oc->value, &end);
+						if (*end) {
+							oo_warning (xin, _("Invalid attribute 'form:value', "
+									   "expected number, received '%s'"), oc->value);
+							val = value_new_string (oc->value);
+						} else
+							val = value_new_float (value_real);
+					} else if (0 == strcmp (oc->value_type, "boolean")) {
+						gboolean b = (g_ascii_strcasecmp (oc->value, "false") &&
+							      strcmp (oc->value, "0"));
+						val = value_new_bool (b);
+					} else
+						val = value_new_string (oc->value);
 					sheet_widget_radio_button_set_value (so, val);
-					value_release (val);
+					value_release (val);					
 				}
 			} else if (oc->t == sheet_widget_checkbox_get_type ()) {
 				so = state->chart.so = g_object_new 
@@ -6021,6 +6045,7 @@ static void
 oo_control_free (OOControl *ctrl)
 {
 	g_free (ctrl->value);
+	g_free (ctrl->value_type);
 	g_free (ctrl->label);
 	g_free (ctrl->linked_cell);
 	g_free (ctrl);
@@ -6108,6 +6133,10 @@ odf_form_control (GsfXMLIn *xin, xmlChar const **attrs, GType t)
 			g_free (oc->value);
 			oc->value = g_strdup (CXML2C (attrs[1]));
 		} else if (gsf_xml_in_namecmp (xin, CXML2C (attrs[0]), 
+						OO_GNUM_NS_EXT, "value-type")) {
+			g_free (oc->value_type);
+			oc->value_type = g_strdup (CXML2C (attrs[1]));
+		} else if (gsf_xml_in_namecmp (xin, CXML2C (attrs[0]), 
 					     OO_NS_FORM, "linked-cell")) {
 			g_free (oc->linked_cell);
 			oc->linked_cell =  g_strdup (CXML2C (attrs[1]));
diff --git a/plugins/openoffice/openoffice-write.c b/plugins/openoffice/openoffice-write.c
index 5e18b59..d816af8 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -3142,7 +3142,7 @@ odf_write_sheet_control_checkbox (GnmOOExport *state, SheetObject *so)
 {
 	char const *id = odf_write_sheet_controls_get_id (state, so);
 	GnmExprTop const *texpr = sheet_widget_checkbox_get_link (so);
-	char *label;
+	char *label = NULL;
 
 	g_object_get (G_OBJECT (so), "text", &label, NULL);
 
@@ -3159,6 +3159,73 @@ odf_write_sheet_control_checkbox (GnmOOExport *state, SheetObject *so)
 	g_free (label);
 }
 
+static void
+odf_write_sheet_control_radio_button (GnmOOExport *state, SheetObject *so)
+{
+	char const *id = odf_write_sheet_controls_get_id (state, so);
+	GnmExprTop const *texpr = sheet_widget_radio_button_get_link (so);
+	char *label = NULL;
+	GnmValue *val = NULL;
+
+	g_object_get (G_OBJECT (so), "text", &label, "value", &val, NULL);
+
+	gsf_xml_out_start_element (state->xml, FORM "radio");
+	gsf_xml_out_add_cstr (state->xml, XML "id", id);
+	gsf_xml_out_add_cstr (state->xml, FORM "id", id);
+	gsf_xml_out_add_cstr (state->xml, FORM "label", label);
+
+	if (val != NULL) {
+		switch (val->type) {
+		case VALUE_EMPTY:
+			break;
+		case VALUE_BOOLEAN:
+			if (state->with_extension)
+				gsf_xml_out_add_cstr_unchecked 
+					(state->xml,
+					 GNMSTYLE "value-type", 
+					 "boolean");
+			odf_add_bool (state->xml, FORM "value",
+				      value_get_as_bool (val, NULL));
+			break;
+		case VALUE_FLOAT: {
+			GString *str = g_string_new (NULL);
+			if (state->with_extension)
+				gsf_xml_out_add_cstr_unchecked 
+					(state->xml,
+					 GNMSTYLE "value-type", 
+					 "float");
+			value_get_as_gstring (val, str, state->conv);
+			gsf_xml_out_add_cstr (state->xml, FORM "value", 
+					      str->str);
+			g_string_free (str, TRUE);
+			break;
+		}
+		case VALUE_ERROR:
+		case VALUE_STRING:
+			if (state->with_extension)
+				gsf_xml_out_add_cstr_unchecked 
+					(state->xml,
+					 GNMSTYLE "value-type", 
+					 "string");
+			gsf_xml_out_add_cstr (state->xml,
+					      FORM "value",
+					      value_peek_string (val));
+			break;
+		case VALUE_CELLRANGE:
+		case VALUE_ARRAY:
+		default:
+			break;
+		}
+	}
+
+	odf_write_sheet_control_linked_cell (state, texpr);
+	gnm_expr_top_unref (texpr);
+	
+	gsf_xml_out_end_element (state->xml); /* form:checkbox */
+
+	g_free (label);
+}
+
 
 
 static void
@@ -3179,6 +3246,8 @@ odf_write_sheet_controls (GnmOOExport *state)
 		    odf_write_sheet_control_scrollbar (state, so);
 		else if (GNM_IS_SOW_CHECKBOX (so))
 			odf_write_sheet_control_checkbox (state, so);
+		else if (GNM_IS_SOW_RADIO_BUTTON (so))
+			odf_write_sheet_control_radio_button (state, so);
 	}
 
 	gsf_xml_out_end_element (state->xml); /* form:form */
diff --git a/src/sheet-object-widget.c b/src/sheet-object-widget.c
index 00b18e2..48f9d8b 100644
--- a/src/sheet-object-widget.c
+++ b/src/sheet-object-widget.c
@@ -2250,7 +2250,8 @@ enum {
 	SOR_PROP_0 = 0,
 	SOR_PROP_ACTIVE,
 	SOR_PROP_TEXT,
-	SOR_PROP_MARKUP
+	SOR_PROP_MARKUP,
+	SOR_PROP_VALUE
 };
 
 static GnmValue *
@@ -2276,6 +2277,9 @@ sheet_widget_radio_button_get_property (GObject *obj, guint param_id,
 	case SOR_PROP_MARKUP:
 		g_value_set_boxed (value, NULL); /* swrb->markup */
 		break;
+	case SOR_PROP_VALUE:
+		g_value_set_pointer (value, swrb->value);
+		break;
 	default :
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, param_id, pspec);
 		break;
@@ -2302,6 +2306,10 @@ sheet_widget_radio_button_set_property (GObject *obj, guint param_id,
 						      g_value_peek_pointer (value));
 #endif
 		break;
+	case SOR_PROP_VALUE:
+		sheet_widget_radio_button_set_value (SHEET_OBJECT (swrb),
+						      g_value_peek_pointer (value));
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, param_id, pspec);
 		return;
@@ -2793,6 +2801,10 @@ SOW_MAKE_TYPE (radio_button, RadioButton,
 			       (object_class, SOR_PROP_MARKUP,
 				g_param_spec_boxed ("markup", NULL, NULL, PANGO_TYPE_ATTR_LIST,
 						    GSF_PARAM_STATIC | G_PARAM_READWRITE));
+		       g_object_class_install_property
+			       (object_class, SOR_PROP_VALUE,
+				g_param_spec_pointer ("value", NULL, NULL,
+						    GSF_PARAM_STATIC | G_PARAM_READWRITE));
 	       })
 
 /****************************************************************************/



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