From: Ben Pfaff Date: Tue, 3 May 2011 13:47:24 +0000 (-0700) Subject: psppire-buttonbox: Add "default" property. X-Git-Tag: v0.7.8~7 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pspp-builds.git;a=commitdiff_plain;h=6bb9fb8db1002ec00f58cae414a06769fe1a7e68 psppire-buttonbox: Add "default" property. This property allows the default button to be controlled from a GtkBuilder description, instead of forcing the default to Continue. Only a single bit should be set in the "default" mask. --- diff --git a/src/ui/gui/psppire-buttonbox.c b/src/ui/gui/psppire-buttonbox.c index c3b94dd0..a6b00689 100644 --- a/src/ui/gui/psppire-buttonbox.c +++ b/src/ui/gui/psppire-buttonbox.c @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2007, 2010 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 @@ -64,57 +64,85 @@ psppire_button_box_get_type (void) } 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; + + case PROP_DEFAULT: + g_value_set_flags (value, bb->def); - g_value_set_flags (value, flags); + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } } @@ -130,6 +158,7 @@ typedef enum } PsppireButtonMask; static GParamSpec *button_flags; +static GParamSpec *default_flags; static void psppire_button_box_class_init (PsppireButtonBoxClass *class) @@ -150,12 +179,20 @@ psppire_button_box_class_init (PsppireButtonBoxClass *class) 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 @@ -249,11 +286,13 @@ on_realize (GtkWidget *buttonbox, gpointer data) 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); psppire_box_pack_start_defaults (GTK_BOX (bb), bb->button[PSPPIRE_BUTTON_OK]); @@ -273,12 +312,6 @@ psppire_button_box_init (PsppireButtonBox *bb) bb->button[PSPPIRE_BUTTON_CONTINUE] = gtk_button_new_with_mnemonic (_("Continue")); - GTK_WIDGET_SET_FLAGS (bb->button[PSPPIRE_BUTTON_CONTINUE], - GTK_CAN_DEFAULT); - - g_signal_connect (bb->button[PSPPIRE_BUTTON_CONTINUE], "realize", - G_CALLBACK (gtk_widget_grab_default), NULL); - psppire_box_pack_start_defaults (GTK_BOX (bb), bb->button[PSPPIRE_BUTTON_CONTINUE]); g_signal_connect (bb->button[PSPPIRE_BUTTON_CONTINUE], "clicked", diff --git a/src/ui/gui/psppire-buttonbox.h b/src/ui/gui/psppire-buttonbox.h index 632e0fd3..654f1814 100644 --- a/src/ui/gui/psppire-buttonbox.h +++ b/src/ui/gui/psppire-buttonbox.h @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2007, 2010 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 @@ -53,6 +53,7 @@ struct _PsppireButtonBox /* */ GtkWidget *button[n_PsppireButtonBoxButtons]; + guint def; }; struct _PsppireButtonBoxClass