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,75 +586,69 @@ biff_font_data_destroy (gpointer key, BIFF_FONT_DATA *fd, gpointer userdata)
return 1 ;
}
char *excel_builtin_formats[EXCEL_BUILTIN_FORMAT_LEN] = {
"", /* 0x00 */
"0",
"0.00",
"#,##0",
"#,##0.00",
"($#,##0_);($#,##0)",
"($#,##0_);[Red]($#,##0)",
"($#,##0.00_);($#,##0.00)",
"($#,##0.00_);[Red]($#,##0.00)",
"0%",
"0.00%",
"0.00E+00",
"#",
"#",
"m/d/yy",
"d-mmm-yy",
"d-mmm", /* 0x10 */
"mmm-yy",
"h:mm",
"h:mm:ss",
"h:mm",
"h:mm:ss",
"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)",
"(#,##0.00_);[Red](#,##0.00)",
"_(*",
"_($*",
"_(*",
"_($*",
"mm:ss",
"[h]:mm:ss",
"mm:ss.0",
"##0.0E+0",
"@"
};
static StyleFormat *
biff_format_data_lookup (MS_EXCEL_WORKBOOK *wb, guint16 idx)
{
char *low_formats[] =
{
"",
"0",
"0.00",
"#,##0",
"#,##0.00",
"($#,##0_);($#,##0)",
"($#,##0_);[Red]($#,##0)",
"($#,##0.00_);($#,##0.00)",
"($#,##0.00_);[Red]($#,##0.00)",
"0%",
"0.00%",
"0.00E+00",
"#",
"#",
"m/d/yy",
"d-mmm-yy",
"d-mmm",
"mmm-yy",
"h:mm",
"h:mm:ss",
"h:mm",
"h:mm:ss",
"m/d/yy"
} ;
char *high_formats[] =
{
"(#,##0_);(#,##0)",
"(#,##0_);[Red](#,##0)",
"(#,##0.00_);(#,##0.00)",
"(#,##0.00_);[Red](#,##0.00)",
"_(*",
"_($*",
"_(*",
"_($*",
"mm:ss",
"[h]:mm:ss",
"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 ;
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,6 +709,38 @@ biff_name_data_destroy (gpointer key, BIFF_NAME_DATA *bnd, gpointer userdata)
return 1 ;
}
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
* there was a bug in the extraction that swapped the
* red and blue. It is too much effort to retype this.
* So I'll leave it in this odd format for now.
*/
{ 0,0,0 }, { 255,255,255 }, { 0,0,255 }, { 0,255,0 },
{ 255,0,0 }, { 0,255,255 }, { 255,0,255 }, { 255,255,0},
{ 0,0,128 }, { 0,128,0 }, { 128,0,0 }, { 0,128,128 },
{ 128,0,128 }, { 128,128,0 }, { 192,192,192}, {128,128,128},
{ 255,153,153}, {102,51,153}, {204,255,255}, {255,255,204 },
{ 102,0,102 }, { 128,128,255 }, {204,102,0}, {255,204,204 },
{ 128,0,0 }, { 255,0,255 }, { 0,255,255 }, { 255,255,0 },
{ 128,0,128 }, { 0,0,128 }, { 128,128,0 }, { 255,0,0 },
{255,204,0}, {255,255,204}, {204,255,204}, { 153,255,255 },
{255,204,153}, {204,153,255}, {255,153,204}, {153,204,255},
{255,102,51}, {204,204,51}, {0,204,153}, {0,204,255},
{0,153,255}, {0,102,255}, {153,102,102}, {150,150,150},
{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 ()
{
......@@ -722,42 +748,7 @@ ms_excel_default_palette ()
if (!pal)
{
static struct default_color
{
/* 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
* there was a bug in the extraction that swapped the
* 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},
{ 0,0,128 }, { 0,128,0 }, { 128,0,0 }, { 0,128,128 },
{ 128,0,128 }, { 128,128,0 }, { 192,192,192}, {128,128,128},
{ 255,153,153}, {102,51,153}, {204,255,255}, {255,255,204 },
{ 102,0,102 }, { 128,128,255 }, {204,102,0}, {255,204,204 },
{ 128,0,0 }, { 255,0,255 }, { 0,255,255 }, { 255,255,0 },
{ 128,0,128 }, { 0,0,128 }, { 128,128,0 }, { 255,0,0 },
{255,204,0}, {255,255,204}, {204,255,204}, { 153,255,255 },
{255,204,153}, {204,153,255}, {255,153,204}, {153,204,255},
{255,102,51}, {204,204,51}, {0,204,153}, {0,204,255},
{0,153,255}, {0,102,255}, {153,102,102}, {150,150,150},
{102,51,0}, {102,153,51}, {0,51,0}, {0,51,51},
{0,51,153}, {102,51,153}, {153,51,51}, {51,51,51}
};
int entries = sizeof(default_colors)/
sizeof(struct default_color);
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] ;
ms_excel_sheet_insert_val (sheet, EX_GETXF (q), EX_GETCOL (q), EX_GETROW (q),
value_new_string (str));
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 */
r = g = b = 0xff;
num = (b<<16) + (g<<8) + (r<<0);
BIFF_SET_GUINT32 (data+2+PALETTE_WHITE*4, num);
r = g = b = 0x00;
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_GUINT16 (data, EXCEL_DEF_PAL_LEN); /* Entries */
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, 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);