pspp-sheet-view: Reduce time and memory cost to O(1) in number of rows.
[pspp] / src / ui / gui / pspp-sheet-selection.h
1 /* PSPPIRE - a graphical user interface for PSPP.
2    Copyright (C) 2011 Free Software Foundation, Inc.
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 /* gtktreeselection.h
18  * Copyright (C) 2000  Red Hat, Inc.,  Jonathan Blandford <jrb@redhat.com>
19  *
20  * This library is free software; you can redistribute it and/or
21  * modify it under the terms of the GNU Library General Public
22  * License as published by the Free Software Foundation; either
23  * version 2 of the License, or (at your option) any later version.
24  *
25  * This library is distributed in the hope that it will be useful,
26  * but WITHOUT ANY WARRANTY; without even the implied warranty of
27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
28  * Library General Public License for more details.
29  *
30  * You should have received a copy of the GNU Library General Public
31  * License along with this library; if not, write to the
32  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
33  * Boston, MA 02111-1307, USA.
34  */
35
36 #ifndef __PSPP_SHEET_SELECTION_H__
37 #define __PSPP_SHEET_SELECTION_H__
38
39 #include <gtk/gtk.h>
40
41 G_BEGIN_DECLS
42
43
44 #define PSPP_TYPE_SHEET_SELECTION                       (pspp_sheet_selection_get_type ())
45 #define PSPP_SHEET_SELECTION(obj)                       (G_TYPE_CHECK_INSTANCE_CAST ((obj), PSPP_TYPE_SHEET_SELECTION, PsppSheetSelection))
46 #define PSPP_SHEET_SELECTION_CLASS(klass)               (G_TYPE_CHECK_CLASS_CAST ((klass), PSPP_TYPE_SHEET_SELECTION, PsppSheetSelectionClass))
47 #define PSPP_IS_SHEET_SELECTION(obj)            (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PSPP_TYPE_SHEET_SELECTION))
48 #define PSPP_IS_SHEET_SELECTION_CLASS(klass)    (G_TYPE_CHECK_CLASS_TYPE ((klass), PSPP_TYPE_SHEET_SELECTION))
49 #define PSPP_SHEET_SELECTION_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS ((obj), PSPP_TYPE_SHEET_SELECTION, PsppSheetSelectionClass))
50
51 typedef gboolean (* PsppSheetSelectionFunc)    (PsppSheetSelection  *selection,
52                                               GtkTreeModel      *model,
53                                               GtkTreePath       *path,
54                                               gboolean           path_currently_selected,
55                                               gpointer           data);
56 typedef void (* PsppSheetSelectionForeachFunc) (GtkTreeModel      *model,
57                                               GtkTreePath       *path,
58                                               GtkTreeIter       *iter,
59                                               gpointer           data);
60
61 struct _PsppSheetSelection
62 {
63   GObject parent;
64
65   /*< private >*/
66
67   PsppSheetView *GSEAL (tree_view);
68   GtkSelectionMode GSEAL (type);
69 };
70
71 struct _PsppSheetSelectionClass
72 {
73   GObjectClass parent_class;
74
75   void (* changed) (PsppSheetSelection *selection);
76
77   /* Padding for future expansion */
78   void (*_gtk_reserved1) (void);
79   void (*_gtk_reserved2) (void);
80   void (*_gtk_reserved3) (void);
81   void (*_gtk_reserved4) (void);
82 };
83
84
85 GType            pspp_sheet_selection_get_type            (void) G_GNUC_CONST;
86
87 void             pspp_sheet_selection_set_mode            (PsppSheetSelection            *selection,
88                                                          GtkSelectionMode             type);
89 GtkSelectionMode pspp_sheet_selection_get_mode        (PsppSheetSelection            *selection);
90 void             pspp_sheet_selection_set_select_function (PsppSheetSelection            *selection,
91                                                          PsppSheetSelectionFunc         func,
92                                                          gpointer                     data,
93                                                          GDestroyNotify               destroy);
94 gpointer         pspp_sheet_selection_get_user_data       (PsppSheetSelection            *selection);
95 PsppSheetView*     pspp_sheet_selection_get_tree_view       (PsppSheetSelection            *selection);
96
97 PsppSheetSelectionFunc pspp_sheet_selection_get_select_function (PsppSheetSelection        *selection);
98
99 /* Only meaningful if GTK_SELECTION_SINGLE or GTK_SELECTION_BROWSE is set */
100 /* Use selected_foreach or get_selected_rows for GTK_SELECTION_MULTIPLE */
101 gboolean         pspp_sheet_selection_get_selected        (PsppSheetSelection            *selection,
102                                                          GtkTreeModel               **model,
103                                                          GtkTreeIter                 *iter);
104 GList *          pspp_sheet_selection_get_selected_rows   (PsppSheetSelection            *selection,
105                                                          GtkTreeModel               **model);
106 gint             pspp_sheet_selection_count_selected_rows (PsppSheetSelection            *selection);
107 void             pspp_sheet_selection_selected_foreach    (PsppSheetSelection            *selection,
108                                                          PsppSheetSelectionForeachFunc  func,
109                                                          gpointer                     data);
110 void             pspp_sheet_selection_select_path         (PsppSheetSelection            *selection,
111                                                          GtkTreePath                 *path);
112 void             pspp_sheet_selection_unselect_path       (PsppSheetSelection            *selection,
113                                                          GtkTreePath                 *path);
114 void             pspp_sheet_selection_select_iter         (PsppSheetSelection            *selection,
115                                                          GtkTreeIter                 *iter);
116 void             pspp_sheet_selection_unselect_iter       (PsppSheetSelection            *selection,
117                                                          GtkTreeIter                 *iter);
118 gboolean         pspp_sheet_selection_path_is_selected    (PsppSheetSelection            *selection,
119                                                          GtkTreePath                 *path);
120 gboolean         pspp_sheet_selection_iter_is_selected    (PsppSheetSelection            *selection,
121                                                          GtkTreeIter                 *iter);
122 void             pspp_sheet_selection_select_all          (PsppSheetSelection            *selection);
123 void             pspp_sheet_selection_unselect_all        (PsppSheetSelection            *selection);
124 void             pspp_sheet_selection_select_range        (PsppSheetSelection            *selection,
125                                                          GtkTreePath                 *start_path,
126                                                          GtkTreePath                 *end_path);
127 void             pspp_sheet_selection_unselect_range      (PsppSheetSelection            *selection,
128                                                          GtkTreePath                 *start_path,
129                                                          GtkTreePath                 *end_path);
130
131
132 G_END_DECLS
133
134 #endif /* __PSPP_SHEET_SELECTION_H__ */