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, GdkRectangle *clip_area)
3753 GtkWidget *widget = GTK_WIDGET (tree_view);
3756 if (!gtk_widget_has_focus (widget))
3759 w = gdk_window_get_width (tree_view->priv->bin_window);
3760 h = gdk_window_get_height (tree_view->priv->bin_window);
3766 gtk_paint_focus (gtk_widget_get_style (widget),
3767 tree_view->priv->bin_window,
3768 gtk_widget_get_state (widget),
3776 pspp_sheet_view_draw_vertical_grid_lines (PsppSheetView *tree_view,
3778 gint n_visible_columns,
3782 GList *list = tree_view->priv->columns;
3786 if (tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
3787 && tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_BOTH)
3790 /* Only draw the lines for visible rows and columns */
3791 for (list = tree_view->priv->columns; list; list = list->next, i++)
3793 PsppSheetViewColumn *column = list->data;
3795 /* We don't want a line for the last column */
3796 if (i == n_visible_columns - 1)
3799 if (! column->visible)
3802 current_x += column->width;
3804 cairo_set_line_width (cr, 1.0);
3805 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
3806 cairo_move_to (cr, current_x - 0.5, min_y);
3807 cairo_line_to (cr, current_x - 0.5 , max_y - min_y);
3813 /* Warning: Very scary function.
3814 * Modify at your own risk
3816 * KEEP IN SYNC WITH pspp_sheet_view_create_row_drag_icon()!
3817 * FIXME: It's not...
3820 pspp_sheet_view_bin_expose (GtkWidget *widget,
3821 GdkEventExpose *event)
3823 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
3828 int drag_highlight = -1;
3831 gint y_offset, cell_offset;
3833 GdkRectangle background_area;
3834 GdkRectangle cell_area;
3836 gint bin_window_width;
3837 gint bin_window_height;
3838 GtkTreePath *cursor_path;
3839 GtkTreePath *drag_dest_path;
3840 GList *first_column, *last_column;
3841 gint vertical_separator;
3842 gint horizontal_separator;
3843 gint focus_line_width;
3844 gboolean allow_rules;
3845 gboolean has_special_cell;
3847 gint n_visible_columns;
3848 gint grid_line_width;
3849 gboolean row_ending_details;
3850 gboolean draw_vgrid_lines, draw_hgrid_lines;
3852 cairo_t *cr = gdk_cairo_create (event->window);
3854 GtkAllocation allocation;
3855 gtk_widget_get_allocation (widget, &allocation);
3859 Zarea.width = gdk_window_get_width (event->window);
3860 Zarea.height = allocation.height;
3862 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
3864 gtk_widget_style_get (widget,
3865 "horizontal-separator", &horizontal_separator,
3866 "vertical-separator", &vertical_separator,
3867 "allow-rules", &allow_rules,
3868 "focus-line-width", &focus_line_width,
3869 "row-ending-details", &row_ending_details,
3872 if (tree_view->priv->row_count == 0)
3874 draw_empty_focus (tree_view, &Zarea);
3879 /* clip event->area to the visible area */
3880 if (Zarea.height < 0.5)
3884 validate_visible_area (tree_view);
3886 new_y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, Zarea.y);
3890 y_offset = -pspp_sheet_view_find_offset (tree_view, new_y, &node);
3892 gdk_window_get_width (tree_view->priv->bin_window);
3895 gdk_window_get_height (tree_view->priv->bin_window);
3898 if (tree_view->priv->height < bin_window_height)
3900 gtk_paint_flat_box (gtk_widget_get_style (widget),
3902 gtk_widget_get_state (widget),
3907 0, tree_view->priv->height,
3909 bin_window_height - tree_view->priv->height);
3915 /* find the path for the node */
3916 path = _pspp_sheet_view_find_path ((PsppSheetView *)widget, node);
3917 gtk_tree_model_get_iter (tree_view->priv->model,
3920 gtk_tree_path_free (path);
3923 drag_dest_path = NULL;
3925 if (tree_view->priv->cursor)
3926 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
3929 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor);
3931 if (tree_view->priv->drag_dest_row)
3932 drag_dest_path = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
3935 _pspp_sheet_view_find_node (tree_view, drag_dest_path,
3939 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
3940 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
3942 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
3943 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
3945 if (draw_vgrid_lines || draw_hgrid_lines)
3946 gtk_widget_style_get (widget, "grid-line-width", &grid_line_width, NULL);
3948 n_visible_columns = 0;
3949 for (list = tree_view->priv->columns; list; list = list->next)
3951 if (! PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
3953 n_visible_columns ++;
3956 /* Find the last column */
3957 for (last_column = g_list_last (tree_view->priv->columns);
3958 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
3959 last_column = last_column->prev)
3963 for (first_column = g_list_first (tree_view->priv->columns);
3964 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
3965 first_column = first_column->next)
3968 /* Actually process the expose event. To do this, we want to
3969 * start at the first node of the event, and walk the tree in
3970 * order, drawing each successive node.
3977 gboolean is_first = FALSE;
3978 gboolean is_last = FALSE;
3979 gboolean done = FALSE;
3982 max_height = ROW_HEIGHT (tree_view);
3986 background_area.y = y_offset + Zarea.y;
3987 background_area.height = max_height;
3988 max_y = background_area.y + max_height;
3992 if (node == tree_view->priv->prelight_node)
3993 flags |= GTK_CELL_RENDERER_PRELIT;
3995 selected = pspp_sheet_view_node_is_selected (tree_view, node);
3999 if (tree_view->priv->special_cells == PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT)
4001 /* we *need* to set cell data on all cells before the call
4002 * to _has_special_cell, else _has_special_cell() does not
4003 * return a correct value.
4005 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
4007 list = (rtl ? list->prev : list->next))
4009 PsppSheetViewColumn *column = list->data;
4010 pspp_sheet_view_column_cell_set_cell_data (column,
4011 tree_view->priv->model,
4015 has_special_cell = pspp_sheet_view_has_special_cell (tree_view);
4018 has_special_cell = tree_view->priv->special_cells == PSPP_SHEET_VIEW_SPECIAL_CELLS_YES;
4020 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
4022 list = (rtl ? list->prev : list->next))
4024 PsppSheetViewColumn *column = list->data;
4025 const gchar *detail = NULL;
4026 gboolean selected_column;
4029 if (!column->visible)
4032 if (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE)
4033 selected_column = column->selected && column->selectable;
4035 selected_column = TRUE;
4038 if (cell_offset > Zarea.x + Zarea.width ||
4039 cell_offset + column->width < Zarea.x)
4041 cell_offset += column->width;
4046 if (selected && selected_column)
4047 flags |= GTK_CELL_RENDERER_SELECTED;
4049 flags &= ~GTK_CELL_RENDERER_SELECTED;
4051 if (column->show_sort_indicator)
4052 flags |= GTK_CELL_RENDERER_SORTED;
4054 flags &= ~GTK_CELL_RENDERER_SORTED;
4057 flags |= GTK_CELL_RENDERER_FOCUSED;
4059 flags &= ~GTK_CELL_RENDERER_FOCUSED;
4061 background_area.x = cell_offset;
4062 background_area.width = column->width;
4064 cell_area = background_area;
4065 cell_area.y += vertical_separator / 2;
4066 cell_area.x += horizontal_separator / 2;
4067 cell_area.height -= vertical_separator;
4068 cell_area.width -= horizontal_separator;
4070 if (draw_vgrid_lines)
4072 if (list == first_column)
4074 cell_area.width -= grid_line_width / 2;
4076 else if (list == last_column)
4078 cell_area.x += grid_line_width / 2;
4079 cell_area.width -= grid_line_width / 2;
4083 cell_area.x += grid_line_width / 2;
4084 cell_area.width -= grid_line_width;
4088 if (draw_hgrid_lines)
4090 cell_area.y += grid_line_width / 2;
4091 cell_area.height -= grid_line_width;
4095 if (gdk_region_rect_in (event->region, &background_area) == GDK_OVERLAP_RECTANGLE_OUT)
4097 cell_offset += column->width;
4102 pspp_sheet_view_column_cell_set_cell_data (column,
4103 tree_view->priv->model,
4106 /* Select the detail for drawing the cell. relevant
4107 * factors are parity, sortedness, and whether to
4110 if (allow_rules && tree_view->priv->has_rules)
4112 if ((flags & GTK_CELL_RENDERER_SORTED) &&
4113 n_visible_columns >= 3)
4116 detail = "cell_odd_ruled_sorted";
4118 detail = "cell_even_ruled_sorted";
4123 detail = "cell_odd_ruled";
4125 detail = "cell_even_ruled";
4130 if ((flags & GTK_CELL_RENDERER_SORTED) &&
4131 n_visible_columns >= 3)
4134 detail = "cell_odd_sorted";
4136 detail = "cell_even_sorted";
4141 detail = "cell_odd";
4143 detail = "cell_even";
4149 if (gtk_widget_get_state (widget) == GTK_STATE_INSENSITIVE)
4150 state = GTK_STATE_INSENSITIVE;
4151 else if (flags & GTK_CELL_RENDERER_SELECTED)
4152 state = GTK_STATE_SELECTED;
4154 state = GTK_STATE_NORMAL;
4156 /* Draw background */
4157 if (row_ending_details)
4159 char new_detail[128];
4161 is_first = (rtl ? !list->next : !list->prev);
4162 is_last = (rtl ? !list->prev : !list->next);
4164 /* (I don't like the snprintfs either, but couldn't find a
4167 if (is_first && is_last)
4168 g_snprintf (new_detail, 127, "%s", detail);
4170 g_snprintf (new_detail, 127, "%s_start", detail);
4172 g_snprintf (new_detail, 127, "%s_end", detail);
4174 g_snprintf (new_detail, 128, "%s_middle", detail);
4176 gtk_paint_flat_box (gtk_widget_get_style (widget),
4185 background_area.width,
4186 background_area.height);
4190 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,
4248 if (node == cursor && has_special_cell &&
4249 ((column == tree_view->priv->focus_column &&
4250 PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS) &&
4251 gtk_widget_has_focus (widget)) ||
4252 (column == tree_view->priv->edited_column)))
4254 _pspp_sheet_view_column_cell_draw_focus (column,
4262 cell_offset += column->width;
4265 if (cell_offset < Zarea.x)
4267 gtk_paint_flat_box (gtk_widget_get_style (widget),
4276 Zarea.x - cell_offset,
4277 background_area.height);
4280 if (node == drag_highlight)
4282 /* Draw indicator for the drop
4284 gint highlight_y = -1;
4288 switch (tree_view->priv->drag_dest_pos)
4290 case PSPP_SHEET_VIEW_DROP_BEFORE:
4291 highlight_y = background_area.y - 1;
4292 if (highlight_y < 0)
4296 case PSPP_SHEET_VIEW_DROP_AFTER:
4297 highlight_y = background_area.y + background_area.height - 1;
4300 case PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE:
4301 case PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER:
4302 _pspp_sheet_view_find_node (tree_view, drag_dest_path, &node);
4306 width = gdk_window_get_width (tree_view->priv->bin_window);
4308 if (row_ending_details)
4309 gtk_paint_focus (gtk_widget_get_style (widget),
4310 tree_view->priv->bin_window,
4311 gtk_widget_get_state (widget),
4315 ? (is_last ? "treeview-drop-indicator" : "treeview-drop-indicator-left" )
4316 : (is_last ? "treeview-drop-indicator-right" : "tree-view-drop-indicator-middle" )),
4317 0, BACKGROUND_FIRST_PIXEL (tree_view, node)
4318 - focus_line_width / 2,
4319 width, ROW_HEIGHT (tree_view)
4320 - focus_line_width + 1);
4322 gtk_paint_focus (gtk_widget_get_style (widget),
4323 tree_view->priv->bin_window,
4324 gtk_widget_get_state (widget),
4327 "treeview-drop-indicator",
4328 0, BACKGROUND_FIRST_PIXEL (tree_view, node)
4329 - focus_line_width / 2,
4330 width, ROW_HEIGHT (tree_view)
4331 - focus_line_width + 1);
4336 if (highlight_y >= 0)
4338 gdk_draw_line (event->window,
4339 widget->style->fg_gc[gtk_widget_get_state (widget)],
4342 rtl ? 0 : bin_window_width,
4348 /* draw the big row-spanning focus rectangle, if needed */
4349 if (!has_special_cell && node == cursor &&
4350 PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS) &&
4351 gtk_widget_has_focus (widget))
4353 gint tmp_y, tmp_height;
4355 GtkStateType focus_rect_state;
4358 flags & GTK_CELL_RENDERER_SELECTED ? GTK_STATE_SELECTED :
4359 (flags & GTK_CELL_RENDERER_PRELIT ? GTK_STATE_PRELIGHT :
4360 (flags & GTK_CELL_RENDERER_INSENSITIVE ? GTK_STATE_INSENSITIVE :
4363 width = gdk_window_get_width (tree_view->priv->bin_window);
4365 if (draw_hgrid_lines)
4367 tmp_y = BACKGROUND_FIRST_PIXEL (tree_view, node) + grid_line_width / 2;
4368 tmp_height = ROW_HEIGHT (tree_view) - grid_line_width;
4372 tmp_y = BACKGROUND_FIRST_PIXEL (tree_view, node);
4373 tmp_height = ROW_HEIGHT (tree_view);
4376 if (row_ending_details)
4377 gtk_paint_focus (gtk_widget_get_style (widget),
4378 tree_view->priv->bin_window,
4383 ? (is_last ? "treeview" : "treeview-left" )
4384 : (is_last ? "treeview-right" : "treeview-middle" )),
4388 gtk_paint_focus (gtk_widget_get_style (widget),
4389 tree_view->priv->bin_window,
4398 y_offset += max_height;
4402 node = pspp_sheet_view_node_next (tree_view, node);
4405 gboolean has_next = gtk_tree_model_iter_next (tree_view->priv->model, &iter);
4409 TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
4416 while (y_offset < Zarea.height);
4419 pspp_sheet_view_draw_vertical_grid_lines (tree_view, cr, n_visible_columns,
4423 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
4425 GdkRectangle *rectangles;
4428 gdk_region_get_rectangles (event->region,
4432 while (n_rectangles--)
4433 pspp_sheet_view_paint_rubber_band (tree_view, &rectangles[n_rectangles]);
4435 g_free (rectangles);
4440 gtk_tree_path_free (cursor_path);
4443 gtk_tree_path_free (drag_dest_path);
4449 pspp_sheet_view_expose (GtkWidget *widget,
4450 GdkEventExpose *event)
4452 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4453 cairo_t *cr = gdk_cairo_create (event->window);
4455 if (event->window == tree_view->priv->bin_window)
4460 retval = pspp_sheet_view_bin_expose (widget, event);
4462 /* We can't just chain up to Container::expose as it will try to send the
4463 * event to the headers, so we handle propagating it to our children
4464 * (eg. widgets being edited) ourselves.
4466 tmp_list = tree_view->priv->children;
4469 PsppSheetViewChild *child = tmp_list->data;
4470 tmp_list = tmp_list->next;
4472 gtk_container_propagate_expose (GTK_CONTAINER (tree_view), child->widget, event);
4477 else if (event->window == tree_view->priv->header_window)
4479 gint n_visible_columns;
4482 gtk_paint_flat_box (gtk_widget_get_style (widget),
4492 event->area.height);
4494 for (list = tree_view->priv->columns; list != NULL; list = list->next)
4496 PsppSheetViewColumn *column = list->data;
4498 if (column == tree_view->priv->drag_column || !column->visible)
4501 if (span_intersects (column->allocation.x, column->allocation.width,
4502 event->area.x, event->area.width)
4503 && column->button != NULL)
4504 gtk_container_propagate_expose (GTK_CONTAINER (tree_view),
4505 column->button, event);
4508 n_visible_columns = 0;
4509 for (list = tree_view->priv->columns; list; list = list->next)
4511 if (! PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
4513 n_visible_columns ++;
4515 pspp_sheet_view_draw_vertical_grid_lines (tree_view,
4519 event->area.height);
4521 else if (event->window == tree_view->priv->drag_window)
4523 gtk_container_propagate_expose (GTK_CONTAINER (tree_view),
4524 tree_view->priv->drag_column->button,
4538 /* returns 0x1 when no column has been found -- yes it's hackish */
4539 static PsppSheetViewColumn *
4540 pspp_sheet_view_get_drop_column (PsppSheetView *tree_view,
4541 PsppSheetViewColumn *column,
4544 PsppSheetViewColumn *left_column = NULL;
4545 PsppSheetViewColumn *cur_column = NULL;
4548 if (!column->reorderable)
4549 return (PsppSheetViewColumn *)0x1;
4551 switch (drop_position)
4554 /* find first column where we can drop */
4555 tmp_list = tree_view->priv->columns;
4556 if (column == PSPP_SHEET_VIEW_COLUMN (tmp_list->data))
4557 return (PsppSheetViewColumn *)0x1;
4561 g_assert (tmp_list);
4563 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4564 tmp_list = tmp_list->next;
4566 if (left_column && left_column->visible == FALSE)
4569 if (!tree_view->priv->column_drop_func)
4572 if (!tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4574 left_column = cur_column;
4581 if (!tree_view->priv->column_drop_func)
4584 if (tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data))
4587 return (PsppSheetViewColumn *)0x1;
4591 /* find first column after column where we can drop */
4592 tmp_list = tree_view->priv->columns;
4594 for (; tmp_list; tmp_list = tmp_list->next)
4595 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data) == column)
4598 if (!tmp_list || !tmp_list->next)
4599 return (PsppSheetViewColumn *)0x1;
4601 tmp_list = tmp_list->next;
4602 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4603 tmp_list = tmp_list->next;
4607 g_assert (tmp_list);
4609 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4610 tmp_list = tmp_list->next;
4612 if (left_column && left_column->visible == FALSE)
4614 left_column = cur_column;
4616 tmp_list = tmp_list->next;
4620 if (!tree_view->priv->column_drop_func)
4623 if (!tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4625 left_column = cur_column;
4632 if (!tree_view->priv->column_drop_func)
4635 if (tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data))
4638 return (PsppSheetViewColumn *)0x1;
4642 /* find first column before column where we can drop */
4643 tmp_list = tree_view->priv->columns;
4645 for (; tmp_list; tmp_list = tmp_list->next)
4646 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data) == column)
4649 if (!tmp_list || !tmp_list->prev)
4650 return (PsppSheetViewColumn *)0x1;
4652 tmp_list = tmp_list->prev;
4653 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4654 tmp_list = tmp_list->prev;
4658 g_assert (tmp_list);
4660 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4662 if (left_column && !left_column->visible)
4664 /*if (!tmp_list->prev)
4665 return (PsppSheetViewColumn *)0x1;
4668 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->prev->data);
4669 tmp_list = tmp_list->prev->prev;
4672 cur_column = left_column;
4674 tmp_list = tmp_list->prev;
4678 if (!tree_view->priv->column_drop_func)
4681 if (tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4684 cur_column = left_column;
4685 tmp_list = tmp_list->prev;
4688 if (!tree_view->priv->column_drop_func)
4691 if (tree_view->priv->column_drop_func (tree_view, column, NULL, cur_column, tree_view->priv->column_drop_func_data))
4694 return (PsppSheetViewColumn *)0x1;
4698 /* same as DROP_HOME case, but doing it backwards */
4699 tmp_list = g_list_last (tree_view->priv->columns);
4702 if (column == PSPP_SHEET_VIEW_COLUMN (tmp_list->data))
4703 return (PsppSheetViewColumn *)0x1;
4707 g_assert (tmp_list);
4709 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4711 if (left_column && !left_column->visible)
4713 cur_column = left_column;
4714 tmp_list = tmp_list->prev;
4717 if (!tree_view->priv->column_drop_func)
4720 if (tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4723 cur_column = left_column;
4724 tmp_list = tmp_list->prev;
4727 if (!tree_view->priv->column_drop_func)
4730 if (tree_view->priv->column_drop_func (tree_view, column, NULL, cur_column, tree_view->priv->column_drop_func_data))
4733 return (PsppSheetViewColumn *)0x1;
4737 return (PsppSheetViewColumn *)0x1;
4741 pspp_sheet_view_key_press (GtkWidget *widget,
4744 PsppSheetView *tree_view = (PsppSheetView *) widget;
4746 if (tree_view->priv->rubber_band_status)
4748 if (event->keyval == GDK_Escape)
4749 pspp_sheet_view_stop_rubber_band (tree_view);
4754 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
4756 if (event->keyval == GDK_Escape)
4758 tree_view->priv->cur_reorder = NULL;
4759 pspp_sheet_view_button_release_drag_column (widget, NULL);
4764 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
4766 GList *focus_column;
4769 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
4771 for (focus_column = tree_view->priv->columns;
4773 focus_column = focus_column->next)
4775 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4777 if (column->button && gtk_widget_has_focus (column->button))
4782 (event->state & GDK_SHIFT_MASK) && (event->state & GDK_MOD1_MASK) &&
4783 (event->keyval == GDK_Left || event->keyval == GDK_KP_Left
4784 || event->keyval == GDK_Right || event->keyval == GDK_KP_Right))
4786 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4788 if (!column->resizable)
4790 gtk_widget_error_bell (widget);
4794 if (event->keyval == (rtl ? GDK_Right : GDK_Left)
4795 || event->keyval == (rtl ? GDK_KP_Right : GDK_KP_Left))
4797 gint old_width = column->resized_width;
4799 column->resized_width = MAX (column->resized_width,
4801 column->resized_width -= 2;
4802 if (column->resized_width < 0)
4803 column->resized_width = 0;
4805 if (column->min_width == -1)
4806 column->resized_width = MAX (column->button_request,
4807 column->resized_width);
4809 column->resized_width = MAX (column->min_width,
4810 column->resized_width);
4812 if (column->max_width != -1)
4813 column->resized_width = MIN (column->resized_width,
4816 column->use_resized_width = TRUE;
4818 if (column->resized_width != old_width)
4819 gtk_widget_queue_resize (widget);
4821 gtk_widget_error_bell (widget);
4823 else if (event->keyval == (rtl ? GDK_Left : GDK_Right)
4824 || event->keyval == (rtl ? GDK_KP_Left : GDK_KP_Right))
4826 gint old_width = column->resized_width;
4828 column->resized_width = MAX (column->resized_width,
4830 column->resized_width += 2;
4832 if (column->max_width != -1)
4833 column->resized_width = MIN (column->resized_width,
4836 column->use_resized_width = TRUE;
4838 if (column->resized_width != old_width)
4839 gtk_widget_queue_resize (widget);
4841 gtk_widget_error_bell (widget);
4848 (event->state & GDK_MOD1_MASK) &&
4849 (event->keyval == GDK_Left || event->keyval == GDK_KP_Left
4850 || event->keyval == GDK_Right || event->keyval == GDK_KP_Right
4851 || event->keyval == GDK_Home || event->keyval == GDK_KP_Home
4852 || event->keyval == GDK_End || event->keyval == GDK_KP_End))
4854 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4856 if (event->keyval == (rtl ? GDK_Right : GDK_Left)
4857 || event->keyval == (rtl ? GDK_KP_Right : GDK_KP_Left))
4859 PsppSheetViewColumn *col;
4860 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_LEFT);
4861 if (col != (PsppSheetViewColumn *)0x1)
4862 pspp_sheet_view_move_column_after (tree_view, column, col);
4864 gtk_widget_error_bell (widget);
4866 else if (event->keyval == (rtl ? GDK_Left : GDK_Right)
4867 || event->keyval == (rtl ? GDK_KP_Left : GDK_KP_Right))
4869 PsppSheetViewColumn *col;
4870 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_RIGHT);
4871 if (col != (PsppSheetViewColumn *)0x1)
4872 pspp_sheet_view_move_column_after (tree_view, column, col);
4874 gtk_widget_error_bell (widget);
4876 else if (event->keyval == GDK_Home || event->keyval == GDK_KP_Home)
4878 PsppSheetViewColumn *col;
4879 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_HOME);
4880 if (col != (PsppSheetViewColumn *)0x1)
4881 pspp_sheet_view_move_column_after (tree_view, column, col);
4883 gtk_widget_error_bell (widget);
4885 else if (event->keyval == GDK_End || event->keyval == GDK_KP_End)
4887 PsppSheetViewColumn *col;
4888 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_END);
4889 if (col != (PsppSheetViewColumn *)0x1)
4890 pspp_sheet_view_move_column_after (tree_view, column, col);
4892 gtk_widget_error_bell (widget);
4899 /* Chain up to the parent class. It handles the keybindings. */
4900 if (GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->key_press_event (widget, event))
4903 if (tree_view->priv->search_entry_avoid_unhandled_binding)
4905 tree_view->priv->search_entry_avoid_unhandled_binding = FALSE;
4909 /* We pass the event to the search_entry. If its text changes, then we start
4910 * the typeahead find capabilities. */
4911 if (gtk_widget_has_focus (GTK_WIDGET (tree_view))
4912 && tree_view->priv->enable_search
4913 && !tree_view->priv->search_custom_entry_set)
4915 GdkEvent *new_event;
4917 const char *new_text;
4920 gboolean text_modified;
4921 gulong popup_menu_id;
4923 pspp_sheet_view_ensure_interactive_directory (tree_view);
4925 /* Make a copy of the current text */
4926 old_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry)));
4927 new_event = gdk_event_copy ((GdkEvent *) event);
4928 g_object_unref (((GdkEventKey *) new_event)->window);
4929 ((GdkEventKey *) new_event)->window = g_object_ref (gtk_widget_get_window (tree_view->priv->search_window));
4930 gtk_widget_realize (tree_view->priv->search_window);
4932 popup_menu_id = g_signal_connect (tree_view->priv->search_entry,
4933 "popup-menu", G_CALLBACK (gtk_true),
4936 /* Move the entry off screen */
4937 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
4938 gtk_window_move (GTK_WINDOW (tree_view->priv->search_window),
4939 gdk_screen_get_width (screen) + 1,
4940 gdk_screen_get_height (screen) + 1);
4941 gtk_widget_show (tree_view->priv->search_window);
4943 /* Send the event to the window. If the preedit_changed signal is emitted
4944 * during this event, we will set priv->imcontext_changed */
4945 tree_view->priv->imcontext_changed = FALSE;
4946 retval = gtk_widget_event (tree_view->priv->search_window, new_event);
4947 gdk_event_free (new_event);
4948 gtk_widget_hide (tree_view->priv->search_window);
4950 g_signal_handler_disconnect (tree_view->priv->search_entry,
4953 /* We check to make sure that the entry tried to handle the text, and that
4954 * the text has changed.
4956 new_text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
4957 text_modified = strcmp (old_text, new_text) != 0;
4959 if (tree_view->priv->imcontext_changed || /* we're in a preedit */
4960 (retval && text_modified)) /* ...or the text was modified */
4962 if (pspp_sheet_view_real_start_interactive_search (tree_view, FALSE))
4964 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
4969 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
4979 pspp_sheet_view_key_release (GtkWidget *widget,
4982 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4984 if (tree_view->priv->rubber_band_status)
4987 return GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->key_release_event (widget, event);
4990 /* FIXME Is this function necessary? Can I get an enter_notify event
4991 * w/o either an expose event or a mouse motion event?
4994 pspp_sheet_view_enter_notify (GtkWidget *widget,
4995 GdkEventCrossing *event)
4997 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
5001 /* Sanity check it */
5002 if (event->window != tree_view->priv->bin_window)
5005 if (tree_view->priv->row_count == 0)
5008 if (event->mode == GDK_CROSSING_GRAB ||
5009 event->mode == GDK_CROSSING_GTK_GRAB ||
5010 event->mode == GDK_CROSSING_GTK_UNGRAB ||
5011 event->mode == GDK_CROSSING_STATE_CHANGED)
5014 /* find the node internally */
5015 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, event->y);
5018 pspp_sheet_view_find_offset (tree_view, new_y, &node);
5020 tree_view->priv->event_last_x = event->x;
5021 tree_view->priv->event_last_y = event->y;
5023 prelight_or_select (tree_view, node, event->x, event->y);
5029 pspp_sheet_view_leave_notify (GtkWidget *widget,
5030 GdkEventCrossing *event)
5032 PsppSheetView *tree_view;
5034 if (event->mode == GDK_CROSSING_GRAB)
5037 tree_view = PSPP_SHEET_VIEW (widget);
5039 if (tree_view->priv->prelight_node >= 0)
5040 _pspp_sheet_view_queue_draw_node (tree_view,
5041 tree_view->priv->prelight_node,
5044 tree_view->priv->event_last_x = -10000;
5045 tree_view->priv->event_last_y = -10000;
5047 prelight_or_select (tree_view,
5049 -1000, -1000); /* coords not possibly over an arrow */
5056 pspp_sheet_view_focus_out (GtkWidget *widget,
5057 GdkEventFocus *event)
5059 PsppSheetView *tree_view;
5061 tree_view = PSPP_SHEET_VIEW (widget);
5063 gtk_widget_queue_draw (widget);
5065 /* destroy interactive search dialog */
5066 if (tree_view->priv->search_window)
5067 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
5073 /* Incremental Reflow
5077 pspp_sheet_view_node_queue_redraw (PsppSheetView *tree_view,
5080 GtkAllocation allocation;
5081 gint y = pspp_sheet_view_node_find_offset (tree_view, node)
5082 - gtk_adjustment_get_value (tree_view->priv->vadjustment)
5083 + TREE_VIEW_HEADER_HEIGHT (tree_view);
5085 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
5087 gtk_widget_queue_draw_area (GTK_WIDGET (tree_view),
5090 tree_view->priv->fixed_height);
5094 node_is_visible (PsppSheetView *tree_view,
5100 y = pspp_sheet_view_node_find_offset (tree_view, node);
5101 height = ROW_HEIGHT (tree_view);
5103 if (y >= gtk_adjustment_get_value (tree_view->priv->vadjustment) &&
5104 y + height <= (gtk_adjustment_get_value (tree_view->priv->vadjustment)
5105 + gtk_adjustment_get_page_size (tree_view->priv->vadjustment)))
5111 /* Returns the row height. */
5113 validate_row (PsppSheetView *tree_view,
5118 PsppSheetViewColumn *column;
5119 GList *list, *first_column, *last_column;
5121 gint horizontal_separator;
5122 gint vertical_separator;
5123 gint focus_line_width;
5124 gboolean draw_vgrid_lines, draw_hgrid_lines;
5126 gint grid_line_width;
5127 gboolean wide_separators;
5128 gint separator_height;
5130 gtk_widget_style_get (GTK_WIDGET (tree_view),
5131 "focus-padding", &focus_pad,
5132 "focus-line-width", &focus_line_width,
5133 "horizontal-separator", &horizontal_separator,
5134 "vertical-separator", &vertical_separator,
5135 "grid-line-width", &grid_line_width,
5136 "wide-separators", &wide_separators,
5137 "separator-height", &separator_height,
5141 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
5142 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
5144 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
5145 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
5147 for (last_column = g_list_last (tree_view->priv->columns);
5148 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
5149 last_column = last_column->prev)
5152 for (first_column = g_list_first (tree_view->priv->columns);
5153 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
5154 first_column = first_column->next)
5157 for (list = tree_view->priv->columns; list; list = list->next)
5162 column = list->data;
5164 if (! column->visible)
5167 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, iter);
5168 pspp_sheet_view_column_cell_get_size (column,
5170 &tmp_width, &tmp_height);
5172 tmp_height += vertical_separator;
5173 height = MAX (height, tmp_height);
5175 tmp_width = tmp_width + horizontal_separator;
5177 if (draw_vgrid_lines)
5179 if (list->data == first_column || list->data == last_column)
5180 tmp_width += grid_line_width / 2.0;
5182 tmp_width += grid_line_width;
5185 if (tmp_width > column->requested_width)
5186 column->requested_width = tmp_width;
5189 if (draw_hgrid_lines)
5190 height += grid_line_width;
5192 tree_view->priv->post_validation_flag = TRUE;
5198 validate_visible_area (PsppSheetView *tree_view)
5200 GtkTreePath *path = NULL;
5201 GtkTreePath *above_path = NULL;
5204 gboolean size_changed = FALSE;
5206 gint area_above = 0;
5207 gint area_below = 0;
5208 GtkAllocation allocation;
5210 if (tree_view->priv->row_count == 0)
5213 if (tree_view->priv->scroll_to_path == NULL)
5216 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
5218 total_height = allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
5220 if (total_height == 0)
5223 path = gtk_tree_row_reference_get_path (tree_view->priv->scroll_to_path);
5226 /* we are going to scroll, and will update dy */
5227 _pspp_sheet_view_find_node (tree_view, path, &node);
5228 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
5230 if (tree_view->priv->scroll_to_use_align)
5232 gint height = ROW_HEIGHT (tree_view);
5233 area_above = (total_height - height) *
5234 tree_view->priv->scroll_to_row_align;
5235 area_below = total_height - area_above - height;
5236 area_above = MAX (area_above, 0);
5237 area_below = MAX (area_below, 0);
5242 * 1) row not visible
5246 gint height = ROW_HEIGHT (tree_view);
5248 dy = pspp_sheet_view_node_find_offset (tree_view, node);
5250 if (dy >= gtk_adjustment_get_value (tree_view->priv->vadjustment) &&
5251 dy + height <= (gtk_adjustment_get_value (tree_view->priv->vadjustment)
5252 + gtk_adjustment_get_page_size (tree_view->priv->vadjustment)))
5254 /* row visible: keep the row at the same position */
5255 area_above = dy - gtk_adjustment_get_value (tree_view->priv->vadjustment);
5256 area_below = (gtk_adjustment_get_value (tree_view->priv->vadjustment) +
5257 gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
5262 /* row not visible */
5264 && dy + height <= gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
5266 /* row at the beginning -- fixed */
5268 area_below = gtk_adjustment_get_page_size (tree_view->priv->vadjustment)
5269 - area_above - height;
5271 else if (dy >= (gtk_adjustment_get_upper (tree_view->priv->vadjustment) -
5272 gtk_adjustment_get_page_size (tree_view->priv->vadjustment)))
5274 /* row at the end -- fixed */
5275 area_above = dy - (gtk_adjustment_get_upper (tree_view->priv->vadjustment) -
5276 gtk_adjustment_get_page_size (tree_view->priv->vadjustment));
5277 area_below = gtk_adjustment_get_page_size (tree_view->priv->vadjustment) -
5278 area_above - height;
5282 area_above = gtk_adjustment_get_page_size (tree_view->priv->vadjustment) - height;
5288 /* row somewhere in the middle, bring it to the top
5292 area_below = total_height - height;
5298 /* the scroll to isn't valid; ignore it.
5301 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
5302 tree_view->priv->scroll_to_path = NULL;
5306 above_path = gtk_tree_path_copy (path);
5308 /* Now, we walk forwards and backwards, measuring rows. Unfortunately,
5309 * backwards is much slower then forward, as there is no iter_prev function.
5310 * We go forwards first in case we run out of tree. Then we go backwards to
5313 while (node >= 0 && area_below > 0)
5315 gboolean done = FALSE;
5318 node = pspp_sheet_view_node_next (tree_view, node);
5321 gboolean has_next = gtk_tree_model_iter_next (tree_view->priv->model, &iter);
5323 gtk_tree_path_next (path);
5326 TREE_VIEW_INTERNAL_ASSERT_VOID (has_next);
5336 area_below -= ROW_HEIGHT (tree_view);
5338 gtk_tree_path_free (path);
5340 /* If we ran out of tree, and have extra area_below left, we need to add it
5343 area_above += area_below;
5345 _pspp_sheet_view_find_node (tree_view, above_path, &node);
5347 /* We walk backwards */
5348 while (area_above > 0)
5350 node = pspp_sheet_view_node_prev (tree_view, node);
5352 /* Always find the new path in the tree. We cannot just assume
5353 * a gtk_tree_path_prev() is enough here, as there might be children
5354 * in between this node and the previous sibling node. If this
5355 * appears to be a performance hotspot in profiles, we can look into
5356 * intrigate logic for keeping path, node and iter in sync like
5357 * we do for forward walks. (Which will be hard because of the lacking
5364 gtk_tree_path_free (above_path);
5365 above_path = _pspp_sheet_view_find_path (tree_view, node);
5367 gtk_tree_model_get_iter (tree_view->priv->model, &iter, above_path);
5369 area_above -= ROW_HEIGHT (tree_view);
5372 /* set the dy here to scroll to the path,
5373 * and sync the top row accordingly
5375 pspp_sheet_view_set_top_row (tree_view, above_path, -area_above);
5376 pspp_sheet_view_top_row_to_dy (tree_view);
5378 /* update width/height and queue a resize */
5381 GtkRequisition requisition;
5383 /* We temporarily guess a size, under the assumption that it will be the
5384 * same when we get our next size_allocate. If we don't do this, we'll be
5385 * in an inconsistent state if we call top_row_to_dy. */
5387 gtk_widget_size_request (GTK_WIDGET (tree_view), &requisition);
5388 gtk_adjustment_set_upper (tree_view->priv->hadjustment, MAX (gtk_adjustment_get_upper (tree_view->priv->hadjustment), (gfloat)requisition.width));
5389 gtk_adjustment_set_upper (tree_view->priv->vadjustment, MAX (gtk_adjustment_get_upper (tree_view->priv->vadjustment), (gfloat)requisition.height));
5390 gtk_adjustment_changed (tree_view->priv->hadjustment);
5391 gtk_adjustment_changed (tree_view->priv->vadjustment);
5392 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
5395 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
5396 tree_view->priv->scroll_to_path = NULL;
5399 gtk_tree_path_free (above_path);
5401 if (tree_view->priv->scroll_to_column)
5403 tree_view->priv->scroll_to_column = NULL;
5405 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
5409 initialize_fixed_height_mode (PsppSheetView *tree_view)
5411 if (!tree_view->priv->row_count)
5414 if (tree_view->priv->fixed_height_set)
5417 if (tree_view->priv->fixed_height < 0)
5424 path = _pspp_sheet_view_find_path (tree_view, node);
5425 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
5427 tree_view->priv->fixed_height = validate_row (tree_view, node, &iter, path);
5429 gtk_tree_path_free (path);
5431 g_object_notify (G_OBJECT (tree_view), "fixed-height");
5435 /* Our strategy for finding nodes to validate is a little convoluted. We find
5436 * the left-most uninvalidated node. We then try walking right, validating
5437 * nodes. Once we find a valid node, we repeat the previous process of finding
5438 * the first invalid node.
5442 validate_rows_handler (PsppSheetView *tree_view)
5444 initialize_fixed_height_mode (tree_view);
5445 if (tree_view->priv->validate_rows_timer)
5447 g_source_remove (tree_view->priv->validate_rows_timer);
5448 tree_view->priv->validate_rows_timer = 0;
5455 do_presize_handler (PsppSheetView *tree_view)
5457 GtkRequisition requisition;
5459 validate_visible_area (tree_view);
5460 tree_view->priv->presize_handler_timer = 0;
5462 if (! gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5465 gtk_widget_size_request (GTK_WIDGET (tree_view), &requisition);
5467 gtk_adjustment_set_upper (tree_view->priv->hadjustment, MAX (gtk_adjustment_get_upper (tree_view->priv->hadjustment), (gfloat)requisition.width));
5468 gtk_adjustment_set_upper (tree_view->priv->vadjustment, MAX (gtk_adjustment_get_upper (tree_view->priv->vadjustment), (gfloat)requisition.height));
5469 gtk_adjustment_changed (tree_view->priv->hadjustment);
5470 gtk_adjustment_changed (tree_view->priv->vadjustment);
5471 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
5477 presize_handler_callback (gpointer data)
5479 do_presize_handler (PSPP_SHEET_VIEW (data));
5485 install_presize_handler (PsppSheetView *tree_view)
5487 if (! gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5490 if (! tree_view->priv->presize_handler_timer)
5492 tree_view->priv->presize_handler_timer =
5493 gdk_threads_add_idle_full (GTK_PRIORITY_RESIZE - 2, presize_handler_callback, tree_view, NULL);
5495 if (! tree_view->priv->validate_rows_timer)
5497 tree_view->priv->validate_rows_timer =
5498 gdk_threads_add_idle_full (PSPP_SHEET_VIEW_PRIORITY_VALIDATE, (GSourceFunc) validate_rows_handler, tree_view, NULL);
5503 scroll_sync_handler (PsppSheetView *tree_view)
5505 if (tree_view->priv->height <= gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
5506 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment), 0);
5507 else if (gtk_tree_row_reference_valid (tree_view->priv->top_row))
5508 pspp_sheet_view_top_row_to_dy (tree_view);
5510 pspp_sheet_view_dy_to_top_row (tree_view);
5512 tree_view->priv->scroll_sync_timer = 0;
5518 install_scroll_sync_handler (PsppSheetView *tree_view)
5520 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5523 if (!tree_view->priv->scroll_sync_timer)
5525 tree_view->priv->scroll_sync_timer =
5526 gdk_threads_add_idle_full (PSPP_SHEET_VIEW_PRIORITY_SCROLL_SYNC, (GSourceFunc) scroll_sync_handler, tree_view, NULL);
5531 pspp_sheet_view_set_top_row (PsppSheetView *tree_view,
5535 gtk_tree_row_reference_free (tree_view->priv->top_row);
5539 tree_view->priv->top_row = NULL;
5540 tree_view->priv->top_row_dy = 0;
5544 tree_view->priv->top_row = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
5545 tree_view->priv->top_row_dy = offset;
5549 /* Always call this iff dy is in the visible range. If the tree is empty, then
5550 * it's set to be NULL, and top_row_dy is 0;
5553 pspp_sheet_view_dy_to_top_row (PsppSheetView *tree_view)
5559 if (tree_view->priv->row_count == 0)
5561 pspp_sheet_view_set_top_row (tree_view, NULL, 0);
5565 offset = pspp_sheet_view_find_offset (tree_view,
5566 tree_view->priv->dy,
5571 pspp_sheet_view_set_top_row (tree_view, NULL, 0);
5575 path = _pspp_sheet_view_find_path (tree_view, node);
5576 pspp_sheet_view_set_top_row (tree_view, path, offset);
5577 gtk_tree_path_free (path);
5583 pspp_sheet_view_top_row_to_dy (PsppSheetView *tree_view)
5589 /* Avoid recursive calls */
5590 if (tree_view->priv->in_top_row_to_dy)
5593 if (tree_view->priv->top_row)
5594 path = gtk_tree_row_reference_get_path (tree_view->priv->top_row);
5601 _pspp_sheet_view_find_node (tree_view, path, &node);
5604 gtk_tree_path_free (path);
5608 /* keep dy and set new toprow */
5609 gtk_tree_row_reference_free (tree_view->priv->top_row);
5610 tree_view->priv->top_row = NULL;
5611 tree_view->priv->top_row_dy = 0;
5612 /* DO NOT install the idle handler */
5613 pspp_sheet_view_dy_to_top_row (tree_view);
5617 if (ROW_HEIGHT (tree_view) < tree_view->priv->top_row_dy)
5619 /* new top row -- do NOT install the idle handler */
5620 pspp_sheet_view_dy_to_top_row (tree_view);
5624 new_dy = pspp_sheet_view_node_find_offset (tree_view, node);
5625 new_dy += tree_view->priv->top_row_dy;
5627 if (new_dy + gtk_adjustment_get_page_size (tree_view->priv->vadjustment) > tree_view->priv->height)
5628 new_dy = tree_view->priv->height - gtk_adjustment_get_page_size (tree_view->priv->vadjustment);
5630 new_dy = MAX (0, new_dy);
5632 tree_view->priv->in_top_row_to_dy = TRUE;
5633 gtk_adjustment_set_value (tree_view->priv->vadjustment, (gdouble)new_dy);
5634 tree_view->priv->in_top_row_to_dy = FALSE;
5639 _pspp_sheet_view_install_mark_rows_col_dirty (PsppSheetView *tree_view)
5641 install_presize_handler (tree_view);
5647 set_source_row (GdkDragContext *context,
5648 GtkTreeModel *model,
5649 GtkTreePath *source_row)
5651 g_object_set_data_full (G_OBJECT (context),
5652 "gtk-tree-view-source-row",
5653 source_row ? gtk_tree_row_reference_new (model, source_row) : NULL,
5654 (GDestroyNotify) (source_row ? gtk_tree_row_reference_free : NULL));
5658 get_source_row (GdkDragContext *context)
5660 GtkTreeRowReference *ref =
5661 g_object_get_data (G_OBJECT (context), "gtk-tree-view-source-row");
5664 return gtk_tree_row_reference_get_path (ref);
5671 GtkTreeRowReference *dest_row;
5672 guint path_down_mode : 1;
5673 guint empty_view_drop : 1;
5674 guint drop_append_mode : 1;
5679 dest_row_free (gpointer data)
5681 DestRow *dr = (DestRow *)data;
5683 gtk_tree_row_reference_free (dr->dest_row);
5684 g_slice_free (DestRow, dr);
5688 set_dest_row (GdkDragContext *context,
5689 GtkTreeModel *model,
5690 GtkTreePath *dest_row,
5691 gboolean path_down_mode,
5692 gboolean empty_view_drop,
5693 gboolean drop_append_mode)
5699 g_object_set_data_full (G_OBJECT (context), "gtk-tree-view-dest-row",
5704 dr = g_slice_new (DestRow);
5706 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5707 dr->path_down_mode = path_down_mode != FALSE;
5708 dr->empty_view_drop = empty_view_drop != FALSE;
5709 dr->drop_append_mode = drop_append_mode != FALSE;
5711 g_object_set_data_full (G_OBJECT (context), "gtk-tree-view-dest-row",
5712 dr, (GDestroyNotify) dest_row_free);
5716 get_dest_row (GdkDragContext *context,
5717 gboolean *path_down_mode)
5720 g_object_get_data (G_OBJECT (context), "gtk-tree-view-dest-row");
5724 GtkTreePath *path = NULL;
5727 *path_down_mode = dr->path_down_mode;
5730 path = gtk_tree_row_reference_get_path (dr->dest_row);
5731 else if (dr->empty_view_drop)
5732 path = gtk_tree_path_new_from_indices (0, -1);
5736 if (path && dr->drop_append_mode)
5737 gtk_tree_path_next (path);
5745 /* Get/set whether drag_motion requested the drag data and
5746 * drag_data_received should thus not actually insert the data,
5747 * since the data doesn't result from a drop.
5750 set_status_pending (GdkDragContext *context,
5751 GdkDragAction suggested_action)
5753 g_object_set_data (G_OBJECT (context),
5754 "gtk-tree-view-status-pending",
5755 GINT_TO_POINTER (suggested_action));
5758 static GdkDragAction
5759 get_status_pending (GdkDragContext *context)
5761 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5762 "gtk-tree-view-status-pending"));
5765 static TreeViewDragInfo*
5766 get_info (PsppSheetView *tree_view)
5768 return g_object_get_data (G_OBJECT (tree_view), "gtk-tree-view-drag-info");
5772 destroy_info (TreeViewDragInfo *di)
5774 g_slice_free (TreeViewDragInfo, di);
5777 static TreeViewDragInfo*
5778 ensure_info (PsppSheetView *tree_view)
5780 TreeViewDragInfo *di;
5782 di = get_info (tree_view);
5786 di = g_slice_new0 (TreeViewDragInfo);
5788 g_object_set_data_full (G_OBJECT (tree_view),
5789 "gtk-tree-view-drag-info",
5791 (GDestroyNotify) destroy_info);
5798 remove_info (PsppSheetView *tree_view)
5800 g_object_set_data (G_OBJECT (tree_view), "gtk-tree-view-drag-info", NULL);
5805 drag_scan_timeout (gpointer data)
5807 PsppSheetView *tree_view;
5809 GdkModifierType state;
5810 GtkTreePath *path = NULL;
5811 PsppSheetViewColumn *column = NULL;
5812 GdkRectangle visible_rect;
5814 GDK_THREADS_ENTER ();
5816 tree_view = PSPP_SHEET_VIEW (data);
5818 gdk_window_get_pointer (tree_view->priv->bin_window,
5821 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
5823 /* See if we are near the edge. */
5824 if ((x - visible_rect.x) < SCROLL_EDGE_SIZE ||
5825 (visible_rect.x + visible_rect.width - x) < SCROLL_EDGE_SIZE ||
5826 (y - visible_rect.y) < SCROLL_EDGE_SIZE ||
5827 (visible_rect.y + visible_rect.height - y) < SCROLL_EDGE_SIZE)
5829 pspp_sheet_view_get_path_at_pos (tree_view,
5830 tree_view->priv->bin_window,
5839 pspp_sheet_view_scroll_to_cell (tree_view,
5845 gtk_tree_path_free (path);
5849 GDK_THREADS_LEAVE ();
5856 add_scroll_timeout (PsppSheetView *tree_view)
5858 if (tree_view->priv->scroll_timeout == 0)
5860 tree_view->priv->scroll_timeout =
5861 gdk_threads_add_timeout (150, scroll_row_timeout, tree_view);
5866 remove_scroll_timeout (PsppSheetView *tree_view)
5868 if (tree_view->priv->scroll_timeout != 0)
5870 g_source_remove (tree_view->priv->scroll_timeout);
5871 tree_view->priv->scroll_timeout = 0;
5876 check_model_dnd (GtkTreeModel *model,
5877 GType required_iface,
5878 const gchar *signal)
5880 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5882 g_warning ("You must override the default '%s' handler "
5883 "on PsppSheetView when using models that don't support "
5884 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5885 "is to connect to '%s' and call "
5886 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5887 "the default handler from running. Look at the source code "
5888 "for the default handler in gtktreeview.c to get an idea what "
5889 "your handler should do. (gtktreeview.c is in the GTK source "
5890 "code.) If you're using GTK from a language other than C, "
5891 "there may be a more natural way to override default handlers, e.g. via derivation.",
5892 signal, g_type_name (required_iface), signal);
5900 scroll_row_timeout (gpointer data)
5902 PsppSheetView *tree_view = data;
5904 pspp_sheet_view_horizontal_autoscroll (tree_view);
5905 pspp_sheet_view_vertical_autoscroll (tree_view);
5907 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
5908 pspp_sheet_view_update_rubber_band (tree_view);
5913 /* Returns TRUE if event should not be propagated to parent widgets */
5915 set_destination_row (PsppSheetView *tree_view,
5916 GdkDragContext *context,
5917 /* coordinates relative to the widget */
5920 GdkDragAction *suggested_action,
5923 GtkTreePath *path = NULL;
5924 PsppSheetViewDropPosition pos;
5925 PsppSheetViewDropPosition old_pos;
5926 TreeViewDragInfo *di;
5928 GtkTreePath *old_dest_path = NULL;
5929 gboolean can_drop = FALSE;
5931 *suggested_action = 0;
5934 widget = GTK_WIDGET (tree_view);
5936 di = get_info (tree_view);
5938 if (di == NULL || y - TREE_VIEW_HEADER_HEIGHT (tree_view) < 0)
5940 /* someone unset us as a drag dest, note that if
5941 * we return FALSE drag_leave isn't called
5944 pspp_sheet_view_set_drag_dest_row (tree_view,
5946 PSPP_SHEET_VIEW_DROP_BEFORE);
5948 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
5950 return FALSE; /* no longer a drop site */
5953 *target = gtk_drag_dest_find_target (widget, context,
5954 gtk_drag_dest_get_target_list (widget));
5955 if (*target == GDK_NONE)
5960 if (!pspp_sheet_view_get_dest_row_at_pos (tree_view,
5966 GtkTreeModel *model;
5968 /* the row got dropped on empty space, let's setup a special case
5972 gtk_tree_path_free (path);
5974 model = pspp_sheet_view_get_model (tree_view);
5976 n_children = gtk_tree_model_iter_n_children (model, NULL);
5979 pos = PSPP_SHEET_VIEW_DROP_AFTER;
5980 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
5984 pos = PSPP_SHEET_VIEW_DROP_BEFORE;
5985 path = gtk_tree_path_new_from_indices (0, -1);
5995 /* If we left the current row's "open" zone, unset the timeout for
5998 pspp_sheet_view_get_drag_dest_row (tree_view,
6003 gtk_tree_path_free (old_dest_path);
6005 if (TRUE /* FIXME if the location droppable predicate */)
6013 GtkWidget *source_widget;
6015 *suggested_action = gdk_drag_context_get_suggested_action (context);
6016 source_widget = gtk_drag_get_source_widget (context);
6018 if (source_widget == widget)
6020 /* Default to MOVE, unless the user has
6021 * pressed ctrl or shift to affect available actions
6023 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
6024 *suggested_action = GDK_ACTION_MOVE;
6027 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6032 /* can't drop here */
6033 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6035 PSPP_SHEET_VIEW_DROP_BEFORE);
6039 gtk_tree_path_free (path);
6045 get_logical_dest_row (PsppSheetView *tree_view,
6046 gboolean *path_down_mode,
6047 gboolean *drop_append_mode)
6049 /* adjust path to point to the row the drop goes in front of */
6050 GtkTreePath *path = NULL;
6051 PsppSheetViewDropPosition pos;
6053 g_return_val_if_fail (path_down_mode != NULL, NULL);
6054 g_return_val_if_fail (drop_append_mode != NULL, NULL);
6056 *path_down_mode = FALSE;
6057 *drop_append_mode = 0;
6059 pspp_sheet_view_get_drag_dest_row (tree_view, &path, &pos);
6064 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE)
6066 else if (pos == PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE ||
6067 pos == PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER)
6068 *path_down_mode = TRUE;
6072 GtkTreeModel *model = pspp_sheet_view_get_model (tree_view);
6074 g_assert (pos == PSPP_SHEET_VIEW_DROP_AFTER);
6076 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6077 !gtk_tree_model_iter_next (model, &iter))
6078 *drop_append_mode = 1;
6081 *drop_append_mode = 0;
6082 gtk_tree_path_next (path);
6090 pspp_sheet_view_maybe_begin_dragging_row (PsppSheetView *tree_view,
6091 GdkEventMotion *event)
6093 GtkWidget *widget = GTK_WIDGET (tree_view);
6094 GdkDragContext *context;
6095 TreeViewDragInfo *di;
6096 GtkTreePath *path = NULL;
6098 gint cell_x, cell_y;
6099 GtkTreeModel *model;
6100 gboolean retval = FALSE;
6102 di = get_info (tree_view);
6104 if (di == NULL || !di->source_set)
6107 if (tree_view->priv->pressed_button < 0)
6110 if (!gtk_drag_check_threshold (widget,
6111 tree_view->priv->press_start_x,
6112 tree_view->priv->press_start_y,
6113 event->x, event->y))
6116 model = pspp_sheet_view_get_model (tree_view);
6121 button = tree_view->priv->pressed_button;
6122 tree_view->priv->pressed_button = -1;
6124 pspp_sheet_view_get_path_at_pos (tree_view,
6125 tree_view->priv->press_start_x,
6126 tree_view->priv->press_start_y,
6135 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6136 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6140 if (!(GDK_BUTTON1_MASK << (button - 1) & di->start_button_mask))
6143 /* Now we can begin the drag */
6147 context = gtk_drag_begin (widget,
6148 gtk_drag_source_get_target_list (widget),
6153 set_source_row (context, model, path);
6157 gtk_tree_path_free (path);
6165 pspp_sheet_view_drag_begin (GtkWidget *widget,
6166 GdkDragContext *context)
6169 PsppSheetView *tree_view;
6170 GtkTreePath *path = NULL;
6171 gint cell_x, cell_y;
6173 TreeViewDragInfo *di;
6175 tree_view = PSPP_SHEET_VIEW (widget);
6177 /* if the user uses a custom DND source impl, we don't set the icon here */
6178 di = get_info (tree_view);
6180 if (di == NULL || !di->source_set)
6183 pspp_sheet_view_get_path_at_pos (tree_view,
6184 tree_view->priv->press_start_x,
6185 tree_view->priv->press_start_y,
6191 g_return_if_fail (path != NULL);
6193 row_pix = pspp_sheet_view_create_row_drag_icon (tree_view,
6196 gtk_drag_set_icon_pixmap (context,
6197 gdk_drawable_get_colormap (row_pix),
6200 /* the + 1 is for the black border in the icon */
6201 tree_view->priv->press_start_x + 1,
6204 g_object_unref (row_pix);
6205 gtk_tree_path_free (path);
6211 pspp_sheet_view_drag_end (GtkWidget *widget,
6212 GdkDragContext *context)
6217 /* Default signal implementations for the drag signals */
6219 pspp_sheet_view_drag_data_get (GtkWidget *widget,
6220 GdkDragContext *context,
6221 GtkSelectionData *selection_data,
6225 PsppSheetView *tree_view;
6226 GtkTreeModel *model;
6227 TreeViewDragInfo *di;
6228 GtkTreePath *source_row;
6230 tree_view = PSPP_SHEET_VIEW (widget);
6232 model = pspp_sheet_view_get_model (tree_view);
6237 di = get_info (PSPP_SHEET_VIEW (widget));
6242 source_row = get_source_row (context);
6244 if (source_row == NULL)
6247 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6248 * any model; for DragSource models there are some other targets
6252 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6253 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6258 /* If drag_data_get does nothing, try providing row data. */
6259 if (gtk_selection_data_get_target (selection_data) == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6261 gtk_tree_set_row_drag_data (selection_data,
6267 gtk_tree_path_free (source_row);
6272 pspp_sheet_view_drag_data_delete (GtkWidget *widget,
6273 GdkDragContext *context)
6275 TreeViewDragInfo *di;
6276 GtkTreeModel *model;
6277 PsppSheetView *tree_view;
6278 GtkTreePath *source_row;
6280 tree_view = PSPP_SHEET_VIEW (widget);
6281 model = pspp_sheet_view_get_model (tree_view);
6283 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
6286 di = get_info (tree_view);
6291 source_row = get_source_row (context);
6293 if (source_row == NULL)
6296 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6299 gtk_tree_path_free (source_row);
6301 set_source_row (context, NULL, NULL);
6305 pspp_sheet_view_drag_leave (GtkWidget *widget,
6306 GdkDragContext *context,
6309 /* unset any highlight row */
6310 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6312 PSPP_SHEET_VIEW_DROP_BEFORE);
6314 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6319 pspp_sheet_view_drag_motion (GtkWidget *widget,
6320 GdkDragContext *context,
6321 /* coordinates relative to the widget */
6327 GtkTreePath *path = NULL;
6328 PsppSheetViewDropPosition pos;
6329 PsppSheetView *tree_view;
6330 GdkDragAction suggested_action = 0;
6333 tree_view = PSPP_SHEET_VIEW (widget);
6335 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6338 pspp_sheet_view_get_drag_dest_row (tree_view, &path, &pos);
6340 /* we only know this *after* set_desination_row */
6341 empty = tree_view->priv->empty_view_drop;
6343 if (path == NULL && !empty)
6345 /* Can't drop here. */
6346 gdk_drag_status (context, 0, time);
6350 if (tree_view->priv->open_dest_timeout == 0 &&
6351 (pos == PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER ||
6352 pos == PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE))
6358 add_scroll_timeout (tree_view);
6361 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6363 /* Request data so we can use the source row when
6364 * determining whether to accept the drop
6366 set_status_pending (context, suggested_action);
6367 gtk_drag_get_data (widget, context, target, time);
6371 set_status_pending (context, 0);
6372 gdk_drag_status (context, suggested_action, time);
6377 gtk_tree_path_free (path);
6384 pspp_sheet_view_drag_drop (GtkWidget *widget,
6385 GdkDragContext *context,
6386 /* coordinates relative to the widget */
6391 PsppSheetView *tree_view;
6393 GdkDragAction suggested_action = 0;
6394 GdkAtom target = GDK_NONE;
6395 TreeViewDragInfo *di;
6396 GtkTreeModel *model;
6397 gboolean path_down_mode;
6398 gboolean drop_append_mode;
6400 tree_view = PSPP_SHEET_VIEW (widget);
6402 model = pspp_sheet_view_get_model (tree_view);
6404 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6406 di = get_info (tree_view);
6411 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
6414 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6417 path = get_logical_dest_row (tree_view, &path_down_mode, &drop_append_mode);
6419 if (target != GDK_NONE && path != NULL)
6421 /* in case a motion had requested drag data, change things so we
6422 * treat drag data receives as a drop.
6424 set_status_pending (context, 0);
6425 set_dest_row (context, model, path,
6426 path_down_mode, tree_view->priv->empty_view_drop,
6431 gtk_tree_path_free (path);
6433 /* Unset this thing */
6434 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6436 PSPP_SHEET_VIEW_DROP_BEFORE);
6438 if (target != GDK_NONE)
6440 gtk_drag_get_data (widget, context, target, time);
6448 pspp_sheet_view_drag_data_received (GtkWidget *widget,
6449 GdkDragContext *context,
6450 /* coordinates relative to the widget */
6453 GtkSelectionData *selection_data,
6458 TreeViewDragInfo *di;
6459 gboolean accepted = FALSE;
6460 GtkTreeModel *model;
6461 PsppSheetView *tree_view;
6462 GtkTreePath *dest_row;
6463 GdkDragAction suggested_action;
6464 gboolean path_down_mode;
6465 gboolean drop_append_mode;
6467 tree_view = PSPP_SHEET_VIEW (widget);
6469 model = pspp_sheet_view_get_model (tree_view);
6471 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_data_received"))
6474 di = get_info (tree_view);
6479 suggested_action = get_status_pending (context);
6481 if (suggested_action)
6483 /* We are getting this data due to a request in drag_motion,
6484 * rather than due to a request in drag_drop, so we are just
6485 * supposed to call drag_status, not actually paste in the
6488 path = get_logical_dest_row (tree_view, &path_down_mode,
6492 suggested_action = 0;
6493 else if (path_down_mode)
6494 gtk_tree_path_down (path);
6496 if (suggested_action)
6498 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6504 path_down_mode = FALSE;
6505 gtk_tree_path_up (path);
6507 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6510 suggested_action = 0;
6513 suggested_action = 0;
6517 gdk_drag_status (context, suggested_action, time);
6520 gtk_tree_path_free (path);
6522 /* If you can't drop, remove user drop indicator until the next motion */
6523 if (suggested_action == 0)
6524 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6526 PSPP_SHEET_VIEW_DROP_BEFORE);
6531 dest_row = get_dest_row (context, &path_down_mode);
6533 if (dest_row == NULL)
6536 if (gtk_selection_data_get_length (selection_data) >= 0)
6540 gtk_tree_path_down (dest_row);
6541 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6542 dest_row, selection_data))
6543 gtk_tree_path_up (dest_row);
6547 if (gtk_selection_data_get_length (selection_data) >= 0)
6549 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6555 gtk_drag_finish (context,
6557 (gdk_drag_context_get_actions (context) == GDK_ACTION_MOVE),
6560 if (gtk_tree_path_get_depth (dest_row) == 1
6561 && gtk_tree_path_get_indices (dest_row)[0] == 0)
6563 /* special special case drag to "0", scroll to first item */
6564 if (!tree_view->priv->scroll_to_path)
6565 pspp_sheet_view_scroll_to_cell (tree_view, dest_row, NULL, FALSE, 0.0, 0.0);
6568 gtk_tree_path_free (dest_row);
6571 set_dest_row (context, NULL, NULL, FALSE, FALSE, FALSE);
6576 /* GtkContainer Methods
6581 pspp_sheet_view_remove (GtkContainer *container,
6584 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6585 PsppSheetViewChild *child = NULL;
6588 tmp_list = tree_view->priv->children;
6591 child = tmp_list->data;
6592 if (child->widget == widget)
6594 gtk_widget_unparent (widget);
6596 tree_view->priv->children = g_list_remove_link (tree_view->priv->children, tmp_list);
6597 g_list_free_1 (tmp_list);
6598 g_slice_free (PsppSheetViewChild, child);
6602 tmp_list = tmp_list->next;
6605 tmp_list = tree_view->priv->columns;
6609 PsppSheetViewColumn *column;
6610 column = tmp_list->data;
6611 if (column->button == widget)
6613 gtk_widget_unparent (widget);
6616 tmp_list = tmp_list->next;
6621 pspp_sheet_view_forall (GtkContainer *container,
6622 gboolean include_internals,
6623 GtkCallback callback,
6624 gpointer callback_data)
6626 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6627 PsppSheetViewChild *child = NULL;
6628 PsppSheetViewColumn *column;
6631 tmp_list = tree_view->priv->children;
6634 child = tmp_list->data;
6635 tmp_list = tmp_list->next;
6637 (* callback) (child->widget, callback_data);
6639 if (include_internals == FALSE)
6642 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6644 column = tmp_list->data;
6647 (* callback) (column->button, callback_data);
6651 /* Returns TRUE if the treeview contains no "special" (editable or activatable)
6652 * cells. If so we draw one big row-spanning focus rectangle.
6655 pspp_sheet_view_has_special_cell (PsppSheetView *tree_view)
6659 if (tree_view->priv->special_cells != PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT)
6660 return tree_view->priv->special_cells = PSPP_SHEET_VIEW_SPECIAL_CELLS_YES;
6662 for (list = tree_view->priv->columns; list; list = list->next)
6664 if (!((PsppSheetViewColumn *)list->data)->visible)
6666 if (_pspp_sheet_view_column_count_special_cells (list->data))
6674 pspp_sheet_view_focus_column (PsppSheetView *tree_view,
6675 PsppSheetViewColumn *focus_column,
6676 gboolean clamp_column_visible)
6678 g_return_if_fail (focus_column != NULL);
6680 tree_view->priv->focus_column = focus_column;
6681 if (!focus_column->button)
6683 pspp_sheet_view_column_set_need_button (focus_column, TRUE);
6684 // g_return_if_fail (focus_column->button != NULL);
6685 if (focus_column->button == NULL)
6689 if (gtk_container_get_focus_child (GTK_CONTAINER (tree_view)) != focus_column->button)
6690 gtk_widget_grab_focus (focus_column->button);
6692 if (clamp_column_visible)
6693 pspp_sheet_view_clamp_column_visible (tree_view, focus_column, FALSE);
6696 /* Returns TRUE if the focus is within the headers, after the focus operation is
6700 pspp_sheet_view_header_focus (PsppSheetView *tree_view,
6701 GtkDirectionType dir,
6702 gboolean clamp_column_visible)
6704 GtkWidget *focus_child;
6705 PsppSheetViewColumn *focus_column;
6706 GList *last_column, *first_column;
6710 if (! PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
6713 focus_child = gtk_container_get_focus_child (GTK_CONTAINER (tree_view));
6715 first_column = tree_view->priv->columns;
6716 while (first_column)
6718 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (first_column->data);
6720 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6722 first_column = first_column->next;
6725 /* No headers are visible, or are focusable. We can't focus in or out.
6727 if (first_column == NULL)
6730 last_column = g_list_last (tree_view->priv->columns);
6733 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (last_column->data);
6735 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6737 last_column = last_column->prev;
6741 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
6745 case GTK_DIR_TAB_BACKWARD:
6746 case GTK_DIR_TAB_FORWARD:
6749 if (focus_child == NULL)
6751 if (tree_view->priv->focus_column != NULL &&
6752 pspp_sheet_view_column_can_focus (tree_view->priv->focus_column))
6753 focus_column = tree_view->priv->focus_column;
6755 focus_column = first_column->data;
6756 pspp_sheet_view_focus_column (tree_view, focus_column,
6757 clamp_column_visible);
6764 if (focus_child == NULL)
6766 if (tree_view->priv->focus_column != NULL)
6767 focus_column = tree_view->priv->focus_column;
6768 else if (dir == GTK_DIR_LEFT)
6769 focus_column = last_column->data;
6771 focus_column = first_column->data;
6772 pspp_sheet_view_focus_column (tree_view, focus_column,
6773 clamp_column_visible);
6777 if (gtk_widget_child_focus (focus_child, dir))
6779 /* The focus moves inside the button. */
6780 /* This is probably a great example of bad UI */
6781 if (clamp_column_visible)
6782 pspp_sheet_view_clamp_column_visible (tree_view,
6783 tree_view->priv->focus_column,
6788 /* We need to move the focus among the row of buttons. */
6789 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6790 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)->button == focus_child)
6793 if ((tmp_list == first_column && dir == (rtl ? GTK_DIR_RIGHT : GTK_DIR_LEFT))
6794 || (tmp_list == last_column && dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT)))
6796 gtk_widget_error_bell (GTK_WIDGET (tree_view));
6802 PsppSheetViewColumn *column;
6804 if (dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT))
6805 tmp_list = tmp_list->next;
6807 tmp_list = tmp_list->prev;
6809 if (tmp_list == NULL)
6811 g_warning ("Internal button not found");
6814 column = tmp_list->data;
6815 if (column->visible &&
6816 pspp_sheet_view_column_can_focus (column))
6818 pspp_sheet_view_column_set_need_button (column, TRUE);
6821 pspp_sheet_view_focus_column (tree_view, column,
6822 clamp_column_visible);
6830 g_assert_not_reached ();
6837 /* This function returns in 'path' the first focusable path, if the given path
6838 * is already focusable, it's the returned one.
6842 search_first_focusable_path (PsppSheetView *tree_view,
6844 gboolean search_forward,
6847 /* XXX this function is trivial given that the sheetview doesn't support
6851 if (!path || !*path)
6854 _pspp_sheet_view_find_node (tree_view, *path, &node);
6862 return (*path != NULL);
6866 pspp_sheet_view_focus (GtkWidget *widget,
6867 GtkDirectionType direction)
6869 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6870 GtkContainer *container = GTK_CONTAINER (widget);
6871 GtkWidget *focus_child;
6873 if (!gtk_widget_is_sensitive (widget) || !gtk_widget_get_can_focus (widget))
6876 focus_child = gtk_container_get_focus_child (container);
6878 pspp_sheet_view_stop_editing (PSPP_SHEET_VIEW (widget), FALSE);
6879 /* Case 1. Headers currently have focus. */
6886 pspp_sheet_view_header_focus (tree_view, direction, TRUE);
6888 case GTK_DIR_TAB_BACKWARD:
6891 case GTK_DIR_TAB_FORWARD:
6893 gtk_widget_grab_focus (widget);
6896 g_assert_not_reached ();
6901 /* Case 2. We don't have focus at all. */
6902 if (!gtk_widget_has_focus (widget))
6904 if (!pspp_sheet_view_header_focus (tree_view, direction, FALSE))
6905 gtk_widget_grab_focus (widget);
6909 /* Case 3. We have focus already. */
6910 if (direction == GTK_DIR_TAB_BACKWARD)
6911 return (pspp_sheet_view_header_focus (tree_view, direction, FALSE));
6912 else if (direction == GTK_DIR_TAB_FORWARD)
6915 /* Other directions caught by the keybindings */
6916 gtk_widget_grab_focus (widget);
6921 pspp_sheet_view_grab_focus (GtkWidget *widget)
6923 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->grab_focus (widget);
6925 pspp_sheet_view_focus_to_cursor (PSPP_SHEET_VIEW (widget));
6929 pspp_sheet_view_style_set (GtkWidget *widget,
6930 GtkStyle *previous_style)
6932 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6934 PsppSheetViewColumn *column;
6936 if (gtk_widget_get_realized (widget))
6938 gdk_window_set_background (tree_view->priv->bin_window, >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
6939 gtk_style_set_background (gtk_widget_get_style (widget), tree_view->priv->header_window, GTK_STATE_NORMAL);
6940 pspp_sheet_view_set_grid_lines (tree_view, tree_view->priv->grid_lines);
6943 gtk_widget_style_get (widget,
6944 "expander-size", &tree_view->priv->expander_size,
6946 tree_view->priv->expander_size += EXPANDER_EXTRA_PADDING;
6948 for (list = tree_view->priv->columns; list; list = list->next)
6950 column = list->data;
6951 _pspp_sheet_view_column_cell_set_dirty (column);
6954 tree_view->priv->fixed_height = -1;
6956 /* Invalidate cached button style. */
6957 if (tree_view->priv->button_style)
6959 g_object_unref (tree_view->priv->button_style);
6960 tree_view->priv->button_style = NULL;
6963 gtk_widget_queue_resize (widget);
6968 pspp_sheet_view_set_focus_child (GtkContainer *container,
6971 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6974 for (list = tree_view->priv->columns; list; list = list->next)
6976 if (PSPP_SHEET_VIEW_COLUMN (list->data)->button == child)
6978 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
6983 GTK_CONTAINER_CLASS (pspp_sheet_view_parent_class)->set_focus_child (container, child);
6987 pspp_sheet_view_set_adjustments (PsppSheetView *tree_view,
6988 GtkAdjustment *hadj,
6989 GtkAdjustment *vadj)
6991 gboolean need_adjust = FALSE;
6993 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
6996 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
6998 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
7000 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
7002 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
7004 if (tree_view->priv->hadjustment && (tree_view->priv->hadjustment != hadj))
7006 g_signal_handlers_disconnect_by_func (tree_view->priv->hadjustment,
7007 pspp_sheet_view_adjustment_changed,
7009 g_object_unref (tree_view->priv->hadjustment);
7012 if (tree_view->priv->vadjustment && (tree_view->priv->vadjustment != vadj))
7014 g_signal_handlers_disconnect_by_func (tree_view->priv->vadjustment,
7015 pspp_sheet_view_adjustment_changed,
7017 g_object_unref (tree_view->priv->vadjustment);
7020 if (tree_view->priv->hadjustment != hadj)
7022 tree_view->priv->hadjustment = hadj;
7023 g_object_ref_sink (tree_view->priv->hadjustment);
7025 g_signal_connect (tree_view->priv->hadjustment, "value-changed",
7026 G_CALLBACK (pspp_sheet_view_adjustment_changed),
7031 if (tree_view->priv->vadjustment != vadj)
7033 tree_view->priv->vadjustment = vadj;
7034 g_object_ref_sink (tree_view->priv->vadjustment);
7036 g_signal_connect (tree_view->priv->vadjustment, "value-changed",
7037 G_CALLBACK (pspp_sheet_view_adjustment_changed),
7043 pspp_sheet_view_adjustment_changed (NULL, tree_view);
7048 pspp_sheet_view_real_move_cursor (PsppSheetView *tree_view,
7049 GtkMovementStep step,
7052 PsppSheetSelectMode mode;
7053 GdkModifierType state;
7055 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
7056 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
7057 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
7058 step == GTK_MOVEMENT_DISPLAY_LINES ||
7059 step == GTK_MOVEMENT_PAGES ||
7060 step == GTK_MOVEMENT_BUFFER_ENDS ||
7061 step == GTK_MOVEMENT_DISPLAY_LINE_ENDS, FALSE);
7063 if (tree_view->priv->row_count == 0)
7065 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7068 pspp_sheet_view_stop_editing (tree_view, FALSE);
7069 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
7070 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7073 if (gtk_get_current_event_state (&state))
7075 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
7076 mode |= PSPP_SHEET_SELECT_MODE_TOGGLE;
7077 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
7078 mode |= PSPP_SHEET_SELECT_MODE_EXTEND;
7080 /* else we assume not pressed */
7084 case GTK_MOVEMENT_LOGICAL_POSITIONS:
7085 pspp_sheet_view_move_cursor_tab (tree_view, count);
7087 case GTK_MOVEMENT_VISUAL_POSITIONS:
7088 pspp_sheet_view_move_cursor_left_right (tree_view, count, mode);
7090 case GTK_MOVEMENT_DISPLAY_LINES:
7091 pspp_sheet_view_move_cursor_up_down (tree_view, count, mode);
7093 case GTK_MOVEMENT_PAGES:
7094 pspp_sheet_view_move_cursor_page_up_down (tree_view, count, mode);
7096 case GTK_MOVEMENT_BUFFER_ENDS:
7097 pspp_sheet_view_move_cursor_start_end (tree_view, count, mode);
7099 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
7100 pspp_sheet_view_move_cursor_line_start_end (tree_view, count, mode);
7103 g_assert_not_reached ();
7110 pspp_sheet_view_put (PsppSheetView *tree_view,
7111 GtkWidget *child_widget,
7112 /* in bin_window coordinates */
7118 PsppSheetViewChild *child;
7120 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
7121 g_return_if_fail (GTK_IS_WIDGET (child_widget));
7123 child = g_slice_new (PsppSheetViewChild);
7125 child->widget = child_widget;
7128 child->width = width;
7129 child->height = height;
7131 tree_view->priv->children = g_list_append (tree_view->priv->children, child);
7133 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7134 gtk_widget_set_parent_window (child->widget, tree_view->priv->bin_window);
7136 gtk_widget_set_parent (child_widget, GTK_WIDGET (tree_view));
7140 _pspp_sheet_view_child_move_resize (PsppSheetView *tree_view,
7142 /* in tree coordinates */
7148 PsppSheetViewChild *child = NULL;
7150 GdkRectangle allocation;
7152 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
7153 g_return_if_fail (GTK_IS_WIDGET (widget));
7155 for (list = tree_view->priv->children; list; list = list->next)
7157 if (((PsppSheetViewChild *)list->data)->widget == widget)
7166 allocation.x = child->x = x;
7167 allocation.y = child->y = y;
7168 allocation.width = child->width = width;
7169 allocation.height = child->height = height;
7171 if (gtk_widget_get_realized (widget))
7172 gtk_widget_size_allocate (widget, &allocation);
7176 /* TreeModel Callbacks
7180 pspp_sheet_view_row_changed (GtkTreeModel *model,
7185 PsppSheetView *tree_view = (PsppSheetView *)data;
7187 gboolean free_path = FALSE;
7188 GtkTreePath *cursor_path;
7190 g_return_if_fail (path != NULL || iter != NULL);
7192 if (tree_view->priv->cursor != NULL)
7193 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7197 if (tree_view->priv->edited_column &&
7198 (cursor_path == NULL || gtk_tree_path_compare (cursor_path, path) == 0))
7199 pspp_sheet_view_stop_editing (tree_view, TRUE);
7201 if (cursor_path != NULL)
7202 gtk_tree_path_free (cursor_path);
7206 path = gtk_tree_model_get_path (model, iter);
7209 else if (iter == NULL)
7210 gtk_tree_model_get_iter (model, iter, path);
7212 _pspp_sheet_view_find_node (tree_view,
7218 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7219 pspp_sheet_view_node_queue_redraw (tree_view, node);
7223 gtk_tree_path_free (path);
7227 pspp_sheet_view_row_inserted (GtkTreeModel *model,
7232 PsppSheetView *tree_view = (PsppSheetView *) data;
7235 gint height = tree_view->priv->fixed_height;
7236 gboolean free_path = FALSE;
7237 gboolean node_visible = TRUE;
7239 g_return_if_fail (path != NULL || iter != NULL);
7243 path = gtk_tree_model_get_path (model, iter);
7246 else if (iter == NULL)
7247 gtk_tree_model_get_iter (model, iter, path);
7249 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7251 /* Update all row-references */
7252 gtk_tree_row_reference_inserted (G_OBJECT (data), path);
7253 indices = gtk_tree_path_get_indices (path);
7254 tmpnode = indices[0];
7256 range_tower_insert0 (tree_view->priv->selected, tmpnode, 1);
7260 if (node_visible && node_is_visible (tree_view, tmpnode))
7261 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7263 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (tree_view));
7266 install_presize_handler (tree_view);
7268 gtk_tree_path_free (path);
7272 pspp_sheet_view_row_deleted (GtkTreeModel *model,
7276 PsppSheetView *tree_view = (PsppSheetView *)data;
7279 g_return_if_fail (path != NULL);
7281 gtk_tree_row_reference_deleted (G_OBJECT (data), path);
7283 _pspp_sheet_view_find_node (tree_view, path, &node);
7288 range_tower_delete (tree_view->priv->selected, node, 1);
7290 /* Ensure we don't have a dangling pointer to a dead node */
7291 ensure_unprelighted (tree_view);
7293 /* Cancel editting if we've started */
7294 pspp_sheet_view_stop_editing (tree_view, TRUE);
7296 if (tree_view->priv->destroy_count_func)
7298 gint child_count = 0;
7299 tree_view->priv->destroy_count_func (tree_view, path, child_count, tree_view->priv->destroy_count_data);
7302 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7304 if (! gtk_tree_row_reference_valid (tree_view->priv->top_row))
7306 gtk_tree_row_reference_free (tree_view->priv->top_row);
7307 tree_view->priv->top_row = NULL;
7310 install_scroll_sync_handler (tree_view);
7312 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7315 if (helper_data.changed)
7316 g_signal_emit_by_name (tree_view->priv->selection, "changed");
7321 pspp_sheet_view_rows_reordered (GtkTreeModel *model,
7322 GtkTreePath *parent,
7327 PsppSheetView *tree_view = PSPP_SHEET_VIEW (data);
7330 /* XXX need to adjust selection */
7331 len = gtk_tree_model_iter_n_children (model, iter);
7336 gtk_tree_row_reference_reordered (G_OBJECT (data),
7341 if (gtk_tree_path_get_depth (parent) != 0)
7344 if (tree_view->priv->edited_column)
7345 pspp_sheet_view_stop_editing (tree_view, TRUE);
7347 /* we need to be unprelighted */
7348 ensure_unprelighted (tree_view);
7350 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
7352 pspp_sheet_view_dy_to_top_row (tree_view);
7356 /* Internal tree functions
7361 pspp_sheet_view_get_background_xrange (PsppSheetView *tree_view,
7362 PsppSheetViewColumn *column,
7366 PsppSheetViewColumn *tmp_column = NULL;
7377 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7380 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
7382 list = (rtl ? list->prev : list->next))
7384 tmp_column = list->data;
7386 if (tmp_column == column)
7389 if (tmp_column->visible)
7390 total_width += tmp_column->width;
7393 if (tmp_column != column)
7395 g_warning (G_STRLOC": passed-in column isn't in the tree");
7404 if (column->visible)
7405 *x2 = total_width + column->width;
7407 *x2 = total_width; /* width of 0 */
7411 /* Make sure the node is visible vertically */
7413 pspp_sheet_view_clamp_node_visible (PsppSheetView *tree_view,
7416 gint node_dy, height;
7417 GtkTreePath *path = NULL;
7419 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7422 /* just return if the node is visible, avoiding a costly expose */
7423 node_dy = pspp_sheet_view_node_find_offset (tree_view, node);
7424 height = ROW_HEIGHT (tree_view);
7425 if (node_dy >= gtk_adjustment_get_value (tree_view->priv->vadjustment)
7426 && node_dy + height <= (gtk_adjustment_get_value (tree_view->priv->vadjustment)
7427 + gtk_adjustment_get_page_size (tree_view->priv->vadjustment)))
7430 path = _pspp_sheet_view_find_path (tree_view, node);
7433 /* We process updates because we want to clear old selected items when we scroll.
7434 * if this is removed, we get a "selection streak" at the bottom. */
7435 gdk_window_process_updates (tree_view->priv->bin_window, TRUE);
7436 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL, FALSE, 0.0, 0.0);
7437 gtk_tree_path_free (path);
7442 pspp_sheet_view_clamp_column_visible (PsppSheetView *tree_view,
7443 PsppSheetViewColumn *column,
7444 gboolean focus_to_cell)
7451 x = column->allocation.x;
7452 width = column->allocation.width;
7454 if (width > gtk_adjustment_get_page_size (tree_view->priv->hadjustment))
7456 /* The column is larger than the horizontal page size. If the
7457 * column has cells which can be focussed individually, then we make
7458 * sure the cell which gets focus is fully visible (if even the
7459 * focus cell is bigger than the page size, we make sure the
7460 * left-hand side of the cell is visible).
7462 * If the column does not have those so-called special cells, we
7463 * make sure the left-hand side of the column is visible.
7466 if (focus_to_cell && pspp_sheet_view_has_special_cell (tree_view))
7468 GtkTreePath *cursor_path;
7469 GdkRectangle background_area, cell_area, focus_area;
7471 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7473 pspp_sheet_view_get_cell_area (tree_view,
7474 cursor_path, column, &cell_area);
7475 pspp_sheet_view_get_background_area (tree_view,
7476 cursor_path, column,
7479 gtk_tree_path_free (cursor_path);
7481 _pspp_sheet_view_column_get_focus_area (column,
7487 width = focus_area.width;
7489 if (width < gtk_adjustment_get_page_size (tree_view->priv->hadjustment))
7491 if ((gtk_adjustment_get_value (tree_view->priv->hadjustment) + gtk_adjustment_get_page_size (tree_view->priv->hadjustment)) < (x + width))
7492 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7493 x + width - gtk_adjustment_get_page_size (tree_view->priv->hadjustment));
7494 else if (gtk_adjustment_get_value (tree_view->priv->hadjustment) > x)
7495 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7499 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7501 gtk_adjustment_get_lower (tree_view->priv->hadjustment),
7502 gtk_adjustment_get_upper (tree_view->priv->hadjustment)
7503 - gtk_adjustment_get_page_size (tree_view->priv->hadjustment)));
7507 if ((gtk_adjustment_get_value (tree_view->priv->hadjustment) + gtk_adjustment_get_page_size (tree_view->priv->hadjustment)) < (x + width))
7508 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7509 x + width - gtk_adjustment_get_page_size (tree_view->priv->hadjustment));
7510 else if (gtk_adjustment_get_value (tree_view->priv->hadjustment) > x)
7511 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7516 _pspp_sheet_view_find_path (PsppSheetView *tree_view,
7521 path = gtk_tree_path_new ();
7523 gtk_tree_path_append_index (path, node);
7528 _pspp_sheet_view_find_node (PsppSheetView *tree_view,
7532 gint *indices = gtk_tree_path_get_indices (path);
7533 gint depth = gtk_tree_path_get_depth (path);
7536 if (depth == 0 || indices[0] < 0 || indices[0] >= tree_view->priv->row_count)
7542 pspp_sheet_view_add_move_binding (GtkBindingSet *binding_set,
7545 gboolean add_shifted_binding,
7546 GtkMovementStep step,
7550 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
7555 if (add_shifted_binding)
7556 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
7561 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
7564 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
7569 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
7576 pspp_sheet_view_set_column_drag_info (PsppSheetView *tree_view,
7577 PsppSheetViewColumn *column)
7579 PsppSheetViewColumn *left_column;
7580 PsppSheetViewColumn *cur_column = NULL;
7581 PsppSheetViewColumnReorder *reorder;
7586 /* We want to precalculate the motion list such that we know what column slots
7590 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7592 /* First, identify all possible drop spots */
7594 tmp_list = g_list_last (tree_view->priv->columns);
7596 tmp_list = g_list_first (tree_view->priv->columns);
7600 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
7601 tmp_list = rtl?g_list_previous (tmp_list):g_list_next (tmp_list);
7603 if (cur_column->visible == FALSE)
7606 /* If it's not the column moving and func tells us to skip over the column, we continue. */
7607 if (left_column != column && cur_column != column &&
7608 tree_view->priv->column_drop_func &&
7609 ! tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
7611 left_column = cur_column;
7614 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7615 reorder->left_column = left_column;
7616 left_column = reorder->right_column = cur_column;
7618 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7621 /* Add the last one */
7622 if (tree_view->priv->column_drop_func == NULL ||
7623 ((left_column != column) &&
7624 tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data)))
7626 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7627 reorder->left_column = left_column;
7628 reorder->right_column = NULL;
7629 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7632 /* We quickly check to see if it even makes sense to reorder columns. */
7633 /* If there is nothing that can be moved, then we return */
7635 if (tree_view->priv->column_drag_info == NULL)
7638 /* We know there are always 2 slots possbile, as you can always return column. */
7639 /* If that's all there is, return */
7640 if (tree_view->priv->column_drag_info->next == NULL ||
7641 (tree_view->priv->column_drag_info->next->next == NULL &&
7642 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->data)->right_column == column &&
7643 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->next->data)->left_column == column))
7645 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7646 g_slice_free (PsppSheetViewColumnReorder, tmp_list->data);
7647 g_list_free (tree_view->priv->column_drag_info);
7648 tree_view->priv->column_drag_info = NULL;
7651 /* We fill in the ranges for the columns, now that we've isolated them */
7652 left = - TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7654 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7656 reorder = (PsppSheetViewColumnReorder *) tmp_list->data;
7658 reorder->left_align = left;
7659 if (tmp_list->next != NULL)
7661 g_assert (tmp_list->next->data);
7662 left = reorder->right_align = (reorder->right_column->allocation.x +
7663 reorder->right_column->allocation.width +
7664 ((PsppSheetViewColumnReorder *)tmp_list->next->data)->left_column->allocation.x)/2;
7668 gint width = gdk_window_get_width (tree_view->priv->header_window);
7669 reorder->right_align = width + TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7675 _pspp_sheet_view_column_start_drag (PsppSheetView *tree_view,
7676 PsppSheetViewColumn *column)
7678 GdkEvent *send_event;
7679 GtkAllocation allocation;
7681 GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
7682 GdkDisplay *display = gdk_screen_get_display (screen);
7684 g_return_if_fail (tree_view->priv->column_drag_info == NULL);
7685 g_return_if_fail (tree_view->priv->cur_reorder == NULL);
7686 g_return_if_fail (column->button);
7688 pspp_sheet_view_set_column_drag_info (tree_view, column);
7690 if (tree_view->priv->column_drag_info == NULL)
7693 if (tree_view->priv->drag_window == NULL)
7695 GdkWindowAttr attributes;
7696 guint attributes_mask;
7698 attributes.window_type = GDK_WINDOW_CHILD;
7699 attributes.wclass = GDK_INPUT_OUTPUT;
7700 attributes.x = column->allocation.x;
7702 attributes.width = column->allocation.width;
7703 attributes.height = column->allocation.height;
7704 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
7705 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
7706 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL ;
7708 tree_view->priv->drag_window = gdk_window_new (tree_view->priv->bin_window,
7711 gdk_window_set_user_data (tree_view->priv->drag_window, GTK_WIDGET (tree_view));
7714 gdk_display_pointer_ungrab (display, GDK_CURRENT_TIME);
7715 gdk_display_keyboard_ungrab (display, GDK_CURRENT_TIME);
7717 gtk_grab_remove (column->button);
7719 send_event = gdk_event_new (GDK_LEAVE_NOTIFY);
7720 send_event->crossing.send_event = TRUE;
7721 send_event->crossing.window = g_object_ref (gtk_button_get_event_window (GTK_BUTTON (column->button)));
7722 send_event->crossing.subwindow = NULL;
7723 send_event->crossing.detail = GDK_NOTIFY_ANCESTOR;
7724 send_event->crossing.time = GDK_CURRENT_TIME;
7726 gtk_propagate_event (column->button, send_event);
7727 gdk_event_free (send_event);
7729 send_event = gdk_event_new (GDK_BUTTON_RELEASE);
7730 send_event->button.window = g_object_ref (gdk_screen_get_root_window (screen));
7731 send_event->button.send_event = TRUE;
7732 send_event->button.time = GDK_CURRENT_TIME;
7733 send_event->button.x = -1;
7734 send_event->button.y = -1;
7735 send_event->button.axes = NULL;
7736 send_event->button.state = 0;
7737 send_event->button.button = 1;
7738 send_event->button.device = gdk_display_get_core_pointer (display);
7739 send_event->button.x_root = 0;
7740 send_event->button.y_root = 0;
7742 gtk_propagate_event (column->button, send_event);
7743 gdk_event_free (send_event);
7745 /* Kids, don't try this at home */
7746 g_object_ref (column->button);
7747 gtk_container_remove (GTK_CONTAINER (tree_view), column->button);
7748 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7749 gtk_widget_set_parent (column->button, GTK_WIDGET (tree_view));
7750 g_object_unref (column->button);
7752 tree_view->priv->drag_column_x = column->allocation.x;
7753 allocation = column->allocation;
7755 gtk_widget_size_allocate (column->button, &allocation);
7756 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7758 tree_view->priv->drag_column = column;
7759 gdk_window_show (tree_view->priv->drag_window);
7761 gdk_window_get_origin (tree_view->priv->header_window, &x, &y);
7763 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7764 while (gtk_events_pending ())
7765 gtk_main_iteration ();
7767 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG);
7768 gdk_pointer_grab (tree_view->priv->drag_window,
7770 GDK_POINTER_MOTION_MASK|GDK_BUTTON_RELEASE_MASK,
7771 NULL, NULL, GDK_CURRENT_TIME);
7772 gdk_keyboard_grab (tree_view->priv->drag_window,
7778 _pspp_sheet_view_queue_draw_node (PsppSheetView *tree_view,
7780 const GdkRectangle *clip_rect)
7783 GtkAllocation allocation;
7785 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7788 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
7790 rect.width = MAX (tree_view->priv->width, allocation.width);
7792 rect.y = BACKGROUND_FIRST_PIXEL (tree_view, node);
7793 rect.height = ROW_HEIGHT (tree_view);
7797 GdkRectangle new_rect;
7799 gdk_rectangle_intersect (clip_rect, &rect, &new_rect);
7801 gdk_window_invalidate_rect (tree_view->priv->bin_window, &new_rect, TRUE);
7805 gdk_window_invalidate_rect (tree_view->priv->bin_window, &rect, TRUE);
7810 pspp_sheet_view_queue_draw_path (PsppSheetView *tree_view,
7812 const GdkRectangle *clip_rect)
7816 _pspp_sheet_view_find_node (tree_view, path, &node);
7819 _pspp_sheet_view_queue_draw_node (tree_view, node, clip_rect);
7823 pspp_sheet_view_focus_to_cursor (PsppSheetView *tree_view)
7826 GtkTreePath *cursor_path;
7828 if ((tree_view->priv->row_count == 0) ||
7829 (! gtk_widget_get_realized (GTK_WIDGET (tree_view))))
7833 if (tree_view->priv->cursor)
7834 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7836 if (cursor_path == NULL)
7838 /* There's no cursor. Move the cursor to the first selected row, if any
7839 * are selected, otherwise to the first row in the sheetview.
7841 GList *selected_rows;
7842 GtkTreeModel *model;
7843 PsppSheetSelection *selection;
7845 selection = pspp_sheet_view_get_selection (tree_view);
7846 selected_rows = pspp_sheet_selection_get_selected_rows (selection, &model);
7850 /* XXX we could avoid doing O(n) work to get this result */
7851 cursor_path = gtk_tree_path_copy((const GtkTreePath *)(selected_rows->data));
7852 g_list_foreach (selected_rows, (GFunc)gtk_tree_path_free, NULL);
7853 g_list_free (selected_rows);
7857 cursor_path = gtk_tree_path_new_first ();
7858 search_first_focusable_path (tree_view, &cursor_path,
7862 gtk_tree_row_reference_free (tree_view->priv->cursor);
7863 tree_view->priv->cursor = NULL;
7867 if (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7868 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE)
7869 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, FALSE, FALSE, 0);
7871 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE, 0);
7877 /* Now find a column for the cursor. */
7878 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
7880 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
7881 gtk_tree_path_free (cursor_path);
7883 if (tree_view->priv->focus_column == NULL)
7886 for (list = tree_view->priv->columns; list; list = list->next)
7888 if (PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
7890 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
7891 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
7892 pspp_sheet_selection_select_column (tree_view->priv->selection, tree_view->priv->focus_column);
7902 pspp_sheet_view_move_cursor_up_down (PsppSheetView *tree_view,
7904 PsppSheetSelectMode mode)
7906 gint selection_count;
7907 int cursor_node = -1;
7908 int new_cursor_node = -1;
7909 GtkTreePath *cursor_path = NULL;
7910 gboolean grab_focus = TRUE;
7912 if (! gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7916 if (!gtk_tree_row_reference_valid (tree_view->priv->cursor))
7917 /* FIXME: we lost the cursor; should we get the first? */
7920 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7921 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
7923 if (cursor_node < 0)
7924 /* FIXME: we lost the cursor; should we get the first? */
7927 selection_count = pspp_sheet_selection_count_selected_rows (tree_view->priv->selection);
7929 if (selection_count == 0
7930 && tree_view->priv->selection->type != PSPP_SHEET_SELECTION_NONE
7931 && !(mode & PSPP_SHEET_SELECT_MODE_TOGGLE))
7933 /* Don't move the cursor, but just select the current node */
7934 new_cursor_node = cursor_node;
7939 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
7941 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7944 gtk_tree_path_free (cursor_path);
7946 if (new_cursor_node)
7948 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
7950 search_first_focusable_path (tree_view, &cursor_path,
7955 gtk_tree_path_free (cursor_path);
7959 * If the list has only one item and multi-selection is set then select
7960 * the row (if not yet selected).
7962 if ((tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7963 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE) &&
7964 new_cursor_node < 0)
7967 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7969 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
7971 if (new_cursor_node < 0
7972 && !pspp_sheet_view_node_is_selected (tree_view, cursor_node))
7974 new_cursor_node = cursor_node;
7978 new_cursor_node = -1;
7982 if (new_cursor_node >= 0)
7984 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
7985 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, TRUE, mode);
7986 gtk_tree_path_free (cursor_path);
7990 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
7992 if (!(mode & PSPP_SHEET_SELECT_MODE_EXTEND))
7994 if (! gtk_widget_keynav_failed (GTK_WIDGET (tree_view),
7996 GTK_DIR_UP : GTK_DIR_DOWN))
7998 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
8001 gtk_widget_child_focus (toplevel,
8003 GTK_DIR_TAB_BACKWARD :
8004 GTK_DIR_TAB_FORWARD);
8011 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8016 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8018 return new_cursor_node >= 0;
8022 pspp_sheet_view_move_cursor_page_up_down (PsppSheetView *tree_view,
8024 PsppSheetSelectMode mode)
8026 int cursor_node = -1;
8027 GtkTreePath *old_cursor_path = NULL;
8028 GtkTreePath *cursor_path = NULL;
8029 int start_cursor_node = -1;
8032 gint vertical_separator;
8034 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8037 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8038 old_cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8040 /* This is sorta weird. Focus in should give us a cursor */
8043 gtk_widget_style_get (GTK_WIDGET (tree_view), "vertical-separator", &vertical_separator, NULL);
8044 _pspp_sheet_view_find_node (tree_view, old_cursor_path, &cursor_node);
8046 if (cursor_node < 0)
8048 /* FIXME: we lost the cursor. Should we try to get one? */
8049 gtk_tree_path_free (old_cursor_path);
8053 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
8054 window_y = RBTREE_Y_TO_TREE_WINDOW_Y (tree_view, y);
8055 y += tree_view->priv->cursor_offset;
8056 y += count * (int)gtk_adjustment_get_page_increment (tree_view->priv->vadjustment);
8057 y = CLAMP (y, (gint)gtk_adjustment_get_lower (tree_view->priv->vadjustment), (gint)gtk_adjustment_get_upper (tree_view->priv->vadjustment) - vertical_separator);
8059 if (y >= tree_view->priv->height)
8060 y = tree_view->priv->height - 1;
8062 tree_view->priv->cursor_offset =
8063 pspp_sheet_view_find_offset (tree_view, y, &cursor_node);
8065 if (tree_view->priv->cursor_offset > BACKGROUND_HEIGHT (tree_view))
8067 cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
8068 tree_view->priv->cursor_offset -= BACKGROUND_HEIGHT (tree_view);
8071 y -= tree_view->priv->cursor_offset;
8072 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
8074 start_cursor_node = cursor_node;
8076 if (! search_first_focusable_path (tree_view, &cursor_path,
8080 /* It looks like we reached the end of the view without finding
8081 * a focusable row. We will step backwards to find the last
8084 cursor_node = start_cursor_node;
8085 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
8087 search_first_focusable_path (tree_view, &cursor_path,
8096 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
8098 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE, mode);
8101 pspp_sheet_view_scroll_to_point (tree_view, -1, y);
8102 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8103 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8105 if (!gtk_tree_path_compare (old_cursor_path, cursor_path))
8106 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8108 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8111 gtk_tree_path_free (old_cursor_path);
8112 gtk_tree_path_free (cursor_path);
8116 pspp_sheet_view_move_cursor_left_right (PsppSheetView *tree_view,
8118 PsppSheetSelectMode mode)
8120 int cursor_node = -1;
8121 GtkTreePath *cursor_path = NULL;
8122 PsppSheetViewColumn *column;
8125 gboolean found_column = FALSE;
8128 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8130 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8133 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8134 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8138 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8139 if (cursor_node < 0)
8141 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8143 gtk_tree_path_free (cursor_path);
8146 gtk_tree_path_free (cursor_path);
8148 list = rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns);
8149 if (tree_view->priv->focus_column)
8151 for (; list; list = (rtl ? list->prev : list->next))
8153 if (list->data == tree_view->priv->focus_column)
8160 gboolean left, right;
8162 column = list->data;
8163 if (column->visible == FALSE || column->row_head)
8166 pspp_sheet_view_column_cell_set_cell_data (column,
8167 tree_view->priv->model,
8172 right = list->prev ? TRUE : FALSE;
8173 left = list->next ? TRUE : FALSE;
8177 left = list->prev ? TRUE : FALSE;
8178 right = list->next ? TRUE : FALSE;
8181 if (_pspp_sheet_view_column_cell_focus (column, count, left, right))
8183 tree_view->priv->focus_column = column;
8184 found_column = TRUE;
8189 list = rtl ? list->prev : list->next;
8191 list = rtl ? list->next : list->prev;
8196 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8197 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8198 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8202 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8205 pspp_sheet_view_clamp_column_visible (tree_view,
8206 tree_view->priv->focus_column, TRUE);
8210 pspp_sheet_view_move_cursor_line_start_end (PsppSheetView *tree_view,
8212 PsppSheetSelectMode mode)
8214 int cursor_node = -1;
8215 GtkTreePath *cursor_path = NULL;
8216 PsppSheetViewColumn *column;
8217 PsppSheetViewColumn *found_column;
8222 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8224 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8227 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8228 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8232 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8233 if (cursor_node < 0)
8235 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8237 gtk_tree_path_free (cursor_path);
8240 gtk_tree_path_free (cursor_path);
8242 list = rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns);
8243 if (tree_view->priv->focus_column)
8245 for (; list; list = (rtl ? list->prev : list->next))
8247 if (list->data == tree_view->priv->focus_column)
8252 found_column = NULL;
8255 gboolean left, right;
8257 column = list->data;
8258 if (column->visible == FALSE || column->row_head)
8261 pspp_sheet_view_column_cell_set_cell_data (column,
8262 tree_view->priv->model,
8267 right = list->prev ? TRUE : FALSE;
8268 left = list->next ? TRUE : FALSE;
8272 left = list->prev ? TRUE : FALSE;
8273 right = list->next ? TRUE : FALSE;
8276 if (column->tabbable
8277 && _pspp_sheet_view_column_cell_focus (column, count, left, right))
8278 found_column = column;
8282 list = rtl ? list->prev : list->next;
8284 list = rtl ? list->next : list->prev;
8289 tree_view->priv->focus_column = found_column;
8290 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8291 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8292 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8295 pspp_sheet_view_clamp_column_visible (tree_view,
8296 tree_view->priv->focus_column, TRUE);
8300 try_move_cursor_tab (PsppSheetView *tree_view,
8301 gboolean start_at_focus_column,
8304 PsppSheetViewColumn *column;
8306 int cursor_node = -1;
8307 GtkTreePath *cursor_path = NULL;
8311 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8312 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8316 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8317 if (cursor_node < 0)
8319 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8321 gtk_tree_path_free (cursor_path);
8324 gtk_tree_path_free (cursor_path);
8326 rtl = gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL;
8327 if (start_at_focus_column)
8330 ? g_list_last (tree_view->priv->columns)
8331 : g_list_first (tree_view->priv->columns));
8332 if (tree_view->priv->focus_column)
8334 for (; list; list = (rtl ? list->prev : list->next))
8336 if (list->data == tree_view->priv->focus_column)
8343 list = (rtl ^ (count == 1)
8344 ? g_list_first (tree_view->priv->columns)
8345 : g_list_last (tree_view->priv->columns));
8350 gboolean left, right;
8352 column = list->data;
8353 if (column->visible == FALSE || !column->tabbable)
8356 pspp_sheet_view_column_cell_set_cell_data (column,
8357 tree_view->priv->model,
8362 right = list->prev ? TRUE : FALSE;
8363 left = list->next ? TRUE : FALSE;
8367 left = list->prev ? TRUE : FALSE;
8368 right = list->next ? TRUE : FALSE;
8371 if (column->tabbable
8372 && _pspp_sheet_view_column_cell_focus (column, count, left, right))
8374 tree_view->priv->focus_column = column;
8375 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8376 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8377 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8382 list = rtl ? list->prev : list->next;
8384 list = rtl ? list->next : list->prev;
8391 pspp_sheet_view_move_cursor_tab (PsppSheetView *tree_view,
8394 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8397 if (!try_move_cursor_tab (tree_view, TRUE, count))
8399 if (pspp_sheet_view_move_cursor_up_down (tree_view, count, 0)
8400 && !try_move_cursor_tab (tree_view, FALSE, count))
8401 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8404 pspp_sheet_view_clamp_column_visible (tree_view,
8405 tree_view->priv->focus_column, TRUE);
8409 pspp_sheet_view_move_cursor_start_end (PsppSheetView *tree_view,
8411 PsppSheetSelectMode mode)
8415 GtkTreePath *old_path;
8417 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8420 g_return_if_fail (tree_view->priv->row_count > 0);
8422 pspp_sheet_view_get_cursor (tree_view, &old_path, NULL);
8426 /* Now go forward to find the first focusable row. */
8427 path = _pspp_sheet_view_find_path (tree_view, 0);
8428 search_first_focusable_path (tree_view, &path,
8429 TRUE, &cursor_node);
8433 /* Now go backwards to find last focusable row. */
8434 path = _pspp_sheet_view_find_path (tree_view, tree_view->priv->row_count - 1);
8435 search_first_focusable_path (tree_view, &path,
8436 FALSE, &cursor_node);
8442 if (gtk_tree_path_compare (old_path, path))
8444 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, mode);
8445 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8449 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8453 gtk_tree_path_free (old_path);
8454 gtk_tree_path_free (path);
8458 pspp_sheet_view_real_select_all (PsppSheetView *tree_view)
8460 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8463 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8464 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8467 pspp_sheet_selection_select_all (tree_view->priv->selection);
8473 pspp_sheet_view_real_unselect_all (PsppSheetView *tree_view)
8475 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8478 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8479 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8482 pspp_sheet_selection_unselect_all (tree_view->priv->selection);
8488 pspp_sheet_view_real_select_cursor_row (PsppSheetView *tree_view,
8489 gboolean start_editing,
8490 PsppSheetSelectMode mode)
8493 int cursor_node = -1;
8494 GtkTreePath *cursor_path = NULL;
8496 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8499 if (tree_view->priv->cursor)
8500 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8502 if (cursor_path == NULL)
8505 _pspp_sheet_view_find_node (tree_view, cursor_path,
8508 if (cursor_node < 0)
8510 gtk_tree_path_free (cursor_path);
8514 if (!(mode & PSPP_SHEET_SELECT_MODE_EXTEND) && start_editing &&
8515 tree_view->priv->focus_column)
8517 if (pspp_sheet_view_start_editing (tree_view, cursor_path))
8519 gtk_tree_path_free (cursor_path);
8524 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8530 /* We bail out if the original (tree, node) don't exist anymore after
8531 * handling the selection-changed callback. We do return TRUE because
8532 * the key press has been handled at this point.
8534 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8536 if (cursor_node != new_node)
8539 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8541 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8542 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8544 if (!(mode & PSPP_SHEET_SELECT_MODE_EXTEND))
8545 pspp_sheet_view_row_activated (tree_view, cursor_path,
8546 tree_view->priv->focus_column);
8548 gtk_tree_path_free (cursor_path);
8554 pspp_sheet_view_real_toggle_cursor_row (PsppSheetView *tree_view)
8557 int cursor_node = -1;
8558 GtkTreePath *cursor_path = NULL;
8560 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8564 if (tree_view->priv->cursor)
8565 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8567 if (cursor_path == NULL)
8570 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8571 if (cursor_node < 0)
8573 gtk_tree_path_free (cursor_path);
8577 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8580 PSPP_SHEET_SELECT_MODE_TOGGLE,
8583 /* We bail out if the original (tree, node) don't exist anymore after
8584 * handling the selection-changed callback. We do return TRUE because
8585 * the key press has been handled at this point.
8587 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8589 if (cursor_node != new_node)
8592 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8594 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8595 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
8596 gtk_tree_path_free (cursor_path);
8602 pspp_sheet_view_search_entry_flush_timeout (PsppSheetView *tree_view)
8604 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
8605 tree_view->priv->typeselect_flush_timeout = 0;
8610 /* Cut and paste from gtkwindow.c */
8612 send_focus_change (GtkWidget *widget,
8615 GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
8617 fevent->focus_change.type = GDK_FOCUS_CHANGE;
8618 fevent->focus_change.window = g_object_ref (gtk_widget_get_window (widget));
8619 fevent->focus_change.in = in;
8621 gtk_widget_send_focus_change (widget, fevent);
8622 gdk_event_free (fevent);
8626 pspp_sheet_view_ensure_interactive_directory (PsppSheetView *tree_view)
8628 GtkWidget *frame, *vbox, *toplevel;
8631 if (tree_view->priv->search_custom_entry_set)
8634 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
8635 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
8637 if (tree_view->priv->search_window != NULL)
8639 if (gtk_window_get_group (GTK_WINDOW (toplevel)))
8640 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
8641 GTK_WINDOW (tree_view->priv->search_window));
8642 else if (gtk_window_get_group (GTK_WINDOW (tree_view->priv->search_window)))
8643 gtk_window_group_remove_window (gtk_window_get_group (GTK_WINDOW (tree_view->priv->search_window)),
8644 GTK_WINDOW (tree_view->priv->search_window));
8645 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8649 tree_view->priv->search_window = gtk_window_new (GTK_WINDOW_POPUP);
8650 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8652 if (gtk_window_get_group (GTK_WINDOW (toplevel)))
8653 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
8654 GTK_WINDOW (tree_view->priv->search_window));
8656 gtk_window_set_type_hint (GTK_WINDOW (tree_view->priv->search_window),
8657 GDK_WINDOW_TYPE_HINT_UTILITY);
8658 gtk_window_set_modal (GTK_WINDOW (tree_view->priv->search_window), TRUE);
8659 g_signal_connect (tree_view->priv->search_window, "delete-event",
8660 G_CALLBACK (pspp_sheet_view_search_delete_event),
8662 g_signal_connect (tree_view->priv->search_window, "key-press-event",
8663 G_CALLBACK (pspp_sheet_view_search_key_press_event),
8665 g_signal_connect (tree_view->priv->search_window, "button-press-event",
8666 G_CALLBACK (pspp_sheet_view_search_button_press_event),
8668 g_signal_connect (tree_view->priv->search_window, "scroll-event",
8669 G_CALLBACK (pspp_sheet_view_search_scroll_event),
8672 frame = gtk_frame_new (NULL);
8673 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
8674 gtk_widget_show (frame);
8675 gtk_container_add (GTK_CONTAINER (tree_view->priv->search_window), frame);
8677 vbox = gtk_vbox_new (FALSE, 0);
8678 gtk_widget_show (vbox);
8679 gtk_container_add (GTK_CONTAINER (frame), vbox);
8680 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
8683 tree_view->priv->search_entry = gtk_entry_new ();
8684 gtk_widget_show (tree_view->priv->search_entry);
8685 g_signal_connect (tree_view->priv->search_entry, "populate-popup",
8686 G_CALLBACK (pspp_sheet_view_search_disable_popdown),
8688 g_signal_connect (tree_view->priv->search_entry,
8689 "activate", G_CALLBACK (pspp_sheet_view_search_activate),
8693 g_signal_connect (GTK_ENTRY (tree_view->priv->search_entry)->im_context,
8695 G_CALLBACK (pspp_sheet_view_search_preedit_changed),
8699 gtk_container_add (GTK_CONTAINER (vbox),
8700 tree_view->priv->search_entry);
8702 gtk_widget_realize (tree_view->priv->search_entry);
8705 /* Pops up the interactive search entry. If keybinding is TRUE then the user
8706 * started this by typing the start_interactive_search keybinding. Otherwise, it came from
8709 pspp_sheet_view_real_start_interactive_search (PsppSheetView *tree_view,
8710 gboolean keybinding)
8712 /* We only start interactive search if we have focus or the columns
8713 * have focus. If one of our children have focus, we don't want to
8717 gboolean found_focus = FALSE;
8718 GtkWidgetClass *entry_parent_class;
8720 if (!tree_view->priv->enable_search && !keybinding)
8723 if (tree_view->priv->search_custom_entry_set)
8726 if (tree_view->priv->search_window != NULL &&
8727 gtk_widget_get_visible (tree_view->priv->search_window))
8730 for (list = tree_view->priv->columns; list; list = list->next)
8732 PsppSheetViewColumn *column;
8734 column = list->data;
8735 if (! column->visible)
8738 if (column->button && gtk_widget_has_focus (column->button))
8745 if (gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8751 if (tree_view->priv->search_column < 0)
8754 pspp_sheet_view_ensure_interactive_directory (tree_view);
8757 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
8760 tree_view->priv->search_position_func (tree_view, tree_view->priv->search_window, tree_view->priv->search_position_user_data);
8761 gtk_widget_show (tree_view->priv->search_window);
8762 if (tree_view->priv->search_entry_changed_id == 0)
8764 tree_view->priv->search_entry_changed_id =
8765 g_signal_connect (tree_view->priv->search_entry, "changed",
8766 G_CALLBACK (pspp_sheet_view_search_init),
8770 tree_view->priv->typeselect_flush_timeout =
8771 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
8772 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
8775 /* Grab focus will select all the text. We don't want that to happen, so we
8776 * call the parent instance and bypass the selection change. This is probably
8777 * really non-kosher. */
8778 entry_parent_class = g_type_class_peek_parent (GTK_ENTRY_GET_CLASS (tree_view->priv->search_entry));
8779 (entry_parent_class->grab_focus) (tree_view->priv->search_entry);
8781 /* send focus-in event */
8782 send_focus_change (tree_view->priv->search_entry, TRUE);
8784 /* search first matching iter */
8785 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
8791 pspp_sheet_view_start_interactive_search (PsppSheetView *tree_view)
8793 return pspp_sheet_view_real_start_interactive_search (tree_view, TRUE);
8796 /* this function returns the new width of the column being resized given
8797 * the column and x position of the cursor; the x cursor position is passed
8798 * in as a pointer and automagicly corrected if it's beyond min/max limits
8801 pspp_sheet_view_new_column_width (PsppSheetView *tree_view,
8805 PsppSheetViewColumn *column;
8809 /* first translate the x position from gtk_widget_get_window (widget)
8810 * to clist->clist_window
8812 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8813 column = g_list_nth (tree_view->priv->columns, i)->data;
8814 width = rtl ? (column->allocation.x + column->allocation.width - *x) : (*x - column->allocation.x);
8816 /* Clamp down the value */
8817 if (column->min_width == -1)
8818 width = MAX (column->button_request, width);
8820 width = MAX (column->min_width, width);
8821 if (column->max_width != -1)
8822 width = MIN (width, column->max_width);
8824 *x = rtl ? (column->allocation.x + column->allocation.width - width) : (column->allocation.x + width);
8830 /* FIXME this adjust_allocation is a big cut-and-paste from
8831 * GtkCList, needs to be some "official" way to do this
8841 /* The window to which gtk_widget_get_window (widget) is relative */
8842 #define ALLOCATION_WINDOW(widget) \
8843 (!gtk_widget_get_has_window (widget) ? \
8844 gtk_widget_get_window (widget) : \
8845 gdk_window_get_parent (gtk_widget_get_window (widget)))
8848 adjust_allocation_recurse (GtkWidget *widget,
8851 ScrollData *scroll_data = data;
8852 GtkAllocation allocation;
8853 gtk_widget_get_allocation (widget, &allocation);
8854 /* Need to really size allocate instead of just poking
8855 * into widget->allocation if the widget is not realized.
8856 * FIXME someone figure out why this was.
8858 if (!gtk_widget_get_realized (widget))
8860 if (gtk_widget_get_visible (widget))
8862 GdkRectangle tmp_rectangle = allocation;
8863 tmp_rectangle.x += scroll_data->dx;
8864 tmp_rectangle.y += scroll_data->dy;
8866 gtk_widget_size_allocate (widget, &tmp_rectangle);
8871 if (ALLOCATION_WINDOW (widget) == scroll_data->window)
8873 allocation.x += scroll_data->dx;
8874 allocation.y += scroll_data->dy;
8876 if (GTK_IS_CONTAINER (widget))
8877 gtk_container_forall (GTK_CONTAINER (widget),
8878 adjust_allocation_recurse,
8885 adjust_allocation (GtkWidget *widget,
8889 ScrollData scroll_data;
8891 if (gtk_widget_get_realized (widget))
8892 scroll_data.window = ALLOCATION_WINDOW (widget);
8894 scroll_data.window = NULL;
8896 scroll_data.dx = dx;
8897 scroll_data.dy = dy;
8899 adjust_allocation_recurse (widget, &scroll_data);
8903 pspp_sheet_view_column_update_button (PsppSheetViewColumn *tree_column);
8907 pspp_sheet_view_adjustment_changed (GtkAdjustment *adjustment,
8908 PsppSheetView *tree_view)
8910 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
8915 gdk_window_move (tree_view->priv->bin_window,
8916 - gtk_adjustment_get_value (tree_view->priv->hadjustment),
8917 TREE_VIEW_HEADER_HEIGHT (tree_view));
8918 gdk_window_move (tree_view->priv->header_window,
8919 - gtk_adjustment_get_value (tree_view->priv->hadjustment),
8921 dy = tree_view->priv->dy - (int) gtk_adjustment_get_value (tree_view->priv->vadjustment);
8924 update_prelight (tree_view,
8925 tree_view->priv->event_last_x,
8926 tree_view->priv->event_last_y - dy);
8928 if (tree_view->priv->edited_column &&
8929 GTK_IS_WIDGET (tree_view->priv->edited_column->editable_widget))
8933 PsppSheetViewChild *child = NULL;
8935 widget = GTK_WIDGET (tree_view->priv->edited_column->editable_widget);
8936 adjust_allocation (widget, 0, dy);
8938 for (list = tree_view->priv->children; list; list = list->next)
8940 child = (PsppSheetViewChild *)list->data;
8941 if (child->widget == widget)
8949 gdk_window_scroll (tree_view->priv->bin_window, 0, dy);
8951 if (tree_view->priv->dy != (int) gtk_adjustment_get_value (tree_view->priv->vadjustment))
8953 /* update our dy and top_row */
8954 tree_view->priv->dy = (int) gtk_adjustment_get_value (tree_view->priv->vadjustment);
8956 if (!tree_view->priv->in_top_row_to_dy)
8957 pspp_sheet_view_dy_to_top_row (tree_view);
8960 for (list = tree_view->priv->columns; list; list = list->next)
8962 PsppSheetViewColumn *column = list->data;
8963 GtkAllocation *col_allocation = &column->allocation;
8964 GtkAllocation widget_allocation;
8965 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &widget_allocation);
8967 if (span_intersects (col_allocation->x, col_allocation->width,
8968 gtk_adjustment_get_value (tree_view->priv->hadjustment),
8969 widget_allocation.width))
8971 pspp_sheet_view_column_set_need_button (column, TRUE);
8972 if (!column->button)
8973 pspp_sheet_view_column_update_button (column);
8985 * pspp_sheet_view_new:
8987 * Creates a new #PsppSheetView widget.
8989 * Return value: A newly created #PsppSheetView widget.
8992 pspp_sheet_view_new (void)
8994 return g_object_new (PSPP_TYPE_SHEET_VIEW, NULL);
8998 * pspp_sheet_view_new_with_model:
8999 * @model: the model.
9001 * Creates a new #PsppSheetView widget with the model initialized to @model.
9003 * Return value: A newly created #PsppSheetView widget.
9006 pspp_sheet_view_new_with_model (GtkTreeModel *model)
9008 return g_object_new (PSPP_TYPE_SHEET_VIEW, "model", model, NULL);
9015 * pspp_sheet_view_get_model:
9016 * @tree_view: a #PsppSheetView
9018 * Returns the model the #PsppSheetView is based on. Returns %NULL if the
9021 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
9024 pspp_sheet_view_get_model (PsppSheetView *tree_view)
9026 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9028 return tree_view->priv->model;
9032 * pspp_sheet_view_set_model:
9033 * @tree_view: A #GtkTreeNode.
9034 * @model: (allow-none): The model.
9036 * Sets the model for a #PsppSheetView. If the @tree_view already has a model
9037 * set, it will remove it before setting the new model. If @model is %NULL,
9038 * then it will unset the old model.
9041 pspp_sheet_view_set_model (PsppSheetView *tree_view,
9042 GtkTreeModel *model)
9044 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9045 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
9047 if (model == tree_view->priv->model)
9050 if (tree_view->priv->scroll_to_path)
9052 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9053 tree_view->priv->scroll_to_path = NULL;
9056 if (tree_view->priv->model)
9058 GList *tmplist = tree_view->priv->columns;
9060 if (tree_view->priv->selected)
9061 range_tower_set0 (tree_view->priv->selected, 0, ULONG_MAX);
9062 pspp_sheet_view_stop_editing (tree_view, TRUE);
9064 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9065 pspp_sheet_view_row_changed,
9067 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9068 pspp_sheet_view_row_inserted,
9070 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9071 pspp_sheet_view_row_deleted,
9073 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9074 pspp_sheet_view_rows_reordered,
9077 for (; tmplist; tmplist = tmplist->next)
9078 _pspp_sheet_view_column_unset_model (tmplist->data,
9079 tree_view->priv->model);
9081 tree_view->priv->prelight_node = -1;
9083 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
9084 tree_view->priv->drag_dest_row = NULL;
9085 gtk_tree_row_reference_free (tree_view->priv->cursor);
9086 tree_view->priv->cursor = NULL;
9087 gtk_tree_row_reference_free (tree_view->priv->anchor);
9088 tree_view->priv->anchor = NULL;
9089 gtk_tree_row_reference_free (tree_view->priv->top_row);
9090 tree_view->priv->top_row = NULL;
9091 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9092 tree_view->priv->scroll_to_path = NULL;
9094 tree_view->priv->scroll_to_column = NULL;
9096 g_object_unref (tree_view->priv->model);
9098 tree_view->priv->search_column = -1;
9099 tree_view->priv->fixed_height = -1;
9100 tree_view->priv->dy = tree_view->priv->top_row_dy = 0;
9101 tree_view->priv->last_button_x = -1;
9102 tree_view->priv->last_button_y = -1;
9105 tree_view->priv->model = model;
9107 if (tree_view->priv->model)
9111 if (tree_view->priv->search_column == -1)
9113 for (i = 0; i < gtk_tree_model_get_n_columns (model); i++)
9115 GType type = gtk_tree_model_get_column_type (model, i);
9117 if (g_value_type_transformable (type, G_TYPE_STRING))
9119 tree_view->priv->search_column = i;
9125 g_object_ref (tree_view->priv->model);
9126 g_signal_connect (tree_view->priv->model,
9128 G_CALLBACK (pspp_sheet_view_row_changed),
9130 g_signal_connect (tree_view->priv->model,
9132 G_CALLBACK (pspp_sheet_view_row_inserted),
9134 g_signal_connect (tree_view->priv->model,
9136 G_CALLBACK (pspp_sheet_view_row_deleted),
9138 g_signal_connect (tree_view->priv->model,
9140 G_CALLBACK (pspp_sheet_view_rows_reordered),
9143 tree_view->priv->row_count = gtk_tree_model_iter_n_children (tree_view->priv->model, NULL);
9145 /* FIXME: do I need to do this? pspp_sheet_view_create_buttons (tree_view); */
9146 install_presize_handler (tree_view);
9149 g_object_notify (G_OBJECT (tree_view), "model");
9151 if (tree_view->priv->selection)
9152 _pspp_sheet_selection_emit_changed (tree_view->priv->selection);
9154 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9155 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9159 * pspp_sheet_view_get_selection:
9160 * @tree_view: A #PsppSheetView.
9162 * Gets the #PsppSheetSelection associated with @tree_view.
9164 * Return value: A #PsppSheetSelection object.
9166 PsppSheetSelection *
9167 pspp_sheet_view_get_selection (PsppSheetView *tree_view)
9169 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9171 return tree_view->priv->selection;
9175 * pspp_sheet_view_get_hadjustment:
9176 * @tree_view: A #PsppSheetView
9178 * Gets the #GtkAdjustment currently being used for the horizontal aspect.
9180 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
9184 pspp_sheet_view_get_hadjustment (PsppSheetView *tree_view)
9186 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9188 if (tree_view->priv->hadjustment == NULL)
9189 pspp_sheet_view_set_hadjustment (tree_view, NULL);
9191 return tree_view->priv->hadjustment;
9195 * pspp_sheet_view_set_hadjustment:
9196 * @tree_view: A #PsppSheetView
9197 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
9199 * Sets the #GtkAdjustment for the current horizontal aspect.
9202 pspp_sheet_view_set_hadjustment (PsppSheetView *tree_view,
9203 GtkAdjustment *adjustment)
9205 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9207 pspp_sheet_view_set_adjustments (tree_view,
9209 tree_view->priv->vadjustment);
9211 g_object_notify (G_OBJECT (tree_view), "hadjustment");
9215 * pspp_sheet_view_get_vadjustment:
9216 * @tree_view: A #PsppSheetView
9218 * Gets the #GtkAdjustment currently being used for the vertical aspect.
9220 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
9224 pspp_sheet_view_get_vadjustment (PsppSheetView *tree_view)
9226 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9228 if (tree_view->priv->vadjustment == NULL)
9229 pspp_sheet_view_set_vadjustment (tree_view, NULL);
9231 return tree_view->priv->vadjustment;
9235 * pspp_sheet_view_set_vadjustment:
9236 * @tree_view: A #PsppSheetView
9237 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
9239 * Sets the #GtkAdjustment for the current vertical aspect.
9242 pspp_sheet_view_set_vadjustment (PsppSheetView *tree_view,
9243 GtkAdjustment *adjustment)
9245 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9247 pspp_sheet_view_set_adjustments (tree_view,
9248 tree_view->priv->hadjustment,
9251 g_object_notify (G_OBJECT (tree_view), "vadjustment");
9254 /* Column and header operations */
9257 * pspp_sheet_view_get_headers_visible:
9258 * @tree_view: A #PsppSheetView.
9260 * Returns %TRUE if the headers on the @tree_view are visible.
9262 * Return value: Whether the headers are visible or not.
9265 pspp_sheet_view_get_headers_visible (PsppSheetView *tree_view)
9267 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9269 return PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9273 * pspp_sheet_view_set_headers_visible:
9274 * @tree_view: A #PsppSheetView.
9275 * @headers_visible: %TRUE if the headers are visible
9277 * Sets the visibility state of the headers.
9280 pspp_sheet_view_set_headers_visible (PsppSheetView *tree_view,
9281 gboolean headers_visible)
9285 PsppSheetViewColumn *column;
9286 GtkAllocation allocation;
9288 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9290 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
9292 headers_visible = !! headers_visible;
9294 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE) == headers_visible)
9297 if (headers_visible)
9298 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9300 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9302 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9304 gdk_window_get_position (tree_view->priv->bin_window, &x, &y);
9305 if (headers_visible)
9307 gdk_window_move_resize (tree_view->priv->bin_window, x, y + TREE_VIEW_HEADER_HEIGHT (tree_view),
9308 tree_view->priv->width, allocation.height - + TREE_VIEW_HEADER_HEIGHT (tree_view));
9310 if (gtk_widget_get_mapped (GTK_WIDGET (tree_view)))
9311 pspp_sheet_view_map_buttons (tree_view);
9315 gdk_window_move_resize (tree_view->priv->bin_window, x, y, tree_view->priv->width, tree_view->priv->height);
9317 for (list = tree_view->priv->columns; list; list = list->next)
9319 column = list->data;
9321 gtk_widget_unmap (column->button);
9323 gdk_window_hide (tree_view->priv->header_window);
9327 gtk_adjustment_set_page_size (tree_view->priv->vadjustment, allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view));
9328 gtk_adjustment_set_page_increment (tree_view->priv->vadjustment, (allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view)) / 2);
9329 gtk_adjustment_set_lower (tree_view->priv->vadjustment, 0);
9330 gtk_adjustment_set_upper (tree_view->priv->vadjustment, tree_view->priv->height);
9331 gtk_adjustment_changed (tree_view->priv->vadjustment);
9333 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9335 g_object_notify (G_OBJECT (tree_view), "headers-visible");
9339 * pspp_sheet_view_columns_autosize:
9340 * @tree_view: A #PsppSheetView.
9342 * Resizes all columns to their optimal width. Only works after the
9343 * treeview has been realized.
9346 pspp_sheet_view_columns_autosize (PsppSheetView *tree_view)
9348 gboolean dirty = FALSE;
9350 PsppSheetViewColumn *column;
9352 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9354 for (list = tree_view->priv->columns; list; list = list->next)
9356 column = list->data;
9357 _pspp_sheet_view_column_cell_set_dirty (column);
9362 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9366 * pspp_sheet_view_set_headers_clickable:
9367 * @tree_view: A #PsppSheetView.
9368 * @setting: %TRUE if the columns are clickable.
9370 * Allow the column title buttons to be clicked.
9373 pspp_sheet_view_set_headers_clickable (PsppSheetView *tree_view,
9378 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9380 for (list = tree_view->priv->columns; list; list = list->next)
9381 pspp_sheet_view_column_set_clickable (PSPP_SHEET_VIEW_COLUMN (list->data), setting);
9383 g_object_notify (G_OBJECT (tree_view), "headers-clickable");
9388 * pspp_sheet_view_get_headers_clickable:
9389 * @tree_view: A #PsppSheetView.
9391 * Returns whether all header columns are clickable.
9393 * Return value: %TRUE if all header columns are clickable, otherwise %FALSE
9398 pspp_sheet_view_get_headers_clickable (PsppSheetView *tree_view)
9402 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9404 for (list = tree_view->priv->columns; list; list = list->next)
9405 if (!PSPP_SHEET_VIEW_COLUMN (list->data)->clickable)
9412 * pspp_sheet_view_set_rules_hint
9413 * @tree_view: a #PsppSheetView
9414 * @setting: %TRUE if the tree requires reading across rows
9416 * This function tells GTK+ that the user interface for your
9417 * application requires users to read across tree rows and associate
9418 * cells with one another. By default, GTK+ will then render the tree
9419 * with alternating row colors. Do <emphasis>not</emphasis> use it
9420 * just because you prefer the appearance of the ruled tree; that's a
9421 * question for the theme. Some themes will draw tree rows in
9422 * alternating colors even when rules are turned off, and users who
9423 * prefer that appearance all the time can choose those themes. You
9424 * should call this function only as a <emphasis>semantic</emphasis>
9425 * hint to the theme engine that your tree makes alternating colors
9426 * useful from a functional standpoint (since it has lots of columns,
9431 pspp_sheet_view_set_rules_hint (PsppSheetView *tree_view,
9434 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9436 setting = setting != FALSE;
9438 if (tree_view->priv->has_rules != setting)
9440 tree_view->priv->has_rules = setting;
9441 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
9444 g_object_notify (G_OBJECT (tree_view), "rules-hint");
9448 * pspp_sheet_view_get_rules_hint
9449 * @tree_view: a #PsppSheetView
9451 * Gets the setting set by pspp_sheet_view_set_rules_hint().
9453 * Return value: %TRUE if rules are useful for the user of this tree
9456 pspp_sheet_view_get_rules_hint (PsppSheetView *tree_view)
9458 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9460 return tree_view->priv->has_rules;
9463 /* Public Column functions
9467 * pspp_sheet_view_append_column:
9468 * @tree_view: A #PsppSheetView.
9469 * @column: The #PsppSheetViewColumn to add.
9471 * Appends @column to the list of columns.
9473 * Return value: The number of columns in @tree_view after appending.
9476 pspp_sheet_view_append_column (PsppSheetView *tree_view,
9477 PsppSheetViewColumn *column)
9479 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9480 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9481 g_return_val_if_fail (column->tree_view == NULL, -1);
9483 return pspp_sheet_view_insert_column (tree_view, column, -1);
9488 * pspp_sheet_view_remove_column:
9489 * @tree_view: A #PsppSheetView.
9490 * @column: The #PsppSheetViewColumn to remove.
9492 * Removes @column from @tree_view.
9494 * Return value: The number of columns in @tree_view after removing.
9497 pspp_sheet_view_remove_column (PsppSheetView *tree_view,
9498 PsppSheetViewColumn *column)
9500 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9501 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9502 g_return_val_if_fail (column->tree_view == GTK_WIDGET (tree_view), -1);
9504 if (tree_view->priv->focus_column == column)
9505 tree_view->priv->focus_column = NULL;
9507 if (tree_view->priv->edited_column == column)
9509 pspp_sheet_view_stop_editing (tree_view, TRUE);
9511 /* no need to, but just to be sure ... */
9512 tree_view->priv->edited_column = NULL;
9515 _pspp_sheet_view_column_unset_tree_view (column);
9517 tree_view->priv->columns = g_list_remove (tree_view->priv->columns, column);
9518 tree_view->priv->n_columns--;
9520 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9524 _pspp_sheet_view_column_unrealize_button (column);
9525 for (list = tree_view->priv->columns; list; list = list->next)
9527 PsppSheetViewColumn *tmp_column;
9529 tmp_column = PSPP_SHEET_VIEW_COLUMN (list->data);
9530 if (tmp_column->visible)
9531 _pspp_sheet_view_column_cell_set_dirty (tmp_column);
9534 if (tree_view->priv->n_columns == 0 &&
9535 pspp_sheet_view_get_headers_visible (tree_view) &&
9536 tree_view->priv->header_window)
9537 gdk_window_hide (tree_view->priv->header_window);
9539 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9542 g_object_unref (column);
9543 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9545 return tree_view->priv->n_columns;
9549 * pspp_sheet_view_insert_column:
9550 * @tree_view: A #PsppSheetView.
9551 * @column: The #PsppSheetViewColumn to be inserted.
9552 * @position: The position to insert @column in.
9554 * This inserts the @column into the @tree_view at @position. If @position is
9555 * -1, then the column is inserted at the end.
9557 * Return value: The number of columns in @tree_view after insertion.
9560 pspp_sheet_view_insert_column (PsppSheetView *tree_view,
9561 PsppSheetViewColumn *column,
9564 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9565 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9566 g_return_val_if_fail (column->tree_view == NULL, -1);
9568 g_object_ref_sink (column);
9570 if (tree_view->priv->n_columns == 0 &&
9571 gtk_widget_get_realized (GTK_WIDGET (tree_view)) &&
9572 pspp_sheet_view_get_headers_visible (tree_view))
9574 gdk_window_show (tree_view->priv->header_window);
9577 tree_view->priv->columns = g_list_insert (tree_view->priv->columns,
9579 tree_view->priv->n_columns++;
9581 _pspp_sheet_view_column_set_tree_view (column, tree_view);
9583 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9587 _pspp_sheet_view_column_realize_button (column);
9589 for (list = tree_view->priv->columns; list; list = list->next)
9591 column = PSPP_SHEET_VIEW_COLUMN (list->data);
9592 if (column->visible)
9593 _pspp_sheet_view_column_cell_set_dirty (column);
9595 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9598 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9600 return tree_view->priv->n_columns;
9604 * pspp_sheet_view_insert_column_with_attributes:
9605 * @tree_view: A #PsppSheetView
9606 * @position: The position to insert the new column in.
9607 * @title: The title to set the header to.
9608 * @cell: The #GtkCellRenderer.
9609 * @Varargs: A %NULL-terminated list of attributes.
9611 * Creates a new #PsppSheetViewColumn and inserts it into the @tree_view at
9612 * @position. If @position is -1, then the newly created column is inserted at
9613 * the end. The column is initialized with the attributes given.
9615 * Return value: The number of columns in @tree_view after insertion.
9618 pspp_sheet_view_insert_column_with_attributes (PsppSheetView *tree_view,
9621 GtkCellRenderer *cell,
9624 PsppSheetViewColumn *column;
9629 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9631 column = pspp_sheet_view_column_new ();
9632 pspp_sheet_view_column_set_title (column, title);
9633 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9635 va_start (args, cell);
9637 attribute = va_arg (args, gchar *);
9639 while (attribute != NULL)
9641 column_id = va_arg (args, gint);
9642 pspp_sheet_view_column_add_attribute (column, cell, attribute, column_id);
9643 attribute = va_arg (args, gchar *);
9648 pspp_sheet_view_insert_column (tree_view, column, position);
9650 return tree_view->priv->n_columns;
9654 * pspp_sheet_view_insert_column_with_data_func:
9655 * @tree_view: a #PsppSheetView
9656 * @position: Position to insert, -1 for append
9657 * @title: column title
9658 * @cell: cell renderer for column
9659 * @func: function to set attributes of cell renderer
9660 * @data: data for @func
9661 * @dnotify: destroy notifier for @data
9663 * Convenience function that inserts a new column into the #PsppSheetView
9664 * with the given cell renderer and a #GtkCellDataFunc to set cell renderer
9665 * attributes (normally using data from the model). See also
9666 * pspp_sheet_view_column_set_cell_data_func(), pspp_sheet_view_column_pack_start().
9668 * Return value: number of columns in the tree view post-insert
9671 pspp_sheet_view_insert_column_with_data_func (PsppSheetView *tree_view,
9674 GtkCellRenderer *cell,
9675 PsppSheetCellDataFunc func,
9677 GDestroyNotify dnotify)
9679 PsppSheetViewColumn *column;
9681 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9683 column = pspp_sheet_view_column_new ();
9684 pspp_sheet_view_column_set_title (column, title);
9685 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9686 pspp_sheet_view_column_set_cell_data_func (column, cell, func, data, dnotify);
9688 pspp_sheet_view_insert_column (tree_view, column, position);
9690 return tree_view->priv->n_columns;
9694 * pspp_sheet_view_get_column:
9695 * @tree_view: A #PsppSheetView.
9696 * @n: The position of the column, counting from 0.
9698 * Gets the #PsppSheetViewColumn at the given position in the #tree_view.
9700 * Return value: The #PsppSheetViewColumn, or %NULL if the position is outside the
9703 PsppSheetViewColumn *
9704 pspp_sheet_view_get_column (PsppSheetView *tree_view,
9707 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9709 if (n < 0 || n >= tree_view->priv->n_columns)
9712 if (tree_view->priv->columns == NULL)
9715 return PSPP_SHEET_VIEW_COLUMN (g_list_nth (tree_view->priv->columns, n)->data);
9719 * pspp_sheet_view_get_columns:
9720 * @tree_view: A #PsppSheetView
9722 * Returns a #GList of all the #PsppSheetViewColumn s currently in @tree_view.
9723 * The returned list must be freed with g_list_free ().
9725 * Return value: (element-type PsppSheetViewColumn) (transfer container): A list of #PsppSheetViewColumn s
9728 pspp_sheet_view_get_columns (PsppSheetView *tree_view)
9730 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9732 return g_list_copy (tree_view->priv->columns);
9736 * pspp_sheet_view_move_column_after:
9737 * @tree_view: A #PsppSheetView
9738 * @column: The #PsppSheetViewColumn to be moved.
9739 * @base_column: (allow-none): The #PsppSheetViewColumn to be moved relative to, or %NULL.
9741 * Moves @column to be after to @base_column. If @base_column is %NULL, then
9742 * @column is placed in the first position.
9745 pspp_sheet_view_move_column_after (PsppSheetView *tree_view,
9746 PsppSheetViewColumn *column,
9747 PsppSheetViewColumn *base_column)
9749 GList *column_list_el, *base_el = NULL;
9751 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9753 column_list_el = g_list_find (tree_view->priv->columns, column);
9754 g_return_if_fail (column_list_el != NULL);
9758 base_el = g_list_find (tree_view->priv->columns, base_column);
9759 g_return_if_fail (base_el != NULL);
9762 if (column_list_el->prev == base_el)
9765 tree_view->priv->columns = g_list_remove_link (tree_view->priv->columns, column_list_el);
9766 if (base_el == NULL)
9768 column_list_el->prev = NULL;
9769 column_list_el->next = tree_view->priv->columns;
9770 if (column_list_el->next)
9771 column_list_el->next->prev = column_list_el;
9772 tree_view->priv->columns = column_list_el;
9776 column_list_el->prev = base_el;
9777 column_list_el->next = base_el->next;
9778 if (column_list_el->next)
9779 column_list_el->next->prev = column_list_el;
9780 base_el->next = column_list_el;
9783 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9785 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9786 pspp_sheet_view_size_allocate_columns (GTK_WIDGET (tree_view), NULL);
9789 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9793 * pspp_sheet_view_set_column_drag_function:
9794 * @tree_view: A #PsppSheetView.
9795 * @func: (allow-none): A function to determine which columns are reorderable, or %NULL.
9796 * @user_data: (allow-none): User data to be passed to @func, or %NULL
9797 * @destroy: (allow-none): Destroy notifier for @user_data, or %NULL
9799 * Sets a user function for determining where a column may be dropped when
9800 * dragged. This function is called on every column pair in turn at the
9801 * beginning of a column drag to determine where a drop can take place. The
9802 * arguments passed to @func are: the @tree_view, the #PsppSheetViewColumn being
9803 * dragged, the two #PsppSheetViewColumn s determining the drop spot, and
9804 * @user_data. If either of the #PsppSheetViewColumn arguments for the drop spot
9805 * are %NULL, then they indicate an edge. If @func is set to be %NULL, then
9806 * @tree_view reverts to the default behavior of allowing all columns to be
9807 * dropped everywhere.
9810 pspp_sheet_view_set_column_drag_function (PsppSheetView *tree_view,
9811 PsppSheetViewColumnDropFunc func,
9813 GDestroyNotify destroy)
9815 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9817 if (tree_view->priv->column_drop_func_data_destroy)
9818 tree_view->priv->column_drop_func_data_destroy (tree_view->priv->column_drop_func_data);
9820 tree_view->priv->column_drop_func = func;
9821 tree_view->priv->column_drop_func_data = user_data;
9822 tree_view->priv->column_drop_func_data_destroy = destroy;
9826 * pspp_sheet_view_scroll_to_point:
9827 * @tree_view: a #PsppSheetView
9828 * @tree_x: X coordinate of new top-left pixel of visible area, or -1
9829 * @tree_y: Y coordinate of new top-left pixel of visible area, or -1
9831 * Scrolls the tree view such that the top-left corner of the visible
9832 * area is @tree_x, @tree_y, where @tree_x and @tree_y are specified
9833 * in tree coordinates. The @tree_view must be realized before
9834 * this function is called. If it isn't, you probably want to be
9835 * using pspp_sheet_view_scroll_to_cell().
9837 * If either @tree_x or @tree_y are -1, then that direction isn't scrolled.
9840 pspp_sheet_view_scroll_to_point (PsppSheetView *tree_view,
9844 GtkAdjustment *hadj;
9845 GtkAdjustment *vadj;
9847 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9848 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
9850 hadj = tree_view->priv->hadjustment;
9851 vadj = tree_view->priv->vadjustment;
9854 gtk_adjustment_set_value (hadj, CLAMP (tree_x, gtk_adjustment_get_lower (hadj), gtk_adjustment_get_upper (hadj) - gtk_adjustment_get_page_size (hadj)));
9856 gtk_adjustment_set_value (vadj, CLAMP (tree_y, gtk_adjustment_get_lower (vadj), gtk_adjustment_get_upper (vadj) - gtk_adjustment_get_page_size (vadj)));
9860 * pspp_sheet_view_scroll_to_cell:
9861 * @tree_view: A #PsppSheetView.
9862 * @path: (allow-none): The path of the row to move to, or %NULL.
9863 * @column: (allow-none): The #PsppSheetViewColumn to move horizontally to, or %NULL.
9864 * @use_align: whether to use alignment arguments, or %FALSE.
9865 * @row_align: The vertical alignment of the row specified by @path.
9866 * @col_align: The horizontal alignment of the column specified by @column.
9868 * Moves the alignments of @tree_view to the position specified by @column and
9869 * @path. If @column is %NULL, then no horizontal scrolling occurs. Likewise,
9870 * if @path is %NULL no vertical scrolling occurs. At a minimum, one of @column
9871 * or @path need to be non-%NULL. @row_align determines where the row is
9872 * placed, and @col_align determines where @column is placed. Both are expected
9873 * to be between 0.0 and 1.0. 0.0 means left/top alignment, 1.0 means
9874 * right/bottom alignment, 0.5 means center.
9876 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
9877 * tree does the minimum amount of work to scroll the cell onto the screen.
9878 * This means that the cell will be scrolled to the edge closest to its current
9879 * position. If the cell is currently visible on the screen, nothing is done.
9881 * This function only works if the model is set, and @path is a valid row on the
9882 * model. If the model changes before the @tree_view is realized, the centered
9883 * path will be modified to reflect this change.
9886 pspp_sheet_view_scroll_to_cell (PsppSheetView *tree_view,
9888 PsppSheetViewColumn *column,
9893 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9894 g_return_if_fail (tree_view->priv->model != NULL);
9895 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
9896 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
9897 g_return_if_fail (path != NULL || column != NULL);
9900 g_print ("pspp_sheet_view_scroll_to_cell:\npath: %s\ncolumn: %s\nuse_align: %d\nrow_align: %f\ncol_align: %f\n",
9901 gtk_tree_path_to_string (path), column?"non-null":"null", use_align, row_align, col_align);
9903 row_align = CLAMP (row_align, 0.0, 1.0);
9904 col_align = CLAMP (col_align, 0.0, 1.0);
9907 /* Note: Despite the benefits that come from having one code path for the
9908 * scrolling code, we short-circuit validate_visible_area's immplementation as
9909 * it is much slower than just going to the point.
9911 if (!gtk_widget_get_visible (GTK_WIDGET (tree_view)) ||
9912 !gtk_widget_get_realized (GTK_WIDGET (tree_view))
9913 /* XXX || GTK_WIDGET_ALLOC_NEEDED (tree_view) */)
9915 if (tree_view->priv->scroll_to_path)
9916 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9918 tree_view->priv->scroll_to_path = NULL;
9919 tree_view->priv->scroll_to_column = NULL;
9922 tree_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
9924 tree_view->priv->scroll_to_column = column;
9925 tree_view->priv->scroll_to_use_align = use_align;
9926 tree_view->priv->scroll_to_row_align = row_align;
9927 tree_view->priv->scroll_to_col_align = col_align;
9929 install_presize_handler (tree_view);
9933 GdkRectangle cell_rect;
9934 GdkRectangle vis_rect;
9935 gint dest_x, dest_y;
9937 pspp_sheet_view_get_background_area (tree_view, path, column, &cell_rect);
9938 pspp_sheet_view_get_visible_rect (tree_view, &vis_rect);
9940 cell_rect.y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, cell_rect.y);
9942 dest_x = vis_rect.x;
9943 dest_y = vis_rect.y;
9949 dest_x = cell_rect.x - ((vis_rect.width - cell_rect.width) * col_align);
9953 if (cell_rect.x < vis_rect.x)
9954 dest_x = cell_rect.x;
9955 if (cell_rect.x + cell_rect.width > vis_rect.x + vis_rect.width)
9956 dest_x = cell_rect.x + cell_rect.width - vis_rect.width;
9964 dest_y = cell_rect.y - ((vis_rect.height - cell_rect.height) * row_align);
9965 dest_y = MAX (dest_y, 0);
9969 if (cell_rect.y < vis_rect.y)
9970 dest_y = cell_rect.y;
9971 if (cell_rect.y + cell_rect.height > vis_rect.y + vis_rect.height)
9972 dest_y = cell_rect.y + cell_rect.height - vis_rect.height;
9976 pspp_sheet_view_scroll_to_point (tree_view, dest_x, dest_y);
9981 * pspp_sheet_view_row_activated:
9982 * @tree_view: A #PsppSheetView
9983 * @path: The #GtkTreePath to be activated.
9984 * @column: The #PsppSheetViewColumn to be activated.
9986 * Activates the cell determined by @path and @column.
9989 pspp_sheet_view_row_activated (PsppSheetView *tree_view,
9991 PsppSheetViewColumn *column)
9993 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9995 g_signal_emit (tree_view, tree_view_signals[ROW_ACTIVATED], 0, path, column);
10000 * pspp_sheet_view_get_reorderable:
10001 * @tree_view: a #PsppSheetView
10003 * Retrieves whether the user can reorder the tree via drag-and-drop. See
10004 * pspp_sheet_view_set_reorderable().
10006 * Return value: %TRUE if the tree can be reordered.
10009 pspp_sheet_view_get_reorderable (PsppSheetView *tree_view)
10011 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
10013 return tree_view->priv->reorderable;
10017 * pspp_sheet_view_set_reorderable:
10018 * @tree_view: A #PsppSheetView.
10019 * @reorderable: %TRUE, if the tree can be reordered.
10021 * This function is a convenience function to allow you to reorder
10022 * models that support the #GtkDragSourceIface and the
10023 * #GtkDragDestIface. Both #GtkTreeStore and #GtkListStore support
10024 * these. If @reorderable is %TRUE, then the user can reorder the
10025 * model by dragging and dropping rows. The developer can listen to
10026 * these changes by connecting to the model's row_inserted and
10027 * row_deleted signals. The reordering is implemented by setting up
10028 * the tree view as a drag source and destination. Therefore, drag and
10029 * drop can not be used in a reorderable view for any other purpose.
10031 * This function does not give you any degree of control over the order -- any
10032 * reordering is allowed. If more control is needed, you should probably
10033 * handle drag and drop manually.
10036 pspp_sheet_view_set_reorderable (PsppSheetView *tree_view,
10037 gboolean reorderable)
10039 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10041 reorderable = reorderable != FALSE;
10043 if (tree_view->priv->reorderable == reorderable)
10048 const GtkTargetEntry row_targets[] = {
10049 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
10052 pspp_sheet_view_enable_model_drag_source (tree_view,
10055 G_N_ELEMENTS (row_targets),
10057 pspp_sheet_view_enable_model_drag_dest (tree_view,
10059 G_N_ELEMENTS (row_targets),
10064 pspp_sheet_view_unset_rows_drag_source (tree_view);
10065 pspp_sheet_view_unset_rows_drag_dest (tree_view);
10068 tree_view->priv->reorderable = reorderable;
10070 g_object_notify (G_OBJECT (tree_view), "reorderable");
10073 /* If CLEAR_AND_SELECT is true, then the row will be selected and, unless Shift
10074 is pressed, other rows will be unselected.
10076 If CLAMP_NODE is true, then the sheetview will scroll to make the row
10079 pspp_sheet_view_real_set_cursor (PsppSheetView *tree_view,
10081 gboolean clear_and_select,
10082 gboolean clamp_node,
10083 PsppSheetSelectMode mode)
10087 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
10089 GtkTreePath *cursor_path;
10090 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
10091 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
10092 gtk_tree_path_free (cursor_path);
10095 gtk_tree_row_reference_free (tree_view->priv->cursor);
10096 tree_view->priv->cursor = NULL;
10098 _pspp_sheet_view_find_node (tree_view, path, &node);
10099 tree_view->priv->cursor =
10100 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
10101 tree_view->priv->model,
10104 if (tree_view->priv->row_count > 0)
10108 if (clear_and_select && !(mode & PSPP_SHEET_SELECT_MODE_TOGGLE))
10109 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
10113 /* We have to re-find tree and node here again, somebody might have
10114 * cleared the node or the whole tree in the PsppSheetSelection::changed
10115 * callback. If the nodes differ we bail out here.
10117 _pspp_sheet_view_find_node (tree_view, path, &new_node);
10119 if (node != new_node)
10124 pspp_sheet_view_clamp_node_visible (tree_view, node);
10125 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
10129 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
10133 * pspp_sheet_view_get_cursor:
10134 * @tree_view: A #PsppSheetView
10135 * @path: (allow-none): A pointer to be filled with the current cursor path, or %NULL
10136 * @focus_column: (allow-none): A pointer to be filled with the current focus column, or %NULL
10138 * Fills in @path and @focus_column with the current path and focus column. If
10139 * the cursor isn't currently set, then *@path will be %NULL. If no column
10140 * currently has focus, then *@focus_column will be %NULL.
10142 * The returned #GtkTreePath must be freed with gtk_tree_path_free() when
10143 * you are done with it.
10146 pspp_sheet_view_get_cursor (PsppSheetView *tree_view,
10147 GtkTreePath **path,
10148 PsppSheetViewColumn **focus_column)
10150 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10154 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
10155 *path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
10162 *focus_column = tree_view->priv->focus_column;
10167 * pspp_sheet_view_set_cursor:
10168 * @tree_view: A #PsppSheetView
10169 * @path: A #GtkTreePath
10170 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
10171 * @start_editing: %TRUE if the specified cell should start being edited.
10173 * Sets the current keyboard focus to be at @path, and selects it. This is
10174 * useful when you want to focus the user's attention on a particular row. If
10175 * @focus_column is not %NULL, then focus is given to the column specified by
10176 * it. Additionally, if @focus_column is specified, and @start_editing is
10177 * %TRUE, then editing should be started in the specified cell.
10178 * This function is often followed by @gtk_widget_grab_focus (@tree_view)
10179 * in order to give keyboard focus to the widget. Please note that editing
10180 * can only happen when the widget is realized.
10182 * If @path is invalid for @model, the current cursor (if any) will be unset
10183 * and the function will return without failing.
10186 pspp_sheet_view_set_cursor (PsppSheetView *tree_view,
10188 PsppSheetViewColumn *focus_column,
10189 gboolean start_editing)
10191 pspp_sheet_view_set_cursor_on_cell (tree_view, path, focus_column,
10192 NULL, start_editing);
10196 * pspp_sheet_view_set_cursor_on_cell:
10197 * @tree_view: A #PsppSheetView
10198 * @path: A #GtkTreePath
10199 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
10200 * @focus_cell: (allow-none): A #GtkCellRenderer, or %NULL
10201 * @start_editing: %TRUE if the specified cell should start being edited.
10203 * Sets the current keyboard focus to be at @path, and selects it. This is
10204 * useful when you want to focus the user's attention on a particular row. If
10205 * @focus_column is not %NULL, then focus is given to the column specified by
10206 * it. If @focus_column and @focus_cell are not %NULL, and @focus_column
10207 * contains 2 or more editable or activatable cells, then focus is given to
10208 * the cell specified by @focus_cell. Additionally, if @focus_column is
10209 * specified, and @start_editing is %TRUE, then editing should be started in
10210 * the specified cell. This function is often followed by
10211 * @gtk_widget_grab_focus (@tree_view) in order to give keyboard focus to the
10212 * widget. Please note that editing can only happen when the widget is
10215 * If @path is invalid for @model, the current cursor (if any) will be unset
10216 * and the function will return without failing.
10221 pspp_sheet_view_set_cursor_on_cell (PsppSheetView *tree_view,
10223 PsppSheetViewColumn *focus_column,
10224 GtkCellRenderer *focus_cell,
10225 gboolean start_editing)
10227 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10228 g_return_if_fail (path != NULL);
10229 g_return_if_fail (focus_column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (focus_column));
10231 if (!tree_view->priv->model)
10236 g_return_if_fail (focus_column);
10237 g_return_if_fail (GTK_IS_CELL_RENDERER (focus_cell));
10240 /* cancel the current editing, if it exists */
10241 if (tree_view->priv->edited_column &&
10242 tree_view->priv->edited_column->editable_widget)
10243 pspp_sheet_view_stop_editing (tree_view, TRUE);
10245 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, 0);
10247 if (focus_column && focus_column->visible)
10250 gboolean column_in_tree = FALSE;
10252 for (list = tree_view->priv->columns; list; list = list->next)
10253 if (list->data == focus_column)
10255 column_in_tree = TRUE;
10258 g_return_if_fail (column_in_tree);
10259 tree_view->priv->focus_column = focus_column;
10261 pspp_sheet_view_column_focus_cell (focus_column, focus_cell);
10263 pspp_sheet_view_start_editing (tree_view, path);
10265 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
10266 pspp_sheet_selection_select_column (tree_view->priv->selection, focus_column);
10272 * pspp_sheet_view_get_bin_window:
10273 * @tree_view: A #PsppSheetView
10275 * Returns the window that @tree_view renders to. This is used primarily to
10276 * compare to <literal>event->window</literal> to confirm that the event on
10277 * @tree_view is on the right window.
10279 * Return value: A #GdkWindow, or %NULL when @tree_view hasn't been realized yet
10282 pspp_sheet_view_get_bin_window (PsppSheetView *tree_view)
10284 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
10286 return tree_view->priv->bin_window;
10290 * pspp_sheet_view_get_path_at_pos:
10291 * @tree_view: A #PsppSheetView.
10292 * @x: The x position to be identified (relative to bin_window).
10293 * @y: The y position to be identified (relative to bin_window).
10294 * @path: (out) (allow-none): A pointer to a #GtkTreePath pointer to be filled in, or %NULL
10295 * @column: (out) (allow-none): A pointer to a #PsppSheetViewColumn pointer to be filled in, or %NULL
10296 * @cell_x: (out) (allow-none): A pointer where the X coordinate relative to the cell can be placed, or %NULL
10297 * @cell_y: (out) (allow-none): A pointer where the Y coordinate relative to the cell can be placed, or %NULL
10299 * Finds the path at the point (@x, @y), relative to bin_window coordinates
10300 * (please see pspp_sheet_view_get_bin_window()).
10301 * That is, @x and @y are relative to an events coordinates. @x and @y must
10302 * come from an event on the @tree_view only where <literal>event->window ==
10303 * pspp_sheet_view_get_bin_window (<!-- -->)</literal>. It is primarily for
10304 * things like popup menus. If @path is non-%NULL, then it will be filled
10305 * with the #GtkTreePath at that point. This path should be freed with
10306 * gtk_tree_path_free(). If @column is non-%NULL, then it will be filled
10307 * with the column at that point. @cell_x and @cell_y return the coordinates
10308 * relative to the cell background (i.e. the @background_area passed to
10309 * gtk_cell_renderer_render()). This function is only meaningful if
10310 * @tree_view is realized. Therefore this function will always return %FALSE
10311 * if @tree_view is not realized or does not have a model.
10313 * For converting widget coordinates (eg. the ones you get from
10314 * GtkWidget::query-tooltip), please see
10315 * pspp_sheet_view_convert_widget_to_bin_window_coords().
10317 * Return value: %TRUE if a row exists at that coordinate.
10320 pspp_sheet_view_get_path_at_pos (PsppSheetView *tree_view,
10323 GtkTreePath **path,
10324 PsppSheetViewColumn **column,
10331 g_return_val_if_fail (tree_view != NULL, FALSE);
10338 if (tree_view->priv->bin_window == NULL)
10341 if (tree_view->priv->row_count == 0)
10344 if (x > gtk_adjustment_get_upper (tree_view->priv->hadjustment))
10347 if (x < 0 || y < 0)
10350 if (column || cell_x)
10352 PsppSheetViewColumn *tmp_column;
10353 PsppSheetViewColumn *last_column = NULL;
10355 gint remaining_x = x;
10356 gboolean found = FALSE;
10359 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
10360 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
10362 list = (rtl ? list->prev : list->next))
10364 tmp_column = list->data;
10366 if (tmp_column->visible == FALSE)
10369 last_column = tmp_column;
10370 if (remaining_x <= tmp_column->width)
10375 *column = tmp_column;
10378 *cell_x = remaining_x;
10382 remaining_x -= tmp_column->width;
10385 /* If found is FALSE and there is a last_column, then it the remainder
10386 * space is in that area
10393 *column = last_column;
10396 *cell_x = last_column->width + remaining_x;
10405 y_offset = pspp_sheet_view_find_offset (tree_view,
10406 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, y),
10413 *cell_y = y_offset;
10416 *path = _pspp_sheet_view_find_path (tree_view, node);
10421 /* Computes 'cell_area' from 'background_area', which must be the background
10422 area for a cell. Set 'subtract_focus_rect' to TRUE to compute the cell area
10423 as passed to a GtkCellRenderer's "render" function, or to FALSE to compute
10424 the cell area as passed to _pspp_sheet_view_column_cell_render().
10426 'column' is required to properly adjust 'cell_area->x' and
10427 'cell_area->width'. It may be set to NULL if these values are not of
10428 interest. In this case 'cell_area->x' and 'cell_area->width' will be
10431 pspp_sheet_view_adjust_cell_area (PsppSheetView *tree_view,
10432 PsppSheetViewColumn *column,
10433 const GdkRectangle *background_area,
10434 gboolean subtract_focus_rect,
10435 GdkRectangle *cell_area)
10437 gint vertical_separator;
10438 gint horizontal_separator;
10440 *cell_area = *background_area;
10442 gtk_widget_style_get (GTK_WIDGET (tree_view),
10443 "vertical-separator", &vertical_separator,
10444 "horizontal-separator", &horizontal_separator,
10446 cell_area->x += horizontal_separator / 2;
10447 cell_area->y += vertical_separator / 2;
10448 cell_area->width -= horizontal_separator;
10449 cell_area->height -= vertical_separator;
10451 if (subtract_focus_rect)
10453 int focus_line_width;
10455 gtk_widget_style_get (GTK_WIDGET (tree_view),
10456 "focus-line-width", &focus_line_width,
10458 cell_area->x += focus_line_width;
10459 cell_area->y += focus_line_width;
10460 cell_area->width -= 2 * focus_line_width;
10461 cell_area->height -= 2 * focus_line_width;
10464 if (tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_NONE)
10466 gint grid_line_width;
10467 gtk_widget_style_get (GTK_WIDGET (tree_view),
10468 "grid-line-width", &grid_line_width,
10471 if ((tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
10472 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10475 PsppSheetViewColumn *first_column, *last_column;
10478 /* Find the last visible column. */
10479 last_column = NULL;
10480 for (list = g_list_last (tree_view->priv->columns);
10484 PsppSheetViewColumn *c = list->data;
10492 /* Find the first visible column. */
10493 first_column = NULL;
10494 for (list = g_list_first (tree_view->priv->columns);
10498 PsppSheetViewColumn *c = list->data;
10506 if (column == first_column)
10508 cell_area->width -= grid_line_width / 2;
10510 else if (column == last_column)
10512 cell_area->x += grid_line_width / 2;
10513 cell_area->width -= grid_line_width / 2;
10517 cell_area->x += grid_line_width / 2;
10518 cell_area->width -= grid_line_width;
10522 if (tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
10523 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10525 cell_area->y += grid_line_width / 2;
10526 cell_area->height -= grid_line_width;
10530 if (column == NULL)
10533 cell_area->width = 0;
10538 * pspp_sheet_view_get_cell_area:
10539 * @tree_view: a #PsppSheetView
10540 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10541 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordinates
10542 * @rect: rectangle to fill with cell rect
10544 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10545 * row specified by @path and the column specified by @column. If @path is
10546 * %NULL, or points to a path not currently displayed, the @y and @height fields
10547 * of the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10548 * fields will be filled with 0. The sum of all cell rects does not cover the
10549 * entire tree; there are extra pixels in between rows, for example. The
10550 * returned rectangle is equivalent to the @cell_area passed to
10551 * gtk_cell_renderer_render(). This function is only valid if @tree_view is
10555 pspp_sheet_view_get_cell_area (PsppSheetView *tree_view,
10557 PsppSheetViewColumn *column,
10558 GdkRectangle *rect)
10560 GdkRectangle background_area;
10562 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10563 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10564 g_return_if_fail (rect != NULL);
10565 g_return_if_fail (!column || column->tree_view == (GtkWidget *) tree_view);
10566 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
10568 pspp_sheet_view_get_background_area (tree_view, path, column,
10570 pspp_sheet_view_adjust_cell_area (tree_view, column, &background_area,
10575 * pspp_sheet_view_get_background_area:
10576 * @tree_view: a #PsppSheetView
10577 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10578 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordiantes
10579 * @rect: rectangle to fill with cell background rect
10581 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10582 * row specified by @path and the column specified by @column. If @path is
10583 * %NULL, or points to a node not found in the tree, the @y and @height fields of
10584 * the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10585 * fields will be filled with 0. The returned rectangle is equivalent to the
10586 * @background_area passed to gtk_cell_renderer_render(). These background
10587 * areas tile to cover the entire bin window. Contrast with the @cell_area,
10588 * returned by pspp_sheet_view_get_cell_area(), which returns only the cell
10589 * itself, excluding surrounding borders.
10593 pspp_sheet_view_get_background_area (PsppSheetView *tree_view,
10595 PsppSheetViewColumn *column,
10596 GdkRectangle *rect)
10600 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10601 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10602 g_return_if_fail (rect != NULL);
10611 /* Get vertical coords */
10613 _pspp_sheet_view_find_node (tree_view, path, &node);
10617 rect->y = BACKGROUND_FIRST_PIXEL (tree_view, node);
10619 rect->height = ROW_HEIGHT (tree_view);
10626 pspp_sheet_view_get_background_xrange (tree_view, column, &rect->x, &x2);
10627 rect->width = x2 - rect->x;
10632 * pspp_sheet_view_get_visible_rect:
10633 * @tree_view: a #PsppSheetView
10634 * @visible_rect: rectangle to fill
10636 * Fills @visible_rect with the currently-visible region of the
10637 * buffer, in tree coordinates. Convert to bin_window coordinates with
10638 * pspp_sheet_view_convert_tree_to_bin_window_coords().
10639 * Tree coordinates start at 0,0 for row 0 of the tree, and cover the entire
10640 * scrollable area of the tree.
10643 pspp_sheet_view_get_visible_rect (PsppSheetView *tree_view,
10644 GdkRectangle *visible_rect)
10648 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10650 widget = GTK_WIDGET (tree_view);
10654 GtkAllocation allocation;
10655 gtk_widget_get_allocation (widget, &allocation);
10656 visible_rect->x = gtk_adjustment_get_value (tree_view->priv->hadjustment);
10657 visible_rect->y = gtk_adjustment_get_value (tree_view->priv->vadjustment);
10658 visible_rect->width = allocation.width;
10659 visible_rect->height = allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
10664 * pspp_sheet_view_widget_to_tree_coords:
10665 * @tree_view: a #PsppSheetView
10666 * @wx: X coordinate relative to bin_window
10667 * @wy: Y coordinate relative to bin_window
10668 * @tx: return location for tree X coordinate
10669 * @ty: return location for tree Y coordinate
10671 * Converts bin_window coordinates to coordinates for the
10672 * tree (the full scrollable area of the tree).
10674 * Deprecated: 2.12: Due to historial reasons the name of this function is
10675 * incorrect. For converting coordinates relative to the widget to
10676 * bin_window coordinates, please see
10677 * pspp_sheet_view_convert_widget_to_bin_window_coords().
10681 pspp_sheet_view_widget_to_tree_coords (PsppSheetView *tree_view,
10687 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10690 *tx = wx + gtk_adjustment_get_value (tree_view->priv->hadjustment);
10692 *ty = wy + tree_view->priv->dy;
10696 * pspp_sheet_view_tree_to_widget_coords:
10697 * @tree_view: a #PsppSheetView
10698 * @tx: tree X coordinate
10699 * @ty: tree Y coordinate
10700 * @wx: return location for X coordinate relative to bin_window
10701 * @wy: return location for Y coordinate relative to bin_window
10703 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10704 * to bin_window coordinates.
10706 * Deprecated: 2.12: Due to historial reasons the name of this function is
10707 * incorrect. For converting bin_window coordinates to coordinates relative
10708 * to bin_window, please see
10709 * pspp_sheet_view_convert_bin_window_to_widget_coords().
10713 pspp_sheet_view_tree_to_widget_coords (PsppSheetView *tree_view,
10719 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10722 *wx = tx - gtk_adjustment_get_value (tree_view->priv->hadjustment);
10724 *wy = ty - tree_view->priv->dy;
10729 * pspp_sheet_view_convert_widget_to_tree_coords:
10730 * @tree_view: a #PsppSheetView
10731 * @wx: X coordinate relative to the widget
10732 * @wy: Y coordinate relative to the widget
10733 * @tx: return location for tree X coordinate
10734 * @ty: return location for tree Y coordinate
10736 * Converts widget coordinates to coordinates for the
10737 * tree (the full scrollable area of the tree).
10742 pspp_sheet_view_convert_widget_to_tree_coords (PsppSheetView *tree_view,
10750 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10752 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view,
10755 pspp_sheet_view_convert_bin_window_to_tree_coords (tree_view,
10761 * pspp_sheet_view_convert_tree_to_widget_coords:
10762 * @tree_view: a #PsppSheetView
10763 * @tx: X coordinate relative to the tree
10764 * @ty: Y coordinate relative to the tree
10765 * @wx: return location for widget X coordinate
10766 * @wy: return location for widget Y coordinate
10768 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10769 * to widget coordinates.
10774 pspp_sheet_view_convert_tree_to_widget_coords (PsppSheetView *tree_view,
10782 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10784 pspp_sheet_view_convert_tree_to_bin_window_coords (tree_view,
10787 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
10793 * pspp_sheet_view_convert_widget_to_bin_window_coords:
10794 * @tree_view: a #PsppSheetView
10795 * @wx: X coordinate relative to the widget
10796 * @wy: Y coordinate relative to the widget
10797 * @bx: return location for bin_window X coordinate
10798 * @by: return location for bin_window Y coordinate
10800 * Converts widget coordinates to coordinates for the bin_window
10801 * (see pspp_sheet_view_get_bin_window()).
10806 pspp_sheet_view_convert_widget_to_bin_window_coords (PsppSheetView *tree_view,
10812 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10815 *bx = wx + gtk_adjustment_get_value (tree_view->priv->hadjustment);
10817 *by = wy - TREE_VIEW_HEADER_HEIGHT (tree_view);
10821 * pspp_sheet_view_convert_bin_window_to_widget_coords:
10822 * @tree_view: a #PsppSheetView
10823 * @bx: bin_window X coordinate
10824 * @by: bin_window Y coordinate
10825 * @wx: return location for widget X coordinate
10826 * @wy: return location for widget Y coordinate
10828 * Converts bin_window coordinates (see pspp_sheet_view_get_bin_window())
10829 * to widget relative coordinates.
10834 pspp_sheet_view_convert_bin_window_to_widget_coords (PsppSheetView *tree_view,
10840 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10843 *wx = bx - gtk_adjustment_get_value (tree_view->priv->hadjustment);
10845 *wy = by + TREE_VIEW_HEADER_HEIGHT (tree_view);
10849 * pspp_sheet_view_convert_tree_to_bin_window_coords:
10850 * @tree_view: a #PsppSheetView
10851 * @tx: tree X coordinate
10852 * @ty: tree Y coordinate
10853 * @bx: return location for X coordinate relative to bin_window
10854 * @by: return location for Y coordinate relative to bin_window
10856 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10857 * to bin_window coordinates.
10862 pspp_sheet_view_convert_tree_to_bin_window_coords (PsppSheetView *tree_view,
10868 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10873 *by = ty - tree_view->priv->dy;
10877 * pspp_sheet_view_convert_bin_window_to_tree_coords:
10878 * @tree_view: a #PsppSheetView
10879 * @bx: X coordinate relative to bin_window
10880 * @by: Y coordinate relative to bin_window
10881 * @tx: return location for tree X coordinate
10882 * @ty: return location for tree Y coordinate
10884 * Converts bin_window coordinates to coordinates for the
10885 * tree (the full scrollable area of the tree).
10890 pspp_sheet_view_convert_bin_window_to_tree_coords (PsppSheetView *tree_view,
10896 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10901 *ty = by + tree_view->priv->dy;
10907 * pspp_sheet_view_get_visible_range:
10908 * @tree_view: A #PsppSheetView
10909 * @start_path: (allow-none): Return location for start of region, or %NULL.
10910 * @end_path: (allow-none): Return location for end of region, or %NULL.
10912 * Sets @start_path and @end_path to be the first and last visible path.
10913 * Note that there may be invisible paths in between.
10915 * The paths should be freed with gtk_tree_path_free() after use.
10917 * Returns: %TRUE, if valid paths were placed in @start_path and @end_path.
10922 pspp_sheet_view_get_visible_range (PsppSheetView *tree_view,
10923 GtkTreePath **start_path,
10924 GtkTreePath **end_path)
10929 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
10931 if (!tree_view->priv->row_count)
10938 pspp_sheet_view_find_offset (tree_view,
10939 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, 0),
10942 *start_path = _pspp_sheet_view_find_path (tree_view, node);
10951 if (tree_view->priv->height < gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
10952 y = tree_view->priv->height - 1;
10954 y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, gtk_adjustment_get_page_size (tree_view->priv->vadjustment)) - 1;
10956 pspp_sheet_view_find_offset (tree_view, y, &node);
10958 *end_path = _pspp_sheet_view_find_path (tree_view, node);
10967 unset_reorderable (PsppSheetView *tree_view)
10969 if (tree_view->priv->reorderable)
10971 tree_view->priv->reorderable = FALSE;
10972 g_object_notify (G_OBJECT (tree_view), "reorderable");
10977 * pspp_sheet_view_enable_model_drag_source:
10978 * @tree_view: a #PsppSheetView
10979 * @start_button_mask: Mask of allowed buttons to start drag
10980 * @targets: the table of targets that the drag will support
10981 * @n_targets: the number of items in @targets
10982 * @actions: the bitmask of possible actions for a drag from this
10985 * Turns @tree_view into a drag source for automatic DND. Calling this
10986 * method sets #PsppSheetView:reorderable to %FALSE.
10989 pspp_sheet_view_enable_model_drag_source (PsppSheetView *tree_view,
10990 GdkModifierType start_button_mask,
10991 const GtkTargetEntry *targets,
10993 GdkDragAction actions)
10995 TreeViewDragInfo *di;
10997 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10999 gtk_drag_source_set (GTK_WIDGET (tree_view),
11005 di = ensure_info (tree_view);
11007 di->start_button_mask = start_button_mask;
11008 di->source_actions = actions;
11009 di->source_set = TRUE;
11011 unset_reorderable (tree_view);
11015 * pspp_sheet_view_enable_model_drag_dest:
11016 * @tree_view: a #PsppSheetView
11017 * @targets: the table of targets that the drag will support
11018 * @n_targets: the number of items in @targets
11019 * @actions: the bitmask of possible actions for a drag from this
11022 * Turns @tree_view into a drop destination for automatic DND. Calling
11023 * this method sets #PsppSheetView:reorderable to %FALSE.
11026 pspp_sheet_view_enable_model_drag_dest (PsppSheetView *tree_view,
11027 const GtkTargetEntry *targets,
11029 GdkDragAction actions)
11031 TreeViewDragInfo *di;
11033 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11035 gtk_drag_dest_set (GTK_WIDGET (tree_view),
11041 di = ensure_info (tree_view);
11042 di->dest_set = TRUE;
11044 unset_reorderable (tree_view);
11048 * pspp_sheet_view_unset_rows_drag_source:
11049 * @tree_view: a #PsppSheetView
11051 * Undoes the effect of
11052 * pspp_sheet_view_enable_model_drag_source(). Calling this method sets
11053 * #PsppSheetView:reorderable to %FALSE.
11056 pspp_sheet_view_unset_rows_drag_source (PsppSheetView *tree_view)
11058 TreeViewDragInfo *di;
11060 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11062 di = get_info (tree_view);
11066 if (di->source_set)
11068 gtk_drag_source_unset (GTK_WIDGET (tree_view));
11069 di->source_set = FALSE;
11072 if (!di->dest_set && !di->source_set)
11073 remove_info (tree_view);
11076 unset_reorderable (tree_view);
11080 * pspp_sheet_view_unset_rows_drag_dest:
11081 * @tree_view: a #PsppSheetView
11083 * Undoes the effect of
11084 * pspp_sheet_view_enable_model_drag_dest(). Calling this method sets
11085 * #PsppSheetView:reorderable to %FALSE.
11088 pspp_sheet_view_unset_rows_drag_dest (PsppSheetView *tree_view)
11090 TreeViewDragInfo *di;
11092 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11094 di = get_info (tree_view);
11100 gtk_drag_dest_unset (GTK_WIDGET (tree_view));
11101 di->dest_set = FALSE;
11104 if (!di->dest_set && !di->source_set)
11105 remove_info (tree_view);
11108 unset_reorderable (tree_view);
11112 * pspp_sheet_view_set_drag_dest_row:
11113 * @tree_view: a #PsppSheetView
11114 * @path: (allow-none): The path of the row to highlight, or %NULL.
11115 * @pos: Specifies whether to drop before, after or into the row
11117 * Sets the row that is highlighted for feedback.
11120 pspp_sheet_view_set_drag_dest_row (PsppSheetView *tree_view,
11122 PsppSheetViewDropPosition pos)
11124 GtkTreePath *current_dest;
11126 /* Note; this function is exported to allow a custom DND
11127 * implementation, so it can't touch TreeViewDragInfo
11130 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11132 current_dest = NULL;
11134 if (tree_view->priv->drag_dest_row)
11136 current_dest = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
11137 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
11140 /* special case a drop on an empty model */
11141 tree_view->priv->empty_view_drop = 0;
11143 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE && path
11144 && gtk_tree_path_get_depth (path) == 1
11145 && gtk_tree_path_get_indices (path)[0] == 0)
11149 n_children = gtk_tree_model_iter_n_children (tree_view->priv->model,
11153 tree_view->priv->empty_view_drop = 1;
11156 tree_view->priv->drag_dest_pos = pos;
11160 tree_view->priv->drag_dest_row =
11161 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
11162 pspp_sheet_view_queue_draw_path (tree_view, path, NULL);
11165 tree_view->priv->drag_dest_row = NULL;
11169 int node, new_node;
11171 _pspp_sheet_view_find_node (tree_view, current_dest, &node);
11172 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
11176 new_node = pspp_sheet_view_node_next (tree_view, node);
11178 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
11180 new_node = pspp_sheet_view_node_prev (tree_view, node);
11182 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
11184 gtk_tree_path_free (current_dest);
11189 * pspp_sheet_view_get_drag_dest_row:
11190 * @tree_view: a #PsppSheetView
11191 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
11192 * @pos: (allow-none): Return location for the drop position, or %NULL
11194 * Gets information about the row that is highlighted for feedback.
11197 pspp_sheet_view_get_drag_dest_row (PsppSheetView *tree_view,
11198 GtkTreePath **path,
11199 PsppSheetViewDropPosition *pos)
11201 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11205 if (tree_view->priv->drag_dest_row)
11206 *path = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
11209 if (tree_view->priv->empty_view_drop)
11210 *path = gtk_tree_path_new_from_indices (0, -1);
11217 *pos = tree_view->priv->drag_dest_pos;
11221 * pspp_sheet_view_get_dest_row_at_pos:
11222 * @tree_view: a #PsppSheetView
11223 * @drag_x: the position to determine the destination row for
11224 * @drag_y: the position to determine the destination row for
11225 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
11226 * @pos: (allow-none): Return location for the drop position, or %NULL
11228 * Determines the destination row for a given position. @drag_x and
11229 * @drag_y are expected to be in widget coordinates. This function is only
11230 * meaningful if @tree_view is realized. Therefore this function will always
11231 * return %FALSE if @tree_view is not realized or does not have a model.
11233 * Return value: whether there is a row at the given position, %TRUE if this
11234 * is indeed the case.
11237 pspp_sheet_view_get_dest_row_at_pos (PsppSheetView *tree_view,
11240 GtkTreePath **path,
11241 PsppSheetViewDropPosition *pos)
11245 gdouble offset_into_row;
11248 PsppSheetViewColumn *column = NULL;
11249 GtkTreePath *tmp_path = NULL;
11251 /* Note; this function is exported to allow a custom DND
11252 * implementation, so it can't touch TreeViewDragInfo
11255 g_return_val_if_fail (tree_view != NULL, FALSE);
11256 g_return_val_if_fail (drag_x >= 0, FALSE);
11257 g_return_val_if_fail (drag_y >= 0, FALSE);
11262 if (tree_view->priv->bin_window == NULL)
11265 if (tree_view->priv->row_count == 0)
11268 /* If in the top third of a row, we drop before that row; if
11269 * in the bottom third, drop after that row; if in the middle,
11270 * and the row has children, drop into the row.
11272 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, drag_x, drag_y,
11275 if (!pspp_sheet_view_get_path_at_pos (tree_view,
11284 pspp_sheet_view_get_background_area (tree_view, tmp_path, column,
11287 offset_into_row = cell_y;
11292 gtk_tree_path_free (tmp_path);
11296 third = cell.height / 3.0;
11300 if (offset_into_row < third)
11302 *pos = PSPP_SHEET_VIEW_DROP_BEFORE;
11304 else if (offset_into_row < (cell.height / 2.0))
11306 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE;
11308 else if (offset_into_row < third * 2.0)
11310 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER;
11314 *pos = PSPP_SHEET_VIEW_DROP_AFTER;
11322 #if GTK3_TRANSITION
11323 /* KEEP IN SYNC WITH PSPP_SHEET_VIEW_BIN_EXPOSE */
11325 * pspp_sheet_view_create_row_drag_icon:
11326 * @tree_view: a #PsppSheetView
11327 * @path: a #GtkTreePath in @tree_view
11329 * Creates a #GdkPixmap representation of the row at @path.
11330 * This image is used for a drag icon.
11332 * Return value: a newly-allocated pixmap of the drag icon.
11335 pspp_sheet_view_create_row_drag_icon (PsppSheetView *tree_view,
11342 GdkRectangle background_area;
11343 GdkRectangle expose_area;
11345 /* start drawing inside the black outline */
11347 GdkDrawable *drawable;
11348 gint bin_window_width;
11351 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11352 g_return_val_if_fail (path != NULL, NULL);
11354 widget = GTK_WIDGET (tree_view);
11356 if (!gtk_widget_get_realized (widget))
11359 _pspp_sheet_view_find_node (tree_view,
11366 if (!gtk_tree_model_get_iter (tree_view->priv->model,
11373 background_area.y = y;
11374 background_area.height = ROW_HEIGHT (tree_view);
11376 bin_window_width = gdk_window_get_width (tree_view->priv->bin_window);
11378 drawable = gdk_pixmap_new (tree_view->priv->bin_window,
11379 bin_window_width + 2,
11380 background_area.height + 2,
11385 expose_area.width = bin_window_width + 2;
11386 expose_area.height = background_area.height + 2;
11388 #if GTK3_TRANSITION
11389 gdk_draw_rectangle (drawable,
11390 widget->style->base_gc [gtk_widget_get_state (widget)],
11393 bin_window_width + 2,
11394 background_area.height + 2);
11397 rtl = gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL;
11399 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
11401 list = (rtl ? list->prev : list->next))
11403 PsppSheetViewColumn *column = list->data;
11404 GdkRectangle cell_area;
11405 gint vertical_separator;
11407 if (!column->visible)
11410 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, &iter);
11412 background_area.x = cell_offset;
11413 background_area.width = column->width;
11415 gtk_widget_style_get (widget,
11416 "vertical-separator", &vertical_separator,
11419 cell_area = background_area;
11421 cell_area.y += vertical_separator / 2;
11422 cell_area.height -= vertical_separator;
11424 if (pspp_sheet_view_column_cell_is_visible (column))
11425 _pspp_sheet_view_column_cell_render (column,
11431 cell_offset += column->width;
11434 #if GTK3_TRANSITION
11435 gdk_draw_rectangle (drawable,
11436 widget->style->black_gc,
11439 bin_window_width + 1,
11440 background_area.height + 1);
11448 * pspp_sheet_view_set_destroy_count_func:
11449 * @tree_view: A #PsppSheetView
11450 * @func: (allow-none): Function to be called when a view row is destroyed, or %NULL
11451 * @data: (allow-none): User data to be passed to @func, or %NULL
11452 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11454 * This function should almost never be used. It is meant for private use by
11455 * ATK for determining the number of visible children that are removed when a row is deleted.
11458 pspp_sheet_view_set_destroy_count_func (PsppSheetView *tree_view,
11459 PsppSheetDestroyCountFunc func,
11461 GDestroyNotify destroy)
11463 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11465 if (tree_view->priv->destroy_count_destroy)
11466 tree_view->priv->destroy_count_destroy (tree_view->priv->destroy_count_data);
11468 tree_view->priv->destroy_count_func = func;
11469 tree_view->priv->destroy_count_data = data;
11470 tree_view->priv->destroy_count_destroy = destroy;
11475 * Interactive search
11479 * pspp_sheet_view_set_enable_search:
11480 * @tree_view: A #PsppSheetView
11481 * @enable_search: %TRUE, if the user can search interactively
11483 * If @enable_search is set, then the user can type in text to search through
11484 * the tree interactively (this is sometimes called "typeahead find").
11486 * Note that even if this is %FALSE, the user can still initiate a search
11487 * using the "start-interactive-search" key binding.
11490 pspp_sheet_view_set_enable_search (PsppSheetView *tree_view,
11491 gboolean enable_search)
11493 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11495 enable_search = !!enable_search;
11497 if (tree_view->priv->enable_search != enable_search)
11499 tree_view->priv->enable_search = enable_search;
11500 g_object_notify (G_OBJECT (tree_view), "enable-search");
11505 * pspp_sheet_view_get_enable_search:
11506 * @tree_view: A #PsppSheetView
11508 * Returns whether or not the tree allows to start interactive searching
11509 * by typing in text.
11511 * Return value: whether or not to let the user search interactively
11514 pspp_sheet_view_get_enable_search (PsppSheetView *tree_view)
11516 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11518 return tree_view->priv->enable_search;
11523 * pspp_sheet_view_get_search_column:
11524 * @tree_view: A #PsppSheetView
11526 * Gets the column searched on by the interactive search code.
11528 * Return value: the column the interactive search code searches in.
11531 pspp_sheet_view_get_search_column (PsppSheetView *tree_view)
11533 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
11535 return (tree_view->priv->search_column);
11539 * pspp_sheet_view_set_search_column:
11540 * @tree_view: A #PsppSheetView
11541 * @column: the column of the model to search in, or -1 to disable searching
11543 * Sets @column as the column where the interactive search code should
11544 * search in for the current model.
11546 * If the search column is set, users can use the "start-interactive-search"
11547 * key binding to bring up search popup. The enable-search property controls
11548 * whether simply typing text will also start an interactive search.
11550 * Note that @column refers to a column of the current model. The search
11551 * column is reset to -1 when the model is changed.
11554 pspp_sheet_view_set_search_column (PsppSheetView *tree_view,
11557 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11558 g_return_if_fail (column >= -1);
11560 if (tree_view->priv->search_column == column)
11563 tree_view->priv->search_column = column;
11564 g_object_notify (G_OBJECT (tree_view), "search-column");
11568 * pspp_sheet_view_get_search_equal_func:
11569 * @tree_view: A #PsppSheetView
11571 * Returns the compare function currently in use.
11573 * Return value: the currently used compare function for the search code.
11576 PsppSheetViewSearchEqualFunc
11577 pspp_sheet_view_get_search_equal_func (PsppSheetView *tree_view)
11579 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11581 return tree_view->priv->search_equal_func;
11585 * pspp_sheet_view_set_search_equal_func:
11586 * @tree_view: A #PsppSheetView
11587 * @search_equal_func: the compare function to use during the search
11588 * @search_user_data: (allow-none): user data to pass to @search_equal_func, or %NULL
11589 * @search_destroy: (allow-none): Destroy notifier for @search_user_data, or %NULL
11591 * Sets the compare function for the interactive search capabilities; note
11592 * that somewhat like strcmp() returning 0 for equality
11593 * #PsppSheetViewSearchEqualFunc returns %FALSE on matches.
11596 pspp_sheet_view_set_search_equal_func (PsppSheetView *tree_view,
11597 PsppSheetViewSearchEqualFunc search_equal_func,
11598 gpointer search_user_data,
11599 GDestroyNotify search_destroy)
11601 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11602 g_return_if_fail (search_equal_func != NULL);
11604 if (tree_view->priv->search_destroy)
11605 tree_view->priv->search_destroy (tree_view->priv->search_user_data);
11607 tree_view->priv->search_equal_func = search_equal_func;
11608 tree_view->priv->search_user_data = search_user_data;
11609 tree_view->priv->search_destroy = search_destroy;
11610 if (tree_view->priv->search_equal_func == NULL)
11611 tree_view->priv->search_equal_func = pspp_sheet_view_search_equal_func;
11615 * pspp_sheet_view_get_search_entry:
11616 * @tree_view: A #PsppSheetView
11618 * Returns the #GtkEntry which is currently in use as interactive search
11619 * entry for @tree_view. In case the built-in entry is being used, %NULL
11620 * will be returned.
11622 * Return value: the entry currently in use as search entry.
11627 pspp_sheet_view_get_search_entry (PsppSheetView *tree_view)
11629 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11631 if (tree_view->priv->search_custom_entry_set)
11632 return GTK_ENTRY (tree_view->priv->search_entry);
11638 * pspp_sheet_view_set_search_entry:
11639 * @tree_view: A #PsppSheetView
11640 * @entry: (allow-none): the entry the interactive search code of @tree_view should use or %NULL
11642 * Sets the entry which the interactive search code will use for this
11643 * @tree_view. This is useful when you want to provide a search entry
11644 * in our interface at all time at a fixed position. Passing %NULL for
11645 * @entry will make the interactive search code use the built-in popup
11651 pspp_sheet_view_set_search_entry (PsppSheetView *tree_view,
11654 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11655 g_return_if_fail (entry == NULL || GTK_IS_ENTRY (entry));
11657 if (tree_view->priv->search_custom_entry_set)
11659 if (tree_view->priv->search_entry_changed_id)
11661 g_signal_handler_disconnect (tree_view->priv->search_entry,
11662 tree_view->priv->search_entry_changed_id);
11663 tree_view->priv->search_entry_changed_id = 0;
11665 g_signal_handlers_disconnect_by_func (tree_view->priv->search_entry,
11666 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11669 g_object_unref (tree_view->priv->search_entry);
11671 else if (tree_view->priv->search_window)
11673 gtk_widget_destroy (tree_view->priv->search_window);
11675 tree_view->priv->search_window = NULL;
11680 tree_view->priv->search_entry = g_object_ref (entry);
11681 tree_view->priv->search_custom_entry_set = TRUE;
11683 if (tree_view->priv->search_entry_changed_id == 0)
11685 tree_view->priv->search_entry_changed_id =
11686 g_signal_connect (tree_view->priv->search_entry, "changed",
11687 G_CALLBACK (pspp_sheet_view_search_init),
11691 g_signal_connect (tree_view->priv->search_entry, "key-press-event",
11692 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11695 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
11699 tree_view->priv->search_entry = NULL;
11700 tree_view->priv->search_custom_entry_set = FALSE;
11705 * pspp_sheet_view_set_search_position_func:
11706 * @tree_view: A #PsppSheetView
11707 * @func: (allow-none): the function to use to position the search dialog, or %NULL
11708 * to use the default search position function
11709 * @data: (allow-none): user data to pass to @func, or %NULL
11710 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11712 * Sets the function to use when positioning the search dialog.
11717 pspp_sheet_view_set_search_position_func (PsppSheetView *tree_view,
11718 PsppSheetViewSearchPositionFunc func,
11719 gpointer user_data,
11720 GDestroyNotify destroy)
11722 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11724 if (tree_view->priv->search_position_destroy)
11725 tree_view->priv->search_position_destroy (tree_view->priv->search_position_user_data);
11727 tree_view->priv->search_position_func = func;
11728 tree_view->priv->search_position_user_data = user_data;
11729 tree_view->priv->search_position_destroy = destroy;
11730 if (tree_view->priv->search_position_func == NULL)
11731 tree_view->priv->search_position_func = pspp_sheet_view_search_position_func;
11735 * pspp_sheet_view_get_search_position_func:
11736 * @tree_view: A #PsppSheetView
11738 * Returns the positioning function currently in use.
11740 * Return value: the currently used function for positioning the search dialog.
11744 PsppSheetViewSearchPositionFunc
11745 pspp_sheet_view_get_search_position_func (PsppSheetView *tree_view)
11747 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11749 return tree_view->priv->search_position_func;
11754 pspp_sheet_view_search_dialog_hide (GtkWidget *search_dialog,
11755 PsppSheetView *tree_view)
11757 if (tree_view->priv->disable_popdown)
11760 if (tree_view->priv->search_entry_changed_id)
11762 g_signal_handler_disconnect (tree_view->priv->search_entry,
11763 tree_view->priv->search_entry_changed_id);
11764 tree_view->priv->search_entry_changed_id = 0;
11766 if (tree_view->priv->typeselect_flush_timeout)
11768 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11769 tree_view->priv->typeselect_flush_timeout = 0;
11772 if (gtk_widget_get_visible (search_dialog))
11774 /* send focus-in event */
11775 send_focus_change (GTK_WIDGET (tree_view->priv->search_entry), FALSE);
11776 gtk_widget_hide (search_dialog);
11777 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
11778 send_focus_change (GTK_WIDGET (tree_view), TRUE);
11783 pspp_sheet_view_search_position_func (PsppSheetView *tree_view,
11784 GtkWidget *search_dialog,
11785 gpointer user_data)
11788 gint tree_x, tree_y;
11789 gint tree_width, tree_height;
11790 GdkWindow *tree_window = gtk_widget_get_window (GTK_WIDGET (tree_view));
11791 GdkScreen *screen = gdk_window_get_screen (tree_window);
11792 GtkRequisition requisition;
11794 GdkRectangle monitor;
11796 monitor_num = gdk_screen_get_monitor_at_window (screen, tree_window);
11797 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
11799 gtk_widget_realize (search_dialog);
11801 gdk_window_get_origin (tree_window, &tree_x, &tree_y);
11802 tree_width = gdk_window_get_width (tree_window);
11803 tree_height = gdk_window_get_height (tree_window);
11805 gtk_widget_size_request (search_dialog, &requisition);
11807 if (tree_x + tree_width > gdk_screen_get_width (screen))
11808 x = gdk_screen_get_width (screen) - requisition.width;
11809 else if (tree_x + tree_width - requisition.width < 0)
11812 x = tree_x + tree_width - requisition.width;
11814 if (tree_y + tree_height + requisition.height > gdk_screen_get_height (screen))
11815 y = gdk_screen_get_height (screen) - requisition.height;
11816 else if (tree_y + tree_height < 0) /* isn't really possible ... */
11819 y = tree_y + tree_height;
11821 gtk_window_move (GTK_WINDOW (search_dialog), x, y);
11825 pspp_sheet_view_search_disable_popdown (GtkEntry *entry,
11829 PsppSheetView *tree_view = (PsppSheetView *)data;
11831 tree_view->priv->disable_popdown = 1;
11832 g_signal_connect (menu, "hide",
11833 G_CALLBACK (pspp_sheet_view_search_enable_popdown), data);
11836 #if GTK3_TRANSITION
11837 /* Because we're visible but offscreen, we just set a flag in the preedit
11841 pspp_sheet_view_search_preedit_changed (GtkIMContext *im_context,
11842 PsppSheetView *tree_view)
11844 tree_view->priv->imcontext_changed = 1;
11845 if (tree_view->priv->typeselect_flush_timeout)
11847 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11848 tree_view->priv->typeselect_flush_timeout =
11849 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11850 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11858 pspp_sheet_view_search_activate (GtkEntry *entry,
11859 PsppSheetView *tree_view)
11864 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window,
11867 /* If we have a row selected and it's the cursor row, we activate
11869 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
11871 path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
11873 _pspp_sheet_view_find_node (tree_view, path, &node);
11875 if (node >= 0 && pspp_sheet_view_node_is_selected (tree_view, node))
11876 pspp_sheet_view_row_activated (tree_view, path, tree_view->priv->focus_column);
11878 gtk_tree_path_free (path);
11883 pspp_sheet_view_real_search_enable_popdown (gpointer data)
11885 PsppSheetView *tree_view = (PsppSheetView *)data;
11887 tree_view->priv->disable_popdown = 0;
11893 pspp_sheet_view_search_enable_popdown (GtkWidget *widget,
11896 gdk_threads_add_timeout_full (G_PRIORITY_HIGH, 200, pspp_sheet_view_real_search_enable_popdown, g_object_ref (data), g_object_unref);
11900 pspp_sheet_view_search_delete_event (GtkWidget *widget,
11901 GdkEventAny *event,
11902 PsppSheetView *tree_view)
11904 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11906 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11912 pspp_sheet_view_search_button_press_event (GtkWidget *widget,
11913 GdkEventButton *event,
11914 PsppSheetView *tree_view)
11916 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11918 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11920 if (event->window == tree_view->priv->bin_window)
11921 pspp_sheet_view_button_press (GTK_WIDGET (tree_view), event);
11927 pspp_sheet_view_search_scroll_event (GtkWidget *widget,
11928 GdkEventScroll *event,
11929 PsppSheetView *tree_view)
11931 gboolean retval = FALSE;
11933 if (event->direction == GDK_SCROLL_UP)
11935 pspp_sheet_view_search_move (widget, tree_view, TRUE);
11938 else if (event->direction == GDK_SCROLL_DOWN)
11940 pspp_sheet_view_search_move (widget, tree_view, FALSE);
11944 /* renew the flush timeout */
11945 if (retval && tree_view->priv->typeselect_flush_timeout
11946 && !tree_view->priv->search_custom_entry_set)
11948 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11949 tree_view->priv->typeselect_flush_timeout =
11950 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11951 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11959 pspp_sheet_view_search_key_press_event (GtkWidget *widget,
11960 GdkEventKey *event,
11961 PsppSheetView *tree_view)
11963 gboolean retval = FALSE;
11965 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11966 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11968 /* close window and cancel the search */
11969 if (!tree_view->priv->search_custom_entry_set
11970 && (event->keyval == GDK_Escape ||
11971 event->keyval == GDK_Tab ||
11972 event->keyval == GDK_KP_Tab ||
11973 event->keyval == GDK_ISO_Left_Tab))
11975 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11979 /* select previous matching iter */
11980 if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up)
11982 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
11983 gtk_widget_error_bell (widget);
11988 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK))
11989 && (event->keyval == GDK_g || event->keyval == GDK_G))
11991 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
11992 gtk_widget_error_bell (widget);
11997 /* select next matching iter */
11998 if (event->keyval == GDK_Down || event->keyval == GDK_KP_Down)
12000 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
12001 gtk_widget_error_bell (widget);
12006 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == GTK_DEFAULT_ACCEL_MOD_MASK)
12007 && (event->keyval == GDK_g || event->keyval == GDK_G))
12009 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
12010 gtk_widget_error_bell (widget);
12015 /* renew the flush timeout */
12016 if (retval && tree_view->priv->typeselect_flush_timeout
12017 && !tree_view->priv->search_custom_entry_set)
12019 g_source_remove (tree_view->priv->typeselect_flush_timeout);
12020 tree_view->priv->typeselect_flush_timeout =
12021 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
12022 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
12029 /* this function returns FALSE if there is a search string but
12030 * nothing was found, and TRUE otherwise.
12033 pspp_sheet_view_search_move (GtkWidget *window,
12034 PsppSheetView *tree_view,
12042 GtkTreeModel *model;
12043 PsppSheetSelection *selection;
12045 text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
12047 g_return_val_if_fail (text != NULL, FALSE);
12049 len = strlen (text);
12051 if (up && tree_view->priv->selected_iter == 1)
12052 return strlen (text) < 1;
12054 len = strlen (text);
12059 model = pspp_sheet_view_get_model (tree_view);
12060 selection = pspp_sheet_view_get_selection (tree_view);
12063 pspp_sheet_selection_unselect_all (selection);
12064 if (!gtk_tree_model_get_iter_first (model, &iter))
12067 ret = pspp_sheet_view_search_iter (model, selection, &iter, text,
12068 &count, up?((tree_view->priv->selected_iter) - 1):((tree_view->priv->selected_iter + 1)));
12073 tree_view->priv->selected_iter += up?(-1):(1);
12078 /* return to old iter */
12080 gtk_tree_model_get_iter_first (model, &iter);
12081 pspp_sheet_view_search_iter (model, selection,
12083 &count, tree_view->priv->selected_iter);
12089 pspp_sheet_view_search_equal_func (GtkTreeModel *model,
12093 gpointer search_data)
12095 gboolean retval = TRUE;
12097 gchar *normalized_string;
12098 gchar *normalized_key;
12099 gchar *case_normalized_string = NULL;
12100 gchar *case_normalized_key = NULL;
12101 GValue value = {0,};
12102 GValue transformed = {0,};
12104 gtk_tree_model_get_value (model, iter, column, &value);
12106 g_value_init (&transformed, G_TYPE_STRING);
12108 if (!g_value_transform (&value, &transformed))
12110 g_value_unset (&value);
12114 g_value_unset (&value);
12116 str = g_value_get_string (&transformed);
12119 g_value_unset (&transformed);
12123 normalized_string = g_utf8_normalize (str, -1, G_NORMALIZE_ALL);
12124 normalized_key = g_utf8_normalize (key, -1, G_NORMALIZE_ALL);
12126 if (normalized_string && normalized_key)
12128 case_normalized_string = g_utf8_casefold (normalized_string, -1);
12129 case_normalized_key = g_utf8_casefold (normalized_key, -1);
12131 if (strncmp (case_normalized_key, case_normalized_string, strlen (case_normalized_key)) == 0)
12135 g_value_unset (&transformed);
12136 g_free (normalized_key);
12137 g_free (normalized_string);
12138 g_free (case_normalized_key);
12139 g_free (case_normalized_string);
12145 pspp_sheet_view_search_iter (GtkTreeModel *model,
12146 PsppSheetSelection *selection,
12155 PsppSheetView *tree_view = pspp_sheet_selection_get_tree_view (selection);
12157 path = gtk_tree_model_get_path (model, iter);
12158 _pspp_sheet_view_find_node (tree_view, path, &node);
12162 gboolean done = FALSE;
12164 if (! tree_view->priv->search_equal_func (model, tree_view->priv->search_column, text, iter, tree_view->priv->search_user_data))
12169 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL,
12171 pspp_sheet_selection_select_iter (selection, iter);
12172 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE, 0);
12175 gtk_tree_path_free (path);
12184 node = pspp_sheet_view_node_next (tree_view, node);
12190 has_next = gtk_tree_model_iter_next (model, iter);
12193 gtk_tree_path_next (path);
12196 TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
12201 gtk_tree_path_free (path);
12203 /* we've run out of tree, done with this func */
12215 pspp_sheet_view_search_init (GtkWidget *entry,
12216 PsppSheetView *tree_view)
12222 GtkTreeModel *model;
12223 PsppSheetSelection *selection;
12225 g_return_if_fail (GTK_IS_ENTRY (entry));
12226 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12228 text = gtk_entry_get_text (GTK_ENTRY (entry));
12230 model = pspp_sheet_view_get_model (tree_view);
12231 selection = pspp_sheet_view_get_selection (tree_view);
12234 pspp_sheet_selection_unselect_all (selection);
12235 if (tree_view->priv->typeselect_flush_timeout
12236 && !tree_view->priv->search_custom_entry_set)
12238 g_source_remove (tree_view->priv->typeselect_flush_timeout);
12239 tree_view->priv->typeselect_flush_timeout =
12240 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
12241 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
12248 if (!gtk_tree_model_get_iter_first (model, &iter))
12251 ret = pspp_sheet_view_search_iter (model, selection,
12256 tree_view->priv->selected_iter = 1;
12260 pspp_sheet_view_remove_widget (GtkCellEditable *cell_editable,
12261 PsppSheetView *tree_view)
12263 if (tree_view->priv->edited_column == NULL)
12266 _pspp_sheet_view_column_stop_editing (tree_view->priv->edited_column);
12267 tree_view->priv->edited_column = NULL;
12269 if (gtk_widget_has_focus (GTK_WIDGET (cell_editable)))
12270 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
12272 g_signal_handlers_disconnect_by_func (cell_editable,
12273 pspp_sheet_view_remove_widget,
12275 g_signal_handlers_disconnect_by_func (cell_editable,
12276 pspp_sheet_view_editable_button_press_event,
12278 g_signal_handlers_disconnect_by_func (cell_editable,
12279 pspp_sheet_view_editable_clicked,
12282 gtk_container_remove (GTK_CONTAINER (tree_view),
12283 GTK_WIDGET (cell_editable));
12285 /* FIXME should only redraw a single node */
12286 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12290 pspp_sheet_view_start_editing (PsppSheetView *tree_view,
12291 GtkTreePath *cursor_path)
12294 GdkRectangle background_area;
12295 GdkRectangle cell_area;
12296 GtkCellEditable *editable_widget = NULL;
12297 gchar *path_string;
12298 guint flags = 0; /* can be 0, as the flags are primarily for rendering */
12299 gint retval = FALSE;
12302 g_assert (tree_view->priv->focus_column);
12304 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
12307 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
12308 if (cursor_node < 0)
12311 path_string = gtk_tree_path_to_string (cursor_path);
12312 gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path);
12314 pspp_sheet_view_column_cell_set_cell_data (tree_view->priv->focus_column,
12315 tree_view->priv->model,
12317 pspp_sheet_view_get_background_area (tree_view,
12319 tree_view->priv->focus_column,
12321 pspp_sheet_view_get_cell_area (tree_view,
12323 tree_view->priv->focus_column,
12326 if (_pspp_sheet_view_column_cell_event (tree_view->priv->focus_column,
12335 if (editable_widget != NULL)
12339 GtkCellRenderer *cell;
12342 cell = _pspp_sheet_view_column_get_edited_cell (tree_view->priv->focus_column);
12344 _pspp_sheet_view_column_get_neighbor_sizes (tree_view->priv->focus_column, cell, &left, &right);
12347 area.width -= right + left;
12349 pspp_sheet_view_real_start_editing (tree_view,
12350 tree_view->priv->focus_column,
12359 g_free (path_string);
12364 pspp_sheet_view_editable_button_press_event (GtkWidget *widget,
12365 GdkEventButton *event,
12366 PsppSheetView *sheet_view)
12370 node = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
12371 "pspp-sheet-view-node"));
12372 return pspp_sheet_view_row_head_clicked (sheet_view,
12374 sheet_view->priv->edited_column,
12379 pspp_sheet_view_editable_clicked (GtkButton *button,
12380 PsppSheetView *sheet_view)
12382 pspp_sheet_view_editable_button_press_event (GTK_WIDGET (button), NULL,
12387 is_all_selected (GtkWidget *widget)
12389 GtkEntryBuffer *buffer;
12390 gint start_pos, end_pos;
12392 if (!GTK_IS_ENTRY (widget))
12395 buffer = gtk_entry_get_buffer (GTK_ENTRY (widget));
12396 return (gtk_editable_get_selection_bounds (GTK_EDITABLE (widget),
12397 &start_pos, &end_pos)
12399 && end_pos == gtk_entry_buffer_get_length (buffer));
12403 is_at_left (GtkWidget *widget)
12405 return (GTK_IS_ENTRY (widget)
12406 && gtk_editable_get_position (GTK_EDITABLE (widget)) == 0);
12410 is_at_right (GtkWidget *widget)
12412 GtkEntryBuffer *buffer;
12415 if (!GTK_IS_ENTRY (widget))
12418 buffer = gtk_entry_get_buffer (GTK_ENTRY (widget));
12419 length = gtk_entry_buffer_get_length (buffer);
12420 return gtk_editable_get_position (GTK_EDITABLE (widget)) == length;
12424 pspp_sheet_view_event (GtkWidget *widget,
12425 GdkEventKey *event,
12426 PsppSheetView *tree_view)
12428 PsppSheetViewColumn *column;
12435 /* Intercept only key press events.
12436 It would make sense to use "key-press-event" instead of "event", but
12437 GtkEntry attaches its own signal handler to "key-press-event" that runs
12438 before ours and overrides our desired behavior for GDK_Up and GDK_Down.
12440 if (event->type != GDK_KEY_PRESS)
12443 keyval = event->keyval;
12445 switch (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK | GDK_MOD1_MASK))
12448 switch (event->keyval)
12450 case GDK_Left: case GDK_KP_Left:
12451 case GDK_Home: case GDK_KP_Home:
12452 if (!is_all_selected (widget) && !is_at_left (widget))
12456 case GDK_Right: case GDK_KP_Right:
12457 case GDK_End: case GDK_KP_End:
12458 if (!is_all_selected (widget) && !is_at_right (widget))
12462 case GDK_Up: case GDK_KP_Up:
12463 case GDK_Down: case GDK_KP_Down:
12466 case GDK_Page_Up: case GDK_KP_Page_Up:
12467 case GDK_Page_Down: case GDK_KP_Page_Down:
12478 case GDK_Tab: case GDK_KP_Tab:
12479 case GDK_ISO_Left_Tab:
12488 case GDK_SHIFT_MASK:
12489 switch (event->keyval)
12492 case GDK_ISO_Left_Tab:
12501 case GDK_CONTROL_MASK:
12502 switch (event->keyval)
12504 case GDK_Left: case GDK_KP_Left:
12505 if (!is_all_selected (widget) && !is_at_left (widget))
12509 case GDK_Right: case GDK_KP_Right:
12510 if (!is_all_selected (widget) && !is_at_right (widget))
12514 case GDK_Up: case GDK_KP_Up:
12515 case GDK_Down: case GDK_KP_Down:
12527 row = tree_view->priv->edited_row;
12528 column = tree_view->priv->edited_column;
12529 path = gtk_tree_path_new_from_indices (row, -1);
12531 pspp_sheet_view_stop_editing (tree_view, cancel);
12532 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
12534 pspp_sheet_view_set_cursor (tree_view, path, column, FALSE);
12535 gtk_tree_path_free (path);
12537 handled = gtk_binding_set_activate (edit_bindings, keyval, event->state,
12538 GTK_OBJECT (tree_view));
12540 g_signal_stop_emission_by_name (widget, "event");
12542 pspp_sheet_view_get_cursor (tree_view, &path, NULL);
12543 pspp_sheet_view_start_editing (tree_view, path);
12544 gtk_tree_path_free (path);
12550 pspp_sheet_view_override_cell_keypresses (GtkWidget *widget,
12553 PsppSheetView *sheet_view = data;
12555 g_signal_connect (widget, "event",
12556 G_CALLBACK (pspp_sheet_view_event),
12559 if (GTK_IS_CONTAINER (widget))
12560 gtk_container_foreach (GTK_CONTAINER (widget),
12561 pspp_sheet_view_override_cell_keypresses,
12566 pspp_sheet_view_real_start_editing (PsppSheetView *tree_view,
12567 PsppSheetViewColumn *column,
12569 GtkCellEditable *cell_editable,
12570 GdkRectangle *cell_area,
12574 PsppSheetSelectionMode mode = pspp_sheet_selection_get_mode (tree_view->priv->selection);
12575 gint pre_val = gtk_adjustment_get_value (tree_view->priv->vadjustment);
12576 GtkRequisition requisition;
12579 g_return_if_fail (gtk_tree_path_get_depth (path) == 1);
12581 tree_view->priv->edited_column = column;
12582 _pspp_sheet_view_column_start_editing (column, GTK_CELL_EDITABLE (cell_editable));
12584 row = gtk_tree_path_get_indices (path)[0];
12585 tree_view->priv->edited_row = row;
12586 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE, 0);
12587 cell_area->y += pre_val - (int)gtk_adjustment_get_value (tree_view->priv->vadjustment);
12589 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
12590 pspp_sheet_selection_select_column (tree_view->priv->selection, column);
12591 tree_view->priv->anchor_column = column;
12593 gtk_widget_size_request (GTK_WIDGET (cell_editable), &requisition);
12595 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
12597 if (requisition.height < cell_area->height)
12599 gint diff = cell_area->height - requisition.height;
12600 pspp_sheet_view_put (tree_view,
12601 GTK_WIDGET (cell_editable),
12602 cell_area->x, cell_area->y + diff/2,
12603 cell_area->width, requisition.height);
12607 pspp_sheet_view_put (tree_view,
12608 GTK_WIDGET (cell_editable),
12609 cell_area->x, cell_area->y,
12610 cell_area->width, cell_area->height);
12613 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (cell_editable),
12614 (GdkEvent *)event);
12616 gtk_widget_grab_focus (GTK_WIDGET (cell_editable));
12617 g_signal_connect (cell_editable, "remove-widget",
12618 G_CALLBACK (pspp_sheet_view_remove_widget), tree_view);
12619 if (mode == PSPP_SHEET_SELECTION_RECTANGLE && column->row_head &&
12620 GTK_IS_BUTTON (cell_editable))
12622 g_signal_connect (cell_editable, "button-press-event",
12623 G_CALLBACK (pspp_sheet_view_editable_button_press_event),
12625 g_object_set_data (G_OBJECT (cell_editable), "pspp-sheet-view-node",
12626 GINT_TO_POINTER (row));
12627 g_signal_connect (cell_editable, "clicked",
12628 G_CALLBACK (pspp_sheet_view_editable_clicked),
12632 pspp_sheet_view_override_cell_keypresses (GTK_WIDGET (cell_editable),
12637 pspp_sheet_view_stop_editing (PsppSheetView *tree_view,
12638 gboolean cancel_editing)
12640 PsppSheetViewColumn *column;
12641 GtkCellRenderer *cell;
12643 if (tree_view->priv->edited_column == NULL)
12647 * This is very evil. We need to do this, because
12648 * gtk_cell_editable_editing_done may trigger pspp_sheet_view_row_changed
12649 * later on. If pspp_sheet_view_row_changed notices
12650 * tree_view->priv->edited_column != NULL, it'll call
12651 * pspp_sheet_view_stop_editing again. Bad things will happen then.
12653 * Please read that again if you intend to modify anything here.
12656 column = tree_view->priv->edited_column;
12657 tree_view->priv->edited_column = NULL;
12659 cell = _pspp_sheet_view_column_get_edited_cell (column);
12660 gtk_cell_renderer_stop_editing (cell, cancel_editing);
12662 if (!cancel_editing)
12663 gtk_cell_editable_editing_done (column->editable_widget);
12665 tree_view->priv->edited_column = column;
12667 gtk_cell_editable_remove_widget (column->editable_widget);
12672 * pspp_sheet_view_set_hover_selection:
12673 * @tree_view: a #PsppSheetView
12674 * @hover: %TRUE to enable hover selection mode
12676 * Enables of disables the hover selection mode of @tree_view.
12677 * Hover selection makes the selected row follow the pointer.
12678 * Currently, this works only for the selection modes
12679 * %PSPP_SHEET_SELECTION_SINGLE and %PSPP_SHEET_SELECTION_BROWSE.
12684 pspp_sheet_view_set_hover_selection (PsppSheetView *tree_view,
12687 hover = hover != FALSE;
12689 if (hover != tree_view->priv->hover_selection)
12691 tree_view->priv->hover_selection = hover;
12693 g_object_notify (G_OBJECT (tree_view), "hover-selection");
12698 * pspp_sheet_view_get_hover_selection:
12699 * @tree_view: a #PsppSheetView
12701 * Returns whether hover selection mode is turned on for @tree_view.
12703 * Return value: %TRUE if @tree_view is in hover selection mode
12708 pspp_sheet_view_get_hover_selection (PsppSheetView *tree_view)
12710 return tree_view->priv->hover_selection;
12714 * pspp_sheet_view_set_rubber_banding:
12715 * @tree_view: a #PsppSheetView
12716 * @enable: %TRUE to enable rubber banding
12718 * Enables or disables rubber banding in @tree_view. If the selection mode is
12719 * #PSPP_SHEET_SELECTION_MULTIPLE or #PSPP_SHEET_SELECTION_RECTANGLE, rubber
12720 * banding will allow the user to select multiple rows by dragging the mouse.
12725 pspp_sheet_view_set_rubber_banding (PsppSheetView *tree_view,
12728 enable = enable != FALSE;
12730 if (enable != tree_view->priv->rubber_banding_enable)
12732 tree_view->priv->rubber_banding_enable = enable;
12734 g_object_notify (G_OBJECT (tree_view), "rubber-banding");
12739 * pspp_sheet_view_get_rubber_banding:
12740 * @tree_view: a #PsppSheetView
12742 * Returns whether rubber banding is turned on for @tree_view. If the
12743 * selection mode is #PSPP_SHEET_SELECTION_MULTIPLE or
12744 * #PSPP_SHEET_SELECTION_RECTANGLE, rubber banding will allow the user to
12745 * select multiple rows by dragging the mouse.
12747 * Return value: %TRUE if rubber banding in @tree_view is enabled.
12752 pspp_sheet_view_get_rubber_banding (PsppSheetView *tree_view)
12754 return tree_view->priv->rubber_banding_enable;
12758 * pspp_sheet_view_is_rubber_banding_active:
12759 * @tree_view: a #PsppSheetView
12761 * Returns whether a rubber banding operation is currently being done
12764 * Return value: %TRUE if a rubber banding operation is currently being
12765 * done in @tree_view.
12770 pspp_sheet_view_is_rubber_banding_active (PsppSheetView *tree_view)
12772 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
12774 if (tree_view->priv->rubber_banding_enable
12775 && tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
12782 pspp_sheet_view_grab_notify (GtkWidget *widget,
12783 gboolean was_grabbed)
12785 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12787 tree_view->priv->in_grab = !was_grabbed;
12791 tree_view->priv->pressed_button = -1;
12793 if (tree_view->priv->rubber_band_status)
12794 pspp_sheet_view_stop_rubber_band (tree_view);
12799 pspp_sheet_view_state_changed (GtkWidget *widget,
12800 GtkStateType previous_state)
12802 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12804 if (gtk_widget_get_realized (widget))
12806 GtkStyle *style = gtk_widget_get_style (widget);
12807 gdk_window_set_background (tree_view->priv->bin_window, &style->base[gtk_widget_get_state (widget)]);
12810 gtk_widget_queue_draw (widget);
12814 * pspp_sheet_view_get_grid_lines:
12815 * @tree_view: a #PsppSheetView
12817 * Returns which grid lines are enabled in @tree_view.
12819 * Return value: a #PsppSheetViewGridLines value indicating which grid lines
12824 PsppSheetViewGridLines
12825 pspp_sheet_view_get_grid_lines (PsppSheetView *tree_view)
12827 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12829 return tree_view->priv->grid_lines;
12833 * pspp_sheet_view_set_grid_lines:
12834 * @tree_view: a #PsppSheetView
12835 * @grid_lines: a #PsppSheetViewGridLines value indicating which grid lines to
12838 * Sets which grid lines to draw in @tree_view.
12843 pspp_sheet_view_set_grid_lines (PsppSheetView *tree_view,
12844 PsppSheetViewGridLines grid_lines)
12846 PsppSheetViewPrivate *priv;
12847 PsppSheetViewGridLines old_grid_lines;
12849 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12851 priv = tree_view->priv;
12853 old_grid_lines = priv->grid_lines;
12854 priv->grid_lines = grid_lines;
12856 if (old_grid_lines != grid_lines)
12858 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12860 g_object_notify (G_OBJECT (tree_view), "enable-grid-lines");
12865 * pspp_sheet_view_get_special_cells:
12866 * @tree_view: a #PsppSheetView
12868 * Returns which grid lines are enabled in @tree_view.
12870 * Return value: a #PsppSheetViewSpecialCells value indicating whether rows in
12871 * the sheet view contain special cells.
12873 PsppSheetViewSpecialCells
12874 pspp_sheet_view_get_special_cells (PsppSheetView *tree_view)
12876 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12878 return tree_view->priv->special_cells;
12882 * pspp_sheet_view_set_special_cells:
12883 * @tree_view: a #PsppSheetView
12884 * @special_cells: a #PsppSheetViewSpecialCells value indicating whether rows in
12885 * the sheet view contain special cells.
12887 * Sets whether rows in the sheet view contain special cells, controlling the
12888 * rendering of row selections.
12891 pspp_sheet_view_set_special_cells (PsppSheetView *tree_view,
12892 PsppSheetViewSpecialCells special_cells)
12894 PsppSheetViewPrivate *priv;
12896 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12898 priv = tree_view->priv;
12900 if (priv->special_cells != special_cells)
12902 priv->special_cells = special_cells;
12903 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12904 g_object_notify (G_OBJECT (tree_view), "special-cells");
12909 pspp_sheet_view_get_fixed_height (const PsppSheetView *tree_view)
12911 /* XXX (re)calculate fixed_height if necessary */
12912 return tree_view->priv->fixed_height;
12916 pspp_sheet_view_set_fixed_height (PsppSheetView *tree_view,
12919 g_return_if_fail (fixed_height > 0);
12921 if (tree_view->priv->fixed_height != fixed_height)
12923 tree_view->priv->fixed_height = fixed_height;
12924 g_object_notify (G_OBJECT (tree_view), "fixed-height");
12926 if (!tree_view->priv->fixed_height_set)
12928 tree_view->priv->fixed_height_set = TRUE;
12929 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
12934 * pspp_sheet_view_set_tooltip_row:
12935 * @tree_view: a #PsppSheetView
12936 * @tooltip: a #GtkTooltip
12937 * @path: a #GtkTreePath
12939 * Sets the tip area of @tooltip to be the area covered by the row at @path.
12940 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
12941 * See also gtk_tooltip_set_tip_area().
12946 pspp_sheet_view_set_tooltip_row (PsppSheetView *tree_view,
12947 GtkTooltip *tooltip,
12950 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12951 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
12953 pspp_sheet_view_set_tooltip_cell (tree_view, tooltip, path, NULL, NULL);
12957 * pspp_sheet_view_set_tooltip_cell:
12958 * @tree_view: a #PsppSheetView
12959 * @tooltip: a #GtkTooltip
12960 * @path: (allow-none): a #GtkTreePath or %NULL
12961 * @column: (allow-none): a #PsppSheetViewColumn or %NULL
12962 * @cell: (allow-none): a #GtkCellRenderer or %NULL
12964 * Sets the tip area of @tooltip to the area @path, @column and @cell have
12965 * in common. For example if @path is %NULL and @column is set, the tip
12966 * area will be set to the full area covered by @column. See also
12967 * gtk_tooltip_set_tip_area().
12969 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
12974 pspp_sheet_view_set_tooltip_cell (PsppSheetView *tree_view,
12975 GtkTooltip *tooltip,
12977 PsppSheetViewColumn *column,
12978 GtkCellRenderer *cell)
12982 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12983 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
12984 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
12985 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
12987 /* Determine x values. */
12988 if (column && cell)
12993 pspp_sheet_view_get_cell_area (tree_view, path, column, &tmp);
12994 pspp_sheet_view_column_cell_get_position (column, cell, &start, &width);
12996 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12999 rect.width = width;
13005 pspp_sheet_view_get_background_area (tree_view, NULL, column, &tmp);
13006 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
13009 rect.width = tmp.width;
13013 GtkAllocation allocation;
13014 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
13016 rect.width = allocation.width;
13019 /* Determine y values. */
13024 pspp_sheet_view_get_background_area (tree_view, path, NULL, &tmp);
13025 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
13028 rect.height = tmp.height;
13033 rect.height = gtk_adjustment_get_page_size (tree_view->priv->vadjustment);
13036 gtk_tooltip_set_tip_area (tooltip, &rect);
13040 * pspp_sheet_view_get_tooltip_context:
13041 * @tree_view: a #PsppSheetView
13042 * @x: the x coordinate (relative to widget coordinates)
13043 * @y: the y coordinate (relative to widget coordinates)
13044 * @keyboard_tip: whether this is a keyboard tooltip or not
13045 * @model: (allow-none): a pointer to receive a #GtkTreeModel or %NULL
13046 * @path: (allow-none): a pointer to receive a #GtkTreePath or %NULL
13047 * @iter: (allow-none): a pointer to receive a #GtkTreeIter or %NULL
13049 * This function is supposed to be used in a #GtkWidget::query-tooltip
13050 * signal handler for #PsppSheetView. The @x, @y and @keyboard_tip values
13051 * which are received in the signal handler, should be passed to this
13052 * function without modification.
13054 * The return value indicates whether there is a tree view row at the given
13055 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
13056 * tooltips the row returned will be the cursor row. When %TRUE, then any of
13057 * @model, @path and @iter which have been provided will be set to point to
13058 * that row and the corresponding model. @x and @y will always be converted
13059 * to be relative to @tree_view's bin_window if @keyboard_tooltip is %FALSE.
13061 * Return value: whether or not the given tooltip context points to a row.
13066 pspp_sheet_view_get_tooltip_context (PsppSheetView *tree_view,
13069 gboolean keyboard_tip,
13070 GtkTreeModel **model,
13071 GtkTreePath **path,
13074 GtkTreePath *tmppath = NULL;
13076 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
13077 g_return_val_if_fail (x != NULL, FALSE);
13078 g_return_val_if_fail (y != NULL, FALSE);
13082 pspp_sheet_view_get_cursor (tree_view, &tmppath, NULL);
13089 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, *x, *y,
13092 if (!pspp_sheet_view_get_path_at_pos (tree_view, *x, *y,
13093 &tmppath, NULL, NULL, NULL))
13098 *model = pspp_sheet_view_get_model (tree_view);
13101 gtk_tree_model_get_iter (pspp_sheet_view_get_model (tree_view),
13107 gtk_tree_path_free (tmppath);
13113 pspp_sheet_view_set_tooltip_query_cb (GtkWidget *widget,
13116 gboolean keyboard_tip,
13117 GtkTooltip *tooltip,
13120 GValue value = { 0, };
13121 GValue transformed = { 0, };
13124 GtkTreeModel *model;
13125 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
13127 if (!pspp_sheet_view_get_tooltip_context (PSPP_SHEET_VIEW (widget),
13130 &model, &path, &iter))
13133 gtk_tree_model_get_value (model, &iter,
13134 tree_view->priv->tooltip_column, &value);
13136 g_value_init (&transformed, G_TYPE_STRING);
13138 if (!g_value_transform (&value, &transformed))
13140 g_value_unset (&value);
13141 gtk_tree_path_free (path);
13146 g_value_unset (&value);
13148 if (!g_value_get_string (&transformed))
13150 g_value_unset (&transformed);
13151 gtk_tree_path_free (path);
13156 gtk_tooltip_set_markup (tooltip, g_value_get_string (&transformed));
13157 pspp_sheet_view_set_tooltip_row (tree_view, tooltip, path);
13159 gtk_tree_path_free (path);
13160 g_value_unset (&transformed);
13166 * pspp_sheet_view_set_tooltip_column:
13167 * @tree_view: a #PsppSheetView
13168 * @column: an integer, which is a valid column number for @tree_view's model
13170 * If you only plan to have simple (text-only) tooltips on full rows, you
13171 * can use this function to have #PsppSheetView handle these automatically
13172 * for you. @column should be set to the column in @tree_view's model
13173 * containing the tooltip texts, or -1 to disable this feature.
13175 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
13176 * @tree_view will connect a #GtkWidget::query-tooltip signal handler.
13178 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
13179 * so &, <, etc have to be escaped in the text.
13184 pspp_sheet_view_set_tooltip_column (PsppSheetView *tree_view,
13187 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
13189 if (column == tree_view->priv->tooltip_column)
13194 g_signal_handlers_disconnect_by_func (tree_view,
13195 pspp_sheet_view_set_tooltip_query_cb,
13197 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), FALSE);
13201 if (tree_view->priv->tooltip_column == -1)
13203 g_signal_connect (tree_view, "query-tooltip",
13204 G_CALLBACK (pspp_sheet_view_set_tooltip_query_cb), NULL);
13205 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), TRUE);
13209 tree_view->priv->tooltip_column = column;
13210 g_object_notify (G_OBJECT (tree_view), "tooltip-column");
13214 * pspp_sheet_view_get_tooltip_column:
13215 * @tree_view: a #PsppSheetView
13217 * Returns the column of @tree_view's model which is being used for
13218 * displaying tooltips on @tree_view's rows.
13220 * Return value: the index of the tooltip column that is currently being
13221 * used, or -1 if this is disabled.
13226 pspp_sheet_view_get_tooltip_column (PsppSheetView *tree_view)
13228 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
13230 return tree_view->priv->tooltip_column;
13234 _gtk_boolean_handled_accumulator (GSignalInvocationHint *ihint,
13235 GValue *return_accu,
13236 const GValue *handler_return,
13239 gboolean continue_emission;
13240 gboolean signal_handled;
13242 signal_handled = g_value_get_boolean (handler_return);
13243 g_value_set_boolean (return_accu, signal_handled);
13244 continue_emission = !signal_handled;
13246 return continue_emission;
13251 pspp_sheet_view_grid_lines_get_type (void)
13253 static GType etype = 0;
13254 if (G_UNLIKELY(etype == 0)) {
13255 static const GEnumValue values[] = {
13256 { PSPP_SHEET_VIEW_GRID_LINES_NONE, "PSPP_SHEET_VIEW_GRID_LINES_NONE", "none" },
13257 { PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL, "PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL", "horizontal" },
13258 { PSPP_SHEET_VIEW_GRID_LINES_VERTICAL, "PSPP_SHEET_VIEW_GRID_LINES_VERTICAL", "vertical" },
13259 { PSPP_SHEET_VIEW_GRID_LINES_BOTH, "PSPP_SHEET_VIEW_GRID_LINES_BOTH", "both" },
13262 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewGridLines"), values);
13268 pspp_sheet_view_special_cells_get_type (void)
13270 static GType etype = 0;
13271 if (G_UNLIKELY(etype == 0)) {
13272 static const GEnumValue values[] = {
13273 { PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT, "PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT", "detect" },
13274 { PSPP_SHEET_VIEW_SPECIAL_CELLS_YES, "PSPP_SHEET_VIEW_SPECIAL_CELLS_YES", "yes" },
13275 { PSPP_SHEET_VIEW_SPECIAL_CELLS_NO, "PSPP_SHEET_VIEW_SPECIAL_CELLS_NO", "no" },
13278 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewSpecialCells"), values);