Disable extend_selection call.
[pspp-builds.git] / lib / gtk-contrib / psppire-sheet.c
index ad1cf78a7fd973d1af993e32696e59813b5f69f3..be4cd24323e4a33946a914908dd510326e574607 100644 (file)
@@ -1,5 +1,5 @@
 /*
-   Copyright (C) 2006, 2008 Free Software Foundation
+   Copyright (C) 2006, 2008, 2009 Free Software Foundation
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -69,7 +69,9 @@
 #include "psppire-sheet.h"
 #include <ui/gui/psppire-marshal.h>
 #include <ui/gui/sheet/psppire-sheetmodel.h>
+#include <ui/gui/sheet/psppire-axis.h>
 #include <libpspp/misc.h>
+
 #include <math.h>
 
 /* sheet flags */
@@ -373,10 +375,10 @@ POSSIBLE_RESIZE (const PsppireSheet *sheet, gint x, gint y,
   ydrag = psppire_axis_start_pixel (sheet->vaxis, sheet->range.rowi) +
     psppire_axis_unit_size (sheet->vaxis, sheet->range.rowi);
 
-  if (sheet->state == PSPPIRE_SHEET_COLUMN_SELECTED)
+  if (sheet->select_status == PSPPIRE_SHEET_COLUMN_SELECTED)
     ydrag = psppire_axis_start_pixel (sheet->vaxis, min_visible_row (sheet));
 
-  if (sheet->state == PSPPIRE_SHEET_ROW_SELECTED)
+  if (sheet->select_status == PSPPIRE_SHEET_ROW_SELECTED)
     xdrag = psppire_axis_start_pixel (sheet->haxis, min_visible_column (sheet));
 
   *drag_column = column_from_xpixel (sheet, x);
@@ -697,6 +699,7 @@ enum
     PROP_0,
     PROP_VAXIS,
     PROP_HAXIS,
+    PROP_CELL_PADDING,
     PROP_MODEL
   };
 
@@ -756,6 +759,7 @@ psppire_sheet_set_vertical_axis (PsppireSheet *sheet, PsppireAxis *a)
     g_object_ref (sheet->vaxis);
 }
 
+static const GtkBorder default_cell_padding = {3, 3, 3, 3};
 
 static void
 psppire_sheet_set_property (GObject         *object,
@@ -768,11 +772,37 @@ psppire_sheet_set_property (GObject         *object,
 
   switch (prop_id)
     {
+    case PROP_CELL_PADDING:
+      if ( sheet->cell_padding)
+       g_boxed_free (GTK_TYPE_BORDER, sheet->cell_padding);
+
+      sheet->cell_padding = g_value_dup_boxed (value);
+
+     if (NULL == sheet->cell_padding)
+       sheet->cell_padding = g_boxed_copy (GTK_TYPE_BORDER,
+                                          &default_cell_padding);
+
+     if (sheet->vaxis)
+       g_object_set (sheet->vaxis, "padding",
+                    sheet->cell_padding->top + sheet->cell_padding->bottom,
+                    NULL);
+
+     if (sheet->haxis)
+       g_object_set (sheet->haxis, "padding",
+                    sheet->cell_padding->left + sheet->cell_padding->right,
+                    NULL);
+      break;
     case PROP_VAXIS:
       psppire_sheet_set_vertical_axis (sheet, g_value_get_pointer (value));
+      g_object_set (sheet->vaxis, "padding",
+                   sheet->cell_padding->top + sheet->cell_padding->bottom,
+                   NULL);
       break;
     case PROP_HAXIS:
       psppire_sheet_set_horizontal_axis (sheet, g_value_get_pointer (value));
+      g_object_set (sheet->haxis, "padding",
+                   sheet->cell_padding->left + sheet->cell_padding->right,
+                   NULL);
       break;
     case PROP_MODEL:
       psppire_sheet_set_model (sheet, g_value_get_pointer (value));
@@ -793,6 +823,9 @@ psppire_sheet_get_property (GObject         *object,
 
   switch (prop_id)
     {
+    case PROP_CELL_PADDING:
+      g_value_set_boxed (value, sheet->cell_padding);
+      break;
     case PROP_VAXIS:
       g_value_set_pointer (value, sheet->vaxis);
       break;
@@ -817,6 +850,7 @@ psppire_sheet_class_init (PsppireSheetClass *klass)
   GParamSpec *haxis_spec ;
   GParamSpec *vaxis_spec ;
   GParamSpec *model_spec ;
+  GParamSpec *cell_padding_spec ;
 
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
   GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
@@ -1018,6 +1052,12 @@ psppire_sheet_class_init (PsppireSheetClass *klass)
   object_class->dispose = psppire_sheet_dispose;
   object_class->finalize = psppire_sheet_finalize;
 
+  cell_padding_spec =
+    g_param_spec_boxed ("cell-padding",
+                       "Cell Padding",
+                       "The space between a cell's contents and its border",
+                       GTK_TYPE_BORDER,
+                       G_PARAM_CONSTRUCT | G_PARAM_READABLE | G_PARAM_WRITABLE);
 
   vaxis_spec =
     g_param_spec_pointer ("vertical-axis",
@@ -1049,6 +1089,10 @@ psppire_sheet_class_init (PsppireSheetClass *klass)
                                    PROP_HAXIS,
                                    haxis_spec);
 
+  g_object_class_install_property (object_class,
+                                   PROP_CELL_PADDING,
+                                   cell_padding_spec);
+
   g_object_class_install_property (object_class,
                                    PROP_MODEL,
                                    model_spec);
@@ -1091,7 +1135,7 @@ psppire_sheet_init (PsppireSheet *sheet)
 
   sheet->flags = 0;
   sheet->selection_mode = GTK_SELECTION_NONE;
-  sheet->state = PSPPIRE_SHEET_NORMAL;
+  sheet->select_status = PSPPIRE_SHEET_NORMAL;
 
   GTK_WIDGET_UNSET_FLAGS (sheet, GTK_NO_WINDOW);
   GTK_WIDGET_SET_FLAGS (sheet, GTK_CAN_FOCUS);
@@ -1119,8 +1163,6 @@ psppire_sheet_init (PsppireSheet *sheet)
   sheet->range.col0 = 0;
   sheet->range.coli = 0;
 
-  sheet->state = PSPPIRE_SHEET_NORMAL;
-
   sheet->sheet_window = NULL;
   sheet->entry_widget = NULL;
   sheet->button = NULL;
@@ -1370,9 +1412,9 @@ psppire_sheet_change_entry (PsppireSheet *sheet, GtkType entry_type)
   g_return_if_fail (sheet != NULL);
   g_return_if_fail (PSPPIRE_IS_SHEET (sheet));
 
-  state = sheet->state;
+  state = sheet->select_status;
 
-  if (sheet->state == PSPPIRE_SHEET_NORMAL)
+  if (sheet->select_status == PSPPIRE_SHEET_NORMAL)
     psppire_sheet_hide_entry_widget (sheet);
 
   sheet->entry_type = entry_type;
@@ -1583,15 +1625,14 @@ psppire_sheet_select_row (PsppireSheet *sheet, gint row)
   if (row < 0 || row >= psppire_axis_unit_count (sheet->vaxis))
     return;
 
-  if (sheet->state != PSPPIRE_SHEET_NORMAL)
+  if (sheet->select_status != PSPPIRE_SHEET_NORMAL)
     psppire_sheet_real_unselect_range (sheet, NULL);
 
-  sheet->state = PSPPIRE_SHEET_ROW_SELECTED;
+  sheet->select_status = PSPPIRE_SHEET_ROW_SELECTED;
   sheet->range.row0 = row;
   sheet->range.col0 = 0;
   sheet->range.rowi = row;
   sheet->range.coli = psppire_axis_unit_count (sheet->haxis) - 1;
-  sheet->active_cell.row = row;
 
   g_signal_emit (sheet, sheet_signals[SELECT_ROW], 0, row);
   psppire_sheet_real_select_range (sheet, NULL);
@@ -1607,15 +1648,14 @@ psppire_sheet_select_column (PsppireSheet *sheet, gint column)
   if (column < 0 || column >= psppire_axis_unit_count (sheet->haxis))
     return;
 
-  if (sheet->state != PSPPIRE_SHEET_NORMAL)
+  if (sheet->select_status != PSPPIRE_SHEET_NORMAL)
     psppire_sheet_real_unselect_range (sheet, NULL);
 
-  sheet->state = PSPPIRE_SHEET_COLUMN_SELECTED;
+  sheet->select_status = PSPPIRE_SHEET_COLUMN_SELECTED;
   sheet->range.row0 = 0;
   sheet->range.col0 = column;
   sheet->range.rowi = psppire_axis_unit_count (sheet->vaxis) - 1;
   sheet->range.coli = column;
-  sheet->active_cell.col = column;
 
   g_signal_emit (sheet, sheet_signals[SELECT_COLUMN], 0, column);
   psppire_sheet_real_select_range (sheet, NULL);
@@ -1752,6 +1792,9 @@ psppire_sheet_dispose  (GObject *object)
 
   sheet->dispose_has_run = TRUE;
 
+  if ( sheet->cell_padding)
+    g_boxed_free (GTK_TYPE_BORDER, sheet->cell_padding);
+
   if (sheet->model) g_object_unref (sheet->model);
   if (sheet->vaxis) g_object_unref (sheet->vaxis);
   if (sheet->haxis) g_object_unref (sheet->haxis);
@@ -1809,7 +1852,6 @@ psppire_sheet_style_set (GtkWidget *widget,
   set_entry_widget_font (sheet);
 }
 
-#define BORDER_WIDTH 3
 
 static void
 psppire_sheet_realize (GtkWidget *widget)
@@ -1917,7 +1959,10 @@ psppire_sheet_realize (GtkWidget *widget)
   values.foreground = widget->style->white;
   values.function = GDK_INVERT;
   values.subwindow_mode = GDK_INCLUDE_INFERIORS;
-  values.line_width = BORDER_WIDTH;
+  values.line_width = MAX (sheet->cell_padding->left,
+                          MAX (sheet->cell_padding->right,
+                               MAX (sheet->cell_padding->top,
+                                    sheet->cell_padding->bottom)));
 
   sheet->xor_gc = gdk_gc_new_with_values (widget->window,
                                          &values,
@@ -1927,13 +1972,15 @@ psppire_sheet_realize (GtkWidget *widget)
                                          GDK_GC_LINE_WIDTH
                                          );
 
-
   gtk_widget_set_parent_window (sheet->entry_widget, sheet->sheet_window);
   gtk_widget_set_parent (sheet->entry_widget, GTK_WIDGET (sheet));
 
   gtk_widget_set_parent_window (sheet->button, sheet->sheet_window);
   gtk_widget_set_parent (sheet->button, GTK_WIDGET (sheet));
 
+  sheet->button->style = gtk_style_attach (sheet->button->style,
+                                          sheet->sheet_window);
+
 
   sheet->cursor_drag = gdk_cursor_new_for_display (display, GDK_PLUS);
 
@@ -2091,11 +2138,9 @@ psppire_sheet_unmap (GtkWidget *widget)
     gdk_window_hide (sheet->row_title_window);
   gdk_window_hide (widget->window);
 
-  if (GTK_WIDGET_MAPPED (sheet->entry_widget))
-    gtk_widget_unmap (sheet->entry_widget);
-
-  if (GTK_WIDGET_MAPPED (sheet->button))
-    gtk_widget_unmap (sheet->button);
+  gtk_widget_unmap (sheet->entry_widget);
+  gtk_widget_unmap (sheet->button);
+  gtk_widget_unmap (sheet->hover_window->window);
 }
 
 /* get cell attributes of the given cell */
@@ -2173,6 +2218,19 @@ psppire_sheet_cell_draw (PsppireSheet *sheet, gint row, gint col)
   if ( !pango_font_description_get_size_is_absolute (font_desc))
     font_height /= PANGO_SCALE;
 
+
+  if ( sheet->cell_padding )
+    {
+      area.x += sheet->cell_padding->left;
+      area.width -= sheet->cell_padding->right
+       + sheet->cell_padding->left;
+
+      area.y += sheet->cell_padding->top;
+      area.height -= sheet->cell_padding->bottom
+       +
+       sheet->cell_padding->top;
+    }
+
   /* Centre the text vertically */
   area.y += (area.height - font_height) / 2.0;
 
@@ -2255,12 +2313,12 @@ draw_sheet_region (PsppireSheet *sheet, GdkRegion *region)
        psppire_sheet_cell_draw (sheet, i, j);
     }
 
-  if (sheet->state != PSPPIRE_SHEET_NORMAL &&
+  if (sheet->select_status != PSPPIRE_SHEET_NORMAL &&
       psppire_sheet_range_isvisible (sheet, &sheet->range))
     psppire_sheet_range_draw_selection (sheet, drawing_range);
 
 
-  if (sheet->state == GTK_STATE_NORMAL &&
+  if (sheet->select_status == GTK_STATE_NORMAL &&
       sheet->active_cell.row >= drawing_range.row0 &&
       sheet->active_cell.row <= drawing_range.rowi &&
       sheet->active_cell.col >= drawing_range.col0 &&
@@ -2442,7 +2500,7 @@ psppire_sheet_cell_get_state (PsppireSheet *sheet, gint row, gint col)
   if (col >= psppire_axis_unit_count (sheet->haxis) || row >= psppire_axis_unit_count (sheet->vaxis)) return 0;
   if (col < 0 || row < 0) return 0;
 
-  state = sheet->state;
+  state = sheet->select_status;
   range = &sheet->range;
 
   switch (state)
@@ -2600,7 +2658,7 @@ entry_load_text (PsppireSheet *sheet)
   PsppireSheetCellAttr attributes;
 
   if (!GTK_WIDGET_VISIBLE (sheet->entry_widget)) return;
-  if (sheet->state != GTK_STATE_NORMAL) return;
+  if (sheet->select_status != GTK_STATE_NORMAL) return;
 
   row = sheet->active_cell.row;
   col = sheet->active_cell.col;
@@ -2647,20 +2705,20 @@ change_active_cell (PsppireSheet *sheet, gint row, gint col)
        || col > psppire_axis_unit_count (sheet->haxis))
     return;
 
-  if (sheet->state != PSPPIRE_SHEET_NORMAL)
+  if (sheet->select_status != PSPPIRE_SHEET_NORMAL)
     {
-      sheet->state = PSPPIRE_SHEET_NORMAL;
+      sheet->select_status = PSPPIRE_SHEET_NORMAL;
       psppire_sheet_real_unselect_range (sheet, NULL);
     }
 
   old_row = sheet->active_cell.row;
   old_col = sheet->active_cell.col;
 
-  /* Erase the old cell */
-  psppire_sheet_draw_active_cell (sheet);
-
   entry_load_text (sheet);
 
+  /* Erase the old cell border */
+  psppire_sheet_draw_active_cell (sheet);
+
   sheet->range.row0 = row;
   sheet->range.col0 = col;
   sheet->range.rowi = row;
@@ -2702,7 +2760,7 @@ psppire_sheet_show_entry_widget (PsppireSheet *sheet)
     return;
 
   if (!GTK_WIDGET_REALIZED (GTK_WIDGET (sheet))) return;
-  if (sheet->state != PSPPIRE_SHEET_NORMAL) return;
+  if (sheet->select_status != PSPPIRE_SHEET_NORMAL) return;
   if (PSPPIRE_SHEET_IN_SELECTION (sheet)) return;
 
   GTK_WIDGET_SET_FLAGS (GTK_WIDGET (sheet->entry_widget), GTK_VISIBLE);
@@ -3024,11 +3082,24 @@ psppire_sheet_draw_border (PsppireSheet *sheet, PsppireSheetRange new_range)
 
   rectangle_from_range (sheet, &new_range, &area);
 
-  gdk_draw_rectangle (sheet->sheet_window,
-                     sheet->xor_gc,
+  area.width ++;
+  area.height ++;
+
+  gdk_gc_set_clip_rectangle (sheet->xor_gc, &area);
+
+  area.x += sheet->cell_padding->left / 2;
+  area.y += sheet->cell_padding->top / 2;
+  area.width -= (sheet->cell_padding->left + sheet->cell_padding->right ) / 2;
+  area.height -= (sheet->cell_padding->top + sheet->cell_padding->bottom ) / 2;
+
+  gdk_draw_rectangle (sheet->sheet_window,  sheet->xor_gc,
                      FALSE,
-                     area.x, area.y,
-                     area.width, area.height);
+                     area.x,
+                     area.y,
+                     area.width,
+                     area.height);
+
+  gdk_gc_set_clip_rectangle (sheet->xor_gc, NULL);
 }
 
 
@@ -3047,7 +3118,7 @@ psppire_sheet_real_select_range (PsppireSheet *sheet,
   if (range->row0 < 0 || range->rowi < 0) return;
   if (range->col0 < 0 || range->coli < 0) return;
 
-  state = sheet->state;
+  state = sheet->select_status;
 
 #if 0
   if (range->coli != sheet->range.coli || range->col0 != sheet->range.col0 ||
@@ -3086,19 +3157,17 @@ psppire_sheet_select_range (PsppireSheet *sheet, const PsppireSheetRange *range)
   if (range->col0 < 0 || range->coli < 0) return;
 
 
-  if (sheet->state != PSPPIRE_SHEET_NORMAL)
+  if (sheet->select_status != PSPPIRE_SHEET_NORMAL)
     psppire_sheet_real_unselect_range (sheet, NULL);
 
   sheet->range.row0 = range->row0;
   sheet->range.rowi = range->rowi;
   sheet->range.col0 = range->col0;
   sheet->range.coli = range->coli;
-  sheet->active_cell.row = range->row0;
-  sheet->active_cell.col = range->col0;
   sheet->selection_cell.row = range->rowi;
   sheet->selection_cell.col = range->coli;
 
-  sheet->state = PSPPIRE_SHEET_RANGE_SELECTED;
+  sheet->select_status = PSPPIRE_SHEET_RANGE_SELECTED;
   psppire_sheet_real_select_range (sheet, NULL);
 }
 
@@ -3109,10 +3178,7 @@ psppire_sheet_unselect_range (PsppireSheet *sheet)
     return;
 
   psppire_sheet_real_unselect_range (sheet, NULL);
-  sheet->state = GTK_STATE_NORMAL;
-
-  change_active_cell (sheet,
-                sheet->active_cell.row, sheet->active_cell.col);
+  sheet->select_status = GTK_STATE_NORMAL;
 }
 
 
@@ -3172,7 +3238,7 @@ psppire_sheet_expose (GtkWidget *widget,
       draw_sheet_region (sheet, event->region);
 
 #if 0
-      if (sheet->state != PSPPIRE_SHEET_NORMAL)
+      if (sheet->select_status != PSPPIRE_SHEET_NORMAL)
        {
          if (psppire_sheet_range_isvisible (sheet, &sheet->range))
            psppire_sheet_range_draw (sheet, &sheet->range);
@@ -3219,7 +3285,7 @@ psppire_sheet_button_press (GtkWidget *widget,
   GdkModifierType mods;
   gint x, y;
   gint  row, column;
-  gboolean veto;
+
 
   g_return_val_if_fail (widget != NULL, FALSE);
   g_return_val_if_fail (PSPPIRE_IS_SHEET (widget), FALSE);
@@ -3323,65 +3389,8 @@ psppire_sheet_button_press (GtkWidget *widget,
                        NULL, NULL, event->time);
       gtk_grab_add (GTK_WIDGET (sheet));
 
-      if (sheet->selection_mode != GTK_SELECTION_SINGLE &&
-         sheet->selection_mode != GTK_SELECTION_NONE &&
-         sheet->cursor_drag->type == GDK_SIZING &&
-         !PSPPIRE_SHEET_IN_SELECTION (sheet) && !PSPPIRE_SHEET_IN_RESIZE (sheet))
-       {
-         if (sheet->state == GTK_STATE_NORMAL)
-           {
-             row = sheet->active_cell.row;
-             column = sheet->active_cell.col;
-             sheet->active_cell.row = row;
-             sheet->active_cell.col = column;
-             sheet->drag_range = sheet->range;
-             sheet->state = PSPPIRE_SHEET_RANGE_SELECTED;
-             psppire_sheet_select_range (sheet, &sheet->drag_range);
-           }
-         sheet->x_drag = x;
-         sheet->y_drag = y;
-         if (row > sheet->range.rowi) row--;
-         if (column > sheet->range.coli) column--;
-         sheet->drag_cell.row = row;
-         sheet->drag_cell.col = column;
-         sheet->drag_range = sheet->range;
-         draw_xor_rectangle (sheet, sheet->drag_range);
-         PSPPIRE_SHEET_SET_FLAGS (sheet, PSPPIRE_SHEET_IN_RESIZE);
-       }
-      else if (sheet->cursor_drag->type == GDK_TOP_LEFT_ARROW &&
-              !PSPPIRE_SHEET_IN_SELECTION (sheet)
-              && ! PSPPIRE_SHEET_IN_DRAG (sheet)
-              && sheet->active_cell.row >= 0
-              && sheet->active_cell.col >= 0
-              )
-       {
-         if (sheet->state == GTK_STATE_NORMAL)
-           {
-             row = sheet->active_cell.row;
-             column = sheet->active_cell.col;
-             sheet->active_cell.row = row;
-             sheet->active_cell.col = column;
-             sheet->drag_range = sheet->range;
-             sheet->state = PSPPIRE_SHEET_RANGE_SELECTED;
-             psppire_sheet_select_range (sheet, &sheet->drag_range);
-           }
-         sheet->x_drag = x;
-         sheet->y_drag = y;
-         if (row < sheet->range.row0) row++;
-         if (row > sheet->range.rowi) row--;
-         if (column < sheet->range.col0) column++;
-         if (column > sheet->range.coli) column--;
-         sheet->drag_cell.row = row;
-         sheet->drag_cell.col = column;
-         sheet->drag_range = sheet->range;
-         draw_xor_rectangle (sheet, sheet->drag_range);
-         PSPPIRE_SHEET_SET_FLAGS (sheet, PSPPIRE_SHEET_IN_DRAG);
-       }
-      else
-       {
-         veto = psppire_sheet_click_cell (sheet, row, column);
-         if (veto) PSPPIRE_SHEET_SET_FLAGS (sheet, PSPPIRE_SHEET_IN_SELECTION);
-       }
+      if (psppire_sheet_click_cell (sheet, row, column))
+       PSPPIRE_SHEET_SET_FLAGS (sheet, PSPPIRE_SHEET_IN_SELECTION);
     }
 
   if (event->window == sheet->column_title_window)
@@ -3396,7 +3405,6 @@ psppire_sheet_button_press (GtkWidget *widget,
 
       if (psppire_sheet_model_get_column_sensitivity (sheet->model, column))
        {
-         veto = psppire_sheet_click_cell (sheet, -1, column);
          gtk_grab_add (GTK_WIDGET (sheet));
          PSPPIRE_SHEET_SET_FLAGS (sheet, PSPPIRE_SHEET_IN_SELECTION);
        }
@@ -3413,7 +3421,6 @@ psppire_sheet_button_press (GtkWidget *widget,
       row = row_from_ypixel (sheet, y);
       if (psppire_sheet_model_get_row_sensitivity (sheet->model, row))
        {
-         veto = psppire_sheet_click_cell (sheet, row, -1);
          gtk_grab_add (GTK_WIDGET (sheet));
          PSPPIRE_SHEET_SET_FLAGS (sheet, PSPPIRE_SHEET_IN_SELECTION);
        }
@@ -3444,7 +3451,7 @@ psppire_sheet_click_cell (PsppireSheet *sheet, gint row, gint column)
 
   if (forbid_move)
     {
-      if (sheet->state == GTK_STATE_NORMAL)
+      if (sheet->select_status == GTK_STATE_NORMAL)
        return FALSE;
 
       row = sheet->active_cell.row;
@@ -3473,15 +3480,13 @@ psppire_sheet_click_cell (PsppireSheet *sheet, gint row, gint column)
       sheet->range.rowi = psppire_axis_unit_count (sheet->vaxis) - 1;
       sheet->range.coli =
        psppire_axis_unit_count (sheet->haxis) - 1;
-      sheet->active_cell.row = 0;
-      sheet->active_cell.col = 0;
       psppire_sheet_select_range (sheet, NULL);
       return TRUE;
     }
 
-  if (sheet->state != PSPPIRE_SHEET_NORMAL)
+  if (sheet->select_status != PSPPIRE_SHEET_NORMAL)
     {
-      sheet->state = PSPPIRE_SHEET_NORMAL;
+      sheet->select_status = PSPPIRE_SHEET_NORMAL;
       psppire_sheet_real_unselect_range (sheet, NULL);
     }
   else
@@ -3489,15 +3494,13 @@ psppire_sheet_click_cell (PsppireSheet *sheet, gint row, gint column)
       change_active_cell (sheet, row, column);
     }
 
-  sheet->active_cell.row = row;
-  sheet->active_cell.col = column;
   sheet->selection_cell.row = row;
   sheet->selection_cell.col = column;
   sheet->range.row0 = row;
   sheet->range.col0 = column;
   sheet->range.rowi = row;
   sheet->range.coli = column;
-  sheet->state = PSPPIRE_SHEET_NORMAL;
+  sheet->select_status = PSPPIRE_SHEET_NORMAL;
   PSPPIRE_SHEET_SET_FLAGS (sheet, PSPPIRE_SHEET_IN_SELECTION);
 
   gtk_widget_grab_focus (GTK_WIDGET (sheet->entry_widget));
@@ -3559,10 +3562,6 @@ psppire_sheet_button_release (GtkWidget *widget,
 
       psppire_sheet_real_unselect_range (sheet, NULL);
 
-      sheet->active_cell.row = sheet->active_cell.row +
-       (sheet->drag_range.row0 - sheet->range.row0);
-      sheet->active_cell.col = sheet->active_cell.col +
-       (sheet->drag_range.col0 - sheet->range.col0);
       sheet->selection_cell.row = sheet->selection_cell.row +
        (sheet->drag_range.row0 - sheet->range.row0);
       sheet->selection_cell.col = sheet->selection_cell.col +
@@ -3584,10 +3583,6 @@ psppire_sheet_button_release (GtkWidget *widget,
 
       psppire_sheet_real_unselect_range (sheet, NULL);
 
-      sheet->active_cell.row = sheet->active_cell.row +
-       (sheet->drag_range.row0 - sheet->range.row0);
-      sheet->active_cell.col = sheet->active_cell.col +
-       (sheet->drag_range.col0 - sheet->range.col0);
       if (sheet->drag_range.row0 < sheet->range.row0)
        sheet->selection_cell.row = sheet->drag_range.row0;
       if (sheet->drag_range.rowi >= sheet->range.rowi)
@@ -3600,13 +3595,13 @@ psppire_sheet_button_release (GtkWidget *widget,
       sheet->range = sheet->drag_range;
       sheet->drag_range = old_range;
 
-      if (sheet->state == GTK_STATE_NORMAL) sheet->state = PSPPIRE_SHEET_RANGE_SELECTED;
+      if (sheet->select_status == GTK_STATE_NORMAL) sheet->select_status = PSPPIRE_SHEET_RANGE_SELECTED;
       g_signal_emit (sheet, sheet_signals[RESIZE_RANGE], 0,
                     &sheet->drag_range, &sheet->range);
       psppire_sheet_select_range (sheet, &sheet->range);
     }
 
-  if (sheet->state == PSPPIRE_SHEET_NORMAL && PSPPIRE_SHEET_IN_SELECTION (sheet))
+  if (sheet->select_status == PSPPIRE_SHEET_NORMAL && PSPPIRE_SHEET_IN_SELECTION (sheet))
     {
       PSPPIRE_SHEET_UNSET_FLAGS (sheet, PSPPIRE_SHEET_IN_SELECTION);
       gdk_display_pointer_ungrab (display, event->time);
@@ -3692,7 +3687,8 @@ create_hover_window (void)
 #define HOVER_WINDOW_Y_OFFSET 2
 
 static void
-show_subtitle (PsppireSheet *sheet, gint row, gint column, const gchar *subtitle)
+show_subtitle (PsppireSheet *sheet, gint row, gint column,
+              const gchar *subtitle)
 {
   gint x, y;
   gint px, py;
@@ -3742,6 +3738,8 @@ motion_timeout_callback (gpointer data)
   PsppireSheet *sheet = PSPPIRE_SHEET (data);
   gint x, y;
   gint row, column;
+
+  gdk_threads_enter ();
   gtk_widget_get_pointer (GTK_WIDGET (sheet), &x, &y);
 
   if ( psppire_sheet_get_pixel_info (sheet, x, y, &row, &column) )
@@ -3765,6 +3763,7 @@ motion_timeout_callback (gpointer data)
        }
     }
 
+  gdk_threads_leave ();
   return FALSE;
 }
 
@@ -3941,8 +3940,8 @@ psppire_sheet_motion (GtkWidget *widget,  GdkEventMotion *event)
       PsppireSheetRange aux;
       column = column_from_xpixel (sheet, x)- sheet->drag_cell.col;
       row = row_from_ypixel (sheet, y) - sheet->drag_cell.row;
-      if (sheet->state == PSPPIRE_SHEET_COLUMN_SELECTED) row = 0;
-      if (sheet->state == PSPPIRE_SHEET_ROW_SELECTED) column = 0;
+      if (sheet->select_status == PSPPIRE_SHEET_COLUMN_SELECTED) row = 0;
+      if (sheet->select_status == PSPPIRE_SHEET_ROW_SELECTED) column = 0;
       sheet->x_drag = x;
       sheet->y_drag = y;
       aux = sheet->range;
@@ -4004,8 +4003,8 @@ psppire_sheet_motion (GtkWidget *widget,  GdkEventMotion *event)
            row +=1;
        }
 
-      if (sheet->state == PSPPIRE_SHEET_COLUMN_SELECTED) row = 0;
-      if (sheet->state == PSPPIRE_SHEET_ROW_SELECTED) column = 0;
+      if (sheet->select_status == PSPPIRE_SHEET_COLUMN_SELECTED) row = 0;
+      if (sheet->select_status == PSPPIRE_SHEET_ROW_SELECTED) column = 0;
       sheet->x_drag = x;
       sheet->y_drag = y;
       aux = sheet->range;
@@ -4040,11 +4039,13 @@ psppire_sheet_motion (GtkWidget *widget,  GdkEventMotion *event)
 
   psppire_sheet_get_pixel_info (sheet, x, y, &row, &column);
 
-  if (sheet->state == PSPPIRE_SHEET_NORMAL && row == sheet->active_cell.row &&
+  if (sheet->select_status == PSPPIRE_SHEET_NORMAL && row == sheet->active_cell.row &&
       column == sheet->active_cell.col) return TRUE;
 
+#if 0
   if (PSPPIRE_SHEET_IN_SELECTION (sheet) && mods&GDK_BUTTON1_MASK)
     psppire_sheet_extend_selection (sheet, row, column);
+#endif
 
   return TRUE;
 }
@@ -4060,6 +4061,9 @@ psppire_sheet_crossing_notify (GtkWidget *widget,
   else if (event->window == sheet->row_title_window)
     sheet->row_title_under = event->type == GDK_ENTER_NOTIFY;
 
+  if (event->type == GDK_LEAVE_NOTIFY)
+    gtk_widget_hide (sheet->hover_window->window);
+
   return TRUE;
 }
 
@@ -4092,9 +4096,9 @@ psppire_sheet_extend_selection (PsppireSheet *sheet, gint row, gint column)
 
   if (PSPPIRE_SHEET_IN_DRAG (sheet)) return;
 
-  state = sheet->state;
+  state = sheet->select_status;
 
-  switch (sheet->state)
+  switch (sheet->select_status)
     {
     case PSPPIRE_SHEET_ROW_SELECTED:
       column = psppire_axis_unit_count (sheet->haxis) - 1;
@@ -4103,7 +4107,7 @@ psppire_sheet_extend_selection (PsppireSheet *sheet, gint row, gint column)
       row = psppire_axis_unit_count (sheet->vaxis) - 1;
       break;
     case PSPPIRE_SHEET_NORMAL:
-      sheet->state = PSPPIRE_SHEET_RANGE_SELECTED;
+      sheet->select_status = PSPPIRE_SHEET_RANGE_SELECTED;
       r = sheet->active_cell.row;
       c = sheet->active_cell.col;
       sheet->range.col0 = c;
@@ -4112,7 +4116,7 @@ psppire_sheet_extend_selection (PsppireSheet *sheet, gint row, gint column)
       sheet->range.rowi = r;
       psppire_sheet_range_draw_selection (sheet, sheet->range);
     case PSPPIRE_SHEET_RANGE_SELECTED:
-      sheet->state = PSPPIRE_SHEET_RANGE_SELECTED;
+      sheet->select_status = PSPPIRE_SHEET_RANGE_SELECTED;
     }
 
   sheet->selection_cell.row = row;
@@ -4605,10 +4609,10 @@ psppire_sheet_size_allocate_entry (PsppireSheet *sheet)
   rectangle_from_cell (sheet, sheet->active_cell.row,
                       sheet->active_cell.col, &entry_alloc);
 
-  entry_alloc.width -= BORDER_WIDTH ;
-  entry_alloc.height -= BORDER_WIDTH ;
-  entry_alloc.x += DIV_RND_UP (BORDER_WIDTH, 2);
-  entry_alloc.y += DIV_RND_UP (BORDER_WIDTH, 2);
+  entry_alloc.x += sheet->cell_padding->left;
+  entry_alloc.y += sheet->cell_padding->right;
+  entry_alloc.width -= sheet->cell_padding->left + sheet->cell_padding->right;
+  entry_alloc.height -= sheet->cell_padding->top + sheet->cell_padding->bottom;
 
 
   gtk_widget_set_size_request (sheet->entry_widget, entry_alloc.width,
@@ -4733,8 +4737,9 @@ draw_button (PsppireSheet *sheet, GdkWindow *window,
 
   gtk_paint_box (sheet->button->style, window,
                 GTK_STATE_NORMAL, GTK_SHADOW_OUT,
-                &allocation, GTK_WIDGET (sheet->button),
-                "buttondefault",
+                &allocation,
+                GTK_WIDGET (sheet->button),
+                NULL,
                 allocation.x, allocation.y,
                 allocation.width, allocation.height);
 
@@ -4750,7 +4755,7 @@ draw_button (PsppireSheet *sheet, GdkWindow *window,
     gtk_paint_box (sheet->button->style, window,
                   button->state, shadow_type,
                   &allocation, GTK_WIDGET (sheet->button),
-                  "button",
+                  NULL,
                   allocation.x, allocation.y,
                   allocation.width, allocation.height);
 
@@ -4768,7 +4773,7 @@ draw_button (PsppireSheet *sheet, GdkWindow *window,
                         shadow_type,
                         NULL,
                         GTK_WIDGET (sheet),
-                        "button",
+                        NULL,
                         points,
                         2,
                         TRUE);
@@ -5219,7 +5224,9 @@ set_column_width (PsppireSheet *sheet,
   if ( width <= 0)
     return;
 
-  psppire_axis_resize (sheet->haxis, column, width);
+  psppire_axis_resize (sheet->haxis, column,
+                      width - sheet->cell_padding->left -
+                      sheet->cell_padding->right);
 
   if (GTK_WIDGET_REALIZED (GTK_WIDGET (sheet)))
     {
@@ -5244,7 +5251,9 @@ set_row_height (PsppireSheet *sheet,
   if (height <= 0)
     return;
 
-  psppire_axis_resize (sheet->vaxis, row, height);
+  psppire_axis_resize (sheet->vaxis, row,
+                      height - sheet->cell_padding->top -
+                      sheet->cell_padding->bottom);
 
   if (GTK_WIDGET_REALIZED (GTK_WIDGET (sheet)) )
     {