cairo: Add support for png and trim.
[pspp] / src / ui / gui / psppire-dialog-action.c
index 70a5a9d4aa93cc805c202b1529a57afac077c6c2..f0caabae726872c980ce7e6a8ac6c0652f252713 100644 (file)
 #include "executor.h"
 #include "helper.h"
 #include "psppire-data-window.h"
-
-static void psppire_dialog_action_init            (PsppireDialogAction      *act);
-static void psppire_dialog_action_class_init      (PsppireDialogActionClass *class);
+#include "builder-wrapper.h"
 
 static GObjectClass * parent_class = NULL;
 
-
 static const gchar *
 __get_name (GAction *act)
 {
@@ -88,44 +85,11 @@ action_model_init (GActionInterface *iface)
   iface->activate = __activate;
 }
 
-
-GType
-psppire_dialog_action_get_type (void)
-{
-  static GType de_type = 0;
-
-  if (!de_type)
-    {
-      static const GTypeInfo de_info =
-      {
-       sizeof (PsppireDialogActionClass),
-       NULL, /* base_init */
-        NULL, /* base_finalize */
-       (GClassInitFunc) psppire_dialog_action_class_init,
-        NULL, /* class_finalize */
-       NULL, /* class_data */
-        sizeof (PsppireDialogAction),
-       0,
-       (GInstanceInitFunc) psppire_dialog_action_init,
-      };
-
-
-      static const GInterfaceInfo ga_info = {
-       (GInterfaceInitFunc) action_model_init,
-       NULL,
-       NULL
-      };
-
-
-      de_type = g_type_register_static (G_TYPE_OBJECT, "PsppireDialogAction",
-                                       &de_info, G_TYPE_FLAG_ABSTRACT);
-
-      g_type_add_interface_static (de_type, G_TYPE_ACTION, &ga_info);
-    }
-
-  return de_type;
-}
-
+G_DEFINE_ABSTRACT_TYPE_WITH_CODE (PsppireDialogAction, \
+                                 psppire_dialog_action, \
+                                 G_TYPE_OBJECT, \
+                                 G_IMPLEMENT_INTERFACE (G_TYPE_ACTION, \
+                                                        action_model_init))
 
 /* Properties */
 enum
@@ -201,7 +165,7 @@ on_destroy_dataset (GObject *w)
 
    This is useful for storing the state of dialogs so they can persist between invocations.
 */
-GHashTable *
+static GHashTable *
 psppire_dialog_action_get_hash_table (PsppireDialogAction *act)
 {
   GHashTable *t = g_object_get_data (G_OBJECT (act->toplevel), "thing-table");
@@ -216,6 +180,14 @@ psppire_dialog_action_get_hash_table (PsppireDialogAction *act)
   return t;
 }
 
+GtkBuilder *
+psppire_dialog_action_get_xml (PsppireDialogAction *da)
+{
+  GHashTable *thing = psppire_dialog_action_get_hash_table (da);
+  GtkBuilder *xml = g_hash_table_lookup (thing, da);
+  return xml;
+}
+
 
 static void
 psppire_dialog_action_activate (PsppireDialogAction *act, GVariant *parameter)
@@ -230,8 +202,24 @@ psppire_dialog_action_activate (PsppireDialogAction *act, GVariant *parameter)
   wl = g_slist_prepend (wl, act->dialog);
   g_object_set_data (G_OBJECT (act->toplevel), "widget-list", wl);
 
+  if (class->initial_activate)
+    {
+      GHashTable *thing = psppire_dialog_action_get_hash_table (act);
+      GtkBuilder *xml = g_hash_table_lookup (thing, act);
+      if (xml == NULL)
+       {
+         xml = class->initial_activate (act, parameter);
+         g_hash_table_insert (thing, act, xml);
+       }
+    }
+
   if (class->activate)
-    class->activate (act, parameter);
+    {
+      GHashTable *thing = psppire_dialog_action_get_hash_table (act);
+      GtkBuilder *xml = g_hash_table_lookup (thing, act);
+      if (xml != NULL)
+       class->activate (act, parameter);
+    }
 
   gtk_window_set_transient_for (GTK_WINDOW (act->dialog),
                                GTK_WINDOW (act->toplevel));
@@ -249,7 +237,7 @@ psppire_dialog_action_activate (PsppireDialogAction *act, GVariant *parameter)
 
   response = psppire_dialog_run (PSPPIRE_DIALOG (act->dialog));
 
-  if ( class->generate_syntax )
+  if (class->generate_syntax)
     {
       switch (response)
        {
@@ -285,8 +273,6 @@ psppire_dialog_action_class_init (PsppireDialogActionClass *class)
 
   class->generate_syntax = NULL;
 
-  class->activate = psppire_dialog_action_activate;
-
   g_object_class_install_property (object_class,
                                    PROP_TOPLEVEL,
                                    toplevel_spec);
@@ -322,11 +308,3 @@ psppire_dialog_action_set_refresh (PsppireDialogAction *pda,
 {
   g_signal_connect_swapped (pda->dialog, "refresh", G_CALLBACK (refresh),  pda);
 }
-
-
-void
-psppire_dialog_action_set_activation (gpointer class, activation activate)
-{
-  PSPPIRE_DIALOG_ACTION_CLASS (class)->activate = (void (*)(PsppireDialogAction *, GVariant *)) activate;
-}
-