Commit af5e3da8 authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg

Remove 1/2 of the glaring performance hit associated with redrawing

every time we set the width/height of a col/row.

2000-02-15  Jody Goldberg <jgoldberg@home.com>

	* src/workbook-cmd-format.c (workbook_cmd_format_{column,row}_auto_fit) :
	  Handle repositioning and redrawing here in preparation to adding undo.
	(workbook_cmd_format_column_width) : Ditto.
	(workbook_cmd_format_row_height) : Ditto.

	* src/sheet.c (sheet_reposition_comments_from_{row,col}) : publicize.
	(sheet_recompute_spans_for_col) : Ditto.
	(sheet_save_row_col_sizes) : Store cols/rows of 'default' size as 0.
	(sheet_restore_row_col_sizes) : Restore cols/rows to true default state.
	(sheet_{col,row}_set_size_pts) : document, and REMOVE calls to reposition
	  and redraw.
parent ed503f02
2000-02-15 Jody Goldberg <jgoldberg@home.com>
* src/workbook-cmd-format.c (workbook_cmd_format_{column,row}_auto_fit) :
Handle repositioning and redrawing here in preparation to adding undo.
(workbook_cmd_format_column_width) : Ditto.
(workbook_cmd_format_row_height) : Ditto.
* src/sheet.c (sheet_reposition_comments_from_{row,col}) : publicize.
(sheet_recompute_spans_for_col) : Ditto.
(sheet_save_row_col_sizes) : Store cols/rows of 'default' size as 0.
(sheet_restore_row_col_sizes) : Restore cols/rows to true default state.
(sheet_{col,row}_set_size_pts) : document, and REMOVE calls to reposition
and redraw.
2000-02-16 Jon K Hellan <hellan@acm.org>
* src/sheet.c (col_row_info_init): Fix typo
......
2000-02-15 Jody Goldberg <jgoldberg@home.com>
* src/workbook-cmd-format.c (workbook_cmd_format_{column,row}_auto_fit) :
Handle repositioning and redrawing here in preparation to adding undo.
(workbook_cmd_format_column_width) : Ditto.
(workbook_cmd_format_row_height) : Ditto.
* src/sheet.c (sheet_reposition_comments_from_{row,col}) : publicize.
(sheet_recompute_spans_for_col) : Ditto.
(sheet_save_row_col_sizes) : Store cols/rows of 'default' size as 0.
(sheet_restore_row_col_sizes) : Restore cols/rows to true default state.
(sheet_{col,row}_set_size_pts) : document, and REMOVE calls to reposition
and redraw.
2000-02-16 Jon K Hellan <hellan@acm.org>
* src/sheet.c (col_row_info_init): Fix typo
......
......@@ -1442,58 +1442,6 @@ cmd_hide_selection_rows_cols (CommandContext *context, Sheet *sheet,
/* Register the command object */
return command_push_undo (sheet->workbook, obj, FALSE);
}
/******************************************************************/
#define CMD_PASTE_COPY_TYPE (cmd_paste_copy_get_type ())
#define CMD_PASTE_COPY(o) (GTK_CHECK_CAST ((o), CMD_PASTE_COPY_TYPE, CmdPasteCopy))
typedef struct
{
GnumericCommand parent;
} CmdPasteCopy;
GNUMERIC_MAKE_COMMAND (CmdPasteCopy, cmd_paste_copy);
static gboolean
cmd_paste_copy_undo (GnumericCommand *cmd, CommandContext *context)
{
CmdPasteCopy *me = CMD_PASTE_COPY (cmd);
g_return_val_if_fail (me != NULL, TRUE);
/* FIXME : Fill in */
return FALSE;
}
static gboolean
cmd_paste_copy_redo (GnumericCommand *cmd, CommandContext *context)
{
CmdPasteCopy *me = CMD_PASTE_COPY (cmd);
g_return_val_if_fail (me != NULL, TRUE);
/* FIXME : Fill in */
return FALSE;
}
static void
cmd_paste_copy_destroy (GtkObject *cmd)
{
#if 0
CmdPasteCopy *me = CMD_PASTE_COPY (cmd);
#endif
/* FIXME : Fill in */
gnumeric_command_destroy (cmd);
}
#if 0
gboolean
cmd_paste_copy (CommandContext *context,
{
return FALSE;
}
#endif
/******************************************************************/
#define CMD_PASTE_CUT_TYPE (cmd_paste_cut_get_type ())
......@@ -1607,6 +1555,61 @@ cmd_paste_cut (CommandContext *context, ExprRelocateInfo const * const info)
return command_push_undo (info->target_sheet->workbook, obj, trouble);
}
/******************************************************************/
#define CMD_COLROW_RESIZE_TYPE (cmd_colrow_resize_get_type ())
#define CMD_COLROW_RESIZE(o) (GTK_CHECK_CAST ((o), CMD_COLROW_RESIZE_TYPE, CmdColRowResize))
typedef struct
{
GnumericCommand parent;
GSList *colrows;
int size_pixels;
} CmdColRowResize;
GNUMERIC_MAKE_COMMAND (CmdColRowResize, cmd_colrow_resize);
static gboolean
cmd_colrow_resize_undo (GnumericCommand *cmd, CommandContext *context)
{
CmdColRowResize *me = CMD_COLROW_RESIZE (cmd);
g_return_val_if_fail (me != NULL, TRUE);
/* FIXME : Fill in */
return FALSE;
}
static gboolean
cmd_colrow_resize_redo (GnumericCommand *cmd, CommandContext *context)
{
CmdColRowResize *me = CMD_COLROW_RESIZE (cmd);
g_return_val_if_fail (me != NULL, TRUE);
/* FIXME : Fill in */
return FALSE;
}
static void
cmd_colrow_resize_destroy (GtkObject *cmd)
{
#if 0
CmdColRowResize *me = CMD_COLROW_RESIZE (cmd);
#endif
/* FIXME : Fill in */
gnumeric_command_destroy (cmd);
}
gboolean
cmd_colrow_resize (CommandContext *context,
gboolean is_cols,
GSList *colrows,
int size_pixels)
{
return FALSE;
}
/******************************************************************/
/* TODO : Make a list of commands that should have undo support
* that do not even have stubs
......
......@@ -431,7 +431,7 @@ sheet_compute_visible_ranges (Sheet const *sheet)
}
}
static void
void
sheet_reposition_comments_from_row (Sheet *sheet, int row)
{
GList *l;
......@@ -445,7 +445,7 @@ sheet_reposition_comments_from_row (Sheet *sheet, int row)
}
}
static void
void
sheet_reposition_comments_from_col (Sheet *sheet, int col)
{
GList *l;
......@@ -731,7 +731,7 @@ cb_collect_cells_in_col (Sheet *sheet, ColRowInfo *ri, closure_cells_in_col *dat
* This routine recomputes the column span for the cells that touches
* the column.
*/
static void
void
sheet_recompute_spans_for_col (Sheet *sheet, int col)
{
GList *l;
......@@ -3280,14 +3280,23 @@ sheet_save_row_col_sizes (Sheet *sheet, gboolean const is_cols,
ColRowInfo *info = is_cols
? sheet_col_get_info (sheet, index + i)
: sheet_row_get_info (sheet, index + i);
g_return_val_if_fail (info != NULL, NULL); /* be anal, and leak */
res[i] = info->size_pts;
if (info->hard_size)
res[i] *= -1.;
if (info->pos != -1) {
res[i] = info->size_pts;
if (info->hard_size)
res[i] *= -1.;
} else
res[i] = 0.;
}
return res;
}
/*
* NOTE : this is a low level routine it does not redraw or
* reposition objects
*/
void
sheet_restore_row_col_sizes (Sheet *sheet, gboolean const is_cols,
int index, int count, double *sizes)
......@@ -3300,14 +3309,32 @@ sheet_restore_row_col_sizes (Sheet *sheet, gboolean const is_cols,
for (i = 0 ; i < count ; ++i) {
gboolean hard_size = FALSE;
if (sizes[i] < 0.) {
hard_size = TRUE;
sizes[i] *= -1.;
/* Reset to the default */
if (sizes[i] == 0.) {
ColRowCollection *infos = &(sheet->cols) : &(sheet->rows);
ColRowInfo ***segment =
(ColRowInfo ***)&COLROW_GET_SEGMENT(infos, index+i);
int const sub = COLROW_SUB_INDEX (index+i);
ColRowInfo *cri = NULL;
if (*segment != NULL) {
ci = (*segment)[sub];
if (ci != NULL) {
(*segment)[sub] = NULL;
g_free (ci);
}
}
} else
{
if (sizes[i] < 0.) {
hard_size = TRUE;
sizes[i] *= -1.;
}
if (is_cols)
sheet_col_set_size_pts (sheet, index+i, sizes[i], hard_size);
else
sheet_row_set_size_pts (sheet, index+i, sizes[i], hard_size);
}
if (is_cols)
sheet_col_set_size_pts (sheet, index+i, sizes[i], hard_size);
else
sheet_row_set_size_pts (sheet, index+i, sizes[i], hard_size);
}
g_free (sizes);
......@@ -3416,6 +3443,18 @@ sheet_col_get_distance_pts (Sheet const *sheet, int from, int to)
return units;
}
/**
* sheet_col_set_size_pts:
* @sheet: The sheet
* @col: The col
* @widtht_pts: The desired widtht in pts
* @set_by_user: TRUE if this was done by a user (ie, user manually
* set the width)
*
* Sets width of a col in pts, INCLUDING left and right margins, and the far
* grid line. This is a low level internal routine. It does NOT redraw,
* or reposition objects.
*/
void
sheet_col_set_size_pts (Sheet *sheet, int col, double width_pts,
gboolean set_by_user)
......@@ -3433,11 +3472,6 @@ sheet_col_set_size_pts (Sheet *sheet, int col, double width_pts,
ci->hard_size |= set_by_user;
ci->size_pts = width_pts;
colrow_compute_pixels_from_pts (sheet, ci, (void*)TRUE);
sheet_recompute_spans_for_col (sheet, col);
sheet_compute_visible_ranges (sheet);
sheet_reposition_comments_from_col (sheet, ci->pos);
sheet_redraw_all (sheet);
}
void
......@@ -3550,12 +3584,13 @@ sheet_row_get_distance_pts (Sheet const *sheet, int from, int to)
* sheet_row_set_size_pts:
* @sheet: The sheet
* @row: The row
* @height: The desired height in pts
* @height_pts: The desired height in pts
* @set_by_user: TRUE if this was done by a user (ie, user manually
* set the width)
* set the height)
*
* Sets height of a row in pts, INCLUDING top and bottom margins, and the lower
* grid line.
* grid line. This is a low level internal routine. It does NOT redraw,
* or reposition objects.
*/
void
sheet_row_set_size_pts (Sheet *sheet, int row, double height_pts,
......@@ -3574,10 +3609,6 @@ sheet_row_set_size_pts (Sheet *sheet, int row, double height_pts,
ri->hard_size |= set_by_user;
ri->size_pts = height_pts;
colrow_compute_pixels_from_pts (sheet, ri, (void*)FALSE);
sheet_compute_visible_ranges (sheet);
sheet_reposition_comments_from_row (sheet, ri->pos);
sheet_redraw_all (sheet);
}
/**
......@@ -3590,6 +3621,10 @@ sheet_row_set_size_pts (Sheet *sheet, int row, double height_pts,
*
* Sets height of a row in pixels, INCLUDING top and bottom margins, and the lower
* grid line.
*
* FIXME : This should not be calling redraw or its relatives.
* We should store the fact that objects need moving and take care of
* that in redraw.
*/
void
sheet_row_set_size_pixels (Sheet *sheet, int row, int height_pixels,
......
......@@ -22,13 +22,14 @@ workbook_cmd_format_column_auto_fit (GtkWidget *widget, Workbook *wb)
{
Sheet *sheet = wb->current_sheet;
GList *l;
int col;
int min_col = SHEET_MAX_COLS;
/*
* Apply autofit to any columns where the selection is
*/
for (l = sheet->selections; l; l = l->next){
SheetSelection *ss = l->data;
int col;
for (col = ss->user.start.col; col <= ss->user.end.col; col++){
int ideal_size;
......@@ -37,10 +38,18 @@ workbook_cmd_format_column_auto_fit (GtkWidget *widget, Workbook *wb)
if (ideal_size == 0)
continue;
/* would be better outside loop, but lets
* be careful in case the fit fails
*/
if (col < min_col)
min_col = col;
sheet_col_set_size_pixels (sheet, col, ideal_size, TRUE);
}
}
sheet_set_dirty (sheet, TRUE);
sheet_compute_visible_ranges (sheet);
sheet_reposition_comments_from_col (sheet, min_col);
sheet_redraw_all (sheet);
}
void
......@@ -49,15 +58,16 @@ workbook_cmd_format_column_width (GtkWidget *widget, Workbook *wb)
Sheet *sheet = wb->current_sheet;
GList *l;
double value = 0.0;
int col;
int min_col = SHEET_MAX_COLS;
/*
* Find out the initial value to display
*/
for (l = sheet->selections; l; l = l->next){
SheetSelection *ss = l->data;
int col;
for (col = ss->user.start.col; col <= ss->user.end.col; col++){
for (col = ss->user.start.col; col <= ss->user.end.col; ++col){
ColRowInfo *ci;
ci = sheet_col_get_info (sheet, col);
......@@ -94,38 +104,54 @@ workbook_cmd_format_column_width (GtkWidget *widget, Workbook *wb)
*/
for (l = sheet->selections; l; l = l->next){
SheetSelection *ss = l->data;
int col;
for (col = ss->user.start.col; col <= ss->user.end.col; col++)
int col = ss->user.start.col;
if (col < min_col)
min_col = col;
for (; col <= ss->user.end.col; ++col) {
sheet_col_set_size_pts (sheet, col, value, TRUE);
sheet_recompute_spans_for_col (sheet, col);
}
}
sheet_set_dirty (sheet, TRUE);
sheet_compute_visible_ranges (sheet);
sheet_reposition_comments_from_col (sheet, min_col);
sheet_redraw_all (sheet);
}
void
workbook_cmd_format_row_auto_fit (GtkWidget *widget, Workbook *wb)
{
Sheet *sheet = wb->current_sheet;
GList *l;
int row;
int min_row = SHEET_MAX_ROWS;
GList *l = sheet->selections;
/*
* Apply autofit to any columns where the selection is
*/
for (l = sheet->selections; l; l = l->next){
g_return_if_fail (l != NULL);
/* Apply autofit to any columns contained in selection */
for (; l != NULL; l = l->next){
SheetSelection *ss = l->data;
int row;
for (row = ss->user.start.row; row <= ss->user.end.row; row++){
for (row = ss->user.start.row; row <= ss->user.end.row; ++row) {
int ideal_size;
ideal_size = sheet_row_size_fit_pixels (sheet, row);
if (ideal_size == 0)
continue;
/* would be better outside loop, but lets
* be careful in case the fit fails
*/
if (row < min_row)
min_row = row;
sheet_row_set_size_pixels (sheet, row, ideal_size, FALSE);
}
}
sheet_set_dirty (sheet, TRUE);
sheet_compute_visible_ranges (sheet);
sheet_reposition_comments_from_row (sheet, min_row);
sheet_redraw_all (sheet);
}
void
......@@ -134,7 +160,8 @@ workbook_cmd_format_row_height (GtkWidget *widget, Workbook *wb)
Sheet *sheet = wb->current_sheet;
GList *l;
double value = 0.0;
int min_row = SHEET_MAX_ROWS;
/*
* Find out the initial value to display
*/
......@@ -178,12 +205,18 @@ workbook_cmd_format_row_height (GtkWidget *widget, Workbook *wb)
*/
for (l = sheet->selections; l; l = l->next){
SheetSelection *ss = l->data;
int row;
int row = ss->user.start.row;
for (row = ss->user.start.row; row <= ss->user.end.row; row++)
if (row < min_row)
min_row = row;
for (;row <= ss->user.end.row; ++row)
sheet_row_set_size_pts (sheet, row, value, TRUE);
}
sheet_set_dirty (sheet, TRUE);
sheet_compute_visible_ranges (sheet);
sheet_reposition_comments_from_row (sheet, min_row);
sheet_redraw_all (sheet);
}
void
......
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