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

Diff of /psppire/src/var_sheet.c

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

revision 1.4 by jmd, Tue Oct 25 12:45:29 2005 UTC revision 1.5 by jmd, Wed Oct 26 08:55:09 2005 UTC
# Line 36  Line 36 
36    
37    
38  extern PSPP_Dict *pspp_dictionary;  extern PSPP_Dict *pspp_dictionary;
39    extern GtkWindow *window1;
40    
41    
42  /* The next new row */  /* The next new row */
43  static gint next_new_row=0;  static gint next_new_row=0;
44    
45    
46  void var_sheet_row_open(GtkSheet *sheet,gint row);  static gint var_sheet_update_callback(GObject *obj,
47  void var_sheet_row_close(GtkSheet *sheet,gint row);                                        gint var_idx, gpointer data);
   
   
 /* Update a variable.  
    This callback is invoked whenever a cell on the var_sheet is  
    changed  
 */  
 static gint  
 update_variable(GtkSheet *sheet, gint row, gint col)  
 {  
   g_assert(pspp_dictionary);  
   g_assert(G_IS_PSPP_DICT(pspp_dictionary));  
48    
49    if ( col == 0 )  static gint update_variable(GtkSheet *sheet, gint row, gint col);
     pspp_dict_set_name(pspp_dictionary, row,  
                        gtk_sheet_cell_get_text(sheet, row, col));  
50    
   var_sheet_row_open(sheet, row);  
   
   return FALSE;  
 }  
   
   
   
 /* This callback is invoked whenever a variable in the dictionary  
    has changed.  VAR_IDX is the index of the changed variable. */  
 static gint  
 var_sheet_update_callback(GObject *obj, gint var_idx, gpointer data)  
 {  
   
   PSPP_Dict *dict = PSPP_DICT(obj);  
   GtkSheet *sheet   = GTK_SHEET(data);  
51    
   struct variable *var = g_ptr_array_index(dict->array, var_idx);  
52    
53    gtk_sheet_set_cell_text (sheet, var_idx, 0, var->name);  void var_sheet_row_open(GtkSheet *sheet,gint row);
54    void var_sheet_row_close(GtkSheet *sheet,gint row);
55    
   return FALSE;  
 }  
56    
57    
58  static  GdkColor colour_disabled;  static  GdkColor colour_disabled;
# Line 88  static  GdkColor colour_enabled; Line 60  static  GdkColor colour_enabled;
60    
61  typedef void (*psppire_construct_entry_func) (GtkSheet *sheet);  typedef void (*psppire_construct_entry_func) (GtkSheet *sheet);
62    
63    
64  void psppire_construct_entry(GtkSheet *sheet);  void psppire_construct_entry(GtkSheet *sheet);
65    void psppire_name_entry(GtkSheet *sheet);
66    
67    
68  struct column_parameters  struct column_parameters
# Line 97  struct column_parameters Line 71  struct column_parameters
71    psppire_construct_entry_func cef;    psppire_construct_entry_func cef;
72  };  };
73    
74    const struct column_parameters col[] = {  const struct column_parameters col[] = {
75      N_("Name"),    0,    N_("Name"), 0,
76      N_("Type"), psppire_construct_entry,    N_("Type"), psppire_construct_entry,
77      N_("Width"),   0,    N_("Width"),   0,
78      N_("Decimals"),0,    N_("Decimals"),0,
79      N_("Label"),   0,    N_("Label"),   0,
80      N_("Values"),  0,    N_("Values"),  0,
81      N_("Missing"), 0,    N_("Missing"), 0,
82      N_("Columns"), 0,    N_("Columns"), 0,
83      N_("Align"),   0,    N_("Align"),   0,
84      N_("Measure"), 0    N_("Measure"), 0
85    };  };
86    
87    enum {COL_NAME,
88          COL_TYPE,
89          COL_WIDTH,
90          COL_DECIMALS,
91          COL_LABEL,
92          COL_VALUES,
93          COL_MISSING,
94          COL_COLUMNS,
95          COL_ALIGN,
96          COL_MEASURE,
97          n_COLS};
98    
 static gint exit_column = -1;  
99    
100    #if 1
101    static gint exit_column = -1;
102    
103    
104  /* cell_enter and cell_leave are a pair of mutually cooperating functions  /* cell_enter and cell_leave are a pair of mutually cooperating functions
# Line 142  var_sheet_cell_leave (GtkSheet * sheet, Line 129  var_sheet_cell_leave (GtkSheet * sheet,
129  }  }
130    
131    
132    #endif
133    
134  void  void
135  psppire_construct_entry(GtkSheet *sheet)  psppire_construct_entry(GtkSheet *sheet)
136  {  {
# Line 159  psppire_construct_entry(GtkSheet *sheet) Line 148  psppire_construct_entry(GtkSheet *sheet)
148    gtk_combo_set_popdown_strings (combo, items);    gtk_combo_set_popdown_strings (combo, items);
149    
150    gtk_combo_set_value_in_list(combo,FALSE,FALSE);    gtk_combo_set_value_in_list(combo,FALSE,FALSE);
151    }
152    
153    void
154    psppire_name_entry(GtkSheet *sheet)
155    {
156      GtkEntry *entry;
157      gtk_sheet_change_entry (sheet, GTK_TYPE_ENTRY);
158    
159      entry = GTK_ENTRY(gtk_sheet_get_entry_widget(sheet));
160  }  }
161    
162    
163    
164  static GdkColor colour_enabled;  static GdkColor colour_enabled;
165  static GdkColor colour_disabled;  static GdkColor colour_disabled;
166    
# Line 244  var_sheet_row_close(GtkSheet *sheet,gint Line 243  var_sheet_row_close(GtkSheet *sheet,gint
243    
244  }  }
245    
246    
247    static GString *
248    gint_to_gstring(gint x)
249    {
250      GString *s = g_string_new ("x");
251    
252      g_string_printf (s, "%d",x);
253                
254      return s;
255    }
256    
257    
258    
259    static void
260    populate_row_from_var(GtkSheet *sheet, const struct variable *var,
261                          gint var_idx)
262    {
263      gint c;
264      if (!var)
265        return;
266    
267      for ( c = 0 ; c < n_COLS ; ++c )
268        {
269          switch (c)
270            {
271            case COL_NAME:
272              gtk_sheet_set_cell_text (sheet, var_idx, c, var->name);
273              break;
274            case COL_WIDTH:
275              {
276              GString *s = gint_to_gstring(var->width);
277              gtk_sheet_set_cell_text(sheet, var_idx, c, s->str);    
278              g_string_free(s, TRUE);
279              }
280              break;
281            case COL_COLUMNS:
282              {
283              GString *s = gint_to_gstring(var->display_width);
284              gtk_sheet_set_cell_text(sheet, var_idx, c, s->str);    
285              g_string_free(s, TRUE);
286              }
287              break;
288            }
289        }
290    }
291    
292    
293  /* Repopulate the rows starting at position FROM, to position TO inclusive*/  /* Repopulate the rows starting at position FROM, to position TO inclusive*/
294  static void  static void
295  repopulate_rows(GtkSheet *sheet, PSPP_Dict *dict, gint from, gint to)  repopulate_rows(GtkSheet *sheet, PSPP_Dict *dict, gint from, gint to)
# Line 252  repopulate_rows(GtkSheet *sheet, PSPP_Di Line 298  repopulate_rows(GtkSheet *sheet, PSPP_Di
298    
299    for ( r = from ; r <= to ; ++r )    for ( r = from ; r <= to ; ++r )
300      {      {
301        struct variable *var = g_ptr_array_index(dict->array, r);        
302                if ( r < pspp_dict_get_var_cnt(dict) )
       if ( r < dict->array->len)  
303          {          {
304            gtk_sheet_set_cell_text (sheet, r, 0, var->name);            struct variable *var = pspp_dict_get_var(dict, r);      
305              populate_row_from_var(sheet, var, r);
306          }          }
307        else        else
308          {          {
309            var_sheet_row_close(sheet, r);            var_sheet_row_close(sheet, r);
310          }          }
311      }      }
   
312  }  }
313    
314    
# Line 293  psppire_variable_sheet_create (gchar *wi Line 338  psppire_variable_sheet_create (gchar *wi
338    GtkWidget *entry;    GtkWidget *entry;
339    gint i;    gint i;
340    const gint columns=10;    const gint columns=10;
341    const gint rows= 5;    const gint rows= 25;
342    
343    sheet = gtk_sheet_new(rows,columns,"variable sheet");    sheet = gtk_sheet_new(rows,columns,"variable sheet");
344    
# Line 315  psppire_variable_sheet_create (gchar *wi Line 360  psppire_variable_sheet_create (gchar *wi
360                     G_CALLBACK(remove_variable), sheet);                     G_CALLBACK(remove_variable), sheet);
361    
362    
363      g_signal_connect (GTK_OBJECT (sheet), "activate",
364                        GTK_SIGNAL_FUNC (var_sheet_cell_enter),
365                        0);
366    
367    g_signal_connect (GTK_OBJECT (sheet), "deactivate",    g_signal_connect (GTK_OBJECT (sheet), "deactivate",
368                      GTK_SIGNAL_FUNC (var_sheet_cell_leave),                      GTK_SIGNAL_FUNC (var_sheet_cell_leave),
369                      0);                      0);
370    
371    
   g_signal_connect (GTK_OBJECT (sheet), "activate",  
                     GTK_SIGNAL_FUNC (var_sheet_cell_enter),  
                     0);  
   
372    g_signal_connect (GTK_OBJECT (sheet), "set_cell",    g_signal_connect (GTK_OBJECT (sheet), "set_cell",
373                      GTK_SIGNAL_FUNC (update_variable),                      GTK_SIGNAL_FUNC (update_variable),
374    
375                      0);                      0);
376    
377    for (i = 0 ; i < columns ; ++i )    for (i = 0 ; i < columns ; ++i )
# Line 337  psppire_variable_sheet_create (gchar *wi Line 383  psppire_variable_sheet_create (gchar *wi
383    
384    var_sheet_set_next_row(GTK_SHEET(sheet), 0);    var_sheet_set_next_row(GTK_SHEET(sheet), 0);
385    
   
386    return sheet;    return sheet;
387    
388  }  }
389    
390    
391    
392    
393    /* Update a variable.
394       This callback is invoked whenever a cell on the var_sheet is
395       changed
396    */
397    static gint
398    update_variable(GtkSheet *sheet, gint row, gint col)
399    {
400      g_assert(pspp_dictionary);
401      g_assert(G_IS_PSPP_DICT(pspp_dictionary));
402    
403      struct variable *old_var = pspp_dict_get_var(pspp_dictionary, row);
404      
405    switch (col)
406        {
407        case COL_NAME:
408          {
409            const gchar *name = gtk_sheet_cell_get_text(sheet, row, col);
410    
411            if ( old_var && (0 == strcmp(old_var->name, name)))
412              {
413                g_print("Name hasn't changed\n");
414                return FALSE;
415              }
416    
417            if ( ! var_is_valid_name(name, 0 ) )
418              {
419                g_print("That's not valid\n");
420                if ( old_var)
421                  gtk_sheet_set_cell_text(sheet, row, col, old_var->name);
422                else
423                  gtk_sheet_cell_clear(sheet, row, col);
424              }
425            else if ( pspp_dict_lookup_var(pspp_dictionary, name))
426              {
427                g_print("Duplicate variable name\n");
428                gtk_sheet_set_cell_text(sheet, row, col, old_var->name);
429              }
430            else
431              {
432                g_print("Updating Name to %s\n", name);
433                pspp_dict_set_name(pspp_dictionary, row, name);
434                var_sheet_row_open(sheet, row );
435              }
436          }
437          break;
438        case COL_COLUMNS:
439          old_var->display_width =
440            atoi(gtk_sheet_cell_get_text(sheet, row, col));
441          break;
442        case COL_WIDTH:
443          old_var->width = atoi(gtk_sheet_cell_get_text(sheet, row, col));
444          break;
445        }
446    
447      return FALSE;
448    }
449    
450    
451    
452    /* This callback is invoked whenever a variable in the dictionary
453       has changed.  VAR_IDX is the index of the changed variable. */
454    static gint
455    var_sheet_update_callback(GObject *obj, gint var_idx, gpointer data)
456    {
457      gint c;
458    
459      PSPP_Dict *dict = PSPP_DICT(obj);
460      GtkSheet *sheet   = GTK_SHEET(data);
461    
462      struct variable *var = pspp_dict_get_var(dict, var_idx);
463    
464      populate_row_from_var(sheet, var, var_idx);
465    
466      return FALSE;
467    }

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.5

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