/* PSPPIRE - a graphical user interface for PSPP.
- Copyright (C) 2007, 2009, 2010, 2012 Free Software Foundation
+ Copyright (C) 2007, 2009, 2010, 2012, 2015 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
This module provides a widget, PsppireSelector derived from
GtkButton.
- It contains a GtkArrow, and is used for selecting objects from a
+ It contains a GtkImage (to indicate the arrow), and is used for selecting objects from a
GtkTreeView and putting them into a destination widget (often
another GtkTreeView). Typically this is used in psppire for
selecting variables, thus:
#include <config.h>
#include "psppire-dictview.h"
-#include "psppire-var-view.h"
#include "psppire-dict.h"
#include "psppire-select-dest.h"
+#include "psppire-means-layer.h"
#include <gtk/gtk.h>
static const GTypeInfo psppire_selector_info =
{
sizeof (PsppireSelectorClass),
- (GBaseInitFunc) NULL,
+ (GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc)psppire_selector_class_init,
(GClassFinalizeFunc) NULL,
-#define SELECTOR_DEBUGGING 0
-
static void
dump_hash_entry (gpointer key, gpointer value, gpointer obj)
{
}
/* This function is for debugging only */
-void
+void
psppire_selector_show_map (PsppireSelector *obj)
{
PsppireSelectorClass *class = g_type_class_peek (PSPPIRE_SELECTOR_TYPE);
sel->source_litem = NULL;
}
-
+
g_object_unref (sel->dest);
g_object_unref (sel->source);
static void on_realize (GtkWidget *selector);
-static void update_subjects (PsppireSelector *selector);
-
-
static void
psppire_selector_set_property (GObject *object,
guint prop_id,
break;
case PROP_PRIMARY:
selector->primary_requested = TRUE;
- update_subjects (selector);
+ psppire_selector_update_subjects (selector);
break;
case PROP_SOURCE_WIDGET:
selector->source = g_value_dup_object (value);
- update_subjects (selector);
+ psppire_selector_update_subjects (selector);
break;
case PROP_DEST_WIDGET:
selector->dest = g_value_dup_object (value);
- update_subjects (selector);
+ psppire_selector_update_subjects (selector);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
FALSE,
G_PARAM_READWRITE);
- GParamSpec *source_widget_spec =
+ 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 =
+ GParamSpec *dest_widget_spec =
g_param_spec_object ("dest-widget",
"Destination Widget",
"The widget to be used as the destination for this selector",
if ( selector->row_activate_id )
g_signal_handler_disconnect (selector->source, selector->row_activate_id);
- selector->row_activate_id =
+ selector->row_activate_id =
g_signal_connect (selector->source, "row-activated", G_CALLBACK (on_row_activate), selector);
}
if ( selector->source_select_id )
g_signal_handler_disconnect (selection, selector->source_select_id);
- selector->source_select_id =
+ selector->source_select_id =
g_signal_connect (selection, "changed", G_CALLBACK (on_source_select), selector);
}
selector->allow_selection = NULL;
selector->filter = NULL;
- selector->arrow = gtk_arrow_new (GTK_ARROW_LEFT, GTK_SHADOW_NONE);
-
+ selector->arrow = gtk_image_new_from_icon_name ("pan-start-symbolic", GTK_ICON_SIZE_BUTTON);
gtk_container_add (GTK_CONTAINER (selector), selector->arrow);
switch (selector->orientation)
{
case PSPPIRE_SELECT_SOURCE_BEFORE_DEST:
- g_object_set (selector->arrow, "arrow-type", GTK_ARROW_RIGHT, NULL);
+ g_object_set (selector->arrow, "icon-name", "pan-end-symbolic", NULL);
break;
case PSPPIRE_SELECT_SOURCE_AFTER_DEST:
- g_object_set (selector->arrow, "arrow-type", GTK_ARROW_LEFT, NULL);
+ g_object_set (selector->arrow, "icon-name", "pan-start-symbolic", NULL);
break;
case PSPPIRE_SELECT_SOURCE_ABOVE_DEST:
- g_object_set (selector->arrow, "arrow-type", GTK_ARROW_DOWN, NULL);
+ g_object_set (selector->arrow, "icon-name", "pan-down-symbolic", NULL);
break;
case PSPPIRE_SELECT_SOURCE_BELOW_DEST:
- g_object_set (selector->arrow, "arrow-type", GTK_ARROW_UP, NULL);
+ g_object_set (selector->arrow, "icon-name", "pan-up-symbolic", NULL);
break;
default:
g_assert_not_reached ();
switch (selector->orientation)
{
case PSPPIRE_SELECT_SOURCE_BEFORE_DEST:
- g_object_set (selector->arrow, "arrow-type", GTK_ARROW_LEFT, NULL);
+ g_object_set (selector->arrow, "icon-name", "pan-start-symbolic", NULL);
break;
case PSPPIRE_SELECT_SOURCE_AFTER_DEST:
- g_object_set (selector->arrow, "arrow-type", GTK_ARROW_RIGHT, NULL);
+ g_object_set (selector->arrow, "icon-name", "pan-end-symbolic", NULL);
break;
case PSPPIRE_SELECT_SOURCE_ABOVE_DEST:
- g_object_set (selector->arrow, "arrow-type", GTK_ARROW_UP, NULL);
+ g_object_set (selector->arrow, "icon-name", "pan-up-symbolic", NULL);
break;
case PSPPIRE_SELECT_SOURCE_BELOW_DEST:
- g_object_set (selector->arrow, "arrow-type", GTK_ARROW_DOWN, NULL);
+ g_object_set (selector->arrow, "icon-name", "pan-down-symbolic", NULL);
break;
default:
g_assert_not_reached ();
break;
};
-
}
}
set_direction (selector, PSPPIRE_SELECTOR_DEST_TO_SOURCE);
}
+
/* Callback for source deselection, when the dest is GtkEntry */
static void
de_select_selection_entry (PsppireSelector *selector)
gtk_entry_set_text (GTK_ENTRY (selector->dest), "");
}
+
+static void de_select_tree_model (GtkTreeSelection *selection, GtkTreeModel *model);
+
+/* Callback for source deselection, when the dest is PsppireMeansLayer */
+static void
+de_select_selection_means_layer (PsppireSelector *selector)
+{
+ PsppireMeansLayer *ml = PSPPIRE_MEANS_LAYER (selector->dest);
+ GtkTreeView *tv = GTK_TREE_VIEW (ml->var_view);
+ GtkTreeSelection *selection = gtk_tree_view_get_selection (tv);
+
+ GtkTreeModel *model = psppire_means_layer_get_model (ml);
+
+ g_return_if_fail (selector->select_items);
+
+ de_select_tree_model (selection, model);
+}
+
/* Callback for source deselection, when the dest is GtkTreeView */
static void
de_select_selection_tree_view (PsppireSelector *selector)
{
- GList *item;
-
GtkTreeSelection* selection =
gtk_tree_view_get_selection ( GTK_TREE_VIEW (selector->dest));
GtkTreeModel *model =
gtk_tree_view_get_model (GTK_TREE_VIEW (selector->dest));
+ g_return_if_fail (selector->select_items);
+
+ de_select_tree_model (selection, model);
+}
+
+static void
+de_select_tree_model (GtkTreeSelection *selection, GtkTreeModel *model)
+{
+ GList *item;
+
GList *selected_rows =
gtk_tree_selection_get_selected_rows (selection, NULL);
- g_return_if_fail (selector->select_items);
-
/* Convert paths to RowRefs */
for (item = g_list_first (selected_rows);
item != NULL;
else if ( GTK_IS_ENTRY (selector->dest))
de_select_selection_entry (selector);
+ else if ( PSPPIRE_IS_MEANS_LAYER (selector->dest))
+ de_select_selection_means_layer (selector);
+
else
g_assert_not_reached ();
g_return_if_fail (selector->select_items);
- if (selector->allow_selection &&
+ if (selector->allow_selection &&
! selector->allow_selection (selector->source, selector->dest))
return;
GList *list = NULL;
PsppireSelectorClass *class = g_type_class_peek (PSPPIRE_SELECTOR_TYPE);
-
+
if ( ! (list = g_hash_table_lookup (class->source_hash, selector->source)))
{
- /* Base case: This widget is currently not the source of
+ /* Base case: This widget is currently not the source of
any selector. Create a hash entry and make this selector
the first selector in the list */
if (model && (model == g_object_get_data (G_OBJECT (source), "model-copy")))
return;
- if (model != NULL)
- {
- GtkTreeModel *new_model = gtk_tree_model_filter_new (model, NULL);
+ if (model != NULL)
+ {
+ GtkTreeModel *new_model = gtk_tree_model_filter_new (model, NULL);
- g_object_set_data (G_OBJECT (source), "model-copy", new_model);
+ g_object_set_data (G_OBJECT (source), "model-copy", new_model);
gtk_tree_view_set_model (source, new_model);
-
+
gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (new_model),
is_source_item_visible,
selector,
}
+static void
+remove_selector_handlers (PsppireSelector *selector, GObject *sel)
+{
+ g_signal_handlers_disconnect_by_data (sel, selector);
+}
+
static void
on_dest_model_changed (PsppireSelector *selector)
{
GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (selector->dest));
- if (model == NULL)
+ if (model == NULL)
return;
g_signal_connect (model, "row-changed", G_CALLBACK (on_dest_data_change),
selector);
-
+
g_signal_connect (model, "row-deleted", G_CALLBACK (on_dest_data_delete),
selector);
-
+
+ g_signal_connect (selector, "destroy", G_CALLBACK (remove_selector_handlers), model);
+
if ( selector->selecting ) return;
-
+
refilter (selector);
}
G_CALLBACK (on_dest_model_changed), selector);
}
+static void
+set_layer_dest (PsppireSelector *selector,
+ PsppireMeansLayer *dest)
+{
+ GtkTreeSelection* selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dest->var_view));
+ gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
+
+
+ g_signal_connect (selection, "changed", G_CALLBACK (on_dest_treeview_select),
+ selector);
+}
/* Callback for when the DEST GtkEntry is selected (clicked) */
}
-static void
-update_subjects (PsppireSelector *selector)
+void
+psppire_selector_update_subjects (PsppireSelector *selector)
{
if ( NULL == selector->dest )
return;
{
set_tree_view_source (selector);
- g_signal_connect (selector->source, "notify::model",
- G_CALLBACK (update_model), selector);
+ g_signal_connect (selector->source, "notify::model",
+ G_CALLBACK (update_model), selector);
update_model (GTK_TREE_VIEW (selector->source), 0, selector);
}
{
set_tree_view_dest (selector, GTK_TREE_VIEW (selector->dest));
}
-
else if ( GTK_IS_ENTRY (selector->dest))
- set_entry_dest (selector, GTK_ENTRY (selector->dest));
-
+ {
+ set_entry_dest (selector, GTK_ENTRY (selector->dest));
+ }
+ else if (PSPPIRE_IS_MEANS_LAYER (selector->dest))
+ {
+ set_layer_dest (selector, PSPPIRE_MEANS_LAYER (selector->dest));
+ }
else if (GTK_IS_TEXT_VIEW (selector->dest))
{
/* Nothing to be done */
g_error ("Unsupported destination widget: %s", G_OBJECT_TYPE_NAME (selector->dest));
- /* FIXME: Remove this dependency */
- if ( PSPPIRE_IS_DICT_VIEW (selector->source) )
+ if ( PSPPIRE_IS_DICT_VIEW (selector->source) && selector->select_items == NULL)
{
GObjectClass *class = G_OBJECT_GET_CLASS (selector);
GType type = G_OBJECT_TYPE (selector->dest);
- SelectItemsFunc *func =
+ SelectItemsFunc *func =
g_hash_table_lookup (PSPPIRE_SELECTOR_CLASS (class)->default_selection_funcs, (gpointer) type);
if ( func )
psppire_selector_orientation_get_type (void)
{
static GType etype = 0;
- if (etype == 0) {
- static const GEnumValue values[] = {
- { PSPPIRE_SELECT_SOURCE_BEFORE_DEST, "PSPPIRE_SELECT_SOURCE_BEFORE_DEST", "source before destination" },
- { PSPPIRE_SELECT_SOURCE_AFTER_DEST, "PSPPIRE_SELECT_SOURCE_AFTER_DEST", "source after destination" },
- { PSPPIRE_SELECT_SOURCE_ABOVE_DEST, "PSPPIRE_SELECT_SOURCE_ABOVE_DEST", "source above destination" },
- { PSPPIRE_SELECT_SOURCE_BELOW_DEST, "PSPPIRE_SELECT_SOURCE_BELOW_DEST", "source below destination" },
- { 0, NULL, NULL }
- };
- etype = g_enum_register_static (g_intern_static_string ("PsppireSelectorOrientation"), values);
- }
+ if (etype == 0)
+ {
+ static const GEnumValue values[] =
+ {
+ { PSPPIRE_SELECT_SOURCE_BEFORE_DEST, "PSPPIRE_SELECT_SOURCE_BEFORE_DEST", "source before destination" },
+ { PSPPIRE_SELECT_SOURCE_AFTER_DEST, "PSPPIRE_SELECT_SOURCE_AFTER_DEST", "source after destination" },
+ { PSPPIRE_SELECT_SOURCE_ABOVE_DEST, "PSPPIRE_SELECT_SOURCE_ABOVE_DEST", "source above destination" },
+ { PSPPIRE_SELECT_SOURCE_BELOW_DEST, "PSPPIRE_SELECT_SOURCE_BELOW_DEST", "source below destination" },
+ { 0, NULL, NULL }
+ };
+ etype = g_enum_register_static (g_intern_static_string ("PsppireSelectorOrientation"), values);
+ }
return etype;
}