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>
* 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.
* README : Ditto.
......@@ -25,6 +40,7 @@
sheet_style_get_extent until it is more intelligent.
(sheet_{insert,delete}_{cols,rows}) : Flag that the range content has
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
too. Limit xml to version 1.x for now.
......
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.
* README : Ditto.
......@@ -25,6 +40,7 @@
sheet_style_get_extent until it is more intelligent.
(sheet_{insert,delete}_{cols,rows}) : Flag that the range content has
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
too. Limit xml to version 1.x for now.
......
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.
* README : Ditto.
......@@ -25,6 +40,7 @@
sheet_style_get_extent until it is more intelligent.
(sheet_{insert,delete}_{cols,rows}) : Flag that the range content has
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
too. Limit xml to version 1.x for now.
......
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.
* README : Ditto.
......@@ -25,6 +40,7 @@
sheet_style_get_extent until it is more intelligent.
(sheet_{insert,delete}_{cols,rows}) : Flag that the range content has
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
too. Limit xml to version 1.x for now.
......
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.
* README : Ditto.
......@@ -25,6 +40,7 @@
sheet_style_get_extent until it is more intelligent.
(sheet_{insert,delete}_{cols,rows}) : Flag that the range content has
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
too. Limit xml to version 1.x for now.
......
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.
* README : Ditto.
......@@ -25,6 +40,7 @@
sheet_style_get_extent until it is more intelligent.
(sheet_{insert,delete}_{cols,rows}) : Flag that the range content has
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
too. Limit xml to version 1.x for now.
......
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.
* README : Ditto.
......@@ -25,6 +40,7 @@
sheet_style_get_extent until it is more intelligent.
(sheet_{insert,delete}_{cols,rows}) : Flag that the range content has
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
too. Limit xml to version 1.x for now.
......
......@@ -270,7 +270,7 @@ stf_read_workbook (CommandContext *context, Workbook *book,
Range range = sheet_get_extent (src.sheet);
sheet_style_optimize (src.sheet, range);
sheet_range_calc_spans (src.sheet, range, TRUE);
sheet_range_calc_spans (src.sheet, range, SPANCALC_RENDER);
} else
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>
* Release 0.53
......
......@@ -328,16 +328,8 @@ readTextWorkbook (CommandContext *context, Workbook *book,
idx = text_parse_file (file, flen, idx, sheet);
if (idx >= 0){
Range range;
sheet->modified = FALSE;
if (idx >= 0)
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)
actual_col = dao->start_col + col;
ideal_size = sheet_col_size_fit_pixels (dao->sheet, actual_col);
if (ideal_size == 0)
return;
......
......@@ -664,7 +664,8 @@ item_bar_event (GnomeCanvasItem *item, GdkEvent *e)
}
break;
case GDK_2BUTTON_PRESS: {
case GDK_2BUTTON_PRESS:
{
Sheet *sheet;
int new_size;
......@@ -684,9 +685,11 @@ item_bar_event (GnomeCanvasItem *item, GdkEvent *e)
else
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;
}
case GDK_BUTTON_RELEASE:
{
......
......@@ -933,41 +933,31 @@ cb_max_cell_width (Sheet *sheet, int col, int row, Cell *cell,
* @sheet: The sheet
* @col: the column that we want to query
*
* This routine computes the ideal size for the column to make all data fit
* properly. Return value is in size_pixels
* This routine computes the ideal size for the column to make the contents all
* cells in the column visible.
*
* Return : Maximum size in pixels INCLUDING margins and grid lines
* or 0 if there are no cells.
*/
int
sheet_col_size_fit_pixels (Sheet *sheet, int col)
{
ColRowInfo *ci;
int max = -1;
g_return_val_if_fail (sheet != NULL, 0);
g_return_val_if_fail (IS_SHEET (sheet), 0);
ci = sheet_col_get_info (sheet, col);
ColRowInfo *ci = sheet_col_get (sheet, col);
if (ci == NULL)
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,
col, 0,
col, SHEET_MAX_ROWS-1,
(ForeachCellCB)&cb_max_cell_width, &max);
/* Reset to the default width if the column was empty */
if (max < 0)
max = sheet->cols.default_style.size_pixels;
else
/* Cell width does not include margins or far grid line*/
max += ci->margin_a + ci->margin_b + 1;
if (max <= 0)
return 0;
/* Cell width does not include margins or far grid line*/
max += ci->margin_a + ci->margin_b + 1;
return max;
}
......@@ -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
* 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
sheet_row_size_fit_pixels (Sheet *sheet, int row)
{
ColRowInfo *ri;
int max = -1;
g_return_val_if_fail (sheet != NULL, 0);
g_return_val_if_fail (IS_SHEET (sheet), 0);
ri = sheet_row_get_info (sheet, row);
ColRowInfo *ri = sheet_row_get (sheet, row);
if (ri == NULL)
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,
0, row,
SHEET_MAX_COLS-1, row,
(ForeachCellCB)&cb_max_cell_height, &max);
/* Reset to the default width if the column was empty */
if (max < 0)
max = sheet->rows.default_style.size_pixels;
else
/* Cell height does not include margins or far grid line */
max += ri->margin_a + ri->margin_b + 1;
if (max <= 0)
return 0;
/* Cell height does not include margins or far grid line */
max += ri->margin_a + ri->margin_b + 1;
return max;
}
......
......@@ -195,7 +195,7 @@ stf_read_workbook (CommandContext *context, Workbook *book, char const *filename
range = sheet_get_extent (sheet);
sheet_style_optimize (sheet, range);
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,
gnumeric_xml_write_workbook);
} else {
......
......@@ -12,6 +12,7 @@
#include <ctype.h>
#include <glib.h>
#include "summary.h"
#include "gutils.h"
/*
* NOTE:
......@@ -109,40 +110,33 @@ summary_item_as_text (const SummaryItem *sit)
time_t time;
g_return_val_if_fail (sit != NULL, NULL);
switch (sit->type) {
case SUMMARY_STRING:
if (sit->v.txt)
return g_strdup (sit->v.txt);
else
return g_strdup ("Internal Error");
break;
return g_strdup ("Internal Error");
case SUMMARY_BOOLEAN:
if (sit->v.boolean == 0)
return "False";
else if (sit->v.boolean == 1)
return "True";
else
return "Unrecognized boolean value";
break;
if (sit->v.boolean == 0)
return g_strdup ("False");
if (sit->v.boolean == 1)
return g_strdup ("True");
return "Unrecognized boolean value";
case SUMMARY_SHORT:
return g_strdup_printf ("%d", sit->v.short_i);
break;
case SUMMARY_INT:
return g_strdup_printf ("%d", sit->v.i);
break;
case SUMMARY_TIME:
time = (time_t)sit->v.time.tv_sec;
ch_time = ctime(&time);
ch_time[strlen(ch_time)-1] = '\0';
return g_strdup (ch_time);
break;
default:
return g_strdup ("Unhandled type");
......@@ -181,44 +175,18 @@ summary_item_dump (SummaryItem *sit)
g_return_if_fail (sit->name);
printf (" '%s' = ", sit->name);
txt = summary_item_as_text (sit);
printf (" %s\n", 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 *
summary_info_new (void)
{
SummaryInfo *sin = g_new (SummaryInfo, 1);
sin->names = g_hash_table_new (g_str_case_hash,
g_str_case_equal);
sin->names = g_hash_table_new (&gnumeric_strcase_hash,
&gnumeric_strcase_equal);
return sin;
}
......@@ -246,7 +214,7 @@ summary_info_add (SummaryInfo *sin, SummaryItem *sit)
g_hash_table_remove (sin->names, sit->name);
summary_item_free (tsit);
}
g_hash_table_insert (sin->names, sit->name, sit);
}
......
......@@ -22,6 +22,7 @@ workbook_cmd_format_column_auto_fit (GtkWidget *widget, Workbook *wb)
{
Sheet *sheet = wb->current_sheet;
GList *l;
gboolean changed = FALSE;
/*
* Apply autofit to any columns where the selection is
......@@ -37,12 +38,14 @@ workbook_cmd_format_column_auto_fit (GtkWidget *widget, Workbook *wb)
if (ideal_size == 0)
continue;
changed = TRUE;
sheet_col_set_size_pixels (sheet, col, ideal_size, TRUE);
sheet_recompute_spans_for_col (sheet, col);
}
}
sheet_set_dirty (sheet, TRUE);
if (changed)
sheet_set_dirty (sheet, TRUE);
sheet_update (sheet);
}
......@@ -113,6 +116,7 @@ workbook_cmd_format_row_auto_fit (GtkWidget *widget, Workbook *wb)
{
Sheet *sheet = wb->current_sheet;
GList *l = sheet->selections;
gboolean changed = FALSE;
g_return_if_fail (l != NULL);
......@@ -128,10 +132,12 @@ workbook_cmd_format_row_auto_fit (GtkWidget *widget, Workbook *wb)
if (ideal_size == 0)
continue;
changed = TRUE;
sheet_row_set_size_pixels (sheet, row, ideal_size, FALSE);
}
}
sheet_set_dirty (sheet, TRUE);
if (changed)
sheet_set_dirty (sheet, TRUE);
sheet_update (sheet);
}
......
......@@ -1168,18 +1168,14 @@ xml_write_attributes (parse_xml_context_t *ctxt, guint n_args, GtkArg *args)
cur = xmlNewDocNode (ctxt->doc, ctxt->ns, "Attributes", NULL);
for (i=0; i < n_args; args++, i++) {
xmlNodePtr tmp;
xmlChar *tstr;
xmlNodePtr tmp = xmlNewDocNode (ctxt->doc, ctxt->ns, "Attribute", NULL);
xmlChar *tstr = xmlEncodeEntitiesReentrant (ctxt->doc, args->name);
tmp = xmlNewDocNode (ctxt->doc, ctxt->ns, "Attribute", NULL);
tstr = xmlEncodeEntitiesReentrant (ctxt->doc, args->name);
xmlNewChild (tmp, ctxt->ns, "name", tstr);
if (tstr) {
if (tstr)
xmlFree (tstr);
}
xmlNewChild (tmp, ctxt->ns, "type", tstr);
xmlNewChild (tmp, ctxt->ns, "type", NULL);
xml_set_value_int (tmp, "type", args->type);
xml_write_attribute (ctxt, tmp, args);
......
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