Hide tooltip when leaving sheet
[pspp-builds.git] / lib / gtk-contrib / psppire-sheet.c
index ad1cf78a7fd973d1af993e32696e59813b5f69f3..6fb9a7a3c604d015989176fd32a4d8ee85e7ba40 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 */
@@ -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, 2, 2 };
 
 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);
@@ -1752,6 +1796,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);
@@ -1934,6 +1981,9 @@ psppire_sheet_realize (GtkWidget *widget)
   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 +2141,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 +2221,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;
 
@@ -3692,7 +3753,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 +3804,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 +3829,7 @@ motion_timeout_callback (gpointer data)
        }
     }
 
+  gdk_threads_leave ();
   return FALSE;
 }
 
@@ -4060,6 +4125,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;
 }
 
@@ -4733,8 +4801,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 +4819,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 +4837,7 @@ draw_button (PsppireSheet *sheet, GdkWindow *window,
                         shadow_type,
                         NULL,
                         GTK_WIDGET (sheet),
-                        "button",
+                        NULL,
                         points,
                         2,
                         TRUE);
@@ -5219,7 +5288,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 +5315,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)) )
     {