dcaac0ce031f9dcb0dd9b2a73584da2d4e506b33
[pspp-builds.git] / src / ui / gui / psppire-selector.c
1 /* PSPPIRE - a graphical user interface for PSPP.
2    Copyright (C) 2007  Free Software Foundation
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17 /*
18   This module provides a widget, PsppireSelector derived from
19   GtkButton.
20
21   It contains a GtkArrow, and is used for selecting objects from a
22   GtkTreeView and putting them into a destination widget (often
23   another GtkTreeView).  Typically this is used in psppire for
24   selecting variables, thus:
25
26
27   +----------------------------------------------------------+
28   |                                                          |
29   |     Source Widget                       Dest Widget      |
30   |   +----------------+                 +----------------+  |
31   |   | Variable0      |                 | Variable2      |  |
32   |   | Variable1      |                 |                |  |
33   |   | Variable3      |                 |                |  |
34   |   |                |    Selector     |                |  |
35   |   |                |                 |                |  |
36   |   |                |    +------+     |                |  |
37   |   |                |    | |\   |     |                |  |
38   |   |                |    | | \  |     |                |  |
39   |   |                |    | | /  |     |                |  |
40   |   |                |    | |/   |     |                |  |
41   |   |                |    +------+     |                |  |
42   |   |                |                 |                |  |
43   |   |                |                 |                |  |
44   |   |                |                 |                |  |
45   |   |                |                 |                |  |
46   |   +----------------+                 +----------------+  |
47   |                                                          |
48   +----------------------------------------------------------+
49
50   The Source Widget is always a GtkTreeView.  The Dest Widget may be a
51   GtkTreeView or a GtkEntry (other destination widgets may be
52   supported in the future).
53
54   Widgets may be source to more than one PsppireSelector.
55 */
56
57
58 #include <config.h>
59
60 #include <gtk/gtksignal.h>
61 #include <gtk/gtkbutton.h>
62 #include <gtk/gtkentry.h>
63
64 #include "psppire-selector.h"
65
66 #include <gtk/gtktreeview.h>
67 #include <gtk/gtktreeselection.h>
68 #include <gtk/gtktextview.h>
69 #include <gtk/gtkwidget.h>
70
71 static void psppire_selector_base_finalize (PsppireSelectorClass *, gpointer);
72 static void psppire_selector_base_init     (PsppireSelectorClass *class);
73 static void psppire_selector_class_init    (PsppireSelectorClass *class);
74 static void psppire_selector_init          (PsppireSelector      *selector);
75
76
77 static void set_direction (PsppireSelector *, enum psppire_selector_dir);
78
79
80 enum  {SELECTED,    /* Emitted when an item is inserted into dest */
81        DE_SELECTED, /* Emitted when an item is removed from dest */
82        n_SIGNALS};
83
84 static guint signals [n_SIGNALS];
85
86
87 GType
88 psppire_selector_get_type (void)
89 {
90   static GType psppire_selector_type = 0;
91
92   if (!psppire_selector_type)
93     {
94       static const GTypeInfo psppire_selector_info =
95       {
96         sizeof (PsppireSelectorClass),
97         (GBaseInitFunc) psppire_selector_base_init,
98         (GBaseFinalizeFunc) psppire_selector_base_finalize,
99         (GClassInitFunc)psppire_selector_class_init,
100         (GClassFinalizeFunc) NULL,
101         NULL,
102         sizeof (PsppireSelector),
103         0,
104         (GInstanceInitFunc) psppire_selector_init,
105       };
106
107       psppire_selector_type =
108         g_type_register_static (GTK_TYPE_BUTTON, "PsppireSelector",
109                                 &psppire_selector_info, 0);
110     }
111
112   return psppire_selector_type;
113 }
114
115
116 static void
117 psppire_selector_finalize (GObject *object)
118 {
119 }
120
121 /* Properties */
122 enum
123 {
124   PROP_0,
125   PROP_ORIENTATION
126 };
127
128
129 static void
130 psppire_selector_set_property (GObject         *object,
131                                guint            prop_id,
132                                const GValue    *value,
133                                GParamSpec      *pspec)
134 {
135   PsppireSelector *selector = PSPPIRE_SELECTOR (object);
136
137   switch (prop_id)
138     {
139     case PROP_ORIENTATION:
140       selector->orientation = g_value_get_enum (value);
141       set_direction (selector, selector->direction);
142       break;
143     default:
144       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
145       break;
146     };
147 }
148
149
150 static void
151 psppire_selector_get_property (GObject         *object,
152                                guint            prop_id,
153                                GValue          *value,
154                                GParamSpec      *pspec)
155 {
156   PsppireSelector *selector = PSPPIRE_SELECTOR (object);
157
158   switch (prop_id)
159     {
160     case PROP_ORIENTATION:
161       g_value_set_enum (value, selector->orientation);
162       break;
163     default:
164       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
165       break;
166     };
167 }
168
169
170
171 static void
172 psppire_selector_class_init (PsppireSelectorClass *class)
173 {
174   GObjectClass *object_class = G_OBJECT_CLASS (class);
175   GParamSpec *orientation_spec =
176     g_param_spec_enum ("orientation",
177                        "Orientation",
178                        "Where the selector is relative to its subjects",
179                        G_TYPE_PSPPIRE_SELECTOR_ORIENTATION,
180                        PSPPIRE_SELECT_SOURCE_BEFORE_DEST /* default value */,
181                        G_PARAM_CONSTRUCT_ONLY |G_PARAM_READWRITE);
182
183
184   object_class->set_property = psppire_selector_set_property;
185   object_class->get_property = psppire_selector_get_property;
186
187   g_object_class_install_property (object_class,
188                                    PROP_ORIENTATION,
189                                    orientation_spec);
190
191   signals [SELECTED] =
192     g_signal_new ("selected",
193                   G_TYPE_FROM_CLASS (class),
194                   G_SIGNAL_RUN_FIRST,
195                   0,
196                   NULL, NULL,
197                   g_cclosure_marshal_VOID__VOID,
198                   G_TYPE_NONE,
199                   0);
200
201   signals [DE_SELECTED] =
202     g_signal_new ("de-selected",
203                   G_TYPE_FROM_CLASS (class),
204                   G_SIGNAL_RUN_FIRST,
205                   0,
206                   NULL, NULL,
207                   g_cclosure_marshal_VOID__VOID,
208                   G_TYPE_NONE,
209                   0);
210 }
211
212
213 static void
214 psppire_selector_base_init (PsppireSelectorClass *class)
215 {
216   GObjectClass *object_class = G_OBJECT_CLASS (class);
217
218   object_class->finalize = psppire_selector_finalize;
219
220   class->source_hash = g_hash_table_new (g_direct_hash, g_direct_equal);
221 }
222
223
224
225 static void
226 psppire_selector_base_finalize(PsppireSelectorClass *class,
227                                 gpointer class_data)
228 {
229   g_hash_table_destroy (class->source_hash);
230 }
231
232
233 static void
234 psppire_selector_init (PsppireSelector *selector)
235 {
236   selector->arrow = gtk_arrow_new (GTK_ARROW_LEFT, GTK_SHADOW_NONE);
237   selector->filtered_source = NULL;
238
239   gtk_container_add (GTK_CONTAINER (selector), selector->arrow);
240
241   gtk_widget_show (selector->arrow);
242
243   selector->selecting = FALSE;
244 }
245
246
247 GtkWidget*
248 psppire_selector_new (void)
249 {
250   return GTK_WIDGET (g_object_new (psppire_selector_get_type (), NULL));
251 }
252
253
254 static void
255 set_direction (PsppireSelector *selector, enum psppire_selector_dir d)
256 {
257   selector->direction = d;
258
259   /* FIXME: Need to reverse the arrow direction if an RTL locale is in
260      effect */
261   if ( d == PSPPIRE_SELECTOR_SOURCE_TO_DEST )
262     {
263       switch (selector->orientation)
264         {
265         case   PSPPIRE_SELECT_SOURCE_BEFORE_DEST:
266           g_object_set (selector->arrow, "arrow-type", GTK_ARROW_RIGHT, NULL);
267           break;
268         case   PSPPIRE_SELECT_SOURCE_AFTER_DEST:
269           g_object_set (selector->arrow, "arrow-type", GTK_ARROW_LEFT, NULL);
270           break;
271         case   PSPPIRE_SELECT_SOURCE_ABOVE_DEST:
272           g_object_set (selector->arrow, "arrow-type", GTK_ARROW_DOWN, NULL);
273           break;
274         case   PSPPIRE_SELECT_SOURCE_BELOW_DEST:
275           g_object_set (selector->arrow, "arrow-type", GTK_ARROW_UP, NULL);
276           break;
277         default:
278           g_assert_not_reached ();
279           break;
280         };
281     }
282   else
283     {
284       switch (selector->orientation)
285         {
286         case   PSPPIRE_SELECT_SOURCE_BEFORE_DEST:
287           g_object_set (selector->arrow, "arrow-type", GTK_ARROW_LEFT, NULL);
288           break;
289         case   PSPPIRE_SELECT_SOURCE_AFTER_DEST:
290           g_object_set (selector->arrow, "arrow-type", GTK_ARROW_RIGHT, NULL);
291           break;
292         case   PSPPIRE_SELECT_SOURCE_ABOVE_DEST:
293           g_object_set (selector->arrow, "arrow-type", GTK_ARROW_UP, NULL);
294           break;
295         case   PSPPIRE_SELECT_SOURCE_BELOW_DEST:
296           g_object_set (selector->arrow, "arrow-type", GTK_ARROW_DOWN, NULL);
297           break;
298         default:
299           g_assert_not_reached ();
300           break;
301         };
302
303     }
304 }
305
306 /* Callback for when the source selection changes */
307 static void
308 on_source_select (GtkTreeSelection *treeselection, gpointer data)
309 {
310   PsppireSelector *selector = data;
311
312   set_direction (selector, PSPPIRE_SELECTOR_SOURCE_TO_DEST);
313
314   if ( GTK_IS_ENTRY (selector->dest) )
315     {
316       gtk_widget_set_sensitive (GTK_WIDGET (selector),
317                                 gtk_tree_selection_count_selected_rows
318                                 (treeselection) <= 1 );
319     }
320 }
321
322 /* Callback for when the destination treeview selection changes */
323 static void
324 on_dest_treeview_select (GtkTreeSelection *treeselection, gpointer data)
325 {
326   PsppireSelector *selector = data;
327
328   set_direction (selector, PSPPIRE_SELECTOR_DEST_TO_SOURCE);
329 }
330
331 /* Callback for source deselection, when the dest is GtkEntry */
332 static void
333 de_select_selection_entry (PsppireSelector *selector)
334 {
335   gtk_entry_set_text (GTK_ENTRY (selector->dest), "");
336 }
337
338 /* Callback for source deselection, when the dest is GtkTreeView */
339 static void
340 de_select_selection_tree_view (PsppireSelector *selector)
341 {
342   GList *item;
343
344   GtkTreeSelection* selection =
345     gtk_tree_view_get_selection ( GTK_TREE_VIEW (selector->dest));
346
347   GtkTreeModel *model =
348     gtk_tree_view_get_model (GTK_TREE_VIEW (selector->dest));
349
350   GList *selected_rows =
351     gtk_tree_selection_get_selected_rows (selection, NULL);
352
353   g_return_if_fail (selector->select_items);
354
355   /* Convert paths to RowRefs */
356   for (item = g_list_first (selected_rows);
357        item != NULL;
358        item = g_list_next (item))
359     {
360       GtkTreeRowReference* rowref;
361       GtkTreePath *path  = item->data;
362
363       rowref = gtk_tree_row_reference_new (GTK_TREE_MODEL (model), path);
364
365       item->data = rowref ;
366       gtk_tree_path_free (path);
367     }
368
369   /* Remove each selected row from the dest widget */
370   for (item = g_list_first (selected_rows);
371        item != NULL;
372        item = g_list_next (item))
373     {
374       GtkTreeIter iter;
375       GtkTreeRowReference *rr = item->data;
376
377       GtkTreePath *path = gtk_tree_row_reference_get_path (rr);
378
379       gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, path);
380
381       gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
382
383       gtk_tree_path_free (path);
384     }
385
386   /* Delete list of RowRefs and its contents */
387   g_list_foreach (selected_rows, (GFunc) gtk_tree_row_reference_free, NULL);
388   g_list_free (selected_rows);
389 }
390
391
392 /* Removes something from the DEST widget */
393 static void
394 de_select_selection (PsppireSelector *selector)
395 {
396   selector->selecting = TRUE;
397
398   if ( GTK_IS_TREE_VIEW (selector->dest ) )
399     de_select_selection_tree_view (selector);
400
401   else if ( GTK_IS_ENTRY (selector->dest))
402     de_select_selection_entry (selector);
403
404   else
405     g_assert_not_reached ();
406
407   selector->selecting = FALSE;
408
409   gtk_tree_model_filter_refilter (selector->filtered_source);
410
411   g_signal_emit (selector, signals [DE_SELECTED], 0);
412 }
413
414
415 /* Puts something into the DEST widget */
416 static void
417 select_selection (PsppireSelector *selector)
418 {
419   GList *item ;
420   GtkTreeSelection* selection =
421     gtk_tree_view_get_selection ( GTK_TREE_VIEW (selector->source));
422
423   GList *selected_rows =
424     gtk_tree_selection_get_selected_rows (selection, NULL);
425
426   GtkTreeModel *childmodel  = gtk_tree_model_filter_get_model
427     (selector->filtered_source);
428
429   g_return_if_fail (selector->select_items);
430
431   selector->selecting = TRUE;
432
433   for (item = g_list_first (selected_rows);
434        item != NULL;
435        item = g_list_next (item))
436     {
437       GtkTreeIter child_iter;
438       GtkTreeIter iter;
439       GtkTreePath *path  = item->data;
440
441       gtk_tree_model_get_iter (GTK_TREE_MODEL (selector->filtered_source),
442                                &iter, path);
443
444       gtk_tree_model_filter_convert_iter_to_child_iter
445         (selector->filtered_source,
446          &child_iter,
447          &iter);
448
449       selector->select_items (child_iter,
450                               selector->dest,
451                               childmodel);
452     }
453
454   g_list_foreach (selected_rows, (GFunc) gtk_tree_path_free, NULL);
455   g_list_free (selected_rows);
456
457   gtk_tree_model_filter_refilter (selector->filtered_source);
458
459   g_signal_emit (selector, signals [SELECTED], 0);
460
461   selector->selecting = FALSE;
462 }
463
464 /* Callback for when the source treeview is activated (double clicked) */
465 static void
466 on_row_activate (GtkTreeView       *tree_view,
467                  GtkTreePath       *path,
468                  GtkTreeViewColumn *column,
469                  gpointer           data)
470 {
471   PsppireSelector *selector  = data;
472
473   select_selection (selector);
474 }
475
476 /* Callback for when the selector button is clicked */
477 static void
478 on_click (PsppireSelector *selector, gpointer data)
479 {
480   switch (selector->direction)
481     {
482     case PSPPIRE_SELECTOR_SOURCE_TO_DEST:
483       select_selection (selector);
484       break;
485     case PSPPIRE_SELECTOR_DEST_TO_SOURCE:
486       de_select_selection (selector);
487       break;
488     default:
489       g_assert_not_reached ();
490       break;
491     }
492 }
493
494 /* Default visibility filter for GtkTreeView DEST widget */
495 static gboolean
496 is_item_in_dest (GtkTreeModel *model, GtkTreeIter *iter,
497                  PsppireSelector *selector)
498 {
499   GtkTreeModel *dest_model;
500   GtkTreeIter dest_iter;
501   GtkTreeIter source_iter;
502   gint index;
503   GtkTreePath *path ;
504   GtkTreeModel *source_model;
505
506   if ( GTK_IS_TREE_MODEL_FILTER (model) )
507     {
508       source_model = gtk_tree_model_filter_get_model
509         (GTK_TREE_MODEL_FILTER (model));
510
511       gtk_tree_model_filter_convert_iter_to_child_iter
512         ( GTK_TREE_MODEL_FILTER (model),  &source_iter,  iter  );
513     }
514   else
515     {
516       source_model = model;
517       source_iter = *iter;
518     }
519
520   dest_model = gtk_tree_view_get_model (GTK_TREE_VIEW (selector->dest));
521
522   path = gtk_tree_model_get_path (source_model, &source_iter);
523
524   index = *gtk_tree_path_get_indices (path);
525
526   gtk_tree_path_free (path);
527
528   if ( ! gtk_tree_model_get_iter_first (dest_model, &dest_iter) )
529     return FALSE;
530
531   do
532     {
533       GValue value = {0};
534       gtk_tree_model_get_value (dest_model, &dest_iter, 0, &value);
535
536       if ( g_value_get_int (&value) == index)
537         return TRUE;
538     }
539   while (gtk_tree_model_iter_next (dest_model, &dest_iter));
540
541   return FALSE;
542 }
543
544 /* Visibility function for items in the SOURCE widget.
545    Returns TRUE iff *all* the selectors for which SOURCE is associated
546    are visible */
547 static gboolean
548 is_source_item_visible (GtkTreeModel *childmodel,
549                         GtkTreeIter *iter, gpointer data)
550 {
551   PsppireSelector *selector = data;
552   PsppireSelectorClass *class = g_type_class_peek (PSPPIRE_SELECTOR_TYPE);
553
554   GList *list = NULL;
555
556   list = g_hash_table_lookup (class->source_hash, selector->source);
557
558   while (list)
559     {
560       PsppireSelector *selector = list->data;
561
562       if ( selector->filter && selector->filter (childmodel, iter, selector))
563         return FALSE;
564
565       list = list->next;
566     }
567
568
569   return TRUE;
570 }
571
572 /* set the source widget to SOURCE */
573 static void
574 set_tree_view_source (PsppireSelector *selector,
575                       GtkTreeView *source)
576 {
577   GtkTreeSelection* selection ;
578   GList *list = NULL;
579
580   PsppireSelectorClass *class = g_type_class_peek (PSPPIRE_SELECTOR_TYPE);
581
582   if ( ! (list = g_hash_table_lookup (class->source_hash, source)))
583     {
584       selector->filtered_source =
585         GTK_TREE_MODEL_FILTER (gtk_tree_model_filter_new
586                                (gtk_tree_view_get_model (source),  NULL));
587
588       gtk_tree_view_set_model (source, NULL);
589
590       gtk_tree_view_set_model (source,
591                                GTK_TREE_MODEL (selector->filtered_source));
592
593       list = g_list_append (list, selector);
594       g_hash_table_insert (class->source_hash, source, list);
595
596
597       gtk_tree_model_filter_set_visible_func (selector->filtered_source,
598                                               is_source_item_visible,
599                                               selector,
600                                               NULL);
601     }
602   else
603     {  /* Append this selector to the list and push the <source,list>
604           pair onto the hash table */
605
606       selector->filtered_source = GTK_TREE_MODEL_FILTER (
607         gtk_tree_view_get_model (source));
608
609       list = g_list_append (list, selector);
610       g_hash_table_replace (class->source_hash, source, list);
611     }
612
613   selection = gtk_tree_view_get_selection (source);
614
615   g_signal_connect (source, "row-activated", G_CALLBACK (on_row_activate),
616                     selector);
617
618   g_signal_connect (selection, "changed", G_CALLBACK (on_source_select),
619                     selector);
620 }
621
622
623 /*
624    Callback for when the destination treeview's data changes
625  */
626 static void
627 on_dest_data_change (GtkTreeModel *tree_model,
628                      GtkTreePath  *path,
629                      GtkTreeIter  *iter,
630                      gpointer      user_data)
631 {
632   PsppireSelector *selector = user_data;
633
634   if ( selector->selecting) return;
635
636   gtk_tree_model_filter_refilter (selector->filtered_source);
637 }
638
639
640 static void
641 on_dest_data_delete (GtkTreeModel *tree_model,
642                      GtkTreePath  *path,
643                      gpointer      user_data)
644 {
645   PsppireSelector *selector = user_data;
646
647   if ( selector->selecting ) return;
648
649   gtk_tree_model_filter_refilter (selector->filtered_source);
650 }
651
652
653
654
655 /* Set the destination widget to DEST */
656 static void
657 set_tree_view_dest (PsppireSelector *selector,
658                     GtkTreeView *dest)
659 {
660   GtkTreeSelection* selection = gtk_tree_view_get_selection (dest);
661   GtkTreeModel *model = gtk_tree_view_get_model (dest);
662
663   gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
664
665   g_signal_connect (selection, "changed", G_CALLBACK (on_dest_treeview_select),
666                     selector);
667
668   g_signal_connect (model, "row-changed", G_CALLBACK (on_dest_data_change),
669                       selector);
670
671   g_signal_connect (model, "row-deleted", G_CALLBACK (on_dest_data_delete),
672                       selector);
673
674 }
675
676 /* Callback which causes the filter to be refiltered.
677    Called when the DEST GtkEntry is activated (Enter is pressed), or when it
678    looses focus.
679 */
680 static gboolean
681 refilter (PsppireSelector *selector)
682 {
683   gtk_tree_model_filter_refilter (selector->filtered_source);
684   return FALSE;
685 }
686
687 /* Callback for when the DEST GtkEntry is selected (clicked) */
688 static gboolean
689 on_entry_dest_select (GtkWidget *widget, GdkEventFocus *event, gpointer data)
690 {
691   PsppireSelector * selector = data;
692
693   set_direction (selector, PSPPIRE_SELECTOR_DEST_TO_SOURCE);
694
695   return FALSE;
696 }
697
698
699
700 /* Callback for when an item disappears from the source list.
701    By implication, this means that the item has been inserted into the
702    destination.
703  */
704 static void
705 on_row_deleted (PsppireSelector *selector)
706 {
707   g_signal_emit (selector, signals [SELECTED], 0);
708 }
709
710 /* Callback for when a new item appears in the source list.
711    By implication, this means that an item has been deleted from the
712    destination.
713  */
714 static void
715 on_row_inserted (PsppireSelector *selector)
716 {
717   g_signal_emit (selector, signals [DE_SELECTED], 0);
718 }
719
720
721
722 /* Set DEST to be the destination GtkEntry widget */
723 static void
724 set_entry_dest (PsppireSelector *selector,
725                 GtkEntry *dest)
726 {
727   g_signal_connect_swapped (dest, "activate", G_CALLBACK (refilter),
728                     selector);
729
730   g_signal_connect (dest, "focus-in-event", G_CALLBACK (on_entry_dest_select),
731                     selector);
732
733   g_signal_connect_swapped (dest, "focus-out-event", G_CALLBACK (refilter),
734                     selector);
735
736
737   g_signal_connect_swapped (selector->filtered_source, "row-deleted",
738                     G_CALLBACK (on_row_deleted), selector);
739
740   g_signal_connect_swapped (selector->filtered_source, "row-inserted",
741                     G_CALLBACK (on_row_inserted), selector);
742 }
743
744
745 /* Set SOURCE and DEST for this selector, and
746    set SELECT_FUNC and FILTER_FUNC */
747 void
748 psppire_selector_set_subjects (PsppireSelector *selector,
749                                GtkWidget *source,
750                                GtkWidget *dest,
751                                SelectItemsFunc *select_func,
752                                FilterItemsFunc *filter_func )
753 {
754   g_assert(selector);
755
756   selector->filter = filter_func ;
757
758   selector->source = source;
759   selector->dest = dest;
760
761   if ( filter_func == NULL)
762     {
763       if  (GTK_IS_TREE_VIEW (dest))
764         selector->filter = is_item_in_dest;
765     }
766
767   g_signal_connect (selector, "clicked", G_CALLBACK (on_click), NULL);
768
769   if ( GTK_IS_TREE_VIEW (source))
770     set_tree_view_source (selector, GTK_TREE_VIEW (source) );
771   else
772     g_error ("Unsupported source widget: %s", G_OBJECT_TYPE_NAME (source));
773
774   g_assert ( GTK_IS_TREE_MODEL_FILTER (selector->filtered_source));
775
776   if  ( GTK_IS_TREE_VIEW (dest))
777     set_tree_view_dest (selector, GTK_TREE_VIEW (dest));
778
779   else if ( GTK_IS_ENTRY (dest))
780     set_entry_dest (selector, GTK_ENTRY (dest));
781
782   else if (GTK_IS_TEXT_VIEW (dest))
783     {
784       /* Nothing to be done */
785     }
786
787   else
788     g_error ("Unsupported destination widget: %s", G_OBJECT_TYPE_NAME (dest));
789
790   selector->select_items = select_func;
791 }
792
793
794
795 GType
796 psppire_selector_orientation_get_type (void)
797 {
798   static GType etype = 0;
799   if (etype == 0) {
800     static const GEnumValue values[] = {
801       { PSPPIRE_SELECT_SOURCE_BEFORE_DEST, "PSPPIRE_SELECT_SOURCE_BEFORE_DEST", "source before destination" },
802       { PSPPIRE_SELECT_SOURCE_AFTER_DEST, "PSPPIRE_SELECT_SOURCE_AFTER_DEST", "source after destination" },
803       { PSPPIRE_SELECT_SOURCE_ABOVE_DEST, "PSPPIRE_SELECT_SOURCE_ABOVE_DEST", "source above destination" },
804       { PSPPIRE_SELECT_SOURCE_BELOW_DEST, "PSPPIRE_SELECT_SOURCE_BELOW_DEST", "source below destination" },
805       { 0, NULL, NULL }
806     };
807     etype = g_enum_register_static (g_intern_static_string ("PsppireSelectorOrientation"), values);
808   }
809   return etype;
810 }