pspp-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pspp-cvs] pspp/lib/gtksheet ChangeLog gtksheet.c gtksheet.h


From: John Darrington
Subject: [Pspp-cvs] pspp/lib/gtksheet ChangeLog gtksheet.c gtksheet.h
Date: Wed, 27 Feb 2008 10:10:28 +0000

CVSROOT:        /sources/pspp
Module name:    pspp
Changes by:     John Darrington <jmd>   08/02/27 10:10:28

Modified files:
        lib/gtksheet   : ChangeLog gtksheet.c gtksheet.h 

Log message:
        Fixed some deallocation problems.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pspp/lib/gtksheet/ChangeLog?cvsroot=pspp&r1=1.22&r2=1.23
http://cvs.savannah.gnu.org/viewcvs/pspp/lib/gtksheet/gtksheet.c?cvsroot=pspp&r1=1.38&r2=1.39
http://cvs.savannah.gnu.org/viewcvs/pspp/lib/gtksheet/gtksheet.h?cvsroot=pspp&r1=1.17&r2=1.18

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/pspp/pspp/lib/gtksheet/ChangeLog,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -b -r1.22 -r1.23
--- ChangeLog   27 Feb 2008 02:38:19 -0000      1.22
+++ ChangeLog   27 Feb 2008 10:10:28 -0000      1.23
@@ -1,4 +1,8 @@
 2008-02-27 John Darrington <address@hidden>
+       * gtksheet.c gtksheet.h: Corrected some leaks and other problems
+       related to de-allocating the sheet.
+
+2008-02-27 John Darrington <address@hidden>
        * gtksheet.c: (gtk_sheet_expose) Don't queue a redraw on the entry
        widget.  Fixes bug #21073
 

Index: gtksheet.c
===================================================================
RCS file: /sources/pspp/pspp/lib/gtksheet/gtksheet.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -b -r1.38 -r1.39
--- gtksheet.c  27 Feb 2008 02:38:19 -0000      1.38
+++ gtksheet.c  27 Feb 2008 10:10:28 -0000      1.39
@@ -1263,7 +1263,6 @@
   sheet->selection_cell.row = 0;
   sheet->selection_cell.col = 0;
 
-  sheet->sheet_entry = NULL;
   sheet->pixmap = NULL;
 
   sheet->range.row0 = 0;
@@ -1276,7 +1275,8 @@
   sheet->sheet_window = NULL;
   sheet->sheet_window_width = 0;
   sheet->sheet_window_height = 0;
-  sheet->sheet_entry = NULL;
+  sheet->entry_widget = NULL;
+  sheet->entry_container = NULL;
   sheet->button = NULL;
 
   sheet->hoffset = 0;
@@ -1794,7 +1794,7 @@
                           "value_changed");
 
   if (sheet->state == GTK_STATE_NORMAL)
-    if (sheet->sheet_entry && GTK_WIDGET_MAPPED (sheet->sheet_entry))
+    if (sheet->entry_widget && GTK_WIDGET_MAPPED (sheet->entry_widget))
       {
        gtk_sheet_activate_cell (sheet, sheet->active_cell.row,
                                 sheet->active_cell.col);
@@ -2415,13 +2415,7 @@
   if (sheet->model) g_object_unref (sheet->model);
   sheet->dispose_has_run = TRUE;
 
-  /* destroy the entry */
-  if (sheet->sheet_entry && GTK_IS_WIDGET (sheet->sheet_entry))
-    {
-      gtk_widget_destroy (sheet->sheet_entry);
-      sheet->sheet_entry = NULL;
-    }
-
+  g_object_unref (sheet->entry_container);
   g_object_unref (sheet->button);
 
   /* unref adjustments */
@@ -2601,13 +2595,8 @@
                                          GDK_GC_FUNCTION |
                                          GDK_GC_SUBWINDOW);
 
-  if (sheet->sheet_entry->parent)
-    {
-      gtk_widget_ref (sheet->sheet_entry);
-      gtk_widget_unparent (sheet->sheet_entry);
-    }
-  gtk_widget_set_parent_window (sheet->sheet_entry, sheet->sheet_window);
-  gtk_widget_set_parent (sheet->sheet_entry, GTK_WIDGET (sheet));
+  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));
@@ -2745,12 +2734,12 @@
          gdk_window_show (sheet->row_title_window);
        }
 
-      if (!GTK_WIDGET_MAPPED (sheet->sheet_entry)
+      if (!GTK_WIDGET_MAPPED (sheet->entry_widget)
          && sheet->active_cell.row >= 0
          && sheet->active_cell.col >= 0 )
        {
-         gtk_widget_show (sheet->sheet_entry);
-         gtk_widget_map (sheet->sheet_entry);
+         gtk_widget_show (sheet->entry_widget);
+         gtk_widget_map (sheet->entry_widget);
        }
 
       if (GTK_WIDGET_VISIBLE (sheet->button) &&
@@ -2810,8 +2799,8 @@
        gdk_window_hide (sheet->row_title_window);
       gdk_window_hide (widget->window);
 
-      if (GTK_WIDGET_MAPPED (sheet->sheet_entry))
-       gtk_widget_unmap (sheet->sheet_entry);
+      if (GTK_WIDGET_MAPPED (sheet->entry_widget))
+       gtk_widget_unmap (sheet->entry_widget);
 
       if (GTK_WIDGET_MAPPED (sheet->button))
        gtk_widget_unmap (sheet->button);
@@ -3778,8 +3767,8 @@
   row = sheet->active_cell.row;
   col = sheet->active_cell.col;
 
-  gtk_widget_hide (sheet->sheet_entry);
-  gtk_widget_unmap (sheet->sheet_entry);
+  gtk_widget_hide (sheet->entry_widget);
+  gtk_widget_unmap (sheet->entry_widget);
 
   if (row != -1 && col != -1)
     gdk_draw_pixmap (sheet->sheet_window,
@@ -3794,7 +3783,7 @@
 
   gtk_widget_grab_focus (GTK_WIDGET (sheet));
 
-  GTK_WIDGET_UNSET_FLAGS (GTK_WIDGET (sheet->sheet_entry), GTK_VISIBLE);
+  GTK_WIDGET_UNSET_FLAGS (GTK_WIDGET (sheet->entry_widget), GTK_VISIBLE);
 
 }
 
@@ -3865,7 +3854,7 @@
   if (sheet->state != GTK_SHEET_NORMAL) return;
   if (GTK_SHEET_IN_SELECTION (sheet)) return;
 
-  GTK_WIDGET_SET_FLAGS (GTK_WIDGET (sheet->sheet_entry), GTK_VISIBLE);
+  GTK_WIDGET_SET_FLAGS (GTK_WIDGET (sheet->entry_widget), GTK_VISIBLE);
 
   sheet_entry = GTK_ENTRY (gtk_sheet_get_entry (sheet));
 
@@ -3896,7 +3885,7 @@
   gtk_sheet_entry_set_max_size (sheet);
   gtk_sheet_size_allocate_entry (sheet);
 
-  gtk_widget_map (sheet->sheet_entry);
+  gtk_widget_map (sheet->entry_widget);
 
   gtk_widget_grab_focus (GTK_WIDGET (sheet_entry));
 
@@ -6086,7 +6075,7 @@
                                   &attributes) )
     return ;
 
-  if ( GTK_WIDGET_REALIZED (sheet->sheet_entry) )
+  if ( GTK_WIDGET_REALIZED (sheet->entry_widget) )
     {
       if (!GTK_WIDGET (sheet_entry)->style)
        gtk_widget_ensure_style (GTK_WIDGET (sheet_entry));
@@ -6106,12 +6095,12 @@
       style->font_desc = pango_font_description_copy (attributes.font_desc);
 
       GTK_WIDGET (sheet_entry)->style = style;
-      gtk_widget_size_request (sheet->sheet_entry, NULL);
+      gtk_widget_size_request (sheet->entry_widget, NULL);
       GTK_WIDGET (sheet_entry)->style = previous_style;
 
       if (style != previous_style)
        {
-         if (!GTK_IS_ITEM_ENTRY (sheet->sheet_entry))
+         if (!GTK_IS_ITEM_ENTRY (sheet->entry_widget))
            {
              style->bg[GTK_STATE_NORMAL] = 
previous_style->bg[GTK_STATE_NORMAL];
              style->fg[GTK_STATE_NORMAL] = 
previous_style->fg[GTK_STATE_NORMAL];
@@ -6146,7 +6135,7 @@
   shentry_allocation.width = column_width;
   shentry_allocation.height = yyy_row_height (sheet, sheet->active_cell.row);
 
-  if (GTK_IS_ITEM_ENTRY (sheet->sheet_entry))
+  if (GTK_IS_ITEM_ENTRY (sheet->entry_widget))
     {
       shentry_allocation.height -= 2 * CELLOFFSET;
       shentry_allocation.y += CELLOFFSET;
@@ -6167,7 +6156,7 @@
        }
     }
 
-  if (!GTK_IS_ITEM_ENTRY (sheet->sheet_entry))
+  if (!GTK_IS_ITEM_ENTRY (sheet->entry_widget))
     {
       shentry_allocation.x += 2;
       shentry_allocation.y += 2;
@@ -6175,7 +6164,7 @@
       shentry_allocation.height -= MIN (shentry_allocation.height, 3);
     }
 
-  gtk_widget_size_allocate (sheet->sheet_entry, &shentry_allocation);
+  gtk_widget_size_allocate (sheet->entry_widget, &shentry_allocation);
 
   if (previous_style == style) g_object_unref (previous_style);
 }
@@ -6193,10 +6182,10 @@
   row = sheet->active_cell.row;
   col = sheet->active_cell.col;
 
-  if ( ! GTK_IS_ITEM_ENTRY (sheet->sheet_entry) )
+  if ( ! GTK_IS_ITEM_ENTRY (sheet->entry_widget) )
     return;
 
-  justification = GTK_ITEM_ENTRY (sheet->sheet_entry)->justification;
+  justification = GTK_ITEM_ENTRY (sheet->entry_widget)->justification;
 
   switch (justification)
     {
@@ -6244,76 +6233,56 @@
 
   if (size != 0)
     size += xxx_column_width (sheet, col);
-  GTK_ITEM_ENTRY (sheet->sheet_entry)->text_max_size = size;
+  GTK_ITEM_ENTRY (sheet->entry_widget)->text_max_size = size;
 }
 
 
 static void
 create_sheet_entry (GtkSheet *sheet)
 {
-  GtkWidget *widget;
-  GtkWidget *parent;
-  GtkWidget *entry;
-  gint found_entry = FALSE;
-
-  widget = GTK_WIDGET (sheet);
-
-  if (sheet->sheet_entry)
+  if (sheet->entry_widget)
     {
-      /* avoids warnings */
-      gtk_widget_ref (sheet->sheet_entry);
-      gtk_widget_unparent (sheet->sheet_entry);
-      gtk_widget_destroy (sheet->sheet_entry);
+      gtk_widget_unparent (sheet->entry_widget);
     }
 
   if (sheet->entry_type)
     {
-      if (!g_type_is_a (sheet->entry_type, GTK_TYPE_ENTRY))
-       {
-         parent = g_object_new (sheet->entry_type, NULL);
-
-         sheet->sheet_entry = parent;
+      sheet->entry_container = g_object_new (sheet->entry_type, NULL);
+      g_object_ref_sink (sheet->entry_container);
+      sheet->entry_widget = gtk_sheet_get_entry (sheet);
 
-         entry = gtk_sheet_get_entry (sheet);
-         if (GTK_IS_ENTRY (entry))
-           found_entry = TRUE;
-       }
-      else
+      if  ( NULL == sheet->entry_widget)
        {
-         parent = g_object_new (sheet->entry_type, NULL);
-         entry = parent;
-         found_entry = TRUE;
+         g_warning ("Entry type is %s. It must be GtkEntry subclass, or a 
widget containing one. "
+                    "Using default", g_type_name (sheet->entry_type));
+         g_object_unref (sheet->entry_container);
+         sheet->entry_widget = sheet->entry_container = gtk_item_entry_new ();
        }
-
-      if (!found_entry)
+      else
        {
-         g_warning ("Entry type must be GtkEntry subclass, using default");
-         entry = gtk_item_entry_new ();
-         sheet->sheet_entry = entry;
+         sheet->entry_widget = sheet->entry_container ;
        }
-      else
-       sheet->sheet_entry = parent;
     }
   else
     {
-      entry = gtk_item_entry_new ();
-      sheet->sheet_entry = entry;
+      sheet->entry_widget = sheet->entry_container = gtk_item_entry_new ();
+      g_object_ref_sink (sheet->entry_container);
     }
 
-  gtk_widget_size_request (sheet->sheet_entry, NULL);
+  gtk_widget_size_request (sheet->entry_widget, NULL);
 
   if (GTK_WIDGET_REALIZED (sheet))
     {
-      gtk_widget_set_parent_window (sheet->sheet_entry, sheet->sheet_window);
-      gtk_widget_set_parent (sheet->sheet_entry, GTK_WIDGET (sheet));
-      gtk_widget_realize (sheet->sheet_entry);
+      gtk_widget_set_parent_window (sheet->entry_widget, sheet->sheet_window);
+      gtk_widget_set_parent (sheet->entry_widget, GTK_WIDGET (sheet));
+      gtk_widget_realize (sheet->entry_widget);
     }
 
-  g_signal_connect_swapped (entry, "key_press_event",
+  g_signal_connect_swapped (sheet->entry_widget, "key_press_event",
                            G_CALLBACK (gtk_sheet_entry_key_press),
                            sheet);
 
-  gtk_widget_show (sheet->sheet_entry);
+  gtk_widget_show (sheet->entry_widget);
 }
 
 
@@ -6339,11 +6308,13 @@
 
   g_return_val_if_fail (sheet != NULL, NULL);
   g_return_val_if_fail (GTK_IS_SHEET (sheet), NULL);
-  g_return_val_if_fail (sheet->sheet_entry != NULL, NULL);
+  g_return_val_if_fail (sheet->entry_widget != NULL, NULL);
 
-  if (GTK_IS_ENTRY (sheet->sheet_entry)) return (sheet->sheet_entry);
+  if (GTK_IS_ENTRY (sheet->entry_container))
+    return (sheet->entry_container);
 
-  parent = GTK_WIDGET (sheet->sheet_entry);
+  //parent = GTK_WIDGET (sheet->entry_widget);
+  parent = sheet->entry_container;
 
   if (GTK_IS_TABLE (parent)) children = GTK_TABLE (parent)->children;
   if (GTK_IS_BOX (parent)) children = GTK_BOX (parent)->children;
@@ -6388,9 +6359,9 @@
 {
   g_return_val_if_fail (sheet != NULL, NULL);
   g_return_val_if_fail (GTK_IS_SHEET (sheet), NULL);
-  g_return_val_if_fail (sheet->sheet_entry != NULL, NULL);
+  g_return_val_if_fail (sheet->entry_widget != NULL, NULL);
 
-  return (sheet->sheet_entry);
+  return (sheet->entry_widget);
 }
 
 
@@ -6752,7 +6723,7 @@
 
   sheet->voffset = - value;
 
-  if (GTK_WIDGET_REALIZED (sheet->sheet_entry) &&
+  if (GTK_WIDGET_REALIZED (sheet->entry_widget) &&
       sheet->state == GTK_SHEET_NORMAL &&
       sheet->active_cell.row >= 0 && sheet->active_cell.col >= 0 &&
       !gtk_sheet_cell_isvisible (sheet, sheet->active_cell.row,
@@ -6766,7 +6737,7 @@
        gtk_sheet_cell_clear (sheet,
                              sheet->active_cell.row,
                              sheet->active_cell.col);
-      gtk_widget_unmap (sheet->sheet_entry);
+      gtk_widget_unmap (sheet->entry_widget);
     }
 
   gtk_sheet_position_children (sheet);
@@ -6858,7 +6829,7 @@
     }
 
   sheet->hoffset = - value;
-  if (GTK_WIDGET_REALIZED (sheet->sheet_entry) &&
+  if (GTK_WIDGET_REALIZED (sheet->entry_widget) &&
       sheet->state == GTK_SHEET_NORMAL &&
       sheet->active_cell.row >= 0 && sheet->active_cell.col >= 0 &&
       !gtk_sheet_cell_isvisible (sheet, sheet->active_cell.row,
@@ -6872,7 +6843,7 @@
                              sheet->active_cell.row,
                              sheet->active_cell.col);
 
-      gtk_widget_unmap (sheet->sheet_entry);
+      gtk_widget_unmap (sheet->entry_widget);
     }
 
   gtk_sheet_position_children (sheet);
@@ -7681,10 +7652,12 @@
 
       (* callback) (child->widget, callback_data);
     }
-  if (sheet->button)
+
+  if (sheet->button && sheet->button->parent)
     (* callback) (sheet->button, callback_data);
-  if (sheet->sheet_entry)
-    (* callback) (sheet->sheet_entry, callback_data);
+
+  if (sheet->entry_container && GTK_IS_CONTAINER (sheet->entry_container))
+    (* callback) (sheet->entry_container, callback_data);
 }
 
 
@@ -7757,6 +7730,7 @@
       g_free (child);
     }
 
+  gtk_widget_unparent (sheet->button);
 }
 
 static void

Index: gtksheet.h
===================================================================
RCS file: /sources/pspp/pspp/lib/gtksheet/gtksheet.h,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -r1.17 -r1.18
--- gtksheet.h  20 Feb 2008 10:04:11 -0000      1.17
+++ gtksheet.h  27 Feb 2008 10:10:28 -0000      1.18
@@ -148,8 +148,15 @@
 
   /* active cell */
   GtkSheetCell active_cell;
-  GtkWidget *sheet_entry;
 
+  /* The GtkEntry used for editing the cells */
+  GtkWidget *entry_widget;
+
+  /* The widget containing entry_widget, or
+     entry_widget itself if no container */
+  GtkWidget *entry_container;
+
+  /* The type of entry_widget */
   GtkType entry_type;
 
   /* expanding selection */




reply via email to

[Prev in Thread] Current Thread [Next in Thread]