Added infrastructure for GtkBuilder and change oneway-dialog to use it.
[pspp-builds.git] / src / ui / gui / psppire-dialog.c
index 90080094f8e2e5d4d4a22ea8ce1a09862abcca96..99e0ad7cdf08ef24977fd7b0754b8afd5ad7729d 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <gtk/gtk.h>
 #include <gtk/gtksignal.h>
+#include <gtk/gtkbuildable.h>
 #include "psppire-dialog.h"
 #include "psppire-buttonbox.h"
 #include "psppire-selector.h"
@@ -34,6 +35,9 @@ enum  {DIALOG_REFRESH,
 static guint signals [n_SIGNALS];
 
 
+static void psppire_dialog_buildable_init (GtkBuildableIface *iface);
+
+
 GType
 psppire_dialog_get_type (void)
 {
@@ -54,8 +58,20 @@ psppire_dialog_get_type (void)
        (GInstanceInitFunc) psppire_dialog_init,
       };
 
+      static const GInterfaceInfo buildable_info =
+      {
+       (GInterfaceInitFunc) psppire_dialog_buildable_init,
+       NULL,
+       NULL
+      };
+
       dialog_type = g_type_register_static (GTK_TYPE_WINDOW,
                                            "PsppireDialog", &dialog_info, 0);
+
+      g_type_add_interface_static (dialog_type,
+                                  GTK_TYPE_BUILDABLE,
+                                  &buildable_info);
+
     }
 
   return dialog_type;
@@ -106,6 +122,8 @@ psppire_dialog_get_property (GObject         *object,
          g_value_set_enum (value, PSPPIRE_VERTICAL);
        else if ( GTK_IS_HBOX (dialog->box))
          g_value_set_enum (value, PSPPIRE_HORIZONTAL);
+       else if ( GTK_IS_TABLE (dialog->box))
+         g_value_set_enum (value, PSPPIRE_TABULAR);
       }
       break;
     default:
@@ -125,13 +143,21 @@ dialog_set_orientation (PsppireDialog *dialog, const GValue *orval)
       gtk_container_remove (GTK_CONTAINER (dialog), dialog->box);
     }
 
-  if ( orientation == PSPPIRE_HORIZONTAL)
+  switch ( orientation )
     {
+    case PSPPIRE_HORIZONTAL:
       dialog->box = gtk_hbox_new (FALSE, 5);
-    }
-  else
-    {
+      break;
+    case PSPPIRE_VERTICAL:
       dialog->box = gtk_vbox_new (FALSE, 5);
+      break;
+    case PSPPIRE_TABULAR:
+      dialog->box = gtk_table_new (2, 3, FALSE);
+      g_object_set (dialog->box,
+                   "row-spacing", 5,
+                   "column-spacing", 5,
+                   NULL);
+      break;
     }
 
   gtk_container_add (GTK_CONTAINER (dialog), dialog->box);
@@ -277,8 +303,8 @@ psppire_dialog_new (void)
 }
 
 
-static void
-notify_change (PsppireDialog *dialog)
+void
+psppire_dialog_notify_change (PsppireDialog *dialog)
 {
   if ( dialog->contents_are_valid )
     {
@@ -290,7 +316,7 @@ notify_change (PsppireDialog *dialog)
 
 
 /* Descend the widget tree, connecting appropriate signals to the
-   notify_change callback */
+   psppire_dialog_notify_change callback */
 static void
 connect_notify_signal (GtkWidget *w, gpointer data)
 {
@@ -315,28 +341,33 @@ connect_notify_signal (GtkWidget *w, gpointer data)
 
   if ( GTK_IS_TOGGLE_BUTTON (w))
     {
-      g_signal_connect_swapped (w, "toggled", G_CALLBACK (notify_change),
+      g_signal_connect_swapped (w, "toggled",
+                               G_CALLBACK (psppire_dialog_notify_change),
                                dialog);
     }
 
   if ( PSPPIRE_IS_SELECTOR (w))
     {
-      g_signal_connect_swapped (w, "selected", G_CALLBACK (notify_change),
+      g_signal_connect_swapped (w, "selected",
+                               G_CALLBACK (psppire_dialog_notify_change),
                                dialog);
 
-      g_signal_connect_swapped (w, "de-selected", G_CALLBACK (notify_change),
+      g_signal_connect_swapped (w, "de-selected",
+                               G_CALLBACK (psppire_dialog_notify_change),
                                dialog);
     }
 
   if ( GTK_IS_EDITABLE (w))
     {
-      g_signal_connect_swapped (w, "changed", G_CALLBACK (notify_change),
+      g_signal_connect_swapped (w, "changed",
+                               G_CALLBACK (psppire_dialog_notify_change),
                                dialog);
     }
 
   if ( GTK_IS_CELL_EDITABLE (w))
     {
-      g_signal_connect_swapped (w, "editing-done", G_CALLBACK (notify_change),
+      g_signal_connect_swapped (w, "editing-done",
+                               G_CALLBACK (psppire_dialog_notify_change),
                                dialog);
     }
 
@@ -344,7 +375,8 @@ connect_notify_signal (GtkWidget *w, gpointer data)
     {
       GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (w));
 
-      g_signal_connect_swapped (buffer, "changed", G_CALLBACK (notify_change),
+      g_signal_connect_swapped (buffer, "changed",
+                               G_CALLBACK (psppire_dialog_notify_change),
                                dialog);
     }
 
@@ -355,9 +387,26 @@ connect_notify_signal (GtkWidget *w, gpointer data)
       GtkTreeSelection *selection =
        gtk_tree_view_get_selection (tv);
       GtkTreeViewColumn *col;
+      GtkTreeModel *model = gtk_tree_view_get_model (tv);
+
+      if ( model)
+       {
+      g_signal_connect_swapped (model, "row-changed",
+                               G_CALLBACK (psppire_dialog_notify_change),
+                               dialog);
+
+      g_signal_connect_swapped (model, "row-deleted",
+                               G_CALLBACK (psppire_dialog_notify_change),
+                               dialog);
+
+      g_signal_connect_swapped (model, "row-inserted",
+                               G_CALLBACK (psppire_dialog_notify_change),
+                               dialog);
+       }
 
       g_signal_connect_swapped (selection, "changed",
-                               G_CALLBACK (notify_change), dialog);
+                               G_CALLBACK (psppire_dialog_notify_change),
+                               dialog);
 
       while ((col = gtk_tree_view_get_column (tv, i++)))
        {
@@ -367,7 +416,7 @@ connect_notify_signal (GtkWidget *w, gpointer data)
            {
              if ( GTK_IS_CELL_RENDERER_TOGGLE (renderers->data))
                g_signal_connect_swapped (renderers->data, "toggled",
-                                         G_CALLBACK (notify_change), dialog);
+                                         G_CALLBACK (psppire_dialog_notify_change), dialog);
              renderers = renderers->next;
            }
          g_list_free (start);
@@ -395,6 +444,8 @@ psppire_dialog_run (PsppireDialog *dialog)
 
   g_main_loop_run (dialog->loop);
 
+  g_main_loop_unref (dialog->loop);
+
   return dialog->response;
 }
 
@@ -418,6 +469,7 @@ psppire_orientation_get_type (void)
        {
          { PSPPIRE_HORIZONTAL, "PSPPIRE_HORIZONTAL", "Horizontal" },
          { PSPPIRE_VERTICAL,   "PSPPIRE_VERTICAL",   "Vertical" },
+         { PSPPIRE_TABULAR,   "PSPPIRE_TABULAR",   "Tabular" },
          { 0, NULL, NULL }
        };
 
@@ -439,3 +491,26 @@ psppire_dialog_set_valid_predicate (PsppireDialog *dialog,
 }
 
 
+
+
+
+static GObject *
+get_internal_child    (GtkBuildable *buildable,
+                      GtkBuilder *builder,
+                      const gchar *childname)
+{
+  PsppireDialog *dialog = PSPPIRE_DIALOG (buildable);
+
+  if ( 0 == strcmp(childname, "hbox"))
+    return G_OBJECT (dialog->box);
+
+  return NULL;
+}
+
+
+
+static void
+psppire_dialog_buildable_init (GtkBuildableIface *iface)
+{
+  iface->get_internal_child = get_internal_child;
+}