X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fpsppire-dialog.c;h=84f9e5de489459a86c702c912a32d7c882a3fc17;hb=b96c526de9a5b0ee767e058cefc42fae9e9b0dc5;hp=6eccb77c4daf17aa2f5f1443bd9d46cdfad63297;hpb=cecaf561d11939de82a6598324376b8cf8225fd5;p=pspp diff --git a/src/ui/gui/psppire-dialog.c b/src/ui/gui/psppire-dialog.c index 6eccb77c4d..84f9e5de48 100644 --- a/src/ui/gui/psppire-dialog.c +++ b/src/ui/gui/psppire-dialog.c @@ -1,39 +1,44 @@ -/* - PSPPIRE --- A Graphical User Interface for PSPP - Copyright (C) 2007 Free Software Foundation +/* PSPPIRE - a graphical user interface for PSPP. + Copyright (C) 2007 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. */ + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ #include #include #include +#include #include "psppire-dialog.h" +#include "psppire-buttonbox.h" +#include "psppire-selector.h" +#include static void psppire_dialog_class_init (PsppireDialogClass *); static void psppire_dialog_init (PsppireDialog *); enum {DIALOG_REFRESH, + VALIDITY_CHANGED, n_SIGNALS}; static guint signals [n_SIGNALS]; +static void psppire_dialog_buildable_init (GtkBuildableIface *iface); + + GType psppire_dialog_get_type (void) { @@ -54,8 +59,20 @@ psppire_dialog_get_type (void) (GInstanceInitFunc) psppire_dialog_init, }; + static const GInterfaceInfo buildable_info = + { + (GInterfaceInitFunc) psppire_dialog_buildable_init, + NULL, + NULL + }; + dialog_type = g_type_register_static (GTK_TYPE_WINDOW, "PsppireDialog", &dialog_info, 0); + + g_type_add_interface_static (dialog_type, + GTK_TYPE_BUILDABLE, + &buildable_info); + } return dialog_type; @@ -106,6 +123,8 @@ psppire_dialog_get_property (GObject *object, g_value_set_enum (value, PSPPIRE_VERTICAL); else if ( GTK_IS_HBOX (dialog->box)) g_value_set_enum (value, PSPPIRE_HORIZONTAL); + else if ( GTK_IS_TABLE (dialog->box)) + g_value_set_enum (value, PSPPIRE_TABULAR); } break; default: @@ -125,13 +144,21 @@ dialog_set_orientation (PsppireDialog *dialog, const GValue *orval) gtk_container_remove (GTK_CONTAINER (dialog), dialog->box); } - if ( orientation == PSPPIRE_HORIZONTAL) + switch ( orientation ) { + case PSPPIRE_HORIZONTAL: dialog->box = gtk_hbox_new (FALSE, 5); - } - else - { + break; + case PSPPIRE_VERTICAL: dialog->box = gtk_vbox_new (FALSE, 5); + break; + case PSPPIRE_TABULAR: + dialog->box = gtk_table_new (2, 3, FALSE); + g_object_set (dialog->box, + "row-spacing", 5, + "column-spacing", 5, + NULL); + break; } gtk_container_add (GTK_CONTAINER (dialog), dialog->box); @@ -196,6 +223,18 @@ psppire_dialog_class_init (PsppireDialogClass *class) 0); + signals [VALIDITY_CHANGED] = + g_signal_new ("validity-changed", + G_TYPE_FROM_CLASS (class), + G_SIGNAL_RUN_FIRST, + 0, + NULL, NULL, + g_cclosure_marshal_VOID__BOOLEAN, + G_TYPE_NONE, + 1, + G_TYPE_BOOLEAN); + + object_class->finalize = psppire_dialog_finalize; } @@ -230,10 +269,15 @@ psppire_dialog_init (PsppireDialog *dialog) { GValue value = {0}; dialog->box = NULL; + dialog->contents_are_valid = NULL; + dialog->validity_data = NULL; g_value_init (&value, orientation_spec->value_type); g_param_value_set_default (orientation_spec, &value); + gtk_window_set_type_hint (GTK_WINDOW (dialog), + GDK_WINDOW_TYPE_HINT_DIALOG); + dialog_set_orientation (dialog, &value); g_value_unset (&value); @@ -242,6 +286,9 @@ psppire_dialog_init (PsppireDialog *dialog) G_CALLBACK (delete_event_callback), dialog); + gtk_window_set_type_hint (GTK_WINDOW (dialog), + GDK_WINDOW_TYPE_HINT_DIALOG); + gtk_widget_show_all (dialog->box); } @@ -256,17 +303,150 @@ psppire_dialog_new (void) return GTK_WIDGET (dialog) ; } + +void +psppire_dialog_notify_change (PsppireDialog *dialog) +{ + if ( dialog->contents_are_valid ) + { + gboolean valid = dialog->contents_are_valid (dialog->validity_data); + + g_signal_emit (dialog, signals [VALIDITY_CHANGED], 0, valid); + } +} + + +/* Descend the widget tree, connecting appropriate signals to the + psppire_dialog_notify_change callback */ +static void +connect_notify_signal (GtkWidget *w, gpointer data) +{ + PsppireDialog *dialog = data; + + if ( PSPPIRE_IS_BUTTONBOX (w)) + return; + + + + if ( GTK_IS_CONTAINER (w)) + { + gtk_container_foreach (GTK_CONTAINER (w), + connect_notify_signal, + dialog); + } + + + /* It's unfortunate that GTK+ doesn't have a generic + "user-modified-state-changed" signal. Instead, we have to try and + predict what widgets and signals are likely to exist in our dialogs. */ + + if ( GTK_IS_TOGGLE_BUTTON (w)) + { + g_signal_connect_swapped (w, "toggled", + G_CALLBACK (psppire_dialog_notify_change), + dialog); + } + + if ( PSPPIRE_IS_SELECTOR (w)) + { + g_signal_connect_swapped (w, "selected", + G_CALLBACK (psppire_dialog_notify_change), + dialog); + + g_signal_connect_swapped (w, "de-selected", + G_CALLBACK (psppire_dialog_notify_change), + dialog); + } + + if ( GTK_IS_EDITABLE (w)) + { + g_signal_connect_swapped (w, "changed", + G_CALLBACK (psppire_dialog_notify_change), + dialog); + } + + if ( GTK_IS_CELL_EDITABLE (w)) + { + g_signal_connect_swapped (w, "editing-done", + G_CALLBACK (psppire_dialog_notify_change), + dialog); + } + + if ( GTK_IS_TEXT_VIEW (w)) + { + GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (w)); + + g_signal_connect_swapped (buffer, "changed", + G_CALLBACK (psppire_dialog_notify_change), + dialog); + } + + if ( GTK_IS_TREE_VIEW (w)) + { + gint i = 0; + GtkTreeView *tv = GTK_TREE_VIEW (w); + GtkTreeSelection *selection = + gtk_tree_view_get_selection (tv); + GtkTreeViewColumn *col; + GtkTreeModel *model = gtk_tree_view_get_model (tv); + + if ( model) + { + g_signal_connect_swapped (model, "row-changed", + G_CALLBACK (psppire_dialog_notify_change), + dialog); + + g_signal_connect_swapped (model, "row-deleted", + G_CALLBACK (psppire_dialog_notify_change), + dialog); + + g_signal_connect_swapped (model, "row-inserted", + G_CALLBACK (psppire_dialog_notify_change), + dialog); + } + + g_signal_connect_swapped (selection, "changed", + G_CALLBACK (psppire_dialog_notify_change), + dialog); + + while ((col = gtk_tree_view_get_column (tv, i++))) + { + GList *renderers = gtk_tree_view_column_get_cell_renderers (col); + GList *start = renderers; + while (renderers) + { + if ( GTK_IS_CELL_RENDERER_TOGGLE (renderers->data)) + g_signal_connect_swapped (renderers->data, "toggled", + G_CALLBACK (psppire_dialog_notify_change), dialog); + renderers = renderers->next; + } + g_list_free (start); + } + } +} + + gint psppire_dialog_run (PsppireDialog *dialog) { + if ( dialog->contents_are_valid != NULL ) + gtk_container_foreach (GTK_CONTAINER (dialog->box), + connect_notify_signal, + dialog); + dialog->loop = g_main_loop_new (NULL, FALSE); gtk_widget_show (GTK_WIDGET (dialog)); + if ( dialog->contents_are_valid != NULL) + g_signal_emit (dialog, signals [VALIDITY_CHANGED], 0, FALSE); + g_signal_emit (dialog, signals [DIALOG_REFRESH], 0); g_main_loop_run (dialog->loop); + g_main_loop_unref (dialog->loop); + return dialog->response; } @@ -290,6 +470,7 @@ psppire_orientation_get_type (void) { { PSPPIRE_HORIZONTAL, "PSPPIRE_HORIZONTAL", "Horizontal" }, { PSPPIRE_VERTICAL, "PSPPIRE_VERTICAL", "Vertical" }, + { PSPPIRE_TABULAR, "PSPPIRE_TABULAR", "Tabular" }, { 0, NULL, NULL } }; @@ -299,3 +480,38 @@ psppire_orientation_get_type (void) } return etype; } + + +void +psppire_dialog_set_valid_predicate (PsppireDialog *dialog, + ContentsAreValid contents_are_valid, + gpointer data) +{ + dialog->contents_are_valid = contents_are_valid; + dialog->validity_data = data; +} + + + + + +static GObject * +get_internal_child (GtkBuildable *buildable, + GtkBuilder *builder, + const gchar *childname) +{ + PsppireDialog *dialog = PSPPIRE_DIALOG (buildable); + + if ( 0 == strcmp (childname, "hbox")) + return G_OBJECT (dialog->box); + + return NULL; +} + + + +static void +psppire_dialog_buildable_init (GtkBuildableIface *iface) +{ + iface->get_internal_child = get_internal_child; +}