Fixed crash when scrolling
[pspp-builds.git] / lib / gtksheet / gtksheet.c
index 28279076faa32872ed8e88c390b84a91107d5338..b908693e0ad949f83416c3fa0750e36286753ee3 100644 (file)
@@ -2572,6 +2572,12 @@ change_active_cell (GtkSheet *sheet, gint row, gint col)
     r.row0 = old_row - 1;
     r.rowi = old_row + 1;
 
+    maximize_int (&r.row0, 0);
+    maximize_int (&r.col0, 0);
+    minimize_int (&r.rowi, psppire_axis_unit_count (sheet->vaxis) - 1);
+    minimize_int (&r.coli, psppire_axis_unit_count (sheet->haxis) - 1);
+
+
     if (  gtk_sheet_range_isvisible (sheet, &r))
       gtk_sheet_range_draw (sheet, &r);
   }
@@ -4725,7 +4731,7 @@ draw_button (GtkSheet *sheet, GdkWindow *window,
 static void
 draw_column_title_buttons_range (GtkSheet *sheet, gint first, gint last)
 {
-  GdkRegion *region;
+  GdkRectangle rect;
   gint col;
   if (!GTK_WIDGET_REALIZED (GTK_WIDGET (sheet))) return;
 
@@ -4734,10 +4740,18 @@ draw_column_title_buttons_range (GtkSheet *sheet, gint first, gint last)
   g_return_if_fail (first >= min_visible_column (sheet));
   g_return_if_fail (last <= max_visible_column (sheet));
 
-  region =
-    gdk_drawable_get_visible_region (GDK_DRAWABLE (sheet->column_title_window));
+  rect.y = 0;
+  rect.height = sheet->column_title_area.height;
+  rect.x = psppire_axis_pixel_start (sheet->haxis, first) + CELL_SPACING;
+  rect.width = psppire_axis_pixel_start (sheet->haxis, last) + CELL_SPACING
+    + psppire_axis_unit_size (sheet->haxis, last);
+
+  rect.x -= sheet->hadjustment->value;
 
-  gdk_window_begin_paint_region (sheet->column_title_window, region);
+  minimize_int (&rect.width, sheet->column_title_area.width);
+  maximize_int (&rect.x, 0);
+
+  gdk_window_begin_paint_rect (sheet->column_title_window, &rect);
 
   for (col = first ; col <= last ; ++col)
     {
@@ -4766,7 +4780,7 @@ draw_column_title_buttons_range (GtkSheet *sheet, gint first, gint last)
 static void
 draw_row_title_buttons_range (GtkSheet *sheet, gint first, gint last)
 {
-  GdkRegion *region;
+  GdkRectangle rect;
   gint row;
   if (!GTK_WIDGET_REALIZED (GTK_WIDGET (sheet))) return;
 
@@ -4775,13 +4789,18 @@ draw_row_title_buttons_range (GtkSheet *sheet, gint first, gint last)
   g_return_if_fail (first >= min_visible_row (sheet));
   g_return_if_fail (last <= max_visible_row (sheet));
 
+  rect.x = 0;
+  rect.width = sheet->row_title_area.width;
+  rect.y = psppire_axis_pixel_start (sheet->vaxis, first) + CELL_SPACING;
+  rect.height = psppire_axis_pixel_start (sheet->vaxis, last) + CELL_SPACING
+    + psppire_axis_unit_size (sheet->vaxis, last);
 
-  region =
-    gdk_drawable_get_visible_region (GDK_DRAWABLE (sheet->row_title_window));
-
-  gdk_window_begin_paint_region (sheet->row_title_window, region);
+  rect.y -= sheet->vadjustment->value;
 
+  minimize_int (&rect.height, sheet->row_title_area.height);
+  maximize_int (&rect.y, 0);
 
+  gdk_window_begin_paint_rect (sheet->row_title_window, &rect);
   for (row = first; row <= last; ++row)
     {
       GdkRectangle allocation;