1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2011, 2012, 2013 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 * Copyright (C) 2000 Red Hat, Inc., Jonathan Blandford <jrb@redhat.com>
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Library General Public
22 * License as published by the Free Software Foundation; either
23 * version 2 of the License, or (at your option) any later version.
25 * This library is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 * Library General Public License for more details.
30 * You should have received a copy of the GNU Library General Public
31 * License along with this library; if not, write to the
32 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
33 * Boston, MA 02111-1307, USA.
38 #include "ui/gui/pspp-sheet-private.h"
42 #include <gdk/gdkkeysyms.h>
43 #include <gdk/gdkkeysyms-compat.h>
46 #include "ui/gui/psppire-marshal.h"
47 #include "ui/gui/pspp-sheet-selection.h"
49 #define P_(STRING) STRING
50 #define GTK_PARAM_READABLE G_PARAM_READABLE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
51 #define GTK_PARAM_READWRITE G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
53 /* Many keyboard shortcuts for Mac are the same as for X
54 * except they use Command key instead of Control (e.g. Cut,
55 * Copy, Paste). This symbol is for those simple cases. */
56 #ifndef GDK_WINDOWING_QUARTZ
57 #define GTK_DEFAULT_ACCEL_MOD_MASK GDK_CONTROL_MASK
59 #define GTK_DEFAULT_ACCEL_MOD_MASK GDK_META_MASK
62 #define PSPP_SHEET_VIEW_PRIORITY_VALIDATE (GDK_PRIORITY_REDRAW + 5)
63 #define PSPP_SHEET_VIEW_PRIORITY_SCROLL_SYNC (PSPP_SHEET_VIEW_PRIORITY_VALIDATE + 2)
64 #define PSPP_SHEET_VIEW_TIME_MS_PER_IDLE 30
65 #define SCROLL_EDGE_SIZE 15
66 #define EXPANDER_EXTRA_PADDING 4
67 #define PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT 5000
69 /* The "background" areas of all rows/cells add up to cover the entire tree.
70 * The background includes all inter-row and inter-cell spacing.
71 * The "cell" areas are the cell_area passed in to gtk_cell_renderer_render(),
72 * i.e. just the cells, no spacing.
75 #define BACKGROUND_HEIGHT(tree_view) (tree_view->priv->fixed_height)
76 #define CELL_HEIGHT(tree_view, separator) ((BACKGROUND_HEIGHT (tree_view)) - (separator))
78 /* Translate from bin_window coordinates to rbtree (tree coordinates) and
81 #define TREE_WINDOW_Y_TO_RBTREE_Y(tree_view,y) ((y) + tree_view->priv->dy)
82 #define RBTREE_Y_TO_TREE_WINDOW_Y(tree_view,y) ((y) - tree_view->priv->dy)
84 /* This is in bin_window coordinates */
85 #define BACKGROUND_FIRST_PIXEL(tree_view,node) (RBTREE_Y_TO_TREE_WINDOW_Y (tree_view, pspp_sheet_view_node_find_offset (tree_view, (node))))
86 #define CELL_FIRST_PIXEL(tree_view,node,separator) (BACKGROUND_FIRST_PIXEL (tree_view,node) + separator/2)
88 #define ROW_HEIGHT(tree_view) \
89 ((tree_view->priv->fixed_height > 0) ? (tree_view->priv->fixed_height) : (tree_view)->priv->expander_size)
92 typedef struct _PsppSheetViewChild PsppSheetViewChild;
93 struct _PsppSheetViewChild
103 typedef struct _TreeViewDragInfo TreeViewDragInfo;
104 struct _TreeViewDragInfo
106 GdkModifierType start_button_mask;
107 GtkTargetList *_unused_source_target_list;
108 GdkDragAction source_actions;
110 GtkTargetList *_unused_dest_target_list;
112 guint source_set : 1;
128 START_INTERACTIVE_SEARCH,
138 PROP_HEADERS_VISIBLE,
139 PROP_HEADERS_CLICKABLE,
144 PROP_HOVER_SELECTION,
146 PROP_ENABLE_GRID_LINES,
150 PROP_FIXED_HEIGHT_SET
154 static void pspp_sheet_view_finalize (GObject *object);
155 static void pspp_sheet_view_set_property (GObject *object,
159 static void pspp_sheet_view_get_property (GObject *object,
164 static void pspp_sheet_view_dispose (GObject *object);
166 /* gtkwidget signals */
167 static void pspp_sheet_view_realize (GtkWidget *widget);
168 static void pspp_sheet_view_unrealize (GtkWidget *widget);
169 static void pspp_sheet_view_map (GtkWidget *widget);
170 static void pspp_sheet_view_size_request (GtkWidget *widget,
171 GtkRequisition *requisition);
172 static void pspp_sheet_view_size_allocate (GtkWidget *widget,
173 GtkAllocation *allocation);
174 static gboolean pspp_sheet_view_expose (GtkWidget *widget,
175 GdkEventExpose *event);
176 static gboolean pspp_sheet_view_key_press (GtkWidget *widget,
178 static gboolean pspp_sheet_view_key_release (GtkWidget *widget,
180 static gboolean pspp_sheet_view_motion (GtkWidget *widget,
181 GdkEventMotion *event);
182 static gboolean pspp_sheet_view_enter_notify (GtkWidget *widget,
183 GdkEventCrossing *event);
184 static gboolean pspp_sheet_view_leave_notify (GtkWidget *widget,
185 GdkEventCrossing *event);
186 static gboolean pspp_sheet_view_button_press (GtkWidget *widget,
187 GdkEventButton *event);
188 static gboolean pspp_sheet_view_button_release (GtkWidget *widget,
189 GdkEventButton *event);
190 static gboolean pspp_sheet_view_grab_broken (GtkWidget *widget,
191 GdkEventGrabBroken *event);
193 static void pspp_sheet_view_set_focus_child (GtkContainer *container,
195 static gint pspp_sheet_view_focus_out (GtkWidget *widget,
196 GdkEventFocus *event);
197 static gint pspp_sheet_view_focus (GtkWidget *widget,
198 GtkDirectionType direction);
199 static void pspp_sheet_view_grab_focus (GtkWidget *widget);
200 static void pspp_sheet_view_style_set (GtkWidget *widget,
201 GtkStyle *previous_style);
202 static void pspp_sheet_view_grab_notify (GtkWidget *widget,
203 gboolean was_grabbed);
204 static void pspp_sheet_view_state_changed (GtkWidget *widget,
205 GtkStateType previous_state);
207 /* container signals */
208 static void pspp_sheet_view_remove (GtkContainer *container,
210 static void pspp_sheet_view_forall (GtkContainer *container,
211 gboolean include_internals,
212 GtkCallback callback,
213 gpointer callback_data);
215 /* Source side drag signals */
216 static void pspp_sheet_view_drag_begin (GtkWidget *widget,
217 GdkDragContext *context);
218 static void pspp_sheet_view_drag_end (GtkWidget *widget,
219 GdkDragContext *context);
220 static void pspp_sheet_view_drag_data_get (GtkWidget *widget,
221 GdkDragContext *context,
222 GtkSelectionData *selection_data,
225 static void pspp_sheet_view_drag_data_delete (GtkWidget *widget,
226 GdkDragContext *context);
228 /* Target side drag signals */
229 static void pspp_sheet_view_drag_leave (GtkWidget *widget,
230 GdkDragContext *context,
232 static gboolean pspp_sheet_view_drag_motion (GtkWidget *widget,
233 GdkDragContext *context,
237 static gboolean pspp_sheet_view_drag_drop (GtkWidget *widget,
238 GdkDragContext *context,
242 static void pspp_sheet_view_drag_data_received (GtkWidget *widget,
243 GdkDragContext *context,
246 GtkSelectionData *selection_data,
250 /* tree_model signals */
251 static void pspp_sheet_view_set_adjustments (PsppSheetView *tree_view,
253 GtkAdjustment *vadj);
254 static gboolean pspp_sheet_view_real_move_cursor (PsppSheetView *tree_view,
255 GtkMovementStep step,
257 static gboolean pspp_sheet_view_real_select_all (PsppSheetView *tree_view);
258 static gboolean pspp_sheet_view_real_unselect_all (PsppSheetView *tree_view);
259 static gboolean pspp_sheet_view_real_select_cursor_row (PsppSheetView *tree_view,
260 gboolean start_editing,
261 PsppSheetSelectMode mode);
262 static gboolean pspp_sheet_view_real_toggle_cursor_row (PsppSheetView *tree_view);
263 static void pspp_sheet_view_row_changed (GtkTreeModel *model,
267 static void pspp_sheet_view_row_inserted (GtkTreeModel *model,
271 static void pspp_sheet_view_row_deleted (GtkTreeModel *model,
274 static void pspp_sheet_view_rows_reordered (GtkTreeModel *model,
280 /* Incremental reflow */
281 static gint validate_row (PsppSheetView *tree_view,
285 static void validate_visible_area (PsppSheetView *tree_view);
286 static gboolean validate_rows_handler (PsppSheetView *tree_view);
287 static gboolean presize_handler_callback (gpointer data);
288 static void install_presize_handler (PsppSheetView *tree_view);
289 static void install_scroll_sync_handler (PsppSheetView *tree_view);
290 static void pspp_sheet_view_set_top_row (PsppSheetView *tree_view,
293 static void pspp_sheet_view_dy_to_top_row (PsppSheetView *tree_view);
294 static void pspp_sheet_view_top_row_to_dy (PsppSheetView *tree_view);
295 static void invalidate_empty_focus (PsppSheetView *tree_view);
297 /* Internal functions */
298 static void pspp_sheet_view_add_move_binding (GtkBindingSet *binding_set,
301 gboolean add_shifted_binding,
302 GtkMovementStep step,
304 static void pspp_sheet_view_queue_draw_path (PsppSheetView *tree_view,
306 const GdkRectangle *clip_rect);
307 static gint pspp_sheet_view_new_column_width (PsppSheetView *tree_view,
310 static void pspp_sheet_view_adjustment_changed (GtkAdjustment *adjustment,
311 PsppSheetView *tree_view);
312 static void pspp_sheet_view_clamp_node_visible (PsppSheetView *tree_view,
314 static void pspp_sheet_view_clamp_column_visible (PsppSheetView *tree_view,
315 PsppSheetViewColumn *column,
316 gboolean focus_to_cell);
317 static gboolean pspp_sheet_view_maybe_begin_dragging_row (PsppSheetView *tree_view,
318 GdkEventMotion *event);
319 static void pspp_sheet_view_focus_to_cursor (PsppSheetView *tree_view);
320 static gboolean pspp_sheet_view_move_cursor_up_down (PsppSheetView *tree_view,
322 PsppSheetSelectMode mode);
323 static void pspp_sheet_view_move_cursor_page_up_down (PsppSheetView *tree_view,
325 PsppSheetSelectMode mode);
326 static void pspp_sheet_view_move_cursor_left_right (PsppSheetView *tree_view,
328 PsppSheetSelectMode mode);
329 static void pspp_sheet_view_move_cursor_line_start_end (PsppSheetView *tree_view,
331 PsppSheetSelectMode mode);
332 static void pspp_sheet_view_move_cursor_tab (PsppSheetView *tree_view,
334 static void pspp_sheet_view_move_cursor_start_end (PsppSheetView *tree_view,
336 PsppSheetSelectMode mode);
337 static void pspp_sheet_view_real_set_cursor (PsppSheetView *tree_view,
339 gboolean clear_and_select,
341 PsppSheetSelectMode mode);
342 static gboolean pspp_sheet_view_has_special_cell (PsppSheetView *tree_view);
343 static void pspp_sheet_view_stop_rubber_band (PsppSheetView *tree_view);
344 static void update_prelight (PsppSheetView *tree_view,
347 static void initialize_fixed_height_mode (PsppSheetView *tree_view);
349 /* interactive search */
350 static void pspp_sheet_view_ensure_interactive_directory (PsppSheetView *tree_view);
351 static void pspp_sheet_view_search_dialog_hide (GtkWidget *search_dialog,
352 PsppSheetView *tree_view);
353 static void pspp_sheet_view_search_position_func (PsppSheetView *tree_view,
354 GtkWidget *search_dialog,
356 static void pspp_sheet_view_search_disable_popdown (GtkEntry *entry,
360 static void pspp_sheet_view_search_preedit_changed (GtkIMContext *im_context,
361 PsppSheetView *tree_view);
363 static void pspp_sheet_view_search_activate (GtkEntry *entry,
364 PsppSheetView *tree_view);
365 static gboolean pspp_sheet_view_real_search_enable_popdown(gpointer data);
366 static void pspp_sheet_view_search_enable_popdown (GtkWidget *widget,
368 static gboolean pspp_sheet_view_search_delete_event (GtkWidget *widget,
370 PsppSheetView *tree_view);
371 static gboolean pspp_sheet_view_search_button_press_event (GtkWidget *widget,
372 GdkEventButton *event,
373 PsppSheetView *tree_view);
374 static gboolean pspp_sheet_view_search_scroll_event (GtkWidget *entry,
375 GdkEventScroll *event,
376 PsppSheetView *tree_view);
377 static gboolean pspp_sheet_view_search_key_press_event (GtkWidget *entry,
379 PsppSheetView *tree_view);
380 static gboolean pspp_sheet_view_search_move (GtkWidget *window,
381 PsppSheetView *tree_view,
383 static gboolean pspp_sheet_view_search_equal_func (GtkTreeModel *model,
387 gpointer search_data);
388 static gboolean pspp_sheet_view_search_iter (GtkTreeModel *model,
389 PsppSheetSelection *selection,
394 static void pspp_sheet_view_search_init (GtkWidget *entry,
395 PsppSheetView *tree_view);
396 static void pspp_sheet_view_put (PsppSheetView *tree_view,
397 GtkWidget *child_widget,
402 static gboolean pspp_sheet_view_start_editing (PsppSheetView *tree_view,
403 GtkTreePath *cursor_path);
404 static gboolean pspp_sheet_view_editable_button_press_event (GtkWidget *,
407 static void pspp_sheet_view_editable_clicked (GtkButton *, PsppSheetView *);
408 static void pspp_sheet_view_real_start_editing (PsppSheetView *tree_view,
409 PsppSheetViewColumn *column,
411 GtkCellEditable *cell_editable,
412 GdkRectangle *cell_area,
415 static gboolean pspp_sheet_view_real_start_interactive_search (PsppSheetView *tree_view,
416 gboolean keybinding);
417 static gboolean pspp_sheet_view_start_interactive_search (PsppSheetView *tree_view);
418 static PsppSheetViewColumn *pspp_sheet_view_get_drop_column (PsppSheetView *tree_view,
419 PsppSheetViewColumn *column,
422 pspp_sheet_view_adjust_cell_area (PsppSheetView *tree_view,
423 PsppSheetViewColumn *column,
424 const GdkRectangle *background_area,
425 gboolean subtract_focus_rect,
426 GdkRectangle *cell_area);
427 static gint pspp_sheet_view_find_offset (PsppSheetView *tree_view,
432 static void pspp_sheet_view_buildable_add_child (GtkBuildable *tree_view,
436 static void pspp_sheet_view_buildable_init (GtkBuildableIface *iface);
439 static gboolean scroll_row_timeout (gpointer data);
440 static void add_scroll_timeout (PsppSheetView *tree_view);
441 static void remove_scroll_timeout (PsppSheetView *tree_view);
443 static guint tree_view_signals [LAST_SIGNAL] = { 0 };
445 static GtkBindingSet *edit_bindings;
452 G_DEFINE_TYPE_WITH_CODE (PsppSheetView, pspp_sheet_view, GTK_TYPE_CONTAINER,
453 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
454 pspp_sheet_view_buildable_init))
457 pspp_sheet_view_class_init (PsppSheetViewClass *class)
459 GObjectClass *o_class;
460 GtkWidgetClass *widget_class;
461 GtkContainerClass *container_class;
462 GtkBindingSet *binding_set[2];
465 binding_set[0] = gtk_binding_set_by_class (class);
467 binding_set[1] = gtk_binding_set_new ("PsppSheetViewEditing");
468 edit_bindings = binding_set[1];
470 o_class = (GObjectClass *) class;
471 widget_class = (GtkWidgetClass *) class;
472 container_class = (GtkContainerClass *) class;
474 /* GObject signals */
475 o_class->set_property = pspp_sheet_view_set_property;
476 o_class->get_property = pspp_sheet_view_get_property;
477 o_class->finalize = pspp_sheet_view_finalize;
478 o_class->dispose = pspp_sheet_view_dispose;
480 /* GtkWidget signals */
481 widget_class->map = pspp_sheet_view_map;
482 widget_class->realize = pspp_sheet_view_realize;
483 widget_class->unrealize = pspp_sheet_view_unrealize;
484 widget_class->size_request = pspp_sheet_view_size_request;
485 widget_class->size_allocate = pspp_sheet_view_size_allocate;
486 widget_class->button_press_event = pspp_sheet_view_button_press;
487 widget_class->button_release_event = pspp_sheet_view_button_release;
488 widget_class->grab_broken_event = pspp_sheet_view_grab_broken;
489 /*widget_class->configure_event = pspp_sheet_view_configure;*/
490 widget_class->motion_notify_event = pspp_sheet_view_motion;
491 widget_class->expose_event = pspp_sheet_view_expose;
492 widget_class->key_press_event = pspp_sheet_view_key_press;
493 widget_class->key_release_event = pspp_sheet_view_key_release;
494 widget_class->enter_notify_event = pspp_sheet_view_enter_notify;
495 widget_class->leave_notify_event = pspp_sheet_view_leave_notify;
496 widget_class->focus_out_event = pspp_sheet_view_focus_out;
497 widget_class->drag_begin = pspp_sheet_view_drag_begin;
498 widget_class->drag_end = pspp_sheet_view_drag_end;
499 widget_class->drag_data_get = pspp_sheet_view_drag_data_get;
500 widget_class->drag_data_delete = pspp_sheet_view_drag_data_delete;
501 widget_class->drag_leave = pspp_sheet_view_drag_leave;
502 widget_class->drag_motion = pspp_sheet_view_drag_motion;
503 widget_class->drag_drop = pspp_sheet_view_drag_drop;
504 widget_class->drag_data_received = pspp_sheet_view_drag_data_received;
505 widget_class->focus = pspp_sheet_view_focus;
506 widget_class->grab_focus = pspp_sheet_view_grab_focus;
507 widget_class->style_set = pspp_sheet_view_style_set;
508 widget_class->grab_notify = pspp_sheet_view_grab_notify;
509 widget_class->state_changed = pspp_sheet_view_state_changed;
511 /* GtkContainer signals */
512 container_class->remove = pspp_sheet_view_remove;
513 container_class->forall = pspp_sheet_view_forall;
514 container_class->set_focus_child = pspp_sheet_view_set_focus_child;
516 class->set_scroll_adjustments = pspp_sheet_view_set_adjustments;
517 class->move_cursor = pspp_sheet_view_real_move_cursor;
518 class->select_all = pspp_sheet_view_real_select_all;
519 class->unselect_all = pspp_sheet_view_real_unselect_all;
520 class->select_cursor_row = pspp_sheet_view_real_select_cursor_row;
521 class->toggle_cursor_row = pspp_sheet_view_real_toggle_cursor_row;
522 class->start_interactive_search = pspp_sheet_view_start_interactive_search;
526 g_object_class_install_property (o_class,
528 g_param_spec_object ("model",
529 P_("TreeView Model"),
530 P_("The model for the tree view"),
532 GTK_PARAM_READWRITE));
534 g_object_class_install_property (o_class,
536 g_param_spec_object ("hadjustment",
537 P_("Horizontal Adjustment"),
538 P_("Horizontal Adjustment for the widget"),
540 GTK_PARAM_READWRITE));
542 g_object_class_install_property (o_class,
544 g_param_spec_object ("vadjustment",
545 P_("Vertical Adjustment"),
546 P_("Vertical Adjustment for the widget"),
548 GTK_PARAM_READWRITE));
550 g_object_class_install_property (o_class,
551 PROP_HEADERS_VISIBLE,
552 g_param_spec_boolean ("headers-visible",
553 P_("Headers Visible"),
554 P_("Show the column header buttons"),
556 GTK_PARAM_READWRITE));
558 g_object_class_install_property (o_class,
559 PROP_HEADERS_CLICKABLE,
560 g_param_spec_boolean ("headers-clickable",
561 P_("Headers Clickable"),
562 P_("Column headers respond to click events"),
564 GTK_PARAM_READWRITE));
566 g_object_class_install_property (o_class,
568 g_param_spec_boolean ("reorderable",
570 P_("View is reorderable"),
572 GTK_PARAM_READWRITE));
574 g_object_class_install_property (o_class,
576 g_param_spec_boolean ("rules-hint",
578 P_("Set a hint to the theme engine to draw rows in alternating colors"),
580 GTK_PARAM_READWRITE));
582 g_object_class_install_property (o_class,
584 g_param_spec_boolean ("enable-search",
586 P_("View allows user to search through columns interactively"),
588 GTK_PARAM_READWRITE));
590 g_object_class_install_property (o_class,
592 g_param_spec_int ("search-column",
594 P_("Model column to search through during interactive search"),
598 GTK_PARAM_READWRITE));
601 * PsppSheetView:hover-selection:
603 * Enables of disables the hover selection mode of @tree_view.
604 * Hover selection makes the selected row follow the pointer.
605 * Currently, this works only for the selection modes
606 * %PSPP_SHEET_SELECTION_SINGLE and %PSPP_SHEET_SELECTION_BROWSE.
608 * This mode is primarily intended for treeviews in popups, e.g.
609 * in #GtkComboBox or #GtkEntryCompletion.
613 g_object_class_install_property (o_class,
614 PROP_HOVER_SELECTION,
615 g_param_spec_boolean ("hover-selection",
616 P_("Hover Selection"),
617 P_("Whether the selection should follow the pointer"),
619 GTK_PARAM_READWRITE));
621 g_object_class_install_property (o_class,
623 g_param_spec_boolean ("rubber-banding",
624 P_("Rubber Banding"),
625 P_("Whether to enable selection of multiple items by dragging the mouse pointer"),
627 GTK_PARAM_READWRITE));
629 g_object_class_install_property (o_class,
630 PROP_ENABLE_GRID_LINES,
631 g_param_spec_enum ("enable-grid-lines",
632 P_("Enable Grid Lines"),
633 P_("Whether grid lines should be drawn in the tree view"),
634 PSPP_TYPE_SHEET_VIEW_GRID_LINES,
635 PSPP_SHEET_VIEW_GRID_LINES_NONE,
636 GTK_PARAM_READWRITE));
638 g_object_class_install_property (o_class,
640 g_param_spec_int ("tooltip-column",
641 P_("Tooltip Column"),
642 P_("The column in the model containing the tooltip texts for the rows"),
646 GTK_PARAM_READWRITE));
648 g_object_class_install_property (o_class,
650 g_param_spec_enum ("special-cells",
652 P_("Whether rows have special cells."),
653 PSPP_TYPE_SHEET_VIEW_SPECIAL_CELLS,
654 PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT,
655 GTK_PARAM_READWRITE));
657 g_object_class_install_property (o_class,
659 g_param_spec_int ("fixed-height",
661 P_("Height of a single row. Normally the height of a row is determined automatically. Writing this property sets fixed-height-set to true, preventing this property's value from changing."),
665 GTK_PARAM_READWRITE));
667 g_object_class_install_property (o_class,
668 PROP_FIXED_HEIGHT_SET,
669 g_param_spec_boolean ("fixed-height-set",
670 P_("Fixed Height Set"),
671 P_("Whether fixed-height was set externally."),
673 GTK_PARAM_READWRITE));
675 /* Style properties */
676 #define _TREE_VIEW_EXPANDER_SIZE 12
677 #define _TREE_VIEW_VERTICAL_SEPARATOR 2
678 #define _TREE_VIEW_HORIZONTAL_SEPARATOR 2
680 gtk_widget_class_install_style_property (widget_class,
681 g_param_spec_int ("expander-size",
683 P_("Size of the expander arrow"),
686 _TREE_VIEW_EXPANDER_SIZE,
687 GTK_PARAM_READABLE));
689 gtk_widget_class_install_style_property (widget_class,
690 g_param_spec_int ("vertical-separator",
691 P_("Vertical Separator Width"),
692 P_("Vertical space between cells. Must be an even number"),
695 _TREE_VIEW_VERTICAL_SEPARATOR,
696 GTK_PARAM_READABLE));
698 gtk_widget_class_install_style_property (widget_class,
699 g_param_spec_int ("horizontal-separator",
700 P_("Horizontal Separator Width"),
701 P_("Horizontal space between cells. Must be an even number"),
704 _TREE_VIEW_HORIZONTAL_SEPARATOR,
705 GTK_PARAM_READABLE));
707 gtk_widget_class_install_style_property (widget_class,
708 g_param_spec_boolean ("allow-rules",
710 P_("Allow drawing of alternating color rows"),
712 GTK_PARAM_READABLE));
714 gtk_widget_class_install_style_property (widget_class,
715 g_param_spec_boxed ("even-row-color",
716 P_("Even Row Color"),
717 P_("Color to use for even rows"),
719 GTK_PARAM_READABLE));
721 gtk_widget_class_install_style_property (widget_class,
722 g_param_spec_boxed ("odd-row-color",
724 P_("Color to use for odd rows"),
726 GTK_PARAM_READABLE));
728 gtk_widget_class_install_style_property (widget_class,
729 g_param_spec_boolean ("row-ending-details",
730 P_("Row Ending details"),
731 P_("Enable extended row background theming"),
733 GTK_PARAM_READABLE));
735 gtk_widget_class_install_style_property (widget_class,
736 g_param_spec_int ("grid-line-width",
737 P_("Grid line width"),
738 P_("Width, in pixels, of the tree view grid lines"),
740 GTK_PARAM_READABLE));
742 gtk_widget_class_install_style_property (widget_class,
743 g_param_spec_int ("tree-line-width",
744 P_("Tree line width"),
745 P_("Width, in pixels, of the tree view lines"),
747 GTK_PARAM_READABLE));
749 gtk_widget_class_install_style_property (widget_class,
750 g_param_spec_string ("tree-line-pattern",
751 P_("Tree line pattern"),
752 P_("Dash pattern used to draw the tree view lines"),
754 GTK_PARAM_READABLE));
758 * PsppSheetView::set-scroll-adjustments
759 * @horizontal: the horizontal #GtkAdjustment
760 * @vertical: the vertical #GtkAdjustment
762 * Set the scroll adjustments for the tree view. Usually scrolled containers
763 * like #GtkScrolledWindow will emit this signal to connect two instances
764 * of #GtkScrollbar to the scroll directions of the #PsppSheetView.
766 widget_class->set_scroll_adjustments_signal =
767 g_signal_new ("set-scroll-adjustments",
768 G_TYPE_FROM_CLASS (o_class),
769 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
770 G_STRUCT_OFFSET (PsppSheetViewClass, set_scroll_adjustments),
772 psppire_marshal_VOID__OBJECT_OBJECT,
775 GTK_TYPE_ADJUSTMENT);
778 * PsppSheetView::row-activated:
779 * @tree_view: the object on which the signal is emitted
780 * @path: the #GtkTreePath for the activated row
781 * @column: the #PsppSheetViewColumn in which the activation occurred
783 * The "row-activated" signal is emitted when the method
784 * pspp_sheet_view_row_activated() is called or the user double clicks
785 * a treeview row. It is also emitted when a non-editable row is
786 * selected and one of the keys: Space, Shift+Space, Return or
789 * For selection handling refer to the <link linkend="TreeWidget">tree
790 * widget conceptual overview</link> as well as #PsppSheetSelection.
792 tree_view_signals[ROW_ACTIVATED] =
793 g_signal_new ("row-activated",
794 G_TYPE_FROM_CLASS (o_class),
795 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
796 G_STRUCT_OFFSET (PsppSheetViewClass, row_activated),
798 psppire_marshal_VOID__BOXED_OBJECT,
801 PSPP_TYPE_SHEET_VIEW_COLUMN);
804 * PsppSheetView::columns-changed:
805 * @tree_view: the object on which the signal is emitted
807 * The number of columns of the treeview has changed.
809 tree_view_signals[COLUMNS_CHANGED] =
810 g_signal_new ("columns-changed",
811 G_TYPE_FROM_CLASS (o_class),
813 G_STRUCT_OFFSET (PsppSheetViewClass, columns_changed),
815 g_cclosure_marshal_VOID__VOID,
819 * PsppSheetView::cursor-changed:
820 * @tree_view: the object on which the signal is emitted
822 * The position of the cursor (focused cell) has changed.
824 tree_view_signals[CURSOR_CHANGED] =
825 g_signal_new ("cursor-changed",
826 G_TYPE_FROM_CLASS (o_class),
828 G_STRUCT_OFFSET (PsppSheetViewClass, cursor_changed),
830 g_cclosure_marshal_VOID__VOID,
833 tree_view_signals[MOVE_CURSOR] =
834 g_signal_new ("move-cursor",
835 G_TYPE_FROM_CLASS (o_class),
836 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
837 G_STRUCT_OFFSET (PsppSheetViewClass, move_cursor),
839 psppire_marshal_BOOLEAN__ENUM_INT,
841 GTK_TYPE_MOVEMENT_STEP,
844 tree_view_signals[SELECT_ALL] =
845 g_signal_new ("select-all",
846 G_TYPE_FROM_CLASS (o_class),
847 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
848 G_STRUCT_OFFSET (PsppSheetViewClass, select_all),
850 psppire_marshal_BOOLEAN__VOID,
853 tree_view_signals[UNSELECT_ALL] =
854 g_signal_new ("unselect-all",
855 G_TYPE_FROM_CLASS (o_class),
856 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
857 G_STRUCT_OFFSET (PsppSheetViewClass, unselect_all),
859 psppire_marshal_BOOLEAN__VOID,
862 tree_view_signals[SELECT_CURSOR_ROW] =
863 g_signal_new ("select-cursor-row",
864 G_TYPE_FROM_CLASS (o_class),
865 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
866 G_STRUCT_OFFSET (PsppSheetViewClass, select_cursor_row),
868 psppire_marshal_BOOLEAN__BOOLEAN,
870 G_TYPE_BOOLEAN, G_TYPE_INT);
872 tree_view_signals[TOGGLE_CURSOR_ROW] =
873 g_signal_new ("toggle-cursor-row",
874 G_TYPE_FROM_CLASS (o_class),
875 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
876 G_STRUCT_OFFSET (PsppSheetViewClass, toggle_cursor_row),
878 psppire_marshal_BOOLEAN__VOID,
881 tree_view_signals[START_INTERACTIVE_SEARCH] =
882 g_signal_new ("start-interactive-search",
883 G_TYPE_FROM_CLASS (o_class),
884 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
885 G_STRUCT_OFFSET (PsppSheetViewClass, start_interactive_search),
887 psppire_marshal_BOOLEAN__VOID,
891 for (i = 0; i < 2; i++)
893 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Up, 0, TRUE,
894 GTK_MOVEMENT_DISPLAY_LINES, -1);
895 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Up, 0, TRUE,
896 GTK_MOVEMENT_DISPLAY_LINES, -1);
898 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Down, 0, TRUE,
899 GTK_MOVEMENT_DISPLAY_LINES, 1);
900 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Down, 0, TRUE,
901 GTK_MOVEMENT_DISPLAY_LINES, 1);
903 pspp_sheet_view_add_move_binding (binding_set[i], GDK_p, GDK_CONTROL_MASK, FALSE,
904 GTK_MOVEMENT_DISPLAY_LINES, -1);
906 pspp_sheet_view_add_move_binding (binding_set[i], GDK_n, GDK_CONTROL_MASK, FALSE,
907 GTK_MOVEMENT_DISPLAY_LINES, 1);
909 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Home, 0, TRUE,
910 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
911 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Home, 0, TRUE,
912 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
914 pspp_sheet_view_add_move_binding (binding_set[i], GDK_End, 0, TRUE,
915 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
916 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_End, 0, TRUE,
917 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
919 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Page_Up, 0, TRUE,
920 GTK_MOVEMENT_PAGES, -1);
921 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Page_Up, 0, TRUE,
922 GTK_MOVEMENT_PAGES, -1);
924 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Page_Down, 0, TRUE,
925 GTK_MOVEMENT_PAGES, 1);
926 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Page_Down, 0, TRUE,
927 GTK_MOVEMENT_PAGES, 1);
930 gtk_binding_entry_add_signal (binding_set[i], GDK_Up, GDK_CONTROL_MASK, "move-cursor", 2,
931 G_TYPE_ENUM, GTK_MOVEMENT_BUFFER_ENDS,
934 gtk_binding_entry_add_signal (binding_set[i], GDK_Down, GDK_CONTROL_MASK, "move-cursor", 2,
935 G_TYPE_ENUM, GTK_MOVEMENT_BUFFER_ENDS,
938 gtk_binding_entry_add_signal (binding_set[i], GDK_Right, 0, "move-cursor", 2,
939 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
942 gtk_binding_entry_add_signal (binding_set[i], GDK_Left, 0, "move-cursor", 2,
943 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
946 gtk_binding_entry_add_signal (binding_set[i], GDK_Tab, 0, "move-cursor", 2,
947 G_TYPE_ENUM, GTK_MOVEMENT_LOGICAL_POSITIONS,
950 gtk_binding_entry_add_signal (binding_set[i], GDK_Tab, GDK_SHIFT_MASK, "move-cursor", 2,
951 G_TYPE_ENUM, GTK_MOVEMENT_LOGICAL_POSITIONS,
954 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Right, 0, "move-cursor", 2,
955 G_TYPE_ENUM, GTK_MOVEMENT_DISPLAY_LINE_ENDS,
958 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Left, 0, "move-cursor", 2,
959 G_TYPE_ENUM, GTK_MOVEMENT_DISPLAY_LINE_ENDS,
962 gtk_binding_entry_add_signal (binding_set[i], GDK_Right, GDK_CONTROL_MASK,
964 G_TYPE_ENUM, GTK_MOVEMENT_DISPLAY_LINE_ENDS,
967 gtk_binding_entry_add_signal (binding_set[i], GDK_Left, GDK_CONTROL_MASK,
969 G_TYPE_ENUM, GTK_MOVEMENT_DISPLAY_LINE_ENDS,
972 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Right, GDK_CONTROL_MASK,
974 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
977 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Left, GDK_CONTROL_MASK,
979 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
982 gtk_binding_entry_add_signal (binding_set[i], GDK_f, GDK_CONTROL_MASK, "start-interactive-search", 0);
984 gtk_binding_entry_add_signal (binding_set[i], GDK_F, GDK_CONTROL_MASK, "start-interactive-search", 0);
987 gtk_binding_entry_add_signal (binding_set[0], GDK_space, GDK_CONTROL_MASK, "toggle-cursor-row", 0);
988 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Space, GDK_CONTROL_MASK, "toggle-cursor-row", 0);
990 gtk_binding_entry_add_signal (binding_set[0], GDK_a, GDK_CONTROL_MASK, "select-all", 0);
991 gtk_binding_entry_add_signal (binding_set[0], GDK_slash, GDK_CONTROL_MASK, "select-all", 0);
993 gtk_binding_entry_add_signal (binding_set[0], GDK_A, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "unselect-all", 0);
994 gtk_binding_entry_add_signal (binding_set[0], GDK_backslash, GDK_CONTROL_MASK, "unselect-all", 0);
996 gtk_binding_entry_add_signal (binding_set[0], GDK_space, GDK_SHIFT_MASK, "select-cursor-row", 1,
997 G_TYPE_BOOLEAN, TRUE,
998 G_TYPE_INT, PSPP_SHEET_SELECT_MODE_EXTEND);
999 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Space, GDK_SHIFT_MASK, "select-cursor-row", 1,
1000 G_TYPE_BOOLEAN, TRUE,
1001 G_TYPE_INT, PSPP_SHEET_SELECT_MODE_EXTEND);
1003 gtk_binding_entry_add_signal (binding_set[0], GDK_space, 0, "select-cursor-row", 1,
1004 G_TYPE_BOOLEAN, TRUE,
1006 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Space, 0, "select-cursor-row", 1,
1007 G_TYPE_BOOLEAN, TRUE,
1009 gtk_binding_entry_add_signal (binding_set[0], GDK_Return, 0, "select-cursor-row", 1,
1010 G_TYPE_BOOLEAN, TRUE,
1012 gtk_binding_entry_add_signal (binding_set[0], GDK_ISO_Enter, 0, "select-cursor-row", 1,
1013 G_TYPE_BOOLEAN, TRUE,
1015 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Enter, 0, "select-cursor-row", 1,
1016 G_TYPE_BOOLEAN, TRUE,
1019 gtk_binding_entry_add_signal (binding_set[0], GDK_BackSpace, 0, "select-cursor-parent", 0);
1020 gtk_binding_entry_add_signal (binding_set[0], GDK_BackSpace, GDK_CONTROL_MASK, "select-cursor-parent", 0);
1022 g_type_class_add_private (o_class, sizeof (PsppSheetViewPrivate));
1026 pspp_sheet_view_buildable_init (GtkBuildableIface *iface)
1028 iface->add_child = pspp_sheet_view_buildable_add_child;
1032 pspp_sheet_view_init (PsppSheetView *tree_view)
1034 tree_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (tree_view, PSPP_TYPE_SHEET_VIEW, PsppSheetViewPrivate);
1036 gtk_widget_set_can_focus (GTK_WIDGET (tree_view), TRUE);
1037 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (tree_view), FALSE);
1039 tree_view->priv->flags = PSPP_SHEET_VIEW_DRAW_KEYFOCUS
1040 | PSPP_SHEET_VIEW_HEADERS_VISIBLE;
1042 /* We need some padding */
1043 tree_view->priv->selected = range_tower_create ();
1044 tree_view->priv->dy = 0;
1045 tree_view->priv->cursor_offset = 0;
1046 tree_view->priv->n_columns = 0;
1047 tree_view->priv->header_height = 1;
1048 tree_view->priv->x_drag = 0;
1049 tree_view->priv->drag_pos = -1;
1050 tree_view->priv->header_has_focus = FALSE;
1051 tree_view->priv->pressed_button = -1;
1052 tree_view->priv->press_start_x = -1;
1053 tree_view->priv->press_start_y = -1;
1054 tree_view->priv->reorderable = FALSE;
1055 tree_view->priv->presize_handler_timer = 0;
1056 tree_view->priv->scroll_sync_timer = 0;
1057 tree_view->priv->fixed_height = -1;
1058 tree_view->priv->fixed_height_set = FALSE;
1059 pspp_sheet_view_set_adjustments (tree_view, NULL, NULL);
1060 tree_view->priv->selection = _pspp_sheet_selection_new_with_tree_view (tree_view);
1061 tree_view->priv->enable_search = TRUE;
1062 tree_view->priv->search_column = -1;
1063 tree_view->priv->search_position_func = pspp_sheet_view_search_position_func;
1064 tree_view->priv->search_equal_func = pspp_sheet_view_search_equal_func;
1065 tree_view->priv->search_custom_entry_set = FALSE;
1066 tree_view->priv->typeselect_flush_timeout = 0;
1067 tree_view->priv->init_hadjust_value = TRUE;
1068 tree_view->priv->width = 0;
1070 tree_view->priv->hover_selection = FALSE;
1072 tree_view->priv->rubber_banding_enable = FALSE;
1074 tree_view->priv->grid_lines = PSPP_SHEET_VIEW_GRID_LINES_NONE;
1076 tree_view->priv->tooltip_column = -1;
1078 tree_view->priv->special_cells = PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT;
1080 tree_view->priv->post_validation_flag = FALSE;
1082 tree_view->priv->last_button_x = -1;
1083 tree_view->priv->last_button_y = -1;
1085 tree_view->priv->event_last_x = -10000;
1086 tree_view->priv->event_last_y = -10000;
1088 tree_view->priv->prelight_node = -1;
1089 tree_view->priv->rubber_band_start_node = -1;
1090 tree_view->priv->rubber_band_end_node = -1;
1092 tree_view->priv->anchor_column = NULL;
1094 tree_view->priv->button_style = NULL;
1096 tree_view->dispose_has_run = FALSE;
1105 pspp_sheet_view_set_property (GObject *object,
1107 const GValue *value,
1110 PsppSheetView *tree_view;
1112 tree_view = PSPP_SHEET_VIEW (object);
1117 pspp_sheet_view_set_model (tree_view, g_value_get_object (value));
1119 case PROP_HADJUSTMENT:
1120 pspp_sheet_view_set_hadjustment (tree_view, g_value_get_object (value));
1122 case PROP_VADJUSTMENT:
1123 pspp_sheet_view_set_vadjustment (tree_view, g_value_get_object (value));
1125 case PROP_HEADERS_VISIBLE:
1126 pspp_sheet_view_set_headers_visible (tree_view, g_value_get_boolean (value));
1128 case PROP_HEADERS_CLICKABLE:
1129 pspp_sheet_view_set_headers_clickable (tree_view, g_value_get_boolean (value));
1131 case PROP_REORDERABLE:
1132 pspp_sheet_view_set_reorderable (tree_view, g_value_get_boolean (value));
1134 case PROP_RULES_HINT:
1135 pspp_sheet_view_set_rules_hint (tree_view, g_value_get_boolean (value));
1137 case PROP_ENABLE_SEARCH:
1138 pspp_sheet_view_set_enable_search (tree_view, g_value_get_boolean (value));
1140 case PROP_SEARCH_COLUMN:
1141 pspp_sheet_view_set_search_column (tree_view, g_value_get_int (value));
1143 case PROP_HOVER_SELECTION:
1144 tree_view->priv->hover_selection = g_value_get_boolean (value);
1146 case PROP_RUBBER_BANDING:
1147 tree_view->priv->rubber_banding_enable = g_value_get_boolean (value);
1149 case PROP_ENABLE_GRID_LINES:
1150 pspp_sheet_view_set_grid_lines (tree_view, g_value_get_enum (value));
1152 case PROP_TOOLTIP_COLUMN:
1153 pspp_sheet_view_set_tooltip_column (tree_view, g_value_get_int (value));
1155 case PROP_SPECIAL_CELLS:
1156 pspp_sheet_view_set_special_cells (tree_view, g_value_get_enum (value));
1158 case PROP_FIXED_HEIGHT:
1159 pspp_sheet_view_set_fixed_height (tree_view, g_value_get_int (value));
1161 case PROP_FIXED_HEIGHT_SET:
1162 if (g_value_get_boolean (value))
1164 if (!tree_view->priv->fixed_height_set
1165 && tree_view->priv->fixed_height >= 0)
1167 tree_view->priv->fixed_height_set = true;
1168 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
1173 if (tree_view->priv->fixed_height_set)
1175 tree_view->priv->fixed_height_set = false;
1176 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
1177 install_presize_handler (tree_view);
1182 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1188 pspp_sheet_view_get_property (GObject *object,
1193 PsppSheetView *tree_view;
1195 tree_view = PSPP_SHEET_VIEW (object);
1200 g_value_set_object (value, tree_view->priv->model);
1202 case PROP_HADJUSTMENT:
1203 g_value_set_object (value, tree_view->priv->hadjustment);
1205 case PROP_VADJUSTMENT:
1206 g_value_set_object (value, tree_view->priv->vadjustment);
1208 case PROP_HEADERS_VISIBLE:
1209 g_value_set_boolean (value, pspp_sheet_view_get_headers_visible (tree_view));
1211 case PROP_HEADERS_CLICKABLE:
1212 g_value_set_boolean (value, pspp_sheet_view_get_headers_clickable (tree_view));
1214 case PROP_REORDERABLE:
1215 g_value_set_boolean (value, tree_view->priv->reorderable);
1217 case PROP_RULES_HINT:
1218 g_value_set_boolean (value, tree_view->priv->has_rules);
1220 case PROP_ENABLE_SEARCH:
1221 g_value_set_boolean (value, tree_view->priv->enable_search);
1223 case PROP_SEARCH_COLUMN:
1224 g_value_set_int (value, tree_view->priv->search_column);
1226 case PROP_HOVER_SELECTION:
1227 g_value_set_boolean (value, tree_view->priv->hover_selection);
1229 case PROP_RUBBER_BANDING:
1230 g_value_set_boolean (value, tree_view->priv->rubber_banding_enable);
1232 case PROP_ENABLE_GRID_LINES:
1233 g_value_set_enum (value, tree_view->priv->grid_lines);
1235 case PROP_TOOLTIP_COLUMN:
1236 g_value_set_int (value, tree_view->priv->tooltip_column);
1238 case PROP_SPECIAL_CELLS:
1239 g_value_set_enum (value, tree_view->priv->special_cells);
1241 case PROP_FIXED_HEIGHT:
1242 g_value_set_int (value, pspp_sheet_view_get_fixed_height (tree_view));
1244 case PROP_FIXED_HEIGHT_SET:
1245 g_value_set_boolean (value, tree_view->priv->fixed_height_set);
1248 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1254 pspp_sheet_view_dispose (GObject *object)
1256 PsppSheetView *tree_view = PSPP_SHEET_VIEW (object);
1258 if (tree_view->dispose_has_run)
1261 tree_view->dispose_has_run = TRUE;
1263 if (tree_view->priv->selection != NULL)
1265 _pspp_sheet_selection_set_tree_view (tree_view->priv->selection, NULL);
1266 g_object_unref (tree_view->priv->selection);
1267 tree_view->priv->selection = NULL;
1270 if (tree_view->priv->hadjustment)
1272 g_object_unref (tree_view->priv->hadjustment);
1273 tree_view->priv->hadjustment = NULL;
1275 if (tree_view->priv->vadjustment)
1277 g_object_unref (tree_view->priv->vadjustment);
1278 tree_view->priv->vadjustment = NULL;
1281 if (tree_view->priv->button_style)
1283 g_object_unref (tree_view->priv->button_style);
1284 tree_view->priv->button_style = NULL;
1288 G_OBJECT_CLASS (pspp_sheet_view_parent_class)->dispose (object);
1294 pspp_sheet_view_buildable_add_child (GtkBuildable *tree_view,
1295 GtkBuilder *builder,
1299 pspp_sheet_view_append_column (PSPP_SHEET_VIEW (tree_view), PSPP_SHEET_VIEW_COLUMN (child));
1303 pspp_sheet_view_finalize (GObject *object)
1305 PsppSheetView *tree_view = PSPP_SHEET_VIEW (object);
1307 pspp_sheet_view_stop_editing (tree_view, TRUE);
1309 if (tree_view->priv->selected != NULL)
1311 range_tower_destroy (tree_view->priv->selected);
1312 tree_view->priv->selected = NULL;
1316 tree_view->priv->prelight_node = -1;
1319 if (tree_view->priv->scroll_to_path != NULL)
1321 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
1322 tree_view->priv->scroll_to_path = NULL;
1325 if (tree_view->priv->drag_dest_row != NULL)
1327 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
1328 tree_view->priv->drag_dest_row = NULL;
1331 if (tree_view->priv->top_row != NULL)
1333 gtk_tree_row_reference_free (tree_view->priv->top_row);
1334 tree_view->priv->top_row = NULL;
1337 if (tree_view->priv->column_drop_func_data &&
1338 tree_view->priv->column_drop_func_data_destroy)
1340 tree_view->priv->column_drop_func_data_destroy (tree_view->priv->column_drop_func_data);
1341 tree_view->priv->column_drop_func_data = NULL;
1344 if (tree_view->priv->destroy_count_destroy &&
1345 tree_view->priv->destroy_count_data)
1347 tree_view->priv->destroy_count_destroy (tree_view->priv->destroy_count_data);
1348 tree_view->priv->destroy_count_data = NULL;
1351 gtk_tree_row_reference_free (tree_view->priv->cursor);
1352 tree_view->priv->cursor = NULL;
1354 gtk_tree_row_reference_free (tree_view->priv->anchor);
1355 tree_view->priv->anchor = NULL;
1357 /* destroy interactive search dialog */
1358 if (tree_view->priv->search_window)
1360 gtk_widget_destroy (tree_view->priv->search_window);
1361 tree_view->priv->search_window = NULL;
1362 tree_view->priv->search_entry = NULL;
1363 if (tree_view->priv->typeselect_flush_timeout)
1365 g_source_remove (tree_view->priv->typeselect_flush_timeout);
1366 tree_view->priv->typeselect_flush_timeout = 0;
1370 if (tree_view->priv->search_destroy && tree_view->priv->search_user_data)
1372 tree_view->priv->search_destroy (tree_view->priv->search_user_data);
1373 tree_view->priv->search_user_data = NULL;
1376 if (tree_view->priv->search_position_destroy && tree_view->priv->search_position_user_data)
1378 tree_view->priv->search_position_destroy (tree_view->priv->search_position_user_data);
1379 tree_view->priv->search_position_user_data = NULL;
1382 pspp_sheet_view_set_model (tree_view, NULL);
1385 G_OBJECT_CLASS (pspp_sheet_view_parent_class)->finalize (object);
1390 /* GtkWidget Methods
1393 /* GtkWidget::map helper */
1395 pspp_sheet_view_map_buttons (PsppSheetView *tree_view)
1399 g_return_if_fail (gtk_widget_get_mapped (GTK_WIDGET (tree_view)));
1401 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
1403 PsppSheetViewColumn *column;
1405 for (list = tree_view->priv->columns; list; list = list->next)
1407 column = list->data;
1408 if (column->button != NULL &&
1409 gtk_widget_get_visible (column->button) &&
1410 !gtk_widget_get_mapped (column->button))
1411 gtk_widget_map (column->button);
1413 for (list = tree_view->priv->columns; list; list = list->next)
1415 column = list->data;
1416 if (column->visible == FALSE || column->window == NULL)
1418 if (column->resizable)
1420 gdk_window_raise (column->window);
1421 gdk_window_show (column->window);
1424 gdk_window_hide (column->window);
1426 gdk_window_show (tree_view->priv->header_window);
1431 pspp_sheet_view_map (GtkWidget *widget)
1433 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1436 gtk_widget_set_mapped (widget, TRUE);
1438 tmp_list = tree_view->priv->children;
1441 PsppSheetViewChild *child = tmp_list->data;
1442 tmp_list = tmp_list->next;
1444 if (gtk_widget_get_visible (child->widget))
1446 if (!gtk_widget_get_mapped (child->widget))
1447 gtk_widget_map (child->widget);
1450 gdk_window_show (tree_view->priv->bin_window);
1452 pspp_sheet_view_map_buttons (tree_view);
1454 gdk_window_show (gtk_widget_get_window (widget));
1458 pspp_sheet_view_realize (GtkWidget *widget)
1460 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1462 GdkWindowAttr attributes;
1463 gint attributes_mask;
1464 GtkAllocation allocation;
1465 GtkAllocation old_allocation;
1467 gtk_widget_set_realized (widget, TRUE);
1469 gtk_widget_get_allocation (widget, &allocation);
1470 gtk_widget_get_allocation (widget, &old_allocation);
1472 /* Make the main, clipping window */
1473 attributes.window_type = GDK_WINDOW_CHILD;
1474 attributes.x = allocation.x;
1475 attributes.y = allocation.y;
1476 attributes.width = allocation.width;
1477 attributes.height = allocation.height;
1478 attributes.wclass = GDK_INPUT_OUTPUT;
1479 attributes.visual = gtk_widget_get_visual (widget);
1480 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1482 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
1484 gtk_widget_set_window (widget,
1485 gdk_window_new (gtk_widget_get_parent_window (widget),
1486 &attributes, attributes_mask));
1487 gdk_window_set_user_data (gtk_widget_get_window (widget), widget);
1489 /* Make the window for the tree */
1491 attributes.y = TREE_VIEW_HEADER_HEIGHT (tree_view);
1492 attributes.width = MAX (tree_view->priv->width, old_allocation.width);
1493 attributes.height = old_allocation.height;
1494 attributes.event_mask = (GDK_EXPOSURE_MASK |
1496 GDK_POINTER_MOTION_MASK |
1497 GDK_ENTER_NOTIFY_MASK |
1498 GDK_LEAVE_NOTIFY_MASK |
1499 GDK_BUTTON_PRESS_MASK |
1500 GDK_BUTTON_RELEASE_MASK |
1501 gtk_widget_get_events (widget));
1503 tree_view->priv->bin_window = gdk_window_new (gtk_widget_get_window (widget),
1504 &attributes, attributes_mask);
1505 gdk_window_set_user_data (tree_view->priv->bin_window, widget);
1507 /* Make the column header window */
1510 attributes.width = MAX (tree_view->priv->width, old_allocation.width);
1511 attributes.height = tree_view->priv->header_height;
1512 attributes.event_mask = (GDK_EXPOSURE_MASK |
1514 GDK_BUTTON_PRESS_MASK |
1515 GDK_BUTTON_RELEASE_MASK |
1516 GDK_KEY_PRESS_MASK |
1517 GDK_KEY_RELEASE_MASK |
1518 gtk_widget_get_events (widget));
1520 tree_view->priv->header_window = gdk_window_new (gtk_widget_get_window (widget),
1521 &attributes, attributes_mask);
1522 gdk_window_set_user_data (tree_view->priv->header_window, widget);
1524 /* Add them all up. */
1525 gtk_widget_set_style (widget,
1526 gtk_style_attach (gtk_widget_get_style (widget), gtk_widget_get_window (widget)));
1527 gdk_window_set_background (tree_view->priv->bin_window, >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
1528 gtk_style_set_background (gtk_widget_get_style (widget), tree_view->priv->header_window, GTK_STATE_NORMAL);
1530 tmp_list = tree_view->priv->children;
1533 PsppSheetViewChild *child = tmp_list->data;
1534 tmp_list = tmp_list->next;
1536 gtk_widget_set_parent_window (child->widget, tree_view->priv->bin_window);
1539 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
1540 _pspp_sheet_view_column_realize_button (PSPP_SHEET_VIEW_COLUMN (tmp_list->data));
1542 /* Need to call those here, since they create GCs */
1543 pspp_sheet_view_set_grid_lines (tree_view, tree_view->priv->grid_lines);
1545 install_presize_handler (tree_view);
1549 pspp_sheet_view_unrealize (GtkWidget *widget)
1551 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1552 PsppSheetViewPrivate *priv = tree_view->priv;
1555 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->unrealize (widget);
1557 if (priv->scroll_timeout != 0)
1559 g_source_remove (priv->scroll_timeout);
1560 priv->scroll_timeout = 0;
1563 if (priv->open_dest_timeout != 0)
1565 g_source_remove (priv->open_dest_timeout);
1566 priv->open_dest_timeout = 0;
1569 if (priv->presize_handler_timer != 0)
1571 g_source_remove (priv->presize_handler_timer);
1572 priv->presize_handler_timer = 0;
1575 if (priv->validate_rows_timer != 0)
1577 g_source_remove (priv->validate_rows_timer);
1578 priv->validate_rows_timer = 0;
1581 if (priv->scroll_sync_timer != 0)
1583 g_source_remove (priv->scroll_sync_timer);
1584 priv->scroll_sync_timer = 0;
1587 if (priv->typeselect_flush_timeout)
1589 g_source_remove (priv->typeselect_flush_timeout);
1590 priv->typeselect_flush_timeout = 0;
1593 for (list = priv->columns; list; list = list->next)
1594 _pspp_sheet_view_column_unrealize_button (PSPP_SHEET_VIEW_COLUMN (list->data));
1596 gdk_window_set_user_data (priv->bin_window, NULL);
1597 gdk_window_destroy (priv->bin_window);
1598 priv->bin_window = NULL;
1600 gdk_window_set_user_data (priv->header_window, NULL);
1601 gdk_window_destroy (priv->header_window);
1602 priv->header_window = NULL;
1604 if (priv->drag_window)
1606 gdk_window_set_user_data (priv->drag_window, NULL);
1607 gdk_window_destroy (priv->drag_window);
1608 priv->drag_window = NULL;
1611 if (priv->drag_highlight_window)
1613 gdk_window_set_user_data (priv->drag_highlight_window, NULL);
1614 gdk_window_destroy (priv->drag_highlight_window);
1615 priv->drag_highlight_window = NULL;
1618 if (tree_view->priv->columns != NULL)
1620 list = tree_view->priv->columns;
1623 PsppSheetViewColumn *column;
1624 column = PSPP_SHEET_VIEW_COLUMN (list->data);
1626 pspp_sheet_view_remove_column (tree_view, column);
1628 tree_view->priv->columns = NULL;
1632 /* GtkWidget::size_request helper */
1634 pspp_sheet_view_size_request_columns (PsppSheetView *tree_view)
1638 tree_view->priv->header_height = 0;
1640 if (tree_view->priv->model)
1642 for (list = tree_view->priv->columns; list; list = list->next)
1644 GtkRequisition requisition;
1645 PsppSheetViewColumn *column = list->data;
1647 pspp_sheet_view_column_size_request (column, &requisition);
1648 column->button_request = requisition.width;
1649 tree_view->priv->header_height = MAX (tree_view->priv->header_height, requisition.height);
1655 /* Called only by ::size_request */
1657 pspp_sheet_view_update_size (PsppSheetView *tree_view)
1660 PsppSheetViewColumn *column;
1663 if (tree_view->priv->model == NULL)
1665 tree_view->priv->width = 0;
1666 tree_view->priv->prev_width = 0;
1667 tree_view->priv->height = 0;
1671 tree_view->priv->prev_width = tree_view->priv->width;
1672 tree_view->priv->width = 0;
1674 /* keep this in sync with size_allocate below */
1675 for (list = tree_view->priv->columns, i = 0; list; list = list->next, i++)
1677 gint real_requested_width = 0;
1678 column = list->data;
1679 if (!column->visible)
1682 if (column->use_resized_width)
1684 real_requested_width = column->resized_width;
1688 real_requested_width = column->fixed_width;
1691 if (column->min_width != -1)
1692 real_requested_width = MAX (real_requested_width, column->min_width);
1693 if (column->max_width != -1)
1694 real_requested_width = MIN (real_requested_width, column->max_width);
1696 tree_view->priv->width += real_requested_width;
1699 tree_view->priv->height = tree_view->priv->fixed_height * tree_view->priv->row_count;
1703 pspp_sheet_view_size_request (GtkWidget *widget,
1704 GtkRequisition *requisition)
1706 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1709 /* we validate some rows initially just to make sure we have some size.
1710 * In practice, with a lot of static lists, this should get a good width.
1712 initialize_fixed_height_mode (tree_view);
1713 pspp_sheet_view_size_request_columns (tree_view);
1714 pspp_sheet_view_update_size (PSPP_SHEET_VIEW (widget));
1716 requisition->width = tree_view->priv->width;
1717 requisition->height = tree_view->priv->height + TREE_VIEW_HEADER_HEIGHT (tree_view);
1719 tmp_list = tree_view->priv->children;
1723 PsppSheetViewChild *child = tmp_list->data;
1724 GtkRequisition child_requisition;
1726 tmp_list = tmp_list->next;
1728 if (gtk_widget_get_visible (child->widget))
1729 gtk_widget_size_request (child->widget, &child_requisition);
1734 invalidate_column (PsppSheetView *tree_view,
1735 PsppSheetViewColumn *column)
1737 gint column_offset = 0;
1739 GtkWidget *widget = GTK_WIDGET (tree_view);
1742 if (!gtk_widget_get_realized (widget))
1745 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
1746 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
1748 list = (rtl ? list->prev : list->next))
1750 PsppSheetViewColumn *tmpcolumn = list->data;
1751 if (tmpcolumn == column)
1753 GdkRectangle invalid_rect;
1754 GtkAllocation allocation;
1756 gtk_widget_get_allocation (widget, &allocation);
1757 invalid_rect.x = column_offset;
1759 invalid_rect.width = column->width;
1760 invalid_rect.height = allocation.height;
1762 gdk_window_invalidate_rect (gtk_widget_get_window (widget), &invalid_rect, TRUE);
1766 column_offset += tmpcolumn->width;
1771 invalidate_last_column (PsppSheetView *tree_view)
1776 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
1778 for (last_column = (rtl ? g_list_first (tree_view->priv->columns) : g_list_last (tree_view->priv->columns));
1780 last_column = (rtl ? last_column->next : last_column->prev))
1782 if (PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible)
1784 invalidate_column (tree_view, last_column->data);
1791 pspp_sheet_view_get_real_requested_width_from_column (PsppSheetView *tree_view,
1792 PsppSheetViewColumn *column)
1794 gint real_requested_width;
1796 if (column->use_resized_width)
1798 real_requested_width = column->resized_width;
1802 real_requested_width = column->fixed_width;
1805 if (column->min_width != -1)
1806 real_requested_width = MAX (real_requested_width, column->min_width);
1807 if (column->max_width != -1)
1808 real_requested_width = MIN (real_requested_width, column->max_width);
1810 return real_requested_width;
1814 span_intersects (int a0, int a_width,
1815 int b0, int b_width)
1817 int a1 = a0 + a_width;
1818 int b1 = b0 + b_width;
1819 return (a0 >= b0 && a0 < b1) || (b0 >= a0 && b0 < a1);
1822 /* GtkWidget::size_allocate helper */
1824 pspp_sheet_view_size_allocate_columns (GtkWidget *widget,
1825 gboolean *width_changed)
1827 PsppSheetView *tree_view;
1828 GList *list, *first_column, *last_column;
1829 PsppSheetViewColumn *column;
1830 GtkAllocation col_allocation;
1831 GtkAllocation allocation;
1833 gint extra, extra_per_column;
1834 gint full_requested_width = 0;
1835 gint number_of_expand_columns = 0;
1836 gboolean column_changed = FALSE;
1839 tree_view = PSPP_SHEET_VIEW (widget);
1841 for (last_column = g_list_last (tree_view->priv->columns);
1842 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
1843 last_column = last_column->prev)
1846 if (last_column == NULL)
1849 for (first_column = g_list_first (tree_view->priv->columns);
1850 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
1851 first_column = first_column->next)
1854 col_allocation.y = 0;
1855 col_allocation.height = tree_view->priv->header_height;
1857 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1859 /* find out how many extra space and expandable columns we have */
1860 for (list = tree_view->priv->columns; list != last_column->next; list = list->next)
1862 column = (PsppSheetViewColumn *)list->data;
1864 if (!column->visible)
1867 full_requested_width += pspp_sheet_view_get_real_requested_width_from_column (tree_view, column);
1870 number_of_expand_columns++;
1873 gtk_widget_get_allocation (widget, &allocation);
1874 extra = MAX (allocation.width - full_requested_width, 0);
1875 if (number_of_expand_columns > 0)
1876 extra_per_column = extra/number_of_expand_columns;
1878 extra_per_column = 0;
1880 for (list = (rtl ? last_column : first_column);
1881 list != (rtl ? first_column->prev : last_column->next);
1882 list = (rtl ? list->prev : list->next))
1884 gint real_requested_width = 0;
1887 column = list->data;
1888 old_width = column->width;
1890 if (!column->visible)
1893 /* We need to handle the dragged button specially.
1895 if (column == tree_view->priv->drag_column)
1897 GtkAllocation drag_allocation;
1898 drag_allocation.width = gdk_window_get_width (tree_view->priv->drag_window);
1899 drag_allocation.height = gdk_window_get_height (tree_view->priv->drag_window);
1900 drag_allocation.x = 0;
1901 drag_allocation.y = 0;
1902 pspp_sheet_view_column_size_allocate (tree_view->priv->drag_column,
1904 width += drag_allocation.width;
1908 real_requested_width = pspp_sheet_view_get_real_requested_width_from_column (tree_view, column);
1910 col_allocation.x = width;
1911 column->width = real_requested_width;
1915 if (number_of_expand_columns == 1)
1917 /* We add the remander to the last column as
1919 column->width += extra;
1923 column->width += extra_per_column;
1924 extra -= extra_per_column;
1925 number_of_expand_columns --;
1929 if (column->width != old_width)
1930 g_object_notify (G_OBJECT (column), "width");
1932 col_allocation.width = column->width;
1933 width += column->width;
1935 if (column->width > old_width)
1936 column_changed = TRUE;
1938 pspp_sheet_view_column_size_allocate (column, &col_allocation);
1940 if (span_intersects (col_allocation.x, col_allocation.width,
1941 gtk_adjustment_get_value (tree_view->priv->hadjustment),
1943 && gtk_widget_get_realized (widget))
1944 pspp_sheet_view_column_set_need_button (column, TRUE);
1947 gdk_window_move_resize (column->window,
1948 col_allocation.x + (rtl ? 0 : col_allocation.width) - TREE_VIEW_DRAG_WIDTH/2,
1950 TREE_VIEW_DRAG_WIDTH, col_allocation.height);
1953 /* We change the width here. The user might have been resizing columns,
1954 * so the total width of the tree view changes.
1956 tree_view->priv->width = width;
1958 *width_changed = TRUE;
1961 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
1965 pspp_sheet_view_size_allocate (GtkWidget *widget,
1966 GtkAllocation *allocation)
1968 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1970 gboolean width_changed = FALSE;
1971 GtkAllocation old_allocation;
1972 gtk_widget_get_allocation (widget, &old_allocation);
1974 if (allocation->width != old_allocation.width)
1975 width_changed = TRUE;
1978 gtk_widget_set_allocation (widget, allocation);
1980 tmp_list = tree_view->priv->children;
1984 GtkAllocation allocation;
1986 PsppSheetViewChild *child = tmp_list->data;
1987 tmp_list = tmp_list->next;
1989 /* totally ignore our child's requisition */
1990 allocation.x = child->x;
1991 allocation.y = child->y;
1992 allocation.width = child->width;
1993 allocation.height = child->height;
1994 gtk_widget_size_allocate (child->widget, &allocation);
1997 /* We size-allocate the columns first because the width of the
1998 * tree view (used in updating the adjustments below) might change.
2000 pspp_sheet_view_size_allocate_columns (widget, &width_changed);
2002 gtk_adjustment_set_page_size (tree_view->priv->hadjustment, allocation->width);
2003 gtk_adjustment_set_page_increment (tree_view->priv->hadjustment, allocation->width * 0.9);
2004 gtk_adjustment_set_step_increment (tree_view->priv->hadjustment, allocation->width * 0.1);
2005 gtk_adjustment_set_lower (tree_view->priv->hadjustment, 0);
2006 gtk_adjustment_set_upper (tree_view->priv->hadjustment, MAX (gtk_adjustment_get_page_size (tree_view->priv->hadjustment), tree_view->priv->width));
2008 if (gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL)
2010 if (allocation->width < tree_view->priv->width)
2012 if (tree_view->priv->init_hadjust_value)
2014 gtk_adjustment_set_value (tree_view->priv->hadjustment, MAX (tree_view->priv->width - allocation->width, 0));
2015 tree_view->priv->init_hadjust_value = FALSE;
2017 else if (allocation->width != old_allocation.width)
2019 gtk_adjustment_set_value (tree_view->priv->hadjustment, CLAMP (gtk_adjustment_get_value (tree_view->priv->hadjustment) - allocation->width + old_allocation.width, 0, tree_view->priv->width - allocation->width));
2022 gtk_adjustment_set_value (tree_view->priv->hadjustment, CLAMP (tree_view->priv->width - (tree_view->priv->prev_width - gtk_adjustment_get_value (tree_view->priv->hadjustment)), 0, tree_view->priv->width - allocation->width));
2026 gtk_adjustment_set_value (tree_view->priv->hadjustment, 0);
2027 tree_view->priv->init_hadjust_value = TRUE;
2031 if (gtk_adjustment_get_value (tree_view->priv->hadjustment) + allocation->width > tree_view->priv->width)
2032 gtk_adjustment_set_value (tree_view->priv->hadjustment, MAX (tree_view->priv->width - allocation->width, 0));
2034 gtk_adjustment_changed (tree_view->priv->hadjustment);
2036 gtk_adjustment_set_page_size (tree_view->priv->vadjustment, allocation->height - TREE_VIEW_HEADER_HEIGHT (tree_view));
2037 gtk_adjustment_set_step_increment (tree_view->priv->vadjustment, gtk_adjustment_get_page_size (tree_view->priv->vadjustment) * 0.1);
2038 gtk_adjustment_set_page_increment (tree_view->priv->vadjustment, gtk_adjustment_get_page_size (tree_view->priv->vadjustment) * 0.9);
2039 gtk_adjustment_set_lower (tree_view->priv->vadjustment, 0);
2040 gtk_adjustment_set_upper (tree_view->priv->vadjustment, MAX (gtk_adjustment_get_page_size (tree_view->priv->vadjustment), tree_view->priv->height));
2042 gtk_adjustment_changed (tree_view->priv->vadjustment);
2044 /* now the adjustments and window sizes are in sync, we can sync toprow/dy again */
2045 if (tree_view->priv->height <= gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
2046 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment), 0);
2047 else if (gtk_adjustment_get_value (tree_view->priv->vadjustment) + gtk_adjustment_get_page_size (tree_view->priv->vadjustment) > tree_view->priv->height)
2048 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment),
2049 tree_view->priv->height - gtk_adjustment_get_page_size (tree_view->priv->vadjustment));
2050 else if (gtk_tree_row_reference_valid (tree_view->priv->top_row))
2051 pspp_sheet_view_top_row_to_dy (tree_view);
2053 pspp_sheet_view_dy_to_top_row (tree_view);
2055 if (gtk_widget_get_realized (widget))
2057 gdk_window_move_resize (gtk_widget_get_window (widget),
2058 allocation->x, allocation->y,
2059 allocation->width, allocation->height);
2060 gdk_window_move_resize (tree_view->priv->header_window,
2061 - (gint) gtk_adjustment_get_value (tree_view->priv->hadjustment),
2063 MAX (tree_view->priv->width, allocation->width),
2064 tree_view->priv->header_height);
2065 gdk_window_move_resize (tree_view->priv->bin_window,
2066 - (gint) gtk_adjustment_get_value (tree_view->priv->hadjustment),
2067 TREE_VIEW_HEADER_HEIGHT (tree_view),
2068 MAX (tree_view->priv->width, allocation->width),
2069 allocation->height - TREE_VIEW_HEADER_HEIGHT (tree_view));
2072 if (tree_view->priv->row_count == 0)
2073 invalidate_empty_focus (tree_view);
2075 if (gtk_widget_get_realized (widget))
2077 gboolean has_expand_column = FALSE;
2078 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
2080 if (pspp_sheet_view_column_get_expand (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)))
2082 has_expand_column = TRUE;
2087 /* This little hack only works if we have an LTR locale, and no column has the */
2090 if (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_LTR &&
2091 ! has_expand_column)
2092 invalidate_last_column (tree_view);
2094 gtk_widget_queue_draw (widget);
2099 /* Grabs the focus and unsets the PSPP_SHEET_VIEW_DRAW_KEYFOCUS flag */
2101 grab_focus_and_unset_draw_keyfocus (PsppSheetView *tree_view)
2103 GtkWidget *widget = GTK_WIDGET (tree_view);
2105 if (gtk_widget_get_can_focus (widget) && !gtk_widget_has_focus (widget))
2106 gtk_widget_grab_focus (widget);
2107 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
2111 pspp_sheet_view_node_is_selected (PsppSheetView *tree_view,
2114 return node >= 0 && range_tower_contains (tree_view->priv->selected, node);
2118 pspp_sheet_view_node_select (PsppSheetView *tree_view,
2121 range_tower_set1 (tree_view->priv->selected, node, 1);
2125 pspp_sheet_view_node_unselect (PsppSheetView *tree_view,
2128 range_tower_set0 (tree_view->priv->selected, node, 1);
2132 pspp_sheet_view_node_next (PsppSheetView *tree_view,
2135 return node + 1 < tree_view->priv->row_count ? node + 1 : -1;
2139 pspp_sheet_view_node_prev (PsppSheetView *tree_view,
2142 return node > 0 ? node - 1 : -1;
2146 all_columns_selected (PsppSheetView *tree_view)
2150 for (list = tree_view->priv->columns; list; list = list->next)
2152 PsppSheetViewColumn *column = list->data;
2153 if (column->selectable && !column->selected)
2161 pspp_sheet_view_row_head_clicked (PsppSheetView *tree_view,
2163 PsppSheetViewColumn *column,
2164 GdkEventButton *event)
2166 PsppSheetSelection *selection;
2167 PsppSheetSelectionMode mode;
2169 gboolean update_anchor;
2173 g_return_val_if_fail (tree_view != NULL, FALSE);
2174 g_return_val_if_fail (column != NULL, FALSE);
2176 selection = tree_view->priv->selection;
2177 mode = pspp_sheet_selection_get_mode (selection);
2178 if (mode != PSPP_SHEET_SELECTION_RECTANGLE)
2181 if (!column->row_head)
2186 modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
2187 if (event->type != GDK_BUTTON_PRESS
2188 || (modifiers != GDK_CONTROL_MASK && modifiers != GDK_SHIFT_MASK))
2194 path = gtk_tree_path_new_from_indices (node, -1);
2197 pspp_sheet_selection_unselect_all (selection);
2198 pspp_sheet_selection_select_path (selection, path);
2199 pspp_sheet_selection_select_all_columns (selection);
2200 update_anchor = TRUE;
2203 else if (event->type == GDK_BUTTON_PRESS && event->button == 3)
2205 if (pspp_sheet_selection_count_selected_rows (selection) <= 1
2206 || !all_columns_selected (tree_view))
2208 pspp_sheet_selection_unselect_all (selection);
2209 pspp_sheet_selection_select_path (selection, path);
2210 pspp_sheet_selection_select_all_columns (selection);
2211 update_anchor = TRUE;
2215 update_anchor = handled = FALSE;
2217 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
2218 && modifiers == GDK_CONTROL_MASK)
2220 if (!all_columns_selected (tree_view))
2222 pspp_sheet_selection_unselect_all (selection);
2223 pspp_sheet_selection_select_all_columns (selection);
2226 if (pspp_sheet_selection_path_is_selected (selection, path))
2227 pspp_sheet_selection_unselect_path (selection, path);
2229 pspp_sheet_selection_select_path (selection, path);
2230 update_anchor = TRUE;
2233 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
2234 && modifiers == GDK_SHIFT_MASK)
2236 GtkTreeRowReference *anchor = tree_view->priv->anchor;
2237 GtkTreePath *anchor_path;
2239 if (all_columns_selected (tree_view)
2240 && gtk_tree_row_reference_valid (anchor))
2242 update_anchor = FALSE;
2243 anchor_path = gtk_tree_row_reference_get_path (anchor);
2247 update_anchor = TRUE;
2248 anchor_path = gtk_tree_path_copy (path);
2251 pspp_sheet_selection_unselect_all (selection);
2252 pspp_sheet_selection_select_range (selection, anchor_path, path);
2253 pspp_sheet_selection_select_all_columns (selection);
2255 gtk_tree_path_free (anchor_path);
2260 update_anchor = handled = FALSE;
2264 if (tree_view->priv->anchor)
2265 gtk_tree_row_reference_free (tree_view->priv->anchor);
2266 tree_view->priv->anchor =
2267 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
2268 tree_view->priv->model,
2272 gtk_tree_path_free (path);
2277 find_click (PsppSheetView *tree_view,
2280 PsppSheetViewColumn **column,
2281 GdkRectangle *background_area,
2282 GdkRectangle *cell_area)
2289 /* find the node that was clicked */
2290 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, y);
2293 y_offset = -pspp_sheet_view_find_offset (tree_view, new_y, node);
2298 background_area->y = y_offset + y;
2299 background_area->height = ROW_HEIGHT (tree_view);
2300 background_area->x = 0;
2302 /* Let the column have a chance at selecting it. */
2303 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
2304 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
2305 list; list = (rtl ? list->prev : list->next))
2307 PsppSheetViewColumn *candidate = list->data;
2309 if (!candidate->visible)
2312 background_area->width = candidate->width;
2313 if ((background_area->x > x) ||
2314 (background_area->x + background_area->width <= x))
2316 background_area->x += background_area->width;
2320 /* we found the focus column */
2322 pspp_sheet_view_adjust_cell_area (tree_view, candidate, background_area,
2324 *column = candidate;
2332 pspp_sheet_view_button_press (GtkWidget *widget,
2333 GdkEventButton *event)
2335 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2337 PsppSheetViewColumn *column = NULL;
2339 GdkRectangle background_area;
2340 GdkRectangle cell_area;
2343 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
2344 pspp_sheet_view_stop_editing (tree_view, FALSE);
2347 /* Because grab_focus can cause reentrancy, we delay grab_focus until after
2348 * we're done handling the button press.
2351 if (event->window == tree_view->priv->bin_window)
2356 gint pre_val, aft_val;
2357 PsppSheetViewColumn *column = NULL;
2358 GtkCellRenderer *focus_cell = NULL;
2359 gboolean row_double_click = FALSE;
2362 if (tree_view->priv->row_count == 0)
2364 grab_focus_and_unset_draw_keyfocus (tree_view);
2368 if (!find_click (tree_view, event->x, event->y, &node, &column,
2369 &background_area, &cell_area))
2371 grab_focus_and_unset_draw_keyfocus (tree_view);
2375 tree_view->priv->focus_column = column;
2377 if (pspp_sheet_view_row_head_clicked (tree_view, node, column, event))
2381 pre_val = gtk_adjustment_get_value (tree_view->priv->vadjustment);
2383 path = _pspp_sheet_view_find_path (tree_view, node);
2385 /* we only handle selection modifications on the first button press
2387 if (event->type == GDK_BUTTON_PRESS)
2389 PsppSheetSelectionMode mode = 0;
2391 if ((event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
2392 mode |= PSPP_SHEET_SELECT_MODE_TOGGLE;
2393 if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
2394 mode |= PSPP_SHEET_SELECT_MODE_EXTEND;
2396 focus_cell = _pspp_sheet_view_column_get_cell_at_pos (column, event->x - background_area.x);
2398 pspp_sheet_view_column_focus_cell (column, focus_cell);
2400 if (event->state & GDK_CONTROL_MASK)
2402 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE, mode);
2403 pspp_sheet_view_real_toggle_cursor_row (tree_view);
2405 else if (event->state & GDK_SHIFT_MASK)
2407 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, mode);
2408 pspp_sheet_view_real_select_cursor_row (tree_view, FALSE, mode);
2412 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, 0);
2415 if (tree_view->priv->anchor_column == NULL ||
2416 !(event->state & GDK_SHIFT_MASK))
2417 tree_view->priv->anchor_column = column;
2418 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
2419 pspp_sheet_selection_select_column_range (tree_view->priv->selection,
2420 tree_view->priv->anchor_column,
2424 /* the treeview may have been scrolled because of _set_cursor,
2428 aft_val = gtk_adjustment_get_value (tree_view->priv->vadjustment);
2429 dval = pre_val - aft_val;
2431 cell_area.y += dval;
2432 background_area.y += dval;
2434 /* Save press to possibly begin a drag
2436 if (!tree_view->priv->in_grab &&
2437 tree_view->priv->pressed_button < 0)
2439 tree_view->priv->pressed_button = event->button;
2440 tree_view->priv->press_start_x = event->x;
2441 tree_view->priv->press_start_y = event->y;
2442 tree_view->priv->press_start_node = node;
2444 if (tree_view->priv->rubber_banding_enable
2445 && (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
2446 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE))
2448 tree_view->priv->press_start_y += tree_view->priv->dy;
2449 tree_view->priv->rubber_band_x = event->x;
2450 tree_view->priv->rubber_band_y = event->y + tree_view->priv->dy;
2451 tree_view->priv->rubber_band_status = RUBBER_BAND_MAYBE_START;
2453 if ((event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
2454 tree_view->priv->rubber_band_ctrl = TRUE;
2455 if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
2456 tree_view->priv->rubber_band_shift = TRUE;
2461 /* Test if a double click happened on the same row. */
2462 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
2464 int double_click_time, double_click_distance;
2466 g_object_get (gtk_settings_get_for_screen (
2467 gtk_widget_get_screen (widget)),
2468 "gtk-double-click-time", &double_click_time,
2469 "gtk-double-click-distance", &double_click_distance,
2472 /* Same conditions as _gdk_event_button_generate */
2473 if (tree_view->priv->last_button_x != -1 &&
2474 (event->time < tree_view->priv->last_button_time + double_click_time) &&
2475 (ABS (event->x - tree_view->priv->last_button_x) <= double_click_distance) &&
2476 (ABS (event->y - tree_view->priv->last_button_y) <= double_click_distance))
2478 /* We do no longer compare paths of this row and the
2479 * row clicked previously. We use the double click
2480 * distance to decide whether this is a valid click,
2481 * allowing the mouse to slightly move over another row.
2483 row_double_click = TRUE;
2485 tree_view->priv->last_button_time = 0;
2486 tree_view->priv->last_button_x = -1;
2487 tree_view->priv->last_button_y = -1;
2491 tree_view->priv->last_button_time = event->time;
2492 tree_view->priv->last_button_x = event->x;
2493 tree_view->priv->last_button_y = event->y;
2497 if (row_double_click)
2499 gtk_grab_remove (widget);
2500 pspp_sheet_view_row_activated (tree_view, path, column);
2502 if (tree_view->priv->pressed_button == event->button)
2503 tree_view->priv->pressed_button = -1;
2506 gtk_tree_path_free (path);
2508 /* If we activated the row through a double click we don't want to grab
2509 * focus back, as moving focus to another widget is pretty common.
2511 if (!row_double_click)
2512 grab_focus_and_unset_draw_keyfocus (tree_view);
2517 /* We didn't click in the window. Let's check to see if we clicked on a column resize window.
2519 for (i = 0, list = tree_view->priv->columns; list; list = list->next, i++)
2521 column = list->data;
2522 if (event->window == column->window &&
2523 column->resizable &&
2528 if (gdk_pointer_grab (column->window, FALSE,
2529 GDK_POINTER_MOTION_HINT_MASK |
2530 GDK_BUTTON1_MOTION_MASK |
2531 GDK_BUTTON_RELEASE_MASK,
2532 NULL, NULL, event->time))
2535 gtk_grab_add (widget);
2536 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE);
2537 column->resized_width = column->width;
2539 /* block attached dnd signal handler */
2540 drag_data = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
2542 g_signal_handlers_block_matched (widget,
2543 G_SIGNAL_MATCH_DATA,
2547 tree_view->priv->drag_pos = i;
2548 tree_view->priv->x_drag = column->allocation.x + (rtl ? 0 : column->allocation.width);
2550 if (!gtk_widget_has_focus (widget))
2551 gtk_widget_grab_focus (widget);
2559 /* GtkWidget::button_release_event helper */
2561 pspp_sheet_view_button_release_drag_column (GtkWidget *widget,
2562 GdkEventButton *event)
2564 PsppSheetView *tree_view;
2568 tree_view = PSPP_SHEET_VIEW (widget);
2570 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
2571 gdk_display_pointer_ungrab (gtk_widget_get_display (widget), GDK_CURRENT_TIME);
2572 gdk_display_keyboard_ungrab (gtk_widget_get_display (widget), GDK_CURRENT_TIME);
2574 /* Move the button back */
2575 g_return_val_if_fail (tree_view->priv->drag_column->button, FALSE);
2577 g_object_ref (tree_view->priv->drag_column->button);
2578 gtk_container_remove (GTK_CONTAINER (tree_view), tree_view->priv->drag_column->button);
2579 gtk_widget_set_parent_window (tree_view->priv->drag_column->button, tree_view->priv->header_window);
2580 gtk_widget_set_parent (tree_view->priv->drag_column->button, GTK_WIDGET (tree_view));
2581 g_object_unref (tree_view->priv->drag_column->button);
2582 gtk_widget_queue_resize (widget);
2583 if (tree_view->priv->drag_column->resizable)
2585 gdk_window_raise (tree_view->priv->drag_column->window);
2586 gdk_window_show (tree_view->priv->drag_column->window);
2589 gdk_window_hide (tree_view->priv->drag_column->window);
2591 gtk_widget_grab_focus (tree_view->priv->drag_column->button);
2595 if (tree_view->priv->cur_reorder &&
2596 tree_view->priv->cur_reorder->right_column != tree_view->priv->drag_column)
2597 pspp_sheet_view_move_column_after (tree_view, tree_view->priv->drag_column,
2598 tree_view->priv->cur_reorder->right_column);
2602 if (tree_view->priv->cur_reorder &&
2603 tree_view->priv->cur_reorder->left_column != tree_view->priv->drag_column)
2604 pspp_sheet_view_move_column_after (tree_view, tree_view->priv->drag_column,
2605 tree_view->priv->cur_reorder->left_column);
2607 tree_view->priv->drag_column = NULL;
2608 gdk_window_hide (tree_view->priv->drag_window);
2610 for (l = tree_view->priv->column_drag_info; l != NULL; l = l->next)
2611 g_slice_free (PsppSheetViewColumnReorder, l->data);
2612 g_list_free (tree_view->priv->column_drag_info);
2613 tree_view->priv->column_drag_info = NULL;
2614 tree_view->priv->cur_reorder = NULL;
2616 if (tree_view->priv->drag_highlight_window)
2617 gdk_window_hide (tree_view->priv->drag_highlight_window);
2619 /* Reset our flags */
2620 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_UNSET;
2621 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG);
2626 /* GtkWidget::button_release_event helper */
2628 pspp_sheet_view_button_release_column_resize (GtkWidget *widget,
2629 GdkEventButton *event)
2631 PsppSheetView *tree_view;
2634 tree_view = PSPP_SHEET_VIEW (widget);
2636 tree_view->priv->drag_pos = -1;
2638 /* unblock attached dnd signal handler */
2639 drag_data = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
2641 g_signal_handlers_unblock_matched (widget,
2642 G_SIGNAL_MATCH_DATA,
2646 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE);
2647 gtk_grab_remove (widget);
2648 gdk_display_pointer_ungrab (gdk_window_get_display (event->window),
2654 pspp_sheet_view_button_release_edit (PsppSheetView *tree_view,
2655 GdkEventButton *event)
2657 GtkCellEditable *cell_editable;
2662 PsppSheetViewColumn *column;
2663 GdkRectangle background_area;
2664 GdkRectangle cell_area;
2670 if (event->window != tree_view->priv->bin_window)
2673 /* Ignore a released button, if that button wasn't depressed */
2674 if (tree_view->priv->pressed_button != event->button)
2677 if (!find_click (tree_view, event->x, event->y, &node, &column, &background_area,
2681 /* decide if we edit */
2682 path = _pspp_sheet_view_find_path (tree_view, node);
2683 modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
2684 if (event->button != 1 || modifiers)
2687 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
2688 pspp_sheet_view_column_cell_set_cell_data (column,
2689 tree_view->priv->model,
2692 if (!pspp_sheet_view_column_get_quick_edit (column)
2693 && _pspp_sheet_view_column_has_editable_cell (column))
2696 flags = 0; /* FIXME: get the right flags */
2697 path_string = gtk_tree_path_to_string (path);
2699 if (!_pspp_sheet_view_column_cell_event (column,
2707 if (cell_editable == NULL)
2710 pspp_sheet_view_real_set_cursor (tree_view, path,
2711 TRUE, TRUE, 0); /* XXX mode? */
2712 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
2715 _pspp_sheet_view_column_get_neighbor_sizes (
2716 column, _pspp_sheet_view_column_get_edited_cell (column), &left, &right);
2719 area.width -= right + left;
2721 pspp_sheet_view_real_start_editing (tree_view,
2728 g_free (path_string);
2729 gtk_tree_path_free (path);
2734 pspp_sheet_view_button_release (GtkWidget *widget,
2735 GdkEventButton *event)
2737 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2739 pspp_sheet_view_stop_editing (tree_view, FALSE);
2740 if (tree_view->priv->rubber_band_status != RUBBER_BAND_ACTIVE
2741 && pspp_sheet_view_button_release_edit (tree_view, event))
2743 if (tree_view->priv->pressed_button == event->button)
2744 tree_view->priv->pressed_button = -1;
2746 tree_view->priv->rubber_band_status = RUBBER_BAND_OFF;
2750 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
2751 return pspp_sheet_view_button_release_drag_column (widget, event);
2753 if (tree_view->priv->rubber_band_status)
2754 pspp_sheet_view_stop_rubber_band (tree_view);
2756 if (tree_view->priv->pressed_button == event->button)
2757 tree_view->priv->pressed_button = -1;
2759 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
2760 return pspp_sheet_view_button_release_column_resize (widget, event);
2766 pspp_sheet_view_grab_broken (GtkWidget *widget,
2767 GdkEventGrabBroken *event)
2769 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2771 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
2772 pspp_sheet_view_button_release_drag_column (widget, (GdkEventButton *)event);
2774 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
2775 pspp_sheet_view_button_release_column_resize (widget, (GdkEventButton *)event);
2780 /* GtkWidget::motion_event function set.
2784 do_prelight (PsppSheetView *tree_view,
2786 /* these are in bin_window coords */
2790 int prev_node = tree_view->priv->prelight_node;
2792 if (prev_node != node)
2794 tree_view->priv->prelight_node = node;
2797 _pspp_sheet_view_queue_draw_node (tree_view, prev_node, NULL);
2800 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
2806 prelight_or_select (PsppSheetView *tree_view,
2808 /* these are in bin_window coords */
2812 PsppSheetSelectionMode mode = pspp_sheet_selection_get_mode (tree_view->priv->selection);
2814 if (tree_view->priv->hover_selection &&
2815 (mode == PSPP_SHEET_SELECTION_SINGLE || mode == PSPP_SHEET_SELECTION_BROWSE) &&
2816 !(tree_view->priv->edited_column &&
2817 tree_view->priv->edited_column->editable_widget))
2821 if (!pspp_sheet_view_node_is_selected (tree_view, node))
2825 path = _pspp_sheet_view_find_path (tree_view, node);
2826 pspp_sheet_selection_select_path (tree_view->priv->selection, path);
2827 if (pspp_sheet_view_node_is_selected (tree_view, node))
2829 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
2830 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, FALSE, 0); /* XXX mode? */
2832 gtk_tree_path_free (path);
2836 else if (mode == PSPP_SHEET_SELECTION_SINGLE)
2837 pspp_sheet_selection_unselect_all (tree_view->priv->selection);
2840 do_prelight (tree_view, node, x, y);
2844 ensure_unprelighted (PsppSheetView *tree_view)
2846 do_prelight (tree_view,
2848 -1000, -1000); /* coords not possibly over an arrow */
2850 g_assert (tree_view->priv->prelight_node < 0);
2854 update_prelight (PsppSheetView *tree_view,
2861 if (tree_view->priv->row_count == 0)
2866 ensure_unprelighted (tree_view);
2870 new_y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, y);
2874 pspp_sheet_view_find_offset (tree_view, new_y, &node);
2877 prelight_or_select (tree_view, node, x, y);
2883 /* Our motion arrow is either a box (in the case of the original spot)
2884 * or an arrow. It is expander_size wide.
2907 pspp_sheet_view_motion_draw_column_motion_arrow (PsppSheetView *tree_view)
2910 PsppSheetViewColumnReorder *reorder = tree_view->priv->cur_reorder;
2911 GtkWidget *widget = GTK_WIDGET (tree_view);
2912 GdkBitmap *mask = NULL;
2917 gint arrow_type = DRAG_COLUMN_WINDOW_STATE_UNSET;
2918 GdkWindowAttr attributes;
2919 guint attributes_mask;
2922 reorder->left_column == tree_view->priv->drag_column ||
2923 reorder->right_column == tree_view->priv->drag_column)
2924 arrow_type = DRAG_COLUMN_WINDOW_STATE_ORIGINAL;
2925 else if (reorder->left_column || reorder->right_column)
2927 GdkRectangle visible_rect;
2928 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
2929 if (reorder->left_column)
2930 x = reorder->left_column->allocation.x + reorder->left_column->allocation.width;
2932 x = reorder->right_column->allocation.x;
2934 if (x < visible_rect.x)
2935 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT;
2936 else if (x > visible_rect.x + visible_rect.width)
2937 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT;
2939 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW;
2942 /* We want to draw the rectangle over the initial location. */
2943 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ORIGINAL)
2948 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ORIGINAL)
2950 if (tree_view->priv->drag_highlight_window)
2952 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
2954 gdk_window_destroy (tree_view->priv->drag_highlight_window);
2957 attributes.window_type = GDK_WINDOW_CHILD;
2958 attributes.wclass = GDK_INPUT_OUTPUT;
2959 attributes.x = tree_view->priv->drag_column_x;
2961 width = attributes.width = tree_view->priv->drag_column->allocation.width;
2962 height = attributes.height = tree_view->priv->drag_column->allocation.height;
2963 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
2964 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
2965 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
2966 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2967 tree_view->priv->drag_highlight_window = gdk_window_new (tree_view->priv->header_window, &attributes, attributes_mask);
2968 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
2970 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
2971 gc = gdk_gc_new (mask);
2973 gdk_gc_set_foreground (gc, &col);
2974 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
2976 gdk_gc_set_foreground(gc, &col);
2977 gdk_draw_rectangle (mask, gc, TRUE, 2, 2, width - 4, height - 4);
2978 g_object_unref (gc);
2980 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
2982 if (mask) g_object_unref (mask);
2983 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_ORIGINAL;
2986 else if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW)
2992 width = tree_view->priv->expander_size;
2994 /* Get x, y, width, height of arrow */
2995 gdk_window_get_origin (tree_view->priv->header_window, &x, &y);
2996 if (reorder->left_column)
2998 x += reorder->left_column->allocation.x + reorder->left_column->allocation.width - width/2;
2999 height = reorder->left_column->allocation.height;
3003 x += reorder->right_column->allocation.x - width/2;
3004 height = reorder->right_column->allocation.height;
3006 y -= tree_view->priv->expander_size/2; /* The arrow takes up only half the space */
3007 height += tree_view->priv->expander_size;
3009 /* Create the new window */
3010 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW)
3012 if (tree_view->priv->drag_highlight_window)
3014 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
3016 gdk_window_destroy (tree_view->priv->drag_highlight_window);
3019 attributes.window_type = GDK_WINDOW_TEMP;
3020 attributes.wclass = GDK_INPUT_OUTPUT;
3021 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
3022 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
3023 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
3024 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
3027 attributes.width = width;
3028 attributes.height = height;
3029 tree_view->priv->drag_highlight_window = gdk_window_new (gtk_widget_get_root_window (widget),
3030 &attributes, attributes_mask);
3031 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
3033 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
3034 gc = gdk_gc_new (mask);
3036 gdk_gc_set_foreground (gc, &col);
3037 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
3039 /* Draw the 2 arrows as per above */
3041 gdk_gc_set_foreground (gc, &col);
3042 for (i = 0; i < width; i ++)
3044 if (i == (width/2 - 1))
3046 gdk_draw_line (mask, gc, i, j, i, height - j);
3047 if (i < (width/2 - 1))
3052 g_object_unref (gc);
3053 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
3055 if (mask) g_object_unref (mask);
3058 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_ARROW;
3059 gdk_window_move (tree_view->priv->drag_highlight_window, x, y);
3061 else if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT ||
3062 arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3068 width = tree_view->priv->expander_size;
3070 /* Get x, y, width, height of arrow */
3071 width = width/2; /* remember, the arrow only takes half the available width */
3072 gdk_window_get_origin (gtk_widget_get_window (widget), &x, &y);
3073 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3074 x += widget->allocation.width - width;
3076 if (reorder->left_column)
3077 height = reorder->left_column->allocation.height;
3079 height = reorder->right_column->allocation.height;
3081 y -= tree_view->priv->expander_size;
3082 height += 2*tree_view->priv->expander_size;
3084 /* Create the new window */
3085 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT &&
3086 tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3088 if (tree_view->priv->drag_highlight_window)
3090 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
3092 gdk_window_destroy (tree_view->priv->drag_highlight_window);
3095 attributes.window_type = GDK_WINDOW_TEMP;
3096 attributes.wclass = GDK_INPUT_OUTPUT;
3097 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
3098 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
3099 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
3100 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
3103 attributes.width = width;
3104 attributes.height = height;
3105 tree_view->priv->drag_highlight_window = gdk_window_new (NULL, &attributes, attributes_mask);
3106 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
3108 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
3109 gc = gdk_gc_new (mask);
3111 gdk_gc_set_foreground (gc, &col);
3112 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
3114 /* Draw the 2 arrows as per above */
3116 gdk_gc_set_foreground (gc, &col);
3117 j = tree_view->priv->expander_size;
3118 for (i = 0; i < width; i ++)
3121 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT)
3125 gdk_draw_line (mask, gc, k, j, k, height - j);
3126 gdk_draw_line (mask, gc, k, 0, k, tree_view->priv->expander_size - j);
3127 gdk_draw_line (mask, gc, k, height, k, height - tree_view->priv->expander_size + j);
3130 g_object_unref (gc);
3131 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
3133 if (mask) g_object_unref (mask);
3136 tree_view->priv->drag_column_window_state = arrow_type;
3137 gdk_window_move (tree_view->priv->drag_highlight_window, x, y);
3141 g_warning (G_STRLOC"Invalid PsppSheetViewColumnReorder struct");
3142 gdk_window_hide (tree_view->priv->drag_highlight_window);
3146 gdk_window_show (tree_view->priv->drag_highlight_window);
3147 gdk_window_raise (tree_view->priv->drag_highlight_window);
3152 pspp_sheet_view_motion_resize_column (GtkWidget *widget,
3153 GdkEventMotion *event)
3157 PsppSheetViewColumn *column;
3158 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
3160 column = pspp_sheet_view_get_column (tree_view, tree_view->priv->drag_pos);
3162 if (event->is_hint || event->window != gtk_widget_get_window (widget))
3163 gtk_widget_get_pointer (widget, &x, NULL);
3167 if (tree_view->priv->hadjustment)
3168 x += gtk_adjustment_get_value (tree_view->priv->hadjustment);
3170 new_width = pspp_sheet_view_new_column_width (tree_view,
3171 tree_view->priv->drag_pos, &x);
3172 if (x != tree_view->priv->x_drag &&
3173 (new_width != column->fixed_width))
3175 column->use_resized_width = TRUE;
3176 column->resized_width = new_width;
3179 column->resized_width -= tree_view->priv->last_extra_space_per_column;
3181 gtk_widget_queue_resize (widget);
3189 pspp_sheet_view_update_current_reorder (PsppSheetView *tree_view)
3191 PsppSheetViewColumnReorder *reorder = NULL;
3195 gdk_window_get_pointer (tree_view->priv->header_window, &mouse_x, NULL, NULL);
3196 for (list = tree_view->priv->column_drag_info; list; list = list->next)
3198 reorder = (PsppSheetViewColumnReorder *) list->data;
3199 if (mouse_x >= reorder->left_align && mouse_x < reorder->right_align)
3204 /* if (reorder && reorder == tree_view->priv->cur_reorder)
3207 tree_view->priv->cur_reorder = reorder;
3208 pspp_sheet_view_motion_draw_column_motion_arrow (tree_view);
3212 pspp_sheet_view_vertical_autoscroll (PsppSheetView *tree_view)
3214 GdkRectangle visible_rect;
3219 gdk_window_get_pointer (tree_view->priv->bin_window, NULL, &y, NULL);
3220 y += tree_view->priv->dy;
3222 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
3224 /* see if we are near the edge. */
3225 offset = y - (visible_rect.y + 2 * SCROLL_EDGE_SIZE);
3228 offset = y - (visible_rect.y + visible_rect.height - 2 * SCROLL_EDGE_SIZE);
3233 value = CLAMP (gtk_adjustment_get_value (tree_view->priv->vadjustment) + offset, 0.0,
3234 gtk_adjustment_get_upper (tree_view->priv->vadjustment) - gtk_adjustment_get_page_size (tree_view->priv->vadjustment));
3235 gtk_adjustment_set_value (tree_view->priv->vadjustment, value);
3239 pspp_sheet_view_horizontal_autoscroll (PsppSheetView *tree_view)
3241 GdkRectangle visible_rect;
3246 gdk_window_get_pointer (tree_view->priv->bin_window, &x, NULL, NULL);
3248 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
3250 /* See if we are near the edge. */
3251 offset = x - (visible_rect.x + SCROLL_EDGE_SIZE);
3254 offset = x - (visible_rect.x + visible_rect.width - SCROLL_EDGE_SIZE);
3260 value = CLAMP (gtk_adjustment_get_value (tree_view->priv->hadjustment) + offset,
3261 0.0, gtk_adjustment_get_upper (tree_view->priv->hadjustment) - gtk_adjustment_get_page_size (tree_view->priv->hadjustment));
3262 gtk_adjustment_set_value (tree_view->priv->hadjustment, value);
3269 pspp_sheet_view_motion_drag_column (GtkWidget *widget,
3270 GdkEventMotion *event)
3272 PsppSheetView *tree_view = (PsppSheetView *) widget;
3273 PsppSheetViewColumn *column = tree_view->priv->drag_column;
3275 GtkAllocation allocation;
3278 if ((column == NULL) ||
3279 (event->window != tree_view->priv->drag_window))
3282 /* Handle moving the header */
3283 gdk_window_get_position (tree_view->priv->drag_window, &x, &y);
3284 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
3285 x = CLAMP (x + (gint)event->x - column->drag_x, 0,
3286 MAX (tree_view->priv->width, allocation.width) - column->allocation.width);
3287 gdk_window_move (tree_view->priv->drag_window, x, y);
3289 /* autoscroll, if needed */
3290 pspp_sheet_view_horizontal_autoscroll (tree_view);
3291 /* Update the current reorder position and arrow; */
3292 pspp_sheet_view_update_current_reorder (tree_view);
3298 pspp_sheet_view_stop_rubber_band (PsppSheetView *tree_view)
3300 remove_scroll_timeout (tree_view);
3301 gtk_grab_remove (GTK_WIDGET (tree_view));
3303 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
3305 GtkTreePath *tmp_path;
3307 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
3309 /* The anchor path should be set to the start path */
3310 tmp_path = _pspp_sheet_view_find_path (tree_view,
3311 tree_view->priv->rubber_band_start_node);
3313 if (tree_view->priv->anchor)
3314 gtk_tree_row_reference_free (tree_view->priv->anchor);
3316 tree_view->priv->anchor =
3317 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
3318 tree_view->priv->model,
3321 gtk_tree_path_free (tmp_path);
3323 /* ... and the cursor to the end path */
3324 tmp_path = _pspp_sheet_view_find_path (tree_view,
3325 tree_view->priv->rubber_band_end_node);
3326 pspp_sheet_view_real_set_cursor (PSPP_SHEET_VIEW (tree_view), tmp_path, FALSE, FALSE, 0); /* XXX mode? */
3327 gtk_tree_path_free (tmp_path);
3329 _pspp_sheet_selection_emit_changed (tree_view->priv->selection);
3332 /* Clear status variables */
3333 tree_view->priv->rubber_band_status = RUBBER_BAND_OFF;
3334 tree_view->priv->rubber_band_shift = 0;
3335 tree_view->priv->rubber_band_ctrl = 0;
3337 tree_view->priv->rubber_band_start_node = -1;
3338 tree_view->priv->rubber_band_end_node = -1;
3342 pspp_sheet_view_update_rubber_band_selection_range (PsppSheetView *tree_view,
3346 gboolean skip_start,
3349 if (start_node == end_node)
3352 /* We skip the first node and jump inside the loop */
3358 /* Small optimization by assuming insensitive nodes are never
3363 if (tree_view->priv->rubber_band_shift)
3364 pspp_sheet_view_node_select (tree_view, start_node);
3365 else if (tree_view->priv->rubber_band_ctrl)
3367 /* Toggle the selection state */
3368 if (pspp_sheet_view_node_is_selected (tree_view, start_node))
3369 pspp_sheet_view_node_unselect (tree_view, start_node);
3371 pspp_sheet_view_node_select (tree_view, start_node);
3374 pspp_sheet_view_node_select (tree_view, start_node);
3378 /* Mirror the above */
3379 if (tree_view->priv->rubber_band_shift)
3380 pspp_sheet_view_node_unselect (tree_view, start_node);
3381 else if (tree_view->priv->rubber_band_ctrl)
3383 /* Toggle the selection state */
3384 if (pspp_sheet_view_node_is_selected (tree_view, start_node))
3385 pspp_sheet_view_node_unselect (tree_view, start_node);
3387 pspp_sheet_view_node_select (tree_view, start_node);
3390 pspp_sheet_view_node_unselect (tree_view, start_node);
3393 _pspp_sheet_view_queue_draw_node (tree_view, start_node, NULL);
3395 if (start_node == end_node)
3400 start_node = pspp_sheet_view_node_next (tree_view, start_node);
3403 /* Ran out of tree */
3406 if (skip_end && start_node == end_node)
3413 pspp_sheet_view_node_find_offset (PsppSheetView *tree_view,
3416 return node * tree_view->priv->fixed_height;
3420 pspp_sheet_view_find_offset (PsppSheetView *tree_view,
3424 int fixed_height = tree_view->priv->fixed_height;
3425 if (fixed_height <= 0
3427 || height >= tree_view->priv->row_count * fixed_height)
3434 *new_node = height / fixed_height;
3435 return height % fixed_height;
3440 pspp_sheet_view_update_rubber_band_selection (PsppSheetView *tree_view)
3445 pspp_sheet_view_find_offset (tree_view, MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y), &start_node);
3446 pspp_sheet_view_find_offset (tree_view, MAX (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y), &end_node);
3448 /* Handle the start area first */
3449 if (tree_view->priv->rubber_band_start_node < 0)
3451 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3458 else if (start_node < tree_view->priv->rubber_band_start_node)
3460 /* New node is above the old one; selection became bigger */
3461 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3463 tree_view->priv->rubber_band_start_node,
3468 else if (start_node > tree_view->priv->rubber_band_start_node)
3470 /* New node is below the old one; selection became smaller */
3471 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3472 tree_view->priv->rubber_band_start_node,
3479 tree_view->priv->rubber_band_start_node = start_node;
3481 /* Next, handle the end area */
3482 if (tree_view->priv->rubber_band_end_node < 0)
3484 /* In the event this happens, start_node was also -1; this case is
3488 else if (end_node < 0)
3490 /* Find the last node in the tree */
3491 pspp_sheet_view_find_offset (tree_view, tree_view->priv->height - 1,
3494 /* Selection reached end of the tree */
3495 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3496 tree_view->priv->rubber_band_end_node,
3502 else if (end_node > tree_view->priv->rubber_band_end_node)
3504 /* New node is below the old one; selection became bigger */
3505 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3506 tree_view->priv->rubber_band_end_node,
3512 else if (end_node < tree_view->priv->rubber_band_end_node)
3514 /* New node is above the old one; selection became smaller */
3515 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3517 tree_view->priv->rubber_band_end_node,
3523 tree_view->priv->rubber_band_end_node = end_node;
3526 #define GDK_RECTANGLE_PTR(X) ((GdkRectangle *)(X))
3529 pspp_sheet_view_update_rubber_band (PsppSheetView *tree_view)
3532 cairo_rectangle_int_t old_area;
3533 cairo_rectangle_int_t new_area;
3534 cairo_rectangle_int_t common;
3535 cairo_region_t *invalid_region;
3536 PsppSheetViewColumn *column;
3538 old_area.x = MIN (tree_view->priv->press_start_x, tree_view->priv->rubber_band_x);
3539 old_area.y = MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y) - tree_view->priv->dy;
3540 old_area.width = ABS (tree_view->priv->rubber_band_x - tree_view->priv->press_start_x) + 1;
3541 old_area.height = ABS (tree_view->priv->rubber_band_y - tree_view->priv->press_start_y) + 1;
3543 gdk_window_get_pointer (tree_view->priv->bin_window, &x, &y, NULL);
3546 y = MAX (y, 0) + tree_view->priv->dy;
3548 new_area.x = MIN (tree_view->priv->press_start_x, x);
3549 new_area.y = MIN (tree_view->priv->press_start_y, y) - tree_view->priv->dy;
3550 new_area.width = ABS (x - tree_view->priv->press_start_x) + 1;
3551 new_area.height = ABS (y - tree_view->priv->press_start_y) + 1;
3553 invalid_region = cairo_region_create_rectangle (&old_area);
3554 cairo_region_union_rectangle (invalid_region, &new_area);
3556 gdk_rectangle_intersect (GDK_RECTANGLE_PTR (&old_area),
3557 GDK_RECTANGLE_PTR (&new_area), GDK_RECTANGLE_PTR (&common));
3558 if (common.width > 2 && common.height > 2)
3560 cairo_region_t *common_region;
3562 /* make sure the border is invalidated */
3568 common_region = cairo_region_create_rectangle (&common);
3570 cairo_region_subtract (invalid_region, common_region);
3571 cairo_region_destroy (common_region);
3574 #if GTK_MAJOR_VERSION == 3
3575 gdk_window_invalidate_region (tree_view->priv->bin_window, invalid_region, TRUE);
3578 cairo_rectangle_int_t extents;
3580 cairo_region_get_extents (invalid_region, &extents);
3581 ereg = gdk_region_rectangle (GDK_RECTANGLE_PTR (&extents));
3582 gdk_window_invalidate_region (tree_view->priv->bin_window, ereg, TRUE);
3583 gdk_region_destroy (ereg);
3587 cairo_region_destroy (invalid_region);
3589 tree_view->priv->rubber_band_x = x;
3590 tree_view->priv->rubber_band_y = y;
3591 pspp_sheet_view_get_path_at_pos (tree_view, x, y, NULL, &column, NULL, NULL);
3593 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
3594 pspp_sheet_selection_select_column_range (tree_view->priv->selection,
3595 tree_view->priv->anchor_column,
3598 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
3600 pspp_sheet_view_update_rubber_band_selection (tree_view);
3605 pspp_sheet_view_paint_rubber_band (PsppSheetView *tree_view,
3610 GdkRectangle rubber_rect;
3614 rubber_rect.x = MIN (tree_view->priv->press_start_x, tree_view->priv->rubber_band_x);
3615 rubber_rect.y = MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y) - tree_view->priv->dy;
3616 rubber_rect.width = ABS (tree_view->priv->press_start_x - tree_view->priv->rubber_band_x) + 1;
3617 rubber_rect.height = ABS (tree_view->priv->press_start_y - tree_view->priv->rubber_band_y) + 1;
3619 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
3622 cr = gdk_cairo_create (tree_view->priv->bin_window);
3623 cairo_set_line_width (cr, 1.0);
3625 style = gtk_widget_get_style (GTK_WIDGET (tree_view));
3626 cairo_set_source_rgba (cr,
3627 style->fg[GTK_STATE_NORMAL].red / 65535.,
3628 style->fg[GTK_STATE_NORMAL].green / 65535.,
3629 style->fg[GTK_STATE_NORMAL].blue / 65535.,
3632 gdk_cairo_rectangle (cr, &rect);
3636 cairo_set_source_rgb (cr,
3637 style->fg[GTK_STATE_NORMAL].red / 65535.,
3638 style->fg[GTK_STATE_NORMAL].green / 65535.,
3639 style->fg[GTK_STATE_NORMAL].blue / 65535.);
3641 cairo_rectangle (cr,
3642 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
3643 rubber_rect.width - 1, rubber_rect.height - 1);
3652 pspp_sheet_view_motion_bin_window (GtkWidget *widget,
3653 GdkEventMotion *event)
3655 PsppSheetView *tree_view;
3659 tree_view = (PsppSheetView *) widget;
3661 if (tree_view->priv->row_count == 0)
3664 if (tree_view->priv->rubber_band_status == RUBBER_BAND_MAYBE_START)
3666 GdkRectangle background_area, cell_area;
3667 PsppSheetViewColumn *column;
3669 if (find_click (tree_view, event->x, event->y, &node, &column,
3670 &background_area, &cell_area)
3671 && tree_view->priv->focus_column == column
3672 && tree_view->priv->press_start_node == node)
3675 gtk_grab_add (GTK_WIDGET (tree_view));
3676 pspp_sheet_view_update_rubber_band (tree_view);
3678 tree_view->priv->rubber_band_status = RUBBER_BAND_ACTIVE;
3680 else if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
3682 pspp_sheet_view_update_rubber_band (tree_view);
3684 add_scroll_timeout (tree_view);
3687 /* only check for an initiated drag when a button is pressed */
3688 if (tree_view->priv->pressed_button >= 0
3689 && !tree_view->priv->rubber_band_status)
3690 pspp_sheet_view_maybe_begin_dragging_row (tree_view, event);
3692 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, event->y);
3696 pspp_sheet_view_find_offset (tree_view, new_y, &node);
3698 tree_view->priv->event_last_x = event->x;
3699 tree_view->priv->event_last_y = event->y;
3701 prelight_or_select (tree_view, node, event->x, event->y);
3707 pspp_sheet_view_motion (GtkWidget *widget,
3708 GdkEventMotion *event)
3710 PsppSheetView *tree_view;
3712 tree_view = (PsppSheetView *) widget;
3714 /* Resizing a column */
3715 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
3716 return pspp_sheet_view_motion_resize_column (widget, event);
3719 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
3720 return pspp_sheet_view_motion_drag_column (widget, event);
3722 /* Sanity check it */
3723 if (event->window == tree_view->priv->bin_window)
3724 return pspp_sheet_view_motion_bin_window (widget, event);
3729 /* Invalidate the focus rectangle near the edge of the bin_window; used when
3730 * the tree is empty.
3733 invalidate_empty_focus (PsppSheetView *tree_view)
3737 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
3742 area.width = gdk_window_get_width (tree_view->priv->bin_window);
3743 area.height = gdk_window_get_height (tree_view->priv->bin_window);
3744 gdk_window_invalidate_rect (tree_view->priv->bin_window, &area, FALSE);
3747 /* Draws a focus rectangle near the edge of the bin_window; used when the tree
3751 draw_empty_focus (PsppSheetView *tree_view)
3753 GtkWidget *widget = GTK_WIDGET (tree_view);
3755 cairo_t *cr = gdk_cairo_create (tree_view->priv->bin_window);
3757 if (!gtk_widget_has_focus (widget))
3760 w = gdk_window_get_width (tree_view->priv->bin_window);
3761 h = gdk_window_get_height (tree_view->priv->bin_window);
3767 gtk_paint_focus (gtk_widget_get_style (widget),
3769 gtk_widget_get_state (widget),
3777 pspp_sheet_view_draw_vertical_grid_lines (PsppSheetView *tree_view,
3779 gint n_visible_columns,
3783 GList *list = tree_view->priv->columns;
3787 if (tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
3788 && tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_BOTH)
3791 /* Only draw the lines for visible rows and columns */
3792 for (list = tree_view->priv->columns; list; list = list->next, i++)
3794 PsppSheetViewColumn *column = list->data;
3796 /* We don't want a line for the last column */
3797 if (i == n_visible_columns - 1)
3800 if (! column->visible)
3803 current_x += column->width;
3805 cairo_set_line_width (cr, 1.0);
3806 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
3807 cairo_move_to (cr, current_x - 0.5, min_y);
3808 cairo_line_to (cr, current_x - 0.5 , max_y - min_y);
3814 /* Warning: Very scary function.
3815 * Modify at your own risk
3817 * KEEP IN SYNC WITH pspp_sheet_view_create_row_drag_icon()!
3818 * FIXME: It's not...
3821 pspp_sheet_view_bin_expose (GtkWidget *widget,
3824 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
3829 int drag_highlight = -1;
3832 gint y_offset, cell_offset;
3834 GdkRectangle background_area;
3835 GdkRectangle cell_area;
3837 gint bin_window_width;
3838 gint bin_window_height;
3839 GtkTreePath *cursor_path;
3840 GtkTreePath *drag_dest_path;
3841 GList *first_column, *last_column;
3842 gint vertical_separator;
3843 gint horizontal_separator;
3844 gint focus_line_width;
3845 gboolean allow_rules;
3846 gboolean has_special_cell;
3848 gint n_visible_columns;
3849 gint grid_line_width;
3850 gboolean row_ending_details;
3851 gboolean draw_vgrid_lines, draw_hgrid_lines;
3854 cairo_t *bwcr = gdk_cairo_create (tree_view->priv->bin_window);
3856 GtkAllocation allocation;
3857 gtk_widget_get_allocation (widget, &allocation);
3861 Zarea.height = allocation.height;
3863 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
3865 gtk_widget_style_get (widget,
3866 "horizontal-separator", &horizontal_separator,
3867 "vertical-separator", &vertical_separator,
3868 "allow-rules", &allow_rules,
3869 "focus-line-width", &focus_line_width,
3870 "row-ending-details", &row_ending_details,
3873 if (tree_view->priv->row_count == 0)
3875 draw_empty_focus (tree_view);
3880 /* clip event->area to the visible area */
3881 if (Zarea.height < 0.5)
3885 validate_visible_area (tree_view);
3887 new_y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, Zarea.y);
3891 y_offset = -pspp_sheet_view_find_offset (tree_view, new_y, &node);
3893 gdk_window_get_width (tree_view->priv->bin_window);
3896 gdk_window_get_height (tree_view->priv->bin_window);
3899 if (tree_view->priv->height < bin_window_height)
3901 gtk_paint_flat_box (gtk_widget_get_style (widget),
3903 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),
4184 background_area.width,
4185 background_area.height);
4189 gtk_paint_flat_box (gtk_widget_get_style (widget),
4197 background_area.width,
4198 background_area.height);
4201 if (draw_hgrid_lines)
4203 cairo_set_line_width (cr, 1.0);
4204 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
4206 if (background_area.y >= 0)
4209 gdk_draw_line (event->window,
4210 tree_view->priv->grid_line_gc[widget->state],
4211 background_area.x, background_area.y,
4212 background_area.x + background_area.width,
4215 cairo_move_to (cr, background_area.x, background_area.y - 0.5);
4216 cairo_line_to (cr, background_area.x + background_area.width,
4217 background_area.y - 0.5);
4221 if (y_offset + max_height >= Zarea.height - 0.5)
4224 gdk_draw_line (event->window,
4225 tree_view->priv->grid_line_gc[widget->state],
4226 background_area.x, background_area.y + max_height,
4227 background_area.x + background_area.width,
4228 background_area.y + max_height);
4231 cairo_move_to (cr, background_area.x, background_area.y + max_height - 0.5);
4232 cairo_line_to (cr, background_area.x + background_area.width,
4233 background_area.y + max_height - 0.5);
4239 _pspp_sheet_view_column_cell_render (column,
4245 if (node == cursor && has_special_cell &&
4246 ((column == tree_view->priv->focus_column &&
4247 PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS) &&
4248 gtk_widget_has_focus (widget)) ||
4249 (column == tree_view->priv->edited_column)))
4251 _pspp_sheet_view_column_cell_draw_focus (column,
4258 cell_offset += column->width;
4261 if (cell_offset < Zarea.x)
4263 gtk_paint_flat_box (gtk_widget_get_style (widget),
4271 Zarea.x - cell_offset,
4272 background_area.height);
4275 if (node == drag_highlight)
4277 /* Draw indicator for the drop
4279 gint highlight_y = -1;
4283 switch (tree_view->priv->drag_dest_pos)
4285 case PSPP_SHEET_VIEW_DROP_BEFORE:
4286 highlight_y = background_area.y - 1;
4287 if (highlight_y < 0)
4291 case PSPP_SHEET_VIEW_DROP_AFTER:
4292 highlight_y = background_area.y + background_area.height - 1;
4295 case PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE:
4296 case PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER:
4297 _pspp_sheet_view_find_node (tree_view, drag_dest_path, &node);
4301 width = gdk_window_get_width (tree_view->priv->bin_window);
4303 if (row_ending_details)
4304 gtk_paint_focus (gtk_widget_get_style (widget),
4306 gtk_widget_get_state (widget),
4309 ? (is_last ? "treeview-drop-indicator" : "treeview-drop-indicator-left" )
4310 : (is_last ? "treeview-drop-indicator-right" : "tree-view-drop-indicator-middle" )),
4311 0, BACKGROUND_FIRST_PIXEL (tree_view, node)
4312 - focus_line_width / 2,
4313 width, ROW_HEIGHT (tree_view)
4314 - focus_line_width + 1);
4316 gtk_paint_focus (gtk_widget_get_style (widget),
4318 gtk_widget_get_state (widget),
4320 "treeview-drop-indicator",
4321 0, BACKGROUND_FIRST_PIXEL (tree_view, node)
4322 - focus_line_width / 2,
4323 width, ROW_HEIGHT (tree_view)
4324 - focus_line_width + 1);
4329 if (highlight_y >= 0)
4331 gdk_draw_line (event->window,
4332 widget->style->fg_gc[gtk_widget_get_state (widget)],
4335 rtl ? 0 : bin_window_width,
4341 /* draw the big row-spanning focus rectangle, if needed */
4342 if (!has_special_cell && node == cursor &&
4343 PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS) &&
4344 gtk_widget_has_focus (widget))
4346 gint tmp_y, tmp_height;
4348 GtkStateType focus_rect_state;
4351 flags & GTK_CELL_RENDERER_SELECTED ? GTK_STATE_SELECTED :
4352 (flags & GTK_CELL_RENDERER_PRELIT ? GTK_STATE_PRELIGHT :
4353 (flags & GTK_CELL_RENDERER_INSENSITIVE ? GTK_STATE_INSENSITIVE :
4356 width = gdk_window_get_width (tree_view->priv->bin_window);
4358 if (draw_hgrid_lines)
4360 tmp_y = BACKGROUND_FIRST_PIXEL (tree_view, node) + grid_line_width / 2;
4361 tmp_height = ROW_HEIGHT (tree_view) - grid_line_width;
4365 tmp_y = BACKGROUND_FIRST_PIXEL (tree_view, node);
4366 tmp_height = ROW_HEIGHT (tree_view);
4369 if (row_ending_details)
4370 gtk_paint_focus (gtk_widget_get_style (widget),
4375 ? (is_last ? "treeview" : "treeview-left" )
4376 : (is_last ? "treeview-right" : "treeview-middle" )),
4380 gtk_paint_focus (gtk_widget_get_style (widget),
4389 y_offset += max_height;
4393 node = pspp_sheet_view_node_next (tree_view, node);
4396 gboolean has_next = gtk_tree_model_iter_next (tree_view->priv->model, &iter);
4400 TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
4407 while (y_offset < Zarea.height);
4410 pspp_sheet_view_draw_vertical_grid_lines (tree_view, cr, n_visible_columns,
4414 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
4416 GdkRectangle *rectangles;
4419 gdk_region_get_rectangles (event->region,
4423 while (n_rectangles--)
4424 pspp_sheet_view_paint_rubber_band (tree_view, &rectangles[n_rectangles]);
4426 g_free (rectangles);
4431 gtk_tree_path_free (cursor_path);
4434 gtk_tree_path_free (drag_dest_path);
4440 pspp_sheet_view_expose (GtkWidget *widget,
4441 GdkEventExpose *event)
4443 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4444 cairo_t *cr = gdk_cairo_create (event->window);
4446 if (event->window == tree_view->priv->bin_window)
4451 retval = pspp_sheet_view_bin_expose (widget, event);
4453 /* We can't just chain up to Container::expose as it will try to send the
4454 * event to the headers, so we handle propagating it to our children
4455 * (eg. widgets being edited) ourselves.
4457 tmp_list = tree_view->priv->children;
4460 PsppSheetViewChild *child = tmp_list->data;
4461 tmp_list = tmp_list->next;
4463 gtk_container_propagate_draw (GTK_CONTAINER (tree_view), child->widget, cr);
4468 else if (event->window == tree_view->priv->header_window)
4470 gint n_visible_columns;
4473 gtk_paint_flat_box (gtk_widget_get_style (widget),
4482 event->area.height);
4484 for (list = tree_view->priv->columns; list != NULL; list = list->next)
4486 PsppSheetViewColumn *column = list->data;
4488 if (column == tree_view->priv->drag_column || !column->visible)
4491 if (span_intersects (column->allocation.x, column->allocation.width,
4492 event->area.x, event->area.width)
4493 && column->button != NULL)
4494 gtk_container_propagate_expose (GTK_CONTAINER (tree_view),
4495 column->button, event);
4498 n_visible_columns = 0;
4499 for (list = tree_view->priv->columns; list; list = list->next)
4501 if (! PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
4503 n_visible_columns ++;
4505 pspp_sheet_view_draw_vertical_grid_lines (tree_view,
4509 event->area.height);
4511 else if (event->window == tree_view->priv->drag_window)
4513 gtk_container_propagate_expose (GTK_CONTAINER (tree_view),
4514 tree_view->priv->drag_column->button,
4528 /* returns 0x1 when no column has been found -- yes it's hackish */
4529 static PsppSheetViewColumn *
4530 pspp_sheet_view_get_drop_column (PsppSheetView *tree_view,
4531 PsppSheetViewColumn *column,
4534 PsppSheetViewColumn *left_column = NULL;
4535 PsppSheetViewColumn *cur_column = NULL;
4538 if (!column->reorderable)
4539 return (PsppSheetViewColumn *)0x1;
4541 switch (drop_position)
4544 /* find first column where we can drop */
4545 tmp_list = tree_view->priv->columns;
4546 if (column == PSPP_SHEET_VIEW_COLUMN (tmp_list->data))
4547 return (PsppSheetViewColumn *)0x1;
4551 g_assert (tmp_list);
4553 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4554 tmp_list = tmp_list->next;
4556 if (left_column && left_column->visible == FALSE)
4559 if (!tree_view->priv->column_drop_func)
4562 if (!tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4564 left_column = cur_column;
4571 if (!tree_view->priv->column_drop_func)
4574 if (tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data))
4577 return (PsppSheetViewColumn *)0x1;
4581 /* find first column after column where we can drop */
4582 tmp_list = tree_view->priv->columns;
4584 for (; tmp_list; tmp_list = tmp_list->next)
4585 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data) == column)
4588 if (!tmp_list || !tmp_list->next)
4589 return (PsppSheetViewColumn *)0x1;
4591 tmp_list = tmp_list->next;
4592 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4593 tmp_list = tmp_list->next;
4597 g_assert (tmp_list);
4599 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4600 tmp_list = tmp_list->next;
4602 if (left_column && left_column->visible == FALSE)
4604 left_column = cur_column;
4606 tmp_list = tmp_list->next;
4610 if (!tree_view->priv->column_drop_func)
4613 if (!tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4615 left_column = cur_column;
4622 if (!tree_view->priv->column_drop_func)
4625 if (tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data))
4628 return (PsppSheetViewColumn *)0x1;
4632 /* find first column before column where we can drop */
4633 tmp_list = tree_view->priv->columns;
4635 for (; tmp_list; tmp_list = tmp_list->next)
4636 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data) == column)
4639 if (!tmp_list || !tmp_list->prev)
4640 return (PsppSheetViewColumn *)0x1;
4642 tmp_list = tmp_list->prev;
4643 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4644 tmp_list = tmp_list->prev;
4648 g_assert (tmp_list);
4650 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4652 if (left_column && !left_column->visible)
4654 /*if (!tmp_list->prev)
4655 return (PsppSheetViewColumn *)0x1;
4658 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->prev->data);
4659 tmp_list = tmp_list->prev->prev;
4662 cur_column = left_column;
4664 tmp_list = tmp_list->prev;
4668 if (!tree_view->priv->column_drop_func)
4671 if (tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4674 cur_column = left_column;
4675 tmp_list = tmp_list->prev;
4678 if (!tree_view->priv->column_drop_func)
4681 if (tree_view->priv->column_drop_func (tree_view, column, NULL, cur_column, tree_view->priv->column_drop_func_data))
4684 return (PsppSheetViewColumn *)0x1;
4688 /* same as DROP_HOME case, but doing it backwards */
4689 tmp_list = g_list_last (tree_view->priv->columns);
4692 if (column == PSPP_SHEET_VIEW_COLUMN (tmp_list->data))
4693 return (PsppSheetViewColumn *)0x1;
4697 g_assert (tmp_list);
4699 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4701 if (left_column && !left_column->visible)
4703 cur_column = left_column;
4704 tmp_list = tmp_list->prev;
4707 if (!tree_view->priv->column_drop_func)
4710 if (tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
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, NULL, cur_column, tree_view->priv->column_drop_func_data))
4723 return (PsppSheetViewColumn *)0x1;
4727 return (PsppSheetViewColumn *)0x1;
4731 pspp_sheet_view_key_press (GtkWidget *widget,
4734 PsppSheetView *tree_view = (PsppSheetView *) widget;
4736 if (tree_view->priv->rubber_band_status)
4738 if (event->keyval == GDK_Escape)
4739 pspp_sheet_view_stop_rubber_band (tree_view);
4744 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
4746 if (event->keyval == GDK_Escape)
4748 tree_view->priv->cur_reorder = NULL;
4749 pspp_sheet_view_button_release_drag_column (widget, NULL);
4754 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
4756 GList *focus_column;
4759 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
4761 for (focus_column = tree_view->priv->columns;
4763 focus_column = focus_column->next)
4765 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4767 if (column->button && gtk_widget_has_focus (column->button))
4772 (event->state & GDK_SHIFT_MASK) && (event->state & GDK_MOD1_MASK) &&
4773 (event->keyval == GDK_Left || event->keyval == GDK_KP_Left
4774 || event->keyval == GDK_Right || event->keyval == GDK_KP_Right))
4776 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4778 if (!column->resizable)
4780 gtk_widget_error_bell (widget);
4784 if (event->keyval == (rtl ? GDK_Right : GDK_Left)
4785 || event->keyval == (rtl ? GDK_KP_Right : GDK_KP_Left))
4787 gint old_width = column->resized_width;
4789 column->resized_width = MAX (column->resized_width,
4791 column->resized_width -= 2;
4792 if (column->resized_width < 0)
4793 column->resized_width = 0;
4795 if (column->min_width == -1)
4796 column->resized_width = MAX (column->button_request,
4797 column->resized_width);
4799 column->resized_width = MAX (column->min_width,
4800 column->resized_width);
4802 if (column->max_width != -1)
4803 column->resized_width = MIN (column->resized_width,
4806 column->use_resized_width = TRUE;
4808 if (column->resized_width != old_width)
4809 gtk_widget_queue_resize (widget);
4811 gtk_widget_error_bell (widget);
4813 else if (event->keyval == (rtl ? GDK_Left : GDK_Right)
4814 || event->keyval == (rtl ? GDK_KP_Left : GDK_KP_Right))
4816 gint old_width = column->resized_width;
4818 column->resized_width = MAX (column->resized_width,
4820 column->resized_width += 2;
4822 if (column->max_width != -1)
4823 column->resized_width = MIN (column->resized_width,
4826 column->use_resized_width = TRUE;
4828 if (column->resized_width != old_width)
4829 gtk_widget_queue_resize (widget);
4831 gtk_widget_error_bell (widget);
4838 (event->state & GDK_MOD1_MASK) &&
4839 (event->keyval == GDK_Left || event->keyval == GDK_KP_Left
4840 || event->keyval == GDK_Right || event->keyval == GDK_KP_Right
4841 || event->keyval == GDK_Home || event->keyval == GDK_KP_Home
4842 || event->keyval == GDK_End || event->keyval == GDK_KP_End))
4844 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4846 if (event->keyval == (rtl ? GDK_Right : GDK_Left)
4847 || event->keyval == (rtl ? GDK_KP_Right : GDK_KP_Left))
4849 PsppSheetViewColumn *col;
4850 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_LEFT);
4851 if (col != (PsppSheetViewColumn *)0x1)
4852 pspp_sheet_view_move_column_after (tree_view, column, col);
4854 gtk_widget_error_bell (widget);
4856 else if (event->keyval == (rtl ? GDK_Left : GDK_Right)
4857 || event->keyval == (rtl ? GDK_KP_Left : GDK_KP_Right))
4859 PsppSheetViewColumn *col;
4860 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_RIGHT);
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 == GDK_Home || event->keyval == GDK_KP_Home)
4868 PsppSheetViewColumn *col;
4869 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_HOME);
4870 if (col != (PsppSheetViewColumn *)0x1)
4871 pspp_sheet_view_move_column_after (tree_view, column, col);
4873 gtk_widget_error_bell (widget);
4875 else if (event->keyval == GDK_End || event->keyval == GDK_KP_End)
4877 PsppSheetViewColumn *col;
4878 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_END);
4879 if (col != (PsppSheetViewColumn *)0x1)
4880 pspp_sheet_view_move_column_after (tree_view, column, col);
4882 gtk_widget_error_bell (widget);
4889 /* Chain up to the parent class. It handles the keybindings. */
4890 if (GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->key_press_event (widget, event))
4893 if (tree_view->priv->search_entry_avoid_unhandled_binding)
4895 tree_view->priv->search_entry_avoid_unhandled_binding = FALSE;
4899 /* We pass the event to the search_entry. If its text changes, then we start
4900 * the typeahead find capabilities. */
4901 if (gtk_widget_has_focus (GTK_WIDGET (tree_view))
4902 && tree_view->priv->enable_search
4903 && !tree_view->priv->search_custom_entry_set)
4905 GdkEvent *new_event;
4907 const char *new_text;
4910 gboolean text_modified;
4911 gulong popup_menu_id;
4913 pspp_sheet_view_ensure_interactive_directory (tree_view);
4915 /* Make a copy of the current text */
4916 old_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry)));
4917 new_event = gdk_event_copy ((GdkEvent *) event);
4918 g_object_unref (((GdkEventKey *) new_event)->window);
4919 ((GdkEventKey *) new_event)->window = g_object_ref (gtk_widget_get_window (tree_view->priv->search_window));
4920 gtk_widget_realize (tree_view->priv->search_window);
4922 popup_menu_id = g_signal_connect (tree_view->priv->search_entry,
4923 "popup-menu", G_CALLBACK (gtk_true),
4926 /* Move the entry off screen */
4927 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
4928 gtk_window_move (GTK_WINDOW (tree_view->priv->search_window),
4929 gdk_screen_get_width (screen) + 1,
4930 gdk_screen_get_height (screen) + 1);
4931 gtk_widget_show (tree_view->priv->search_window);
4933 /* Send the event to the window. If the preedit_changed signal is emitted
4934 * during this event, we will set priv->imcontext_changed */
4935 tree_view->priv->imcontext_changed = FALSE;
4936 retval = gtk_widget_event (tree_view->priv->search_window, new_event);
4937 gdk_event_free (new_event);
4938 gtk_widget_hide (tree_view->priv->search_window);
4940 g_signal_handler_disconnect (tree_view->priv->search_entry,
4943 /* We check to make sure that the entry tried to handle the text, and that
4944 * the text has changed.
4946 new_text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
4947 text_modified = strcmp (old_text, new_text) != 0;
4949 if (tree_view->priv->imcontext_changed || /* we're in a preedit */
4950 (retval && text_modified)) /* ...or the text was modified */
4952 if (pspp_sheet_view_real_start_interactive_search (tree_view, FALSE))
4954 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
4959 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
4969 pspp_sheet_view_key_release (GtkWidget *widget,
4972 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4974 if (tree_view->priv->rubber_band_status)
4977 return GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->key_release_event (widget, event);
4980 /* FIXME Is this function necessary? Can I get an enter_notify event
4981 * w/o either an expose event or a mouse motion event?
4984 pspp_sheet_view_enter_notify (GtkWidget *widget,
4985 GdkEventCrossing *event)
4987 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4991 /* Sanity check it */
4992 if (event->window != tree_view->priv->bin_window)
4995 if (tree_view->priv->row_count == 0)
4998 if (event->mode == GDK_CROSSING_GRAB ||
4999 event->mode == GDK_CROSSING_GTK_GRAB ||
5000 event->mode == GDK_CROSSING_GTK_UNGRAB ||
5001 event->mode == GDK_CROSSING_STATE_CHANGED)
5004 /* find the node internally */
5005 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, event->y);
5008 pspp_sheet_view_find_offset (tree_view, new_y, &node);
5010 tree_view->priv->event_last_x = event->x;
5011 tree_view->priv->event_last_y = event->y;
5013 prelight_or_select (tree_view, node, event->x, event->y);
5019 pspp_sheet_view_leave_notify (GtkWidget *widget,
5020 GdkEventCrossing *event)
5022 PsppSheetView *tree_view;
5024 if (event->mode == GDK_CROSSING_GRAB)
5027 tree_view = PSPP_SHEET_VIEW (widget);
5029 if (tree_view->priv->prelight_node >= 0)
5030 _pspp_sheet_view_queue_draw_node (tree_view,
5031 tree_view->priv->prelight_node,
5034 tree_view->priv->event_last_x = -10000;
5035 tree_view->priv->event_last_y = -10000;
5037 prelight_or_select (tree_view,
5039 -1000, -1000); /* coords not possibly over an arrow */
5046 pspp_sheet_view_focus_out (GtkWidget *widget,
5047 GdkEventFocus *event)
5049 PsppSheetView *tree_view;
5051 tree_view = PSPP_SHEET_VIEW (widget);
5053 gtk_widget_queue_draw (widget);
5055 /* destroy interactive search dialog */
5056 if (tree_view->priv->search_window)
5057 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
5063 /* Incremental Reflow
5067 pspp_sheet_view_node_queue_redraw (PsppSheetView *tree_view,
5070 GtkAllocation allocation;
5071 gint y = pspp_sheet_view_node_find_offset (tree_view, node)
5072 - gtk_adjustment_get_value (tree_view->priv->vadjustment)
5073 + TREE_VIEW_HEADER_HEIGHT (tree_view);
5075 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
5077 gtk_widget_queue_draw_area (GTK_WIDGET (tree_view),
5080 tree_view->priv->fixed_height);
5084 node_is_visible (PsppSheetView *tree_view,
5090 y = pspp_sheet_view_node_find_offset (tree_view, node);
5091 height = ROW_HEIGHT (tree_view);
5093 if (y >= gtk_adjustment_get_value (tree_view->priv->vadjustment) &&
5094 y + height <= (gtk_adjustment_get_value (tree_view->priv->vadjustment)
5095 + gtk_adjustment_get_page_size (tree_view->priv->vadjustment)))
5101 /* Returns the row height. */
5103 validate_row (PsppSheetView *tree_view,
5108 PsppSheetViewColumn *column;
5109 GList *list, *first_column, *last_column;
5111 gint horizontal_separator;
5112 gint vertical_separator;
5113 gint focus_line_width;
5114 gboolean draw_vgrid_lines, draw_hgrid_lines;
5116 gint grid_line_width;
5117 gboolean wide_separators;
5118 gint separator_height;
5120 gtk_widget_style_get (GTK_WIDGET (tree_view),
5121 "focus-padding", &focus_pad,
5122 "focus-line-width", &focus_line_width,
5123 "horizontal-separator", &horizontal_separator,
5124 "vertical-separator", &vertical_separator,
5125 "grid-line-width", &grid_line_width,
5126 "wide-separators", &wide_separators,
5127 "separator-height", &separator_height,
5131 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
5132 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
5134 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
5135 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
5137 for (last_column = g_list_last (tree_view->priv->columns);
5138 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
5139 last_column = last_column->prev)
5142 for (first_column = g_list_first (tree_view->priv->columns);
5143 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
5144 first_column = first_column->next)
5147 for (list = tree_view->priv->columns; list; list = list->next)
5152 column = list->data;
5154 if (! column->visible)
5157 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, iter);
5158 pspp_sheet_view_column_cell_get_size (column,
5160 &tmp_width, &tmp_height);
5162 tmp_height += vertical_separator;
5163 height = MAX (height, tmp_height);
5165 tmp_width = tmp_width + horizontal_separator;
5167 if (draw_vgrid_lines)
5169 if (list->data == first_column || list->data == last_column)
5170 tmp_width += grid_line_width / 2.0;
5172 tmp_width += grid_line_width;
5175 if (tmp_width > column->requested_width)
5176 column->requested_width = tmp_width;
5179 if (draw_hgrid_lines)
5180 height += grid_line_width;
5182 tree_view->priv->post_validation_flag = TRUE;
5188 validate_visible_area (PsppSheetView *tree_view)
5190 GtkTreePath *path = NULL;
5191 GtkTreePath *above_path = NULL;
5194 gboolean size_changed = FALSE;
5196 gint area_above = 0;
5197 gint area_below = 0;
5198 GtkAllocation allocation;
5200 if (tree_view->priv->row_count == 0)
5203 if (tree_view->priv->scroll_to_path == NULL)
5206 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
5208 total_height = allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
5210 if (total_height == 0)
5213 path = gtk_tree_row_reference_get_path (tree_view->priv->scroll_to_path);
5216 /* we are going to scroll, and will update dy */
5217 _pspp_sheet_view_find_node (tree_view, path, &node);
5218 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
5220 if (tree_view->priv->scroll_to_use_align)
5222 gint height = ROW_HEIGHT (tree_view);
5223 area_above = (total_height - height) *
5224 tree_view->priv->scroll_to_row_align;
5225 area_below = total_height - area_above - height;
5226 area_above = MAX (area_above, 0);
5227 area_below = MAX (area_below, 0);
5232 * 1) row not visible
5236 gint height = ROW_HEIGHT (tree_view);
5238 dy = pspp_sheet_view_node_find_offset (tree_view, node);
5240 if (dy >= gtk_adjustment_get_value (tree_view->priv->vadjustment) &&
5241 dy + height <= (gtk_adjustment_get_value (tree_view->priv->vadjustment)
5242 + gtk_adjustment_get_page_size (tree_view->priv->vadjustment)))
5244 /* row visible: keep the row at the same position */
5245 area_above = dy - gtk_adjustment_get_value (tree_view->priv->vadjustment);
5246 area_below = (gtk_adjustment_get_value (tree_view->priv->vadjustment) +
5247 gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
5252 /* row not visible */
5254 && dy + height <= gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
5256 /* row at the beginning -- fixed */
5258 area_below = gtk_adjustment_get_page_size (tree_view->priv->vadjustment)
5259 - area_above - height;
5261 else if (dy >= (gtk_adjustment_get_upper (tree_view->priv->vadjustment) -
5262 gtk_adjustment_get_page_size (tree_view->priv->vadjustment)))
5264 /* row at the end -- fixed */
5265 area_above = dy - (gtk_adjustment_get_upper (tree_view->priv->vadjustment) -
5266 gtk_adjustment_get_page_size (tree_view->priv->vadjustment));
5267 area_below = gtk_adjustment_get_page_size (tree_view->priv->vadjustment) -
5268 area_above - height;
5272 area_above = gtk_adjustment_get_page_size (tree_view->priv->vadjustment) - height;
5278 /* row somewhere in the middle, bring it to the top
5282 area_below = total_height - height;
5288 /* the scroll to isn't valid; ignore it.
5291 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
5292 tree_view->priv->scroll_to_path = NULL;
5296 above_path = gtk_tree_path_copy (path);
5298 /* Now, we walk forwards and backwards, measuring rows. Unfortunately,
5299 * backwards is much slower then forward, as there is no iter_prev function.
5300 * We go forwards first in case we run out of tree. Then we go backwards to
5303 while (node >= 0 && area_below > 0)
5305 gboolean done = FALSE;
5308 node = pspp_sheet_view_node_next (tree_view, node);
5311 gboolean has_next = gtk_tree_model_iter_next (tree_view->priv->model, &iter);
5313 gtk_tree_path_next (path);
5316 TREE_VIEW_INTERNAL_ASSERT_VOID (has_next);
5326 area_below -= ROW_HEIGHT (tree_view);
5328 gtk_tree_path_free (path);
5330 /* If we ran out of tree, and have extra area_below left, we need to add it
5333 area_above += area_below;
5335 _pspp_sheet_view_find_node (tree_view, above_path, &node);
5337 /* We walk backwards */
5338 while (area_above > 0)
5340 node = pspp_sheet_view_node_prev (tree_view, node);
5342 /* Always find the new path in the tree. We cannot just assume
5343 * a gtk_tree_path_prev() is enough here, as there might be children
5344 * in between this node and the previous sibling node. If this
5345 * appears to be a performance hotspot in profiles, we can look into
5346 * intrigate logic for keeping path, node and iter in sync like
5347 * we do for forward walks. (Which will be hard because of the lacking
5354 gtk_tree_path_free (above_path);
5355 above_path = _pspp_sheet_view_find_path (tree_view, node);
5357 gtk_tree_model_get_iter (tree_view->priv->model, &iter, above_path);
5359 area_above -= ROW_HEIGHT (tree_view);
5362 /* set the dy here to scroll to the path,
5363 * and sync the top row accordingly
5365 pspp_sheet_view_set_top_row (tree_view, above_path, -area_above);
5366 pspp_sheet_view_top_row_to_dy (tree_view);
5368 /* update width/height and queue a resize */
5371 GtkRequisition requisition;
5373 /* We temporarily guess a size, under the assumption that it will be the
5374 * same when we get our next size_allocate. If we don't do this, we'll be
5375 * in an inconsistent state if we call top_row_to_dy. */
5377 gtk_widget_size_request (GTK_WIDGET (tree_view), &requisition);
5378 gtk_adjustment_set_upper (tree_view->priv->hadjustment, MAX (gtk_adjustment_get_upper (tree_view->priv->hadjustment), (gfloat)requisition.width));
5379 gtk_adjustment_set_upper (tree_view->priv->vadjustment, MAX (gtk_adjustment_get_upper (tree_view->priv->vadjustment), (gfloat)requisition.height));
5380 gtk_adjustment_changed (tree_view->priv->hadjustment);
5381 gtk_adjustment_changed (tree_view->priv->vadjustment);
5382 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
5385 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
5386 tree_view->priv->scroll_to_path = NULL;
5389 gtk_tree_path_free (above_path);
5391 if (tree_view->priv->scroll_to_column)
5393 tree_view->priv->scroll_to_column = NULL;
5395 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
5399 initialize_fixed_height_mode (PsppSheetView *tree_view)
5401 if (!tree_view->priv->row_count)
5404 if (tree_view->priv->fixed_height_set)
5407 if (tree_view->priv->fixed_height < 0)
5414 path = _pspp_sheet_view_find_path (tree_view, node);
5415 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
5417 tree_view->priv->fixed_height = validate_row (tree_view, node, &iter, path);
5419 gtk_tree_path_free (path);
5421 g_object_notify (G_OBJECT (tree_view), "fixed-height");
5425 /* Our strategy for finding nodes to validate is a little convoluted. We find
5426 * the left-most uninvalidated node. We then try walking right, validating
5427 * nodes. Once we find a valid node, we repeat the previous process of finding
5428 * the first invalid node.
5432 validate_rows_handler (PsppSheetView *tree_view)
5434 initialize_fixed_height_mode (tree_view);
5435 if (tree_view->priv->validate_rows_timer)
5437 g_source_remove (tree_view->priv->validate_rows_timer);
5438 tree_view->priv->validate_rows_timer = 0;
5445 do_presize_handler (PsppSheetView *tree_view)
5447 GtkRequisition requisition;
5449 validate_visible_area (tree_view);
5450 tree_view->priv->presize_handler_timer = 0;
5452 if (! gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5455 gtk_widget_size_request (GTK_WIDGET (tree_view), &requisition);
5457 gtk_adjustment_set_upper (tree_view->priv->hadjustment, MAX (gtk_adjustment_get_upper (tree_view->priv->hadjustment), (gfloat)requisition.width));
5458 gtk_adjustment_set_upper (tree_view->priv->vadjustment, MAX (gtk_adjustment_get_upper (tree_view->priv->vadjustment), (gfloat)requisition.height));
5459 gtk_adjustment_changed (tree_view->priv->hadjustment);
5460 gtk_adjustment_changed (tree_view->priv->vadjustment);
5461 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
5467 presize_handler_callback (gpointer data)
5469 do_presize_handler (PSPP_SHEET_VIEW (data));
5475 install_presize_handler (PsppSheetView *tree_view)
5477 if (! gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5480 if (! tree_view->priv->presize_handler_timer)
5482 tree_view->priv->presize_handler_timer =
5483 gdk_threads_add_idle_full (GTK_PRIORITY_RESIZE - 2, presize_handler_callback, tree_view, NULL);
5485 if (! tree_view->priv->validate_rows_timer)
5487 tree_view->priv->validate_rows_timer =
5488 gdk_threads_add_idle_full (PSPP_SHEET_VIEW_PRIORITY_VALIDATE, (GSourceFunc) validate_rows_handler, tree_view, NULL);
5493 scroll_sync_handler (PsppSheetView *tree_view)
5495 if (tree_view->priv->height <= gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
5496 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment), 0);
5497 else if (gtk_tree_row_reference_valid (tree_view->priv->top_row))
5498 pspp_sheet_view_top_row_to_dy (tree_view);
5500 pspp_sheet_view_dy_to_top_row (tree_view);
5502 tree_view->priv->scroll_sync_timer = 0;
5508 install_scroll_sync_handler (PsppSheetView *tree_view)
5510 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5513 if (!tree_view->priv->scroll_sync_timer)
5515 tree_view->priv->scroll_sync_timer =
5516 gdk_threads_add_idle_full (PSPP_SHEET_VIEW_PRIORITY_SCROLL_SYNC, (GSourceFunc) scroll_sync_handler, tree_view, NULL);
5521 pspp_sheet_view_set_top_row (PsppSheetView *tree_view,
5525 gtk_tree_row_reference_free (tree_view->priv->top_row);
5529 tree_view->priv->top_row = NULL;
5530 tree_view->priv->top_row_dy = 0;
5534 tree_view->priv->top_row = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
5535 tree_view->priv->top_row_dy = offset;
5539 /* Always call this iff dy is in the visible range. If the tree is empty, then
5540 * it's set to be NULL, and top_row_dy is 0;
5543 pspp_sheet_view_dy_to_top_row (PsppSheetView *tree_view)
5549 if (tree_view->priv->row_count == 0)
5551 pspp_sheet_view_set_top_row (tree_view, NULL, 0);
5555 offset = pspp_sheet_view_find_offset (tree_view,
5556 tree_view->priv->dy,
5561 pspp_sheet_view_set_top_row (tree_view, NULL, 0);
5565 path = _pspp_sheet_view_find_path (tree_view, node);
5566 pspp_sheet_view_set_top_row (tree_view, path, offset);
5567 gtk_tree_path_free (path);
5573 pspp_sheet_view_top_row_to_dy (PsppSheetView *tree_view)
5579 /* Avoid recursive calls */
5580 if (tree_view->priv->in_top_row_to_dy)
5583 if (tree_view->priv->top_row)
5584 path = gtk_tree_row_reference_get_path (tree_view->priv->top_row);
5591 _pspp_sheet_view_find_node (tree_view, path, &node);
5594 gtk_tree_path_free (path);
5598 /* keep dy and set new toprow */
5599 gtk_tree_row_reference_free (tree_view->priv->top_row);
5600 tree_view->priv->top_row = NULL;
5601 tree_view->priv->top_row_dy = 0;
5602 /* DO NOT install the idle handler */
5603 pspp_sheet_view_dy_to_top_row (tree_view);
5607 if (ROW_HEIGHT (tree_view) < tree_view->priv->top_row_dy)
5609 /* new top row -- do NOT install the idle handler */
5610 pspp_sheet_view_dy_to_top_row (tree_view);
5614 new_dy = pspp_sheet_view_node_find_offset (tree_view, node);
5615 new_dy += tree_view->priv->top_row_dy;
5617 if (new_dy + gtk_adjustment_get_page_size (tree_view->priv->vadjustment) > tree_view->priv->height)
5618 new_dy = tree_view->priv->height - gtk_adjustment_get_page_size (tree_view->priv->vadjustment);
5620 new_dy = MAX (0, new_dy);
5622 tree_view->priv->in_top_row_to_dy = TRUE;
5623 gtk_adjustment_set_value (tree_view->priv->vadjustment, (gdouble)new_dy);
5624 tree_view->priv->in_top_row_to_dy = FALSE;
5629 _pspp_sheet_view_install_mark_rows_col_dirty (PsppSheetView *tree_view)
5631 install_presize_handler (tree_view);
5637 set_source_row (GdkDragContext *context,
5638 GtkTreeModel *model,
5639 GtkTreePath *source_row)
5641 g_object_set_data_full (G_OBJECT (context),
5642 "gtk-tree-view-source-row",
5643 source_row ? gtk_tree_row_reference_new (model, source_row) : NULL,
5644 (GDestroyNotify) (source_row ? gtk_tree_row_reference_free : NULL));
5648 get_source_row (GdkDragContext *context)
5650 GtkTreeRowReference *ref =
5651 g_object_get_data (G_OBJECT (context), "gtk-tree-view-source-row");
5654 return gtk_tree_row_reference_get_path (ref);
5661 GtkTreeRowReference *dest_row;
5662 guint path_down_mode : 1;
5663 guint empty_view_drop : 1;
5664 guint drop_append_mode : 1;
5669 dest_row_free (gpointer data)
5671 DestRow *dr = (DestRow *)data;
5673 gtk_tree_row_reference_free (dr->dest_row);
5674 g_slice_free (DestRow, dr);
5678 set_dest_row (GdkDragContext *context,
5679 GtkTreeModel *model,
5680 GtkTreePath *dest_row,
5681 gboolean path_down_mode,
5682 gboolean empty_view_drop,
5683 gboolean drop_append_mode)
5689 g_object_set_data_full (G_OBJECT (context), "gtk-tree-view-dest-row",
5694 dr = g_slice_new (DestRow);
5696 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5697 dr->path_down_mode = path_down_mode != FALSE;
5698 dr->empty_view_drop = empty_view_drop != FALSE;
5699 dr->drop_append_mode = drop_append_mode != FALSE;
5701 g_object_set_data_full (G_OBJECT (context), "gtk-tree-view-dest-row",
5702 dr, (GDestroyNotify) dest_row_free);
5706 get_dest_row (GdkDragContext *context,
5707 gboolean *path_down_mode)
5710 g_object_get_data (G_OBJECT (context), "gtk-tree-view-dest-row");
5714 GtkTreePath *path = NULL;
5717 *path_down_mode = dr->path_down_mode;
5720 path = gtk_tree_row_reference_get_path (dr->dest_row);
5721 else if (dr->empty_view_drop)
5722 path = gtk_tree_path_new_from_indices (0, -1);
5726 if (path && dr->drop_append_mode)
5727 gtk_tree_path_next (path);
5735 /* Get/set whether drag_motion requested the drag data and
5736 * drag_data_received should thus not actually insert the data,
5737 * since the data doesn't result from a drop.
5740 set_status_pending (GdkDragContext *context,
5741 GdkDragAction suggested_action)
5743 g_object_set_data (G_OBJECT (context),
5744 "gtk-tree-view-status-pending",
5745 GINT_TO_POINTER (suggested_action));
5748 static GdkDragAction
5749 get_status_pending (GdkDragContext *context)
5751 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5752 "gtk-tree-view-status-pending"));
5755 static TreeViewDragInfo*
5756 get_info (PsppSheetView *tree_view)
5758 return g_object_get_data (G_OBJECT (tree_view), "gtk-tree-view-drag-info");
5762 destroy_info (TreeViewDragInfo *di)
5764 g_slice_free (TreeViewDragInfo, di);
5767 static TreeViewDragInfo*
5768 ensure_info (PsppSheetView *tree_view)
5770 TreeViewDragInfo *di;
5772 di = get_info (tree_view);
5776 di = g_slice_new0 (TreeViewDragInfo);
5778 g_object_set_data_full (G_OBJECT (tree_view),
5779 "gtk-tree-view-drag-info",
5781 (GDestroyNotify) destroy_info);
5788 remove_info (PsppSheetView *tree_view)
5790 g_object_set_data (G_OBJECT (tree_view), "gtk-tree-view-drag-info", NULL);
5795 drag_scan_timeout (gpointer data)
5797 PsppSheetView *tree_view;
5799 GdkModifierType state;
5800 GtkTreePath *path = NULL;
5801 PsppSheetViewColumn *column = NULL;
5802 GdkRectangle visible_rect;
5804 GDK_THREADS_ENTER ();
5806 tree_view = PSPP_SHEET_VIEW (data);
5808 gdk_window_get_pointer (tree_view->priv->bin_window,
5811 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
5813 /* See if we are near the edge. */
5814 if ((x - visible_rect.x) < SCROLL_EDGE_SIZE ||
5815 (visible_rect.x + visible_rect.width - x) < SCROLL_EDGE_SIZE ||
5816 (y - visible_rect.y) < SCROLL_EDGE_SIZE ||
5817 (visible_rect.y + visible_rect.height - y) < SCROLL_EDGE_SIZE)
5819 pspp_sheet_view_get_path_at_pos (tree_view,
5820 tree_view->priv->bin_window,
5829 pspp_sheet_view_scroll_to_cell (tree_view,
5835 gtk_tree_path_free (path);
5839 GDK_THREADS_LEAVE ();
5846 add_scroll_timeout (PsppSheetView *tree_view)
5848 if (tree_view->priv->scroll_timeout == 0)
5850 tree_view->priv->scroll_timeout =
5851 gdk_threads_add_timeout (150, scroll_row_timeout, tree_view);
5856 remove_scroll_timeout (PsppSheetView *tree_view)
5858 if (tree_view->priv->scroll_timeout != 0)
5860 g_source_remove (tree_view->priv->scroll_timeout);
5861 tree_view->priv->scroll_timeout = 0;
5866 check_model_dnd (GtkTreeModel *model,
5867 GType required_iface,
5868 const gchar *signal)
5870 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5872 g_warning ("You must override the default '%s' handler "
5873 "on PsppSheetView when using models that don't support "
5874 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5875 "is to connect to '%s' and call "
5876 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5877 "the default handler from running. Look at the source code "
5878 "for the default handler in gtktreeview.c to get an idea what "
5879 "your handler should do. (gtktreeview.c is in the GTK source "
5880 "code.) If you're using GTK from a language other than C, "
5881 "there may be a more natural way to override default handlers, e.g. via derivation.",
5882 signal, g_type_name (required_iface), signal);
5890 scroll_row_timeout (gpointer data)
5892 PsppSheetView *tree_view = data;
5894 pspp_sheet_view_horizontal_autoscroll (tree_view);
5895 pspp_sheet_view_vertical_autoscroll (tree_view);
5897 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
5898 pspp_sheet_view_update_rubber_band (tree_view);
5903 /* Returns TRUE if event should not be propagated to parent widgets */
5905 set_destination_row (PsppSheetView *tree_view,
5906 GdkDragContext *context,
5907 /* coordinates relative to the widget */
5910 GdkDragAction *suggested_action,
5913 GtkTreePath *path = NULL;
5914 PsppSheetViewDropPosition pos;
5915 PsppSheetViewDropPosition old_pos;
5916 TreeViewDragInfo *di;
5918 GtkTreePath *old_dest_path = NULL;
5919 gboolean can_drop = FALSE;
5921 *suggested_action = 0;
5924 widget = GTK_WIDGET (tree_view);
5926 di = get_info (tree_view);
5928 if (di == NULL || y - TREE_VIEW_HEADER_HEIGHT (tree_view) < 0)
5930 /* someone unset us as a drag dest, note that if
5931 * we return FALSE drag_leave isn't called
5934 pspp_sheet_view_set_drag_dest_row (tree_view,
5936 PSPP_SHEET_VIEW_DROP_BEFORE);
5938 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
5940 return FALSE; /* no longer a drop site */
5943 *target = gtk_drag_dest_find_target (widget, context,
5944 gtk_drag_dest_get_target_list (widget));
5945 if (*target == GDK_NONE)
5950 if (!pspp_sheet_view_get_dest_row_at_pos (tree_view,
5956 GtkTreeModel *model;
5958 /* the row got dropped on empty space, let's setup a special case
5962 gtk_tree_path_free (path);
5964 model = pspp_sheet_view_get_model (tree_view);
5966 n_children = gtk_tree_model_iter_n_children (model, NULL);
5969 pos = PSPP_SHEET_VIEW_DROP_AFTER;
5970 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
5974 pos = PSPP_SHEET_VIEW_DROP_BEFORE;
5975 path = gtk_tree_path_new_from_indices (0, -1);
5985 /* If we left the current row's "open" zone, unset the timeout for
5988 pspp_sheet_view_get_drag_dest_row (tree_view,
5993 gtk_tree_path_free (old_dest_path);
5995 if (TRUE /* FIXME if the location droppable predicate */)
6003 GtkWidget *source_widget;
6005 *suggested_action = gdk_drag_context_get_suggested_action (context);
6006 source_widget = gtk_drag_get_source_widget (context);
6008 if (source_widget == widget)
6010 /* Default to MOVE, unless the user has
6011 * pressed ctrl or shift to affect available actions
6013 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
6014 *suggested_action = GDK_ACTION_MOVE;
6017 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6022 /* can't drop here */
6023 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6025 PSPP_SHEET_VIEW_DROP_BEFORE);
6029 gtk_tree_path_free (path);
6035 get_logical_dest_row (PsppSheetView *tree_view,
6036 gboolean *path_down_mode,
6037 gboolean *drop_append_mode)
6039 /* adjust path to point to the row the drop goes in front of */
6040 GtkTreePath *path = NULL;
6041 PsppSheetViewDropPosition pos;
6043 g_return_val_if_fail (path_down_mode != NULL, NULL);
6044 g_return_val_if_fail (drop_append_mode != NULL, NULL);
6046 *path_down_mode = FALSE;
6047 *drop_append_mode = 0;
6049 pspp_sheet_view_get_drag_dest_row (tree_view, &path, &pos);
6054 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE)
6056 else if (pos == PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE ||
6057 pos == PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER)
6058 *path_down_mode = TRUE;
6062 GtkTreeModel *model = pspp_sheet_view_get_model (tree_view);
6064 g_assert (pos == PSPP_SHEET_VIEW_DROP_AFTER);
6066 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6067 !gtk_tree_model_iter_next (model, &iter))
6068 *drop_append_mode = 1;
6071 *drop_append_mode = 0;
6072 gtk_tree_path_next (path);
6080 pspp_sheet_view_maybe_begin_dragging_row (PsppSheetView *tree_view,
6081 GdkEventMotion *event)
6083 GtkWidget *widget = GTK_WIDGET (tree_view);
6084 GdkDragContext *context;
6085 TreeViewDragInfo *di;
6086 GtkTreePath *path = NULL;
6088 gint cell_x, cell_y;
6089 GtkTreeModel *model;
6090 gboolean retval = FALSE;
6092 di = get_info (tree_view);
6094 if (di == NULL || !di->source_set)
6097 if (tree_view->priv->pressed_button < 0)
6100 if (!gtk_drag_check_threshold (widget,
6101 tree_view->priv->press_start_x,
6102 tree_view->priv->press_start_y,
6103 event->x, event->y))
6106 model = pspp_sheet_view_get_model (tree_view);
6111 button = tree_view->priv->pressed_button;
6112 tree_view->priv->pressed_button = -1;
6114 pspp_sheet_view_get_path_at_pos (tree_view,
6115 tree_view->priv->press_start_x,
6116 tree_view->priv->press_start_y,
6125 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6126 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6130 if (!(GDK_BUTTON1_MASK << (button - 1) & di->start_button_mask))
6133 /* Now we can begin the drag */
6137 context = gtk_drag_begin (widget,
6138 gtk_drag_source_get_target_list (widget),
6143 set_source_row (context, model, path);
6147 gtk_tree_path_free (path);
6155 pspp_sheet_view_drag_begin (GtkWidget *widget,
6156 GdkDragContext *context)
6159 PsppSheetView *tree_view;
6160 GtkTreePath *path = NULL;
6161 gint cell_x, cell_y;
6163 TreeViewDragInfo *di;
6165 tree_view = PSPP_SHEET_VIEW (widget);
6167 /* if the user uses a custom DND source impl, we don't set the icon here */
6168 di = get_info (tree_view);
6170 if (di == NULL || !di->source_set)
6173 pspp_sheet_view_get_path_at_pos (tree_view,
6174 tree_view->priv->press_start_x,
6175 tree_view->priv->press_start_y,
6181 g_return_if_fail (path != NULL);
6183 row_pix = pspp_sheet_view_create_row_drag_icon (tree_view,
6186 gtk_drag_set_icon_pixmap (context,
6187 gdk_drawable_get_colormap (row_pix),
6190 /* the + 1 is for the black border in the icon */
6191 tree_view->priv->press_start_x + 1,
6194 g_object_unref (row_pix);
6195 gtk_tree_path_free (path);
6201 pspp_sheet_view_drag_end (GtkWidget *widget,
6202 GdkDragContext *context)
6207 /* Default signal implementations for the drag signals */
6209 pspp_sheet_view_drag_data_get (GtkWidget *widget,
6210 GdkDragContext *context,
6211 GtkSelectionData *selection_data,
6215 PsppSheetView *tree_view;
6216 GtkTreeModel *model;
6217 TreeViewDragInfo *di;
6218 GtkTreePath *source_row;
6220 tree_view = PSPP_SHEET_VIEW (widget);
6222 model = pspp_sheet_view_get_model (tree_view);
6227 di = get_info (PSPP_SHEET_VIEW (widget));
6232 source_row = get_source_row (context);
6234 if (source_row == NULL)
6237 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6238 * any model; for DragSource models there are some other targets
6242 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6243 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6248 /* If drag_data_get does nothing, try providing row data. */
6249 if (gtk_selection_data_get_target (selection_data) == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6251 gtk_tree_set_row_drag_data (selection_data,
6257 gtk_tree_path_free (source_row);
6262 pspp_sheet_view_drag_data_delete (GtkWidget *widget,
6263 GdkDragContext *context)
6265 TreeViewDragInfo *di;
6266 GtkTreeModel *model;
6267 PsppSheetView *tree_view;
6268 GtkTreePath *source_row;
6270 tree_view = PSPP_SHEET_VIEW (widget);
6271 model = pspp_sheet_view_get_model (tree_view);
6273 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
6276 di = get_info (tree_view);
6281 source_row = get_source_row (context);
6283 if (source_row == NULL)
6286 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6289 gtk_tree_path_free (source_row);
6291 set_source_row (context, NULL, NULL);
6295 pspp_sheet_view_drag_leave (GtkWidget *widget,
6296 GdkDragContext *context,
6299 /* unset any highlight row */
6300 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6302 PSPP_SHEET_VIEW_DROP_BEFORE);
6304 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6309 pspp_sheet_view_drag_motion (GtkWidget *widget,
6310 GdkDragContext *context,
6311 /* coordinates relative to the widget */
6317 GtkTreePath *path = NULL;
6318 PsppSheetViewDropPosition pos;
6319 PsppSheetView *tree_view;
6320 GdkDragAction suggested_action = 0;
6323 tree_view = PSPP_SHEET_VIEW (widget);
6325 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6328 pspp_sheet_view_get_drag_dest_row (tree_view, &path, &pos);
6330 /* we only know this *after* set_desination_row */
6331 empty = tree_view->priv->empty_view_drop;
6333 if (path == NULL && !empty)
6335 /* Can't drop here. */
6336 gdk_drag_status (context, 0, time);
6340 if (tree_view->priv->open_dest_timeout == 0 &&
6341 (pos == PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER ||
6342 pos == PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE))
6348 add_scroll_timeout (tree_view);
6351 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6353 /* Request data so we can use the source row when
6354 * determining whether to accept the drop
6356 set_status_pending (context, suggested_action);
6357 gtk_drag_get_data (widget, context, target, time);
6361 set_status_pending (context, 0);
6362 gdk_drag_status (context, suggested_action, time);
6367 gtk_tree_path_free (path);
6374 pspp_sheet_view_drag_drop (GtkWidget *widget,
6375 GdkDragContext *context,
6376 /* coordinates relative to the widget */
6381 PsppSheetView *tree_view;
6383 GdkDragAction suggested_action = 0;
6384 GdkAtom target = GDK_NONE;
6385 TreeViewDragInfo *di;
6386 GtkTreeModel *model;
6387 gboolean path_down_mode;
6388 gboolean drop_append_mode;
6390 tree_view = PSPP_SHEET_VIEW (widget);
6392 model = pspp_sheet_view_get_model (tree_view);
6394 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6396 di = get_info (tree_view);
6401 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
6404 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6407 path = get_logical_dest_row (tree_view, &path_down_mode, &drop_append_mode);
6409 if (target != GDK_NONE && path != NULL)
6411 /* in case a motion had requested drag data, change things so we
6412 * treat drag data receives as a drop.
6414 set_status_pending (context, 0);
6415 set_dest_row (context, model, path,
6416 path_down_mode, tree_view->priv->empty_view_drop,
6421 gtk_tree_path_free (path);
6423 /* Unset this thing */
6424 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6426 PSPP_SHEET_VIEW_DROP_BEFORE);
6428 if (target != GDK_NONE)
6430 gtk_drag_get_data (widget, context, target, time);
6438 pspp_sheet_view_drag_data_received (GtkWidget *widget,
6439 GdkDragContext *context,
6440 /* coordinates relative to the widget */
6443 GtkSelectionData *selection_data,
6448 TreeViewDragInfo *di;
6449 gboolean accepted = FALSE;
6450 GtkTreeModel *model;
6451 PsppSheetView *tree_view;
6452 GtkTreePath *dest_row;
6453 GdkDragAction suggested_action;
6454 gboolean path_down_mode;
6455 gboolean drop_append_mode;
6457 tree_view = PSPP_SHEET_VIEW (widget);
6459 model = pspp_sheet_view_get_model (tree_view);
6461 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_data_received"))
6464 di = get_info (tree_view);
6469 suggested_action = get_status_pending (context);
6471 if (suggested_action)
6473 /* We are getting this data due to a request in drag_motion,
6474 * rather than due to a request in drag_drop, so we are just
6475 * supposed to call drag_status, not actually paste in the
6478 path = get_logical_dest_row (tree_view, &path_down_mode,
6482 suggested_action = 0;
6483 else if (path_down_mode)
6484 gtk_tree_path_down (path);
6486 if (suggested_action)
6488 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6494 path_down_mode = FALSE;
6495 gtk_tree_path_up (path);
6497 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6500 suggested_action = 0;
6503 suggested_action = 0;
6507 gdk_drag_status (context, suggested_action, time);
6510 gtk_tree_path_free (path);
6512 /* If you can't drop, remove user drop indicator until the next motion */
6513 if (suggested_action == 0)
6514 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6516 PSPP_SHEET_VIEW_DROP_BEFORE);
6521 dest_row = get_dest_row (context, &path_down_mode);
6523 if (dest_row == NULL)
6526 if (gtk_selection_data_get_length (selection_data) >= 0)
6530 gtk_tree_path_down (dest_row);
6531 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6532 dest_row, selection_data))
6533 gtk_tree_path_up (dest_row);
6537 if (gtk_selection_data_get_length (selection_data) >= 0)
6539 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6545 gtk_drag_finish (context,
6547 (gdk_drag_context_get_actions (context) == GDK_ACTION_MOVE),
6550 if (gtk_tree_path_get_depth (dest_row) == 1
6551 && gtk_tree_path_get_indices (dest_row)[0] == 0)
6553 /* special special case drag to "0", scroll to first item */
6554 if (!tree_view->priv->scroll_to_path)
6555 pspp_sheet_view_scroll_to_cell (tree_view, dest_row, NULL, FALSE, 0.0, 0.0);
6558 gtk_tree_path_free (dest_row);
6561 set_dest_row (context, NULL, NULL, FALSE, FALSE, FALSE);
6566 /* GtkContainer Methods
6571 pspp_sheet_view_remove (GtkContainer *container,
6574 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6575 PsppSheetViewChild *child = NULL;
6578 tmp_list = tree_view->priv->children;
6581 child = tmp_list->data;
6582 if (child->widget == widget)
6584 gtk_widget_unparent (widget);
6586 tree_view->priv->children = g_list_remove_link (tree_view->priv->children, tmp_list);
6587 g_list_free_1 (tmp_list);
6588 g_slice_free (PsppSheetViewChild, child);
6592 tmp_list = tmp_list->next;
6595 tmp_list = tree_view->priv->columns;
6599 PsppSheetViewColumn *column;
6600 column = tmp_list->data;
6601 if (column->button == widget)
6603 gtk_widget_unparent (widget);
6606 tmp_list = tmp_list->next;
6611 pspp_sheet_view_forall (GtkContainer *container,
6612 gboolean include_internals,
6613 GtkCallback callback,
6614 gpointer callback_data)
6616 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6617 PsppSheetViewChild *child = NULL;
6618 PsppSheetViewColumn *column;
6621 tmp_list = tree_view->priv->children;
6624 child = tmp_list->data;
6625 tmp_list = tmp_list->next;
6627 (* callback) (child->widget, callback_data);
6629 if (include_internals == FALSE)
6632 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6634 column = tmp_list->data;
6637 (* callback) (column->button, callback_data);
6641 /* Returns TRUE if the treeview contains no "special" (editable or activatable)
6642 * cells. If so we draw one big row-spanning focus rectangle.
6645 pspp_sheet_view_has_special_cell (PsppSheetView *tree_view)
6649 if (tree_view->priv->special_cells != PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT)
6650 return tree_view->priv->special_cells = PSPP_SHEET_VIEW_SPECIAL_CELLS_YES;
6652 for (list = tree_view->priv->columns; list; list = list->next)
6654 if (!((PsppSheetViewColumn *)list->data)->visible)
6656 if (_pspp_sheet_view_column_count_special_cells (list->data))
6664 pspp_sheet_view_focus_column (PsppSheetView *tree_view,
6665 PsppSheetViewColumn *focus_column,
6666 gboolean clamp_column_visible)
6668 g_return_if_fail (focus_column != NULL);
6670 tree_view->priv->focus_column = focus_column;
6671 if (!focus_column->button)
6673 pspp_sheet_view_column_set_need_button (focus_column, TRUE);
6674 // g_return_if_fail (focus_column->button != NULL);
6675 if (focus_column->button == NULL)
6679 if (gtk_container_get_focus_child (GTK_CONTAINER (tree_view)) != focus_column->button)
6680 gtk_widget_grab_focus (focus_column->button);
6682 if (clamp_column_visible)
6683 pspp_sheet_view_clamp_column_visible (tree_view, focus_column, FALSE);
6686 /* Returns TRUE if the focus is within the headers, after the focus operation is
6690 pspp_sheet_view_header_focus (PsppSheetView *tree_view,
6691 GtkDirectionType dir,
6692 gboolean clamp_column_visible)
6694 GtkWidget *focus_child;
6695 PsppSheetViewColumn *focus_column;
6696 GList *last_column, *first_column;
6700 if (! PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
6703 focus_child = gtk_container_get_focus_child (GTK_CONTAINER (tree_view));
6705 first_column = tree_view->priv->columns;
6706 while (first_column)
6708 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (first_column->data);
6710 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6712 first_column = first_column->next;
6715 /* No headers are visible, or are focusable. We can't focus in or out.
6717 if (first_column == NULL)
6720 last_column = g_list_last (tree_view->priv->columns);
6723 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (last_column->data);
6725 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6727 last_column = last_column->prev;
6731 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
6735 case GTK_DIR_TAB_BACKWARD:
6736 case GTK_DIR_TAB_FORWARD:
6739 if (focus_child == NULL)
6741 if (tree_view->priv->focus_column != NULL &&
6742 pspp_sheet_view_column_can_focus (tree_view->priv->focus_column))
6743 focus_column = tree_view->priv->focus_column;
6745 focus_column = first_column->data;
6746 pspp_sheet_view_focus_column (tree_view, focus_column,
6747 clamp_column_visible);
6754 if (focus_child == NULL)
6756 if (tree_view->priv->focus_column != NULL)
6757 focus_column = tree_view->priv->focus_column;
6758 else if (dir == GTK_DIR_LEFT)
6759 focus_column = last_column->data;
6761 focus_column = first_column->data;
6762 pspp_sheet_view_focus_column (tree_view, focus_column,
6763 clamp_column_visible);
6767 if (gtk_widget_child_focus (focus_child, dir))
6769 /* The focus moves inside the button. */
6770 /* This is probably a great example of bad UI */
6771 if (clamp_column_visible)
6772 pspp_sheet_view_clamp_column_visible (tree_view,
6773 tree_view->priv->focus_column,
6778 /* We need to move the focus among the row of buttons. */
6779 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6780 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)->button == focus_child)
6783 if ((tmp_list == first_column && dir == (rtl ? GTK_DIR_RIGHT : GTK_DIR_LEFT))
6784 || (tmp_list == last_column && dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT)))
6786 gtk_widget_error_bell (GTK_WIDGET (tree_view));
6792 PsppSheetViewColumn *column;
6794 if (dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT))
6795 tmp_list = tmp_list->next;
6797 tmp_list = tmp_list->prev;
6799 if (tmp_list == NULL)
6801 g_warning ("Internal button not found");
6804 column = tmp_list->data;
6805 if (column->visible &&
6806 pspp_sheet_view_column_can_focus (column))
6808 pspp_sheet_view_column_set_need_button (column, TRUE);
6811 pspp_sheet_view_focus_column (tree_view, column,
6812 clamp_column_visible);
6820 g_assert_not_reached ();
6827 /* This function returns in 'path' the first focusable path, if the given path
6828 * is already focusable, it's the returned one.
6832 search_first_focusable_path (PsppSheetView *tree_view,
6834 gboolean search_forward,
6837 /* XXX this function is trivial given that the sheetview doesn't support
6841 if (!path || !*path)
6844 _pspp_sheet_view_find_node (tree_view, *path, &node);
6852 return (*path != NULL);
6856 pspp_sheet_view_focus (GtkWidget *widget,
6857 GtkDirectionType direction)
6859 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6860 GtkContainer *container = GTK_CONTAINER (widget);
6861 GtkWidget *focus_child;
6863 if (!gtk_widget_is_sensitive (widget) || !gtk_widget_get_can_focus (widget))
6866 focus_child = gtk_container_get_focus_child (container);
6868 pspp_sheet_view_stop_editing (PSPP_SHEET_VIEW (widget), FALSE);
6869 /* Case 1. Headers currently have focus. */
6876 pspp_sheet_view_header_focus (tree_view, direction, TRUE);
6878 case GTK_DIR_TAB_BACKWARD:
6881 case GTK_DIR_TAB_FORWARD:
6883 gtk_widget_grab_focus (widget);
6886 g_assert_not_reached ();
6891 /* Case 2. We don't have focus at all. */
6892 if (!gtk_widget_has_focus (widget))
6894 if (!pspp_sheet_view_header_focus (tree_view, direction, FALSE))
6895 gtk_widget_grab_focus (widget);
6899 /* Case 3. We have focus already. */
6900 if (direction == GTK_DIR_TAB_BACKWARD)
6901 return (pspp_sheet_view_header_focus (tree_view, direction, FALSE));
6902 else if (direction == GTK_DIR_TAB_FORWARD)
6905 /* Other directions caught by the keybindings */
6906 gtk_widget_grab_focus (widget);
6911 pspp_sheet_view_grab_focus (GtkWidget *widget)
6913 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->grab_focus (widget);
6915 pspp_sheet_view_focus_to_cursor (PSPP_SHEET_VIEW (widget));
6919 pspp_sheet_view_style_set (GtkWidget *widget,
6920 GtkStyle *previous_style)
6922 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6924 PsppSheetViewColumn *column;
6926 if (gtk_widget_get_realized (widget))
6928 gdk_window_set_background (tree_view->priv->bin_window, >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
6929 gtk_style_set_background (gtk_widget_get_style (widget), tree_view->priv->header_window, GTK_STATE_NORMAL);
6930 pspp_sheet_view_set_grid_lines (tree_view, tree_view->priv->grid_lines);
6933 gtk_widget_style_get (widget,
6934 "expander-size", &tree_view->priv->expander_size,
6936 tree_view->priv->expander_size += EXPANDER_EXTRA_PADDING;
6938 for (list = tree_view->priv->columns; list; list = list->next)
6940 column = list->data;
6941 _pspp_sheet_view_column_cell_set_dirty (column);
6944 tree_view->priv->fixed_height = -1;
6946 /* Invalidate cached button style. */
6947 if (tree_view->priv->button_style)
6949 g_object_unref (tree_view->priv->button_style);
6950 tree_view->priv->button_style = NULL;
6953 gtk_widget_queue_resize (widget);
6958 pspp_sheet_view_set_focus_child (GtkContainer *container,
6961 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6964 for (list = tree_view->priv->columns; list; list = list->next)
6966 if (PSPP_SHEET_VIEW_COLUMN (list->data)->button == child)
6968 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
6973 GTK_CONTAINER_CLASS (pspp_sheet_view_parent_class)->set_focus_child (container, child);
6977 pspp_sheet_view_set_adjustments (PsppSheetView *tree_view,
6978 GtkAdjustment *hadj,
6979 GtkAdjustment *vadj)
6981 gboolean need_adjust = FALSE;
6983 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
6986 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
6988 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
6990 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
6992 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
6994 if (tree_view->priv->hadjustment && (tree_view->priv->hadjustment != hadj))
6996 g_signal_handlers_disconnect_by_func (tree_view->priv->hadjustment,
6997 pspp_sheet_view_adjustment_changed,
6999 g_object_unref (tree_view->priv->hadjustment);
7002 if (tree_view->priv->vadjustment && (tree_view->priv->vadjustment != vadj))
7004 g_signal_handlers_disconnect_by_func (tree_view->priv->vadjustment,
7005 pspp_sheet_view_adjustment_changed,
7007 g_object_unref (tree_view->priv->vadjustment);
7010 if (tree_view->priv->hadjustment != hadj)
7012 tree_view->priv->hadjustment = hadj;
7013 g_object_ref_sink (tree_view->priv->hadjustment);
7015 g_signal_connect (tree_view->priv->hadjustment, "value-changed",
7016 G_CALLBACK (pspp_sheet_view_adjustment_changed),
7021 if (tree_view->priv->vadjustment != vadj)
7023 tree_view->priv->vadjustment = vadj;
7024 g_object_ref_sink (tree_view->priv->vadjustment);
7026 g_signal_connect (tree_view->priv->vadjustment, "value-changed",
7027 G_CALLBACK (pspp_sheet_view_adjustment_changed),
7033 pspp_sheet_view_adjustment_changed (NULL, tree_view);
7038 pspp_sheet_view_real_move_cursor (PsppSheetView *tree_view,
7039 GtkMovementStep step,
7042 PsppSheetSelectMode mode;
7043 GdkModifierType state;
7045 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
7046 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
7047 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
7048 step == GTK_MOVEMENT_DISPLAY_LINES ||
7049 step == GTK_MOVEMENT_PAGES ||
7050 step == GTK_MOVEMENT_BUFFER_ENDS ||
7051 step == GTK_MOVEMENT_DISPLAY_LINE_ENDS, FALSE);
7053 if (tree_view->priv->row_count == 0)
7055 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7058 pspp_sheet_view_stop_editing (tree_view, FALSE);
7059 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
7060 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7063 if (gtk_get_current_event_state (&state))
7065 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
7066 mode |= PSPP_SHEET_SELECT_MODE_TOGGLE;
7067 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
7068 mode |= PSPP_SHEET_SELECT_MODE_EXTEND;
7070 /* else we assume not pressed */
7074 case GTK_MOVEMENT_LOGICAL_POSITIONS:
7075 pspp_sheet_view_move_cursor_tab (tree_view, count);
7077 case GTK_MOVEMENT_VISUAL_POSITIONS:
7078 pspp_sheet_view_move_cursor_left_right (tree_view, count, mode);
7080 case GTK_MOVEMENT_DISPLAY_LINES:
7081 pspp_sheet_view_move_cursor_up_down (tree_view, count, mode);
7083 case GTK_MOVEMENT_PAGES:
7084 pspp_sheet_view_move_cursor_page_up_down (tree_view, count, mode);
7086 case GTK_MOVEMENT_BUFFER_ENDS:
7087 pspp_sheet_view_move_cursor_start_end (tree_view, count, mode);
7089 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
7090 pspp_sheet_view_move_cursor_line_start_end (tree_view, count, mode);
7093 g_assert_not_reached ();
7100 pspp_sheet_view_put (PsppSheetView *tree_view,
7101 GtkWidget *child_widget,
7102 /* in bin_window coordinates */
7108 PsppSheetViewChild *child;
7110 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
7111 g_return_if_fail (GTK_IS_WIDGET (child_widget));
7113 child = g_slice_new (PsppSheetViewChild);
7115 child->widget = child_widget;
7118 child->width = width;
7119 child->height = height;
7121 tree_view->priv->children = g_list_append (tree_view->priv->children, child);
7123 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7124 gtk_widget_set_parent_window (child->widget, tree_view->priv->bin_window);
7126 gtk_widget_set_parent (child_widget, GTK_WIDGET (tree_view));
7130 _pspp_sheet_view_child_move_resize (PsppSheetView *tree_view,
7132 /* in tree coordinates */
7138 PsppSheetViewChild *child = NULL;
7140 GdkRectangle allocation;
7142 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
7143 g_return_if_fail (GTK_IS_WIDGET (widget));
7145 for (list = tree_view->priv->children; list; list = list->next)
7147 if (((PsppSheetViewChild *)list->data)->widget == widget)
7156 allocation.x = child->x = x;
7157 allocation.y = child->y = y;
7158 allocation.width = child->width = width;
7159 allocation.height = child->height = height;
7161 if (gtk_widget_get_realized (widget))
7162 gtk_widget_size_allocate (widget, &allocation);
7166 /* TreeModel Callbacks
7170 pspp_sheet_view_row_changed (GtkTreeModel *model,
7175 PsppSheetView *tree_view = (PsppSheetView *)data;
7177 gboolean free_path = FALSE;
7178 GtkTreePath *cursor_path;
7180 g_return_if_fail (path != NULL || iter != NULL);
7182 if (tree_view->priv->cursor != NULL)
7183 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7187 if (tree_view->priv->edited_column &&
7188 (cursor_path == NULL || gtk_tree_path_compare (cursor_path, path) == 0))
7189 pspp_sheet_view_stop_editing (tree_view, TRUE);
7191 if (cursor_path != NULL)
7192 gtk_tree_path_free (cursor_path);
7196 path = gtk_tree_model_get_path (model, iter);
7199 else if (iter == NULL)
7200 gtk_tree_model_get_iter (model, iter, path);
7202 _pspp_sheet_view_find_node (tree_view,
7208 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7209 pspp_sheet_view_node_queue_redraw (tree_view, node);
7213 gtk_tree_path_free (path);
7217 pspp_sheet_view_row_inserted (GtkTreeModel *model,
7222 PsppSheetView *tree_view = (PsppSheetView *) data;
7225 gint height = tree_view->priv->fixed_height;
7226 gboolean free_path = FALSE;
7227 gboolean node_visible = TRUE;
7229 g_return_if_fail (path != NULL || iter != NULL);
7233 path = gtk_tree_model_get_path (model, iter);
7236 else if (iter == NULL)
7237 gtk_tree_model_get_iter (model, iter, path);
7239 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7241 /* Update all row-references */
7242 gtk_tree_row_reference_inserted (G_OBJECT (data), path);
7243 indices = gtk_tree_path_get_indices (path);
7244 tmpnode = indices[0];
7246 range_tower_insert0 (tree_view->priv->selected, tmpnode, 1);
7250 if (node_visible && node_is_visible (tree_view, tmpnode))
7251 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7253 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (tree_view));
7256 install_presize_handler (tree_view);
7258 gtk_tree_path_free (path);
7262 pspp_sheet_view_row_deleted (GtkTreeModel *model,
7266 PsppSheetView *tree_view = (PsppSheetView *)data;
7269 g_return_if_fail (path != NULL);
7271 gtk_tree_row_reference_deleted (G_OBJECT (data), path);
7273 _pspp_sheet_view_find_node (tree_view, path, &node);
7278 range_tower_delete (tree_view->priv->selected, node, 1);
7280 /* Ensure we don't have a dangling pointer to a dead node */
7281 ensure_unprelighted (tree_view);
7283 /* Cancel editting if we've started */
7284 pspp_sheet_view_stop_editing (tree_view, TRUE);
7286 if (tree_view->priv->destroy_count_func)
7288 gint child_count = 0;
7289 tree_view->priv->destroy_count_func (tree_view, path, child_count, tree_view->priv->destroy_count_data);
7292 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7294 if (! gtk_tree_row_reference_valid (tree_view->priv->top_row))
7296 gtk_tree_row_reference_free (tree_view->priv->top_row);
7297 tree_view->priv->top_row = NULL;
7300 install_scroll_sync_handler (tree_view);
7302 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7305 if (helper_data.changed)
7306 g_signal_emit_by_name (tree_view->priv->selection, "changed");
7311 pspp_sheet_view_rows_reordered (GtkTreeModel *model,
7312 GtkTreePath *parent,
7317 PsppSheetView *tree_view = PSPP_SHEET_VIEW (data);
7320 /* XXX need to adjust selection */
7321 len = gtk_tree_model_iter_n_children (model, iter);
7326 gtk_tree_row_reference_reordered (G_OBJECT (data),
7331 if (gtk_tree_path_get_depth (parent) != 0)
7334 if (tree_view->priv->edited_column)
7335 pspp_sheet_view_stop_editing (tree_view, TRUE);
7337 /* we need to be unprelighted */
7338 ensure_unprelighted (tree_view);
7340 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
7342 pspp_sheet_view_dy_to_top_row (tree_view);
7346 /* Internal tree functions
7351 pspp_sheet_view_get_background_xrange (PsppSheetView *tree_view,
7352 PsppSheetViewColumn *column,
7356 PsppSheetViewColumn *tmp_column = NULL;
7367 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7370 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
7372 list = (rtl ? list->prev : list->next))
7374 tmp_column = list->data;
7376 if (tmp_column == column)
7379 if (tmp_column->visible)
7380 total_width += tmp_column->width;
7383 if (tmp_column != column)
7385 g_warning (G_STRLOC": passed-in column isn't in the tree");
7394 if (column->visible)
7395 *x2 = total_width + column->width;
7397 *x2 = total_width; /* width of 0 */
7401 /* Make sure the node is visible vertically */
7403 pspp_sheet_view_clamp_node_visible (PsppSheetView *tree_view,
7406 gint node_dy, height;
7407 GtkTreePath *path = NULL;
7409 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7412 /* just return if the node is visible, avoiding a costly expose */
7413 node_dy = pspp_sheet_view_node_find_offset (tree_view, node);
7414 height = ROW_HEIGHT (tree_view);
7415 if (node_dy >= gtk_adjustment_get_value (tree_view->priv->vadjustment)
7416 && node_dy + height <= (gtk_adjustment_get_value (tree_view->priv->vadjustment)
7417 + gtk_adjustment_get_page_size (tree_view->priv->vadjustment)))
7420 path = _pspp_sheet_view_find_path (tree_view, node);
7423 /* We process updates because we want to clear old selected items when we scroll.
7424 * if this is removed, we get a "selection streak" at the bottom. */
7425 gdk_window_process_updates (tree_view->priv->bin_window, TRUE);
7426 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL, FALSE, 0.0, 0.0);
7427 gtk_tree_path_free (path);
7432 pspp_sheet_view_clamp_column_visible (PsppSheetView *tree_view,
7433 PsppSheetViewColumn *column,
7434 gboolean focus_to_cell)
7441 x = column->allocation.x;
7442 width = column->allocation.width;
7444 if (width > gtk_adjustment_get_page_size (tree_view->priv->hadjustment))
7446 /* The column is larger than the horizontal page size. If the
7447 * column has cells which can be focussed individually, then we make
7448 * sure the cell which gets focus is fully visible (if even the
7449 * focus cell is bigger than the page size, we make sure the
7450 * left-hand side of the cell is visible).
7452 * If the column does not have those so-called special cells, we
7453 * make sure the left-hand side of the column is visible.
7456 if (focus_to_cell && pspp_sheet_view_has_special_cell (tree_view))
7458 GtkTreePath *cursor_path;
7459 GdkRectangle background_area, cell_area, focus_area;
7461 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7463 pspp_sheet_view_get_cell_area (tree_view,
7464 cursor_path, column, &cell_area);
7465 pspp_sheet_view_get_background_area (tree_view,
7466 cursor_path, column,
7469 gtk_tree_path_free (cursor_path);
7471 _pspp_sheet_view_column_get_focus_area (column,
7477 width = focus_area.width;
7479 if (width < gtk_adjustment_get_page_size (tree_view->priv->hadjustment))
7481 if ((gtk_adjustment_get_value (tree_view->priv->hadjustment) + gtk_adjustment_get_page_size (tree_view->priv->hadjustment)) < (x + width))
7482 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7483 x + width - gtk_adjustment_get_page_size (tree_view->priv->hadjustment));
7484 else if (gtk_adjustment_get_value (tree_view->priv->hadjustment) > x)
7485 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7489 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7491 gtk_adjustment_get_lower (tree_view->priv->hadjustment),
7492 gtk_adjustment_get_upper (tree_view->priv->hadjustment)
7493 - gtk_adjustment_get_page_size (tree_view->priv->hadjustment)));
7497 if ((gtk_adjustment_get_value (tree_view->priv->hadjustment) + gtk_adjustment_get_page_size (tree_view->priv->hadjustment)) < (x + width))
7498 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7499 x + width - gtk_adjustment_get_page_size (tree_view->priv->hadjustment));
7500 else if (gtk_adjustment_get_value (tree_view->priv->hadjustment) > x)
7501 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7506 _pspp_sheet_view_find_path (PsppSheetView *tree_view,
7511 path = gtk_tree_path_new ();
7513 gtk_tree_path_append_index (path, node);
7518 _pspp_sheet_view_find_node (PsppSheetView *tree_view,
7522 gint *indices = gtk_tree_path_get_indices (path);
7523 gint depth = gtk_tree_path_get_depth (path);
7526 if (depth == 0 || indices[0] < 0 || indices[0] >= tree_view->priv->row_count)
7532 pspp_sheet_view_add_move_binding (GtkBindingSet *binding_set,
7535 gboolean add_shifted_binding,
7536 GtkMovementStep step,
7540 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
7545 if (add_shifted_binding)
7546 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
7551 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
7554 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
7559 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
7566 pspp_sheet_view_set_column_drag_info (PsppSheetView *tree_view,
7567 PsppSheetViewColumn *column)
7569 PsppSheetViewColumn *left_column;
7570 PsppSheetViewColumn *cur_column = NULL;
7571 PsppSheetViewColumnReorder *reorder;
7576 /* We want to precalculate the motion list such that we know what column slots
7580 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7582 /* First, identify all possible drop spots */
7584 tmp_list = g_list_last (tree_view->priv->columns);
7586 tmp_list = g_list_first (tree_view->priv->columns);
7590 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
7591 tmp_list = rtl?g_list_previous (tmp_list):g_list_next (tmp_list);
7593 if (cur_column->visible == FALSE)
7596 /* If it's not the column moving and func tells us to skip over the column, we continue. */
7597 if (left_column != column && cur_column != column &&
7598 tree_view->priv->column_drop_func &&
7599 ! tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
7601 left_column = cur_column;
7604 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7605 reorder->left_column = left_column;
7606 left_column = reorder->right_column = cur_column;
7608 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7611 /* Add the last one */
7612 if (tree_view->priv->column_drop_func == NULL ||
7613 ((left_column != column) &&
7614 tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data)))
7616 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7617 reorder->left_column = left_column;
7618 reorder->right_column = NULL;
7619 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7622 /* We quickly check to see if it even makes sense to reorder columns. */
7623 /* If there is nothing that can be moved, then we return */
7625 if (tree_view->priv->column_drag_info == NULL)
7628 /* We know there are always 2 slots possbile, as you can always return column. */
7629 /* If that's all there is, return */
7630 if (tree_view->priv->column_drag_info->next == NULL ||
7631 (tree_view->priv->column_drag_info->next->next == NULL &&
7632 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->data)->right_column == column &&
7633 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->next->data)->left_column == column))
7635 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7636 g_slice_free (PsppSheetViewColumnReorder, tmp_list->data);
7637 g_list_free (tree_view->priv->column_drag_info);
7638 tree_view->priv->column_drag_info = NULL;
7641 /* We fill in the ranges for the columns, now that we've isolated them */
7642 left = - TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7644 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7646 reorder = (PsppSheetViewColumnReorder *) tmp_list->data;
7648 reorder->left_align = left;
7649 if (tmp_list->next != NULL)
7651 g_assert (tmp_list->next->data);
7652 left = reorder->right_align = (reorder->right_column->allocation.x +
7653 reorder->right_column->allocation.width +
7654 ((PsppSheetViewColumnReorder *)tmp_list->next->data)->left_column->allocation.x)/2;
7658 gint width = gdk_window_get_width (tree_view->priv->header_window);
7659 reorder->right_align = width + TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7665 _pspp_sheet_view_column_start_drag (PsppSheetView *tree_view,
7666 PsppSheetViewColumn *column)
7668 GdkEvent *send_event;
7669 GtkAllocation allocation;
7671 GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
7672 GdkDisplay *display = gdk_screen_get_display (screen);
7674 g_return_if_fail (tree_view->priv->column_drag_info == NULL);
7675 g_return_if_fail (tree_view->priv->cur_reorder == NULL);
7676 g_return_if_fail (column->button);
7678 pspp_sheet_view_set_column_drag_info (tree_view, column);
7680 if (tree_view->priv->column_drag_info == NULL)
7683 if (tree_view->priv->drag_window == NULL)
7685 GdkWindowAttr attributes;
7686 guint attributes_mask;
7688 attributes.window_type = GDK_WINDOW_CHILD;
7689 attributes.wclass = GDK_INPUT_OUTPUT;
7690 attributes.x = column->allocation.x;
7692 attributes.width = column->allocation.width;
7693 attributes.height = column->allocation.height;
7694 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
7695 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
7696 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL ;
7698 tree_view->priv->drag_window = gdk_window_new (tree_view->priv->bin_window,
7701 gdk_window_set_user_data (tree_view->priv->drag_window, GTK_WIDGET (tree_view));
7704 gdk_display_pointer_ungrab (display, GDK_CURRENT_TIME);
7705 gdk_display_keyboard_ungrab (display, GDK_CURRENT_TIME);
7707 gtk_grab_remove (column->button);
7709 send_event = gdk_event_new (GDK_LEAVE_NOTIFY);
7710 send_event->crossing.send_event = TRUE;
7711 send_event->crossing.window = g_object_ref (gtk_button_get_event_window (GTK_BUTTON (column->button)));
7712 send_event->crossing.subwindow = NULL;
7713 send_event->crossing.detail = GDK_NOTIFY_ANCESTOR;
7714 send_event->crossing.time = GDK_CURRENT_TIME;
7716 gtk_propagate_event (column->button, send_event);
7717 gdk_event_free (send_event);
7719 send_event = gdk_event_new (GDK_BUTTON_RELEASE);
7720 send_event->button.window = g_object_ref (gdk_screen_get_root_window (screen));
7721 send_event->button.send_event = TRUE;
7722 send_event->button.time = GDK_CURRENT_TIME;
7723 send_event->button.x = -1;
7724 send_event->button.y = -1;
7725 send_event->button.axes = NULL;
7726 send_event->button.state = 0;
7727 send_event->button.button = 1;
7728 send_event->button.device =
7729 gdk_device_manager_get_client_pointer (gdk_display_get_device_manager (display));
7731 send_event->button.x_root = 0;
7732 send_event->button.y_root = 0;
7734 gtk_propagate_event (column->button, send_event);
7735 gdk_event_free (send_event);
7737 /* Kids, don't try this at home */
7738 g_object_ref (column->button);
7739 gtk_container_remove (GTK_CONTAINER (tree_view), column->button);
7740 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7741 gtk_widget_set_parent (column->button, GTK_WIDGET (tree_view));
7742 g_object_unref (column->button);
7744 tree_view->priv->drag_column_x = column->allocation.x;
7745 allocation = column->allocation;
7747 gtk_widget_size_allocate (column->button, &allocation);
7748 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7750 tree_view->priv->drag_column = column;
7751 gdk_window_show (tree_view->priv->drag_window);
7753 gdk_window_get_origin (tree_view->priv->header_window, &x, &y);
7755 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7756 while (gtk_events_pending ())
7757 gtk_main_iteration ();
7759 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG);
7760 gdk_pointer_grab (tree_view->priv->drag_window,
7762 GDK_POINTER_MOTION_MASK|GDK_BUTTON_RELEASE_MASK,
7763 NULL, NULL, GDK_CURRENT_TIME);
7764 gdk_keyboard_grab (tree_view->priv->drag_window,
7770 _pspp_sheet_view_queue_draw_node (PsppSheetView *tree_view,
7772 const GdkRectangle *clip_rect)
7775 GtkAllocation allocation;
7777 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7780 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
7782 rect.width = MAX (tree_view->priv->width, allocation.width);
7784 rect.y = BACKGROUND_FIRST_PIXEL (tree_view, node);
7785 rect.height = ROW_HEIGHT (tree_view);
7789 GdkRectangle new_rect;
7791 gdk_rectangle_intersect (clip_rect, &rect, &new_rect);
7793 gdk_window_invalidate_rect (tree_view->priv->bin_window, &new_rect, TRUE);
7797 gdk_window_invalidate_rect (tree_view->priv->bin_window, &rect, TRUE);
7802 pspp_sheet_view_queue_draw_path (PsppSheetView *tree_view,
7804 const GdkRectangle *clip_rect)
7808 _pspp_sheet_view_find_node (tree_view, path, &node);
7811 _pspp_sheet_view_queue_draw_node (tree_view, node, clip_rect);
7815 pspp_sheet_view_focus_to_cursor (PsppSheetView *tree_view)
7818 GtkTreePath *cursor_path;
7820 if ((tree_view->priv->row_count == 0) ||
7821 (! gtk_widget_get_realized (GTK_WIDGET (tree_view))))
7825 if (tree_view->priv->cursor)
7826 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7828 if (cursor_path == NULL)
7830 /* There's no cursor. Move the cursor to the first selected row, if any
7831 * are selected, otherwise to the first row in the sheetview.
7833 GList *selected_rows;
7834 GtkTreeModel *model;
7835 PsppSheetSelection *selection;
7837 selection = pspp_sheet_view_get_selection (tree_view);
7838 selected_rows = pspp_sheet_selection_get_selected_rows (selection, &model);
7842 /* XXX we could avoid doing O(n) work to get this result */
7843 cursor_path = gtk_tree_path_copy((const GtkTreePath *)(selected_rows->data));
7844 g_list_foreach (selected_rows, (GFunc)gtk_tree_path_free, NULL);
7845 g_list_free (selected_rows);
7849 cursor_path = gtk_tree_path_new_first ();
7850 search_first_focusable_path (tree_view, &cursor_path,
7854 gtk_tree_row_reference_free (tree_view->priv->cursor);
7855 tree_view->priv->cursor = NULL;
7859 if (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7860 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE)
7861 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, FALSE, FALSE, 0);
7863 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE, 0);
7869 /* Now find a column for the cursor. */
7870 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
7872 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
7873 gtk_tree_path_free (cursor_path);
7875 if (tree_view->priv->focus_column == NULL)
7878 for (list = tree_view->priv->columns; list; list = list->next)
7880 if (PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
7882 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
7883 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
7884 pspp_sheet_selection_select_column (tree_view->priv->selection, tree_view->priv->focus_column);
7894 pspp_sheet_view_move_cursor_up_down (PsppSheetView *tree_view,
7896 PsppSheetSelectMode mode)
7898 gint selection_count;
7899 int cursor_node = -1;
7900 int new_cursor_node = -1;
7901 GtkTreePath *cursor_path = NULL;
7902 gboolean grab_focus = TRUE;
7904 if (! gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7908 if (!gtk_tree_row_reference_valid (tree_view->priv->cursor))
7909 /* FIXME: we lost the cursor; should we get the first? */
7912 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7913 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
7915 if (cursor_node < 0)
7916 /* FIXME: we lost the cursor; should we get the first? */
7919 selection_count = pspp_sheet_selection_count_selected_rows (tree_view->priv->selection);
7921 if (selection_count == 0
7922 && tree_view->priv->selection->type != PSPP_SHEET_SELECTION_NONE
7923 && !(mode & PSPP_SHEET_SELECT_MODE_TOGGLE))
7925 /* Don't move the cursor, but just select the current node */
7926 new_cursor_node = cursor_node;
7931 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
7933 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7936 gtk_tree_path_free (cursor_path);
7938 if (new_cursor_node)
7940 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
7942 search_first_focusable_path (tree_view, &cursor_path,
7947 gtk_tree_path_free (cursor_path);
7951 * If the list has only one item and multi-selection is set then select
7952 * the row (if not yet selected).
7954 if ((tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7955 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE) &&
7956 new_cursor_node < 0)
7959 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7961 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
7963 if (new_cursor_node < 0
7964 && !pspp_sheet_view_node_is_selected (tree_view, cursor_node))
7966 new_cursor_node = cursor_node;
7970 new_cursor_node = -1;
7974 if (new_cursor_node >= 0)
7976 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
7977 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, TRUE, mode);
7978 gtk_tree_path_free (cursor_path);
7982 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
7984 if (!(mode & PSPP_SHEET_SELECT_MODE_EXTEND))
7986 if (! gtk_widget_keynav_failed (GTK_WIDGET (tree_view),
7988 GTK_DIR_UP : GTK_DIR_DOWN))
7990 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
7993 gtk_widget_child_focus (toplevel,
7995 GTK_DIR_TAB_BACKWARD :
7996 GTK_DIR_TAB_FORWARD);
8003 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8008 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8010 return new_cursor_node >= 0;
8014 pspp_sheet_view_move_cursor_page_up_down (PsppSheetView *tree_view,
8016 PsppSheetSelectMode mode)
8018 int cursor_node = -1;
8019 GtkTreePath *old_cursor_path = NULL;
8020 GtkTreePath *cursor_path = NULL;
8021 int start_cursor_node = -1;
8024 gint vertical_separator;
8026 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8029 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8030 old_cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8032 /* This is sorta weird. Focus in should give us a cursor */
8035 gtk_widget_style_get (GTK_WIDGET (tree_view), "vertical-separator", &vertical_separator, NULL);
8036 _pspp_sheet_view_find_node (tree_view, old_cursor_path, &cursor_node);
8038 if (cursor_node < 0)
8040 /* FIXME: we lost the cursor. Should we try to get one? */
8041 gtk_tree_path_free (old_cursor_path);
8045 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
8046 window_y = RBTREE_Y_TO_TREE_WINDOW_Y (tree_view, y);
8047 y += tree_view->priv->cursor_offset;
8048 y += count * (int)gtk_adjustment_get_page_increment (tree_view->priv->vadjustment);
8049 y = CLAMP (y, (gint)gtk_adjustment_get_lower (tree_view->priv->vadjustment), (gint)gtk_adjustment_get_upper (tree_view->priv->vadjustment) - vertical_separator);
8051 if (y >= tree_view->priv->height)
8052 y = tree_view->priv->height - 1;
8054 tree_view->priv->cursor_offset =
8055 pspp_sheet_view_find_offset (tree_view, y, &cursor_node);
8057 if (tree_view->priv->cursor_offset > BACKGROUND_HEIGHT (tree_view))
8059 cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
8060 tree_view->priv->cursor_offset -= BACKGROUND_HEIGHT (tree_view);
8063 y -= tree_view->priv->cursor_offset;
8064 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
8066 start_cursor_node = cursor_node;
8068 if (! search_first_focusable_path (tree_view, &cursor_path,
8072 /* It looks like we reached the end of the view without finding
8073 * a focusable row. We will step backwards to find the last
8076 cursor_node = start_cursor_node;
8077 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
8079 search_first_focusable_path (tree_view, &cursor_path,
8088 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
8090 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE, mode);
8093 pspp_sheet_view_scroll_to_point (tree_view, -1, y);
8094 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8095 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8097 if (!gtk_tree_path_compare (old_cursor_path, cursor_path))
8098 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8100 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8103 gtk_tree_path_free (old_cursor_path);
8104 gtk_tree_path_free (cursor_path);
8108 pspp_sheet_view_move_cursor_left_right (PsppSheetView *tree_view,
8110 PsppSheetSelectMode mode)
8112 int cursor_node = -1;
8113 GtkTreePath *cursor_path = NULL;
8114 PsppSheetViewColumn *column;
8117 gboolean found_column = FALSE;
8120 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8122 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8125 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8126 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8130 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8131 if (cursor_node < 0)
8133 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8135 gtk_tree_path_free (cursor_path);
8138 gtk_tree_path_free (cursor_path);
8140 list = rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns);
8141 if (tree_view->priv->focus_column)
8143 for (; list; list = (rtl ? list->prev : list->next))
8145 if (list->data == tree_view->priv->focus_column)
8152 gboolean left, right;
8154 column = list->data;
8155 if (column->visible == FALSE || column->row_head)
8158 pspp_sheet_view_column_cell_set_cell_data (column,
8159 tree_view->priv->model,
8164 right = list->prev ? TRUE : FALSE;
8165 left = list->next ? TRUE : FALSE;
8169 left = list->prev ? TRUE : FALSE;
8170 right = list->next ? TRUE : FALSE;
8173 if (_pspp_sheet_view_column_cell_focus (column, count, left, right))
8175 tree_view->priv->focus_column = column;
8176 found_column = TRUE;
8181 list = rtl ? list->prev : list->next;
8183 list = rtl ? list->next : list->prev;
8188 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8189 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8190 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8194 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8197 pspp_sheet_view_clamp_column_visible (tree_view,
8198 tree_view->priv->focus_column, TRUE);
8202 pspp_sheet_view_move_cursor_line_start_end (PsppSheetView *tree_view,
8204 PsppSheetSelectMode mode)
8206 int cursor_node = -1;
8207 GtkTreePath *cursor_path = NULL;
8208 PsppSheetViewColumn *column;
8209 PsppSheetViewColumn *found_column;
8214 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8216 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8219 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8220 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8224 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8225 if (cursor_node < 0)
8227 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8229 gtk_tree_path_free (cursor_path);
8232 gtk_tree_path_free (cursor_path);
8234 list = rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns);
8235 if (tree_view->priv->focus_column)
8237 for (; list; list = (rtl ? list->prev : list->next))
8239 if (list->data == tree_view->priv->focus_column)
8244 found_column = NULL;
8247 gboolean left, right;
8249 column = list->data;
8250 if (column->visible == FALSE || column->row_head)
8253 pspp_sheet_view_column_cell_set_cell_data (column,
8254 tree_view->priv->model,
8259 right = list->prev ? TRUE : FALSE;
8260 left = list->next ? TRUE : FALSE;
8264 left = list->prev ? TRUE : FALSE;
8265 right = list->next ? TRUE : FALSE;
8268 if (column->tabbable
8269 && _pspp_sheet_view_column_cell_focus (column, count, left, right))
8270 found_column = column;
8274 list = rtl ? list->prev : list->next;
8276 list = rtl ? list->next : list->prev;
8281 tree_view->priv->focus_column = found_column;
8282 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8283 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8284 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8287 pspp_sheet_view_clamp_column_visible (tree_view,
8288 tree_view->priv->focus_column, TRUE);
8292 try_move_cursor_tab (PsppSheetView *tree_view,
8293 gboolean start_at_focus_column,
8296 PsppSheetViewColumn *column;
8298 int cursor_node = -1;
8299 GtkTreePath *cursor_path = NULL;
8303 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8304 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8308 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8309 if (cursor_node < 0)
8311 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8313 gtk_tree_path_free (cursor_path);
8316 gtk_tree_path_free (cursor_path);
8318 rtl = gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL;
8319 if (start_at_focus_column)
8322 ? g_list_last (tree_view->priv->columns)
8323 : g_list_first (tree_view->priv->columns));
8324 if (tree_view->priv->focus_column)
8326 for (; list; list = (rtl ? list->prev : list->next))
8328 if (list->data == tree_view->priv->focus_column)
8335 list = (rtl ^ (count == 1)
8336 ? g_list_first (tree_view->priv->columns)
8337 : g_list_last (tree_view->priv->columns));
8342 gboolean left, right;
8344 column = list->data;
8345 if (column->visible == FALSE || !column->tabbable)
8348 pspp_sheet_view_column_cell_set_cell_data (column,
8349 tree_view->priv->model,
8354 right = list->prev ? TRUE : FALSE;
8355 left = list->next ? TRUE : FALSE;
8359 left = list->prev ? TRUE : FALSE;
8360 right = list->next ? TRUE : FALSE;
8363 if (column->tabbable
8364 && _pspp_sheet_view_column_cell_focus (column, count, left, right))
8366 tree_view->priv->focus_column = column;
8367 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8368 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8369 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8374 list = rtl ? list->prev : list->next;
8376 list = rtl ? list->next : list->prev;
8383 pspp_sheet_view_move_cursor_tab (PsppSheetView *tree_view,
8386 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8389 if (!try_move_cursor_tab (tree_view, TRUE, count))
8391 if (pspp_sheet_view_move_cursor_up_down (tree_view, count, 0)
8392 && !try_move_cursor_tab (tree_view, FALSE, count))
8393 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8396 pspp_sheet_view_clamp_column_visible (tree_view,
8397 tree_view->priv->focus_column, TRUE);
8401 pspp_sheet_view_move_cursor_start_end (PsppSheetView *tree_view,
8403 PsppSheetSelectMode mode)
8407 GtkTreePath *old_path;
8409 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8412 g_return_if_fail (tree_view->priv->row_count > 0);
8414 pspp_sheet_view_get_cursor (tree_view, &old_path, NULL);
8418 /* Now go forward to find the first focusable row. */
8419 path = _pspp_sheet_view_find_path (tree_view, 0);
8420 search_first_focusable_path (tree_view, &path,
8421 TRUE, &cursor_node);
8425 /* Now go backwards to find last focusable row. */
8426 path = _pspp_sheet_view_find_path (tree_view, tree_view->priv->row_count - 1);
8427 search_first_focusable_path (tree_view, &path,
8428 FALSE, &cursor_node);
8434 if (gtk_tree_path_compare (old_path, path))
8436 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, mode);
8437 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8441 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8445 gtk_tree_path_free (old_path);
8446 gtk_tree_path_free (path);
8450 pspp_sheet_view_real_select_all (PsppSheetView *tree_view)
8452 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8455 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8456 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8459 pspp_sheet_selection_select_all (tree_view->priv->selection);
8465 pspp_sheet_view_real_unselect_all (PsppSheetView *tree_view)
8467 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8470 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8471 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8474 pspp_sheet_selection_unselect_all (tree_view->priv->selection);
8480 pspp_sheet_view_real_select_cursor_row (PsppSheetView *tree_view,
8481 gboolean start_editing,
8482 PsppSheetSelectMode mode)
8485 int cursor_node = -1;
8486 GtkTreePath *cursor_path = NULL;
8488 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8491 if (tree_view->priv->cursor)
8492 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8494 if (cursor_path == NULL)
8497 _pspp_sheet_view_find_node (tree_view, cursor_path,
8500 if (cursor_node < 0)
8502 gtk_tree_path_free (cursor_path);
8506 if (!(mode & PSPP_SHEET_SELECT_MODE_EXTEND) && start_editing &&
8507 tree_view->priv->focus_column)
8509 if (pspp_sheet_view_start_editing (tree_view, cursor_path))
8511 gtk_tree_path_free (cursor_path);
8516 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8522 /* We bail out if the original (tree, node) don't exist anymore after
8523 * handling the selection-changed callback. We do return TRUE because
8524 * the key press has been handled at this point.
8526 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8528 if (cursor_node != new_node)
8531 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8533 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8534 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8536 if (!(mode & PSPP_SHEET_SELECT_MODE_EXTEND))
8537 pspp_sheet_view_row_activated (tree_view, cursor_path,
8538 tree_view->priv->focus_column);
8540 gtk_tree_path_free (cursor_path);
8546 pspp_sheet_view_real_toggle_cursor_row (PsppSheetView *tree_view)
8549 int cursor_node = -1;
8550 GtkTreePath *cursor_path = NULL;
8552 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8556 if (tree_view->priv->cursor)
8557 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8559 if (cursor_path == NULL)
8562 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8563 if (cursor_node < 0)
8565 gtk_tree_path_free (cursor_path);
8569 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8572 PSPP_SHEET_SELECT_MODE_TOGGLE,
8575 /* We bail out if the original (tree, node) don't exist anymore after
8576 * handling the selection-changed callback. We do return TRUE because
8577 * the key press has been handled at this point.
8579 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8581 if (cursor_node != new_node)
8584 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8586 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8587 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
8588 gtk_tree_path_free (cursor_path);
8594 pspp_sheet_view_search_entry_flush_timeout (PsppSheetView *tree_view)
8596 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
8597 tree_view->priv->typeselect_flush_timeout = 0;
8602 /* Cut and paste from gtkwindow.c */
8604 send_focus_change (GtkWidget *widget,
8607 GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
8609 fevent->focus_change.type = GDK_FOCUS_CHANGE;
8610 fevent->focus_change.window = g_object_ref (gtk_widget_get_window (widget));
8611 fevent->focus_change.in = in;
8613 gtk_widget_send_focus_change (widget, fevent);
8614 gdk_event_free (fevent);
8618 pspp_sheet_view_ensure_interactive_directory (PsppSheetView *tree_view)
8620 GtkWidget *frame, *vbox, *toplevel;
8623 if (tree_view->priv->search_custom_entry_set)
8626 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
8627 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
8629 if (tree_view->priv->search_window != NULL)
8631 if (gtk_window_get_group (GTK_WINDOW (toplevel)))
8632 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
8633 GTK_WINDOW (tree_view->priv->search_window));
8634 else if (gtk_window_get_group (GTK_WINDOW (tree_view->priv->search_window)))
8635 gtk_window_group_remove_window (gtk_window_get_group (GTK_WINDOW (tree_view->priv->search_window)),
8636 GTK_WINDOW (tree_view->priv->search_window));
8637 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8641 tree_view->priv->search_window = gtk_window_new (GTK_WINDOW_POPUP);
8642 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8644 if (gtk_window_get_group (GTK_WINDOW (toplevel)))
8645 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
8646 GTK_WINDOW (tree_view->priv->search_window));
8648 gtk_window_set_type_hint (GTK_WINDOW (tree_view->priv->search_window),
8649 GDK_WINDOW_TYPE_HINT_UTILITY);
8650 gtk_window_set_modal (GTK_WINDOW (tree_view->priv->search_window), TRUE);
8651 g_signal_connect (tree_view->priv->search_window, "delete-event",
8652 G_CALLBACK (pspp_sheet_view_search_delete_event),
8654 g_signal_connect (tree_view->priv->search_window, "key-press-event",
8655 G_CALLBACK (pspp_sheet_view_search_key_press_event),
8657 g_signal_connect (tree_view->priv->search_window, "button-press-event",
8658 G_CALLBACK (pspp_sheet_view_search_button_press_event),
8660 g_signal_connect (tree_view->priv->search_window, "scroll-event",
8661 G_CALLBACK (pspp_sheet_view_search_scroll_event),
8664 frame = gtk_frame_new (NULL);
8665 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
8666 gtk_widget_show (frame);
8667 gtk_container_add (GTK_CONTAINER (tree_view->priv->search_window), frame);
8669 vbox = gtk_vbox_new (FALSE, 0);
8670 gtk_widget_show (vbox);
8671 gtk_container_add (GTK_CONTAINER (frame), vbox);
8672 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
8675 tree_view->priv->search_entry = gtk_entry_new ();
8676 gtk_widget_show (tree_view->priv->search_entry);
8677 g_signal_connect (tree_view->priv->search_entry, "populate-popup",
8678 G_CALLBACK (pspp_sheet_view_search_disable_popdown),
8680 g_signal_connect (tree_view->priv->search_entry,
8681 "activate", G_CALLBACK (pspp_sheet_view_search_activate),
8685 g_signal_connect (GTK_ENTRY (tree_view->priv->search_entry)->im_context,
8687 G_CALLBACK (pspp_sheet_view_search_preedit_changed),
8691 gtk_container_add (GTK_CONTAINER (vbox),
8692 tree_view->priv->search_entry);
8694 gtk_widget_realize (tree_view->priv->search_entry);
8697 /* Pops up the interactive search entry. If keybinding is TRUE then the user
8698 * started this by typing the start_interactive_search keybinding. Otherwise, it came from
8701 pspp_sheet_view_real_start_interactive_search (PsppSheetView *tree_view,
8702 gboolean keybinding)
8704 /* We only start interactive search if we have focus or the columns
8705 * have focus. If one of our children have focus, we don't want to
8709 gboolean found_focus = FALSE;
8710 GtkWidgetClass *entry_parent_class;
8712 if (!tree_view->priv->enable_search && !keybinding)
8715 if (tree_view->priv->search_custom_entry_set)
8718 if (tree_view->priv->search_window != NULL &&
8719 gtk_widget_get_visible (tree_view->priv->search_window))
8722 for (list = tree_view->priv->columns; list; list = list->next)
8724 PsppSheetViewColumn *column;
8726 column = list->data;
8727 if (! column->visible)
8730 if (column->button && gtk_widget_has_focus (column->button))
8737 if (gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8743 if (tree_view->priv->search_column < 0)
8746 pspp_sheet_view_ensure_interactive_directory (tree_view);
8749 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
8752 tree_view->priv->search_position_func (tree_view, tree_view->priv->search_window, tree_view->priv->search_position_user_data);
8753 gtk_widget_show (tree_view->priv->search_window);
8754 if (tree_view->priv->search_entry_changed_id == 0)
8756 tree_view->priv->search_entry_changed_id =
8757 g_signal_connect (tree_view->priv->search_entry, "changed",
8758 G_CALLBACK (pspp_sheet_view_search_init),
8762 tree_view->priv->typeselect_flush_timeout =
8763 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
8764 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
8767 /* Grab focus will select all the text. We don't want that to happen, so we
8768 * call the parent instance and bypass the selection change. This is probably
8769 * really non-kosher. */
8770 entry_parent_class = g_type_class_peek_parent (GTK_ENTRY_GET_CLASS (tree_view->priv->search_entry));
8771 (entry_parent_class->grab_focus) (tree_view->priv->search_entry);
8773 /* send focus-in event */
8774 send_focus_change (tree_view->priv->search_entry, TRUE);
8776 /* search first matching iter */
8777 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
8783 pspp_sheet_view_start_interactive_search (PsppSheetView *tree_view)
8785 return pspp_sheet_view_real_start_interactive_search (tree_view, TRUE);
8788 /* this function returns the new width of the column being resized given
8789 * the column and x position of the cursor; the x cursor position is passed
8790 * in as a pointer and automagicly corrected if it's beyond min/max limits
8793 pspp_sheet_view_new_column_width (PsppSheetView *tree_view,
8797 PsppSheetViewColumn *column;
8801 /* first translate the x position from gtk_widget_get_window (widget)
8802 * to clist->clist_window
8804 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8805 column = g_list_nth (tree_view->priv->columns, i)->data;
8806 width = rtl ? (column->allocation.x + column->allocation.width - *x) : (*x - column->allocation.x);
8808 /* Clamp down the value */
8809 if (column->min_width == -1)
8810 width = MAX (column->button_request, width);
8812 width = MAX (column->min_width, width);
8813 if (column->max_width != -1)
8814 width = MIN (width, column->max_width);
8816 *x = rtl ? (column->allocation.x + column->allocation.width - width) : (column->allocation.x + width);
8822 /* FIXME this adjust_allocation is a big cut-and-paste from
8823 * GtkCList, needs to be some "official" way to do this
8833 /* The window to which gtk_widget_get_window (widget) is relative */
8834 #define ALLOCATION_WINDOW(widget) \
8835 (!gtk_widget_get_has_window (widget) ? \
8836 gtk_widget_get_window (widget) : \
8837 gdk_window_get_parent (gtk_widget_get_window (widget)))
8840 adjust_allocation_recurse (GtkWidget *widget,
8843 ScrollData *scroll_data = data;
8844 GtkAllocation allocation;
8845 gtk_widget_get_allocation (widget, &allocation);
8846 /* Need to really size allocate instead of just poking
8847 * into widget->allocation if the widget is not realized.
8848 * FIXME someone figure out why this was.
8850 if (!gtk_widget_get_realized (widget))
8852 if (gtk_widget_get_visible (widget))
8854 GdkRectangle tmp_rectangle = allocation;
8855 tmp_rectangle.x += scroll_data->dx;
8856 tmp_rectangle.y += scroll_data->dy;
8858 gtk_widget_size_allocate (widget, &tmp_rectangle);
8863 if (ALLOCATION_WINDOW (widget) == scroll_data->window)
8865 allocation.x += scroll_data->dx;
8866 allocation.y += scroll_data->dy;
8868 if (GTK_IS_CONTAINER (widget))
8869 gtk_container_forall (GTK_CONTAINER (widget),
8870 adjust_allocation_recurse,
8877 adjust_allocation (GtkWidget *widget,
8881 ScrollData scroll_data;
8883 if (gtk_widget_get_realized (widget))
8884 scroll_data.window = ALLOCATION_WINDOW (widget);
8886 scroll_data.window = NULL;
8888 scroll_data.dx = dx;
8889 scroll_data.dy = dy;
8891 adjust_allocation_recurse (widget, &scroll_data);
8895 pspp_sheet_view_column_update_button (PsppSheetViewColumn *tree_column);
8899 pspp_sheet_view_adjustment_changed (GtkAdjustment *adjustment,
8900 PsppSheetView *tree_view)
8902 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
8907 gdk_window_move (tree_view->priv->bin_window,
8908 - gtk_adjustment_get_value (tree_view->priv->hadjustment),
8909 TREE_VIEW_HEADER_HEIGHT (tree_view));
8910 gdk_window_move (tree_view->priv->header_window,
8911 - gtk_adjustment_get_value (tree_view->priv->hadjustment),
8913 dy = tree_view->priv->dy - (int) gtk_adjustment_get_value (tree_view->priv->vadjustment);
8916 update_prelight (tree_view,
8917 tree_view->priv->event_last_x,
8918 tree_view->priv->event_last_y - dy);
8920 if (tree_view->priv->edited_column &&
8921 GTK_IS_WIDGET (tree_view->priv->edited_column->editable_widget))
8925 PsppSheetViewChild *child = NULL;
8927 widget = GTK_WIDGET (tree_view->priv->edited_column->editable_widget);
8928 adjust_allocation (widget, 0, dy);
8930 for (list = tree_view->priv->children; list; list = list->next)
8932 child = (PsppSheetViewChild *)list->data;
8933 if (child->widget == widget)
8941 gdk_window_scroll (tree_view->priv->bin_window, 0, dy);
8943 if (tree_view->priv->dy != (int) gtk_adjustment_get_value (tree_view->priv->vadjustment))
8945 /* update our dy and top_row */
8946 tree_view->priv->dy = (int) gtk_adjustment_get_value (tree_view->priv->vadjustment);
8948 if (!tree_view->priv->in_top_row_to_dy)
8949 pspp_sheet_view_dy_to_top_row (tree_view);
8952 for (list = tree_view->priv->columns; list; list = list->next)
8954 PsppSheetViewColumn *column = list->data;
8955 GtkAllocation *col_allocation = &column->allocation;
8956 GtkAllocation widget_allocation;
8957 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &widget_allocation);
8959 if (span_intersects (col_allocation->x, col_allocation->width,
8960 gtk_adjustment_get_value (tree_view->priv->hadjustment),
8961 widget_allocation.width))
8963 pspp_sheet_view_column_set_need_button (column, TRUE);
8964 if (!column->button)
8965 pspp_sheet_view_column_update_button (column);
8977 * pspp_sheet_view_new:
8979 * Creates a new #PsppSheetView widget.
8981 * Return value: A newly created #PsppSheetView widget.
8984 pspp_sheet_view_new (void)
8986 return g_object_new (PSPP_TYPE_SHEET_VIEW, NULL);
8990 * pspp_sheet_view_new_with_model:
8991 * @model: the model.
8993 * Creates a new #PsppSheetView widget with the model initialized to @model.
8995 * Return value: A newly created #PsppSheetView widget.
8998 pspp_sheet_view_new_with_model (GtkTreeModel *model)
9000 return g_object_new (PSPP_TYPE_SHEET_VIEW, "model", model, NULL);
9007 * pspp_sheet_view_get_model:
9008 * @tree_view: a #PsppSheetView
9010 * Returns the model the #PsppSheetView is based on. Returns %NULL if the
9013 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
9016 pspp_sheet_view_get_model (PsppSheetView *tree_view)
9018 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9020 return tree_view->priv->model;
9024 * pspp_sheet_view_set_model:
9025 * @tree_view: A #GtkTreeNode.
9026 * @model: (allow-none): The model.
9028 * Sets the model for a #PsppSheetView. If the @tree_view already has a model
9029 * set, it will remove it before setting the new model. If @model is %NULL,
9030 * then it will unset the old model.
9033 pspp_sheet_view_set_model (PsppSheetView *tree_view,
9034 GtkTreeModel *model)
9036 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9037 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
9039 if (model == tree_view->priv->model)
9042 if (tree_view->priv->scroll_to_path)
9044 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9045 tree_view->priv->scroll_to_path = NULL;
9048 if (tree_view->priv->model)
9050 GList *tmplist = tree_view->priv->columns;
9052 if (tree_view->priv->selected)
9053 range_tower_set0 (tree_view->priv->selected, 0, ULONG_MAX);
9054 pspp_sheet_view_stop_editing (tree_view, TRUE);
9056 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9057 pspp_sheet_view_row_changed,
9059 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9060 pspp_sheet_view_row_inserted,
9062 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9063 pspp_sheet_view_row_deleted,
9065 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9066 pspp_sheet_view_rows_reordered,
9069 for (; tmplist; tmplist = tmplist->next)
9070 _pspp_sheet_view_column_unset_model (tmplist->data,
9071 tree_view->priv->model);
9073 tree_view->priv->prelight_node = -1;
9075 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
9076 tree_view->priv->drag_dest_row = NULL;
9077 gtk_tree_row_reference_free (tree_view->priv->cursor);
9078 tree_view->priv->cursor = NULL;
9079 gtk_tree_row_reference_free (tree_view->priv->anchor);
9080 tree_view->priv->anchor = NULL;
9081 gtk_tree_row_reference_free (tree_view->priv->top_row);
9082 tree_view->priv->top_row = NULL;
9083 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9084 tree_view->priv->scroll_to_path = NULL;
9086 tree_view->priv->scroll_to_column = NULL;
9088 g_object_unref (tree_view->priv->model);
9090 tree_view->priv->search_column = -1;
9091 tree_view->priv->fixed_height = -1;
9092 tree_view->priv->dy = tree_view->priv->top_row_dy = 0;
9093 tree_view->priv->last_button_x = -1;
9094 tree_view->priv->last_button_y = -1;
9097 tree_view->priv->model = model;
9099 if (tree_view->priv->model)
9103 if (tree_view->priv->search_column == -1)
9105 for (i = 0; i < gtk_tree_model_get_n_columns (model); i++)
9107 GType type = gtk_tree_model_get_column_type (model, i);
9109 if (g_value_type_transformable (type, G_TYPE_STRING))
9111 tree_view->priv->search_column = i;
9117 g_object_ref (tree_view->priv->model);
9118 g_signal_connect (tree_view->priv->model,
9120 G_CALLBACK (pspp_sheet_view_row_changed),
9122 g_signal_connect (tree_view->priv->model,
9124 G_CALLBACK (pspp_sheet_view_row_inserted),
9126 g_signal_connect (tree_view->priv->model,
9128 G_CALLBACK (pspp_sheet_view_row_deleted),
9130 g_signal_connect (tree_view->priv->model,
9132 G_CALLBACK (pspp_sheet_view_rows_reordered),
9135 tree_view->priv->row_count = gtk_tree_model_iter_n_children (tree_view->priv->model, NULL);
9137 /* FIXME: do I need to do this? pspp_sheet_view_create_buttons (tree_view); */
9138 install_presize_handler (tree_view);
9141 g_object_notify (G_OBJECT (tree_view), "model");
9143 if (tree_view->priv->selection)
9144 _pspp_sheet_selection_emit_changed (tree_view->priv->selection);
9146 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9147 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9151 * pspp_sheet_view_get_selection:
9152 * @tree_view: A #PsppSheetView.
9154 * Gets the #PsppSheetSelection associated with @tree_view.
9156 * Return value: A #PsppSheetSelection object.
9158 PsppSheetSelection *
9159 pspp_sheet_view_get_selection (PsppSheetView *tree_view)
9161 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9163 return tree_view->priv->selection;
9167 * pspp_sheet_view_get_hadjustment:
9168 * @tree_view: A #PsppSheetView
9170 * Gets the #GtkAdjustment currently being used for the horizontal aspect.
9172 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
9176 pspp_sheet_view_get_hadjustment (PsppSheetView *tree_view)
9178 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9180 if (tree_view->priv->hadjustment == NULL)
9181 pspp_sheet_view_set_hadjustment (tree_view, NULL);
9183 return tree_view->priv->hadjustment;
9187 * pspp_sheet_view_set_hadjustment:
9188 * @tree_view: A #PsppSheetView
9189 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
9191 * Sets the #GtkAdjustment for the current horizontal aspect.
9194 pspp_sheet_view_set_hadjustment (PsppSheetView *tree_view,
9195 GtkAdjustment *adjustment)
9197 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9199 pspp_sheet_view_set_adjustments (tree_view,
9201 tree_view->priv->vadjustment);
9203 g_object_notify (G_OBJECT (tree_view), "hadjustment");
9207 * pspp_sheet_view_get_vadjustment:
9208 * @tree_view: A #PsppSheetView
9210 * Gets the #GtkAdjustment currently being used for the vertical aspect.
9212 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
9216 pspp_sheet_view_get_vadjustment (PsppSheetView *tree_view)
9218 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9220 if (tree_view->priv->vadjustment == NULL)
9221 pspp_sheet_view_set_vadjustment (tree_view, NULL);
9223 return tree_view->priv->vadjustment;
9227 * pspp_sheet_view_set_vadjustment:
9228 * @tree_view: A #PsppSheetView
9229 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
9231 * Sets the #GtkAdjustment for the current vertical aspect.
9234 pspp_sheet_view_set_vadjustment (PsppSheetView *tree_view,
9235 GtkAdjustment *adjustment)
9237 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9239 pspp_sheet_view_set_adjustments (tree_view,
9240 tree_view->priv->hadjustment,
9243 g_object_notify (G_OBJECT (tree_view), "vadjustment");
9246 /* Column and header operations */
9249 * pspp_sheet_view_get_headers_visible:
9250 * @tree_view: A #PsppSheetView.
9252 * Returns %TRUE if the headers on the @tree_view are visible.
9254 * Return value: Whether the headers are visible or not.
9257 pspp_sheet_view_get_headers_visible (PsppSheetView *tree_view)
9259 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9261 return PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9265 * pspp_sheet_view_set_headers_visible:
9266 * @tree_view: A #PsppSheetView.
9267 * @headers_visible: %TRUE if the headers are visible
9269 * Sets the visibility state of the headers.
9272 pspp_sheet_view_set_headers_visible (PsppSheetView *tree_view,
9273 gboolean headers_visible)
9277 PsppSheetViewColumn *column;
9278 GtkAllocation allocation;
9280 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9282 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
9284 headers_visible = !! headers_visible;
9286 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE) == headers_visible)
9289 if (headers_visible)
9290 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9292 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9294 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9296 gdk_window_get_position (tree_view->priv->bin_window, &x, &y);
9297 if (headers_visible)
9299 gdk_window_move_resize (tree_view->priv->bin_window, x, y + TREE_VIEW_HEADER_HEIGHT (tree_view),
9300 tree_view->priv->width, allocation.height - + TREE_VIEW_HEADER_HEIGHT (tree_view));
9302 if (gtk_widget_get_mapped (GTK_WIDGET (tree_view)))
9303 pspp_sheet_view_map_buttons (tree_view);
9307 gdk_window_move_resize (tree_view->priv->bin_window, x, y, tree_view->priv->width, tree_view->priv->height);
9309 for (list = tree_view->priv->columns; list; list = list->next)
9311 column = list->data;
9313 gtk_widget_unmap (column->button);
9315 gdk_window_hide (tree_view->priv->header_window);
9319 gtk_adjustment_set_page_size (tree_view->priv->vadjustment, allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view));
9320 gtk_adjustment_set_page_increment (tree_view->priv->vadjustment, (allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view)) / 2);
9321 gtk_adjustment_set_lower (tree_view->priv->vadjustment, 0);
9322 gtk_adjustment_set_upper (tree_view->priv->vadjustment, tree_view->priv->height);
9323 gtk_adjustment_changed (tree_view->priv->vadjustment);
9325 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9327 g_object_notify (G_OBJECT (tree_view), "headers-visible");
9331 * pspp_sheet_view_columns_autosize:
9332 * @tree_view: A #PsppSheetView.
9334 * Resizes all columns to their optimal width. Only works after the
9335 * treeview has been realized.
9338 pspp_sheet_view_columns_autosize (PsppSheetView *tree_view)
9340 gboolean dirty = FALSE;
9342 PsppSheetViewColumn *column;
9344 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9346 for (list = tree_view->priv->columns; list; list = list->next)
9348 column = list->data;
9349 _pspp_sheet_view_column_cell_set_dirty (column);
9354 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9358 * pspp_sheet_view_set_headers_clickable:
9359 * @tree_view: A #PsppSheetView.
9360 * @setting: %TRUE if the columns are clickable.
9362 * Allow the column title buttons to be clicked.
9365 pspp_sheet_view_set_headers_clickable (PsppSheetView *tree_view,
9370 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9372 for (list = tree_view->priv->columns; list; list = list->next)
9373 pspp_sheet_view_column_set_clickable (PSPP_SHEET_VIEW_COLUMN (list->data), setting);
9375 g_object_notify (G_OBJECT (tree_view), "headers-clickable");
9380 * pspp_sheet_view_get_headers_clickable:
9381 * @tree_view: A #PsppSheetView.
9383 * Returns whether all header columns are clickable.
9385 * Return value: %TRUE if all header columns are clickable, otherwise %FALSE
9390 pspp_sheet_view_get_headers_clickable (PsppSheetView *tree_view)
9394 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9396 for (list = tree_view->priv->columns; list; list = list->next)
9397 if (!PSPP_SHEET_VIEW_COLUMN (list->data)->clickable)
9404 * pspp_sheet_view_set_rules_hint
9405 * @tree_view: a #PsppSheetView
9406 * @setting: %TRUE if the tree requires reading across rows
9408 * This function tells GTK+ that the user interface for your
9409 * application requires users to read across tree rows and associate
9410 * cells with one another. By default, GTK+ will then render the tree
9411 * with alternating row colors. Do <emphasis>not</emphasis> use it
9412 * just because you prefer the appearance of the ruled tree; that's a
9413 * question for the theme. Some themes will draw tree rows in
9414 * alternating colors even when rules are turned off, and users who
9415 * prefer that appearance all the time can choose those themes. You
9416 * should call this function only as a <emphasis>semantic</emphasis>
9417 * hint to the theme engine that your tree makes alternating colors
9418 * useful from a functional standpoint (since it has lots of columns,
9423 pspp_sheet_view_set_rules_hint (PsppSheetView *tree_view,
9426 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9428 setting = setting != FALSE;
9430 if (tree_view->priv->has_rules != setting)
9432 tree_view->priv->has_rules = setting;
9433 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
9436 g_object_notify (G_OBJECT (tree_view), "rules-hint");
9440 * pspp_sheet_view_get_rules_hint
9441 * @tree_view: a #PsppSheetView
9443 * Gets the setting set by pspp_sheet_view_set_rules_hint().
9445 * Return value: %TRUE if rules are useful for the user of this tree
9448 pspp_sheet_view_get_rules_hint (PsppSheetView *tree_view)
9450 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9452 return tree_view->priv->has_rules;
9455 /* Public Column functions
9459 * pspp_sheet_view_append_column:
9460 * @tree_view: A #PsppSheetView.
9461 * @column: The #PsppSheetViewColumn to add.
9463 * Appends @column to the list of columns.
9465 * Return value: The number of columns in @tree_view after appending.
9468 pspp_sheet_view_append_column (PsppSheetView *tree_view,
9469 PsppSheetViewColumn *column)
9471 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9472 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9473 g_return_val_if_fail (column->tree_view == NULL, -1);
9475 return pspp_sheet_view_insert_column (tree_view, column, -1);
9480 * pspp_sheet_view_remove_column:
9481 * @tree_view: A #PsppSheetView.
9482 * @column: The #PsppSheetViewColumn to remove.
9484 * Removes @column from @tree_view.
9486 * Return value: The number of columns in @tree_view after removing.
9489 pspp_sheet_view_remove_column (PsppSheetView *tree_view,
9490 PsppSheetViewColumn *column)
9492 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9493 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9494 g_return_val_if_fail (column->tree_view == GTK_WIDGET (tree_view), -1);
9496 if (tree_view->priv->focus_column == column)
9497 tree_view->priv->focus_column = NULL;
9499 if (tree_view->priv->edited_column == column)
9501 pspp_sheet_view_stop_editing (tree_view, TRUE);
9503 /* no need to, but just to be sure ... */
9504 tree_view->priv->edited_column = NULL;
9507 _pspp_sheet_view_column_unset_tree_view (column);
9509 tree_view->priv->columns = g_list_remove (tree_view->priv->columns, column);
9510 tree_view->priv->n_columns--;
9512 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9516 _pspp_sheet_view_column_unrealize_button (column);
9517 for (list = tree_view->priv->columns; list; list = list->next)
9519 PsppSheetViewColumn *tmp_column;
9521 tmp_column = PSPP_SHEET_VIEW_COLUMN (list->data);
9522 if (tmp_column->visible)
9523 _pspp_sheet_view_column_cell_set_dirty (tmp_column);
9526 if (tree_view->priv->n_columns == 0 &&
9527 pspp_sheet_view_get_headers_visible (tree_view) &&
9528 tree_view->priv->header_window)
9529 gdk_window_hide (tree_view->priv->header_window);
9531 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9534 g_object_unref (column);
9535 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9537 return tree_view->priv->n_columns;
9541 * pspp_sheet_view_insert_column:
9542 * @tree_view: A #PsppSheetView.
9543 * @column: The #PsppSheetViewColumn to be inserted.
9544 * @position: The position to insert @column in.
9546 * This inserts the @column into the @tree_view at @position. If @position is
9547 * -1, then the column is inserted at the end.
9549 * Return value: The number of columns in @tree_view after insertion.
9552 pspp_sheet_view_insert_column (PsppSheetView *tree_view,
9553 PsppSheetViewColumn *column,
9556 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9557 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9558 g_return_val_if_fail (column->tree_view == NULL, -1);
9560 g_object_ref_sink (column);
9562 if (tree_view->priv->n_columns == 0 &&
9563 gtk_widget_get_realized (GTK_WIDGET (tree_view)) &&
9564 pspp_sheet_view_get_headers_visible (tree_view))
9566 gdk_window_show (tree_view->priv->header_window);
9569 tree_view->priv->columns = g_list_insert (tree_view->priv->columns,
9571 tree_view->priv->n_columns++;
9573 _pspp_sheet_view_column_set_tree_view (column, tree_view);
9575 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9579 _pspp_sheet_view_column_realize_button (column);
9581 for (list = tree_view->priv->columns; list; list = list->next)
9583 column = PSPP_SHEET_VIEW_COLUMN (list->data);
9584 if (column->visible)
9585 _pspp_sheet_view_column_cell_set_dirty (column);
9587 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9590 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9592 return tree_view->priv->n_columns;
9596 * pspp_sheet_view_insert_column_with_attributes:
9597 * @tree_view: A #PsppSheetView
9598 * @position: The position to insert the new column in.
9599 * @title: The title to set the header to.
9600 * @cell: The #GtkCellRenderer.
9601 * @Varargs: A %NULL-terminated list of attributes.
9603 * Creates a new #PsppSheetViewColumn and inserts it into the @tree_view at
9604 * @position. If @position is -1, then the newly created column is inserted at
9605 * the end. The column is initialized with the attributes given.
9607 * Return value: The number of columns in @tree_view after insertion.
9610 pspp_sheet_view_insert_column_with_attributes (PsppSheetView *tree_view,
9613 GtkCellRenderer *cell,
9616 PsppSheetViewColumn *column;
9621 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9623 column = pspp_sheet_view_column_new ();
9624 pspp_sheet_view_column_set_title (column, title);
9625 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9627 va_start (args, cell);
9629 attribute = va_arg (args, gchar *);
9631 while (attribute != NULL)
9633 column_id = va_arg (args, gint);
9634 pspp_sheet_view_column_add_attribute (column, cell, attribute, column_id);
9635 attribute = va_arg (args, gchar *);
9640 pspp_sheet_view_insert_column (tree_view, column, position);
9642 return tree_view->priv->n_columns;
9646 * pspp_sheet_view_insert_column_with_data_func:
9647 * @tree_view: a #PsppSheetView
9648 * @position: Position to insert, -1 for append
9649 * @title: column title
9650 * @cell: cell renderer for column
9651 * @func: function to set attributes of cell renderer
9652 * @data: data for @func
9653 * @dnotify: destroy notifier for @data
9655 * Convenience function that inserts a new column into the #PsppSheetView
9656 * with the given cell renderer and a #GtkCellDataFunc to set cell renderer
9657 * attributes (normally using data from the model). See also
9658 * pspp_sheet_view_column_set_cell_data_func(), pspp_sheet_view_column_pack_start().
9660 * Return value: number of columns in the tree view post-insert
9663 pspp_sheet_view_insert_column_with_data_func (PsppSheetView *tree_view,
9666 GtkCellRenderer *cell,
9667 PsppSheetCellDataFunc func,
9669 GDestroyNotify dnotify)
9671 PsppSheetViewColumn *column;
9673 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9675 column = pspp_sheet_view_column_new ();
9676 pspp_sheet_view_column_set_title (column, title);
9677 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9678 pspp_sheet_view_column_set_cell_data_func (column, cell, func, data, dnotify);
9680 pspp_sheet_view_insert_column (tree_view, column, position);
9682 return tree_view->priv->n_columns;
9686 * pspp_sheet_view_get_column:
9687 * @tree_view: A #PsppSheetView.
9688 * @n: The position of the column, counting from 0.
9690 * Gets the #PsppSheetViewColumn at the given position in the #tree_view.
9692 * Return value: The #PsppSheetViewColumn, or %NULL if the position is outside the
9695 PsppSheetViewColumn *
9696 pspp_sheet_view_get_column (PsppSheetView *tree_view,
9699 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9701 if (n < 0 || n >= tree_view->priv->n_columns)
9704 if (tree_view->priv->columns == NULL)
9707 return PSPP_SHEET_VIEW_COLUMN (g_list_nth (tree_view->priv->columns, n)->data);
9711 * pspp_sheet_view_get_columns:
9712 * @tree_view: A #PsppSheetView
9714 * Returns a #GList of all the #PsppSheetViewColumn s currently in @tree_view.
9715 * The returned list must be freed with g_list_free ().
9717 * Return value: (element-type PsppSheetViewColumn) (transfer container): A list of #PsppSheetViewColumn s
9720 pspp_sheet_view_get_columns (PsppSheetView *tree_view)
9722 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9724 return g_list_copy (tree_view->priv->columns);
9728 * pspp_sheet_view_move_column_after:
9729 * @tree_view: A #PsppSheetView
9730 * @column: The #PsppSheetViewColumn to be moved.
9731 * @base_column: (allow-none): The #PsppSheetViewColumn to be moved relative to, or %NULL.
9733 * Moves @column to be after to @base_column. If @base_column is %NULL, then
9734 * @column is placed in the first position.
9737 pspp_sheet_view_move_column_after (PsppSheetView *tree_view,
9738 PsppSheetViewColumn *column,
9739 PsppSheetViewColumn *base_column)
9741 GList *column_list_el, *base_el = NULL;
9743 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9745 column_list_el = g_list_find (tree_view->priv->columns, column);
9746 g_return_if_fail (column_list_el != NULL);
9750 base_el = g_list_find (tree_view->priv->columns, base_column);
9751 g_return_if_fail (base_el != NULL);
9754 if (column_list_el->prev == base_el)
9757 tree_view->priv->columns = g_list_remove_link (tree_view->priv->columns, column_list_el);
9758 if (base_el == NULL)
9760 column_list_el->prev = NULL;
9761 column_list_el->next = tree_view->priv->columns;
9762 if (column_list_el->next)
9763 column_list_el->next->prev = column_list_el;
9764 tree_view->priv->columns = column_list_el;
9768 column_list_el->prev = base_el;
9769 column_list_el->next = base_el->next;
9770 if (column_list_el->next)
9771 column_list_el->next->prev = column_list_el;
9772 base_el->next = column_list_el;
9775 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9777 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9778 pspp_sheet_view_size_allocate_columns (GTK_WIDGET (tree_view), NULL);
9781 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9785 * pspp_sheet_view_set_column_drag_function:
9786 * @tree_view: A #PsppSheetView.
9787 * @func: (allow-none): A function to determine which columns are reorderable, or %NULL.
9788 * @user_data: (allow-none): User data to be passed to @func, or %NULL
9789 * @destroy: (allow-none): Destroy notifier for @user_data, or %NULL
9791 * Sets a user function for determining where a column may be dropped when
9792 * dragged. This function is called on every column pair in turn at the
9793 * beginning of a column drag to determine where a drop can take place. The
9794 * arguments passed to @func are: the @tree_view, the #PsppSheetViewColumn being
9795 * dragged, the two #PsppSheetViewColumn s determining the drop spot, and
9796 * @user_data. If either of the #PsppSheetViewColumn arguments for the drop spot
9797 * are %NULL, then they indicate an edge. If @func is set to be %NULL, then
9798 * @tree_view reverts to the default behavior of allowing all columns to be
9799 * dropped everywhere.
9802 pspp_sheet_view_set_column_drag_function (PsppSheetView *tree_view,
9803 PsppSheetViewColumnDropFunc func,
9805 GDestroyNotify destroy)
9807 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9809 if (tree_view->priv->column_drop_func_data_destroy)
9810 tree_view->priv->column_drop_func_data_destroy (tree_view->priv->column_drop_func_data);
9812 tree_view->priv->column_drop_func = func;
9813 tree_view->priv->column_drop_func_data = user_data;
9814 tree_view->priv->column_drop_func_data_destroy = destroy;
9818 * pspp_sheet_view_scroll_to_point:
9819 * @tree_view: a #PsppSheetView
9820 * @tree_x: X coordinate of new top-left pixel of visible area, or -1
9821 * @tree_y: Y coordinate of new top-left pixel of visible area, or -1
9823 * Scrolls the tree view such that the top-left corner of the visible
9824 * area is @tree_x, @tree_y, where @tree_x and @tree_y are specified
9825 * in tree coordinates. The @tree_view must be realized before
9826 * this function is called. If it isn't, you probably want to be
9827 * using pspp_sheet_view_scroll_to_cell().
9829 * If either @tree_x or @tree_y are -1, then that direction isn't scrolled.
9832 pspp_sheet_view_scroll_to_point (PsppSheetView *tree_view,
9836 GtkAdjustment *hadj;
9837 GtkAdjustment *vadj;
9839 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9840 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
9842 hadj = tree_view->priv->hadjustment;
9843 vadj = tree_view->priv->vadjustment;
9846 gtk_adjustment_set_value (hadj, CLAMP (tree_x, gtk_adjustment_get_lower (hadj), gtk_adjustment_get_upper (hadj) - gtk_adjustment_get_page_size (hadj)));
9848 gtk_adjustment_set_value (vadj, CLAMP (tree_y, gtk_adjustment_get_lower (vadj), gtk_adjustment_get_upper (vadj) - gtk_adjustment_get_page_size (vadj)));
9852 * pspp_sheet_view_scroll_to_cell:
9853 * @tree_view: A #PsppSheetView.
9854 * @path: (allow-none): The path of the row to move to, or %NULL.
9855 * @column: (allow-none): The #PsppSheetViewColumn to move horizontally to, or %NULL.
9856 * @use_align: whether to use alignment arguments, or %FALSE.
9857 * @row_align: The vertical alignment of the row specified by @path.
9858 * @col_align: The horizontal alignment of the column specified by @column.
9860 * Moves the alignments of @tree_view to the position specified by @column and
9861 * @path. If @column is %NULL, then no horizontal scrolling occurs. Likewise,
9862 * if @path is %NULL no vertical scrolling occurs. At a minimum, one of @column
9863 * or @path need to be non-%NULL. @row_align determines where the row is
9864 * placed, and @col_align determines where @column is placed. Both are expected
9865 * to be between 0.0 and 1.0. 0.0 means left/top alignment, 1.0 means
9866 * right/bottom alignment, 0.5 means center.
9868 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
9869 * tree does the minimum amount of work to scroll the cell onto the screen.
9870 * This means that the cell will be scrolled to the edge closest to its current
9871 * position. If the cell is currently visible on the screen, nothing is done.
9873 * This function only works if the model is set, and @path is a valid row on the
9874 * model. If the model changes before the @tree_view is realized, the centered
9875 * path will be modified to reflect this change.
9878 pspp_sheet_view_scroll_to_cell (PsppSheetView *tree_view,
9880 PsppSheetViewColumn *column,
9885 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9886 g_return_if_fail (tree_view->priv->model != NULL);
9887 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
9888 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
9889 g_return_if_fail (path != NULL || column != NULL);
9892 g_print ("pspp_sheet_view_scroll_to_cell:\npath: %s\ncolumn: %s\nuse_align: %d\nrow_align: %f\ncol_align: %f\n",
9893 gtk_tree_path_to_string (path), column?"non-null":"null", use_align, row_align, col_align);
9895 row_align = CLAMP (row_align, 0.0, 1.0);
9896 col_align = CLAMP (col_align, 0.0, 1.0);
9899 /* Note: Despite the benefits that come from having one code path for the
9900 * scrolling code, we short-circuit validate_visible_area's immplementation as
9901 * it is much slower than just going to the point.
9903 if (!gtk_widget_get_visible (GTK_WIDGET (tree_view)) ||
9904 !gtk_widget_get_realized (GTK_WIDGET (tree_view))
9905 /* XXX || GTK_WIDGET_ALLOC_NEEDED (tree_view) */)
9907 if (tree_view->priv->scroll_to_path)
9908 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9910 tree_view->priv->scroll_to_path = NULL;
9911 tree_view->priv->scroll_to_column = NULL;
9914 tree_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
9916 tree_view->priv->scroll_to_column = column;
9917 tree_view->priv->scroll_to_use_align = use_align;
9918 tree_view->priv->scroll_to_row_align = row_align;
9919 tree_view->priv->scroll_to_col_align = col_align;
9921 install_presize_handler (tree_view);
9925 GdkRectangle cell_rect;
9926 GdkRectangle vis_rect;
9927 gint dest_x, dest_y;
9929 pspp_sheet_view_get_background_area (tree_view, path, column, &cell_rect);
9930 pspp_sheet_view_get_visible_rect (tree_view, &vis_rect);
9932 cell_rect.y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, cell_rect.y);
9934 dest_x = vis_rect.x;
9935 dest_y = vis_rect.y;
9941 dest_x = cell_rect.x - ((vis_rect.width - cell_rect.width) * col_align);
9945 if (cell_rect.x < vis_rect.x)
9946 dest_x = cell_rect.x;
9947 if (cell_rect.x + cell_rect.width > vis_rect.x + vis_rect.width)
9948 dest_x = cell_rect.x + cell_rect.width - vis_rect.width;
9956 dest_y = cell_rect.y - ((vis_rect.height - cell_rect.height) * row_align);
9957 dest_y = MAX (dest_y, 0);
9961 if (cell_rect.y < vis_rect.y)
9962 dest_y = cell_rect.y;
9963 if (cell_rect.y + cell_rect.height > vis_rect.y + vis_rect.height)
9964 dest_y = cell_rect.y + cell_rect.height - vis_rect.height;
9968 pspp_sheet_view_scroll_to_point (tree_view, dest_x, dest_y);
9973 * pspp_sheet_view_row_activated:
9974 * @tree_view: A #PsppSheetView
9975 * @path: The #GtkTreePath to be activated.
9976 * @column: The #PsppSheetViewColumn to be activated.
9978 * Activates the cell determined by @path and @column.
9981 pspp_sheet_view_row_activated (PsppSheetView *tree_view,
9983 PsppSheetViewColumn *column)
9985 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9987 g_signal_emit (tree_view, tree_view_signals[ROW_ACTIVATED], 0, path, column);
9992 * pspp_sheet_view_get_reorderable:
9993 * @tree_view: a #PsppSheetView
9995 * Retrieves whether the user can reorder the tree via drag-and-drop. See
9996 * pspp_sheet_view_set_reorderable().
9998 * Return value: %TRUE if the tree can be reordered.
10001 pspp_sheet_view_get_reorderable (PsppSheetView *tree_view)
10003 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
10005 return tree_view->priv->reorderable;
10009 * pspp_sheet_view_set_reorderable:
10010 * @tree_view: A #PsppSheetView.
10011 * @reorderable: %TRUE, if the tree can be reordered.
10013 * This function is a convenience function to allow you to reorder
10014 * models that support the #GtkDragSourceIface and the
10015 * #GtkDragDestIface. Both #GtkTreeStore and #GtkListStore support
10016 * these. If @reorderable is %TRUE, then the user can reorder the
10017 * model by dragging and dropping rows. The developer can listen to
10018 * these changes by connecting to the model's row_inserted and
10019 * row_deleted signals. The reordering is implemented by setting up
10020 * the tree view as a drag source and destination. Therefore, drag and
10021 * drop can not be used in a reorderable view for any other purpose.
10023 * This function does not give you any degree of control over the order -- any
10024 * reordering is allowed. If more control is needed, you should probably
10025 * handle drag and drop manually.
10028 pspp_sheet_view_set_reorderable (PsppSheetView *tree_view,
10029 gboolean reorderable)
10031 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10033 reorderable = reorderable != FALSE;
10035 if (tree_view->priv->reorderable == reorderable)
10040 const GtkTargetEntry row_targets[] = {
10041 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
10044 pspp_sheet_view_enable_model_drag_source (tree_view,
10047 G_N_ELEMENTS (row_targets),
10049 pspp_sheet_view_enable_model_drag_dest (tree_view,
10051 G_N_ELEMENTS (row_targets),
10056 pspp_sheet_view_unset_rows_drag_source (tree_view);
10057 pspp_sheet_view_unset_rows_drag_dest (tree_view);
10060 tree_view->priv->reorderable = reorderable;
10062 g_object_notify (G_OBJECT (tree_view), "reorderable");
10065 /* If CLEAR_AND_SELECT is true, then the row will be selected and, unless Shift
10066 is pressed, other rows will be unselected.
10068 If CLAMP_NODE is true, then the sheetview will scroll to make the row
10071 pspp_sheet_view_real_set_cursor (PsppSheetView *tree_view,
10073 gboolean clear_and_select,
10074 gboolean clamp_node,
10075 PsppSheetSelectMode mode)
10079 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
10081 GtkTreePath *cursor_path;
10082 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
10083 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
10084 gtk_tree_path_free (cursor_path);
10087 gtk_tree_row_reference_free (tree_view->priv->cursor);
10088 tree_view->priv->cursor = NULL;
10090 _pspp_sheet_view_find_node (tree_view, path, &node);
10091 tree_view->priv->cursor =
10092 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
10093 tree_view->priv->model,
10096 if (tree_view->priv->row_count > 0)
10100 if (clear_and_select && !(mode & PSPP_SHEET_SELECT_MODE_TOGGLE))
10101 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
10105 /* We have to re-find tree and node here again, somebody might have
10106 * cleared the node or the whole tree in the PsppSheetSelection::changed
10107 * callback. If the nodes differ we bail out here.
10109 _pspp_sheet_view_find_node (tree_view, path, &new_node);
10111 if (node != new_node)
10116 pspp_sheet_view_clamp_node_visible (tree_view, node);
10117 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
10121 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
10125 * pspp_sheet_view_get_cursor:
10126 * @tree_view: A #PsppSheetView
10127 * @path: (allow-none): A pointer to be filled with the current cursor path, or %NULL
10128 * @focus_column: (allow-none): A pointer to be filled with the current focus column, or %NULL
10130 * Fills in @path and @focus_column with the current path and focus column. If
10131 * the cursor isn't currently set, then *@path will be %NULL. If no column
10132 * currently has focus, then *@focus_column will be %NULL.
10134 * The returned #GtkTreePath must be freed with gtk_tree_path_free() when
10135 * you are done with it.
10138 pspp_sheet_view_get_cursor (PsppSheetView *tree_view,
10139 GtkTreePath **path,
10140 PsppSheetViewColumn **focus_column)
10142 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10146 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
10147 *path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
10154 *focus_column = tree_view->priv->focus_column;
10159 * pspp_sheet_view_set_cursor:
10160 * @tree_view: A #PsppSheetView
10161 * @path: A #GtkTreePath
10162 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
10163 * @start_editing: %TRUE if the specified cell should start being edited.
10165 * Sets the current keyboard focus to be at @path, and selects it. This is
10166 * useful when you want to focus the user's attention on a particular row. If
10167 * @focus_column is not %NULL, then focus is given to the column specified by
10168 * it. Additionally, if @focus_column is specified, and @start_editing is
10169 * %TRUE, then editing should be started in the specified cell.
10170 * This function is often followed by @gtk_widget_grab_focus (@tree_view)
10171 * in order to give keyboard focus to the widget. Please note that editing
10172 * can only happen when the widget is realized.
10174 * If @path is invalid for @model, the current cursor (if any) will be unset
10175 * and the function will return without failing.
10178 pspp_sheet_view_set_cursor (PsppSheetView *tree_view,
10180 PsppSheetViewColumn *focus_column,
10181 gboolean start_editing)
10183 pspp_sheet_view_set_cursor_on_cell (tree_view, path, focus_column,
10184 NULL, start_editing);
10188 * pspp_sheet_view_set_cursor_on_cell:
10189 * @tree_view: A #PsppSheetView
10190 * @path: A #GtkTreePath
10191 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
10192 * @focus_cell: (allow-none): A #GtkCellRenderer, or %NULL
10193 * @start_editing: %TRUE if the specified cell should start being edited.
10195 * Sets the current keyboard focus to be at @path, and selects it. This is
10196 * useful when you want to focus the user's attention on a particular row. If
10197 * @focus_column is not %NULL, then focus is given to the column specified by
10198 * it. If @focus_column and @focus_cell are not %NULL, and @focus_column
10199 * contains 2 or more editable or activatable cells, then focus is given to
10200 * the cell specified by @focus_cell. Additionally, if @focus_column is
10201 * specified, and @start_editing is %TRUE, then editing should be started in
10202 * the specified cell. This function is often followed by
10203 * @gtk_widget_grab_focus (@tree_view) in order to give keyboard focus to the
10204 * widget. Please note that editing can only happen when the widget is
10207 * If @path is invalid for @model, the current cursor (if any) will be unset
10208 * and the function will return without failing.
10213 pspp_sheet_view_set_cursor_on_cell (PsppSheetView *tree_view,
10215 PsppSheetViewColumn *focus_column,
10216 GtkCellRenderer *focus_cell,
10217 gboolean start_editing)
10219 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10220 g_return_if_fail (path != NULL);
10221 g_return_if_fail (focus_column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (focus_column));
10223 if (!tree_view->priv->model)
10228 g_return_if_fail (focus_column);
10229 g_return_if_fail (GTK_IS_CELL_RENDERER (focus_cell));
10232 /* cancel the current editing, if it exists */
10233 if (tree_view->priv->edited_column &&
10234 tree_view->priv->edited_column->editable_widget)
10235 pspp_sheet_view_stop_editing (tree_view, TRUE);
10237 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, 0);
10239 if (focus_column && focus_column->visible)
10242 gboolean column_in_tree = FALSE;
10244 for (list = tree_view->priv->columns; list; list = list->next)
10245 if (list->data == focus_column)
10247 column_in_tree = TRUE;
10250 g_return_if_fail (column_in_tree);
10251 tree_view->priv->focus_column = focus_column;
10253 pspp_sheet_view_column_focus_cell (focus_column, focus_cell);
10255 pspp_sheet_view_start_editing (tree_view, path);
10257 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
10258 pspp_sheet_selection_select_column (tree_view->priv->selection, focus_column);
10264 * pspp_sheet_view_get_bin_window:
10265 * @tree_view: A #PsppSheetView
10267 * Returns the window that @tree_view renders to. This is used primarily to
10268 * compare to <literal>event->window</literal> to confirm that the event on
10269 * @tree_view is on the right window.
10271 * Return value: A #GdkWindow, or %NULL when @tree_view hasn't been realized yet
10274 pspp_sheet_view_get_bin_window (PsppSheetView *tree_view)
10276 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
10278 return tree_view->priv->bin_window;
10282 * pspp_sheet_view_get_path_at_pos:
10283 * @tree_view: A #PsppSheetView.
10284 * @x: The x position to be identified (relative to bin_window).
10285 * @y: The y position to be identified (relative to bin_window).
10286 * @path: (out) (allow-none): A pointer to a #GtkTreePath pointer to be filled in, or %NULL
10287 * @column: (out) (allow-none): A pointer to a #PsppSheetViewColumn pointer to be filled in, or %NULL
10288 * @cell_x: (out) (allow-none): A pointer where the X coordinate relative to the cell can be placed, or %NULL
10289 * @cell_y: (out) (allow-none): A pointer where the Y coordinate relative to the cell can be placed, or %NULL
10291 * Finds the path at the point (@x, @y), relative to bin_window coordinates
10292 * (please see pspp_sheet_view_get_bin_window()).
10293 * That is, @x and @y are relative to an events coordinates. @x and @y must
10294 * come from an event on the @tree_view only where <literal>event->window ==
10295 * pspp_sheet_view_get_bin_window (<!-- -->)</literal>. It is primarily for
10296 * things like popup menus. If @path is non-%NULL, then it will be filled
10297 * with the #GtkTreePath at that point. This path should be freed with
10298 * gtk_tree_path_free(). If @column is non-%NULL, then it will be filled
10299 * with the column at that point. @cell_x and @cell_y return the coordinates
10300 * relative to the cell background (i.e. the @background_area passed to
10301 * gtk_cell_renderer_render()). This function is only meaningful if
10302 * @tree_view is realized. Therefore this function will always return %FALSE
10303 * if @tree_view is not realized or does not have a model.
10305 * For converting widget coordinates (eg. the ones you get from
10306 * GtkWidget::query-tooltip), please see
10307 * pspp_sheet_view_convert_widget_to_bin_window_coords().
10309 * Return value: %TRUE if a row exists at that coordinate.
10312 pspp_sheet_view_get_path_at_pos (PsppSheetView *tree_view,
10315 GtkTreePath **path,
10316 PsppSheetViewColumn **column,
10323 g_return_val_if_fail (tree_view != NULL, FALSE);
10330 if (tree_view->priv->bin_window == NULL)
10333 if (tree_view->priv->row_count == 0)
10336 if (x > gtk_adjustment_get_upper (tree_view->priv->hadjustment))
10339 if (x < 0 || y < 0)
10342 if (column || cell_x)
10344 PsppSheetViewColumn *tmp_column;
10345 PsppSheetViewColumn *last_column = NULL;
10347 gint remaining_x = x;
10348 gboolean found = FALSE;
10351 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
10352 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
10354 list = (rtl ? list->prev : list->next))
10356 tmp_column = list->data;
10358 if (tmp_column->visible == FALSE)
10361 last_column = tmp_column;
10362 if (remaining_x <= tmp_column->width)
10367 *column = tmp_column;
10370 *cell_x = remaining_x;
10374 remaining_x -= tmp_column->width;
10377 /* If found is FALSE and there is a last_column, then it the remainder
10378 * space is in that area
10385 *column = last_column;
10388 *cell_x = last_column->width + remaining_x;
10397 y_offset = pspp_sheet_view_find_offset (tree_view,
10398 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, y),
10405 *cell_y = y_offset;
10408 *path = _pspp_sheet_view_find_path (tree_view, node);
10413 /* Computes 'cell_area' from 'background_area', which must be the background
10414 area for a cell. Set 'subtract_focus_rect' to TRUE to compute the cell area
10415 as passed to a GtkCellRenderer's "render" function, or to FALSE to compute
10416 the cell area as passed to _pspp_sheet_view_column_cell_render().
10418 'column' is required to properly adjust 'cell_area->x' and
10419 'cell_area->width'. It may be set to NULL if these values are not of
10420 interest. In this case 'cell_area->x' and 'cell_area->width' will be
10423 pspp_sheet_view_adjust_cell_area (PsppSheetView *tree_view,
10424 PsppSheetViewColumn *column,
10425 const GdkRectangle *background_area,
10426 gboolean subtract_focus_rect,
10427 GdkRectangle *cell_area)
10429 gint vertical_separator;
10430 gint horizontal_separator;
10432 *cell_area = *background_area;
10434 gtk_widget_style_get (GTK_WIDGET (tree_view),
10435 "vertical-separator", &vertical_separator,
10436 "horizontal-separator", &horizontal_separator,
10438 cell_area->x += horizontal_separator / 2;
10439 cell_area->y += vertical_separator / 2;
10440 cell_area->width -= horizontal_separator;
10441 cell_area->height -= vertical_separator;
10443 if (subtract_focus_rect)
10445 int focus_line_width;
10447 gtk_widget_style_get (GTK_WIDGET (tree_view),
10448 "focus-line-width", &focus_line_width,
10450 cell_area->x += focus_line_width;
10451 cell_area->y += focus_line_width;
10452 cell_area->width -= 2 * focus_line_width;
10453 cell_area->height -= 2 * focus_line_width;
10456 if (tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_NONE)
10458 gint grid_line_width;
10459 gtk_widget_style_get (GTK_WIDGET (tree_view),
10460 "grid-line-width", &grid_line_width,
10463 if ((tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
10464 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10467 PsppSheetViewColumn *first_column, *last_column;
10470 /* Find the last visible column. */
10471 last_column = NULL;
10472 for (list = g_list_last (tree_view->priv->columns);
10476 PsppSheetViewColumn *c = list->data;
10484 /* Find the first visible column. */
10485 first_column = NULL;
10486 for (list = g_list_first (tree_view->priv->columns);
10490 PsppSheetViewColumn *c = list->data;
10498 if (column == first_column)
10500 cell_area->width -= grid_line_width / 2;
10502 else if (column == last_column)
10504 cell_area->x += grid_line_width / 2;
10505 cell_area->width -= grid_line_width / 2;
10509 cell_area->x += grid_line_width / 2;
10510 cell_area->width -= grid_line_width;
10514 if (tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
10515 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10517 cell_area->y += grid_line_width / 2;
10518 cell_area->height -= grid_line_width;
10522 if (column == NULL)
10525 cell_area->width = 0;
10530 * pspp_sheet_view_get_cell_area:
10531 * @tree_view: a #PsppSheetView
10532 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10533 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordinates
10534 * @rect: rectangle to fill with cell rect
10536 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10537 * row specified by @path and the column specified by @column. If @path is
10538 * %NULL, or points to a path not currently displayed, the @y and @height fields
10539 * of the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10540 * fields will be filled with 0. The sum of all cell rects does not cover the
10541 * entire tree; there are extra pixels in between rows, for example. The
10542 * returned rectangle is equivalent to the @cell_area passed to
10543 * gtk_cell_renderer_render(). This function is only valid if @tree_view is
10547 pspp_sheet_view_get_cell_area (PsppSheetView *tree_view,
10549 PsppSheetViewColumn *column,
10550 GdkRectangle *rect)
10552 GdkRectangle background_area;
10554 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10555 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10556 g_return_if_fail (rect != NULL);
10557 g_return_if_fail (!column || column->tree_view == (GtkWidget *) tree_view);
10558 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
10560 pspp_sheet_view_get_background_area (tree_view, path, column,
10562 pspp_sheet_view_adjust_cell_area (tree_view, column, &background_area,
10567 * pspp_sheet_view_get_background_area:
10568 * @tree_view: a #PsppSheetView
10569 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10570 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordiantes
10571 * @rect: rectangle to fill with cell background rect
10573 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10574 * row specified by @path and the column specified by @column. If @path is
10575 * %NULL, or points to a node not found in the tree, the @y and @height fields of
10576 * the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10577 * fields will be filled with 0. The returned rectangle is equivalent to the
10578 * @background_area passed to gtk_cell_renderer_render(). These background
10579 * areas tile to cover the entire bin window. Contrast with the @cell_area,
10580 * returned by pspp_sheet_view_get_cell_area(), which returns only the cell
10581 * itself, excluding surrounding borders.
10585 pspp_sheet_view_get_background_area (PsppSheetView *tree_view,
10587 PsppSheetViewColumn *column,
10588 GdkRectangle *rect)
10592 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10593 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10594 g_return_if_fail (rect != NULL);
10603 /* Get vertical coords */
10605 _pspp_sheet_view_find_node (tree_view, path, &node);
10609 rect->y = BACKGROUND_FIRST_PIXEL (tree_view, node);
10611 rect->height = ROW_HEIGHT (tree_view);
10618 pspp_sheet_view_get_background_xrange (tree_view, column, &rect->x, &x2);
10619 rect->width = x2 - rect->x;
10624 * pspp_sheet_view_get_visible_rect:
10625 * @tree_view: a #PsppSheetView
10626 * @visible_rect: rectangle to fill
10628 * Fills @visible_rect with the currently-visible region of the
10629 * buffer, in tree coordinates. Convert to bin_window coordinates with
10630 * pspp_sheet_view_convert_tree_to_bin_window_coords().
10631 * Tree coordinates start at 0,0 for row 0 of the tree, and cover the entire
10632 * scrollable area of the tree.
10635 pspp_sheet_view_get_visible_rect (PsppSheetView *tree_view,
10636 GdkRectangle *visible_rect)
10640 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10642 widget = GTK_WIDGET (tree_view);
10646 GtkAllocation allocation;
10647 gtk_widget_get_allocation (widget, &allocation);
10648 visible_rect->x = gtk_adjustment_get_value (tree_view->priv->hadjustment);
10649 visible_rect->y = gtk_adjustment_get_value (tree_view->priv->vadjustment);
10650 visible_rect->width = allocation.width;
10651 visible_rect->height = allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
10656 * pspp_sheet_view_widget_to_tree_coords:
10657 * @tree_view: a #PsppSheetView
10658 * @wx: X coordinate relative to bin_window
10659 * @wy: Y coordinate relative to bin_window
10660 * @tx: return location for tree X coordinate
10661 * @ty: return location for tree Y coordinate
10663 * Converts bin_window coordinates to coordinates for the
10664 * tree (the full scrollable area of the tree).
10666 * Deprecated: 2.12: Due to historial reasons the name of this function is
10667 * incorrect. For converting coordinates relative to the widget to
10668 * bin_window coordinates, please see
10669 * pspp_sheet_view_convert_widget_to_bin_window_coords().
10673 pspp_sheet_view_widget_to_tree_coords (PsppSheetView *tree_view,
10679 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10682 *tx = wx + gtk_adjustment_get_value (tree_view->priv->hadjustment);
10684 *ty = wy + tree_view->priv->dy;
10688 * pspp_sheet_view_tree_to_widget_coords:
10689 * @tree_view: a #PsppSheetView
10690 * @tx: tree X coordinate
10691 * @ty: tree Y coordinate
10692 * @wx: return location for X coordinate relative to bin_window
10693 * @wy: return location for Y coordinate relative to bin_window
10695 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10696 * to bin_window coordinates.
10698 * Deprecated: 2.12: Due to historial reasons the name of this function is
10699 * incorrect. For converting bin_window coordinates to coordinates relative
10700 * to bin_window, please see
10701 * pspp_sheet_view_convert_bin_window_to_widget_coords().
10705 pspp_sheet_view_tree_to_widget_coords (PsppSheetView *tree_view,
10711 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10714 *wx = tx - gtk_adjustment_get_value (tree_view->priv->hadjustment);
10716 *wy = ty - tree_view->priv->dy;
10721 * pspp_sheet_view_convert_widget_to_tree_coords:
10722 * @tree_view: a #PsppSheetView
10723 * @wx: X coordinate relative to the widget
10724 * @wy: Y coordinate relative to the widget
10725 * @tx: return location for tree X coordinate
10726 * @ty: return location for tree Y coordinate
10728 * Converts widget coordinates to coordinates for the
10729 * tree (the full scrollable area of the tree).
10734 pspp_sheet_view_convert_widget_to_tree_coords (PsppSheetView *tree_view,
10742 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10744 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view,
10747 pspp_sheet_view_convert_bin_window_to_tree_coords (tree_view,
10753 * pspp_sheet_view_convert_tree_to_widget_coords:
10754 * @tree_view: a #PsppSheetView
10755 * @tx: X coordinate relative to the tree
10756 * @ty: Y coordinate relative to the tree
10757 * @wx: return location for widget X coordinate
10758 * @wy: return location for widget Y coordinate
10760 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10761 * to widget coordinates.
10766 pspp_sheet_view_convert_tree_to_widget_coords (PsppSheetView *tree_view,
10774 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10776 pspp_sheet_view_convert_tree_to_bin_window_coords (tree_view,
10779 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
10785 * pspp_sheet_view_convert_widget_to_bin_window_coords:
10786 * @tree_view: a #PsppSheetView
10787 * @wx: X coordinate relative to the widget
10788 * @wy: Y coordinate relative to the widget
10789 * @bx: return location for bin_window X coordinate
10790 * @by: return location for bin_window Y coordinate
10792 * Converts widget coordinates to coordinates for the bin_window
10793 * (see pspp_sheet_view_get_bin_window()).
10798 pspp_sheet_view_convert_widget_to_bin_window_coords (PsppSheetView *tree_view,
10804 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10807 *bx = wx + gtk_adjustment_get_value (tree_view->priv->hadjustment);
10809 *by = wy - TREE_VIEW_HEADER_HEIGHT (tree_view);
10813 * pspp_sheet_view_convert_bin_window_to_widget_coords:
10814 * @tree_view: a #PsppSheetView
10815 * @bx: bin_window X coordinate
10816 * @by: bin_window Y coordinate
10817 * @wx: return location for widget X coordinate
10818 * @wy: return location for widget Y coordinate
10820 * Converts bin_window coordinates (see pspp_sheet_view_get_bin_window())
10821 * to widget relative coordinates.
10826 pspp_sheet_view_convert_bin_window_to_widget_coords (PsppSheetView *tree_view,
10832 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10835 *wx = bx - gtk_adjustment_get_value (tree_view->priv->hadjustment);
10837 *wy = by + TREE_VIEW_HEADER_HEIGHT (tree_view);
10841 * pspp_sheet_view_convert_tree_to_bin_window_coords:
10842 * @tree_view: a #PsppSheetView
10843 * @tx: tree X coordinate
10844 * @ty: tree Y coordinate
10845 * @bx: return location for X coordinate relative to bin_window
10846 * @by: return location for Y coordinate relative to bin_window
10848 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10849 * to bin_window coordinates.
10854 pspp_sheet_view_convert_tree_to_bin_window_coords (PsppSheetView *tree_view,
10860 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10865 *by = ty - tree_view->priv->dy;
10869 * pspp_sheet_view_convert_bin_window_to_tree_coords:
10870 * @tree_view: a #PsppSheetView
10871 * @bx: X coordinate relative to bin_window
10872 * @by: Y coordinate relative to bin_window
10873 * @tx: return location for tree X coordinate
10874 * @ty: return location for tree Y coordinate
10876 * Converts bin_window coordinates to coordinates for the
10877 * tree (the full scrollable area of the tree).
10882 pspp_sheet_view_convert_bin_window_to_tree_coords (PsppSheetView *tree_view,
10888 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10893 *ty = by + tree_view->priv->dy;
10899 * pspp_sheet_view_get_visible_range:
10900 * @tree_view: A #PsppSheetView
10901 * @start_path: (allow-none): Return location for start of region, or %NULL.
10902 * @end_path: (allow-none): Return location for end of region, or %NULL.
10904 * Sets @start_path and @end_path to be the first and last visible path.
10905 * Note that there may be invisible paths in between.
10907 * The paths should be freed with gtk_tree_path_free() after use.
10909 * Returns: %TRUE, if valid paths were placed in @start_path and @end_path.
10914 pspp_sheet_view_get_visible_range (PsppSheetView *tree_view,
10915 GtkTreePath **start_path,
10916 GtkTreePath **end_path)
10921 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
10923 if (!tree_view->priv->row_count)
10930 pspp_sheet_view_find_offset (tree_view,
10931 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, 0),
10934 *start_path = _pspp_sheet_view_find_path (tree_view, node);
10943 if (tree_view->priv->height < gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
10944 y = tree_view->priv->height - 1;
10946 y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, gtk_adjustment_get_page_size (tree_view->priv->vadjustment)) - 1;
10948 pspp_sheet_view_find_offset (tree_view, y, &node);
10950 *end_path = _pspp_sheet_view_find_path (tree_view, node);
10959 unset_reorderable (PsppSheetView *tree_view)
10961 if (tree_view->priv->reorderable)
10963 tree_view->priv->reorderable = FALSE;
10964 g_object_notify (G_OBJECT (tree_view), "reorderable");
10969 * pspp_sheet_view_enable_model_drag_source:
10970 * @tree_view: a #PsppSheetView
10971 * @start_button_mask: Mask of allowed buttons to start drag
10972 * @targets: the table of targets that the drag will support
10973 * @n_targets: the number of items in @targets
10974 * @actions: the bitmask of possible actions for a drag from this
10977 * Turns @tree_view into a drag source for automatic DND. Calling this
10978 * method sets #PsppSheetView:reorderable to %FALSE.
10981 pspp_sheet_view_enable_model_drag_source (PsppSheetView *tree_view,
10982 GdkModifierType start_button_mask,
10983 const GtkTargetEntry *targets,
10985 GdkDragAction actions)
10987 TreeViewDragInfo *di;
10989 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10991 gtk_drag_source_set (GTK_WIDGET (tree_view),
10997 di = ensure_info (tree_view);
10999 di->start_button_mask = start_button_mask;
11000 di->source_actions = actions;
11001 di->source_set = TRUE;
11003 unset_reorderable (tree_view);
11007 * pspp_sheet_view_enable_model_drag_dest:
11008 * @tree_view: a #PsppSheetView
11009 * @targets: the table of targets that the drag will support
11010 * @n_targets: the number of items in @targets
11011 * @actions: the bitmask of possible actions for a drag from this
11014 * Turns @tree_view into a drop destination for automatic DND. Calling
11015 * this method sets #PsppSheetView:reorderable to %FALSE.
11018 pspp_sheet_view_enable_model_drag_dest (PsppSheetView *tree_view,
11019 const GtkTargetEntry *targets,
11021 GdkDragAction actions)
11023 TreeViewDragInfo *di;
11025 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11027 gtk_drag_dest_set (GTK_WIDGET (tree_view),
11033 di = ensure_info (tree_view);
11034 di->dest_set = TRUE;
11036 unset_reorderable (tree_view);
11040 * pspp_sheet_view_unset_rows_drag_source:
11041 * @tree_view: a #PsppSheetView
11043 * Undoes the effect of
11044 * pspp_sheet_view_enable_model_drag_source(). Calling this method sets
11045 * #PsppSheetView:reorderable to %FALSE.
11048 pspp_sheet_view_unset_rows_drag_source (PsppSheetView *tree_view)
11050 TreeViewDragInfo *di;
11052 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11054 di = get_info (tree_view);
11058 if (di->source_set)
11060 gtk_drag_source_unset (GTK_WIDGET (tree_view));
11061 di->source_set = FALSE;
11064 if (!di->dest_set && !di->source_set)
11065 remove_info (tree_view);
11068 unset_reorderable (tree_view);
11072 * pspp_sheet_view_unset_rows_drag_dest:
11073 * @tree_view: a #PsppSheetView
11075 * Undoes the effect of
11076 * pspp_sheet_view_enable_model_drag_dest(). Calling this method sets
11077 * #PsppSheetView:reorderable to %FALSE.
11080 pspp_sheet_view_unset_rows_drag_dest (PsppSheetView *tree_view)
11082 TreeViewDragInfo *di;
11084 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11086 di = get_info (tree_view);
11092 gtk_drag_dest_unset (GTK_WIDGET (tree_view));
11093 di->dest_set = FALSE;
11096 if (!di->dest_set && !di->source_set)
11097 remove_info (tree_view);
11100 unset_reorderable (tree_view);
11104 * pspp_sheet_view_set_drag_dest_row:
11105 * @tree_view: a #PsppSheetView
11106 * @path: (allow-none): The path of the row to highlight, or %NULL.
11107 * @pos: Specifies whether to drop before, after or into the row
11109 * Sets the row that is highlighted for feedback.
11112 pspp_sheet_view_set_drag_dest_row (PsppSheetView *tree_view,
11114 PsppSheetViewDropPosition pos)
11116 GtkTreePath *current_dest;
11118 /* Note; this function is exported to allow a custom DND
11119 * implementation, so it can't touch TreeViewDragInfo
11122 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11124 current_dest = NULL;
11126 if (tree_view->priv->drag_dest_row)
11128 current_dest = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
11129 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
11132 /* special case a drop on an empty model */
11133 tree_view->priv->empty_view_drop = 0;
11135 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE && path
11136 && gtk_tree_path_get_depth (path) == 1
11137 && gtk_tree_path_get_indices (path)[0] == 0)
11141 n_children = gtk_tree_model_iter_n_children (tree_view->priv->model,
11145 tree_view->priv->empty_view_drop = 1;
11148 tree_view->priv->drag_dest_pos = pos;
11152 tree_view->priv->drag_dest_row =
11153 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
11154 pspp_sheet_view_queue_draw_path (tree_view, path, NULL);
11157 tree_view->priv->drag_dest_row = NULL;
11161 int node, new_node;
11163 _pspp_sheet_view_find_node (tree_view, current_dest, &node);
11164 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
11168 new_node = pspp_sheet_view_node_next (tree_view, node);
11170 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
11172 new_node = pspp_sheet_view_node_prev (tree_view, node);
11174 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
11176 gtk_tree_path_free (current_dest);
11181 * pspp_sheet_view_get_drag_dest_row:
11182 * @tree_view: a #PsppSheetView
11183 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
11184 * @pos: (allow-none): Return location for the drop position, or %NULL
11186 * Gets information about the row that is highlighted for feedback.
11189 pspp_sheet_view_get_drag_dest_row (PsppSheetView *tree_view,
11190 GtkTreePath **path,
11191 PsppSheetViewDropPosition *pos)
11193 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11197 if (tree_view->priv->drag_dest_row)
11198 *path = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
11201 if (tree_view->priv->empty_view_drop)
11202 *path = gtk_tree_path_new_from_indices (0, -1);
11209 *pos = tree_view->priv->drag_dest_pos;
11213 * pspp_sheet_view_get_dest_row_at_pos:
11214 * @tree_view: a #PsppSheetView
11215 * @drag_x: the position to determine the destination row for
11216 * @drag_y: the position to determine the destination row for
11217 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
11218 * @pos: (allow-none): Return location for the drop position, or %NULL
11220 * Determines the destination row for a given position. @drag_x and
11221 * @drag_y are expected to be in widget coordinates. This function is only
11222 * meaningful if @tree_view is realized. Therefore this function will always
11223 * return %FALSE if @tree_view is not realized or does not have a model.
11225 * Return value: whether there is a row at the given position, %TRUE if this
11226 * is indeed the case.
11229 pspp_sheet_view_get_dest_row_at_pos (PsppSheetView *tree_view,
11232 GtkTreePath **path,
11233 PsppSheetViewDropPosition *pos)
11237 gdouble offset_into_row;
11240 PsppSheetViewColumn *column = NULL;
11241 GtkTreePath *tmp_path = NULL;
11243 /* Note; this function is exported to allow a custom DND
11244 * implementation, so it can't touch TreeViewDragInfo
11247 g_return_val_if_fail (tree_view != NULL, FALSE);
11248 g_return_val_if_fail (drag_x >= 0, FALSE);
11249 g_return_val_if_fail (drag_y >= 0, FALSE);
11254 if (tree_view->priv->bin_window == NULL)
11257 if (tree_view->priv->row_count == 0)
11260 /* If in the top third of a row, we drop before that row; if
11261 * in the bottom third, drop after that row; if in the middle,
11262 * and the row has children, drop into the row.
11264 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, drag_x, drag_y,
11267 if (!pspp_sheet_view_get_path_at_pos (tree_view,
11276 pspp_sheet_view_get_background_area (tree_view, tmp_path, column,
11279 offset_into_row = cell_y;
11284 gtk_tree_path_free (tmp_path);
11288 third = cell.height / 3.0;
11292 if (offset_into_row < third)
11294 *pos = PSPP_SHEET_VIEW_DROP_BEFORE;
11296 else if (offset_into_row < (cell.height / 2.0))
11298 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE;
11300 else if (offset_into_row < third * 2.0)
11302 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER;
11306 *pos = PSPP_SHEET_VIEW_DROP_AFTER;
11314 #if GTK3_TRANSITION
11315 /* KEEP IN SYNC WITH PSPP_SHEET_VIEW_BIN_EXPOSE */
11317 * pspp_sheet_view_create_row_drag_icon:
11318 * @tree_view: a #PsppSheetView
11319 * @path: a #GtkTreePath in @tree_view
11321 * Creates a #GdkPixmap representation of the row at @path.
11322 * This image is used for a drag icon.
11324 * Return value: a newly-allocated pixmap of the drag icon.
11327 pspp_sheet_view_create_row_drag_icon (PsppSheetView *tree_view,
11334 GdkRectangle background_area;
11335 GdkRectangle expose_area;
11337 /* start drawing inside the black outline */
11339 GdkDrawable *drawable;
11340 gint bin_window_width;
11343 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11344 g_return_val_if_fail (path != NULL, NULL);
11346 widget = GTK_WIDGET (tree_view);
11348 if (!gtk_widget_get_realized (widget))
11351 _pspp_sheet_view_find_node (tree_view,
11358 if (!gtk_tree_model_get_iter (tree_view->priv->model,
11365 background_area.y = y;
11366 background_area.height = ROW_HEIGHT (tree_view);
11368 bin_window_width = gdk_window_get_width (tree_view->priv->bin_window);
11370 drawable = gdk_pixmap_new (tree_view->priv->bin_window,
11371 bin_window_width + 2,
11372 background_area.height + 2,
11377 expose_area.width = bin_window_width + 2;
11378 expose_area.height = background_area.height + 2;
11380 #if GTK3_TRANSITION
11381 gdk_draw_rectangle (drawable,
11382 widget->style->base_gc [gtk_widget_get_state (widget)],
11385 bin_window_width + 2,
11386 background_area.height + 2);
11389 rtl = gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL;
11391 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
11393 list = (rtl ? list->prev : list->next))
11395 PsppSheetViewColumn *column = list->data;
11396 GdkRectangle cell_area;
11397 gint vertical_separator;
11399 if (!column->visible)
11402 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, &iter);
11404 background_area.x = cell_offset;
11405 background_area.width = column->width;
11407 gtk_widget_style_get (widget,
11408 "vertical-separator", &vertical_separator,
11411 cell_area = background_area;
11413 cell_area.y += vertical_separator / 2;
11414 cell_area.height -= vertical_separator;
11416 if (pspp_sheet_view_column_cell_is_visible (column))
11417 _pspp_sheet_view_column_cell_render (column,
11423 cell_offset += column->width;
11426 #if GTK3_TRANSITION
11427 gdk_draw_rectangle (drawable,
11428 widget->style->black_gc,
11431 bin_window_width + 1,
11432 background_area.height + 1);
11440 * pspp_sheet_view_set_destroy_count_func:
11441 * @tree_view: A #PsppSheetView
11442 * @func: (allow-none): Function to be called when a view row is destroyed, or %NULL
11443 * @data: (allow-none): User data to be passed to @func, or %NULL
11444 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11446 * This function should almost never be used. It is meant for private use by
11447 * ATK for determining the number of visible children that are removed when a row is deleted.
11450 pspp_sheet_view_set_destroy_count_func (PsppSheetView *tree_view,
11451 PsppSheetDestroyCountFunc func,
11453 GDestroyNotify destroy)
11455 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11457 if (tree_view->priv->destroy_count_destroy)
11458 tree_view->priv->destroy_count_destroy (tree_view->priv->destroy_count_data);
11460 tree_view->priv->destroy_count_func = func;
11461 tree_view->priv->destroy_count_data = data;
11462 tree_view->priv->destroy_count_destroy = destroy;
11467 * Interactive search
11471 * pspp_sheet_view_set_enable_search:
11472 * @tree_view: A #PsppSheetView
11473 * @enable_search: %TRUE, if the user can search interactively
11475 * If @enable_search is set, then the user can type in text to search through
11476 * the tree interactively (this is sometimes called "typeahead find").
11478 * Note that even if this is %FALSE, the user can still initiate a search
11479 * using the "start-interactive-search" key binding.
11482 pspp_sheet_view_set_enable_search (PsppSheetView *tree_view,
11483 gboolean enable_search)
11485 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11487 enable_search = !!enable_search;
11489 if (tree_view->priv->enable_search != enable_search)
11491 tree_view->priv->enable_search = enable_search;
11492 g_object_notify (G_OBJECT (tree_view), "enable-search");
11497 * pspp_sheet_view_get_enable_search:
11498 * @tree_view: A #PsppSheetView
11500 * Returns whether or not the tree allows to start interactive searching
11501 * by typing in text.
11503 * Return value: whether or not to let the user search interactively
11506 pspp_sheet_view_get_enable_search (PsppSheetView *tree_view)
11508 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11510 return tree_view->priv->enable_search;
11515 * pspp_sheet_view_get_search_column:
11516 * @tree_view: A #PsppSheetView
11518 * Gets the column searched on by the interactive search code.
11520 * Return value: the column the interactive search code searches in.
11523 pspp_sheet_view_get_search_column (PsppSheetView *tree_view)
11525 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
11527 return (tree_view->priv->search_column);
11531 * pspp_sheet_view_set_search_column:
11532 * @tree_view: A #PsppSheetView
11533 * @column: the column of the model to search in, or -1 to disable searching
11535 * Sets @column as the column where the interactive search code should
11536 * search in for the current model.
11538 * If the search column is set, users can use the "start-interactive-search"
11539 * key binding to bring up search popup. The enable-search property controls
11540 * whether simply typing text will also start an interactive search.
11542 * Note that @column refers to a column of the current model. The search
11543 * column is reset to -1 when the model is changed.
11546 pspp_sheet_view_set_search_column (PsppSheetView *tree_view,
11549 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11550 g_return_if_fail (column >= -1);
11552 if (tree_view->priv->search_column == column)
11555 tree_view->priv->search_column = column;
11556 g_object_notify (G_OBJECT (tree_view), "search-column");
11560 * pspp_sheet_view_get_search_equal_func:
11561 * @tree_view: A #PsppSheetView
11563 * Returns the compare function currently in use.
11565 * Return value: the currently used compare function for the search code.
11568 PsppSheetViewSearchEqualFunc
11569 pspp_sheet_view_get_search_equal_func (PsppSheetView *tree_view)
11571 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11573 return tree_view->priv->search_equal_func;
11577 * pspp_sheet_view_set_search_equal_func:
11578 * @tree_view: A #PsppSheetView
11579 * @search_equal_func: the compare function to use during the search
11580 * @search_user_data: (allow-none): user data to pass to @search_equal_func, or %NULL
11581 * @search_destroy: (allow-none): Destroy notifier for @search_user_data, or %NULL
11583 * Sets the compare function for the interactive search capabilities; note
11584 * that somewhat like strcmp() returning 0 for equality
11585 * #PsppSheetViewSearchEqualFunc returns %FALSE on matches.
11588 pspp_sheet_view_set_search_equal_func (PsppSheetView *tree_view,
11589 PsppSheetViewSearchEqualFunc search_equal_func,
11590 gpointer search_user_data,
11591 GDestroyNotify search_destroy)
11593 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11594 g_return_if_fail (search_equal_func != NULL);
11596 if (tree_view->priv->search_destroy)
11597 tree_view->priv->search_destroy (tree_view->priv->search_user_data);
11599 tree_view->priv->search_equal_func = search_equal_func;
11600 tree_view->priv->search_user_data = search_user_data;
11601 tree_view->priv->search_destroy = search_destroy;
11602 if (tree_view->priv->search_equal_func == NULL)
11603 tree_view->priv->search_equal_func = pspp_sheet_view_search_equal_func;
11607 * pspp_sheet_view_get_search_entry:
11608 * @tree_view: A #PsppSheetView
11610 * Returns the #GtkEntry which is currently in use as interactive search
11611 * entry for @tree_view. In case the built-in entry is being used, %NULL
11612 * will be returned.
11614 * Return value: the entry currently in use as search entry.
11619 pspp_sheet_view_get_search_entry (PsppSheetView *tree_view)
11621 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11623 if (tree_view->priv->search_custom_entry_set)
11624 return GTK_ENTRY (tree_view->priv->search_entry);
11630 * pspp_sheet_view_set_search_entry:
11631 * @tree_view: A #PsppSheetView
11632 * @entry: (allow-none): the entry the interactive search code of @tree_view should use or %NULL
11634 * Sets the entry which the interactive search code will use for this
11635 * @tree_view. This is useful when you want to provide a search entry
11636 * in our interface at all time at a fixed position. Passing %NULL for
11637 * @entry will make the interactive search code use the built-in popup
11643 pspp_sheet_view_set_search_entry (PsppSheetView *tree_view,
11646 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11647 g_return_if_fail (entry == NULL || GTK_IS_ENTRY (entry));
11649 if (tree_view->priv->search_custom_entry_set)
11651 if (tree_view->priv->search_entry_changed_id)
11653 g_signal_handler_disconnect (tree_view->priv->search_entry,
11654 tree_view->priv->search_entry_changed_id);
11655 tree_view->priv->search_entry_changed_id = 0;
11657 g_signal_handlers_disconnect_by_func (tree_view->priv->search_entry,
11658 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11661 g_object_unref (tree_view->priv->search_entry);
11663 else if (tree_view->priv->search_window)
11665 gtk_widget_destroy (tree_view->priv->search_window);
11667 tree_view->priv->search_window = NULL;
11672 tree_view->priv->search_entry = g_object_ref (entry);
11673 tree_view->priv->search_custom_entry_set = TRUE;
11675 if (tree_view->priv->search_entry_changed_id == 0)
11677 tree_view->priv->search_entry_changed_id =
11678 g_signal_connect (tree_view->priv->search_entry, "changed",
11679 G_CALLBACK (pspp_sheet_view_search_init),
11683 g_signal_connect (tree_view->priv->search_entry, "key-press-event",
11684 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11687 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
11691 tree_view->priv->search_entry = NULL;
11692 tree_view->priv->search_custom_entry_set = FALSE;
11697 * pspp_sheet_view_set_search_position_func:
11698 * @tree_view: A #PsppSheetView
11699 * @func: (allow-none): the function to use to position the search dialog, or %NULL
11700 * to use the default search position function
11701 * @data: (allow-none): user data to pass to @func, or %NULL
11702 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11704 * Sets the function to use when positioning the search dialog.
11709 pspp_sheet_view_set_search_position_func (PsppSheetView *tree_view,
11710 PsppSheetViewSearchPositionFunc func,
11711 gpointer user_data,
11712 GDestroyNotify destroy)
11714 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11716 if (tree_view->priv->search_position_destroy)
11717 tree_view->priv->search_position_destroy (tree_view->priv->search_position_user_data);
11719 tree_view->priv->search_position_func = func;
11720 tree_view->priv->search_position_user_data = user_data;
11721 tree_view->priv->search_position_destroy = destroy;
11722 if (tree_view->priv->search_position_func == NULL)
11723 tree_view->priv->search_position_func = pspp_sheet_view_search_position_func;
11727 * pspp_sheet_view_get_search_position_func:
11728 * @tree_view: A #PsppSheetView
11730 * Returns the positioning function currently in use.
11732 * Return value: the currently used function for positioning the search dialog.
11736 PsppSheetViewSearchPositionFunc
11737 pspp_sheet_view_get_search_position_func (PsppSheetView *tree_view)
11739 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11741 return tree_view->priv->search_position_func;
11746 pspp_sheet_view_search_dialog_hide (GtkWidget *search_dialog,
11747 PsppSheetView *tree_view)
11749 if (tree_view->priv->disable_popdown)
11752 if (tree_view->priv->search_entry_changed_id)
11754 g_signal_handler_disconnect (tree_view->priv->search_entry,
11755 tree_view->priv->search_entry_changed_id);
11756 tree_view->priv->search_entry_changed_id = 0;
11758 if (tree_view->priv->typeselect_flush_timeout)
11760 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11761 tree_view->priv->typeselect_flush_timeout = 0;
11764 if (gtk_widget_get_visible (search_dialog))
11766 /* send focus-in event */
11767 send_focus_change (GTK_WIDGET (tree_view->priv->search_entry), FALSE);
11768 gtk_widget_hide (search_dialog);
11769 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
11770 send_focus_change (GTK_WIDGET (tree_view), TRUE);
11775 pspp_sheet_view_search_position_func (PsppSheetView *tree_view,
11776 GtkWidget *search_dialog,
11777 gpointer user_data)
11780 gint tree_x, tree_y;
11781 gint tree_width, tree_height;
11782 GdkWindow *tree_window = gtk_widget_get_window (GTK_WIDGET (tree_view));
11783 GdkScreen *screen = gdk_window_get_screen (tree_window);
11784 GtkRequisition requisition;
11786 GdkRectangle monitor;
11788 monitor_num = gdk_screen_get_monitor_at_window (screen, tree_window);
11789 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
11791 gtk_widget_realize (search_dialog);
11793 gdk_window_get_origin (tree_window, &tree_x, &tree_y);
11794 tree_width = gdk_window_get_width (tree_window);
11795 tree_height = gdk_window_get_height (tree_window);
11797 gtk_widget_size_request (search_dialog, &requisition);
11799 if (tree_x + tree_width > gdk_screen_get_width (screen))
11800 x = gdk_screen_get_width (screen) - requisition.width;
11801 else if (tree_x + tree_width - requisition.width < 0)
11804 x = tree_x + tree_width - requisition.width;
11806 if (tree_y + tree_height + requisition.height > gdk_screen_get_height (screen))
11807 y = gdk_screen_get_height (screen) - requisition.height;
11808 else if (tree_y + tree_height < 0) /* isn't really possible ... */
11811 y = tree_y + tree_height;
11813 gtk_window_move (GTK_WINDOW (search_dialog), x, y);
11817 pspp_sheet_view_search_disable_popdown (GtkEntry *entry,
11821 PsppSheetView *tree_view = (PsppSheetView *)data;
11823 tree_view->priv->disable_popdown = 1;
11824 g_signal_connect (menu, "hide",
11825 G_CALLBACK (pspp_sheet_view_search_enable_popdown), data);
11828 #if GTK3_TRANSITION
11829 /* Because we're visible but offscreen, we just set a flag in the preedit
11833 pspp_sheet_view_search_preedit_changed (GtkIMContext *im_context,
11834 PsppSheetView *tree_view)
11836 tree_view->priv->imcontext_changed = 1;
11837 if (tree_view->priv->typeselect_flush_timeout)
11839 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11840 tree_view->priv->typeselect_flush_timeout =
11841 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11842 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11850 pspp_sheet_view_search_activate (GtkEntry *entry,
11851 PsppSheetView *tree_view)
11856 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window,
11859 /* If we have a row selected and it's the cursor row, we activate
11861 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
11863 path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
11865 _pspp_sheet_view_find_node (tree_view, path, &node);
11867 if (node >= 0 && pspp_sheet_view_node_is_selected (tree_view, node))
11868 pspp_sheet_view_row_activated (tree_view, path, tree_view->priv->focus_column);
11870 gtk_tree_path_free (path);
11875 pspp_sheet_view_real_search_enable_popdown (gpointer data)
11877 PsppSheetView *tree_view = (PsppSheetView *)data;
11879 tree_view->priv->disable_popdown = 0;
11885 pspp_sheet_view_search_enable_popdown (GtkWidget *widget,
11888 gdk_threads_add_timeout_full (G_PRIORITY_HIGH, 200, pspp_sheet_view_real_search_enable_popdown, g_object_ref (data), g_object_unref);
11892 pspp_sheet_view_search_delete_event (GtkWidget *widget,
11893 GdkEventAny *event,
11894 PsppSheetView *tree_view)
11896 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11898 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11904 pspp_sheet_view_search_button_press_event (GtkWidget *widget,
11905 GdkEventButton *event,
11906 PsppSheetView *tree_view)
11908 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11910 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11912 if (event->window == tree_view->priv->bin_window)
11913 pspp_sheet_view_button_press (GTK_WIDGET (tree_view), event);
11919 pspp_sheet_view_search_scroll_event (GtkWidget *widget,
11920 GdkEventScroll *event,
11921 PsppSheetView *tree_view)
11923 gboolean retval = FALSE;
11925 if (event->direction == GDK_SCROLL_UP)
11927 pspp_sheet_view_search_move (widget, tree_view, TRUE);
11930 else if (event->direction == GDK_SCROLL_DOWN)
11932 pspp_sheet_view_search_move (widget, tree_view, FALSE);
11936 /* renew the flush timeout */
11937 if (retval && tree_view->priv->typeselect_flush_timeout
11938 && !tree_view->priv->search_custom_entry_set)
11940 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11941 tree_view->priv->typeselect_flush_timeout =
11942 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11943 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11951 pspp_sheet_view_search_key_press_event (GtkWidget *widget,
11952 GdkEventKey *event,
11953 PsppSheetView *tree_view)
11955 gboolean retval = FALSE;
11957 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11958 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11960 /* close window and cancel the search */
11961 if (!tree_view->priv->search_custom_entry_set
11962 && (event->keyval == GDK_Escape ||
11963 event->keyval == GDK_Tab ||
11964 event->keyval == GDK_KP_Tab ||
11965 event->keyval == GDK_ISO_Left_Tab))
11967 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11971 /* select previous matching iter */
11972 if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up)
11974 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
11975 gtk_widget_error_bell (widget);
11980 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK))
11981 && (event->keyval == GDK_g || event->keyval == GDK_G))
11983 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
11984 gtk_widget_error_bell (widget);
11989 /* select next matching iter */
11990 if (event->keyval == GDK_Down || event->keyval == GDK_KP_Down)
11992 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
11993 gtk_widget_error_bell (widget);
11998 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == GTK_DEFAULT_ACCEL_MOD_MASK)
11999 && (event->keyval == GDK_g || event->keyval == GDK_G))
12001 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
12002 gtk_widget_error_bell (widget);
12007 /* renew the flush timeout */
12008 if (retval && tree_view->priv->typeselect_flush_timeout
12009 && !tree_view->priv->search_custom_entry_set)
12011 g_source_remove (tree_view->priv->typeselect_flush_timeout);
12012 tree_view->priv->typeselect_flush_timeout =
12013 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
12014 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
12021 /* this function returns FALSE if there is a search string but
12022 * nothing was found, and TRUE otherwise.
12025 pspp_sheet_view_search_move (GtkWidget *window,
12026 PsppSheetView *tree_view,
12034 GtkTreeModel *model;
12035 PsppSheetSelection *selection;
12037 text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
12039 g_return_val_if_fail (text != NULL, FALSE);
12041 len = strlen (text);
12043 if (up && tree_view->priv->selected_iter == 1)
12044 return strlen (text) < 1;
12046 len = strlen (text);
12051 model = pspp_sheet_view_get_model (tree_view);
12052 selection = pspp_sheet_view_get_selection (tree_view);
12055 pspp_sheet_selection_unselect_all (selection);
12056 if (!gtk_tree_model_get_iter_first (model, &iter))
12059 ret = pspp_sheet_view_search_iter (model, selection, &iter, text,
12060 &count, up?((tree_view->priv->selected_iter) - 1):((tree_view->priv->selected_iter + 1)));
12065 tree_view->priv->selected_iter += up?(-1):(1);
12070 /* return to old iter */
12072 gtk_tree_model_get_iter_first (model, &iter);
12073 pspp_sheet_view_search_iter (model, selection,
12075 &count, tree_view->priv->selected_iter);
12081 pspp_sheet_view_search_equal_func (GtkTreeModel *model,
12085 gpointer search_data)
12087 gboolean retval = TRUE;
12089 gchar *normalized_string;
12090 gchar *normalized_key;
12091 gchar *case_normalized_string = NULL;
12092 gchar *case_normalized_key = NULL;
12093 GValue value = {0,};
12094 GValue transformed = {0,};
12096 gtk_tree_model_get_value (model, iter, column, &value);
12098 g_value_init (&transformed, G_TYPE_STRING);
12100 if (!g_value_transform (&value, &transformed))
12102 g_value_unset (&value);
12106 g_value_unset (&value);
12108 str = g_value_get_string (&transformed);
12111 g_value_unset (&transformed);
12115 normalized_string = g_utf8_normalize (str, -1, G_NORMALIZE_ALL);
12116 normalized_key = g_utf8_normalize (key, -1, G_NORMALIZE_ALL);
12118 if (normalized_string && normalized_key)
12120 case_normalized_string = g_utf8_casefold (normalized_string, -1);
12121 case_normalized_key = g_utf8_casefold (normalized_key, -1);
12123 if (strncmp (case_normalized_key, case_normalized_string, strlen (case_normalized_key)) == 0)
12127 g_value_unset (&transformed);
12128 g_free (normalized_key);
12129 g_free (normalized_string);
12130 g_free (case_normalized_key);
12131 g_free (case_normalized_string);
12137 pspp_sheet_view_search_iter (GtkTreeModel *model,
12138 PsppSheetSelection *selection,
12147 PsppSheetView *tree_view = pspp_sheet_selection_get_tree_view (selection);
12149 path = gtk_tree_model_get_path (model, iter);
12150 _pspp_sheet_view_find_node (tree_view, path, &node);
12154 gboolean done = FALSE;
12156 if (! tree_view->priv->search_equal_func (model, tree_view->priv->search_column, text, iter, tree_view->priv->search_user_data))
12161 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL,
12163 pspp_sheet_selection_select_iter (selection, iter);
12164 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE, 0);
12167 gtk_tree_path_free (path);
12176 node = pspp_sheet_view_node_next (tree_view, node);
12182 has_next = gtk_tree_model_iter_next (model, iter);
12185 gtk_tree_path_next (path);
12188 TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
12193 gtk_tree_path_free (path);
12195 /* we've run out of tree, done with this func */
12207 pspp_sheet_view_search_init (GtkWidget *entry,
12208 PsppSheetView *tree_view)
12214 GtkTreeModel *model;
12215 PsppSheetSelection *selection;
12217 g_return_if_fail (GTK_IS_ENTRY (entry));
12218 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12220 text = gtk_entry_get_text (GTK_ENTRY (entry));
12222 model = pspp_sheet_view_get_model (tree_view);
12223 selection = pspp_sheet_view_get_selection (tree_view);
12226 pspp_sheet_selection_unselect_all (selection);
12227 if (tree_view->priv->typeselect_flush_timeout
12228 && !tree_view->priv->search_custom_entry_set)
12230 g_source_remove (tree_view->priv->typeselect_flush_timeout);
12231 tree_view->priv->typeselect_flush_timeout =
12232 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
12233 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
12240 if (!gtk_tree_model_get_iter_first (model, &iter))
12243 ret = pspp_sheet_view_search_iter (model, selection,
12248 tree_view->priv->selected_iter = 1;
12252 pspp_sheet_view_remove_widget (GtkCellEditable *cell_editable,
12253 PsppSheetView *tree_view)
12255 if (tree_view->priv->edited_column == NULL)
12258 _pspp_sheet_view_column_stop_editing (tree_view->priv->edited_column);
12259 tree_view->priv->edited_column = NULL;
12261 if (gtk_widget_has_focus (GTK_WIDGET (cell_editable)))
12262 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
12264 g_signal_handlers_disconnect_by_func (cell_editable,
12265 pspp_sheet_view_remove_widget,
12267 g_signal_handlers_disconnect_by_func (cell_editable,
12268 pspp_sheet_view_editable_button_press_event,
12270 g_signal_handlers_disconnect_by_func (cell_editable,
12271 pspp_sheet_view_editable_clicked,
12274 gtk_container_remove (GTK_CONTAINER (tree_view),
12275 GTK_WIDGET (cell_editable));
12277 /* FIXME should only redraw a single node */
12278 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12282 pspp_sheet_view_start_editing (PsppSheetView *tree_view,
12283 GtkTreePath *cursor_path)
12286 GdkRectangle background_area;
12287 GdkRectangle cell_area;
12288 GtkCellEditable *editable_widget = NULL;
12289 gchar *path_string;
12290 guint flags = 0; /* can be 0, as the flags are primarily for rendering */
12291 gint retval = FALSE;
12294 g_assert (tree_view->priv->focus_column);
12296 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
12299 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
12300 if (cursor_node < 0)
12303 path_string = gtk_tree_path_to_string (cursor_path);
12304 gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path);
12306 pspp_sheet_view_column_cell_set_cell_data (tree_view->priv->focus_column,
12307 tree_view->priv->model,
12309 pspp_sheet_view_get_background_area (tree_view,
12311 tree_view->priv->focus_column,
12313 pspp_sheet_view_get_cell_area (tree_view,
12315 tree_view->priv->focus_column,
12318 if (_pspp_sheet_view_column_cell_event (tree_view->priv->focus_column,
12327 if (editable_widget != NULL)
12331 GtkCellRenderer *cell;
12334 cell = _pspp_sheet_view_column_get_edited_cell (tree_view->priv->focus_column);
12336 _pspp_sheet_view_column_get_neighbor_sizes (tree_view->priv->focus_column, cell, &left, &right);
12339 area.width -= right + left;
12341 pspp_sheet_view_real_start_editing (tree_view,
12342 tree_view->priv->focus_column,
12351 g_free (path_string);
12356 pspp_sheet_view_editable_button_press_event (GtkWidget *widget,
12357 GdkEventButton *event,
12358 PsppSheetView *sheet_view)
12362 node = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
12363 "pspp-sheet-view-node"));
12364 return pspp_sheet_view_row_head_clicked (sheet_view,
12366 sheet_view->priv->edited_column,
12371 pspp_sheet_view_editable_clicked (GtkButton *button,
12372 PsppSheetView *sheet_view)
12374 pspp_sheet_view_editable_button_press_event (GTK_WIDGET (button), NULL,
12379 is_all_selected (GtkWidget *widget)
12381 GtkEntryBuffer *buffer;
12382 gint start_pos, end_pos;
12384 if (!GTK_IS_ENTRY (widget))
12387 buffer = gtk_entry_get_buffer (GTK_ENTRY (widget));
12388 return (gtk_editable_get_selection_bounds (GTK_EDITABLE (widget),
12389 &start_pos, &end_pos)
12391 && end_pos == gtk_entry_buffer_get_length (buffer));
12395 is_at_left (GtkWidget *widget)
12397 return (GTK_IS_ENTRY (widget)
12398 && gtk_editable_get_position (GTK_EDITABLE (widget)) == 0);
12402 is_at_right (GtkWidget *widget)
12404 GtkEntryBuffer *buffer;
12407 if (!GTK_IS_ENTRY (widget))
12410 buffer = gtk_entry_get_buffer (GTK_ENTRY (widget));
12411 length = gtk_entry_buffer_get_length (buffer);
12412 return gtk_editable_get_position (GTK_EDITABLE (widget)) == length;
12416 pspp_sheet_view_event (GtkWidget *widget,
12417 GdkEventKey *event,
12418 PsppSheetView *tree_view)
12420 PsppSheetViewColumn *column;
12427 /* Intercept only key press events.
12428 It would make sense to use "key-press-event" instead of "event", but
12429 GtkEntry attaches its own signal handler to "key-press-event" that runs
12430 before ours and overrides our desired behavior for GDK_Up and GDK_Down.
12432 if (event->type != GDK_KEY_PRESS)
12435 keyval = event->keyval;
12437 switch (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK | GDK_MOD1_MASK))
12440 switch (event->keyval)
12442 case GDK_Left: case GDK_KP_Left:
12443 case GDK_Home: case GDK_KP_Home:
12444 if (!is_all_selected (widget) && !is_at_left (widget))
12448 case GDK_Right: case GDK_KP_Right:
12449 case GDK_End: case GDK_KP_End:
12450 if (!is_all_selected (widget) && !is_at_right (widget))
12454 case GDK_Up: case GDK_KP_Up:
12455 case GDK_Down: case GDK_KP_Down:
12458 case GDK_Page_Up: case GDK_KP_Page_Up:
12459 case GDK_Page_Down: case GDK_KP_Page_Down:
12470 case GDK_Tab: case GDK_KP_Tab:
12471 case GDK_ISO_Left_Tab:
12480 case GDK_SHIFT_MASK:
12481 switch (event->keyval)
12484 case GDK_ISO_Left_Tab:
12493 case GDK_CONTROL_MASK:
12494 switch (event->keyval)
12496 case GDK_Left: case GDK_KP_Left:
12497 if (!is_all_selected (widget) && !is_at_left (widget))
12501 case GDK_Right: case GDK_KP_Right:
12502 if (!is_all_selected (widget) && !is_at_right (widget))
12506 case GDK_Up: case GDK_KP_Up:
12507 case GDK_Down: case GDK_KP_Down:
12519 row = tree_view->priv->edited_row;
12520 column = tree_view->priv->edited_column;
12521 path = gtk_tree_path_new_from_indices (row, -1);
12523 pspp_sheet_view_stop_editing (tree_view, cancel);
12524 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
12526 pspp_sheet_view_set_cursor (tree_view, path, column, FALSE);
12527 gtk_tree_path_free (path);
12529 handled = gtk_binding_set_activate (edit_bindings, keyval, event->state,
12530 G_OBJECT (tree_view));
12532 g_signal_stop_emission_by_name (widget, "event");
12534 pspp_sheet_view_get_cursor (tree_view, &path, NULL);
12535 pspp_sheet_view_start_editing (tree_view, path);
12536 gtk_tree_path_free (path);
12542 pspp_sheet_view_override_cell_keypresses (GtkWidget *widget,
12545 PsppSheetView *sheet_view = data;
12547 g_signal_connect (widget, "event",
12548 G_CALLBACK (pspp_sheet_view_event),
12551 if (GTK_IS_CONTAINER (widget))
12552 gtk_container_foreach (GTK_CONTAINER (widget),
12553 pspp_sheet_view_override_cell_keypresses,
12558 pspp_sheet_view_real_start_editing (PsppSheetView *tree_view,
12559 PsppSheetViewColumn *column,
12561 GtkCellEditable *cell_editable,
12562 GdkRectangle *cell_area,
12566 PsppSheetSelectionMode mode = pspp_sheet_selection_get_mode (tree_view->priv->selection);
12567 gint pre_val = gtk_adjustment_get_value (tree_view->priv->vadjustment);
12568 GtkRequisition requisition;
12571 g_return_if_fail (gtk_tree_path_get_depth (path) == 1);
12573 tree_view->priv->edited_column = column;
12574 _pspp_sheet_view_column_start_editing (column, GTK_CELL_EDITABLE (cell_editable));
12576 row = gtk_tree_path_get_indices (path)[0];
12577 tree_view->priv->edited_row = row;
12578 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE, 0);
12579 cell_area->y += pre_val - (int)gtk_adjustment_get_value (tree_view->priv->vadjustment);
12581 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
12582 pspp_sheet_selection_select_column (tree_view->priv->selection, column);
12583 tree_view->priv->anchor_column = column;
12585 gtk_widget_size_request (GTK_WIDGET (cell_editable), &requisition);
12587 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
12589 if (requisition.height < cell_area->height)
12591 gint diff = cell_area->height - requisition.height;
12592 pspp_sheet_view_put (tree_view,
12593 GTK_WIDGET (cell_editable),
12594 cell_area->x, cell_area->y + diff/2,
12595 cell_area->width, requisition.height);
12599 pspp_sheet_view_put (tree_view,
12600 GTK_WIDGET (cell_editable),
12601 cell_area->x, cell_area->y,
12602 cell_area->width, cell_area->height);
12605 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (cell_editable),
12606 (GdkEvent *)event);
12608 gtk_widget_grab_focus (GTK_WIDGET (cell_editable));
12609 g_signal_connect (cell_editable, "remove-widget",
12610 G_CALLBACK (pspp_sheet_view_remove_widget), tree_view);
12611 if (mode == PSPP_SHEET_SELECTION_RECTANGLE && column->row_head &&
12612 GTK_IS_BUTTON (cell_editable))
12614 g_signal_connect (cell_editable, "button-press-event",
12615 G_CALLBACK (pspp_sheet_view_editable_button_press_event),
12617 g_object_set_data (G_OBJECT (cell_editable), "pspp-sheet-view-node",
12618 GINT_TO_POINTER (row));
12619 g_signal_connect (cell_editable, "clicked",
12620 G_CALLBACK (pspp_sheet_view_editable_clicked),
12624 pspp_sheet_view_override_cell_keypresses (GTK_WIDGET (cell_editable),
12629 pspp_sheet_view_stop_editing (PsppSheetView *tree_view,
12630 gboolean cancel_editing)
12632 PsppSheetViewColumn *column;
12633 GtkCellRenderer *cell;
12635 if (tree_view->priv->edited_column == NULL)
12639 * This is very evil. We need to do this, because
12640 * gtk_cell_editable_editing_done may trigger pspp_sheet_view_row_changed
12641 * later on. If pspp_sheet_view_row_changed notices
12642 * tree_view->priv->edited_column != NULL, it'll call
12643 * pspp_sheet_view_stop_editing again. Bad things will happen then.
12645 * Please read that again if you intend to modify anything here.
12648 column = tree_view->priv->edited_column;
12649 tree_view->priv->edited_column = NULL;
12651 cell = _pspp_sheet_view_column_get_edited_cell (column);
12652 gtk_cell_renderer_stop_editing (cell, cancel_editing);
12654 if (!cancel_editing)
12655 gtk_cell_editable_editing_done (column->editable_widget);
12657 tree_view->priv->edited_column = column;
12659 gtk_cell_editable_remove_widget (column->editable_widget);
12664 * pspp_sheet_view_set_hover_selection:
12665 * @tree_view: a #PsppSheetView
12666 * @hover: %TRUE to enable hover selection mode
12668 * Enables of disables the hover selection mode of @tree_view.
12669 * Hover selection makes the selected row follow the pointer.
12670 * Currently, this works only for the selection modes
12671 * %PSPP_SHEET_SELECTION_SINGLE and %PSPP_SHEET_SELECTION_BROWSE.
12676 pspp_sheet_view_set_hover_selection (PsppSheetView *tree_view,
12679 hover = hover != FALSE;
12681 if (hover != tree_view->priv->hover_selection)
12683 tree_view->priv->hover_selection = hover;
12685 g_object_notify (G_OBJECT (tree_view), "hover-selection");
12690 * pspp_sheet_view_get_hover_selection:
12691 * @tree_view: a #PsppSheetView
12693 * Returns whether hover selection mode is turned on for @tree_view.
12695 * Return value: %TRUE if @tree_view is in hover selection mode
12700 pspp_sheet_view_get_hover_selection (PsppSheetView *tree_view)
12702 return tree_view->priv->hover_selection;
12706 * pspp_sheet_view_set_rubber_banding:
12707 * @tree_view: a #PsppSheetView
12708 * @enable: %TRUE to enable rubber banding
12710 * Enables or disables rubber banding in @tree_view. If the selection mode is
12711 * #PSPP_SHEET_SELECTION_MULTIPLE or #PSPP_SHEET_SELECTION_RECTANGLE, rubber
12712 * banding will allow the user to select multiple rows by dragging the mouse.
12717 pspp_sheet_view_set_rubber_banding (PsppSheetView *tree_view,
12720 enable = enable != FALSE;
12722 if (enable != tree_view->priv->rubber_banding_enable)
12724 tree_view->priv->rubber_banding_enable = enable;
12726 g_object_notify (G_OBJECT (tree_view), "rubber-banding");
12731 * pspp_sheet_view_get_rubber_banding:
12732 * @tree_view: a #PsppSheetView
12734 * Returns whether rubber banding is turned on for @tree_view. If the
12735 * selection mode is #PSPP_SHEET_SELECTION_MULTIPLE or
12736 * #PSPP_SHEET_SELECTION_RECTANGLE, rubber banding will allow the user to
12737 * select multiple rows by dragging the mouse.
12739 * Return value: %TRUE if rubber banding in @tree_view is enabled.
12744 pspp_sheet_view_get_rubber_banding (PsppSheetView *tree_view)
12746 return tree_view->priv->rubber_banding_enable;
12750 * pspp_sheet_view_is_rubber_banding_active:
12751 * @tree_view: a #PsppSheetView
12753 * Returns whether a rubber banding operation is currently being done
12756 * Return value: %TRUE if a rubber banding operation is currently being
12757 * done in @tree_view.
12762 pspp_sheet_view_is_rubber_banding_active (PsppSheetView *tree_view)
12764 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
12766 if (tree_view->priv->rubber_banding_enable
12767 && tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
12774 pspp_sheet_view_grab_notify (GtkWidget *widget,
12775 gboolean was_grabbed)
12777 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12779 tree_view->priv->in_grab = !was_grabbed;
12783 tree_view->priv->pressed_button = -1;
12785 if (tree_view->priv->rubber_band_status)
12786 pspp_sheet_view_stop_rubber_band (tree_view);
12791 pspp_sheet_view_state_changed (GtkWidget *widget,
12792 GtkStateType previous_state)
12794 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12796 if (gtk_widget_get_realized (widget))
12798 GtkStyle *style = gtk_widget_get_style (widget);
12799 gdk_window_set_background (tree_view->priv->bin_window, &style->base[gtk_widget_get_state (widget)]);
12802 gtk_widget_queue_draw (widget);
12806 * pspp_sheet_view_get_grid_lines:
12807 * @tree_view: a #PsppSheetView
12809 * Returns which grid lines are enabled in @tree_view.
12811 * Return value: a #PsppSheetViewGridLines value indicating which grid lines
12816 PsppSheetViewGridLines
12817 pspp_sheet_view_get_grid_lines (PsppSheetView *tree_view)
12819 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12821 return tree_view->priv->grid_lines;
12825 * pspp_sheet_view_set_grid_lines:
12826 * @tree_view: a #PsppSheetView
12827 * @grid_lines: a #PsppSheetViewGridLines value indicating which grid lines to
12830 * Sets which grid lines to draw in @tree_view.
12835 pspp_sheet_view_set_grid_lines (PsppSheetView *tree_view,
12836 PsppSheetViewGridLines grid_lines)
12838 PsppSheetViewPrivate *priv;
12839 PsppSheetViewGridLines old_grid_lines;
12841 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12843 priv = tree_view->priv;
12845 old_grid_lines = priv->grid_lines;
12846 priv->grid_lines = grid_lines;
12848 if (old_grid_lines != grid_lines)
12850 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12852 g_object_notify (G_OBJECT (tree_view), "enable-grid-lines");
12857 * pspp_sheet_view_get_special_cells:
12858 * @tree_view: a #PsppSheetView
12860 * Returns which grid lines are enabled in @tree_view.
12862 * Return value: a #PsppSheetViewSpecialCells value indicating whether rows in
12863 * the sheet view contain special cells.
12865 PsppSheetViewSpecialCells
12866 pspp_sheet_view_get_special_cells (PsppSheetView *tree_view)
12868 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12870 return tree_view->priv->special_cells;
12874 * pspp_sheet_view_set_special_cells:
12875 * @tree_view: a #PsppSheetView
12876 * @special_cells: a #PsppSheetViewSpecialCells value indicating whether rows in
12877 * the sheet view contain special cells.
12879 * Sets whether rows in the sheet view contain special cells, controlling the
12880 * rendering of row selections.
12883 pspp_sheet_view_set_special_cells (PsppSheetView *tree_view,
12884 PsppSheetViewSpecialCells special_cells)
12886 PsppSheetViewPrivate *priv;
12888 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12890 priv = tree_view->priv;
12892 if (priv->special_cells != special_cells)
12894 priv->special_cells = special_cells;
12895 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12896 g_object_notify (G_OBJECT (tree_view), "special-cells");
12901 pspp_sheet_view_get_fixed_height (const PsppSheetView *tree_view)
12903 /* XXX (re)calculate fixed_height if necessary */
12904 return tree_view->priv->fixed_height;
12908 pspp_sheet_view_set_fixed_height (PsppSheetView *tree_view,
12911 g_return_if_fail (fixed_height > 0);
12913 if (tree_view->priv->fixed_height != fixed_height)
12915 tree_view->priv->fixed_height = fixed_height;
12916 g_object_notify (G_OBJECT (tree_view), "fixed-height");
12918 if (!tree_view->priv->fixed_height_set)
12920 tree_view->priv->fixed_height_set = TRUE;
12921 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
12926 * pspp_sheet_view_set_tooltip_row:
12927 * @tree_view: a #PsppSheetView
12928 * @tooltip: a #GtkTooltip
12929 * @path: a #GtkTreePath
12931 * Sets the tip area of @tooltip to be the area covered by the row at @path.
12932 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
12933 * See also gtk_tooltip_set_tip_area().
12938 pspp_sheet_view_set_tooltip_row (PsppSheetView *tree_view,
12939 GtkTooltip *tooltip,
12942 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12943 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
12945 pspp_sheet_view_set_tooltip_cell (tree_view, tooltip, path, NULL, NULL);
12949 * pspp_sheet_view_set_tooltip_cell:
12950 * @tree_view: a #PsppSheetView
12951 * @tooltip: a #GtkTooltip
12952 * @path: (allow-none): a #GtkTreePath or %NULL
12953 * @column: (allow-none): a #PsppSheetViewColumn or %NULL
12954 * @cell: (allow-none): a #GtkCellRenderer or %NULL
12956 * Sets the tip area of @tooltip to the area @path, @column and @cell have
12957 * in common. For example if @path is %NULL and @column is set, the tip
12958 * area will be set to the full area covered by @column. See also
12959 * gtk_tooltip_set_tip_area().
12961 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
12966 pspp_sheet_view_set_tooltip_cell (PsppSheetView *tree_view,
12967 GtkTooltip *tooltip,
12969 PsppSheetViewColumn *column,
12970 GtkCellRenderer *cell)
12974 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12975 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
12976 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
12977 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
12979 /* Determine x values. */
12980 if (column && cell)
12985 pspp_sheet_view_get_cell_area (tree_view, path, column, &tmp);
12986 pspp_sheet_view_column_cell_get_position (column, cell, &start, &width);
12988 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12991 rect.width = width;
12997 pspp_sheet_view_get_background_area (tree_view, NULL, column, &tmp);
12998 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
13001 rect.width = tmp.width;
13005 GtkAllocation allocation;
13006 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
13008 rect.width = allocation.width;
13011 /* Determine y values. */
13016 pspp_sheet_view_get_background_area (tree_view, path, NULL, &tmp);
13017 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
13020 rect.height = tmp.height;
13025 rect.height = gtk_adjustment_get_page_size (tree_view->priv->vadjustment);
13028 gtk_tooltip_set_tip_area (tooltip, &rect);
13032 * pspp_sheet_view_get_tooltip_context:
13033 * @tree_view: a #PsppSheetView
13034 * @x: the x coordinate (relative to widget coordinates)
13035 * @y: the y coordinate (relative to widget coordinates)
13036 * @keyboard_tip: whether this is a keyboard tooltip or not
13037 * @model: (allow-none): a pointer to receive a #GtkTreeModel or %NULL
13038 * @path: (allow-none): a pointer to receive a #GtkTreePath or %NULL
13039 * @iter: (allow-none): a pointer to receive a #GtkTreeIter or %NULL
13041 * This function is supposed to be used in a #GtkWidget::query-tooltip
13042 * signal handler for #PsppSheetView. The @x, @y and @keyboard_tip values
13043 * which are received in the signal handler, should be passed to this
13044 * function without modification.
13046 * The return value indicates whether there is a tree view row at the given
13047 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
13048 * tooltips the row returned will be the cursor row. When %TRUE, then any of
13049 * @model, @path and @iter which have been provided will be set to point to
13050 * that row and the corresponding model. @x and @y will always be converted
13051 * to be relative to @tree_view's bin_window if @keyboard_tooltip is %FALSE.
13053 * Return value: whether or not the given tooltip context points to a row.
13058 pspp_sheet_view_get_tooltip_context (PsppSheetView *tree_view,
13061 gboolean keyboard_tip,
13062 GtkTreeModel **model,
13063 GtkTreePath **path,
13066 GtkTreePath *tmppath = NULL;
13068 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
13069 g_return_val_if_fail (x != NULL, FALSE);
13070 g_return_val_if_fail (y != NULL, FALSE);
13074 pspp_sheet_view_get_cursor (tree_view, &tmppath, NULL);
13081 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, *x, *y,
13084 if (!pspp_sheet_view_get_path_at_pos (tree_view, *x, *y,
13085 &tmppath, NULL, NULL, NULL))
13090 *model = pspp_sheet_view_get_model (tree_view);
13093 gtk_tree_model_get_iter (pspp_sheet_view_get_model (tree_view),
13099 gtk_tree_path_free (tmppath);
13105 pspp_sheet_view_set_tooltip_query_cb (GtkWidget *widget,
13108 gboolean keyboard_tip,
13109 GtkTooltip *tooltip,
13112 GValue value = { 0, };
13113 GValue transformed = { 0, };
13116 GtkTreeModel *model;
13117 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
13119 if (!pspp_sheet_view_get_tooltip_context (PSPP_SHEET_VIEW (widget),
13122 &model, &path, &iter))
13125 gtk_tree_model_get_value (model, &iter,
13126 tree_view->priv->tooltip_column, &value);
13128 g_value_init (&transformed, G_TYPE_STRING);
13130 if (!g_value_transform (&value, &transformed))
13132 g_value_unset (&value);
13133 gtk_tree_path_free (path);
13138 g_value_unset (&value);
13140 if (!g_value_get_string (&transformed))
13142 g_value_unset (&transformed);
13143 gtk_tree_path_free (path);
13148 gtk_tooltip_set_markup (tooltip, g_value_get_string (&transformed));
13149 pspp_sheet_view_set_tooltip_row (tree_view, tooltip, path);
13151 gtk_tree_path_free (path);
13152 g_value_unset (&transformed);
13158 * pspp_sheet_view_set_tooltip_column:
13159 * @tree_view: a #PsppSheetView
13160 * @column: an integer, which is a valid column number for @tree_view's model
13162 * If you only plan to have simple (text-only) tooltips on full rows, you
13163 * can use this function to have #PsppSheetView handle these automatically
13164 * for you. @column should be set to the column in @tree_view's model
13165 * containing the tooltip texts, or -1 to disable this feature.
13167 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
13168 * @tree_view will connect a #GtkWidget::query-tooltip signal handler.
13170 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
13171 * so &, <, etc have to be escaped in the text.
13176 pspp_sheet_view_set_tooltip_column (PsppSheetView *tree_view,
13179 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
13181 if (column == tree_view->priv->tooltip_column)
13186 g_signal_handlers_disconnect_by_func (tree_view,
13187 pspp_sheet_view_set_tooltip_query_cb,
13189 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), FALSE);
13193 if (tree_view->priv->tooltip_column == -1)
13195 g_signal_connect (tree_view, "query-tooltip",
13196 G_CALLBACK (pspp_sheet_view_set_tooltip_query_cb), NULL);
13197 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), TRUE);
13201 tree_view->priv->tooltip_column = column;
13202 g_object_notify (G_OBJECT (tree_view), "tooltip-column");
13206 * pspp_sheet_view_get_tooltip_column:
13207 * @tree_view: a #PsppSheetView
13209 * Returns the column of @tree_view's model which is being used for
13210 * displaying tooltips on @tree_view's rows.
13212 * Return value: the index of the tooltip column that is currently being
13213 * used, or -1 if this is disabled.
13218 pspp_sheet_view_get_tooltip_column (PsppSheetView *tree_view)
13220 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
13222 return tree_view->priv->tooltip_column;
13226 _gtk_boolean_handled_accumulator (GSignalInvocationHint *ihint,
13227 GValue *return_accu,
13228 const GValue *handler_return,
13231 gboolean continue_emission;
13232 gboolean signal_handled;
13234 signal_handled = g_value_get_boolean (handler_return);
13235 g_value_set_boolean (return_accu, signal_handled);
13236 continue_emission = !signal_handled;
13238 return continue_emission;
13243 pspp_sheet_view_grid_lines_get_type (void)
13245 static GType etype = 0;
13246 if (G_UNLIKELY(etype == 0)) {
13247 static const GEnumValue values[] = {
13248 { PSPP_SHEET_VIEW_GRID_LINES_NONE, "PSPP_SHEET_VIEW_GRID_LINES_NONE", "none" },
13249 { PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL, "PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL", "horizontal" },
13250 { PSPP_SHEET_VIEW_GRID_LINES_VERTICAL, "PSPP_SHEET_VIEW_GRID_LINES_VERTICAL", "vertical" },
13251 { PSPP_SHEET_VIEW_GRID_LINES_BOTH, "PSPP_SHEET_VIEW_GRID_LINES_BOTH", "both" },
13254 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewGridLines"), values);
13260 pspp_sheet_view_special_cells_get_type (void)
13262 static GType etype = 0;
13263 if (G_UNLIKELY(etype == 0)) {
13264 static const GEnumValue values[] = {
13265 { PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT, "PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT", "detect" },
13266 { PSPP_SHEET_VIEW_SPECIAL_CELLS_YES, "PSPP_SHEET_VIEW_SPECIAL_CELLS_YES", "yes" },
13267 { PSPP_SHEET_VIEW_SPECIAL_CELLS_NO, "PSPP_SHEET_VIEW_SPECIAL_CELLS_NO", "no" },
13270 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewSpecialCells"), values);