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