X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fpsppire-acr.c;h=0b397fe3dcbd97edc8a65462a4294a42a3d255b6;hb=2501627caac743acbfcc97480f15344f8a393a6e;hp=c0988d84d7bffcafa00beaf21c3fd8f25902ec22;hpb=53ae54521dfa22f62bb9ba8be02457a3a46dfb15;p=pspp diff --git a/src/ui/gui/psppire-acr.c b/src/ui/gui/psppire-acr.c index c0988d84d7..0b397fe3dc 100644 --- a/src/ui/gui/psppire-acr.c +++ b/src/ui/gui/psppire-acr.c @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007, 2012 Free Software Foundation, Inc. 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 @@ -38,36 +38,33 @@ #include #include "psppire-acr.h" +#include "helper.h" -static void psppire_acr_init (PsppireAcr *); +#include "gettext.h" +#define _(msgid) gettext (msgid) +#define N_(msgid) msgid -GType -psppire_acr_get_type (void) +G_DEFINE_TYPE (PsppireAcr, psppire_acr, GTK_TYPE_BOX); + +static void +psppire_acr_dispose (GObject *obj) { - static GType acr_type = 0; + PsppireAcr *acr = PSPPIRE_ACR (obj); - if (!acr_type) - { - static const GTypeInfo acr_info = - { - sizeof (PsppireAcrClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - NULL, /* class_init */ - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (PsppireAcr), - 0, - (GInstanceInitFunc) psppire_acr_init, - }; - - acr_type = g_type_register_static (GTK_TYPE_HBOX, "PsppireAcr", - &acr_info, 0); - } + if (acr->dispose_has_run) + return; + acr->dispose_has_run = TRUE; - return acr_type; + psppire_acr_set_model (acr, NULL); + + G_OBJECT_CLASS (psppire_acr_parent_class)->dispose (obj); } +static void +psppire_acr_class_init (PsppireAcrClass *class) +{ + G_OBJECT_CLASS (class)->dispose = psppire_acr_dispose; +} static gboolean row_is_selected (const PsppireAcr *acr); @@ -143,7 +140,7 @@ on_add_button_clicked (PsppireAcr *acr) ++i) { static GValue value; - if ( ! acr->get_value (i, &value, acr->get_value_data) ) + if (! acr->get_value (i, &value, acr->get_value_data)) continue; gtk_list_store_set_value (acr->list_store, &iter, @@ -178,7 +175,7 @@ on_change_button_clicked (PsppireAcr *acr) ++i) { static GValue value; - if ( ! acr->get_value (i, &value, acr->get_value_data) ) + if (! acr->get_value (i, &value, acr->get_value_data)) continue; gtk_list_store_set_value (acr->list_store, &iter, @@ -186,10 +183,10 @@ on_change_button_clicked (PsppireAcr *acr) g_value_unset (&value); } - g_list_foreach (l, (GFunc) gtk_tree_path_free, NULL); + g_list_foreach (l, GFUNC_COMPAT_CAST (gtk_tree_path_free), NULL); g_list_free (l); - if ( acr->update) acr->update (acr->update_data); + if (acr->update) acr->update (acr->update_data); } @@ -212,7 +209,7 @@ on_remove_button_clicked (PsppireAcr *acr) gtk_list_store_remove (acr->list_store, &iter); - g_list_foreach (l, (GFunc) gtk_tree_path_free, NULL); + g_list_foreach (l, GFUNC_COMPAT_CAST (gtk_tree_path_free), NULL); g_list_free (l); } @@ -228,7 +225,7 @@ row_is_selected (const PsppireAcr *acr) result = (l != NULL); - g_list_foreach (l, (GFunc) gtk_tree_path_free, NULL); + g_list_foreach (l, GFUNC_COMPAT_CAST (gtk_tree_path_free), NULL); g_list_free (l); return result; @@ -246,7 +243,7 @@ on_select (GtkTreeSelection *selection, gpointer data) gtk_widget_set_sensitive (acr->change_button, row_is_selected (acr) - ); + ); } @@ -260,19 +257,22 @@ psppire_acr_set_enabled (PsppireAcr *acr, gboolean status) && row_is_selected (acr)); } - static void psppire_acr_init (PsppireAcr *acr) { - GtkWidget *bb = gtk_vbutton_box_new (); + GtkWidget *bb = gtk_button_box_new (GTK_ORIENTATION_VERTICAL); GtkWidget *sw = gtk_scrolled_window_new (NULL, NULL); + acr->dispose_has_run = FALSE; + + gtk_orientable_set_orientation (GTK_ORIENTABLE (acr), GTK_ORIENTATION_HORIZONTAL); + acr->tv = GTK_TREE_VIEW (gtk_tree_view_new ()); - acr->add_button = gtk_button_new_from_stock (GTK_STOCK_ADD); - acr->change_button = gtk_button_new_from_stock (GTK_STOCK_EDIT); - acr->remove_button = gtk_button_new_from_stock (GTK_STOCK_REMOVE); + acr->add_button = gtk_button_new_with_label (_("Add")); + acr->change_button = gtk_button_new_with_label (_("Edit")); + acr->remove_button = gtk_button_new_with_label (_("Remove")); acr->get_value = NULL; acr->get_value_data = NULL; @@ -283,9 +283,9 @@ psppire_acr_init (PsppireAcr *acr) gtk_widget_set_sensitive (acr->remove_button, FALSE); gtk_widget_set_sensitive (acr->add_button, FALSE); - gtk_box_pack_start_defaults (GTK_BOX (bb), acr->add_button); - gtk_box_pack_start_defaults (GTK_BOX (bb), acr->change_button); - gtk_box_pack_start_defaults (GTK_BOX (bb), acr->remove_button); + psppire_box_pack_start_defaults (GTK_BOX (bb), acr->add_button); + psppire_box_pack_start_defaults (GTK_BOX (bb), acr->change_button); + psppire_box_pack_start_defaults (GTK_BOX (bb), acr->remove_button); gtk_box_pack_start (GTK_BOX (acr), bb, FALSE, TRUE, 5); @@ -346,10 +346,16 @@ psppire_acr_new (void) -/* Set the widget's treemodel */ +/* Set the widget's treemodel to LISTSTORE. LISTSTORE ownership is not + transferred. */ void psppire_acr_set_model (PsppireAcr *acr, GtkListStore *liststore) { + if (acr->list_store) + g_object_unref (acr->list_store); + if (liststore) + g_object_ref (liststore); + acr->list_store = liststore; gtk_tree_view_set_model (GTK_TREE_VIEW (acr->tv),