Commit cdd5ec53 authored by Michael Meeks's avatar Michael Meeks

New cell_set_value API.

Speedups using this for ms-excel numbers also gives better precision.
parent b906f492
1999-05-02 Michael Meeks <michael@imaginator.com>
* src/cell.c (cell_set_value): Created.
(cell_set_value_simple): Created.
* src/cell.h: Added headers
1999-05-01 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/corba-workbook.c, src/corba-sheet.c: New files implementing
......
1999-05-02 Michael Meeks <michael@imaginator.com>
* src/cell.c (cell_set_value): Created.
(cell_set_value_simple): Created.
* src/cell.h: Added headers
1999-05-01 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/corba-workbook.c, src/corba-sheet.c: New files implementing
......
1999-05-02 Michael Meeks <michael@imaginator.com>
* src/cell.c (cell_set_value): Created.
(cell_set_value_simple): Created.
* src/cell.h: Added headers
1999-05-01 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/corba-workbook.c, src/corba-sheet.c: New files implementing
......
1999-05-02 Michael Meeks <michael@imaginator.com>
* src/cell.c (cell_set_value): Created.
(cell_set_value_simple): Created.
* src/cell.h: Added headers
1999-05-01 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/corba-workbook.c, src/corba-sheet.c: New files implementing
......
1999-05-02 Michael Meeks <michael@imaginator.com>
* ms-formula.c (ms_excel_parse_formula): Removed annoying
debug killing performance.
* ms-excel.c (ms_excel_sheet_insert_val): Created.
(biff_get_rk): Removed impossible clause.
Returns a Value now for speed; also increases accuracy.
(ms_excel_read_cell): BIFF_RK, BIFF_MULRK: Removed nasty
buffer and ugly printf.
(ms_excel_sheet_insert): Made static, & removed from .h
1999-04-29 Miguel de Icaza <miguel@nuclecu.unam.mx>
* ms-ole.c (ms_ole_new): Applied patch from Michael Meeks to allow
......
......@@ -1214,7 +1214,7 @@ ms_excel_sheet_set_version (MS_EXCEL_SHEET *sheet, eBiff_version ver)
sheet->ver = ver ;
}
void
static void
ms_excel_sheet_insert (MS_EXCEL_SHEET * sheet, int xfidx,
int col, int row, const char *text)
{
......@@ -1230,6 +1230,19 @@ ms_excel_sheet_insert (MS_EXCEL_SHEET * sheet, int xfidx,
ms_excel_set_cell_xf (sheet, cell, xfidx);
}
static void
ms_excel_sheet_insert_val (MS_EXCEL_SHEET * sheet, int xfidx,
int col, int row, const Value *v)
{
Cell *cell;
g_return_if_fail (v);
g_return_if_fail (sheet);
cell = sheet_cell_fetch (sheet->gnum_sheet, col, row);
sheet->blank = 0 ;
cell_set_value_simple (cell, v);
ms_excel_set_cell_xf (sheet, cell, xfidx);
}
static void
ms_excel_sheet_set_comment (MS_EXCEL_SHEET * sheet, int col, int row, char *text)
{
......@@ -1409,12 +1422,12 @@ ms_excel_workbook_destroy (MS_EXCEL_WORKBOOK * wb)
/**
* Unpacks a MS Excel RK structure,
* This needs to return / insert sensibly to keep precision / accelerate
**/
static double
static Value *
biff_get_rk (guint8 *ptr)
{
LONG number;
Value *ans=NULL;
guint8 tmp[8];
int lp;
double answer;
......@@ -1425,17 +1438,6 @@ biff_get_rk (guint8 *ptr)
number = BIFF_GETLONG (ptr);
type = (number & 0x3);
switch (type){
/* case eIEEE:
tmp[li] = 0;
tmp[hi] = *((LONG *)(ptr)) & 0xfffffffc;
answer = BIFF_GETDOUBLE (((BYTE *) tmp));
break;
case eIEEEx100:
tmp[li] = 0;
tmp[hi] = *((LONG *)(ptr)) & 0xfffffffc;
answer = BIFF_GETDOUBLE (((BYTE *) tmp));
answer /= 100.0;
break;*/
case eIEEE:
case eIEEEx100:
for (lp=0;lp<4;lp++) {
......@@ -1445,19 +1447,19 @@ biff_get_rk (guint8 *ptr)
answer = BIFF_GETDOUBLE(tmp);
answer /= (type == eIEEEx100)?100.0:1.0;
ans = value_float (answer);
break;
case eInt:
answer = (double) (number >> 2);
ans = value_int ((number>>2));
break;
case eIntx100:
answer = ((double) (number >> 2)) / 100.0;
if (number%100==0)
ans = value_int ((number>>2)/100);
else
ans = value_float ((number>>2)/100.0);
break;
default:
printf ("You don't exist go away\n");
answer = 0;
}
return answer ;
return ans;
}
/**
......@@ -1595,20 +1597,19 @@ ms_excel_read_cell (BIFF_QUERY * q, MS_EXCEL_SHEET * sheet)
}
case BIFF_RK: /* See: S59DDA.HTM */
{
char buf[MS_EXCEL_DOUBLE_FORMAT_LEN];
Value *v = biff_get_rk(q->data+6);
/* printf ("RK number : 0x%x, length 0x%x\n", q->opcode, q->length);
dump (q->data, q->length);*/
snprintf (buf, MS_EXCEL_DOUBLE_FORMAT_LEN-1,
MS_EXCEL_DOUBLE_FORMAT, biff_get_rk(q->data+6));
ms_excel_sheet_insert (sheet, EX_GETXF (q), EX_GETCOL (q), EX_GETROW (q), buf);
ms_excel_sheet_insert_val (sheet, EX_GETXF (q), EX_GETCOL (q),
EX_GETROW (q), v);
break;
}
case BIFF_MULRK: /* S59DA8.HTM */
{
guint32 col, row, lastcol;
char buf[MS_EXCEL_DOUBLE_FORMAT_LEN];
guint8 *ptr = q->data;
Value *v;
/* printf ("MULRK\n") ;
dump (q->data, q->length) ; */
......@@ -1621,9 +1622,9 @@ ms_excel_read_cell (BIFF_QUERY * q, MS_EXCEL_SHEET * sheet)
g_assert (lastcol>=col) ;
while (col<=lastcol)
{ /* 2byte XF, 4 byte RK */
snprintf (buf, MS_EXCEL_DOUBLE_FORMAT_LEN,
MS_EXCEL_DOUBLE_FORMAT, biff_get_rk(ptr+2)) ;
ms_excel_sheet_insert(sheet, BIFF_GETWORD(ptr), col, row, buf) ;
v = biff_get_rk(ptr+2);
ms_excel_sheet_insert_val (sheet, BIFF_GETWORD(ptr),
col, row, v) ;
col++ ;
ptr+= 6 ;
}
......
......@@ -43,9 +43,6 @@ typedef struct {
guint32 data_len ;
} BIFF_SHARED_FORMULA ;
extern void ms_excel_sheet_insert (MS_EXCEL_SHEET *sheet,
int xfidx, int col,
int row, const char *text) ;
extern char *ms_excel_sheet_shared_formula (MS_EXCEL_SHEET *sheet,
int shr_col, int shr_row,
int col, int row) ;
......
......@@ -1214,7 +1214,7 @@ ms_excel_sheet_set_version (MS_EXCEL_SHEET *sheet, eBiff_version ver)
sheet->ver = ver ;
}
void
static void
ms_excel_sheet_insert (MS_EXCEL_SHEET * sheet, int xfidx,
int col, int row, const char *text)
{
......@@ -1230,6 +1230,19 @@ ms_excel_sheet_insert (MS_EXCEL_SHEET * sheet, int xfidx,
ms_excel_set_cell_xf (sheet, cell, xfidx);
}
static void
ms_excel_sheet_insert_val (MS_EXCEL_SHEET * sheet, int xfidx,
int col, int row, const Value *v)
{
Cell *cell;
g_return_if_fail (v);
g_return_if_fail (sheet);
cell = sheet_cell_fetch (sheet->gnum_sheet, col, row);
sheet->blank = 0 ;
cell_set_value_simple (cell, v);
ms_excel_set_cell_xf (sheet, cell, xfidx);
}
static void
ms_excel_sheet_set_comment (MS_EXCEL_SHEET * sheet, int col, int row, char *text)
{
......@@ -1409,12 +1422,12 @@ ms_excel_workbook_destroy (MS_EXCEL_WORKBOOK * wb)
/**
* Unpacks a MS Excel RK structure,
* This needs to return / insert sensibly to keep precision / accelerate
**/
static double
static Value *
biff_get_rk (guint8 *ptr)
{
LONG number;
Value *ans=NULL;
guint8 tmp[8];
int lp;
double answer;
......@@ -1425,17 +1438,6 @@ biff_get_rk (guint8 *ptr)
number = BIFF_GETLONG (ptr);
type = (number & 0x3);
switch (type){
/* case eIEEE:
tmp[li] = 0;
tmp[hi] = *((LONG *)(ptr)) & 0xfffffffc;
answer = BIFF_GETDOUBLE (((BYTE *) tmp));
break;
case eIEEEx100:
tmp[li] = 0;
tmp[hi] = *((LONG *)(ptr)) & 0xfffffffc;
answer = BIFF_GETDOUBLE (((BYTE *) tmp));
answer /= 100.0;
break;*/
case eIEEE:
case eIEEEx100:
for (lp=0;lp<4;lp++) {
......@@ -1445,19 +1447,19 @@ biff_get_rk (guint8 *ptr)
answer = BIFF_GETDOUBLE(tmp);
answer /= (type == eIEEEx100)?100.0:1.0;
ans = value_float (answer);
break;
case eInt:
answer = (double) (number >> 2);
ans = value_int ((number>>2));
break;
case eIntx100:
answer = ((double) (number >> 2)) / 100.0;
if (number%100==0)
ans = value_int ((number>>2)/100);
else
ans = value_float ((number>>2)/100.0);
break;
default:
printf ("You don't exist go away\n");
answer = 0;
}
return answer ;
return ans;
}
/**
......@@ -1595,20 +1597,19 @@ ms_excel_read_cell (BIFF_QUERY * q, MS_EXCEL_SHEET * sheet)
}
case BIFF_RK: /* See: S59DDA.HTM */
{
char buf[MS_EXCEL_DOUBLE_FORMAT_LEN];
Value *v = biff_get_rk(q->data+6);
/* printf ("RK number : 0x%x, length 0x%x\n", q->opcode, q->length);
dump (q->data, q->length);*/
snprintf (buf, MS_EXCEL_DOUBLE_FORMAT_LEN-1,
MS_EXCEL_DOUBLE_FORMAT, biff_get_rk(q->data+6));
ms_excel_sheet_insert (sheet, EX_GETXF (q), EX_GETCOL (q), EX_GETROW (q), buf);
ms_excel_sheet_insert_val (sheet, EX_GETXF (q), EX_GETCOL (q),
EX_GETROW (q), v);
break;
}
case BIFF_MULRK: /* S59DA8.HTM */
{
guint32 col, row, lastcol;
char buf[MS_EXCEL_DOUBLE_FORMAT_LEN];
guint8 *ptr = q->data;
Value *v;
/* printf ("MULRK\n") ;
dump (q->data, q->length) ; */
......@@ -1621,9 +1622,9 @@ ms_excel_read_cell (BIFF_QUERY * q, MS_EXCEL_SHEET * sheet)
g_assert (lastcol>=col) ;
while (col<=lastcol)
{ /* 2byte XF, 4 byte RK */
snprintf (buf, MS_EXCEL_DOUBLE_FORMAT_LEN,
MS_EXCEL_DOUBLE_FORMAT, biff_get_rk(ptr+2)) ;
ms_excel_sheet_insert(sheet, BIFF_GETWORD(ptr), col, row, buf) ;
v = biff_get_rk(ptr+2);
ms_excel_sheet_insert_val (sheet, BIFF_GETWORD(ptr),
col, row, v) ;
col++ ;
ptr+= 6 ;
}
......
......@@ -43,9 +43,6 @@ typedef struct {
guint32 data_len ;
} BIFF_SHARED_FORMULA ;
extern void ms_excel_sheet_insert (MS_EXCEL_SHEET *sheet,
int xfidx, int col,
int row, const char *text) ;
extern char *ms_excel_sheet_shared_formula (MS_EXCEL_SHEET *sheet,
int shr_col, int shr_row,
int col, int row) ;
......
......@@ -986,8 +986,10 @@ char *ms_excel_parse_formula (MS_EXCEL_SHEET *sheet, guint8 *mem,
name_idx = BIFF_GETWORD(cur) ;
txt = biff_name_data_get_name (sheet, name_idx);
if (!txt) {
printf ("FIXME: Ptg Name not found: %d\n", name_idx) ;
dump(mem, length) ;
if (FORMULA_DEBUG>0) {
printf ("FIXME: Ptg Name not found: %d\n", name_idx) ;
dump(mem, length) ;
}
parse_list_push_raw (stack, g_strdup("Unknown name"), NO_PRECEDENCE) ;
} else
parse_list_push_raw (stack, g_strdup(txt), NO_PRECEDENCE) ;
......
......@@ -986,8 +986,10 @@ char *ms_excel_parse_formula (MS_EXCEL_SHEET *sheet, guint8 *mem,
name_idx = BIFF_GETWORD(cur) ;
txt = biff_name_data_get_name (sheet, name_idx);
if (!txt) {
printf ("FIXME: Ptg Name not found: %d\n", name_idx) ;
dump(mem, length) ;
if (FORMULA_DEBUG>0) {
printf ("FIXME: Ptg Name not found: %d\n", name_idx) ;
dump(mem, length) ;
}
parse_list_push_raw (stack, g_strdup("Unknown name"), NO_PRECEDENCE) ;
} else
parse_list_push_raw (stack, g_strdup(txt), NO_PRECEDENCE) ;
......
......@@ -536,6 +536,67 @@ cell_render_value (Cell *cell)
g_free (str);
}
/*
* Sets the value for a cell:
*
* This is kind of an internal function and should be only called by
* routines that know what they are doing. These are the important
* differences from cell_set_value:
*
* - It does not queue redraws (so you have to queue the redraw yourself
* or queue a full redraw).
*
* - It does not queue any recomputations. You have to queue the recompute
* yourself.
*/
void
cell_set_value_simple (Cell *cell, const Value *v)
{
struct lconv *lconv;
g_return_if_fail (cell);
g_return_if_fail (v);
cell_modified (cell);
if (cell->entered_text)
string_unref (cell->entered_text);
cell->entered_text = NULL;
if (cell->value)
value_release (cell->value);
if (cell->parsed_node){
sheet_cell_formula_unlink (cell);
expr_tree_unref (cell->parsed_node);
cell->parsed_node = NULL;
}
cell->value = v;
cell_render_value (cell);
}
/*
* cell_set_value
*
* Changes the value of a cell
*/
void
cell_set_value (Cell *cell, const Value *v)
{
g_return_if_fail (cell);
g_return_if_fail (v);
cell_queue_redraw (cell);
cell_set_value_simple (cell, v);
cell_content_changed (cell);
cell_queue_redraw (cell);
}
/*
* Sets the text for a cell:
*
......@@ -642,9 +703,7 @@ cell_set_text_simple (Cell *cell, const char *text)
cell->value = v;
cell_render_value (cell);
}
}
}
/*
......
......@@ -116,6 +116,8 @@ char *value_format (Value *value, StyleFormat *format, cha
void cell_set_text (Cell *cell, const char *text);
void cell_set_text_simple (Cell *cell, const char *text);
void cell_set_value (Cell *cell, const Value *v);
void cell_set_value_simple (Cell *cell, const Value *v);
void cell_content_changed (Cell *cell);
void cell_set_formula (Cell *cell, const char *text);
void cell_set_formula_tree (Cell *cell, ExprTree *formula);
......
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