Added a dict parameter to data_in and dealt with the consequences.
[pspp-builds.git] / src / ui / gui / find-dialog.c
index 3c54cac4cc554bfce3cb717efd516b95421fda9b..f24bdbd0d87a577e54c146568dcfcc4564bc5853 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2007  Free Software Foundation
+   Copyright (C) 2007, 2009  Free Software Foundation
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -24,7 +24,7 @@ which match particular strings */
 #include "psppire-selector.h"
 #include "psppire-dialog.h"
 #include "helper.h"
-#include "data-editor.h"
+#include "psppire-data-window.h"
 #include "dict-display.h"
 #include <data/value.h>
 #include <data/format.h>
@@ -37,7 +37,6 @@ which match particular strings */
 #include <libpspp/message.h>
 
 #include <gtk/gtk.h>
-#include <glade/glade.h>
 #include <stdlib.h>
 
 #include "xalloc.h"
@@ -52,10 +51,10 @@ which match particular strings */
 
 struct find_dialog
 {
-  GladeXML *xml;
+  GtkBuilder *xml;
   PsppireDict *dict;
   struct datasheet *data;
-  struct data_editor *de;
+  PsppireDataWindow *de;
   GtkWidget *variable_entry;
   GtkWidget *value_entry;
   GtkWidget *value_labels_checkbox;
@@ -186,7 +185,7 @@ value_labels_toggled (GtkToggleButton *tb, gpointer data)
 void
 find_dialog (GObject *o, gpointer data)
 {
-  struct data_editor *de = data;
+  PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
 
   struct find_dialog fd;
 
@@ -200,7 +199,7 @@ find_dialog (GObject *o, gpointer data)
   PsppireVarStore *vs ;
   PsppireDataStore *ds ;
 
-  fd.xml = XML_NEW ("psppire.glade");
+  fd.xml = builder_new ("find.ui");
   fd.de = de;
 
   find_button = gtk_button_new_from_stock  (GTK_STOCK_FIND);
@@ -221,7 +220,7 @@ find_dialog (GObject *o, gpointer data)
                NULL);
 
   fd.dict = vs->dict;
-  fd.data = ds->case_file->datasheet;
+  fd.data = ds->datasheet;
 
   fd.variable_entry        = get_widget_assert (fd.xml, "find-variable-entry");
   fd.value_entry           = get_widget_assert (fd.xml, "find-value-entry");
@@ -239,13 +238,12 @@ find_dialog (GObject *o, gpointer data)
 
 
 
-  gtk_window_set_transient_for (GTK_WINDOW (dialog), de->parent.window);
+  gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de));
 
 
-  attach_dictionary_to_treeview (GTK_TREE_VIEW (source),
-                                fd.dict,
-                                GTK_SELECTION_SINGLE,
-                                NULL);
+  g_object_set (source, "dictionary", fd.dict,
+       "selection-mode", GTK_SELECTION_SINGLE,
+       NULL);
 
   psppire_selector_set_subjects (PSPPIRE_SELECTOR (selector),
                                 source,
@@ -287,7 +285,7 @@ forward (casenumber *i, struct datasheet *data UNUSED)
 static void
 forward_wrap (casenumber *i, struct datasheet *data)
 {
-  if ( ++*i >=  datasheet_get_row_cnt (data) ) *i = 0;
+  if ( ++*i >=  datasheet_get_n_rows (data) ) *i = 0;
 }
 
 static void
@@ -301,7 +299,7 @@ static void
 backward_wrap (casenumber *i, struct datasheet *data)
 {
   if ( --*i < 0 )
-    *i = datasheet_get_row_cnt (data) - 1;
+    *i = datasheet_get_n_rows (data) - 1;
 }
 
 
@@ -346,7 +344,7 @@ cm1c (casenumber current, struct datasheet *data)
 static casenumber
 last (casenumber current, struct datasheet *data)
 {
-  return datasheet_get_row_cnt (data) ;
+  return datasheet_get_n_rows (data) ;
 }
 
 static casenumber
@@ -441,7 +439,7 @@ struct comparator
 struct value_comparator
 {
   struct comparator parent;
-  union value *pattern;
+  union value pattern;
 };
 
 /* A comparator which matches string values or parts thereof */
@@ -464,7 +462,7 @@ value_compare (const struct comparator *cmptr,
               const union value *v)
 {
   const struct value_comparator *vc = (const struct value_comparator *) cmptr;
-  return 0 == compare_values_short (v, vc->pattern, cmptr->var);
+  return 0 == value_compare_3way (v, &vc->pattern, var_get_width (cmptr->var));
 }
 
 
@@ -497,8 +495,8 @@ string_value_compare (const struct comparator *cmptr,
   const struct string_comparator *ssc =
     (const struct string_comparator *) cmptr;
 
-  const char *text = val->s;
   int width = var_get_width (cmptr->var);
+  const char *text = value_str (val, width);
 
   assert ( ! (cmptr->flags & STR_CMP_LABELS));
 
@@ -530,7 +528,7 @@ regexp_value_compare (const struct comparator *cmptr,
 
   /* We must remove trailing whitespace, otherwise $ will not match where
      one would expect */
-  text = g_strndup (val->s, width);
+  text = g_strndup (value_str (val, width), width);
   g_strchomp (text);
 
   retval = (0 == regexec (&rec->re, text, 0, 0, 0));
@@ -572,10 +570,10 @@ regexp_destroy (struct comparator *cmptr)
 }
 
 static void
-value_destroy (struct comparator *cmptr)
+cmptr_value_destroy (struct comparator *cmptr)
 {
   struct value_comparator *vc = (struct value_comparator *) cmptr;
-  free (vc->pattern);
+  value_destroy (&vc->pattern, var_get_width (cmptr->var));
 }
 
 
@@ -590,19 +588,21 @@ value_comparator_create (const struct variable *var, const char *target)
   cmptr->flags = 0;
   cmptr->var = var;
   cmptr->compare  = value_compare ;
-  cmptr->destroy = value_destroy;
+  cmptr->destroy = cmptr_value_destroy;
 
   width = var_get_width (var);
   fmt = var_get_write_format (var);
 
-  vc->pattern = value_create (width);
+  value_init (&vc->pattern, width);
 
   if ( ! data_in (ss_cstr (target),
                   LEGACY_NATIVE,
                  fmt->type,
                  0, 0, 0,
-                 vc->pattern, width) )
+                 NULL,
+                 &vc->pattern, width) )
     {
+      value_destroy (&vc->pattern, width);
       free (vc);
       return NULL;
     }
@@ -741,12 +741,13 @@ find_value (const struct find_dialog *fd, casenumber current_row,
     flags |= STR_CMP_LABELS;
 
   {
-    union value *val = value_create (width);
+    union value val;
     casenumber i;
     const struct casenum_iterator *ip = get_iteration_params (fd);
     struct comparator *cmptr =
       comparator_factory (var, target_string, flags);
 
+    value_init (&val, width);
     if ( ! cmptr)
       goto finish;
 
@@ -754,10 +755,9 @@ find_value (const struct find_dialog *fd, casenumber current_row,
         i != ip->end (current_row, fd->data);
         ip->next (&i, fd->data))
       {
-       datasheet_get_value (fd->data, i, var_get_case_index (var),
-                            val, width);
+       datasheet_get_value (fd->data, i, var_get_case_index (var), &val);
 
-       if ( comparator_compare (cmptr, val))
+       if ( comparator_compare (cmptr, &val))
          {
            *row = i;
            break;
@@ -766,6 +766,6 @@ find_value (const struct find_dialog *fd, casenumber current_row,
 
   finish:
     comparator_destroy (cmptr);
-    free (val);
+    value_destroy (&val, width);
   }
 }