Commit 5e2e700b authored by Miguel de Icaza's avatar Miguel de Icaza Committed by Arturo Espinosa

use dialog_run_and_close here. (dialog_get_number): ditto.

1999-09-18  Miguel de Icaza  <miguel@gnu.org>

	* src/dialogs/dialog-simple-input.c (dialog_get_sheet_name): use
	dialog_run_and_close here.
	(dialog_get_number): ditto.

	* src/format.c (format_add_thousand, format_remove_decimal,
	format_add_decimal): New routines.
	(format_number): Fixed bug in 'E', 'e' handler (format was
	incremented twice).

	* src/workbook-cmd-format.c: Hook up the add/remove decimal and
	add thousand actions.

	* src/sheet.c (range_is_homogeneous): Do not value_release a value
	terminate.

	* src/workbook-cmd-format.c (do_apply_style_to_selection): set
	shett dirty.
	(workbook_cmd_format_column_auto_fit): ditto.
	(workbook_cmd_format_column_width): ditto.
	(workbook_cmd_format_row_auto_fit): ditto.
	(workbook_cmd_format_row_height): ditto.

	* src/workbook.c (workbook_rename_sheet): dirty sheet.
parent 000bec1e
1999-09-18 Miguel de Icaza <miguel@gnu.org>
* src/dialogs/dialog-simple-input.c (dialog_get_sheet_name): use
dialog_run_and_close here.
(dialog_get_number): ditto.
* src/format.c (format_add_thousand, format_remove_decimal,
format_add_decimal): New routines.
(format_number): Fixed bug in 'E', 'e' handler (format was
incremented twice).
* src/workbook-cmd-format.c: Hook up the add/remove decimal and
add thousand actions.
* src/sheet.c (range_is_homogeneous): Do not value_release a value
terminate.
* src/workbook-cmd-format.c (do_apply_style_to_selection): set
shett dirty.
(workbook_cmd_format_column_auto_fit): ditto.
(workbook_cmd_format_column_width): ditto.
(workbook_cmd_format_row_auto_fit): ditto.
(workbook_cmd_format_row_height): ditto.
* src/workbook.c (workbook_rename_sheet): dirty sheet.
1999-09-19 Michael Meeks <michael@nuclecu.unam.mx>
* src/workbook.c (about_cmd): make static.
......
1999-09-18 Miguel de Icaza <miguel@gnu.org>
* src/dialogs/dialog-simple-input.c (dialog_get_sheet_name): use
dialog_run_and_close here.
(dialog_get_number): ditto.
* src/format.c (format_add_thousand, format_remove_decimal,
format_add_decimal): New routines.
(format_number): Fixed bug in 'E', 'e' handler (format was
incremented twice).
* src/workbook-cmd-format.c: Hook up the add/remove decimal and
add thousand actions.
* src/sheet.c (range_is_homogeneous): Do not value_release a value
terminate.
* src/workbook-cmd-format.c (do_apply_style_to_selection): set
shett dirty.
(workbook_cmd_format_column_auto_fit): ditto.
(workbook_cmd_format_column_width): ditto.
(workbook_cmd_format_row_auto_fit): ditto.
(workbook_cmd_format_row_height): ditto.
* src/workbook.c (workbook_rename_sheet): dirty sheet.
1999-09-19 Michael Meeks <michael@nuclecu.unam.mx>
* src/workbook.c (about_cmd): make static.
......
......@@ -44,7 +44,7 @@ dialog_get_number (Workbook *wb, const char *glade_file, double *init_and_return
}
gnome_dialog_set_parent (dialog, GTK_WINDOW (wb->toplevel));
switch (gnome_dialog_run (dialog)){
switch (gnome_dialog_run_and_close (dialog)){
case 1: /* cancel */
case -1: /* window manager close */
return FALSE;
......@@ -80,7 +80,7 @@ dialog_get_sheet_name (Workbook *wb, const char *current)
gtk_entry_set_text (GTK_ENTRY (entry), current);
gnome_dialog_set_parent (dialog, GTK_WINDOW (wb->toplevel));
switch (gnome_dialog_run (dialog)){
switch (gnome_dialog_run_and_close (dialog)){
case 1: /* cancel */
case -1: /* window manager close */
return NULL;
......
......@@ -686,6 +686,177 @@ split_time (gdouble number)
return &tm;
}
/*
* Returns a new format string with the thousand separator
* or NULL if the format string already contains the thousand
* separator
*/
char *
format_add_thousand (const char *format_string)
{
char *b;
if (!lc)
lc = localeconv ();
if (strcmp (format_string, "General") == 0){
char *s = g_strdup ("#!##0");
s [1] = THOUSAND_CHAR_OF_LC(lc);
return s;
}
if (strchr (format_string, THOUSAND_CHAR_OF_LC(lc)) != NULL)
return NULL;
b = g_malloc (strlen (format_string) + 7);
if (!b)
return NULL;
strcpy (b, "#!##0");
b [1] = THOUSAND_CHAR_OF_LC(lc);
strcpy (&b[5], format_string);
return b;
}
/*
* Finds the decimal char in @str doing the proper parsing of a
* format string
*/
static const char *
find_decimal_char (const char *str)
{
char dc = DECIMAL_CHAR_OF_LC (lc);
for (;*str; str++){
if (*str == dc)
return str;
if (*str == THOUSAND_CHAR_OF_LC (lc))
continue;
switch (*str){
/* These ones do not have any argument */
case '#': case '?': case '0': case '%':
case '-': case '+': case ')': case '£':
case ':': case '$':
case 'M': case 'm': case 'D': case 'd':
case 'Y': case 'y': case 'S': case 's':
case '*': case 'h': case 'H': case 'A':
case 'a': case 'P': case 'p':
break;
/* Quoted string */
case '"':
for (str++; *str && *str != '"'; str++)
;
break;
/* Escaped char and spacing format */
case '\\': case '_':
if (*(str+1))
str++;
break;
/* Scientific number */
case 'E': case 'e':
for (str++; *str;){
if (*str == '+')
str++;
else if (*str == '-')
str++;
else if (*str == '0')
str++;
else
break;
}
}
}
return NULL;
}
/*
* This routine scans the format_string for a decimal dot,
* and if it finds it, it removes the first zero after it to
* reduce the display precision for the number.
*
* Returns NULL if the new format would not change things
*/
char *
format_remove_decimal (const char *format_string)
{
char *ret, *t, *p;
if (!lc)
lc = localeconv ();
/*
* Consider General format as 0.0
*/
if (strcmp (format_string, "General") == 0)
format_string = "0.0#######";
ret = g_strdup (format_string);
p = (char *) find_decimal_char (ret);
if (!p){
g_free (ret);
return NULL;
}
if ((*(p+1) == '0') || (*(p+1) == '#'))
p++;
for (t = p; *t; t++)
*t = *(t+1);
return ret;
}
/*
* This routine scans format_string for the decimal
* character and when it finds it, it adds a zero after
* it to force the rendering of the number with one more digit
* of decimal precision.
*
* Returns NULL if the new format would not change things
*/
char *
format_add_decimal (const char *format_string)
{
const char *p;
char *n;
if (!lc)
lc = localeconv ();
if (strcmp (format_string, "General") == 0)
format_string = "0";
p = find_decimal_char (format_string);
if (!p){
char ret_val [3];
ret_val [0] = DECIMAL_CHAR_OF_LC(lc);
ret_val [1] = '0';
ret_val [2] = 0;
return g_strdup (ret_val);
}
p++;
n = g_malloc ((p - format_string) +
1 +
strlen (p) +
1);
if (!n)
return NULL;
strncpy (n, format_string, p - format_string);
n [p-format_string] = '0';
strcpy (&n [p-format_string+1], p);
return n;
}
static gchar *
format_number (gdouble number, const StyleFormatEntry *style_format_entry)
{
......@@ -765,7 +936,6 @@ format_number (gdouble number, const StyleFormatEntry *style_format_entry)
case 'E': case 'e':
can_render_number = 1;
info.scientific = TRUE;
format++;
for (format++; *format;){
if (*format == '+'){
info.scientific_shows_plus = TRUE;
......
......@@ -10,4 +10,9 @@ gchar *format_value (StyleFormat *format, const Value *value, StyleColor **col
void format_color_init (void);
void format_color_shutdown (void);
char *format_add_thousand (const char *format);
char *format_add_decimal (const char *format);
char *format_remove_decimal (const char *format);
#endif /* GNUMERIC_FORMAT_H */
......@@ -15,7 +15,7 @@
#include "workbook.h"
#include "workbook-cmd-format.h"
#include "dialogs.h"
#include "format.h"
static const char *money_format = "Default Money Format:$#,##0_);($#,##0)";
static const char *percent_format = "Default Percent Format:0.00%";
......@@ -23,7 +23,7 @@ static Value *
set_cell_format_style (Sheet *sheet, int col, int row, Cell *cell, void *_style)
{
Style *style = _style;
cell_set_format_from_style (cell, style->format);
return NULL;
}
......@@ -42,7 +42,6 @@ apply_format (Sheet *sheet,
sheet, TRUE,
start_col, start_row, end_col, end_row,
set_cell_format_style, closure);
}
static void
......@@ -61,6 +60,7 @@ do_apply_style_to_selection (Sheet *sheet, const char *format)
style->format = style_format_new (real_format);
selection_apply (sheet, apply_format, TRUE, style);
sheet_set_dirty (sheet, TRUE);
style_destroy (style);
}
......@@ -80,22 +80,73 @@ workbook_cmd_format_as_percent (GtkWidget *widget, Workbook *wb)
do_apply_style_to_selection (sheet, _(percent_format));
}
/*
* The routines that modify the format of a cell using the
* helper routines in format.c.
*/
typedef char *(*format_modify_fn) (const char *format);
static Value *
modify_cell_format (Sheet *sheet, int col, int row, Cell *cell, void *closure)
{
StyleFormat *sf = cell->style->format;
format_modify_fn modify_format = closure;
char *new_fmt;
new_fmt = (*modify_format) (sf->format);
if (new_fmt == NULL)
return NULL;
cell_set_format (cell, new_fmt);
g_free (new_fmt);
return NULL;
}
static void
modify_cell_region (Sheet *sheet,
int start_col, int start_row,
int end_col, int end_row,
void *closure)
{
sheet_cell_foreach_range (
sheet, TRUE,
start_col, start_row, end_col, end_row,
modify_cell_format, closure);
}
/*
* This is sort of broken, it just operates on the
* existing cells, rather than the empty spots.
* To do: think if it is worth doing.
*
* Ie, the user could set and set styles, and work on them
* with no visible cell. Does it matter?
*/
static void
do_modify_format (Workbook *wb, format_modify_fn modify_fn)
{
Sheet *sheet = workbook_get_current_sheet (wb);
selection_apply (sheet, modify_cell_region, FALSE, modify_fn);
sheet_set_dirty (sheet, TRUE);
}
void
workbook_cmd_format_add_thousands (GtkWidget *widget, Workbook *wb)
{
/* FIXME */
do_modify_format (wb, format_add_thousand);
}
void
workbook_cmd_format_add_decimals (GtkWidget *widget, Workbook *wb)
{
/* FIXME */
do_modify_format (wb, format_add_decimal);
}
void
workbook_cmd_format_remove_decimals (GtkWidget *widget, Workbook *wb)
{
/* FIXME */
do_modify_format (wb, format_remove_decimal);
}
void
......@@ -121,6 +172,7 @@ workbook_cmd_format_column_auto_fit (GtkWidget *widget, Workbook *wb)
sheet_col_set_width (sheet, col, ideal_size);
}
}
sheet_set_dirty (sheet, TRUE);
}
void
......@@ -174,6 +226,7 @@ workbook_cmd_format_column_width (GtkWidget *widget, Workbook *wb)
for (col = ss->user.start.col; col < ss->user.end.col; col++)
sheet_col_set_width_units (sheet, col, value);
}
sheet_set_dirty (sheet, TRUE);
}
void
......@@ -199,6 +252,7 @@ workbook_cmd_format_row_auto_fit (GtkWidget *widget, Workbook *wb)
sheet_row_set_height (sheet, row, ideal_size, FALSE);
}
}
sheet_set_dirty (sheet, TRUE);
}
void
......@@ -251,6 +305,7 @@ workbook_cmd_format_row_height (GtkWidget *widget, Workbook *wb)
for (row = ss->user.start.row; row < ss->user.end.row; row++)
sheet_row_set_height_units (sheet, row, value, TRUE);
}
sheet_set_dirty (sheet, TRUE);
}
void
......
......@@ -1081,12 +1081,8 @@ static GnomeUIInfo workbook_menu_edit [] = {
insert_object_cmd),
#endif
GNOMEUIINFO_SEPARATOR,
#if 1
{ GNOME_APP_UI_ITEM, N_("_Define cell names"), NULL, define_cell_cmd },
GNOMEUIINFO_SEPARATOR,
#endif
{ GNOME_APP_UI_ITEM, N_("_Recalculate"),
N_("Recalculate the spreadsheet"), recalc_cmd, NULL, NULL,
......@@ -2385,6 +2381,7 @@ workbook_rename_sheet (Workbook *wb, const char *old_name, const char *new_name)
sheet_rename (sheet, new_name);
g_hash_table_insert (wb->sheets, sheet->name, sheet);
sheet_set_dirty (sheet, TRUE);
return TRUE;
}
......
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