Commit cf4defb5 authored by Michael Meeks's avatar Michael Meeks

Misc. minor function improvements,

Fixed function wizard,
Plugin warning fix,
auto-expression parsing clean,
externalised shared excel function data,
various function fixes,
Better excel export support ( thats easy :-)
parent 21c9054a
1999-06-25 Michael Meeks <michael@edenproject.org>
* src/dialog-function-wizard.c: Re-vamped table layout.
* src/fn-string.c (string_functions_init): Change category
name to 'String'; silly me.
* src/dialog-function-select.c (function_definition_update): Fixed
old & broken function pointer code.
* src/expr.c (eval_funcall): Updated to use union.
(function_def_call_with_values): ditto.
* src/func.c (function_add_nodes): ditto.
(function_add_args): ditto.
* src/expr.h: Changed void *fn pointer to a slicker union.
* src/plugin.h: Added a prototype for the one external function
every plugin must have ( kills some plugins warnings ).
* src/workbook.c (workbook_new): Updated call to set_auto_expr
(change_auto_expr): ditto.
(workbook_do_destroy): Update.
(workbook_set_auto_expr): Updated, just to set text leaving heavy
lifting for sheet.c. This removes possible error checking of our
quick-functions, but an error will be displayed in the status bar
having set the function, and the functionality wasn't used.
* src/sheet.h: Removed previously extern'd workbook_set_auto_expr,
this should be internal.
Remove auto_expr_tree from Workbook *.
* src/sheet.c (sheet_update_auto_expr): Moved auto_expr parsing
into sheet_update_auto_expr. Rational; neater, and not performace
critical.
1999-06-26 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/pixmaps.h: Removed unused pixmaps.
......
1999-06-25 Michael Meeks <michael@edenproject.org>
* src/dialog-function-wizard.c: Re-vamped table layout.
* src/fn-string.c (string_functions_init): Change category
name to 'String'; silly me.
* src/dialog-function-select.c (function_definition_update): Fixed
old & broken function pointer code.
* src/expr.c (eval_funcall): Updated to use union.
(function_def_call_with_values): ditto.
* src/func.c (function_add_nodes): ditto.
(function_add_args): ditto.
* src/expr.h: Changed void *fn pointer to a slicker union.
* src/plugin.h: Added a prototype for the one external function
every plugin must have ( kills some plugins warnings ).
* src/workbook.c (workbook_new): Updated call to set_auto_expr
(change_auto_expr): ditto.
(workbook_do_destroy): Update.
(workbook_set_auto_expr): Updated, just to set text leaving heavy
lifting for sheet.c. This removes possible error checking of our
quick-functions, but an error will be displayed in the status bar
having set the function, and the functionality wasn't used.
* src/sheet.h: Removed previously extern'd workbook_set_auto_expr,
this should be internal.
Remove auto_expr_tree from Workbook *.
* src/sheet.c (sheet_update_auto_expr): Moved auto_expr parsing
into sheet_update_auto_expr. Rational; neater, and not performace
critical.
1999-06-26 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/pixmaps.h: Removed unused pixmaps.
......
1999-06-25 Michael Meeks <michael@edenproject.org>
* src/dialog-function-wizard.c: Re-vamped table layout.
* src/fn-string.c (string_functions_init): Change category
name to 'String'; silly me.
* src/dialog-function-select.c (function_definition_update): Fixed
old & broken function pointer code.
* src/expr.c (eval_funcall): Updated to use union.
(function_def_call_with_values): ditto.
* src/func.c (function_add_nodes): ditto.
(function_add_args): ditto.
* src/expr.h: Changed void *fn pointer to a slicker union.
* src/plugin.h: Added a prototype for the one external function
every plugin must have ( kills some plugins warnings ).
* src/workbook.c (workbook_new): Updated call to set_auto_expr
(change_auto_expr): ditto.
(workbook_do_destroy): Update.
(workbook_set_auto_expr): Updated, just to set text leaving heavy
lifting for sheet.c. This removes possible error checking of our
quick-functions, but an error will be displayed in the status bar
having set the function, and the functionality wasn't used.
* src/sheet.h: Removed previously extern'd workbook_set_auto_expr,
this should be internal.
Remove auto_expr_tree from Workbook *.
* src/sheet.c (sheet_update_auto_expr): Moved auto_expr parsing
into sheet_update_auto_expr. Rational; neater, and not performace
critical.
1999-06-26 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/pixmaps.h: Removed unused pixmaps.
......
1999-06-25 Michael Meeks <michael@edenproject.org>
* src/dialog-function-wizard.c: Re-vamped table layout.
* src/fn-string.c (string_functions_init): Change category
name to 'String'; silly me.
* src/dialog-function-select.c (function_definition_update): Fixed
old & broken function pointer code.
* src/expr.c (eval_funcall): Updated to use union.
(function_def_call_with_values): ditto.
* src/func.c (function_add_nodes): ditto.
(function_add_args): ditto.
* src/expr.h: Changed void *fn pointer to a slicker union.
* src/plugin.h: Added a prototype for the one external function
every plugin must have ( kills some plugins warnings ).
* src/workbook.c (workbook_new): Updated call to set_auto_expr
(change_auto_expr): ditto.
(workbook_do_destroy): Update.
(workbook_set_auto_expr): Updated, just to set text leaving heavy
lifting for sheet.c. This removes possible error checking of our
quick-functions, but an error will be displayed in the status bar
having set the function, and the functionality wasn't used.
* src/sheet.h: Removed previously extern'd workbook_set_auto_expr,
this should be internal.
Remove auto_expr_tree from Workbook *.
* src/sheet.c (sheet_update_auto_expr): Moved auto_expr parsing
into sheet_update_auto_expr. Rational; neater, and not performace
critical.
1999-06-26 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/pixmaps.h: Removed unused pixmaps.
......
1999-06-27 Michael Meeks <michael@edenproject.org>
* ms-excel-read.c: excel_builtin_formats: Populated with
NULL's in sensible places to clean maintainability.
* ms-formula-read.c (ms_excel_parse_formula): Add fix for
broken array formulae causing infinite loop.
* ms-excel-read.c (ms_excel_read_cell): Fix Morten's fatal
cock-up in value_new_string (NULL).
* ms-excel-write.c (write_mulblank): Implemented.
(write_sheet): Started to get DBCELL / Index type code in
place.
Cleaned nasty cell hash iterator, and closure. We now rely
on the optimal handling of max_col/row_used in the sheet.
* ms-excel-read.c (ms_excel_read_cell): Insert blank into
the correct column, not just the same one all the time.
* ms-excel-write.c (write_palette): Write default palette.
* ms-excel-read.c: Externalised default palette, and format
data.
* excel.h: ditto.
1999-06-25 Michael Meeks <michael@edenproject.org>
* ms-excel-read.c: Minor fiddles setting blank flag in some new
places, and types changed to gboolean.
* ms-excel-read.h (_MS_EXCEL_SHEET): changed 'blank' to gboolean.
1999-06-26 Miguel de Icaza <miguel@nuclecu.unam.mx>
* ms-excel-read.c (biff_font_data_get_style_font): Use
......
......@@ -21,5 +21,18 @@ extern Workbook *ms_excel_read_workbook (MS_OLE *file);
extern int ms_excel_write_workbook (MS_OLE *file, Workbook *wb,
eBiff_version ver);
/* We need to use these for both read and write */
typedef struct {
int b, g, r;
} EXCEL_PALETTE_ENTRY;
extern EXCEL_PALETTE_ENTRY excel_default_palette[];
#define EXCEL_DEF_PAL_LEN 56
extern char *excel_builtin_formats[];
#define EXCEL_BUILTIN_FORMAT_LEN 0x32
#endif
......@@ -586,12 +586,8 @@ biff_font_data_destroy (gpointer key, BIFF_FONT_DATA *fd, gpointer userdata)
return 1 ;
}
static StyleFormat *
biff_format_data_lookup (MS_EXCEL_WORKBOOK *wb, guint16 idx)
{
char *low_formats[] =
{
"",
char *excel_builtin_formats[EXCEL_BUILTIN_FORMAT_LEN] = {
"", /* 0x00 */
"0",
"0.00",
"#,##0",
......@@ -607,16 +603,16 @@ biff_format_data_lookup (MS_EXCEL_WORKBOOK *wb, guint16 idx)
"#",
"m/d/yy",
"d-mmm-yy",
"d-mmm",
"d-mmm", /* 0x10 */
"mmm-yy",
"h:mm",
"h:mm:ss",
"h:mm",
"h:mm:ss",
"m/d/yy"
} ;
char *high_formats[] =
{
"m/d/yy", /* 0x16 */
0,0, /* 0x18 */
0,0,0,0,0,0,0,0, /* 0x20 */
0,0,0,0, /* 0x24 */
"(#,##0_);(#,##0)",
"(#,##0_);[Red](#,##0)",
"(#,##0.00_);(#,##0.00)",
......@@ -630,31 +626,29 @@ biff_format_data_lookup (MS_EXCEL_WORKBOOK *wb, guint16 idx)
"mm:ss.0",
"##0.0E+0",
"@"
} ;
char *ans ;
if (idx <= 0x16)
ans = low_formats[idx] ;
else if (idx < 0x25)
{
printf ("Foreign undocumented format\n") ;
ans = 0 ;
};
static StyleFormat *
biff_format_data_lookup (MS_EXCEL_WORKBOOK *wb, guint16 idx)
{
char *ans;
if (idx <= 0x31) {
ans = excel_builtin_formats[idx];
if (!ans)
printf ("Foreign undocumented format\n");
}
else if (idx <= 0x31)
ans = high_formats[idx-0x25] ;
else
{
if (!ans) {
BIFF_FORMAT_DATA *d = g_hash_table_lookup (wb->format_data,
&idx) ;
if (!d)
{
printf ("Unknown format: 0x%x\n", idx) ;
ans = 0 ;
}
else
ans = d->name ;
&idx);
if (!d) {
printf ("Unknown format: 0x%x\n", idx);
ans = 0;
} else
ans = d->name;
}
if (ans)
return style_format_new (ans) ;
return style_format_new (ans);
else
return NULL ;
}
......@@ -715,16 +709,9 @@ biff_name_data_destroy (gpointer key, BIFF_NAME_DATA *bnd, gpointer userdata)
return 1 ;
}
static MS_EXCEL_PALETTE *
ms_excel_default_palette ()
{
static MS_EXCEL_PALETTE * pal = NULL;
if (!pal)
{
static struct default_color
{
/* These were generated by creating a sheet and
EXCEL_PALETTE_ENTRY excel_default_palette[EXCEL_DEF_PAL_LEN] = {
/* These were generated by creating a sheet and
* modifying the 1st color cell and saving. This
* created a custom palette. I then loaded the sheet
* into gnumeric and dumped the results. Unfortunately
......@@ -732,8 +719,6 @@ ms_excel_default_palette ()
* red and blue. It is too much effort to retype this.
* So I'll leave it in this odd format for now.
*/
int b, g, r;
} default_colors[56] = {
{ 0,0,0 }, { 255,255,255 }, { 0,0,255 }, { 0,255,0 },
{ 255,0,0 }, { 0,255,255 }, { 255,0,255 }, { 255,255,0},
......@@ -754,10 +739,16 @@ ms_excel_default_palette ()
{102,51,0}, {102,153,51}, {0,51,0}, {0,51,51},
{0,51,153}, {102,51,153}, {153,51,51}, {51,51,51}
};
};
static MS_EXCEL_PALETTE *
ms_excel_default_palette ()
{
static MS_EXCEL_PALETTE * pal = NULL;
int entries = sizeof(default_colors)/
sizeof(struct default_color);
if (!pal)
{
int entries = EXCEL_DEF_PAL_LEN;
#if EXCEL_DEBUG_COLOR > 1
printf ("Creating default pallete\n");
#endif
......@@ -769,9 +760,9 @@ ms_excel_default_palette ()
pal->gnum_cols = g_new (StyleColor *, entries) ;
while (--entries >= 0) {
pal->red[entries] = default_colors[entries].r;
pal->green[entries] = default_colors[entries].g;
pal->blue[entries] = default_colors[entries].b;
pal->red[entries] = excel_default_palette[entries].r;
pal->green[entries] = excel_default_palette[entries].g;
pal->blue[entries] = excel_default_palette[entries].b;
pal->gnum_cols[entries] = NULL ;
}
}
......@@ -1363,7 +1354,7 @@ ms_excel_sheet_new (MS_EXCEL_WORKBOOK * wb, char *name)
MS_EXCEL_SHEET *ans = (MS_EXCEL_SHEET *) g_malloc (sizeof (MS_EXCEL_SHEET));
ans->gnum_sheet = sheet_new (wb->gnum_wb, name);
ans->blank = 1 ;
ans->blank = TRUE ;
ans->wb = wb;
ans->shared_formulae = g_hash_table_new ((GHashFunc)biff_shared_formula_hash,
......@@ -1404,9 +1395,8 @@ ms_excel_sheet_insert (MS_EXCEL_SHEET * sheet, int xfidx,
{
Cell *cell = sheet_cell_fetch (sheet->gnum_sheet, col, row);
/* NB. cell_set_text _certainly_ strdups *text */
if (text)
{
sheet->blank = 0 ;
if (text) {
sheet->blank = FALSE ;
cell_set_text_simple (cell, text);
}
else
......@@ -1420,7 +1410,7 @@ ms_excel_sheet_insert_form (MS_EXCEL_SHEET * sheet, int xfidx,
{
Cell *cell = sheet_cell_fetch (sheet->gnum_sheet, col, row);
if (tr) {
sheet->blank = 0 ;
sheet->blank = FALSE ;
cell_set_formula_tree_simple (cell, tr);
} else
cell_set_text_simple (cell, "") ;
......@@ -1435,7 +1425,7 @@ ms_excel_sheet_insert_val (MS_EXCEL_SHEET * sheet, int xfidx,
g_return_if_fail (v);
g_return_if_fail (sheet);
cell = sheet_cell_fetch (sheet->gnum_sheet, col, row);
sheet->blank = 0 ;
sheet->blank = FALSE ;
cell_set_value_simple (cell, v);
ms_excel_set_cell_xf (sheet, cell, xfidx);
}
......@@ -1450,7 +1440,7 @@ ms_excel_sheet_set_comment (MS_EXCEL_SHEET * sheet, int col, int row, char *text
cell = sheet_cell_fetch (sheet->gnum_sheet, col, row);
cell_set_text_simple (cell, "");
}
sheet->blank = 0 ;
sheet->blank = FALSE ;
cell_set_comment (cell, text);
}
}
......@@ -1464,7 +1454,7 @@ ms_excel_sheet_append_comment (MS_EXCEL_SHEET * sheet, int col, int row, char *t
if (cell->comment && cell->comment->comment &&
cell->comment->comment->str) {
char *txt = g_strconcat (cell->comment->comment->str, text, NULL);
sheet->blank = 0 ;
sheet->blank = FALSE ;
cell_set_comment (cell, txt);
g_free (txt);
}
......@@ -1793,7 +1783,7 @@ ms_excel_read_cell (BIFF_QUERY * q, MS_EXCEL_SHEET * sheet)
row, col, lastcol, lastcol); */
incr = (lastcol > col) ? 1 : -1;
while (col != lastcol){
ms_excel_sheet_insert (sheet, BIFF_GETWORD (ptr), EX_GETCOL (q), EX_GETROW (q), 0);
ms_excel_sheet_insert (sheet, BIFF_GETWORD (ptr), col, EX_GETROW (q), 0);
col += incr;
ptr += 2;
}
......@@ -1971,6 +1961,7 @@ ms_excel_read_cell (BIFF_QUERY * q, MS_EXCEL_SHEET * sheet)
array_col_first, array_row_first);
if (cell)
cell_set_formula_tree_simple (cell, tr);
sheet->blank = FALSE;
expr_tree_unref (tr);
}
break ;
......@@ -1988,6 +1979,8 @@ ms_excel_read_cell (BIFF_QUERY * q, MS_EXCEL_SHEET * sheet)
array_col_first = BIFF_GETBYTE(q->data + 4) ;
array_col_last = BIFF_GETBYTE(q->data + 5) ;
sheet->blank = FALSE;
/* int options = BIFF_GETWORD(q->data + 6) ; not so useful */
data = q->data + 14 ;
data_len = BIFF_GETWORD(q->data + 12) ;
......@@ -2007,6 +2000,7 @@ ms_excel_read_cell (BIFF_QUERY * q, MS_EXCEL_SHEET * sheet)
expr_tree_unref (tr);
}
}
sheet->blank = FALSE;
break ;
}
case BIFF_FORMULA: /* See: S59D8F.HTM */
......@@ -2037,8 +2031,11 @@ ms_excel_read_cell (BIFF_QUERY * q, MS_EXCEL_SHEET * sheet)
else {
const char *str;
str = sheet->wb->global_strings[idx] ;
if (str)
ms_excel_sheet_insert_val (sheet, EX_GETXF (q), EX_GETCOL (q), EX_GETROW (q),
value_new_string (str));
else
ms_excel_sheet_insert (sheet, EX_GETXF (q), EX_GETCOL (q), EX_GETROW (q), "");
}
break;
}
......
......@@ -13,7 +13,7 @@
typedef struct _MS_EXCEL_SHEET
{
int blank;
gboolean blank;
Sheet *gnum_sheet;
struct _MS_EXCEL_WORKBOOK *wb;
eBiff_version ver;
......
......@@ -31,7 +31,7 @@
#include "excel.h"
#include "ms-excel-write.h"
#define EXCEL_DEBUG 0
#define EXCEL_DEBUG 1
typedef struct _XF XF;
typedef struct _FONTS FONTS;
......@@ -45,6 +45,8 @@ struct _SHEET {
Sheet *gnum_sheet;
guint32 streamPos;
guint32 boundsheetPos;
guint32 maxx;
guint32 maxy;
};
struct _WORKBOOK {
......@@ -439,24 +441,24 @@ static PALETTE *
write_palette (BIFF_PUT *bp, WORKBOOK *wb)
{
PALETTE *pal = g_new (PALETTE, 1);
guint8 r,g,b, data[16];
guint32 num;
guint8 r,g,b, data[8];
guint32 num, i;
pal->col_to_idx = g_hash_table_new (g_direct_hash,
g_direct_equal);
/* FIXME: should scan styles for colors and write intelligently. */
ms_biff_put_var_next (bp, BIFF_PALETTE);
BIFF_SET_GUINT16 (data, 2); /* Entries */
BIFF_SET_GUINT16 (data, EXCEL_DEF_PAL_LEN); /* Entries */
r = g = b = 0xff;
num = (b<<16) + (g<<8) + (r<<0);
BIFF_SET_GUINT32 (data+2+PALETTE_WHITE*4, num);
r = g = b = 0x00;
ms_biff_put_var_write (bp, data, 2);
for (i=0;i<EXCEL_DEF_PAL_LEN;i++) {
r = excel_default_palette[i].r;
g = excel_default_palette[i].g;
b = excel_default_palette[i].b;
num = (b<<16) + (g<<8) + (r<<0);
BIFF_SET_GUINT32 (data+2+PALETTE_BLACK*4, num);
ms_biff_put_var_write (bp, data, 10);
BIFF_SET_GUINT32 (data, num);
ms_biff_put_var_write (bp, data, 4);
}
ms_biff_put_commit (bp);
......@@ -739,17 +741,10 @@ write_value (BIFF_PUT *bp, Value *v, eBiff_version ver,
}
}
typedef struct {
SHEET *sheet;
BIFF_PUT *bp;
} CellArgs;
static void
write_cell (gpointer key, Cell *cell, CellArgs *a)
write_cell (BIFF_PUT *bp, SHEET *sheet, Cell *cell)
{
BIFF_PUT *bp = a->bp;
g_return_if_fail (a);
g_return_if_fail (bp);
g_return_if_fail (cell);
if (cell->parsed_node)
......@@ -759,10 +754,45 @@ write_cell (gpointer key, Cell *cell, CellArgs *a)
;
#endif
else if (cell->value)
write_value (bp, cell->value, a->sheet->wb->ver,
write_value (bp, cell->value, sheet->wb->ver,
cell->col->pos, cell->row->pos, XF_MAGIC);
}
#define MAGIC_BLANK_XF 0
static void
write_mulblank (BIFF_PUT *bp, SHEET *sheet, guint32 end_col, guint32 row, guint32 run)
{
g_return_if_fail (bp);
g_return_if_fail (run);
g_return_if_fail (sheet);
if (run == 1) {
guint8 *data;
data = ms_biff_put_len_next (bp, BIFF_BLANK, 6);
EX_SETXF (data, MAGIC_BLANK_XF);
EX_SETCOL(data, end_col);
EX_SETROW(data, row);
ms_biff_put_commit (bp);
} else { /* S59DA7.HTM */
BYTE *ptr;
guint32 len = 4 + 2*run + 2;
guint8 *data;
data = ms_biff_put_len_next (bp, BIFF_MULBLANK, len);
EX_SETCOL (data, end_col-run);
EX_SETROW (data, row);
BIFF_SET_GUINT16 (data + len - 2, end_col);
ptr = data + 4;
while (run > 0) {
BIFF_SET_GUINT16 (ptr, MAGIC_BLANK_XF);
ptr+=2;
run--;
}
}
}
static void
write_sheet_bools (BIFF_PUT *bp, SHEET *sheet)
{
......@@ -880,45 +910,29 @@ write_sheet_bools (BIFF_PUT *bp, SHEET *sheet)
if (sheet->wb->ver >= eBiffV8) {
data = ms_biff_put_len_next (bp, BIFF_DIMENSIONS, 14);
BIFF_SET_GUINT32 (data + 0, 0);
BIFF_SET_GUINT32 (data + 4, sheet->gnum_sheet->max_row_used);
BIFF_SET_GUINT32 (data + 4, sheet->maxy-1);
BIFF_SET_GUINT16 (data + 8, 0);
BIFF_SET_GUINT16 (data + 10, sheet->gnum_sheet->max_col_used+1);
BIFF_SET_GUINT16 (data + 10, sheet->maxx);
BIFF_SET_GUINT16 (data + 12, 0x0000);
} else {
data = ms_biff_put_len_next (bp, BIFF_DIMENSIONS, 10);
BIFF_SET_GUINT16 (data + 0, 0);
BIFF_SET_GUINT16 (data + 2, sheet->gnum_sheet->max_row_used);
BIFF_SET_GUINT16 (data + 2, sheet->maxy-1);
BIFF_SET_GUINT16 (data + 4, 0);
BIFF_SET_GUINT16 (data + 6, sheet->gnum_sheet->max_col_used+1);
BIFF_SET_GUINT16 (data + 6, sheet->maxx);
BIFF_SET_GUINT16 (data + 8, 0x0000);
}
ms_biff_put_commit (bp);
if (0) {
/* See: S59D67.HTM */
data = ms_biff_put_len_next (bp, BIFF_COLINFO, 11);
BIFF_SET_GUINT16 (data+ 0, 0x00); /* 1st col formatted */
BIFF_SET_GUINT16 (data+ 2, 0x00); /* last col formatted */
BIFF_SET_GUINT16 (data+ 2, sheet->maxx); /* last col formatted */
BIFF_SET_GUINT16 (data+ 4, 0x0b9b); /* width */
BIFF_SET_GUINT16 (data+ 6, 0x0f); /* XF index */
BIFF_SET_GUINT16 (data+ 8, 0x00); /* options */
BIFF_SET_GUINT8 (data+10, 0x00); /* zero */
ms_biff_put_commit (bp);
}
if (0) {
/* See: S59DDB.HTM */
data = ms_biff_put_len_next (bp, BIFF_ROW, 16);
BIFF_SET_GUINT16 (data + 0, 0); /* Row number */
BIFF_SET_GUINT16 (data + 2, 0); /* first def. col */
BIFF_SET_GUINT16 (data + 4, 0+1); /* last def. col */
BIFF_SET_GUINT16 (data + 6, 0xff); /* height */
BIFF_SET_GUINT16 (data + 8, 0x00); /* undocumented */
BIFF_SET_GUINT16 (data + 10, 0x00); /* reserved */
BIFF_SET_GUINT16 (data + 12, 0x0100); /* options */
BIFF_SET_GUINT16 (data + 14, 0x00f0); /* magic so far */
ms_biff_put_commit (bp);
}