1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2011, 2012, 2013, 2015 Free Software Foundation, Inc.
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.
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.
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/>. */
18 * Copyright (C) 2000 Red Hat, Inc., Jonathan Blandford <jrb@redhat.com>
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.
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.
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.
38 #include "ui/gui/pspp-sheet-private.h"
42 #include <gdk/gdkkeysyms.h>
43 #include <gdk/gdkkeysyms-compat.h>
46 #include "ui/gui/psppire-marshal.h"
47 #include "ui/gui/pspp-sheet-selection.h"
49 #define P_(STRING) STRING
50 #define GTK_PARAM_READABLE G_PARAM_READABLE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
51 #define GTK_PARAM_READWRITE G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
53 /* Many keyboard shortcuts for Mac are the same as for X
54 * except they use Command key instead of Control (e.g. Cut,
55 * Copy, Paste). This symbol is for those simple cases. */
56 #ifndef GDK_WINDOWING_QUARTZ
57 #define GTK_DEFAULT_ACCEL_MOD_MASK GDK_CONTROL_MASK
59 #define GTK_DEFAULT_ACCEL_MOD_MASK GDK_META_MASK
62 #define PSPP_SHEET_VIEW_PRIORITY_VALIDATE (GDK_PRIORITY_REDRAW + 5)
63 #define PSPP_SHEET_VIEW_PRIORITY_SCROLL_SYNC (PSPP_SHEET_VIEW_PRIORITY_VALIDATE + 2)
64 #define PSPP_SHEET_VIEW_TIME_MS_PER_IDLE 30
65 #define SCROLL_EDGE_SIZE 15
66 #define EXPANDER_EXTRA_PADDING 4
67 #define PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT 5000
69 /* The "background" areas of all rows/cells add up to cover the entire tree.
70 * The background includes all inter-row and inter-cell spacing.
71 * The "cell" areas are the cell_area passed in to gtk_cell_renderer_render(),
72 * i.e. just the cells, no spacing.
75 #define BACKGROUND_HEIGHT(tree_view) (tree_view->priv->fixed_height)
76 #define CELL_HEIGHT(tree_view, separator) ((BACKGROUND_HEIGHT (tree_view)) - (separator))
78 /* Translate from bin_window coordinates to rbtree (tree coordinates) and
81 #define TREE_WINDOW_Y_TO_RBTREE_Y(tree_view,y) ((y) + tree_view->priv->dy)
82 #define RBTREE_Y_TO_TREE_WINDOW_Y(tree_view,y) ((y) - tree_view->priv->dy)
84 /* This is in bin_window coordinates */
85 #define BACKGROUND_FIRST_PIXEL(tree_view,node) (RBTREE_Y_TO_TREE_WINDOW_Y (tree_view, pspp_sheet_view_node_find_offset (tree_view, (node))))
86 #define CELL_FIRST_PIXEL(tree_view,node,separator) (BACKGROUND_FIRST_PIXEL (tree_view,node) + separator/2)
88 #define ROW_HEIGHT(tree_view) \
89 ((tree_view->priv->fixed_height > 0) ? (tree_view->priv->fixed_height) : (tree_view)->priv->expander_size)
92 typedef struct _PsppSheetViewChild PsppSheetViewChild;
93 struct _PsppSheetViewChild
96 PsppSheetViewColumn *column;
101 typedef struct _TreeViewDragInfo TreeViewDragInfo;
102 struct _TreeViewDragInfo
104 GdkModifierType start_button_mask;
105 GtkTargetList *_unused_source_target_list;
106 GdkDragAction source_actions;
108 GtkTargetList *_unused_dest_target_list;
110 guint source_set : 1;
126 START_INTERACTIVE_SEARCH,
138 PROP_HEADERS_VISIBLE,
139 PROP_HEADERS_CLICKABLE,
144 PROP_HOVER_SELECTION,
146 PROP_ENABLE_GRID_LINES,
150 PROP_FIXED_HEIGHT_SET
154 static void pspp_sheet_view_finalize (GObject *object);
155 static void pspp_sheet_view_set_property (GObject *object,
159 static void pspp_sheet_view_get_property (GObject *object,
164 static void pspp_sheet_view_dispose (GObject *object);
166 /* gtkwidget signals */
167 static void pspp_sheet_view_realize (GtkWidget *widget);
168 static void pspp_sheet_view_unrealize (GtkWidget *widget);
169 static void pspp_sheet_view_map (GtkWidget *widget);
170 static void pspp_sheet_view_size_request (GtkWidget *widget,
171 GtkRequisition *requisition);
172 static void pspp_sheet_view_size_allocate (GtkWidget *widget,
173 GtkAllocation *allocation);
174 static gboolean pspp_sheet_view_draw (GtkWidget *widget,
176 static gboolean pspp_sheet_view_key_press (GtkWidget *widget,
178 static gboolean pspp_sheet_view_key_release (GtkWidget *widget,
180 static gboolean pspp_sheet_view_motion (GtkWidget *widget,
181 GdkEventMotion *event);
182 static gboolean pspp_sheet_view_enter_notify (GtkWidget *widget,
183 GdkEventCrossing *event);
184 static gboolean pspp_sheet_view_leave_notify (GtkWidget *widget,
185 GdkEventCrossing *event);
186 static gboolean pspp_sheet_view_button_press (GtkWidget *widget,
187 GdkEventButton *event);
188 static gboolean pspp_sheet_view_button_release (GtkWidget *widget,
189 GdkEventButton *event);
190 static gboolean pspp_sheet_view_grab_broken (GtkWidget *widget,
191 GdkEventGrabBroken *event);
193 static void pspp_sheet_view_set_focus_child (GtkContainer *container,
195 static gint pspp_sheet_view_focus_out (GtkWidget *widget,
196 GdkEventFocus *event);
197 static gint pspp_sheet_view_focus (GtkWidget *widget,
198 GtkDirectionType direction);
199 static void pspp_sheet_view_grab_focus (GtkWidget *widget);
200 static void pspp_sheet_view_style_updated (GtkWidget *widget);
201 static void pspp_sheet_view_grab_notify (GtkWidget *widget,
202 gboolean was_grabbed);
203 static void pspp_sheet_view_state_changed (GtkWidget *widget,
204 GtkStateType previous_state);
206 /* container signals */
207 static void pspp_sheet_view_remove (GtkContainer *container,
209 static void pspp_sheet_view_forall (GtkContainer *container,
210 gboolean include_internals,
211 GtkCallback callback,
212 gpointer callback_data);
214 /* Source side drag signals */
215 static void pspp_sheet_view_drag_begin (GtkWidget *widget,
216 GdkDragContext *context);
217 static void pspp_sheet_view_drag_end (GtkWidget *widget,
218 GdkDragContext *context);
219 static void pspp_sheet_view_drag_data_get (GtkWidget *widget,
220 GdkDragContext *context,
221 GtkSelectionData *selection_data,
224 static void pspp_sheet_view_drag_data_delete (GtkWidget *widget,
225 GdkDragContext *context);
227 /* Target side drag signals */
228 static void pspp_sheet_view_drag_leave (GtkWidget *widget,
229 GdkDragContext *context,
231 static gboolean pspp_sheet_view_drag_motion (GtkWidget *widget,
232 GdkDragContext *context,
236 static gboolean pspp_sheet_view_drag_drop (GtkWidget *widget,
237 GdkDragContext *context,
241 static void pspp_sheet_view_drag_data_received (GtkWidget *widget,
242 GdkDragContext *context,
245 GtkSelectionData *selection_data,
249 /* tree_model signals */
250 static void pspp_sheet_view_set_adjustments (PsppSheetView *tree_view,
252 GtkAdjustment *vadj);
253 static gboolean pspp_sheet_view_real_move_cursor (PsppSheetView *tree_view,
254 GtkMovementStep step,
256 static gboolean pspp_sheet_view_real_select_all (PsppSheetView *tree_view);
257 static gboolean pspp_sheet_view_real_unselect_all (PsppSheetView *tree_view);
258 static gboolean pspp_sheet_view_real_select_cursor_row (PsppSheetView *tree_view,
259 gboolean start_editing,
260 PsppSheetSelectMode mode);
261 static gboolean pspp_sheet_view_real_toggle_cursor_row (PsppSheetView *tree_view);
262 static void pspp_sheet_view_row_changed (GtkTreeModel *model,
266 static void pspp_sheet_view_row_inserted (GtkTreeModel *model,
270 static void pspp_sheet_view_row_deleted (GtkTreeModel *model,
273 static void pspp_sheet_view_rows_reordered (GtkTreeModel *model,
279 /* Incremental reflow */
280 static gint validate_row (PsppSheetView *tree_view,
284 static void validate_visible_area (PsppSheetView *tree_view);
285 static gboolean validate_rows_handler (PsppSheetView *tree_view);
286 static gboolean presize_handler_callback (gpointer data);
287 static void install_presize_handler (PsppSheetView *tree_view);
288 static void install_scroll_sync_handler (PsppSheetView *tree_view);
289 static void pspp_sheet_view_set_top_row (PsppSheetView *tree_view,
292 static void pspp_sheet_view_dy_to_top_row (PsppSheetView *tree_view);
293 static void pspp_sheet_view_top_row_to_dy (PsppSheetView *tree_view);
294 static void invalidate_empty_focus (PsppSheetView *tree_view);
296 /* Internal functions */
297 static GtkAdjustment *pspp_sheet_view_do_get_hadjustment (PsppSheetView *);
298 static GtkAdjustment *pspp_sheet_view_do_get_vadjustment (PsppSheetView *);
299 static void pspp_sheet_view_do_set_hadjustment (PsppSheetView *tree_view,
300 GtkAdjustment *adjustment);
301 static void pspp_sheet_view_do_set_vadjustment (PsppSheetView *tree_view,
302 GtkAdjustment *adjustment);
303 static void pspp_sheet_view_add_move_binding (GtkBindingSet *binding_set,
306 gboolean add_shifted_binding,
307 GtkMovementStep step,
309 static void pspp_sheet_view_queue_draw_path (PsppSheetView *tree_view,
311 const GdkRectangle *clip_rect);
312 static gint pspp_sheet_view_new_column_width (PsppSheetView *tree_view,
315 static void pspp_sheet_view_adjustment_changed (GtkAdjustment *adjustment,
316 PsppSheetView *tree_view);
317 static void pspp_sheet_view_clamp_node_visible (PsppSheetView *tree_view,
319 static void pspp_sheet_view_clamp_column_visible (PsppSheetView *tree_view,
320 PsppSheetViewColumn *column,
321 gboolean focus_to_cell);
322 static gboolean pspp_sheet_view_maybe_begin_dragging_row (PsppSheetView *tree_view,
323 GdkEventMotion *event);
324 static void pspp_sheet_view_focus_to_cursor (PsppSheetView *tree_view);
325 static gboolean pspp_sheet_view_move_cursor_up_down (PsppSheetView *tree_view,
327 PsppSheetSelectMode mode);
328 static void pspp_sheet_view_move_cursor_page_up_down (PsppSheetView *tree_view,
330 PsppSheetSelectMode mode);
331 static void pspp_sheet_view_move_cursor_left_right (PsppSheetView *tree_view,
333 PsppSheetSelectMode mode);
334 static void pspp_sheet_view_move_cursor_line_start_end (PsppSheetView *tree_view,
336 PsppSheetSelectMode mode);
337 static void pspp_sheet_view_move_cursor_tab (PsppSheetView *tree_view,
339 static void pspp_sheet_view_move_cursor_start_end (PsppSheetView *tree_view,
341 PsppSheetSelectMode mode);
342 static void pspp_sheet_view_real_set_cursor (PsppSheetView *tree_view,
344 gboolean clear_and_select,
346 PsppSheetSelectMode mode);
347 static gboolean pspp_sheet_view_has_special_cell (PsppSheetView *tree_view);
348 static void pspp_sheet_view_stop_rubber_band (PsppSheetView *tree_view);
349 static void update_prelight (PsppSheetView *tree_view,
352 static void initialize_fixed_height_mode (PsppSheetView *tree_view);
354 /* interactive search */
355 static void pspp_sheet_view_ensure_interactive_directory (PsppSheetView *tree_view);
356 static void pspp_sheet_view_search_dialog_hide (GtkWidget *search_dialog,
357 PsppSheetView *tree_view);
358 static void pspp_sheet_view_search_position_func (PsppSheetView *tree_view,
359 GtkWidget *search_dialog,
361 static void pspp_sheet_view_search_disable_popdown (GtkEntry *entry,
365 static void pspp_sheet_view_search_preedit_changed (GtkIMContext *im_context,
366 PsppSheetView *tree_view);
368 static void pspp_sheet_view_search_activate (GtkEntry *entry,
369 PsppSheetView *tree_view);
370 static gboolean pspp_sheet_view_real_search_enable_popdown(gpointer data);
371 static void pspp_sheet_view_search_enable_popdown (GtkWidget *widget,
373 static gboolean pspp_sheet_view_search_delete_event (GtkWidget *widget,
375 PsppSheetView *tree_view);
376 static gboolean pspp_sheet_view_search_button_press_event (GtkWidget *widget,
377 GdkEventButton *event,
378 PsppSheetView *tree_view);
379 static gboolean pspp_sheet_view_search_scroll_event (GtkWidget *entry,
380 GdkEventScroll *event,
381 PsppSheetView *tree_view);
382 static gboolean pspp_sheet_view_search_key_press_event (GtkWidget *entry,
384 PsppSheetView *tree_view);
385 static gboolean pspp_sheet_view_search_move (GtkWidget *window,
386 PsppSheetView *tree_view,
388 static gboolean pspp_sheet_view_search_equal_func (GtkTreeModel *model,
392 gpointer search_data);
393 static gboolean pspp_sheet_view_search_iter (GtkTreeModel *model,
394 PsppSheetSelection *selection,
399 static void pspp_sheet_view_search_init (GtkWidget *entry,
400 PsppSheetView *tree_view);
401 static void pspp_sheet_view_put (PsppSheetView *tree_view,
402 GtkWidget *child_widget,
404 PsppSheetViewColumn *column);
405 static gboolean pspp_sheet_view_start_editing (PsppSheetView *tree_view,
406 GtkTreePath *cursor_path);
407 static gboolean pspp_sheet_view_editable_button_press_event (GtkWidget *,
410 static void pspp_sheet_view_editable_clicked (GtkButton *, PsppSheetView *);
411 static void pspp_sheet_view_real_start_editing (PsppSheetView *tree_view,
412 PsppSheetViewColumn *column,
414 GtkCellEditable *cell_editable,
415 GdkRectangle *cell_area,
418 static gboolean pspp_sheet_view_real_start_interactive_search (PsppSheetView *tree_view,
419 gboolean keybinding);
420 static gboolean pspp_sheet_view_start_interactive_search (PsppSheetView *tree_view);
421 static PsppSheetViewColumn *pspp_sheet_view_get_drop_column (PsppSheetView *tree_view,
422 PsppSheetViewColumn *column,
425 pspp_sheet_view_adjust_cell_area (PsppSheetView *tree_view,
426 PsppSheetViewColumn *column,
427 const GdkRectangle *background_area,
428 gboolean subtract_focus_rect,
429 GdkRectangle *cell_area);
430 static gint pspp_sheet_view_find_offset (PsppSheetView *tree_view,
435 static void pspp_sheet_view_buildable_add_child (GtkBuildable *tree_view,
439 static void pspp_sheet_view_buildable_init (GtkBuildableIface *iface);
442 static gboolean scroll_row_timeout (gpointer data);
443 static void add_scroll_timeout (PsppSheetView *tree_view);
444 static void remove_scroll_timeout (PsppSheetView *tree_view);
446 static guint tree_view_signals [LAST_SIGNAL] = { 0 };
448 static GtkBindingSet *edit_bindings;
455 G_DEFINE_TYPE_WITH_CODE (PsppSheetView, pspp_sheet_view, GTK_TYPE_CONTAINER,
456 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
457 pspp_sheet_view_buildable_init)
458 G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
461 pspp_sheet_view_get_preferred_width (GtkWidget *widget,
465 GtkRequisition requisition;
467 pspp_sheet_view_size_request (widget, &requisition);
469 *minimal_width = *natural_width = requisition.width;
473 pspp_sheet_view_get_preferred_height (GtkWidget *widget,
474 gint *minimal_height,
475 gint *natural_height)
477 GtkRequisition requisition;
479 pspp_sheet_view_size_request (widget, &requisition);
481 *minimal_height = *natural_height = requisition.height;
485 pspp_sheet_view_class_init (PsppSheetViewClass *class)
487 GObjectClass *o_class;
488 GtkWidgetClass *widget_class;
489 GtkContainerClass *container_class;
490 GtkBindingSet *binding_set[2];
493 binding_set[0] = gtk_binding_set_by_class (class);
495 binding_set[1] = gtk_binding_set_new ("PsppSheetViewEditing");
496 edit_bindings = binding_set[1];
498 o_class = (GObjectClass *) class;
499 widget_class = (GtkWidgetClass *) class;
500 container_class = (GtkContainerClass *) class;
502 /* GObject signals */
503 o_class->set_property = pspp_sheet_view_set_property;
504 o_class->get_property = pspp_sheet_view_get_property;
505 o_class->finalize = pspp_sheet_view_finalize;
506 o_class->dispose = pspp_sheet_view_dispose;
508 /* GtkWidget signals */
509 widget_class->map = pspp_sheet_view_map;
510 widget_class->realize = pspp_sheet_view_realize;
511 widget_class->unrealize = pspp_sheet_view_unrealize;
512 widget_class->get_preferred_width = pspp_sheet_view_get_preferred_width;
513 widget_class->get_preferred_height = pspp_sheet_view_get_preferred_height;
514 widget_class->size_allocate = pspp_sheet_view_size_allocate;
515 widget_class->button_press_event = pspp_sheet_view_button_press;
516 widget_class->button_release_event = pspp_sheet_view_button_release;
517 widget_class->grab_broken_event = pspp_sheet_view_grab_broken;
518 /*widget_class->configure_event = pspp_sheet_view_configure;*/
519 widget_class->motion_notify_event = pspp_sheet_view_motion;
520 widget_class->draw = pspp_sheet_view_draw;
521 widget_class->key_press_event = pspp_sheet_view_key_press;
522 widget_class->key_release_event = pspp_sheet_view_key_release;
523 widget_class->enter_notify_event = pspp_sheet_view_enter_notify;
524 widget_class->leave_notify_event = pspp_sheet_view_leave_notify;
525 widget_class->focus_out_event = pspp_sheet_view_focus_out;
526 widget_class->drag_begin = pspp_sheet_view_drag_begin;
527 widget_class->drag_end = pspp_sheet_view_drag_end;
528 widget_class->drag_data_get = pspp_sheet_view_drag_data_get;
529 widget_class->drag_data_delete = pspp_sheet_view_drag_data_delete;
530 widget_class->drag_leave = pspp_sheet_view_drag_leave;
531 widget_class->drag_motion = pspp_sheet_view_drag_motion;
532 widget_class->drag_drop = pspp_sheet_view_drag_drop;
533 widget_class->drag_data_received = pspp_sheet_view_drag_data_received;
534 widget_class->focus = pspp_sheet_view_focus;
535 widget_class->grab_focus = pspp_sheet_view_grab_focus;
536 widget_class->style_updated = pspp_sheet_view_style_updated;
537 widget_class->grab_notify = pspp_sheet_view_grab_notify;
538 widget_class->state_changed = pspp_sheet_view_state_changed;
540 /* GtkContainer signals */
541 container_class->remove = pspp_sheet_view_remove;
542 container_class->forall = pspp_sheet_view_forall;
543 container_class->set_focus_child = pspp_sheet_view_set_focus_child;
545 class->set_scroll_adjustments = pspp_sheet_view_set_adjustments;
546 class->move_cursor = pspp_sheet_view_real_move_cursor;
547 class->select_all = pspp_sheet_view_real_select_all;
548 class->unselect_all = pspp_sheet_view_real_unselect_all;
549 class->select_cursor_row = pspp_sheet_view_real_select_cursor_row;
550 class->toggle_cursor_row = pspp_sheet_view_real_toggle_cursor_row;
551 class->start_interactive_search = pspp_sheet_view_start_interactive_search;
555 g_object_class_install_property (o_class,
557 g_param_spec_object ("model",
558 P_("TreeView Model"),
559 P_("The model for the tree view"),
561 GTK_PARAM_READWRITE));
563 g_object_class_override_property (o_class, PROP_HADJUSTMENT, "hadjustment");
564 g_object_class_override_property (o_class, PROP_VADJUSTMENT, "vadjustment");
565 g_object_class_override_property (o_class, PROP_HSCROLL_POLICY, "hscroll-policy");
566 g_object_class_override_property (o_class, PROP_VSCROLL_POLICY, "vscroll-policy");
568 g_object_class_install_property (o_class,
569 PROP_HEADERS_VISIBLE,
570 g_param_spec_boolean ("headers-visible",
571 P_("Headers Visible"),
572 P_("Show the column header buttons"),
574 GTK_PARAM_READWRITE));
576 g_object_class_install_property (o_class,
577 PROP_HEADERS_CLICKABLE,
578 g_param_spec_boolean ("headers-clickable",
579 P_("Headers Clickable"),
580 P_("Column headers respond to click events"),
582 GTK_PARAM_READWRITE));
584 g_object_class_install_property (o_class,
586 g_param_spec_boolean ("reorderable",
588 P_("View is reorderable"),
590 GTK_PARAM_READWRITE));
592 g_object_class_install_property (o_class,
594 g_param_spec_boolean ("rules-hint",
596 P_("Set a hint to the theme engine to draw rows in alternating colors"),
598 GTK_PARAM_READWRITE));
600 g_object_class_install_property (o_class,
602 g_param_spec_boolean ("enable-search",
604 P_("View allows user to search through columns interactively"),
606 GTK_PARAM_READWRITE));
608 g_object_class_install_property (o_class,
610 g_param_spec_int ("search-column",
612 P_("Model column to search through during interactive search"),
616 GTK_PARAM_READWRITE));
619 * PsppSheetView:hover-selection:
621 * Enables of disables the hover selection mode of @tree_view.
622 * Hover selection makes the selected row follow the pointer.
623 * Currently, this works only for the selection modes
624 * %PSPP_SHEET_SELECTION_SINGLE and %PSPP_SHEET_SELECTION_BROWSE.
626 * This mode is primarily intended for treeviews in popups, e.g.
627 * in #GtkComboBox or #GtkEntryCompletion.
631 g_object_class_install_property (o_class,
632 PROP_HOVER_SELECTION,
633 g_param_spec_boolean ("hover-selection",
634 P_("Hover Selection"),
635 P_("Whether the selection should follow the pointer"),
637 GTK_PARAM_READWRITE));
639 g_object_class_install_property (o_class,
641 g_param_spec_boolean ("rubber-banding",
642 P_("Rubber Banding"),
643 P_("Whether to enable selection of multiple items by dragging the mouse pointer"),
645 GTK_PARAM_READWRITE));
647 g_object_class_install_property (o_class,
648 PROP_ENABLE_GRID_LINES,
649 g_param_spec_enum ("enable-grid-lines",
650 P_("Enable Grid Lines"),
651 P_("Whether grid lines should be drawn in the tree view"),
652 PSPP_TYPE_SHEET_VIEW_GRID_LINES,
653 PSPP_SHEET_VIEW_GRID_LINES_NONE,
654 GTK_PARAM_READWRITE));
656 g_object_class_install_property (o_class,
658 g_param_spec_int ("tooltip-column",
659 P_("Tooltip Column"),
660 P_("The column in the model containing the tooltip texts for the rows"),
664 GTK_PARAM_READWRITE));
666 g_object_class_install_property (o_class,
668 g_param_spec_enum ("special-cells",
670 P_("Whether rows have special cells."),
671 PSPP_TYPE_SHEET_VIEW_SPECIAL_CELLS,
672 PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT,
673 GTK_PARAM_READWRITE));
675 g_object_class_install_property (o_class,
677 g_param_spec_int ("fixed-height",
679 P_("Height of a single row. Normally the height of a row is determined automatically. Writing this property sets fixed-height-set to true, preventing this property's value from changing."),
683 GTK_PARAM_READWRITE));
685 g_object_class_install_property (o_class,
686 PROP_FIXED_HEIGHT_SET,
687 g_param_spec_boolean ("fixed-height-set",
688 P_("Fixed Height Set"),
689 P_("Whether fixed-height was set externally."),
691 GTK_PARAM_READWRITE));
693 /* Style properties */
694 #define _TREE_VIEW_EXPANDER_SIZE 12
695 #define _TREE_VIEW_VERTICAL_SEPARATOR 2
696 #define _TREE_VIEW_HORIZONTAL_SEPARATOR 2
698 gtk_widget_class_install_style_property (widget_class,
699 g_param_spec_int ("expander-size",
701 P_("Size of the expander arrow"),
704 _TREE_VIEW_EXPANDER_SIZE,
705 GTK_PARAM_READABLE));
707 gtk_widget_class_install_style_property (widget_class,
708 g_param_spec_int ("vertical-separator",
709 P_("Vertical Separator Width"),
710 P_("Vertical space between cells. Must be an even number"),
713 _TREE_VIEW_VERTICAL_SEPARATOR,
714 GTK_PARAM_READABLE));
716 gtk_widget_class_install_style_property (widget_class,
717 g_param_spec_int ("horizontal-separator",
718 P_("Horizontal Separator Width"),
719 P_("Horizontal space between cells. Must be an even number"),
722 _TREE_VIEW_HORIZONTAL_SEPARATOR,
723 GTK_PARAM_READABLE));
725 gtk_widget_class_install_style_property (widget_class,
726 g_param_spec_boolean ("allow-rules",
728 P_("Allow drawing of alternating color rows"),
730 GTK_PARAM_READABLE));
732 gtk_widget_class_install_style_property (widget_class,
733 g_param_spec_boxed ("even-row-color",
734 P_("Even Row Color"),
735 P_("Color to use for even rows"),
737 GTK_PARAM_READABLE));
739 gtk_widget_class_install_style_property (widget_class,
740 g_param_spec_boxed ("odd-row-color",
742 P_("Color to use for odd rows"),
744 GTK_PARAM_READABLE));
746 gtk_widget_class_install_style_property (widget_class,
747 g_param_spec_boolean ("row-ending-details",
748 P_("Row Ending details"),
749 P_("Enable extended row background theming"),
751 GTK_PARAM_READABLE));
753 gtk_widget_class_install_style_property (widget_class,
754 g_param_spec_int ("grid-line-width",
755 P_("Grid line width"),
756 P_("Width, in pixels, of the tree view grid lines"),
758 GTK_PARAM_READABLE));
760 gtk_widget_class_install_style_property (widget_class,
761 g_param_spec_int ("tree-line-width",
762 P_("Tree line width"),
763 P_("Width, in pixels, of the tree view lines"),
765 GTK_PARAM_READABLE));
767 gtk_widget_class_install_style_property (widget_class,
768 g_param_spec_string ("tree-line-pattern",
769 P_("Tree line pattern"),
770 P_("Dash pattern used to draw the tree view lines"),
772 GTK_PARAM_READABLE));
777 * PsppSheetView::set-scroll-adjustments
778 * @horizontal: the horizontal #GtkAdjustment
779 * @vertical: the vertical #GtkAdjustment
781 * Set the scroll adjustments for the tree view. Usually scrolled containers
782 * like #GtkScrolledWindow will emit this signal to connect two instances
783 * of #GtkScrollbar to the scroll directions of the #PsppSheetView.
785 widget_class->set_scroll_adjustments_signal =
786 g_signal_new ("set-scroll-adjustments",
787 G_TYPE_FROM_CLASS (o_class),
788 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
789 G_STRUCT_OFFSET (PsppSheetViewClass, set_scroll_adjustments),
791 psppire_marshal_VOID__OBJECT_OBJECT,
794 GTK_TYPE_ADJUSTMENT);
798 * PsppSheetView::row-activated:
799 * @tree_view: the object on which the signal is emitted
800 * @path: the #GtkTreePath for the activated row
801 * @column: the #PsppSheetViewColumn in which the activation occurred
803 * The "row-activated" signal is emitted when the method
804 * pspp_sheet_view_row_activated() is called or the user double clicks
805 * a treeview row. It is also emitted when a non-editable row is
806 * selected and one of the keys: Space, Shift+Space, Return or
809 * For selection handling refer to the <link linkend="TreeWidget">tree
810 * widget conceptual overview</link> as well as #PsppSheetSelection.
812 tree_view_signals[ROW_ACTIVATED] =
813 g_signal_new ("row-activated",
814 G_TYPE_FROM_CLASS (o_class),
815 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
816 G_STRUCT_OFFSET (PsppSheetViewClass, row_activated),
818 psppire_marshal_VOID__BOXED_OBJECT,
821 PSPP_TYPE_SHEET_VIEW_COLUMN);
824 * PsppSheetView::columns-changed:
825 * @tree_view: the object on which the signal is emitted
827 * The number of columns of the treeview has changed.
829 tree_view_signals[COLUMNS_CHANGED] =
830 g_signal_new ("columns-changed",
831 G_TYPE_FROM_CLASS (o_class),
833 G_STRUCT_OFFSET (PsppSheetViewClass, columns_changed),
835 g_cclosure_marshal_VOID__VOID,
839 * PsppSheetView::cursor-changed:
840 * @tree_view: the object on which the signal is emitted
842 * The position of the cursor (focused cell) has changed.
844 tree_view_signals[CURSOR_CHANGED] =
845 g_signal_new ("cursor-changed",
846 G_TYPE_FROM_CLASS (o_class),
848 G_STRUCT_OFFSET (PsppSheetViewClass, cursor_changed),
850 g_cclosure_marshal_VOID__VOID,
853 tree_view_signals[MOVE_CURSOR] =
854 g_signal_new ("move-cursor",
855 G_TYPE_FROM_CLASS (o_class),
856 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
857 G_STRUCT_OFFSET (PsppSheetViewClass, move_cursor),
859 psppire_marshal_BOOLEAN__ENUM_INT,
861 GTK_TYPE_MOVEMENT_STEP,
864 tree_view_signals[SELECT_ALL] =
865 g_signal_new ("select-all",
866 G_TYPE_FROM_CLASS (o_class),
867 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
868 G_STRUCT_OFFSET (PsppSheetViewClass, select_all),
870 psppire_marshal_BOOLEAN__VOID,
873 tree_view_signals[UNSELECT_ALL] =
874 g_signal_new ("unselect-all",
875 G_TYPE_FROM_CLASS (o_class),
876 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
877 G_STRUCT_OFFSET (PsppSheetViewClass, unselect_all),
879 psppire_marshal_BOOLEAN__VOID,
882 tree_view_signals[SELECT_CURSOR_ROW] =
883 g_signal_new ("select-cursor-row",
884 G_TYPE_FROM_CLASS (o_class),
885 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
886 G_STRUCT_OFFSET (PsppSheetViewClass, select_cursor_row),
888 psppire_marshal_BOOLEAN__BOOLEAN,
890 G_TYPE_BOOLEAN, G_TYPE_INT);
892 tree_view_signals[TOGGLE_CURSOR_ROW] =
893 g_signal_new ("toggle-cursor-row",
894 G_TYPE_FROM_CLASS (o_class),
895 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
896 G_STRUCT_OFFSET (PsppSheetViewClass, toggle_cursor_row),
898 psppire_marshal_BOOLEAN__VOID,
901 tree_view_signals[START_INTERACTIVE_SEARCH] =
902 g_signal_new ("start-interactive-search",
903 G_TYPE_FROM_CLASS (o_class),
904 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
905 G_STRUCT_OFFSET (PsppSheetViewClass, start_interactive_search),
907 psppire_marshal_BOOLEAN__VOID,
911 for (i = 0; i < 2; i++)
913 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Up, 0, TRUE,
914 GTK_MOVEMENT_DISPLAY_LINES, -1);
915 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Up, 0, TRUE,
916 GTK_MOVEMENT_DISPLAY_LINES, -1);
918 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Down, 0, TRUE,
919 GTK_MOVEMENT_DISPLAY_LINES, 1);
920 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Down, 0, TRUE,
921 GTK_MOVEMENT_DISPLAY_LINES, 1);
923 pspp_sheet_view_add_move_binding (binding_set[i], GDK_p, GDK_CONTROL_MASK, FALSE,
924 GTK_MOVEMENT_DISPLAY_LINES, -1);
926 pspp_sheet_view_add_move_binding (binding_set[i], GDK_n, GDK_CONTROL_MASK, FALSE,
927 GTK_MOVEMENT_DISPLAY_LINES, 1);
929 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Home, 0, TRUE,
930 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
931 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Home, 0, TRUE,
932 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
934 pspp_sheet_view_add_move_binding (binding_set[i], GDK_End, 0, TRUE,
935 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
936 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_End, 0, TRUE,
937 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
939 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Page_Up, 0, TRUE,
940 GTK_MOVEMENT_PAGES, -1);
941 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Page_Up, 0, TRUE,
942 GTK_MOVEMENT_PAGES, -1);
944 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Page_Down, 0, TRUE,
945 GTK_MOVEMENT_PAGES, 1);
946 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Page_Down, 0, TRUE,
947 GTK_MOVEMENT_PAGES, 1);
950 gtk_binding_entry_add_signal (binding_set[i], GDK_Up, GDK_CONTROL_MASK, "move-cursor", 2,
951 G_TYPE_ENUM, GTK_MOVEMENT_BUFFER_ENDS,
954 gtk_binding_entry_add_signal (binding_set[i], GDK_Down, GDK_CONTROL_MASK, "move-cursor", 2,
955 G_TYPE_ENUM, GTK_MOVEMENT_BUFFER_ENDS,
958 gtk_binding_entry_add_signal (binding_set[i], GDK_Right, 0, "move-cursor", 2,
959 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
962 gtk_binding_entry_add_signal (binding_set[i], GDK_Left, 0, "move-cursor", 2,
963 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
966 gtk_binding_entry_add_signal (binding_set[i], GDK_Tab, 0, "move-cursor", 2,
967 G_TYPE_ENUM, GTK_MOVEMENT_LOGICAL_POSITIONS,
970 gtk_binding_entry_add_signal (binding_set[i], GDK_Tab, GDK_SHIFT_MASK, "move-cursor", 2,
971 G_TYPE_ENUM, GTK_MOVEMENT_LOGICAL_POSITIONS,
974 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Right, 0, "move-cursor", 2,
975 G_TYPE_ENUM, GTK_MOVEMENT_DISPLAY_LINE_ENDS,
978 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Left, 0, "move-cursor", 2,
979 G_TYPE_ENUM, GTK_MOVEMENT_DISPLAY_LINE_ENDS,
982 gtk_binding_entry_add_signal (binding_set[i], GDK_Right, GDK_CONTROL_MASK,
984 G_TYPE_ENUM, GTK_MOVEMENT_DISPLAY_LINE_ENDS,
987 gtk_binding_entry_add_signal (binding_set[i], GDK_Left, GDK_CONTROL_MASK,
989 G_TYPE_ENUM, GTK_MOVEMENT_DISPLAY_LINE_ENDS,
992 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Right, GDK_CONTROL_MASK,
994 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
997 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Left, GDK_CONTROL_MASK,
999 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
1002 gtk_binding_entry_add_signal (binding_set[i], GDK_f, GDK_CONTROL_MASK, "start-interactive-search", 0);
1004 gtk_binding_entry_add_signal (binding_set[i], GDK_F, GDK_CONTROL_MASK, "start-interactive-search", 0);
1007 gtk_binding_entry_add_signal (binding_set[0], GDK_space, GDK_CONTROL_MASK, "toggle-cursor-row", 0);
1008 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Space, GDK_CONTROL_MASK, "toggle-cursor-row", 0);
1010 gtk_binding_entry_add_signal (binding_set[0], GDK_a, GDK_CONTROL_MASK, "select-all", 0);
1011 gtk_binding_entry_add_signal (binding_set[0], GDK_slash, GDK_CONTROL_MASK, "select-all", 0);
1013 gtk_binding_entry_add_signal (binding_set[0], GDK_A, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "unselect-all", 0);
1014 gtk_binding_entry_add_signal (binding_set[0], GDK_backslash, GDK_CONTROL_MASK, "unselect-all", 0);
1016 gtk_binding_entry_add_signal (binding_set[0], GDK_space, GDK_SHIFT_MASK, "select-cursor-row", 1,
1017 G_TYPE_BOOLEAN, TRUE,
1018 G_TYPE_INT, PSPP_SHEET_SELECT_MODE_EXTEND);
1019 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Space, GDK_SHIFT_MASK, "select-cursor-row", 1,
1020 G_TYPE_BOOLEAN, TRUE,
1021 G_TYPE_INT, PSPP_SHEET_SELECT_MODE_EXTEND);
1023 gtk_binding_entry_add_signal (binding_set[0], GDK_space, 0, "select-cursor-row", 1,
1024 G_TYPE_BOOLEAN, TRUE,
1026 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Space, 0, "select-cursor-row", 1,
1027 G_TYPE_BOOLEAN, TRUE,
1029 gtk_binding_entry_add_signal (binding_set[0], GDK_Return, 0, "select-cursor-row", 1,
1030 G_TYPE_BOOLEAN, TRUE,
1032 gtk_binding_entry_add_signal (binding_set[0], GDK_ISO_Enter, 0, "select-cursor-row", 1,
1033 G_TYPE_BOOLEAN, TRUE,
1035 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Enter, 0, "select-cursor-row", 1,
1036 G_TYPE_BOOLEAN, TRUE,
1039 gtk_binding_entry_add_signal (binding_set[0], GDK_BackSpace, 0, "select-cursor-parent", 0);
1040 gtk_binding_entry_add_signal (binding_set[0], GDK_BackSpace, GDK_CONTROL_MASK, "select-cursor-parent", 0);
1042 g_type_class_add_private (o_class, sizeof (PsppSheetViewPrivate));
1046 pspp_sheet_view_buildable_init (GtkBuildableIface *iface)
1048 iface->add_child = pspp_sheet_view_buildable_add_child;
1052 pspp_sheet_view_init (PsppSheetView *tree_view)
1054 tree_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (tree_view, PSPP_TYPE_SHEET_VIEW, PsppSheetViewPrivate);
1056 gtk_widget_set_can_focus (GTK_WIDGET (tree_view), TRUE);
1057 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (tree_view), FALSE);
1059 tree_view->priv->flags = PSPP_SHEET_VIEW_DRAW_KEYFOCUS
1060 | PSPP_SHEET_VIEW_HEADERS_VISIBLE;
1062 /* We need some padding */
1063 tree_view->priv->selected = range_tower_create ();
1064 tree_view->priv->dy = 0;
1065 tree_view->priv->cursor_offset = 0;
1066 tree_view->priv->n_columns = 0;
1067 tree_view->priv->header_height = 1;
1068 tree_view->priv->x_drag = 0;
1069 tree_view->priv->drag_pos = -1;
1070 tree_view->priv->header_has_focus = FALSE;
1071 tree_view->priv->pressed_button = -1;
1072 tree_view->priv->press_start_x = -1;
1073 tree_view->priv->press_start_y = -1;
1074 tree_view->priv->reorderable = FALSE;
1075 tree_view->priv->presize_handler_timer = 0;
1076 tree_view->priv->scroll_sync_timer = 0;
1077 tree_view->priv->fixed_height = -1;
1078 tree_view->priv->fixed_height_set = FALSE;
1079 pspp_sheet_view_set_adjustments (tree_view, NULL, NULL);
1080 tree_view->priv->selection = _pspp_sheet_selection_new_with_tree_view (tree_view);
1081 tree_view->priv->enable_search = TRUE;
1082 tree_view->priv->search_column = -1;
1083 tree_view->priv->search_position_func = pspp_sheet_view_search_position_func;
1084 tree_view->priv->search_equal_func = pspp_sheet_view_search_equal_func;
1085 tree_view->priv->search_custom_entry_set = FALSE;
1086 tree_view->priv->typeselect_flush_timeout = 0;
1087 tree_view->priv->init_hadjust_value = TRUE;
1088 tree_view->priv->width = 0;
1090 tree_view->priv->hover_selection = FALSE;
1092 tree_view->priv->rubber_banding_enable = FALSE;
1094 tree_view->priv->grid_lines = PSPP_SHEET_VIEW_GRID_LINES_NONE;
1096 tree_view->priv->tooltip_column = -1;
1098 tree_view->priv->special_cells = PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT;
1100 tree_view->priv->post_validation_flag = FALSE;
1102 tree_view->priv->last_button_x = -1;
1103 tree_view->priv->last_button_y = -1;
1105 tree_view->priv->event_last_x = -10000;
1106 tree_view->priv->event_last_y = -10000;
1108 tree_view->priv->prelight_node = -1;
1109 tree_view->priv->rubber_band_start_node = -1;
1110 tree_view->priv->rubber_band_end_node = -1;
1112 tree_view->priv->anchor_column = NULL;
1114 tree_view->priv->button_style = NULL;
1116 tree_view->dispose_has_run = FALSE;
1118 pspp_sheet_view_do_set_vadjustment (tree_view, NULL);
1119 pspp_sheet_view_do_set_hadjustment (tree_view, NULL);
1120 gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (tree_view)),
1121 GTK_STYLE_CLASS_VIEW);
1130 pspp_sheet_view_set_property (GObject *object,
1132 const GValue *value,
1135 PsppSheetView *tree_view;
1137 tree_view = PSPP_SHEET_VIEW (object);
1142 pspp_sheet_view_set_model (tree_view, g_value_get_object (value));
1144 case PROP_HADJUSTMENT:
1145 pspp_sheet_view_do_set_hadjustment (tree_view, g_value_get_object (value));
1147 case PROP_VADJUSTMENT:
1148 pspp_sheet_view_do_set_vadjustment (tree_view, g_value_get_object (value));
1150 case PROP_HSCROLL_POLICY:
1151 tree_view->priv->hscroll_policy = g_value_get_enum (value);
1152 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
1154 case PROP_VSCROLL_POLICY:
1155 tree_view->priv->vscroll_policy = g_value_get_enum (value);
1156 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
1158 case PROP_HEADERS_VISIBLE:
1159 pspp_sheet_view_set_headers_visible (tree_view, g_value_get_boolean (value));
1161 case PROP_HEADERS_CLICKABLE:
1162 pspp_sheet_view_set_headers_clickable (tree_view, g_value_get_boolean (value));
1164 case PROP_REORDERABLE:
1165 pspp_sheet_view_set_reorderable (tree_view, g_value_get_boolean (value));
1167 case PROP_RULES_HINT:
1168 pspp_sheet_view_set_rules_hint (tree_view, g_value_get_boolean (value));
1170 case PROP_ENABLE_SEARCH:
1171 pspp_sheet_view_set_enable_search (tree_view, g_value_get_boolean (value));
1173 case PROP_SEARCH_COLUMN:
1174 pspp_sheet_view_set_search_column (tree_view, g_value_get_int (value));
1176 case PROP_HOVER_SELECTION:
1177 tree_view->priv->hover_selection = g_value_get_boolean (value);
1179 case PROP_RUBBER_BANDING:
1180 tree_view->priv->rubber_banding_enable = g_value_get_boolean (value);
1182 case PROP_ENABLE_GRID_LINES:
1183 pspp_sheet_view_set_grid_lines (tree_view, g_value_get_enum (value));
1185 case PROP_TOOLTIP_COLUMN:
1186 pspp_sheet_view_set_tooltip_column (tree_view, g_value_get_int (value));
1188 case PROP_SPECIAL_CELLS:
1189 pspp_sheet_view_set_special_cells (tree_view, g_value_get_enum (value));
1191 case PROP_FIXED_HEIGHT:
1192 pspp_sheet_view_set_fixed_height (tree_view, g_value_get_int (value));
1194 case PROP_FIXED_HEIGHT_SET:
1195 if (g_value_get_boolean (value))
1197 if (!tree_view->priv->fixed_height_set
1198 && tree_view->priv->fixed_height >= 0)
1200 tree_view->priv->fixed_height_set = true;
1201 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
1206 if (tree_view->priv->fixed_height_set)
1208 tree_view->priv->fixed_height_set = false;
1209 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
1210 install_presize_handler (tree_view);
1215 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1221 pspp_sheet_view_get_property (GObject *object,
1226 PsppSheetView *tree_view;
1228 tree_view = PSPP_SHEET_VIEW (object);
1233 g_value_set_object (value, tree_view->priv->model);
1235 case PROP_HADJUSTMENT:
1236 g_value_set_object (value, tree_view->priv->hadjustment);
1238 case PROP_VADJUSTMENT:
1239 g_value_set_object (value, tree_view->priv->vadjustment);
1241 case PROP_HSCROLL_POLICY:
1242 g_value_set_enum (value, tree_view->priv->hscroll_policy);
1244 case PROP_VSCROLL_POLICY:
1245 g_value_set_enum (value, tree_view->priv->vscroll_policy);
1247 case PROP_HEADERS_VISIBLE:
1248 g_value_set_boolean (value, pspp_sheet_view_get_headers_visible (tree_view));
1250 case PROP_HEADERS_CLICKABLE:
1251 g_value_set_boolean (value, pspp_sheet_view_get_headers_clickable (tree_view));
1253 case PROP_REORDERABLE:
1254 g_value_set_boolean (value, tree_view->priv->reorderable);
1256 case PROP_RULES_HINT:
1257 g_value_set_boolean (value, tree_view->priv->has_rules);
1259 case PROP_ENABLE_SEARCH:
1260 g_value_set_boolean (value, tree_view->priv->enable_search);
1262 case PROP_SEARCH_COLUMN:
1263 g_value_set_int (value, tree_view->priv->search_column);
1265 case PROP_HOVER_SELECTION:
1266 g_value_set_boolean (value, tree_view->priv->hover_selection);
1268 case PROP_RUBBER_BANDING:
1269 g_value_set_boolean (value, tree_view->priv->rubber_banding_enable);
1271 case PROP_ENABLE_GRID_LINES:
1272 g_value_set_enum (value, tree_view->priv->grid_lines);
1274 case PROP_TOOLTIP_COLUMN:
1275 g_value_set_int (value, tree_view->priv->tooltip_column);
1277 case PROP_SPECIAL_CELLS:
1278 g_value_set_enum (value, tree_view->priv->special_cells);
1280 case PROP_FIXED_HEIGHT:
1281 g_value_set_int (value, pspp_sheet_view_get_fixed_height (tree_view));
1283 case PROP_FIXED_HEIGHT_SET:
1284 g_value_set_boolean (value, tree_view->priv->fixed_height_set);
1287 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1293 pspp_sheet_view_dispose (GObject *object)
1295 PsppSheetView *tree_view = PSPP_SHEET_VIEW (object);
1297 if (tree_view->dispose_has_run)
1300 tree_view->dispose_has_run = TRUE;
1302 if (tree_view->priv->selection != NULL)
1304 _pspp_sheet_selection_set_tree_view (tree_view->priv->selection, NULL);
1305 g_object_unref (tree_view->priv->selection);
1306 tree_view->priv->selection = NULL;
1309 if (tree_view->priv->hadjustment)
1311 g_object_unref (tree_view->priv->hadjustment);
1312 tree_view->priv->hadjustment = NULL;
1314 if (tree_view->priv->vadjustment)
1316 g_object_unref (tree_view->priv->vadjustment);
1317 tree_view->priv->vadjustment = NULL;
1320 if (tree_view->priv->button_style)
1322 g_object_unref (tree_view->priv->button_style);
1323 tree_view->priv->button_style = NULL;
1327 G_OBJECT_CLASS (pspp_sheet_view_parent_class)->dispose (object);
1333 pspp_sheet_view_buildable_add_child (GtkBuildable *tree_view,
1334 GtkBuilder *builder,
1338 pspp_sheet_view_append_column (PSPP_SHEET_VIEW (tree_view), PSPP_SHEET_VIEW_COLUMN (child));
1342 pspp_sheet_view_finalize (GObject *object)
1344 PsppSheetView *tree_view = PSPP_SHEET_VIEW (object);
1346 pspp_sheet_view_stop_editing (tree_view, TRUE);
1348 if (tree_view->priv->selected != NULL)
1350 range_tower_destroy (tree_view->priv->selected);
1351 tree_view->priv->selected = NULL;
1355 tree_view->priv->prelight_node = -1;
1358 if (tree_view->priv->scroll_to_path != NULL)
1360 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
1361 tree_view->priv->scroll_to_path = NULL;
1364 if (tree_view->priv->drag_dest_row != NULL)
1366 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
1367 tree_view->priv->drag_dest_row = NULL;
1370 if (tree_view->priv->top_row != NULL)
1372 gtk_tree_row_reference_free (tree_view->priv->top_row);
1373 tree_view->priv->top_row = NULL;
1376 if (tree_view->priv->column_drop_func_data &&
1377 tree_view->priv->column_drop_func_data_destroy)
1379 tree_view->priv->column_drop_func_data_destroy (tree_view->priv->column_drop_func_data);
1380 tree_view->priv->column_drop_func_data = NULL;
1383 if (tree_view->priv->destroy_count_destroy &&
1384 tree_view->priv->destroy_count_data)
1386 tree_view->priv->destroy_count_destroy (tree_view->priv->destroy_count_data);
1387 tree_view->priv->destroy_count_data = NULL;
1390 gtk_tree_row_reference_free (tree_view->priv->cursor);
1391 tree_view->priv->cursor = NULL;
1393 gtk_tree_row_reference_free (tree_view->priv->anchor);
1394 tree_view->priv->anchor = NULL;
1396 /* destroy interactive search dialog */
1397 if (tree_view->priv->search_window)
1399 gtk_widget_destroy (tree_view->priv->search_window);
1400 tree_view->priv->search_window = NULL;
1401 tree_view->priv->search_entry = NULL;
1402 if (tree_view->priv->typeselect_flush_timeout)
1404 g_source_remove (tree_view->priv->typeselect_flush_timeout);
1405 tree_view->priv->typeselect_flush_timeout = 0;
1409 if (tree_view->priv->search_destroy && tree_view->priv->search_user_data)
1411 tree_view->priv->search_destroy (tree_view->priv->search_user_data);
1412 tree_view->priv->search_user_data = NULL;
1415 if (tree_view->priv->search_position_destroy && tree_view->priv->search_position_user_data)
1417 tree_view->priv->search_position_destroy (tree_view->priv->search_position_user_data);
1418 tree_view->priv->search_position_user_data = NULL;
1421 pspp_sheet_view_set_model (tree_view, NULL);
1424 G_OBJECT_CLASS (pspp_sheet_view_parent_class)->finalize (object);
1429 /* GtkWidget Methods
1432 /* GtkWidget::map helper */
1434 pspp_sheet_view_map_buttons (PsppSheetView *tree_view)
1438 g_return_if_fail (gtk_widget_get_mapped (GTK_WIDGET (tree_view)));
1440 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
1442 PsppSheetViewColumn *column;
1444 for (list = tree_view->priv->columns; list; list = list->next)
1446 column = list->data;
1447 if (column->button != NULL &&
1448 gtk_widget_get_visible (column->button) &&
1449 !gtk_widget_get_mapped (column->button))
1450 gtk_widget_map (column->button);
1452 for (list = tree_view->priv->columns; list; list = list->next)
1454 column = list->data;
1455 if (column->visible == FALSE || column->window == NULL)
1457 if (column->resizable)
1459 gdk_window_raise (column->window);
1460 gdk_window_show (column->window);
1463 gdk_window_hide (column->window);
1465 gdk_window_show (tree_view->priv->header_window);
1470 pspp_sheet_view_map (GtkWidget *widget)
1472 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1475 gtk_widget_set_mapped (widget, TRUE);
1477 tmp_list = tree_view->priv->children;
1480 PsppSheetViewChild *child = tmp_list->data;
1481 tmp_list = tmp_list->next;
1483 if (gtk_widget_get_visible (child->widget))
1485 if (!gtk_widget_get_mapped (child->widget))
1486 gtk_widget_map (child->widget);
1489 gdk_window_show (tree_view->priv->bin_window);
1491 pspp_sheet_view_map_buttons (tree_view);
1493 gdk_window_show (gtk_widget_get_window (widget));
1497 pspp_sheet_view_realize (GtkWidget *widget)
1499 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1502 GdkWindowAttr attributes;
1503 gint attributes_mask;
1504 GtkAllocation allocation;
1506 gtk_widget_set_realized (widget, TRUE);
1508 gtk_widget_get_allocation (widget, &allocation);
1510 /* Make the main, clipping window */
1511 attributes.window_type = GDK_WINDOW_CHILD;
1512 attributes.x = allocation.x;
1513 attributes.y = allocation.y;
1514 attributes.width = allocation.width;
1515 attributes.height = allocation.height;
1516 attributes.wclass = GDK_INPUT_OUTPUT;
1517 attributes.visual = gtk_widget_get_visual (widget);
1518 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1520 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
1522 window = gdk_window_new (gtk_widget_get_parent_window (widget),
1523 &attributes, attributes_mask);
1524 gtk_widget_set_window (widget, window);
1526 gtk_widget_register_window (widget, window);
1527 gtk_widget_get_allocation (widget, &allocation);
1529 /* Make the window for the tree */
1531 attributes.y = TREE_VIEW_HEADER_HEIGHT (tree_view);
1532 attributes.width = MAX (tree_view->priv->width, allocation.width);
1533 attributes.height = allocation.height;
1534 attributes.event_mask = (GDK_EXPOSURE_MASK |
1536 GDK_POINTER_MOTION_MASK |
1537 GDK_ENTER_NOTIFY_MASK |
1538 GDK_LEAVE_NOTIFY_MASK |
1539 GDK_BUTTON_PRESS_MASK |
1540 GDK_BUTTON_RELEASE_MASK |
1541 gtk_widget_get_events (widget));
1543 tree_view->priv->bin_window = gdk_window_new (window,
1544 &attributes, attributes_mask);
1545 gtk_widget_register_window (widget, tree_view->priv->bin_window);
1546 gtk_widget_get_allocation (widget, &allocation);
1548 /* Make the column header window */
1551 attributes.width = MAX (tree_view->priv->width, allocation.width);
1552 attributes.height = tree_view->priv->header_height;
1553 attributes.event_mask = (GDK_EXPOSURE_MASK |
1555 GDK_BUTTON_PRESS_MASK |
1556 GDK_BUTTON_RELEASE_MASK |
1557 GDK_KEY_PRESS_MASK |
1558 GDK_KEY_RELEASE_MASK |
1559 gtk_widget_get_events (widget));
1561 tree_view->priv->header_window = gdk_window_new (window,
1562 &attributes, attributes_mask);
1563 gtk_widget_register_window (widget, tree_view->priv->header_window);
1565 { /* Ensure Background */
1566 GtkStyleContext *context;
1568 context = gtk_widget_get_style_context (GTK_WIDGET (tree_view));
1570 gtk_style_context_set_background (context, gtk_widget_get_window (GTK_WIDGET (tree_view)));
1571 gtk_style_context_set_background (context, tree_view->priv->header_window);
1574 tmp_list = tree_view->priv->children;
1577 PsppSheetViewChild *child = tmp_list->data;
1578 tmp_list = tmp_list->next;
1580 gtk_widget_set_parent_window (child->widget, tree_view->priv->bin_window);
1583 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
1584 _pspp_sheet_view_column_realize_button (PSPP_SHEET_VIEW_COLUMN (tmp_list->data));
1586 /* Need to call those here, since they create GCs */
1587 pspp_sheet_view_set_grid_lines (tree_view, tree_view->priv->grid_lines);
1589 install_presize_handler (tree_view);
1593 pspp_sheet_view_unrealize (GtkWidget *widget)
1595 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1596 PsppSheetViewPrivate *priv = tree_view->priv;
1599 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->unrealize (widget);
1601 if (priv->scroll_timeout != 0)
1603 g_source_remove (priv->scroll_timeout);
1604 priv->scroll_timeout = 0;
1607 if (priv->open_dest_timeout != 0)
1609 g_source_remove (priv->open_dest_timeout);
1610 priv->open_dest_timeout = 0;
1613 if (priv->presize_handler_timer != 0)
1615 g_source_remove (priv->presize_handler_timer);
1616 priv->presize_handler_timer = 0;
1619 if (priv->validate_rows_timer != 0)
1621 g_source_remove (priv->validate_rows_timer);
1622 priv->validate_rows_timer = 0;
1625 if (priv->scroll_sync_timer != 0)
1627 g_source_remove (priv->scroll_sync_timer);
1628 priv->scroll_sync_timer = 0;
1631 if (priv->typeselect_flush_timeout)
1633 g_source_remove (priv->typeselect_flush_timeout);
1634 priv->typeselect_flush_timeout = 0;
1637 for (list = priv->columns; list; list = list->next)
1638 _pspp_sheet_view_column_unrealize_button (PSPP_SHEET_VIEW_COLUMN (list->data));
1640 gdk_window_set_user_data (priv->bin_window, NULL);
1641 gdk_window_destroy (priv->bin_window);
1642 priv->bin_window = NULL;
1644 gdk_window_set_user_data (priv->header_window, NULL);
1645 gdk_window_destroy (priv->header_window);
1646 priv->header_window = NULL;
1648 if (priv->drag_window)
1650 gdk_window_set_user_data (priv->drag_window, NULL);
1651 gdk_window_destroy (priv->drag_window);
1652 priv->drag_window = NULL;
1655 if (priv->drag_highlight_window)
1657 gdk_window_set_user_data (priv->drag_highlight_window, NULL);
1658 gdk_window_destroy (priv->drag_highlight_window);
1659 priv->drag_highlight_window = NULL;
1662 if (tree_view->priv->columns != NULL)
1664 list = tree_view->priv->columns;
1667 PsppSheetViewColumn *column;
1668 column = PSPP_SHEET_VIEW_COLUMN (list->data);
1670 pspp_sheet_view_remove_column (tree_view, column);
1672 tree_view->priv->columns = NULL;
1676 /* GtkWidget::size_request helper */
1678 pspp_sheet_view_size_request_columns (PsppSheetView *tree_view)
1682 tree_view->priv->header_height = 0;
1684 if (tree_view->priv->model)
1686 for (list = tree_view->priv->columns; list; list = list->next)
1688 GtkRequisition requisition;
1689 PsppSheetViewColumn *column = list->data;
1691 pspp_sheet_view_column_size_request (column, &requisition);
1692 column->button_request = requisition.width;
1693 tree_view->priv->header_height = MAX (tree_view->priv->header_height, requisition.height);
1699 /* Called only by ::size_request */
1701 pspp_sheet_view_update_size (PsppSheetView *tree_view)
1704 PsppSheetViewColumn *column;
1707 if (tree_view->priv->model == NULL)
1709 tree_view->priv->width = 0;
1710 tree_view->priv->prev_width = 0;
1711 tree_view->priv->height = 0;
1715 tree_view->priv->prev_width = tree_view->priv->width;
1716 tree_view->priv->width = 0;
1718 /* keep this in sync with size_allocate below */
1719 for (list = tree_view->priv->columns, i = 0; list; list = list->next, i++)
1721 gint real_requested_width = 0;
1722 column = list->data;
1723 if (!column->visible)
1726 if (column->use_resized_width)
1728 real_requested_width = column->resized_width;
1732 real_requested_width = column->fixed_width;
1735 if (column->min_width != -1)
1736 real_requested_width = MAX (real_requested_width, column->min_width);
1737 if (column->max_width != -1)
1738 real_requested_width = MIN (real_requested_width, column->max_width);
1740 tree_view->priv->width += real_requested_width;
1743 tree_view->priv->height = tree_view->priv->fixed_height * tree_view->priv->row_count;
1747 pspp_sheet_view_size_request (GtkWidget *widget,
1748 GtkRequisition *requisition)
1750 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1753 /* we validate some rows initially just to make sure we have some size.
1754 * In practice, with a lot of static lists, this should get a good width.
1756 initialize_fixed_height_mode (tree_view);
1757 pspp_sheet_view_size_request_columns (tree_view);
1758 pspp_sheet_view_update_size (PSPP_SHEET_VIEW (widget));
1760 requisition->width = tree_view->priv->width;
1761 requisition->height = tree_view->priv->height + TREE_VIEW_HEADER_HEIGHT (tree_view);
1763 tmp_list = tree_view->priv->children;
1767 PsppSheetViewChild *child = tmp_list->data;
1768 GtkRequisition child_requisition;
1770 tmp_list = tmp_list->next;
1772 if (gtk_widget_get_visible (child->widget))
1774 gtk_widget_get_preferred_size (child->widget, NULL, &child_requisition);
1780 invalidate_column (PsppSheetView *tree_view,
1781 PsppSheetViewColumn *column)
1783 gint column_offset = 0;
1785 GtkWidget *widget = GTK_WIDGET (tree_view);
1788 if (!gtk_widget_get_realized (widget))
1791 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
1792 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
1794 list = (rtl ? list->prev : list->next))
1796 PsppSheetViewColumn *tmpcolumn = list->data;
1797 if (tmpcolumn == column)
1799 GdkRectangle invalid_rect;
1800 GtkAllocation allocation;
1802 gtk_widget_get_allocation (widget, &allocation);
1803 invalid_rect.x = column_offset;
1805 invalid_rect.width = column->width;
1806 invalid_rect.height = allocation.height;
1808 gdk_window_invalidate_rect (gtk_widget_get_window (widget), &invalid_rect, TRUE);
1812 column_offset += tmpcolumn->width;
1817 invalidate_last_column (PsppSheetView *tree_view)
1822 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
1824 for (last_column = (rtl ? g_list_first (tree_view->priv->columns) : g_list_last (tree_view->priv->columns));
1826 last_column = (rtl ? last_column->next : last_column->prev))
1828 if (PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible)
1830 invalidate_column (tree_view, last_column->data);
1837 pspp_sheet_view_get_real_requested_width_from_column (PsppSheetView *tree_view,
1838 PsppSheetViewColumn *column)
1840 gint real_requested_width;
1842 if (column->use_resized_width)
1844 real_requested_width = column->resized_width;
1848 real_requested_width = column->fixed_width;
1851 if (column->min_width != -1)
1852 real_requested_width = MAX (real_requested_width, column->min_width);
1853 if (column->max_width != -1)
1854 real_requested_width = MIN (real_requested_width, column->max_width);
1856 return real_requested_width;
1860 span_intersects (int a0, int a_width,
1861 int b0, int b_width)
1863 int a1 = a0 + a_width;
1864 int b1 = b0 + b_width;
1865 return (a0 >= b0 && a0 < b1) || (b0 >= a0 && b0 < a1);
1868 /* GtkWidget::size_allocate helper */
1870 pspp_sheet_view_size_allocate_columns (GtkWidget *widget,
1871 gboolean *width_changed)
1873 PsppSheetView *tree_view;
1874 GList *list, *first_column, *last_column;
1875 PsppSheetViewColumn *column;
1876 GtkAllocation col_allocation;
1877 GtkAllocation allocation;
1879 gint extra, extra_per_column;
1880 gint full_requested_width = 0;
1881 gint number_of_expand_columns = 0;
1882 gboolean column_changed = FALSE;
1885 tree_view = PSPP_SHEET_VIEW (widget);
1887 for (last_column = g_list_last (tree_view->priv->columns);
1888 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
1889 last_column = last_column->prev)
1892 if (last_column == NULL)
1895 for (first_column = g_list_first (tree_view->priv->columns);
1896 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
1897 first_column = first_column->next)
1900 col_allocation.y = 0;
1901 col_allocation.height = tree_view->priv->header_height;
1903 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1905 /* find out how many extra space and expandable columns we have */
1906 for (list = tree_view->priv->columns; list != last_column->next; list = list->next)
1908 column = (PsppSheetViewColumn *)list->data;
1910 if (!column->visible)
1913 full_requested_width += pspp_sheet_view_get_real_requested_width_from_column (tree_view, column);
1916 number_of_expand_columns++;
1919 gtk_widget_get_allocation (widget, &allocation);
1920 extra = MAX (allocation.width - full_requested_width, 0);
1921 if (number_of_expand_columns > 0)
1922 extra_per_column = extra/number_of_expand_columns;
1924 extra_per_column = 0;
1926 for (list = (rtl ? last_column : first_column);
1927 list != (rtl ? first_column->prev : last_column->next);
1928 list = (rtl ? list->prev : list->next))
1930 gint real_requested_width = 0;
1933 column = list->data;
1934 old_width = column->width;
1936 if (!column->visible)
1939 /* We need to handle the dragged button specially.
1941 if (column == tree_view->priv->drag_column)
1943 GtkAllocation drag_allocation;
1944 drag_allocation.width = gdk_window_get_width (tree_view->priv->drag_window);
1945 drag_allocation.height = gdk_window_get_height (tree_view->priv->drag_window);
1946 drag_allocation.x = 0;
1947 drag_allocation.y = 0;
1948 pspp_sheet_view_column_size_allocate (tree_view->priv->drag_column,
1950 width += drag_allocation.width;
1954 real_requested_width = pspp_sheet_view_get_real_requested_width_from_column (tree_view, column);
1956 col_allocation.x = width;
1957 column->width = real_requested_width;
1961 if (number_of_expand_columns == 1)
1963 /* We add the remander to the last column as
1965 column->width += extra;
1969 column->width += extra_per_column;
1970 extra -= extra_per_column;
1971 number_of_expand_columns --;
1975 if (column->width != old_width)
1976 g_object_notify (G_OBJECT (column), "width");
1978 col_allocation.width = column->width;
1979 width += column->width;
1981 if (column->width > old_width)
1982 column_changed = TRUE;
1984 pspp_sheet_view_column_size_allocate (column, &col_allocation);
1987 gdk_window_move_resize (column->window,
1988 col_allocation.x + (rtl ? 0 : col_allocation.width) - TREE_VIEW_DRAG_WIDTH/2,
1990 TREE_VIEW_DRAG_WIDTH, col_allocation.height);
1993 /* We change the width here. The user might have been resizing columns,
1994 * so the total width of the tree view changes.
1996 tree_view->priv->width = width;
1998 *width_changed = TRUE;
2001 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
2005 update_childrens_allocation (PsppSheetView *tree_view)
2008 for (tmp_list = tree_view->priv->children; tmp_list; tmp_list = tmp_list->next)
2010 PsppSheetViewChild *child = tmp_list->data;
2011 GtkAllocation allocation;
2014 /* totally ignore our child's requisition */
2015 path = _pspp_sheet_view_find_path (tree_view, child->node);
2016 pspp_sheet_view_get_cell_area (tree_view, path, child->column, &allocation);
2017 gtk_tree_path_free (path);
2018 gtk_widget_size_allocate (child->widget, &allocation);
2023 pspp_sheet_view_size_allocate (GtkWidget *widget,
2024 GtkAllocation *allocation)
2026 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2028 gboolean width_changed = FALSE;
2029 GtkAllocation old_allocation;
2030 gtk_widget_get_allocation (widget, &old_allocation);
2032 if (allocation->width != old_allocation.width)
2033 width_changed = TRUE;
2035 if (gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL)
2036 allocation->x += allocation->width - tree_view->priv->width ;
2038 gtk_widget_set_allocation (widget, allocation);
2040 /* We size-allocate the columns first because the width of the
2041 * tree view (used in updating the adjustments below) might change.
2043 pspp_sheet_view_size_allocate_columns (widget, &width_changed);
2045 gtk_adjustment_set_page_size (tree_view->priv->hadjustment, allocation->width);
2046 gtk_adjustment_set_page_increment (tree_view->priv->hadjustment, allocation->width * 0.9);
2047 gtk_adjustment_set_step_increment (tree_view->priv->hadjustment, allocation->width * 0.1);
2048 gtk_adjustment_set_lower (tree_view->priv->hadjustment, 0);
2049 gtk_adjustment_set_upper (tree_view->priv->hadjustment, MAX (gtk_adjustment_get_page_size (tree_view->priv->hadjustment), tree_view->priv->width));
2051 if (gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL)
2053 if (allocation->width < tree_view->priv->width)
2055 if (tree_view->priv->init_hadjust_value)
2057 gtk_adjustment_set_value (tree_view->priv->hadjustment, MAX (tree_view->priv->width - allocation->width, 0));
2058 tree_view->priv->init_hadjust_value = FALSE;
2060 else if (allocation->width != old_allocation.width)
2062 gtk_adjustment_set_value (tree_view->priv->hadjustment, CLAMP (gtk_adjustment_get_value (tree_view->priv->hadjustment) - allocation->width + old_allocation.width, 0, tree_view->priv->width - allocation->width));
2065 gtk_adjustment_set_value (tree_view->priv->hadjustment, CLAMP (tree_view->priv->width - (tree_view->priv->prev_width - gtk_adjustment_get_value (tree_view->priv->hadjustment)), 0, tree_view->priv->width - allocation->width));
2069 gtk_adjustment_set_value (tree_view->priv->hadjustment, 0);
2070 tree_view->priv->init_hadjust_value = TRUE;
2074 if (gtk_adjustment_get_value (tree_view->priv->hadjustment) + allocation->width > tree_view->priv->width)
2075 gtk_adjustment_set_value (tree_view->priv->hadjustment, MAX (tree_view->priv->width - allocation->width, 0));
2077 gtk_adjustment_changed (tree_view->priv->hadjustment);
2079 gtk_adjustment_set_page_size (tree_view->priv->vadjustment, allocation->height - TREE_VIEW_HEADER_HEIGHT (tree_view));
2080 gtk_adjustment_set_step_increment (tree_view->priv->vadjustment, gtk_adjustment_get_page_size (tree_view->priv->vadjustment) * 0.1);
2081 gtk_adjustment_set_page_increment (tree_view->priv->vadjustment, gtk_adjustment_get_page_size (tree_view->priv->vadjustment) * 0.9);
2082 gtk_adjustment_set_lower (tree_view->priv->vadjustment, 0);
2083 gtk_adjustment_set_upper (tree_view->priv->vadjustment, MAX (gtk_adjustment_get_page_size (tree_view->priv->vadjustment), tree_view->priv->height));
2085 gtk_adjustment_changed (tree_view->priv->vadjustment);
2087 /* now the adjustments and window sizes are in sync, we can sync toprow/dy again */
2088 if (tree_view->priv->height <= gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
2089 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment), 0);
2090 else if (gtk_adjustment_get_value (tree_view->priv->vadjustment) + gtk_adjustment_get_page_size (tree_view->priv->vadjustment) > tree_view->priv->height)
2091 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment),
2092 tree_view->priv->height - gtk_adjustment_get_page_size (tree_view->priv->vadjustment));
2093 else if (gtk_tree_row_reference_valid (tree_view->priv->top_row))
2094 pspp_sheet_view_top_row_to_dy (tree_view);
2096 pspp_sheet_view_dy_to_top_row (tree_view);
2098 if (gtk_widget_get_realized (widget))
2100 gdk_window_move_resize (gtk_widget_get_window (widget),
2101 allocation->x, allocation->y,
2102 allocation->width, allocation->height);
2103 gdk_window_move_resize (tree_view->priv->header_window,
2104 - (gint) gtk_adjustment_get_value (tree_view->priv->hadjustment),
2106 MAX (tree_view->priv->width, allocation->width),
2107 tree_view->priv->header_height);
2108 gdk_window_move_resize (tree_view->priv->bin_window,
2109 - (gint) gtk_adjustment_get_value (tree_view->priv->hadjustment),
2110 TREE_VIEW_HEADER_HEIGHT (tree_view),
2111 MAX (tree_view->priv->width, allocation->width),
2112 allocation->height - TREE_VIEW_HEADER_HEIGHT (tree_view));
2115 if (tree_view->priv->row_count == 0)
2116 invalidate_empty_focus (tree_view);
2118 if (gtk_widget_get_realized (widget))
2120 gboolean has_expand_column = FALSE;
2121 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
2123 if (pspp_sheet_view_column_get_expand (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)))
2125 has_expand_column = TRUE;
2130 /* This little hack only works if we have an LTR locale, and no column has the */
2133 if (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_LTR &&
2134 ! has_expand_column)
2135 invalidate_last_column (tree_view);
2137 gtk_widget_queue_draw (widget);
2139 update_childrens_allocation(tree_view);
2143 /* Grabs the focus and unsets the PSPP_SHEET_VIEW_DRAW_KEYFOCUS flag */
2145 grab_focus_and_unset_draw_keyfocus (PsppSheetView *tree_view)
2147 GtkWidget *widget = GTK_WIDGET (tree_view);
2149 if (gtk_widget_get_can_focus (widget) && !gtk_widget_has_focus (widget))
2150 gtk_widget_grab_focus (widget);
2151 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
2155 pspp_sheet_view_node_is_selected (PsppSheetView *tree_view,
2158 return node >= 0 && range_tower_contains (tree_view->priv->selected, node);
2162 pspp_sheet_view_node_select (PsppSheetView *tree_view,
2165 range_tower_set1 (tree_view->priv->selected, node, 1);
2169 pspp_sheet_view_node_unselect (PsppSheetView *tree_view,
2172 range_tower_set0 (tree_view->priv->selected, node, 1);
2176 pspp_sheet_view_node_next (PsppSheetView *tree_view,
2179 return node + 1 < tree_view->priv->row_count ? node + 1 : -1;
2183 pspp_sheet_view_node_prev (PsppSheetView *tree_view,
2186 return node > 0 ? node - 1 : -1;
2190 all_columns_selected (PsppSheetView *tree_view)
2194 for (list = tree_view->priv->columns; list; list = list->next)
2196 PsppSheetViewColumn *column = list->data;
2197 if (column->selectable && !column->selected)
2205 pspp_sheet_view_row_head_clicked (PsppSheetView *tree_view,
2207 PsppSheetViewColumn *column,
2208 GdkEventButton *event)
2210 PsppSheetSelection *selection;
2211 PsppSheetSelectionMode mode;
2213 gboolean update_anchor;
2217 g_return_val_if_fail (tree_view != NULL, FALSE);
2218 g_return_val_if_fail (column != NULL, FALSE);
2220 selection = tree_view->priv->selection;
2221 mode = pspp_sheet_selection_get_mode (selection);
2222 if (mode != PSPP_SHEET_SELECTION_RECTANGLE)
2225 if (!column->row_head)
2230 modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
2231 if (event->type != GDK_BUTTON_PRESS
2232 || (modifiers != GDK_CONTROL_MASK && modifiers != GDK_SHIFT_MASK))
2238 path = gtk_tree_path_new_from_indices (node, -1);
2241 pspp_sheet_selection_unselect_all (selection);
2242 pspp_sheet_selection_select_path (selection, path);
2243 pspp_sheet_selection_select_all_columns (selection);
2244 update_anchor = TRUE;
2247 else if (event->type == GDK_BUTTON_PRESS && event->button == 3)
2249 if (pspp_sheet_selection_count_selected_rows (selection) <= 1
2250 || !all_columns_selected (tree_view))
2252 pspp_sheet_selection_unselect_all (selection);
2253 pspp_sheet_selection_select_path (selection, path);
2254 pspp_sheet_selection_select_all_columns (selection);
2255 update_anchor = TRUE;
2259 update_anchor = handled = FALSE;
2261 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
2262 && modifiers == GDK_CONTROL_MASK)
2264 if (!all_columns_selected (tree_view))
2266 pspp_sheet_selection_unselect_all (selection);
2267 pspp_sheet_selection_select_all_columns (selection);
2270 if (pspp_sheet_selection_path_is_selected (selection, path))
2271 pspp_sheet_selection_unselect_path (selection, path);
2273 pspp_sheet_selection_select_path (selection, path);
2274 update_anchor = TRUE;
2277 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
2278 && modifiers == GDK_SHIFT_MASK)
2280 GtkTreeRowReference *anchor = tree_view->priv->anchor;
2281 GtkTreePath *anchor_path;
2283 if (all_columns_selected (tree_view)
2284 && gtk_tree_row_reference_valid (anchor))
2286 update_anchor = FALSE;
2287 anchor_path = gtk_tree_row_reference_get_path (anchor);
2291 update_anchor = TRUE;
2292 anchor_path = gtk_tree_path_copy (path);
2295 pspp_sheet_selection_unselect_all (selection);
2296 pspp_sheet_selection_select_range (selection, anchor_path, path);
2297 pspp_sheet_selection_select_all_columns (selection);
2299 gtk_tree_path_free (anchor_path);
2304 update_anchor = handled = FALSE;
2308 if (tree_view->priv->anchor)
2309 gtk_tree_row_reference_free (tree_view->priv->anchor);
2310 tree_view->priv->anchor =
2311 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
2312 tree_view->priv->model,
2316 gtk_tree_path_free (path);
2321 find_click (PsppSheetView *tree_view,
2324 PsppSheetViewColumn **column,
2325 GdkRectangle *background_area,
2326 GdkRectangle *cell_area)
2333 /* find the node that was clicked */
2334 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, y);
2337 y_offset = -pspp_sheet_view_find_offset (tree_view, new_y, node);
2342 background_area->y = y_offset + y;
2343 background_area->height = ROW_HEIGHT (tree_view);
2344 background_area->x = 0;
2346 /* Let the column have a chance at selecting it. */
2347 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
2348 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
2349 list; list = (rtl ? list->prev : list->next))
2351 PsppSheetViewColumn *candidate = list->data;
2353 if (!candidate->visible)
2356 background_area->width = candidate->width;
2357 if ((background_area->x > x) ||
2358 (background_area->x + background_area->width <= x))
2360 background_area->x += background_area->width;
2364 /* we found the focus column */
2366 pspp_sheet_view_adjust_cell_area (tree_view, candidate, background_area,
2368 *column = candidate;
2376 pspp_sheet_view_button_press (GtkWidget *widget,
2377 GdkEventButton *event)
2379 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2381 PsppSheetViewColumn *column = NULL;
2383 GdkRectangle background_area;
2384 GdkRectangle cell_area;
2387 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
2388 pspp_sheet_view_stop_editing (tree_view, FALSE);
2391 /* Because grab_focus can cause reentrancy, we delay grab_focus until after
2392 * we're done handling the button press.
2395 if (event->window == tree_view->priv->bin_window)
2400 gint pre_val, aft_val;
2401 PsppSheetViewColumn *column = NULL;
2402 GtkCellRenderer *focus_cell = NULL;
2403 gboolean row_double_click = FALSE;
2406 if (tree_view->priv->row_count == 0)
2408 grab_focus_and_unset_draw_keyfocus (tree_view);
2412 if (!find_click (tree_view, event->x, event->y, &node, &column,
2413 &background_area, &cell_area))
2415 grab_focus_and_unset_draw_keyfocus (tree_view);
2419 tree_view->priv->focus_column = column;
2421 if (pspp_sheet_view_row_head_clicked (tree_view, node, column, event))
2425 pre_val = gtk_adjustment_get_value (tree_view->priv->vadjustment);
2427 path = _pspp_sheet_view_find_path (tree_view, node);
2429 /* we only handle selection modifications on the first button press
2431 if (event->type == GDK_BUTTON_PRESS)
2433 PsppSheetSelectionMode mode = 0;
2435 if ((event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
2436 mode |= PSPP_SHEET_SELECT_MODE_TOGGLE;
2437 if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
2438 mode |= PSPP_SHEET_SELECT_MODE_EXTEND;
2440 focus_cell = _pspp_sheet_view_column_get_cell_at_pos (column, event->x - background_area.x);
2442 pspp_sheet_view_column_focus_cell (column, focus_cell);
2444 if (event->state & GDK_CONTROL_MASK)
2446 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE, mode);
2447 pspp_sheet_view_real_toggle_cursor_row (tree_view);
2449 else if (event->state & GDK_SHIFT_MASK)
2451 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, mode);
2452 pspp_sheet_view_real_select_cursor_row (tree_view, FALSE, mode);
2456 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, 0);
2459 if (tree_view->priv->anchor_column == NULL ||
2460 !(event->state & GDK_SHIFT_MASK))
2461 tree_view->priv->anchor_column = column;
2462 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
2463 pspp_sheet_selection_select_column_range (tree_view->priv->selection,
2464 tree_view->priv->anchor_column,
2468 /* the treeview may have been scrolled because of _set_cursor,
2472 aft_val = gtk_adjustment_get_value (tree_view->priv->vadjustment);
2473 dval = pre_val - aft_val;
2475 cell_area.y += dval;
2476 background_area.y += dval;
2478 /* Save press to possibly begin a drag
2480 if (!tree_view->priv->in_grab &&
2481 tree_view->priv->pressed_button < 0)
2483 tree_view->priv->pressed_button = event->button;
2484 tree_view->priv->press_start_x = event->x;
2485 tree_view->priv->press_start_y = event->y;
2486 tree_view->priv->press_start_node = node;
2488 if (tree_view->priv->rubber_banding_enable
2489 && (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
2490 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE))
2492 tree_view->priv->press_start_y += tree_view->priv->dy;
2493 tree_view->priv->rubber_band_x = event->x;
2494 tree_view->priv->rubber_band_y = event->y + tree_view->priv->dy;
2495 tree_view->priv->rubber_band_status = RUBBER_BAND_MAYBE_START;
2497 if ((event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
2498 tree_view->priv->rubber_band_ctrl = TRUE;
2499 if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
2500 tree_view->priv->rubber_band_shift = TRUE;
2505 /* Test if a double click happened on the same row. */
2506 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
2508 int double_click_time, double_click_distance;
2510 g_object_get (gtk_settings_get_for_screen (
2511 gtk_widget_get_screen (widget)),
2512 "gtk-double-click-time", &double_click_time,
2513 "gtk-double-click-distance", &double_click_distance,
2516 /* Same conditions as _gdk_event_button_generate */
2517 if (tree_view->priv->last_button_x != -1 &&
2518 (event->time < tree_view->priv->last_button_time + double_click_time) &&
2519 (ABS (event->x - tree_view->priv->last_button_x) <= double_click_distance) &&
2520 (ABS (event->y - tree_view->priv->last_button_y) <= double_click_distance))
2522 /* We do no longer compare paths of this row and the
2523 * row clicked previously. We use the double click
2524 * distance to decide whether this is a valid click,
2525 * allowing the mouse to slightly move over another row.
2527 row_double_click = TRUE;
2529 tree_view->priv->last_button_time = 0;
2530 tree_view->priv->last_button_x = -1;
2531 tree_view->priv->last_button_y = -1;
2535 tree_view->priv->last_button_time = event->time;
2536 tree_view->priv->last_button_x = event->x;
2537 tree_view->priv->last_button_y = event->y;
2541 if (row_double_click)
2543 gtk_grab_remove (widget);
2544 pspp_sheet_view_row_activated (tree_view, path, column);
2546 if (tree_view->priv->pressed_button == event->button)
2547 tree_view->priv->pressed_button = -1;
2550 gtk_tree_path_free (path);
2552 /* If we activated the row through a double click we don't want to grab
2553 * focus back, as moving focus to another widget is pretty common.
2555 if (!row_double_click)
2556 grab_focus_and_unset_draw_keyfocus (tree_view);
2561 /* We didn't click in the window. Let's check to see if we clicked on a column resize window.
2563 for (i = 0, list = tree_view->priv->columns; list; list = list->next, i++)
2565 column = list->data;
2566 if (event->window == column->window &&
2567 column->resizable &&
2572 if (GDK_GRAB_SUCCESS != gdk_device_grab (event->device,
2576 GDK_POINTER_MOTION_HINT_MASK |
2577 GDK_BUTTON1_MOTION_MASK |
2578 GDK_BUTTON_RELEASE_MASK,
2582 gtk_grab_add (widget);
2583 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE);
2584 column->resized_width = column->width;
2586 /* block attached dnd signal handler */
2587 drag_data = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
2589 g_signal_handlers_block_matched (widget,
2590 G_SIGNAL_MATCH_DATA,
2594 tree_view->priv->drag_pos = i;
2595 tree_view->priv->x_drag = column->allocation.x + (rtl ? 0 : column->allocation.width);
2597 if (!gtk_widget_has_focus (widget))
2598 gtk_widget_grab_focus (widget);
2606 /* GtkWidget::button_release_event helper */
2608 pspp_sheet_view_button_release_drag_column (GtkWidget *widget,
2609 GdkEventButton *event)
2611 PsppSheetView *tree_view;
2615 tree_view = PSPP_SHEET_VIEW (widget);
2617 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
2618 gdk_display_pointer_ungrab (gtk_widget_get_display (widget), GDK_CURRENT_TIME);
2619 gdk_display_keyboard_ungrab (gtk_widget_get_display (widget), GDK_CURRENT_TIME);
2621 /* Move the button back */
2622 g_return_val_if_fail (tree_view->priv->drag_column->button, FALSE);
2624 g_object_ref (tree_view->priv->drag_column->button);
2625 gtk_container_remove (GTK_CONTAINER (tree_view), tree_view->priv->drag_column->button);
2626 gtk_widget_set_parent_window (tree_view->priv->drag_column->button, tree_view->priv->header_window);
2627 gtk_widget_set_parent (tree_view->priv->drag_column->button, GTK_WIDGET (tree_view));
2628 g_object_unref (tree_view->priv->drag_column->button);
2629 gtk_widget_queue_resize (widget);
2630 if (tree_view->priv->drag_column->resizable)
2632 gdk_window_raise (tree_view->priv->drag_column->window);
2633 gdk_window_show (tree_view->priv->drag_column->window);
2636 gdk_window_hide (tree_view->priv->drag_column->window);
2638 gtk_widget_grab_focus (tree_view->priv->drag_column->button);
2642 if (tree_view->priv->cur_reorder &&
2643 tree_view->priv->cur_reorder->right_column != tree_view->priv->drag_column)
2644 pspp_sheet_view_move_column_after (tree_view, tree_view->priv->drag_column,
2645 tree_view->priv->cur_reorder->right_column);
2649 if (tree_view->priv->cur_reorder &&
2650 tree_view->priv->cur_reorder->left_column != tree_view->priv->drag_column)
2651 pspp_sheet_view_move_column_after (tree_view, tree_view->priv->drag_column,
2652 tree_view->priv->cur_reorder->left_column);
2654 tree_view->priv->drag_column = NULL;
2655 gdk_window_hide (tree_view->priv->drag_window);
2657 for (l = tree_view->priv->column_drag_info; l != NULL; l = l->next)
2658 g_slice_free (PsppSheetViewColumnReorder, l->data);
2659 g_list_free (tree_view->priv->column_drag_info);
2660 tree_view->priv->column_drag_info = NULL;
2661 tree_view->priv->cur_reorder = NULL;
2663 if (tree_view->priv->drag_highlight_window)
2664 gdk_window_hide (tree_view->priv->drag_highlight_window);
2666 /* Reset our flags */
2667 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_UNSET;
2668 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG);
2673 /* GtkWidget::button_release_event helper */
2675 pspp_sheet_view_button_release_column_resize (GtkWidget *widget,
2676 GdkEventButton *event)
2678 PsppSheetView *tree_view;
2681 tree_view = PSPP_SHEET_VIEW (widget);
2683 tree_view->priv->drag_pos = -1;
2685 /* unblock attached dnd signal handler */
2686 drag_data = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
2688 g_signal_handlers_unblock_matched (widget,
2689 G_SIGNAL_MATCH_DATA,
2693 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE);
2694 gtk_grab_remove (widget);
2695 gdk_device_ungrab (event->device, event->time);
2701 pspp_sheet_view_button_release_edit (PsppSheetView *tree_view,
2702 GdkEventButton *event)
2704 GtkCellEditable *cell_editable;
2709 PsppSheetViewColumn *column;
2710 GdkRectangle background_area;
2711 GdkRectangle cell_area;
2717 if (event->window != tree_view->priv->bin_window)
2720 /* Ignore a released button, if that button wasn't depressed */
2721 if (tree_view->priv->pressed_button != event->button)
2724 if (!find_click (tree_view, event->x, event->y, &node, &column, &background_area,
2728 /* decide if we edit */
2729 path = _pspp_sheet_view_find_path (tree_view, node);
2730 modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
2731 if (event->button != 1 || modifiers)
2734 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
2735 pspp_sheet_view_column_cell_set_cell_data (column,
2736 tree_view->priv->model,
2739 if (!pspp_sheet_view_column_get_quick_edit (column)
2740 && _pspp_sheet_view_column_has_editable_cell (column))
2743 flags = 0; /* FIXME: get the right flags */
2744 path_string = gtk_tree_path_to_string (path);
2746 if (!_pspp_sheet_view_column_cell_event (column,
2754 if (cell_editable == NULL)
2757 pspp_sheet_view_real_set_cursor (tree_view, path,
2758 TRUE, TRUE, 0); /* XXX mode? */
2759 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
2762 _pspp_sheet_view_column_get_neighbor_sizes (
2763 column, _pspp_sheet_view_column_get_edited_cell (column), &left, &right);
2766 area.width -= right + left;
2768 pspp_sheet_view_real_start_editing (tree_view,
2775 g_free (path_string);
2776 gtk_tree_path_free (path);
2781 pspp_sheet_view_button_release (GtkWidget *widget,
2782 GdkEventButton *event)
2784 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2786 pspp_sheet_view_stop_editing (tree_view, FALSE);
2787 if (tree_view->priv->rubber_band_status != RUBBER_BAND_ACTIVE
2788 && pspp_sheet_view_button_release_edit (tree_view, event))
2790 if (tree_view->priv->pressed_button == event->button)
2791 tree_view->priv->pressed_button = -1;
2793 tree_view->priv->rubber_band_status = RUBBER_BAND_OFF;
2797 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
2798 return pspp_sheet_view_button_release_drag_column (widget, event);
2800 if (tree_view->priv->rubber_band_status)
2801 pspp_sheet_view_stop_rubber_band (tree_view);
2803 if (tree_view->priv->pressed_button == event->button)
2804 tree_view->priv->pressed_button = -1;
2806 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
2807 return pspp_sheet_view_button_release_column_resize (widget, event);
2813 pspp_sheet_view_grab_broken (GtkWidget *widget,
2814 GdkEventGrabBroken *event)
2816 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2818 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
2819 pspp_sheet_view_button_release_drag_column (widget, (GdkEventButton *)event);
2821 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
2822 pspp_sheet_view_button_release_column_resize (widget, (GdkEventButton *)event);
2827 /* GtkWidget::motion_event function set.
2831 do_prelight (PsppSheetView *tree_view,
2833 /* these are in bin_window coords */
2837 int prev_node = tree_view->priv->prelight_node;
2839 if (prev_node != node)
2841 tree_view->priv->prelight_node = node;
2844 _pspp_sheet_view_queue_draw_node (tree_view, prev_node, NULL);
2847 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
2853 prelight_or_select (PsppSheetView *tree_view,
2855 /* these are in bin_window coords */
2859 PsppSheetSelectionMode mode = pspp_sheet_selection_get_mode (tree_view->priv->selection);
2861 if (tree_view->priv->hover_selection &&
2862 (mode == PSPP_SHEET_SELECTION_SINGLE || mode == PSPP_SHEET_SELECTION_BROWSE) &&
2863 !(tree_view->priv->edited_column &&
2864 tree_view->priv->edited_column->editable_widget))
2868 if (!pspp_sheet_view_node_is_selected (tree_view, node))
2872 path = _pspp_sheet_view_find_path (tree_view, node);
2873 pspp_sheet_selection_select_path (tree_view->priv->selection, path);
2874 if (pspp_sheet_view_node_is_selected (tree_view, node))
2876 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
2877 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, FALSE, 0); /* XXX mode? */
2879 gtk_tree_path_free (path);
2883 else if (mode == PSPP_SHEET_SELECTION_SINGLE)
2884 pspp_sheet_selection_unselect_all (tree_view->priv->selection);
2887 do_prelight (tree_view, node, x, y);
2891 ensure_unprelighted (PsppSheetView *tree_view)
2893 do_prelight (tree_view,
2895 -1000, -1000); /* coords not possibly over an arrow */
2897 g_assert (tree_view->priv->prelight_node < 0);
2901 update_prelight (PsppSheetView *tree_view,
2908 if (tree_view->priv->row_count == 0)
2913 ensure_unprelighted (tree_view);
2917 new_y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, y);
2921 pspp_sheet_view_find_offset (tree_view, new_y, &node);
2924 prelight_or_select (tree_view, node, x, y);
2930 /* Our motion arrow is either a box (in the case of the original spot)
2931 * or an arrow. It is expander_size wide.
2954 pspp_sheet_view_motion_draw_column_motion_arrow (PsppSheetView *tree_view)
2957 PsppSheetViewColumnReorder *reorder = tree_view->priv->cur_reorder;
2958 GtkWidget *widget = GTK_WIDGET (tree_view);
2959 GdkBitmap *mask = NULL;
2964 gint arrow_type = DRAG_COLUMN_WINDOW_STATE_UNSET;
2965 GdkWindowAttr attributes;
2966 guint attributes_mask;
2969 reorder->left_column == tree_view->priv->drag_column ||
2970 reorder->right_column == tree_view->priv->drag_column)
2971 arrow_type = DRAG_COLUMN_WINDOW_STATE_ORIGINAL;
2972 else if (reorder->left_column || reorder->right_column)
2974 GdkRectangle visible_rect;
2975 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
2976 if (reorder->left_column)
2977 x = reorder->left_column->allocation.x + reorder->left_column->allocation.width;
2979 x = reorder->right_column->allocation.x;
2981 if (x < visible_rect.x)
2982 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT;
2983 else if (x > visible_rect.x + visible_rect.width)
2984 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT;
2986 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW;
2989 /* We want to draw the rectangle over the initial location. */
2990 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ORIGINAL)
2995 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ORIGINAL)
2997 if (tree_view->priv->drag_highlight_window)
2999 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
3001 gdk_window_destroy (tree_view->priv->drag_highlight_window);
3004 attributes.window_type = GDK_WINDOW_CHILD;
3005 attributes.wclass = GDK_INPUT_OUTPUT;
3006 attributes.x = tree_view->priv->drag_column_x;
3008 width = attributes.width = tree_view->priv->drag_column->allocation.width;
3009 height = attributes.height = tree_view->priv->drag_column->allocation.height;
3010 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
3011 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
3012 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
3013 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
3014 tree_view->priv->drag_highlight_window = gdk_window_new (tree_view->priv->header_window, &attributes, attributes_mask);
3015 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
3017 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
3018 gc = gdk_gc_new (mask);
3020 gdk_gc_set_foreground (gc, &col);
3021 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
3023 gdk_gc_set_foreground(gc, &col);
3024 gdk_draw_rectangle (mask, gc, TRUE, 2, 2, width - 4, height - 4);
3025 g_object_unref (gc);
3027 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
3029 if (mask) g_object_unref (mask);
3030 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_ORIGINAL;
3033 else if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW)
3039 width = tree_view->priv->expander_size;
3041 /* Get x, y, width, height of arrow */
3042 gdk_window_get_origin (tree_view->priv->header_window, &x, &y);
3043 if (reorder->left_column)
3045 x += reorder->left_column->allocation.x + reorder->left_column->allocation.width - width/2;
3046 height = reorder->left_column->allocation.height;
3050 x += reorder->right_column->allocation.x - width/2;
3051 height = reorder->right_column->allocation.height;
3053 y -= tree_view->priv->expander_size/2; /* The arrow takes up only half the space */
3054 height += tree_view->priv->expander_size;
3056 /* Create the new window */
3057 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW)
3059 if (tree_view->priv->drag_highlight_window)
3061 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
3063 gdk_window_destroy (tree_view->priv->drag_highlight_window);
3066 attributes.window_type = GDK_WINDOW_TEMP;
3067 attributes.wclass = GDK_INPUT_OUTPUT;
3068 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
3069 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
3070 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
3071 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
3074 attributes.width = width;
3075 attributes.height = height;
3076 tree_view->priv->drag_highlight_window = gdk_window_new (gtk_widget_get_root_window (widget),
3077 &attributes, attributes_mask);
3078 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
3080 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
3081 gc = gdk_gc_new (mask);
3083 gdk_gc_set_foreground (gc, &col);
3084 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
3086 /* Draw the 2 arrows as per above */
3088 gdk_gc_set_foreground (gc, &col);
3089 for (i = 0; i < width; i ++)
3091 if (i == (width/2 - 1))
3093 gdk_draw_line (mask, gc, i, j, i, height - j);
3094 if (i < (width/2 - 1))
3099 g_object_unref (gc);
3100 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
3102 if (mask) g_object_unref (mask);
3105 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_ARROW;
3106 gdk_window_move (tree_view->priv->drag_highlight_window, x, y);
3108 else if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT ||
3109 arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3115 width = tree_view->priv->expander_size;
3117 /* Get x, y, width, height of arrow */
3118 width = width/2; /* remember, the arrow only takes half the available width */
3119 gdk_window_get_origin (gtk_widget_get_window (widget), &x, &y);
3120 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3121 x += widget->allocation.width - width;
3123 if (reorder->left_column)
3124 height = reorder->left_column->allocation.height;
3126 height = reorder->right_column->allocation.height;
3128 y -= tree_view->priv->expander_size;
3129 height += 2*tree_view->priv->expander_size;
3131 /* Create the new window */
3132 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT &&
3133 tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3135 if (tree_view->priv->drag_highlight_window)
3137 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
3139 gdk_window_destroy (tree_view->priv->drag_highlight_window);
3142 attributes.window_type = GDK_WINDOW_TEMP;
3143 attributes.wclass = GDK_INPUT_OUTPUT;
3144 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
3145 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
3146 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
3147 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
3150 attributes.width = width;
3151 attributes.height = height;
3152 tree_view->priv->drag_highlight_window = gdk_window_new (NULL, &attributes, attributes_mask);
3153 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
3155 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
3156 gc = gdk_gc_new (mask);
3158 gdk_gc_set_foreground (gc, &col);
3159 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
3161 /* Draw the 2 arrows as per above */
3163 gdk_gc_set_foreground (gc, &col);
3164 j = tree_view->priv->expander_size;
3165 for (i = 0; i < width; i ++)
3168 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT)
3172 gdk_draw_line (mask, gc, k, j, k, height - j);
3173 gdk_draw_line (mask, gc, k, 0, k, tree_view->priv->expander_size - j);
3174 gdk_draw_line (mask, gc, k, height, k, height - tree_view->priv->expander_size + j);
3177 g_object_unref (gc);
3178 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
3180 if (mask) g_object_unref (mask);
3183 tree_view->priv->drag_column_window_state = arrow_type;
3184 gdk_window_move (tree_view->priv->drag_highlight_window, x, y);
3188 g_warning (G_STRLOC"Invalid PsppSheetViewColumnReorder struct");
3189 gdk_window_hide (tree_view->priv->drag_highlight_window);
3193 gdk_window_show (tree_view->priv->drag_highlight_window);
3194 gdk_window_raise (tree_view->priv->drag_highlight_window);
3199 pspp_sheet_view_motion_resize_column (GtkWidget *widget,
3200 GdkEventMotion *event)
3204 PsppSheetViewColumn *column;
3205 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
3207 column = pspp_sheet_view_get_column (tree_view, tree_view->priv->drag_pos);
3209 if (event->is_hint || event->window != gtk_widget_get_window (widget))
3210 gtk_widget_get_pointer (widget, &x, NULL);
3214 if (tree_view->priv->hadjustment)
3215 x += gtk_adjustment_get_value (tree_view->priv->hadjustment);
3217 new_width = pspp_sheet_view_new_column_width (tree_view,
3218 tree_view->priv->drag_pos, &x);
3219 if (x != tree_view->priv->x_drag &&
3220 (new_width != column->fixed_width))
3222 column->use_resized_width = TRUE;
3223 column->resized_width = new_width;
3226 column->resized_width -= tree_view->priv->last_extra_space_per_column;
3228 gtk_widget_queue_resize (widget);
3236 pspp_sheet_view_update_current_reorder (PsppSheetView *tree_view)
3238 PsppSheetViewColumnReorder *reorder = NULL;
3242 gdk_window_get_pointer (tree_view->priv->header_window, &mouse_x, NULL, NULL);
3243 for (list = tree_view->priv->column_drag_info; list; list = list->next)
3245 reorder = (PsppSheetViewColumnReorder *) list->data;
3246 if (mouse_x >= reorder->left_align && mouse_x < reorder->right_align)
3251 /* if (reorder && reorder == tree_view->priv->cur_reorder)
3254 tree_view->priv->cur_reorder = reorder;
3255 pspp_sheet_view_motion_draw_column_motion_arrow (tree_view);
3259 pspp_sheet_view_vertical_autoscroll (PsppSheetView *tree_view)
3261 GdkRectangle visible_rect;
3266 gdk_window_get_pointer (tree_view->priv->bin_window, NULL, &y, NULL);
3267 y += tree_view->priv->dy;
3269 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
3271 /* see if we are near the edge. */
3272 offset = y - (visible_rect.y + 2 * SCROLL_EDGE_SIZE);
3275 offset = y - (visible_rect.y + visible_rect.height - 2 * SCROLL_EDGE_SIZE);
3280 value = CLAMP (gtk_adjustment_get_value (tree_view->priv->vadjustment) + offset, 0.0,
3281 gtk_adjustment_get_upper (tree_view->priv->vadjustment) - gtk_adjustment_get_page_size (tree_view->priv->vadjustment));
3282 gtk_adjustment_set_value (tree_view->priv->vadjustment, value);
3286 pspp_sheet_view_horizontal_autoscroll (PsppSheetView *tree_view)
3288 GdkRectangle visible_rect;
3293 gdk_window_get_pointer (tree_view->priv->bin_window, &x, NULL, NULL);
3295 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
3297 /* See if we are near the edge. */
3298 offset = x - (visible_rect.x + SCROLL_EDGE_SIZE);
3301 offset = x - (visible_rect.x + visible_rect.width - SCROLL_EDGE_SIZE);
3307 value = CLAMP (gtk_adjustment_get_value (tree_view->priv->hadjustment) + offset,
3308 0.0, gtk_adjustment_get_upper (tree_view->priv->hadjustment) - gtk_adjustment_get_page_size (tree_view->priv->hadjustment));
3309 gtk_adjustment_set_value (tree_view->priv->hadjustment, value);
3316 pspp_sheet_view_motion_drag_column (GtkWidget *widget,
3317 GdkEventMotion *event)
3319 PsppSheetView *tree_view = (PsppSheetView *) widget;
3320 PsppSheetViewColumn *column = tree_view->priv->drag_column;
3322 GtkAllocation allocation;
3325 if ((column == NULL) ||
3326 (event->window != tree_view->priv->drag_window))
3329 /* Handle moving the header */
3330 gdk_window_get_position (tree_view->priv->drag_window, &x, &y);
3331 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
3332 x = CLAMP (x + (gint)event->x - column->drag_x, 0,
3333 MAX (tree_view->priv->width, allocation.width) - column->allocation.width);
3334 gdk_window_move (tree_view->priv->drag_window, x, y);
3336 /* autoscroll, if needed */
3337 pspp_sheet_view_horizontal_autoscroll (tree_view);
3338 /* Update the current reorder position and arrow; */
3339 pspp_sheet_view_update_current_reorder (tree_view);
3345 pspp_sheet_view_stop_rubber_band (PsppSheetView *tree_view)
3347 remove_scroll_timeout (tree_view);
3348 gtk_grab_remove (GTK_WIDGET (tree_view));
3350 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
3352 GtkTreePath *tmp_path;
3354 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
3356 /* The anchor path should be set to the start path */
3357 tmp_path = _pspp_sheet_view_find_path (tree_view,
3358 tree_view->priv->rubber_band_start_node);
3360 if (tree_view->priv->anchor)
3361 gtk_tree_row_reference_free (tree_view->priv->anchor);
3363 tree_view->priv->anchor =
3364 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
3365 tree_view->priv->model,
3368 gtk_tree_path_free (tmp_path);
3370 /* ... and the cursor to the end path */
3371 tmp_path = _pspp_sheet_view_find_path (tree_view,
3372 tree_view->priv->rubber_band_end_node);
3373 pspp_sheet_view_real_set_cursor (PSPP_SHEET_VIEW (tree_view), tmp_path, FALSE, FALSE, 0); /* XXX mode? */
3374 gtk_tree_path_free (tmp_path);
3376 _pspp_sheet_selection_emit_changed (tree_view->priv->selection);
3379 /* Clear status variables */
3380 tree_view->priv->rubber_band_status = RUBBER_BAND_OFF;
3381 tree_view->priv->rubber_band_shift = 0;
3382 tree_view->priv->rubber_band_ctrl = 0;
3384 tree_view->priv->rubber_band_start_node = -1;
3385 tree_view->priv->rubber_band_end_node = -1;
3389 pspp_sheet_view_update_rubber_band_selection_range (PsppSheetView *tree_view,
3393 gboolean skip_start,
3396 if (start_node == end_node)
3399 /* We skip the first node and jump inside the loop */
3405 /* Small optimization by assuming insensitive nodes are never
3410 if (tree_view->priv->rubber_band_shift)
3411 pspp_sheet_view_node_select (tree_view, start_node);
3412 else if (tree_view->priv->rubber_band_ctrl)
3414 /* Toggle the selection state */
3415 if (pspp_sheet_view_node_is_selected (tree_view, start_node))
3416 pspp_sheet_view_node_unselect (tree_view, start_node);
3418 pspp_sheet_view_node_select (tree_view, start_node);
3421 pspp_sheet_view_node_select (tree_view, start_node);
3425 /* Mirror the above */
3426 if (tree_view->priv->rubber_band_shift)
3427 pspp_sheet_view_node_unselect (tree_view, start_node);
3428 else if (tree_view->priv->rubber_band_ctrl)
3430 /* Toggle the selection state */
3431 if (pspp_sheet_view_node_is_selected (tree_view, start_node))
3432 pspp_sheet_view_node_unselect (tree_view, start_node);
3434 pspp_sheet_view_node_select (tree_view, start_node);
3437 pspp_sheet_view_node_unselect (tree_view, start_node);
3440 _pspp_sheet_view_queue_draw_node (tree_view, start_node, NULL);
3442 if (start_node == end_node)
3447 start_node = pspp_sheet_view_node_next (tree_view, start_node);
3450 /* Ran out of tree */
3453 if (skip_end && start_node == end_node)
3460 pspp_sheet_view_node_find_offset (PsppSheetView *tree_view,
3463 return node * tree_view->priv->fixed_height;
3467 pspp_sheet_view_find_offset (PsppSheetView *tree_view,
3471 int fixed_height = tree_view->priv->fixed_height;
3472 if (fixed_height <= 0
3474 || height >= tree_view->priv->row_count * fixed_height)
3481 *new_node = height / fixed_height;
3482 return height % fixed_height;
3487 pspp_sheet_view_update_rubber_band_selection (PsppSheetView *tree_view)
3492 pspp_sheet_view_find_offset (tree_view, MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y), &start_node);
3493 pspp_sheet_view_find_offset (tree_view, MAX (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y), &end_node);
3495 /* Handle the start area first */
3496 if (tree_view->priv->rubber_band_start_node < 0)
3498 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3505 else if (start_node < tree_view->priv->rubber_band_start_node)
3507 /* New node is above the old one; selection became bigger */
3508 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3510 tree_view->priv->rubber_band_start_node,
3515 else if (start_node > tree_view->priv->rubber_band_start_node)
3517 /* New node is below the old one; selection became smaller */
3518 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3519 tree_view->priv->rubber_band_start_node,
3526 tree_view->priv->rubber_band_start_node = start_node;
3528 /* Next, handle the end area */
3529 if (tree_view->priv->rubber_band_end_node < 0)
3531 /* In the event this happens, start_node was also -1; this case is
3535 else if (end_node < 0)
3537 /* Find the last node in the tree */
3538 pspp_sheet_view_find_offset (tree_view, tree_view->priv->height - 1,
3541 /* Selection reached end of the tree */
3542 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3543 tree_view->priv->rubber_band_end_node,
3549 else if (end_node > tree_view->priv->rubber_band_end_node)
3551 /* New node is below the old one; selection became bigger */
3552 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3553 tree_view->priv->rubber_band_end_node,
3559 else if (end_node < tree_view->priv->rubber_band_end_node)
3561 /* New node is above the old one; selection became smaller */
3562 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3564 tree_view->priv->rubber_band_end_node,
3570 tree_view->priv->rubber_band_end_node = end_node;
3573 #define GDK_RECTANGLE_PTR(X) ((GdkRectangle *)(X))
3576 pspp_sheet_view_update_rubber_band (PsppSheetView *tree_view)
3579 cairo_rectangle_int_t old_area;
3580 cairo_rectangle_int_t new_area;
3581 cairo_rectangle_int_t common;
3582 cairo_region_t *invalid_region;
3583 PsppSheetViewColumn *column;
3585 old_area.x = MIN (tree_view->priv->press_start_x, tree_view->priv->rubber_band_x);
3586 old_area.y = MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y) - tree_view->priv->dy;
3587 old_area.width = ABS (tree_view->priv->rubber_band_x - tree_view->priv->press_start_x) + 1;
3588 old_area.height = ABS (tree_view->priv->rubber_band_y - tree_view->priv->press_start_y) + 1;
3590 gdk_window_get_pointer (tree_view->priv->bin_window, &x, &y, NULL);
3593 y = MAX (y, 0) + tree_view->priv->dy;
3595 new_area.x = MIN (tree_view->priv->press_start_x, x);
3596 new_area.y = MIN (tree_view->priv->press_start_y, y) - tree_view->priv->dy;
3597 new_area.width = ABS (x - tree_view->priv->press_start_x) + 1;
3598 new_area.height = ABS (y - tree_view->priv->press_start_y) + 1;
3600 invalid_region = cairo_region_create_rectangle (&old_area);
3601 cairo_region_union_rectangle (invalid_region, &new_area);
3603 gdk_rectangle_intersect (GDK_RECTANGLE_PTR (&old_area),
3604 GDK_RECTANGLE_PTR (&new_area), GDK_RECTANGLE_PTR (&common));
3605 if (common.width > 2 && common.height > 2)
3607 cairo_region_t *common_region;
3609 /* make sure the border is invalidated */
3615 common_region = cairo_region_create_rectangle (&common);
3617 cairo_region_subtract (invalid_region, common_region);
3618 cairo_region_destroy (common_region);
3621 #if GTK_MAJOR_VERSION == 3
3622 gdk_window_invalidate_region (tree_view->priv->bin_window, invalid_region, TRUE);
3625 cairo_rectangle_int_t extents;
3627 cairo_region_get_extents (invalid_region, &extents);
3628 ereg = gdk_region_rectangle (GDK_RECTANGLE_PTR (&extents));
3629 gdk_window_invalidate_region (tree_view->priv->bin_window, ereg, TRUE);
3630 gdk_region_destroy (ereg);
3634 cairo_region_destroy (invalid_region);
3636 tree_view->priv->rubber_band_x = x;
3637 tree_view->priv->rubber_band_y = y;
3638 pspp_sheet_view_get_path_at_pos (tree_view, x, y, NULL, &column, NULL, NULL);
3640 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
3641 pspp_sheet_selection_select_column_range (tree_view->priv->selection,
3642 tree_view->priv->anchor_column,
3645 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
3647 pspp_sheet_view_update_rubber_band_selection (tree_view);
3652 pspp_sheet_view_paint_rubber_band (PsppSheetView *tree_view,
3657 GdkRectangle rubber_rect;
3661 rubber_rect.x = MIN (tree_view->priv->press_start_x, tree_view->priv->rubber_band_x);
3662 rubber_rect.y = MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y) - tree_view->priv->dy;
3663 rubber_rect.width = ABS (tree_view->priv->press_start_x - tree_view->priv->rubber_band_x) + 1;
3664 rubber_rect.height = ABS (tree_view->priv->press_start_y - tree_view->priv->rubber_band_y) + 1;
3666 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
3669 cr = gdk_cairo_create (tree_view->priv->bin_window);
3670 cairo_set_line_width (cr, 1.0);
3672 style = gtk_widget_get_style (GTK_WIDGET (tree_view));
3673 cairo_set_source_rgba (cr,
3674 style->fg[GTK_STATE_NORMAL].red / 65535.,
3675 style->fg[GTK_STATE_NORMAL].green / 65535.,
3676 style->fg[GTK_STATE_NORMAL].blue / 65535.,
3679 gdk_cairo_rectangle (cr, &rect);
3683 cairo_set_source_rgb (cr,
3684 style->fg[GTK_STATE_NORMAL].red / 65535.,
3685 style->fg[GTK_STATE_NORMAL].green / 65535.,
3686 style->fg[GTK_STATE_NORMAL].blue / 65535.);
3688 cairo_rectangle (cr,
3689 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
3690 rubber_rect.width - 1, rubber_rect.height - 1);
3699 pspp_sheet_view_motion_bin_window (GtkWidget *widget,
3700 GdkEventMotion *event)
3702 PsppSheetView *tree_view;
3706 tree_view = (PsppSheetView *) widget;
3708 if (tree_view->priv->row_count == 0)
3711 if (tree_view->priv->rubber_band_status == RUBBER_BAND_MAYBE_START)
3713 GdkRectangle background_area, cell_area;
3714 PsppSheetViewColumn *column;
3716 if (find_click (tree_view, event->x, event->y, &node, &column,
3717 &background_area, &cell_area)
3718 && tree_view->priv->focus_column == column
3719 && tree_view->priv->press_start_node == node)
3722 gtk_grab_add (GTK_WIDGET (tree_view));
3723 pspp_sheet_view_update_rubber_band (tree_view);
3725 tree_view->priv->rubber_band_status = RUBBER_BAND_ACTIVE;
3727 else if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
3729 pspp_sheet_view_update_rubber_band (tree_view);
3731 add_scroll_timeout (tree_view);
3734 /* only check for an initiated drag when a button is pressed */
3735 if (tree_view->priv->pressed_button >= 0
3736 && !tree_view->priv->rubber_band_status)
3737 pspp_sheet_view_maybe_begin_dragging_row (tree_view, event);
3739 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, event->y);
3743 pspp_sheet_view_find_offset (tree_view, new_y, &node);
3745 tree_view->priv->event_last_x = event->x;
3746 tree_view->priv->event_last_y = event->y;
3748 prelight_or_select (tree_view, node, event->x, event->y);
3754 pspp_sheet_view_motion (GtkWidget *widget,
3755 GdkEventMotion *event)
3757 PsppSheetView *tree_view;
3759 tree_view = (PsppSheetView *) widget;
3761 /* Resizing a column */
3762 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
3763 return pspp_sheet_view_motion_resize_column (widget, event);
3766 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
3767 return pspp_sheet_view_motion_drag_column (widget, event);
3769 /* Sanity check it */
3770 if (event->window == tree_view->priv->bin_window)
3771 return pspp_sheet_view_motion_bin_window (widget, event);
3776 /* Invalidate the focus rectangle near the edge of the bin_window; used when
3777 * the tree is empty.
3780 invalidate_empty_focus (PsppSheetView *tree_view)
3784 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
3789 area.width = gdk_window_get_width (tree_view->priv->bin_window);
3790 area.height = gdk_window_get_height (tree_view->priv->bin_window);
3791 gdk_window_invalidate_rect (tree_view->priv->bin_window, &area, FALSE);
3794 /* Draws a focus rectangle near the edge of the bin_window; used when the tree
3798 draw_empty_focus (PsppSheetView *tree_view)
3800 GtkWidget *widget = GTK_WIDGET (tree_view);
3802 cairo_t *cr = gdk_cairo_create (tree_view->priv->bin_window);
3804 if (!gtk_widget_has_focus (widget))
3807 w = gdk_window_get_width (tree_view->priv->bin_window);
3808 h = gdk_window_get_height (tree_view->priv->bin_window);
3814 gtk_paint_focus (gtk_widget_get_style (widget),
3816 gtk_widget_get_state (widget),
3824 pspp_sheet_view_draw_vertical_grid_lines (PsppSheetView *tree_view,
3826 gint n_visible_columns,
3830 GList *list = tree_view->priv->columns;
3833 if (tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
3834 && tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_BOTH)
3837 /* Only draw the lines for visible rows and columns */
3838 gboolean rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
3840 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
3842 list = (rtl ? list->prev : list->next))
3844 PsppSheetViewColumn *column = list->data;
3846 if (! column->visible)
3851 cairo_set_line_width (cr, 1.0);
3852 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
3853 cairo_move_to (cr, x + 0.5, min_y);
3854 cairo_line_to (cr, x + 0.5, max_y - min_y - 0.5);
3859 /* Warning: Very scary function.
3860 * Modify at your own risk
3862 * KEEP IN SYNC WITH pspp_sheet_view_create_row_drag_icon()!
3863 * FIXME: It's not...
3866 pspp_sheet_view_draw_bin (GtkWidget *widget,
3869 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
3874 int drag_highlight = -1;
3877 gint y_offset, cell_offset;
3879 GdkRectangle background_area;
3880 GdkRectangle cell_area;
3882 gint bin_window_width;
3883 gint bin_window_height;
3884 GtkTreePath *cursor_path;
3885 GtkTreePath *drag_dest_path;
3886 GList *first_column, *last_column;
3887 gint vertical_separator;
3888 gint horizontal_separator;
3889 gint focus_line_width;
3890 gboolean allow_rules;
3892 gint n_visible_columns;
3893 gint grid_line_width;
3894 gboolean row_ending_details;
3895 gboolean draw_vgrid_lines, draw_hgrid_lines;
3897 GtkStyleContext *context;
3898 context = gtk_widget_get_style_context (widget);
3901 GtkAllocation allocation;
3902 gtk_widget_get_allocation (widget, &allocation);
3904 GdkRectangle exposed_rect;
3905 gdk_cairo_get_clip_rectangle (cr, &exposed_rect);
3909 Zarea.height = allocation.height;
3911 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
3913 gtk_widget_style_get (widget,
3914 "horizontal-separator", &horizontal_separator,
3915 "vertical-separator", &vertical_separator,
3916 "allow-rules", &allow_rules,
3917 "focus-line-width", &focus_line_width,
3918 "row-ending-details", &row_ending_details,
3921 if (tree_view->priv->row_count == 0)
3923 draw_empty_focus (tree_view);
3928 /* clip event->area to the visible area */
3929 if (Zarea.height < 0.5)
3933 validate_visible_area (tree_view);
3935 new_y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, Zarea.y);
3939 y_offset = -pspp_sheet_view_find_offset (tree_view, new_y, &node);
3941 gdk_window_get_width (tree_view->priv->bin_window);
3944 gdk_window_get_height (tree_view->priv->bin_window);
3947 if (tree_view->priv->height < bin_window_height)
3949 gtk_paint_flat_box (gtk_widget_get_style (widget),
3951 gtk_widget_get_state (widget),
3955 0, tree_view->priv->height,
3957 bin_window_height - tree_view->priv->height);
3963 /* find the path for the node */
3964 path = _pspp_sheet_view_find_path ((PsppSheetView *)widget, node);
3965 gtk_tree_model_get_iter (tree_view->priv->model,
3968 gtk_tree_path_free (path);
3971 drag_dest_path = NULL;
3973 if (tree_view->priv->cursor)
3974 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
3977 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor);
3979 if (tree_view->priv->drag_dest_row)
3980 drag_dest_path = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
3983 _pspp_sheet_view_find_node (tree_view, drag_dest_path,
3987 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
3988 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
3990 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
3991 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
3993 if (draw_vgrid_lines || draw_hgrid_lines)
3994 gtk_widget_style_get (widget, "grid-line-width", &grid_line_width, NULL);
3996 n_visible_columns = 0;
3997 for (list = tree_view->priv->columns; list; list = list->next)
3999 if (! PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
4001 n_visible_columns ++;
4004 /* Find the last column */
4005 for (last_column = g_list_last (tree_view->priv->columns);
4006 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
4007 last_column = last_column->prev)
4011 for (first_column = g_list_first (tree_view->priv->columns);
4012 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
4013 first_column = first_column->next)
4016 /* Actually process the expose event. To do this, we want to
4017 * start at the first node of the event, and walk the tree in
4018 * order, drawing each successive node.
4025 gboolean is_first = FALSE;
4026 gboolean is_last = FALSE;
4027 gboolean done = FALSE;
4030 max_height = ROW_HEIGHT (tree_view);
4034 background_area.y = y_offset + Zarea.y;
4035 background_area.height = max_height;
4036 max_y = background_area.y + max_height;
4040 if (node == tree_view->priv->prelight_node)
4041 flags |= GTK_CELL_RENDERER_PRELIT;
4043 selected = pspp_sheet_view_node_is_selected (tree_view, node);
4047 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
4049 list = (rtl ? list->prev : list->next))
4051 PsppSheetViewColumn *column = list->data;
4052 const gchar *detail = NULL;
4053 gboolean selected_column;
4056 if (!column->visible)
4059 if (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE)
4060 selected_column = column->selected && column->selectable;
4062 selected_column = TRUE;
4065 if (cell_offset > Zarea.x + Zarea.width ||
4066 cell_offset + column->width < Zarea.x)
4068 cell_offset += column->width;
4073 if (selected && selected_column)
4074 flags |= GTK_CELL_RENDERER_SELECTED;
4076 flags &= ~GTK_CELL_RENDERER_SELECTED;
4078 if (column->show_sort_indicator)
4079 flags |= GTK_CELL_RENDERER_SORTED;
4081 flags &= ~GTK_CELL_RENDERER_SORTED;
4084 flags |= GTK_CELL_RENDERER_FOCUSED;
4086 flags &= ~GTK_CELL_RENDERER_FOCUSED;
4088 background_area.x = cell_offset;
4089 background_area.width = column->width;
4091 cell_area = background_area;
4092 cell_area.y += vertical_separator / 2;
4093 cell_area.x += horizontal_separator / 2;
4094 cell_area.height -= vertical_separator;
4095 cell_area.width -= horizontal_separator;
4097 if (draw_vgrid_lines)
4099 if (list == first_column)
4101 cell_area.width -= grid_line_width / 2;
4103 else if (list == last_column)
4105 cell_area.x += grid_line_width / 2;
4106 cell_area.width -= grid_line_width / 2;
4110 cell_area.x += grid_line_width / 2;
4111 cell_area.width -= grid_line_width;
4115 if (draw_hgrid_lines)
4117 cell_area.y += grid_line_width / 2;
4118 cell_area.height -= grid_line_width;
4122 if (gdk_region_rect_in (event->region, &background_area) == GDK_OVERLAP_RECTANGLE_OUT)
4124 if (!gdk_rectangle_intersect (&background_area, &exposed_rect, NULL))
4127 cell_offset += column->width;
4132 pspp_sheet_view_column_cell_set_cell_data (column,
4133 tree_view->priv->model,
4136 /* Select the detail for drawing the cell. relevant
4137 * factors are parity, sortedness, and whether to
4140 if (allow_rules && tree_view->priv->has_rules)
4142 if ((flags & GTK_CELL_RENDERER_SORTED) &&
4143 n_visible_columns >= 3)
4146 detail = "cell_odd_ruled_sorted";
4148 detail = "cell_even_ruled_sorted";
4153 detail = "cell_odd_ruled";
4155 detail = "cell_even_ruled";
4160 if ((flags & GTK_CELL_RENDERER_SORTED) &&
4161 n_visible_columns >= 3)
4164 detail = "cell_odd_sorted";
4166 detail = "cell_even_sorted";
4171 detail = "cell_odd";
4173 detail = "cell_even";
4179 gtk_style_context_save (context);
4180 state = gtk_cell_renderer_get_state (NULL, widget, flags);
4181 gtk_style_context_set_state (context, state);
4182 gtk_style_context_add_class (context, GTK_STYLE_CLASS_CELL);
4184 /* Draw background */
4185 gtk_render_background (context, cr,
4188 background_area.width,
4189 background_area.height);
4192 gtk_render_frame (context, cr,
4195 background_area.width,
4196 background_area.height);
4198 if (draw_hgrid_lines)
4200 cairo_set_line_width (cr, 1.0);
4201 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
4203 if (background_area.y >= 0)
4206 gdk_draw_line (event->window,
4207 tree_view->priv->grid_line_gc[widget->state],
4208 background_area.x, background_area.y,
4209 background_area.x + background_area.width,
4212 cairo_move_to (cr, background_area.x, background_area.y - 0.5);
4213 cairo_line_to (cr, background_area.x + background_area.width,
4214 background_area.y - 0.5);
4218 if (y_offset + max_height <= Zarea.height - 0.5)
4221 gdk_draw_line (event->window,
4222 tree_view->priv->grid_line_gc[widget->state],
4223 background_area.x, background_area.y + max_height,
4224 background_area.x + background_area.width,
4225 background_area.y + max_height);
4228 cairo_move_to (cr, background_area.x, background_area.y + max_height - 0.5);
4229 cairo_line_to (cr, background_area.x + background_area.width,
4230 background_area.y + max_height - 0.5);
4236 _pspp_sheet_view_column_cell_render (column,
4243 cell_offset += column->width;
4244 gtk_style_context_restore (context);
4247 if (node == drag_highlight)
4249 /* Draw indicator for the drop
4251 gint highlight_y = -1;
4255 switch (tree_view->priv->drag_dest_pos)
4257 case PSPP_SHEET_VIEW_DROP_BEFORE:
4258 highlight_y = background_area.y - 1;
4259 if (highlight_y < 0)
4263 case PSPP_SHEET_VIEW_DROP_AFTER:
4264 highlight_y = background_area.y + background_area.height - 1;
4267 case PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE:
4268 case PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER:
4269 _pspp_sheet_view_find_node (tree_view, drag_dest_path, &node);
4273 width = gdk_window_get_width (tree_view->priv->bin_window);
4275 if (row_ending_details)
4276 gtk_paint_focus (gtk_widget_get_style (widget),
4278 gtk_widget_get_state (widget),
4281 ? (is_last ? "treeview-drop-indicator" : "treeview-drop-indicator-left" )
4282 : (is_last ? "treeview-drop-indicator-right" : "tree-view-drop-indicator-middle" )),
4283 0, BACKGROUND_FIRST_PIXEL (tree_view, node)
4284 - focus_line_width / 2,
4285 width, ROW_HEIGHT (tree_view)
4286 - focus_line_width + 1);
4288 gtk_paint_focus (gtk_widget_get_style (widget),
4290 gtk_widget_get_state (widget),
4292 "treeview-drop-indicator",
4293 0, BACKGROUND_FIRST_PIXEL (tree_view, node)
4294 - focus_line_width / 2,
4295 width, ROW_HEIGHT (tree_view)
4296 - focus_line_width + 1);
4301 if (highlight_y >= 0)
4303 gdk_draw_line (event->window,
4304 widget->style->fg_gc[gtk_widget_get_state (widget)],
4307 rtl ? 0 : bin_window_width,
4313 y_offset += max_height;
4317 node = pspp_sheet_view_node_next (tree_view, node);
4320 gboolean has_next = gtk_tree_model_iter_next (tree_view->priv->model, &iter);
4324 TREE_VIEW_INTERNAL_ASSERT_VOID (has_next);
4331 while (y_offset < Zarea.height);
4334 pspp_sheet_view_draw_vertical_grid_lines (tree_view, cr, n_visible_columns,
4338 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
4340 GdkRectangle *rectangles;
4343 gdk_region_get_rectangles (event->region,
4347 while (n_rectangles--)
4348 pspp_sheet_view_paint_rubber_band (tree_view, &rectangles[n_rectangles]);
4350 g_free (rectangles);
4355 gtk_tree_path_free (cursor_path);
4358 gtk_tree_path_free (drag_dest_path);
4365 pspp_sheet_view_draw (GtkWidget *widget,
4368 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4369 GtkStyleContext *context;
4371 context = gtk_widget_get_style_context (widget);
4373 if (gtk_cairo_should_draw_window (cr, tree_view->priv->bin_window))
4378 gtk_cairo_transform_to_window(cr,widget,tree_view->priv->bin_window);
4379 pspp_sheet_view_draw_bin (widget, cr);
4382 /* We can't just chain up to Container::expose as it will try to send the
4383 * event to the headers, so we handle propagating it to our children
4384 * (eg. widgets being edited) ourselves.
4386 tmp_list = tree_view->priv->children;
4389 PsppSheetViewChild *child = tmp_list->data;
4390 tmp_list = tmp_list->next;
4392 gtk_container_propagate_draw (GTK_CONTAINER (tree_view), child->widget, cr);
4397 gtk_render_background (context, cr,
4399 gtk_widget_get_allocated_width (widget),
4400 gtk_widget_get_allocated_height (widget));
4403 gtk_style_context_save (context);
4404 gtk_style_context_remove_class (context, GTK_STYLE_CLASS_VIEW);
4406 if (gtk_cairo_should_draw_window (cr, tree_view->priv->header_window))
4408 gint n_visible_columns;
4411 for (list = tree_view->priv->columns; list != NULL; list = list->next)
4413 PsppSheetViewColumn *column = list->data;
4415 if (column == tree_view->priv->drag_column || !column->visible)
4418 if (span_intersects (column->allocation.x, column->allocation.width,
4419 (int) gtk_adjustment_get_value (tree_view->priv->hadjustment),
4420 (int) gtk_widget_get_allocated_width (widget))
4421 && column->button != NULL)
4422 gtk_container_propagate_draw (GTK_CONTAINER (tree_view),
4423 column->button, cr);
4426 n_visible_columns = 0;
4427 for (list = tree_view->priv->columns; list; list = list->next)
4429 if (! PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
4431 n_visible_columns ++;
4434 gtk_cairo_transform_to_window(cr,widget,tree_view->priv->header_window);
4435 pspp_sheet_view_draw_vertical_grid_lines (tree_view,
4439 TREE_VIEW_HEADER_HEIGHT (tree_view));
4442 if (tree_view->priv->drag_window &&
4443 gtk_cairo_should_draw_window (cr, tree_view->priv->drag_window))
4445 gtk_container_propagate_draw (GTK_CONTAINER (tree_view),
4446 tree_view->priv->drag_column->button,
4450 gtk_style_context_restore (context);
4462 /* returns 0x1 when no column has been found -- yes it's hackish */
4463 static PsppSheetViewColumn *
4464 pspp_sheet_view_get_drop_column (PsppSheetView *tree_view,
4465 PsppSheetViewColumn *column,
4468 PsppSheetViewColumn *left_column = NULL;
4469 PsppSheetViewColumn *cur_column = NULL;
4472 if (!column->reorderable)
4473 return (PsppSheetViewColumn *)0x1;
4475 switch (drop_position)
4478 /* find first column where we can drop */
4479 tmp_list = tree_view->priv->columns;
4480 if (column == PSPP_SHEET_VIEW_COLUMN (tmp_list->data))
4481 return (PsppSheetViewColumn *)0x1;
4485 g_assert (tmp_list);
4487 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4488 tmp_list = tmp_list->next;
4490 if (left_column && left_column->visible == FALSE)
4493 if (!tree_view->priv->column_drop_func)
4496 if (!tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4498 left_column = cur_column;
4505 if (!tree_view->priv->column_drop_func)
4508 if (tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data))
4511 return (PsppSheetViewColumn *)0x1;
4515 /* find first column after column where we can drop */
4516 tmp_list = tree_view->priv->columns;
4518 for (; tmp_list; tmp_list = tmp_list->next)
4519 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data) == column)
4522 if (!tmp_list || !tmp_list->next)
4523 return (PsppSheetViewColumn *)0x1;
4525 tmp_list = tmp_list->next;
4526 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4527 tmp_list = tmp_list->next;
4531 g_assert (tmp_list);
4533 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4534 tmp_list = tmp_list->next;
4536 if (left_column && left_column->visible == FALSE)
4538 left_column = cur_column;
4540 tmp_list = tmp_list->next;
4544 if (!tree_view->priv->column_drop_func)
4547 if (!tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4549 left_column = cur_column;
4556 if (!tree_view->priv->column_drop_func)
4559 if (tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data))
4562 return (PsppSheetViewColumn *)0x1;
4566 /* find first column before column where we can drop */
4567 tmp_list = tree_view->priv->columns;
4569 for (; tmp_list; tmp_list = tmp_list->next)
4570 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data) == column)
4573 if (!tmp_list || !tmp_list->prev)
4574 return (PsppSheetViewColumn *)0x1;
4576 tmp_list = tmp_list->prev;
4577 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4578 tmp_list = tmp_list->prev;
4582 g_assert (tmp_list);
4584 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4586 if (left_column && !left_column->visible)
4588 /*if (!tmp_list->prev)
4589 return (PsppSheetViewColumn *)0x1;
4592 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->prev->data);
4593 tmp_list = tmp_list->prev->prev;
4596 cur_column = left_column;
4598 tmp_list = tmp_list->prev;
4602 if (!tree_view->priv->column_drop_func)
4605 if (tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4608 cur_column = left_column;
4609 tmp_list = tmp_list->prev;
4612 if (!tree_view->priv->column_drop_func)
4615 if (tree_view->priv->column_drop_func (tree_view, column, NULL, cur_column, tree_view->priv->column_drop_func_data))
4618 return (PsppSheetViewColumn *)0x1;
4622 /* same as DROP_HOME case, but doing it backwards */
4623 tmp_list = g_list_last (tree_view->priv->columns);
4626 if (column == PSPP_SHEET_VIEW_COLUMN (tmp_list->data))
4627 return (PsppSheetViewColumn *)0x1;
4631 g_assert (tmp_list);
4633 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4635 if (left_column && !left_column->visible)
4637 cur_column = left_column;
4638 tmp_list = tmp_list->prev;
4641 if (!tree_view->priv->column_drop_func)
4644 if (tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4647 cur_column = left_column;
4648 tmp_list = tmp_list->prev;
4651 if (!tree_view->priv->column_drop_func)
4654 if (tree_view->priv->column_drop_func (tree_view, column, NULL, cur_column, tree_view->priv->column_drop_func_data))
4657 return (PsppSheetViewColumn *)0x1;
4661 return (PsppSheetViewColumn *)0x1;
4665 pspp_sheet_view_key_press (GtkWidget *widget,
4668 PsppSheetView *tree_view = (PsppSheetView *) widget;
4670 if (tree_view->priv->rubber_band_status)
4672 if (event->keyval == GDK_Escape)
4673 pspp_sheet_view_stop_rubber_band (tree_view);
4678 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
4680 if (event->keyval == GDK_Escape)
4682 tree_view->priv->cur_reorder = NULL;
4683 pspp_sheet_view_button_release_drag_column (widget, NULL);
4688 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
4690 GList *focus_column;
4693 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
4695 for (focus_column = tree_view->priv->columns;
4697 focus_column = focus_column->next)
4699 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4701 if (column->button && gtk_widget_has_focus (column->button))
4706 (event->state & GDK_SHIFT_MASK) && (event->state & GDK_MOD1_MASK) &&
4707 (event->keyval == GDK_Left || event->keyval == GDK_KP_Left
4708 || event->keyval == GDK_Right || event->keyval == GDK_KP_Right))
4710 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4712 if (!column->resizable)
4714 gtk_widget_error_bell (widget);
4718 if (event->keyval == (rtl ? GDK_Right : GDK_Left)
4719 || event->keyval == (rtl ? GDK_KP_Right : GDK_KP_Left))
4721 gint old_width = column->resized_width;
4723 column->resized_width = MAX (column->resized_width,
4725 column->resized_width -= 2;
4726 if (column->resized_width < 0)
4727 column->resized_width = 0;
4729 if (column->min_width == -1)
4730 column->resized_width = MAX (column->button_request,
4731 column->resized_width);
4733 column->resized_width = MAX (column->min_width,
4734 column->resized_width);
4736 if (column->max_width != -1)
4737 column->resized_width = MIN (column->resized_width,
4740 column->use_resized_width = TRUE;
4742 if (column->resized_width != old_width)
4743 gtk_widget_queue_resize (widget);
4745 gtk_widget_error_bell (widget);
4747 else if (event->keyval == (rtl ? GDK_Left : GDK_Right)
4748 || event->keyval == (rtl ? GDK_KP_Left : GDK_KP_Right))
4750 gint old_width = column->resized_width;
4752 column->resized_width = MAX (column->resized_width,
4754 column->resized_width += 2;
4756 if (column->max_width != -1)
4757 column->resized_width = MIN (column->resized_width,
4760 column->use_resized_width = TRUE;
4762 if (column->resized_width != old_width)
4763 gtk_widget_queue_resize (widget);
4765 gtk_widget_error_bell (widget);
4772 (event->state & GDK_MOD1_MASK) &&
4773 (event->keyval == GDK_Left || event->keyval == GDK_KP_Left
4774 || event->keyval == GDK_Right || event->keyval == GDK_KP_Right
4775 || event->keyval == GDK_Home || event->keyval == GDK_KP_Home
4776 || event->keyval == GDK_End || event->keyval == GDK_KP_End))
4778 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4780 if (event->keyval == (rtl ? GDK_Right : GDK_Left)
4781 || event->keyval == (rtl ? GDK_KP_Right : GDK_KP_Left))
4783 PsppSheetViewColumn *col;
4784 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_LEFT);
4785 if (col != (PsppSheetViewColumn *)0x1)
4786 pspp_sheet_view_move_column_after (tree_view, column, col);
4788 gtk_widget_error_bell (widget);
4790 else if (event->keyval == (rtl ? GDK_Left : GDK_Right)
4791 || event->keyval == (rtl ? GDK_KP_Left : GDK_KP_Right))
4793 PsppSheetViewColumn *col;
4794 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_RIGHT);
4795 if (col != (PsppSheetViewColumn *)0x1)
4796 pspp_sheet_view_move_column_after (tree_view, column, col);
4798 gtk_widget_error_bell (widget);
4800 else if (event->keyval == GDK_Home || event->keyval == GDK_KP_Home)
4802 PsppSheetViewColumn *col;
4803 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_HOME);
4804 if (col != (PsppSheetViewColumn *)0x1)
4805 pspp_sheet_view_move_column_after (tree_view, column, col);
4807 gtk_widget_error_bell (widget);
4809 else if (event->keyval == GDK_End || event->keyval == GDK_KP_End)
4811 PsppSheetViewColumn *col;
4812 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_END);
4813 if (col != (PsppSheetViewColumn *)0x1)
4814 pspp_sheet_view_move_column_after (tree_view, column, col);
4816 gtk_widget_error_bell (widget);
4823 /* Chain up to the parent class. It handles the keybindings. */
4824 if (GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->key_press_event (widget, event))
4827 if (tree_view->priv->search_entry_avoid_unhandled_binding)
4829 tree_view->priv->search_entry_avoid_unhandled_binding = FALSE;
4833 /* We pass the event to the search_entry. If its text changes, then we start
4834 * the typeahead find capabilities. */
4835 if (gtk_widget_has_focus (GTK_WIDGET (tree_view))
4836 && tree_view->priv->enable_search
4837 && !tree_view->priv->search_custom_entry_set)
4839 GdkEvent *new_event;
4841 const char *new_text;
4844 gboolean text_modified;
4845 gulong popup_menu_id;
4847 pspp_sheet_view_ensure_interactive_directory (tree_view);
4849 /* Make a copy of the current text */
4850 old_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry)));
4851 new_event = gdk_event_copy ((GdkEvent *) event);
4852 g_object_unref (((GdkEventKey *) new_event)->window);
4853 ((GdkEventKey *) new_event)->window = g_object_ref (gtk_widget_get_window (tree_view->priv->search_window));
4854 gtk_widget_realize (tree_view->priv->search_window);
4856 popup_menu_id = g_signal_connect (tree_view->priv->search_entry,
4857 "popup-menu", G_CALLBACK (gtk_true),
4860 /* Move the entry off screen */
4861 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
4862 gtk_window_move (GTK_WINDOW (tree_view->priv->search_window),
4863 gdk_screen_get_width (screen) + 1,
4864 gdk_screen_get_height (screen) + 1);
4865 gtk_widget_show (tree_view->priv->search_window);
4867 /* Send the event to the window. If the preedit_changed signal is emitted
4868 * during this event, we will set priv->imcontext_changed */
4869 tree_view->priv->imcontext_changed = FALSE;
4870 retval = gtk_widget_event (tree_view->priv->search_window, new_event);
4871 gdk_event_free (new_event);
4872 gtk_widget_hide (tree_view->priv->search_window);
4874 g_signal_handler_disconnect (tree_view->priv->search_entry,
4877 /* We check to make sure that the entry tried to handle the text, and that
4878 * the text has changed.
4880 new_text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
4881 text_modified = strcmp (old_text, new_text) != 0;
4883 if (tree_view->priv->imcontext_changed || /* we're in a preedit */
4884 (retval && text_modified)) /* ...or the text was modified */
4886 if (pspp_sheet_view_real_start_interactive_search (tree_view, FALSE))
4888 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
4893 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
4903 pspp_sheet_view_key_release (GtkWidget *widget,
4906 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4908 if (tree_view->priv->rubber_band_status)
4911 return GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->key_release_event (widget, event);
4914 /* FIXME Is this function necessary? Can I get an enter_notify event
4915 * w/o either an expose event or a mouse motion event?
4918 pspp_sheet_view_enter_notify (GtkWidget *widget,
4919 GdkEventCrossing *event)
4921 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4925 /* Sanity check it */
4926 if (event->window != tree_view->priv->bin_window)
4929 if (tree_view->priv->row_count == 0)
4932 if (event->mode == GDK_CROSSING_GRAB ||
4933 event->mode == GDK_CROSSING_GTK_GRAB ||
4934 event->mode == GDK_CROSSING_GTK_UNGRAB ||
4935 event->mode == GDK_CROSSING_STATE_CHANGED)
4938 /* find the node internally */
4939 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, event->y);
4942 pspp_sheet_view_find_offset (tree_view, new_y, &node);
4944 tree_view->priv->event_last_x = event->x;
4945 tree_view->priv->event_last_y = event->y;
4947 prelight_or_select (tree_view, node, event->x, event->y);
4953 pspp_sheet_view_leave_notify (GtkWidget *widget,
4954 GdkEventCrossing *event)
4956 PsppSheetView *tree_view;
4958 if (event->mode == GDK_CROSSING_GRAB)
4961 tree_view = PSPP_SHEET_VIEW (widget);
4963 if (tree_view->priv->prelight_node >= 0)
4964 _pspp_sheet_view_queue_draw_node (tree_view,
4965 tree_view->priv->prelight_node,
4968 tree_view->priv->event_last_x = -10000;
4969 tree_view->priv->event_last_y = -10000;
4971 prelight_or_select (tree_view,
4973 -1000, -1000); /* coords not possibly over an arrow */
4980 pspp_sheet_view_focus_out (GtkWidget *widget,
4981 GdkEventFocus *event)
4983 PsppSheetView *tree_view;
4985 tree_view = PSPP_SHEET_VIEW (widget);
4987 gtk_widget_queue_draw (widget);
4989 /* destroy interactive search dialog */
4990 if (tree_view->priv->search_window)
4991 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
4997 /* Incremental Reflow
5001 pspp_sheet_view_node_queue_redraw (PsppSheetView *tree_view,
5004 GtkAllocation allocation;
5005 gint y = pspp_sheet_view_node_find_offset (tree_view, node)
5006 - gtk_adjustment_get_value (tree_view->priv->vadjustment)
5007 + TREE_VIEW_HEADER_HEIGHT (tree_view);
5009 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
5011 gtk_widget_queue_draw_area (GTK_WIDGET (tree_view),
5014 tree_view->priv->fixed_height);
5018 node_is_visible (PsppSheetView *tree_view,
5024 y = pspp_sheet_view_node_find_offset (tree_view, node);
5025 height = ROW_HEIGHT (tree_view);
5027 if (y >= gtk_adjustment_get_value (tree_view->priv->vadjustment) &&
5028 y + height <= (gtk_adjustment_get_value (tree_view->priv->vadjustment)
5029 + gtk_adjustment_get_page_size (tree_view->priv->vadjustment)))
5035 /* Returns the row height. */
5037 validate_row (PsppSheetView *tree_view,
5042 PsppSheetViewColumn *column;
5043 GList *list, *first_column, *last_column;
5045 gint horizontal_separator;
5046 gint vertical_separator;
5047 gint focus_line_width;
5048 gboolean draw_vgrid_lines, draw_hgrid_lines;
5050 gint grid_line_width;
5051 gboolean wide_separators;
5052 gint separator_height;
5054 gtk_widget_style_get (GTK_WIDGET (tree_view),
5055 "focus-padding", &focus_pad,
5056 "focus-line-width", &focus_line_width,
5057 "horizontal-separator", &horizontal_separator,
5058 "vertical-separator", &vertical_separator,
5059 "grid-line-width", &grid_line_width,
5060 "wide-separators", &wide_separators,
5061 "separator-height", &separator_height,
5065 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
5066 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
5068 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
5069 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
5071 for (last_column = g_list_last (tree_view->priv->columns);
5072 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
5073 last_column = last_column->prev)
5076 for (first_column = g_list_first (tree_view->priv->columns);
5077 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
5078 first_column = first_column->next)
5081 for (list = tree_view->priv->columns; list; list = list->next)
5086 column = list->data;
5088 if (! column->visible)
5091 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, iter);
5092 pspp_sheet_view_column_cell_get_size (column,
5094 &tmp_width, &tmp_height);
5096 tmp_height += vertical_separator;
5097 height = MAX (height, tmp_height);
5099 tmp_width = tmp_width + horizontal_separator;
5101 if (draw_vgrid_lines)
5103 if (list->data == first_column || list->data == last_column)
5104 tmp_width += grid_line_width / 2.0;
5106 tmp_width += grid_line_width;
5109 if (tmp_width > column->requested_width)
5110 column->requested_width = tmp_width;
5113 if (draw_hgrid_lines)
5114 height += grid_line_width;
5116 tree_view->priv->post_validation_flag = TRUE;
5122 validate_visible_area (PsppSheetView *tree_view)
5124 GtkTreePath *path = NULL;
5125 GtkTreePath *above_path = NULL;
5129 gint area_above = 0;
5130 gint area_below = 0;
5131 GtkAllocation allocation;
5133 if (tree_view->priv->row_count == 0)
5136 if (tree_view->priv->scroll_to_path == NULL)
5139 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
5141 total_height = allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
5143 if (total_height == 0)
5146 path = gtk_tree_row_reference_get_path (tree_view->priv->scroll_to_path);
5149 /* we are going to scroll, and will update dy */
5150 _pspp_sheet_view_find_node (tree_view, path, &node);
5151 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
5153 if (tree_view->priv->scroll_to_use_align)
5155 gint height = ROW_HEIGHT (tree_view);
5156 area_above = (total_height - height) *
5157 tree_view->priv->scroll_to_row_align;
5158 area_below = total_height - area_above - height;
5159 area_above = MAX (area_above, 0);
5160 area_below = MAX (area_below, 0);
5165 * 1) row not visible
5169 gint height = ROW_HEIGHT (tree_view);
5171 dy = pspp_sheet_view_node_find_offset (tree_view, node);
5173 if (dy >= gtk_adjustment_get_value (tree_view->priv->vadjustment) &&
5174 dy + height <= (gtk_adjustment_get_value (tree_view->priv->vadjustment)
5175 + gtk_adjustment_get_page_size (tree_view->priv->vadjustment)))
5177 /* row visible: keep the row at the same position */
5178 area_above = dy - gtk_adjustment_get_value (tree_view->priv->vadjustment);
5179 area_below = (gtk_adjustment_get_value (tree_view->priv->vadjustment) +
5180 gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
5185 /* row not visible */
5187 && dy + height <= gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
5189 /* row at the beginning -- fixed */
5191 area_below = gtk_adjustment_get_page_size (tree_view->priv->vadjustment)
5192 - area_above - height;
5194 else if (dy >= (gtk_adjustment_get_upper (tree_view->priv->vadjustment) -
5195 gtk_adjustment_get_page_size (tree_view->priv->vadjustment)))
5197 /* row at the end -- fixed */
5198 area_above = dy - (gtk_adjustment_get_upper (tree_view->priv->vadjustment) -
5199 gtk_adjustment_get_page_size (tree_view->priv->vadjustment));
5200 area_below = gtk_adjustment_get_page_size (tree_view->priv->vadjustment) -
5201 area_above - height;
5205 area_above = gtk_adjustment_get_page_size (tree_view->priv->vadjustment) - height;
5211 /* row somewhere in the middle, bring it to the top
5215 area_below = total_height - height;
5221 /* the scroll to isn't valid; ignore it.
5224 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
5225 tree_view->priv->scroll_to_path = NULL;
5229 above_path = gtk_tree_path_copy (path);
5231 /* Now, we walk forwards and backwards, measuring rows. Unfortunately,
5232 * backwards is much slower then forward, as there is no iter_prev function.
5233 * We go forwards first in case we run out of tree. Then we go backwards to
5236 while (node >= 0 && area_below > 0)
5238 gboolean done = FALSE;
5241 node = pspp_sheet_view_node_next (tree_view, node);
5244 gboolean has_next = gtk_tree_model_iter_next (tree_view->priv->model, &iter);
5246 gtk_tree_path_next (path);
5249 TREE_VIEW_INTERNAL_ASSERT_VOID (has_next);
5259 area_below -= ROW_HEIGHT (tree_view);
5261 gtk_tree_path_free (path);
5263 /* If we ran out of tree, and have extra area_below left, we need to add it
5266 area_above += area_below;
5268 _pspp_sheet_view_find_node (tree_view, above_path, &node);
5270 /* We walk backwards */
5271 while (area_above > 0)
5273 node = pspp_sheet_view_node_prev (tree_view, node);
5275 /* Always find the new path in the tree. We cannot just assume
5276 * a gtk_tree_path_prev() is enough here, as there might be children
5277 * in between this node and the previous sibling node. If this
5278 * appears to be a performance hotspot in profiles, we can look into
5279 * intrigate logic for keeping path, node and iter in sync like
5280 * we do for forward walks. (Which will be hard because of the lacking
5287 gtk_tree_path_free (above_path);
5288 above_path = _pspp_sheet_view_find_path (tree_view, node);
5290 gtk_tree_model_get_iter (tree_view->priv->model, &iter, above_path);
5292 area_above -= ROW_HEIGHT (tree_view);
5295 /* set the dy here to scroll to the path,
5296 * and sync the top row accordingly
5298 pspp_sheet_view_set_top_row (tree_view, above_path, -area_above);
5299 pspp_sheet_view_top_row_to_dy (tree_view);
5301 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
5302 tree_view->priv->scroll_to_path = NULL;
5305 gtk_tree_path_free (above_path);
5307 if (tree_view->priv->scroll_to_column)
5309 tree_view->priv->scroll_to_column = NULL;
5311 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
5315 initialize_fixed_height_mode (PsppSheetView *tree_view)
5317 if (!tree_view->priv->row_count)
5320 if (tree_view->priv->fixed_height_set)
5323 if (tree_view->priv->fixed_height < 0)
5330 path = _pspp_sheet_view_find_path (tree_view, node);
5331 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
5333 tree_view->priv->fixed_height = validate_row (tree_view, node, &iter, path);
5335 gtk_tree_path_free (path);
5337 g_object_notify (G_OBJECT (tree_view), "fixed-height");
5341 /* Our strategy for finding nodes to validate is a little convoluted. We find
5342 * the left-most uninvalidated node. We then try walking right, validating
5343 * nodes. Once we find a valid node, we repeat the previous process of finding
5344 * the first invalid node.
5348 validate_rows_handler (PsppSheetView *tree_view)
5350 initialize_fixed_height_mode (tree_view);
5351 if (tree_view->priv->validate_rows_timer)
5353 g_source_remove (tree_view->priv->validate_rows_timer);
5354 tree_view->priv->validate_rows_timer = 0;
5361 do_presize_handler (PsppSheetView *tree_view)
5363 GtkRequisition requisition;
5365 validate_visible_area (tree_view);
5366 tree_view->priv->presize_handler_timer = 0;
5368 if (! gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5371 gtk_widget_get_preferred_size (GTK_WIDGET (tree_view), NULL, &requisition);
5373 gtk_adjustment_set_upper (tree_view->priv->hadjustment, MAX (gtk_adjustment_get_upper (tree_view->priv->hadjustment), (gfloat)requisition.width));
5374 gtk_adjustment_set_upper (tree_view->priv->vadjustment, MAX (gtk_adjustment_get_upper (tree_view->priv->vadjustment), (gfloat)requisition.height));
5375 gtk_adjustment_changed (tree_view->priv->hadjustment);
5376 gtk_adjustment_changed (tree_view->priv->vadjustment);
5377 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
5383 presize_handler_callback (gpointer data)
5385 do_presize_handler (PSPP_SHEET_VIEW (data));
5391 install_presize_handler (PsppSheetView *tree_view)
5393 if (! gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5396 if (! tree_view->priv->presize_handler_timer)
5398 tree_view->priv->presize_handler_timer =
5399 gdk_threads_add_idle_full (GTK_PRIORITY_RESIZE - 2, presize_handler_callback, tree_view, NULL);
5401 if (! tree_view->priv->validate_rows_timer)
5403 tree_view->priv->validate_rows_timer =
5404 gdk_threads_add_idle_full (PSPP_SHEET_VIEW_PRIORITY_VALIDATE, (GSourceFunc) validate_rows_handler, tree_view, NULL);
5409 scroll_sync_handler (PsppSheetView *tree_view)
5411 if (tree_view->priv->height <= gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
5412 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment), 0);
5413 else if (gtk_tree_row_reference_valid (tree_view->priv->top_row))
5414 pspp_sheet_view_top_row_to_dy (tree_view);
5416 pspp_sheet_view_dy_to_top_row (tree_view);
5418 tree_view->priv->scroll_sync_timer = 0;
5424 install_scroll_sync_handler (PsppSheetView *tree_view)
5426 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5429 if (!tree_view->priv->scroll_sync_timer)
5431 tree_view->priv->scroll_sync_timer =
5432 gdk_threads_add_idle_full (PSPP_SHEET_VIEW_PRIORITY_SCROLL_SYNC, (GSourceFunc) scroll_sync_handler, tree_view, NULL);
5437 pspp_sheet_view_set_top_row (PsppSheetView *tree_view,
5441 gtk_tree_row_reference_free (tree_view->priv->top_row);
5445 tree_view->priv->top_row = NULL;
5446 tree_view->priv->top_row_dy = 0;
5450 tree_view->priv->top_row = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
5451 tree_view->priv->top_row_dy = offset;
5455 /* Always call this iff dy is in the visible range. If the tree is empty, then
5456 * it's set to be NULL, and top_row_dy is 0;
5459 pspp_sheet_view_dy_to_top_row (PsppSheetView *tree_view)
5465 if (tree_view->priv->row_count == 0)
5467 pspp_sheet_view_set_top_row (tree_view, NULL, 0);
5471 offset = pspp_sheet_view_find_offset (tree_view,
5472 tree_view->priv->dy,
5477 pspp_sheet_view_set_top_row (tree_view, NULL, 0);
5481 path = _pspp_sheet_view_find_path (tree_view, node);
5482 pspp_sheet_view_set_top_row (tree_view, path, offset);
5483 gtk_tree_path_free (path);
5489 pspp_sheet_view_top_row_to_dy (PsppSheetView *tree_view)
5495 /* Avoid recursive calls */
5496 if (tree_view->priv->in_top_row_to_dy)
5499 if (tree_view->priv->top_row)
5500 path = gtk_tree_row_reference_get_path (tree_view->priv->top_row);
5507 _pspp_sheet_view_find_node (tree_view, path, &node);
5510 gtk_tree_path_free (path);
5514 /* keep dy and set new toprow */
5515 gtk_tree_row_reference_free (tree_view->priv->top_row);
5516 tree_view->priv->top_row = NULL;
5517 tree_view->priv->top_row_dy = 0;
5518 /* DO NOT install the idle handler */
5519 pspp_sheet_view_dy_to_top_row (tree_view);
5523 if (ROW_HEIGHT (tree_view) < tree_view->priv->top_row_dy)
5525 /* new top row -- do NOT install the idle handler */
5526 pspp_sheet_view_dy_to_top_row (tree_view);
5530 new_dy = pspp_sheet_view_node_find_offset (tree_view, node);
5531 new_dy += tree_view->priv->top_row_dy;
5533 if (new_dy + gtk_adjustment_get_page_size (tree_view->priv->vadjustment) > tree_view->priv->height)
5534 new_dy = tree_view->priv->height - gtk_adjustment_get_page_size (tree_view->priv->vadjustment);
5536 new_dy = MAX (0, new_dy);
5538 tree_view->priv->in_top_row_to_dy = TRUE;
5539 gtk_adjustment_set_value (tree_view->priv->vadjustment, (gdouble)new_dy);
5540 tree_view->priv->in_top_row_to_dy = FALSE;
5545 _pspp_sheet_view_install_mark_rows_col_dirty (PsppSheetView *tree_view)
5547 install_presize_handler (tree_view);
5553 set_source_row (GdkDragContext *context,
5554 GtkTreeModel *model,
5555 GtkTreePath *source_row)
5557 g_object_set_data_full (G_OBJECT (context),
5558 "gtk-tree-view-source-row",
5559 source_row ? gtk_tree_row_reference_new (model, source_row) : NULL,
5560 (GDestroyNotify) (source_row ? gtk_tree_row_reference_free : NULL));
5564 get_source_row (GdkDragContext *context)
5566 GtkTreeRowReference *ref =
5567 g_object_get_data (G_OBJECT (context), "gtk-tree-view-source-row");
5570 return gtk_tree_row_reference_get_path (ref);
5577 GtkTreeRowReference *dest_row;
5578 guint path_down_mode : 1;
5579 guint empty_view_drop : 1;
5580 guint drop_append_mode : 1;
5585 dest_row_free (gpointer data)
5587 DestRow *dr = (DestRow *)data;
5589 gtk_tree_row_reference_free (dr->dest_row);
5590 g_slice_free (DestRow, dr);
5594 set_dest_row (GdkDragContext *context,
5595 GtkTreeModel *model,
5596 GtkTreePath *dest_row,
5597 gboolean path_down_mode,
5598 gboolean empty_view_drop,
5599 gboolean drop_append_mode)
5605 g_object_set_data_full (G_OBJECT (context), "gtk-tree-view-dest-row",
5610 dr = g_slice_new (DestRow);
5612 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5613 dr->path_down_mode = path_down_mode != FALSE;
5614 dr->empty_view_drop = empty_view_drop != FALSE;
5615 dr->drop_append_mode = drop_append_mode != FALSE;
5617 g_object_set_data_full (G_OBJECT (context), "gtk-tree-view-dest-row",
5618 dr, (GDestroyNotify) dest_row_free);
5622 get_dest_row (GdkDragContext *context,
5623 gboolean *path_down_mode)
5626 g_object_get_data (G_OBJECT (context), "gtk-tree-view-dest-row");
5630 GtkTreePath *path = NULL;
5633 *path_down_mode = dr->path_down_mode;
5636 path = gtk_tree_row_reference_get_path (dr->dest_row);
5637 else if (dr->empty_view_drop)
5638 path = gtk_tree_path_new_from_indices (0, -1);
5642 if (path && dr->drop_append_mode)
5643 gtk_tree_path_next (path);
5651 /* Get/set whether drag_motion requested the drag data and
5652 * drag_data_received should thus not actually insert the data,
5653 * since the data doesn't result from a drop.
5656 set_status_pending (GdkDragContext *context,
5657 GdkDragAction suggested_action)
5659 g_object_set_data (G_OBJECT (context),
5660 "gtk-tree-view-status-pending",
5661 GINT_TO_POINTER (suggested_action));
5664 static GdkDragAction
5665 get_status_pending (GdkDragContext *context)
5667 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5668 "gtk-tree-view-status-pending"));
5671 static TreeViewDragInfo*
5672 get_info (PsppSheetView *tree_view)
5674 return g_object_get_data (G_OBJECT (tree_view), "gtk-tree-view-drag-info");
5678 destroy_info (TreeViewDragInfo *di)
5680 g_slice_free (TreeViewDragInfo, di);
5683 static TreeViewDragInfo*
5684 ensure_info (PsppSheetView *tree_view)
5686 TreeViewDragInfo *di;
5688 di = get_info (tree_view);
5692 di = g_slice_new0 (TreeViewDragInfo);
5694 g_object_set_data_full (G_OBJECT (tree_view),
5695 "gtk-tree-view-drag-info",
5697 (GDestroyNotify) destroy_info);
5704 remove_info (PsppSheetView *tree_view)
5706 g_object_set_data (G_OBJECT (tree_view), "gtk-tree-view-drag-info", NULL);
5711 drag_scan_timeout (gpointer data)
5713 PsppSheetView *tree_view;
5715 GdkModifierType state;
5716 GtkTreePath *path = NULL;
5717 PsppSheetViewColumn *column = NULL;
5718 GdkRectangle visible_rect;
5720 GDK_THREADS_ENTER ();
5722 tree_view = PSPP_SHEET_VIEW (data);
5724 gdk_window_get_pointer (tree_view->priv->bin_window,
5727 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
5729 /* See if we are near the edge. */
5730 if ((x - visible_rect.x) < SCROLL_EDGE_SIZE ||
5731 (visible_rect.x + visible_rect.width - x) < SCROLL_EDGE_SIZE ||
5732 (y - visible_rect.y) < SCROLL_EDGE_SIZE ||
5733 (visible_rect.y + visible_rect.height - y) < SCROLL_EDGE_SIZE)
5735 pspp_sheet_view_get_path_at_pos (tree_view,
5736 tree_view->priv->bin_window,
5745 pspp_sheet_view_scroll_to_cell (tree_view,
5751 gtk_tree_path_free (path);
5755 GDK_THREADS_LEAVE ();
5762 add_scroll_timeout (PsppSheetView *tree_view)
5764 if (tree_view->priv->scroll_timeout == 0)
5766 tree_view->priv->scroll_timeout =
5767 gdk_threads_add_timeout (150, scroll_row_timeout, tree_view);
5772 remove_scroll_timeout (PsppSheetView *tree_view)
5774 if (tree_view->priv->scroll_timeout != 0)
5776 g_source_remove (tree_view->priv->scroll_timeout);
5777 tree_view->priv->scroll_timeout = 0;
5782 check_model_dnd (GtkTreeModel *model,
5783 GType required_iface,
5784 const gchar *signal)
5786 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5788 g_warning ("You must override the default '%s' handler "
5789 "on PsppSheetView when using models that don't support "
5790 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5791 "is to connect to '%s' and call "
5792 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5793 "the default handler from running. Look at the source code "
5794 "for the default handler in gtktreeview.c to get an idea what "
5795 "your handler should do. (gtktreeview.c is in the GTK source "
5796 "code.) If you're using GTK from a language other than C, "
5797 "there may be a more natural way to override default handlers, e.g. via derivation.",
5798 signal, g_type_name (required_iface), signal);
5806 scroll_row_timeout (gpointer data)
5808 PsppSheetView *tree_view = data;
5810 pspp_sheet_view_horizontal_autoscroll (tree_view);
5811 pspp_sheet_view_vertical_autoscroll (tree_view);
5813 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
5814 pspp_sheet_view_update_rubber_band (tree_view);
5819 /* Returns TRUE if event should not be propagated to parent widgets */
5821 set_destination_row (PsppSheetView *tree_view,
5822 GdkDragContext *context,
5823 /* coordinates relative to the widget */
5826 GdkDragAction *suggested_action,
5829 GtkTreePath *path = NULL;
5830 PsppSheetViewDropPosition pos;
5831 PsppSheetViewDropPosition old_pos;
5832 TreeViewDragInfo *di;
5834 GtkTreePath *old_dest_path = NULL;
5835 gboolean can_drop = FALSE;
5837 *suggested_action = 0;
5840 widget = GTK_WIDGET (tree_view);
5842 di = get_info (tree_view);
5844 if (di == NULL || y - TREE_VIEW_HEADER_HEIGHT (tree_view) < 0)
5846 /* someone unset us as a drag dest, note that if
5847 * we return FALSE drag_leave isn't called
5850 pspp_sheet_view_set_drag_dest_row (tree_view,
5852 PSPP_SHEET_VIEW_DROP_BEFORE);
5854 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
5856 return FALSE; /* no longer a drop site */
5859 *target = gtk_drag_dest_find_target (widget, context,
5860 gtk_drag_dest_get_target_list (widget));
5861 if (*target == GDK_NONE)
5866 if (!pspp_sheet_view_get_dest_row_at_pos (tree_view,
5872 GtkTreeModel *model;
5874 /* the row got dropped on empty space, let's setup a special case
5878 gtk_tree_path_free (path);
5880 model = pspp_sheet_view_get_model (tree_view);
5882 n_children = gtk_tree_model_iter_n_children (model, NULL);
5885 pos = PSPP_SHEET_VIEW_DROP_AFTER;
5886 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
5890 pos = PSPP_SHEET_VIEW_DROP_BEFORE;
5891 path = gtk_tree_path_new_from_indices (0, -1);
5901 /* If we left the current row's "open" zone, unset the timeout for
5904 pspp_sheet_view_get_drag_dest_row (tree_view,
5909 gtk_tree_path_free (old_dest_path);
5911 if (TRUE /* FIXME if the location droppable predicate */)
5919 GtkWidget *source_widget;
5921 *suggested_action = gdk_drag_context_get_suggested_action (context);
5922 source_widget = gtk_drag_get_source_widget (context);
5924 if (source_widget == widget)
5926 /* Default to MOVE, unless the user has
5927 * pressed ctrl or shift to affect available actions
5929 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
5930 *suggested_action = GDK_ACTION_MOVE;
5933 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
5938 /* can't drop here */
5939 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
5941 PSPP_SHEET_VIEW_DROP_BEFORE);
5945 gtk_tree_path_free (path);
5951 get_logical_dest_row (PsppSheetView *tree_view,
5952 gboolean *path_down_mode,
5953 gboolean *drop_append_mode)
5955 /* adjust path to point to the row the drop goes in front of */
5956 GtkTreePath *path = NULL;
5957 PsppSheetViewDropPosition pos;
5959 g_return_val_if_fail (path_down_mode != NULL, NULL);
5960 g_return_val_if_fail (drop_append_mode != NULL, NULL);
5962 *path_down_mode = FALSE;
5963 *drop_append_mode = 0;
5965 pspp_sheet_view_get_drag_dest_row (tree_view, &path, &pos);
5970 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE)
5972 else if (pos == PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE ||
5973 pos == PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER)
5974 *path_down_mode = TRUE;
5978 GtkTreeModel *model = pspp_sheet_view_get_model (tree_view);
5980 g_assert (pos == PSPP_SHEET_VIEW_DROP_AFTER);
5982 if (!gtk_tree_model_get_iter (model, &iter, path) ||
5983 !gtk_tree_model_iter_next (model, &iter))
5984 *drop_append_mode = 1;
5987 *drop_append_mode = 0;
5988 gtk_tree_path_next (path);
5996 pspp_sheet_view_maybe_begin_dragging_row (PsppSheetView *tree_view,
5997 GdkEventMotion *event)
5999 GtkWidget *widget = GTK_WIDGET (tree_view);
6000 GdkDragContext *context;
6001 TreeViewDragInfo *di;
6002 GtkTreePath *path = NULL;
6004 gint cell_x, cell_y;
6005 GtkTreeModel *model;
6006 gboolean retval = FALSE;
6008 di = get_info (tree_view);
6010 if (di == NULL || !di->source_set)
6013 if (tree_view->priv->pressed_button < 0)
6016 if (!gtk_drag_check_threshold (widget,
6017 tree_view->priv->press_start_x,
6018 tree_view->priv->press_start_y,
6019 event->x, event->y))
6022 model = pspp_sheet_view_get_model (tree_view);
6027 button = tree_view->priv->pressed_button;
6028 tree_view->priv->pressed_button = -1;
6030 pspp_sheet_view_get_path_at_pos (tree_view,
6031 tree_view->priv->press_start_x,
6032 tree_view->priv->press_start_y,
6041 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6042 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6046 if (!(GDK_BUTTON1_MASK << (button - 1) & di->start_button_mask))
6049 /* Now we can begin the drag */
6053 context = gtk_drag_begin (widget,
6054 gtk_drag_source_get_target_list (widget),
6059 set_source_row (context, model, path);
6063 gtk_tree_path_free (path);
6071 pspp_sheet_view_drag_begin (GtkWidget *widget,
6072 GdkDragContext *context)
6075 PsppSheetView *tree_view;
6076 GtkTreePath *path = NULL;
6077 gint cell_x, cell_y;
6079 TreeViewDragInfo *di;
6081 tree_view = PSPP_SHEET_VIEW (widget);
6083 /* if the user uses a custom DND source impl, we don't set the icon here */
6084 di = get_info (tree_view);
6086 if (di == NULL || !di->source_set)
6089 pspp_sheet_view_get_path_at_pos (tree_view,
6090 tree_view->priv->press_start_x,
6091 tree_view->priv->press_start_y,
6097 g_return_if_fail (path != NULL);
6099 row_pix = pspp_sheet_view_create_row_drag_icon (tree_view,
6102 gtk_drag_set_icon_pixmap (context,
6103 gdk_drawable_get_colormap (row_pix),
6106 /* the + 1 is for the black border in the icon */
6107 tree_view->priv->press_start_x + 1,
6110 g_object_unref (row_pix);
6111 gtk_tree_path_free (path);
6117 pspp_sheet_view_drag_end (GtkWidget *widget,
6118 GdkDragContext *context)
6123 /* Default signal implementations for the drag signals */
6125 pspp_sheet_view_drag_data_get (GtkWidget *widget,
6126 GdkDragContext *context,
6127 GtkSelectionData *selection_data,
6131 PsppSheetView *tree_view;
6132 GtkTreeModel *model;
6133 TreeViewDragInfo *di;
6134 GtkTreePath *source_row;
6136 tree_view = PSPP_SHEET_VIEW (widget);
6138 model = pspp_sheet_view_get_model (tree_view);
6143 di = get_info (PSPP_SHEET_VIEW (widget));
6148 source_row = get_source_row (context);
6150 if (source_row == NULL)
6153 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6154 * any model; for DragSource models there are some other targets
6158 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6159 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6164 /* If drag_data_get does nothing, try providing row data. */
6165 if (gtk_selection_data_get_target (selection_data) == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6167 gtk_tree_set_row_drag_data (selection_data,
6173 gtk_tree_path_free (source_row);
6178 pspp_sheet_view_drag_data_delete (GtkWidget *widget,
6179 GdkDragContext *context)
6181 TreeViewDragInfo *di;
6182 GtkTreeModel *model;
6183 PsppSheetView *tree_view;
6184 GtkTreePath *source_row;
6186 tree_view = PSPP_SHEET_VIEW (widget);
6187 model = pspp_sheet_view_get_model (tree_view);
6189 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
6192 di = get_info (tree_view);
6197 source_row = get_source_row (context);
6199 if (source_row == NULL)
6202 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6205 gtk_tree_path_free (source_row);
6207 set_source_row (context, NULL, NULL);
6211 pspp_sheet_view_drag_leave (GtkWidget *widget,
6212 GdkDragContext *context,
6215 /* unset any highlight row */
6216 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6218 PSPP_SHEET_VIEW_DROP_BEFORE);
6220 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6225 pspp_sheet_view_drag_motion (GtkWidget *widget,
6226 GdkDragContext *context,
6227 /* coordinates relative to the widget */
6233 GtkTreePath *path = NULL;
6234 PsppSheetViewDropPosition pos;
6235 PsppSheetView *tree_view;
6236 GdkDragAction suggested_action = 0;
6239 tree_view = PSPP_SHEET_VIEW (widget);
6241 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6244 pspp_sheet_view_get_drag_dest_row (tree_view, &path, &pos);
6246 /* we only know this *after* set_desination_row */
6247 empty = tree_view->priv->empty_view_drop;
6249 if (path == NULL && !empty)
6251 /* Can't drop here. */
6252 gdk_drag_status (context, 0, time);
6256 if (tree_view->priv->open_dest_timeout == 0 &&
6257 (pos == PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER ||
6258 pos == PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE))
6264 add_scroll_timeout (tree_view);
6267 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6269 /* Request data so we can use the source row when
6270 * determining whether to accept the drop
6272 set_status_pending (context, suggested_action);
6273 gtk_drag_get_data (widget, context, target, time);
6277 set_status_pending (context, 0);
6278 gdk_drag_status (context, suggested_action, time);
6283 gtk_tree_path_free (path);
6290 pspp_sheet_view_drag_drop (GtkWidget *widget,
6291 GdkDragContext *context,
6292 /* coordinates relative to the widget */
6297 PsppSheetView *tree_view;
6299 GdkDragAction suggested_action = 0;
6300 GdkAtom target = GDK_NONE;
6301 TreeViewDragInfo *di;
6302 GtkTreeModel *model;
6303 gboolean path_down_mode;
6304 gboolean drop_append_mode;
6306 tree_view = PSPP_SHEET_VIEW (widget);
6308 model = pspp_sheet_view_get_model (tree_view);
6310 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6312 di = get_info (tree_view);
6317 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
6320 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6323 path = get_logical_dest_row (tree_view, &path_down_mode, &drop_append_mode);
6325 if (target != GDK_NONE && path != NULL)
6327 /* in case a motion had requested drag data, change things so we
6328 * treat drag data receives as a drop.
6330 set_status_pending (context, 0);
6331 set_dest_row (context, model, path,
6332 path_down_mode, tree_view->priv->empty_view_drop,
6337 gtk_tree_path_free (path);
6339 /* Unset this thing */
6340 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6342 PSPP_SHEET_VIEW_DROP_BEFORE);
6344 if (target != GDK_NONE)
6346 gtk_drag_get_data (widget, context, target, time);
6354 pspp_sheet_view_drag_data_received (GtkWidget *widget,
6355 GdkDragContext *context,
6356 /* coordinates relative to the widget */
6359 GtkSelectionData *selection_data,
6364 TreeViewDragInfo *di;
6365 gboolean accepted = FALSE;
6366 GtkTreeModel *model;
6367 PsppSheetView *tree_view;
6368 GtkTreePath *dest_row;
6369 GdkDragAction suggested_action;
6370 gboolean path_down_mode;
6371 gboolean drop_append_mode;
6373 tree_view = PSPP_SHEET_VIEW (widget);
6375 model = pspp_sheet_view_get_model (tree_view);
6377 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_data_received"))
6380 di = get_info (tree_view);
6385 suggested_action = get_status_pending (context);
6387 if (suggested_action)
6389 /* We are getting this data due to a request in drag_motion,
6390 * rather than due to a request in drag_drop, so we are just
6391 * supposed to call drag_status, not actually paste in the
6394 path = get_logical_dest_row (tree_view, &path_down_mode,
6398 suggested_action = 0;
6399 else if (path_down_mode)
6400 gtk_tree_path_down (path);
6402 if (suggested_action)
6404 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6410 path_down_mode = FALSE;
6411 gtk_tree_path_up (path);
6413 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6416 suggested_action = 0;
6419 suggested_action = 0;
6423 gdk_drag_status (context, suggested_action, time);
6426 gtk_tree_path_free (path);
6428 /* If you can't drop, remove user drop indicator until the next motion */
6429 if (suggested_action == 0)
6430 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6432 PSPP_SHEET_VIEW_DROP_BEFORE);
6437 dest_row = get_dest_row (context, &path_down_mode);
6439 if (dest_row == NULL)
6442 if (gtk_selection_data_get_length (selection_data) >= 0)
6446 gtk_tree_path_down (dest_row);
6447 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6448 dest_row, selection_data))
6449 gtk_tree_path_up (dest_row);
6453 if (gtk_selection_data_get_length (selection_data) >= 0)
6455 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6461 gtk_drag_finish (context,
6463 (gdk_drag_context_get_actions (context) == GDK_ACTION_MOVE),
6466 if (gtk_tree_path_get_depth (dest_row) == 1
6467 && gtk_tree_path_get_indices (dest_row)[0] == 0)
6469 /* special special case drag to "0", scroll to first item */
6470 if (!tree_view->priv->scroll_to_path)
6471 pspp_sheet_view_scroll_to_cell (tree_view, dest_row, NULL, FALSE, 0.0, 0.0);
6474 gtk_tree_path_free (dest_row);
6477 set_dest_row (context, NULL, NULL, FALSE, FALSE, FALSE);
6482 /* GtkContainer Methods
6487 pspp_sheet_view_remove (GtkContainer *container,
6490 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6491 PsppSheetViewChild *child = NULL;
6494 tmp_list = tree_view->priv->children;
6497 child = tmp_list->data;
6498 if (child->widget == widget)
6500 gtk_widget_unparent (widget);
6502 tree_view->priv->children = g_list_remove_link (tree_view->priv->children, tmp_list);
6503 g_list_free_1 (tmp_list);
6504 g_slice_free (PsppSheetViewChild, child);
6508 tmp_list = tmp_list->next;
6511 tmp_list = tree_view->priv->columns;
6515 PsppSheetViewColumn *column;
6516 column = tmp_list->data;
6517 if (column->button == widget)
6519 gtk_widget_unparent (widget);
6522 tmp_list = tmp_list->next;
6527 pspp_sheet_view_forall (GtkContainer *container,
6528 gboolean include_internals,
6529 GtkCallback callback,
6530 gpointer callback_data)
6532 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6533 PsppSheetViewChild *child = NULL;
6534 PsppSheetViewColumn *column;
6537 tmp_list = tree_view->priv->children;
6540 child = tmp_list->data;
6541 tmp_list = tmp_list->next;
6543 (* callback) (child->widget, callback_data);
6545 if (include_internals == FALSE)
6548 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6550 column = tmp_list->data;
6553 (* callback) (column->button, callback_data);
6557 /* Returns TRUE if the treeview contains no "special" (editable or activatable)
6558 * cells. If so we draw one big row-spanning focus rectangle.
6561 pspp_sheet_view_has_special_cell (PsppSheetView *tree_view)
6565 if (tree_view->priv->special_cells != PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT)
6566 return tree_view->priv->special_cells = PSPP_SHEET_VIEW_SPECIAL_CELLS_YES;
6568 for (list = tree_view->priv->columns; list; list = list->next)
6570 if (!((PsppSheetViewColumn *)list->data)->visible)
6572 if (_pspp_sheet_view_column_count_special_cells (list->data))
6580 pspp_sheet_view_focus_column (PsppSheetView *tree_view,
6581 PsppSheetViewColumn *focus_column,
6582 gboolean clamp_column_visible)
6584 g_return_if_fail (focus_column != NULL);
6586 tree_view->priv->focus_column = focus_column;
6588 if (gtk_container_get_focus_child (GTK_CONTAINER (tree_view)) != focus_column->button)
6589 gtk_widget_grab_focus (focus_column->button);
6591 if (clamp_column_visible)
6592 pspp_sheet_view_clamp_column_visible (tree_view, focus_column, FALSE);
6595 /* Returns TRUE if the focus is within the headers, after the focus operation is
6599 pspp_sheet_view_header_focus (PsppSheetView *tree_view,
6600 GtkDirectionType dir,
6601 gboolean clamp_column_visible)
6603 GtkWidget *focus_child;
6604 PsppSheetViewColumn *focus_column;
6605 GList *last_column, *first_column;
6609 if (! PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
6612 focus_child = gtk_container_get_focus_child (GTK_CONTAINER (tree_view));
6614 first_column = tree_view->priv->columns;
6615 while (first_column)
6617 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (first_column->data);
6619 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6621 first_column = first_column->next;
6624 /* No headers are visible, or are focusable. We can't focus in or out.
6626 if (first_column == NULL)
6629 last_column = g_list_last (tree_view->priv->columns);
6632 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (last_column->data);
6634 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6636 last_column = last_column->prev;
6640 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
6644 case GTK_DIR_TAB_BACKWARD:
6645 case GTK_DIR_TAB_FORWARD:
6648 if (focus_child == NULL)
6650 if (tree_view->priv->focus_column != NULL &&
6651 pspp_sheet_view_column_can_focus (tree_view->priv->focus_column))
6652 focus_column = tree_view->priv->focus_column;
6654 focus_column = first_column->data;
6655 pspp_sheet_view_focus_column (tree_view, focus_column,
6656 clamp_column_visible);
6663 if (focus_child == NULL)
6665 if (tree_view->priv->focus_column != NULL)
6666 focus_column = tree_view->priv->focus_column;
6667 else if (dir == GTK_DIR_LEFT)
6668 focus_column = last_column->data;
6670 focus_column = first_column->data;
6671 pspp_sheet_view_focus_column (tree_view, focus_column,
6672 clamp_column_visible);
6676 if (gtk_widget_child_focus (focus_child, dir))
6678 /* The focus moves inside the button. */
6679 /* This is probably a great example of bad UI */
6680 if (clamp_column_visible)
6681 pspp_sheet_view_clamp_column_visible (tree_view,
6682 tree_view->priv->focus_column,
6687 /* We need to move the focus among the row of buttons. */
6688 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6689 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)->button == focus_child)
6692 if ((tmp_list == first_column && dir == (rtl ? GTK_DIR_RIGHT : GTK_DIR_LEFT))
6693 || (tmp_list == last_column && dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT)))
6695 gtk_widget_error_bell (GTK_WIDGET (tree_view));
6701 PsppSheetViewColumn *column;
6703 if (dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT))
6704 tmp_list = tmp_list->next;
6706 tmp_list = tmp_list->prev;
6708 if (tmp_list == NULL)
6710 g_warning ("Internal button not found");
6713 column = tmp_list->data;
6714 if (column->visible &&
6715 pspp_sheet_view_column_can_focus (column))
6719 pspp_sheet_view_focus_column (tree_view, column,
6720 clamp_column_visible);
6728 g_assert_not_reached ();
6735 /* This function returns in 'path' the first focusable path, if the given path
6736 * is already focusable, it's the returned one.
6740 search_first_focusable_path (PsppSheetView *tree_view,
6742 gboolean search_forward,
6745 /* XXX this function is trivial given that the sheetview doesn't support
6749 if (!path || !*path)
6752 _pspp_sheet_view_find_node (tree_view, *path, &node);
6760 return (*path != NULL);
6764 pspp_sheet_view_focus (GtkWidget *widget,
6765 GtkDirectionType direction)
6767 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6768 GtkContainer *container = GTK_CONTAINER (widget);
6769 GtkWidget *focus_child;
6771 if (!gtk_widget_is_sensitive (widget) || !gtk_widget_get_can_focus (widget))
6774 focus_child = gtk_container_get_focus_child (container);
6776 pspp_sheet_view_stop_editing (PSPP_SHEET_VIEW (widget), FALSE);
6777 /* Case 1. Headers currently have focus. */
6784 pspp_sheet_view_header_focus (tree_view, direction, TRUE);
6786 case GTK_DIR_TAB_BACKWARD:
6789 case GTK_DIR_TAB_FORWARD:
6791 gtk_widget_grab_focus (widget);
6794 g_assert_not_reached ();
6799 /* Case 2. We don't have focus at all. */
6800 if (!gtk_widget_has_focus (widget))
6802 if (!pspp_sheet_view_header_focus (tree_view, direction, FALSE))
6803 gtk_widget_grab_focus (widget);
6807 /* Case 3. We have focus already. */
6808 if (direction == GTK_DIR_TAB_BACKWARD)
6809 return (pspp_sheet_view_header_focus (tree_view, direction, FALSE));
6810 else if (direction == GTK_DIR_TAB_FORWARD)
6813 /* Other directions caught by the keybindings */
6814 gtk_widget_grab_focus (widget);
6819 pspp_sheet_view_grab_focus (GtkWidget *widget)
6821 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->grab_focus (widget);
6823 pspp_sheet_view_focus_to_cursor (PSPP_SHEET_VIEW (widget));
6827 pspp_sheet_view_style_updated (GtkWidget *widget)
6829 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6831 PsppSheetViewColumn *column;
6832 GtkStyleContext *context;
6834 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->style_updated (widget);
6836 if (gtk_widget_get_realized (widget))
6838 context = gtk_widget_get_style_context (GTK_WIDGET (tree_view));
6839 gtk_style_context_set_background (context, gtk_widget_get_window (GTK_WIDGET (tree_view)));
6840 gtk_style_context_set_background (context, tree_view->priv->header_window);
6841 pspp_sheet_view_set_grid_lines (tree_view, tree_view->priv->grid_lines);
6844 gtk_widget_style_get (widget,
6845 "expander-size", &tree_view->priv->expander_size,
6847 tree_view->priv->expander_size += EXPANDER_EXTRA_PADDING;
6849 for (list = tree_view->priv->columns; list; list = list->next)
6851 column = list->data;
6852 _pspp_sheet_view_column_cell_set_dirty (column);
6855 tree_view->priv->fixed_height = -1;
6857 /* Invalidate cached button style. */
6858 if (tree_view->priv->button_style)
6860 g_object_unref (tree_view->priv->button_style);
6861 tree_view->priv->button_style = NULL;
6864 gtk_widget_queue_resize (widget);
6869 pspp_sheet_view_set_focus_child (GtkContainer *container,
6872 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6875 for (list = tree_view->priv->columns; list; list = list->next)
6877 if (PSPP_SHEET_VIEW_COLUMN (list->data)->button == child)
6879 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
6884 GTK_CONTAINER_CLASS (pspp_sheet_view_parent_class)->set_focus_child (container, child);
6888 pspp_sheet_view_set_adjustments (PsppSheetView *tree_view,
6889 GtkAdjustment *hadj,
6890 GtkAdjustment *vadj)
6892 gboolean need_adjust = FALSE;
6894 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
6897 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
6899 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
6901 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
6903 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
6905 if (tree_view->priv->hadjustment && (tree_view->priv->hadjustment != hadj))
6907 g_signal_handlers_disconnect_by_func (tree_view->priv->hadjustment,
6908 pspp_sheet_view_adjustment_changed,
6910 g_object_unref (tree_view->priv->hadjustment);
6913 if (tree_view->priv->vadjustment && (tree_view->priv->vadjustment != vadj))
6915 g_signal_handlers_disconnect_by_func (tree_view->priv->vadjustment,
6916 pspp_sheet_view_adjustment_changed,
6918 g_object_unref (tree_view->priv->vadjustment);
6921 if (tree_view->priv->hadjustment != hadj)
6923 tree_view->priv->hadjustment = hadj;
6924 g_object_ref_sink (tree_view->priv->hadjustment);
6926 g_signal_connect (tree_view->priv->hadjustment, "value-changed",
6927 G_CALLBACK (pspp_sheet_view_adjustment_changed),
6932 if (tree_view->priv->vadjustment != vadj)
6934 tree_view->priv->vadjustment = vadj;
6935 g_object_ref_sink (tree_view->priv->vadjustment);
6937 g_signal_connect (tree_view->priv->vadjustment, "value-changed",
6938 G_CALLBACK (pspp_sheet_view_adjustment_changed),
6944 pspp_sheet_view_adjustment_changed (NULL, tree_view);
6949 pspp_sheet_view_real_move_cursor (PsppSheetView *tree_view,
6950 GtkMovementStep step,
6953 PsppSheetSelectMode mode;
6954 GdkModifierType state;
6956 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
6957 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
6958 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
6959 step == GTK_MOVEMENT_DISPLAY_LINES ||
6960 step == GTK_MOVEMENT_PAGES ||
6961 step == GTK_MOVEMENT_BUFFER_ENDS ||
6962 step == GTK_MOVEMENT_DISPLAY_LINE_ENDS, FALSE);
6964 if (tree_view->priv->row_count == 0)
6966 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
6969 pspp_sheet_view_stop_editing (tree_view, FALSE);
6970 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
6971 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
6974 if (gtk_get_current_event_state (&state))
6976 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
6977 mode |= PSPP_SHEET_SELECT_MODE_TOGGLE;
6978 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
6979 mode |= PSPP_SHEET_SELECT_MODE_EXTEND;
6981 /* else we assume not pressed */
6985 case GTK_MOVEMENT_LOGICAL_POSITIONS:
6986 pspp_sheet_view_move_cursor_tab (tree_view, count);
6988 case GTK_MOVEMENT_VISUAL_POSITIONS:
6989 pspp_sheet_view_move_cursor_left_right (tree_view, count, mode);
6991 case GTK_MOVEMENT_DISPLAY_LINES:
6992 pspp_sheet_view_move_cursor_up_down (tree_view, count, mode);
6994 case GTK_MOVEMENT_PAGES:
6995 pspp_sheet_view_move_cursor_page_up_down (tree_view, count, mode);
6997 case GTK_MOVEMENT_BUFFER_ENDS:
6998 pspp_sheet_view_move_cursor_start_end (tree_view, count, mode);
7000 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
7001 pspp_sheet_view_move_cursor_line_start_end (tree_view, count, mode);
7004 g_assert_not_reached ();
7011 pspp_sheet_view_put (PsppSheetView *tree_view,
7012 GtkWidget *child_widget,
7014 PsppSheetViewColumn *column)
7016 PsppSheetViewChild *child;
7018 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
7019 g_return_if_fail (GTK_IS_WIDGET (child_widget));
7021 child = g_slice_new (PsppSheetViewChild);
7023 child->widget = child_widget;
7024 _pspp_sheet_view_find_node (tree_view, path, &child->node);
7025 if (child->node < 0)
7027 g_assert_not_reached ();
7029 child->column = column;
7031 tree_view->priv->children = g_list_append (tree_view->priv->children, child);
7033 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7034 gtk_widget_set_parent_window (child->widget, tree_view->priv->bin_window);
7036 gtk_widget_set_parent (child_widget, GTK_WIDGET (tree_view));
7039 /* TreeModel Callbacks
7043 pspp_sheet_view_row_changed (GtkTreeModel *model,
7048 PsppSheetView *tree_view = (PsppSheetView *)data;
7050 gboolean free_path = FALSE;
7051 GtkTreePath *cursor_path;
7053 g_return_if_fail (path != NULL || iter != NULL);
7055 if (tree_view->priv->cursor != NULL)
7056 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7060 if (tree_view->priv->edited_column &&
7061 (cursor_path == NULL || gtk_tree_path_compare (cursor_path, path) == 0))
7062 pspp_sheet_view_stop_editing (tree_view, TRUE);
7064 if (cursor_path != NULL)
7065 gtk_tree_path_free (cursor_path);
7069 path = gtk_tree_model_get_path (model, iter);
7072 else if (iter == NULL)
7073 gtk_tree_model_get_iter (model, iter, path);
7075 _pspp_sheet_view_find_node (tree_view,
7081 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7082 pspp_sheet_view_node_queue_redraw (tree_view, node);
7086 gtk_tree_path_free (path);
7090 pspp_sheet_view_row_inserted (GtkTreeModel *model,
7095 PsppSheetView *tree_view = (PsppSheetView *) data;
7098 gint height = tree_view->priv->fixed_height;
7099 gboolean free_path = FALSE;
7100 gboolean node_visible = TRUE;
7102 g_return_if_fail (path != NULL || iter != NULL);
7106 path = gtk_tree_model_get_path (model, iter);
7109 else if (iter == NULL)
7110 gtk_tree_model_get_iter (model, iter, path);
7112 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7114 /* Update all row-references */
7115 gtk_tree_row_reference_inserted (G_OBJECT (data), path);
7116 indices = gtk_tree_path_get_indices (path);
7117 tmpnode = indices[0];
7119 range_tower_insert0 (tree_view->priv->selected, tmpnode, 1);
7123 if (node_visible && node_is_visible (tree_view, tmpnode))
7124 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7126 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (tree_view));
7129 install_presize_handler (tree_view);
7131 gtk_tree_path_free (path);
7135 pspp_sheet_view_row_deleted (GtkTreeModel *model,
7139 PsppSheetView *tree_view = (PsppSheetView *)data;
7142 g_return_if_fail (path != NULL);
7144 gtk_tree_row_reference_deleted (G_OBJECT (data), path);
7146 _pspp_sheet_view_find_node (tree_view, path, &node);
7151 range_tower_delete (tree_view->priv->selected, node, 1);
7153 /* Ensure we don't have a dangling pointer to a dead node */
7154 ensure_unprelighted (tree_view);
7156 /* Cancel editting if we've started */
7157 pspp_sheet_view_stop_editing (tree_view, TRUE);
7159 if (tree_view->priv->destroy_count_func)
7161 gint child_count = 0;
7162 tree_view->priv->destroy_count_func (tree_view, path, child_count, tree_view->priv->destroy_count_data);
7165 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7167 if (! gtk_tree_row_reference_valid (tree_view->priv->top_row))
7169 gtk_tree_row_reference_free (tree_view->priv->top_row);
7170 tree_view->priv->top_row = NULL;
7173 install_scroll_sync_handler (tree_view);
7175 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7178 if (helper_data.changed)
7179 g_signal_emit_by_name (tree_view->priv->selection, "changed");
7184 pspp_sheet_view_rows_reordered (GtkTreeModel *model,
7185 GtkTreePath *parent,
7190 PsppSheetView *tree_view = PSPP_SHEET_VIEW (data);
7193 /* XXX need to adjust selection */
7194 len = gtk_tree_model_iter_n_children (model, iter);
7199 gtk_tree_row_reference_reordered (G_OBJECT (data),
7204 if (gtk_tree_path_get_depth (parent) != 0)
7207 if (tree_view->priv->edited_column)
7208 pspp_sheet_view_stop_editing (tree_view, TRUE);
7210 /* we need to be unprelighted */
7211 ensure_unprelighted (tree_view);
7213 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
7215 pspp_sheet_view_dy_to_top_row (tree_view);
7219 /* Internal tree functions
7224 pspp_sheet_view_get_background_xrange (PsppSheetView *tree_view,
7225 PsppSheetViewColumn *column,
7229 PsppSheetViewColumn *tmp_column = NULL;
7240 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7243 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
7245 list = (rtl ? list->prev : list->next))
7247 tmp_column = list->data;
7249 if (tmp_column == column)
7252 if (tmp_column->visible)
7253 total_width += tmp_column->width;
7256 if (tmp_column != column)
7258 g_warning (G_STRLOC": passed-in column isn't in the tree");
7267 if (column->visible)
7268 *x2 = total_width + column->width;
7270 *x2 = total_width; /* width of 0 */
7274 /* Make sure the node is visible vertically */
7276 pspp_sheet_view_clamp_node_visible (PsppSheetView *tree_view,
7279 gint node_dy, height;
7280 GtkTreePath *path = NULL;
7282 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7285 /* just return if the node is visible, avoiding a costly expose */
7286 node_dy = pspp_sheet_view_node_find_offset (tree_view, node);
7287 height = ROW_HEIGHT (tree_view);
7288 if (node_dy >= gtk_adjustment_get_value (tree_view->priv->vadjustment)
7289 && node_dy + height <= (gtk_adjustment_get_value (tree_view->priv->vadjustment)
7290 + gtk_adjustment_get_page_size (tree_view->priv->vadjustment)))
7293 path = _pspp_sheet_view_find_path (tree_view, node);
7296 /* We process updates because we want to clear old selected items when we scroll.
7297 * if this is removed, we get a "selection streak" at the bottom. */
7298 gdk_window_process_updates (tree_view->priv->bin_window, TRUE);
7299 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL, FALSE, 0.0, 0.0);
7300 gtk_tree_path_free (path);
7305 pspp_sheet_view_clamp_column_visible (PsppSheetView *tree_view,
7306 PsppSheetViewColumn *column,
7307 gboolean focus_to_cell)
7314 x = column->allocation.x;
7315 width = column->allocation.width;
7317 if (width > gtk_adjustment_get_page_size (tree_view->priv->hadjustment))
7319 /* The column is larger than the horizontal page size. If the
7320 * column has cells which can be focussed individually, then we make
7321 * sure the cell which gets focus is fully visible (if even the
7322 * focus cell is bigger than the page size, we make sure the
7323 * left-hand side of the cell is visible).
7325 * If the column does not have those so-called special cells, we
7326 * make sure the left-hand side of the column is visible.
7329 if (focus_to_cell && pspp_sheet_view_has_special_cell (tree_view))
7331 GtkTreePath *cursor_path;
7332 GdkRectangle background_area, cell_area, focus_area;
7334 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7336 pspp_sheet_view_get_cell_area (tree_view,
7337 cursor_path, column, &cell_area);
7338 pspp_sheet_view_get_background_area (tree_view,
7339 cursor_path, column,
7342 gtk_tree_path_free (cursor_path);
7344 _pspp_sheet_view_column_get_focus_area (column,
7350 width = focus_area.width;
7352 if (width < gtk_adjustment_get_page_size (tree_view->priv->hadjustment))
7354 if ((gtk_adjustment_get_value (tree_view->priv->hadjustment) + gtk_adjustment_get_page_size (tree_view->priv->hadjustment)) < (x + width))
7355 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7356 x + width - gtk_adjustment_get_page_size (tree_view->priv->hadjustment));
7357 else if (gtk_adjustment_get_value (tree_view->priv->hadjustment) > x)
7358 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7362 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7364 gtk_adjustment_get_lower (tree_view->priv->hadjustment),
7365 gtk_adjustment_get_upper (tree_view->priv->hadjustment)
7366 - gtk_adjustment_get_page_size (tree_view->priv->hadjustment)));
7370 if ((gtk_adjustment_get_value (tree_view->priv->hadjustment) + gtk_adjustment_get_page_size (tree_view->priv->hadjustment)) < (x + width))
7371 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7372 x + width - gtk_adjustment_get_page_size (tree_view->priv->hadjustment));
7373 else if (gtk_adjustment_get_value (tree_view->priv->hadjustment) > x)
7374 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7379 _pspp_sheet_view_find_path (PsppSheetView *tree_view,
7384 path = gtk_tree_path_new ();
7386 gtk_tree_path_append_index (path, node);
7391 _pspp_sheet_view_find_node (PsppSheetView *tree_view,
7395 gint *indices = gtk_tree_path_get_indices (path);
7396 gint depth = gtk_tree_path_get_depth (path);
7399 if (depth == 0 || indices[0] < 0 || indices[0] >= tree_view->priv->row_count)
7405 pspp_sheet_view_add_move_binding (GtkBindingSet *binding_set,
7408 gboolean add_shifted_binding,
7409 GtkMovementStep step,
7413 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
7418 if (add_shifted_binding)
7419 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
7424 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
7427 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
7432 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
7439 pspp_sheet_view_set_column_drag_info (PsppSheetView *tree_view,
7440 PsppSheetViewColumn *column)
7442 PsppSheetViewColumn *left_column;
7443 PsppSheetViewColumn *cur_column = NULL;
7444 PsppSheetViewColumnReorder *reorder;
7449 /* We want to precalculate the motion list such that we know what column slots
7453 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7455 /* First, identify all possible drop spots */
7457 tmp_list = g_list_last (tree_view->priv->columns);
7459 tmp_list = g_list_first (tree_view->priv->columns);
7463 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
7464 tmp_list = rtl?g_list_previous (tmp_list):g_list_next (tmp_list);
7466 if (cur_column->visible == FALSE)
7469 /* If it's not the column moving and func tells us to skip over the column, we continue. */
7470 if (left_column != column && cur_column != column &&
7471 tree_view->priv->column_drop_func &&
7472 ! tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
7474 left_column = cur_column;
7477 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7478 reorder->left_column = left_column;
7479 left_column = reorder->right_column = cur_column;
7481 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7484 /* Add the last one */
7485 if (tree_view->priv->column_drop_func == NULL ||
7486 ((left_column != column) &&
7487 tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data)))
7489 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7490 reorder->left_column = left_column;
7491 reorder->right_column = NULL;
7492 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7495 /* We quickly check to see if it even makes sense to reorder columns. */
7496 /* If there is nothing that can be moved, then we return */
7498 if (tree_view->priv->column_drag_info == NULL)
7501 /* We know there are always 2 slots possbile, as you can always return column. */
7502 /* If that's all there is, return */
7503 if (tree_view->priv->column_drag_info->next == NULL ||
7504 (tree_view->priv->column_drag_info->next->next == NULL &&
7505 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->data)->right_column == column &&
7506 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->next->data)->left_column == column))
7508 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7509 g_slice_free (PsppSheetViewColumnReorder, tmp_list->data);
7510 g_list_free (tree_view->priv->column_drag_info);
7511 tree_view->priv->column_drag_info = NULL;
7514 /* We fill in the ranges for the columns, now that we've isolated them */
7515 left = - TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7517 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7519 reorder = (PsppSheetViewColumnReorder *) tmp_list->data;
7521 reorder->left_align = left;
7522 if (tmp_list->next != NULL)
7524 g_assert (tmp_list->next->data);
7525 left = reorder->right_align = (reorder->right_column->allocation.x +
7526 reorder->right_column->allocation.width +
7527 ((PsppSheetViewColumnReorder *)tmp_list->next->data)->left_column->allocation.x)/2;
7531 gint width = gdk_window_get_width (tree_view->priv->header_window);
7532 reorder->right_align = width + TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7538 _pspp_sheet_view_column_start_drag (PsppSheetView *tree_view,
7539 PsppSheetViewColumn *column)
7541 GdkEvent *send_event;
7542 GtkAllocation allocation;
7544 GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
7545 GdkDisplay *display = gdk_screen_get_display (screen);
7547 g_return_if_fail (tree_view->priv->column_drag_info == NULL);
7548 g_return_if_fail (tree_view->priv->cur_reorder == NULL);
7549 g_return_if_fail (column->button);
7551 pspp_sheet_view_set_column_drag_info (tree_view, column);
7553 if (tree_view->priv->column_drag_info == NULL)
7556 if (tree_view->priv->drag_window == NULL)
7558 GdkWindowAttr attributes;
7559 guint attributes_mask;
7561 attributes.window_type = GDK_WINDOW_CHILD;
7562 attributes.wclass = GDK_INPUT_OUTPUT;
7563 attributes.x = column->allocation.x;
7565 attributes.width = column->allocation.width;
7566 attributes.height = column->allocation.height;
7567 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
7568 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
7569 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL ;
7571 tree_view->priv->drag_window = gdk_window_new (tree_view->priv->bin_window,
7574 gdk_window_set_user_data (tree_view->priv->drag_window, GTK_WIDGET (tree_view));
7577 gdk_display_pointer_ungrab (display, GDK_CURRENT_TIME);
7578 gdk_display_keyboard_ungrab (display, GDK_CURRENT_TIME);
7580 gtk_grab_remove (column->button);
7582 send_event = gdk_event_new (GDK_LEAVE_NOTIFY);
7583 send_event->crossing.send_event = TRUE;
7584 send_event->crossing.window = g_object_ref (gtk_button_get_event_window (GTK_BUTTON (column->button)));
7585 send_event->crossing.subwindow = NULL;
7586 send_event->crossing.detail = GDK_NOTIFY_ANCESTOR;
7587 send_event->crossing.time = GDK_CURRENT_TIME;
7589 gtk_propagate_event (column->button, send_event);
7590 gdk_event_free (send_event);
7592 send_event = gdk_event_new (GDK_BUTTON_RELEASE);
7593 send_event->button.window = g_object_ref (gdk_screen_get_root_window (screen));
7594 send_event->button.send_event = TRUE;
7595 send_event->button.time = GDK_CURRENT_TIME;
7596 send_event->button.x = -1;
7597 send_event->button.y = -1;
7598 send_event->button.axes = NULL;
7599 send_event->button.state = 0;
7600 send_event->button.button = 1;
7601 send_event->button.device =
7602 gdk_device_manager_get_client_pointer (gdk_display_get_device_manager (display));
7604 send_event->button.x_root = 0;
7605 send_event->button.y_root = 0;
7607 gtk_propagate_event (column->button, send_event);
7608 gdk_event_free (send_event);
7610 /* Kids, don't try this at home */
7611 g_object_ref (column->button);
7612 gtk_container_remove (GTK_CONTAINER (tree_view), column->button);
7613 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7614 gtk_widget_set_parent (column->button, GTK_WIDGET (tree_view));
7615 g_object_unref (column->button);
7617 tree_view->priv->drag_column_x = column->allocation.x;
7618 allocation = column->allocation;
7620 gtk_widget_size_allocate (column->button, &allocation);
7621 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7623 tree_view->priv->drag_column = column;
7624 gdk_window_show (tree_view->priv->drag_window);
7626 gdk_window_get_origin (tree_view->priv->header_window, &x, &y);
7628 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7629 while (gtk_events_pending ())
7630 gtk_main_iteration ();
7632 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG);
7633 gdk_pointer_grab (tree_view->priv->drag_window,
7635 GDK_POINTER_MOTION_MASK|GDK_BUTTON_RELEASE_MASK,
7636 NULL, NULL, GDK_CURRENT_TIME);
7637 gdk_keyboard_grab (tree_view->priv->drag_window,
7643 _pspp_sheet_view_queue_draw_node (PsppSheetView *tree_view,
7645 const GdkRectangle *clip_rect)
7648 GtkAllocation allocation;
7650 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7653 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
7655 rect.width = MAX (tree_view->priv->width, allocation.width);
7657 rect.y = BACKGROUND_FIRST_PIXEL (tree_view, node);
7658 rect.height = ROW_HEIGHT (tree_view);
7662 GdkRectangle new_rect;
7664 gdk_rectangle_intersect (clip_rect, &rect, &new_rect);
7666 gdk_window_invalidate_rect (tree_view->priv->bin_window, &new_rect, TRUE);
7670 gdk_window_invalidate_rect (tree_view->priv->bin_window, &rect, TRUE);
7675 pspp_sheet_view_queue_draw_path (PsppSheetView *tree_view,
7677 const GdkRectangle *clip_rect)
7681 _pspp_sheet_view_find_node (tree_view, path, &node);
7684 _pspp_sheet_view_queue_draw_node (tree_view, node, clip_rect);
7688 pspp_sheet_view_focus_to_cursor (PsppSheetView *tree_view)
7691 GtkTreePath *cursor_path;
7693 if ((tree_view->priv->row_count == 0) ||
7694 (! gtk_widget_get_realized (GTK_WIDGET (tree_view))))
7698 if (tree_view->priv->cursor)
7699 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7701 if (cursor_path == NULL)
7703 /* There's no cursor. Move the cursor to the first selected row, if any
7704 * are selected, otherwise to the first row in the sheetview.
7706 GList *selected_rows;
7707 GtkTreeModel *model;
7708 PsppSheetSelection *selection;
7710 selection = pspp_sheet_view_get_selection (tree_view);
7711 selected_rows = pspp_sheet_selection_get_selected_rows (selection, &model);
7715 /* XXX we could avoid doing O(n) work to get this result */
7716 cursor_path = gtk_tree_path_copy((const GtkTreePath *)(selected_rows->data));
7717 g_list_foreach (selected_rows, (GFunc)gtk_tree_path_free, NULL);
7718 g_list_free (selected_rows);
7722 cursor_path = gtk_tree_path_new_first ();
7723 search_first_focusable_path (tree_view, &cursor_path,
7727 gtk_tree_row_reference_free (tree_view->priv->cursor);
7728 tree_view->priv->cursor = NULL;
7732 if (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7733 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE)
7734 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, FALSE, FALSE, 0);
7736 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE, 0);
7742 /* Now find a column for the cursor. */
7743 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
7745 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
7746 gtk_tree_path_free (cursor_path);
7748 if (tree_view->priv->focus_column == NULL)
7751 for (list = tree_view->priv->columns; list; list = list->next)
7753 if (PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
7755 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
7756 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
7757 pspp_sheet_selection_select_column (tree_view->priv->selection, tree_view->priv->focus_column);
7767 pspp_sheet_view_move_cursor_up_down (PsppSheetView *tree_view,
7769 PsppSheetSelectMode mode)
7771 gint selection_count;
7772 int cursor_node = -1;
7773 int new_cursor_node = -1;
7774 GtkTreePath *cursor_path = NULL;
7775 gboolean grab_focus = TRUE;
7777 if (! gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7781 if (!gtk_tree_row_reference_valid (tree_view->priv->cursor))
7782 /* FIXME: we lost the cursor; should we get the first? */
7785 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7786 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
7788 if (cursor_node < 0)
7789 /* FIXME: we lost the cursor; should we get the first? */
7792 selection_count = pspp_sheet_selection_count_selected_rows (tree_view->priv->selection);
7794 if (selection_count == 0
7795 && tree_view->priv->selection->type != PSPP_SHEET_SELECTION_NONE
7796 && !(mode & PSPP_SHEET_SELECT_MODE_TOGGLE))
7798 /* Don't move the cursor, but just select the current node */
7799 new_cursor_node = cursor_node;
7804 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
7806 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7809 gtk_tree_path_free (cursor_path);
7811 if (new_cursor_node)
7813 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
7815 search_first_focusable_path (tree_view, &cursor_path,
7820 gtk_tree_path_free (cursor_path);
7824 * If the list has only one item and multi-selection is set then select
7825 * the row (if not yet selected).
7827 if ((tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7828 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE) &&
7829 new_cursor_node < 0)
7832 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7834 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
7836 if (new_cursor_node < 0
7837 && !pspp_sheet_view_node_is_selected (tree_view, cursor_node))
7839 new_cursor_node = cursor_node;
7843 new_cursor_node = -1;
7847 if (new_cursor_node >= 0)
7849 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
7850 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, TRUE, mode);
7851 gtk_tree_path_free (cursor_path);
7855 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
7857 if (!(mode & PSPP_SHEET_SELECT_MODE_EXTEND))
7859 if (! gtk_widget_keynav_failed (GTK_WIDGET (tree_view),
7861 GTK_DIR_UP : GTK_DIR_DOWN))
7863 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
7866 gtk_widget_child_focus (toplevel,
7868 GTK_DIR_TAB_BACKWARD :
7869 GTK_DIR_TAB_FORWARD);
7876 gtk_widget_error_bell (GTK_WIDGET (tree_view));
7881 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7883 return new_cursor_node >= 0;
7887 pspp_sheet_view_move_cursor_page_up_down (PsppSheetView *tree_view,
7889 PsppSheetSelectMode mode)
7891 int cursor_node = -1;
7892 GtkTreePath *old_cursor_path = NULL;
7893 GtkTreePath *cursor_path = NULL;
7894 int start_cursor_node = -1;
7897 gint vertical_separator;
7899 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7902 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
7903 old_cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7905 /* This is sorta weird. Focus in should give us a cursor */
7908 gtk_widget_style_get (GTK_WIDGET (tree_view), "vertical-separator", &vertical_separator, NULL);
7909 _pspp_sheet_view_find_node (tree_view, old_cursor_path, &cursor_node);
7911 if (cursor_node < 0)
7913 /* FIXME: we lost the cursor. Should we try to get one? */
7914 gtk_tree_path_free (old_cursor_path);
7918 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
7919 window_y = RBTREE_Y_TO_TREE_WINDOW_Y (tree_view, y);
7920 y += tree_view->priv->cursor_offset;
7921 y += count * (int)gtk_adjustment_get_page_increment (tree_view->priv->vadjustment);
7922 y = CLAMP (y, (gint)gtk_adjustment_get_lower (tree_view->priv->vadjustment), (gint)gtk_adjustment_get_upper (tree_view->priv->vadjustment) - vertical_separator);
7924 if (y >= tree_view->priv->height)
7925 y = tree_view->priv->height - 1;
7927 tree_view->priv->cursor_offset =
7928 pspp_sheet_view_find_offset (tree_view, y, &cursor_node);
7930 if (tree_view->priv->cursor_offset > BACKGROUND_HEIGHT (tree_view))
7932 cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7933 tree_view->priv->cursor_offset -= BACKGROUND_HEIGHT (tree_view);
7936 y -= tree_view->priv->cursor_offset;
7937 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
7939 start_cursor_node = cursor_node;
7941 if (! search_first_focusable_path (tree_view, &cursor_path,
7945 /* It looks like we reached the end of the view without finding
7946 * a focusable row. We will step backwards to find the last
7949 cursor_node = start_cursor_node;
7950 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
7952 search_first_focusable_path (tree_view, &cursor_path,
7961 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
7963 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE, mode);
7966 pspp_sheet_view_scroll_to_point (tree_view, -1, y);
7967 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
7968 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
7970 if (!gtk_tree_path_compare (old_cursor_path, cursor_path))
7971 gtk_widget_error_bell (GTK_WIDGET (tree_view));
7973 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7976 gtk_tree_path_free (old_cursor_path);
7977 gtk_tree_path_free (cursor_path);
7981 pspp_sheet_view_move_cursor_left_right (PsppSheetView *tree_view,
7983 PsppSheetSelectMode mode)
7985 int cursor_node = -1;
7986 GtkTreePath *cursor_path = NULL;
7987 PsppSheetViewColumn *column;
7990 gboolean found_column = FALSE;
7993 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7995 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7998 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
7999 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8003 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8004 if (cursor_node < 0)
8006 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8008 gtk_tree_path_free (cursor_path);
8011 gtk_tree_path_free (cursor_path);
8013 list = rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns);
8014 if (tree_view->priv->focus_column)
8016 for (; list; list = (rtl ? list->prev : list->next))
8018 if (list->data == tree_view->priv->focus_column)
8025 gboolean left, right;
8027 column = list->data;
8028 if (column->visible == FALSE || column->row_head)
8031 pspp_sheet_view_column_cell_set_cell_data (column,
8032 tree_view->priv->model,
8037 right = list->prev ? TRUE : FALSE;
8038 left = list->next ? TRUE : FALSE;
8042 left = list->prev ? TRUE : FALSE;
8043 right = list->next ? TRUE : FALSE;
8046 if (_pspp_sheet_view_column_cell_focus (column, count, left, right))
8048 tree_view->priv->focus_column = column;
8049 found_column = TRUE;
8054 list = rtl ? list->prev : list->next;
8056 list = rtl ? list->next : list->prev;
8061 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8062 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8063 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8067 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8070 pspp_sheet_view_clamp_column_visible (tree_view,
8071 tree_view->priv->focus_column, TRUE);
8075 pspp_sheet_view_move_cursor_line_start_end (PsppSheetView *tree_view,
8077 PsppSheetSelectMode mode)
8079 int cursor_node = -1;
8080 GtkTreePath *cursor_path = NULL;
8081 PsppSheetViewColumn *column;
8082 PsppSheetViewColumn *found_column;
8087 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8089 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8092 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8093 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8097 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8098 if (cursor_node < 0)
8100 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8102 gtk_tree_path_free (cursor_path);
8105 gtk_tree_path_free (cursor_path);
8107 list = rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns);
8108 if (tree_view->priv->focus_column)
8110 for (; list; list = (rtl ? list->prev : list->next))
8112 if (list->data == tree_view->priv->focus_column)
8117 found_column = NULL;
8120 gboolean left, right;
8122 column = list->data;
8123 if (column->visible == FALSE || column->row_head)
8126 pspp_sheet_view_column_cell_set_cell_data (column,
8127 tree_view->priv->model,
8132 right = list->prev ? TRUE : FALSE;
8133 left = list->next ? TRUE : FALSE;
8137 left = list->prev ? TRUE : FALSE;
8138 right = list->next ? TRUE : FALSE;
8141 if (column->tabbable
8142 && _pspp_sheet_view_column_cell_focus (column, count, left, right))
8143 found_column = column;
8147 list = rtl ? list->prev : list->next;
8149 list = rtl ? list->next : list->prev;
8154 tree_view->priv->focus_column = found_column;
8155 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8156 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8157 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8160 pspp_sheet_view_clamp_column_visible (tree_view,
8161 tree_view->priv->focus_column, TRUE);
8165 try_move_cursor_tab (PsppSheetView *tree_view,
8166 gboolean start_at_focus_column,
8169 PsppSheetViewColumn *column;
8171 int cursor_node = -1;
8172 GtkTreePath *cursor_path = NULL;
8176 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8177 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8181 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8182 if (cursor_node < 0)
8184 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8186 gtk_tree_path_free (cursor_path);
8189 gtk_tree_path_free (cursor_path);
8191 rtl = gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL;
8192 if (start_at_focus_column)
8195 ? g_list_last (tree_view->priv->columns)
8196 : g_list_first (tree_view->priv->columns));
8197 if (tree_view->priv->focus_column)
8199 for (; list; list = (rtl ? list->prev : list->next))
8201 if (list->data == tree_view->priv->focus_column)
8208 list = (rtl ^ (count == 1)
8209 ? g_list_first (tree_view->priv->columns)
8210 : g_list_last (tree_view->priv->columns));
8215 gboolean left, right;
8217 column = list->data;
8218 if (column->visible == FALSE || !column->tabbable)
8221 pspp_sheet_view_column_cell_set_cell_data (column,
8222 tree_view->priv->model,
8227 right = list->prev ? TRUE : FALSE;
8228 left = list->next ? TRUE : FALSE;
8232 left = list->prev ? TRUE : FALSE;
8233 right = list->next ? TRUE : FALSE;
8236 if (column->tabbable
8237 && _pspp_sheet_view_column_cell_focus (column, count, left, right))
8239 tree_view->priv->focus_column = column;
8240 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8241 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8242 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8247 list = rtl ? list->prev : list->next;
8249 list = rtl ? list->next : list->prev;
8256 pspp_sheet_view_move_cursor_tab (PsppSheetView *tree_view,
8259 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8262 if (!try_move_cursor_tab (tree_view, TRUE, count))
8264 if (pspp_sheet_view_move_cursor_up_down (tree_view, count, 0)
8265 && !try_move_cursor_tab (tree_view, FALSE, count))
8266 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8269 pspp_sheet_view_clamp_column_visible (tree_view,
8270 tree_view->priv->focus_column, TRUE);
8274 pspp_sheet_view_move_cursor_start_end (PsppSheetView *tree_view,
8276 PsppSheetSelectMode mode)
8280 GtkTreePath *old_path;
8282 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8285 g_return_if_fail (tree_view->priv->row_count > 0);
8287 pspp_sheet_view_get_cursor (tree_view, &old_path, NULL);
8291 /* Now go forward to find the first focusable row. */
8292 path = _pspp_sheet_view_find_path (tree_view, 0);
8293 search_first_focusable_path (tree_view, &path,
8294 TRUE, &cursor_node);
8298 /* Now go backwards to find last focusable row. */
8299 path = _pspp_sheet_view_find_path (tree_view, tree_view->priv->row_count - 1);
8300 search_first_focusable_path (tree_view, &path,
8301 FALSE, &cursor_node);
8307 if (gtk_tree_path_compare (old_path, path))
8309 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, mode);
8310 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8314 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8318 gtk_tree_path_free (old_path);
8319 gtk_tree_path_free (path);
8323 pspp_sheet_view_real_select_all (PsppSheetView *tree_view)
8325 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8328 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8329 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8332 pspp_sheet_selection_select_all (tree_view->priv->selection);
8338 pspp_sheet_view_real_unselect_all (PsppSheetView *tree_view)
8340 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8343 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8344 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8347 pspp_sheet_selection_unselect_all (tree_view->priv->selection);
8353 pspp_sheet_view_real_select_cursor_row (PsppSheetView *tree_view,
8354 gboolean start_editing,
8355 PsppSheetSelectMode mode)
8358 int cursor_node = -1;
8359 GtkTreePath *cursor_path = NULL;
8361 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8364 if (tree_view->priv->cursor)
8365 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8367 if (cursor_path == NULL)
8370 _pspp_sheet_view_find_node (tree_view, cursor_path,
8373 if (cursor_node < 0)
8375 gtk_tree_path_free (cursor_path);
8379 if (!(mode & PSPP_SHEET_SELECT_MODE_EXTEND) && start_editing &&
8380 tree_view->priv->focus_column)
8382 if (pspp_sheet_view_start_editing (tree_view, cursor_path))
8384 gtk_tree_path_free (cursor_path);
8389 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8395 /* We bail out if the original (tree, node) don't exist anymore after
8396 * handling the selection-changed callback. We do return TRUE because
8397 * the key press has been handled at this point.
8399 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8401 if (cursor_node != new_node)
8404 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8406 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8407 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8409 if (!(mode & PSPP_SHEET_SELECT_MODE_EXTEND))
8410 pspp_sheet_view_row_activated (tree_view, cursor_path,
8411 tree_view->priv->focus_column);
8413 gtk_tree_path_free (cursor_path);
8419 pspp_sheet_view_real_toggle_cursor_row (PsppSheetView *tree_view)
8422 int cursor_node = -1;
8423 GtkTreePath *cursor_path = NULL;
8425 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8429 if (tree_view->priv->cursor)
8430 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8432 if (cursor_path == NULL)
8435 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8436 if (cursor_node < 0)
8438 gtk_tree_path_free (cursor_path);
8442 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8445 PSPP_SHEET_SELECT_MODE_TOGGLE,
8448 /* We bail out if the original (tree, node) don't exist anymore after
8449 * handling the selection-changed callback. We do return TRUE because
8450 * the key press has been handled at this point.
8452 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8454 if (cursor_node != new_node)
8457 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8459 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8460 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
8461 gtk_tree_path_free (cursor_path);
8467 pspp_sheet_view_search_entry_flush_timeout (PsppSheetView *tree_view)
8469 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
8470 tree_view->priv->typeselect_flush_timeout = 0;
8475 /* Cut and paste from gtkwindow.c */
8477 send_focus_change (GtkWidget *widget,
8480 GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
8482 fevent->focus_change.type = GDK_FOCUS_CHANGE;
8483 fevent->focus_change.window = g_object_ref (gtk_widget_get_window (widget));
8484 fevent->focus_change.in = in;
8486 gtk_widget_send_focus_change (widget, fevent);
8487 gdk_event_free (fevent);
8491 pspp_sheet_view_ensure_interactive_directory (PsppSheetView *tree_view)
8493 GtkWidget *frame, *vbox, *toplevel;
8496 if (tree_view->priv->search_custom_entry_set)
8499 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
8500 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
8502 if (tree_view->priv->search_window != NULL)
8504 if (gtk_window_get_group (GTK_WINDOW (toplevel)))
8505 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
8506 GTK_WINDOW (tree_view->priv->search_window));
8507 else if (gtk_window_get_group (GTK_WINDOW (tree_view->priv->search_window)))
8508 gtk_window_group_remove_window (gtk_window_get_group (GTK_WINDOW (tree_view->priv->search_window)),
8509 GTK_WINDOW (tree_view->priv->search_window));
8510 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8514 tree_view->priv->search_window = gtk_window_new (GTK_WINDOW_POPUP);
8515 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8517 if (gtk_window_get_group (GTK_WINDOW (toplevel)))
8518 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
8519 GTK_WINDOW (tree_view->priv->search_window));
8521 gtk_window_set_type_hint (GTK_WINDOW (tree_view->priv->search_window),
8522 GDK_WINDOW_TYPE_HINT_UTILITY);
8523 gtk_window_set_modal (GTK_WINDOW (tree_view->priv->search_window), TRUE);
8524 g_signal_connect (tree_view->priv->search_window, "delete-event",
8525 G_CALLBACK (pspp_sheet_view_search_delete_event),
8527 g_signal_connect (tree_view->priv->search_window, "key-press-event",
8528 G_CALLBACK (pspp_sheet_view_search_key_press_event),
8530 g_signal_connect (tree_view->priv->search_window, "button-press-event",
8531 G_CALLBACK (pspp_sheet_view_search_button_press_event),
8533 g_signal_connect (tree_view->priv->search_window, "scroll-event",
8534 G_CALLBACK (pspp_sheet_view_search_scroll_event),
8537 frame = gtk_frame_new (NULL);
8538 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
8539 gtk_widget_show (frame);
8540 gtk_container_add (GTK_CONTAINER (tree_view->priv->search_window), frame);
8542 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
8543 gtk_widget_show (vbox);
8544 gtk_container_add (GTK_CONTAINER (frame), vbox);
8545 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
8548 tree_view->priv->search_entry = gtk_entry_new ();
8549 gtk_widget_show (tree_view->priv->search_entry);
8550 g_signal_connect (tree_view->priv->search_entry, "populate-popup",
8551 G_CALLBACK (pspp_sheet_view_search_disable_popdown),
8553 g_signal_connect (tree_view->priv->search_entry,
8554 "activate", G_CALLBACK (pspp_sheet_view_search_activate),
8558 g_signal_connect (GTK_ENTRY (tree_view->priv->search_entry)->im_context,
8560 G_CALLBACK (pspp_sheet_view_search_preedit_changed),
8564 gtk_container_add (GTK_CONTAINER (vbox),
8565 tree_view->priv->search_entry);
8567 gtk_widget_realize (tree_view->priv->search_entry);
8570 /* Pops up the interactive search entry. If keybinding is TRUE then the user
8571 * started this by typing the start_interactive_search keybinding. Otherwise, it came from
8574 pspp_sheet_view_real_start_interactive_search (PsppSheetView *tree_view,
8575 gboolean keybinding)
8577 /* We only start interactive search if we have focus or the columns
8578 * have focus. If one of our children have focus, we don't want to
8582 gboolean found_focus = FALSE;
8583 GtkWidgetClass *entry_parent_class;
8585 if (!tree_view->priv->enable_search && !keybinding)
8588 if (tree_view->priv->search_custom_entry_set)
8591 if (tree_view->priv->search_window != NULL &&
8592 gtk_widget_get_visible (tree_view->priv->search_window))
8595 for (list = tree_view->priv->columns; list; list = list->next)
8597 PsppSheetViewColumn *column;
8599 column = list->data;
8600 if (! column->visible)
8603 if (column->button && gtk_widget_has_focus (column->button))
8610 if (gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8616 if (tree_view->priv->search_column < 0)
8619 pspp_sheet_view_ensure_interactive_directory (tree_view);
8622 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
8625 tree_view->priv->search_position_func (tree_view, tree_view->priv->search_window, tree_view->priv->search_position_user_data);
8626 gtk_widget_show (tree_view->priv->search_window);
8627 if (tree_view->priv->search_entry_changed_id == 0)
8629 tree_view->priv->search_entry_changed_id =
8630 g_signal_connect (tree_view->priv->search_entry, "changed",
8631 G_CALLBACK (pspp_sheet_view_search_init),
8635 tree_view->priv->typeselect_flush_timeout =
8636 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
8637 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
8640 /* Grab focus will select all the text. We don't want that to happen, so we
8641 * call the parent instance and bypass the selection change. This is probably
8642 * really non-kosher. */
8643 entry_parent_class = g_type_class_peek_parent (GTK_ENTRY_GET_CLASS (tree_view->priv->search_entry));
8644 (entry_parent_class->grab_focus) (tree_view->priv->search_entry);
8646 /* send focus-in event */
8647 send_focus_change (tree_view->priv->search_entry, TRUE);
8649 /* search first matching iter */
8650 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
8656 pspp_sheet_view_start_interactive_search (PsppSheetView *tree_view)
8658 return pspp_sheet_view_real_start_interactive_search (tree_view, TRUE);
8661 /* this function returns the new width of the column being resized given
8662 * the column and x position of the cursor; the x cursor position is passed
8663 * in as a pointer and automagicly corrected if it's beyond min/max limits
8666 pspp_sheet_view_new_column_width (PsppSheetView *tree_view,
8670 PsppSheetViewColumn *column;
8674 /* first translate the x position from gtk_widget_get_window (widget)
8675 * to clist->clist_window
8677 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8678 column = g_list_nth (tree_view->priv->columns, i)->data;
8679 width = rtl ? (column->allocation.x + column->allocation.width - *x) : (*x - column->allocation.x);
8681 /* Clamp down the value */
8682 if (column->min_width == -1)
8683 width = MAX (column->button_request, width);
8685 width = MAX (column->min_width, width);
8686 if (column->max_width != -1)
8687 width = MIN (width, column->max_width);
8689 *x = rtl ? (column->allocation.x + column->allocation.width - width) : (column->allocation.x + width);
8695 pspp_sheet_view_column_update_button (PsppSheetViewColumn *tree_column);
8699 pspp_sheet_view_adjustment_changed (GtkAdjustment *adjustment,
8700 PsppSheetView *tree_view)
8702 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
8706 gdk_window_move (tree_view->priv->bin_window,
8707 - gtk_adjustment_get_value (tree_view->priv->hadjustment),
8708 TREE_VIEW_HEADER_HEIGHT (tree_view));
8709 gdk_window_move (tree_view->priv->header_window,
8710 - gtk_adjustment_get_value (tree_view->priv->hadjustment),
8712 dy = tree_view->priv->dy - (int) gtk_adjustment_get_value (tree_view->priv->vadjustment);
8714 gdk_window_scroll (tree_view->priv->bin_window, 0, dy);
8718 /* update our dy and top_row */
8719 tree_view->priv->dy = (int) gtk_adjustment_get_value (tree_view->priv->vadjustment);
8721 update_prelight (tree_view,
8722 tree_view->priv->event_last_x,
8723 tree_view->priv->event_last_y);
8725 if (!tree_view->priv->in_top_row_to_dy)
8726 pspp_sheet_view_dy_to_top_row (tree_view);
8729 update_childrens_allocation(tree_view);
8737 * pspp_sheet_view_new:
8739 * Creates a new #PsppSheetView widget.
8741 * Return value: A newly created #PsppSheetView widget.
8744 pspp_sheet_view_new (void)
8746 return g_object_new (PSPP_TYPE_SHEET_VIEW, NULL);
8750 * pspp_sheet_view_new_with_model:
8751 * @model: the model.
8753 * Creates a new #PsppSheetView widget with the model initialized to @model.
8755 * Return value: A newly created #PsppSheetView widget.
8758 pspp_sheet_view_new_with_model (GtkTreeModel *model)
8760 return g_object_new (PSPP_TYPE_SHEET_VIEW, "model", model, NULL);
8767 * pspp_sheet_view_get_model:
8768 * @tree_view: a #PsppSheetView
8770 * Returns the model the #PsppSheetView is based on. Returns %NULL if the
8773 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
8776 pspp_sheet_view_get_model (PsppSheetView *tree_view)
8778 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
8780 return tree_view->priv->model;
8784 * pspp_sheet_view_set_model:
8785 * @tree_view: A #GtkTreeNode.
8786 * @model: (allow-none): The model.
8788 * Sets the model for a #PsppSheetView. If the @tree_view already has a model
8789 * set, it will remove it before setting the new model. If @model is %NULL,
8790 * then it will unset the old model.
8793 pspp_sheet_view_set_model (PsppSheetView *tree_view,
8794 GtkTreeModel *model)
8796 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8797 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
8799 if (model == tree_view->priv->model)
8802 if (tree_view->priv->scroll_to_path)
8804 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
8805 tree_view->priv->scroll_to_path = NULL;
8808 if (tree_view->priv->model)
8810 GList *tmplist = tree_view->priv->columns;
8812 if (tree_view->priv->selected)
8813 range_tower_set0 (tree_view->priv->selected, 0, ULONG_MAX);
8814 pspp_sheet_view_stop_editing (tree_view, TRUE);
8816 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
8817 pspp_sheet_view_row_changed,
8819 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
8820 pspp_sheet_view_row_inserted,
8822 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
8823 pspp_sheet_view_row_deleted,
8825 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
8826 pspp_sheet_view_rows_reordered,
8829 for (; tmplist; tmplist = tmplist->next)
8830 _pspp_sheet_view_column_unset_model (tmplist->data,
8831 tree_view->priv->model);
8833 tree_view->priv->prelight_node = -1;
8835 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
8836 tree_view->priv->drag_dest_row = NULL;
8837 gtk_tree_row_reference_free (tree_view->priv->cursor);
8838 tree_view->priv->cursor = NULL;
8839 gtk_tree_row_reference_free (tree_view->priv->anchor);
8840 tree_view->priv->anchor = NULL;
8841 gtk_tree_row_reference_free (tree_view->priv->top_row);
8842 tree_view->priv->top_row = NULL;
8843 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
8844 tree_view->priv->scroll_to_path = NULL;
8846 tree_view->priv->scroll_to_column = NULL;
8848 g_object_unref (tree_view->priv->model);
8850 tree_view->priv->search_column = -1;
8851 tree_view->priv->fixed_height = -1;
8852 tree_view->priv->dy = tree_view->priv->top_row_dy = 0;
8853 tree_view->priv->last_button_x = -1;
8854 tree_view->priv->last_button_y = -1;
8857 tree_view->priv->model = model;
8859 if (tree_view->priv->model)
8863 if (tree_view->priv->search_column == -1)
8865 for (i = 0; i < gtk_tree_model_get_n_columns (model); i++)
8867 GType type = gtk_tree_model_get_column_type (model, i);
8869 if (g_value_type_transformable (type, G_TYPE_STRING))
8871 tree_view->priv->search_column = i;
8877 g_object_ref (tree_view->priv->model);
8878 g_signal_connect (tree_view->priv->model,
8880 G_CALLBACK (pspp_sheet_view_row_changed),
8882 g_signal_connect (tree_view->priv->model,
8884 G_CALLBACK (pspp_sheet_view_row_inserted),
8886 g_signal_connect (tree_view->priv->model,
8888 G_CALLBACK (pspp_sheet_view_row_deleted),
8890 g_signal_connect (tree_view->priv->model,
8892 G_CALLBACK (pspp_sheet_view_rows_reordered),
8895 tree_view->priv->row_count = gtk_tree_model_iter_n_children (tree_view->priv->model, NULL);
8897 /* FIXME: do I need to do this? pspp_sheet_view_create_buttons (tree_view); */
8898 install_presize_handler (tree_view);
8901 g_object_notify (G_OBJECT (tree_view), "model");
8903 if (tree_view->priv->selection)
8904 _pspp_sheet_selection_emit_changed (tree_view->priv->selection);
8906 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
8907 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
8911 * pspp_sheet_view_get_selection:
8912 * @tree_view: A #PsppSheetView.
8914 * Gets the #PsppSheetSelection associated with @tree_view.
8916 * Return value: A #PsppSheetSelection object.
8918 PsppSheetSelection *
8919 pspp_sheet_view_get_selection (PsppSheetView *tree_view)
8921 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
8923 return tree_view->priv->selection;
8927 * pspp_sheet_view_get_hadjustment:
8928 * @tree_view: A #PsppSheetView
8930 * Gets the #GtkAdjustment currently being used for the horizontal aspect.
8932 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
8936 pspp_sheet_view_get_hadjustment (PsppSheetView *tree_view)
8938 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
8940 return pspp_sheet_view_do_get_hadjustment (tree_view);
8943 static GtkAdjustment *
8944 pspp_sheet_view_do_get_hadjustment (PsppSheetView *tree_view)
8946 return tree_view->priv->hadjustment;
8950 * pspp_sheet_view_set_hadjustment:
8951 * @tree_view: A #PsppSheetView
8952 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
8954 * Sets the #GtkAdjustment for the current horizontal aspect.
8957 pspp_sheet_view_set_hadjustment (PsppSheetView *tree_view,
8958 GtkAdjustment *adjustment)
8960 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8962 pspp_sheet_view_set_adjustments (tree_view,
8964 tree_view->priv->vadjustment);
8966 g_object_notify (G_OBJECT (tree_view), "hadjustment");
8970 pspp_sheet_view_do_set_hadjustment (PsppSheetView *tree_view,
8971 GtkAdjustment *adjustment)
8973 PsppSheetViewPrivate *priv = tree_view->priv;
8975 if (adjustment && priv->hadjustment == adjustment)
8978 if (priv->hadjustment != NULL)
8980 g_signal_handlers_disconnect_by_func (priv->hadjustment,
8981 pspp_sheet_view_adjustment_changed,
8983 g_object_unref (priv->hadjustment);
8986 if (adjustment == NULL)
8987 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
8990 g_signal_connect (adjustment, "value-changed",
8991 G_CALLBACK (pspp_sheet_view_adjustment_changed), tree_view);
8992 priv->hadjustment = g_object_ref_sink (adjustment);
8993 /* FIXME: Adjustment should probably be populated here with fresh values, but
8994 * internal details are too complicated for me to decipher right now.
8996 pspp_sheet_view_adjustment_changed (NULL, tree_view);
8998 g_object_notify (G_OBJECT (tree_view), "hadjustment");
9002 * pspp_sheet_view_get_vadjustment:
9003 * @tree_view: A #PsppSheetView
9005 * Gets the #GtkAdjustment currently being used for the vertical aspect.
9007 * Return value: (transfer none): A #GtkAdjustment object, or %NULL
9008 * if none is currently being used.
9010 * Deprecated: 3.0: Use gtk_scrollable_get_vadjustment()
9013 pspp_sheet_view_get_vadjustment (PsppSheetView *tree_view)
9015 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9017 return pspp_sheet_view_do_get_vadjustment (tree_view);
9020 static GtkAdjustment *
9021 pspp_sheet_view_do_get_vadjustment (PsppSheetView *tree_view)
9023 return tree_view->priv->vadjustment;
9027 * pspp_sheet_view_set_vadjustment:
9028 * @tree_view: A #PsppSheetView
9029 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
9031 * Sets the #GtkAdjustment for the current vertical aspect.
9033 * Deprecated: 3.0: Use gtk_scrollable_set_vadjustment()
9036 pspp_sheet_view_set_vadjustment (PsppSheetView *tree_view,
9037 GtkAdjustment *adjustment)
9039 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9040 g_return_if_fail (adjustment == NULL || GTK_IS_ADJUSTMENT (adjustment));
9042 pspp_sheet_view_do_set_vadjustment (tree_view, adjustment);
9046 pspp_sheet_view_do_set_vadjustment (PsppSheetView *tree_view,
9047 GtkAdjustment *adjustment)
9049 PsppSheetViewPrivate *priv = tree_view->priv;
9051 if (adjustment && priv->vadjustment == adjustment)
9054 if (priv->vadjustment != NULL)
9056 g_signal_handlers_disconnect_by_func (priv->vadjustment,
9057 pspp_sheet_view_adjustment_changed,
9059 g_object_unref (priv->vadjustment);
9062 if (adjustment == NULL)
9063 adjustment = gtk_adjustment_new (0.0, 0.0, 0.0,
9066 g_signal_connect (adjustment, "value-changed",
9067 G_CALLBACK (pspp_sheet_view_adjustment_changed), tree_view);
9068 priv->vadjustment = g_object_ref_sink (adjustment);
9069 /* FIXME: Adjustment should probably be populated here with fresh values, but
9070 * internal details are too complicated for me to decipher right now.
9072 pspp_sheet_view_adjustment_changed (NULL, tree_view);
9073 g_object_notify (G_OBJECT (tree_view), "vadjustment");
9076 /* Column and header operations */
9079 * pspp_sheet_view_get_headers_visible:
9080 * @tree_view: A #PsppSheetView.
9082 * Returns %TRUE if the headers on the @tree_view are visible.
9084 * Return value: Whether the headers are visible or not.
9087 pspp_sheet_view_get_headers_visible (PsppSheetView *tree_view)
9089 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9091 return PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9095 * pspp_sheet_view_set_headers_visible:
9096 * @tree_view: A #PsppSheetView.
9097 * @headers_visible: %TRUE if the headers are visible
9099 * Sets the visibility state of the headers.
9102 pspp_sheet_view_set_headers_visible (PsppSheetView *tree_view,
9103 gboolean headers_visible)
9107 PsppSheetViewColumn *column;
9108 GtkAllocation allocation;
9110 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9112 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
9114 headers_visible = !! headers_visible;
9116 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE) == headers_visible)
9119 if (headers_visible)
9120 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9122 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9124 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9126 gdk_window_get_position (tree_view->priv->bin_window, &x, &y);
9127 if (headers_visible)
9129 gdk_window_move_resize (tree_view->priv->bin_window, x, y + TREE_VIEW_HEADER_HEIGHT (tree_view),
9130 tree_view->priv->width, allocation.height - + TREE_VIEW_HEADER_HEIGHT (tree_view));
9132 if (gtk_widget_get_mapped (GTK_WIDGET (tree_view)))
9133 pspp_sheet_view_map_buttons (tree_view);
9137 gdk_window_move_resize (tree_view->priv->bin_window, x, y, tree_view->priv->width, tree_view->priv->height);
9139 for (list = tree_view->priv->columns; list; list = list->next)
9141 column = list->data;
9143 gtk_widget_unmap (column->button);
9145 gdk_window_hide (tree_view->priv->header_window);
9149 gtk_adjustment_set_page_size (tree_view->priv->vadjustment, allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view));
9150 gtk_adjustment_set_page_increment (tree_view->priv->vadjustment, (allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view)) / 2);
9151 gtk_adjustment_set_lower (tree_view->priv->vadjustment, 0);
9152 gtk_adjustment_set_upper (tree_view->priv->vadjustment, tree_view->priv->height);
9153 gtk_adjustment_changed (tree_view->priv->vadjustment);
9155 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9157 g_object_notify (G_OBJECT (tree_view), "headers-visible");
9161 * pspp_sheet_view_columns_autosize:
9162 * @tree_view: A #PsppSheetView.
9164 * Resizes all columns to their optimal width. Only works after the
9165 * treeview has been realized.
9168 pspp_sheet_view_columns_autosize (PsppSheetView *tree_view)
9170 gboolean dirty = FALSE;
9172 PsppSheetViewColumn *column;
9174 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9176 for (list = tree_view->priv->columns; list; list = list->next)
9178 column = list->data;
9179 _pspp_sheet_view_column_cell_set_dirty (column);
9184 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9188 * pspp_sheet_view_set_headers_clickable:
9189 * @tree_view: A #PsppSheetView.
9190 * @setting: %TRUE if the columns are clickable.
9192 * Allow the column title buttons to be clicked.
9195 pspp_sheet_view_set_headers_clickable (PsppSheetView *tree_view,
9200 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9202 for (list = tree_view->priv->columns; list; list = list->next)
9203 pspp_sheet_view_column_set_clickable (PSPP_SHEET_VIEW_COLUMN (list->data), setting);
9205 g_object_notify (G_OBJECT (tree_view), "headers-clickable");
9210 * pspp_sheet_view_get_headers_clickable:
9211 * @tree_view: A #PsppSheetView.
9213 * Returns whether all header columns are clickable.
9215 * Return value: %TRUE if all header columns are clickable, otherwise %FALSE
9220 pspp_sheet_view_get_headers_clickable (PsppSheetView *tree_view)
9224 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9226 for (list = tree_view->priv->columns; list; list = list->next)
9227 if (!PSPP_SHEET_VIEW_COLUMN (list->data)->clickable)
9234 * pspp_sheet_view_set_rules_hint
9235 * @tree_view: a #PsppSheetView
9236 * @setting: %TRUE if the tree requires reading across rows
9238 * This function tells GTK+ that the user interface for your
9239 * application requires users to read across tree rows and associate
9240 * cells with one another. By default, GTK+ will then render the tree
9241 * with alternating row colors. Do <emphasis>not</emphasis> use it
9242 * just because you prefer the appearance of the ruled tree; that's a
9243 * question for the theme. Some themes will draw tree rows in
9244 * alternating colors even when rules are turned off, and users who
9245 * prefer that appearance all the time can choose those themes. You
9246 * should call this function only as a <emphasis>semantic</emphasis>
9247 * hint to the theme engine that your tree makes alternating colors
9248 * useful from a functional standpoint (since it has lots of columns,
9253 pspp_sheet_view_set_rules_hint (PsppSheetView *tree_view,
9256 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9258 setting = setting != FALSE;
9260 if (tree_view->priv->has_rules != setting)
9262 tree_view->priv->has_rules = setting;
9263 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
9266 g_object_notify (G_OBJECT (tree_view), "rules-hint");
9270 * pspp_sheet_view_get_rules_hint
9271 * @tree_view: a #PsppSheetView
9273 * Gets the setting set by pspp_sheet_view_set_rules_hint().
9275 * Return value: %TRUE if rules are useful for the user of this tree
9278 pspp_sheet_view_get_rules_hint (PsppSheetView *tree_view)
9280 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9282 return tree_view->priv->has_rules;
9285 /* Public Column functions
9289 * pspp_sheet_view_append_column:
9290 * @tree_view: A #PsppSheetView.
9291 * @column: The #PsppSheetViewColumn to add.
9293 * Appends @column to the list of columns.
9295 * Return value: The number of columns in @tree_view after appending.
9298 pspp_sheet_view_append_column (PsppSheetView *tree_view,
9299 PsppSheetViewColumn *column)
9301 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9302 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9303 g_return_val_if_fail (column->tree_view == NULL, -1);
9305 return pspp_sheet_view_insert_column (tree_view, column, -1);
9310 * pspp_sheet_view_remove_column:
9311 * @tree_view: A #PsppSheetView.
9312 * @column: The #PsppSheetViewColumn to remove.
9314 * Removes @column from @tree_view.
9316 * Return value: The number of columns in @tree_view after removing.
9319 pspp_sheet_view_remove_column (PsppSheetView *tree_view,
9320 PsppSheetViewColumn *column)
9322 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9323 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9324 g_return_val_if_fail (column->tree_view == GTK_WIDGET (tree_view), -1);
9326 if (tree_view->priv->focus_column == column)
9327 tree_view->priv->focus_column = NULL;
9329 if (tree_view->priv->edited_column == column)
9331 pspp_sheet_view_stop_editing (tree_view, TRUE);
9333 /* no need to, but just to be sure ... */
9334 tree_view->priv->edited_column = NULL;
9337 _pspp_sheet_view_column_unset_tree_view (column);
9339 tree_view->priv->columns = g_list_remove (tree_view->priv->columns, column);
9340 tree_view->priv->n_columns--;
9342 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9346 _pspp_sheet_view_column_unrealize_button (column);
9347 for (list = tree_view->priv->columns; list; list = list->next)
9349 PsppSheetViewColumn *tmp_column;
9351 tmp_column = PSPP_SHEET_VIEW_COLUMN (list->data);
9352 if (tmp_column->visible)
9353 _pspp_sheet_view_column_cell_set_dirty (tmp_column);
9356 if (tree_view->priv->n_columns == 0 &&
9357 pspp_sheet_view_get_headers_visible (tree_view) &&
9358 tree_view->priv->header_window)
9359 gdk_window_hide (tree_view->priv->header_window);
9361 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9364 g_object_unref (column);
9365 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9367 return tree_view->priv->n_columns;
9371 * pspp_sheet_view_insert_column:
9372 * @tree_view: A #PsppSheetView.
9373 * @column: The #PsppSheetViewColumn to be inserted.
9374 * @position: The position to insert @column in.
9376 * This inserts the @column into the @tree_view at @position. If @position is
9377 * -1, then the column is inserted at the end.
9379 * Return value: The number of columns in @tree_view after insertion.
9382 pspp_sheet_view_insert_column (PsppSheetView *tree_view,
9383 PsppSheetViewColumn *column,
9386 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9387 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9388 g_return_val_if_fail (column->tree_view == NULL, -1);
9390 g_object_ref_sink (column);
9392 if (tree_view->priv->n_columns == 0 &&
9393 gtk_widget_get_realized (GTK_WIDGET (tree_view)) &&
9394 pspp_sheet_view_get_headers_visible (tree_view))
9396 gdk_window_show (tree_view->priv->header_window);
9399 tree_view->priv->columns = g_list_insert (tree_view->priv->columns,
9401 tree_view->priv->n_columns++;
9403 _pspp_sheet_view_column_set_tree_view (column, tree_view);
9405 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9409 _pspp_sheet_view_column_realize_button (column);
9411 for (list = tree_view->priv->columns; list; list = list->next)
9413 column = PSPP_SHEET_VIEW_COLUMN (list->data);
9414 if (column->visible)
9415 _pspp_sheet_view_column_cell_set_dirty (column);
9417 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9420 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9422 return tree_view->priv->n_columns;
9426 * pspp_sheet_view_insert_column_with_attributes:
9427 * @tree_view: A #PsppSheetView
9428 * @position: The position to insert the new column in.
9429 * @title: The title to set the header to.
9430 * @cell: The #GtkCellRenderer.
9431 * @Varargs: A %NULL-terminated list of attributes.
9433 * Creates a new #PsppSheetViewColumn and inserts it into the @tree_view at
9434 * @position. If @position is -1, then the newly created column is inserted at
9435 * the end. The column is initialized with the attributes given.
9437 * Return value: The number of columns in @tree_view after insertion.
9440 pspp_sheet_view_insert_column_with_attributes (PsppSheetView *tree_view,
9443 GtkCellRenderer *cell,
9446 PsppSheetViewColumn *column;
9451 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9453 column = pspp_sheet_view_column_new ();
9454 pspp_sheet_view_column_set_title (column, title);
9455 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9457 va_start (args, cell);
9459 attribute = va_arg (args, gchar *);
9461 while (attribute != NULL)
9463 column_id = va_arg (args, gint);
9464 pspp_sheet_view_column_add_attribute (column, cell, attribute, column_id);
9465 attribute = va_arg (args, gchar *);
9470 pspp_sheet_view_insert_column (tree_view, column, position);
9472 return tree_view->priv->n_columns;
9476 * pspp_sheet_view_insert_column_with_data_func:
9477 * @tree_view: a #PsppSheetView
9478 * @position: Position to insert, -1 for append
9479 * @title: column title
9480 * @cell: cell renderer for column
9481 * @func: function to set attributes of cell renderer
9482 * @data: data for @func
9483 * @dnotify: destroy notifier for @data
9485 * Convenience function that inserts a new column into the #PsppSheetView
9486 * with the given cell renderer and a #GtkCellDataFunc to set cell renderer
9487 * attributes (normally using data from the model). See also
9488 * pspp_sheet_view_column_set_cell_data_func(), pspp_sheet_view_column_pack_start().
9490 * Return value: number of columns in the tree view post-insert
9493 pspp_sheet_view_insert_column_with_data_func (PsppSheetView *tree_view,
9496 GtkCellRenderer *cell,
9497 PsppSheetCellDataFunc func,
9499 GDestroyNotify dnotify)
9501 PsppSheetViewColumn *column;
9503 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9505 column = pspp_sheet_view_column_new ();
9506 pspp_sheet_view_column_set_title (column, title);
9507 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9508 pspp_sheet_view_column_set_cell_data_func (column, cell, func, data, dnotify);
9510 pspp_sheet_view_insert_column (tree_view, column, position);
9512 return tree_view->priv->n_columns;
9516 * pspp_sheet_view_get_column:
9517 * @tree_view: A #PsppSheetView.
9518 * @n: The position of the column, counting from 0.
9520 * Gets the #PsppSheetViewColumn at the given position in the #tree_view.
9522 * Return value: The #PsppSheetViewColumn, or %NULL if the position is outside the
9525 PsppSheetViewColumn *
9526 pspp_sheet_view_get_column (PsppSheetView *tree_view,
9529 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9531 if (n < 0 || n >= tree_view->priv->n_columns)
9534 if (tree_view->priv->columns == NULL)
9537 return PSPP_SHEET_VIEW_COLUMN (g_list_nth (tree_view->priv->columns, n)->data);
9541 * pspp_sheet_view_get_columns:
9542 * @tree_view: A #PsppSheetView
9544 * Returns a #GList of all the #PsppSheetViewColumn s currently in @tree_view.
9545 * The returned list must be freed with g_list_free ().
9547 * Return value: (element-type PsppSheetViewColumn) (transfer container): A list of #PsppSheetViewColumn s
9550 pspp_sheet_view_get_columns (PsppSheetView *tree_view)
9552 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9554 return g_list_copy (tree_view->priv->columns);
9558 * pspp_sheet_view_move_column_after:
9559 * @tree_view: A #PsppSheetView
9560 * @column: The #PsppSheetViewColumn to be moved.
9561 * @base_column: (allow-none): The #PsppSheetViewColumn to be moved relative to, or %NULL.
9563 * Moves @column to be after to @base_column. If @base_column is %NULL, then
9564 * @column is placed in the first position.
9567 pspp_sheet_view_move_column_after (PsppSheetView *tree_view,
9568 PsppSheetViewColumn *column,
9569 PsppSheetViewColumn *base_column)
9571 GList *column_list_el, *base_el = NULL;
9573 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9575 column_list_el = g_list_find (tree_view->priv->columns, column);
9576 g_return_if_fail (column_list_el != NULL);
9580 base_el = g_list_find (tree_view->priv->columns, base_column);
9581 g_return_if_fail (base_el != NULL);
9584 if (column_list_el->prev == base_el)
9587 tree_view->priv->columns = g_list_remove_link (tree_view->priv->columns, column_list_el);
9588 if (base_el == NULL)
9590 column_list_el->prev = NULL;
9591 column_list_el->next = tree_view->priv->columns;
9592 if (column_list_el->next)
9593 column_list_el->next->prev = column_list_el;
9594 tree_view->priv->columns = column_list_el;
9598 column_list_el->prev = base_el;
9599 column_list_el->next = base_el->next;
9600 if (column_list_el->next)
9601 column_list_el->next->prev = column_list_el;
9602 base_el->next = column_list_el;
9605 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9607 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9608 pspp_sheet_view_size_allocate_columns (GTK_WIDGET (tree_view), NULL);
9611 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9615 * pspp_sheet_view_set_column_drag_function:
9616 * @tree_view: A #PsppSheetView.
9617 * @func: (allow-none): A function to determine which columns are reorderable, or %NULL.
9618 * @user_data: (allow-none): User data to be passed to @func, or %NULL
9619 * @destroy: (allow-none): Destroy notifier for @user_data, or %NULL
9621 * Sets a user function for determining where a column may be dropped when
9622 * dragged. This function is called on every column pair in turn at the
9623 * beginning of a column drag to determine where a drop can take place. The
9624 * arguments passed to @func are: the @tree_view, the #PsppSheetViewColumn being
9625 * dragged, the two #PsppSheetViewColumn s determining the drop spot, and
9626 * @user_data. If either of the #PsppSheetViewColumn arguments for the drop spot
9627 * are %NULL, then they indicate an edge. If @func is set to be %NULL, then
9628 * @tree_view reverts to the default behavior of allowing all columns to be
9629 * dropped everywhere.
9632 pspp_sheet_view_set_column_drag_function (PsppSheetView *tree_view,
9633 PsppSheetViewColumnDropFunc func,
9635 GDestroyNotify destroy)
9637 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9639 if (tree_view->priv->column_drop_func_data_destroy)
9640 tree_view->priv->column_drop_func_data_destroy (tree_view->priv->column_drop_func_data);
9642 tree_view->priv->column_drop_func = func;
9643 tree_view->priv->column_drop_func_data = user_data;
9644 tree_view->priv->column_drop_func_data_destroy = destroy;
9648 * pspp_sheet_view_scroll_to_point:
9649 * @tree_view: a #PsppSheetView
9650 * @tree_x: X coordinate of new top-left pixel of visible area, or -1
9651 * @tree_y: Y coordinate of new top-left pixel of visible area, or -1
9653 * Scrolls the tree view such that the top-left corner of the visible
9654 * area is @tree_x, @tree_y, where @tree_x and @tree_y are specified
9655 * in tree coordinates. The @tree_view must be realized before
9656 * this function is called. If it isn't, you probably want to be
9657 * using pspp_sheet_view_scroll_to_cell().
9659 * If either @tree_x or @tree_y are -1, then that direction isn't scrolled.
9662 pspp_sheet_view_scroll_to_point (PsppSheetView *tree_view,
9666 GtkAdjustment *hadj;
9667 GtkAdjustment *vadj;
9669 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9670 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
9672 hadj = tree_view->priv->hadjustment;
9673 vadj = tree_view->priv->vadjustment;
9676 gtk_adjustment_set_value (hadj, CLAMP (tree_x, gtk_adjustment_get_lower (hadj), gtk_adjustment_get_upper (hadj) - gtk_adjustment_get_page_size (hadj)));
9678 gtk_adjustment_set_value (vadj, CLAMP (tree_y, gtk_adjustment_get_lower (vadj), gtk_adjustment_get_upper (vadj) - gtk_adjustment_get_page_size (vadj)));
9682 * pspp_sheet_view_scroll_to_cell:
9683 * @tree_view: A #PsppSheetView.
9684 * @path: (allow-none): The path of the row to move to, or %NULL.
9685 * @column: (allow-none): The #PsppSheetViewColumn to move horizontally to, or %NULL.
9686 * @use_align: whether to use alignment arguments, or %FALSE.
9687 * @row_align: The vertical alignment of the row specified by @path.
9688 * @col_align: The horizontal alignment of the column specified by @column.
9690 * Moves the alignments of @tree_view to the position specified by @column and
9691 * @path. If @column is %NULL, then no horizontal scrolling occurs. Likewise,
9692 * if @path is %NULL no vertical scrolling occurs. At a minimum, one of @column
9693 * or @path need to be non-%NULL. @row_align determines where the row is
9694 * placed, and @col_align determines where @column is placed. Both are expected
9695 * to be between 0.0 and 1.0. 0.0 means left/top alignment, 1.0 means
9696 * right/bottom alignment, 0.5 means center.
9698 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
9699 * tree does the minimum amount of work to scroll the cell onto the screen.
9700 * This means that the cell will be scrolled to the edge closest to its current
9701 * position. If the cell is currently visible on the screen, nothing is done.
9703 * This function only works if the model is set, and @path is a valid row on the
9704 * model. If the model changes before the @tree_view is realized, the centered
9705 * path will be modified to reflect this change.
9708 pspp_sheet_view_scroll_to_cell (PsppSheetView *tree_view,
9710 PsppSheetViewColumn *column,
9715 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9716 g_return_if_fail (tree_view->priv->model != NULL);
9717 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
9718 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
9719 g_return_if_fail (path != NULL || column != NULL);
9722 g_print ("pspp_sheet_view_scroll_to_cell:\npath: %s\ncolumn: %s\nuse_align: %d\nrow_align: %f\ncol_align: %f\n",
9723 gtk_tree_path_to_string (path), column?"non-null":"null", use_align, row_align, col_align);
9725 row_align = CLAMP (row_align, 0.0, 1.0);
9726 col_align = CLAMP (col_align, 0.0, 1.0);
9729 /* Note: Despite the benefits that come from having one code path for the
9730 * scrolling code, we short-circuit validate_visible_area's immplementation as
9731 * it is much slower than just going to the point.
9733 if (!gtk_widget_get_visible (GTK_WIDGET (tree_view)) ||
9734 !gtk_widget_get_realized (GTK_WIDGET (tree_view))
9735 /* XXX || GTK_WIDGET_ALLOC_NEEDED (tree_view) */)
9737 if (tree_view->priv->scroll_to_path)
9738 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9740 tree_view->priv->scroll_to_path = NULL;
9741 tree_view->priv->scroll_to_column = NULL;
9744 tree_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
9746 tree_view->priv->scroll_to_column = column;
9747 tree_view->priv->scroll_to_use_align = use_align;
9748 tree_view->priv->scroll_to_row_align = row_align;
9749 tree_view->priv->scroll_to_col_align = col_align;
9751 install_presize_handler (tree_view);
9755 GdkRectangle cell_rect;
9756 GdkRectangle vis_rect;
9757 gint dest_x, dest_y;
9759 pspp_sheet_view_get_background_area (tree_view, path, column, &cell_rect);
9760 pspp_sheet_view_get_visible_rect (tree_view, &vis_rect);
9762 cell_rect.y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, cell_rect.y);
9764 dest_x = vis_rect.x;
9765 dest_y = vis_rect.y;
9771 dest_x = cell_rect.x - ((vis_rect.width - cell_rect.width) * col_align);
9775 if (cell_rect.x < vis_rect.x)
9776 dest_x = cell_rect.x;
9777 if (cell_rect.x + cell_rect.width > vis_rect.x + vis_rect.width)
9778 dest_x = cell_rect.x + cell_rect.width - vis_rect.width;
9786 dest_y = cell_rect.y - ((vis_rect.height - cell_rect.height) * row_align);
9787 dest_y = MAX (dest_y, 0);
9791 if (cell_rect.y < vis_rect.y)
9792 dest_y = cell_rect.y;
9793 if (cell_rect.y + cell_rect.height > vis_rect.y + vis_rect.height)
9794 dest_y = cell_rect.y + cell_rect.height - vis_rect.height;
9798 pspp_sheet_view_scroll_to_point (tree_view, dest_x, dest_y);
9803 * pspp_sheet_view_row_activated:
9804 * @tree_view: A #PsppSheetView
9805 * @path: The #GtkTreePath to be activated.
9806 * @column: The #PsppSheetViewColumn to be activated.
9808 * Activates the cell determined by @path and @column.
9811 pspp_sheet_view_row_activated (PsppSheetView *tree_view,
9813 PsppSheetViewColumn *column)
9815 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9817 g_signal_emit (tree_view, tree_view_signals[ROW_ACTIVATED], 0, path, column);
9822 * pspp_sheet_view_get_reorderable:
9823 * @tree_view: a #PsppSheetView
9825 * Retrieves whether the user can reorder the tree via drag-and-drop. See
9826 * pspp_sheet_view_set_reorderable().
9828 * Return value: %TRUE if the tree can be reordered.
9831 pspp_sheet_view_get_reorderable (PsppSheetView *tree_view)
9833 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9835 return tree_view->priv->reorderable;
9839 * pspp_sheet_view_set_reorderable:
9840 * @tree_view: A #PsppSheetView.
9841 * @reorderable: %TRUE, if the tree can be reordered.
9843 * This function is a convenience function to allow you to reorder
9844 * models that support the #GtkDragSourceIface and the
9845 * #GtkDragDestIface. Both #GtkTreeStore and #GtkListStore support
9846 * these. If @reorderable is %TRUE, then the user can reorder the
9847 * model by dragging and dropping rows. The developer can listen to
9848 * these changes by connecting to the model's row_inserted and
9849 * row_deleted signals. The reordering is implemented by setting up
9850 * the tree view as a drag source and destination. Therefore, drag and
9851 * drop can not be used in a reorderable view for any other purpose.
9853 * This function does not give you any degree of control over the order -- any
9854 * reordering is allowed. If more control is needed, you should probably
9855 * handle drag and drop manually.
9858 pspp_sheet_view_set_reorderable (PsppSheetView *tree_view,
9859 gboolean reorderable)
9861 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9863 reorderable = reorderable != FALSE;
9865 if (tree_view->priv->reorderable == reorderable)
9870 const GtkTargetEntry row_targets[] = {
9871 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
9874 pspp_sheet_view_enable_model_drag_source (tree_view,
9877 G_N_ELEMENTS (row_targets),
9879 pspp_sheet_view_enable_model_drag_dest (tree_view,
9881 G_N_ELEMENTS (row_targets),
9886 pspp_sheet_view_unset_rows_drag_source (tree_view);
9887 pspp_sheet_view_unset_rows_drag_dest (tree_view);
9890 tree_view->priv->reorderable = reorderable;
9892 g_object_notify (G_OBJECT (tree_view), "reorderable");
9895 /* If CLEAR_AND_SELECT is true, then the row will be selected and, unless Shift
9896 is pressed, other rows will be unselected.
9898 If CLAMP_NODE is true, then the sheetview will scroll to make the row
9901 pspp_sheet_view_real_set_cursor (PsppSheetView *tree_view,
9903 gboolean clear_and_select,
9904 gboolean clamp_node,
9905 PsppSheetSelectMode mode)
9909 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
9911 GtkTreePath *cursor_path;
9912 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
9913 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
9914 gtk_tree_path_free (cursor_path);
9917 gtk_tree_row_reference_free (tree_view->priv->cursor);
9918 tree_view->priv->cursor = NULL;
9920 _pspp_sheet_view_find_node (tree_view, path, &node);
9921 tree_view->priv->cursor =
9922 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
9923 tree_view->priv->model,
9926 if (tree_view->priv->row_count > 0)
9930 if (clear_and_select && !(mode & PSPP_SHEET_SELECT_MODE_TOGGLE))
9931 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
9935 /* We have to re-find tree and node here again, somebody might have
9936 * cleared the node or the whole tree in the PsppSheetSelection::changed
9937 * callback. If the nodes differ we bail out here.
9939 _pspp_sheet_view_find_node (tree_view, path, &new_node);
9941 if (node != new_node)
9946 pspp_sheet_view_clamp_node_visible (tree_view, node);
9947 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
9951 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
9955 * pspp_sheet_view_get_cursor:
9956 * @tree_view: A #PsppSheetView
9957 * @path: (allow-none): A pointer to be filled with the current cursor path, or %NULL
9958 * @focus_column: (allow-none): A pointer to be filled with the current focus column, or %NULL
9960 * Fills in @path and @focus_column with the current path and focus column. If
9961 * the cursor isn't currently set, then *@path will be %NULL. If no column
9962 * currently has focus, then *@focus_column will be %NULL.
9964 * The returned #GtkTreePath must be freed with gtk_tree_path_free() when
9965 * you are done with it.
9968 pspp_sheet_view_get_cursor (PsppSheetView *tree_view,
9970 PsppSheetViewColumn **focus_column)
9972 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9976 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
9977 *path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
9984 *focus_column = tree_view->priv->focus_column;
9989 * pspp_sheet_view_set_cursor:
9990 * @tree_view: A #PsppSheetView
9991 * @path: A #GtkTreePath
9992 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
9993 * @start_editing: %TRUE if the specified cell should start being edited.
9995 * Sets the current keyboard focus to be at @path, and selects it. This is
9996 * useful when you want to focus the user's attention on a particular row. If
9997 * @focus_column is not %NULL, then focus is given to the column specified by
9998 * it. Additionally, if @focus_column is specified, and @start_editing is
9999 * %TRUE, then editing should be started in the specified cell.
10000 * This function is often followed by @gtk_widget_grab_focus (@tree_view)
10001 * in order to give keyboard focus to the widget. Please note that editing
10002 * can only happen when the widget is realized.
10004 * If @path is invalid for @model, the current cursor (if any) will be unset
10005 * and the function will return without failing.
10008 pspp_sheet_view_set_cursor (PsppSheetView *tree_view,
10010 PsppSheetViewColumn *focus_column,
10011 gboolean start_editing)
10013 pspp_sheet_view_set_cursor_on_cell (tree_view, path, focus_column,
10014 NULL, start_editing);
10018 * pspp_sheet_view_set_cursor_on_cell:
10019 * @tree_view: A #PsppSheetView
10020 * @path: A #GtkTreePath
10021 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
10022 * @focus_cell: (allow-none): A #GtkCellRenderer, or %NULL
10023 * @start_editing: %TRUE if the specified cell should start being edited.
10025 * Sets the current keyboard focus to be at @path, and selects it. This is
10026 * useful when you want to focus the user's attention on a particular row. If
10027 * @focus_column is not %NULL, then focus is given to the column specified by
10028 * it. If @focus_column and @focus_cell are not %NULL, and @focus_column
10029 * contains 2 or more editable or activatable cells, then focus is given to
10030 * the cell specified by @focus_cell. Additionally, if @focus_column is
10031 * specified, and @start_editing is %TRUE, then editing should be started in
10032 * the specified cell. This function is often followed by
10033 * @gtk_widget_grab_focus (@tree_view) in order to give keyboard focus to the
10034 * widget. Please note that editing can only happen when the widget is
10037 * If @path is invalid for @model, the current cursor (if any) will be unset
10038 * and the function will return without failing.
10043 pspp_sheet_view_set_cursor_on_cell (PsppSheetView *tree_view,
10045 PsppSheetViewColumn *focus_column,
10046 GtkCellRenderer *focus_cell,
10047 gboolean start_editing)
10049 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10050 g_return_if_fail (path != NULL);
10051 g_return_if_fail (focus_column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (focus_column));
10053 if (!tree_view->priv->model)
10058 g_return_if_fail (focus_column);
10059 g_return_if_fail (GTK_IS_CELL_RENDERER (focus_cell));
10062 /* cancel the current editing, if it exists */
10063 if (tree_view->priv->edited_column &&
10064 tree_view->priv->edited_column->editable_widget)
10065 pspp_sheet_view_stop_editing (tree_view, TRUE);
10067 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, 0);
10069 if (focus_column && focus_column->visible)
10072 gboolean column_in_tree = FALSE;
10074 for (list = tree_view->priv->columns; list; list = list->next)
10075 if (list->data == focus_column)
10077 column_in_tree = TRUE;
10080 g_return_if_fail (column_in_tree);
10081 tree_view->priv->focus_column = focus_column;
10083 pspp_sheet_view_column_focus_cell (focus_column, focus_cell);
10085 pspp_sheet_view_start_editing (tree_view, path);
10087 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
10088 pspp_sheet_selection_select_column (tree_view->priv->selection, focus_column);
10094 * pspp_sheet_view_get_bin_window:
10095 * @tree_view: A #PsppSheetView
10097 * Returns the window that @tree_view renders to. This is used primarily to
10098 * compare to <literal>event->window</literal> to confirm that the event on
10099 * @tree_view is on the right window.
10101 * Return value: A #GdkWindow, or %NULL when @tree_view hasn't been realized yet
10104 pspp_sheet_view_get_bin_window (PsppSheetView *tree_view)
10106 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
10108 return tree_view->priv->bin_window;
10112 * pspp_sheet_view_get_path_at_pos:
10113 * @tree_view: A #PsppSheetView.
10114 * @x: The x position to be identified (relative to bin_window).
10115 * @y: The y position to be identified (relative to bin_window).
10116 * @path: (out) (allow-none): A pointer to a #GtkTreePath pointer to be filled in, or %NULL
10117 * @column: (out) (allow-none): A pointer to a #PsppSheetViewColumn pointer to be filled in, or %NULL
10118 * @cell_x: (out) (allow-none): A pointer where the X coordinate relative to the cell can be placed, or %NULL
10119 * @cell_y: (out) (allow-none): A pointer where the Y coordinate relative to the cell can be placed, or %NULL
10121 * Finds the path at the point (@x, @y), relative to bin_window coordinates
10122 * (please see pspp_sheet_view_get_bin_window()).
10123 * That is, @x and @y are relative to an events coordinates. @x and @y must
10124 * come from an event on the @tree_view only where <literal>event->window ==
10125 * pspp_sheet_view_get_bin_window (<!-- -->)</literal>. It is primarily for
10126 * things like popup menus. If @path is non-%NULL, then it will be filled
10127 * with the #GtkTreePath at that point. This path should be freed with
10128 * gtk_tree_path_free(). If @column is non-%NULL, then it will be filled
10129 * with the column at that point. @cell_x and @cell_y return the coordinates
10130 * relative to the cell background (i.e. the @background_area passed to
10131 * gtk_cell_renderer_render()). This function is only meaningful if
10132 * @tree_view is realized. Therefore this function will always return %FALSE
10133 * if @tree_view is not realized or does not have a model.
10135 * For converting widget coordinates (eg. the ones you get from
10136 * GtkWidget::query-tooltip), please see
10137 * pspp_sheet_view_convert_widget_to_bin_window_coords().
10139 * Return value: %TRUE if a row exists at that coordinate.
10142 pspp_sheet_view_get_path_at_pos (PsppSheetView *tree_view,
10145 GtkTreePath **path,
10146 PsppSheetViewColumn **column,
10153 g_return_val_if_fail (tree_view != NULL, FALSE);
10160 if (tree_view->priv->bin_window == NULL)
10163 if (tree_view->priv->row_count == 0)
10166 if (x > gtk_adjustment_get_upper (tree_view->priv->hadjustment))
10169 if (x < 0 || y < 0)
10172 if (column || cell_x)
10174 PsppSheetViewColumn *tmp_column;
10175 PsppSheetViewColumn *last_column = NULL;
10177 gint remaining_x = x;
10178 gboolean found = FALSE;
10181 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
10182 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
10184 list = (rtl ? list->prev : list->next))
10186 tmp_column = list->data;
10188 if (tmp_column->visible == FALSE)
10191 last_column = tmp_column;
10192 if (remaining_x <= tmp_column->width)
10197 *column = tmp_column;
10200 *cell_x = remaining_x;
10204 remaining_x -= tmp_column->width;
10207 /* If found is FALSE and there is a last_column, then it the remainder
10208 * space is in that area
10215 *column = last_column;
10218 *cell_x = last_column->width + remaining_x;
10227 y_offset = pspp_sheet_view_find_offset (tree_view,
10228 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, y),
10235 *cell_y = y_offset;
10238 *path = _pspp_sheet_view_find_path (tree_view, node);
10243 /* Computes 'cell_area' from 'background_area', which must be the background
10244 area for a cell. Set 'subtract_focus_rect' to TRUE to compute the cell area
10245 as passed to a GtkCellRenderer's "render" function, or to FALSE to compute
10246 the cell area as passed to _pspp_sheet_view_column_cell_render().
10248 'column' is required to properly adjust 'cell_area->x' and
10249 'cell_area->width'. It may be set to NULL if these values are not of
10250 interest. In this case 'cell_area->x' and 'cell_area->width' will be
10253 pspp_sheet_view_adjust_cell_area (PsppSheetView *tree_view,
10254 PsppSheetViewColumn *column,
10255 const GdkRectangle *background_area,
10256 gboolean subtract_focus_rect,
10257 GdkRectangle *cell_area)
10259 gint vertical_separator;
10260 gint horizontal_separator;
10262 *cell_area = *background_area;
10264 gtk_widget_style_get (GTK_WIDGET (tree_view),
10265 "vertical-separator", &vertical_separator,
10266 "horizontal-separator", &horizontal_separator,
10268 cell_area->x += horizontal_separator / 2;
10269 cell_area->y += vertical_separator / 2;
10270 cell_area->width -= horizontal_separator;
10271 cell_area->height -= vertical_separator;
10273 if (subtract_focus_rect)
10275 int focus_line_width;
10277 gtk_widget_style_get (GTK_WIDGET (tree_view),
10278 "focus-line-width", &focus_line_width,
10280 cell_area->x += focus_line_width;
10281 cell_area->y += focus_line_width;
10282 cell_area->width -= 2 * focus_line_width;
10283 cell_area->height -= 2 * focus_line_width;
10286 if (tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_NONE)
10288 gint grid_line_width;
10289 gtk_widget_style_get (GTK_WIDGET (tree_view),
10290 "grid-line-width", &grid_line_width,
10293 if ((tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
10294 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10297 PsppSheetViewColumn *first_column, *last_column;
10300 /* Find the last visible column. */
10301 last_column = NULL;
10302 for (list = g_list_last (tree_view->priv->columns);
10306 PsppSheetViewColumn *c = list->data;
10314 /* Find the first visible column. */
10315 first_column = NULL;
10316 for (list = g_list_first (tree_view->priv->columns);
10320 PsppSheetViewColumn *c = list->data;
10328 if (column == first_column)
10330 cell_area->width -= grid_line_width / 2;
10332 else if (column == last_column)
10334 cell_area->x += grid_line_width / 2;
10335 cell_area->width -= grid_line_width / 2;
10339 cell_area->x += grid_line_width / 2;
10340 cell_area->width -= grid_line_width;
10344 if (tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
10345 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10347 cell_area->y += grid_line_width / 2;
10348 cell_area->height -= grid_line_width;
10352 if (column == NULL)
10355 cell_area->width = 0;
10360 * pspp_sheet_view_get_cell_area:
10361 * @tree_view: a #PsppSheetView
10362 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10363 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordinates
10364 * @rect: rectangle to fill with cell rect
10366 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10367 * row specified by @path and the column specified by @column. If @path is
10368 * %NULL, or points to a path not currently displayed, the @y and @height fields
10369 * of the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10370 * fields will be filled with 0. The sum of all cell rects does not cover the
10371 * entire tree; there are extra pixels in between rows, for example. The
10372 * returned rectangle is equivalent to the @cell_area passed to
10373 * gtk_cell_renderer_render(). This function is only valid if @tree_view is
10377 pspp_sheet_view_get_cell_area (PsppSheetView *tree_view,
10379 PsppSheetViewColumn *column,
10380 GdkRectangle *rect)
10382 GdkRectangle background_area;
10384 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10385 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10386 g_return_if_fail (rect != NULL);
10387 g_return_if_fail (!column || column->tree_view == (GtkWidget *) tree_view);
10388 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
10390 pspp_sheet_view_get_background_area (tree_view, path, column,
10392 pspp_sheet_view_adjust_cell_area (tree_view, column, &background_area,
10397 * pspp_sheet_view_get_background_area:
10398 * @tree_view: a #PsppSheetView
10399 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10400 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordiantes
10401 * @rect: rectangle to fill with cell background rect
10403 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10404 * row specified by @path and the column specified by @column. If @path is
10405 * %NULL, or points to a node not found in the tree, the @y and @height fields of
10406 * the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10407 * fields will be filled with 0. The returned rectangle is equivalent to the
10408 * @background_area passed to gtk_cell_renderer_render(). These background
10409 * areas tile to cover the entire bin window. Contrast with the @cell_area,
10410 * returned by pspp_sheet_view_get_cell_area(), which returns only the cell
10411 * itself, excluding surrounding borders.
10415 pspp_sheet_view_get_background_area (PsppSheetView *tree_view,
10417 PsppSheetViewColumn *column,
10418 GdkRectangle *rect)
10422 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10423 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10424 g_return_if_fail (rect != NULL);
10433 /* Get vertical coords */
10435 _pspp_sheet_view_find_node (tree_view, path, &node);
10439 rect->y = BACKGROUND_FIRST_PIXEL (tree_view, node);
10441 rect->height = ROW_HEIGHT (tree_view);
10448 pspp_sheet_view_get_background_xrange (tree_view, column, &rect->x, &x2);
10449 rect->width = x2 - rect->x;
10454 * pspp_sheet_view_get_visible_rect:
10455 * @tree_view: a #PsppSheetView
10456 * @visible_rect: rectangle to fill
10458 * Fills @visible_rect with the currently-visible region of the
10459 * buffer, in tree coordinates. Convert to bin_window coordinates with
10460 * pspp_sheet_view_convert_tree_to_bin_window_coords().
10461 * Tree coordinates start at 0,0 for row 0 of the tree, and cover the entire
10462 * scrollable area of the tree.
10465 pspp_sheet_view_get_visible_rect (PsppSheetView *tree_view,
10466 GdkRectangle *visible_rect)
10470 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10472 widget = GTK_WIDGET (tree_view);
10476 GtkAllocation allocation;
10477 gtk_widget_get_allocation (widget, &allocation);
10478 visible_rect->x = gtk_adjustment_get_value (tree_view->priv->hadjustment);
10479 visible_rect->y = gtk_adjustment_get_value (tree_view->priv->vadjustment);
10480 visible_rect->width = allocation.width;
10481 visible_rect->height = allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
10486 * pspp_sheet_view_widget_to_tree_coords:
10487 * @tree_view: a #PsppSheetView
10488 * @wx: X coordinate relative to bin_window
10489 * @wy: Y coordinate relative to bin_window
10490 * @tx: return location for tree X coordinate
10491 * @ty: return location for tree Y coordinate
10493 * Converts bin_window coordinates to coordinates for the
10494 * tree (the full scrollable area of the tree).
10496 * Deprecated: 2.12: Due to historial reasons the name of this function is
10497 * incorrect. For converting coordinates relative to the widget to
10498 * bin_window coordinates, please see
10499 * pspp_sheet_view_convert_widget_to_bin_window_coords().
10503 pspp_sheet_view_widget_to_tree_coords (PsppSheetView *tree_view,
10509 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10512 *tx = wx + gtk_adjustment_get_value (tree_view->priv->hadjustment);
10514 *ty = wy + tree_view->priv->dy;
10518 * pspp_sheet_view_tree_to_widget_coords:
10519 * @tree_view: a #PsppSheetView
10520 * @tx: tree X coordinate
10521 * @ty: tree Y coordinate
10522 * @wx: return location for X coordinate relative to bin_window
10523 * @wy: return location for Y coordinate relative to bin_window
10525 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10526 * to bin_window coordinates.
10528 * Deprecated: 2.12: Due to historial reasons the name of this function is
10529 * incorrect. For converting bin_window coordinates to coordinates relative
10530 * to bin_window, please see
10531 * pspp_sheet_view_convert_bin_window_to_widget_coords().
10535 pspp_sheet_view_tree_to_widget_coords (PsppSheetView *tree_view,
10541 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10544 *wx = tx - gtk_adjustment_get_value (tree_view->priv->hadjustment);
10546 *wy = ty - tree_view->priv->dy;
10551 * pspp_sheet_view_convert_widget_to_tree_coords:
10552 * @tree_view: a #PsppSheetView
10553 * @wx: X coordinate relative to the widget
10554 * @wy: Y coordinate relative to the widget
10555 * @tx: return location for tree X coordinate
10556 * @ty: return location for tree Y coordinate
10558 * Converts widget coordinates to coordinates for the
10559 * tree (the full scrollable area of the tree).
10564 pspp_sheet_view_convert_widget_to_tree_coords (PsppSheetView *tree_view,
10572 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10574 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view,
10577 pspp_sheet_view_convert_bin_window_to_tree_coords (tree_view,
10583 * pspp_sheet_view_convert_tree_to_widget_coords:
10584 * @tree_view: a #PsppSheetView
10585 * @tx: X coordinate relative to the tree
10586 * @ty: Y coordinate relative to the tree
10587 * @wx: return location for widget X coordinate
10588 * @wy: return location for widget Y coordinate
10590 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10591 * to widget coordinates.
10596 pspp_sheet_view_convert_tree_to_widget_coords (PsppSheetView *tree_view,
10604 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10606 pspp_sheet_view_convert_tree_to_bin_window_coords (tree_view,
10609 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
10615 * pspp_sheet_view_convert_widget_to_bin_window_coords:
10616 * @tree_view: a #PsppSheetView
10617 * @wx: X coordinate relative to the widget
10618 * @wy: Y coordinate relative to the widget
10619 * @bx: return location for bin_window X coordinate
10620 * @by: return location for bin_window Y coordinate
10622 * Converts widget coordinates to coordinates for the bin_window
10623 * (see pspp_sheet_view_get_bin_window()).
10628 pspp_sheet_view_convert_widget_to_bin_window_coords (PsppSheetView *tree_view,
10634 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10637 *bx = wx + gtk_adjustment_get_value (tree_view->priv->hadjustment);
10639 *by = wy - TREE_VIEW_HEADER_HEIGHT (tree_view);
10643 * pspp_sheet_view_convert_bin_window_to_widget_coords:
10644 * @tree_view: a #PsppSheetView
10645 * @bx: bin_window X coordinate
10646 * @by: bin_window Y coordinate
10647 * @wx: return location for widget X coordinate
10648 * @wy: return location for widget Y coordinate
10650 * Converts bin_window coordinates (see pspp_sheet_view_get_bin_window())
10651 * to widget relative coordinates.
10656 pspp_sheet_view_convert_bin_window_to_widget_coords (PsppSheetView *tree_view,
10662 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10665 *wx = bx - gtk_adjustment_get_value (tree_view->priv->hadjustment);
10667 *wy = by + TREE_VIEW_HEADER_HEIGHT (tree_view);
10671 * pspp_sheet_view_convert_tree_to_bin_window_coords:
10672 * @tree_view: a #PsppSheetView
10673 * @tx: tree X coordinate
10674 * @ty: tree Y coordinate
10675 * @bx: return location for X coordinate relative to bin_window
10676 * @by: return location for Y coordinate relative to bin_window
10678 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10679 * to bin_window coordinates.
10684 pspp_sheet_view_convert_tree_to_bin_window_coords (PsppSheetView *tree_view,
10690 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10695 *by = ty - tree_view->priv->dy;
10699 * pspp_sheet_view_convert_bin_window_to_tree_coords:
10700 * @tree_view: a #PsppSheetView
10701 * @bx: X coordinate relative to bin_window
10702 * @by: Y coordinate relative to bin_window
10703 * @tx: return location for tree X coordinate
10704 * @ty: return location for tree Y coordinate
10706 * Converts bin_window coordinates to coordinates for the
10707 * tree (the full scrollable area of the tree).
10712 pspp_sheet_view_convert_bin_window_to_tree_coords (PsppSheetView *tree_view,
10718 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10723 *ty = by + tree_view->priv->dy;
10729 * pspp_sheet_view_get_visible_range:
10730 * @tree_view: A #PsppSheetView
10731 * @start_path: (allow-none): Return location for start of region, or %NULL.
10732 * @end_path: (allow-none): Return location for end of region, or %NULL.
10734 * Sets @start_path and @end_path to be the first and last visible path.
10735 * Note that there may be invisible paths in between.
10737 * The paths should be freed with gtk_tree_path_free() after use.
10739 * Returns: %TRUE, if valid paths were placed in @start_path and @end_path.
10744 pspp_sheet_view_get_visible_range (PsppSheetView *tree_view,
10745 GtkTreePath **start_path,
10746 GtkTreePath **end_path)
10751 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
10753 if (!tree_view->priv->row_count)
10760 pspp_sheet_view_find_offset (tree_view,
10761 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, 0),
10764 *start_path = _pspp_sheet_view_find_path (tree_view, node);
10773 if (tree_view->priv->height < gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
10774 y = tree_view->priv->height - 1;
10776 y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, gtk_adjustment_get_page_size (tree_view->priv->vadjustment)) - 1;
10778 pspp_sheet_view_find_offset (tree_view, y, &node);
10780 *end_path = _pspp_sheet_view_find_path (tree_view, node);
10789 unset_reorderable (PsppSheetView *tree_view)
10791 if (tree_view->priv->reorderable)
10793 tree_view->priv->reorderable = FALSE;
10794 g_object_notify (G_OBJECT (tree_view), "reorderable");
10799 * pspp_sheet_view_enable_model_drag_source:
10800 * @tree_view: a #PsppSheetView
10801 * @start_button_mask: Mask of allowed buttons to start drag
10802 * @targets: the table of targets that the drag will support
10803 * @n_targets: the number of items in @targets
10804 * @actions: the bitmask of possible actions for a drag from this
10807 * Turns @tree_view into a drag source for automatic DND. Calling this
10808 * method sets #PsppSheetView:reorderable to %FALSE.
10811 pspp_sheet_view_enable_model_drag_source (PsppSheetView *tree_view,
10812 GdkModifierType start_button_mask,
10813 const GtkTargetEntry *targets,
10815 GdkDragAction actions)
10817 TreeViewDragInfo *di;
10819 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10821 gtk_drag_source_set (GTK_WIDGET (tree_view),
10827 di = ensure_info (tree_view);
10829 di->start_button_mask = start_button_mask;
10830 di->source_actions = actions;
10831 di->source_set = TRUE;
10833 unset_reorderable (tree_view);
10837 * pspp_sheet_view_enable_model_drag_dest:
10838 * @tree_view: a #PsppSheetView
10839 * @targets: the table of targets that the drag will support
10840 * @n_targets: the number of items in @targets
10841 * @actions: the bitmask of possible actions for a drag from this
10844 * Turns @tree_view into a drop destination for automatic DND. Calling
10845 * this method sets #PsppSheetView:reorderable to %FALSE.
10848 pspp_sheet_view_enable_model_drag_dest (PsppSheetView *tree_view,
10849 const GtkTargetEntry *targets,
10851 GdkDragAction actions)
10853 TreeViewDragInfo *di;
10855 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10857 gtk_drag_dest_set (GTK_WIDGET (tree_view),
10863 di = ensure_info (tree_view);
10864 di->dest_set = TRUE;
10866 unset_reorderable (tree_view);
10870 * pspp_sheet_view_unset_rows_drag_source:
10871 * @tree_view: a #PsppSheetView
10873 * Undoes the effect of
10874 * pspp_sheet_view_enable_model_drag_source(). Calling this method sets
10875 * #PsppSheetView:reorderable to %FALSE.
10878 pspp_sheet_view_unset_rows_drag_source (PsppSheetView *tree_view)
10880 TreeViewDragInfo *di;
10882 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10884 di = get_info (tree_view);
10888 if (di->source_set)
10890 gtk_drag_source_unset (GTK_WIDGET (tree_view));
10891 di->source_set = FALSE;
10894 if (!di->dest_set && !di->source_set)
10895 remove_info (tree_view);
10898 unset_reorderable (tree_view);
10902 * pspp_sheet_view_unset_rows_drag_dest:
10903 * @tree_view: a #PsppSheetView
10905 * Undoes the effect of
10906 * pspp_sheet_view_enable_model_drag_dest(). Calling this method sets
10907 * #PsppSheetView:reorderable to %FALSE.
10910 pspp_sheet_view_unset_rows_drag_dest (PsppSheetView *tree_view)
10912 TreeViewDragInfo *di;
10914 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10916 di = get_info (tree_view);
10922 gtk_drag_dest_unset (GTK_WIDGET (tree_view));
10923 di->dest_set = FALSE;
10926 if (!di->dest_set && !di->source_set)
10927 remove_info (tree_view);
10930 unset_reorderable (tree_view);
10934 * pspp_sheet_view_set_drag_dest_row:
10935 * @tree_view: a #PsppSheetView
10936 * @path: (allow-none): The path of the row to highlight, or %NULL.
10937 * @pos: Specifies whether to drop before, after or into the row
10939 * Sets the row that is highlighted for feedback.
10942 pspp_sheet_view_set_drag_dest_row (PsppSheetView *tree_view,
10944 PsppSheetViewDropPosition pos)
10946 GtkTreePath *current_dest;
10948 /* Note; this function is exported to allow a custom DND
10949 * implementation, so it can't touch TreeViewDragInfo
10952 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10954 current_dest = NULL;
10956 if (tree_view->priv->drag_dest_row)
10958 current_dest = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
10959 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
10962 /* special case a drop on an empty model */
10963 tree_view->priv->empty_view_drop = 0;
10965 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE && path
10966 && gtk_tree_path_get_depth (path) == 1
10967 && gtk_tree_path_get_indices (path)[0] == 0)
10971 n_children = gtk_tree_model_iter_n_children (tree_view->priv->model,
10975 tree_view->priv->empty_view_drop = 1;
10978 tree_view->priv->drag_dest_pos = pos;
10982 tree_view->priv->drag_dest_row =
10983 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
10984 pspp_sheet_view_queue_draw_path (tree_view, path, NULL);
10987 tree_view->priv->drag_dest_row = NULL;
10991 int node, new_node;
10993 _pspp_sheet_view_find_node (tree_view, current_dest, &node);
10994 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
10998 new_node = pspp_sheet_view_node_next (tree_view, node);
11000 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
11002 new_node = pspp_sheet_view_node_prev (tree_view, node);
11004 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
11006 gtk_tree_path_free (current_dest);
11011 * pspp_sheet_view_get_drag_dest_row:
11012 * @tree_view: a #PsppSheetView
11013 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
11014 * @pos: (allow-none): Return location for the drop position, or %NULL
11016 * Gets information about the row that is highlighted for feedback.
11019 pspp_sheet_view_get_drag_dest_row (PsppSheetView *tree_view,
11020 GtkTreePath **path,
11021 PsppSheetViewDropPosition *pos)
11023 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11027 if (tree_view->priv->drag_dest_row)
11028 *path = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
11031 if (tree_view->priv->empty_view_drop)
11032 *path = gtk_tree_path_new_from_indices (0, -1);
11039 *pos = tree_view->priv->drag_dest_pos;
11043 * pspp_sheet_view_get_dest_row_at_pos:
11044 * @tree_view: a #PsppSheetView
11045 * @drag_x: the position to determine the destination row for
11046 * @drag_y: the position to determine the destination row for
11047 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
11048 * @pos: (allow-none): Return location for the drop position, or %NULL
11050 * Determines the destination row for a given position. @drag_x and
11051 * @drag_y are expected to be in widget coordinates. This function is only
11052 * meaningful if @tree_view is realized. Therefore this function will always
11053 * return %FALSE if @tree_view is not realized or does not have a model.
11055 * Return value: whether there is a row at the given position, %TRUE if this
11056 * is indeed the case.
11059 pspp_sheet_view_get_dest_row_at_pos (PsppSheetView *tree_view,
11062 GtkTreePath **path,
11063 PsppSheetViewDropPosition *pos)
11067 gdouble offset_into_row;
11070 PsppSheetViewColumn *column = NULL;
11071 GtkTreePath *tmp_path = NULL;
11073 /* Note; this function is exported to allow a custom DND
11074 * implementation, so it can't touch TreeViewDragInfo
11077 g_return_val_if_fail (tree_view != NULL, FALSE);
11078 g_return_val_if_fail (drag_x >= 0, FALSE);
11079 g_return_val_if_fail (drag_y >= 0, FALSE);
11084 if (tree_view->priv->bin_window == NULL)
11087 if (tree_view->priv->row_count == 0)
11090 /* If in the top third of a row, we drop before that row; if
11091 * in the bottom third, drop after that row; if in the middle,
11092 * and the row has children, drop into the row.
11094 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, drag_x, drag_y,
11097 if (!pspp_sheet_view_get_path_at_pos (tree_view,
11106 pspp_sheet_view_get_background_area (tree_view, tmp_path, column,
11109 offset_into_row = cell_y;
11114 gtk_tree_path_free (tmp_path);
11118 third = cell.height / 3.0;
11122 if (offset_into_row < third)
11124 *pos = PSPP_SHEET_VIEW_DROP_BEFORE;
11126 else if (offset_into_row < (cell.height / 2.0))
11128 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE;
11130 else if (offset_into_row < third * 2.0)
11132 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER;
11136 *pos = PSPP_SHEET_VIEW_DROP_AFTER;
11144 #if GTK3_TRANSITION
11145 /* KEEP IN SYNC WITH PSPP_SHEET_VIEW_BIN_EXPOSE */
11147 * pspp_sheet_view_create_row_drag_icon:
11148 * @tree_view: a #PsppSheetView
11149 * @path: a #GtkTreePath in @tree_view
11151 * Creates a #GdkPixmap representation of the row at @path.
11152 * This image is used for a drag icon.
11154 * Return value: a newly-allocated pixmap of the drag icon.
11157 pspp_sheet_view_create_row_drag_icon (PsppSheetView *tree_view,
11164 GdkRectangle background_area;
11165 GdkRectangle expose_area;
11167 /* start drawing inside the black outline */
11169 GdkDrawable *drawable;
11170 gint bin_window_width;
11173 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11174 g_return_val_if_fail (path != NULL, NULL);
11176 widget = GTK_WIDGET (tree_view);
11178 if (!gtk_widget_get_realized (widget))
11181 _pspp_sheet_view_find_node (tree_view,
11188 if (!gtk_tree_model_get_iter (tree_view->priv->model,
11195 background_area.y = y;
11196 background_area.height = ROW_HEIGHT (tree_view);
11198 bin_window_width = gdk_window_get_width (tree_view->priv->bin_window);
11200 drawable = gdk_pixmap_new (tree_view->priv->bin_window,
11201 bin_window_width + 2,
11202 background_area.height + 2,
11207 expose_area.width = bin_window_width + 2;
11208 expose_area.height = background_area.height + 2;
11210 #if GTK3_TRANSITION
11211 gdk_draw_rectangle (drawable,
11212 widget->style->base_gc [gtk_widget_get_state (widget)],
11215 bin_window_width + 2,
11216 background_area.height + 2);
11219 rtl = gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL;
11221 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
11223 list = (rtl ? list->prev : list->next))
11225 PsppSheetViewColumn *column = list->data;
11226 GdkRectangle cell_area;
11227 gint vertical_separator;
11229 if (!column->visible)
11232 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, &iter);
11234 background_area.x = cell_offset;
11235 background_area.width = column->width;
11237 gtk_widget_style_get (widget,
11238 "vertical-separator", &vertical_separator,
11241 cell_area = background_area;
11243 cell_area.y += vertical_separator / 2;
11244 cell_area.height -= vertical_separator;
11246 if (pspp_sheet_view_column_cell_is_visible (column))
11247 _pspp_sheet_view_column_cell_render (column,
11253 cell_offset += column->width;
11256 #if GTK3_TRANSITION
11257 gdk_draw_rectangle (drawable,
11258 widget->style->black_gc,
11261 bin_window_width + 1,
11262 background_area.height + 1);
11270 * pspp_sheet_view_set_destroy_count_func:
11271 * @tree_view: A #PsppSheetView
11272 * @func: (allow-none): Function to be called when a view row is destroyed, or %NULL
11273 * @data: (allow-none): User data to be passed to @func, or %NULL
11274 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11276 * This function should almost never be used. It is meant for private use by
11277 * ATK for determining the number of visible children that are removed when a row is deleted.
11280 pspp_sheet_view_set_destroy_count_func (PsppSheetView *tree_view,
11281 PsppSheetDestroyCountFunc func,
11283 GDestroyNotify destroy)
11285 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11287 if (tree_view->priv->destroy_count_destroy)
11288 tree_view->priv->destroy_count_destroy (tree_view->priv->destroy_count_data);
11290 tree_view->priv->destroy_count_func = func;
11291 tree_view->priv->destroy_count_data = data;
11292 tree_view->priv->destroy_count_destroy = destroy;
11297 * Interactive search
11301 * pspp_sheet_view_set_enable_search:
11302 * @tree_view: A #PsppSheetView
11303 * @enable_search: %TRUE, if the user can search interactively
11305 * If @enable_search is set, then the user can type in text to search through
11306 * the tree interactively (this is sometimes called "typeahead find").
11308 * Note that even if this is %FALSE, the user can still initiate a search
11309 * using the "start-interactive-search" key binding.
11312 pspp_sheet_view_set_enable_search (PsppSheetView *tree_view,
11313 gboolean enable_search)
11315 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11317 enable_search = !!enable_search;
11319 if (tree_view->priv->enable_search != enable_search)
11321 tree_view->priv->enable_search = enable_search;
11322 g_object_notify (G_OBJECT (tree_view), "enable-search");
11327 * pspp_sheet_view_get_enable_search:
11328 * @tree_view: A #PsppSheetView
11330 * Returns whether or not the tree allows to start interactive searching
11331 * by typing in text.
11333 * Return value: whether or not to let the user search interactively
11336 pspp_sheet_view_get_enable_search (PsppSheetView *tree_view)
11338 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11340 return tree_view->priv->enable_search;
11345 * pspp_sheet_view_get_search_column:
11346 * @tree_view: A #PsppSheetView
11348 * Gets the column searched on by the interactive search code.
11350 * Return value: the column the interactive search code searches in.
11353 pspp_sheet_view_get_search_column (PsppSheetView *tree_view)
11355 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
11357 return (tree_view->priv->search_column);
11361 * pspp_sheet_view_set_search_column:
11362 * @tree_view: A #PsppSheetView
11363 * @column: the column of the model to search in, or -1 to disable searching
11365 * Sets @column as the column where the interactive search code should
11366 * search in for the current model.
11368 * If the search column is set, users can use the "start-interactive-search"
11369 * key binding to bring up search popup. The enable-search property controls
11370 * whether simply typing text will also start an interactive search.
11372 * Note that @column refers to a column of the current model. The search
11373 * column is reset to -1 when the model is changed.
11376 pspp_sheet_view_set_search_column (PsppSheetView *tree_view,
11379 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11380 g_return_if_fail (column >= -1);
11382 if (tree_view->priv->search_column == column)
11385 tree_view->priv->search_column = column;
11386 g_object_notify (G_OBJECT (tree_view), "search-column");
11390 * pspp_sheet_view_get_search_equal_func:
11391 * @tree_view: A #PsppSheetView
11393 * Returns the compare function currently in use.
11395 * Return value: the currently used compare function for the search code.
11398 PsppSheetViewSearchEqualFunc
11399 pspp_sheet_view_get_search_equal_func (PsppSheetView *tree_view)
11401 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11403 return tree_view->priv->search_equal_func;
11407 * pspp_sheet_view_set_search_equal_func:
11408 * @tree_view: A #PsppSheetView
11409 * @search_equal_func: the compare function to use during the search
11410 * @search_user_data: (allow-none): user data to pass to @search_equal_func, or %NULL
11411 * @search_destroy: (allow-none): Destroy notifier for @search_user_data, or %NULL
11413 * Sets the compare function for the interactive search capabilities; note
11414 * that somewhat like strcmp() returning 0 for equality
11415 * #PsppSheetViewSearchEqualFunc returns %FALSE on matches.
11418 pspp_sheet_view_set_search_equal_func (PsppSheetView *tree_view,
11419 PsppSheetViewSearchEqualFunc search_equal_func,
11420 gpointer search_user_data,
11421 GDestroyNotify search_destroy)
11423 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11424 g_return_if_fail (search_equal_func != NULL);
11426 if (tree_view->priv->search_destroy)
11427 tree_view->priv->search_destroy (tree_view->priv->search_user_data);
11429 tree_view->priv->search_equal_func = search_equal_func;
11430 tree_view->priv->search_user_data = search_user_data;
11431 tree_view->priv->search_destroy = search_destroy;
11432 if (tree_view->priv->search_equal_func == NULL)
11433 tree_view->priv->search_equal_func = pspp_sheet_view_search_equal_func;
11437 * pspp_sheet_view_get_search_entry:
11438 * @tree_view: A #PsppSheetView
11440 * Returns the #GtkEntry which is currently in use as interactive search
11441 * entry for @tree_view. In case the built-in entry is being used, %NULL
11442 * will be returned.
11444 * Return value: the entry currently in use as search entry.
11449 pspp_sheet_view_get_search_entry (PsppSheetView *tree_view)
11451 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11453 if (tree_view->priv->search_custom_entry_set)
11454 return GTK_ENTRY (tree_view->priv->search_entry);
11460 * pspp_sheet_view_set_search_entry:
11461 * @tree_view: A #PsppSheetView
11462 * @entry: (allow-none): the entry the interactive search code of @tree_view should use or %NULL
11464 * Sets the entry which the interactive search code will use for this
11465 * @tree_view. This is useful when you want to provide a search entry
11466 * in our interface at all time at a fixed position. Passing %NULL for
11467 * @entry will make the interactive search code use the built-in popup
11473 pspp_sheet_view_set_search_entry (PsppSheetView *tree_view,
11476 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11477 g_return_if_fail (entry == NULL || GTK_IS_ENTRY (entry));
11479 if (tree_view->priv->search_custom_entry_set)
11481 if (tree_view->priv->search_entry_changed_id)
11483 g_signal_handler_disconnect (tree_view->priv->search_entry,
11484 tree_view->priv->search_entry_changed_id);
11485 tree_view->priv->search_entry_changed_id = 0;
11487 g_signal_handlers_disconnect_by_func (tree_view->priv->search_entry,
11488 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11491 g_object_unref (tree_view->priv->search_entry);
11493 else if (tree_view->priv->search_window)
11495 gtk_widget_destroy (tree_view->priv->search_window);
11497 tree_view->priv->search_window = NULL;
11502 tree_view->priv->search_entry = g_object_ref (entry);
11503 tree_view->priv->search_custom_entry_set = TRUE;
11505 if (tree_view->priv->search_entry_changed_id == 0)
11507 tree_view->priv->search_entry_changed_id =
11508 g_signal_connect (tree_view->priv->search_entry, "changed",
11509 G_CALLBACK (pspp_sheet_view_search_init),
11513 g_signal_connect (tree_view->priv->search_entry, "key-press-event",
11514 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11517 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
11521 tree_view->priv->search_entry = NULL;
11522 tree_view->priv->search_custom_entry_set = FALSE;
11527 * pspp_sheet_view_set_search_position_func:
11528 * @tree_view: A #PsppSheetView
11529 * @func: (allow-none): the function to use to position the search dialog, or %NULL
11530 * to use the default search position function
11531 * @data: (allow-none): user data to pass to @func, or %NULL
11532 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11534 * Sets the function to use when positioning the search dialog.
11539 pspp_sheet_view_set_search_position_func (PsppSheetView *tree_view,
11540 PsppSheetViewSearchPositionFunc func,
11541 gpointer user_data,
11542 GDestroyNotify destroy)
11544 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11546 if (tree_view->priv->search_position_destroy)
11547 tree_view->priv->search_position_destroy (tree_view->priv->search_position_user_data);
11549 tree_view->priv->search_position_func = func;
11550 tree_view->priv->search_position_user_data = user_data;
11551 tree_view->priv->search_position_destroy = destroy;
11552 if (tree_view->priv->search_position_func == NULL)
11553 tree_view->priv->search_position_func = pspp_sheet_view_search_position_func;
11557 * pspp_sheet_view_get_search_position_func:
11558 * @tree_view: A #PsppSheetView
11560 * Returns the positioning function currently in use.
11562 * Return value: the currently used function for positioning the search dialog.
11566 PsppSheetViewSearchPositionFunc
11567 pspp_sheet_view_get_search_position_func (PsppSheetView *tree_view)
11569 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11571 return tree_view->priv->search_position_func;
11576 pspp_sheet_view_search_dialog_hide (GtkWidget *search_dialog,
11577 PsppSheetView *tree_view)
11579 if (tree_view->priv->disable_popdown)
11582 if (tree_view->priv->search_entry_changed_id)
11584 g_signal_handler_disconnect (tree_view->priv->search_entry,
11585 tree_view->priv->search_entry_changed_id);
11586 tree_view->priv->search_entry_changed_id = 0;
11588 if (tree_view->priv->typeselect_flush_timeout)
11590 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11591 tree_view->priv->typeselect_flush_timeout = 0;
11594 if (gtk_widget_get_visible (search_dialog))
11596 /* send focus-in event */
11597 send_focus_change (GTK_WIDGET (tree_view->priv->search_entry), FALSE);
11598 gtk_widget_hide (search_dialog);
11599 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
11600 send_focus_change (GTK_WIDGET (tree_view), TRUE);
11605 pspp_sheet_view_search_position_func (PsppSheetView *tree_view,
11606 GtkWidget *search_dialog,
11607 gpointer user_data)
11610 gint tree_x, tree_y;
11611 gint tree_width, tree_height;
11612 GdkWindow *tree_window = gtk_widget_get_window (GTK_WIDGET (tree_view));
11613 GdkScreen *screen = gdk_window_get_screen (tree_window);
11614 GtkRequisition requisition;
11616 GdkRectangle monitor;
11618 monitor_num = gdk_screen_get_monitor_at_window (screen, tree_window);
11619 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
11621 gtk_widget_realize (search_dialog);
11623 gdk_window_get_origin (tree_window, &tree_x, &tree_y);
11624 tree_width = gdk_window_get_width (tree_window);
11625 tree_height = gdk_window_get_height (tree_window);
11627 gtk_widget_size_request (search_dialog, &requisition);
11629 if (tree_x + tree_width > gdk_screen_get_width (screen))
11630 x = gdk_screen_get_width (screen) - requisition.width;
11631 else if (tree_x + tree_width - requisition.width < 0)
11634 x = tree_x + tree_width - requisition.width;
11636 if (tree_y + tree_height + requisition.height > gdk_screen_get_height (screen))
11637 y = gdk_screen_get_height (screen) - requisition.height;
11638 else if (tree_y + tree_height < 0) /* isn't really possible ... */
11641 y = tree_y + tree_height;
11643 gtk_window_move (GTK_WINDOW (search_dialog), x, y);
11647 pspp_sheet_view_search_disable_popdown (GtkEntry *entry,
11651 PsppSheetView *tree_view = (PsppSheetView *)data;
11653 tree_view->priv->disable_popdown = 1;
11654 g_signal_connect (menu, "hide",
11655 G_CALLBACK (pspp_sheet_view_search_enable_popdown), data);
11658 #if GTK3_TRANSITION
11659 /* Because we're visible but offscreen, we just set a flag in the preedit
11663 pspp_sheet_view_search_preedit_changed (GtkIMContext *im_context,
11664 PsppSheetView *tree_view)
11666 tree_view->priv->imcontext_changed = 1;
11667 if (tree_view->priv->typeselect_flush_timeout)
11669 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11670 tree_view->priv->typeselect_flush_timeout =
11671 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11672 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11680 pspp_sheet_view_search_activate (GtkEntry *entry,
11681 PsppSheetView *tree_view)
11686 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window,
11689 /* If we have a row selected and it's the cursor row, we activate
11691 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
11693 path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
11695 _pspp_sheet_view_find_node (tree_view, path, &node);
11697 if (node >= 0 && pspp_sheet_view_node_is_selected (tree_view, node))
11698 pspp_sheet_view_row_activated (tree_view, path, tree_view->priv->focus_column);
11700 gtk_tree_path_free (path);
11705 pspp_sheet_view_real_search_enable_popdown (gpointer data)
11707 PsppSheetView *tree_view = (PsppSheetView *)data;
11709 tree_view->priv->disable_popdown = 0;
11715 pspp_sheet_view_search_enable_popdown (GtkWidget *widget,
11718 gdk_threads_add_timeout_full (G_PRIORITY_HIGH, 200, pspp_sheet_view_real_search_enable_popdown, g_object_ref (data), g_object_unref);
11722 pspp_sheet_view_search_delete_event (GtkWidget *widget,
11723 GdkEventAny *event,
11724 PsppSheetView *tree_view)
11726 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11728 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11734 pspp_sheet_view_search_button_press_event (GtkWidget *widget,
11735 GdkEventButton *event,
11736 PsppSheetView *tree_view)
11738 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11740 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11742 if (event->window == tree_view->priv->bin_window)
11743 pspp_sheet_view_button_press (GTK_WIDGET (tree_view), event);
11749 pspp_sheet_view_search_scroll_event (GtkWidget *widget,
11750 GdkEventScroll *event,
11751 PsppSheetView *tree_view)
11753 gboolean retval = FALSE;
11755 if (event->direction == GDK_SCROLL_UP)
11757 pspp_sheet_view_search_move (widget, tree_view, TRUE);
11760 else if (event->direction == GDK_SCROLL_DOWN)
11762 pspp_sheet_view_search_move (widget, tree_view, FALSE);
11766 /* renew the flush timeout */
11767 if (retval && tree_view->priv->typeselect_flush_timeout
11768 && !tree_view->priv->search_custom_entry_set)
11770 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11771 tree_view->priv->typeselect_flush_timeout =
11772 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11773 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11781 pspp_sheet_view_search_key_press_event (GtkWidget *widget,
11782 GdkEventKey *event,
11783 PsppSheetView *tree_view)
11785 gboolean retval = FALSE;
11787 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11788 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11790 /* close window and cancel the search */
11791 if (!tree_view->priv->search_custom_entry_set
11792 && (event->keyval == GDK_Escape ||
11793 event->keyval == GDK_Tab ||
11794 event->keyval == GDK_KP_Tab ||
11795 event->keyval == GDK_ISO_Left_Tab))
11797 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11801 /* select previous matching iter */
11802 if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up)
11804 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
11805 gtk_widget_error_bell (widget);
11810 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK))
11811 && (event->keyval == GDK_g || event->keyval == GDK_G))
11813 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
11814 gtk_widget_error_bell (widget);
11819 /* select next matching iter */
11820 if (event->keyval == GDK_Down || event->keyval == GDK_KP_Down)
11822 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
11823 gtk_widget_error_bell (widget);
11828 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == GTK_DEFAULT_ACCEL_MOD_MASK)
11829 && (event->keyval == GDK_g || event->keyval == GDK_G))
11831 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
11832 gtk_widget_error_bell (widget);
11837 /* renew the flush timeout */
11838 if (retval && tree_view->priv->typeselect_flush_timeout
11839 && !tree_view->priv->search_custom_entry_set)
11841 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11842 tree_view->priv->typeselect_flush_timeout =
11843 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11844 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11851 /* this function returns FALSE if there is a search string but
11852 * nothing was found, and TRUE otherwise.
11855 pspp_sheet_view_search_move (GtkWidget *window,
11856 PsppSheetView *tree_view,
11864 GtkTreeModel *model;
11865 PsppSheetSelection *selection;
11867 text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
11869 g_return_val_if_fail (text != NULL, FALSE);
11871 len = strlen (text);
11873 if (up && tree_view->priv->selected_iter == 1)
11874 return strlen (text) < 1;
11876 len = strlen (text);
11881 model = pspp_sheet_view_get_model (tree_view);
11882 selection = pspp_sheet_view_get_selection (tree_view);
11885 pspp_sheet_selection_unselect_all (selection);
11886 if (!gtk_tree_model_get_iter_first (model, &iter))
11889 ret = pspp_sheet_view_search_iter (model, selection, &iter, text,
11890 &count, up?((tree_view->priv->selected_iter) - 1):((tree_view->priv->selected_iter + 1)));
11895 tree_view->priv->selected_iter += up?(-1):(1);
11900 /* return to old iter */
11902 gtk_tree_model_get_iter_first (model, &iter);
11903 pspp_sheet_view_search_iter (model, selection,
11905 &count, tree_view->priv->selected_iter);
11911 pspp_sheet_view_search_equal_func (GtkTreeModel *model,
11915 gpointer search_data)
11917 gboolean retval = TRUE;
11919 gchar *normalized_string;
11920 gchar *normalized_key;
11921 gchar *case_normalized_string = NULL;
11922 gchar *case_normalized_key = NULL;
11923 GValue value = {0,};
11924 GValue transformed = {0,};
11926 gtk_tree_model_get_value (model, iter, column, &value);
11928 g_value_init (&transformed, G_TYPE_STRING);
11930 if (!g_value_transform (&value, &transformed))
11932 g_value_unset (&value);
11936 g_value_unset (&value);
11938 str = g_value_get_string (&transformed);
11941 g_value_unset (&transformed);
11945 normalized_string = g_utf8_normalize (str, -1, G_NORMALIZE_ALL);
11946 normalized_key = g_utf8_normalize (key, -1, G_NORMALIZE_ALL);
11948 if (normalized_string && normalized_key)
11950 case_normalized_string = g_utf8_casefold (normalized_string, -1);
11951 case_normalized_key = g_utf8_casefold (normalized_key, -1);
11953 if (strncmp (case_normalized_key, case_normalized_string, strlen (case_normalized_key)) == 0)
11957 g_value_unset (&transformed);
11958 g_free (normalized_key);
11959 g_free (normalized_string);
11960 g_free (case_normalized_key);
11961 g_free (case_normalized_string);
11967 pspp_sheet_view_search_iter (GtkTreeModel *model,
11968 PsppSheetSelection *selection,
11977 PsppSheetView *tree_view = pspp_sheet_selection_get_tree_view (selection);
11979 path = gtk_tree_model_get_path (model, iter);
11980 _pspp_sheet_view_find_node (tree_view, path, &node);
11984 gboolean done = FALSE;
11986 if (! tree_view->priv->search_equal_func (model, tree_view->priv->search_column, text, iter, tree_view->priv->search_user_data))
11991 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL,
11993 pspp_sheet_selection_select_iter (selection, iter);
11994 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE, 0);
11997 gtk_tree_path_free (path);
12006 node = pspp_sheet_view_node_next (tree_view, node);
12012 has_next = gtk_tree_model_iter_next (model, iter);
12015 gtk_tree_path_next (path);
12018 TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
12023 gtk_tree_path_free (path);
12025 /* we've run out of tree, done with this func */
12037 pspp_sheet_view_search_init (GtkWidget *entry,
12038 PsppSheetView *tree_view)
12044 GtkTreeModel *model;
12045 PsppSheetSelection *selection;
12047 g_return_if_fail (GTK_IS_ENTRY (entry));
12048 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12050 text = gtk_entry_get_text (GTK_ENTRY (entry));
12052 model = pspp_sheet_view_get_model (tree_view);
12053 selection = pspp_sheet_view_get_selection (tree_view);
12056 pspp_sheet_selection_unselect_all (selection);
12057 if (tree_view->priv->typeselect_flush_timeout
12058 && !tree_view->priv->search_custom_entry_set)
12060 g_source_remove (tree_view->priv->typeselect_flush_timeout);
12061 tree_view->priv->typeselect_flush_timeout =
12062 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
12063 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
12070 if (!gtk_tree_model_get_iter_first (model, &iter))
12073 ret = pspp_sheet_view_search_iter (model, selection,
12078 tree_view->priv->selected_iter = 1;
12082 pspp_sheet_view_remove_widget (GtkCellEditable *cell_editable,
12083 PsppSheetView *tree_view)
12085 if (tree_view->priv->edited_column == NULL)
12088 _pspp_sheet_view_column_stop_editing (tree_view->priv->edited_column);
12089 tree_view->priv->edited_column = NULL;
12091 if (gtk_widget_has_focus (GTK_WIDGET (cell_editable)))
12092 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
12094 g_signal_handlers_disconnect_by_func (cell_editable,
12095 pspp_sheet_view_remove_widget,
12097 g_signal_handlers_disconnect_by_func (cell_editable,
12098 pspp_sheet_view_editable_button_press_event,
12100 g_signal_handlers_disconnect_by_func (cell_editable,
12101 pspp_sheet_view_editable_clicked,
12104 gtk_container_remove (GTK_CONTAINER (tree_view),
12105 GTK_WIDGET (cell_editable));
12107 /* FIXME should only redraw a single node */
12108 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12112 pspp_sheet_view_start_editing (PsppSheetView *tree_view,
12113 GtkTreePath *cursor_path)
12116 GdkRectangle background_area;
12117 GdkRectangle cell_area;
12118 GtkCellEditable *editable_widget = NULL;
12119 gchar *path_string;
12120 guint flags = 0; /* can be 0, as the flags are primarily for rendering */
12121 gint retval = FALSE;
12124 g_assert (tree_view->priv->focus_column);
12126 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
12129 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
12130 if (cursor_node < 0)
12133 path_string = gtk_tree_path_to_string (cursor_path);
12134 gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path);
12136 pspp_sheet_view_column_cell_set_cell_data (tree_view->priv->focus_column,
12137 tree_view->priv->model,
12139 pspp_sheet_view_get_background_area (tree_view,
12141 tree_view->priv->focus_column,
12143 pspp_sheet_view_get_cell_area (tree_view,
12145 tree_view->priv->focus_column,
12148 if (_pspp_sheet_view_column_cell_event (tree_view->priv->focus_column,
12157 if (editable_widget != NULL)
12161 GtkCellRenderer *cell;
12164 cell = _pspp_sheet_view_column_get_edited_cell (tree_view->priv->focus_column);
12166 _pspp_sheet_view_column_get_neighbor_sizes (tree_view->priv->focus_column, cell, &left, &right);
12169 area.width -= right + left;
12171 pspp_sheet_view_real_start_editing (tree_view,
12172 tree_view->priv->focus_column,
12181 g_free (path_string);
12186 pspp_sheet_view_editable_button_press_event (GtkWidget *widget,
12187 GdkEventButton *event,
12188 PsppSheetView *sheet_view)
12192 node = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
12193 "pspp-sheet-view-node"));
12194 return pspp_sheet_view_row_head_clicked (sheet_view,
12196 sheet_view->priv->edited_column,
12201 pspp_sheet_view_editable_clicked (GtkButton *button,
12202 PsppSheetView *sheet_view)
12204 pspp_sheet_view_editable_button_press_event (GTK_WIDGET (button), NULL,
12209 is_all_selected (GtkWidget *widget)
12211 GtkEntryBuffer *buffer;
12212 gint start_pos, end_pos;
12214 if (!GTK_IS_ENTRY (widget))
12217 buffer = gtk_entry_get_buffer (GTK_ENTRY (widget));
12218 return (gtk_editable_get_selection_bounds (GTK_EDITABLE (widget),
12219 &start_pos, &end_pos)
12221 && end_pos == gtk_entry_buffer_get_length (buffer));
12225 is_at_left (GtkWidget *widget)
12227 return (GTK_IS_ENTRY (widget)
12228 && gtk_editable_get_position (GTK_EDITABLE (widget)) == 0);
12232 is_at_right (GtkWidget *widget)
12234 GtkEntryBuffer *buffer;
12237 if (!GTK_IS_ENTRY (widget))
12240 buffer = gtk_entry_get_buffer (GTK_ENTRY (widget));
12241 length = gtk_entry_buffer_get_length (buffer);
12242 return gtk_editable_get_position (GTK_EDITABLE (widget)) == length;
12246 pspp_sheet_view_event (GtkWidget *widget,
12247 GdkEventKey *event,
12248 PsppSheetView *tree_view)
12250 PsppSheetViewColumn *column;
12257 /* Intercept only key press events.
12258 It would make sense to use "key-press-event" instead of "event", but
12259 GtkEntry attaches its own signal handler to "key-press-event" that runs
12260 before ours and overrides our desired behavior for GDK_Up and GDK_Down.
12262 if (event->type != GDK_KEY_PRESS)
12265 keyval = event->keyval;
12267 switch (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK | GDK_MOD1_MASK))
12270 switch (event->keyval)
12272 case GDK_Left: case GDK_KP_Left:
12273 case GDK_Home: case GDK_KP_Home:
12274 if (!is_all_selected (widget) && !is_at_left (widget))
12278 case GDK_Right: case GDK_KP_Right:
12279 case GDK_End: case GDK_KP_End:
12280 if (!is_all_selected (widget) && !is_at_right (widget))
12284 case GDK_Up: case GDK_KP_Up:
12285 case GDK_Down: case GDK_KP_Down:
12288 case GDK_Page_Up: case GDK_KP_Page_Up:
12289 case GDK_Page_Down: case GDK_KP_Page_Down:
12300 case GDK_Tab: case GDK_KP_Tab:
12301 case GDK_ISO_Left_Tab:
12310 case GDK_SHIFT_MASK:
12311 switch (event->keyval)
12314 case GDK_ISO_Left_Tab:
12323 case GDK_CONTROL_MASK:
12324 switch (event->keyval)
12326 case GDK_Left: case GDK_KP_Left:
12327 if (!is_all_selected (widget) && !is_at_left (widget))
12331 case GDK_Right: case GDK_KP_Right:
12332 if (!is_all_selected (widget) && !is_at_right (widget))
12336 case GDK_Up: case GDK_KP_Up:
12337 case GDK_Down: case GDK_KP_Down:
12349 row = tree_view->priv->edited_row;
12350 column = tree_view->priv->edited_column;
12351 path = gtk_tree_path_new_from_indices (row, -1);
12353 pspp_sheet_view_stop_editing (tree_view, cancel);
12354 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
12356 pspp_sheet_view_set_cursor (tree_view, path, column, FALSE);
12357 gtk_tree_path_free (path);
12359 handled = gtk_binding_set_activate (edit_bindings, keyval, event->state,
12360 G_OBJECT (tree_view));
12362 g_signal_stop_emission_by_name (widget, "event");
12364 pspp_sheet_view_get_cursor (tree_view, &path, NULL);
12365 pspp_sheet_view_start_editing (tree_view, path);
12366 gtk_tree_path_free (path);
12372 pspp_sheet_view_override_cell_keypresses (GtkWidget *widget,
12375 PsppSheetView *sheet_view = data;
12377 g_signal_connect (widget, "event",
12378 G_CALLBACK (pspp_sheet_view_event),
12381 if (GTK_IS_CONTAINER (widget))
12382 gtk_container_foreach (GTK_CONTAINER (widget),
12383 pspp_sheet_view_override_cell_keypresses,
12388 pspp_sheet_view_real_start_editing (PsppSheetView *tree_view,
12389 PsppSheetViewColumn *column,
12391 GtkCellEditable *cell_editable,
12392 GdkRectangle *cell_area,
12396 PsppSheetSelectionMode mode = pspp_sheet_selection_get_mode (tree_view->priv->selection);
12397 gint pre_val = gtk_adjustment_get_value (tree_view->priv->vadjustment);
12400 g_return_if_fail (gtk_tree_path_get_depth (path) == 1);
12402 tree_view->priv->edited_column = column;
12403 _pspp_sheet_view_column_start_editing (column, GTK_CELL_EDITABLE (cell_editable));
12405 row = gtk_tree_path_get_indices (path)[0];
12406 tree_view->priv->edited_row = row;
12407 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE, 0);
12408 cell_area->y += pre_val - (int)gtk_adjustment_get_value (tree_view->priv->vadjustment);
12410 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
12411 pspp_sheet_selection_select_column (tree_view->priv->selection, column);
12412 tree_view->priv->anchor_column = column;
12414 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
12416 pspp_sheet_view_put (tree_view,
12417 GTK_WIDGET (cell_editable),
12421 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (cell_editable),
12422 (GdkEvent *)event);
12424 gtk_widget_grab_focus (GTK_WIDGET (cell_editable));
12425 g_signal_connect (cell_editable, "remove-widget",
12426 G_CALLBACK (pspp_sheet_view_remove_widget), tree_view);
12427 if (mode == PSPP_SHEET_SELECTION_RECTANGLE && column->row_head &&
12428 GTK_IS_BUTTON (cell_editable))
12430 g_signal_connect (cell_editable, "button-press-event",
12431 G_CALLBACK (pspp_sheet_view_editable_button_press_event),
12433 g_object_set_data (G_OBJECT (cell_editable), "pspp-sheet-view-node",
12434 GINT_TO_POINTER (row));
12435 g_signal_connect (cell_editable, "clicked",
12436 G_CALLBACK (pspp_sheet_view_editable_clicked),
12440 pspp_sheet_view_override_cell_keypresses (GTK_WIDGET (cell_editable),
12445 pspp_sheet_view_stop_editing (PsppSheetView *tree_view,
12446 gboolean cancel_editing)
12448 PsppSheetViewColumn *column;
12449 GtkCellRenderer *cell;
12451 if (tree_view->priv->edited_column == NULL)
12455 * This is very evil. We need to do this, because
12456 * gtk_cell_editable_editing_done may trigger pspp_sheet_view_row_changed
12457 * later on. If pspp_sheet_view_row_changed notices
12458 * tree_view->priv->edited_column != NULL, it'll call
12459 * pspp_sheet_view_stop_editing again. Bad things will happen then.
12461 * Please read that again if you intend to modify anything here.
12464 column = tree_view->priv->edited_column;
12465 tree_view->priv->edited_column = NULL;
12467 cell = _pspp_sheet_view_column_get_edited_cell (column);
12468 gtk_cell_renderer_stop_editing (cell, cancel_editing);
12470 if (!cancel_editing)
12471 gtk_cell_editable_editing_done (column->editable_widget);
12473 tree_view->priv->edited_column = column;
12475 gtk_cell_editable_remove_widget (column->editable_widget);
12480 * pspp_sheet_view_set_hover_selection:
12481 * @tree_view: a #PsppSheetView
12482 * @hover: %TRUE to enable hover selection mode
12484 * Enables of disables the hover selection mode of @tree_view.
12485 * Hover selection makes the selected row follow the pointer.
12486 * Currently, this works only for the selection modes
12487 * %PSPP_SHEET_SELECTION_SINGLE and %PSPP_SHEET_SELECTION_BROWSE.
12492 pspp_sheet_view_set_hover_selection (PsppSheetView *tree_view,
12495 hover = hover != FALSE;
12497 if (hover != tree_view->priv->hover_selection)
12499 tree_view->priv->hover_selection = hover;
12501 g_object_notify (G_OBJECT (tree_view), "hover-selection");
12506 * pspp_sheet_view_get_hover_selection:
12507 * @tree_view: a #PsppSheetView
12509 * Returns whether hover selection mode is turned on for @tree_view.
12511 * Return value: %TRUE if @tree_view is in hover selection mode
12516 pspp_sheet_view_get_hover_selection (PsppSheetView *tree_view)
12518 return tree_view->priv->hover_selection;
12522 * pspp_sheet_view_set_rubber_banding:
12523 * @tree_view: a #PsppSheetView
12524 * @enable: %TRUE to enable rubber banding
12526 * Enables or disables rubber banding in @tree_view. If the selection mode is
12527 * #PSPP_SHEET_SELECTION_MULTIPLE or #PSPP_SHEET_SELECTION_RECTANGLE, rubber
12528 * banding will allow the user to select multiple rows by dragging the mouse.
12533 pspp_sheet_view_set_rubber_banding (PsppSheetView *tree_view,
12536 enable = enable != FALSE;
12538 if (enable != tree_view->priv->rubber_banding_enable)
12540 tree_view->priv->rubber_banding_enable = enable;
12542 g_object_notify (G_OBJECT (tree_view), "rubber-banding");
12547 * pspp_sheet_view_get_rubber_banding:
12548 * @tree_view: a #PsppSheetView
12550 * Returns whether rubber banding is turned on for @tree_view. If the
12551 * selection mode is #PSPP_SHEET_SELECTION_MULTIPLE or
12552 * #PSPP_SHEET_SELECTION_RECTANGLE, rubber banding will allow the user to
12553 * select multiple rows by dragging the mouse.
12555 * Return value: %TRUE if rubber banding in @tree_view is enabled.
12560 pspp_sheet_view_get_rubber_banding (PsppSheetView *tree_view)
12562 return tree_view->priv->rubber_banding_enable;
12566 * pspp_sheet_view_is_rubber_banding_active:
12567 * @tree_view: a #PsppSheetView
12569 * Returns whether a rubber banding operation is currently being done
12572 * Return value: %TRUE if a rubber banding operation is currently being
12573 * done in @tree_view.
12578 pspp_sheet_view_is_rubber_banding_active (PsppSheetView *tree_view)
12580 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
12582 if (tree_view->priv->rubber_banding_enable
12583 && tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
12590 pspp_sheet_view_grab_notify (GtkWidget *widget,
12591 gboolean was_grabbed)
12593 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12595 tree_view->priv->in_grab = !was_grabbed;
12599 tree_view->priv->pressed_button = -1;
12601 if (tree_view->priv->rubber_band_status)
12602 pspp_sheet_view_stop_rubber_band (tree_view);
12607 pspp_sheet_view_state_changed (GtkWidget *widget,
12608 GtkStateType previous_state)
12610 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12612 if (gtk_widget_get_realized (widget))
12614 GtkStyle *style = gtk_widget_get_style (widget);
12615 gdk_window_set_background (tree_view->priv->bin_window, &style->base[gtk_widget_get_state (widget)]);
12618 gtk_widget_queue_draw (widget);
12622 * pspp_sheet_view_get_grid_lines:
12623 * @tree_view: a #PsppSheetView
12625 * Returns which grid lines are enabled in @tree_view.
12627 * Return value: a #PsppSheetViewGridLines value indicating which grid lines
12632 PsppSheetViewGridLines
12633 pspp_sheet_view_get_grid_lines (PsppSheetView *tree_view)
12635 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12637 return tree_view->priv->grid_lines;
12641 * pspp_sheet_view_set_grid_lines:
12642 * @tree_view: a #PsppSheetView
12643 * @grid_lines: a #PsppSheetViewGridLines value indicating which grid lines to
12646 * Sets which grid lines to draw in @tree_view.
12651 pspp_sheet_view_set_grid_lines (PsppSheetView *tree_view,
12652 PsppSheetViewGridLines grid_lines)
12654 PsppSheetViewPrivate *priv;
12655 PsppSheetViewGridLines old_grid_lines;
12657 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12659 priv = tree_view->priv;
12661 old_grid_lines = priv->grid_lines;
12662 priv->grid_lines = grid_lines;
12664 if (old_grid_lines != grid_lines)
12666 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12668 g_object_notify (G_OBJECT (tree_view), "enable-grid-lines");
12673 * pspp_sheet_view_get_special_cells:
12674 * @tree_view: a #PsppSheetView
12676 * Returns which grid lines are enabled in @tree_view.
12678 * Return value: a #PsppSheetViewSpecialCells value indicating whether rows in
12679 * the sheet view contain special cells.
12681 PsppSheetViewSpecialCells
12682 pspp_sheet_view_get_special_cells (PsppSheetView *tree_view)
12684 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12686 return tree_view->priv->special_cells;
12690 * pspp_sheet_view_set_special_cells:
12691 * @tree_view: a #PsppSheetView
12692 * @special_cells: a #PsppSheetViewSpecialCells value indicating whether rows in
12693 * the sheet view contain special cells.
12695 * Sets whether rows in the sheet view contain special cells, controlling the
12696 * rendering of row selections.
12699 pspp_sheet_view_set_special_cells (PsppSheetView *tree_view,
12700 PsppSheetViewSpecialCells special_cells)
12702 PsppSheetViewPrivate *priv;
12704 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12706 priv = tree_view->priv;
12708 if (priv->special_cells != special_cells)
12710 priv->special_cells = special_cells;
12711 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12712 g_object_notify (G_OBJECT (tree_view), "special-cells");
12717 pspp_sheet_view_get_fixed_height (const PsppSheetView *tree_view)
12719 /* XXX (re)calculate fixed_height if necessary */
12720 return tree_view->priv->fixed_height;
12724 pspp_sheet_view_set_fixed_height (PsppSheetView *tree_view,
12727 g_return_if_fail (fixed_height > 0);
12729 if (tree_view->priv->fixed_height != fixed_height)
12731 tree_view->priv->fixed_height = fixed_height;
12732 g_object_notify (G_OBJECT (tree_view), "fixed-height");
12734 if (!tree_view->priv->fixed_height_set)
12736 tree_view->priv->fixed_height_set = TRUE;
12737 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
12742 * pspp_sheet_view_set_tooltip_row:
12743 * @tree_view: a #PsppSheetView
12744 * @tooltip: a #GtkTooltip
12745 * @path: a #GtkTreePath
12747 * Sets the tip area of @tooltip to be the area covered by the row at @path.
12748 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
12749 * See also gtk_tooltip_set_tip_area().
12754 pspp_sheet_view_set_tooltip_row (PsppSheetView *tree_view,
12755 GtkTooltip *tooltip,
12758 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12759 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
12761 pspp_sheet_view_set_tooltip_cell (tree_view, tooltip, path, NULL, NULL);
12765 * pspp_sheet_view_set_tooltip_cell:
12766 * @tree_view: a #PsppSheetView
12767 * @tooltip: a #GtkTooltip
12768 * @path: (allow-none): a #GtkTreePath or %NULL
12769 * @column: (allow-none): a #PsppSheetViewColumn or %NULL
12770 * @cell: (allow-none): a #GtkCellRenderer or %NULL
12772 * Sets the tip area of @tooltip to the area @path, @column and @cell have
12773 * in common. For example if @path is %NULL and @column is set, the tip
12774 * area will be set to the full area covered by @column. See also
12775 * gtk_tooltip_set_tip_area().
12777 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
12782 pspp_sheet_view_set_tooltip_cell (PsppSheetView *tree_view,
12783 GtkTooltip *tooltip,
12785 PsppSheetViewColumn *column,
12786 GtkCellRenderer *cell)
12790 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12791 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
12792 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
12793 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
12795 /* Determine x values. */
12796 if (column && cell)
12801 pspp_sheet_view_get_cell_area (tree_view, path, column, &tmp);
12802 pspp_sheet_view_column_cell_get_position (column, cell, &start, &width);
12804 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12807 rect.width = width;
12813 pspp_sheet_view_get_background_area (tree_view, NULL, column, &tmp);
12814 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12817 rect.width = tmp.width;
12821 GtkAllocation allocation;
12822 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
12824 rect.width = allocation.width;
12827 /* Determine y values. */
12832 pspp_sheet_view_get_background_area (tree_view, path, NULL, &tmp);
12833 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12836 rect.height = tmp.height;
12841 rect.height = gtk_adjustment_get_page_size (tree_view->priv->vadjustment);
12844 gtk_tooltip_set_tip_area (tooltip, &rect);
12848 * pspp_sheet_view_get_tooltip_context:
12849 * @tree_view: a #PsppSheetView
12850 * @x: the x coordinate (relative to widget coordinates)
12851 * @y: the y coordinate (relative to widget coordinates)
12852 * @keyboard_tip: whether this is a keyboard tooltip or not
12853 * @model: (allow-none): a pointer to receive a #GtkTreeModel or %NULL
12854 * @path: (allow-none): a pointer to receive a #GtkTreePath or %NULL
12855 * @iter: (allow-none): a pointer to receive a #GtkTreeIter or %NULL
12857 * This function is supposed to be used in a #GtkWidget::query-tooltip
12858 * signal handler for #PsppSheetView. The @x, @y and @keyboard_tip values
12859 * which are received in the signal handler, should be passed to this
12860 * function without modification.
12862 * The return value indicates whether there is a tree view row at the given
12863 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
12864 * tooltips the row returned will be the cursor row. When %TRUE, then any of
12865 * @model, @path and @iter which have been provided will be set to point to
12866 * that row and the corresponding model. @x and @y will always be converted
12867 * to be relative to @tree_view's bin_window if @keyboard_tooltip is %FALSE.
12869 * Return value: whether or not the given tooltip context points to a row.
12874 pspp_sheet_view_get_tooltip_context (PsppSheetView *tree_view,
12877 gboolean keyboard_tip,
12878 GtkTreeModel **model,
12879 GtkTreePath **path,
12882 GtkTreePath *tmppath = NULL;
12884 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
12885 g_return_val_if_fail (x != NULL, FALSE);
12886 g_return_val_if_fail (y != NULL, FALSE);
12890 pspp_sheet_view_get_cursor (tree_view, &tmppath, NULL);
12897 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, *x, *y,
12900 if (!pspp_sheet_view_get_path_at_pos (tree_view, *x, *y,
12901 &tmppath, NULL, NULL, NULL))
12906 *model = pspp_sheet_view_get_model (tree_view);
12909 gtk_tree_model_get_iter (pspp_sheet_view_get_model (tree_view),
12915 gtk_tree_path_free (tmppath);
12921 pspp_sheet_view_set_tooltip_query_cb (GtkWidget *widget,
12924 gboolean keyboard_tip,
12925 GtkTooltip *tooltip,
12928 GValue value = { 0, };
12929 GValue transformed = { 0, };
12932 GtkTreeModel *model;
12933 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12935 if (!pspp_sheet_view_get_tooltip_context (PSPP_SHEET_VIEW (widget),
12938 &model, &path, &iter))
12941 gtk_tree_model_get_value (model, &iter,
12942 tree_view->priv->tooltip_column, &value);
12944 g_value_init (&transformed, G_TYPE_STRING);
12946 if (!g_value_transform (&value, &transformed))
12948 g_value_unset (&value);
12949 gtk_tree_path_free (path);
12954 g_value_unset (&value);
12956 if (!g_value_get_string (&transformed))
12958 g_value_unset (&transformed);
12959 gtk_tree_path_free (path);
12964 gtk_tooltip_set_markup (tooltip, g_value_get_string (&transformed));
12965 pspp_sheet_view_set_tooltip_row (tree_view, tooltip, path);
12967 gtk_tree_path_free (path);
12968 g_value_unset (&transformed);
12974 * pspp_sheet_view_set_tooltip_column:
12975 * @tree_view: a #PsppSheetView
12976 * @column: an integer, which is a valid column number for @tree_view's model
12978 * If you only plan to have simple (text-only) tooltips on full rows, you
12979 * can use this function to have #PsppSheetView handle these automatically
12980 * for you. @column should be set to the column in @tree_view's model
12981 * containing the tooltip texts, or -1 to disable this feature.
12983 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
12984 * @tree_view will connect a #GtkWidget::query-tooltip signal handler.
12986 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
12987 * so &, <, etc have to be escaped in the text.
12992 pspp_sheet_view_set_tooltip_column (PsppSheetView *tree_view,
12995 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12997 if (column == tree_view->priv->tooltip_column)
13002 g_signal_handlers_disconnect_by_func (tree_view,
13003 pspp_sheet_view_set_tooltip_query_cb,
13005 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), FALSE);
13009 if (tree_view->priv->tooltip_column == -1)
13011 g_signal_connect (tree_view, "query-tooltip",
13012 G_CALLBACK (pspp_sheet_view_set_tooltip_query_cb), NULL);
13013 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), TRUE);
13017 tree_view->priv->tooltip_column = column;
13018 g_object_notify (G_OBJECT (tree_view), "tooltip-column");
13022 * pspp_sheet_view_get_tooltip_column:
13023 * @tree_view: a #PsppSheetView
13025 * Returns the column of @tree_view's model which is being used for
13026 * displaying tooltips on @tree_view's rows.
13028 * Return value: the index of the tooltip column that is currently being
13029 * used, or -1 if this is disabled.
13034 pspp_sheet_view_get_tooltip_column (PsppSheetView *tree_view)
13036 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
13038 return tree_view->priv->tooltip_column;
13042 _gtk_boolean_handled_accumulator (GSignalInvocationHint *ihint,
13043 GValue *return_accu,
13044 const GValue *handler_return,
13047 gboolean continue_emission;
13048 gboolean signal_handled;
13050 signal_handled = g_value_get_boolean (handler_return);
13051 g_value_set_boolean (return_accu, signal_handled);
13052 continue_emission = !signal_handled;
13054 return continue_emission;
13059 pspp_sheet_view_grid_lines_get_type (void)
13061 static GType etype = 0;
13062 if (G_UNLIKELY(etype == 0)) {
13063 static const GEnumValue values[] = {
13064 { PSPP_SHEET_VIEW_GRID_LINES_NONE, "PSPP_SHEET_VIEW_GRID_LINES_NONE", "none" },
13065 { PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL, "PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL", "horizontal" },
13066 { PSPP_SHEET_VIEW_GRID_LINES_VERTICAL, "PSPP_SHEET_VIEW_GRID_LINES_VERTICAL", "vertical" },
13067 { PSPP_SHEET_VIEW_GRID_LINES_BOTH, "PSPP_SHEET_VIEW_GRID_LINES_BOTH", "both" },
13070 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewGridLines"), values);
13076 pspp_sheet_view_special_cells_get_type (void)
13078 static GType etype = 0;
13079 if (G_UNLIKELY(etype == 0)) {
13080 static const GEnumValue values[] = {
13081 { PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT, "PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT", "detect" },
13082 { PSPP_SHEET_VIEW_SPECIAL_CELLS_YES, "PSPP_SHEET_VIEW_SPECIAL_CELLS_YES", "yes" },
13083 { PSPP_SHEET_VIEW_SPECIAL_CELLS_NO, "PSPP_SHEET_VIEW_SPECIAL_CELLS_NO", "no" },
13086 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewSpecialCells"), values);