pspp-sheet-view: Rename GtkTreeSelectMode to PsppSheetSelectMode.
[pspp] / src / ui / gui / pspp-sheet-view.h
1 /* PSPPIRE - a graphical user interface for PSPP.
2    Copyright (C) 2011, 2012 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 /* gtktreeview.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_VIEW_H__
37 #define __PSPP_SHEET_VIEW_H__
38
39 #include <gtk/gtk.h>
40 #include "ui/gui/pspp-sheet-view-column.h"
41
42 G_BEGIN_DECLS
43
44
45 typedef enum
46 {
47   PSPP_SHEET_VIEW_GRID_LINES_NONE,
48   PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL,
49   PSPP_SHEET_VIEW_GRID_LINES_VERTICAL,
50   PSPP_SHEET_VIEW_GRID_LINES_BOTH
51 } PsppSheetViewGridLines;
52
53 GType pspp_sheet_view_grid_lines_get_type (void) G_GNUC_CONST;
54 #define PSPP_TYPE_SHEET_VIEW_GRID_LINES (pspp_sheet_view_grid_lines_get_type ())
55
56 /* A "special cell" is a cell that is editable or activatable.  When a row that
57  * contains a special cell is selected, the cursor is drawn around a single
58  * cell; when other rows are selected, the cursor is drawn around the entire
59  * row.
60  *
61  * With the default of "detect", whether a given row contains a special cell is
62  * detected automatically.  This is the best choice most of the time.  For
63  * sheet views that contain more than 100 columns, an explicit "yes" or "no"
64  * improves performance. */
65 typedef enum
66 {
67   PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT,
68   PSPP_SHEET_VIEW_SPECIAL_CELLS_YES,
69   PSPP_SHEET_VIEW_SPECIAL_CELLS_NO,
70 } PsppSheetViewSpecialCells;
71
72 GType pspp_sheet_view_special_cells_get_type (void) G_GNUC_CONST;
73 #define PSPP_TYPE_SHEET_VIEW_SPECIAL_CELLS (pspp_sheet_view_special_cells_get_type ())
74
75 typedef enum
76 {
77   /* drop before/after this row */
78   PSPP_SHEET_VIEW_DROP_BEFORE,
79   PSPP_SHEET_VIEW_DROP_AFTER,
80   /* drop as a child of this row (with fallback to before or after
81    * if into is not possible)
82    */
83   PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE,
84   PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER
85 } PsppSheetViewDropPosition;
86
87 #define PSPP_TYPE_SHEET_VIEW            (pspp_sheet_view_get_type ())
88 #define PSPP_SHEET_VIEW(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), PSPP_TYPE_SHEET_VIEW, PsppSheetView))
89 #define PSPP_SHEET_VIEW_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), PSPP_TYPE_SHEET_VIEW, PsppSheetViewClass))
90 #define PSPP_IS_SHEET_VIEW(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PSPP_TYPE_SHEET_VIEW))
91 #define PSPP_IS_SHEET_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PSPP_TYPE_SHEET_VIEW))
92 #define PSPP_SHEET_VIEW_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), PSPP_TYPE_SHEET_VIEW, PsppSheetViewClass))
93
94 typedef struct _PsppSheetView           PsppSheetView;
95 typedef struct _PsppSheetViewClass      PsppSheetViewClass;
96 typedef struct _PsppSheetViewPrivate    PsppSheetViewPrivate;
97 typedef struct _PsppSheetSelection      PsppSheetSelection;
98 typedef struct _PsppSheetSelectionClass PsppSheetSelectionClass;
99
100 struct _PsppSheetView
101 {
102   GtkContainer parent;
103
104   PsppSheetViewPrivate *GSEAL (priv);
105
106   gboolean dispose_has_run ;
107 };
108
109 struct _PsppSheetViewClass
110 {
111   GtkContainerClass parent_class;
112
113   void     (* set_scroll_adjustments)     (PsppSheetView       *tree_view,
114                                            GtkAdjustment     *hadjustment,
115                                            GtkAdjustment     *vadjustment);
116   void     (* row_activated)              (PsppSheetView       *tree_view,
117                                            GtkTreePath       *path,
118                                            PsppSheetViewColumn *column);
119   void     (* columns_changed)            (PsppSheetView       *tree_view);
120   void     (* cursor_changed)             (PsppSheetView       *tree_view);
121
122   /* Key Binding signals */
123   gboolean (* move_cursor)                (PsppSheetView       *tree_view,
124                                            GtkMovementStep    step,
125                                            gint               count);
126   gboolean (* select_all)                 (PsppSheetView       *tree_view);
127   gboolean (* unselect_all)               (PsppSheetView       *tree_view);
128   gboolean (* select_cursor_row)          (PsppSheetView       *tree_view,
129                                            gboolean           start_editing);
130   gboolean (* toggle_cursor_row)          (PsppSheetView       *tree_view);
131   gboolean (* select_cursor_parent)       (PsppSheetView       *tree_view);
132   gboolean (* start_interactive_search)   (PsppSheetView       *tree_view);
133
134   /* Padding for future expansion */
135   void (*_gtk_reserved0) (void);
136   void (*_gtk_reserved1) (void);
137   void (*_gtk_reserved2) (void);
138   void (*_gtk_reserved3) (void);
139   void (*_gtk_reserved4) (void);
140 };
141
142
143 typedef gboolean (* PsppSheetViewColumnDropFunc) (PsppSheetView             *tree_view,
144                                                 PsppSheetViewColumn       *column,
145                                                 PsppSheetViewColumn       *prev_column,
146                                                 PsppSheetViewColumn       *next_column,
147                                                 gpointer                 data);
148 typedef void     (* PsppSheetViewMappingFunc)    (PsppSheetView             *tree_view,
149                                                 GtkTreePath             *path,
150                                                 gpointer                 user_data);
151 typedef gboolean (*PsppSheetViewSearchEqualFunc) (GtkTreeModel            *model,
152                                                 gint                     column,
153                                                 const gchar             *key,
154                                                 GtkTreeIter             *iter,
155                                                 gpointer                 search_data);
156 typedef void     (*PsppSheetViewSearchPositionFunc) (PsppSheetView  *tree_view,
157                                                    GtkWidget    *search_dialog,
158                                                    gpointer      user_data);
159
160
161 /* Creators */
162 GType                  pspp_sheet_view_get_type                      (void) G_GNUC_CONST;
163 GtkWidget             *pspp_sheet_view_new                           (void);
164 GtkWidget             *pspp_sheet_view_new_with_model                (GtkTreeModel              *model);
165
166 /* Accessors */
167 GtkTreeModel          *pspp_sheet_view_get_model                     (PsppSheetView               *tree_view);
168 void                   pspp_sheet_view_set_model                     (PsppSheetView               *tree_view,
169                                                                     GtkTreeModel              *model);
170 PsppSheetSelection      *pspp_sheet_view_get_selection                 (PsppSheetView               *tree_view);
171 GtkAdjustment         *pspp_sheet_view_get_hadjustment               (PsppSheetView               *tree_view);
172 void                   pspp_sheet_view_set_hadjustment               (PsppSheetView               *tree_view,
173                                                                     GtkAdjustment             *adjustment);
174 GtkAdjustment         *pspp_sheet_view_get_vadjustment               (PsppSheetView               *tree_view);
175 void                   pspp_sheet_view_set_vadjustment               (PsppSheetView               *tree_view,
176                                                                     GtkAdjustment             *adjustment);
177 gboolean               pspp_sheet_view_get_headers_visible           (PsppSheetView               *tree_view);
178 void                   pspp_sheet_view_set_headers_visible           (PsppSheetView               *tree_view,
179                                                                     gboolean                   headers_visible);
180 void                   pspp_sheet_view_columns_autosize              (PsppSheetView               *tree_view);
181 gboolean               pspp_sheet_view_get_headers_clickable         (PsppSheetView *tree_view);
182 void                   pspp_sheet_view_set_headers_clickable         (PsppSheetView               *tree_view,
183                                                                     gboolean                   setting);
184 void                   pspp_sheet_view_set_rules_hint                (PsppSheetView               *tree_view,
185                                                                     gboolean                   setting);
186 gboolean               pspp_sheet_view_get_rules_hint                (PsppSheetView               *tree_view);
187
188 /* Column funtions */
189 gint                   pspp_sheet_view_append_column                 (PsppSheetView               *tree_view,
190                                                                     PsppSheetViewColumn         *column);
191 gint                   pspp_sheet_view_remove_column                 (PsppSheetView               *tree_view,
192                                                                     PsppSheetViewColumn         *column);
193 gint                   pspp_sheet_view_insert_column                 (PsppSheetView               *tree_view,
194                                                                     PsppSheetViewColumn         *column,
195                                                                     gint                       position);
196 gint                   pspp_sheet_view_insert_column_with_attributes (PsppSheetView               *tree_view,
197                                                                     gint                       position,
198                                                                     const gchar               *title,
199                                                                     GtkCellRenderer           *cell,
200                                                                     ...) G_GNUC_NULL_TERMINATED;
201 gint                   pspp_sheet_view_insert_column_with_data_func  (PsppSheetView               *tree_view,
202                                                                     gint                       position,
203                                                                     const gchar               *title,
204                                                                     GtkCellRenderer           *cell,
205                                                                     PsppSheetCellDataFunc        func,
206                                                                     gpointer                   data,
207                                                                     GDestroyNotify             dnotify);
208 PsppSheetViewColumn     *pspp_sheet_view_get_column                    (PsppSheetView               *tree_view,
209                                                                     gint                       n);
210 GList                 *pspp_sheet_view_get_columns                   (PsppSheetView               *tree_view);
211 void                   pspp_sheet_view_move_column_after             (PsppSheetView               *tree_view,
212                                                                     PsppSheetViewColumn         *column,
213                                                                     PsppSheetViewColumn         *base_column);
214 void                   pspp_sheet_view_set_column_drag_function      (PsppSheetView               *tree_view,
215                                                                     PsppSheetViewColumnDropFunc  func,
216                                                                     gpointer                   user_data,
217                                                                     GDestroyNotify             destroy);
218
219 /* Actions */
220 void                   pspp_sheet_view_scroll_to_point               (PsppSheetView               *tree_view,
221                                                                     gint                       tree_x,
222                                                                     gint                       tree_y);
223 void                   pspp_sheet_view_scroll_to_cell                (PsppSheetView               *tree_view,
224                                                                     GtkTreePath               *path,
225                                                                     PsppSheetViewColumn         *column,
226                                                                     gboolean                   use_align,
227                                                                     gfloat                     row_align,
228                                                                     gfloat                     col_align);
229 void                   pspp_sheet_view_row_activated                 (PsppSheetView               *tree_view,
230                                                                     GtkTreePath               *path,
231                                                                     PsppSheetViewColumn         *column);
232 void                   pspp_sheet_view_set_reorderable               (PsppSheetView               *tree_view,
233                                                                     gboolean                   reorderable);
234 gboolean               pspp_sheet_view_get_reorderable               (PsppSheetView               *tree_view);
235 void                   pspp_sheet_view_set_cursor                    (PsppSheetView               *tree_view,
236                                                                     GtkTreePath               *path,
237                                                                     PsppSheetViewColumn         *focus_column,
238                                                                     gboolean                   start_editing);
239 void                   pspp_sheet_view_set_cursor_on_cell            (PsppSheetView               *tree_view,
240                                                                     GtkTreePath               *path,
241                                                                     PsppSheetViewColumn         *focus_column,
242                                                                     GtkCellRenderer           *focus_cell,
243                                                                     gboolean                   start_editing);
244 void                   pspp_sheet_view_get_cursor                    (PsppSheetView               *tree_view,
245                                                                     GtkTreePath              **path,
246                                                                     PsppSheetViewColumn        **focus_column);
247
248
249 /* Layout information */
250 GdkWindow             *pspp_sheet_view_get_bin_window                (PsppSheetView               *tree_view);
251 gboolean               pspp_sheet_view_get_path_at_pos               (PsppSheetView               *tree_view,
252                                                                     gint                       x,
253                                                                     gint                       y,
254                                                                     GtkTreePath              **path,
255                                                                     PsppSheetViewColumn        **column,
256                                                                     gint                      *cell_x,
257                                                                     gint                      *cell_y);
258 void                   pspp_sheet_view_get_cell_area                 (PsppSheetView               *tree_view,
259                                                                     GtkTreePath               *path,
260                                                                     PsppSheetViewColumn         *column,
261                                                                     GdkRectangle              *rect);
262 void                   pspp_sheet_view_get_background_area           (PsppSheetView               *tree_view,
263                                                                     GtkTreePath               *path,
264                                                                     PsppSheetViewColumn         *column,
265                                                                     GdkRectangle              *rect);
266 void                   pspp_sheet_view_get_visible_rect              (PsppSheetView               *tree_view,
267                                                                     GdkRectangle              *visible_rect);
268
269 #ifndef GTK_DISABLE_DEPRECATED
270 void                   pspp_sheet_view_widget_to_tree_coords         (PsppSheetView               *tree_view,
271                                                                     gint                       wx,
272                                                                     gint                       wy,
273                                                                     gint                      *tx,
274                                                                     gint                      *ty);
275 void                   pspp_sheet_view_tree_to_widget_coords         (PsppSheetView               *tree_view,
276                                                                     gint                       tx,
277                                                                     gint                       ty,
278                                                                     gint                      *wx,
279                                                                     gint                      *wy);
280 #endif /* !GTK_DISABLE_DEPRECATED */
281 gboolean               pspp_sheet_view_get_visible_range             (PsppSheetView               *tree_view,
282                                                                     GtkTreePath              **start_path,
283                                                                     GtkTreePath              **end_path);
284
285 /* Drag-and-Drop support */
286 void                   pspp_sheet_view_enable_model_drag_source      (PsppSheetView               *tree_view,
287                                                                     GdkModifierType            start_button_mask,
288                                                                     const GtkTargetEntry      *targets,
289                                                                     gint                       n_targets,
290                                                                     GdkDragAction              actions);
291 void                   pspp_sheet_view_enable_model_drag_dest        (PsppSheetView               *tree_view,
292                                                                     const GtkTargetEntry      *targets,
293                                                                     gint                       n_targets,
294                                                                     GdkDragAction              actions);
295 void                   pspp_sheet_view_unset_rows_drag_source        (PsppSheetView               *tree_view);
296 void                   pspp_sheet_view_unset_rows_drag_dest          (PsppSheetView               *tree_view);
297
298
299 /* These are useful to implement your own custom stuff. */
300 void                   pspp_sheet_view_set_drag_dest_row             (PsppSheetView               *tree_view,
301                                                                     GtkTreePath               *path,
302                                                                     PsppSheetViewDropPosition    pos);
303 void                   pspp_sheet_view_get_drag_dest_row             (PsppSheetView               *tree_view,
304                                                                     GtkTreePath              **path,
305                                                                     PsppSheetViewDropPosition   *pos);
306 gboolean               pspp_sheet_view_get_dest_row_at_pos           (PsppSheetView               *tree_view,
307                                                                     gint                       drag_x,
308                                                                     gint                       drag_y,
309                                                                     GtkTreePath              **path,
310                                                                     PsppSheetViewDropPosition   *pos);
311 GdkPixmap             *pspp_sheet_view_create_row_drag_icon          (PsppSheetView               *tree_view,
312                                                                     GtkTreePath               *path);
313
314 /* Interactive search */
315 void                       pspp_sheet_view_set_enable_search     (PsppSheetView                *tree_view,
316                                                                 gboolean                    enable_search);
317 gboolean                   pspp_sheet_view_get_enable_search     (PsppSheetView                *tree_view);
318 gint                       pspp_sheet_view_get_search_column     (PsppSheetView                *tree_view);
319 void                       pspp_sheet_view_set_search_column     (PsppSheetView                *tree_view,
320                                                                 gint                        column);
321 PsppSheetViewSearchEqualFunc pspp_sheet_view_get_search_equal_func (PsppSheetView                *tree_view);
322 void                       pspp_sheet_view_set_search_equal_func (PsppSheetView                *tree_view,
323                                                                 PsppSheetViewSearchEqualFunc  search_equal_func,
324                                                                 gpointer                    search_user_data,
325                                                                 GDestroyNotify              search_destroy);
326
327 GtkEntry                     *pspp_sheet_view_get_search_entry         (PsppSheetView                   *tree_view);
328 void                          pspp_sheet_view_set_search_entry         (PsppSheetView                   *tree_view,
329                                                                       GtkEntry                      *entry);
330 PsppSheetViewSearchPositionFunc pspp_sheet_view_get_search_position_func (PsppSheetView                   *tree_view);
331 void                          pspp_sheet_view_set_search_position_func (PsppSheetView                   *tree_view,
332                                                                       PsppSheetViewSearchPositionFunc  func,
333                                                                       gpointer                       data,
334                                                                       GDestroyNotify                 destroy);
335
336 /* Convert between the different coordinate systems */
337 void pspp_sheet_view_convert_widget_to_tree_coords       (PsppSheetView *tree_view,
338                                                         gint         wx,
339                                                         gint         wy,
340                                                         gint        *tx,
341                                                         gint        *ty);
342 void pspp_sheet_view_convert_tree_to_widget_coords       (PsppSheetView *tree_view,
343                                                         gint         tx,
344                                                         gint         ty,
345                                                         gint        *wx,
346                                                         gint        *wy);
347 void pspp_sheet_view_convert_widget_to_bin_window_coords (PsppSheetView *tree_view,
348                                                         gint         wx,
349                                                         gint         wy,
350                                                         gint        *bx,
351                                                         gint        *by);
352 void pspp_sheet_view_convert_bin_window_to_widget_coords (PsppSheetView *tree_view,
353                                                         gint         bx,
354                                                         gint         by,
355                                                         gint        *wx,
356                                                         gint        *wy);
357 void pspp_sheet_view_convert_tree_to_bin_window_coords   (PsppSheetView *tree_view,
358                                                         gint         tx,
359                                                         gint         ty,
360                                                         gint        *bx,
361                                                         gint        *by);
362 void pspp_sheet_view_convert_bin_window_to_tree_coords   (PsppSheetView *tree_view,
363                                                         gint         bx,
364                                                         gint         by,
365                                                         gint        *tx,
366                                                         gint        *ty);
367
368 /* This function should really never be used.  It is just for use by ATK.
369  */
370 typedef void (* PsppSheetDestroyCountFunc)  (PsppSheetView             *tree_view,
371                                            GtkTreePath             *path,
372                                            gint                     children,
373                                            gpointer                 user_data);
374 void pspp_sheet_view_set_destroy_count_func (PsppSheetView             *tree_view,
375                                            PsppSheetDestroyCountFunc  func,
376                                            gpointer                 data,
377                                            GDestroyNotify           destroy);
378
379 void     pspp_sheet_view_set_hover_selection   (PsppSheetView          *tree_view,
380                                               gboolean              hover);
381 gboolean pspp_sheet_view_get_hover_selection   (PsppSheetView          *tree_view);
382 void     pspp_sheet_view_set_rubber_banding    (PsppSheetView          *tree_view,
383                                               gboolean              enable);
384 gboolean pspp_sheet_view_get_rubber_banding    (PsppSheetView          *tree_view);
385
386 gboolean pspp_sheet_view_is_rubber_banding_active (PsppSheetView       *tree_view);
387
388 PsppSheetViewGridLines        pspp_sheet_view_get_grid_lines         (PsppSheetView                *tree_view);
389 void                        pspp_sheet_view_set_grid_lines         (PsppSheetView                *tree_view,
390                                                                   PsppSheetViewGridLines        grid_lines);
391
392 PsppSheetViewSpecialCells pspp_sheet_view_get_special_cells (PsppSheetView                *tree_view);
393 void                        pspp_sheet_view_set_special_cells (PsppSheetView                *tree_view,
394                                                                PsppSheetViewSpecialCells);
395
396 int           pspp_sheet_view_get_fixed_height (const PsppSheetView *);
397 void          pspp_sheet_view_set_fixed_height (PsppSheetView *,
398                                                 int fixed_height);
399
400 /* Convenience functions for setting tooltips */
401 void          pspp_sheet_view_set_tooltip_row    (PsppSheetView       *tree_view,
402                                                 GtkTooltip        *tooltip,
403                                                 GtkTreePath       *path);
404 void          pspp_sheet_view_set_tooltip_cell   (PsppSheetView       *tree_view,
405                                                 GtkTooltip        *tooltip,
406                                                 GtkTreePath       *path,
407                                                 PsppSheetViewColumn *column,
408                                                 GtkCellRenderer   *cell);
409 gboolean      pspp_sheet_view_get_tooltip_context(PsppSheetView       *tree_view,
410                                                 gint              *x,
411                                                 gint              *y,
412                                                 gboolean           keyboard_tip,
413                                                 GtkTreeModel     **model,
414                                                 GtkTreePath      **path,
415                                                 GtkTreeIter       *iter);
416 void          pspp_sheet_view_set_tooltip_column (PsppSheetView       *tree_view,
417                                                 gint               column);
418 gint          pspp_sheet_view_get_tooltip_column (PsppSheetView       *tree_view);
419
420 void pspp_sheet_view_stop_editing (PsppSheetView *tree_view,
421                                    gboolean     cancel_editing);
422
423 G_END_DECLS
424
425
426 #endif /* __PSPP_SHEET_VIEW_H__ */