gnumeric r16777 - in trunk: . src
- From: jody svn gnome org
- To: svn-commits-list gnome org
- Subject: gnumeric r16777 - in trunk: . src
- Date: Sun, 7 Sep 2008 18:32:15 +0000 (UTC)
Author: jody
Date: Sun Sep 7 18:32:15 2008
New Revision: 16777
URL: http://svn.gnome.org/viewvc/gnumeric?rev=16777&view=rev
Log:
2008-09-07 Jody Goldberg <jody gnome org>
* src/sheet.c (sheet_scale_changed) : split from.
(sheet_set_zoom_factor) : here.
(sheet_set_display_formulas) : used here.
* src/print-cell.c (gnm_gtk_print_cell_range) : handle the doubling of
column width during 'display forumla' mode.
* src/expr.c (gnm_expr_top_is_array) : new.
* src/rendered-value.c (gnm_rendered_value_new) : Use a simpler syntax
to denote arrays. The full form used in the entry is too verboase.
Modified:
trunk/ChangeLog
trunk/NEWS
trunk/src/cell.c
trunk/src/cell.h
trunk/src/colrow.c
trunk/src/expr.c
trunk/src/expr.h
trunk/src/print-cell.c
trunk/src/rendered-value.c
trunk/src/sheet.c
trunk/src/workbook-view.c
Modified: trunk/NEWS
==============================================================================
--- trunk/NEWS (original)
+++ trunk/NEWS Sun Sep 7 18:32:15 2008
@@ -12,13 +12,14 @@
Jody:
* Extend ssgrep to search VBA too.
+ * Add column width doubling in 'display formula' mode.
J.H.M. Dassen (Ray):
* Understand and ignore byte-order markers for CSV/stf probing and
importing. [#549743]
Morten:
- * Fix display of array formulas. [#550902]
+ * Fix display of array formulas. [#550902]
--------------------------------------------------------------------------
Gnumeric 1.9.2
Modified: trunk/src/cell.c
==============================================================================
--- trunk/src/cell.c (original)
+++ trunk/src/cell.c Sun Sep 7 18:32:15 2008
@@ -26,7 +26,6 @@
#include "sheet-style.h"
#include "parse-util.h"
#include <goffice/utils/go-glib-extras.h>
-#include <goffice/utils/go-locale.h>
/**
* gnm_cell_cleanout :
@@ -565,50 +564,6 @@
}
-char *
-gnm_cell_get_displayed_text (GnmCell const *cell)
-{
- if (gnm_cell_has_expr (cell)) {
- GnmExprTop const *texpr = cell->base.texpr;
- GnmCell const *corner = NULL;
- int x = 0, y = 0;
-
- if (gnm_expr_top_is_array_corner (texpr))
- corner = cell;
- else if (gnm_expr_top_is_array_elem (texpr, &x, &y)) {
- corner = sheet_cell_get
- (cell->base.sheet,
- cell->pos.col - x,
- cell->pos.row - y);
- }
-
- if (corner) {
- GnmExprArrayCorner const *ac =
- gnm_cell_is_array_corner (corner);
- GnmParsePos pp;
- GnmConventionsOut out;
-
- out.accum = g_string_new ("={");
- out.pp = parse_pos_init_cell (&pp, cell);
- out.convs = cell->base.sheet->convs;
-
- gnm_expr_top_as_gstring (cell->base.texpr, &out);
-
- g_string_append_printf (out.accum,
- "}(%d%c%d)[%d][%d]",
- ac->cols,
- go_locale_get_arg_sep (),
- ac->rows,
- x, y);
-
- return g_string_free (out.accum, FALSE);
- }
- }
-
- return gnm_cell_get_entered_text (cell);
-}
-
-
/*
* Return the height of the rendered layout after rotation.
*/
Modified: trunk/src/cell.h
==============================================================================
--- trunk/src/cell.h (original)
+++ trunk/src/cell.h Sun Sep 7 18:32:15 2008
@@ -83,12 +83,11 @@
void gnm_cell_set_format (GnmCell *cell, char const *format);
void gnm_cell_render_value (GnmCell *cell, gboolean allow_variable_width);
-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);
-GOColor gnm_cell_get_render_color (GnmCell const *cell);
-char * gnm_cell_get_entered_text (GnmCell const *cell);
-char * gnm_cell_get_displayed_text (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);
+GOColor gnm_cell_get_render_color (GnmCell const * cell);
+char * gnm_cell_get_entered_text (GnmCell const * cell);
char * gnm_cell_get_rendered_text (GnmCell *cell);
G_END_DECLS
Modified: trunk/src/colrow.c
==============================================================================
--- trunk/src/colrow.c (original)
+++ trunk/src/colrow.c Sun Sep 7 18:32:15 2008
@@ -40,11 +40,15 @@
Sheet const *sheet, gboolean horizontal)
{
int const margin = horizontal ? 2*GNM_COL_MARGIN : 2*GNM_ROW_MARGIN;
- double const scale =
+ double scale =
sheet->last_zoom_factor_used *
gnm_app_display_dpi_get (horizontal) / 72.;
+ if (horizontal && sheet->display_formulas)
+ scale *= 2;
+
cri->size_pixels = (int)(cri->size_pts * scale + 0.5);
+
if (cri->size_pixels <= margin)
cri->size_pixels = margin + 1;
}
@@ -53,10 +57,13 @@
colrow_compute_pts_from_pixels (ColRowInfo *cri,
Sheet const *sheet, gboolean horizontal)
{
- double const scale =
+ double scale =
sheet->last_zoom_factor_used *
gnm_app_display_dpi_get (horizontal) / 72.;
+ if (horizontal && sheet->display_formulas)
+ scale *= 2;
+
cri->size_pts = cri->size_pixels / scale;
#if 0
/* Disable this until we decide how to deal with scaling */
Modified: trunk/src/expr.c
==============================================================================
--- trunk/src/expr.c (original)
+++ trunk/src/expr.c Sun Sep 7 18:32:15 2008
@@ -2953,6 +2953,14 @@
return TRUE;
}
+gboolean
+gnm_expr_top_is_array (GnmExprTop const *texpr)
+{
+ g_return_val_if_fail (IS_GNM_EXPR_TOP (texpr), FALSE);
+ return (GNM_EXPR_GET_OPER (texpr->expr) == GNM_EXPR_OP_ARRAY_ELEM ||
+ GNM_EXPR_GET_OPER (texpr->expr) == GNM_EXPR_OP_ARRAY_CORNER);
+}
+
GnmExprTop const *
gnm_expr_top_transpose (GnmExprTop const *texpr)
{
Modified: trunk/src/expr.h
==============================================================================
--- trunk/src/expr.h (original)
+++ trunk/src/expr.h Sun Sep 7 18:32:15 2008
@@ -121,6 +121,7 @@
gboolean gnm_expr_top_is_array_elem (GnmExprTop const *texpr, int *x, int *y);
gboolean gnm_expr_top_is_array_corner (GnmExprTop const *texpr);
GnmExprArrayCorner const *gnm_expr_top_get_array_corner (GnmExprTop const *texpr);
+gboolean gnm_expr_top_is_array (GnmExprTop const *texpr);
GnmValue *gnm_expr_top_get_range (GnmExprTop const *texpr);
GSList *gnm_expr_top_get_ranges (GnmExprTop const *texpr);
GnmValue const *gnm_expr_top_get_constant (GnmExprTop const *texpr);
Modified: trunk/src/print-cell.c
==============================================================================
--- trunk/src/print-cell.c (original)
+++ trunk/src/print-cell.c Sun Sep 7 18:32:15 2008
@@ -263,6 +263,7 @@
{
ColRowInfo const *ri = NULL, *next_ri = NULL;
int const dir = sheet->text_is_rtl ? -1 : 1;
+ float const hscale = sheet->display_formulas ? 2 : 1;
int start_row, start_col, end_col, end_row;
GnmStyleRow sr, next_sr;
@@ -468,10 +469,10 @@
}
if (dir < 0)
- x -= ci->size_pts;
+ x -= ci->size_pts * hscale;
style = sr.styles [col];
print_cell_background_gtk (context, style, col, row, x, y,
- ci->size_pts, ri->size_pts);
+ ci->size_pts * hscale, ri->size_pts);
/* Is this part of a span?
* 1) There are cells allocated in the row
@@ -479,31 +480,27 @@
* 2) Look in the rows hash table to see if
* there is a span descriptor.
*/
- if (NULL == ri->spans || NULL == (span = row_span_get (ri, col)))
- {
-
+ if (NULL == ri->spans || NULL == (span = row_span_get (ri, col))) {
/* no need to draw blanks */
GnmCell const *cell = sheet_cell_get (sheet, col, row);
if (!gnm_cell_is_empty (cell))
- print_cell_gtk (cell, style,
- context,
- x, y,
- ci->size_pts, ri->size_pts, -1.);
+ print_cell_gtk (cell, style, context, x, y,
+ ci->size_pts * hscale,
+ ri->size_pts, -1.);
/* Only draw spaning cells after all the backgrounds
* that we are going to draw have been drawn. No need
* to draw the edit cell, or blanks.
*/
- }
- else if (col == span->right || col == end_col) {
+ } else if (col == span->right || col == end_col) {
GnmCell const *cell = span->cell;
int const start_span_col = span->left;
int const end_span_col = span->right;
double real_x = x;
ColRowInfo const *cell_col =
sheet_col_get_info (sheet, cell->pos.col);
- double center_offset = cell_col->size_pts / 2;
- double tmp_width = ci->size_pts;
+ double center_offset = cell_col->size_pts * hscale / 2;
+ double tmp_width = ci->size_pts * hscale;
if (col != cell->pos.col)
style = sheet_style_get (sheet,
@@ -540,7 +537,7 @@
sr.vertical [col] = NULL;
if (dir > 0)
- x += ci->size_pts;
+ x += ci->size_pts * hscale;
}
gnm_style_borders_row_print_gtk (prev_vert, &sr,
context, base_x, y, y+ri->size_pts,
Modified: trunk/src/rendered-value.c
==============================================================================
--- trunk/src/rendered-value.c (original)
+++ trunk/src/rendered-value.c Sun Sep 7 18:32:15 2008
@@ -341,9 +341,20 @@
res->numeric_overflow = FALSE;
if (displayed_formula) {
- char *text = gnm_cell_get_displayed_text (cell);
- pango_layout_set_text (layout, text, -1);
- g_free (text);
+ GnmParsePos pp;
+ GnmConventionsOut out;
+ gboolean is_array = gnm_expr_top_is_array (cell->base.texpr);
+
+ out.accum = g_string_new (is_array ? "{=" : "=");
+ out.convs = sheet->convs;
+ out.pp = &pp;
+
+ parse_pos_init_cell (&pp, cell),
+ gnm_expr_top_as_gstring (cell->base.texpr, &out);
+ if (is_array)
+ g_string_append_c (out.accum, '}');
+ pango_layout_set_text (layout, out.accum->str, out.accum->len);
+ g_string_free (out.accum, TRUE);
fore = 0;
res->might_overflow = FALSE;
} else if (sheet->hide_zero && gnm_cell_is_zero (cell)) {
Modified: trunk/src/sheet.c
==============================================================================
--- trunk/src/sheet.c (original)
+++ trunk/src/sheet.c Sun Sep 7 18:32:15 2008
@@ -171,16 +171,6 @@
}
static void
-sheet_set_display_formulas (Sheet *sheet, gboolean display)
-{
- display = !!display;
- if (sheet->display_formulas == display)
- return;
- sheet->display_formulas = display;
- re_render_formulas (sheet);
-}
-
-static void
sheet_set_conventions (Sheet *sheet, GnmConventions const *convs)
{
if (sheet->convs == convs)
@@ -323,31 +313,49 @@
}
static void
-sheet_set_zoom_factor (Sheet *sheet, double factor)
+sheet_scale_changed (Sheet *sheet, gboolean cols_rescaled, gboolean rows_rescaled)
{
struct resize_colrow closure;
- if (fabs (factor - sheet->last_zoom_factor_used) < 1e-6)
- return;
- sheet->last_zoom_factor_used = factor;
-
- /* First, the default styles */
- colrow_compute_pixels_from_pts (&sheet->rows.default_style, sheet, FALSE);
- colrow_compute_pixels_from_pts (&sheet->cols.default_style, sheet, TRUE);
+ g_return_if_fail (cols_rescaled || rows_rescaled);
/* Then every column and row */
- closure.sheet = sheet;
- closure.is_cols = TRUE;
- colrow_foreach (&sheet->cols, 0, gnm_sheet_get_max_cols (sheet) - 1,
- (ColRowHandler)&cb_colrow_compute_pixels_from_pts, &closure);
- closure.is_cols = FALSE;
- colrow_foreach (&sheet->rows, 0, gnm_sheet_get_max_rows (sheet) - 1,
- (ColRowHandler)&cb_colrow_compute_pixels_from_pts, &closure);
+ if (cols_rescaled) {
+ colrow_compute_pixels_from_pts (&sheet->cols.default_style, sheet, TRUE);
+ closure.sheet = sheet;
+ closure.is_cols = TRUE;
+ colrow_foreach (&sheet->cols, 0, gnm_sheet_get_max_cols (sheet) - 1,
+ (ColRowHandler)&cb_colrow_compute_pixels_from_pts, &closure);
+ }
+ if (rows_rescaled) {
+ colrow_compute_pixels_from_pts (&sheet->rows.default_style, sheet, FALSE);
+ closure.is_cols = FALSE;
+ colrow_foreach (&sheet->rows, 0, gnm_sheet_get_max_rows (sheet) - 1,
+ (ColRowHandler)&cb_colrow_compute_pixels_from_pts, &closure);
+ }
sheet_cell_foreach (sheet, (GHFunc)&cb_clear_rendered_cells, NULL);
SHEET_FOREACH_CONTROL (sheet, view, control, sc_scale_changed (control););
}
+static void
+sheet_set_display_formulas (Sheet *sheet, gboolean display)
+{
+ display = !!display;
+ if (sheet->display_formulas == display)
+ return;
+ sheet->display_formulas = display;
+ sheet_scale_changed (sheet, TRUE, FALSE);
+}
+
+static void
+sheet_set_zoom_factor (Sheet *sheet, double factor)
+{
+ if (fabs (factor - sheet->last_zoom_factor_used) < 1e-6)
+ return;
+ sheet->last_zoom_factor_used = factor;
+ sheet_scale_changed (sheet, TRUE, TRUE);
+}
static void
gnm_sheet_set_property (GObject *object, guint property_id,
@@ -4496,6 +4504,9 @@
pts += ci->size_pts;
}
+ if (sheet->display_formulas)
+ pts *= 2.;
+
return pts * sign;
}
Modified: trunk/src/workbook-view.c
==============================================================================
--- trunk/src/workbook-view.c (original)
+++ trunk/src/workbook-view.c Sun Sep 7 18:32:15 2008
@@ -54,6 +54,7 @@
#include <goffice/app/io-context.h>
#include <goffice/utils/go-file.h>
#include <goffice/utils/go-glib-extras.h>
+#include <goffice/utils/go-locale.h>
#include <gsf/gsf.h>
#include <gsf/gsf-impl-utils.h>
#include <gsf/gsf-output-stdio.h>
@@ -386,12 +387,49 @@
sv = wbv->current_sheet_view;
if (sv != NULL) {
char *text;
- GnmCell const *cell = sheet_cell_get (sv->sheet,
+ Sheet *sheet = sv->sheet;
+ GnmCell const *cell = sheet_cell_get (sheet,
sv->edit_pos.col, sv->edit_pos.row);
- if (NULL != cell)
- text = gnm_cell_get_displayed_text (cell);
- else
+ if (NULL != cell) {
+ text = gnm_cell_get_entered_text (cell);
+
+ if (gnm_cell_has_expr (cell)) {
+ GnmExprTop const *texpr = cell->base.texpr;
+ GnmCell const *corner = NULL;
+ int x = 0, y = 0;
+
+ /*
+ * If this is part of an array we add '{' '}'
+ * and size information to the display. That
+ * is not actually part of the parsable
+ * expression, but it is a useful extension to
+ * the simple '{' '}' that MS excel(tm) uses.
+ */
+ if (gnm_expr_top_is_array_corner (texpr))
+ corner = cell;
+ else if (gnm_expr_top_is_array_elem (texpr, &x, &y)) {
+ corner = sheet_cell_get
+ (sheet,
+ cell->pos.col - x,
+ cell->pos.row - y);
+ }
+
+ if (corner) {
+ GnmExprArrayCorner const *ac = gnm_cell_is_array_corner (corner);
+
+ char *tmp = g_strdup_printf
+ ("{%s}(%d%c%d)[%d][%d]",
+ text,
+ ac->cols,
+ go_locale_get_arg_sep (),
+ ac->rows,
+ x, y);
+ g_free (text);
+ text = tmp;
+ }
+ }
+ } else
text = g_strdup ("");
if (optional_wbc == NULL) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]