X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Fui%2Fgui%2Fpsppire-selector.c;h=d871d5d1511a69c894525be369e933ca85d6a2b6;hb=03134dc262125d1785891d6111eec58ca09b3b54;hp=6465189d759d365b8c627654b84a8209f464db74;hpb=7eda1a159f93609f8bd68e98e1b04db2d99067f5;p=pspp-builds.git
diff --git a/src/ui/gui/psppire-selector.c b/src/ui/gui/psppire-selector.c
index 6465189d..d871d5d1 100644
--- a/src/ui/gui/psppire-selector.c
+++ b/src/ui/gui/psppire-selector.c
@@ -1,10 +1,9 @@
-/*
- PSPPIRE --- A Graphical User Interface for PSPP
- Copyright (C) 2007 Free Software Foundation
+/* PSPPIRE - a graphical user interface for PSPP.
+ Copyright (C) 2007, 2009 Free Software Foundation
- This program is free software; you can redistribute it and/or modify
+ 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
+ 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,
@@ -13,9 +12,7 @@
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. */
+ along with this program. If not, see . */
/*
This module provides a widget, PsppireSelector derived from
@@ -68,6 +65,7 @@
#include
#include
+#include
#include
static void psppire_selector_base_finalize (PsppireSelectorClass *, gpointer);
@@ -114,20 +112,50 @@ psppire_selector_get_type (void)
return psppire_selector_type;
}
+static GObjectClass * parent_class = NULL;
+
+static void
+psppire_selector_finalize (GObject *obj)
+{
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS (parent_class)->finalize (obj);
+}
+
static void
-psppire_selector_finalize (GObject *object)
+psppire_selector_dispose (GObject *obj)
{
+ PsppireSelector *sel = PSPPIRE_SELECTOR (obj);
+
+ if (sel->dispose_has_run)
+ return;
+
+ /* Make sure dispose does not run twice. */
+ sel->dispose_has_run = TRUE;
+
+ g_object_unref (sel->dest);
+ g_object_unref (sel->source);
+
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS (parent_class)->dispose (obj);
}
+
/* Properties */
enum
{
PROP_0,
- PROP_ORIENTATION
+ PROP_ORIENTATION,
+ PROP_SOURCE_WIDGET,
+ PROP_DEST_WIDGET
};
+static void on_activate (PsppireSelector *selector, gpointer data);
+
+static void update_subjects (PsppireSelector *selector);
+
+
static void
psppire_selector_set_property (GObject *object,
guint prop_id,
@@ -142,6 +170,14 @@ psppire_selector_set_property (GObject *object,
selector->orientation = g_value_get_enum (value);
set_direction (selector, selector->direction);
break;
+ case PROP_SOURCE_WIDGET:
+ selector->source = g_value_dup_object (value);
+ update_subjects (selector);
+ break;
+ case PROP_DEST_WIDGET:
+ selector->dest = g_value_dup_object (value);
+ update_subjects (selector);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -162,6 +198,12 @@ psppire_selector_get_property (GObject *object,
case PROP_ORIENTATION:
g_value_set_enum (value, selector->orientation);
break;
+ case PROP_SOURCE_WIDGET:
+ g_value_take_object (value, selector->source);
+ break;
+ case PROP_DEST_WIDGET:
+ g_value_take_object (value, selector->dest);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -178,10 +220,24 @@ psppire_selector_class_init (PsppireSelectorClass *class)
g_param_spec_enum ("orientation",
"Orientation",
"Where the selector is relative to its subjects",
- G_TYPE_PSPPIRE_SELECTOR_ORIENTATION,
+ PSPPIRE_TYPE_SELECTOR_ORIENTATION,
PSPPIRE_SELECT_SOURCE_BEFORE_DEST /* default value */,
G_PARAM_CONSTRUCT_ONLY |G_PARAM_READWRITE);
+ GParamSpec *source_widget_spec =
+ g_param_spec_object ("source-widget",
+ "Source Widget",
+ "The widget to be used as the source for this selector",
+ GTK_TYPE_WIDGET,
+ G_PARAM_READWRITE);
+
+ GParamSpec *dest_widget_spec =
+ g_param_spec_object ("dest-widget",
+ "Destination Widget",
+ "The widget to be used as the destination for this selector",
+ GTK_TYPE_WIDGET,
+ G_PARAM_READWRITE);
+
object_class->set_property = psppire_selector_set_property;
object_class->get_property = psppire_selector_get_property;
@@ -190,6 +246,16 @@ psppire_selector_class_init (PsppireSelectorClass *class)
PROP_ORIENTATION,
orientation_spec);
+ g_object_class_install_property (object_class,
+ PROP_SOURCE_WIDGET,
+ source_widget_spec);
+
+ g_object_class_install_property (object_class,
+ PROP_DEST_WIDGET,
+ dest_widget_spec);
+
+ parent_class = g_type_class_peek_parent (class);
+
signals [SELECTED] =
g_signal_new ("selected",
G_TYPE_FROM_CLASS (class),
@@ -218,6 +284,7 @@ psppire_selector_base_init (PsppireSelectorClass *class)
GObjectClass *object_class = G_OBJECT_CLASS (class);
object_class->finalize = psppire_selector_finalize;
+ object_class->dispose = psppire_selector_dispose;
class->source_hash = g_hash_table_new (g_direct_hash, g_direct_equal);
}
@@ -232,17 +299,37 @@ psppire_selector_base_finalize(PsppireSelectorClass *class,
}
+
static void
psppire_selector_init (PsppireSelector *selector)
{
+ selector->select_user_data = NULL;
+ selector->select_items = NULL;
+ selector->allow_selection = NULL;
+ selector->filter = NULL;
+
selector->arrow = gtk_arrow_new (GTK_ARROW_LEFT, GTK_SHADOW_NONE);
selector->filtered_source = NULL;
+ selector->action = gtk_action_new ("select", NULL, NULL, "pspp-stock-select");
+
+ gtk_action_connect_proxy (selector->action, GTK_WIDGET (selector));
+
gtk_container_add (GTK_CONTAINER (selector), selector->arrow);
gtk_widget_show (selector->arrow);
+ g_signal_connect_swapped (selector->action, "activate", G_CALLBACK (on_activate), selector);
+
selector->selecting = FALSE;
+
+ selector->source = NULL;
+ selector->dest = NULL;
+ selector->dispose_has_run = FALSE;
+
+
+ selector->row_activate_id = 0;
+ selector->source_select_id = 0;
}
@@ -313,9 +400,14 @@ on_source_select (GtkTreeSelection *treeselection, gpointer data)
set_direction (selector, PSPPIRE_SELECTOR_SOURCE_TO_DEST);
- if ( GTK_IS_ENTRY (selector->dest) )
+ if ( selector->allow_selection )
+ {
+ gtk_action_set_sensitive (selector->action,
+ selector->allow_selection (selector->source, selector->dest));
+ }
+ else if ( GTK_IS_ENTRY (selector->dest) )
{
- gtk_widget_set_sensitive (GTK_WIDGET (selector),
+ gtk_action_set_sensitive (selector->action,
gtk_tree_selection_count_selected_rows
(treeselection) <= 1 );
}
@@ -327,6 +419,8 @@ on_dest_treeview_select (GtkTreeSelection *treeselection, gpointer data)
{
PsppireSelector *selector = data;
+ gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (selector->source)));
+
set_direction (selector, PSPPIRE_SELECTOR_DEST_TO_SOURCE);
}
@@ -450,7 +544,9 @@ select_selection (PsppireSelector *selector)
selector->select_items (child_iter,
selector->dest,
- childmodel);
+ childmodel,
+ selector->select_user_data
+ );
}
g_list_foreach (selected_rows, (GFunc) gtk_tree_path_free, NULL);
@@ -472,12 +568,14 @@ on_row_activate (GtkTreeView *tree_view,
{
PsppireSelector *selector = data;
- select_selection (selector);
+ gtk_action_activate (selector->action);
}
-/* Callback for when the selector button is clicked */
+/* Callback for when the selector button is clicked,
+ or other event which causes the selector's action to occur.
+ */
static void
-on_click (PsppireSelector *selector, gpointer data)
+on_activate (PsppireSelector *selector, gpointer data)
{
switch (selector->direction)
{
@@ -532,10 +630,21 @@ is_item_in_dest (GtkTreeModel *model, GtkTreeIter *iter,
do
{
+ int x;
GValue value = {0};
+ GValue int_value = {0};
gtk_tree_model_get_value (dest_model, &dest_iter, 0, &value);
- if ( g_value_get_int (&value) == index)
+ g_value_init (&int_value, G_TYPE_INT);
+
+ g_value_transform (&value, &int_value);
+
+ x = g_value_get_int (&int_value);
+
+ g_value_unset (&int_value);
+ g_value_unset (&value);
+
+ if ( x == index )
return TRUE;
}
while (gtk_tree_model_iter_next (dest_model, &dest_iter));
@@ -561,8 +670,8 @@ is_source_item_visible (GtkTreeModel *childmodel,
{
PsppireSelector *selector = list->data;
- if ( selector->filter (childmodel, iter, selector))
- return FALSE;
+ if ( selector->filter && selector->filter (childmodel, iter, selector))
+ return FALSE;
list = list->next;
}
@@ -580,14 +689,13 @@ set_tree_view_source (PsppireSelector *selector,
GList *list = NULL;
PsppireSelectorClass *class = g_type_class_peek (PSPPIRE_SELECTOR_TYPE);
+
+ GtkTreeModel *model = gtk_tree_view_get_model (source);
if ( ! (list = g_hash_table_lookup (class->source_hash, source)))
{
selector->filtered_source =
- GTK_TREE_MODEL_FILTER (gtk_tree_model_filter_new
- (gtk_tree_view_get_model (source), NULL));
-
- gtk_tree_view_set_model (source, NULL);
+ GTK_TREE_MODEL_FILTER (gtk_tree_model_filter_new (model, NULL));
gtk_tree_view_set_model (source,
GTK_TREE_MODEL (selector->filtered_source));
@@ -605,8 +713,7 @@ set_tree_view_source (PsppireSelector *selector,
{ /* Append this selector to the list and push the