Commit 76e2dfd1 authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg

Implement a more user preferences.

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

	* src/workbook.c : Menu items for sheet and workbook preferences.

	* src/sheet-view.c (sheet_view_adjust_preferences) : New function.
	* src/sheet.c (sheet_adjust_preferences) : New function.
	(sheet_new) : Init the new preferences.
	(sheet_set_text) : Avoid leaking in the failure case.

	* src/selection.c (sheet_selection_paste) : Pass a context.

	* src/cell.c (cell_render_value) : display_fomulas is now a sheet
	  level preference.
	(cell_is_number) : return boolean.
	(cell_is_zero) : New function.

	* src/item-grid.c (item_grid_draw_cell) : honour display_zero.
parent adf8d5aa
2000-01-17 Jody Goldberg <jgoldberg@home.com>
* src/workbook.c : Menu items for sheet and workbook preferences.
* src/sheet-view.c (sheet_view_adjust_preferences) : New function.
* src/sheet.c (sheet_adjust_preferences) : New function.
(sheet_new) : Init the new preferences.
(sheet_set_text) : Avoid leaking in the failure case.
* src/selection.c (sheet_selection_paste) : Pass a context.
* src/cell.c (cell_render_value) : display_fomulas is now a sheet
level preference.
(cell_is_number) : return boolean.
(cell_is_zero) : New function.
* src/item-grid.c (item_grid_draw_cell) : honour display_zero.
2000-01-16 Morten Welinder <terra@diku.dk>
* src/datetime.c: New file.
......
2000-01-17 Jody Goldberg <jgoldberg@home.com>
* src/workbook.c : Menu items for sheet and workbook preferences.
* src/sheet-view.c (sheet_view_adjust_preferences) : New function.
* src/sheet.c (sheet_adjust_preferences) : New function.
(sheet_new) : Init the new preferences.
(sheet_set_text) : Avoid leaking in the failure case.
* src/selection.c (sheet_selection_paste) : Pass a context.
* src/cell.c (cell_render_value) : display_fomulas is now a sheet
level preference.
(cell_is_number) : return boolean.
(cell_is_zero) : New function.
* src/item-grid.c (item_grid_draw_cell) : honour display_zero.
2000-01-16 Morten Welinder <terra@diku.dk>
* src/datetime.c: New file.
......
2000-01-17 Jody Goldberg <jgoldberg@home.com>
* ms-excel-read.c (ms_excel_read_workbook) : Improve sizing of
window, Use the support for some of the new preferences
hiding scrollbars, and notebooktabs.
* ms-excel-read.c (ms_excel_read_sheet) : Use support for
hidden grid lines, hidden formulas, hidden zeros, hidden
row/col headers. Use the information on where the upper left
corner is.
2000-01-14 Jon K Hellan <hellan@acm.org>
* ms-excel-write.h: (ExcelWorkbook): Make
......
......@@ -3326,22 +3326,26 @@ ms_excel_read_sheet (ExcelSheet *sheet, BiffQuery *q, ExcelWorkbook *wb)
case BIFF_WINDOW2:
if (q->length >= 10) {
guint16 const options = MS_OLE_GET_GUINT16(q->data + 0);
guint16 const top_row = MS_OLE_GET_GUINT16(q->data + 2);
guint16 const left_col = MS_OLE_GET_GUINT16(q->data + 4);
wb->gnum_wb->display_formulas = (options & 0x0001);
if (!(options & 0x0002))
printf ("Unsupported : no grid lines\n");
if (!(options & 0x0004))
printf ("Unsupported : hidden row & col headings\n");
guint16 top_row = MS_OLE_GET_GUINT16(q->data + 2);
guint16 left_col = MS_OLE_GET_GUINT16(q->data + 4);
sheet->gnum_sheet->display_formulas = (options & 0x0001);
sheet->gnum_sheet->display_zero = (options & 0x0010);
sheet->gnum_sheet->show_grid = (options & 0x0002);
sheet->gnum_sheet->show_col_header =
sheet->gnum_sheet->show_row_header = (options & 0x0004);
/* The docs are unclear whether or not the counters
* are 0 or 1 based. I'll assume 1 based but make the
* checks conditional just in case I'm wrong.
*/
if (top_row > 0) --top_row;
if (left_col > 0) --left_col;
sheet_make_cell_visible (sheet->gnum_sheet,
left_col, top_row);
#if 0
if (!(options & 0x0008))
printf ("Unsupported : frozen panes\n");
#endif
if (!(options & 0x0010))
printf ("Unsupported : we always display zeros\n");
#if 0
if (!(options & 0x0020)) {
guint32 const grid_color = MS_OLE_GET_GUINT32(q->data + 6);
/* This is quicky fake code to express the idea */
......@@ -3361,10 +3365,8 @@ ms_excel_read_sheet (ExcelSheet *sheet, BiffQuery *q, ExcelWorkbook *wb)
printf ("Sheet flag selected\n");
}
#endif
if (options & 0x0400) {
if (options & 0x0400)
workbook_focus_sheet (sheet->gnum_sheet);
/* printf ("Sheet top in workbook\n"); */
}
}
#ifndef NO_DEBUG_EXCEL
if (q->length >= 14) {
......@@ -3898,20 +3900,24 @@ ms_excel_read_workbook (Workbook *workbook, MsOle *file)
guint16 const ratio = MS_OLE_GET_GUINT32(q->data + 16);
#endif
/* FIXME FIXME FIXME :
* This is wrong on many levels.
* 1) We are scaling this by arbitrary factors.
* 2) We are sizing the window including the toolbars,
* menus, and notbook tabs. Excel does not.
*/
workbook_view_set_size (wb->gnum_wb,
width*MAGIC_ZOOM / 20.,
height*MAGIC_ZOOM / 20.);
width*1.35 / 20.,
height*1.5 / 20.);
if (options & 0x0001)
printf ("Unsupported : Hidden sheet\n");
printf ("Unsupported : Hidden workbook\n");
if (options & 0x0002)
printf ("Unsupported : Iconic sheet\n");
if (!(options & 0x0008))
printf ("Unsupported : Hidden horizonal scroll bar\n");
if (!(options & 0x0010))
printf ("Unsupported : Hidden horizonal scroll bar\n");
if (!(options & 0x0020))
printf ("Unsupported : Hidden notbook tabs\n");
printf ("Unsupported : Iconic workbook\n");
wb->gnum_wb->show_horizontal_scrollbar = (options & 0x0008);
wb->gnum_wb->show_vertical_scrollbar = (options & 0x0010);
wb->gnum_wb->show_notebook_tabs = (options & 0x0020);
workbook_view_pref_visibility (wb->gnum_wb);
}
break;
......
......@@ -401,7 +401,7 @@ cell_render_value (Cell *cell)
cell->render_color = NULL;
}
if (cell->sheet->workbook->display_formulas && cell->parsed_node){
if (cell->sheet->display_formulas && cell->parsed_node){
ParsePosition pp;
char *tmpstr = expr_decode_tree (cell->parsed_node,
parse_pos_cell (&pp, cell));
......@@ -981,11 +981,30 @@ cell_get_horizontal_align (const Cell *cell, int align)
return align;
}
int inline
gboolean inline
cell_is_number (const Cell *cell)
{
return cell->value && VALUE_IS_NUMBER (cell->value);
}
gboolean
cell_is_zero (const Cell *cell)
{
Value const * const v = cell->value;
if (v == NULL)
return FALSE;
switch (v->type) {
case VALUE_BOOLEAN : return !v->v.v_bool;
case VALUE_INTEGER : return v->v.v_int == 0;
case VALUE_FLOAT :
{
double const res = v->v.v_float;
return (-1e-10 < res && res < 1e-10);
}
default :
return FALSE;
}
}
static inline int
cell_contents_fit_inside_column (const Cell *cell)
......
......@@ -156,7 +156,8 @@ Cell *cell_copy (const Cell *cell);
void cell_destroy (Cell *cell);
void cell_queue_redraw (Cell *cell);
int cell_get_horizontal_align (const Cell *cell, int align);
int cell_is_number (const Cell *cell);
gboolean cell_is_number (const Cell *cell);
gboolean cell_is_zero (const Cell *cell);
int cell_draw (Cell *cell, SheetView *sheet_view,
GdkGC *gc, GdkDrawable *drawable,
......
......@@ -276,7 +276,7 @@ item_grid_draw_cell (GdkDrawable *drawable, ItemGrid *item_grid, Cell *cell, int
{
GdkGC *gc = item_grid->gc;
GdkColor *col;
int count;
int count = 1;
int w, h;
MStyle *mstyle;
......@@ -302,7 +302,8 @@ item_grid_draw_cell (GdkDrawable *drawable, ItemGrid *item_grid, Cell *cell, int
h = cell->row->pixels;
/* Draw cell contents BEFORE border */
count = cell_draw (cell, item_grid->sheet_view, gc, drawable, x1, y1);
if (cell->sheet->display_zero || !cell_is_zero (cell))
count = cell_draw (cell, item_grid->sheet_view, gc, drawable, x1, y1);
item_grid_draw_border (drawable, mstyle, x1, y1, w, h, count > 1, FALSE);
......
......@@ -735,7 +735,7 @@ sheet_selection_paste (CommandContext *context, Sheet *sheet,
rinfo.origin_sheet = src_sheet;
rinfo.target_sheet = sheet;
sheet_move_range (NULL, &rinfo);
sheet_move_range (context, &rinfo);
sheet_selection_move (&rinfo);
application_clipboard_clear ();
} else {
......
......@@ -588,34 +588,6 @@ sheet_view_set_header_visibility (SheetView *sheet_view,
}
}
/* This seems unused comment it out for now */
#if 0
static void
sheet_view_scrollbar_display (SheetView *sheet_view,
gboolean show_col_scrollbar,
gboolean show_row_scrollbar)
{
g_return_if_fail (sheet_view != NULL);
g_return_if_fail (IS_SHEET_VIEW (sheet_view));
if (show_col_scrollbar){
if (!GTK_WIDGET_VISIBLE (sheet_view->hs))
gtk_widget_show (sheet_view->hs);
} else {
if (GTK_WIDGET_VISIBLE (sheet_view->hs))
gtk_widget_hide (sheet_view->hs);
}
if (show_row_scrollbar){
if (!GTK_WIDGET_VISIBLE (sheet_view->vs))
gtk_widget_show (sheet_view->vs);
} else {
if (GTK_WIDGET_VISIBLE (sheet_view->vs))
gtk_widget_hide (sheet_view->vs);
}
}
#endif
GtkWidget *
sheet_view_new (Sheet *sheet)
{
......@@ -814,6 +786,37 @@ sheet_view_selection_ant (SheetView *sheet_view)
}
}
void
sheet_view_adjust_preferences (SheetView *sheet_view)
{
Sheet *sheet = sheet_view->sheet;
Workbook *wb = sheet->workbook;
if (sheet->show_col_header)
gtk_widget_show (GTK_WIDGET (sheet_view->col_canvas));
else
gtk_widget_hide (GTK_WIDGET (sheet_view->col_canvas));
if (sheet->show_row_header)
gtk_widget_show (GTK_WIDGET (sheet_view->row_canvas));
else
gtk_widget_hide (GTK_WIDGET (sheet_view->row_canvas));
if (sheet->show_col_header && sheet->show_row_header)
gtk_widget_show (sheet_view->select_all);
else
gtk_widget_hide (sheet_view->select_all);
if (wb->show_horizontal_scrollbar)
gtk_widget_show (sheet_view->hs);
else
gtk_widget_hide (sheet_view->hs);
if (wb->show_vertical_scrollbar)
gtk_widget_show (sheet_view->vs);
else
gtk_widget_hide (sheet_view->vs);
}
#if 0
#ifdef ENABLE_BONOBO
......
......@@ -85,6 +85,8 @@ void sheet_view_scrollbar_config (SheetView const *sheet_view);
void sheet_view_selection_ant (SheetView *sheet_view);
void sheet_view_selection_unant (SheetView *sheet_view);
void sheet_view_adjust_preferences (SheetView *sheet_view);
typedef struct {
GtkTableClass parent_class;
} SheetViewClass;
......
......@@ -588,34 +588,6 @@ sheet_view_set_header_visibility (SheetView *sheet_view,
}
}
/* This seems unused comment it out for now */
#if 0
static void
sheet_view_scrollbar_display (SheetView *sheet_view,
gboolean show_col_scrollbar,
gboolean show_row_scrollbar)
{
g_return_if_fail (sheet_view != NULL);
g_return_if_fail (IS_SHEET_VIEW (sheet_view));
if (show_col_scrollbar){
if (!GTK_WIDGET_VISIBLE (sheet_view->hs))
gtk_widget_show (sheet_view->hs);
} else {
if (GTK_WIDGET_VISIBLE (sheet_view->hs))
gtk_widget_hide (sheet_view->hs);
}
if (show_row_scrollbar){
if (!GTK_WIDGET_VISIBLE (sheet_view->vs))
gtk_widget_show (sheet_view->vs);
} else {
if (GTK_WIDGET_VISIBLE (sheet_view->vs))
gtk_widget_hide (sheet_view->vs);
}
}
#endif
GtkWidget *
sheet_view_new (Sheet *sheet)
{
......@@ -814,6 +786,37 @@ sheet_view_selection_ant (SheetView *sheet_view)
}
}
void
sheet_view_adjust_preferences (SheetView *sheet_view)
{
Sheet *sheet = sheet_view->sheet;
Workbook *wb = sheet->workbook;
if (sheet->show_col_header)
gtk_widget_show (GTK_WIDGET (sheet_view->col_canvas));
else
gtk_widget_hide (GTK_WIDGET (sheet_view->col_canvas));
if (sheet->show_row_header)
gtk_widget_show (GTK_WIDGET (sheet_view->row_canvas));
else
gtk_widget_hide (GTK_WIDGET (sheet_view->row_canvas));
if (sheet->show_col_header && sheet->show_row_header)
gtk_widget_show (sheet_view->select_all);
else
gtk_widget_hide (sheet_view->select_all);
if (wb->show_horizontal_scrollbar)
gtk_widget_show (sheet_view->hs);
else
gtk_widget_hide (sheet_view->hs);
if (wb->show_vertical_scrollbar)
gtk_widget_show (sheet_view->vs);
else
gtk_widget_hide (sheet_view->vs);
}
#if 0
#ifdef ENABLE_BONOBO
......
......@@ -85,6 +85,8 @@ void sheet_view_scrollbar_config (SheetView const *sheet_view);
void sheet_view_selection_ant (SheetView *sheet_view);
void sheet_view_selection_unant (SheetView *sheet_view);
void sheet_view_adjust_preferences (SheetView *sheet_view);
typedef struct {
GtkTableClass parent_class;
} SheetViewClass;
......
......@@ -39,6 +39,18 @@
#define COLROW_GET_SEGMENT(seg_array, i) \
(g_ptr_array_index ((seg_array)->info, COLROW_SEGMENT_INDEX(i)))
void
sheet_adjust_preferences (Sheet const *sheet)
{
GList *l;
for (l = sheet->sheet_views; l; l = l->next){
SheetView *sheet_view = l->data;
sheet_view_adjust_preferences (sheet_view);
}
}
void
sheet_redraw_all (Sheet const *sheet)
{
......@@ -226,7 +238,11 @@ sheet_new (Workbook *wb, const char *name)
sheet->modified = FALSE;
/* Init preferences */
sheet->display_formulas = FALSE;
sheet->display_zero = TRUE;
sheet->show_grid = TRUE;
sheet->show_col_header = TRUE;
sheet->show_row_header = TRUE;
return sheet;
}
......@@ -1269,11 +1285,7 @@ sheet_set_text (Sheet *sheet, char const *text, Range const * r)
g_return_if_fail (sheet != NULL);
g_return_if_fail (IS_SHEET (sheet));
/*
* Figure out if a format matches, and for sanity compare that to
* a rendered version of the text, if they compare equally, then
* use that.
*/
/* If its not a formula see if there is a prefered format. */
if (!gnumeric_char_start_expr_p (*text) || text[1] == '\0') {
closure_set_cell_value closure;
char *end;
......@@ -1326,10 +1338,8 @@ sheet_set_current_value (Sheet *sheet)
/* TODO : Get a context */
/* Store the old value for undo */
if (cmd_set_text (NULL, sheet, &r.start, str, sheet->editing_saved_text))
return;
sheet_set_text (sheet, str, &r);
if (!cmd_set_text (NULL, sheet, &r.start, str, sheet->editing_saved_text))
sheet_set_text (sheet, str, &r);
for (l = sheet->sheet_views; l; l = l->next){
GnumericSheet *gsheet = GNUMERIC_SHEET_VIEW (l->data);
......
......@@ -139,8 +139,12 @@ struct _Sheet {
gboolean pristine;
gboolean modified;
/* Preferences */
/* Sheet level preferences */
gboolean display_formulas;
gboolean display_zero;
gboolean show_grid;
gboolean show_col_header;
gboolean show_row_header;
/* Solver parameters */
SolverParameters solver_parameters;
......@@ -402,6 +406,8 @@ void sheet_shift_rows (CommandContext *context, Sheet *sheet,
int col,
int start_row, int end_row, int count);
void sheet_adjust_preferences (Sheet const *sheet);
typedef enum
{
CLEAR_VALUES = 0x1,
......
......@@ -114,14 +114,16 @@ struct _Workbook {
void *corba_server;
gboolean display_formulas;
WorkbookPrivate *priv;
/* Workbook level preferences */
gboolean autosave;
gboolean autosave_prompt;
gint autosave_minutes;
gint autosave_timer;
gboolean show_horizontal_scrollbar;
gboolean show_vertical_scrollbar;
gboolean show_notebook_tabs;
};
typedef struct {
......
......@@ -842,19 +842,78 @@ cb_cell_rerender (gpointer cell, gpointer data)
cell_queue_redraw (cell);
}
/***********************************************************************/
/* Sheet preferences */
static void
toggle_formulas_cmd (GtkWidget *widget, Workbook *wb)
cb_sheet_pref_display_formulas (GtkWidget *widget, Workbook *wb)
{
wb->display_formulas = !wb->display_formulas;
Sheet *sheet = workbook_get_current_sheet (wb);
sheet->display_formulas = !sheet->display_formulas;
g_list_foreach (wb->formula_cell_list, &cb_cell_rerender, NULL);
}
static void
toggle_grid_lines (GtkWidget *widget, Workbook *wb)
cb_sheet_pref_hide_zeros (GtkWidget *widget, Workbook *wb)
{
Sheet *sheet = workbook_get_current_sheet (wb);
sheet->display_zero = ! sheet->display_zero;
sheet_redraw_all (sheet);
}
static void
cb_sheet_pref_hide_grid_lines (GtkWidget *widget, Workbook *wb)
{
Sheet *sheet = workbook_get_current_sheet (wb);
sheet->show_grid = !sheet->show_grid;
sheet_redraw_all (sheet);
}
static void
cb_sheet_pref_hide_col_header (GtkWidget *widget, Workbook *wb)
{
Sheet *sheet = workbook_get_current_sheet (wb);
sheet->show_col_header = ! sheet->show_col_header;
sheet_adjust_preferences (sheet);
}
static void
cb_sheet_pref_hide_row_header (GtkWidget *widget, Workbook *wb)
{
Sheet *sheet = workbook_get_current_sheet (wb);
sheet->show_row_header = ! sheet->show_row_header;
sheet_adjust_preferences (sheet);
}
/***********************************************************************/
/* Workbook level preferences */
static void
cb_update_sheet_view_prefs (gpointer key, gpointer value, gpointer user_data)
{
Sheet *sheet = value;
sheet_adjust_preferences (sheet);
}
static void
cb_wb_pref_hide_hscroll (GtkWidget *widget, Workbook *wb)
{
wb->show_horizontal_scrollbar = ! wb->show_horizontal_scrollbar;
g_hash_table_foreach (wb->sheets, &cb_update_sheet_view_prefs, NULL);
}
static void
cb_wb_pref_hide_vscroll (GtkWidget *widget, Workbook *wb)
{
wb->show_vertical_scrollbar = ! wb->show_vertical_scrollbar;
g_hash_table_foreach (wb->sheets, &cb_update_sheet_view_prefs, NULL);
}
static void
cb_wb_pref_hide_tabs (GtkWidget *widget, Workbook *wb)
{
gtk_notebook_set_show_tabs (GTK_NOTEBOOK (wb->notebook),
wb->show_notebook_tabs = ! wb->show_notebook_tabs);
}
/***********************************************************************/
static void
format_cells_cmd (GtkWidget *widget, Workbook *wb)
{
......@@ -1079,10 +1138,6 @@ static GnomeUIInfo workbook_menu_edit [] = {
static GnomeUIInfo workbook_menu_view [] = {
{ GNOME_APP_UI_ITEM, N_("_Zoom..."),
N_("Zoom the spreadsheet in or out"), zoom_cmd },
{ GNOME_APP_UI_TOGGLEITEM, N_("Toggle _Formulas"),
N_("Toggle the display of formulas"), toggle_formulas_cmd },
{ GNOME_APP_UI_TOGGLEITEM, N_("Display _Grid lines"),
N_("Toggle the display of formulas"), toggle_grid_lines },
GNOMEUIINFO_END
};
......@@ -1146,6 +1201,28 @@ static GnomeUIInfo workbook_menu_format_row [] = {
static GnomeUIInfo workbook_menu_format_sheet [] = {
{ GNOME_APP_UI_ITEM, N_("_Change name"), NULL,
workbook_cmd_format_sheet_change_name },
{ GNOME_APP_UI_TOGGLEITEM, N_("Display _Formulas"),
NULL, &cb_sheet_pref_display_formulas },
{ GNOME_APP_UI_TOGGLEITEM, N_("Hide _Zeros"),
NULL, &cb_sheet_pref_hide_zeros },
{ GNOME_APP_UI_TOGGLEITEM, N_("Hide _Gridlines"),
NULL, &cb_sheet_pref_hide_grid_lines },
{ GNOME_APP_UI_TOGGLEITEM, N_("Hide _Column Header"),
NULL, &cb_sheet_pref_hide_col_header },
{ GNOME_APP_UI_TOGGLEITEM, N_("Hide _Row Header"),
NULL, &cb_sheet_pref_hide_row_header },
GNOMEUIINFO_END
};
static GnomeUIInfo workbook_menu_format_workbook [] = {
{ GNOME_APP_UI_TOGGLEITEM, N_("Hide _Horizontal Scrollbar"),
NULL, &cb_wb_pref_hide_hscroll },
{ GNOME_APP_UI_TOGGLEITEM, N_("Hide _Vertical Scrollbar"),
NULL, &cb_wb_pref_hide_vscroll },
{ GNOME_APP_UI_TOGGLEITEM, N_("Hide Sheet _Tabs"),
NULL, &cb_wb_pref_hide_tabs },
GNOMEUIINFO_END
};
......@@ -1156,7 +1233,7 @@ static GnomeUIInfo workbook_menu_format [] = {
{ GNOME_APP_UI_SUBTREE, N_("C_olumn"), NULL, workbook_menu_format_column },
{ GNOME_APP_UI_SUBTREE, N_("_Row"), NULL, workbook_menu_format_row },
{ GNOME_APP_UI_SUBTREE, N_("_Sheet"), NULL, workbook_menu_format_sheet },
{ GNOME_APP_UI_SUBTREE, N_("_Workbook"), NULL, workbook_menu_format_workbook },
GNOMEUIINFO_END
};
......@@ -2075,7 +2152,6 @@ workbook_new (void)
wb = gtk_type_new (workbook_get_type ());
wb->toplevel = gnome_app_new ("Gnumeric", "Gnumeric");
wb->table = gtk_table_new (0, 0, 0);
wb->display_formulas = FALSE;
wb->autosave = FALSE;
wb->autosave_prompt = TRUE;
wb->autosave_minutes = 15;
......@@ -2084,6 +2160,10 @@ workbook_new (void)
gtk_timeout_add (wb->autosave_minutes*60000,
(GtkFunction) dialog_autosave_callback, wb);
wb->show_horizontal_scrollbar = TRUE;
wb->show_vertical_scrollbar = TRUE;
wb->show_notebook_tabs = TRUE;
gtk_window_set_policy (GTK_WINDOW (wb->toplevel), 1, 1, 0);
sx = MAX (gdk_screen_width () - 64, 400);
sy = MAX (gdk_screen_height () - 64, 200);
......
......@@ -114,14 +114,16 @@ struct _Workbook {
void *corba_server;
gboolean display_formulas;
WorkbookPrivate *priv;
/* Workbook level preferences */
gboolean autosave;
gboolean autosave_prompt;
gint autosave_minutes;