[gnumeric] Import/export checkboxes from and to ODF files.
- From: Andreas J. Guelzow <guelzow src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Import/export checkboxes from and to ODF files.
- Date: Wed, 8 Sep 2010 17:04:31 +0000 (UTC)
commit 9b0de1e8d616f8fe2532039cd933b2eeebe4f38a
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date: Wed Sep 8 11:01:31 2010 -0600
Import/export checkboxes from and to ODF files.
2010-09-08 Andreas J. Guelzow <aguelzow pyrshep ca>
* openoffice-read.c (od_draw_control_start): handle checkboxes
(oo_control_free): free new label field
(odf_form_control): new
(odf_form_value_range): use odf_form_control
(odf_form_checkbox): new
(opendoc_content_dtd): connect odf_form_checkbox
* openoffice-write.c (odf_write_sheet_control_linked_cell): new
(odf_write_sheet_control_scrollbar): use
odf_write_sheet_control_linked_cell
(odf_write_sheet_control_checkbox): new
(odf_write_sheet_controls): also handle checkboxes
NEWS | 2 +-
plugins/openoffice/ChangeLog | 14 ++++++
plugins/openoffice/openoffice-read.c | 74 +++++++++++++++++++++++----------
plugins/openoffice/openoffice-write.c | 61 +++++++++++++++++++++------
4 files changed, 114 insertions(+), 37 deletions(-)
---
diff --git a/NEWS b/NEWS
index 4e21385..ae025f8 100644
--- a/NEWS
+++ b/NEWS
@@ -4,7 +4,7 @@ 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 from and to ODF files.
+ * Import/export scrollbars and checkboxes from and to ODF files.
--------------------------------------------------------------------------
Gnumeric 1.10.10
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index a121b8d..52bd3ae 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,5 +1,19 @@
2010-09-08 Andreas J. Guelzow <aguelzow pyrshep ca>
+ * openoffice-read.c (od_draw_control_start): handle checkboxes
+ (oo_control_free): free new label field
+ (odf_form_control): new
+ (odf_form_value_range): use odf_form_control
+ (odf_form_checkbox): new
+ (opendoc_content_dtd): connect odf_form_checkbox
+ * openoffice-write.c (odf_write_sheet_control_linked_cell): new
+ (odf_write_sheet_control_scrollbar): use
+ odf_write_sheet_control_linked_cell
+ (odf_write_sheet_control_checkbox): new
+ (odf_write_sheet_controls): also handle checkboxes
+
+2010-09-08 Andreas J. Guelzow <aguelzow pyrshep ca>
+
* openoffice-read.c (odf_form_value_range): fix attribute name and
also read gnm:linked_cell
* openoffice-write.c (odf_write_frame): write frame or control
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index 062e68c..3208c5e 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -187,6 +187,7 @@ typedef struct {
int page_step;
gnm_float value;
char *linked_cell;
+ char *label;
} OOControl;
typedef struct {
@@ -4670,28 +4671,34 @@ od_draw_control_start (GsfXMLIn *xin, xmlChar const **attrs)
OOControl *oc = g_hash_table_lookup (state->controls, name);
if (oc != NULL) {
SheetObject *so;
- GtkAdjustment *adj;
- int min_real = (oc->min < oc->max) ? oc->min : oc->max;
- int max_real = (oc->min < oc->max) ? oc->max : oc->min;
- gnm_float value_real = oc->value;
- if (value_real < (gnm_float)min_real)
- value_real = min_real;
- if (value_real > (gnm_float)max_real)
- value_real = max_real;
+ if (oc->t == sheet_widget_scrollbar_get_type ()) {
+ GtkAdjustment *adj;
+ int min_real = (oc->min < oc->max) ? oc->min : oc->max;
+ int max_real = (oc->min < oc->max) ? oc->max : oc->min;
+ gnm_float value_real = oc->value;
+ if (value_real < (gnm_float)min_real)
+ value_real = min_real;
+ if (value_real > (gnm_float)max_real)
+ value_real = max_real;
- so = state->chart.so = g_object_new
- (oc->t, "horizontal", oc->horizontal, NULL);
- adj = sheet_widget_adjustment_get_adjustment (so);
+ so = state->chart.so = g_object_new
+ (oc->t, "horizontal", oc->horizontal, NULL);
+ adj = sheet_widget_adjustment_get_adjustment (so);
- gtk_adjustment_configure (adj,
- value_real,
- min_real,
- max_real,
- oc->step,
- oc->page_step,
- 0);
+ gtk_adjustment_configure (adj,
+ value_real,
+ min_real,
+ max_real,
+ oc->step,
+ oc->page_step,
+ 0);
+ } else if (oc->t == sheet_widget_checkbox_get_type ()) {
+ so = state->chart.so = g_object_new
+ (oc->t, "text", oc->label, NULL);
+ }
od_draw_frame_end (xin, NULL);
+
if (oc->linked_cell) {
GnmParsePos pp;
@@ -4705,8 +4712,12 @@ od_draw_control_start (GsfXMLIn *xin, xmlChar const **attrs)
GnmExprTop const *texpr
= gnm_expr_top_new_constant (v);
if (texpr != NULL) {
- sheet_widget_adjustment_set_link
- (so, texpr);
+ if (oc->t == sheet_widget_scrollbar_get_type ())
+ sheet_widget_adjustment_set_link
+ (so, texpr);
+ else if (oc->t == sheet_widget_checkbox_get_type ())
+ sheet_widget_checkbox_set_link
+ (so, texpr);
gnm_expr_top_unref (texpr);
}
}
@@ -5987,6 +5998,7 @@ oo_chart_style_free (OOChartStyle *cstyle)
static void
oo_control_free (OOControl *ctrl)
{
+ g_free (ctrl->label);
g_free (ctrl->linked_cell);
g_free (ctrl);
}
@@ -6034,7 +6046,7 @@ odf_annotation_end (GsfXMLIn *xin, G_GNUC_UNUSED GsfXMLBlob *blob)
/******************************** controls ******************************/
static void
-odf_form_value_range (GsfXMLIn *xin, xmlChar const **attrs)
+odf_form_control (GsfXMLIn *xin, xmlChar const **attrs, GType t)
{
OOControl *oc = g_new0 (OOControl, 1);
OOParseState *state = (OOParseState *)xin->user_state;
@@ -6078,16 +6090,32 @@ odf_form_value_range (GsfXMLIn *xin, xmlChar const **attrs)
OO_GNUM_NS_EXT, "linked-cell")) {
g_free (oc->linked_cell);
oc->linked_cell = g_strdup (CXML2C (attrs[1]));
+ } else if (gsf_xml_in_namecmp (xin, CXML2C (attrs[0]),
+ OO_NS_FORM, "label")) {
+ g_free (oc->label);
+ oc->label = g_strdup (CXML2C (attrs[1]));
}
if (name != NULL) {
- oc->t = sheet_widget_scrollbar_get_type ();
+ oc->t = t;
g_hash_table_replace (state->controls, name, oc);
} else
oo_control_free (oc);
}
+static void
+odf_form_value_range (GsfXMLIn *xin, xmlChar const **attrs)
+{
+ odf_form_control (xin, attrs, sheet_widget_scrollbar_get_type ());
+}
+
+static void
+odf_form_checkbox (GsfXMLIn *xin, xmlChar const **attrs)
+{
+ odf_form_control (xin, attrs, sheet_widget_checkbox_get_type ());
+}
+
/****************************************************************************/
/******************************** settings.xml ******************************/
@@ -6689,6 +6717,8 @@ static GsfXMLInNode const opendoc_content_dtd [] =
GSF_XML_IN_NODE (FORM_EVENT_LISTENERS, SCRIPT_LISTENER, OO_NS_SCRIPT, "event-listener", GSF_XML_NO_CONTENT, NULL, NULL),
GSF_XML_IN_NODE (FORM, FORM_VALUE_RANGE, OO_NS_FORM, "value-range", GSF_XML_NO_CONTENT, &odf_form_value_range, NULL),
GSF_XML_IN_NODE (FORM_VALUE_RANGE, FORM_PROPERTIES, OO_NS_FORM, "properties", GSF_XML_NO_CONTENT, NULL, NULL), /* 2nd Def */
+ GSF_XML_IN_NODE (FORM, FORM_CHECKBOX, OO_NS_FORM, "checkbox", GSF_XML_NO_CONTENT, &odf_form_checkbox, NULL),
+ GSF_XML_IN_NODE (FORM_CHECKBOX, FORM_PROPERTIES, OO_NS_FORM, "properties", GSF_XML_NO_CONTENT, NULL, NULL), /* 2nd Def */
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 f868cd9..5e18b59 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -3084,6 +3084,26 @@ odf_write_sheet_controls_get_id (GnmOOExport *state, SheetObject *so)
}
static void
+odf_write_sheet_control_linked_cell (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 "linked-cell",
+ odf_strip_brackets (link));
+ else
+ gsf_xml_out_add_cstr (state->xml, GNMSTYLE "linked-cell",
+ odf_strip_brackets (link));
+ g_free (link);
+ }
+}
+
+static void
odf_write_sheet_control_scrollbar (GnmOOExport *state, SheetObject *so)
{
char const *id = odf_write_sheet_controls_get_id (state, so);
@@ -3110,27 +3130,38 @@ odf_write_sheet_control_scrollbar (GnmOOExport *state, SheetObject *so)
/* crashes OOo */
/* gsf_xml_out_add_cstr (state->xml, FORM "control-implementation", */
/* OOO "com.sun.star.form.component.ScrollBar"); */
- 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 "linked-cell",
- odf_strip_brackets (link));
- else
- gsf_xml_out_add_cstr (state->xml, GNMSTYLE "linked-cell",
- odf_strip_brackets (link));
- g_free (link);
- }
+ odf_write_sheet_control_linked_cell (state, texpr);
gnm_expr_top_unref (texpr);
gsf_xml_out_end_element (state->xml); /* form:value-range */
}
static void
+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;
+
+ g_object_get (G_OBJECT (so), "text", &label, NULL);
+
+ gsf_xml_out_start_element (state->xml, FORM "checkbox");
+ 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);
+
+ 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
odf_write_sheet_controls (GnmOOExport *state)
{
Sheet const *sheet = state->sheet;
@@ -3146,6 +3177,8 @@ odf_write_sheet_controls (GnmOOExport *state)
if (GNM_IS_SOW_SCROLLBAR (so))
odf_write_sheet_control_scrollbar (state, so);
+ else if (GNM_IS_SOW_CHECKBOX (so))
+ odf_write_sheet_control_checkbox (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]