X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fval-labs-dialog.c;h=42dd0b349c530c3f7a3d3daa5e970b78d541c0b1;hb=9e0e4996fad6563f0a1ce628b80db5c23ef8279e;hp=3918f2f2553314be3cc03686d10e24cafe8a10da;hpb=cf63d499efd5e6ca3a7dcc6386b3b87bd31bfda9;p=pspp-builds.git diff --git a/src/ui/gui/val-labs-dialog.c b/src/ui/gui/val-labs-dialog.c index 3918f2f2..42dd0b34 100644 --- a/src/ui/gui/val-labs-dialog.c +++ b/src/ui/gui/val-labs-dialog.c @@ -1,21 +1,18 @@ -/* - PSPPIRE --- A Graphical User Interface for PSPP - Copyright (C) 2005 Free Software Foundation +/* PSPPIRE - a graphical user interface for PSPP. + Copyright (C) 2005, 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. */ + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ /* This module describes the behaviour of the Value Labels dialog box, @@ -28,6 +25,39 @@ #include "helper.h" #include "val-labs-dialog.h" #include +#include +#include "psppire-var-sheet.h" +#include "psppire-var-store.h" +#include + +struct val_labs_dialog +{ + GtkWidget *window; + + PsppireSheet *vs; + + /* The variable to be updated */ + struct variable *pv; + + /* Local copy of labels */ + struct val_labs *labs; + + /* Actions */ + GtkWidget *add_button; + GtkWidget *remove_button; + GtkWidget *change_button; + + /* Entry Boxes */ + GtkWidget *value_entry; + GtkWidget *label_entry; + + /* Signal handler ids */ + gint change_handler_id; + gint value_handler_id; + + GtkWidget *treeview; +}; + /* This callback occurs when the text in the label entry box is changed */ @@ -152,23 +182,50 @@ val_labs_ok (GtkWidget *w, gpointer data) dialog->labs = 0; + gtk_widget_hide (dialog->window); + return FALSE; } +/* Callback for when the Value Labels dialog is closed using + the Cancel button.*/ +static void +val_labs_cancel (struct val_labs_dialog *dialog) +{ + val_labs_destroy (dialog->labs); + + dialog->labs = 0; + + gtk_widget_hide (dialog->window); +} + + /* Callback for when the Value Labels dialog is closed using the Cancel button.*/ static gint -val_labs_cancel (GtkWidget *w, gpointer data) +on_cancel (GtkWidget *w, gpointer data) { struct val_labs_dialog *dialog = data; - val_labs_destroy (dialog->labs); - dialog->labs = 0; + val_labs_cancel (dialog); return FALSE; } +/* Callback for when the Value Labels dialog is closed using + the window delete button.*/ +static gint +on_delete (GtkWidget *w, GdkEvent *e, gpointer data) +{ + struct val_labs_dialog *dialog = data; + + val_labs_cancel (dialog); + + return TRUE; +} + + /* Return the value-label pair currently selected in the dialog box */ static struct val_lab * get_selected_tuple (struct val_labs_dialog *dialog) @@ -217,6 +274,7 @@ on_change (GtkWidget *w, gpointer data) gtk_widget_set_sensitive (dialog->change_button, FALSE); repopulate_dialog (dialog); + gtk_widget_grab_focus (dialog->value_entry); return FALSE; } @@ -243,6 +301,7 @@ on_add (GtkWidget *w, gpointer data) gtk_widget_set_sensitive (dialog->add_button, FALSE); repopulate_dialog (dialog); + gtk_widget_grab_focus (dialog->value_entry); return FALSE; } @@ -258,6 +317,7 @@ on_remove (GtkWidget *w, gpointer data) val_labs_remove (dialog->labs, vl->value); repopulate_dialog (dialog); + gtk_widget_grab_focus (dialog->value_entry); gtk_widget_set_sensitive (dialog->remove_button, FALSE); @@ -269,8 +329,7 @@ on_remove (GtkWidget *w, gpointer data) /* Callback which occurs when a line item is selected in the list of value--label pairs.*/ static void -on_select_row (GtkTreeView *treeview, - gpointer data) +on_select_row (GtkTreeView *treeview, gpointer data) { gchar *labeltext; struct val_labs_dialog *dialog = data; @@ -280,6 +339,9 @@ on_select_row (GtkTreeView *treeview, gchar *const text = value_to_text (vl->value, *var_get_write_format (dialog->pv)); + PsppireVarStore *var_store = + PSPPIRE_VAR_STORE (psppire_sheet_get_model (dialog->vs)); + g_signal_handler_block (GTK_ENTRY (dialog->value_entry), dialog->value_handler_id); @@ -292,7 +354,10 @@ on_select_row (GtkTreeView *treeview, g_signal_handler_block (GTK_ENTRY (dialog->label_entry), dialog->change_handler_id); - labeltext = pspp_locale_to_utf8 (vl->label, -1, 0); + + labeltext = recode_string (UTF8, psppire_dict_encoding (var_store->dict), + vl->label, -1); + gtk_entry_set_text (GTK_ENTRY (dialog->label_entry), labeltext); g_free (labeltext); @@ -308,23 +373,24 @@ on_select_row (GtkTreeView *treeview, /* Create a new dialog box (there should normally be only one)*/ struct val_labs_dialog * -val_labs_dialog_create (GladeXML *xml) +val_labs_dialog_create (GtkWindow *toplevel, PsppireSheet *sheet) { GtkTreeViewColumn *column; GtkCellRenderer *renderer ; + GtkBuilder *xml = builder_new ("var-sheet-dialogs.ui"); + struct val_labs_dialog *dialog = g_malloc (sizeof (*dialog)); dialog->window = get_widget_assert (xml,"val_labs_dialog"); dialog->value_entry = get_widget_assert (xml,"value_entry"); dialog->label_entry = get_widget_assert (xml,"label_entry"); + dialog->vs = sheet; gtk_window_set_transient_for - (GTK_WINDOW (dialog->window), - GTK_WINDOW (get_widget_assert (xml, "data_editor"))); + (GTK_WINDOW (dialog->window), toplevel); - dialog->ok = get_widget_assert (xml, "val_labs_ok"); dialog->add_button = get_widget_assert (xml, "val_labs_add"); dialog->remove_button = get_widget_assert (xml, "val_labs_remove"); dialog->change_button = get_widget_assert (xml, "val_labs_change"); @@ -343,47 +409,58 @@ val_labs_dialog_create (GladeXML *xml) gtk_tree_view_append_column (GTK_TREE_VIEW (dialog->treeview), column); - g_signal_connect (GTK_OBJECT (get_widget_assert (xml, "val_labs_cancel")), + g_signal_connect (get_widget_assert (xml, "val_labs_cancel"), "clicked", - GTK_SIGNAL_FUNC (val_labs_cancel), dialog); + GTK_SIGNAL_FUNC (on_cancel), dialog); + + g_signal_connect (dialog->window, "delete-event", + GTK_SIGNAL_FUNC (on_delete), dialog); + + g_signal_connect (get_widget_assert (xml, "val_labs_ok"), + "clicked", + GTK_SIGNAL_FUNC (val_labs_ok), dialog); dialog->change_handler_id = - g_signal_connect (GTK_OBJECT (dialog->label_entry), + g_signal_connect (dialog->label_entry, "changed", GTK_SIGNAL_FUNC (on_label_entry_change), dialog); dialog->value_handler_id = - g_signal_connect (GTK_OBJECT (dialog->value_entry), + g_signal_connect (dialog->value_entry, "changed", GTK_SIGNAL_FUNC (on_value_entry_change), dialog); - g_signal_connect (GTK_OBJECT (dialog->change_button), + g_signal_connect (dialog->change_button, "clicked", GTK_SIGNAL_FUNC (on_change), dialog); - g_signal_connect (GTK_OBJECT (get_widget_assert (xml, "val_labs_ok")), - "clicked", - GTK_SIGNAL_FUNC (val_labs_ok), dialog); - - - g_signal_connect (GTK_OBJECT (dialog->treeview), "cursor-changed", + g_signal_connect (dialog->treeview, "cursor-changed", GTK_SIGNAL_FUNC (on_select_row), dialog); - - g_signal_connect (GTK_OBJECT (dialog->remove_button), "clicked", + g_signal_connect (dialog->remove_button, "clicked", GTK_SIGNAL_FUNC (on_remove), dialog); - - g_signal_connect (GTK_OBJECT (dialog->add_button), "clicked", + g_signal_connect (dialog->add_button, "clicked", GTK_SIGNAL_FUNC (on_add), dialog); dialog->labs = 0; + g_object_unref (xml); + return dialog; } +void +val_labs_dialog_set_target_variable (struct val_labs_dialog *dialog, + struct variable *var) +{ + dialog->pv = var; +} + + + /* Populate the components of the dialog box, from the 'labs' member variable */ static void @@ -394,6 +471,9 @@ repopulate_dialog (struct val_labs_dialog *dialog) GtkTreeIter iter; + PsppireVarStore *var_store = + PSPPIRE_VAR_STORE (psppire_sheet_get_model (dialog->vs)); + GtkListStore *list_store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_DOUBLE); @@ -422,11 +502,12 @@ repopulate_dialog (struct val_labs_dialog *dialog) *var_get_write_format (dialog->pv)); gchar *labeltext = - pspp_locale_to_utf8 (vl->label, -1, 0); + recode_string (UTF8, + psppire_dict_encoding (var_store->dict), + vl->label, -1); gchar *const text = g_strdup_printf ("%s = \"%s\"", - vstr, labeltext); - + vstr, labeltext); gtk_list_store_append (list_store, &iter); gtk_list_store_set (list_store, &iter, @@ -457,7 +538,7 @@ val_labs_dialog_show (struct val_labs_dialog *dialog) value_labels = var_get_value_labels (dialog->pv); if (value_labels) - dialog->labs = val_labs_copy ( value_labels ); + dialog->labs = val_labs_clone ( value_labels ); else dialog->labs = val_labs_create ( var_get_width (dialog->pv)); @@ -465,6 +546,8 @@ val_labs_dialog_show (struct val_labs_dialog *dialog) gtk_widget_set_sensitive (dialog->change_button, FALSE); gtk_widget_set_sensitive (dialog->add_button, FALSE); + gtk_widget_grab_focus (dialog->value_entry); + repopulate_dialog (dialog); gtk_widget_show (dialog->window); }