af3d45a372f6d8b6f5235b351cef94294409bae5
[pspp] / src / ui / gui / psppire-selector.h
1 /* PSPPIRE - a graphical user interface for PSPP.
2    Copyright (C) 2007, 2010  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 #ifndef __PSPPIRE_SELECTOR_H__
19 #define __PSPPIRE_SELECTOR_H__
20
21
22 #include <glib.h>
23 #include <glib-object.h>
24 #include <gtk/gtk.h>
25
26 G_BEGIN_DECLS
27
28 #define PSPPIRE_SELECTOR_TYPE            (psppire_selector_get_type ())
29 #define PSPPIRE_SELECTOR(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), PSPPIRE_SELECTOR_TYPE, PsppireSelector))
30 #define PSPPIRE_SELECTOR_CLASS(class)    (G_TYPE_CHECK_CLASS_CAST ((class), \
31     PSPPIRE_SELECTOR_TYPE, PsppireSelectorClass))
32 #define PSPPIRE_IS_SELECTOR(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
33     PSPPIRE_SELECTOR_TYPE))
34 #define PSPPIRE_IS_SELECTOR_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), \
35     PSPPIRE_SELECTOR_TYPE))
36
37
38 typedef struct _PsppireSelector       PsppireSelector;
39 typedef struct _PsppireSelectorClass  PsppireSelectorClass;
40
41
42 /* Function for appending selected items to the destination widget */
43 typedef void SelectItemsFunc (GtkTreeIter iter,
44                               GtkWidget *dest,
45                               GtkTreeModel *source_model,
46                               gpointer data);
47
48 /* Function to determine if items may be selected */
49 typedef gboolean AllowSelectionFunc (GtkWidget *src, GtkWidget *dest);
50
51
52 /* Function to determine whether an item in MODEL, pointed to by ITER
53    is currently selected.
54
55    Returns TRUE if the item is currently selected, FALSE otherwise.
56  */
57 typedef gboolean FilterItemsFunc (GtkTreeModel *model,
58                                   GtkTreeIter *iter,
59                                   PsppireSelector *selector);
60
61 enum psppire_selector_dir
62   {
63     PSPPIRE_SELECTOR_SOURCE_TO_DEST,
64     PSPPIRE_SELECTOR_DEST_TO_SOURCE
65   };
66
67
68 struct _PsppireSelector
69 {
70   GtkButton parent;
71
72   /* <private> */
73   GtkWidget *arrow;
74
75   gboolean dispose_has_run;
76
77   enum psppire_selector_dir direction;
78
79   GtkWidget *source;
80   GtkWidget *dest;
81
82   /* A flag indicating that the object is in the process of
83      updating its subjects.
84      (not thread safe if two threads access the same object)
85   */
86   gboolean selecting;
87
88   gint orientation;
89
90   GtkTreeModelFilter *filtered_source;
91
92   SelectItemsFunc *select_items;
93   gpointer select_user_data;
94
95   FilterItemsFunc *filter;
96
97   AllowSelectionFunc *allow_selection;
98
99   gulong row_activate_id ;
100
101   gulong source_select_id ;
102
103   gboolean primary_requested;
104 };
105
106 struct _PsppireSelectorClass
107 {
108   GtkButtonClass parent_class;
109
110   /* This is a hash of Lists of FilterItemsFunc pointers, keyed by address of
111      the source widget */
112   GHashTable *source_hash;
113
114   /* A hash of SelectItemFuncs indexed by GType */
115   GHashTable *default_selection_funcs;
116 };
117
118 GType      psppire_selector_get_type        (void);
119 GtkWidget* psppire_selector_new             (void);
120
121
122 /* Set FILTER_FUNC for this selector */
123 void psppire_selector_set_filter_func (PsppireSelector *selector,
124                                        FilterItemsFunc *filter_func);
125
126 /* Set SELECT_FUNC for this selector */
127 void psppire_selector_set_select_func (PsppireSelector *selector,
128                                        SelectItemsFunc *select_func,
129                                        gpointer user_data);
130
131
132 void psppire_selector_set_allow (PsppireSelector *, AllowSelectionFunc *);
133
134
135 GType psppire_selector_orientation_get_type (void) G_GNUC_CONST;
136
137
138 typedef enum {
139   PSPPIRE_SELECT_SOURCE_BEFORE_DEST,
140   PSPPIRE_SELECT_SOURCE_AFTER_DEST,
141   PSPPIRE_SELECT_SOURCE_ABOVE_DEST,
142   PSPPIRE_SELECT_SOURCE_BELOW_DEST
143 } PsppireSelectorOrientation;
144
145 #define PSPPIRE_TYPE_SELECTOR_ORIENTATION \
146   (psppire_selector_orientation_get_type())
147
148
149 void psppire_selector_set_default_selection_func (GType type, SelectItemsFunc *);
150
151
152 G_END_DECLS
153
154 #endif /* __PSPPIRE_SELECTOR_H__ */