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.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1482 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
1484 gtk_widget_set_window (widget,
1485 gdk_window_new (gtk_widget_get_parent_window (widget),
1486 &attributes, attributes_mask));
1487 gdk_window_set_user_data (gtk_widget_get_window (widget), widget);
1489 /* Make the window for the tree */
1491 attributes.y = TREE_VIEW_HEADER_HEIGHT (tree_view);
1492 attributes.width = MAX (tree_view->priv->width, old_allocation.width);
1493 attributes.height = old_allocation.height;
1494 attributes.event_mask = (GDK_EXPOSURE_MASK |
1496 GDK_POINTER_MOTION_MASK |
1497 GDK_ENTER_NOTIFY_MASK |
1498 GDK_LEAVE_NOTIFY_MASK |
1499 GDK_BUTTON_PRESS_MASK |
1500 GDK_BUTTON_RELEASE_MASK |
1501 gtk_widget_get_events (widget));
1503 tree_view->priv->bin_window = gdk_window_new (gtk_widget_get_window (widget),
1504 &attributes, attributes_mask);
1505 gdk_window_set_user_data (tree_view->priv->bin_window, widget);
1507 /* Make the column header window */
1510 attributes.width = MAX (tree_view->priv->width, old_allocation.width);
1511 attributes.height = tree_view->priv->header_height;
1512 attributes.event_mask = (GDK_EXPOSURE_MASK |
1514 GDK_BUTTON_PRESS_MASK |
1515 GDK_BUTTON_RELEASE_MASK |
1516 GDK_KEY_PRESS_MASK |
1517 GDK_KEY_RELEASE_MASK |
1518 gtk_widget_get_events (widget));
1520 tree_view->priv->header_window = gdk_window_new (gtk_widget_get_window (widget),
1521 &attributes, attributes_mask);
1522 gdk_window_set_user_data (tree_view->priv->header_window, widget);
1524 /* Add them all up. */
1525 gtk_widget_set_style (widget,
1526 gtk_style_attach (gtk_widget_get_style (widget), gtk_widget_get_window (widget)));
1527 gdk_window_set_background (tree_view->priv->bin_window, >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
1528 gtk_style_set_background (gtk_widget_get_style (widget), tree_view->priv->header_window, GTK_STATE_NORMAL);
1530 tmp_list = tree_view->priv->children;
1533 PsppSheetViewChild *child = tmp_list->data;
1534 tmp_list = tmp_list->next;
1536 gtk_widget_set_parent_window (child->widget, tree_view->priv->bin_window);
1539 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
1540 _pspp_sheet_view_column_realize_button (PSPP_SHEET_VIEW_COLUMN (tmp_list->data));
1542 /* Need to call those here, since they create GCs */
1543 pspp_sheet_view_set_grid_lines (tree_view, tree_view->priv->grid_lines);
1545 install_presize_handler (tree_view);
1549 pspp_sheet_view_unrealize (GtkWidget *widget)
1551 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1552 PsppSheetViewPrivate *priv = tree_view->priv;
1555 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->unrealize (widget);
1557 if (priv->scroll_timeout != 0)
1559 g_source_remove (priv->scroll_timeout);
1560 priv->scroll_timeout = 0;
1563 if (priv->open_dest_timeout != 0)
1565 g_source_remove (priv->open_dest_timeout);
1566 priv->open_dest_timeout = 0;
1569 if (priv->presize_handler_timer != 0)
1571 g_source_remove (priv->presize_handler_timer);
1572 priv->presize_handler_timer = 0;
1575 if (priv->validate_rows_timer != 0)
1577 g_source_remove (priv->validate_rows_timer);
1578 priv->validate_rows_timer = 0;
1581 if (priv->scroll_sync_timer != 0)
1583 g_source_remove (priv->scroll_sync_timer);
1584 priv->scroll_sync_timer = 0;
1587 if (priv->typeselect_flush_timeout)
1589 g_source_remove (priv->typeselect_flush_timeout);
1590 priv->typeselect_flush_timeout = 0;
1593 for (list = priv->columns; list; list = list->next)
1594 _pspp_sheet_view_column_unrealize_button (PSPP_SHEET_VIEW_COLUMN (list->data));
1596 gdk_window_set_user_data (priv->bin_window, NULL);
1597 gdk_window_destroy (priv->bin_window);
1598 priv->bin_window = NULL;
1600 gdk_window_set_user_data (priv->header_window, NULL);
1601 gdk_window_destroy (priv->header_window);
1602 priv->header_window = NULL;
1604 if (priv->drag_window)
1606 gdk_window_set_user_data (priv->drag_window, NULL);
1607 gdk_window_destroy (priv->drag_window);
1608 priv->drag_window = NULL;
1611 if (priv->drag_highlight_window)
1613 gdk_window_set_user_data (priv->drag_highlight_window, NULL);
1614 gdk_window_destroy (priv->drag_highlight_window);
1615 priv->drag_highlight_window = NULL;
1618 if (tree_view->priv->columns != NULL)
1620 list = tree_view->priv->columns;
1623 PsppSheetViewColumn *column;
1624 column = PSPP_SHEET_VIEW_COLUMN (list->data);
1626 pspp_sheet_view_remove_column (tree_view, column);
1628 tree_view->priv->columns = NULL;
1632 /* GtkWidget::size_request helper */
1634 pspp_sheet_view_size_request_columns (PsppSheetView *tree_view)
1638 tree_view->priv->header_height = 0;
1640 if (tree_view->priv->model)
1642 for (list = tree_view->priv->columns; list; list = list->next)
1644 GtkRequisition requisition;
1645 PsppSheetViewColumn *column = list->data;
1647 pspp_sheet_view_column_size_request (column, &requisition);
1648 column->button_request = requisition.width;
1649 tree_view->priv->header_height = MAX (tree_view->priv->header_height, requisition.height);
1655 /* Called only by ::size_request */
1657 pspp_sheet_view_update_size (PsppSheetView *tree_view)
1660 PsppSheetViewColumn *column;
1663 if (tree_view->priv->model == NULL)
1665 tree_view->priv->width = 0;
1666 tree_view->priv->prev_width = 0;
1667 tree_view->priv->height = 0;
1671 tree_view->priv->prev_width = tree_view->priv->width;
1672 tree_view->priv->width = 0;
1674 /* keep this in sync with size_allocate below */
1675 for (list = tree_view->priv->columns, i = 0; list; list = list->next, i++)
1677 gint real_requested_width = 0;
1678 column = list->data;
1679 if (!column->visible)
1682 if (column->use_resized_width)
1684 real_requested_width = column->resized_width;
1688 real_requested_width = column->fixed_width;
1691 if (column->min_width != -1)
1692 real_requested_width = MAX (real_requested_width, column->min_width);
1693 if (column->max_width != -1)
1694 real_requested_width = MIN (real_requested_width, column->max_width);
1696 tree_view->priv->width += real_requested_width;
1699 tree_view->priv->height = tree_view->priv->fixed_height * tree_view->priv->row_count;
1703 pspp_sheet_view_size_request (GtkWidget *widget,
1704 GtkRequisition *requisition)
1706 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1709 /* we validate some rows initially just to make sure we have some size.
1710 * In practice, with a lot of static lists, this should get a good width.
1712 initialize_fixed_height_mode (tree_view);
1713 pspp_sheet_view_size_request_columns (tree_view);
1714 pspp_sheet_view_update_size (PSPP_SHEET_VIEW (widget));
1716 requisition->width = tree_view->priv->width;
1717 requisition->height = tree_view->priv->height + TREE_VIEW_HEADER_HEIGHT (tree_view);
1719 tmp_list = tree_view->priv->children;
1723 PsppSheetViewChild *child = tmp_list->data;
1724 GtkRequisition child_requisition;
1726 tmp_list = tmp_list->next;
1728 if (gtk_widget_get_visible (child->widget))
1729 gtk_widget_size_request (child->widget, &child_requisition);
1734 invalidate_column (PsppSheetView *tree_view,
1735 PsppSheetViewColumn *column)
1737 gint column_offset = 0;
1739 GtkWidget *widget = GTK_WIDGET (tree_view);
1742 if (!gtk_widget_get_realized (widget))
1745 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
1746 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
1748 list = (rtl ? list->prev : list->next))
1750 PsppSheetViewColumn *tmpcolumn = list->data;
1751 if (tmpcolumn == column)
1753 GdkRectangle invalid_rect;
1754 GtkAllocation allocation;
1756 gtk_widget_get_allocation (widget, &allocation);
1757 invalid_rect.x = column_offset;
1759 invalid_rect.width = column->width;
1760 invalid_rect.height = allocation.height;
1762 gdk_window_invalidate_rect (gtk_widget_get_window (widget), &invalid_rect, TRUE);
1766 column_offset += tmpcolumn->width;
1771 invalidate_last_column (PsppSheetView *tree_view)
1776 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
1778 for (last_column = (rtl ? g_list_first (tree_view->priv->columns) : g_list_last (tree_view->priv->columns));
1780 last_column = (rtl ? last_column->next : last_column->prev))
1782 if (PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible)
1784 invalidate_column (tree_view, last_column->data);
1791 pspp_sheet_view_get_real_requested_width_from_column (PsppSheetView *tree_view,
1792 PsppSheetViewColumn *column)
1794 gint real_requested_width;
1796 if (column->use_resized_width)
1798 real_requested_width = column->resized_width;
1802 real_requested_width = column->fixed_width;
1805 if (column->min_width != -1)
1806 real_requested_width = MAX (real_requested_width, column->min_width);
1807 if (column->max_width != -1)
1808 real_requested_width = MIN (real_requested_width, column->max_width);
1810 return real_requested_width;
1814 span_intersects (int a0, int a_width,
1815 int b0, int b_width)
1817 int a1 = a0 + a_width;
1818 int b1 = b0 + b_width;
1819 return (a0 >= b0 && a0 < b1) || (b0 >= a0 && b0 < a1);
1822 /* GtkWidget::size_allocate helper */
1824 pspp_sheet_view_size_allocate_columns (GtkWidget *widget,
1825 gboolean *width_changed)
1827 PsppSheetView *tree_view;
1828 GList *list, *first_column, *last_column;
1829 PsppSheetViewColumn *column;
1830 GtkAllocation col_allocation;
1831 GtkAllocation allocation;
1833 gint extra, extra_per_column;
1834 gint full_requested_width = 0;
1835 gint number_of_expand_columns = 0;
1836 gboolean column_changed = FALSE;
1839 tree_view = PSPP_SHEET_VIEW (widget);
1841 for (last_column = g_list_last (tree_view->priv->columns);
1842 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
1843 last_column = last_column->prev)
1846 if (last_column == NULL)
1849 for (first_column = g_list_first (tree_view->priv->columns);
1850 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
1851 first_column = first_column->next)
1854 col_allocation.y = 0;
1855 col_allocation.height = tree_view->priv->header_height;
1857 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1859 /* find out how many extra space and expandable columns we have */
1860 for (list = tree_view->priv->columns; list != last_column->next; list = list->next)
1862 column = (PsppSheetViewColumn *)list->data;
1864 if (!column->visible)
1867 full_requested_width += pspp_sheet_view_get_real_requested_width_from_column (tree_view, column);
1870 number_of_expand_columns++;
1873 gtk_widget_get_allocation (widget, &allocation);
1874 extra = MAX (allocation.width - full_requested_width, 0);
1875 if (number_of_expand_columns > 0)
1876 extra_per_column = extra/number_of_expand_columns;
1878 extra_per_column = 0;
1880 for (list = (rtl ? last_column : first_column);
1881 list != (rtl ? first_column->prev : last_column->next);
1882 list = (rtl ? list->prev : list->next))
1884 gint real_requested_width = 0;
1887 column = list->data;
1888 old_width = column->width;
1890 if (!column->visible)
1893 /* We need to handle the dragged button specially.
1895 if (column == tree_view->priv->drag_column)
1897 GtkAllocation drag_allocation;
1898 drag_allocation.width = gdk_window_get_width (tree_view->priv->drag_window);
1899 drag_allocation.height = gdk_window_get_height (tree_view->priv->drag_window);
1900 drag_allocation.x = 0;
1901 drag_allocation.y = 0;
1902 pspp_sheet_view_column_size_allocate (tree_view->priv->drag_column,
1904 width += drag_allocation.width;
1908 real_requested_width = pspp_sheet_view_get_real_requested_width_from_column (tree_view, column);
1910 col_allocation.x = width;
1911 column->width = real_requested_width;
1915 if (number_of_expand_columns == 1)
1917 /* We add the remander to the last column as
1919 column->width += extra;
1923 column->width += extra_per_column;
1924 extra -= extra_per_column;
1925 number_of_expand_columns --;
1929 if (column->width != old_width)
1930 g_object_notify (G_OBJECT (column), "width");
1932 col_allocation.width = column->width;
1933 width += column->width;
1935 if (column->width > old_width)
1936 column_changed = TRUE;
1938 pspp_sheet_view_column_size_allocate (column, &col_allocation);
1940 if (span_intersects (col_allocation.x, col_allocation.width,
1941 gtk_adjustment_get_value (tree_view->priv->hadjustment),
1943 && gtk_widget_get_realized (widget))
1944 pspp_sheet_view_column_set_need_button (column, TRUE);
1947 gdk_window_move_resize (column->window,
1948 col_allocation.x + (rtl ? 0 : col_allocation.width) - TREE_VIEW_DRAG_WIDTH/2,
1950 TREE_VIEW_DRAG_WIDTH, col_allocation.height);
1953 /* We change the width here. The user might have been resizing columns,
1954 * so the total width of the tree view changes.
1956 tree_view->priv->width = width;
1958 *width_changed = TRUE;
1961 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
1965 pspp_sheet_view_size_allocate (GtkWidget *widget,
1966 GtkAllocation *allocation)
1968 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1970 gboolean width_changed = FALSE;
1971 GtkAllocation old_allocation;
1972 gtk_widget_get_allocation (widget, &old_allocation);
1974 if (allocation->width != old_allocation.width)
1975 width_changed = TRUE;
1978 gtk_widget_set_allocation (widget, allocation);
1980 tmp_list = tree_view->priv->children;
1984 GtkAllocation allocation;
1986 PsppSheetViewChild *child = tmp_list->data;
1987 tmp_list = tmp_list->next;
1989 /* totally ignore our child's requisition */
1990 allocation.x = child->x;
1991 allocation.y = child->y;
1992 allocation.width = child->width;
1993 allocation.height = child->height;
1994 gtk_widget_size_allocate (child->widget, &allocation);
1997 /* We size-allocate the columns first because the width of the
1998 * tree view (used in updating the adjustments below) might change.
2000 pspp_sheet_view_size_allocate_columns (widget, &width_changed);
2002 gtk_adjustment_set_page_size (tree_view->priv->hadjustment, allocation->width);
2003 gtk_adjustment_set_page_increment (tree_view->priv->hadjustment, allocation->width * 0.9);
2004 gtk_adjustment_set_step_increment (tree_view->priv->hadjustment, allocation->width * 0.1);
2005 gtk_adjustment_set_lower (tree_view->priv->hadjustment, 0);
2006 gtk_adjustment_set_upper (tree_view->priv->hadjustment, MAX (gtk_adjustment_get_page_size (tree_view->priv->hadjustment), tree_view->priv->width));
2008 if (gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL)
2010 if (allocation->width < tree_view->priv->width)
2012 if (tree_view->priv->init_hadjust_value)
2014 gtk_adjustment_set_value (tree_view->priv->hadjustment, MAX (tree_view->priv->width - allocation->width, 0));
2015 tree_view->priv->init_hadjust_value = FALSE;
2017 else if (allocation->width != old_allocation.width)
2019 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));
2022 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));
2026 gtk_adjustment_set_value (tree_view->priv->hadjustment, 0);
2027 tree_view->priv->init_hadjust_value = TRUE;
2031 if (gtk_adjustment_get_value (tree_view->priv->hadjustment) + allocation->width > tree_view->priv->width)
2032 gtk_adjustment_set_value (tree_view->priv->hadjustment, MAX (tree_view->priv->width - allocation->width, 0));
2034 gtk_adjustment_changed (tree_view->priv->hadjustment);
2036 gtk_adjustment_set_page_size (tree_view->priv->vadjustment, allocation->height - TREE_VIEW_HEADER_HEIGHT (tree_view));
2037 gtk_adjustment_set_step_increment (tree_view->priv->vadjustment, gtk_adjustment_get_page_size (tree_view->priv->vadjustment) * 0.1);
2038 gtk_adjustment_set_page_increment (tree_view->priv->vadjustment, gtk_adjustment_get_page_size (tree_view->priv->vadjustment) * 0.9);
2039 gtk_adjustment_set_lower (tree_view->priv->vadjustment, 0);
2040 gtk_adjustment_set_upper (tree_view->priv->vadjustment, MAX (gtk_adjustment_get_page_size (tree_view->priv->vadjustment), tree_view->priv->height));
2042 gtk_adjustment_changed (tree_view->priv->vadjustment);
2044 /* now the adjustments and window sizes are in sync, we can sync toprow/dy again */
2045 if (tree_view->priv->height <= gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
2046 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment), 0);
2047 else if (gtk_adjustment_get_value (tree_view->priv->vadjustment) + gtk_adjustment_get_page_size (tree_view->priv->vadjustment) > tree_view->priv->height)
2048 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment),
2049 tree_view->priv->height - gtk_adjustment_get_page_size (tree_view->priv->vadjustment));
2050 else if (gtk_tree_row_reference_valid (tree_view->priv->top_row))
2051 pspp_sheet_view_top_row_to_dy (tree_view);
2053 pspp_sheet_view_dy_to_top_row (tree_view);
2055 if (gtk_widget_get_realized (widget))
2057 gdk_window_move_resize (gtk_widget_get_window (widget),
2058 allocation->x, allocation->y,
2059 allocation->width, allocation->height);
2060 gdk_window_move_resize (tree_view->priv->header_window,
2061 - (gint) gtk_adjustment_get_value (tree_view->priv->hadjustment),
2063 MAX (tree_view->priv->width, allocation->width),
2064 tree_view->priv->header_height);
2065 gdk_window_move_resize (tree_view->priv->bin_window,
2066 - (gint) gtk_adjustment_get_value (tree_view->priv->hadjustment),
2067 TREE_VIEW_HEADER_HEIGHT (tree_view),
2068 MAX (tree_view->priv->width, allocation->width),
2069 allocation->height - TREE_VIEW_HEADER_HEIGHT (tree_view));
2072 if (tree_view->priv->row_count == 0)
2073 invalidate_empty_focus (tree_view);
2075 if (gtk_widget_get_realized (widget))
2077 gboolean has_expand_column = FALSE;
2078 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
2080 if (pspp_sheet_view_column_get_expand (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)))
2082 has_expand_column = TRUE;
2087 /* This little hack only works if we have an LTR locale, and no column has the */
2090 if (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_LTR &&
2091 ! has_expand_column)
2092 invalidate_last_column (tree_view);
2094 gtk_widget_queue_draw (widget);
2099 /* Grabs the focus and unsets the PSPP_SHEET_VIEW_DRAW_KEYFOCUS flag */
2101 grab_focus_and_unset_draw_keyfocus (PsppSheetView *tree_view)
2103 GtkWidget *widget = GTK_WIDGET (tree_view);
2105 if (gtk_widget_get_can_focus (widget) && !gtk_widget_has_focus (widget))
2106 gtk_widget_grab_focus (widget);
2107 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
2111 pspp_sheet_view_node_is_selected (PsppSheetView *tree_view,
2114 return node >= 0 && range_tower_contains (tree_view->priv->selected, node);
2118 pspp_sheet_view_node_select (PsppSheetView *tree_view,
2121 range_tower_set1 (tree_view->priv->selected, node, 1);
2125 pspp_sheet_view_node_unselect (PsppSheetView *tree_view,
2128 range_tower_set0 (tree_view->priv->selected, node, 1);
2132 pspp_sheet_view_node_next (PsppSheetView *tree_view,
2135 return node + 1 < tree_view->priv->row_count ? node + 1 : -1;
2139 pspp_sheet_view_node_prev (PsppSheetView *tree_view,
2142 return node > 0 ? node - 1 : -1;
2146 all_columns_selected (PsppSheetView *tree_view)
2150 for (list = tree_view->priv->columns; list; list = list->next)
2152 PsppSheetViewColumn *column = list->data;
2153 if (column->selectable && !column->selected)
2161 pspp_sheet_view_row_head_clicked (PsppSheetView *tree_view,
2163 PsppSheetViewColumn *column,
2164 GdkEventButton *event)
2166 PsppSheetSelection *selection;
2167 PsppSheetSelectionMode mode;
2169 gboolean update_anchor;
2173 g_return_val_if_fail (tree_view != NULL, FALSE);
2174 g_return_val_if_fail (column != NULL, FALSE);
2176 selection = tree_view->priv->selection;
2177 mode = pspp_sheet_selection_get_mode (selection);
2178 if (mode != PSPP_SHEET_SELECTION_RECTANGLE)
2181 if (!column->row_head)
2186 modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
2187 if (event->type != GDK_BUTTON_PRESS
2188 || (modifiers != GDK_CONTROL_MASK && modifiers != GDK_SHIFT_MASK))
2194 path = gtk_tree_path_new_from_indices (node, -1);
2197 pspp_sheet_selection_unselect_all (selection);
2198 pspp_sheet_selection_select_path (selection, path);
2199 pspp_sheet_selection_select_all_columns (selection);
2200 update_anchor = TRUE;
2203 else if (event->type == GDK_BUTTON_PRESS && event->button == 3)
2205 if (pspp_sheet_selection_count_selected_rows (selection) <= 1
2206 || !all_columns_selected (tree_view))
2208 pspp_sheet_selection_unselect_all (selection);
2209 pspp_sheet_selection_select_path (selection, path);
2210 pspp_sheet_selection_select_all_columns (selection);
2211 update_anchor = TRUE;
2215 update_anchor = handled = FALSE;
2217 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
2218 && modifiers == GDK_CONTROL_MASK)
2220 if (!all_columns_selected (tree_view))
2222 pspp_sheet_selection_unselect_all (selection);
2223 pspp_sheet_selection_select_all_columns (selection);
2226 if (pspp_sheet_selection_path_is_selected (selection, path))
2227 pspp_sheet_selection_unselect_path (selection, path);
2229 pspp_sheet_selection_select_path (selection, path);
2230 update_anchor = TRUE;
2233 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
2234 && modifiers == GDK_SHIFT_MASK)
2236 GtkTreeRowReference *anchor = tree_view->priv->anchor;
2237 GtkTreePath *anchor_path;
2239 if (all_columns_selected (tree_view)
2240 && gtk_tree_row_reference_valid (anchor))
2242 update_anchor = FALSE;
2243 anchor_path = gtk_tree_row_reference_get_path (anchor);
2247 update_anchor = TRUE;
2248 anchor_path = gtk_tree_path_copy (path);
2251 pspp_sheet_selection_unselect_all (selection);
2252 pspp_sheet_selection_select_range (selection, anchor_path, path);
2253 pspp_sheet_selection_select_all_columns (selection);
2255 gtk_tree_path_free (anchor_path);
2260 update_anchor = handled = FALSE;
2264 if (tree_view->priv->anchor)
2265 gtk_tree_row_reference_free (tree_view->priv->anchor);
2266 tree_view->priv->anchor =
2267 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
2268 tree_view->priv->model,
2272 gtk_tree_path_free (path);
2277 find_click (PsppSheetView *tree_view,
2280 PsppSheetViewColumn **column,
2281 GdkRectangle *background_area,
2282 GdkRectangle *cell_area)
2289 /* find the node that was clicked */
2290 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, y);
2293 y_offset = -pspp_sheet_view_find_offset (tree_view, new_y, node);
2298 background_area->y = y_offset + y;
2299 background_area->height = ROW_HEIGHT (tree_view);
2300 background_area->x = 0;
2302 /* Let the column have a chance at selecting it. */
2303 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
2304 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
2305 list; list = (rtl ? list->prev : list->next))
2307 PsppSheetViewColumn *candidate = list->data;
2309 if (!candidate->visible)
2312 background_area->width = candidate->width;
2313 if ((background_area->x > x) ||
2314 (background_area->x + background_area->width <= x))
2316 background_area->x += background_area->width;
2320 /* we found the focus column */
2322 pspp_sheet_view_adjust_cell_area (tree_view, candidate, background_area,
2324 *column = candidate;
2332 pspp_sheet_view_button_press (GtkWidget *widget,
2333 GdkEventButton *event)
2335 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2337 PsppSheetViewColumn *column = NULL;
2339 GdkRectangle background_area;
2340 GdkRectangle cell_area;
2343 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
2344 pspp_sheet_view_stop_editing (tree_view, FALSE);
2347 /* Because grab_focus can cause reentrancy, we delay grab_focus until after
2348 * we're done handling the button press.
2351 if (event->window == tree_view->priv->bin_window)
2356 gint pre_val, aft_val;
2357 PsppSheetViewColumn *column = NULL;
2358 GtkCellRenderer *focus_cell = NULL;
2359 gboolean row_double_click = FALSE;
2362 if (tree_view->priv->row_count == 0)
2364 grab_focus_and_unset_draw_keyfocus (tree_view);
2368 if (!find_click (tree_view, event->x, event->y, &node, &column,
2369 &background_area, &cell_area))
2371 grab_focus_and_unset_draw_keyfocus (tree_view);
2375 tree_view->priv->focus_column = column;
2377 if (pspp_sheet_view_row_head_clicked (tree_view, node, column, event))
2381 pre_val = gtk_adjustment_get_value (tree_view->priv->vadjustment);
2383 path = _pspp_sheet_view_find_path (tree_view, node);
2385 /* we only handle selection modifications on the first button press
2387 if (event->type == GDK_BUTTON_PRESS)
2389 PsppSheetSelectionMode mode = 0;
2391 if ((event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
2392 mode |= PSPP_SHEET_SELECT_MODE_TOGGLE;
2393 if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
2394 mode |= PSPP_SHEET_SELECT_MODE_EXTEND;
2396 focus_cell = _pspp_sheet_view_column_get_cell_at_pos (column, event->x - background_area.x);
2398 pspp_sheet_view_column_focus_cell (column, focus_cell);
2400 if (event->state & GDK_CONTROL_MASK)
2402 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE, mode);
2403 pspp_sheet_view_real_toggle_cursor_row (tree_view);
2405 else if (event->state & GDK_SHIFT_MASK)
2407 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, mode);
2408 pspp_sheet_view_real_select_cursor_row (tree_view, FALSE, mode);
2412 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, 0);
2415 if (tree_view->priv->anchor_column == NULL ||
2416 !(event->state & GDK_SHIFT_MASK))
2417 tree_view->priv->anchor_column = column;
2418 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
2419 pspp_sheet_selection_select_column_range (tree_view->priv->selection,
2420 tree_view->priv->anchor_column,
2424 /* the treeview may have been scrolled because of _set_cursor,
2428 aft_val = gtk_adjustment_get_value (tree_view->priv->vadjustment);
2429 dval = pre_val - aft_val;
2431 cell_area.y += dval;
2432 background_area.y += dval;
2434 /* Save press to possibly begin a drag
2436 if (!tree_view->priv->in_grab &&
2437 tree_view->priv->pressed_button < 0)
2439 tree_view->priv->pressed_button = event->button;
2440 tree_view->priv->press_start_x = event->x;
2441 tree_view->priv->press_start_y = event->y;
2442 tree_view->priv->press_start_node = node;
2444 if (tree_view->priv->rubber_banding_enable
2445 && (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
2446 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE))
2448 tree_view->priv->press_start_y += tree_view->priv->dy;
2449 tree_view->priv->rubber_band_x = event->x;
2450 tree_view->priv->rubber_band_y = event->y + tree_view->priv->dy;
2451 tree_view->priv->rubber_band_status = RUBBER_BAND_MAYBE_START;
2453 if ((event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
2454 tree_view->priv->rubber_band_ctrl = TRUE;
2455 if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
2456 tree_view->priv->rubber_band_shift = TRUE;
2461 /* Test if a double click happened on the same row. */
2462 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
2464 int double_click_time, double_click_distance;
2466 g_object_get (gtk_settings_get_for_screen (
2467 gtk_widget_get_screen (widget)),
2468 "gtk-double-click-time", &double_click_time,
2469 "gtk-double-click-distance", &double_click_distance,
2472 /* Same conditions as _gdk_event_button_generate */
2473 if (tree_view->priv->last_button_x != -1 &&
2474 (event->time < tree_view->priv->last_button_time + double_click_time) &&
2475 (ABS (event->x - tree_view->priv->last_button_x) <= double_click_distance) &&
2476 (ABS (event->y - tree_view->priv->last_button_y) <= double_click_distance))
2478 /* We do no longer compare paths of this row and the
2479 * row clicked previously. We use the double click
2480 * distance to decide whether this is a valid click,
2481 * allowing the mouse to slightly move over another row.
2483 row_double_click = TRUE;
2485 tree_view->priv->last_button_time = 0;
2486 tree_view->priv->last_button_x = -1;
2487 tree_view->priv->last_button_y = -1;
2491 tree_view->priv->last_button_time = event->time;
2492 tree_view->priv->last_button_x = event->x;
2493 tree_view->priv->last_button_y = event->y;
2497 if (row_double_click)
2499 gtk_grab_remove (widget);
2500 pspp_sheet_view_row_activated (tree_view, path, column);
2502 if (tree_view->priv->pressed_button == event->button)
2503 tree_view->priv->pressed_button = -1;
2506 gtk_tree_path_free (path);
2508 /* If we activated the row through a double click we don't want to grab
2509 * focus back, as moving focus to another widget is pretty common.
2511 if (!row_double_click)
2512 grab_focus_and_unset_draw_keyfocus (tree_view);
2517 /* We didn't click in the window. Let's check to see if we clicked on a column resize window.
2519 for (i = 0, list = tree_view->priv->columns; list; list = list->next, i++)
2521 column = list->data;
2522 if (event->window == column->window &&
2523 column->resizable &&
2528 if (gdk_pointer_grab (column->window, FALSE,
2529 GDK_POINTER_MOTION_HINT_MASK |
2530 GDK_BUTTON1_MOTION_MASK |
2531 GDK_BUTTON_RELEASE_MASK,
2532 NULL, NULL, event->time))
2535 gtk_grab_add (widget);
2536 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE);
2537 column->resized_width = column->width;
2539 /* block attached dnd signal handler */
2540 drag_data = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
2542 g_signal_handlers_block_matched (widget,
2543 G_SIGNAL_MATCH_DATA,
2547 tree_view->priv->drag_pos = i;
2548 tree_view->priv->x_drag = column->allocation.x + (rtl ? 0 : column->allocation.width);
2550 if (!gtk_widget_has_focus (widget))
2551 gtk_widget_grab_focus (widget);
2559 /* GtkWidget::button_release_event helper */
2561 pspp_sheet_view_button_release_drag_column (GtkWidget *widget,
2562 GdkEventButton *event)
2564 PsppSheetView *tree_view;
2568 tree_view = PSPP_SHEET_VIEW (widget);
2570 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
2571 gdk_display_pointer_ungrab (gtk_widget_get_display (widget), GDK_CURRENT_TIME);
2572 gdk_display_keyboard_ungrab (gtk_widget_get_display (widget), GDK_CURRENT_TIME);
2574 /* Move the button back */
2575 g_return_val_if_fail (tree_view->priv->drag_column->button, FALSE);
2577 g_object_ref (tree_view->priv->drag_column->button);
2578 gtk_container_remove (GTK_CONTAINER (tree_view), tree_view->priv->drag_column->button);
2579 gtk_widget_set_parent_window (tree_view->priv->drag_column->button, tree_view->priv->header_window);
2580 gtk_widget_set_parent (tree_view->priv->drag_column->button, GTK_WIDGET (tree_view));
2581 g_object_unref (tree_view->priv->drag_column->button);
2582 gtk_widget_queue_resize (widget);
2583 if (tree_view->priv->drag_column->resizable)
2585 gdk_window_raise (tree_view->priv->drag_column->window);
2586 gdk_window_show (tree_view->priv->drag_column->window);
2589 gdk_window_hide (tree_view->priv->drag_column->window);
2591 gtk_widget_grab_focus (tree_view->priv->drag_column->button);
2595 if (tree_view->priv->cur_reorder &&
2596 tree_view->priv->cur_reorder->right_column != tree_view->priv->drag_column)
2597 pspp_sheet_view_move_column_after (tree_view, tree_view->priv->drag_column,
2598 tree_view->priv->cur_reorder->right_column);
2602 if (tree_view->priv->cur_reorder &&
2603 tree_view->priv->cur_reorder->left_column != tree_view->priv->drag_column)
2604 pspp_sheet_view_move_column_after (tree_view, tree_view->priv->drag_column,
2605 tree_view->priv->cur_reorder->left_column);
2607 tree_view->priv->drag_column = NULL;
2608 gdk_window_hide (tree_view->priv->drag_window);
2610 for (l = tree_view->priv->column_drag_info; l != NULL; l = l->next)
2611 g_slice_free (PsppSheetViewColumnReorder, l->data);
2612 g_list_free (tree_view->priv->column_drag_info);
2613 tree_view->priv->column_drag_info = NULL;
2614 tree_view->priv->cur_reorder = NULL;
2616 if (tree_view->priv->drag_highlight_window)
2617 gdk_window_hide (tree_view->priv->drag_highlight_window);
2619 /* Reset our flags */
2620 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_UNSET;
2621 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG);
2626 /* GtkWidget::button_release_event helper */
2628 pspp_sheet_view_button_release_column_resize (GtkWidget *widget,
2629 GdkEventButton *event)
2631 PsppSheetView *tree_view;
2634 tree_view = PSPP_SHEET_VIEW (widget);
2636 tree_view->priv->drag_pos = -1;
2638 /* unblock attached dnd signal handler */
2639 drag_data = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
2641 g_signal_handlers_unblock_matched (widget,
2642 G_SIGNAL_MATCH_DATA,
2646 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE);
2647 gtk_grab_remove (widget);
2648 gdk_display_pointer_ungrab (gdk_window_get_display (event->window),
2654 pspp_sheet_view_button_release_edit (PsppSheetView *tree_view,
2655 GdkEventButton *event)
2657 GtkCellEditable *cell_editable;
2662 PsppSheetViewColumn *column;
2663 GdkRectangle background_area;
2664 GdkRectangle cell_area;
2670 if (event->window != tree_view->priv->bin_window)
2673 /* Ignore a released button, if that button wasn't depressed */
2674 if (tree_view->priv->pressed_button != event->button)
2677 if (!find_click (tree_view, event->x, event->y, &node, &column, &background_area,
2681 /* decide if we edit */
2682 path = _pspp_sheet_view_find_path (tree_view, node);
2683 modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
2684 if (event->button != 1 || modifiers)
2687 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
2688 pspp_sheet_view_column_cell_set_cell_data (column,
2689 tree_view->priv->model,
2692 if (!pspp_sheet_view_column_get_quick_edit (column)
2693 && _pspp_sheet_view_column_has_editable_cell (column))
2696 flags = 0; /* FIXME: get the right flags */
2697 path_string = gtk_tree_path_to_string (path);
2699 if (!_pspp_sheet_view_column_cell_event (column,
2707 if (cell_editable == NULL)
2710 pspp_sheet_view_real_set_cursor (tree_view, path,
2711 TRUE, TRUE, 0); /* XXX mode? */
2712 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
2715 _pspp_sheet_view_column_get_neighbor_sizes (
2716 column, _pspp_sheet_view_column_get_edited_cell (column), &left, &right);
2719 area.width -= right + left;
2721 pspp_sheet_view_real_start_editing (tree_view,
2728 g_free (path_string);
2729 gtk_tree_path_free (path);
2734 pspp_sheet_view_button_release (GtkWidget *widget,
2735 GdkEventButton *event)
2737 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2739 pspp_sheet_view_stop_editing (tree_view, FALSE);
2740 if (tree_view->priv->rubber_band_status != RUBBER_BAND_ACTIVE
2741 && pspp_sheet_view_button_release_edit (tree_view, event))
2743 if (tree_view->priv->pressed_button == event->button)
2744 tree_view->priv->pressed_button = -1;
2746 tree_view->priv->rubber_band_status = RUBBER_BAND_OFF;
2750 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
2751 return pspp_sheet_view_button_release_drag_column (widget, event);
2753 if (tree_view->priv->rubber_band_status)
2754 pspp_sheet_view_stop_rubber_band (tree_view);
2756 if (tree_view->priv->pressed_button == event->button)
2757 tree_view->priv->pressed_button = -1;
2759 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
2760 return pspp_sheet_view_button_release_column_resize (widget, event);
2766 pspp_sheet_view_grab_broken (GtkWidget *widget,
2767 GdkEventGrabBroken *event)
2769 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2771 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
2772 pspp_sheet_view_button_release_drag_column (widget, (GdkEventButton *)event);
2774 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
2775 pspp_sheet_view_button_release_column_resize (widget, (GdkEventButton *)event);
2780 /* GtkWidget::motion_event function set.
2784 do_prelight (PsppSheetView *tree_view,
2786 /* these are in bin_window coords */
2790 int prev_node = tree_view->priv->prelight_node;
2792 if (prev_node != node)
2794 tree_view->priv->prelight_node = node;
2797 _pspp_sheet_view_queue_draw_node (tree_view, prev_node, NULL);
2800 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
2806 prelight_or_select (PsppSheetView *tree_view,
2808 /* these are in bin_window coords */
2812 PsppSheetSelectionMode mode = pspp_sheet_selection_get_mode (tree_view->priv->selection);
2814 if (tree_view->priv->hover_selection &&
2815 (mode == PSPP_SHEET_SELECTION_SINGLE || mode == PSPP_SHEET_SELECTION_BROWSE) &&
2816 !(tree_view->priv->edited_column &&
2817 tree_view->priv->edited_column->editable_widget))
2821 if (!pspp_sheet_view_node_is_selected (tree_view, node))
2825 path = _pspp_sheet_view_find_path (tree_view, node);
2826 pspp_sheet_selection_select_path (tree_view->priv->selection, path);
2827 if (pspp_sheet_view_node_is_selected (tree_view, node))
2829 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
2830 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, FALSE, 0); /* XXX mode? */
2832 gtk_tree_path_free (path);
2836 else if (mode == PSPP_SHEET_SELECTION_SINGLE)
2837 pspp_sheet_selection_unselect_all (tree_view->priv->selection);
2840 do_prelight (tree_view, node, x, y);
2844 ensure_unprelighted (PsppSheetView *tree_view)
2846 do_prelight (tree_view,
2848 -1000, -1000); /* coords not possibly over an arrow */
2850 g_assert (tree_view->priv->prelight_node < 0);
2854 update_prelight (PsppSheetView *tree_view,
2861 if (tree_view->priv->row_count == 0)
2866 ensure_unprelighted (tree_view);
2870 new_y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, y);
2874 pspp_sheet_view_find_offset (tree_view, new_y, &node);
2877 prelight_or_select (tree_view, node, x, y);
2883 /* Our motion arrow is either a box (in the case of the original spot)
2884 * or an arrow. It is expander_size wide.
2907 pspp_sheet_view_motion_draw_column_motion_arrow (PsppSheetView *tree_view)
2910 PsppSheetViewColumnReorder *reorder = tree_view->priv->cur_reorder;
2911 GtkWidget *widget = GTK_WIDGET (tree_view);
2912 GdkBitmap *mask = NULL;
2917 gint arrow_type = DRAG_COLUMN_WINDOW_STATE_UNSET;
2918 GdkWindowAttr attributes;
2919 guint attributes_mask;
2922 reorder->left_column == tree_view->priv->drag_column ||
2923 reorder->right_column == tree_view->priv->drag_column)
2924 arrow_type = DRAG_COLUMN_WINDOW_STATE_ORIGINAL;
2925 else if (reorder->left_column || reorder->right_column)
2927 GdkRectangle visible_rect;
2928 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
2929 if (reorder->left_column)
2930 x = reorder->left_column->allocation.x + reorder->left_column->allocation.width;
2932 x = reorder->right_column->allocation.x;
2934 if (x < visible_rect.x)
2935 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT;
2936 else if (x > visible_rect.x + visible_rect.width)
2937 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT;
2939 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW;
2942 /* We want to draw the rectangle over the initial location. */
2943 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ORIGINAL)
2948 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ORIGINAL)
2950 if (tree_view->priv->drag_highlight_window)
2952 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
2954 gdk_window_destroy (tree_view->priv->drag_highlight_window);
2957 attributes.window_type = GDK_WINDOW_CHILD;
2958 attributes.wclass = GDK_INPUT_OUTPUT;
2959 attributes.x = tree_view->priv->drag_column_x;
2961 width = attributes.width = tree_view->priv->drag_column->allocation.width;
2962 height = attributes.height = tree_view->priv->drag_column->allocation.height;
2963 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
2964 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
2965 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
2966 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2967 tree_view->priv->drag_highlight_window = gdk_window_new (tree_view->priv->header_window, &attributes, attributes_mask);
2968 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
2970 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
2971 gc = gdk_gc_new (mask);
2973 gdk_gc_set_foreground (gc, &col);
2974 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
2976 gdk_gc_set_foreground(gc, &col);
2977 gdk_draw_rectangle (mask, gc, TRUE, 2, 2, width - 4, height - 4);
2978 g_object_unref (gc);
2980 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
2982 if (mask) g_object_unref (mask);
2983 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_ORIGINAL;
2986 else if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW)
2992 width = tree_view->priv->expander_size;
2994 /* Get x, y, width, height of arrow */
2995 gdk_window_get_origin (tree_view->priv->header_window, &x, &y);
2996 if (reorder->left_column)
2998 x += reorder->left_column->allocation.x + reorder->left_column->allocation.width - width/2;
2999 height = reorder->left_column->allocation.height;
3003 x += reorder->right_column->allocation.x - width/2;
3004 height = reorder->right_column->allocation.height;
3006 y -= tree_view->priv->expander_size/2; /* The arrow takes up only half the space */
3007 height += tree_view->priv->expander_size;
3009 /* Create the new window */
3010 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW)
3012 if (tree_view->priv->drag_highlight_window)
3014 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
3016 gdk_window_destroy (tree_view->priv->drag_highlight_window);
3019 attributes.window_type = GDK_WINDOW_TEMP;
3020 attributes.wclass = GDK_INPUT_OUTPUT;
3021 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
3022 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
3023 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
3024 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
3027 attributes.width = width;
3028 attributes.height = height;
3029 tree_view->priv->drag_highlight_window = gdk_window_new (gtk_widget_get_root_window (widget),
3030 &attributes, attributes_mask);
3031 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
3033 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
3034 gc = gdk_gc_new (mask);
3036 gdk_gc_set_foreground (gc, &col);
3037 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
3039 /* Draw the 2 arrows as per above */
3041 gdk_gc_set_foreground (gc, &col);
3042 for (i = 0; i < width; i ++)
3044 if (i == (width/2 - 1))
3046 gdk_draw_line (mask, gc, i, j, i, height - j);
3047 if (i < (width/2 - 1))
3052 g_object_unref (gc);
3053 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
3055 if (mask) g_object_unref (mask);
3058 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_ARROW;
3059 gdk_window_move (tree_view->priv->drag_highlight_window, x, y);
3061 else if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT ||
3062 arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3068 width = tree_view->priv->expander_size;
3070 /* Get x, y, width, height of arrow */
3071 width = width/2; /* remember, the arrow only takes half the available width */
3072 gdk_window_get_origin (gtk_widget_get_window (widget), &x, &y);
3073 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3074 x += widget->allocation.width - width;
3076 if (reorder->left_column)
3077 height = reorder->left_column->allocation.height;
3079 height = reorder->right_column->allocation.height;
3081 y -= tree_view->priv->expander_size;
3082 height += 2*tree_view->priv->expander_size;
3084 /* Create the new window */
3085 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT &&
3086 tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3088 if (tree_view->priv->drag_highlight_window)
3090 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
3092 gdk_window_destroy (tree_view->priv->drag_highlight_window);
3095 attributes.window_type = GDK_WINDOW_TEMP;
3096 attributes.wclass = GDK_INPUT_OUTPUT;
3097 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
3098 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
3099 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
3100 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
3103 attributes.width = width;
3104 attributes.height = height;
3105 tree_view->priv->drag_highlight_window = gdk_window_new (NULL, &attributes, attributes_mask);
3106 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
3108 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
3109 gc = gdk_gc_new (mask);
3111 gdk_gc_set_foreground (gc, &col);
3112 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
3114 /* Draw the 2 arrows as per above */
3116 gdk_gc_set_foreground (gc, &col);
3117 j = tree_view->priv->expander_size;
3118 for (i = 0; i < width; i ++)
3121 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT)
3125 gdk_draw_line (mask, gc, k, j, k, height - j);
3126 gdk_draw_line (mask, gc, k, 0, k, tree_view->priv->expander_size - j);
3127 gdk_draw_line (mask, gc, k, height, k, height - tree_view->priv->expander_size + j);
3130 g_object_unref (gc);
3131 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
3133 if (mask) g_object_unref (mask);
3136 tree_view->priv->drag_column_window_state = arrow_type;
3137 gdk_window_move (tree_view->priv->drag_highlight_window, x, y);
3141 g_warning (G_STRLOC"Invalid PsppSheetViewColumnReorder struct");
3142 gdk_window_hide (tree_view->priv->drag_highlight_window);
3146 gdk_window_show (tree_view->priv->drag_highlight_window);
3147 gdk_window_raise (tree_view->priv->drag_highlight_window);
3152 pspp_sheet_view_motion_resize_column (GtkWidget *widget,
3153 GdkEventMotion *event)
3157 PsppSheetViewColumn *column;
3158 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
3160 column = pspp_sheet_view_get_column (tree_view, tree_view->priv->drag_pos);
3162 if (event->is_hint || event->window != gtk_widget_get_window (widget))
3163 gtk_widget_get_pointer (widget, &x, NULL);
3167 if (tree_view->priv->hadjustment)
3168 x += gtk_adjustment_get_value (tree_view->priv->hadjustment);
3170 new_width = pspp_sheet_view_new_column_width (tree_view,
3171 tree_view->priv->drag_pos, &x);
3172 if (x != tree_view->priv->x_drag &&
3173 (new_width != column->fixed_width))
3175 column->use_resized_width = TRUE;
3176 column->resized_width = new_width;
3179 column->resized_width -= tree_view->priv->last_extra_space_per_column;
3181 gtk_widget_queue_resize (widget);
3189 pspp_sheet_view_update_current_reorder (PsppSheetView *tree_view)
3191 PsppSheetViewColumnReorder *reorder = NULL;
3195 gdk_window_get_pointer (tree_view->priv->header_window, &mouse_x, NULL, NULL);
3196 for (list = tree_view->priv->column_drag_info; list; list = list->next)
3198 reorder = (PsppSheetViewColumnReorder *) list->data;
3199 if (mouse_x >= reorder->left_align && mouse_x < reorder->right_align)
3204 /* if (reorder && reorder == tree_view->priv->cur_reorder)
3207 tree_view->priv->cur_reorder = reorder;
3208 pspp_sheet_view_motion_draw_column_motion_arrow (tree_view);
3212 pspp_sheet_view_vertical_autoscroll (PsppSheetView *tree_view)
3214 GdkRectangle visible_rect;
3219 gdk_window_get_pointer (tree_view->priv->bin_window, NULL, &y, NULL);
3220 y += tree_view->priv->dy;
3222 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
3224 /* see if we are near the edge. */
3225 offset = y - (visible_rect.y + 2 * SCROLL_EDGE_SIZE);
3228 offset = y - (visible_rect.y + visible_rect.height - 2 * SCROLL_EDGE_SIZE);
3233 value = CLAMP (gtk_adjustment_get_value (tree_view->priv->vadjustment) + offset, 0.0,
3234 gtk_adjustment_get_upper (tree_view->priv->vadjustment) - gtk_adjustment_get_page_size (tree_view->priv->vadjustment));
3235 gtk_adjustment_set_value (tree_view->priv->vadjustment, value);
3239 pspp_sheet_view_horizontal_autoscroll (PsppSheetView *tree_view)
3241 GdkRectangle visible_rect;
3246 gdk_window_get_pointer (tree_view->priv->bin_window, &x, NULL, NULL);
3248 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
3250 /* See if we are near the edge. */
3251 offset = x - (visible_rect.x + SCROLL_EDGE_SIZE);
3254 offset = x - (visible_rect.x + visible_rect.width - SCROLL_EDGE_SIZE);
3260 value = CLAMP (gtk_adjustment_get_value (tree_view->priv->hadjustment) + offset,
3261 0.0, gtk_adjustment_get_upper (tree_view->priv->hadjustment) - gtk_adjustment_get_page_size (tree_view->priv->hadjustment));
3262 gtk_adjustment_set_value (tree_view->priv->hadjustment, value);
3269 pspp_sheet_view_motion_drag_column (GtkWidget *widget,
3270 GdkEventMotion *event)
3272 PsppSheetView *tree_view = (PsppSheetView *) widget;
3273 PsppSheetViewColumn *column = tree_view->priv->drag_column;
3275 GtkAllocation allocation;
3278 if ((column == NULL) ||
3279 (event->window != tree_view->priv->drag_window))
3282 /* Handle moving the header */
3283 gdk_window_get_position (tree_view->priv->drag_window, &x, &y);
3284 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
3285 x = CLAMP (x + (gint)event->x - column->drag_x, 0,
3286 MAX (tree_view->priv->width, allocation.width) - column->allocation.width);
3287 gdk_window_move (tree_view->priv->drag_window, x, y);
3289 /* autoscroll, if needed */
3290 pspp_sheet_view_horizontal_autoscroll (tree_view);
3291 /* Update the current reorder position and arrow; */
3292 pspp_sheet_view_update_current_reorder (tree_view);
3298 pspp_sheet_view_stop_rubber_band (PsppSheetView *tree_view)
3300 remove_scroll_timeout (tree_view);
3301 gtk_grab_remove (GTK_WIDGET (tree_view));
3303 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
3305 GtkTreePath *tmp_path;
3307 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
3309 /* The anchor path should be set to the start path */
3310 tmp_path = _pspp_sheet_view_find_path (tree_view,
3311 tree_view->priv->rubber_band_start_node);
3313 if (tree_view->priv->anchor)
3314 gtk_tree_row_reference_free (tree_view->priv->anchor);
3316 tree_view->priv->anchor =
3317 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
3318 tree_view->priv->model,
3321 gtk_tree_path_free (tmp_path);
3323 /* ... and the cursor to the end path */
3324 tmp_path = _pspp_sheet_view_find_path (tree_view,
3325 tree_view->priv->rubber_band_end_node);
3326 pspp_sheet_view_real_set_cursor (PSPP_SHEET_VIEW (tree_view), tmp_path, FALSE, FALSE, 0); /* XXX mode? */
3327 gtk_tree_path_free (tmp_path);
3329 _pspp_sheet_selection_emit_changed (tree_view->priv->selection);
3332 /* Clear status variables */
3333 tree_view->priv->rubber_band_status = RUBBER_BAND_OFF;
3334 tree_view->priv->rubber_band_shift = 0;
3335 tree_view->priv->rubber_band_ctrl = 0;
3337 tree_view->priv->rubber_band_start_node = -1;
3338 tree_view->priv->rubber_band_end_node = -1;
3342 pspp_sheet_view_update_rubber_band_selection_range (PsppSheetView *tree_view,
3346 gboolean skip_start,
3349 if (start_node == end_node)
3352 /* We skip the first node and jump inside the loop */
3358 /* Small optimization by assuming insensitive nodes are never
3363 if (tree_view->priv->rubber_band_shift)
3364 pspp_sheet_view_node_select (tree_view, start_node);
3365 else if (tree_view->priv->rubber_band_ctrl)
3367 /* Toggle the selection state */
3368 if (pspp_sheet_view_node_is_selected (tree_view, start_node))
3369 pspp_sheet_view_node_unselect (tree_view, start_node);
3371 pspp_sheet_view_node_select (tree_view, start_node);
3374 pspp_sheet_view_node_select (tree_view, start_node);
3378 /* Mirror the above */
3379 if (tree_view->priv->rubber_band_shift)
3380 pspp_sheet_view_node_unselect (tree_view, start_node);
3381 else if (tree_view->priv->rubber_band_ctrl)
3383 /* Toggle the selection state */
3384 if (pspp_sheet_view_node_is_selected (tree_view, start_node))
3385 pspp_sheet_view_node_unselect (tree_view, start_node);
3387 pspp_sheet_view_node_select (tree_view, start_node);
3390 pspp_sheet_view_node_unselect (tree_view, start_node);
3393 _pspp_sheet_view_queue_draw_node (tree_view, start_node, NULL);
3395 if (start_node == end_node)
3400 start_node = pspp_sheet_view_node_next (tree_view, start_node);
3403 /* Ran out of tree */
3406 if (skip_end && start_node == end_node)
3413 pspp_sheet_view_node_find_offset (PsppSheetView *tree_view,
3416 return node * tree_view->priv->fixed_height;
3420 pspp_sheet_view_find_offset (PsppSheetView *tree_view,
3424 int fixed_height = tree_view->priv->fixed_height;
3425 if (fixed_height <= 0
3427 || height >= tree_view->priv->row_count * fixed_height)
3434 *new_node = height / fixed_height;
3435 return height % fixed_height;
3440 pspp_sheet_view_update_rubber_band_selection (PsppSheetView *tree_view)
3445 pspp_sheet_view_find_offset (tree_view, MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y), &start_node);
3446 pspp_sheet_view_find_offset (tree_view, MAX (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y), &end_node);
3448 /* Handle the start area first */
3449 if (tree_view->priv->rubber_band_start_node < 0)
3451 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3458 else if (start_node < tree_view->priv->rubber_band_start_node)
3460 /* New node is above the old one; selection became bigger */
3461 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3463 tree_view->priv->rubber_band_start_node,
3468 else if (start_node > tree_view->priv->rubber_band_start_node)
3470 /* New node is below the old one; selection became smaller */
3471 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3472 tree_view->priv->rubber_band_start_node,
3479 tree_view->priv->rubber_band_start_node = start_node;
3481 /* Next, handle the end area */
3482 if (tree_view->priv->rubber_band_end_node < 0)
3484 /* In the event this happens, start_node was also -1; this case is
3488 else if (end_node < 0)
3490 /* Find the last node in the tree */
3491 pspp_sheet_view_find_offset (tree_view, tree_view->priv->height - 1,
3494 /* Selection reached end of the tree */
3495 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3496 tree_view->priv->rubber_band_end_node,
3502 else if (end_node > tree_view->priv->rubber_band_end_node)
3504 /* New node is below the old one; selection became bigger */
3505 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3506 tree_view->priv->rubber_band_end_node,
3512 else if (end_node < tree_view->priv->rubber_band_end_node)
3514 /* New node is above the old one; selection became smaller */
3515 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3517 tree_view->priv->rubber_band_end_node,
3523 tree_view->priv->rubber_band_end_node = end_node;
3526 #define GDK_RECTANGLE_PTR(X) ((GdkRectangle *)(X))
3529 pspp_sheet_view_update_rubber_band (PsppSheetView *tree_view)
3532 cairo_rectangle_int_t old_area;
3533 cairo_rectangle_int_t new_area;
3534 cairo_rectangle_int_t common;
3535 cairo_region_t *invalid_region;
3536 PsppSheetViewColumn *column;
3538 old_area.x = MIN (tree_view->priv->press_start_x, tree_view->priv->rubber_band_x);
3539 old_area.y = MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y) - tree_view->priv->dy;
3540 old_area.width = ABS (tree_view->priv->rubber_band_x - tree_view->priv->press_start_x) + 1;
3541 old_area.height = ABS (tree_view->priv->rubber_band_y - tree_view->priv->press_start_y) + 1;
3543 gdk_window_get_pointer (tree_view->priv->bin_window, &x, &y, NULL);
3546 y = MAX (y, 0) + tree_view->priv->dy;
3548 new_area.x = MIN (tree_view->priv->press_start_x, x);
3549 new_area.y = MIN (tree_view->priv->press_start_y, y) - tree_view->priv->dy;
3550 new_area.width = ABS (x - tree_view->priv->press_start_x) + 1;
3551 new_area.height = ABS (y - tree_view->priv->press_start_y) + 1;
3553 invalid_region = cairo_region_create_rectangle (&old_area);
3554 cairo_region_union_rectangle (invalid_region, &new_area);
3556 gdk_rectangle_intersect (GDK_RECTANGLE_PTR (&old_area),
3557 GDK_RECTANGLE_PTR (&new_area), GDK_RECTANGLE_PTR (&common));
3558 if (common.width > 2 && common.height > 2)
3560 cairo_region_t *common_region;
3562 /* make sure the border is invalidated */
3568 common_region = cairo_region_create_rectangle (&common);
3570 cairo_region_subtract (invalid_region, common_region);
3571 cairo_region_destroy (common_region);
3574 #if GTK_MAJOR_VERSION == 3
3575 gdk_window_invalidate_region (tree_view->priv->bin_window, invalid_region, TRUE);
3578 cairo_rectangle_int_t extents;
3580 cairo_region_get_extents (invalid_region, &extents);
3581 ereg = gdk_region_rectangle (GDK_RECTANGLE_PTR (&extents));
3582 gdk_window_invalidate_region (tree_view->priv->bin_window, ereg, TRUE);
3583 gdk_region_destroy (ereg);
3587 cairo_region_destroy (invalid_region);
3589 tree_view->priv->rubber_band_x = x;
3590 tree_view->priv->rubber_band_y = y;
3591 pspp_sheet_view_get_path_at_pos (tree_view, x, y, NULL, &column, NULL, NULL);
3593 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
3594 pspp_sheet_selection_select_column_range (tree_view->priv->selection,
3595 tree_view->priv->anchor_column,
3598 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
3600 pspp_sheet_view_update_rubber_band_selection (tree_view);
3605 pspp_sheet_view_paint_rubber_band (PsppSheetView *tree_view,
3610 GdkRectangle rubber_rect;
3614 rubber_rect.x = MIN (tree_view->priv->press_start_x, tree_view->priv->rubber_band_x);
3615 rubber_rect.y = MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y) - tree_view->priv->dy;
3616 rubber_rect.width = ABS (tree_view->priv->press_start_x - tree_view->priv->rubber_band_x) + 1;
3617 rubber_rect.height = ABS (tree_view->priv->press_start_y - tree_view->priv->rubber_band_y) + 1;
3619 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
3622 cr = gdk_cairo_create (tree_view->priv->bin_window);
3623 cairo_set_line_width (cr, 1.0);
3625 style = gtk_widget_get_style (GTK_WIDGET (tree_view));
3626 cairo_set_source_rgba (cr,
3627 style->fg[GTK_STATE_NORMAL].red / 65535.,
3628 style->fg[GTK_STATE_NORMAL].green / 65535.,
3629 style->fg[GTK_STATE_NORMAL].blue / 65535.,
3632 gdk_cairo_rectangle (cr, &rect);
3636 cairo_set_source_rgb (cr,
3637 style->fg[GTK_STATE_NORMAL].red / 65535.,
3638 style->fg[GTK_STATE_NORMAL].green / 65535.,
3639 style->fg[GTK_STATE_NORMAL].blue / 65535.);
3641 cairo_rectangle (cr,
3642 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
3643 rubber_rect.width - 1, rubber_rect.height - 1);
3652 pspp_sheet_view_motion_bin_window (GtkWidget *widget,
3653 GdkEventMotion *event)
3655 PsppSheetView *tree_view;
3659 tree_view = (PsppSheetView *) widget;
3661 if (tree_view->priv->row_count == 0)
3664 if (tree_view->priv->rubber_band_status == RUBBER_BAND_MAYBE_START)
3666 GdkRectangle background_area, cell_area;
3667 PsppSheetViewColumn *column;
3669 if (find_click (tree_view, event->x, event->y, &node, &column,
3670 &background_area, &cell_area)
3671 && tree_view->priv->focus_column == column
3672 && tree_view->priv->press_start_node == node)
3675 gtk_grab_add (GTK_WIDGET (tree_view));
3676 pspp_sheet_view_update_rubber_band (tree_view);
3678 tree_view->priv->rubber_band_status = RUBBER_BAND_ACTIVE;
3680 else if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
3682 pspp_sheet_view_update_rubber_band (tree_view);
3684 add_scroll_timeout (tree_view);
3687 /* only check for an initiated drag when a button is pressed */
3688 if (tree_view->priv->pressed_button >= 0
3689 && !tree_view->priv->rubber_band_status)
3690 pspp_sheet_view_maybe_begin_dragging_row (tree_view, event);
3692 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, event->y);
3696 pspp_sheet_view_find_offset (tree_view, new_y, &node);
3698 tree_view->priv->event_last_x = event->x;
3699 tree_view->priv->event_last_y = event->y;
3701 prelight_or_select (tree_view, node, event->x, event->y);
3707 pspp_sheet_view_motion (GtkWidget *widget,
3708 GdkEventMotion *event)
3710 PsppSheetView *tree_view;
3712 tree_view = (PsppSheetView *) widget;
3714 /* Resizing a column */
3715 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
3716 return pspp_sheet_view_motion_resize_column (widget, event);
3719 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
3720 return pspp_sheet_view_motion_drag_column (widget, event);
3722 /* Sanity check it */
3723 if (event->window == tree_view->priv->bin_window)
3724 return pspp_sheet_view_motion_bin_window (widget, event);
3729 /* Invalidate the focus rectangle near the edge of the bin_window; used when
3730 * the tree is empty.
3733 invalidate_empty_focus (PsppSheetView *tree_view)
3737 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
3742 area.width = gdk_window_get_width (tree_view->priv->bin_window);
3743 area.height = gdk_window_get_height (tree_view->priv->bin_window);
3744 gdk_window_invalidate_rect (tree_view->priv->bin_window, &area, FALSE);
3747 /* Draws a focus rectangle near the edge of the bin_window; used when the tree
3751 draw_empty_focus (PsppSheetView *tree_view)
3753 GtkWidget *widget = GTK_WIDGET (tree_view);
3755 cairo_t *cr = gdk_cairo_create (tree_view->priv->bin_window);
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),
3769 gtk_widget_get_state (widget),
3777 pspp_sheet_view_draw_vertical_grid_lines (PsppSheetView *tree_view,
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 cairo_set_line_width (cr, 1.0);
3806 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
3807 cairo_move_to (cr, current_x - 0.5, min_y);
3808 cairo_line_to (cr, current_x - 0.5 , max_y - min_y);
3814 /* Warning: Very scary function.
3815 * Modify at your own risk
3817 * KEEP IN SYNC WITH pspp_sheet_view_create_row_drag_icon()!
3818 * FIXME: It's not...
3821 pspp_sheet_view_bin_expose (GtkWidget *widget,
3822 GdkEventExpose *event)
3824 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
3829 int drag_highlight = -1;
3832 gint y_offset, cell_offset;
3834 GdkRectangle background_area;
3835 GdkRectangle cell_area;
3837 gint bin_window_width;
3838 gint bin_window_height;
3839 GtkTreePath *cursor_path;
3840 GtkTreePath *drag_dest_path;
3841 GList *first_column, *last_column;
3842 gint vertical_separator;
3843 gint horizontal_separator;
3844 gint focus_line_width;
3845 gboolean allow_rules;
3846 gboolean has_special_cell;
3848 gint n_visible_columns;
3849 gint grid_line_width;
3850 gboolean row_ending_details;
3851 gboolean draw_vgrid_lines, draw_hgrid_lines;
3853 cairo_t *cr = gdk_cairo_create (event->window);
3855 cairo_t *bwcr = gdk_cairo_create (tree_view->priv->bin_window);
3857 GtkAllocation allocation;
3858 gtk_widget_get_allocation (widget, &allocation);
3862 Zarea.width = gdk_window_get_width (event->window);
3863 Zarea.height = allocation.height;
3865 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
3867 gtk_widget_style_get (widget,
3868 "horizontal-separator", &horizontal_separator,
3869 "vertical-separator", &vertical_separator,
3870 "allow-rules", &allow_rules,
3871 "focus-line-width", &focus_line_width,
3872 "row-ending-details", &row_ending_details,
3875 if (tree_view->priv->row_count == 0)
3877 draw_empty_focus (tree_view);
3882 /* clip event->area to the visible area */
3883 if (Zarea.height < 0.5)
3887 validate_visible_area (tree_view);
3889 new_y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, Zarea.y);
3893 y_offset = -pspp_sheet_view_find_offset (tree_view, new_y, &node);
3895 gdk_window_get_width (tree_view->priv->bin_window);
3898 gdk_window_get_height (tree_view->priv->bin_window);
3901 if (tree_view->priv->height < bin_window_height)
3903 gtk_paint_flat_box (gtk_widget_get_style (widget),
3905 gtk_widget_get_state (widget),
3909 0, tree_view->priv->height,
3911 bin_window_height - tree_view->priv->height);
3917 /* find the path for the node */
3918 path = _pspp_sheet_view_find_path ((PsppSheetView *)widget, node);
3919 gtk_tree_model_get_iter (tree_view->priv->model,
3922 gtk_tree_path_free (path);
3925 drag_dest_path = NULL;
3927 if (tree_view->priv->cursor)
3928 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
3931 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor);
3933 if (tree_view->priv->drag_dest_row)
3934 drag_dest_path = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
3937 _pspp_sheet_view_find_node (tree_view, drag_dest_path,
3941 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
3942 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
3944 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
3945 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
3947 if (draw_vgrid_lines || draw_hgrid_lines)
3948 gtk_widget_style_get (widget, "grid-line-width", &grid_line_width, NULL);
3950 n_visible_columns = 0;
3951 for (list = tree_view->priv->columns; list; list = list->next)
3953 if (! PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
3955 n_visible_columns ++;
3958 /* Find the last column */
3959 for (last_column = g_list_last (tree_view->priv->columns);
3960 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
3961 last_column = last_column->prev)
3965 for (first_column = g_list_first (tree_view->priv->columns);
3966 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
3967 first_column = first_column->next)
3970 /* Actually process the expose event. To do this, we want to
3971 * start at the first node of the event, and walk the tree in
3972 * order, drawing each successive node.
3979 gboolean is_first = FALSE;
3980 gboolean is_last = FALSE;
3981 gboolean done = FALSE;
3984 max_height = ROW_HEIGHT (tree_view);
3988 background_area.y = y_offset + Zarea.y;
3989 background_area.height = max_height;
3990 max_y = background_area.y + max_height;
3994 if (node == tree_view->priv->prelight_node)
3995 flags |= GTK_CELL_RENDERER_PRELIT;
3997 selected = pspp_sheet_view_node_is_selected (tree_view, node);
4001 if (tree_view->priv->special_cells == PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT)
4003 /* we *need* to set cell data on all cells before the call
4004 * to _has_special_cell, else _has_special_cell() does not
4005 * return a correct value.
4007 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
4009 list = (rtl ? list->prev : list->next))
4011 PsppSheetViewColumn *column = list->data;
4012 pspp_sheet_view_column_cell_set_cell_data (column,
4013 tree_view->priv->model,
4017 has_special_cell = pspp_sheet_view_has_special_cell (tree_view);
4020 has_special_cell = tree_view->priv->special_cells == PSPP_SHEET_VIEW_SPECIAL_CELLS_YES;
4022 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
4024 list = (rtl ? list->prev : list->next))
4026 PsppSheetViewColumn *column = list->data;
4027 const gchar *detail = NULL;
4028 gboolean selected_column;
4031 if (!column->visible)
4034 if (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE)
4035 selected_column = column->selected && column->selectable;
4037 selected_column = TRUE;
4040 if (cell_offset > Zarea.x + Zarea.width ||
4041 cell_offset + column->width < Zarea.x)
4043 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),
4186 background_area.width,
4187 background_area.height);
4191 gtk_paint_flat_box (gtk_widget_get_style (widget),
4199 background_area.width,
4200 background_area.height);
4203 if (draw_hgrid_lines)
4205 cairo_set_line_width (cr, 1.0);
4206 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
4208 if (background_area.y >= 0)
4211 gdk_draw_line (event->window,
4212 tree_view->priv->grid_line_gc[widget->state],
4213 background_area.x, background_area.y,
4214 background_area.x + background_area.width,
4217 cairo_move_to (cr, background_area.x, background_area.y - 0.5);
4218 cairo_line_to (cr, background_area.x + background_area.width,
4219 background_area.y - 0.5);
4223 if (y_offset + max_height >= Zarea.height - 0.5)
4226 gdk_draw_line (event->window,
4227 tree_view->priv->grid_line_gc[widget->state],
4228 background_area.x, background_area.y + max_height,
4229 background_area.x + background_area.width,
4230 background_area.y + max_height);
4233 cairo_move_to (cr, background_area.x, background_area.y + max_height - 0.5);
4234 cairo_line_to (cr, background_area.x + background_area.width,
4235 background_area.y + max_height - 0.5);
4241 _pspp_sheet_view_column_cell_render (column,
4247 if (node == cursor && has_special_cell &&
4248 ((column == tree_view->priv->focus_column &&
4249 PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS) &&
4250 gtk_widget_has_focus (widget)) ||
4251 (column == tree_view->priv->edited_column)))
4253 _pspp_sheet_view_column_cell_draw_focus (column,
4260 cell_offset += column->width;
4263 if (cell_offset < Zarea.x)
4265 gtk_paint_flat_box (gtk_widget_get_style (widget),
4273 Zarea.x - cell_offset,
4274 background_area.height);
4277 if (node == drag_highlight)
4279 /* Draw indicator for the drop
4281 gint highlight_y = -1;
4285 switch (tree_view->priv->drag_dest_pos)
4287 case PSPP_SHEET_VIEW_DROP_BEFORE:
4288 highlight_y = background_area.y - 1;
4289 if (highlight_y < 0)
4293 case PSPP_SHEET_VIEW_DROP_AFTER:
4294 highlight_y = background_area.y + background_area.height - 1;
4297 case PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE:
4298 case PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER:
4299 _pspp_sheet_view_find_node (tree_view, drag_dest_path, &node);
4303 width = gdk_window_get_width (tree_view->priv->bin_window);
4305 if (row_ending_details)
4306 gtk_paint_focus (gtk_widget_get_style (widget),
4308 gtk_widget_get_state (widget),
4311 ? (is_last ? "treeview-drop-indicator" : "treeview-drop-indicator-left" )
4312 : (is_last ? "treeview-drop-indicator-right" : "tree-view-drop-indicator-middle" )),
4313 0, BACKGROUND_FIRST_PIXEL (tree_view, node)
4314 - focus_line_width / 2,
4315 width, ROW_HEIGHT (tree_view)
4316 - focus_line_width + 1);
4318 gtk_paint_focus (gtk_widget_get_style (widget),
4320 gtk_widget_get_state (widget),
4322 "treeview-drop-indicator",
4323 0, BACKGROUND_FIRST_PIXEL (tree_view, node)
4324 - focus_line_width / 2,
4325 width, ROW_HEIGHT (tree_view)
4326 - focus_line_width + 1);
4331 if (highlight_y >= 0)
4333 gdk_draw_line (event->window,
4334 widget->style->fg_gc[gtk_widget_get_state (widget)],
4337 rtl ? 0 : bin_window_width,
4343 /* draw the big row-spanning focus rectangle, if needed */
4344 if (!has_special_cell && node == cursor &&
4345 PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS) &&
4346 gtk_widget_has_focus (widget))
4348 gint tmp_y, tmp_height;
4350 GtkStateType focus_rect_state;
4353 flags & GTK_CELL_RENDERER_SELECTED ? GTK_STATE_SELECTED :
4354 (flags & GTK_CELL_RENDERER_PRELIT ? GTK_STATE_PRELIGHT :
4355 (flags & GTK_CELL_RENDERER_INSENSITIVE ? GTK_STATE_INSENSITIVE :
4358 width = gdk_window_get_width (tree_view->priv->bin_window);
4360 if (draw_hgrid_lines)
4362 tmp_y = BACKGROUND_FIRST_PIXEL (tree_view, node) + grid_line_width / 2;
4363 tmp_height = ROW_HEIGHT (tree_view) - grid_line_width;
4367 tmp_y = BACKGROUND_FIRST_PIXEL (tree_view, node);
4368 tmp_height = ROW_HEIGHT (tree_view);
4371 if (row_ending_details)
4372 gtk_paint_focus (gtk_widget_get_style (widget),
4377 ? (is_last ? "treeview" : "treeview-left" )
4378 : (is_last ? "treeview-right" : "treeview-middle" )),
4382 gtk_paint_focus (gtk_widget_get_style (widget),
4391 y_offset += max_height;
4395 node = pspp_sheet_view_node_next (tree_view, node);
4398 gboolean has_next = gtk_tree_model_iter_next (tree_view->priv->model, &iter);
4402 TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
4409 while (y_offset < Zarea.height);
4412 pspp_sheet_view_draw_vertical_grid_lines (tree_view, cr, n_visible_columns,
4416 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
4418 GdkRectangle *rectangles;
4421 gdk_region_get_rectangles (event->region,
4425 while (n_rectangles--)
4426 pspp_sheet_view_paint_rubber_band (tree_view, &rectangles[n_rectangles]);
4428 g_free (rectangles);
4433 gtk_tree_path_free (cursor_path);
4436 gtk_tree_path_free (drag_dest_path);
4442 pspp_sheet_view_expose (GtkWidget *widget,
4443 GdkEventExpose *event)
4445 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4446 cairo_t *cr = gdk_cairo_create (event->window);
4448 if (event->window == tree_view->priv->bin_window)
4453 retval = pspp_sheet_view_bin_expose (widget, event);
4455 /* We can't just chain up to Container::expose as it will try to send the
4456 * event to the headers, so we handle propagating it to our children
4457 * (eg. widgets being edited) ourselves.
4459 tmp_list = tree_view->priv->children;
4462 PsppSheetViewChild *child = tmp_list->data;
4463 tmp_list = tmp_list->next;
4465 gtk_container_propagate_expose (GTK_CONTAINER (tree_view), child->widget, event);
4470 else if (event->window == tree_view->priv->header_window)
4472 gint n_visible_columns;
4475 gtk_paint_flat_box (gtk_widget_get_style (widget),
4484 event->area.height);
4486 for (list = tree_view->priv->columns; list != NULL; list = list->next)
4488 PsppSheetViewColumn *column = list->data;
4490 if (column == tree_view->priv->drag_column || !column->visible)
4493 if (span_intersects (column->allocation.x, column->allocation.width,
4494 event->area.x, event->area.width)
4495 && column->button != NULL)
4496 gtk_container_propagate_expose (GTK_CONTAINER (tree_view),
4497 column->button, event);
4500 n_visible_columns = 0;
4501 for (list = tree_view->priv->columns; list; list = list->next)
4503 if (! PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
4505 n_visible_columns ++;
4507 pspp_sheet_view_draw_vertical_grid_lines (tree_view,
4511 event->area.height);
4513 else if (event->window == tree_view->priv->drag_window)
4515 gtk_container_propagate_expose (GTK_CONTAINER (tree_view),
4516 tree_view->priv->drag_column->button,
4530 /* returns 0x1 when no column has been found -- yes it's hackish */
4531 static PsppSheetViewColumn *
4532 pspp_sheet_view_get_drop_column (PsppSheetView *tree_view,
4533 PsppSheetViewColumn *column,
4536 PsppSheetViewColumn *left_column = NULL;
4537 PsppSheetViewColumn *cur_column = NULL;
4540 if (!column->reorderable)
4541 return (PsppSheetViewColumn *)0x1;
4543 switch (drop_position)
4546 /* find first column where we can drop */
4547 tmp_list = tree_view->priv->columns;
4548 if (column == PSPP_SHEET_VIEW_COLUMN (tmp_list->data))
4549 return (PsppSheetViewColumn *)0x1;
4553 g_assert (tmp_list);
4555 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4556 tmp_list = tmp_list->next;
4558 if (left_column && left_column->visible == FALSE)
4561 if (!tree_view->priv->column_drop_func)
4564 if (!tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4566 left_column = cur_column;
4573 if (!tree_view->priv->column_drop_func)
4576 if (tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data))
4579 return (PsppSheetViewColumn *)0x1;
4583 /* find first column after column where we can drop */
4584 tmp_list = tree_view->priv->columns;
4586 for (; tmp_list; tmp_list = tmp_list->next)
4587 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data) == column)
4590 if (!tmp_list || !tmp_list->next)
4591 return (PsppSheetViewColumn *)0x1;
4593 tmp_list = tmp_list->next;
4594 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4595 tmp_list = tmp_list->next;
4599 g_assert (tmp_list);
4601 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4602 tmp_list = tmp_list->next;
4604 if (left_column && left_column->visible == FALSE)
4606 left_column = cur_column;
4608 tmp_list = tmp_list->next;
4612 if (!tree_view->priv->column_drop_func)
4615 if (!tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4617 left_column = cur_column;
4624 if (!tree_view->priv->column_drop_func)
4627 if (tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data))
4630 return (PsppSheetViewColumn *)0x1;
4634 /* find first column before column where we can drop */
4635 tmp_list = tree_view->priv->columns;
4637 for (; tmp_list; tmp_list = tmp_list->next)
4638 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data) == column)
4641 if (!tmp_list || !tmp_list->prev)
4642 return (PsppSheetViewColumn *)0x1;
4644 tmp_list = tmp_list->prev;
4645 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4646 tmp_list = tmp_list->prev;
4650 g_assert (tmp_list);
4652 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4654 if (left_column && !left_column->visible)
4656 /*if (!tmp_list->prev)
4657 return (PsppSheetViewColumn *)0x1;
4660 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->prev->data);
4661 tmp_list = tmp_list->prev->prev;
4664 cur_column = left_column;
4666 tmp_list = tmp_list->prev;
4670 if (!tree_view->priv->column_drop_func)
4673 if (tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4676 cur_column = left_column;
4677 tmp_list = tmp_list->prev;
4680 if (!tree_view->priv->column_drop_func)
4683 if (tree_view->priv->column_drop_func (tree_view, column, NULL, cur_column, tree_view->priv->column_drop_func_data))
4686 return (PsppSheetViewColumn *)0x1;
4690 /* same as DROP_HOME case, but doing it backwards */
4691 tmp_list = g_list_last (tree_view->priv->columns);
4694 if (column == PSPP_SHEET_VIEW_COLUMN (tmp_list->data))
4695 return (PsppSheetViewColumn *)0x1;
4699 g_assert (tmp_list);
4701 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4703 if (left_column && !left_column->visible)
4705 cur_column = left_column;
4706 tmp_list = tmp_list->prev;
4709 if (!tree_view->priv->column_drop_func)
4712 if (tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4715 cur_column = left_column;
4716 tmp_list = tmp_list->prev;
4719 if (!tree_view->priv->column_drop_func)
4722 if (tree_view->priv->column_drop_func (tree_view, column, NULL, cur_column, tree_view->priv->column_drop_func_data))
4725 return (PsppSheetViewColumn *)0x1;
4729 return (PsppSheetViewColumn *)0x1;
4733 pspp_sheet_view_key_press (GtkWidget *widget,
4736 PsppSheetView *tree_view = (PsppSheetView *) widget;
4738 if (tree_view->priv->rubber_band_status)
4740 if (event->keyval == GDK_Escape)
4741 pspp_sheet_view_stop_rubber_band (tree_view);
4746 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
4748 if (event->keyval == GDK_Escape)
4750 tree_view->priv->cur_reorder = NULL;
4751 pspp_sheet_view_button_release_drag_column (widget, NULL);
4756 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
4758 GList *focus_column;
4761 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
4763 for (focus_column = tree_view->priv->columns;
4765 focus_column = focus_column->next)
4767 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4769 if (column->button && gtk_widget_has_focus (column->button))
4774 (event->state & GDK_SHIFT_MASK) && (event->state & GDK_MOD1_MASK) &&
4775 (event->keyval == GDK_Left || event->keyval == GDK_KP_Left
4776 || event->keyval == GDK_Right || event->keyval == GDK_KP_Right))
4778 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4780 if (!column->resizable)
4782 gtk_widget_error_bell (widget);
4786 if (event->keyval == (rtl ? GDK_Right : GDK_Left)
4787 || event->keyval == (rtl ? GDK_KP_Right : GDK_KP_Left))
4789 gint old_width = column->resized_width;
4791 column->resized_width = MAX (column->resized_width,
4793 column->resized_width -= 2;
4794 if (column->resized_width < 0)
4795 column->resized_width = 0;
4797 if (column->min_width == -1)
4798 column->resized_width = MAX (column->button_request,
4799 column->resized_width);
4801 column->resized_width = MAX (column->min_width,
4802 column->resized_width);
4804 if (column->max_width != -1)
4805 column->resized_width = MIN (column->resized_width,
4808 column->use_resized_width = TRUE;
4810 if (column->resized_width != old_width)
4811 gtk_widget_queue_resize (widget);
4813 gtk_widget_error_bell (widget);
4815 else if (event->keyval == (rtl ? GDK_Left : GDK_Right)
4816 || event->keyval == (rtl ? GDK_KP_Left : GDK_KP_Right))
4818 gint old_width = column->resized_width;
4820 column->resized_width = MAX (column->resized_width,
4822 column->resized_width += 2;
4824 if (column->max_width != -1)
4825 column->resized_width = MIN (column->resized_width,
4828 column->use_resized_width = TRUE;
4830 if (column->resized_width != old_width)
4831 gtk_widget_queue_resize (widget);
4833 gtk_widget_error_bell (widget);
4840 (event->state & GDK_MOD1_MASK) &&
4841 (event->keyval == GDK_Left || event->keyval == GDK_KP_Left
4842 || event->keyval == GDK_Right || event->keyval == GDK_KP_Right
4843 || event->keyval == GDK_Home || event->keyval == GDK_KP_Home
4844 || event->keyval == GDK_End || event->keyval == GDK_KP_End))
4846 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4848 if (event->keyval == (rtl ? GDK_Right : GDK_Left)
4849 || event->keyval == (rtl ? GDK_KP_Right : GDK_KP_Left))
4851 PsppSheetViewColumn *col;
4852 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_LEFT);
4853 if (col != (PsppSheetViewColumn *)0x1)
4854 pspp_sheet_view_move_column_after (tree_view, column, col);
4856 gtk_widget_error_bell (widget);
4858 else if (event->keyval == (rtl ? GDK_Left : GDK_Right)
4859 || event->keyval == (rtl ? GDK_KP_Left : GDK_KP_Right))
4861 PsppSheetViewColumn *col;
4862 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_RIGHT);
4863 if (col != (PsppSheetViewColumn *)0x1)
4864 pspp_sheet_view_move_column_after (tree_view, column, col);
4866 gtk_widget_error_bell (widget);
4868 else if (event->keyval == GDK_Home || event->keyval == GDK_KP_Home)
4870 PsppSheetViewColumn *col;
4871 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_HOME);
4872 if (col != (PsppSheetViewColumn *)0x1)
4873 pspp_sheet_view_move_column_after (tree_view, column, col);
4875 gtk_widget_error_bell (widget);
4877 else if (event->keyval == GDK_End || event->keyval == GDK_KP_End)
4879 PsppSheetViewColumn *col;
4880 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_END);
4881 if (col != (PsppSheetViewColumn *)0x1)
4882 pspp_sheet_view_move_column_after (tree_view, column, col);
4884 gtk_widget_error_bell (widget);
4891 /* Chain up to the parent class. It handles the keybindings. */
4892 if (GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->key_press_event (widget, event))
4895 if (tree_view->priv->search_entry_avoid_unhandled_binding)
4897 tree_view->priv->search_entry_avoid_unhandled_binding = FALSE;
4901 /* We pass the event to the search_entry. If its text changes, then we start
4902 * the typeahead find capabilities. */
4903 if (gtk_widget_has_focus (GTK_WIDGET (tree_view))
4904 && tree_view->priv->enable_search
4905 && !tree_view->priv->search_custom_entry_set)
4907 GdkEvent *new_event;
4909 const char *new_text;
4912 gboolean text_modified;
4913 gulong popup_menu_id;
4915 pspp_sheet_view_ensure_interactive_directory (tree_view);
4917 /* Make a copy of the current text */
4918 old_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry)));
4919 new_event = gdk_event_copy ((GdkEvent *) event);
4920 g_object_unref (((GdkEventKey *) new_event)->window);
4921 ((GdkEventKey *) new_event)->window = g_object_ref (gtk_widget_get_window (tree_view->priv->search_window));
4922 gtk_widget_realize (tree_view->priv->search_window);
4924 popup_menu_id = g_signal_connect (tree_view->priv->search_entry,
4925 "popup-menu", G_CALLBACK (gtk_true),
4928 /* Move the entry off screen */
4929 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
4930 gtk_window_move (GTK_WINDOW (tree_view->priv->search_window),
4931 gdk_screen_get_width (screen) + 1,
4932 gdk_screen_get_height (screen) + 1);
4933 gtk_widget_show (tree_view->priv->search_window);
4935 /* Send the event to the window. If the preedit_changed signal is emitted
4936 * during this event, we will set priv->imcontext_changed */
4937 tree_view->priv->imcontext_changed = FALSE;
4938 retval = gtk_widget_event (tree_view->priv->search_window, new_event);
4939 gdk_event_free (new_event);
4940 gtk_widget_hide (tree_view->priv->search_window);
4942 g_signal_handler_disconnect (tree_view->priv->search_entry,
4945 /* We check to make sure that the entry tried to handle the text, and that
4946 * the text has changed.
4948 new_text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
4949 text_modified = strcmp (old_text, new_text) != 0;
4951 if (tree_view->priv->imcontext_changed || /* we're in a preedit */
4952 (retval && text_modified)) /* ...or the text was modified */
4954 if (pspp_sheet_view_real_start_interactive_search (tree_view, FALSE))
4956 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
4961 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
4971 pspp_sheet_view_key_release (GtkWidget *widget,
4974 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4976 if (tree_view->priv->rubber_band_status)
4979 return GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->key_release_event (widget, event);
4982 /* FIXME Is this function necessary? Can I get an enter_notify event
4983 * w/o either an expose event or a mouse motion event?
4986 pspp_sheet_view_enter_notify (GtkWidget *widget,
4987 GdkEventCrossing *event)
4989 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4993 /* Sanity check it */
4994 if (event->window != tree_view->priv->bin_window)
4997 if (tree_view->priv->row_count == 0)
5000 if (event->mode == GDK_CROSSING_GRAB ||
5001 event->mode == GDK_CROSSING_GTK_GRAB ||
5002 event->mode == GDK_CROSSING_GTK_UNGRAB ||
5003 event->mode == GDK_CROSSING_STATE_CHANGED)
5006 /* find the node internally */
5007 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, event->y);
5010 pspp_sheet_view_find_offset (tree_view, new_y, &node);
5012 tree_view->priv->event_last_x = event->x;
5013 tree_view->priv->event_last_y = event->y;
5015 prelight_or_select (tree_view, node, event->x, event->y);
5021 pspp_sheet_view_leave_notify (GtkWidget *widget,
5022 GdkEventCrossing *event)
5024 PsppSheetView *tree_view;
5026 if (event->mode == GDK_CROSSING_GRAB)
5029 tree_view = PSPP_SHEET_VIEW (widget);
5031 if (tree_view->priv->prelight_node >= 0)
5032 _pspp_sheet_view_queue_draw_node (tree_view,
5033 tree_view->priv->prelight_node,
5036 tree_view->priv->event_last_x = -10000;
5037 tree_view->priv->event_last_y = -10000;
5039 prelight_or_select (tree_view,
5041 -1000, -1000); /* coords not possibly over an arrow */
5048 pspp_sheet_view_focus_out (GtkWidget *widget,
5049 GdkEventFocus *event)
5051 PsppSheetView *tree_view;
5053 tree_view = PSPP_SHEET_VIEW (widget);
5055 gtk_widget_queue_draw (widget);
5057 /* destroy interactive search dialog */
5058 if (tree_view->priv->search_window)
5059 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
5065 /* Incremental Reflow
5069 pspp_sheet_view_node_queue_redraw (PsppSheetView *tree_view,
5072 GtkAllocation allocation;
5073 gint y = pspp_sheet_view_node_find_offset (tree_view, node)
5074 - gtk_adjustment_get_value (tree_view->priv->vadjustment)
5075 + TREE_VIEW_HEADER_HEIGHT (tree_view);
5077 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
5079 gtk_widget_queue_draw_area (GTK_WIDGET (tree_view),
5082 tree_view->priv->fixed_height);
5086 node_is_visible (PsppSheetView *tree_view,
5092 y = pspp_sheet_view_node_find_offset (tree_view, node);
5093 height = ROW_HEIGHT (tree_view);
5095 if (y >= gtk_adjustment_get_value (tree_view->priv->vadjustment) &&
5096 y + height <= (gtk_adjustment_get_value (tree_view->priv->vadjustment)
5097 + gtk_adjustment_get_page_size (tree_view->priv->vadjustment)))
5103 /* Returns the row height. */
5105 validate_row (PsppSheetView *tree_view,
5110 PsppSheetViewColumn *column;
5111 GList *list, *first_column, *last_column;
5113 gint horizontal_separator;
5114 gint vertical_separator;
5115 gint focus_line_width;
5116 gboolean draw_vgrid_lines, draw_hgrid_lines;
5118 gint grid_line_width;
5119 gboolean wide_separators;
5120 gint separator_height;
5122 gtk_widget_style_get (GTK_WIDGET (tree_view),
5123 "focus-padding", &focus_pad,
5124 "focus-line-width", &focus_line_width,
5125 "horizontal-separator", &horizontal_separator,
5126 "vertical-separator", &vertical_separator,
5127 "grid-line-width", &grid_line_width,
5128 "wide-separators", &wide_separators,
5129 "separator-height", &separator_height,
5133 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
5134 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
5136 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
5137 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
5139 for (last_column = g_list_last (tree_view->priv->columns);
5140 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
5141 last_column = last_column->prev)
5144 for (first_column = g_list_first (tree_view->priv->columns);
5145 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
5146 first_column = first_column->next)
5149 for (list = tree_view->priv->columns; list; list = list->next)
5154 column = list->data;
5156 if (! column->visible)
5159 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, iter);
5160 pspp_sheet_view_column_cell_get_size (column,
5162 &tmp_width, &tmp_height);
5164 tmp_height += vertical_separator;
5165 height = MAX (height, tmp_height);
5167 tmp_width = tmp_width + horizontal_separator;
5169 if (draw_vgrid_lines)
5171 if (list->data == first_column || list->data == last_column)
5172 tmp_width += grid_line_width / 2.0;
5174 tmp_width += grid_line_width;
5177 if (tmp_width > column->requested_width)
5178 column->requested_width = tmp_width;
5181 if (draw_hgrid_lines)
5182 height += grid_line_width;
5184 tree_view->priv->post_validation_flag = TRUE;
5190 validate_visible_area (PsppSheetView *tree_view)
5192 GtkTreePath *path = NULL;
5193 GtkTreePath *above_path = NULL;
5196 gboolean size_changed = FALSE;
5198 gint area_above = 0;
5199 gint area_below = 0;
5200 GtkAllocation allocation;
5202 if (tree_view->priv->row_count == 0)
5205 if (tree_view->priv->scroll_to_path == NULL)
5208 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
5210 total_height = allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
5212 if (total_height == 0)
5215 path = gtk_tree_row_reference_get_path (tree_view->priv->scroll_to_path);
5218 /* we are going to scroll, and will update dy */
5219 _pspp_sheet_view_find_node (tree_view, path, &node);
5220 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
5222 if (tree_view->priv->scroll_to_use_align)
5224 gint height = ROW_HEIGHT (tree_view);
5225 area_above = (total_height - height) *
5226 tree_view->priv->scroll_to_row_align;
5227 area_below = total_height - area_above - height;
5228 area_above = MAX (area_above, 0);
5229 area_below = MAX (area_below, 0);
5234 * 1) row not visible
5238 gint height = ROW_HEIGHT (tree_view);
5240 dy = pspp_sheet_view_node_find_offset (tree_view, node);
5242 if (dy >= gtk_adjustment_get_value (tree_view->priv->vadjustment) &&
5243 dy + height <= (gtk_adjustment_get_value (tree_view->priv->vadjustment)
5244 + gtk_adjustment_get_page_size (tree_view->priv->vadjustment)))
5246 /* row visible: keep the row at the same position */
5247 area_above = dy - gtk_adjustment_get_value (tree_view->priv->vadjustment);
5248 area_below = (gtk_adjustment_get_value (tree_view->priv->vadjustment) +
5249 gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
5254 /* row not visible */
5256 && dy + height <= gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
5258 /* row at the beginning -- fixed */
5260 area_below = gtk_adjustment_get_page_size (tree_view->priv->vadjustment)
5261 - area_above - height;
5263 else if (dy >= (gtk_adjustment_get_upper (tree_view->priv->vadjustment) -
5264 gtk_adjustment_get_page_size (tree_view->priv->vadjustment)))
5266 /* row at the end -- fixed */
5267 area_above = dy - (gtk_adjustment_get_upper (tree_view->priv->vadjustment) -
5268 gtk_adjustment_get_page_size (tree_view->priv->vadjustment));
5269 area_below = gtk_adjustment_get_page_size (tree_view->priv->vadjustment) -
5270 area_above - height;
5274 area_above = gtk_adjustment_get_page_size (tree_view->priv->vadjustment) - height;
5280 /* row somewhere in the middle, bring it to the top
5284 area_below = total_height - height;
5290 /* the scroll to isn't valid; ignore it.
5293 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
5294 tree_view->priv->scroll_to_path = NULL;
5298 above_path = gtk_tree_path_copy (path);
5300 /* Now, we walk forwards and backwards, measuring rows. Unfortunately,
5301 * backwards is much slower then forward, as there is no iter_prev function.
5302 * We go forwards first in case we run out of tree. Then we go backwards to
5305 while (node >= 0 && area_below > 0)
5307 gboolean done = FALSE;
5310 node = pspp_sheet_view_node_next (tree_view, node);
5313 gboolean has_next = gtk_tree_model_iter_next (tree_view->priv->model, &iter);
5315 gtk_tree_path_next (path);
5318 TREE_VIEW_INTERNAL_ASSERT_VOID (has_next);
5328 area_below -= ROW_HEIGHT (tree_view);
5330 gtk_tree_path_free (path);
5332 /* If we ran out of tree, and have extra area_below left, we need to add it
5335 area_above += area_below;
5337 _pspp_sheet_view_find_node (tree_view, above_path, &node);
5339 /* We walk backwards */
5340 while (area_above > 0)
5342 node = pspp_sheet_view_node_prev (tree_view, node);
5344 /* Always find the new path in the tree. We cannot just assume
5345 * a gtk_tree_path_prev() is enough here, as there might be children
5346 * in between this node and the previous sibling node. If this
5347 * appears to be a performance hotspot in profiles, we can look into
5348 * intrigate logic for keeping path, node and iter in sync like
5349 * we do for forward walks. (Which will be hard because of the lacking
5356 gtk_tree_path_free (above_path);
5357 above_path = _pspp_sheet_view_find_path (tree_view, node);
5359 gtk_tree_model_get_iter (tree_view->priv->model, &iter, above_path);
5361 area_above -= ROW_HEIGHT (tree_view);
5364 /* set the dy here to scroll to the path,
5365 * and sync the top row accordingly
5367 pspp_sheet_view_set_top_row (tree_view, above_path, -area_above);
5368 pspp_sheet_view_top_row_to_dy (tree_view);
5370 /* update width/height and queue a resize */
5373 GtkRequisition requisition;
5375 /* We temporarily guess a size, under the assumption that it will be the
5376 * same when we get our next size_allocate. If we don't do this, we'll be
5377 * in an inconsistent state if we call top_row_to_dy. */
5379 gtk_widget_size_request (GTK_WIDGET (tree_view), &requisition);
5380 gtk_adjustment_set_upper (tree_view->priv->hadjustment, MAX (gtk_adjustment_get_upper (tree_view->priv->hadjustment), (gfloat)requisition.width));
5381 gtk_adjustment_set_upper (tree_view->priv->vadjustment, MAX (gtk_adjustment_get_upper (tree_view->priv->vadjustment), (gfloat)requisition.height));
5382 gtk_adjustment_changed (tree_view->priv->hadjustment);
5383 gtk_adjustment_changed (tree_view->priv->vadjustment);
5384 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
5387 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
5388 tree_view->priv->scroll_to_path = NULL;
5391 gtk_tree_path_free (above_path);
5393 if (tree_view->priv->scroll_to_column)
5395 tree_view->priv->scroll_to_column = NULL;
5397 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
5401 initialize_fixed_height_mode (PsppSheetView *tree_view)
5403 if (!tree_view->priv->row_count)
5406 if (tree_view->priv->fixed_height_set)
5409 if (tree_view->priv->fixed_height < 0)
5416 path = _pspp_sheet_view_find_path (tree_view, node);
5417 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
5419 tree_view->priv->fixed_height = validate_row (tree_view, node, &iter, path);
5421 gtk_tree_path_free (path);
5423 g_object_notify (G_OBJECT (tree_view), "fixed-height");
5427 /* Our strategy for finding nodes to validate is a little convoluted. We find
5428 * the left-most uninvalidated node. We then try walking right, validating
5429 * nodes. Once we find a valid node, we repeat the previous process of finding
5430 * the first invalid node.
5434 validate_rows_handler (PsppSheetView *tree_view)
5436 initialize_fixed_height_mode (tree_view);
5437 if (tree_view->priv->validate_rows_timer)
5439 g_source_remove (tree_view->priv->validate_rows_timer);
5440 tree_view->priv->validate_rows_timer = 0;
5447 do_presize_handler (PsppSheetView *tree_view)
5449 GtkRequisition requisition;
5451 validate_visible_area (tree_view);
5452 tree_view->priv->presize_handler_timer = 0;
5454 if (! gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5457 gtk_widget_size_request (GTK_WIDGET (tree_view), &requisition);
5459 gtk_adjustment_set_upper (tree_view->priv->hadjustment, MAX (gtk_adjustment_get_upper (tree_view->priv->hadjustment), (gfloat)requisition.width));
5460 gtk_adjustment_set_upper (tree_view->priv->vadjustment, MAX (gtk_adjustment_get_upper (tree_view->priv->vadjustment), (gfloat)requisition.height));
5461 gtk_adjustment_changed (tree_view->priv->hadjustment);
5462 gtk_adjustment_changed (tree_view->priv->vadjustment);
5463 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
5469 presize_handler_callback (gpointer data)
5471 do_presize_handler (PSPP_SHEET_VIEW (data));
5477 install_presize_handler (PsppSheetView *tree_view)
5479 if (! gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5482 if (! tree_view->priv->presize_handler_timer)
5484 tree_view->priv->presize_handler_timer =
5485 gdk_threads_add_idle_full (GTK_PRIORITY_RESIZE - 2, presize_handler_callback, tree_view, NULL);
5487 if (! tree_view->priv->validate_rows_timer)
5489 tree_view->priv->validate_rows_timer =
5490 gdk_threads_add_idle_full (PSPP_SHEET_VIEW_PRIORITY_VALIDATE, (GSourceFunc) validate_rows_handler, tree_view, NULL);
5495 scroll_sync_handler (PsppSheetView *tree_view)
5497 if (tree_view->priv->height <= gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
5498 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment), 0);
5499 else if (gtk_tree_row_reference_valid (tree_view->priv->top_row))
5500 pspp_sheet_view_top_row_to_dy (tree_view);
5502 pspp_sheet_view_dy_to_top_row (tree_view);
5504 tree_view->priv->scroll_sync_timer = 0;
5510 install_scroll_sync_handler (PsppSheetView *tree_view)
5512 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5515 if (!tree_view->priv->scroll_sync_timer)
5517 tree_view->priv->scroll_sync_timer =
5518 gdk_threads_add_idle_full (PSPP_SHEET_VIEW_PRIORITY_SCROLL_SYNC, (GSourceFunc) scroll_sync_handler, tree_view, NULL);
5523 pspp_sheet_view_set_top_row (PsppSheetView *tree_view,
5527 gtk_tree_row_reference_free (tree_view->priv->top_row);
5531 tree_view->priv->top_row = NULL;
5532 tree_view->priv->top_row_dy = 0;
5536 tree_view->priv->top_row = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
5537 tree_view->priv->top_row_dy = offset;
5541 /* Always call this iff dy is in the visible range. If the tree is empty, then
5542 * it's set to be NULL, and top_row_dy is 0;
5545 pspp_sheet_view_dy_to_top_row (PsppSheetView *tree_view)
5551 if (tree_view->priv->row_count == 0)
5553 pspp_sheet_view_set_top_row (tree_view, NULL, 0);
5557 offset = pspp_sheet_view_find_offset (tree_view,
5558 tree_view->priv->dy,
5563 pspp_sheet_view_set_top_row (tree_view, NULL, 0);
5567 path = _pspp_sheet_view_find_path (tree_view, node);
5568 pspp_sheet_view_set_top_row (tree_view, path, offset);
5569 gtk_tree_path_free (path);
5575 pspp_sheet_view_top_row_to_dy (PsppSheetView *tree_view)
5581 /* Avoid recursive calls */
5582 if (tree_view->priv->in_top_row_to_dy)
5585 if (tree_view->priv->top_row)
5586 path = gtk_tree_row_reference_get_path (tree_view->priv->top_row);
5593 _pspp_sheet_view_find_node (tree_view, path, &node);
5596 gtk_tree_path_free (path);
5600 /* keep dy and set new toprow */
5601 gtk_tree_row_reference_free (tree_view->priv->top_row);
5602 tree_view->priv->top_row = NULL;
5603 tree_view->priv->top_row_dy = 0;
5604 /* DO NOT install the idle handler */
5605 pspp_sheet_view_dy_to_top_row (tree_view);
5609 if (ROW_HEIGHT (tree_view) < tree_view->priv->top_row_dy)
5611 /* new top row -- do NOT install the idle handler */
5612 pspp_sheet_view_dy_to_top_row (tree_view);
5616 new_dy = pspp_sheet_view_node_find_offset (tree_view, node);
5617 new_dy += tree_view->priv->top_row_dy;
5619 if (new_dy + gtk_adjustment_get_page_size (tree_view->priv->vadjustment) > tree_view->priv->height)
5620 new_dy = tree_view->priv->height - gtk_adjustment_get_page_size (tree_view->priv->vadjustment);
5622 new_dy = MAX (0, new_dy);
5624 tree_view->priv->in_top_row_to_dy = TRUE;
5625 gtk_adjustment_set_value (tree_view->priv->vadjustment, (gdouble)new_dy);
5626 tree_view->priv->in_top_row_to_dy = FALSE;
5631 _pspp_sheet_view_install_mark_rows_col_dirty (PsppSheetView *tree_view)
5633 install_presize_handler (tree_view);
5639 set_source_row (GdkDragContext *context,
5640 GtkTreeModel *model,
5641 GtkTreePath *source_row)
5643 g_object_set_data_full (G_OBJECT (context),
5644 "gtk-tree-view-source-row",
5645 source_row ? gtk_tree_row_reference_new (model, source_row) : NULL,
5646 (GDestroyNotify) (source_row ? gtk_tree_row_reference_free : NULL));
5650 get_source_row (GdkDragContext *context)
5652 GtkTreeRowReference *ref =
5653 g_object_get_data (G_OBJECT (context), "gtk-tree-view-source-row");
5656 return gtk_tree_row_reference_get_path (ref);
5663 GtkTreeRowReference *dest_row;
5664 guint path_down_mode : 1;
5665 guint empty_view_drop : 1;
5666 guint drop_append_mode : 1;
5671 dest_row_free (gpointer data)
5673 DestRow *dr = (DestRow *)data;
5675 gtk_tree_row_reference_free (dr->dest_row);
5676 g_slice_free (DestRow, dr);
5680 set_dest_row (GdkDragContext *context,
5681 GtkTreeModel *model,
5682 GtkTreePath *dest_row,
5683 gboolean path_down_mode,
5684 gboolean empty_view_drop,
5685 gboolean drop_append_mode)
5691 g_object_set_data_full (G_OBJECT (context), "gtk-tree-view-dest-row",
5696 dr = g_slice_new (DestRow);
5698 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5699 dr->path_down_mode = path_down_mode != FALSE;
5700 dr->empty_view_drop = empty_view_drop != FALSE;
5701 dr->drop_append_mode = drop_append_mode != FALSE;
5703 g_object_set_data_full (G_OBJECT (context), "gtk-tree-view-dest-row",
5704 dr, (GDestroyNotify) dest_row_free);
5708 get_dest_row (GdkDragContext *context,
5709 gboolean *path_down_mode)
5712 g_object_get_data (G_OBJECT (context), "gtk-tree-view-dest-row");
5716 GtkTreePath *path = NULL;
5719 *path_down_mode = dr->path_down_mode;
5722 path = gtk_tree_row_reference_get_path (dr->dest_row);
5723 else if (dr->empty_view_drop)
5724 path = gtk_tree_path_new_from_indices (0, -1);
5728 if (path && dr->drop_append_mode)
5729 gtk_tree_path_next (path);
5737 /* Get/set whether drag_motion requested the drag data and
5738 * drag_data_received should thus not actually insert the data,
5739 * since the data doesn't result from a drop.
5742 set_status_pending (GdkDragContext *context,
5743 GdkDragAction suggested_action)
5745 g_object_set_data (G_OBJECT (context),
5746 "gtk-tree-view-status-pending",
5747 GINT_TO_POINTER (suggested_action));
5750 static GdkDragAction
5751 get_status_pending (GdkDragContext *context)
5753 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5754 "gtk-tree-view-status-pending"));
5757 static TreeViewDragInfo*
5758 get_info (PsppSheetView *tree_view)
5760 return g_object_get_data (G_OBJECT (tree_view), "gtk-tree-view-drag-info");
5764 destroy_info (TreeViewDragInfo *di)
5766 g_slice_free (TreeViewDragInfo, di);
5769 static TreeViewDragInfo*
5770 ensure_info (PsppSheetView *tree_view)
5772 TreeViewDragInfo *di;
5774 di = get_info (tree_view);
5778 di = g_slice_new0 (TreeViewDragInfo);
5780 g_object_set_data_full (G_OBJECT (tree_view),
5781 "gtk-tree-view-drag-info",
5783 (GDestroyNotify) destroy_info);
5790 remove_info (PsppSheetView *tree_view)
5792 g_object_set_data (G_OBJECT (tree_view), "gtk-tree-view-drag-info", NULL);
5797 drag_scan_timeout (gpointer data)
5799 PsppSheetView *tree_view;
5801 GdkModifierType state;
5802 GtkTreePath *path = NULL;
5803 PsppSheetViewColumn *column = NULL;
5804 GdkRectangle visible_rect;
5806 GDK_THREADS_ENTER ();
5808 tree_view = PSPP_SHEET_VIEW (data);
5810 gdk_window_get_pointer (tree_view->priv->bin_window,
5813 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
5815 /* See if we are near the edge. */
5816 if ((x - visible_rect.x) < SCROLL_EDGE_SIZE ||
5817 (visible_rect.x + visible_rect.width - x) < SCROLL_EDGE_SIZE ||
5818 (y - visible_rect.y) < SCROLL_EDGE_SIZE ||
5819 (visible_rect.y + visible_rect.height - y) < SCROLL_EDGE_SIZE)
5821 pspp_sheet_view_get_path_at_pos (tree_view,
5822 tree_view->priv->bin_window,
5831 pspp_sheet_view_scroll_to_cell (tree_view,
5837 gtk_tree_path_free (path);
5841 GDK_THREADS_LEAVE ();
5848 add_scroll_timeout (PsppSheetView *tree_view)
5850 if (tree_view->priv->scroll_timeout == 0)
5852 tree_view->priv->scroll_timeout =
5853 gdk_threads_add_timeout (150, scroll_row_timeout, tree_view);
5858 remove_scroll_timeout (PsppSheetView *tree_view)
5860 if (tree_view->priv->scroll_timeout != 0)
5862 g_source_remove (tree_view->priv->scroll_timeout);
5863 tree_view->priv->scroll_timeout = 0;
5868 check_model_dnd (GtkTreeModel *model,
5869 GType required_iface,
5870 const gchar *signal)
5872 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5874 g_warning ("You must override the default '%s' handler "
5875 "on PsppSheetView when using models that don't support "
5876 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5877 "is to connect to '%s' and call "
5878 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5879 "the default handler from running. Look at the source code "
5880 "for the default handler in gtktreeview.c to get an idea what "
5881 "your handler should do. (gtktreeview.c is in the GTK source "
5882 "code.) If you're using GTK from a language other than C, "
5883 "there may be a more natural way to override default handlers, e.g. via derivation.",
5884 signal, g_type_name (required_iface), signal);
5892 scroll_row_timeout (gpointer data)
5894 PsppSheetView *tree_view = data;
5896 pspp_sheet_view_horizontal_autoscroll (tree_view);
5897 pspp_sheet_view_vertical_autoscroll (tree_view);
5899 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
5900 pspp_sheet_view_update_rubber_band (tree_view);
5905 /* Returns TRUE if event should not be propagated to parent widgets */
5907 set_destination_row (PsppSheetView *tree_view,
5908 GdkDragContext *context,
5909 /* coordinates relative to the widget */
5912 GdkDragAction *suggested_action,
5915 GtkTreePath *path = NULL;
5916 PsppSheetViewDropPosition pos;
5917 PsppSheetViewDropPosition old_pos;
5918 TreeViewDragInfo *di;
5920 GtkTreePath *old_dest_path = NULL;
5921 gboolean can_drop = FALSE;
5923 *suggested_action = 0;
5926 widget = GTK_WIDGET (tree_view);
5928 di = get_info (tree_view);
5930 if (di == NULL || y - TREE_VIEW_HEADER_HEIGHT (tree_view) < 0)
5932 /* someone unset us as a drag dest, note that if
5933 * we return FALSE drag_leave isn't called
5936 pspp_sheet_view_set_drag_dest_row (tree_view,
5938 PSPP_SHEET_VIEW_DROP_BEFORE);
5940 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
5942 return FALSE; /* no longer a drop site */
5945 *target = gtk_drag_dest_find_target (widget, context,
5946 gtk_drag_dest_get_target_list (widget));
5947 if (*target == GDK_NONE)
5952 if (!pspp_sheet_view_get_dest_row_at_pos (tree_view,
5958 GtkTreeModel *model;
5960 /* the row got dropped on empty space, let's setup a special case
5964 gtk_tree_path_free (path);
5966 model = pspp_sheet_view_get_model (tree_view);
5968 n_children = gtk_tree_model_iter_n_children (model, NULL);
5971 pos = PSPP_SHEET_VIEW_DROP_AFTER;
5972 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
5976 pos = PSPP_SHEET_VIEW_DROP_BEFORE;
5977 path = gtk_tree_path_new_from_indices (0, -1);
5987 /* If we left the current row's "open" zone, unset the timeout for
5990 pspp_sheet_view_get_drag_dest_row (tree_view,
5995 gtk_tree_path_free (old_dest_path);
5997 if (TRUE /* FIXME if the location droppable predicate */)
6005 GtkWidget *source_widget;
6007 *suggested_action = gdk_drag_context_get_suggested_action (context);
6008 source_widget = gtk_drag_get_source_widget (context);
6010 if (source_widget == widget)
6012 /* Default to MOVE, unless the user has
6013 * pressed ctrl or shift to affect available actions
6015 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
6016 *suggested_action = GDK_ACTION_MOVE;
6019 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6024 /* can't drop here */
6025 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6027 PSPP_SHEET_VIEW_DROP_BEFORE);
6031 gtk_tree_path_free (path);
6037 get_logical_dest_row (PsppSheetView *tree_view,
6038 gboolean *path_down_mode,
6039 gboolean *drop_append_mode)
6041 /* adjust path to point to the row the drop goes in front of */
6042 GtkTreePath *path = NULL;
6043 PsppSheetViewDropPosition pos;
6045 g_return_val_if_fail (path_down_mode != NULL, NULL);
6046 g_return_val_if_fail (drop_append_mode != NULL, NULL);
6048 *path_down_mode = FALSE;
6049 *drop_append_mode = 0;
6051 pspp_sheet_view_get_drag_dest_row (tree_view, &path, &pos);
6056 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE)
6058 else if (pos == PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE ||
6059 pos == PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER)
6060 *path_down_mode = TRUE;
6064 GtkTreeModel *model = pspp_sheet_view_get_model (tree_view);
6066 g_assert (pos == PSPP_SHEET_VIEW_DROP_AFTER);
6068 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6069 !gtk_tree_model_iter_next (model, &iter))
6070 *drop_append_mode = 1;
6073 *drop_append_mode = 0;
6074 gtk_tree_path_next (path);
6082 pspp_sheet_view_maybe_begin_dragging_row (PsppSheetView *tree_view,
6083 GdkEventMotion *event)
6085 GtkWidget *widget = GTK_WIDGET (tree_view);
6086 GdkDragContext *context;
6087 TreeViewDragInfo *di;
6088 GtkTreePath *path = NULL;
6090 gint cell_x, cell_y;
6091 GtkTreeModel *model;
6092 gboolean retval = FALSE;
6094 di = get_info (tree_view);
6096 if (di == NULL || !di->source_set)
6099 if (tree_view->priv->pressed_button < 0)
6102 if (!gtk_drag_check_threshold (widget,
6103 tree_view->priv->press_start_x,
6104 tree_view->priv->press_start_y,
6105 event->x, event->y))
6108 model = pspp_sheet_view_get_model (tree_view);
6113 button = tree_view->priv->pressed_button;
6114 tree_view->priv->pressed_button = -1;
6116 pspp_sheet_view_get_path_at_pos (tree_view,
6117 tree_view->priv->press_start_x,
6118 tree_view->priv->press_start_y,
6127 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6128 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6132 if (!(GDK_BUTTON1_MASK << (button - 1) & di->start_button_mask))
6135 /* Now we can begin the drag */
6139 context = gtk_drag_begin (widget,
6140 gtk_drag_source_get_target_list (widget),
6145 set_source_row (context, model, path);
6149 gtk_tree_path_free (path);
6157 pspp_sheet_view_drag_begin (GtkWidget *widget,
6158 GdkDragContext *context)
6161 PsppSheetView *tree_view;
6162 GtkTreePath *path = NULL;
6163 gint cell_x, cell_y;
6165 TreeViewDragInfo *di;
6167 tree_view = PSPP_SHEET_VIEW (widget);
6169 /* if the user uses a custom DND source impl, we don't set the icon here */
6170 di = get_info (tree_view);
6172 if (di == NULL || !di->source_set)
6175 pspp_sheet_view_get_path_at_pos (tree_view,
6176 tree_view->priv->press_start_x,
6177 tree_view->priv->press_start_y,
6183 g_return_if_fail (path != NULL);
6185 row_pix = pspp_sheet_view_create_row_drag_icon (tree_view,
6188 gtk_drag_set_icon_pixmap (context,
6189 gdk_drawable_get_colormap (row_pix),
6192 /* the + 1 is for the black border in the icon */
6193 tree_view->priv->press_start_x + 1,
6196 g_object_unref (row_pix);
6197 gtk_tree_path_free (path);
6203 pspp_sheet_view_drag_end (GtkWidget *widget,
6204 GdkDragContext *context)
6209 /* Default signal implementations for the drag signals */
6211 pspp_sheet_view_drag_data_get (GtkWidget *widget,
6212 GdkDragContext *context,
6213 GtkSelectionData *selection_data,
6217 PsppSheetView *tree_view;
6218 GtkTreeModel *model;
6219 TreeViewDragInfo *di;
6220 GtkTreePath *source_row;
6222 tree_view = PSPP_SHEET_VIEW (widget);
6224 model = pspp_sheet_view_get_model (tree_view);
6229 di = get_info (PSPP_SHEET_VIEW (widget));
6234 source_row = get_source_row (context);
6236 if (source_row == NULL)
6239 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6240 * any model; for DragSource models there are some other targets
6244 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6245 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6250 /* If drag_data_get does nothing, try providing row data. */
6251 if (gtk_selection_data_get_target (selection_data) == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6253 gtk_tree_set_row_drag_data (selection_data,
6259 gtk_tree_path_free (source_row);
6264 pspp_sheet_view_drag_data_delete (GtkWidget *widget,
6265 GdkDragContext *context)
6267 TreeViewDragInfo *di;
6268 GtkTreeModel *model;
6269 PsppSheetView *tree_view;
6270 GtkTreePath *source_row;
6272 tree_view = PSPP_SHEET_VIEW (widget);
6273 model = pspp_sheet_view_get_model (tree_view);
6275 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
6278 di = get_info (tree_view);
6283 source_row = get_source_row (context);
6285 if (source_row == NULL)
6288 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6291 gtk_tree_path_free (source_row);
6293 set_source_row (context, NULL, NULL);
6297 pspp_sheet_view_drag_leave (GtkWidget *widget,
6298 GdkDragContext *context,
6301 /* unset any highlight row */
6302 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6304 PSPP_SHEET_VIEW_DROP_BEFORE);
6306 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6311 pspp_sheet_view_drag_motion (GtkWidget *widget,
6312 GdkDragContext *context,
6313 /* coordinates relative to the widget */
6319 GtkTreePath *path = NULL;
6320 PsppSheetViewDropPosition pos;
6321 PsppSheetView *tree_view;
6322 GdkDragAction suggested_action = 0;
6325 tree_view = PSPP_SHEET_VIEW (widget);
6327 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6330 pspp_sheet_view_get_drag_dest_row (tree_view, &path, &pos);
6332 /* we only know this *after* set_desination_row */
6333 empty = tree_view->priv->empty_view_drop;
6335 if (path == NULL && !empty)
6337 /* Can't drop here. */
6338 gdk_drag_status (context, 0, time);
6342 if (tree_view->priv->open_dest_timeout == 0 &&
6343 (pos == PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER ||
6344 pos == PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE))
6350 add_scroll_timeout (tree_view);
6353 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6355 /* Request data so we can use the source row when
6356 * determining whether to accept the drop
6358 set_status_pending (context, suggested_action);
6359 gtk_drag_get_data (widget, context, target, time);
6363 set_status_pending (context, 0);
6364 gdk_drag_status (context, suggested_action, time);
6369 gtk_tree_path_free (path);
6376 pspp_sheet_view_drag_drop (GtkWidget *widget,
6377 GdkDragContext *context,
6378 /* coordinates relative to the widget */
6383 PsppSheetView *tree_view;
6385 GdkDragAction suggested_action = 0;
6386 GdkAtom target = GDK_NONE;
6387 TreeViewDragInfo *di;
6388 GtkTreeModel *model;
6389 gboolean path_down_mode;
6390 gboolean drop_append_mode;
6392 tree_view = PSPP_SHEET_VIEW (widget);
6394 model = pspp_sheet_view_get_model (tree_view);
6396 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6398 di = get_info (tree_view);
6403 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
6406 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6409 path = get_logical_dest_row (tree_view, &path_down_mode, &drop_append_mode);
6411 if (target != GDK_NONE && path != NULL)
6413 /* in case a motion had requested drag data, change things so we
6414 * treat drag data receives as a drop.
6416 set_status_pending (context, 0);
6417 set_dest_row (context, model, path,
6418 path_down_mode, tree_view->priv->empty_view_drop,
6423 gtk_tree_path_free (path);
6425 /* Unset this thing */
6426 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6428 PSPP_SHEET_VIEW_DROP_BEFORE);
6430 if (target != GDK_NONE)
6432 gtk_drag_get_data (widget, context, target, time);
6440 pspp_sheet_view_drag_data_received (GtkWidget *widget,
6441 GdkDragContext *context,
6442 /* coordinates relative to the widget */
6445 GtkSelectionData *selection_data,
6450 TreeViewDragInfo *di;
6451 gboolean accepted = FALSE;
6452 GtkTreeModel *model;
6453 PsppSheetView *tree_view;
6454 GtkTreePath *dest_row;
6455 GdkDragAction suggested_action;
6456 gboolean path_down_mode;
6457 gboolean drop_append_mode;
6459 tree_view = PSPP_SHEET_VIEW (widget);
6461 model = pspp_sheet_view_get_model (tree_view);
6463 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_data_received"))
6466 di = get_info (tree_view);
6471 suggested_action = get_status_pending (context);
6473 if (suggested_action)
6475 /* We are getting this data due to a request in drag_motion,
6476 * rather than due to a request in drag_drop, so we are just
6477 * supposed to call drag_status, not actually paste in the
6480 path = get_logical_dest_row (tree_view, &path_down_mode,
6484 suggested_action = 0;
6485 else if (path_down_mode)
6486 gtk_tree_path_down (path);
6488 if (suggested_action)
6490 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6496 path_down_mode = FALSE;
6497 gtk_tree_path_up (path);
6499 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6502 suggested_action = 0;
6505 suggested_action = 0;
6509 gdk_drag_status (context, suggested_action, time);
6512 gtk_tree_path_free (path);
6514 /* If you can't drop, remove user drop indicator until the next motion */
6515 if (suggested_action == 0)
6516 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6518 PSPP_SHEET_VIEW_DROP_BEFORE);
6523 dest_row = get_dest_row (context, &path_down_mode);
6525 if (dest_row == NULL)
6528 if (gtk_selection_data_get_length (selection_data) >= 0)
6532 gtk_tree_path_down (dest_row);
6533 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6534 dest_row, selection_data))
6535 gtk_tree_path_up (dest_row);
6539 if (gtk_selection_data_get_length (selection_data) >= 0)
6541 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6547 gtk_drag_finish (context,
6549 (gdk_drag_context_get_actions (context) == GDK_ACTION_MOVE),
6552 if (gtk_tree_path_get_depth (dest_row) == 1
6553 && gtk_tree_path_get_indices (dest_row)[0] == 0)
6555 /* special special case drag to "0", scroll to first item */
6556 if (!tree_view->priv->scroll_to_path)
6557 pspp_sheet_view_scroll_to_cell (tree_view, dest_row, NULL, FALSE, 0.0, 0.0);
6560 gtk_tree_path_free (dest_row);
6563 set_dest_row (context, NULL, NULL, FALSE, FALSE, FALSE);
6568 /* GtkContainer Methods
6573 pspp_sheet_view_remove (GtkContainer *container,
6576 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6577 PsppSheetViewChild *child = NULL;
6580 tmp_list = tree_view->priv->children;
6583 child = tmp_list->data;
6584 if (child->widget == widget)
6586 gtk_widget_unparent (widget);
6588 tree_view->priv->children = g_list_remove_link (tree_view->priv->children, tmp_list);
6589 g_list_free_1 (tmp_list);
6590 g_slice_free (PsppSheetViewChild, child);
6594 tmp_list = tmp_list->next;
6597 tmp_list = tree_view->priv->columns;
6601 PsppSheetViewColumn *column;
6602 column = tmp_list->data;
6603 if (column->button == widget)
6605 gtk_widget_unparent (widget);
6608 tmp_list = tmp_list->next;
6613 pspp_sheet_view_forall (GtkContainer *container,
6614 gboolean include_internals,
6615 GtkCallback callback,
6616 gpointer callback_data)
6618 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6619 PsppSheetViewChild *child = NULL;
6620 PsppSheetViewColumn *column;
6623 tmp_list = tree_view->priv->children;
6626 child = tmp_list->data;
6627 tmp_list = tmp_list->next;
6629 (* callback) (child->widget, callback_data);
6631 if (include_internals == FALSE)
6634 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6636 column = tmp_list->data;
6639 (* callback) (column->button, callback_data);
6643 /* Returns TRUE if the treeview contains no "special" (editable or activatable)
6644 * cells. If so we draw one big row-spanning focus rectangle.
6647 pspp_sheet_view_has_special_cell (PsppSheetView *tree_view)
6651 if (tree_view->priv->special_cells != PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT)
6652 return tree_view->priv->special_cells = PSPP_SHEET_VIEW_SPECIAL_CELLS_YES;
6654 for (list = tree_view->priv->columns; list; list = list->next)
6656 if (!((PsppSheetViewColumn *)list->data)->visible)
6658 if (_pspp_sheet_view_column_count_special_cells (list->data))
6666 pspp_sheet_view_focus_column (PsppSheetView *tree_view,
6667 PsppSheetViewColumn *focus_column,
6668 gboolean clamp_column_visible)
6670 g_return_if_fail (focus_column != NULL);
6672 tree_view->priv->focus_column = focus_column;
6673 if (!focus_column->button)
6675 pspp_sheet_view_column_set_need_button (focus_column, TRUE);
6676 // g_return_if_fail (focus_column->button != NULL);
6677 if (focus_column->button == NULL)
6681 if (gtk_container_get_focus_child (GTK_CONTAINER (tree_view)) != focus_column->button)
6682 gtk_widget_grab_focus (focus_column->button);
6684 if (clamp_column_visible)
6685 pspp_sheet_view_clamp_column_visible (tree_view, focus_column, FALSE);
6688 /* Returns TRUE if the focus is within the headers, after the focus operation is
6692 pspp_sheet_view_header_focus (PsppSheetView *tree_view,
6693 GtkDirectionType dir,
6694 gboolean clamp_column_visible)
6696 GtkWidget *focus_child;
6697 PsppSheetViewColumn *focus_column;
6698 GList *last_column, *first_column;
6702 if (! PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
6705 focus_child = gtk_container_get_focus_child (GTK_CONTAINER (tree_view));
6707 first_column = tree_view->priv->columns;
6708 while (first_column)
6710 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (first_column->data);
6712 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6714 first_column = first_column->next;
6717 /* No headers are visible, or are focusable. We can't focus in or out.
6719 if (first_column == NULL)
6722 last_column = g_list_last (tree_view->priv->columns);
6725 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (last_column->data);
6727 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6729 last_column = last_column->prev;
6733 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
6737 case GTK_DIR_TAB_BACKWARD:
6738 case GTK_DIR_TAB_FORWARD:
6741 if (focus_child == NULL)
6743 if (tree_view->priv->focus_column != NULL &&
6744 pspp_sheet_view_column_can_focus (tree_view->priv->focus_column))
6745 focus_column = tree_view->priv->focus_column;
6747 focus_column = first_column->data;
6748 pspp_sheet_view_focus_column (tree_view, focus_column,
6749 clamp_column_visible);
6756 if (focus_child == NULL)
6758 if (tree_view->priv->focus_column != NULL)
6759 focus_column = tree_view->priv->focus_column;
6760 else if (dir == GTK_DIR_LEFT)
6761 focus_column = last_column->data;
6763 focus_column = first_column->data;
6764 pspp_sheet_view_focus_column (tree_view, focus_column,
6765 clamp_column_visible);
6769 if (gtk_widget_child_focus (focus_child, dir))
6771 /* The focus moves inside the button. */
6772 /* This is probably a great example of bad UI */
6773 if (clamp_column_visible)
6774 pspp_sheet_view_clamp_column_visible (tree_view,
6775 tree_view->priv->focus_column,
6780 /* We need to move the focus among the row of buttons. */
6781 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6782 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)->button == focus_child)
6785 if ((tmp_list == first_column && dir == (rtl ? GTK_DIR_RIGHT : GTK_DIR_LEFT))
6786 || (tmp_list == last_column && dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT)))
6788 gtk_widget_error_bell (GTK_WIDGET (tree_view));
6794 PsppSheetViewColumn *column;
6796 if (dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT))
6797 tmp_list = tmp_list->next;
6799 tmp_list = tmp_list->prev;
6801 if (tmp_list == NULL)
6803 g_warning ("Internal button not found");
6806 column = tmp_list->data;
6807 if (column->visible &&
6808 pspp_sheet_view_column_can_focus (column))
6810 pspp_sheet_view_column_set_need_button (column, TRUE);
6813 pspp_sheet_view_focus_column (tree_view, column,
6814 clamp_column_visible);
6822 g_assert_not_reached ();
6829 /* This function returns in 'path' the first focusable path, if the given path
6830 * is already focusable, it's the returned one.
6834 search_first_focusable_path (PsppSheetView *tree_view,
6836 gboolean search_forward,
6839 /* XXX this function is trivial given that the sheetview doesn't support
6843 if (!path || !*path)
6846 _pspp_sheet_view_find_node (tree_view, *path, &node);
6854 return (*path != NULL);
6858 pspp_sheet_view_focus (GtkWidget *widget,
6859 GtkDirectionType direction)
6861 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6862 GtkContainer *container = GTK_CONTAINER (widget);
6863 GtkWidget *focus_child;
6865 if (!gtk_widget_is_sensitive (widget) || !gtk_widget_get_can_focus (widget))
6868 focus_child = gtk_container_get_focus_child (container);
6870 pspp_sheet_view_stop_editing (PSPP_SHEET_VIEW (widget), FALSE);
6871 /* Case 1. Headers currently have focus. */
6878 pspp_sheet_view_header_focus (tree_view, direction, TRUE);
6880 case GTK_DIR_TAB_BACKWARD:
6883 case GTK_DIR_TAB_FORWARD:
6885 gtk_widget_grab_focus (widget);
6888 g_assert_not_reached ();
6893 /* Case 2. We don't have focus at all. */
6894 if (!gtk_widget_has_focus (widget))
6896 if (!pspp_sheet_view_header_focus (tree_view, direction, FALSE))
6897 gtk_widget_grab_focus (widget);
6901 /* Case 3. We have focus already. */
6902 if (direction == GTK_DIR_TAB_BACKWARD)
6903 return (pspp_sheet_view_header_focus (tree_view, direction, FALSE));
6904 else if (direction == GTK_DIR_TAB_FORWARD)
6907 /* Other directions caught by the keybindings */
6908 gtk_widget_grab_focus (widget);
6913 pspp_sheet_view_grab_focus (GtkWidget *widget)
6915 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->grab_focus (widget);
6917 pspp_sheet_view_focus_to_cursor (PSPP_SHEET_VIEW (widget));
6921 pspp_sheet_view_style_set (GtkWidget *widget,
6922 GtkStyle *previous_style)
6924 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6926 PsppSheetViewColumn *column;
6928 if (gtk_widget_get_realized (widget))
6930 gdk_window_set_background (tree_view->priv->bin_window, >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
6931 gtk_style_set_background (gtk_widget_get_style (widget), tree_view->priv->header_window, GTK_STATE_NORMAL);
6932 pspp_sheet_view_set_grid_lines (tree_view, tree_view->priv->grid_lines);
6935 gtk_widget_style_get (widget,
6936 "expander-size", &tree_view->priv->expander_size,
6938 tree_view->priv->expander_size += EXPANDER_EXTRA_PADDING;
6940 for (list = tree_view->priv->columns; list; list = list->next)
6942 column = list->data;
6943 _pspp_sheet_view_column_cell_set_dirty (column);
6946 tree_view->priv->fixed_height = -1;
6948 /* Invalidate cached button style. */
6949 if (tree_view->priv->button_style)
6951 g_object_unref (tree_view->priv->button_style);
6952 tree_view->priv->button_style = NULL;
6955 gtk_widget_queue_resize (widget);
6960 pspp_sheet_view_set_focus_child (GtkContainer *container,
6963 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6966 for (list = tree_view->priv->columns; list; list = list->next)
6968 if (PSPP_SHEET_VIEW_COLUMN (list->data)->button == child)
6970 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
6975 GTK_CONTAINER_CLASS (pspp_sheet_view_parent_class)->set_focus_child (container, child);
6979 pspp_sheet_view_set_adjustments (PsppSheetView *tree_view,
6980 GtkAdjustment *hadj,
6981 GtkAdjustment *vadj)
6983 gboolean need_adjust = FALSE;
6985 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
6988 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
6990 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
6992 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
6994 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
6996 if (tree_view->priv->hadjustment && (tree_view->priv->hadjustment != hadj))
6998 g_signal_handlers_disconnect_by_func (tree_view->priv->hadjustment,
6999 pspp_sheet_view_adjustment_changed,
7001 g_object_unref (tree_view->priv->hadjustment);
7004 if (tree_view->priv->vadjustment && (tree_view->priv->vadjustment != vadj))
7006 g_signal_handlers_disconnect_by_func (tree_view->priv->vadjustment,
7007 pspp_sheet_view_adjustment_changed,
7009 g_object_unref (tree_view->priv->vadjustment);
7012 if (tree_view->priv->hadjustment != hadj)
7014 tree_view->priv->hadjustment = hadj;
7015 g_object_ref_sink (tree_view->priv->hadjustment);
7017 g_signal_connect (tree_view->priv->hadjustment, "value-changed",
7018 G_CALLBACK (pspp_sheet_view_adjustment_changed),
7023 if (tree_view->priv->vadjustment != vadj)
7025 tree_view->priv->vadjustment = vadj;
7026 g_object_ref_sink (tree_view->priv->vadjustment);
7028 g_signal_connect (tree_view->priv->vadjustment, "value-changed",
7029 G_CALLBACK (pspp_sheet_view_adjustment_changed),
7035 pspp_sheet_view_adjustment_changed (NULL, tree_view);
7040 pspp_sheet_view_real_move_cursor (PsppSheetView *tree_view,
7041 GtkMovementStep step,
7044 PsppSheetSelectMode mode;
7045 GdkModifierType state;
7047 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
7048 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
7049 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
7050 step == GTK_MOVEMENT_DISPLAY_LINES ||
7051 step == GTK_MOVEMENT_PAGES ||
7052 step == GTK_MOVEMENT_BUFFER_ENDS ||
7053 step == GTK_MOVEMENT_DISPLAY_LINE_ENDS, FALSE);
7055 if (tree_view->priv->row_count == 0)
7057 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7060 pspp_sheet_view_stop_editing (tree_view, FALSE);
7061 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
7062 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7065 if (gtk_get_current_event_state (&state))
7067 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
7068 mode |= PSPP_SHEET_SELECT_MODE_TOGGLE;
7069 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
7070 mode |= PSPP_SHEET_SELECT_MODE_EXTEND;
7072 /* else we assume not pressed */
7076 case GTK_MOVEMENT_LOGICAL_POSITIONS:
7077 pspp_sheet_view_move_cursor_tab (tree_view, count);
7079 case GTK_MOVEMENT_VISUAL_POSITIONS:
7080 pspp_sheet_view_move_cursor_left_right (tree_view, count, mode);
7082 case GTK_MOVEMENT_DISPLAY_LINES:
7083 pspp_sheet_view_move_cursor_up_down (tree_view, count, mode);
7085 case GTK_MOVEMENT_PAGES:
7086 pspp_sheet_view_move_cursor_page_up_down (tree_view, count, mode);
7088 case GTK_MOVEMENT_BUFFER_ENDS:
7089 pspp_sheet_view_move_cursor_start_end (tree_view, count, mode);
7091 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
7092 pspp_sheet_view_move_cursor_line_start_end (tree_view, count, mode);
7095 g_assert_not_reached ();
7102 pspp_sheet_view_put (PsppSheetView *tree_view,
7103 GtkWidget *child_widget,
7104 /* in bin_window coordinates */
7110 PsppSheetViewChild *child;
7112 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
7113 g_return_if_fail (GTK_IS_WIDGET (child_widget));
7115 child = g_slice_new (PsppSheetViewChild);
7117 child->widget = child_widget;
7120 child->width = width;
7121 child->height = height;
7123 tree_view->priv->children = g_list_append (tree_view->priv->children, child);
7125 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7126 gtk_widget_set_parent_window (child->widget, tree_view->priv->bin_window);
7128 gtk_widget_set_parent (child_widget, GTK_WIDGET (tree_view));
7132 _pspp_sheet_view_child_move_resize (PsppSheetView *tree_view,
7134 /* in tree coordinates */
7140 PsppSheetViewChild *child = NULL;
7142 GdkRectangle allocation;
7144 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
7145 g_return_if_fail (GTK_IS_WIDGET (widget));
7147 for (list = tree_view->priv->children; list; list = list->next)
7149 if (((PsppSheetViewChild *)list->data)->widget == widget)
7158 allocation.x = child->x = x;
7159 allocation.y = child->y = y;
7160 allocation.width = child->width = width;
7161 allocation.height = child->height = height;
7163 if (gtk_widget_get_realized (widget))
7164 gtk_widget_size_allocate (widget, &allocation);
7168 /* TreeModel Callbacks
7172 pspp_sheet_view_row_changed (GtkTreeModel *model,
7177 PsppSheetView *tree_view = (PsppSheetView *)data;
7179 gboolean free_path = FALSE;
7180 GtkTreePath *cursor_path;
7182 g_return_if_fail (path != NULL || iter != NULL);
7184 if (tree_view->priv->cursor != NULL)
7185 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7189 if (tree_view->priv->edited_column &&
7190 (cursor_path == NULL || gtk_tree_path_compare (cursor_path, path) == 0))
7191 pspp_sheet_view_stop_editing (tree_view, TRUE);
7193 if (cursor_path != NULL)
7194 gtk_tree_path_free (cursor_path);
7198 path = gtk_tree_model_get_path (model, iter);
7201 else if (iter == NULL)
7202 gtk_tree_model_get_iter (model, iter, path);
7204 _pspp_sheet_view_find_node (tree_view,
7210 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7211 pspp_sheet_view_node_queue_redraw (tree_view, node);
7215 gtk_tree_path_free (path);
7219 pspp_sheet_view_row_inserted (GtkTreeModel *model,
7224 PsppSheetView *tree_view = (PsppSheetView *) data;
7227 gint height = tree_view->priv->fixed_height;
7228 gboolean free_path = FALSE;
7229 gboolean node_visible = TRUE;
7231 g_return_if_fail (path != NULL || iter != NULL);
7235 path = gtk_tree_model_get_path (model, iter);
7238 else if (iter == NULL)
7239 gtk_tree_model_get_iter (model, iter, path);
7241 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7243 /* Update all row-references */
7244 gtk_tree_row_reference_inserted (G_OBJECT (data), path);
7245 indices = gtk_tree_path_get_indices (path);
7246 tmpnode = indices[0];
7248 range_tower_insert0 (tree_view->priv->selected, tmpnode, 1);
7252 if (node_visible && node_is_visible (tree_view, tmpnode))
7253 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7255 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (tree_view));
7258 install_presize_handler (tree_view);
7260 gtk_tree_path_free (path);
7264 pspp_sheet_view_row_deleted (GtkTreeModel *model,
7268 PsppSheetView *tree_view = (PsppSheetView *)data;
7271 g_return_if_fail (path != NULL);
7273 gtk_tree_row_reference_deleted (G_OBJECT (data), path);
7275 _pspp_sheet_view_find_node (tree_view, path, &node);
7280 range_tower_delete (tree_view->priv->selected, node, 1);
7282 /* Ensure we don't have a dangling pointer to a dead node */
7283 ensure_unprelighted (tree_view);
7285 /* Cancel editting if we've started */
7286 pspp_sheet_view_stop_editing (tree_view, TRUE);
7288 if (tree_view->priv->destroy_count_func)
7290 gint child_count = 0;
7291 tree_view->priv->destroy_count_func (tree_view, path, child_count, tree_view->priv->destroy_count_data);
7294 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7296 if (! gtk_tree_row_reference_valid (tree_view->priv->top_row))
7298 gtk_tree_row_reference_free (tree_view->priv->top_row);
7299 tree_view->priv->top_row = NULL;
7302 install_scroll_sync_handler (tree_view);
7304 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7307 if (helper_data.changed)
7308 g_signal_emit_by_name (tree_view->priv->selection, "changed");
7313 pspp_sheet_view_rows_reordered (GtkTreeModel *model,
7314 GtkTreePath *parent,
7319 PsppSheetView *tree_view = PSPP_SHEET_VIEW (data);
7322 /* XXX need to adjust selection */
7323 len = gtk_tree_model_iter_n_children (model, iter);
7328 gtk_tree_row_reference_reordered (G_OBJECT (data),
7333 if (gtk_tree_path_get_depth (parent) != 0)
7336 if (tree_view->priv->edited_column)
7337 pspp_sheet_view_stop_editing (tree_view, TRUE);
7339 /* we need to be unprelighted */
7340 ensure_unprelighted (tree_view);
7342 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
7344 pspp_sheet_view_dy_to_top_row (tree_view);
7348 /* Internal tree functions
7353 pspp_sheet_view_get_background_xrange (PsppSheetView *tree_view,
7354 PsppSheetViewColumn *column,
7358 PsppSheetViewColumn *tmp_column = NULL;
7369 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7372 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
7374 list = (rtl ? list->prev : list->next))
7376 tmp_column = list->data;
7378 if (tmp_column == column)
7381 if (tmp_column->visible)
7382 total_width += tmp_column->width;
7385 if (tmp_column != column)
7387 g_warning (G_STRLOC": passed-in column isn't in the tree");
7396 if (column->visible)
7397 *x2 = total_width + column->width;
7399 *x2 = total_width; /* width of 0 */
7403 /* Make sure the node is visible vertically */
7405 pspp_sheet_view_clamp_node_visible (PsppSheetView *tree_view,
7408 gint node_dy, height;
7409 GtkTreePath *path = NULL;
7411 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7414 /* just return if the node is visible, avoiding a costly expose */
7415 node_dy = pspp_sheet_view_node_find_offset (tree_view, node);
7416 height = ROW_HEIGHT (tree_view);
7417 if (node_dy >= gtk_adjustment_get_value (tree_view->priv->vadjustment)
7418 && node_dy + height <= (gtk_adjustment_get_value (tree_view->priv->vadjustment)
7419 + gtk_adjustment_get_page_size (tree_view->priv->vadjustment)))
7422 path = _pspp_sheet_view_find_path (tree_view, node);
7425 /* We process updates because we want to clear old selected items when we scroll.
7426 * if this is removed, we get a "selection streak" at the bottom. */
7427 gdk_window_process_updates (tree_view->priv->bin_window, TRUE);
7428 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL, FALSE, 0.0, 0.0);
7429 gtk_tree_path_free (path);
7434 pspp_sheet_view_clamp_column_visible (PsppSheetView *tree_view,
7435 PsppSheetViewColumn *column,
7436 gboolean focus_to_cell)
7443 x = column->allocation.x;
7444 width = column->allocation.width;
7446 if (width > gtk_adjustment_get_page_size (tree_view->priv->hadjustment))
7448 /* The column is larger than the horizontal page size. If the
7449 * column has cells which can be focussed individually, then we make
7450 * sure the cell which gets focus is fully visible (if even the
7451 * focus cell is bigger than the page size, we make sure the
7452 * left-hand side of the cell is visible).
7454 * If the column does not have those so-called special cells, we
7455 * make sure the left-hand side of the column is visible.
7458 if (focus_to_cell && pspp_sheet_view_has_special_cell (tree_view))
7460 GtkTreePath *cursor_path;
7461 GdkRectangle background_area, cell_area, focus_area;
7463 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7465 pspp_sheet_view_get_cell_area (tree_view,
7466 cursor_path, column, &cell_area);
7467 pspp_sheet_view_get_background_area (tree_view,
7468 cursor_path, column,
7471 gtk_tree_path_free (cursor_path);
7473 _pspp_sheet_view_column_get_focus_area (column,
7479 width = focus_area.width;
7481 if (width < gtk_adjustment_get_page_size (tree_view->priv->hadjustment))
7483 if ((gtk_adjustment_get_value (tree_view->priv->hadjustment) + gtk_adjustment_get_page_size (tree_view->priv->hadjustment)) < (x + width))
7484 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7485 x + width - gtk_adjustment_get_page_size (tree_view->priv->hadjustment));
7486 else if (gtk_adjustment_get_value (tree_view->priv->hadjustment) > x)
7487 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7491 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7493 gtk_adjustment_get_lower (tree_view->priv->hadjustment),
7494 gtk_adjustment_get_upper (tree_view->priv->hadjustment)
7495 - gtk_adjustment_get_page_size (tree_view->priv->hadjustment)));
7499 if ((gtk_adjustment_get_value (tree_view->priv->hadjustment) + gtk_adjustment_get_page_size (tree_view->priv->hadjustment)) < (x + width))
7500 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7501 x + width - gtk_adjustment_get_page_size (tree_view->priv->hadjustment));
7502 else if (gtk_adjustment_get_value (tree_view->priv->hadjustment) > x)
7503 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7508 _pspp_sheet_view_find_path (PsppSheetView *tree_view,
7513 path = gtk_tree_path_new ();
7515 gtk_tree_path_append_index (path, node);
7520 _pspp_sheet_view_find_node (PsppSheetView *tree_view,
7524 gint *indices = gtk_tree_path_get_indices (path);
7525 gint depth = gtk_tree_path_get_depth (path);
7528 if (depth == 0 || indices[0] < 0 || indices[0] >= tree_view->priv->row_count)
7534 pspp_sheet_view_add_move_binding (GtkBindingSet *binding_set,
7537 gboolean add_shifted_binding,
7538 GtkMovementStep step,
7542 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
7547 if (add_shifted_binding)
7548 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
7553 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
7556 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
7561 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
7568 pspp_sheet_view_set_column_drag_info (PsppSheetView *tree_view,
7569 PsppSheetViewColumn *column)
7571 PsppSheetViewColumn *left_column;
7572 PsppSheetViewColumn *cur_column = NULL;
7573 PsppSheetViewColumnReorder *reorder;
7578 /* We want to precalculate the motion list such that we know what column slots
7582 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7584 /* First, identify all possible drop spots */
7586 tmp_list = g_list_last (tree_view->priv->columns);
7588 tmp_list = g_list_first (tree_view->priv->columns);
7592 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
7593 tmp_list = rtl?g_list_previous (tmp_list):g_list_next (tmp_list);
7595 if (cur_column->visible == FALSE)
7598 /* If it's not the column moving and func tells us to skip over the column, we continue. */
7599 if (left_column != column && cur_column != column &&
7600 tree_view->priv->column_drop_func &&
7601 ! tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
7603 left_column = cur_column;
7606 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7607 reorder->left_column = left_column;
7608 left_column = reorder->right_column = cur_column;
7610 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7613 /* Add the last one */
7614 if (tree_view->priv->column_drop_func == NULL ||
7615 ((left_column != column) &&
7616 tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data)))
7618 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7619 reorder->left_column = left_column;
7620 reorder->right_column = NULL;
7621 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7624 /* We quickly check to see if it even makes sense to reorder columns. */
7625 /* If there is nothing that can be moved, then we return */
7627 if (tree_view->priv->column_drag_info == NULL)
7630 /* We know there are always 2 slots possbile, as you can always return column. */
7631 /* If that's all there is, return */
7632 if (tree_view->priv->column_drag_info->next == NULL ||
7633 (tree_view->priv->column_drag_info->next->next == NULL &&
7634 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->data)->right_column == column &&
7635 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->next->data)->left_column == column))
7637 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7638 g_slice_free (PsppSheetViewColumnReorder, tmp_list->data);
7639 g_list_free (tree_view->priv->column_drag_info);
7640 tree_view->priv->column_drag_info = NULL;
7643 /* We fill in the ranges for the columns, now that we've isolated them */
7644 left = - TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7646 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7648 reorder = (PsppSheetViewColumnReorder *) tmp_list->data;
7650 reorder->left_align = left;
7651 if (tmp_list->next != NULL)
7653 g_assert (tmp_list->next->data);
7654 left = reorder->right_align = (reorder->right_column->allocation.x +
7655 reorder->right_column->allocation.width +
7656 ((PsppSheetViewColumnReorder *)tmp_list->next->data)->left_column->allocation.x)/2;
7660 gint width = gdk_window_get_width (tree_view->priv->header_window);
7661 reorder->right_align = width + TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7667 _pspp_sheet_view_column_start_drag (PsppSheetView *tree_view,
7668 PsppSheetViewColumn *column)
7670 GdkEvent *send_event;
7671 GtkAllocation allocation;
7673 GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
7674 GdkDisplay *display = gdk_screen_get_display (screen);
7676 g_return_if_fail (tree_view->priv->column_drag_info == NULL);
7677 g_return_if_fail (tree_view->priv->cur_reorder == NULL);
7678 g_return_if_fail (column->button);
7680 pspp_sheet_view_set_column_drag_info (tree_view, column);
7682 if (tree_view->priv->column_drag_info == NULL)
7685 if (tree_view->priv->drag_window == NULL)
7687 GdkWindowAttr attributes;
7688 guint attributes_mask;
7690 attributes.window_type = GDK_WINDOW_CHILD;
7691 attributes.wclass = GDK_INPUT_OUTPUT;
7692 attributes.x = column->allocation.x;
7694 attributes.width = column->allocation.width;
7695 attributes.height = column->allocation.height;
7696 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
7697 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
7698 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL ;
7700 tree_view->priv->drag_window = gdk_window_new (tree_view->priv->bin_window,
7703 gdk_window_set_user_data (tree_view->priv->drag_window, GTK_WIDGET (tree_view));
7706 gdk_display_pointer_ungrab (display, GDK_CURRENT_TIME);
7707 gdk_display_keyboard_ungrab (display, GDK_CURRENT_TIME);
7709 gtk_grab_remove (column->button);
7711 send_event = gdk_event_new (GDK_LEAVE_NOTIFY);
7712 send_event->crossing.send_event = TRUE;
7713 send_event->crossing.window = g_object_ref (gtk_button_get_event_window (GTK_BUTTON (column->button)));
7714 send_event->crossing.subwindow = NULL;
7715 send_event->crossing.detail = GDK_NOTIFY_ANCESTOR;
7716 send_event->crossing.time = GDK_CURRENT_TIME;
7718 gtk_propagate_event (column->button, send_event);
7719 gdk_event_free (send_event);
7721 send_event = gdk_event_new (GDK_BUTTON_RELEASE);
7722 send_event->button.window = g_object_ref (gdk_screen_get_root_window (screen));
7723 send_event->button.send_event = TRUE;
7724 send_event->button.time = GDK_CURRENT_TIME;
7725 send_event->button.x = -1;
7726 send_event->button.y = -1;
7727 send_event->button.axes = NULL;
7728 send_event->button.state = 0;
7729 send_event->button.button = 1;
7730 send_event->button.device =
7731 gdk_device_manager_get_client_pointer (gdk_display_get_device_manager (display));
7733 send_event->button.x_root = 0;
7734 send_event->button.y_root = 0;
7736 gtk_propagate_event (column->button, send_event);
7737 gdk_event_free (send_event);
7739 /* Kids, don't try this at home */
7740 g_object_ref (column->button);
7741 gtk_container_remove (GTK_CONTAINER (tree_view), column->button);
7742 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7743 gtk_widget_set_parent (column->button, GTK_WIDGET (tree_view));
7744 g_object_unref (column->button);
7746 tree_view->priv->drag_column_x = column->allocation.x;
7747 allocation = column->allocation;
7749 gtk_widget_size_allocate (column->button, &allocation);
7750 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7752 tree_view->priv->drag_column = column;
7753 gdk_window_show (tree_view->priv->drag_window);
7755 gdk_window_get_origin (tree_view->priv->header_window, &x, &y);
7757 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7758 while (gtk_events_pending ())
7759 gtk_main_iteration ();
7761 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG);
7762 gdk_pointer_grab (tree_view->priv->drag_window,
7764 GDK_POINTER_MOTION_MASK|GDK_BUTTON_RELEASE_MASK,
7765 NULL, NULL, GDK_CURRENT_TIME);
7766 gdk_keyboard_grab (tree_view->priv->drag_window,
7772 _pspp_sheet_view_queue_draw_node (PsppSheetView *tree_view,
7774 const GdkRectangle *clip_rect)
7777 GtkAllocation allocation;
7779 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7782 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
7784 rect.width = MAX (tree_view->priv->width, allocation.width);
7786 rect.y = BACKGROUND_FIRST_PIXEL (tree_view, node);
7787 rect.height = ROW_HEIGHT (tree_view);
7791 GdkRectangle new_rect;
7793 gdk_rectangle_intersect (clip_rect, &rect, &new_rect);
7795 gdk_window_invalidate_rect (tree_view->priv->bin_window, &new_rect, TRUE);
7799 gdk_window_invalidate_rect (tree_view->priv->bin_window, &rect, TRUE);
7804 pspp_sheet_view_queue_draw_path (PsppSheetView *tree_view,
7806 const GdkRectangle *clip_rect)
7810 _pspp_sheet_view_find_node (tree_view, path, &node);
7813 _pspp_sheet_view_queue_draw_node (tree_view, node, clip_rect);
7817 pspp_sheet_view_focus_to_cursor (PsppSheetView *tree_view)
7820 GtkTreePath *cursor_path;
7822 if ((tree_view->priv->row_count == 0) ||
7823 (! gtk_widget_get_realized (GTK_WIDGET (tree_view))))
7827 if (tree_view->priv->cursor)
7828 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7830 if (cursor_path == NULL)
7832 /* There's no cursor. Move the cursor to the first selected row, if any
7833 * are selected, otherwise to the first row in the sheetview.
7835 GList *selected_rows;
7836 GtkTreeModel *model;
7837 PsppSheetSelection *selection;
7839 selection = pspp_sheet_view_get_selection (tree_view);
7840 selected_rows = pspp_sheet_selection_get_selected_rows (selection, &model);
7844 /* XXX we could avoid doing O(n) work to get this result */
7845 cursor_path = gtk_tree_path_copy((const GtkTreePath *)(selected_rows->data));
7846 g_list_foreach (selected_rows, (GFunc)gtk_tree_path_free, NULL);
7847 g_list_free (selected_rows);
7851 cursor_path = gtk_tree_path_new_first ();
7852 search_first_focusable_path (tree_view, &cursor_path,
7856 gtk_tree_row_reference_free (tree_view->priv->cursor);
7857 tree_view->priv->cursor = NULL;
7861 if (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7862 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE)
7863 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, FALSE, FALSE, 0);
7865 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE, 0);
7871 /* Now find a column for the cursor. */
7872 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
7874 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
7875 gtk_tree_path_free (cursor_path);
7877 if (tree_view->priv->focus_column == NULL)
7880 for (list = tree_view->priv->columns; list; list = list->next)
7882 if (PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
7884 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
7885 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
7886 pspp_sheet_selection_select_column (tree_view->priv->selection, tree_view->priv->focus_column);
7896 pspp_sheet_view_move_cursor_up_down (PsppSheetView *tree_view,
7898 PsppSheetSelectMode mode)
7900 gint selection_count;
7901 int cursor_node = -1;
7902 int new_cursor_node = -1;
7903 GtkTreePath *cursor_path = NULL;
7904 gboolean grab_focus = TRUE;
7906 if (! gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7910 if (!gtk_tree_row_reference_valid (tree_view->priv->cursor))
7911 /* FIXME: we lost the cursor; should we get the first? */
7914 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7915 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
7917 if (cursor_node < 0)
7918 /* FIXME: we lost the cursor; should we get the first? */
7921 selection_count = pspp_sheet_selection_count_selected_rows (tree_view->priv->selection);
7923 if (selection_count == 0
7924 && tree_view->priv->selection->type != PSPP_SHEET_SELECTION_NONE
7925 && !(mode & PSPP_SHEET_SELECT_MODE_TOGGLE))
7927 /* Don't move the cursor, but just select the current node */
7928 new_cursor_node = cursor_node;
7933 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
7935 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7938 gtk_tree_path_free (cursor_path);
7940 if (new_cursor_node)
7942 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
7944 search_first_focusable_path (tree_view, &cursor_path,
7949 gtk_tree_path_free (cursor_path);
7953 * If the list has only one item and multi-selection is set then select
7954 * the row (if not yet selected).
7956 if ((tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7957 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE) &&
7958 new_cursor_node < 0)
7961 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7963 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
7965 if (new_cursor_node < 0
7966 && !pspp_sheet_view_node_is_selected (tree_view, cursor_node))
7968 new_cursor_node = cursor_node;
7972 new_cursor_node = -1;
7976 if (new_cursor_node >= 0)
7978 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
7979 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, TRUE, mode);
7980 gtk_tree_path_free (cursor_path);
7984 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
7986 if (!(mode & PSPP_SHEET_SELECT_MODE_EXTEND))
7988 if (! gtk_widget_keynav_failed (GTK_WIDGET (tree_view),
7990 GTK_DIR_UP : GTK_DIR_DOWN))
7992 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
7995 gtk_widget_child_focus (toplevel,
7997 GTK_DIR_TAB_BACKWARD :
7998 GTK_DIR_TAB_FORWARD);
8005 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8010 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8012 return new_cursor_node >= 0;
8016 pspp_sheet_view_move_cursor_page_up_down (PsppSheetView *tree_view,
8018 PsppSheetSelectMode mode)
8020 int cursor_node = -1;
8021 GtkTreePath *old_cursor_path = NULL;
8022 GtkTreePath *cursor_path = NULL;
8023 int start_cursor_node = -1;
8026 gint vertical_separator;
8028 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8031 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8032 old_cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8034 /* This is sorta weird. Focus in should give us a cursor */
8037 gtk_widget_style_get (GTK_WIDGET (tree_view), "vertical-separator", &vertical_separator, NULL);
8038 _pspp_sheet_view_find_node (tree_view, old_cursor_path, &cursor_node);
8040 if (cursor_node < 0)
8042 /* FIXME: we lost the cursor. Should we try to get one? */
8043 gtk_tree_path_free (old_cursor_path);
8047 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
8048 window_y = RBTREE_Y_TO_TREE_WINDOW_Y (tree_view, y);
8049 y += tree_view->priv->cursor_offset;
8050 y += count * (int)gtk_adjustment_get_page_increment (tree_view->priv->vadjustment);
8051 y = CLAMP (y, (gint)gtk_adjustment_get_lower (tree_view->priv->vadjustment), (gint)gtk_adjustment_get_upper (tree_view->priv->vadjustment) - vertical_separator);
8053 if (y >= tree_view->priv->height)
8054 y = tree_view->priv->height - 1;
8056 tree_view->priv->cursor_offset =
8057 pspp_sheet_view_find_offset (tree_view, y, &cursor_node);
8059 if (tree_view->priv->cursor_offset > BACKGROUND_HEIGHT (tree_view))
8061 cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
8062 tree_view->priv->cursor_offset -= BACKGROUND_HEIGHT (tree_view);
8065 y -= tree_view->priv->cursor_offset;
8066 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
8068 start_cursor_node = cursor_node;
8070 if (! search_first_focusable_path (tree_view, &cursor_path,
8074 /* It looks like we reached the end of the view without finding
8075 * a focusable row. We will step backwards to find the last
8078 cursor_node = start_cursor_node;
8079 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
8081 search_first_focusable_path (tree_view, &cursor_path,
8090 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
8092 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE, mode);
8095 pspp_sheet_view_scroll_to_point (tree_view, -1, y);
8096 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8097 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8099 if (!gtk_tree_path_compare (old_cursor_path, cursor_path))
8100 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8102 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8105 gtk_tree_path_free (old_cursor_path);
8106 gtk_tree_path_free (cursor_path);
8110 pspp_sheet_view_move_cursor_left_right (PsppSheetView *tree_view,
8112 PsppSheetSelectMode mode)
8114 int cursor_node = -1;
8115 GtkTreePath *cursor_path = NULL;
8116 PsppSheetViewColumn *column;
8119 gboolean found_column = FALSE;
8122 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8124 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8127 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8128 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8132 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8133 if (cursor_node < 0)
8135 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8137 gtk_tree_path_free (cursor_path);
8140 gtk_tree_path_free (cursor_path);
8142 list = rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns);
8143 if (tree_view->priv->focus_column)
8145 for (; list; list = (rtl ? list->prev : list->next))
8147 if (list->data == tree_view->priv->focus_column)
8154 gboolean left, right;
8156 column = list->data;
8157 if (column->visible == FALSE || column->row_head)
8160 pspp_sheet_view_column_cell_set_cell_data (column,
8161 tree_view->priv->model,
8166 right = list->prev ? TRUE : FALSE;
8167 left = list->next ? TRUE : FALSE;
8171 left = list->prev ? TRUE : FALSE;
8172 right = list->next ? TRUE : FALSE;
8175 if (_pspp_sheet_view_column_cell_focus (column, count, left, right))
8177 tree_view->priv->focus_column = column;
8178 found_column = TRUE;
8183 list = rtl ? list->prev : list->next;
8185 list = rtl ? list->next : list->prev;
8190 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8191 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8192 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8196 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8199 pspp_sheet_view_clamp_column_visible (tree_view,
8200 tree_view->priv->focus_column, TRUE);
8204 pspp_sheet_view_move_cursor_line_start_end (PsppSheetView *tree_view,
8206 PsppSheetSelectMode mode)
8208 int cursor_node = -1;
8209 GtkTreePath *cursor_path = NULL;
8210 PsppSheetViewColumn *column;
8211 PsppSheetViewColumn *found_column;
8216 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8218 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8221 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8222 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8226 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8227 if (cursor_node < 0)
8229 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8231 gtk_tree_path_free (cursor_path);
8234 gtk_tree_path_free (cursor_path);
8236 list = rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns);
8237 if (tree_view->priv->focus_column)
8239 for (; list; list = (rtl ? list->prev : list->next))
8241 if (list->data == tree_view->priv->focus_column)
8246 found_column = NULL;
8249 gboolean left, right;
8251 column = list->data;
8252 if (column->visible == FALSE || column->row_head)
8255 pspp_sheet_view_column_cell_set_cell_data (column,
8256 tree_view->priv->model,
8261 right = list->prev ? TRUE : FALSE;
8262 left = list->next ? TRUE : FALSE;
8266 left = list->prev ? TRUE : FALSE;
8267 right = list->next ? TRUE : FALSE;
8270 if (column->tabbable
8271 && _pspp_sheet_view_column_cell_focus (column, count, left, right))
8272 found_column = column;
8276 list = rtl ? list->prev : list->next;
8278 list = rtl ? list->next : list->prev;
8283 tree_view->priv->focus_column = found_column;
8284 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8285 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8286 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8289 pspp_sheet_view_clamp_column_visible (tree_view,
8290 tree_view->priv->focus_column, TRUE);
8294 try_move_cursor_tab (PsppSheetView *tree_view,
8295 gboolean start_at_focus_column,
8298 PsppSheetViewColumn *column;
8300 int cursor_node = -1;
8301 GtkTreePath *cursor_path = NULL;
8305 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8306 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8310 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8311 if (cursor_node < 0)
8313 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8315 gtk_tree_path_free (cursor_path);
8318 gtk_tree_path_free (cursor_path);
8320 rtl = gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL;
8321 if (start_at_focus_column)
8324 ? g_list_last (tree_view->priv->columns)
8325 : g_list_first (tree_view->priv->columns));
8326 if (tree_view->priv->focus_column)
8328 for (; list; list = (rtl ? list->prev : list->next))
8330 if (list->data == tree_view->priv->focus_column)
8337 list = (rtl ^ (count == 1)
8338 ? g_list_first (tree_view->priv->columns)
8339 : g_list_last (tree_view->priv->columns));
8344 gboolean left, right;
8346 column = list->data;
8347 if (column->visible == FALSE || !column->tabbable)
8350 pspp_sheet_view_column_cell_set_cell_data (column,
8351 tree_view->priv->model,
8356 right = list->prev ? TRUE : FALSE;
8357 left = list->next ? TRUE : FALSE;
8361 left = list->prev ? TRUE : FALSE;
8362 right = list->next ? TRUE : FALSE;
8365 if (column->tabbable
8366 && _pspp_sheet_view_column_cell_focus (column, count, left, right))
8368 tree_view->priv->focus_column = column;
8369 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8370 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8371 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8376 list = rtl ? list->prev : list->next;
8378 list = rtl ? list->next : list->prev;
8385 pspp_sheet_view_move_cursor_tab (PsppSheetView *tree_view,
8388 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8391 if (!try_move_cursor_tab (tree_view, TRUE, count))
8393 if (pspp_sheet_view_move_cursor_up_down (tree_view, count, 0)
8394 && !try_move_cursor_tab (tree_view, FALSE, count))
8395 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8398 pspp_sheet_view_clamp_column_visible (tree_view,
8399 tree_view->priv->focus_column, TRUE);
8403 pspp_sheet_view_move_cursor_start_end (PsppSheetView *tree_view,
8405 PsppSheetSelectMode mode)
8409 GtkTreePath *old_path;
8411 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8414 g_return_if_fail (tree_view->priv->row_count > 0);
8416 pspp_sheet_view_get_cursor (tree_view, &old_path, NULL);
8420 /* Now go forward to find the first focusable row. */
8421 path = _pspp_sheet_view_find_path (tree_view, 0);
8422 search_first_focusable_path (tree_view, &path,
8423 TRUE, &cursor_node);
8427 /* Now go backwards to find last focusable row. */
8428 path = _pspp_sheet_view_find_path (tree_view, tree_view->priv->row_count - 1);
8429 search_first_focusable_path (tree_view, &path,
8430 FALSE, &cursor_node);
8436 if (gtk_tree_path_compare (old_path, path))
8438 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, mode);
8439 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8443 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8447 gtk_tree_path_free (old_path);
8448 gtk_tree_path_free (path);
8452 pspp_sheet_view_real_select_all (PsppSheetView *tree_view)
8454 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8457 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8458 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8461 pspp_sheet_selection_select_all (tree_view->priv->selection);
8467 pspp_sheet_view_real_unselect_all (PsppSheetView *tree_view)
8469 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8472 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8473 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8476 pspp_sheet_selection_unselect_all (tree_view->priv->selection);
8482 pspp_sheet_view_real_select_cursor_row (PsppSheetView *tree_view,
8483 gboolean start_editing,
8484 PsppSheetSelectMode mode)
8487 int cursor_node = -1;
8488 GtkTreePath *cursor_path = NULL;
8490 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8493 if (tree_view->priv->cursor)
8494 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8496 if (cursor_path == NULL)
8499 _pspp_sheet_view_find_node (tree_view, cursor_path,
8502 if (cursor_node < 0)
8504 gtk_tree_path_free (cursor_path);
8508 if (!(mode & PSPP_SHEET_SELECT_MODE_EXTEND) && start_editing &&
8509 tree_view->priv->focus_column)
8511 if (pspp_sheet_view_start_editing (tree_view, cursor_path))
8513 gtk_tree_path_free (cursor_path);
8518 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8524 /* We bail out if the original (tree, node) don't exist anymore after
8525 * handling the selection-changed callback. We do return TRUE because
8526 * the key press has been handled at this point.
8528 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8530 if (cursor_node != new_node)
8533 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8535 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8536 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8538 if (!(mode & PSPP_SHEET_SELECT_MODE_EXTEND))
8539 pspp_sheet_view_row_activated (tree_view, cursor_path,
8540 tree_view->priv->focus_column);
8542 gtk_tree_path_free (cursor_path);
8548 pspp_sheet_view_real_toggle_cursor_row (PsppSheetView *tree_view)
8551 int cursor_node = -1;
8552 GtkTreePath *cursor_path = NULL;
8554 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8558 if (tree_view->priv->cursor)
8559 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8561 if (cursor_path == NULL)
8564 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8565 if (cursor_node < 0)
8567 gtk_tree_path_free (cursor_path);
8571 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8574 PSPP_SHEET_SELECT_MODE_TOGGLE,
8577 /* We bail out if the original (tree, node) don't exist anymore after
8578 * handling the selection-changed callback. We do return TRUE because
8579 * the key press has been handled at this point.
8581 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8583 if (cursor_node != new_node)
8586 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8588 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8589 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
8590 gtk_tree_path_free (cursor_path);
8596 pspp_sheet_view_search_entry_flush_timeout (PsppSheetView *tree_view)
8598 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
8599 tree_view->priv->typeselect_flush_timeout = 0;
8604 /* Cut and paste from gtkwindow.c */
8606 send_focus_change (GtkWidget *widget,
8609 GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
8611 fevent->focus_change.type = GDK_FOCUS_CHANGE;
8612 fevent->focus_change.window = g_object_ref (gtk_widget_get_window (widget));
8613 fevent->focus_change.in = in;
8615 gtk_widget_send_focus_change (widget, fevent);
8616 gdk_event_free (fevent);
8620 pspp_sheet_view_ensure_interactive_directory (PsppSheetView *tree_view)
8622 GtkWidget *frame, *vbox, *toplevel;
8625 if (tree_view->priv->search_custom_entry_set)
8628 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
8629 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
8631 if (tree_view->priv->search_window != NULL)
8633 if (gtk_window_get_group (GTK_WINDOW (toplevel)))
8634 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
8635 GTK_WINDOW (tree_view->priv->search_window));
8636 else if (gtk_window_get_group (GTK_WINDOW (tree_view->priv->search_window)))
8637 gtk_window_group_remove_window (gtk_window_get_group (GTK_WINDOW (tree_view->priv->search_window)),
8638 GTK_WINDOW (tree_view->priv->search_window));
8639 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8643 tree_view->priv->search_window = gtk_window_new (GTK_WINDOW_POPUP);
8644 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8646 if (gtk_window_get_group (GTK_WINDOW (toplevel)))
8647 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
8648 GTK_WINDOW (tree_view->priv->search_window));
8650 gtk_window_set_type_hint (GTK_WINDOW (tree_view->priv->search_window),
8651 GDK_WINDOW_TYPE_HINT_UTILITY);
8652 gtk_window_set_modal (GTK_WINDOW (tree_view->priv->search_window), TRUE);
8653 g_signal_connect (tree_view->priv->search_window, "delete-event",
8654 G_CALLBACK (pspp_sheet_view_search_delete_event),
8656 g_signal_connect (tree_view->priv->search_window, "key-press-event",
8657 G_CALLBACK (pspp_sheet_view_search_key_press_event),
8659 g_signal_connect (tree_view->priv->search_window, "button-press-event",
8660 G_CALLBACK (pspp_sheet_view_search_button_press_event),
8662 g_signal_connect (tree_view->priv->search_window, "scroll-event",
8663 G_CALLBACK (pspp_sheet_view_search_scroll_event),
8666 frame = gtk_frame_new (NULL);
8667 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
8668 gtk_widget_show (frame);
8669 gtk_container_add (GTK_CONTAINER (tree_view->priv->search_window), frame);
8671 vbox = gtk_vbox_new (FALSE, 0);
8672 gtk_widget_show (vbox);
8673 gtk_container_add (GTK_CONTAINER (frame), vbox);
8674 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
8677 tree_view->priv->search_entry = gtk_entry_new ();
8678 gtk_widget_show (tree_view->priv->search_entry);
8679 g_signal_connect (tree_view->priv->search_entry, "populate-popup",
8680 G_CALLBACK (pspp_sheet_view_search_disable_popdown),
8682 g_signal_connect (tree_view->priv->search_entry,
8683 "activate", G_CALLBACK (pspp_sheet_view_search_activate),
8687 g_signal_connect (GTK_ENTRY (tree_view->priv->search_entry)->im_context,
8689 G_CALLBACK (pspp_sheet_view_search_preedit_changed),
8693 gtk_container_add (GTK_CONTAINER (vbox),
8694 tree_view->priv->search_entry);
8696 gtk_widget_realize (tree_view->priv->search_entry);
8699 /* Pops up the interactive search entry. If keybinding is TRUE then the user
8700 * started this by typing the start_interactive_search keybinding. Otherwise, it came from
8703 pspp_sheet_view_real_start_interactive_search (PsppSheetView *tree_view,
8704 gboolean keybinding)
8706 /* We only start interactive search if we have focus or the columns
8707 * have focus. If one of our children have focus, we don't want to
8711 gboolean found_focus = FALSE;
8712 GtkWidgetClass *entry_parent_class;
8714 if (!tree_view->priv->enable_search && !keybinding)
8717 if (tree_view->priv->search_custom_entry_set)
8720 if (tree_view->priv->search_window != NULL &&
8721 gtk_widget_get_visible (tree_view->priv->search_window))
8724 for (list = tree_view->priv->columns; list; list = list->next)
8726 PsppSheetViewColumn *column;
8728 column = list->data;
8729 if (! column->visible)
8732 if (column->button && gtk_widget_has_focus (column->button))
8739 if (gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8745 if (tree_view->priv->search_column < 0)
8748 pspp_sheet_view_ensure_interactive_directory (tree_view);
8751 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
8754 tree_view->priv->search_position_func (tree_view, tree_view->priv->search_window, tree_view->priv->search_position_user_data);
8755 gtk_widget_show (tree_view->priv->search_window);
8756 if (tree_view->priv->search_entry_changed_id == 0)
8758 tree_view->priv->search_entry_changed_id =
8759 g_signal_connect (tree_view->priv->search_entry, "changed",
8760 G_CALLBACK (pspp_sheet_view_search_init),
8764 tree_view->priv->typeselect_flush_timeout =
8765 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
8766 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
8769 /* Grab focus will select all the text. We don't want that to happen, so we
8770 * call the parent instance and bypass the selection change. This is probably
8771 * really non-kosher. */
8772 entry_parent_class = g_type_class_peek_parent (GTK_ENTRY_GET_CLASS (tree_view->priv->search_entry));
8773 (entry_parent_class->grab_focus) (tree_view->priv->search_entry);
8775 /* send focus-in event */
8776 send_focus_change (tree_view->priv->search_entry, TRUE);
8778 /* search first matching iter */
8779 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
8785 pspp_sheet_view_start_interactive_search (PsppSheetView *tree_view)
8787 return pspp_sheet_view_real_start_interactive_search (tree_view, TRUE);
8790 /* this function returns the new width of the column being resized given
8791 * the column and x position of the cursor; the x cursor position is passed
8792 * in as a pointer and automagicly corrected if it's beyond min/max limits
8795 pspp_sheet_view_new_column_width (PsppSheetView *tree_view,
8799 PsppSheetViewColumn *column;
8803 /* first translate the x position from gtk_widget_get_window (widget)
8804 * to clist->clist_window
8806 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8807 column = g_list_nth (tree_view->priv->columns, i)->data;
8808 width = rtl ? (column->allocation.x + column->allocation.width - *x) : (*x - column->allocation.x);
8810 /* Clamp down the value */
8811 if (column->min_width == -1)
8812 width = MAX (column->button_request, width);
8814 width = MAX (column->min_width, width);
8815 if (column->max_width != -1)
8816 width = MIN (width, column->max_width);
8818 *x = rtl ? (column->allocation.x + column->allocation.width - width) : (column->allocation.x + width);
8824 /* FIXME this adjust_allocation is a big cut-and-paste from
8825 * GtkCList, needs to be some "official" way to do this
8835 /* The window to which gtk_widget_get_window (widget) is relative */
8836 #define ALLOCATION_WINDOW(widget) \
8837 (!gtk_widget_get_has_window (widget) ? \
8838 gtk_widget_get_window (widget) : \
8839 gdk_window_get_parent (gtk_widget_get_window (widget)))
8842 adjust_allocation_recurse (GtkWidget *widget,
8845 ScrollData *scroll_data = data;
8846 GtkAllocation allocation;
8847 gtk_widget_get_allocation (widget, &allocation);
8848 /* Need to really size allocate instead of just poking
8849 * into widget->allocation if the widget is not realized.
8850 * FIXME someone figure out why this was.
8852 if (!gtk_widget_get_realized (widget))
8854 if (gtk_widget_get_visible (widget))
8856 GdkRectangle tmp_rectangle = allocation;
8857 tmp_rectangle.x += scroll_data->dx;
8858 tmp_rectangle.y += scroll_data->dy;
8860 gtk_widget_size_allocate (widget, &tmp_rectangle);
8865 if (ALLOCATION_WINDOW (widget) == scroll_data->window)
8867 allocation.x += scroll_data->dx;
8868 allocation.y += scroll_data->dy;
8870 if (GTK_IS_CONTAINER (widget))
8871 gtk_container_forall (GTK_CONTAINER (widget),
8872 adjust_allocation_recurse,
8879 adjust_allocation (GtkWidget *widget,
8883 ScrollData scroll_data;
8885 if (gtk_widget_get_realized (widget))
8886 scroll_data.window = ALLOCATION_WINDOW (widget);
8888 scroll_data.window = NULL;
8890 scroll_data.dx = dx;
8891 scroll_data.dy = dy;
8893 adjust_allocation_recurse (widget, &scroll_data);
8897 pspp_sheet_view_column_update_button (PsppSheetViewColumn *tree_column);
8901 pspp_sheet_view_adjustment_changed (GtkAdjustment *adjustment,
8902 PsppSheetView *tree_view)
8904 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
8909 gdk_window_move (tree_view->priv->bin_window,
8910 - gtk_adjustment_get_value (tree_view->priv->hadjustment),
8911 TREE_VIEW_HEADER_HEIGHT (tree_view));
8912 gdk_window_move (tree_view->priv->header_window,
8913 - gtk_adjustment_get_value (tree_view->priv->hadjustment),
8915 dy = tree_view->priv->dy - (int) gtk_adjustment_get_value (tree_view->priv->vadjustment);
8918 update_prelight (tree_view,
8919 tree_view->priv->event_last_x,
8920 tree_view->priv->event_last_y - dy);
8922 if (tree_view->priv->edited_column &&
8923 GTK_IS_WIDGET (tree_view->priv->edited_column->editable_widget))
8927 PsppSheetViewChild *child = NULL;
8929 widget = GTK_WIDGET (tree_view->priv->edited_column->editable_widget);
8930 adjust_allocation (widget, 0, dy);
8932 for (list = tree_view->priv->children; list; list = list->next)
8934 child = (PsppSheetViewChild *)list->data;
8935 if (child->widget == widget)
8943 gdk_window_scroll (tree_view->priv->bin_window, 0, dy);
8945 if (tree_view->priv->dy != (int) gtk_adjustment_get_value (tree_view->priv->vadjustment))
8947 /* update our dy and top_row */
8948 tree_view->priv->dy = (int) gtk_adjustment_get_value (tree_view->priv->vadjustment);
8950 if (!tree_view->priv->in_top_row_to_dy)
8951 pspp_sheet_view_dy_to_top_row (tree_view);
8954 for (list = tree_view->priv->columns; list; list = list->next)
8956 PsppSheetViewColumn *column = list->data;
8957 GtkAllocation *col_allocation = &column->allocation;
8958 GtkAllocation widget_allocation;
8959 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &widget_allocation);
8961 if (span_intersects (col_allocation->x, col_allocation->width,
8962 gtk_adjustment_get_value (tree_view->priv->hadjustment),
8963 widget_allocation.width))
8965 pspp_sheet_view_column_set_need_button (column, TRUE);
8966 if (!column->button)
8967 pspp_sheet_view_column_update_button (column);
8979 * pspp_sheet_view_new:
8981 * Creates a new #PsppSheetView widget.
8983 * Return value: A newly created #PsppSheetView widget.
8986 pspp_sheet_view_new (void)
8988 return g_object_new (PSPP_TYPE_SHEET_VIEW, NULL);
8992 * pspp_sheet_view_new_with_model:
8993 * @model: the model.
8995 * Creates a new #PsppSheetView widget with the model initialized to @model.
8997 * Return value: A newly created #PsppSheetView widget.
9000 pspp_sheet_view_new_with_model (GtkTreeModel *model)
9002 return g_object_new (PSPP_TYPE_SHEET_VIEW, "model", model, NULL);
9009 * pspp_sheet_view_get_model:
9010 * @tree_view: a #PsppSheetView
9012 * Returns the model the #PsppSheetView is based on. Returns %NULL if the
9015 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
9018 pspp_sheet_view_get_model (PsppSheetView *tree_view)
9020 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9022 return tree_view->priv->model;
9026 * pspp_sheet_view_set_model:
9027 * @tree_view: A #GtkTreeNode.
9028 * @model: (allow-none): The model.
9030 * Sets the model for a #PsppSheetView. If the @tree_view already has a model
9031 * set, it will remove it before setting the new model. If @model is %NULL,
9032 * then it will unset the old model.
9035 pspp_sheet_view_set_model (PsppSheetView *tree_view,
9036 GtkTreeModel *model)
9038 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9039 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
9041 if (model == tree_view->priv->model)
9044 if (tree_view->priv->scroll_to_path)
9046 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9047 tree_view->priv->scroll_to_path = NULL;
9050 if (tree_view->priv->model)
9052 GList *tmplist = tree_view->priv->columns;
9054 if (tree_view->priv->selected)
9055 range_tower_set0 (tree_view->priv->selected, 0, ULONG_MAX);
9056 pspp_sheet_view_stop_editing (tree_view, TRUE);
9058 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9059 pspp_sheet_view_row_changed,
9061 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9062 pspp_sheet_view_row_inserted,
9064 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9065 pspp_sheet_view_row_deleted,
9067 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9068 pspp_sheet_view_rows_reordered,
9071 for (; tmplist; tmplist = tmplist->next)
9072 _pspp_sheet_view_column_unset_model (tmplist->data,
9073 tree_view->priv->model);
9075 tree_view->priv->prelight_node = -1;
9077 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
9078 tree_view->priv->drag_dest_row = NULL;
9079 gtk_tree_row_reference_free (tree_view->priv->cursor);
9080 tree_view->priv->cursor = NULL;
9081 gtk_tree_row_reference_free (tree_view->priv->anchor);
9082 tree_view->priv->anchor = NULL;
9083 gtk_tree_row_reference_free (tree_view->priv->top_row);
9084 tree_view->priv->top_row = NULL;
9085 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9086 tree_view->priv->scroll_to_path = NULL;
9088 tree_view->priv->scroll_to_column = NULL;
9090 g_object_unref (tree_view->priv->model);
9092 tree_view->priv->search_column = -1;
9093 tree_view->priv->fixed_height = -1;
9094 tree_view->priv->dy = tree_view->priv->top_row_dy = 0;
9095 tree_view->priv->last_button_x = -1;
9096 tree_view->priv->last_button_y = -1;
9099 tree_view->priv->model = model;
9101 if (tree_view->priv->model)
9105 if (tree_view->priv->search_column == -1)
9107 for (i = 0; i < gtk_tree_model_get_n_columns (model); i++)
9109 GType type = gtk_tree_model_get_column_type (model, i);
9111 if (g_value_type_transformable (type, G_TYPE_STRING))
9113 tree_view->priv->search_column = i;
9119 g_object_ref (tree_view->priv->model);
9120 g_signal_connect (tree_view->priv->model,
9122 G_CALLBACK (pspp_sheet_view_row_changed),
9124 g_signal_connect (tree_view->priv->model,
9126 G_CALLBACK (pspp_sheet_view_row_inserted),
9128 g_signal_connect (tree_view->priv->model,
9130 G_CALLBACK (pspp_sheet_view_row_deleted),
9132 g_signal_connect (tree_view->priv->model,
9134 G_CALLBACK (pspp_sheet_view_rows_reordered),
9137 tree_view->priv->row_count = gtk_tree_model_iter_n_children (tree_view->priv->model, NULL);
9139 /* FIXME: do I need to do this? pspp_sheet_view_create_buttons (tree_view); */
9140 install_presize_handler (tree_view);
9143 g_object_notify (G_OBJECT (tree_view), "model");
9145 if (tree_view->priv->selection)
9146 _pspp_sheet_selection_emit_changed (tree_view->priv->selection);
9148 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9149 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9153 * pspp_sheet_view_get_selection:
9154 * @tree_view: A #PsppSheetView.
9156 * Gets the #PsppSheetSelection associated with @tree_view.
9158 * Return value: A #PsppSheetSelection object.
9160 PsppSheetSelection *
9161 pspp_sheet_view_get_selection (PsppSheetView *tree_view)
9163 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9165 return tree_view->priv->selection;
9169 * pspp_sheet_view_get_hadjustment:
9170 * @tree_view: A #PsppSheetView
9172 * Gets the #GtkAdjustment currently being used for the horizontal aspect.
9174 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
9178 pspp_sheet_view_get_hadjustment (PsppSheetView *tree_view)
9180 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9182 if (tree_view->priv->hadjustment == NULL)
9183 pspp_sheet_view_set_hadjustment (tree_view, NULL);
9185 return tree_view->priv->hadjustment;
9189 * pspp_sheet_view_set_hadjustment:
9190 * @tree_view: A #PsppSheetView
9191 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
9193 * Sets the #GtkAdjustment for the current horizontal aspect.
9196 pspp_sheet_view_set_hadjustment (PsppSheetView *tree_view,
9197 GtkAdjustment *adjustment)
9199 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9201 pspp_sheet_view_set_adjustments (tree_view,
9203 tree_view->priv->vadjustment);
9205 g_object_notify (G_OBJECT (tree_view), "hadjustment");
9209 * pspp_sheet_view_get_vadjustment:
9210 * @tree_view: A #PsppSheetView
9212 * Gets the #GtkAdjustment currently being used for the vertical aspect.
9214 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
9218 pspp_sheet_view_get_vadjustment (PsppSheetView *tree_view)
9220 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9222 if (tree_view->priv->vadjustment == NULL)
9223 pspp_sheet_view_set_vadjustment (tree_view, NULL);
9225 return tree_view->priv->vadjustment;
9229 * pspp_sheet_view_set_vadjustment:
9230 * @tree_view: A #PsppSheetView
9231 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
9233 * Sets the #GtkAdjustment for the current vertical aspect.
9236 pspp_sheet_view_set_vadjustment (PsppSheetView *tree_view,
9237 GtkAdjustment *adjustment)
9239 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9241 pspp_sheet_view_set_adjustments (tree_view,
9242 tree_view->priv->hadjustment,
9245 g_object_notify (G_OBJECT (tree_view), "vadjustment");
9248 /* Column and header operations */
9251 * pspp_sheet_view_get_headers_visible:
9252 * @tree_view: A #PsppSheetView.
9254 * Returns %TRUE if the headers on the @tree_view are visible.
9256 * Return value: Whether the headers are visible or not.
9259 pspp_sheet_view_get_headers_visible (PsppSheetView *tree_view)
9261 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9263 return PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9267 * pspp_sheet_view_set_headers_visible:
9268 * @tree_view: A #PsppSheetView.
9269 * @headers_visible: %TRUE if the headers are visible
9271 * Sets the visibility state of the headers.
9274 pspp_sheet_view_set_headers_visible (PsppSheetView *tree_view,
9275 gboolean headers_visible)
9279 PsppSheetViewColumn *column;
9280 GtkAllocation allocation;
9282 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9284 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
9286 headers_visible = !! headers_visible;
9288 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE) == headers_visible)
9291 if (headers_visible)
9292 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9294 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9296 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9298 gdk_window_get_position (tree_view->priv->bin_window, &x, &y);
9299 if (headers_visible)
9301 gdk_window_move_resize (tree_view->priv->bin_window, x, y + TREE_VIEW_HEADER_HEIGHT (tree_view),
9302 tree_view->priv->width, allocation.height - + TREE_VIEW_HEADER_HEIGHT (tree_view));
9304 if (gtk_widget_get_mapped (GTK_WIDGET (tree_view)))
9305 pspp_sheet_view_map_buttons (tree_view);
9309 gdk_window_move_resize (tree_view->priv->bin_window, x, y, tree_view->priv->width, tree_view->priv->height);
9311 for (list = tree_view->priv->columns; list; list = list->next)
9313 column = list->data;
9315 gtk_widget_unmap (column->button);
9317 gdk_window_hide (tree_view->priv->header_window);
9321 gtk_adjustment_set_page_size (tree_view->priv->vadjustment, allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view));
9322 gtk_adjustment_set_page_increment (tree_view->priv->vadjustment, (allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view)) / 2);
9323 gtk_adjustment_set_lower (tree_view->priv->vadjustment, 0);
9324 gtk_adjustment_set_upper (tree_view->priv->vadjustment, tree_view->priv->height);
9325 gtk_adjustment_changed (tree_view->priv->vadjustment);
9327 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9329 g_object_notify (G_OBJECT (tree_view), "headers-visible");
9333 * pspp_sheet_view_columns_autosize:
9334 * @tree_view: A #PsppSheetView.
9336 * Resizes all columns to their optimal width. Only works after the
9337 * treeview has been realized.
9340 pspp_sheet_view_columns_autosize (PsppSheetView *tree_view)
9342 gboolean dirty = FALSE;
9344 PsppSheetViewColumn *column;
9346 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9348 for (list = tree_view->priv->columns; list; list = list->next)
9350 column = list->data;
9351 _pspp_sheet_view_column_cell_set_dirty (column);
9356 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9360 * pspp_sheet_view_set_headers_clickable:
9361 * @tree_view: A #PsppSheetView.
9362 * @setting: %TRUE if the columns are clickable.
9364 * Allow the column title buttons to be clicked.
9367 pspp_sheet_view_set_headers_clickable (PsppSheetView *tree_view,
9372 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9374 for (list = tree_view->priv->columns; list; list = list->next)
9375 pspp_sheet_view_column_set_clickable (PSPP_SHEET_VIEW_COLUMN (list->data), setting);
9377 g_object_notify (G_OBJECT (tree_view), "headers-clickable");
9382 * pspp_sheet_view_get_headers_clickable:
9383 * @tree_view: A #PsppSheetView.
9385 * Returns whether all header columns are clickable.
9387 * Return value: %TRUE if all header columns are clickable, otherwise %FALSE
9392 pspp_sheet_view_get_headers_clickable (PsppSheetView *tree_view)
9396 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9398 for (list = tree_view->priv->columns; list; list = list->next)
9399 if (!PSPP_SHEET_VIEW_COLUMN (list->data)->clickable)
9406 * pspp_sheet_view_set_rules_hint
9407 * @tree_view: a #PsppSheetView
9408 * @setting: %TRUE if the tree requires reading across rows
9410 * This function tells GTK+ that the user interface for your
9411 * application requires users to read across tree rows and associate
9412 * cells with one another. By default, GTK+ will then render the tree
9413 * with alternating row colors. Do <emphasis>not</emphasis> use it
9414 * just because you prefer the appearance of the ruled tree; that's a
9415 * question for the theme. Some themes will draw tree rows in
9416 * alternating colors even when rules are turned off, and users who
9417 * prefer that appearance all the time can choose those themes. You
9418 * should call this function only as a <emphasis>semantic</emphasis>
9419 * hint to the theme engine that your tree makes alternating colors
9420 * useful from a functional standpoint (since it has lots of columns,
9425 pspp_sheet_view_set_rules_hint (PsppSheetView *tree_view,
9428 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9430 setting = setting != FALSE;
9432 if (tree_view->priv->has_rules != setting)
9434 tree_view->priv->has_rules = setting;
9435 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
9438 g_object_notify (G_OBJECT (tree_view), "rules-hint");
9442 * pspp_sheet_view_get_rules_hint
9443 * @tree_view: a #PsppSheetView
9445 * Gets the setting set by pspp_sheet_view_set_rules_hint().
9447 * Return value: %TRUE if rules are useful for the user of this tree
9450 pspp_sheet_view_get_rules_hint (PsppSheetView *tree_view)
9452 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9454 return tree_view->priv->has_rules;
9457 /* Public Column functions
9461 * pspp_sheet_view_append_column:
9462 * @tree_view: A #PsppSheetView.
9463 * @column: The #PsppSheetViewColumn to add.
9465 * Appends @column to the list of columns.
9467 * Return value: The number of columns in @tree_view after appending.
9470 pspp_sheet_view_append_column (PsppSheetView *tree_view,
9471 PsppSheetViewColumn *column)
9473 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9474 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9475 g_return_val_if_fail (column->tree_view == NULL, -1);
9477 return pspp_sheet_view_insert_column (tree_view, column, -1);
9482 * pspp_sheet_view_remove_column:
9483 * @tree_view: A #PsppSheetView.
9484 * @column: The #PsppSheetViewColumn to remove.
9486 * Removes @column from @tree_view.
9488 * Return value: The number of columns in @tree_view after removing.
9491 pspp_sheet_view_remove_column (PsppSheetView *tree_view,
9492 PsppSheetViewColumn *column)
9494 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9495 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9496 g_return_val_if_fail (column->tree_view == GTK_WIDGET (tree_view), -1);
9498 if (tree_view->priv->focus_column == column)
9499 tree_view->priv->focus_column = NULL;
9501 if (tree_view->priv->edited_column == column)
9503 pspp_sheet_view_stop_editing (tree_view, TRUE);
9505 /* no need to, but just to be sure ... */
9506 tree_view->priv->edited_column = NULL;
9509 _pspp_sheet_view_column_unset_tree_view (column);
9511 tree_view->priv->columns = g_list_remove (tree_view->priv->columns, column);
9512 tree_view->priv->n_columns--;
9514 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9518 _pspp_sheet_view_column_unrealize_button (column);
9519 for (list = tree_view->priv->columns; list; list = list->next)
9521 PsppSheetViewColumn *tmp_column;
9523 tmp_column = PSPP_SHEET_VIEW_COLUMN (list->data);
9524 if (tmp_column->visible)
9525 _pspp_sheet_view_column_cell_set_dirty (tmp_column);
9528 if (tree_view->priv->n_columns == 0 &&
9529 pspp_sheet_view_get_headers_visible (tree_view) &&
9530 tree_view->priv->header_window)
9531 gdk_window_hide (tree_view->priv->header_window);
9533 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9536 g_object_unref (column);
9537 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9539 return tree_view->priv->n_columns;
9543 * pspp_sheet_view_insert_column:
9544 * @tree_view: A #PsppSheetView.
9545 * @column: The #PsppSheetViewColumn to be inserted.
9546 * @position: The position to insert @column in.
9548 * This inserts the @column into the @tree_view at @position. If @position is
9549 * -1, then the column is inserted at the end.
9551 * Return value: The number of columns in @tree_view after insertion.
9554 pspp_sheet_view_insert_column (PsppSheetView *tree_view,
9555 PsppSheetViewColumn *column,
9558 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9559 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9560 g_return_val_if_fail (column->tree_view == NULL, -1);
9562 g_object_ref_sink (column);
9564 if (tree_view->priv->n_columns == 0 &&
9565 gtk_widget_get_realized (GTK_WIDGET (tree_view)) &&
9566 pspp_sheet_view_get_headers_visible (tree_view))
9568 gdk_window_show (tree_view->priv->header_window);
9571 tree_view->priv->columns = g_list_insert (tree_view->priv->columns,
9573 tree_view->priv->n_columns++;
9575 _pspp_sheet_view_column_set_tree_view (column, tree_view);
9577 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9581 _pspp_sheet_view_column_realize_button (column);
9583 for (list = tree_view->priv->columns; list; list = list->next)
9585 column = PSPP_SHEET_VIEW_COLUMN (list->data);
9586 if (column->visible)
9587 _pspp_sheet_view_column_cell_set_dirty (column);
9589 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9592 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9594 return tree_view->priv->n_columns;
9598 * pspp_sheet_view_insert_column_with_attributes:
9599 * @tree_view: A #PsppSheetView
9600 * @position: The position to insert the new column in.
9601 * @title: The title to set the header to.
9602 * @cell: The #GtkCellRenderer.
9603 * @Varargs: A %NULL-terminated list of attributes.
9605 * Creates a new #PsppSheetViewColumn and inserts it into the @tree_view at
9606 * @position. If @position is -1, then the newly created column is inserted at
9607 * the end. The column is initialized with the attributes given.
9609 * Return value: The number of columns in @tree_view after insertion.
9612 pspp_sheet_view_insert_column_with_attributes (PsppSheetView *tree_view,
9615 GtkCellRenderer *cell,
9618 PsppSheetViewColumn *column;
9623 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9625 column = pspp_sheet_view_column_new ();
9626 pspp_sheet_view_column_set_title (column, title);
9627 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9629 va_start (args, cell);
9631 attribute = va_arg (args, gchar *);
9633 while (attribute != NULL)
9635 column_id = va_arg (args, gint);
9636 pspp_sheet_view_column_add_attribute (column, cell, attribute, column_id);
9637 attribute = va_arg (args, gchar *);
9642 pspp_sheet_view_insert_column (tree_view, column, position);
9644 return tree_view->priv->n_columns;
9648 * pspp_sheet_view_insert_column_with_data_func:
9649 * @tree_view: a #PsppSheetView
9650 * @position: Position to insert, -1 for append
9651 * @title: column title
9652 * @cell: cell renderer for column
9653 * @func: function to set attributes of cell renderer
9654 * @data: data for @func
9655 * @dnotify: destroy notifier for @data
9657 * Convenience function that inserts a new column into the #PsppSheetView
9658 * with the given cell renderer and a #GtkCellDataFunc to set cell renderer
9659 * attributes (normally using data from the model). See also
9660 * pspp_sheet_view_column_set_cell_data_func(), pspp_sheet_view_column_pack_start().
9662 * Return value: number of columns in the tree view post-insert
9665 pspp_sheet_view_insert_column_with_data_func (PsppSheetView *tree_view,
9668 GtkCellRenderer *cell,
9669 PsppSheetCellDataFunc func,
9671 GDestroyNotify dnotify)
9673 PsppSheetViewColumn *column;
9675 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9677 column = pspp_sheet_view_column_new ();
9678 pspp_sheet_view_column_set_title (column, title);
9679 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9680 pspp_sheet_view_column_set_cell_data_func (column, cell, func, data, dnotify);
9682 pspp_sheet_view_insert_column (tree_view, column, position);
9684 return tree_view->priv->n_columns;
9688 * pspp_sheet_view_get_column:
9689 * @tree_view: A #PsppSheetView.
9690 * @n: The position of the column, counting from 0.
9692 * Gets the #PsppSheetViewColumn at the given position in the #tree_view.
9694 * Return value: The #PsppSheetViewColumn, or %NULL if the position is outside the
9697 PsppSheetViewColumn *
9698 pspp_sheet_view_get_column (PsppSheetView *tree_view,
9701 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9703 if (n < 0 || n >= tree_view->priv->n_columns)
9706 if (tree_view->priv->columns == NULL)
9709 return PSPP_SHEET_VIEW_COLUMN (g_list_nth (tree_view->priv->columns, n)->data);
9713 * pspp_sheet_view_get_columns:
9714 * @tree_view: A #PsppSheetView
9716 * Returns a #GList of all the #PsppSheetViewColumn s currently in @tree_view.
9717 * The returned list must be freed with g_list_free ().
9719 * Return value: (element-type PsppSheetViewColumn) (transfer container): A list of #PsppSheetViewColumn s
9722 pspp_sheet_view_get_columns (PsppSheetView *tree_view)
9724 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9726 return g_list_copy (tree_view->priv->columns);
9730 * pspp_sheet_view_move_column_after:
9731 * @tree_view: A #PsppSheetView
9732 * @column: The #PsppSheetViewColumn to be moved.
9733 * @base_column: (allow-none): The #PsppSheetViewColumn to be moved relative to, or %NULL.
9735 * Moves @column to be after to @base_column. If @base_column is %NULL, then
9736 * @column is placed in the first position.
9739 pspp_sheet_view_move_column_after (PsppSheetView *tree_view,
9740 PsppSheetViewColumn *column,
9741 PsppSheetViewColumn *base_column)
9743 GList *column_list_el, *base_el = NULL;
9745 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9747 column_list_el = g_list_find (tree_view->priv->columns, column);
9748 g_return_if_fail (column_list_el != NULL);
9752 base_el = g_list_find (tree_view->priv->columns, base_column);
9753 g_return_if_fail (base_el != NULL);
9756 if (column_list_el->prev == base_el)
9759 tree_view->priv->columns = g_list_remove_link (tree_view->priv->columns, column_list_el);
9760 if (base_el == NULL)
9762 column_list_el->prev = NULL;
9763 column_list_el->next = tree_view->priv->columns;
9764 if (column_list_el->next)
9765 column_list_el->next->prev = column_list_el;
9766 tree_view->priv->columns = column_list_el;
9770 column_list_el->prev = base_el;
9771 column_list_el->next = base_el->next;
9772 if (column_list_el->next)
9773 column_list_el->next->prev = column_list_el;
9774 base_el->next = column_list_el;
9777 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9779 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9780 pspp_sheet_view_size_allocate_columns (GTK_WIDGET (tree_view), NULL);
9783 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9787 * pspp_sheet_view_set_column_drag_function:
9788 * @tree_view: A #PsppSheetView.
9789 * @func: (allow-none): A function to determine which columns are reorderable, or %NULL.
9790 * @user_data: (allow-none): User data to be passed to @func, or %NULL
9791 * @destroy: (allow-none): Destroy notifier for @user_data, or %NULL
9793 * Sets a user function for determining where a column may be dropped when
9794 * dragged. This function is called on every column pair in turn at the
9795 * beginning of a column drag to determine where a drop can take place. The
9796 * arguments passed to @func are: the @tree_view, the #PsppSheetViewColumn being
9797 * dragged, the two #PsppSheetViewColumn s determining the drop spot, and
9798 * @user_data. If either of the #PsppSheetViewColumn arguments for the drop spot
9799 * are %NULL, then they indicate an edge. If @func is set to be %NULL, then
9800 * @tree_view reverts to the default behavior of allowing all columns to be
9801 * dropped everywhere.
9804 pspp_sheet_view_set_column_drag_function (PsppSheetView *tree_view,
9805 PsppSheetViewColumnDropFunc func,
9807 GDestroyNotify destroy)
9809 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9811 if (tree_view->priv->column_drop_func_data_destroy)
9812 tree_view->priv->column_drop_func_data_destroy (tree_view->priv->column_drop_func_data);
9814 tree_view->priv->column_drop_func = func;
9815 tree_view->priv->column_drop_func_data = user_data;
9816 tree_view->priv->column_drop_func_data_destroy = destroy;
9820 * pspp_sheet_view_scroll_to_point:
9821 * @tree_view: a #PsppSheetView
9822 * @tree_x: X coordinate of new top-left pixel of visible area, or -1
9823 * @tree_y: Y coordinate of new top-left pixel of visible area, or -1
9825 * Scrolls the tree view such that the top-left corner of the visible
9826 * area is @tree_x, @tree_y, where @tree_x and @tree_y are specified
9827 * in tree coordinates. The @tree_view must be realized before
9828 * this function is called. If it isn't, you probably want to be
9829 * using pspp_sheet_view_scroll_to_cell().
9831 * If either @tree_x or @tree_y are -1, then that direction isn't scrolled.
9834 pspp_sheet_view_scroll_to_point (PsppSheetView *tree_view,
9838 GtkAdjustment *hadj;
9839 GtkAdjustment *vadj;
9841 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9842 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
9844 hadj = tree_view->priv->hadjustment;
9845 vadj = tree_view->priv->vadjustment;
9848 gtk_adjustment_set_value (hadj, CLAMP (tree_x, gtk_adjustment_get_lower (hadj), gtk_adjustment_get_upper (hadj) - gtk_adjustment_get_page_size (hadj)));
9850 gtk_adjustment_set_value (vadj, CLAMP (tree_y, gtk_adjustment_get_lower (vadj), gtk_adjustment_get_upper (vadj) - gtk_adjustment_get_page_size (vadj)));
9854 * pspp_sheet_view_scroll_to_cell:
9855 * @tree_view: A #PsppSheetView.
9856 * @path: (allow-none): The path of the row to move to, or %NULL.
9857 * @column: (allow-none): The #PsppSheetViewColumn to move horizontally to, or %NULL.
9858 * @use_align: whether to use alignment arguments, or %FALSE.
9859 * @row_align: The vertical alignment of the row specified by @path.
9860 * @col_align: The horizontal alignment of the column specified by @column.
9862 * Moves the alignments of @tree_view to the position specified by @column and
9863 * @path. If @column is %NULL, then no horizontal scrolling occurs. Likewise,
9864 * if @path is %NULL no vertical scrolling occurs. At a minimum, one of @column
9865 * or @path need to be non-%NULL. @row_align determines where the row is
9866 * placed, and @col_align determines where @column is placed. Both are expected
9867 * to be between 0.0 and 1.0. 0.0 means left/top alignment, 1.0 means
9868 * right/bottom alignment, 0.5 means center.
9870 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
9871 * tree does the minimum amount of work to scroll the cell onto the screen.
9872 * This means that the cell will be scrolled to the edge closest to its current
9873 * position. If the cell is currently visible on the screen, nothing is done.
9875 * This function only works if the model is set, and @path is a valid row on the
9876 * model. If the model changes before the @tree_view is realized, the centered
9877 * path will be modified to reflect this change.
9880 pspp_sheet_view_scroll_to_cell (PsppSheetView *tree_view,
9882 PsppSheetViewColumn *column,
9887 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9888 g_return_if_fail (tree_view->priv->model != NULL);
9889 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
9890 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
9891 g_return_if_fail (path != NULL || column != NULL);
9894 g_print ("pspp_sheet_view_scroll_to_cell:\npath: %s\ncolumn: %s\nuse_align: %d\nrow_align: %f\ncol_align: %f\n",
9895 gtk_tree_path_to_string (path), column?"non-null":"null", use_align, row_align, col_align);
9897 row_align = CLAMP (row_align, 0.0, 1.0);
9898 col_align = CLAMP (col_align, 0.0, 1.0);
9901 /* Note: Despite the benefits that come from having one code path for the
9902 * scrolling code, we short-circuit validate_visible_area's immplementation as
9903 * it is much slower than just going to the point.
9905 if (!gtk_widget_get_visible (GTK_WIDGET (tree_view)) ||
9906 !gtk_widget_get_realized (GTK_WIDGET (tree_view))
9907 /* XXX || GTK_WIDGET_ALLOC_NEEDED (tree_view) */)
9909 if (tree_view->priv->scroll_to_path)
9910 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9912 tree_view->priv->scroll_to_path = NULL;
9913 tree_view->priv->scroll_to_column = NULL;
9916 tree_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
9918 tree_view->priv->scroll_to_column = column;
9919 tree_view->priv->scroll_to_use_align = use_align;
9920 tree_view->priv->scroll_to_row_align = row_align;
9921 tree_view->priv->scroll_to_col_align = col_align;
9923 install_presize_handler (tree_view);
9927 GdkRectangle cell_rect;
9928 GdkRectangle vis_rect;
9929 gint dest_x, dest_y;
9931 pspp_sheet_view_get_background_area (tree_view, path, column, &cell_rect);
9932 pspp_sheet_view_get_visible_rect (tree_view, &vis_rect);
9934 cell_rect.y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, cell_rect.y);
9936 dest_x = vis_rect.x;
9937 dest_y = vis_rect.y;
9943 dest_x = cell_rect.x - ((vis_rect.width - cell_rect.width) * col_align);
9947 if (cell_rect.x < vis_rect.x)
9948 dest_x = cell_rect.x;
9949 if (cell_rect.x + cell_rect.width > vis_rect.x + vis_rect.width)
9950 dest_x = cell_rect.x + cell_rect.width - vis_rect.width;
9958 dest_y = cell_rect.y - ((vis_rect.height - cell_rect.height) * row_align);
9959 dest_y = MAX (dest_y, 0);
9963 if (cell_rect.y < vis_rect.y)
9964 dest_y = cell_rect.y;
9965 if (cell_rect.y + cell_rect.height > vis_rect.y + vis_rect.height)
9966 dest_y = cell_rect.y + cell_rect.height - vis_rect.height;
9970 pspp_sheet_view_scroll_to_point (tree_view, dest_x, dest_y);
9975 * pspp_sheet_view_row_activated:
9976 * @tree_view: A #PsppSheetView
9977 * @path: The #GtkTreePath to be activated.
9978 * @column: The #PsppSheetViewColumn to be activated.
9980 * Activates the cell determined by @path and @column.
9983 pspp_sheet_view_row_activated (PsppSheetView *tree_view,
9985 PsppSheetViewColumn *column)
9987 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9989 g_signal_emit (tree_view, tree_view_signals[ROW_ACTIVATED], 0, path, column);
9994 * pspp_sheet_view_get_reorderable:
9995 * @tree_view: a #PsppSheetView
9997 * Retrieves whether the user can reorder the tree via drag-and-drop. See
9998 * pspp_sheet_view_set_reorderable().
10000 * Return value: %TRUE if the tree can be reordered.
10003 pspp_sheet_view_get_reorderable (PsppSheetView *tree_view)
10005 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
10007 return tree_view->priv->reorderable;
10011 * pspp_sheet_view_set_reorderable:
10012 * @tree_view: A #PsppSheetView.
10013 * @reorderable: %TRUE, if the tree can be reordered.
10015 * This function is a convenience function to allow you to reorder
10016 * models that support the #GtkDragSourceIface and the
10017 * #GtkDragDestIface. Both #GtkTreeStore and #GtkListStore support
10018 * these. If @reorderable is %TRUE, then the user can reorder the
10019 * model by dragging and dropping rows. The developer can listen to
10020 * these changes by connecting to the model's row_inserted and
10021 * row_deleted signals. The reordering is implemented by setting up
10022 * the tree view as a drag source and destination. Therefore, drag and
10023 * drop can not be used in a reorderable view for any other purpose.
10025 * This function does not give you any degree of control over the order -- any
10026 * reordering is allowed. If more control is needed, you should probably
10027 * handle drag and drop manually.
10030 pspp_sheet_view_set_reorderable (PsppSheetView *tree_view,
10031 gboolean reorderable)
10033 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10035 reorderable = reorderable != FALSE;
10037 if (tree_view->priv->reorderable == reorderable)
10042 const GtkTargetEntry row_targets[] = {
10043 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
10046 pspp_sheet_view_enable_model_drag_source (tree_view,
10049 G_N_ELEMENTS (row_targets),
10051 pspp_sheet_view_enable_model_drag_dest (tree_view,
10053 G_N_ELEMENTS (row_targets),
10058 pspp_sheet_view_unset_rows_drag_source (tree_view);
10059 pspp_sheet_view_unset_rows_drag_dest (tree_view);
10062 tree_view->priv->reorderable = reorderable;
10064 g_object_notify (G_OBJECT (tree_view), "reorderable");
10067 /* If CLEAR_AND_SELECT is true, then the row will be selected and, unless Shift
10068 is pressed, other rows will be unselected.
10070 If CLAMP_NODE is true, then the sheetview will scroll to make the row
10073 pspp_sheet_view_real_set_cursor (PsppSheetView *tree_view,
10075 gboolean clear_and_select,
10076 gboolean clamp_node,
10077 PsppSheetSelectMode mode)
10081 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
10083 GtkTreePath *cursor_path;
10084 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
10085 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
10086 gtk_tree_path_free (cursor_path);
10089 gtk_tree_row_reference_free (tree_view->priv->cursor);
10090 tree_view->priv->cursor = NULL;
10092 _pspp_sheet_view_find_node (tree_view, path, &node);
10093 tree_view->priv->cursor =
10094 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
10095 tree_view->priv->model,
10098 if (tree_view->priv->row_count > 0)
10102 if (clear_and_select && !(mode & PSPP_SHEET_SELECT_MODE_TOGGLE))
10103 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
10107 /* We have to re-find tree and node here again, somebody might have
10108 * cleared the node or the whole tree in the PsppSheetSelection::changed
10109 * callback. If the nodes differ we bail out here.
10111 _pspp_sheet_view_find_node (tree_view, path, &new_node);
10113 if (node != new_node)
10118 pspp_sheet_view_clamp_node_visible (tree_view, node);
10119 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
10123 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
10127 * pspp_sheet_view_get_cursor:
10128 * @tree_view: A #PsppSheetView
10129 * @path: (allow-none): A pointer to be filled with the current cursor path, or %NULL
10130 * @focus_column: (allow-none): A pointer to be filled with the current focus column, or %NULL
10132 * Fills in @path and @focus_column with the current path and focus column. If
10133 * the cursor isn't currently set, then *@path will be %NULL. If no column
10134 * currently has focus, then *@focus_column will be %NULL.
10136 * The returned #GtkTreePath must be freed with gtk_tree_path_free() when
10137 * you are done with it.
10140 pspp_sheet_view_get_cursor (PsppSheetView *tree_view,
10141 GtkTreePath **path,
10142 PsppSheetViewColumn **focus_column)
10144 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10148 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
10149 *path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
10156 *focus_column = tree_view->priv->focus_column;
10161 * pspp_sheet_view_set_cursor:
10162 * @tree_view: A #PsppSheetView
10163 * @path: A #GtkTreePath
10164 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
10165 * @start_editing: %TRUE if the specified cell should start being edited.
10167 * Sets the current keyboard focus to be at @path, and selects it. This is
10168 * useful when you want to focus the user's attention on a particular row. If
10169 * @focus_column is not %NULL, then focus is given to the column specified by
10170 * it. Additionally, if @focus_column is specified, and @start_editing is
10171 * %TRUE, then editing should be started in the specified cell.
10172 * This function is often followed by @gtk_widget_grab_focus (@tree_view)
10173 * in order to give keyboard focus to the widget. Please note that editing
10174 * can only happen when the widget is realized.
10176 * If @path is invalid for @model, the current cursor (if any) will be unset
10177 * and the function will return without failing.
10180 pspp_sheet_view_set_cursor (PsppSheetView *tree_view,
10182 PsppSheetViewColumn *focus_column,
10183 gboolean start_editing)
10185 pspp_sheet_view_set_cursor_on_cell (tree_view, path, focus_column,
10186 NULL, start_editing);
10190 * pspp_sheet_view_set_cursor_on_cell:
10191 * @tree_view: A #PsppSheetView
10192 * @path: A #GtkTreePath
10193 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
10194 * @focus_cell: (allow-none): A #GtkCellRenderer, or %NULL
10195 * @start_editing: %TRUE if the specified cell should start being edited.
10197 * Sets the current keyboard focus to be at @path, and selects it. This is
10198 * useful when you want to focus the user's attention on a particular row. If
10199 * @focus_column is not %NULL, then focus is given to the column specified by
10200 * it. If @focus_column and @focus_cell are not %NULL, and @focus_column
10201 * contains 2 or more editable or activatable cells, then focus is given to
10202 * the cell specified by @focus_cell. Additionally, if @focus_column is
10203 * specified, and @start_editing is %TRUE, then editing should be started in
10204 * the specified cell. This function is often followed by
10205 * @gtk_widget_grab_focus (@tree_view) in order to give keyboard focus to the
10206 * widget. Please note that editing can only happen when the widget is
10209 * If @path is invalid for @model, the current cursor (if any) will be unset
10210 * and the function will return without failing.
10215 pspp_sheet_view_set_cursor_on_cell (PsppSheetView *tree_view,
10217 PsppSheetViewColumn *focus_column,
10218 GtkCellRenderer *focus_cell,
10219 gboolean start_editing)
10221 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10222 g_return_if_fail (path != NULL);
10223 g_return_if_fail (focus_column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (focus_column));
10225 if (!tree_view->priv->model)
10230 g_return_if_fail (focus_column);
10231 g_return_if_fail (GTK_IS_CELL_RENDERER (focus_cell));
10234 /* cancel the current editing, if it exists */
10235 if (tree_view->priv->edited_column &&
10236 tree_view->priv->edited_column->editable_widget)
10237 pspp_sheet_view_stop_editing (tree_view, TRUE);
10239 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, 0);
10241 if (focus_column && focus_column->visible)
10244 gboolean column_in_tree = FALSE;
10246 for (list = tree_view->priv->columns; list; list = list->next)
10247 if (list->data == focus_column)
10249 column_in_tree = TRUE;
10252 g_return_if_fail (column_in_tree);
10253 tree_view->priv->focus_column = focus_column;
10255 pspp_sheet_view_column_focus_cell (focus_column, focus_cell);
10257 pspp_sheet_view_start_editing (tree_view, path);
10259 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
10260 pspp_sheet_selection_select_column (tree_view->priv->selection, focus_column);
10266 * pspp_sheet_view_get_bin_window:
10267 * @tree_view: A #PsppSheetView
10269 * Returns the window that @tree_view renders to. This is used primarily to
10270 * compare to <literal>event->window</literal> to confirm that the event on
10271 * @tree_view is on the right window.
10273 * Return value: A #GdkWindow, or %NULL when @tree_view hasn't been realized yet
10276 pspp_sheet_view_get_bin_window (PsppSheetView *tree_view)
10278 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
10280 return tree_view->priv->bin_window;
10284 * pspp_sheet_view_get_path_at_pos:
10285 * @tree_view: A #PsppSheetView.
10286 * @x: The x position to be identified (relative to bin_window).
10287 * @y: The y position to be identified (relative to bin_window).
10288 * @path: (out) (allow-none): A pointer to a #GtkTreePath pointer to be filled in, or %NULL
10289 * @column: (out) (allow-none): A pointer to a #PsppSheetViewColumn pointer to be filled in, or %NULL
10290 * @cell_x: (out) (allow-none): A pointer where the X coordinate relative to the cell can be placed, or %NULL
10291 * @cell_y: (out) (allow-none): A pointer where the Y coordinate relative to the cell can be placed, or %NULL
10293 * Finds the path at the point (@x, @y), relative to bin_window coordinates
10294 * (please see pspp_sheet_view_get_bin_window()).
10295 * That is, @x and @y are relative to an events coordinates. @x and @y must
10296 * come from an event on the @tree_view only where <literal>event->window ==
10297 * pspp_sheet_view_get_bin_window (<!-- -->)</literal>. It is primarily for
10298 * things like popup menus. If @path is non-%NULL, then it will be filled
10299 * with the #GtkTreePath at that point. This path should be freed with
10300 * gtk_tree_path_free(). If @column is non-%NULL, then it will be filled
10301 * with the column at that point. @cell_x and @cell_y return the coordinates
10302 * relative to the cell background (i.e. the @background_area passed to
10303 * gtk_cell_renderer_render()). This function is only meaningful if
10304 * @tree_view is realized. Therefore this function will always return %FALSE
10305 * if @tree_view is not realized or does not have a model.
10307 * For converting widget coordinates (eg. the ones you get from
10308 * GtkWidget::query-tooltip), please see
10309 * pspp_sheet_view_convert_widget_to_bin_window_coords().
10311 * Return value: %TRUE if a row exists at that coordinate.
10314 pspp_sheet_view_get_path_at_pos (PsppSheetView *tree_view,
10317 GtkTreePath **path,
10318 PsppSheetViewColumn **column,
10325 g_return_val_if_fail (tree_view != NULL, FALSE);
10332 if (tree_view->priv->bin_window == NULL)
10335 if (tree_view->priv->row_count == 0)
10338 if (x > gtk_adjustment_get_upper (tree_view->priv->hadjustment))
10341 if (x < 0 || y < 0)
10344 if (column || cell_x)
10346 PsppSheetViewColumn *tmp_column;
10347 PsppSheetViewColumn *last_column = NULL;
10349 gint remaining_x = x;
10350 gboolean found = FALSE;
10353 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
10354 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
10356 list = (rtl ? list->prev : list->next))
10358 tmp_column = list->data;
10360 if (tmp_column->visible == FALSE)
10363 last_column = tmp_column;
10364 if (remaining_x <= tmp_column->width)
10369 *column = tmp_column;
10372 *cell_x = remaining_x;
10376 remaining_x -= tmp_column->width;
10379 /* If found is FALSE and there is a last_column, then it the remainder
10380 * space is in that area
10387 *column = last_column;
10390 *cell_x = last_column->width + remaining_x;
10399 y_offset = pspp_sheet_view_find_offset (tree_view,
10400 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, y),
10407 *cell_y = y_offset;
10410 *path = _pspp_sheet_view_find_path (tree_view, node);
10415 /* Computes 'cell_area' from 'background_area', which must be the background
10416 area for a cell. Set 'subtract_focus_rect' to TRUE to compute the cell area
10417 as passed to a GtkCellRenderer's "render" function, or to FALSE to compute
10418 the cell area as passed to _pspp_sheet_view_column_cell_render().
10420 'column' is required to properly adjust 'cell_area->x' and
10421 'cell_area->width'. It may be set to NULL if these values are not of
10422 interest. In this case 'cell_area->x' and 'cell_area->width' will be
10425 pspp_sheet_view_adjust_cell_area (PsppSheetView *tree_view,
10426 PsppSheetViewColumn *column,
10427 const GdkRectangle *background_area,
10428 gboolean subtract_focus_rect,
10429 GdkRectangle *cell_area)
10431 gint vertical_separator;
10432 gint horizontal_separator;
10434 *cell_area = *background_area;
10436 gtk_widget_style_get (GTK_WIDGET (tree_view),
10437 "vertical-separator", &vertical_separator,
10438 "horizontal-separator", &horizontal_separator,
10440 cell_area->x += horizontal_separator / 2;
10441 cell_area->y += vertical_separator / 2;
10442 cell_area->width -= horizontal_separator;
10443 cell_area->height -= vertical_separator;
10445 if (subtract_focus_rect)
10447 int focus_line_width;
10449 gtk_widget_style_get (GTK_WIDGET (tree_view),
10450 "focus-line-width", &focus_line_width,
10452 cell_area->x += focus_line_width;
10453 cell_area->y += focus_line_width;
10454 cell_area->width -= 2 * focus_line_width;
10455 cell_area->height -= 2 * focus_line_width;
10458 if (tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_NONE)
10460 gint grid_line_width;
10461 gtk_widget_style_get (GTK_WIDGET (tree_view),
10462 "grid-line-width", &grid_line_width,
10465 if ((tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
10466 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10469 PsppSheetViewColumn *first_column, *last_column;
10472 /* Find the last visible column. */
10473 last_column = NULL;
10474 for (list = g_list_last (tree_view->priv->columns);
10478 PsppSheetViewColumn *c = list->data;
10486 /* Find the first visible column. */
10487 first_column = NULL;
10488 for (list = g_list_first (tree_view->priv->columns);
10492 PsppSheetViewColumn *c = list->data;
10500 if (column == first_column)
10502 cell_area->width -= grid_line_width / 2;
10504 else if (column == last_column)
10506 cell_area->x += grid_line_width / 2;
10507 cell_area->width -= grid_line_width / 2;
10511 cell_area->x += grid_line_width / 2;
10512 cell_area->width -= grid_line_width;
10516 if (tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
10517 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10519 cell_area->y += grid_line_width / 2;
10520 cell_area->height -= grid_line_width;
10524 if (column == NULL)
10527 cell_area->width = 0;
10532 * pspp_sheet_view_get_cell_area:
10533 * @tree_view: a #PsppSheetView
10534 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10535 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordinates
10536 * @rect: rectangle to fill with cell rect
10538 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10539 * row specified by @path and the column specified by @column. If @path is
10540 * %NULL, or points to a path not currently displayed, the @y and @height fields
10541 * of the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10542 * fields will be filled with 0. The sum of all cell rects does not cover the
10543 * entire tree; there are extra pixels in between rows, for example. The
10544 * returned rectangle is equivalent to the @cell_area passed to
10545 * gtk_cell_renderer_render(). This function is only valid if @tree_view is
10549 pspp_sheet_view_get_cell_area (PsppSheetView *tree_view,
10551 PsppSheetViewColumn *column,
10552 GdkRectangle *rect)
10554 GdkRectangle background_area;
10556 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10557 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10558 g_return_if_fail (rect != NULL);
10559 g_return_if_fail (!column || column->tree_view == (GtkWidget *) tree_view);
10560 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
10562 pspp_sheet_view_get_background_area (tree_view, path, column,
10564 pspp_sheet_view_adjust_cell_area (tree_view, column, &background_area,
10569 * pspp_sheet_view_get_background_area:
10570 * @tree_view: a #PsppSheetView
10571 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10572 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordiantes
10573 * @rect: rectangle to fill with cell background rect
10575 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10576 * row specified by @path and the column specified by @column. If @path is
10577 * %NULL, or points to a node not found in the tree, the @y and @height fields of
10578 * the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10579 * fields will be filled with 0. The returned rectangle is equivalent to the
10580 * @background_area passed to gtk_cell_renderer_render(). These background
10581 * areas tile to cover the entire bin window. Contrast with the @cell_area,
10582 * returned by pspp_sheet_view_get_cell_area(), which returns only the cell
10583 * itself, excluding surrounding borders.
10587 pspp_sheet_view_get_background_area (PsppSheetView *tree_view,
10589 PsppSheetViewColumn *column,
10590 GdkRectangle *rect)
10594 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10595 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10596 g_return_if_fail (rect != NULL);
10605 /* Get vertical coords */
10607 _pspp_sheet_view_find_node (tree_view, path, &node);
10611 rect->y = BACKGROUND_FIRST_PIXEL (tree_view, node);
10613 rect->height = ROW_HEIGHT (tree_view);
10620 pspp_sheet_view_get_background_xrange (tree_view, column, &rect->x, &x2);
10621 rect->width = x2 - rect->x;
10626 * pspp_sheet_view_get_visible_rect:
10627 * @tree_view: a #PsppSheetView
10628 * @visible_rect: rectangle to fill
10630 * Fills @visible_rect with the currently-visible region of the
10631 * buffer, in tree coordinates. Convert to bin_window coordinates with
10632 * pspp_sheet_view_convert_tree_to_bin_window_coords().
10633 * Tree coordinates start at 0,0 for row 0 of the tree, and cover the entire
10634 * scrollable area of the tree.
10637 pspp_sheet_view_get_visible_rect (PsppSheetView *tree_view,
10638 GdkRectangle *visible_rect)
10642 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10644 widget = GTK_WIDGET (tree_view);
10648 GtkAllocation allocation;
10649 gtk_widget_get_allocation (widget, &allocation);
10650 visible_rect->x = gtk_adjustment_get_value (tree_view->priv->hadjustment);
10651 visible_rect->y = gtk_adjustment_get_value (tree_view->priv->vadjustment);
10652 visible_rect->width = allocation.width;
10653 visible_rect->height = allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
10658 * pspp_sheet_view_widget_to_tree_coords:
10659 * @tree_view: a #PsppSheetView
10660 * @wx: X coordinate relative to bin_window
10661 * @wy: Y coordinate relative to bin_window
10662 * @tx: return location for tree X coordinate
10663 * @ty: return location for tree Y coordinate
10665 * Converts bin_window coordinates to coordinates for the
10666 * tree (the full scrollable area of the tree).
10668 * Deprecated: 2.12: Due to historial reasons the name of this function is
10669 * incorrect. For converting coordinates relative to the widget to
10670 * bin_window coordinates, please see
10671 * pspp_sheet_view_convert_widget_to_bin_window_coords().
10675 pspp_sheet_view_widget_to_tree_coords (PsppSheetView *tree_view,
10681 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10684 *tx = wx + gtk_adjustment_get_value (tree_view->priv->hadjustment);
10686 *ty = wy + tree_view->priv->dy;
10690 * pspp_sheet_view_tree_to_widget_coords:
10691 * @tree_view: a #PsppSheetView
10692 * @tx: tree X coordinate
10693 * @ty: tree Y coordinate
10694 * @wx: return location for X coordinate relative to bin_window
10695 * @wy: return location for Y coordinate relative to bin_window
10697 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10698 * to bin_window coordinates.
10700 * Deprecated: 2.12: Due to historial reasons the name of this function is
10701 * incorrect. For converting bin_window coordinates to coordinates relative
10702 * to bin_window, please see
10703 * pspp_sheet_view_convert_bin_window_to_widget_coords().
10707 pspp_sheet_view_tree_to_widget_coords (PsppSheetView *tree_view,
10713 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10716 *wx = tx - gtk_adjustment_get_value (tree_view->priv->hadjustment);
10718 *wy = ty - tree_view->priv->dy;
10723 * pspp_sheet_view_convert_widget_to_tree_coords:
10724 * @tree_view: a #PsppSheetView
10725 * @wx: X coordinate relative to the widget
10726 * @wy: Y coordinate relative to the widget
10727 * @tx: return location for tree X coordinate
10728 * @ty: return location for tree Y coordinate
10730 * Converts widget coordinates to coordinates for the
10731 * tree (the full scrollable area of the tree).
10736 pspp_sheet_view_convert_widget_to_tree_coords (PsppSheetView *tree_view,
10744 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10746 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view,
10749 pspp_sheet_view_convert_bin_window_to_tree_coords (tree_view,
10755 * pspp_sheet_view_convert_tree_to_widget_coords:
10756 * @tree_view: a #PsppSheetView
10757 * @tx: X coordinate relative to the tree
10758 * @ty: Y coordinate relative to the tree
10759 * @wx: return location for widget X coordinate
10760 * @wy: return location for widget Y coordinate
10762 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10763 * to widget coordinates.
10768 pspp_sheet_view_convert_tree_to_widget_coords (PsppSheetView *tree_view,
10776 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10778 pspp_sheet_view_convert_tree_to_bin_window_coords (tree_view,
10781 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
10787 * pspp_sheet_view_convert_widget_to_bin_window_coords:
10788 * @tree_view: a #PsppSheetView
10789 * @wx: X coordinate relative to the widget
10790 * @wy: Y coordinate relative to the widget
10791 * @bx: return location for bin_window X coordinate
10792 * @by: return location for bin_window Y coordinate
10794 * Converts widget coordinates to coordinates for the bin_window
10795 * (see pspp_sheet_view_get_bin_window()).
10800 pspp_sheet_view_convert_widget_to_bin_window_coords (PsppSheetView *tree_view,
10806 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10809 *bx = wx + gtk_adjustment_get_value (tree_view->priv->hadjustment);
10811 *by = wy - TREE_VIEW_HEADER_HEIGHT (tree_view);
10815 * pspp_sheet_view_convert_bin_window_to_widget_coords:
10816 * @tree_view: a #PsppSheetView
10817 * @bx: bin_window X coordinate
10818 * @by: bin_window Y coordinate
10819 * @wx: return location for widget X coordinate
10820 * @wy: return location for widget Y coordinate
10822 * Converts bin_window coordinates (see pspp_sheet_view_get_bin_window())
10823 * to widget relative coordinates.
10828 pspp_sheet_view_convert_bin_window_to_widget_coords (PsppSheetView *tree_view,
10834 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10837 *wx = bx - gtk_adjustment_get_value (tree_view->priv->hadjustment);
10839 *wy = by + TREE_VIEW_HEADER_HEIGHT (tree_view);
10843 * pspp_sheet_view_convert_tree_to_bin_window_coords:
10844 * @tree_view: a #PsppSheetView
10845 * @tx: tree X coordinate
10846 * @ty: tree Y coordinate
10847 * @bx: return location for X coordinate relative to bin_window
10848 * @by: return location for Y coordinate relative to bin_window
10850 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10851 * to bin_window coordinates.
10856 pspp_sheet_view_convert_tree_to_bin_window_coords (PsppSheetView *tree_view,
10862 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10867 *by = ty - tree_view->priv->dy;
10871 * pspp_sheet_view_convert_bin_window_to_tree_coords:
10872 * @tree_view: a #PsppSheetView
10873 * @bx: X coordinate relative to bin_window
10874 * @by: Y coordinate relative to bin_window
10875 * @tx: return location for tree X coordinate
10876 * @ty: return location for tree Y coordinate
10878 * Converts bin_window coordinates to coordinates for the
10879 * tree (the full scrollable area of the tree).
10884 pspp_sheet_view_convert_bin_window_to_tree_coords (PsppSheetView *tree_view,
10890 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10895 *ty = by + tree_view->priv->dy;
10901 * pspp_sheet_view_get_visible_range:
10902 * @tree_view: A #PsppSheetView
10903 * @start_path: (allow-none): Return location for start of region, or %NULL.
10904 * @end_path: (allow-none): Return location for end of region, or %NULL.
10906 * Sets @start_path and @end_path to be the first and last visible path.
10907 * Note that there may be invisible paths in between.
10909 * The paths should be freed with gtk_tree_path_free() after use.
10911 * Returns: %TRUE, if valid paths were placed in @start_path and @end_path.
10916 pspp_sheet_view_get_visible_range (PsppSheetView *tree_view,
10917 GtkTreePath **start_path,
10918 GtkTreePath **end_path)
10923 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
10925 if (!tree_view->priv->row_count)
10932 pspp_sheet_view_find_offset (tree_view,
10933 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, 0),
10936 *start_path = _pspp_sheet_view_find_path (tree_view, node);
10945 if (tree_view->priv->height < gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
10946 y = tree_view->priv->height - 1;
10948 y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, gtk_adjustment_get_page_size (tree_view->priv->vadjustment)) - 1;
10950 pspp_sheet_view_find_offset (tree_view, y, &node);
10952 *end_path = _pspp_sheet_view_find_path (tree_view, node);
10961 unset_reorderable (PsppSheetView *tree_view)
10963 if (tree_view->priv->reorderable)
10965 tree_view->priv->reorderable = FALSE;
10966 g_object_notify (G_OBJECT (tree_view), "reorderable");
10971 * pspp_sheet_view_enable_model_drag_source:
10972 * @tree_view: a #PsppSheetView
10973 * @start_button_mask: Mask of allowed buttons to start drag
10974 * @targets: the table of targets that the drag will support
10975 * @n_targets: the number of items in @targets
10976 * @actions: the bitmask of possible actions for a drag from this
10979 * Turns @tree_view into a drag source for automatic DND. Calling this
10980 * method sets #PsppSheetView:reorderable to %FALSE.
10983 pspp_sheet_view_enable_model_drag_source (PsppSheetView *tree_view,
10984 GdkModifierType start_button_mask,
10985 const GtkTargetEntry *targets,
10987 GdkDragAction actions)
10989 TreeViewDragInfo *di;
10991 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10993 gtk_drag_source_set (GTK_WIDGET (tree_view),
10999 di = ensure_info (tree_view);
11001 di->start_button_mask = start_button_mask;
11002 di->source_actions = actions;
11003 di->source_set = TRUE;
11005 unset_reorderable (tree_view);
11009 * pspp_sheet_view_enable_model_drag_dest:
11010 * @tree_view: a #PsppSheetView
11011 * @targets: the table of targets that the drag will support
11012 * @n_targets: the number of items in @targets
11013 * @actions: the bitmask of possible actions for a drag from this
11016 * Turns @tree_view into a drop destination for automatic DND. Calling
11017 * this method sets #PsppSheetView:reorderable to %FALSE.
11020 pspp_sheet_view_enable_model_drag_dest (PsppSheetView *tree_view,
11021 const GtkTargetEntry *targets,
11023 GdkDragAction actions)
11025 TreeViewDragInfo *di;
11027 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11029 gtk_drag_dest_set (GTK_WIDGET (tree_view),
11035 di = ensure_info (tree_view);
11036 di->dest_set = TRUE;
11038 unset_reorderable (tree_view);
11042 * pspp_sheet_view_unset_rows_drag_source:
11043 * @tree_view: a #PsppSheetView
11045 * Undoes the effect of
11046 * pspp_sheet_view_enable_model_drag_source(). Calling this method sets
11047 * #PsppSheetView:reorderable to %FALSE.
11050 pspp_sheet_view_unset_rows_drag_source (PsppSheetView *tree_view)
11052 TreeViewDragInfo *di;
11054 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11056 di = get_info (tree_view);
11060 if (di->source_set)
11062 gtk_drag_source_unset (GTK_WIDGET (tree_view));
11063 di->source_set = FALSE;
11066 if (!di->dest_set && !di->source_set)
11067 remove_info (tree_view);
11070 unset_reorderable (tree_view);
11074 * pspp_sheet_view_unset_rows_drag_dest:
11075 * @tree_view: a #PsppSheetView
11077 * Undoes the effect of
11078 * pspp_sheet_view_enable_model_drag_dest(). Calling this method sets
11079 * #PsppSheetView:reorderable to %FALSE.
11082 pspp_sheet_view_unset_rows_drag_dest (PsppSheetView *tree_view)
11084 TreeViewDragInfo *di;
11086 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11088 di = get_info (tree_view);
11094 gtk_drag_dest_unset (GTK_WIDGET (tree_view));
11095 di->dest_set = FALSE;
11098 if (!di->dest_set && !di->source_set)
11099 remove_info (tree_view);
11102 unset_reorderable (tree_view);
11106 * pspp_sheet_view_set_drag_dest_row:
11107 * @tree_view: a #PsppSheetView
11108 * @path: (allow-none): The path of the row to highlight, or %NULL.
11109 * @pos: Specifies whether to drop before, after or into the row
11111 * Sets the row that is highlighted for feedback.
11114 pspp_sheet_view_set_drag_dest_row (PsppSheetView *tree_view,
11116 PsppSheetViewDropPosition pos)
11118 GtkTreePath *current_dest;
11120 /* Note; this function is exported to allow a custom DND
11121 * implementation, so it can't touch TreeViewDragInfo
11124 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11126 current_dest = NULL;
11128 if (tree_view->priv->drag_dest_row)
11130 current_dest = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
11131 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
11134 /* special case a drop on an empty model */
11135 tree_view->priv->empty_view_drop = 0;
11137 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE && path
11138 && gtk_tree_path_get_depth (path) == 1
11139 && gtk_tree_path_get_indices (path)[0] == 0)
11143 n_children = gtk_tree_model_iter_n_children (tree_view->priv->model,
11147 tree_view->priv->empty_view_drop = 1;
11150 tree_view->priv->drag_dest_pos = pos;
11154 tree_view->priv->drag_dest_row =
11155 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
11156 pspp_sheet_view_queue_draw_path (tree_view, path, NULL);
11159 tree_view->priv->drag_dest_row = NULL;
11163 int node, new_node;
11165 _pspp_sheet_view_find_node (tree_view, current_dest, &node);
11166 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
11170 new_node = pspp_sheet_view_node_next (tree_view, node);
11172 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
11174 new_node = pspp_sheet_view_node_prev (tree_view, node);
11176 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
11178 gtk_tree_path_free (current_dest);
11183 * pspp_sheet_view_get_drag_dest_row:
11184 * @tree_view: a #PsppSheetView
11185 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
11186 * @pos: (allow-none): Return location for the drop position, or %NULL
11188 * Gets information about the row that is highlighted for feedback.
11191 pspp_sheet_view_get_drag_dest_row (PsppSheetView *tree_view,
11192 GtkTreePath **path,
11193 PsppSheetViewDropPosition *pos)
11195 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11199 if (tree_view->priv->drag_dest_row)
11200 *path = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
11203 if (tree_view->priv->empty_view_drop)
11204 *path = gtk_tree_path_new_from_indices (0, -1);
11211 *pos = tree_view->priv->drag_dest_pos;
11215 * pspp_sheet_view_get_dest_row_at_pos:
11216 * @tree_view: a #PsppSheetView
11217 * @drag_x: the position to determine the destination row for
11218 * @drag_y: the position to determine the destination row for
11219 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
11220 * @pos: (allow-none): Return location for the drop position, or %NULL
11222 * Determines the destination row for a given position. @drag_x and
11223 * @drag_y are expected to be in widget coordinates. This function is only
11224 * meaningful if @tree_view is realized. Therefore this function will always
11225 * return %FALSE if @tree_view is not realized or does not have a model.
11227 * Return value: whether there is a row at the given position, %TRUE if this
11228 * is indeed the case.
11231 pspp_sheet_view_get_dest_row_at_pos (PsppSheetView *tree_view,
11234 GtkTreePath **path,
11235 PsppSheetViewDropPosition *pos)
11239 gdouble offset_into_row;
11242 PsppSheetViewColumn *column = NULL;
11243 GtkTreePath *tmp_path = NULL;
11245 /* Note; this function is exported to allow a custom DND
11246 * implementation, so it can't touch TreeViewDragInfo
11249 g_return_val_if_fail (tree_view != NULL, FALSE);
11250 g_return_val_if_fail (drag_x >= 0, FALSE);
11251 g_return_val_if_fail (drag_y >= 0, FALSE);
11256 if (tree_view->priv->bin_window == NULL)
11259 if (tree_view->priv->row_count == 0)
11262 /* If in the top third of a row, we drop before that row; if
11263 * in the bottom third, drop after that row; if in the middle,
11264 * and the row has children, drop into the row.
11266 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, drag_x, drag_y,
11269 if (!pspp_sheet_view_get_path_at_pos (tree_view,
11278 pspp_sheet_view_get_background_area (tree_view, tmp_path, column,
11281 offset_into_row = cell_y;
11286 gtk_tree_path_free (tmp_path);
11290 third = cell.height / 3.0;
11294 if (offset_into_row < third)
11296 *pos = PSPP_SHEET_VIEW_DROP_BEFORE;
11298 else if (offset_into_row < (cell.height / 2.0))
11300 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE;
11302 else if (offset_into_row < third * 2.0)
11304 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER;
11308 *pos = PSPP_SHEET_VIEW_DROP_AFTER;
11316 #if GTK3_TRANSITION
11317 /* KEEP IN SYNC WITH PSPP_SHEET_VIEW_BIN_EXPOSE */
11319 * pspp_sheet_view_create_row_drag_icon:
11320 * @tree_view: a #PsppSheetView
11321 * @path: a #GtkTreePath in @tree_view
11323 * Creates a #GdkPixmap representation of the row at @path.
11324 * This image is used for a drag icon.
11326 * Return value: a newly-allocated pixmap of the drag icon.
11329 pspp_sheet_view_create_row_drag_icon (PsppSheetView *tree_view,
11336 GdkRectangle background_area;
11337 GdkRectangle expose_area;
11339 /* start drawing inside the black outline */
11341 GdkDrawable *drawable;
11342 gint bin_window_width;
11345 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11346 g_return_val_if_fail (path != NULL, NULL);
11348 widget = GTK_WIDGET (tree_view);
11350 if (!gtk_widget_get_realized (widget))
11353 _pspp_sheet_view_find_node (tree_view,
11360 if (!gtk_tree_model_get_iter (tree_view->priv->model,
11367 background_area.y = y;
11368 background_area.height = ROW_HEIGHT (tree_view);
11370 bin_window_width = gdk_window_get_width (tree_view->priv->bin_window);
11372 drawable = gdk_pixmap_new (tree_view->priv->bin_window,
11373 bin_window_width + 2,
11374 background_area.height + 2,
11379 expose_area.width = bin_window_width + 2;
11380 expose_area.height = background_area.height + 2;
11382 #if GTK3_TRANSITION
11383 gdk_draw_rectangle (drawable,
11384 widget->style->base_gc [gtk_widget_get_state (widget)],
11387 bin_window_width + 2,
11388 background_area.height + 2);
11391 rtl = gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL;
11393 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
11395 list = (rtl ? list->prev : list->next))
11397 PsppSheetViewColumn *column = list->data;
11398 GdkRectangle cell_area;
11399 gint vertical_separator;
11401 if (!column->visible)
11404 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, &iter);
11406 background_area.x = cell_offset;
11407 background_area.width = column->width;
11409 gtk_widget_style_get (widget,
11410 "vertical-separator", &vertical_separator,
11413 cell_area = background_area;
11415 cell_area.y += vertical_separator / 2;
11416 cell_area.height -= vertical_separator;
11418 if (pspp_sheet_view_column_cell_is_visible (column))
11419 _pspp_sheet_view_column_cell_render (column,
11425 cell_offset += column->width;
11428 #if GTK3_TRANSITION
11429 gdk_draw_rectangle (drawable,
11430 widget->style->black_gc,
11433 bin_window_width + 1,
11434 background_area.height + 1);
11442 * pspp_sheet_view_set_destroy_count_func:
11443 * @tree_view: A #PsppSheetView
11444 * @func: (allow-none): Function to be called when a view row is destroyed, or %NULL
11445 * @data: (allow-none): User data to be passed to @func, or %NULL
11446 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11448 * This function should almost never be used. It is meant for private use by
11449 * ATK for determining the number of visible children that are removed when a row is deleted.
11452 pspp_sheet_view_set_destroy_count_func (PsppSheetView *tree_view,
11453 PsppSheetDestroyCountFunc func,
11455 GDestroyNotify destroy)
11457 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11459 if (tree_view->priv->destroy_count_destroy)
11460 tree_view->priv->destroy_count_destroy (tree_view->priv->destroy_count_data);
11462 tree_view->priv->destroy_count_func = func;
11463 tree_view->priv->destroy_count_data = data;
11464 tree_view->priv->destroy_count_destroy = destroy;
11469 * Interactive search
11473 * pspp_sheet_view_set_enable_search:
11474 * @tree_view: A #PsppSheetView
11475 * @enable_search: %TRUE, if the user can search interactively
11477 * If @enable_search is set, then the user can type in text to search through
11478 * the tree interactively (this is sometimes called "typeahead find").
11480 * Note that even if this is %FALSE, the user can still initiate a search
11481 * using the "start-interactive-search" key binding.
11484 pspp_sheet_view_set_enable_search (PsppSheetView *tree_view,
11485 gboolean enable_search)
11487 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11489 enable_search = !!enable_search;
11491 if (tree_view->priv->enable_search != enable_search)
11493 tree_view->priv->enable_search = enable_search;
11494 g_object_notify (G_OBJECT (tree_view), "enable-search");
11499 * pspp_sheet_view_get_enable_search:
11500 * @tree_view: A #PsppSheetView
11502 * Returns whether or not the tree allows to start interactive searching
11503 * by typing in text.
11505 * Return value: whether or not to let the user search interactively
11508 pspp_sheet_view_get_enable_search (PsppSheetView *tree_view)
11510 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11512 return tree_view->priv->enable_search;
11517 * pspp_sheet_view_get_search_column:
11518 * @tree_view: A #PsppSheetView
11520 * Gets the column searched on by the interactive search code.
11522 * Return value: the column the interactive search code searches in.
11525 pspp_sheet_view_get_search_column (PsppSheetView *tree_view)
11527 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
11529 return (tree_view->priv->search_column);
11533 * pspp_sheet_view_set_search_column:
11534 * @tree_view: A #PsppSheetView
11535 * @column: the column of the model to search in, or -1 to disable searching
11537 * Sets @column as the column where the interactive search code should
11538 * search in for the current model.
11540 * If the search column is set, users can use the "start-interactive-search"
11541 * key binding to bring up search popup. The enable-search property controls
11542 * whether simply typing text will also start an interactive search.
11544 * Note that @column refers to a column of the current model. The search
11545 * column is reset to -1 when the model is changed.
11548 pspp_sheet_view_set_search_column (PsppSheetView *tree_view,
11551 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11552 g_return_if_fail (column >= -1);
11554 if (tree_view->priv->search_column == column)
11557 tree_view->priv->search_column = column;
11558 g_object_notify (G_OBJECT (tree_view), "search-column");
11562 * pspp_sheet_view_get_search_equal_func:
11563 * @tree_view: A #PsppSheetView
11565 * Returns the compare function currently in use.
11567 * Return value: the currently used compare function for the search code.
11570 PsppSheetViewSearchEqualFunc
11571 pspp_sheet_view_get_search_equal_func (PsppSheetView *tree_view)
11573 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11575 return tree_view->priv->search_equal_func;
11579 * pspp_sheet_view_set_search_equal_func:
11580 * @tree_view: A #PsppSheetView
11581 * @search_equal_func: the compare function to use during the search
11582 * @search_user_data: (allow-none): user data to pass to @search_equal_func, or %NULL
11583 * @search_destroy: (allow-none): Destroy notifier for @search_user_data, or %NULL
11585 * Sets the compare function for the interactive search capabilities; note
11586 * that somewhat like strcmp() returning 0 for equality
11587 * #PsppSheetViewSearchEqualFunc returns %FALSE on matches.
11590 pspp_sheet_view_set_search_equal_func (PsppSheetView *tree_view,
11591 PsppSheetViewSearchEqualFunc search_equal_func,
11592 gpointer search_user_data,
11593 GDestroyNotify search_destroy)
11595 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11596 g_return_if_fail (search_equal_func != NULL);
11598 if (tree_view->priv->search_destroy)
11599 tree_view->priv->search_destroy (tree_view->priv->search_user_data);
11601 tree_view->priv->search_equal_func = search_equal_func;
11602 tree_view->priv->search_user_data = search_user_data;
11603 tree_view->priv->search_destroy = search_destroy;
11604 if (tree_view->priv->search_equal_func == NULL)
11605 tree_view->priv->search_equal_func = pspp_sheet_view_search_equal_func;
11609 * pspp_sheet_view_get_search_entry:
11610 * @tree_view: A #PsppSheetView
11612 * Returns the #GtkEntry which is currently in use as interactive search
11613 * entry for @tree_view. In case the built-in entry is being used, %NULL
11614 * will be returned.
11616 * Return value: the entry currently in use as search entry.
11621 pspp_sheet_view_get_search_entry (PsppSheetView *tree_view)
11623 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11625 if (tree_view->priv->search_custom_entry_set)
11626 return GTK_ENTRY (tree_view->priv->search_entry);
11632 * pspp_sheet_view_set_search_entry:
11633 * @tree_view: A #PsppSheetView
11634 * @entry: (allow-none): the entry the interactive search code of @tree_view should use or %NULL
11636 * Sets the entry which the interactive search code will use for this
11637 * @tree_view. This is useful when you want to provide a search entry
11638 * in our interface at all time at a fixed position. Passing %NULL for
11639 * @entry will make the interactive search code use the built-in popup
11645 pspp_sheet_view_set_search_entry (PsppSheetView *tree_view,
11648 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11649 g_return_if_fail (entry == NULL || GTK_IS_ENTRY (entry));
11651 if (tree_view->priv->search_custom_entry_set)
11653 if (tree_view->priv->search_entry_changed_id)
11655 g_signal_handler_disconnect (tree_view->priv->search_entry,
11656 tree_view->priv->search_entry_changed_id);
11657 tree_view->priv->search_entry_changed_id = 0;
11659 g_signal_handlers_disconnect_by_func (tree_view->priv->search_entry,
11660 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11663 g_object_unref (tree_view->priv->search_entry);
11665 else if (tree_view->priv->search_window)
11667 gtk_widget_destroy (tree_view->priv->search_window);
11669 tree_view->priv->search_window = NULL;
11674 tree_view->priv->search_entry = g_object_ref (entry);
11675 tree_view->priv->search_custom_entry_set = TRUE;
11677 if (tree_view->priv->search_entry_changed_id == 0)
11679 tree_view->priv->search_entry_changed_id =
11680 g_signal_connect (tree_view->priv->search_entry, "changed",
11681 G_CALLBACK (pspp_sheet_view_search_init),
11685 g_signal_connect (tree_view->priv->search_entry, "key-press-event",
11686 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11689 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
11693 tree_view->priv->search_entry = NULL;
11694 tree_view->priv->search_custom_entry_set = FALSE;
11699 * pspp_sheet_view_set_search_position_func:
11700 * @tree_view: A #PsppSheetView
11701 * @func: (allow-none): the function to use to position the search dialog, or %NULL
11702 * to use the default search position function
11703 * @data: (allow-none): user data to pass to @func, or %NULL
11704 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11706 * Sets the function to use when positioning the search dialog.
11711 pspp_sheet_view_set_search_position_func (PsppSheetView *tree_view,
11712 PsppSheetViewSearchPositionFunc func,
11713 gpointer user_data,
11714 GDestroyNotify destroy)
11716 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11718 if (tree_view->priv->search_position_destroy)
11719 tree_view->priv->search_position_destroy (tree_view->priv->search_position_user_data);
11721 tree_view->priv->search_position_func = func;
11722 tree_view->priv->search_position_user_data = user_data;
11723 tree_view->priv->search_position_destroy = destroy;
11724 if (tree_view->priv->search_position_func == NULL)
11725 tree_view->priv->search_position_func = pspp_sheet_view_search_position_func;
11729 * pspp_sheet_view_get_search_position_func:
11730 * @tree_view: A #PsppSheetView
11732 * Returns the positioning function currently in use.
11734 * Return value: the currently used function for positioning the search dialog.
11738 PsppSheetViewSearchPositionFunc
11739 pspp_sheet_view_get_search_position_func (PsppSheetView *tree_view)
11741 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11743 return tree_view->priv->search_position_func;
11748 pspp_sheet_view_search_dialog_hide (GtkWidget *search_dialog,
11749 PsppSheetView *tree_view)
11751 if (tree_view->priv->disable_popdown)
11754 if (tree_view->priv->search_entry_changed_id)
11756 g_signal_handler_disconnect (tree_view->priv->search_entry,
11757 tree_view->priv->search_entry_changed_id);
11758 tree_view->priv->search_entry_changed_id = 0;
11760 if (tree_view->priv->typeselect_flush_timeout)
11762 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11763 tree_view->priv->typeselect_flush_timeout = 0;
11766 if (gtk_widget_get_visible (search_dialog))
11768 /* send focus-in event */
11769 send_focus_change (GTK_WIDGET (tree_view->priv->search_entry), FALSE);
11770 gtk_widget_hide (search_dialog);
11771 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
11772 send_focus_change (GTK_WIDGET (tree_view), TRUE);
11777 pspp_sheet_view_search_position_func (PsppSheetView *tree_view,
11778 GtkWidget *search_dialog,
11779 gpointer user_data)
11782 gint tree_x, tree_y;
11783 gint tree_width, tree_height;
11784 GdkWindow *tree_window = gtk_widget_get_window (GTK_WIDGET (tree_view));
11785 GdkScreen *screen = gdk_window_get_screen (tree_window);
11786 GtkRequisition requisition;
11788 GdkRectangle monitor;
11790 monitor_num = gdk_screen_get_monitor_at_window (screen, tree_window);
11791 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
11793 gtk_widget_realize (search_dialog);
11795 gdk_window_get_origin (tree_window, &tree_x, &tree_y);
11796 tree_width = gdk_window_get_width (tree_window);
11797 tree_height = gdk_window_get_height (tree_window);
11799 gtk_widget_size_request (search_dialog, &requisition);
11801 if (tree_x + tree_width > gdk_screen_get_width (screen))
11802 x = gdk_screen_get_width (screen) - requisition.width;
11803 else if (tree_x + tree_width - requisition.width < 0)
11806 x = tree_x + tree_width - requisition.width;
11808 if (tree_y + tree_height + requisition.height > gdk_screen_get_height (screen))
11809 y = gdk_screen_get_height (screen) - requisition.height;
11810 else if (tree_y + tree_height < 0) /* isn't really possible ... */
11813 y = tree_y + tree_height;
11815 gtk_window_move (GTK_WINDOW (search_dialog), x, y);
11819 pspp_sheet_view_search_disable_popdown (GtkEntry *entry,
11823 PsppSheetView *tree_view = (PsppSheetView *)data;
11825 tree_view->priv->disable_popdown = 1;
11826 g_signal_connect (menu, "hide",
11827 G_CALLBACK (pspp_sheet_view_search_enable_popdown), data);
11830 #if GTK3_TRANSITION
11831 /* Because we're visible but offscreen, we just set a flag in the preedit
11835 pspp_sheet_view_search_preedit_changed (GtkIMContext *im_context,
11836 PsppSheetView *tree_view)
11838 tree_view->priv->imcontext_changed = 1;
11839 if (tree_view->priv->typeselect_flush_timeout)
11841 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11842 tree_view->priv->typeselect_flush_timeout =
11843 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11844 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11852 pspp_sheet_view_search_activate (GtkEntry *entry,
11853 PsppSheetView *tree_view)
11858 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window,
11861 /* If we have a row selected and it's the cursor row, we activate
11863 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
11865 path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
11867 _pspp_sheet_view_find_node (tree_view, path, &node);
11869 if (node >= 0 && pspp_sheet_view_node_is_selected (tree_view, node))
11870 pspp_sheet_view_row_activated (tree_view, path, tree_view->priv->focus_column);
11872 gtk_tree_path_free (path);
11877 pspp_sheet_view_real_search_enable_popdown (gpointer data)
11879 PsppSheetView *tree_view = (PsppSheetView *)data;
11881 tree_view->priv->disable_popdown = 0;
11887 pspp_sheet_view_search_enable_popdown (GtkWidget *widget,
11890 gdk_threads_add_timeout_full (G_PRIORITY_HIGH, 200, pspp_sheet_view_real_search_enable_popdown, g_object_ref (data), g_object_unref);
11894 pspp_sheet_view_search_delete_event (GtkWidget *widget,
11895 GdkEventAny *event,
11896 PsppSheetView *tree_view)
11898 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11900 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11906 pspp_sheet_view_search_button_press_event (GtkWidget *widget,
11907 GdkEventButton *event,
11908 PsppSheetView *tree_view)
11910 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11912 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11914 if (event->window == tree_view->priv->bin_window)
11915 pspp_sheet_view_button_press (GTK_WIDGET (tree_view), event);
11921 pspp_sheet_view_search_scroll_event (GtkWidget *widget,
11922 GdkEventScroll *event,
11923 PsppSheetView *tree_view)
11925 gboolean retval = FALSE;
11927 if (event->direction == GDK_SCROLL_UP)
11929 pspp_sheet_view_search_move (widget, tree_view, TRUE);
11932 else if (event->direction == GDK_SCROLL_DOWN)
11934 pspp_sheet_view_search_move (widget, tree_view, FALSE);
11938 /* renew the flush timeout */
11939 if (retval && tree_view->priv->typeselect_flush_timeout
11940 && !tree_view->priv->search_custom_entry_set)
11942 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11943 tree_view->priv->typeselect_flush_timeout =
11944 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11945 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11953 pspp_sheet_view_search_key_press_event (GtkWidget *widget,
11954 GdkEventKey *event,
11955 PsppSheetView *tree_view)
11957 gboolean retval = FALSE;
11959 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11960 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11962 /* close window and cancel the search */
11963 if (!tree_view->priv->search_custom_entry_set
11964 && (event->keyval == GDK_Escape ||
11965 event->keyval == GDK_Tab ||
11966 event->keyval == GDK_KP_Tab ||
11967 event->keyval == GDK_ISO_Left_Tab))
11969 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11973 /* select previous matching iter */
11974 if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up)
11976 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
11977 gtk_widget_error_bell (widget);
11982 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK))
11983 && (event->keyval == GDK_g || event->keyval == GDK_G))
11985 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
11986 gtk_widget_error_bell (widget);
11991 /* select next matching iter */
11992 if (event->keyval == GDK_Down || event->keyval == GDK_KP_Down)
11994 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
11995 gtk_widget_error_bell (widget);
12000 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == GTK_DEFAULT_ACCEL_MOD_MASK)
12001 && (event->keyval == GDK_g || event->keyval == GDK_G))
12003 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
12004 gtk_widget_error_bell (widget);
12009 /* renew the flush timeout */
12010 if (retval && tree_view->priv->typeselect_flush_timeout
12011 && !tree_view->priv->search_custom_entry_set)
12013 g_source_remove (tree_view->priv->typeselect_flush_timeout);
12014 tree_view->priv->typeselect_flush_timeout =
12015 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
12016 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
12023 /* this function returns FALSE if there is a search string but
12024 * nothing was found, and TRUE otherwise.
12027 pspp_sheet_view_search_move (GtkWidget *window,
12028 PsppSheetView *tree_view,
12036 GtkTreeModel *model;
12037 PsppSheetSelection *selection;
12039 text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
12041 g_return_val_if_fail (text != NULL, FALSE);
12043 len = strlen (text);
12045 if (up && tree_view->priv->selected_iter == 1)
12046 return strlen (text) < 1;
12048 len = strlen (text);
12053 model = pspp_sheet_view_get_model (tree_view);
12054 selection = pspp_sheet_view_get_selection (tree_view);
12057 pspp_sheet_selection_unselect_all (selection);
12058 if (!gtk_tree_model_get_iter_first (model, &iter))
12061 ret = pspp_sheet_view_search_iter (model, selection, &iter, text,
12062 &count, up?((tree_view->priv->selected_iter) - 1):((tree_view->priv->selected_iter + 1)));
12067 tree_view->priv->selected_iter += up?(-1):(1);
12072 /* return to old iter */
12074 gtk_tree_model_get_iter_first (model, &iter);
12075 pspp_sheet_view_search_iter (model, selection,
12077 &count, tree_view->priv->selected_iter);
12083 pspp_sheet_view_search_equal_func (GtkTreeModel *model,
12087 gpointer search_data)
12089 gboolean retval = TRUE;
12091 gchar *normalized_string;
12092 gchar *normalized_key;
12093 gchar *case_normalized_string = NULL;
12094 gchar *case_normalized_key = NULL;
12095 GValue value = {0,};
12096 GValue transformed = {0,};
12098 gtk_tree_model_get_value (model, iter, column, &value);
12100 g_value_init (&transformed, G_TYPE_STRING);
12102 if (!g_value_transform (&value, &transformed))
12104 g_value_unset (&value);
12108 g_value_unset (&value);
12110 str = g_value_get_string (&transformed);
12113 g_value_unset (&transformed);
12117 normalized_string = g_utf8_normalize (str, -1, G_NORMALIZE_ALL);
12118 normalized_key = g_utf8_normalize (key, -1, G_NORMALIZE_ALL);
12120 if (normalized_string && normalized_key)
12122 case_normalized_string = g_utf8_casefold (normalized_string, -1);
12123 case_normalized_key = g_utf8_casefold (normalized_key, -1);
12125 if (strncmp (case_normalized_key, case_normalized_string, strlen (case_normalized_key)) == 0)
12129 g_value_unset (&transformed);
12130 g_free (normalized_key);
12131 g_free (normalized_string);
12132 g_free (case_normalized_key);
12133 g_free (case_normalized_string);
12139 pspp_sheet_view_search_iter (GtkTreeModel *model,
12140 PsppSheetSelection *selection,
12149 PsppSheetView *tree_view = pspp_sheet_selection_get_tree_view (selection);
12151 path = gtk_tree_model_get_path (model, iter);
12152 _pspp_sheet_view_find_node (tree_view, path, &node);
12156 gboolean done = FALSE;
12158 if (! tree_view->priv->search_equal_func (model, tree_view->priv->search_column, text, iter, tree_view->priv->search_user_data))
12163 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL,
12165 pspp_sheet_selection_select_iter (selection, iter);
12166 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE, 0);
12169 gtk_tree_path_free (path);
12178 node = pspp_sheet_view_node_next (tree_view, node);
12184 has_next = gtk_tree_model_iter_next (model, iter);
12187 gtk_tree_path_next (path);
12190 TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
12195 gtk_tree_path_free (path);
12197 /* we've run out of tree, done with this func */
12209 pspp_sheet_view_search_init (GtkWidget *entry,
12210 PsppSheetView *tree_view)
12216 GtkTreeModel *model;
12217 PsppSheetSelection *selection;
12219 g_return_if_fail (GTK_IS_ENTRY (entry));
12220 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12222 text = gtk_entry_get_text (GTK_ENTRY (entry));
12224 model = pspp_sheet_view_get_model (tree_view);
12225 selection = pspp_sheet_view_get_selection (tree_view);
12228 pspp_sheet_selection_unselect_all (selection);
12229 if (tree_view->priv->typeselect_flush_timeout
12230 && !tree_view->priv->search_custom_entry_set)
12232 g_source_remove (tree_view->priv->typeselect_flush_timeout);
12233 tree_view->priv->typeselect_flush_timeout =
12234 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
12235 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
12242 if (!gtk_tree_model_get_iter_first (model, &iter))
12245 ret = pspp_sheet_view_search_iter (model, selection,
12250 tree_view->priv->selected_iter = 1;
12254 pspp_sheet_view_remove_widget (GtkCellEditable *cell_editable,
12255 PsppSheetView *tree_view)
12257 if (tree_view->priv->edited_column == NULL)
12260 _pspp_sheet_view_column_stop_editing (tree_view->priv->edited_column);
12261 tree_view->priv->edited_column = NULL;
12263 if (gtk_widget_has_focus (GTK_WIDGET (cell_editable)))
12264 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
12266 g_signal_handlers_disconnect_by_func (cell_editable,
12267 pspp_sheet_view_remove_widget,
12269 g_signal_handlers_disconnect_by_func (cell_editable,
12270 pspp_sheet_view_editable_button_press_event,
12272 g_signal_handlers_disconnect_by_func (cell_editable,
12273 pspp_sheet_view_editable_clicked,
12276 gtk_container_remove (GTK_CONTAINER (tree_view),
12277 GTK_WIDGET (cell_editable));
12279 /* FIXME should only redraw a single node */
12280 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12284 pspp_sheet_view_start_editing (PsppSheetView *tree_view,
12285 GtkTreePath *cursor_path)
12288 GdkRectangle background_area;
12289 GdkRectangle cell_area;
12290 GtkCellEditable *editable_widget = NULL;
12291 gchar *path_string;
12292 guint flags = 0; /* can be 0, as the flags are primarily for rendering */
12293 gint retval = FALSE;
12296 g_assert (tree_view->priv->focus_column);
12298 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
12301 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
12302 if (cursor_node < 0)
12305 path_string = gtk_tree_path_to_string (cursor_path);
12306 gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path);
12308 pspp_sheet_view_column_cell_set_cell_data (tree_view->priv->focus_column,
12309 tree_view->priv->model,
12311 pspp_sheet_view_get_background_area (tree_view,
12313 tree_view->priv->focus_column,
12315 pspp_sheet_view_get_cell_area (tree_view,
12317 tree_view->priv->focus_column,
12320 if (_pspp_sheet_view_column_cell_event (tree_view->priv->focus_column,
12329 if (editable_widget != NULL)
12333 GtkCellRenderer *cell;
12336 cell = _pspp_sheet_view_column_get_edited_cell (tree_view->priv->focus_column);
12338 _pspp_sheet_view_column_get_neighbor_sizes (tree_view->priv->focus_column, cell, &left, &right);
12341 area.width -= right + left;
12343 pspp_sheet_view_real_start_editing (tree_view,
12344 tree_view->priv->focus_column,
12353 g_free (path_string);
12358 pspp_sheet_view_editable_button_press_event (GtkWidget *widget,
12359 GdkEventButton *event,
12360 PsppSheetView *sheet_view)
12364 node = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
12365 "pspp-sheet-view-node"));
12366 return pspp_sheet_view_row_head_clicked (sheet_view,
12368 sheet_view->priv->edited_column,
12373 pspp_sheet_view_editable_clicked (GtkButton *button,
12374 PsppSheetView *sheet_view)
12376 pspp_sheet_view_editable_button_press_event (GTK_WIDGET (button), NULL,
12381 is_all_selected (GtkWidget *widget)
12383 GtkEntryBuffer *buffer;
12384 gint start_pos, end_pos;
12386 if (!GTK_IS_ENTRY (widget))
12389 buffer = gtk_entry_get_buffer (GTK_ENTRY (widget));
12390 return (gtk_editable_get_selection_bounds (GTK_EDITABLE (widget),
12391 &start_pos, &end_pos)
12393 && end_pos == gtk_entry_buffer_get_length (buffer));
12397 is_at_left (GtkWidget *widget)
12399 return (GTK_IS_ENTRY (widget)
12400 && gtk_editable_get_position (GTK_EDITABLE (widget)) == 0);
12404 is_at_right (GtkWidget *widget)
12406 GtkEntryBuffer *buffer;
12409 if (!GTK_IS_ENTRY (widget))
12412 buffer = gtk_entry_get_buffer (GTK_ENTRY (widget));
12413 length = gtk_entry_buffer_get_length (buffer);
12414 return gtk_editable_get_position (GTK_EDITABLE (widget)) == length;
12418 pspp_sheet_view_event (GtkWidget *widget,
12419 GdkEventKey *event,
12420 PsppSheetView *tree_view)
12422 PsppSheetViewColumn *column;
12429 /* Intercept only key press events.
12430 It would make sense to use "key-press-event" instead of "event", but
12431 GtkEntry attaches its own signal handler to "key-press-event" that runs
12432 before ours and overrides our desired behavior for GDK_Up and GDK_Down.
12434 if (event->type != GDK_KEY_PRESS)
12437 keyval = event->keyval;
12439 switch (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK | GDK_MOD1_MASK))
12442 switch (event->keyval)
12444 case GDK_Left: case GDK_KP_Left:
12445 case GDK_Home: case GDK_KP_Home:
12446 if (!is_all_selected (widget) && !is_at_left (widget))
12450 case GDK_Right: case GDK_KP_Right:
12451 case GDK_End: case GDK_KP_End:
12452 if (!is_all_selected (widget) && !is_at_right (widget))
12456 case GDK_Up: case GDK_KP_Up:
12457 case GDK_Down: case GDK_KP_Down:
12460 case GDK_Page_Up: case GDK_KP_Page_Up:
12461 case GDK_Page_Down: case GDK_KP_Page_Down:
12472 case GDK_Tab: case GDK_KP_Tab:
12473 case GDK_ISO_Left_Tab:
12482 case GDK_SHIFT_MASK:
12483 switch (event->keyval)
12486 case GDK_ISO_Left_Tab:
12495 case GDK_CONTROL_MASK:
12496 switch (event->keyval)
12498 case GDK_Left: case GDK_KP_Left:
12499 if (!is_all_selected (widget) && !is_at_left (widget))
12503 case GDK_Right: case GDK_KP_Right:
12504 if (!is_all_selected (widget) && !is_at_right (widget))
12508 case GDK_Up: case GDK_KP_Up:
12509 case GDK_Down: case GDK_KP_Down:
12521 row = tree_view->priv->edited_row;
12522 column = tree_view->priv->edited_column;
12523 path = gtk_tree_path_new_from_indices (row, -1);
12525 pspp_sheet_view_stop_editing (tree_view, cancel);
12526 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
12528 pspp_sheet_view_set_cursor (tree_view, path, column, FALSE);
12529 gtk_tree_path_free (path);
12531 handled = gtk_binding_set_activate (edit_bindings, keyval, event->state,
12532 G_OBJECT (tree_view));
12534 g_signal_stop_emission_by_name (widget, "event");
12536 pspp_sheet_view_get_cursor (tree_view, &path, NULL);
12537 pspp_sheet_view_start_editing (tree_view, path);
12538 gtk_tree_path_free (path);
12544 pspp_sheet_view_override_cell_keypresses (GtkWidget *widget,
12547 PsppSheetView *sheet_view = data;
12549 g_signal_connect (widget, "event",
12550 G_CALLBACK (pspp_sheet_view_event),
12553 if (GTK_IS_CONTAINER (widget))
12554 gtk_container_foreach (GTK_CONTAINER (widget),
12555 pspp_sheet_view_override_cell_keypresses,
12560 pspp_sheet_view_real_start_editing (PsppSheetView *tree_view,
12561 PsppSheetViewColumn *column,
12563 GtkCellEditable *cell_editable,
12564 GdkRectangle *cell_area,
12568 PsppSheetSelectionMode mode = pspp_sheet_selection_get_mode (tree_view->priv->selection);
12569 gint pre_val = gtk_adjustment_get_value (tree_view->priv->vadjustment);
12570 GtkRequisition requisition;
12573 g_return_if_fail (gtk_tree_path_get_depth (path) == 1);
12575 tree_view->priv->edited_column = column;
12576 _pspp_sheet_view_column_start_editing (column, GTK_CELL_EDITABLE (cell_editable));
12578 row = gtk_tree_path_get_indices (path)[0];
12579 tree_view->priv->edited_row = row;
12580 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE, 0);
12581 cell_area->y += pre_val - (int)gtk_adjustment_get_value (tree_view->priv->vadjustment);
12583 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
12584 pspp_sheet_selection_select_column (tree_view->priv->selection, column);
12585 tree_view->priv->anchor_column = column;
12587 gtk_widget_size_request (GTK_WIDGET (cell_editable), &requisition);
12589 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
12591 if (requisition.height < cell_area->height)
12593 gint diff = cell_area->height - requisition.height;
12594 pspp_sheet_view_put (tree_view,
12595 GTK_WIDGET (cell_editable),
12596 cell_area->x, cell_area->y + diff/2,
12597 cell_area->width, requisition.height);
12601 pspp_sheet_view_put (tree_view,
12602 GTK_WIDGET (cell_editable),
12603 cell_area->x, cell_area->y,
12604 cell_area->width, cell_area->height);
12607 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (cell_editable),
12608 (GdkEvent *)event);
12610 gtk_widget_grab_focus (GTK_WIDGET (cell_editable));
12611 g_signal_connect (cell_editable, "remove-widget",
12612 G_CALLBACK (pspp_sheet_view_remove_widget), tree_view);
12613 if (mode == PSPP_SHEET_SELECTION_RECTANGLE && column->row_head &&
12614 GTK_IS_BUTTON (cell_editable))
12616 g_signal_connect (cell_editable, "button-press-event",
12617 G_CALLBACK (pspp_sheet_view_editable_button_press_event),
12619 g_object_set_data (G_OBJECT (cell_editable), "pspp-sheet-view-node",
12620 GINT_TO_POINTER (row));
12621 g_signal_connect (cell_editable, "clicked",
12622 G_CALLBACK (pspp_sheet_view_editable_clicked),
12626 pspp_sheet_view_override_cell_keypresses (GTK_WIDGET (cell_editable),
12631 pspp_sheet_view_stop_editing (PsppSheetView *tree_view,
12632 gboolean cancel_editing)
12634 PsppSheetViewColumn *column;
12635 GtkCellRenderer *cell;
12637 if (tree_view->priv->edited_column == NULL)
12641 * This is very evil. We need to do this, because
12642 * gtk_cell_editable_editing_done may trigger pspp_sheet_view_row_changed
12643 * later on. If pspp_sheet_view_row_changed notices
12644 * tree_view->priv->edited_column != NULL, it'll call
12645 * pspp_sheet_view_stop_editing again. Bad things will happen then.
12647 * Please read that again if you intend to modify anything here.
12650 column = tree_view->priv->edited_column;
12651 tree_view->priv->edited_column = NULL;
12653 cell = _pspp_sheet_view_column_get_edited_cell (column);
12654 gtk_cell_renderer_stop_editing (cell, cancel_editing);
12656 if (!cancel_editing)
12657 gtk_cell_editable_editing_done (column->editable_widget);
12659 tree_view->priv->edited_column = column;
12661 gtk_cell_editable_remove_widget (column->editable_widget);
12666 * pspp_sheet_view_set_hover_selection:
12667 * @tree_view: a #PsppSheetView
12668 * @hover: %TRUE to enable hover selection mode
12670 * Enables of disables the hover selection mode of @tree_view.
12671 * Hover selection makes the selected row follow the pointer.
12672 * Currently, this works only for the selection modes
12673 * %PSPP_SHEET_SELECTION_SINGLE and %PSPP_SHEET_SELECTION_BROWSE.
12678 pspp_sheet_view_set_hover_selection (PsppSheetView *tree_view,
12681 hover = hover != FALSE;
12683 if (hover != tree_view->priv->hover_selection)
12685 tree_view->priv->hover_selection = hover;
12687 g_object_notify (G_OBJECT (tree_view), "hover-selection");
12692 * pspp_sheet_view_get_hover_selection:
12693 * @tree_view: a #PsppSheetView
12695 * Returns whether hover selection mode is turned on for @tree_view.
12697 * Return value: %TRUE if @tree_view is in hover selection mode
12702 pspp_sheet_view_get_hover_selection (PsppSheetView *tree_view)
12704 return tree_view->priv->hover_selection;
12708 * pspp_sheet_view_set_rubber_banding:
12709 * @tree_view: a #PsppSheetView
12710 * @enable: %TRUE to enable rubber banding
12712 * Enables or disables rubber banding in @tree_view. If the selection mode is
12713 * #PSPP_SHEET_SELECTION_MULTIPLE or #PSPP_SHEET_SELECTION_RECTANGLE, rubber
12714 * banding will allow the user to select multiple rows by dragging the mouse.
12719 pspp_sheet_view_set_rubber_banding (PsppSheetView *tree_view,
12722 enable = enable != FALSE;
12724 if (enable != tree_view->priv->rubber_banding_enable)
12726 tree_view->priv->rubber_banding_enable = enable;
12728 g_object_notify (G_OBJECT (tree_view), "rubber-banding");
12733 * pspp_sheet_view_get_rubber_banding:
12734 * @tree_view: a #PsppSheetView
12736 * Returns whether rubber banding is turned on for @tree_view. If the
12737 * selection mode is #PSPP_SHEET_SELECTION_MULTIPLE or
12738 * #PSPP_SHEET_SELECTION_RECTANGLE, rubber banding will allow the user to
12739 * select multiple rows by dragging the mouse.
12741 * Return value: %TRUE if rubber banding in @tree_view is enabled.
12746 pspp_sheet_view_get_rubber_banding (PsppSheetView *tree_view)
12748 return tree_view->priv->rubber_banding_enable;
12752 * pspp_sheet_view_is_rubber_banding_active:
12753 * @tree_view: a #PsppSheetView
12755 * Returns whether a rubber banding operation is currently being done
12758 * Return value: %TRUE if a rubber banding operation is currently being
12759 * done in @tree_view.
12764 pspp_sheet_view_is_rubber_banding_active (PsppSheetView *tree_view)
12766 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
12768 if (tree_view->priv->rubber_banding_enable
12769 && tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
12776 pspp_sheet_view_grab_notify (GtkWidget *widget,
12777 gboolean was_grabbed)
12779 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12781 tree_view->priv->in_grab = !was_grabbed;
12785 tree_view->priv->pressed_button = -1;
12787 if (tree_view->priv->rubber_band_status)
12788 pspp_sheet_view_stop_rubber_band (tree_view);
12793 pspp_sheet_view_state_changed (GtkWidget *widget,
12794 GtkStateType previous_state)
12796 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12798 if (gtk_widget_get_realized (widget))
12800 GtkStyle *style = gtk_widget_get_style (widget);
12801 gdk_window_set_background (tree_view->priv->bin_window, &style->base[gtk_widget_get_state (widget)]);
12804 gtk_widget_queue_draw (widget);
12808 * pspp_sheet_view_get_grid_lines:
12809 * @tree_view: a #PsppSheetView
12811 * Returns which grid lines are enabled in @tree_view.
12813 * Return value: a #PsppSheetViewGridLines value indicating which grid lines
12818 PsppSheetViewGridLines
12819 pspp_sheet_view_get_grid_lines (PsppSheetView *tree_view)
12821 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12823 return tree_view->priv->grid_lines;
12827 * pspp_sheet_view_set_grid_lines:
12828 * @tree_view: a #PsppSheetView
12829 * @grid_lines: a #PsppSheetViewGridLines value indicating which grid lines to
12832 * Sets which grid lines to draw in @tree_view.
12837 pspp_sheet_view_set_grid_lines (PsppSheetView *tree_view,
12838 PsppSheetViewGridLines grid_lines)
12840 PsppSheetViewPrivate *priv;
12841 PsppSheetViewGridLines old_grid_lines;
12843 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12845 priv = tree_view->priv;
12847 old_grid_lines = priv->grid_lines;
12848 priv->grid_lines = grid_lines;
12850 if (old_grid_lines != grid_lines)
12852 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12854 g_object_notify (G_OBJECT (tree_view), "enable-grid-lines");
12859 * pspp_sheet_view_get_special_cells:
12860 * @tree_view: a #PsppSheetView
12862 * Returns which grid lines are enabled in @tree_view.
12864 * Return value: a #PsppSheetViewSpecialCells value indicating whether rows in
12865 * the sheet view contain special cells.
12867 PsppSheetViewSpecialCells
12868 pspp_sheet_view_get_special_cells (PsppSheetView *tree_view)
12870 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12872 return tree_view->priv->special_cells;
12876 * pspp_sheet_view_set_special_cells:
12877 * @tree_view: a #PsppSheetView
12878 * @special_cells: a #PsppSheetViewSpecialCells value indicating whether rows in
12879 * the sheet view contain special cells.
12881 * Sets whether rows in the sheet view contain special cells, controlling the
12882 * rendering of row selections.
12885 pspp_sheet_view_set_special_cells (PsppSheetView *tree_view,
12886 PsppSheetViewSpecialCells special_cells)
12888 PsppSheetViewPrivate *priv;
12890 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12892 priv = tree_view->priv;
12894 if (priv->special_cells != special_cells)
12896 priv->special_cells = special_cells;
12897 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12898 g_object_notify (G_OBJECT (tree_view), "special-cells");
12903 pspp_sheet_view_get_fixed_height (const PsppSheetView *tree_view)
12905 /* XXX (re)calculate fixed_height if necessary */
12906 return tree_view->priv->fixed_height;
12910 pspp_sheet_view_set_fixed_height (PsppSheetView *tree_view,
12913 g_return_if_fail (fixed_height > 0);
12915 if (tree_view->priv->fixed_height != fixed_height)
12917 tree_view->priv->fixed_height = fixed_height;
12918 g_object_notify (G_OBJECT (tree_view), "fixed-height");
12920 if (!tree_view->priv->fixed_height_set)
12922 tree_view->priv->fixed_height_set = TRUE;
12923 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
12928 * pspp_sheet_view_set_tooltip_row:
12929 * @tree_view: a #PsppSheetView
12930 * @tooltip: a #GtkTooltip
12931 * @path: a #GtkTreePath
12933 * Sets the tip area of @tooltip to be the area covered by the row at @path.
12934 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
12935 * See also gtk_tooltip_set_tip_area().
12940 pspp_sheet_view_set_tooltip_row (PsppSheetView *tree_view,
12941 GtkTooltip *tooltip,
12944 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12945 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
12947 pspp_sheet_view_set_tooltip_cell (tree_view, tooltip, path, NULL, NULL);
12951 * pspp_sheet_view_set_tooltip_cell:
12952 * @tree_view: a #PsppSheetView
12953 * @tooltip: a #GtkTooltip
12954 * @path: (allow-none): a #GtkTreePath or %NULL
12955 * @column: (allow-none): a #PsppSheetViewColumn or %NULL
12956 * @cell: (allow-none): a #GtkCellRenderer or %NULL
12958 * Sets the tip area of @tooltip to the area @path, @column and @cell have
12959 * in common. For example if @path is %NULL and @column is set, the tip
12960 * area will be set to the full area covered by @column. See also
12961 * gtk_tooltip_set_tip_area().
12963 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
12968 pspp_sheet_view_set_tooltip_cell (PsppSheetView *tree_view,
12969 GtkTooltip *tooltip,
12971 PsppSheetViewColumn *column,
12972 GtkCellRenderer *cell)
12976 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12977 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
12978 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
12979 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
12981 /* Determine x values. */
12982 if (column && cell)
12987 pspp_sheet_view_get_cell_area (tree_view, path, column, &tmp);
12988 pspp_sheet_view_column_cell_get_position (column, cell, &start, &width);
12990 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12993 rect.width = width;
12999 pspp_sheet_view_get_background_area (tree_view, NULL, column, &tmp);
13000 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
13003 rect.width = tmp.width;
13007 GtkAllocation allocation;
13008 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
13010 rect.width = allocation.width;
13013 /* Determine y values. */
13018 pspp_sheet_view_get_background_area (tree_view, path, NULL, &tmp);
13019 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
13022 rect.height = tmp.height;
13027 rect.height = gtk_adjustment_get_page_size (tree_view->priv->vadjustment);
13030 gtk_tooltip_set_tip_area (tooltip, &rect);
13034 * pspp_sheet_view_get_tooltip_context:
13035 * @tree_view: a #PsppSheetView
13036 * @x: the x coordinate (relative to widget coordinates)
13037 * @y: the y coordinate (relative to widget coordinates)
13038 * @keyboard_tip: whether this is a keyboard tooltip or not
13039 * @model: (allow-none): a pointer to receive a #GtkTreeModel or %NULL
13040 * @path: (allow-none): a pointer to receive a #GtkTreePath or %NULL
13041 * @iter: (allow-none): a pointer to receive a #GtkTreeIter or %NULL
13043 * This function is supposed to be used in a #GtkWidget::query-tooltip
13044 * signal handler for #PsppSheetView. The @x, @y and @keyboard_tip values
13045 * which are received in the signal handler, should be passed to this
13046 * function without modification.
13048 * The return value indicates whether there is a tree view row at the given
13049 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
13050 * tooltips the row returned will be the cursor row. When %TRUE, then any of
13051 * @model, @path and @iter which have been provided will be set to point to
13052 * that row and the corresponding model. @x and @y will always be converted
13053 * to be relative to @tree_view's bin_window if @keyboard_tooltip is %FALSE.
13055 * Return value: whether or not the given tooltip context points to a row.
13060 pspp_sheet_view_get_tooltip_context (PsppSheetView *tree_view,
13063 gboolean keyboard_tip,
13064 GtkTreeModel **model,
13065 GtkTreePath **path,
13068 GtkTreePath *tmppath = NULL;
13070 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
13071 g_return_val_if_fail (x != NULL, FALSE);
13072 g_return_val_if_fail (y != NULL, FALSE);
13076 pspp_sheet_view_get_cursor (tree_view, &tmppath, NULL);
13083 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, *x, *y,
13086 if (!pspp_sheet_view_get_path_at_pos (tree_view, *x, *y,
13087 &tmppath, NULL, NULL, NULL))
13092 *model = pspp_sheet_view_get_model (tree_view);
13095 gtk_tree_model_get_iter (pspp_sheet_view_get_model (tree_view),
13101 gtk_tree_path_free (tmppath);
13107 pspp_sheet_view_set_tooltip_query_cb (GtkWidget *widget,
13110 gboolean keyboard_tip,
13111 GtkTooltip *tooltip,
13114 GValue value = { 0, };
13115 GValue transformed = { 0, };
13118 GtkTreeModel *model;
13119 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
13121 if (!pspp_sheet_view_get_tooltip_context (PSPP_SHEET_VIEW (widget),
13124 &model, &path, &iter))
13127 gtk_tree_model_get_value (model, &iter,
13128 tree_view->priv->tooltip_column, &value);
13130 g_value_init (&transformed, G_TYPE_STRING);
13132 if (!g_value_transform (&value, &transformed))
13134 g_value_unset (&value);
13135 gtk_tree_path_free (path);
13140 g_value_unset (&value);
13142 if (!g_value_get_string (&transformed))
13144 g_value_unset (&transformed);
13145 gtk_tree_path_free (path);
13150 gtk_tooltip_set_markup (tooltip, g_value_get_string (&transformed));
13151 pspp_sheet_view_set_tooltip_row (tree_view, tooltip, path);
13153 gtk_tree_path_free (path);
13154 g_value_unset (&transformed);
13160 * pspp_sheet_view_set_tooltip_column:
13161 * @tree_view: a #PsppSheetView
13162 * @column: an integer, which is a valid column number for @tree_view's model
13164 * If you only plan to have simple (text-only) tooltips on full rows, you
13165 * can use this function to have #PsppSheetView handle these automatically
13166 * for you. @column should be set to the column in @tree_view's model
13167 * containing the tooltip texts, or -1 to disable this feature.
13169 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
13170 * @tree_view will connect a #GtkWidget::query-tooltip signal handler.
13172 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
13173 * so &, <, etc have to be escaped in the text.
13178 pspp_sheet_view_set_tooltip_column (PsppSheetView *tree_view,
13181 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
13183 if (column == tree_view->priv->tooltip_column)
13188 g_signal_handlers_disconnect_by_func (tree_view,
13189 pspp_sheet_view_set_tooltip_query_cb,
13191 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), FALSE);
13195 if (tree_view->priv->tooltip_column == -1)
13197 g_signal_connect (tree_view, "query-tooltip",
13198 G_CALLBACK (pspp_sheet_view_set_tooltip_query_cb), NULL);
13199 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), TRUE);
13203 tree_view->priv->tooltip_column = column;
13204 g_object_notify (G_OBJECT (tree_view), "tooltip-column");
13208 * pspp_sheet_view_get_tooltip_column:
13209 * @tree_view: a #PsppSheetView
13211 * Returns the column of @tree_view's model which is being used for
13212 * displaying tooltips on @tree_view's rows.
13214 * Return value: the index of the tooltip column that is currently being
13215 * used, or -1 if this is disabled.
13220 pspp_sheet_view_get_tooltip_column (PsppSheetView *tree_view)
13222 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
13224 return tree_view->priv->tooltip_column;
13228 _gtk_boolean_handled_accumulator (GSignalInvocationHint *ihint,
13229 GValue *return_accu,
13230 const GValue *handler_return,
13233 gboolean continue_emission;
13234 gboolean signal_handled;
13236 signal_handled = g_value_get_boolean (handler_return);
13237 g_value_set_boolean (return_accu, signal_handled);
13238 continue_emission = !signal_handled;
13240 return continue_emission;
13245 pspp_sheet_view_grid_lines_get_type (void)
13247 static GType etype = 0;
13248 if (G_UNLIKELY(etype == 0)) {
13249 static const GEnumValue values[] = {
13250 { PSPP_SHEET_VIEW_GRID_LINES_NONE, "PSPP_SHEET_VIEW_GRID_LINES_NONE", "none" },
13251 { PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL, "PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL", "horizontal" },
13252 { PSPP_SHEET_VIEW_GRID_LINES_VERTICAL, "PSPP_SHEET_VIEW_GRID_LINES_VERTICAL", "vertical" },
13253 { PSPP_SHEET_VIEW_GRID_LINES_BOTH, "PSPP_SHEET_VIEW_GRID_LINES_BOTH", "both" },
13256 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewGridLines"), values);
13262 pspp_sheet_view_special_cells_get_type (void)
13264 static GType etype = 0;
13265 if (G_UNLIKELY(etype == 0)) {
13266 static const GEnumValue values[] = {
13267 { PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT, "PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT", "detect" },
13268 { PSPP_SHEET_VIEW_SPECIAL_CELLS_YES, "PSPP_SHEET_VIEW_SPECIAL_CELLS_YES", "yes" },
13269 { PSPP_SHEET_VIEW_SPECIAL_CELLS_NO, "PSPP_SHEET_VIEW_SPECIAL_CELLS_NO", "no" },
13272 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewSpecialCells"), values);