Commit 332034ff authored by Morten Welinder's avatar Morten Welinder Committed by Morten Welinder

Don't add one to the number of lines if the last line is empty.

2000-07-03  Morten Welinder  <terra@diku.dk>

	* src/stf-parse.c (stf_parse_get_rowcount): Don't add one to the
 	number of lines if the last line is empty.

	* src/sheet.c (sheet_cell_set_text): Plug leak.

	* src/workbook-format-toolbar.c
 	(do_sheet_selection_apply_number_format): Avoid double translation
 	of format.

	* src/mstyle.c (mstyle_set_format_text): Renamed from
 	mstyle_set_format.
	(mstyle_set_format): New function taking a StyleFormat *.
parent 672ded42
2000-07-03 Morten Welinder <terra@diku.dk>
* src/stf-parse.c (stf_parse_get_rowcount): Don't add one to the
number of lines if the last line is empty.
* src/sheet.c (sheet_cell_set_text): Plug leak.
* src/workbook-format-toolbar.c
(do_sheet_selection_apply_number_format): Avoid double translation
of format.
* src/mstyle.c (mstyle_set_format_text): Renamed from
mstyle_set_format.
(mstyle_set_format): New function taking a StyleFormat *.
2000-07-03 Jody Goldberg <jgoldberg@home.com>
* src/workbook.c : Begin the Name menu.
......@@ -23,7 +38,7 @@
* src/analysis-tools.c: Implemented `Histogram' tool (mostly).
* src/dialogs/tools.h: Related changes.
* src/dialogs/analysis-tools.glade,
src/dialogs/dialog-analysis-tools.c: Added dialogs for `Histogram'
and `Fourier Analysis' tools. The later is not implemented yet.
......
2000-07-03 Morten Welinder <terra@diku.dk>
* src/stf-parse.c (stf_parse_get_rowcount): Don't add one to the
number of lines if the last line is empty.
* src/sheet.c (sheet_cell_set_text): Plug leak.
* src/workbook-format-toolbar.c
(do_sheet_selection_apply_number_format): Avoid double translation
of format.
* src/mstyle.c (mstyle_set_format_text): Renamed from
mstyle_set_format.
(mstyle_set_format): New function taking a StyleFormat *.
2000-07-03 Jody Goldberg <jgoldberg@home.com>
* src/workbook.c : Begin the Name menu.
......@@ -23,7 +38,7 @@
* src/analysis-tools.c: Implemented `Histogram' tool (mostly).
* src/dialogs/tools.h: Related changes.
* src/dialogs/analysis-tools.glade,
src/dialogs/dialog-analysis-tools.c: Added dialogs for `Histogram'
and `Fourier Analysis' tools. The later is not implemented yet.
......
2000-07-03 Morten Welinder <terra@diku.dk>
* src/stf-parse.c (stf_parse_get_rowcount): Don't add one to the
number of lines if the last line is empty.
* src/sheet.c (sheet_cell_set_text): Plug leak.
* src/workbook-format-toolbar.c
(do_sheet_selection_apply_number_format): Avoid double translation
of format.
* src/mstyle.c (mstyle_set_format_text): Renamed from
mstyle_set_format.
(mstyle_set_format): New function taking a StyleFormat *.
2000-07-03 Jody Goldberg <jgoldberg@home.com>
* src/workbook.c : Begin the Name menu.
......@@ -23,7 +38,7 @@
* src/analysis-tools.c: Implemented `Histogram' tool (mostly).
* src/dialogs/tools.h: Related changes.
* src/dialogs/analysis-tools.glade,
src/dialogs/dialog-analysis-tools.c: Added dialogs for `Histogram'
and `Fourier Analysis' tools. The later is not implemented yet.
......
2000-07-03 Morten Welinder <terra@diku.dk>
* src/stf-parse.c (stf_parse_get_rowcount): Don't add one to the
number of lines if the last line is empty.
* src/sheet.c (sheet_cell_set_text): Plug leak.
* src/workbook-format-toolbar.c
(do_sheet_selection_apply_number_format): Avoid double translation
of format.
* src/mstyle.c (mstyle_set_format_text): Renamed from
mstyle_set_format.
(mstyle_set_format): New function taking a StyleFormat *.
2000-07-03 Jody Goldberg <jgoldberg@home.com>
* src/workbook.c : Begin the Name menu.
......@@ -23,7 +38,7 @@
* src/analysis-tools.c: Implemented `Histogram' tool (mostly).
* src/dialogs/tools.h: Related changes.
* src/dialogs/analysis-tools.glade,
src/dialogs/dialog-analysis-tools.c: Added dialogs for `Histogram'
and `Fourier Analysis' tools. The later is not implemented yet.
......
2000-07-03 Morten Welinder <terra@diku.dk>
* src/stf-parse.c (stf_parse_get_rowcount): Don't add one to the
number of lines if the last line is empty.
* src/sheet.c (sheet_cell_set_text): Plug leak.
* src/workbook-format-toolbar.c
(do_sheet_selection_apply_number_format): Avoid double translation
of format.
* src/mstyle.c (mstyle_set_format_text): Renamed from
mstyle_set_format.
(mstyle_set_format): New function taking a StyleFormat *.
2000-07-03 Jody Goldberg <jgoldberg@home.com>
* src/workbook.c : Begin the Name menu.
......@@ -23,7 +38,7 @@
* src/analysis-tools.c: Implemented `Histogram' tool (mostly).
* src/dialogs/tools.h: Related changes.
* src/dialogs/analysis-tools.glade,
src/dialogs/dialog-analysis-tools.c: Added dialogs for `Histogram'
and `Fourier Analysis' tools. The later is not implemented yet.
......
2000-07-03 Morten Welinder <terra@diku.dk>
* src/stf-parse.c (stf_parse_get_rowcount): Don't add one to the
number of lines if the last line is empty.
* src/sheet.c (sheet_cell_set_text): Plug leak.
* src/workbook-format-toolbar.c
(do_sheet_selection_apply_number_format): Avoid double translation
of format.
* src/mstyle.c (mstyle_set_format_text): Renamed from
mstyle_set_format.
(mstyle_set_format): New function taking a StyleFormat *.
2000-07-03 Jody Goldberg <jgoldberg@home.com>
* src/workbook.c : Begin the Name menu.
......@@ -23,7 +38,7 @@
* src/analysis-tools.c: Implemented `Histogram' tool (mostly).
* src/dialogs/tools.h: Related changes.
* src/dialogs/analysis-tools.glade,
src/dialogs/dialog-analysis-tools.c: Added dialogs for `Histogram'
and `Fourier Analysis' tools. The later is not implemented yet.
......
2000-07-03 Morten Welinder <terra@diku.dk>
* src/stf-parse.c (stf_parse_get_rowcount): Don't add one to the
number of lines if the last line is empty.
* src/sheet.c (sheet_cell_set_text): Plug leak.
* src/workbook-format-toolbar.c
(do_sheet_selection_apply_number_format): Avoid double translation
of format.
* src/mstyle.c (mstyle_set_format_text): Renamed from
mstyle_set_format.
(mstyle_set_format): New function taking a StyleFormat *.
2000-07-03 Jody Goldberg <jgoldberg@home.com>
* src/workbook.c : Begin the Name menu.
......@@ -23,7 +38,7 @@
* src/analysis-tools.c: Implemented `Histogram' tool (mostly).
* src/dialogs/tools.h: Related changes.
* src/dialogs/analysis-tools.glade,
src/dialogs/dialog-analysis-tools.c: Added dialogs for `Histogram'
and `Fourier Analysis' tools. The later is not implemented yet.
......
......@@ -1240,7 +1240,7 @@ ms_excel_get_style_from_xf (ExcelSheet *sheet, guint16 xfidx)
/* Format */
if (xf->style_format)
mstyle_set_format (mstyle, xf->style_format->format);
mstyle_set_format_text (mstyle, xf->style_format->format);
/* Alignment */
mstyle_set_align_v (mstyle, xf->valign);
......
......@@ -617,7 +617,7 @@ xml2ParseStyleRegionStyle (XML2ParseState *state, CHAR const **attrs)
else if (xml2ParseAttrColour (attrs, "PatternColor", &colour))
mstyle_set_color (state->style, MSTYLE_COLOR_PATTERN, colour);
else if (!strcmp (attrs[0], "Format"))
mstyle_set_format (state->style, attrs[1]);
mstyle_set_format_text (state->style, attrs[1]);
else
xml2UnknownAttr (state, attrs, "StyleRegion");
}
......
......@@ -617,7 +617,7 @@ xml2ParseStyleRegionStyle (XML2ParseState *state, CHAR const **attrs)
else if (xml2ParseAttrColour (attrs, "PatternColor", &colour))
mstyle_set_color (state->style, MSTYLE_COLOR_PATTERN, colour);
else if (!strcmp (attrs[0], "Format"))
mstyle_set_format (state->style, attrs[1]);
mstyle_set_format_text (state->style, attrs[1]);
else
xml2UnknownAttr (state, attrs, "StyleRegion");
}
......
......@@ -38,6 +38,7 @@ cell_dirty (Cell *cell)
* cell_formula_changed : Registers the expression with the sheet and
* optionally queues a recalc.
* @cell : the dirty cell.
* @queue_recalc: also queue a recalc for the cell.
*
* INTERNAL.
*/
......@@ -453,8 +454,9 @@ cell_set_expr_and_value (Cell *cell, ExprTree *expr, Value *v)
/**
* cell_set_expr_internal:
* @cell: the cell to set the formula to
* @cell: the cell to set the formula to
* @expr: an expression tree with the formula
* opt_fmt: an optional format to apply to the cell.
*
* A private internal utility to store an expression.
* Does NOT
......@@ -739,7 +741,7 @@ cell_set_format (Cell *cell, char const *format)
g_return_if_fail (mstyle != NULL);
mstyle_set_format (mstyle, format);
mstyle_set_format_text (mstyle, format);
cell_set_mstyle (cell, mstyle);
cell_dirty (cell);
}
......
......@@ -989,7 +989,7 @@ Sheet_range_set_format (PortableServer_Servant servant,
verify_range (sheet, range, &ranges);
mstyle = mstyle_new ();
mstyle_set_format (mstyle, format);
mstyle_set_format_text (mstyle, format);
ranges_set_style (sheet, ranges, mstyle);
range_list_destroy (ranges);
......
2000-07-03 Morten Welinder <terra@diku.dk>
* dialog-stf-format-page.c (format_page_format_changed): Plug
leak.
* dialog-stf-preview.c (stf_preview_colformats_add): Change to
take a StyleFormat *. All callers changed.
* dialog-stf.c (stf_dialog_result_free): Use style_format_unref
since the character strings were replaced by StyleFormats.
2000-07-02 Jody Goldberg <jgoldberg@home.com>
* dialog-define-names.c : Remove a few glitches so that things no
......
......@@ -737,7 +737,7 @@ cb_format_entry (GtkEditable *w, FormatState *state)
if (state->enable_edit) {
g_free ((char *)state->format.spec);
state->format.spec = g_strdup (tmp);
mstyle_set_format (state->result, state->format.spec);
mstyle_set_format_text (state->result, state->format.spec);
fmt_dialog_changed (state);
draw_format_preview (state);
}
......
......@@ -31,9 +31,7 @@ format_page_update_preview (DruidPageData_t *pagedata)
stf_preview_colformats_clear (info->format_run_renderdata);
iterator = info->format_run_list;
while (iterator) {
stf_preview_colformats_add (info->format_run_renderdata, iterator->data);
iterator = g_slist_next (iterator);
}
......@@ -119,7 +117,7 @@ static void
format_page_collist_select_row (GtkCList *clist, int row, int column, GdkEventButton *event, DruidPageData_t *data)
{
FormatInfo_t *info = data->format_info;
char *colformat = g_slist_nth_data (info->format_run_list, row);
StyleFormat *colformat = g_slist_nth_data (info->format_run_list, row);
if (!colformat) return;
stf_preview_set_activecolumn (info->format_run_renderdata, row);
......@@ -132,7 +130,7 @@ format_page_collist_select_row (GtkCList *clist, int row, int column, GdkEventBu
}
info->format_run_index = row;
gtk_entry_set_text (info->format_format, colformat);
gtk_entry_set_text (info->format_format, colformat->format);
}
/**
......@@ -190,16 +188,18 @@ format_page_format_changed (GtkEntry *entry, DruidPageData_t *data)
char *t[1];
GSList *listitem;
char *format = gtk_editable_get_chars (GTK_EDITABLE (entry), 0, -1);
StyleFormat *sf;
listitem = g_slist_nth (info->format_run_list, info->format_run_index);
g_return_if_fail (listitem != NULL);
if (strcmp (listitem->data, format) != 0)
sf = listitem->data;
if (strcmp (sf->format, format) != 0)
stf_cache_options_invalidate (info->format_run_cacheoptions);
if (listitem->data)
g_free (listitem->data);
listitem->data = format;
if (sf)
style_format_unref (sf);
listitem->data = style_format_new (format);
gtk_clist_set_text (info->format_collist, info->format_run_index, 1, format);
......@@ -210,7 +210,7 @@ format_page_format_changed (GtkEntry *entry, DruidPageData_t *data)
found = 0;
for (i = 0; i < info->format_sublist->rows; i++) {
gtk_clist_get_text (info->format_sublist, i, 0, t);
if (strcmp (t[0], format)==0) {
if (strcmp (t[0], format) == 0) {
found = i;
break;
}
......@@ -219,6 +219,8 @@ format_page_format_changed (GtkEntry *entry, DruidPageData_t *data)
info->format_run_manual_change = TRUE;
gtk_clist_select_row (info->format_sublist, found, 0);
gnumeric_clist_moveto (info->format_sublist, found);
g_free (format);
}
format_page_update_preview (data);
......@@ -243,7 +245,6 @@ void
stf_dialog_format_page_prepare (GnomeDruidPage *page, GnomeDruid *druid, DruidPageData_t *data)
{
FormatInfo_t *info = data->format_info;
char *t[2];
int listcount, i;
data->colcount = stf_parse_get_colcount (info->format_run_parseoptions, data->cur);
......@@ -252,7 +253,8 @@ stf_dialog_format_page_prepare (GnomeDruidPage *page, GnomeDruid *druid, DruidPa
/* If necessary add new items (non-visual) */
while (listcount <= data->colcount) {
info->format_run_list = g_slist_append (info->format_run_list, g_strdup (cell_formats[0][0]));
info->format_run_list = g_slist_append (info->format_run_list,
style_format_new (cell_formats[0][0]));
listcount++;
}
......@@ -260,8 +262,12 @@ stf_dialog_format_page_prepare (GnomeDruidPage *page, GnomeDruid *druid, DruidPa
gtk_clist_clear (info->format_collist);
for (i = 0; i <= data->colcount; i++) {
StyleFormat *sf;
char *t[2];
sf = g_slist_nth_data (info->format_run_list, i);
t[0] = g_strdup_printf ("%d", i);
t[1] = g_slist_nth_data (info->format_run_list, i);
t[1] = sf->format;
gtk_clist_append (info->format_collist, t);
g_free (t[0]);
}
......@@ -285,8 +291,12 @@ stf_dialog_format_page_prepare (GnomeDruidPage *page, GnomeDruid *druid, DruidPa
info->format_run_index = 0;
t[0] = g_slist_nth_data (info->format_run_list, 0);
gtk_entry_set_text (info->format_format, t[0]);
{
StyleFormat *sf;
sf = g_slist_nth_data (info->format_run_list, 0);
gtk_entry_set_text (info->format_format, sf->format);
}
}
/**
......
......@@ -478,9 +478,8 @@ stf_preview_format_line (RenderData_t *renderdata, GSList *data, int colcount)
StyleFormat *sf;
StyleColor *color;
char *celltext;
if (!iterator || !iterator->data) {
if (!iterator || !iterator->data) {
iterator = g_slist_next (iterator);
continue;
}
......@@ -488,18 +487,17 @@ stf_preview_format_line (RenderData_t *renderdata, GSList *data, int colcount)
/* Formatting */
if (NULL == (value = format_match (iterator->data, NULL)))
value = value_new_string (iterator->data);
sf = style_format_new (g_ptr_array_index (renderdata->colformats, col));
sf = g_ptr_array_index (renderdata->colformats, col);
celltext = format_value (sf, value, &color, iterator->data);
style_format_unref (sf);
value_release (value);
/* Replacement of old data */
g_free (iterator->data);
iterator->data = celltext;
iterator = g_slist_next (iterator);
}
}
......@@ -754,8 +752,10 @@ stf_preview_free (RenderData_t *renderdata)
g_array_free (renderdata->colwidths, TRUE);
g_array_free (renderdata->actualwidths, TRUE);
stf_preview_colformats_clear (renderdata);
g_ptr_array_free (renderdata->colformats, TRUE);
g_hash_table_foreach_remove (renderdata->hashtable,
stf_preview_hash_item_remove,
NULL);
......@@ -869,8 +869,11 @@ stf_preview_colwidths_add (RenderData_t *renderdata, int width)
void
stf_preview_colformats_clear (RenderData_t *renderdata)
{
int i;
g_return_if_fail (renderdata != NULL);
for (i = 0; i < renderdata->colformats->len; i++)
style_format_unref (g_ptr_array_index (renderdata->colformats, i));
g_ptr_array_free (renderdata->colformats, TRUE);
renderdata->colformats = g_ptr_array_new ();
}
......@@ -887,12 +890,13 @@ stf_preview_colformats_clear (RenderData_t *renderdata)
* returns : nothing
**/
void
stf_preview_colformats_add (RenderData_t *renderdata, char *format)
stf_preview_colformats_add (RenderData_t *renderdata, StyleFormat *format)
{
g_return_if_fail (renderdata != NULL);
g_return_if_fail (format != NULL);
style_format_ref (format);
g_ptr_array_add (renderdata->colformats, format);
}
......
......@@ -60,7 +60,7 @@ void stf_preview_colwidths_clear (RenderData_t *renderda
void stf_preview_colwidths_add (RenderData_t *renderdata, int width);
void stf_preview_colformats_clear (RenderData_t *renderdata);
void stf_preview_colformats_add (RenderData_t *renderdata, char *format);
void stf_preview_colformats_add (RenderData_t *renderdata, StyleFormat *format);
/* These are public utility functions */
int stf_preview_get_displayed_rowcount (RenderData_t *renderdata);
......
......@@ -622,7 +622,7 @@ stf_dialog_result_free (DialogStfResult_t *dialogresult)
iterator = dialogresult->formats;
while (iterator != NULL) {
g_free (iterator->data);
style_format_unref (iterator->data);
iterator = g_slist_next (iterator);
}
g_slist_free (dialogresult->formats);
......
......@@ -92,7 +92,7 @@ typedef struct {
StfParseOptions_t *format_run_parseoptions; /* Note : refers to either FixedInfo_t or CsvInfo_t parseoptions */
StfCacheOptions_t *format_run_cacheoptions; /* Note : refers to either FixedInfo_t or CsvInfo_t cacheoptions */
RenderData_t *format_run_source_hash; /* Note : refers to either FixedInfo_t or CsvInfo_t RenderData_t */
GSList *format_run_list;
GSList *format_run_list; /* List of StyleFormat * */
int format_run_index;
gboolean format_run_manual_change;
int format_run_displayrows; /* Number of rows to display in the preview window */
......
......@@ -536,7 +536,7 @@ mstyle_new_default (void)
mstyle = mstyle_new ();
mstyle_set_format (mstyle, "General");
mstyle_set_format_text (mstyle, "General");
mstyle_set_align_v (mstyle, VALIGN_BOTTOM);
mstyle_set_align_h (mstyle, HALIGN_GENERAL);
mstyle_set_orientation (mstyle, ORIENT_HORIZ);
......@@ -1039,14 +1039,28 @@ mstyle_get_font_size (const MStyle *style)
}
void
mstyle_set_format (MStyle *style, const char *format)
mstyle_set_format (MStyle *style, StyleFormat *format)
{
g_return_if_fail (style != NULL);
g_return_if_fail (format != NULL);
mstyle_element_unref (style->elements [MSTYLE_FORMAT]);
style->elements [MSTYLE_FORMAT].type = MSTYLE_FORMAT;
style->elements [MSTYLE_FORMAT].u.format = style_format_new (format);
style_format_ref (format);
mstyle_element_unref (style->elements[MSTYLE_FORMAT]);
style->elements[MSTYLE_FORMAT].type = MSTYLE_FORMAT;
style->elements[MSTYLE_FORMAT].u.format = format;
}
void
mstyle_set_format_text (MStyle *style, const char *format)
{
StyleFormat *sf;
g_return_if_fail (style != NULL);
g_return_if_fail (format != NULL);
sf = style_format_new (format);
mstyle_set_format (style, sf);
style_format_unref (sf);
}
StyleFormat *
......
......@@ -89,7 +89,8 @@ double mstyle_get_font_size (const MStyle *st);
/* this font must be unrefd after use */
StyleFont *mstyle_get_font (const MStyle *st, double zoom);
void mstyle_set_format (MStyle *st, const char *format);
void mstyle_set_format (MStyle *st, StyleFormat *);
void mstyle_set_format_text (MStyle *st, const char *format);
StyleFormat *mstyle_get_format (MStyle *st);
void mstyle_set_align_h (MStyle *st, StyleHAlignFlags a);
StyleHAlignFlags mstyle_get_align_h (const MStyle *st);
......
......@@ -1162,14 +1162,18 @@ sheet_cell_set_text (Cell *cell, char const *str)
Value *val;
ExprTree *expr;
EvalPos pos;
char *cformat;
g_return_if_fail (str != NULL);
g_return_if_fail (cell != NULL);
g_return_if_fail (!cell_is_partial_array (cell));
cformat = cell_get_format (cell);
format = parse_text_value_or_expr (eval_pos_init_cell (&pos, cell),
str, &val, &expr,
cell_get_format (cell));
cformat);
g_free (cformat);
if (expr != NULL) {
cell_set_expr (cell, expr, format);
expr_tree_unref (expr);
......
......@@ -1102,6 +1102,7 @@ stf_parse_get_rowcount (StfParseOptions_t *parseoptions, const char *data)
{
const char *iterator;
int rowcount = 0;
gboolean last_row_empty = TRUE;
g_return_val_if_fail (parseoptions != NULL, 0);
g_return_val_if_fail (data != NULL, 0);
......@@ -1109,9 +1110,10 @@ stf_parse_get_rowcount (StfParseOptions_t *parseoptions, const char *data)
iterator = data;
while (*iterator) {
if (*iterator == parseoptions->terminator)
rowcount++;
rowcount++, last_row_empty = TRUE;
else
last_row_empty = FALSE;
if (parseoptions->parselines != -1)
if (rowcount > parseoptions->parselines)
......@@ -1120,7 +1122,7 @@ stf_parse_get_rowcount (StfParseOptions_t *parseoptions, const char *data)
iterator++;
}
return (rowcount + 1);
return last_row_empty ? rowcount : rowcount + 1;
}
/**
......
......@@ -229,11 +229,11 @@ change_font_size_in_selection_cmd (GtkEntry *entry, Workbook *wb)
static void
do_sheet_selection_apply_number_format (Sheet *sheet,
const char *untranslated_format)
const char *translated_format)
{
MStyle *mstyle = mstyle_new ();
mstyle_set_format (mstyle, _(untranslated_format));
mstyle_set_format_text (mstyle, translated_format);
cmd_format (workbook_command_context_gui (sheet->workbook),
sheet, mstyle, NULL);
}
......
......@@ -1476,7 +1476,7 @@ xml_read_style (parse_xml_context_t *ctxt, xmlNodePtr tree)
prop = xml_value_get (tree, "Format");
if (prop != NULL) {
mstyle_set_format (mstyle, prop);
mstyle_set_format_text (mstyle, prop);
g_free (prop);
}
......
......@@ -617,7 +617,7 @@ xml2ParseStyleRegionStyle (XML2ParseState *state, CHAR const **attrs)
else if (xml2ParseAttrColour (attrs, "PatternColor", &colour))
mstyle_set_color (state->style, MSTYLE_COLOR_PATTERN, colour);
else if (!strcmp (attrs[0], "Format"))
mstyle_set_format (state->style, attrs[1]);
mstyle_set_format_text (state->style, attrs[1]);
else
xml2UnknownAttr (state, attrs, "StyleRegion");
}
......
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