val-labs-dialog: Convert to a GObject.
authorBen Pfaff <blp@cs.stanford.edu>
Sat, 18 Aug 2012 19:26:03 +0000 (12:26 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sat, 18 Aug 2012 19:28:55 +0000 (12:28 -0700)
src/ui/gui/automake.mk
src/ui/gui/psppire-var-sheet.c
src/ui/gui/psppire-var-sheet.h
src/ui/gui/val-labs-dialog.c
src/ui/gui/val-labs-dialog.h
src/ui/gui/val-labs-dialog.ui [new file with mode: 0644]
src/ui/gui/var-sheet-dialogs.ui

index 55f8291432d850b8bf89abc6bb83d06584023ea7..7468c89038d1e459cdc1aa74921b0219386bd358 100644 (file)
@@ -38,6 +38,7 @@ UI_FILES = \
        src/ui/gui/t-test.ui \
        src/ui/gui/text-data-import.ui \
        src/ui/gui/univariate.ui \
+       src/ui/gui/val-labs-dialog.ui \
        src/ui/gui/var-sheet-dialogs.ui \
        src/ui/gui/variable-info.ui \
        src/ui/gui/data-editor.ui \
index a3208f00007e4dad0258ec2d42ef4cbfbd41b213..5171cabbb1dd02c0a88e84db2e1313bea6f8b02f 100644 (file)
@@ -23,7 +23,9 @@
 
 #include "customentry.h"
 #include <data/variable.h>
+#include "data/value-labels.h"
 #include "psppire-var-store.h"
+#include "ui/gui/val-labs-dialog.h"
 
 #include <gettext.h>
 #define _(msgid) gettext (msgid)
@@ -309,6 +311,29 @@ var_sheet_show_var_type_dialog (PsppireVarSheet *vs)
   var_set_both_formats (var, &format);
 }
 
+static void
+var_sheet_show_val_labs_dialog (PsppireVarSheet *vs)
+{
+  PsppireVarStore *var_store;
+  struct val_labs *labels;
+  struct variable *var;
+  gint row;
+
+  var_store = PSPPIRE_VAR_STORE (psppire_sheet_get_model (PSPPIRE_SHEET (vs)));
+
+  psppire_sheet_get_active_cell (PSPPIRE_SHEET (vs), &row, NULL);
+  var = psppire_var_store_get_var (var_store, row);
+  g_return_if_fail (var != NULL);
+
+  labels = psppire_val_labs_dialog_run (GTK_WINDOW (gtk_widget_get_toplevel (
+                                                      GTK_WIDGET (vs))), var);
+  if (labels)
+    {
+      var_set_value_labels (var, labels);
+      val_labs_destroy (labels);
+    }
+}
+
 /*
    Callback whenever the active cell changes on the var sheet.
 */
@@ -386,12 +411,10 @@ var_sheet_change_active_cell (PsppireVarSheet *vs,
        customEntry =
          PSPPIRE_CUSTOM_ENTRY (psppire_sheet_get_entry (sheet));
 
-       val_labs_dialog_set_target_variable (vs->val_labs_dialog, var);
-
        g_signal_connect_swapped (customEntry,
                                  "clicked",
-                                 G_CALLBACK (val_labs_dialog_show),
-                                 vs->val_labs_dialog);
+                                 G_CALLBACK (var_sheet_show_val_labs_dialog),
+                                 vs);
       }
       break;
 
@@ -497,8 +520,6 @@ psppire_var_sheet_realize (GtkWidget *w)
 
   GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (vs));
 
-  vs->val_labs_dialog = val_labs_dialog_create (GTK_WINDOW (toplevel));
-
   vs->missing_val_dialog = missing_val_dialog_create (GTK_WINDOW (toplevel));
   
   /* Chain up to the parent class */
@@ -510,7 +531,6 @@ psppire_var_sheet_unrealize (GtkWidget *w)
 {
   PsppireVarSheet *vs = PSPPIRE_VAR_SHEET (w);
 
-  g_free (vs->val_labs_dialog);
   g_free (vs->missing_val_dialog);
 
   /* Chain up to the parent class */
index 7c043ca5a29d1e14f4ef6a5176da3133e01d2e39..24e69af1b0bb5e5887be88c619a324d67e2b5923 100644 (file)
@@ -21,7 +21,6 @@
 #include <glib.h>
 #include <glib-object.h>
 #include <gtk-contrib/psppire-sheet.h>
-#include "val-labs-dialog.h"
 #include "missing-val-dialog.h"
 #include "var-type-dialog.h"
 
@@ -45,7 +44,6 @@ struct _PsppireVarSheet
   gboolean dispose_has_run;
   gboolean may_create_vars;
 
-  struct val_labs_dialog *val_labs_dialog ;
   struct missing_val_dialog *missing_val_dialog ;
 };
 
index 6b556d6de7861baa006530b2cfcf943fe0ff46d9..094a422af002268df421eeb9749a99c568f6d84e 100644 (file)
 
 #include <config.h>
 
-#include <string.h>
+#include "ui/gui/val-labs-dialog.h"
 
-#include "builder-wrapper.h"
-#include "val-labs-dialog.h"
-#include <data/value-labels.h>
-#include <data/format.h>
-#include "psppire-var-sheet.h"
-#include "psppire-var-store.h"
-#include <libpspp/i18n.h>
+#include <string.h>
 
-#include "helper.h"
+#include "data/value-labels.h"
+#include "data/format.h"
+#include "libpspp/i18n.h"
+#include "ui/gui/builder-wrapper.h"
+#include "ui/gui/helper.h"
 
 #include <gettext.h>
 #define _(msgid) gettext (msgid)
 #define N_(msgid) msgid
 
-struct val_labs_dialog
+static GObject *psppire_val_labs_dialog_constructor (GType type, guint,
+                                                     GObjectConstructParam *);
+static void psppire_val_labs_dialog_finalize (GObject *);
+
+G_DEFINE_TYPE (PsppireValLabsDialog,
+               psppire_val_labs_dialog,
+               PSPPIRE_TYPE_DIALOG);
+enum
+  {
+    PROP_0,
+    PROP_VARIABLE,
+    PROP_VALUE_LABELS
+  };
+
+static void
+psppire_val_labs_dialog_set_property (GObject      *object,
+                                      guint         prop_id,
+                                      const GValue *value,
+                                      GParamSpec   *pspec)
 {
-  GtkWidget *window;
+  PsppireValLabsDialog *obj = PSPPIRE_VAL_LABS_DIALOG (object);
 
-  /* The variable to be updated */
-  struct variable *pv;
+  switch (prop_id)
+    {
+    case PROP_VARIABLE:
+      psppire_val_labs_dialog_set_variable (obj, g_value_get_pointer (value));
+      break;
+    case PROP_VALUE_LABELS:
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
 
-  /* Local copy of labels */
-  struct val_labs *labs;
+static void
+psppire_val_labs_dialog_get_property (GObject      *object,
+                                      guint         prop_id,
+                                      GValue       *value,
+                                      GParamSpec   *pspec)
+{
+  PsppireValLabsDialog *obj = PSPPIRE_VAL_LABS_DIALOG (object);
 
-  /* Actions */
-  GtkWidget *add_button;
-  GtkWidget *remove_button;
-  GtkWidget *change_button;
+  switch (prop_id)
+    {
+    case PROP_VALUE_LABELS:
+      g_value_set_pointer (value, obj->labs);
+      break;
+    case PROP_VARIABLE:
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
 
-  /* Entry Boxes */
-  GtkWidget *value_entry;
-  GtkWidget *label_entry;
+static void
+psppire_val_labs_dialog_class_init (PsppireValLabsDialogClass *class)
+{
+  GObjectClass *gobject_class;
+  gobject_class = G_OBJECT_CLASS (class);
+
+  gobject_class->constructor = psppire_val_labs_dialog_constructor;
+  gobject_class->finalize = psppire_val_labs_dialog_finalize;
+  gobject_class->set_property = psppire_val_labs_dialog_set_property;
+  gobject_class->get_property = psppire_val_labs_dialog_get_property;
+
+  g_object_class_install_property (
+    gobject_class, PROP_VARIABLE,
+    g_param_spec_pointer ("variable",
+                          "Variable",
+                          "Variable whose value labels are to be edited.  The "
+                          "variable's print format and encoding are also used "
+                          "for editing.",
+                          G_PARAM_WRITABLE));
+
+  g_object_class_install_property (
+    gobject_class, PROP_VALUE_LABELS,
+    g_param_spec_pointer ("value-labels",
+                          "Value Labels",
+                          "Edited value labels.",
+                          G_PARAM_READABLE));
+}
 
-  /* Signal handler ids */
-  gint change_handler_id;
-  gint value_handler_id;
+static void
+psppire_val_labs_dialog_init (PsppireValLabsDialog *obj)
+{
+  /* We do all of our work on widgets in the constructor function, because that
+     runs after the construction properties have been set.  Otherwise
+     PsppireDialog's "orientation" property hasn't been set and therefore we
+     have no box to populate. */
+  obj->labs = val_labs_create (0);
+}
 
-  GtkWidget *treeview;
-};
+static void
+psppire_val_labs_dialog_finalize (GObject *obj)
+{
+  PsppireValLabsDialog *dialog = PSPPIRE_VAL_LABS_DIALOG (obj);
 
+  val_labs_destroy (dialog->labs);
+  g_free (dialog->encoding);
+
+  G_OBJECT_CLASS (psppire_val_labs_dialog_parent_class)->finalize (obj);
+}
+
+PsppireValLabsDialog *
+psppire_val_labs_dialog_new (const struct variable *var)
+{
+  return PSPPIRE_VAL_LABS_DIALOG (
+    g_object_new (PSPPIRE_TYPE_VAL_LABS_DIALOG,
+                  "orientation", PSPPIRE_HORIZONTAL,
+                  "variable", var,
+                  NULL));
+}
+
+struct val_labs *
+psppire_val_labs_dialog_run (GtkWindow *parent_window,
+                             const struct variable *var)
+{
+  PsppireValLabsDialog *dialog;
+  struct val_labs *labs;
+
+  dialog = psppire_val_labs_dialog_new (var);
+  gtk_window_set_transient_for (GTK_WINDOW (dialog), parent_window);
+  gtk_widget_show (GTK_WIDGET (dialog));
+
+  labs = (psppire_dialog_run (PSPPIRE_DIALOG (dialog)) == GTK_RESPONSE_OK
+          ? val_labs_clone (psppire_val_labs_dialog_get_value_labels (dialog))
+          : NULL);
+
+  gtk_widget_destroy (GTK_WIDGET (dialog));
+
+  return labs;
+}
 
 /* This callback occurs when the text in the label entry box
    is changed */
@@ -70,14 +174,12 @@ on_label_entry_change (GtkEntry *entry, gpointer data)
 {
   union value v;
   const gchar *text ;
-  struct val_labs_dialog *dialog = data;
+  PsppireValLabsDialog *dialog = data;
   g_assert (dialog->labs);
 
   text = gtk_entry_get_text (GTK_ENTRY (dialog->value_entry));
 
-  text_to_value (text,
-                dialog->pv,
-                &v);
+  text_to_value__ (text, &dialog->format, dialog->encoding, &v);
 
   if (val_labs_find (dialog->labs, &v))
     {
@@ -90,7 +192,7 @@ on_label_entry_change (GtkEntry *entry, gpointer data)
       gtk_widget_set_sensitive (dialog->add_button, TRUE);
     }
 
-  value_destroy (&v, var_get_width (dialog->pv));
+  value_destroy (&v, val_labs_get_width (dialog->labs));
 }
 
 
@@ -142,15 +244,12 @@ on_value_entry_change (GtkEntry *entry, gpointer data)
 {
   const char *s;
 
-  struct val_labs_dialog *dialog = data;
+  PsppireValLabsDialog *dialog = data;
 
   const gchar *text = gtk_entry_get_text (GTK_ENTRY (dialog->value_entry));
 
   union value v;
-  text_to_value (text,
-                dialog->pv,
-                &v);
-
+  text_to_value__ (text, &dialog->format, dialog->encoding, &v);
 
   g_signal_handler_block (GTK_ENTRY (dialog->label_entry),
                         dialog->change_handler_id);
@@ -174,68 +273,13 @@ on_value_entry_change (GtkEntry *entry, gpointer data)
   g_signal_handler_unblock (GTK_ENTRY (dialog->label_entry),
                         dialog->change_handler_id);
 
-  value_destroy (&v, var_get_width (dialog->pv));
-}
-
-
-/* Callback for when the Value Labels dialog is closed using
-   the OK button.*/
-static gint
-val_labs_ok (GtkWidget *w, gpointer data)
-{
-  struct val_labs_dialog *dialog = data;
-
-  var_set_value_labels (dialog->pv, dialog->labs);
-
-  val_labs_destroy (dialog->labs);
-
-  dialog->labs = NULL;
-
-  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 = NULL;
-
-  gtk_widget_hide (dialog->window);
-}
-
-
-/* Callback for when the Value Labels dialog is closed using
-   the Cancel button.*/
-static void
-on_cancel (GtkWidget *w, gpointer data)
-{
-  struct val_labs_dialog *dialog = data;
-
-  val_labs_cancel (dialog);
-}
-
-
-/* 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;
+  value_destroy (&v, val_labs_get_width (dialog->labs));
 }
 
 
 /* Return the value-label pair currently selected in the dialog box  */
 static void
-get_selected_tuple (struct val_labs_dialog *dialog,
+get_selected_tuple (PsppireValLabsDialog *dialog,
                     union value *valuep, const char **label)
 {
   GtkTreeView *treeview = GTK_TREE_VIEW (dialog->treeview);
@@ -266,21 +310,19 @@ get_selected_tuple (struct val_labs_dialog *dialog,
 }
 
 
-static void repopulate_dialog (struct val_labs_dialog *dialog);
+static void repopulate_dialog (PsppireValLabsDialog *dialog);
 
 /* Callback which occurs when the "Change" button is clicked */
 static void
 on_change (GtkWidget *w, gpointer data)
 {
-  struct val_labs_dialog *dialog = data;
+  PsppireValLabsDialog *dialog = data;
 
   const gchar *val_text = gtk_entry_get_text (GTK_ENTRY (dialog->value_entry));
 
   union value v;
 
-  text_to_value (val_text,
-                dialog->pv,
-                &v);
+  text_to_value__ (val_text, &dialog->format, dialog->encoding, &v);
 
   val_labs_replace (dialog->labs, &v,
                    gtk_entry_get_text (GTK_ENTRY (dialog->label_entry)));
@@ -290,22 +332,20 @@ on_change (GtkWidget *w, gpointer data)
   repopulate_dialog (dialog);
   gtk_widget_grab_focus (dialog->value_entry);
 
-  value_destroy (&v, var_get_width (dialog->pv));
+  value_destroy (&v, val_labs_get_width (dialog->labs));
 }
 
 /* Callback which occurs when the "Add" button is clicked */
 static void
 on_add (GtkWidget *w, gpointer data)
 {
-  struct val_labs_dialog *dialog = data;
+  PsppireValLabsDialog *dialog = data;
 
   union value v;
 
   const gchar *text = gtk_entry_get_text (GTK_ENTRY (dialog->value_entry));
 
-  text_to_value (text,
-                dialog->pv,
-                &v);
+  text_to_value__ (text, &dialog->format, dialog->encoding, &v);
 
   if (val_labs_add (dialog->labs, &v,
                    gtk_entry_get_text
@@ -317,14 +357,14 @@ on_add (GtkWidget *w, gpointer data)
       gtk_widget_grab_focus (dialog->value_entry);
     }
 
-  value_destroy (&v, var_get_width (dialog->pv));
+  value_destroy (&v, val_labs_get_width (dialog->labs));
 }
 
 /* Callback which occurs when the "Remove" button is clicked */
 static void
 on_remove (GtkWidget *w, gpointer data)
 {
-  struct val_labs_dialog *dialog = data;
+  PsppireValLabsDialog *dialog = data;
 
   union value value;
   struct val_lab *vl;
@@ -347,7 +387,7 @@ on_remove (GtkWidget *w, gpointer data)
 static void
 on_select_row (GtkTreeView *treeview, gpointer data)
 {
-  struct val_labs_dialog *dialog = data;
+  PsppireValLabsDialog *dialog = data;
 
   union value value;
   const char *label = NULL;
@@ -355,7 +395,7 @@ on_select_row (GtkTreeView *treeview, gpointer data)
   gchar *text;
 
   get_selected_tuple (dialog, &value, &label);
-  text = value_to_text (value, dialog->pv);
+  text = value_to_text__ (value, &dialog->format, dialog->encoding);
 
   g_signal_handler_block (GTK_ENTRY (dialog->value_entry),
                         dialog->value_handler_id);
@@ -383,24 +423,32 @@ on_select_row (GtkTreeView *treeview, gpointer data)
 
 /* Create a new dialog box
    (there should  normally be only one)*/
-struct val_labs_dialog *
-val_labs_dialog_create (GtkWindow *toplevel)
+static GObject *
+psppire_val_labs_dialog_constructor (GType                  type,
+                                     guint                  n_properties,
+                                     GObjectConstructParam *properties)
 {
+  PsppireValLabsDialog *dialog;
   GtkTreeViewColumn *column;
 
   GtkCellRenderer *renderer ;
 
-  GtkBuilder *xml = builder_new ("var-sheet-dialogs.ui");
+  GtkBuilder *xml = builder_new ("val-labs-dialog.ui");
+
+  GtkContainer *content_area;
+  GObject *obj;
+
+  obj = G_OBJECT_CLASS (psppire_val_labs_dialog_parent_class)->constructor (
+    type, n_properties, properties);
+  dialog = PSPPIRE_VAL_LABS_DIALOG (obj);
 
-  struct val_labs_dialog *dialog = g_malloc (sizeof (*dialog));
+  content_area = GTK_CONTAINER (PSPPIRE_DIALOG (dialog)->box);
+  gtk_container_add (GTK_CONTAINER (content_area),
+                     get_widget_assert (xml, "val-labs-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");
 
-  gtk_window_set_transient_for
-    (GTK_WINDOW (dialog->window), toplevel);
-
   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");
@@ -419,17 +467,6 @@ val_labs_dialog_create (GtkWindow *toplevel)
 
   gtk_tree_view_append_column (GTK_TREE_VIEW (dialog->treeview), column);
 
-  g_signal_connect (get_widget_assert (xml, "val_labs_cancel"),
-                  "clicked",
-                  G_CALLBACK (on_cancel), dialog);
-
-  g_signal_connect (dialog->window, "delete-event",
-                   G_CALLBACK (on_delete), dialog);
-
-  g_signal_connect (get_widget_assert (xml, "val_labs_ok"),
-                  "clicked",
-                  G_CALLBACK (val_labs_ok), dialog);
-
   dialog->change_handler_id =
     g_signal_connect (dialog->label_entry,
                     "changed",
@@ -458,23 +495,14 @@ val_labs_dialog_create (GtkWindow *toplevel)
 
   g_object_unref (xml);
 
-  return dialog;
+  return obj;
 }
 
 
-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
-repopulate_dialog (struct val_labs_dialog *dialog)
+repopulate_dialog (PsppireValLabsDialog *dialog)
 {
   const struct val_lab **labels;
   size_t n_labels;
@@ -506,7 +534,7 @@ repopulate_dialog (struct val_labs_dialog *dialog)
       const struct val_lab *vl = labels[i];
 
       gchar *const vstr  =
-       value_to_text (vl->value, dialog->pv);
+        value_to_text__ (vl->value, &dialog->format, dialog->encoding);
 
       gchar *const text = g_strdup_printf (_("%s = `%s'"), vstr,
                                            val_lab_get_escaped_label (vl));
@@ -529,28 +557,33 @@ repopulate_dialog (struct val_labs_dialog *dialog)
 
 }
 
-/* Initialise and display the dialog box */
 void
-val_labs_dialog_show (struct val_labs_dialog *dialog)
+psppire_val_labs_dialog_set_variable (PsppireValLabsDialog *dialog,
+                                      const struct variable *var)
 {
-  const struct val_labs *value_labels;
-
-  g_assert (!dialog->labs);
+  val_labs_destroy (dialog->labs);
+  dialog->labs = NULL;
 
-  value_labels = var_get_value_labels (dialog->pv);
+  g_free (dialog->encoding);
+  dialog->encoding = NULL;
 
-  if (value_labels)
-    dialog->labs = val_labs_clone ( value_labels );
+  if (var != NULL)
+    {
+      dialog->labs = val_labs_clone (var_get_value_labels (var));
+      dialog->encoding = g_strdup (var_get_encoding (var));
+      dialog->format = *var_get_print_format (var);
+    }
   else
-    dialog->labs = val_labs_create ( var_get_width (dialog->pv));
+    dialog->format = F_8_0;
 
-  gtk_widget_set_sensitive (dialog->remove_button, FALSE);
-  gtk_widget_set_sensitive (dialog->change_button, FALSE);
-  gtk_widget_set_sensitive (dialog->add_button, FALSE);
-
-  gtk_widget_grab_focus (dialog->value_entry);
+  if (dialog->labs == NULL)
+    dialog->labs = val_labs_create (var_get_width (var));
 
   repopulate_dialog (dialog);
-  gtk_widget_show (dialog->window);
 }
 
+const struct val_labs *
+psppire_val_labs_dialog_get_value_labels (const PsppireValLabsDialog *dialog)
+{
+  return dialog->labs;
+}
index 85feaaca7891ec1115639d70886730fc26078c08..f3facce054120b69a062a8811a0e832f55d80411 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2005, 2011  Free Software Foundation
+   Copyright (C) 2005, 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
@@ -14,8 +14,8 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
-#ifndef __PSPPIRE_VAL_LABS_DIALOG_H
-#define __PSPPIRE_VAL_LABS_DIALOG_H
+#ifndef PSPPIRE_VAL_LABS_DIALOG_H
+#define PSPPIRE_VAL_LABS_DIALOG_H
 
 
 /*  This module describes the behaviour of the Value Labels dialog box,
 
 
 #include <gtk/gtk.h>
-#include <data/variable.h>
-//#include <gtk-contrib/psppire-sheet.h>
-#include "psppire-var-store.h"
+#include "data/format.h"
+#include "data/variable.h"
+#include "ui/gui/psppire-dialog.h"
+#include "ui/gui/psppire-var-store.h"
 
-struct val_labs;
+G_BEGIN_DECLS
 
+#define PSPPIRE_TYPE_VAL_LABS_DIALOG             (psppire_val_labs_dialog_get_type())
+#define PSPPIRE_VAL_LABS_DIALOG(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj),PSPPIRE_TYPE_VAL_LABS_DIALOG,PsppireValLabsDialog))
+#define PSPPIRE_VAL_LABS_DIALOG_CLASS(class)     (G_TYPE_CHECK_CLASS_CAST ((class),PSPPIRE_TYPE_VAL_LABS_DIALOG,PsppireValLabsDialogClass))
+#define PSPPIRE_IS_VAL_LABS_DIALOG(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj),PSPPIRE_TYPE_VAL_LABS_DIALOG))
+#define PSPPIRE_IS_VAL_LABS_DIALOG_CLASS(class)  (G_TYPE_CHECK_CLASS_TYPE ((class),PSPPIRE_TYPE_VAL_LABS_DIALOG))
+#define PSPPIRE_VAL_LABS_DIALOG_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj),PSPPIRE_TYPE_VAL_LABS_DIALOG,PsppireValLabsDialogClass))
 
-struct val_labs_dialog * val_labs_dialog_create (GtkWindow *);
+typedef struct _PsppireValLabsDialog      PsppireValLabsDialog;
+typedef struct _PsppireValLabsDialogClass PsppireValLabsDialogClass;
 
-void val_labs_dialog_show (struct val_labs_dialog *);
+struct _PsppireValLabsDialog {
+  PsppireDialog parent;
 
-void val_labs_dialog_set_target_variable (struct val_labs_dialog *,
-                                         struct variable *);
+  GtkWidget *window;
 
-#endif
+  struct val_labs *labs;
+  gchar *encoding;
+  struct fmt_spec format;
+
+  /* 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;
+};
+
+struct _PsppireValLabsDialogClass {
+  PsppireDialogClass parent_class;
+};
+
+GType psppire_val_labs_dialog_get_type (void) G_GNUC_CONST;
+PsppireValLabsDialog* psppire_val_labs_dialog_new (const struct variable *);
+
+void psppire_val_labs_dialog_set_variable (PsppireValLabsDialog *,
+                                           const struct variable *);
+const struct val_labs *psppire_val_labs_dialog_get_value_labels (
+  const PsppireValLabsDialog *);
+
+struct val_labs *psppire_val_labs_dialog_run (GtkWindow *parent_window,
+                                              const struct variable *);
+
+G_END_DECLS
+
+#endif /* psppire-val-labs-dialog.h */
diff --git a/src/ui/gui/val-labs-dialog.ui b/src/ui/gui/val-labs-dialog.ui
new file mode 100644 (file)
index 0000000..d75abc5
--- /dev/null
@@ -0,0 +1,215 @@
+<?xml version="1.0"?>
+<interface>
+  <!-- interface-requires gtk+ 2.12 -->
+  <!-- interface-naming-policy project-wide -->
+  <object class="GtkHBox" id="val-labs-dialog">
+    <property name="visible">True</property>
+    <property name="border_width">5</property>
+    <child>
+      <object class="GtkFrame" id="frame1">
+       <property name="visible">True</property>
+       <property name="label_xalign">0</property>
+       <child>
+         <object class="GtkAlignment" id="alignment1">
+           <property name="visible">True</property>
+           <property name="border_width">8</property>
+           <property name="left_padding">12</property>
+           <child>
+             <object class="GtkTable" id="table3">
+               <property name="visible">True</property>
+               <property name="n_rows">2</property>
+               <property name="n_columns">2</property>
+               <property name="row_spacing">5</property>
+               <child>
+                 <object class="GtkScrolledWindow" id="scrolledwindow3">
+                   <property name="visible">True</property>
+                   <property name="can_focus">True</property>
+                   <property name="hscrollbar_policy">automatic</property>
+                   <property name="vscrollbar_policy">automatic</property>
+                   <property name="shadow_type">etched-in</property>
+                   <child>
+                     <object class="GtkTreeView" id="treeview1">
+                       <property name="visible">True</property>
+                       <property name="can_focus">True</property>
+                       <property name="headers_visible">False</property>
+                       <property name="enable_search">False</property>
+                     </object>
+                   </child>
+                 </object>
+                 <packing>
+                   <property name="left_attach">1</property>
+                   <property name="right_attach">2</property>
+                   <property name="top_attach">1</property>
+                   <property name="bottom_attach">2</property>
+                   <property name="y_options">GTK_FILL</property>
+                 </packing>
+               </child>
+               <child>
+                 <object class="GtkTable" id="table4">
+                   <property name="visible">True</property>
+                   <property name="border_width">5</property>
+                   <property name="n_rows">2</property>
+                   <property name="n_columns">2</property>
+                   <property name="column_spacing">5</property>
+                   <property name="row_spacing">4</property>
+                   <child>
+                     <object class="GtkHBox" id="hbox4">
+                       <property name="visible">True</property>
+                       <child>
+                         <object class="GtkEntry" id="value_entry">
+                           <property name="width_request">85</property>
+                           <property name="visible">True</property>
+                           <property name="can_focus">True</property>
+                         </object>
+                         <packing>
+                           <property name="expand">False</property>
+                           <property name="fill">False</property>
+                           <property name="padding">1</property>
+                           <property name="position">0</property>
+                         </packing>
+                       </child>
+                     </object>
+                     <packing>
+                       <property name="left_attach">1</property>
+                       <property name="right_attach">2</property>
+                       <property name="x_options">GTK_FILL</property>
+                       <property name="y_options">GTK_FILL</property>
+                     </packing>
+                   </child>
+                   <child>
+                     <object class="GtkEntry" id="label_entry">
+                       <property name="visible">True</property>
+                       <property name="can_focus">True</property>
+                     </object>
+                     <packing>
+                       <property name="left_attach">1</property>
+                       <property name="right_attach">2</property>
+                       <property name="top_attach">1</property>
+                       <property name="bottom_attach">2</property>
+                       <property name="y_options"></property>
+                     </packing>
+                   </child>
+                   <child>
+                     <object class="GtkLabel" id="label6">
+                       <property name="visible">True</property>
+                       <property name="xalign">0</property>
+                       <property name="label" translatable="yes">Value Label:</property>
+                     </object>
+                     <packing>
+                       <property name="top_attach">1</property>
+                       <property name="bottom_attach">2</property>
+                       <property name="x_options">GTK_FILL</property>
+                       <property name="y_options"></property>
+                     </packing>
+                   </child>
+                   <child>
+                     <object class="GtkLabel" id="label5">
+                       <property name="visible">True</property>
+                       <property name="xalign">0</property>
+                       <property name="label" translatable="yes">Value:</property>
+                     </object>
+                     <packing>
+                       <property name="x_options">GTK_FILL</property>
+                       <property name="y_options"></property>
+                     </packing>
+                   </child>
+                 </object>
+                 <packing>
+                   <property name="right_attach">2</property>
+                   <property name="x_options">GTK_FILL</property>
+                   <property name="y_options"></property>
+                 </packing>
+               </child>
+               <child>
+                 <object class="GtkVButtonBox" id="vbuttonbox2">
+                   <property name="visible">True</property>
+                   <property name="border_width">5</property>
+                   <property name="orientation">vertical</property>
+                   <child>
+                     <object class="GtkButton" id="val_labs_add">
+                       <property name="label">gtk-add</property>
+                       <property name="visible">True</property>
+                       <property name="sensitive">False</property>
+                       <property name="can_focus">True</property>
+                       <property name="can_default">True</property>
+                       <property name="receives_default">False</property>
+                       <property name="use_stock">True</property>
+                     </object>
+                     <packing>
+                       <property name="expand">False</property>
+                       <property name="fill">False</property>
+                       <property name="position">0</property>
+                     </packing>
+                   </child>
+                   <child>
+                     <object class="GtkButton" id="val_labs_change">
+                       <property name="label">gtk-apply</property>
+                       <property name="visible">True</property>
+                       <property name="sensitive">False</property>
+                       <property name="can_focus">True</property>
+                       <property name="can_default">True</property>
+                       <property name="receives_default">False</property>
+                       <property name="use_stock">True</property>
+                     </object>
+                     <packing>
+                       <property name="expand">False</property>
+                       <property name="fill">False</property>
+                       <property name="position">1</property>
+                     </packing>
+                   </child>
+                   <child>
+                     <object class="GtkButton" id="val_labs_remove">
+                       <property name="label">gtk-remove</property>
+                       <property name="visible">True</property>
+                       <property name="sensitive">False</property>
+                       <property name="can_focus">True</property>
+                       <property name="can_default">True</property>
+                       <property name="receives_default">False</property>
+                       <property name="use_stock">True</property>
+                     </object>
+                     <packing>
+                       <property name="expand">False</property>
+                       <property name="fill">False</property>
+                       <property name="position">2</property>
+                     </packing>
+                   </child>
+                 </object>
+                 <packing>
+                   <property name="top_attach">1</property>
+                   <property name="bottom_attach">2</property>
+                   <property name="x_options">GTK_FILL</property>
+                 </packing>
+               </child>
+             </object>
+           </child>
+         </object>
+       </child>
+       <child type="label">
+         <object class="GtkLabel" id="label7">
+           <property name="visible">True</property>
+           <property name="label" translatable="yes">Value Labels</property>
+           <property name="use_markup">True</property>
+         </object>
+       </child>
+      </object>
+      <packing>
+       <property name="padding">10</property>
+       <property name="position">0</property>
+      </packing>
+    </child>
+    <child>
+      <object class="PsppireVButtonBox" id="vbuttonbox">
+       <property name="visible">True</property>
+       <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+       <property name="border_width">5</property>
+       <property name="buttons">PSPPIRE_BUTTON_CANCEL_MASK | PSPPIRE_BUTTON_OK_MASK | PSPPIRE_BUTTON_HELP_MASK</property>
+      </object>
+      <packing>
+       <property name="expand">False</property>
+       <property name="fill">False</property>
+       <property name="pack_type">end</property>
+       <property name="position">1</property>
+      </packing>
+    </child>
+  </object>
+</interface>
index cfba0b53bc0e22eff749e3a4f031549eb848f751..eb0c1246682d745d360c493baa4e4e8a78b986a0 100644 (file)
@@ -2,271 +2,6 @@
 <interface>
   <!-- interface-requires gtk+ 2.12 -->
   <!-- interface-naming-policy project-wide -->
-  <object class="GtkWindow" id="val_labs_dialog">
-    <property name="title" translatable="yes">Value Labels</property>
-    <property name="modal">True</property>
-    <property name="type_hint">dialog</property>
-    <property name="skip_taskbar_hint">True</property>
-    <property name="skip_pager_hint">True</property>
-    <child>
-      <object class="GtkHBox" id="hbox3">
-        <property name="visible">True</property>
-        <property name="border_width">5</property>
-        <child>
-          <object class="GtkFrame" id="frame1">
-            <property name="visible">True</property>
-            <property name="label_xalign">0</property>
-            <child>
-              <object class="GtkAlignment" id="alignment1">
-                <property name="visible">True</property>
-                <property name="border_width">8</property>
-                <property name="left_padding">12</property>
-                <child>
-                  <object class="GtkTable" id="table3">
-                    <property name="visible">True</property>
-                    <property name="n_rows">2</property>
-                    <property name="n_columns">2</property>
-                    <property name="row_spacing">5</property>
-                    <child>
-                      <object class="GtkScrolledWindow" id="scrolledwindow3">
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="hscrollbar_policy">automatic</property>
-                        <property name="vscrollbar_policy">automatic</property>
-                        <property name="shadow_type">etched-in</property>
-                        <child>
-                          <object class="GtkTreeView" id="treeview1">
-                            <property name="visible">True</property>
-                            <property name="can_focus">True</property>
-                            <property name="headers_visible">False</property>
-                            <property name="enable_search">False</property>
-                          </object>
-                        </child>
-                      </object>
-                      <packing>
-                        <property name="left_attach">1</property>
-                        <property name="right_attach">2</property>
-                        <property name="top_attach">1</property>
-                        <property name="bottom_attach">2</property>
-                        <property name="y_options">GTK_FILL</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkTable" id="table4">
-                        <property name="visible">True</property>
-                        <property name="border_width">5</property>
-                        <property name="n_rows">2</property>
-                        <property name="n_columns">2</property>
-                        <property name="column_spacing">5</property>
-                        <property name="row_spacing">4</property>
-                        <child>
-                          <object class="GtkHBox" id="hbox4">
-                            <property name="visible">True</property>
-                            <child>
-                              <object class="GtkEntry" id="value_entry">
-                                <property name="width_request">85</property>
-                                <property name="visible">True</property>
-                                <property name="can_focus">True</property>
-                              </object>
-                              <packing>
-                                <property name="expand">False</property>
-                                <property name="fill">False</property>
-                                <property name="padding">1</property>
-                                <property name="position">0</property>
-                              </packing>
-                            </child>
-                          </object>
-                          <packing>
-                            <property name="left_attach">1</property>
-                            <property name="right_attach">2</property>
-                            <property name="x_options">GTK_FILL</property>
-                            <property name="y_options">GTK_FILL</property>
-                          </packing>
-                        </child>
-                        <child>
-                          <object class="GtkEntry" id="label_entry">
-                            <property name="visible">True</property>
-                            <property name="can_focus">True</property>
-                          </object>
-                          <packing>
-                            <property name="left_attach">1</property>
-                            <property name="right_attach">2</property>
-                            <property name="top_attach">1</property>
-                            <property name="bottom_attach">2</property>
-                            <property name="y_options"></property>
-                          </packing>
-                        </child>
-                        <child>
-                          <object class="GtkLabel" id="label6">
-                            <property name="visible">True</property>
-                            <property name="xalign">0</property>
-                            <property name="label" translatable="yes">Value Label:</property>
-                          </object>
-                          <packing>
-                            <property name="top_attach">1</property>
-                            <property name="bottom_attach">2</property>
-                            <property name="x_options">GTK_FILL</property>
-                            <property name="y_options"></property>
-                          </packing>
-                        </child>
-                        <child>
-                          <object class="GtkLabel" id="label5">
-                            <property name="visible">True</property>
-                            <property name="xalign">0</property>
-                            <property name="label" translatable="yes">Value:</property>
-                          </object>
-                          <packing>
-                            <property name="x_options">GTK_FILL</property>
-                            <property name="y_options"></property>
-                          </packing>
-                        </child>
-                      </object>
-                      <packing>
-                        <property name="right_attach">2</property>
-                        <property name="x_options">GTK_FILL</property>
-                        <property name="y_options"></property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkVButtonBox" id="vbuttonbox2">
-                        <property name="visible">True</property>
-                        <property name="border_width">5</property>
-                        <property name="orientation">vertical</property>
-                        <child>
-                          <object class="GtkButton" id="val_labs_add">
-                            <property name="label">gtk-add</property>
-                            <property name="visible">True</property>
-                            <property name="sensitive">False</property>
-                            <property name="can_focus">True</property>
-                            <property name="can_default">True</property>
-                            <property name="receives_default">False</property>
-                            <property name="use_stock">True</property>
-                          </object>
-                          <packing>
-                            <property name="expand">False</property>
-                            <property name="fill">False</property>
-                            <property name="position">0</property>
-                          </packing>
-                        </child>
-                        <child>
-                          <object class="GtkButton" id="val_labs_change">
-                            <property name="label">gtk-apply</property>
-                            <property name="visible">True</property>
-                            <property name="sensitive">False</property>
-                            <property name="can_focus">True</property>
-                            <property name="can_default">True</property>
-                            <property name="receives_default">False</property>
-                            <property name="use_stock">True</property>
-                          </object>
-                          <packing>
-                            <property name="expand">False</property>
-                            <property name="fill">False</property>
-                            <property name="position">1</property>
-                          </packing>
-                        </child>
-                        <child>
-                          <object class="GtkButton" id="val_labs_remove">
-                            <property name="label">gtk-remove</property>
-                            <property name="visible">True</property>
-                            <property name="sensitive">False</property>
-                            <property name="can_focus">True</property>
-                            <property name="can_default">True</property>
-                            <property name="receives_default">False</property>
-                            <property name="use_stock">True</property>
-                          </object>
-                          <packing>
-                            <property name="expand">False</property>
-                            <property name="fill">False</property>
-                            <property name="position">2</property>
-                          </packing>
-                        </child>
-                      </object>
-                      <packing>
-                        <property name="top_attach">1</property>
-                        <property name="bottom_attach">2</property>
-                        <property name="x_options">GTK_FILL</property>
-                      </packing>
-                    </child>
-                  </object>
-                </child>
-              </object>
-            </child>
-            <child type="label">
-              <object class="GtkLabel" id="label7">
-                <property name="visible">True</property>
-                <property name="label" translatable="yes">Value Labels</property>
-                <property name="use_markup">True</property>
-              </object>
-            </child>
-          </object>
-          <packing>
-            <property name="padding">10</property>
-            <property name="position">0</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkVButtonBox" id="vbuttonbox3">
-            <property name="visible">True</property>
-            <property name="border_width">5</property>
-            <property name="orientation">vertical</property>
-            <property name="spacing">5</property>
-            <property name="layout_style">start</property>
-            <child>
-              <object class="GtkButton" id="val_labs_ok">
-                <property name="label">gtk-ok</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="receives_default">False</property>
-                <property name="use_stock">True</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">0</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkButton" id="val_labs_cancel">
-                <property name="label">gtk-cancel</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="receives_default">False</property>
-                <property name="use_stock">True</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">1</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkButton" id="help_button_value_labels">
-                <property name="label">gtk-help</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="receives_default">False</property>
-                <property name="use_stock">True</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">2</property>
-              </packing>
-            </child>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">False</property>
-            <property name="pack_type">end</property>
-            <property name="position">1</property>
-          </packing>
-        </child>
-      </object>
-    </child>
-  </object>
   <object class="GtkWindow" id="missing_values_dialog">
     <property name="border_width">12</property>
     <property name="title" translatable="yes">Missing Values</property>