Commit 4ee2ee43 authored by Arturo Espinosa's avatar Arturo Espinosa

Format fixes



Format fixes

Paste works just like Excel now.  Dragging a selection
moves the cursor and the selection properly.

Move the paste-special dialog box to its own file.

Other misc fixes.

Miguel.
parent 26db3fa1
1998-08-20 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/gnumeric-sheet.c (gnumeric_sheet_set_cursor_bounds): New
routine to set the cursor bounds.
* src/sheet.c (sheet_selection_paste): Set the cursor and the
selection to the new spot.
* src/dialog-paste-specia.c: Move the dialog code here.
* src/format.c (format_number): Do not abort after we have
processed the whole format, but rather append the rest of the
format string.
(style_entry_free): Kill the warnings
1998-08-20 Chris Lahey <clahey@umich.edu>
* src/style.h: Added StyleFormatEntry and changed StyleFormat.
......
1998-08-20 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/gnumeric-sheet.c (gnumeric_sheet_set_cursor_bounds): New
routine to set the cursor bounds.
* src/sheet.c (sheet_selection_paste): Set the cursor and the
selection to the new spot.
* src/dialog-paste-specia.c: Move the dialog code here.
* src/format.c (format_number): Do not abort after we have
processed the whole format, but rather append the rest of the
format string.
(style_entry_free): Kill the warnings
1998-08-20 Chris Lahey <clahey@umich.edu>
* src/style.h: Added StyleFormatEntry and changed StyleFormat.
......
1998-08-20 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/gnumeric-sheet.c (gnumeric_sheet_set_cursor_bounds): New
routine to set the cursor bounds.
* src/sheet.c (sheet_selection_paste): Set the cursor and the
selection to the new spot.
* src/dialog-paste-specia.c: Move the dialog code here.
* src/format.c (format_number): Do not abort after we have
processed the whole format, but rather append the rest of the
format string.
(style_entry_free): Kill the warnings
1998-08-20 Chris Lahey <clahey@umich.edu>
* src/style.h: Added StyleFormatEntry and changed StyleFormat.
......
1998-08-20 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/gnumeric-sheet.c (gnumeric_sheet_set_cursor_bounds): New
routine to set the cursor bounds.
* src/sheet.c (sheet_selection_paste): Set the cursor and the
selection to the new spot.
* src/dialog-paste-specia.c: Move the dialog code here.
* src/format.c (format_number): Do not abort after we have
processed the whole format, but rather append the rest of the
format string.
(style_entry_free): Kill the warnings
1998-08-20 Chris Lahey <clahey@umich.edu>
* src/style.h: Added StyleFormatEntry and changed StyleFormat.
......
......@@ -17,8 +17,9 @@ GNUMERIC_BASE_SOURCES = \
cell.c \
clipboard.c \
clipboard.h \
dialog-goto-cell.c \
dialog-cell-format.c \
dialog-goto-cell.c \
dialog-paste-special.c \
dialogs.h \
eval.c \
expr.c \
......
......@@ -173,143 +173,4 @@ clipboard_release (CellRegion *region)
g_free (region);
}
static struct {
char *name;
int disables_second_group;
} paste_types [] = {
{ N_("All"), 0 },
{ N_("Formulas"), 0 },
{ N_("Values"), 0 },
{ N_("Formats"), 1 },
{ NULL, 0 }
};
static char *paste_ops [] = {
N_("None"),
N_("Add"),
N_("Substract"),
N_("Multiply"),
N_("Divide"),
NULL
};
static void
disable_op_group (GtkWidget *widget, GtkWidget *group)
{
gtk_widget_set_sensitive (group, FALSE);
}
static void
enable_op_group (GtkWidget *widget, GtkWidget *group)
{
gtk_widget_set_sensitive (group, TRUE);
}
int
dialog_paste_special (void)
{
GtkWidget *dialog, *hbox;
GtkWidget *f1, *f1v, *f2, *f2v;
GSList *group_type, *group_ops;
int result, i;
dialog = gnome_dialog_new (_("Paste special"),
GNOME_STOCK_BUTTON_OK,
GNOME_STOCK_BUTTON_CANCEL,
NULL);
f1 = gtk_frame_new (_("Paste type"));
f1v = gtk_vbox_new (TRUE, 0);
gtk_container_add (GTK_CONTAINER (f1), f1v);
f2 = gtk_frame_new (_("Operation"));
f2v = gtk_vbox_new (TRUE, 0);
gtk_container_add (GTK_CONTAINER (f2), f2v);
group_type = NULL;
for (i = 0; paste_types [i].name; i++){
GtkSignalFunc func;
GtkWidget *r;
if (paste_types [i].disables_second_group)
func = GTK_SIGNAL_FUNC (disable_op_group);
else
func = GTK_SIGNAL_FUNC (enable_op_group);
r = gtk_radio_button_new_with_label (group_type, _(paste_types [i].name));
group_type = GTK_RADIO_BUTTON (r)->group;
gtk_signal_connect (GTK_OBJECT (r), "toggled", func, f2);
gtk_box_pack_start_defaults (GTK_BOX (f1v), r);
}
group_ops = NULL;
for (i = 0; paste_ops [i]; i++){
GtkWidget *r;
r = gtk_radio_button_new_with_label (group_ops, _(paste_ops [i]));
group_ops = GTK_RADIO_BUTTON (r)->group;
gtk_box_pack_start_defaults (GTK_BOX (f2v), r);
}
hbox = gtk_hbox_new (TRUE, 0);
gtk_box_pack_start_defaults (GTK_BOX (hbox), f1);
gtk_box_pack_start_defaults (GTK_BOX (hbox), f2);
gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), hbox, TRUE, TRUE, 0);
gtk_widget_show_all (hbox);
/* Run the dialog */
gnome_dialog_run_modal (GNOME_DIALOG (dialog));
/* Fetch the results */
result = 0;
i = gtk_radio_group_get_selected (group_type);
switch (i){
case 0: /* all */
result = PASTE_ALL_TYPES;
break;
case 1: /* formulas */
result = PASTE_FORMULAS;
break;
case 2: /* values */
result = PASTE_VALUES;
break;
case 3: /* formats */
result = PASTE_FORMATS;
break;
}
/* If it was not just formats, check operation */
if (i != 3){
i = gtk_radio_group_get_selected (group_ops);
switch (i){
case 1: /* Add */
result |= PASTE_OP_ADD;
break;
case 2:
result |= PASTE_OP_SUB;
break;
case 3:
result |= PASTE_OP_MULT;
break;
case 4:
result |= PASTE_OP_DIV;
break;
}
}
gtk_object_destroy (GTK_OBJECT (dialog));
return result;
}
......@@ -29,6 +29,4 @@ void clipboard_paste_region (CellRegion *region,
void clipboard_release (CellRegion *region);
int dialog_paste_special (void);
#endif
......@@ -31,6 +31,7 @@ static Cell *first_cell;
/* The various formats */
static char *cell_format_numbers [] = {
"General",
"0",
"0.00",
"#,##0",
......
/*
* Clipboard.c: Implements the copy/paste operations
* (C) 1998 The Free Software Foundation.
*
* Author:
* MIguel de Icaza (miguel@gnu.org)
*
*/
#include <config.h>
#include <gnome.h>
#include "gnumeric.h"
#include "gnumeric-util.h"
#include "clipboard.h"
#include "eval.h"
#include "dialogs.h"
static struct {
char *name;
int disables_second_group;
} paste_types [] = {
{ N_("All"), 0 },
{ N_("Formulas"), 0 },
{ N_("Values"), 0 },
{ N_("Formats"), 1 },
{ NULL, 0 }
};
static char *paste_ops [] = {
N_("None"),
N_("Add"),
N_("Substract"),
N_("Multiply"),
N_("Divide"),
NULL
};
static void
disable_op_group (GtkWidget *widget, GtkWidget *group)
{
gtk_widget_set_sensitive (group, FALSE);
}
static void
enable_op_group (GtkWidget *widget, GtkWidget *group)
{
gtk_widget_set_sensitive (group, TRUE);
}
int
dialog_paste_special (void)
{
GtkWidget *dialog, *hbox;
GtkWidget *f1, *f1v, *f2, *f2v;
GSList *group_type, *group_ops;
int result, i;
dialog = gnome_dialog_new (_("Paste special"),
GNOME_STOCK_BUTTON_OK,
GNOME_STOCK_BUTTON_CANCEL,
NULL);
f1 = gtk_frame_new (_("Paste type"));
f1v = gtk_vbox_new (TRUE, 0);
gtk_container_add (GTK_CONTAINER (f1), f1v);
f2 = gtk_frame_new (_("Operation"));
f2v = gtk_vbox_new (TRUE, 0);
gtk_container_add (GTK_CONTAINER (f2), f2v);
group_type = NULL;
for (i = 0; paste_types [i].name; i++){
GtkSignalFunc func;
GtkWidget *r;
if (paste_types [i].disables_second_group)
func = GTK_SIGNAL_FUNC (disable_op_group);
else
func = GTK_SIGNAL_FUNC (enable_op_group);
r = gtk_radio_button_new_with_label (group_type, _(paste_types [i].name));
group_type = GTK_RADIO_BUTTON (r)->group;
gtk_signal_connect (GTK_OBJECT (r), "toggled", func, f2);
gtk_box_pack_start_defaults (GTK_BOX (f1v), r);
}
group_ops = NULL;
for (i = 0; paste_ops [i]; i++){
GtkWidget *r;
r = gtk_radio_button_new_with_label (group_ops, _(paste_ops [i]));
group_ops = GTK_RADIO_BUTTON (r)->group;
gtk_box_pack_start_defaults (GTK_BOX (f2v), r);
}
hbox = gtk_hbox_new (TRUE, 0);
gtk_box_pack_start_defaults (GTK_BOX (hbox), f1);
gtk_box_pack_start_defaults (GTK_BOX (hbox), f2);
gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), hbox, TRUE, TRUE, 0);
gtk_widget_show_all (hbox);
/* Run the dialog */
gnome_dialog_run_modal (GNOME_DIALOG (dialog));
/* Fetch the results */
result = 0;
i = gtk_radio_group_get_selected (group_type);
switch (i){
case 0: /* all */
result = PASTE_ALL_TYPES;
break;
case 1: /* formulas */
result = PASTE_FORMULAS;
break;
case 2: /* values */
result = PASTE_VALUES;
break;
case 3: /* formats */
result = PASTE_FORMATS;
break;
}
/* If it was not just formats, check operation */
if (i != 3){
i = gtk_radio_group_get_selected (group_ops);
switch (i){
case 1: /* Add */
result |= PASTE_OP_ADD;
break;
case 2:
result |= PASTE_OP_SUB;
break;
case 3:
result |= PASTE_OP_MULT;
break;
case 4:
result |= PASTE_OP_DIV;
break;
}
}
gtk_object_destroy (GTK_OBJECT (dialog));
return result;
}
#ifndef DIALOGS_H
#define DIALOGS_H
void dialog_goto_cell (Workbook *wb);
void dialog_cell_format (Sheet *sheet);
void dialog_goto_cell (Workbook *wb);
void dialog_cell_format (Sheet *sheet);
int dialog_paste_special (void);
#endif
......@@ -31,6 +31,7 @@ static Cell *first_cell;
/* The various formats */
static char *cell_format_numbers [] = {
"General",
"0",
"0.00",
"#,##0",
......
/*
* Clipboard.c: Implements the copy/paste operations
* (C) 1998 The Free Software Foundation.
*
* Author:
* MIguel de Icaza (miguel@gnu.org)
*
*/
#include <config.h>
#include <gnome.h>
#include "gnumeric.h"
#include "gnumeric-util.h"
#include "clipboard.h"
#include "eval.h"
#include "dialogs.h"
static struct {
char *name;
int disables_second_group;
} paste_types [] = {
{ N_("All"), 0 },
{ N_("Formulas"), 0 },
{ N_("Values"), 0 },
{ N_("Formats"), 1 },
{ NULL, 0 }
};
static char *paste_ops [] = {
N_("None"),
N_("Add"),
N_("Substract"),
N_("Multiply"),
N_("Divide"),
NULL
};
static void
disable_op_group (GtkWidget *widget, GtkWidget *group)
{
gtk_widget_set_sensitive (group, FALSE);
}
static void
enable_op_group (GtkWidget *widget, GtkWidget *group)
{
gtk_widget_set_sensitive (group, TRUE);
}
int
dialog_paste_special (void)
{
GtkWidget *dialog, *hbox;
GtkWidget *f1, *f1v, *f2, *f2v;
GSList *group_type, *group_ops;
int result, i;
dialog = gnome_dialog_new (_("Paste special"),
GNOME_STOCK_BUTTON_OK,
GNOME_STOCK_BUTTON_CANCEL,
NULL);
f1 = gtk_frame_new (_("Paste type"));
f1v = gtk_vbox_new (TRUE, 0);
gtk_container_add (GTK_CONTAINER (f1), f1v);
f2 = gtk_frame_new (_("Operation"));
f2v = gtk_vbox_new (TRUE, 0);
gtk_container_add (GTK_CONTAINER (f2), f2v);
group_type = NULL;
for (i = 0; paste_types [i].name; i++){
GtkSignalFunc func;
GtkWidget *r;
if (paste_types [i].disables_second_group)
func = GTK_SIGNAL_FUNC (disable_op_group);
else
func = GTK_SIGNAL_FUNC (enable_op_group);
r = gtk_radio_button_new_with_label (group_type, _(paste_types [i].name));
group_type = GTK_RADIO_BUTTON (r)->group;
gtk_signal_connect (GTK_OBJECT (r), "toggled", func, f2);
gtk_box_pack_start_defaults (GTK_BOX (f1v), r);
}
group_ops = NULL;
for (i = 0; paste_ops [i]; i++){
GtkWidget *r;
r = gtk_radio_button_new_with_label (group_ops, _(paste_ops [i]));
group_ops = GTK_RADIO_BUTTON (r)->group;
gtk_box_pack_start_defaults (GTK_BOX (f2v), r);
}
hbox = gtk_hbox_new (TRUE, 0);
gtk_box_pack_start_defaults (GTK_BOX (hbox), f1);
gtk_box_pack_start_defaults (GTK_BOX (hbox), f2);
gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), hbox, TRUE, TRUE, 0);
gtk_widget_show_all (hbox);
/* Run the dialog */
gnome_dialog_run_modal (GNOME_DIALOG (dialog));
/* Fetch the results */
result = 0;
i = gtk_radio_group_get_selected (group_type);
switch (i){
case 0: /* all */
result = PASTE_ALL_TYPES;
break;
case 1: /* formulas */
result = PASTE_FORMULAS;
break;
case 2: /* values */
result = PASTE_VALUES;
break;
case 3: /* formats */
result = PASTE_FORMATS;
break;
}
/* If it was not just formats, check operation */
if (i != 3){
i = gtk_radio_group_get_selected (group_ops);
switch (i){
case 1: /* Add */
result |= PASTE_OP_ADD;
break;
case 2:
result |= PASTE_OP_SUB;
break;
case 3:
result |= PASTE_OP_MULT;
break;
case 4:
result |= PASTE_OP_DIV;
break;
}
}
gtk_object_destroy (GTK_OBJECT (dialog));
return result;
}
#ifndef DIALOGS_H
#define DIALOGS_H
void dialog_goto_cell (Workbook *wb);
void dialog_cell_format (Sheet *sheet);
void dialog_goto_cell (Workbook *wb);
void dialog_cell_format (Sheet *sheet);
int dialog_paste_special (void);
#endif
......@@ -419,6 +419,13 @@ format_number(gdouble number, StyleFormatEntry *style_format_entry, char **color
info.decimal = -1;
info.timeformat = 0;
info.hasnumbers = FALSE;
if (strcmp (format, "General") == 0){
char buffer [40];
snprintf (buffer, sizeof (buffer), "%g", number);
return g_strdup (buffer);
}
for ( i = 0; i < length; i++ )
{
......
......@@ -224,6 +224,21 @@ gnumeric_sheet_move_cursor (GnumericSheet *gsheet, int col, int row)
move_cursor (gsheet, col, row, 1);
}
void
gnumeric_sheet_set_cursor_bounds (GnumericSheet *gsheet,
int start_col, int start_row,
int end_col, int end_row)
{
g_return_if_fail (gsheet != NULL);
g_return_if_fail (GNUMERIC_IS_SHEET (gsheet));
gnumeric_sheet_cursor_set (gsheet, start_col, start_row);
item_cursor_set_bounds (gsheet->item_cursor,
start_col, start_row, end_col, end_row);
gnumeric_sheet_load_cell_val (gsheet);
}
/*
* move_cursor_horizontal:
* @Sheet: The sheet name
......
......@@ -52,6 +52,9 @@ void gnumeric_sheet_cursor_set (GnumericSheet *gsheet,
int col, int row);
void gnumeric_sheet_move_cursor (GnumericSheet *gsheet,
int col, int row);
void gnumeric_sheet_set_cursor_bounds (GnumericSheet *gsheet,
int start_col, int start_row,
int end_col, int end_row);
void gnumeric_sheet_load_cell_val (GnumericSheet *gsheet);
void gnumeric_sheet_accept_pending_output (GnumericSheet *sheet);
void gnumeric_sheet_compute_visible_ranges (GnumericSheet *gsheet);
......
......@@ -224,6 +224,21 @@ gnumeric_sheet_move_cursor (GnumericSheet *gsheet, int col, int row)
move_cursor (gsheet, col, row, 1);
}
void
gnumeric_sheet_set_cursor_bounds (GnumericSheet *gsheet,
int start_col, int start_row,
int end_col, int end_row)
{
g_return_if_fail (gsheet != NULL);
g_return_if_fail (GNUMERIC_IS_SHEET (gsheet));
gnumeric_sheet_cursor_set (gsheet, start_col, start_row);
item_cursor_set_bounds (gsheet->item_cursor,
start_col, start_row, end_col, end_row);
gnumeric_sheet_load_cell_val (gsheet);
}
/*
* move_cursor_horizontal:
* @Sheet: The sheet name
......
......@@ -52,6 +52,9 @@ void gnumeric_sheet_cursor_set (GnumericSheet *gsheet,
int col, int row);
void gnumeric_sheet_move_cursor (GnumericSheet *gsheet,
int col, int row);
void gnumeric_sheet_set_cursor_bounds (GnumericSheet *gsheet,
int start_col, int start_row,
int end_col, int end_row);
void gnumeric_sheet_load_cell_val (GnumericSheet *gsheet);
void gnumeric_sheet_accept_pending_output (GnumericSheet *sheet);
void gnumeric_sheet_compute_visible_ranges (GnumericSheet *gsheet);
......
......@@ -125,7 +125,7 @@ sheet_col_selection_changed (ItemBar *item_bar, int column, int reset, Sheet *sh
ci = sheet_col_get (sheet, column);
if (reset){
sheet_cursor_set (sheet, column, 0);
sheet_cursor_set (sheet, column, 0, column, SHEET_MAX_ROWS - 1);
sheet_selection_clear (sheet);
sheet_selection_append_range (sheet,
column, 0,
......@@ -151,7 +151,7 @@ sheet_row_selection_changed (ItemBar *item_bar, int row, int reset, Sheet *sheet
ri = sheet_row_get (sheet, row);
if (reset){
sheet_cursor_set (sheet, 0, row);
sheet_cursor_set (sheet, 0, row, SHEET_MAX_COLS-1, row);
sheet_selection_clear (sheet);
sheet_selection_append_range (sheet,
0, row,
......@@ -868,7 +868,7 @@ sheet_select_all (Sheet *sheet)
g_return_if_fail (IS_SHEET (sheet));
sheet_selection_clear_only (sheet);
sheet_cursor_set (sheet, 0, 0);
sheet_cursor_set (sheet, 0, 0, SHEET_MAX_COLS-1, SHEET_MAX_ROWS-1);
sheet_selection_append_range (sheet, 0, 0, 0, 0,
SHEET_MAX_COLS-1, SHEET_MAX_ROWS-1);
......@@ -1700,6 +1700,8 @@ void
sheet_selection_paste (Sheet *sheet, int dest_col, int dest_row, int paste_flags)
{
CellRegion *content;
int end_col, end_row;
g_return_if_fail (sheet != NULL);
g_return_if_fail (IS_SHEET (sheet));
g_return_if_fail (sheet->selections);
......@@ -1708,9 +1710,16 @@ sheet_selection_paste (Sheet *sheet, int dest_col, int dest_row, int paste_flags
if (!content)
return;
end_col = dest_col + content->cols - 1;
end_row = dest_row + content->rows - 1;
clipboard_paste_region (content, sheet, dest_col, dest_row, paste_flags);
sheet_cursor_set (sheet, dest_col, dest_row);
sheet_cursor_set (sheet, dest_col, dest_row, end_col, end_row);
sheet_selection_clear_only (sheet);
sheet_selection_append (sheet, dest_col, dest_row);
sheet_selection_extend_to (sheet, end_col, end_row);
}
......@@ -1727,10 +1736,22 @@ sheet_style_attach (Sheet *sheet, int start_col, int start_row, int end_col, int
}
void
sheet_cursor_set (Sheet *sheet, int col, int row)
sheet_cursor_set (Sheet *sheet, int start_col, int start_row, int end_col, int end_row)
{
g_return_if_fail (sheet != NULL);
g_return_if_fail (IS_SHEET (sheet));
gnumeric_sheet_set_cursor_bounds (
GNUMERIC_SHEET (sheet->sheet_view),
start_col, start_row, end_col, end_row);
}
void
sheet_cursor_move (Sheet *sheet, int col, int row)
{
g_return_if_fail (sheet != NULL);