[gnumeric] Import & export list validation from and to ODF files. [#640701]
- From: Andreas J. Guelzow <guelzow src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Import & export list validation from and to ODF files. [#640701]
- Date: Wed, 16 Feb 2011 08:01:05 +0000 (UTC)
commit 0370701f6727e6003c6b7ca4e3c34fe67f20eb8f
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date: Wed Feb 16 01:04:24 2011 -0700
Import & export list validation from and to ODF files. [#640701]
2011-02-16 Andreas J. Guelzow <aguelzow pyrshep ca>
* openoffice-read.c (odf_validation_new_list): also read
expressions as allowed in ODF1.2
(odf_validations_translate): add a few stubs for other
validation types.
* openoffice-write.c (odf_write_objects): don't write
validation combos
(odf_write_cell): write validation name
(odf_validation_general_attributes): new
(odf_validation_in_list): new
(odf_print_spreadsheet_content_validations): new
(odf_print_spreadsheet_content_prelude): connect the above
2011-02-15 Andreas J. Guelzow <aguelzow pyrshep ca>
* src/validation-combo.h (IS_GNM_VALIDATION_COMBO): new
ChangeLog | 4 +
NEWS | 2 +-
plugins/openoffice/ChangeLog | 17 +++++-
plugins/openoffice/openoffice-read.c | 37 +++++++++++-
plugins/openoffice/openoffice-write.c | 105 ++++++++++++++++++++++++++++++++-
src/validation-combo.h | 1 +
6 files changed, 160 insertions(+), 6 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index bb5b724..8588933 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2011-02-15 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+ * src/validation-combo.h (IS_GNM_VALIDATION_COMBO): new
+
2011-02-07 Andreas J. Guelzow <aguelzow pyrshep ca>
* schemas/gnumeric-dialogs.schemas.in
diff --git a/NEWS b/NEWS
index 5fbb2a1..d7099b8 100644
--- a/NEWS
+++ b/NEWS
@@ -3,7 +3,7 @@ Gnumeric 1.10.14
Andreas:
* Fix width of translated lists in various dialogs [#641626]
* Allow function tooltips to be closed temporarily [#641355]
- * Import list validation from ODF files. [#640701]
+ * Import & export list validation from and to ODF files. [#640701]
Jean:
* Fix cursor position inside a cell edited in a zoomed sheet. [#641709]
diff --git a/plugins/openoffice/ChangeLog b/plugins/openoffice/ChangeLog
index af6d81f..41036b9 100644
--- a/plugins/openoffice/ChangeLog
+++ b/plugins/openoffice/ChangeLog
@@ -1,8 +1,23 @@
+2011-02-16 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+ * openoffice-read.c (odf_validation_new_list): also read
+ expressions as allowed in ODF1.2
+ (odf_validations_translate): add a few stubs for other
+ validation types.
+ * openoffice-write.c (odf_write_objects): don't write
+ validation combos
+ (odf_write_cell): write validation name
+ (odf_validation_general_attributes): new
+ (odf_validation_in_list): new
+ (odf_print_spreadsheet_content_validations): new
+ (odf_print_spreadsheet_content_prelude): connect the above
+
2011-02-15 Andreas J. Guelzow <aguelzow pyrshep ca>
* openoffice-read.c (odf_validation_t): add field
(odf_validation_new_list): new
- (odf_validations_translate): call odf_validation_new_list if applicable
+ (odf_validations_translate): call odf_validation_new_list
+ if applicable
(odf_validation_new): initialize new field
(odf_validation): determine name space
diff --git a/plugins/openoffice/openoffice-read.c b/plugins/openoffice/openoffice-read.c
index a5edc5f..e262616 100644
--- a/plugins/openoffice/openoffice-read.c
+++ b/plugins/openoffice/openoffice-read.c
@@ -1435,9 +1435,14 @@ odf_validation_new_list (GsfXMLIn *xin, odf_validation_t *val)
}
}
- str = g_string_new ("{");
- g_string_append_len (str, start + 1, end - start - 1);
- g_string_append_c (str, '}');
+ if (*(start + 1) == '\"') {
+ str = g_string_new ("{");
+ g_string_append_len (str, start + 1, end - start - 1);
+ g_string_append_c (str, '}');
+ } else {
+ str = g_string_new (NULL);
+ g_string_append_len (str, start + 1, end - start - 1);
+ }
texpr = oo_expr_parse_str (xin, str->str, &pp,
GNM_EXPR_PARSE_DEFAULT,
@@ -1476,6 +1481,32 @@ odf_validations_translate (GsfXMLIn *xin, char const *name)
if (g_str_has_prefix (val->condition, "cell-content-is-in-list"))
validation = odf_validation_new_list (xin, val);
+ else if (g_str_has_prefix (val->condition,
+ "cell-content-text-length()"))
+ /* validation = odf_validation_new_ (xin, val) */;
+ else if (g_str_has_prefix (val->condition,
+ "cell-content-text-length-is-between"))
+ /* validation = odf_validation_new_ (xin, val) */;
+ else if (g_str_has_prefix
+ (val->condition,
+ "cell-content-text-length-is-not-between"))
+ /* validation = odf_validation_new_ (xin, val) */;
+ else if (g_str_has_prefix
+ (val->condition,
+ "cell-content-is-decimal-number () and"))
+ /* validation = odf_validation_new_ (xin, val) */;
+ else if (g_str_has_prefix
+ (val->condition,
+ "cell-content-is-whole-number() and"))
+ /* validation = odf_validation_new_ (xin, val) */;
+ else if (g_str_has_prefix (val->condition,
+ "cell-content-is-date() and"))
+ /* validation = odf_validation_new_ (xin, val) */;
+ else if (g_str_has_prefix (val->condition,
+ "cell-content-is-time() and "))
+ /* validation = odf_validation_new_ (xin, val) */;
+ else if (g_str_has_prefix (val->condition, "is-true-formula"))
+ /* validation = odf_validation_new_ (xin, val) */;
if (validation != NULL) {
GError *err;
diff --git a/plugins/openoffice/openoffice-write.c b/plugins/openoffice/openoffice-write.c
index 83fd0f3..a015143 100644
--- a/plugins/openoffice/openoffice-write.c
+++ b/plugins/openoffice/openoffice-write.c
@@ -50,6 +50,7 @@
#include <input-msg.h>
#include <style-border.h>
#include <validation.h>
+#include <validation-combo.h>
#include <hlink.h>
#include <sheet-filter.h>
#include <print-info.h>
@@ -2741,7 +2742,7 @@ odf_write_objects (GnmOOExport *state, GSList *objects)
g_warning ("NULL sheet object encountered.");
continue;
}
- if (IS_GNM_FILTER_COMBO (so))
+ if (IS_GNM_FILTER_COMBO (so) || IS_GNM_VALIDATION_COMBO(so))
continue;
if (id != NULL)
odf_write_control (state, so, id);
@@ -2788,9 +2789,17 @@ odf_write_empty_cell (GnmOOExport *state, int num, GnmStyle const *style, GSList
num);
if (style != NULL) {
char const * name = odf_find_style (state, style);
+ GnmValidation const *val = gnm_style_get_validation (style);
if (name != NULL)
gsf_xml_out_add_cstr (state->xml,
TABLE "style-name", name);
+ if (val != NULL) {
+ char *vname = g_strdup_printf ("VAL-%p", val);
+ gsf_xml_out_add_cstr (state->xml,
+ TABLE "content-validation-name", vname);
+ g_free (vname);
+ }
+
}
odf_write_objects (state, objects);
gsf_xml_out_end_element (state->xml); /* table-cell */
@@ -2839,9 +2848,16 @@ odf_write_cell (GnmOOExport *state, GnmCell *cell, GnmRange const *merge_range,
if (style) {
char const * name = odf_find_style (state, style);
+ GnmValidation const *val = gnm_style_get_validation (style);
if (name != NULL)
gsf_xml_out_add_cstr (state->xml,
TABLE "style-name", name);
+ if (val != NULL) {
+ char *vname = g_strdup_printf ("VAL-%p", val);
+ gsf_xml_out_add_cstr (state->xml,
+ TABLE "content-validation-name", vname);
+ g_free (vname);
+ }
link = gnm_style_get_hlink (style);
}
@@ -3719,6 +3735,91 @@ odf_write_autofilter (GnmOOExport *state, GnmFilter const *filter)
}
static void
+odf_validation_general_attributes (GnmOOExport *state, GnmValidation const *val)
+{
+ char *name = g_strdup_printf ("VAL-%p", val);
+
+ gsf_xml_out_add_cstr (state->xml, TABLE "name", name);
+ g_free (name);
+ odf_add_bool (state->xml, TABLE "allow-empty-cell", val->allow_blank);
+ gsf_xml_out_add_cstr (state->xml, TABLE "display-list",
+ val->use_dropdown ? "unsorted" : "none");
+}
+
+static void
+odf_validation_in_list (GnmOOExport *state, GnmValidation const *val,
+ Sheet *sheet, GnmStyleRegion const *sr)
+{
+ GnmExprTop const *texpr;
+ GnmParsePos pp;
+ char *formula;
+ GnmCellRef ref;
+ GString *str;
+
+ gnm_cellref_init (&ref, sheet,
+ sr->range.start.col,
+ sr->range.start.row, TRUE);
+ texpr = gnm_expr_top_new (gnm_expr_new_cellref (&ref));
+ parse_pos_init (&pp, (Workbook *)state->wb, sheet,
+ sr->range.start.col,
+ sr->range.start.row);
+ formula = gnm_expr_top_as_string (texpr, &pp, state->conv);
+ gsf_xml_out_add_cstr (state->xml, TABLE "base-cell-address",
+ odf_strip_brackets (formula));
+ g_free (formula);
+ gnm_expr_top_unref (texpr);
+
+ /* Note that this is really not valid ODF1.1 but will be valid in ODF1.2 */
+ formula = gnm_expr_top_as_string (val->texpr[0], &pp, state->conv);
+ str = g_string_new ("of:cell-content-is-in-list(");
+ g_string_append (str, formula);
+ g_string_append_c (str, ')');
+
+ g_free (formula);
+ gsf_xml_out_add_cstr (state->xml, TABLE "condition", str->str);
+ g_string_free (str, TRUE);
+}
+
+static void
+odf_print_spreadsheet_content_validations (GnmOOExport *state)
+{
+ gboolean element_written = FALSE;
+ int i;
+
+ for (i = 0; i < workbook_sheet_count (state->wb); i++) {
+ Sheet *sheet = workbook_sheet_by_index (state->wb, i);
+ GnmStyleList *list, *l;
+
+ list = sheet_style_collect_validations (sheet, NULL);
+
+ for (l = list; l != NULL; l = l->next) {
+ GnmStyleRegion const *sr = l->data;
+ GnmValidation const *val = gnm_style_get_validation (sr->style);
+
+ if (val->type == VALIDATION_TYPE_IN_LIST) {
+ if (!element_written) {
+ gsf_xml_out_start_element
+ (state->xml, TABLE "content-validations");
+ element_written = TRUE;
+ }
+ gsf_xml_out_start_element (state->xml,
+ TABLE "content-validation");
+ odf_validation_general_attributes (state, val);
+ odf_validation_in_list (state, val, sheet, sr);
+ gsf_xml_out_end_element (state->xml);
+ /* </table:content-validation> */
+ }
+ }
+
+ style_list_free (list);
+ }
+
+ if (element_written)
+ gsf_xml_out_end_element (state->xml); /* </table:content-validations> */
+
+}
+
+static void
odf_print_spreadsheet_content_prelude (GnmOOExport *state)
{
gsf_xml_out_start_element (state->xml, TABLE "calculation-settings");
@@ -3746,6 +3847,8 @@ odf_print_spreadsheet_content_prelude (GnmOOExport *state)
gsf_xml_out_add_int (state->xml, TABLE "steps", state->wb->iteration.max_number);
gsf_xml_out_end_element (state->xml); /* </table:iteration> */
gsf_xml_out_end_element (state->xml); /* </table:calculation-settings> */
+
+ odf_print_spreadsheet_content_validations (state);
}
diff --git a/src/validation-combo.h b/src/validation-combo.h
index 7469f9d..cb12c6d 100644
--- a/src/validation-combo.h
+++ b/src/validation-combo.h
@@ -13,6 +13,7 @@ typedef struct {
} GnmValidationCombo;
#define GNM_VALIDATION_COMBO_TYPE (gnm_validation_combo_get_type ())
+#define IS_GNM_VALIDATION_COMBO(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GNM_VALIDATION_COMBO_TYPE))
#define GNM_VALIDATION_COMBO(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GNM_VALIDATION_COMBO_TYPE, GnmValidationCombo))
GType gnm_validation_combo_get_type (void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]