/[pspp]/psppire/src/data_sheet.c
ViewVC logotype

Diff of /psppire/src/data_sheet.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.14 by jmd, Fri Nov 4 06:26:18 2005 UTC revision 1.15 by jmd, Fri Nov 4 23:56:46 2005 UTC
# Line 1  Line 1 
1  /*  /*
2      PSPPIRE --- A Graphical User Interface for PSPP     PSPPIRE --- A Graphical User Interface for PSPP
3      Copyright (C) 2004  Free Software Foundation     Copyright (C) 2004  Free Software Foundation
4      Written by John Darrington     Written by John Darrington
5    
6      This program is free software; you can redistribute it and/or modify     This program is free software; you can redistribute it and/or modify
7      it under the terms of the GNU General Public License as published by     it under the terms of the GNU General Public License as published by
8      the Free Software Foundation; either version 2 of the License, or     the Free Software Foundation; either version 2 of the License, or
9      (at your option) any later version.     (at your option) any later version.
10    
11      This program is distributed in the hope that it will be useful,     This program is distributed in the hope that it will be useful,
12      but WITHOUT ANY WARRANTY; without even the implied warranty of     but WITHOUT ANY WARRANTY; without even the implied warranty of
13      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14      GNU General Public License for more details.     GNU General Public License for more details.
15    
16      You should have received a copy of the GNU General Public License     You should have received a copy of the GNU General Public License
17      along with this program; if not, write to the Free Software     along with this program; if not, write to the Free Software
18      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19      02110-1301, USA. */     02110-1301, USA. */
20    
21  #include <psppire-conf.h>  #include <psppire-conf.h>
22    
# Line 32  Line 32 
32  #define _(A) A  #define _(A) A
33  #define N_(A) A  #define N_(A) A
34    
 static GdkColor colour_enabled;  
 static GdkColor colour_disabled;  
35    
36  static PSPP_Dict *pspp_dictionary ;  static PSPP_Dict *pspp_dictionary ;
37    
38    static gint last_populated_row = -1;
 /* Enable/Disable columns in the data sheet  
    sheet : The sheet to enable  
    col1: Starting column  
    col2: Ending column  
    enabled: TRUE if enabling FALSE if disabling  
 */  
 void  
 psppire_data_sheet_col_set_enable(GtkSheet *sheet, gint col1, gint col2,  
                                   gboolean enabled)  
 {  
   
   GtkSheetRange range;  
   
   range.row0=0;  
   range.rowi= gtk_sheet_get_rows_count(sheet) - 1 ;  
     
   range.col0 = col1;  
   range.coli = col2;  
   
   gtk_sheet_range_set_background (GTK_SHEET(sheet),  
                                   &range,  
                                   enabled?&colour_enabled:&colour_disabled);  
   
   gtk_sheet_range_set_editable (GTK_SHEET(sheet),  
                                 &range,  
                                 enabled);  
 }  
39    
40    
41  /* Return the width that an  'M' character would occupy when typeset at  /* Return the width that an  'M' character would occupy when typeset at
# Line 96  static guint Line 67  static guint
67  columnWidthToPixels(GtkSheet *sheet, gint column, guint width)  columnWidthToPixels(GtkSheet *sheet, gint column, guint width)
68  {  {
69    return (M_width(sheet, 1, column) * width);    return (M_width(sheet, 1, column) * width);
   
70  }  }
71    
72    
73    static gint
74    data_sheet_set_cell(GtkSheet *sheet, gint row, gint col)
75    {
76      gint r;
77    
78      const gint cols = pspp_dict_get_var_cnt(pspp_dictionary);
79    
80    
81      for ( r = last_populated_row + 1; r < row ; ++r )
82        {
83          gint c;
84          for ( c = 0 ; c < cols ; ++c )
85            gtk_sheet_set_cell_text (sheet, r, c, " ~. ");
86        }
87      if ( row > last_populated_row)
88        last_populated_row = row;
89    }
90    
91  /* Update COLUMN of the data sheet */  /* Update COLUMN of the data sheet */
92  static gint  static gint
# Line 107  update_variable(GObject *obj, gint colum Line 94  update_variable(GObject *obj, gint colum
94  {  {
95    PSPP_Dict *dict = PSPP_DICT(obj);    PSPP_Dict *dict = PSPP_DICT(obj);
96    
97      GtkSheetRange range;
98    GtkSheet *sheet = GTK_SHEET(data);    GtkSheet *sheet = GTK_SHEET(data);
99    
100    struct variable *var = pspp_dict_get_var(dict, column);    struct variable *var = pspp_dict_get_var(dict, column);
101    
102      range.row0 = 0; range.rowi = gtk_sheet_get_columns_count(sheet) - 1;
103      range.col0 = range.coli = column;
104      gtk_sheet_range_set_editable(sheet, &range, TRUE);
105    
106    gtk_sheet_column_button_add_label(sheet, column, var->name);    gtk_sheet_column_button_add_label(sheet, column, var->name);
107    
108    
109    gtk_sheet_set_column_width (sheet, column,    gtk_sheet_set_column_width (sheet, column,
110                                columnWidthToPixels(sheet, column,                                columnWidthToPixels(sheet, column,
111                                                    var->display_width));                                                    var->display_width));
   
   
   psppire_data_sheet_col_set_enable(sheet, column, column, TRUE);  
   
112    return FALSE;    return FALSE;
113  }  }
114    
# Line 132  repopulate_columns(GtkSheet *sheet, PSPP Line 121  repopulate_columns(GtkSheet *sheet, PSPP
121  {  {
122    gint col;    gint col;
123    
124    
125    for ( col = from ; col <= to ; ++col )    for ( col = from ; col <= to ; ++col )
126      {      {
127        if ( col < pspp_dict_get_var_cnt(dict))        if ( col < pspp_dict_get_var_cnt(dict))
# Line 142  repopulate_columns(GtkSheet *sheet, PSPP Line 132  repopulate_columns(GtkSheet *sheet, PSPP
132            gtk_sheet_set_column_width (sheet, col,            gtk_sheet_set_column_width (sheet, col,
133                                        columnWidthToPixels(sheet, col,                                        columnWidthToPixels(sheet, col,
134                                                            var->display_width));                                                            var->display_width));
   
           psppire_data_sheet_col_set_enable(sheet, col, col, TRUE);  
135          }          }
136        else        else
137          {          {
# Line 157  repopulate_columns(GtkSheet *sheet, PSPP Line 145  repopulate_columns(GtkSheet *sheet, PSPP
145    
146            /* Clear the column which relates to variables no longer valid,            /* Clear the column which relates to variables no longer valid,
147               and disable them               and disable them
148             */            */
149            gtk_sheet_range_clear (sheet, &this_column);            gtk_sheet_range_clear (sheet, &this_column);
150            psppire_data_sheet_col_set_enable(sheet, col, col, FALSE);            gtk_sheet_range_set_editable(sheet, &this_column, FALSE);
151              gtk_sheet_set_column_width(sheet, col, 80);
152          }          }
153      }      }
154  }  }
# Line 176  remove_variable(GObject *obj, gint colum Line 165  remove_variable(GObject *obj, gint colum
165    
166        
167    gtk_sheet_delete_columns (sheet, column, 1);    gtk_sheet_delete_columns (sheet, column, 1);
168      gtk_sheet_add_column(sheet, 1);
169    
170    repopulate_columns(sheet, dict, column,    repopulate_columns(sheet, dict, column,
171                    gtk_sheet_get_columns_count(sheet) - 1);                       gtk_sheet_get_columns_count(sheet) - 1);
172    
173    return FALSE;    return FALSE;
174  }  }
# Line 211  psppire_data_sheet_clear(GtkSheet *sheet Line 201  psppire_data_sheet_clear(GtkSheet *sheet
201    /* get rid of all the cells */    /* get rid of all the cells */
202    gtk_sheet_range_clear (sheet, NULL);    gtk_sheet_range_clear (sheet, NULL);
203    
204    
205      last_populated_row = -1;
206    
207    repopulate_columns(sheet, pspp_dictionary, 0,    repopulate_columns(sheet, pspp_dictionary, 0,
208                       gtk_sheet_get_columns_count(sheet) - 1);                       gtk_sheet_get_columns_count(sheet) - 1);
   
209  }  }
210    
211    
# Line 232  psppire_data_sheet_set_dictionary(GtkWid Line 224  psppire_data_sheet_set_dictionary(GtkWid
224  }  }
225    
226    
227    
228  GtkWidget*  GtkWidget*
229  psppire_data_sheet_create (gchar *widget_name, gchar *string1, gchar *string2,  psppire_data_sheet_create (gchar *widget_name, gchar *string1, gchar *string2,
230                  gint int1, gint int2)                             gint int1, gint int2)
231  {  {
232    GtkWidget *sheet;    GtkWidget *sheet;
233    gint i;    gint i;
# Line 242  psppire_data_sheet_create (gchar *widget Line 235  psppire_data_sheet_create (gchar *widget
235    const gint columns=10;    const gint columns=10;
236    const gint rows=46;    const gint rows=46;
237    
238    
239    
240    GtkSheetRange entire_sheet= {0,0,0,0};    GtkSheetRange entire_sheet= {0,0,0,0};
241    entire_sheet.rowi = rows - 1;    entire_sheet.rowi = rows - 1;
242    entire_sheet.coli = columns - 1;    entire_sheet.coli = columns - 1;
243    
244    sheet = gtk_sheet_new(rows, columns, "data sheet");    sheet = gtk_sheet_new(rows, columns, "data sheet");
245    
   g_assert(gdk_color_parse("dark slate gray",&colour_disabled));  
   g_assert(gdk_color_parse("white",&colour_enabled));  
     
   gdk_colormap_alloc_color(gdk_colormap_get_system(),  
                                    &colour_disabled, FALSE, TRUE);  
   
   gdk_colormap_alloc_color(gdk_colormap_get_system(),  
                                    &colour_enabled, FALSE, TRUE);  
   
   
   
   psppire_data_sheet_col_set_enable(GTK_SHEET(sheet),0,columns -1,FALSE);  
   
246    g_signal_connect(sheet, "new_column_width",    g_signal_connect(sheet, "new_column_width",
247                     G_CALLBACK(adjust_column_width), 0);                     G_CALLBACK(adjust_column_width), 0);
248    
# Line 272  psppire_data_sheet_create (gchar *widget Line 254  psppire_data_sheet_create (gchar *widget
254    /* We want to control column widths ourself */    /* We want to control column widths ourself */
255    gtk_sheet_set_autoresize(sheet, FALSE);    gtk_sheet_set_autoresize(sheet, FALSE);
256    
257    gtk_widget_show(sheet);    /* Whilst there's no variables the entire sheet is uneditable */
258      gtk_sheet_range_set_editable(GTK_SHEET(sheet), &entire_sheet, FALSE);
259    
260    
261    return sheet;    g_signal_connect (GTK_OBJECT (sheet), "set_cell",
262                        GTK_SIGNAL_FUNC (data_sheet_set_cell),
263                        0);
264    
265      gtk_widget_show(sheet);
266    
267      return sheet;
268  }  }
269    
270  void  void
# Line 294  psppire_create_system_file(GtkSheet *she Line 282  psppire_create_system_file(GtkSheet *she
282    
283    g_assert(writer);    g_assert(writer);
284    
   
285    gint var_cnt = pspp_dict_get_var_cnt(d);    gint var_cnt = pspp_dict_get_var_cnt(d);
286    
287      for (r = 0 ; r <= last_populated_row ; ++r )
   for (r = 0 ; r < gtk_sheet_get_rows_count(sheet) ; ++r )  
288      {      {
289        struct ccase mycase;        struct ccase mycase;
290        gint c;        gint c;
# Line 322  psppire_create_system_file(GtkSheet *she Line 308  psppire_create_system_file(GtkSheet *she
308            d_in.format = v->write;            d_in.format = v->write;
309            d_in.flags = 0;            d_in.flags = 0;
310    
311            data_in(&d_in);            
312              if ( ! data_in(&d_in) )
313                {
314                  g_print("Cant format string at %d, %d\n",r, c);
315                }
316          }          }
317    
   
318        if ( ! sfm_write_case(writer, &mycase) )        if ( ! sfm_write_case(writer, &mycase) )
319          g_print("Failed to write case %d\n",r);          g_print("Failed to write case %d\n",r);
320    
# Line 333  psppire_create_system_file(GtkSheet *she Line 322  psppire_create_system_file(GtkSheet *she
322    
323      }      }
324    
   
325    sfm_close_writer(writer);    sfm_close_writer(writer);
326  }  }

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.15

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26