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_draw (GtkWidget *widget,
176 static gboolean pspp_sheet_view_key_press (GtkWidget *widget,
178 static gboolean pspp_sheet_view_key_release (GtkWidget *widget,
180 static gboolean pspp_sheet_view_motion (GtkWidget *widget,
181 GdkEventMotion *event);
182 static gboolean pspp_sheet_view_enter_notify (GtkWidget *widget,
183 GdkEventCrossing *event);
184 static gboolean pspp_sheet_view_leave_notify (GtkWidget *widget,
185 GdkEventCrossing *event);
186 static gboolean pspp_sheet_view_button_press (GtkWidget *widget,
187 GdkEventButton *event);
188 static gboolean pspp_sheet_view_button_release (GtkWidget *widget,
189 GdkEventButton *event);
190 static gboolean pspp_sheet_view_grab_broken (GtkWidget *widget,
191 GdkEventGrabBroken *event);
193 static void pspp_sheet_view_set_focus_child (GtkContainer *container,
195 static gint pspp_sheet_view_focus_out (GtkWidget *widget,
196 GdkEventFocus *event);
197 static gint pspp_sheet_view_focus (GtkWidget *widget,
198 GtkDirectionType direction);
199 static void pspp_sheet_view_grab_focus (GtkWidget *widget);
200 static void pspp_sheet_view_style_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_get_preferred_width (GtkWidget *widget,
461 GtkRequisition requisition;
463 pspp_sheet_view_size_request (widget, &requisition);
465 *minimal_width = *natural_width = requisition.width;
469 pspp_sheet_view_get_preferred_height (GtkWidget *widget,
470 gint *minimal_height,
471 gint *natural_height)
473 GtkRequisition requisition;
475 pspp_sheet_view_size_request (widget, &requisition);
477 *minimal_height = *natural_height = requisition.height;
481 pspp_sheet_view_class_init (PsppSheetViewClass *class)
483 GObjectClass *o_class;
484 GtkWidgetClass *widget_class;
485 GtkContainerClass *container_class;
486 GtkBindingSet *binding_set[2];
489 binding_set[0] = gtk_binding_set_by_class (class);
491 binding_set[1] = gtk_binding_set_new ("PsppSheetViewEditing");
492 edit_bindings = binding_set[1];
494 o_class = (GObjectClass *) class;
495 widget_class = (GtkWidgetClass *) class;
496 container_class = (GtkContainerClass *) class;
498 /* GObject signals */
499 o_class->set_property = pspp_sheet_view_set_property;
500 o_class->get_property = pspp_sheet_view_get_property;
501 o_class->finalize = pspp_sheet_view_finalize;
502 o_class->dispose = pspp_sheet_view_dispose;
504 /* GtkWidget signals */
505 widget_class->map = pspp_sheet_view_map;
506 widget_class->realize = pspp_sheet_view_realize;
507 widget_class->unrealize = pspp_sheet_view_unrealize;
508 widget_class->get_preferred_width = pspp_sheet_view_get_preferred_width;
509 widget_class->get_preferred_height = pspp_sheet_view_get_preferred_height;
510 widget_class->size_allocate = pspp_sheet_view_size_allocate;
511 widget_class->button_press_event = pspp_sheet_view_button_press;
512 widget_class->button_release_event = pspp_sheet_view_button_release;
513 widget_class->grab_broken_event = pspp_sheet_view_grab_broken;
514 /*widget_class->configure_event = pspp_sheet_view_configure;*/
515 widget_class->motion_notify_event = pspp_sheet_view_motion;
516 widget_class->draw = pspp_sheet_view_draw;
517 widget_class->key_press_event = pspp_sheet_view_key_press;
518 widget_class->key_release_event = pspp_sheet_view_key_release;
519 widget_class->enter_notify_event = pspp_sheet_view_enter_notify;
520 widget_class->leave_notify_event = pspp_sheet_view_leave_notify;
521 widget_class->focus_out_event = pspp_sheet_view_focus_out;
522 widget_class->drag_begin = pspp_sheet_view_drag_begin;
523 widget_class->drag_end = pspp_sheet_view_drag_end;
524 widget_class->drag_data_get = pspp_sheet_view_drag_data_get;
525 widget_class->drag_data_delete = pspp_sheet_view_drag_data_delete;
526 widget_class->drag_leave = pspp_sheet_view_drag_leave;
527 widget_class->drag_motion = pspp_sheet_view_drag_motion;
528 widget_class->drag_drop = pspp_sheet_view_drag_drop;
529 widget_class->drag_data_received = pspp_sheet_view_drag_data_received;
530 widget_class->focus = pspp_sheet_view_focus;
531 widget_class->grab_focus = pspp_sheet_view_grab_focus;
532 widget_class->style_set = pspp_sheet_view_style_set;
533 widget_class->grab_notify = pspp_sheet_view_grab_notify;
534 widget_class->state_changed = pspp_sheet_view_state_changed;
536 /* GtkContainer signals */
537 container_class->remove = pspp_sheet_view_remove;
538 container_class->forall = pspp_sheet_view_forall;
539 container_class->set_focus_child = pspp_sheet_view_set_focus_child;
541 class->set_scroll_adjustments = pspp_sheet_view_set_adjustments;
542 class->move_cursor = pspp_sheet_view_real_move_cursor;
543 class->select_all = pspp_sheet_view_real_select_all;
544 class->unselect_all = pspp_sheet_view_real_unselect_all;
545 class->select_cursor_row = pspp_sheet_view_real_select_cursor_row;
546 class->toggle_cursor_row = pspp_sheet_view_real_toggle_cursor_row;
547 class->start_interactive_search = pspp_sheet_view_start_interactive_search;
551 g_object_class_install_property (o_class,
553 g_param_spec_object ("model",
554 P_("TreeView Model"),
555 P_("The model for the tree view"),
557 GTK_PARAM_READWRITE));
559 g_object_class_install_property (o_class,
561 g_param_spec_object ("hadjustment",
562 P_("Horizontal Adjustment"),
563 P_("Horizontal Adjustment for the widget"),
565 GTK_PARAM_READWRITE));
567 g_object_class_install_property (o_class,
569 g_param_spec_object ("vadjustment",
570 P_("Vertical Adjustment"),
571 P_("Vertical Adjustment for the widget"),
573 GTK_PARAM_READWRITE));
575 g_object_class_install_property (o_class,
576 PROP_HEADERS_VISIBLE,
577 g_param_spec_boolean ("headers-visible",
578 P_("Headers Visible"),
579 P_("Show the column header buttons"),
581 GTK_PARAM_READWRITE));
583 g_object_class_install_property (o_class,
584 PROP_HEADERS_CLICKABLE,
585 g_param_spec_boolean ("headers-clickable",
586 P_("Headers Clickable"),
587 P_("Column headers respond to click events"),
589 GTK_PARAM_READWRITE));
591 g_object_class_install_property (o_class,
593 g_param_spec_boolean ("reorderable",
595 P_("View is reorderable"),
597 GTK_PARAM_READWRITE));
599 g_object_class_install_property (o_class,
601 g_param_spec_boolean ("rules-hint",
603 P_("Set a hint to the theme engine to draw rows in alternating colors"),
605 GTK_PARAM_READWRITE));
607 g_object_class_install_property (o_class,
609 g_param_spec_boolean ("enable-search",
611 P_("View allows user to search through columns interactively"),
613 GTK_PARAM_READWRITE));
615 g_object_class_install_property (o_class,
617 g_param_spec_int ("search-column",
619 P_("Model column to search through during interactive search"),
623 GTK_PARAM_READWRITE));
626 * PsppSheetView:hover-selection:
628 * Enables of disables the hover selection mode of @tree_view.
629 * Hover selection makes the selected row follow the pointer.
630 * Currently, this works only for the selection modes
631 * %PSPP_SHEET_SELECTION_SINGLE and %PSPP_SHEET_SELECTION_BROWSE.
633 * This mode is primarily intended for treeviews in popups, e.g.
634 * in #GtkComboBox or #GtkEntryCompletion.
638 g_object_class_install_property (o_class,
639 PROP_HOVER_SELECTION,
640 g_param_spec_boolean ("hover-selection",
641 P_("Hover Selection"),
642 P_("Whether the selection should follow the pointer"),
644 GTK_PARAM_READWRITE));
646 g_object_class_install_property (o_class,
648 g_param_spec_boolean ("rubber-banding",
649 P_("Rubber Banding"),
650 P_("Whether to enable selection of multiple items by dragging the mouse pointer"),
652 GTK_PARAM_READWRITE));
654 g_object_class_install_property (o_class,
655 PROP_ENABLE_GRID_LINES,
656 g_param_spec_enum ("enable-grid-lines",
657 P_("Enable Grid Lines"),
658 P_("Whether grid lines should be drawn in the tree view"),
659 PSPP_TYPE_SHEET_VIEW_GRID_LINES,
660 PSPP_SHEET_VIEW_GRID_LINES_NONE,
661 GTK_PARAM_READWRITE));
663 g_object_class_install_property (o_class,
665 g_param_spec_int ("tooltip-column",
666 P_("Tooltip Column"),
667 P_("The column in the model containing the tooltip texts for the rows"),
671 GTK_PARAM_READWRITE));
673 g_object_class_install_property (o_class,
675 g_param_spec_enum ("special-cells",
677 P_("Whether rows have special cells."),
678 PSPP_TYPE_SHEET_VIEW_SPECIAL_CELLS,
679 PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT,
680 GTK_PARAM_READWRITE));
682 g_object_class_install_property (o_class,
684 g_param_spec_int ("fixed-height",
686 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."),
690 GTK_PARAM_READWRITE));
692 g_object_class_install_property (o_class,
693 PROP_FIXED_HEIGHT_SET,
694 g_param_spec_boolean ("fixed-height-set",
695 P_("Fixed Height Set"),
696 P_("Whether fixed-height was set externally."),
698 GTK_PARAM_READWRITE));
700 /* Style properties */
701 #define _TREE_VIEW_EXPANDER_SIZE 12
702 #define _TREE_VIEW_VERTICAL_SEPARATOR 2
703 #define _TREE_VIEW_HORIZONTAL_SEPARATOR 2
705 gtk_widget_class_install_style_property (widget_class,
706 g_param_spec_int ("expander-size",
708 P_("Size of the expander arrow"),
711 _TREE_VIEW_EXPANDER_SIZE,
712 GTK_PARAM_READABLE));
714 gtk_widget_class_install_style_property (widget_class,
715 g_param_spec_int ("vertical-separator",
716 P_("Vertical Separator Width"),
717 P_("Vertical space between cells. Must be an even number"),
720 _TREE_VIEW_VERTICAL_SEPARATOR,
721 GTK_PARAM_READABLE));
723 gtk_widget_class_install_style_property (widget_class,
724 g_param_spec_int ("horizontal-separator",
725 P_("Horizontal Separator Width"),
726 P_("Horizontal space between cells. Must be an even number"),
729 _TREE_VIEW_HORIZONTAL_SEPARATOR,
730 GTK_PARAM_READABLE));
732 gtk_widget_class_install_style_property (widget_class,
733 g_param_spec_boolean ("allow-rules",
735 P_("Allow drawing of alternating color rows"),
737 GTK_PARAM_READABLE));
739 gtk_widget_class_install_style_property (widget_class,
740 g_param_spec_boxed ("even-row-color",
741 P_("Even Row Color"),
742 P_("Color to use for even rows"),
744 GTK_PARAM_READABLE));
746 gtk_widget_class_install_style_property (widget_class,
747 g_param_spec_boxed ("odd-row-color",
749 P_("Color to use for odd rows"),
751 GTK_PARAM_READABLE));
753 gtk_widget_class_install_style_property (widget_class,
754 g_param_spec_boolean ("row-ending-details",
755 P_("Row Ending details"),
756 P_("Enable extended row background theming"),
758 GTK_PARAM_READABLE));
760 gtk_widget_class_install_style_property (widget_class,
761 g_param_spec_int ("grid-line-width",
762 P_("Grid line width"),
763 P_("Width, in pixels, of the tree view grid lines"),
765 GTK_PARAM_READABLE));
767 gtk_widget_class_install_style_property (widget_class,
768 g_param_spec_int ("tree-line-width",
769 P_("Tree line width"),
770 P_("Width, in pixels, of the tree view lines"),
772 GTK_PARAM_READABLE));
774 gtk_widget_class_install_style_property (widget_class,
775 g_param_spec_string ("tree-line-pattern",
776 P_("Tree line pattern"),
777 P_("Dash pattern used to draw the tree view lines"),
779 GTK_PARAM_READABLE));
784 * PsppSheetView::set-scroll-adjustments
785 * @horizontal: the horizontal #GtkAdjustment
786 * @vertical: the vertical #GtkAdjustment
788 * Set the scroll adjustments for the tree view. Usually scrolled containers
789 * like #GtkScrolledWindow will emit this signal to connect two instances
790 * of #GtkScrollbar to the scroll directions of the #PsppSheetView.
792 widget_class->set_scroll_adjustments_signal =
793 g_signal_new ("set-scroll-adjustments",
794 G_TYPE_FROM_CLASS (o_class),
795 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
796 G_STRUCT_OFFSET (PsppSheetViewClass, set_scroll_adjustments),
798 psppire_marshal_VOID__OBJECT_OBJECT,
801 GTK_TYPE_ADJUSTMENT);
805 * PsppSheetView::row-activated:
806 * @tree_view: the object on which the signal is emitted
807 * @path: the #GtkTreePath for the activated row
808 * @column: the #PsppSheetViewColumn in which the activation occurred
810 * The "row-activated" signal is emitted when the method
811 * pspp_sheet_view_row_activated() is called or the user double clicks
812 * a treeview row. It is also emitted when a non-editable row is
813 * selected and one of the keys: Space, Shift+Space, Return or
816 * For selection handling refer to the <link linkend="TreeWidget">tree
817 * widget conceptual overview</link> as well as #PsppSheetSelection.
819 tree_view_signals[ROW_ACTIVATED] =
820 g_signal_new ("row-activated",
821 G_TYPE_FROM_CLASS (o_class),
822 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
823 G_STRUCT_OFFSET (PsppSheetViewClass, row_activated),
825 psppire_marshal_VOID__BOXED_OBJECT,
828 PSPP_TYPE_SHEET_VIEW_COLUMN);
831 * PsppSheetView::columns-changed:
832 * @tree_view: the object on which the signal is emitted
834 * The number of columns of the treeview has changed.
836 tree_view_signals[COLUMNS_CHANGED] =
837 g_signal_new ("columns-changed",
838 G_TYPE_FROM_CLASS (o_class),
840 G_STRUCT_OFFSET (PsppSheetViewClass, columns_changed),
842 g_cclosure_marshal_VOID__VOID,
846 * PsppSheetView::cursor-changed:
847 * @tree_view: the object on which the signal is emitted
849 * The position of the cursor (focused cell) has changed.
851 tree_view_signals[CURSOR_CHANGED] =
852 g_signal_new ("cursor-changed",
853 G_TYPE_FROM_CLASS (o_class),
855 G_STRUCT_OFFSET (PsppSheetViewClass, cursor_changed),
857 g_cclosure_marshal_VOID__VOID,
860 tree_view_signals[MOVE_CURSOR] =
861 g_signal_new ("move-cursor",
862 G_TYPE_FROM_CLASS (o_class),
863 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
864 G_STRUCT_OFFSET (PsppSheetViewClass, move_cursor),
866 psppire_marshal_BOOLEAN__ENUM_INT,
868 GTK_TYPE_MOVEMENT_STEP,
871 tree_view_signals[SELECT_ALL] =
872 g_signal_new ("select-all",
873 G_TYPE_FROM_CLASS (o_class),
874 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
875 G_STRUCT_OFFSET (PsppSheetViewClass, select_all),
877 psppire_marshal_BOOLEAN__VOID,
880 tree_view_signals[UNSELECT_ALL] =
881 g_signal_new ("unselect-all",
882 G_TYPE_FROM_CLASS (o_class),
883 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
884 G_STRUCT_OFFSET (PsppSheetViewClass, unselect_all),
886 psppire_marshal_BOOLEAN__VOID,
889 tree_view_signals[SELECT_CURSOR_ROW] =
890 g_signal_new ("select-cursor-row",
891 G_TYPE_FROM_CLASS (o_class),
892 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
893 G_STRUCT_OFFSET (PsppSheetViewClass, select_cursor_row),
895 psppire_marshal_BOOLEAN__BOOLEAN,
897 G_TYPE_BOOLEAN, G_TYPE_INT);
899 tree_view_signals[TOGGLE_CURSOR_ROW] =
900 g_signal_new ("toggle-cursor-row",
901 G_TYPE_FROM_CLASS (o_class),
902 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
903 G_STRUCT_OFFSET (PsppSheetViewClass, toggle_cursor_row),
905 psppire_marshal_BOOLEAN__VOID,
908 tree_view_signals[START_INTERACTIVE_SEARCH] =
909 g_signal_new ("start-interactive-search",
910 G_TYPE_FROM_CLASS (o_class),
911 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
912 G_STRUCT_OFFSET (PsppSheetViewClass, start_interactive_search),
914 psppire_marshal_BOOLEAN__VOID,
918 for (i = 0; i < 2; i++)
920 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Up, 0, TRUE,
921 GTK_MOVEMENT_DISPLAY_LINES, -1);
922 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Up, 0, TRUE,
923 GTK_MOVEMENT_DISPLAY_LINES, -1);
925 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Down, 0, TRUE,
926 GTK_MOVEMENT_DISPLAY_LINES, 1);
927 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Down, 0, TRUE,
928 GTK_MOVEMENT_DISPLAY_LINES, 1);
930 pspp_sheet_view_add_move_binding (binding_set[i], GDK_p, GDK_CONTROL_MASK, FALSE,
931 GTK_MOVEMENT_DISPLAY_LINES, -1);
933 pspp_sheet_view_add_move_binding (binding_set[i], GDK_n, GDK_CONTROL_MASK, FALSE,
934 GTK_MOVEMENT_DISPLAY_LINES, 1);
936 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Home, 0, TRUE,
937 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
938 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Home, 0, TRUE,
939 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
941 pspp_sheet_view_add_move_binding (binding_set[i], GDK_End, 0, TRUE,
942 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
943 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_End, 0, TRUE,
944 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
946 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Page_Up, 0, TRUE,
947 GTK_MOVEMENT_PAGES, -1);
948 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Page_Up, 0, TRUE,
949 GTK_MOVEMENT_PAGES, -1);
951 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Page_Down, 0, TRUE,
952 GTK_MOVEMENT_PAGES, 1);
953 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Page_Down, 0, TRUE,
954 GTK_MOVEMENT_PAGES, 1);
957 gtk_binding_entry_add_signal (binding_set[i], GDK_Up, GDK_CONTROL_MASK, "move-cursor", 2,
958 G_TYPE_ENUM, GTK_MOVEMENT_BUFFER_ENDS,
961 gtk_binding_entry_add_signal (binding_set[i], GDK_Down, GDK_CONTROL_MASK, "move-cursor", 2,
962 G_TYPE_ENUM, GTK_MOVEMENT_BUFFER_ENDS,
965 gtk_binding_entry_add_signal (binding_set[i], GDK_Right, 0, "move-cursor", 2,
966 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
969 gtk_binding_entry_add_signal (binding_set[i], GDK_Left, 0, "move-cursor", 2,
970 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
973 gtk_binding_entry_add_signal (binding_set[i], GDK_Tab, 0, "move-cursor", 2,
974 G_TYPE_ENUM, GTK_MOVEMENT_LOGICAL_POSITIONS,
977 gtk_binding_entry_add_signal (binding_set[i], GDK_Tab, GDK_SHIFT_MASK, "move-cursor", 2,
978 G_TYPE_ENUM, GTK_MOVEMENT_LOGICAL_POSITIONS,
981 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Right, 0, "move-cursor", 2,
982 G_TYPE_ENUM, GTK_MOVEMENT_DISPLAY_LINE_ENDS,
985 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Left, 0, "move-cursor", 2,
986 G_TYPE_ENUM, GTK_MOVEMENT_DISPLAY_LINE_ENDS,
989 gtk_binding_entry_add_signal (binding_set[i], GDK_Right, GDK_CONTROL_MASK,
991 G_TYPE_ENUM, GTK_MOVEMENT_DISPLAY_LINE_ENDS,
994 gtk_binding_entry_add_signal (binding_set[i], GDK_Left, GDK_CONTROL_MASK,
996 G_TYPE_ENUM, GTK_MOVEMENT_DISPLAY_LINE_ENDS,
999 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Right, GDK_CONTROL_MASK,
1001 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
1004 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Left, GDK_CONTROL_MASK,
1006 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
1009 gtk_binding_entry_add_signal (binding_set[i], GDK_f, GDK_CONTROL_MASK, "start-interactive-search", 0);
1011 gtk_binding_entry_add_signal (binding_set[i], GDK_F, GDK_CONTROL_MASK, "start-interactive-search", 0);
1014 gtk_binding_entry_add_signal (binding_set[0], GDK_space, GDK_CONTROL_MASK, "toggle-cursor-row", 0);
1015 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Space, GDK_CONTROL_MASK, "toggle-cursor-row", 0);
1017 gtk_binding_entry_add_signal (binding_set[0], GDK_a, GDK_CONTROL_MASK, "select-all", 0);
1018 gtk_binding_entry_add_signal (binding_set[0], GDK_slash, GDK_CONTROL_MASK, "select-all", 0);
1020 gtk_binding_entry_add_signal (binding_set[0], GDK_A, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "unselect-all", 0);
1021 gtk_binding_entry_add_signal (binding_set[0], GDK_backslash, GDK_CONTROL_MASK, "unselect-all", 0);
1023 gtk_binding_entry_add_signal (binding_set[0], GDK_space, GDK_SHIFT_MASK, "select-cursor-row", 1,
1024 G_TYPE_BOOLEAN, TRUE,
1025 G_TYPE_INT, PSPP_SHEET_SELECT_MODE_EXTEND);
1026 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Space, GDK_SHIFT_MASK, "select-cursor-row", 1,
1027 G_TYPE_BOOLEAN, TRUE,
1028 G_TYPE_INT, PSPP_SHEET_SELECT_MODE_EXTEND);
1030 gtk_binding_entry_add_signal (binding_set[0], GDK_space, 0, "select-cursor-row", 1,
1031 G_TYPE_BOOLEAN, TRUE,
1033 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Space, 0, "select-cursor-row", 1,
1034 G_TYPE_BOOLEAN, TRUE,
1036 gtk_binding_entry_add_signal (binding_set[0], GDK_Return, 0, "select-cursor-row", 1,
1037 G_TYPE_BOOLEAN, TRUE,
1039 gtk_binding_entry_add_signal (binding_set[0], GDK_ISO_Enter, 0, "select-cursor-row", 1,
1040 G_TYPE_BOOLEAN, TRUE,
1042 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Enter, 0, "select-cursor-row", 1,
1043 G_TYPE_BOOLEAN, TRUE,
1046 gtk_binding_entry_add_signal (binding_set[0], GDK_BackSpace, 0, "select-cursor-parent", 0);
1047 gtk_binding_entry_add_signal (binding_set[0], GDK_BackSpace, GDK_CONTROL_MASK, "select-cursor-parent", 0);
1049 g_type_class_add_private (o_class, sizeof (PsppSheetViewPrivate));
1053 pspp_sheet_view_buildable_init (GtkBuildableIface *iface)
1055 iface->add_child = pspp_sheet_view_buildable_add_child;
1059 pspp_sheet_view_init (PsppSheetView *tree_view)
1061 tree_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (tree_view, PSPP_TYPE_SHEET_VIEW, PsppSheetViewPrivate);
1063 gtk_widget_set_can_focus (GTK_WIDGET (tree_view), TRUE);
1064 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (tree_view), FALSE);
1066 tree_view->priv->flags = PSPP_SHEET_VIEW_DRAW_KEYFOCUS
1067 | PSPP_SHEET_VIEW_HEADERS_VISIBLE;
1069 /* We need some padding */
1070 tree_view->priv->selected = range_tower_create ();
1071 tree_view->priv->dy = 0;
1072 tree_view->priv->cursor_offset = 0;
1073 tree_view->priv->n_columns = 0;
1074 tree_view->priv->header_height = 1;
1075 tree_view->priv->x_drag = 0;
1076 tree_view->priv->drag_pos = -1;
1077 tree_view->priv->header_has_focus = FALSE;
1078 tree_view->priv->pressed_button = -1;
1079 tree_view->priv->press_start_x = -1;
1080 tree_view->priv->press_start_y = -1;
1081 tree_view->priv->reorderable = FALSE;
1082 tree_view->priv->presize_handler_timer = 0;
1083 tree_view->priv->scroll_sync_timer = 0;
1084 tree_view->priv->fixed_height = -1;
1085 tree_view->priv->fixed_height_set = FALSE;
1086 pspp_sheet_view_set_adjustments (tree_view, NULL, NULL);
1087 tree_view->priv->selection = _pspp_sheet_selection_new_with_tree_view (tree_view);
1088 tree_view->priv->enable_search = TRUE;
1089 tree_view->priv->search_column = -1;
1090 tree_view->priv->search_position_func = pspp_sheet_view_search_position_func;
1091 tree_view->priv->search_equal_func = pspp_sheet_view_search_equal_func;
1092 tree_view->priv->search_custom_entry_set = FALSE;
1093 tree_view->priv->typeselect_flush_timeout = 0;
1094 tree_view->priv->init_hadjust_value = TRUE;
1095 tree_view->priv->width = 0;
1097 tree_view->priv->hover_selection = FALSE;
1099 tree_view->priv->rubber_banding_enable = FALSE;
1101 tree_view->priv->grid_lines = PSPP_SHEET_VIEW_GRID_LINES_NONE;
1103 tree_view->priv->tooltip_column = -1;
1105 tree_view->priv->special_cells = PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT;
1107 tree_view->priv->post_validation_flag = FALSE;
1109 tree_view->priv->last_button_x = -1;
1110 tree_view->priv->last_button_y = -1;
1112 tree_view->priv->event_last_x = -10000;
1113 tree_view->priv->event_last_y = -10000;
1115 tree_view->priv->prelight_node = -1;
1116 tree_view->priv->rubber_band_start_node = -1;
1117 tree_view->priv->rubber_band_end_node = -1;
1119 tree_view->priv->anchor_column = NULL;
1121 tree_view->priv->button_style = NULL;
1123 tree_view->dispose_has_run = FALSE;
1132 pspp_sheet_view_set_property (GObject *object,
1134 const GValue *value,
1137 PsppSheetView *tree_view;
1139 tree_view = PSPP_SHEET_VIEW (object);
1144 pspp_sheet_view_set_model (tree_view, g_value_get_object (value));
1146 case PROP_HADJUSTMENT:
1147 pspp_sheet_view_set_hadjustment (tree_view, g_value_get_object (value));
1149 case PROP_VADJUSTMENT:
1150 pspp_sheet_view_set_vadjustment (tree_view, g_value_get_object (value));
1152 case PROP_HEADERS_VISIBLE:
1153 pspp_sheet_view_set_headers_visible (tree_view, g_value_get_boolean (value));
1155 case PROP_HEADERS_CLICKABLE:
1156 pspp_sheet_view_set_headers_clickable (tree_view, g_value_get_boolean (value));
1158 case PROP_REORDERABLE:
1159 pspp_sheet_view_set_reorderable (tree_view, g_value_get_boolean (value));
1161 case PROP_RULES_HINT:
1162 pspp_sheet_view_set_rules_hint (tree_view, g_value_get_boolean (value));
1164 case PROP_ENABLE_SEARCH:
1165 pspp_sheet_view_set_enable_search (tree_view, g_value_get_boolean (value));
1167 case PROP_SEARCH_COLUMN:
1168 pspp_sheet_view_set_search_column (tree_view, g_value_get_int (value));
1170 case PROP_HOVER_SELECTION:
1171 tree_view->priv->hover_selection = g_value_get_boolean (value);
1173 case PROP_RUBBER_BANDING:
1174 tree_view->priv->rubber_banding_enable = g_value_get_boolean (value);
1176 case PROP_ENABLE_GRID_LINES:
1177 pspp_sheet_view_set_grid_lines (tree_view, g_value_get_enum (value));
1179 case PROP_TOOLTIP_COLUMN:
1180 pspp_sheet_view_set_tooltip_column (tree_view, g_value_get_int (value));
1182 case PROP_SPECIAL_CELLS:
1183 pspp_sheet_view_set_special_cells (tree_view, g_value_get_enum (value));
1185 case PROP_FIXED_HEIGHT:
1186 pspp_sheet_view_set_fixed_height (tree_view, g_value_get_int (value));
1188 case PROP_FIXED_HEIGHT_SET:
1189 if (g_value_get_boolean (value))
1191 if (!tree_view->priv->fixed_height_set
1192 && tree_view->priv->fixed_height >= 0)
1194 tree_view->priv->fixed_height_set = true;
1195 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
1200 if (tree_view->priv->fixed_height_set)
1202 tree_view->priv->fixed_height_set = false;
1203 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
1204 install_presize_handler (tree_view);
1209 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1215 pspp_sheet_view_get_property (GObject *object,
1220 PsppSheetView *tree_view;
1222 tree_view = PSPP_SHEET_VIEW (object);
1227 g_value_set_object (value, tree_view->priv->model);
1229 case PROP_HADJUSTMENT:
1230 g_value_set_object (value, tree_view->priv->hadjustment);
1232 case PROP_VADJUSTMENT:
1233 g_value_set_object (value, tree_view->priv->vadjustment);
1235 case PROP_HEADERS_VISIBLE:
1236 g_value_set_boolean (value, pspp_sheet_view_get_headers_visible (tree_view));
1238 case PROP_HEADERS_CLICKABLE:
1239 g_value_set_boolean (value, pspp_sheet_view_get_headers_clickable (tree_view));
1241 case PROP_REORDERABLE:
1242 g_value_set_boolean (value, tree_view->priv->reorderable);
1244 case PROP_RULES_HINT:
1245 g_value_set_boolean (value, tree_view->priv->has_rules);
1247 case PROP_ENABLE_SEARCH:
1248 g_value_set_boolean (value, tree_view->priv->enable_search);
1250 case PROP_SEARCH_COLUMN:
1251 g_value_set_int (value, tree_view->priv->search_column);
1253 case PROP_HOVER_SELECTION:
1254 g_value_set_boolean (value, tree_view->priv->hover_selection);
1256 case PROP_RUBBER_BANDING:
1257 g_value_set_boolean (value, tree_view->priv->rubber_banding_enable);
1259 case PROP_ENABLE_GRID_LINES:
1260 g_value_set_enum (value, tree_view->priv->grid_lines);
1262 case PROP_TOOLTIP_COLUMN:
1263 g_value_set_int (value, tree_view->priv->tooltip_column);
1265 case PROP_SPECIAL_CELLS:
1266 g_value_set_enum (value, tree_view->priv->special_cells);
1268 case PROP_FIXED_HEIGHT:
1269 g_value_set_int (value, pspp_sheet_view_get_fixed_height (tree_view));
1271 case PROP_FIXED_HEIGHT_SET:
1272 g_value_set_boolean (value, tree_view->priv->fixed_height_set);
1275 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1281 pspp_sheet_view_dispose (GObject *object)
1283 PsppSheetView *tree_view = PSPP_SHEET_VIEW (object);
1285 if (tree_view->dispose_has_run)
1288 tree_view->dispose_has_run = TRUE;
1290 if (tree_view->priv->selection != NULL)
1292 _pspp_sheet_selection_set_tree_view (tree_view->priv->selection, NULL);
1293 g_object_unref (tree_view->priv->selection);
1294 tree_view->priv->selection = NULL;
1297 if (tree_view->priv->hadjustment)
1299 g_object_unref (tree_view->priv->hadjustment);
1300 tree_view->priv->hadjustment = NULL;
1302 if (tree_view->priv->vadjustment)
1304 g_object_unref (tree_view->priv->vadjustment);
1305 tree_view->priv->vadjustment = NULL;
1308 if (tree_view->priv->button_style)
1310 g_object_unref (tree_view->priv->button_style);
1311 tree_view->priv->button_style = NULL;
1315 G_OBJECT_CLASS (pspp_sheet_view_parent_class)->dispose (object);
1321 pspp_sheet_view_buildable_add_child (GtkBuildable *tree_view,
1322 GtkBuilder *builder,
1326 pspp_sheet_view_append_column (PSPP_SHEET_VIEW (tree_view), PSPP_SHEET_VIEW_COLUMN (child));
1330 pspp_sheet_view_finalize (GObject *object)
1332 PsppSheetView *tree_view = PSPP_SHEET_VIEW (object);
1334 pspp_sheet_view_stop_editing (tree_view, TRUE);
1336 if (tree_view->priv->selected != NULL)
1338 range_tower_destroy (tree_view->priv->selected);
1339 tree_view->priv->selected = NULL;
1343 tree_view->priv->prelight_node = -1;
1346 if (tree_view->priv->scroll_to_path != NULL)
1348 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
1349 tree_view->priv->scroll_to_path = NULL;
1352 if (tree_view->priv->drag_dest_row != NULL)
1354 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
1355 tree_view->priv->drag_dest_row = NULL;
1358 if (tree_view->priv->top_row != NULL)
1360 gtk_tree_row_reference_free (tree_view->priv->top_row);
1361 tree_view->priv->top_row = NULL;
1364 if (tree_view->priv->column_drop_func_data &&
1365 tree_view->priv->column_drop_func_data_destroy)
1367 tree_view->priv->column_drop_func_data_destroy (tree_view->priv->column_drop_func_data);
1368 tree_view->priv->column_drop_func_data = NULL;
1371 if (tree_view->priv->destroy_count_destroy &&
1372 tree_view->priv->destroy_count_data)
1374 tree_view->priv->destroy_count_destroy (tree_view->priv->destroy_count_data);
1375 tree_view->priv->destroy_count_data = NULL;
1378 gtk_tree_row_reference_free (tree_view->priv->cursor);
1379 tree_view->priv->cursor = NULL;
1381 gtk_tree_row_reference_free (tree_view->priv->anchor);
1382 tree_view->priv->anchor = NULL;
1384 /* destroy interactive search dialog */
1385 if (tree_view->priv->search_window)
1387 gtk_widget_destroy (tree_view->priv->search_window);
1388 tree_view->priv->search_window = NULL;
1389 tree_view->priv->search_entry = NULL;
1390 if (tree_view->priv->typeselect_flush_timeout)
1392 g_source_remove (tree_view->priv->typeselect_flush_timeout);
1393 tree_view->priv->typeselect_flush_timeout = 0;
1397 if (tree_view->priv->search_destroy && tree_view->priv->search_user_data)
1399 tree_view->priv->search_destroy (tree_view->priv->search_user_data);
1400 tree_view->priv->search_user_data = NULL;
1403 if (tree_view->priv->search_position_destroy && tree_view->priv->search_position_user_data)
1405 tree_view->priv->search_position_destroy (tree_view->priv->search_position_user_data);
1406 tree_view->priv->search_position_user_data = NULL;
1409 pspp_sheet_view_set_model (tree_view, NULL);
1412 G_OBJECT_CLASS (pspp_sheet_view_parent_class)->finalize (object);
1417 /* GtkWidget Methods
1420 /* GtkWidget::map helper */
1422 pspp_sheet_view_map_buttons (PsppSheetView *tree_view)
1426 g_return_if_fail (gtk_widget_get_mapped (GTK_WIDGET (tree_view)));
1428 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
1430 PsppSheetViewColumn *column;
1432 for (list = tree_view->priv->columns; list; list = list->next)
1434 column = list->data;
1435 if (column->button != NULL &&
1436 gtk_widget_get_visible (column->button) &&
1437 !gtk_widget_get_mapped (column->button))
1438 gtk_widget_map (column->button);
1440 for (list = tree_view->priv->columns; list; list = list->next)
1442 column = list->data;
1443 if (column->visible == FALSE || column->window == NULL)
1445 if (column->resizable)
1447 gdk_window_raise (column->window);
1448 gdk_window_show (column->window);
1451 gdk_window_hide (column->window);
1453 gdk_window_show (tree_view->priv->header_window);
1458 pspp_sheet_view_map (GtkWidget *widget)
1460 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1463 gtk_widget_set_mapped (widget, TRUE);
1465 tmp_list = tree_view->priv->children;
1468 PsppSheetViewChild *child = tmp_list->data;
1469 tmp_list = tmp_list->next;
1471 if (gtk_widget_get_visible (child->widget))
1473 if (!gtk_widget_get_mapped (child->widget))
1474 gtk_widget_map (child->widget);
1477 gdk_window_show (tree_view->priv->bin_window);
1479 pspp_sheet_view_map_buttons (tree_view);
1481 gdk_window_show (gtk_widget_get_window (widget));
1485 pspp_sheet_view_realize (GtkWidget *widget)
1487 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1489 GdkWindowAttr attributes;
1490 gint attributes_mask;
1491 GtkAllocation allocation;
1492 GtkAllocation old_allocation;
1494 gtk_widget_set_realized (widget, TRUE);
1496 gtk_widget_get_allocation (widget, &allocation);
1497 gtk_widget_get_allocation (widget, &old_allocation);
1499 /* Make the main, clipping window */
1500 attributes.window_type = GDK_WINDOW_CHILD;
1501 attributes.x = allocation.x;
1502 attributes.y = allocation.y;
1503 attributes.width = allocation.width;
1504 attributes.height = allocation.height;
1505 attributes.wclass = GDK_INPUT_OUTPUT;
1506 attributes.visual = gtk_widget_get_visual (widget);
1507 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1509 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
1511 gtk_widget_set_window (widget,
1512 gdk_window_new (gtk_widget_get_parent_window (widget),
1513 &attributes, attributes_mask));
1514 gdk_window_set_user_data (gtk_widget_get_window (widget), widget);
1516 /* Make the window for the tree */
1518 attributes.y = TREE_VIEW_HEADER_HEIGHT (tree_view);
1519 attributes.width = MAX (tree_view->priv->width, old_allocation.width);
1520 attributes.height = old_allocation.height;
1521 attributes.event_mask = (GDK_EXPOSURE_MASK |
1523 GDK_POINTER_MOTION_MASK |
1524 GDK_ENTER_NOTIFY_MASK |
1525 GDK_LEAVE_NOTIFY_MASK |
1526 GDK_BUTTON_PRESS_MASK |
1527 GDK_BUTTON_RELEASE_MASK |
1528 gtk_widget_get_events (widget));
1530 tree_view->priv->bin_window = gdk_window_new (gtk_widget_get_window (widget),
1531 &attributes, attributes_mask);
1532 gdk_window_set_user_data (tree_view->priv->bin_window, widget);
1534 /* Make the column header window */
1537 attributes.width = MAX (tree_view->priv->width, old_allocation.width);
1538 attributes.height = tree_view->priv->header_height;
1539 attributes.event_mask = (GDK_EXPOSURE_MASK |
1541 GDK_BUTTON_PRESS_MASK |
1542 GDK_BUTTON_RELEASE_MASK |
1543 GDK_KEY_PRESS_MASK |
1544 GDK_KEY_RELEASE_MASK |
1545 gtk_widget_get_events (widget));
1547 tree_view->priv->header_window = gdk_window_new (gtk_widget_get_window (widget),
1548 &attributes, attributes_mask);
1549 gdk_window_set_user_data (tree_view->priv->header_window, widget);
1551 /* Add them all up. */
1552 gtk_widget_set_style (widget,
1553 gtk_style_attach (gtk_widget_get_style (widget), gtk_widget_get_window (widget)));
1554 gdk_window_set_background (tree_view->priv->bin_window, >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
1555 gtk_style_set_background (gtk_widget_get_style (widget), tree_view->priv->header_window, GTK_STATE_NORMAL);
1557 tmp_list = tree_view->priv->children;
1560 PsppSheetViewChild *child = tmp_list->data;
1561 tmp_list = tmp_list->next;
1563 gtk_widget_set_parent_window (child->widget, tree_view->priv->bin_window);
1566 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
1567 _pspp_sheet_view_column_realize_button (PSPP_SHEET_VIEW_COLUMN (tmp_list->data));
1569 /* Need to call those here, since they create GCs */
1570 pspp_sheet_view_set_grid_lines (tree_view, tree_view->priv->grid_lines);
1572 install_presize_handler (tree_view);
1576 pspp_sheet_view_unrealize (GtkWidget *widget)
1578 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1579 PsppSheetViewPrivate *priv = tree_view->priv;
1582 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->unrealize (widget);
1584 if (priv->scroll_timeout != 0)
1586 g_source_remove (priv->scroll_timeout);
1587 priv->scroll_timeout = 0;
1590 if (priv->open_dest_timeout != 0)
1592 g_source_remove (priv->open_dest_timeout);
1593 priv->open_dest_timeout = 0;
1596 if (priv->presize_handler_timer != 0)
1598 g_source_remove (priv->presize_handler_timer);
1599 priv->presize_handler_timer = 0;
1602 if (priv->validate_rows_timer != 0)
1604 g_source_remove (priv->validate_rows_timer);
1605 priv->validate_rows_timer = 0;
1608 if (priv->scroll_sync_timer != 0)
1610 g_source_remove (priv->scroll_sync_timer);
1611 priv->scroll_sync_timer = 0;
1614 if (priv->typeselect_flush_timeout)
1616 g_source_remove (priv->typeselect_flush_timeout);
1617 priv->typeselect_flush_timeout = 0;
1620 for (list = priv->columns; list; list = list->next)
1621 _pspp_sheet_view_column_unrealize_button (PSPP_SHEET_VIEW_COLUMN (list->data));
1623 gdk_window_set_user_data (priv->bin_window, NULL);
1624 gdk_window_destroy (priv->bin_window);
1625 priv->bin_window = NULL;
1627 gdk_window_set_user_data (priv->header_window, NULL);
1628 gdk_window_destroy (priv->header_window);
1629 priv->header_window = NULL;
1631 if (priv->drag_window)
1633 gdk_window_set_user_data (priv->drag_window, NULL);
1634 gdk_window_destroy (priv->drag_window);
1635 priv->drag_window = NULL;
1638 if (priv->drag_highlight_window)
1640 gdk_window_set_user_data (priv->drag_highlight_window, NULL);
1641 gdk_window_destroy (priv->drag_highlight_window);
1642 priv->drag_highlight_window = NULL;
1645 if (tree_view->priv->columns != NULL)
1647 list = tree_view->priv->columns;
1650 PsppSheetViewColumn *column;
1651 column = PSPP_SHEET_VIEW_COLUMN (list->data);
1653 pspp_sheet_view_remove_column (tree_view, column);
1655 tree_view->priv->columns = NULL;
1659 /* GtkWidget::size_request helper */
1661 pspp_sheet_view_size_request_columns (PsppSheetView *tree_view)
1665 tree_view->priv->header_height = 0;
1667 if (tree_view->priv->model)
1669 for (list = tree_view->priv->columns; list; list = list->next)
1671 GtkRequisition requisition;
1672 PsppSheetViewColumn *column = list->data;
1674 pspp_sheet_view_column_size_request (column, &requisition);
1675 column->button_request = requisition.width;
1676 tree_view->priv->header_height = MAX (tree_view->priv->header_height, requisition.height);
1682 /* Called only by ::size_request */
1684 pspp_sheet_view_update_size (PsppSheetView *tree_view)
1687 PsppSheetViewColumn *column;
1690 if (tree_view->priv->model == NULL)
1692 tree_view->priv->width = 0;
1693 tree_view->priv->prev_width = 0;
1694 tree_view->priv->height = 0;
1698 tree_view->priv->prev_width = tree_view->priv->width;
1699 tree_view->priv->width = 0;
1701 /* keep this in sync with size_allocate below */
1702 for (list = tree_view->priv->columns, i = 0; list; list = list->next, i++)
1704 gint real_requested_width = 0;
1705 column = list->data;
1706 if (!column->visible)
1709 if (column->use_resized_width)
1711 real_requested_width = column->resized_width;
1715 real_requested_width = column->fixed_width;
1718 if (column->min_width != -1)
1719 real_requested_width = MAX (real_requested_width, column->min_width);
1720 if (column->max_width != -1)
1721 real_requested_width = MIN (real_requested_width, column->max_width);
1723 tree_view->priv->width += real_requested_width;
1726 tree_view->priv->height = tree_view->priv->fixed_height * tree_view->priv->row_count;
1730 pspp_sheet_view_size_request (GtkWidget *widget,
1731 GtkRequisition *requisition)
1733 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1736 /* we validate some rows initially just to make sure we have some size.
1737 * In practice, with a lot of static lists, this should get a good width.
1739 initialize_fixed_height_mode (tree_view);
1740 pspp_sheet_view_size_request_columns (tree_view);
1741 pspp_sheet_view_update_size (PSPP_SHEET_VIEW (widget));
1743 requisition->width = tree_view->priv->width;
1744 requisition->height = tree_view->priv->height + TREE_VIEW_HEADER_HEIGHT (tree_view);
1746 tmp_list = tree_view->priv->children;
1750 PsppSheetViewChild *child = tmp_list->data;
1751 GtkRequisition child_requisition;
1753 tmp_list = tmp_list->next;
1755 if (gtk_widget_get_visible (child->widget))
1756 gtk_widget_size_request (child->widget, &child_requisition);
1761 invalidate_column (PsppSheetView *tree_view,
1762 PsppSheetViewColumn *column)
1764 gint column_offset = 0;
1766 GtkWidget *widget = GTK_WIDGET (tree_view);
1769 if (!gtk_widget_get_realized (widget))
1772 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
1773 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
1775 list = (rtl ? list->prev : list->next))
1777 PsppSheetViewColumn *tmpcolumn = list->data;
1778 if (tmpcolumn == column)
1780 GdkRectangle invalid_rect;
1781 GtkAllocation allocation;
1783 gtk_widget_get_allocation (widget, &allocation);
1784 invalid_rect.x = column_offset;
1786 invalid_rect.width = column->width;
1787 invalid_rect.height = allocation.height;
1789 gdk_window_invalidate_rect (gtk_widget_get_window (widget), &invalid_rect, TRUE);
1793 column_offset += tmpcolumn->width;
1798 invalidate_last_column (PsppSheetView *tree_view)
1803 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
1805 for (last_column = (rtl ? g_list_first (tree_view->priv->columns) : g_list_last (tree_view->priv->columns));
1807 last_column = (rtl ? last_column->next : last_column->prev))
1809 if (PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible)
1811 invalidate_column (tree_view, last_column->data);
1818 pspp_sheet_view_get_real_requested_width_from_column (PsppSheetView *tree_view,
1819 PsppSheetViewColumn *column)
1821 gint real_requested_width;
1823 if (column->use_resized_width)
1825 real_requested_width = column->resized_width;
1829 real_requested_width = column->fixed_width;
1832 if (column->min_width != -1)
1833 real_requested_width = MAX (real_requested_width, column->min_width);
1834 if (column->max_width != -1)
1835 real_requested_width = MIN (real_requested_width, column->max_width);
1837 return real_requested_width;
1841 span_intersects (int a0, int a_width,
1842 int b0, int b_width)
1844 int a1 = a0 + a_width;
1845 int b1 = b0 + b_width;
1846 return (a0 >= b0 && a0 < b1) || (b0 >= a0 && b0 < a1);
1849 /* GtkWidget::size_allocate helper */
1851 pspp_sheet_view_size_allocate_columns (GtkWidget *widget,
1852 gboolean *width_changed)
1854 PsppSheetView *tree_view;
1855 GList *list, *first_column, *last_column;
1856 PsppSheetViewColumn *column;
1857 GtkAllocation col_allocation;
1858 GtkAllocation allocation;
1860 gint extra, extra_per_column;
1861 gint full_requested_width = 0;
1862 gint number_of_expand_columns = 0;
1863 gboolean column_changed = FALSE;
1866 tree_view = PSPP_SHEET_VIEW (widget);
1868 for (last_column = g_list_last (tree_view->priv->columns);
1869 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
1870 last_column = last_column->prev)
1873 if (last_column == NULL)
1876 for (first_column = g_list_first (tree_view->priv->columns);
1877 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
1878 first_column = first_column->next)
1881 col_allocation.y = 0;
1882 col_allocation.height = tree_view->priv->header_height;
1884 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1886 /* find out how many extra space and expandable columns we have */
1887 for (list = tree_view->priv->columns; list != last_column->next; list = list->next)
1889 column = (PsppSheetViewColumn *)list->data;
1891 if (!column->visible)
1894 full_requested_width += pspp_sheet_view_get_real_requested_width_from_column (tree_view, column);
1897 number_of_expand_columns++;
1900 gtk_widget_get_allocation (widget, &allocation);
1901 extra = MAX (allocation.width - full_requested_width, 0);
1902 if (number_of_expand_columns > 0)
1903 extra_per_column = extra/number_of_expand_columns;
1905 extra_per_column = 0;
1907 for (list = (rtl ? last_column : first_column);
1908 list != (rtl ? first_column->prev : last_column->next);
1909 list = (rtl ? list->prev : list->next))
1911 gint real_requested_width = 0;
1914 column = list->data;
1915 old_width = column->width;
1917 if (!column->visible)
1920 /* We need to handle the dragged button specially.
1922 if (column == tree_view->priv->drag_column)
1924 GtkAllocation drag_allocation;
1925 drag_allocation.width = gdk_window_get_width (tree_view->priv->drag_window);
1926 drag_allocation.height = gdk_window_get_height (tree_view->priv->drag_window);
1927 drag_allocation.x = 0;
1928 drag_allocation.y = 0;
1929 pspp_sheet_view_column_size_allocate (tree_view->priv->drag_column,
1931 width += drag_allocation.width;
1935 real_requested_width = pspp_sheet_view_get_real_requested_width_from_column (tree_view, column);
1937 col_allocation.x = width;
1938 column->width = real_requested_width;
1942 if (number_of_expand_columns == 1)
1944 /* We add the remander to the last column as
1946 column->width += extra;
1950 column->width += extra_per_column;
1951 extra -= extra_per_column;
1952 number_of_expand_columns --;
1956 if (column->width != old_width)
1957 g_object_notify (G_OBJECT (column), "width");
1959 col_allocation.width = column->width;
1960 width += column->width;
1962 if (column->width > old_width)
1963 column_changed = TRUE;
1965 pspp_sheet_view_column_size_allocate (column, &col_allocation);
1967 if (span_intersects (col_allocation.x, col_allocation.width,
1968 gtk_adjustment_get_value (tree_view->priv->hadjustment),
1970 && gtk_widget_get_realized (widget))
1971 pspp_sheet_view_column_set_need_button (column, TRUE);
1974 gdk_window_move_resize (column->window,
1975 col_allocation.x + (rtl ? 0 : col_allocation.width) - TREE_VIEW_DRAG_WIDTH/2,
1977 TREE_VIEW_DRAG_WIDTH, col_allocation.height);
1980 /* We change the width here. The user might have been resizing columns,
1981 * so the total width of the tree view changes.
1983 tree_view->priv->width = width;
1985 *width_changed = TRUE;
1988 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
1992 pspp_sheet_view_size_allocate (GtkWidget *widget,
1993 GtkAllocation *allocation)
1995 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1997 gboolean width_changed = FALSE;
1998 GtkAllocation old_allocation;
1999 gtk_widget_get_allocation (widget, &old_allocation);
2001 if (allocation->width != old_allocation.width)
2002 width_changed = TRUE;
2005 gtk_widget_set_allocation (widget, allocation);
2007 tmp_list = tree_view->priv->children;
2011 GtkAllocation allocation;
2013 PsppSheetViewChild *child = tmp_list->data;
2014 tmp_list = tmp_list->next;
2016 /* totally ignore our child's requisition */
2017 allocation.x = child->x;
2018 allocation.y = child->y;
2019 allocation.width = child->width;
2020 allocation.height = child->height;
2021 gtk_widget_size_allocate (child->widget, &allocation);
2024 /* We size-allocate the columns first because the width of the
2025 * tree view (used in updating the adjustments below) might change.
2027 pspp_sheet_view_size_allocate_columns (widget, &width_changed);
2029 gtk_adjustment_set_page_size (tree_view->priv->hadjustment, allocation->width);
2030 gtk_adjustment_set_page_increment (tree_view->priv->hadjustment, allocation->width * 0.9);
2031 gtk_adjustment_set_step_increment (tree_view->priv->hadjustment, allocation->width * 0.1);
2032 gtk_adjustment_set_lower (tree_view->priv->hadjustment, 0);
2033 gtk_adjustment_set_upper (tree_view->priv->hadjustment, MAX (gtk_adjustment_get_page_size (tree_view->priv->hadjustment), tree_view->priv->width));
2035 if (gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL)
2037 if (allocation->width < tree_view->priv->width)
2039 if (tree_view->priv->init_hadjust_value)
2041 gtk_adjustment_set_value (tree_view->priv->hadjustment, MAX (tree_view->priv->width - allocation->width, 0));
2042 tree_view->priv->init_hadjust_value = FALSE;
2044 else if (allocation->width != old_allocation.width)
2046 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));
2049 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));
2053 gtk_adjustment_set_value (tree_view->priv->hadjustment, 0);
2054 tree_view->priv->init_hadjust_value = TRUE;
2058 if (gtk_adjustment_get_value (tree_view->priv->hadjustment) + allocation->width > tree_view->priv->width)
2059 gtk_adjustment_set_value (tree_view->priv->hadjustment, MAX (tree_view->priv->width - allocation->width, 0));
2061 gtk_adjustment_changed (tree_view->priv->hadjustment);
2063 gtk_adjustment_set_page_size (tree_view->priv->vadjustment, allocation->height - TREE_VIEW_HEADER_HEIGHT (tree_view));
2064 gtk_adjustment_set_step_increment (tree_view->priv->vadjustment, gtk_adjustment_get_page_size (tree_view->priv->vadjustment) * 0.1);
2065 gtk_adjustment_set_page_increment (tree_view->priv->vadjustment, gtk_adjustment_get_page_size (tree_view->priv->vadjustment) * 0.9);
2066 gtk_adjustment_set_lower (tree_view->priv->vadjustment, 0);
2067 gtk_adjustment_set_upper (tree_view->priv->vadjustment, MAX (gtk_adjustment_get_page_size (tree_view->priv->vadjustment), tree_view->priv->height));
2069 gtk_adjustment_changed (tree_view->priv->vadjustment);
2071 /* now the adjustments and window sizes are in sync, we can sync toprow/dy again */
2072 if (tree_view->priv->height <= gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
2073 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment), 0);
2074 else if (gtk_adjustment_get_value (tree_view->priv->vadjustment) + gtk_adjustment_get_page_size (tree_view->priv->vadjustment) > tree_view->priv->height)
2075 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment),
2076 tree_view->priv->height - gtk_adjustment_get_page_size (tree_view->priv->vadjustment));
2077 else if (gtk_tree_row_reference_valid (tree_view->priv->top_row))
2078 pspp_sheet_view_top_row_to_dy (tree_view);
2080 pspp_sheet_view_dy_to_top_row (tree_view);
2082 if (gtk_widget_get_realized (widget))
2084 gdk_window_move_resize (gtk_widget_get_window (widget),
2085 allocation->x, allocation->y,
2086 allocation->width, allocation->height);
2087 gdk_window_move_resize (tree_view->priv->header_window,
2088 - (gint) gtk_adjustment_get_value (tree_view->priv->hadjustment),
2090 MAX (tree_view->priv->width, allocation->width),
2091 tree_view->priv->header_height);
2092 gdk_window_move_resize (tree_view->priv->bin_window,
2093 - (gint) gtk_adjustment_get_value (tree_view->priv->hadjustment),
2094 TREE_VIEW_HEADER_HEIGHT (tree_view),
2095 MAX (tree_view->priv->width, allocation->width),
2096 allocation->height - TREE_VIEW_HEADER_HEIGHT (tree_view));
2099 if (tree_view->priv->row_count == 0)
2100 invalidate_empty_focus (tree_view);
2102 if (gtk_widget_get_realized (widget))
2104 gboolean has_expand_column = FALSE;
2105 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
2107 if (pspp_sheet_view_column_get_expand (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)))
2109 has_expand_column = TRUE;
2114 /* This little hack only works if we have an LTR locale, and no column has the */
2117 if (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_LTR &&
2118 ! has_expand_column)
2119 invalidate_last_column (tree_view);
2121 gtk_widget_queue_draw (widget);
2126 /* Grabs the focus and unsets the PSPP_SHEET_VIEW_DRAW_KEYFOCUS flag */
2128 grab_focus_and_unset_draw_keyfocus (PsppSheetView *tree_view)
2130 GtkWidget *widget = GTK_WIDGET (tree_view);
2132 if (gtk_widget_get_can_focus (widget) && !gtk_widget_has_focus (widget))
2133 gtk_widget_grab_focus (widget);
2134 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
2138 pspp_sheet_view_node_is_selected (PsppSheetView *tree_view,
2141 return node >= 0 && range_tower_contains (tree_view->priv->selected, node);
2145 pspp_sheet_view_node_select (PsppSheetView *tree_view,
2148 range_tower_set1 (tree_view->priv->selected, node, 1);
2152 pspp_sheet_view_node_unselect (PsppSheetView *tree_view,
2155 range_tower_set0 (tree_view->priv->selected, node, 1);
2159 pspp_sheet_view_node_next (PsppSheetView *tree_view,
2162 return node + 1 < tree_view->priv->row_count ? node + 1 : -1;
2166 pspp_sheet_view_node_prev (PsppSheetView *tree_view,
2169 return node > 0 ? node - 1 : -1;
2173 all_columns_selected (PsppSheetView *tree_view)
2177 for (list = tree_view->priv->columns; list; list = list->next)
2179 PsppSheetViewColumn *column = list->data;
2180 if (column->selectable && !column->selected)
2188 pspp_sheet_view_row_head_clicked (PsppSheetView *tree_view,
2190 PsppSheetViewColumn *column,
2191 GdkEventButton *event)
2193 PsppSheetSelection *selection;
2194 PsppSheetSelectionMode mode;
2196 gboolean update_anchor;
2200 g_return_val_if_fail (tree_view != NULL, FALSE);
2201 g_return_val_if_fail (column != NULL, FALSE);
2203 selection = tree_view->priv->selection;
2204 mode = pspp_sheet_selection_get_mode (selection);
2205 if (mode != PSPP_SHEET_SELECTION_RECTANGLE)
2208 if (!column->row_head)
2213 modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
2214 if (event->type != GDK_BUTTON_PRESS
2215 || (modifiers != GDK_CONTROL_MASK && modifiers != GDK_SHIFT_MASK))
2221 path = gtk_tree_path_new_from_indices (node, -1);
2224 pspp_sheet_selection_unselect_all (selection);
2225 pspp_sheet_selection_select_path (selection, path);
2226 pspp_sheet_selection_select_all_columns (selection);
2227 update_anchor = TRUE;
2230 else if (event->type == GDK_BUTTON_PRESS && event->button == 3)
2232 if (pspp_sheet_selection_count_selected_rows (selection) <= 1
2233 || !all_columns_selected (tree_view))
2235 pspp_sheet_selection_unselect_all (selection);
2236 pspp_sheet_selection_select_path (selection, path);
2237 pspp_sheet_selection_select_all_columns (selection);
2238 update_anchor = TRUE;
2242 update_anchor = handled = FALSE;
2244 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
2245 && modifiers == GDK_CONTROL_MASK)
2247 if (!all_columns_selected (tree_view))
2249 pspp_sheet_selection_unselect_all (selection);
2250 pspp_sheet_selection_select_all_columns (selection);
2253 if (pspp_sheet_selection_path_is_selected (selection, path))
2254 pspp_sheet_selection_unselect_path (selection, path);
2256 pspp_sheet_selection_select_path (selection, path);
2257 update_anchor = TRUE;
2260 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
2261 && modifiers == GDK_SHIFT_MASK)
2263 GtkTreeRowReference *anchor = tree_view->priv->anchor;
2264 GtkTreePath *anchor_path;
2266 if (all_columns_selected (tree_view)
2267 && gtk_tree_row_reference_valid (anchor))
2269 update_anchor = FALSE;
2270 anchor_path = gtk_tree_row_reference_get_path (anchor);
2274 update_anchor = TRUE;
2275 anchor_path = gtk_tree_path_copy (path);
2278 pspp_sheet_selection_unselect_all (selection);
2279 pspp_sheet_selection_select_range (selection, anchor_path, path);
2280 pspp_sheet_selection_select_all_columns (selection);
2282 gtk_tree_path_free (anchor_path);
2287 update_anchor = handled = FALSE;
2291 if (tree_view->priv->anchor)
2292 gtk_tree_row_reference_free (tree_view->priv->anchor);
2293 tree_view->priv->anchor =
2294 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
2295 tree_view->priv->model,
2299 gtk_tree_path_free (path);
2304 find_click (PsppSheetView *tree_view,
2307 PsppSheetViewColumn **column,
2308 GdkRectangle *background_area,
2309 GdkRectangle *cell_area)
2316 /* find the node that was clicked */
2317 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, y);
2320 y_offset = -pspp_sheet_view_find_offset (tree_view, new_y, node);
2325 background_area->y = y_offset + y;
2326 background_area->height = ROW_HEIGHT (tree_view);
2327 background_area->x = 0;
2329 /* Let the column have a chance at selecting it. */
2330 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
2331 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
2332 list; list = (rtl ? list->prev : list->next))
2334 PsppSheetViewColumn *candidate = list->data;
2336 if (!candidate->visible)
2339 background_area->width = candidate->width;
2340 if ((background_area->x > x) ||
2341 (background_area->x + background_area->width <= x))
2343 background_area->x += background_area->width;
2347 /* we found the focus column */
2349 pspp_sheet_view_adjust_cell_area (tree_view, candidate, background_area,
2351 *column = candidate;
2359 pspp_sheet_view_button_press (GtkWidget *widget,
2360 GdkEventButton *event)
2362 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2364 PsppSheetViewColumn *column = NULL;
2366 GdkRectangle background_area;
2367 GdkRectangle cell_area;
2370 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
2371 pspp_sheet_view_stop_editing (tree_view, FALSE);
2374 /* Because grab_focus can cause reentrancy, we delay grab_focus until after
2375 * we're done handling the button press.
2378 if (event->window == tree_view->priv->bin_window)
2383 gint pre_val, aft_val;
2384 PsppSheetViewColumn *column = NULL;
2385 GtkCellRenderer *focus_cell = NULL;
2386 gboolean row_double_click = FALSE;
2389 if (tree_view->priv->row_count == 0)
2391 grab_focus_and_unset_draw_keyfocus (tree_view);
2395 if (!find_click (tree_view, event->x, event->y, &node, &column,
2396 &background_area, &cell_area))
2398 grab_focus_and_unset_draw_keyfocus (tree_view);
2402 tree_view->priv->focus_column = column;
2404 if (pspp_sheet_view_row_head_clicked (tree_view, node, column, event))
2408 pre_val = gtk_adjustment_get_value (tree_view->priv->vadjustment);
2410 path = _pspp_sheet_view_find_path (tree_view, node);
2412 /* we only handle selection modifications on the first button press
2414 if (event->type == GDK_BUTTON_PRESS)
2416 PsppSheetSelectionMode mode = 0;
2418 if ((event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
2419 mode |= PSPP_SHEET_SELECT_MODE_TOGGLE;
2420 if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
2421 mode |= PSPP_SHEET_SELECT_MODE_EXTEND;
2423 focus_cell = _pspp_sheet_view_column_get_cell_at_pos (column, event->x - background_area.x);
2425 pspp_sheet_view_column_focus_cell (column, focus_cell);
2427 if (event->state & GDK_CONTROL_MASK)
2429 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE, mode);
2430 pspp_sheet_view_real_toggle_cursor_row (tree_view);
2432 else if (event->state & GDK_SHIFT_MASK)
2434 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, mode);
2435 pspp_sheet_view_real_select_cursor_row (tree_view, FALSE, mode);
2439 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, 0);
2442 if (tree_view->priv->anchor_column == NULL ||
2443 !(event->state & GDK_SHIFT_MASK))
2444 tree_view->priv->anchor_column = column;
2445 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
2446 pspp_sheet_selection_select_column_range (tree_view->priv->selection,
2447 tree_view->priv->anchor_column,
2451 /* the treeview may have been scrolled because of _set_cursor,
2455 aft_val = gtk_adjustment_get_value (tree_view->priv->vadjustment);
2456 dval = pre_val - aft_val;
2458 cell_area.y += dval;
2459 background_area.y += dval;
2461 /* Save press to possibly begin a drag
2463 if (!tree_view->priv->in_grab &&
2464 tree_view->priv->pressed_button < 0)
2466 tree_view->priv->pressed_button = event->button;
2467 tree_view->priv->press_start_x = event->x;
2468 tree_view->priv->press_start_y = event->y;
2469 tree_view->priv->press_start_node = node;
2471 if (tree_view->priv->rubber_banding_enable
2472 && (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
2473 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE))
2475 tree_view->priv->press_start_y += tree_view->priv->dy;
2476 tree_view->priv->rubber_band_x = event->x;
2477 tree_view->priv->rubber_band_y = event->y + tree_view->priv->dy;
2478 tree_view->priv->rubber_band_status = RUBBER_BAND_MAYBE_START;
2480 if ((event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
2481 tree_view->priv->rubber_band_ctrl = TRUE;
2482 if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
2483 tree_view->priv->rubber_band_shift = TRUE;
2488 /* Test if a double click happened on the same row. */
2489 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
2491 int double_click_time, double_click_distance;
2493 g_object_get (gtk_settings_get_for_screen (
2494 gtk_widget_get_screen (widget)),
2495 "gtk-double-click-time", &double_click_time,
2496 "gtk-double-click-distance", &double_click_distance,
2499 /* Same conditions as _gdk_event_button_generate */
2500 if (tree_view->priv->last_button_x != -1 &&
2501 (event->time < tree_view->priv->last_button_time + double_click_time) &&
2502 (ABS (event->x - tree_view->priv->last_button_x) <= double_click_distance) &&
2503 (ABS (event->y - tree_view->priv->last_button_y) <= double_click_distance))
2505 /* We do no longer compare paths of this row and the
2506 * row clicked previously. We use the double click
2507 * distance to decide whether this is a valid click,
2508 * allowing the mouse to slightly move over another row.
2510 row_double_click = TRUE;
2512 tree_view->priv->last_button_time = 0;
2513 tree_view->priv->last_button_x = -1;
2514 tree_view->priv->last_button_y = -1;
2518 tree_view->priv->last_button_time = event->time;
2519 tree_view->priv->last_button_x = event->x;
2520 tree_view->priv->last_button_y = event->y;
2524 if (row_double_click)
2526 gtk_grab_remove (widget);
2527 pspp_sheet_view_row_activated (tree_view, path, column);
2529 if (tree_view->priv->pressed_button == event->button)
2530 tree_view->priv->pressed_button = -1;
2533 gtk_tree_path_free (path);
2535 /* If we activated the row through a double click we don't want to grab
2536 * focus back, as moving focus to another widget is pretty common.
2538 if (!row_double_click)
2539 grab_focus_and_unset_draw_keyfocus (tree_view);
2544 /* We didn't click in the window. Let's check to see if we clicked on a column resize window.
2546 for (i = 0, list = tree_view->priv->columns; list; list = list->next, i++)
2548 column = list->data;
2549 if (event->window == column->window &&
2550 column->resizable &&
2555 if (gdk_pointer_grab (column->window, FALSE,
2556 GDK_POINTER_MOTION_HINT_MASK |
2557 GDK_BUTTON1_MOTION_MASK |
2558 GDK_BUTTON_RELEASE_MASK,
2559 NULL, NULL, event->time))
2562 gtk_grab_add (widget);
2563 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE);
2564 column->resized_width = column->width;
2566 /* block attached dnd signal handler */
2567 drag_data = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
2569 g_signal_handlers_block_matched (widget,
2570 G_SIGNAL_MATCH_DATA,
2574 tree_view->priv->drag_pos = i;
2575 tree_view->priv->x_drag = column->allocation.x + (rtl ? 0 : column->allocation.width);
2577 if (!gtk_widget_has_focus (widget))
2578 gtk_widget_grab_focus (widget);
2586 /* GtkWidget::button_release_event helper */
2588 pspp_sheet_view_button_release_drag_column (GtkWidget *widget,
2589 GdkEventButton *event)
2591 PsppSheetView *tree_view;
2595 tree_view = PSPP_SHEET_VIEW (widget);
2597 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
2598 gdk_display_pointer_ungrab (gtk_widget_get_display (widget), GDK_CURRENT_TIME);
2599 gdk_display_keyboard_ungrab (gtk_widget_get_display (widget), GDK_CURRENT_TIME);
2601 /* Move the button back */
2602 g_return_val_if_fail (tree_view->priv->drag_column->button, FALSE);
2604 g_object_ref (tree_view->priv->drag_column->button);
2605 gtk_container_remove (GTK_CONTAINER (tree_view), tree_view->priv->drag_column->button);
2606 gtk_widget_set_parent_window (tree_view->priv->drag_column->button, tree_view->priv->header_window);
2607 gtk_widget_set_parent (tree_view->priv->drag_column->button, GTK_WIDGET (tree_view));
2608 g_object_unref (tree_view->priv->drag_column->button);
2609 gtk_widget_queue_resize (widget);
2610 if (tree_view->priv->drag_column->resizable)
2612 gdk_window_raise (tree_view->priv->drag_column->window);
2613 gdk_window_show (tree_view->priv->drag_column->window);
2616 gdk_window_hide (tree_view->priv->drag_column->window);
2618 gtk_widget_grab_focus (tree_view->priv->drag_column->button);
2622 if (tree_view->priv->cur_reorder &&
2623 tree_view->priv->cur_reorder->right_column != tree_view->priv->drag_column)
2624 pspp_sheet_view_move_column_after (tree_view, tree_view->priv->drag_column,
2625 tree_view->priv->cur_reorder->right_column);
2629 if (tree_view->priv->cur_reorder &&
2630 tree_view->priv->cur_reorder->left_column != tree_view->priv->drag_column)
2631 pspp_sheet_view_move_column_after (tree_view, tree_view->priv->drag_column,
2632 tree_view->priv->cur_reorder->left_column);
2634 tree_view->priv->drag_column = NULL;
2635 gdk_window_hide (tree_view->priv->drag_window);
2637 for (l = tree_view->priv->column_drag_info; l != NULL; l = l->next)
2638 g_slice_free (PsppSheetViewColumnReorder, l->data);
2639 g_list_free (tree_view->priv->column_drag_info);
2640 tree_view->priv->column_drag_info = NULL;
2641 tree_view->priv->cur_reorder = NULL;
2643 if (tree_view->priv->drag_highlight_window)
2644 gdk_window_hide (tree_view->priv->drag_highlight_window);
2646 /* Reset our flags */
2647 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_UNSET;
2648 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG);
2653 /* GtkWidget::button_release_event helper */
2655 pspp_sheet_view_button_release_column_resize (GtkWidget *widget,
2656 GdkEventButton *event)
2658 PsppSheetView *tree_view;
2661 tree_view = PSPP_SHEET_VIEW (widget);
2663 tree_view->priv->drag_pos = -1;
2665 /* unblock attached dnd signal handler */
2666 drag_data = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
2668 g_signal_handlers_unblock_matched (widget,
2669 G_SIGNAL_MATCH_DATA,
2673 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE);
2674 gtk_grab_remove (widget);
2675 gdk_display_pointer_ungrab (gdk_window_get_display (event->window),
2681 pspp_sheet_view_button_release_edit (PsppSheetView *tree_view,
2682 GdkEventButton *event)
2684 GtkCellEditable *cell_editable;
2689 PsppSheetViewColumn *column;
2690 GdkRectangle background_area;
2691 GdkRectangle cell_area;
2697 if (event->window != tree_view->priv->bin_window)
2700 /* Ignore a released button, if that button wasn't depressed */
2701 if (tree_view->priv->pressed_button != event->button)
2704 if (!find_click (tree_view, event->x, event->y, &node, &column, &background_area,
2708 /* decide if we edit */
2709 path = _pspp_sheet_view_find_path (tree_view, node);
2710 modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
2711 if (event->button != 1 || modifiers)
2714 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
2715 pspp_sheet_view_column_cell_set_cell_data (column,
2716 tree_view->priv->model,
2719 if (!pspp_sheet_view_column_get_quick_edit (column)
2720 && _pspp_sheet_view_column_has_editable_cell (column))
2723 flags = 0; /* FIXME: get the right flags */
2724 path_string = gtk_tree_path_to_string (path);
2726 if (!_pspp_sheet_view_column_cell_event (column,
2734 if (cell_editable == NULL)
2737 pspp_sheet_view_real_set_cursor (tree_view, path,
2738 TRUE, TRUE, 0); /* XXX mode? */
2739 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
2742 _pspp_sheet_view_column_get_neighbor_sizes (
2743 column, _pspp_sheet_view_column_get_edited_cell (column), &left, &right);
2746 area.width -= right + left;
2748 pspp_sheet_view_real_start_editing (tree_view,
2755 g_free (path_string);
2756 gtk_tree_path_free (path);
2761 pspp_sheet_view_button_release (GtkWidget *widget,
2762 GdkEventButton *event)
2764 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2766 pspp_sheet_view_stop_editing (tree_view, FALSE);
2767 if (tree_view->priv->rubber_band_status != RUBBER_BAND_ACTIVE
2768 && pspp_sheet_view_button_release_edit (tree_view, event))
2770 if (tree_view->priv->pressed_button == event->button)
2771 tree_view->priv->pressed_button = -1;
2773 tree_view->priv->rubber_band_status = RUBBER_BAND_OFF;
2777 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
2778 return pspp_sheet_view_button_release_drag_column (widget, event);
2780 if (tree_view->priv->rubber_band_status)
2781 pspp_sheet_view_stop_rubber_band (tree_view);
2783 if (tree_view->priv->pressed_button == event->button)
2784 tree_view->priv->pressed_button = -1;
2786 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
2787 return pspp_sheet_view_button_release_column_resize (widget, event);
2793 pspp_sheet_view_grab_broken (GtkWidget *widget,
2794 GdkEventGrabBroken *event)
2796 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2798 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
2799 pspp_sheet_view_button_release_drag_column (widget, (GdkEventButton *)event);
2801 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
2802 pspp_sheet_view_button_release_column_resize (widget, (GdkEventButton *)event);
2807 /* GtkWidget::motion_event function set.
2811 do_prelight (PsppSheetView *tree_view,
2813 /* these are in bin_window coords */
2817 int prev_node = tree_view->priv->prelight_node;
2819 if (prev_node != node)
2821 tree_view->priv->prelight_node = node;
2824 _pspp_sheet_view_queue_draw_node (tree_view, prev_node, NULL);
2827 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
2833 prelight_or_select (PsppSheetView *tree_view,
2835 /* these are in bin_window coords */
2839 PsppSheetSelectionMode mode = pspp_sheet_selection_get_mode (tree_view->priv->selection);
2841 if (tree_view->priv->hover_selection &&
2842 (mode == PSPP_SHEET_SELECTION_SINGLE || mode == PSPP_SHEET_SELECTION_BROWSE) &&
2843 !(tree_view->priv->edited_column &&
2844 tree_view->priv->edited_column->editable_widget))
2848 if (!pspp_sheet_view_node_is_selected (tree_view, node))
2852 path = _pspp_sheet_view_find_path (tree_view, node);
2853 pspp_sheet_selection_select_path (tree_view->priv->selection, path);
2854 if (pspp_sheet_view_node_is_selected (tree_view, node))
2856 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
2857 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, FALSE, 0); /* XXX mode? */
2859 gtk_tree_path_free (path);
2863 else if (mode == PSPP_SHEET_SELECTION_SINGLE)
2864 pspp_sheet_selection_unselect_all (tree_view->priv->selection);
2867 do_prelight (tree_view, node, x, y);
2871 ensure_unprelighted (PsppSheetView *tree_view)
2873 do_prelight (tree_view,
2875 -1000, -1000); /* coords not possibly over an arrow */
2877 g_assert (tree_view->priv->prelight_node < 0);
2881 update_prelight (PsppSheetView *tree_view,
2888 if (tree_view->priv->row_count == 0)
2893 ensure_unprelighted (tree_view);
2897 new_y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, y);
2901 pspp_sheet_view_find_offset (tree_view, new_y, &node);
2904 prelight_or_select (tree_view, node, x, y);
2910 /* Our motion arrow is either a box (in the case of the original spot)
2911 * or an arrow. It is expander_size wide.
2934 pspp_sheet_view_motion_draw_column_motion_arrow (PsppSheetView *tree_view)
2937 PsppSheetViewColumnReorder *reorder = tree_view->priv->cur_reorder;
2938 GtkWidget *widget = GTK_WIDGET (tree_view);
2939 GdkBitmap *mask = NULL;
2944 gint arrow_type = DRAG_COLUMN_WINDOW_STATE_UNSET;
2945 GdkWindowAttr attributes;
2946 guint attributes_mask;
2949 reorder->left_column == tree_view->priv->drag_column ||
2950 reorder->right_column == tree_view->priv->drag_column)
2951 arrow_type = DRAG_COLUMN_WINDOW_STATE_ORIGINAL;
2952 else if (reorder->left_column || reorder->right_column)
2954 GdkRectangle visible_rect;
2955 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
2956 if (reorder->left_column)
2957 x = reorder->left_column->allocation.x + reorder->left_column->allocation.width;
2959 x = reorder->right_column->allocation.x;
2961 if (x < visible_rect.x)
2962 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT;
2963 else if (x > visible_rect.x + visible_rect.width)
2964 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT;
2966 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW;
2969 /* We want to draw the rectangle over the initial location. */
2970 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ORIGINAL)
2975 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ORIGINAL)
2977 if (tree_view->priv->drag_highlight_window)
2979 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
2981 gdk_window_destroy (tree_view->priv->drag_highlight_window);
2984 attributes.window_type = GDK_WINDOW_CHILD;
2985 attributes.wclass = GDK_INPUT_OUTPUT;
2986 attributes.x = tree_view->priv->drag_column_x;
2988 width = attributes.width = tree_view->priv->drag_column->allocation.width;
2989 height = attributes.height = tree_view->priv->drag_column->allocation.height;
2990 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
2991 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
2992 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
2993 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2994 tree_view->priv->drag_highlight_window = gdk_window_new (tree_view->priv->header_window, &attributes, attributes_mask);
2995 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
2997 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
2998 gc = gdk_gc_new (mask);
3000 gdk_gc_set_foreground (gc, &col);
3001 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
3003 gdk_gc_set_foreground(gc, &col);
3004 gdk_draw_rectangle (mask, gc, TRUE, 2, 2, width - 4, height - 4);
3005 g_object_unref (gc);
3007 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
3009 if (mask) g_object_unref (mask);
3010 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_ORIGINAL;
3013 else if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW)
3019 width = tree_view->priv->expander_size;
3021 /* Get x, y, width, height of arrow */
3022 gdk_window_get_origin (tree_view->priv->header_window, &x, &y);
3023 if (reorder->left_column)
3025 x += reorder->left_column->allocation.x + reorder->left_column->allocation.width - width/2;
3026 height = reorder->left_column->allocation.height;
3030 x += reorder->right_column->allocation.x - width/2;
3031 height = reorder->right_column->allocation.height;
3033 y -= tree_view->priv->expander_size/2; /* The arrow takes up only half the space */
3034 height += tree_view->priv->expander_size;
3036 /* Create the new window */
3037 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW)
3039 if (tree_view->priv->drag_highlight_window)
3041 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
3043 gdk_window_destroy (tree_view->priv->drag_highlight_window);
3046 attributes.window_type = GDK_WINDOW_TEMP;
3047 attributes.wclass = GDK_INPUT_OUTPUT;
3048 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
3049 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
3050 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
3051 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
3054 attributes.width = width;
3055 attributes.height = height;
3056 tree_view->priv->drag_highlight_window = gdk_window_new (gtk_widget_get_root_window (widget),
3057 &attributes, attributes_mask);
3058 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
3060 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
3061 gc = gdk_gc_new (mask);
3063 gdk_gc_set_foreground (gc, &col);
3064 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
3066 /* Draw the 2 arrows as per above */
3068 gdk_gc_set_foreground (gc, &col);
3069 for (i = 0; i < width; i ++)
3071 if (i == (width/2 - 1))
3073 gdk_draw_line (mask, gc, i, j, i, height - j);
3074 if (i < (width/2 - 1))
3079 g_object_unref (gc);
3080 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
3082 if (mask) g_object_unref (mask);
3085 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_ARROW;
3086 gdk_window_move (tree_view->priv->drag_highlight_window, x, y);
3088 else if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT ||
3089 arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3095 width = tree_view->priv->expander_size;
3097 /* Get x, y, width, height of arrow */
3098 width = width/2; /* remember, the arrow only takes half the available width */
3099 gdk_window_get_origin (gtk_widget_get_window (widget), &x, &y);
3100 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3101 x += widget->allocation.width - width;
3103 if (reorder->left_column)
3104 height = reorder->left_column->allocation.height;
3106 height = reorder->right_column->allocation.height;
3108 y -= tree_view->priv->expander_size;
3109 height += 2*tree_view->priv->expander_size;
3111 /* Create the new window */
3112 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT &&
3113 tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3115 if (tree_view->priv->drag_highlight_window)
3117 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
3119 gdk_window_destroy (tree_view->priv->drag_highlight_window);
3122 attributes.window_type = GDK_WINDOW_TEMP;
3123 attributes.wclass = GDK_INPUT_OUTPUT;
3124 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
3125 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
3126 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
3127 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
3130 attributes.width = width;
3131 attributes.height = height;
3132 tree_view->priv->drag_highlight_window = gdk_window_new (NULL, &attributes, attributes_mask);
3133 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
3135 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
3136 gc = gdk_gc_new (mask);
3138 gdk_gc_set_foreground (gc, &col);
3139 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
3141 /* Draw the 2 arrows as per above */
3143 gdk_gc_set_foreground (gc, &col);
3144 j = tree_view->priv->expander_size;
3145 for (i = 0; i < width; i ++)
3148 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT)
3152 gdk_draw_line (mask, gc, k, j, k, height - j);
3153 gdk_draw_line (mask, gc, k, 0, k, tree_view->priv->expander_size - j);
3154 gdk_draw_line (mask, gc, k, height, k, height - tree_view->priv->expander_size + j);
3157 g_object_unref (gc);
3158 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
3160 if (mask) g_object_unref (mask);
3163 tree_view->priv->drag_column_window_state = arrow_type;
3164 gdk_window_move (tree_view->priv->drag_highlight_window, x, y);
3168 g_warning (G_STRLOC"Invalid PsppSheetViewColumnReorder struct");
3169 gdk_window_hide (tree_view->priv->drag_highlight_window);
3173 gdk_window_show (tree_view->priv->drag_highlight_window);
3174 gdk_window_raise (tree_view->priv->drag_highlight_window);
3179 pspp_sheet_view_motion_resize_column (GtkWidget *widget,
3180 GdkEventMotion *event)
3184 PsppSheetViewColumn *column;
3185 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
3187 column = pspp_sheet_view_get_column (tree_view, tree_view->priv->drag_pos);
3189 if (event->is_hint || event->window != gtk_widget_get_window (widget))
3190 gtk_widget_get_pointer (widget, &x, NULL);
3194 if (tree_view->priv->hadjustment)
3195 x += gtk_adjustment_get_value (tree_view->priv->hadjustment);
3197 new_width = pspp_sheet_view_new_column_width (tree_view,
3198 tree_view->priv->drag_pos, &x);
3199 if (x != tree_view->priv->x_drag &&
3200 (new_width != column->fixed_width))
3202 column->use_resized_width = TRUE;
3203 column->resized_width = new_width;
3206 column->resized_width -= tree_view->priv->last_extra_space_per_column;
3208 gtk_widget_queue_resize (widget);
3216 pspp_sheet_view_update_current_reorder (PsppSheetView *tree_view)
3218 PsppSheetViewColumnReorder *reorder = NULL;
3222 gdk_window_get_pointer (tree_view->priv->header_window, &mouse_x, NULL, NULL);
3223 for (list = tree_view->priv->column_drag_info; list; list = list->next)
3225 reorder = (PsppSheetViewColumnReorder *) list->data;
3226 if (mouse_x >= reorder->left_align && mouse_x < reorder->right_align)
3231 /* if (reorder && reorder == tree_view->priv->cur_reorder)
3234 tree_view->priv->cur_reorder = reorder;
3235 pspp_sheet_view_motion_draw_column_motion_arrow (tree_view);
3239 pspp_sheet_view_vertical_autoscroll (PsppSheetView *tree_view)
3241 GdkRectangle visible_rect;
3246 gdk_window_get_pointer (tree_view->priv->bin_window, NULL, &y, NULL);
3247 y += tree_view->priv->dy;
3249 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
3251 /* see if we are near the edge. */
3252 offset = y - (visible_rect.y + 2 * SCROLL_EDGE_SIZE);
3255 offset = y - (visible_rect.y + visible_rect.height - 2 * SCROLL_EDGE_SIZE);
3260 value = CLAMP (gtk_adjustment_get_value (tree_view->priv->vadjustment) + offset, 0.0,
3261 gtk_adjustment_get_upper (tree_view->priv->vadjustment) - gtk_adjustment_get_page_size (tree_view->priv->vadjustment));
3262 gtk_adjustment_set_value (tree_view->priv->vadjustment, value);
3266 pspp_sheet_view_horizontal_autoscroll (PsppSheetView *tree_view)
3268 GdkRectangle visible_rect;
3273 gdk_window_get_pointer (tree_view->priv->bin_window, &x, NULL, NULL);
3275 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
3277 /* See if we are near the edge. */
3278 offset = x - (visible_rect.x + SCROLL_EDGE_SIZE);
3281 offset = x - (visible_rect.x + visible_rect.width - SCROLL_EDGE_SIZE);
3287 value = CLAMP (gtk_adjustment_get_value (tree_view->priv->hadjustment) + offset,
3288 0.0, gtk_adjustment_get_upper (tree_view->priv->hadjustment) - gtk_adjustment_get_page_size (tree_view->priv->hadjustment));
3289 gtk_adjustment_set_value (tree_view->priv->hadjustment, value);
3296 pspp_sheet_view_motion_drag_column (GtkWidget *widget,
3297 GdkEventMotion *event)
3299 PsppSheetView *tree_view = (PsppSheetView *) widget;
3300 PsppSheetViewColumn *column = tree_view->priv->drag_column;
3302 GtkAllocation allocation;
3305 if ((column == NULL) ||
3306 (event->window != tree_view->priv->drag_window))
3309 /* Handle moving the header */
3310 gdk_window_get_position (tree_view->priv->drag_window, &x, &y);
3311 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
3312 x = CLAMP (x + (gint)event->x - column->drag_x, 0,
3313 MAX (tree_view->priv->width, allocation.width) - column->allocation.width);
3314 gdk_window_move (tree_view->priv->drag_window, x, y);
3316 /* autoscroll, if needed */
3317 pspp_sheet_view_horizontal_autoscroll (tree_view);
3318 /* Update the current reorder position and arrow; */
3319 pspp_sheet_view_update_current_reorder (tree_view);
3325 pspp_sheet_view_stop_rubber_band (PsppSheetView *tree_view)
3327 remove_scroll_timeout (tree_view);
3328 gtk_grab_remove (GTK_WIDGET (tree_view));
3330 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
3332 GtkTreePath *tmp_path;
3334 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
3336 /* The anchor path should be set to the start path */
3337 tmp_path = _pspp_sheet_view_find_path (tree_view,
3338 tree_view->priv->rubber_band_start_node);
3340 if (tree_view->priv->anchor)
3341 gtk_tree_row_reference_free (tree_view->priv->anchor);
3343 tree_view->priv->anchor =
3344 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
3345 tree_view->priv->model,
3348 gtk_tree_path_free (tmp_path);
3350 /* ... and the cursor to the end path */
3351 tmp_path = _pspp_sheet_view_find_path (tree_view,
3352 tree_view->priv->rubber_band_end_node);
3353 pspp_sheet_view_real_set_cursor (PSPP_SHEET_VIEW (tree_view), tmp_path, FALSE, FALSE, 0); /* XXX mode? */
3354 gtk_tree_path_free (tmp_path);
3356 _pspp_sheet_selection_emit_changed (tree_view->priv->selection);
3359 /* Clear status variables */
3360 tree_view->priv->rubber_band_status = RUBBER_BAND_OFF;
3361 tree_view->priv->rubber_band_shift = 0;
3362 tree_view->priv->rubber_band_ctrl = 0;
3364 tree_view->priv->rubber_band_start_node = -1;
3365 tree_view->priv->rubber_band_end_node = -1;
3369 pspp_sheet_view_update_rubber_band_selection_range (PsppSheetView *tree_view,
3373 gboolean skip_start,
3376 if (start_node == end_node)
3379 /* We skip the first node and jump inside the loop */
3385 /* Small optimization by assuming insensitive nodes are never
3390 if (tree_view->priv->rubber_band_shift)
3391 pspp_sheet_view_node_select (tree_view, start_node);
3392 else if (tree_view->priv->rubber_band_ctrl)
3394 /* Toggle the selection state */
3395 if (pspp_sheet_view_node_is_selected (tree_view, start_node))
3396 pspp_sheet_view_node_unselect (tree_view, start_node);
3398 pspp_sheet_view_node_select (tree_view, start_node);
3401 pspp_sheet_view_node_select (tree_view, start_node);
3405 /* Mirror the above */
3406 if (tree_view->priv->rubber_band_shift)
3407 pspp_sheet_view_node_unselect (tree_view, start_node);
3408 else if (tree_view->priv->rubber_band_ctrl)
3410 /* Toggle the selection state */
3411 if (pspp_sheet_view_node_is_selected (tree_view, start_node))
3412 pspp_sheet_view_node_unselect (tree_view, start_node);
3414 pspp_sheet_view_node_select (tree_view, start_node);
3417 pspp_sheet_view_node_unselect (tree_view, start_node);
3420 _pspp_sheet_view_queue_draw_node (tree_view, start_node, NULL);
3422 if (start_node == end_node)
3427 start_node = pspp_sheet_view_node_next (tree_view, start_node);
3430 /* Ran out of tree */
3433 if (skip_end && start_node == end_node)
3440 pspp_sheet_view_node_find_offset (PsppSheetView *tree_view,
3443 return node * tree_view->priv->fixed_height;
3447 pspp_sheet_view_find_offset (PsppSheetView *tree_view,
3451 int fixed_height = tree_view->priv->fixed_height;
3452 if (fixed_height <= 0
3454 || height >= tree_view->priv->row_count * fixed_height)
3461 *new_node = height / fixed_height;
3462 return height % fixed_height;
3467 pspp_sheet_view_update_rubber_band_selection (PsppSheetView *tree_view)
3472 pspp_sheet_view_find_offset (tree_view, MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y), &start_node);
3473 pspp_sheet_view_find_offset (tree_view, MAX (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y), &end_node);
3475 /* Handle the start area first */
3476 if (tree_view->priv->rubber_band_start_node < 0)
3478 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3485 else if (start_node < tree_view->priv->rubber_band_start_node)
3487 /* New node is above the old one; selection became bigger */
3488 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3490 tree_view->priv->rubber_band_start_node,
3495 else if (start_node > tree_view->priv->rubber_band_start_node)
3497 /* New node is below the old one; selection became smaller */
3498 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3499 tree_view->priv->rubber_band_start_node,
3506 tree_view->priv->rubber_band_start_node = start_node;
3508 /* Next, handle the end area */
3509 if (tree_view->priv->rubber_band_end_node < 0)
3511 /* In the event this happens, start_node was also -1; this case is
3515 else if (end_node < 0)
3517 /* Find the last node in the tree */
3518 pspp_sheet_view_find_offset (tree_view, tree_view->priv->height - 1,
3521 /* Selection reached end of the tree */
3522 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3523 tree_view->priv->rubber_band_end_node,
3529 else if (end_node > tree_view->priv->rubber_band_end_node)
3531 /* New node is below the old one; selection became bigger */
3532 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3533 tree_view->priv->rubber_band_end_node,
3539 else if (end_node < tree_view->priv->rubber_band_end_node)
3541 /* New node is above the old one; selection became smaller */
3542 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3544 tree_view->priv->rubber_band_end_node,
3550 tree_view->priv->rubber_band_end_node = end_node;
3553 #define GDK_RECTANGLE_PTR(X) ((GdkRectangle *)(X))
3556 pspp_sheet_view_update_rubber_band (PsppSheetView *tree_view)
3559 cairo_rectangle_int_t old_area;
3560 cairo_rectangle_int_t new_area;
3561 cairo_rectangle_int_t common;
3562 cairo_region_t *invalid_region;
3563 PsppSheetViewColumn *column;
3565 old_area.x = MIN (tree_view->priv->press_start_x, tree_view->priv->rubber_band_x);
3566 old_area.y = MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y) - tree_view->priv->dy;
3567 old_area.width = ABS (tree_view->priv->rubber_band_x - tree_view->priv->press_start_x) + 1;
3568 old_area.height = ABS (tree_view->priv->rubber_band_y - tree_view->priv->press_start_y) + 1;
3570 gdk_window_get_pointer (tree_view->priv->bin_window, &x, &y, NULL);
3573 y = MAX (y, 0) + tree_view->priv->dy;
3575 new_area.x = MIN (tree_view->priv->press_start_x, x);
3576 new_area.y = MIN (tree_view->priv->press_start_y, y) - tree_view->priv->dy;
3577 new_area.width = ABS (x - tree_view->priv->press_start_x) + 1;
3578 new_area.height = ABS (y - tree_view->priv->press_start_y) + 1;
3580 invalid_region = cairo_region_create_rectangle (&old_area);
3581 cairo_region_union_rectangle (invalid_region, &new_area);
3583 gdk_rectangle_intersect (GDK_RECTANGLE_PTR (&old_area),
3584 GDK_RECTANGLE_PTR (&new_area), GDK_RECTANGLE_PTR (&common));
3585 if (common.width > 2 && common.height > 2)
3587 cairo_region_t *common_region;
3589 /* make sure the border is invalidated */
3595 common_region = cairo_region_create_rectangle (&common);
3597 cairo_region_subtract (invalid_region, common_region);
3598 cairo_region_destroy (common_region);
3601 #if GTK_MAJOR_VERSION == 3
3602 gdk_window_invalidate_region (tree_view->priv->bin_window, invalid_region, TRUE);
3605 cairo_rectangle_int_t extents;
3607 cairo_region_get_extents (invalid_region, &extents);
3608 ereg = gdk_region_rectangle (GDK_RECTANGLE_PTR (&extents));
3609 gdk_window_invalidate_region (tree_view->priv->bin_window, ereg, TRUE);
3610 gdk_region_destroy (ereg);
3614 cairo_region_destroy (invalid_region);
3616 tree_view->priv->rubber_band_x = x;
3617 tree_view->priv->rubber_band_y = y;
3618 pspp_sheet_view_get_path_at_pos (tree_view, x, y, NULL, &column, NULL, NULL);
3620 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
3621 pspp_sheet_selection_select_column_range (tree_view->priv->selection,
3622 tree_view->priv->anchor_column,
3625 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
3627 pspp_sheet_view_update_rubber_band_selection (tree_view);
3632 pspp_sheet_view_paint_rubber_band (PsppSheetView *tree_view,
3637 GdkRectangle rubber_rect;
3641 rubber_rect.x = MIN (tree_view->priv->press_start_x, tree_view->priv->rubber_band_x);
3642 rubber_rect.y = MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y) - tree_view->priv->dy;
3643 rubber_rect.width = ABS (tree_view->priv->press_start_x - tree_view->priv->rubber_band_x) + 1;
3644 rubber_rect.height = ABS (tree_view->priv->press_start_y - tree_view->priv->rubber_band_y) + 1;
3646 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
3649 cr = gdk_cairo_create (tree_view->priv->bin_window);
3650 cairo_set_line_width (cr, 1.0);
3652 style = gtk_widget_get_style (GTK_WIDGET (tree_view));
3653 cairo_set_source_rgba (cr,
3654 style->fg[GTK_STATE_NORMAL].red / 65535.,
3655 style->fg[GTK_STATE_NORMAL].green / 65535.,
3656 style->fg[GTK_STATE_NORMAL].blue / 65535.,
3659 gdk_cairo_rectangle (cr, &rect);
3663 cairo_set_source_rgb (cr,
3664 style->fg[GTK_STATE_NORMAL].red / 65535.,
3665 style->fg[GTK_STATE_NORMAL].green / 65535.,
3666 style->fg[GTK_STATE_NORMAL].blue / 65535.);
3668 cairo_rectangle (cr,
3669 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
3670 rubber_rect.width - 1, rubber_rect.height - 1);
3679 pspp_sheet_view_motion_bin_window (GtkWidget *widget,
3680 GdkEventMotion *event)
3682 PsppSheetView *tree_view;
3686 tree_view = (PsppSheetView *) widget;
3688 if (tree_view->priv->row_count == 0)
3691 if (tree_view->priv->rubber_band_status == RUBBER_BAND_MAYBE_START)
3693 GdkRectangle background_area, cell_area;
3694 PsppSheetViewColumn *column;
3696 if (find_click (tree_view, event->x, event->y, &node, &column,
3697 &background_area, &cell_area)
3698 && tree_view->priv->focus_column == column
3699 && tree_view->priv->press_start_node == node)
3702 gtk_grab_add (GTK_WIDGET (tree_view));
3703 pspp_sheet_view_update_rubber_band (tree_view);
3705 tree_view->priv->rubber_band_status = RUBBER_BAND_ACTIVE;
3707 else if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
3709 pspp_sheet_view_update_rubber_band (tree_view);
3711 add_scroll_timeout (tree_view);
3714 /* only check for an initiated drag when a button is pressed */
3715 if (tree_view->priv->pressed_button >= 0
3716 && !tree_view->priv->rubber_band_status)
3717 pspp_sheet_view_maybe_begin_dragging_row (tree_view, event);
3719 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, event->y);
3723 pspp_sheet_view_find_offset (tree_view, new_y, &node);
3725 tree_view->priv->event_last_x = event->x;
3726 tree_view->priv->event_last_y = event->y;
3728 prelight_or_select (tree_view, node, event->x, event->y);
3734 pspp_sheet_view_motion (GtkWidget *widget,
3735 GdkEventMotion *event)
3737 PsppSheetView *tree_view;
3739 tree_view = (PsppSheetView *) widget;
3741 /* Resizing a column */
3742 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
3743 return pspp_sheet_view_motion_resize_column (widget, event);
3746 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
3747 return pspp_sheet_view_motion_drag_column (widget, event);
3749 /* Sanity check it */
3750 if (event->window == tree_view->priv->bin_window)
3751 return pspp_sheet_view_motion_bin_window (widget, event);
3756 /* Invalidate the focus rectangle near the edge of the bin_window; used when
3757 * the tree is empty.
3760 invalidate_empty_focus (PsppSheetView *tree_view)
3764 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
3769 area.width = gdk_window_get_width (tree_view->priv->bin_window);
3770 area.height = gdk_window_get_height (tree_view->priv->bin_window);
3771 gdk_window_invalidate_rect (tree_view->priv->bin_window, &area, FALSE);
3774 /* Draws a focus rectangle near the edge of the bin_window; used when the tree
3778 draw_empty_focus (PsppSheetView *tree_view)
3780 GtkWidget *widget = GTK_WIDGET (tree_view);
3782 cairo_t *cr = gdk_cairo_create (tree_view->priv->bin_window);
3784 if (!gtk_widget_has_focus (widget))
3787 w = gdk_window_get_width (tree_view->priv->bin_window);
3788 h = gdk_window_get_height (tree_view->priv->bin_window);
3794 gtk_paint_focus (gtk_widget_get_style (widget),
3796 gtk_widget_get_state (widget),
3804 pspp_sheet_view_draw_vertical_grid_lines (PsppSheetView *tree_view,
3806 gint n_visible_columns,
3810 GList *list = tree_view->priv->columns;
3814 if (tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
3815 && tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_BOTH)
3818 /* Only draw the lines for visible rows and columns */
3819 for (list = tree_view->priv->columns; list; list = list->next, i++)
3821 PsppSheetViewColumn *column = list->data;
3823 /* We don't want a line for the last column */
3824 if (i == n_visible_columns - 1)
3827 if (! column->visible)
3830 current_x += column->width;
3832 cairo_set_line_width (cr, 1.0);
3833 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
3834 cairo_move_to (cr, current_x - 0.5, min_y);
3835 cairo_line_to (cr, current_x - 0.5 , max_y - min_y);
3841 /* Warning: Very scary function.
3842 * Modify at your own risk
3844 * KEEP IN SYNC WITH pspp_sheet_view_create_row_drag_icon()!
3845 * FIXME: It's not...
3848 pspp_sheet_view_bin_expose (GtkWidget *widget,
3851 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
3856 int drag_highlight = -1;
3859 gint y_offset, cell_offset;
3861 GdkRectangle background_area;
3862 GdkRectangle cell_area;
3864 gint bin_window_width;
3865 gint bin_window_height;
3866 GtkTreePath *cursor_path;
3867 GtkTreePath *drag_dest_path;
3868 GList *first_column, *last_column;
3869 gint vertical_separator;
3870 gint horizontal_separator;
3871 gint focus_line_width;
3872 gboolean allow_rules;
3873 gboolean has_special_cell;
3875 gint n_visible_columns;
3876 gint grid_line_width;
3877 gboolean row_ending_details;
3878 gboolean draw_vgrid_lines, draw_hgrid_lines;
3881 cairo_t *bwcr = gdk_cairo_create (tree_view->priv->bin_window);
3883 GtkAllocation allocation;
3884 gtk_widget_get_allocation (widget, &allocation);
3888 Zarea.height = allocation.height;
3890 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
3892 gtk_widget_style_get (widget,
3893 "horizontal-separator", &horizontal_separator,
3894 "vertical-separator", &vertical_separator,
3895 "allow-rules", &allow_rules,
3896 "focus-line-width", &focus_line_width,
3897 "row-ending-details", &row_ending_details,
3900 if (tree_view->priv->row_count == 0)
3902 draw_empty_focus (tree_view);
3907 /* clip event->area to the visible area */
3908 if (Zarea.height < 0.5)
3912 validate_visible_area (tree_view);
3914 new_y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, Zarea.y);
3918 y_offset = -pspp_sheet_view_find_offset (tree_view, new_y, &node);
3920 gdk_window_get_width (tree_view->priv->bin_window);
3923 gdk_window_get_height (tree_view->priv->bin_window);
3926 if (tree_view->priv->height < bin_window_height)
3928 gtk_paint_flat_box (gtk_widget_get_style (widget),
3930 gtk_widget_get_state (widget),
3934 0, tree_view->priv->height,
3936 bin_window_height - tree_view->priv->height);
3942 /* find the path for the node */
3943 path = _pspp_sheet_view_find_path ((PsppSheetView *)widget, node);
3944 gtk_tree_model_get_iter (tree_view->priv->model,
3947 gtk_tree_path_free (path);
3950 drag_dest_path = NULL;
3952 if (tree_view->priv->cursor)
3953 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
3956 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor);
3958 if (tree_view->priv->drag_dest_row)
3959 drag_dest_path = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
3962 _pspp_sheet_view_find_node (tree_view, drag_dest_path,
3966 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
3967 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
3969 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
3970 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
3972 if (draw_vgrid_lines || draw_hgrid_lines)
3973 gtk_widget_style_get (widget, "grid-line-width", &grid_line_width, NULL);
3975 n_visible_columns = 0;
3976 for (list = tree_view->priv->columns; list; list = list->next)
3978 if (! PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
3980 n_visible_columns ++;
3983 /* Find the last column */
3984 for (last_column = g_list_last (tree_view->priv->columns);
3985 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
3986 last_column = last_column->prev)
3990 for (first_column = g_list_first (tree_view->priv->columns);
3991 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
3992 first_column = first_column->next)
3995 /* Actually process the expose event. To do this, we want to
3996 * start at the first node of the event, and walk the tree in
3997 * order, drawing each successive node.
4004 gboolean is_first = FALSE;
4005 gboolean is_last = FALSE;
4006 gboolean done = FALSE;
4009 max_height = ROW_HEIGHT (tree_view);
4013 background_area.y = y_offset + Zarea.y;
4014 background_area.height = max_height;
4015 max_y = background_area.y + max_height;
4019 if (node == tree_view->priv->prelight_node)
4020 flags |= GTK_CELL_RENDERER_PRELIT;
4022 selected = pspp_sheet_view_node_is_selected (tree_view, node);
4026 if (tree_view->priv->special_cells == PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT)
4028 /* we *need* to set cell data on all cells before the call
4029 * to _has_special_cell, else _has_special_cell() does not
4030 * return a correct value.
4032 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
4034 list = (rtl ? list->prev : list->next))
4036 PsppSheetViewColumn *column = list->data;
4037 pspp_sheet_view_column_cell_set_cell_data (column,
4038 tree_view->priv->model,
4042 has_special_cell = pspp_sheet_view_has_special_cell (tree_view);
4045 has_special_cell = tree_view->priv->special_cells == PSPP_SHEET_VIEW_SPECIAL_CELLS_YES;
4047 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
4049 list = (rtl ? list->prev : list->next))
4051 PsppSheetViewColumn *column = list->data;
4052 const gchar *detail = NULL;
4053 gboolean selected_column;
4056 if (!column->visible)
4059 if (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE)
4060 selected_column = column->selected && column->selectable;
4062 selected_column = TRUE;
4065 if (cell_offset > Zarea.x + Zarea.width ||
4066 cell_offset + column->width < Zarea.x)
4068 cell_offset += column->width;
4073 if (selected && selected_column)
4074 flags |= GTK_CELL_RENDERER_SELECTED;
4076 flags &= ~GTK_CELL_RENDERER_SELECTED;
4078 if (column->show_sort_indicator)
4079 flags |= GTK_CELL_RENDERER_SORTED;
4081 flags &= ~GTK_CELL_RENDERER_SORTED;
4084 flags |= GTK_CELL_RENDERER_FOCUSED;
4086 flags &= ~GTK_CELL_RENDERER_FOCUSED;
4088 background_area.x = cell_offset;
4089 background_area.width = column->width;
4091 cell_area = background_area;
4092 cell_area.y += vertical_separator / 2;
4093 cell_area.x += horizontal_separator / 2;
4094 cell_area.height -= vertical_separator;
4095 cell_area.width -= horizontal_separator;
4097 if (draw_vgrid_lines)
4099 if (list == first_column)
4101 cell_area.width -= grid_line_width / 2;
4103 else if (list == last_column)
4105 cell_area.x += grid_line_width / 2;
4106 cell_area.width -= grid_line_width / 2;
4110 cell_area.x += grid_line_width / 2;
4111 cell_area.width -= grid_line_width;
4115 if (draw_hgrid_lines)
4117 cell_area.y += grid_line_width / 2;
4118 cell_area.height -= grid_line_width;
4122 if (gdk_region_rect_in (event->region, &background_area) == GDK_OVERLAP_RECTANGLE_OUT)
4124 cell_offset += column->width;
4129 pspp_sheet_view_column_cell_set_cell_data (column,
4130 tree_view->priv->model,
4133 /* Select the detail for drawing the cell. relevant
4134 * factors are parity, sortedness, and whether to
4137 if (allow_rules && tree_view->priv->has_rules)
4139 if ((flags & GTK_CELL_RENDERER_SORTED) &&
4140 n_visible_columns >= 3)
4143 detail = "cell_odd_ruled_sorted";
4145 detail = "cell_even_ruled_sorted";
4150 detail = "cell_odd_ruled";
4152 detail = "cell_even_ruled";
4157 if ((flags & GTK_CELL_RENDERER_SORTED) &&
4158 n_visible_columns >= 3)
4161 detail = "cell_odd_sorted";
4163 detail = "cell_even_sorted";
4168 detail = "cell_odd";
4170 detail = "cell_even";
4176 if (gtk_widget_get_state (widget) == GTK_STATE_INSENSITIVE)
4177 state = GTK_STATE_INSENSITIVE;
4178 else if (flags & GTK_CELL_RENDERER_SELECTED)
4179 state = GTK_STATE_SELECTED;
4181 state = GTK_STATE_NORMAL;
4183 /* Draw background */
4184 if (row_ending_details)
4186 char new_detail[128];
4188 is_first = (rtl ? !list->next : !list->prev);
4189 is_last = (rtl ? !list->prev : !list->next);
4191 /* (I don't like the snprintfs either, but couldn't find a
4194 if (is_first && is_last)
4195 g_snprintf (new_detail, 127, "%s", detail);
4197 g_snprintf (new_detail, 127, "%s_start", detail);
4199 g_snprintf (new_detail, 127, "%s_end", detail);
4201 g_snprintf (new_detail, 128, "%s_middle", detail);
4203 gtk_paint_flat_box (gtk_widget_get_style (widget),
4211 background_area.width,
4212 background_area.height);
4216 gtk_paint_flat_box (gtk_widget_get_style (widget),
4224 background_area.width,
4225 background_area.height);
4228 if (draw_hgrid_lines)
4230 cairo_set_line_width (cr, 1.0);
4231 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
4233 if (background_area.y >= 0)
4236 gdk_draw_line (event->window,
4237 tree_view->priv->grid_line_gc[widget->state],
4238 background_area.x, background_area.y,
4239 background_area.x + background_area.width,
4242 cairo_move_to (cr, background_area.x, background_area.y - 0.5);
4243 cairo_line_to (cr, background_area.x + background_area.width,
4244 background_area.y - 0.5);
4248 if (y_offset + max_height >= Zarea.height - 0.5)
4251 gdk_draw_line (event->window,
4252 tree_view->priv->grid_line_gc[widget->state],
4253 background_area.x, background_area.y + max_height,
4254 background_area.x + background_area.width,
4255 background_area.y + max_height);
4258 cairo_move_to (cr, background_area.x, background_area.y + max_height - 0.5);
4259 cairo_line_to (cr, background_area.x + background_area.width,
4260 background_area.y + max_height - 0.5);
4266 _pspp_sheet_view_column_cell_render (column,
4272 if (node == cursor && has_special_cell &&
4273 ((column == tree_view->priv->focus_column &&
4274 PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS) &&
4275 gtk_widget_has_focus (widget)) ||
4276 (column == tree_view->priv->edited_column)))
4278 _pspp_sheet_view_column_cell_draw_focus (column,
4285 cell_offset += column->width;
4288 if (cell_offset < Zarea.x)
4290 gtk_paint_flat_box (gtk_widget_get_style (widget),
4298 Zarea.x - cell_offset,
4299 background_area.height);
4302 if (node == drag_highlight)
4304 /* Draw indicator for the drop
4306 gint highlight_y = -1;
4310 switch (tree_view->priv->drag_dest_pos)
4312 case PSPP_SHEET_VIEW_DROP_BEFORE:
4313 highlight_y = background_area.y - 1;
4314 if (highlight_y < 0)
4318 case PSPP_SHEET_VIEW_DROP_AFTER:
4319 highlight_y = background_area.y + background_area.height - 1;
4322 case PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE:
4323 case PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER:
4324 _pspp_sheet_view_find_node (tree_view, drag_dest_path, &node);
4328 width = gdk_window_get_width (tree_view->priv->bin_window);
4330 if (row_ending_details)
4331 gtk_paint_focus (gtk_widget_get_style (widget),
4333 gtk_widget_get_state (widget),
4336 ? (is_last ? "treeview-drop-indicator" : "treeview-drop-indicator-left" )
4337 : (is_last ? "treeview-drop-indicator-right" : "tree-view-drop-indicator-middle" )),
4338 0, BACKGROUND_FIRST_PIXEL (tree_view, node)
4339 - focus_line_width / 2,
4340 width, ROW_HEIGHT (tree_view)
4341 - focus_line_width + 1);
4343 gtk_paint_focus (gtk_widget_get_style (widget),
4345 gtk_widget_get_state (widget),
4347 "treeview-drop-indicator",
4348 0, BACKGROUND_FIRST_PIXEL (tree_view, node)
4349 - focus_line_width / 2,
4350 width, ROW_HEIGHT (tree_view)
4351 - focus_line_width + 1);
4356 if (highlight_y >= 0)
4358 gdk_draw_line (event->window,
4359 widget->style->fg_gc[gtk_widget_get_state (widget)],
4362 rtl ? 0 : bin_window_width,
4368 /* draw the big row-spanning focus rectangle, if needed */
4369 if (!has_special_cell && node == cursor &&
4370 PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS) &&
4371 gtk_widget_has_focus (widget))
4373 gint tmp_y, tmp_height;
4375 GtkStateType focus_rect_state;
4378 flags & GTK_CELL_RENDERER_SELECTED ? GTK_STATE_SELECTED :
4379 (flags & GTK_CELL_RENDERER_PRELIT ? GTK_STATE_PRELIGHT :
4380 (flags & GTK_CELL_RENDERER_INSENSITIVE ? GTK_STATE_INSENSITIVE :
4383 width = gdk_window_get_width (tree_view->priv->bin_window);
4385 if (draw_hgrid_lines)
4387 tmp_y = BACKGROUND_FIRST_PIXEL (tree_view, node) + grid_line_width / 2;
4388 tmp_height = ROW_HEIGHT (tree_view) - grid_line_width;
4392 tmp_y = BACKGROUND_FIRST_PIXEL (tree_view, node);
4393 tmp_height = ROW_HEIGHT (tree_view);
4396 if (row_ending_details)
4397 gtk_paint_focus (gtk_widget_get_style (widget),
4402 ? (is_last ? "treeview" : "treeview-left" )
4403 : (is_last ? "treeview-right" : "treeview-middle" )),
4407 gtk_paint_focus (gtk_widget_get_style (widget),
4416 y_offset += max_height;
4420 node = pspp_sheet_view_node_next (tree_view, node);
4423 gboolean has_next = gtk_tree_model_iter_next (tree_view->priv->model, &iter);
4427 TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
4434 while (y_offset < Zarea.height);
4437 pspp_sheet_view_draw_vertical_grid_lines (tree_view, cr, n_visible_columns,
4441 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
4443 GdkRectangle *rectangles;
4446 gdk_region_get_rectangles (event->region,
4450 while (n_rectangles--)
4451 pspp_sheet_view_paint_rubber_band (tree_view, &rectangles[n_rectangles]);
4453 g_free (rectangles);
4458 gtk_tree_path_free (cursor_path);
4461 gtk_tree_path_free (drag_dest_path);
4468 window_intersects (GdkWindow *window, GdkRectangle *rect)
4470 GdkRectangle window_rect;
4471 gdk_window_get_position (window,
4472 &window_rect.x, &window_rect.y);
4474 window_rect.width = gdk_window_get_width (window);
4475 window_rect.height = gdk_window_get_height (window);
4477 return gdk_rectangle_intersect (&window_rect, rect, NULL);
4482 pspp_sheet_view_draw (GtkWidget *widget,
4485 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4486 GtkAllocation allocation;
4487 GdkRectangle clip_rect;
4488 gtk_widget_get_allocation (widget, &allocation);
4490 gdk_cairo_get_clip_rectangle (cr, &clip_rect);
4492 if (window_intersects (tree_view->priv->bin_window, &clip_rect))
4497 retval = pspp_sheet_view_bin_expose (widget, cr);
4499 /* We can't just chain up to Container::expose as it will try to send the
4500 * event to the headers, so we handle propagating it to our children
4501 * (eg. widgets being edited) ourselves.
4503 tmp_list = tree_view->priv->children;
4506 PsppSheetViewChild *child = tmp_list->data;
4507 tmp_list = tmp_list->next;
4509 gtk_container_propagate_draw (GTK_CONTAINER (tree_view), child->widget, cr);
4514 else if (window_intersects (tree_view->priv->header_window, &clip_rect))
4516 gint n_visible_columns;
4519 gtk_paint_flat_box (gtk_widget_get_style (widget),
4531 for (list = tree_view->priv->columns; list != NULL; list = list->next)
4533 PsppSheetViewColumn *column = list->data;
4535 if (column == tree_view->priv->drag_column || !column->visible)
4538 if (span_intersects (column->allocation.x, column->allocation.width,
4539 allocation.x, allocation.width)
4540 && column->button != NULL)
4541 gtk_container_propagate_draw (GTK_CONTAINER (tree_view),
4542 column->button, cr);
4545 n_visible_columns = 0;
4546 for (list = tree_view->priv->columns; list; list = list->next)
4548 if (! PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
4550 n_visible_columns ++;
4552 pspp_sheet_view_draw_vertical_grid_lines (tree_view,
4560 else if (window_intersects (tree_view->priv->drag_window, &clip_rect))
4562 gtk_container_propagate_draw (GTK_CONTAINER (tree_view),
4563 tree_view->priv->drag_column->button,
4580 /* returns 0x1 when no column has been found -- yes it's hackish */
4581 static PsppSheetViewColumn *
4582 pspp_sheet_view_get_drop_column (PsppSheetView *tree_view,
4583 PsppSheetViewColumn *column,
4586 PsppSheetViewColumn *left_column = NULL;
4587 PsppSheetViewColumn *cur_column = NULL;
4590 if (!column->reorderable)
4591 return (PsppSheetViewColumn *)0x1;
4593 switch (drop_position)
4596 /* find first column where we can drop */
4597 tmp_list = tree_view->priv->columns;
4598 if (column == PSPP_SHEET_VIEW_COLUMN (tmp_list->data))
4599 return (PsppSheetViewColumn *)0x1;
4603 g_assert (tmp_list);
4605 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4606 tmp_list = tmp_list->next;
4608 if (left_column && left_column->visible == FALSE)
4611 if (!tree_view->priv->column_drop_func)
4614 if (!tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4616 left_column = cur_column;
4623 if (!tree_view->priv->column_drop_func)
4626 if (tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data))
4629 return (PsppSheetViewColumn *)0x1;
4633 /* find first column after column where we can drop */
4634 tmp_list = tree_view->priv->columns;
4636 for (; tmp_list; tmp_list = tmp_list->next)
4637 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data) == column)
4640 if (!tmp_list || !tmp_list->next)
4641 return (PsppSheetViewColumn *)0x1;
4643 tmp_list = tmp_list->next;
4644 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4645 tmp_list = tmp_list->next;
4649 g_assert (tmp_list);
4651 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4652 tmp_list = tmp_list->next;
4654 if (left_column && left_column->visible == FALSE)
4656 left_column = cur_column;
4658 tmp_list = tmp_list->next;
4662 if (!tree_view->priv->column_drop_func)
4665 if (!tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4667 left_column = cur_column;
4674 if (!tree_view->priv->column_drop_func)
4677 if (tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data))
4680 return (PsppSheetViewColumn *)0x1;
4684 /* find first column before column where we can drop */
4685 tmp_list = tree_view->priv->columns;
4687 for (; tmp_list; tmp_list = tmp_list->next)
4688 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data) == column)
4691 if (!tmp_list || !tmp_list->prev)
4692 return (PsppSheetViewColumn *)0x1;
4694 tmp_list = tmp_list->prev;
4695 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4696 tmp_list = tmp_list->prev;
4700 g_assert (tmp_list);
4702 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4704 if (left_column && !left_column->visible)
4706 /*if (!tmp_list->prev)
4707 return (PsppSheetViewColumn *)0x1;
4710 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->prev->data);
4711 tmp_list = tmp_list->prev->prev;
4714 cur_column = left_column;
4716 tmp_list = tmp_list->prev;
4720 if (!tree_view->priv->column_drop_func)
4723 if (tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4726 cur_column = left_column;
4727 tmp_list = tmp_list->prev;
4730 if (!tree_view->priv->column_drop_func)
4733 if (tree_view->priv->column_drop_func (tree_view, column, NULL, cur_column, tree_view->priv->column_drop_func_data))
4736 return (PsppSheetViewColumn *)0x1;
4740 /* same as DROP_HOME case, but doing it backwards */
4741 tmp_list = g_list_last (tree_view->priv->columns);
4744 if (column == PSPP_SHEET_VIEW_COLUMN (tmp_list->data))
4745 return (PsppSheetViewColumn *)0x1;
4749 g_assert (tmp_list);
4751 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4753 if (left_column && !left_column->visible)
4755 cur_column = left_column;
4756 tmp_list = tmp_list->prev;
4759 if (!tree_view->priv->column_drop_func)
4762 if (tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4765 cur_column = left_column;
4766 tmp_list = tmp_list->prev;
4769 if (!tree_view->priv->column_drop_func)
4772 if (tree_view->priv->column_drop_func (tree_view, column, NULL, cur_column, tree_view->priv->column_drop_func_data))
4775 return (PsppSheetViewColumn *)0x1;
4779 return (PsppSheetViewColumn *)0x1;
4783 pspp_sheet_view_key_press (GtkWidget *widget,
4786 PsppSheetView *tree_view = (PsppSheetView *) widget;
4788 if (tree_view->priv->rubber_band_status)
4790 if (event->keyval == GDK_Escape)
4791 pspp_sheet_view_stop_rubber_band (tree_view);
4796 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
4798 if (event->keyval == GDK_Escape)
4800 tree_view->priv->cur_reorder = NULL;
4801 pspp_sheet_view_button_release_drag_column (widget, NULL);
4806 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
4808 GList *focus_column;
4811 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
4813 for (focus_column = tree_view->priv->columns;
4815 focus_column = focus_column->next)
4817 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4819 if (column->button && gtk_widget_has_focus (column->button))
4824 (event->state & GDK_SHIFT_MASK) && (event->state & GDK_MOD1_MASK) &&
4825 (event->keyval == GDK_Left || event->keyval == GDK_KP_Left
4826 || event->keyval == GDK_Right || event->keyval == GDK_KP_Right))
4828 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4830 if (!column->resizable)
4832 gtk_widget_error_bell (widget);
4836 if (event->keyval == (rtl ? GDK_Right : GDK_Left)
4837 || event->keyval == (rtl ? GDK_KP_Right : GDK_KP_Left))
4839 gint old_width = column->resized_width;
4841 column->resized_width = MAX (column->resized_width,
4843 column->resized_width -= 2;
4844 if (column->resized_width < 0)
4845 column->resized_width = 0;
4847 if (column->min_width == -1)
4848 column->resized_width = MAX (column->button_request,
4849 column->resized_width);
4851 column->resized_width = MAX (column->min_width,
4852 column->resized_width);
4854 if (column->max_width != -1)
4855 column->resized_width = MIN (column->resized_width,
4858 column->use_resized_width = TRUE;
4860 if (column->resized_width != old_width)
4861 gtk_widget_queue_resize (widget);
4863 gtk_widget_error_bell (widget);
4865 else if (event->keyval == (rtl ? GDK_Left : GDK_Right)
4866 || event->keyval == (rtl ? GDK_KP_Left : GDK_KP_Right))
4868 gint old_width = column->resized_width;
4870 column->resized_width = MAX (column->resized_width,
4872 column->resized_width += 2;
4874 if (column->max_width != -1)
4875 column->resized_width = MIN (column->resized_width,
4878 column->use_resized_width = TRUE;
4880 if (column->resized_width != old_width)
4881 gtk_widget_queue_resize (widget);
4883 gtk_widget_error_bell (widget);
4890 (event->state & GDK_MOD1_MASK) &&
4891 (event->keyval == GDK_Left || event->keyval == GDK_KP_Left
4892 || event->keyval == GDK_Right || event->keyval == GDK_KP_Right
4893 || event->keyval == GDK_Home || event->keyval == GDK_KP_Home
4894 || event->keyval == GDK_End || event->keyval == GDK_KP_End))
4896 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4898 if (event->keyval == (rtl ? GDK_Right : GDK_Left)
4899 || event->keyval == (rtl ? GDK_KP_Right : GDK_KP_Left))
4901 PsppSheetViewColumn *col;
4902 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_LEFT);
4903 if (col != (PsppSheetViewColumn *)0x1)
4904 pspp_sheet_view_move_column_after (tree_view, column, col);
4906 gtk_widget_error_bell (widget);
4908 else if (event->keyval == (rtl ? GDK_Left : GDK_Right)
4909 || event->keyval == (rtl ? GDK_KP_Left : GDK_KP_Right))
4911 PsppSheetViewColumn *col;
4912 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_RIGHT);
4913 if (col != (PsppSheetViewColumn *)0x1)
4914 pspp_sheet_view_move_column_after (tree_view, column, col);
4916 gtk_widget_error_bell (widget);
4918 else if (event->keyval == GDK_Home || event->keyval == GDK_KP_Home)
4920 PsppSheetViewColumn *col;
4921 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_HOME);
4922 if (col != (PsppSheetViewColumn *)0x1)
4923 pspp_sheet_view_move_column_after (tree_view, column, col);
4925 gtk_widget_error_bell (widget);
4927 else if (event->keyval == GDK_End || event->keyval == GDK_KP_End)
4929 PsppSheetViewColumn *col;
4930 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_END);
4931 if (col != (PsppSheetViewColumn *)0x1)
4932 pspp_sheet_view_move_column_after (tree_view, column, col);
4934 gtk_widget_error_bell (widget);
4941 /* Chain up to the parent class. It handles the keybindings. */
4942 if (GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->key_press_event (widget, event))
4945 if (tree_view->priv->search_entry_avoid_unhandled_binding)
4947 tree_view->priv->search_entry_avoid_unhandled_binding = FALSE;
4951 /* We pass the event to the search_entry. If its text changes, then we start
4952 * the typeahead find capabilities. */
4953 if (gtk_widget_has_focus (GTK_WIDGET (tree_view))
4954 && tree_view->priv->enable_search
4955 && !tree_view->priv->search_custom_entry_set)
4957 GdkEvent *new_event;
4959 const char *new_text;
4962 gboolean text_modified;
4963 gulong popup_menu_id;
4965 pspp_sheet_view_ensure_interactive_directory (tree_view);
4967 /* Make a copy of the current text */
4968 old_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry)));
4969 new_event = gdk_event_copy ((GdkEvent *) event);
4970 g_object_unref (((GdkEventKey *) new_event)->window);
4971 ((GdkEventKey *) new_event)->window = g_object_ref (gtk_widget_get_window (tree_view->priv->search_window));
4972 gtk_widget_realize (tree_view->priv->search_window);
4974 popup_menu_id = g_signal_connect (tree_view->priv->search_entry,
4975 "popup-menu", G_CALLBACK (gtk_true),
4978 /* Move the entry off screen */
4979 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
4980 gtk_window_move (GTK_WINDOW (tree_view->priv->search_window),
4981 gdk_screen_get_width (screen) + 1,
4982 gdk_screen_get_height (screen) + 1);
4983 gtk_widget_show (tree_view->priv->search_window);
4985 /* Send the event to the window. If the preedit_changed signal is emitted
4986 * during this event, we will set priv->imcontext_changed */
4987 tree_view->priv->imcontext_changed = FALSE;
4988 retval = gtk_widget_event (tree_view->priv->search_window, new_event);
4989 gdk_event_free (new_event);
4990 gtk_widget_hide (tree_view->priv->search_window);
4992 g_signal_handler_disconnect (tree_view->priv->search_entry,
4995 /* We check to make sure that the entry tried to handle the text, and that
4996 * the text has changed.
4998 new_text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
4999 text_modified = strcmp (old_text, new_text) != 0;
5001 if (tree_view->priv->imcontext_changed || /* we're in a preedit */
5002 (retval && text_modified)) /* ...or the text was modified */
5004 if (pspp_sheet_view_real_start_interactive_search (tree_view, FALSE))
5006 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
5011 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
5021 pspp_sheet_view_key_release (GtkWidget *widget,
5024 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
5026 if (tree_view->priv->rubber_band_status)
5029 return GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->key_release_event (widget, event);
5032 /* FIXME Is this function necessary? Can I get an enter_notify event
5033 * w/o either an expose event or a mouse motion event?
5036 pspp_sheet_view_enter_notify (GtkWidget *widget,
5037 GdkEventCrossing *event)
5039 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
5043 /* Sanity check it */
5044 if (event->window != tree_view->priv->bin_window)
5047 if (tree_view->priv->row_count == 0)
5050 if (event->mode == GDK_CROSSING_GRAB ||
5051 event->mode == GDK_CROSSING_GTK_GRAB ||
5052 event->mode == GDK_CROSSING_GTK_UNGRAB ||
5053 event->mode == GDK_CROSSING_STATE_CHANGED)
5056 /* find the node internally */
5057 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, event->y);
5060 pspp_sheet_view_find_offset (tree_view, new_y, &node);
5062 tree_view->priv->event_last_x = event->x;
5063 tree_view->priv->event_last_y = event->y;
5065 prelight_or_select (tree_view, node, event->x, event->y);
5071 pspp_sheet_view_leave_notify (GtkWidget *widget,
5072 GdkEventCrossing *event)
5074 PsppSheetView *tree_view;
5076 if (event->mode == GDK_CROSSING_GRAB)
5079 tree_view = PSPP_SHEET_VIEW (widget);
5081 if (tree_view->priv->prelight_node >= 0)
5082 _pspp_sheet_view_queue_draw_node (tree_view,
5083 tree_view->priv->prelight_node,
5086 tree_view->priv->event_last_x = -10000;
5087 tree_view->priv->event_last_y = -10000;
5089 prelight_or_select (tree_view,
5091 -1000, -1000); /* coords not possibly over an arrow */
5098 pspp_sheet_view_focus_out (GtkWidget *widget,
5099 GdkEventFocus *event)
5101 PsppSheetView *tree_view;
5103 tree_view = PSPP_SHEET_VIEW (widget);
5105 gtk_widget_queue_draw (widget);
5107 /* destroy interactive search dialog */
5108 if (tree_view->priv->search_window)
5109 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
5115 /* Incremental Reflow
5119 pspp_sheet_view_node_queue_redraw (PsppSheetView *tree_view,
5122 GtkAllocation allocation;
5123 gint y = pspp_sheet_view_node_find_offset (tree_view, node)
5124 - gtk_adjustment_get_value (tree_view->priv->vadjustment)
5125 + TREE_VIEW_HEADER_HEIGHT (tree_view);
5127 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
5129 gtk_widget_queue_draw_area (GTK_WIDGET (tree_view),
5132 tree_view->priv->fixed_height);
5136 node_is_visible (PsppSheetView *tree_view,
5142 y = pspp_sheet_view_node_find_offset (tree_view, node);
5143 height = ROW_HEIGHT (tree_view);
5145 if (y >= gtk_adjustment_get_value (tree_view->priv->vadjustment) &&
5146 y + height <= (gtk_adjustment_get_value (tree_view->priv->vadjustment)
5147 + gtk_adjustment_get_page_size (tree_view->priv->vadjustment)))
5153 /* Returns the row height. */
5155 validate_row (PsppSheetView *tree_view,
5160 PsppSheetViewColumn *column;
5161 GList *list, *first_column, *last_column;
5163 gint horizontal_separator;
5164 gint vertical_separator;
5165 gint focus_line_width;
5166 gboolean draw_vgrid_lines, draw_hgrid_lines;
5168 gint grid_line_width;
5169 gboolean wide_separators;
5170 gint separator_height;
5172 gtk_widget_style_get (GTK_WIDGET (tree_view),
5173 "focus-padding", &focus_pad,
5174 "focus-line-width", &focus_line_width,
5175 "horizontal-separator", &horizontal_separator,
5176 "vertical-separator", &vertical_separator,
5177 "grid-line-width", &grid_line_width,
5178 "wide-separators", &wide_separators,
5179 "separator-height", &separator_height,
5183 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
5184 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
5186 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
5187 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
5189 for (last_column = g_list_last (tree_view->priv->columns);
5190 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
5191 last_column = last_column->prev)
5194 for (first_column = g_list_first (tree_view->priv->columns);
5195 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
5196 first_column = first_column->next)
5199 for (list = tree_view->priv->columns; list; list = list->next)
5204 column = list->data;
5206 if (! column->visible)
5209 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, iter);
5210 pspp_sheet_view_column_cell_get_size (column,
5212 &tmp_width, &tmp_height);
5214 tmp_height += vertical_separator;
5215 height = MAX (height, tmp_height);
5217 tmp_width = tmp_width + horizontal_separator;
5219 if (draw_vgrid_lines)
5221 if (list->data == first_column || list->data == last_column)
5222 tmp_width += grid_line_width / 2.0;
5224 tmp_width += grid_line_width;
5227 if (tmp_width > column->requested_width)
5228 column->requested_width = tmp_width;
5231 if (draw_hgrid_lines)
5232 height += grid_line_width;
5234 tree_view->priv->post_validation_flag = TRUE;
5240 validate_visible_area (PsppSheetView *tree_view)
5242 GtkTreePath *path = NULL;
5243 GtkTreePath *above_path = NULL;
5246 gboolean size_changed = FALSE;
5248 gint area_above = 0;
5249 gint area_below = 0;
5250 GtkAllocation allocation;
5252 if (tree_view->priv->row_count == 0)
5255 if (tree_view->priv->scroll_to_path == NULL)
5258 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
5260 total_height = allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
5262 if (total_height == 0)
5265 path = gtk_tree_row_reference_get_path (tree_view->priv->scroll_to_path);
5268 /* we are going to scroll, and will update dy */
5269 _pspp_sheet_view_find_node (tree_view, path, &node);
5270 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
5272 if (tree_view->priv->scroll_to_use_align)
5274 gint height = ROW_HEIGHT (tree_view);
5275 area_above = (total_height - height) *
5276 tree_view->priv->scroll_to_row_align;
5277 area_below = total_height - area_above - height;
5278 area_above = MAX (area_above, 0);
5279 area_below = MAX (area_below, 0);
5284 * 1) row not visible
5288 gint height = ROW_HEIGHT (tree_view);
5290 dy = pspp_sheet_view_node_find_offset (tree_view, node);
5292 if (dy >= gtk_adjustment_get_value (tree_view->priv->vadjustment) &&
5293 dy + height <= (gtk_adjustment_get_value (tree_view->priv->vadjustment)
5294 + gtk_adjustment_get_page_size (tree_view->priv->vadjustment)))
5296 /* row visible: keep the row at the same position */
5297 area_above = dy - gtk_adjustment_get_value (tree_view->priv->vadjustment);
5298 area_below = (gtk_adjustment_get_value (tree_view->priv->vadjustment) +
5299 gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
5304 /* row not visible */
5306 && dy + height <= gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
5308 /* row at the beginning -- fixed */
5310 area_below = gtk_adjustment_get_page_size (tree_view->priv->vadjustment)
5311 - area_above - height;
5313 else if (dy >= (gtk_adjustment_get_upper (tree_view->priv->vadjustment) -
5314 gtk_adjustment_get_page_size (tree_view->priv->vadjustment)))
5316 /* row at the end -- fixed */
5317 area_above = dy - (gtk_adjustment_get_upper (tree_view->priv->vadjustment) -
5318 gtk_adjustment_get_page_size (tree_view->priv->vadjustment));
5319 area_below = gtk_adjustment_get_page_size (tree_view->priv->vadjustment) -
5320 area_above - height;
5324 area_above = gtk_adjustment_get_page_size (tree_view->priv->vadjustment) - height;
5330 /* row somewhere in the middle, bring it to the top
5334 area_below = total_height - height;
5340 /* the scroll to isn't valid; ignore it.
5343 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
5344 tree_view->priv->scroll_to_path = NULL;
5348 above_path = gtk_tree_path_copy (path);
5350 /* Now, we walk forwards and backwards, measuring rows. Unfortunately,
5351 * backwards is much slower then forward, as there is no iter_prev function.
5352 * We go forwards first in case we run out of tree. Then we go backwards to
5355 while (node >= 0 && area_below > 0)
5357 gboolean done = FALSE;
5360 node = pspp_sheet_view_node_next (tree_view, node);
5363 gboolean has_next = gtk_tree_model_iter_next (tree_view->priv->model, &iter);
5365 gtk_tree_path_next (path);
5368 TREE_VIEW_INTERNAL_ASSERT_VOID (has_next);
5378 area_below -= ROW_HEIGHT (tree_view);
5380 gtk_tree_path_free (path);
5382 /* If we ran out of tree, and have extra area_below left, we need to add it
5385 area_above += area_below;
5387 _pspp_sheet_view_find_node (tree_view, above_path, &node);
5389 /* We walk backwards */
5390 while (area_above > 0)
5392 node = pspp_sheet_view_node_prev (tree_view, node);
5394 /* Always find the new path in the tree. We cannot just assume
5395 * a gtk_tree_path_prev() is enough here, as there might be children
5396 * in between this node and the previous sibling node. If this
5397 * appears to be a performance hotspot in profiles, we can look into
5398 * intrigate logic for keeping path, node and iter in sync like
5399 * we do for forward walks. (Which will be hard because of the lacking
5406 gtk_tree_path_free (above_path);
5407 above_path = _pspp_sheet_view_find_path (tree_view, node);
5409 gtk_tree_model_get_iter (tree_view->priv->model, &iter, above_path);
5411 area_above -= ROW_HEIGHT (tree_view);
5414 /* set the dy here to scroll to the path,
5415 * and sync the top row accordingly
5417 pspp_sheet_view_set_top_row (tree_view, above_path, -area_above);
5418 pspp_sheet_view_top_row_to_dy (tree_view);
5420 /* update width/height and queue a resize */
5423 GtkRequisition requisition;
5425 /* We temporarily guess a size, under the assumption that it will be the
5426 * same when we get our next size_allocate. If we don't do this, we'll be
5427 * in an inconsistent state if we call top_row_to_dy. */
5429 gtk_widget_size_request (GTK_WIDGET (tree_view), &requisition);
5430 gtk_adjustment_set_upper (tree_view->priv->hadjustment, MAX (gtk_adjustment_get_upper (tree_view->priv->hadjustment), (gfloat)requisition.width));
5431 gtk_adjustment_set_upper (tree_view->priv->vadjustment, MAX (gtk_adjustment_get_upper (tree_view->priv->vadjustment), (gfloat)requisition.height));
5432 gtk_adjustment_changed (tree_view->priv->hadjustment);
5433 gtk_adjustment_changed (tree_view->priv->vadjustment);
5434 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
5437 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
5438 tree_view->priv->scroll_to_path = NULL;
5441 gtk_tree_path_free (above_path);
5443 if (tree_view->priv->scroll_to_column)
5445 tree_view->priv->scroll_to_column = NULL;
5447 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
5451 initialize_fixed_height_mode (PsppSheetView *tree_view)
5453 if (!tree_view->priv->row_count)
5456 if (tree_view->priv->fixed_height_set)
5459 if (tree_view->priv->fixed_height < 0)
5466 path = _pspp_sheet_view_find_path (tree_view, node);
5467 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
5469 tree_view->priv->fixed_height = validate_row (tree_view, node, &iter, path);
5471 gtk_tree_path_free (path);
5473 g_object_notify (G_OBJECT (tree_view), "fixed-height");
5477 /* Our strategy for finding nodes to validate is a little convoluted. We find
5478 * the left-most uninvalidated node. We then try walking right, validating
5479 * nodes. Once we find a valid node, we repeat the previous process of finding
5480 * the first invalid node.
5484 validate_rows_handler (PsppSheetView *tree_view)
5486 initialize_fixed_height_mode (tree_view);
5487 if (tree_view->priv->validate_rows_timer)
5489 g_source_remove (tree_view->priv->validate_rows_timer);
5490 tree_view->priv->validate_rows_timer = 0;
5497 do_presize_handler (PsppSheetView *tree_view)
5499 GtkRequisition requisition;
5501 validate_visible_area (tree_view);
5502 tree_view->priv->presize_handler_timer = 0;
5504 if (! gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5507 gtk_widget_size_request (GTK_WIDGET (tree_view), &requisition);
5509 gtk_adjustment_set_upper (tree_view->priv->hadjustment, MAX (gtk_adjustment_get_upper (tree_view->priv->hadjustment), (gfloat)requisition.width));
5510 gtk_adjustment_set_upper (tree_view->priv->vadjustment, MAX (gtk_adjustment_get_upper (tree_view->priv->vadjustment), (gfloat)requisition.height));
5511 gtk_adjustment_changed (tree_view->priv->hadjustment);
5512 gtk_adjustment_changed (tree_view->priv->vadjustment);
5513 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
5519 presize_handler_callback (gpointer data)
5521 do_presize_handler (PSPP_SHEET_VIEW (data));
5527 install_presize_handler (PsppSheetView *tree_view)
5529 if (! gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5532 if (! tree_view->priv->presize_handler_timer)
5534 tree_view->priv->presize_handler_timer =
5535 gdk_threads_add_idle_full (GTK_PRIORITY_RESIZE - 2, presize_handler_callback, tree_view, NULL);
5537 if (! tree_view->priv->validate_rows_timer)
5539 tree_view->priv->validate_rows_timer =
5540 gdk_threads_add_idle_full (PSPP_SHEET_VIEW_PRIORITY_VALIDATE, (GSourceFunc) validate_rows_handler, tree_view, NULL);
5545 scroll_sync_handler (PsppSheetView *tree_view)
5547 if (tree_view->priv->height <= gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
5548 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment), 0);
5549 else if (gtk_tree_row_reference_valid (tree_view->priv->top_row))
5550 pspp_sheet_view_top_row_to_dy (tree_view);
5552 pspp_sheet_view_dy_to_top_row (tree_view);
5554 tree_view->priv->scroll_sync_timer = 0;
5560 install_scroll_sync_handler (PsppSheetView *tree_view)
5562 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5565 if (!tree_view->priv->scroll_sync_timer)
5567 tree_view->priv->scroll_sync_timer =
5568 gdk_threads_add_idle_full (PSPP_SHEET_VIEW_PRIORITY_SCROLL_SYNC, (GSourceFunc) scroll_sync_handler, tree_view, NULL);
5573 pspp_sheet_view_set_top_row (PsppSheetView *tree_view,
5577 gtk_tree_row_reference_free (tree_view->priv->top_row);
5581 tree_view->priv->top_row = NULL;
5582 tree_view->priv->top_row_dy = 0;
5586 tree_view->priv->top_row = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
5587 tree_view->priv->top_row_dy = offset;
5591 /* Always call this iff dy is in the visible range. If the tree is empty, then
5592 * it's set to be NULL, and top_row_dy is 0;
5595 pspp_sheet_view_dy_to_top_row (PsppSheetView *tree_view)
5601 if (tree_view->priv->row_count == 0)
5603 pspp_sheet_view_set_top_row (tree_view, NULL, 0);
5607 offset = pspp_sheet_view_find_offset (tree_view,
5608 tree_view->priv->dy,
5613 pspp_sheet_view_set_top_row (tree_view, NULL, 0);
5617 path = _pspp_sheet_view_find_path (tree_view, node);
5618 pspp_sheet_view_set_top_row (tree_view, path, offset);
5619 gtk_tree_path_free (path);
5625 pspp_sheet_view_top_row_to_dy (PsppSheetView *tree_view)
5631 /* Avoid recursive calls */
5632 if (tree_view->priv->in_top_row_to_dy)
5635 if (tree_view->priv->top_row)
5636 path = gtk_tree_row_reference_get_path (tree_view->priv->top_row);
5643 _pspp_sheet_view_find_node (tree_view, path, &node);
5646 gtk_tree_path_free (path);
5650 /* keep dy and set new toprow */
5651 gtk_tree_row_reference_free (tree_view->priv->top_row);
5652 tree_view->priv->top_row = NULL;
5653 tree_view->priv->top_row_dy = 0;
5654 /* DO NOT install the idle handler */
5655 pspp_sheet_view_dy_to_top_row (tree_view);
5659 if (ROW_HEIGHT (tree_view) < tree_view->priv->top_row_dy)
5661 /* new top row -- do NOT install the idle handler */
5662 pspp_sheet_view_dy_to_top_row (tree_view);
5666 new_dy = pspp_sheet_view_node_find_offset (tree_view, node);
5667 new_dy += tree_view->priv->top_row_dy;
5669 if (new_dy + gtk_adjustment_get_page_size (tree_view->priv->vadjustment) > tree_view->priv->height)
5670 new_dy = tree_view->priv->height - gtk_adjustment_get_page_size (tree_view->priv->vadjustment);
5672 new_dy = MAX (0, new_dy);
5674 tree_view->priv->in_top_row_to_dy = TRUE;
5675 gtk_adjustment_set_value (tree_view->priv->vadjustment, (gdouble)new_dy);
5676 tree_view->priv->in_top_row_to_dy = FALSE;
5681 _pspp_sheet_view_install_mark_rows_col_dirty (PsppSheetView *tree_view)
5683 install_presize_handler (tree_view);
5689 set_source_row (GdkDragContext *context,
5690 GtkTreeModel *model,
5691 GtkTreePath *source_row)
5693 g_object_set_data_full (G_OBJECT (context),
5694 "gtk-tree-view-source-row",
5695 source_row ? gtk_tree_row_reference_new (model, source_row) : NULL,
5696 (GDestroyNotify) (source_row ? gtk_tree_row_reference_free : NULL));
5700 get_source_row (GdkDragContext *context)
5702 GtkTreeRowReference *ref =
5703 g_object_get_data (G_OBJECT (context), "gtk-tree-view-source-row");
5706 return gtk_tree_row_reference_get_path (ref);
5713 GtkTreeRowReference *dest_row;
5714 guint path_down_mode : 1;
5715 guint empty_view_drop : 1;
5716 guint drop_append_mode : 1;
5721 dest_row_free (gpointer data)
5723 DestRow *dr = (DestRow *)data;
5725 gtk_tree_row_reference_free (dr->dest_row);
5726 g_slice_free (DestRow, dr);
5730 set_dest_row (GdkDragContext *context,
5731 GtkTreeModel *model,
5732 GtkTreePath *dest_row,
5733 gboolean path_down_mode,
5734 gboolean empty_view_drop,
5735 gboolean drop_append_mode)
5741 g_object_set_data_full (G_OBJECT (context), "gtk-tree-view-dest-row",
5746 dr = g_slice_new (DestRow);
5748 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5749 dr->path_down_mode = path_down_mode != FALSE;
5750 dr->empty_view_drop = empty_view_drop != FALSE;
5751 dr->drop_append_mode = drop_append_mode != FALSE;
5753 g_object_set_data_full (G_OBJECT (context), "gtk-tree-view-dest-row",
5754 dr, (GDestroyNotify) dest_row_free);
5758 get_dest_row (GdkDragContext *context,
5759 gboolean *path_down_mode)
5762 g_object_get_data (G_OBJECT (context), "gtk-tree-view-dest-row");
5766 GtkTreePath *path = NULL;
5769 *path_down_mode = dr->path_down_mode;
5772 path = gtk_tree_row_reference_get_path (dr->dest_row);
5773 else if (dr->empty_view_drop)
5774 path = gtk_tree_path_new_from_indices (0, -1);
5778 if (path && dr->drop_append_mode)
5779 gtk_tree_path_next (path);
5787 /* Get/set whether drag_motion requested the drag data and
5788 * drag_data_received should thus not actually insert the data,
5789 * since the data doesn't result from a drop.
5792 set_status_pending (GdkDragContext *context,
5793 GdkDragAction suggested_action)
5795 g_object_set_data (G_OBJECT (context),
5796 "gtk-tree-view-status-pending",
5797 GINT_TO_POINTER (suggested_action));
5800 static GdkDragAction
5801 get_status_pending (GdkDragContext *context)
5803 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5804 "gtk-tree-view-status-pending"));
5807 static TreeViewDragInfo*
5808 get_info (PsppSheetView *tree_view)
5810 return g_object_get_data (G_OBJECT (tree_view), "gtk-tree-view-drag-info");
5814 destroy_info (TreeViewDragInfo *di)
5816 g_slice_free (TreeViewDragInfo, di);
5819 static TreeViewDragInfo*
5820 ensure_info (PsppSheetView *tree_view)
5822 TreeViewDragInfo *di;
5824 di = get_info (tree_view);
5828 di = g_slice_new0 (TreeViewDragInfo);
5830 g_object_set_data_full (G_OBJECT (tree_view),
5831 "gtk-tree-view-drag-info",
5833 (GDestroyNotify) destroy_info);
5840 remove_info (PsppSheetView *tree_view)
5842 g_object_set_data (G_OBJECT (tree_view), "gtk-tree-view-drag-info", NULL);
5847 drag_scan_timeout (gpointer data)
5849 PsppSheetView *tree_view;
5851 GdkModifierType state;
5852 GtkTreePath *path = NULL;
5853 PsppSheetViewColumn *column = NULL;
5854 GdkRectangle visible_rect;
5856 GDK_THREADS_ENTER ();
5858 tree_view = PSPP_SHEET_VIEW (data);
5860 gdk_window_get_pointer (tree_view->priv->bin_window,
5863 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
5865 /* See if we are near the edge. */
5866 if ((x - visible_rect.x) < SCROLL_EDGE_SIZE ||
5867 (visible_rect.x + visible_rect.width - x) < SCROLL_EDGE_SIZE ||
5868 (y - visible_rect.y) < SCROLL_EDGE_SIZE ||
5869 (visible_rect.y + visible_rect.height - y) < SCROLL_EDGE_SIZE)
5871 pspp_sheet_view_get_path_at_pos (tree_view,
5872 tree_view->priv->bin_window,
5881 pspp_sheet_view_scroll_to_cell (tree_view,
5887 gtk_tree_path_free (path);
5891 GDK_THREADS_LEAVE ();
5898 add_scroll_timeout (PsppSheetView *tree_view)
5900 if (tree_view->priv->scroll_timeout == 0)
5902 tree_view->priv->scroll_timeout =
5903 gdk_threads_add_timeout (150, scroll_row_timeout, tree_view);
5908 remove_scroll_timeout (PsppSheetView *tree_view)
5910 if (tree_view->priv->scroll_timeout != 0)
5912 g_source_remove (tree_view->priv->scroll_timeout);
5913 tree_view->priv->scroll_timeout = 0;
5918 check_model_dnd (GtkTreeModel *model,
5919 GType required_iface,
5920 const gchar *signal)
5922 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5924 g_warning ("You must override the default '%s' handler "
5925 "on PsppSheetView when using models that don't support "
5926 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5927 "is to connect to '%s' and call "
5928 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5929 "the default handler from running. Look at the source code "
5930 "for the default handler in gtktreeview.c to get an idea what "
5931 "your handler should do. (gtktreeview.c is in the GTK source "
5932 "code.) If you're using GTK from a language other than C, "
5933 "there may be a more natural way to override default handlers, e.g. via derivation.",
5934 signal, g_type_name (required_iface), signal);
5942 scroll_row_timeout (gpointer data)
5944 PsppSheetView *tree_view = data;
5946 pspp_sheet_view_horizontal_autoscroll (tree_view);
5947 pspp_sheet_view_vertical_autoscroll (tree_view);
5949 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
5950 pspp_sheet_view_update_rubber_band (tree_view);
5955 /* Returns TRUE if event should not be propagated to parent widgets */
5957 set_destination_row (PsppSheetView *tree_view,
5958 GdkDragContext *context,
5959 /* coordinates relative to the widget */
5962 GdkDragAction *suggested_action,
5965 GtkTreePath *path = NULL;
5966 PsppSheetViewDropPosition pos;
5967 PsppSheetViewDropPosition old_pos;
5968 TreeViewDragInfo *di;
5970 GtkTreePath *old_dest_path = NULL;
5971 gboolean can_drop = FALSE;
5973 *suggested_action = 0;
5976 widget = GTK_WIDGET (tree_view);
5978 di = get_info (tree_view);
5980 if (di == NULL || y - TREE_VIEW_HEADER_HEIGHT (tree_view) < 0)
5982 /* someone unset us as a drag dest, note that if
5983 * we return FALSE drag_leave isn't called
5986 pspp_sheet_view_set_drag_dest_row (tree_view,
5988 PSPP_SHEET_VIEW_DROP_BEFORE);
5990 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
5992 return FALSE; /* no longer a drop site */
5995 *target = gtk_drag_dest_find_target (widget, context,
5996 gtk_drag_dest_get_target_list (widget));
5997 if (*target == GDK_NONE)
6002 if (!pspp_sheet_view_get_dest_row_at_pos (tree_view,
6008 GtkTreeModel *model;
6010 /* the row got dropped on empty space, let's setup a special case
6014 gtk_tree_path_free (path);
6016 model = pspp_sheet_view_get_model (tree_view);
6018 n_children = gtk_tree_model_iter_n_children (model, NULL);
6021 pos = PSPP_SHEET_VIEW_DROP_AFTER;
6022 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6026 pos = PSPP_SHEET_VIEW_DROP_BEFORE;
6027 path = gtk_tree_path_new_from_indices (0, -1);
6037 /* If we left the current row's "open" zone, unset the timeout for
6040 pspp_sheet_view_get_drag_dest_row (tree_view,
6045 gtk_tree_path_free (old_dest_path);
6047 if (TRUE /* FIXME if the location droppable predicate */)
6055 GtkWidget *source_widget;
6057 *suggested_action = gdk_drag_context_get_suggested_action (context);
6058 source_widget = gtk_drag_get_source_widget (context);
6060 if (source_widget == widget)
6062 /* Default to MOVE, unless the user has
6063 * pressed ctrl or shift to affect available actions
6065 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
6066 *suggested_action = GDK_ACTION_MOVE;
6069 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6074 /* can't drop here */
6075 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6077 PSPP_SHEET_VIEW_DROP_BEFORE);
6081 gtk_tree_path_free (path);
6087 get_logical_dest_row (PsppSheetView *tree_view,
6088 gboolean *path_down_mode,
6089 gboolean *drop_append_mode)
6091 /* adjust path to point to the row the drop goes in front of */
6092 GtkTreePath *path = NULL;
6093 PsppSheetViewDropPosition pos;
6095 g_return_val_if_fail (path_down_mode != NULL, NULL);
6096 g_return_val_if_fail (drop_append_mode != NULL, NULL);
6098 *path_down_mode = FALSE;
6099 *drop_append_mode = 0;
6101 pspp_sheet_view_get_drag_dest_row (tree_view, &path, &pos);
6106 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE)
6108 else if (pos == PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE ||
6109 pos == PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER)
6110 *path_down_mode = TRUE;
6114 GtkTreeModel *model = pspp_sheet_view_get_model (tree_view);
6116 g_assert (pos == PSPP_SHEET_VIEW_DROP_AFTER);
6118 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6119 !gtk_tree_model_iter_next (model, &iter))
6120 *drop_append_mode = 1;
6123 *drop_append_mode = 0;
6124 gtk_tree_path_next (path);
6132 pspp_sheet_view_maybe_begin_dragging_row (PsppSheetView *tree_view,
6133 GdkEventMotion *event)
6135 GtkWidget *widget = GTK_WIDGET (tree_view);
6136 GdkDragContext *context;
6137 TreeViewDragInfo *di;
6138 GtkTreePath *path = NULL;
6140 gint cell_x, cell_y;
6141 GtkTreeModel *model;
6142 gboolean retval = FALSE;
6144 di = get_info (tree_view);
6146 if (di == NULL || !di->source_set)
6149 if (tree_view->priv->pressed_button < 0)
6152 if (!gtk_drag_check_threshold (widget,
6153 tree_view->priv->press_start_x,
6154 tree_view->priv->press_start_y,
6155 event->x, event->y))
6158 model = pspp_sheet_view_get_model (tree_view);
6163 button = tree_view->priv->pressed_button;
6164 tree_view->priv->pressed_button = -1;
6166 pspp_sheet_view_get_path_at_pos (tree_view,
6167 tree_view->priv->press_start_x,
6168 tree_view->priv->press_start_y,
6177 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6178 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6182 if (!(GDK_BUTTON1_MASK << (button - 1) & di->start_button_mask))
6185 /* Now we can begin the drag */
6189 context = gtk_drag_begin (widget,
6190 gtk_drag_source_get_target_list (widget),
6195 set_source_row (context, model, path);
6199 gtk_tree_path_free (path);
6207 pspp_sheet_view_drag_begin (GtkWidget *widget,
6208 GdkDragContext *context)
6211 PsppSheetView *tree_view;
6212 GtkTreePath *path = NULL;
6213 gint cell_x, cell_y;
6215 TreeViewDragInfo *di;
6217 tree_view = PSPP_SHEET_VIEW (widget);
6219 /* if the user uses a custom DND source impl, we don't set the icon here */
6220 di = get_info (tree_view);
6222 if (di == NULL || !di->source_set)
6225 pspp_sheet_view_get_path_at_pos (tree_view,
6226 tree_view->priv->press_start_x,
6227 tree_view->priv->press_start_y,
6233 g_return_if_fail (path != NULL);
6235 row_pix = pspp_sheet_view_create_row_drag_icon (tree_view,
6238 gtk_drag_set_icon_pixmap (context,
6239 gdk_drawable_get_colormap (row_pix),
6242 /* the + 1 is for the black border in the icon */
6243 tree_view->priv->press_start_x + 1,
6246 g_object_unref (row_pix);
6247 gtk_tree_path_free (path);
6253 pspp_sheet_view_drag_end (GtkWidget *widget,
6254 GdkDragContext *context)
6259 /* Default signal implementations for the drag signals */
6261 pspp_sheet_view_drag_data_get (GtkWidget *widget,
6262 GdkDragContext *context,
6263 GtkSelectionData *selection_data,
6267 PsppSheetView *tree_view;
6268 GtkTreeModel *model;
6269 TreeViewDragInfo *di;
6270 GtkTreePath *source_row;
6272 tree_view = PSPP_SHEET_VIEW (widget);
6274 model = pspp_sheet_view_get_model (tree_view);
6279 di = get_info (PSPP_SHEET_VIEW (widget));
6284 source_row = get_source_row (context);
6286 if (source_row == NULL)
6289 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6290 * any model; for DragSource models there are some other targets
6294 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6295 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6300 /* If drag_data_get does nothing, try providing row data. */
6301 if (gtk_selection_data_get_target (selection_data) == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6303 gtk_tree_set_row_drag_data (selection_data,
6309 gtk_tree_path_free (source_row);
6314 pspp_sheet_view_drag_data_delete (GtkWidget *widget,
6315 GdkDragContext *context)
6317 TreeViewDragInfo *di;
6318 GtkTreeModel *model;
6319 PsppSheetView *tree_view;
6320 GtkTreePath *source_row;
6322 tree_view = PSPP_SHEET_VIEW (widget);
6323 model = pspp_sheet_view_get_model (tree_view);
6325 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
6328 di = get_info (tree_view);
6333 source_row = get_source_row (context);
6335 if (source_row == NULL)
6338 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6341 gtk_tree_path_free (source_row);
6343 set_source_row (context, NULL, NULL);
6347 pspp_sheet_view_drag_leave (GtkWidget *widget,
6348 GdkDragContext *context,
6351 /* unset any highlight row */
6352 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6354 PSPP_SHEET_VIEW_DROP_BEFORE);
6356 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6361 pspp_sheet_view_drag_motion (GtkWidget *widget,
6362 GdkDragContext *context,
6363 /* coordinates relative to the widget */
6369 GtkTreePath *path = NULL;
6370 PsppSheetViewDropPosition pos;
6371 PsppSheetView *tree_view;
6372 GdkDragAction suggested_action = 0;
6375 tree_view = PSPP_SHEET_VIEW (widget);
6377 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6380 pspp_sheet_view_get_drag_dest_row (tree_view, &path, &pos);
6382 /* we only know this *after* set_desination_row */
6383 empty = tree_view->priv->empty_view_drop;
6385 if (path == NULL && !empty)
6387 /* Can't drop here. */
6388 gdk_drag_status (context, 0, time);
6392 if (tree_view->priv->open_dest_timeout == 0 &&
6393 (pos == PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER ||
6394 pos == PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE))
6400 add_scroll_timeout (tree_view);
6403 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6405 /* Request data so we can use the source row when
6406 * determining whether to accept the drop
6408 set_status_pending (context, suggested_action);
6409 gtk_drag_get_data (widget, context, target, time);
6413 set_status_pending (context, 0);
6414 gdk_drag_status (context, suggested_action, time);
6419 gtk_tree_path_free (path);
6426 pspp_sheet_view_drag_drop (GtkWidget *widget,
6427 GdkDragContext *context,
6428 /* coordinates relative to the widget */
6433 PsppSheetView *tree_view;
6435 GdkDragAction suggested_action = 0;
6436 GdkAtom target = GDK_NONE;
6437 TreeViewDragInfo *di;
6438 GtkTreeModel *model;
6439 gboolean path_down_mode;
6440 gboolean drop_append_mode;
6442 tree_view = PSPP_SHEET_VIEW (widget);
6444 model = pspp_sheet_view_get_model (tree_view);
6446 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6448 di = get_info (tree_view);
6453 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
6456 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6459 path = get_logical_dest_row (tree_view, &path_down_mode, &drop_append_mode);
6461 if (target != GDK_NONE && path != NULL)
6463 /* in case a motion had requested drag data, change things so we
6464 * treat drag data receives as a drop.
6466 set_status_pending (context, 0);
6467 set_dest_row (context, model, path,
6468 path_down_mode, tree_view->priv->empty_view_drop,
6473 gtk_tree_path_free (path);
6475 /* Unset this thing */
6476 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6478 PSPP_SHEET_VIEW_DROP_BEFORE);
6480 if (target != GDK_NONE)
6482 gtk_drag_get_data (widget, context, target, time);
6490 pspp_sheet_view_drag_data_received (GtkWidget *widget,
6491 GdkDragContext *context,
6492 /* coordinates relative to the widget */
6495 GtkSelectionData *selection_data,
6500 TreeViewDragInfo *di;
6501 gboolean accepted = FALSE;
6502 GtkTreeModel *model;
6503 PsppSheetView *tree_view;
6504 GtkTreePath *dest_row;
6505 GdkDragAction suggested_action;
6506 gboolean path_down_mode;
6507 gboolean drop_append_mode;
6509 tree_view = PSPP_SHEET_VIEW (widget);
6511 model = pspp_sheet_view_get_model (tree_view);
6513 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_data_received"))
6516 di = get_info (tree_view);
6521 suggested_action = get_status_pending (context);
6523 if (suggested_action)
6525 /* We are getting this data due to a request in drag_motion,
6526 * rather than due to a request in drag_drop, so we are just
6527 * supposed to call drag_status, not actually paste in the
6530 path = get_logical_dest_row (tree_view, &path_down_mode,
6534 suggested_action = 0;
6535 else if (path_down_mode)
6536 gtk_tree_path_down (path);
6538 if (suggested_action)
6540 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6546 path_down_mode = FALSE;
6547 gtk_tree_path_up (path);
6549 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6552 suggested_action = 0;
6555 suggested_action = 0;
6559 gdk_drag_status (context, suggested_action, time);
6562 gtk_tree_path_free (path);
6564 /* If you can't drop, remove user drop indicator until the next motion */
6565 if (suggested_action == 0)
6566 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6568 PSPP_SHEET_VIEW_DROP_BEFORE);
6573 dest_row = get_dest_row (context, &path_down_mode);
6575 if (dest_row == NULL)
6578 if (gtk_selection_data_get_length (selection_data) >= 0)
6582 gtk_tree_path_down (dest_row);
6583 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6584 dest_row, selection_data))
6585 gtk_tree_path_up (dest_row);
6589 if (gtk_selection_data_get_length (selection_data) >= 0)
6591 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6597 gtk_drag_finish (context,
6599 (gdk_drag_context_get_actions (context) == GDK_ACTION_MOVE),
6602 if (gtk_tree_path_get_depth (dest_row) == 1
6603 && gtk_tree_path_get_indices (dest_row)[0] == 0)
6605 /* special special case drag to "0", scroll to first item */
6606 if (!tree_view->priv->scroll_to_path)
6607 pspp_sheet_view_scroll_to_cell (tree_view, dest_row, NULL, FALSE, 0.0, 0.0);
6610 gtk_tree_path_free (dest_row);
6613 set_dest_row (context, NULL, NULL, FALSE, FALSE, FALSE);
6618 /* GtkContainer Methods
6623 pspp_sheet_view_remove (GtkContainer *container,
6626 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6627 PsppSheetViewChild *child = NULL;
6630 tmp_list = tree_view->priv->children;
6633 child = tmp_list->data;
6634 if (child->widget == widget)
6636 gtk_widget_unparent (widget);
6638 tree_view->priv->children = g_list_remove_link (tree_view->priv->children, tmp_list);
6639 g_list_free_1 (tmp_list);
6640 g_slice_free (PsppSheetViewChild, child);
6644 tmp_list = tmp_list->next;
6647 tmp_list = tree_view->priv->columns;
6651 PsppSheetViewColumn *column;
6652 column = tmp_list->data;
6653 if (column->button == widget)
6655 gtk_widget_unparent (widget);
6658 tmp_list = tmp_list->next;
6663 pspp_sheet_view_forall (GtkContainer *container,
6664 gboolean include_internals,
6665 GtkCallback callback,
6666 gpointer callback_data)
6668 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6669 PsppSheetViewChild *child = NULL;
6670 PsppSheetViewColumn *column;
6673 tmp_list = tree_view->priv->children;
6676 child = tmp_list->data;
6677 tmp_list = tmp_list->next;
6679 (* callback) (child->widget, callback_data);
6681 if (include_internals == FALSE)
6684 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6686 column = tmp_list->data;
6689 (* callback) (column->button, callback_data);
6693 /* Returns TRUE if the treeview contains no "special" (editable or activatable)
6694 * cells. If so we draw one big row-spanning focus rectangle.
6697 pspp_sheet_view_has_special_cell (PsppSheetView *tree_view)
6701 if (tree_view->priv->special_cells != PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT)
6702 return tree_view->priv->special_cells = PSPP_SHEET_VIEW_SPECIAL_CELLS_YES;
6704 for (list = tree_view->priv->columns; list; list = list->next)
6706 if (!((PsppSheetViewColumn *)list->data)->visible)
6708 if (_pspp_sheet_view_column_count_special_cells (list->data))
6716 pspp_sheet_view_focus_column (PsppSheetView *tree_view,
6717 PsppSheetViewColumn *focus_column,
6718 gboolean clamp_column_visible)
6720 g_return_if_fail (focus_column != NULL);
6722 tree_view->priv->focus_column = focus_column;
6723 if (!focus_column->button)
6725 pspp_sheet_view_column_set_need_button (focus_column, TRUE);
6726 // g_return_if_fail (focus_column->button != NULL);
6727 if (focus_column->button == NULL)
6731 if (gtk_container_get_focus_child (GTK_CONTAINER (tree_view)) != focus_column->button)
6732 gtk_widget_grab_focus (focus_column->button);
6734 if (clamp_column_visible)
6735 pspp_sheet_view_clamp_column_visible (tree_view, focus_column, FALSE);
6738 /* Returns TRUE if the focus is within the headers, after the focus operation is
6742 pspp_sheet_view_header_focus (PsppSheetView *tree_view,
6743 GtkDirectionType dir,
6744 gboolean clamp_column_visible)
6746 GtkWidget *focus_child;
6747 PsppSheetViewColumn *focus_column;
6748 GList *last_column, *first_column;
6752 if (! PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
6755 focus_child = gtk_container_get_focus_child (GTK_CONTAINER (tree_view));
6757 first_column = tree_view->priv->columns;
6758 while (first_column)
6760 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (first_column->data);
6762 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6764 first_column = first_column->next;
6767 /* No headers are visible, or are focusable. We can't focus in or out.
6769 if (first_column == NULL)
6772 last_column = g_list_last (tree_view->priv->columns);
6775 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (last_column->data);
6777 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6779 last_column = last_column->prev;
6783 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
6787 case GTK_DIR_TAB_BACKWARD:
6788 case GTK_DIR_TAB_FORWARD:
6791 if (focus_child == NULL)
6793 if (tree_view->priv->focus_column != NULL &&
6794 pspp_sheet_view_column_can_focus (tree_view->priv->focus_column))
6795 focus_column = tree_view->priv->focus_column;
6797 focus_column = first_column->data;
6798 pspp_sheet_view_focus_column (tree_view, focus_column,
6799 clamp_column_visible);
6806 if (focus_child == NULL)
6808 if (tree_view->priv->focus_column != NULL)
6809 focus_column = tree_view->priv->focus_column;
6810 else if (dir == GTK_DIR_LEFT)
6811 focus_column = last_column->data;
6813 focus_column = first_column->data;
6814 pspp_sheet_view_focus_column (tree_view, focus_column,
6815 clamp_column_visible);
6819 if (gtk_widget_child_focus (focus_child, dir))
6821 /* The focus moves inside the button. */
6822 /* This is probably a great example of bad UI */
6823 if (clamp_column_visible)
6824 pspp_sheet_view_clamp_column_visible (tree_view,
6825 tree_view->priv->focus_column,
6830 /* We need to move the focus among the row of buttons. */
6831 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6832 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)->button == focus_child)
6835 if ((tmp_list == first_column && dir == (rtl ? GTK_DIR_RIGHT : GTK_DIR_LEFT))
6836 || (tmp_list == last_column && dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT)))
6838 gtk_widget_error_bell (GTK_WIDGET (tree_view));
6844 PsppSheetViewColumn *column;
6846 if (dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT))
6847 tmp_list = tmp_list->next;
6849 tmp_list = tmp_list->prev;
6851 if (tmp_list == NULL)
6853 g_warning ("Internal button not found");
6856 column = tmp_list->data;
6857 if (column->visible &&
6858 pspp_sheet_view_column_can_focus (column))
6860 pspp_sheet_view_column_set_need_button (column, TRUE);
6863 pspp_sheet_view_focus_column (tree_view, column,
6864 clamp_column_visible);
6872 g_assert_not_reached ();
6879 /* This function returns in 'path' the first focusable path, if the given path
6880 * is already focusable, it's the returned one.
6884 search_first_focusable_path (PsppSheetView *tree_view,
6886 gboolean search_forward,
6889 /* XXX this function is trivial given that the sheetview doesn't support
6893 if (!path || !*path)
6896 _pspp_sheet_view_find_node (tree_view, *path, &node);
6904 return (*path != NULL);
6908 pspp_sheet_view_focus (GtkWidget *widget,
6909 GtkDirectionType direction)
6911 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6912 GtkContainer *container = GTK_CONTAINER (widget);
6913 GtkWidget *focus_child;
6915 if (!gtk_widget_is_sensitive (widget) || !gtk_widget_get_can_focus (widget))
6918 focus_child = gtk_container_get_focus_child (container);
6920 pspp_sheet_view_stop_editing (PSPP_SHEET_VIEW (widget), FALSE);
6921 /* Case 1. Headers currently have focus. */
6928 pspp_sheet_view_header_focus (tree_view, direction, TRUE);
6930 case GTK_DIR_TAB_BACKWARD:
6933 case GTK_DIR_TAB_FORWARD:
6935 gtk_widget_grab_focus (widget);
6938 g_assert_not_reached ();
6943 /* Case 2. We don't have focus at all. */
6944 if (!gtk_widget_has_focus (widget))
6946 if (!pspp_sheet_view_header_focus (tree_view, direction, FALSE))
6947 gtk_widget_grab_focus (widget);
6951 /* Case 3. We have focus already. */
6952 if (direction == GTK_DIR_TAB_BACKWARD)
6953 return (pspp_sheet_view_header_focus (tree_view, direction, FALSE));
6954 else if (direction == GTK_DIR_TAB_FORWARD)
6957 /* Other directions caught by the keybindings */
6958 gtk_widget_grab_focus (widget);
6963 pspp_sheet_view_grab_focus (GtkWidget *widget)
6965 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->grab_focus (widget);
6967 pspp_sheet_view_focus_to_cursor (PSPP_SHEET_VIEW (widget));
6971 pspp_sheet_view_style_set (GtkWidget *widget,
6972 GtkStyle *previous_style)
6974 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6976 PsppSheetViewColumn *column;
6978 if (gtk_widget_get_realized (widget))
6980 gdk_window_set_background (tree_view->priv->bin_window, >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
6981 gtk_style_set_background (gtk_widget_get_style (widget), tree_view->priv->header_window, GTK_STATE_NORMAL);
6982 pspp_sheet_view_set_grid_lines (tree_view, tree_view->priv->grid_lines);
6985 gtk_widget_style_get (widget,
6986 "expander-size", &tree_view->priv->expander_size,
6988 tree_view->priv->expander_size += EXPANDER_EXTRA_PADDING;
6990 for (list = tree_view->priv->columns; list; list = list->next)
6992 column = list->data;
6993 _pspp_sheet_view_column_cell_set_dirty (column);
6996 tree_view->priv->fixed_height = -1;
6998 /* Invalidate cached button style. */
6999 if (tree_view->priv->button_style)
7001 g_object_unref (tree_view->priv->button_style);
7002 tree_view->priv->button_style = NULL;
7005 gtk_widget_queue_resize (widget);
7010 pspp_sheet_view_set_focus_child (GtkContainer *container,
7013 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
7016 for (list = tree_view->priv->columns; list; list = list->next)
7018 if (PSPP_SHEET_VIEW_COLUMN (list->data)->button == child)
7020 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
7025 GTK_CONTAINER_CLASS (pspp_sheet_view_parent_class)->set_focus_child (container, child);
7029 pspp_sheet_view_set_adjustments (PsppSheetView *tree_view,
7030 GtkAdjustment *hadj,
7031 GtkAdjustment *vadj)
7033 gboolean need_adjust = FALSE;
7035 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
7038 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
7040 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
7042 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
7044 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
7046 if (tree_view->priv->hadjustment && (tree_view->priv->hadjustment != hadj))
7048 g_signal_handlers_disconnect_by_func (tree_view->priv->hadjustment,
7049 pspp_sheet_view_adjustment_changed,
7051 g_object_unref (tree_view->priv->hadjustment);
7054 if (tree_view->priv->vadjustment && (tree_view->priv->vadjustment != vadj))
7056 g_signal_handlers_disconnect_by_func (tree_view->priv->vadjustment,
7057 pspp_sheet_view_adjustment_changed,
7059 g_object_unref (tree_view->priv->vadjustment);
7062 if (tree_view->priv->hadjustment != hadj)
7064 tree_view->priv->hadjustment = hadj;
7065 g_object_ref_sink (tree_view->priv->hadjustment);
7067 g_signal_connect (tree_view->priv->hadjustment, "value-changed",
7068 G_CALLBACK (pspp_sheet_view_adjustment_changed),
7073 if (tree_view->priv->vadjustment != vadj)
7075 tree_view->priv->vadjustment = vadj;
7076 g_object_ref_sink (tree_view->priv->vadjustment);
7078 g_signal_connect (tree_view->priv->vadjustment, "value-changed",
7079 G_CALLBACK (pspp_sheet_view_adjustment_changed),
7085 pspp_sheet_view_adjustment_changed (NULL, tree_view);
7090 pspp_sheet_view_real_move_cursor (PsppSheetView *tree_view,
7091 GtkMovementStep step,
7094 PsppSheetSelectMode mode;
7095 GdkModifierType state;
7097 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
7098 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
7099 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
7100 step == GTK_MOVEMENT_DISPLAY_LINES ||
7101 step == GTK_MOVEMENT_PAGES ||
7102 step == GTK_MOVEMENT_BUFFER_ENDS ||
7103 step == GTK_MOVEMENT_DISPLAY_LINE_ENDS, FALSE);
7105 if (tree_view->priv->row_count == 0)
7107 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7110 pspp_sheet_view_stop_editing (tree_view, FALSE);
7111 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
7112 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7115 if (gtk_get_current_event_state (&state))
7117 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
7118 mode |= PSPP_SHEET_SELECT_MODE_TOGGLE;
7119 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
7120 mode |= PSPP_SHEET_SELECT_MODE_EXTEND;
7122 /* else we assume not pressed */
7126 case GTK_MOVEMENT_LOGICAL_POSITIONS:
7127 pspp_sheet_view_move_cursor_tab (tree_view, count);
7129 case GTK_MOVEMENT_VISUAL_POSITIONS:
7130 pspp_sheet_view_move_cursor_left_right (tree_view, count, mode);
7132 case GTK_MOVEMENT_DISPLAY_LINES:
7133 pspp_sheet_view_move_cursor_up_down (tree_view, count, mode);
7135 case GTK_MOVEMENT_PAGES:
7136 pspp_sheet_view_move_cursor_page_up_down (tree_view, count, mode);
7138 case GTK_MOVEMENT_BUFFER_ENDS:
7139 pspp_sheet_view_move_cursor_start_end (tree_view, count, mode);
7141 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
7142 pspp_sheet_view_move_cursor_line_start_end (tree_view, count, mode);
7145 g_assert_not_reached ();
7152 pspp_sheet_view_put (PsppSheetView *tree_view,
7153 GtkWidget *child_widget,
7154 /* in bin_window coordinates */
7160 PsppSheetViewChild *child;
7162 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
7163 g_return_if_fail (GTK_IS_WIDGET (child_widget));
7165 child = g_slice_new (PsppSheetViewChild);
7167 child->widget = child_widget;
7170 child->width = width;
7171 child->height = height;
7173 tree_view->priv->children = g_list_append (tree_view->priv->children, child);
7175 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7176 gtk_widget_set_parent_window (child->widget, tree_view->priv->bin_window);
7178 gtk_widget_set_parent (child_widget, GTK_WIDGET (tree_view));
7182 _pspp_sheet_view_child_move_resize (PsppSheetView *tree_view,
7184 /* in tree coordinates */
7190 PsppSheetViewChild *child = NULL;
7192 GdkRectangle allocation;
7194 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
7195 g_return_if_fail (GTK_IS_WIDGET (widget));
7197 for (list = tree_view->priv->children; list; list = list->next)
7199 if (((PsppSheetViewChild *)list->data)->widget == widget)
7208 allocation.x = child->x = x;
7209 allocation.y = child->y = y;
7210 allocation.width = child->width = width;
7211 allocation.height = child->height = height;
7213 if (gtk_widget_get_realized (widget))
7214 gtk_widget_size_allocate (widget, &allocation);
7218 /* TreeModel Callbacks
7222 pspp_sheet_view_row_changed (GtkTreeModel *model,
7227 PsppSheetView *tree_view = (PsppSheetView *)data;
7229 gboolean free_path = FALSE;
7230 GtkTreePath *cursor_path;
7232 g_return_if_fail (path != NULL || iter != NULL);
7234 if (tree_view->priv->cursor != NULL)
7235 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7239 if (tree_view->priv->edited_column &&
7240 (cursor_path == NULL || gtk_tree_path_compare (cursor_path, path) == 0))
7241 pspp_sheet_view_stop_editing (tree_view, TRUE);
7243 if (cursor_path != NULL)
7244 gtk_tree_path_free (cursor_path);
7248 path = gtk_tree_model_get_path (model, iter);
7251 else if (iter == NULL)
7252 gtk_tree_model_get_iter (model, iter, path);
7254 _pspp_sheet_view_find_node (tree_view,
7260 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7261 pspp_sheet_view_node_queue_redraw (tree_view, node);
7265 gtk_tree_path_free (path);
7269 pspp_sheet_view_row_inserted (GtkTreeModel *model,
7274 PsppSheetView *tree_view = (PsppSheetView *) data;
7277 gint height = tree_view->priv->fixed_height;
7278 gboolean free_path = FALSE;
7279 gboolean node_visible = TRUE;
7281 g_return_if_fail (path != NULL || iter != NULL);
7285 path = gtk_tree_model_get_path (model, iter);
7288 else if (iter == NULL)
7289 gtk_tree_model_get_iter (model, iter, path);
7291 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7293 /* Update all row-references */
7294 gtk_tree_row_reference_inserted (G_OBJECT (data), path);
7295 indices = gtk_tree_path_get_indices (path);
7296 tmpnode = indices[0];
7298 range_tower_insert0 (tree_view->priv->selected, tmpnode, 1);
7302 if (node_visible && node_is_visible (tree_view, tmpnode))
7303 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7305 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (tree_view));
7308 install_presize_handler (tree_view);
7310 gtk_tree_path_free (path);
7314 pspp_sheet_view_row_deleted (GtkTreeModel *model,
7318 PsppSheetView *tree_view = (PsppSheetView *)data;
7321 g_return_if_fail (path != NULL);
7323 gtk_tree_row_reference_deleted (G_OBJECT (data), path);
7325 _pspp_sheet_view_find_node (tree_view, path, &node);
7330 range_tower_delete (tree_view->priv->selected, node, 1);
7332 /* Ensure we don't have a dangling pointer to a dead node */
7333 ensure_unprelighted (tree_view);
7335 /* Cancel editting if we've started */
7336 pspp_sheet_view_stop_editing (tree_view, TRUE);
7338 if (tree_view->priv->destroy_count_func)
7340 gint child_count = 0;
7341 tree_view->priv->destroy_count_func (tree_view, path, child_count, tree_view->priv->destroy_count_data);
7344 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7346 if (! gtk_tree_row_reference_valid (tree_view->priv->top_row))
7348 gtk_tree_row_reference_free (tree_view->priv->top_row);
7349 tree_view->priv->top_row = NULL;
7352 install_scroll_sync_handler (tree_view);
7354 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7357 if (helper_data.changed)
7358 g_signal_emit_by_name (tree_view->priv->selection, "changed");
7363 pspp_sheet_view_rows_reordered (GtkTreeModel *model,
7364 GtkTreePath *parent,
7369 PsppSheetView *tree_view = PSPP_SHEET_VIEW (data);
7372 /* XXX need to adjust selection */
7373 len = gtk_tree_model_iter_n_children (model, iter);
7378 gtk_tree_row_reference_reordered (G_OBJECT (data),
7383 if (gtk_tree_path_get_depth (parent) != 0)
7386 if (tree_view->priv->edited_column)
7387 pspp_sheet_view_stop_editing (tree_view, TRUE);
7389 /* we need to be unprelighted */
7390 ensure_unprelighted (tree_view);
7392 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
7394 pspp_sheet_view_dy_to_top_row (tree_view);
7398 /* Internal tree functions
7403 pspp_sheet_view_get_background_xrange (PsppSheetView *tree_view,
7404 PsppSheetViewColumn *column,
7408 PsppSheetViewColumn *tmp_column = NULL;
7419 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7422 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
7424 list = (rtl ? list->prev : list->next))
7426 tmp_column = list->data;
7428 if (tmp_column == column)
7431 if (tmp_column->visible)
7432 total_width += tmp_column->width;
7435 if (tmp_column != column)
7437 g_warning (G_STRLOC": passed-in column isn't in the tree");
7446 if (column->visible)
7447 *x2 = total_width + column->width;
7449 *x2 = total_width; /* width of 0 */
7453 /* Make sure the node is visible vertically */
7455 pspp_sheet_view_clamp_node_visible (PsppSheetView *tree_view,
7458 gint node_dy, height;
7459 GtkTreePath *path = NULL;
7461 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7464 /* just return if the node is visible, avoiding a costly expose */
7465 node_dy = pspp_sheet_view_node_find_offset (tree_view, node);
7466 height = ROW_HEIGHT (tree_view);
7467 if (node_dy >= gtk_adjustment_get_value (tree_view->priv->vadjustment)
7468 && node_dy + height <= (gtk_adjustment_get_value (tree_view->priv->vadjustment)
7469 + gtk_adjustment_get_page_size (tree_view->priv->vadjustment)))
7472 path = _pspp_sheet_view_find_path (tree_view, node);
7475 /* We process updates because we want to clear old selected items when we scroll.
7476 * if this is removed, we get a "selection streak" at the bottom. */
7477 gdk_window_process_updates (tree_view->priv->bin_window, TRUE);
7478 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL, FALSE, 0.0, 0.0);
7479 gtk_tree_path_free (path);
7484 pspp_sheet_view_clamp_column_visible (PsppSheetView *tree_view,
7485 PsppSheetViewColumn *column,
7486 gboolean focus_to_cell)
7493 x = column->allocation.x;
7494 width = column->allocation.width;
7496 if (width > gtk_adjustment_get_page_size (tree_view->priv->hadjustment))
7498 /* The column is larger than the horizontal page size. If the
7499 * column has cells which can be focussed individually, then we make
7500 * sure the cell which gets focus is fully visible (if even the
7501 * focus cell is bigger than the page size, we make sure the
7502 * left-hand side of the cell is visible).
7504 * If the column does not have those so-called special cells, we
7505 * make sure the left-hand side of the column is visible.
7508 if (focus_to_cell && pspp_sheet_view_has_special_cell (tree_view))
7510 GtkTreePath *cursor_path;
7511 GdkRectangle background_area, cell_area, focus_area;
7513 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7515 pspp_sheet_view_get_cell_area (tree_view,
7516 cursor_path, column, &cell_area);
7517 pspp_sheet_view_get_background_area (tree_view,
7518 cursor_path, column,
7521 gtk_tree_path_free (cursor_path);
7523 _pspp_sheet_view_column_get_focus_area (column,
7529 width = focus_area.width;
7531 if (width < gtk_adjustment_get_page_size (tree_view->priv->hadjustment))
7533 if ((gtk_adjustment_get_value (tree_view->priv->hadjustment) + gtk_adjustment_get_page_size (tree_view->priv->hadjustment)) < (x + width))
7534 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7535 x + width - gtk_adjustment_get_page_size (tree_view->priv->hadjustment));
7536 else if (gtk_adjustment_get_value (tree_view->priv->hadjustment) > x)
7537 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7541 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7543 gtk_adjustment_get_lower (tree_view->priv->hadjustment),
7544 gtk_adjustment_get_upper (tree_view->priv->hadjustment)
7545 - gtk_adjustment_get_page_size (tree_view->priv->hadjustment)));
7549 if ((gtk_adjustment_get_value (tree_view->priv->hadjustment) + gtk_adjustment_get_page_size (tree_view->priv->hadjustment)) < (x + width))
7550 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7551 x + width - gtk_adjustment_get_page_size (tree_view->priv->hadjustment));
7552 else if (gtk_adjustment_get_value (tree_view->priv->hadjustment) > x)
7553 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7558 _pspp_sheet_view_find_path (PsppSheetView *tree_view,
7563 path = gtk_tree_path_new ();
7565 gtk_tree_path_append_index (path, node);
7570 _pspp_sheet_view_find_node (PsppSheetView *tree_view,
7574 gint *indices = gtk_tree_path_get_indices (path);
7575 gint depth = gtk_tree_path_get_depth (path);
7578 if (depth == 0 || indices[0] < 0 || indices[0] >= tree_view->priv->row_count)
7584 pspp_sheet_view_add_move_binding (GtkBindingSet *binding_set,
7587 gboolean add_shifted_binding,
7588 GtkMovementStep step,
7592 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
7597 if (add_shifted_binding)
7598 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
7603 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
7606 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
7611 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
7618 pspp_sheet_view_set_column_drag_info (PsppSheetView *tree_view,
7619 PsppSheetViewColumn *column)
7621 PsppSheetViewColumn *left_column;
7622 PsppSheetViewColumn *cur_column = NULL;
7623 PsppSheetViewColumnReorder *reorder;
7628 /* We want to precalculate the motion list such that we know what column slots
7632 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7634 /* First, identify all possible drop spots */
7636 tmp_list = g_list_last (tree_view->priv->columns);
7638 tmp_list = g_list_first (tree_view->priv->columns);
7642 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
7643 tmp_list = rtl?g_list_previous (tmp_list):g_list_next (tmp_list);
7645 if (cur_column->visible == FALSE)
7648 /* If it's not the column moving and func tells us to skip over the column, we continue. */
7649 if (left_column != column && cur_column != column &&
7650 tree_view->priv->column_drop_func &&
7651 ! tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
7653 left_column = cur_column;
7656 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7657 reorder->left_column = left_column;
7658 left_column = reorder->right_column = cur_column;
7660 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7663 /* Add the last one */
7664 if (tree_view->priv->column_drop_func == NULL ||
7665 ((left_column != column) &&
7666 tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data)))
7668 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7669 reorder->left_column = left_column;
7670 reorder->right_column = NULL;
7671 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7674 /* We quickly check to see if it even makes sense to reorder columns. */
7675 /* If there is nothing that can be moved, then we return */
7677 if (tree_view->priv->column_drag_info == NULL)
7680 /* We know there are always 2 slots possbile, as you can always return column. */
7681 /* If that's all there is, return */
7682 if (tree_view->priv->column_drag_info->next == NULL ||
7683 (tree_view->priv->column_drag_info->next->next == NULL &&
7684 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->data)->right_column == column &&
7685 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->next->data)->left_column == column))
7687 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7688 g_slice_free (PsppSheetViewColumnReorder, tmp_list->data);
7689 g_list_free (tree_view->priv->column_drag_info);
7690 tree_view->priv->column_drag_info = NULL;
7693 /* We fill in the ranges for the columns, now that we've isolated them */
7694 left = - TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7696 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7698 reorder = (PsppSheetViewColumnReorder *) tmp_list->data;
7700 reorder->left_align = left;
7701 if (tmp_list->next != NULL)
7703 g_assert (tmp_list->next->data);
7704 left = reorder->right_align = (reorder->right_column->allocation.x +
7705 reorder->right_column->allocation.width +
7706 ((PsppSheetViewColumnReorder *)tmp_list->next->data)->left_column->allocation.x)/2;
7710 gint width = gdk_window_get_width (tree_view->priv->header_window);
7711 reorder->right_align = width + TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7717 _pspp_sheet_view_column_start_drag (PsppSheetView *tree_view,
7718 PsppSheetViewColumn *column)
7720 GdkEvent *send_event;
7721 GtkAllocation allocation;
7723 GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
7724 GdkDisplay *display = gdk_screen_get_display (screen);
7726 g_return_if_fail (tree_view->priv->column_drag_info == NULL);
7727 g_return_if_fail (tree_view->priv->cur_reorder == NULL);
7728 g_return_if_fail (column->button);
7730 pspp_sheet_view_set_column_drag_info (tree_view, column);
7732 if (tree_view->priv->column_drag_info == NULL)
7735 if (tree_view->priv->drag_window == NULL)
7737 GdkWindowAttr attributes;
7738 guint attributes_mask;
7740 attributes.window_type = GDK_WINDOW_CHILD;
7741 attributes.wclass = GDK_INPUT_OUTPUT;
7742 attributes.x = column->allocation.x;
7744 attributes.width = column->allocation.width;
7745 attributes.height = column->allocation.height;
7746 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
7747 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
7748 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL ;
7750 tree_view->priv->drag_window = gdk_window_new (tree_view->priv->bin_window,
7753 gdk_window_set_user_data (tree_view->priv->drag_window, GTK_WIDGET (tree_view));
7756 gdk_display_pointer_ungrab (display, GDK_CURRENT_TIME);
7757 gdk_display_keyboard_ungrab (display, GDK_CURRENT_TIME);
7759 gtk_grab_remove (column->button);
7761 send_event = gdk_event_new (GDK_LEAVE_NOTIFY);
7762 send_event->crossing.send_event = TRUE;
7763 send_event->crossing.window = g_object_ref (gtk_button_get_event_window (GTK_BUTTON (column->button)));
7764 send_event->crossing.subwindow = NULL;
7765 send_event->crossing.detail = GDK_NOTIFY_ANCESTOR;
7766 send_event->crossing.time = GDK_CURRENT_TIME;
7768 gtk_propagate_event (column->button, send_event);
7769 gdk_event_free (send_event);
7771 send_event = gdk_event_new (GDK_BUTTON_RELEASE);
7772 send_event->button.window = g_object_ref (gdk_screen_get_root_window (screen));
7773 send_event->button.send_event = TRUE;
7774 send_event->button.time = GDK_CURRENT_TIME;
7775 send_event->button.x = -1;
7776 send_event->button.y = -1;
7777 send_event->button.axes = NULL;
7778 send_event->button.state = 0;
7779 send_event->button.button = 1;
7780 send_event->button.device =
7781 gdk_device_manager_get_client_pointer (gdk_display_get_device_manager (display));
7783 send_event->button.x_root = 0;
7784 send_event->button.y_root = 0;
7786 gtk_propagate_event (column->button, send_event);
7787 gdk_event_free (send_event);
7789 /* Kids, don't try this at home */
7790 g_object_ref (column->button);
7791 gtk_container_remove (GTK_CONTAINER (tree_view), column->button);
7792 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7793 gtk_widget_set_parent (column->button, GTK_WIDGET (tree_view));
7794 g_object_unref (column->button);
7796 tree_view->priv->drag_column_x = column->allocation.x;
7797 allocation = column->allocation;
7799 gtk_widget_size_allocate (column->button, &allocation);
7800 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7802 tree_view->priv->drag_column = column;
7803 gdk_window_show (tree_view->priv->drag_window);
7805 gdk_window_get_origin (tree_view->priv->header_window, &x, &y);
7807 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7808 while (gtk_events_pending ())
7809 gtk_main_iteration ();
7811 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG);
7812 gdk_pointer_grab (tree_view->priv->drag_window,
7814 GDK_POINTER_MOTION_MASK|GDK_BUTTON_RELEASE_MASK,
7815 NULL, NULL, GDK_CURRENT_TIME);
7816 gdk_keyboard_grab (tree_view->priv->drag_window,
7822 _pspp_sheet_view_queue_draw_node (PsppSheetView *tree_view,
7824 const GdkRectangle *clip_rect)
7827 GtkAllocation allocation;
7829 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7832 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
7834 rect.width = MAX (tree_view->priv->width, allocation.width);
7836 rect.y = BACKGROUND_FIRST_PIXEL (tree_view, node);
7837 rect.height = ROW_HEIGHT (tree_view);
7841 GdkRectangle new_rect;
7843 gdk_rectangle_intersect (clip_rect, &rect, &new_rect);
7845 gdk_window_invalidate_rect (tree_view->priv->bin_window, &new_rect, TRUE);
7849 gdk_window_invalidate_rect (tree_view->priv->bin_window, &rect, TRUE);
7854 pspp_sheet_view_queue_draw_path (PsppSheetView *tree_view,
7856 const GdkRectangle *clip_rect)
7860 _pspp_sheet_view_find_node (tree_view, path, &node);
7863 _pspp_sheet_view_queue_draw_node (tree_view, node, clip_rect);
7867 pspp_sheet_view_focus_to_cursor (PsppSheetView *tree_view)
7870 GtkTreePath *cursor_path;
7872 if ((tree_view->priv->row_count == 0) ||
7873 (! gtk_widget_get_realized (GTK_WIDGET (tree_view))))
7877 if (tree_view->priv->cursor)
7878 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7880 if (cursor_path == NULL)
7882 /* There's no cursor. Move the cursor to the first selected row, if any
7883 * are selected, otherwise to the first row in the sheetview.
7885 GList *selected_rows;
7886 GtkTreeModel *model;
7887 PsppSheetSelection *selection;
7889 selection = pspp_sheet_view_get_selection (tree_view);
7890 selected_rows = pspp_sheet_selection_get_selected_rows (selection, &model);
7894 /* XXX we could avoid doing O(n) work to get this result */
7895 cursor_path = gtk_tree_path_copy((const GtkTreePath *)(selected_rows->data));
7896 g_list_foreach (selected_rows, (GFunc)gtk_tree_path_free, NULL);
7897 g_list_free (selected_rows);
7901 cursor_path = gtk_tree_path_new_first ();
7902 search_first_focusable_path (tree_view, &cursor_path,
7906 gtk_tree_row_reference_free (tree_view->priv->cursor);
7907 tree_view->priv->cursor = NULL;
7911 if (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7912 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE)
7913 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, FALSE, FALSE, 0);
7915 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE, 0);
7921 /* Now find a column for the cursor. */
7922 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
7924 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
7925 gtk_tree_path_free (cursor_path);
7927 if (tree_view->priv->focus_column == NULL)
7930 for (list = tree_view->priv->columns; list; list = list->next)
7932 if (PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
7934 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
7935 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
7936 pspp_sheet_selection_select_column (tree_view->priv->selection, tree_view->priv->focus_column);
7946 pspp_sheet_view_move_cursor_up_down (PsppSheetView *tree_view,
7948 PsppSheetSelectMode mode)
7950 gint selection_count;
7951 int cursor_node = -1;
7952 int new_cursor_node = -1;
7953 GtkTreePath *cursor_path = NULL;
7954 gboolean grab_focus = TRUE;
7956 if (! gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7960 if (!gtk_tree_row_reference_valid (tree_view->priv->cursor))
7961 /* FIXME: we lost the cursor; should we get the first? */
7964 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7965 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
7967 if (cursor_node < 0)
7968 /* FIXME: we lost the cursor; should we get the first? */
7971 selection_count = pspp_sheet_selection_count_selected_rows (tree_view->priv->selection);
7973 if (selection_count == 0
7974 && tree_view->priv->selection->type != PSPP_SHEET_SELECTION_NONE
7975 && !(mode & PSPP_SHEET_SELECT_MODE_TOGGLE))
7977 /* Don't move the cursor, but just select the current node */
7978 new_cursor_node = cursor_node;
7983 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
7985 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7988 gtk_tree_path_free (cursor_path);
7990 if (new_cursor_node)
7992 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
7994 search_first_focusable_path (tree_view, &cursor_path,
7999 gtk_tree_path_free (cursor_path);
8003 * If the list has only one item and multi-selection is set then select
8004 * the row (if not yet selected).
8006 if ((tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
8007 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE) &&
8008 new_cursor_node < 0)
8011 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
8013 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
8015 if (new_cursor_node < 0
8016 && !pspp_sheet_view_node_is_selected (tree_view, cursor_node))
8018 new_cursor_node = cursor_node;
8022 new_cursor_node = -1;
8026 if (new_cursor_node >= 0)
8028 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
8029 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, TRUE, mode);
8030 gtk_tree_path_free (cursor_path);
8034 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8036 if (!(mode & PSPP_SHEET_SELECT_MODE_EXTEND))
8038 if (! gtk_widget_keynav_failed (GTK_WIDGET (tree_view),
8040 GTK_DIR_UP : GTK_DIR_DOWN))
8042 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
8045 gtk_widget_child_focus (toplevel,
8047 GTK_DIR_TAB_BACKWARD :
8048 GTK_DIR_TAB_FORWARD);
8055 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8060 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8062 return new_cursor_node >= 0;
8066 pspp_sheet_view_move_cursor_page_up_down (PsppSheetView *tree_view,
8068 PsppSheetSelectMode mode)
8070 int cursor_node = -1;
8071 GtkTreePath *old_cursor_path = NULL;
8072 GtkTreePath *cursor_path = NULL;
8073 int start_cursor_node = -1;
8076 gint vertical_separator;
8078 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8081 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8082 old_cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8084 /* This is sorta weird. Focus in should give us a cursor */
8087 gtk_widget_style_get (GTK_WIDGET (tree_view), "vertical-separator", &vertical_separator, NULL);
8088 _pspp_sheet_view_find_node (tree_view, old_cursor_path, &cursor_node);
8090 if (cursor_node < 0)
8092 /* FIXME: we lost the cursor. Should we try to get one? */
8093 gtk_tree_path_free (old_cursor_path);
8097 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
8098 window_y = RBTREE_Y_TO_TREE_WINDOW_Y (tree_view, y);
8099 y += tree_view->priv->cursor_offset;
8100 y += count * (int)gtk_adjustment_get_page_increment (tree_view->priv->vadjustment);
8101 y = CLAMP (y, (gint)gtk_adjustment_get_lower (tree_view->priv->vadjustment), (gint)gtk_adjustment_get_upper (tree_view->priv->vadjustment) - vertical_separator);
8103 if (y >= tree_view->priv->height)
8104 y = tree_view->priv->height - 1;
8106 tree_view->priv->cursor_offset =
8107 pspp_sheet_view_find_offset (tree_view, y, &cursor_node);
8109 if (tree_view->priv->cursor_offset > BACKGROUND_HEIGHT (tree_view))
8111 cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
8112 tree_view->priv->cursor_offset -= BACKGROUND_HEIGHT (tree_view);
8115 y -= tree_view->priv->cursor_offset;
8116 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
8118 start_cursor_node = cursor_node;
8120 if (! search_first_focusable_path (tree_view, &cursor_path,
8124 /* It looks like we reached the end of the view without finding
8125 * a focusable row. We will step backwards to find the last
8128 cursor_node = start_cursor_node;
8129 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
8131 search_first_focusable_path (tree_view, &cursor_path,
8140 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
8142 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE, mode);
8145 pspp_sheet_view_scroll_to_point (tree_view, -1, y);
8146 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8147 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8149 if (!gtk_tree_path_compare (old_cursor_path, cursor_path))
8150 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8152 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8155 gtk_tree_path_free (old_cursor_path);
8156 gtk_tree_path_free (cursor_path);
8160 pspp_sheet_view_move_cursor_left_right (PsppSheetView *tree_view,
8162 PsppSheetSelectMode mode)
8164 int cursor_node = -1;
8165 GtkTreePath *cursor_path = NULL;
8166 PsppSheetViewColumn *column;
8169 gboolean found_column = FALSE;
8172 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8174 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8177 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8178 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8182 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8183 if (cursor_node < 0)
8185 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8187 gtk_tree_path_free (cursor_path);
8190 gtk_tree_path_free (cursor_path);
8192 list = rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns);
8193 if (tree_view->priv->focus_column)
8195 for (; list; list = (rtl ? list->prev : list->next))
8197 if (list->data == tree_view->priv->focus_column)
8204 gboolean left, right;
8206 column = list->data;
8207 if (column->visible == FALSE || column->row_head)
8210 pspp_sheet_view_column_cell_set_cell_data (column,
8211 tree_view->priv->model,
8216 right = list->prev ? TRUE : FALSE;
8217 left = list->next ? TRUE : FALSE;
8221 left = list->prev ? TRUE : FALSE;
8222 right = list->next ? TRUE : FALSE;
8225 if (_pspp_sheet_view_column_cell_focus (column, count, left, right))
8227 tree_view->priv->focus_column = column;
8228 found_column = TRUE;
8233 list = rtl ? list->prev : list->next;
8235 list = rtl ? list->next : list->prev;
8240 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8241 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8242 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8246 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8249 pspp_sheet_view_clamp_column_visible (tree_view,
8250 tree_view->priv->focus_column, TRUE);
8254 pspp_sheet_view_move_cursor_line_start_end (PsppSheetView *tree_view,
8256 PsppSheetSelectMode mode)
8258 int cursor_node = -1;
8259 GtkTreePath *cursor_path = NULL;
8260 PsppSheetViewColumn *column;
8261 PsppSheetViewColumn *found_column;
8266 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8268 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8271 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8272 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8276 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8277 if (cursor_node < 0)
8279 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8281 gtk_tree_path_free (cursor_path);
8284 gtk_tree_path_free (cursor_path);
8286 list = rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns);
8287 if (tree_view->priv->focus_column)
8289 for (; list; list = (rtl ? list->prev : list->next))
8291 if (list->data == tree_view->priv->focus_column)
8296 found_column = NULL;
8299 gboolean left, right;
8301 column = list->data;
8302 if (column->visible == FALSE || column->row_head)
8305 pspp_sheet_view_column_cell_set_cell_data (column,
8306 tree_view->priv->model,
8311 right = list->prev ? TRUE : FALSE;
8312 left = list->next ? TRUE : FALSE;
8316 left = list->prev ? TRUE : FALSE;
8317 right = list->next ? TRUE : FALSE;
8320 if (column->tabbable
8321 && _pspp_sheet_view_column_cell_focus (column, count, left, right))
8322 found_column = column;
8326 list = rtl ? list->prev : list->next;
8328 list = rtl ? list->next : list->prev;
8333 tree_view->priv->focus_column = found_column;
8334 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8335 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8336 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8339 pspp_sheet_view_clamp_column_visible (tree_view,
8340 tree_view->priv->focus_column, TRUE);
8344 try_move_cursor_tab (PsppSheetView *tree_view,
8345 gboolean start_at_focus_column,
8348 PsppSheetViewColumn *column;
8350 int cursor_node = -1;
8351 GtkTreePath *cursor_path = NULL;
8355 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8356 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8360 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8361 if (cursor_node < 0)
8363 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8365 gtk_tree_path_free (cursor_path);
8368 gtk_tree_path_free (cursor_path);
8370 rtl = gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL;
8371 if (start_at_focus_column)
8374 ? g_list_last (tree_view->priv->columns)
8375 : g_list_first (tree_view->priv->columns));
8376 if (tree_view->priv->focus_column)
8378 for (; list; list = (rtl ? list->prev : list->next))
8380 if (list->data == tree_view->priv->focus_column)
8387 list = (rtl ^ (count == 1)
8388 ? g_list_first (tree_view->priv->columns)
8389 : g_list_last (tree_view->priv->columns));
8394 gboolean left, right;
8396 column = list->data;
8397 if (column->visible == FALSE || !column->tabbable)
8400 pspp_sheet_view_column_cell_set_cell_data (column,
8401 tree_view->priv->model,
8406 right = list->prev ? TRUE : FALSE;
8407 left = list->next ? TRUE : FALSE;
8411 left = list->prev ? TRUE : FALSE;
8412 right = list->next ? TRUE : FALSE;
8415 if (column->tabbable
8416 && _pspp_sheet_view_column_cell_focus (column, count, left, right))
8418 tree_view->priv->focus_column = column;
8419 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8420 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8421 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8426 list = rtl ? list->prev : list->next;
8428 list = rtl ? list->next : list->prev;
8435 pspp_sheet_view_move_cursor_tab (PsppSheetView *tree_view,
8438 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8441 if (!try_move_cursor_tab (tree_view, TRUE, count))
8443 if (pspp_sheet_view_move_cursor_up_down (tree_view, count, 0)
8444 && !try_move_cursor_tab (tree_view, FALSE, count))
8445 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8448 pspp_sheet_view_clamp_column_visible (tree_view,
8449 tree_view->priv->focus_column, TRUE);
8453 pspp_sheet_view_move_cursor_start_end (PsppSheetView *tree_view,
8455 PsppSheetSelectMode mode)
8459 GtkTreePath *old_path;
8461 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8464 g_return_if_fail (tree_view->priv->row_count > 0);
8466 pspp_sheet_view_get_cursor (tree_view, &old_path, NULL);
8470 /* Now go forward to find the first focusable row. */
8471 path = _pspp_sheet_view_find_path (tree_view, 0);
8472 search_first_focusable_path (tree_view, &path,
8473 TRUE, &cursor_node);
8477 /* Now go backwards to find last focusable row. */
8478 path = _pspp_sheet_view_find_path (tree_view, tree_view->priv->row_count - 1);
8479 search_first_focusable_path (tree_view, &path,
8480 FALSE, &cursor_node);
8486 if (gtk_tree_path_compare (old_path, path))
8488 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, mode);
8489 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8493 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8497 gtk_tree_path_free (old_path);
8498 gtk_tree_path_free (path);
8502 pspp_sheet_view_real_select_all (PsppSheetView *tree_view)
8504 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8507 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8508 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8511 pspp_sheet_selection_select_all (tree_view->priv->selection);
8517 pspp_sheet_view_real_unselect_all (PsppSheetView *tree_view)
8519 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8522 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8523 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8526 pspp_sheet_selection_unselect_all (tree_view->priv->selection);
8532 pspp_sheet_view_real_select_cursor_row (PsppSheetView *tree_view,
8533 gboolean start_editing,
8534 PsppSheetSelectMode mode)
8537 int cursor_node = -1;
8538 GtkTreePath *cursor_path = NULL;
8540 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8543 if (tree_view->priv->cursor)
8544 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8546 if (cursor_path == NULL)
8549 _pspp_sheet_view_find_node (tree_view, cursor_path,
8552 if (cursor_node < 0)
8554 gtk_tree_path_free (cursor_path);
8558 if (!(mode & PSPP_SHEET_SELECT_MODE_EXTEND) && start_editing &&
8559 tree_view->priv->focus_column)
8561 if (pspp_sheet_view_start_editing (tree_view, cursor_path))
8563 gtk_tree_path_free (cursor_path);
8568 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8574 /* We bail out if the original (tree, node) don't exist anymore after
8575 * handling the selection-changed callback. We do return TRUE because
8576 * the key press has been handled at this point.
8578 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8580 if (cursor_node != new_node)
8583 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8585 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8586 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8588 if (!(mode & PSPP_SHEET_SELECT_MODE_EXTEND))
8589 pspp_sheet_view_row_activated (tree_view, cursor_path,
8590 tree_view->priv->focus_column);
8592 gtk_tree_path_free (cursor_path);
8598 pspp_sheet_view_real_toggle_cursor_row (PsppSheetView *tree_view)
8601 int cursor_node = -1;
8602 GtkTreePath *cursor_path = NULL;
8604 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8608 if (tree_view->priv->cursor)
8609 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8611 if (cursor_path == NULL)
8614 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8615 if (cursor_node < 0)
8617 gtk_tree_path_free (cursor_path);
8621 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8624 PSPP_SHEET_SELECT_MODE_TOGGLE,
8627 /* We bail out if the original (tree, node) don't exist anymore after
8628 * handling the selection-changed callback. We do return TRUE because
8629 * the key press has been handled at this point.
8631 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8633 if (cursor_node != new_node)
8636 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8638 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8639 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
8640 gtk_tree_path_free (cursor_path);
8646 pspp_sheet_view_search_entry_flush_timeout (PsppSheetView *tree_view)
8648 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
8649 tree_view->priv->typeselect_flush_timeout = 0;
8654 /* Cut and paste from gtkwindow.c */
8656 send_focus_change (GtkWidget *widget,
8659 GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
8661 fevent->focus_change.type = GDK_FOCUS_CHANGE;
8662 fevent->focus_change.window = g_object_ref (gtk_widget_get_window (widget));
8663 fevent->focus_change.in = in;
8665 gtk_widget_send_focus_change (widget, fevent);
8666 gdk_event_free (fevent);
8670 pspp_sheet_view_ensure_interactive_directory (PsppSheetView *tree_view)
8672 GtkWidget *frame, *vbox, *toplevel;
8675 if (tree_view->priv->search_custom_entry_set)
8678 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
8679 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
8681 if (tree_view->priv->search_window != NULL)
8683 if (gtk_window_get_group (GTK_WINDOW (toplevel)))
8684 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
8685 GTK_WINDOW (tree_view->priv->search_window));
8686 else if (gtk_window_get_group (GTK_WINDOW (tree_view->priv->search_window)))
8687 gtk_window_group_remove_window (gtk_window_get_group (GTK_WINDOW (tree_view->priv->search_window)),
8688 GTK_WINDOW (tree_view->priv->search_window));
8689 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8693 tree_view->priv->search_window = gtk_window_new (GTK_WINDOW_POPUP);
8694 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8696 if (gtk_window_get_group (GTK_WINDOW (toplevel)))
8697 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
8698 GTK_WINDOW (tree_view->priv->search_window));
8700 gtk_window_set_type_hint (GTK_WINDOW (tree_view->priv->search_window),
8701 GDK_WINDOW_TYPE_HINT_UTILITY);
8702 gtk_window_set_modal (GTK_WINDOW (tree_view->priv->search_window), TRUE);
8703 g_signal_connect (tree_view->priv->search_window, "delete-event",
8704 G_CALLBACK (pspp_sheet_view_search_delete_event),
8706 g_signal_connect (tree_view->priv->search_window, "key-press-event",
8707 G_CALLBACK (pspp_sheet_view_search_key_press_event),
8709 g_signal_connect (tree_view->priv->search_window, "button-press-event",
8710 G_CALLBACK (pspp_sheet_view_search_button_press_event),
8712 g_signal_connect (tree_view->priv->search_window, "scroll-event",
8713 G_CALLBACK (pspp_sheet_view_search_scroll_event),
8716 frame = gtk_frame_new (NULL);
8717 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
8718 gtk_widget_show (frame);
8719 gtk_container_add (GTK_CONTAINER (tree_view->priv->search_window), frame);
8721 vbox = gtk_vbox_new (FALSE, 0);
8722 gtk_widget_show (vbox);
8723 gtk_container_add (GTK_CONTAINER (frame), vbox);
8724 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
8727 tree_view->priv->search_entry = gtk_entry_new ();
8728 gtk_widget_show (tree_view->priv->search_entry);
8729 g_signal_connect (tree_view->priv->search_entry, "populate-popup",
8730 G_CALLBACK (pspp_sheet_view_search_disable_popdown),
8732 g_signal_connect (tree_view->priv->search_entry,
8733 "activate", G_CALLBACK (pspp_sheet_view_search_activate),
8737 g_signal_connect (GTK_ENTRY (tree_view->priv->search_entry)->im_context,
8739 G_CALLBACK (pspp_sheet_view_search_preedit_changed),
8743 gtk_container_add (GTK_CONTAINER (vbox),
8744 tree_view->priv->search_entry);
8746 gtk_widget_realize (tree_view->priv->search_entry);
8749 /* Pops up the interactive search entry. If keybinding is TRUE then the user
8750 * started this by typing the start_interactive_search keybinding. Otherwise, it came from
8753 pspp_sheet_view_real_start_interactive_search (PsppSheetView *tree_view,
8754 gboolean keybinding)
8756 /* We only start interactive search if we have focus or the columns
8757 * have focus. If one of our children have focus, we don't want to
8761 gboolean found_focus = FALSE;
8762 GtkWidgetClass *entry_parent_class;
8764 if (!tree_view->priv->enable_search && !keybinding)
8767 if (tree_view->priv->search_custom_entry_set)
8770 if (tree_view->priv->search_window != NULL &&
8771 gtk_widget_get_visible (tree_view->priv->search_window))
8774 for (list = tree_view->priv->columns; list; list = list->next)
8776 PsppSheetViewColumn *column;
8778 column = list->data;
8779 if (! column->visible)
8782 if (column->button && gtk_widget_has_focus (column->button))
8789 if (gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8795 if (tree_view->priv->search_column < 0)
8798 pspp_sheet_view_ensure_interactive_directory (tree_view);
8801 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
8804 tree_view->priv->search_position_func (tree_view, tree_view->priv->search_window, tree_view->priv->search_position_user_data);
8805 gtk_widget_show (tree_view->priv->search_window);
8806 if (tree_view->priv->search_entry_changed_id == 0)
8808 tree_view->priv->search_entry_changed_id =
8809 g_signal_connect (tree_view->priv->search_entry, "changed",
8810 G_CALLBACK (pspp_sheet_view_search_init),
8814 tree_view->priv->typeselect_flush_timeout =
8815 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
8816 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
8819 /* Grab focus will select all the text. We don't want that to happen, so we
8820 * call the parent instance and bypass the selection change. This is probably
8821 * really non-kosher. */
8822 entry_parent_class = g_type_class_peek_parent (GTK_ENTRY_GET_CLASS (tree_view->priv->search_entry));
8823 (entry_parent_class->grab_focus) (tree_view->priv->search_entry);
8825 /* send focus-in event */
8826 send_focus_change (tree_view->priv->search_entry, TRUE);
8828 /* search first matching iter */
8829 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
8835 pspp_sheet_view_start_interactive_search (PsppSheetView *tree_view)
8837 return pspp_sheet_view_real_start_interactive_search (tree_view, TRUE);
8840 /* this function returns the new width of the column being resized given
8841 * the column and x position of the cursor; the x cursor position is passed
8842 * in as a pointer and automagicly corrected if it's beyond min/max limits
8845 pspp_sheet_view_new_column_width (PsppSheetView *tree_view,
8849 PsppSheetViewColumn *column;
8853 /* first translate the x position from gtk_widget_get_window (widget)
8854 * to clist->clist_window
8856 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8857 column = g_list_nth (tree_view->priv->columns, i)->data;
8858 width = rtl ? (column->allocation.x + column->allocation.width - *x) : (*x - column->allocation.x);
8860 /* Clamp down the value */
8861 if (column->min_width == -1)
8862 width = MAX (column->button_request, width);
8864 width = MAX (column->min_width, width);
8865 if (column->max_width != -1)
8866 width = MIN (width, column->max_width);
8868 *x = rtl ? (column->allocation.x + column->allocation.width - width) : (column->allocation.x + width);
8874 /* FIXME this adjust_allocation is a big cut-and-paste from
8875 * GtkCList, needs to be some "official" way to do this
8885 /* The window to which gtk_widget_get_window (widget) is relative */
8886 #define ALLOCATION_WINDOW(widget) \
8887 (!gtk_widget_get_has_window (widget) ? \
8888 gtk_widget_get_window (widget) : \
8889 gdk_window_get_parent (gtk_widget_get_window (widget)))
8892 adjust_allocation_recurse (GtkWidget *widget,
8895 ScrollData *scroll_data = data;
8896 GtkAllocation allocation;
8897 gtk_widget_get_allocation (widget, &allocation);
8898 /* Need to really size allocate instead of just poking
8899 * into widget->allocation if the widget is not realized.
8900 * FIXME someone figure out why this was.
8902 if (!gtk_widget_get_realized (widget))
8904 if (gtk_widget_get_visible (widget))
8906 GdkRectangle tmp_rectangle = allocation;
8907 tmp_rectangle.x += scroll_data->dx;
8908 tmp_rectangle.y += scroll_data->dy;
8910 gtk_widget_size_allocate (widget, &tmp_rectangle);
8915 if (ALLOCATION_WINDOW (widget) == scroll_data->window)
8917 allocation.x += scroll_data->dx;
8918 allocation.y += scroll_data->dy;
8920 if (GTK_IS_CONTAINER (widget))
8921 gtk_container_forall (GTK_CONTAINER (widget),
8922 adjust_allocation_recurse,
8929 adjust_allocation (GtkWidget *widget,
8933 ScrollData scroll_data;
8935 if (gtk_widget_get_realized (widget))
8936 scroll_data.window = ALLOCATION_WINDOW (widget);
8938 scroll_data.window = NULL;
8940 scroll_data.dx = dx;
8941 scroll_data.dy = dy;
8943 adjust_allocation_recurse (widget, &scroll_data);
8947 pspp_sheet_view_column_update_button (PsppSheetViewColumn *tree_column);
8951 pspp_sheet_view_adjustment_changed (GtkAdjustment *adjustment,
8952 PsppSheetView *tree_view)
8954 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
8959 gdk_window_move (tree_view->priv->bin_window,
8960 - gtk_adjustment_get_value (tree_view->priv->hadjustment),
8961 TREE_VIEW_HEADER_HEIGHT (tree_view));
8962 gdk_window_move (tree_view->priv->header_window,
8963 - gtk_adjustment_get_value (tree_view->priv->hadjustment),
8965 dy = tree_view->priv->dy - (int) gtk_adjustment_get_value (tree_view->priv->vadjustment);
8968 update_prelight (tree_view,
8969 tree_view->priv->event_last_x,
8970 tree_view->priv->event_last_y - dy);
8972 if (tree_view->priv->edited_column &&
8973 GTK_IS_WIDGET (tree_view->priv->edited_column->editable_widget))
8977 PsppSheetViewChild *child = NULL;
8979 widget = GTK_WIDGET (tree_view->priv->edited_column->editable_widget);
8980 adjust_allocation (widget, 0, dy);
8982 for (list = tree_view->priv->children; list; list = list->next)
8984 child = (PsppSheetViewChild *)list->data;
8985 if (child->widget == widget)
8993 gdk_window_scroll (tree_view->priv->bin_window, 0, dy);
8995 if (tree_view->priv->dy != (int) gtk_adjustment_get_value (tree_view->priv->vadjustment))
8997 /* update our dy and top_row */
8998 tree_view->priv->dy = (int) gtk_adjustment_get_value (tree_view->priv->vadjustment);
9000 if (!tree_view->priv->in_top_row_to_dy)
9001 pspp_sheet_view_dy_to_top_row (tree_view);
9004 for (list = tree_view->priv->columns; list; list = list->next)
9006 PsppSheetViewColumn *column = list->data;
9007 GtkAllocation *col_allocation = &column->allocation;
9008 GtkAllocation widget_allocation;
9009 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &widget_allocation);
9011 if (span_intersects (col_allocation->x, col_allocation->width,
9012 gtk_adjustment_get_value (tree_view->priv->hadjustment),
9013 widget_allocation.width))
9015 pspp_sheet_view_column_set_need_button (column, TRUE);
9016 if (!column->button)
9017 pspp_sheet_view_column_update_button (column);
9029 * pspp_sheet_view_new:
9031 * Creates a new #PsppSheetView widget.
9033 * Return value: A newly created #PsppSheetView widget.
9036 pspp_sheet_view_new (void)
9038 return g_object_new (PSPP_TYPE_SHEET_VIEW, NULL);
9042 * pspp_sheet_view_new_with_model:
9043 * @model: the model.
9045 * Creates a new #PsppSheetView widget with the model initialized to @model.
9047 * Return value: A newly created #PsppSheetView widget.
9050 pspp_sheet_view_new_with_model (GtkTreeModel *model)
9052 return g_object_new (PSPP_TYPE_SHEET_VIEW, "model", model, NULL);
9059 * pspp_sheet_view_get_model:
9060 * @tree_view: a #PsppSheetView
9062 * Returns the model the #PsppSheetView is based on. Returns %NULL if the
9065 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
9068 pspp_sheet_view_get_model (PsppSheetView *tree_view)
9070 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9072 return tree_view->priv->model;
9076 * pspp_sheet_view_set_model:
9077 * @tree_view: A #GtkTreeNode.
9078 * @model: (allow-none): The model.
9080 * Sets the model for a #PsppSheetView. If the @tree_view already has a model
9081 * set, it will remove it before setting the new model. If @model is %NULL,
9082 * then it will unset the old model.
9085 pspp_sheet_view_set_model (PsppSheetView *tree_view,
9086 GtkTreeModel *model)
9088 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9089 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
9091 if (model == tree_view->priv->model)
9094 if (tree_view->priv->scroll_to_path)
9096 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9097 tree_view->priv->scroll_to_path = NULL;
9100 if (tree_view->priv->model)
9102 GList *tmplist = tree_view->priv->columns;
9104 if (tree_view->priv->selected)
9105 range_tower_set0 (tree_view->priv->selected, 0, ULONG_MAX);
9106 pspp_sheet_view_stop_editing (tree_view, TRUE);
9108 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9109 pspp_sheet_view_row_changed,
9111 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9112 pspp_sheet_view_row_inserted,
9114 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9115 pspp_sheet_view_row_deleted,
9117 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9118 pspp_sheet_view_rows_reordered,
9121 for (; tmplist; tmplist = tmplist->next)
9122 _pspp_sheet_view_column_unset_model (tmplist->data,
9123 tree_view->priv->model);
9125 tree_view->priv->prelight_node = -1;
9127 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
9128 tree_view->priv->drag_dest_row = NULL;
9129 gtk_tree_row_reference_free (tree_view->priv->cursor);
9130 tree_view->priv->cursor = NULL;
9131 gtk_tree_row_reference_free (tree_view->priv->anchor);
9132 tree_view->priv->anchor = NULL;
9133 gtk_tree_row_reference_free (tree_view->priv->top_row);
9134 tree_view->priv->top_row = NULL;
9135 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9136 tree_view->priv->scroll_to_path = NULL;
9138 tree_view->priv->scroll_to_column = NULL;
9140 g_object_unref (tree_view->priv->model);
9142 tree_view->priv->search_column = -1;
9143 tree_view->priv->fixed_height = -1;
9144 tree_view->priv->dy = tree_view->priv->top_row_dy = 0;
9145 tree_view->priv->last_button_x = -1;
9146 tree_view->priv->last_button_y = -1;
9149 tree_view->priv->model = model;
9151 if (tree_view->priv->model)
9155 if (tree_view->priv->search_column == -1)
9157 for (i = 0; i < gtk_tree_model_get_n_columns (model); i++)
9159 GType type = gtk_tree_model_get_column_type (model, i);
9161 if (g_value_type_transformable (type, G_TYPE_STRING))
9163 tree_view->priv->search_column = i;
9169 g_object_ref (tree_view->priv->model);
9170 g_signal_connect (tree_view->priv->model,
9172 G_CALLBACK (pspp_sheet_view_row_changed),
9174 g_signal_connect (tree_view->priv->model,
9176 G_CALLBACK (pspp_sheet_view_row_inserted),
9178 g_signal_connect (tree_view->priv->model,
9180 G_CALLBACK (pspp_sheet_view_row_deleted),
9182 g_signal_connect (tree_view->priv->model,
9184 G_CALLBACK (pspp_sheet_view_rows_reordered),
9187 tree_view->priv->row_count = gtk_tree_model_iter_n_children (tree_view->priv->model, NULL);
9189 /* FIXME: do I need to do this? pspp_sheet_view_create_buttons (tree_view); */
9190 install_presize_handler (tree_view);
9193 g_object_notify (G_OBJECT (tree_view), "model");
9195 if (tree_view->priv->selection)
9196 _pspp_sheet_selection_emit_changed (tree_view->priv->selection);
9198 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9199 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9203 * pspp_sheet_view_get_selection:
9204 * @tree_view: A #PsppSheetView.
9206 * Gets the #PsppSheetSelection associated with @tree_view.
9208 * Return value: A #PsppSheetSelection object.
9210 PsppSheetSelection *
9211 pspp_sheet_view_get_selection (PsppSheetView *tree_view)
9213 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9215 return tree_view->priv->selection;
9219 * pspp_sheet_view_get_hadjustment:
9220 * @tree_view: A #PsppSheetView
9222 * Gets the #GtkAdjustment currently being used for the horizontal aspect.
9224 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
9228 pspp_sheet_view_get_hadjustment (PsppSheetView *tree_view)
9230 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9232 if (tree_view->priv->hadjustment == NULL)
9233 pspp_sheet_view_set_hadjustment (tree_view, NULL);
9235 return tree_view->priv->hadjustment;
9239 * pspp_sheet_view_set_hadjustment:
9240 * @tree_view: A #PsppSheetView
9241 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
9243 * Sets the #GtkAdjustment for the current horizontal aspect.
9246 pspp_sheet_view_set_hadjustment (PsppSheetView *tree_view,
9247 GtkAdjustment *adjustment)
9249 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9251 pspp_sheet_view_set_adjustments (tree_view,
9253 tree_view->priv->vadjustment);
9255 g_object_notify (G_OBJECT (tree_view), "hadjustment");
9259 * pspp_sheet_view_get_vadjustment:
9260 * @tree_view: A #PsppSheetView
9262 * Gets the #GtkAdjustment currently being used for the vertical aspect.
9264 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
9268 pspp_sheet_view_get_vadjustment (PsppSheetView *tree_view)
9270 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9272 if (tree_view->priv->vadjustment == NULL)
9273 pspp_sheet_view_set_vadjustment (tree_view, NULL);
9275 return tree_view->priv->vadjustment;
9279 * pspp_sheet_view_set_vadjustment:
9280 * @tree_view: A #PsppSheetView
9281 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
9283 * Sets the #GtkAdjustment for the current vertical aspect.
9286 pspp_sheet_view_set_vadjustment (PsppSheetView *tree_view,
9287 GtkAdjustment *adjustment)
9289 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9291 pspp_sheet_view_set_adjustments (tree_view,
9292 tree_view->priv->hadjustment,
9295 g_object_notify (G_OBJECT (tree_view), "vadjustment");
9298 /* Column and header operations */
9301 * pspp_sheet_view_get_headers_visible:
9302 * @tree_view: A #PsppSheetView.
9304 * Returns %TRUE if the headers on the @tree_view are visible.
9306 * Return value: Whether the headers are visible or not.
9309 pspp_sheet_view_get_headers_visible (PsppSheetView *tree_view)
9311 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9313 return PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9317 * pspp_sheet_view_set_headers_visible:
9318 * @tree_view: A #PsppSheetView.
9319 * @headers_visible: %TRUE if the headers are visible
9321 * Sets the visibility state of the headers.
9324 pspp_sheet_view_set_headers_visible (PsppSheetView *tree_view,
9325 gboolean headers_visible)
9329 PsppSheetViewColumn *column;
9330 GtkAllocation allocation;
9332 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9334 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
9336 headers_visible = !! headers_visible;
9338 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE) == headers_visible)
9341 if (headers_visible)
9342 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9344 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9346 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9348 gdk_window_get_position (tree_view->priv->bin_window, &x, &y);
9349 if (headers_visible)
9351 gdk_window_move_resize (tree_view->priv->bin_window, x, y + TREE_VIEW_HEADER_HEIGHT (tree_view),
9352 tree_view->priv->width, allocation.height - + TREE_VIEW_HEADER_HEIGHT (tree_view));
9354 if (gtk_widget_get_mapped (GTK_WIDGET (tree_view)))
9355 pspp_sheet_view_map_buttons (tree_view);
9359 gdk_window_move_resize (tree_view->priv->bin_window, x, y, tree_view->priv->width, tree_view->priv->height);
9361 for (list = tree_view->priv->columns; list; list = list->next)
9363 column = list->data;
9365 gtk_widget_unmap (column->button);
9367 gdk_window_hide (tree_view->priv->header_window);
9371 gtk_adjustment_set_page_size (tree_view->priv->vadjustment, allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view));
9372 gtk_adjustment_set_page_increment (tree_view->priv->vadjustment, (allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view)) / 2);
9373 gtk_adjustment_set_lower (tree_view->priv->vadjustment, 0);
9374 gtk_adjustment_set_upper (tree_view->priv->vadjustment, tree_view->priv->height);
9375 gtk_adjustment_changed (tree_view->priv->vadjustment);
9377 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9379 g_object_notify (G_OBJECT (tree_view), "headers-visible");
9383 * pspp_sheet_view_columns_autosize:
9384 * @tree_view: A #PsppSheetView.
9386 * Resizes all columns to their optimal width. Only works after the
9387 * treeview has been realized.
9390 pspp_sheet_view_columns_autosize (PsppSheetView *tree_view)
9392 gboolean dirty = FALSE;
9394 PsppSheetViewColumn *column;
9396 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9398 for (list = tree_view->priv->columns; list; list = list->next)
9400 column = list->data;
9401 _pspp_sheet_view_column_cell_set_dirty (column);
9406 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9410 * pspp_sheet_view_set_headers_clickable:
9411 * @tree_view: A #PsppSheetView.
9412 * @setting: %TRUE if the columns are clickable.
9414 * Allow the column title buttons to be clicked.
9417 pspp_sheet_view_set_headers_clickable (PsppSheetView *tree_view,
9422 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9424 for (list = tree_view->priv->columns; list; list = list->next)
9425 pspp_sheet_view_column_set_clickable (PSPP_SHEET_VIEW_COLUMN (list->data), setting);
9427 g_object_notify (G_OBJECT (tree_view), "headers-clickable");
9432 * pspp_sheet_view_get_headers_clickable:
9433 * @tree_view: A #PsppSheetView.
9435 * Returns whether all header columns are clickable.
9437 * Return value: %TRUE if all header columns are clickable, otherwise %FALSE
9442 pspp_sheet_view_get_headers_clickable (PsppSheetView *tree_view)
9446 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9448 for (list = tree_view->priv->columns; list; list = list->next)
9449 if (!PSPP_SHEET_VIEW_COLUMN (list->data)->clickable)
9456 * pspp_sheet_view_set_rules_hint
9457 * @tree_view: a #PsppSheetView
9458 * @setting: %TRUE if the tree requires reading across rows
9460 * This function tells GTK+ that the user interface for your
9461 * application requires users to read across tree rows and associate
9462 * cells with one another. By default, GTK+ will then render the tree
9463 * with alternating row colors. Do <emphasis>not</emphasis> use it
9464 * just because you prefer the appearance of the ruled tree; that's a
9465 * question for the theme. Some themes will draw tree rows in
9466 * alternating colors even when rules are turned off, and users who
9467 * prefer that appearance all the time can choose those themes. You
9468 * should call this function only as a <emphasis>semantic</emphasis>
9469 * hint to the theme engine that your tree makes alternating colors
9470 * useful from a functional standpoint (since it has lots of columns,
9475 pspp_sheet_view_set_rules_hint (PsppSheetView *tree_view,
9478 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9480 setting = setting != FALSE;
9482 if (tree_view->priv->has_rules != setting)
9484 tree_view->priv->has_rules = setting;
9485 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
9488 g_object_notify (G_OBJECT (tree_view), "rules-hint");
9492 * pspp_sheet_view_get_rules_hint
9493 * @tree_view: a #PsppSheetView
9495 * Gets the setting set by pspp_sheet_view_set_rules_hint().
9497 * Return value: %TRUE if rules are useful for the user of this tree
9500 pspp_sheet_view_get_rules_hint (PsppSheetView *tree_view)
9502 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9504 return tree_view->priv->has_rules;
9507 /* Public Column functions
9511 * pspp_sheet_view_append_column:
9512 * @tree_view: A #PsppSheetView.
9513 * @column: The #PsppSheetViewColumn to add.
9515 * Appends @column to the list of columns.
9517 * Return value: The number of columns in @tree_view after appending.
9520 pspp_sheet_view_append_column (PsppSheetView *tree_view,
9521 PsppSheetViewColumn *column)
9523 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9524 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9525 g_return_val_if_fail (column->tree_view == NULL, -1);
9527 return pspp_sheet_view_insert_column (tree_view, column, -1);
9532 * pspp_sheet_view_remove_column:
9533 * @tree_view: A #PsppSheetView.
9534 * @column: The #PsppSheetViewColumn to remove.
9536 * Removes @column from @tree_view.
9538 * Return value: The number of columns in @tree_view after removing.
9541 pspp_sheet_view_remove_column (PsppSheetView *tree_view,
9542 PsppSheetViewColumn *column)
9544 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9545 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9546 g_return_val_if_fail (column->tree_view == GTK_WIDGET (tree_view), -1);
9548 if (tree_view->priv->focus_column == column)
9549 tree_view->priv->focus_column = NULL;
9551 if (tree_view->priv->edited_column == column)
9553 pspp_sheet_view_stop_editing (tree_view, TRUE);
9555 /* no need to, but just to be sure ... */
9556 tree_view->priv->edited_column = NULL;
9559 _pspp_sheet_view_column_unset_tree_view (column);
9561 tree_view->priv->columns = g_list_remove (tree_view->priv->columns, column);
9562 tree_view->priv->n_columns--;
9564 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9568 _pspp_sheet_view_column_unrealize_button (column);
9569 for (list = tree_view->priv->columns; list; list = list->next)
9571 PsppSheetViewColumn *tmp_column;
9573 tmp_column = PSPP_SHEET_VIEW_COLUMN (list->data);
9574 if (tmp_column->visible)
9575 _pspp_sheet_view_column_cell_set_dirty (tmp_column);
9578 if (tree_view->priv->n_columns == 0 &&
9579 pspp_sheet_view_get_headers_visible (tree_view) &&
9580 tree_view->priv->header_window)
9581 gdk_window_hide (tree_view->priv->header_window);
9583 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9586 g_object_unref (column);
9587 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9589 return tree_view->priv->n_columns;
9593 * pspp_sheet_view_insert_column:
9594 * @tree_view: A #PsppSheetView.
9595 * @column: The #PsppSheetViewColumn to be inserted.
9596 * @position: The position to insert @column in.
9598 * This inserts the @column into the @tree_view at @position. If @position is
9599 * -1, then the column is inserted at the end.
9601 * Return value: The number of columns in @tree_view after insertion.
9604 pspp_sheet_view_insert_column (PsppSheetView *tree_view,
9605 PsppSheetViewColumn *column,
9608 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9609 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9610 g_return_val_if_fail (column->tree_view == NULL, -1);
9612 g_object_ref_sink (column);
9614 if (tree_view->priv->n_columns == 0 &&
9615 gtk_widget_get_realized (GTK_WIDGET (tree_view)) &&
9616 pspp_sheet_view_get_headers_visible (tree_view))
9618 gdk_window_show (tree_view->priv->header_window);
9621 tree_view->priv->columns = g_list_insert (tree_view->priv->columns,
9623 tree_view->priv->n_columns++;
9625 _pspp_sheet_view_column_set_tree_view (column, tree_view);
9627 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9631 _pspp_sheet_view_column_realize_button (column);
9633 for (list = tree_view->priv->columns; list; list = list->next)
9635 column = PSPP_SHEET_VIEW_COLUMN (list->data);
9636 if (column->visible)
9637 _pspp_sheet_view_column_cell_set_dirty (column);
9639 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9642 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9644 return tree_view->priv->n_columns;
9648 * pspp_sheet_view_insert_column_with_attributes:
9649 * @tree_view: A #PsppSheetView
9650 * @position: The position to insert the new column in.
9651 * @title: The title to set the header to.
9652 * @cell: The #GtkCellRenderer.
9653 * @Varargs: A %NULL-terminated list of attributes.
9655 * Creates a new #PsppSheetViewColumn and inserts it into the @tree_view at
9656 * @position. If @position is -1, then the newly created column is inserted at
9657 * the end. The column is initialized with the attributes given.
9659 * Return value: The number of columns in @tree_view after insertion.
9662 pspp_sheet_view_insert_column_with_attributes (PsppSheetView *tree_view,
9665 GtkCellRenderer *cell,
9668 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);
9679 va_start (args, cell);
9681 attribute = va_arg (args, gchar *);
9683 while (attribute != NULL)
9685 column_id = va_arg (args, gint);
9686 pspp_sheet_view_column_add_attribute (column, cell, attribute, column_id);
9687 attribute = va_arg (args, gchar *);
9692 pspp_sheet_view_insert_column (tree_view, column, position);
9694 return tree_view->priv->n_columns;
9698 * pspp_sheet_view_insert_column_with_data_func:
9699 * @tree_view: a #PsppSheetView
9700 * @position: Position to insert, -1 for append
9701 * @title: column title
9702 * @cell: cell renderer for column
9703 * @func: function to set attributes of cell renderer
9704 * @data: data for @func
9705 * @dnotify: destroy notifier for @data
9707 * Convenience function that inserts a new column into the #PsppSheetView
9708 * with the given cell renderer and a #GtkCellDataFunc to set cell renderer
9709 * attributes (normally using data from the model). See also
9710 * pspp_sheet_view_column_set_cell_data_func(), pspp_sheet_view_column_pack_start().
9712 * Return value: number of columns in the tree view post-insert
9715 pspp_sheet_view_insert_column_with_data_func (PsppSheetView *tree_view,
9718 GtkCellRenderer *cell,
9719 PsppSheetCellDataFunc func,
9721 GDestroyNotify dnotify)
9723 PsppSheetViewColumn *column;
9725 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9727 column = pspp_sheet_view_column_new ();
9728 pspp_sheet_view_column_set_title (column, title);
9729 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9730 pspp_sheet_view_column_set_cell_data_func (column, cell, func, data, dnotify);
9732 pspp_sheet_view_insert_column (tree_view, column, position);
9734 return tree_view->priv->n_columns;
9738 * pspp_sheet_view_get_column:
9739 * @tree_view: A #PsppSheetView.
9740 * @n: The position of the column, counting from 0.
9742 * Gets the #PsppSheetViewColumn at the given position in the #tree_view.
9744 * Return value: The #PsppSheetViewColumn, or %NULL if the position is outside the
9747 PsppSheetViewColumn *
9748 pspp_sheet_view_get_column (PsppSheetView *tree_view,
9751 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9753 if (n < 0 || n >= tree_view->priv->n_columns)
9756 if (tree_view->priv->columns == NULL)
9759 return PSPP_SHEET_VIEW_COLUMN (g_list_nth (tree_view->priv->columns, n)->data);
9763 * pspp_sheet_view_get_columns:
9764 * @tree_view: A #PsppSheetView
9766 * Returns a #GList of all the #PsppSheetViewColumn s currently in @tree_view.
9767 * The returned list must be freed with g_list_free ().
9769 * Return value: (element-type PsppSheetViewColumn) (transfer container): A list of #PsppSheetViewColumn s
9772 pspp_sheet_view_get_columns (PsppSheetView *tree_view)
9774 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9776 return g_list_copy (tree_view->priv->columns);
9780 * pspp_sheet_view_move_column_after:
9781 * @tree_view: A #PsppSheetView
9782 * @column: The #PsppSheetViewColumn to be moved.
9783 * @base_column: (allow-none): The #PsppSheetViewColumn to be moved relative to, or %NULL.
9785 * Moves @column to be after to @base_column. If @base_column is %NULL, then
9786 * @column is placed in the first position.
9789 pspp_sheet_view_move_column_after (PsppSheetView *tree_view,
9790 PsppSheetViewColumn *column,
9791 PsppSheetViewColumn *base_column)
9793 GList *column_list_el, *base_el = NULL;
9795 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9797 column_list_el = g_list_find (tree_view->priv->columns, column);
9798 g_return_if_fail (column_list_el != NULL);
9802 base_el = g_list_find (tree_view->priv->columns, base_column);
9803 g_return_if_fail (base_el != NULL);
9806 if (column_list_el->prev == base_el)
9809 tree_view->priv->columns = g_list_remove_link (tree_view->priv->columns, column_list_el);
9810 if (base_el == NULL)
9812 column_list_el->prev = NULL;
9813 column_list_el->next = tree_view->priv->columns;
9814 if (column_list_el->next)
9815 column_list_el->next->prev = column_list_el;
9816 tree_view->priv->columns = column_list_el;
9820 column_list_el->prev = base_el;
9821 column_list_el->next = base_el->next;
9822 if (column_list_el->next)
9823 column_list_el->next->prev = column_list_el;
9824 base_el->next = column_list_el;
9827 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9829 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9830 pspp_sheet_view_size_allocate_columns (GTK_WIDGET (tree_view), NULL);
9833 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9837 * pspp_sheet_view_set_column_drag_function:
9838 * @tree_view: A #PsppSheetView.
9839 * @func: (allow-none): A function to determine which columns are reorderable, or %NULL.
9840 * @user_data: (allow-none): User data to be passed to @func, or %NULL
9841 * @destroy: (allow-none): Destroy notifier for @user_data, or %NULL
9843 * Sets a user function for determining where a column may be dropped when
9844 * dragged. This function is called on every column pair in turn at the
9845 * beginning of a column drag to determine where a drop can take place. The
9846 * arguments passed to @func are: the @tree_view, the #PsppSheetViewColumn being
9847 * dragged, the two #PsppSheetViewColumn s determining the drop spot, and
9848 * @user_data. If either of the #PsppSheetViewColumn arguments for the drop spot
9849 * are %NULL, then they indicate an edge. If @func is set to be %NULL, then
9850 * @tree_view reverts to the default behavior of allowing all columns to be
9851 * dropped everywhere.
9854 pspp_sheet_view_set_column_drag_function (PsppSheetView *tree_view,
9855 PsppSheetViewColumnDropFunc func,
9857 GDestroyNotify destroy)
9859 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9861 if (tree_view->priv->column_drop_func_data_destroy)
9862 tree_view->priv->column_drop_func_data_destroy (tree_view->priv->column_drop_func_data);
9864 tree_view->priv->column_drop_func = func;
9865 tree_view->priv->column_drop_func_data = user_data;
9866 tree_view->priv->column_drop_func_data_destroy = destroy;
9870 * pspp_sheet_view_scroll_to_point:
9871 * @tree_view: a #PsppSheetView
9872 * @tree_x: X coordinate of new top-left pixel of visible area, or -1
9873 * @tree_y: Y coordinate of new top-left pixel of visible area, or -1
9875 * Scrolls the tree view such that the top-left corner of the visible
9876 * area is @tree_x, @tree_y, where @tree_x and @tree_y are specified
9877 * in tree coordinates. The @tree_view must be realized before
9878 * this function is called. If it isn't, you probably want to be
9879 * using pspp_sheet_view_scroll_to_cell().
9881 * If either @tree_x or @tree_y are -1, then that direction isn't scrolled.
9884 pspp_sheet_view_scroll_to_point (PsppSheetView *tree_view,
9888 GtkAdjustment *hadj;
9889 GtkAdjustment *vadj;
9891 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9892 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
9894 hadj = tree_view->priv->hadjustment;
9895 vadj = tree_view->priv->vadjustment;
9898 gtk_adjustment_set_value (hadj, CLAMP (tree_x, gtk_adjustment_get_lower (hadj), gtk_adjustment_get_upper (hadj) - gtk_adjustment_get_page_size (hadj)));
9900 gtk_adjustment_set_value (vadj, CLAMP (tree_y, gtk_adjustment_get_lower (vadj), gtk_adjustment_get_upper (vadj) - gtk_adjustment_get_page_size (vadj)));
9904 * pspp_sheet_view_scroll_to_cell:
9905 * @tree_view: A #PsppSheetView.
9906 * @path: (allow-none): The path of the row to move to, or %NULL.
9907 * @column: (allow-none): The #PsppSheetViewColumn to move horizontally to, or %NULL.
9908 * @use_align: whether to use alignment arguments, or %FALSE.
9909 * @row_align: The vertical alignment of the row specified by @path.
9910 * @col_align: The horizontal alignment of the column specified by @column.
9912 * Moves the alignments of @tree_view to the position specified by @column and
9913 * @path. If @column is %NULL, then no horizontal scrolling occurs. Likewise,
9914 * if @path is %NULL no vertical scrolling occurs. At a minimum, one of @column
9915 * or @path need to be non-%NULL. @row_align determines where the row is
9916 * placed, and @col_align determines where @column is placed. Both are expected
9917 * to be between 0.0 and 1.0. 0.0 means left/top alignment, 1.0 means
9918 * right/bottom alignment, 0.5 means center.
9920 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
9921 * tree does the minimum amount of work to scroll the cell onto the screen.
9922 * This means that the cell will be scrolled to the edge closest to its current
9923 * position. If the cell is currently visible on the screen, nothing is done.
9925 * This function only works if the model is set, and @path is a valid row on the
9926 * model. If the model changes before the @tree_view is realized, the centered
9927 * path will be modified to reflect this change.
9930 pspp_sheet_view_scroll_to_cell (PsppSheetView *tree_view,
9932 PsppSheetViewColumn *column,
9937 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9938 g_return_if_fail (tree_view->priv->model != NULL);
9939 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
9940 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
9941 g_return_if_fail (path != NULL || column != NULL);
9944 g_print ("pspp_sheet_view_scroll_to_cell:\npath: %s\ncolumn: %s\nuse_align: %d\nrow_align: %f\ncol_align: %f\n",
9945 gtk_tree_path_to_string (path), column?"non-null":"null", use_align, row_align, col_align);
9947 row_align = CLAMP (row_align, 0.0, 1.0);
9948 col_align = CLAMP (col_align, 0.0, 1.0);
9951 /* Note: Despite the benefits that come from having one code path for the
9952 * scrolling code, we short-circuit validate_visible_area's immplementation as
9953 * it is much slower than just going to the point.
9955 if (!gtk_widget_get_visible (GTK_WIDGET (tree_view)) ||
9956 !gtk_widget_get_realized (GTK_WIDGET (tree_view))
9957 /* XXX || GTK_WIDGET_ALLOC_NEEDED (tree_view) */)
9959 if (tree_view->priv->scroll_to_path)
9960 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9962 tree_view->priv->scroll_to_path = NULL;
9963 tree_view->priv->scroll_to_column = NULL;
9966 tree_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
9968 tree_view->priv->scroll_to_column = column;
9969 tree_view->priv->scroll_to_use_align = use_align;
9970 tree_view->priv->scroll_to_row_align = row_align;
9971 tree_view->priv->scroll_to_col_align = col_align;
9973 install_presize_handler (tree_view);
9977 GdkRectangle cell_rect;
9978 GdkRectangle vis_rect;
9979 gint dest_x, dest_y;
9981 pspp_sheet_view_get_background_area (tree_view, path, column, &cell_rect);
9982 pspp_sheet_view_get_visible_rect (tree_view, &vis_rect);
9984 cell_rect.y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, cell_rect.y);
9986 dest_x = vis_rect.x;
9987 dest_y = vis_rect.y;
9993 dest_x = cell_rect.x - ((vis_rect.width - cell_rect.width) * col_align);
9997 if (cell_rect.x < vis_rect.x)
9998 dest_x = cell_rect.x;
9999 if (cell_rect.x + cell_rect.width > vis_rect.x + vis_rect.width)
10000 dest_x = cell_rect.x + cell_rect.width - vis_rect.width;
10008 dest_y = cell_rect.y - ((vis_rect.height - cell_rect.height) * row_align);
10009 dest_y = MAX (dest_y, 0);
10013 if (cell_rect.y < vis_rect.y)
10014 dest_y = cell_rect.y;
10015 if (cell_rect.y + cell_rect.height > vis_rect.y + vis_rect.height)
10016 dest_y = cell_rect.y + cell_rect.height - vis_rect.height;
10020 pspp_sheet_view_scroll_to_point (tree_view, dest_x, dest_y);
10025 * pspp_sheet_view_row_activated:
10026 * @tree_view: A #PsppSheetView
10027 * @path: The #GtkTreePath to be activated.
10028 * @column: The #PsppSheetViewColumn to be activated.
10030 * Activates the cell determined by @path and @column.
10033 pspp_sheet_view_row_activated (PsppSheetView *tree_view,
10035 PsppSheetViewColumn *column)
10037 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10039 g_signal_emit (tree_view, tree_view_signals[ROW_ACTIVATED], 0, path, column);
10044 * pspp_sheet_view_get_reorderable:
10045 * @tree_view: a #PsppSheetView
10047 * Retrieves whether the user can reorder the tree via drag-and-drop. See
10048 * pspp_sheet_view_set_reorderable().
10050 * Return value: %TRUE if the tree can be reordered.
10053 pspp_sheet_view_get_reorderable (PsppSheetView *tree_view)
10055 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
10057 return tree_view->priv->reorderable;
10061 * pspp_sheet_view_set_reorderable:
10062 * @tree_view: A #PsppSheetView.
10063 * @reorderable: %TRUE, if the tree can be reordered.
10065 * This function is a convenience function to allow you to reorder
10066 * models that support the #GtkDragSourceIface and the
10067 * #GtkDragDestIface. Both #GtkTreeStore and #GtkListStore support
10068 * these. If @reorderable is %TRUE, then the user can reorder the
10069 * model by dragging and dropping rows. The developer can listen to
10070 * these changes by connecting to the model's row_inserted and
10071 * row_deleted signals. The reordering is implemented by setting up
10072 * the tree view as a drag source and destination. Therefore, drag and
10073 * drop can not be used in a reorderable view for any other purpose.
10075 * This function does not give you any degree of control over the order -- any
10076 * reordering is allowed. If more control is needed, you should probably
10077 * handle drag and drop manually.
10080 pspp_sheet_view_set_reorderable (PsppSheetView *tree_view,
10081 gboolean reorderable)
10083 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10085 reorderable = reorderable != FALSE;
10087 if (tree_view->priv->reorderable == reorderable)
10092 const GtkTargetEntry row_targets[] = {
10093 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
10096 pspp_sheet_view_enable_model_drag_source (tree_view,
10099 G_N_ELEMENTS (row_targets),
10101 pspp_sheet_view_enable_model_drag_dest (tree_view,
10103 G_N_ELEMENTS (row_targets),
10108 pspp_sheet_view_unset_rows_drag_source (tree_view);
10109 pspp_sheet_view_unset_rows_drag_dest (tree_view);
10112 tree_view->priv->reorderable = reorderable;
10114 g_object_notify (G_OBJECT (tree_view), "reorderable");
10117 /* If CLEAR_AND_SELECT is true, then the row will be selected and, unless Shift
10118 is pressed, other rows will be unselected.
10120 If CLAMP_NODE is true, then the sheetview will scroll to make the row
10123 pspp_sheet_view_real_set_cursor (PsppSheetView *tree_view,
10125 gboolean clear_and_select,
10126 gboolean clamp_node,
10127 PsppSheetSelectMode mode)
10131 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
10133 GtkTreePath *cursor_path;
10134 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
10135 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
10136 gtk_tree_path_free (cursor_path);
10139 gtk_tree_row_reference_free (tree_view->priv->cursor);
10140 tree_view->priv->cursor = NULL;
10142 _pspp_sheet_view_find_node (tree_view, path, &node);
10143 tree_view->priv->cursor =
10144 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
10145 tree_view->priv->model,
10148 if (tree_view->priv->row_count > 0)
10152 if (clear_and_select && !(mode & PSPP_SHEET_SELECT_MODE_TOGGLE))
10153 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
10157 /* We have to re-find tree and node here again, somebody might have
10158 * cleared the node or the whole tree in the PsppSheetSelection::changed
10159 * callback. If the nodes differ we bail out here.
10161 _pspp_sheet_view_find_node (tree_view, path, &new_node);
10163 if (node != new_node)
10168 pspp_sheet_view_clamp_node_visible (tree_view, node);
10169 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
10173 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
10177 * pspp_sheet_view_get_cursor:
10178 * @tree_view: A #PsppSheetView
10179 * @path: (allow-none): A pointer to be filled with the current cursor path, or %NULL
10180 * @focus_column: (allow-none): A pointer to be filled with the current focus column, or %NULL
10182 * Fills in @path and @focus_column with the current path and focus column. If
10183 * the cursor isn't currently set, then *@path will be %NULL. If no column
10184 * currently has focus, then *@focus_column will be %NULL.
10186 * The returned #GtkTreePath must be freed with gtk_tree_path_free() when
10187 * you are done with it.
10190 pspp_sheet_view_get_cursor (PsppSheetView *tree_view,
10191 GtkTreePath **path,
10192 PsppSheetViewColumn **focus_column)
10194 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10198 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
10199 *path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
10206 *focus_column = tree_view->priv->focus_column;
10211 * pspp_sheet_view_set_cursor:
10212 * @tree_view: A #PsppSheetView
10213 * @path: A #GtkTreePath
10214 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
10215 * @start_editing: %TRUE if the specified cell should start being edited.
10217 * Sets the current keyboard focus to be at @path, and selects it. This is
10218 * useful when you want to focus the user's attention on a particular row. If
10219 * @focus_column is not %NULL, then focus is given to the column specified by
10220 * it. Additionally, if @focus_column is specified, and @start_editing is
10221 * %TRUE, then editing should be started in the specified cell.
10222 * This function is often followed by @gtk_widget_grab_focus (@tree_view)
10223 * in order to give keyboard focus to the widget. Please note that editing
10224 * can only happen when the widget is realized.
10226 * If @path is invalid for @model, the current cursor (if any) will be unset
10227 * and the function will return without failing.
10230 pspp_sheet_view_set_cursor (PsppSheetView *tree_view,
10232 PsppSheetViewColumn *focus_column,
10233 gboolean start_editing)
10235 pspp_sheet_view_set_cursor_on_cell (tree_view, path, focus_column,
10236 NULL, start_editing);
10240 * pspp_sheet_view_set_cursor_on_cell:
10241 * @tree_view: A #PsppSheetView
10242 * @path: A #GtkTreePath
10243 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
10244 * @focus_cell: (allow-none): A #GtkCellRenderer, or %NULL
10245 * @start_editing: %TRUE if the specified cell should start being edited.
10247 * Sets the current keyboard focus to be at @path, and selects it. This is
10248 * useful when you want to focus the user's attention on a particular row. If
10249 * @focus_column is not %NULL, then focus is given to the column specified by
10250 * it. If @focus_column and @focus_cell are not %NULL, and @focus_column
10251 * contains 2 or more editable or activatable cells, then focus is given to
10252 * the cell specified by @focus_cell. Additionally, if @focus_column is
10253 * specified, and @start_editing is %TRUE, then editing should be started in
10254 * the specified cell. This function is often followed by
10255 * @gtk_widget_grab_focus (@tree_view) in order to give keyboard focus to the
10256 * widget. Please note that editing can only happen when the widget is
10259 * If @path is invalid for @model, the current cursor (if any) will be unset
10260 * and the function will return without failing.
10265 pspp_sheet_view_set_cursor_on_cell (PsppSheetView *tree_view,
10267 PsppSheetViewColumn *focus_column,
10268 GtkCellRenderer *focus_cell,
10269 gboolean start_editing)
10271 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10272 g_return_if_fail (path != NULL);
10273 g_return_if_fail (focus_column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (focus_column));
10275 if (!tree_view->priv->model)
10280 g_return_if_fail (focus_column);
10281 g_return_if_fail (GTK_IS_CELL_RENDERER (focus_cell));
10284 /* cancel the current editing, if it exists */
10285 if (tree_view->priv->edited_column &&
10286 tree_view->priv->edited_column->editable_widget)
10287 pspp_sheet_view_stop_editing (tree_view, TRUE);
10289 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, 0);
10291 if (focus_column && focus_column->visible)
10294 gboolean column_in_tree = FALSE;
10296 for (list = tree_view->priv->columns; list; list = list->next)
10297 if (list->data == focus_column)
10299 column_in_tree = TRUE;
10302 g_return_if_fail (column_in_tree);
10303 tree_view->priv->focus_column = focus_column;
10305 pspp_sheet_view_column_focus_cell (focus_column, focus_cell);
10307 pspp_sheet_view_start_editing (tree_view, path);
10309 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
10310 pspp_sheet_selection_select_column (tree_view->priv->selection, focus_column);
10316 * pspp_sheet_view_get_bin_window:
10317 * @tree_view: A #PsppSheetView
10319 * Returns the window that @tree_view renders to. This is used primarily to
10320 * compare to <literal>event->window</literal> to confirm that the event on
10321 * @tree_view is on the right window.
10323 * Return value: A #GdkWindow, or %NULL when @tree_view hasn't been realized yet
10326 pspp_sheet_view_get_bin_window (PsppSheetView *tree_view)
10328 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
10330 return tree_view->priv->bin_window;
10334 * pspp_sheet_view_get_path_at_pos:
10335 * @tree_view: A #PsppSheetView.
10336 * @x: The x position to be identified (relative to bin_window).
10337 * @y: The y position to be identified (relative to bin_window).
10338 * @path: (out) (allow-none): A pointer to a #GtkTreePath pointer to be filled in, or %NULL
10339 * @column: (out) (allow-none): A pointer to a #PsppSheetViewColumn pointer to be filled in, or %NULL
10340 * @cell_x: (out) (allow-none): A pointer where the X coordinate relative to the cell can be placed, or %NULL
10341 * @cell_y: (out) (allow-none): A pointer where the Y coordinate relative to the cell can be placed, or %NULL
10343 * Finds the path at the point (@x, @y), relative to bin_window coordinates
10344 * (please see pspp_sheet_view_get_bin_window()).
10345 * That is, @x and @y are relative to an events coordinates. @x and @y must
10346 * come from an event on the @tree_view only where <literal>event->window ==
10347 * pspp_sheet_view_get_bin_window (<!-- -->)</literal>. It is primarily for
10348 * things like popup menus. If @path is non-%NULL, then it will be filled
10349 * with the #GtkTreePath at that point. This path should be freed with
10350 * gtk_tree_path_free(). If @column is non-%NULL, then it will be filled
10351 * with the column at that point. @cell_x and @cell_y return the coordinates
10352 * relative to the cell background (i.e. the @background_area passed to
10353 * gtk_cell_renderer_render()). This function is only meaningful if
10354 * @tree_view is realized. Therefore this function will always return %FALSE
10355 * if @tree_view is not realized or does not have a model.
10357 * For converting widget coordinates (eg. the ones you get from
10358 * GtkWidget::query-tooltip), please see
10359 * pspp_sheet_view_convert_widget_to_bin_window_coords().
10361 * Return value: %TRUE if a row exists at that coordinate.
10364 pspp_sheet_view_get_path_at_pos (PsppSheetView *tree_view,
10367 GtkTreePath **path,
10368 PsppSheetViewColumn **column,
10375 g_return_val_if_fail (tree_view != NULL, FALSE);
10382 if (tree_view->priv->bin_window == NULL)
10385 if (tree_view->priv->row_count == 0)
10388 if (x > gtk_adjustment_get_upper (tree_view->priv->hadjustment))
10391 if (x < 0 || y < 0)
10394 if (column || cell_x)
10396 PsppSheetViewColumn *tmp_column;
10397 PsppSheetViewColumn *last_column = NULL;
10399 gint remaining_x = x;
10400 gboolean found = FALSE;
10403 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
10404 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
10406 list = (rtl ? list->prev : list->next))
10408 tmp_column = list->data;
10410 if (tmp_column->visible == FALSE)
10413 last_column = tmp_column;
10414 if (remaining_x <= tmp_column->width)
10419 *column = tmp_column;
10422 *cell_x = remaining_x;
10426 remaining_x -= tmp_column->width;
10429 /* If found is FALSE and there is a last_column, then it the remainder
10430 * space is in that area
10437 *column = last_column;
10440 *cell_x = last_column->width + remaining_x;
10449 y_offset = pspp_sheet_view_find_offset (tree_view,
10450 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, y),
10457 *cell_y = y_offset;
10460 *path = _pspp_sheet_view_find_path (tree_view, node);
10465 /* Computes 'cell_area' from 'background_area', which must be the background
10466 area for a cell. Set 'subtract_focus_rect' to TRUE to compute the cell area
10467 as passed to a GtkCellRenderer's "render" function, or to FALSE to compute
10468 the cell area as passed to _pspp_sheet_view_column_cell_render().
10470 'column' is required to properly adjust 'cell_area->x' and
10471 'cell_area->width'. It may be set to NULL if these values are not of
10472 interest. In this case 'cell_area->x' and 'cell_area->width' will be
10475 pspp_sheet_view_adjust_cell_area (PsppSheetView *tree_view,
10476 PsppSheetViewColumn *column,
10477 const GdkRectangle *background_area,
10478 gboolean subtract_focus_rect,
10479 GdkRectangle *cell_area)
10481 gint vertical_separator;
10482 gint horizontal_separator;
10484 *cell_area = *background_area;
10486 gtk_widget_style_get (GTK_WIDGET (tree_view),
10487 "vertical-separator", &vertical_separator,
10488 "horizontal-separator", &horizontal_separator,
10490 cell_area->x += horizontal_separator / 2;
10491 cell_area->y += vertical_separator / 2;
10492 cell_area->width -= horizontal_separator;
10493 cell_area->height -= vertical_separator;
10495 if (subtract_focus_rect)
10497 int focus_line_width;
10499 gtk_widget_style_get (GTK_WIDGET (tree_view),
10500 "focus-line-width", &focus_line_width,
10502 cell_area->x += focus_line_width;
10503 cell_area->y += focus_line_width;
10504 cell_area->width -= 2 * focus_line_width;
10505 cell_area->height -= 2 * focus_line_width;
10508 if (tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_NONE)
10510 gint grid_line_width;
10511 gtk_widget_style_get (GTK_WIDGET (tree_view),
10512 "grid-line-width", &grid_line_width,
10515 if ((tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
10516 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10519 PsppSheetViewColumn *first_column, *last_column;
10522 /* Find the last visible column. */
10523 last_column = NULL;
10524 for (list = g_list_last (tree_view->priv->columns);
10528 PsppSheetViewColumn *c = list->data;
10536 /* Find the first visible column. */
10537 first_column = NULL;
10538 for (list = g_list_first (tree_view->priv->columns);
10542 PsppSheetViewColumn *c = list->data;
10550 if (column == first_column)
10552 cell_area->width -= grid_line_width / 2;
10554 else if (column == last_column)
10556 cell_area->x += grid_line_width / 2;
10557 cell_area->width -= grid_line_width / 2;
10561 cell_area->x += grid_line_width / 2;
10562 cell_area->width -= grid_line_width;
10566 if (tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
10567 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10569 cell_area->y += grid_line_width / 2;
10570 cell_area->height -= grid_line_width;
10574 if (column == NULL)
10577 cell_area->width = 0;
10582 * pspp_sheet_view_get_cell_area:
10583 * @tree_view: a #PsppSheetView
10584 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10585 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordinates
10586 * @rect: rectangle to fill with cell rect
10588 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10589 * row specified by @path and the column specified by @column. If @path is
10590 * %NULL, or points to a path not currently displayed, the @y and @height fields
10591 * of the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10592 * fields will be filled with 0. The sum of all cell rects does not cover the
10593 * entire tree; there are extra pixels in between rows, for example. The
10594 * returned rectangle is equivalent to the @cell_area passed to
10595 * gtk_cell_renderer_render(). This function is only valid if @tree_view is
10599 pspp_sheet_view_get_cell_area (PsppSheetView *tree_view,
10601 PsppSheetViewColumn *column,
10602 GdkRectangle *rect)
10604 GdkRectangle background_area;
10606 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10607 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10608 g_return_if_fail (rect != NULL);
10609 g_return_if_fail (!column || column->tree_view == (GtkWidget *) tree_view);
10610 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
10612 pspp_sheet_view_get_background_area (tree_view, path, column,
10614 pspp_sheet_view_adjust_cell_area (tree_view, column, &background_area,
10619 * pspp_sheet_view_get_background_area:
10620 * @tree_view: a #PsppSheetView
10621 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10622 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordiantes
10623 * @rect: rectangle to fill with cell background rect
10625 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10626 * row specified by @path and the column specified by @column. If @path is
10627 * %NULL, or points to a node not found in the tree, the @y and @height fields of
10628 * the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10629 * fields will be filled with 0. The returned rectangle is equivalent to the
10630 * @background_area passed to gtk_cell_renderer_render(). These background
10631 * areas tile to cover the entire bin window. Contrast with the @cell_area,
10632 * returned by pspp_sheet_view_get_cell_area(), which returns only the cell
10633 * itself, excluding surrounding borders.
10637 pspp_sheet_view_get_background_area (PsppSheetView *tree_view,
10639 PsppSheetViewColumn *column,
10640 GdkRectangle *rect)
10644 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10645 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10646 g_return_if_fail (rect != NULL);
10655 /* Get vertical coords */
10657 _pspp_sheet_view_find_node (tree_view, path, &node);
10661 rect->y = BACKGROUND_FIRST_PIXEL (tree_view, node);
10663 rect->height = ROW_HEIGHT (tree_view);
10670 pspp_sheet_view_get_background_xrange (tree_view, column, &rect->x, &x2);
10671 rect->width = x2 - rect->x;
10676 * pspp_sheet_view_get_visible_rect:
10677 * @tree_view: a #PsppSheetView
10678 * @visible_rect: rectangle to fill
10680 * Fills @visible_rect with the currently-visible region of the
10681 * buffer, in tree coordinates. Convert to bin_window coordinates with
10682 * pspp_sheet_view_convert_tree_to_bin_window_coords().
10683 * Tree coordinates start at 0,0 for row 0 of the tree, and cover the entire
10684 * scrollable area of the tree.
10687 pspp_sheet_view_get_visible_rect (PsppSheetView *tree_view,
10688 GdkRectangle *visible_rect)
10692 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10694 widget = GTK_WIDGET (tree_view);
10698 GtkAllocation allocation;
10699 gtk_widget_get_allocation (widget, &allocation);
10700 visible_rect->x = gtk_adjustment_get_value (tree_view->priv->hadjustment);
10701 visible_rect->y = gtk_adjustment_get_value (tree_view->priv->vadjustment);
10702 visible_rect->width = allocation.width;
10703 visible_rect->height = allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
10708 * pspp_sheet_view_widget_to_tree_coords:
10709 * @tree_view: a #PsppSheetView
10710 * @wx: X coordinate relative to bin_window
10711 * @wy: Y coordinate relative to bin_window
10712 * @tx: return location for tree X coordinate
10713 * @ty: return location for tree Y coordinate
10715 * Converts bin_window coordinates to coordinates for the
10716 * tree (the full scrollable area of the tree).
10718 * Deprecated: 2.12: Due to historial reasons the name of this function is
10719 * incorrect. For converting coordinates relative to the widget to
10720 * bin_window coordinates, please see
10721 * pspp_sheet_view_convert_widget_to_bin_window_coords().
10725 pspp_sheet_view_widget_to_tree_coords (PsppSheetView *tree_view,
10731 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10734 *tx = wx + gtk_adjustment_get_value (tree_view->priv->hadjustment);
10736 *ty = wy + tree_view->priv->dy;
10740 * pspp_sheet_view_tree_to_widget_coords:
10741 * @tree_view: a #PsppSheetView
10742 * @tx: tree X coordinate
10743 * @ty: tree Y coordinate
10744 * @wx: return location for X coordinate relative to bin_window
10745 * @wy: return location for Y coordinate relative to bin_window
10747 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10748 * to bin_window coordinates.
10750 * Deprecated: 2.12: Due to historial reasons the name of this function is
10751 * incorrect. For converting bin_window coordinates to coordinates relative
10752 * to bin_window, please see
10753 * pspp_sheet_view_convert_bin_window_to_widget_coords().
10757 pspp_sheet_view_tree_to_widget_coords (PsppSheetView *tree_view,
10763 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10766 *wx = tx - gtk_adjustment_get_value (tree_view->priv->hadjustment);
10768 *wy = ty - tree_view->priv->dy;
10773 * pspp_sheet_view_convert_widget_to_tree_coords:
10774 * @tree_view: a #PsppSheetView
10775 * @wx: X coordinate relative to the widget
10776 * @wy: Y coordinate relative to the widget
10777 * @tx: return location for tree X coordinate
10778 * @ty: return location for tree Y coordinate
10780 * Converts widget coordinates to coordinates for the
10781 * tree (the full scrollable area of the tree).
10786 pspp_sheet_view_convert_widget_to_tree_coords (PsppSheetView *tree_view,
10794 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10796 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view,
10799 pspp_sheet_view_convert_bin_window_to_tree_coords (tree_view,
10805 * pspp_sheet_view_convert_tree_to_widget_coords:
10806 * @tree_view: a #PsppSheetView
10807 * @tx: X coordinate relative to the tree
10808 * @ty: Y coordinate relative to the tree
10809 * @wx: return location for widget X coordinate
10810 * @wy: return location for widget Y coordinate
10812 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10813 * to widget coordinates.
10818 pspp_sheet_view_convert_tree_to_widget_coords (PsppSheetView *tree_view,
10826 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10828 pspp_sheet_view_convert_tree_to_bin_window_coords (tree_view,
10831 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
10837 * pspp_sheet_view_convert_widget_to_bin_window_coords:
10838 * @tree_view: a #PsppSheetView
10839 * @wx: X coordinate relative to the widget
10840 * @wy: Y coordinate relative to the widget
10841 * @bx: return location for bin_window X coordinate
10842 * @by: return location for bin_window Y coordinate
10844 * Converts widget coordinates to coordinates for the bin_window
10845 * (see pspp_sheet_view_get_bin_window()).
10850 pspp_sheet_view_convert_widget_to_bin_window_coords (PsppSheetView *tree_view,
10856 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10859 *bx = wx + gtk_adjustment_get_value (tree_view->priv->hadjustment);
10861 *by = wy - TREE_VIEW_HEADER_HEIGHT (tree_view);
10865 * pspp_sheet_view_convert_bin_window_to_widget_coords:
10866 * @tree_view: a #PsppSheetView
10867 * @bx: bin_window X coordinate
10868 * @by: bin_window Y coordinate
10869 * @wx: return location for widget X coordinate
10870 * @wy: return location for widget Y coordinate
10872 * Converts bin_window coordinates (see pspp_sheet_view_get_bin_window())
10873 * to widget relative coordinates.
10878 pspp_sheet_view_convert_bin_window_to_widget_coords (PsppSheetView *tree_view,
10884 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10887 *wx = bx - gtk_adjustment_get_value (tree_view->priv->hadjustment);
10889 *wy = by + TREE_VIEW_HEADER_HEIGHT (tree_view);
10893 * pspp_sheet_view_convert_tree_to_bin_window_coords:
10894 * @tree_view: a #PsppSheetView
10895 * @tx: tree X coordinate
10896 * @ty: tree Y coordinate
10897 * @bx: return location for X coordinate relative to bin_window
10898 * @by: return location for Y coordinate relative to bin_window
10900 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10901 * to bin_window coordinates.
10906 pspp_sheet_view_convert_tree_to_bin_window_coords (PsppSheetView *tree_view,
10912 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10917 *by = ty - tree_view->priv->dy;
10921 * pspp_sheet_view_convert_bin_window_to_tree_coords:
10922 * @tree_view: a #PsppSheetView
10923 * @bx: X coordinate relative to bin_window
10924 * @by: Y coordinate relative to bin_window
10925 * @tx: return location for tree X coordinate
10926 * @ty: return location for tree Y coordinate
10928 * Converts bin_window coordinates to coordinates for the
10929 * tree (the full scrollable area of the tree).
10934 pspp_sheet_view_convert_bin_window_to_tree_coords (PsppSheetView *tree_view,
10940 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10945 *ty = by + tree_view->priv->dy;
10951 * pspp_sheet_view_get_visible_range:
10952 * @tree_view: A #PsppSheetView
10953 * @start_path: (allow-none): Return location for start of region, or %NULL.
10954 * @end_path: (allow-none): Return location for end of region, or %NULL.
10956 * Sets @start_path and @end_path to be the first and last visible path.
10957 * Note that there may be invisible paths in between.
10959 * The paths should be freed with gtk_tree_path_free() after use.
10961 * Returns: %TRUE, if valid paths were placed in @start_path and @end_path.
10966 pspp_sheet_view_get_visible_range (PsppSheetView *tree_view,
10967 GtkTreePath **start_path,
10968 GtkTreePath **end_path)
10973 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
10975 if (!tree_view->priv->row_count)
10982 pspp_sheet_view_find_offset (tree_view,
10983 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, 0),
10986 *start_path = _pspp_sheet_view_find_path (tree_view, node);
10995 if (tree_view->priv->height < gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
10996 y = tree_view->priv->height - 1;
10998 y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, gtk_adjustment_get_page_size (tree_view->priv->vadjustment)) - 1;
11000 pspp_sheet_view_find_offset (tree_view, y, &node);
11002 *end_path = _pspp_sheet_view_find_path (tree_view, node);
11011 unset_reorderable (PsppSheetView *tree_view)
11013 if (tree_view->priv->reorderable)
11015 tree_view->priv->reorderable = FALSE;
11016 g_object_notify (G_OBJECT (tree_view), "reorderable");
11021 * pspp_sheet_view_enable_model_drag_source:
11022 * @tree_view: a #PsppSheetView
11023 * @start_button_mask: Mask of allowed buttons to start drag
11024 * @targets: the table of targets that the drag will support
11025 * @n_targets: the number of items in @targets
11026 * @actions: the bitmask of possible actions for a drag from this
11029 * Turns @tree_view into a drag source for automatic DND. Calling this
11030 * method sets #PsppSheetView:reorderable to %FALSE.
11033 pspp_sheet_view_enable_model_drag_source (PsppSheetView *tree_view,
11034 GdkModifierType start_button_mask,
11035 const GtkTargetEntry *targets,
11037 GdkDragAction actions)
11039 TreeViewDragInfo *di;
11041 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11043 gtk_drag_source_set (GTK_WIDGET (tree_view),
11049 di = ensure_info (tree_view);
11051 di->start_button_mask = start_button_mask;
11052 di->source_actions = actions;
11053 di->source_set = TRUE;
11055 unset_reorderable (tree_view);
11059 * pspp_sheet_view_enable_model_drag_dest:
11060 * @tree_view: a #PsppSheetView
11061 * @targets: the table of targets that the drag will support
11062 * @n_targets: the number of items in @targets
11063 * @actions: the bitmask of possible actions for a drag from this
11066 * Turns @tree_view into a drop destination for automatic DND. Calling
11067 * this method sets #PsppSheetView:reorderable to %FALSE.
11070 pspp_sheet_view_enable_model_drag_dest (PsppSheetView *tree_view,
11071 const GtkTargetEntry *targets,
11073 GdkDragAction actions)
11075 TreeViewDragInfo *di;
11077 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11079 gtk_drag_dest_set (GTK_WIDGET (tree_view),
11085 di = ensure_info (tree_view);
11086 di->dest_set = TRUE;
11088 unset_reorderable (tree_view);
11092 * pspp_sheet_view_unset_rows_drag_source:
11093 * @tree_view: a #PsppSheetView
11095 * Undoes the effect of
11096 * pspp_sheet_view_enable_model_drag_source(). Calling this method sets
11097 * #PsppSheetView:reorderable to %FALSE.
11100 pspp_sheet_view_unset_rows_drag_source (PsppSheetView *tree_view)
11102 TreeViewDragInfo *di;
11104 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11106 di = get_info (tree_view);
11110 if (di->source_set)
11112 gtk_drag_source_unset (GTK_WIDGET (tree_view));
11113 di->source_set = FALSE;
11116 if (!di->dest_set && !di->source_set)
11117 remove_info (tree_view);
11120 unset_reorderable (tree_view);
11124 * pspp_sheet_view_unset_rows_drag_dest:
11125 * @tree_view: a #PsppSheetView
11127 * Undoes the effect of
11128 * pspp_sheet_view_enable_model_drag_dest(). Calling this method sets
11129 * #PsppSheetView:reorderable to %FALSE.
11132 pspp_sheet_view_unset_rows_drag_dest (PsppSheetView *tree_view)
11134 TreeViewDragInfo *di;
11136 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11138 di = get_info (tree_view);
11144 gtk_drag_dest_unset (GTK_WIDGET (tree_view));
11145 di->dest_set = FALSE;
11148 if (!di->dest_set && !di->source_set)
11149 remove_info (tree_view);
11152 unset_reorderable (tree_view);
11156 * pspp_sheet_view_set_drag_dest_row:
11157 * @tree_view: a #PsppSheetView
11158 * @path: (allow-none): The path of the row to highlight, or %NULL.
11159 * @pos: Specifies whether to drop before, after or into the row
11161 * Sets the row that is highlighted for feedback.
11164 pspp_sheet_view_set_drag_dest_row (PsppSheetView *tree_view,
11166 PsppSheetViewDropPosition pos)
11168 GtkTreePath *current_dest;
11170 /* Note; this function is exported to allow a custom DND
11171 * implementation, so it can't touch TreeViewDragInfo
11174 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11176 current_dest = NULL;
11178 if (tree_view->priv->drag_dest_row)
11180 current_dest = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
11181 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
11184 /* special case a drop on an empty model */
11185 tree_view->priv->empty_view_drop = 0;
11187 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE && path
11188 && gtk_tree_path_get_depth (path) == 1
11189 && gtk_tree_path_get_indices (path)[0] == 0)
11193 n_children = gtk_tree_model_iter_n_children (tree_view->priv->model,
11197 tree_view->priv->empty_view_drop = 1;
11200 tree_view->priv->drag_dest_pos = pos;
11204 tree_view->priv->drag_dest_row =
11205 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
11206 pspp_sheet_view_queue_draw_path (tree_view, path, NULL);
11209 tree_view->priv->drag_dest_row = NULL;
11213 int node, new_node;
11215 _pspp_sheet_view_find_node (tree_view, current_dest, &node);
11216 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
11220 new_node = pspp_sheet_view_node_next (tree_view, node);
11222 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
11224 new_node = pspp_sheet_view_node_prev (tree_view, node);
11226 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
11228 gtk_tree_path_free (current_dest);
11233 * pspp_sheet_view_get_drag_dest_row:
11234 * @tree_view: a #PsppSheetView
11235 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
11236 * @pos: (allow-none): Return location for the drop position, or %NULL
11238 * Gets information about the row that is highlighted for feedback.
11241 pspp_sheet_view_get_drag_dest_row (PsppSheetView *tree_view,
11242 GtkTreePath **path,
11243 PsppSheetViewDropPosition *pos)
11245 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11249 if (tree_view->priv->drag_dest_row)
11250 *path = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
11253 if (tree_view->priv->empty_view_drop)
11254 *path = gtk_tree_path_new_from_indices (0, -1);
11261 *pos = tree_view->priv->drag_dest_pos;
11265 * pspp_sheet_view_get_dest_row_at_pos:
11266 * @tree_view: a #PsppSheetView
11267 * @drag_x: the position to determine the destination row for
11268 * @drag_y: the position to determine the destination row for
11269 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
11270 * @pos: (allow-none): Return location for the drop position, or %NULL
11272 * Determines the destination row for a given position. @drag_x and
11273 * @drag_y are expected to be in widget coordinates. This function is only
11274 * meaningful if @tree_view is realized. Therefore this function will always
11275 * return %FALSE if @tree_view is not realized or does not have a model.
11277 * Return value: whether there is a row at the given position, %TRUE if this
11278 * is indeed the case.
11281 pspp_sheet_view_get_dest_row_at_pos (PsppSheetView *tree_view,
11284 GtkTreePath **path,
11285 PsppSheetViewDropPosition *pos)
11289 gdouble offset_into_row;
11292 PsppSheetViewColumn *column = NULL;
11293 GtkTreePath *tmp_path = NULL;
11295 /* Note; this function is exported to allow a custom DND
11296 * implementation, so it can't touch TreeViewDragInfo
11299 g_return_val_if_fail (tree_view != NULL, FALSE);
11300 g_return_val_if_fail (drag_x >= 0, FALSE);
11301 g_return_val_if_fail (drag_y >= 0, FALSE);
11306 if (tree_view->priv->bin_window == NULL)
11309 if (tree_view->priv->row_count == 0)
11312 /* If in the top third of a row, we drop before that row; if
11313 * in the bottom third, drop after that row; if in the middle,
11314 * and the row has children, drop into the row.
11316 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, drag_x, drag_y,
11319 if (!pspp_sheet_view_get_path_at_pos (tree_view,
11328 pspp_sheet_view_get_background_area (tree_view, tmp_path, column,
11331 offset_into_row = cell_y;
11336 gtk_tree_path_free (tmp_path);
11340 third = cell.height / 3.0;
11344 if (offset_into_row < third)
11346 *pos = PSPP_SHEET_VIEW_DROP_BEFORE;
11348 else if (offset_into_row < (cell.height / 2.0))
11350 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE;
11352 else if (offset_into_row < third * 2.0)
11354 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER;
11358 *pos = PSPP_SHEET_VIEW_DROP_AFTER;
11366 #if GTK3_TRANSITION
11367 /* KEEP IN SYNC WITH PSPP_SHEET_VIEW_BIN_EXPOSE */
11369 * pspp_sheet_view_create_row_drag_icon:
11370 * @tree_view: a #PsppSheetView
11371 * @path: a #GtkTreePath in @tree_view
11373 * Creates a #GdkPixmap representation of the row at @path.
11374 * This image is used for a drag icon.
11376 * Return value: a newly-allocated pixmap of the drag icon.
11379 pspp_sheet_view_create_row_drag_icon (PsppSheetView *tree_view,
11386 GdkRectangle background_area;
11387 GdkRectangle expose_area;
11389 /* start drawing inside the black outline */
11391 GdkDrawable *drawable;
11392 gint bin_window_width;
11395 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11396 g_return_val_if_fail (path != NULL, NULL);
11398 widget = GTK_WIDGET (tree_view);
11400 if (!gtk_widget_get_realized (widget))
11403 _pspp_sheet_view_find_node (tree_view,
11410 if (!gtk_tree_model_get_iter (tree_view->priv->model,
11417 background_area.y = y;
11418 background_area.height = ROW_HEIGHT (tree_view);
11420 bin_window_width = gdk_window_get_width (tree_view->priv->bin_window);
11422 drawable = gdk_pixmap_new (tree_view->priv->bin_window,
11423 bin_window_width + 2,
11424 background_area.height + 2,
11429 expose_area.width = bin_window_width + 2;
11430 expose_area.height = background_area.height + 2;
11432 #if GTK3_TRANSITION
11433 gdk_draw_rectangle (drawable,
11434 widget->style->base_gc [gtk_widget_get_state (widget)],
11437 bin_window_width + 2,
11438 background_area.height + 2);
11441 rtl = gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL;
11443 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
11445 list = (rtl ? list->prev : list->next))
11447 PsppSheetViewColumn *column = list->data;
11448 GdkRectangle cell_area;
11449 gint vertical_separator;
11451 if (!column->visible)
11454 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, &iter);
11456 background_area.x = cell_offset;
11457 background_area.width = column->width;
11459 gtk_widget_style_get (widget,
11460 "vertical-separator", &vertical_separator,
11463 cell_area = background_area;
11465 cell_area.y += vertical_separator / 2;
11466 cell_area.height -= vertical_separator;
11468 if (pspp_sheet_view_column_cell_is_visible (column))
11469 _pspp_sheet_view_column_cell_render (column,
11475 cell_offset += column->width;
11478 #if GTK3_TRANSITION
11479 gdk_draw_rectangle (drawable,
11480 widget->style->black_gc,
11483 bin_window_width + 1,
11484 background_area.height + 1);
11492 * pspp_sheet_view_set_destroy_count_func:
11493 * @tree_view: A #PsppSheetView
11494 * @func: (allow-none): Function to be called when a view row is destroyed, or %NULL
11495 * @data: (allow-none): User data to be passed to @func, or %NULL
11496 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11498 * This function should almost never be used. It is meant for private use by
11499 * ATK for determining the number of visible children that are removed when a row is deleted.
11502 pspp_sheet_view_set_destroy_count_func (PsppSheetView *tree_view,
11503 PsppSheetDestroyCountFunc func,
11505 GDestroyNotify destroy)
11507 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11509 if (tree_view->priv->destroy_count_destroy)
11510 tree_view->priv->destroy_count_destroy (tree_view->priv->destroy_count_data);
11512 tree_view->priv->destroy_count_func = func;
11513 tree_view->priv->destroy_count_data = data;
11514 tree_view->priv->destroy_count_destroy = destroy;
11519 * Interactive search
11523 * pspp_sheet_view_set_enable_search:
11524 * @tree_view: A #PsppSheetView
11525 * @enable_search: %TRUE, if the user can search interactively
11527 * If @enable_search is set, then the user can type in text to search through
11528 * the tree interactively (this is sometimes called "typeahead find").
11530 * Note that even if this is %FALSE, the user can still initiate a search
11531 * using the "start-interactive-search" key binding.
11534 pspp_sheet_view_set_enable_search (PsppSheetView *tree_view,
11535 gboolean enable_search)
11537 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11539 enable_search = !!enable_search;
11541 if (tree_view->priv->enable_search != enable_search)
11543 tree_view->priv->enable_search = enable_search;
11544 g_object_notify (G_OBJECT (tree_view), "enable-search");
11549 * pspp_sheet_view_get_enable_search:
11550 * @tree_view: A #PsppSheetView
11552 * Returns whether or not the tree allows to start interactive searching
11553 * by typing in text.
11555 * Return value: whether or not to let the user search interactively
11558 pspp_sheet_view_get_enable_search (PsppSheetView *tree_view)
11560 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11562 return tree_view->priv->enable_search;
11567 * pspp_sheet_view_get_search_column:
11568 * @tree_view: A #PsppSheetView
11570 * Gets the column searched on by the interactive search code.
11572 * Return value: the column the interactive search code searches in.
11575 pspp_sheet_view_get_search_column (PsppSheetView *tree_view)
11577 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
11579 return (tree_view->priv->search_column);
11583 * pspp_sheet_view_set_search_column:
11584 * @tree_view: A #PsppSheetView
11585 * @column: the column of the model to search in, or -1 to disable searching
11587 * Sets @column as the column where the interactive search code should
11588 * search in for the current model.
11590 * If the search column is set, users can use the "start-interactive-search"
11591 * key binding to bring up search popup. The enable-search property controls
11592 * whether simply typing text will also start an interactive search.
11594 * Note that @column refers to a column of the current model. The search
11595 * column is reset to -1 when the model is changed.
11598 pspp_sheet_view_set_search_column (PsppSheetView *tree_view,
11601 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11602 g_return_if_fail (column >= -1);
11604 if (tree_view->priv->search_column == column)
11607 tree_view->priv->search_column = column;
11608 g_object_notify (G_OBJECT (tree_view), "search-column");
11612 * pspp_sheet_view_get_search_equal_func:
11613 * @tree_view: A #PsppSheetView
11615 * Returns the compare function currently in use.
11617 * Return value: the currently used compare function for the search code.
11620 PsppSheetViewSearchEqualFunc
11621 pspp_sheet_view_get_search_equal_func (PsppSheetView *tree_view)
11623 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11625 return tree_view->priv->search_equal_func;
11629 * pspp_sheet_view_set_search_equal_func:
11630 * @tree_view: A #PsppSheetView
11631 * @search_equal_func: the compare function to use during the search
11632 * @search_user_data: (allow-none): user data to pass to @search_equal_func, or %NULL
11633 * @search_destroy: (allow-none): Destroy notifier for @search_user_data, or %NULL
11635 * Sets the compare function for the interactive search capabilities; note
11636 * that somewhat like strcmp() returning 0 for equality
11637 * #PsppSheetViewSearchEqualFunc returns %FALSE on matches.
11640 pspp_sheet_view_set_search_equal_func (PsppSheetView *tree_view,
11641 PsppSheetViewSearchEqualFunc search_equal_func,
11642 gpointer search_user_data,
11643 GDestroyNotify search_destroy)
11645 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11646 g_return_if_fail (search_equal_func != NULL);
11648 if (tree_view->priv->search_destroy)
11649 tree_view->priv->search_destroy (tree_view->priv->search_user_data);
11651 tree_view->priv->search_equal_func = search_equal_func;
11652 tree_view->priv->search_user_data = search_user_data;
11653 tree_view->priv->search_destroy = search_destroy;
11654 if (tree_view->priv->search_equal_func == NULL)
11655 tree_view->priv->search_equal_func = pspp_sheet_view_search_equal_func;
11659 * pspp_sheet_view_get_search_entry:
11660 * @tree_view: A #PsppSheetView
11662 * Returns the #GtkEntry which is currently in use as interactive search
11663 * entry for @tree_view. In case the built-in entry is being used, %NULL
11664 * will be returned.
11666 * Return value: the entry currently in use as search entry.
11671 pspp_sheet_view_get_search_entry (PsppSheetView *tree_view)
11673 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11675 if (tree_view->priv->search_custom_entry_set)
11676 return GTK_ENTRY (tree_view->priv->search_entry);
11682 * pspp_sheet_view_set_search_entry:
11683 * @tree_view: A #PsppSheetView
11684 * @entry: (allow-none): the entry the interactive search code of @tree_view should use or %NULL
11686 * Sets the entry which the interactive search code will use for this
11687 * @tree_view. This is useful when you want to provide a search entry
11688 * in our interface at all time at a fixed position. Passing %NULL for
11689 * @entry will make the interactive search code use the built-in popup
11695 pspp_sheet_view_set_search_entry (PsppSheetView *tree_view,
11698 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11699 g_return_if_fail (entry == NULL || GTK_IS_ENTRY (entry));
11701 if (tree_view->priv->search_custom_entry_set)
11703 if (tree_view->priv->search_entry_changed_id)
11705 g_signal_handler_disconnect (tree_view->priv->search_entry,
11706 tree_view->priv->search_entry_changed_id);
11707 tree_view->priv->search_entry_changed_id = 0;
11709 g_signal_handlers_disconnect_by_func (tree_view->priv->search_entry,
11710 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11713 g_object_unref (tree_view->priv->search_entry);
11715 else if (tree_view->priv->search_window)
11717 gtk_widget_destroy (tree_view->priv->search_window);
11719 tree_view->priv->search_window = NULL;
11724 tree_view->priv->search_entry = g_object_ref (entry);
11725 tree_view->priv->search_custom_entry_set = TRUE;
11727 if (tree_view->priv->search_entry_changed_id == 0)
11729 tree_view->priv->search_entry_changed_id =
11730 g_signal_connect (tree_view->priv->search_entry, "changed",
11731 G_CALLBACK (pspp_sheet_view_search_init),
11735 g_signal_connect (tree_view->priv->search_entry, "key-press-event",
11736 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11739 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
11743 tree_view->priv->search_entry = NULL;
11744 tree_view->priv->search_custom_entry_set = FALSE;
11749 * pspp_sheet_view_set_search_position_func:
11750 * @tree_view: A #PsppSheetView
11751 * @func: (allow-none): the function to use to position the search dialog, or %NULL
11752 * to use the default search position function
11753 * @data: (allow-none): user data to pass to @func, or %NULL
11754 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11756 * Sets the function to use when positioning the search dialog.
11761 pspp_sheet_view_set_search_position_func (PsppSheetView *tree_view,
11762 PsppSheetViewSearchPositionFunc func,
11763 gpointer user_data,
11764 GDestroyNotify destroy)
11766 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11768 if (tree_view->priv->search_position_destroy)
11769 tree_view->priv->search_position_destroy (tree_view->priv->search_position_user_data);
11771 tree_view->priv->search_position_func = func;
11772 tree_view->priv->search_position_user_data = user_data;
11773 tree_view->priv->search_position_destroy = destroy;
11774 if (tree_view->priv->search_position_func == NULL)
11775 tree_view->priv->search_position_func = pspp_sheet_view_search_position_func;
11779 * pspp_sheet_view_get_search_position_func:
11780 * @tree_view: A #PsppSheetView
11782 * Returns the positioning function currently in use.
11784 * Return value: the currently used function for positioning the search dialog.
11788 PsppSheetViewSearchPositionFunc
11789 pspp_sheet_view_get_search_position_func (PsppSheetView *tree_view)
11791 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11793 return tree_view->priv->search_position_func;
11798 pspp_sheet_view_search_dialog_hide (GtkWidget *search_dialog,
11799 PsppSheetView *tree_view)
11801 if (tree_view->priv->disable_popdown)
11804 if (tree_view->priv->search_entry_changed_id)
11806 g_signal_handler_disconnect (tree_view->priv->search_entry,
11807 tree_view->priv->search_entry_changed_id);
11808 tree_view->priv->search_entry_changed_id = 0;
11810 if (tree_view->priv->typeselect_flush_timeout)
11812 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11813 tree_view->priv->typeselect_flush_timeout = 0;
11816 if (gtk_widget_get_visible (search_dialog))
11818 /* send focus-in event */
11819 send_focus_change (GTK_WIDGET (tree_view->priv->search_entry), FALSE);
11820 gtk_widget_hide (search_dialog);
11821 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
11822 send_focus_change (GTK_WIDGET (tree_view), TRUE);
11827 pspp_sheet_view_search_position_func (PsppSheetView *tree_view,
11828 GtkWidget *search_dialog,
11829 gpointer user_data)
11832 gint tree_x, tree_y;
11833 gint tree_width, tree_height;
11834 GdkWindow *tree_window = gtk_widget_get_window (GTK_WIDGET (tree_view));
11835 GdkScreen *screen = gdk_window_get_screen (tree_window);
11836 GtkRequisition requisition;
11838 GdkRectangle monitor;
11840 monitor_num = gdk_screen_get_monitor_at_window (screen, tree_window);
11841 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
11843 gtk_widget_realize (search_dialog);
11845 gdk_window_get_origin (tree_window, &tree_x, &tree_y);
11846 tree_width = gdk_window_get_width (tree_window);
11847 tree_height = gdk_window_get_height (tree_window);
11849 gtk_widget_size_request (search_dialog, &requisition);
11851 if (tree_x + tree_width > gdk_screen_get_width (screen))
11852 x = gdk_screen_get_width (screen) - requisition.width;
11853 else if (tree_x + tree_width - requisition.width < 0)
11856 x = tree_x + tree_width - requisition.width;
11858 if (tree_y + tree_height + requisition.height > gdk_screen_get_height (screen))
11859 y = gdk_screen_get_height (screen) - requisition.height;
11860 else if (tree_y + tree_height < 0) /* isn't really possible ... */
11863 y = tree_y + tree_height;
11865 gtk_window_move (GTK_WINDOW (search_dialog), x, y);
11869 pspp_sheet_view_search_disable_popdown (GtkEntry *entry,
11873 PsppSheetView *tree_view = (PsppSheetView *)data;
11875 tree_view->priv->disable_popdown = 1;
11876 g_signal_connect (menu, "hide",
11877 G_CALLBACK (pspp_sheet_view_search_enable_popdown), data);
11880 #if GTK3_TRANSITION
11881 /* Because we're visible but offscreen, we just set a flag in the preedit
11885 pspp_sheet_view_search_preedit_changed (GtkIMContext *im_context,
11886 PsppSheetView *tree_view)
11888 tree_view->priv->imcontext_changed = 1;
11889 if (tree_view->priv->typeselect_flush_timeout)
11891 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11892 tree_view->priv->typeselect_flush_timeout =
11893 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11894 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11902 pspp_sheet_view_search_activate (GtkEntry *entry,
11903 PsppSheetView *tree_view)
11908 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window,
11911 /* If we have a row selected and it's the cursor row, we activate
11913 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
11915 path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
11917 _pspp_sheet_view_find_node (tree_view, path, &node);
11919 if (node >= 0 && pspp_sheet_view_node_is_selected (tree_view, node))
11920 pspp_sheet_view_row_activated (tree_view, path, tree_view->priv->focus_column);
11922 gtk_tree_path_free (path);
11927 pspp_sheet_view_real_search_enable_popdown (gpointer data)
11929 PsppSheetView *tree_view = (PsppSheetView *)data;
11931 tree_view->priv->disable_popdown = 0;
11937 pspp_sheet_view_search_enable_popdown (GtkWidget *widget,
11940 gdk_threads_add_timeout_full (G_PRIORITY_HIGH, 200, pspp_sheet_view_real_search_enable_popdown, g_object_ref (data), g_object_unref);
11944 pspp_sheet_view_search_delete_event (GtkWidget *widget,
11945 GdkEventAny *event,
11946 PsppSheetView *tree_view)
11948 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11950 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11956 pspp_sheet_view_search_button_press_event (GtkWidget *widget,
11957 GdkEventButton *event,
11958 PsppSheetView *tree_view)
11960 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11962 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11964 if (event->window == tree_view->priv->bin_window)
11965 pspp_sheet_view_button_press (GTK_WIDGET (tree_view), event);
11971 pspp_sheet_view_search_scroll_event (GtkWidget *widget,
11972 GdkEventScroll *event,
11973 PsppSheetView *tree_view)
11975 gboolean retval = FALSE;
11977 if (event->direction == GDK_SCROLL_UP)
11979 pspp_sheet_view_search_move (widget, tree_view, TRUE);
11982 else if (event->direction == GDK_SCROLL_DOWN)
11984 pspp_sheet_view_search_move (widget, tree_view, FALSE);
11988 /* renew the flush timeout */
11989 if (retval && tree_view->priv->typeselect_flush_timeout
11990 && !tree_view->priv->search_custom_entry_set)
11992 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11993 tree_view->priv->typeselect_flush_timeout =
11994 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11995 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
12003 pspp_sheet_view_search_key_press_event (GtkWidget *widget,
12004 GdkEventKey *event,
12005 PsppSheetView *tree_view)
12007 gboolean retval = FALSE;
12009 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
12010 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
12012 /* close window and cancel the search */
12013 if (!tree_view->priv->search_custom_entry_set
12014 && (event->keyval == GDK_Escape ||
12015 event->keyval == GDK_Tab ||
12016 event->keyval == GDK_KP_Tab ||
12017 event->keyval == GDK_ISO_Left_Tab))
12019 pspp_sheet_view_search_dialog_hide (widget, tree_view);
12023 /* select previous matching iter */
12024 if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up)
12026 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
12027 gtk_widget_error_bell (widget);
12032 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK))
12033 && (event->keyval == GDK_g || event->keyval == GDK_G))
12035 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
12036 gtk_widget_error_bell (widget);
12041 /* select next matching iter */
12042 if (event->keyval == GDK_Down || event->keyval == GDK_KP_Down)
12044 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
12045 gtk_widget_error_bell (widget);
12050 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == GTK_DEFAULT_ACCEL_MOD_MASK)
12051 && (event->keyval == GDK_g || event->keyval == GDK_G))
12053 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
12054 gtk_widget_error_bell (widget);
12059 /* renew the flush timeout */
12060 if (retval && tree_view->priv->typeselect_flush_timeout
12061 && !tree_view->priv->search_custom_entry_set)
12063 g_source_remove (tree_view->priv->typeselect_flush_timeout);
12064 tree_view->priv->typeselect_flush_timeout =
12065 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
12066 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
12073 /* this function returns FALSE if there is a search string but
12074 * nothing was found, and TRUE otherwise.
12077 pspp_sheet_view_search_move (GtkWidget *window,
12078 PsppSheetView *tree_view,
12086 GtkTreeModel *model;
12087 PsppSheetSelection *selection;
12089 text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
12091 g_return_val_if_fail (text != NULL, FALSE);
12093 len = strlen (text);
12095 if (up && tree_view->priv->selected_iter == 1)
12096 return strlen (text) < 1;
12098 len = strlen (text);
12103 model = pspp_sheet_view_get_model (tree_view);
12104 selection = pspp_sheet_view_get_selection (tree_view);
12107 pspp_sheet_selection_unselect_all (selection);
12108 if (!gtk_tree_model_get_iter_first (model, &iter))
12111 ret = pspp_sheet_view_search_iter (model, selection, &iter, text,
12112 &count, up?((tree_view->priv->selected_iter) - 1):((tree_view->priv->selected_iter + 1)));
12117 tree_view->priv->selected_iter += up?(-1):(1);
12122 /* return to old iter */
12124 gtk_tree_model_get_iter_first (model, &iter);
12125 pspp_sheet_view_search_iter (model, selection,
12127 &count, tree_view->priv->selected_iter);
12133 pspp_sheet_view_search_equal_func (GtkTreeModel *model,
12137 gpointer search_data)
12139 gboolean retval = TRUE;
12141 gchar *normalized_string;
12142 gchar *normalized_key;
12143 gchar *case_normalized_string = NULL;
12144 gchar *case_normalized_key = NULL;
12145 GValue value = {0,};
12146 GValue transformed = {0,};
12148 gtk_tree_model_get_value (model, iter, column, &value);
12150 g_value_init (&transformed, G_TYPE_STRING);
12152 if (!g_value_transform (&value, &transformed))
12154 g_value_unset (&value);
12158 g_value_unset (&value);
12160 str = g_value_get_string (&transformed);
12163 g_value_unset (&transformed);
12167 normalized_string = g_utf8_normalize (str, -1, G_NORMALIZE_ALL);
12168 normalized_key = g_utf8_normalize (key, -1, G_NORMALIZE_ALL);
12170 if (normalized_string && normalized_key)
12172 case_normalized_string = g_utf8_casefold (normalized_string, -1);
12173 case_normalized_key = g_utf8_casefold (normalized_key, -1);
12175 if (strncmp (case_normalized_key, case_normalized_string, strlen (case_normalized_key)) == 0)
12179 g_value_unset (&transformed);
12180 g_free (normalized_key);
12181 g_free (normalized_string);
12182 g_free (case_normalized_key);
12183 g_free (case_normalized_string);
12189 pspp_sheet_view_search_iter (GtkTreeModel *model,
12190 PsppSheetSelection *selection,
12199 PsppSheetView *tree_view = pspp_sheet_selection_get_tree_view (selection);
12201 path = gtk_tree_model_get_path (model, iter);
12202 _pspp_sheet_view_find_node (tree_view, path, &node);
12206 gboolean done = FALSE;
12208 if (! tree_view->priv->search_equal_func (model, tree_view->priv->search_column, text, iter, tree_view->priv->search_user_data))
12213 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL,
12215 pspp_sheet_selection_select_iter (selection, iter);
12216 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE, 0);
12219 gtk_tree_path_free (path);
12228 node = pspp_sheet_view_node_next (tree_view, node);
12234 has_next = gtk_tree_model_iter_next (model, iter);
12237 gtk_tree_path_next (path);
12240 TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
12245 gtk_tree_path_free (path);
12247 /* we've run out of tree, done with this func */
12259 pspp_sheet_view_search_init (GtkWidget *entry,
12260 PsppSheetView *tree_view)
12266 GtkTreeModel *model;
12267 PsppSheetSelection *selection;
12269 g_return_if_fail (GTK_IS_ENTRY (entry));
12270 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12272 text = gtk_entry_get_text (GTK_ENTRY (entry));
12274 model = pspp_sheet_view_get_model (tree_view);
12275 selection = pspp_sheet_view_get_selection (tree_view);
12278 pspp_sheet_selection_unselect_all (selection);
12279 if (tree_view->priv->typeselect_flush_timeout
12280 && !tree_view->priv->search_custom_entry_set)
12282 g_source_remove (tree_view->priv->typeselect_flush_timeout);
12283 tree_view->priv->typeselect_flush_timeout =
12284 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
12285 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
12292 if (!gtk_tree_model_get_iter_first (model, &iter))
12295 ret = pspp_sheet_view_search_iter (model, selection,
12300 tree_view->priv->selected_iter = 1;
12304 pspp_sheet_view_remove_widget (GtkCellEditable *cell_editable,
12305 PsppSheetView *tree_view)
12307 if (tree_view->priv->edited_column == NULL)
12310 _pspp_sheet_view_column_stop_editing (tree_view->priv->edited_column);
12311 tree_view->priv->edited_column = NULL;
12313 if (gtk_widget_has_focus (GTK_WIDGET (cell_editable)))
12314 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
12316 g_signal_handlers_disconnect_by_func (cell_editable,
12317 pspp_sheet_view_remove_widget,
12319 g_signal_handlers_disconnect_by_func (cell_editable,
12320 pspp_sheet_view_editable_button_press_event,
12322 g_signal_handlers_disconnect_by_func (cell_editable,
12323 pspp_sheet_view_editable_clicked,
12326 gtk_container_remove (GTK_CONTAINER (tree_view),
12327 GTK_WIDGET (cell_editable));
12329 /* FIXME should only redraw a single node */
12330 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12334 pspp_sheet_view_start_editing (PsppSheetView *tree_view,
12335 GtkTreePath *cursor_path)
12338 GdkRectangle background_area;
12339 GdkRectangle cell_area;
12340 GtkCellEditable *editable_widget = NULL;
12341 gchar *path_string;
12342 guint flags = 0; /* can be 0, as the flags are primarily for rendering */
12343 gint retval = FALSE;
12346 g_assert (tree_view->priv->focus_column);
12348 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
12351 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
12352 if (cursor_node < 0)
12355 path_string = gtk_tree_path_to_string (cursor_path);
12356 gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path);
12358 pspp_sheet_view_column_cell_set_cell_data (tree_view->priv->focus_column,
12359 tree_view->priv->model,
12361 pspp_sheet_view_get_background_area (tree_view,
12363 tree_view->priv->focus_column,
12365 pspp_sheet_view_get_cell_area (tree_view,
12367 tree_view->priv->focus_column,
12370 if (_pspp_sheet_view_column_cell_event (tree_view->priv->focus_column,
12379 if (editable_widget != NULL)
12383 GtkCellRenderer *cell;
12386 cell = _pspp_sheet_view_column_get_edited_cell (tree_view->priv->focus_column);
12388 _pspp_sheet_view_column_get_neighbor_sizes (tree_view->priv->focus_column, cell, &left, &right);
12391 area.width -= right + left;
12393 pspp_sheet_view_real_start_editing (tree_view,
12394 tree_view->priv->focus_column,
12403 g_free (path_string);
12408 pspp_sheet_view_editable_button_press_event (GtkWidget *widget,
12409 GdkEventButton *event,
12410 PsppSheetView *sheet_view)
12414 node = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
12415 "pspp-sheet-view-node"));
12416 return pspp_sheet_view_row_head_clicked (sheet_view,
12418 sheet_view->priv->edited_column,
12423 pspp_sheet_view_editable_clicked (GtkButton *button,
12424 PsppSheetView *sheet_view)
12426 pspp_sheet_view_editable_button_press_event (GTK_WIDGET (button), NULL,
12431 is_all_selected (GtkWidget *widget)
12433 GtkEntryBuffer *buffer;
12434 gint start_pos, end_pos;
12436 if (!GTK_IS_ENTRY (widget))
12439 buffer = gtk_entry_get_buffer (GTK_ENTRY (widget));
12440 return (gtk_editable_get_selection_bounds (GTK_EDITABLE (widget),
12441 &start_pos, &end_pos)
12443 && end_pos == gtk_entry_buffer_get_length (buffer));
12447 is_at_left (GtkWidget *widget)
12449 return (GTK_IS_ENTRY (widget)
12450 && gtk_editable_get_position (GTK_EDITABLE (widget)) == 0);
12454 is_at_right (GtkWidget *widget)
12456 GtkEntryBuffer *buffer;
12459 if (!GTK_IS_ENTRY (widget))
12462 buffer = gtk_entry_get_buffer (GTK_ENTRY (widget));
12463 length = gtk_entry_buffer_get_length (buffer);
12464 return gtk_editable_get_position (GTK_EDITABLE (widget)) == length;
12468 pspp_sheet_view_event (GtkWidget *widget,
12469 GdkEventKey *event,
12470 PsppSheetView *tree_view)
12472 PsppSheetViewColumn *column;
12479 /* Intercept only key press events.
12480 It would make sense to use "key-press-event" instead of "event", but
12481 GtkEntry attaches its own signal handler to "key-press-event" that runs
12482 before ours and overrides our desired behavior for GDK_Up and GDK_Down.
12484 if (event->type != GDK_KEY_PRESS)
12487 keyval = event->keyval;
12489 switch (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK | GDK_MOD1_MASK))
12492 switch (event->keyval)
12494 case GDK_Left: case GDK_KP_Left:
12495 case GDK_Home: case GDK_KP_Home:
12496 if (!is_all_selected (widget) && !is_at_left (widget))
12500 case GDK_Right: case GDK_KP_Right:
12501 case GDK_End: case GDK_KP_End:
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:
12510 case GDK_Page_Up: case GDK_KP_Page_Up:
12511 case GDK_Page_Down: case GDK_KP_Page_Down:
12522 case GDK_Tab: case GDK_KP_Tab:
12523 case GDK_ISO_Left_Tab:
12532 case GDK_SHIFT_MASK:
12533 switch (event->keyval)
12536 case GDK_ISO_Left_Tab:
12545 case GDK_CONTROL_MASK:
12546 switch (event->keyval)
12548 case GDK_Left: case GDK_KP_Left:
12549 if (!is_all_selected (widget) && !is_at_left (widget))
12553 case GDK_Right: case GDK_KP_Right:
12554 if (!is_all_selected (widget) && !is_at_right (widget))
12558 case GDK_Up: case GDK_KP_Up:
12559 case GDK_Down: case GDK_KP_Down:
12571 row = tree_view->priv->edited_row;
12572 column = tree_view->priv->edited_column;
12573 path = gtk_tree_path_new_from_indices (row, -1);
12575 pspp_sheet_view_stop_editing (tree_view, cancel);
12576 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
12578 pspp_sheet_view_set_cursor (tree_view, path, column, FALSE);
12579 gtk_tree_path_free (path);
12581 handled = gtk_binding_set_activate (edit_bindings, keyval, event->state,
12582 G_OBJECT (tree_view));
12584 g_signal_stop_emission_by_name (widget, "event");
12586 pspp_sheet_view_get_cursor (tree_view, &path, NULL);
12587 pspp_sheet_view_start_editing (tree_view, path);
12588 gtk_tree_path_free (path);
12594 pspp_sheet_view_override_cell_keypresses (GtkWidget *widget,
12597 PsppSheetView *sheet_view = data;
12599 g_signal_connect (widget, "event",
12600 G_CALLBACK (pspp_sheet_view_event),
12603 if (GTK_IS_CONTAINER (widget))
12604 gtk_container_foreach (GTK_CONTAINER (widget),
12605 pspp_sheet_view_override_cell_keypresses,
12610 pspp_sheet_view_real_start_editing (PsppSheetView *tree_view,
12611 PsppSheetViewColumn *column,
12613 GtkCellEditable *cell_editable,
12614 GdkRectangle *cell_area,
12618 PsppSheetSelectionMode mode = pspp_sheet_selection_get_mode (tree_view->priv->selection);
12619 gint pre_val = gtk_adjustment_get_value (tree_view->priv->vadjustment);
12620 GtkRequisition requisition;
12623 g_return_if_fail (gtk_tree_path_get_depth (path) == 1);
12625 tree_view->priv->edited_column = column;
12626 _pspp_sheet_view_column_start_editing (column, GTK_CELL_EDITABLE (cell_editable));
12628 row = gtk_tree_path_get_indices (path)[0];
12629 tree_view->priv->edited_row = row;
12630 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE, 0);
12631 cell_area->y += pre_val - (int)gtk_adjustment_get_value (tree_view->priv->vadjustment);
12633 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
12634 pspp_sheet_selection_select_column (tree_view->priv->selection, column);
12635 tree_view->priv->anchor_column = column;
12637 gtk_widget_size_request (GTK_WIDGET (cell_editable), &requisition);
12639 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
12641 if (requisition.height < cell_area->height)
12643 gint diff = cell_area->height - requisition.height;
12644 pspp_sheet_view_put (tree_view,
12645 GTK_WIDGET (cell_editable),
12646 cell_area->x, cell_area->y + diff/2,
12647 cell_area->width, requisition.height);
12651 pspp_sheet_view_put (tree_view,
12652 GTK_WIDGET (cell_editable),
12653 cell_area->x, cell_area->y,
12654 cell_area->width, cell_area->height);
12657 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (cell_editable),
12658 (GdkEvent *)event);
12660 gtk_widget_grab_focus (GTK_WIDGET (cell_editable));
12661 g_signal_connect (cell_editable, "remove-widget",
12662 G_CALLBACK (pspp_sheet_view_remove_widget), tree_view);
12663 if (mode == PSPP_SHEET_SELECTION_RECTANGLE && column->row_head &&
12664 GTK_IS_BUTTON (cell_editable))
12666 g_signal_connect (cell_editable, "button-press-event",
12667 G_CALLBACK (pspp_sheet_view_editable_button_press_event),
12669 g_object_set_data (G_OBJECT (cell_editable), "pspp-sheet-view-node",
12670 GINT_TO_POINTER (row));
12671 g_signal_connect (cell_editable, "clicked",
12672 G_CALLBACK (pspp_sheet_view_editable_clicked),
12676 pspp_sheet_view_override_cell_keypresses (GTK_WIDGET (cell_editable),
12681 pspp_sheet_view_stop_editing (PsppSheetView *tree_view,
12682 gboolean cancel_editing)
12684 PsppSheetViewColumn *column;
12685 GtkCellRenderer *cell;
12687 if (tree_view->priv->edited_column == NULL)
12691 * This is very evil. We need to do this, because
12692 * gtk_cell_editable_editing_done may trigger pspp_sheet_view_row_changed
12693 * later on. If pspp_sheet_view_row_changed notices
12694 * tree_view->priv->edited_column != NULL, it'll call
12695 * pspp_sheet_view_stop_editing again. Bad things will happen then.
12697 * Please read that again if you intend to modify anything here.
12700 column = tree_view->priv->edited_column;
12701 tree_view->priv->edited_column = NULL;
12703 cell = _pspp_sheet_view_column_get_edited_cell (column);
12704 gtk_cell_renderer_stop_editing (cell, cancel_editing);
12706 if (!cancel_editing)
12707 gtk_cell_editable_editing_done (column->editable_widget);
12709 tree_view->priv->edited_column = column;
12711 gtk_cell_editable_remove_widget (column->editable_widget);
12716 * pspp_sheet_view_set_hover_selection:
12717 * @tree_view: a #PsppSheetView
12718 * @hover: %TRUE to enable hover selection mode
12720 * Enables of disables the hover selection mode of @tree_view.
12721 * Hover selection makes the selected row follow the pointer.
12722 * Currently, this works only for the selection modes
12723 * %PSPP_SHEET_SELECTION_SINGLE and %PSPP_SHEET_SELECTION_BROWSE.
12728 pspp_sheet_view_set_hover_selection (PsppSheetView *tree_view,
12731 hover = hover != FALSE;
12733 if (hover != tree_view->priv->hover_selection)
12735 tree_view->priv->hover_selection = hover;
12737 g_object_notify (G_OBJECT (tree_view), "hover-selection");
12742 * pspp_sheet_view_get_hover_selection:
12743 * @tree_view: a #PsppSheetView
12745 * Returns whether hover selection mode is turned on for @tree_view.
12747 * Return value: %TRUE if @tree_view is in hover selection mode
12752 pspp_sheet_view_get_hover_selection (PsppSheetView *tree_view)
12754 return tree_view->priv->hover_selection;
12758 * pspp_sheet_view_set_rubber_banding:
12759 * @tree_view: a #PsppSheetView
12760 * @enable: %TRUE to enable rubber banding
12762 * Enables or disables rubber banding in @tree_view. If the selection mode is
12763 * #PSPP_SHEET_SELECTION_MULTIPLE or #PSPP_SHEET_SELECTION_RECTANGLE, rubber
12764 * banding will allow the user to select multiple rows by dragging the mouse.
12769 pspp_sheet_view_set_rubber_banding (PsppSheetView *tree_view,
12772 enable = enable != FALSE;
12774 if (enable != tree_view->priv->rubber_banding_enable)
12776 tree_view->priv->rubber_banding_enable = enable;
12778 g_object_notify (G_OBJECT (tree_view), "rubber-banding");
12783 * pspp_sheet_view_get_rubber_banding:
12784 * @tree_view: a #PsppSheetView
12786 * Returns whether rubber banding is turned on for @tree_view. If the
12787 * selection mode is #PSPP_SHEET_SELECTION_MULTIPLE or
12788 * #PSPP_SHEET_SELECTION_RECTANGLE, rubber banding will allow the user to
12789 * select multiple rows by dragging the mouse.
12791 * Return value: %TRUE if rubber banding in @tree_view is enabled.
12796 pspp_sheet_view_get_rubber_banding (PsppSheetView *tree_view)
12798 return tree_view->priv->rubber_banding_enable;
12802 * pspp_sheet_view_is_rubber_banding_active:
12803 * @tree_view: a #PsppSheetView
12805 * Returns whether a rubber banding operation is currently being done
12808 * Return value: %TRUE if a rubber banding operation is currently being
12809 * done in @tree_view.
12814 pspp_sheet_view_is_rubber_banding_active (PsppSheetView *tree_view)
12816 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
12818 if (tree_view->priv->rubber_banding_enable
12819 && tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
12826 pspp_sheet_view_grab_notify (GtkWidget *widget,
12827 gboolean was_grabbed)
12829 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12831 tree_view->priv->in_grab = !was_grabbed;
12835 tree_view->priv->pressed_button = -1;
12837 if (tree_view->priv->rubber_band_status)
12838 pspp_sheet_view_stop_rubber_band (tree_view);
12843 pspp_sheet_view_state_changed (GtkWidget *widget,
12844 GtkStateType previous_state)
12846 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12848 if (gtk_widget_get_realized (widget))
12850 GtkStyle *style = gtk_widget_get_style (widget);
12851 gdk_window_set_background (tree_view->priv->bin_window, &style->base[gtk_widget_get_state (widget)]);
12854 gtk_widget_queue_draw (widget);
12858 * pspp_sheet_view_get_grid_lines:
12859 * @tree_view: a #PsppSheetView
12861 * Returns which grid lines are enabled in @tree_view.
12863 * Return value: a #PsppSheetViewGridLines value indicating which grid lines
12868 PsppSheetViewGridLines
12869 pspp_sheet_view_get_grid_lines (PsppSheetView *tree_view)
12871 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12873 return tree_view->priv->grid_lines;
12877 * pspp_sheet_view_set_grid_lines:
12878 * @tree_view: a #PsppSheetView
12879 * @grid_lines: a #PsppSheetViewGridLines value indicating which grid lines to
12882 * Sets which grid lines to draw in @tree_view.
12887 pspp_sheet_view_set_grid_lines (PsppSheetView *tree_view,
12888 PsppSheetViewGridLines grid_lines)
12890 PsppSheetViewPrivate *priv;
12891 PsppSheetViewGridLines old_grid_lines;
12893 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12895 priv = tree_view->priv;
12897 old_grid_lines = priv->grid_lines;
12898 priv->grid_lines = grid_lines;
12900 if (old_grid_lines != grid_lines)
12902 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12904 g_object_notify (G_OBJECT (tree_view), "enable-grid-lines");
12909 * pspp_sheet_view_get_special_cells:
12910 * @tree_view: a #PsppSheetView
12912 * Returns which grid lines are enabled in @tree_view.
12914 * Return value: a #PsppSheetViewSpecialCells value indicating whether rows in
12915 * the sheet view contain special cells.
12917 PsppSheetViewSpecialCells
12918 pspp_sheet_view_get_special_cells (PsppSheetView *tree_view)
12920 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12922 return tree_view->priv->special_cells;
12926 * pspp_sheet_view_set_special_cells:
12927 * @tree_view: a #PsppSheetView
12928 * @special_cells: a #PsppSheetViewSpecialCells value indicating whether rows in
12929 * the sheet view contain special cells.
12931 * Sets whether rows in the sheet view contain special cells, controlling the
12932 * rendering of row selections.
12935 pspp_sheet_view_set_special_cells (PsppSheetView *tree_view,
12936 PsppSheetViewSpecialCells special_cells)
12938 PsppSheetViewPrivate *priv;
12940 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12942 priv = tree_view->priv;
12944 if (priv->special_cells != special_cells)
12946 priv->special_cells = special_cells;
12947 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12948 g_object_notify (G_OBJECT (tree_view), "special-cells");
12953 pspp_sheet_view_get_fixed_height (const PsppSheetView *tree_view)
12955 /* XXX (re)calculate fixed_height if necessary */
12956 return tree_view->priv->fixed_height;
12960 pspp_sheet_view_set_fixed_height (PsppSheetView *tree_view,
12963 g_return_if_fail (fixed_height > 0);
12965 if (tree_view->priv->fixed_height != fixed_height)
12967 tree_view->priv->fixed_height = fixed_height;
12968 g_object_notify (G_OBJECT (tree_view), "fixed-height");
12970 if (!tree_view->priv->fixed_height_set)
12972 tree_view->priv->fixed_height_set = TRUE;
12973 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
12978 * pspp_sheet_view_set_tooltip_row:
12979 * @tree_view: a #PsppSheetView
12980 * @tooltip: a #GtkTooltip
12981 * @path: a #GtkTreePath
12983 * Sets the tip area of @tooltip to be the area covered by the row at @path.
12984 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
12985 * See also gtk_tooltip_set_tip_area().
12990 pspp_sheet_view_set_tooltip_row (PsppSheetView *tree_view,
12991 GtkTooltip *tooltip,
12994 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12995 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
12997 pspp_sheet_view_set_tooltip_cell (tree_view, tooltip, path, NULL, NULL);
13001 * pspp_sheet_view_set_tooltip_cell:
13002 * @tree_view: a #PsppSheetView
13003 * @tooltip: a #GtkTooltip
13004 * @path: (allow-none): a #GtkTreePath or %NULL
13005 * @column: (allow-none): a #PsppSheetViewColumn or %NULL
13006 * @cell: (allow-none): a #GtkCellRenderer or %NULL
13008 * Sets the tip area of @tooltip to the area @path, @column and @cell have
13009 * in common. For example if @path is %NULL and @column is set, the tip
13010 * area will be set to the full area covered by @column. See also
13011 * gtk_tooltip_set_tip_area().
13013 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
13018 pspp_sheet_view_set_tooltip_cell (PsppSheetView *tree_view,
13019 GtkTooltip *tooltip,
13021 PsppSheetViewColumn *column,
13022 GtkCellRenderer *cell)
13026 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
13027 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
13028 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
13029 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
13031 /* Determine x values. */
13032 if (column && cell)
13037 pspp_sheet_view_get_cell_area (tree_view, path, column, &tmp);
13038 pspp_sheet_view_column_cell_get_position (column, cell, &start, &width);
13040 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
13043 rect.width = width;
13049 pspp_sheet_view_get_background_area (tree_view, NULL, column, &tmp);
13050 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
13053 rect.width = tmp.width;
13057 GtkAllocation allocation;
13058 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
13060 rect.width = allocation.width;
13063 /* Determine y values. */
13068 pspp_sheet_view_get_background_area (tree_view, path, NULL, &tmp);
13069 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
13072 rect.height = tmp.height;
13077 rect.height = gtk_adjustment_get_page_size (tree_view->priv->vadjustment);
13080 gtk_tooltip_set_tip_area (tooltip, &rect);
13084 * pspp_sheet_view_get_tooltip_context:
13085 * @tree_view: a #PsppSheetView
13086 * @x: the x coordinate (relative to widget coordinates)
13087 * @y: the y coordinate (relative to widget coordinates)
13088 * @keyboard_tip: whether this is a keyboard tooltip or not
13089 * @model: (allow-none): a pointer to receive a #GtkTreeModel or %NULL
13090 * @path: (allow-none): a pointer to receive a #GtkTreePath or %NULL
13091 * @iter: (allow-none): a pointer to receive a #GtkTreeIter or %NULL
13093 * This function is supposed to be used in a #GtkWidget::query-tooltip
13094 * signal handler for #PsppSheetView. The @x, @y and @keyboard_tip values
13095 * which are received in the signal handler, should be passed to this
13096 * function without modification.
13098 * The return value indicates whether there is a tree view row at the given
13099 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
13100 * tooltips the row returned will be the cursor row. When %TRUE, then any of
13101 * @model, @path and @iter which have been provided will be set to point to
13102 * that row and the corresponding model. @x and @y will always be converted
13103 * to be relative to @tree_view's bin_window if @keyboard_tooltip is %FALSE.
13105 * Return value: whether or not the given tooltip context points to a row.
13110 pspp_sheet_view_get_tooltip_context (PsppSheetView *tree_view,
13113 gboolean keyboard_tip,
13114 GtkTreeModel **model,
13115 GtkTreePath **path,
13118 GtkTreePath *tmppath = NULL;
13120 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
13121 g_return_val_if_fail (x != NULL, FALSE);
13122 g_return_val_if_fail (y != NULL, FALSE);
13126 pspp_sheet_view_get_cursor (tree_view, &tmppath, NULL);
13133 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, *x, *y,
13136 if (!pspp_sheet_view_get_path_at_pos (tree_view, *x, *y,
13137 &tmppath, NULL, NULL, NULL))
13142 *model = pspp_sheet_view_get_model (tree_view);
13145 gtk_tree_model_get_iter (pspp_sheet_view_get_model (tree_view),
13151 gtk_tree_path_free (tmppath);
13157 pspp_sheet_view_set_tooltip_query_cb (GtkWidget *widget,
13160 gboolean keyboard_tip,
13161 GtkTooltip *tooltip,
13164 GValue value = { 0, };
13165 GValue transformed = { 0, };
13168 GtkTreeModel *model;
13169 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
13171 if (!pspp_sheet_view_get_tooltip_context (PSPP_SHEET_VIEW (widget),
13174 &model, &path, &iter))
13177 gtk_tree_model_get_value (model, &iter,
13178 tree_view->priv->tooltip_column, &value);
13180 g_value_init (&transformed, G_TYPE_STRING);
13182 if (!g_value_transform (&value, &transformed))
13184 g_value_unset (&value);
13185 gtk_tree_path_free (path);
13190 g_value_unset (&value);
13192 if (!g_value_get_string (&transformed))
13194 g_value_unset (&transformed);
13195 gtk_tree_path_free (path);
13200 gtk_tooltip_set_markup (tooltip, g_value_get_string (&transformed));
13201 pspp_sheet_view_set_tooltip_row (tree_view, tooltip, path);
13203 gtk_tree_path_free (path);
13204 g_value_unset (&transformed);
13210 * pspp_sheet_view_set_tooltip_column:
13211 * @tree_view: a #PsppSheetView
13212 * @column: an integer, which is a valid column number for @tree_view's model
13214 * If you only plan to have simple (text-only) tooltips on full rows, you
13215 * can use this function to have #PsppSheetView handle these automatically
13216 * for you. @column should be set to the column in @tree_view's model
13217 * containing the tooltip texts, or -1 to disable this feature.
13219 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
13220 * @tree_view will connect a #GtkWidget::query-tooltip signal handler.
13222 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
13223 * so &, <, etc have to be escaped in the text.
13228 pspp_sheet_view_set_tooltip_column (PsppSheetView *tree_view,
13231 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
13233 if (column == tree_view->priv->tooltip_column)
13238 g_signal_handlers_disconnect_by_func (tree_view,
13239 pspp_sheet_view_set_tooltip_query_cb,
13241 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), FALSE);
13245 if (tree_view->priv->tooltip_column == -1)
13247 g_signal_connect (tree_view, "query-tooltip",
13248 G_CALLBACK (pspp_sheet_view_set_tooltip_query_cb), NULL);
13249 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), TRUE);
13253 tree_view->priv->tooltip_column = column;
13254 g_object_notify (G_OBJECT (tree_view), "tooltip-column");
13258 * pspp_sheet_view_get_tooltip_column:
13259 * @tree_view: a #PsppSheetView
13261 * Returns the column of @tree_view's model which is being used for
13262 * displaying tooltips on @tree_view's rows.
13264 * Return value: the index of the tooltip column that is currently being
13265 * used, or -1 if this is disabled.
13270 pspp_sheet_view_get_tooltip_column (PsppSheetView *tree_view)
13272 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
13274 return tree_view->priv->tooltip_column;
13278 _gtk_boolean_handled_accumulator (GSignalInvocationHint *ihint,
13279 GValue *return_accu,
13280 const GValue *handler_return,
13283 gboolean continue_emission;
13284 gboolean signal_handled;
13286 signal_handled = g_value_get_boolean (handler_return);
13287 g_value_set_boolean (return_accu, signal_handled);
13288 continue_emission = !signal_handled;
13290 return continue_emission;
13295 pspp_sheet_view_grid_lines_get_type (void)
13297 static GType etype = 0;
13298 if (G_UNLIKELY(etype == 0)) {
13299 static const GEnumValue values[] = {
13300 { PSPP_SHEET_VIEW_GRID_LINES_NONE, "PSPP_SHEET_VIEW_GRID_LINES_NONE", "none" },
13301 { PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL, "PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL", "horizontal" },
13302 { PSPP_SHEET_VIEW_GRID_LINES_VERTICAL, "PSPP_SHEET_VIEW_GRID_LINES_VERTICAL", "vertical" },
13303 { PSPP_SHEET_VIEW_GRID_LINES_BOTH, "PSPP_SHEET_VIEW_GRID_LINES_BOTH", "both" },
13306 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewGridLines"), values);
13312 pspp_sheet_view_special_cells_get_type (void)
13314 static GType etype = 0;
13315 if (G_UNLIKELY(etype == 0)) {
13316 static const GEnumValue values[] = {
13317 { PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT, "PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT", "detect" },
13318 { PSPP_SHEET_VIEW_SPECIAL_CELLS_YES, "PSPP_SHEET_VIEW_SPECIAL_CELLS_YES", "yes" },
13319 { PSPP_SHEET_VIEW_SPECIAL_CELLS_NO, "PSPP_SHEET_VIEW_SPECIAL_CELLS_NO", "no" },
13322 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewSpecialCells"), values);