pspp-cvs
[Top][All Lists]
Advanced

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

[Pspp-cvs] pspp lib/gtksheet/ChangeLog lib/gtksheet/gsheet...


From: John Darrington
Subject: [Pspp-cvs] pspp lib/gtksheet/ChangeLog lib/gtksheet/gsheet...
Date: Sun, 14 May 2006 00:01:39 +0000

CVSROOT:        /sources/pspp
Module name:    pspp
Branch:         
Changes by:     John Darrington <address@hidden>        06/05/14 00:01:39

Modified files:
        lib/gtksheet   : ChangeLog gsheetmodel.c gsheetmodel.h 
                         gtksheet.c gtksheet.h 
        src/ui/gui     : ChangeLog data-sheet.c helper.c helper.h 
                         psppire-data-store.c psppire-var-store.c 

Log message:
        Fixed some memory leaks in GUI.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/lib/gtksheet/ChangeLog.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/lib/gtksheet/gsheetmodel.c.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/lib/gtksheet/gsheetmodel.h.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/lib/gtksheet/gtksheet.c.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/lib/gtksheet/gtksheet.h.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/ui/gui/ChangeLog.diff?tr1=1.11&tr2=1.12&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/ui/gui/data-sheet.c.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/ui/gui/helper.c.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/ui/gui/helper.h.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/ui/gui/psppire-data-store.c.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/pspp/pspp/src/ui/gui/psppire-var-store.c.diff?tr1=1.5&tr2=1.6&r1=text&r2=text

Patches:
Index: pspp/lib/gtksheet/ChangeLog
diff -u pspp/lib/gtksheet/ChangeLog:1.3 pspp/lib/gtksheet/ChangeLog:1.4
--- pspp/lib/gtksheet/ChangeLog:1.3     Thu May 11 14:28:02 2006
+++ pspp/lib/gtksheet/ChangeLog Sun May 14 00:01:39 2006
@@ -1,3 +1,9 @@
+Sat May 13 07:58:32 WST 2006 John Darrington <address@hidden>
+
+        * gsheetmodel.c gsheetmodel.h gtksheet.c gtksheeet.h: Added
+       free_strings flag to tell the sheet whether to free the string
+       data passed from the model.
+
 Thu May 11 22:20:04 WST 2006 John Darrington <address@hidden>
 
     * gtksheet.c, gtksheet.h: Fixed broken deallocation of sheet->pixmap.
Index: pspp/lib/gtksheet/gsheetmodel.c
diff -u pspp/lib/gtksheet/gsheetmodel.c:1.2 pspp/lib/gtksheet/gsheetmodel.c:1.3
--- pspp/lib/gtksheet/gsheetmodel.c:1.2 Tue Apr  4 12:43:21 2006
+++ pspp/lib/gtksheet/gsheetmodel.c     Sun May 14 00:01:39 2006
@@ -113,6 +113,23 @@
     }
 }
 
+
+/**
+ * g_sheet_model_free_strings
+ * @sheet_model: A #GSheetModel
+ * 
+ * Returns: True if strings obtained with get_string should be freed by the 
+ * sheet when no longer required.
+ **/
+inline  gboolean 
+g_sheet_model_free_strings (const GSheetModel *sheet_model)
+{
+  g_return_val_if_fail (G_IS_SHEET_MODEL (sheet_model), FALSE);
+
+  return G_SHEET_MODEL_GET_IFACE (sheet_model)->free_strings;
+}
+
+
 /**
  * g_sheet_model_get_string:
  * @sheet_model: A #GSheetModel
@@ -122,7 +139,7 @@
  * Retrieves the datum at location ROW, COLUMN in the form of a string.
  * Returns: The string representation of the datum, or NULL on error.
  **/
-inline const gchar *
+inline gchar *
 g_sheet_model_get_string (const GSheetModel *sheet_model, 
                          gint row, gint column)
 {
@@ -393,3 +410,6 @@
   return G_SHEET_MODEL_GET_IFACE (model)->get_cell_border (model, 
                                                           row, column);
 }
+
+
+
Index: pspp/lib/gtksheet/gsheetmodel.h
diff -u pspp/lib/gtksheet/gsheetmodel.h:1.2 pspp/lib/gtksheet/gsheetmodel.h:1.3
--- pspp/lib/gtksheet/gsheetmodel.h:1.2 Tue Apr  4 12:43:21 2006
+++ pspp/lib/gtksheet/gsheetmodel.h     Sun May 14 00:01:39 2006
@@ -15,6 +15,7 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
+
 #ifndef __G_SHEET_MODEL_H__
 #define __G_SHEET_MODEL_H__
 
@@ -70,6 +71,8 @@
 {
   GTypeInterface g_iface;
 
+  gboolean free_strings;
+
   /* Signals */
   void         (* range_changed)    (GSheetModel *sheet_model,
                                     gint row0, gint col0, 
@@ -82,9 +85,9 @@
                                     gint row, gint n_rows);
 
 
-
   /* Virtual Table */
-  const gchar *      (* get_string)      (const GSheetModel *sheet_model, 
+
+  gchar *      (* get_string)      (const GSheetModel *sheet_model, 
                                               gint row, gint column);
 
   gboolean  (* set_string) (GSheetModel *sheet_model, 
@@ -118,7 +121,7 @@
 GType              g_sheet_model_get_type   (void) G_GNUC_CONST;
 
 
-inline const gchar * g_sheet_model_get_string (const GSheetModel *sheet_model, 
+inline  gchar * g_sheet_model_get_string (const GSheetModel *sheet_model, 
                                               gint row, gint column);
 
 inline gboolean  g_sheet_model_set_string (GSheetModel *sheet_model, 
@@ -163,6 +166,7 @@
 inline const GtkSheetCellBorder * g_sheet_model_get_cell_border 
                    (const GSheetModel *model, gint row, gint column);
 
+inline  gboolean g_sheet_model_free_strings (const GSheetModel *sheet_model);
 
 
 
Index: pspp/lib/gtksheet/gtksheet.c
diff -u pspp/lib/gtksheet/gtksheet.c:1.4 pspp/lib/gtksheet/gtksheet.c:1.5
--- pspp/lib/gtksheet/gtksheet.c:1.4    Thu May 11 14:28:02 2006
+++ pspp/lib/gtksheet/gtksheet.c        Sun May 14 00:01:39 2006
@@ -1,4 +1,4 @@
-/* This version of GtkSheet has been heavily modified, for the specific 
+/* This version of GtkSheet has been *heavily* modified, for the specific 
    requirements of PSPPIRE. */
 
 /* GtkSheet widget for Gtk+.
@@ -101,8 +101,19 @@
 #define DEFAULT_COLUMN_WIDTH 80
 
 
+static gboolean gtk_sheet_cell_empty (const GtkSheet *sheet, gint row, gint 
col);
 
+static inline
+void dispose_string (const GtkSheet *sheet, gchar *text)
+{
+  GSheetModel *model  = gtk_sheet_get_model(sheet);
 
+  if ( ! model ) 
+    return;
+
+  if (g_sheet_model_free_strings(model))
+    g_free(text);
+}
 
 static inline 
 guint DEFAULT_ROW_HEIGHT(GtkWidget *widget) 
@@ -1488,21 +1499,23 @@
   g_return_if_fail (GTK_IS_SHEET (sheet));
   if (column >= xxx_column_count(sheet) || column < 0) return;
 
-  for (row = 0; row < yyy_row_count(sheet); row++){
-    const gchar *text = gtk_sheet_cell_get_text(sheet, row, column);
-    if (text && strlen(text) > 0){
-      GtkSheetCellAttr attributes;
-
-      gtk_sheet_get_attributes(sheet, row, column, &attributes);
-      if(attributes.is_visible){
-        gint width = STRING_WIDTH(GTK_WIDGET(sheet),
-                                  attributes.font_desc,
-                                 text)
-                   + 2*CELLOFFSET + attributes.border.width;
-        text_width = MAX (text_width, width);
+  for (row = 0; row < yyy_row_count(sheet); row++)
+    {
+      gchar *text = gtk_sheet_cell_get_text(sheet, row, column);
+      if (text && strlen(text) > 0){
+       GtkSheetCellAttr attributes;
+
+       gtk_sheet_get_attributes(sheet, row, column, &attributes);
+       if(attributes.is_visible){
+         gint width = STRING_WIDTH(GTK_WIDGET(sheet),
+                                   attributes.font_desc,
+                                   text)
+           + 2*CELLOFFSET + attributes.border.width;
+         text_width = MAX (text_width, width);
+       }
       }
+      dispose_string(sheet, text);
     }
-  }
 
   if(text_width > xxx_column_width(sheet, column) )
     {
@@ -3054,7 +3067,7 @@
   PangoContext *context = gtk_widget_get_pango_context(GTK_WIDGET(sheet)); 
   gint ascent, descent, y_pos;
 
-  const gchar *label;
+  gchar *label;
 
   g_return_if_fail (sheet != NULL);
 
@@ -3091,6 +3104,7 @@
   clip_area = area;
 
   layout = gtk_widget_create_pango_layout (GTK_WIDGET(sheet), label);
+  dispose_string(sheet, label);
   pango_layout_set_font_description (layout, attributes.font_desc);
 
   pango_layout_get_pixel_extents (layout, NULL, &rect);
@@ -3130,7 +3144,7 @@
           area.x+=area.width;
           if(!gtk_sheet_clip_text(sheet)){          
            for(i=col-1; i>=MIN_VISIBLE_COLUMN(sheet); i--){
-             if(gtk_sheet_cell_get_text(sheet, row, i)) break;
+             if( !gtk_sheet_cell_empty(sheet, row, i)) break;
              if(size>=text_width+CELLOFFSET) break;
              size+=xxx_column_width(sheet, i);
             xxx_column_set_right_column(sheet, i, 
@@ -3149,7 +3163,7 @@
          area.x+=area.width/2;
           if(!gtk_sheet_clip_text(sheet)){          
            for(i=col+1; i<=MAX_VISIBLE_COLUMN(sheet); i++){
-             if(gtk_sheet_cell_get_text(sheet, row, i)) break;
+             if( ! gtk_sheet_cell_empty(sheet, row, i)) break;
              if(sizer>=text_width/2) break;
              sizer+= xxx_column_width(sheet, i);
             xxx_column_set_left_column(sheet, i, 
@@ -3158,7 +3172,7 @@
                                            xxx_column_left_column(sheet, i)));
            }
            for(i=col-1; i>=MIN_VISIBLE_COLUMN(sheet); i--){
-             if(gtk_sheet_cell_get_text(sheet, row, i)) break;
+             if( ! gtk_sheet_cell_empty(sheet, row, i)) break;
              if(sizel>=text_width/2) break;
              sizel+=xxx_column_width(sheet, i);
             xxx_column_set_right_column(sheet, i, 
@@ -3176,7 +3190,7 @@
           size=area.width;
           if(!gtk_sheet_clip_text(sheet)){          
            for(i=col+1; i<=MAX_VISIBLE_COLUMN(sheet); i++){
-             if(gtk_sheet_cell_get_text(sheet, row, i)) break;
+             if(! gtk_sheet_cell_empty(sheet, row, i)) break;
              if(size>=text_width+CELLOFFSET) break;
              size+=xxx_column_width(sheet, i);
             xxx_column_set_left_column(sheet, i, 
@@ -3506,7 +3520,7 @@
 {
   GSheetModel *model ;
   gboolean changed ;
-  const gchar *old_text ; 
+  gchar *old_text ; 
 
   GtkSheetRange range;
   gint text_width;
@@ -3530,14 +3544,19 @@
   if (0 != safe_strcmp(old_text, text))
     changed = g_sheet_model_set_string(model, text, row, col);
 
+  if ( g_sheet_model_free_strings(model))
+    g_free(old_text);
+
+
   if(changed && attributes.is_visible)
     {
-      const gchar *s = gtk_sheet_cell_get_text(sheet, row, col);
+      gchar *s = gtk_sheet_cell_get_text(sheet, row, col);
       text_width = 0;
       if(s && strlen(s) > 0) {
        text_width = STRING_WIDTH(GTK_WIDGET(sheet), 
                                  attributes.font_desc, text);
       }
+      dispose_string(sheet, s);
 
     range.row0 = row;
     range.rowi = row;
@@ -3609,7 +3628,7 @@
 {
   GSheetModel *model =  gtk_sheet_get_model(sheet);
 
-  const gchar *old_text = gtk_sheet_cell_get_text(sheet, row, column); 
+  gchar *old_text = gtk_sheet_cell_get_text(sheet, row, column); 
  
   if (old_text && strlen(old_text) > 0 )
     {
@@ -3620,6 +3639,7 @@
                        row, column);
     }  
 
+  dispose_string (sheet, old_text);
 }
     
 void
@@ -3670,8 +3690,21 @@
 }
 
 
-const gchar *     
-gtk_sheet_cell_get_text (GtkSheet *sheet, gint row, gint col)
+static gboolean
+gtk_sheet_cell_empty (const GtkSheet *sheet, gint row, gint col)
+{
+  gboolean empty;
+  char *text = gtk_sheet_cell_get_text(sheet, row, col);
+  empty = (text == NULL );
+ 
+  dispose_string(sheet, text);
+
+  return empty;
+}
+
+
+gchar *     
+gtk_sheet_cell_get_text (const GtkSheet *sheet, gint row, gint col)
 {
   GSheetModel *model;
   g_return_val_if_fail (sheet != NULL, NULL);
@@ -4051,9 +4084,9 @@
  if(gtk_sheet_justify_entry(sheet))
       justification = attributes.justification;
 
- text = g_strdup(gtk_sheet_cell_get_text(sheet, row, col));
-
- if(!text) text = g_strdup("");
+ text = gtk_sheet_cell_get_text(sheet, row, col);
+ if ( ! text ) 
+        text = g_strdup("");
 
  gtk_entry_set_visibility(GTK_ENTRY(sheet_entry), attributes.is_visible);
 
@@ -4081,7 +4114,7 @@
 
  gtk_widget_grab_focus(GTK_WIDGET(sheet_entry));
 
- g_free(text);
+ dispose_string(sheet, text);
 }
 
 static void
@@ -6431,10 +6464,10 @@
      shadow_type = GTK_SHADOW_OUT;
 
   if(state != GTK_STATE_NORMAL && state != GTK_STATE_INSENSITIVE)
-  gtk_paint_box (sheet->button->style, window,
-                 button->state, shadow_type, 
-                 &allocation, GTK_WIDGET(sheet->button),
-                 "button", x, y, width, height);
+    gtk_paint_box (sheet->button->style, window,
+                  button->state, shadow_type, 
+                  &allocation, GTK_WIDGET(sheet->button),
+                  "button", x, y, width, height);
 
   if(button->label_visible){
 
Index: pspp/lib/gtksheet/gtksheet.h
diff -u pspp/lib/gtksheet/gtksheet.h:1.2 pspp/lib/gtksheet/gtksheet.h:1.3
--- pspp/lib/gtksheet/gtksheet.h:1.2    Thu May 11 14:28:02 2006
+++ pspp/lib/gtksheet/gtksheet.h        Sun May 14 00:01:39 2006
@@ -540,8 +540,8 @@
                                        gint row, gint col,
                                        const gchar *text);
 /* get cell contents */
-const gchar *     
-gtk_sheet_cell_get_text                (GtkSheet *sheet, gint row, gint col);
+gchar *     
+gtk_sheet_cell_get_text                (const GtkSheet *sheet, gint row, gint 
col);
 
 /* clear cell contents */
 void 
Index: pspp/src/ui/gui/ChangeLog
diff -u pspp/src/ui/gui/ChangeLog:1.11 pspp/src/ui/gui/ChangeLog:1.12
--- pspp/src/ui/gui/ChangeLog:1.11      Thu May 11 14:28:03 2006
+++ pspp/src/ui/gui/ChangeLog   Sun May 14 00:01:39 2006
@@ -1,3 +1,11 @@
+Sat May 13 08:00:50 WST 2006 John Darrington <address@hidden>
+
+       * data-sheet.c, helper.c, helper.h, psppire-data-store.c, 
+          psppire-var-store.c:
+         
+         Set free_strings flag so that the gtksheet frees the string data 
+         when it's done with them.
+
 Thu May 11 22:25:49 WST 2006 John Darrington <address@hidden>
 
        * data-sheet.c helper.c helper.h psppire-data-store.c 
psppire-var-store.c 
Index: pspp/src/ui/gui/data-sheet.c
diff -u pspp/src/ui/gui/data-sheet.c:1.4 pspp/src/ui/gui/data-sheet.c:1.5
--- pspp/src/ui/gui/data-sheet.c:1.4    Thu May 11 14:28:03 2006
+++ pspp/src/ui/gui/data-sheet.c        Sun May 14 00:01:39 2006
@@ -85,7 +85,7 @@
 
 /* Update the data_ref_entry with the reference of the active cell */
 static gint 
-update_data_ref_entry(GtkSheet *sheet, gint row, gint col)
+update_data_ref_entry(const GtkSheet *sheet, gint row, gint col)
 {
 
   /* The entry where the reference to the current cell is displayed */
Index: pspp/src/ui/gui/helper.c
diff -u pspp/src/ui/gui/helper.c:1.4 pspp/src/ui/gui/helper.c:1.5
--- pspp/src/ui/gui/helper.c:1.4        Thu May 11 14:28:03 2006
+++ pspp/src/ui/gui/helper.c    Sun May 14 00:01:39 2006
@@ -77,12 +77,12 @@
 }
 
 /* Converts a string in the pspp locale to utf-8 */
-const char *
+char *
 pspp_locale_to_utf8(const gchar *text, gssize len, GError **err)
 {
   GError *tmp_error = 0;
 
-  const gchar *s;
+  gchar *s;
 
   if ( ! text ) 
     return 0;
Index: pspp/src/ui/gui/helper.h
diff -u pspp/src/ui/gui/helper.h:1.3 pspp/src/ui/gui/helper.h:1.4
--- pspp/src/ui/gui/helper.h:1.3        Thu May 11 14:28:03 2006
+++ pspp/src/ui/gui/helper.h    Sun May 14 00:01:39 2006
@@ -39,7 +39,7 @@
 GtkWidget * get_widget_assert(GladeXML *xml, const gchar *name);
 
 /* Converts a string in the pspp locale to utf-8 */
-const char * pspp_locale_to_utf8(const gchar *text, gssize len, GError **err);
+char * pspp_locale_to_utf8(const gchar *text, gssize len, GError **err);
 
 
 #endif
Index: pspp/src/ui/gui/psppire-data-store.c
diff -u pspp/src/ui/gui/psppire-data-store.c:1.7 
pspp/src/ui/gui/psppire-data-store.c:1.8
--- pspp/src/ui/gui/psppire-data-store.c:1.7    Thu May 11 14:28:03 2006
+++ pspp/src/ui/gui/psppire-data-store.c        Sun May 14 00:01:39 2006
@@ -29,6 +29,7 @@
 
 #include "psppire-variable.h"
 #include "psppire-data-store.h"
+#include "helper.h"
 
 #include <data/dictionary.h>
 #include <data/missing-values.h>
@@ -147,6 +148,7 @@
 static void
 psppire_data_store_sheet_model_init (GSheetModelIface *iface)
 {
+  iface->free_strings = TRUE;
   iface->get_string = psppire_data_store_get_string;
   iface->set_string = psppire_data_store_set_string;
   iface->clear_datum = psppire_data_store_clear_datum;
Index: pspp/src/ui/gui/psppire-var-store.c
diff -u pspp/src/ui/gui/psppire-var-store.c:1.5 
pspp/src/ui/gui/psppire-var-store.c:1.6
--- pspp/src/ui/gui/psppire-var-store.c:1.5     Thu May 11 14:28:03 2006
+++ pspp/src/ui/gui/psppire-var-store.c Sun May 14 00:01:39 2006
@@ -199,6 +199,7 @@
 static void
 psppire_var_store_sheet_model_init (GSheetModelIface *iface)
 {
+  iface->free_strings = TRUE;
   iface->get_string = psppire_var_store_get_string;
   iface->set_string = psppire_var_store_set_string;
   iface->clear_datum = psppire_var_store_clear;




reply via email to

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