[gnumeric] GnmCell: clean up access to ->rendered_value.
- From: Morten Welinder <mortenw src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnumeric] GnmCell: clean up access to ->rendered_value.
- Date: Fri, 11 Sep 2009 17:01:05 +0000 (UTC)
commit c9f3bd708291f672dcc492aff70e0566549517a3
Author: Morten Welinder <terra gnome org>
Date: Fri Sep 11 12:56:05 2009 -0400
GnmCell: clean up access to ->rendered_value.
ChangeLog | 3 +
src/cell-draw.c | 33 +++++++---------
src/cell.c | 107 +++++++++++++++++++++++++++++++-------------------
src/cell.h | 10 ++++-
src/cellspan.c | 3 +-
src/colrow.c | 8 +--
src/dependent.c | 5 +--
src/print-cell.c | 7 +--
src/rendered-value.c | 4 +-
src/rendered-value.h | 2 +-
src/sheet.c | 58 ++++++++++-----------------
src/sheet.h | 5 +-
12 files changed, 125 insertions(+), 120 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 162999c..5b29c1b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
2009-09-11 Morten Welinder <terra gnome org>
+ * src/cell.c (gnm_cell_unrender, gnm_cell_get_rendered_value,
+ gnm_cell_fetch_rendered_value): New functions.
+
* src/gnm-so-filled.c (gnm_so_filled_draw_cairo): NULL-check
->text like elsewhere. Fixes 594862.
diff --git a/src/cell-draw.c b/src/cell-draw.c
index ed12385..bb8ee25 100644
--- a/src/cell-draw.c
+++ b/src/cell-draw.c
@@ -237,31 +237,26 @@ cell_finish_layout (GnmCell *cell, GnmRenderedValue *rv,
int dummy_h_center = -1; /* Affects position only. */
int dummy_height = 1; /* Unhandled. */
gboolean might_overflow;
+ GnmRenderedValue *cell_rv;
+
+ cell_rv = gnm_cell_get_rendered_value (cell);
if (!rv)
- rv = cell->rendered_value;
+ rv = cell_rv;
if (rv->drawn)
return;
- if (rv->variable_width && rv == cell->rendered_value) {
- GnmStyle const *mstyle = gnm_cell_get_style (cell);
- GOFormat const *fmt = gnm_cell_get_format (cell);
- if (!go_format_is_general (fmt)) {
- /*
- * We get here when entering a new value in a cell
- * with a format that has a filler, for example
- * one of the standard accounting formats. We need
- * to rerender such that the filler gets a chance
- * to expand.
- */
- cell->rendered_value =
- gnm_rendered_value_new (cell, mstyle, TRUE,
- pango_layout_get_context (rv->layout),
- cell->base.sheet->last_zoom_factor_used);
- gnm_rendered_value_destroy (rv);
- rv = cell->rendered_value;
- }
+ if (rv->variable_width && rv == cell_rv &&
+ !go_format_is_general (gnm_cell_get_format (cell))) {
+ /*
+ * We get here when entering a new value in a cell
+ * with a format that has a filler, for example
+ * one of the standard accounting formats. We need
+ * to rerender such that the filler gets a chance
+ * to expand.
+ */
+ rv = gnm_cell_render_value (cell, TRUE);
}
might_overflow = rv->might_overflow;
diff --git a/src/cell.c b/src/cell.c
index 641a46c..4a1d6dd 100644
--- a/src/cell.c
+++ b/src/cell.c
@@ -62,10 +62,9 @@ gnm_cell_cleanout (GnmCell *cell)
value_release (cell->value);
cell->value = NULL;
}
- if (cell->rendered_value != NULL) {
- gnm_rendered_value_destroy (cell->rendered_value);
- cell->rendered_value = NULL;
- }
+
+ gnm_cell_unrender (cell);
+
if (cell->row_info != NULL)
cell->row_info->needs_respan = TRUE;
}
@@ -454,33 +453,60 @@ gnm_cell_is_nonsingleton_array (GnmCell const *cell)
/***************************************************************************/
+GnmRenderedValue *
+gnm_cell_get_rendered_value (GnmCell const *cell)
+{
+ g_return_val_if_fail (cell != NULL, NULL);
+
+ return cell->rendered_value;
+}
+
+GnmRenderedValue *
+gnm_cell_fetch_rendered_value (GnmCell const *cell,
+ gboolean allow_variable_width)
+{
+ GnmRenderedValue *rv;
+
+ g_return_val_if_fail (cell != NULL, NULL);
+
+ rv = gnm_cell_get_rendered_value (cell);
+ if (rv)
+ return rv;
+
+ return gnm_cell_render_value (cell, allow_variable_width);
+}
+
+void
+gnm_cell_unrender (GnmCell const *cell)
+{
+ if (cell->rendered_value) {
+ gnm_rendered_value_destroy (cell->rendered_value);
+ ((GnmCell *)cell)->rendered_value = NULL;
+ }
+}
+
/**
* gnm_cell_render_value :
* @cell: The cell whose value needs to be rendered
* @allow_variable_width : Allow format to depend on column width.
- *
- * TODO :
- * The reason the rendered values are stored separately from the GnmCell is
- * that in the future only visible cells will be rendered. The render
- * will be SheetControl specific to allow for multiple zooms and different
- * display resolutions.
*/
-void
-gnm_cell_render_value (GnmCell *cell, gboolean allow_variable_width)
+GnmRenderedValue *
+gnm_cell_render_value (GnmCell const *cell, gboolean allow_variable_width)
{
GnmRenderedValue *rv;
Sheet *sheet;
- g_return_if_fail (cell != NULL);
+ g_return_val_if_fail (cell != NULL, NULL);
sheet = cell->base.sheet;
rv = gnm_rendered_value_new (cell, gnm_cell_get_style (cell),
allow_variable_width,
sheet->context,
sheet->last_zoom_factor_used);
- if (cell->rendered_value)
- gnm_rendered_value_destroy (cell->rendered_value);
- cell->rendered_value = rv;
+ gnm_cell_unrender (cell);
+ ((GnmCell*)cell)->rendered_value = rv;
+
+ return rv;
}
/*
@@ -491,15 +517,15 @@ gnm_cell_render_value (GnmCell *cell, gboolean allow_variable_width)
* then that is what you get.
*/
char *
-gnm_cell_get_rendered_text (GnmCell *cell)
+gnm_cell_get_rendered_text (GnmCell *cell)
{
+ GnmRenderedValue *rv;
+
g_return_val_if_fail (cell != NULL, g_strdup ("ERROR"));
- /* A precursor to just in time rendering Ick! */
- if (cell->rendered_value == NULL)
- gnm_cell_render_value (cell, TRUE);
+ rv = gnm_cell_fetch_rendered_value (cell, TRUE);
- return g_strdup (gnm_rendered_value_get_text (cell->rendered_value));
+ return g_strdup (gnm_rendered_value_get_text (rv));
}
/**
@@ -512,13 +538,13 @@ gnm_cell_get_rendered_text (GnmCell *cell)
GOColor
gnm_cell_get_render_color (GnmCell const *cell)
{
- g_return_val_if_fail (cell != NULL, 0);
+ GnmRenderedValue *rv;
- /* A precursor to just in time rendering Ick! */
- if (cell->rendered_value == NULL)
- gnm_cell_render_value ((GnmCell *)cell, TRUE);
+ g_return_val_if_fail (cell != NULL, GO_COLOR_BLACK);
- return cell->rendered_value->go_fore_color;
+ rv = gnm_cell_fetch_rendered_value (cell, TRUE);
+
+ return rv->go_fore_color;
}
/**
@@ -593,11 +619,10 @@ gnm_cell_rendered_height (GnmCell const *cell)
g_return_val_if_fail (cell != NULL, 0);
- rv = cell->rendered_value;
- if (!rv)
- return 0;
-
- return PANGO_PIXELS (cell->rendered_value->layout_natural_height);
+ rv = gnm_cell_get_rendered_value (cell);
+ return rv
+ ? PANGO_PIXELS (rv->layout_natural_height)
+ : 0;
}
/*
@@ -610,21 +635,23 @@ gnm_cell_rendered_width (GnmCell const *cell)
g_return_val_if_fail (cell != NULL, 0);
- rv = cell->rendered_value;
- if (!rv)
- return 0;
-
- return PANGO_PIXELS (cell->rendered_value->layout_natural_width);
+ rv = gnm_cell_get_rendered_value (cell);
+ return rv
+ ? PANGO_PIXELS (rv->layout_natural_width)
+ : 0;
}
int
gnm_cell_rendered_offset (GnmCell const * cell)
{
- if (!cell || !cell->rendered_value)
- return 0;
+ const GnmRenderedValue *rv;
+
+ g_return_val_if_fail (cell != NULL, 0);
- return (cell->rendered_value->indent_left +
- cell->rendered_value->indent_right);
+ rv = gnm_cell_get_rendered_value (cell);
+ return rv
+ ? rv->indent_left + rv->indent_right
+ : 0;
}
GnmStyle const *
diff --git a/src/cell.h b/src/cell.h
index 5689cd0..47c7bb7 100644
--- a/src/cell.h
+++ b/src/cell.h
@@ -54,7 +54,7 @@ gboolean gnm_cell_array_bound (GnmCell const *cell, GnmRange *res);
do { \
if (gnm_cell_needs_recalc (cell)) { \
gnm_cell_eval_content (cell); \
- cell->base.flags &= ~(DEPENDENT_NEEDS_RECALC | (int)GNM_CELL_HAS_NEW_EXPR ); \
+ (cell)->base.flags &= ~(DEPENDENT_NEEDS_RECALC | (int)GNM_CELL_HAS_NEW_EXPR ); \
} \
} while (0)
@@ -82,7 +82,13 @@ GnmStyle const *gnm_cell_get_style (GnmCell const *cell);
GOFormat const *gnm_cell_get_format (GnmCell const *cell);
void gnm_cell_set_format (GnmCell *cell, char const *format);
-void gnm_cell_render_value (GnmCell *cell, gboolean allow_variable_width);
+GnmRenderedValue *gnm_cell_get_rendered_value (GnmCell const *cell);
+GnmRenderedValue *gnm_cell_fetch_rendered_value (GnmCell const *cell,
+ gboolean allow_variable_width);
+GnmRenderedValue *gnm_cell_render_value (GnmCell const *cell,
+ gboolean allow_variable_width);
+void gnm_cell_unrender (GnmCell const *cell);
+
int gnm_cell_rendered_height (GnmCell const * cell);
int gnm_cell_rendered_width (GnmCell const * cell); /* excludes offset */
int gnm_cell_rendered_offset (GnmCell const * cell);
diff --git a/src/cellspan.c b/src/cellspan.c
index ed4e66c..f2e126b 100644
--- a/src/cellspan.c
+++ b/src/cellspan.c
@@ -407,8 +407,7 @@ row_calc_spans (ColRowInfo *ri, int row, Sheet const *sheet)
}
/* render as necessary */
- if (cell->rendered_value == NULL)
- gnm_cell_render_value ((GnmCell *)cell, TRUE);
+ (void)gnm_cell_fetch_rendered_value (cell, TRUE);
if (gnm_cell_is_merged (cell)) {
merged = gnm_sheet_merge_is_corner (sheet, &cell->pos);
diff --git a/src/colrow.c b/src/colrow.c
index 917d074..13a38f4 100644
--- a/src/colrow.c
+++ b/src/colrow.c
@@ -394,12 +394,10 @@ static GnmValue *
cb_clear_variable_width_content (GnmCellIter const *iter,
G_GNUC_UNUSED gpointer user)
{
- GnmRenderedValue *rv;
- if (NULL != (rv = iter->cell->rendered_value) &&
- rv->variable_width) {
+ GnmRenderedValue *rv = gnm_cell_get_rendered_value (iter->cell);
+ if (rv && rv->variable_width) {
iter->ri->needs_respan = TRUE;
- gnm_rendered_value_destroy (rv);
- iter->cell->rendered_value = NULL;
+ gnm_cell_unrender (iter->cell);
}
return NULL;
}
diff --git a/src/dependent.c b/src/dependent.c
index d8b11b8..02913ba 100644
--- a/src/dependent.c
+++ b/src/dependent.c
@@ -1516,10 +1516,7 @@ iterate :
value_release (cell->value);
cell->value = v;
- if (cell->rendered_value) {
- gnm_rendered_value_destroy (cell->rendered_value);
- cell->rendered_value = NULL;
- }
+ gnm_cell_unrender (cell);
}
}
diff --git a/src/print-cell.c b/src/print-cell.c
index 372753a..82fa443 100644
--- a/src/print-cell.c
+++ b/src/print-cell.c
@@ -57,7 +57,7 @@ print_cell_gtk (GnmCell const *cell, GnmStyle const *mstyle,
cairo_t *context,
double x1, double y1, double width, double height, double h_center)
{
- GnmRenderedValue *rv = cell->rendered_value, *rv100 = NULL;
+ GnmRenderedValue *rv, *rv100 = NULL;
GOColor fore_color;
gint x, y;
Sheet *sheet = cell->base.sheet;
@@ -69,10 +69,7 @@ print_cell_gtk (GnmCell const *cell, GnmStyle const *mstyle,
height -= GNM_ROW_MARGIN + GNM_ROW_MARGIN + 1;
width -= GNM_COL_MARGIN + GNM_COL_MARGIN + 1;
- if (rv == NULL) {
- gnm_cell_render_value ((GnmCell *)cell, TRUE);
- rv = cell->rendered_value;
- }
+ rv = gnm_cell_fetch_rendered_value (cell, TRUE);
/* Create a rendered value for printing */
if (sheet->last_zoom_factor_used != 1) {
diff --git a/src/rendered-value.c b/src/rendered-value.c
index c839fa9..e45374f 100644
--- a/src/rendered-value.c
+++ b/src/rendered-value.c
@@ -181,7 +181,7 @@ gnm_rendered_value_remeasure (GnmRenderedValue *rv)
* Return value: a new GnmRenderedValue
**/
GnmRenderedValue *
-gnm_rendered_value_new (GnmCell *cell, GnmStyle const *mstyle,
+gnm_rendered_value_new (GnmCell const *cell, GnmStyle const *mstyle,
gboolean allow_variable_width,
PangoContext *context,
double zoom)
@@ -207,7 +207,7 @@ gnm_rendered_value_new (GnmCell *cell, GnmStyle const *mstyle,
* If a cell has a new expression and something tries to display it we
* need to recalc the value */
if (cell->base.flags & GNM_CELL_HAS_NEW_EXPR) {
- gnm_cell_eval (cell);
+ gnm_cell_eval ((GnmCell *)cell);
}
/* Must come after above gnm_cell_eval. */
diff --git a/src/rendered-value.h b/src/rendered-value.h
index 27432a1..c9f25ed 100644
--- a/src/rendered-value.h
+++ b/src/rendered-value.h
@@ -43,7 +43,7 @@ struct _GnmRenderedRotatedValue {
} *lines;
};
-GnmRenderedValue *gnm_rendered_value_new (GnmCell *cell,
+GnmRenderedValue *gnm_rendered_value_new (GnmCell const *cell,
GnmStyle const *mstyle,
gboolean variable_width,
PangoContext *context,
diff --git a/src/sheet.c b/src/sheet.c
index 9b5506d..3238baa 100644
--- a/src/sheet.c
+++ b/src/sheet.c
@@ -163,10 +163,7 @@ cb_re_render_formulas (G_GNUC_UNUSED gpointer unused,
G_GNUC_UNUSED gpointer user)
{
if (gnm_cell_has_expr (cell)) {
- if (cell->rendered_value != NULL) {
- gnm_rendered_value_destroy (cell->rendered_value);
- cell->rendered_value = NULL;
- }
+ gnm_cell_unrender (cell);
if (cell->row_info != NULL)
cell->row_info->needs_respan = TRUE;
}
@@ -203,8 +200,8 @@ cb_sheet_set_hide_zeros (G_GNUC_UNUSED gpointer unused,
GnmCell *cell,
G_GNUC_UNUSED gpointer user)
{
- if (cell->rendered_value && gnm_cell_is_zero (cell))
- gnm_cell_render_value (cell, TRUE);
+ if (gnm_cell_is_zero (cell))
+ gnm_cell_unrender (cell);
}
static void
@@ -317,10 +314,9 @@ cb_colrow_compute_pixels_from_pts (GnmColRowIter const *iter,
static void
cb_clear_rendered_cells (gpointer ignored, GnmCell *cell)
{
- if (cell->rendered_value != NULL) {
+ if (gnm_cell_get_rendered_value (cell) != NULL) {
cell->row_info->needs_respan = TRUE;
- gnm_rendered_value_destroy (cell->rendered_value);
- cell->rendered_value = NULL;
+ gnm_cell_unrender (cell);
}
}
@@ -786,6 +782,7 @@ gnm_sheet_init (Sheet *sheet)
/* FIXME: probably not here. */
/* See also gtk_widget_create_pango_context (). */
sheet->context = gnm_pango_context_get ();
+ sheet->last_zoom_factor_used = -1; /* Overridden later */
/* Init menu states */
sheet->priv->enable_showhide_detail = TRUE;
@@ -794,12 +791,6 @@ gnm_sheet_init (Sheet *sheet)
sheet->style_data = NULL;
sheet->index_in_wb = -1;
-
- /*
- * "zoom-factor" is a construction parameter and will thus
- * override this.
- */
- sheet->last_zoom_factor_used = -1;
}
static void
@@ -1348,10 +1339,7 @@ sheet_redraw_all (Sheet const *sheet, gboolean headers)
static GnmValue *
cb_clear_rendered_values (GnmCellIter const *iter, G_GNUC_UNUSED gpointer user)
{
- if (iter->cell->rendered_value != NULL) {
- gnm_rendered_value_destroy (iter->cell->rendered_value);
- iter->cell->rendered_value = NULL;
- }
+ gnm_cell_unrender (iter->cell);
return NULL;
}
@@ -1395,24 +1383,22 @@ sheet_cell_calc_span (GnmCell *cell, GnmSpanCalcFlags flags)
CellSpanInfo const * span;
int left, right;
int min_col, max_col;
- gboolean render = (flags & GNM_SPANCALC_RE_RENDER);
- gboolean const resize = (flags & GNM_SPANCALC_RESIZE);
+ gboolean render = (flags & GNM_SPANCALC_RE_RENDER) != 0;
+ gboolean const resize = (flags & GNM_SPANCALC_RESIZE) != 0;
gboolean existing = FALSE;
GnmRange const *merged;
g_return_if_fail (cell != NULL);
/* Render & Size any unrendered cells */
- if ((flags & GNM_SPANCALC_RENDER) && cell->rendered_value == NULL)
+ if ((flags & GNM_SPANCALC_RENDER) && gnm_cell_get_rendered_value (cell) == NULL)
render = TRUE;
if (render) {
if (!gnm_cell_has_expr (cell))
gnm_cell_render_value ((GnmCell *)cell, TRUE);
- else if (cell->rendered_value) {
- gnm_rendered_value_destroy (cell->rendered_value);
- cell->rendered_value = NULL;
- }
+ else
+ gnm_cell_unrender (cell);
} else if (resize) {
/* FIXME: what was wanted here? */
/* rendered_value_calc_size (cell); */
@@ -2136,6 +2122,7 @@ cb_max_cell_width (GnmCellIter const *iter, struct cb_fit *data)
{
int width;
GnmCell *cell = iter->cell;
+ GnmRenderedValue *rv;
if (gnm_cell_is_merged (cell))
return NULL;
@@ -2152,8 +2139,8 @@ cb_max_cell_width (GnmCellIter const *iter, struct cb_fit *data)
return NULL;
/* Variable width cell must be re-rendered */
- if (cell->rendered_value == NULL ||
- cell->rendered_value->variable_width)
+ rv = gnm_cell_get_rendered_value (cell);
+ if (rv == NULL || rv->variable_width)
gnm_cell_render_value (cell, FALSE);
/* Make sure things are as-if drawn. */
@@ -2232,12 +2219,12 @@ cb_max_cell_height (GnmCellIter const *iter, struct cb_fit *data)
* that they are all the same height, more or less.
*/
Sheet const *sheet = cell->base.sheet;
- height = gnm_style_get_pango_height (gnm_cell_get_style (cell),
- sheet->context,
- sheet->last_zoom_factor_used);
+ height = sheet->last_zoom_factor_used *
+ gnm_style_get_pango_height (gnm_cell_get_style (cell),
+ sheet->context,
+ sheet->last_zoom_factor_used);
} else {
- if (cell->rendered_value == NULL)
- gnm_cell_render_value (cell, TRUE);
+ (void)gnm_cell_fetch_rendered_value (cell, TRUE);
/* Make sure things are as-if drawn. Inhibit #####s. */
cell_finish_layout (cell, NULL, iter->ci->size_pixels, FALSE);
@@ -3590,10 +3577,7 @@ sheet_cell_add_to_hash (Sheet *sheet, GnmCell *cell)
(void) sheet_col_fetch (sheet, cell->pos.col);
cell->row_info = sheet_row_fetch (sheet, cell->pos.row);
- if (cell->rendered_value) {
- gnm_rendered_value_destroy (cell->rendered_value);
- cell->rendered_value = NULL;
- }
+ gnm_cell_unrender (cell);
g_hash_table_insert (sheet->cell_hash, &cell->pos, cell);
diff --git a/src/sheet.h b/src/sheet.h
index 13e01db..51c42b9 100644
--- a/src/sheet.h
+++ b/src/sheet.h
@@ -51,7 +51,9 @@ struct _Sheet {
GnmNamedExprCollection *names;
+ /* This should eventually be moved to the views. */
double last_zoom_factor_used;
+ PangoContext *context;
GSList *sheet_objects; /* List of objects in this sheet */
GnmCellPos max_object_extent;
@@ -108,9 +110,6 @@ struct _Sheet {
GnmColor *tab_text_color;
GnmSheetType sheet_type;
- /* This needs to move elsewhere and get shared. */
- PangoContext *context;
-
GnmSheetSize size;
/* tile related data */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]