1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2011, 2012 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>
45 #include "ui/gui/psppire-marshal.h"
46 #include "ui/gui/pspp-sheet-selection.h"
48 #define P_(STRING) STRING
49 #define GTK_PARAM_READABLE G_PARAM_READABLE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
50 #define GTK_PARAM_READWRITE G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
52 /* Many keyboard shortcuts for Mac are the same as for X
53 * except they use Command key instead of Control (e.g. Cut,
54 * Copy, Paste). This symbol is for those simple cases. */
55 #ifndef GDK_WINDOWING_QUARTZ
56 #define GTK_DEFAULT_ACCEL_MOD_MASK GDK_CONTROL_MASK
58 #define GTK_DEFAULT_ACCEL_MOD_MASK GDK_META_MASK
61 #define PSPP_SHEET_VIEW_PRIORITY_VALIDATE (GDK_PRIORITY_REDRAW + 5)
62 #define PSPP_SHEET_VIEW_PRIORITY_SCROLL_SYNC (PSPP_SHEET_VIEW_PRIORITY_VALIDATE + 2)
63 #define PSPP_SHEET_VIEW_TIME_MS_PER_IDLE 30
64 #define SCROLL_EDGE_SIZE 15
65 #define EXPANDER_EXTRA_PADDING 4
66 #define PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT 5000
68 /* The "background" areas of all rows/cells add up to cover the entire tree.
69 * The background includes all inter-row and inter-cell spacing.
70 * The "cell" areas are the cell_area passed in to gtk_cell_renderer_render(),
71 * i.e. just the cells, no spacing.
74 #define BACKGROUND_HEIGHT(tree_view) (tree_view->priv->fixed_height)
75 #define CELL_HEIGHT(tree_view, separator) ((BACKGROUND_HEIGHT (tree_view)) - (separator))
77 /* Translate from bin_window coordinates to rbtree (tree coordinates) and
80 #define TREE_WINDOW_Y_TO_RBTREE_Y(tree_view,y) ((y) + tree_view->priv->dy)
81 #define RBTREE_Y_TO_TREE_WINDOW_Y(tree_view,y) ((y) - tree_view->priv->dy)
83 /* This is in bin_window coordinates */
84 #define BACKGROUND_FIRST_PIXEL(tree_view,node) (RBTREE_Y_TO_TREE_WINDOW_Y (tree_view, pspp_sheet_view_node_find_offset (tree_view, (node))))
85 #define CELL_FIRST_PIXEL(tree_view,node,separator) (BACKGROUND_FIRST_PIXEL (tree_view,node) + separator/2)
87 #define ROW_HEIGHT(tree_view) \
88 ((tree_view->priv->fixed_height > 0) ? (tree_view->priv->fixed_height) : (tree_view)->priv->expander_size)
91 typedef struct _PsppSheetViewChild PsppSheetViewChild;
92 struct _PsppSheetViewChild
102 typedef struct _TreeViewDragInfo TreeViewDragInfo;
103 struct _TreeViewDragInfo
105 GdkModifierType start_button_mask;
106 GtkTargetList *_unused_source_target_list;
107 GdkDragAction source_actions;
109 GtkTargetList *_unused_dest_target_list;
111 guint source_set : 1;
127 START_INTERACTIVE_SEARCH,
137 PROP_HEADERS_VISIBLE,
138 PROP_HEADERS_CLICKABLE,
143 PROP_HOVER_SELECTION,
145 PROP_ENABLE_GRID_LINES,
149 PROP_FIXED_HEIGHT_SET
153 static void pspp_sheet_view_finalize (GObject *object);
154 static void pspp_sheet_view_set_property (GObject *object,
158 static void pspp_sheet_view_get_property (GObject *object,
163 static void pspp_sheet_view_dispose (GObject *object);
165 /* gtkwidget signals */
166 static void pspp_sheet_view_realize (GtkWidget *widget);
167 static void pspp_sheet_view_unrealize (GtkWidget *widget);
168 static void pspp_sheet_view_map (GtkWidget *widget);
169 static void pspp_sheet_view_size_request (GtkWidget *widget,
170 GtkRequisition *requisition);
171 static void pspp_sheet_view_size_allocate (GtkWidget *widget,
172 GtkAllocation *allocation);
173 static gboolean pspp_sheet_view_expose (GtkWidget *widget,
174 GdkEventExpose *event);
175 static gboolean pspp_sheet_view_key_press (GtkWidget *widget,
177 static gboolean pspp_sheet_view_key_release (GtkWidget *widget,
179 static gboolean pspp_sheet_view_motion (GtkWidget *widget,
180 GdkEventMotion *event);
181 static gboolean pspp_sheet_view_enter_notify (GtkWidget *widget,
182 GdkEventCrossing *event);
183 static gboolean pspp_sheet_view_leave_notify (GtkWidget *widget,
184 GdkEventCrossing *event);
185 static gboolean pspp_sheet_view_button_press (GtkWidget *widget,
186 GdkEventButton *event);
187 static gboolean pspp_sheet_view_button_release (GtkWidget *widget,
188 GdkEventButton *event);
189 static gboolean pspp_sheet_view_grab_broken (GtkWidget *widget,
190 GdkEventGrabBroken *event);
192 static void pspp_sheet_view_set_focus_child (GtkContainer *container,
194 static gint pspp_sheet_view_focus_out (GtkWidget *widget,
195 GdkEventFocus *event);
196 static gint pspp_sheet_view_focus (GtkWidget *widget,
197 GtkDirectionType direction);
198 static void pspp_sheet_view_grab_focus (GtkWidget *widget);
199 static void pspp_sheet_view_style_set (GtkWidget *widget,
200 GtkStyle *previous_style);
201 static void pspp_sheet_view_grab_notify (GtkWidget *widget,
202 gboolean was_grabbed);
203 static void pspp_sheet_view_state_changed (GtkWidget *widget,
204 GtkStateType previous_state);
206 /* container signals */
207 static void pspp_sheet_view_remove (GtkContainer *container,
209 static void pspp_sheet_view_forall (GtkContainer *container,
210 gboolean include_internals,
211 GtkCallback callback,
212 gpointer callback_data);
214 /* Source side drag signals */
215 static void pspp_sheet_view_drag_begin (GtkWidget *widget,
216 GdkDragContext *context);
217 static void pspp_sheet_view_drag_end (GtkWidget *widget,
218 GdkDragContext *context);
219 static void pspp_sheet_view_drag_data_get (GtkWidget *widget,
220 GdkDragContext *context,
221 GtkSelectionData *selection_data,
224 static void pspp_sheet_view_drag_data_delete (GtkWidget *widget,
225 GdkDragContext *context);
227 /* Target side drag signals */
228 static void pspp_sheet_view_drag_leave (GtkWidget *widget,
229 GdkDragContext *context,
231 static gboolean pspp_sheet_view_drag_motion (GtkWidget *widget,
232 GdkDragContext *context,
236 static gboolean pspp_sheet_view_drag_drop (GtkWidget *widget,
237 GdkDragContext *context,
241 static void pspp_sheet_view_drag_data_received (GtkWidget *widget,
242 GdkDragContext *context,
245 GtkSelectionData *selection_data,
249 /* tree_model signals */
250 static void pspp_sheet_view_set_adjustments (PsppSheetView *tree_view,
252 GtkAdjustment *vadj);
253 static gboolean pspp_sheet_view_real_move_cursor (PsppSheetView *tree_view,
254 GtkMovementStep step,
256 static gboolean pspp_sheet_view_real_select_all (PsppSheetView *tree_view);
257 static gboolean pspp_sheet_view_real_unselect_all (PsppSheetView *tree_view);
258 static gboolean pspp_sheet_view_real_select_cursor_row (PsppSheetView *tree_view,
259 gboolean start_editing);
260 static gboolean pspp_sheet_view_real_toggle_cursor_row (PsppSheetView *tree_view);
261 static void pspp_sheet_view_row_changed (GtkTreeModel *model,
265 static void pspp_sheet_view_row_inserted (GtkTreeModel *model,
269 static void pspp_sheet_view_row_deleted (GtkTreeModel *model,
272 static void pspp_sheet_view_rows_reordered (GtkTreeModel *model,
278 /* Incremental reflow */
279 static gint validate_row (PsppSheetView *tree_view,
283 static void validate_visible_area (PsppSheetView *tree_view);
284 static gboolean validate_rows_handler (PsppSheetView *tree_view);
285 static gboolean presize_handler_callback (gpointer data);
286 static void install_presize_handler (PsppSheetView *tree_view);
287 static void install_scroll_sync_handler (PsppSheetView *tree_view);
288 static void pspp_sheet_view_set_top_row (PsppSheetView *tree_view,
291 static void pspp_sheet_view_dy_to_top_row (PsppSheetView *tree_view);
292 static void pspp_sheet_view_top_row_to_dy (PsppSheetView *tree_view);
293 static void invalidate_empty_focus (PsppSheetView *tree_view);
295 /* Internal functions */
296 static void pspp_sheet_view_add_move_binding (GtkBindingSet *binding_set,
299 gboolean add_shifted_binding,
300 GtkMovementStep step,
302 static void pspp_sheet_view_queue_draw_path (PsppSheetView *tree_view,
304 const GdkRectangle *clip_rect);
305 static gint pspp_sheet_view_new_column_width (PsppSheetView *tree_view,
308 static void pspp_sheet_view_adjustment_changed (GtkAdjustment *adjustment,
309 PsppSheetView *tree_view);
310 static void pspp_sheet_view_clamp_node_visible (PsppSheetView *tree_view,
312 static void pspp_sheet_view_clamp_column_visible (PsppSheetView *tree_view,
313 PsppSheetViewColumn *column,
314 gboolean focus_to_cell);
315 static gboolean pspp_sheet_view_maybe_begin_dragging_row (PsppSheetView *tree_view,
316 GdkEventMotion *event);
317 static void pspp_sheet_view_focus_to_cursor (PsppSheetView *tree_view);
318 static void pspp_sheet_view_move_cursor_up_down (PsppSheetView *tree_view,
320 static void pspp_sheet_view_move_cursor_page_up_down (PsppSheetView *tree_view,
322 static void pspp_sheet_view_move_cursor_left_right (PsppSheetView *tree_view,
324 static void pspp_sheet_view_move_cursor_start_end (PsppSheetView *tree_view,
326 static void pspp_sheet_view_real_set_cursor (PsppSheetView *tree_view,
328 gboolean clear_and_select,
329 gboolean clamp_node);
330 static gboolean pspp_sheet_view_has_special_cell (PsppSheetView *tree_view);
331 static void pspp_sheet_view_stop_rubber_band (PsppSheetView *tree_view);
332 static void update_prelight (PsppSheetView *tree_view,
335 static void initialize_fixed_height_mode (PsppSheetView *tree_view);
337 /* interactive search */
338 static void pspp_sheet_view_ensure_interactive_directory (PsppSheetView *tree_view);
339 static void pspp_sheet_view_search_dialog_hide (GtkWidget *search_dialog,
340 PsppSheetView *tree_view);
341 static void pspp_sheet_view_search_position_func (PsppSheetView *tree_view,
342 GtkWidget *search_dialog,
344 static void pspp_sheet_view_search_disable_popdown (GtkEntry *entry,
347 static void pspp_sheet_view_search_preedit_changed (GtkIMContext *im_context,
348 PsppSheetView *tree_view);
349 static void pspp_sheet_view_search_activate (GtkEntry *entry,
350 PsppSheetView *tree_view);
351 static gboolean pspp_sheet_view_real_search_enable_popdown(gpointer data);
352 static void pspp_sheet_view_search_enable_popdown (GtkWidget *widget,
354 static gboolean pspp_sheet_view_search_delete_event (GtkWidget *widget,
356 PsppSheetView *tree_view);
357 static gboolean pspp_sheet_view_search_button_press_event (GtkWidget *widget,
358 GdkEventButton *event,
359 PsppSheetView *tree_view);
360 static gboolean pspp_sheet_view_search_scroll_event (GtkWidget *entry,
361 GdkEventScroll *event,
362 PsppSheetView *tree_view);
363 static gboolean pspp_sheet_view_search_key_press_event (GtkWidget *entry,
365 PsppSheetView *tree_view);
366 static gboolean pspp_sheet_view_search_move (GtkWidget *window,
367 PsppSheetView *tree_view,
369 static gboolean pspp_sheet_view_search_equal_func (GtkTreeModel *model,
373 gpointer search_data);
374 static gboolean pspp_sheet_view_search_iter (GtkTreeModel *model,
375 PsppSheetSelection *selection,
380 static void pspp_sheet_view_search_init (GtkWidget *entry,
381 PsppSheetView *tree_view);
382 static void pspp_sheet_view_put (PsppSheetView *tree_view,
383 GtkWidget *child_widget,
388 static gboolean pspp_sheet_view_start_editing (PsppSheetView *tree_view,
389 GtkTreePath *cursor_path);
390 static gboolean pspp_sheet_view_editable_button_press_event (GtkWidget *,
393 static void pspp_sheet_view_editable_clicked (GtkButton *, PsppSheetView *);
394 static void pspp_sheet_view_real_start_editing (PsppSheetView *tree_view,
395 PsppSheetViewColumn *column,
397 GtkCellEditable *cell_editable,
398 GdkRectangle *cell_area,
401 static gboolean pspp_sheet_view_real_start_interactive_search (PsppSheetView *tree_view,
402 gboolean keybinding);
403 static gboolean pspp_sheet_view_start_interactive_search (PsppSheetView *tree_view);
404 static PsppSheetViewColumn *pspp_sheet_view_get_drop_column (PsppSheetView *tree_view,
405 PsppSheetViewColumn *column,
408 pspp_sheet_view_adjust_cell_area (PsppSheetView *tree_view,
409 PsppSheetViewColumn *column,
410 const GdkRectangle *background_area,
411 gboolean subtract_focus_rect,
412 GdkRectangle *cell_area);
413 static gint pspp_sheet_view_find_offset (PsppSheetView *tree_view,
418 static void pspp_sheet_view_buildable_add_child (GtkBuildable *tree_view,
422 static void pspp_sheet_view_buildable_init (GtkBuildableIface *iface);
425 static gboolean scroll_row_timeout (gpointer data);
426 static void add_scroll_timeout (PsppSheetView *tree_view);
427 static void remove_scroll_timeout (PsppSheetView *tree_view);
429 static guint tree_view_signals [LAST_SIGNAL] = { 0 };
431 static GtkBindingSet *edit_bindings;
438 G_DEFINE_TYPE_WITH_CODE (PsppSheetView, pspp_sheet_view, GTK_TYPE_CONTAINER,
439 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
440 pspp_sheet_view_buildable_init))
443 pspp_sheet_view_class_init (PsppSheetViewClass *class)
445 GObjectClass *o_class;
446 GtkWidgetClass *widget_class;
447 GtkContainerClass *container_class;
448 GtkBindingSet *binding_set[2];
451 binding_set[0] = gtk_binding_set_by_class (class);
453 binding_set[1] = gtk_binding_set_new ("PsppSheetViewEditing");
454 edit_bindings = binding_set[1];
456 o_class = (GObjectClass *) class;
457 widget_class = (GtkWidgetClass *) class;
458 container_class = (GtkContainerClass *) class;
460 /* GObject signals */
461 o_class->set_property = pspp_sheet_view_set_property;
462 o_class->get_property = pspp_sheet_view_get_property;
463 o_class->finalize = pspp_sheet_view_finalize;
464 o_class->dispose = pspp_sheet_view_dispose;
466 /* GtkWidget signals */
467 widget_class->map = pspp_sheet_view_map;
468 widget_class->realize = pspp_sheet_view_realize;
469 widget_class->unrealize = pspp_sheet_view_unrealize;
470 widget_class->size_request = pspp_sheet_view_size_request;
471 widget_class->size_allocate = pspp_sheet_view_size_allocate;
472 widget_class->button_press_event = pspp_sheet_view_button_press;
473 widget_class->button_release_event = pspp_sheet_view_button_release;
474 widget_class->grab_broken_event = pspp_sheet_view_grab_broken;
475 /*widget_class->configure_event = pspp_sheet_view_configure;*/
476 widget_class->motion_notify_event = pspp_sheet_view_motion;
477 widget_class->expose_event = pspp_sheet_view_expose;
478 widget_class->key_press_event = pspp_sheet_view_key_press;
479 widget_class->key_release_event = pspp_sheet_view_key_release;
480 widget_class->enter_notify_event = pspp_sheet_view_enter_notify;
481 widget_class->leave_notify_event = pspp_sheet_view_leave_notify;
482 widget_class->focus_out_event = pspp_sheet_view_focus_out;
483 widget_class->drag_begin = pspp_sheet_view_drag_begin;
484 widget_class->drag_end = pspp_sheet_view_drag_end;
485 widget_class->drag_data_get = pspp_sheet_view_drag_data_get;
486 widget_class->drag_data_delete = pspp_sheet_view_drag_data_delete;
487 widget_class->drag_leave = pspp_sheet_view_drag_leave;
488 widget_class->drag_motion = pspp_sheet_view_drag_motion;
489 widget_class->drag_drop = pspp_sheet_view_drag_drop;
490 widget_class->drag_data_received = pspp_sheet_view_drag_data_received;
491 widget_class->focus = pspp_sheet_view_focus;
492 widget_class->grab_focus = pspp_sheet_view_grab_focus;
493 widget_class->style_set = pspp_sheet_view_style_set;
494 widget_class->grab_notify = pspp_sheet_view_grab_notify;
495 widget_class->state_changed = pspp_sheet_view_state_changed;
497 /* GtkContainer signals */
498 container_class->remove = pspp_sheet_view_remove;
499 container_class->forall = pspp_sheet_view_forall;
500 container_class->set_focus_child = pspp_sheet_view_set_focus_child;
502 class->set_scroll_adjustments = pspp_sheet_view_set_adjustments;
503 class->move_cursor = pspp_sheet_view_real_move_cursor;
504 class->select_all = pspp_sheet_view_real_select_all;
505 class->unselect_all = pspp_sheet_view_real_unselect_all;
506 class->select_cursor_row = pspp_sheet_view_real_select_cursor_row;
507 class->toggle_cursor_row = pspp_sheet_view_real_toggle_cursor_row;
508 class->start_interactive_search = pspp_sheet_view_start_interactive_search;
512 g_object_class_install_property (o_class,
514 g_param_spec_object ("model",
515 P_("TreeView Model"),
516 P_("The model for the tree view"),
518 GTK_PARAM_READWRITE));
520 g_object_class_install_property (o_class,
522 g_param_spec_object ("hadjustment",
523 P_("Horizontal Adjustment"),
524 P_("Horizontal Adjustment for the widget"),
526 GTK_PARAM_READWRITE));
528 g_object_class_install_property (o_class,
530 g_param_spec_object ("vadjustment",
531 P_("Vertical Adjustment"),
532 P_("Vertical Adjustment for the widget"),
534 GTK_PARAM_READWRITE));
536 g_object_class_install_property (o_class,
537 PROP_HEADERS_VISIBLE,
538 g_param_spec_boolean ("headers-visible",
539 P_("Headers Visible"),
540 P_("Show the column header buttons"),
542 GTK_PARAM_READWRITE));
544 g_object_class_install_property (o_class,
545 PROP_HEADERS_CLICKABLE,
546 g_param_spec_boolean ("headers-clickable",
547 P_("Headers Clickable"),
548 P_("Column headers respond to click events"),
550 GTK_PARAM_READWRITE));
552 g_object_class_install_property (o_class,
554 g_param_spec_boolean ("reorderable",
556 P_("View is reorderable"),
558 GTK_PARAM_READWRITE));
560 g_object_class_install_property (o_class,
562 g_param_spec_boolean ("rules-hint",
564 P_("Set a hint to the theme engine to draw rows in alternating colors"),
566 GTK_PARAM_READWRITE));
568 g_object_class_install_property (o_class,
570 g_param_spec_boolean ("enable-search",
572 P_("View allows user to search through columns interactively"),
574 GTK_PARAM_READWRITE));
576 g_object_class_install_property (o_class,
578 g_param_spec_int ("search-column",
580 P_("Model column to search through during interactive search"),
584 GTK_PARAM_READWRITE));
587 * PsppSheetView:hover-selection:
589 * Enables of disables the hover selection mode of @tree_view.
590 * Hover selection makes the selected row follow the pointer.
591 * Currently, this works only for the selection modes
592 * %PSPP_SHEET_SELECTION_SINGLE and %PSPP_SHEET_SELECTION_BROWSE.
594 * This mode is primarily intended for treeviews in popups, e.g.
595 * in #GtkComboBox or #GtkEntryCompletion.
599 g_object_class_install_property (o_class,
600 PROP_HOVER_SELECTION,
601 g_param_spec_boolean ("hover-selection",
602 P_("Hover Selection"),
603 P_("Whether the selection should follow the pointer"),
605 GTK_PARAM_READWRITE));
607 g_object_class_install_property (o_class,
609 g_param_spec_boolean ("rubber-banding",
610 P_("Rubber Banding"),
611 P_("Whether to enable selection of multiple items by dragging the mouse pointer"),
613 GTK_PARAM_READWRITE));
615 g_object_class_install_property (o_class,
616 PROP_ENABLE_GRID_LINES,
617 g_param_spec_enum ("enable-grid-lines",
618 P_("Enable Grid Lines"),
619 P_("Whether grid lines should be drawn in the tree view"),
620 PSPP_TYPE_SHEET_VIEW_GRID_LINES,
621 PSPP_SHEET_VIEW_GRID_LINES_NONE,
622 GTK_PARAM_READWRITE));
624 g_object_class_install_property (o_class,
626 g_param_spec_int ("tooltip-column",
627 P_("Tooltip Column"),
628 P_("The column in the model containing the tooltip texts for the rows"),
632 GTK_PARAM_READWRITE));
634 g_object_class_install_property (o_class,
636 g_param_spec_enum ("special-cells",
638 P_("Whether rows have special cells."),
639 PSPP_TYPE_SHEET_VIEW_SPECIAL_CELLS,
640 PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT,
641 GTK_PARAM_READWRITE));
643 g_object_class_install_property (o_class,
645 g_param_spec_int ("fixed-height",
647 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."),
651 GTK_PARAM_READWRITE));
653 g_object_class_install_property (o_class,
654 PROP_FIXED_HEIGHT_SET,
655 g_param_spec_boolean ("fixed-height-set",
656 P_("Fixed Height Set"),
657 P_("Whether fixed-height was set externally."),
659 GTK_PARAM_READWRITE));
661 /* Style properties */
662 #define _TREE_VIEW_EXPANDER_SIZE 12
663 #define _TREE_VIEW_VERTICAL_SEPARATOR 2
664 #define _TREE_VIEW_HORIZONTAL_SEPARATOR 2
666 gtk_widget_class_install_style_property (widget_class,
667 g_param_spec_int ("expander-size",
669 P_("Size of the expander arrow"),
672 _TREE_VIEW_EXPANDER_SIZE,
673 GTK_PARAM_READABLE));
675 gtk_widget_class_install_style_property (widget_class,
676 g_param_spec_int ("vertical-separator",
677 P_("Vertical Separator Width"),
678 P_("Vertical space between cells. Must be an even number"),
681 _TREE_VIEW_VERTICAL_SEPARATOR,
682 GTK_PARAM_READABLE));
684 gtk_widget_class_install_style_property (widget_class,
685 g_param_spec_int ("horizontal-separator",
686 P_("Horizontal Separator Width"),
687 P_("Horizontal space between cells. Must be an even number"),
690 _TREE_VIEW_HORIZONTAL_SEPARATOR,
691 GTK_PARAM_READABLE));
693 gtk_widget_class_install_style_property (widget_class,
694 g_param_spec_boolean ("allow-rules",
696 P_("Allow drawing of alternating color rows"),
698 GTK_PARAM_READABLE));
700 gtk_widget_class_install_style_property (widget_class,
701 g_param_spec_boxed ("even-row-color",
702 P_("Even Row Color"),
703 P_("Color to use for even rows"),
705 GTK_PARAM_READABLE));
707 gtk_widget_class_install_style_property (widget_class,
708 g_param_spec_boxed ("odd-row-color",
710 P_("Color to use for odd rows"),
712 GTK_PARAM_READABLE));
714 gtk_widget_class_install_style_property (widget_class,
715 g_param_spec_boolean ("row-ending-details",
716 P_("Row Ending details"),
717 P_("Enable extended row background theming"),
719 GTK_PARAM_READABLE));
721 gtk_widget_class_install_style_property (widget_class,
722 g_param_spec_int ("grid-line-width",
723 P_("Grid line width"),
724 P_("Width, in pixels, of the tree view grid lines"),
726 GTK_PARAM_READABLE));
728 gtk_widget_class_install_style_property (widget_class,
729 g_param_spec_int ("tree-line-width",
730 P_("Tree line width"),
731 P_("Width, in pixels, of the tree view lines"),
733 GTK_PARAM_READABLE));
735 gtk_widget_class_install_style_property (widget_class,
736 g_param_spec_string ("tree-line-pattern",
737 P_("Tree line pattern"),
738 P_("Dash pattern used to draw the tree view lines"),
740 GTK_PARAM_READABLE));
744 * PsppSheetView::set-scroll-adjustments
745 * @horizontal: the horizontal #GtkAdjustment
746 * @vertical: the vertical #GtkAdjustment
748 * Set the scroll adjustments for the tree view. Usually scrolled containers
749 * like #GtkScrolledWindow will emit this signal to connect two instances
750 * of #GtkScrollbar to the scroll directions of the #PsppSheetView.
752 widget_class->set_scroll_adjustments_signal =
753 g_signal_new ("set-scroll-adjustments",
754 G_TYPE_FROM_CLASS (o_class),
755 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
756 G_STRUCT_OFFSET (PsppSheetViewClass, set_scroll_adjustments),
758 psppire_marshal_VOID__OBJECT_OBJECT,
761 GTK_TYPE_ADJUSTMENT);
764 * PsppSheetView::row-activated:
765 * @tree_view: the object on which the signal is emitted
766 * @path: the #GtkTreePath for the activated row
767 * @column: the #PsppSheetViewColumn in which the activation occurred
769 * The "row-activated" signal is emitted when the method
770 * pspp_sheet_view_row_activated() is called or the user double clicks
771 * a treeview row. It is also emitted when a non-editable row is
772 * selected and one of the keys: Space, Shift+Space, Return or
775 * For selection handling refer to the <link linkend="TreeWidget">tree
776 * widget conceptual overview</link> as well as #PsppSheetSelection.
778 tree_view_signals[ROW_ACTIVATED] =
779 g_signal_new ("row-activated",
780 G_TYPE_FROM_CLASS (o_class),
781 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
782 G_STRUCT_OFFSET (PsppSheetViewClass, row_activated),
784 psppire_marshal_VOID__BOXED_OBJECT,
787 PSPP_TYPE_SHEET_VIEW_COLUMN);
790 * PsppSheetView::columns-changed:
791 * @tree_view: the object on which the signal is emitted
793 * The number of columns of the treeview has changed.
795 tree_view_signals[COLUMNS_CHANGED] =
796 g_signal_new ("columns-changed",
797 G_TYPE_FROM_CLASS (o_class),
799 G_STRUCT_OFFSET (PsppSheetViewClass, columns_changed),
801 g_cclosure_marshal_VOID__VOID,
805 * PsppSheetView::cursor-changed:
806 * @tree_view: the object on which the signal is emitted
808 * The position of the cursor (focused cell) has changed.
810 tree_view_signals[CURSOR_CHANGED] =
811 g_signal_new ("cursor-changed",
812 G_TYPE_FROM_CLASS (o_class),
814 G_STRUCT_OFFSET (PsppSheetViewClass, cursor_changed),
816 g_cclosure_marshal_VOID__VOID,
819 tree_view_signals[MOVE_CURSOR] =
820 g_signal_new ("move-cursor",
821 G_TYPE_FROM_CLASS (o_class),
822 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
823 G_STRUCT_OFFSET (PsppSheetViewClass, move_cursor),
825 psppire_marshal_BOOLEAN__ENUM_INT,
827 GTK_TYPE_MOVEMENT_STEP,
830 tree_view_signals[SELECT_ALL] =
831 g_signal_new ("select-all",
832 G_TYPE_FROM_CLASS (o_class),
833 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
834 G_STRUCT_OFFSET (PsppSheetViewClass, select_all),
836 psppire_marshal_BOOLEAN__VOID,
839 tree_view_signals[UNSELECT_ALL] =
840 g_signal_new ("unselect-all",
841 G_TYPE_FROM_CLASS (o_class),
842 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
843 G_STRUCT_OFFSET (PsppSheetViewClass, unselect_all),
845 psppire_marshal_BOOLEAN__VOID,
848 tree_view_signals[SELECT_CURSOR_ROW] =
849 g_signal_new ("select-cursor-row",
850 G_TYPE_FROM_CLASS (o_class),
851 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
852 G_STRUCT_OFFSET (PsppSheetViewClass, select_cursor_row),
854 psppire_marshal_BOOLEAN__BOOLEAN,
858 tree_view_signals[TOGGLE_CURSOR_ROW] =
859 g_signal_new ("toggle-cursor-row",
860 G_TYPE_FROM_CLASS (o_class),
861 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
862 G_STRUCT_OFFSET (PsppSheetViewClass, toggle_cursor_row),
864 psppire_marshal_BOOLEAN__VOID,
867 tree_view_signals[START_INTERACTIVE_SEARCH] =
868 g_signal_new ("start-interactive-search",
869 G_TYPE_FROM_CLASS (o_class),
870 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
871 G_STRUCT_OFFSET (PsppSheetViewClass, start_interactive_search),
873 psppire_marshal_BOOLEAN__VOID,
877 for (i = 0; i < 2; i++)
879 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Up, 0, TRUE,
880 GTK_MOVEMENT_DISPLAY_LINES, -1);
881 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Up, 0, TRUE,
882 GTK_MOVEMENT_DISPLAY_LINES, -1);
884 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Down, 0, TRUE,
885 GTK_MOVEMENT_DISPLAY_LINES, 1);
886 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Down, 0, TRUE,
887 GTK_MOVEMENT_DISPLAY_LINES, 1);
889 pspp_sheet_view_add_move_binding (binding_set[i], GDK_p, GDK_CONTROL_MASK, FALSE,
890 GTK_MOVEMENT_DISPLAY_LINES, -1);
892 pspp_sheet_view_add_move_binding (binding_set[i], GDK_n, GDK_CONTROL_MASK, FALSE,
893 GTK_MOVEMENT_DISPLAY_LINES, 1);
895 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Home, 0, TRUE,
896 GTK_MOVEMENT_BUFFER_ENDS, -1);
897 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Home, 0, TRUE,
898 GTK_MOVEMENT_BUFFER_ENDS, -1);
900 pspp_sheet_view_add_move_binding (binding_set[i], GDK_End, 0, TRUE,
901 GTK_MOVEMENT_BUFFER_ENDS, 1);
902 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_End, 0, TRUE,
903 GTK_MOVEMENT_BUFFER_ENDS, 1);
905 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Page_Up, 0, TRUE,
906 GTK_MOVEMENT_PAGES, -1);
907 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Page_Up, 0, TRUE,
908 GTK_MOVEMENT_PAGES, -1);
910 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Page_Down, 0, TRUE,
911 GTK_MOVEMENT_PAGES, 1);
912 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Page_Down, 0, TRUE,
913 GTK_MOVEMENT_PAGES, 1);
916 gtk_binding_entry_add_signal (binding_set[i], GDK_Right, 0, "move-cursor", 2,
917 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
920 gtk_binding_entry_add_signal (binding_set[i], GDK_Left, 0, "move-cursor", 2,
921 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
924 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Right, 0, "move-cursor", 2,
925 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
928 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Left, 0, "move-cursor", 2,
929 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
932 gtk_binding_entry_add_signal (binding_set[i], GDK_Right, GDK_CONTROL_MASK,
934 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
937 gtk_binding_entry_add_signal (binding_set[i], GDK_Left, GDK_CONTROL_MASK,
939 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
942 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Right, GDK_CONTROL_MASK,
944 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
947 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Left, GDK_CONTROL_MASK,
949 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
952 gtk_binding_entry_add_signal (binding_set[i], GDK_f, GDK_CONTROL_MASK, "start-interactive-search", 0);
954 gtk_binding_entry_add_signal (binding_set[i], GDK_F, GDK_CONTROL_MASK, "start-interactive-search", 0);
957 gtk_binding_entry_add_signal (binding_set[0], GDK_space, GDK_CONTROL_MASK, "toggle-cursor-row", 0);
958 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Space, GDK_CONTROL_MASK, "toggle-cursor-row", 0);
960 gtk_binding_entry_add_signal (binding_set[0], GDK_a, GDK_CONTROL_MASK, "select-all", 0);
961 gtk_binding_entry_add_signal (binding_set[0], GDK_slash, GDK_CONTROL_MASK, "select-all", 0);
963 gtk_binding_entry_add_signal (binding_set[0], GDK_A, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "unselect-all", 0);
964 gtk_binding_entry_add_signal (binding_set[0], GDK_backslash, GDK_CONTROL_MASK, "unselect-all", 0);
966 gtk_binding_entry_add_signal (binding_set[0], GDK_space, GDK_SHIFT_MASK, "select-cursor-row", 1,
967 G_TYPE_BOOLEAN, TRUE);
968 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Space, GDK_SHIFT_MASK, "select-cursor-row", 1,
969 G_TYPE_BOOLEAN, TRUE);
971 gtk_binding_entry_add_signal (binding_set[0], GDK_space, 0, "select-cursor-row", 1,
972 G_TYPE_BOOLEAN, TRUE);
973 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Space, 0, "select-cursor-row", 1,
974 G_TYPE_BOOLEAN, TRUE);
975 gtk_binding_entry_add_signal (binding_set[0], GDK_Return, 0, "select-cursor-row", 1,
976 G_TYPE_BOOLEAN, TRUE);
977 gtk_binding_entry_add_signal (binding_set[0], GDK_ISO_Enter, 0, "select-cursor-row", 1,
978 G_TYPE_BOOLEAN, TRUE);
979 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Enter, 0, "select-cursor-row", 1,
980 G_TYPE_BOOLEAN, TRUE);
982 gtk_binding_entry_add_signal (binding_set[0], GDK_BackSpace, 0, "select-cursor-parent", 0);
983 gtk_binding_entry_add_signal (binding_set[0], GDK_BackSpace, GDK_CONTROL_MASK, "select-cursor-parent", 0);
985 g_type_class_add_private (o_class, sizeof (PsppSheetViewPrivate));
989 pspp_sheet_view_buildable_init (GtkBuildableIface *iface)
991 iface->add_child = pspp_sheet_view_buildable_add_child;
995 pspp_sheet_view_init (PsppSheetView *tree_view)
997 tree_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (tree_view, PSPP_TYPE_SHEET_VIEW, PsppSheetViewPrivate);
999 gtk_widget_set_can_focus (GTK_WIDGET (tree_view), TRUE);
1000 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (tree_view), FALSE);
1002 tree_view->priv->flags = PSPP_SHEET_VIEW_DRAW_KEYFOCUS
1003 | PSPP_SHEET_VIEW_HEADERS_VISIBLE;
1005 /* We need some padding */
1006 tree_view->priv->selected = range_tower_create ();
1007 tree_view->priv->dy = 0;
1008 tree_view->priv->cursor_offset = 0;
1009 tree_view->priv->n_columns = 0;
1010 tree_view->priv->header_height = 1;
1011 tree_view->priv->x_drag = 0;
1012 tree_view->priv->drag_pos = -1;
1013 tree_view->priv->header_has_focus = FALSE;
1014 tree_view->priv->pressed_button = -1;
1015 tree_view->priv->press_start_x = -1;
1016 tree_view->priv->press_start_y = -1;
1017 tree_view->priv->reorderable = FALSE;
1018 tree_view->priv->presize_handler_timer = 0;
1019 tree_view->priv->scroll_sync_timer = 0;
1020 tree_view->priv->fixed_height = -1;
1021 tree_view->priv->fixed_height_set = FALSE;
1022 pspp_sheet_view_set_adjustments (tree_view, NULL, NULL);
1023 tree_view->priv->selection = _pspp_sheet_selection_new_with_tree_view (tree_view);
1024 tree_view->priv->enable_search = TRUE;
1025 tree_view->priv->search_column = -1;
1026 tree_view->priv->search_position_func = pspp_sheet_view_search_position_func;
1027 tree_view->priv->search_equal_func = pspp_sheet_view_search_equal_func;
1028 tree_view->priv->search_custom_entry_set = FALSE;
1029 tree_view->priv->typeselect_flush_timeout = 0;
1030 tree_view->priv->init_hadjust_value = TRUE;
1031 tree_view->priv->width = 0;
1033 tree_view->priv->hover_selection = FALSE;
1035 tree_view->priv->rubber_banding_enable = FALSE;
1037 tree_view->priv->grid_lines = PSPP_SHEET_VIEW_GRID_LINES_NONE;
1039 tree_view->priv->tooltip_column = -1;
1041 tree_view->priv->special_cells = PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT;
1043 tree_view->priv->post_validation_flag = FALSE;
1045 tree_view->priv->last_button_x = -1;
1046 tree_view->priv->last_button_y = -1;
1048 tree_view->priv->event_last_x = -10000;
1049 tree_view->priv->event_last_y = -10000;
1051 tree_view->priv->prelight_node = -1;
1052 tree_view->priv->rubber_band_start_node = -1;
1053 tree_view->priv->rubber_band_end_node = -1;
1055 tree_view->priv->anchor_column = NULL;
1057 tree_view->priv->button_style = NULL;
1059 tree_view->dispose_has_run = FALSE;
1068 pspp_sheet_view_set_property (GObject *object,
1070 const GValue *value,
1073 PsppSheetView *tree_view;
1075 tree_view = PSPP_SHEET_VIEW (object);
1080 pspp_sheet_view_set_model (tree_view, g_value_get_object (value));
1082 case PROP_HADJUSTMENT:
1083 pspp_sheet_view_set_hadjustment (tree_view, g_value_get_object (value));
1085 case PROP_VADJUSTMENT:
1086 pspp_sheet_view_set_vadjustment (tree_view, g_value_get_object (value));
1088 case PROP_HEADERS_VISIBLE:
1089 pspp_sheet_view_set_headers_visible (tree_view, g_value_get_boolean (value));
1091 case PROP_HEADERS_CLICKABLE:
1092 pspp_sheet_view_set_headers_clickable (tree_view, g_value_get_boolean (value));
1094 case PROP_REORDERABLE:
1095 pspp_sheet_view_set_reorderable (tree_view, g_value_get_boolean (value));
1097 case PROP_RULES_HINT:
1098 pspp_sheet_view_set_rules_hint (tree_view, g_value_get_boolean (value));
1100 case PROP_ENABLE_SEARCH:
1101 pspp_sheet_view_set_enable_search (tree_view, g_value_get_boolean (value));
1103 case PROP_SEARCH_COLUMN:
1104 pspp_sheet_view_set_search_column (tree_view, g_value_get_int (value));
1106 case PROP_HOVER_SELECTION:
1107 tree_view->priv->hover_selection = g_value_get_boolean (value);
1109 case PROP_RUBBER_BANDING:
1110 tree_view->priv->rubber_banding_enable = g_value_get_boolean (value);
1112 case PROP_ENABLE_GRID_LINES:
1113 pspp_sheet_view_set_grid_lines (tree_view, g_value_get_enum (value));
1115 case PROP_TOOLTIP_COLUMN:
1116 pspp_sheet_view_set_tooltip_column (tree_view, g_value_get_int (value));
1118 case PROP_SPECIAL_CELLS:
1119 pspp_sheet_view_set_special_cells (tree_view, g_value_get_enum (value));
1121 case PROP_FIXED_HEIGHT:
1122 pspp_sheet_view_set_fixed_height (tree_view, g_value_get_int (value));
1124 case PROP_FIXED_HEIGHT_SET:
1125 if (g_value_get_boolean (value))
1127 if (!tree_view->priv->fixed_height_set
1128 && tree_view->priv->fixed_height >= 0)
1130 tree_view->priv->fixed_height_set = true;
1131 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
1136 if (tree_view->priv->fixed_height_set)
1138 tree_view->priv->fixed_height_set = false;
1139 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
1140 install_presize_handler (tree_view);
1145 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1151 pspp_sheet_view_get_property (GObject *object,
1156 PsppSheetView *tree_view;
1158 tree_view = PSPP_SHEET_VIEW (object);
1163 g_value_set_object (value, tree_view->priv->model);
1165 case PROP_HADJUSTMENT:
1166 g_value_set_object (value, tree_view->priv->hadjustment);
1168 case PROP_VADJUSTMENT:
1169 g_value_set_object (value, tree_view->priv->vadjustment);
1171 case PROP_HEADERS_VISIBLE:
1172 g_value_set_boolean (value, pspp_sheet_view_get_headers_visible (tree_view));
1174 case PROP_HEADERS_CLICKABLE:
1175 g_value_set_boolean (value, pspp_sheet_view_get_headers_clickable (tree_view));
1177 case PROP_REORDERABLE:
1178 g_value_set_boolean (value, tree_view->priv->reorderable);
1180 case PROP_RULES_HINT:
1181 g_value_set_boolean (value, tree_view->priv->has_rules);
1183 case PROP_ENABLE_SEARCH:
1184 g_value_set_boolean (value, tree_view->priv->enable_search);
1186 case PROP_SEARCH_COLUMN:
1187 g_value_set_int (value, tree_view->priv->search_column);
1189 case PROP_HOVER_SELECTION:
1190 g_value_set_boolean (value, tree_view->priv->hover_selection);
1192 case PROP_RUBBER_BANDING:
1193 g_value_set_boolean (value, tree_view->priv->rubber_banding_enable);
1195 case PROP_ENABLE_GRID_LINES:
1196 g_value_set_enum (value, tree_view->priv->grid_lines);
1198 case PROP_TOOLTIP_COLUMN:
1199 g_value_set_int (value, tree_view->priv->tooltip_column);
1201 case PROP_SPECIAL_CELLS:
1202 g_value_set_enum (value, tree_view->priv->special_cells);
1204 case PROP_FIXED_HEIGHT:
1205 g_value_set_int (value, pspp_sheet_view_get_fixed_height (tree_view));
1207 case PROP_FIXED_HEIGHT_SET:
1208 g_value_set_boolean (value, tree_view->priv->fixed_height_set);
1211 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1217 pspp_sheet_view_dispose (GObject *object)
1219 PsppSheetView *tree_view = PSPP_SHEET_VIEW (object);
1221 if (tree_view->dispose_has_run)
1224 tree_view->dispose_has_run = TRUE;
1226 if (tree_view->priv->selection != NULL)
1228 _pspp_sheet_selection_set_tree_view (tree_view->priv->selection, NULL);
1229 g_object_unref (tree_view->priv->selection);
1230 tree_view->priv->selection = NULL;
1233 if (tree_view->priv->hadjustment)
1235 g_object_unref (tree_view->priv->hadjustment);
1236 tree_view->priv->hadjustment = NULL;
1238 if (tree_view->priv->vadjustment)
1240 g_object_unref (tree_view->priv->vadjustment);
1241 tree_view->priv->vadjustment = NULL;
1244 if (tree_view->priv->button_style)
1246 g_object_unref (tree_view->priv->button_style);
1247 tree_view->priv->button_style = NULL;
1251 G_OBJECT_CLASS (pspp_sheet_view_parent_class)->dispose (object);
1257 pspp_sheet_view_buildable_add_child (GtkBuildable *tree_view,
1258 GtkBuilder *builder,
1262 pspp_sheet_view_append_column (PSPP_SHEET_VIEW (tree_view), PSPP_SHEET_VIEW_COLUMN (child));
1266 pspp_sheet_view_finalize (GObject *object)
1268 PsppSheetView *tree_view = PSPP_SHEET_VIEW (object);
1270 pspp_sheet_view_stop_editing (tree_view, TRUE);
1272 if (tree_view->priv->selected != NULL)
1274 range_tower_destroy (tree_view->priv->selected);
1275 tree_view->priv->selected = NULL;
1279 tree_view->priv->prelight_node = -1;
1282 if (tree_view->priv->scroll_to_path != NULL)
1284 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
1285 tree_view->priv->scroll_to_path = NULL;
1288 if (tree_view->priv->drag_dest_row != NULL)
1290 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
1291 tree_view->priv->drag_dest_row = NULL;
1294 if (tree_view->priv->top_row != NULL)
1296 gtk_tree_row_reference_free (tree_view->priv->top_row);
1297 tree_view->priv->top_row = NULL;
1300 if (tree_view->priv->column_drop_func_data &&
1301 tree_view->priv->column_drop_func_data_destroy)
1303 tree_view->priv->column_drop_func_data_destroy (tree_view->priv->column_drop_func_data);
1304 tree_view->priv->column_drop_func_data = NULL;
1307 if (tree_view->priv->destroy_count_destroy &&
1308 tree_view->priv->destroy_count_data)
1310 tree_view->priv->destroy_count_destroy (tree_view->priv->destroy_count_data);
1311 tree_view->priv->destroy_count_data = NULL;
1314 gtk_tree_row_reference_free (tree_view->priv->cursor);
1315 tree_view->priv->cursor = NULL;
1317 gtk_tree_row_reference_free (tree_view->priv->anchor);
1318 tree_view->priv->anchor = NULL;
1320 /* destroy interactive search dialog */
1321 if (tree_view->priv->search_window)
1323 gtk_widget_destroy (tree_view->priv->search_window);
1324 tree_view->priv->search_window = NULL;
1325 tree_view->priv->search_entry = NULL;
1326 if (tree_view->priv->typeselect_flush_timeout)
1328 g_source_remove (tree_view->priv->typeselect_flush_timeout);
1329 tree_view->priv->typeselect_flush_timeout = 0;
1333 if (tree_view->priv->search_destroy && tree_view->priv->search_user_data)
1335 tree_view->priv->search_destroy (tree_view->priv->search_user_data);
1336 tree_view->priv->search_user_data = NULL;
1339 if (tree_view->priv->search_position_destroy && tree_view->priv->search_position_user_data)
1341 tree_view->priv->search_position_destroy (tree_view->priv->search_position_user_data);
1342 tree_view->priv->search_position_user_data = NULL;
1345 pspp_sheet_view_set_model (tree_view, NULL);
1348 G_OBJECT_CLASS (pspp_sheet_view_parent_class)->finalize (object);
1353 /* GtkWidget Methods
1356 /* GtkWidget::map helper */
1358 pspp_sheet_view_map_buttons (PsppSheetView *tree_view)
1362 g_return_if_fail (gtk_widget_get_mapped (GTK_WIDGET (tree_view)));
1364 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
1366 PsppSheetViewColumn *column;
1368 for (list = tree_view->priv->columns; list; list = list->next)
1370 column = list->data;
1371 if (column->button != NULL &&
1372 gtk_widget_get_visible (column->button) &&
1373 !gtk_widget_get_mapped (column->button))
1374 gtk_widget_map (column->button);
1376 for (list = tree_view->priv->columns; list; list = list->next)
1378 column = list->data;
1379 if (column->visible == FALSE || column->window == NULL)
1381 if (column->resizable)
1383 gdk_window_raise (column->window);
1384 gdk_window_show (column->window);
1387 gdk_window_hide (column->window);
1389 gdk_window_show (tree_view->priv->header_window);
1394 pspp_sheet_view_map (GtkWidget *widget)
1396 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1399 gtk_widget_set_mapped (widget, TRUE);
1401 tmp_list = tree_view->priv->children;
1404 PsppSheetViewChild *child = tmp_list->data;
1405 tmp_list = tmp_list->next;
1407 if (gtk_widget_get_visible (child->widget))
1409 if (!gtk_widget_get_mapped (child->widget))
1410 gtk_widget_map (child->widget);
1413 gdk_window_show (tree_view->priv->bin_window);
1415 pspp_sheet_view_map_buttons (tree_view);
1417 gdk_window_show (widget->window);
1421 pspp_sheet_view_realize (GtkWidget *widget)
1424 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1426 GdkWindowAttr attributes;
1427 gint attributes_mask;
1429 gtk_widget_set_realized (widget, TRUE);
1431 /* Make the main, clipping window */
1432 attributes.window_type = GDK_WINDOW_CHILD;
1433 attributes.x = widget->allocation.x;
1434 attributes.y = widget->allocation.y;
1435 attributes.width = widget->allocation.width;
1436 attributes.height = widget->allocation.height;
1437 attributes.wclass = GDK_INPUT_OUTPUT;
1438 attributes.visual = gtk_widget_get_visual (widget);
1439 attributes.colormap = gtk_widget_get_colormap (widget);
1440 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1442 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1444 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
1445 &attributes, attributes_mask);
1446 gdk_window_set_user_data (widget->window, widget);
1448 /* Make the window for the tree */
1450 attributes.y = TREE_VIEW_HEADER_HEIGHT (tree_view);
1451 attributes.width = MAX (tree_view->priv->width, widget->allocation.width);
1452 attributes.height = widget->allocation.height;
1453 attributes.event_mask = (GDK_EXPOSURE_MASK |
1455 GDK_POINTER_MOTION_MASK |
1456 GDK_ENTER_NOTIFY_MASK |
1457 GDK_LEAVE_NOTIFY_MASK |
1458 GDK_BUTTON_PRESS_MASK |
1459 GDK_BUTTON_RELEASE_MASK |
1460 gtk_widget_get_events (widget));
1462 tree_view->priv->bin_window = gdk_window_new (widget->window,
1463 &attributes, attributes_mask);
1464 gdk_window_set_user_data (tree_view->priv->bin_window, widget);
1466 /* Make the column header window */
1469 attributes.width = MAX (tree_view->priv->width, widget->allocation.width);
1470 attributes.height = tree_view->priv->header_height;
1471 attributes.event_mask = (GDK_EXPOSURE_MASK |
1473 GDK_BUTTON_PRESS_MASK |
1474 GDK_BUTTON_RELEASE_MASK |
1475 GDK_KEY_PRESS_MASK |
1476 GDK_KEY_RELEASE_MASK |
1477 gtk_widget_get_events (widget));
1479 tree_view->priv->header_window = gdk_window_new (widget->window,
1480 &attributes, attributes_mask);
1481 gdk_window_set_user_data (tree_view->priv->header_window, widget);
1483 /* Add them all up. */
1484 widget->style = gtk_style_attach (widget->style, widget->window);
1485 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
1486 gdk_window_set_background (tree_view->priv->bin_window, &widget->style->base[widget->state]);
1487 gtk_style_set_background (widget->style, tree_view->priv->header_window, GTK_STATE_NORMAL);
1489 tmp_list = tree_view->priv->children;
1492 PsppSheetViewChild *child = tmp_list->data;
1493 tmp_list = tmp_list->next;
1495 gtk_widget_set_parent_window (child->widget, tree_view->priv->bin_window);
1498 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
1499 _pspp_sheet_view_column_realize_button (PSPP_SHEET_VIEW_COLUMN (tmp_list->data));
1501 /* Need to call those here, since they create GCs */
1502 pspp_sheet_view_set_grid_lines (tree_view, tree_view->priv->grid_lines);
1504 install_presize_handler (tree_view);
1506 for (i = 0; i < 5; ++i)
1508 tree_view->priv->grid_line_gc[i] = gdk_gc_new (widget->window);
1509 gdk_gc_copy (tree_view->priv->grid_line_gc[i], widget->style->text_aa_gc[i]);
1514 pspp_sheet_view_unrealize (GtkWidget *widget)
1517 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1518 PsppSheetViewPrivate *priv = tree_view->priv;
1521 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->unrealize (widget);
1523 if (priv->scroll_timeout != 0)
1525 g_source_remove (priv->scroll_timeout);
1526 priv->scroll_timeout = 0;
1529 if (priv->open_dest_timeout != 0)
1531 g_source_remove (priv->open_dest_timeout);
1532 priv->open_dest_timeout = 0;
1535 if (priv->presize_handler_timer != 0)
1537 g_source_remove (priv->presize_handler_timer);
1538 priv->presize_handler_timer = 0;
1541 if (priv->validate_rows_timer != 0)
1543 g_source_remove (priv->validate_rows_timer);
1544 priv->validate_rows_timer = 0;
1547 if (priv->scroll_sync_timer != 0)
1549 g_source_remove (priv->scroll_sync_timer);
1550 priv->scroll_sync_timer = 0;
1553 if (priv->typeselect_flush_timeout)
1555 g_source_remove (priv->typeselect_flush_timeout);
1556 priv->typeselect_flush_timeout = 0;
1559 for (list = priv->columns; list; list = list->next)
1560 _pspp_sheet_view_column_unrealize_button (PSPP_SHEET_VIEW_COLUMN (list->data));
1562 gdk_window_set_user_data (priv->bin_window, NULL);
1563 gdk_window_destroy (priv->bin_window);
1564 priv->bin_window = NULL;
1566 gdk_window_set_user_data (priv->header_window, NULL);
1567 gdk_window_destroy (priv->header_window);
1568 priv->header_window = NULL;
1570 if (priv->drag_window)
1572 gdk_window_set_user_data (priv->drag_window, NULL);
1573 gdk_window_destroy (priv->drag_window);
1574 priv->drag_window = NULL;
1577 if (priv->drag_highlight_window)
1579 gdk_window_set_user_data (priv->drag_highlight_window, NULL);
1580 gdk_window_destroy (priv->drag_highlight_window);
1581 priv->drag_highlight_window = NULL;
1584 for (x = 0 ; x < 5 ; ++x)
1585 g_object_unref (priv->grid_line_gc[x]);
1587 if (tree_view->priv->columns != NULL)
1589 list = tree_view->priv->columns;
1592 PsppSheetViewColumn *column;
1593 column = PSPP_SHEET_VIEW_COLUMN (list->data);
1595 pspp_sheet_view_remove_column (tree_view, column);
1597 tree_view->priv->columns = NULL;
1601 /* GtkWidget::size_request helper */
1603 pspp_sheet_view_size_request_columns (PsppSheetView *tree_view)
1607 tree_view->priv->header_height = 0;
1609 if (tree_view->priv->model)
1611 for (list = tree_view->priv->columns; list; list = list->next)
1613 GtkRequisition requisition;
1614 PsppSheetViewColumn *column = list->data;
1616 pspp_sheet_view_column_size_request (column, &requisition);
1617 column->button_request = requisition.width;
1618 tree_view->priv->header_height = MAX (tree_view->priv->header_height, requisition.height);
1624 /* Called only by ::size_request */
1626 pspp_sheet_view_update_size (PsppSheetView *tree_view)
1629 PsppSheetViewColumn *column;
1632 if (tree_view->priv->model == NULL)
1634 tree_view->priv->width = 0;
1635 tree_view->priv->prev_width = 0;
1636 tree_view->priv->height = 0;
1640 tree_view->priv->prev_width = tree_view->priv->width;
1641 tree_view->priv->width = 0;
1643 /* keep this in sync with size_allocate below */
1644 for (list = tree_view->priv->columns, i = 0; list; list = list->next, i++)
1646 gint real_requested_width = 0;
1647 column = list->data;
1648 if (!column->visible)
1651 if (column->use_resized_width)
1653 real_requested_width = column->resized_width;
1657 real_requested_width = column->fixed_width;
1660 if (column->min_width != -1)
1661 real_requested_width = MAX (real_requested_width, column->min_width);
1662 if (column->max_width != -1)
1663 real_requested_width = MIN (real_requested_width, column->max_width);
1665 tree_view->priv->width += real_requested_width;
1668 tree_view->priv->height = tree_view->priv->fixed_height * tree_view->priv->row_count;
1672 pspp_sheet_view_size_request (GtkWidget *widget,
1673 GtkRequisition *requisition)
1675 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1678 /* we validate some rows initially just to make sure we have some size.
1679 * In practice, with a lot of static lists, this should get a good width.
1681 initialize_fixed_height_mode (tree_view);
1682 pspp_sheet_view_size_request_columns (tree_view);
1683 pspp_sheet_view_update_size (PSPP_SHEET_VIEW (widget));
1685 requisition->width = tree_view->priv->width;
1686 requisition->height = tree_view->priv->height + TREE_VIEW_HEADER_HEIGHT (tree_view);
1688 tmp_list = tree_view->priv->children;
1692 PsppSheetViewChild *child = tmp_list->data;
1693 GtkRequisition child_requisition;
1695 tmp_list = tmp_list->next;
1697 if (gtk_widget_get_visible (child->widget))
1698 gtk_widget_size_request (child->widget, &child_requisition);
1703 invalidate_column (PsppSheetView *tree_view,
1704 PsppSheetViewColumn *column)
1706 gint column_offset = 0;
1708 GtkWidget *widget = GTK_WIDGET (tree_view);
1711 if (!gtk_widget_get_realized (widget))
1714 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
1715 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
1717 list = (rtl ? list->prev : list->next))
1719 PsppSheetViewColumn *tmpcolumn = list->data;
1720 if (tmpcolumn == column)
1722 GdkRectangle invalid_rect;
1724 invalid_rect.x = column_offset;
1726 invalid_rect.width = column->width;
1727 invalid_rect.height = widget->allocation.height;
1729 gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
1733 column_offset += tmpcolumn->width;
1738 invalidate_last_column (PsppSheetView *tree_view)
1743 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
1745 for (last_column = (rtl ? g_list_first (tree_view->priv->columns) : g_list_last (tree_view->priv->columns));
1747 last_column = (rtl ? last_column->next : last_column->prev))
1749 if (PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible)
1751 invalidate_column (tree_view, last_column->data);
1758 pspp_sheet_view_get_real_requested_width_from_column (PsppSheetView *tree_view,
1759 PsppSheetViewColumn *column)
1761 gint real_requested_width;
1763 if (column->use_resized_width)
1765 real_requested_width = column->resized_width;
1769 real_requested_width = column->fixed_width;
1772 if (column->min_width != -1)
1773 real_requested_width = MAX (real_requested_width, column->min_width);
1774 if (column->max_width != -1)
1775 real_requested_width = MIN (real_requested_width, column->max_width);
1777 return real_requested_width;
1781 span_intersects (int a0, int a_width,
1782 int b0, int b_width)
1784 int a1 = a0 + a_width;
1785 int b1 = b0 + b_width;
1786 return (a0 >= b0 && a0 < b1) || (b0 >= a0 && b0 < a1);
1789 /* GtkWidget::size_allocate helper */
1791 pspp_sheet_view_size_allocate_columns (GtkWidget *widget,
1792 gboolean *width_changed)
1794 PsppSheetView *tree_view;
1795 GList *list, *first_column, *last_column;
1796 PsppSheetViewColumn *column;
1797 GtkAllocation allocation;
1799 gint extra, extra_per_column;
1800 gint full_requested_width = 0;
1801 gint number_of_expand_columns = 0;
1802 gboolean column_changed = FALSE;
1805 tree_view = PSPP_SHEET_VIEW (widget);
1807 for (last_column = g_list_last (tree_view->priv->columns);
1808 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
1809 last_column = last_column->prev)
1811 if (last_column == NULL)
1814 for (first_column = g_list_first (tree_view->priv->columns);
1815 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
1816 first_column = first_column->next)
1820 allocation.height = tree_view->priv->header_height;
1822 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1824 /* find out how many extra space and expandable columns we have */
1825 for (list = tree_view->priv->columns; list != last_column->next; list = list->next)
1827 column = (PsppSheetViewColumn *)list->data;
1829 if (!column->visible)
1832 full_requested_width += pspp_sheet_view_get_real_requested_width_from_column (tree_view, column);
1835 number_of_expand_columns++;
1838 extra = MAX (widget->allocation.width - full_requested_width, 0);
1839 if (number_of_expand_columns > 0)
1840 extra_per_column = extra/number_of_expand_columns;
1842 extra_per_column = 0;
1844 for (list = (rtl ? last_column : first_column);
1845 list != (rtl ? first_column->prev : last_column->next);
1846 list = (rtl ? list->prev : list->next))
1848 gint real_requested_width = 0;
1851 column = list->data;
1852 old_width = column->width;
1854 if (!column->visible)
1857 /* We need to handle the dragged button specially.
1859 if (column == tree_view->priv->drag_column)
1861 GtkAllocation drag_allocation;
1862 gdk_drawable_get_size (tree_view->priv->drag_window,
1863 &(drag_allocation.width),
1864 &(drag_allocation.height));
1865 drag_allocation.x = 0;
1866 drag_allocation.y = 0;
1867 pspp_sheet_view_column_size_allocate (tree_view->priv->drag_column,
1869 width += drag_allocation.width;
1873 real_requested_width = pspp_sheet_view_get_real_requested_width_from_column (tree_view, column);
1875 allocation.x = width;
1876 column->width = real_requested_width;
1880 if (number_of_expand_columns == 1)
1882 /* We add the remander to the last column as
1884 column->width += extra;
1888 column->width += extra_per_column;
1889 extra -= extra_per_column;
1890 number_of_expand_columns --;
1894 if (column->width != old_width)
1895 g_object_notify (G_OBJECT (column), "width");
1897 allocation.width = column->width;
1898 width += column->width;
1900 if (column->width > old_width)
1901 column_changed = TRUE;
1903 pspp_sheet_view_column_size_allocate (column, &allocation);
1905 if (span_intersects (allocation.x, allocation.width,
1906 tree_view->priv->hadjustment->value,
1907 widget->allocation.width)
1908 && gtk_widget_get_realized (widget))
1909 pspp_sheet_view_column_set_need_button (column, TRUE);
1912 gdk_window_move_resize (column->window,
1913 allocation.x + (rtl ? 0 : allocation.width) - TREE_VIEW_DRAG_WIDTH/2,
1915 TREE_VIEW_DRAG_WIDTH, allocation.height);
1918 /* We change the width here. The user might have been resizing columns,
1919 * so the total width of the tree view changes.
1921 tree_view->priv->width = width;
1923 *width_changed = TRUE;
1926 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
1931 pspp_sheet_view_size_allocate (GtkWidget *widget,
1932 GtkAllocation *allocation)
1934 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1936 gboolean width_changed = FALSE;
1937 gint old_width = widget->allocation.width;
1939 if (allocation->width != widget->allocation.width)
1940 width_changed = TRUE;
1942 widget->allocation = *allocation;
1944 tmp_list = tree_view->priv->children;
1948 GtkAllocation allocation;
1950 PsppSheetViewChild *child = tmp_list->data;
1951 tmp_list = tmp_list->next;
1953 /* totally ignore our child's requisition */
1954 allocation.x = child->x;
1955 allocation.y = child->y;
1956 allocation.width = child->width;
1957 allocation.height = child->height;
1958 gtk_widget_size_allocate (child->widget, &allocation);
1961 /* We size-allocate the columns first because the width of the
1962 * tree view (used in updating the adjustments below) might change.
1964 pspp_sheet_view_size_allocate_columns (widget, &width_changed);
1966 tree_view->priv->hadjustment->page_size = allocation->width;
1967 tree_view->priv->hadjustment->page_increment = allocation->width * 0.9;
1968 tree_view->priv->hadjustment->step_increment = allocation->width * 0.1;
1969 tree_view->priv->hadjustment->lower = 0;
1970 tree_view->priv->hadjustment->upper = MAX (tree_view->priv->hadjustment->page_size, tree_view->priv->width);
1972 if (gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL)
1974 if (allocation->width < tree_view->priv->width)
1976 if (tree_view->priv->init_hadjust_value)
1978 tree_view->priv->hadjustment->value = MAX (tree_view->priv->width - allocation->width, 0);
1979 tree_view->priv->init_hadjust_value = FALSE;
1981 else if (allocation->width != old_width)
1983 tree_view->priv->hadjustment->value = CLAMP (tree_view->priv->hadjustment->value - allocation->width + old_width, 0, tree_view->priv->width - allocation->width);
1986 tree_view->priv->hadjustment->value = CLAMP (tree_view->priv->width - (tree_view->priv->prev_width - tree_view->priv->hadjustment->value), 0, tree_view->priv->width - allocation->width);
1990 tree_view->priv->hadjustment->value = 0;
1991 tree_view->priv->init_hadjust_value = TRUE;
1995 if (tree_view->priv->hadjustment->value + allocation->width > tree_view->priv->width)
1996 tree_view->priv->hadjustment->value = MAX (tree_view->priv->width - allocation->width, 0);
1998 gtk_adjustment_changed (tree_view->priv->hadjustment);
2000 tree_view->priv->vadjustment->page_size = allocation->height - TREE_VIEW_HEADER_HEIGHT (tree_view);
2001 tree_view->priv->vadjustment->step_increment = tree_view->priv->vadjustment->page_size * 0.1;
2002 tree_view->priv->vadjustment->page_increment = tree_view->priv->vadjustment->page_size * 0.9;
2003 tree_view->priv->vadjustment->lower = 0;
2004 tree_view->priv->vadjustment->upper = MAX (tree_view->priv->vadjustment->page_size, tree_view->priv->height);
2006 gtk_adjustment_changed (tree_view->priv->vadjustment);
2008 /* now the adjustments and window sizes are in sync, we can sync toprow/dy again */
2009 if (tree_view->priv->height <= tree_view->priv->vadjustment->page_size)
2010 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment), 0);
2011 else if (tree_view->priv->vadjustment->value + tree_view->priv->vadjustment->page_size > tree_view->priv->height)
2012 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment),
2013 tree_view->priv->height - tree_view->priv->vadjustment->page_size);
2014 else if (gtk_tree_row_reference_valid (tree_view->priv->top_row))
2015 pspp_sheet_view_top_row_to_dy (tree_view);
2017 pspp_sheet_view_dy_to_top_row (tree_view);
2019 if (gtk_widget_get_realized (widget))
2021 gdk_window_move_resize (widget->window,
2022 allocation->x, allocation->y,
2023 allocation->width, allocation->height);
2024 gdk_window_move_resize (tree_view->priv->header_window,
2025 - (gint) tree_view->priv->hadjustment->value,
2027 MAX (tree_view->priv->width, allocation->width),
2028 tree_view->priv->header_height);
2029 gdk_window_move_resize (tree_view->priv->bin_window,
2030 - (gint) tree_view->priv->hadjustment->value,
2031 TREE_VIEW_HEADER_HEIGHT (tree_view),
2032 MAX (tree_view->priv->width, allocation->width),
2033 allocation->height - TREE_VIEW_HEADER_HEIGHT (tree_view));
2036 if (tree_view->priv->row_count == 0)
2037 invalidate_empty_focus (tree_view);
2039 if (gtk_widget_get_realized (widget))
2041 gboolean has_expand_column = FALSE;
2042 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
2044 if (pspp_sheet_view_column_get_expand (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)))
2046 has_expand_column = TRUE;
2051 /* This little hack only works if we have an LTR locale, and no column has the */
2054 if (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_LTR &&
2055 ! has_expand_column)
2056 invalidate_last_column (tree_view);
2058 gtk_widget_queue_draw (widget);
2063 /* Grabs the focus and unsets the PSPP_SHEET_VIEW_DRAW_KEYFOCUS flag */
2065 grab_focus_and_unset_draw_keyfocus (PsppSheetView *tree_view)
2067 GtkWidget *widget = GTK_WIDGET (tree_view);
2069 if (gtk_widget_get_can_focus (widget) && !gtk_widget_has_focus (widget))
2070 gtk_widget_grab_focus (widget);
2071 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
2075 pspp_sheet_view_node_is_selected (PsppSheetView *tree_view,
2078 return node >= 0 && range_tower_contains (tree_view->priv->selected, node);
2082 pspp_sheet_view_node_select (PsppSheetView *tree_view,
2085 range_tower_set1 (tree_view->priv->selected, node, 1);
2089 pspp_sheet_view_node_unselect (PsppSheetView *tree_view,
2092 range_tower_set0 (tree_view->priv->selected, node, 1);
2096 pspp_sheet_view_node_next (PsppSheetView *tree_view,
2099 return node + 1 < tree_view->priv->row_count ? node + 1 : -1;
2103 pspp_sheet_view_node_prev (PsppSheetView *tree_view,
2106 return node > 0 ? node - 1 : -1;
2110 all_columns_selected (PsppSheetView *tree_view)
2114 for (list = tree_view->priv->columns; list; list = list->next)
2116 PsppSheetViewColumn *column = list->data;
2117 if (column->selectable && !column->selected)
2125 pspp_sheet_view_row_head_clicked (PsppSheetView *tree_view,
2127 PsppSheetViewColumn *column,
2128 GdkEventButton *event)
2130 PsppSheetSelection *selection;
2131 PsppSheetSelectionMode mode;
2133 gboolean update_anchor;
2137 g_return_val_if_fail (tree_view != NULL, FALSE);
2138 g_return_val_if_fail (column != NULL, FALSE);
2140 selection = tree_view->priv->selection;
2141 mode = pspp_sheet_selection_get_mode (selection);
2142 if (mode != PSPP_SHEET_SELECTION_RECTANGLE)
2145 if (!column->row_head)
2150 modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
2151 if (event->type != GDK_BUTTON_PRESS
2152 || (modifiers != GDK_CONTROL_MASK && modifiers != GDK_SHIFT_MASK))
2158 path = gtk_tree_path_new_from_indices (node, -1);
2161 pspp_sheet_selection_unselect_all (selection);
2162 pspp_sheet_selection_select_path (selection, path);
2163 pspp_sheet_selection_select_all_columns (selection);
2164 update_anchor = TRUE;
2167 else if (event->type == GDK_BUTTON_PRESS && event->button == 3)
2169 if (pspp_sheet_selection_count_selected_rows (selection) <= 1
2170 || !all_columns_selected (tree_view))
2172 pspp_sheet_selection_unselect_all (selection);
2173 pspp_sheet_selection_select_path (selection, path);
2174 pspp_sheet_selection_select_all_columns (selection);
2175 update_anchor = TRUE;
2179 update_anchor = handled = FALSE;
2181 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
2182 && modifiers == GDK_CONTROL_MASK)
2184 if (!all_columns_selected (tree_view))
2186 pspp_sheet_selection_unselect_all (selection);
2187 pspp_sheet_selection_select_all_columns (selection);
2190 if (pspp_sheet_selection_path_is_selected (selection, path))
2191 pspp_sheet_selection_unselect_path (selection, path);
2193 pspp_sheet_selection_select_path (selection, path);
2194 update_anchor = TRUE;
2197 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
2198 && modifiers == GDK_SHIFT_MASK)
2200 GtkTreeRowReference *anchor = tree_view->priv->anchor;
2201 GtkTreePath *anchor_path;
2203 if (all_columns_selected (tree_view)
2204 && gtk_tree_row_reference_valid (anchor))
2206 update_anchor = FALSE;
2207 anchor_path = gtk_tree_row_reference_get_path (anchor);
2211 update_anchor = TRUE;
2212 anchor_path = gtk_tree_path_copy (path);
2215 pspp_sheet_selection_unselect_all (selection);
2216 pspp_sheet_selection_select_range (selection, anchor_path, path);
2217 pspp_sheet_selection_select_all_columns (selection);
2219 gtk_tree_path_free (anchor_path);
2224 update_anchor = handled = FALSE;
2228 if (tree_view->priv->anchor)
2229 gtk_tree_row_reference_free (tree_view->priv->anchor);
2230 tree_view->priv->anchor =
2231 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
2232 tree_view->priv->model,
2236 gtk_tree_path_free (path);
2241 find_click (PsppSheetView *tree_view,
2244 PsppSheetViewColumn **column,
2245 GdkRectangle *background_area,
2246 GdkRectangle *cell_area)
2253 /* find the node that was clicked */
2254 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, y);
2257 y_offset = -pspp_sheet_view_find_offset (tree_view, new_y, node);
2262 background_area->y = y_offset + y;
2263 background_area->height = ROW_HEIGHT (tree_view);
2264 background_area->x = 0;
2266 /* Let the column have a chance at selecting it. */
2267 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
2268 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
2269 list; list = (rtl ? list->prev : list->next))
2271 PsppSheetViewColumn *candidate = list->data;
2273 if (!candidate->visible)
2276 background_area->width = candidate->width;
2277 if ((background_area->x > x) ||
2278 (background_area->x + background_area->width <= x))
2280 background_area->x += background_area->width;
2284 /* we found the focus column */
2286 pspp_sheet_view_adjust_cell_area (tree_view, candidate, background_area,
2288 *column = candidate;
2296 pspp_sheet_view_button_press (GtkWidget *widget,
2297 GdkEventButton *event)
2299 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2301 PsppSheetViewColumn *column = NULL;
2303 GdkRectangle background_area;
2304 GdkRectangle cell_area;
2307 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
2308 pspp_sheet_view_stop_editing (tree_view, FALSE);
2311 /* Because grab_focus can cause reentrancy, we delay grab_focus until after
2312 * we're done handling the button press.
2315 if (event->window == tree_view->priv->bin_window)
2320 gint pre_val, aft_val;
2321 PsppSheetViewColumn *column = NULL;
2322 GtkCellRenderer *focus_cell = NULL;
2323 gboolean row_double_click = FALSE;
2326 if (tree_view->priv->row_count == 0)
2328 grab_focus_and_unset_draw_keyfocus (tree_view);
2332 if (!find_click (tree_view, event->x, event->y, &node, &column,
2333 &background_area, &cell_area))
2335 grab_focus_and_unset_draw_keyfocus (tree_view);
2339 tree_view->priv->focus_column = column;
2341 if (pspp_sheet_view_row_head_clicked (tree_view, node, column, event))
2345 pre_val = tree_view->priv->vadjustment->value;
2347 path = _pspp_sheet_view_find_path (tree_view, node);
2349 /* we only handle selection modifications on the first button press
2351 if (event->type == GDK_BUTTON_PRESS)
2353 if ((event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
2354 tree_view->priv->ctrl_pressed = TRUE;
2355 if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
2356 tree_view->priv->shift_pressed = TRUE;
2358 focus_cell = _pspp_sheet_view_column_get_cell_at_pos (column, event->x - background_area.x);
2360 pspp_sheet_view_column_focus_cell (column, focus_cell);
2362 if (event->state & GDK_CONTROL_MASK)
2364 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE);
2365 pspp_sheet_view_real_toggle_cursor_row (tree_view);
2367 else if (event->state & GDK_SHIFT_MASK)
2369 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE);
2370 pspp_sheet_view_real_select_cursor_row (tree_view, FALSE);
2374 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE);
2377 if (tree_view->priv->anchor_column == NULL ||
2378 !(event->state & GDK_SHIFT_MASK))
2379 tree_view->priv->anchor_column = column;
2380 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
2381 pspp_sheet_selection_select_column_range (tree_view->priv->selection,
2382 tree_view->priv->anchor_column,
2385 tree_view->priv->ctrl_pressed = FALSE;
2386 tree_view->priv->shift_pressed = FALSE;
2389 /* the treeview may have been scrolled because of _set_cursor,
2393 aft_val = tree_view->priv->vadjustment->value;
2394 dval = pre_val - aft_val;
2396 cell_area.y += dval;
2397 background_area.y += dval;
2399 /* Save press to possibly begin a drag
2401 if (!tree_view->priv->in_grab &&
2402 tree_view->priv->pressed_button < 0)
2404 tree_view->priv->pressed_button = event->button;
2405 tree_view->priv->press_start_x = event->x;
2406 tree_view->priv->press_start_y = event->y;
2407 tree_view->priv->press_start_node = node;
2409 if (tree_view->priv->rubber_banding_enable
2410 && (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
2411 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE))
2413 tree_view->priv->press_start_y += tree_view->priv->dy;
2414 tree_view->priv->rubber_band_x = event->x;
2415 tree_view->priv->rubber_band_y = event->y + tree_view->priv->dy;
2416 tree_view->priv->rubber_band_status = RUBBER_BAND_MAYBE_START;
2418 if ((event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
2419 tree_view->priv->rubber_band_ctrl = TRUE;
2420 if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
2421 tree_view->priv->rubber_band_shift = TRUE;
2426 /* Test if a double click happened on the same row. */
2427 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
2429 int double_click_time, double_click_distance;
2431 g_object_get (gtk_settings_get_for_screen (
2432 gtk_widget_get_screen (widget)),
2433 "gtk-double-click-time", &double_click_time,
2434 "gtk-double-click-distance", &double_click_distance,
2437 /* Same conditions as _gdk_event_button_generate */
2438 if (tree_view->priv->last_button_x != -1 &&
2439 (event->time < tree_view->priv->last_button_time + double_click_time) &&
2440 (ABS (event->x - tree_view->priv->last_button_x) <= double_click_distance) &&
2441 (ABS (event->y - tree_view->priv->last_button_y) <= double_click_distance))
2443 /* We do no longer compare paths of this row and the
2444 * row clicked previously. We use the double click
2445 * distance to decide whether this is a valid click,
2446 * allowing the mouse to slightly move over another row.
2448 row_double_click = TRUE;
2450 tree_view->priv->last_button_time = 0;
2451 tree_view->priv->last_button_x = -1;
2452 tree_view->priv->last_button_y = -1;
2456 tree_view->priv->last_button_time = event->time;
2457 tree_view->priv->last_button_x = event->x;
2458 tree_view->priv->last_button_y = event->y;
2462 if (row_double_click)
2464 gtk_grab_remove (widget);
2465 pspp_sheet_view_row_activated (tree_view, path, column);
2467 if (tree_view->priv->pressed_button == event->button)
2468 tree_view->priv->pressed_button = -1;
2471 gtk_tree_path_free (path);
2473 /* If we activated the row through a double click we don't want to grab
2474 * focus back, as moving focus to another widget is pretty common.
2476 if (!row_double_click)
2477 grab_focus_and_unset_draw_keyfocus (tree_view);
2482 /* We didn't click in the window. Let's check to see if we clicked on a column resize window.
2484 for (i = 0, list = tree_view->priv->columns; list; list = list->next, i++)
2486 column = list->data;
2487 if (event->window == column->window &&
2488 column->resizable &&
2493 if (gdk_pointer_grab (column->window, FALSE,
2494 GDK_POINTER_MOTION_HINT_MASK |
2495 GDK_BUTTON1_MOTION_MASK |
2496 GDK_BUTTON_RELEASE_MASK,
2497 NULL, NULL, event->time))
2500 gtk_grab_add (widget);
2501 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE);
2502 column->resized_width = column->width;
2504 /* block attached dnd signal handler */
2505 drag_data = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
2507 g_signal_handlers_block_matched (widget,
2508 G_SIGNAL_MATCH_DATA,
2512 tree_view->priv->drag_pos = i;
2513 tree_view->priv->x_drag = column->allocation.x + (rtl ? 0 : column->allocation.width);
2515 if (!gtk_widget_has_focus (widget))
2516 gtk_widget_grab_focus (widget);
2524 /* GtkWidget::button_release_event helper */
2526 pspp_sheet_view_button_release_drag_column (GtkWidget *widget,
2527 GdkEventButton *event)
2529 PsppSheetView *tree_view;
2533 tree_view = PSPP_SHEET_VIEW (widget);
2535 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
2536 gdk_display_pointer_ungrab (gtk_widget_get_display (widget), GDK_CURRENT_TIME);
2537 gdk_display_keyboard_ungrab (gtk_widget_get_display (widget), GDK_CURRENT_TIME);
2539 /* Move the button back */
2540 g_return_val_if_fail (tree_view->priv->drag_column->button, FALSE);
2542 g_object_ref (tree_view->priv->drag_column->button);
2543 gtk_container_remove (GTK_CONTAINER (tree_view), tree_view->priv->drag_column->button);
2544 gtk_widget_set_parent_window (tree_view->priv->drag_column->button, tree_view->priv->header_window);
2545 gtk_widget_set_parent (tree_view->priv->drag_column->button, GTK_WIDGET (tree_view));
2546 g_object_unref (tree_view->priv->drag_column->button);
2547 gtk_widget_queue_resize (widget);
2548 if (tree_view->priv->drag_column->resizable)
2550 gdk_window_raise (tree_view->priv->drag_column->window);
2551 gdk_window_show (tree_view->priv->drag_column->window);
2554 gdk_window_hide (tree_view->priv->drag_column->window);
2556 gtk_widget_grab_focus (tree_view->priv->drag_column->button);
2560 if (tree_view->priv->cur_reorder &&
2561 tree_view->priv->cur_reorder->right_column != tree_view->priv->drag_column)
2562 pspp_sheet_view_move_column_after (tree_view, tree_view->priv->drag_column,
2563 tree_view->priv->cur_reorder->right_column);
2567 if (tree_view->priv->cur_reorder &&
2568 tree_view->priv->cur_reorder->left_column != tree_view->priv->drag_column)
2569 pspp_sheet_view_move_column_after (tree_view, tree_view->priv->drag_column,
2570 tree_view->priv->cur_reorder->left_column);
2572 tree_view->priv->drag_column = NULL;
2573 gdk_window_hide (tree_view->priv->drag_window);
2575 for (l = tree_view->priv->column_drag_info; l != NULL; l = l->next)
2576 g_slice_free (PsppSheetViewColumnReorder, l->data);
2577 g_list_free (tree_view->priv->column_drag_info);
2578 tree_view->priv->column_drag_info = NULL;
2579 tree_view->priv->cur_reorder = NULL;
2581 if (tree_view->priv->drag_highlight_window)
2582 gdk_window_hide (tree_view->priv->drag_highlight_window);
2584 /* Reset our flags */
2585 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_UNSET;
2586 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG);
2591 /* GtkWidget::button_release_event helper */
2593 pspp_sheet_view_button_release_column_resize (GtkWidget *widget,
2594 GdkEventButton *event)
2596 PsppSheetView *tree_view;
2599 tree_view = PSPP_SHEET_VIEW (widget);
2601 tree_view->priv->drag_pos = -1;
2603 /* unblock attached dnd signal handler */
2604 drag_data = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
2606 g_signal_handlers_unblock_matched (widget,
2607 G_SIGNAL_MATCH_DATA,
2611 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE);
2612 gtk_grab_remove (widget);
2613 gdk_display_pointer_ungrab (gdk_drawable_get_display (event->window),
2619 pspp_sheet_view_button_release_edit (PsppSheetView *tree_view,
2620 GdkEventButton *event)
2622 GtkCellEditable *cell_editable;
2627 PsppSheetViewColumn *column;
2628 GdkRectangle background_area;
2629 GdkRectangle cell_area;
2635 if (event->window != tree_view->priv->bin_window)
2638 if (!find_click (tree_view, event->x, event->y, &node, &column, &background_area,
2642 /* decide if we edit */
2643 path = _pspp_sheet_view_find_path (tree_view, node);
2644 modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
2645 if (event->button != 1 || modifiers)
2648 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
2649 pspp_sheet_view_column_cell_set_cell_data (column,
2650 tree_view->priv->model,
2653 if (!pspp_sheet_view_column_get_quick_edit (column)
2654 && _pspp_sheet_view_column_has_editable_cell (column))
2657 flags = 0; /* FIXME: get the right flags */
2658 path_string = gtk_tree_path_to_string (path);
2660 if (!_pspp_sheet_view_column_cell_event (column,
2668 if (cell_editable == NULL)
2671 pspp_sheet_view_real_set_cursor (tree_view, path,
2673 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
2676 _pspp_sheet_view_column_get_neighbor_sizes (
2677 column, _pspp_sheet_view_column_get_edited_cell (column), &left, &right);
2680 area.width -= right + left;
2682 pspp_sheet_view_real_start_editing (tree_view,
2689 g_free (path_string);
2690 gtk_tree_path_free (path);
2695 pspp_sheet_view_button_release (GtkWidget *widget,
2696 GdkEventButton *event)
2698 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2700 pspp_sheet_view_stop_editing (tree_view, FALSE);
2701 if (tree_view->priv->rubber_band_status != RUBBER_BAND_ACTIVE
2702 && pspp_sheet_view_button_release_edit (tree_view, event))
2704 if (tree_view->priv->pressed_button == event->button)
2705 tree_view->priv->pressed_button = -1;
2707 tree_view->priv->rubber_band_status = RUBBER_BAND_OFF;
2711 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
2712 return pspp_sheet_view_button_release_drag_column (widget, event);
2714 if (tree_view->priv->rubber_band_status)
2715 pspp_sheet_view_stop_rubber_band (tree_view);
2717 if (tree_view->priv->pressed_button == event->button)
2718 tree_view->priv->pressed_button = -1;
2720 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
2721 return pspp_sheet_view_button_release_column_resize (widget, event);
2727 pspp_sheet_view_grab_broken (GtkWidget *widget,
2728 GdkEventGrabBroken *event)
2730 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2732 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
2733 pspp_sheet_view_button_release_drag_column (widget, (GdkEventButton *)event);
2735 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
2736 pspp_sheet_view_button_release_column_resize (widget, (GdkEventButton *)event);
2741 /* GtkWidget::motion_event function set.
2745 do_prelight (PsppSheetView *tree_view,
2747 /* these are in bin_window coords */
2751 int prev_node = tree_view->priv->prelight_node;
2753 if (prev_node != node)
2755 tree_view->priv->prelight_node = node;
2758 _pspp_sheet_view_queue_draw_node (tree_view, prev_node, NULL);
2761 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
2766 prelight_or_select (PsppSheetView *tree_view,
2768 /* these are in bin_window coords */
2772 PsppSheetSelectionMode mode = pspp_sheet_selection_get_mode (tree_view->priv->selection);
2774 if (tree_view->priv->hover_selection &&
2775 (mode == PSPP_SHEET_SELECTION_SINGLE || mode == PSPP_SHEET_SELECTION_BROWSE) &&
2776 !(tree_view->priv->edited_column &&
2777 tree_view->priv->edited_column->editable_widget))
2781 if (!pspp_sheet_view_node_is_selected (tree_view, node))
2785 path = _pspp_sheet_view_find_path (tree_view, node);
2786 pspp_sheet_selection_select_path (tree_view->priv->selection, path);
2787 if (pspp_sheet_view_node_is_selected (tree_view, node))
2789 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
2790 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, FALSE);
2792 gtk_tree_path_free (path);
2796 else if (mode == PSPP_SHEET_SELECTION_SINGLE)
2797 pspp_sheet_selection_unselect_all (tree_view->priv->selection);
2800 do_prelight (tree_view, node, x, y);
2804 ensure_unprelighted (PsppSheetView *tree_view)
2806 do_prelight (tree_view,
2808 -1000, -1000); /* coords not possibly over an arrow */
2810 g_assert (tree_view->priv->prelight_node < 0);
2814 update_prelight (PsppSheetView *tree_view,
2821 if (tree_view->priv->row_count == 0)
2826 ensure_unprelighted (tree_view);
2830 new_y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, y);
2834 pspp_sheet_view_find_offset (tree_view, new_y, &node);
2837 prelight_or_select (tree_view, node, x, y);
2843 /* Our motion arrow is either a box (in the case of the original spot)
2844 * or an arrow. It is expander_size wide.
2867 pspp_sheet_view_motion_draw_column_motion_arrow (PsppSheetView *tree_view)
2869 PsppSheetViewColumnReorder *reorder = tree_view->priv->cur_reorder;
2870 GtkWidget *widget = GTK_WIDGET (tree_view);
2871 GdkBitmap *mask = NULL;
2876 gint arrow_type = DRAG_COLUMN_WINDOW_STATE_UNSET;
2877 GdkWindowAttr attributes;
2878 guint attributes_mask;
2881 reorder->left_column == tree_view->priv->drag_column ||
2882 reorder->right_column == tree_view->priv->drag_column)
2883 arrow_type = DRAG_COLUMN_WINDOW_STATE_ORIGINAL;
2884 else if (reorder->left_column || reorder->right_column)
2886 GdkRectangle visible_rect;
2887 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
2888 if (reorder->left_column)
2889 x = reorder->left_column->allocation.x + reorder->left_column->allocation.width;
2891 x = reorder->right_column->allocation.x;
2893 if (x < visible_rect.x)
2894 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT;
2895 else if (x > visible_rect.x + visible_rect.width)
2896 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT;
2898 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW;
2901 /* We want to draw the rectangle over the initial location. */
2902 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ORIGINAL)
2907 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ORIGINAL)
2909 if (tree_view->priv->drag_highlight_window)
2911 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
2913 gdk_window_destroy (tree_view->priv->drag_highlight_window);
2916 attributes.window_type = GDK_WINDOW_CHILD;
2917 attributes.wclass = GDK_INPUT_OUTPUT;
2918 attributes.x = tree_view->priv->drag_column_x;
2920 width = attributes.width = tree_view->priv->drag_column->allocation.width;
2921 height = attributes.height = tree_view->priv->drag_column->allocation.height;
2922 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
2923 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
2924 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
2925 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2926 tree_view->priv->drag_highlight_window = gdk_window_new (tree_view->priv->header_window, &attributes, attributes_mask);
2927 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
2929 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
2930 gc = gdk_gc_new (mask);
2932 gdk_gc_set_foreground (gc, &col);
2933 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
2935 gdk_gc_set_foreground(gc, &col);
2936 gdk_draw_rectangle (mask, gc, TRUE, 2, 2, width - 4, height - 4);
2937 g_object_unref (gc);
2939 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
2941 if (mask) g_object_unref (mask);
2942 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_ORIGINAL;
2945 else if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW)
2951 width = tree_view->priv->expander_size;
2953 /* Get x, y, width, height of arrow */
2954 gdk_window_get_origin (tree_view->priv->header_window, &x, &y);
2955 if (reorder->left_column)
2957 x += reorder->left_column->allocation.x + reorder->left_column->allocation.width - width/2;
2958 height = reorder->left_column->allocation.height;
2962 x += reorder->right_column->allocation.x - width/2;
2963 height = reorder->right_column->allocation.height;
2965 y -= tree_view->priv->expander_size/2; /* The arrow takes up only half the space */
2966 height += tree_view->priv->expander_size;
2968 /* Create the new window */
2969 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW)
2971 if (tree_view->priv->drag_highlight_window)
2973 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
2975 gdk_window_destroy (tree_view->priv->drag_highlight_window);
2978 attributes.window_type = GDK_WINDOW_TEMP;
2979 attributes.wclass = GDK_INPUT_OUTPUT;
2980 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
2981 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
2982 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
2983 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2986 attributes.width = width;
2987 attributes.height = height;
2988 tree_view->priv->drag_highlight_window = gdk_window_new (gtk_widget_get_root_window (widget),
2989 &attributes, attributes_mask);
2990 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
2992 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
2993 gc = gdk_gc_new (mask);
2995 gdk_gc_set_foreground (gc, &col);
2996 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
2998 /* Draw the 2 arrows as per above */
3000 gdk_gc_set_foreground (gc, &col);
3001 for (i = 0; i < width; i ++)
3003 if (i == (width/2 - 1))
3005 gdk_draw_line (mask, gc, i, j, i, height - j);
3006 if (i < (width/2 - 1))
3011 g_object_unref (gc);
3012 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
3014 if (mask) g_object_unref (mask);
3017 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_ARROW;
3018 gdk_window_move (tree_view->priv->drag_highlight_window, x, y);
3020 else if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT ||
3021 arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3027 width = tree_view->priv->expander_size;
3029 /* Get x, y, width, height of arrow */
3030 width = width/2; /* remember, the arrow only takes half the available width */
3031 gdk_window_get_origin (widget->window, &x, &y);
3032 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3033 x += widget->allocation.width - width;
3035 if (reorder->left_column)
3036 height = reorder->left_column->allocation.height;
3038 height = reorder->right_column->allocation.height;
3040 y -= tree_view->priv->expander_size;
3041 height += 2*tree_view->priv->expander_size;
3043 /* Create the new window */
3044 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT &&
3045 tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3047 if (tree_view->priv->drag_highlight_window)
3049 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
3051 gdk_window_destroy (tree_view->priv->drag_highlight_window);
3054 attributes.window_type = GDK_WINDOW_TEMP;
3055 attributes.wclass = GDK_INPUT_OUTPUT;
3056 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
3057 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
3058 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
3059 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
3062 attributes.width = width;
3063 attributes.height = height;
3064 tree_view->priv->drag_highlight_window = gdk_window_new (NULL, &attributes, attributes_mask);
3065 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
3067 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
3068 gc = gdk_gc_new (mask);
3070 gdk_gc_set_foreground (gc, &col);
3071 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
3073 /* Draw the 2 arrows as per above */
3075 gdk_gc_set_foreground (gc, &col);
3076 j = tree_view->priv->expander_size;
3077 for (i = 0; i < width; i ++)
3080 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT)
3084 gdk_draw_line (mask, gc, k, j, k, height - j);
3085 gdk_draw_line (mask, gc, k, 0, k, tree_view->priv->expander_size - j);
3086 gdk_draw_line (mask, gc, k, height, k, height - tree_view->priv->expander_size + j);
3089 g_object_unref (gc);
3090 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
3092 if (mask) g_object_unref (mask);
3095 tree_view->priv->drag_column_window_state = arrow_type;
3096 gdk_window_move (tree_view->priv->drag_highlight_window, x, y);
3100 g_warning (G_STRLOC"Invalid PsppSheetViewColumnReorder struct");
3101 gdk_window_hide (tree_view->priv->drag_highlight_window);
3105 gdk_window_show (tree_view->priv->drag_highlight_window);
3106 gdk_window_raise (tree_view->priv->drag_highlight_window);
3110 pspp_sheet_view_motion_resize_column (GtkWidget *widget,
3111 GdkEventMotion *event)
3115 PsppSheetViewColumn *column;
3116 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
3118 column = pspp_sheet_view_get_column (tree_view, tree_view->priv->drag_pos);
3120 if (event->is_hint || event->window != widget->window)
3121 gtk_widget_get_pointer (widget, &x, NULL);
3125 if (tree_view->priv->hadjustment)
3126 x += tree_view->priv->hadjustment->value;
3128 new_width = pspp_sheet_view_new_column_width (tree_view,
3129 tree_view->priv->drag_pos, &x);
3130 if (x != tree_view->priv->x_drag &&
3131 (new_width != column->fixed_width))
3133 column->use_resized_width = TRUE;
3134 column->resized_width = new_width;
3137 column->resized_width -= tree_view->priv->last_extra_space_per_column;
3139 gtk_widget_queue_resize (widget);
3147 pspp_sheet_view_update_current_reorder (PsppSheetView *tree_view)
3149 PsppSheetViewColumnReorder *reorder = NULL;
3153 gdk_window_get_pointer (tree_view->priv->header_window, &mouse_x, NULL, NULL);
3154 for (list = tree_view->priv->column_drag_info; list; list = list->next)
3156 reorder = (PsppSheetViewColumnReorder *) list->data;
3157 if (mouse_x >= reorder->left_align && mouse_x < reorder->right_align)
3162 /* if (reorder && reorder == tree_view->priv->cur_reorder)
3165 tree_view->priv->cur_reorder = reorder;
3166 pspp_sheet_view_motion_draw_column_motion_arrow (tree_view);
3170 pspp_sheet_view_vertical_autoscroll (PsppSheetView *tree_view)
3172 GdkRectangle visible_rect;
3177 gdk_window_get_pointer (tree_view->priv->bin_window, NULL, &y, NULL);
3178 y += tree_view->priv->dy;
3180 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
3182 /* see if we are near the edge. */
3183 offset = y - (visible_rect.y + 2 * SCROLL_EDGE_SIZE);
3186 offset = y - (visible_rect.y + visible_rect.height - 2 * SCROLL_EDGE_SIZE);
3191 value = CLAMP (tree_view->priv->vadjustment->value + offset, 0.0,
3192 tree_view->priv->vadjustment->upper - tree_view->priv->vadjustment->page_size);
3193 gtk_adjustment_set_value (tree_view->priv->vadjustment, value);
3197 pspp_sheet_view_horizontal_autoscroll (PsppSheetView *tree_view)
3199 GdkRectangle visible_rect;
3204 gdk_window_get_pointer (tree_view->priv->bin_window, &x, NULL, NULL);
3206 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
3208 /* See if we are near the edge. */
3209 offset = x - (visible_rect.x + SCROLL_EDGE_SIZE);
3212 offset = x - (visible_rect.x + visible_rect.width - SCROLL_EDGE_SIZE);
3218 value = CLAMP (tree_view->priv->hadjustment->value + offset,
3219 0.0, tree_view->priv->hadjustment->upper - tree_view->priv->hadjustment->page_size);
3220 gtk_adjustment_set_value (tree_view->priv->hadjustment, value);
3227 pspp_sheet_view_motion_drag_column (GtkWidget *widget,
3228 GdkEventMotion *event)
3230 PsppSheetView *tree_view = (PsppSheetView *) widget;
3231 PsppSheetViewColumn *column = tree_view->priv->drag_column;
3235 if ((column == NULL) ||
3236 (event->window != tree_view->priv->drag_window))
3239 /* Handle moving the header */
3240 gdk_window_get_position (tree_view->priv->drag_window, &x, &y);
3241 x = CLAMP (x + (gint)event->x - column->drag_x, 0,
3242 MAX (tree_view->priv->width, GTK_WIDGET (tree_view)->allocation.width) - column->allocation.width);
3243 gdk_window_move (tree_view->priv->drag_window, x, y);
3245 /* autoscroll, if needed */
3246 pspp_sheet_view_horizontal_autoscroll (tree_view);
3247 /* Update the current reorder position and arrow; */
3248 pspp_sheet_view_update_current_reorder (tree_view);
3254 pspp_sheet_view_stop_rubber_band (PsppSheetView *tree_view)
3256 remove_scroll_timeout (tree_view);
3257 gtk_grab_remove (GTK_WIDGET (tree_view));
3259 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
3261 GtkTreePath *tmp_path;
3263 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
3265 /* The anchor path should be set to the start path */
3266 tmp_path = _pspp_sheet_view_find_path (tree_view,
3267 tree_view->priv->rubber_band_start_node);
3269 if (tree_view->priv->anchor)
3270 gtk_tree_row_reference_free (tree_view->priv->anchor);
3272 tree_view->priv->anchor =
3273 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
3274 tree_view->priv->model,
3277 gtk_tree_path_free (tmp_path);
3279 /* ... and the cursor to the end path */
3280 tmp_path = _pspp_sheet_view_find_path (tree_view,
3281 tree_view->priv->rubber_band_end_node);
3282 pspp_sheet_view_real_set_cursor (PSPP_SHEET_VIEW (tree_view), tmp_path, FALSE, FALSE);
3283 gtk_tree_path_free (tmp_path);
3285 _pspp_sheet_selection_emit_changed (tree_view->priv->selection);
3288 /* Clear status variables */
3289 tree_view->priv->rubber_band_status = RUBBER_BAND_OFF;
3290 tree_view->priv->rubber_band_shift = 0;
3291 tree_view->priv->rubber_band_ctrl = 0;
3293 tree_view->priv->rubber_band_start_node = -1;
3294 tree_view->priv->rubber_band_end_node = -1;
3298 pspp_sheet_view_update_rubber_band_selection_range (PsppSheetView *tree_view,
3302 gboolean skip_start,
3305 if (start_node == end_node)
3308 /* We skip the first node and jump inside the loop */
3314 /* Small optimization by assuming insensitive nodes are never
3319 if (tree_view->priv->rubber_band_shift)
3320 pspp_sheet_view_node_select (tree_view, start_node);
3321 else if (tree_view->priv->rubber_band_ctrl)
3323 /* Toggle the selection state */
3324 if (pspp_sheet_view_node_is_selected (tree_view, start_node))
3325 pspp_sheet_view_node_unselect (tree_view, start_node);
3327 pspp_sheet_view_node_select (tree_view, start_node);
3330 pspp_sheet_view_node_select (tree_view, start_node);
3334 /* Mirror the above */
3335 if (tree_view->priv->rubber_band_shift)
3336 pspp_sheet_view_node_unselect (tree_view, start_node);
3337 else if (tree_view->priv->rubber_band_ctrl)
3339 /* Toggle the selection state */
3340 if (pspp_sheet_view_node_is_selected (tree_view, start_node))
3341 pspp_sheet_view_node_unselect (tree_view, start_node);
3343 pspp_sheet_view_node_select (tree_view, start_node);
3346 pspp_sheet_view_node_unselect (tree_view, start_node);
3349 _pspp_sheet_view_queue_draw_node (tree_view, start_node, NULL);
3351 if (start_node == end_node)
3356 start_node = pspp_sheet_view_node_next (tree_view, start_node);
3359 /* Ran out of tree */
3362 if (skip_end && start_node == end_node)
3369 pspp_sheet_view_node_find_offset (PsppSheetView *tree_view,
3372 return node * tree_view->priv->fixed_height;
3376 pspp_sheet_view_find_offset (PsppSheetView *tree_view,
3380 int fixed_height = tree_view->priv->fixed_height;
3381 if (fixed_height <= 0
3383 || height >= tree_view->priv->row_count * fixed_height)
3390 *new_node = height / fixed_height;
3391 return height % fixed_height;
3396 pspp_sheet_view_update_rubber_band_selection (PsppSheetView *tree_view)
3401 pspp_sheet_view_find_offset (tree_view, MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y), &start_node);
3402 pspp_sheet_view_find_offset (tree_view, MAX (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y), &end_node);
3404 /* Handle the start area first */
3405 if (tree_view->priv->rubber_band_start_node < 0)
3407 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3414 else if (start_node < tree_view->priv->rubber_band_start_node)
3416 /* New node is above the old one; selection became bigger */
3417 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3419 tree_view->priv->rubber_band_start_node,
3424 else if (start_node > tree_view->priv->rubber_band_start_node)
3426 /* New node is below the old one; selection became smaller */
3427 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3428 tree_view->priv->rubber_band_start_node,
3435 tree_view->priv->rubber_band_start_node = start_node;
3437 /* Next, handle the end area */
3438 if (tree_view->priv->rubber_band_end_node < 0)
3440 /* In the event this happens, start_node was also -1; this case is
3444 else if (end_node < 0)
3446 /* Find the last node in the tree */
3447 pspp_sheet_view_find_offset (tree_view, tree_view->priv->height - 1,
3450 /* Selection reached end of the tree */
3451 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3452 tree_view->priv->rubber_band_end_node,
3458 else if (end_node > tree_view->priv->rubber_band_end_node)
3460 /* New node is below the old one; selection became bigger */
3461 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3462 tree_view->priv->rubber_band_end_node,
3468 else if (end_node < tree_view->priv->rubber_band_end_node)
3470 /* New node is above the old one; selection became smaller */
3471 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3473 tree_view->priv->rubber_band_end_node,
3479 tree_view->priv->rubber_band_end_node = end_node;
3483 pspp_sheet_view_update_rubber_band (PsppSheetView *tree_view)
3486 GdkRectangle old_area;
3487 GdkRectangle new_area;
3488 GdkRectangle common;
3489 GdkRegion *invalid_region;
3490 PsppSheetViewColumn *column;
3492 old_area.x = MIN (tree_view->priv->press_start_x, tree_view->priv->rubber_band_x);
3493 old_area.y = MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y) - tree_view->priv->dy;
3494 old_area.width = ABS (tree_view->priv->rubber_band_x - tree_view->priv->press_start_x) + 1;
3495 old_area.height = ABS (tree_view->priv->rubber_band_y - tree_view->priv->press_start_y) + 1;
3497 gdk_window_get_pointer (tree_view->priv->bin_window, &x, &y, NULL);
3500 y = MAX (y, 0) + tree_view->priv->dy;
3502 new_area.x = MIN (tree_view->priv->press_start_x, x);
3503 new_area.y = MIN (tree_view->priv->press_start_y, y) - tree_view->priv->dy;
3504 new_area.width = ABS (x - tree_view->priv->press_start_x) + 1;
3505 new_area.height = ABS (y - tree_view->priv->press_start_y) + 1;
3507 invalid_region = gdk_region_rectangle (&old_area);
3508 gdk_region_union_with_rect (invalid_region, &new_area);
3510 gdk_rectangle_intersect (&old_area, &new_area, &common);
3511 if (common.width > 2 && common.height > 2)
3513 GdkRegion *common_region;
3515 /* make sure the border is invalidated */
3521 common_region = gdk_region_rectangle (&common);
3523 gdk_region_subtract (invalid_region, common_region);
3524 gdk_region_destroy (common_region);
3527 gdk_window_invalidate_region (tree_view->priv->bin_window, invalid_region, TRUE);
3529 gdk_region_destroy (invalid_region);
3531 tree_view->priv->rubber_band_x = x;
3532 tree_view->priv->rubber_band_y = y;
3533 pspp_sheet_view_get_path_at_pos (tree_view, x, y, NULL, &column, NULL, NULL);
3535 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
3536 pspp_sheet_selection_select_column_range (tree_view->priv->selection,
3537 tree_view->priv->anchor_column,
3540 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
3542 pspp_sheet_view_update_rubber_band_selection (tree_view);
3546 pspp_sheet_view_paint_rubber_band (PsppSheetView *tree_view,
3551 GdkRectangle rubber_rect;
3554 rubber_rect.x = MIN (tree_view->priv->press_start_x, tree_view->priv->rubber_band_x);
3555 rubber_rect.y = MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y) - tree_view->priv->dy;
3556 rubber_rect.width = ABS (tree_view->priv->press_start_x - tree_view->priv->rubber_band_x) + 1;
3557 rubber_rect.height = ABS (tree_view->priv->press_start_y - tree_view->priv->rubber_band_y) + 1;
3559 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
3562 cr = gdk_cairo_create (tree_view->priv->bin_window);
3563 cairo_set_line_width (cr, 1.0);
3565 cairo_set_source_rgba (cr,
3566 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].red / 65535.,
3567 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].green / 65535.,
3568 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].blue / 65535.,
3571 gdk_cairo_rectangle (cr, &rect);
3575 cairo_set_source_rgb (cr,
3576 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].red / 65535.,
3577 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].green / 65535.,
3578 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].blue / 65535.);
3580 cairo_rectangle (cr,
3581 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
3582 rubber_rect.width - 1, rubber_rect.height - 1);
3589 pspp_sheet_view_motion_bin_window (GtkWidget *widget,
3590 GdkEventMotion *event)
3592 PsppSheetView *tree_view;
3596 tree_view = (PsppSheetView *) widget;
3598 if (tree_view->priv->row_count == 0)
3601 if (tree_view->priv->rubber_band_status == RUBBER_BAND_MAYBE_START)
3603 GdkRectangle background_area, cell_area;
3604 PsppSheetViewColumn *column;
3606 if (find_click (tree_view, event->x, event->y, &node, &column,
3607 &background_area, &cell_area)
3608 && tree_view->priv->focus_column == column
3609 && tree_view->priv->press_start_node == node)
3612 gtk_grab_add (GTK_WIDGET (tree_view));
3613 pspp_sheet_view_update_rubber_band (tree_view);
3615 tree_view->priv->rubber_band_status = RUBBER_BAND_ACTIVE;
3617 else if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
3619 pspp_sheet_view_update_rubber_band (tree_view);
3621 add_scroll_timeout (tree_view);
3624 /* only check for an initiated drag when a button is pressed */
3625 if (tree_view->priv->pressed_button >= 0
3626 && !tree_view->priv->rubber_band_status)
3627 pspp_sheet_view_maybe_begin_dragging_row (tree_view, event);
3629 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, event->y);
3633 pspp_sheet_view_find_offset (tree_view, new_y, &node);
3635 tree_view->priv->event_last_x = event->x;
3636 tree_view->priv->event_last_y = event->y;
3638 prelight_or_select (tree_view, node, event->x, event->y);
3644 pspp_sheet_view_motion (GtkWidget *widget,
3645 GdkEventMotion *event)
3647 PsppSheetView *tree_view;
3649 tree_view = (PsppSheetView *) widget;
3651 /* Resizing a column */
3652 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
3653 return pspp_sheet_view_motion_resize_column (widget, event);
3656 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
3657 return pspp_sheet_view_motion_drag_column (widget, event);
3659 /* Sanity check it */
3660 if (event->window == tree_view->priv->bin_window)
3661 return pspp_sheet_view_motion_bin_window (widget, event);
3666 /* Invalidate the focus rectangle near the edge of the bin_window; used when
3667 * the tree is empty.
3670 invalidate_empty_focus (PsppSheetView *tree_view)
3674 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
3679 gdk_drawable_get_size (tree_view->priv->bin_window, &area.width, &area.height);
3680 gdk_window_invalidate_rect (tree_view->priv->bin_window, &area, FALSE);
3683 /* Draws a focus rectangle near the edge of the bin_window; used when the tree
3687 draw_empty_focus (PsppSheetView *tree_view, GdkRectangle *clip_area)
3689 GtkWidget *widget = GTK_WIDGET (tree_view);
3692 if (!gtk_widget_has_focus (widget))
3695 gdk_drawable_get_size (tree_view->priv->bin_window, &w, &h);
3701 gtk_paint_focus (gtk_widget_get_style (widget),
3702 tree_view->priv->bin_window,
3703 gtk_widget_get_state (widget),
3711 pspp_sheet_view_draw_grid_lines (PsppSheetView *tree_view,
3712 GdkEventExpose *event,
3713 gint n_visible_columns,
3717 GList *list = tree_view->priv->columns;
3722 if (tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
3723 && tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_BOTH)
3726 gdk_drawable_get_size (event->window, NULL, &height);
3728 /* Only draw the lines for visible rows and columns */
3729 for (list = tree_view->priv->columns; list; list = list->next, i++)
3731 PsppSheetViewColumn *column = list->data;
3733 /* We don't want a line for the last column */
3734 if (i == n_visible_columns - 1)
3737 if (! column->visible)
3740 current_x += column->width;
3742 if (current_x - 1 >= event->area.x
3743 && current_x - 1 < event->area.x + event->area.width)
3744 gdk_draw_line (event->window,
3745 tree_view->priv->grid_line_gc[GTK_WIDGET(tree_view)->state],
3746 current_x - 1, min_y,
3747 current_x - 1, max_y - min_y);
3751 /* Warning: Very scary function.
3752 * Modify at your own risk
3754 * KEEP IN SYNC WITH pspp_sheet_view_create_row_drag_icon()!
3755 * FIXME: It's not...
3758 pspp_sheet_view_bin_expose (GtkWidget *widget,
3759 GdkEventExpose *event)
3761 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
3766 int drag_highlight = -1;
3769 gint y_offset, cell_offset;
3771 GdkRectangle background_area;
3772 GdkRectangle cell_area;
3774 gint bin_window_width;
3775 gint bin_window_height;
3776 GtkTreePath *cursor_path;
3777 GtkTreePath *drag_dest_path;
3778 GList *first_column, *last_column;
3779 gint vertical_separator;
3780 gint horizontal_separator;
3781 gint focus_line_width;
3782 gboolean allow_rules;
3783 gboolean has_special_cell;
3785 gint n_visible_columns;
3786 gint grid_line_width;
3787 gboolean row_ending_details;
3788 gboolean draw_vgrid_lines, draw_hgrid_lines;
3791 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
3793 gtk_widget_style_get (widget,
3794 "horizontal-separator", &horizontal_separator,
3795 "vertical-separator", &vertical_separator,
3796 "allow-rules", &allow_rules,
3797 "focus-line-width", &focus_line_width,
3798 "row-ending-details", &row_ending_details,
3801 if (tree_view->priv->row_count == 0)
3803 draw_empty_focus (tree_view, &event->area);
3807 /* clip event->area to the visible area */
3808 if (event->area.height < 0)
3811 validate_visible_area (tree_view);
3813 new_y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, event->area.y);
3817 y_offset = -pspp_sheet_view_find_offset (tree_view, new_y, &node);
3818 gdk_drawable_get_size (tree_view->priv->bin_window,
3819 &bin_window_width, &bin_window_height);
3821 if (tree_view->priv->height < bin_window_height)
3823 gtk_paint_flat_box (widget->style,
3830 0, tree_view->priv->height,
3832 bin_window_height - tree_view->priv->height);
3838 /* find the path for the node */
3839 path = _pspp_sheet_view_find_path ((PsppSheetView *)widget, node);
3840 gtk_tree_model_get_iter (tree_view->priv->model,
3843 gtk_tree_path_free (path);
3846 drag_dest_path = NULL;
3848 if (tree_view->priv->cursor)
3849 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
3852 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor);
3854 if (tree_view->priv->drag_dest_row)
3855 drag_dest_path = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
3858 _pspp_sheet_view_find_node (tree_view, drag_dest_path,
3862 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
3863 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
3865 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
3866 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
3868 if (draw_vgrid_lines || draw_hgrid_lines)
3869 gtk_widget_style_get (widget, "grid-line-width", &grid_line_width, NULL);
3871 n_visible_columns = 0;
3872 for (list = tree_view->priv->columns; list; list = list->next)
3874 if (! PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
3876 n_visible_columns ++;
3879 /* Find the last column */
3880 for (last_column = g_list_last (tree_view->priv->columns);
3881 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
3882 last_column = last_column->prev)
3886 for (first_column = g_list_first (tree_view->priv->columns);
3887 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
3888 first_column = first_column->next)
3891 /* Actually process the expose event. To do this, we want to
3892 * start at the first node of the event, and walk the tree in
3893 * order, drawing each successive node.
3900 gboolean is_first = FALSE;
3901 gboolean is_last = FALSE;
3902 gboolean done = FALSE;
3905 max_height = ROW_HEIGHT (tree_view);
3909 background_area.y = y_offset + event->area.y;
3910 background_area.height = max_height;
3911 max_y = background_area.y + max_height;
3915 if (node == tree_view->priv->prelight_node)
3916 flags |= GTK_CELL_RENDERER_PRELIT;
3918 selected = pspp_sheet_view_node_is_selected (tree_view, node);
3922 if (tree_view->priv->special_cells == PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT)
3924 /* we *need* to set cell data on all cells before the call
3925 * to _has_special_cell, else _has_special_cell() does not
3926 * return a correct value.
3928 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
3930 list = (rtl ? list->prev : list->next))
3932 PsppSheetViewColumn *column = list->data;
3933 pspp_sheet_view_column_cell_set_cell_data (column,
3934 tree_view->priv->model,
3938 has_special_cell = pspp_sheet_view_has_special_cell (tree_view);
3941 has_special_cell = tree_view->priv->special_cells == PSPP_SHEET_VIEW_SPECIAL_CELLS_YES;
3943 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
3945 list = (rtl ? list->prev : list->next))
3947 PsppSheetViewColumn *column = list->data;
3948 const gchar *detail = NULL;
3949 gboolean selected_column;
3952 if (!column->visible)
3955 if (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE)
3956 selected_column = column->selected && column->selectable;
3958 selected_column = TRUE;
3960 if (cell_offset > event->area.x + event->area.width ||
3961 cell_offset + column->width < event->area.x)
3963 cell_offset += column->width;
3967 if (selected && selected_column)
3968 flags |= GTK_CELL_RENDERER_SELECTED;
3970 flags &= ~GTK_CELL_RENDERER_SELECTED;
3972 if (column->show_sort_indicator)
3973 flags |= GTK_CELL_RENDERER_SORTED;
3975 flags &= ~GTK_CELL_RENDERER_SORTED;
3978 flags |= GTK_CELL_RENDERER_FOCUSED;
3980 flags &= ~GTK_CELL_RENDERER_FOCUSED;
3982 background_area.x = cell_offset;
3983 background_area.width = column->width;
3985 cell_area = background_area;
3986 cell_area.y += vertical_separator / 2;
3987 cell_area.x += horizontal_separator / 2;
3988 cell_area.height -= vertical_separator;
3989 cell_area.width -= horizontal_separator;
3991 if (draw_vgrid_lines)
3993 if (list == first_column)
3995 cell_area.width -= grid_line_width / 2;
3997 else if (list == last_column)
3999 cell_area.x += grid_line_width / 2;
4000 cell_area.width -= grid_line_width / 2;
4004 cell_area.x += grid_line_width / 2;
4005 cell_area.width -= grid_line_width;
4009 if (draw_hgrid_lines)
4011 cell_area.y += grid_line_width / 2;
4012 cell_area.height -= grid_line_width;
4015 if (gdk_region_rect_in (event->region, &background_area) == GDK_OVERLAP_RECTANGLE_OUT)
4017 cell_offset += column->width;
4021 pspp_sheet_view_column_cell_set_cell_data (column,
4022 tree_view->priv->model,
4025 /* Select the detail for drawing the cell. relevant
4026 * factors are parity, sortedness, and whether to
4029 if (allow_rules && tree_view->priv->has_rules)
4031 if ((flags & GTK_CELL_RENDERER_SORTED) &&
4032 n_visible_columns >= 3)
4035 detail = "cell_odd_ruled_sorted";
4037 detail = "cell_even_ruled_sorted";
4042 detail = "cell_odd_ruled";
4044 detail = "cell_even_ruled";
4049 if ((flags & GTK_CELL_RENDERER_SORTED) &&
4050 n_visible_columns >= 3)
4053 detail = "cell_odd_sorted";
4055 detail = "cell_even_sorted";
4060 detail = "cell_odd";
4062 detail = "cell_even";
4068 if (widget->state == GTK_STATE_INSENSITIVE)
4069 state = GTK_STATE_INSENSITIVE;
4070 else if (flags & GTK_CELL_RENDERER_SELECTED)
4071 state = GTK_STATE_SELECTED;
4073 state = GTK_STATE_NORMAL;
4075 /* Draw background */
4076 if (row_ending_details)
4078 char new_detail[128];
4080 is_first = (rtl ? !list->next : !list->prev);
4081 is_last = (rtl ? !list->prev : !list->next);
4083 /* (I don't like the snprintfs either, but couldn't find a
4086 if (is_first && is_last)
4087 g_snprintf (new_detail, 127, "%s", detail);
4089 g_snprintf (new_detail, 127, "%s_start", detail);
4091 g_snprintf (new_detail, 127, "%s_end", detail);
4093 g_snprintf (new_detail, 128, "%s_middle", detail);
4095 gtk_paint_flat_box (widget->style,
4104 background_area.width,
4105 background_area.height);
4109 gtk_paint_flat_box (widget->style,
4118 background_area.width,
4119 background_area.height);
4122 if (draw_hgrid_lines)
4124 if (background_area.y > 0)
4125 gdk_draw_line (event->window,
4126 tree_view->priv->grid_line_gc[widget->state],
4127 background_area.x, background_area.y,
4128 background_area.x + background_area.width,
4131 if (y_offset + max_height >= event->area.height)
4132 gdk_draw_line (event->window,
4133 tree_view->priv->grid_line_gc[widget->state],
4134 background_area.x, background_area.y + max_height,
4135 background_area.x + background_area.width,
4136 background_area.y + max_height);
4139 _pspp_sheet_view_column_cell_render (column,
4146 if (node == cursor && has_special_cell &&
4147 ((column == tree_view->priv->focus_column &&
4148 PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS) &&
4149 gtk_widget_has_focus (widget)) ||
4150 (column == tree_view->priv->edited_column)))
4152 _pspp_sheet_view_column_cell_draw_focus (column,
4160 cell_offset += column->width;
4163 if (cell_offset < event->area.x)
4165 gtk_paint_flat_box (widget->style,
4174 event->area.x - cell_offset,
4175 background_area.height);
4178 if (node == drag_highlight)
4180 /* Draw indicator for the drop
4182 gint highlight_y = -1;
4186 switch (tree_view->priv->drag_dest_pos)
4188 case PSPP_SHEET_VIEW_DROP_BEFORE:
4189 highlight_y = background_area.y - 1;
4190 if (highlight_y < 0)
4194 case PSPP_SHEET_VIEW_DROP_AFTER:
4195 highlight_y = background_area.y + background_area.height - 1;
4198 case PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE:
4199 case PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER:
4200 _pspp_sheet_view_find_node (tree_view, drag_dest_path, &node);
4204 gdk_drawable_get_size (tree_view->priv->bin_window,
4207 if (row_ending_details)
4208 gtk_paint_focus (widget->style,
4209 tree_view->priv->bin_window,
4210 gtk_widget_get_state (widget),
4214 ? (is_last ? "treeview-drop-indicator" : "treeview-drop-indicator-left" )
4215 : (is_last ? "treeview-drop-indicator-right" : "tree-view-drop-indicator-middle" )),
4216 0, BACKGROUND_FIRST_PIXEL (tree_view, node)
4217 - focus_line_width / 2,
4218 width, ROW_HEIGHT (tree_view)
4219 - focus_line_width + 1);
4221 gtk_paint_focus (widget->style,
4222 tree_view->priv->bin_window,
4223 gtk_widget_get_state (widget),
4226 "treeview-drop-indicator",
4227 0, BACKGROUND_FIRST_PIXEL (tree_view, node)
4228 - focus_line_width / 2,
4229 width, ROW_HEIGHT (tree_view)
4230 - focus_line_width + 1);
4234 if (highlight_y >= 0)
4236 gdk_draw_line (event->window,
4237 widget->style->fg_gc[gtk_widget_get_state (widget)],
4240 rtl ? 0 : bin_window_width,
4245 /* draw the big row-spanning focus rectangle, if needed */
4246 if (!has_special_cell && node == cursor &&
4247 PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS) &&
4248 gtk_widget_has_focus (widget))
4250 gint tmp_y, tmp_height;
4252 GtkStateType focus_rect_state;
4255 flags & GTK_CELL_RENDERER_SELECTED ? GTK_STATE_SELECTED :
4256 (flags & GTK_CELL_RENDERER_PRELIT ? GTK_STATE_PRELIGHT :
4257 (flags & GTK_CELL_RENDERER_INSENSITIVE ? GTK_STATE_INSENSITIVE :
4260 gdk_drawable_get_size (tree_view->priv->bin_window,
4263 if (draw_hgrid_lines)
4265 tmp_y = BACKGROUND_FIRST_PIXEL (tree_view, node) + grid_line_width / 2;
4266 tmp_height = ROW_HEIGHT (tree_view) - grid_line_width;
4270 tmp_y = BACKGROUND_FIRST_PIXEL (tree_view, node);
4271 tmp_height = ROW_HEIGHT (tree_view);
4274 if (row_ending_details)
4275 gtk_paint_focus (widget->style,
4276 tree_view->priv->bin_window,
4281 ? (is_last ? "treeview" : "treeview-left" )
4282 : (is_last ? "treeview-right" : "treeview-middle" )),
4286 gtk_paint_focus (widget->style,
4287 tree_view->priv->bin_window,
4296 y_offset += max_height;
4300 node = pspp_sheet_view_node_next (tree_view, node);
4303 gboolean has_next = gtk_tree_model_iter_next (tree_view->priv->model, &iter);
4307 TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
4314 while (y_offset < event->area.height);
4317 pspp_sheet_view_draw_grid_lines (tree_view, event, n_visible_columns,
4320 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
4322 GdkRectangle *rectangles;
4325 gdk_region_get_rectangles (event->region,
4329 while (n_rectangles--)
4330 pspp_sheet_view_paint_rubber_band (tree_view, &rectangles[n_rectangles]);
4332 g_free (rectangles);
4336 gtk_tree_path_free (cursor_path);
4339 gtk_tree_path_free (drag_dest_path);
4345 pspp_sheet_view_expose (GtkWidget *widget,
4346 GdkEventExpose *event)
4348 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4350 if (event->window == tree_view->priv->bin_window)
4355 retval = pspp_sheet_view_bin_expose (widget, event);
4357 /* We can't just chain up to Container::expose as it will try to send the
4358 * event to the headers, so we handle propagating it to our children
4359 * (eg. widgets being edited) ourselves.
4361 tmp_list = tree_view->priv->children;
4364 PsppSheetViewChild *child = tmp_list->data;
4365 tmp_list = tmp_list->next;
4367 gtk_container_propagate_expose (GTK_CONTAINER (tree_view), child->widget, event);
4373 else if (event->window == tree_view->priv->header_window)
4375 gint n_visible_columns;
4378 gtk_paint_flat_box (widget->style,
4388 event->area.height);
4390 for (list = tree_view->priv->columns; list != NULL; list = list->next)
4392 PsppSheetViewColumn *column = list->data;
4394 if (column == tree_view->priv->drag_column || !column->visible)
4397 if (span_intersects (column->allocation.x, column->allocation.width,
4398 event->area.x, event->area.width)
4399 && column->button != NULL)
4400 gtk_container_propagate_expose (GTK_CONTAINER (tree_view),
4401 column->button, event);
4404 n_visible_columns = 0;
4405 for (list = tree_view->priv->columns; list; list = list->next)
4407 if (! PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
4409 n_visible_columns ++;
4411 pspp_sheet_view_draw_grid_lines (tree_view,
4415 event->area.height);
4417 else if (event->window == tree_view->priv->drag_window)
4419 gtk_container_propagate_expose (GTK_CONTAINER (tree_view),
4420 tree_view->priv->drag_column->button,
4434 /* returns 0x1 when no column has been found -- yes it's hackish */
4435 static PsppSheetViewColumn *
4436 pspp_sheet_view_get_drop_column (PsppSheetView *tree_view,
4437 PsppSheetViewColumn *column,
4440 PsppSheetViewColumn *left_column = NULL;
4441 PsppSheetViewColumn *cur_column = NULL;
4444 if (!column->reorderable)
4445 return (PsppSheetViewColumn *)0x1;
4447 switch (drop_position)
4450 /* find first column where we can drop */
4451 tmp_list = tree_view->priv->columns;
4452 if (column == PSPP_SHEET_VIEW_COLUMN (tmp_list->data))
4453 return (PsppSheetViewColumn *)0x1;
4457 g_assert (tmp_list);
4459 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4460 tmp_list = tmp_list->next;
4462 if (left_column && left_column->visible == FALSE)
4465 if (!tree_view->priv->column_drop_func)
4468 if (!tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4470 left_column = cur_column;
4477 if (!tree_view->priv->column_drop_func)
4480 if (tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data))
4483 return (PsppSheetViewColumn *)0x1;
4487 /* find first column after column where we can drop */
4488 tmp_list = tree_view->priv->columns;
4490 for (; tmp_list; tmp_list = tmp_list->next)
4491 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data) == column)
4494 if (!tmp_list || !tmp_list->next)
4495 return (PsppSheetViewColumn *)0x1;
4497 tmp_list = tmp_list->next;
4498 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4499 tmp_list = tmp_list->next;
4503 g_assert (tmp_list);
4505 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4506 tmp_list = tmp_list->next;
4508 if (left_column && left_column->visible == FALSE)
4510 left_column = cur_column;
4512 tmp_list = tmp_list->next;
4516 if (!tree_view->priv->column_drop_func)
4519 if (!tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4521 left_column = cur_column;
4528 if (!tree_view->priv->column_drop_func)
4531 if (tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data))
4534 return (PsppSheetViewColumn *)0x1;
4538 /* find first column before column where we can drop */
4539 tmp_list = tree_view->priv->columns;
4541 for (; tmp_list; tmp_list = tmp_list->next)
4542 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data) == column)
4545 if (!tmp_list || !tmp_list->prev)
4546 return (PsppSheetViewColumn *)0x1;
4548 tmp_list = tmp_list->prev;
4549 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4550 tmp_list = tmp_list->prev;
4554 g_assert (tmp_list);
4556 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4558 if (left_column && !left_column->visible)
4560 /*if (!tmp_list->prev)
4561 return (PsppSheetViewColumn *)0x1;
4564 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->prev->data);
4565 tmp_list = tmp_list->prev->prev;
4568 cur_column = left_column;
4570 tmp_list = tmp_list->prev;
4574 if (!tree_view->priv->column_drop_func)
4577 if (tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4580 cur_column = left_column;
4581 tmp_list = tmp_list->prev;
4584 if (!tree_view->priv->column_drop_func)
4587 if (tree_view->priv->column_drop_func (tree_view, column, NULL, cur_column, tree_view->priv->column_drop_func_data))
4590 return (PsppSheetViewColumn *)0x1;
4594 /* same as DROP_HOME case, but doing it backwards */
4595 tmp_list = g_list_last (tree_view->priv->columns);
4598 if (column == PSPP_SHEET_VIEW_COLUMN (tmp_list->data))
4599 return (PsppSheetViewColumn *)0x1;
4603 g_assert (tmp_list);
4605 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4607 if (left_column && !left_column->visible)
4609 cur_column = left_column;
4610 tmp_list = tmp_list->prev;
4613 if (!tree_view->priv->column_drop_func)
4616 if (tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4619 cur_column = left_column;
4620 tmp_list = tmp_list->prev;
4623 if (!tree_view->priv->column_drop_func)
4626 if (tree_view->priv->column_drop_func (tree_view, column, NULL, cur_column, tree_view->priv->column_drop_func_data))
4629 return (PsppSheetViewColumn *)0x1;
4633 return (PsppSheetViewColumn *)0x1;
4637 pspp_sheet_view_key_press (GtkWidget *widget,
4640 PsppSheetView *tree_view = (PsppSheetView *) widget;
4642 if (tree_view->priv->rubber_band_status)
4644 if (event->keyval == GDK_Escape)
4645 pspp_sheet_view_stop_rubber_band (tree_view);
4650 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
4652 if (event->keyval == GDK_Escape)
4654 tree_view->priv->cur_reorder = NULL;
4655 pspp_sheet_view_button_release_drag_column (widget, NULL);
4660 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
4662 GList *focus_column;
4665 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
4667 for (focus_column = tree_view->priv->columns;
4669 focus_column = focus_column->next)
4671 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4673 if (column->button && gtk_widget_has_focus (column->button))
4678 (event->state & GDK_SHIFT_MASK) && (event->state & GDK_MOD1_MASK) &&
4679 (event->keyval == GDK_Left || event->keyval == GDK_KP_Left
4680 || event->keyval == GDK_Right || event->keyval == GDK_KP_Right))
4682 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4684 if (!column->resizable)
4686 gtk_widget_error_bell (widget);
4690 if (event->keyval == (rtl ? GDK_Right : GDK_Left)
4691 || event->keyval == (rtl ? GDK_KP_Right : GDK_KP_Left))
4693 gint old_width = column->resized_width;
4695 column->resized_width = MAX (column->resized_width,
4697 column->resized_width -= 2;
4698 if (column->resized_width < 0)
4699 column->resized_width = 0;
4701 if (column->min_width == -1)
4702 column->resized_width = MAX (column->button_request,
4703 column->resized_width);
4705 column->resized_width = MAX (column->min_width,
4706 column->resized_width);
4708 if (column->max_width != -1)
4709 column->resized_width = MIN (column->resized_width,
4712 column->use_resized_width = TRUE;
4714 if (column->resized_width != old_width)
4715 gtk_widget_queue_resize (widget);
4717 gtk_widget_error_bell (widget);
4719 else if (event->keyval == (rtl ? GDK_Left : GDK_Right)
4720 || event->keyval == (rtl ? GDK_KP_Left : GDK_KP_Right))
4722 gint old_width = column->resized_width;
4724 column->resized_width = MAX (column->resized_width,
4726 column->resized_width += 2;
4728 if (column->max_width != -1)
4729 column->resized_width = MIN (column->resized_width,
4732 column->use_resized_width = TRUE;
4734 if (column->resized_width != old_width)
4735 gtk_widget_queue_resize (widget);
4737 gtk_widget_error_bell (widget);
4744 (event->state & GDK_MOD1_MASK) &&
4745 (event->keyval == GDK_Left || event->keyval == GDK_KP_Left
4746 || event->keyval == GDK_Right || event->keyval == GDK_KP_Right
4747 || event->keyval == GDK_Home || event->keyval == GDK_KP_Home
4748 || event->keyval == GDK_End || event->keyval == GDK_KP_End))
4750 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4752 if (event->keyval == (rtl ? GDK_Right : GDK_Left)
4753 || event->keyval == (rtl ? GDK_KP_Right : GDK_KP_Left))
4755 PsppSheetViewColumn *col;
4756 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_LEFT);
4757 if (col != (PsppSheetViewColumn *)0x1)
4758 pspp_sheet_view_move_column_after (tree_view, column, col);
4760 gtk_widget_error_bell (widget);
4762 else if (event->keyval == (rtl ? GDK_Left : GDK_Right)
4763 || event->keyval == (rtl ? GDK_KP_Left : GDK_KP_Right))
4765 PsppSheetViewColumn *col;
4766 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_RIGHT);
4767 if (col != (PsppSheetViewColumn *)0x1)
4768 pspp_sheet_view_move_column_after (tree_view, column, col);
4770 gtk_widget_error_bell (widget);
4772 else if (event->keyval == GDK_Home || event->keyval == GDK_KP_Home)
4774 PsppSheetViewColumn *col;
4775 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_HOME);
4776 if (col != (PsppSheetViewColumn *)0x1)
4777 pspp_sheet_view_move_column_after (tree_view, column, col);
4779 gtk_widget_error_bell (widget);
4781 else if (event->keyval == GDK_End || event->keyval == GDK_KP_End)
4783 PsppSheetViewColumn *col;
4784 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_END);
4785 if (col != (PsppSheetViewColumn *)0x1)
4786 pspp_sheet_view_move_column_after (tree_view, column, col);
4788 gtk_widget_error_bell (widget);
4795 /* Chain up to the parent class. It handles the keybindings. */
4796 if (GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->key_press_event (widget, event))
4799 if (tree_view->priv->search_entry_avoid_unhandled_binding)
4801 tree_view->priv->search_entry_avoid_unhandled_binding = FALSE;
4805 /* We pass the event to the search_entry. If its text changes, then we start
4806 * the typeahead find capabilities. */
4807 if (gtk_widget_has_focus (GTK_WIDGET (tree_view))
4808 && tree_view->priv->enable_search
4809 && !tree_view->priv->search_custom_entry_set)
4811 GdkEvent *new_event;
4813 const char *new_text;
4816 gboolean text_modified;
4817 gulong popup_menu_id;
4819 pspp_sheet_view_ensure_interactive_directory (tree_view);
4821 /* Make a copy of the current text */
4822 old_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry)));
4823 new_event = gdk_event_copy ((GdkEvent *) event);
4824 g_object_unref (((GdkEventKey *) new_event)->window);
4825 ((GdkEventKey *) new_event)->window = g_object_ref (tree_view->priv->search_window->window);
4826 gtk_widget_realize (tree_view->priv->search_window);
4828 popup_menu_id = g_signal_connect (tree_view->priv->search_entry,
4829 "popup-menu", G_CALLBACK (gtk_true),
4832 /* Move the entry off screen */
4833 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
4834 gtk_window_move (GTK_WINDOW (tree_view->priv->search_window),
4835 gdk_screen_get_width (screen) + 1,
4836 gdk_screen_get_height (screen) + 1);
4837 gtk_widget_show (tree_view->priv->search_window);
4839 /* Send the event to the window. If the preedit_changed signal is emitted
4840 * during this event, we will set priv->imcontext_changed */
4841 tree_view->priv->imcontext_changed = FALSE;
4842 retval = gtk_widget_event (tree_view->priv->search_window, new_event);
4843 gdk_event_free (new_event);
4844 gtk_widget_hide (tree_view->priv->search_window);
4846 g_signal_handler_disconnect (tree_view->priv->search_entry,
4849 /* We check to make sure that the entry tried to handle the text, and that
4850 * the text has changed.
4852 new_text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
4853 text_modified = strcmp (old_text, new_text) != 0;
4855 if (tree_view->priv->imcontext_changed || /* we're in a preedit */
4856 (retval && text_modified)) /* ...or the text was modified */
4858 if (pspp_sheet_view_real_start_interactive_search (tree_view, FALSE))
4860 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
4865 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
4875 pspp_sheet_view_key_release (GtkWidget *widget,
4878 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4880 if (tree_view->priv->rubber_band_status)
4883 return GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->key_release_event (widget, event);
4886 /* FIXME Is this function necessary? Can I get an enter_notify event
4887 * w/o either an expose event or a mouse motion event?
4890 pspp_sheet_view_enter_notify (GtkWidget *widget,
4891 GdkEventCrossing *event)
4893 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4897 /* Sanity check it */
4898 if (event->window != tree_view->priv->bin_window)
4901 if (tree_view->priv->row_count == 0)
4904 if (event->mode == GDK_CROSSING_GRAB ||
4905 event->mode == GDK_CROSSING_GTK_GRAB ||
4906 event->mode == GDK_CROSSING_GTK_UNGRAB ||
4907 event->mode == GDK_CROSSING_STATE_CHANGED)
4910 /* find the node internally */
4911 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, event->y);
4914 pspp_sheet_view_find_offset (tree_view, new_y, &node);
4916 tree_view->priv->event_last_x = event->x;
4917 tree_view->priv->event_last_y = event->y;
4919 prelight_or_select (tree_view, node, event->x, event->y);
4925 pspp_sheet_view_leave_notify (GtkWidget *widget,
4926 GdkEventCrossing *event)
4928 PsppSheetView *tree_view;
4930 if (event->mode == GDK_CROSSING_GRAB)
4933 tree_view = PSPP_SHEET_VIEW (widget);
4935 if (tree_view->priv->prelight_node >= 0)
4936 _pspp_sheet_view_queue_draw_node (tree_view,
4937 tree_view->priv->prelight_node,
4940 tree_view->priv->event_last_x = -10000;
4941 tree_view->priv->event_last_y = -10000;
4943 prelight_or_select (tree_view,
4945 -1000, -1000); /* coords not possibly over an arrow */
4952 pspp_sheet_view_focus_out (GtkWidget *widget,
4953 GdkEventFocus *event)
4955 PsppSheetView *tree_view;
4957 tree_view = PSPP_SHEET_VIEW (widget);
4959 gtk_widget_queue_draw (widget);
4961 /* destroy interactive search dialog */
4962 if (tree_view->priv->search_window)
4963 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
4969 /* Incremental Reflow
4973 pspp_sheet_view_node_queue_redraw (PsppSheetView *tree_view,
4978 y = pspp_sheet_view_node_find_offset (tree_view, node)
4979 - tree_view->priv->vadjustment->value
4980 + TREE_VIEW_HEADER_HEIGHT (tree_view);
4982 gtk_widget_queue_draw_area (GTK_WIDGET (tree_view),
4984 GTK_WIDGET (tree_view)->allocation.width,
4985 tree_view->priv->fixed_height);
4989 node_is_visible (PsppSheetView *tree_view,
4995 y = pspp_sheet_view_node_find_offset (tree_view, node);
4996 height = ROW_HEIGHT (tree_view);
4998 if (y >= tree_view->priv->vadjustment->value &&
4999 y + height <= (tree_view->priv->vadjustment->value
5000 + tree_view->priv->vadjustment->page_size))
5006 /* Returns the row height. */
5008 validate_row (PsppSheetView *tree_view,
5013 PsppSheetViewColumn *column;
5014 GList *list, *first_column, *last_column;
5016 gint horizontal_separator;
5017 gint vertical_separator;
5018 gint focus_line_width;
5019 gboolean draw_vgrid_lines, draw_hgrid_lines;
5021 gint grid_line_width;
5022 gboolean wide_separators;
5023 gint separator_height;
5025 gtk_widget_style_get (GTK_WIDGET (tree_view),
5026 "focus-padding", &focus_pad,
5027 "focus-line-width", &focus_line_width,
5028 "horizontal-separator", &horizontal_separator,
5029 "vertical-separator", &vertical_separator,
5030 "grid-line-width", &grid_line_width,
5031 "wide-separators", &wide_separators,
5032 "separator-height", &separator_height,
5036 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
5037 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
5039 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
5040 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
5042 for (last_column = g_list_last (tree_view->priv->columns);
5043 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
5044 last_column = last_column->prev)
5047 for (first_column = g_list_first (tree_view->priv->columns);
5048 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
5049 first_column = first_column->next)
5052 for (list = tree_view->priv->columns; list; list = list->next)
5057 column = list->data;
5059 if (! column->visible)
5062 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, iter);
5063 pspp_sheet_view_column_cell_get_size (column,
5065 &tmp_width, &tmp_height);
5067 tmp_height += vertical_separator;
5068 height = MAX (height, tmp_height);
5070 tmp_width = tmp_width + horizontal_separator;
5072 if (draw_vgrid_lines)
5074 if (list->data == first_column || list->data == last_column)
5075 tmp_width += grid_line_width / 2.0;
5077 tmp_width += grid_line_width;
5080 if (tmp_width > column->requested_width)
5081 column->requested_width = tmp_width;
5084 if (draw_hgrid_lines)
5085 height += grid_line_width;
5087 tree_view->priv->post_validation_flag = TRUE;
5093 validate_visible_area (PsppSheetView *tree_view)
5095 GtkTreePath *path = NULL;
5096 GtkTreePath *above_path = NULL;
5099 gboolean size_changed = FALSE;
5101 gint area_above = 0;
5102 gint area_below = 0;
5104 if (tree_view->priv->row_count == 0)
5107 if (tree_view->priv->scroll_to_path == NULL)
5110 total_height = GTK_WIDGET (tree_view)->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
5112 if (total_height == 0)
5115 path = gtk_tree_row_reference_get_path (tree_view->priv->scroll_to_path);
5118 /* we are going to scroll, and will update dy */
5119 _pspp_sheet_view_find_node (tree_view, path, &node);
5120 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
5122 if (tree_view->priv->scroll_to_use_align)
5124 gint height = ROW_HEIGHT (tree_view);
5125 area_above = (total_height - height) *
5126 tree_view->priv->scroll_to_row_align;
5127 area_below = total_height - area_above - height;
5128 area_above = MAX (area_above, 0);
5129 area_below = MAX (area_below, 0);
5134 * 1) row not visible
5138 gint height = ROW_HEIGHT (tree_view);
5140 dy = pspp_sheet_view_node_find_offset (tree_view, node);
5142 if (dy >= tree_view->priv->vadjustment->value &&
5143 dy + height <= (tree_view->priv->vadjustment->value
5144 + tree_view->priv->vadjustment->page_size))
5146 /* row visible: keep the row at the same position */
5147 area_above = dy - tree_view->priv->vadjustment->value;
5148 area_below = (tree_view->priv->vadjustment->value +
5149 tree_view->priv->vadjustment->page_size)
5154 /* row not visible */
5156 && dy + height <= tree_view->priv->vadjustment->page_size)
5158 /* row at the beginning -- fixed */
5160 area_below = tree_view->priv->vadjustment->page_size
5161 - area_above - height;
5163 else if (dy >= (tree_view->priv->vadjustment->upper -
5164 tree_view->priv->vadjustment->page_size))
5166 /* row at the end -- fixed */
5167 area_above = dy - (tree_view->priv->vadjustment->upper -
5168 tree_view->priv->vadjustment->page_size);
5169 area_below = tree_view->priv->vadjustment->page_size -
5170 area_above - height;
5174 area_above = tree_view->priv->vadjustment->page_size - height;
5180 /* row somewhere in the middle, bring it to the top
5184 area_below = total_height - height;
5190 /* the scroll to isn't valid; ignore it.
5193 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
5194 tree_view->priv->scroll_to_path = NULL;
5198 above_path = gtk_tree_path_copy (path);
5200 /* Now, we walk forwards and backwards, measuring rows. Unfortunately,
5201 * backwards is much slower then forward, as there is no iter_prev function.
5202 * We go forwards first in case we run out of tree. Then we go backwards to
5205 while (node >= 0 && area_below > 0)
5207 gboolean done = FALSE;
5210 node = pspp_sheet_view_node_next (tree_view, node);
5213 gboolean has_next = gtk_tree_model_iter_next (tree_view->priv->model, &iter);
5215 gtk_tree_path_next (path);
5218 TREE_VIEW_INTERNAL_ASSERT_VOID (has_next);
5228 area_below -= ROW_HEIGHT (tree_view);
5230 gtk_tree_path_free (path);
5232 /* If we ran out of tree, and have extra area_below left, we need to add it
5235 area_above += area_below;
5237 _pspp_sheet_view_find_node (tree_view, above_path, &node);
5239 /* We walk backwards */
5240 while (area_above > 0)
5242 node = pspp_sheet_view_node_prev (tree_view, node);
5244 /* Always find the new path in the tree. We cannot just assume
5245 * a gtk_tree_path_prev() is enough here, as there might be children
5246 * in between this node and the previous sibling node. If this
5247 * appears to be a performance hotspot in profiles, we can look into
5248 * intrigate logic for keeping path, node and iter in sync like
5249 * we do for forward walks. (Which will be hard because of the lacking
5256 gtk_tree_path_free (above_path);
5257 above_path = _pspp_sheet_view_find_path (tree_view, node);
5259 gtk_tree_model_get_iter (tree_view->priv->model, &iter, above_path);
5261 area_above -= ROW_HEIGHT (tree_view);
5264 /* set the dy here to scroll to the path,
5265 * and sync the top row accordingly
5267 pspp_sheet_view_set_top_row (tree_view, above_path, -area_above);
5268 pspp_sheet_view_top_row_to_dy (tree_view);
5270 /* update width/height and queue a resize */
5273 GtkRequisition requisition;
5275 /* We temporarily guess a size, under the assumption that it will be the
5276 * same when we get our next size_allocate. If we don't do this, we'll be
5277 * in an inconsistent state if we call top_row_to_dy. */
5279 gtk_widget_size_request (GTK_WIDGET (tree_view), &requisition);
5280 tree_view->priv->hadjustment->upper = MAX (tree_view->priv->hadjustment->upper, (gfloat)requisition.width);
5281 tree_view->priv->vadjustment->upper = MAX (tree_view->priv->vadjustment->upper, (gfloat)requisition.height);
5282 gtk_adjustment_changed (tree_view->priv->hadjustment);
5283 gtk_adjustment_changed (tree_view->priv->vadjustment);
5284 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
5287 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
5288 tree_view->priv->scroll_to_path = NULL;
5291 gtk_tree_path_free (above_path);
5293 if (tree_view->priv->scroll_to_column)
5295 tree_view->priv->scroll_to_column = NULL;
5297 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
5301 initialize_fixed_height_mode (PsppSheetView *tree_view)
5303 if (!tree_view->priv->row_count)
5306 if (tree_view->priv->fixed_height_set)
5309 if (tree_view->priv->fixed_height < 0)
5316 path = _pspp_sheet_view_find_path (tree_view, node);
5317 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
5319 tree_view->priv->fixed_height = validate_row (tree_view, node, &iter, path);
5321 gtk_tree_path_free (path);
5323 g_object_notify (G_OBJECT (tree_view), "fixed-height");
5327 /* Our strategy for finding nodes to validate is a little convoluted. We find
5328 * the left-most uninvalidated node. We then try walking right, validating
5329 * nodes. Once we find a valid node, we repeat the previous process of finding
5330 * the first invalid node.
5334 validate_rows_handler (PsppSheetView *tree_view)
5336 initialize_fixed_height_mode (tree_view);
5337 if (tree_view->priv->validate_rows_timer)
5339 g_source_remove (tree_view->priv->validate_rows_timer);
5340 tree_view->priv->validate_rows_timer = 0;
5347 do_presize_handler (PsppSheetView *tree_view)
5349 GtkRequisition requisition;
5351 validate_visible_area (tree_view);
5352 tree_view->priv->presize_handler_timer = 0;
5354 if (! gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5357 gtk_widget_size_request (GTK_WIDGET (tree_view), &requisition);
5359 tree_view->priv->hadjustment->upper = MAX (tree_view->priv->hadjustment->upper, (gfloat)requisition.width);
5360 tree_view->priv->vadjustment->upper = MAX (tree_view->priv->vadjustment->upper, (gfloat)requisition.height);
5361 gtk_adjustment_changed (tree_view->priv->hadjustment);
5362 gtk_adjustment_changed (tree_view->priv->vadjustment);
5363 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
5369 presize_handler_callback (gpointer data)
5371 do_presize_handler (PSPP_SHEET_VIEW (data));
5377 install_presize_handler (PsppSheetView *tree_view)
5379 if (! gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5382 if (! tree_view->priv->presize_handler_timer)
5384 tree_view->priv->presize_handler_timer =
5385 gdk_threads_add_idle_full (GTK_PRIORITY_RESIZE - 2, presize_handler_callback, tree_view, NULL);
5387 if (! tree_view->priv->validate_rows_timer)
5389 tree_view->priv->validate_rows_timer =
5390 gdk_threads_add_idle_full (PSPP_SHEET_VIEW_PRIORITY_VALIDATE, (GSourceFunc) validate_rows_handler, tree_view, NULL);
5395 scroll_sync_handler (PsppSheetView *tree_view)
5397 if (tree_view->priv->height <= tree_view->priv->vadjustment->page_size)
5398 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment), 0);
5399 else if (gtk_tree_row_reference_valid (tree_view->priv->top_row))
5400 pspp_sheet_view_top_row_to_dy (tree_view);
5402 pspp_sheet_view_dy_to_top_row (tree_view);
5404 tree_view->priv->scroll_sync_timer = 0;
5410 install_scroll_sync_handler (PsppSheetView *tree_view)
5412 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5415 if (!tree_view->priv->scroll_sync_timer)
5417 tree_view->priv->scroll_sync_timer =
5418 gdk_threads_add_idle_full (PSPP_SHEET_VIEW_PRIORITY_SCROLL_SYNC, (GSourceFunc) scroll_sync_handler, tree_view, NULL);
5423 pspp_sheet_view_set_top_row (PsppSheetView *tree_view,
5427 gtk_tree_row_reference_free (tree_view->priv->top_row);
5431 tree_view->priv->top_row = NULL;
5432 tree_view->priv->top_row_dy = 0;
5436 tree_view->priv->top_row = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
5437 tree_view->priv->top_row_dy = offset;
5441 /* Always call this iff dy is in the visible range. If the tree is empty, then
5442 * it's set to be NULL, and top_row_dy is 0;
5445 pspp_sheet_view_dy_to_top_row (PsppSheetView *tree_view)
5451 if (tree_view->priv->row_count == 0)
5453 pspp_sheet_view_set_top_row (tree_view, NULL, 0);
5457 offset = pspp_sheet_view_find_offset (tree_view,
5458 tree_view->priv->dy,
5463 pspp_sheet_view_set_top_row (tree_view, NULL, 0);
5467 path = _pspp_sheet_view_find_path (tree_view, node);
5468 pspp_sheet_view_set_top_row (tree_view, path, offset);
5469 gtk_tree_path_free (path);
5475 pspp_sheet_view_top_row_to_dy (PsppSheetView *tree_view)
5481 /* Avoid recursive calls */
5482 if (tree_view->priv->in_top_row_to_dy)
5485 if (tree_view->priv->top_row)
5486 path = gtk_tree_row_reference_get_path (tree_view->priv->top_row);
5493 _pspp_sheet_view_find_node (tree_view, path, &node);
5496 gtk_tree_path_free (path);
5500 /* keep dy and set new toprow */
5501 gtk_tree_row_reference_free (tree_view->priv->top_row);
5502 tree_view->priv->top_row = NULL;
5503 tree_view->priv->top_row_dy = 0;
5504 /* DO NOT install the idle handler */
5505 pspp_sheet_view_dy_to_top_row (tree_view);
5509 if (ROW_HEIGHT (tree_view) < tree_view->priv->top_row_dy)
5511 /* new top row -- do NOT install the idle handler */
5512 pspp_sheet_view_dy_to_top_row (tree_view);
5516 new_dy = pspp_sheet_view_node_find_offset (tree_view, node);
5517 new_dy += tree_view->priv->top_row_dy;
5519 if (new_dy + tree_view->priv->vadjustment->page_size > tree_view->priv->height)
5520 new_dy = tree_view->priv->height - tree_view->priv->vadjustment->page_size;
5522 new_dy = MAX (0, new_dy);
5524 tree_view->priv->in_top_row_to_dy = TRUE;
5525 gtk_adjustment_set_value (tree_view->priv->vadjustment, (gdouble)new_dy);
5526 tree_view->priv->in_top_row_to_dy = FALSE;
5531 _pspp_sheet_view_install_mark_rows_col_dirty (PsppSheetView *tree_view)
5533 install_presize_handler (tree_view);
5539 set_source_row (GdkDragContext *context,
5540 GtkTreeModel *model,
5541 GtkTreePath *source_row)
5543 g_object_set_data_full (G_OBJECT (context),
5544 "gtk-tree-view-source-row",
5545 source_row ? gtk_tree_row_reference_new (model, source_row) : NULL,
5546 (GDestroyNotify) (source_row ? gtk_tree_row_reference_free : NULL));
5550 get_source_row (GdkDragContext *context)
5552 GtkTreeRowReference *ref =
5553 g_object_get_data (G_OBJECT (context), "gtk-tree-view-source-row");
5556 return gtk_tree_row_reference_get_path (ref);
5563 GtkTreeRowReference *dest_row;
5564 guint path_down_mode : 1;
5565 guint empty_view_drop : 1;
5566 guint drop_append_mode : 1;
5571 dest_row_free (gpointer data)
5573 DestRow *dr = (DestRow *)data;
5575 gtk_tree_row_reference_free (dr->dest_row);
5576 g_slice_free (DestRow, dr);
5580 set_dest_row (GdkDragContext *context,
5581 GtkTreeModel *model,
5582 GtkTreePath *dest_row,
5583 gboolean path_down_mode,
5584 gboolean empty_view_drop,
5585 gboolean drop_append_mode)
5591 g_object_set_data_full (G_OBJECT (context), "gtk-tree-view-dest-row",
5596 dr = g_slice_new (DestRow);
5598 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5599 dr->path_down_mode = path_down_mode != FALSE;
5600 dr->empty_view_drop = empty_view_drop != FALSE;
5601 dr->drop_append_mode = drop_append_mode != FALSE;
5603 g_object_set_data_full (G_OBJECT (context), "gtk-tree-view-dest-row",
5604 dr, (GDestroyNotify) dest_row_free);
5608 get_dest_row (GdkDragContext *context,
5609 gboolean *path_down_mode)
5612 g_object_get_data (G_OBJECT (context), "gtk-tree-view-dest-row");
5616 GtkTreePath *path = NULL;
5619 *path_down_mode = dr->path_down_mode;
5622 path = gtk_tree_row_reference_get_path (dr->dest_row);
5623 else if (dr->empty_view_drop)
5624 path = gtk_tree_path_new_from_indices (0, -1);
5628 if (path && dr->drop_append_mode)
5629 gtk_tree_path_next (path);
5637 /* Get/set whether drag_motion requested the drag data and
5638 * drag_data_received should thus not actually insert the data,
5639 * since the data doesn't result from a drop.
5642 set_status_pending (GdkDragContext *context,
5643 GdkDragAction suggested_action)
5645 g_object_set_data (G_OBJECT (context),
5646 "gtk-tree-view-status-pending",
5647 GINT_TO_POINTER (suggested_action));
5650 static GdkDragAction
5651 get_status_pending (GdkDragContext *context)
5653 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5654 "gtk-tree-view-status-pending"));
5657 static TreeViewDragInfo*
5658 get_info (PsppSheetView *tree_view)
5660 return g_object_get_data (G_OBJECT (tree_view), "gtk-tree-view-drag-info");
5664 destroy_info (TreeViewDragInfo *di)
5666 g_slice_free (TreeViewDragInfo, di);
5669 static TreeViewDragInfo*
5670 ensure_info (PsppSheetView *tree_view)
5672 TreeViewDragInfo *di;
5674 di = get_info (tree_view);
5678 di = g_slice_new0 (TreeViewDragInfo);
5680 g_object_set_data_full (G_OBJECT (tree_view),
5681 "gtk-tree-view-drag-info",
5683 (GDestroyNotify) destroy_info);
5690 remove_info (PsppSheetView *tree_view)
5692 g_object_set_data (G_OBJECT (tree_view), "gtk-tree-view-drag-info", NULL);
5697 drag_scan_timeout (gpointer data)
5699 PsppSheetView *tree_view;
5701 GdkModifierType state;
5702 GtkTreePath *path = NULL;
5703 PsppSheetViewColumn *column = NULL;
5704 GdkRectangle visible_rect;
5706 GDK_THREADS_ENTER ();
5708 tree_view = PSPP_SHEET_VIEW (data);
5710 gdk_window_get_pointer (tree_view->priv->bin_window,
5713 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
5715 /* See if we are near the edge. */
5716 if ((x - visible_rect.x) < SCROLL_EDGE_SIZE ||
5717 (visible_rect.x + visible_rect.width - x) < SCROLL_EDGE_SIZE ||
5718 (y - visible_rect.y) < SCROLL_EDGE_SIZE ||
5719 (visible_rect.y + visible_rect.height - y) < SCROLL_EDGE_SIZE)
5721 pspp_sheet_view_get_path_at_pos (tree_view,
5722 tree_view->priv->bin_window,
5731 pspp_sheet_view_scroll_to_cell (tree_view,
5737 gtk_tree_path_free (path);
5741 GDK_THREADS_LEAVE ();
5748 add_scroll_timeout (PsppSheetView *tree_view)
5750 if (tree_view->priv->scroll_timeout == 0)
5752 tree_view->priv->scroll_timeout =
5753 gdk_threads_add_timeout (150, scroll_row_timeout, tree_view);
5758 remove_scroll_timeout (PsppSheetView *tree_view)
5760 if (tree_view->priv->scroll_timeout != 0)
5762 g_source_remove (tree_view->priv->scroll_timeout);
5763 tree_view->priv->scroll_timeout = 0;
5768 check_model_dnd (GtkTreeModel *model,
5769 GType required_iface,
5770 const gchar *signal)
5772 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5774 g_warning ("You must override the default '%s' handler "
5775 "on PsppSheetView when using models that don't support "
5776 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5777 "is to connect to '%s' and call "
5778 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5779 "the default handler from running. Look at the source code "
5780 "for the default handler in gtktreeview.c to get an idea what "
5781 "your handler should do. (gtktreeview.c is in the GTK source "
5782 "code.) If you're using GTK from a language other than C, "
5783 "there may be a more natural way to override default handlers, e.g. via derivation.",
5784 signal, g_type_name (required_iface), signal);
5792 scroll_row_timeout (gpointer data)
5794 PsppSheetView *tree_view = data;
5796 pspp_sheet_view_horizontal_autoscroll (tree_view);
5797 pspp_sheet_view_vertical_autoscroll (tree_view);
5799 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
5800 pspp_sheet_view_update_rubber_band (tree_view);
5805 /* Returns TRUE if event should not be propagated to parent widgets */
5807 set_destination_row (PsppSheetView *tree_view,
5808 GdkDragContext *context,
5809 /* coordinates relative to the widget */
5812 GdkDragAction *suggested_action,
5815 GtkTreePath *path = NULL;
5816 PsppSheetViewDropPosition pos;
5817 PsppSheetViewDropPosition old_pos;
5818 TreeViewDragInfo *di;
5820 GtkTreePath *old_dest_path = NULL;
5821 gboolean can_drop = FALSE;
5823 *suggested_action = 0;
5826 widget = GTK_WIDGET (tree_view);
5828 di = get_info (tree_view);
5830 if (di == NULL || y - TREE_VIEW_HEADER_HEIGHT (tree_view) < 0)
5832 /* someone unset us as a drag dest, note that if
5833 * we return FALSE drag_leave isn't called
5836 pspp_sheet_view_set_drag_dest_row (tree_view,
5838 PSPP_SHEET_VIEW_DROP_BEFORE);
5840 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
5842 return FALSE; /* no longer a drop site */
5845 *target = gtk_drag_dest_find_target (widget, context,
5846 gtk_drag_dest_get_target_list (widget));
5847 if (*target == GDK_NONE)
5852 if (!pspp_sheet_view_get_dest_row_at_pos (tree_view,
5858 GtkTreeModel *model;
5860 /* the row got dropped on empty space, let's setup a special case
5864 gtk_tree_path_free (path);
5866 model = pspp_sheet_view_get_model (tree_view);
5868 n_children = gtk_tree_model_iter_n_children (model, NULL);
5871 pos = PSPP_SHEET_VIEW_DROP_AFTER;
5872 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
5876 pos = PSPP_SHEET_VIEW_DROP_BEFORE;
5877 path = gtk_tree_path_new_from_indices (0, -1);
5887 /* If we left the current row's "open" zone, unset the timeout for
5890 pspp_sheet_view_get_drag_dest_row (tree_view,
5895 gtk_tree_path_free (old_dest_path);
5897 if (TRUE /* FIXME if the location droppable predicate */)
5905 GtkWidget *source_widget;
5907 *suggested_action = context->suggested_action;
5908 source_widget = gtk_drag_get_source_widget (context);
5910 if (source_widget == widget)
5912 /* Default to MOVE, unless the user has
5913 * pressed ctrl or shift to affect available actions
5915 if ((context->actions & GDK_ACTION_MOVE) != 0)
5916 *suggested_action = GDK_ACTION_MOVE;
5919 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
5924 /* can't drop here */
5925 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
5927 PSPP_SHEET_VIEW_DROP_BEFORE);
5931 gtk_tree_path_free (path);
5937 get_logical_dest_row (PsppSheetView *tree_view,
5938 gboolean *path_down_mode,
5939 gboolean *drop_append_mode)
5941 /* adjust path to point to the row the drop goes in front of */
5942 GtkTreePath *path = NULL;
5943 PsppSheetViewDropPosition pos;
5945 g_return_val_if_fail (path_down_mode != NULL, NULL);
5946 g_return_val_if_fail (drop_append_mode != NULL, NULL);
5948 *path_down_mode = FALSE;
5949 *drop_append_mode = 0;
5951 pspp_sheet_view_get_drag_dest_row (tree_view, &path, &pos);
5956 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE)
5958 else if (pos == PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE ||
5959 pos == PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER)
5960 *path_down_mode = TRUE;
5964 GtkTreeModel *model = pspp_sheet_view_get_model (tree_view);
5966 g_assert (pos == PSPP_SHEET_VIEW_DROP_AFTER);
5968 if (!gtk_tree_model_get_iter (model, &iter, path) ||
5969 !gtk_tree_model_iter_next (model, &iter))
5970 *drop_append_mode = 1;
5973 *drop_append_mode = 0;
5974 gtk_tree_path_next (path);
5982 pspp_sheet_view_maybe_begin_dragging_row (PsppSheetView *tree_view,
5983 GdkEventMotion *event)
5985 GtkWidget *widget = GTK_WIDGET (tree_view);
5986 GdkDragContext *context;
5987 TreeViewDragInfo *di;
5988 GtkTreePath *path = NULL;
5990 gint cell_x, cell_y;
5991 GtkTreeModel *model;
5992 gboolean retval = FALSE;
5994 di = get_info (tree_view);
5996 if (di == NULL || !di->source_set)
5999 if (tree_view->priv->pressed_button < 0)
6002 if (!gtk_drag_check_threshold (widget,
6003 tree_view->priv->press_start_x,
6004 tree_view->priv->press_start_y,
6005 event->x, event->y))
6008 model = pspp_sheet_view_get_model (tree_view);
6013 button = tree_view->priv->pressed_button;
6014 tree_view->priv->pressed_button = -1;
6016 pspp_sheet_view_get_path_at_pos (tree_view,
6017 tree_view->priv->press_start_x,
6018 tree_view->priv->press_start_y,
6027 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6028 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6032 if (!(GDK_BUTTON1_MASK << (button - 1) & di->start_button_mask))
6035 /* Now we can begin the drag */
6039 context = gtk_drag_begin (widget,
6040 gtk_drag_source_get_target_list (widget),
6045 set_source_row (context, model, path);
6049 gtk_tree_path_free (path);
6056 pspp_sheet_view_drag_begin (GtkWidget *widget,
6057 GdkDragContext *context)
6059 PsppSheetView *tree_view;
6060 GtkTreePath *path = NULL;
6061 gint cell_x, cell_y;
6063 TreeViewDragInfo *di;
6065 tree_view = PSPP_SHEET_VIEW (widget);
6067 /* if the user uses a custom DND source impl, we don't set the icon here */
6068 di = get_info (tree_view);
6070 if (di == NULL || !di->source_set)
6073 pspp_sheet_view_get_path_at_pos (tree_view,
6074 tree_view->priv->press_start_x,
6075 tree_view->priv->press_start_y,
6081 g_return_if_fail (path != NULL);
6083 row_pix = pspp_sheet_view_create_row_drag_icon (tree_view,
6086 gtk_drag_set_icon_pixmap (context,
6087 gdk_drawable_get_colormap (row_pix),
6090 /* the + 1 is for the black border in the icon */
6091 tree_view->priv->press_start_x + 1,
6094 g_object_unref (row_pix);
6095 gtk_tree_path_free (path);
6099 pspp_sheet_view_drag_end (GtkWidget *widget,
6100 GdkDragContext *context)
6105 /* Default signal implementations for the drag signals */
6107 pspp_sheet_view_drag_data_get (GtkWidget *widget,
6108 GdkDragContext *context,
6109 GtkSelectionData *selection_data,
6113 PsppSheetView *tree_view;
6114 GtkTreeModel *model;
6115 TreeViewDragInfo *di;
6116 GtkTreePath *source_row;
6118 tree_view = PSPP_SHEET_VIEW (widget);
6120 model = pspp_sheet_view_get_model (tree_view);
6125 di = get_info (PSPP_SHEET_VIEW (widget));
6130 source_row = get_source_row (context);
6132 if (source_row == NULL)
6135 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6136 * any model; for DragSource models there are some other targets
6140 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6141 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6146 /* If drag_data_get does nothing, try providing row data. */
6147 if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6149 gtk_tree_set_row_drag_data (selection_data,
6155 gtk_tree_path_free (source_row);
6160 pspp_sheet_view_drag_data_delete (GtkWidget *widget,
6161 GdkDragContext *context)
6163 TreeViewDragInfo *di;
6164 GtkTreeModel *model;
6165 PsppSheetView *tree_view;
6166 GtkTreePath *source_row;
6168 tree_view = PSPP_SHEET_VIEW (widget);
6169 model = pspp_sheet_view_get_model (tree_view);
6171 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
6174 di = get_info (tree_view);
6179 source_row = get_source_row (context);
6181 if (source_row == NULL)
6184 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6187 gtk_tree_path_free (source_row);
6189 set_source_row (context, NULL, NULL);
6193 pspp_sheet_view_drag_leave (GtkWidget *widget,
6194 GdkDragContext *context,
6197 /* unset any highlight row */
6198 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6200 PSPP_SHEET_VIEW_DROP_BEFORE);
6202 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6207 pspp_sheet_view_drag_motion (GtkWidget *widget,
6208 GdkDragContext *context,
6209 /* coordinates relative to the widget */
6215 GtkTreePath *path = NULL;
6216 PsppSheetViewDropPosition pos;
6217 PsppSheetView *tree_view;
6218 GdkDragAction suggested_action = 0;
6221 tree_view = PSPP_SHEET_VIEW (widget);
6223 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6226 pspp_sheet_view_get_drag_dest_row (tree_view, &path, &pos);
6228 /* we only know this *after* set_desination_row */
6229 empty = tree_view->priv->empty_view_drop;
6231 if (path == NULL && !empty)
6233 /* Can't drop here. */
6234 gdk_drag_status (context, 0, time);
6238 if (tree_view->priv->open_dest_timeout == 0 &&
6239 (pos == PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER ||
6240 pos == PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE))
6246 add_scroll_timeout (tree_view);
6249 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6251 /* Request data so we can use the source row when
6252 * determining whether to accept the drop
6254 set_status_pending (context, suggested_action);
6255 gtk_drag_get_data (widget, context, target, time);
6259 set_status_pending (context, 0);
6260 gdk_drag_status (context, suggested_action, time);
6265 gtk_tree_path_free (path);
6272 pspp_sheet_view_drag_drop (GtkWidget *widget,
6273 GdkDragContext *context,
6274 /* coordinates relative to the widget */
6279 PsppSheetView *tree_view;
6281 GdkDragAction suggested_action = 0;
6282 GdkAtom target = GDK_NONE;
6283 TreeViewDragInfo *di;
6284 GtkTreeModel *model;
6285 gboolean path_down_mode;
6286 gboolean drop_append_mode;
6288 tree_view = PSPP_SHEET_VIEW (widget);
6290 model = pspp_sheet_view_get_model (tree_view);
6292 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6294 di = get_info (tree_view);
6299 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
6302 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6305 path = get_logical_dest_row (tree_view, &path_down_mode, &drop_append_mode);
6307 if (target != GDK_NONE && path != NULL)
6309 /* in case a motion had requested drag data, change things so we
6310 * treat drag data receives as a drop.
6312 set_status_pending (context, 0);
6313 set_dest_row (context, model, path,
6314 path_down_mode, tree_view->priv->empty_view_drop,
6319 gtk_tree_path_free (path);
6321 /* Unset this thing */
6322 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6324 PSPP_SHEET_VIEW_DROP_BEFORE);
6326 if (target != GDK_NONE)
6328 gtk_drag_get_data (widget, context, target, time);
6336 pspp_sheet_view_drag_data_received (GtkWidget *widget,
6337 GdkDragContext *context,
6338 /* coordinates relative to the widget */
6341 GtkSelectionData *selection_data,
6346 TreeViewDragInfo *di;
6347 gboolean accepted = FALSE;
6348 GtkTreeModel *model;
6349 PsppSheetView *tree_view;
6350 GtkTreePath *dest_row;
6351 GdkDragAction suggested_action;
6352 gboolean path_down_mode;
6353 gboolean drop_append_mode;
6355 tree_view = PSPP_SHEET_VIEW (widget);
6357 model = pspp_sheet_view_get_model (tree_view);
6359 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_data_received"))
6362 di = get_info (tree_view);
6367 suggested_action = get_status_pending (context);
6369 if (suggested_action)
6371 /* We are getting this data due to a request in drag_motion,
6372 * rather than due to a request in drag_drop, so we are just
6373 * supposed to call drag_status, not actually paste in the
6376 path = get_logical_dest_row (tree_view, &path_down_mode,
6380 suggested_action = 0;
6381 else if (path_down_mode)
6382 gtk_tree_path_down (path);
6384 if (suggested_action)
6386 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6392 path_down_mode = FALSE;
6393 gtk_tree_path_up (path);
6395 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6398 suggested_action = 0;
6401 suggested_action = 0;
6405 gdk_drag_status (context, suggested_action, time);
6408 gtk_tree_path_free (path);
6410 /* If you can't drop, remove user drop indicator until the next motion */
6411 if (suggested_action == 0)
6412 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6414 PSPP_SHEET_VIEW_DROP_BEFORE);
6419 dest_row = get_dest_row (context, &path_down_mode);
6421 if (dest_row == NULL)
6424 if (selection_data->length >= 0)
6428 gtk_tree_path_down (dest_row);
6429 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6430 dest_row, selection_data))
6431 gtk_tree_path_up (dest_row);
6435 if (selection_data->length >= 0)
6437 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6443 gtk_drag_finish (context,
6445 (context->action == GDK_ACTION_MOVE),
6448 if (gtk_tree_path_get_depth (dest_row) == 1
6449 && gtk_tree_path_get_indices (dest_row)[0] == 0)
6451 /* special special case drag to "0", scroll to first item */
6452 if (!tree_view->priv->scroll_to_path)
6453 pspp_sheet_view_scroll_to_cell (tree_view, dest_row, NULL, FALSE, 0.0, 0.0);
6456 gtk_tree_path_free (dest_row);
6459 set_dest_row (context, NULL, NULL, FALSE, FALSE, FALSE);
6464 /* GtkContainer Methods
6469 pspp_sheet_view_remove (GtkContainer *container,
6472 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6473 PsppSheetViewChild *child = NULL;
6476 tmp_list = tree_view->priv->children;
6479 child = tmp_list->data;
6480 if (child->widget == widget)
6482 gtk_widget_unparent (widget);
6484 tree_view->priv->children = g_list_remove_link (tree_view->priv->children, tmp_list);
6485 g_list_free_1 (tmp_list);
6486 g_slice_free (PsppSheetViewChild, child);
6490 tmp_list = tmp_list->next;
6493 tmp_list = tree_view->priv->columns;
6497 PsppSheetViewColumn *column;
6498 column = tmp_list->data;
6499 if (column->button == widget)
6501 gtk_widget_unparent (widget);
6504 tmp_list = tmp_list->next;
6509 pspp_sheet_view_forall (GtkContainer *container,
6510 gboolean include_internals,
6511 GtkCallback callback,
6512 gpointer callback_data)
6514 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6515 PsppSheetViewChild *child = NULL;
6516 PsppSheetViewColumn *column;
6519 tmp_list = tree_view->priv->children;
6522 child = tmp_list->data;
6523 tmp_list = tmp_list->next;
6525 (* callback) (child->widget, callback_data);
6527 if (include_internals == FALSE)
6530 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6532 column = tmp_list->data;
6535 (* callback) (column->button, callback_data);
6539 /* Returns TRUE if the treeview contains no "special" (editable or activatable)
6540 * cells. If so we draw one big row-spanning focus rectangle.
6543 pspp_sheet_view_has_special_cell (PsppSheetView *tree_view)
6547 if (tree_view->priv->special_cells != PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT)
6548 return tree_view->priv->special_cells = PSPP_SHEET_VIEW_SPECIAL_CELLS_YES;
6550 for (list = tree_view->priv->columns; list; list = list->next)
6552 if (!((PsppSheetViewColumn *)list->data)->visible)
6554 if (_pspp_sheet_view_column_count_special_cells (list->data))
6562 pspp_sheet_view_focus_column (PsppSheetView *tree_view,
6563 PsppSheetViewColumn *focus_column,
6564 gboolean clamp_column_visible)
6566 g_return_if_fail (focus_column != NULL);
6568 tree_view->priv->focus_column = focus_column;
6569 if (!focus_column->button)
6571 pspp_sheet_view_column_set_need_button (focus_column, TRUE);
6572 g_return_if_fail (focus_column->button != NULL);
6575 if (GTK_CONTAINER (tree_view)->focus_child != focus_column->button)
6576 gtk_widget_grab_focus (focus_column->button);
6578 if (clamp_column_visible)
6579 pspp_sheet_view_clamp_column_visible (tree_view, focus_column, FALSE);
6582 /* Returns TRUE if the focus is within the headers, after the focus operation is
6586 pspp_sheet_view_header_focus (PsppSheetView *tree_view,
6587 GtkDirectionType dir,
6588 gboolean clamp_column_visible)
6590 GtkWidget *focus_child;
6591 PsppSheetViewColumn *focus_column;
6592 GList *last_column, *first_column;
6596 if (! PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
6599 focus_child = GTK_CONTAINER (tree_view)->focus_child;
6601 first_column = tree_view->priv->columns;
6602 while (first_column)
6604 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (first_column->data);
6606 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6608 first_column = first_column->next;
6611 /* No headers are visible, or are focusable. We can't focus in or out.
6613 if (first_column == NULL)
6616 last_column = g_list_last (tree_view->priv->columns);
6619 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (last_column->data);
6621 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6623 last_column = last_column->prev;
6627 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
6631 case GTK_DIR_TAB_BACKWARD:
6632 case GTK_DIR_TAB_FORWARD:
6635 if (focus_child == NULL)
6637 if (tree_view->priv->focus_column != NULL &&
6638 pspp_sheet_view_column_can_focus (tree_view->priv->focus_column))
6639 focus_column = tree_view->priv->focus_column;
6641 focus_column = first_column->data;
6642 pspp_sheet_view_focus_column (tree_view, focus_column,
6643 clamp_column_visible);
6650 if (focus_child == NULL)
6652 if (tree_view->priv->focus_column != NULL)
6653 focus_column = tree_view->priv->focus_column;
6654 else if (dir == GTK_DIR_LEFT)
6655 focus_column = last_column->data;
6657 focus_column = first_column->data;
6658 pspp_sheet_view_focus_column (tree_view, focus_column,
6659 clamp_column_visible);
6663 if (gtk_widget_child_focus (focus_child, dir))
6665 /* The focus moves inside the button. */
6666 /* This is probably a great example of bad UI */
6667 if (clamp_column_visible)
6668 pspp_sheet_view_clamp_column_visible (tree_view,
6669 tree_view->priv->focus_column,
6674 /* We need to move the focus among the row of buttons. */
6675 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6676 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)->button == focus_child)
6679 if ((tmp_list == first_column && dir == (rtl ? GTK_DIR_RIGHT : GTK_DIR_LEFT))
6680 || (tmp_list == last_column && dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT)))
6682 gtk_widget_error_bell (GTK_WIDGET (tree_view));
6688 PsppSheetViewColumn *column;
6690 if (dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT))
6691 tmp_list = tmp_list->next;
6693 tmp_list = tmp_list->prev;
6695 if (tmp_list == NULL)
6697 g_warning ("Internal button not found");
6700 column = tmp_list->data;
6701 if (column->button &&
6703 pspp_sheet_view_column_can_focus (column))
6705 pspp_sheet_view_focus_column (tree_view, column,
6706 clamp_column_visible);
6713 g_assert_not_reached ();
6720 /* This function returns in 'path' the first focusable path, if the given path
6721 * is already focusable, it's the returned one.
6725 search_first_focusable_path (PsppSheetView *tree_view,
6727 gboolean search_forward,
6730 /* XXX this function is trivial given that the sheetview doesn't support
6734 if (!path || !*path)
6737 _pspp_sheet_view_find_node (tree_view, *path, &node);
6745 return (*path != NULL);
6749 pspp_sheet_view_focus (GtkWidget *widget,
6750 GtkDirectionType direction)
6752 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6753 GtkContainer *container = GTK_CONTAINER (widget);
6754 GtkWidget *focus_child;
6756 if (!gtk_widget_is_sensitive (widget) || !gtk_widget_get_can_focus (widget))
6759 focus_child = container->focus_child;
6761 pspp_sheet_view_stop_editing (PSPP_SHEET_VIEW (widget), FALSE);
6762 /* Case 1. Headers currently have focus. */
6769 pspp_sheet_view_header_focus (tree_view, direction, TRUE);
6771 case GTK_DIR_TAB_BACKWARD:
6774 case GTK_DIR_TAB_FORWARD:
6776 gtk_widget_grab_focus (widget);
6779 g_assert_not_reached ();
6784 /* Case 2. We don't have focus at all. */
6785 if (!gtk_widget_has_focus (widget))
6787 if (!pspp_sheet_view_header_focus (tree_view, direction, FALSE))
6788 gtk_widget_grab_focus (widget);
6792 /* Case 3. We have focus already. */
6793 if (direction == GTK_DIR_TAB_BACKWARD)
6794 return (pspp_sheet_view_header_focus (tree_view, direction, FALSE));
6795 else if (direction == GTK_DIR_TAB_FORWARD)
6798 /* Other directions caught by the keybindings */
6799 gtk_widget_grab_focus (widget);
6804 pspp_sheet_view_grab_focus (GtkWidget *widget)
6806 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->grab_focus (widget);
6808 pspp_sheet_view_focus_to_cursor (PSPP_SHEET_VIEW (widget));
6812 pspp_sheet_view_style_set (GtkWidget *widget,
6813 GtkStyle *previous_style)
6815 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6817 PsppSheetViewColumn *column;
6819 if (gtk_widget_get_realized (widget))
6822 PsppSheetViewPrivate *priv = PSPP_SHEET_VIEW (widget)->priv;
6824 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
6825 gdk_window_set_background (tree_view->priv->bin_window, &widget->style->base[widget->state]);
6826 gtk_style_set_background (widget->style, tree_view->priv->header_window, GTK_STATE_NORMAL);
6827 for (i = 0; i < 5 ; ++i)
6829 g_object_unref (priv->grid_line_gc[i]);
6830 priv->grid_line_gc[i] = gdk_gc_new (widget->window);
6831 gdk_gc_copy (priv->grid_line_gc[i], widget->style->text_aa_gc[i]);
6834 pspp_sheet_view_set_grid_lines (tree_view, tree_view->priv->grid_lines);
6837 gtk_widget_style_get (widget,
6838 "expander-size", &tree_view->priv->expander_size,
6840 tree_view->priv->expander_size += EXPANDER_EXTRA_PADDING;
6842 for (list = tree_view->priv->columns; list; list = list->next)
6844 column = list->data;
6845 _pspp_sheet_view_column_cell_set_dirty (column);
6848 tree_view->priv->fixed_height = -1;
6850 /* Invalidate cached button style. */
6851 if (tree_view->priv->button_style)
6853 g_object_unref (tree_view->priv->button_style);
6854 tree_view->priv->button_style = NULL;
6857 gtk_widget_queue_resize (widget);
6862 pspp_sheet_view_set_focus_child (GtkContainer *container,
6865 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6868 for (list = tree_view->priv->columns; list; list = list->next)
6870 if (PSPP_SHEET_VIEW_COLUMN (list->data)->button == child)
6872 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
6877 GTK_CONTAINER_CLASS (pspp_sheet_view_parent_class)->set_focus_child (container, child);
6881 pspp_sheet_view_set_adjustments (PsppSheetView *tree_view,
6882 GtkAdjustment *hadj,
6883 GtkAdjustment *vadj)
6885 gboolean need_adjust = FALSE;
6887 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
6890 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
6892 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
6894 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
6896 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
6898 if (tree_view->priv->hadjustment && (tree_view->priv->hadjustment != hadj))
6900 g_signal_handlers_disconnect_by_func (tree_view->priv->hadjustment,
6901 pspp_sheet_view_adjustment_changed,
6903 g_object_unref (tree_view->priv->hadjustment);
6906 if (tree_view->priv->vadjustment && (tree_view->priv->vadjustment != vadj))
6908 g_signal_handlers_disconnect_by_func (tree_view->priv->vadjustment,
6909 pspp_sheet_view_adjustment_changed,
6911 g_object_unref (tree_view->priv->vadjustment);
6914 if (tree_view->priv->hadjustment != hadj)
6916 tree_view->priv->hadjustment = hadj;
6917 g_object_ref_sink (tree_view->priv->hadjustment);
6919 g_signal_connect (tree_view->priv->hadjustment, "value-changed",
6920 G_CALLBACK (pspp_sheet_view_adjustment_changed),
6925 if (tree_view->priv->vadjustment != vadj)
6927 tree_view->priv->vadjustment = vadj;
6928 g_object_ref_sink (tree_view->priv->vadjustment);
6930 g_signal_connect (tree_view->priv->vadjustment, "value-changed",
6931 G_CALLBACK (pspp_sheet_view_adjustment_changed),
6937 pspp_sheet_view_adjustment_changed (NULL, tree_view);
6942 pspp_sheet_view_real_move_cursor (PsppSheetView *tree_view,
6943 GtkMovementStep step,
6946 GdkModifierType state;
6948 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
6949 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
6950 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
6951 step == GTK_MOVEMENT_DISPLAY_LINES ||
6952 step == GTK_MOVEMENT_PAGES ||
6953 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
6955 if (tree_view->priv->row_count == 0)
6957 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
6960 pspp_sheet_view_stop_editing (tree_view, FALSE);
6961 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
6962 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
6964 if (gtk_get_current_event_state (&state))
6966 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
6967 tree_view->priv->ctrl_pressed = TRUE;
6968 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
6969 tree_view->priv->shift_pressed = TRUE;
6971 /* else we assume not pressed */
6975 /* currently we make no distinction. When we go bi-di, we need to */
6976 case GTK_MOVEMENT_LOGICAL_POSITIONS:
6977 case GTK_MOVEMENT_VISUAL_POSITIONS:
6978 pspp_sheet_view_move_cursor_left_right (tree_view, count);
6980 case GTK_MOVEMENT_DISPLAY_LINES:
6981 pspp_sheet_view_move_cursor_up_down (tree_view, count);
6983 case GTK_MOVEMENT_PAGES:
6984 pspp_sheet_view_move_cursor_page_up_down (tree_view, count);
6986 case GTK_MOVEMENT_BUFFER_ENDS:
6987 pspp_sheet_view_move_cursor_start_end (tree_view, count);
6990 g_assert_not_reached ();
6993 tree_view->priv->ctrl_pressed = FALSE;
6994 tree_view->priv->shift_pressed = FALSE;
7000 pspp_sheet_view_put (PsppSheetView *tree_view,
7001 GtkWidget *child_widget,
7002 /* in bin_window coordinates */
7008 PsppSheetViewChild *child;
7010 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
7011 g_return_if_fail (GTK_IS_WIDGET (child_widget));
7013 child = g_slice_new (PsppSheetViewChild);
7015 child->widget = child_widget;
7018 child->width = width;
7019 child->height = height;
7021 tree_view->priv->children = g_list_append (tree_view->priv->children, child);
7023 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7024 gtk_widget_set_parent_window (child->widget, tree_view->priv->bin_window);
7026 gtk_widget_set_parent (child_widget, GTK_WIDGET (tree_view));
7030 _pspp_sheet_view_child_move_resize (PsppSheetView *tree_view,
7032 /* in tree coordinates */
7038 PsppSheetViewChild *child = NULL;
7040 GdkRectangle allocation;
7042 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
7043 g_return_if_fail (GTK_IS_WIDGET (widget));
7045 for (list = tree_view->priv->children; list; list = list->next)
7047 if (((PsppSheetViewChild *)list->data)->widget == widget)
7056 allocation.x = child->x = x;
7057 allocation.y = child->y = y;
7058 allocation.width = child->width = width;
7059 allocation.height = child->height = height;
7061 if (gtk_widget_get_realized (widget))
7062 gtk_widget_size_allocate (widget, &allocation);
7066 /* TreeModel Callbacks
7070 pspp_sheet_view_row_changed (GtkTreeModel *model,
7075 PsppSheetView *tree_view = (PsppSheetView *)data;
7077 gboolean free_path = FALSE;
7078 GtkTreePath *cursor_path;
7080 g_return_if_fail (path != NULL || iter != NULL);
7082 if (tree_view->priv->cursor != NULL)
7083 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7087 if (tree_view->priv->edited_column &&
7088 (cursor_path == NULL || gtk_tree_path_compare (cursor_path, path) == 0))
7089 pspp_sheet_view_stop_editing (tree_view, TRUE);
7091 if (cursor_path != NULL)
7092 gtk_tree_path_free (cursor_path);
7096 path = gtk_tree_model_get_path (model, iter);
7099 else if (iter == NULL)
7100 gtk_tree_model_get_iter (model, iter, path);
7102 _pspp_sheet_view_find_node (tree_view,
7108 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7109 pspp_sheet_view_node_queue_redraw (tree_view, node);
7113 gtk_tree_path_free (path);
7117 pspp_sheet_view_row_inserted (GtkTreeModel *model,
7122 PsppSheetView *tree_view = (PsppSheetView *) data;
7125 gint height = tree_view->priv->fixed_height;
7126 gboolean free_path = FALSE;
7127 gboolean node_visible = TRUE;
7129 g_return_if_fail (path != NULL || iter != NULL);
7133 path = gtk_tree_model_get_path (model, iter);
7136 else if (iter == NULL)
7137 gtk_tree_model_get_iter (model, iter, path);
7139 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7141 /* Update all row-references */
7142 gtk_tree_row_reference_inserted (G_OBJECT (data), path);
7143 indices = gtk_tree_path_get_indices (path);
7144 tmpnode = indices[0];
7146 range_tower_insert0 (tree_view->priv->selected, tmpnode, 1);
7150 if (node_visible && node_is_visible (tree_view, tmpnode))
7151 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7153 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (tree_view));
7156 install_presize_handler (tree_view);
7158 gtk_tree_path_free (path);
7162 pspp_sheet_view_row_deleted (GtkTreeModel *model,
7166 PsppSheetView *tree_view = (PsppSheetView *)data;
7169 g_return_if_fail (path != NULL);
7171 gtk_tree_row_reference_deleted (G_OBJECT (data), path);
7173 _pspp_sheet_view_find_node (tree_view, path, &node);
7178 range_tower_delete (tree_view->priv->selected, node, 1);
7180 /* Ensure we don't have a dangling pointer to a dead node */
7181 ensure_unprelighted (tree_view);
7183 /* Cancel editting if we've started */
7184 pspp_sheet_view_stop_editing (tree_view, TRUE);
7186 if (tree_view->priv->destroy_count_func)
7188 gint child_count = 0;
7189 tree_view->priv->destroy_count_func (tree_view, path, child_count, tree_view->priv->destroy_count_data);
7192 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7194 if (! gtk_tree_row_reference_valid (tree_view->priv->top_row))
7196 gtk_tree_row_reference_free (tree_view->priv->top_row);
7197 tree_view->priv->top_row = NULL;
7200 install_scroll_sync_handler (tree_view);
7202 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7205 if (helper_data.changed)
7206 g_signal_emit_by_name (tree_view->priv->selection, "changed");
7211 pspp_sheet_view_rows_reordered (GtkTreeModel *model,
7212 GtkTreePath *parent,
7217 PsppSheetView *tree_view = PSPP_SHEET_VIEW (data);
7220 /* XXX need to adjust selection */
7221 len = gtk_tree_model_iter_n_children (model, iter);
7226 gtk_tree_row_reference_reordered (G_OBJECT (data),
7231 if (gtk_tree_path_get_depth (parent) != 0)
7234 if (tree_view->priv->edited_column)
7235 pspp_sheet_view_stop_editing (tree_view, TRUE);
7237 /* we need to be unprelighted */
7238 ensure_unprelighted (tree_view);
7240 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
7242 pspp_sheet_view_dy_to_top_row (tree_view);
7246 /* Internal tree functions
7251 pspp_sheet_view_get_background_xrange (PsppSheetView *tree_view,
7252 PsppSheetViewColumn *column,
7256 PsppSheetViewColumn *tmp_column = NULL;
7267 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7270 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
7272 list = (rtl ? list->prev : list->next))
7274 tmp_column = list->data;
7276 if (tmp_column == column)
7279 if (tmp_column->visible)
7280 total_width += tmp_column->width;
7283 if (tmp_column != column)
7285 g_warning (G_STRLOC": passed-in column isn't in the tree");
7294 if (column->visible)
7295 *x2 = total_width + column->width;
7297 *x2 = total_width; /* width of 0 */
7301 /* Make sure the node is visible vertically */
7303 pspp_sheet_view_clamp_node_visible (PsppSheetView *tree_view,
7306 gint node_dy, height;
7307 GtkTreePath *path = NULL;
7309 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7312 /* just return if the node is visible, avoiding a costly expose */
7313 node_dy = pspp_sheet_view_node_find_offset (tree_view, node);
7314 height = ROW_HEIGHT (tree_view);
7315 if (node_dy >= tree_view->priv->vadjustment->value
7316 && node_dy + height <= (tree_view->priv->vadjustment->value
7317 + tree_view->priv->vadjustment->page_size))
7320 path = _pspp_sheet_view_find_path (tree_view, node);
7323 /* We process updates because we want to clear old selected items when we scroll.
7324 * if this is removed, we get a "selection streak" at the bottom. */
7325 gdk_window_process_updates (tree_view->priv->bin_window, TRUE);
7326 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL, FALSE, 0.0, 0.0);
7327 gtk_tree_path_free (path);
7332 pspp_sheet_view_clamp_column_visible (PsppSheetView *tree_view,
7333 PsppSheetViewColumn *column,
7334 gboolean focus_to_cell)
7341 x = column->allocation.x;
7342 width = column->allocation.width;
7344 if (width > tree_view->priv->hadjustment->page_size)
7346 /* The column is larger than the horizontal page size. If the
7347 * column has cells which can be focussed individually, then we make
7348 * sure the cell which gets focus is fully visible (if even the
7349 * focus cell is bigger than the page size, we make sure the
7350 * left-hand side of the cell is visible).
7352 * If the column does not have those so-called special cells, we
7353 * make sure the left-hand side of the column is visible.
7356 if (focus_to_cell && pspp_sheet_view_has_special_cell (tree_view))
7358 GtkTreePath *cursor_path;
7359 GdkRectangle background_area, cell_area, focus_area;
7361 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7363 pspp_sheet_view_get_cell_area (tree_view,
7364 cursor_path, column, &cell_area);
7365 pspp_sheet_view_get_background_area (tree_view,
7366 cursor_path, column,
7369 gtk_tree_path_free (cursor_path);
7371 _pspp_sheet_view_column_get_focus_area (column,
7377 width = focus_area.width;
7379 if (width < tree_view->priv->hadjustment->page_size)
7381 if ((tree_view->priv->hadjustment->value + tree_view->priv->hadjustment->page_size) < (x + width))
7382 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7383 x + width - tree_view->priv->hadjustment->page_size);
7384 else if (tree_view->priv->hadjustment->value > x)
7385 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7389 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7391 tree_view->priv->hadjustment->lower,
7392 tree_view->priv->hadjustment->upper
7393 - tree_view->priv->hadjustment->page_size));
7397 if ((tree_view->priv->hadjustment->value + tree_view->priv->hadjustment->page_size) < (x + width))
7398 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7399 x + width - tree_view->priv->hadjustment->page_size);
7400 else if (tree_view->priv->hadjustment->value > x)
7401 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7406 _pspp_sheet_view_find_path (PsppSheetView *tree_view,
7411 path = gtk_tree_path_new ();
7413 gtk_tree_path_append_index (path, node);
7418 _pspp_sheet_view_find_node (PsppSheetView *tree_view,
7422 gint *indices = gtk_tree_path_get_indices (path);
7423 gint depth = gtk_tree_path_get_depth (path);
7426 if (depth == 0 || indices[0] < 0 || indices[0] >= tree_view->priv->row_count)
7432 pspp_sheet_view_add_move_binding (GtkBindingSet *binding_set,
7435 gboolean add_shifted_binding,
7436 GtkMovementStep step,
7440 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
7445 if (add_shifted_binding)
7446 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
7451 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
7454 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
7459 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
7466 pspp_sheet_view_set_column_drag_info (PsppSheetView *tree_view,
7467 PsppSheetViewColumn *column)
7469 PsppSheetViewColumn *left_column;
7470 PsppSheetViewColumn *cur_column = NULL;
7471 PsppSheetViewColumnReorder *reorder;
7476 /* We want to precalculate the motion list such that we know what column slots
7480 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7482 /* First, identify all possible drop spots */
7484 tmp_list = g_list_last (tree_view->priv->columns);
7486 tmp_list = g_list_first (tree_view->priv->columns);
7490 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
7491 tmp_list = rtl?g_list_previous (tmp_list):g_list_next (tmp_list);
7493 if (cur_column->visible == FALSE)
7496 /* If it's not the column moving and func tells us to skip over the column, we continue. */
7497 if (left_column != column && cur_column != column &&
7498 tree_view->priv->column_drop_func &&
7499 ! tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
7501 left_column = cur_column;
7504 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7505 reorder->left_column = left_column;
7506 left_column = reorder->right_column = cur_column;
7508 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7511 /* Add the last one */
7512 if (tree_view->priv->column_drop_func == NULL ||
7513 ((left_column != column) &&
7514 tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data)))
7516 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7517 reorder->left_column = left_column;
7518 reorder->right_column = NULL;
7519 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7522 /* We quickly check to see if it even makes sense to reorder columns. */
7523 /* If there is nothing that can be moved, then we return */
7525 if (tree_view->priv->column_drag_info == NULL)
7528 /* We know there are always 2 slots possbile, as you can always return column. */
7529 /* If that's all there is, return */
7530 if (tree_view->priv->column_drag_info->next == NULL ||
7531 (tree_view->priv->column_drag_info->next->next == NULL &&
7532 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->data)->right_column == column &&
7533 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->next->data)->left_column == column))
7535 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7536 g_slice_free (PsppSheetViewColumnReorder, tmp_list->data);
7537 g_list_free (tree_view->priv->column_drag_info);
7538 tree_view->priv->column_drag_info = NULL;
7541 /* We fill in the ranges for the columns, now that we've isolated them */
7542 left = - TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7544 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7546 reorder = (PsppSheetViewColumnReorder *) tmp_list->data;
7548 reorder->left_align = left;
7549 if (tmp_list->next != NULL)
7551 g_assert (tmp_list->next->data);
7552 left = reorder->right_align = (reorder->right_column->allocation.x +
7553 reorder->right_column->allocation.width +
7554 ((PsppSheetViewColumnReorder *)tmp_list->next->data)->left_column->allocation.x)/2;
7560 gdk_drawable_get_size (tree_view->priv->header_window, &width, NULL);
7561 reorder->right_align = width + TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7567 _pspp_sheet_view_column_start_drag (PsppSheetView *tree_view,
7568 PsppSheetViewColumn *column)
7570 GdkEvent *send_event;
7571 GtkAllocation allocation;
7572 gint x, y, width, height;
7573 GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
7574 GdkDisplay *display = gdk_screen_get_display (screen);
7576 g_return_if_fail (tree_view->priv->column_drag_info == NULL);
7577 g_return_if_fail (tree_view->priv->cur_reorder == NULL);
7578 g_return_if_fail (column->button);
7580 pspp_sheet_view_set_column_drag_info (tree_view, column);
7582 if (tree_view->priv->column_drag_info == NULL)
7585 if (tree_view->priv->drag_window == NULL)
7587 GdkWindowAttr attributes;
7588 guint attributes_mask;
7590 attributes.window_type = GDK_WINDOW_CHILD;
7591 attributes.wclass = GDK_INPUT_OUTPUT;
7592 attributes.x = column->allocation.x;
7594 attributes.width = column->allocation.width;
7595 attributes.height = column->allocation.height;
7596 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
7597 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
7598 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
7599 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
7601 tree_view->priv->drag_window = gdk_window_new (tree_view->priv->bin_window,
7604 gdk_window_set_user_data (tree_view->priv->drag_window, GTK_WIDGET (tree_view));
7607 gdk_display_pointer_ungrab (display, GDK_CURRENT_TIME);
7608 gdk_display_keyboard_ungrab (display, GDK_CURRENT_TIME);
7610 gtk_grab_remove (column->button);
7612 send_event = gdk_event_new (GDK_LEAVE_NOTIFY);
7613 send_event->crossing.send_event = TRUE;
7614 send_event->crossing.window = g_object_ref (GTK_BUTTON (column->button)->event_window);
7615 send_event->crossing.subwindow = NULL;
7616 send_event->crossing.detail = GDK_NOTIFY_ANCESTOR;
7617 send_event->crossing.time = GDK_CURRENT_TIME;
7619 gtk_propagate_event (column->button, send_event);
7620 gdk_event_free (send_event);
7622 send_event = gdk_event_new (GDK_BUTTON_RELEASE);
7623 send_event->button.window = g_object_ref (gdk_screen_get_root_window (screen));
7624 send_event->button.send_event = TRUE;
7625 send_event->button.time = GDK_CURRENT_TIME;
7626 send_event->button.x = -1;
7627 send_event->button.y = -1;
7628 send_event->button.axes = NULL;
7629 send_event->button.state = 0;
7630 send_event->button.button = 1;
7631 send_event->button.device = gdk_display_get_core_pointer (display);
7632 send_event->button.x_root = 0;
7633 send_event->button.y_root = 0;
7635 gtk_propagate_event (column->button, send_event);
7636 gdk_event_free (send_event);
7638 /* Kids, don't try this at home */
7639 g_object_ref (column->button);
7640 gtk_container_remove (GTK_CONTAINER (tree_view), column->button);
7641 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7642 gtk_widget_set_parent (column->button, GTK_WIDGET (tree_view));
7643 g_object_unref (column->button);
7645 tree_view->priv->drag_column_x = column->allocation.x;
7646 allocation = column->allocation;
7648 gtk_widget_size_allocate (column->button, &allocation);
7649 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7651 tree_view->priv->drag_column = column;
7652 gdk_window_show (tree_view->priv->drag_window);
7654 gdk_window_get_origin (tree_view->priv->header_window, &x, &y);
7655 gdk_drawable_get_size (tree_view->priv->header_window, &width, &height);
7657 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7658 while (gtk_events_pending ())
7659 gtk_main_iteration ();
7661 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG);
7662 gdk_pointer_grab (tree_view->priv->drag_window,
7664 GDK_POINTER_MOTION_MASK|GDK_BUTTON_RELEASE_MASK,
7665 NULL, NULL, GDK_CURRENT_TIME);
7666 gdk_keyboard_grab (tree_view->priv->drag_window,
7672 _pspp_sheet_view_queue_draw_node (PsppSheetView *tree_view,
7674 const GdkRectangle *clip_rect)
7678 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7682 rect.width = MAX (tree_view->priv->width, GTK_WIDGET (tree_view)->allocation.width);
7684 rect.y = BACKGROUND_FIRST_PIXEL (tree_view, node);
7685 rect.height = ROW_HEIGHT (tree_view);
7689 GdkRectangle new_rect;
7691 gdk_rectangle_intersect (clip_rect, &rect, &new_rect);
7693 gdk_window_invalidate_rect (tree_view->priv->bin_window, &new_rect, TRUE);
7697 gdk_window_invalidate_rect (tree_view->priv->bin_window, &rect, TRUE);
7702 pspp_sheet_view_queue_draw_path (PsppSheetView *tree_view,
7704 const GdkRectangle *clip_rect)
7708 _pspp_sheet_view_find_node (tree_view, path, &node);
7711 _pspp_sheet_view_queue_draw_node (tree_view, node, clip_rect);
7715 pspp_sheet_view_focus_to_cursor (PsppSheetView *tree_view)
7718 GtkTreePath *cursor_path;
7720 if ((tree_view->priv->row_count == 0) ||
7721 (! gtk_widget_get_realized (GTK_WIDGET (tree_view))))
7725 if (tree_view->priv->cursor)
7726 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7728 if (cursor_path == NULL)
7730 /* There's no cursor. Move the cursor to the first selected row, if any
7731 * are selected, otherwise to the first row in the sheetview.
7733 GList *selected_rows;
7734 GtkTreeModel *model;
7735 PsppSheetSelection *selection;
7737 selection = pspp_sheet_view_get_selection (tree_view);
7738 selected_rows = pspp_sheet_selection_get_selected_rows (selection, &model);
7742 /* XXX we could avoid doing O(n) work to get this result */
7743 cursor_path = gtk_tree_path_copy((const GtkTreePath *)(selected_rows->data));
7744 g_list_foreach (selected_rows, (GFunc)gtk_tree_path_free, NULL);
7745 g_list_free (selected_rows);
7749 cursor_path = gtk_tree_path_new_first ();
7750 search_first_focusable_path (tree_view, &cursor_path,
7754 gtk_tree_row_reference_free (tree_view->priv->cursor);
7755 tree_view->priv->cursor = NULL;
7759 if (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7760 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE)
7761 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, FALSE, FALSE);
7763 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE);
7769 /* Now find a column for the cursor. */
7770 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
7772 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
7773 gtk_tree_path_free (cursor_path);
7775 if (tree_view->priv->focus_column == NULL)
7778 for (list = tree_view->priv->columns; list; list = list->next)
7780 if (PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
7782 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
7783 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
7784 pspp_sheet_selection_select_column (tree_view->priv->selection, tree_view->priv->focus_column);
7794 pspp_sheet_view_move_cursor_up_down (PsppSheetView *tree_view,
7797 gint selection_count;
7798 int cursor_node = -1;
7799 int new_cursor_node = -1;
7800 GtkTreePath *cursor_path = NULL;
7801 gboolean grab_focus = TRUE;
7803 if (! gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7807 if (!gtk_tree_row_reference_valid (tree_view->priv->cursor))
7808 /* FIXME: we lost the cursor; should we get the first? */
7811 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7812 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
7814 if (cursor_node < 0)
7815 /* FIXME: we lost the cursor; should we get the first? */
7818 selection_count = pspp_sheet_selection_count_selected_rows (tree_view->priv->selection);
7820 if (selection_count == 0
7821 && tree_view->priv->selection->type != PSPP_SHEET_SELECTION_NONE
7822 && !tree_view->priv->ctrl_pressed)
7824 /* Don't move the cursor, but just select the current node */
7825 new_cursor_node = cursor_node;
7830 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
7832 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7835 gtk_tree_path_free (cursor_path);
7837 if (new_cursor_node)
7839 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
7841 search_first_focusable_path (tree_view, &cursor_path,
7846 gtk_tree_path_free (cursor_path);
7850 * If the list has only one item and multi-selection is set then select
7851 * the row (if not yet selected).
7853 if ((tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7854 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE) &&
7855 new_cursor_node < 0)
7858 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7860 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
7862 if (new_cursor_node < 0
7863 && !pspp_sheet_view_node_is_selected (tree_view, cursor_node))
7865 new_cursor_node = cursor_node;
7869 new_cursor_node = -1;
7873 if (new_cursor_node >= 0)
7875 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
7876 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, TRUE);
7877 gtk_tree_path_free (cursor_path);
7881 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
7883 if (!tree_view->priv->shift_pressed)
7885 if (! gtk_widget_keynav_failed (GTK_WIDGET (tree_view),
7887 GTK_DIR_UP : GTK_DIR_DOWN))
7889 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
7892 gtk_widget_child_focus (toplevel,
7894 GTK_DIR_TAB_BACKWARD :
7895 GTK_DIR_TAB_FORWARD);
7902 gtk_widget_error_bell (GTK_WIDGET (tree_view));
7907 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7911 pspp_sheet_view_move_cursor_page_up_down (PsppSheetView *tree_view,
7914 int cursor_node = -1;
7915 GtkTreePath *old_cursor_path = NULL;
7916 GtkTreePath *cursor_path = NULL;
7917 int start_cursor_node = -1;
7920 gint vertical_separator;
7922 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7925 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
7926 old_cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7928 /* This is sorta weird. Focus in should give us a cursor */
7931 gtk_widget_style_get (GTK_WIDGET (tree_view), "vertical-separator", &vertical_separator, NULL);
7932 _pspp_sheet_view_find_node (tree_view, old_cursor_path, &cursor_node);
7934 if (cursor_node < 0)
7936 /* FIXME: we lost the cursor. Should we try to get one? */
7937 gtk_tree_path_free (old_cursor_path);
7941 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
7942 window_y = RBTREE_Y_TO_TREE_WINDOW_Y (tree_view, y);
7943 y += tree_view->priv->cursor_offset;
7944 y += count * (int)tree_view->priv->vadjustment->page_increment;
7945 y = CLAMP (y, (gint)tree_view->priv->vadjustment->lower, (gint)tree_view->priv->vadjustment->upper - vertical_separator);
7947 if (y >= tree_view->priv->height)
7948 y = tree_view->priv->height - 1;
7950 tree_view->priv->cursor_offset =
7951 pspp_sheet_view_find_offset (tree_view, y, &cursor_node);
7953 if (tree_view->priv->cursor_offset > BACKGROUND_HEIGHT (tree_view))
7955 cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7956 tree_view->priv->cursor_offset -= BACKGROUND_HEIGHT (tree_view);
7959 y -= tree_view->priv->cursor_offset;
7960 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
7962 start_cursor_node = cursor_node;
7964 if (! search_first_focusable_path (tree_view, &cursor_path,
7968 /* It looks like we reached the end of the view without finding
7969 * a focusable row. We will step backwards to find the last
7972 cursor_node = start_cursor_node;
7973 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
7975 search_first_focusable_path (tree_view, &cursor_path,
7984 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
7986 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE);
7989 pspp_sheet_view_scroll_to_point (tree_view, -1, y);
7990 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
7991 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
7993 if (!gtk_tree_path_compare (old_cursor_path, cursor_path))
7994 gtk_widget_error_bell (GTK_WIDGET (tree_view));
7996 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7999 gtk_tree_path_free (old_cursor_path);
8000 gtk_tree_path_free (cursor_path);
8004 pspp_sheet_view_move_cursor_left_right (PsppSheetView *tree_view,
8007 int cursor_node = -1;
8008 GtkTreePath *cursor_path = NULL;
8009 PsppSheetViewColumn *column;
8012 gboolean found_column = FALSE;
8015 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8017 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8020 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8021 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8025 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8026 if (cursor_node < 0)
8028 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8030 gtk_tree_path_free (cursor_path);
8033 gtk_tree_path_free (cursor_path);
8035 list = rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns);
8036 if (tree_view->priv->focus_column)
8038 for (; list; list = (rtl ? list->prev : list->next))
8040 if (list->data == tree_view->priv->focus_column)
8047 gboolean left, right;
8049 column = list->data;
8050 if (column->visible == FALSE || column->row_head)
8053 pspp_sheet_view_column_cell_set_cell_data (column,
8054 tree_view->priv->model,
8059 right = list->prev ? TRUE : FALSE;
8060 left = list->next ? TRUE : FALSE;
8064 left = list->prev ? TRUE : FALSE;
8065 right = list->next ? TRUE : FALSE;
8068 if (_pspp_sheet_view_column_cell_focus (column, count, left, right))
8070 tree_view->priv->focus_column = column;
8071 found_column = TRUE;
8076 list = rtl ? list->prev : list->next;
8078 list = rtl ? list->next : list->prev;
8083 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8084 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8085 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8089 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8092 pspp_sheet_view_clamp_column_visible (tree_view,
8093 tree_view->priv->focus_column, TRUE);
8097 pspp_sheet_view_move_cursor_start_end (PsppSheetView *tree_view,
8102 GtkTreePath *old_path;
8104 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8107 g_return_if_fail (tree_view->priv->row_count > 0);
8109 pspp_sheet_view_get_cursor (tree_view, &old_path, NULL);
8113 /* Now go forward to find the first focusable row. */
8114 path = _pspp_sheet_view_find_path (tree_view, 0);
8115 search_first_focusable_path (tree_view, &path,
8116 TRUE, &cursor_node);
8120 /* Now go backwards to find last focusable row. */
8121 path = _pspp_sheet_view_find_path (tree_view, tree_view->priv->row_count - 1);
8122 search_first_focusable_path (tree_view, &path,
8123 FALSE, &cursor_node);
8129 if (gtk_tree_path_compare (old_path, path))
8131 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE);
8132 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8136 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8140 gtk_tree_path_free (old_path);
8141 gtk_tree_path_free (path);
8145 pspp_sheet_view_real_select_all (PsppSheetView *tree_view)
8147 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8150 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8151 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8154 pspp_sheet_selection_select_all (tree_view->priv->selection);
8160 pspp_sheet_view_real_unselect_all (PsppSheetView *tree_view)
8162 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8165 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8166 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8169 pspp_sheet_selection_unselect_all (tree_view->priv->selection);
8175 pspp_sheet_view_real_select_cursor_row (PsppSheetView *tree_view,
8176 gboolean start_editing)
8179 int cursor_node = -1;
8180 GtkTreePath *cursor_path = NULL;
8181 GtkTreeSelectMode mode = 0;
8183 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8186 if (tree_view->priv->cursor)
8187 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8189 if (cursor_path == NULL)
8192 _pspp_sheet_view_find_node (tree_view, cursor_path,
8195 if (cursor_node < 0)
8197 gtk_tree_path_free (cursor_path);
8201 if (!tree_view->priv->shift_pressed && start_editing &&
8202 tree_view->priv->focus_column)
8204 if (pspp_sheet_view_start_editing (tree_view, cursor_path))
8206 gtk_tree_path_free (cursor_path);
8211 if (tree_view->priv->ctrl_pressed)
8212 mode |= GTK_TREE_SELECT_MODE_TOGGLE;
8213 if (tree_view->priv->shift_pressed)
8214 mode |= GTK_TREE_SELECT_MODE_EXTEND;
8216 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8222 /* We bail out if the original (tree, node) don't exist anymore after
8223 * handling the selection-changed callback. We do return TRUE because
8224 * the key press has been handled at this point.
8226 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8228 if (cursor_node != new_node)
8231 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8233 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8234 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8236 if (!tree_view->priv->shift_pressed)
8237 pspp_sheet_view_row_activated (tree_view, cursor_path,
8238 tree_view->priv->focus_column);
8240 gtk_tree_path_free (cursor_path);
8246 pspp_sheet_view_real_toggle_cursor_row (PsppSheetView *tree_view)
8249 int cursor_node = -1;
8250 GtkTreePath *cursor_path = NULL;
8252 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8256 if (tree_view->priv->cursor)
8257 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8259 if (cursor_path == NULL)
8262 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8263 if (cursor_node < 0)
8265 gtk_tree_path_free (cursor_path);
8269 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8272 GTK_TREE_SELECT_MODE_TOGGLE,
8275 /* We bail out if the original (tree, node) don't exist anymore after
8276 * handling the selection-changed callback. We do return TRUE because
8277 * the key press has been handled at this point.
8279 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8281 if (cursor_node != new_node)
8284 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8286 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8287 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
8288 gtk_tree_path_free (cursor_path);
8294 pspp_sheet_view_search_entry_flush_timeout (PsppSheetView *tree_view)
8296 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
8297 tree_view->priv->typeselect_flush_timeout = 0;
8302 /* Cut and paste from gtkwindow.c */
8304 send_focus_change (GtkWidget *widget,
8307 GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
8309 g_object_ref (widget);
8312 GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS);
8314 GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS);
8316 fevent->focus_change.type = GDK_FOCUS_CHANGE;
8317 fevent->focus_change.window = g_object_ref (widget->window);
8318 fevent->focus_change.in = in;
8320 gtk_widget_event (widget, fevent);
8322 g_object_notify (G_OBJECT (widget), "has-focus");
8324 g_object_unref (widget);
8325 gdk_event_free (fevent);
8329 pspp_sheet_view_ensure_interactive_directory (PsppSheetView *tree_view)
8331 GtkWidget *frame, *vbox, *toplevel;
8334 if (tree_view->priv->search_custom_entry_set)
8337 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
8338 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
8340 if (tree_view->priv->search_window != NULL)
8342 if (GTK_WINDOW (toplevel)->group)
8343 gtk_window_group_add_window (GTK_WINDOW (toplevel)->group,
8344 GTK_WINDOW (tree_view->priv->search_window));
8345 else if (GTK_WINDOW (tree_view->priv->search_window)->group)
8346 gtk_window_group_remove_window (GTK_WINDOW (tree_view->priv->search_window)->group,
8347 GTK_WINDOW (tree_view->priv->search_window));
8348 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8352 tree_view->priv->search_window = gtk_window_new (GTK_WINDOW_POPUP);
8353 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8355 if (GTK_WINDOW (toplevel)->group)
8356 gtk_window_group_add_window (GTK_WINDOW (toplevel)->group,
8357 GTK_WINDOW (tree_view->priv->search_window));
8359 gtk_window_set_type_hint (GTK_WINDOW (tree_view->priv->search_window),
8360 GDK_WINDOW_TYPE_HINT_UTILITY);
8361 gtk_window_set_modal (GTK_WINDOW (tree_view->priv->search_window), TRUE);
8362 g_signal_connect (tree_view->priv->search_window, "delete-event",
8363 G_CALLBACK (pspp_sheet_view_search_delete_event),
8365 g_signal_connect (tree_view->priv->search_window, "key-press-event",
8366 G_CALLBACK (pspp_sheet_view_search_key_press_event),
8368 g_signal_connect (tree_view->priv->search_window, "button-press-event",
8369 G_CALLBACK (pspp_sheet_view_search_button_press_event),
8371 g_signal_connect (tree_view->priv->search_window, "scroll-event",
8372 G_CALLBACK (pspp_sheet_view_search_scroll_event),
8375 frame = gtk_frame_new (NULL);
8376 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
8377 gtk_widget_show (frame);
8378 gtk_container_add (GTK_CONTAINER (tree_view->priv->search_window), frame);
8380 vbox = gtk_vbox_new (FALSE, 0);
8381 gtk_widget_show (vbox);
8382 gtk_container_add (GTK_CONTAINER (frame), vbox);
8383 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
8386 tree_view->priv->search_entry = gtk_entry_new ();
8387 gtk_widget_show (tree_view->priv->search_entry);
8388 g_signal_connect (tree_view->priv->search_entry, "populate-popup",
8389 G_CALLBACK (pspp_sheet_view_search_disable_popdown),
8391 g_signal_connect (tree_view->priv->search_entry,
8392 "activate", G_CALLBACK (pspp_sheet_view_search_activate),
8394 g_signal_connect (GTK_ENTRY (tree_view->priv->search_entry)->im_context,
8396 G_CALLBACK (pspp_sheet_view_search_preedit_changed),
8398 gtk_container_add (GTK_CONTAINER (vbox),
8399 tree_view->priv->search_entry);
8401 gtk_widget_realize (tree_view->priv->search_entry);
8404 /* Pops up the interactive search entry. If keybinding is TRUE then the user
8405 * started this by typing the start_interactive_search keybinding. Otherwise, it came from
8408 pspp_sheet_view_real_start_interactive_search (PsppSheetView *tree_view,
8409 gboolean keybinding)
8411 /* We only start interactive search if we have focus or the columns
8412 * have focus. If one of our children have focus, we don't want to
8416 gboolean found_focus = FALSE;
8417 GtkWidgetClass *entry_parent_class;
8419 if (!tree_view->priv->enable_search && !keybinding)
8422 if (tree_view->priv->search_custom_entry_set)
8425 if (tree_view->priv->search_window != NULL &&
8426 gtk_widget_get_visible (tree_view->priv->search_window))
8429 for (list = tree_view->priv->columns; list; list = list->next)
8431 PsppSheetViewColumn *column;
8433 column = list->data;
8434 if (! column->visible)
8437 if (column->button && gtk_widget_has_focus (column->button))
8444 if (gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8450 if (tree_view->priv->search_column < 0)
8453 pspp_sheet_view_ensure_interactive_directory (tree_view);
8456 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
8459 tree_view->priv->search_position_func (tree_view, tree_view->priv->search_window, tree_view->priv->search_position_user_data);
8460 gtk_widget_show (tree_view->priv->search_window);
8461 if (tree_view->priv->search_entry_changed_id == 0)
8463 tree_view->priv->search_entry_changed_id =
8464 g_signal_connect (tree_view->priv->search_entry, "changed",
8465 G_CALLBACK (pspp_sheet_view_search_init),
8469 tree_view->priv->typeselect_flush_timeout =
8470 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
8471 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
8474 /* Grab focus will select all the text. We don't want that to happen, so we
8475 * call the parent instance and bypass the selection change. This is probably
8476 * really non-kosher. */
8477 entry_parent_class = g_type_class_peek_parent (GTK_ENTRY_GET_CLASS (tree_view->priv->search_entry));
8478 (entry_parent_class->grab_focus) (tree_view->priv->search_entry);
8480 /* send focus-in event */
8481 send_focus_change (tree_view->priv->search_entry, TRUE);
8483 /* search first matching iter */
8484 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
8490 pspp_sheet_view_start_interactive_search (PsppSheetView *tree_view)
8492 return pspp_sheet_view_real_start_interactive_search (tree_view, TRUE);
8495 /* this function returns the new width of the column being resized given
8496 * the column and x position of the cursor; the x cursor position is passed
8497 * in as a pointer and automagicly corrected if it's beyond min/max limits
8500 pspp_sheet_view_new_column_width (PsppSheetView *tree_view,
8504 PsppSheetViewColumn *column;
8508 /* first translate the x position from widget->window
8509 * to clist->clist_window
8511 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8512 column = g_list_nth (tree_view->priv->columns, i)->data;
8513 width = rtl ? (column->allocation.x + column->allocation.width - *x) : (*x - column->allocation.x);
8515 /* Clamp down the value */
8516 if (column->min_width == -1)
8517 width = MAX (column->button_request, width);
8519 width = MAX (column->min_width, width);
8520 if (column->max_width != -1)
8521 width = MIN (width, column->max_width);
8523 *x = rtl ? (column->allocation.x + column->allocation.width - width) : (column->allocation.x + width);
8529 /* FIXME this adjust_allocation is a big cut-and-paste from
8530 * GtkCList, needs to be some "official" way to do this
8540 /* The window to which widget->window is relative */
8541 #define ALLOCATION_WINDOW(widget) \
8542 (!gtk_widget_get_has_window (widget) ? \
8543 (widget)->window : \
8544 gdk_window_get_parent ((widget)->window))
8547 adjust_allocation_recurse (GtkWidget *widget,
8550 ScrollData *scroll_data = data;
8552 /* Need to really size allocate instead of just poking
8553 * into widget->allocation if the widget is not realized.
8554 * FIXME someone figure out why this was.
8556 if (!gtk_widget_get_realized (widget))
8558 if (gtk_widget_get_visible (widget))
8560 GdkRectangle tmp_rectangle = widget->allocation;
8561 tmp_rectangle.x += scroll_data->dx;
8562 tmp_rectangle.y += scroll_data->dy;
8564 gtk_widget_size_allocate (widget, &tmp_rectangle);
8569 if (ALLOCATION_WINDOW (widget) == scroll_data->window)
8571 widget->allocation.x += scroll_data->dx;
8572 widget->allocation.y += scroll_data->dy;
8574 if (GTK_IS_CONTAINER (widget))
8575 gtk_container_forall (GTK_CONTAINER (widget),
8576 adjust_allocation_recurse,
8583 adjust_allocation (GtkWidget *widget,
8587 ScrollData scroll_data;
8589 if (gtk_widget_get_realized (widget))
8590 scroll_data.window = ALLOCATION_WINDOW (widget);
8592 scroll_data.window = NULL;
8594 scroll_data.dx = dx;
8595 scroll_data.dy = dy;
8597 adjust_allocation_recurse (widget, &scroll_data);
8601 pspp_sheet_view_column_update_button (PsppSheetViewColumn *tree_column);
8605 pspp_sheet_view_adjustment_changed (GtkAdjustment *adjustment,
8606 PsppSheetView *tree_view)
8608 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
8613 gdk_window_move (tree_view->priv->bin_window,
8614 - tree_view->priv->hadjustment->value,
8615 TREE_VIEW_HEADER_HEIGHT (tree_view));
8616 gdk_window_move (tree_view->priv->header_window,
8617 - tree_view->priv->hadjustment->value,
8619 dy = tree_view->priv->dy - (int) tree_view->priv->vadjustment->value;
8622 update_prelight (tree_view,
8623 tree_view->priv->event_last_x,
8624 tree_view->priv->event_last_y - dy);
8626 if (tree_view->priv->edited_column &&
8627 GTK_IS_WIDGET (tree_view->priv->edited_column->editable_widget))
8631 PsppSheetViewChild *child = NULL;
8633 widget = GTK_WIDGET (tree_view->priv->edited_column->editable_widget);
8634 adjust_allocation (widget, 0, dy);
8636 for (list = tree_view->priv->children; list; list = list->next)
8638 child = (PsppSheetViewChild *)list->data;
8639 if (child->widget == widget)
8647 gdk_window_scroll (tree_view->priv->bin_window, 0, dy);
8649 if (tree_view->priv->dy != (int) tree_view->priv->vadjustment->value)
8651 /* update our dy and top_row */
8652 tree_view->priv->dy = (int) tree_view->priv->vadjustment->value;
8654 if (!tree_view->priv->in_top_row_to_dy)
8655 pspp_sheet_view_dy_to_top_row (tree_view);
8658 for (list = tree_view->priv->columns; list; list = list->next)
8660 PsppSheetViewColumn *column = list->data;
8661 GtkAllocation *allocation = &column->allocation;
8663 if (span_intersects (allocation->x, allocation->width,
8664 tree_view->priv->hadjustment->value,
8665 GTK_WIDGET (tree_view)->allocation.width))
8667 pspp_sheet_view_column_set_need_button (column, TRUE);
8668 if (!column->button)
8669 pspp_sheet_view_column_update_button (column);
8681 * pspp_sheet_view_new:
8683 * Creates a new #PsppSheetView widget.
8685 * Return value: A newly created #PsppSheetView widget.
8688 pspp_sheet_view_new (void)
8690 return g_object_new (PSPP_TYPE_SHEET_VIEW, NULL);
8694 * pspp_sheet_view_new_with_model:
8695 * @model: the model.
8697 * Creates a new #PsppSheetView widget with the model initialized to @model.
8699 * Return value: A newly created #PsppSheetView widget.
8702 pspp_sheet_view_new_with_model (GtkTreeModel *model)
8704 return g_object_new (PSPP_TYPE_SHEET_VIEW, "model", model, NULL);
8711 * pspp_sheet_view_get_model:
8712 * @tree_view: a #PsppSheetView
8714 * Returns the model the #PsppSheetView is based on. Returns %NULL if the
8717 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
8720 pspp_sheet_view_get_model (PsppSheetView *tree_view)
8722 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
8724 return tree_view->priv->model;
8728 * pspp_sheet_view_set_model:
8729 * @tree_view: A #GtkTreeNode.
8730 * @model: (allow-none): The model.
8732 * Sets the model for a #PsppSheetView. If the @tree_view already has a model
8733 * set, it will remove it before setting the new model. If @model is %NULL,
8734 * then it will unset the old model.
8737 pspp_sheet_view_set_model (PsppSheetView *tree_view,
8738 GtkTreeModel *model)
8740 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8741 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
8743 if (model == tree_view->priv->model)
8746 if (tree_view->priv->scroll_to_path)
8748 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
8749 tree_view->priv->scroll_to_path = NULL;
8752 if (tree_view->priv->model)
8754 GList *tmplist = tree_view->priv->columns;
8756 if (tree_view->priv->selected)
8757 range_tower_set0 (tree_view->priv->selected, 0, ULONG_MAX);
8758 pspp_sheet_view_stop_editing (tree_view, TRUE);
8760 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
8761 pspp_sheet_view_row_changed,
8763 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
8764 pspp_sheet_view_row_inserted,
8766 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
8767 pspp_sheet_view_row_deleted,
8769 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
8770 pspp_sheet_view_rows_reordered,
8773 for (; tmplist; tmplist = tmplist->next)
8774 _pspp_sheet_view_column_unset_model (tmplist->data,
8775 tree_view->priv->model);
8777 tree_view->priv->prelight_node = -1;
8779 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
8780 tree_view->priv->drag_dest_row = NULL;
8781 gtk_tree_row_reference_free (tree_view->priv->cursor);
8782 tree_view->priv->cursor = NULL;
8783 gtk_tree_row_reference_free (tree_view->priv->anchor);
8784 tree_view->priv->anchor = NULL;
8785 gtk_tree_row_reference_free (tree_view->priv->top_row);
8786 tree_view->priv->top_row = NULL;
8787 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
8788 tree_view->priv->scroll_to_path = NULL;
8790 tree_view->priv->scroll_to_column = NULL;
8792 g_object_unref (tree_view->priv->model);
8794 tree_view->priv->search_column = -1;
8795 tree_view->priv->fixed_height = -1;
8796 tree_view->priv->dy = tree_view->priv->top_row_dy = 0;
8797 tree_view->priv->last_button_x = -1;
8798 tree_view->priv->last_button_y = -1;
8801 tree_view->priv->model = model;
8803 if (tree_view->priv->model)
8807 if (tree_view->priv->search_column == -1)
8809 for (i = 0; i < gtk_tree_model_get_n_columns (model); i++)
8811 GType type = gtk_tree_model_get_column_type (model, i);
8813 if (g_value_type_transformable (type, G_TYPE_STRING))
8815 tree_view->priv->search_column = i;
8821 g_object_ref (tree_view->priv->model);
8822 g_signal_connect (tree_view->priv->model,
8824 G_CALLBACK (pspp_sheet_view_row_changed),
8826 g_signal_connect (tree_view->priv->model,
8828 G_CALLBACK (pspp_sheet_view_row_inserted),
8830 g_signal_connect (tree_view->priv->model,
8832 G_CALLBACK (pspp_sheet_view_row_deleted),
8834 g_signal_connect (tree_view->priv->model,
8836 G_CALLBACK (pspp_sheet_view_rows_reordered),
8839 tree_view->priv->row_count = gtk_tree_model_iter_n_children (tree_view->priv->model, NULL);
8841 /* FIXME: do I need to do this? pspp_sheet_view_create_buttons (tree_view); */
8842 install_presize_handler (tree_view);
8845 g_object_notify (G_OBJECT (tree_view), "model");
8847 if (tree_view->priv->selection)
8848 _pspp_sheet_selection_emit_changed (tree_view->priv->selection);
8850 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
8851 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
8855 * pspp_sheet_view_get_selection:
8856 * @tree_view: A #PsppSheetView.
8858 * Gets the #PsppSheetSelection associated with @tree_view.
8860 * Return value: A #PsppSheetSelection object.
8862 PsppSheetSelection *
8863 pspp_sheet_view_get_selection (PsppSheetView *tree_view)
8865 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
8867 return tree_view->priv->selection;
8871 * pspp_sheet_view_get_hadjustment:
8872 * @tree_view: A #PsppSheetView
8874 * Gets the #GtkAdjustment currently being used for the horizontal aspect.
8876 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
8880 pspp_sheet_view_get_hadjustment (PsppSheetView *tree_view)
8882 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
8884 if (tree_view->priv->hadjustment == NULL)
8885 pspp_sheet_view_set_hadjustment (tree_view, NULL);
8887 return tree_view->priv->hadjustment;
8891 * pspp_sheet_view_set_hadjustment:
8892 * @tree_view: A #PsppSheetView
8893 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
8895 * Sets the #GtkAdjustment for the current horizontal aspect.
8898 pspp_sheet_view_set_hadjustment (PsppSheetView *tree_view,
8899 GtkAdjustment *adjustment)
8901 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8903 pspp_sheet_view_set_adjustments (tree_view,
8905 tree_view->priv->vadjustment);
8907 g_object_notify (G_OBJECT (tree_view), "hadjustment");
8911 * pspp_sheet_view_get_vadjustment:
8912 * @tree_view: A #PsppSheetView
8914 * Gets the #GtkAdjustment currently being used for the vertical aspect.
8916 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
8920 pspp_sheet_view_get_vadjustment (PsppSheetView *tree_view)
8922 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
8924 if (tree_view->priv->vadjustment == NULL)
8925 pspp_sheet_view_set_vadjustment (tree_view, NULL);
8927 return tree_view->priv->vadjustment;
8931 * pspp_sheet_view_set_vadjustment:
8932 * @tree_view: A #PsppSheetView
8933 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
8935 * Sets the #GtkAdjustment for the current vertical aspect.
8938 pspp_sheet_view_set_vadjustment (PsppSheetView *tree_view,
8939 GtkAdjustment *adjustment)
8941 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8943 pspp_sheet_view_set_adjustments (tree_view,
8944 tree_view->priv->hadjustment,
8947 g_object_notify (G_OBJECT (tree_view), "vadjustment");
8950 /* Column and header operations */
8953 * pspp_sheet_view_get_headers_visible:
8954 * @tree_view: A #PsppSheetView.
8956 * Returns %TRUE if the headers on the @tree_view are visible.
8958 * Return value: Whether the headers are visible or not.
8961 pspp_sheet_view_get_headers_visible (PsppSheetView *tree_view)
8963 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
8965 return PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
8969 * pspp_sheet_view_set_headers_visible:
8970 * @tree_view: A #PsppSheetView.
8971 * @headers_visible: %TRUE if the headers are visible
8973 * Sets the visibility state of the headers.
8976 pspp_sheet_view_set_headers_visible (PsppSheetView *tree_view,
8977 gboolean headers_visible)
8981 PsppSheetViewColumn *column;
8983 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8985 headers_visible = !! headers_visible;
8987 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE) == headers_visible)
8990 if (headers_visible)
8991 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
8993 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
8995 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
8997 gdk_window_get_position (tree_view->priv->bin_window, &x, &y);
8998 if (headers_visible)
9000 gdk_window_move_resize (tree_view->priv->bin_window, x, y + TREE_VIEW_HEADER_HEIGHT (tree_view), tree_view->priv->width, GTK_WIDGET (tree_view)->allocation.height - + TREE_VIEW_HEADER_HEIGHT (tree_view));
9002 if (gtk_widget_get_mapped (GTK_WIDGET (tree_view)))
9003 pspp_sheet_view_map_buttons (tree_view);
9007 gdk_window_move_resize (tree_view->priv->bin_window, x, y, tree_view->priv->width, tree_view->priv->height);
9009 for (list = tree_view->priv->columns; list; list = list->next)
9011 column = list->data;
9013 gtk_widget_unmap (column->button);
9015 gdk_window_hide (tree_view->priv->header_window);
9019 tree_view->priv->vadjustment->page_size = GTK_WIDGET (tree_view)->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
9020 tree_view->priv->vadjustment->page_increment = (GTK_WIDGET (tree_view)->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view)) / 2;
9021 tree_view->priv->vadjustment->lower = 0;
9022 tree_view->priv->vadjustment->upper = tree_view->priv->height;
9023 gtk_adjustment_changed (tree_view->priv->vadjustment);
9025 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9027 g_object_notify (G_OBJECT (tree_view), "headers-visible");
9031 * pspp_sheet_view_columns_autosize:
9032 * @tree_view: A #PsppSheetView.
9034 * Resizes all columns to their optimal width. Only works after the
9035 * treeview has been realized.
9038 pspp_sheet_view_columns_autosize (PsppSheetView *tree_view)
9040 gboolean dirty = FALSE;
9042 PsppSheetViewColumn *column;
9044 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9046 for (list = tree_view->priv->columns; list; list = list->next)
9048 column = list->data;
9049 _pspp_sheet_view_column_cell_set_dirty (column);
9054 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9058 * pspp_sheet_view_set_headers_clickable:
9059 * @tree_view: A #PsppSheetView.
9060 * @setting: %TRUE if the columns are clickable.
9062 * Allow the column title buttons to be clicked.
9065 pspp_sheet_view_set_headers_clickable (PsppSheetView *tree_view,
9070 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9072 for (list = tree_view->priv->columns; list; list = list->next)
9073 pspp_sheet_view_column_set_clickable (PSPP_SHEET_VIEW_COLUMN (list->data), setting);
9075 g_object_notify (G_OBJECT (tree_view), "headers-clickable");
9080 * pspp_sheet_view_get_headers_clickable:
9081 * @tree_view: A #PsppSheetView.
9083 * Returns whether all header columns are clickable.
9085 * Return value: %TRUE if all header columns are clickable, otherwise %FALSE
9090 pspp_sheet_view_get_headers_clickable (PsppSheetView *tree_view)
9094 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9096 for (list = tree_view->priv->columns; list; list = list->next)
9097 if (!PSPP_SHEET_VIEW_COLUMN (list->data)->clickable)
9104 * pspp_sheet_view_set_rules_hint
9105 * @tree_view: a #PsppSheetView
9106 * @setting: %TRUE if the tree requires reading across rows
9108 * This function tells GTK+ that the user interface for your
9109 * application requires users to read across tree rows and associate
9110 * cells with one another. By default, GTK+ will then render the tree
9111 * with alternating row colors. Do <emphasis>not</emphasis> use it
9112 * just because you prefer the appearance of the ruled tree; that's a
9113 * question for the theme. Some themes will draw tree rows in
9114 * alternating colors even when rules are turned off, and users who
9115 * prefer that appearance all the time can choose those themes. You
9116 * should call this function only as a <emphasis>semantic</emphasis>
9117 * hint to the theme engine that your tree makes alternating colors
9118 * useful from a functional standpoint (since it has lots of columns,
9123 pspp_sheet_view_set_rules_hint (PsppSheetView *tree_view,
9126 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9128 setting = setting != FALSE;
9130 if (tree_view->priv->has_rules != setting)
9132 tree_view->priv->has_rules = setting;
9133 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
9136 g_object_notify (G_OBJECT (tree_view), "rules-hint");
9140 * pspp_sheet_view_get_rules_hint
9141 * @tree_view: a #PsppSheetView
9143 * Gets the setting set by pspp_sheet_view_set_rules_hint().
9145 * Return value: %TRUE if rules are useful for the user of this tree
9148 pspp_sheet_view_get_rules_hint (PsppSheetView *tree_view)
9150 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9152 return tree_view->priv->has_rules;
9155 /* Public Column functions
9159 * pspp_sheet_view_append_column:
9160 * @tree_view: A #PsppSheetView.
9161 * @column: The #PsppSheetViewColumn to add.
9163 * Appends @column to the list of columns.
9165 * Return value: The number of columns in @tree_view after appending.
9168 pspp_sheet_view_append_column (PsppSheetView *tree_view,
9169 PsppSheetViewColumn *column)
9171 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9172 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9173 g_return_val_if_fail (column->tree_view == NULL, -1);
9175 return pspp_sheet_view_insert_column (tree_view, column, -1);
9180 * pspp_sheet_view_remove_column:
9181 * @tree_view: A #PsppSheetView.
9182 * @column: The #PsppSheetViewColumn to remove.
9184 * Removes @column from @tree_view.
9186 * Return value: The number of columns in @tree_view after removing.
9189 pspp_sheet_view_remove_column (PsppSheetView *tree_view,
9190 PsppSheetViewColumn *column)
9192 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9193 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9194 g_return_val_if_fail (column->tree_view == GTK_WIDGET (tree_view), -1);
9196 if (tree_view->priv->focus_column == column)
9197 tree_view->priv->focus_column = NULL;
9199 if (tree_view->priv->edited_column == column)
9201 pspp_sheet_view_stop_editing (tree_view, TRUE);
9203 /* no need to, but just to be sure ... */
9204 tree_view->priv->edited_column = NULL;
9207 _pspp_sheet_view_column_unset_tree_view (column);
9209 tree_view->priv->columns = g_list_remove (tree_view->priv->columns, column);
9210 tree_view->priv->n_columns--;
9212 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9216 _pspp_sheet_view_column_unrealize_button (column);
9217 for (list = tree_view->priv->columns; list; list = list->next)
9219 PsppSheetViewColumn *tmp_column;
9221 tmp_column = PSPP_SHEET_VIEW_COLUMN (list->data);
9222 if (tmp_column->visible)
9223 _pspp_sheet_view_column_cell_set_dirty (tmp_column);
9226 if (tree_view->priv->n_columns == 0 &&
9227 pspp_sheet_view_get_headers_visible (tree_view) &&
9228 tree_view->priv->header_window)
9229 gdk_window_hide (tree_view->priv->header_window);
9231 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9234 g_object_unref (column);
9235 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9237 return tree_view->priv->n_columns;
9241 * pspp_sheet_view_insert_column:
9242 * @tree_view: A #PsppSheetView.
9243 * @column: The #PsppSheetViewColumn to be inserted.
9244 * @position: The position to insert @column in.
9246 * This inserts the @column into the @tree_view at @position. If @position is
9247 * -1, then the column is inserted at the end.
9249 * Return value: The number of columns in @tree_view after insertion.
9252 pspp_sheet_view_insert_column (PsppSheetView *tree_view,
9253 PsppSheetViewColumn *column,
9256 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9257 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9258 g_return_val_if_fail (column->tree_view == NULL, -1);
9260 g_object_ref_sink (column);
9262 if (tree_view->priv->n_columns == 0 &&
9263 gtk_widget_get_realized (GTK_WIDGET (tree_view)) &&
9264 pspp_sheet_view_get_headers_visible (tree_view))
9266 gdk_window_show (tree_view->priv->header_window);
9269 tree_view->priv->columns = g_list_insert (tree_view->priv->columns,
9271 tree_view->priv->n_columns++;
9273 _pspp_sheet_view_column_set_tree_view (column, tree_view);
9275 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9279 _pspp_sheet_view_column_realize_button (column);
9281 for (list = tree_view->priv->columns; list; list = list->next)
9283 column = PSPP_SHEET_VIEW_COLUMN (list->data);
9284 if (column->visible)
9285 _pspp_sheet_view_column_cell_set_dirty (column);
9287 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9290 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9292 return tree_view->priv->n_columns;
9296 * pspp_sheet_view_insert_column_with_attributes:
9297 * @tree_view: A #PsppSheetView
9298 * @position: The position to insert the new column in.
9299 * @title: The title to set the header to.
9300 * @cell: The #GtkCellRenderer.
9301 * @Varargs: A %NULL-terminated list of attributes.
9303 * Creates a new #PsppSheetViewColumn and inserts it into the @tree_view at
9304 * @position. If @position is -1, then the newly created column is inserted at
9305 * the end. The column is initialized with the attributes given.
9307 * Return value: The number of columns in @tree_view after insertion.
9310 pspp_sheet_view_insert_column_with_attributes (PsppSheetView *tree_view,
9313 GtkCellRenderer *cell,
9316 PsppSheetViewColumn *column;
9321 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9323 column = pspp_sheet_view_column_new ();
9324 pspp_sheet_view_column_set_title (column, title);
9325 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9327 va_start (args, cell);
9329 attribute = va_arg (args, gchar *);
9331 while (attribute != NULL)
9333 column_id = va_arg (args, gint);
9334 pspp_sheet_view_column_add_attribute (column, cell, attribute, column_id);
9335 attribute = va_arg (args, gchar *);
9340 pspp_sheet_view_insert_column (tree_view, column, position);
9342 return tree_view->priv->n_columns;
9346 * pspp_sheet_view_insert_column_with_data_func:
9347 * @tree_view: a #PsppSheetView
9348 * @position: Position to insert, -1 for append
9349 * @title: column title
9350 * @cell: cell renderer for column
9351 * @func: function to set attributes of cell renderer
9352 * @data: data for @func
9353 * @dnotify: destroy notifier for @data
9355 * Convenience function that inserts a new column into the #PsppSheetView
9356 * with the given cell renderer and a #GtkCellDataFunc to set cell renderer
9357 * attributes (normally using data from the model). See also
9358 * pspp_sheet_view_column_set_cell_data_func(), pspp_sheet_view_column_pack_start().
9360 * Return value: number of columns in the tree view post-insert
9363 pspp_sheet_view_insert_column_with_data_func (PsppSheetView *tree_view,
9366 GtkCellRenderer *cell,
9367 PsppSheetCellDataFunc func,
9369 GDestroyNotify dnotify)
9371 PsppSheetViewColumn *column;
9373 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9375 column = pspp_sheet_view_column_new ();
9376 pspp_sheet_view_column_set_title (column, title);
9377 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9378 pspp_sheet_view_column_set_cell_data_func (column, cell, func, data, dnotify);
9380 pspp_sheet_view_insert_column (tree_view, column, position);
9382 return tree_view->priv->n_columns;
9386 * pspp_sheet_view_get_column:
9387 * @tree_view: A #PsppSheetView.
9388 * @n: The position of the column, counting from 0.
9390 * Gets the #PsppSheetViewColumn at the given position in the #tree_view.
9392 * Return value: The #PsppSheetViewColumn, or %NULL if the position is outside the
9395 PsppSheetViewColumn *
9396 pspp_sheet_view_get_column (PsppSheetView *tree_view,
9399 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9401 if (n < 0 || n >= tree_view->priv->n_columns)
9404 if (tree_view->priv->columns == NULL)
9407 return PSPP_SHEET_VIEW_COLUMN (g_list_nth (tree_view->priv->columns, n)->data);
9411 * pspp_sheet_view_get_columns:
9412 * @tree_view: A #PsppSheetView
9414 * Returns a #GList of all the #PsppSheetViewColumn s currently in @tree_view.
9415 * The returned list must be freed with g_list_free ().
9417 * Return value: (element-type PsppSheetViewColumn) (transfer container): A list of #PsppSheetViewColumn s
9420 pspp_sheet_view_get_columns (PsppSheetView *tree_view)
9422 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9424 return g_list_copy (tree_view->priv->columns);
9428 * pspp_sheet_view_move_column_after:
9429 * @tree_view: A #PsppSheetView
9430 * @column: The #PsppSheetViewColumn to be moved.
9431 * @base_column: (allow-none): The #PsppSheetViewColumn to be moved relative to, or %NULL.
9433 * Moves @column to be after to @base_column. If @base_column is %NULL, then
9434 * @column is placed in the first position.
9437 pspp_sheet_view_move_column_after (PsppSheetView *tree_view,
9438 PsppSheetViewColumn *column,
9439 PsppSheetViewColumn *base_column)
9441 GList *column_list_el, *base_el = NULL;
9443 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9445 column_list_el = g_list_find (tree_view->priv->columns, column);
9446 g_return_if_fail (column_list_el != NULL);
9450 base_el = g_list_find (tree_view->priv->columns, base_column);
9451 g_return_if_fail (base_el != NULL);
9454 if (column_list_el->prev == base_el)
9457 tree_view->priv->columns = g_list_remove_link (tree_view->priv->columns, column_list_el);
9458 if (base_el == NULL)
9460 column_list_el->prev = NULL;
9461 column_list_el->next = tree_view->priv->columns;
9462 if (column_list_el->next)
9463 column_list_el->next->prev = column_list_el;
9464 tree_view->priv->columns = column_list_el;
9468 column_list_el->prev = base_el;
9469 column_list_el->next = base_el->next;
9470 if (column_list_el->next)
9471 column_list_el->next->prev = column_list_el;
9472 base_el->next = column_list_el;
9475 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9477 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9478 pspp_sheet_view_size_allocate_columns (GTK_WIDGET (tree_view), NULL);
9481 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9485 * pspp_sheet_view_set_column_drag_function:
9486 * @tree_view: A #PsppSheetView.
9487 * @func: (allow-none): A function to determine which columns are reorderable, or %NULL.
9488 * @user_data: (allow-none): User data to be passed to @func, or %NULL
9489 * @destroy: (allow-none): Destroy notifier for @user_data, or %NULL
9491 * Sets a user function for determining where a column may be dropped when
9492 * dragged. This function is called on every column pair in turn at the
9493 * beginning of a column drag to determine where a drop can take place. The
9494 * arguments passed to @func are: the @tree_view, the #PsppSheetViewColumn being
9495 * dragged, the two #PsppSheetViewColumn s determining the drop spot, and
9496 * @user_data. If either of the #PsppSheetViewColumn arguments for the drop spot
9497 * are %NULL, then they indicate an edge. If @func is set to be %NULL, then
9498 * @tree_view reverts to the default behavior of allowing all columns to be
9499 * dropped everywhere.
9502 pspp_sheet_view_set_column_drag_function (PsppSheetView *tree_view,
9503 PsppSheetViewColumnDropFunc func,
9505 GDestroyNotify destroy)
9507 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9509 if (tree_view->priv->column_drop_func_data_destroy)
9510 tree_view->priv->column_drop_func_data_destroy (tree_view->priv->column_drop_func_data);
9512 tree_view->priv->column_drop_func = func;
9513 tree_view->priv->column_drop_func_data = user_data;
9514 tree_view->priv->column_drop_func_data_destroy = destroy;
9518 * pspp_sheet_view_scroll_to_point:
9519 * @tree_view: a #PsppSheetView
9520 * @tree_x: X coordinate of new top-left pixel of visible area, or -1
9521 * @tree_y: Y coordinate of new top-left pixel of visible area, or -1
9523 * Scrolls the tree view such that the top-left corner of the visible
9524 * area is @tree_x, @tree_y, where @tree_x and @tree_y are specified
9525 * in tree coordinates. The @tree_view must be realized before
9526 * this function is called. If it isn't, you probably want to be
9527 * using pspp_sheet_view_scroll_to_cell().
9529 * If either @tree_x or @tree_y are -1, then that direction isn't scrolled.
9532 pspp_sheet_view_scroll_to_point (PsppSheetView *tree_view,
9536 GtkAdjustment *hadj;
9537 GtkAdjustment *vadj;
9539 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9540 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
9542 hadj = tree_view->priv->hadjustment;
9543 vadj = tree_view->priv->vadjustment;
9546 gtk_adjustment_set_value (hadj, CLAMP (tree_x, hadj->lower, hadj->upper - hadj->page_size));
9548 gtk_adjustment_set_value (vadj, CLAMP (tree_y, vadj->lower, vadj->upper - vadj->page_size));
9552 * pspp_sheet_view_scroll_to_cell:
9553 * @tree_view: A #PsppSheetView.
9554 * @path: (allow-none): The path of the row to move to, or %NULL.
9555 * @column: (allow-none): The #PsppSheetViewColumn to move horizontally to, or %NULL.
9556 * @use_align: whether to use alignment arguments, or %FALSE.
9557 * @row_align: The vertical alignment of the row specified by @path.
9558 * @col_align: The horizontal alignment of the column specified by @column.
9560 * Moves the alignments of @tree_view to the position specified by @column and
9561 * @path. If @column is %NULL, then no horizontal scrolling occurs. Likewise,
9562 * if @path is %NULL no vertical scrolling occurs. At a minimum, one of @column
9563 * or @path need to be non-%NULL. @row_align determines where the row is
9564 * placed, and @col_align determines where @column is placed. Both are expected
9565 * to be between 0.0 and 1.0. 0.0 means left/top alignment, 1.0 means
9566 * right/bottom alignment, 0.5 means center.
9568 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
9569 * tree does the minimum amount of work to scroll the cell onto the screen.
9570 * This means that the cell will be scrolled to the edge closest to its current
9571 * position. If the cell is currently visible on the screen, nothing is done.
9573 * This function only works if the model is set, and @path is a valid row on the
9574 * model. If the model changes before the @tree_view is realized, the centered
9575 * path will be modified to reflect this change.
9578 pspp_sheet_view_scroll_to_cell (PsppSheetView *tree_view,
9580 PsppSheetViewColumn *column,
9585 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9586 g_return_if_fail (tree_view->priv->model != NULL);
9587 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
9588 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
9589 g_return_if_fail (path != NULL || column != NULL);
9592 g_print ("pspp_sheet_view_scroll_to_cell:\npath: %s\ncolumn: %s\nuse_align: %d\nrow_align: %f\ncol_align: %f\n",
9593 gtk_tree_path_to_string (path), column?"non-null":"null", use_align, row_align, col_align);
9595 row_align = CLAMP (row_align, 0.0, 1.0);
9596 col_align = CLAMP (col_align, 0.0, 1.0);
9599 /* Note: Despite the benefits that come from having one code path for the
9600 * scrolling code, we short-circuit validate_visible_area's immplementation as
9601 * it is much slower than just going to the point.
9603 if (!gtk_widget_get_visible (GTK_WIDGET (tree_view)) ||
9604 !gtk_widget_get_realized (GTK_WIDGET (tree_view))
9605 /* XXX || GTK_WIDGET_ALLOC_NEEDED (tree_view) */)
9607 if (tree_view->priv->scroll_to_path)
9608 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9610 tree_view->priv->scroll_to_path = NULL;
9611 tree_view->priv->scroll_to_column = NULL;
9614 tree_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
9616 tree_view->priv->scroll_to_column = column;
9617 tree_view->priv->scroll_to_use_align = use_align;
9618 tree_view->priv->scroll_to_row_align = row_align;
9619 tree_view->priv->scroll_to_col_align = col_align;
9621 install_presize_handler (tree_view);
9625 GdkRectangle cell_rect;
9626 GdkRectangle vis_rect;
9627 gint dest_x, dest_y;
9629 pspp_sheet_view_get_background_area (tree_view, path, column, &cell_rect);
9630 pspp_sheet_view_get_visible_rect (tree_view, &vis_rect);
9632 cell_rect.y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, cell_rect.y);
9634 dest_x = vis_rect.x;
9635 dest_y = vis_rect.y;
9641 dest_x = cell_rect.x - ((vis_rect.width - cell_rect.width) * col_align);
9645 if (cell_rect.x < vis_rect.x)
9646 dest_x = cell_rect.x;
9647 if (cell_rect.x + cell_rect.width > vis_rect.x + vis_rect.width)
9648 dest_x = cell_rect.x + cell_rect.width - vis_rect.width;
9656 dest_y = cell_rect.y - ((vis_rect.height - cell_rect.height) * row_align);
9657 dest_y = MAX (dest_y, 0);
9661 if (cell_rect.y < vis_rect.y)
9662 dest_y = cell_rect.y;
9663 if (cell_rect.y + cell_rect.height > vis_rect.y + vis_rect.height)
9664 dest_y = cell_rect.y + cell_rect.height - vis_rect.height;
9668 pspp_sheet_view_scroll_to_point (tree_view, dest_x, dest_y);
9673 * pspp_sheet_view_row_activated:
9674 * @tree_view: A #PsppSheetView
9675 * @path: The #GtkTreePath to be activated.
9676 * @column: The #PsppSheetViewColumn to be activated.
9678 * Activates the cell determined by @path and @column.
9681 pspp_sheet_view_row_activated (PsppSheetView *tree_view,
9683 PsppSheetViewColumn *column)
9685 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9687 g_signal_emit (tree_view, tree_view_signals[ROW_ACTIVATED], 0, path, column);
9692 * pspp_sheet_view_get_reorderable:
9693 * @tree_view: a #PsppSheetView
9695 * Retrieves whether the user can reorder the tree via drag-and-drop. See
9696 * pspp_sheet_view_set_reorderable().
9698 * Return value: %TRUE if the tree can be reordered.
9701 pspp_sheet_view_get_reorderable (PsppSheetView *tree_view)
9703 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9705 return tree_view->priv->reorderable;
9709 * pspp_sheet_view_set_reorderable:
9710 * @tree_view: A #PsppSheetView.
9711 * @reorderable: %TRUE, if the tree can be reordered.
9713 * This function is a convenience function to allow you to reorder
9714 * models that support the #GtkDragSourceIface and the
9715 * #GtkDragDestIface. Both #GtkTreeStore and #GtkListStore support
9716 * these. If @reorderable is %TRUE, then the user can reorder the
9717 * model by dragging and dropping rows. The developer can listen to
9718 * these changes by connecting to the model's row_inserted and
9719 * row_deleted signals. The reordering is implemented by setting up
9720 * the tree view as a drag source and destination. Therefore, drag and
9721 * drop can not be used in a reorderable view for any other purpose.
9723 * This function does not give you any degree of control over the order -- any
9724 * reordering is allowed. If more control is needed, you should probably
9725 * handle drag and drop manually.
9728 pspp_sheet_view_set_reorderable (PsppSheetView *tree_view,
9729 gboolean reorderable)
9731 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9733 reorderable = reorderable != FALSE;
9735 if (tree_view->priv->reorderable == reorderable)
9740 const GtkTargetEntry row_targets[] = {
9741 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
9744 pspp_sheet_view_enable_model_drag_source (tree_view,
9747 G_N_ELEMENTS (row_targets),
9749 pspp_sheet_view_enable_model_drag_dest (tree_view,
9751 G_N_ELEMENTS (row_targets),
9756 pspp_sheet_view_unset_rows_drag_source (tree_view);
9757 pspp_sheet_view_unset_rows_drag_dest (tree_view);
9760 tree_view->priv->reorderable = reorderable;
9762 g_object_notify (G_OBJECT (tree_view), "reorderable");
9765 /* If CLEAR_AND_SELECT is true, then the row will be selected and, unless Shift
9766 is pressed, other rows will be unselected.
9768 If CLAMP_NODE is true, then the sheetview will scroll to make the row
9771 pspp_sheet_view_real_set_cursor (PsppSheetView *tree_view,
9773 gboolean clear_and_select,
9774 gboolean clamp_node)
9778 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
9780 GtkTreePath *cursor_path;
9781 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
9782 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
9783 gtk_tree_path_free (cursor_path);
9786 gtk_tree_row_reference_free (tree_view->priv->cursor);
9787 tree_view->priv->cursor = NULL;
9789 _pspp_sheet_view_find_node (tree_view, path, &node);
9790 tree_view->priv->cursor =
9791 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
9792 tree_view->priv->model,
9795 if (tree_view->priv->row_count > 0)
9799 if (clear_and_select && !tree_view->priv->ctrl_pressed)
9801 GtkTreeSelectMode mode = 0;
9803 if (tree_view->priv->ctrl_pressed)
9804 mode |= GTK_TREE_SELECT_MODE_TOGGLE;
9805 if (tree_view->priv->shift_pressed)
9806 mode |= GTK_TREE_SELECT_MODE_EXTEND;
9808 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
9813 /* We have to re-find tree and node here again, somebody might have
9814 * cleared the node or the whole tree in the PsppSheetSelection::changed
9815 * callback. If the nodes differ we bail out here.
9817 _pspp_sheet_view_find_node (tree_view, path, &new_node);
9819 if (node != new_node)
9824 pspp_sheet_view_clamp_node_visible (tree_view, node);
9825 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
9829 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
9833 * pspp_sheet_view_get_cursor:
9834 * @tree_view: A #PsppSheetView
9835 * @path: (allow-none): A pointer to be filled with the current cursor path, or %NULL
9836 * @focus_column: (allow-none): A pointer to be filled with the current focus column, or %NULL
9838 * Fills in @path and @focus_column with the current path and focus column. If
9839 * the cursor isn't currently set, then *@path will be %NULL. If no column
9840 * currently has focus, then *@focus_column will be %NULL.
9842 * The returned #GtkTreePath must be freed with gtk_tree_path_free() when
9843 * you are done with it.
9846 pspp_sheet_view_get_cursor (PsppSheetView *tree_view,
9848 PsppSheetViewColumn **focus_column)
9850 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9854 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
9855 *path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
9862 *focus_column = tree_view->priv->focus_column;
9867 * pspp_sheet_view_set_cursor:
9868 * @tree_view: A #PsppSheetView
9869 * @path: A #GtkTreePath
9870 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
9871 * @start_editing: %TRUE if the specified cell should start being edited.
9873 * Sets the current keyboard focus to be at @path, and selects it. This is
9874 * useful when you want to focus the user's attention on a particular row. If
9875 * @focus_column is not %NULL, then focus is given to the column specified by
9876 * it. Additionally, if @focus_column is specified, and @start_editing is
9877 * %TRUE, then editing should be started in the specified cell.
9878 * This function is often followed by @gtk_widget_grab_focus (@tree_view)
9879 * in order to give keyboard focus to the widget. Please note that editing
9880 * can only happen when the widget is realized.
9882 * If @path is invalid for @model, the current cursor (if any) will be unset
9883 * and the function will return without failing.
9886 pspp_sheet_view_set_cursor (PsppSheetView *tree_view,
9888 PsppSheetViewColumn *focus_column,
9889 gboolean start_editing)
9891 pspp_sheet_view_set_cursor_on_cell (tree_view, path, focus_column,
9892 NULL, start_editing);
9896 * pspp_sheet_view_set_cursor_on_cell:
9897 * @tree_view: A #PsppSheetView
9898 * @path: A #GtkTreePath
9899 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
9900 * @focus_cell: (allow-none): A #GtkCellRenderer, or %NULL
9901 * @start_editing: %TRUE if the specified cell should start being edited.
9903 * Sets the current keyboard focus to be at @path, and selects it. This is
9904 * useful when you want to focus the user's attention on a particular row. If
9905 * @focus_column is not %NULL, then focus is given to the column specified by
9906 * it. If @focus_column and @focus_cell are not %NULL, and @focus_column
9907 * contains 2 or more editable or activatable cells, then focus is given to
9908 * the cell specified by @focus_cell. Additionally, if @focus_column is
9909 * specified, and @start_editing is %TRUE, then editing should be started in
9910 * the specified cell. This function is often followed by
9911 * @gtk_widget_grab_focus (@tree_view) in order to give keyboard focus to the
9912 * widget. Please note that editing can only happen when the widget is
9915 * If @path is invalid for @model, the current cursor (if any) will be unset
9916 * and the function will return without failing.
9921 pspp_sheet_view_set_cursor_on_cell (PsppSheetView *tree_view,
9923 PsppSheetViewColumn *focus_column,
9924 GtkCellRenderer *focus_cell,
9925 gboolean start_editing)
9927 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9928 g_return_if_fail (path != NULL);
9929 g_return_if_fail (focus_column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (focus_column));
9931 if (!tree_view->priv->model)
9936 g_return_if_fail (focus_column);
9937 g_return_if_fail (GTK_IS_CELL_RENDERER (focus_cell));
9940 /* cancel the current editing, if it exists */
9941 if (tree_view->priv->edited_column &&
9942 tree_view->priv->edited_column->editable_widget)
9943 pspp_sheet_view_stop_editing (tree_view, TRUE);
9945 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE);
9947 if (focus_column && focus_column->visible)
9950 gboolean column_in_tree = FALSE;
9952 for (list = tree_view->priv->columns; list; list = list->next)
9953 if (list->data == focus_column)
9955 column_in_tree = TRUE;
9958 g_return_if_fail (column_in_tree);
9959 tree_view->priv->focus_column = focus_column;
9961 pspp_sheet_view_column_focus_cell (focus_column, focus_cell);
9963 pspp_sheet_view_start_editing (tree_view, path);
9965 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
9966 pspp_sheet_selection_select_column (tree_view->priv->selection, focus_column);
9972 * pspp_sheet_view_get_bin_window:
9973 * @tree_view: A #PsppSheetView
9975 * Returns the window that @tree_view renders to. This is used primarily to
9976 * compare to <literal>event->window</literal> to confirm that the event on
9977 * @tree_view is on the right window.
9979 * Return value: A #GdkWindow, or %NULL when @tree_view hasn't been realized yet
9982 pspp_sheet_view_get_bin_window (PsppSheetView *tree_view)
9984 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9986 return tree_view->priv->bin_window;
9990 * pspp_sheet_view_get_path_at_pos:
9991 * @tree_view: A #PsppSheetView.
9992 * @x: The x position to be identified (relative to bin_window).
9993 * @y: The y position to be identified (relative to bin_window).
9994 * @path: (out) (allow-none): A pointer to a #GtkTreePath pointer to be filled in, or %NULL
9995 * @column: (out) (allow-none): A pointer to a #PsppSheetViewColumn pointer to be filled in, or %NULL
9996 * @cell_x: (out) (allow-none): A pointer where the X coordinate relative to the cell can be placed, or %NULL
9997 * @cell_y: (out) (allow-none): A pointer where the Y coordinate relative to the cell can be placed, or %NULL
9999 * Finds the path at the point (@x, @y), relative to bin_window coordinates
10000 * (please see pspp_sheet_view_get_bin_window()).
10001 * That is, @x and @y are relative to an events coordinates. @x and @y must
10002 * come from an event on the @tree_view only where <literal>event->window ==
10003 * pspp_sheet_view_get_bin_window (<!-- -->)</literal>. It is primarily for
10004 * things like popup menus. If @path is non-%NULL, then it will be filled
10005 * with the #GtkTreePath at that point. This path should be freed with
10006 * gtk_tree_path_free(). If @column is non-%NULL, then it will be filled
10007 * with the column at that point. @cell_x and @cell_y return the coordinates
10008 * relative to the cell background (i.e. the @background_area passed to
10009 * gtk_cell_renderer_render()). This function is only meaningful if
10010 * @tree_view is realized. Therefore this function will always return %FALSE
10011 * if @tree_view is not realized or does not have a model.
10013 * For converting widget coordinates (eg. the ones you get from
10014 * GtkWidget::query-tooltip), please see
10015 * pspp_sheet_view_convert_widget_to_bin_window_coords().
10017 * Return value: %TRUE if a row exists at that coordinate.
10020 pspp_sheet_view_get_path_at_pos (PsppSheetView *tree_view,
10023 GtkTreePath **path,
10024 PsppSheetViewColumn **column,
10031 g_return_val_if_fail (tree_view != NULL, FALSE);
10038 if (tree_view->priv->bin_window == NULL)
10041 if (tree_view->priv->row_count == 0)
10044 if (x > tree_view->priv->hadjustment->upper)
10047 if (x < 0 || y < 0)
10050 if (column || cell_x)
10052 PsppSheetViewColumn *tmp_column;
10053 PsppSheetViewColumn *last_column = NULL;
10055 gint remaining_x = x;
10056 gboolean found = FALSE;
10059 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
10060 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
10062 list = (rtl ? list->prev : list->next))
10064 tmp_column = list->data;
10066 if (tmp_column->visible == FALSE)
10069 last_column = tmp_column;
10070 if (remaining_x <= tmp_column->width)
10075 *column = tmp_column;
10078 *cell_x = remaining_x;
10082 remaining_x -= tmp_column->width;
10085 /* If found is FALSE and there is a last_column, then it the remainder
10086 * space is in that area
10093 *column = last_column;
10096 *cell_x = last_column->width + remaining_x;
10105 y_offset = pspp_sheet_view_find_offset (tree_view,
10106 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, y),
10113 *cell_y = y_offset;
10116 *path = _pspp_sheet_view_find_path (tree_view, node);
10121 /* Computes 'cell_area' from 'background_area', which must be the background
10122 area for a cell. Set 'subtract_focus_rect' to TRUE to compute the cell area
10123 as passed to a GtkCellRenderer's "render" function, or to FALSE to compute
10124 the cell area as passed to _pspp_sheet_view_column_cell_render().
10126 'column' is required to properly adjust 'cell_area->x' and
10127 'cell_area->width'. It may be set to NULL if these values are not of
10128 interest. In this case 'cell_area->x' and 'cell_area->width' will be
10131 pspp_sheet_view_adjust_cell_area (PsppSheetView *tree_view,
10132 PsppSheetViewColumn *column,
10133 const GdkRectangle *background_area,
10134 gboolean subtract_focus_rect,
10135 GdkRectangle *cell_area)
10137 gint vertical_separator;
10138 gint horizontal_separator;
10140 *cell_area = *background_area;
10142 gtk_widget_style_get (GTK_WIDGET (tree_view),
10143 "vertical-separator", &vertical_separator,
10144 "horizontal-separator", &horizontal_separator,
10146 cell_area->x += horizontal_separator / 2;
10147 cell_area->y += vertical_separator / 2;
10148 cell_area->width -= horizontal_separator;
10149 cell_area->height -= vertical_separator;
10151 if (subtract_focus_rect)
10153 int focus_line_width;
10155 gtk_widget_style_get (GTK_WIDGET (tree_view),
10156 "focus-line-width", &focus_line_width,
10158 cell_area->x += focus_line_width;
10159 cell_area->y += focus_line_width;
10160 cell_area->width -= 2 * focus_line_width;
10161 cell_area->height -= 2 * focus_line_width;
10164 if (tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_NONE)
10166 gint grid_line_width;
10167 gtk_widget_style_get (GTK_WIDGET (tree_view),
10168 "grid-line-width", &grid_line_width,
10171 if ((tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
10172 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10175 PsppSheetViewColumn *first_column, *last_column;
10178 /* Find the last visible column. */
10179 last_column = NULL;
10180 for (list = g_list_last (tree_view->priv->columns);
10184 PsppSheetViewColumn *c = list->data;
10192 /* Find the first visible column. */
10193 first_column = NULL;
10194 for (list = g_list_first (tree_view->priv->columns);
10198 PsppSheetViewColumn *c = list->data;
10206 if (column == first_column)
10208 cell_area->width -= grid_line_width / 2;
10210 else if (column == last_column)
10212 cell_area->x += grid_line_width / 2;
10213 cell_area->width -= grid_line_width / 2;
10217 cell_area->x += grid_line_width / 2;
10218 cell_area->width -= grid_line_width;
10222 if (tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
10223 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10225 cell_area->y += grid_line_width / 2;
10226 cell_area->height -= grid_line_width;
10230 if (column == NULL)
10233 cell_area->width = 0;
10238 * pspp_sheet_view_get_cell_area:
10239 * @tree_view: a #PsppSheetView
10240 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10241 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordinates
10242 * @rect: rectangle to fill with cell rect
10244 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10245 * row specified by @path and the column specified by @column. If @path is
10246 * %NULL, or points to a path not currently displayed, the @y and @height fields
10247 * of the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10248 * fields will be filled with 0. The sum of all cell rects does not cover the
10249 * entire tree; there are extra pixels in between rows, for example. The
10250 * returned rectangle is equivalent to the @cell_area passed to
10251 * gtk_cell_renderer_render(). This function is only valid if @tree_view is
10255 pspp_sheet_view_get_cell_area (PsppSheetView *tree_view,
10257 PsppSheetViewColumn *column,
10258 GdkRectangle *rect)
10260 GdkRectangle background_area;
10262 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10263 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10264 g_return_if_fail (rect != NULL);
10265 g_return_if_fail (!column || column->tree_view == (GtkWidget *) tree_view);
10266 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
10268 pspp_sheet_view_get_background_area (tree_view, path, column,
10270 pspp_sheet_view_adjust_cell_area (tree_view, column, &background_area,
10275 * pspp_sheet_view_get_background_area:
10276 * @tree_view: a #PsppSheetView
10277 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10278 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordiantes
10279 * @rect: rectangle to fill with cell background rect
10281 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10282 * row specified by @path and the column specified by @column. If @path is
10283 * %NULL, or points to a node not found in the tree, the @y and @height fields of
10284 * the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10285 * fields will be filled with 0. The returned rectangle is equivalent to the
10286 * @background_area passed to gtk_cell_renderer_render(). These background
10287 * areas tile to cover the entire bin window. Contrast with the @cell_area,
10288 * returned by pspp_sheet_view_get_cell_area(), which returns only the cell
10289 * itself, excluding surrounding borders.
10293 pspp_sheet_view_get_background_area (PsppSheetView *tree_view,
10295 PsppSheetViewColumn *column,
10296 GdkRectangle *rect)
10300 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10301 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10302 g_return_if_fail (rect != NULL);
10311 /* Get vertical coords */
10313 _pspp_sheet_view_find_node (tree_view, path, &node);
10317 rect->y = BACKGROUND_FIRST_PIXEL (tree_view, node);
10319 rect->height = ROW_HEIGHT (tree_view);
10326 pspp_sheet_view_get_background_xrange (tree_view, column, &rect->x, &x2);
10327 rect->width = x2 - rect->x;
10332 * pspp_sheet_view_get_visible_rect:
10333 * @tree_view: a #PsppSheetView
10334 * @visible_rect: rectangle to fill
10336 * Fills @visible_rect with the currently-visible region of the
10337 * buffer, in tree coordinates. Convert to bin_window coordinates with
10338 * pspp_sheet_view_convert_tree_to_bin_window_coords().
10339 * Tree coordinates start at 0,0 for row 0 of the tree, and cover the entire
10340 * scrollable area of the tree.
10343 pspp_sheet_view_get_visible_rect (PsppSheetView *tree_view,
10344 GdkRectangle *visible_rect)
10348 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10350 widget = GTK_WIDGET (tree_view);
10354 visible_rect->x = tree_view->priv->hadjustment->value;
10355 visible_rect->y = tree_view->priv->vadjustment->value;
10356 visible_rect->width = widget->allocation.width;
10357 visible_rect->height = widget->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
10362 * pspp_sheet_view_widget_to_tree_coords:
10363 * @tree_view: a #PsppSheetView
10364 * @wx: X coordinate relative to bin_window
10365 * @wy: Y coordinate relative to bin_window
10366 * @tx: return location for tree X coordinate
10367 * @ty: return location for tree Y coordinate
10369 * Converts bin_window coordinates to coordinates for the
10370 * tree (the full scrollable area of the tree).
10372 * Deprecated: 2.12: Due to historial reasons the name of this function is
10373 * incorrect. For converting coordinates relative to the widget to
10374 * bin_window coordinates, please see
10375 * pspp_sheet_view_convert_widget_to_bin_window_coords().
10379 pspp_sheet_view_widget_to_tree_coords (PsppSheetView *tree_view,
10385 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10388 *tx = wx + tree_view->priv->hadjustment->value;
10390 *ty = wy + tree_view->priv->dy;
10394 * pspp_sheet_view_tree_to_widget_coords:
10395 * @tree_view: a #PsppSheetView
10396 * @tx: tree X coordinate
10397 * @ty: tree Y coordinate
10398 * @wx: return location for X coordinate relative to bin_window
10399 * @wy: return location for Y coordinate relative to bin_window
10401 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10402 * to bin_window coordinates.
10404 * Deprecated: 2.12: Due to historial reasons the name of this function is
10405 * incorrect. For converting bin_window coordinates to coordinates relative
10406 * to bin_window, please see
10407 * pspp_sheet_view_convert_bin_window_to_widget_coords().
10411 pspp_sheet_view_tree_to_widget_coords (PsppSheetView *tree_view,
10417 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10420 *wx = tx - tree_view->priv->hadjustment->value;
10422 *wy = ty - tree_view->priv->dy;
10427 * pspp_sheet_view_convert_widget_to_tree_coords:
10428 * @tree_view: a #PsppSheetView
10429 * @wx: X coordinate relative to the widget
10430 * @wy: Y coordinate relative to the widget
10431 * @tx: return location for tree X coordinate
10432 * @ty: return location for tree Y coordinate
10434 * Converts widget coordinates to coordinates for the
10435 * tree (the full scrollable area of the tree).
10440 pspp_sheet_view_convert_widget_to_tree_coords (PsppSheetView *tree_view,
10448 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10450 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view,
10453 pspp_sheet_view_convert_bin_window_to_tree_coords (tree_view,
10459 * pspp_sheet_view_convert_tree_to_widget_coords:
10460 * @tree_view: a #PsppSheetView
10461 * @tx: X coordinate relative to the tree
10462 * @ty: Y coordinate relative to the tree
10463 * @wx: return location for widget X coordinate
10464 * @wy: return location for widget Y coordinate
10466 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10467 * to widget coordinates.
10472 pspp_sheet_view_convert_tree_to_widget_coords (PsppSheetView *tree_view,
10480 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10482 pspp_sheet_view_convert_tree_to_bin_window_coords (tree_view,
10485 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
10491 * pspp_sheet_view_convert_widget_to_bin_window_coords:
10492 * @tree_view: a #PsppSheetView
10493 * @wx: X coordinate relative to the widget
10494 * @wy: Y coordinate relative to the widget
10495 * @bx: return location for bin_window X coordinate
10496 * @by: return location for bin_window Y coordinate
10498 * Converts widget coordinates to coordinates for the bin_window
10499 * (see pspp_sheet_view_get_bin_window()).
10504 pspp_sheet_view_convert_widget_to_bin_window_coords (PsppSheetView *tree_view,
10510 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10513 *bx = wx + tree_view->priv->hadjustment->value;
10515 *by = wy - TREE_VIEW_HEADER_HEIGHT (tree_view);
10519 * pspp_sheet_view_convert_bin_window_to_widget_coords:
10520 * @tree_view: a #PsppSheetView
10521 * @bx: bin_window X coordinate
10522 * @by: bin_window Y coordinate
10523 * @wx: return location for widget X coordinate
10524 * @wy: return location for widget Y coordinate
10526 * Converts bin_window coordinates (see pspp_sheet_view_get_bin_window())
10527 * to widget relative coordinates.
10532 pspp_sheet_view_convert_bin_window_to_widget_coords (PsppSheetView *tree_view,
10538 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10541 *wx = bx - tree_view->priv->hadjustment->value;
10543 *wy = by + TREE_VIEW_HEADER_HEIGHT (tree_view);
10547 * pspp_sheet_view_convert_tree_to_bin_window_coords:
10548 * @tree_view: a #PsppSheetView
10549 * @tx: tree X coordinate
10550 * @ty: tree Y coordinate
10551 * @bx: return location for X coordinate relative to bin_window
10552 * @by: return location for Y coordinate relative to bin_window
10554 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10555 * to bin_window coordinates.
10560 pspp_sheet_view_convert_tree_to_bin_window_coords (PsppSheetView *tree_view,
10566 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10571 *by = ty - tree_view->priv->dy;
10575 * pspp_sheet_view_convert_bin_window_to_tree_coords:
10576 * @tree_view: a #PsppSheetView
10577 * @bx: X coordinate relative to bin_window
10578 * @by: Y coordinate relative to bin_window
10579 * @tx: return location for tree X coordinate
10580 * @ty: return location for tree Y coordinate
10582 * Converts bin_window coordinates to coordinates for the
10583 * tree (the full scrollable area of the tree).
10588 pspp_sheet_view_convert_bin_window_to_tree_coords (PsppSheetView *tree_view,
10594 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10599 *ty = by + tree_view->priv->dy;
10605 * pspp_sheet_view_get_visible_range:
10606 * @tree_view: A #PsppSheetView
10607 * @start_path: (allow-none): Return location for start of region, or %NULL.
10608 * @end_path: (allow-none): Return location for end of region, or %NULL.
10610 * Sets @start_path and @end_path to be the first and last visible path.
10611 * Note that there may be invisible paths in between.
10613 * The paths should be freed with gtk_tree_path_free() after use.
10615 * Returns: %TRUE, if valid paths were placed in @start_path and @end_path.
10620 pspp_sheet_view_get_visible_range (PsppSheetView *tree_view,
10621 GtkTreePath **start_path,
10622 GtkTreePath **end_path)
10627 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
10629 if (!tree_view->priv->row_count)
10636 pspp_sheet_view_find_offset (tree_view,
10637 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, 0),
10640 *start_path = _pspp_sheet_view_find_path (tree_view, node);
10649 if (tree_view->priv->height < tree_view->priv->vadjustment->page_size)
10650 y = tree_view->priv->height - 1;
10652 y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, tree_view->priv->vadjustment->page_size) - 1;
10654 pspp_sheet_view_find_offset (tree_view, y, &node);
10656 *end_path = _pspp_sheet_view_find_path (tree_view, node);
10665 unset_reorderable (PsppSheetView *tree_view)
10667 if (tree_view->priv->reorderable)
10669 tree_view->priv->reorderable = FALSE;
10670 g_object_notify (G_OBJECT (tree_view), "reorderable");
10675 * pspp_sheet_view_enable_model_drag_source:
10676 * @tree_view: a #PsppSheetView
10677 * @start_button_mask: Mask of allowed buttons to start drag
10678 * @targets: the table of targets that the drag will support
10679 * @n_targets: the number of items in @targets
10680 * @actions: the bitmask of possible actions for a drag from this
10683 * Turns @tree_view into a drag source for automatic DND. Calling this
10684 * method sets #PsppSheetView:reorderable to %FALSE.
10687 pspp_sheet_view_enable_model_drag_source (PsppSheetView *tree_view,
10688 GdkModifierType start_button_mask,
10689 const GtkTargetEntry *targets,
10691 GdkDragAction actions)
10693 TreeViewDragInfo *di;
10695 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10697 gtk_drag_source_set (GTK_WIDGET (tree_view),
10703 di = ensure_info (tree_view);
10705 di->start_button_mask = start_button_mask;
10706 di->source_actions = actions;
10707 di->source_set = TRUE;
10709 unset_reorderable (tree_view);
10713 * pspp_sheet_view_enable_model_drag_dest:
10714 * @tree_view: a #PsppSheetView
10715 * @targets: the table of targets that the drag will support
10716 * @n_targets: the number of items in @targets
10717 * @actions: the bitmask of possible actions for a drag from this
10720 * Turns @tree_view into a drop destination for automatic DND. Calling
10721 * this method sets #PsppSheetView:reorderable to %FALSE.
10724 pspp_sheet_view_enable_model_drag_dest (PsppSheetView *tree_view,
10725 const GtkTargetEntry *targets,
10727 GdkDragAction actions)
10729 TreeViewDragInfo *di;
10731 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10733 gtk_drag_dest_set (GTK_WIDGET (tree_view),
10739 di = ensure_info (tree_view);
10740 di->dest_set = TRUE;
10742 unset_reorderable (tree_view);
10746 * pspp_sheet_view_unset_rows_drag_source:
10747 * @tree_view: a #PsppSheetView
10749 * Undoes the effect of
10750 * pspp_sheet_view_enable_model_drag_source(). Calling this method sets
10751 * #PsppSheetView:reorderable to %FALSE.
10754 pspp_sheet_view_unset_rows_drag_source (PsppSheetView *tree_view)
10756 TreeViewDragInfo *di;
10758 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10760 di = get_info (tree_view);
10764 if (di->source_set)
10766 gtk_drag_source_unset (GTK_WIDGET (tree_view));
10767 di->source_set = FALSE;
10770 if (!di->dest_set && !di->source_set)
10771 remove_info (tree_view);
10774 unset_reorderable (tree_view);
10778 * pspp_sheet_view_unset_rows_drag_dest:
10779 * @tree_view: a #PsppSheetView
10781 * Undoes the effect of
10782 * pspp_sheet_view_enable_model_drag_dest(). Calling this method sets
10783 * #PsppSheetView:reorderable to %FALSE.
10786 pspp_sheet_view_unset_rows_drag_dest (PsppSheetView *tree_view)
10788 TreeViewDragInfo *di;
10790 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10792 di = get_info (tree_view);
10798 gtk_drag_dest_unset (GTK_WIDGET (tree_view));
10799 di->dest_set = FALSE;
10802 if (!di->dest_set && !di->source_set)
10803 remove_info (tree_view);
10806 unset_reorderable (tree_view);
10810 * pspp_sheet_view_set_drag_dest_row:
10811 * @tree_view: a #PsppSheetView
10812 * @path: (allow-none): The path of the row to highlight, or %NULL.
10813 * @pos: Specifies whether to drop before, after or into the row
10815 * Sets the row that is highlighted for feedback.
10818 pspp_sheet_view_set_drag_dest_row (PsppSheetView *tree_view,
10820 PsppSheetViewDropPosition pos)
10822 GtkTreePath *current_dest;
10824 /* Note; this function is exported to allow a custom DND
10825 * implementation, so it can't touch TreeViewDragInfo
10828 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10830 current_dest = NULL;
10832 if (tree_view->priv->drag_dest_row)
10834 current_dest = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
10835 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
10838 /* special case a drop on an empty model */
10839 tree_view->priv->empty_view_drop = 0;
10841 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE && path
10842 && gtk_tree_path_get_depth (path) == 1
10843 && gtk_tree_path_get_indices (path)[0] == 0)
10847 n_children = gtk_tree_model_iter_n_children (tree_view->priv->model,
10851 tree_view->priv->empty_view_drop = 1;
10854 tree_view->priv->drag_dest_pos = pos;
10858 tree_view->priv->drag_dest_row =
10859 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
10860 pspp_sheet_view_queue_draw_path (tree_view, path, NULL);
10863 tree_view->priv->drag_dest_row = NULL;
10867 int node, new_node;
10869 _pspp_sheet_view_find_node (tree_view, current_dest, &node);
10870 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
10874 new_node = pspp_sheet_view_node_next (tree_view, node);
10876 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
10878 new_node = pspp_sheet_view_node_prev (tree_view, node);
10880 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
10882 gtk_tree_path_free (current_dest);
10887 * pspp_sheet_view_get_drag_dest_row:
10888 * @tree_view: a #PsppSheetView
10889 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
10890 * @pos: (allow-none): Return location for the drop position, or %NULL
10892 * Gets information about the row that is highlighted for feedback.
10895 pspp_sheet_view_get_drag_dest_row (PsppSheetView *tree_view,
10896 GtkTreePath **path,
10897 PsppSheetViewDropPosition *pos)
10899 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10903 if (tree_view->priv->drag_dest_row)
10904 *path = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
10907 if (tree_view->priv->empty_view_drop)
10908 *path = gtk_tree_path_new_from_indices (0, -1);
10915 *pos = tree_view->priv->drag_dest_pos;
10919 * pspp_sheet_view_get_dest_row_at_pos:
10920 * @tree_view: a #PsppSheetView
10921 * @drag_x: the position to determine the destination row for
10922 * @drag_y: the position to determine the destination row for
10923 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
10924 * @pos: (allow-none): Return location for the drop position, or %NULL
10926 * Determines the destination row for a given position. @drag_x and
10927 * @drag_y are expected to be in widget coordinates. This function is only
10928 * meaningful if @tree_view is realized. Therefore this function will always
10929 * return %FALSE if @tree_view is not realized or does not have a model.
10931 * Return value: whether there is a row at the given position, %TRUE if this
10932 * is indeed the case.
10935 pspp_sheet_view_get_dest_row_at_pos (PsppSheetView *tree_view,
10938 GtkTreePath **path,
10939 PsppSheetViewDropPosition *pos)
10943 gdouble offset_into_row;
10946 PsppSheetViewColumn *column = NULL;
10947 GtkTreePath *tmp_path = NULL;
10949 /* Note; this function is exported to allow a custom DND
10950 * implementation, so it can't touch TreeViewDragInfo
10953 g_return_val_if_fail (tree_view != NULL, FALSE);
10954 g_return_val_if_fail (drag_x >= 0, FALSE);
10955 g_return_val_if_fail (drag_y >= 0, FALSE);
10960 if (tree_view->priv->bin_window == NULL)
10963 if (tree_view->priv->row_count == 0)
10966 /* If in the top third of a row, we drop before that row; if
10967 * in the bottom third, drop after that row; if in the middle,
10968 * and the row has children, drop into the row.
10970 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, drag_x, drag_y,
10973 if (!pspp_sheet_view_get_path_at_pos (tree_view,
10982 pspp_sheet_view_get_background_area (tree_view, tmp_path, column,
10985 offset_into_row = cell_y;
10990 gtk_tree_path_free (tmp_path);
10994 third = cell.height / 3.0;
10998 if (offset_into_row < third)
11000 *pos = PSPP_SHEET_VIEW_DROP_BEFORE;
11002 else if (offset_into_row < (cell.height / 2.0))
11004 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE;
11006 else if (offset_into_row < third * 2.0)
11008 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER;
11012 *pos = PSPP_SHEET_VIEW_DROP_AFTER;
11021 /* KEEP IN SYNC WITH PSPP_SHEET_VIEW_BIN_EXPOSE */
11023 * pspp_sheet_view_create_row_drag_icon:
11024 * @tree_view: a #PsppSheetView
11025 * @path: a #GtkTreePath in @tree_view
11027 * Creates a #GdkPixmap representation of the row at @path.
11028 * This image is used for a drag icon.
11030 * Return value: a newly-allocated pixmap of the drag icon.
11033 pspp_sheet_view_create_row_drag_icon (PsppSheetView *tree_view,
11040 GdkRectangle background_area;
11041 GdkRectangle expose_area;
11043 /* start drawing inside the black outline */
11045 GdkDrawable *drawable;
11046 gint bin_window_width;
11049 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11050 g_return_val_if_fail (path != NULL, NULL);
11052 widget = GTK_WIDGET (tree_view);
11054 if (!gtk_widget_get_realized (widget))
11057 _pspp_sheet_view_find_node (tree_view,
11064 if (!gtk_tree_model_get_iter (tree_view->priv->model,
11071 background_area.y = y;
11072 background_area.height = ROW_HEIGHT (tree_view);
11074 gdk_drawable_get_size (tree_view->priv->bin_window,
11075 &bin_window_width, NULL);
11077 drawable = gdk_pixmap_new (tree_view->priv->bin_window,
11078 bin_window_width + 2,
11079 background_area.height + 2,
11084 expose_area.width = bin_window_width + 2;
11085 expose_area.height = background_area.height + 2;
11087 gdk_draw_rectangle (drawable,
11088 widget->style->base_gc [gtk_widget_get_state (widget)],
11091 bin_window_width + 2,
11092 background_area.height + 2);
11094 rtl = gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL;
11096 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
11098 list = (rtl ? list->prev : list->next))
11100 PsppSheetViewColumn *column = list->data;
11101 GdkRectangle cell_area;
11102 gint vertical_separator;
11104 if (!column->visible)
11107 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, &iter);
11109 background_area.x = cell_offset;
11110 background_area.width = column->width;
11112 gtk_widget_style_get (widget,
11113 "vertical-separator", &vertical_separator,
11116 cell_area = background_area;
11118 cell_area.y += vertical_separator / 2;
11119 cell_area.height -= vertical_separator;
11121 if (pspp_sheet_view_column_cell_is_visible (column))
11122 _pspp_sheet_view_column_cell_render (column,
11128 cell_offset += column->width;
11131 gdk_draw_rectangle (drawable,
11132 widget->style->black_gc,
11135 bin_window_width + 1,
11136 background_area.height + 1);
11143 * pspp_sheet_view_set_destroy_count_func:
11144 * @tree_view: A #PsppSheetView
11145 * @func: (allow-none): Function to be called when a view row is destroyed, or %NULL
11146 * @data: (allow-none): User data to be passed to @func, or %NULL
11147 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11149 * This function should almost never be used. It is meant for private use by
11150 * ATK for determining the number of visible children that are removed when a row is deleted.
11153 pspp_sheet_view_set_destroy_count_func (PsppSheetView *tree_view,
11154 PsppSheetDestroyCountFunc func,
11156 GDestroyNotify destroy)
11158 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11160 if (tree_view->priv->destroy_count_destroy)
11161 tree_view->priv->destroy_count_destroy (tree_view->priv->destroy_count_data);
11163 tree_view->priv->destroy_count_func = func;
11164 tree_view->priv->destroy_count_data = data;
11165 tree_view->priv->destroy_count_destroy = destroy;
11170 * Interactive search
11174 * pspp_sheet_view_set_enable_search:
11175 * @tree_view: A #PsppSheetView
11176 * @enable_search: %TRUE, if the user can search interactively
11178 * If @enable_search is set, then the user can type in text to search through
11179 * the tree interactively (this is sometimes called "typeahead find").
11181 * Note that even if this is %FALSE, the user can still initiate a search
11182 * using the "start-interactive-search" key binding.
11185 pspp_sheet_view_set_enable_search (PsppSheetView *tree_view,
11186 gboolean enable_search)
11188 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11190 enable_search = !!enable_search;
11192 if (tree_view->priv->enable_search != enable_search)
11194 tree_view->priv->enable_search = enable_search;
11195 g_object_notify (G_OBJECT (tree_view), "enable-search");
11200 * pspp_sheet_view_get_enable_search:
11201 * @tree_view: A #PsppSheetView
11203 * Returns whether or not the tree allows to start interactive searching
11204 * by typing in text.
11206 * Return value: whether or not to let the user search interactively
11209 pspp_sheet_view_get_enable_search (PsppSheetView *tree_view)
11211 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11213 return tree_view->priv->enable_search;
11218 * pspp_sheet_view_get_search_column:
11219 * @tree_view: A #PsppSheetView
11221 * Gets the column searched on by the interactive search code.
11223 * Return value: the column the interactive search code searches in.
11226 pspp_sheet_view_get_search_column (PsppSheetView *tree_view)
11228 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
11230 return (tree_view->priv->search_column);
11234 * pspp_sheet_view_set_search_column:
11235 * @tree_view: A #PsppSheetView
11236 * @column: the column of the model to search in, or -1 to disable searching
11238 * Sets @column as the column where the interactive search code should
11239 * search in for the current model.
11241 * If the search column is set, users can use the "start-interactive-search"
11242 * key binding to bring up search popup. The enable-search property controls
11243 * whether simply typing text will also start an interactive search.
11245 * Note that @column refers to a column of the current model. The search
11246 * column is reset to -1 when the model is changed.
11249 pspp_sheet_view_set_search_column (PsppSheetView *tree_view,
11252 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11253 g_return_if_fail (column >= -1);
11255 if (tree_view->priv->search_column == column)
11258 tree_view->priv->search_column = column;
11259 g_object_notify (G_OBJECT (tree_view), "search-column");
11263 * pspp_sheet_view_get_search_equal_func:
11264 * @tree_view: A #PsppSheetView
11266 * Returns the compare function currently in use.
11268 * Return value: the currently used compare function for the search code.
11271 PsppSheetViewSearchEqualFunc
11272 pspp_sheet_view_get_search_equal_func (PsppSheetView *tree_view)
11274 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11276 return tree_view->priv->search_equal_func;
11280 * pspp_sheet_view_set_search_equal_func:
11281 * @tree_view: A #PsppSheetView
11282 * @search_equal_func: the compare function to use during the search
11283 * @search_user_data: (allow-none): user data to pass to @search_equal_func, or %NULL
11284 * @search_destroy: (allow-none): Destroy notifier for @search_user_data, or %NULL
11286 * Sets the compare function for the interactive search capabilities; note
11287 * that somewhat like strcmp() returning 0 for equality
11288 * #PsppSheetViewSearchEqualFunc returns %FALSE on matches.
11291 pspp_sheet_view_set_search_equal_func (PsppSheetView *tree_view,
11292 PsppSheetViewSearchEqualFunc search_equal_func,
11293 gpointer search_user_data,
11294 GDestroyNotify search_destroy)
11296 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11297 g_return_if_fail (search_equal_func != NULL);
11299 if (tree_view->priv->search_destroy)
11300 tree_view->priv->search_destroy (tree_view->priv->search_user_data);
11302 tree_view->priv->search_equal_func = search_equal_func;
11303 tree_view->priv->search_user_data = search_user_data;
11304 tree_view->priv->search_destroy = search_destroy;
11305 if (tree_view->priv->search_equal_func == NULL)
11306 tree_view->priv->search_equal_func = pspp_sheet_view_search_equal_func;
11310 * pspp_sheet_view_get_search_entry:
11311 * @tree_view: A #PsppSheetView
11313 * Returns the #GtkEntry which is currently in use as interactive search
11314 * entry for @tree_view. In case the built-in entry is being used, %NULL
11315 * will be returned.
11317 * Return value: the entry currently in use as search entry.
11322 pspp_sheet_view_get_search_entry (PsppSheetView *tree_view)
11324 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11326 if (tree_view->priv->search_custom_entry_set)
11327 return GTK_ENTRY (tree_view->priv->search_entry);
11333 * pspp_sheet_view_set_search_entry:
11334 * @tree_view: A #PsppSheetView
11335 * @entry: (allow-none): the entry the interactive search code of @tree_view should use or %NULL
11337 * Sets the entry which the interactive search code will use for this
11338 * @tree_view. This is useful when you want to provide a search entry
11339 * in our interface at all time at a fixed position. Passing %NULL for
11340 * @entry will make the interactive search code use the built-in popup
11346 pspp_sheet_view_set_search_entry (PsppSheetView *tree_view,
11349 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11350 g_return_if_fail (entry == NULL || GTK_IS_ENTRY (entry));
11352 if (tree_view->priv->search_custom_entry_set)
11354 if (tree_view->priv->search_entry_changed_id)
11356 g_signal_handler_disconnect (tree_view->priv->search_entry,
11357 tree_view->priv->search_entry_changed_id);
11358 tree_view->priv->search_entry_changed_id = 0;
11360 g_signal_handlers_disconnect_by_func (tree_view->priv->search_entry,
11361 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11364 g_object_unref (tree_view->priv->search_entry);
11366 else if (tree_view->priv->search_window)
11368 gtk_widget_destroy (tree_view->priv->search_window);
11370 tree_view->priv->search_window = NULL;
11375 tree_view->priv->search_entry = g_object_ref (entry);
11376 tree_view->priv->search_custom_entry_set = TRUE;
11378 if (tree_view->priv->search_entry_changed_id == 0)
11380 tree_view->priv->search_entry_changed_id =
11381 g_signal_connect (tree_view->priv->search_entry, "changed",
11382 G_CALLBACK (pspp_sheet_view_search_init),
11386 g_signal_connect (tree_view->priv->search_entry, "key-press-event",
11387 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11390 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
11394 tree_view->priv->search_entry = NULL;
11395 tree_view->priv->search_custom_entry_set = FALSE;
11400 * pspp_sheet_view_set_search_position_func:
11401 * @tree_view: A #PsppSheetView
11402 * @func: (allow-none): the function to use to position the search dialog, or %NULL
11403 * to use the default search position function
11404 * @data: (allow-none): user data to pass to @func, or %NULL
11405 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11407 * Sets the function to use when positioning the search dialog.
11412 pspp_sheet_view_set_search_position_func (PsppSheetView *tree_view,
11413 PsppSheetViewSearchPositionFunc func,
11414 gpointer user_data,
11415 GDestroyNotify destroy)
11417 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11419 if (tree_view->priv->search_position_destroy)
11420 tree_view->priv->search_position_destroy (tree_view->priv->search_position_user_data);
11422 tree_view->priv->search_position_func = func;
11423 tree_view->priv->search_position_user_data = user_data;
11424 tree_view->priv->search_position_destroy = destroy;
11425 if (tree_view->priv->search_position_func == NULL)
11426 tree_view->priv->search_position_func = pspp_sheet_view_search_position_func;
11430 * pspp_sheet_view_get_search_position_func:
11431 * @tree_view: A #PsppSheetView
11433 * Returns the positioning function currently in use.
11435 * Return value: the currently used function for positioning the search dialog.
11439 PsppSheetViewSearchPositionFunc
11440 pspp_sheet_view_get_search_position_func (PsppSheetView *tree_view)
11442 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11444 return tree_view->priv->search_position_func;
11449 pspp_sheet_view_search_dialog_hide (GtkWidget *search_dialog,
11450 PsppSheetView *tree_view)
11452 if (tree_view->priv->disable_popdown)
11455 if (tree_view->priv->search_entry_changed_id)
11457 g_signal_handler_disconnect (tree_view->priv->search_entry,
11458 tree_view->priv->search_entry_changed_id);
11459 tree_view->priv->search_entry_changed_id = 0;
11461 if (tree_view->priv->typeselect_flush_timeout)
11463 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11464 tree_view->priv->typeselect_flush_timeout = 0;
11467 if (gtk_widget_get_visible (search_dialog))
11469 /* send focus-in event */
11470 send_focus_change (GTK_WIDGET (tree_view->priv->search_entry), FALSE);
11471 gtk_widget_hide (search_dialog);
11472 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
11473 send_focus_change (GTK_WIDGET (tree_view), TRUE);
11478 pspp_sheet_view_search_position_func (PsppSheetView *tree_view,
11479 GtkWidget *search_dialog,
11480 gpointer user_data)
11483 gint tree_x, tree_y;
11484 gint tree_width, tree_height;
11485 GdkWindow *tree_window = GTK_WIDGET (tree_view)->window;
11486 GdkScreen *screen = gdk_drawable_get_screen (tree_window);
11487 GtkRequisition requisition;
11489 GdkRectangle monitor;
11491 monitor_num = gdk_screen_get_monitor_at_window (screen, tree_window);
11492 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
11494 gtk_widget_realize (search_dialog);
11496 gdk_window_get_origin (tree_window, &tree_x, &tree_y);
11497 gdk_drawable_get_size (tree_window,
11500 gtk_widget_size_request (search_dialog, &requisition);
11502 if (tree_x + tree_width > gdk_screen_get_width (screen))
11503 x = gdk_screen_get_width (screen) - requisition.width;
11504 else if (tree_x + tree_width - requisition.width < 0)
11507 x = tree_x + tree_width - requisition.width;
11509 if (tree_y + tree_height + requisition.height > gdk_screen_get_height (screen))
11510 y = gdk_screen_get_height (screen) - requisition.height;
11511 else if (tree_y + tree_height < 0) /* isn't really possible ... */
11514 y = tree_y + tree_height;
11516 gtk_window_move (GTK_WINDOW (search_dialog), x, y);
11520 pspp_sheet_view_search_disable_popdown (GtkEntry *entry,
11524 PsppSheetView *tree_view = (PsppSheetView *)data;
11526 tree_view->priv->disable_popdown = 1;
11527 g_signal_connect (menu, "hide",
11528 G_CALLBACK (pspp_sheet_view_search_enable_popdown), data);
11531 /* Because we're visible but offscreen, we just set a flag in the preedit
11535 pspp_sheet_view_search_preedit_changed (GtkIMContext *im_context,
11536 PsppSheetView *tree_view)
11538 tree_view->priv->imcontext_changed = 1;
11539 if (tree_view->priv->typeselect_flush_timeout)
11541 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11542 tree_view->priv->typeselect_flush_timeout =
11543 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11544 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11551 pspp_sheet_view_search_activate (GtkEntry *entry,
11552 PsppSheetView *tree_view)
11557 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window,
11560 /* If we have a row selected and it's the cursor row, we activate
11562 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
11564 path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
11566 _pspp_sheet_view_find_node (tree_view, path, &node);
11568 if (node >= 0 && pspp_sheet_view_node_is_selected (tree_view, node))
11569 pspp_sheet_view_row_activated (tree_view, path, tree_view->priv->focus_column);
11571 gtk_tree_path_free (path);
11576 pspp_sheet_view_real_search_enable_popdown (gpointer data)
11578 PsppSheetView *tree_view = (PsppSheetView *)data;
11580 tree_view->priv->disable_popdown = 0;
11586 pspp_sheet_view_search_enable_popdown (GtkWidget *widget,
11589 gdk_threads_add_timeout_full (G_PRIORITY_HIGH, 200, pspp_sheet_view_real_search_enable_popdown, g_object_ref (data), g_object_unref);
11593 pspp_sheet_view_search_delete_event (GtkWidget *widget,
11594 GdkEventAny *event,
11595 PsppSheetView *tree_view)
11597 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11599 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11605 pspp_sheet_view_search_button_press_event (GtkWidget *widget,
11606 GdkEventButton *event,
11607 PsppSheetView *tree_view)
11609 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11611 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11613 if (event->window == tree_view->priv->bin_window)
11614 pspp_sheet_view_button_press (GTK_WIDGET (tree_view), event);
11620 pspp_sheet_view_search_scroll_event (GtkWidget *widget,
11621 GdkEventScroll *event,
11622 PsppSheetView *tree_view)
11624 gboolean retval = FALSE;
11626 if (event->direction == GDK_SCROLL_UP)
11628 pspp_sheet_view_search_move (widget, tree_view, TRUE);
11631 else if (event->direction == GDK_SCROLL_DOWN)
11633 pspp_sheet_view_search_move (widget, tree_view, FALSE);
11637 /* renew the flush timeout */
11638 if (retval && tree_view->priv->typeselect_flush_timeout
11639 && !tree_view->priv->search_custom_entry_set)
11641 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11642 tree_view->priv->typeselect_flush_timeout =
11643 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11644 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11652 pspp_sheet_view_search_key_press_event (GtkWidget *widget,
11653 GdkEventKey *event,
11654 PsppSheetView *tree_view)
11656 gboolean retval = FALSE;
11658 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11659 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11661 /* close window and cancel the search */
11662 if (!tree_view->priv->search_custom_entry_set
11663 && (event->keyval == GDK_Escape ||
11664 event->keyval == GDK_Tab ||
11665 event->keyval == GDK_KP_Tab ||
11666 event->keyval == GDK_ISO_Left_Tab))
11668 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11672 /* select previous matching iter */
11673 if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up)
11675 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
11676 gtk_widget_error_bell (widget);
11681 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK))
11682 && (event->keyval == GDK_g || event->keyval == GDK_G))
11684 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
11685 gtk_widget_error_bell (widget);
11690 /* select next matching iter */
11691 if (event->keyval == GDK_Down || event->keyval == GDK_KP_Down)
11693 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
11694 gtk_widget_error_bell (widget);
11699 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == GTK_DEFAULT_ACCEL_MOD_MASK)
11700 && (event->keyval == GDK_g || event->keyval == GDK_G))
11702 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
11703 gtk_widget_error_bell (widget);
11708 /* renew the flush timeout */
11709 if (retval && tree_view->priv->typeselect_flush_timeout
11710 && !tree_view->priv->search_custom_entry_set)
11712 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11713 tree_view->priv->typeselect_flush_timeout =
11714 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11715 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11722 /* this function returns FALSE if there is a search string but
11723 * nothing was found, and TRUE otherwise.
11726 pspp_sheet_view_search_move (GtkWidget *window,
11727 PsppSheetView *tree_view,
11735 GtkTreeModel *model;
11736 PsppSheetSelection *selection;
11738 text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
11740 g_return_val_if_fail (text != NULL, FALSE);
11742 len = strlen (text);
11744 if (up && tree_view->priv->selected_iter == 1)
11745 return strlen (text) < 1;
11747 len = strlen (text);
11752 model = pspp_sheet_view_get_model (tree_view);
11753 selection = pspp_sheet_view_get_selection (tree_view);
11756 pspp_sheet_selection_unselect_all (selection);
11757 if (!gtk_tree_model_get_iter_first (model, &iter))
11760 ret = pspp_sheet_view_search_iter (model, selection, &iter, text,
11761 &count, up?((tree_view->priv->selected_iter) - 1):((tree_view->priv->selected_iter + 1)));
11766 tree_view->priv->selected_iter += up?(-1):(1);
11771 /* return to old iter */
11773 gtk_tree_model_get_iter_first (model, &iter);
11774 pspp_sheet_view_search_iter (model, selection,
11776 &count, tree_view->priv->selected_iter);
11782 pspp_sheet_view_search_equal_func (GtkTreeModel *model,
11786 gpointer search_data)
11788 gboolean retval = TRUE;
11790 gchar *normalized_string;
11791 gchar *normalized_key;
11792 gchar *case_normalized_string = NULL;
11793 gchar *case_normalized_key = NULL;
11794 GValue value = {0,};
11795 GValue transformed = {0,};
11797 gtk_tree_model_get_value (model, iter, column, &value);
11799 g_value_init (&transformed, G_TYPE_STRING);
11801 if (!g_value_transform (&value, &transformed))
11803 g_value_unset (&value);
11807 g_value_unset (&value);
11809 str = g_value_get_string (&transformed);
11812 g_value_unset (&transformed);
11816 normalized_string = g_utf8_normalize (str, -1, G_NORMALIZE_ALL);
11817 normalized_key = g_utf8_normalize (key, -1, G_NORMALIZE_ALL);
11819 if (normalized_string && normalized_key)
11821 case_normalized_string = g_utf8_casefold (normalized_string, -1);
11822 case_normalized_key = g_utf8_casefold (normalized_key, -1);
11824 if (strncmp (case_normalized_key, case_normalized_string, strlen (case_normalized_key)) == 0)
11828 g_value_unset (&transformed);
11829 g_free (normalized_key);
11830 g_free (normalized_string);
11831 g_free (case_normalized_key);
11832 g_free (case_normalized_string);
11838 pspp_sheet_view_search_iter (GtkTreeModel *model,
11839 PsppSheetSelection *selection,
11848 PsppSheetView *tree_view = pspp_sheet_selection_get_tree_view (selection);
11850 path = gtk_tree_model_get_path (model, iter);
11851 _pspp_sheet_view_find_node (tree_view, path, &node);
11855 gboolean done = FALSE;
11857 if (! tree_view->priv->search_equal_func (model, tree_view->priv->search_column, text, iter, tree_view->priv->search_user_data))
11862 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL,
11864 pspp_sheet_selection_select_iter (selection, iter);
11865 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE);
11868 gtk_tree_path_free (path);
11877 node = pspp_sheet_view_node_next (tree_view, node);
11883 has_next = gtk_tree_model_iter_next (model, iter);
11886 gtk_tree_path_next (path);
11889 TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
11894 gtk_tree_path_free (path);
11896 /* we've run out of tree, done with this func */
11908 pspp_sheet_view_search_init (GtkWidget *entry,
11909 PsppSheetView *tree_view)
11915 GtkTreeModel *model;
11916 PsppSheetSelection *selection;
11918 g_return_if_fail (GTK_IS_ENTRY (entry));
11919 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11921 text = gtk_entry_get_text (GTK_ENTRY (entry));
11923 model = pspp_sheet_view_get_model (tree_view);
11924 selection = pspp_sheet_view_get_selection (tree_view);
11927 pspp_sheet_selection_unselect_all (selection);
11928 if (tree_view->priv->typeselect_flush_timeout
11929 && !tree_view->priv->search_custom_entry_set)
11931 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11932 tree_view->priv->typeselect_flush_timeout =
11933 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11934 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11941 if (!gtk_tree_model_get_iter_first (model, &iter))
11944 ret = pspp_sheet_view_search_iter (model, selection,
11949 tree_view->priv->selected_iter = 1;
11953 pspp_sheet_view_remove_widget (GtkCellEditable *cell_editable,
11954 PsppSheetView *tree_view)
11956 if (tree_view->priv->edited_column == NULL)
11959 _pspp_sheet_view_column_stop_editing (tree_view->priv->edited_column);
11960 tree_view->priv->edited_column = NULL;
11962 if (gtk_widget_has_focus (GTK_WIDGET (cell_editable)))
11963 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
11965 g_signal_handlers_disconnect_by_func (cell_editable,
11966 pspp_sheet_view_remove_widget,
11968 g_signal_handlers_disconnect_by_func (cell_editable,
11969 pspp_sheet_view_editable_button_press_event,
11971 g_signal_handlers_disconnect_by_func (cell_editable,
11972 pspp_sheet_view_editable_clicked,
11975 gtk_container_remove (GTK_CONTAINER (tree_view),
11976 GTK_WIDGET (cell_editable));
11978 /* FIXME should only redraw a single node */
11979 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
11983 pspp_sheet_view_start_editing (PsppSheetView *tree_view,
11984 GtkTreePath *cursor_path)
11987 GdkRectangle background_area;
11988 GdkRectangle cell_area;
11989 GtkCellEditable *editable_widget = NULL;
11990 gchar *path_string;
11991 guint flags = 0; /* can be 0, as the flags are primarily for rendering */
11992 gint retval = FALSE;
11995 g_assert (tree_view->priv->focus_column);
11997 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
12000 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
12001 if (cursor_node < 0)
12004 path_string = gtk_tree_path_to_string (cursor_path);
12005 gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path);
12007 pspp_sheet_view_column_cell_set_cell_data (tree_view->priv->focus_column,
12008 tree_view->priv->model,
12010 pspp_sheet_view_get_background_area (tree_view,
12012 tree_view->priv->focus_column,
12014 pspp_sheet_view_get_cell_area (tree_view,
12016 tree_view->priv->focus_column,
12019 if (_pspp_sheet_view_column_cell_event (tree_view->priv->focus_column,
12028 if (editable_widget != NULL)
12032 GtkCellRenderer *cell;
12035 cell = _pspp_sheet_view_column_get_edited_cell (tree_view->priv->focus_column);
12037 _pspp_sheet_view_column_get_neighbor_sizes (tree_view->priv->focus_column, cell, &left, &right);
12040 area.width -= right + left;
12042 pspp_sheet_view_real_start_editing (tree_view,
12043 tree_view->priv->focus_column,
12052 g_free (path_string);
12057 pspp_sheet_view_editable_button_press_event (GtkWidget *widget,
12058 GdkEventButton *event,
12059 PsppSheetView *sheet_view)
12063 node = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
12064 "pspp-sheet-view-node"));
12065 return pspp_sheet_view_row_head_clicked (sheet_view,
12067 sheet_view->priv->edited_column,
12072 pspp_sheet_view_editable_clicked (GtkButton *button,
12073 PsppSheetView *sheet_view)
12075 pspp_sheet_view_editable_button_press_event (GTK_WIDGET (button), NULL,
12080 is_all_selected (GtkWidget *widget)
12082 GtkEntryBuffer *buffer;
12083 gint start_pos, end_pos;
12085 if (!GTK_IS_ENTRY (widget))
12088 buffer = gtk_entry_get_buffer (GTK_ENTRY (widget));
12089 return (gtk_editable_get_selection_bounds (GTK_EDITABLE (widget),
12090 &start_pos, &end_pos)
12092 && end_pos == gtk_entry_buffer_get_length (buffer));
12096 is_at_left (GtkWidget *widget)
12098 return (GTK_IS_ENTRY (widget)
12099 && gtk_editable_get_position (GTK_EDITABLE (widget)) == 0);
12103 is_at_right (GtkWidget *widget)
12105 GtkEntryBuffer *buffer;
12108 if (!GTK_IS_ENTRY (widget))
12111 buffer = gtk_entry_get_buffer (GTK_ENTRY (widget));
12112 length = gtk_entry_buffer_get_length (buffer);
12113 return gtk_editable_get_position (GTK_EDITABLE (widget)) == length;
12117 pspp_sheet_view_event (GtkWidget *widget,
12118 GdkEventKey *event,
12119 PsppSheetView *tree_view)
12121 PsppSheetViewColumn *column;
12129 /* Intercept only key press events.
12130 It would make sense to use "key-press-event" instead of "event", but
12131 GtkEntry attaches its own signal handler to "key-press-event" that runs
12132 before ours and overrides our desired behavior for GDK_Up and GDK_Down.
12134 if (event->type != GDK_KEY_PRESS)
12137 if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK | GDK_MOD1_MASK))
12139 /* Pass through most keys that include modifiers. */
12140 if ((event->keyval == GDK_Tab || event->keyval == GDK_ISO_Left_Tab)
12141 && !(event->state & (GDK_CONTROL_MASK | GDK_MOD1_MASK)))
12143 /* Special case for Shift-Tab. */
12149 keyval = event->keyval;
12150 state = event->state & ~(GDK_CONTROL_MASK | GDK_SHIFT_MASK | GDK_MOD1_MASK);
12152 switch (event->keyval)
12154 case GDK_Left: case GDK_KP_Left:
12155 if (!is_all_selected (widget) && !is_at_left (widget))
12159 case GDK_Right: case GDK_KP_Right:
12160 if (!is_all_selected (widget) && !is_at_right (widget))
12164 case GDK_Up: case GDK_KP_Up:
12165 case GDK_Down: case GDK_KP_Down:
12168 case GDK_Page_Up: case GDK_KP_Page_Up:
12169 case GDK_Page_Down: case GDK_KP_Page_Down:
12181 case GDK_ISO_Left_Tab:
12182 keyval = event->state & GDK_SHIFT_MASK ? GDK_Left : GDK_Right;
12189 row = tree_view->priv->edited_row;
12190 column = tree_view->priv->edited_column;
12191 path = gtk_tree_path_new_from_indices (row, -1);
12193 pspp_sheet_view_stop_editing (tree_view, cancel);
12194 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
12196 pspp_sheet_view_set_cursor (tree_view, path, column, FALSE);
12197 gtk_tree_path_free (path);
12199 handled = gtk_binding_set_activate (edit_bindings, keyval, state,
12200 GTK_OBJECT (tree_view));
12202 g_signal_stop_emission_by_name (widget, "event");
12204 pspp_sheet_view_get_cursor (tree_view, &path, NULL);
12205 pspp_sheet_view_start_editing (tree_view, path);
12206 gtk_tree_path_free (path);
12212 pspp_sheet_view_override_cell_keypresses (GtkWidget *widget,
12215 PsppSheetView *sheet_view = data;
12217 g_signal_connect (widget, "event",
12218 G_CALLBACK (pspp_sheet_view_event),
12221 if (GTK_IS_CONTAINER (widget))
12222 gtk_container_foreach (GTK_CONTAINER (widget),
12223 pspp_sheet_view_override_cell_keypresses,
12228 pspp_sheet_view_real_start_editing (PsppSheetView *tree_view,
12229 PsppSheetViewColumn *column,
12231 GtkCellEditable *cell_editable,
12232 GdkRectangle *cell_area,
12236 PsppSheetSelectionMode mode = pspp_sheet_selection_get_mode (tree_view->priv->selection);
12237 gint pre_val = tree_view->priv->vadjustment->value;
12238 GtkRequisition requisition;
12241 g_return_if_fail (gtk_tree_path_get_depth (path) == 1);
12243 tree_view->priv->edited_column = column;
12244 _pspp_sheet_view_column_start_editing (column, GTK_CELL_EDITABLE (cell_editable));
12246 row = gtk_tree_path_get_indices (path)[0];
12247 tree_view->priv->edited_row = row;
12248 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE);
12249 cell_area->y += pre_val - (int)tree_view->priv->vadjustment->value;
12251 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
12252 pspp_sheet_selection_select_column (tree_view->priv->selection, column);
12253 tree_view->priv->anchor_column = column;
12255 gtk_widget_size_request (GTK_WIDGET (cell_editable), &requisition);
12257 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
12259 if (requisition.height < cell_area->height)
12261 gint diff = cell_area->height - requisition.height;
12262 pspp_sheet_view_put (tree_view,
12263 GTK_WIDGET (cell_editable),
12264 cell_area->x, cell_area->y + diff/2,
12265 cell_area->width, requisition.height);
12269 pspp_sheet_view_put (tree_view,
12270 GTK_WIDGET (cell_editable),
12271 cell_area->x, cell_area->y,
12272 cell_area->width, cell_area->height);
12275 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (cell_editable),
12276 (GdkEvent *)event);
12278 gtk_widget_grab_focus (GTK_WIDGET (cell_editable));
12279 g_signal_connect (cell_editable, "remove-widget",
12280 G_CALLBACK (pspp_sheet_view_remove_widget), tree_view);
12281 if (mode == PSPP_SHEET_SELECTION_RECTANGLE && column->row_head &&
12282 GTK_IS_BUTTON (cell_editable))
12284 g_signal_connect (cell_editable, "button-press-event",
12285 G_CALLBACK (pspp_sheet_view_editable_button_press_event),
12287 g_object_set_data (G_OBJECT (cell_editable), "pspp-sheet-view-node",
12288 GINT_TO_POINTER (row));
12289 g_signal_connect (cell_editable, "clicked",
12290 G_CALLBACK (pspp_sheet_view_editable_clicked),
12294 pspp_sheet_view_override_cell_keypresses (GTK_WIDGET (cell_editable),
12299 pspp_sheet_view_stop_editing (PsppSheetView *tree_view,
12300 gboolean cancel_editing)
12302 PsppSheetViewColumn *column;
12303 GtkCellRenderer *cell;
12305 if (tree_view->priv->edited_column == NULL)
12309 * This is very evil. We need to do this, because
12310 * gtk_cell_editable_editing_done may trigger pspp_sheet_view_row_changed
12311 * later on. If pspp_sheet_view_row_changed notices
12312 * tree_view->priv->edited_column != NULL, it'll call
12313 * pspp_sheet_view_stop_editing again. Bad things will happen then.
12315 * Please read that again if you intend to modify anything here.
12318 column = tree_view->priv->edited_column;
12319 tree_view->priv->edited_column = NULL;
12321 cell = _pspp_sheet_view_column_get_edited_cell (column);
12322 gtk_cell_renderer_stop_editing (cell, cancel_editing);
12324 if (!cancel_editing)
12325 gtk_cell_editable_editing_done (column->editable_widget);
12327 tree_view->priv->edited_column = column;
12329 gtk_cell_editable_remove_widget (column->editable_widget);
12334 * pspp_sheet_view_set_hover_selection:
12335 * @tree_view: a #PsppSheetView
12336 * @hover: %TRUE to enable hover selection mode
12338 * Enables of disables the hover selection mode of @tree_view.
12339 * Hover selection makes the selected row follow the pointer.
12340 * Currently, this works only for the selection modes
12341 * %PSPP_SHEET_SELECTION_SINGLE and %PSPP_SHEET_SELECTION_BROWSE.
12346 pspp_sheet_view_set_hover_selection (PsppSheetView *tree_view,
12349 hover = hover != FALSE;
12351 if (hover != tree_view->priv->hover_selection)
12353 tree_view->priv->hover_selection = hover;
12355 g_object_notify (G_OBJECT (tree_view), "hover-selection");
12360 * pspp_sheet_view_get_hover_selection:
12361 * @tree_view: a #PsppSheetView
12363 * Returns whether hover selection mode is turned on for @tree_view.
12365 * Return value: %TRUE if @tree_view is in hover selection mode
12370 pspp_sheet_view_get_hover_selection (PsppSheetView *tree_view)
12372 return tree_view->priv->hover_selection;
12376 * pspp_sheet_view_set_rubber_banding:
12377 * @tree_view: a #PsppSheetView
12378 * @enable: %TRUE to enable rubber banding
12380 * Enables or disables rubber banding in @tree_view. If the selection mode is
12381 * #PSPP_SHEET_SELECTION_MULTIPLE or #PSPP_SHEET_SELECTION_RECTANGLE, rubber
12382 * banding will allow the user to select multiple rows by dragging the mouse.
12387 pspp_sheet_view_set_rubber_banding (PsppSheetView *tree_view,
12390 enable = enable != FALSE;
12392 if (enable != tree_view->priv->rubber_banding_enable)
12394 tree_view->priv->rubber_banding_enable = enable;
12396 g_object_notify (G_OBJECT (tree_view), "rubber-banding");
12401 * pspp_sheet_view_get_rubber_banding:
12402 * @tree_view: a #PsppSheetView
12404 * Returns whether rubber banding is turned on for @tree_view. If the
12405 * selection mode is #PSPP_SHEET_SELECTION_MULTIPLE or
12406 * #PSPP_SHEET_SELECTION_RECTANGLE, rubber banding will allow the user to
12407 * select multiple rows by dragging the mouse.
12409 * Return value: %TRUE if rubber banding in @tree_view is enabled.
12414 pspp_sheet_view_get_rubber_banding (PsppSheetView *tree_view)
12416 return tree_view->priv->rubber_banding_enable;
12420 * pspp_sheet_view_is_rubber_banding_active:
12421 * @tree_view: a #PsppSheetView
12423 * Returns whether a rubber banding operation is currently being done
12426 * Return value: %TRUE if a rubber banding operation is currently being
12427 * done in @tree_view.
12432 pspp_sheet_view_is_rubber_banding_active (PsppSheetView *tree_view)
12434 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
12436 if (tree_view->priv->rubber_banding_enable
12437 && tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
12444 pspp_sheet_view_grab_notify (GtkWidget *widget,
12445 gboolean was_grabbed)
12447 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12449 tree_view->priv->in_grab = !was_grabbed;
12453 tree_view->priv->pressed_button = -1;
12455 if (tree_view->priv->rubber_band_status)
12456 pspp_sheet_view_stop_rubber_band (tree_view);
12461 pspp_sheet_view_state_changed (GtkWidget *widget,
12462 GtkStateType previous_state)
12464 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12466 if (gtk_widget_get_realized (widget))
12468 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
12469 gdk_window_set_background (tree_view->priv->bin_window, &widget->style->base[widget->state]);
12472 gtk_widget_queue_draw (widget);
12476 * pspp_sheet_view_get_grid_lines:
12477 * @tree_view: a #PsppSheetView
12479 * Returns which grid lines are enabled in @tree_view.
12481 * Return value: a #PsppSheetViewGridLines value indicating which grid lines
12486 PsppSheetViewGridLines
12487 pspp_sheet_view_get_grid_lines (PsppSheetView *tree_view)
12489 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12491 return tree_view->priv->grid_lines;
12495 * pspp_sheet_view_set_grid_lines:
12496 * @tree_view: a #PsppSheetView
12497 * @grid_lines: a #PsppSheetViewGridLines value indicating which grid lines to
12500 * Sets which grid lines to draw in @tree_view.
12505 pspp_sheet_view_set_grid_lines (PsppSheetView *tree_view,
12506 PsppSheetViewGridLines grid_lines)
12508 PsppSheetViewPrivate *priv;
12510 PsppSheetViewGridLines old_grid_lines;
12512 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12514 priv = tree_view->priv;
12515 widget = GTK_WIDGET (tree_view);
12517 old_grid_lines = priv->grid_lines;
12518 priv->grid_lines = grid_lines;
12520 if (old_grid_lines != grid_lines)
12522 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12524 g_object_notify (G_OBJECT (tree_view), "enable-grid-lines");
12529 * pspp_sheet_view_get_special_cells:
12530 * @tree_view: a #PsppSheetView
12532 * Returns which grid lines are enabled in @tree_view.
12534 * Return value: a #PsppSheetViewSpecialCells value indicating whether rows in
12535 * the sheet view contain special cells.
12537 PsppSheetViewSpecialCells
12538 pspp_sheet_view_get_special_cells (PsppSheetView *tree_view)
12540 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12542 return tree_view->priv->special_cells;
12546 * pspp_sheet_view_set_special_cells:
12547 * @tree_view: a #PsppSheetView
12548 * @special_cells: a #PsppSheetViewSpecialCells value indicating whether rows in
12549 * the sheet view contain special cells.
12551 * Sets whether rows in the sheet view contain special cells, controlling the
12552 * rendering of row selections.
12555 pspp_sheet_view_set_special_cells (PsppSheetView *tree_view,
12556 PsppSheetViewSpecialCells special_cells)
12558 PsppSheetViewPrivate *priv;
12560 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12562 priv = tree_view->priv;
12564 if (priv->special_cells != special_cells)
12566 priv->special_cells = special_cells;
12567 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12568 g_object_notify (G_OBJECT (tree_view), "special-cells");
12573 pspp_sheet_view_get_fixed_height (const PsppSheetView *tree_view)
12575 /* XXX (re)calculate fixed_height if necessary */
12576 return tree_view->priv->fixed_height;
12580 pspp_sheet_view_set_fixed_height (PsppSheetView *tree_view,
12583 g_return_if_fail (fixed_height > 0);
12585 if (tree_view->priv->fixed_height != fixed_height)
12587 tree_view->priv->fixed_height = fixed_height;
12588 g_object_notify (G_OBJECT (tree_view), "fixed-height");
12590 if (!tree_view->priv->fixed_height_set)
12592 tree_view->priv->fixed_height_set = TRUE;
12593 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
12598 * pspp_sheet_view_set_tooltip_row:
12599 * @tree_view: a #PsppSheetView
12600 * @tooltip: a #GtkTooltip
12601 * @path: a #GtkTreePath
12603 * Sets the tip area of @tooltip to be the area covered by the row at @path.
12604 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
12605 * See also gtk_tooltip_set_tip_area().
12610 pspp_sheet_view_set_tooltip_row (PsppSheetView *tree_view,
12611 GtkTooltip *tooltip,
12614 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12615 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
12617 pspp_sheet_view_set_tooltip_cell (tree_view, tooltip, path, NULL, NULL);
12621 * pspp_sheet_view_set_tooltip_cell:
12622 * @tree_view: a #PsppSheetView
12623 * @tooltip: a #GtkTooltip
12624 * @path: (allow-none): a #GtkTreePath or %NULL
12625 * @column: (allow-none): a #PsppSheetViewColumn or %NULL
12626 * @cell: (allow-none): a #GtkCellRenderer or %NULL
12628 * Sets the tip area of @tooltip to the area @path, @column and @cell have
12629 * in common. For example if @path is %NULL and @column is set, the tip
12630 * area will be set to the full area covered by @column. See also
12631 * gtk_tooltip_set_tip_area().
12633 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
12638 pspp_sheet_view_set_tooltip_cell (PsppSheetView *tree_view,
12639 GtkTooltip *tooltip,
12641 PsppSheetViewColumn *column,
12642 GtkCellRenderer *cell)
12646 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12647 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
12648 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
12649 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
12651 /* Determine x values. */
12652 if (column && cell)
12657 pspp_sheet_view_get_cell_area (tree_view, path, column, &tmp);
12658 pspp_sheet_view_column_cell_get_position (column, cell, &start, &width);
12660 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12663 rect.width = width;
12669 pspp_sheet_view_get_background_area (tree_view, NULL, column, &tmp);
12670 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12673 rect.width = tmp.width;
12678 rect.width = GTK_WIDGET (tree_view)->allocation.width;
12681 /* Determine y values. */
12686 pspp_sheet_view_get_background_area (tree_view, path, NULL, &tmp);
12687 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12690 rect.height = tmp.height;
12695 rect.height = tree_view->priv->vadjustment->page_size;
12698 gtk_tooltip_set_tip_area (tooltip, &rect);
12702 * pspp_sheet_view_get_tooltip_context:
12703 * @tree_view: a #PsppSheetView
12704 * @x: the x coordinate (relative to widget coordinates)
12705 * @y: the y coordinate (relative to widget coordinates)
12706 * @keyboard_tip: whether this is a keyboard tooltip or not
12707 * @model: (allow-none): a pointer to receive a #GtkTreeModel or %NULL
12708 * @path: (allow-none): a pointer to receive a #GtkTreePath or %NULL
12709 * @iter: (allow-none): a pointer to receive a #GtkTreeIter or %NULL
12711 * This function is supposed to be used in a #GtkWidget::query-tooltip
12712 * signal handler for #PsppSheetView. The @x, @y and @keyboard_tip values
12713 * which are received in the signal handler, should be passed to this
12714 * function without modification.
12716 * The return value indicates whether there is a tree view row at the given
12717 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
12718 * tooltips the row returned will be the cursor row. When %TRUE, then any of
12719 * @model, @path and @iter which have been provided will be set to point to
12720 * that row and the corresponding model. @x and @y will always be converted
12721 * to be relative to @tree_view's bin_window if @keyboard_tooltip is %FALSE.
12723 * Return value: whether or not the given tooltip context points to a row.
12728 pspp_sheet_view_get_tooltip_context (PsppSheetView *tree_view,
12731 gboolean keyboard_tip,
12732 GtkTreeModel **model,
12733 GtkTreePath **path,
12736 GtkTreePath *tmppath = NULL;
12738 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
12739 g_return_val_if_fail (x != NULL, FALSE);
12740 g_return_val_if_fail (y != NULL, FALSE);
12744 pspp_sheet_view_get_cursor (tree_view, &tmppath, NULL);
12751 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, *x, *y,
12754 if (!pspp_sheet_view_get_path_at_pos (tree_view, *x, *y,
12755 &tmppath, NULL, NULL, NULL))
12760 *model = pspp_sheet_view_get_model (tree_view);
12763 gtk_tree_model_get_iter (pspp_sheet_view_get_model (tree_view),
12769 gtk_tree_path_free (tmppath);
12775 pspp_sheet_view_set_tooltip_query_cb (GtkWidget *widget,
12778 gboolean keyboard_tip,
12779 GtkTooltip *tooltip,
12782 GValue value = { 0, };
12783 GValue transformed = { 0, };
12786 GtkTreeModel *model;
12787 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12789 if (!pspp_sheet_view_get_tooltip_context (PSPP_SHEET_VIEW (widget),
12792 &model, &path, &iter))
12795 gtk_tree_model_get_value (model, &iter,
12796 tree_view->priv->tooltip_column, &value);
12798 g_value_init (&transformed, G_TYPE_STRING);
12800 if (!g_value_transform (&value, &transformed))
12802 g_value_unset (&value);
12803 gtk_tree_path_free (path);
12808 g_value_unset (&value);
12810 if (!g_value_get_string (&transformed))
12812 g_value_unset (&transformed);
12813 gtk_tree_path_free (path);
12818 gtk_tooltip_set_markup (tooltip, g_value_get_string (&transformed));
12819 pspp_sheet_view_set_tooltip_row (tree_view, tooltip, path);
12821 gtk_tree_path_free (path);
12822 g_value_unset (&transformed);
12828 * pspp_sheet_view_set_tooltip_column:
12829 * @tree_view: a #PsppSheetView
12830 * @column: an integer, which is a valid column number for @tree_view's model
12832 * If you only plan to have simple (text-only) tooltips on full rows, you
12833 * can use this function to have #PsppSheetView handle these automatically
12834 * for you. @column should be set to the column in @tree_view's model
12835 * containing the tooltip texts, or -1 to disable this feature.
12837 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
12838 * @tree_view will connect a #GtkWidget::query-tooltip signal handler.
12840 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
12841 * so &, <, etc have to be escaped in the text.
12846 pspp_sheet_view_set_tooltip_column (PsppSheetView *tree_view,
12849 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12851 if (column == tree_view->priv->tooltip_column)
12856 g_signal_handlers_disconnect_by_func (tree_view,
12857 pspp_sheet_view_set_tooltip_query_cb,
12859 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), FALSE);
12863 if (tree_view->priv->tooltip_column == -1)
12865 g_signal_connect (tree_view, "query-tooltip",
12866 G_CALLBACK (pspp_sheet_view_set_tooltip_query_cb), NULL);
12867 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), TRUE);
12871 tree_view->priv->tooltip_column = column;
12872 g_object_notify (G_OBJECT (tree_view), "tooltip-column");
12876 * pspp_sheet_view_get_tooltip_column:
12877 * @tree_view: a #PsppSheetView
12879 * Returns the column of @tree_view's model which is being used for
12880 * displaying tooltips on @tree_view's rows.
12882 * Return value: the index of the tooltip column that is currently being
12883 * used, or -1 if this is disabled.
12888 pspp_sheet_view_get_tooltip_column (PsppSheetView *tree_view)
12890 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12892 return tree_view->priv->tooltip_column;
12896 _gtk_boolean_handled_accumulator (GSignalInvocationHint *ihint,
12897 GValue *return_accu,
12898 const GValue *handler_return,
12901 gboolean continue_emission;
12902 gboolean signal_handled;
12904 signal_handled = g_value_get_boolean (handler_return);
12905 g_value_set_boolean (return_accu, signal_handled);
12906 continue_emission = !signal_handled;
12908 return continue_emission;
12912 pspp_sheet_view_grid_lines_get_type (void)
12914 static GType etype = 0;
12915 if (G_UNLIKELY(etype == 0)) {
12916 static const GEnumValue values[] = {
12917 { PSPP_SHEET_VIEW_GRID_LINES_NONE, "PSPP_SHEET_VIEW_GRID_LINES_NONE", "none" },
12918 { PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL, "PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL", "horizontal" },
12919 { PSPP_SHEET_VIEW_GRID_LINES_VERTICAL, "PSPP_SHEET_VIEW_GRID_LINES_VERTICAL", "vertical" },
12920 { PSPP_SHEET_VIEW_GRID_LINES_BOTH, "PSPP_SHEET_VIEW_GRID_LINES_BOTH", "both" },
12923 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewGridLines"), values);
12929 pspp_sheet_view_special_cells_get_type (void)
12931 static GType etype = 0;
12932 if (G_UNLIKELY(etype == 0)) {
12933 static const GEnumValue values[] = {
12934 { PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT, "PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT", "detect" },
12935 { PSPP_SHEET_VIEW_SPECIAL_CELLS_YES, "PSPP_SHEET_VIEW_SPECIAL_CELLS_YES", "yes" },
12936 { PSPP_SHEET_VIEW_SPECIAL_CELLS_NO, "PSPP_SHEET_VIEW_SPECIAL_CELLS_NO", "no" },
12939 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewSpecialCells"), values);