Yuri Chornoivan contributed some typo fixes
[pspp] / src / ui / gui / psppire-buttonbox.c
index a9480a331198e450fa5a5056531d76edbba79040..a01518994738513898083b8d878572224239548a 100644 (file)
 
 GType psppire_button_flags_get_type (void);
 
-
-static void psppire_button_box_class_init          (PsppireButtonBoxClass *);
-static void psppire_button_box_init                (PsppireButtonBox      *);
-
-
-GType
-psppire_button_box_get_type (void)
-{
-  static GType button_box_type = 0;
-
-  if (!button_box_type)
-    {
-      static const GTypeInfo button_box_info =
-      {
-       sizeof (PsppireButtonBoxClass),
-       NULL, /* base_init */
-        NULL, /* base_finalize */
-       (GClassInitFunc) psppire_button_box_class_init,
-        NULL, /* class_finalize */
-       NULL, /* class_data */
-        sizeof (PsppireButtonBox),
-       0,
-       (GInstanceInitFunc) psppire_button_box_init,
-      };
-
-      button_box_type = g_type_register_static (GTK_TYPE_BUTTON_BOX,
-                                           "PsppireButtonBox", &button_box_info, G_TYPE_FLAG_ABSTRACT);
-    }
-
-  return button_box_type;
-}
+G_DEFINE_TYPE (PsppireButtonBox, psppire_button_box, GTK_TYPE_BUTTON_BOX)
 
 enum {
   PROP_BUTTONS = 1,
@@ -73,7 +43,7 @@ set_default (PsppireButtonBox *bb)
 {
   int i;
 
-  for (i = 0 ; i < n_PsppireButtonBoxButtons ; ++i )
+  for (i = 0 ; i < n_PsppireButtonBoxButtons ; ++i)
     if (bb->def == (1 << i))
       {
         gtk_widget_set_can_default (bb->button[i], TRUE);
@@ -89,13 +59,13 @@ psppire_buttonbox_set_property (GObject         *object,
 {
   gint i;
   guint flags;
-  PsppireButtonBox *bb = PSPPIRE_BUTTONBOX (object);
+  PsppireButtonBox *bb = PSPPIRE_BUTTON_BOX (object);
 
   switch (prop_id)
     {
     case PROP_BUTTONS:
       flags = g_value_get_flags (value);
-      for (i = 0 ; i < n_PsppireButtonBoxButtons ; ++i )
+      for (i = 0 ; i < n_PsppireButtonBoxButtons ; ++i)
         g_object_set (bb->button[i], "visible", 0x01 & (flags >> i)  , NULL);
       break;
 
@@ -119,17 +89,17 @@ psppire_buttonbox_get_property (GObject         *object,
   guint flags = 0;
   gint i;
 
-  PsppireButtonBox *bb = PSPPIRE_BUTTONBOX (object);
+  PsppireButtonBox *bb = PSPPIRE_BUTTON_BOX (object);
 
   switch (prop_id)
     {
     case PROP_BUTTONS:
-      for (i = 0 ; i < n_PsppireButtonBoxButtons ; ++i )
+      for (i = 0 ; i < n_PsppireButtonBoxButtons ; ++i)
         {
           gboolean visibility;
           g_object_get (bb->button[i], "visible", &visibility, NULL);
 
-          if ( visibility )
+          if (visibility)
             flags |= (0x01 << i);
         }
 
@@ -138,6 +108,7 @@ psppire_buttonbox_get_property (GObject         *object,
 
     case PROP_DEFAULT:
       g_value_set_flags (value, bb->def);
+      break;
 
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -146,18 +117,6 @@ psppire_buttonbox_get_property (GObject         *object,
 }
 
 
-typedef enum
-  {
-    PSPPIRE_BUTTON_OK_MASK     = (1 << PSPPIRE_BUTTON_OK),
-    PSPPIRE_BUTTON_GOTO_MASK   = (1 << PSPPIRE_BUTTON_GOTO),
-    PSPPIRE_BUTTON_CONTINUE_MASK = (1 << PSPPIRE_BUTTON_CONTINUE),
-    PSPPIRE_BUTTON_CANCEL_MASK = (1 << PSPPIRE_BUTTON_CANCEL),
-    PSPPIRE_BUTTON_CLOSE_MASK  = (1 << PSPPIRE_BUTTON_CLOSE),
-    PSPPIRE_BUTTON_HELP_MASK   = (1 << PSPPIRE_BUTTON_HELP),
-    PSPPIRE_BUTTON_RESET_MASK  = (1 << PSPPIRE_BUTTON_RESET),
-    PSPPIRE_BUTTON_PASTE_MASK  = (1 << PSPPIRE_BUTTON_PASTE)
-  } PsppireButtonMask;
-
 static GParamSpec *button_flags;
 static GParamSpec *default_flags;
 
@@ -187,7 +146,7 @@ psppire_button_box_class_init (PsppireButtonBoxClass *class)
   default_flags =
     g_param_spec_flags ("default",
                        "Default",
-                       "The mask that decides what what button grabs the default",
+                       "The mask that decides what button grabs the default",
                        PSPPIRE_TYPE_BUTTON_MASK,
                        0,
                        G_PARAM_READWRITE);
@@ -205,7 +164,7 @@ close_and_respond (GtkWidget *w, gint response)
 
   /* If we're not in a psppire dialog (for example when in glade)
      then do nothing */
-  if ( ! PSPPIRE_IS_DIALOG (toplevel))
+  if (! PSPPIRE_IS_DIALOG (toplevel))
     return;
 
   dialog = PSPPIRE_DIALOG (toplevel);
@@ -267,7 +226,7 @@ refresh_clicked (GtkWidget *w, gpointer data)
   GtkWidget *toplevel = gtk_widget_get_toplevel (w);
   PsppireDialog *dialog;
 
-  if ( ! PSPPIRE_IS_DIALOG (toplevel))
+  if (! PSPPIRE_IS_DIALOG (toplevel))
     return;
 
   dialog = PSPPIRE_DIALOG (toplevel);
@@ -275,15 +234,13 @@ refresh_clicked (GtkWidget *w, gpointer data)
   psppire_dialog_reload (dialog);
 }
 
-
-
 static void
 help_clicked (GtkWidget *w, gpointer data)
 {
   GtkWidget *toplevel = gtk_widget_get_toplevel (w);
   PsppireDialog *dialog;
 
-  if ( ! PSPPIRE_IS_DIALOG (toplevel))
+  if (! PSPPIRE_IS_DIALOG (toplevel))
     return;
 
   dialog = PSPPIRE_DIALOG (toplevel);
@@ -291,8 +248,6 @@ help_clicked (GtkWidget *w, gpointer data)
   psppire_dialog_help (dialog);
 }
 
-
-
 static void
 on_validity_change (GtkWidget *toplevel, gboolean valid, gpointer data)
 {
@@ -305,25 +260,43 @@ on_validity_change (GtkWidget *toplevel, gboolean valid, gpointer data)
   gtk_widget_set_sensitive (GTK_WIDGET (bb->button[PSPPIRE_BUTTON_CONTINUE]), valid);
 }
 
+static gboolean
+on_key_press (GtkWidget *w, GdkEventKey *e, gpointer ud)
+{
+  PsppireButtonBox *bb = PSPPIRE_BUTTON_BOX (ud);
+  if (e->keyval == GDK_KEY_Escape)
+    {
+      g_signal_emit_by_name (bb->button[PSPPIRE_BUTTON_CANCEL], "activate");
+      g_signal_emit_by_name (bb->button[PSPPIRE_BUTTON_CLOSE], "activate");
+    }
+  return FALSE;
+}
+
+
 static void
 on_realize (GtkWidget *buttonbox, gpointer data)
 {
   GtkWidget *toplevel = gtk_widget_get_toplevel (buttonbox);
 
-  if ( PSPPIRE_IS_DIALOG (toplevel))
+  if (PSPPIRE_IS_DIALOG (toplevel))
     {
       g_signal_connect (toplevel, "validity-changed",
                        G_CALLBACK (on_validity_change), buttonbox);
+
+      g_signal_connect (toplevel, "key-press-event",
+                       G_CALLBACK (on_key_press), buttonbox);
     }
-  set_default (PSPPIRE_BUTTONBOX (buttonbox));
+
+  set_default (PSPPIRE_BUTTON_BOX (buttonbox));
 }
 
+
 static void
 psppire_button_box_init (PsppireButtonBox *bb)
 {
   bb->def = PSPPIRE_BUTTON_CONTINUE;
 
-  bb->button[PSPPIRE_BUTTON_OK] = gtk_button_new_from_stock (GTK_STOCK_OK);
+  bb->button[PSPPIRE_BUTTON_OK] = gtk_button_new_with_label (_("OK"));
   psppire_box_pack_start_defaults (GTK_BOX (bb), bb->button[PSPPIRE_BUTTON_OK]);
   g_signal_connect (bb->button[PSPPIRE_BUTTON_OK], "clicked",
                    G_CALLBACK (ok_button_clicked), NULL);
@@ -331,7 +304,7 @@ psppire_button_box_init (PsppireButtonBox *bb)
 
 
   bb->button[PSPPIRE_BUTTON_GOTO] =
-    gtk_button_new_from_stock (GTK_STOCK_JUMP_TO);
+    gtk_button_new_with_label (_("Go To"));
   psppire_box_pack_start_defaults (GTK_BOX (bb), bb->button[PSPPIRE_BUTTON_GOTO]);
   g_signal_connect (bb->button[PSPPIRE_BUTTON_GOTO], "clicked",
                    G_CALLBACK (goto_button_clicked), NULL);
@@ -351,33 +324,33 @@ psppire_button_box_init (PsppireButtonBox *bb)
 
 
 
-  bb->button[PSPPIRE_BUTTON_PASTE] = gtk_button_new_from_stock (GTK_STOCK_PASTE);
+  bb->button[PSPPIRE_BUTTON_PASTE] = gtk_button_new_with_label (_("Paste"));
   g_signal_connect (bb->button[PSPPIRE_BUTTON_PASTE], "clicked",
                    G_CALLBACK (paste_button_clicked), NULL);
   psppire_box_pack_start_defaults (GTK_BOX (bb), bb->button[PSPPIRE_BUTTON_PASTE]);
   g_object_set (bb->button[PSPPIRE_BUTTON_PASTE], "no-show-all", TRUE, NULL);
 
-  bb->button[PSPPIRE_BUTTON_CANCEL] = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
+  bb->button[PSPPIRE_BUTTON_CANCEL] = gtk_button_new_with_label (_("Cancel"));
   g_signal_connect (bb->button[PSPPIRE_BUTTON_CANCEL], "clicked",
                    G_CALLBACK (close_dialog), NULL);
   psppire_box_pack_start_defaults (GTK_BOX (bb), bb->button[PSPPIRE_BUTTON_CANCEL]);
   g_object_set (bb->button[PSPPIRE_BUTTON_CANCEL], "no-show-all", TRUE, NULL);
 
-  bb->button[PSPPIRE_BUTTON_CLOSE] = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
+  bb->button[PSPPIRE_BUTTON_CLOSE] = gtk_button_new_with_label (_("Close"));
   g_signal_connect (bb->button[PSPPIRE_BUTTON_CLOSE], "clicked",
                    G_CALLBACK (close_dialog), NULL);
   psppire_box_pack_start_defaults (GTK_BOX (bb), bb->button[PSPPIRE_BUTTON_CLOSE]);
   g_object_set (bb->button[PSPPIRE_BUTTON_CLOSE], "no-show-all", TRUE, NULL);
 
 
-  bb->button[PSPPIRE_BUTTON_RESET] = gtk_button_new_from_stock ("pspp-stock-reset");
+  bb->button[PSPPIRE_BUTTON_RESET] = gtk_button_new_with_label (_("Reset"));
   g_signal_connect (bb->button[PSPPIRE_BUTTON_RESET], "clicked",
                    G_CALLBACK (refresh_clicked), NULL);
   psppire_box_pack_start_defaults (GTK_BOX (bb), bb->button[PSPPIRE_BUTTON_RESET]);
   g_object_set (bb->button[PSPPIRE_BUTTON_RESET], "no-show-all", TRUE, NULL);
 
 
-  bb->button[PSPPIRE_BUTTON_HELP] = gtk_button_new_from_stock (GTK_STOCK_HELP);
+  bb->button[PSPPIRE_BUTTON_HELP] = gtk_button_new_with_label (_("Help"));
   g_signal_connect (bb->button[PSPPIRE_BUTTON_HELP], "clicked",
                    G_CALLBACK (help_clicked), NULL);
   psppire_box_pack_start_defaults (GTK_BOX (bb), bb->button[PSPPIRE_BUTTON_HELP]);
@@ -395,7 +368,7 @@ psppire_button_box_init (PsppireButtonBox *bb)
 
     flags = g_value_get_flags (&value);
 
-    for (i = 0 ; i < n_PsppireButtonBoxButtons ; ++i )
+    for (i = 0 ; i < n_PsppireButtonBoxButtons ; ++i)
       g_object_set (bb->button[i], "visible", 0x01 & (flags >> i)  , NULL);
 
     g_value_unset (&value);
@@ -405,99 +378,6 @@ psppire_button_box_init (PsppireButtonBox *bb)
   g_signal_connect (bb, "realize", G_CALLBACK (on_realize), NULL);
 }
 
-
-/* This function was lifted verbatim from the Gtk2.10.6 library.
-   But later modified to fit Gtk2.24
- */
-void
-_psppire_button_box_child_requisition (GtkWidget *widget,
-                                      int       *nvis_children,
-                                      int       *nvis_secondaries,
-                                      int       *width,
-                                      int       *height)
-{
-  GtkButtonBox *bbox;
-  GList *children;
-  gint nchildren;
-  gint nsecondaries;
-  gint needed_width;
-  gint needed_height;
-  GtkRequisition child_requisition;
-  gint ipad_w;
-  gint ipad_h;
-  gint width_default;
-  gint height_default;
-  gint ipad_x_default;
-  gint ipad_y_default;
-
-  gint child_min_width;
-  gint child_min_height;
-  gint ipad_x;
-  gint ipad_y;
-
-  g_return_if_fail (GTK_IS_BUTTON_BOX (widget));
-
-  bbox = GTK_BUTTON_BOX (widget);
-
-  gtk_widget_style_get (widget,
-                        "child-min-width", &width_default,
-                        "child-min-height", &height_default,
-                        "child-internal-pad-x", &ipad_x_default,
-                        "child-internal-pad-y", &ipad_y_default,
-                       NULL);
-
-  child_min_width = bbox->child_min_width   != GTK_BUTTONBOX_DEFAULT
-    ? bbox->child_min_width : width_default;
-  child_min_height = bbox->child_min_height !=GTK_BUTTONBOX_DEFAULT
-    ? bbox->child_min_height : height_default;
-  ipad_x = bbox->child_ipad_x != GTK_BUTTONBOX_DEFAULT
-    ? bbox->child_ipad_x : ipad_x_default;
-  ipad_y = bbox->child_ipad_y != GTK_BUTTONBOX_DEFAULT
-    ? bbox->child_ipad_y : ipad_y_default;
-
-  nchildren = 0;
-  nsecondaries = 0;
-
-  needed_width = child_min_width;
-  needed_height = child_min_height;
-  ipad_w = ipad_x * 2;
-  ipad_h = ipad_y * 2;
-
-  children = gtk_container_get_children (GTK_CONTAINER (bbox));
-  while (children)
-    {
-      GtkWidget *child = children->data;
-      children = children->next;
-
-      if (gtk_widget_get_visible (child))
-       {
-          gboolean is_secondary = FALSE;
-         nchildren += 1;
-         gtk_widget_size_request (child, &child_requisition);
-
-         if (child_requisition.width + ipad_w > needed_width)
-           needed_width = child_requisition.width + ipad_w;
-         if (child_requisition.height + ipad_h > needed_height)
-           needed_height = child_requisition.height + ipad_h;
-
-          gtk_container_child_get (GTK_CONTAINER (bbox), child, "secondary", &is_secondary, NULL);
-
-          if (is_secondary)
-           nsecondaries++;
-       }
-    }
-
-  if (nvis_children)
-    *nvis_children = nchildren;
-  if (nvis_secondaries)
-    *nvis_secondaries = nsecondaries;
-  if (width)
-    *width = needed_width;
-  if (height)
-    *height = needed_height;
-}
-
-
 GType
 psppire_button_flags_get_type (void)
 {
@@ -516,7 +396,7 @@ psppire_button_flags_get_type (void)
          { PSPPIRE_BUTTON_PASTE_MASK,   "PSPPIRE_BUTTON_PASTE_MASK",    "Accept dialog and paste syntax" },
          { 0, NULL, NULL }
        };
-      
+
       ftype = g_flags_register_static
        (g_intern_static_string ("PsppireButtonFlags"), values);
 
@@ -524,3 +404,8 @@ psppire_button_flags_get_type (void)
   return ftype;
 }
 
+GtkWidget*
+psppire_button_box_new (void)
+{
+  return GTK_WIDGET (g_object_new (psppire_button_box_get_type (), NULL));
+}