Revert "Keep systems happy which do not have sys/resource.h"
[pspp] / src / ui / gui / psppire-data-editor.c
index 7ddb0bff9c047ac000448ad30512aca6ca93bc9d..e852b7d92b403d2d1647c7ea8b863cddd648def5 100644 (file)
@@ -80,28 +80,29 @@ psppire_data_editor_get_type (void)
 
 static GObjectClass * parent_class = NULL;
 
+static void
+psppire_data_editor_finalize (GObject *obj)
+{
+  PsppireDataEditor *de = (PsppireDataEditor *) obj;
+  if (de->font)
+    pango_font_description_free (de->font);
+
+  /* Chain up to the parent class */
+  G_OBJECT_CLASS (parent_class)->finalize (obj);
+}
+
 static void
 psppire_data_editor_dispose (GObject *obj)
 {
   PsppireDataEditor *de = (PsppireDataEditor *) obj;
 
-  if (de->data_store)
-    {
-      g_object_unref (de->data_store);
-      de->data_store = NULL;
-    }
+  if (de->dispose_has_run)
+    return;
 
-  if (de->dict)
-    {
-      g_object_unref (de->dict);
-      de->dict = NULL;
-    }
+  de->dispose_has_run = TRUE;
 
-  if (de->font != NULL)
-    {
-      pango_font_description_free (de->font);
-      de->font = NULL;
-    }
+  g_object_unref (de->data_store);
+  g_object_unref (de->dict);
 
   /* Chain up to the parent class */
   G_OBJECT_CLASS (parent_class)->dispose (obj);
@@ -138,7 +139,7 @@ psppire_data_editor_set_property (GObject         *object,
       g_object_set (de->var_sheet, "split", de->split, NULL);
       break;
     case PROP_DATA_STORE:
-      if ( de->data_store)
+      if (de->data_store)
         {
           g_signal_handlers_disconnect_by_func (de->data_store,
                                                 G_CALLBACK (refresh_entry),
@@ -258,6 +259,7 @@ psppire_data_editor_class_init (PsppireDataEditorClass *klass)
   parent_class = g_type_class_peek_parent (klass);
 
   object_class->dispose = psppire_data_editor_dispose;
+  object_class->finalize = psppire_data_editor_finalize;
   object_class->set_property = psppire_data_editor_set_property;
   object_class->get_property = psppire_data_editor_get_property;
 
@@ -269,7 +271,7 @@ psppire_data_editor_class_init (PsppireDataEditorClass *klass)
     g_param_spec_pointer ("data-store",
                          "Data Store",
                          "A pointer to the data store associated with this editor",
-                         G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | G_PARAM_READABLE );
+                         G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | G_PARAM_READABLE);
 
   g_object_class_install_property (object_class,
                                    PROP_DATA_STORE,
@@ -279,7 +281,7 @@ psppire_data_editor_class_init (PsppireDataEditorClass *klass)
     g_param_spec_pointer ("dictionary",
                          "Dictionary",
                          "A pointer to the dictionary associated with this editor",
-                         G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | G_PARAM_READABLE );
+                         G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | G_PARAM_READABLE);
 
   g_object_class_install_property (object_class,
                                    PROP_DICTIONARY,
@@ -445,6 +447,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));
 
@@ -476,6 +485,8 @@ psppire_data_editor_init (PsppireDataEditor *de)
   GtkStyleContext *context = gtk_widget_get_style_context (GTK_WIDGET (de));
   gtk_style_context_add_class (context, "psppire-data-editor");
 
+  de->dispose_has_run = FALSE;
+
   de->font = NULL;
 
   g_object_set (de, "tab-pos", GTK_POS_BOTTOM, NULL);
@@ -530,7 +541,7 @@ psppire_data_editor_init (PsppireDataEditor *de)
 
   if (psppire_conf_get_string (psppire_conf_new (),
                           "Data Editor", "font",
-                               &fontname) )
+                               &fontname))
     {
       de->font = pango_font_description_from_string (fontname);
       g_free (fontname);
@@ -593,7 +604,7 @@ set_font_recursively (GtkWidget *w, gpointer data)
   g_object_unref (cssp);
 
 
-  if ( GTK_IS_CONTAINER (w))
+  if (GTK_IS_CONTAINER (w))
     gtk_container_foreach (GTK_CONTAINER (w), set_font_recursively, font_desc);
 }