1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2011, 2012, 2013 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
103 typedef struct _TreeViewDragInfo TreeViewDragInfo;
104 struct _TreeViewDragInfo
106 GdkModifierType start_button_mask;
107 GtkTargetList *_unused_source_target_list;
108 GdkDragAction source_actions;
110 GtkTargetList *_unused_dest_target_list;
112 guint source_set : 1;
128 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_expose (GtkWidget *widget,
175 GdkEventExpose *event);
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_set (GtkWidget *widget,
201 GtkStyle *previous_style);
202 static void pspp_sheet_view_grab_notify (GtkWidget *widget,
203 gboolean was_grabbed);
204 static void pspp_sheet_view_state_changed (GtkWidget *widget,
205 GtkStateType previous_state);
207 /* container signals */
208 static void pspp_sheet_view_remove (GtkContainer *container,
210 static void pspp_sheet_view_forall (GtkContainer *container,
211 gboolean include_internals,
212 GtkCallback callback,
213 gpointer callback_data);
215 /* Source side drag signals */
216 static void pspp_sheet_view_drag_begin (GtkWidget *widget,
217 GdkDragContext *context);
218 static void pspp_sheet_view_drag_end (GtkWidget *widget,
219 GdkDragContext *context);
220 static void pspp_sheet_view_drag_data_get (GtkWidget *widget,
221 GdkDragContext *context,
222 GtkSelectionData *selection_data,
225 static void pspp_sheet_view_drag_data_delete (GtkWidget *widget,
226 GdkDragContext *context);
228 /* Target side drag signals */
229 static void pspp_sheet_view_drag_leave (GtkWidget *widget,
230 GdkDragContext *context,
232 static gboolean pspp_sheet_view_drag_motion (GtkWidget *widget,
233 GdkDragContext *context,
237 static gboolean pspp_sheet_view_drag_drop (GtkWidget *widget,
238 GdkDragContext *context,
242 static void pspp_sheet_view_drag_data_received (GtkWidget *widget,
243 GdkDragContext *context,
246 GtkSelectionData *selection_data,
250 /* tree_model signals */
251 static void pspp_sheet_view_set_adjustments (PsppSheetView *tree_view,
253 GtkAdjustment *vadj);
254 static gboolean pspp_sheet_view_real_move_cursor (PsppSheetView *tree_view,
255 GtkMovementStep step,
257 static gboolean pspp_sheet_view_real_select_all (PsppSheetView *tree_view);
258 static gboolean pspp_sheet_view_real_unselect_all (PsppSheetView *tree_view);
259 static gboolean pspp_sheet_view_real_select_cursor_row (PsppSheetView *tree_view,
260 gboolean start_editing,
261 PsppSheetSelectMode mode);
262 static gboolean pspp_sheet_view_real_toggle_cursor_row (PsppSheetView *tree_view);
263 static void pspp_sheet_view_row_changed (GtkTreeModel *model,
267 static void pspp_sheet_view_row_inserted (GtkTreeModel *model,
271 static void pspp_sheet_view_row_deleted (GtkTreeModel *model,
274 static void pspp_sheet_view_rows_reordered (GtkTreeModel *model,
280 /* Incremental reflow */
281 static gint validate_row (PsppSheetView *tree_view,
285 static void validate_visible_area (PsppSheetView *tree_view);
286 static gboolean validate_rows_handler (PsppSheetView *tree_view);
287 static gboolean presize_handler_callback (gpointer data);
288 static void install_presize_handler (PsppSheetView *tree_view);
289 static void install_scroll_sync_handler (PsppSheetView *tree_view);
290 static void pspp_sheet_view_set_top_row (PsppSheetView *tree_view,
293 static void pspp_sheet_view_dy_to_top_row (PsppSheetView *tree_view);
294 static void pspp_sheet_view_top_row_to_dy (PsppSheetView *tree_view);
295 static void invalidate_empty_focus (PsppSheetView *tree_view);
297 /* Internal functions */
298 static void pspp_sheet_view_add_move_binding (GtkBindingSet *binding_set,
301 gboolean add_shifted_binding,
302 GtkMovementStep step,
304 static void pspp_sheet_view_queue_draw_path (PsppSheetView *tree_view,
306 const GdkRectangle *clip_rect);
307 static gint pspp_sheet_view_new_column_width (PsppSheetView *tree_view,
310 static void pspp_sheet_view_adjustment_changed (GtkAdjustment *adjustment,
311 PsppSheetView *tree_view);
312 static void pspp_sheet_view_clamp_node_visible (PsppSheetView *tree_view,
314 static void pspp_sheet_view_clamp_column_visible (PsppSheetView *tree_view,
315 PsppSheetViewColumn *column,
316 gboolean focus_to_cell);
317 static gboolean pspp_sheet_view_maybe_begin_dragging_row (PsppSheetView *tree_view,
318 GdkEventMotion *event);
319 static void pspp_sheet_view_focus_to_cursor (PsppSheetView *tree_view);
320 static gboolean pspp_sheet_view_move_cursor_up_down (PsppSheetView *tree_view,
322 PsppSheetSelectMode mode);
323 static void pspp_sheet_view_move_cursor_page_up_down (PsppSheetView *tree_view,
325 PsppSheetSelectMode mode);
326 static void pspp_sheet_view_move_cursor_left_right (PsppSheetView *tree_view,
328 PsppSheetSelectMode mode);
329 static void pspp_sheet_view_move_cursor_line_start_end (PsppSheetView *tree_view,
331 PsppSheetSelectMode mode);
332 static void pspp_sheet_view_move_cursor_tab (PsppSheetView *tree_view,
334 static void pspp_sheet_view_move_cursor_start_end (PsppSheetView *tree_view,
336 PsppSheetSelectMode mode);
337 static void pspp_sheet_view_real_set_cursor (PsppSheetView *tree_view,
339 gboolean clear_and_select,
341 PsppSheetSelectMode mode);
342 static gboolean pspp_sheet_view_has_special_cell (PsppSheetView *tree_view);
343 static void pspp_sheet_view_stop_rubber_band (PsppSheetView *tree_view);
344 static void update_prelight (PsppSheetView *tree_view,
347 static void initialize_fixed_height_mode (PsppSheetView *tree_view);
349 /* interactive search */
350 static void pspp_sheet_view_ensure_interactive_directory (PsppSheetView *tree_view);
351 static void pspp_sheet_view_search_dialog_hide (GtkWidget *search_dialog,
352 PsppSheetView *tree_view);
353 static void pspp_sheet_view_search_position_func (PsppSheetView *tree_view,
354 GtkWidget *search_dialog,
356 static void pspp_sheet_view_search_disable_popdown (GtkEntry *entry,
360 static void pspp_sheet_view_search_preedit_changed (GtkIMContext *im_context,
361 PsppSheetView *tree_view);
363 static void pspp_sheet_view_search_activate (GtkEntry *entry,
364 PsppSheetView *tree_view);
365 static gboolean pspp_sheet_view_real_search_enable_popdown(gpointer data);
366 static void pspp_sheet_view_search_enable_popdown (GtkWidget *widget,
368 static gboolean pspp_sheet_view_search_delete_event (GtkWidget *widget,
370 PsppSheetView *tree_view);
371 static gboolean pspp_sheet_view_search_button_press_event (GtkWidget *widget,
372 GdkEventButton *event,
373 PsppSheetView *tree_view);
374 static gboolean pspp_sheet_view_search_scroll_event (GtkWidget *entry,
375 GdkEventScroll *event,
376 PsppSheetView *tree_view);
377 static gboolean pspp_sheet_view_search_key_press_event (GtkWidget *entry,
379 PsppSheetView *tree_view);
380 static gboolean pspp_sheet_view_search_move (GtkWidget *window,
381 PsppSheetView *tree_view,
383 static gboolean pspp_sheet_view_search_equal_func (GtkTreeModel *model,
387 gpointer search_data);
388 static gboolean pspp_sheet_view_search_iter (GtkTreeModel *model,
389 PsppSheetSelection *selection,
394 static void pspp_sheet_view_search_init (GtkWidget *entry,
395 PsppSheetView *tree_view);
396 static void pspp_sheet_view_put (PsppSheetView *tree_view,
397 GtkWidget *child_widget,
402 static gboolean pspp_sheet_view_start_editing (PsppSheetView *tree_view,
403 GtkTreePath *cursor_path);
404 static gboolean pspp_sheet_view_editable_button_press_event (GtkWidget *,
407 static void pspp_sheet_view_editable_clicked (GtkButton *, PsppSheetView *);
408 static void pspp_sheet_view_real_start_editing (PsppSheetView *tree_view,
409 PsppSheetViewColumn *column,
411 GtkCellEditable *cell_editable,
412 GdkRectangle *cell_area,
415 static gboolean pspp_sheet_view_real_start_interactive_search (PsppSheetView *tree_view,
416 gboolean keybinding);
417 static gboolean pspp_sheet_view_start_interactive_search (PsppSheetView *tree_view);
418 static PsppSheetViewColumn *pspp_sheet_view_get_drop_column (PsppSheetView *tree_view,
419 PsppSheetViewColumn *column,
422 pspp_sheet_view_adjust_cell_area (PsppSheetView *tree_view,
423 PsppSheetViewColumn *column,
424 const GdkRectangle *background_area,
425 gboolean subtract_focus_rect,
426 GdkRectangle *cell_area);
427 static gint pspp_sheet_view_find_offset (PsppSheetView *tree_view,
432 static void pspp_sheet_view_buildable_add_child (GtkBuildable *tree_view,
436 static void pspp_sheet_view_buildable_init (GtkBuildableIface *iface);
439 static gboolean scroll_row_timeout (gpointer data);
440 static void add_scroll_timeout (PsppSheetView *tree_view);
441 static void remove_scroll_timeout (PsppSheetView *tree_view);
443 static guint tree_view_signals [LAST_SIGNAL] = { 0 };
445 static GtkBindingSet *edit_bindings;
452 G_DEFINE_TYPE_WITH_CODE (PsppSheetView, pspp_sheet_view, GTK_TYPE_CONTAINER,
453 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
454 pspp_sheet_view_buildable_init))
457 pspp_sheet_view_class_init (PsppSheetViewClass *class)
459 GObjectClass *o_class;
460 GtkWidgetClass *widget_class;
461 GtkContainerClass *container_class;
462 GtkBindingSet *binding_set[2];
465 binding_set[0] = gtk_binding_set_by_class (class);
467 binding_set[1] = gtk_binding_set_new ("PsppSheetViewEditing");
468 edit_bindings = binding_set[1];
470 o_class = (GObjectClass *) class;
471 widget_class = (GtkWidgetClass *) class;
472 container_class = (GtkContainerClass *) class;
474 /* GObject signals */
475 o_class->set_property = pspp_sheet_view_set_property;
476 o_class->get_property = pspp_sheet_view_get_property;
477 o_class->finalize = pspp_sheet_view_finalize;
478 o_class->dispose = pspp_sheet_view_dispose;
480 /* GtkWidget signals */
481 widget_class->map = pspp_sheet_view_map;
482 widget_class->realize = pspp_sheet_view_realize;
483 widget_class->unrealize = pspp_sheet_view_unrealize;
484 widget_class->size_request = pspp_sheet_view_size_request;
485 widget_class->size_allocate = pspp_sheet_view_size_allocate;
486 widget_class->button_press_event = pspp_sheet_view_button_press;
487 widget_class->button_release_event = pspp_sheet_view_button_release;
488 widget_class->grab_broken_event = pspp_sheet_view_grab_broken;
489 /*widget_class->configure_event = pspp_sheet_view_configure;*/
490 widget_class->motion_notify_event = pspp_sheet_view_motion;
491 widget_class->expose_event = pspp_sheet_view_expose;
492 widget_class->key_press_event = pspp_sheet_view_key_press;
493 widget_class->key_release_event = pspp_sheet_view_key_release;
494 widget_class->enter_notify_event = pspp_sheet_view_enter_notify;
495 widget_class->leave_notify_event = pspp_sheet_view_leave_notify;
496 widget_class->focus_out_event = pspp_sheet_view_focus_out;
497 widget_class->drag_begin = pspp_sheet_view_drag_begin;
498 widget_class->drag_end = pspp_sheet_view_drag_end;
499 widget_class->drag_data_get = pspp_sheet_view_drag_data_get;
500 widget_class->drag_data_delete = pspp_sheet_view_drag_data_delete;
501 widget_class->drag_leave = pspp_sheet_view_drag_leave;
502 widget_class->drag_motion = pspp_sheet_view_drag_motion;
503 widget_class->drag_drop = pspp_sheet_view_drag_drop;
504 widget_class->drag_data_received = pspp_sheet_view_drag_data_received;
505 widget_class->focus = pspp_sheet_view_focus;
506 widget_class->grab_focus = pspp_sheet_view_grab_focus;
507 widget_class->style_set = pspp_sheet_view_style_set;
508 widget_class->grab_notify = pspp_sheet_view_grab_notify;
509 widget_class->state_changed = pspp_sheet_view_state_changed;
511 /* GtkContainer signals */
512 container_class->remove = pspp_sheet_view_remove;
513 container_class->forall = pspp_sheet_view_forall;
514 container_class->set_focus_child = pspp_sheet_view_set_focus_child;
516 class->set_scroll_adjustments = pspp_sheet_view_set_adjustments;
517 class->move_cursor = pspp_sheet_view_real_move_cursor;
518 class->select_all = pspp_sheet_view_real_select_all;
519 class->unselect_all = pspp_sheet_view_real_unselect_all;
520 class->select_cursor_row = pspp_sheet_view_real_select_cursor_row;
521 class->toggle_cursor_row = pspp_sheet_view_real_toggle_cursor_row;
522 class->start_interactive_search = pspp_sheet_view_start_interactive_search;
526 g_object_class_install_property (o_class,
528 g_param_spec_object ("model",
529 P_("TreeView Model"),
530 P_("The model for the tree view"),
532 GTK_PARAM_READWRITE));
534 g_object_class_install_property (o_class,
536 g_param_spec_object ("hadjustment",
537 P_("Horizontal Adjustment"),
538 P_("Horizontal Adjustment for the widget"),
540 GTK_PARAM_READWRITE));
542 g_object_class_install_property (o_class,
544 g_param_spec_object ("vadjustment",
545 P_("Vertical Adjustment"),
546 P_("Vertical Adjustment for the widget"),
548 GTK_PARAM_READWRITE));
550 g_object_class_install_property (o_class,
551 PROP_HEADERS_VISIBLE,
552 g_param_spec_boolean ("headers-visible",
553 P_("Headers Visible"),
554 P_("Show the column header buttons"),
556 GTK_PARAM_READWRITE));
558 g_object_class_install_property (o_class,
559 PROP_HEADERS_CLICKABLE,
560 g_param_spec_boolean ("headers-clickable",
561 P_("Headers Clickable"),
562 P_("Column headers respond to click events"),
564 GTK_PARAM_READWRITE));
566 g_object_class_install_property (o_class,
568 g_param_spec_boolean ("reorderable",
570 P_("View is reorderable"),
572 GTK_PARAM_READWRITE));
574 g_object_class_install_property (o_class,
576 g_param_spec_boolean ("rules-hint",
578 P_("Set a hint to the theme engine to draw rows in alternating colors"),
580 GTK_PARAM_READWRITE));
582 g_object_class_install_property (o_class,
584 g_param_spec_boolean ("enable-search",
586 P_("View allows user to search through columns interactively"),
588 GTK_PARAM_READWRITE));
590 g_object_class_install_property (o_class,
592 g_param_spec_int ("search-column",
594 P_("Model column to search through during interactive search"),
598 GTK_PARAM_READWRITE));
601 * PsppSheetView:hover-selection:
603 * Enables of disables the hover selection mode of @tree_view.
604 * Hover selection makes the selected row follow the pointer.
605 * Currently, this works only for the selection modes
606 * %PSPP_SHEET_SELECTION_SINGLE and %PSPP_SHEET_SELECTION_BROWSE.
608 * This mode is primarily intended for treeviews in popups, e.g.
609 * in #GtkComboBox or #GtkEntryCompletion.
613 g_object_class_install_property (o_class,
614 PROP_HOVER_SELECTION,
615 g_param_spec_boolean ("hover-selection",
616 P_("Hover Selection"),
617 P_("Whether the selection should follow the pointer"),
619 GTK_PARAM_READWRITE));
621 g_object_class_install_property (o_class,
623 g_param_spec_boolean ("rubber-banding",
624 P_("Rubber Banding"),
625 P_("Whether to enable selection of multiple items by dragging the mouse pointer"),
627 GTK_PARAM_READWRITE));
629 g_object_class_install_property (o_class,
630 PROP_ENABLE_GRID_LINES,
631 g_param_spec_enum ("enable-grid-lines",
632 P_("Enable Grid Lines"),
633 P_("Whether grid lines should be drawn in the tree view"),
634 PSPP_TYPE_SHEET_VIEW_GRID_LINES,
635 PSPP_SHEET_VIEW_GRID_LINES_NONE,
636 GTK_PARAM_READWRITE));
638 g_object_class_install_property (o_class,
640 g_param_spec_int ("tooltip-column",
641 P_("Tooltip Column"),
642 P_("The column in the model containing the tooltip texts for the rows"),
646 GTK_PARAM_READWRITE));
648 g_object_class_install_property (o_class,
650 g_param_spec_enum ("special-cells",
652 P_("Whether rows have special cells."),
653 PSPP_TYPE_SHEET_VIEW_SPECIAL_CELLS,
654 PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT,
655 GTK_PARAM_READWRITE));
657 g_object_class_install_property (o_class,
659 g_param_spec_int ("fixed-height",
661 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."),
665 GTK_PARAM_READWRITE));
667 g_object_class_install_property (o_class,
668 PROP_FIXED_HEIGHT_SET,
669 g_param_spec_boolean ("fixed-height-set",
670 P_("Fixed Height Set"),
671 P_("Whether fixed-height was set externally."),
673 GTK_PARAM_READWRITE));
675 /* Style properties */
676 #define _TREE_VIEW_EXPANDER_SIZE 12
677 #define _TREE_VIEW_VERTICAL_SEPARATOR 2
678 #define _TREE_VIEW_HORIZONTAL_SEPARATOR 2
680 gtk_widget_class_install_style_property (widget_class,
681 g_param_spec_int ("expander-size",
683 P_("Size of the expander arrow"),
686 _TREE_VIEW_EXPANDER_SIZE,
687 GTK_PARAM_READABLE));
689 gtk_widget_class_install_style_property (widget_class,
690 g_param_spec_int ("vertical-separator",
691 P_("Vertical Separator Width"),
692 P_("Vertical space between cells. Must be an even number"),
695 _TREE_VIEW_VERTICAL_SEPARATOR,
696 GTK_PARAM_READABLE));
698 gtk_widget_class_install_style_property (widget_class,
699 g_param_spec_int ("horizontal-separator",
700 P_("Horizontal Separator Width"),
701 P_("Horizontal space between cells. Must be an even number"),
704 _TREE_VIEW_HORIZONTAL_SEPARATOR,
705 GTK_PARAM_READABLE));
707 gtk_widget_class_install_style_property (widget_class,
708 g_param_spec_boolean ("allow-rules",
710 P_("Allow drawing of alternating color rows"),
712 GTK_PARAM_READABLE));
714 gtk_widget_class_install_style_property (widget_class,
715 g_param_spec_boxed ("even-row-color",
716 P_("Even Row Color"),
717 P_("Color to use for even rows"),
719 GTK_PARAM_READABLE));
721 gtk_widget_class_install_style_property (widget_class,
722 g_param_spec_boxed ("odd-row-color",
724 P_("Color to use for odd rows"),
726 GTK_PARAM_READABLE));
728 gtk_widget_class_install_style_property (widget_class,
729 g_param_spec_boolean ("row-ending-details",
730 P_("Row Ending details"),
731 P_("Enable extended row background theming"),
733 GTK_PARAM_READABLE));
735 gtk_widget_class_install_style_property (widget_class,
736 g_param_spec_int ("grid-line-width",
737 P_("Grid line width"),
738 P_("Width, in pixels, of the tree view grid lines"),
740 GTK_PARAM_READABLE));
742 gtk_widget_class_install_style_property (widget_class,
743 g_param_spec_int ("tree-line-width",
744 P_("Tree line width"),
745 P_("Width, in pixels, of the tree view lines"),
747 GTK_PARAM_READABLE));
749 gtk_widget_class_install_style_property (widget_class,
750 g_param_spec_string ("tree-line-pattern",
751 P_("Tree line pattern"),
752 P_("Dash pattern used to draw the tree view lines"),
754 GTK_PARAM_READABLE));
758 * PsppSheetView::set-scroll-adjustments
759 * @horizontal: the horizontal #GtkAdjustment
760 * @vertical: the vertical #GtkAdjustment
762 * Set the scroll adjustments for the tree view. Usually scrolled containers
763 * like #GtkScrolledWindow will emit this signal to connect two instances
764 * of #GtkScrollbar to the scroll directions of the #PsppSheetView.
766 widget_class->set_scroll_adjustments_signal =
767 g_signal_new ("set-scroll-adjustments",
768 G_TYPE_FROM_CLASS (o_class),
769 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
770 G_STRUCT_OFFSET (PsppSheetViewClass, set_scroll_adjustments),
772 psppire_marshal_VOID__OBJECT_OBJECT,
775 GTK_TYPE_ADJUSTMENT);
778 * PsppSheetView::row-activated:
779 * @tree_view: the object on which the signal is emitted
780 * @path: the #GtkTreePath for the activated row
781 * @column: the #PsppSheetViewColumn in which the activation occurred
783 * The "row-activated" signal is emitted when the method
784 * pspp_sheet_view_row_activated() is called or the user double clicks
785 * a treeview row. It is also emitted when a non-editable row is
786 * selected and one of the keys: Space, Shift+Space, Return or
789 * For selection handling refer to the <link linkend="TreeWidget">tree
790 * widget conceptual overview</link> as well as #PsppSheetSelection.
792 tree_view_signals[ROW_ACTIVATED] =
793 g_signal_new ("row-activated",
794 G_TYPE_FROM_CLASS (o_class),
795 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
796 G_STRUCT_OFFSET (PsppSheetViewClass, row_activated),
798 psppire_marshal_VOID__BOXED_OBJECT,
801 PSPP_TYPE_SHEET_VIEW_COLUMN);
804 * PsppSheetView::columns-changed:
805 * @tree_view: the object on which the signal is emitted
807 * The number of columns of the treeview has changed.
809 tree_view_signals[COLUMNS_CHANGED] =
810 g_signal_new ("columns-changed",
811 G_TYPE_FROM_CLASS (o_class),
813 G_STRUCT_OFFSET (PsppSheetViewClass, columns_changed),
815 g_cclosure_marshal_VOID__VOID,
819 * PsppSheetView::cursor-changed:
820 * @tree_view: the object on which the signal is emitted
822 * The position of the cursor (focused cell) has changed.
824 tree_view_signals[CURSOR_CHANGED] =
825 g_signal_new ("cursor-changed",
826 G_TYPE_FROM_CLASS (o_class),
828 G_STRUCT_OFFSET (PsppSheetViewClass, cursor_changed),
830 g_cclosure_marshal_VOID__VOID,
833 tree_view_signals[MOVE_CURSOR] =
834 g_signal_new ("move-cursor",
835 G_TYPE_FROM_CLASS (o_class),
836 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
837 G_STRUCT_OFFSET (PsppSheetViewClass, move_cursor),
839 psppire_marshal_BOOLEAN__ENUM_INT,
841 GTK_TYPE_MOVEMENT_STEP,
844 tree_view_signals[SELECT_ALL] =
845 g_signal_new ("select-all",
846 G_TYPE_FROM_CLASS (o_class),
847 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
848 G_STRUCT_OFFSET (PsppSheetViewClass, select_all),
850 psppire_marshal_BOOLEAN__VOID,
853 tree_view_signals[UNSELECT_ALL] =
854 g_signal_new ("unselect-all",
855 G_TYPE_FROM_CLASS (o_class),
856 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
857 G_STRUCT_OFFSET (PsppSheetViewClass, unselect_all),
859 psppire_marshal_BOOLEAN__VOID,
862 tree_view_signals[SELECT_CURSOR_ROW] =
863 g_signal_new ("select-cursor-row",
864 G_TYPE_FROM_CLASS (o_class),
865 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
866 G_STRUCT_OFFSET (PsppSheetViewClass, select_cursor_row),
868 psppire_marshal_BOOLEAN__BOOLEAN,
870 G_TYPE_BOOLEAN, G_TYPE_INT);
872 tree_view_signals[TOGGLE_CURSOR_ROW] =
873 g_signal_new ("toggle-cursor-row",
874 G_TYPE_FROM_CLASS (o_class),
875 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
876 G_STRUCT_OFFSET (PsppSheetViewClass, toggle_cursor_row),
878 psppire_marshal_BOOLEAN__VOID,
881 tree_view_signals[START_INTERACTIVE_SEARCH] =
882 g_signal_new ("start-interactive-search",
883 G_TYPE_FROM_CLASS (o_class),
884 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
885 G_STRUCT_OFFSET (PsppSheetViewClass, start_interactive_search),
887 psppire_marshal_BOOLEAN__VOID,
891 for (i = 0; i < 2; i++)
893 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Up, 0, TRUE,
894 GTK_MOVEMENT_DISPLAY_LINES, -1);
895 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Up, 0, TRUE,
896 GTK_MOVEMENT_DISPLAY_LINES, -1);
898 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Down, 0, TRUE,
899 GTK_MOVEMENT_DISPLAY_LINES, 1);
900 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Down, 0, TRUE,
901 GTK_MOVEMENT_DISPLAY_LINES, 1);
903 pspp_sheet_view_add_move_binding (binding_set[i], GDK_p, GDK_CONTROL_MASK, FALSE,
904 GTK_MOVEMENT_DISPLAY_LINES, -1);
906 pspp_sheet_view_add_move_binding (binding_set[i], GDK_n, GDK_CONTROL_MASK, FALSE,
907 GTK_MOVEMENT_DISPLAY_LINES, 1);
909 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Home, 0, TRUE,
910 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
911 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Home, 0, TRUE,
912 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
914 pspp_sheet_view_add_move_binding (binding_set[i], GDK_End, 0, TRUE,
915 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
916 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_End, 0, TRUE,
917 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
919 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Page_Up, 0, TRUE,
920 GTK_MOVEMENT_PAGES, -1);
921 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Page_Up, 0, TRUE,
922 GTK_MOVEMENT_PAGES, -1);
924 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Page_Down, 0, TRUE,
925 GTK_MOVEMENT_PAGES, 1);
926 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Page_Down, 0, TRUE,
927 GTK_MOVEMENT_PAGES, 1);
930 gtk_binding_entry_add_signal (binding_set[i], GDK_Up, GDK_CONTROL_MASK, "move-cursor", 2,
931 G_TYPE_ENUM, GTK_MOVEMENT_BUFFER_ENDS,
934 gtk_binding_entry_add_signal (binding_set[i], GDK_Down, GDK_CONTROL_MASK, "move-cursor", 2,
935 G_TYPE_ENUM, GTK_MOVEMENT_BUFFER_ENDS,
938 gtk_binding_entry_add_signal (binding_set[i], GDK_Right, 0, "move-cursor", 2,
939 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
942 gtk_binding_entry_add_signal (binding_set[i], GDK_Left, 0, "move-cursor", 2,
943 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
946 gtk_binding_entry_add_signal (binding_set[i], GDK_Tab, 0, "move-cursor", 2,
947 G_TYPE_ENUM, GTK_MOVEMENT_LOGICAL_POSITIONS,
950 gtk_binding_entry_add_signal (binding_set[i], GDK_Tab, GDK_SHIFT_MASK, "move-cursor", 2,
951 G_TYPE_ENUM, GTK_MOVEMENT_LOGICAL_POSITIONS,
954 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Right, 0, "move-cursor", 2,
955 G_TYPE_ENUM, GTK_MOVEMENT_DISPLAY_LINE_ENDS,
958 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Left, 0, "move-cursor", 2,
959 G_TYPE_ENUM, GTK_MOVEMENT_DISPLAY_LINE_ENDS,
962 gtk_binding_entry_add_signal (binding_set[i], GDK_Right, GDK_CONTROL_MASK,
964 G_TYPE_ENUM, GTK_MOVEMENT_DISPLAY_LINE_ENDS,
967 gtk_binding_entry_add_signal (binding_set[i], GDK_Left, GDK_CONTROL_MASK,
969 G_TYPE_ENUM, GTK_MOVEMENT_DISPLAY_LINE_ENDS,
972 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Right, GDK_CONTROL_MASK,
974 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
977 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Left, GDK_CONTROL_MASK,
979 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
982 gtk_binding_entry_add_signal (binding_set[i], GDK_f, GDK_CONTROL_MASK, "start-interactive-search", 0);
984 gtk_binding_entry_add_signal (binding_set[i], GDK_F, GDK_CONTROL_MASK, "start-interactive-search", 0);
987 gtk_binding_entry_add_signal (binding_set[0], GDK_space, GDK_CONTROL_MASK, "toggle-cursor-row", 0);
988 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Space, GDK_CONTROL_MASK, "toggle-cursor-row", 0);
990 gtk_binding_entry_add_signal (binding_set[0], GDK_a, GDK_CONTROL_MASK, "select-all", 0);
991 gtk_binding_entry_add_signal (binding_set[0], GDK_slash, GDK_CONTROL_MASK, "select-all", 0);
993 gtk_binding_entry_add_signal (binding_set[0], GDK_A, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "unselect-all", 0);
994 gtk_binding_entry_add_signal (binding_set[0], GDK_backslash, GDK_CONTROL_MASK, "unselect-all", 0);
996 gtk_binding_entry_add_signal (binding_set[0], GDK_space, GDK_SHIFT_MASK, "select-cursor-row", 1,
997 G_TYPE_BOOLEAN, TRUE,
998 G_TYPE_INT, PSPP_SHEET_SELECT_MODE_EXTEND);
999 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Space, GDK_SHIFT_MASK, "select-cursor-row", 1,
1000 G_TYPE_BOOLEAN, TRUE,
1001 G_TYPE_INT, PSPP_SHEET_SELECT_MODE_EXTEND);
1003 gtk_binding_entry_add_signal (binding_set[0], GDK_space, 0, "select-cursor-row", 1,
1004 G_TYPE_BOOLEAN, TRUE,
1006 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Space, 0, "select-cursor-row", 1,
1007 G_TYPE_BOOLEAN, TRUE,
1009 gtk_binding_entry_add_signal (binding_set[0], GDK_Return, 0, "select-cursor-row", 1,
1010 G_TYPE_BOOLEAN, TRUE,
1012 gtk_binding_entry_add_signal (binding_set[0], GDK_ISO_Enter, 0, "select-cursor-row", 1,
1013 G_TYPE_BOOLEAN, TRUE,
1015 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Enter, 0, "select-cursor-row", 1,
1016 G_TYPE_BOOLEAN, TRUE,
1019 gtk_binding_entry_add_signal (binding_set[0], GDK_BackSpace, 0, "select-cursor-parent", 0);
1020 gtk_binding_entry_add_signal (binding_set[0], GDK_BackSpace, GDK_CONTROL_MASK, "select-cursor-parent", 0);
1022 g_type_class_add_private (o_class, sizeof (PsppSheetViewPrivate));
1026 pspp_sheet_view_buildable_init (GtkBuildableIface *iface)
1028 iface->add_child = pspp_sheet_view_buildable_add_child;
1032 pspp_sheet_view_init (PsppSheetView *tree_view)
1034 tree_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (tree_view, PSPP_TYPE_SHEET_VIEW, PsppSheetViewPrivate);
1036 gtk_widget_set_can_focus (GTK_WIDGET (tree_view), TRUE);
1037 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (tree_view), FALSE);
1039 tree_view->priv->flags = PSPP_SHEET_VIEW_DRAW_KEYFOCUS
1040 | PSPP_SHEET_VIEW_HEADERS_VISIBLE;
1042 /* We need some padding */
1043 tree_view->priv->selected = range_tower_create ();
1044 tree_view->priv->dy = 0;
1045 tree_view->priv->cursor_offset = 0;
1046 tree_view->priv->n_columns = 0;
1047 tree_view->priv->header_height = 1;
1048 tree_view->priv->x_drag = 0;
1049 tree_view->priv->drag_pos = -1;
1050 tree_view->priv->header_has_focus = FALSE;
1051 tree_view->priv->pressed_button = -1;
1052 tree_view->priv->press_start_x = -1;
1053 tree_view->priv->press_start_y = -1;
1054 tree_view->priv->reorderable = FALSE;
1055 tree_view->priv->presize_handler_timer = 0;
1056 tree_view->priv->scroll_sync_timer = 0;
1057 tree_view->priv->fixed_height = -1;
1058 tree_view->priv->fixed_height_set = FALSE;
1059 pspp_sheet_view_set_adjustments (tree_view, NULL, NULL);
1060 tree_view->priv->selection = _pspp_sheet_selection_new_with_tree_view (tree_view);
1061 tree_view->priv->enable_search = TRUE;
1062 tree_view->priv->search_column = -1;
1063 tree_view->priv->search_position_func = pspp_sheet_view_search_position_func;
1064 tree_view->priv->search_equal_func = pspp_sheet_view_search_equal_func;
1065 tree_view->priv->search_custom_entry_set = FALSE;
1066 tree_view->priv->typeselect_flush_timeout = 0;
1067 tree_view->priv->init_hadjust_value = TRUE;
1068 tree_view->priv->width = 0;
1070 tree_view->priv->hover_selection = FALSE;
1072 tree_view->priv->rubber_banding_enable = FALSE;
1074 tree_view->priv->grid_lines = PSPP_SHEET_VIEW_GRID_LINES_NONE;
1076 tree_view->priv->tooltip_column = -1;
1078 tree_view->priv->special_cells = PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT;
1080 tree_view->priv->post_validation_flag = FALSE;
1082 tree_view->priv->last_button_x = -1;
1083 tree_view->priv->last_button_y = -1;
1085 tree_view->priv->event_last_x = -10000;
1086 tree_view->priv->event_last_y = -10000;
1088 tree_view->priv->prelight_node = -1;
1089 tree_view->priv->rubber_band_start_node = -1;
1090 tree_view->priv->rubber_band_end_node = -1;
1092 tree_view->priv->anchor_column = NULL;
1094 tree_view->priv->button_style = NULL;
1096 tree_view->dispose_has_run = FALSE;
1105 pspp_sheet_view_set_property (GObject *object,
1107 const GValue *value,
1110 PsppSheetView *tree_view;
1112 tree_view = PSPP_SHEET_VIEW (object);
1117 pspp_sheet_view_set_model (tree_view, g_value_get_object (value));
1119 case PROP_HADJUSTMENT:
1120 pspp_sheet_view_set_hadjustment (tree_view, g_value_get_object (value));
1122 case PROP_VADJUSTMENT:
1123 pspp_sheet_view_set_vadjustment (tree_view, g_value_get_object (value));
1125 case PROP_HEADERS_VISIBLE:
1126 pspp_sheet_view_set_headers_visible (tree_view, g_value_get_boolean (value));
1128 case PROP_HEADERS_CLICKABLE:
1129 pspp_sheet_view_set_headers_clickable (tree_view, g_value_get_boolean (value));
1131 case PROP_REORDERABLE:
1132 pspp_sheet_view_set_reorderable (tree_view, g_value_get_boolean (value));
1134 case PROP_RULES_HINT:
1135 pspp_sheet_view_set_rules_hint (tree_view, g_value_get_boolean (value));
1137 case PROP_ENABLE_SEARCH:
1138 pspp_sheet_view_set_enable_search (tree_view, g_value_get_boolean (value));
1140 case PROP_SEARCH_COLUMN:
1141 pspp_sheet_view_set_search_column (tree_view, g_value_get_int (value));
1143 case PROP_HOVER_SELECTION:
1144 tree_view->priv->hover_selection = g_value_get_boolean (value);
1146 case PROP_RUBBER_BANDING:
1147 tree_view->priv->rubber_banding_enable = g_value_get_boolean (value);
1149 case PROP_ENABLE_GRID_LINES:
1150 pspp_sheet_view_set_grid_lines (tree_view, g_value_get_enum (value));
1152 case PROP_TOOLTIP_COLUMN:
1153 pspp_sheet_view_set_tooltip_column (tree_view, g_value_get_int (value));
1155 case PROP_SPECIAL_CELLS:
1156 pspp_sheet_view_set_special_cells (tree_view, g_value_get_enum (value));
1158 case PROP_FIXED_HEIGHT:
1159 pspp_sheet_view_set_fixed_height (tree_view, g_value_get_int (value));
1161 case PROP_FIXED_HEIGHT_SET:
1162 if (g_value_get_boolean (value))
1164 if (!tree_view->priv->fixed_height_set
1165 && tree_view->priv->fixed_height >= 0)
1167 tree_view->priv->fixed_height_set = true;
1168 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
1173 if (tree_view->priv->fixed_height_set)
1175 tree_view->priv->fixed_height_set = false;
1176 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
1177 install_presize_handler (tree_view);
1182 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1188 pspp_sheet_view_get_property (GObject *object,
1193 PsppSheetView *tree_view;
1195 tree_view = PSPP_SHEET_VIEW (object);
1200 g_value_set_object (value, tree_view->priv->model);
1202 case PROP_HADJUSTMENT:
1203 g_value_set_object (value, tree_view->priv->hadjustment);
1205 case PROP_VADJUSTMENT:
1206 g_value_set_object (value, tree_view->priv->vadjustment);
1208 case PROP_HEADERS_VISIBLE:
1209 g_value_set_boolean (value, pspp_sheet_view_get_headers_visible (tree_view));
1211 case PROP_HEADERS_CLICKABLE:
1212 g_value_set_boolean (value, pspp_sheet_view_get_headers_clickable (tree_view));
1214 case PROP_REORDERABLE:
1215 g_value_set_boolean (value, tree_view->priv->reorderable);
1217 case PROP_RULES_HINT:
1218 g_value_set_boolean (value, tree_view->priv->has_rules);
1220 case PROP_ENABLE_SEARCH:
1221 g_value_set_boolean (value, tree_view->priv->enable_search);
1223 case PROP_SEARCH_COLUMN:
1224 g_value_set_int (value, tree_view->priv->search_column);
1226 case PROP_HOVER_SELECTION:
1227 g_value_set_boolean (value, tree_view->priv->hover_selection);
1229 case PROP_RUBBER_BANDING:
1230 g_value_set_boolean (value, tree_view->priv->rubber_banding_enable);
1232 case PROP_ENABLE_GRID_LINES:
1233 g_value_set_enum (value, tree_view->priv->grid_lines);
1235 case PROP_TOOLTIP_COLUMN:
1236 g_value_set_int (value, tree_view->priv->tooltip_column);
1238 case PROP_SPECIAL_CELLS:
1239 g_value_set_enum (value, tree_view->priv->special_cells);
1241 case PROP_FIXED_HEIGHT:
1242 g_value_set_int (value, pspp_sheet_view_get_fixed_height (tree_view));
1244 case PROP_FIXED_HEIGHT_SET:
1245 g_value_set_boolean (value, tree_view->priv->fixed_height_set);
1248 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1254 pspp_sheet_view_dispose (GObject *object)
1256 PsppSheetView *tree_view = PSPP_SHEET_VIEW (object);
1258 if (tree_view->dispose_has_run)
1261 tree_view->dispose_has_run = TRUE;
1263 if (tree_view->priv->selection != NULL)
1265 _pspp_sheet_selection_set_tree_view (tree_view->priv->selection, NULL);
1266 g_object_unref (tree_view->priv->selection);
1267 tree_view->priv->selection = NULL;
1270 if (tree_view->priv->hadjustment)
1272 g_object_unref (tree_view->priv->hadjustment);
1273 tree_view->priv->hadjustment = NULL;
1275 if (tree_view->priv->vadjustment)
1277 g_object_unref (tree_view->priv->vadjustment);
1278 tree_view->priv->vadjustment = NULL;
1281 if (tree_view->priv->button_style)
1283 g_object_unref (tree_view->priv->button_style);
1284 tree_view->priv->button_style = NULL;
1288 G_OBJECT_CLASS (pspp_sheet_view_parent_class)->dispose (object);
1294 pspp_sheet_view_buildable_add_child (GtkBuildable *tree_view,
1295 GtkBuilder *builder,
1299 pspp_sheet_view_append_column (PSPP_SHEET_VIEW (tree_view), PSPP_SHEET_VIEW_COLUMN (child));
1303 pspp_sheet_view_finalize (GObject *object)
1305 PsppSheetView *tree_view = PSPP_SHEET_VIEW (object);
1307 pspp_sheet_view_stop_editing (tree_view, TRUE);
1309 if (tree_view->priv->selected != NULL)
1311 range_tower_destroy (tree_view->priv->selected);
1312 tree_view->priv->selected = NULL;
1316 tree_view->priv->prelight_node = -1;
1319 if (tree_view->priv->scroll_to_path != NULL)
1321 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
1322 tree_view->priv->scroll_to_path = NULL;
1325 if (tree_view->priv->drag_dest_row != NULL)
1327 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
1328 tree_view->priv->drag_dest_row = NULL;
1331 if (tree_view->priv->top_row != NULL)
1333 gtk_tree_row_reference_free (tree_view->priv->top_row);
1334 tree_view->priv->top_row = NULL;
1337 if (tree_view->priv->column_drop_func_data &&
1338 tree_view->priv->column_drop_func_data_destroy)
1340 tree_view->priv->column_drop_func_data_destroy (tree_view->priv->column_drop_func_data);
1341 tree_view->priv->column_drop_func_data = NULL;
1344 if (tree_view->priv->destroy_count_destroy &&
1345 tree_view->priv->destroy_count_data)
1347 tree_view->priv->destroy_count_destroy (tree_view->priv->destroy_count_data);
1348 tree_view->priv->destroy_count_data = NULL;
1351 gtk_tree_row_reference_free (tree_view->priv->cursor);
1352 tree_view->priv->cursor = NULL;
1354 gtk_tree_row_reference_free (tree_view->priv->anchor);
1355 tree_view->priv->anchor = NULL;
1357 /* destroy interactive search dialog */
1358 if (tree_view->priv->search_window)
1360 gtk_widget_destroy (tree_view->priv->search_window);
1361 tree_view->priv->search_window = NULL;
1362 tree_view->priv->search_entry = NULL;
1363 if (tree_view->priv->typeselect_flush_timeout)
1365 g_source_remove (tree_view->priv->typeselect_flush_timeout);
1366 tree_view->priv->typeselect_flush_timeout = 0;
1370 if (tree_view->priv->search_destroy && tree_view->priv->search_user_data)
1372 tree_view->priv->search_destroy (tree_view->priv->search_user_data);
1373 tree_view->priv->search_user_data = NULL;
1376 if (tree_view->priv->search_position_destroy && tree_view->priv->search_position_user_data)
1378 tree_view->priv->search_position_destroy (tree_view->priv->search_position_user_data);
1379 tree_view->priv->search_position_user_data = NULL;
1382 pspp_sheet_view_set_model (tree_view, NULL);
1385 G_OBJECT_CLASS (pspp_sheet_view_parent_class)->finalize (object);
1390 /* GtkWidget Methods
1393 /* GtkWidget::map helper */
1395 pspp_sheet_view_map_buttons (PsppSheetView *tree_view)
1399 g_return_if_fail (gtk_widget_get_mapped (GTK_WIDGET (tree_view)));
1401 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
1403 PsppSheetViewColumn *column;
1405 for (list = tree_view->priv->columns; list; list = list->next)
1407 column = list->data;
1408 if (column->button != NULL &&
1409 gtk_widget_get_visible (column->button) &&
1410 !gtk_widget_get_mapped (column->button))
1411 gtk_widget_map (column->button);
1413 for (list = tree_view->priv->columns; list; list = list->next)
1415 column = list->data;
1416 if (column->visible == FALSE || column->window == NULL)
1418 if (column->resizable)
1420 gdk_window_raise (column->window);
1421 gdk_window_show (column->window);
1424 gdk_window_hide (column->window);
1426 gdk_window_show (tree_view->priv->header_window);
1431 pspp_sheet_view_map (GtkWidget *widget)
1433 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1436 gtk_widget_set_mapped (widget, TRUE);
1438 tmp_list = tree_view->priv->children;
1441 PsppSheetViewChild *child = tmp_list->data;
1442 tmp_list = tmp_list->next;
1444 if (gtk_widget_get_visible (child->widget))
1446 if (!gtk_widget_get_mapped (child->widget))
1447 gtk_widget_map (child->widget);
1450 gdk_window_show (tree_view->priv->bin_window);
1452 pspp_sheet_view_map_buttons (tree_view);
1454 gdk_window_show (gtk_widget_get_window (widget));
1458 pspp_sheet_view_realize (GtkWidget *widget)
1460 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1462 GdkWindowAttr attributes;
1463 gint attributes_mask;
1464 GtkAllocation allocation;
1465 GtkAllocation old_allocation;
1467 gtk_widget_set_realized (widget, TRUE);
1469 gtk_widget_get_allocation (widget, &allocation);
1470 gtk_widget_get_allocation (widget, &old_allocation);
1472 /* Make the main, clipping window */
1473 attributes.window_type = GDK_WINDOW_CHILD;
1474 attributes.x = allocation.x;
1475 attributes.y = allocation.y;
1476 attributes.width = allocation.width;
1477 attributes.height = allocation.height;
1478 attributes.wclass = GDK_INPUT_OUTPUT;
1479 attributes.visual = gtk_widget_get_visual (widget);
1480 attributes.colormap = gtk_widget_get_colormap (widget);
1481 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1483 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1485 gtk_widget_set_window (widget,
1486 gdk_window_new (gtk_widget_get_parent_window (widget),
1487 &attributes, attributes_mask));
1488 gdk_window_set_user_data (gtk_widget_get_window (widget), widget);
1490 /* Make the window for the tree */
1492 attributes.y = TREE_VIEW_HEADER_HEIGHT (tree_view);
1493 attributes.width = MAX (tree_view->priv->width, old_allocation.width);
1494 attributes.height = old_allocation.height;
1495 attributes.event_mask = (GDK_EXPOSURE_MASK |
1497 GDK_POINTER_MOTION_MASK |
1498 GDK_ENTER_NOTIFY_MASK |
1499 GDK_LEAVE_NOTIFY_MASK |
1500 GDK_BUTTON_PRESS_MASK |
1501 GDK_BUTTON_RELEASE_MASK |
1502 gtk_widget_get_events (widget));
1504 tree_view->priv->bin_window = gdk_window_new (gtk_widget_get_window (widget),
1505 &attributes, attributes_mask);
1506 gdk_window_set_user_data (tree_view->priv->bin_window, widget);
1508 /* Make the column header window */
1511 attributes.width = MAX (tree_view->priv->width, old_allocation.width);
1512 attributes.height = tree_view->priv->header_height;
1513 attributes.event_mask = (GDK_EXPOSURE_MASK |
1515 GDK_BUTTON_PRESS_MASK |
1516 GDK_BUTTON_RELEASE_MASK |
1517 GDK_KEY_PRESS_MASK |
1518 GDK_KEY_RELEASE_MASK |
1519 gtk_widget_get_events (widget));
1521 tree_view->priv->header_window = gdk_window_new (gtk_widget_get_window (widget),
1522 &attributes, attributes_mask);
1523 gdk_window_set_user_data (tree_view->priv->header_window, widget);
1525 /* Add them all up. */
1526 gtk_widget_set_style (widget,
1527 gtk_style_attach (gtk_widget_get_style (widget), gtk_widget_get_window (widget)));
1528 gdk_window_set_background (tree_view->priv->bin_window, >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
1529 gtk_style_set_background (gtk_widget_get_style (widget), tree_view->priv->header_window, GTK_STATE_NORMAL);
1531 tmp_list = tree_view->priv->children;
1534 PsppSheetViewChild *child = tmp_list->data;
1535 tmp_list = tmp_list->next;
1537 gtk_widget_set_parent_window (child->widget, tree_view->priv->bin_window);
1540 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
1541 _pspp_sheet_view_column_realize_button (PSPP_SHEET_VIEW_COLUMN (tmp_list->data));
1543 /* Need to call those here, since they create GCs */
1544 pspp_sheet_view_set_grid_lines (tree_view, tree_view->priv->grid_lines);
1546 install_presize_handler (tree_view);
1550 pspp_sheet_view_unrealize (GtkWidget *widget)
1552 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1553 PsppSheetViewPrivate *priv = tree_view->priv;
1556 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->unrealize (widget);
1558 if (priv->scroll_timeout != 0)
1560 g_source_remove (priv->scroll_timeout);
1561 priv->scroll_timeout = 0;
1564 if (priv->open_dest_timeout != 0)
1566 g_source_remove (priv->open_dest_timeout);
1567 priv->open_dest_timeout = 0;
1570 if (priv->presize_handler_timer != 0)
1572 g_source_remove (priv->presize_handler_timer);
1573 priv->presize_handler_timer = 0;
1576 if (priv->validate_rows_timer != 0)
1578 g_source_remove (priv->validate_rows_timer);
1579 priv->validate_rows_timer = 0;
1582 if (priv->scroll_sync_timer != 0)
1584 g_source_remove (priv->scroll_sync_timer);
1585 priv->scroll_sync_timer = 0;
1588 if (priv->typeselect_flush_timeout)
1590 g_source_remove (priv->typeselect_flush_timeout);
1591 priv->typeselect_flush_timeout = 0;
1594 for (list = priv->columns; list; list = list->next)
1595 _pspp_sheet_view_column_unrealize_button (PSPP_SHEET_VIEW_COLUMN (list->data));
1597 gdk_window_set_user_data (priv->bin_window, NULL);
1598 gdk_window_destroy (priv->bin_window);
1599 priv->bin_window = NULL;
1601 gdk_window_set_user_data (priv->header_window, NULL);
1602 gdk_window_destroy (priv->header_window);
1603 priv->header_window = NULL;
1605 if (priv->drag_window)
1607 gdk_window_set_user_data (priv->drag_window, NULL);
1608 gdk_window_destroy (priv->drag_window);
1609 priv->drag_window = NULL;
1612 if (priv->drag_highlight_window)
1614 gdk_window_set_user_data (priv->drag_highlight_window, NULL);
1615 gdk_window_destroy (priv->drag_highlight_window);
1616 priv->drag_highlight_window = NULL;
1619 if (tree_view->priv->columns != NULL)
1621 list = tree_view->priv->columns;
1624 PsppSheetViewColumn *column;
1625 column = PSPP_SHEET_VIEW_COLUMN (list->data);
1627 pspp_sheet_view_remove_column (tree_view, column);
1629 tree_view->priv->columns = NULL;
1633 /* GtkWidget::size_request helper */
1635 pspp_sheet_view_size_request_columns (PsppSheetView *tree_view)
1639 tree_view->priv->header_height = 0;
1641 if (tree_view->priv->model)
1643 for (list = tree_view->priv->columns; list; list = list->next)
1645 GtkRequisition requisition;
1646 PsppSheetViewColumn *column = list->data;
1648 pspp_sheet_view_column_size_request (column, &requisition);
1649 column->button_request = requisition.width;
1650 tree_view->priv->header_height = MAX (tree_view->priv->header_height, requisition.height);
1656 /* Called only by ::size_request */
1658 pspp_sheet_view_update_size (PsppSheetView *tree_view)
1661 PsppSheetViewColumn *column;
1664 if (tree_view->priv->model == NULL)
1666 tree_view->priv->width = 0;
1667 tree_view->priv->prev_width = 0;
1668 tree_view->priv->height = 0;
1672 tree_view->priv->prev_width = tree_view->priv->width;
1673 tree_view->priv->width = 0;
1675 /* keep this in sync with size_allocate below */
1676 for (list = tree_view->priv->columns, i = 0; list; list = list->next, i++)
1678 gint real_requested_width = 0;
1679 column = list->data;
1680 if (!column->visible)
1683 if (column->use_resized_width)
1685 real_requested_width = column->resized_width;
1689 real_requested_width = column->fixed_width;
1692 if (column->min_width != -1)
1693 real_requested_width = MAX (real_requested_width, column->min_width);
1694 if (column->max_width != -1)
1695 real_requested_width = MIN (real_requested_width, column->max_width);
1697 tree_view->priv->width += real_requested_width;
1700 tree_view->priv->height = tree_view->priv->fixed_height * tree_view->priv->row_count;
1704 pspp_sheet_view_size_request (GtkWidget *widget,
1705 GtkRequisition *requisition)
1707 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1710 /* we validate some rows initially just to make sure we have some size.
1711 * In practice, with a lot of static lists, this should get a good width.
1713 initialize_fixed_height_mode (tree_view);
1714 pspp_sheet_view_size_request_columns (tree_view);
1715 pspp_sheet_view_update_size (PSPP_SHEET_VIEW (widget));
1717 requisition->width = tree_view->priv->width;
1718 requisition->height = tree_view->priv->height + TREE_VIEW_HEADER_HEIGHT (tree_view);
1720 tmp_list = tree_view->priv->children;
1724 PsppSheetViewChild *child = tmp_list->data;
1725 GtkRequisition child_requisition;
1727 tmp_list = tmp_list->next;
1729 if (gtk_widget_get_visible (child->widget))
1730 gtk_widget_size_request (child->widget, &child_requisition);
1735 invalidate_column (PsppSheetView *tree_view,
1736 PsppSheetViewColumn *column)
1738 gint column_offset = 0;
1740 GtkWidget *widget = GTK_WIDGET (tree_view);
1743 if (!gtk_widget_get_realized (widget))
1746 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
1747 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
1749 list = (rtl ? list->prev : list->next))
1751 PsppSheetViewColumn *tmpcolumn = list->data;
1752 if (tmpcolumn == column)
1754 GdkRectangle invalid_rect;
1755 GtkAllocation allocation;
1757 gtk_widget_get_allocation (widget, &allocation);
1758 invalid_rect.x = column_offset;
1760 invalid_rect.width = column->width;
1761 invalid_rect.height = allocation.height;
1763 gdk_window_invalidate_rect (gtk_widget_get_window (widget), &invalid_rect, TRUE);
1767 column_offset += tmpcolumn->width;
1772 invalidate_last_column (PsppSheetView *tree_view)
1777 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
1779 for (last_column = (rtl ? g_list_first (tree_view->priv->columns) : g_list_last (tree_view->priv->columns));
1781 last_column = (rtl ? last_column->next : last_column->prev))
1783 if (PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible)
1785 invalidate_column (tree_view, last_column->data);
1792 pspp_sheet_view_get_real_requested_width_from_column (PsppSheetView *tree_view,
1793 PsppSheetViewColumn *column)
1795 gint real_requested_width;
1797 if (column->use_resized_width)
1799 real_requested_width = column->resized_width;
1803 real_requested_width = column->fixed_width;
1806 if (column->min_width != -1)
1807 real_requested_width = MAX (real_requested_width, column->min_width);
1808 if (column->max_width != -1)
1809 real_requested_width = MIN (real_requested_width, column->max_width);
1811 return real_requested_width;
1815 span_intersects (int a0, int a_width,
1816 int b0, int b_width)
1818 int a1 = a0 + a_width;
1819 int b1 = b0 + b_width;
1820 return (a0 >= b0 && a0 < b1) || (b0 >= a0 && b0 < a1);
1823 /* GtkWidget::size_allocate helper */
1825 pspp_sheet_view_size_allocate_columns (GtkWidget *widget,
1826 gboolean *width_changed)
1828 PsppSheetView *tree_view;
1829 GList *list, *first_column, *last_column;
1830 PsppSheetViewColumn *column;
1831 GtkAllocation col_allocation;
1832 GtkAllocation allocation;
1834 gint extra, extra_per_column;
1835 gint full_requested_width = 0;
1836 gint number_of_expand_columns = 0;
1837 gboolean column_changed = FALSE;
1840 tree_view = PSPP_SHEET_VIEW (widget);
1842 for (last_column = g_list_last (tree_view->priv->columns);
1843 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
1844 last_column = last_column->prev)
1847 if (last_column == NULL)
1850 for (first_column = g_list_first (tree_view->priv->columns);
1851 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
1852 first_column = first_column->next)
1855 col_allocation.y = 0;
1856 col_allocation.height = tree_view->priv->header_height;
1858 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1860 /* find out how many extra space and expandable columns we have */
1861 for (list = tree_view->priv->columns; list != last_column->next; list = list->next)
1863 column = (PsppSheetViewColumn *)list->data;
1865 if (!column->visible)
1868 full_requested_width += pspp_sheet_view_get_real_requested_width_from_column (tree_view, column);
1871 number_of_expand_columns++;
1874 gtk_widget_get_allocation (widget, &allocation);
1875 extra = MAX (allocation.width - full_requested_width, 0);
1876 if (number_of_expand_columns > 0)
1877 extra_per_column = extra/number_of_expand_columns;
1879 extra_per_column = 0;
1881 for (list = (rtl ? last_column : first_column);
1882 list != (rtl ? first_column->prev : last_column->next);
1883 list = (rtl ? list->prev : list->next))
1885 gint real_requested_width = 0;
1888 column = list->data;
1889 old_width = column->width;
1891 if (!column->visible)
1894 /* We need to handle the dragged button specially.
1896 if (column == tree_view->priv->drag_column)
1898 GtkAllocation drag_allocation;
1899 drag_allocation.width = gdk_window_get_width (tree_view->priv->drag_window);
1900 drag_allocation.height = gdk_window_get_height (tree_view->priv->drag_window);
1901 drag_allocation.x = 0;
1902 drag_allocation.y = 0;
1903 pspp_sheet_view_column_size_allocate (tree_view->priv->drag_column,
1905 width += drag_allocation.width;
1909 real_requested_width = pspp_sheet_view_get_real_requested_width_from_column (tree_view, column);
1911 col_allocation.x = width;
1912 column->width = real_requested_width;
1916 if (number_of_expand_columns == 1)
1918 /* We add the remander to the last column as
1920 column->width += extra;
1924 column->width += extra_per_column;
1925 extra -= extra_per_column;
1926 number_of_expand_columns --;
1930 if (column->width != old_width)
1931 g_object_notify (G_OBJECT (column), "width");
1933 col_allocation.width = column->width;
1934 width += column->width;
1936 if (column->width > old_width)
1937 column_changed = TRUE;
1939 pspp_sheet_view_column_size_allocate (column, &col_allocation);
1941 if (span_intersects (col_allocation.x, col_allocation.width,
1942 gtk_adjustment_get_value (tree_view->priv->hadjustment),
1944 && gtk_widget_get_realized (widget))
1945 pspp_sheet_view_column_set_need_button (column, TRUE);
1948 gdk_window_move_resize (column->window,
1949 col_allocation.x + (rtl ? 0 : col_allocation.width) - TREE_VIEW_DRAG_WIDTH/2,
1951 TREE_VIEW_DRAG_WIDTH, col_allocation.height);
1954 /* We change the width here. The user might have been resizing columns,
1955 * so the total width of the tree view changes.
1957 tree_view->priv->width = width;
1959 *width_changed = TRUE;
1962 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
1966 pspp_sheet_view_size_allocate (GtkWidget *widget,
1967 GtkAllocation *allocation)
1969 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1971 gboolean width_changed = FALSE;
1972 GtkAllocation old_allocation;
1973 gtk_widget_get_allocation (widget, &old_allocation);
1975 if (allocation->width != old_allocation.width)
1976 width_changed = TRUE;
1979 gtk_widget_set_allocation (widget, allocation);
1981 tmp_list = tree_view->priv->children;
1985 GtkAllocation allocation;
1987 PsppSheetViewChild *child = tmp_list->data;
1988 tmp_list = tmp_list->next;
1990 /* totally ignore our child's requisition */
1991 allocation.x = child->x;
1992 allocation.y = child->y;
1993 allocation.width = child->width;
1994 allocation.height = child->height;
1995 gtk_widget_size_allocate (child->widget, &allocation);
1998 /* We size-allocate the columns first because the width of the
1999 * tree view (used in updating the adjustments below) might change.
2001 pspp_sheet_view_size_allocate_columns (widget, &width_changed);
2003 gtk_adjustment_set_page_size (tree_view->priv->hadjustment, allocation->width);
2004 gtk_adjustment_set_page_increment (tree_view->priv->hadjustment, allocation->width * 0.9);
2005 gtk_adjustment_set_step_increment (tree_view->priv->hadjustment, allocation->width * 0.1);
2006 gtk_adjustment_set_lower (tree_view->priv->hadjustment, 0);
2007 gtk_adjustment_set_upper (tree_view->priv->hadjustment, MAX (gtk_adjustment_get_page_size (tree_view->priv->hadjustment), tree_view->priv->width));
2009 if (gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL)
2011 if (allocation->width < tree_view->priv->width)
2013 if (tree_view->priv->init_hadjust_value)
2015 gtk_adjustment_set_value (tree_view->priv->hadjustment, MAX (tree_view->priv->width - allocation->width, 0));
2016 tree_view->priv->init_hadjust_value = FALSE;
2018 else if (allocation->width != old_allocation.width)
2020 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));
2023 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));
2027 gtk_adjustment_set_value (tree_view->priv->hadjustment, 0);
2028 tree_view->priv->init_hadjust_value = TRUE;
2032 if (gtk_adjustment_get_value (tree_view->priv->hadjustment) + allocation->width > tree_view->priv->width)
2033 gtk_adjustment_set_value (tree_view->priv->hadjustment, MAX (tree_view->priv->width - allocation->width, 0));
2035 gtk_adjustment_changed (tree_view->priv->hadjustment);
2037 gtk_adjustment_set_page_size (tree_view->priv->vadjustment, allocation->height - TREE_VIEW_HEADER_HEIGHT (tree_view));
2038 gtk_adjustment_set_step_increment (tree_view->priv->vadjustment, gtk_adjustment_get_page_size (tree_view->priv->vadjustment) * 0.1);
2039 gtk_adjustment_set_page_increment (tree_view->priv->vadjustment, gtk_adjustment_get_page_size (tree_view->priv->vadjustment) * 0.9);
2040 gtk_adjustment_set_lower (tree_view->priv->vadjustment, 0);
2041 gtk_adjustment_set_upper (tree_view->priv->vadjustment, MAX (gtk_adjustment_get_page_size (tree_view->priv->vadjustment), tree_view->priv->height));
2043 gtk_adjustment_changed (tree_view->priv->vadjustment);
2045 /* now the adjustments and window sizes are in sync, we can sync toprow/dy again */
2046 if (tree_view->priv->height <= gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
2047 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment), 0);
2048 else if (gtk_adjustment_get_value (tree_view->priv->vadjustment) + gtk_adjustment_get_page_size (tree_view->priv->vadjustment) > tree_view->priv->height)
2049 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment),
2050 tree_view->priv->height - gtk_adjustment_get_page_size (tree_view->priv->vadjustment));
2051 else if (gtk_tree_row_reference_valid (tree_view->priv->top_row))
2052 pspp_sheet_view_top_row_to_dy (tree_view);
2054 pspp_sheet_view_dy_to_top_row (tree_view);
2056 if (gtk_widget_get_realized (widget))
2058 gdk_window_move_resize (gtk_widget_get_window (widget),
2059 allocation->x, allocation->y,
2060 allocation->width, allocation->height);
2061 gdk_window_move_resize (tree_view->priv->header_window,
2062 - (gint) gtk_adjustment_get_value (tree_view->priv->hadjustment),
2064 MAX (tree_view->priv->width, allocation->width),
2065 tree_view->priv->header_height);
2066 gdk_window_move_resize (tree_view->priv->bin_window,
2067 - (gint) gtk_adjustment_get_value (tree_view->priv->hadjustment),
2068 TREE_VIEW_HEADER_HEIGHT (tree_view),
2069 MAX (tree_view->priv->width, allocation->width),
2070 allocation->height - TREE_VIEW_HEADER_HEIGHT (tree_view));
2073 if (tree_view->priv->row_count == 0)
2074 invalidate_empty_focus (tree_view);
2076 if (gtk_widget_get_realized (widget))
2078 gboolean has_expand_column = FALSE;
2079 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
2081 if (pspp_sheet_view_column_get_expand (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)))
2083 has_expand_column = TRUE;
2088 /* This little hack only works if we have an LTR locale, and no column has the */
2091 if (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_LTR &&
2092 ! has_expand_column)
2093 invalidate_last_column (tree_view);
2095 gtk_widget_queue_draw (widget);
2100 /* Grabs the focus and unsets the PSPP_SHEET_VIEW_DRAW_KEYFOCUS flag */
2102 grab_focus_and_unset_draw_keyfocus (PsppSheetView *tree_view)
2104 GtkWidget *widget = GTK_WIDGET (tree_view);
2106 if (gtk_widget_get_can_focus (widget) && !gtk_widget_has_focus (widget))
2107 gtk_widget_grab_focus (widget);
2108 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
2112 pspp_sheet_view_node_is_selected (PsppSheetView *tree_view,
2115 return node >= 0 && range_tower_contains (tree_view->priv->selected, node);
2119 pspp_sheet_view_node_select (PsppSheetView *tree_view,
2122 range_tower_set1 (tree_view->priv->selected, node, 1);
2126 pspp_sheet_view_node_unselect (PsppSheetView *tree_view,
2129 range_tower_set0 (tree_view->priv->selected, node, 1);
2133 pspp_sheet_view_node_next (PsppSheetView *tree_view,
2136 return node + 1 < tree_view->priv->row_count ? node + 1 : -1;
2140 pspp_sheet_view_node_prev (PsppSheetView *tree_view,
2143 return node > 0 ? node - 1 : -1;
2147 all_columns_selected (PsppSheetView *tree_view)
2151 for (list = tree_view->priv->columns; list; list = list->next)
2153 PsppSheetViewColumn *column = list->data;
2154 if (column->selectable && !column->selected)
2162 pspp_sheet_view_row_head_clicked (PsppSheetView *tree_view,
2164 PsppSheetViewColumn *column,
2165 GdkEventButton *event)
2167 PsppSheetSelection *selection;
2168 PsppSheetSelectionMode mode;
2170 gboolean update_anchor;
2174 g_return_val_if_fail (tree_view != NULL, FALSE);
2175 g_return_val_if_fail (column != NULL, FALSE);
2177 selection = tree_view->priv->selection;
2178 mode = pspp_sheet_selection_get_mode (selection);
2179 if (mode != PSPP_SHEET_SELECTION_RECTANGLE)
2182 if (!column->row_head)
2187 modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
2188 if (event->type != GDK_BUTTON_PRESS
2189 || (modifiers != GDK_CONTROL_MASK && modifiers != GDK_SHIFT_MASK))
2195 path = gtk_tree_path_new_from_indices (node, -1);
2198 pspp_sheet_selection_unselect_all (selection);
2199 pspp_sheet_selection_select_path (selection, path);
2200 pspp_sheet_selection_select_all_columns (selection);
2201 update_anchor = TRUE;
2204 else if (event->type == GDK_BUTTON_PRESS && event->button == 3)
2206 if (pspp_sheet_selection_count_selected_rows (selection) <= 1
2207 || !all_columns_selected (tree_view))
2209 pspp_sheet_selection_unselect_all (selection);
2210 pspp_sheet_selection_select_path (selection, path);
2211 pspp_sheet_selection_select_all_columns (selection);
2212 update_anchor = TRUE;
2216 update_anchor = handled = FALSE;
2218 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
2219 && modifiers == GDK_CONTROL_MASK)
2221 if (!all_columns_selected (tree_view))
2223 pspp_sheet_selection_unselect_all (selection);
2224 pspp_sheet_selection_select_all_columns (selection);
2227 if (pspp_sheet_selection_path_is_selected (selection, path))
2228 pspp_sheet_selection_unselect_path (selection, path);
2230 pspp_sheet_selection_select_path (selection, path);
2231 update_anchor = TRUE;
2234 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
2235 && modifiers == GDK_SHIFT_MASK)
2237 GtkTreeRowReference *anchor = tree_view->priv->anchor;
2238 GtkTreePath *anchor_path;
2240 if (all_columns_selected (tree_view)
2241 && gtk_tree_row_reference_valid (anchor))
2243 update_anchor = FALSE;
2244 anchor_path = gtk_tree_row_reference_get_path (anchor);
2248 update_anchor = TRUE;
2249 anchor_path = gtk_tree_path_copy (path);
2252 pspp_sheet_selection_unselect_all (selection);
2253 pspp_sheet_selection_select_range (selection, anchor_path, path);
2254 pspp_sheet_selection_select_all_columns (selection);
2256 gtk_tree_path_free (anchor_path);
2261 update_anchor = handled = FALSE;
2265 if (tree_view->priv->anchor)
2266 gtk_tree_row_reference_free (tree_view->priv->anchor);
2267 tree_view->priv->anchor =
2268 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
2269 tree_view->priv->model,
2273 gtk_tree_path_free (path);
2278 find_click (PsppSheetView *tree_view,
2281 PsppSheetViewColumn **column,
2282 GdkRectangle *background_area,
2283 GdkRectangle *cell_area)
2290 /* find the node that was clicked */
2291 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, y);
2294 y_offset = -pspp_sheet_view_find_offset (tree_view, new_y, node);
2299 background_area->y = y_offset + y;
2300 background_area->height = ROW_HEIGHT (tree_view);
2301 background_area->x = 0;
2303 /* Let the column have a chance at selecting it. */
2304 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
2305 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
2306 list; list = (rtl ? list->prev : list->next))
2308 PsppSheetViewColumn *candidate = list->data;
2310 if (!candidate->visible)
2313 background_area->width = candidate->width;
2314 if ((background_area->x > x) ||
2315 (background_area->x + background_area->width <= x))
2317 background_area->x += background_area->width;
2321 /* we found the focus column */
2323 pspp_sheet_view_adjust_cell_area (tree_view, candidate, background_area,
2325 *column = candidate;
2333 pspp_sheet_view_button_press (GtkWidget *widget,
2334 GdkEventButton *event)
2336 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2338 PsppSheetViewColumn *column = NULL;
2340 GdkRectangle background_area;
2341 GdkRectangle cell_area;
2344 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
2345 pspp_sheet_view_stop_editing (tree_view, FALSE);
2348 /* Because grab_focus can cause reentrancy, we delay grab_focus until after
2349 * we're done handling the button press.
2352 if (event->window == tree_view->priv->bin_window)
2357 gint pre_val, aft_val;
2358 PsppSheetViewColumn *column = NULL;
2359 GtkCellRenderer *focus_cell = NULL;
2360 gboolean row_double_click = FALSE;
2363 if (tree_view->priv->row_count == 0)
2365 grab_focus_and_unset_draw_keyfocus (tree_view);
2369 if (!find_click (tree_view, event->x, event->y, &node, &column,
2370 &background_area, &cell_area))
2372 grab_focus_and_unset_draw_keyfocus (tree_view);
2376 tree_view->priv->focus_column = column;
2378 if (pspp_sheet_view_row_head_clicked (tree_view, node, column, event))
2382 pre_val = gtk_adjustment_get_value (tree_view->priv->vadjustment);
2384 path = _pspp_sheet_view_find_path (tree_view, node);
2386 /* we only handle selection modifications on the first button press
2388 if (event->type == GDK_BUTTON_PRESS)
2390 PsppSheetSelectionMode mode = 0;
2392 if ((event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
2393 mode |= PSPP_SHEET_SELECT_MODE_TOGGLE;
2394 if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
2395 mode |= PSPP_SHEET_SELECT_MODE_EXTEND;
2397 focus_cell = _pspp_sheet_view_column_get_cell_at_pos (column, event->x - background_area.x);
2399 pspp_sheet_view_column_focus_cell (column, focus_cell);
2401 if (event->state & GDK_CONTROL_MASK)
2403 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE, mode);
2404 pspp_sheet_view_real_toggle_cursor_row (tree_view);
2406 else if (event->state & GDK_SHIFT_MASK)
2408 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, mode);
2409 pspp_sheet_view_real_select_cursor_row (tree_view, FALSE, mode);
2413 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, 0);
2416 if (tree_view->priv->anchor_column == NULL ||
2417 !(event->state & GDK_SHIFT_MASK))
2418 tree_view->priv->anchor_column = column;
2419 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
2420 pspp_sheet_selection_select_column_range (tree_view->priv->selection,
2421 tree_view->priv->anchor_column,
2425 /* the treeview may have been scrolled because of _set_cursor,
2429 aft_val = gtk_adjustment_get_value (tree_view->priv->vadjustment);
2430 dval = pre_val - aft_val;
2432 cell_area.y += dval;
2433 background_area.y += dval;
2435 /* Save press to possibly begin a drag
2437 if (!tree_view->priv->in_grab &&
2438 tree_view->priv->pressed_button < 0)
2440 tree_view->priv->pressed_button = event->button;
2441 tree_view->priv->press_start_x = event->x;
2442 tree_view->priv->press_start_y = event->y;
2443 tree_view->priv->press_start_node = node;
2445 if (tree_view->priv->rubber_banding_enable
2446 && (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
2447 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE))
2449 tree_view->priv->press_start_y += tree_view->priv->dy;
2450 tree_view->priv->rubber_band_x = event->x;
2451 tree_view->priv->rubber_band_y = event->y + tree_view->priv->dy;
2452 tree_view->priv->rubber_band_status = RUBBER_BAND_MAYBE_START;
2454 if ((event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
2455 tree_view->priv->rubber_band_ctrl = TRUE;
2456 if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
2457 tree_view->priv->rubber_band_shift = TRUE;
2462 /* Test if a double click happened on the same row. */
2463 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
2465 int double_click_time, double_click_distance;
2467 g_object_get (gtk_settings_get_for_screen (
2468 gtk_widget_get_screen (widget)),
2469 "gtk-double-click-time", &double_click_time,
2470 "gtk-double-click-distance", &double_click_distance,
2473 /* Same conditions as _gdk_event_button_generate */
2474 if (tree_view->priv->last_button_x != -1 &&
2475 (event->time < tree_view->priv->last_button_time + double_click_time) &&
2476 (ABS (event->x - tree_view->priv->last_button_x) <= double_click_distance) &&
2477 (ABS (event->y - tree_view->priv->last_button_y) <= double_click_distance))
2479 /* We do no longer compare paths of this row and the
2480 * row clicked previously. We use the double click
2481 * distance to decide whether this is a valid click,
2482 * allowing the mouse to slightly move over another row.
2484 row_double_click = TRUE;
2486 tree_view->priv->last_button_time = 0;
2487 tree_view->priv->last_button_x = -1;
2488 tree_view->priv->last_button_y = -1;
2492 tree_view->priv->last_button_time = event->time;
2493 tree_view->priv->last_button_x = event->x;
2494 tree_view->priv->last_button_y = event->y;
2498 if (row_double_click)
2500 gtk_grab_remove (widget);
2501 pspp_sheet_view_row_activated (tree_view, path, column);
2503 if (tree_view->priv->pressed_button == event->button)
2504 tree_view->priv->pressed_button = -1;
2507 gtk_tree_path_free (path);
2509 /* If we activated the row through a double click we don't want to grab
2510 * focus back, as moving focus to another widget is pretty common.
2512 if (!row_double_click)
2513 grab_focus_and_unset_draw_keyfocus (tree_view);
2518 /* We didn't click in the window. Let's check to see if we clicked on a column resize window.
2520 for (i = 0, list = tree_view->priv->columns; list; list = list->next, i++)
2522 column = list->data;
2523 if (event->window == column->window &&
2524 column->resizable &&
2529 if (gdk_pointer_grab (column->window, FALSE,
2530 GDK_POINTER_MOTION_HINT_MASK |
2531 GDK_BUTTON1_MOTION_MASK |
2532 GDK_BUTTON_RELEASE_MASK,
2533 NULL, NULL, event->time))
2536 gtk_grab_add (widget);
2537 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE);
2538 column->resized_width = column->width;
2540 /* block attached dnd signal handler */
2541 drag_data = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
2543 g_signal_handlers_block_matched (widget,
2544 G_SIGNAL_MATCH_DATA,
2548 tree_view->priv->drag_pos = i;
2549 tree_view->priv->x_drag = column->allocation.x + (rtl ? 0 : column->allocation.width);
2551 if (!gtk_widget_has_focus (widget))
2552 gtk_widget_grab_focus (widget);
2560 /* GtkWidget::button_release_event helper */
2562 pspp_sheet_view_button_release_drag_column (GtkWidget *widget,
2563 GdkEventButton *event)
2565 PsppSheetView *tree_view;
2569 tree_view = PSPP_SHEET_VIEW (widget);
2571 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
2572 gdk_display_pointer_ungrab (gtk_widget_get_display (widget), GDK_CURRENT_TIME);
2573 gdk_display_keyboard_ungrab (gtk_widget_get_display (widget), GDK_CURRENT_TIME);
2575 /* Move the button back */
2576 g_return_val_if_fail (tree_view->priv->drag_column->button, FALSE);
2578 g_object_ref (tree_view->priv->drag_column->button);
2579 gtk_container_remove (GTK_CONTAINER (tree_view), tree_view->priv->drag_column->button);
2580 gtk_widget_set_parent_window (tree_view->priv->drag_column->button, tree_view->priv->header_window);
2581 gtk_widget_set_parent (tree_view->priv->drag_column->button, GTK_WIDGET (tree_view));
2582 g_object_unref (tree_view->priv->drag_column->button);
2583 gtk_widget_queue_resize (widget);
2584 if (tree_view->priv->drag_column->resizable)
2586 gdk_window_raise (tree_view->priv->drag_column->window);
2587 gdk_window_show (tree_view->priv->drag_column->window);
2590 gdk_window_hide (tree_view->priv->drag_column->window);
2592 gtk_widget_grab_focus (tree_view->priv->drag_column->button);
2596 if (tree_view->priv->cur_reorder &&
2597 tree_view->priv->cur_reorder->right_column != tree_view->priv->drag_column)
2598 pspp_sheet_view_move_column_after (tree_view, tree_view->priv->drag_column,
2599 tree_view->priv->cur_reorder->right_column);
2603 if (tree_view->priv->cur_reorder &&
2604 tree_view->priv->cur_reorder->left_column != tree_view->priv->drag_column)
2605 pspp_sheet_view_move_column_after (tree_view, tree_view->priv->drag_column,
2606 tree_view->priv->cur_reorder->left_column);
2608 tree_view->priv->drag_column = NULL;
2609 gdk_window_hide (tree_view->priv->drag_window);
2611 for (l = tree_view->priv->column_drag_info; l != NULL; l = l->next)
2612 g_slice_free (PsppSheetViewColumnReorder, l->data);
2613 g_list_free (tree_view->priv->column_drag_info);
2614 tree_view->priv->column_drag_info = NULL;
2615 tree_view->priv->cur_reorder = NULL;
2617 if (tree_view->priv->drag_highlight_window)
2618 gdk_window_hide (tree_view->priv->drag_highlight_window);
2620 /* Reset our flags */
2621 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_UNSET;
2622 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG);
2627 /* GtkWidget::button_release_event helper */
2629 pspp_sheet_view_button_release_column_resize (GtkWidget *widget,
2630 GdkEventButton *event)
2632 PsppSheetView *tree_view;
2635 tree_view = PSPP_SHEET_VIEW (widget);
2637 tree_view->priv->drag_pos = -1;
2639 /* unblock attached dnd signal handler */
2640 drag_data = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
2642 g_signal_handlers_unblock_matched (widget,
2643 G_SIGNAL_MATCH_DATA,
2647 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE);
2648 gtk_grab_remove (widget);
2649 gdk_display_pointer_ungrab (gdk_window_get_display (event->window),
2655 pspp_sheet_view_button_release_edit (PsppSheetView *tree_view,
2656 GdkEventButton *event)
2658 GtkCellEditable *cell_editable;
2663 PsppSheetViewColumn *column;
2664 GdkRectangle background_area;
2665 GdkRectangle cell_area;
2671 if (event->window != tree_view->priv->bin_window)
2674 /* Ignore a released button, if that button wasn't depressed */
2675 if (tree_view->priv->pressed_button != event->button)
2678 if (!find_click (tree_view, event->x, event->y, &node, &column, &background_area,
2682 /* decide if we edit */
2683 path = _pspp_sheet_view_find_path (tree_view, node);
2684 modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
2685 if (event->button != 1 || modifiers)
2688 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
2689 pspp_sheet_view_column_cell_set_cell_data (column,
2690 tree_view->priv->model,
2693 if (!pspp_sheet_view_column_get_quick_edit (column)
2694 && _pspp_sheet_view_column_has_editable_cell (column))
2697 flags = 0; /* FIXME: get the right flags */
2698 path_string = gtk_tree_path_to_string (path);
2700 if (!_pspp_sheet_view_column_cell_event (column,
2708 if (cell_editable == NULL)
2711 pspp_sheet_view_real_set_cursor (tree_view, path,
2712 TRUE, TRUE, 0); /* XXX mode? */
2713 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
2716 _pspp_sheet_view_column_get_neighbor_sizes (
2717 column, _pspp_sheet_view_column_get_edited_cell (column), &left, &right);
2720 area.width -= right + left;
2722 pspp_sheet_view_real_start_editing (tree_view,
2729 g_free (path_string);
2730 gtk_tree_path_free (path);
2735 pspp_sheet_view_button_release (GtkWidget *widget,
2736 GdkEventButton *event)
2738 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2740 pspp_sheet_view_stop_editing (tree_view, FALSE);
2741 if (tree_view->priv->rubber_band_status != RUBBER_BAND_ACTIVE
2742 && pspp_sheet_view_button_release_edit (tree_view, event))
2744 if (tree_view->priv->pressed_button == event->button)
2745 tree_view->priv->pressed_button = -1;
2747 tree_view->priv->rubber_band_status = RUBBER_BAND_OFF;
2751 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
2752 return pspp_sheet_view_button_release_drag_column (widget, event);
2754 if (tree_view->priv->rubber_band_status)
2755 pspp_sheet_view_stop_rubber_band (tree_view);
2757 if (tree_view->priv->pressed_button == event->button)
2758 tree_view->priv->pressed_button = -1;
2760 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
2761 return pspp_sheet_view_button_release_column_resize (widget, event);
2767 pspp_sheet_view_grab_broken (GtkWidget *widget,
2768 GdkEventGrabBroken *event)
2770 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2772 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
2773 pspp_sheet_view_button_release_drag_column (widget, (GdkEventButton *)event);
2775 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
2776 pspp_sheet_view_button_release_column_resize (widget, (GdkEventButton *)event);
2781 /* GtkWidget::motion_event function set.
2785 do_prelight (PsppSheetView *tree_view,
2787 /* these are in bin_window coords */
2791 int prev_node = tree_view->priv->prelight_node;
2793 if (prev_node != node)
2795 tree_view->priv->prelight_node = node;
2798 _pspp_sheet_view_queue_draw_node (tree_view, prev_node, NULL);
2801 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
2807 prelight_or_select (PsppSheetView *tree_view,
2809 /* these are in bin_window coords */
2813 PsppSheetSelectionMode mode = pspp_sheet_selection_get_mode (tree_view->priv->selection);
2815 if (tree_view->priv->hover_selection &&
2816 (mode == PSPP_SHEET_SELECTION_SINGLE || mode == PSPP_SHEET_SELECTION_BROWSE) &&
2817 !(tree_view->priv->edited_column &&
2818 tree_view->priv->edited_column->editable_widget))
2822 if (!pspp_sheet_view_node_is_selected (tree_view, node))
2826 path = _pspp_sheet_view_find_path (tree_view, node);
2827 pspp_sheet_selection_select_path (tree_view->priv->selection, path);
2828 if (pspp_sheet_view_node_is_selected (tree_view, node))
2830 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
2831 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, FALSE, 0); /* XXX mode? */
2833 gtk_tree_path_free (path);
2837 else if (mode == PSPP_SHEET_SELECTION_SINGLE)
2838 pspp_sheet_selection_unselect_all (tree_view->priv->selection);
2841 do_prelight (tree_view, node, x, y);
2845 ensure_unprelighted (PsppSheetView *tree_view)
2847 do_prelight (tree_view,
2849 -1000, -1000); /* coords not possibly over an arrow */
2851 g_assert (tree_view->priv->prelight_node < 0);
2855 update_prelight (PsppSheetView *tree_view,
2862 if (tree_view->priv->row_count == 0)
2867 ensure_unprelighted (tree_view);
2871 new_y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, y);
2875 pspp_sheet_view_find_offset (tree_view, new_y, &node);
2878 prelight_or_select (tree_view, node, x, y);
2884 /* Our motion arrow is either a box (in the case of the original spot)
2885 * or an arrow. It is expander_size wide.
2908 pspp_sheet_view_motion_draw_column_motion_arrow (PsppSheetView *tree_view)
2911 PsppSheetViewColumnReorder *reorder = tree_view->priv->cur_reorder;
2912 GtkWidget *widget = GTK_WIDGET (tree_view);
2913 GdkBitmap *mask = NULL;
2918 gint arrow_type = DRAG_COLUMN_WINDOW_STATE_UNSET;
2919 GdkWindowAttr attributes;
2920 guint attributes_mask;
2923 reorder->left_column == tree_view->priv->drag_column ||
2924 reorder->right_column == tree_view->priv->drag_column)
2925 arrow_type = DRAG_COLUMN_WINDOW_STATE_ORIGINAL;
2926 else if (reorder->left_column || reorder->right_column)
2928 GdkRectangle visible_rect;
2929 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
2930 if (reorder->left_column)
2931 x = reorder->left_column->allocation.x + reorder->left_column->allocation.width;
2933 x = reorder->right_column->allocation.x;
2935 if (x < visible_rect.x)
2936 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT;
2937 else if (x > visible_rect.x + visible_rect.width)
2938 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT;
2940 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW;
2943 /* We want to draw the rectangle over the initial location. */
2944 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ORIGINAL)
2949 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ORIGINAL)
2951 if (tree_view->priv->drag_highlight_window)
2953 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
2955 gdk_window_destroy (tree_view->priv->drag_highlight_window);
2958 attributes.window_type = GDK_WINDOW_CHILD;
2959 attributes.wclass = GDK_INPUT_OUTPUT;
2960 attributes.x = tree_view->priv->drag_column_x;
2962 width = attributes.width = tree_view->priv->drag_column->allocation.width;
2963 height = attributes.height = tree_view->priv->drag_column->allocation.height;
2964 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
2965 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
2966 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
2967 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2968 tree_view->priv->drag_highlight_window = gdk_window_new (tree_view->priv->header_window, &attributes, attributes_mask);
2969 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
2971 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
2972 gc = gdk_gc_new (mask);
2974 gdk_gc_set_foreground (gc, &col);
2975 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
2977 gdk_gc_set_foreground(gc, &col);
2978 gdk_draw_rectangle (mask, gc, TRUE, 2, 2, width - 4, height - 4);
2979 g_object_unref (gc);
2981 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
2983 if (mask) g_object_unref (mask);
2984 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_ORIGINAL;
2987 else if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW)
2993 width = tree_view->priv->expander_size;
2995 /* Get x, y, width, height of arrow */
2996 gdk_window_get_origin (tree_view->priv->header_window, &x, &y);
2997 if (reorder->left_column)
2999 x += reorder->left_column->allocation.x + reorder->left_column->allocation.width - width/2;
3000 height = reorder->left_column->allocation.height;
3004 x += reorder->right_column->allocation.x - width/2;
3005 height = reorder->right_column->allocation.height;
3007 y -= tree_view->priv->expander_size/2; /* The arrow takes up only half the space */
3008 height += tree_view->priv->expander_size;
3010 /* Create the new window */
3011 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW)
3013 if (tree_view->priv->drag_highlight_window)
3015 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
3017 gdk_window_destroy (tree_view->priv->drag_highlight_window);
3020 attributes.window_type = GDK_WINDOW_TEMP;
3021 attributes.wclass = GDK_INPUT_OUTPUT;
3022 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
3023 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
3024 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
3025 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
3028 attributes.width = width;
3029 attributes.height = height;
3030 tree_view->priv->drag_highlight_window = gdk_window_new (gtk_widget_get_root_window (widget),
3031 &attributes, attributes_mask);
3032 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
3034 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
3035 gc = gdk_gc_new (mask);
3037 gdk_gc_set_foreground (gc, &col);
3038 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
3040 /* Draw the 2 arrows as per above */
3042 gdk_gc_set_foreground (gc, &col);
3043 for (i = 0; i < width; i ++)
3045 if (i == (width/2 - 1))
3047 gdk_draw_line (mask, gc, i, j, i, height - j);
3048 if (i < (width/2 - 1))
3053 g_object_unref (gc);
3054 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
3056 if (mask) g_object_unref (mask);
3059 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_ARROW;
3060 gdk_window_move (tree_view->priv->drag_highlight_window, x, y);
3062 else if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT ||
3063 arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3069 width = tree_view->priv->expander_size;
3071 /* Get x, y, width, height of arrow */
3072 width = width/2; /* remember, the arrow only takes half the available width */
3073 gdk_window_get_origin (gtk_widget_get_window (widget), &x, &y);
3074 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3075 x += widget->allocation.width - width;
3077 if (reorder->left_column)
3078 height = reorder->left_column->allocation.height;
3080 height = reorder->right_column->allocation.height;
3082 y -= tree_view->priv->expander_size;
3083 height += 2*tree_view->priv->expander_size;
3085 /* Create the new window */
3086 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT &&
3087 tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3089 if (tree_view->priv->drag_highlight_window)
3091 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
3093 gdk_window_destroy (tree_view->priv->drag_highlight_window);
3096 attributes.window_type = GDK_WINDOW_TEMP;
3097 attributes.wclass = GDK_INPUT_OUTPUT;
3098 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
3099 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
3100 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
3101 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
3104 attributes.width = width;
3105 attributes.height = height;
3106 tree_view->priv->drag_highlight_window = gdk_window_new (NULL, &attributes, attributes_mask);
3107 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
3109 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
3110 gc = gdk_gc_new (mask);
3112 gdk_gc_set_foreground (gc, &col);
3113 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
3115 /* Draw the 2 arrows as per above */
3117 gdk_gc_set_foreground (gc, &col);
3118 j = tree_view->priv->expander_size;
3119 for (i = 0; i < width; i ++)
3122 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT)
3126 gdk_draw_line (mask, gc, k, j, k, height - j);
3127 gdk_draw_line (mask, gc, k, 0, k, tree_view->priv->expander_size - j);
3128 gdk_draw_line (mask, gc, k, height, k, height - tree_view->priv->expander_size + j);
3131 g_object_unref (gc);
3132 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
3134 if (mask) g_object_unref (mask);
3137 tree_view->priv->drag_column_window_state = arrow_type;
3138 gdk_window_move (tree_view->priv->drag_highlight_window, x, y);
3142 g_warning (G_STRLOC"Invalid PsppSheetViewColumnReorder struct");
3143 gdk_window_hide (tree_view->priv->drag_highlight_window);
3147 gdk_window_show (tree_view->priv->drag_highlight_window);
3148 gdk_window_raise (tree_view->priv->drag_highlight_window);
3153 pspp_sheet_view_motion_resize_column (GtkWidget *widget,
3154 GdkEventMotion *event)
3158 PsppSheetViewColumn *column;
3159 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
3161 column = pspp_sheet_view_get_column (tree_view, tree_view->priv->drag_pos);
3163 if (event->is_hint || event->window != gtk_widget_get_window (widget))
3164 gtk_widget_get_pointer (widget, &x, NULL);
3168 if (tree_view->priv->hadjustment)
3169 x += gtk_adjustment_get_value (tree_view->priv->hadjustment);
3171 new_width = pspp_sheet_view_new_column_width (tree_view,
3172 tree_view->priv->drag_pos, &x);
3173 if (x != tree_view->priv->x_drag &&
3174 (new_width != column->fixed_width))
3176 column->use_resized_width = TRUE;
3177 column->resized_width = new_width;
3180 column->resized_width -= tree_view->priv->last_extra_space_per_column;
3182 gtk_widget_queue_resize (widget);
3190 pspp_sheet_view_update_current_reorder (PsppSheetView *tree_view)
3192 PsppSheetViewColumnReorder *reorder = NULL;
3196 gdk_window_get_pointer (tree_view->priv->header_window, &mouse_x, NULL, NULL);
3197 for (list = tree_view->priv->column_drag_info; list; list = list->next)
3199 reorder = (PsppSheetViewColumnReorder *) list->data;
3200 if (mouse_x >= reorder->left_align && mouse_x < reorder->right_align)
3205 /* if (reorder && reorder == tree_view->priv->cur_reorder)
3208 tree_view->priv->cur_reorder = reorder;
3209 pspp_sheet_view_motion_draw_column_motion_arrow (tree_view);
3213 pspp_sheet_view_vertical_autoscroll (PsppSheetView *tree_view)
3215 GdkRectangle visible_rect;
3220 gdk_window_get_pointer (tree_view->priv->bin_window, NULL, &y, NULL);
3221 y += tree_view->priv->dy;
3223 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
3225 /* see if we are near the edge. */
3226 offset = y - (visible_rect.y + 2 * SCROLL_EDGE_SIZE);
3229 offset = y - (visible_rect.y + visible_rect.height - 2 * SCROLL_EDGE_SIZE);
3234 value = CLAMP (gtk_adjustment_get_value (tree_view->priv->vadjustment) + offset, 0.0,
3235 gtk_adjustment_get_upper (tree_view->priv->vadjustment) - gtk_adjustment_get_page_size (tree_view->priv->vadjustment));
3236 gtk_adjustment_set_value (tree_view->priv->vadjustment, value);
3240 pspp_sheet_view_horizontal_autoscroll (PsppSheetView *tree_view)
3242 GdkRectangle visible_rect;
3247 gdk_window_get_pointer (tree_view->priv->bin_window, &x, NULL, NULL);
3249 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
3251 /* See if we are near the edge. */
3252 offset = x - (visible_rect.x + SCROLL_EDGE_SIZE);
3255 offset = x - (visible_rect.x + visible_rect.width - SCROLL_EDGE_SIZE);
3261 value = CLAMP (gtk_adjustment_get_value (tree_view->priv->hadjustment) + offset,
3262 0.0, gtk_adjustment_get_upper (tree_view->priv->hadjustment) - gtk_adjustment_get_page_size (tree_view->priv->hadjustment));
3263 gtk_adjustment_set_value (tree_view->priv->hadjustment, value);
3270 pspp_sheet_view_motion_drag_column (GtkWidget *widget,
3271 GdkEventMotion *event)
3273 PsppSheetView *tree_view = (PsppSheetView *) widget;
3274 PsppSheetViewColumn *column = tree_view->priv->drag_column;
3276 GtkAllocation allocation;
3279 if ((column == NULL) ||
3280 (event->window != tree_view->priv->drag_window))
3283 /* Handle moving the header */
3284 gdk_window_get_position (tree_view->priv->drag_window, &x, &y);
3285 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
3286 x = CLAMP (x + (gint)event->x - column->drag_x, 0,
3287 MAX (tree_view->priv->width, allocation.width) - column->allocation.width);
3288 gdk_window_move (tree_view->priv->drag_window, x, y);
3290 /* autoscroll, if needed */
3291 pspp_sheet_view_horizontal_autoscroll (tree_view);
3292 /* Update the current reorder position and arrow; */
3293 pspp_sheet_view_update_current_reorder (tree_view);
3299 pspp_sheet_view_stop_rubber_band (PsppSheetView *tree_view)
3301 remove_scroll_timeout (tree_view);
3302 gtk_grab_remove (GTK_WIDGET (tree_view));
3304 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
3306 GtkTreePath *tmp_path;
3308 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
3310 /* The anchor path should be set to the start path */
3311 tmp_path = _pspp_sheet_view_find_path (tree_view,
3312 tree_view->priv->rubber_band_start_node);
3314 if (tree_view->priv->anchor)
3315 gtk_tree_row_reference_free (tree_view->priv->anchor);
3317 tree_view->priv->anchor =
3318 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
3319 tree_view->priv->model,
3322 gtk_tree_path_free (tmp_path);
3324 /* ... and the cursor to the end path */
3325 tmp_path = _pspp_sheet_view_find_path (tree_view,
3326 tree_view->priv->rubber_band_end_node);
3327 pspp_sheet_view_real_set_cursor (PSPP_SHEET_VIEW (tree_view), tmp_path, FALSE, FALSE, 0); /* XXX mode? */
3328 gtk_tree_path_free (tmp_path);
3330 _pspp_sheet_selection_emit_changed (tree_view->priv->selection);
3333 /* Clear status variables */
3334 tree_view->priv->rubber_band_status = RUBBER_BAND_OFF;
3335 tree_view->priv->rubber_band_shift = 0;
3336 tree_view->priv->rubber_band_ctrl = 0;
3338 tree_view->priv->rubber_band_start_node = -1;
3339 tree_view->priv->rubber_band_end_node = -1;
3343 pspp_sheet_view_update_rubber_band_selection_range (PsppSheetView *tree_view,
3347 gboolean skip_start,
3350 if (start_node == end_node)
3353 /* We skip the first node and jump inside the loop */
3359 /* Small optimization by assuming insensitive nodes are never
3364 if (tree_view->priv->rubber_band_shift)
3365 pspp_sheet_view_node_select (tree_view, start_node);
3366 else if (tree_view->priv->rubber_band_ctrl)
3368 /* Toggle the selection state */
3369 if (pspp_sheet_view_node_is_selected (tree_view, start_node))
3370 pspp_sheet_view_node_unselect (tree_view, start_node);
3372 pspp_sheet_view_node_select (tree_view, start_node);
3375 pspp_sheet_view_node_select (tree_view, start_node);
3379 /* Mirror the above */
3380 if (tree_view->priv->rubber_band_shift)
3381 pspp_sheet_view_node_unselect (tree_view, start_node);
3382 else if (tree_view->priv->rubber_band_ctrl)
3384 /* Toggle the selection state */
3385 if (pspp_sheet_view_node_is_selected (tree_view, start_node))
3386 pspp_sheet_view_node_unselect (tree_view, start_node);
3388 pspp_sheet_view_node_select (tree_view, start_node);
3391 pspp_sheet_view_node_unselect (tree_view, start_node);
3394 _pspp_sheet_view_queue_draw_node (tree_view, start_node, NULL);
3396 if (start_node == end_node)
3401 start_node = pspp_sheet_view_node_next (tree_view, start_node);
3404 /* Ran out of tree */
3407 if (skip_end && start_node == end_node)
3414 pspp_sheet_view_node_find_offset (PsppSheetView *tree_view,
3417 return node * tree_view->priv->fixed_height;
3421 pspp_sheet_view_find_offset (PsppSheetView *tree_view,
3425 int fixed_height = tree_view->priv->fixed_height;
3426 if (fixed_height <= 0
3428 || height >= tree_view->priv->row_count * fixed_height)
3435 *new_node = height / fixed_height;
3436 return height % fixed_height;
3441 pspp_sheet_view_update_rubber_band_selection (PsppSheetView *tree_view)
3446 pspp_sheet_view_find_offset (tree_view, MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y), &start_node);
3447 pspp_sheet_view_find_offset (tree_view, MAX (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y), &end_node);
3449 /* Handle the start area first */
3450 if (tree_view->priv->rubber_band_start_node < 0)
3452 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3459 else if (start_node < tree_view->priv->rubber_band_start_node)
3461 /* New node is above the old one; selection became bigger */
3462 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3464 tree_view->priv->rubber_band_start_node,
3469 else if (start_node > tree_view->priv->rubber_band_start_node)
3471 /* New node is below the old one; selection became smaller */
3472 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3473 tree_view->priv->rubber_band_start_node,
3480 tree_view->priv->rubber_band_start_node = start_node;
3482 /* Next, handle the end area */
3483 if (tree_view->priv->rubber_band_end_node < 0)
3485 /* In the event this happens, start_node was also -1; this case is
3489 else if (end_node < 0)
3491 /* Find the last node in the tree */
3492 pspp_sheet_view_find_offset (tree_view, tree_view->priv->height - 1,
3495 /* Selection reached end of the tree */
3496 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3497 tree_view->priv->rubber_band_end_node,
3503 else if (end_node > tree_view->priv->rubber_band_end_node)
3505 /* New node is below the old one; selection became bigger */
3506 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3507 tree_view->priv->rubber_band_end_node,
3513 else if (end_node < tree_view->priv->rubber_band_end_node)
3515 /* New node is above the old one; selection became smaller */
3516 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3518 tree_view->priv->rubber_band_end_node,
3524 tree_view->priv->rubber_band_end_node = end_node;
3527 #define GDK_RECTANGLE_PTR(X) ((GdkRectangle *)(X))
3530 pspp_sheet_view_update_rubber_band (PsppSheetView *tree_view)
3533 cairo_rectangle_int_t old_area;
3534 cairo_rectangle_int_t new_area;
3535 cairo_rectangle_int_t common;
3536 cairo_region_t *invalid_region;
3537 PsppSheetViewColumn *column;
3539 old_area.x = MIN (tree_view->priv->press_start_x, tree_view->priv->rubber_band_x);
3540 old_area.y = MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y) - tree_view->priv->dy;
3541 old_area.width = ABS (tree_view->priv->rubber_band_x - tree_view->priv->press_start_x) + 1;
3542 old_area.height = ABS (tree_view->priv->rubber_band_y - tree_view->priv->press_start_y) + 1;
3544 gdk_window_get_pointer (tree_view->priv->bin_window, &x, &y, NULL);
3547 y = MAX (y, 0) + tree_view->priv->dy;
3549 new_area.x = MIN (tree_view->priv->press_start_x, x);
3550 new_area.y = MIN (tree_view->priv->press_start_y, y) - tree_view->priv->dy;
3551 new_area.width = ABS (x - tree_view->priv->press_start_x) + 1;
3552 new_area.height = ABS (y - tree_view->priv->press_start_y) + 1;
3554 invalid_region = cairo_region_create_rectangle (&old_area);
3555 cairo_region_union_rectangle (invalid_region, &new_area);
3557 gdk_rectangle_intersect (GDK_RECTANGLE_PTR (&old_area),
3558 GDK_RECTANGLE_PTR (&new_area), GDK_RECTANGLE_PTR (&common));
3559 if (common.width > 2 && common.height > 2)
3561 cairo_region_t *common_region;
3563 /* make sure the border is invalidated */
3569 common_region = cairo_region_create_rectangle (&common);
3571 cairo_region_subtract (invalid_region, common_region);
3572 cairo_region_destroy (common_region);
3575 #if GTK_MAJOR_VERSION == 3
3576 gdk_window_invalidate_region (tree_view->priv->bin_window, invalid_region, TRUE);
3579 cairo_rectangle_int_t extents;
3581 cairo_region_get_extents (invalid_region, &extents);
3582 ereg = gdk_region_rectangle (GDK_RECTANGLE_PTR (&extents));
3583 gdk_window_invalidate_region (tree_view->priv->bin_window, ereg, TRUE);
3584 gdk_region_destroy (ereg);
3588 cairo_region_destroy (invalid_region);
3590 tree_view->priv->rubber_band_x = x;
3591 tree_view->priv->rubber_band_y = y;
3592 pspp_sheet_view_get_path_at_pos (tree_view, x, y, NULL, &column, NULL, NULL);
3594 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
3595 pspp_sheet_selection_select_column_range (tree_view->priv->selection,
3596 tree_view->priv->anchor_column,
3599 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
3601 pspp_sheet_view_update_rubber_band_selection (tree_view);
3606 pspp_sheet_view_paint_rubber_band (PsppSheetView *tree_view,
3611 GdkRectangle rubber_rect;
3615 rubber_rect.x = MIN (tree_view->priv->press_start_x, tree_view->priv->rubber_band_x);
3616 rubber_rect.y = MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y) - tree_view->priv->dy;
3617 rubber_rect.width = ABS (tree_view->priv->press_start_x - tree_view->priv->rubber_band_x) + 1;
3618 rubber_rect.height = ABS (tree_view->priv->press_start_y - tree_view->priv->rubber_band_y) + 1;
3620 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
3623 cr = gdk_cairo_create (tree_view->priv->bin_window);
3624 cairo_set_line_width (cr, 1.0);
3626 style = gtk_widget_get_style (GTK_WIDGET (tree_view));
3627 cairo_set_source_rgba (cr,
3628 style->fg[GTK_STATE_NORMAL].red / 65535.,
3629 style->fg[GTK_STATE_NORMAL].green / 65535.,
3630 style->fg[GTK_STATE_NORMAL].blue / 65535.,
3633 gdk_cairo_rectangle (cr, &rect);
3637 cairo_set_source_rgb (cr,
3638 style->fg[GTK_STATE_NORMAL].red / 65535.,
3639 style->fg[GTK_STATE_NORMAL].green / 65535.,
3640 style->fg[GTK_STATE_NORMAL].blue / 65535.);
3642 cairo_rectangle (cr,
3643 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
3644 rubber_rect.width - 1, rubber_rect.height - 1);
3653 pspp_sheet_view_motion_bin_window (GtkWidget *widget,
3654 GdkEventMotion *event)
3656 PsppSheetView *tree_view;
3660 tree_view = (PsppSheetView *) widget;
3662 if (tree_view->priv->row_count == 0)
3665 if (tree_view->priv->rubber_band_status == RUBBER_BAND_MAYBE_START)
3667 GdkRectangle background_area, cell_area;
3668 PsppSheetViewColumn *column;
3670 if (find_click (tree_view, event->x, event->y, &node, &column,
3671 &background_area, &cell_area)
3672 && tree_view->priv->focus_column == column
3673 && tree_view->priv->press_start_node == node)
3676 gtk_grab_add (GTK_WIDGET (tree_view));
3677 pspp_sheet_view_update_rubber_band (tree_view);
3679 tree_view->priv->rubber_band_status = RUBBER_BAND_ACTIVE;
3681 else if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
3683 pspp_sheet_view_update_rubber_band (tree_view);
3685 add_scroll_timeout (tree_view);
3688 /* only check for an initiated drag when a button is pressed */
3689 if (tree_view->priv->pressed_button >= 0
3690 && !tree_view->priv->rubber_band_status)
3691 pspp_sheet_view_maybe_begin_dragging_row (tree_view, event);
3693 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, event->y);
3697 pspp_sheet_view_find_offset (tree_view, new_y, &node);
3699 tree_view->priv->event_last_x = event->x;
3700 tree_view->priv->event_last_y = event->y;
3702 prelight_or_select (tree_view, node, event->x, event->y);
3708 pspp_sheet_view_motion (GtkWidget *widget,
3709 GdkEventMotion *event)
3711 PsppSheetView *tree_view;
3713 tree_view = (PsppSheetView *) widget;
3715 /* Resizing a column */
3716 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
3717 return pspp_sheet_view_motion_resize_column (widget, event);
3720 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
3721 return pspp_sheet_view_motion_drag_column (widget, event);
3723 /* Sanity check it */
3724 if (event->window == tree_view->priv->bin_window)
3725 return pspp_sheet_view_motion_bin_window (widget, event);
3730 /* Invalidate the focus rectangle near the edge of the bin_window; used when
3731 * the tree is empty.
3734 invalidate_empty_focus (PsppSheetView *tree_view)
3738 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
3743 area.width = gdk_window_get_width (tree_view->priv->bin_window);
3744 area.height = gdk_window_get_height (tree_view->priv->bin_window);
3745 gdk_window_invalidate_rect (tree_view->priv->bin_window, &area, FALSE);
3748 /* Draws a focus rectangle near the edge of the bin_window; used when the tree
3752 draw_empty_focus (PsppSheetView *tree_view, GdkRectangle *clip_area)
3754 GtkWidget *widget = GTK_WIDGET (tree_view);
3757 if (!gtk_widget_has_focus (widget))
3760 w = gdk_window_get_width (tree_view->priv->bin_window);
3761 h = gdk_window_get_height (tree_view->priv->bin_window);
3767 gtk_paint_focus (gtk_widget_get_style (widget),
3768 tree_view->priv->bin_window,
3769 gtk_widget_get_state (widget),
3777 pspp_sheet_view_draw_vertical_grid_lines (PsppSheetView *tree_view,
3778 GdkEventExpose *event,
3779 gint n_visible_columns,
3783 GList *list = tree_view->priv->columns;
3787 if (tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
3788 && tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_BOTH)
3791 /* Only draw the lines for visible rows and columns */
3792 for (list = tree_view->priv->columns; list; list = list->next, i++)
3794 PsppSheetViewColumn *column = list->data;
3796 /* We don't want a line for the last column */
3797 if (i == n_visible_columns - 1)
3800 if (! column->visible)
3803 current_x += column->width;
3805 if (current_x - 1 >= event->area.x
3806 && current_x - 1 < event->area.x + event->area.width)
3809 gdk_draw_line (event->window,
3810 tree_view->priv->grid_line_gc[GTK_WIDGET(tree_view)->state],
3811 current_x - 1, min_y,
3812 current_x - 1, max_y - min_y);
3815 cairo_t *cr = gdk_cairo_create (event->window);
3816 cairo_set_line_width (cr, 1.0);
3817 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
3818 cairo_move_to (cr, current_x - 0.5, min_y);
3819 cairo_line_to (cr, current_x - 0.5 , max_y - min_y);
3828 /* Warning: Very scary function.
3829 * Modify at your own risk
3831 * KEEP IN SYNC WITH pspp_sheet_view_create_row_drag_icon()!
3832 * FIXME: It's not...
3835 pspp_sheet_view_bin_expose (GtkWidget *widget,
3836 GdkEventExpose *event)
3838 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
3843 int drag_highlight = -1;
3846 gint y_offset, cell_offset;
3848 GdkRectangle background_area;
3849 GdkRectangle cell_area;
3851 gint bin_window_width;
3852 gint bin_window_height;
3853 GtkTreePath *cursor_path;
3854 GtkTreePath *drag_dest_path;
3855 GList *first_column, *last_column;
3856 gint vertical_separator;
3857 gint horizontal_separator;
3858 gint focus_line_width;
3859 gboolean allow_rules;
3860 gboolean has_special_cell;
3862 gint n_visible_columns;
3863 gint grid_line_width;
3864 gboolean row_ending_details;
3865 gboolean draw_vgrid_lines, draw_hgrid_lines;
3868 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
3870 gtk_widget_style_get (widget,
3871 "horizontal-separator", &horizontal_separator,
3872 "vertical-separator", &vertical_separator,
3873 "allow-rules", &allow_rules,
3874 "focus-line-width", &focus_line_width,
3875 "row-ending-details", &row_ending_details,
3878 if (tree_view->priv->row_count == 0)
3880 draw_empty_focus (tree_view, &event->area);
3884 /* clip event->area to the visible area */
3885 if (event->area.height < 0.5)
3888 validate_visible_area (tree_view);
3890 new_y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, event->area.y);
3894 y_offset = -pspp_sheet_view_find_offset (tree_view, new_y, &node);
3896 gdk_window_get_width (tree_view->priv->bin_window);
3899 gdk_window_get_height (tree_view->priv->bin_window);
3902 if (tree_view->priv->height < bin_window_height)
3904 gtk_paint_flat_box (gtk_widget_get_style (widget),
3906 gtk_widget_get_state (widget),
3911 0, tree_view->priv->height,
3913 bin_window_height - tree_view->priv->height);
3919 /* find the path for the node */
3920 path = _pspp_sheet_view_find_path ((PsppSheetView *)widget, node);
3921 gtk_tree_model_get_iter (tree_view->priv->model,
3924 gtk_tree_path_free (path);
3927 drag_dest_path = NULL;
3929 if (tree_view->priv->cursor)
3930 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
3933 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor);
3935 if (tree_view->priv->drag_dest_row)
3936 drag_dest_path = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
3939 _pspp_sheet_view_find_node (tree_view, drag_dest_path,
3943 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
3944 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
3946 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
3947 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
3949 if (draw_vgrid_lines || draw_hgrid_lines)
3950 gtk_widget_style_get (widget, "grid-line-width", &grid_line_width, NULL);
3952 n_visible_columns = 0;
3953 for (list = tree_view->priv->columns; list; list = list->next)
3955 if (! PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
3957 n_visible_columns ++;
3960 /* Find the last column */
3961 for (last_column = g_list_last (tree_view->priv->columns);
3962 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
3963 last_column = last_column->prev)
3967 for (first_column = g_list_first (tree_view->priv->columns);
3968 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
3969 first_column = first_column->next)
3972 /* Actually process the expose event. To do this, we want to
3973 * start at the first node of the event, and walk the tree in
3974 * order, drawing each successive node.
3981 gboolean is_first = FALSE;
3982 gboolean is_last = FALSE;
3983 gboolean done = FALSE;
3986 max_height = ROW_HEIGHT (tree_view);
3990 background_area.y = y_offset + event->area.y;
3991 background_area.height = max_height;
3992 max_y = background_area.y + max_height;
3996 if (node == tree_view->priv->prelight_node)
3997 flags |= GTK_CELL_RENDERER_PRELIT;
3999 selected = pspp_sheet_view_node_is_selected (tree_view, node);
4003 if (tree_view->priv->special_cells == PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT)
4005 /* we *need* to set cell data on all cells before the call
4006 * to _has_special_cell, else _has_special_cell() does not
4007 * return a correct value.
4009 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
4011 list = (rtl ? list->prev : list->next))
4013 PsppSheetViewColumn *column = list->data;
4014 pspp_sheet_view_column_cell_set_cell_data (column,
4015 tree_view->priv->model,
4019 has_special_cell = pspp_sheet_view_has_special_cell (tree_view);
4022 has_special_cell = tree_view->priv->special_cells == PSPP_SHEET_VIEW_SPECIAL_CELLS_YES;
4024 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
4026 list = (rtl ? list->prev : list->next))
4028 PsppSheetViewColumn *column = list->data;
4029 const gchar *detail = NULL;
4030 gboolean selected_column;
4033 if (!column->visible)
4036 if (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE)
4037 selected_column = column->selected && column->selectable;
4039 selected_column = TRUE;
4041 if (cell_offset > event->area.x + event->area.width ||
4042 cell_offset + column->width < event->area.x)
4044 cell_offset += column->width;
4048 if (selected && selected_column)
4049 flags |= GTK_CELL_RENDERER_SELECTED;
4051 flags &= ~GTK_CELL_RENDERER_SELECTED;
4053 if (column->show_sort_indicator)
4054 flags |= GTK_CELL_RENDERER_SORTED;
4056 flags &= ~GTK_CELL_RENDERER_SORTED;
4059 flags |= GTK_CELL_RENDERER_FOCUSED;
4061 flags &= ~GTK_CELL_RENDERER_FOCUSED;
4063 background_area.x = cell_offset;
4064 background_area.width = column->width;
4066 cell_area = background_area;
4067 cell_area.y += vertical_separator / 2;
4068 cell_area.x += horizontal_separator / 2;
4069 cell_area.height -= vertical_separator;
4070 cell_area.width -= horizontal_separator;
4072 if (draw_vgrid_lines)
4074 if (list == first_column)
4076 cell_area.width -= grid_line_width / 2;
4078 else if (list == last_column)
4080 cell_area.x += grid_line_width / 2;
4081 cell_area.width -= grid_line_width / 2;
4085 cell_area.x += grid_line_width / 2;
4086 cell_area.width -= grid_line_width;
4090 if (draw_hgrid_lines)
4092 cell_area.y += grid_line_width / 2;
4093 cell_area.height -= grid_line_width;
4097 if (gdk_region_rect_in (event->region, &background_area) == GDK_OVERLAP_RECTANGLE_OUT)
4099 cell_offset += column->width;
4104 pspp_sheet_view_column_cell_set_cell_data (column,
4105 tree_view->priv->model,
4108 /* Select the detail for drawing the cell. relevant
4109 * factors are parity, sortedness, and whether to
4112 if (allow_rules && tree_view->priv->has_rules)
4114 if ((flags & GTK_CELL_RENDERER_SORTED) &&
4115 n_visible_columns >= 3)
4118 detail = "cell_odd_ruled_sorted";
4120 detail = "cell_even_ruled_sorted";
4125 detail = "cell_odd_ruled";
4127 detail = "cell_even_ruled";
4132 if ((flags & GTK_CELL_RENDERER_SORTED) &&
4133 n_visible_columns >= 3)
4136 detail = "cell_odd_sorted";
4138 detail = "cell_even_sorted";
4143 detail = "cell_odd";
4145 detail = "cell_even";
4151 if (gtk_widget_get_state (widget) == GTK_STATE_INSENSITIVE)
4152 state = GTK_STATE_INSENSITIVE;
4153 else if (flags & GTK_CELL_RENDERER_SELECTED)
4154 state = GTK_STATE_SELECTED;
4156 state = GTK_STATE_NORMAL;
4158 /* Draw background */
4159 if (row_ending_details)
4161 char new_detail[128];
4163 is_first = (rtl ? !list->next : !list->prev);
4164 is_last = (rtl ? !list->prev : !list->next);
4166 /* (I don't like the snprintfs either, but couldn't find a
4169 if (is_first && is_last)
4170 g_snprintf (new_detail, 127, "%s", detail);
4172 g_snprintf (new_detail, 127, "%s_start", detail);
4174 g_snprintf (new_detail, 127, "%s_end", detail);
4176 g_snprintf (new_detail, 128, "%s_middle", detail);
4178 gtk_paint_flat_box (gtk_widget_get_style (widget),
4187 background_area.width,
4188 background_area.height);
4192 gtk_paint_flat_box (gtk_widget_get_style (widget),
4201 background_area.width,
4202 background_area.height);
4205 if (draw_hgrid_lines)
4207 cairo_t *cr = gdk_cairo_create (event->window);
4208 cairo_set_line_width (cr, 1.0);
4209 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
4211 if (background_area.y >= 0)
4214 gdk_draw_line (event->window,
4215 tree_view->priv->grid_line_gc[widget->state],
4216 background_area.x, background_area.y,
4217 background_area.x + background_area.width,
4220 cairo_move_to (cr, background_area.x, background_area.y - 0.5);
4221 cairo_line_to (cr, background_area.x + background_area.width,
4222 background_area.y - 0.5);
4226 if (y_offset + max_height >= event->area.height - 0.5)
4229 gdk_draw_line (event->window,
4230 tree_view->priv->grid_line_gc[widget->state],
4231 background_area.x, background_area.y + max_height,
4232 background_area.x + background_area.width,
4233 background_area.y + max_height);
4236 cairo_move_to (cr, background_area.x, background_area.y + max_height - 0.5);
4237 cairo_line_to (cr, background_area.x + background_area.width,
4238 background_area.y + max_height - 0.5);
4245 _pspp_sheet_view_column_cell_render (column,
4252 if (node == cursor && has_special_cell &&
4253 ((column == tree_view->priv->focus_column &&
4254 PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS) &&
4255 gtk_widget_has_focus (widget)) ||
4256 (column == tree_view->priv->edited_column)))
4258 _pspp_sheet_view_column_cell_draw_focus (column,
4266 cell_offset += column->width;
4269 if (cell_offset < event->area.x)
4271 gtk_paint_flat_box (gtk_widget_get_style (widget),
4280 event->area.x - cell_offset,
4281 background_area.height);
4284 if (node == drag_highlight)
4286 /* Draw indicator for the drop
4288 gint highlight_y = -1;
4292 switch (tree_view->priv->drag_dest_pos)
4294 case PSPP_SHEET_VIEW_DROP_BEFORE:
4295 highlight_y = background_area.y - 1;
4296 if (highlight_y < 0)
4300 case PSPP_SHEET_VIEW_DROP_AFTER:
4301 highlight_y = background_area.y + background_area.height - 1;
4304 case PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE:
4305 case PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER:
4306 _pspp_sheet_view_find_node (tree_view, drag_dest_path, &node);
4310 width = gdk_window_get_width (tree_view->priv->bin_window);
4312 if (row_ending_details)
4313 gtk_paint_focus (gtk_widget_get_style (widget),
4314 tree_view->priv->bin_window,
4315 gtk_widget_get_state (widget),
4319 ? (is_last ? "treeview-drop-indicator" : "treeview-drop-indicator-left" )
4320 : (is_last ? "treeview-drop-indicator-right" : "tree-view-drop-indicator-middle" )),
4321 0, BACKGROUND_FIRST_PIXEL (tree_view, node)
4322 - focus_line_width / 2,
4323 width, ROW_HEIGHT (tree_view)
4324 - focus_line_width + 1);
4326 gtk_paint_focus (gtk_widget_get_style (widget),
4327 tree_view->priv->bin_window,
4328 gtk_widget_get_state (widget),
4331 "treeview-drop-indicator",
4332 0, BACKGROUND_FIRST_PIXEL (tree_view, node)
4333 - focus_line_width / 2,
4334 width, ROW_HEIGHT (tree_view)
4335 - focus_line_width + 1);
4340 if (highlight_y >= 0)
4342 gdk_draw_line (event->window,
4343 widget->style->fg_gc[gtk_widget_get_state (widget)],
4346 rtl ? 0 : bin_window_width,
4352 /* draw the big row-spanning focus rectangle, if needed */
4353 if (!has_special_cell && node == cursor &&
4354 PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS) &&
4355 gtk_widget_has_focus (widget))
4357 gint tmp_y, tmp_height;
4359 GtkStateType focus_rect_state;
4362 flags & GTK_CELL_RENDERER_SELECTED ? GTK_STATE_SELECTED :
4363 (flags & GTK_CELL_RENDERER_PRELIT ? GTK_STATE_PRELIGHT :
4364 (flags & GTK_CELL_RENDERER_INSENSITIVE ? GTK_STATE_INSENSITIVE :
4367 width = gdk_window_get_width (tree_view->priv->bin_window);
4369 if (draw_hgrid_lines)
4371 tmp_y = BACKGROUND_FIRST_PIXEL (tree_view, node) + grid_line_width / 2;
4372 tmp_height = ROW_HEIGHT (tree_view) - grid_line_width;
4376 tmp_y = BACKGROUND_FIRST_PIXEL (tree_view, node);
4377 tmp_height = ROW_HEIGHT (tree_view);
4380 if (row_ending_details)
4381 gtk_paint_focus (gtk_widget_get_style (widget),
4382 tree_view->priv->bin_window,
4387 ? (is_last ? "treeview" : "treeview-left" )
4388 : (is_last ? "treeview-right" : "treeview-middle" )),
4392 gtk_paint_focus (gtk_widget_get_style (widget),
4393 tree_view->priv->bin_window,
4402 y_offset += max_height;
4406 node = pspp_sheet_view_node_next (tree_view, node);
4409 gboolean has_next = gtk_tree_model_iter_next (tree_view->priv->model, &iter);
4413 TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
4420 while (y_offset < event->area.height);
4423 pspp_sheet_view_draw_vertical_grid_lines (tree_view, event, n_visible_columns,
4427 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
4429 GdkRectangle *rectangles;
4432 gdk_region_get_rectangles (event->region,
4436 while (n_rectangles--)
4437 pspp_sheet_view_paint_rubber_band (tree_view, &rectangles[n_rectangles]);
4439 g_free (rectangles);
4444 gtk_tree_path_free (cursor_path);
4447 gtk_tree_path_free (drag_dest_path);
4453 pspp_sheet_view_expose (GtkWidget *widget,
4454 GdkEventExpose *event)
4456 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4458 if (event->window == tree_view->priv->bin_window)
4463 retval = pspp_sheet_view_bin_expose (widget, event);
4465 /* We can't just chain up to Container::expose as it will try to send the
4466 * event to the headers, so we handle propagating it to our children
4467 * (eg. widgets being edited) ourselves.
4469 tmp_list = tree_view->priv->children;
4472 PsppSheetViewChild *child = tmp_list->data;
4473 tmp_list = tmp_list->next;
4475 gtk_container_propagate_expose (GTK_CONTAINER (tree_view), child->widget, event);
4480 else if (event->window == tree_view->priv->header_window)
4482 gint n_visible_columns;
4485 gtk_paint_flat_box (gtk_widget_get_style (widget),
4495 event->area.height);
4497 for (list = tree_view->priv->columns; list != NULL; list = list->next)
4499 PsppSheetViewColumn *column = list->data;
4501 if (column == tree_view->priv->drag_column || !column->visible)
4504 if (span_intersects (column->allocation.x, column->allocation.width,
4505 event->area.x, event->area.width)
4506 && column->button != NULL)
4507 gtk_container_propagate_expose (GTK_CONTAINER (tree_view),
4508 column->button, event);
4511 n_visible_columns = 0;
4512 for (list = tree_view->priv->columns; list; list = list->next)
4514 if (! PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
4516 n_visible_columns ++;
4518 pspp_sheet_view_draw_vertical_grid_lines (tree_view,
4522 event->area.height);
4524 else if (event->window == tree_view->priv->drag_window)
4526 gtk_container_propagate_expose (GTK_CONTAINER (tree_view),
4527 tree_view->priv->drag_column->button,
4541 /* returns 0x1 when no column has been found -- yes it's hackish */
4542 static PsppSheetViewColumn *
4543 pspp_sheet_view_get_drop_column (PsppSheetView *tree_view,
4544 PsppSheetViewColumn *column,
4547 PsppSheetViewColumn *left_column = NULL;
4548 PsppSheetViewColumn *cur_column = NULL;
4551 if (!column->reorderable)
4552 return (PsppSheetViewColumn *)0x1;
4554 switch (drop_position)
4557 /* find first column where we can drop */
4558 tmp_list = tree_view->priv->columns;
4559 if (column == PSPP_SHEET_VIEW_COLUMN (tmp_list->data))
4560 return (PsppSheetViewColumn *)0x1;
4564 g_assert (tmp_list);
4566 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4567 tmp_list = tmp_list->next;
4569 if (left_column && left_column->visible == FALSE)
4572 if (!tree_view->priv->column_drop_func)
4575 if (!tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4577 left_column = cur_column;
4584 if (!tree_view->priv->column_drop_func)
4587 if (tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data))
4590 return (PsppSheetViewColumn *)0x1;
4594 /* find first column after column where we can drop */
4595 tmp_list = tree_view->priv->columns;
4597 for (; tmp_list; tmp_list = tmp_list->next)
4598 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data) == column)
4601 if (!tmp_list || !tmp_list->next)
4602 return (PsppSheetViewColumn *)0x1;
4604 tmp_list = tmp_list->next;
4605 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4606 tmp_list = tmp_list->next;
4610 g_assert (tmp_list);
4612 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4613 tmp_list = tmp_list->next;
4615 if (left_column && left_column->visible == FALSE)
4617 left_column = cur_column;
4619 tmp_list = tmp_list->next;
4623 if (!tree_view->priv->column_drop_func)
4626 if (!tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4628 left_column = cur_column;
4635 if (!tree_view->priv->column_drop_func)
4638 if (tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data))
4641 return (PsppSheetViewColumn *)0x1;
4645 /* find first column before column where we can drop */
4646 tmp_list = tree_view->priv->columns;
4648 for (; tmp_list; tmp_list = tmp_list->next)
4649 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data) == column)
4652 if (!tmp_list || !tmp_list->prev)
4653 return (PsppSheetViewColumn *)0x1;
4655 tmp_list = tmp_list->prev;
4656 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4657 tmp_list = tmp_list->prev;
4661 g_assert (tmp_list);
4663 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4665 if (left_column && !left_column->visible)
4667 /*if (!tmp_list->prev)
4668 return (PsppSheetViewColumn *)0x1;
4671 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->prev->data);
4672 tmp_list = tmp_list->prev->prev;
4675 cur_column = left_column;
4677 tmp_list = tmp_list->prev;
4681 if (!tree_view->priv->column_drop_func)
4684 if (tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4687 cur_column = left_column;
4688 tmp_list = tmp_list->prev;
4691 if (!tree_view->priv->column_drop_func)
4694 if (tree_view->priv->column_drop_func (tree_view, column, NULL, cur_column, tree_view->priv->column_drop_func_data))
4697 return (PsppSheetViewColumn *)0x1;
4701 /* same as DROP_HOME case, but doing it backwards */
4702 tmp_list = g_list_last (tree_view->priv->columns);
4705 if (column == PSPP_SHEET_VIEW_COLUMN (tmp_list->data))
4706 return (PsppSheetViewColumn *)0x1;
4710 g_assert (tmp_list);
4712 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4714 if (left_column && !left_column->visible)
4716 cur_column = left_column;
4717 tmp_list = tmp_list->prev;
4720 if (!tree_view->priv->column_drop_func)
4723 if (tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4726 cur_column = left_column;
4727 tmp_list = tmp_list->prev;
4730 if (!tree_view->priv->column_drop_func)
4733 if (tree_view->priv->column_drop_func (tree_view, column, NULL, cur_column, tree_view->priv->column_drop_func_data))
4736 return (PsppSheetViewColumn *)0x1;
4740 return (PsppSheetViewColumn *)0x1;
4744 pspp_sheet_view_key_press (GtkWidget *widget,
4747 PsppSheetView *tree_view = (PsppSheetView *) widget;
4749 if (tree_view->priv->rubber_band_status)
4751 if (event->keyval == GDK_Escape)
4752 pspp_sheet_view_stop_rubber_band (tree_view);
4757 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
4759 if (event->keyval == GDK_Escape)
4761 tree_view->priv->cur_reorder = NULL;
4762 pspp_sheet_view_button_release_drag_column (widget, NULL);
4767 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
4769 GList *focus_column;
4772 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
4774 for (focus_column = tree_view->priv->columns;
4776 focus_column = focus_column->next)
4778 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4780 if (column->button && gtk_widget_has_focus (column->button))
4785 (event->state & GDK_SHIFT_MASK) && (event->state & GDK_MOD1_MASK) &&
4786 (event->keyval == GDK_Left || event->keyval == GDK_KP_Left
4787 || event->keyval == GDK_Right || event->keyval == GDK_KP_Right))
4789 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4791 if (!column->resizable)
4793 gtk_widget_error_bell (widget);
4797 if (event->keyval == (rtl ? GDK_Right : GDK_Left)
4798 || event->keyval == (rtl ? GDK_KP_Right : GDK_KP_Left))
4800 gint old_width = column->resized_width;
4802 column->resized_width = MAX (column->resized_width,
4804 column->resized_width -= 2;
4805 if (column->resized_width < 0)
4806 column->resized_width = 0;
4808 if (column->min_width == -1)
4809 column->resized_width = MAX (column->button_request,
4810 column->resized_width);
4812 column->resized_width = MAX (column->min_width,
4813 column->resized_width);
4815 if (column->max_width != -1)
4816 column->resized_width = MIN (column->resized_width,
4819 column->use_resized_width = TRUE;
4821 if (column->resized_width != old_width)
4822 gtk_widget_queue_resize (widget);
4824 gtk_widget_error_bell (widget);
4826 else if (event->keyval == (rtl ? GDK_Left : GDK_Right)
4827 || event->keyval == (rtl ? GDK_KP_Left : GDK_KP_Right))
4829 gint old_width = column->resized_width;
4831 column->resized_width = MAX (column->resized_width,
4833 column->resized_width += 2;
4835 if (column->max_width != -1)
4836 column->resized_width = MIN (column->resized_width,
4839 column->use_resized_width = TRUE;
4841 if (column->resized_width != old_width)
4842 gtk_widget_queue_resize (widget);
4844 gtk_widget_error_bell (widget);
4851 (event->state & GDK_MOD1_MASK) &&
4852 (event->keyval == GDK_Left || event->keyval == GDK_KP_Left
4853 || event->keyval == GDK_Right || event->keyval == GDK_KP_Right
4854 || event->keyval == GDK_Home || event->keyval == GDK_KP_Home
4855 || event->keyval == GDK_End || event->keyval == GDK_KP_End))
4857 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4859 if (event->keyval == (rtl ? GDK_Right : GDK_Left)
4860 || event->keyval == (rtl ? GDK_KP_Right : GDK_KP_Left))
4862 PsppSheetViewColumn *col;
4863 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_LEFT);
4864 if (col != (PsppSheetViewColumn *)0x1)
4865 pspp_sheet_view_move_column_after (tree_view, column, col);
4867 gtk_widget_error_bell (widget);
4869 else if (event->keyval == (rtl ? GDK_Left : GDK_Right)
4870 || event->keyval == (rtl ? GDK_KP_Left : GDK_KP_Right))
4872 PsppSheetViewColumn *col;
4873 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_RIGHT);
4874 if (col != (PsppSheetViewColumn *)0x1)
4875 pspp_sheet_view_move_column_after (tree_view, column, col);
4877 gtk_widget_error_bell (widget);
4879 else if (event->keyval == GDK_Home || event->keyval == GDK_KP_Home)
4881 PsppSheetViewColumn *col;
4882 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_HOME);
4883 if (col != (PsppSheetViewColumn *)0x1)
4884 pspp_sheet_view_move_column_after (tree_view, column, col);
4886 gtk_widget_error_bell (widget);
4888 else if (event->keyval == GDK_End || event->keyval == GDK_KP_End)
4890 PsppSheetViewColumn *col;
4891 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_END);
4892 if (col != (PsppSheetViewColumn *)0x1)
4893 pspp_sheet_view_move_column_after (tree_view, column, col);
4895 gtk_widget_error_bell (widget);
4902 /* Chain up to the parent class. It handles the keybindings. */
4903 if (GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->key_press_event (widget, event))
4906 if (tree_view->priv->search_entry_avoid_unhandled_binding)
4908 tree_view->priv->search_entry_avoid_unhandled_binding = FALSE;
4912 /* We pass the event to the search_entry. If its text changes, then we start
4913 * the typeahead find capabilities. */
4914 if (gtk_widget_has_focus (GTK_WIDGET (tree_view))
4915 && tree_view->priv->enable_search
4916 && !tree_view->priv->search_custom_entry_set)
4918 GdkEvent *new_event;
4920 const char *new_text;
4923 gboolean text_modified;
4924 gulong popup_menu_id;
4926 pspp_sheet_view_ensure_interactive_directory (tree_view);
4928 /* Make a copy of the current text */
4929 old_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry)));
4930 new_event = gdk_event_copy ((GdkEvent *) event);
4931 g_object_unref (((GdkEventKey *) new_event)->window);
4932 ((GdkEventKey *) new_event)->window = g_object_ref (gtk_widget_get_window (tree_view->priv->search_window));
4933 gtk_widget_realize (tree_view->priv->search_window);
4935 popup_menu_id = g_signal_connect (tree_view->priv->search_entry,
4936 "popup-menu", G_CALLBACK (gtk_true),
4939 /* Move the entry off screen */
4940 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
4941 gtk_window_move (GTK_WINDOW (tree_view->priv->search_window),
4942 gdk_screen_get_width (screen) + 1,
4943 gdk_screen_get_height (screen) + 1);
4944 gtk_widget_show (tree_view->priv->search_window);
4946 /* Send the event to the window. If the preedit_changed signal is emitted
4947 * during this event, we will set priv->imcontext_changed */
4948 tree_view->priv->imcontext_changed = FALSE;
4949 retval = gtk_widget_event (tree_view->priv->search_window, new_event);
4950 gdk_event_free (new_event);
4951 gtk_widget_hide (tree_view->priv->search_window);
4953 g_signal_handler_disconnect (tree_view->priv->search_entry,
4956 /* We check to make sure that the entry tried to handle the text, and that
4957 * the text has changed.
4959 new_text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
4960 text_modified = strcmp (old_text, new_text) != 0;
4962 if (tree_view->priv->imcontext_changed || /* we're in a preedit */
4963 (retval && text_modified)) /* ...or the text was modified */
4965 if (pspp_sheet_view_real_start_interactive_search (tree_view, FALSE))
4967 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
4972 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
4982 pspp_sheet_view_key_release (GtkWidget *widget,
4985 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4987 if (tree_view->priv->rubber_band_status)
4990 return GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->key_release_event (widget, event);
4993 /* FIXME Is this function necessary? Can I get an enter_notify event
4994 * w/o either an expose event or a mouse motion event?
4997 pspp_sheet_view_enter_notify (GtkWidget *widget,
4998 GdkEventCrossing *event)
5000 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
5004 /* Sanity check it */
5005 if (event->window != tree_view->priv->bin_window)
5008 if (tree_view->priv->row_count == 0)
5011 if (event->mode == GDK_CROSSING_GRAB ||
5012 event->mode == GDK_CROSSING_GTK_GRAB ||
5013 event->mode == GDK_CROSSING_GTK_UNGRAB ||
5014 event->mode == GDK_CROSSING_STATE_CHANGED)
5017 /* find the node internally */
5018 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, event->y);
5021 pspp_sheet_view_find_offset (tree_view, new_y, &node);
5023 tree_view->priv->event_last_x = event->x;
5024 tree_view->priv->event_last_y = event->y;
5026 prelight_or_select (tree_view, node, event->x, event->y);
5032 pspp_sheet_view_leave_notify (GtkWidget *widget,
5033 GdkEventCrossing *event)
5035 PsppSheetView *tree_view;
5037 if (event->mode == GDK_CROSSING_GRAB)
5040 tree_view = PSPP_SHEET_VIEW (widget);
5042 if (tree_view->priv->prelight_node >= 0)
5043 _pspp_sheet_view_queue_draw_node (tree_view,
5044 tree_view->priv->prelight_node,
5047 tree_view->priv->event_last_x = -10000;
5048 tree_view->priv->event_last_y = -10000;
5050 prelight_or_select (tree_view,
5052 -1000, -1000); /* coords not possibly over an arrow */
5059 pspp_sheet_view_focus_out (GtkWidget *widget,
5060 GdkEventFocus *event)
5062 PsppSheetView *tree_view;
5064 tree_view = PSPP_SHEET_VIEW (widget);
5066 gtk_widget_queue_draw (widget);
5068 /* destroy interactive search dialog */
5069 if (tree_view->priv->search_window)
5070 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
5076 /* Incremental Reflow
5080 pspp_sheet_view_node_queue_redraw (PsppSheetView *tree_view,
5083 GtkAllocation allocation;
5084 gint y = pspp_sheet_view_node_find_offset (tree_view, node)
5085 - gtk_adjustment_get_value (tree_view->priv->vadjustment)
5086 + TREE_VIEW_HEADER_HEIGHT (tree_view);
5088 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
5090 gtk_widget_queue_draw_area (GTK_WIDGET (tree_view),
5093 tree_view->priv->fixed_height);
5097 node_is_visible (PsppSheetView *tree_view,
5103 y = pspp_sheet_view_node_find_offset (tree_view, node);
5104 height = ROW_HEIGHT (tree_view);
5106 if (y >= gtk_adjustment_get_value (tree_view->priv->vadjustment) &&
5107 y + height <= (gtk_adjustment_get_value (tree_view->priv->vadjustment)
5108 + gtk_adjustment_get_page_size (tree_view->priv->vadjustment)))
5114 /* Returns the row height. */
5116 validate_row (PsppSheetView *tree_view,
5121 PsppSheetViewColumn *column;
5122 GList *list, *first_column, *last_column;
5124 gint horizontal_separator;
5125 gint vertical_separator;
5126 gint focus_line_width;
5127 gboolean draw_vgrid_lines, draw_hgrid_lines;
5129 gint grid_line_width;
5130 gboolean wide_separators;
5131 gint separator_height;
5133 gtk_widget_style_get (GTK_WIDGET (tree_view),
5134 "focus-padding", &focus_pad,
5135 "focus-line-width", &focus_line_width,
5136 "horizontal-separator", &horizontal_separator,
5137 "vertical-separator", &vertical_separator,
5138 "grid-line-width", &grid_line_width,
5139 "wide-separators", &wide_separators,
5140 "separator-height", &separator_height,
5144 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
5145 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
5147 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
5148 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
5150 for (last_column = g_list_last (tree_view->priv->columns);
5151 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
5152 last_column = last_column->prev)
5155 for (first_column = g_list_first (tree_view->priv->columns);
5156 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
5157 first_column = first_column->next)
5160 for (list = tree_view->priv->columns; list; list = list->next)
5165 column = list->data;
5167 if (! column->visible)
5170 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, iter);
5171 pspp_sheet_view_column_cell_get_size (column,
5173 &tmp_width, &tmp_height);
5175 tmp_height += vertical_separator;
5176 height = MAX (height, tmp_height);
5178 tmp_width = tmp_width + horizontal_separator;
5180 if (draw_vgrid_lines)
5182 if (list->data == first_column || list->data == last_column)
5183 tmp_width += grid_line_width / 2.0;
5185 tmp_width += grid_line_width;
5188 if (tmp_width > column->requested_width)
5189 column->requested_width = tmp_width;
5192 if (draw_hgrid_lines)
5193 height += grid_line_width;
5195 tree_view->priv->post_validation_flag = TRUE;
5201 validate_visible_area (PsppSheetView *tree_view)
5203 GtkTreePath *path = NULL;
5204 GtkTreePath *above_path = NULL;
5207 gboolean size_changed = FALSE;
5209 gint area_above = 0;
5210 gint area_below = 0;
5211 GtkAllocation allocation;
5213 if (tree_view->priv->row_count == 0)
5216 if (tree_view->priv->scroll_to_path == NULL)
5219 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
5221 total_height = allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
5223 if (total_height == 0)
5226 path = gtk_tree_row_reference_get_path (tree_view->priv->scroll_to_path);
5229 /* we are going to scroll, and will update dy */
5230 _pspp_sheet_view_find_node (tree_view, path, &node);
5231 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
5233 if (tree_view->priv->scroll_to_use_align)
5235 gint height = ROW_HEIGHT (tree_view);
5236 area_above = (total_height - height) *
5237 tree_view->priv->scroll_to_row_align;
5238 area_below = total_height - area_above - height;
5239 area_above = MAX (area_above, 0);
5240 area_below = MAX (area_below, 0);
5245 * 1) row not visible
5249 gint height = ROW_HEIGHT (tree_view);
5251 dy = pspp_sheet_view_node_find_offset (tree_view, node);
5253 if (dy >= gtk_adjustment_get_value (tree_view->priv->vadjustment) &&
5254 dy + height <= (gtk_adjustment_get_value (tree_view->priv->vadjustment)
5255 + gtk_adjustment_get_page_size (tree_view->priv->vadjustment)))
5257 /* row visible: keep the row at the same position */
5258 area_above = dy - gtk_adjustment_get_value (tree_view->priv->vadjustment);
5259 area_below = (gtk_adjustment_get_value (tree_view->priv->vadjustment) +
5260 gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
5265 /* row not visible */
5267 && dy + height <= gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
5269 /* row at the beginning -- fixed */
5271 area_below = gtk_adjustment_get_page_size (tree_view->priv->vadjustment)
5272 - area_above - height;
5274 else if (dy >= (gtk_adjustment_get_upper (tree_view->priv->vadjustment) -
5275 gtk_adjustment_get_page_size (tree_view->priv->vadjustment)))
5277 /* row at the end -- fixed */
5278 area_above = dy - (gtk_adjustment_get_upper (tree_view->priv->vadjustment) -
5279 gtk_adjustment_get_page_size (tree_view->priv->vadjustment));
5280 area_below = gtk_adjustment_get_page_size (tree_view->priv->vadjustment) -
5281 area_above - height;
5285 area_above = gtk_adjustment_get_page_size (tree_view->priv->vadjustment) - height;
5291 /* row somewhere in the middle, bring it to the top
5295 area_below = total_height - height;
5301 /* the scroll to isn't valid; ignore it.
5304 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
5305 tree_view->priv->scroll_to_path = NULL;
5309 above_path = gtk_tree_path_copy (path);
5311 /* Now, we walk forwards and backwards, measuring rows. Unfortunately,
5312 * backwards is much slower then forward, as there is no iter_prev function.
5313 * We go forwards first in case we run out of tree. Then we go backwards to
5316 while (node >= 0 && area_below > 0)
5318 gboolean done = FALSE;
5321 node = pspp_sheet_view_node_next (tree_view, node);
5324 gboolean has_next = gtk_tree_model_iter_next (tree_view->priv->model, &iter);
5326 gtk_tree_path_next (path);
5329 TREE_VIEW_INTERNAL_ASSERT_VOID (has_next);
5339 area_below -= ROW_HEIGHT (tree_view);
5341 gtk_tree_path_free (path);
5343 /* If we ran out of tree, and have extra area_below left, we need to add it
5346 area_above += area_below;
5348 _pspp_sheet_view_find_node (tree_view, above_path, &node);
5350 /* We walk backwards */
5351 while (area_above > 0)
5353 node = pspp_sheet_view_node_prev (tree_view, node);
5355 /* Always find the new path in the tree. We cannot just assume
5356 * a gtk_tree_path_prev() is enough here, as there might be children
5357 * in between this node and the previous sibling node. If this
5358 * appears to be a performance hotspot in profiles, we can look into
5359 * intrigate logic for keeping path, node and iter in sync like
5360 * we do for forward walks. (Which will be hard because of the lacking
5367 gtk_tree_path_free (above_path);
5368 above_path = _pspp_sheet_view_find_path (tree_view, node);
5370 gtk_tree_model_get_iter (tree_view->priv->model, &iter, above_path);
5372 area_above -= ROW_HEIGHT (tree_view);
5375 /* set the dy here to scroll to the path,
5376 * and sync the top row accordingly
5378 pspp_sheet_view_set_top_row (tree_view, above_path, -area_above);
5379 pspp_sheet_view_top_row_to_dy (tree_view);
5381 /* update width/height and queue a resize */
5384 GtkRequisition requisition;
5386 /* We temporarily guess a size, under the assumption that it will be the
5387 * same when we get our next size_allocate. If we don't do this, we'll be
5388 * in an inconsistent state if we call top_row_to_dy. */
5390 gtk_widget_size_request (GTK_WIDGET (tree_view), &requisition);
5391 gtk_adjustment_set_upper (tree_view->priv->hadjustment, MAX (gtk_adjustment_get_upper (tree_view->priv->hadjustment), (gfloat)requisition.width));
5392 gtk_adjustment_set_upper (tree_view->priv->vadjustment, MAX (gtk_adjustment_get_upper (tree_view->priv->vadjustment), (gfloat)requisition.height));
5393 gtk_adjustment_changed (tree_view->priv->hadjustment);
5394 gtk_adjustment_changed (tree_view->priv->vadjustment);
5395 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
5398 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
5399 tree_view->priv->scroll_to_path = NULL;
5402 gtk_tree_path_free (above_path);
5404 if (tree_view->priv->scroll_to_column)
5406 tree_view->priv->scroll_to_column = NULL;
5408 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
5412 initialize_fixed_height_mode (PsppSheetView *tree_view)
5414 if (!tree_view->priv->row_count)
5417 if (tree_view->priv->fixed_height_set)
5420 if (tree_view->priv->fixed_height < 0)
5427 path = _pspp_sheet_view_find_path (tree_view, node);
5428 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
5430 tree_view->priv->fixed_height = validate_row (tree_view, node, &iter, path);
5432 gtk_tree_path_free (path);
5434 g_object_notify (G_OBJECT (tree_view), "fixed-height");
5438 /* Our strategy for finding nodes to validate is a little convoluted. We find
5439 * the left-most uninvalidated node. We then try walking right, validating
5440 * nodes. Once we find a valid node, we repeat the previous process of finding
5441 * the first invalid node.
5445 validate_rows_handler (PsppSheetView *tree_view)
5447 initialize_fixed_height_mode (tree_view);
5448 if (tree_view->priv->validate_rows_timer)
5450 g_source_remove (tree_view->priv->validate_rows_timer);
5451 tree_view->priv->validate_rows_timer = 0;
5458 do_presize_handler (PsppSheetView *tree_view)
5460 GtkRequisition requisition;
5462 validate_visible_area (tree_view);
5463 tree_view->priv->presize_handler_timer = 0;
5465 if (! gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5468 gtk_widget_size_request (GTK_WIDGET (tree_view), &requisition);
5470 gtk_adjustment_set_upper (tree_view->priv->hadjustment, MAX (gtk_adjustment_get_upper (tree_view->priv->hadjustment), (gfloat)requisition.width));
5471 gtk_adjustment_set_upper (tree_view->priv->vadjustment, MAX (gtk_adjustment_get_upper (tree_view->priv->vadjustment), (gfloat)requisition.height));
5472 gtk_adjustment_changed (tree_view->priv->hadjustment);
5473 gtk_adjustment_changed (tree_view->priv->vadjustment);
5474 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
5480 presize_handler_callback (gpointer data)
5482 do_presize_handler (PSPP_SHEET_VIEW (data));
5488 install_presize_handler (PsppSheetView *tree_view)
5490 if (! gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5493 if (! tree_view->priv->presize_handler_timer)
5495 tree_view->priv->presize_handler_timer =
5496 gdk_threads_add_idle_full (GTK_PRIORITY_RESIZE - 2, presize_handler_callback, tree_view, NULL);
5498 if (! tree_view->priv->validate_rows_timer)
5500 tree_view->priv->validate_rows_timer =
5501 gdk_threads_add_idle_full (PSPP_SHEET_VIEW_PRIORITY_VALIDATE, (GSourceFunc) validate_rows_handler, tree_view, NULL);
5506 scroll_sync_handler (PsppSheetView *tree_view)
5508 if (tree_view->priv->height <= gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
5509 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment), 0);
5510 else if (gtk_tree_row_reference_valid (tree_view->priv->top_row))
5511 pspp_sheet_view_top_row_to_dy (tree_view);
5513 pspp_sheet_view_dy_to_top_row (tree_view);
5515 tree_view->priv->scroll_sync_timer = 0;
5521 install_scroll_sync_handler (PsppSheetView *tree_view)
5523 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5526 if (!tree_view->priv->scroll_sync_timer)
5528 tree_view->priv->scroll_sync_timer =
5529 gdk_threads_add_idle_full (PSPP_SHEET_VIEW_PRIORITY_SCROLL_SYNC, (GSourceFunc) scroll_sync_handler, tree_view, NULL);
5534 pspp_sheet_view_set_top_row (PsppSheetView *tree_view,
5538 gtk_tree_row_reference_free (tree_view->priv->top_row);
5542 tree_view->priv->top_row = NULL;
5543 tree_view->priv->top_row_dy = 0;
5547 tree_view->priv->top_row = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
5548 tree_view->priv->top_row_dy = offset;
5552 /* Always call this iff dy is in the visible range. If the tree is empty, then
5553 * it's set to be NULL, and top_row_dy is 0;
5556 pspp_sheet_view_dy_to_top_row (PsppSheetView *tree_view)
5562 if (tree_view->priv->row_count == 0)
5564 pspp_sheet_view_set_top_row (tree_view, NULL, 0);
5568 offset = pspp_sheet_view_find_offset (tree_view,
5569 tree_view->priv->dy,
5574 pspp_sheet_view_set_top_row (tree_view, NULL, 0);
5578 path = _pspp_sheet_view_find_path (tree_view, node);
5579 pspp_sheet_view_set_top_row (tree_view, path, offset);
5580 gtk_tree_path_free (path);
5586 pspp_sheet_view_top_row_to_dy (PsppSheetView *tree_view)
5592 /* Avoid recursive calls */
5593 if (tree_view->priv->in_top_row_to_dy)
5596 if (tree_view->priv->top_row)
5597 path = gtk_tree_row_reference_get_path (tree_view->priv->top_row);
5604 _pspp_sheet_view_find_node (tree_view, path, &node);
5607 gtk_tree_path_free (path);
5611 /* keep dy and set new toprow */
5612 gtk_tree_row_reference_free (tree_view->priv->top_row);
5613 tree_view->priv->top_row = NULL;
5614 tree_view->priv->top_row_dy = 0;
5615 /* DO NOT install the idle handler */
5616 pspp_sheet_view_dy_to_top_row (tree_view);
5620 if (ROW_HEIGHT (tree_view) < tree_view->priv->top_row_dy)
5622 /* new top row -- do NOT install the idle handler */
5623 pspp_sheet_view_dy_to_top_row (tree_view);
5627 new_dy = pspp_sheet_view_node_find_offset (tree_view, node);
5628 new_dy += tree_view->priv->top_row_dy;
5630 if (new_dy + gtk_adjustment_get_page_size (tree_view->priv->vadjustment) > tree_view->priv->height)
5631 new_dy = tree_view->priv->height - gtk_adjustment_get_page_size (tree_view->priv->vadjustment);
5633 new_dy = MAX (0, new_dy);
5635 tree_view->priv->in_top_row_to_dy = TRUE;
5636 gtk_adjustment_set_value (tree_view->priv->vadjustment, (gdouble)new_dy);
5637 tree_view->priv->in_top_row_to_dy = FALSE;
5642 _pspp_sheet_view_install_mark_rows_col_dirty (PsppSheetView *tree_view)
5644 install_presize_handler (tree_view);
5650 set_source_row (GdkDragContext *context,
5651 GtkTreeModel *model,
5652 GtkTreePath *source_row)
5654 g_object_set_data_full (G_OBJECT (context),
5655 "gtk-tree-view-source-row",
5656 source_row ? gtk_tree_row_reference_new (model, source_row) : NULL,
5657 (GDestroyNotify) (source_row ? gtk_tree_row_reference_free : NULL));
5661 get_source_row (GdkDragContext *context)
5663 GtkTreeRowReference *ref =
5664 g_object_get_data (G_OBJECT (context), "gtk-tree-view-source-row");
5667 return gtk_tree_row_reference_get_path (ref);
5674 GtkTreeRowReference *dest_row;
5675 guint path_down_mode : 1;
5676 guint empty_view_drop : 1;
5677 guint drop_append_mode : 1;
5682 dest_row_free (gpointer data)
5684 DestRow *dr = (DestRow *)data;
5686 gtk_tree_row_reference_free (dr->dest_row);
5687 g_slice_free (DestRow, dr);
5691 set_dest_row (GdkDragContext *context,
5692 GtkTreeModel *model,
5693 GtkTreePath *dest_row,
5694 gboolean path_down_mode,
5695 gboolean empty_view_drop,
5696 gboolean drop_append_mode)
5702 g_object_set_data_full (G_OBJECT (context), "gtk-tree-view-dest-row",
5707 dr = g_slice_new (DestRow);
5709 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5710 dr->path_down_mode = path_down_mode != FALSE;
5711 dr->empty_view_drop = empty_view_drop != FALSE;
5712 dr->drop_append_mode = drop_append_mode != FALSE;
5714 g_object_set_data_full (G_OBJECT (context), "gtk-tree-view-dest-row",
5715 dr, (GDestroyNotify) dest_row_free);
5719 get_dest_row (GdkDragContext *context,
5720 gboolean *path_down_mode)
5723 g_object_get_data (G_OBJECT (context), "gtk-tree-view-dest-row");
5727 GtkTreePath *path = NULL;
5730 *path_down_mode = dr->path_down_mode;
5733 path = gtk_tree_row_reference_get_path (dr->dest_row);
5734 else if (dr->empty_view_drop)
5735 path = gtk_tree_path_new_from_indices (0, -1);
5739 if (path && dr->drop_append_mode)
5740 gtk_tree_path_next (path);
5748 /* Get/set whether drag_motion requested the drag data and
5749 * drag_data_received should thus not actually insert the data,
5750 * since the data doesn't result from a drop.
5753 set_status_pending (GdkDragContext *context,
5754 GdkDragAction suggested_action)
5756 g_object_set_data (G_OBJECT (context),
5757 "gtk-tree-view-status-pending",
5758 GINT_TO_POINTER (suggested_action));
5761 static GdkDragAction
5762 get_status_pending (GdkDragContext *context)
5764 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5765 "gtk-tree-view-status-pending"));
5768 static TreeViewDragInfo*
5769 get_info (PsppSheetView *tree_view)
5771 return g_object_get_data (G_OBJECT (tree_view), "gtk-tree-view-drag-info");
5775 destroy_info (TreeViewDragInfo *di)
5777 g_slice_free (TreeViewDragInfo, di);
5780 static TreeViewDragInfo*
5781 ensure_info (PsppSheetView *tree_view)
5783 TreeViewDragInfo *di;
5785 di = get_info (tree_view);
5789 di = g_slice_new0 (TreeViewDragInfo);
5791 g_object_set_data_full (G_OBJECT (tree_view),
5792 "gtk-tree-view-drag-info",
5794 (GDestroyNotify) destroy_info);
5801 remove_info (PsppSheetView *tree_view)
5803 g_object_set_data (G_OBJECT (tree_view), "gtk-tree-view-drag-info", NULL);
5808 drag_scan_timeout (gpointer data)
5810 PsppSheetView *tree_view;
5812 GdkModifierType state;
5813 GtkTreePath *path = NULL;
5814 PsppSheetViewColumn *column = NULL;
5815 GdkRectangle visible_rect;
5817 GDK_THREADS_ENTER ();
5819 tree_view = PSPP_SHEET_VIEW (data);
5821 gdk_window_get_pointer (tree_view->priv->bin_window,
5824 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
5826 /* See if we are near the edge. */
5827 if ((x - visible_rect.x) < SCROLL_EDGE_SIZE ||
5828 (visible_rect.x + visible_rect.width - x) < SCROLL_EDGE_SIZE ||
5829 (y - visible_rect.y) < SCROLL_EDGE_SIZE ||
5830 (visible_rect.y + visible_rect.height - y) < SCROLL_EDGE_SIZE)
5832 pspp_sheet_view_get_path_at_pos (tree_view,
5833 tree_view->priv->bin_window,
5842 pspp_sheet_view_scroll_to_cell (tree_view,
5848 gtk_tree_path_free (path);
5852 GDK_THREADS_LEAVE ();
5859 add_scroll_timeout (PsppSheetView *tree_view)
5861 if (tree_view->priv->scroll_timeout == 0)
5863 tree_view->priv->scroll_timeout =
5864 gdk_threads_add_timeout (150, scroll_row_timeout, tree_view);
5869 remove_scroll_timeout (PsppSheetView *tree_view)
5871 if (tree_view->priv->scroll_timeout != 0)
5873 g_source_remove (tree_view->priv->scroll_timeout);
5874 tree_view->priv->scroll_timeout = 0;
5879 check_model_dnd (GtkTreeModel *model,
5880 GType required_iface,
5881 const gchar *signal)
5883 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5885 g_warning ("You must override the default '%s' handler "
5886 "on PsppSheetView when using models that don't support "
5887 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5888 "is to connect to '%s' and call "
5889 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5890 "the default handler from running. Look at the source code "
5891 "for the default handler in gtktreeview.c to get an idea what "
5892 "your handler should do. (gtktreeview.c is in the GTK source "
5893 "code.) If you're using GTK from a language other than C, "
5894 "there may be a more natural way to override default handlers, e.g. via derivation.",
5895 signal, g_type_name (required_iface), signal);
5903 scroll_row_timeout (gpointer data)
5905 PsppSheetView *tree_view = data;
5907 pspp_sheet_view_horizontal_autoscroll (tree_view);
5908 pspp_sheet_view_vertical_autoscroll (tree_view);
5910 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
5911 pspp_sheet_view_update_rubber_band (tree_view);
5916 /* Returns TRUE if event should not be propagated to parent widgets */
5918 set_destination_row (PsppSheetView *tree_view,
5919 GdkDragContext *context,
5920 /* coordinates relative to the widget */
5923 GdkDragAction *suggested_action,
5926 GtkTreePath *path = NULL;
5927 PsppSheetViewDropPosition pos;
5928 PsppSheetViewDropPosition old_pos;
5929 TreeViewDragInfo *di;
5931 GtkTreePath *old_dest_path = NULL;
5932 gboolean can_drop = FALSE;
5934 *suggested_action = 0;
5937 widget = GTK_WIDGET (tree_view);
5939 di = get_info (tree_view);
5941 if (di == NULL || y - TREE_VIEW_HEADER_HEIGHT (tree_view) < 0)
5943 /* someone unset us as a drag dest, note that if
5944 * we return FALSE drag_leave isn't called
5947 pspp_sheet_view_set_drag_dest_row (tree_view,
5949 PSPP_SHEET_VIEW_DROP_BEFORE);
5951 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
5953 return FALSE; /* no longer a drop site */
5956 *target = gtk_drag_dest_find_target (widget, context,
5957 gtk_drag_dest_get_target_list (widget));
5958 if (*target == GDK_NONE)
5963 if (!pspp_sheet_view_get_dest_row_at_pos (tree_view,
5969 GtkTreeModel *model;
5971 /* the row got dropped on empty space, let's setup a special case
5975 gtk_tree_path_free (path);
5977 model = pspp_sheet_view_get_model (tree_view);
5979 n_children = gtk_tree_model_iter_n_children (model, NULL);
5982 pos = PSPP_SHEET_VIEW_DROP_AFTER;
5983 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
5987 pos = PSPP_SHEET_VIEW_DROP_BEFORE;
5988 path = gtk_tree_path_new_from_indices (0, -1);
5998 /* If we left the current row's "open" zone, unset the timeout for
6001 pspp_sheet_view_get_drag_dest_row (tree_view,
6006 gtk_tree_path_free (old_dest_path);
6008 if (TRUE /* FIXME if the location droppable predicate */)
6016 GtkWidget *source_widget;
6018 *suggested_action = gdk_drag_context_get_suggested_action (context);
6019 source_widget = gtk_drag_get_source_widget (context);
6021 if (source_widget == widget)
6023 /* Default to MOVE, unless the user has
6024 * pressed ctrl or shift to affect available actions
6026 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
6027 *suggested_action = GDK_ACTION_MOVE;
6030 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6035 /* can't drop here */
6036 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6038 PSPP_SHEET_VIEW_DROP_BEFORE);
6042 gtk_tree_path_free (path);
6048 get_logical_dest_row (PsppSheetView *tree_view,
6049 gboolean *path_down_mode,
6050 gboolean *drop_append_mode)
6052 /* adjust path to point to the row the drop goes in front of */
6053 GtkTreePath *path = NULL;
6054 PsppSheetViewDropPosition pos;
6056 g_return_val_if_fail (path_down_mode != NULL, NULL);
6057 g_return_val_if_fail (drop_append_mode != NULL, NULL);
6059 *path_down_mode = FALSE;
6060 *drop_append_mode = 0;
6062 pspp_sheet_view_get_drag_dest_row (tree_view, &path, &pos);
6067 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE)
6069 else if (pos == PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE ||
6070 pos == PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER)
6071 *path_down_mode = TRUE;
6075 GtkTreeModel *model = pspp_sheet_view_get_model (tree_view);
6077 g_assert (pos == PSPP_SHEET_VIEW_DROP_AFTER);
6079 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6080 !gtk_tree_model_iter_next (model, &iter))
6081 *drop_append_mode = 1;
6084 *drop_append_mode = 0;
6085 gtk_tree_path_next (path);
6093 pspp_sheet_view_maybe_begin_dragging_row (PsppSheetView *tree_view,
6094 GdkEventMotion *event)
6096 GtkWidget *widget = GTK_WIDGET (tree_view);
6097 GdkDragContext *context;
6098 TreeViewDragInfo *di;
6099 GtkTreePath *path = NULL;
6101 gint cell_x, cell_y;
6102 GtkTreeModel *model;
6103 gboolean retval = FALSE;
6105 di = get_info (tree_view);
6107 if (di == NULL || !di->source_set)
6110 if (tree_view->priv->pressed_button < 0)
6113 if (!gtk_drag_check_threshold (widget,
6114 tree_view->priv->press_start_x,
6115 tree_view->priv->press_start_y,
6116 event->x, event->y))
6119 model = pspp_sheet_view_get_model (tree_view);
6124 button = tree_view->priv->pressed_button;
6125 tree_view->priv->pressed_button = -1;
6127 pspp_sheet_view_get_path_at_pos (tree_view,
6128 tree_view->priv->press_start_x,
6129 tree_view->priv->press_start_y,
6138 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6139 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6143 if (!(GDK_BUTTON1_MASK << (button - 1) & di->start_button_mask))
6146 /* Now we can begin the drag */
6150 context = gtk_drag_begin (widget,
6151 gtk_drag_source_get_target_list (widget),
6156 set_source_row (context, model, path);
6160 gtk_tree_path_free (path);
6168 pspp_sheet_view_drag_begin (GtkWidget *widget,
6169 GdkDragContext *context)
6172 PsppSheetView *tree_view;
6173 GtkTreePath *path = NULL;
6174 gint cell_x, cell_y;
6176 TreeViewDragInfo *di;
6178 tree_view = PSPP_SHEET_VIEW (widget);
6180 /* if the user uses a custom DND source impl, we don't set the icon here */
6181 di = get_info (tree_view);
6183 if (di == NULL || !di->source_set)
6186 pspp_sheet_view_get_path_at_pos (tree_view,
6187 tree_view->priv->press_start_x,
6188 tree_view->priv->press_start_y,
6194 g_return_if_fail (path != NULL);
6196 row_pix = pspp_sheet_view_create_row_drag_icon (tree_view,
6199 gtk_drag_set_icon_pixmap (context,
6200 gdk_drawable_get_colormap (row_pix),
6203 /* the + 1 is for the black border in the icon */
6204 tree_view->priv->press_start_x + 1,
6207 g_object_unref (row_pix);
6208 gtk_tree_path_free (path);
6214 pspp_sheet_view_drag_end (GtkWidget *widget,
6215 GdkDragContext *context)
6220 /* Default signal implementations for the drag signals */
6222 pspp_sheet_view_drag_data_get (GtkWidget *widget,
6223 GdkDragContext *context,
6224 GtkSelectionData *selection_data,
6228 PsppSheetView *tree_view;
6229 GtkTreeModel *model;
6230 TreeViewDragInfo *di;
6231 GtkTreePath *source_row;
6233 tree_view = PSPP_SHEET_VIEW (widget);
6235 model = pspp_sheet_view_get_model (tree_view);
6240 di = get_info (PSPP_SHEET_VIEW (widget));
6245 source_row = get_source_row (context);
6247 if (source_row == NULL)
6250 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6251 * any model; for DragSource models there are some other targets
6255 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6256 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6261 /* If drag_data_get does nothing, try providing row data. */
6262 if (gtk_selection_data_get_target (selection_data) == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6264 gtk_tree_set_row_drag_data (selection_data,
6270 gtk_tree_path_free (source_row);
6275 pspp_sheet_view_drag_data_delete (GtkWidget *widget,
6276 GdkDragContext *context)
6278 TreeViewDragInfo *di;
6279 GtkTreeModel *model;
6280 PsppSheetView *tree_view;
6281 GtkTreePath *source_row;
6283 tree_view = PSPP_SHEET_VIEW (widget);
6284 model = pspp_sheet_view_get_model (tree_view);
6286 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
6289 di = get_info (tree_view);
6294 source_row = get_source_row (context);
6296 if (source_row == NULL)
6299 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6302 gtk_tree_path_free (source_row);
6304 set_source_row (context, NULL, NULL);
6308 pspp_sheet_view_drag_leave (GtkWidget *widget,
6309 GdkDragContext *context,
6312 /* unset any highlight row */
6313 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6315 PSPP_SHEET_VIEW_DROP_BEFORE);
6317 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6322 pspp_sheet_view_drag_motion (GtkWidget *widget,
6323 GdkDragContext *context,
6324 /* coordinates relative to the widget */
6330 GtkTreePath *path = NULL;
6331 PsppSheetViewDropPosition pos;
6332 PsppSheetView *tree_view;
6333 GdkDragAction suggested_action = 0;
6336 tree_view = PSPP_SHEET_VIEW (widget);
6338 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6341 pspp_sheet_view_get_drag_dest_row (tree_view, &path, &pos);
6343 /* we only know this *after* set_desination_row */
6344 empty = tree_view->priv->empty_view_drop;
6346 if (path == NULL && !empty)
6348 /* Can't drop here. */
6349 gdk_drag_status (context, 0, time);
6353 if (tree_view->priv->open_dest_timeout == 0 &&
6354 (pos == PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER ||
6355 pos == PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE))
6361 add_scroll_timeout (tree_view);
6364 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6366 /* Request data so we can use the source row when
6367 * determining whether to accept the drop
6369 set_status_pending (context, suggested_action);
6370 gtk_drag_get_data (widget, context, target, time);
6374 set_status_pending (context, 0);
6375 gdk_drag_status (context, suggested_action, time);
6380 gtk_tree_path_free (path);
6387 pspp_sheet_view_drag_drop (GtkWidget *widget,
6388 GdkDragContext *context,
6389 /* coordinates relative to the widget */
6394 PsppSheetView *tree_view;
6396 GdkDragAction suggested_action = 0;
6397 GdkAtom target = GDK_NONE;
6398 TreeViewDragInfo *di;
6399 GtkTreeModel *model;
6400 gboolean path_down_mode;
6401 gboolean drop_append_mode;
6403 tree_view = PSPP_SHEET_VIEW (widget);
6405 model = pspp_sheet_view_get_model (tree_view);
6407 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6409 di = get_info (tree_view);
6414 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
6417 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6420 path = get_logical_dest_row (tree_view, &path_down_mode, &drop_append_mode);
6422 if (target != GDK_NONE && path != NULL)
6424 /* in case a motion had requested drag data, change things so we
6425 * treat drag data receives as a drop.
6427 set_status_pending (context, 0);
6428 set_dest_row (context, model, path,
6429 path_down_mode, tree_view->priv->empty_view_drop,
6434 gtk_tree_path_free (path);
6436 /* Unset this thing */
6437 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6439 PSPP_SHEET_VIEW_DROP_BEFORE);
6441 if (target != GDK_NONE)
6443 gtk_drag_get_data (widget, context, target, time);
6451 pspp_sheet_view_drag_data_received (GtkWidget *widget,
6452 GdkDragContext *context,
6453 /* coordinates relative to the widget */
6456 GtkSelectionData *selection_data,
6461 TreeViewDragInfo *di;
6462 gboolean accepted = FALSE;
6463 GtkTreeModel *model;
6464 PsppSheetView *tree_view;
6465 GtkTreePath *dest_row;
6466 GdkDragAction suggested_action;
6467 gboolean path_down_mode;
6468 gboolean drop_append_mode;
6470 tree_view = PSPP_SHEET_VIEW (widget);
6472 model = pspp_sheet_view_get_model (tree_view);
6474 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_data_received"))
6477 di = get_info (tree_view);
6482 suggested_action = get_status_pending (context);
6484 if (suggested_action)
6486 /* We are getting this data due to a request in drag_motion,
6487 * rather than due to a request in drag_drop, so we are just
6488 * supposed to call drag_status, not actually paste in the
6491 path = get_logical_dest_row (tree_view, &path_down_mode,
6495 suggested_action = 0;
6496 else if (path_down_mode)
6497 gtk_tree_path_down (path);
6499 if (suggested_action)
6501 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6507 path_down_mode = FALSE;
6508 gtk_tree_path_up (path);
6510 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6513 suggested_action = 0;
6516 suggested_action = 0;
6520 gdk_drag_status (context, suggested_action, time);
6523 gtk_tree_path_free (path);
6525 /* If you can't drop, remove user drop indicator until the next motion */
6526 if (suggested_action == 0)
6527 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6529 PSPP_SHEET_VIEW_DROP_BEFORE);
6534 dest_row = get_dest_row (context, &path_down_mode);
6536 if (dest_row == NULL)
6539 if (gtk_selection_data_get_length (selection_data) >= 0)
6543 gtk_tree_path_down (dest_row);
6544 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6545 dest_row, selection_data))
6546 gtk_tree_path_up (dest_row);
6550 if (gtk_selection_data_get_length (selection_data) >= 0)
6552 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6558 gtk_drag_finish (context,
6560 (gdk_drag_context_get_actions (context) == GDK_ACTION_MOVE),
6563 if (gtk_tree_path_get_depth (dest_row) == 1
6564 && gtk_tree_path_get_indices (dest_row)[0] == 0)
6566 /* special special case drag to "0", scroll to first item */
6567 if (!tree_view->priv->scroll_to_path)
6568 pspp_sheet_view_scroll_to_cell (tree_view, dest_row, NULL, FALSE, 0.0, 0.0);
6571 gtk_tree_path_free (dest_row);
6574 set_dest_row (context, NULL, NULL, FALSE, FALSE, FALSE);
6579 /* GtkContainer Methods
6584 pspp_sheet_view_remove (GtkContainer *container,
6587 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6588 PsppSheetViewChild *child = NULL;
6591 tmp_list = tree_view->priv->children;
6594 child = tmp_list->data;
6595 if (child->widget == widget)
6597 gtk_widget_unparent (widget);
6599 tree_view->priv->children = g_list_remove_link (tree_view->priv->children, tmp_list);
6600 g_list_free_1 (tmp_list);
6601 g_slice_free (PsppSheetViewChild, child);
6605 tmp_list = tmp_list->next;
6608 tmp_list = tree_view->priv->columns;
6612 PsppSheetViewColumn *column;
6613 column = tmp_list->data;
6614 if (column->button == widget)
6616 gtk_widget_unparent (widget);
6619 tmp_list = tmp_list->next;
6624 pspp_sheet_view_forall (GtkContainer *container,
6625 gboolean include_internals,
6626 GtkCallback callback,
6627 gpointer callback_data)
6629 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6630 PsppSheetViewChild *child = NULL;
6631 PsppSheetViewColumn *column;
6634 tmp_list = tree_view->priv->children;
6637 child = tmp_list->data;
6638 tmp_list = tmp_list->next;
6640 (* callback) (child->widget, callback_data);
6642 if (include_internals == FALSE)
6645 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6647 column = tmp_list->data;
6650 (* callback) (column->button, callback_data);
6654 /* Returns TRUE if the treeview contains no "special" (editable or activatable)
6655 * cells. If so we draw one big row-spanning focus rectangle.
6658 pspp_sheet_view_has_special_cell (PsppSheetView *tree_view)
6662 if (tree_view->priv->special_cells != PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT)
6663 return tree_view->priv->special_cells = PSPP_SHEET_VIEW_SPECIAL_CELLS_YES;
6665 for (list = tree_view->priv->columns; list; list = list->next)
6667 if (!((PsppSheetViewColumn *)list->data)->visible)
6669 if (_pspp_sheet_view_column_count_special_cells (list->data))
6677 pspp_sheet_view_focus_column (PsppSheetView *tree_view,
6678 PsppSheetViewColumn *focus_column,
6679 gboolean clamp_column_visible)
6681 g_return_if_fail (focus_column != NULL);
6683 tree_view->priv->focus_column = focus_column;
6684 if (!focus_column->button)
6686 pspp_sheet_view_column_set_need_button (focus_column, TRUE);
6687 // g_return_if_fail (focus_column->button != NULL);
6688 if (focus_column->button == NULL)
6692 if (gtk_container_get_focus_child (GTK_CONTAINER (tree_view)) != focus_column->button)
6693 gtk_widget_grab_focus (focus_column->button);
6695 if (clamp_column_visible)
6696 pspp_sheet_view_clamp_column_visible (tree_view, focus_column, FALSE);
6699 /* Returns TRUE if the focus is within the headers, after the focus operation is
6703 pspp_sheet_view_header_focus (PsppSheetView *tree_view,
6704 GtkDirectionType dir,
6705 gboolean clamp_column_visible)
6707 GtkWidget *focus_child;
6708 PsppSheetViewColumn *focus_column;
6709 GList *last_column, *first_column;
6713 if (! PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
6716 focus_child = gtk_container_get_focus_child (GTK_CONTAINER (tree_view));
6718 first_column = tree_view->priv->columns;
6719 while (first_column)
6721 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (first_column->data);
6723 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6725 first_column = first_column->next;
6728 /* No headers are visible, or are focusable. We can't focus in or out.
6730 if (first_column == NULL)
6733 last_column = g_list_last (tree_view->priv->columns);
6736 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (last_column->data);
6738 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6740 last_column = last_column->prev;
6744 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
6748 case GTK_DIR_TAB_BACKWARD:
6749 case GTK_DIR_TAB_FORWARD:
6752 if (focus_child == NULL)
6754 if (tree_view->priv->focus_column != NULL &&
6755 pspp_sheet_view_column_can_focus (tree_view->priv->focus_column))
6756 focus_column = tree_view->priv->focus_column;
6758 focus_column = first_column->data;
6759 pspp_sheet_view_focus_column (tree_view, focus_column,
6760 clamp_column_visible);
6767 if (focus_child == NULL)
6769 if (tree_view->priv->focus_column != NULL)
6770 focus_column = tree_view->priv->focus_column;
6771 else if (dir == GTK_DIR_LEFT)
6772 focus_column = last_column->data;
6774 focus_column = first_column->data;
6775 pspp_sheet_view_focus_column (tree_view, focus_column,
6776 clamp_column_visible);
6780 if (gtk_widget_child_focus (focus_child, dir))
6782 /* The focus moves inside the button. */
6783 /* This is probably a great example of bad UI */
6784 if (clamp_column_visible)
6785 pspp_sheet_view_clamp_column_visible (tree_view,
6786 tree_view->priv->focus_column,
6791 /* We need to move the focus among the row of buttons. */
6792 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6793 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)->button == focus_child)
6796 if ((tmp_list == first_column && dir == (rtl ? GTK_DIR_RIGHT : GTK_DIR_LEFT))
6797 || (tmp_list == last_column && dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT)))
6799 gtk_widget_error_bell (GTK_WIDGET (tree_view));
6805 PsppSheetViewColumn *column;
6807 if (dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT))
6808 tmp_list = tmp_list->next;
6810 tmp_list = tmp_list->prev;
6812 if (tmp_list == NULL)
6814 g_warning ("Internal button not found");
6817 column = tmp_list->data;
6818 if (column->visible &&
6819 pspp_sheet_view_column_can_focus (column))
6821 pspp_sheet_view_column_set_need_button (column, TRUE);
6824 pspp_sheet_view_focus_column (tree_view, column,
6825 clamp_column_visible);
6833 g_assert_not_reached ();
6840 /* This function returns in 'path' the first focusable path, if the given path
6841 * is already focusable, it's the returned one.
6845 search_first_focusable_path (PsppSheetView *tree_view,
6847 gboolean search_forward,
6850 /* XXX this function is trivial given that the sheetview doesn't support
6854 if (!path || !*path)
6857 _pspp_sheet_view_find_node (tree_view, *path, &node);
6865 return (*path != NULL);
6869 pspp_sheet_view_focus (GtkWidget *widget,
6870 GtkDirectionType direction)
6872 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6873 GtkContainer *container = GTK_CONTAINER (widget);
6874 GtkWidget *focus_child;
6876 if (!gtk_widget_is_sensitive (widget) || !gtk_widget_get_can_focus (widget))
6879 focus_child = gtk_container_get_focus_child (container);
6881 pspp_sheet_view_stop_editing (PSPP_SHEET_VIEW (widget), FALSE);
6882 /* Case 1. Headers currently have focus. */
6889 pspp_sheet_view_header_focus (tree_view, direction, TRUE);
6891 case GTK_DIR_TAB_BACKWARD:
6894 case GTK_DIR_TAB_FORWARD:
6896 gtk_widget_grab_focus (widget);
6899 g_assert_not_reached ();
6904 /* Case 2. We don't have focus at all. */
6905 if (!gtk_widget_has_focus (widget))
6907 if (!pspp_sheet_view_header_focus (tree_view, direction, FALSE))
6908 gtk_widget_grab_focus (widget);
6912 /* Case 3. We have focus already. */
6913 if (direction == GTK_DIR_TAB_BACKWARD)
6914 return (pspp_sheet_view_header_focus (tree_view, direction, FALSE));
6915 else if (direction == GTK_DIR_TAB_FORWARD)
6918 /* Other directions caught by the keybindings */
6919 gtk_widget_grab_focus (widget);
6924 pspp_sheet_view_grab_focus (GtkWidget *widget)
6926 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->grab_focus (widget);
6928 pspp_sheet_view_focus_to_cursor (PSPP_SHEET_VIEW (widget));
6932 pspp_sheet_view_style_set (GtkWidget *widget,
6933 GtkStyle *previous_style)
6935 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6937 PsppSheetViewColumn *column;
6939 if (gtk_widget_get_realized (widget))
6941 gdk_window_set_background (tree_view->priv->bin_window, >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
6942 gtk_style_set_background (gtk_widget_get_style (widget), tree_view->priv->header_window, GTK_STATE_NORMAL);
6943 pspp_sheet_view_set_grid_lines (tree_view, tree_view->priv->grid_lines);
6946 gtk_widget_style_get (widget,
6947 "expander-size", &tree_view->priv->expander_size,
6949 tree_view->priv->expander_size += EXPANDER_EXTRA_PADDING;
6951 for (list = tree_view->priv->columns; list; list = list->next)
6953 column = list->data;
6954 _pspp_sheet_view_column_cell_set_dirty (column);
6957 tree_view->priv->fixed_height = -1;
6959 /* Invalidate cached button style. */
6960 if (tree_view->priv->button_style)
6962 g_object_unref (tree_view->priv->button_style);
6963 tree_view->priv->button_style = NULL;
6966 gtk_widget_queue_resize (widget);
6971 pspp_sheet_view_set_focus_child (GtkContainer *container,
6974 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6977 for (list = tree_view->priv->columns; list; list = list->next)
6979 if (PSPP_SHEET_VIEW_COLUMN (list->data)->button == child)
6981 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
6986 GTK_CONTAINER_CLASS (pspp_sheet_view_parent_class)->set_focus_child (container, child);
6990 pspp_sheet_view_set_adjustments (PsppSheetView *tree_view,
6991 GtkAdjustment *hadj,
6992 GtkAdjustment *vadj)
6994 gboolean need_adjust = FALSE;
6996 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
6999 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
7001 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
7003 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
7005 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
7007 if (tree_view->priv->hadjustment && (tree_view->priv->hadjustment != hadj))
7009 g_signal_handlers_disconnect_by_func (tree_view->priv->hadjustment,
7010 pspp_sheet_view_adjustment_changed,
7012 g_object_unref (tree_view->priv->hadjustment);
7015 if (tree_view->priv->vadjustment && (tree_view->priv->vadjustment != vadj))
7017 g_signal_handlers_disconnect_by_func (tree_view->priv->vadjustment,
7018 pspp_sheet_view_adjustment_changed,
7020 g_object_unref (tree_view->priv->vadjustment);
7023 if (tree_view->priv->hadjustment != hadj)
7025 tree_view->priv->hadjustment = hadj;
7026 g_object_ref_sink (tree_view->priv->hadjustment);
7028 g_signal_connect (tree_view->priv->hadjustment, "value-changed",
7029 G_CALLBACK (pspp_sheet_view_adjustment_changed),
7034 if (tree_view->priv->vadjustment != vadj)
7036 tree_view->priv->vadjustment = vadj;
7037 g_object_ref_sink (tree_view->priv->vadjustment);
7039 g_signal_connect (tree_view->priv->vadjustment, "value-changed",
7040 G_CALLBACK (pspp_sheet_view_adjustment_changed),
7046 pspp_sheet_view_adjustment_changed (NULL, tree_view);
7051 pspp_sheet_view_real_move_cursor (PsppSheetView *tree_view,
7052 GtkMovementStep step,
7055 PsppSheetSelectMode mode;
7056 GdkModifierType state;
7058 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
7059 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
7060 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
7061 step == GTK_MOVEMENT_DISPLAY_LINES ||
7062 step == GTK_MOVEMENT_PAGES ||
7063 step == GTK_MOVEMENT_BUFFER_ENDS ||
7064 step == GTK_MOVEMENT_DISPLAY_LINE_ENDS, FALSE);
7066 if (tree_view->priv->row_count == 0)
7068 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7071 pspp_sheet_view_stop_editing (tree_view, FALSE);
7072 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
7073 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7076 if (gtk_get_current_event_state (&state))
7078 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
7079 mode |= PSPP_SHEET_SELECT_MODE_TOGGLE;
7080 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
7081 mode |= PSPP_SHEET_SELECT_MODE_EXTEND;
7083 /* else we assume not pressed */
7087 case GTK_MOVEMENT_LOGICAL_POSITIONS:
7088 pspp_sheet_view_move_cursor_tab (tree_view, count);
7090 case GTK_MOVEMENT_VISUAL_POSITIONS:
7091 pspp_sheet_view_move_cursor_left_right (tree_view, count, mode);
7093 case GTK_MOVEMENT_DISPLAY_LINES:
7094 pspp_sheet_view_move_cursor_up_down (tree_view, count, mode);
7096 case GTK_MOVEMENT_PAGES:
7097 pspp_sheet_view_move_cursor_page_up_down (tree_view, count, mode);
7099 case GTK_MOVEMENT_BUFFER_ENDS:
7100 pspp_sheet_view_move_cursor_start_end (tree_view, count, mode);
7102 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
7103 pspp_sheet_view_move_cursor_line_start_end (tree_view, count, mode);
7106 g_assert_not_reached ();
7113 pspp_sheet_view_put (PsppSheetView *tree_view,
7114 GtkWidget *child_widget,
7115 /* in bin_window coordinates */
7121 PsppSheetViewChild *child;
7123 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
7124 g_return_if_fail (GTK_IS_WIDGET (child_widget));
7126 child = g_slice_new (PsppSheetViewChild);
7128 child->widget = child_widget;
7131 child->width = width;
7132 child->height = height;
7134 tree_view->priv->children = g_list_append (tree_view->priv->children, child);
7136 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7137 gtk_widget_set_parent_window (child->widget, tree_view->priv->bin_window);
7139 gtk_widget_set_parent (child_widget, GTK_WIDGET (tree_view));
7143 _pspp_sheet_view_child_move_resize (PsppSheetView *tree_view,
7145 /* in tree coordinates */
7151 PsppSheetViewChild *child = NULL;
7153 GdkRectangle allocation;
7155 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
7156 g_return_if_fail (GTK_IS_WIDGET (widget));
7158 for (list = tree_view->priv->children; list; list = list->next)
7160 if (((PsppSheetViewChild *)list->data)->widget == widget)
7169 allocation.x = child->x = x;
7170 allocation.y = child->y = y;
7171 allocation.width = child->width = width;
7172 allocation.height = child->height = height;
7174 if (gtk_widget_get_realized (widget))
7175 gtk_widget_size_allocate (widget, &allocation);
7179 /* TreeModel Callbacks
7183 pspp_sheet_view_row_changed (GtkTreeModel *model,
7188 PsppSheetView *tree_view = (PsppSheetView *)data;
7190 gboolean free_path = FALSE;
7191 GtkTreePath *cursor_path;
7193 g_return_if_fail (path != NULL || iter != NULL);
7195 if (tree_view->priv->cursor != NULL)
7196 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7200 if (tree_view->priv->edited_column &&
7201 (cursor_path == NULL || gtk_tree_path_compare (cursor_path, path) == 0))
7202 pspp_sheet_view_stop_editing (tree_view, TRUE);
7204 if (cursor_path != NULL)
7205 gtk_tree_path_free (cursor_path);
7209 path = gtk_tree_model_get_path (model, iter);
7212 else if (iter == NULL)
7213 gtk_tree_model_get_iter (model, iter, path);
7215 _pspp_sheet_view_find_node (tree_view,
7221 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7222 pspp_sheet_view_node_queue_redraw (tree_view, node);
7226 gtk_tree_path_free (path);
7230 pspp_sheet_view_row_inserted (GtkTreeModel *model,
7235 PsppSheetView *tree_view = (PsppSheetView *) data;
7238 gint height = tree_view->priv->fixed_height;
7239 gboolean free_path = FALSE;
7240 gboolean node_visible = TRUE;
7242 g_return_if_fail (path != NULL || iter != NULL);
7246 path = gtk_tree_model_get_path (model, iter);
7249 else if (iter == NULL)
7250 gtk_tree_model_get_iter (model, iter, path);
7252 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7254 /* Update all row-references */
7255 gtk_tree_row_reference_inserted (G_OBJECT (data), path);
7256 indices = gtk_tree_path_get_indices (path);
7257 tmpnode = indices[0];
7259 range_tower_insert0 (tree_view->priv->selected, tmpnode, 1);
7263 if (node_visible && node_is_visible (tree_view, tmpnode))
7264 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7266 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (tree_view));
7269 install_presize_handler (tree_view);
7271 gtk_tree_path_free (path);
7275 pspp_sheet_view_row_deleted (GtkTreeModel *model,
7279 PsppSheetView *tree_view = (PsppSheetView *)data;
7282 g_return_if_fail (path != NULL);
7284 gtk_tree_row_reference_deleted (G_OBJECT (data), path);
7286 _pspp_sheet_view_find_node (tree_view, path, &node);
7291 range_tower_delete (tree_view->priv->selected, node, 1);
7293 /* Ensure we don't have a dangling pointer to a dead node */
7294 ensure_unprelighted (tree_view);
7296 /* Cancel editting if we've started */
7297 pspp_sheet_view_stop_editing (tree_view, TRUE);
7299 if (tree_view->priv->destroy_count_func)
7301 gint child_count = 0;
7302 tree_view->priv->destroy_count_func (tree_view, path, child_count, tree_view->priv->destroy_count_data);
7305 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7307 if (! gtk_tree_row_reference_valid (tree_view->priv->top_row))
7309 gtk_tree_row_reference_free (tree_view->priv->top_row);
7310 tree_view->priv->top_row = NULL;
7313 install_scroll_sync_handler (tree_view);
7315 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7318 if (helper_data.changed)
7319 g_signal_emit_by_name (tree_view->priv->selection, "changed");
7324 pspp_sheet_view_rows_reordered (GtkTreeModel *model,
7325 GtkTreePath *parent,
7330 PsppSheetView *tree_view = PSPP_SHEET_VIEW (data);
7333 /* XXX need to adjust selection */
7334 len = gtk_tree_model_iter_n_children (model, iter);
7339 gtk_tree_row_reference_reordered (G_OBJECT (data),
7344 if (gtk_tree_path_get_depth (parent) != 0)
7347 if (tree_view->priv->edited_column)
7348 pspp_sheet_view_stop_editing (tree_view, TRUE);
7350 /* we need to be unprelighted */
7351 ensure_unprelighted (tree_view);
7353 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
7355 pspp_sheet_view_dy_to_top_row (tree_view);
7359 /* Internal tree functions
7364 pspp_sheet_view_get_background_xrange (PsppSheetView *tree_view,
7365 PsppSheetViewColumn *column,
7369 PsppSheetViewColumn *tmp_column = NULL;
7380 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7383 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
7385 list = (rtl ? list->prev : list->next))
7387 tmp_column = list->data;
7389 if (tmp_column == column)
7392 if (tmp_column->visible)
7393 total_width += tmp_column->width;
7396 if (tmp_column != column)
7398 g_warning (G_STRLOC": passed-in column isn't in the tree");
7407 if (column->visible)
7408 *x2 = total_width + column->width;
7410 *x2 = total_width; /* width of 0 */
7414 /* Make sure the node is visible vertically */
7416 pspp_sheet_view_clamp_node_visible (PsppSheetView *tree_view,
7419 gint node_dy, height;
7420 GtkTreePath *path = NULL;
7422 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7425 /* just return if the node is visible, avoiding a costly expose */
7426 node_dy = pspp_sheet_view_node_find_offset (tree_view, node);
7427 height = ROW_HEIGHT (tree_view);
7428 if (node_dy >= gtk_adjustment_get_value (tree_view->priv->vadjustment)
7429 && node_dy + height <= (gtk_adjustment_get_value (tree_view->priv->vadjustment)
7430 + gtk_adjustment_get_page_size (tree_view->priv->vadjustment)))
7433 path = _pspp_sheet_view_find_path (tree_view, node);
7436 /* We process updates because we want to clear old selected items when we scroll.
7437 * if this is removed, we get a "selection streak" at the bottom. */
7438 gdk_window_process_updates (tree_view->priv->bin_window, TRUE);
7439 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL, FALSE, 0.0, 0.0);
7440 gtk_tree_path_free (path);
7445 pspp_sheet_view_clamp_column_visible (PsppSheetView *tree_view,
7446 PsppSheetViewColumn *column,
7447 gboolean focus_to_cell)
7454 x = column->allocation.x;
7455 width = column->allocation.width;
7457 if (width > gtk_adjustment_get_page_size (tree_view->priv->hadjustment))
7459 /* The column is larger than the horizontal page size. If the
7460 * column has cells which can be focussed individually, then we make
7461 * sure the cell which gets focus is fully visible (if even the
7462 * focus cell is bigger than the page size, we make sure the
7463 * left-hand side of the cell is visible).
7465 * If the column does not have those so-called special cells, we
7466 * make sure the left-hand side of the column is visible.
7469 if (focus_to_cell && pspp_sheet_view_has_special_cell (tree_view))
7471 GtkTreePath *cursor_path;
7472 GdkRectangle background_area, cell_area, focus_area;
7474 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7476 pspp_sheet_view_get_cell_area (tree_view,
7477 cursor_path, column, &cell_area);
7478 pspp_sheet_view_get_background_area (tree_view,
7479 cursor_path, column,
7482 gtk_tree_path_free (cursor_path);
7484 _pspp_sheet_view_column_get_focus_area (column,
7490 width = focus_area.width;
7492 if (width < gtk_adjustment_get_page_size (tree_view->priv->hadjustment))
7494 if ((gtk_adjustment_get_value (tree_view->priv->hadjustment) + gtk_adjustment_get_page_size (tree_view->priv->hadjustment)) < (x + width))
7495 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7496 x + width - gtk_adjustment_get_page_size (tree_view->priv->hadjustment));
7497 else if (gtk_adjustment_get_value (tree_view->priv->hadjustment) > x)
7498 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7502 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7504 gtk_adjustment_get_lower (tree_view->priv->hadjustment),
7505 gtk_adjustment_get_upper (tree_view->priv->hadjustment)
7506 - gtk_adjustment_get_page_size (tree_view->priv->hadjustment)));
7510 if ((gtk_adjustment_get_value (tree_view->priv->hadjustment) + gtk_adjustment_get_page_size (tree_view->priv->hadjustment)) < (x + width))
7511 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7512 x + width - gtk_adjustment_get_page_size (tree_view->priv->hadjustment));
7513 else if (gtk_adjustment_get_value (tree_view->priv->hadjustment) > x)
7514 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7519 _pspp_sheet_view_find_path (PsppSheetView *tree_view,
7524 path = gtk_tree_path_new ();
7526 gtk_tree_path_append_index (path, node);
7531 _pspp_sheet_view_find_node (PsppSheetView *tree_view,
7535 gint *indices = gtk_tree_path_get_indices (path);
7536 gint depth = gtk_tree_path_get_depth (path);
7539 if (depth == 0 || indices[0] < 0 || indices[0] >= tree_view->priv->row_count)
7545 pspp_sheet_view_add_move_binding (GtkBindingSet *binding_set,
7548 gboolean add_shifted_binding,
7549 GtkMovementStep step,
7553 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
7558 if (add_shifted_binding)
7559 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
7564 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
7567 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
7572 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
7579 pspp_sheet_view_set_column_drag_info (PsppSheetView *tree_view,
7580 PsppSheetViewColumn *column)
7582 PsppSheetViewColumn *left_column;
7583 PsppSheetViewColumn *cur_column = NULL;
7584 PsppSheetViewColumnReorder *reorder;
7589 /* We want to precalculate the motion list such that we know what column slots
7593 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7595 /* First, identify all possible drop spots */
7597 tmp_list = g_list_last (tree_view->priv->columns);
7599 tmp_list = g_list_first (tree_view->priv->columns);
7603 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
7604 tmp_list = rtl?g_list_previous (tmp_list):g_list_next (tmp_list);
7606 if (cur_column->visible == FALSE)
7609 /* If it's not the column moving and func tells us to skip over the column, we continue. */
7610 if (left_column != column && cur_column != column &&
7611 tree_view->priv->column_drop_func &&
7612 ! tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
7614 left_column = cur_column;
7617 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7618 reorder->left_column = left_column;
7619 left_column = reorder->right_column = cur_column;
7621 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7624 /* Add the last one */
7625 if (tree_view->priv->column_drop_func == NULL ||
7626 ((left_column != column) &&
7627 tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data)))
7629 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7630 reorder->left_column = left_column;
7631 reorder->right_column = NULL;
7632 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7635 /* We quickly check to see if it even makes sense to reorder columns. */
7636 /* If there is nothing that can be moved, then we return */
7638 if (tree_view->priv->column_drag_info == NULL)
7641 /* We know there are always 2 slots possbile, as you can always return column. */
7642 /* If that's all there is, return */
7643 if (tree_view->priv->column_drag_info->next == NULL ||
7644 (tree_view->priv->column_drag_info->next->next == NULL &&
7645 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->data)->right_column == column &&
7646 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->next->data)->left_column == column))
7648 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7649 g_slice_free (PsppSheetViewColumnReorder, tmp_list->data);
7650 g_list_free (tree_view->priv->column_drag_info);
7651 tree_view->priv->column_drag_info = NULL;
7654 /* We fill in the ranges for the columns, now that we've isolated them */
7655 left = - TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7657 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7659 reorder = (PsppSheetViewColumnReorder *) tmp_list->data;
7661 reorder->left_align = left;
7662 if (tmp_list->next != NULL)
7664 g_assert (tmp_list->next->data);
7665 left = reorder->right_align = (reorder->right_column->allocation.x +
7666 reorder->right_column->allocation.width +
7667 ((PsppSheetViewColumnReorder *)tmp_list->next->data)->left_column->allocation.x)/2;
7671 gint width = gdk_window_get_width (tree_view->priv->header_window);
7672 reorder->right_align = width + TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7678 _pspp_sheet_view_column_start_drag (PsppSheetView *tree_view,
7679 PsppSheetViewColumn *column)
7681 GdkEvent *send_event;
7682 GtkAllocation allocation;
7684 GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
7685 GdkDisplay *display = gdk_screen_get_display (screen);
7687 g_return_if_fail (tree_view->priv->column_drag_info == NULL);
7688 g_return_if_fail (tree_view->priv->cur_reorder == NULL);
7689 g_return_if_fail (column->button);
7691 pspp_sheet_view_set_column_drag_info (tree_view, column);
7693 if (tree_view->priv->column_drag_info == NULL)
7696 if (tree_view->priv->drag_window == NULL)
7698 GdkWindowAttr attributes;
7699 guint attributes_mask;
7701 attributes.window_type = GDK_WINDOW_CHILD;
7702 attributes.wclass = GDK_INPUT_OUTPUT;
7703 attributes.x = column->allocation.x;
7705 attributes.width = column->allocation.width;
7706 attributes.height = column->allocation.height;
7707 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
7708 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
7709 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
7710 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
7712 tree_view->priv->drag_window = gdk_window_new (tree_view->priv->bin_window,
7715 gdk_window_set_user_data (tree_view->priv->drag_window, GTK_WIDGET (tree_view));
7718 gdk_display_pointer_ungrab (display, GDK_CURRENT_TIME);
7719 gdk_display_keyboard_ungrab (display, GDK_CURRENT_TIME);
7721 gtk_grab_remove (column->button);
7723 send_event = gdk_event_new (GDK_LEAVE_NOTIFY);
7724 send_event->crossing.send_event = TRUE;
7725 send_event->crossing.window = g_object_ref (gtk_button_get_event_window (GTK_BUTTON (column->button)));
7726 send_event->crossing.subwindow = NULL;
7727 send_event->crossing.detail = GDK_NOTIFY_ANCESTOR;
7728 send_event->crossing.time = GDK_CURRENT_TIME;
7730 gtk_propagate_event (column->button, send_event);
7731 gdk_event_free (send_event);
7733 send_event = gdk_event_new (GDK_BUTTON_RELEASE);
7734 send_event->button.window = g_object_ref (gdk_screen_get_root_window (screen));
7735 send_event->button.send_event = TRUE;
7736 send_event->button.time = GDK_CURRENT_TIME;
7737 send_event->button.x = -1;
7738 send_event->button.y = -1;
7739 send_event->button.axes = NULL;
7740 send_event->button.state = 0;
7741 send_event->button.button = 1;
7742 send_event->button.device = gdk_display_get_core_pointer (display);
7743 send_event->button.x_root = 0;
7744 send_event->button.y_root = 0;
7746 gtk_propagate_event (column->button, send_event);
7747 gdk_event_free (send_event);
7749 /* Kids, don't try this at home */
7750 g_object_ref (column->button);
7751 gtk_container_remove (GTK_CONTAINER (tree_view), column->button);
7752 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7753 gtk_widget_set_parent (column->button, GTK_WIDGET (tree_view));
7754 g_object_unref (column->button);
7756 tree_view->priv->drag_column_x = column->allocation.x;
7757 allocation = column->allocation;
7759 gtk_widget_size_allocate (column->button, &allocation);
7760 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7762 tree_view->priv->drag_column = column;
7763 gdk_window_show (tree_view->priv->drag_window);
7765 gdk_window_get_origin (tree_view->priv->header_window, &x, &y);
7767 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7768 while (gtk_events_pending ())
7769 gtk_main_iteration ();
7771 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG);
7772 gdk_pointer_grab (tree_view->priv->drag_window,
7774 GDK_POINTER_MOTION_MASK|GDK_BUTTON_RELEASE_MASK,
7775 NULL, NULL, GDK_CURRENT_TIME);
7776 gdk_keyboard_grab (tree_view->priv->drag_window,
7782 _pspp_sheet_view_queue_draw_node (PsppSheetView *tree_view,
7784 const GdkRectangle *clip_rect)
7787 GtkAllocation allocation;
7789 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7792 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
7794 rect.width = MAX (tree_view->priv->width, allocation.width);
7796 rect.y = BACKGROUND_FIRST_PIXEL (tree_view, node);
7797 rect.height = ROW_HEIGHT (tree_view);
7801 GdkRectangle new_rect;
7803 gdk_rectangle_intersect (clip_rect, &rect, &new_rect);
7805 gdk_window_invalidate_rect (tree_view->priv->bin_window, &new_rect, TRUE);
7809 gdk_window_invalidate_rect (tree_view->priv->bin_window, &rect, TRUE);
7814 pspp_sheet_view_queue_draw_path (PsppSheetView *tree_view,
7816 const GdkRectangle *clip_rect)
7820 _pspp_sheet_view_find_node (tree_view, path, &node);
7823 _pspp_sheet_view_queue_draw_node (tree_view, node, clip_rect);
7827 pspp_sheet_view_focus_to_cursor (PsppSheetView *tree_view)
7830 GtkTreePath *cursor_path;
7832 if ((tree_view->priv->row_count == 0) ||
7833 (! gtk_widget_get_realized (GTK_WIDGET (tree_view))))
7837 if (tree_view->priv->cursor)
7838 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7840 if (cursor_path == NULL)
7842 /* There's no cursor. Move the cursor to the first selected row, if any
7843 * are selected, otherwise to the first row in the sheetview.
7845 GList *selected_rows;
7846 GtkTreeModel *model;
7847 PsppSheetSelection *selection;
7849 selection = pspp_sheet_view_get_selection (tree_view);
7850 selected_rows = pspp_sheet_selection_get_selected_rows (selection, &model);
7854 /* XXX we could avoid doing O(n) work to get this result */
7855 cursor_path = gtk_tree_path_copy((const GtkTreePath *)(selected_rows->data));
7856 g_list_foreach (selected_rows, (GFunc)gtk_tree_path_free, NULL);
7857 g_list_free (selected_rows);
7861 cursor_path = gtk_tree_path_new_first ();
7862 search_first_focusable_path (tree_view, &cursor_path,
7866 gtk_tree_row_reference_free (tree_view->priv->cursor);
7867 tree_view->priv->cursor = NULL;
7871 if (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7872 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE)
7873 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, FALSE, FALSE, 0);
7875 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE, 0);
7881 /* Now find a column for the cursor. */
7882 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
7884 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
7885 gtk_tree_path_free (cursor_path);
7887 if (tree_view->priv->focus_column == NULL)
7890 for (list = tree_view->priv->columns; list; list = list->next)
7892 if (PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
7894 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
7895 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
7896 pspp_sheet_selection_select_column (tree_view->priv->selection, tree_view->priv->focus_column);
7906 pspp_sheet_view_move_cursor_up_down (PsppSheetView *tree_view,
7908 PsppSheetSelectMode mode)
7910 gint selection_count;
7911 int cursor_node = -1;
7912 int new_cursor_node = -1;
7913 GtkTreePath *cursor_path = NULL;
7914 gboolean grab_focus = TRUE;
7916 if (! gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7920 if (!gtk_tree_row_reference_valid (tree_view->priv->cursor))
7921 /* FIXME: we lost the cursor; should we get the first? */
7924 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7925 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
7927 if (cursor_node < 0)
7928 /* FIXME: we lost the cursor; should we get the first? */
7931 selection_count = pspp_sheet_selection_count_selected_rows (tree_view->priv->selection);
7933 if (selection_count == 0
7934 && tree_view->priv->selection->type != PSPP_SHEET_SELECTION_NONE
7935 && !(mode & PSPP_SHEET_SELECT_MODE_TOGGLE))
7937 /* Don't move the cursor, but just select the current node */
7938 new_cursor_node = cursor_node;
7943 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
7945 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7948 gtk_tree_path_free (cursor_path);
7950 if (new_cursor_node)
7952 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
7954 search_first_focusable_path (tree_view, &cursor_path,
7959 gtk_tree_path_free (cursor_path);
7963 * If the list has only one item and multi-selection is set then select
7964 * the row (if not yet selected).
7966 if ((tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7967 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE) &&
7968 new_cursor_node < 0)
7971 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7973 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
7975 if (new_cursor_node < 0
7976 && !pspp_sheet_view_node_is_selected (tree_view, cursor_node))
7978 new_cursor_node = cursor_node;
7982 new_cursor_node = -1;
7986 if (new_cursor_node >= 0)
7988 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
7989 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, TRUE, mode);
7990 gtk_tree_path_free (cursor_path);
7994 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
7996 if (!(mode & PSPP_SHEET_SELECT_MODE_EXTEND))
7998 if (! gtk_widget_keynav_failed (GTK_WIDGET (tree_view),
8000 GTK_DIR_UP : GTK_DIR_DOWN))
8002 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
8005 gtk_widget_child_focus (toplevel,
8007 GTK_DIR_TAB_BACKWARD :
8008 GTK_DIR_TAB_FORWARD);
8015 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8020 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8022 return new_cursor_node >= 0;
8026 pspp_sheet_view_move_cursor_page_up_down (PsppSheetView *tree_view,
8028 PsppSheetSelectMode mode)
8030 int cursor_node = -1;
8031 GtkTreePath *old_cursor_path = NULL;
8032 GtkTreePath *cursor_path = NULL;
8033 int start_cursor_node = -1;
8036 gint vertical_separator;
8038 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8041 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8042 old_cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8044 /* This is sorta weird. Focus in should give us a cursor */
8047 gtk_widget_style_get (GTK_WIDGET (tree_view), "vertical-separator", &vertical_separator, NULL);
8048 _pspp_sheet_view_find_node (tree_view, old_cursor_path, &cursor_node);
8050 if (cursor_node < 0)
8052 /* FIXME: we lost the cursor. Should we try to get one? */
8053 gtk_tree_path_free (old_cursor_path);
8057 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
8058 window_y = RBTREE_Y_TO_TREE_WINDOW_Y (tree_view, y);
8059 y += tree_view->priv->cursor_offset;
8060 y += count * (int)gtk_adjustment_get_page_increment (tree_view->priv->vadjustment);
8061 y = CLAMP (y, (gint)gtk_adjustment_get_lower (tree_view->priv->vadjustment), (gint)gtk_adjustment_get_upper (tree_view->priv->vadjustment) - vertical_separator);
8063 if (y >= tree_view->priv->height)
8064 y = tree_view->priv->height - 1;
8066 tree_view->priv->cursor_offset =
8067 pspp_sheet_view_find_offset (tree_view, y, &cursor_node);
8069 if (tree_view->priv->cursor_offset > BACKGROUND_HEIGHT (tree_view))
8071 cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
8072 tree_view->priv->cursor_offset -= BACKGROUND_HEIGHT (tree_view);
8075 y -= tree_view->priv->cursor_offset;
8076 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
8078 start_cursor_node = cursor_node;
8080 if (! search_first_focusable_path (tree_view, &cursor_path,
8084 /* It looks like we reached the end of the view without finding
8085 * a focusable row. We will step backwards to find the last
8088 cursor_node = start_cursor_node;
8089 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
8091 search_first_focusable_path (tree_view, &cursor_path,
8100 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
8102 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE, mode);
8105 pspp_sheet_view_scroll_to_point (tree_view, -1, y);
8106 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8107 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8109 if (!gtk_tree_path_compare (old_cursor_path, cursor_path))
8110 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8112 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8115 gtk_tree_path_free (old_cursor_path);
8116 gtk_tree_path_free (cursor_path);
8120 pspp_sheet_view_move_cursor_left_right (PsppSheetView *tree_view,
8122 PsppSheetSelectMode mode)
8124 int cursor_node = -1;
8125 GtkTreePath *cursor_path = NULL;
8126 PsppSheetViewColumn *column;
8129 gboolean found_column = FALSE;
8132 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8134 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8137 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8138 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8142 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8143 if (cursor_node < 0)
8145 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8147 gtk_tree_path_free (cursor_path);
8150 gtk_tree_path_free (cursor_path);
8152 list = rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns);
8153 if (tree_view->priv->focus_column)
8155 for (; list; list = (rtl ? list->prev : list->next))
8157 if (list->data == tree_view->priv->focus_column)
8164 gboolean left, right;
8166 column = list->data;
8167 if (column->visible == FALSE || column->row_head)
8170 pspp_sheet_view_column_cell_set_cell_data (column,
8171 tree_view->priv->model,
8176 right = list->prev ? TRUE : FALSE;
8177 left = list->next ? TRUE : FALSE;
8181 left = list->prev ? TRUE : FALSE;
8182 right = list->next ? TRUE : FALSE;
8185 if (_pspp_sheet_view_column_cell_focus (column, count, left, right))
8187 tree_view->priv->focus_column = column;
8188 found_column = TRUE;
8193 list = rtl ? list->prev : list->next;
8195 list = rtl ? list->next : list->prev;
8200 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8201 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8202 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8206 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8209 pspp_sheet_view_clamp_column_visible (tree_view,
8210 tree_view->priv->focus_column, TRUE);
8214 pspp_sheet_view_move_cursor_line_start_end (PsppSheetView *tree_view,
8216 PsppSheetSelectMode mode)
8218 int cursor_node = -1;
8219 GtkTreePath *cursor_path = NULL;
8220 PsppSheetViewColumn *column;
8221 PsppSheetViewColumn *found_column;
8226 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8228 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8231 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8232 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8236 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8237 if (cursor_node < 0)
8239 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8241 gtk_tree_path_free (cursor_path);
8244 gtk_tree_path_free (cursor_path);
8246 list = rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns);
8247 if (tree_view->priv->focus_column)
8249 for (; list; list = (rtl ? list->prev : list->next))
8251 if (list->data == tree_view->priv->focus_column)
8256 found_column = NULL;
8259 gboolean left, right;
8261 column = list->data;
8262 if (column->visible == FALSE || column->row_head)
8265 pspp_sheet_view_column_cell_set_cell_data (column,
8266 tree_view->priv->model,
8271 right = list->prev ? TRUE : FALSE;
8272 left = list->next ? TRUE : FALSE;
8276 left = list->prev ? TRUE : FALSE;
8277 right = list->next ? TRUE : FALSE;
8280 if (column->tabbable
8281 && _pspp_sheet_view_column_cell_focus (column, count, left, right))
8282 found_column = column;
8286 list = rtl ? list->prev : list->next;
8288 list = rtl ? list->next : list->prev;
8293 tree_view->priv->focus_column = found_column;
8294 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8295 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8296 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8299 pspp_sheet_view_clamp_column_visible (tree_view,
8300 tree_view->priv->focus_column, TRUE);
8304 try_move_cursor_tab (PsppSheetView *tree_view,
8305 gboolean start_at_focus_column,
8308 PsppSheetViewColumn *column;
8310 int cursor_node = -1;
8311 GtkTreePath *cursor_path = NULL;
8315 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8316 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8320 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8321 if (cursor_node < 0)
8323 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8325 gtk_tree_path_free (cursor_path);
8328 gtk_tree_path_free (cursor_path);
8330 rtl = gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL;
8331 if (start_at_focus_column)
8334 ? g_list_last (tree_view->priv->columns)
8335 : g_list_first (tree_view->priv->columns));
8336 if (tree_view->priv->focus_column)
8338 for (; list; list = (rtl ? list->prev : list->next))
8340 if (list->data == tree_view->priv->focus_column)
8347 list = (rtl ^ (count == 1)
8348 ? g_list_first (tree_view->priv->columns)
8349 : g_list_last (tree_view->priv->columns));
8354 gboolean left, right;
8356 column = list->data;
8357 if (column->visible == FALSE || !column->tabbable)
8360 pspp_sheet_view_column_cell_set_cell_data (column,
8361 tree_view->priv->model,
8366 right = list->prev ? TRUE : FALSE;
8367 left = list->next ? TRUE : FALSE;
8371 left = list->prev ? TRUE : FALSE;
8372 right = list->next ? TRUE : FALSE;
8375 if (column->tabbable
8376 && _pspp_sheet_view_column_cell_focus (column, count, left, right))
8378 tree_view->priv->focus_column = column;
8379 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8380 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8381 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8386 list = rtl ? list->prev : list->next;
8388 list = rtl ? list->next : list->prev;
8395 pspp_sheet_view_move_cursor_tab (PsppSheetView *tree_view,
8398 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8401 if (!try_move_cursor_tab (tree_view, TRUE, count))
8403 if (pspp_sheet_view_move_cursor_up_down (tree_view, count, 0)
8404 && !try_move_cursor_tab (tree_view, FALSE, count))
8405 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8408 pspp_sheet_view_clamp_column_visible (tree_view,
8409 tree_view->priv->focus_column, TRUE);
8413 pspp_sheet_view_move_cursor_start_end (PsppSheetView *tree_view,
8415 PsppSheetSelectMode mode)
8419 GtkTreePath *old_path;
8421 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8424 g_return_if_fail (tree_view->priv->row_count > 0);
8426 pspp_sheet_view_get_cursor (tree_view, &old_path, NULL);
8430 /* Now go forward to find the first focusable row. */
8431 path = _pspp_sheet_view_find_path (tree_view, 0);
8432 search_first_focusable_path (tree_view, &path,
8433 TRUE, &cursor_node);
8437 /* Now go backwards to find last focusable row. */
8438 path = _pspp_sheet_view_find_path (tree_view, tree_view->priv->row_count - 1);
8439 search_first_focusable_path (tree_view, &path,
8440 FALSE, &cursor_node);
8446 if (gtk_tree_path_compare (old_path, path))
8448 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, mode);
8449 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8453 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8457 gtk_tree_path_free (old_path);
8458 gtk_tree_path_free (path);
8462 pspp_sheet_view_real_select_all (PsppSheetView *tree_view)
8464 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8467 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8468 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8471 pspp_sheet_selection_select_all (tree_view->priv->selection);
8477 pspp_sheet_view_real_unselect_all (PsppSheetView *tree_view)
8479 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8482 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8483 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8486 pspp_sheet_selection_unselect_all (tree_view->priv->selection);
8492 pspp_sheet_view_real_select_cursor_row (PsppSheetView *tree_view,
8493 gboolean start_editing,
8494 PsppSheetSelectMode mode)
8497 int cursor_node = -1;
8498 GtkTreePath *cursor_path = NULL;
8500 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8503 if (tree_view->priv->cursor)
8504 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8506 if (cursor_path == NULL)
8509 _pspp_sheet_view_find_node (tree_view, cursor_path,
8512 if (cursor_node < 0)
8514 gtk_tree_path_free (cursor_path);
8518 if (!(mode & PSPP_SHEET_SELECT_MODE_EXTEND) && start_editing &&
8519 tree_view->priv->focus_column)
8521 if (pspp_sheet_view_start_editing (tree_view, cursor_path))
8523 gtk_tree_path_free (cursor_path);
8528 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8534 /* We bail out if the original (tree, node) don't exist anymore after
8535 * handling the selection-changed callback. We do return TRUE because
8536 * the key press has been handled at this point.
8538 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8540 if (cursor_node != new_node)
8543 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8545 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8546 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8548 if (!(mode & PSPP_SHEET_SELECT_MODE_EXTEND))
8549 pspp_sheet_view_row_activated (tree_view, cursor_path,
8550 tree_view->priv->focus_column);
8552 gtk_tree_path_free (cursor_path);
8558 pspp_sheet_view_real_toggle_cursor_row (PsppSheetView *tree_view)
8561 int cursor_node = -1;
8562 GtkTreePath *cursor_path = NULL;
8564 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8568 if (tree_view->priv->cursor)
8569 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8571 if (cursor_path == NULL)
8574 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8575 if (cursor_node < 0)
8577 gtk_tree_path_free (cursor_path);
8581 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8584 PSPP_SHEET_SELECT_MODE_TOGGLE,
8587 /* We bail out if the original (tree, node) don't exist anymore after
8588 * handling the selection-changed callback. We do return TRUE because
8589 * the key press has been handled at this point.
8591 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8593 if (cursor_node != new_node)
8596 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8598 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8599 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
8600 gtk_tree_path_free (cursor_path);
8606 pspp_sheet_view_search_entry_flush_timeout (PsppSheetView *tree_view)
8608 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
8609 tree_view->priv->typeselect_flush_timeout = 0;
8614 /* Cut and paste from gtkwindow.c */
8616 send_focus_change (GtkWidget *widget,
8619 GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
8621 fevent->focus_change.type = GDK_FOCUS_CHANGE;
8622 fevent->focus_change.window = g_object_ref (gtk_widget_get_window (widget));
8623 fevent->focus_change.in = in;
8625 gtk_widget_send_focus_change (widget, fevent);
8626 gdk_event_free (fevent);
8630 pspp_sheet_view_ensure_interactive_directory (PsppSheetView *tree_view)
8632 GtkWidget *frame, *vbox, *toplevel;
8635 if (tree_view->priv->search_custom_entry_set)
8638 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
8639 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
8641 if (tree_view->priv->search_window != NULL)
8643 if (gtk_window_get_group (GTK_WINDOW (toplevel)))
8644 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
8645 GTK_WINDOW (tree_view->priv->search_window));
8646 else if (gtk_window_get_group (GTK_WINDOW (tree_view->priv->search_window)))
8647 gtk_window_group_remove_window (gtk_window_get_group (GTK_WINDOW (tree_view->priv->search_window)),
8648 GTK_WINDOW (tree_view->priv->search_window));
8649 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8653 tree_view->priv->search_window = gtk_window_new (GTK_WINDOW_POPUP);
8654 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8656 if (gtk_window_get_group (GTK_WINDOW (toplevel)))
8657 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
8658 GTK_WINDOW (tree_view->priv->search_window));
8660 gtk_window_set_type_hint (GTK_WINDOW (tree_view->priv->search_window),
8661 GDK_WINDOW_TYPE_HINT_UTILITY);
8662 gtk_window_set_modal (GTK_WINDOW (tree_view->priv->search_window), TRUE);
8663 g_signal_connect (tree_view->priv->search_window, "delete-event",
8664 G_CALLBACK (pspp_sheet_view_search_delete_event),
8666 g_signal_connect (tree_view->priv->search_window, "key-press-event",
8667 G_CALLBACK (pspp_sheet_view_search_key_press_event),
8669 g_signal_connect (tree_view->priv->search_window, "button-press-event",
8670 G_CALLBACK (pspp_sheet_view_search_button_press_event),
8672 g_signal_connect (tree_view->priv->search_window, "scroll-event",
8673 G_CALLBACK (pspp_sheet_view_search_scroll_event),
8676 frame = gtk_frame_new (NULL);
8677 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
8678 gtk_widget_show (frame);
8679 gtk_container_add (GTK_CONTAINER (tree_view->priv->search_window), frame);
8681 vbox = gtk_vbox_new (FALSE, 0);
8682 gtk_widget_show (vbox);
8683 gtk_container_add (GTK_CONTAINER (frame), vbox);
8684 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
8687 tree_view->priv->search_entry = gtk_entry_new ();
8688 gtk_widget_show (tree_view->priv->search_entry);
8689 g_signal_connect (tree_view->priv->search_entry, "populate-popup",
8690 G_CALLBACK (pspp_sheet_view_search_disable_popdown),
8692 g_signal_connect (tree_view->priv->search_entry,
8693 "activate", G_CALLBACK (pspp_sheet_view_search_activate),
8697 g_signal_connect (GTK_ENTRY (tree_view->priv->search_entry)->im_context,
8699 G_CALLBACK (pspp_sheet_view_search_preedit_changed),
8703 gtk_container_add (GTK_CONTAINER (vbox),
8704 tree_view->priv->search_entry);
8706 gtk_widget_realize (tree_view->priv->search_entry);
8709 /* Pops up the interactive search entry. If keybinding is TRUE then the user
8710 * started this by typing the start_interactive_search keybinding. Otherwise, it came from
8713 pspp_sheet_view_real_start_interactive_search (PsppSheetView *tree_view,
8714 gboolean keybinding)
8716 /* We only start interactive search if we have focus or the columns
8717 * have focus. If one of our children have focus, we don't want to
8721 gboolean found_focus = FALSE;
8722 GtkWidgetClass *entry_parent_class;
8724 if (!tree_view->priv->enable_search && !keybinding)
8727 if (tree_view->priv->search_custom_entry_set)
8730 if (tree_view->priv->search_window != NULL &&
8731 gtk_widget_get_visible (tree_view->priv->search_window))
8734 for (list = tree_view->priv->columns; list; list = list->next)
8736 PsppSheetViewColumn *column;
8738 column = list->data;
8739 if (! column->visible)
8742 if (column->button && gtk_widget_has_focus (column->button))
8749 if (gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8755 if (tree_view->priv->search_column < 0)
8758 pspp_sheet_view_ensure_interactive_directory (tree_view);
8761 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
8764 tree_view->priv->search_position_func (tree_view, tree_view->priv->search_window, tree_view->priv->search_position_user_data);
8765 gtk_widget_show (tree_view->priv->search_window);
8766 if (tree_view->priv->search_entry_changed_id == 0)
8768 tree_view->priv->search_entry_changed_id =
8769 g_signal_connect (tree_view->priv->search_entry, "changed",
8770 G_CALLBACK (pspp_sheet_view_search_init),
8774 tree_view->priv->typeselect_flush_timeout =
8775 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
8776 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
8779 /* Grab focus will select all the text. We don't want that to happen, so we
8780 * call the parent instance and bypass the selection change. This is probably
8781 * really non-kosher. */
8782 entry_parent_class = g_type_class_peek_parent (GTK_ENTRY_GET_CLASS (tree_view->priv->search_entry));
8783 (entry_parent_class->grab_focus) (tree_view->priv->search_entry);
8785 /* send focus-in event */
8786 send_focus_change (tree_view->priv->search_entry, TRUE);
8788 /* search first matching iter */
8789 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
8795 pspp_sheet_view_start_interactive_search (PsppSheetView *tree_view)
8797 return pspp_sheet_view_real_start_interactive_search (tree_view, TRUE);
8800 /* this function returns the new width of the column being resized given
8801 * the column and x position of the cursor; the x cursor position is passed
8802 * in as a pointer and automagicly corrected if it's beyond min/max limits
8805 pspp_sheet_view_new_column_width (PsppSheetView *tree_view,
8809 PsppSheetViewColumn *column;
8813 /* first translate the x position from gtk_widget_get_window (widget)
8814 * to clist->clist_window
8816 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8817 column = g_list_nth (tree_view->priv->columns, i)->data;
8818 width = rtl ? (column->allocation.x + column->allocation.width - *x) : (*x - column->allocation.x);
8820 /* Clamp down the value */
8821 if (column->min_width == -1)
8822 width = MAX (column->button_request, width);
8824 width = MAX (column->min_width, width);
8825 if (column->max_width != -1)
8826 width = MIN (width, column->max_width);
8828 *x = rtl ? (column->allocation.x + column->allocation.width - width) : (column->allocation.x + width);
8834 /* FIXME this adjust_allocation is a big cut-and-paste from
8835 * GtkCList, needs to be some "official" way to do this
8845 /* The window to which gtk_widget_get_window (widget) is relative */
8846 #define ALLOCATION_WINDOW(widget) \
8847 (!gtk_widget_get_has_window (widget) ? \
8848 gtk_widget_get_window (widget) : \
8849 gdk_window_get_parent (gtk_widget_get_window (widget)))
8852 adjust_allocation_recurse (GtkWidget *widget,
8855 ScrollData *scroll_data = data;
8856 GtkAllocation allocation;
8857 gtk_widget_get_allocation (widget, &allocation);
8858 /* Need to really size allocate instead of just poking
8859 * into widget->allocation if the widget is not realized.
8860 * FIXME someone figure out why this was.
8862 if (!gtk_widget_get_realized (widget))
8864 if (gtk_widget_get_visible (widget))
8866 GdkRectangle tmp_rectangle = allocation;
8867 tmp_rectangle.x += scroll_data->dx;
8868 tmp_rectangle.y += scroll_data->dy;
8870 gtk_widget_size_allocate (widget, &tmp_rectangle);
8875 if (ALLOCATION_WINDOW (widget) == scroll_data->window)
8877 allocation.x += scroll_data->dx;
8878 allocation.y += scroll_data->dy;
8880 if (GTK_IS_CONTAINER (widget))
8881 gtk_container_forall (GTK_CONTAINER (widget),
8882 adjust_allocation_recurse,
8889 adjust_allocation (GtkWidget *widget,
8893 ScrollData scroll_data;
8895 if (gtk_widget_get_realized (widget))
8896 scroll_data.window = ALLOCATION_WINDOW (widget);
8898 scroll_data.window = NULL;
8900 scroll_data.dx = dx;
8901 scroll_data.dy = dy;
8903 adjust_allocation_recurse (widget, &scroll_data);
8907 pspp_sheet_view_column_update_button (PsppSheetViewColumn *tree_column);
8911 pspp_sheet_view_adjustment_changed (GtkAdjustment *adjustment,
8912 PsppSheetView *tree_view)
8914 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
8919 gdk_window_move (tree_view->priv->bin_window,
8920 - gtk_adjustment_get_value (tree_view->priv->hadjustment),
8921 TREE_VIEW_HEADER_HEIGHT (tree_view));
8922 gdk_window_move (tree_view->priv->header_window,
8923 - gtk_adjustment_get_value (tree_view->priv->hadjustment),
8925 dy = tree_view->priv->dy - (int) gtk_adjustment_get_value (tree_view->priv->vadjustment);
8928 update_prelight (tree_view,
8929 tree_view->priv->event_last_x,
8930 tree_view->priv->event_last_y - dy);
8932 if (tree_view->priv->edited_column &&
8933 GTK_IS_WIDGET (tree_view->priv->edited_column->editable_widget))
8937 PsppSheetViewChild *child = NULL;
8939 widget = GTK_WIDGET (tree_view->priv->edited_column->editable_widget);
8940 adjust_allocation (widget, 0, dy);
8942 for (list = tree_view->priv->children; list; list = list->next)
8944 child = (PsppSheetViewChild *)list->data;
8945 if (child->widget == widget)
8953 gdk_window_scroll (tree_view->priv->bin_window, 0, dy);
8955 if (tree_view->priv->dy != (int) gtk_adjustment_get_value (tree_view->priv->vadjustment))
8957 /* update our dy and top_row */
8958 tree_view->priv->dy = (int) gtk_adjustment_get_value (tree_view->priv->vadjustment);
8960 if (!tree_view->priv->in_top_row_to_dy)
8961 pspp_sheet_view_dy_to_top_row (tree_view);
8964 for (list = tree_view->priv->columns; list; list = list->next)
8966 PsppSheetViewColumn *column = list->data;
8967 GtkAllocation *col_allocation = &column->allocation;
8968 GtkAllocation widget_allocation;
8969 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &widget_allocation);
8971 if (span_intersects (col_allocation->x, col_allocation->width,
8972 gtk_adjustment_get_value (tree_view->priv->hadjustment),
8973 widget_allocation.width))
8975 pspp_sheet_view_column_set_need_button (column, TRUE);
8976 if (!column->button)
8977 pspp_sheet_view_column_update_button (column);
8989 * pspp_sheet_view_new:
8991 * Creates a new #PsppSheetView widget.
8993 * Return value: A newly created #PsppSheetView widget.
8996 pspp_sheet_view_new (void)
8998 return g_object_new (PSPP_TYPE_SHEET_VIEW, NULL);
9002 * pspp_sheet_view_new_with_model:
9003 * @model: the model.
9005 * Creates a new #PsppSheetView widget with the model initialized to @model.
9007 * Return value: A newly created #PsppSheetView widget.
9010 pspp_sheet_view_new_with_model (GtkTreeModel *model)
9012 return g_object_new (PSPP_TYPE_SHEET_VIEW, "model", model, NULL);
9019 * pspp_sheet_view_get_model:
9020 * @tree_view: a #PsppSheetView
9022 * Returns the model the #PsppSheetView is based on. Returns %NULL if the
9025 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
9028 pspp_sheet_view_get_model (PsppSheetView *tree_view)
9030 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9032 return tree_view->priv->model;
9036 * pspp_sheet_view_set_model:
9037 * @tree_view: A #GtkTreeNode.
9038 * @model: (allow-none): The model.
9040 * Sets the model for a #PsppSheetView. If the @tree_view already has a model
9041 * set, it will remove it before setting the new model. If @model is %NULL,
9042 * then it will unset the old model.
9045 pspp_sheet_view_set_model (PsppSheetView *tree_view,
9046 GtkTreeModel *model)
9048 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9049 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
9051 if (model == tree_view->priv->model)
9054 if (tree_view->priv->scroll_to_path)
9056 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9057 tree_view->priv->scroll_to_path = NULL;
9060 if (tree_view->priv->model)
9062 GList *tmplist = tree_view->priv->columns;
9064 if (tree_view->priv->selected)
9065 range_tower_set0 (tree_view->priv->selected, 0, ULONG_MAX);
9066 pspp_sheet_view_stop_editing (tree_view, TRUE);
9068 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9069 pspp_sheet_view_row_changed,
9071 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9072 pspp_sheet_view_row_inserted,
9074 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9075 pspp_sheet_view_row_deleted,
9077 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9078 pspp_sheet_view_rows_reordered,
9081 for (; tmplist; tmplist = tmplist->next)
9082 _pspp_sheet_view_column_unset_model (tmplist->data,
9083 tree_view->priv->model);
9085 tree_view->priv->prelight_node = -1;
9087 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
9088 tree_view->priv->drag_dest_row = NULL;
9089 gtk_tree_row_reference_free (tree_view->priv->cursor);
9090 tree_view->priv->cursor = NULL;
9091 gtk_tree_row_reference_free (tree_view->priv->anchor);
9092 tree_view->priv->anchor = NULL;
9093 gtk_tree_row_reference_free (tree_view->priv->top_row);
9094 tree_view->priv->top_row = NULL;
9095 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9096 tree_view->priv->scroll_to_path = NULL;
9098 tree_view->priv->scroll_to_column = NULL;
9100 g_object_unref (tree_view->priv->model);
9102 tree_view->priv->search_column = -1;
9103 tree_view->priv->fixed_height = -1;
9104 tree_view->priv->dy = tree_view->priv->top_row_dy = 0;
9105 tree_view->priv->last_button_x = -1;
9106 tree_view->priv->last_button_y = -1;
9109 tree_view->priv->model = model;
9111 if (tree_view->priv->model)
9115 if (tree_view->priv->search_column == -1)
9117 for (i = 0; i < gtk_tree_model_get_n_columns (model); i++)
9119 GType type = gtk_tree_model_get_column_type (model, i);
9121 if (g_value_type_transformable (type, G_TYPE_STRING))
9123 tree_view->priv->search_column = i;
9129 g_object_ref (tree_view->priv->model);
9130 g_signal_connect (tree_view->priv->model,
9132 G_CALLBACK (pspp_sheet_view_row_changed),
9134 g_signal_connect (tree_view->priv->model,
9136 G_CALLBACK (pspp_sheet_view_row_inserted),
9138 g_signal_connect (tree_view->priv->model,
9140 G_CALLBACK (pspp_sheet_view_row_deleted),
9142 g_signal_connect (tree_view->priv->model,
9144 G_CALLBACK (pspp_sheet_view_rows_reordered),
9147 tree_view->priv->row_count = gtk_tree_model_iter_n_children (tree_view->priv->model, NULL);
9149 /* FIXME: do I need to do this? pspp_sheet_view_create_buttons (tree_view); */
9150 install_presize_handler (tree_view);
9153 g_object_notify (G_OBJECT (tree_view), "model");
9155 if (tree_view->priv->selection)
9156 _pspp_sheet_selection_emit_changed (tree_view->priv->selection);
9158 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9159 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9163 * pspp_sheet_view_get_selection:
9164 * @tree_view: A #PsppSheetView.
9166 * Gets the #PsppSheetSelection associated with @tree_view.
9168 * Return value: A #PsppSheetSelection object.
9170 PsppSheetSelection *
9171 pspp_sheet_view_get_selection (PsppSheetView *tree_view)
9173 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9175 return tree_view->priv->selection;
9179 * pspp_sheet_view_get_hadjustment:
9180 * @tree_view: A #PsppSheetView
9182 * Gets the #GtkAdjustment currently being used for the horizontal aspect.
9184 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
9188 pspp_sheet_view_get_hadjustment (PsppSheetView *tree_view)
9190 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9192 if (tree_view->priv->hadjustment == NULL)
9193 pspp_sheet_view_set_hadjustment (tree_view, NULL);
9195 return tree_view->priv->hadjustment;
9199 * pspp_sheet_view_set_hadjustment:
9200 * @tree_view: A #PsppSheetView
9201 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
9203 * Sets the #GtkAdjustment for the current horizontal aspect.
9206 pspp_sheet_view_set_hadjustment (PsppSheetView *tree_view,
9207 GtkAdjustment *adjustment)
9209 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9211 pspp_sheet_view_set_adjustments (tree_view,
9213 tree_view->priv->vadjustment);
9215 g_object_notify (G_OBJECT (tree_view), "hadjustment");
9219 * pspp_sheet_view_get_vadjustment:
9220 * @tree_view: A #PsppSheetView
9222 * Gets the #GtkAdjustment currently being used for the vertical aspect.
9224 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
9228 pspp_sheet_view_get_vadjustment (PsppSheetView *tree_view)
9230 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9232 if (tree_view->priv->vadjustment == NULL)
9233 pspp_sheet_view_set_vadjustment (tree_view, NULL);
9235 return tree_view->priv->vadjustment;
9239 * pspp_sheet_view_set_vadjustment:
9240 * @tree_view: A #PsppSheetView
9241 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
9243 * Sets the #GtkAdjustment for the current vertical aspect.
9246 pspp_sheet_view_set_vadjustment (PsppSheetView *tree_view,
9247 GtkAdjustment *adjustment)
9249 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9251 pspp_sheet_view_set_adjustments (tree_view,
9252 tree_view->priv->hadjustment,
9255 g_object_notify (G_OBJECT (tree_view), "vadjustment");
9258 /* Column and header operations */
9261 * pspp_sheet_view_get_headers_visible:
9262 * @tree_view: A #PsppSheetView.
9264 * Returns %TRUE if the headers on the @tree_view are visible.
9266 * Return value: Whether the headers are visible or not.
9269 pspp_sheet_view_get_headers_visible (PsppSheetView *tree_view)
9271 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9273 return PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9277 * pspp_sheet_view_set_headers_visible:
9278 * @tree_view: A #PsppSheetView.
9279 * @headers_visible: %TRUE if the headers are visible
9281 * Sets the visibility state of the headers.
9284 pspp_sheet_view_set_headers_visible (PsppSheetView *tree_view,
9285 gboolean headers_visible)
9289 PsppSheetViewColumn *column;
9290 GtkAllocation allocation;
9292 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9294 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
9296 headers_visible = !! headers_visible;
9298 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE) == headers_visible)
9301 if (headers_visible)
9302 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9304 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9306 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9308 gdk_window_get_position (tree_view->priv->bin_window, &x, &y);
9309 if (headers_visible)
9311 gdk_window_move_resize (tree_view->priv->bin_window, x, y + TREE_VIEW_HEADER_HEIGHT (tree_view),
9312 tree_view->priv->width, allocation.height - + TREE_VIEW_HEADER_HEIGHT (tree_view));
9314 if (gtk_widget_get_mapped (GTK_WIDGET (tree_view)))
9315 pspp_sheet_view_map_buttons (tree_view);
9319 gdk_window_move_resize (tree_view->priv->bin_window, x, y, tree_view->priv->width, tree_view->priv->height);
9321 for (list = tree_view->priv->columns; list; list = list->next)
9323 column = list->data;
9325 gtk_widget_unmap (column->button);
9327 gdk_window_hide (tree_view->priv->header_window);
9331 gtk_adjustment_set_page_size (tree_view->priv->vadjustment, allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view));
9332 gtk_adjustment_set_page_increment (tree_view->priv->vadjustment, (allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view)) / 2);
9333 gtk_adjustment_set_lower (tree_view->priv->vadjustment, 0);
9334 gtk_adjustment_set_upper (tree_view->priv->vadjustment, tree_view->priv->height);
9335 gtk_adjustment_changed (tree_view->priv->vadjustment);
9337 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9339 g_object_notify (G_OBJECT (tree_view), "headers-visible");
9343 * pspp_sheet_view_columns_autosize:
9344 * @tree_view: A #PsppSheetView.
9346 * Resizes all columns to their optimal width. Only works after the
9347 * treeview has been realized.
9350 pspp_sheet_view_columns_autosize (PsppSheetView *tree_view)
9352 gboolean dirty = FALSE;
9354 PsppSheetViewColumn *column;
9356 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9358 for (list = tree_view->priv->columns; list; list = list->next)
9360 column = list->data;
9361 _pspp_sheet_view_column_cell_set_dirty (column);
9366 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9370 * pspp_sheet_view_set_headers_clickable:
9371 * @tree_view: A #PsppSheetView.
9372 * @setting: %TRUE if the columns are clickable.
9374 * Allow the column title buttons to be clicked.
9377 pspp_sheet_view_set_headers_clickable (PsppSheetView *tree_view,
9382 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9384 for (list = tree_view->priv->columns; list; list = list->next)
9385 pspp_sheet_view_column_set_clickable (PSPP_SHEET_VIEW_COLUMN (list->data), setting);
9387 g_object_notify (G_OBJECT (tree_view), "headers-clickable");
9392 * pspp_sheet_view_get_headers_clickable:
9393 * @tree_view: A #PsppSheetView.
9395 * Returns whether all header columns are clickable.
9397 * Return value: %TRUE if all header columns are clickable, otherwise %FALSE
9402 pspp_sheet_view_get_headers_clickable (PsppSheetView *tree_view)
9406 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9408 for (list = tree_view->priv->columns; list; list = list->next)
9409 if (!PSPP_SHEET_VIEW_COLUMN (list->data)->clickable)
9416 * pspp_sheet_view_set_rules_hint
9417 * @tree_view: a #PsppSheetView
9418 * @setting: %TRUE if the tree requires reading across rows
9420 * This function tells GTK+ that the user interface for your
9421 * application requires users to read across tree rows and associate
9422 * cells with one another. By default, GTK+ will then render the tree
9423 * with alternating row colors. Do <emphasis>not</emphasis> use it
9424 * just because you prefer the appearance of the ruled tree; that's a
9425 * question for the theme. Some themes will draw tree rows in
9426 * alternating colors even when rules are turned off, and users who
9427 * prefer that appearance all the time can choose those themes. You
9428 * should call this function only as a <emphasis>semantic</emphasis>
9429 * hint to the theme engine that your tree makes alternating colors
9430 * useful from a functional standpoint (since it has lots of columns,
9435 pspp_sheet_view_set_rules_hint (PsppSheetView *tree_view,
9438 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9440 setting = setting != FALSE;
9442 if (tree_view->priv->has_rules != setting)
9444 tree_view->priv->has_rules = setting;
9445 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
9448 g_object_notify (G_OBJECT (tree_view), "rules-hint");
9452 * pspp_sheet_view_get_rules_hint
9453 * @tree_view: a #PsppSheetView
9455 * Gets the setting set by pspp_sheet_view_set_rules_hint().
9457 * Return value: %TRUE if rules are useful for the user of this tree
9460 pspp_sheet_view_get_rules_hint (PsppSheetView *tree_view)
9462 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9464 return tree_view->priv->has_rules;
9467 /* Public Column functions
9471 * pspp_sheet_view_append_column:
9472 * @tree_view: A #PsppSheetView.
9473 * @column: The #PsppSheetViewColumn to add.
9475 * Appends @column to the list of columns.
9477 * Return value: The number of columns in @tree_view after appending.
9480 pspp_sheet_view_append_column (PsppSheetView *tree_view,
9481 PsppSheetViewColumn *column)
9483 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9484 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9485 g_return_val_if_fail (column->tree_view == NULL, -1);
9487 return pspp_sheet_view_insert_column (tree_view, column, -1);
9492 * pspp_sheet_view_remove_column:
9493 * @tree_view: A #PsppSheetView.
9494 * @column: The #PsppSheetViewColumn to remove.
9496 * Removes @column from @tree_view.
9498 * Return value: The number of columns in @tree_view after removing.
9501 pspp_sheet_view_remove_column (PsppSheetView *tree_view,
9502 PsppSheetViewColumn *column)
9504 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9505 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9506 g_return_val_if_fail (column->tree_view == GTK_WIDGET (tree_view), -1);
9508 if (tree_view->priv->focus_column == column)
9509 tree_view->priv->focus_column = NULL;
9511 if (tree_view->priv->edited_column == column)
9513 pspp_sheet_view_stop_editing (tree_view, TRUE);
9515 /* no need to, but just to be sure ... */
9516 tree_view->priv->edited_column = NULL;
9519 _pspp_sheet_view_column_unset_tree_view (column);
9521 tree_view->priv->columns = g_list_remove (tree_view->priv->columns, column);
9522 tree_view->priv->n_columns--;
9524 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9528 _pspp_sheet_view_column_unrealize_button (column);
9529 for (list = tree_view->priv->columns; list; list = list->next)
9531 PsppSheetViewColumn *tmp_column;
9533 tmp_column = PSPP_SHEET_VIEW_COLUMN (list->data);
9534 if (tmp_column->visible)
9535 _pspp_sheet_view_column_cell_set_dirty (tmp_column);
9538 if (tree_view->priv->n_columns == 0 &&
9539 pspp_sheet_view_get_headers_visible (tree_view) &&
9540 tree_view->priv->header_window)
9541 gdk_window_hide (tree_view->priv->header_window);
9543 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9546 g_object_unref (column);
9547 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9549 return tree_view->priv->n_columns;
9553 * pspp_sheet_view_insert_column:
9554 * @tree_view: A #PsppSheetView.
9555 * @column: The #PsppSheetViewColumn to be inserted.
9556 * @position: The position to insert @column in.
9558 * This inserts the @column into the @tree_view at @position. If @position is
9559 * -1, then the column is inserted at the end.
9561 * Return value: The number of columns in @tree_view after insertion.
9564 pspp_sheet_view_insert_column (PsppSheetView *tree_view,
9565 PsppSheetViewColumn *column,
9568 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9569 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9570 g_return_val_if_fail (column->tree_view == NULL, -1);
9572 g_object_ref_sink (column);
9574 if (tree_view->priv->n_columns == 0 &&
9575 gtk_widget_get_realized (GTK_WIDGET (tree_view)) &&
9576 pspp_sheet_view_get_headers_visible (tree_view))
9578 gdk_window_show (tree_view->priv->header_window);
9581 tree_view->priv->columns = g_list_insert (tree_view->priv->columns,
9583 tree_view->priv->n_columns++;
9585 _pspp_sheet_view_column_set_tree_view (column, tree_view);
9587 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9591 _pspp_sheet_view_column_realize_button (column);
9593 for (list = tree_view->priv->columns; list; list = list->next)
9595 column = PSPP_SHEET_VIEW_COLUMN (list->data);
9596 if (column->visible)
9597 _pspp_sheet_view_column_cell_set_dirty (column);
9599 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9602 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9604 return tree_view->priv->n_columns;
9608 * pspp_sheet_view_insert_column_with_attributes:
9609 * @tree_view: A #PsppSheetView
9610 * @position: The position to insert the new column in.
9611 * @title: The title to set the header to.
9612 * @cell: The #GtkCellRenderer.
9613 * @Varargs: A %NULL-terminated list of attributes.
9615 * Creates a new #PsppSheetViewColumn and inserts it into the @tree_view at
9616 * @position. If @position is -1, then the newly created column is inserted at
9617 * the end. The column is initialized with the attributes given.
9619 * Return value: The number of columns in @tree_view after insertion.
9622 pspp_sheet_view_insert_column_with_attributes (PsppSheetView *tree_view,
9625 GtkCellRenderer *cell,
9628 PsppSheetViewColumn *column;
9633 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9635 column = pspp_sheet_view_column_new ();
9636 pspp_sheet_view_column_set_title (column, title);
9637 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9639 va_start (args, cell);
9641 attribute = va_arg (args, gchar *);
9643 while (attribute != NULL)
9645 column_id = va_arg (args, gint);
9646 pspp_sheet_view_column_add_attribute (column, cell, attribute, column_id);
9647 attribute = va_arg (args, gchar *);
9652 pspp_sheet_view_insert_column (tree_view, column, position);
9654 return tree_view->priv->n_columns;
9658 * pspp_sheet_view_insert_column_with_data_func:
9659 * @tree_view: a #PsppSheetView
9660 * @position: Position to insert, -1 for append
9661 * @title: column title
9662 * @cell: cell renderer for column
9663 * @func: function to set attributes of cell renderer
9664 * @data: data for @func
9665 * @dnotify: destroy notifier for @data
9667 * Convenience function that inserts a new column into the #PsppSheetView
9668 * with the given cell renderer and a #GtkCellDataFunc to set cell renderer
9669 * attributes (normally using data from the model). See also
9670 * pspp_sheet_view_column_set_cell_data_func(), pspp_sheet_view_column_pack_start().
9672 * Return value: number of columns in the tree view post-insert
9675 pspp_sheet_view_insert_column_with_data_func (PsppSheetView *tree_view,
9678 GtkCellRenderer *cell,
9679 PsppSheetCellDataFunc func,
9681 GDestroyNotify dnotify)
9683 PsppSheetViewColumn *column;
9685 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9687 column = pspp_sheet_view_column_new ();
9688 pspp_sheet_view_column_set_title (column, title);
9689 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9690 pspp_sheet_view_column_set_cell_data_func (column, cell, func, data, dnotify);
9692 pspp_sheet_view_insert_column (tree_view, column, position);
9694 return tree_view->priv->n_columns;
9698 * pspp_sheet_view_get_column:
9699 * @tree_view: A #PsppSheetView.
9700 * @n: The position of the column, counting from 0.
9702 * Gets the #PsppSheetViewColumn at the given position in the #tree_view.
9704 * Return value: The #PsppSheetViewColumn, or %NULL if the position is outside the
9707 PsppSheetViewColumn *
9708 pspp_sheet_view_get_column (PsppSheetView *tree_view,
9711 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9713 if (n < 0 || n >= tree_view->priv->n_columns)
9716 if (tree_view->priv->columns == NULL)
9719 return PSPP_SHEET_VIEW_COLUMN (g_list_nth (tree_view->priv->columns, n)->data);
9723 * pspp_sheet_view_get_columns:
9724 * @tree_view: A #PsppSheetView
9726 * Returns a #GList of all the #PsppSheetViewColumn s currently in @tree_view.
9727 * The returned list must be freed with g_list_free ().
9729 * Return value: (element-type PsppSheetViewColumn) (transfer container): A list of #PsppSheetViewColumn s
9732 pspp_sheet_view_get_columns (PsppSheetView *tree_view)
9734 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9736 return g_list_copy (tree_view->priv->columns);
9740 * pspp_sheet_view_move_column_after:
9741 * @tree_view: A #PsppSheetView
9742 * @column: The #PsppSheetViewColumn to be moved.
9743 * @base_column: (allow-none): The #PsppSheetViewColumn to be moved relative to, or %NULL.
9745 * Moves @column to be after to @base_column. If @base_column is %NULL, then
9746 * @column is placed in the first position.
9749 pspp_sheet_view_move_column_after (PsppSheetView *tree_view,
9750 PsppSheetViewColumn *column,
9751 PsppSheetViewColumn *base_column)
9753 GList *column_list_el, *base_el = NULL;
9755 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9757 column_list_el = g_list_find (tree_view->priv->columns, column);
9758 g_return_if_fail (column_list_el != NULL);
9762 base_el = g_list_find (tree_view->priv->columns, base_column);
9763 g_return_if_fail (base_el != NULL);
9766 if (column_list_el->prev == base_el)
9769 tree_view->priv->columns = g_list_remove_link (tree_view->priv->columns, column_list_el);
9770 if (base_el == NULL)
9772 column_list_el->prev = NULL;
9773 column_list_el->next = tree_view->priv->columns;
9774 if (column_list_el->next)
9775 column_list_el->next->prev = column_list_el;
9776 tree_view->priv->columns = column_list_el;
9780 column_list_el->prev = base_el;
9781 column_list_el->next = base_el->next;
9782 if (column_list_el->next)
9783 column_list_el->next->prev = column_list_el;
9784 base_el->next = column_list_el;
9787 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9789 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9790 pspp_sheet_view_size_allocate_columns (GTK_WIDGET (tree_view), NULL);
9793 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9797 * pspp_sheet_view_set_column_drag_function:
9798 * @tree_view: A #PsppSheetView.
9799 * @func: (allow-none): A function to determine which columns are reorderable, or %NULL.
9800 * @user_data: (allow-none): User data to be passed to @func, or %NULL
9801 * @destroy: (allow-none): Destroy notifier for @user_data, or %NULL
9803 * Sets a user function for determining where a column may be dropped when
9804 * dragged. This function is called on every column pair in turn at the
9805 * beginning of a column drag to determine where a drop can take place. The
9806 * arguments passed to @func are: the @tree_view, the #PsppSheetViewColumn being
9807 * dragged, the two #PsppSheetViewColumn s determining the drop spot, and
9808 * @user_data. If either of the #PsppSheetViewColumn arguments for the drop spot
9809 * are %NULL, then they indicate an edge. If @func is set to be %NULL, then
9810 * @tree_view reverts to the default behavior of allowing all columns to be
9811 * dropped everywhere.
9814 pspp_sheet_view_set_column_drag_function (PsppSheetView *tree_view,
9815 PsppSheetViewColumnDropFunc func,
9817 GDestroyNotify destroy)
9819 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9821 if (tree_view->priv->column_drop_func_data_destroy)
9822 tree_view->priv->column_drop_func_data_destroy (tree_view->priv->column_drop_func_data);
9824 tree_view->priv->column_drop_func = func;
9825 tree_view->priv->column_drop_func_data = user_data;
9826 tree_view->priv->column_drop_func_data_destroy = destroy;
9830 * pspp_sheet_view_scroll_to_point:
9831 * @tree_view: a #PsppSheetView
9832 * @tree_x: X coordinate of new top-left pixel of visible area, or -1
9833 * @tree_y: Y coordinate of new top-left pixel of visible area, or -1
9835 * Scrolls the tree view such that the top-left corner of the visible
9836 * area is @tree_x, @tree_y, where @tree_x and @tree_y are specified
9837 * in tree coordinates. The @tree_view must be realized before
9838 * this function is called. If it isn't, you probably want to be
9839 * using pspp_sheet_view_scroll_to_cell().
9841 * If either @tree_x or @tree_y are -1, then that direction isn't scrolled.
9844 pspp_sheet_view_scroll_to_point (PsppSheetView *tree_view,
9848 GtkAdjustment *hadj;
9849 GtkAdjustment *vadj;
9851 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9852 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
9854 hadj = tree_view->priv->hadjustment;
9855 vadj = tree_view->priv->vadjustment;
9858 gtk_adjustment_set_value (hadj, CLAMP (tree_x, gtk_adjustment_get_lower (hadj), gtk_adjustment_get_upper (hadj) - gtk_adjustment_get_page_size (hadj)));
9860 gtk_adjustment_set_value (vadj, CLAMP (tree_y, gtk_adjustment_get_lower (vadj), gtk_adjustment_get_upper (vadj) - gtk_adjustment_get_page_size (vadj)));
9864 * pspp_sheet_view_scroll_to_cell:
9865 * @tree_view: A #PsppSheetView.
9866 * @path: (allow-none): The path of the row to move to, or %NULL.
9867 * @column: (allow-none): The #PsppSheetViewColumn to move horizontally to, or %NULL.
9868 * @use_align: whether to use alignment arguments, or %FALSE.
9869 * @row_align: The vertical alignment of the row specified by @path.
9870 * @col_align: The horizontal alignment of the column specified by @column.
9872 * Moves the alignments of @tree_view to the position specified by @column and
9873 * @path. If @column is %NULL, then no horizontal scrolling occurs. Likewise,
9874 * if @path is %NULL no vertical scrolling occurs. At a minimum, one of @column
9875 * or @path need to be non-%NULL. @row_align determines where the row is
9876 * placed, and @col_align determines where @column is placed. Both are expected
9877 * to be between 0.0 and 1.0. 0.0 means left/top alignment, 1.0 means
9878 * right/bottom alignment, 0.5 means center.
9880 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
9881 * tree does the minimum amount of work to scroll the cell onto the screen.
9882 * This means that the cell will be scrolled to the edge closest to its current
9883 * position. If the cell is currently visible on the screen, nothing is done.
9885 * This function only works if the model is set, and @path is a valid row on the
9886 * model. If the model changes before the @tree_view is realized, the centered
9887 * path will be modified to reflect this change.
9890 pspp_sheet_view_scroll_to_cell (PsppSheetView *tree_view,
9892 PsppSheetViewColumn *column,
9897 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9898 g_return_if_fail (tree_view->priv->model != NULL);
9899 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
9900 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
9901 g_return_if_fail (path != NULL || column != NULL);
9904 g_print ("pspp_sheet_view_scroll_to_cell:\npath: %s\ncolumn: %s\nuse_align: %d\nrow_align: %f\ncol_align: %f\n",
9905 gtk_tree_path_to_string (path), column?"non-null":"null", use_align, row_align, col_align);
9907 row_align = CLAMP (row_align, 0.0, 1.0);
9908 col_align = CLAMP (col_align, 0.0, 1.0);
9911 /* Note: Despite the benefits that come from having one code path for the
9912 * scrolling code, we short-circuit validate_visible_area's immplementation as
9913 * it is much slower than just going to the point.
9915 if (!gtk_widget_get_visible (GTK_WIDGET (tree_view)) ||
9916 !gtk_widget_get_realized (GTK_WIDGET (tree_view))
9917 /* XXX || GTK_WIDGET_ALLOC_NEEDED (tree_view) */)
9919 if (tree_view->priv->scroll_to_path)
9920 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9922 tree_view->priv->scroll_to_path = NULL;
9923 tree_view->priv->scroll_to_column = NULL;
9926 tree_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
9928 tree_view->priv->scroll_to_column = column;
9929 tree_view->priv->scroll_to_use_align = use_align;
9930 tree_view->priv->scroll_to_row_align = row_align;
9931 tree_view->priv->scroll_to_col_align = col_align;
9933 install_presize_handler (tree_view);
9937 GdkRectangle cell_rect;
9938 GdkRectangle vis_rect;
9939 gint dest_x, dest_y;
9941 pspp_sheet_view_get_background_area (tree_view, path, column, &cell_rect);
9942 pspp_sheet_view_get_visible_rect (tree_view, &vis_rect);
9944 cell_rect.y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, cell_rect.y);
9946 dest_x = vis_rect.x;
9947 dest_y = vis_rect.y;
9953 dest_x = cell_rect.x - ((vis_rect.width - cell_rect.width) * col_align);
9957 if (cell_rect.x < vis_rect.x)
9958 dest_x = cell_rect.x;
9959 if (cell_rect.x + cell_rect.width > vis_rect.x + vis_rect.width)
9960 dest_x = cell_rect.x + cell_rect.width - vis_rect.width;
9968 dest_y = cell_rect.y - ((vis_rect.height - cell_rect.height) * row_align);
9969 dest_y = MAX (dest_y, 0);
9973 if (cell_rect.y < vis_rect.y)
9974 dest_y = cell_rect.y;
9975 if (cell_rect.y + cell_rect.height > vis_rect.y + vis_rect.height)
9976 dest_y = cell_rect.y + cell_rect.height - vis_rect.height;
9980 pspp_sheet_view_scroll_to_point (tree_view, dest_x, dest_y);
9985 * pspp_sheet_view_row_activated:
9986 * @tree_view: A #PsppSheetView
9987 * @path: The #GtkTreePath to be activated.
9988 * @column: The #PsppSheetViewColumn to be activated.
9990 * Activates the cell determined by @path and @column.
9993 pspp_sheet_view_row_activated (PsppSheetView *tree_view,
9995 PsppSheetViewColumn *column)
9997 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9999 g_signal_emit (tree_view, tree_view_signals[ROW_ACTIVATED], 0, path, column);
10004 * pspp_sheet_view_get_reorderable:
10005 * @tree_view: a #PsppSheetView
10007 * Retrieves whether the user can reorder the tree via drag-and-drop. See
10008 * pspp_sheet_view_set_reorderable().
10010 * Return value: %TRUE if the tree can be reordered.
10013 pspp_sheet_view_get_reorderable (PsppSheetView *tree_view)
10015 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
10017 return tree_view->priv->reorderable;
10021 * pspp_sheet_view_set_reorderable:
10022 * @tree_view: A #PsppSheetView.
10023 * @reorderable: %TRUE, if the tree can be reordered.
10025 * This function is a convenience function to allow you to reorder
10026 * models that support the #GtkDragSourceIface and the
10027 * #GtkDragDestIface. Both #GtkTreeStore and #GtkListStore support
10028 * these. If @reorderable is %TRUE, then the user can reorder the
10029 * model by dragging and dropping rows. The developer can listen to
10030 * these changes by connecting to the model's row_inserted and
10031 * row_deleted signals. The reordering is implemented by setting up
10032 * the tree view as a drag source and destination. Therefore, drag and
10033 * drop can not be used in a reorderable view for any other purpose.
10035 * This function does not give you any degree of control over the order -- any
10036 * reordering is allowed. If more control is needed, you should probably
10037 * handle drag and drop manually.
10040 pspp_sheet_view_set_reorderable (PsppSheetView *tree_view,
10041 gboolean reorderable)
10043 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10045 reorderable = reorderable != FALSE;
10047 if (tree_view->priv->reorderable == reorderable)
10052 const GtkTargetEntry row_targets[] = {
10053 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
10056 pspp_sheet_view_enable_model_drag_source (tree_view,
10059 G_N_ELEMENTS (row_targets),
10061 pspp_sheet_view_enable_model_drag_dest (tree_view,
10063 G_N_ELEMENTS (row_targets),
10068 pspp_sheet_view_unset_rows_drag_source (tree_view);
10069 pspp_sheet_view_unset_rows_drag_dest (tree_view);
10072 tree_view->priv->reorderable = reorderable;
10074 g_object_notify (G_OBJECT (tree_view), "reorderable");
10077 /* If CLEAR_AND_SELECT is true, then the row will be selected and, unless Shift
10078 is pressed, other rows will be unselected.
10080 If CLAMP_NODE is true, then the sheetview will scroll to make the row
10083 pspp_sheet_view_real_set_cursor (PsppSheetView *tree_view,
10085 gboolean clear_and_select,
10086 gboolean clamp_node,
10087 PsppSheetSelectMode mode)
10091 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
10093 GtkTreePath *cursor_path;
10094 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
10095 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
10096 gtk_tree_path_free (cursor_path);
10099 gtk_tree_row_reference_free (tree_view->priv->cursor);
10100 tree_view->priv->cursor = NULL;
10102 _pspp_sheet_view_find_node (tree_view, path, &node);
10103 tree_view->priv->cursor =
10104 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
10105 tree_view->priv->model,
10108 if (tree_view->priv->row_count > 0)
10112 if (clear_and_select && !(mode & PSPP_SHEET_SELECT_MODE_TOGGLE))
10113 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
10117 /* We have to re-find tree and node here again, somebody might have
10118 * cleared the node or the whole tree in the PsppSheetSelection::changed
10119 * callback. If the nodes differ we bail out here.
10121 _pspp_sheet_view_find_node (tree_view, path, &new_node);
10123 if (node != new_node)
10128 pspp_sheet_view_clamp_node_visible (tree_view, node);
10129 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
10133 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
10137 * pspp_sheet_view_get_cursor:
10138 * @tree_view: A #PsppSheetView
10139 * @path: (allow-none): A pointer to be filled with the current cursor path, or %NULL
10140 * @focus_column: (allow-none): A pointer to be filled with the current focus column, or %NULL
10142 * Fills in @path and @focus_column with the current path and focus column. If
10143 * the cursor isn't currently set, then *@path will be %NULL. If no column
10144 * currently has focus, then *@focus_column will be %NULL.
10146 * The returned #GtkTreePath must be freed with gtk_tree_path_free() when
10147 * you are done with it.
10150 pspp_sheet_view_get_cursor (PsppSheetView *tree_view,
10151 GtkTreePath **path,
10152 PsppSheetViewColumn **focus_column)
10154 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10158 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
10159 *path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
10166 *focus_column = tree_view->priv->focus_column;
10171 * pspp_sheet_view_set_cursor:
10172 * @tree_view: A #PsppSheetView
10173 * @path: A #GtkTreePath
10174 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
10175 * @start_editing: %TRUE if the specified cell should start being edited.
10177 * Sets the current keyboard focus to be at @path, and selects it. This is
10178 * useful when you want to focus the user's attention on a particular row. If
10179 * @focus_column is not %NULL, then focus is given to the column specified by
10180 * it. Additionally, if @focus_column is specified, and @start_editing is
10181 * %TRUE, then editing should be started in the specified cell.
10182 * This function is often followed by @gtk_widget_grab_focus (@tree_view)
10183 * in order to give keyboard focus to the widget. Please note that editing
10184 * can only happen when the widget is realized.
10186 * If @path is invalid for @model, the current cursor (if any) will be unset
10187 * and the function will return without failing.
10190 pspp_sheet_view_set_cursor (PsppSheetView *tree_view,
10192 PsppSheetViewColumn *focus_column,
10193 gboolean start_editing)
10195 pspp_sheet_view_set_cursor_on_cell (tree_view, path, focus_column,
10196 NULL, start_editing);
10200 * pspp_sheet_view_set_cursor_on_cell:
10201 * @tree_view: A #PsppSheetView
10202 * @path: A #GtkTreePath
10203 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
10204 * @focus_cell: (allow-none): A #GtkCellRenderer, or %NULL
10205 * @start_editing: %TRUE if the specified cell should start being edited.
10207 * Sets the current keyboard focus to be at @path, and selects it. This is
10208 * useful when you want to focus the user's attention on a particular row. If
10209 * @focus_column is not %NULL, then focus is given to the column specified by
10210 * it. If @focus_column and @focus_cell are not %NULL, and @focus_column
10211 * contains 2 or more editable or activatable cells, then focus is given to
10212 * the cell specified by @focus_cell. Additionally, if @focus_column is
10213 * specified, and @start_editing is %TRUE, then editing should be started in
10214 * the specified cell. This function is often followed by
10215 * @gtk_widget_grab_focus (@tree_view) in order to give keyboard focus to the
10216 * widget. Please note that editing can only happen when the widget is
10219 * If @path is invalid for @model, the current cursor (if any) will be unset
10220 * and the function will return without failing.
10225 pspp_sheet_view_set_cursor_on_cell (PsppSheetView *tree_view,
10227 PsppSheetViewColumn *focus_column,
10228 GtkCellRenderer *focus_cell,
10229 gboolean start_editing)
10231 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10232 g_return_if_fail (path != NULL);
10233 g_return_if_fail (focus_column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (focus_column));
10235 if (!tree_view->priv->model)
10240 g_return_if_fail (focus_column);
10241 g_return_if_fail (GTK_IS_CELL_RENDERER (focus_cell));
10244 /* cancel the current editing, if it exists */
10245 if (tree_view->priv->edited_column &&
10246 tree_view->priv->edited_column->editable_widget)
10247 pspp_sheet_view_stop_editing (tree_view, TRUE);
10249 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, 0);
10251 if (focus_column && focus_column->visible)
10254 gboolean column_in_tree = FALSE;
10256 for (list = tree_view->priv->columns; list; list = list->next)
10257 if (list->data == focus_column)
10259 column_in_tree = TRUE;
10262 g_return_if_fail (column_in_tree);
10263 tree_view->priv->focus_column = focus_column;
10265 pspp_sheet_view_column_focus_cell (focus_column, focus_cell);
10267 pspp_sheet_view_start_editing (tree_view, path);
10269 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
10270 pspp_sheet_selection_select_column (tree_view->priv->selection, focus_column);
10276 * pspp_sheet_view_get_bin_window:
10277 * @tree_view: A #PsppSheetView
10279 * Returns the window that @tree_view renders to. This is used primarily to
10280 * compare to <literal>event->window</literal> to confirm that the event on
10281 * @tree_view is on the right window.
10283 * Return value: A #GdkWindow, or %NULL when @tree_view hasn't been realized yet
10286 pspp_sheet_view_get_bin_window (PsppSheetView *tree_view)
10288 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
10290 return tree_view->priv->bin_window;
10294 * pspp_sheet_view_get_path_at_pos:
10295 * @tree_view: A #PsppSheetView.
10296 * @x: The x position to be identified (relative to bin_window).
10297 * @y: The y position to be identified (relative to bin_window).
10298 * @path: (out) (allow-none): A pointer to a #GtkTreePath pointer to be filled in, or %NULL
10299 * @column: (out) (allow-none): A pointer to a #PsppSheetViewColumn pointer to be filled in, or %NULL
10300 * @cell_x: (out) (allow-none): A pointer where the X coordinate relative to the cell can be placed, or %NULL
10301 * @cell_y: (out) (allow-none): A pointer where the Y coordinate relative to the cell can be placed, or %NULL
10303 * Finds the path at the point (@x, @y), relative to bin_window coordinates
10304 * (please see pspp_sheet_view_get_bin_window()).
10305 * That is, @x and @y are relative to an events coordinates. @x and @y must
10306 * come from an event on the @tree_view only where <literal>event->window ==
10307 * pspp_sheet_view_get_bin_window (<!-- -->)</literal>. It is primarily for
10308 * things like popup menus. If @path is non-%NULL, then it will be filled
10309 * with the #GtkTreePath at that point. This path should be freed with
10310 * gtk_tree_path_free(). If @column is non-%NULL, then it will be filled
10311 * with the column at that point. @cell_x and @cell_y return the coordinates
10312 * relative to the cell background (i.e. the @background_area passed to
10313 * gtk_cell_renderer_render()). This function is only meaningful if
10314 * @tree_view is realized. Therefore this function will always return %FALSE
10315 * if @tree_view is not realized or does not have a model.
10317 * For converting widget coordinates (eg. the ones you get from
10318 * GtkWidget::query-tooltip), please see
10319 * pspp_sheet_view_convert_widget_to_bin_window_coords().
10321 * Return value: %TRUE if a row exists at that coordinate.
10324 pspp_sheet_view_get_path_at_pos (PsppSheetView *tree_view,
10327 GtkTreePath **path,
10328 PsppSheetViewColumn **column,
10335 g_return_val_if_fail (tree_view != NULL, FALSE);
10342 if (tree_view->priv->bin_window == NULL)
10345 if (tree_view->priv->row_count == 0)
10348 if (x > gtk_adjustment_get_upper (tree_view->priv->hadjustment))
10351 if (x < 0 || y < 0)
10354 if (column || cell_x)
10356 PsppSheetViewColumn *tmp_column;
10357 PsppSheetViewColumn *last_column = NULL;
10359 gint remaining_x = x;
10360 gboolean found = FALSE;
10363 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
10364 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
10366 list = (rtl ? list->prev : list->next))
10368 tmp_column = list->data;
10370 if (tmp_column->visible == FALSE)
10373 last_column = tmp_column;
10374 if (remaining_x <= tmp_column->width)
10379 *column = tmp_column;
10382 *cell_x = remaining_x;
10386 remaining_x -= tmp_column->width;
10389 /* If found is FALSE and there is a last_column, then it the remainder
10390 * space is in that area
10397 *column = last_column;
10400 *cell_x = last_column->width + remaining_x;
10409 y_offset = pspp_sheet_view_find_offset (tree_view,
10410 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, y),
10417 *cell_y = y_offset;
10420 *path = _pspp_sheet_view_find_path (tree_view, node);
10425 /* Computes 'cell_area' from 'background_area', which must be the background
10426 area for a cell. Set 'subtract_focus_rect' to TRUE to compute the cell area
10427 as passed to a GtkCellRenderer's "render" function, or to FALSE to compute
10428 the cell area as passed to _pspp_sheet_view_column_cell_render().
10430 'column' is required to properly adjust 'cell_area->x' and
10431 'cell_area->width'. It may be set to NULL if these values are not of
10432 interest. In this case 'cell_area->x' and 'cell_area->width' will be
10435 pspp_sheet_view_adjust_cell_area (PsppSheetView *tree_view,
10436 PsppSheetViewColumn *column,
10437 const GdkRectangle *background_area,
10438 gboolean subtract_focus_rect,
10439 GdkRectangle *cell_area)
10441 gint vertical_separator;
10442 gint horizontal_separator;
10444 *cell_area = *background_area;
10446 gtk_widget_style_get (GTK_WIDGET (tree_view),
10447 "vertical-separator", &vertical_separator,
10448 "horizontal-separator", &horizontal_separator,
10450 cell_area->x += horizontal_separator / 2;
10451 cell_area->y += vertical_separator / 2;
10452 cell_area->width -= horizontal_separator;
10453 cell_area->height -= vertical_separator;
10455 if (subtract_focus_rect)
10457 int focus_line_width;
10459 gtk_widget_style_get (GTK_WIDGET (tree_view),
10460 "focus-line-width", &focus_line_width,
10462 cell_area->x += focus_line_width;
10463 cell_area->y += focus_line_width;
10464 cell_area->width -= 2 * focus_line_width;
10465 cell_area->height -= 2 * focus_line_width;
10468 if (tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_NONE)
10470 gint grid_line_width;
10471 gtk_widget_style_get (GTK_WIDGET (tree_view),
10472 "grid-line-width", &grid_line_width,
10475 if ((tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
10476 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10479 PsppSheetViewColumn *first_column, *last_column;
10482 /* Find the last visible column. */
10483 last_column = NULL;
10484 for (list = g_list_last (tree_view->priv->columns);
10488 PsppSheetViewColumn *c = list->data;
10496 /* Find the first visible column. */
10497 first_column = NULL;
10498 for (list = g_list_first (tree_view->priv->columns);
10502 PsppSheetViewColumn *c = list->data;
10510 if (column == first_column)
10512 cell_area->width -= grid_line_width / 2;
10514 else if (column == last_column)
10516 cell_area->x += grid_line_width / 2;
10517 cell_area->width -= grid_line_width / 2;
10521 cell_area->x += grid_line_width / 2;
10522 cell_area->width -= grid_line_width;
10526 if (tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
10527 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10529 cell_area->y += grid_line_width / 2;
10530 cell_area->height -= grid_line_width;
10534 if (column == NULL)
10537 cell_area->width = 0;
10542 * pspp_sheet_view_get_cell_area:
10543 * @tree_view: a #PsppSheetView
10544 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10545 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordinates
10546 * @rect: rectangle to fill with cell rect
10548 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10549 * row specified by @path and the column specified by @column. If @path is
10550 * %NULL, or points to a path not currently displayed, the @y and @height fields
10551 * of the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10552 * fields will be filled with 0. The sum of all cell rects does not cover the
10553 * entire tree; there are extra pixels in between rows, for example. The
10554 * returned rectangle is equivalent to the @cell_area passed to
10555 * gtk_cell_renderer_render(). This function is only valid if @tree_view is
10559 pspp_sheet_view_get_cell_area (PsppSheetView *tree_view,
10561 PsppSheetViewColumn *column,
10562 GdkRectangle *rect)
10564 GdkRectangle background_area;
10566 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10567 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10568 g_return_if_fail (rect != NULL);
10569 g_return_if_fail (!column || column->tree_view == (GtkWidget *) tree_view);
10570 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
10572 pspp_sheet_view_get_background_area (tree_view, path, column,
10574 pspp_sheet_view_adjust_cell_area (tree_view, column, &background_area,
10579 * pspp_sheet_view_get_background_area:
10580 * @tree_view: a #PsppSheetView
10581 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10582 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordiantes
10583 * @rect: rectangle to fill with cell background rect
10585 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10586 * row specified by @path and the column specified by @column. If @path is
10587 * %NULL, or points to a node not found in the tree, the @y and @height fields of
10588 * the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10589 * fields will be filled with 0. The returned rectangle is equivalent to the
10590 * @background_area passed to gtk_cell_renderer_render(). These background
10591 * areas tile to cover the entire bin window. Contrast with the @cell_area,
10592 * returned by pspp_sheet_view_get_cell_area(), which returns only the cell
10593 * itself, excluding surrounding borders.
10597 pspp_sheet_view_get_background_area (PsppSheetView *tree_view,
10599 PsppSheetViewColumn *column,
10600 GdkRectangle *rect)
10604 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10605 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10606 g_return_if_fail (rect != NULL);
10615 /* Get vertical coords */
10617 _pspp_sheet_view_find_node (tree_view, path, &node);
10621 rect->y = BACKGROUND_FIRST_PIXEL (tree_view, node);
10623 rect->height = ROW_HEIGHT (tree_view);
10630 pspp_sheet_view_get_background_xrange (tree_view, column, &rect->x, &x2);
10631 rect->width = x2 - rect->x;
10636 * pspp_sheet_view_get_visible_rect:
10637 * @tree_view: a #PsppSheetView
10638 * @visible_rect: rectangle to fill
10640 * Fills @visible_rect with the currently-visible region of the
10641 * buffer, in tree coordinates. Convert to bin_window coordinates with
10642 * pspp_sheet_view_convert_tree_to_bin_window_coords().
10643 * Tree coordinates start at 0,0 for row 0 of the tree, and cover the entire
10644 * scrollable area of the tree.
10647 pspp_sheet_view_get_visible_rect (PsppSheetView *tree_view,
10648 GdkRectangle *visible_rect)
10652 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10654 widget = GTK_WIDGET (tree_view);
10658 GtkAllocation allocation;
10659 gtk_widget_get_allocation (widget, &allocation);
10660 visible_rect->x = gtk_adjustment_get_value (tree_view->priv->hadjustment);
10661 visible_rect->y = gtk_adjustment_get_value (tree_view->priv->vadjustment);
10662 visible_rect->width = allocation.width;
10663 visible_rect->height = allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
10668 * pspp_sheet_view_widget_to_tree_coords:
10669 * @tree_view: a #PsppSheetView
10670 * @wx: X coordinate relative to bin_window
10671 * @wy: Y coordinate relative to bin_window
10672 * @tx: return location for tree X coordinate
10673 * @ty: return location for tree Y coordinate
10675 * Converts bin_window coordinates to coordinates for the
10676 * tree (the full scrollable area of the tree).
10678 * Deprecated: 2.12: Due to historial reasons the name of this function is
10679 * incorrect. For converting coordinates relative to the widget to
10680 * bin_window coordinates, please see
10681 * pspp_sheet_view_convert_widget_to_bin_window_coords().
10685 pspp_sheet_view_widget_to_tree_coords (PsppSheetView *tree_view,
10691 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10694 *tx = wx + gtk_adjustment_get_value (tree_view->priv->hadjustment);
10696 *ty = wy + tree_view->priv->dy;
10700 * pspp_sheet_view_tree_to_widget_coords:
10701 * @tree_view: a #PsppSheetView
10702 * @tx: tree X coordinate
10703 * @ty: tree Y coordinate
10704 * @wx: return location for X coordinate relative to bin_window
10705 * @wy: return location for Y coordinate relative to bin_window
10707 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10708 * to bin_window coordinates.
10710 * Deprecated: 2.12: Due to historial reasons the name of this function is
10711 * incorrect. For converting bin_window coordinates to coordinates relative
10712 * to bin_window, please see
10713 * pspp_sheet_view_convert_bin_window_to_widget_coords().
10717 pspp_sheet_view_tree_to_widget_coords (PsppSheetView *tree_view,
10723 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10726 *wx = tx - gtk_adjustment_get_value (tree_view->priv->hadjustment);
10728 *wy = ty - tree_view->priv->dy;
10733 * pspp_sheet_view_convert_widget_to_tree_coords:
10734 * @tree_view: a #PsppSheetView
10735 * @wx: X coordinate relative to the widget
10736 * @wy: Y coordinate relative to the widget
10737 * @tx: return location for tree X coordinate
10738 * @ty: return location for tree Y coordinate
10740 * Converts widget coordinates to coordinates for the
10741 * tree (the full scrollable area of the tree).
10746 pspp_sheet_view_convert_widget_to_tree_coords (PsppSheetView *tree_view,
10754 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10756 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view,
10759 pspp_sheet_view_convert_bin_window_to_tree_coords (tree_view,
10765 * pspp_sheet_view_convert_tree_to_widget_coords:
10766 * @tree_view: a #PsppSheetView
10767 * @tx: X coordinate relative to the tree
10768 * @ty: Y coordinate relative to the tree
10769 * @wx: return location for widget X coordinate
10770 * @wy: return location for widget Y coordinate
10772 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10773 * to widget coordinates.
10778 pspp_sheet_view_convert_tree_to_widget_coords (PsppSheetView *tree_view,
10786 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10788 pspp_sheet_view_convert_tree_to_bin_window_coords (tree_view,
10791 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
10797 * pspp_sheet_view_convert_widget_to_bin_window_coords:
10798 * @tree_view: a #PsppSheetView
10799 * @wx: X coordinate relative to the widget
10800 * @wy: Y coordinate relative to the widget
10801 * @bx: return location for bin_window X coordinate
10802 * @by: return location for bin_window Y coordinate
10804 * Converts widget coordinates to coordinates for the bin_window
10805 * (see pspp_sheet_view_get_bin_window()).
10810 pspp_sheet_view_convert_widget_to_bin_window_coords (PsppSheetView *tree_view,
10816 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10819 *bx = wx + gtk_adjustment_get_value (tree_view->priv->hadjustment);
10821 *by = wy - TREE_VIEW_HEADER_HEIGHT (tree_view);
10825 * pspp_sheet_view_convert_bin_window_to_widget_coords:
10826 * @tree_view: a #PsppSheetView
10827 * @bx: bin_window X coordinate
10828 * @by: bin_window Y coordinate
10829 * @wx: return location for widget X coordinate
10830 * @wy: return location for widget Y coordinate
10832 * Converts bin_window coordinates (see pspp_sheet_view_get_bin_window())
10833 * to widget relative coordinates.
10838 pspp_sheet_view_convert_bin_window_to_widget_coords (PsppSheetView *tree_view,
10844 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10847 *wx = bx - gtk_adjustment_get_value (tree_view->priv->hadjustment);
10849 *wy = by + TREE_VIEW_HEADER_HEIGHT (tree_view);
10853 * pspp_sheet_view_convert_tree_to_bin_window_coords:
10854 * @tree_view: a #PsppSheetView
10855 * @tx: tree X coordinate
10856 * @ty: tree Y coordinate
10857 * @bx: return location for X coordinate relative to bin_window
10858 * @by: return location for Y coordinate relative to bin_window
10860 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10861 * to bin_window coordinates.
10866 pspp_sheet_view_convert_tree_to_bin_window_coords (PsppSheetView *tree_view,
10872 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10877 *by = ty - tree_view->priv->dy;
10881 * pspp_sheet_view_convert_bin_window_to_tree_coords:
10882 * @tree_view: a #PsppSheetView
10883 * @bx: X coordinate relative to bin_window
10884 * @by: Y coordinate relative to bin_window
10885 * @tx: return location for tree X coordinate
10886 * @ty: return location for tree Y coordinate
10888 * Converts bin_window coordinates to coordinates for the
10889 * tree (the full scrollable area of the tree).
10894 pspp_sheet_view_convert_bin_window_to_tree_coords (PsppSheetView *tree_view,
10900 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10905 *ty = by + tree_view->priv->dy;
10911 * pspp_sheet_view_get_visible_range:
10912 * @tree_view: A #PsppSheetView
10913 * @start_path: (allow-none): Return location for start of region, or %NULL.
10914 * @end_path: (allow-none): Return location for end of region, or %NULL.
10916 * Sets @start_path and @end_path to be the first and last visible path.
10917 * Note that there may be invisible paths in between.
10919 * The paths should be freed with gtk_tree_path_free() after use.
10921 * Returns: %TRUE, if valid paths were placed in @start_path and @end_path.
10926 pspp_sheet_view_get_visible_range (PsppSheetView *tree_view,
10927 GtkTreePath **start_path,
10928 GtkTreePath **end_path)
10933 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
10935 if (!tree_view->priv->row_count)
10942 pspp_sheet_view_find_offset (tree_view,
10943 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, 0),
10946 *start_path = _pspp_sheet_view_find_path (tree_view, node);
10955 if (tree_view->priv->height < gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
10956 y = tree_view->priv->height - 1;
10958 y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, gtk_adjustment_get_page_size (tree_view->priv->vadjustment)) - 1;
10960 pspp_sheet_view_find_offset (tree_view, y, &node);
10962 *end_path = _pspp_sheet_view_find_path (tree_view, node);
10971 unset_reorderable (PsppSheetView *tree_view)
10973 if (tree_view->priv->reorderable)
10975 tree_view->priv->reorderable = FALSE;
10976 g_object_notify (G_OBJECT (tree_view), "reorderable");
10981 * pspp_sheet_view_enable_model_drag_source:
10982 * @tree_view: a #PsppSheetView
10983 * @start_button_mask: Mask of allowed buttons to start drag
10984 * @targets: the table of targets that the drag will support
10985 * @n_targets: the number of items in @targets
10986 * @actions: the bitmask of possible actions for a drag from this
10989 * Turns @tree_view into a drag source for automatic DND. Calling this
10990 * method sets #PsppSheetView:reorderable to %FALSE.
10993 pspp_sheet_view_enable_model_drag_source (PsppSheetView *tree_view,
10994 GdkModifierType start_button_mask,
10995 const GtkTargetEntry *targets,
10997 GdkDragAction actions)
10999 TreeViewDragInfo *di;
11001 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11003 gtk_drag_source_set (GTK_WIDGET (tree_view),
11009 di = ensure_info (tree_view);
11011 di->start_button_mask = start_button_mask;
11012 di->source_actions = actions;
11013 di->source_set = TRUE;
11015 unset_reorderable (tree_view);
11019 * pspp_sheet_view_enable_model_drag_dest:
11020 * @tree_view: a #PsppSheetView
11021 * @targets: the table of targets that the drag will support
11022 * @n_targets: the number of items in @targets
11023 * @actions: the bitmask of possible actions for a drag from this
11026 * Turns @tree_view into a drop destination for automatic DND. Calling
11027 * this method sets #PsppSheetView:reorderable to %FALSE.
11030 pspp_sheet_view_enable_model_drag_dest (PsppSheetView *tree_view,
11031 const GtkTargetEntry *targets,
11033 GdkDragAction actions)
11035 TreeViewDragInfo *di;
11037 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11039 gtk_drag_dest_set (GTK_WIDGET (tree_view),
11045 di = ensure_info (tree_view);
11046 di->dest_set = TRUE;
11048 unset_reorderable (tree_view);
11052 * pspp_sheet_view_unset_rows_drag_source:
11053 * @tree_view: a #PsppSheetView
11055 * Undoes the effect of
11056 * pspp_sheet_view_enable_model_drag_source(). Calling this method sets
11057 * #PsppSheetView:reorderable to %FALSE.
11060 pspp_sheet_view_unset_rows_drag_source (PsppSheetView *tree_view)
11062 TreeViewDragInfo *di;
11064 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11066 di = get_info (tree_view);
11070 if (di->source_set)
11072 gtk_drag_source_unset (GTK_WIDGET (tree_view));
11073 di->source_set = FALSE;
11076 if (!di->dest_set && !di->source_set)
11077 remove_info (tree_view);
11080 unset_reorderable (tree_view);
11084 * pspp_sheet_view_unset_rows_drag_dest:
11085 * @tree_view: a #PsppSheetView
11087 * Undoes the effect of
11088 * pspp_sheet_view_enable_model_drag_dest(). Calling this method sets
11089 * #PsppSheetView:reorderable to %FALSE.
11092 pspp_sheet_view_unset_rows_drag_dest (PsppSheetView *tree_view)
11094 TreeViewDragInfo *di;
11096 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11098 di = get_info (tree_view);
11104 gtk_drag_dest_unset (GTK_WIDGET (tree_view));
11105 di->dest_set = FALSE;
11108 if (!di->dest_set && !di->source_set)
11109 remove_info (tree_view);
11112 unset_reorderable (tree_view);
11116 * pspp_sheet_view_set_drag_dest_row:
11117 * @tree_view: a #PsppSheetView
11118 * @path: (allow-none): The path of the row to highlight, or %NULL.
11119 * @pos: Specifies whether to drop before, after or into the row
11121 * Sets the row that is highlighted for feedback.
11124 pspp_sheet_view_set_drag_dest_row (PsppSheetView *tree_view,
11126 PsppSheetViewDropPosition pos)
11128 GtkTreePath *current_dest;
11130 /* Note; this function is exported to allow a custom DND
11131 * implementation, so it can't touch TreeViewDragInfo
11134 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11136 current_dest = NULL;
11138 if (tree_view->priv->drag_dest_row)
11140 current_dest = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
11141 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
11144 /* special case a drop on an empty model */
11145 tree_view->priv->empty_view_drop = 0;
11147 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE && path
11148 && gtk_tree_path_get_depth (path) == 1
11149 && gtk_tree_path_get_indices (path)[0] == 0)
11153 n_children = gtk_tree_model_iter_n_children (tree_view->priv->model,
11157 tree_view->priv->empty_view_drop = 1;
11160 tree_view->priv->drag_dest_pos = pos;
11164 tree_view->priv->drag_dest_row =
11165 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
11166 pspp_sheet_view_queue_draw_path (tree_view, path, NULL);
11169 tree_view->priv->drag_dest_row = NULL;
11173 int node, new_node;
11175 _pspp_sheet_view_find_node (tree_view, current_dest, &node);
11176 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
11180 new_node = pspp_sheet_view_node_next (tree_view, node);
11182 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
11184 new_node = pspp_sheet_view_node_prev (tree_view, node);
11186 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
11188 gtk_tree_path_free (current_dest);
11193 * pspp_sheet_view_get_drag_dest_row:
11194 * @tree_view: a #PsppSheetView
11195 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
11196 * @pos: (allow-none): Return location for the drop position, or %NULL
11198 * Gets information about the row that is highlighted for feedback.
11201 pspp_sheet_view_get_drag_dest_row (PsppSheetView *tree_view,
11202 GtkTreePath **path,
11203 PsppSheetViewDropPosition *pos)
11205 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11209 if (tree_view->priv->drag_dest_row)
11210 *path = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
11213 if (tree_view->priv->empty_view_drop)
11214 *path = gtk_tree_path_new_from_indices (0, -1);
11221 *pos = tree_view->priv->drag_dest_pos;
11225 * pspp_sheet_view_get_dest_row_at_pos:
11226 * @tree_view: a #PsppSheetView
11227 * @drag_x: the position to determine the destination row for
11228 * @drag_y: the position to determine the destination row for
11229 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
11230 * @pos: (allow-none): Return location for the drop position, or %NULL
11232 * Determines the destination row for a given position. @drag_x and
11233 * @drag_y are expected to be in widget coordinates. This function is only
11234 * meaningful if @tree_view is realized. Therefore this function will always
11235 * return %FALSE if @tree_view is not realized or does not have a model.
11237 * Return value: whether there is a row at the given position, %TRUE if this
11238 * is indeed the case.
11241 pspp_sheet_view_get_dest_row_at_pos (PsppSheetView *tree_view,
11244 GtkTreePath **path,
11245 PsppSheetViewDropPosition *pos)
11249 gdouble offset_into_row;
11252 PsppSheetViewColumn *column = NULL;
11253 GtkTreePath *tmp_path = NULL;
11255 /* Note; this function is exported to allow a custom DND
11256 * implementation, so it can't touch TreeViewDragInfo
11259 g_return_val_if_fail (tree_view != NULL, FALSE);
11260 g_return_val_if_fail (drag_x >= 0, FALSE);
11261 g_return_val_if_fail (drag_y >= 0, FALSE);
11266 if (tree_view->priv->bin_window == NULL)
11269 if (tree_view->priv->row_count == 0)
11272 /* If in the top third of a row, we drop before that row; if
11273 * in the bottom third, drop after that row; if in the middle,
11274 * and the row has children, drop into the row.
11276 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, drag_x, drag_y,
11279 if (!pspp_sheet_view_get_path_at_pos (tree_view,
11288 pspp_sheet_view_get_background_area (tree_view, tmp_path, column,
11291 offset_into_row = cell_y;
11296 gtk_tree_path_free (tmp_path);
11300 third = cell.height / 3.0;
11304 if (offset_into_row < third)
11306 *pos = PSPP_SHEET_VIEW_DROP_BEFORE;
11308 else if (offset_into_row < (cell.height / 2.0))
11310 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE;
11312 else if (offset_into_row < third * 2.0)
11314 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER;
11318 *pos = PSPP_SHEET_VIEW_DROP_AFTER;
11326 #if GTK3_TRANSITION
11327 /* KEEP IN SYNC WITH PSPP_SHEET_VIEW_BIN_EXPOSE */
11329 * pspp_sheet_view_create_row_drag_icon:
11330 * @tree_view: a #PsppSheetView
11331 * @path: a #GtkTreePath in @tree_view
11333 * Creates a #GdkPixmap representation of the row at @path.
11334 * This image is used for a drag icon.
11336 * Return value: a newly-allocated pixmap of the drag icon.
11339 pspp_sheet_view_create_row_drag_icon (PsppSheetView *tree_view,
11346 GdkRectangle background_area;
11347 GdkRectangle expose_area;
11349 /* start drawing inside the black outline */
11351 GdkDrawable *drawable;
11352 gint bin_window_width;
11355 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11356 g_return_val_if_fail (path != NULL, NULL);
11358 widget = GTK_WIDGET (tree_view);
11360 if (!gtk_widget_get_realized (widget))
11363 _pspp_sheet_view_find_node (tree_view,
11370 if (!gtk_tree_model_get_iter (tree_view->priv->model,
11377 background_area.y = y;
11378 background_area.height = ROW_HEIGHT (tree_view);
11380 bin_window_width = gdk_window_get_width (tree_view->priv->bin_window);
11382 drawable = gdk_pixmap_new (tree_view->priv->bin_window,
11383 bin_window_width + 2,
11384 background_area.height + 2,
11389 expose_area.width = bin_window_width + 2;
11390 expose_area.height = background_area.height + 2;
11392 #if GTK3_TRANSITION
11393 gdk_draw_rectangle (drawable,
11394 widget->style->base_gc [gtk_widget_get_state (widget)],
11397 bin_window_width + 2,
11398 background_area.height + 2);
11401 rtl = gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL;
11403 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
11405 list = (rtl ? list->prev : list->next))
11407 PsppSheetViewColumn *column = list->data;
11408 GdkRectangle cell_area;
11409 gint vertical_separator;
11411 if (!column->visible)
11414 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, &iter);
11416 background_area.x = cell_offset;
11417 background_area.width = column->width;
11419 gtk_widget_style_get (widget,
11420 "vertical-separator", &vertical_separator,
11423 cell_area = background_area;
11425 cell_area.y += vertical_separator / 2;
11426 cell_area.height -= vertical_separator;
11428 if (pspp_sheet_view_column_cell_is_visible (column))
11429 _pspp_sheet_view_column_cell_render (column,
11435 cell_offset += column->width;
11438 #if GTK3_TRANSITION
11439 gdk_draw_rectangle (drawable,
11440 widget->style->black_gc,
11443 bin_window_width + 1,
11444 background_area.height + 1);
11452 * pspp_sheet_view_set_destroy_count_func:
11453 * @tree_view: A #PsppSheetView
11454 * @func: (allow-none): Function to be called when a view row is destroyed, or %NULL
11455 * @data: (allow-none): User data to be passed to @func, or %NULL
11456 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11458 * This function should almost never be used. It is meant for private use by
11459 * ATK for determining the number of visible children that are removed when a row is deleted.
11462 pspp_sheet_view_set_destroy_count_func (PsppSheetView *tree_view,
11463 PsppSheetDestroyCountFunc func,
11465 GDestroyNotify destroy)
11467 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11469 if (tree_view->priv->destroy_count_destroy)
11470 tree_view->priv->destroy_count_destroy (tree_view->priv->destroy_count_data);
11472 tree_view->priv->destroy_count_func = func;
11473 tree_view->priv->destroy_count_data = data;
11474 tree_view->priv->destroy_count_destroy = destroy;
11479 * Interactive search
11483 * pspp_sheet_view_set_enable_search:
11484 * @tree_view: A #PsppSheetView
11485 * @enable_search: %TRUE, if the user can search interactively
11487 * If @enable_search is set, then the user can type in text to search through
11488 * the tree interactively (this is sometimes called "typeahead find").
11490 * Note that even if this is %FALSE, the user can still initiate a search
11491 * using the "start-interactive-search" key binding.
11494 pspp_sheet_view_set_enable_search (PsppSheetView *tree_view,
11495 gboolean enable_search)
11497 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11499 enable_search = !!enable_search;
11501 if (tree_view->priv->enable_search != enable_search)
11503 tree_view->priv->enable_search = enable_search;
11504 g_object_notify (G_OBJECT (tree_view), "enable-search");
11509 * pspp_sheet_view_get_enable_search:
11510 * @tree_view: A #PsppSheetView
11512 * Returns whether or not the tree allows to start interactive searching
11513 * by typing in text.
11515 * Return value: whether or not to let the user search interactively
11518 pspp_sheet_view_get_enable_search (PsppSheetView *tree_view)
11520 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11522 return tree_view->priv->enable_search;
11527 * pspp_sheet_view_get_search_column:
11528 * @tree_view: A #PsppSheetView
11530 * Gets the column searched on by the interactive search code.
11532 * Return value: the column the interactive search code searches in.
11535 pspp_sheet_view_get_search_column (PsppSheetView *tree_view)
11537 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
11539 return (tree_view->priv->search_column);
11543 * pspp_sheet_view_set_search_column:
11544 * @tree_view: A #PsppSheetView
11545 * @column: the column of the model to search in, or -1 to disable searching
11547 * Sets @column as the column where the interactive search code should
11548 * search in for the current model.
11550 * If the search column is set, users can use the "start-interactive-search"
11551 * key binding to bring up search popup. The enable-search property controls
11552 * whether simply typing text will also start an interactive search.
11554 * Note that @column refers to a column of the current model. The search
11555 * column is reset to -1 when the model is changed.
11558 pspp_sheet_view_set_search_column (PsppSheetView *tree_view,
11561 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11562 g_return_if_fail (column >= -1);
11564 if (tree_view->priv->search_column == column)
11567 tree_view->priv->search_column = column;
11568 g_object_notify (G_OBJECT (tree_view), "search-column");
11572 * pspp_sheet_view_get_search_equal_func:
11573 * @tree_view: A #PsppSheetView
11575 * Returns the compare function currently in use.
11577 * Return value: the currently used compare function for the search code.
11580 PsppSheetViewSearchEqualFunc
11581 pspp_sheet_view_get_search_equal_func (PsppSheetView *tree_view)
11583 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11585 return tree_view->priv->search_equal_func;
11589 * pspp_sheet_view_set_search_equal_func:
11590 * @tree_view: A #PsppSheetView
11591 * @search_equal_func: the compare function to use during the search
11592 * @search_user_data: (allow-none): user data to pass to @search_equal_func, or %NULL
11593 * @search_destroy: (allow-none): Destroy notifier for @search_user_data, or %NULL
11595 * Sets the compare function for the interactive search capabilities; note
11596 * that somewhat like strcmp() returning 0 for equality
11597 * #PsppSheetViewSearchEqualFunc returns %FALSE on matches.
11600 pspp_sheet_view_set_search_equal_func (PsppSheetView *tree_view,
11601 PsppSheetViewSearchEqualFunc search_equal_func,
11602 gpointer search_user_data,
11603 GDestroyNotify search_destroy)
11605 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11606 g_return_if_fail (search_equal_func != NULL);
11608 if (tree_view->priv->search_destroy)
11609 tree_view->priv->search_destroy (tree_view->priv->search_user_data);
11611 tree_view->priv->search_equal_func = search_equal_func;
11612 tree_view->priv->search_user_data = search_user_data;
11613 tree_view->priv->search_destroy = search_destroy;
11614 if (tree_view->priv->search_equal_func == NULL)
11615 tree_view->priv->search_equal_func = pspp_sheet_view_search_equal_func;
11619 * pspp_sheet_view_get_search_entry:
11620 * @tree_view: A #PsppSheetView
11622 * Returns the #GtkEntry which is currently in use as interactive search
11623 * entry for @tree_view. In case the built-in entry is being used, %NULL
11624 * will be returned.
11626 * Return value: the entry currently in use as search entry.
11631 pspp_sheet_view_get_search_entry (PsppSheetView *tree_view)
11633 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11635 if (tree_view->priv->search_custom_entry_set)
11636 return GTK_ENTRY (tree_view->priv->search_entry);
11642 * pspp_sheet_view_set_search_entry:
11643 * @tree_view: A #PsppSheetView
11644 * @entry: (allow-none): the entry the interactive search code of @tree_view should use or %NULL
11646 * Sets the entry which the interactive search code will use for this
11647 * @tree_view. This is useful when you want to provide a search entry
11648 * in our interface at all time at a fixed position. Passing %NULL for
11649 * @entry will make the interactive search code use the built-in popup
11655 pspp_sheet_view_set_search_entry (PsppSheetView *tree_view,
11658 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11659 g_return_if_fail (entry == NULL || GTK_IS_ENTRY (entry));
11661 if (tree_view->priv->search_custom_entry_set)
11663 if (tree_view->priv->search_entry_changed_id)
11665 g_signal_handler_disconnect (tree_view->priv->search_entry,
11666 tree_view->priv->search_entry_changed_id);
11667 tree_view->priv->search_entry_changed_id = 0;
11669 g_signal_handlers_disconnect_by_func (tree_view->priv->search_entry,
11670 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11673 g_object_unref (tree_view->priv->search_entry);
11675 else if (tree_view->priv->search_window)
11677 gtk_widget_destroy (tree_view->priv->search_window);
11679 tree_view->priv->search_window = NULL;
11684 tree_view->priv->search_entry = g_object_ref (entry);
11685 tree_view->priv->search_custom_entry_set = TRUE;
11687 if (tree_view->priv->search_entry_changed_id == 0)
11689 tree_view->priv->search_entry_changed_id =
11690 g_signal_connect (tree_view->priv->search_entry, "changed",
11691 G_CALLBACK (pspp_sheet_view_search_init),
11695 g_signal_connect (tree_view->priv->search_entry, "key-press-event",
11696 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11699 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
11703 tree_view->priv->search_entry = NULL;
11704 tree_view->priv->search_custom_entry_set = FALSE;
11709 * pspp_sheet_view_set_search_position_func:
11710 * @tree_view: A #PsppSheetView
11711 * @func: (allow-none): the function to use to position the search dialog, or %NULL
11712 * to use the default search position function
11713 * @data: (allow-none): user data to pass to @func, or %NULL
11714 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11716 * Sets the function to use when positioning the search dialog.
11721 pspp_sheet_view_set_search_position_func (PsppSheetView *tree_view,
11722 PsppSheetViewSearchPositionFunc func,
11723 gpointer user_data,
11724 GDestroyNotify destroy)
11726 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11728 if (tree_view->priv->search_position_destroy)
11729 tree_view->priv->search_position_destroy (tree_view->priv->search_position_user_data);
11731 tree_view->priv->search_position_func = func;
11732 tree_view->priv->search_position_user_data = user_data;
11733 tree_view->priv->search_position_destroy = destroy;
11734 if (tree_view->priv->search_position_func == NULL)
11735 tree_view->priv->search_position_func = pspp_sheet_view_search_position_func;
11739 * pspp_sheet_view_get_search_position_func:
11740 * @tree_view: A #PsppSheetView
11742 * Returns the positioning function currently in use.
11744 * Return value: the currently used function for positioning the search dialog.
11748 PsppSheetViewSearchPositionFunc
11749 pspp_sheet_view_get_search_position_func (PsppSheetView *tree_view)
11751 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11753 return tree_view->priv->search_position_func;
11758 pspp_sheet_view_search_dialog_hide (GtkWidget *search_dialog,
11759 PsppSheetView *tree_view)
11761 if (tree_view->priv->disable_popdown)
11764 if (tree_view->priv->search_entry_changed_id)
11766 g_signal_handler_disconnect (tree_view->priv->search_entry,
11767 tree_view->priv->search_entry_changed_id);
11768 tree_view->priv->search_entry_changed_id = 0;
11770 if (tree_view->priv->typeselect_flush_timeout)
11772 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11773 tree_view->priv->typeselect_flush_timeout = 0;
11776 if (gtk_widget_get_visible (search_dialog))
11778 /* send focus-in event */
11779 send_focus_change (GTK_WIDGET (tree_view->priv->search_entry), FALSE);
11780 gtk_widget_hide (search_dialog);
11781 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
11782 send_focus_change (GTK_WIDGET (tree_view), TRUE);
11787 pspp_sheet_view_search_position_func (PsppSheetView *tree_view,
11788 GtkWidget *search_dialog,
11789 gpointer user_data)
11792 gint tree_x, tree_y;
11793 gint tree_width, tree_height;
11794 GdkWindow *tree_window = gtk_widget_get_window (GTK_WIDGET (tree_view));
11795 GdkScreen *screen = gdk_window_get_screen (tree_window);
11796 GtkRequisition requisition;
11798 GdkRectangle monitor;
11800 monitor_num = gdk_screen_get_monitor_at_window (screen, tree_window);
11801 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
11803 gtk_widget_realize (search_dialog);
11805 gdk_window_get_origin (tree_window, &tree_x, &tree_y);
11806 tree_width = gdk_window_get_width (tree_window);
11807 tree_height = gdk_window_get_height (tree_window);
11809 gtk_widget_size_request (search_dialog, &requisition);
11811 if (tree_x + tree_width > gdk_screen_get_width (screen))
11812 x = gdk_screen_get_width (screen) - requisition.width;
11813 else if (tree_x + tree_width - requisition.width < 0)
11816 x = tree_x + tree_width - requisition.width;
11818 if (tree_y + tree_height + requisition.height > gdk_screen_get_height (screen))
11819 y = gdk_screen_get_height (screen) - requisition.height;
11820 else if (tree_y + tree_height < 0) /* isn't really possible ... */
11823 y = tree_y + tree_height;
11825 gtk_window_move (GTK_WINDOW (search_dialog), x, y);
11829 pspp_sheet_view_search_disable_popdown (GtkEntry *entry,
11833 PsppSheetView *tree_view = (PsppSheetView *)data;
11835 tree_view->priv->disable_popdown = 1;
11836 g_signal_connect (menu, "hide",
11837 G_CALLBACK (pspp_sheet_view_search_enable_popdown), data);
11840 #if GTK3_TRANSITION
11841 /* Because we're visible but offscreen, we just set a flag in the preedit
11845 pspp_sheet_view_search_preedit_changed (GtkIMContext *im_context,
11846 PsppSheetView *tree_view)
11848 tree_view->priv->imcontext_changed = 1;
11849 if (tree_view->priv->typeselect_flush_timeout)
11851 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11852 tree_view->priv->typeselect_flush_timeout =
11853 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11854 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11862 pspp_sheet_view_search_activate (GtkEntry *entry,
11863 PsppSheetView *tree_view)
11868 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window,
11871 /* If we have a row selected and it's the cursor row, we activate
11873 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
11875 path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
11877 _pspp_sheet_view_find_node (tree_view, path, &node);
11879 if (node >= 0 && pspp_sheet_view_node_is_selected (tree_view, node))
11880 pspp_sheet_view_row_activated (tree_view, path, tree_view->priv->focus_column);
11882 gtk_tree_path_free (path);
11887 pspp_sheet_view_real_search_enable_popdown (gpointer data)
11889 PsppSheetView *tree_view = (PsppSheetView *)data;
11891 tree_view->priv->disable_popdown = 0;
11897 pspp_sheet_view_search_enable_popdown (GtkWidget *widget,
11900 gdk_threads_add_timeout_full (G_PRIORITY_HIGH, 200, pspp_sheet_view_real_search_enable_popdown, g_object_ref (data), g_object_unref);
11904 pspp_sheet_view_search_delete_event (GtkWidget *widget,
11905 GdkEventAny *event,
11906 PsppSheetView *tree_view)
11908 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11910 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11916 pspp_sheet_view_search_button_press_event (GtkWidget *widget,
11917 GdkEventButton *event,
11918 PsppSheetView *tree_view)
11920 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11922 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11924 if (event->window == tree_view->priv->bin_window)
11925 pspp_sheet_view_button_press (GTK_WIDGET (tree_view), event);
11931 pspp_sheet_view_search_scroll_event (GtkWidget *widget,
11932 GdkEventScroll *event,
11933 PsppSheetView *tree_view)
11935 gboolean retval = FALSE;
11937 if (event->direction == GDK_SCROLL_UP)
11939 pspp_sheet_view_search_move (widget, tree_view, TRUE);
11942 else if (event->direction == GDK_SCROLL_DOWN)
11944 pspp_sheet_view_search_move (widget, tree_view, FALSE);
11948 /* renew the flush timeout */
11949 if (retval && tree_view->priv->typeselect_flush_timeout
11950 && !tree_view->priv->search_custom_entry_set)
11952 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11953 tree_view->priv->typeselect_flush_timeout =
11954 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11955 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11963 pspp_sheet_view_search_key_press_event (GtkWidget *widget,
11964 GdkEventKey *event,
11965 PsppSheetView *tree_view)
11967 gboolean retval = FALSE;
11969 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11970 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11972 /* close window and cancel the search */
11973 if (!tree_view->priv->search_custom_entry_set
11974 && (event->keyval == GDK_Escape ||
11975 event->keyval == GDK_Tab ||
11976 event->keyval == GDK_KP_Tab ||
11977 event->keyval == GDK_ISO_Left_Tab))
11979 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11983 /* select previous matching iter */
11984 if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up)
11986 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
11987 gtk_widget_error_bell (widget);
11992 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK))
11993 && (event->keyval == GDK_g || event->keyval == GDK_G))
11995 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
11996 gtk_widget_error_bell (widget);
12001 /* select next matching iter */
12002 if (event->keyval == GDK_Down || event->keyval == GDK_KP_Down)
12004 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
12005 gtk_widget_error_bell (widget);
12010 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == GTK_DEFAULT_ACCEL_MOD_MASK)
12011 && (event->keyval == GDK_g || event->keyval == GDK_G))
12013 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
12014 gtk_widget_error_bell (widget);
12019 /* renew the flush timeout */
12020 if (retval && tree_view->priv->typeselect_flush_timeout
12021 && !tree_view->priv->search_custom_entry_set)
12023 g_source_remove (tree_view->priv->typeselect_flush_timeout);
12024 tree_view->priv->typeselect_flush_timeout =
12025 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
12026 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
12033 /* this function returns FALSE if there is a search string but
12034 * nothing was found, and TRUE otherwise.
12037 pspp_sheet_view_search_move (GtkWidget *window,
12038 PsppSheetView *tree_view,
12046 GtkTreeModel *model;
12047 PsppSheetSelection *selection;
12049 text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
12051 g_return_val_if_fail (text != NULL, FALSE);
12053 len = strlen (text);
12055 if (up && tree_view->priv->selected_iter == 1)
12056 return strlen (text) < 1;
12058 len = strlen (text);
12063 model = pspp_sheet_view_get_model (tree_view);
12064 selection = pspp_sheet_view_get_selection (tree_view);
12067 pspp_sheet_selection_unselect_all (selection);
12068 if (!gtk_tree_model_get_iter_first (model, &iter))
12071 ret = pspp_sheet_view_search_iter (model, selection, &iter, text,
12072 &count, up?((tree_view->priv->selected_iter) - 1):((tree_view->priv->selected_iter + 1)));
12077 tree_view->priv->selected_iter += up?(-1):(1);
12082 /* return to old iter */
12084 gtk_tree_model_get_iter_first (model, &iter);
12085 pspp_sheet_view_search_iter (model, selection,
12087 &count, tree_view->priv->selected_iter);
12093 pspp_sheet_view_search_equal_func (GtkTreeModel *model,
12097 gpointer search_data)
12099 gboolean retval = TRUE;
12101 gchar *normalized_string;
12102 gchar *normalized_key;
12103 gchar *case_normalized_string = NULL;
12104 gchar *case_normalized_key = NULL;
12105 GValue value = {0,};
12106 GValue transformed = {0,};
12108 gtk_tree_model_get_value (model, iter, column, &value);
12110 g_value_init (&transformed, G_TYPE_STRING);
12112 if (!g_value_transform (&value, &transformed))
12114 g_value_unset (&value);
12118 g_value_unset (&value);
12120 str = g_value_get_string (&transformed);
12123 g_value_unset (&transformed);
12127 normalized_string = g_utf8_normalize (str, -1, G_NORMALIZE_ALL);
12128 normalized_key = g_utf8_normalize (key, -1, G_NORMALIZE_ALL);
12130 if (normalized_string && normalized_key)
12132 case_normalized_string = g_utf8_casefold (normalized_string, -1);
12133 case_normalized_key = g_utf8_casefold (normalized_key, -1);
12135 if (strncmp (case_normalized_key, case_normalized_string, strlen (case_normalized_key)) == 0)
12139 g_value_unset (&transformed);
12140 g_free (normalized_key);
12141 g_free (normalized_string);
12142 g_free (case_normalized_key);
12143 g_free (case_normalized_string);
12149 pspp_sheet_view_search_iter (GtkTreeModel *model,
12150 PsppSheetSelection *selection,
12159 PsppSheetView *tree_view = pspp_sheet_selection_get_tree_view (selection);
12161 path = gtk_tree_model_get_path (model, iter);
12162 _pspp_sheet_view_find_node (tree_view, path, &node);
12166 gboolean done = FALSE;
12168 if (! tree_view->priv->search_equal_func (model, tree_view->priv->search_column, text, iter, tree_view->priv->search_user_data))
12173 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL,
12175 pspp_sheet_selection_select_iter (selection, iter);
12176 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE, 0);
12179 gtk_tree_path_free (path);
12188 node = pspp_sheet_view_node_next (tree_view, node);
12194 has_next = gtk_tree_model_iter_next (model, iter);
12197 gtk_tree_path_next (path);
12200 TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
12205 gtk_tree_path_free (path);
12207 /* we've run out of tree, done with this func */
12219 pspp_sheet_view_search_init (GtkWidget *entry,
12220 PsppSheetView *tree_view)
12226 GtkTreeModel *model;
12227 PsppSheetSelection *selection;
12229 g_return_if_fail (GTK_IS_ENTRY (entry));
12230 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12232 text = gtk_entry_get_text (GTK_ENTRY (entry));
12234 model = pspp_sheet_view_get_model (tree_view);
12235 selection = pspp_sheet_view_get_selection (tree_view);
12238 pspp_sheet_selection_unselect_all (selection);
12239 if (tree_view->priv->typeselect_flush_timeout
12240 && !tree_view->priv->search_custom_entry_set)
12242 g_source_remove (tree_view->priv->typeselect_flush_timeout);
12243 tree_view->priv->typeselect_flush_timeout =
12244 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
12245 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
12252 if (!gtk_tree_model_get_iter_first (model, &iter))
12255 ret = pspp_sheet_view_search_iter (model, selection,
12260 tree_view->priv->selected_iter = 1;
12264 pspp_sheet_view_remove_widget (GtkCellEditable *cell_editable,
12265 PsppSheetView *tree_view)
12267 if (tree_view->priv->edited_column == NULL)
12270 _pspp_sheet_view_column_stop_editing (tree_view->priv->edited_column);
12271 tree_view->priv->edited_column = NULL;
12273 if (gtk_widget_has_focus (GTK_WIDGET (cell_editable)))
12274 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
12276 g_signal_handlers_disconnect_by_func (cell_editable,
12277 pspp_sheet_view_remove_widget,
12279 g_signal_handlers_disconnect_by_func (cell_editable,
12280 pspp_sheet_view_editable_button_press_event,
12282 g_signal_handlers_disconnect_by_func (cell_editable,
12283 pspp_sheet_view_editable_clicked,
12286 gtk_container_remove (GTK_CONTAINER (tree_view),
12287 GTK_WIDGET (cell_editable));
12289 /* FIXME should only redraw a single node */
12290 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12294 pspp_sheet_view_start_editing (PsppSheetView *tree_view,
12295 GtkTreePath *cursor_path)
12298 GdkRectangle background_area;
12299 GdkRectangle cell_area;
12300 GtkCellEditable *editable_widget = NULL;
12301 gchar *path_string;
12302 guint flags = 0; /* can be 0, as the flags are primarily for rendering */
12303 gint retval = FALSE;
12306 g_assert (tree_view->priv->focus_column);
12308 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
12311 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
12312 if (cursor_node < 0)
12315 path_string = gtk_tree_path_to_string (cursor_path);
12316 gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path);
12318 pspp_sheet_view_column_cell_set_cell_data (tree_view->priv->focus_column,
12319 tree_view->priv->model,
12321 pspp_sheet_view_get_background_area (tree_view,
12323 tree_view->priv->focus_column,
12325 pspp_sheet_view_get_cell_area (tree_view,
12327 tree_view->priv->focus_column,
12330 if (_pspp_sheet_view_column_cell_event (tree_view->priv->focus_column,
12339 if (editable_widget != NULL)
12343 GtkCellRenderer *cell;
12346 cell = _pspp_sheet_view_column_get_edited_cell (tree_view->priv->focus_column);
12348 _pspp_sheet_view_column_get_neighbor_sizes (tree_view->priv->focus_column, cell, &left, &right);
12351 area.width -= right + left;
12353 pspp_sheet_view_real_start_editing (tree_view,
12354 tree_view->priv->focus_column,
12363 g_free (path_string);
12368 pspp_sheet_view_editable_button_press_event (GtkWidget *widget,
12369 GdkEventButton *event,
12370 PsppSheetView *sheet_view)
12374 node = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
12375 "pspp-sheet-view-node"));
12376 return pspp_sheet_view_row_head_clicked (sheet_view,
12378 sheet_view->priv->edited_column,
12383 pspp_sheet_view_editable_clicked (GtkButton *button,
12384 PsppSheetView *sheet_view)
12386 pspp_sheet_view_editable_button_press_event (GTK_WIDGET (button), NULL,
12391 is_all_selected (GtkWidget *widget)
12393 GtkEntryBuffer *buffer;
12394 gint start_pos, end_pos;
12396 if (!GTK_IS_ENTRY (widget))
12399 buffer = gtk_entry_get_buffer (GTK_ENTRY (widget));
12400 return (gtk_editable_get_selection_bounds (GTK_EDITABLE (widget),
12401 &start_pos, &end_pos)
12403 && end_pos == gtk_entry_buffer_get_length (buffer));
12407 is_at_left (GtkWidget *widget)
12409 return (GTK_IS_ENTRY (widget)
12410 && gtk_editable_get_position (GTK_EDITABLE (widget)) == 0);
12414 is_at_right (GtkWidget *widget)
12416 GtkEntryBuffer *buffer;
12419 if (!GTK_IS_ENTRY (widget))
12422 buffer = gtk_entry_get_buffer (GTK_ENTRY (widget));
12423 length = gtk_entry_buffer_get_length (buffer);
12424 return gtk_editable_get_position (GTK_EDITABLE (widget)) == length;
12428 pspp_sheet_view_event (GtkWidget *widget,
12429 GdkEventKey *event,
12430 PsppSheetView *tree_view)
12432 PsppSheetViewColumn *column;
12439 /* Intercept only key press events.
12440 It would make sense to use "key-press-event" instead of "event", but
12441 GtkEntry attaches its own signal handler to "key-press-event" that runs
12442 before ours and overrides our desired behavior for GDK_Up and GDK_Down.
12444 if (event->type != GDK_KEY_PRESS)
12447 keyval = event->keyval;
12449 switch (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK | GDK_MOD1_MASK))
12452 switch (event->keyval)
12454 case GDK_Left: case GDK_KP_Left:
12455 case GDK_Home: case GDK_KP_Home:
12456 if (!is_all_selected (widget) && !is_at_left (widget))
12460 case GDK_Right: case GDK_KP_Right:
12461 case GDK_End: case GDK_KP_End:
12462 if (!is_all_selected (widget) && !is_at_right (widget))
12466 case GDK_Up: case GDK_KP_Up:
12467 case GDK_Down: case GDK_KP_Down:
12470 case GDK_Page_Up: case GDK_KP_Page_Up:
12471 case GDK_Page_Down: case GDK_KP_Page_Down:
12482 case GDK_Tab: case GDK_KP_Tab:
12483 case GDK_ISO_Left_Tab:
12492 case GDK_SHIFT_MASK:
12493 switch (event->keyval)
12496 case GDK_ISO_Left_Tab:
12505 case GDK_CONTROL_MASK:
12506 switch (event->keyval)
12508 case GDK_Left: case GDK_KP_Left:
12509 if (!is_all_selected (widget) && !is_at_left (widget))
12513 case GDK_Right: case GDK_KP_Right:
12514 if (!is_all_selected (widget) && !is_at_right (widget))
12518 case GDK_Up: case GDK_KP_Up:
12519 case GDK_Down: case GDK_KP_Down:
12531 row = tree_view->priv->edited_row;
12532 column = tree_view->priv->edited_column;
12533 path = gtk_tree_path_new_from_indices (row, -1);
12535 pspp_sheet_view_stop_editing (tree_view, cancel);
12536 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
12538 pspp_sheet_view_set_cursor (tree_view, path, column, FALSE);
12539 gtk_tree_path_free (path);
12541 handled = gtk_binding_set_activate (edit_bindings, keyval, event->state,
12542 GTK_OBJECT (tree_view));
12544 g_signal_stop_emission_by_name (widget, "event");
12546 pspp_sheet_view_get_cursor (tree_view, &path, NULL);
12547 pspp_sheet_view_start_editing (tree_view, path);
12548 gtk_tree_path_free (path);
12554 pspp_sheet_view_override_cell_keypresses (GtkWidget *widget,
12557 PsppSheetView *sheet_view = data;
12559 g_signal_connect (widget, "event",
12560 G_CALLBACK (pspp_sheet_view_event),
12563 if (GTK_IS_CONTAINER (widget))
12564 gtk_container_foreach (GTK_CONTAINER (widget),
12565 pspp_sheet_view_override_cell_keypresses,
12570 pspp_sheet_view_real_start_editing (PsppSheetView *tree_view,
12571 PsppSheetViewColumn *column,
12573 GtkCellEditable *cell_editable,
12574 GdkRectangle *cell_area,
12578 PsppSheetSelectionMode mode = pspp_sheet_selection_get_mode (tree_view->priv->selection);
12579 gint pre_val = gtk_adjustment_get_value (tree_view->priv->vadjustment);
12580 GtkRequisition requisition;
12583 g_return_if_fail (gtk_tree_path_get_depth (path) == 1);
12585 tree_view->priv->edited_column = column;
12586 _pspp_sheet_view_column_start_editing (column, GTK_CELL_EDITABLE (cell_editable));
12588 row = gtk_tree_path_get_indices (path)[0];
12589 tree_view->priv->edited_row = row;
12590 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE, 0);
12591 cell_area->y += pre_val - (int)gtk_adjustment_get_value (tree_view->priv->vadjustment);
12593 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
12594 pspp_sheet_selection_select_column (tree_view->priv->selection, column);
12595 tree_view->priv->anchor_column = column;
12597 gtk_widget_size_request (GTK_WIDGET (cell_editable), &requisition);
12599 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
12601 if (requisition.height < cell_area->height)
12603 gint diff = cell_area->height - requisition.height;
12604 pspp_sheet_view_put (tree_view,
12605 GTK_WIDGET (cell_editable),
12606 cell_area->x, cell_area->y + diff/2,
12607 cell_area->width, requisition.height);
12611 pspp_sheet_view_put (tree_view,
12612 GTK_WIDGET (cell_editable),
12613 cell_area->x, cell_area->y,
12614 cell_area->width, cell_area->height);
12617 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (cell_editable),
12618 (GdkEvent *)event);
12620 gtk_widget_grab_focus (GTK_WIDGET (cell_editable));
12621 g_signal_connect (cell_editable, "remove-widget",
12622 G_CALLBACK (pspp_sheet_view_remove_widget), tree_view);
12623 if (mode == PSPP_SHEET_SELECTION_RECTANGLE && column->row_head &&
12624 GTK_IS_BUTTON (cell_editable))
12626 g_signal_connect (cell_editable, "button-press-event",
12627 G_CALLBACK (pspp_sheet_view_editable_button_press_event),
12629 g_object_set_data (G_OBJECT (cell_editable), "pspp-sheet-view-node",
12630 GINT_TO_POINTER (row));
12631 g_signal_connect (cell_editable, "clicked",
12632 G_CALLBACK (pspp_sheet_view_editable_clicked),
12636 pspp_sheet_view_override_cell_keypresses (GTK_WIDGET (cell_editable),
12641 pspp_sheet_view_stop_editing (PsppSheetView *tree_view,
12642 gboolean cancel_editing)
12644 PsppSheetViewColumn *column;
12645 GtkCellRenderer *cell;
12647 if (tree_view->priv->edited_column == NULL)
12651 * This is very evil. We need to do this, because
12652 * gtk_cell_editable_editing_done may trigger pspp_sheet_view_row_changed
12653 * later on. If pspp_sheet_view_row_changed notices
12654 * tree_view->priv->edited_column != NULL, it'll call
12655 * pspp_sheet_view_stop_editing again. Bad things will happen then.
12657 * Please read that again if you intend to modify anything here.
12660 column = tree_view->priv->edited_column;
12661 tree_view->priv->edited_column = NULL;
12663 cell = _pspp_sheet_view_column_get_edited_cell (column);
12664 gtk_cell_renderer_stop_editing (cell, cancel_editing);
12666 if (!cancel_editing)
12667 gtk_cell_editable_editing_done (column->editable_widget);
12669 tree_view->priv->edited_column = column;
12671 gtk_cell_editable_remove_widget (column->editable_widget);
12676 * pspp_sheet_view_set_hover_selection:
12677 * @tree_view: a #PsppSheetView
12678 * @hover: %TRUE to enable hover selection mode
12680 * Enables of disables the hover selection mode of @tree_view.
12681 * Hover selection makes the selected row follow the pointer.
12682 * Currently, this works only for the selection modes
12683 * %PSPP_SHEET_SELECTION_SINGLE and %PSPP_SHEET_SELECTION_BROWSE.
12688 pspp_sheet_view_set_hover_selection (PsppSheetView *tree_view,
12691 hover = hover != FALSE;
12693 if (hover != tree_view->priv->hover_selection)
12695 tree_view->priv->hover_selection = hover;
12697 g_object_notify (G_OBJECT (tree_view), "hover-selection");
12702 * pspp_sheet_view_get_hover_selection:
12703 * @tree_view: a #PsppSheetView
12705 * Returns whether hover selection mode is turned on for @tree_view.
12707 * Return value: %TRUE if @tree_view is in hover selection mode
12712 pspp_sheet_view_get_hover_selection (PsppSheetView *tree_view)
12714 return tree_view->priv->hover_selection;
12718 * pspp_sheet_view_set_rubber_banding:
12719 * @tree_view: a #PsppSheetView
12720 * @enable: %TRUE to enable rubber banding
12722 * Enables or disables rubber banding in @tree_view. If the selection mode is
12723 * #PSPP_SHEET_SELECTION_MULTIPLE or #PSPP_SHEET_SELECTION_RECTANGLE, rubber
12724 * banding will allow the user to select multiple rows by dragging the mouse.
12729 pspp_sheet_view_set_rubber_banding (PsppSheetView *tree_view,
12732 enable = enable != FALSE;
12734 if (enable != tree_view->priv->rubber_banding_enable)
12736 tree_view->priv->rubber_banding_enable = enable;
12738 g_object_notify (G_OBJECT (tree_view), "rubber-banding");
12743 * pspp_sheet_view_get_rubber_banding:
12744 * @tree_view: a #PsppSheetView
12746 * Returns whether rubber banding is turned on for @tree_view. If the
12747 * selection mode is #PSPP_SHEET_SELECTION_MULTIPLE or
12748 * #PSPP_SHEET_SELECTION_RECTANGLE, rubber banding will allow the user to
12749 * select multiple rows by dragging the mouse.
12751 * Return value: %TRUE if rubber banding in @tree_view is enabled.
12756 pspp_sheet_view_get_rubber_banding (PsppSheetView *tree_view)
12758 return tree_view->priv->rubber_banding_enable;
12762 * pspp_sheet_view_is_rubber_banding_active:
12763 * @tree_view: a #PsppSheetView
12765 * Returns whether a rubber banding operation is currently being done
12768 * Return value: %TRUE if a rubber banding operation is currently being
12769 * done in @tree_view.
12774 pspp_sheet_view_is_rubber_banding_active (PsppSheetView *tree_view)
12776 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
12778 if (tree_view->priv->rubber_banding_enable
12779 && tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
12786 pspp_sheet_view_grab_notify (GtkWidget *widget,
12787 gboolean was_grabbed)
12789 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12791 tree_view->priv->in_grab = !was_grabbed;
12795 tree_view->priv->pressed_button = -1;
12797 if (tree_view->priv->rubber_band_status)
12798 pspp_sheet_view_stop_rubber_band (tree_view);
12803 pspp_sheet_view_state_changed (GtkWidget *widget,
12804 GtkStateType previous_state)
12806 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12808 if (gtk_widget_get_realized (widget))
12810 GtkStyle *style = gtk_widget_get_style (widget);
12811 gdk_window_set_background (tree_view->priv->bin_window, &style->base[gtk_widget_get_state (widget)]);
12814 gtk_widget_queue_draw (widget);
12818 * pspp_sheet_view_get_grid_lines:
12819 * @tree_view: a #PsppSheetView
12821 * Returns which grid lines are enabled in @tree_view.
12823 * Return value: a #PsppSheetViewGridLines value indicating which grid lines
12828 PsppSheetViewGridLines
12829 pspp_sheet_view_get_grid_lines (PsppSheetView *tree_view)
12831 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12833 return tree_view->priv->grid_lines;
12837 * pspp_sheet_view_set_grid_lines:
12838 * @tree_view: a #PsppSheetView
12839 * @grid_lines: a #PsppSheetViewGridLines value indicating which grid lines to
12842 * Sets which grid lines to draw in @tree_view.
12847 pspp_sheet_view_set_grid_lines (PsppSheetView *tree_view,
12848 PsppSheetViewGridLines grid_lines)
12850 PsppSheetViewPrivate *priv;
12851 PsppSheetViewGridLines old_grid_lines;
12853 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12855 priv = tree_view->priv;
12857 old_grid_lines = priv->grid_lines;
12858 priv->grid_lines = grid_lines;
12860 if (old_grid_lines != grid_lines)
12862 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12864 g_object_notify (G_OBJECT (tree_view), "enable-grid-lines");
12869 * pspp_sheet_view_get_special_cells:
12870 * @tree_view: a #PsppSheetView
12872 * Returns which grid lines are enabled in @tree_view.
12874 * Return value: a #PsppSheetViewSpecialCells value indicating whether rows in
12875 * the sheet view contain special cells.
12877 PsppSheetViewSpecialCells
12878 pspp_sheet_view_get_special_cells (PsppSheetView *tree_view)
12880 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12882 return tree_view->priv->special_cells;
12886 * pspp_sheet_view_set_special_cells:
12887 * @tree_view: a #PsppSheetView
12888 * @special_cells: a #PsppSheetViewSpecialCells value indicating whether rows in
12889 * the sheet view contain special cells.
12891 * Sets whether rows in the sheet view contain special cells, controlling the
12892 * rendering of row selections.
12895 pspp_sheet_view_set_special_cells (PsppSheetView *tree_view,
12896 PsppSheetViewSpecialCells special_cells)
12898 PsppSheetViewPrivate *priv;
12900 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12902 priv = tree_view->priv;
12904 if (priv->special_cells != special_cells)
12906 priv->special_cells = special_cells;
12907 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12908 g_object_notify (G_OBJECT (tree_view), "special-cells");
12913 pspp_sheet_view_get_fixed_height (const PsppSheetView *tree_view)
12915 /* XXX (re)calculate fixed_height if necessary */
12916 return tree_view->priv->fixed_height;
12920 pspp_sheet_view_set_fixed_height (PsppSheetView *tree_view,
12923 g_return_if_fail (fixed_height > 0);
12925 if (tree_view->priv->fixed_height != fixed_height)
12927 tree_view->priv->fixed_height = fixed_height;
12928 g_object_notify (G_OBJECT (tree_view), "fixed-height");
12930 if (!tree_view->priv->fixed_height_set)
12932 tree_view->priv->fixed_height_set = TRUE;
12933 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
12938 * pspp_sheet_view_set_tooltip_row:
12939 * @tree_view: a #PsppSheetView
12940 * @tooltip: a #GtkTooltip
12941 * @path: a #GtkTreePath
12943 * Sets the tip area of @tooltip to be the area covered by the row at @path.
12944 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
12945 * See also gtk_tooltip_set_tip_area().
12950 pspp_sheet_view_set_tooltip_row (PsppSheetView *tree_view,
12951 GtkTooltip *tooltip,
12954 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12955 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
12957 pspp_sheet_view_set_tooltip_cell (tree_view, tooltip, path, NULL, NULL);
12961 * pspp_sheet_view_set_tooltip_cell:
12962 * @tree_view: a #PsppSheetView
12963 * @tooltip: a #GtkTooltip
12964 * @path: (allow-none): a #GtkTreePath or %NULL
12965 * @column: (allow-none): a #PsppSheetViewColumn or %NULL
12966 * @cell: (allow-none): a #GtkCellRenderer or %NULL
12968 * Sets the tip area of @tooltip to the area @path, @column and @cell have
12969 * in common. For example if @path is %NULL and @column is set, the tip
12970 * area will be set to the full area covered by @column. See also
12971 * gtk_tooltip_set_tip_area().
12973 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
12978 pspp_sheet_view_set_tooltip_cell (PsppSheetView *tree_view,
12979 GtkTooltip *tooltip,
12981 PsppSheetViewColumn *column,
12982 GtkCellRenderer *cell)
12986 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12987 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
12988 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
12989 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
12991 /* Determine x values. */
12992 if (column && cell)
12997 pspp_sheet_view_get_cell_area (tree_view, path, column, &tmp);
12998 pspp_sheet_view_column_cell_get_position (column, cell, &start, &width);
13000 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
13003 rect.width = width;
13009 pspp_sheet_view_get_background_area (tree_view, NULL, column, &tmp);
13010 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
13013 rect.width = tmp.width;
13017 GtkAllocation allocation;
13018 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
13020 rect.width = allocation.width;
13023 /* Determine y values. */
13028 pspp_sheet_view_get_background_area (tree_view, path, NULL, &tmp);
13029 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
13032 rect.height = tmp.height;
13037 rect.height = gtk_adjustment_get_page_size (tree_view->priv->vadjustment);
13040 gtk_tooltip_set_tip_area (tooltip, &rect);
13044 * pspp_sheet_view_get_tooltip_context:
13045 * @tree_view: a #PsppSheetView
13046 * @x: the x coordinate (relative to widget coordinates)
13047 * @y: the y coordinate (relative to widget coordinates)
13048 * @keyboard_tip: whether this is a keyboard tooltip or not
13049 * @model: (allow-none): a pointer to receive a #GtkTreeModel or %NULL
13050 * @path: (allow-none): a pointer to receive a #GtkTreePath or %NULL
13051 * @iter: (allow-none): a pointer to receive a #GtkTreeIter or %NULL
13053 * This function is supposed to be used in a #GtkWidget::query-tooltip
13054 * signal handler for #PsppSheetView. The @x, @y and @keyboard_tip values
13055 * which are received in the signal handler, should be passed to this
13056 * function without modification.
13058 * The return value indicates whether there is a tree view row at the given
13059 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
13060 * tooltips the row returned will be the cursor row. When %TRUE, then any of
13061 * @model, @path and @iter which have been provided will be set to point to
13062 * that row and the corresponding model. @x and @y will always be converted
13063 * to be relative to @tree_view's bin_window if @keyboard_tooltip is %FALSE.
13065 * Return value: whether or not the given tooltip context points to a row.
13070 pspp_sheet_view_get_tooltip_context (PsppSheetView *tree_view,
13073 gboolean keyboard_tip,
13074 GtkTreeModel **model,
13075 GtkTreePath **path,
13078 GtkTreePath *tmppath = NULL;
13080 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
13081 g_return_val_if_fail (x != NULL, FALSE);
13082 g_return_val_if_fail (y != NULL, FALSE);
13086 pspp_sheet_view_get_cursor (tree_view, &tmppath, NULL);
13093 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, *x, *y,
13096 if (!pspp_sheet_view_get_path_at_pos (tree_view, *x, *y,
13097 &tmppath, NULL, NULL, NULL))
13102 *model = pspp_sheet_view_get_model (tree_view);
13105 gtk_tree_model_get_iter (pspp_sheet_view_get_model (tree_view),
13111 gtk_tree_path_free (tmppath);
13117 pspp_sheet_view_set_tooltip_query_cb (GtkWidget *widget,
13120 gboolean keyboard_tip,
13121 GtkTooltip *tooltip,
13124 GValue value = { 0, };
13125 GValue transformed = { 0, };
13128 GtkTreeModel *model;
13129 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
13131 if (!pspp_sheet_view_get_tooltip_context (PSPP_SHEET_VIEW (widget),
13134 &model, &path, &iter))
13137 gtk_tree_model_get_value (model, &iter,
13138 tree_view->priv->tooltip_column, &value);
13140 g_value_init (&transformed, G_TYPE_STRING);
13142 if (!g_value_transform (&value, &transformed))
13144 g_value_unset (&value);
13145 gtk_tree_path_free (path);
13150 g_value_unset (&value);
13152 if (!g_value_get_string (&transformed))
13154 g_value_unset (&transformed);
13155 gtk_tree_path_free (path);
13160 gtk_tooltip_set_markup (tooltip, g_value_get_string (&transformed));
13161 pspp_sheet_view_set_tooltip_row (tree_view, tooltip, path);
13163 gtk_tree_path_free (path);
13164 g_value_unset (&transformed);
13170 * pspp_sheet_view_set_tooltip_column:
13171 * @tree_view: a #PsppSheetView
13172 * @column: an integer, which is a valid column number for @tree_view's model
13174 * If you only plan to have simple (text-only) tooltips on full rows, you
13175 * can use this function to have #PsppSheetView handle these automatically
13176 * for you. @column should be set to the column in @tree_view's model
13177 * containing the tooltip texts, or -1 to disable this feature.
13179 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
13180 * @tree_view will connect a #GtkWidget::query-tooltip signal handler.
13182 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
13183 * so &, <, etc have to be escaped in the text.
13188 pspp_sheet_view_set_tooltip_column (PsppSheetView *tree_view,
13191 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
13193 if (column == tree_view->priv->tooltip_column)
13198 g_signal_handlers_disconnect_by_func (tree_view,
13199 pspp_sheet_view_set_tooltip_query_cb,
13201 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), FALSE);
13205 if (tree_view->priv->tooltip_column == -1)
13207 g_signal_connect (tree_view, "query-tooltip",
13208 G_CALLBACK (pspp_sheet_view_set_tooltip_query_cb), NULL);
13209 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), TRUE);
13213 tree_view->priv->tooltip_column = column;
13214 g_object_notify (G_OBJECT (tree_view), "tooltip-column");
13218 * pspp_sheet_view_get_tooltip_column:
13219 * @tree_view: a #PsppSheetView
13221 * Returns the column of @tree_view's model which is being used for
13222 * displaying tooltips on @tree_view's rows.
13224 * Return value: the index of the tooltip column that is currently being
13225 * used, or -1 if this is disabled.
13230 pspp_sheet_view_get_tooltip_column (PsppSheetView *tree_view)
13232 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
13234 return tree_view->priv->tooltip_column;
13238 _gtk_boolean_handled_accumulator (GSignalInvocationHint *ihint,
13239 GValue *return_accu,
13240 const GValue *handler_return,
13243 gboolean continue_emission;
13244 gboolean signal_handled;
13246 signal_handled = g_value_get_boolean (handler_return);
13247 g_value_set_boolean (return_accu, signal_handled);
13248 continue_emission = !signal_handled;
13250 return continue_emission;
13255 pspp_sheet_view_grid_lines_get_type (void)
13257 static GType etype = 0;
13258 if (G_UNLIKELY(etype == 0)) {
13259 static const GEnumValue values[] = {
13260 { PSPP_SHEET_VIEW_GRID_LINES_NONE, "PSPP_SHEET_VIEW_GRID_LINES_NONE", "none" },
13261 { PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL, "PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL", "horizontal" },
13262 { PSPP_SHEET_VIEW_GRID_LINES_VERTICAL, "PSPP_SHEET_VIEW_GRID_LINES_VERTICAL", "vertical" },
13263 { PSPP_SHEET_VIEW_GRID_LINES_BOTH, "PSPP_SHEET_VIEW_GRID_LINES_BOTH", "both" },
13266 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewGridLines"), values);
13272 pspp_sheet_view_special_cells_get_type (void)
13274 static GType etype = 0;
13275 if (G_UNLIKELY(etype == 0)) {
13276 static const GEnumValue values[] = {
13277 { PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT, "PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT", "detect" },
13278 { PSPP_SHEET_VIEW_SPECIAL_CELLS_YES, "PSPP_SHEET_VIEW_SPECIAL_CELLS_YES", "yes" },
13279 { PSPP_SHEET_VIEW_SPECIAL_CELLS_NO, "PSPP_SHEET_VIEW_SPECIAL_CELLS_NO", "no" },
13282 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewSpecialCells"), values);