/* 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
#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>
#include <libpspp/message.h>
#include <gtk/gtk.h>
-#include <glade/glade.h>
#include <stdlib.h>
#include "xalloc.h"
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;
void
find_dialog (GObject *o, gpointer data)
{
- struct data_editor *de = data;
+ PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
struct find_dialog fd;
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);
- 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,
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
backward_wrap (casenumber *i, struct datasheet *data)
{
if ( --*i < 0 )
- *i = datasheet_get_row_cnt (data) - 1;
+ *i = datasheet_get_n_rows (data) - 1;
}
static casenumber
last (casenumber current, struct datasheet *data)
{
- return datasheet_get_row_cnt (data) ;
+ return datasheet_get_n_rows (data) ;
}
static casenumber
{
const struct variable *var;
enum string_cmp_flags flags;
+ const PsppireDict *dict;
bool (*compare) (const struct comparator *,
const union value *);
struct value_comparator
{
struct comparator parent;
- union value *pattern;
+ union value pattern;
};
/* A comparator which matches string values or parts thereof */
const union value *v)
{
const struct value_comparator *vc = (const struct value_comparator *) cmptr;
- return 0 == value_compare_3way (v, vc->pattern, var_get_width (cmptr->var));
+ return 0 == value_compare_3way (v, &vc->pattern, var_get_width (cmptr->var));
}
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;
- const char *text = val->s;
int width = var_get_width (cmptr->var);
-
+ 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->dict, *var_get_write_format (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;
}
g_return_val_if_fail (width > 0, false);
+ text = value_to_text (*val, cmptr->dict, *var_get_write_format (cmptr->var));
/* We must remove trailing whitespace, otherwise $ will not match where
one would expect */
- text = g_strndup (val->s, width);
g_strchomp (text);
retval = (0 == regexec (&rec->re, text, 0, 0, 0));
}
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));
}
static struct comparator *
-value_comparator_create (const struct variable *var, const char *target)
+value_comparator_create (const struct variable *var, const PsppireDict *dict, const char *target)
{
const struct fmt_spec *fmt;
int width ;
cmptr->flags = 0;
cmptr->var = var;
cmptr->compare = value_compare ;
- cmptr->destroy = value_destroy;
+ cmptr->destroy = cmptr_value_destroy;
+ cmptr->dict = dict;
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) )
- {
- free (vc);
- return NULL;
- }
+ text_to_value (target, &vc->pattern, dict, *var_get_write_format (var) );
return cmptr;
}
static struct comparator *
-string_comparator_create (const struct variable *var, const char *target,
+string_comparator_create (const struct variable *var, const PsppireDict *dict,
+ const char *target,
enum string_cmp_flags flags)
{
struct string_comparator *ssc = xzalloc (sizeof (*ssc));
cmptr->flags = flags;
cmptr->var = var;
+ cmptr->dict = dict;
if ( flags & STR_CMP_LABELS)
cmptr->compare = string_label_compare;
static struct comparator *
-regexp_comparator_create (const struct variable *var, const char *target,
+regexp_comparator_create (const struct variable *var, const PsppireDict *dict, const char *target,
enum string_cmp_flags flags)
{
int code;
cmptr->flags = flags;
cmptr->var = var;
+ cmptr->dict = dict;
cmptr->compare = (flags & STR_CMP_LABELS)
? regexp_label_compare : regexp_value_compare ;
static struct comparator *
-comparator_factory (const struct variable *var, const char *str,
+comparator_factory (const struct variable *var, const PsppireDict *dict, const char *str,
enum string_cmp_flags flags)
{
if ( flags & STR_CMP_REGEXP )
- return regexp_comparator_create (var, str, flags);
+ return regexp_comparator_create (var, dict, str, flags);
if ( flags & (STR_CMP_SUBSTR | STR_CMP_LABELS) )
- return string_comparator_create (var, str, flags);
+ return string_comparator_create (var, dict, str, flags);
- return value_comparator_create (var, str);
+ return value_comparator_create (var, dict, str);
}
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);
+ comparator_factory (var, fd->dict, target_string, flags);
+ value_init (&val, width);
if ( ! cmptr)
goto finish;
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;
finish:
comparator_destroy (cmptr);
- free (val);
+ value_destroy (&val, width);
}
}