New file: builder-wrapper.h and builder-wrapper.c
[pspp-builds.git] / src / ui / gui / find-dialog.c
index 3d3aed8813c9628b672bd6d853d9385af7caec41..0f856f94629d29c58383d9a1fc3d078015b47bf4 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2007, 2009  Free Software Foundation
+   Copyright (C) 2007, 2009, 2011, 2012  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
@@ -23,6 +23,7 @@ which match particular strings */
 #include "find-dialog.h"
 #include "psppire-selector.h"
 #include "psppire-dialog.h"
+#include "builder-wrapper.h"
 #include "helper.h"
 #include "psppire-data-window.h"
 #include "dict-display.h"
@@ -184,10 +185,8 @@ value_labels_toggled (GtkToggleButton *tb, gpointer data)
 /* Pops up the Find dialog box
  */
 void
-find_dialog (GObject *o, gpointer data)
+find_dialog (PsppireDataWindow *de)
 {
-  PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
-
   struct find_dialog fd;
 
   GtkWidget *dialog ;
@@ -208,7 +207,7 @@ find_dialog (GObject *o, gpointer data)
 
   buttonbox = get_widget_assert (fd.xml, "find-buttonbox");
 
-  gtk_box_pack_start_defaults (GTK_BOX (buttonbox), find_button);
+  psppire_box_pack_start_defaults (GTK_BOX (buttonbox), find_button);
   gtk_box_reorder_child (GTK_BOX (buttonbox), find_button, 0);
 
   dialog = get_widget_assert (fd.xml, "find-dialog");
@@ -220,7 +219,8 @@ find_dialog (GObject *o, gpointer data)
                "data-store", &ds,
                NULL);
 
-  fd.dict = vs->dict;
+  g_object_get (vs, "dictionary", &fd.dict, NULL);
+
   fd.data = ds->datasheet;
 
   fd.variable_entry        = get_widget_assert (fd.xml, "find-variable-entry");
@@ -242,17 +242,13 @@ find_dialog (GObject *o, gpointer data)
   gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de));
 
 
-  g_object_set (source, "dictionary", fd.dict,
+  g_object_set (source, "model", fd.dict,
        "selection-mode", GTK_SELECTION_SINGLE,
        NULL);
 
-  psppire_selector_set_subjects (PSPPIRE_SELECTOR (selector),
-                                source,
-                                fd.variable_entry,
-                                insert_source_row_into_entry,
-                                is_currently_in_entry,
-                                NULL
-                                );
+
+  psppire_selector_set_filter_func (PSPPIRE_SELECTOR (selector),
+                                   is_currently_in_entry);
 
   g_signal_connect (dialog, "refresh", G_CALLBACK (refresh),  &fd);
 
@@ -493,20 +489,24 @@ static bool
 string_value_compare (const struct comparator *cmptr,
                      const union value *val)
 {
+  bool found;
+  char *text;
   const struct string_comparator *ssc =
     (const struct string_comparator *) cmptr;
 
   int width = var_get_width (cmptr->var);
-  const char *text = value_str (val, width);
-
+  g_return_val_if_fail (width > 0, false);
   assert ( ! (cmptr->flags & STR_CMP_LABELS));
 
-  g_return_val_if_fail (width > 0, false);
+  text = value_to_text (*val, cmptr->var);
 
   if ( cmptr->flags & STR_CMP_SUBSTR)
-    return (NULL != g_strstr_len (text, width, ssc->pattern));
+    found =  (NULL != g_strstr_len (text, width, ssc->pattern));
   else
-    return (0 == strncmp (text, ssc->pattern, width));
+    found = (0 == strncmp (text, ssc->pattern, width));
+
+  free (text);
+  return found;
 }
 
 
@@ -527,9 +527,9 @@ regexp_value_compare (const struct comparator *cmptr,
 
   g_return_val_if_fail (width > 0, false);
 
+  text = value_to_text (*val, cmptr->var);
   /* We must remove trailing whitespace, otherwise $ will not match where
      one would expect */
-  text = g_strndup (value_str (val, width), width);
   g_strchomp (text);
 
   retval = (0 == regexec (&rec->re, text, 0, 0, 0));
@@ -583,8 +583,6 @@ cmptr_value_destroy (struct comparator *cmptr)
 static struct comparator *
 value_comparator_create (const struct variable *var, const char *target)
 {
-  const struct fmt_spec *fmt;
-  int width ;
   struct value_comparator *vc = xzalloc (sizeof (*vc));
   struct comparator *cmptr = &vc->parent;
 
@@ -593,21 +591,7 @@ value_comparator_create (const struct variable *var, const char *target)
   cmptr->compare  = value_compare ;
   cmptr->destroy = cmptr_value_destroy;
 
-  width = var_get_width (var);
-  fmt = var_get_write_format (var);
-
-  value_init (&vc->pattern, width);
-
-  if ( ! data_in (ss_cstr (target),
-                  LEGACY_NATIVE,
-                 fmt->type,
-                 0, 0, 0,
-                 &vc->pattern, width) )
-    {
-      value_destroy (&vc->pattern, width);
-      free (vc);
-      return NULL;
-    }
+  text_to_value (target, var, &vc->pattern);
 
   return cmptr;
 }