Commit 0370701f authored by Andreas J. Guelzow 's avatar Andreas J. Guelzow

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
parent 3648f48d
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
......
......@@ -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]
......
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
......
......@@ -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;
......
......@@ -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);
}
......@@ -3718,6 +3734,91 @@ odf_write_autofilter (GnmOOExport *state, GnmFilter const *filter)
gsf_xml_out_end_element (state->xml); /* </table:database-range> */
}
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)
{
......@@ -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);
}
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment