Commit e32cdefe authored by Miguel de Icaza's avatar Miguel de Icaza Committed by Arturo Espinosa

New value format framework installed.



New value format framework installed.

The idea is that we will precompile formats to avoid parsing the
format everytime a cell is repainted.

Miguel.

1998-08-19  Miguel de Icaza  <miguel@nuclecu.unam.mx>

	* src/format.c (format_value): The new entry point for formating
	values.  This takes a Value instead of a float.
	NULL is never returned from format_value now: if there is a format
	error, then value_string is used to display it.

	(format_compile): This routine should always return, it cant fail,
	in the worst * case it should just downgrade to simplistic formatting.

	(format_destroy): This routine is invoked when the last user of
	the format is gone (ie, refcount has reached zero) just before the
	StyleFormat structure is actually released.  resources allocated
	in format_compile should be disposed here
parent af81b693
1998-08-19 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/format.c (format_value): The new entry point for formating
values. This takes a Value instead of a float.
NULL is never returned from format_value now: if there is a format
error, then value_string is used to display it.
(format_compile): This routine should always return, it cant fail,
in the worst * case it should just downgrade to simplistic formatting.
(format_destroy): This routine is invoked when the last user of
the format is gone (ie, refcount has reached zero) just before the
StyleFormat structure is actually released. resources allocated
in format_compile should be disposed here
* src/sheet.c (sheet_cursor_set): New function. Use this instead
of the view-specific routine (gnumeric_cursor_set).
......
1998-08-19 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/format.c (format_value): The new entry point for formating
values. This takes a Value instead of a float.
NULL is never returned from format_value now: if there is a format
error, then value_string is used to display it.
(format_compile): This routine should always return, it cant fail,
in the worst * case it should just downgrade to simplistic formatting.
(format_destroy): This routine is invoked when the last user of
the format is gone (ie, refcount has reached zero) just before the
StyleFormat structure is actually released. resources allocated
in format_compile should be disposed here
* src/sheet.c (sheet_cursor_set): New function. Use this instead
of the view-specific routine (gnumeric_cursor_set).
......
1998-08-19 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/format.c (format_value): The new entry point for formating
values. This takes a Value instead of a float.
NULL is never returned from format_value now: if there is a format
error, then value_string is used to display it.
(format_compile): This routine should always return, it cant fail,
in the worst * case it should just downgrade to simplistic formatting.
(format_destroy): This routine is invoked when the last user of
the format is gone (ie, refcount has reached zero) just before the
StyleFormat structure is actually released. resources allocated
in format_compile should be disposed here
* src/sheet.c (sheet_cursor_set): New function. Use this instead
of the view-specific routine (gnumeric_cursor_set).
......
1998-08-19 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/format.c (format_value): The new entry point for formating
values. This takes a Value instead of a float.
NULL is never returned from format_value now: if there is a format
error, then value_string is used to display it.
(format_compile): This routine should always return, it cant fail,
in the worst * case it should just downgrade to simplistic formatting.
(format_destroy): This routine is invoked when the last user of
the format is gone (ie, refcount has reached zero) just before the
StyleFormat structure is actually released. resources allocated
in format_compile should be disposed here
* src/sheet.c (sheet_cursor_set): New function. Use this instead
of the view-specific routine (gnumeric_cursor_set).
......
......@@ -2,6 +2,7 @@
#include <gnome.h>
#include "gnumeric.h"
#include "eval.h"
#include "format.h"
void
cell_formula_changed (Cell *cell)
......@@ -158,7 +159,7 @@ cell_render_value (Cell *cell)
g_return_if_fail (cell->value != NULL);
cell_auto_align (cell);
str = value_format (cell->value, cell->style->format, NULL);
str = format_value (cell->style->format, cell->value, NULL);
cell_set_rendered_text (cell, str);
g_free (str);
}
......
......@@ -191,11 +191,8 @@ render_formated_version (char *format)
char *str;
style_format = style_format_new (format);
str = value_format (v, style_format, NULL);
str = format_value (style_format, v, NULL);
if (!str)
str = g_strdup (_("Format error"));
gtk_label_set (GTK_LABEL (number_sample), str);
g_free (str);
style_format_unref (style_format);
......
......@@ -191,11 +191,8 @@ render_formated_version (char *format)
char *str;
style_format = style_format_new (format);
str = value_format (v, style_format, NULL);
str = format_value (style_format, v, NULL);
if (!str)
str = g_strdup (_("Format error"));
gtk_label_set (GTK_LABEL (number_sample), str);
g_free (str);
style_format_unref (style_format);
......
......@@ -168,27 +168,6 @@ value_string (Value *value)
return g_strdup (buffer);
}
/*
* formats a number with the format string
*/
char *
value_format (Value *v, StyleFormat *format, char **color)
{
switch (v->type){
case VALUE_INTEGER:
return format_number (v->v.v_int, format->format, color);
case VALUE_FLOAT:
return format_number (v->v.v_float, format->format, color);
default:
if (color)
*color = NULL;
return value_string (v);
}
}
void
value_release (Value *value)
{
......
......@@ -22,6 +22,7 @@
#include <string.h>
#include <time.h>
#include <math.h>
#include "gnumeric.h"
#include "format.h"
static int append_year( GString *string, gchar *format, struct tm *time_split );
......@@ -280,8 +281,27 @@ typedef struct
int hasnumbers;
} format_info;
gchar *
format_number( gdouble number, gchar *format, char **color_name )
void
format_compile (StyleFormat *format)
{
/* This routine should always return, it cant fail, in the worst
* case it should just downgrade to stupid formatting
*/
}
void
format_destroy (StyleFormat *format)
{
/* This routine is invoked when the last user of the
* format is gone (ie, refcount has reached zero) just
* before the StyleFormat structure is actually released.
*
* resources allocated in format_compile should be disposed here
*/
}
static gchar *
format_number(gdouble number, StyleFormat *style_format, char **color_name )
{
gint left_req = 0, right_req = 0;
gint left_spaces = 0, right_spaces = 0;
......@@ -291,6 +311,7 @@ format_number( gdouble number, gchar *format, char **color_name )
gboolean negative = FALSE;
GString *string = g_string_new( "" );
GString *number_string = g_string_new( "" );
gchar *format = style_format->format;
gint length = strlen(format);
gchar *returnvalue;
gint zero_count;
......@@ -543,3 +564,31 @@ format_number( gdouble number, gchar *format, char **color_name )
return returnvalue;
}
gchar *
format_value (StyleFormat *format, Value *value, char **color_name)
{
char *v = NULL;
switch (value->type){
case VALUE_FLOAT:
v = format_number (value->v.v_float, format, color_name);
break;
case VALUE_INTEGER:
v = format_number (value->v.v_int, format, color_name);
break;
case VALUE_STRING:
return g_strdup (value->v.str->str);
default:
return g_strdup ("Internal error");
}
/* Format error, return a default value */
if (v == NULL)
return value_string (value);
return v;
}
#ifndef FORMAT_H_
#define FORMAT_H_
gchar *format_number (gdouble number, gchar *format, char **use_color);
void format_destroy (StyleFormat *format);
void format_compile (StyleFormat *format);
gchar *format_value (StyleFormat *format, Value *value, char **color_name);
#endif
......@@ -894,6 +894,7 @@ sheet_redraw_cell_region (Sheet *sheet, int start_col, int start_row,
int end_col, int end_row)
{
GnumericSheet *gsheet;
int first_visible_col, first_visible_row;
int x, y, w, h;
g_return_if_fail (sheet != NULL);
......@@ -901,9 +902,19 @@ sheet_redraw_cell_region (Sheet *sheet, int start_col, int start_row,
gsheet = GNUMERIC_SHEET (sheet->sheet_view);
g_return_if_fail (GNUMERIC_IS_SHEET (gsheet));
if (gsheet->top_col > start_col)
first_visible_col = start_col;
else
first_visible_col = gsheet->top_col;
if (gsheet->top_row > start_row)
first_visible_row = start_row;
else
first_visible_row = gsheet->top_row;
x = sheet_col_get_distance (sheet, gsheet->top_col, start_col);
y = sheet_row_get_distance (sheet, gsheet->top_row, start_row);
x = sheet_col_get_distance (sheet, first_visible_col, start_col);
y = sheet_row_get_distance (sheet, first_visible_row, start_row);
w = sheet_col_get_distance (sheet, start_col, end_col+1);
h = sheet_col_get_distance (sheet, start_col, end_col+1);
......
......@@ -7,7 +7,8 @@
*/
#include <config.h>
#include <gnome.h>
#include "style.h"
#include "gnumeric.h"
#include "format.h"
static GHashTable *style_format_hash;
static GHashTable *style_font_hash;
......@@ -25,6 +26,7 @@ style_format_new (char *name)
if (!format){
format = g_new0 (StyleFormat, 1);
format->format = g_strdup (name);
format_compile (format);
g_hash_table_insert (style_format_hash, name, format);
}
format->ref_count++;
......@@ -48,8 +50,10 @@ style_format_unref (StyleFormat *sf)
sf->ref_count--;
if (sf->ref_count != 0)
return;
g_hash_table_remove (style_format_hash, sf->format);
format_destroy (sf);
g_free (sf->format);
g_free (sf);
}
......
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