#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 GObjectClass * parent_class = NULL;
+
+
+#define SELECTOR_DEBUGGING 0
+
+static void
+dump_hash_entry (gpointer key, gpointer value, gpointer obj)
+{
+ GList *item = NULL;
+ g_print ("Source %p; ", key);
+
+ for (item = g_list_first (value);
+ item != NULL;
+ item = g_list_next (item))
+ {
+ g_print ("%p(%p) ", item->data, item);
+ }
+ g_print ("\n");
+}
+
+/* This function is for debugging only */
+void
+psppire_selector_show_map (PsppireSelector *obj)
+{
+ PsppireSelectorClass *class = g_type_class_peek (PSPPIRE_SELECTOR_TYPE);
+
+ g_print ("%s %p\n", __FUNCTION__, obj);
+ g_hash_table_foreach (class->source_hash, dump_hash_entry, obj);
+}
+
+
+
static void
psppire_selector_dispose (GObject *obj)
{
PsppireSelector *sel = PSPPIRE_SELECTOR (obj);
+ PsppireSelectorClass *class = g_type_class_peek (PSPPIRE_SELECTOR_TYPE);
+ GList *list;
if (sel->dispose_has_run)
return;
/* Make sure dispose does not run twice. */
sel->dispose_has_run = TRUE;
+ /* Remove ourself from the source map. If we are the only entry for this source
+ widget, that will result in an empty list for the source. In that case, we
+ remove the entire entry too. */
+ if ((list = g_hash_table_lookup (class->source_hash, sel->source)))
+ {
+ GList *newlist = g_list_remove_link (list, sel->source_litem);
+ g_list_free (sel->source_litem);
+ if (newlist == NULL)
+ g_hash_table_remove (class->source_hash, sel->source);
+ else
+ g_hash_table_replace (class->source_hash, sel->source, newlist);
+
+ sel->source_litem = NULL;
+ }
+
g_object_unref (sel->dest);
g_object_unref (sel->source);
selector->row_activate_id = 0;
selector->source_select_id = 0;
+
+ selector->source_litem = NULL;
}
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;
refilter (PsppireSelector *selector)
{
GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (selector->source));
- gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (model));
+ if (GTK_IS_TREE_MODEL_FILTER (model))
+ gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (model));
return FALSE;
}
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 ();
if ( ! (list = g_hash_table_lookup (class->source_hash, selector->source)))
{
+ /* 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 */
+
list = g_list_append (list, selector);
g_hash_table_insert (class->source_hash, selector->source, list);
+
+ /* Save the list item so that it can be removed later */
+ selector->source_litem = list;
}
else
{ /* Append this selector to the list and push the <source,list>
if ( NULL == g_list_find (list, selector) )
{
if ( selector->primary_requested )
- list = g_list_prepend (list, selector);
+ {
+ list = g_list_prepend (list, selector);
+ selector->source_litem = list;
+ }
else
- list = g_list_append (list, selector);
+ {
+ list = g_list_append (list, selector);
+ selector->source_litem = g_list_last (list);
+ }
g_hash_table_replace (class->source_hash, selector->source, list);
}
}
}
+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 )
- {
- 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);
- }
+ 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);
}
/* Set the destination widget to DEST */
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) */
{
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 */
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;
}