/* PSPPIRE - a graphical user interface for PSPP.
- Copyright (C) 2007 Free Software Foundation
+ Copyright (C) 2007, 2010, 2011 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
#include <glib.h>
#include <gtk/gtk.h>
-#include <gtk/gtksignal.h>
#include "psppire-buttonbox.h"
#include "psppire-dialog.h"
+#include "helper.h"
+
#include <gettext.h>
#define _(msgid) gettext (msgid)
};
button_box_type = g_type_register_static (GTK_TYPE_BUTTON_BOX,
- "PsppireButtonBox", &button_box_info, 0);
+ "PsppireButtonBox", &button_box_info, G_TYPE_FLAG_ABSTRACT);
}
return button_box_type;
}
enum {
- PROP_BUTTONS = 1
+ PROP_BUTTONS = 1,
+ PROP_DEFAULT = 2
};
+static void
+set_default (PsppireButtonBox *bb)
+{
+ int i;
+
+ for (i = 0 ; i < n_PsppireButtonBoxButtons ; ++i )
+ if (bb->def == (1 << i))
+ {
+ gtk_widget_set_can_default (bb->button[i], TRUE);
+ gtk_widget_grab_default (bb->button[i]);
+ }
+}
+
static void
psppire_buttonbox_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
gint i;
guint flags;
PsppireButtonBox *bb = PSPPIRE_BUTTONBOX (object);
- if ( prop_id != PROP_BUTTONS)
+
+ switch (prop_id)
{
+ case PROP_BUTTONS:
+ flags = g_value_get_flags (value);
+ for (i = 0 ; i < n_PsppireButtonBoxButtons ; ++i )
+ g_object_set (bb->button[i], "visible", 0x01 & (flags >> i) , NULL);
+ break;
+
+ case PROP_DEFAULT:
+ bb->def = g_value_get_flags (value);
+ if (gtk_widget_get_realized (GTK_WIDGET (bb)))
+ set_default (bb);
+ break;
+
+ default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- return ;
}
-
- flags = g_value_get_flags (value);
-
- for (i = 0 ; i < n_PsppireButtonBoxButtons ; ++i )
- g_object_set (bb->button[i], "visible", 0x01 & (flags >> i) , NULL);
}
static void
psppire_buttonbox_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
guint flags = 0;
gint i;
PsppireButtonBox *bb = PSPPIRE_BUTTONBOX (object);
- if (PROP_BUTTONS != prop_id)
+ switch (prop_id)
{
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- return;
- }
+ case PROP_BUTTONS:
+ for (i = 0 ; i < n_PsppireButtonBoxButtons ; ++i )
+ {
+ gboolean visibility;
+ g_object_get (bb->button[i], "visible", &visibility, NULL);
- for (i = 0 ; i < n_PsppireButtonBoxButtons ; ++i )
- {
- gboolean visibility;
- g_object_get (bb->button[i], "visible", &visibility, NULL);
+ if ( visibility )
+ flags |= (0x01 << i);
+ }
- if ( visibility )
- flags |= (0x01 << i);
- }
+ g_value_set_flags (value, flags);
+ break;
- g_value_set_flags (value, flags);
+ case PROP_DEFAULT:
+ g_value_set_flags (value, bb->def);
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
}
} PsppireButtonMask;
static GParamSpec *button_flags;
+static GParamSpec *default_flags;
static void
psppire_button_box_class_init (PsppireButtonBoxClass *class)
button_flags =
g_param_spec_flags ("buttons",
- _("Buttons"),
- _("The mask that decides what buttons appear in the button box"),
- G_TYPE_PSPPIRE_BUTTON_MASK,
+ "Buttons",
+ "The mask that decides what buttons appear in the button box",
+ PSPPIRE_TYPE_BUTTON_MASK,
PSPPIRE_BUTTON_OK_MASK |
PSPPIRE_BUTTON_CANCEL_MASK |
PSPPIRE_BUTTON_RESET_MASK |
PSPPIRE_BUTTON_HELP_MASK |
PSPPIRE_BUTTON_PASTE_MASK,
G_PARAM_READWRITE);
-
-
g_object_class_install_property (object_class,
PROP_BUTTONS,
button_flags);
+ default_flags =
+ g_param_spec_flags ("default",
+ "Default",
+ "The mask that decides what what button grabs the default",
+ PSPPIRE_TYPE_BUTTON_MASK,
+ 0,
+ G_PARAM_READWRITE);
+ g_object_class_install_property (object_class,
+ PROP_DEFAULT,
+ default_flags);
}
static void
}
+
+static void
+on_validity_change (GtkWidget *toplevel, gboolean valid, gpointer data)
+{
+ PsppireButtonBox *bb = data;
+
+ /* Set the sensitivity of all the 'executive order' buttons */
+ gtk_widget_set_sensitive (GTK_WIDGET (bb->button[PSPPIRE_BUTTON_OK]), valid);
+ gtk_widget_set_sensitive (GTK_WIDGET (bb->button[PSPPIRE_BUTTON_PASTE]), valid);
+ gtk_widget_set_sensitive (GTK_WIDGET (bb->button[PSPPIRE_BUTTON_GOTO]), valid);
+ gtk_widget_set_sensitive (GTK_WIDGET (bb->button[PSPPIRE_BUTTON_CONTINUE]), valid);
+}
+
+static void
+on_realize (GtkWidget *buttonbox, gpointer data)
+{
+ GtkWidget *toplevel = gtk_widget_get_toplevel (buttonbox);
+
+ if ( PSPPIRE_IS_DIALOG (toplevel))
+ {
+ g_signal_connect (toplevel, "validity-changed",
+ G_CALLBACK (on_validity_change), buttonbox);
+ }
+ set_default (PSPPIRE_BUTTONBOX (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);
- gtk_box_pack_start_defaults (GTK_BOX (bb), bb->button[PSPPIRE_BUTTON_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);
g_object_set (bb->button[PSPPIRE_BUTTON_OK], "no-show-all", TRUE, NULL);
bb->button[PSPPIRE_BUTTON_GOTO] =
gtk_button_new_from_stock (GTK_STOCK_JUMP_TO);
- gtk_box_pack_start_defaults (GTK_BOX (bb), bb->button[PSPPIRE_BUTTON_GOTO]);
+ 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);
g_object_set (bb->button[PSPPIRE_BUTTON_GOTO], "no-show-all", TRUE, NULL);
bb->button[PSPPIRE_BUTTON_CONTINUE] =
gtk_button_new_with_mnemonic (_("Continue"));
- gtk_box_pack_start_defaults (GTK_BOX (bb),
+ psppire_box_pack_start_defaults (GTK_BOX (bb),
bb->button[PSPPIRE_BUTTON_CONTINUE]);
g_signal_connect (bb->button[PSPPIRE_BUTTON_CONTINUE], "clicked",
G_CALLBACK (continue_button_clicked), NULL);
- bb->button[PSPPIRE_BUTTON_PASTE] = gtk_button_new_with_mnemonic (_("_Paste"));
+ bb->button[PSPPIRE_BUTTON_PASTE] = gtk_button_new_from_stock (GTK_STOCK_PASTE);
g_signal_connect (bb->button[PSPPIRE_BUTTON_PASTE], "clicked",
G_CALLBACK (paste_button_clicked), NULL);
- gtk_box_pack_start_defaults (GTK_BOX (bb), bb->button[PSPPIRE_BUTTON_PASTE]);
+ 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);
g_signal_connect (bb->button[PSPPIRE_BUTTON_CANCEL], "clicked",
G_CALLBACK (close_dialog), NULL);
- gtk_box_pack_start_defaults (GTK_BOX (bb), bb->button[PSPPIRE_BUTTON_CANCEL]);
+ 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_RESET] = gtk_button_new_from_stock (GTK_STOCK_REFRESH);
+ bb->button[PSPPIRE_BUTTON_RESET] = gtk_button_new_from_stock ("pspp-stock-reset");
g_signal_connect (bb->button[PSPPIRE_BUTTON_RESET], "clicked",
G_CALLBACK (refresh_clicked), NULL);
- gtk_box_pack_start_defaults (GTK_BOX (bb), bb->button[PSPPIRE_BUTTON_RESET]);
+ 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);
- gtk_box_pack_start_defaults (GTK_BOX (bb), bb->button[PSPPIRE_BUTTON_HELP]);
+ psppire_box_pack_start_defaults (GTK_BOX (bb), bb->button[PSPPIRE_BUTTON_HELP]);
g_object_set (bb->button[PSPPIRE_BUTTON_HELP], "no-show-all", TRUE, NULL);
g_value_unset (&value);
}
+
+ g_signal_connect (bb, "realize", G_CALLBACK (on_realize), NULL);
}
child = children->data;
children = children->next;
- if (GTK_WIDGET_VISIBLE (child->widget))
+ if (gtk_widget_get_visible (child->widget))
{
nchildren += 1;
gtk_widget_size_request (child->widget, &child_requisition);