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