From: John Darrington Date: Thu, 20 Nov 2008 01:49:23 +0000 (+0900) Subject: Improve the behaviour of the moveto function X-Git-Tag: v0.7.1~138 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a698937f8a70b90dda232f9dc9b5c6664c4a4a2d;p=pspp-builds.git Improve the behaviour of the moveto function --- diff --git a/lib/gtksheet/gtksheet.c b/lib/gtksheet/gtksheet.c index 3a965aec..3f2fe5a4 100644 --- a/lib/gtksheet/gtksheet.c +++ b/lib/gtksheet/gtksheet.c @@ -1506,105 +1506,50 @@ gtk_sheet_hide_row_titles (GtkSheet *sheet) } +/* Scroll the sheet so that the cell ROW, COLUMN is visible. + If {ROW,COL}_ALIGN is zero, then the cell will be placed + at the {top,left} of the sheet. If it's 1, then it'll + be placed at the {bottom,right}. + ROW or COL may be -1, in which case scrolling in that dimension + does not occur. + */ void gtk_sheet_moveto (GtkSheet *sheet, gint row, - gint column, + gint col, gfloat row_align, gfloat col_align) { - gint x, y; gint width, height; - gint adjust; - gint min_row, min_col; - - g_return_if_fail (sheet != NULL); - g_return_if_fail (GTK_IS_SHEET (sheet)); - g_return_if_fail (sheet->hadjustment != NULL); - g_return_if_fail (sheet->vadjustment != NULL); - - if (row < 0 || row >= g_sheet_row_get_row_count (sheet->row_geometry)) - return; - if (column < 0 || column >= g_sheet_column_get_column_count (sheet->column_geometry)) - return; - - gdk_drawable_get_size (sheet->sheet_window, &width, &height); - - /* adjust vertical scrollbar */ - if (row >= 0 && row_align >= 0.0) - { - y = g_sheet_row_start_pixel (sheet->row_geometry, row) - - (gint) ( row_align * height + (1.0 - row_align) - * g_sheet_row_get_height (sheet->row_geometry, row)); - - /* This forces the sheet to scroll when you don't see the entire cell */ - min_row = row; - adjust = 0; - if (row_align >= 1.0) - { - while (min_row >= 0 && min_row > min_visible_row (sheet)) - { - adjust += g_sheet_row_get_height (sheet->row_geometry, min_row); - - if (adjust >= height) - { - break; - } - min_row--; - } - min_row = MAX (min_row, 0); - min_row ++; + g_return_if_fail (row_align >= 0); + g_return_if_fail (col_align >= 0); - y = g_sheet_row_start_pixel (sheet->row_geometry, min_row) + - g_sheet_row_get_height (sheet->row_geometry, min_row) - 1; - } + g_return_if_fail (row_align <= 1); + g_return_if_fail (col_align <= 1); - if (y < 0) - sheet->vadjustment->value = 0.0; - else - sheet->vadjustment->value = y; + g_return_if_fail (col < + g_sheet_column_get_column_count (sheet->column_geometry)); + g_return_if_fail (row < + g_sheet_row_get_row_count (sheet->row_geometry)); - g_signal_emit_by_name (sheet->vadjustment, - "value_changed"); + gdk_drawable_get_size (sheet->sheet_window, &width, &height); - } - /* adjust horizontal scrollbar */ - if (column >= 0 && col_align >= 0.0) - { - x = g_sheet_column_start_pixel (sheet->column_geometry, column) - - (gint) ( col_align*width + (1.0 - col_align)* - g_sheet_column_get_width (sheet->column_geometry, column)); + if (row >= 0) + { + gint y = g_sheet_row_start_pixel (sheet->row_geometry, row); - /* This forces the sheet to scroll when you don't see the entire cell */ - min_col = column; - adjust = 0; - if (col_align == 1.0) - { - while (min_col >= 0 && min_col > min_visible_column (sheet)) - { - adjust += g_sheet_column_get_width (sheet->column_geometry, min_col); + gtk_adjustment_set_value (sheet->vadjustment, y - height * row_align); + } - if (adjust >= width) - { - break; - } - min_col--; - } - min_col = MAX (min_col, 0); - x = g_sheet_column_start_pixel (sheet->column_geometry, min_col) + - g_sheet_column_get_width (sheet->column_geometry, min_col) - 1; - } - if (x < 0) - sheet->hadjustment->value = 0.0; - else - sheet->hadjustment->value = x; + if (col >= 0) + { + gint x = g_sheet_column_start_pixel (sheet->column_geometry, col); - g_signal_emit_by_name (sheet->hadjustment, - "value_changed"); - } + gtk_adjustment_set_value (sheet->hadjustment, x - width * col_align); + } } diff --git a/src/ui/gui/psppire-data-editor.c b/src/ui/gui/psppire-data-editor.c index 7d2374e0..82a835be 100644 --- a/src/ui/gui/psppire-data-editor.c +++ b/src/ui/gui/psppire-data-editor.c @@ -157,7 +157,7 @@ on_var_row_clicked (PsppireDataEditor *de, gint row, gpointer data) if ( row < visible_range.col0 || row > visible_range.coli) { gtk_sheet_moveto (GTK_SHEET (de->data_sheet[0]), - current_row, row, 0, 0); + -1, row, 0, 0); } return FALSE; @@ -240,12 +240,12 @@ psppire_data_editor_set_property (GObject *object, case PSPPIRE_DATA_EDITOR_DATA_VIEW: gtk_sheet_get_active_cell (GTK_SHEET (de->data_sheet[0]), &row, &col); gtk_sheet_set_active_cell (GTK_SHEET (de->data_sheet[0]), row, var); - gtk_sheet_moveto (GTK_SHEET (de->data_sheet[0]), row, var, 0.5, 0.5); + gtk_sheet_moveto (GTK_SHEET (de->data_sheet[0]), -1, var, 0.5, 0.5); break; case PSPPIRE_DATA_EDITOR_VARIABLE_VIEW: gtk_sheet_get_active_cell (GTK_SHEET (de->var_sheet), &row, &col); gtk_sheet_set_active_cell (GTK_SHEET (de->var_sheet), var, col); - gtk_sheet_moveto (GTK_SHEET (de->var_sheet), var, col, 0.5, 0.5); + gtk_sheet_moveto (GTK_SHEET (de->var_sheet), var, -1, 0.5, 0.5); break; default: g_assert_not_reached (); @@ -259,7 +259,7 @@ psppire_data_editor_set_property (GObject *object, gint case_num = g_value_get_long (value); gtk_sheet_get_active_cell (GTK_SHEET (de->data_sheet[0]), &row, &col); gtk_sheet_set_active_cell (GTK_SHEET (de->data_sheet[0]), case_num, col); - gtk_sheet_moveto (GTK_SHEET (de->data_sheet[0]), case_num, col, 0.5, 0.5); + gtk_sheet_moveto (GTK_SHEET (de->data_sheet[0]), case_num, -1, 0.5, 0.5); } break; case PROP_VALUE_LABELS: