/*
PSPPIRE --- A Graphical User Interface for PSPP
- Copyright (C) 2005 Free Software Foundation
- Written by John Darrington
+ Copyright (C) 2005, 2006 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
/* This module describes the behaviour of the Variable Type dialog box used
for inputing the variable type in the var sheet */
+#include <config.h>
+
#include <gtk/gtk.h>
#include <glade/glade.h>
#include "var-type-dialog.h"
-#include "psppire-variable.h"
+#include "helper.h"
#include <data/variable.h>
#include <data/settings.h>
+#include <libpspp/message.h>
struct tgs
static void
set_local_width_decimals(struct var_type_dialog *dialog)
{
- dialog->fmt_l = * psppire_variable_get_write_spec(dialog->pv);
+ dialog->fmt_l = * var_get_write_format (dialog->pv);
switch (dialog->active_button)
{
#define LEN 20
-/* return a string of the form "$#,###.##" according to FMT.
- FMT must be of type FMT_DOLLAR
- */
-static const gchar *
-dollar_format_template(const struct fmt_spec *fmt)
-{
- static gchar buf[LEN];
- g_assert( fmt->type == FMT_DOLLAR);
-
- {
- gint c ;
- gint int_part = fmt->w - fmt->d;
- if ( fmt->d > 0 ) --int_part;
- g_assert(int_part > 0);
-
- g_strlcpy(buf, "$", LEN);
-
- c = int_part - 1;
- while(c > 0)
- {
- g_strlcat(buf, "#", LEN);
- if(--c % 4 == 0 && c > 0 )
- {
- g_strlcat(buf, ",", LEN);
- --c;
- }
- }
- if ( fmt->d > 0 )
- {
- g_strlcat(buf, ".", LEN);
- for ( c = 0 ; c < fmt->d ; ++c )
- g_strlcat(buf, "#", LEN);
- }
- }
-
- return buf;
-}
-
static void
add_to_group(GtkWidget *w, gpointer data)
{
text = gtk_entry_get_text(GTK_ENTRY(dialog->entry_width));
dialog->fmt_l.w = atoi(text);
- if ( ! check_output_specifier(&dialog->fmt_l, 0))
+ msg_disable ();
+ if ( ! fmt_check_output(&dialog->fmt_l))
{
gtk_label_set_text(GTK_LABEL(dialog->label_psample), "---");
gtk_label_set_text(GTK_LABEL(dialog->label_nsample), "---");
gtk_label_set_text(GTK_LABEL(dialog->label_nsample), sample_text);
g_free(sample_text);
}
+ msg_enable ();
}
/* Callback for when a treeview row is changed.
for ( i = 0 ; i < sizeof(dollar_format)/sizeof(dollar_format[0]) ; ++i )
{
+ char *template = fmt_dollar_template (&dollar_format[i]);
gtk_list_store_append (list_store, &iter);
gtk_list_store_set (list_store, &iter,
- 0, dollar_format_template(&dollar_format[i]),
+ 0, template,
1, &dollar_format[i],
-1);
+ free (template);
}
gtk_tree_view_set_model(GTK_TREE_VIEW(dialog->dollar_treeview),
list_store = gtk_list_store_new (2, G_TYPE_STRING,
G_TYPE_POINTER);
- for ( i = 0 ; i < CC_CNT ; ++i )
+ for ( i = 0 ; i < 5 ; ++i )
{
+ enum fmt_type cc_fmts[5] = {FMT_CCA, FMT_CCB, FMT_CCC, FMT_CCD, FMT_CCE};
gchar text[4];
- g_snprintf(text, 4, "CC%c", 'A' + i);
+ g_snprintf(text, 4, "%s", fmt_name (cc_fmts[i]));
gtk_list_store_append (list_store, &iter);
gtk_list_store_set (list_store, &iter,
0, text,
gtk_tree_view_set_cursor(treeview, path, 0, 0);
gtk_tree_path_free(path);
}
- else
- g_warning("Unusual date format: %s\n", fmt_to_string(fmt));
-
+ else
+ {
+ char str[FMT_STRING_LEN_MAX + 1];
+ g_warning("Unusual date format: %s\n", fmt_to_string(fmt, str));
+ }
}
g_assert(dialog->pv);
/* Populate width and decimals */
- write_spec = psppire_variable_get_write_spec(dialog->pv);
+ write_spec = var_get_write_format (dialog->pv);
g_string_printf(str, "%d", write_spec->d);
f->type = type;
f->w = w;
f->d = d;
- return check_output_specifier (f, true);
+ return fmt_check_output (f);
}
gint decimals = atoi(gtk_entry_get_text
(GTK_ENTRY(dialog->entry_decimals)));
- gint new_type = NUMERIC;
+ gint new_type = VAR_NUMERIC;
gint new_width = 0;
bool result = false;
struct fmt_spec spec;
switch (dialog->active_button)
{
case BUTTON_STRING:
- new_type = ALPHA;
+ new_type = VAR_STRING;
new_width = width;
result = make_output_format_try(&spec, FMT_A, width, 0);
break;
break;
case BUTTON_DATE:
case BUTTON_CUSTOM:
- g_assert(check_output_specifier(&dialog->fmt_l, TRUE));
+ g_assert(fmt_check_output(&dialog->fmt_l));
result = memcpy(&spec, &dialog->fmt_l, sizeof(struct fmt_spec));
break;
case BUTTON_DOLLAR:
break;
}
- if ( result == true )
+ if ( result == true )
{
- psppire_variable_set_type(dialog->pv, new_type);
- psppire_variable_set_width(dialog->pv, new_width);
- psppire_variable_set_write_spec(dialog->pv, spec);
- psppire_variable_set_print_spec(dialog->pv, spec);
+ var_set_width (dialog->pv, new_width);
+ var_set_both_formats (dialog->pv, &spec);
}
}