Commit 98e8cf26 authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg

Fix more memory errors.

    creating rows/cols when resizing empties.

2000-05-17  Jody Goldberg <jgoldberg@home.com>

	* src/sheet.c
	(sheet_{col,row}_size_fit_pixels) : Return 0 if there are no cells.

	* src/summary.c (summary_item_as_text) : Be careful to strdup all strings.
	(g_str_case_equal) : Delete duplicate.
	(g_str_case_hash) : Delete duplicate.
	(summary_info_new) : Use gnumeric_strcase_hash & gnumeric_strcase_equal.

	* src/workbook-cmd-format.c (workbook_cmd_format_{column,row}_auto_fit) :
	  Only mark the sheet as dirty if something was changed.

	* src/stf.c (stf_read_workbook) :  Bring up to date.

	* src/xml-io.c (xml_write_attributes) : Do not use freed memory.

	* src/item-bar.c (item_bar_event) : Autosizing an empty row/col
	  returns 0.
parent 87c5d750
2000-05-17 Jody Goldberg <jgoldberg@home.com> 2000-05-17 Jody Goldberg <jgoldberg@home.com>
* src/summary.c (summary_item_as_text) : Be careful to strdup all strings.
(g_str_case_equal) : Delete duplicate.
(g_str_case_hash) : Delete duplicate.
(summary_info_new) : Use gnumeric_strcase_hash & gnumeric_strcase_equal.
* src/workbook-cmd-format.c (workbook_cmd_format_{column,row}_auto_fit) :
Only mark the sheet as dirty if something was changed.
* src/stf.c (stf_read_workbook) : Bring up to date.
* src/xml-io.c (xml_write_attributes) : Do not use freed memory.
* src/item-bar.c (item_bar_event) : Autosizing an empty row/col
returns 0.
* configure.in : Update required version of bonobo to 0.13. * configure.in : Update required version of bonobo to 0.13.
* README : Ditto. * README : Ditto.
...@@ -25,6 +40,7 @@ ...@@ -25,6 +40,7 @@
sheet_style_get_extent until it is more intelligent. sheet_style_get_extent until it is more intelligent.
(sheet_{insert,delete}_{cols,rows}) : Flag that the range content has (sheet_{insert,delete}_{cols,rows}) : Flag that the range content has
changed so that the status areas will be updated. changed so that the status areas will be updated.
(sheet_{col,row}_size_fit_pixels) : Return 0 if there are no cells.
* configure.in : Produce a Using OAF message in the non-bonobo case * configure.in : Produce a Using OAF message in the non-bonobo case
too. Limit xml to version 1.x for now. too. Limit xml to version 1.x for now.
......
2000-05-17 Jody Goldberg <jgoldberg@home.com> 2000-05-17 Jody Goldberg <jgoldberg@home.com>
* src/summary.c (summary_item_as_text) : Be careful to strdup all strings.
(g_str_case_equal) : Delete duplicate.
(g_str_case_hash) : Delete duplicate.
(summary_info_new) : Use gnumeric_strcase_hash & gnumeric_strcase_equal.
* src/workbook-cmd-format.c (workbook_cmd_format_{column,row}_auto_fit) :
Only mark the sheet as dirty if something was changed.
* src/stf.c (stf_read_workbook) : Bring up to date.
* src/xml-io.c (xml_write_attributes) : Do not use freed memory.
* src/item-bar.c (item_bar_event) : Autosizing an empty row/col
returns 0.
* configure.in : Update required version of bonobo to 0.13. * configure.in : Update required version of bonobo to 0.13.
* README : Ditto. * README : Ditto.
...@@ -25,6 +40,7 @@ ...@@ -25,6 +40,7 @@
sheet_style_get_extent until it is more intelligent. sheet_style_get_extent until it is more intelligent.
(sheet_{insert,delete}_{cols,rows}) : Flag that the range content has (sheet_{insert,delete}_{cols,rows}) : Flag that the range content has
changed so that the status areas will be updated. changed so that the status areas will be updated.
(sheet_{col,row}_size_fit_pixels) : Return 0 if there are no cells.
* configure.in : Produce a Using OAF message in the non-bonobo case * configure.in : Produce a Using OAF message in the non-bonobo case
too. Limit xml to version 1.x for now. too. Limit xml to version 1.x for now.
......
2000-05-17 Jody Goldberg <jgoldberg@home.com> 2000-05-17 Jody Goldberg <jgoldberg@home.com>
* src/summary.c (summary_item_as_text) : Be careful to strdup all strings.
(g_str_case_equal) : Delete duplicate.
(g_str_case_hash) : Delete duplicate.
(summary_info_new) : Use gnumeric_strcase_hash & gnumeric_strcase_equal.
* src/workbook-cmd-format.c (workbook_cmd_format_{column,row}_auto_fit) :
Only mark the sheet as dirty if something was changed.
* src/stf.c (stf_read_workbook) : Bring up to date.
* src/xml-io.c (xml_write_attributes) : Do not use freed memory.
* src/item-bar.c (item_bar_event) : Autosizing an empty row/col
returns 0.
* configure.in : Update required version of bonobo to 0.13. * configure.in : Update required version of bonobo to 0.13.
* README : Ditto. * README : Ditto.
...@@ -25,6 +40,7 @@ ...@@ -25,6 +40,7 @@
sheet_style_get_extent until it is more intelligent. sheet_style_get_extent until it is more intelligent.
(sheet_{insert,delete}_{cols,rows}) : Flag that the range content has (sheet_{insert,delete}_{cols,rows}) : Flag that the range content has
changed so that the status areas will be updated. changed so that the status areas will be updated.
(sheet_{col,row}_size_fit_pixels) : Return 0 if there are no cells.
* configure.in : Produce a Using OAF message in the non-bonobo case * configure.in : Produce a Using OAF message in the non-bonobo case
too. Limit xml to version 1.x for now. too. Limit xml to version 1.x for now.
......
2000-05-17 Jody Goldberg <jgoldberg@home.com> 2000-05-17 Jody Goldberg <jgoldberg@home.com>
* src/summary.c (summary_item_as_text) : Be careful to strdup all strings.
(g_str_case_equal) : Delete duplicate.
(g_str_case_hash) : Delete duplicate.
(summary_info_new) : Use gnumeric_strcase_hash & gnumeric_strcase_equal.
* src/workbook-cmd-format.c (workbook_cmd_format_{column,row}_auto_fit) :
Only mark the sheet as dirty if something was changed.
* src/stf.c (stf_read_workbook) : Bring up to date.
* src/xml-io.c (xml_write_attributes) : Do not use freed memory.
* src/item-bar.c (item_bar_event) : Autosizing an empty row/col
returns 0.
* configure.in : Update required version of bonobo to 0.13. * configure.in : Update required version of bonobo to 0.13.
* README : Ditto. * README : Ditto.
...@@ -25,6 +40,7 @@ ...@@ -25,6 +40,7 @@
sheet_style_get_extent until it is more intelligent. sheet_style_get_extent until it is more intelligent.
(sheet_{insert,delete}_{cols,rows}) : Flag that the range content has (sheet_{insert,delete}_{cols,rows}) : Flag that the range content has
changed so that the status areas will be updated. changed so that the status areas will be updated.
(sheet_{col,row}_size_fit_pixels) : Return 0 if there are no cells.
* configure.in : Produce a Using OAF message in the non-bonobo case * configure.in : Produce a Using OAF message in the non-bonobo case
too. Limit xml to version 1.x for now. too. Limit xml to version 1.x for now.
......
2000-05-17 Jody Goldberg <jgoldberg@home.com> 2000-05-17 Jody Goldberg <jgoldberg@home.com>
* src/summary.c (summary_item_as_text) : Be careful to strdup all strings.
(g_str_case_equal) : Delete duplicate.
(g_str_case_hash) : Delete duplicate.
(summary_info_new) : Use gnumeric_strcase_hash & gnumeric_strcase_equal.
* src/workbook-cmd-format.c (workbook_cmd_format_{column,row}_auto_fit) :
Only mark the sheet as dirty if something was changed.
* src/stf.c (stf_read_workbook) : Bring up to date.
* src/xml-io.c (xml_write_attributes) : Do not use freed memory.
* src/item-bar.c (item_bar_event) : Autosizing an empty row/col
returns 0.
* configure.in : Update required version of bonobo to 0.13. * configure.in : Update required version of bonobo to 0.13.
* README : Ditto. * README : Ditto.
...@@ -25,6 +40,7 @@ ...@@ -25,6 +40,7 @@
sheet_style_get_extent until it is more intelligent. sheet_style_get_extent until it is more intelligent.
(sheet_{insert,delete}_{cols,rows}) : Flag that the range content has (sheet_{insert,delete}_{cols,rows}) : Flag that the range content has
changed so that the status areas will be updated. changed so that the status areas will be updated.
(sheet_{col,row}_size_fit_pixels) : Return 0 if there are no cells.
* configure.in : Produce a Using OAF message in the non-bonobo case * configure.in : Produce a Using OAF message in the non-bonobo case
too. Limit xml to version 1.x for now. too. Limit xml to version 1.x for now.
......
2000-05-17 Jody Goldberg <jgoldberg@home.com> 2000-05-17 Jody Goldberg <jgoldberg@home.com>
* src/summary.c (summary_item_as_text) : Be careful to strdup all strings.
(g_str_case_equal) : Delete duplicate.
(g_str_case_hash) : Delete duplicate.
(summary_info_new) : Use gnumeric_strcase_hash & gnumeric_strcase_equal.
* src/workbook-cmd-format.c (workbook_cmd_format_{column,row}_auto_fit) :
Only mark the sheet as dirty if something was changed.
* src/stf.c (stf_read_workbook) : Bring up to date.
* src/xml-io.c (xml_write_attributes) : Do not use freed memory.
* src/item-bar.c (item_bar_event) : Autosizing an empty row/col
returns 0.
* configure.in : Update required version of bonobo to 0.13. * configure.in : Update required version of bonobo to 0.13.
* README : Ditto. * README : Ditto.
...@@ -25,6 +40,7 @@ ...@@ -25,6 +40,7 @@
sheet_style_get_extent until it is more intelligent. sheet_style_get_extent until it is more intelligent.
(sheet_{insert,delete}_{cols,rows}) : Flag that the range content has (sheet_{insert,delete}_{cols,rows}) : Flag that the range content has
changed so that the status areas will be updated. changed so that the status areas will be updated.
(sheet_{col,row}_size_fit_pixels) : Return 0 if there are no cells.
* configure.in : Produce a Using OAF message in the non-bonobo case * configure.in : Produce a Using OAF message in the non-bonobo case
too. Limit xml to version 1.x for now. too. Limit xml to version 1.x for now.
......
2000-05-17 Jody Goldberg <jgoldberg@home.com> 2000-05-17 Jody Goldberg <jgoldberg@home.com>
* src/summary.c (summary_item_as_text) : Be careful to strdup all strings.
(g_str_case_equal) : Delete duplicate.
(g_str_case_hash) : Delete duplicate.
(summary_info_new) : Use gnumeric_strcase_hash & gnumeric_strcase_equal.
* src/workbook-cmd-format.c (workbook_cmd_format_{column,row}_auto_fit) :
Only mark the sheet as dirty if something was changed.
* src/stf.c (stf_read_workbook) : Bring up to date.
* src/xml-io.c (xml_write_attributes) : Do not use freed memory.
* src/item-bar.c (item_bar_event) : Autosizing an empty row/col
returns 0.
* configure.in : Update required version of bonobo to 0.13. * configure.in : Update required version of bonobo to 0.13.
* README : Ditto. * README : Ditto.
...@@ -25,6 +40,7 @@ ...@@ -25,6 +40,7 @@
sheet_style_get_extent until it is more intelligent. sheet_style_get_extent until it is more intelligent.
(sheet_{insert,delete}_{cols,rows}) : Flag that the range content has (sheet_{insert,delete}_{cols,rows}) : Flag that the range content has
changed so that the status areas will be updated. changed so that the status areas will be updated.
(sheet_{col,row}_size_fit_pixels) : Return 0 if there are no cells.
* configure.in : Produce a Using OAF message in the non-bonobo case * configure.in : Produce a Using OAF message in the non-bonobo case
too. Limit xml to version 1.x for now. too. Limit xml to version 1.x for now.
......
...@@ -270,7 +270,7 @@ stf_read_workbook (CommandContext *context, Workbook *book, ...@@ -270,7 +270,7 @@ stf_read_workbook (CommandContext *context, Workbook *book,
Range range = sheet_get_extent (src.sheet); Range range = sheet_get_extent (src.sheet);
sheet_style_optimize (src.sheet, range); sheet_style_optimize (src.sheet, range);
sheet_range_calc_spans (src.sheet, range, TRUE); sheet_range_calc_spans (src.sheet, range, SPANCALC_RENDER);
} else } else
workbook_detach_sheet (book, src.sheet, TRUE); workbook_detach_sheet (book, src.sheet, TRUE);
......
2000-05-17 Jody Goldberg <jgoldberg@home.com>
* text-io.c (readTextWorkbook) : No need to do spans or recalc here
the import handles that now.
2000-05-09 Jody Goldberg <jgoldberg@home.com> 2000-05-09 Jody Goldberg <jgoldberg@home.com>
* Release 0.53 * Release 0.53
......
...@@ -328,16 +328,8 @@ readTextWorkbook (CommandContext *context, Workbook *book, ...@@ -328,16 +328,8 @@ readTextWorkbook (CommandContext *context, Workbook *book,
idx = text_parse_file (file, flen, idx, sheet); idx = text_parse_file (file, flen, idx, sheet);
if (idx >= 0){ if (idx >= 0)
Range range;
sheet->modified = FALSE;
workbook_attach_sheet (book, sheet); workbook_attach_sheet (book, sheet);
workbook_recalc (book);
range = sheet_get_extent (sheet);
sheet_range_calc_spans (sheet, range, TRUE);
}
} }
} }
......
...@@ -262,7 +262,6 @@ autofit_column (data_analysis_output_t *dao, int col) ...@@ -262,7 +262,6 @@ autofit_column (data_analysis_output_t *dao, int col)
actual_col = dao->start_col + col; actual_col = dao->start_col + col;
ideal_size = sheet_col_size_fit_pixels (dao->sheet, actual_col); ideal_size = sheet_col_size_fit_pixels (dao->sheet, actual_col);
if (ideal_size == 0) if (ideal_size == 0)
return; return;
......
...@@ -664,7 +664,8 @@ item_bar_event (GnomeCanvasItem *item, GdkEvent *e) ...@@ -664,7 +664,8 @@ item_bar_event (GnomeCanvasItem *item, GdkEvent *e)
} }
break; break;
case GDK_2BUTTON_PRESS: { case GDK_2BUTTON_PRESS:
{
Sheet *sheet; Sheet *sheet;
int new_size; int new_size;
...@@ -684,9 +685,11 @@ item_bar_event (GnomeCanvasItem *item, GdkEvent *e) ...@@ -684,9 +685,11 @@ item_bar_event (GnomeCanvasItem *item, GdkEvent *e)
else else
new_size = sheet_col_size_fit_pixels (sheet, item_bar->resize_pos); new_size = sheet_col_size_fit_pixels (sheet, item_bar->resize_pos);
item_bar_end_resize (item_bar, new_size); /* autosizing an empty col/row returns 0 */
} if (new_size > 0)
item_bar_end_resize (item_bar, new_size);
break; break;
}
case GDK_BUTTON_RELEASE: case GDK_BUTTON_RELEASE:
{ {
......
...@@ -933,41 +933,31 @@ cb_max_cell_width (Sheet *sheet, int col, int row, Cell *cell, ...@@ -933,41 +933,31 @@ cb_max_cell_width (Sheet *sheet, int col, int row, Cell *cell,
* @sheet: The sheet * @sheet: The sheet
* @col: the column that we want to query * @col: the column that we want to query
* *
* This routine computes the ideal size for the column to make all data fit * This routine computes the ideal size for the column to make the contents all
* properly. Return value is in size_pixels * cells in the column visible.
*
* Return : Maximum size in pixels INCLUDING margins and grid lines
* or 0 if there are no cells.
*/ */
int int
sheet_col_size_fit_pixels (Sheet *sheet, int col) sheet_col_size_fit_pixels (Sheet *sheet, int col)
{ {
ColRowInfo *ci;
int max = -1; int max = -1;
ColRowInfo *ci = sheet_col_get (sheet, col);
g_return_val_if_fail (sheet != NULL, 0);
g_return_val_if_fail (IS_SHEET (sheet), 0);
ci = sheet_col_get_info (sheet, col);
if (ci == NULL) if (ci == NULL)
return 0; return 0;
/*
* If ci == sheet->cols.default_style then it means
* no cells have been allocated here
*/
if (ci == &sheet->cols.default_style)
return ci->size_pixels;
sheet_cell_foreach_range (sheet, TRUE, sheet_cell_foreach_range (sheet, TRUE,
col, 0, col, 0,
col, SHEET_MAX_ROWS-1, col, SHEET_MAX_ROWS-1,
(ForeachCellCB)&cb_max_cell_width, &max); (ForeachCellCB)&cb_max_cell_width, &max);
/* Reset to the default width if the column was empty */ /* Reset to the default width if the column was empty */
if (max < 0) if (max <= 0)
max = sheet->cols.default_style.size_pixels; return 0;
else
/* Cell width does not include margins or far grid line*/
max += ci->margin_a + ci->margin_b + 1;
/* Cell width does not include margins or far grid line*/
max += ci->margin_a + ci->margin_b + 1;
return max; return max;
} }
...@@ -993,40 +983,28 @@ cb_max_cell_height (Sheet *sheet, int col, int row, Cell *cell, ...@@ -993,40 +983,28 @@ cb_max_cell_height (Sheet *sheet, int col, int row, Cell *cell,
* This routine computes the ideal size for the row to make all data fit * This routine computes the ideal size for the row to make all data fit
* properly. * properly.
* *
* Return : Size in pixels INCLUDING the margins and grid lines. * Return : Maximum size in pixels INCLUDING margins and grid lines
* or 0 if there are no cells.
*/ */
int int
sheet_row_size_fit_pixels (Sheet *sheet, int row) sheet_row_size_fit_pixels (Sheet *sheet, int row)
{ {
ColRowInfo *ri;
int max = -1; int max = -1;
ColRowInfo *ri = sheet_row_get (sheet, row);
g_return_val_if_fail (sheet != NULL, 0);
g_return_val_if_fail (IS_SHEET (sheet), 0);
ri = sheet_row_get_info (sheet, row);
if (ri == NULL) if (ri == NULL)
return 0; return 0;
/*
* If ri == sheet->rows.default_style then it means
* no cells have been allocated here
*/
if (ri == &sheet->rows.default_style)
return ri->size_pixels;
sheet_cell_foreach_range (sheet, TRUE, sheet_cell_foreach_range (sheet, TRUE,
0, row, 0, row,
SHEET_MAX_COLS-1, row, SHEET_MAX_COLS-1, row,
(ForeachCellCB)&cb_max_cell_height, &max); (ForeachCellCB)&cb_max_cell_height, &max);
/* Reset to the default width if the column was empty */ /* Reset to the default width if the column was empty */
if (max < 0) if (max <= 0)
max = sheet->rows.default_style.size_pixels; return 0;
else
/* Cell height does not include margins or far grid line */
max += ri->margin_a + ri->margin_b + 1;
/* Cell height does not include margins or far grid line */
max += ri->margin_a + ri->margin_b + 1;
return max; return max;
} }
......
...@@ -195,7 +195,7 @@ stf_read_workbook (CommandContext *context, Workbook *book, char const *filename ...@@ -195,7 +195,7 @@ stf_read_workbook (CommandContext *context, Workbook *book, char const *filename
range = sheet_get_extent (sheet); range = sheet_get_extent (sheet);
sheet_style_optimize (sheet, range); sheet_style_optimize (sheet, range);
workbook_recalc (book); workbook_recalc (book);
sheet_range_calc_spans (sheet, range, TRUE); sheet_range_calc_spans (sheet, range, SPANCALC_RENDER);
workbook_set_saveinfo (book, filename, FILE_FL_MANUAL, workbook_set_saveinfo (book, filename, FILE_FL_MANUAL,
gnumeric_xml_write_workbook); gnumeric_xml_write_workbook);
} else { } else {
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <ctype.h> #include <ctype.h>
#include <glib.h> #include <glib.h>
#include "summary.h" #include "summary.h"
#include "gutils.h"
/* /*
* NOTE: * NOTE:
...@@ -109,40 +110,33 @@ summary_item_as_text (const SummaryItem *sit) ...@@ -109,40 +110,33 @@ summary_item_as_text (const SummaryItem *sit)
time_t time; time_t time;
g_return_val_if_fail (sit != NULL, NULL); g_return_val_if_fail (sit != NULL, NULL);
switch (sit->type) { switch (sit->type) {
case SUMMARY_STRING: case SUMMARY_STRING:
if (sit->v.txt) if (sit->v.txt)
return g_strdup (sit->v.txt); return g_strdup (sit->v.txt);
else return g_strdup ("Internal Error");
return g_strdup ("Internal Error");
break;
case SUMMARY_BOOLEAN: case SUMMARY_BOOLEAN:
if (sit->v.boolean == 0) if (sit->v.boolean == 0)
return "False"; return g_strdup ("False");
else if (sit->v.boolean == 1) if (sit->v.boolean == 1)
return "True"; return g_strdup ("True");
else return "Unrecognized boolean value";
return "Unrecognized boolean value";
break;
case SUMMARY_SHORT: case SUMMARY_SHORT:
return g_strdup_printf ("%d", sit->v.short_i); return g_strdup_printf ("%d", sit->v.short_i);
break;
case SUMMARY_INT: case SUMMARY_INT:
return g_strdup_printf ("%d", sit->v.i); return g_strdup_printf ("%d", sit->v.i);
break;
case SUMMARY_TIME: case SUMMARY_TIME:
time = (time_t)sit->v.time.tv_sec; time = (time_t)sit->v.time.tv_sec;
ch_time = ctime(&time); ch_time = ctime(&time);
ch_time[strlen(ch_time)-1] = '\0'; ch_time[strlen(ch_time)-1] = '\0';
return g_strdup (ch_time); return g_strdup (ch_time);
break;
default: default:
return g_strdup ("Unhandled type"); return g_strdup ("Unhandled type");
...@@ -181,44 +175,18 @@ summary_item_dump (SummaryItem *sit) ...@@ -181,44 +175,18 @@ summary_item_dump (SummaryItem *sit)
g_return_if_fail (sit->name); g_return_if_fail (sit->name);
printf (" '%s' = ", sit->name); printf (" '%s' = ", sit->name);
txt = summary_item_as_text (sit); txt = summary_item_as_text (sit);
printf (" %s\n", txt); printf (" %s\n", txt);
g_free (txt); g_free (txt);
} }
static gint
g_str_case_equal (gconstpointer v, gconstpointer v2)
{
return g_strcasecmp ((const gchar*) v, (const gchar*)v2) == 0;
}
/* a char* hash function from ASU */
static guint
g_str_case_hash (gconstpointer v)
{
const char *s = (char*)v;
const char *p;
guint h=0, g;
for(p = s; *p != '\0'; p += 1) {
h = ( h << 4 ) + tolower (*p);
if ( ( g = h & 0xf0000000 ) ) {
h = h ^ (g >> 24);
h = h ^ g;
}
}
return h /* % M */;
}
SummaryInfo * SummaryInfo *
summary_info_new (void) summary_info_new (void)
{ {
SummaryInfo *sin = g_new (SummaryInfo, 1); SummaryInfo *sin = g_new (SummaryInfo, 1);
sin->names = g_hash_table_new (g_str_case_hash, sin->names = g_hash_table_new (&gnumeric_strcase_hash,
g_str_case_equal); &gnumeric_strcase_equal);
return sin; return sin;
} }
...@@ -246,7 +214,7 @@ summary_info_add (SummaryInfo *sin, SummaryItem *sit) ...@@ -246,7 +214,7 @@ summary_info_add (SummaryInfo *sin, SummaryItem *sit)
g_hash_table_remove (sin->names, sit->name); g_hash_table_remove (sin->names, sit->name);
summary_item_free (tsit); summary_item_free (tsit);
} }
g_hash_table_insert (sin->names, sit->name, sit); g_hash_table_insert (sin->names, sit->name, sit);
} }
......
...@@ -22,6 +22,7 @@ workbook_cmd_format_column_auto_fit (GtkWidget *widget, Workbook *wb) ...@@ -22,6 +22,7 @@ workbook_cmd_format_column_auto_fit (GtkWidget *widget, Workbook *wb)
{ {
Sheet *sheet = wb->current_sheet; Sheet *sheet = wb->current_sheet;
GList *l; GList *l;
gboolean changed = FALSE;
/*