fixed goto case dialog
[pspp] / src / ui / gui / psppire-data-editor.c
index b9c6fb62148f299421bf1c8aa6f32d75a47b5dca..8bfb74df1601636f490b5e620918821f0ee5e357 100644 (file)
@@ -1,6 +1,6 @@
 /* PSPPIRE - a graphical user interface for PSPP.
    Copyright (C) 2008, 2009, 2010, 2011, 2012, 2016,
-   2017 Free Software Foundation, Inc.
+   2017, 2019 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
@@ -31,6 +31,7 @@
 #include "ui/gui/val-labs-dialog.h"
 #include "ui/gui/missing-val-dialog.h"
 #include "ui/gui/var-type-dialog.h"
+#include "ui/gui/value-variant.h"
 #include "ui/gui/psppire-dict.h"
 #include "ui/gui/psppire-data-store.h"
 #include "ui/gui/psppire-data-window.h"
@@ -380,7 +381,7 @@ on_datum_entry_activate (GtkEntry *entry, PsppireDataEditor *de)
       value_destroy (&val, width);
 
       gtk_widget_grab_focus (de->data_sheet);
-      ssw_sheet_set_active_cell (de->data_sheet, col, row, NULL);
+      ssw_sheet_set_active_cell (SSW_SHEET (de->data_sheet), col, row, NULL);
     }
 }
 
@@ -436,12 +437,7 @@ static void set_font_recursively (GtkWidget *w, gpointer data);
 void
 psppire_data_editor_data_delete_variables (PsppireDataEditor *de)
 {
-  SswRange *range = SSW_SHEET(de->data_sheet)->selection;
-
-  psppire_dict_delete_variables (de->dict, range->start_x,
-                                (range->end_x - range->start_x + 1));
-
-  gtk_widget_queue_draw (GTK_WIDGET (de->data_sheet));
+  psppire_data_sheet_delete_variables (PSPPIRE_DATA_SHEET (de->data_sheet));
 }
 
 void
@@ -449,6 +445,13 @@ psppire_data_editor_var_delete_variables (PsppireDataEditor *de)
 {
   SswRange *range = SSW_SHEET(de->var_sheet)->selection;
 
+  if (range->start_x > range->end_x)
+    {
+      gint temp = range->start_x;
+      range->start_x = range->end_x;
+      range->end_x = temp;
+    }
+
   psppire_dict_delete_variables (de->dict, range->start_y,
                                 (range->end_y - range->start_y + 1));
 
@@ -458,6 +461,8 @@ psppire_data_editor_var_delete_variables (PsppireDataEditor *de)
 void
 psppire_data_editor_insert_new_case_at_posn  (PsppireDataEditor *de, gint posn)
 {
+  g_return_if_fail (posn >= 0);
+
   psppire_data_store_insert_new_case (de->data_store, posn);
 
   gtk_widget_queue_draw (GTK_WIDGET (de->data_sheet));
@@ -466,11 +471,7 @@ psppire_data_editor_insert_new_case_at_posn  (PsppireDataEditor *de, gint posn)
 void
 psppire_data_editor_insert_new_variable_at_posn (PsppireDataEditor *de, gint posn)
 {
-  const struct variable *v = psppire_dict_insert_variable (de->dict, posn, NULL);
-  psppire_data_store_insert_value (de->data_store, var_get_width(v),
-                                  var_get_case_index (v));
-
-  gtk_widget_queue_draw (GTK_WIDGET (de));
+  psppire_data_sheet_insert_new_variable_at_posn (PSPPIRE_DATA_SHEET (de->data_sheet), posn);
 }
 
 static void
@@ -574,10 +575,15 @@ set_font_recursively (GtkWidget *w, gpointer data)
   GtkStyleContext *style = gtk_widget_get_style_context (w);
   GtkCssProvider *cssp = gtk_css_provider_new ();
 
-  gchar *str = pango_font_description_to_string (font_desc);
+  /* The Pango font description as string has a different syntax than the
+     css style description:
+     Pango: Courier Italic 12
+     CSS: italic 12pt Courier
+     I ignore Weight, Style and Variant and just take family and size */
+  const gchar *str = pango_font_description_get_family (font_desc);
+  gint size = pango_font_description_get_size (font_desc);
   gchar *css =
-    g_strdup_printf ("* {font: %s}", str);
-  g_free (str);
+    g_strdup_printf ("* {font: %dpt %s}", size/PANGO_SCALE, str);
 
   GError *err = NULL;
   gtk_css_provider_load_from_data (cssp, css, -1, &err);