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