[gnumeric] cell format: use gnm_cell_get_format



commit 76914832141c6635d7ace2a21be4dc530c3cbd0f
Author: Morten Welinder <terra gnome org>
Date:   Sun Feb 14 17:47:05 2021 -0500

    cell format: use gnm_cell_get_format
    
    As opposed to old-style getting the mstyle and the format from that.
    This handles values with format better.

 src/clipboard.c                |  2 +-
 src/dialogs/dialog-goal-seek.c |  4 ++--
 src/dialogs/dialog-tabulate.c  |  2 +-
 src/stf-parse.c                |  2 +-
 src/tools/tabulate.c           | 17 +++--------------
 5 files changed, 8 insertions(+), 19 deletions(-)
---
diff --git a/src/clipboard.c b/src/clipboard.c
index 2310585cb..bf01c277c 100644
--- a/src/clipboard.c
+++ b/src/clipboard.c
@@ -297,7 +297,7 @@ paste_cell (int target_col, int target_row,
                        if (dat->translate_dates && oldval && VALUE_IS_FLOAT (oldval)) {
                                GOFormat const *fmt = VALUE_FMT (oldval)
                                        ? VALUE_FMT (oldval)
-                                       : gnm_style_get_format (gnm_cell_get_style (dst));
+                                       : gnm_cell_get_format (dst);
                                if (go_format_is_date (fmt) > 0) {
                                        gnm_float fnew = go_date_conv_translate
                                                (value_get_as_float (oldval),
diff --git a/src/dialogs/dialog-goal-seek.c b/src/dialogs/dialog-goal-seek.c
index 77f0e448a..1bb6ee0e8 100644
--- a/src/dialogs/dialog-goal-seek.c
+++ b/src/dialogs/dialog-goal-seek.c
@@ -216,7 +216,7 @@ cb_dialog_apply_clicked (G_GNUC_UNUSED GtkWidget *button,
        }
 
 
-       format = gnm_style_get_format (gnm_cell_get_style (state->set_cell));
+       format = gnm_cell_get_format (state->set_cell);
        if (entry_to_float_with_format (GTK_ENTRY(state->to_value_entry),
                                        &state->target_value, TRUE, format)){
                go_gtk_notice_nonmodal_dialog (GTK_WINDOW(state->dialog),
@@ -228,7 +228,7 @@ cb_dialog_apply_clicked (G_GNUC_UNUSED GtkWidget *button,
                return;
        }
 
-       format = gnm_style_get_format (gnm_cell_get_style (state->change_cell));
+       format = gnm_cell_get_format (state->change_cell);
        if (entry_to_float_with_format (GTK_ENTRY(state->at_least_entry),
                                         &state->xmin, TRUE, format)) {
                state->xmin = -max_range_val;
diff --git a/src/dialogs/dialog-tabulate.c b/src/dialogs/dialog-tabulate.c
index 3c72bcc15..3fc8dbbba 100644
--- a/src/dialogs/dialog-tabulate.c
+++ b/src/dialogs/dialog-tabulate.c
@@ -119,7 +119,7 @@ get_grid_float_entry (GtkGrid *g, int y, int x, GnmCell *cell, gnm_float *number
        g_return_val_if_fail (GTK_IS_ENTRY (w), 3);
 
        *wp = GTK_ENTRY (w);
-       format = gnm_style_get_format (gnm_cell_get_style (cell));
+       format = gnm_cell_get_format (cell);
 
        return (with_default?
                entry_to_float_with_format_default (*wp, number, TRUE, format,
diff --git a/src/stf-parse.c b/src/stf-parse.c
index 7a4332a05..ff6c9c1e5 100644
--- a/src/stf-parse.c
+++ b/src/stf-parse.c
@@ -1241,7 +1241,7 @@ stf_cell_set_text (GnmCell *cell, char const *text)
 {
        GnmExprTop const *texpr;
        GnmValue *val;
-       GOFormat const *fmt = gnm_style_get_format (gnm_cell_get_style (cell));
+       GOFormat const *fmt = gnm_cell_get_format (cell);
        const GODateConventions *date_conv = sheet_date_conv (cell->base.sheet);
 
        if (!go_format_is_text (fmt) && *text == '=' && text[1] != 0) {
diff --git a/src/tools/tabulate.c b/src/tools/tabulate.c
index 0eb2c3860..5608d36be 100644
--- a/src/tools/tabulate.c
+++ b/src/tools/tabulate.c
@@ -63,17 +63,6 @@ tabulation_eval (G_GNUC_UNUSED Workbook *wb, int dims, gnm_float const *x,
                : value_new_error_VALUE (NULL);
 }
 
-static GOFormat const *
-my_get_format (GnmCell const *cell)
-{
-       GOFormat const *format = gnm_style_get_format (gnm_cell_get_style (cell));
-
-       if (go_format_is_general (format) &&
-           cell->value != NULL && VALUE_FMT (cell->value) != NULL)
-               return VALUE_FMT (cell->value);
-       return format;
-}
-
 /**
  * do_tabulation:
  * @wbc: control
@@ -90,7 +79,7 @@ do_tabulation (WorkbookControl *wbc,
        GSList *sheet_idx = NULL;
        Sheet *sheet = NULL;
        gboolean sheetdim = (!data->with_coordinates && data->dims >= 3);
-       GOFormat const *targetformat = my_get_format (data->target);
+       GOFormat const *targetformat = gnm_cell_get_format (data->target);
        int row = 0;
 
        gnm_float *values = g_new (gnm_float, data->dims);
@@ -112,7 +101,7 @@ do_tabulation (WorkbookControl *wbc,
 
                        values[i] = data->minima[i];
                        index[i] = 0;
-                       formats[i] = my_get_format (data->cells[i]);
+                       formats[i] = gnm_cell_get_format (data->cells[i]);
                        old_values[i] = value_dup (data->cells[i]->value);
 
                        /* Silently truncate at the edges.  */
@@ -133,7 +122,7 @@ do_tabulation (WorkbookControl *wbc,
        if (sheetdim) {
                int dim = 2;
                gnm_float val = data->minima[dim];
-               GOFormat const *sf = my_get_format (data->cells[dim]);
+               GOFormat const *sf = gnm_cell_get_format (data->cells[dim]);
                int i;
 
                sheets = g_new (Sheet *, counts[dim]);


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