Added "comments" dialog.
[pspp-builds.git] / src / ui / gui / psppire-dialog.c
index f0d76de9bbff71954e95e0c6c03e6ade719af687..6eccb77c4daf17aa2f5f1443bd9d46cdfad63297 100644 (file)
@@ -81,11 +81,110 @@ psppire_dialog_finalize (GObject *object)
 }
 
 
+
+/* Properties */
+enum
+{
+  PROP_0,
+  PROP_ORIENTATION
+};
+
+
+static void
+psppire_dialog_get_property (GObject         *object,
+                            guint            prop_id,
+                            GValue          *value,
+                            GParamSpec      *pspec)
+{
+  PsppireDialog *dialog = PSPPIRE_DIALOG (object);
+
+  switch (prop_id)
+    {
+    case PROP_ORIENTATION:
+      {
+       if ( GTK_IS_VBOX (dialog->box) )
+         g_value_set_enum (value, PSPPIRE_VERTICAL);
+       else if ( GTK_IS_HBOX (dialog->box))
+         g_value_set_enum (value, PSPPIRE_HORIZONTAL);
+      }
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    };
+}
+
+
+static void
+dialog_set_orientation (PsppireDialog *dialog, const GValue *orval)
+{
+  PsppireOrientation orientation = g_value_get_enum (orval);
+
+  if ( dialog->box != NULL)
+    {
+      gtk_container_remove (GTK_CONTAINER (dialog), dialog->box);
+    }
+
+  if ( orientation == PSPPIRE_HORIZONTAL)
+    {
+      dialog->box = gtk_hbox_new (FALSE, 5);
+    }
+  else
+    {
+      dialog->box = gtk_vbox_new (FALSE, 5);
+    }
+
+  gtk_container_add (GTK_CONTAINER (dialog), dialog->box);
+}
+
+
+static void
+psppire_dialog_set_property (GObject         *object,
+                            guint            prop_id,
+                            const GValue    *value,
+                            GParamSpec      *pspec)
+
+{
+  PsppireDialog *dialog = PSPPIRE_DIALOG (object);
+
+  switch (prop_id)
+    {
+    case PROP_ORIENTATION:
+      dialog_set_orientation (dialog, value);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    };
+}
+
+
+static GParamSpec *orientation_spec ;
+
 static void
 psppire_dialog_class_init (PsppireDialogClass *class)
 {
   GObjectClass *object_class = (GObjectClass *) class;
 
+
+  orientation_spec =
+    g_param_spec_enum ("orientation",
+                      "Orientation",
+                      "Which way widgets are packed",
+                      G_TYPE_PSPPIRE_ORIENTATION,
+                      PSPPIRE_HORIZONTAL /* default value */,
+                      G_PARAM_CONSTRUCT_ONLY |G_PARAM_READWRITE);
+
+
+  object_class->set_property = psppire_dialog_set_property;
+  object_class->get_property = psppire_dialog_get_property;
+
+  g_object_class_install_property (object_class,
+                                   PROP_ORIENTATION,
+                                   orientation_spec);
+
+
+
   signals [DIALOG_REFRESH] =
     g_signal_new ("refresh",
                  G_TYPE_FROM_CLASS (class),
@@ -129,11 +228,15 @@ delete_event_callback (GtkWidget *w, GdkEvent *e, gpointer data)
 static void
 psppire_dialog_init (PsppireDialog *dialog)
 {
-  dialog->box = gtk_hbox_new (FALSE, 5);
+  GValue value = {0};
+  dialog->box = NULL;
 
+  g_value_init (&value, orientation_spec->value_type);
+  g_param_value_set_default (orientation_spec, &value);
 
-  gtk_container_add (GTK_CONTAINER (dialog), dialog->box);
+  dialog_set_orientation (dialog, &value);
 
+  g_value_unset (&value);
 
   g_signal_connect (G_OBJECT (dialog), "delete-event",
                    G_CALLBACK (delete_event_callback),
@@ -173,3 +276,26 @@ psppire_dialog_reload (PsppireDialog *dialog)
 {
   g_signal_emit (dialog, signals [DIALOG_REFRESH], 0);
 }
+
+
+
+
+GType
+psppire_orientation_get_type (void)
+{
+  static GType etype = 0;
+  if (etype == 0)
+    {
+      static const GEnumValue values[] =
+       {
+         { PSPPIRE_HORIZONTAL, "PSPPIRE_HORIZONTAL", "Horizontal" },
+         { PSPPIRE_VERTICAL,   "PSPPIRE_VERTICAL",   "Vertical" },
+         { 0, NULL, NULL }
+       };
+
+      etype = g_enum_register_static
+       (g_intern_static_string ("PsppireOrientation"), values);
+
+    }
+  return etype;
+}