Merge remote-tracking branch 'origin/master' into sheet
[pspp] / src / ui / gui / psppire-data-editor.c
index c108de556363f6cd6f4a4262186d3f9330fb6f8e..40a2c490b4460fcdb5a874dd28fb1d648ce3f55f 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
+   Copyright (C) 2008, 2009, 2010, 2011, 2012, 2016 Free Software Foundation, Inc.
 
    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
@@ -458,7 +458,21 @@ on_data_sheet_var_double_clicked (JmdSheet *data_sheet, gint dict_index,
 static void
 refresh_entry (PsppireDataEditor *de)
 {
-  g_print ("%s\n", __FUNCTION__);
+  union value val;
+  gint row, col;
+  jmd_sheet_get_active_cell (JMD_SHEET (de->data_sheet), &col, &row);
+
+  const struct variable *var = psppire_dict_get_variable (de->dict, col);
+  psppire_value_entry_set_variable (PSPPIRE_VALUE_ENTRY (de->datum_entry), var);
+
+  int width = var_get_width (var);
+  if (! psppire_data_store_get_value (PSPPIRE_DATA_STORE (de->data_store),
+                                     row, var, &val))
+    return;
+
+  psppire_value_entry_set_value (PSPPIRE_VALUE_ENTRY (de->datum_entry),
+                                &val, width);
+  value_destroy (&val, width);
 }
 
 static void
@@ -528,6 +542,9 @@ psppire_data_editor_init (PsppireDataEditor *de)
   GtkWidget *hbox;
   gchar *fontname = NULL;
 
+  GtkStyleContext *context = gtk_widget_get_style_context (GTK_WIDGET (de));
+  gtk_style_context_add_class (context, "psppire-data-editor");
+  
   de->font = NULL;
   de->old_vbox_widget = NULL;
 
@@ -628,7 +645,28 @@ set_font_recursively (GtkWidget *w, gpointer data)
 {
   PangoFontDescription *font_desc = data;
 
-  gtk_widget_override_font (w, font_desc);
+  GtkStyleContext *style = gtk_widget_get_style_context (w);
+  GtkCssProvider *cssp = gtk_css_provider_new ();
+
+  gchar *str = pango_font_description_to_string (font_desc);
+  gchar *css =
+    g_strdup_printf ("* {font: %s}", str);
+  g_free (str);
+
+  GError *err = NULL;
+  gtk_css_provider_load_from_data (cssp, css, -1, &err);
+  if (err)
+    {
+      g_warning ("Failed to load font css \"%s\": %s", css, err->message);
+      g_error_free (err);
+    }
+  g_free (css);
+
+  gtk_style_context_add_provider (style,
+                                 GTK_STYLE_PROVIDER (cssp),
+                                 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+  g_object_unref (cssp);
+
 
   if ( GTK_IS_CONTAINER (w))
     gtk_container_foreach (GTK_CONTAINER (w), set_font_recursively, font_desc);
@@ -649,7 +687,7 @@ psppire_data_editor_set_font (PsppireDataEditor *de, PangoFontDescription *font_
   psppire_conf_set_string (psppire_conf_new (),
                           "Data Editor", "font",
                           font_name);
-
+  g_free (font_name);
 }
 
 /* If SPLIT is TRUE, splits DE's data sheet into four panes.
@@ -679,41 +717,3 @@ void
 psppire_data_editor_goto_variable (PsppireDataEditor *de, gint dict_index)
 {
 }
-
-#if SHEET_MERGE
-/* Returns the "active" data sheet in DE.  If DE is in single-paned mode, this
-   is the only data sheet.  If DE is in split mode (showing four data sheets),
-   this is the focused data sheet or, if none is focused, the data sheet with
-   selected cells or, if none has selected cells, the upper-left data sheet. */
-PsppireDataSheet *
-psppire_data_editor_get_active_data_sheet (PsppireDataEditor *de)
-{
-  if (de->split)
-    {
-      PsppireDataSheet *data_sheet;
-      GtkWidget *scroller;
-      int i;
-
-      /* If one of the datasheet's scrollers is focused, choose that one. */
-      scroller = gtk_container_get_focus_child (
-        GTK_CONTAINER (de->datasheet_vbox_widget));
-      if (scroller != NULL)
-        return PSPPIRE_DATA_SHEET (gtk_bin_get_child (GTK_BIN (scroller)));
-
-      /* Otherwise if there's a nonempty selection in some data sheet, choose
-         that one. */
-      FOR_EACH_DATA_SHEET (data_sheet, i, de)
-        {
-          PsppSheetSelection *selection;
-
-          selection = pspp_sheet_view_get_selection (
-            PSPP_SHEET_VIEW (data_sheet));
-          if (pspp_sheet_selection_count_selected_rows (selection)
-              && pspp_sheet_selection_count_selected_columns (selection))
-            return data_sheet;
-        }
-    }
-
-  return PSPPIRE_DATA_SHEET (de->data_sheets[0]);
-}
-#endif