-struct column
-{
- /* Variable name for this column. This is the variable name
- used on the separators page; it can be overridden by the
- user on the formats page. */
- char *name;
-
- /* Maximum length of any row in this column. */
- size_t width;
-
- /* Contents of this column: contents[row] is the contents for
- the given row.
-
- A null substring indicates a missing column for that row
- (because the line contains an insufficient number of
- separators).
-
- contents[] elements may be substrings of the lines[]
- strings that represent the whole lines of the file, to
- save memory. Other elements are dynamically allocated
- with ss_alloc_substring. */
- struct substring *contents;
-};
-
-
-static void
-destroy_columns (PsppireImportAssistant *ia)
-{
- struct column *col;
- for (col = ia->columns; col < &ia->columns[ia->column_cnt]; col++)
- {
- free (col->name);
- free (col->contents);
- }
-
- free (ia->columns);
-}
-
-#if SHEET_MERGE
-
-/* Called to render one of the cells in the fields preview tree
- view. */
-static void
-render_input_cell (PsppSheetViewColumn *tree_column, GtkCellRenderer *cell,
- GtkTreeModel *model, GtkTreeIter *iter,
- gpointer ia_)
-{
- PsppireImportAssistant *ia = ia_;
- struct substring field;
- size_t row;
- gint column;
-
- column = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_column),
- "column-number"));
- row = empty_list_store_iter_to_row (iter) + ia->skip_lines;
- field = ia->columns[column].contents[row];
- if (field.string != NULL)
- {
- GValue text = {0, };
- g_value_init (&text, G_TYPE_STRING);
- g_value_take_string (&text, ss_xstrdup (field));
- g_object_set_property (G_OBJECT (cell), "text", &text);
- g_value_unset (&text);
- g_object_set (cell, "background-set", FALSE, (void *) NULL);
- }
- else
- g_object_set (cell,
- "text", "",
- "background", "red",
- "background-set", TRUE,
- (void *) NULL);
-}
-
-#endif
-
-/* Parses the contents of the field at (ROW,COLUMN) according to
- its variable format. If OUTPUTP is non-null, then *OUTPUTP
- receives the formatted output for that field (which must be
- freed with free). If TOOLTIPP is non-null, then *TOOLTIPP
- receives a message suitable for use in a tooltip, if one is
- needed, or a null pointer otherwise. Returns TRUE if a
- tooltip message is needed, otherwise FALSE. */
-static bool
-parse_field (PsppireImportAssistant *ia,
- size_t row, size_t column,
- char **outputp, char **tooltipp)
-{
- const struct fmt_spec *in;
- struct fmt_spec out;
- char *tooltip;
- bool ok;
-
- struct substring field = ia->columns[column].contents[row];
- struct variable *var = dict_get_var (ia->dict, column);
- union value val;
-
- value_init (&val, var_get_width (var));
- in = var_get_print_format (var);
- out = fmt_for_output_from_input (in);
- tooltip = NULL;
- if (field.string != NULL)
- {
- char *error = data_in (field, "UTF-8", in->type, &val, var_get_width (var),
- dict_get_encoding (ia->dict));
- if (error != NULL)
- {
- tooltip = xasprintf (_("Cannot parse field content `%.*s' as "
- "format %s: %s"),
- (int) field.length, field.string,
- fmt_name (in->type), error);
- free (error);
- }
- }
- else
- {
- tooltip = xstrdup (_("This input line has too few separators "
- "to fill in this field."));
- value_set_missing (&val, var_get_width (var));
- }
- if (outputp != NULL)
- {
- *outputp = data_out (&val, dict_get_encoding (ia->dict), &out);
- }
- value_destroy (&val, var_get_width (var));
-
- ok = tooltip == NULL;
- if (tooltipp != NULL)
- *tooltipp = tooltip;
- else
- free (tooltip);
- return ok;
-}
-
-#if SHEET_MERGE
-
-/* Called to render one of the cells in the data preview tree
- view. */
-static void
-render_output_cell (PsppSheetViewColumn *tree_column,
- GtkCellRenderer *cell,
- GtkTreeModel *model,
- GtkTreeIter *iter,
- gpointer ia_)
-{
- PsppireImportAssistant *ia = ia_;
- char *output;
- GValue gvalue = { 0, };
- bool ok = parse_field (ia,
- (empty_list_store_iter_to_row (iter)
- + ia->skip_lines),
- GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_column),
- "column-number")),
- &output, NULL);
-
- g_value_init (&gvalue, G_TYPE_STRING);
- g_value_take_string (&gvalue, output);
- g_object_set_property (G_OBJECT (cell), "text", &gvalue);
- g_value_unset (&gvalue);
-
- if (ok)
- g_object_set (cell, "background-set", FALSE, (void *) NULL);
- else
- g_object_set (cell,
- "background", "red",
- "background-set", TRUE,
- (void *) NULL);
-}
-
-
-/* Utility functions used by multiple pages of the assistant. */
-
-static gboolean
-get_tooltip_location (GtkWidget *widget, gint wx, gint wy,
- const PsppireImportAssistant *ia,
- size_t *row, size_t *column)
-{
- PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
- gint bx, by;
- GtkTreePath *path;
- GtkTreeIter iter;
- PsppSheetViewColumn *tree_column;
- GtkTreeModel *tree_model;
- bool ok;
-
- pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view,
- wx, wy, &bx, &by);
- if (!pspp_sheet_view_get_path_at_pos (tree_view, bx, by,
- &path, &tree_column, NULL, NULL))
- return FALSE;
-
- *column = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tree_column),
- "column-number"));
-
- tree_model = pspp_sheet_view_get_model (tree_view);
- ok = gtk_tree_model_get_iter (tree_model, &iter, path);
- gtk_tree_path_free (path);
- if (!ok)
- return FALSE;
-
- *row = empty_list_store_iter_to_row (&iter) + ia->skip_lines;
- return TRUE;
-}
-
-
-
-\f
-
-
-/* Called to render a tooltip on one of the cells in the fields
- preview tree view. */
-static gboolean
-on_query_input_tooltip (GtkWidget *widget, gint wx, gint wy,
- gboolean keyboard_mode UNUSED,
- GtkTooltip *tooltip, PsppireImportAssistant *ia)
-{
- size_t row, column;
-
- if (!get_tooltip_location (widget, wx, wy, ia, &row, &column))
- return FALSE;
-
- if (ia->columns[column].contents[row].string != NULL)
- return FALSE;
-
- gtk_tooltip_set_text (tooltip,
- _("This input line has too few separators "
- "to fill in this field."));
- return TRUE;
-}
-
-
-/* Called to render a tooltip for one of the cells in the data
- preview tree view. */
-static gboolean
-on_query_output_tooltip (GtkWidget *widget, gint wx, gint wy,
- gboolean keyboard_mode UNUSED,
- GtkTooltip *tooltip, PsppireImportAssistant *ia)
-{
- size_t row, column;
- char *text;
-
- if (!gtk_widget_get_mapped (widget))
- return FALSE;
-
- if (!get_tooltip_location (widget, wx, wy, ia, &row, &column))
- return FALSE;
-
- if (parse_field (ia, row, column, NULL, &text))
- return FALSE;
-
- gtk_tooltip_set_text (tooltip, text);
- free (text);
- return TRUE;
-}
-#endif
-\f
-
-