1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2011, 2012, 2013 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 * Copyright (C) 2000 Red Hat, Inc., Jonathan Blandford <jrb@redhat.com>
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Library General Public
22 * License as published by the Free Software Foundation; either
23 * version 2 of the License, or (at your option) any later version.
25 * This library is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 * Library General Public License for more details.
30 * You should have received a copy of the GNU Library General Public
31 * License along with this library; if not, write to the
32 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
33 * Boston, MA 02111-1307, USA.
38 #include "ui/gui/pspp-sheet-private.h"
42 #include <gdk/gdkkeysyms.h>
43 #include <gdk/gdkkeysyms-compat.h>
46 #include "ui/gui/psppire-marshal.h"
47 #include "ui/gui/pspp-sheet-selection.h"
49 #define P_(STRING) STRING
50 #define GTK_PARAM_READABLE G_PARAM_READABLE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
51 #define GTK_PARAM_READWRITE G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
53 /* Many keyboard shortcuts for Mac are the same as for X
54 * except they use Command key instead of Control (e.g. Cut,
55 * Copy, Paste). This symbol is for those simple cases. */
56 #ifndef GDK_WINDOWING_QUARTZ
57 #define GTK_DEFAULT_ACCEL_MOD_MASK GDK_CONTROL_MASK
59 #define GTK_DEFAULT_ACCEL_MOD_MASK GDK_META_MASK
62 #define PSPP_SHEET_VIEW_PRIORITY_VALIDATE (GDK_PRIORITY_REDRAW + 5)
63 #define PSPP_SHEET_VIEW_PRIORITY_SCROLL_SYNC (PSPP_SHEET_VIEW_PRIORITY_VALIDATE + 2)
64 #define PSPP_SHEET_VIEW_TIME_MS_PER_IDLE 30
65 #define SCROLL_EDGE_SIZE 15
66 #define EXPANDER_EXTRA_PADDING 4
67 #define PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT 5000
69 /* The "background" areas of all rows/cells add up to cover the entire tree.
70 * The background includes all inter-row and inter-cell spacing.
71 * The "cell" areas are the cell_area passed in to gtk_cell_renderer_render(),
72 * i.e. just the cells, no spacing.
75 #define BACKGROUND_HEIGHT(tree_view) (tree_view->priv->fixed_height)
76 #define CELL_HEIGHT(tree_view, separator) ((BACKGROUND_HEIGHT (tree_view)) - (separator))
78 /* Translate from bin_window coordinates to rbtree (tree coordinates) and
81 #define TREE_WINDOW_Y_TO_RBTREE_Y(tree_view,y) ((y) + tree_view->priv->dy)
82 #define RBTREE_Y_TO_TREE_WINDOW_Y(tree_view,y) ((y) - tree_view->priv->dy)
84 /* This is in bin_window coordinates */
85 #define BACKGROUND_FIRST_PIXEL(tree_view,node) (RBTREE_Y_TO_TREE_WINDOW_Y (tree_view, pspp_sheet_view_node_find_offset (tree_view, (node))))
86 #define CELL_FIRST_PIXEL(tree_view,node,separator) (BACKGROUND_FIRST_PIXEL (tree_view,node) + separator/2)
88 #define ROW_HEIGHT(tree_view) \
89 ((tree_view->priv->fixed_height > 0) ? (tree_view->priv->fixed_height) : (tree_view)->priv->expander_size)
92 typedef struct _PsppSheetViewChild PsppSheetViewChild;
93 struct _PsppSheetViewChild
103 typedef struct _TreeViewDragInfo TreeViewDragInfo;
104 struct _TreeViewDragInfo
106 GdkModifierType start_button_mask;
107 GtkTargetList *_unused_source_target_list;
108 GdkDragAction source_actions;
110 GtkTargetList *_unused_dest_target_list;
112 guint source_set : 1;
128 START_INTERACTIVE_SEARCH,
138 PROP_HEADERS_VISIBLE,
139 PROP_HEADERS_CLICKABLE,
144 PROP_HOVER_SELECTION,
146 PROP_ENABLE_GRID_LINES,
150 PROP_FIXED_HEIGHT_SET
154 static void pspp_sheet_view_finalize (GObject *object);
155 static void pspp_sheet_view_set_property (GObject *object,
159 static void pspp_sheet_view_get_property (GObject *object,
164 static void pspp_sheet_view_dispose (GObject *object);
166 /* gtkwidget signals */
167 static void pspp_sheet_view_realize (GtkWidget *widget);
168 static void pspp_sheet_view_unrealize (GtkWidget *widget);
169 static void pspp_sheet_view_map (GtkWidget *widget);
170 static void pspp_sheet_view_size_request (GtkWidget *widget,
171 GtkRequisition *requisition);
172 static void pspp_sheet_view_size_allocate (GtkWidget *widget,
173 GtkAllocation *allocation);
174 static gboolean pspp_sheet_view_draw (GtkWidget *widget,
176 static gboolean pspp_sheet_view_key_press (GtkWidget *widget,
178 static gboolean pspp_sheet_view_key_release (GtkWidget *widget,
180 static gboolean pspp_sheet_view_motion (GtkWidget *widget,
181 GdkEventMotion *event);
182 static gboolean pspp_sheet_view_enter_notify (GtkWidget *widget,
183 GdkEventCrossing *event);
184 static gboolean pspp_sheet_view_leave_notify (GtkWidget *widget,
185 GdkEventCrossing *event);
186 static gboolean pspp_sheet_view_button_press (GtkWidget *widget,
187 GdkEventButton *event);
188 static gboolean pspp_sheet_view_button_release (GtkWidget *widget,
189 GdkEventButton *event);
190 static gboolean pspp_sheet_view_grab_broken (GtkWidget *widget,
191 GdkEventGrabBroken *event);
193 static void pspp_sheet_view_set_focus_child (GtkContainer *container,
195 static gint pspp_sheet_view_focus_out (GtkWidget *widget,
196 GdkEventFocus *event);
197 static gint pspp_sheet_view_focus (GtkWidget *widget,
198 GtkDirectionType direction);
199 static void pspp_sheet_view_grab_focus (GtkWidget *widget);
200 static void pspp_sheet_view_style_set (GtkWidget *widget,
201 GtkStyle *previous_style);
202 static void pspp_sheet_view_grab_notify (GtkWidget *widget,
203 gboolean was_grabbed);
204 static void pspp_sheet_view_state_changed (GtkWidget *widget,
205 GtkStateType previous_state);
207 /* container signals */
208 static void pspp_sheet_view_remove (GtkContainer *container,
210 static void pspp_sheet_view_forall (GtkContainer *container,
211 gboolean include_internals,
212 GtkCallback callback,
213 gpointer callback_data);
215 /* Source side drag signals */
216 static void pspp_sheet_view_drag_begin (GtkWidget *widget,
217 GdkDragContext *context);
218 static void pspp_sheet_view_drag_end (GtkWidget *widget,
219 GdkDragContext *context);
220 static void pspp_sheet_view_drag_data_get (GtkWidget *widget,
221 GdkDragContext *context,
222 GtkSelectionData *selection_data,
225 static void pspp_sheet_view_drag_data_delete (GtkWidget *widget,
226 GdkDragContext *context);
228 /* Target side drag signals */
229 static void pspp_sheet_view_drag_leave (GtkWidget *widget,
230 GdkDragContext *context,
232 static gboolean pspp_sheet_view_drag_motion (GtkWidget *widget,
233 GdkDragContext *context,
237 static gboolean pspp_sheet_view_drag_drop (GtkWidget *widget,
238 GdkDragContext *context,
242 static void pspp_sheet_view_drag_data_received (GtkWidget *widget,
243 GdkDragContext *context,
246 GtkSelectionData *selection_data,
250 /* tree_model signals */
251 static void pspp_sheet_view_set_adjustments (PsppSheetView *tree_view,
253 GtkAdjustment *vadj);
254 static gboolean pspp_sheet_view_real_move_cursor (PsppSheetView *tree_view,
255 GtkMovementStep step,
257 static gboolean pspp_sheet_view_real_select_all (PsppSheetView *tree_view);
258 static gboolean pspp_sheet_view_real_unselect_all (PsppSheetView *tree_view);
259 static gboolean pspp_sheet_view_real_select_cursor_row (PsppSheetView *tree_view,
260 gboolean start_editing,
261 PsppSheetSelectMode mode);
262 static gboolean pspp_sheet_view_real_toggle_cursor_row (PsppSheetView *tree_view);
263 static void pspp_sheet_view_row_changed (GtkTreeModel *model,
267 static void pspp_sheet_view_row_inserted (GtkTreeModel *model,
271 static void pspp_sheet_view_row_deleted (GtkTreeModel *model,
274 static void pspp_sheet_view_rows_reordered (GtkTreeModel *model,
280 /* Incremental reflow */
281 static gint validate_row (PsppSheetView *tree_view,
285 static void validate_visible_area (PsppSheetView *tree_view);
286 static gboolean validate_rows_handler (PsppSheetView *tree_view);
287 static gboolean presize_handler_callback (gpointer data);
288 static void install_presize_handler (PsppSheetView *tree_view);
289 static void install_scroll_sync_handler (PsppSheetView *tree_view);
290 static void pspp_sheet_view_set_top_row (PsppSheetView *tree_view,
293 static void pspp_sheet_view_dy_to_top_row (PsppSheetView *tree_view);
294 static void pspp_sheet_view_top_row_to_dy (PsppSheetView *tree_view);
295 static void invalidate_empty_focus (PsppSheetView *tree_view);
297 /* Internal functions */
298 static void pspp_sheet_view_add_move_binding (GtkBindingSet *binding_set,
301 gboolean add_shifted_binding,
302 GtkMovementStep step,
304 static void pspp_sheet_view_queue_draw_path (PsppSheetView *tree_view,
306 const GdkRectangle *clip_rect);
307 static gint pspp_sheet_view_new_column_width (PsppSheetView *tree_view,
310 static void pspp_sheet_view_adjustment_changed (GtkAdjustment *adjustment,
311 PsppSheetView *tree_view);
312 static void pspp_sheet_view_clamp_node_visible (PsppSheetView *tree_view,
314 static void pspp_sheet_view_clamp_column_visible (PsppSheetView *tree_view,
315 PsppSheetViewColumn *column,
316 gboolean focus_to_cell);
317 static gboolean pspp_sheet_view_maybe_begin_dragging_row (PsppSheetView *tree_view,
318 GdkEventMotion *event);
319 static void pspp_sheet_view_focus_to_cursor (PsppSheetView *tree_view);
320 static gboolean pspp_sheet_view_move_cursor_up_down (PsppSheetView *tree_view,
322 PsppSheetSelectMode mode);
323 static void pspp_sheet_view_move_cursor_page_up_down (PsppSheetView *tree_view,
325 PsppSheetSelectMode mode);
326 static void pspp_sheet_view_move_cursor_left_right (PsppSheetView *tree_view,
328 PsppSheetSelectMode mode);
329 static void pspp_sheet_view_move_cursor_line_start_end (PsppSheetView *tree_view,
331 PsppSheetSelectMode mode);
332 static void pspp_sheet_view_move_cursor_tab (PsppSheetView *tree_view,
334 static void pspp_sheet_view_move_cursor_start_end (PsppSheetView *tree_view,
336 PsppSheetSelectMode mode);
337 static void pspp_sheet_view_real_set_cursor (PsppSheetView *tree_view,
339 gboolean clear_and_select,
341 PsppSheetSelectMode mode);
342 static gboolean pspp_sheet_view_has_special_cell (PsppSheetView *tree_view);
343 static void pspp_sheet_view_stop_rubber_band (PsppSheetView *tree_view);
344 static void update_prelight (PsppSheetView *tree_view,
347 static void initialize_fixed_height_mode (PsppSheetView *tree_view);
349 /* interactive search */
350 static void pspp_sheet_view_ensure_interactive_directory (PsppSheetView *tree_view);
351 static void pspp_sheet_view_search_dialog_hide (GtkWidget *search_dialog,
352 PsppSheetView *tree_view);
353 static void pspp_sheet_view_search_position_func (PsppSheetView *tree_view,
354 GtkWidget *search_dialog,
356 static void pspp_sheet_view_search_disable_popdown (GtkEntry *entry,
360 static void pspp_sheet_view_search_preedit_changed (GtkIMContext *im_context,
361 PsppSheetView *tree_view);
363 static void pspp_sheet_view_search_activate (GtkEntry *entry,
364 PsppSheetView *tree_view);
365 static gboolean pspp_sheet_view_real_search_enable_popdown(gpointer data);
366 static void pspp_sheet_view_search_enable_popdown (GtkWidget *widget,
368 static gboolean pspp_sheet_view_search_delete_event (GtkWidget *widget,
370 PsppSheetView *tree_view);
371 static gboolean pspp_sheet_view_search_button_press_event (GtkWidget *widget,
372 GdkEventButton *event,
373 PsppSheetView *tree_view);
374 static gboolean pspp_sheet_view_search_scroll_event (GtkWidget *entry,
375 GdkEventScroll *event,
376 PsppSheetView *tree_view);
377 static gboolean pspp_sheet_view_search_key_press_event (GtkWidget *entry,
379 PsppSheetView *tree_view);
380 static gboolean pspp_sheet_view_search_move (GtkWidget *window,
381 PsppSheetView *tree_view,
383 static gboolean pspp_sheet_view_search_equal_func (GtkTreeModel *model,
387 gpointer search_data);
388 static gboolean pspp_sheet_view_search_iter (GtkTreeModel *model,
389 PsppSheetSelection *selection,
394 static void pspp_sheet_view_search_init (GtkWidget *entry,
395 PsppSheetView *tree_view);
396 static void pspp_sheet_view_put (PsppSheetView *tree_view,
397 GtkWidget *child_widget,
402 static gboolean pspp_sheet_view_start_editing (PsppSheetView *tree_view,
403 GtkTreePath *cursor_path);
404 static gboolean pspp_sheet_view_editable_button_press_event (GtkWidget *,
407 static void pspp_sheet_view_editable_clicked (GtkButton *, PsppSheetView *);
408 static void pspp_sheet_view_real_start_editing (PsppSheetView *tree_view,
409 PsppSheetViewColumn *column,
411 GtkCellEditable *cell_editable,
412 GdkRectangle *cell_area,
415 static gboolean pspp_sheet_view_real_start_interactive_search (PsppSheetView *tree_view,
416 gboolean keybinding);
417 static gboolean pspp_sheet_view_start_interactive_search (PsppSheetView *tree_view);
418 static PsppSheetViewColumn *pspp_sheet_view_get_drop_column (PsppSheetView *tree_view,
419 PsppSheetViewColumn *column,
422 pspp_sheet_view_adjust_cell_area (PsppSheetView *tree_view,
423 PsppSheetViewColumn *column,
424 const GdkRectangle *background_area,
425 gboolean subtract_focus_rect,
426 GdkRectangle *cell_area);
427 static gint pspp_sheet_view_find_offset (PsppSheetView *tree_view,
432 static void pspp_sheet_view_buildable_add_child (GtkBuildable *tree_view,
436 static void pspp_sheet_view_buildable_init (GtkBuildableIface *iface);
439 static gboolean scroll_row_timeout (gpointer data);
440 static void add_scroll_timeout (PsppSheetView *tree_view);
441 static void remove_scroll_timeout (PsppSheetView *tree_view);
443 static guint tree_view_signals [LAST_SIGNAL] = { 0 };
445 static GtkBindingSet *edit_bindings;
452 G_DEFINE_TYPE_WITH_CODE (PsppSheetView, pspp_sheet_view, GTK_TYPE_CONTAINER,
453 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
454 pspp_sheet_view_buildable_init))
457 pspp_sheet_view_get_preferred_width (GtkWidget *widget,
461 GtkRequisition requisition;
463 pspp_sheet_view_size_request (widget, &requisition);
465 *minimal_width = *natural_width = requisition.width;
469 pspp_sheet_view_get_preferred_height (GtkWidget *widget,
470 gint *minimal_height,
471 gint *natural_height)
473 GtkRequisition requisition;
475 pspp_sheet_view_size_request (widget, &requisition);
477 *minimal_height = *natural_height = requisition.height;
481 pspp_sheet_view_class_init (PsppSheetViewClass *class)
483 GObjectClass *o_class;
484 GtkWidgetClass *widget_class;
485 GtkContainerClass *container_class;
486 GtkBindingSet *binding_set[2];
489 binding_set[0] = gtk_binding_set_by_class (class);
491 binding_set[1] = gtk_binding_set_new ("PsppSheetViewEditing");
492 edit_bindings = binding_set[1];
494 o_class = (GObjectClass *) class;
495 widget_class = (GtkWidgetClass *) class;
496 container_class = (GtkContainerClass *) class;
498 /* GObject signals */
499 o_class->set_property = pspp_sheet_view_set_property;
500 o_class->get_property = pspp_sheet_view_get_property;
501 o_class->finalize = pspp_sheet_view_finalize;
502 o_class->dispose = pspp_sheet_view_dispose;
504 /* GtkWidget signals */
505 widget_class->map = pspp_sheet_view_map;
506 widget_class->realize = pspp_sheet_view_realize;
507 widget_class->unrealize = pspp_sheet_view_unrealize;
508 widget_class->get_preferred_width = pspp_sheet_view_get_preferred_width;
509 widget_class->get_preferred_height = pspp_sheet_view_get_preferred_height;
510 widget_class->size_allocate = pspp_sheet_view_size_allocate;
511 widget_class->button_press_event = pspp_sheet_view_button_press;
512 widget_class->button_release_event = pspp_sheet_view_button_release;
513 widget_class->grab_broken_event = pspp_sheet_view_grab_broken;
514 /*widget_class->configure_event = pspp_sheet_view_configure;*/
515 widget_class->motion_notify_event = pspp_sheet_view_motion;
516 widget_class->draw = pspp_sheet_view_draw;
517 widget_class->key_press_event = pspp_sheet_view_key_press;
518 widget_class->key_release_event = pspp_sheet_view_key_release;
519 widget_class->enter_notify_event = pspp_sheet_view_enter_notify;
520 widget_class->leave_notify_event = pspp_sheet_view_leave_notify;
521 widget_class->focus_out_event = pspp_sheet_view_focus_out;
522 widget_class->drag_begin = pspp_sheet_view_drag_begin;
523 widget_class->drag_end = pspp_sheet_view_drag_end;
524 widget_class->drag_data_get = pspp_sheet_view_drag_data_get;
525 widget_class->drag_data_delete = pspp_sheet_view_drag_data_delete;
526 widget_class->drag_leave = pspp_sheet_view_drag_leave;
527 widget_class->drag_motion = pspp_sheet_view_drag_motion;
528 widget_class->drag_drop = pspp_sheet_view_drag_drop;
529 widget_class->drag_data_received = pspp_sheet_view_drag_data_received;
530 widget_class->focus = pspp_sheet_view_focus;
531 widget_class->grab_focus = pspp_sheet_view_grab_focus;
532 widget_class->style_set = pspp_sheet_view_style_set;
533 widget_class->grab_notify = pspp_sheet_view_grab_notify;
534 widget_class->state_changed = pspp_sheet_view_state_changed;
536 /* GtkContainer signals */
537 container_class->remove = pspp_sheet_view_remove;
538 container_class->forall = pspp_sheet_view_forall;
539 container_class->set_focus_child = pspp_sheet_view_set_focus_child;
541 class->set_scroll_adjustments = pspp_sheet_view_set_adjustments;
542 class->move_cursor = pspp_sheet_view_real_move_cursor;
543 class->select_all = pspp_sheet_view_real_select_all;
544 class->unselect_all = pspp_sheet_view_real_unselect_all;
545 class->select_cursor_row = pspp_sheet_view_real_select_cursor_row;
546 class->toggle_cursor_row = pspp_sheet_view_real_toggle_cursor_row;
547 class->start_interactive_search = pspp_sheet_view_start_interactive_search;
551 g_object_class_install_property (o_class,
553 g_param_spec_object ("model",
554 P_("TreeView Model"),
555 P_("The model for the tree view"),
557 GTK_PARAM_READWRITE));
559 g_object_class_install_property (o_class,
561 g_param_spec_object ("hadjustment",
562 P_("Horizontal Adjustment"),
563 P_("Horizontal Adjustment for the widget"),
565 GTK_PARAM_READWRITE));
567 g_object_class_install_property (o_class,
569 g_param_spec_object ("vadjustment",
570 P_("Vertical Adjustment"),
571 P_("Vertical Adjustment for the widget"),
573 GTK_PARAM_READWRITE));
575 g_object_class_install_property (o_class,
576 PROP_HEADERS_VISIBLE,
577 g_param_spec_boolean ("headers-visible",
578 P_("Headers Visible"),
579 P_("Show the column header buttons"),
581 GTK_PARAM_READWRITE));
583 g_object_class_install_property (o_class,
584 PROP_HEADERS_CLICKABLE,
585 g_param_spec_boolean ("headers-clickable",
586 P_("Headers Clickable"),
587 P_("Column headers respond to click events"),
589 GTK_PARAM_READWRITE));
591 g_object_class_install_property (o_class,
593 g_param_spec_boolean ("reorderable",
595 P_("View is reorderable"),
597 GTK_PARAM_READWRITE));
599 g_object_class_install_property (o_class,
601 g_param_spec_boolean ("rules-hint",
603 P_("Set a hint to the theme engine to draw rows in alternating colors"),
605 GTK_PARAM_READWRITE));
607 g_object_class_install_property (o_class,
609 g_param_spec_boolean ("enable-search",
611 P_("View allows user to search through columns interactively"),
613 GTK_PARAM_READWRITE));
615 g_object_class_install_property (o_class,
617 g_param_spec_int ("search-column",
619 P_("Model column to search through during interactive search"),
623 GTK_PARAM_READWRITE));
626 * PsppSheetView:hover-selection:
628 * Enables of disables the hover selection mode of @tree_view.
629 * Hover selection makes the selected row follow the pointer.
630 * Currently, this works only for the selection modes
631 * %PSPP_SHEET_SELECTION_SINGLE and %PSPP_SHEET_SELECTION_BROWSE.
633 * This mode is primarily intended for treeviews in popups, e.g.
634 * in #GtkComboBox or #GtkEntryCompletion.
638 g_object_class_install_property (o_class,
639 PROP_HOVER_SELECTION,
640 g_param_spec_boolean ("hover-selection",
641 P_("Hover Selection"),
642 P_("Whether the selection should follow the pointer"),
644 GTK_PARAM_READWRITE));
646 g_object_class_install_property (o_class,
648 g_param_spec_boolean ("rubber-banding",
649 P_("Rubber Banding"),
650 P_("Whether to enable selection of multiple items by dragging the mouse pointer"),
652 GTK_PARAM_READWRITE));
654 g_object_class_install_property (o_class,
655 PROP_ENABLE_GRID_LINES,
656 g_param_spec_enum ("enable-grid-lines",
657 P_("Enable Grid Lines"),
658 P_("Whether grid lines should be drawn in the tree view"),
659 PSPP_TYPE_SHEET_VIEW_GRID_LINES,
660 PSPP_SHEET_VIEW_GRID_LINES_NONE,
661 GTK_PARAM_READWRITE));
663 g_object_class_install_property (o_class,
665 g_param_spec_int ("tooltip-column",
666 P_("Tooltip Column"),
667 P_("The column in the model containing the tooltip texts for the rows"),
671 GTK_PARAM_READWRITE));
673 g_object_class_install_property (o_class,
675 g_param_spec_enum ("special-cells",
677 P_("Whether rows have special cells."),
678 PSPP_TYPE_SHEET_VIEW_SPECIAL_CELLS,
679 PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT,
680 GTK_PARAM_READWRITE));
682 g_object_class_install_property (o_class,
684 g_param_spec_int ("fixed-height",
686 P_("Height of a single row. Normally the height of a row is determined automatically. Writing this property sets fixed-height-set to true, preventing this property's value from changing."),
690 GTK_PARAM_READWRITE));
692 g_object_class_install_property (o_class,
693 PROP_FIXED_HEIGHT_SET,
694 g_param_spec_boolean ("fixed-height-set",
695 P_("Fixed Height Set"),
696 P_("Whether fixed-height was set externally."),
698 GTK_PARAM_READWRITE));
700 /* Style properties */
701 #define _TREE_VIEW_EXPANDER_SIZE 12
702 #define _TREE_VIEW_VERTICAL_SEPARATOR 2
703 #define _TREE_VIEW_HORIZONTAL_SEPARATOR 2
705 gtk_widget_class_install_style_property (widget_class,
706 g_param_spec_int ("expander-size",
708 P_("Size of the expander arrow"),
711 _TREE_VIEW_EXPANDER_SIZE,
712 GTK_PARAM_READABLE));
714 gtk_widget_class_install_style_property (widget_class,
715 g_param_spec_int ("vertical-separator",
716 P_("Vertical Separator Width"),
717 P_("Vertical space between cells. Must be an even number"),
720 _TREE_VIEW_VERTICAL_SEPARATOR,
721 GTK_PARAM_READABLE));
723 gtk_widget_class_install_style_property (widget_class,
724 g_param_spec_int ("horizontal-separator",
725 P_("Horizontal Separator Width"),
726 P_("Horizontal space between cells. Must be an even number"),
729 _TREE_VIEW_HORIZONTAL_SEPARATOR,
730 GTK_PARAM_READABLE));
732 gtk_widget_class_install_style_property (widget_class,
733 g_param_spec_boolean ("allow-rules",
735 P_("Allow drawing of alternating color rows"),
737 GTK_PARAM_READABLE));
739 gtk_widget_class_install_style_property (widget_class,
740 g_param_spec_boxed ("even-row-color",
741 P_("Even Row Color"),
742 P_("Color to use for even rows"),
744 GTK_PARAM_READABLE));
746 gtk_widget_class_install_style_property (widget_class,
747 g_param_spec_boxed ("odd-row-color",
749 P_("Color to use for odd rows"),
751 GTK_PARAM_READABLE));
753 gtk_widget_class_install_style_property (widget_class,
754 g_param_spec_boolean ("row-ending-details",
755 P_("Row Ending details"),
756 P_("Enable extended row background theming"),
758 GTK_PARAM_READABLE));
760 gtk_widget_class_install_style_property (widget_class,
761 g_param_spec_int ("grid-line-width",
762 P_("Grid line width"),
763 P_("Width, in pixels, of the tree view grid lines"),
765 GTK_PARAM_READABLE));
767 gtk_widget_class_install_style_property (widget_class,
768 g_param_spec_int ("tree-line-width",
769 P_("Tree line width"),
770 P_("Width, in pixels, of the tree view lines"),
772 GTK_PARAM_READABLE));
774 gtk_widget_class_install_style_property (widget_class,
775 g_param_spec_string ("tree-line-pattern",
776 P_("Tree line pattern"),
777 P_("Dash pattern used to draw the tree view lines"),
779 GTK_PARAM_READABLE));
784 * PsppSheetView::set-scroll-adjustments
785 * @horizontal: the horizontal #GtkAdjustment
786 * @vertical: the vertical #GtkAdjustment
788 * Set the scroll adjustments for the tree view. Usually scrolled containers
789 * like #GtkScrolledWindow will emit this signal to connect two instances
790 * of #GtkScrollbar to the scroll directions of the #PsppSheetView.
792 widget_class->set_scroll_adjustments_signal =
793 g_signal_new ("set-scroll-adjustments",
794 G_TYPE_FROM_CLASS (o_class),
795 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
796 G_STRUCT_OFFSET (PsppSheetViewClass, set_scroll_adjustments),
798 psppire_marshal_VOID__OBJECT_OBJECT,
801 GTK_TYPE_ADJUSTMENT);
805 * PsppSheetView::row-activated:
806 * @tree_view: the object on which the signal is emitted
807 * @path: the #GtkTreePath for the activated row
808 * @column: the #PsppSheetViewColumn in which the activation occurred
810 * The "row-activated" signal is emitted when the method
811 * pspp_sheet_view_row_activated() is called or the user double clicks
812 * a treeview row. It is also emitted when a non-editable row is
813 * selected and one of the keys: Space, Shift+Space, Return or
816 * For selection handling refer to the <link linkend="TreeWidget">tree
817 * widget conceptual overview</link> as well as #PsppSheetSelection.
819 tree_view_signals[ROW_ACTIVATED] =
820 g_signal_new ("row-activated",
821 G_TYPE_FROM_CLASS (o_class),
822 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
823 G_STRUCT_OFFSET (PsppSheetViewClass, row_activated),
825 psppire_marshal_VOID__BOXED_OBJECT,
828 PSPP_TYPE_SHEET_VIEW_COLUMN);
831 * PsppSheetView::columns-changed:
832 * @tree_view: the object on which the signal is emitted
834 * The number of columns of the treeview has changed.
836 tree_view_signals[COLUMNS_CHANGED] =
837 g_signal_new ("columns-changed",
838 G_TYPE_FROM_CLASS (o_class),
840 G_STRUCT_OFFSET (PsppSheetViewClass, columns_changed),
842 g_cclosure_marshal_VOID__VOID,
846 * PsppSheetView::cursor-changed:
847 * @tree_view: the object on which the signal is emitted
849 * The position of the cursor (focused cell) has changed.
851 tree_view_signals[CURSOR_CHANGED] =
852 g_signal_new ("cursor-changed",
853 G_TYPE_FROM_CLASS (o_class),
855 G_STRUCT_OFFSET (PsppSheetViewClass, cursor_changed),
857 g_cclosure_marshal_VOID__VOID,
860 tree_view_signals[MOVE_CURSOR] =
861 g_signal_new ("move-cursor",
862 G_TYPE_FROM_CLASS (o_class),
863 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
864 G_STRUCT_OFFSET (PsppSheetViewClass, move_cursor),
866 psppire_marshal_BOOLEAN__ENUM_INT,
868 GTK_TYPE_MOVEMENT_STEP,
871 tree_view_signals[SELECT_ALL] =
872 g_signal_new ("select-all",
873 G_TYPE_FROM_CLASS (o_class),
874 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
875 G_STRUCT_OFFSET (PsppSheetViewClass, select_all),
877 psppire_marshal_BOOLEAN__VOID,
880 tree_view_signals[UNSELECT_ALL] =
881 g_signal_new ("unselect-all",
882 G_TYPE_FROM_CLASS (o_class),
883 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
884 G_STRUCT_OFFSET (PsppSheetViewClass, unselect_all),
886 psppire_marshal_BOOLEAN__VOID,
889 tree_view_signals[SELECT_CURSOR_ROW] =
890 g_signal_new ("select-cursor-row",
891 G_TYPE_FROM_CLASS (o_class),
892 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
893 G_STRUCT_OFFSET (PsppSheetViewClass, select_cursor_row),
895 psppire_marshal_BOOLEAN__BOOLEAN,
897 G_TYPE_BOOLEAN, G_TYPE_INT);
899 tree_view_signals[TOGGLE_CURSOR_ROW] =
900 g_signal_new ("toggle-cursor-row",
901 G_TYPE_FROM_CLASS (o_class),
902 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
903 G_STRUCT_OFFSET (PsppSheetViewClass, toggle_cursor_row),
905 psppire_marshal_BOOLEAN__VOID,
908 tree_view_signals[START_INTERACTIVE_SEARCH] =
909 g_signal_new ("start-interactive-search",
910 G_TYPE_FROM_CLASS (o_class),
911 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
912 G_STRUCT_OFFSET (PsppSheetViewClass, start_interactive_search),
914 psppire_marshal_BOOLEAN__VOID,
918 for (i = 0; i < 2; i++)
920 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Up, 0, TRUE,
921 GTK_MOVEMENT_DISPLAY_LINES, -1);
922 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Up, 0, TRUE,
923 GTK_MOVEMENT_DISPLAY_LINES, -1);
925 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Down, 0, TRUE,
926 GTK_MOVEMENT_DISPLAY_LINES, 1);
927 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Down, 0, TRUE,
928 GTK_MOVEMENT_DISPLAY_LINES, 1);
930 pspp_sheet_view_add_move_binding (binding_set[i], GDK_p, GDK_CONTROL_MASK, FALSE,
931 GTK_MOVEMENT_DISPLAY_LINES, -1);
933 pspp_sheet_view_add_move_binding (binding_set[i], GDK_n, GDK_CONTROL_MASK, FALSE,
934 GTK_MOVEMENT_DISPLAY_LINES, 1);
936 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Home, 0, TRUE,
937 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
938 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Home, 0, TRUE,
939 GTK_MOVEMENT_DISPLAY_LINE_ENDS, -1);
941 pspp_sheet_view_add_move_binding (binding_set[i], GDK_End, 0, TRUE,
942 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
943 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_End, 0, TRUE,
944 GTK_MOVEMENT_DISPLAY_LINE_ENDS, 1);
946 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Page_Up, 0, TRUE,
947 GTK_MOVEMENT_PAGES, -1);
948 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Page_Up, 0, TRUE,
949 GTK_MOVEMENT_PAGES, -1);
951 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Page_Down, 0, TRUE,
952 GTK_MOVEMENT_PAGES, 1);
953 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Page_Down, 0, TRUE,
954 GTK_MOVEMENT_PAGES, 1);
957 gtk_binding_entry_add_signal (binding_set[i], GDK_Up, GDK_CONTROL_MASK, "move-cursor", 2,
958 G_TYPE_ENUM, GTK_MOVEMENT_BUFFER_ENDS,
961 gtk_binding_entry_add_signal (binding_set[i], GDK_Down, GDK_CONTROL_MASK, "move-cursor", 2,
962 G_TYPE_ENUM, GTK_MOVEMENT_BUFFER_ENDS,
965 gtk_binding_entry_add_signal (binding_set[i], GDK_Right, 0, "move-cursor", 2,
966 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
969 gtk_binding_entry_add_signal (binding_set[i], GDK_Left, 0, "move-cursor", 2,
970 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
973 gtk_binding_entry_add_signal (binding_set[i], GDK_Tab, 0, "move-cursor", 2,
974 G_TYPE_ENUM, GTK_MOVEMENT_LOGICAL_POSITIONS,
977 gtk_binding_entry_add_signal (binding_set[i], GDK_Tab, GDK_SHIFT_MASK, "move-cursor", 2,
978 G_TYPE_ENUM, GTK_MOVEMENT_LOGICAL_POSITIONS,
981 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Right, 0, "move-cursor", 2,
982 G_TYPE_ENUM, GTK_MOVEMENT_DISPLAY_LINE_ENDS,
985 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Left, 0, "move-cursor", 2,
986 G_TYPE_ENUM, GTK_MOVEMENT_DISPLAY_LINE_ENDS,
989 gtk_binding_entry_add_signal (binding_set[i], GDK_Right, GDK_CONTROL_MASK,
991 G_TYPE_ENUM, GTK_MOVEMENT_DISPLAY_LINE_ENDS,
994 gtk_binding_entry_add_signal (binding_set[i], GDK_Left, GDK_CONTROL_MASK,
996 G_TYPE_ENUM, GTK_MOVEMENT_DISPLAY_LINE_ENDS,
999 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Right, GDK_CONTROL_MASK,
1001 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
1004 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Left, GDK_CONTROL_MASK,
1006 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
1009 gtk_binding_entry_add_signal (binding_set[i], GDK_f, GDK_CONTROL_MASK, "start-interactive-search", 0);
1011 gtk_binding_entry_add_signal (binding_set[i], GDK_F, GDK_CONTROL_MASK, "start-interactive-search", 0);
1014 gtk_binding_entry_add_signal (binding_set[0], GDK_space, GDK_CONTROL_MASK, "toggle-cursor-row", 0);
1015 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Space, GDK_CONTROL_MASK, "toggle-cursor-row", 0);
1017 gtk_binding_entry_add_signal (binding_set[0], GDK_a, GDK_CONTROL_MASK, "select-all", 0);
1018 gtk_binding_entry_add_signal (binding_set[0], GDK_slash, GDK_CONTROL_MASK, "select-all", 0);
1020 gtk_binding_entry_add_signal (binding_set[0], GDK_A, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "unselect-all", 0);
1021 gtk_binding_entry_add_signal (binding_set[0], GDK_backslash, GDK_CONTROL_MASK, "unselect-all", 0);
1023 gtk_binding_entry_add_signal (binding_set[0], GDK_space, GDK_SHIFT_MASK, "select-cursor-row", 1,
1024 G_TYPE_BOOLEAN, TRUE,
1025 G_TYPE_INT, PSPP_SHEET_SELECT_MODE_EXTEND);
1026 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Space, GDK_SHIFT_MASK, "select-cursor-row", 1,
1027 G_TYPE_BOOLEAN, TRUE,
1028 G_TYPE_INT, PSPP_SHEET_SELECT_MODE_EXTEND);
1030 gtk_binding_entry_add_signal (binding_set[0], GDK_space, 0, "select-cursor-row", 1,
1031 G_TYPE_BOOLEAN, TRUE,
1033 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Space, 0, "select-cursor-row", 1,
1034 G_TYPE_BOOLEAN, TRUE,
1036 gtk_binding_entry_add_signal (binding_set[0], GDK_Return, 0, "select-cursor-row", 1,
1037 G_TYPE_BOOLEAN, TRUE,
1039 gtk_binding_entry_add_signal (binding_set[0], GDK_ISO_Enter, 0, "select-cursor-row", 1,
1040 G_TYPE_BOOLEAN, TRUE,
1042 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Enter, 0, "select-cursor-row", 1,
1043 G_TYPE_BOOLEAN, TRUE,
1046 gtk_binding_entry_add_signal (binding_set[0], GDK_BackSpace, 0, "select-cursor-parent", 0);
1047 gtk_binding_entry_add_signal (binding_set[0], GDK_BackSpace, GDK_CONTROL_MASK, "select-cursor-parent", 0);
1049 g_type_class_add_private (o_class, sizeof (PsppSheetViewPrivate));
1053 pspp_sheet_view_buildable_init (GtkBuildableIface *iface)
1055 iface->add_child = pspp_sheet_view_buildable_add_child;
1059 pspp_sheet_view_init (PsppSheetView *tree_view)
1061 tree_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (tree_view, PSPP_TYPE_SHEET_VIEW, PsppSheetViewPrivate);
1063 gtk_widget_set_can_focus (GTK_WIDGET (tree_view), TRUE);
1064 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (tree_view), FALSE);
1066 tree_view->priv->flags = PSPP_SHEET_VIEW_DRAW_KEYFOCUS
1067 | PSPP_SHEET_VIEW_HEADERS_VISIBLE;
1069 /* We need some padding */
1070 tree_view->priv->selected = range_tower_create ();
1071 tree_view->priv->dy = 0;
1072 tree_view->priv->cursor_offset = 0;
1073 tree_view->priv->n_columns = 0;
1074 tree_view->priv->header_height = 1;
1075 tree_view->priv->x_drag = 0;
1076 tree_view->priv->drag_pos = -1;
1077 tree_view->priv->header_has_focus = FALSE;
1078 tree_view->priv->pressed_button = -1;
1079 tree_view->priv->press_start_x = -1;
1080 tree_view->priv->press_start_y = -1;
1081 tree_view->priv->reorderable = FALSE;
1082 tree_view->priv->presize_handler_timer = 0;
1083 tree_view->priv->scroll_sync_timer = 0;
1084 tree_view->priv->fixed_height = -1;
1085 tree_view->priv->fixed_height_set = FALSE;
1086 pspp_sheet_view_set_adjustments (tree_view, NULL, NULL);
1087 tree_view->priv->selection = _pspp_sheet_selection_new_with_tree_view (tree_view);
1088 tree_view->priv->enable_search = TRUE;
1089 tree_view->priv->search_column = -1;
1090 tree_view->priv->search_position_func = pspp_sheet_view_search_position_func;
1091 tree_view->priv->search_equal_func = pspp_sheet_view_search_equal_func;
1092 tree_view->priv->search_custom_entry_set = FALSE;
1093 tree_view->priv->typeselect_flush_timeout = 0;
1094 tree_view->priv->init_hadjust_value = TRUE;
1095 tree_view->priv->width = 0;
1097 tree_view->priv->hover_selection = FALSE;
1099 tree_view->priv->rubber_banding_enable = FALSE;
1101 tree_view->priv->grid_lines = PSPP_SHEET_VIEW_GRID_LINES_NONE;
1103 tree_view->priv->tooltip_column = -1;
1105 tree_view->priv->special_cells = PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT;
1107 tree_view->priv->post_validation_flag = FALSE;
1109 tree_view->priv->last_button_x = -1;
1110 tree_view->priv->last_button_y = -1;
1112 tree_view->priv->event_last_x = -10000;
1113 tree_view->priv->event_last_y = -10000;
1115 tree_view->priv->prelight_node = -1;
1116 tree_view->priv->rubber_band_start_node = -1;
1117 tree_view->priv->rubber_band_end_node = -1;
1119 tree_view->priv->anchor_column = NULL;
1121 tree_view->priv->button_style = NULL;
1123 tree_view->dispose_has_run = FALSE;
1132 pspp_sheet_view_set_property (GObject *object,
1134 const GValue *value,
1137 PsppSheetView *tree_view;
1139 tree_view = PSPP_SHEET_VIEW (object);
1144 pspp_sheet_view_set_model (tree_view, g_value_get_object (value));
1146 case PROP_HADJUSTMENT:
1147 pspp_sheet_view_set_hadjustment (tree_view, g_value_get_object (value));
1149 case PROP_VADJUSTMENT:
1150 pspp_sheet_view_set_vadjustment (tree_view, g_value_get_object (value));
1152 case PROP_HEADERS_VISIBLE:
1153 pspp_sheet_view_set_headers_visible (tree_view, g_value_get_boolean (value));
1155 case PROP_HEADERS_CLICKABLE:
1156 pspp_sheet_view_set_headers_clickable (tree_view, g_value_get_boolean (value));
1158 case PROP_REORDERABLE:
1159 pspp_sheet_view_set_reorderable (tree_view, g_value_get_boolean (value));
1161 case PROP_RULES_HINT:
1162 pspp_sheet_view_set_rules_hint (tree_view, g_value_get_boolean (value));
1164 case PROP_ENABLE_SEARCH:
1165 pspp_sheet_view_set_enable_search (tree_view, g_value_get_boolean (value));
1167 case PROP_SEARCH_COLUMN:
1168 pspp_sheet_view_set_search_column (tree_view, g_value_get_int (value));
1170 case PROP_HOVER_SELECTION:
1171 tree_view->priv->hover_selection = g_value_get_boolean (value);
1173 case PROP_RUBBER_BANDING:
1174 tree_view->priv->rubber_banding_enable = g_value_get_boolean (value);
1176 case PROP_ENABLE_GRID_LINES:
1177 pspp_sheet_view_set_grid_lines (tree_view, g_value_get_enum (value));
1179 case PROP_TOOLTIP_COLUMN:
1180 pspp_sheet_view_set_tooltip_column (tree_view, g_value_get_int (value));
1182 case PROP_SPECIAL_CELLS:
1183 pspp_sheet_view_set_special_cells (tree_view, g_value_get_enum (value));
1185 case PROP_FIXED_HEIGHT:
1186 pspp_sheet_view_set_fixed_height (tree_view, g_value_get_int (value));
1188 case PROP_FIXED_HEIGHT_SET:
1189 if (g_value_get_boolean (value))
1191 if (!tree_view->priv->fixed_height_set
1192 && tree_view->priv->fixed_height >= 0)
1194 tree_view->priv->fixed_height_set = true;
1195 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
1200 if (tree_view->priv->fixed_height_set)
1202 tree_view->priv->fixed_height_set = false;
1203 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
1204 install_presize_handler (tree_view);
1209 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1215 pspp_sheet_view_get_property (GObject *object,
1220 PsppSheetView *tree_view;
1222 tree_view = PSPP_SHEET_VIEW (object);
1227 g_value_set_object (value, tree_view->priv->model);
1229 case PROP_HADJUSTMENT:
1230 g_value_set_object (value, tree_view->priv->hadjustment);
1232 case PROP_VADJUSTMENT:
1233 g_value_set_object (value, tree_view->priv->vadjustment);
1235 case PROP_HEADERS_VISIBLE:
1236 g_value_set_boolean (value, pspp_sheet_view_get_headers_visible (tree_view));
1238 case PROP_HEADERS_CLICKABLE:
1239 g_value_set_boolean (value, pspp_sheet_view_get_headers_clickable (tree_view));
1241 case PROP_REORDERABLE:
1242 g_value_set_boolean (value, tree_view->priv->reorderable);
1244 case PROP_RULES_HINT:
1245 g_value_set_boolean (value, tree_view->priv->has_rules);
1247 case PROP_ENABLE_SEARCH:
1248 g_value_set_boolean (value, tree_view->priv->enable_search);
1250 case PROP_SEARCH_COLUMN:
1251 g_value_set_int (value, tree_view->priv->search_column);
1253 case PROP_HOVER_SELECTION:
1254 g_value_set_boolean (value, tree_view->priv->hover_selection);
1256 case PROP_RUBBER_BANDING:
1257 g_value_set_boolean (value, tree_view->priv->rubber_banding_enable);
1259 case PROP_ENABLE_GRID_LINES:
1260 g_value_set_enum (value, tree_view->priv->grid_lines);
1262 case PROP_TOOLTIP_COLUMN:
1263 g_value_set_int (value, tree_view->priv->tooltip_column);
1265 case PROP_SPECIAL_CELLS:
1266 g_value_set_enum (value, tree_view->priv->special_cells);
1268 case PROP_FIXED_HEIGHT:
1269 g_value_set_int (value, pspp_sheet_view_get_fixed_height (tree_view));
1271 case PROP_FIXED_HEIGHT_SET:
1272 g_value_set_boolean (value, tree_view->priv->fixed_height_set);
1275 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1281 pspp_sheet_view_dispose (GObject *object)
1283 PsppSheetView *tree_view = PSPP_SHEET_VIEW (object);
1285 if (tree_view->dispose_has_run)
1288 tree_view->dispose_has_run = TRUE;
1290 if (tree_view->priv->selection != NULL)
1292 _pspp_sheet_selection_set_tree_view (tree_view->priv->selection, NULL);
1293 g_object_unref (tree_view->priv->selection);
1294 tree_view->priv->selection = NULL;
1297 if (tree_view->priv->hadjustment)
1299 g_object_unref (tree_view->priv->hadjustment);
1300 tree_view->priv->hadjustment = NULL;
1302 if (tree_view->priv->vadjustment)
1304 g_object_unref (tree_view->priv->vadjustment);
1305 tree_view->priv->vadjustment = NULL;
1308 if (tree_view->priv->button_style)
1310 g_object_unref (tree_view->priv->button_style);
1311 tree_view->priv->button_style = NULL;
1315 G_OBJECT_CLASS (pspp_sheet_view_parent_class)->dispose (object);
1321 pspp_sheet_view_buildable_add_child (GtkBuildable *tree_view,
1322 GtkBuilder *builder,
1326 pspp_sheet_view_append_column (PSPP_SHEET_VIEW (tree_view), PSPP_SHEET_VIEW_COLUMN (child));
1330 pspp_sheet_view_finalize (GObject *object)
1332 PsppSheetView *tree_view = PSPP_SHEET_VIEW (object);
1334 pspp_sheet_view_stop_editing (tree_view, TRUE);
1336 if (tree_view->priv->selected != NULL)
1338 range_tower_destroy (tree_view->priv->selected);
1339 tree_view->priv->selected = NULL;
1343 tree_view->priv->prelight_node = -1;
1346 if (tree_view->priv->scroll_to_path != NULL)
1348 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
1349 tree_view->priv->scroll_to_path = NULL;
1352 if (tree_view->priv->drag_dest_row != NULL)
1354 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
1355 tree_view->priv->drag_dest_row = NULL;
1358 if (tree_view->priv->top_row != NULL)
1360 gtk_tree_row_reference_free (tree_view->priv->top_row);
1361 tree_view->priv->top_row = NULL;
1364 if (tree_view->priv->column_drop_func_data &&
1365 tree_view->priv->column_drop_func_data_destroy)
1367 tree_view->priv->column_drop_func_data_destroy (tree_view->priv->column_drop_func_data);
1368 tree_view->priv->column_drop_func_data = NULL;
1371 if (tree_view->priv->destroy_count_destroy &&
1372 tree_view->priv->destroy_count_data)
1374 tree_view->priv->destroy_count_destroy (tree_view->priv->destroy_count_data);
1375 tree_view->priv->destroy_count_data = NULL;
1378 gtk_tree_row_reference_free (tree_view->priv->cursor);
1379 tree_view->priv->cursor = NULL;
1381 gtk_tree_row_reference_free (tree_view->priv->anchor);
1382 tree_view->priv->anchor = NULL;
1384 /* destroy interactive search dialog */
1385 if (tree_view->priv->search_window)
1387 gtk_widget_destroy (tree_view->priv->search_window);
1388 tree_view->priv->search_window = NULL;
1389 tree_view->priv->search_entry = NULL;
1390 if (tree_view->priv->typeselect_flush_timeout)
1392 g_source_remove (tree_view->priv->typeselect_flush_timeout);
1393 tree_view->priv->typeselect_flush_timeout = 0;
1397 if (tree_view->priv->search_destroy && tree_view->priv->search_user_data)
1399 tree_view->priv->search_destroy (tree_view->priv->search_user_data);
1400 tree_view->priv->search_user_data = NULL;
1403 if (tree_view->priv->search_position_destroy && tree_view->priv->search_position_user_data)
1405 tree_view->priv->search_position_destroy (tree_view->priv->search_position_user_data);
1406 tree_view->priv->search_position_user_data = NULL;
1409 pspp_sheet_view_set_model (tree_view, NULL);
1412 G_OBJECT_CLASS (pspp_sheet_view_parent_class)->finalize (object);
1417 /* GtkWidget Methods
1420 /* GtkWidget::map helper */
1422 pspp_sheet_view_map_buttons (PsppSheetView *tree_view)
1426 g_return_if_fail (gtk_widget_get_mapped (GTK_WIDGET (tree_view)));
1428 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
1430 PsppSheetViewColumn *column;
1432 for (list = tree_view->priv->columns; list; list = list->next)
1434 column = list->data;
1435 if (column->button != NULL &&
1436 gtk_widget_get_visible (column->button) &&
1437 !gtk_widget_get_mapped (column->button))
1438 gtk_widget_map (column->button);
1440 for (list = tree_view->priv->columns; list; list = list->next)
1442 column = list->data;
1443 if (column->visible == FALSE || column->window == NULL)
1445 if (column->resizable)
1447 gdk_window_raise (column->window);
1448 gdk_window_show (column->window);
1451 gdk_window_hide (column->window);
1453 gdk_window_show (tree_view->priv->header_window);
1458 pspp_sheet_view_map (GtkWidget *widget)
1460 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1463 gtk_widget_set_mapped (widget, TRUE);
1465 tmp_list = tree_view->priv->children;
1468 PsppSheetViewChild *child = tmp_list->data;
1469 tmp_list = tmp_list->next;
1471 if (gtk_widget_get_visible (child->widget))
1473 if (!gtk_widget_get_mapped (child->widget))
1474 gtk_widget_map (child->widget);
1477 gdk_window_show (tree_view->priv->bin_window);
1479 pspp_sheet_view_map_buttons (tree_view);
1481 gdk_window_show (gtk_widget_get_window (widget));
1485 pspp_sheet_view_realize (GtkWidget *widget)
1487 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1489 GdkWindowAttr attributes;
1490 gint attributes_mask;
1491 GtkAllocation allocation;
1492 GtkAllocation old_allocation;
1494 gtk_widget_set_realized (widget, TRUE);
1496 gtk_widget_get_allocation (widget, &allocation);
1497 gtk_widget_get_allocation (widget, &old_allocation);
1499 /* Make the main, clipping window */
1500 attributes.window_type = GDK_WINDOW_CHILD;
1501 attributes.x = allocation.x;
1502 attributes.y = allocation.y;
1503 attributes.width = allocation.width;
1504 attributes.height = allocation.height;
1505 attributes.wclass = GDK_INPUT_OUTPUT;
1506 attributes.visual = gtk_widget_get_visual (widget);
1507 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1509 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
1511 gtk_widget_set_window (widget,
1512 gdk_window_new (gtk_widget_get_parent_window (widget),
1513 &attributes, attributes_mask));
1514 gdk_window_set_user_data (gtk_widget_get_window (widget), widget);
1516 /* Make the window for the tree */
1518 attributes.y = TREE_VIEW_HEADER_HEIGHT (tree_view);
1519 attributes.width = MAX (tree_view->priv->width, old_allocation.width);
1520 attributes.height = old_allocation.height;
1521 attributes.event_mask = (GDK_EXPOSURE_MASK |
1523 GDK_POINTER_MOTION_MASK |
1524 GDK_ENTER_NOTIFY_MASK |
1525 GDK_LEAVE_NOTIFY_MASK |
1526 GDK_BUTTON_PRESS_MASK |
1527 GDK_BUTTON_RELEASE_MASK |
1528 gtk_widget_get_events (widget));
1530 tree_view->priv->bin_window = gdk_window_new (gtk_widget_get_window (widget),
1531 &attributes, attributes_mask);
1532 gdk_window_set_user_data (tree_view->priv->bin_window, widget);
1534 /* Make the column header window */
1537 attributes.width = MAX (tree_view->priv->width, old_allocation.width);
1538 attributes.height = tree_view->priv->header_height;
1539 attributes.event_mask = (GDK_EXPOSURE_MASK |
1541 GDK_BUTTON_PRESS_MASK |
1542 GDK_BUTTON_RELEASE_MASK |
1543 GDK_KEY_PRESS_MASK |
1544 GDK_KEY_RELEASE_MASK |
1545 gtk_widget_get_events (widget));
1547 tree_view->priv->header_window = gdk_window_new (gtk_widget_get_window (widget),
1548 &attributes, attributes_mask);
1549 gdk_window_set_user_data (tree_view->priv->header_window, widget);
1551 /* Add them all up. */
1552 gtk_widget_set_style (widget,
1553 gtk_style_attach (gtk_widget_get_style (widget), gtk_widget_get_window (widget)));
1554 gdk_window_set_background (tree_view->priv->bin_window, >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
1555 gtk_style_set_background (gtk_widget_get_style (widget), tree_view->priv->header_window, GTK_STATE_NORMAL);
1557 tmp_list = tree_view->priv->children;
1560 PsppSheetViewChild *child = tmp_list->data;
1561 tmp_list = tmp_list->next;
1563 gtk_widget_set_parent_window (child->widget, tree_view->priv->bin_window);
1566 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
1567 _pspp_sheet_view_column_realize_button (PSPP_SHEET_VIEW_COLUMN (tmp_list->data));
1569 /* Need to call those here, since they create GCs */
1570 pspp_sheet_view_set_grid_lines (tree_view, tree_view->priv->grid_lines);
1572 install_presize_handler (tree_view);
1576 pspp_sheet_view_unrealize (GtkWidget *widget)
1578 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1579 PsppSheetViewPrivate *priv = tree_view->priv;
1582 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->unrealize (widget);
1584 if (priv->scroll_timeout != 0)
1586 g_source_remove (priv->scroll_timeout);
1587 priv->scroll_timeout = 0;
1590 if (priv->open_dest_timeout != 0)
1592 g_source_remove (priv->open_dest_timeout);
1593 priv->open_dest_timeout = 0;
1596 if (priv->presize_handler_timer != 0)
1598 g_source_remove (priv->presize_handler_timer);
1599 priv->presize_handler_timer = 0;
1602 if (priv->validate_rows_timer != 0)
1604 g_source_remove (priv->validate_rows_timer);
1605 priv->validate_rows_timer = 0;
1608 if (priv->scroll_sync_timer != 0)
1610 g_source_remove (priv->scroll_sync_timer);
1611 priv->scroll_sync_timer = 0;
1614 if (priv->typeselect_flush_timeout)
1616 g_source_remove (priv->typeselect_flush_timeout);
1617 priv->typeselect_flush_timeout = 0;
1620 for (list = priv->columns; list; list = list->next)
1621 _pspp_sheet_view_column_unrealize_button (PSPP_SHEET_VIEW_COLUMN (list->data));
1623 gdk_window_set_user_data (priv->bin_window, NULL);
1624 gdk_window_destroy (priv->bin_window);
1625 priv->bin_window = NULL;
1627 gdk_window_set_user_data (priv->header_window, NULL);
1628 gdk_window_destroy (priv->header_window);
1629 priv->header_window = NULL;
1631 if (priv->drag_window)
1633 gdk_window_set_user_data (priv->drag_window, NULL);
1634 gdk_window_destroy (priv->drag_window);
1635 priv->drag_window = NULL;
1638 if (priv->drag_highlight_window)
1640 gdk_window_set_user_data (priv->drag_highlight_window, NULL);
1641 gdk_window_destroy (priv->drag_highlight_window);
1642 priv->drag_highlight_window = NULL;
1645 if (tree_view->priv->columns != NULL)
1647 list = tree_view->priv->columns;
1650 PsppSheetViewColumn *column;
1651 column = PSPP_SHEET_VIEW_COLUMN (list->data);
1653 pspp_sheet_view_remove_column (tree_view, column);
1655 tree_view->priv->columns = NULL;
1659 /* GtkWidget::size_request helper */
1661 pspp_sheet_view_size_request_columns (PsppSheetView *tree_view)
1665 tree_view->priv->header_height = 0;
1667 if (tree_view->priv->model)
1669 for (list = tree_view->priv->columns; list; list = list->next)
1671 GtkRequisition requisition;
1672 PsppSheetViewColumn *column = list->data;
1674 pspp_sheet_view_column_size_request (column, &requisition);
1675 column->button_request = requisition.width;
1676 tree_view->priv->header_height = MAX (tree_view->priv->header_height, requisition.height);
1682 /* Called only by ::size_request */
1684 pspp_sheet_view_update_size (PsppSheetView *tree_view)
1687 PsppSheetViewColumn *column;
1690 if (tree_view->priv->model == NULL)
1692 tree_view->priv->width = 0;
1693 tree_view->priv->prev_width = 0;
1694 tree_view->priv->height = 0;
1698 tree_view->priv->prev_width = tree_view->priv->width;
1699 tree_view->priv->width = 0;
1701 /* keep this in sync with size_allocate below */
1702 for (list = tree_view->priv->columns, i = 0; list; list = list->next, i++)
1704 gint real_requested_width = 0;
1705 column = list->data;
1706 if (!column->visible)
1709 if (column->use_resized_width)
1711 real_requested_width = column->resized_width;
1715 real_requested_width = column->fixed_width;
1718 if (column->min_width != -1)
1719 real_requested_width = MAX (real_requested_width, column->min_width);
1720 if (column->max_width != -1)
1721 real_requested_width = MIN (real_requested_width, column->max_width);
1723 tree_view->priv->width += real_requested_width;
1726 tree_view->priv->height = tree_view->priv->fixed_height * tree_view->priv->row_count;
1730 pspp_sheet_view_size_request (GtkWidget *widget,
1731 GtkRequisition *requisition)
1733 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1736 /* we validate some rows initially just to make sure we have some size.
1737 * In practice, with a lot of static lists, this should get a good width.
1739 initialize_fixed_height_mode (tree_view);
1740 pspp_sheet_view_size_request_columns (tree_view);
1741 pspp_sheet_view_update_size (PSPP_SHEET_VIEW (widget));
1743 requisition->width = tree_view->priv->width;
1744 requisition->height = tree_view->priv->height + TREE_VIEW_HEADER_HEIGHT (tree_view);
1746 tmp_list = tree_view->priv->children;
1750 PsppSheetViewChild *child = tmp_list->data;
1751 GtkRequisition child_requisition;
1753 tmp_list = tmp_list->next;
1755 if (gtk_widget_get_visible (child->widget))
1756 gtk_widget_size_request (child->widget, &child_requisition);
1761 invalidate_column (PsppSheetView *tree_view,
1762 PsppSheetViewColumn *column)
1764 gint column_offset = 0;
1766 GtkWidget *widget = GTK_WIDGET (tree_view);
1769 if (!gtk_widget_get_realized (widget))
1772 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
1773 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
1775 list = (rtl ? list->prev : list->next))
1777 PsppSheetViewColumn *tmpcolumn = list->data;
1778 if (tmpcolumn == column)
1780 GdkRectangle invalid_rect;
1781 GtkAllocation allocation;
1783 gtk_widget_get_allocation (widget, &allocation);
1784 invalid_rect.x = column_offset;
1786 invalid_rect.width = column->width;
1787 invalid_rect.height = allocation.height;
1789 gdk_window_invalidate_rect (gtk_widget_get_window (widget), &invalid_rect, TRUE);
1793 column_offset += tmpcolumn->width;
1798 invalidate_last_column (PsppSheetView *tree_view)
1803 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
1805 for (last_column = (rtl ? g_list_first (tree_view->priv->columns) : g_list_last (tree_view->priv->columns));
1807 last_column = (rtl ? last_column->next : last_column->prev))
1809 if (PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible)
1811 invalidate_column (tree_view, last_column->data);
1818 pspp_sheet_view_get_real_requested_width_from_column (PsppSheetView *tree_view,
1819 PsppSheetViewColumn *column)
1821 gint real_requested_width;
1823 if (column->use_resized_width)
1825 real_requested_width = column->resized_width;
1829 real_requested_width = column->fixed_width;
1832 if (column->min_width != -1)
1833 real_requested_width = MAX (real_requested_width, column->min_width);
1834 if (column->max_width != -1)
1835 real_requested_width = MIN (real_requested_width, column->max_width);
1837 return real_requested_width;
1841 span_intersects (int a0, int a_width,
1842 int b0, int b_width)
1844 int a1 = a0 + a_width;
1845 int b1 = b0 + b_width;
1846 return (a0 >= b0 && a0 < b1) || (b0 >= a0 && b0 < a1);
1849 /* GtkWidget::size_allocate helper */
1851 pspp_sheet_view_size_allocate_columns (GtkWidget *widget,
1852 gboolean *width_changed)
1854 PsppSheetView *tree_view;
1855 GList *list, *first_column, *last_column;
1856 PsppSheetViewColumn *column;
1857 GtkAllocation col_allocation;
1858 GtkAllocation allocation;
1860 gint extra, extra_per_column;
1861 gint full_requested_width = 0;
1862 gint number_of_expand_columns = 0;
1863 gboolean column_changed = FALSE;
1866 tree_view = PSPP_SHEET_VIEW (widget);
1868 for (last_column = g_list_last (tree_view->priv->columns);
1869 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
1870 last_column = last_column->prev)
1873 if (last_column == NULL)
1876 for (first_column = g_list_first (tree_view->priv->columns);
1877 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
1878 first_column = first_column->next)
1881 col_allocation.y = 0;
1882 col_allocation.height = tree_view->priv->header_height;
1884 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1886 /* find out how many extra space and expandable columns we have */
1887 for (list = tree_view->priv->columns; list != last_column->next; list = list->next)
1889 column = (PsppSheetViewColumn *)list->data;
1891 if (!column->visible)
1894 full_requested_width += pspp_sheet_view_get_real_requested_width_from_column (tree_view, column);
1897 number_of_expand_columns++;
1900 gtk_widget_get_allocation (widget, &allocation);
1901 extra = MAX (allocation.width - full_requested_width, 0);
1902 if (number_of_expand_columns > 0)
1903 extra_per_column = extra/number_of_expand_columns;
1905 extra_per_column = 0;
1907 for (list = (rtl ? last_column : first_column);
1908 list != (rtl ? first_column->prev : last_column->next);
1909 list = (rtl ? list->prev : list->next))
1911 gint real_requested_width = 0;
1914 column = list->data;
1915 old_width = column->width;
1917 if (!column->visible)
1920 /* We need to handle the dragged button specially.
1922 if (column == tree_view->priv->drag_column)
1924 GtkAllocation drag_allocation;
1925 drag_allocation.width = gdk_window_get_width (tree_view->priv->drag_window);
1926 drag_allocation.height = gdk_window_get_height (tree_view->priv->drag_window);
1927 drag_allocation.x = 0;
1928 drag_allocation.y = 0;
1929 pspp_sheet_view_column_size_allocate (tree_view->priv->drag_column,
1931 width += drag_allocation.width;
1935 real_requested_width = pspp_sheet_view_get_real_requested_width_from_column (tree_view, column);
1937 col_allocation.x = width;
1938 column->width = real_requested_width;
1942 if (number_of_expand_columns == 1)
1944 /* We add the remander to the last column as
1946 column->width += extra;
1950 column->width += extra_per_column;
1951 extra -= extra_per_column;
1952 number_of_expand_columns --;
1956 if (column->width != old_width)
1957 g_object_notify (G_OBJECT (column), "width");
1959 col_allocation.width = column->width;
1960 width += column->width;
1962 if (column->width > old_width)
1963 column_changed = TRUE;
1965 pspp_sheet_view_column_size_allocate (column, &col_allocation);
1967 if (span_intersects (col_allocation.x, col_allocation.width,
1968 gtk_adjustment_get_value (tree_view->priv->hadjustment),
1970 && gtk_widget_get_realized (widget))
1971 pspp_sheet_view_column_set_need_button (column, TRUE);
1974 gdk_window_move_resize (column->window,
1975 col_allocation.x + (rtl ? 0 : col_allocation.width) - TREE_VIEW_DRAG_WIDTH/2,
1977 TREE_VIEW_DRAG_WIDTH, col_allocation.height);
1980 /* We change the width here. The user might have been resizing columns,
1981 * so the total width of the tree view changes.
1983 tree_view->priv->width = width;
1985 *width_changed = TRUE;
1988 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
1992 pspp_sheet_view_size_allocate (GtkWidget *widget,
1993 GtkAllocation *allocation)
1995 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1997 gboolean width_changed = FALSE;
1998 GtkAllocation old_allocation;
1999 gtk_widget_get_allocation (widget, &old_allocation);
2001 if (allocation->width != old_allocation.width)
2002 width_changed = TRUE;
2005 gtk_widget_set_allocation (widget, allocation);
2007 tmp_list = tree_view->priv->children;
2011 GtkAllocation allocation;
2013 PsppSheetViewChild *child = tmp_list->data;
2014 tmp_list = tmp_list->next;
2016 /* totally ignore our child's requisition */
2017 allocation.x = child->x;
2018 allocation.y = child->y;
2019 allocation.width = child->width;
2020 allocation.height = child->height;
2021 gtk_widget_size_allocate (child->widget, &allocation);
2024 /* We size-allocate the columns first because the width of the
2025 * tree view (used in updating the adjustments below) might change.
2027 pspp_sheet_view_size_allocate_columns (widget, &width_changed);
2029 gtk_adjustment_set_page_size (tree_view->priv->hadjustment, allocation->width);
2030 gtk_adjustment_set_page_increment (tree_view->priv->hadjustment, allocation->width * 0.9);
2031 gtk_adjustment_set_step_increment (tree_view->priv->hadjustment, allocation->width * 0.1);
2032 gtk_adjustment_set_lower (tree_view->priv->hadjustment, 0);
2033 gtk_adjustment_set_upper (tree_view->priv->hadjustment, MAX (gtk_adjustment_get_page_size (tree_view->priv->hadjustment), tree_view->priv->width));
2035 if (gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL)
2037 if (allocation->width < tree_view->priv->width)
2039 if (tree_view->priv->init_hadjust_value)
2041 gtk_adjustment_set_value (tree_view->priv->hadjustment, MAX (tree_view->priv->width - allocation->width, 0));
2042 tree_view->priv->init_hadjust_value = FALSE;
2044 else if (allocation->width != old_allocation.width)
2046 gtk_adjustment_set_value (tree_view->priv->hadjustment, CLAMP (gtk_adjustment_get_value (tree_view->priv->hadjustment) - allocation->width + old_allocation.width, 0, tree_view->priv->width - allocation->width));
2049 gtk_adjustment_set_value (tree_view->priv->hadjustment, CLAMP (tree_view->priv->width - (tree_view->priv->prev_width - gtk_adjustment_get_value (tree_view->priv->hadjustment)), 0, tree_view->priv->width - allocation->width));
2053 gtk_adjustment_set_value (tree_view->priv->hadjustment, 0);
2054 tree_view->priv->init_hadjust_value = TRUE;
2058 if (gtk_adjustment_get_value (tree_view->priv->hadjustment) + allocation->width > tree_view->priv->width)
2059 gtk_adjustment_set_value (tree_view->priv->hadjustment, MAX (tree_view->priv->width - allocation->width, 0));
2061 gtk_adjustment_changed (tree_view->priv->hadjustment);
2063 gtk_adjustment_set_page_size (tree_view->priv->vadjustment, allocation->height - TREE_VIEW_HEADER_HEIGHT (tree_view));
2064 gtk_adjustment_set_step_increment (tree_view->priv->vadjustment, gtk_adjustment_get_page_size (tree_view->priv->vadjustment) * 0.1);
2065 gtk_adjustment_set_page_increment (tree_view->priv->vadjustment, gtk_adjustment_get_page_size (tree_view->priv->vadjustment) * 0.9);
2066 gtk_adjustment_set_lower (tree_view->priv->vadjustment, 0);
2067 gtk_adjustment_set_upper (tree_view->priv->vadjustment, MAX (gtk_adjustment_get_page_size (tree_view->priv->vadjustment), tree_view->priv->height));
2069 gtk_adjustment_changed (tree_view->priv->vadjustment);
2071 /* now the adjustments and window sizes are in sync, we can sync toprow/dy again */
2072 if (tree_view->priv->height <= gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
2073 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment), 0);
2074 else if (gtk_adjustment_get_value (tree_view->priv->vadjustment) + gtk_adjustment_get_page_size (tree_view->priv->vadjustment) > tree_view->priv->height)
2075 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment),
2076 tree_view->priv->height - gtk_adjustment_get_page_size (tree_view->priv->vadjustment));
2077 else if (gtk_tree_row_reference_valid (tree_view->priv->top_row))
2078 pspp_sheet_view_top_row_to_dy (tree_view);
2080 pspp_sheet_view_dy_to_top_row (tree_view);
2082 if (gtk_widget_get_realized (widget))
2084 gdk_window_move_resize (gtk_widget_get_window (widget),
2085 allocation->x, allocation->y,
2086 allocation->width, allocation->height);
2087 gdk_window_move_resize (tree_view->priv->header_window,
2088 - (gint) gtk_adjustment_get_value (tree_view->priv->hadjustment),
2090 MAX (tree_view->priv->width, allocation->width),
2091 tree_view->priv->header_height);
2092 gdk_window_move_resize (tree_view->priv->bin_window,
2093 - (gint) gtk_adjustment_get_value (tree_view->priv->hadjustment),
2094 TREE_VIEW_HEADER_HEIGHT (tree_view),
2095 MAX (tree_view->priv->width, allocation->width),
2096 allocation->height - TREE_VIEW_HEADER_HEIGHT (tree_view));
2099 if (tree_view->priv->row_count == 0)
2100 invalidate_empty_focus (tree_view);
2102 if (gtk_widget_get_realized (widget))
2104 gboolean has_expand_column = FALSE;
2105 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
2107 if (pspp_sheet_view_column_get_expand (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)))
2109 has_expand_column = TRUE;
2114 /* This little hack only works if we have an LTR locale, and no column has the */
2117 if (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_LTR &&
2118 ! has_expand_column)
2119 invalidate_last_column (tree_view);
2121 gtk_widget_queue_draw (widget);
2126 /* Grabs the focus and unsets the PSPP_SHEET_VIEW_DRAW_KEYFOCUS flag */
2128 grab_focus_and_unset_draw_keyfocus (PsppSheetView *tree_view)
2130 GtkWidget *widget = GTK_WIDGET (tree_view);
2132 if (gtk_widget_get_can_focus (widget) && !gtk_widget_has_focus (widget))
2133 gtk_widget_grab_focus (widget);
2134 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
2138 pspp_sheet_view_node_is_selected (PsppSheetView *tree_view,
2141 return node >= 0 && range_tower_contains (tree_view->priv->selected, node);
2145 pspp_sheet_view_node_select (PsppSheetView *tree_view,
2148 range_tower_set1 (tree_view->priv->selected, node, 1);
2152 pspp_sheet_view_node_unselect (PsppSheetView *tree_view,
2155 range_tower_set0 (tree_view->priv->selected, node, 1);
2159 pspp_sheet_view_node_next (PsppSheetView *tree_view,
2162 return node + 1 < tree_view->priv->row_count ? node + 1 : -1;
2166 pspp_sheet_view_node_prev (PsppSheetView *tree_view,
2169 return node > 0 ? node - 1 : -1;
2173 all_columns_selected (PsppSheetView *tree_view)
2177 for (list = tree_view->priv->columns; list; list = list->next)
2179 PsppSheetViewColumn *column = list->data;
2180 if (column->selectable && !column->selected)
2188 pspp_sheet_view_row_head_clicked (PsppSheetView *tree_view,
2190 PsppSheetViewColumn *column,
2191 GdkEventButton *event)
2193 PsppSheetSelection *selection;
2194 PsppSheetSelectionMode mode;
2196 gboolean update_anchor;
2200 g_return_val_if_fail (tree_view != NULL, FALSE);
2201 g_return_val_if_fail (column != NULL, FALSE);
2203 selection = tree_view->priv->selection;
2204 mode = pspp_sheet_selection_get_mode (selection);
2205 if (mode != PSPP_SHEET_SELECTION_RECTANGLE)
2208 if (!column->row_head)
2213 modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
2214 if (event->type != GDK_BUTTON_PRESS
2215 || (modifiers != GDK_CONTROL_MASK && modifiers != GDK_SHIFT_MASK))
2221 path = gtk_tree_path_new_from_indices (node, -1);
2224 pspp_sheet_selection_unselect_all (selection);
2225 pspp_sheet_selection_select_path (selection, path);
2226 pspp_sheet_selection_select_all_columns (selection);
2227 update_anchor = TRUE;
2230 else if (event->type == GDK_BUTTON_PRESS && event->button == 3)
2232 if (pspp_sheet_selection_count_selected_rows (selection) <= 1
2233 || !all_columns_selected (tree_view))
2235 pspp_sheet_selection_unselect_all (selection);
2236 pspp_sheet_selection_select_path (selection, path);
2237 pspp_sheet_selection_select_all_columns (selection);
2238 update_anchor = TRUE;
2242 update_anchor = handled = FALSE;
2244 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
2245 && modifiers == GDK_CONTROL_MASK)
2247 if (!all_columns_selected (tree_view))
2249 pspp_sheet_selection_unselect_all (selection);
2250 pspp_sheet_selection_select_all_columns (selection);
2253 if (pspp_sheet_selection_path_is_selected (selection, path))
2254 pspp_sheet_selection_unselect_path (selection, path);
2256 pspp_sheet_selection_select_path (selection, path);
2257 update_anchor = TRUE;
2260 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
2261 && modifiers == GDK_SHIFT_MASK)
2263 GtkTreeRowReference *anchor = tree_view->priv->anchor;
2264 GtkTreePath *anchor_path;
2266 if (all_columns_selected (tree_view)
2267 && gtk_tree_row_reference_valid (anchor))
2269 update_anchor = FALSE;
2270 anchor_path = gtk_tree_row_reference_get_path (anchor);
2274 update_anchor = TRUE;
2275 anchor_path = gtk_tree_path_copy (path);
2278 pspp_sheet_selection_unselect_all (selection);
2279 pspp_sheet_selection_select_range (selection, anchor_path, path);
2280 pspp_sheet_selection_select_all_columns (selection);
2282 gtk_tree_path_free (anchor_path);
2287 update_anchor = handled = FALSE;
2291 if (tree_view->priv->anchor)
2292 gtk_tree_row_reference_free (tree_view->priv->anchor);
2293 tree_view->priv->anchor =
2294 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
2295 tree_view->priv->model,
2299 gtk_tree_path_free (path);
2304 find_click (PsppSheetView *tree_view,
2307 PsppSheetViewColumn **column,
2308 GdkRectangle *background_area,
2309 GdkRectangle *cell_area)
2316 /* find the node that was clicked */
2317 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, y);
2320 y_offset = -pspp_sheet_view_find_offset (tree_view, new_y, node);
2325 background_area->y = y_offset + y;
2326 background_area->height = ROW_HEIGHT (tree_view);
2327 background_area->x = 0;
2329 /* Let the column have a chance at selecting it. */
2330 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
2331 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
2332 list; list = (rtl ? list->prev : list->next))
2334 PsppSheetViewColumn *candidate = list->data;
2336 if (!candidate->visible)
2339 background_area->width = candidate->width;
2340 if ((background_area->x > x) ||
2341 (background_area->x + background_area->width <= x))
2343 background_area->x += background_area->width;
2347 /* we found the focus column */
2349 pspp_sheet_view_adjust_cell_area (tree_view, candidate, background_area,
2351 *column = candidate;
2359 pspp_sheet_view_button_press (GtkWidget *widget,
2360 GdkEventButton *event)
2362 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2364 PsppSheetViewColumn *column = NULL;
2366 GdkRectangle background_area;
2367 GdkRectangle cell_area;
2370 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
2371 pspp_sheet_view_stop_editing (tree_view, FALSE);
2374 /* Because grab_focus can cause reentrancy, we delay grab_focus until after
2375 * we're done handling the button press.
2378 if (event->window == tree_view->priv->bin_window)
2383 gint pre_val, aft_val;
2384 PsppSheetViewColumn *column = NULL;
2385 GtkCellRenderer *focus_cell = NULL;
2386 gboolean row_double_click = FALSE;
2389 if (tree_view->priv->row_count == 0)
2391 grab_focus_and_unset_draw_keyfocus (tree_view);
2395 if (!find_click (tree_view, event->x, event->y, &node, &column,
2396 &background_area, &cell_area))
2398 grab_focus_and_unset_draw_keyfocus (tree_view);
2402 tree_view->priv->focus_column = column;
2404 if (pspp_sheet_view_row_head_clicked (tree_view, node, column, event))
2408 pre_val = gtk_adjustment_get_value (tree_view->priv->vadjustment);
2410 path = _pspp_sheet_view_find_path (tree_view, node);
2412 /* we only handle selection modifications on the first button press
2414 if (event->type == GDK_BUTTON_PRESS)
2416 PsppSheetSelectionMode mode = 0;
2418 if ((event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
2419 mode |= PSPP_SHEET_SELECT_MODE_TOGGLE;
2420 if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
2421 mode |= PSPP_SHEET_SELECT_MODE_EXTEND;
2423 focus_cell = _pspp_sheet_view_column_get_cell_at_pos (column, event->x - background_area.x);
2425 pspp_sheet_view_column_focus_cell (column, focus_cell);
2427 if (event->state & GDK_CONTROL_MASK)
2429 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE, mode);
2430 pspp_sheet_view_real_toggle_cursor_row (tree_view);
2432 else if (event->state & GDK_SHIFT_MASK)
2434 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, mode);
2435 pspp_sheet_view_real_select_cursor_row (tree_view, FALSE, mode);
2439 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, 0);
2442 if (tree_view->priv->anchor_column == NULL ||
2443 !(event->state & GDK_SHIFT_MASK))
2444 tree_view->priv->anchor_column = column;
2445 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
2446 pspp_sheet_selection_select_column_range (tree_view->priv->selection,
2447 tree_view->priv->anchor_column,
2451 /* the treeview may have been scrolled because of _set_cursor,
2455 aft_val = gtk_adjustment_get_value (tree_view->priv->vadjustment);
2456 dval = pre_val - aft_val;
2458 cell_area.y += dval;
2459 background_area.y += dval;
2461 /* Save press to possibly begin a drag
2463 if (!tree_view->priv->in_grab &&
2464 tree_view->priv->pressed_button < 0)
2466 tree_view->priv->pressed_button = event->button;
2467 tree_view->priv->press_start_x = event->x;
2468 tree_view->priv->press_start_y = event->y;
2469 tree_view->priv->press_start_node = node;
2471 if (tree_view->priv->rubber_banding_enable
2472 && (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
2473 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE))
2475 tree_view->priv->press_start_y += tree_view->priv->dy;
2476 tree_view->priv->rubber_band_x = event->x;
2477 tree_view->priv->rubber_band_y = event->y + tree_view->priv->dy;
2478 tree_view->priv->rubber_band_status = RUBBER_BAND_MAYBE_START;
2480 if ((event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
2481 tree_view->priv->rubber_band_ctrl = TRUE;
2482 if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
2483 tree_view->priv->rubber_band_shift = TRUE;
2488 /* Test if a double click happened on the same row. */
2489 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
2491 int double_click_time, double_click_distance;
2493 g_object_get (gtk_settings_get_for_screen (
2494 gtk_widget_get_screen (widget)),
2495 "gtk-double-click-time", &double_click_time,
2496 "gtk-double-click-distance", &double_click_distance,
2499 /* Same conditions as _gdk_event_button_generate */
2500 if (tree_view->priv->last_button_x != -1 &&
2501 (event->time < tree_view->priv->last_button_time + double_click_time) &&
2502 (ABS (event->x - tree_view->priv->last_button_x) <= double_click_distance) &&
2503 (ABS (event->y - tree_view->priv->last_button_y) <= double_click_distance))
2505 /* We do no longer compare paths of this row and the
2506 * row clicked previously. We use the double click
2507 * distance to decide whether this is a valid click,
2508 * allowing the mouse to slightly move over another row.
2510 row_double_click = TRUE;
2512 tree_view->priv->last_button_time = 0;
2513 tree_view->priv->last_button_x = -1;
2514 tree_view->priv->last_button_y = -1;
2518 tree_view->priv->last_button_time = event->time;
2519 tree_view->priv->last_button_x = event->x;
2520 tree_view->priv->last_button_y = event->y;
2524 if (row_double_click)
2526 gtk_grab_remove (widget);
2527 pspp_sheet_view_row_activated (tree_view, path, column);
2529 if (tree_view->priv->pressed_button == event->button)
2530 tree_view->priv->pressed_button = -1;
2533 gtk_tree_path_free (path);
2535 /* If we activated the row through a double click we don't want to grab
2536 * focus back, as moving focus to another widget is pretty common.
2538 if (!row_double_click)
2539 grab_focus_and_unset_draw_keyfocus (tree_view);
2544 /* We didn't click in the window. Let's check to see if we clicked on a column resize window.
2546 for (i = 0, list = tree_view->priv->columns; list; list = list->next, i++)
2548 column = list->data;
2549 if (event->window == column->window &&
2550 column->resizable &&
2555 if (gdk_pointer_grab (column->window, FALSE,
2556 GDK_POINTER_MOTION_HINT_MASK |
2557 GDK_BUTTON1_MOTION_MASK |
2558 GDK_BUTTON_RELEASE_MASK,
2559 NULL, NULL, event->time))
2562 gtk_grab_add (widget);
2563 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE);
2564 column->resized_width = column->width;
2566 /* block attached dnd signal handler */
2567 drag_data = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
2569 g_signal_handlers_block_matched (widget,
2570 G_SIGNAL_MATCH_DATA,
2574 tree_view->priv->drag_pos = i;
2575 tree_view->priv->x_drag = column->allocation.x + (rtl ? 0 : column->allocation.width);
2577 if (!gtk_widget_has_focus (widget))
2578 gtk_widget_grab_focus (widget);
2586 /* GtkWidget::button_release_event helper */
2588 pspp_sheet_view_button_release_drag_column (GtkWidget *widget,
2589 GdkEventButton *event)
2591 PsppSheetView *tree_view;
2595 tree_view = PSPP_SHEET_VIEW (widget);
2597 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
2598 gdk_display_pointer_ungrab (gtk_widget_get_display (widget), GDK_CURRENT_TIME);
2599 gdk_display_keyboard_ungrab (gtk_widget_get_display (widget), GDK_CURRENT_TIME);
2601 /* Move the button back */
2602 g_return_val_if_fail (tree_view->priv->drag_column->button, FALSE);
2604 g_object_ref (tree_view->priv->drag_column->button);
2605 gtk_container_remove (GTK_CONTAINER (tree_view), tree_view->priv->drag_column->button);
2606 gtk_widget_set_parent_window (tree_view->priv->drag_column->button, tree_view->priv->header_window);
2607 gtk_widget_set_parent (tree_view->priv->drag_column->button, GTK_WIDGET (tree_view));
2608 g_object_unref (tree_view->priv->drag_column->button);
2609 gtk_widget_queue_resize (widget);
2610 if (tree_view->priv->drag_column->resizable)
2612 gdk_window_raise (tree_view->priv->drag_column->window);
2613 gdk_window_show (tree_view->priv->drag_column->window);
2616 gdk_window_hide (tree_view->priv->drag_column->window);
2618 gtk_widget_grab_focus (tree_view->priv->drag_column->button);
2622 if (tree_view->priv->cur_reorder &&
2623 tree_view->priv->cur_reorder->right_column != tree_view->priv->drag_column)
2624 pspp_sheet_view_move_column_after (tree_view, tree_view->priv->drag_column,
2625 tree_view->priv->cur_reorder->right_column);
2629 if (tree_view->priv->cur_reorder &&
2630 tree_view->priv->cur_reorder->left_column != tree_view->priv->drag_column)
2631 pspp_sheet_view_move_column_after (tree_view, tree_view->priv->drag_column,
2632 tree_view->priv->cur_reorder->left_column);
2634 tree_view->priv->drag_column = NULL;
2635 gdk_window_hide (tree_view->priv->drag_window);
2637 for (l = tree_view->priv->column_drag_info; l != NULL; l = l->next)
2638 g_slice_free (PsppSheetViewColumnReorder, l->data);
2639 g_list_free (tree_view->priv->column_drag_info);
2640 tree_view->priv->column_drag_info = NULL;
2641 tree_view->priv->cur_reorder = NULL;
2643 if (tree_view->priv->drag_highlight_window)
2644 gdk_window_hide (tree_view->priv->drag_highlight_window);
2646 /* Reset our flags */
2647 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_UNSET;
2648 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG);
2653 /* GtkWidget::button_release_event helper */
2655 pspp_sheet_view_button_release_column_resize (GtkWidget *widget,
2656 GdkEventButton *event)
2658 PsppSheetView *tree_view;
2661 tree_view = PSPP_SHEET_VIEW (widget);
2663 tree_view->priv->drag_pos = -1;
2665 /* unblock attached dnd signal handler */
2666 drag_data = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
2668 g_signal_handlers_unblock_matched (widget,
2669 G_SIGNAL_MATCH_DATA,
2673 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE);
2674 gtk_grab_remove (widget);
2675 gdk_display_pointer_ungrab (gdk_window_get_display (event->window),
2681 pspp_sheet_view_button_release_edit (PsppSheetView *tree_view,
2682 GdkEventButton *event)
2684 GtkCellEditable *cell_editable;
2689 PsppSheetViewColumn *column;
2690 GdkRectangle background_area;
2691 GdkRectangle cell_area;
2697 if (event->window != tree_view->priv->bin_window)
2700 /* Ignore a released button, if that button wasn't depressed */
2701 if (tree_view->priv->pressed_button != event->button)
2704 if (!find_click (tree_view, event->x, event->y, &node, &column, &background_area,
2708 /* decide if we edit */
2709 path = _pspp_sheet_view_find_path (tree_view, node);
2710 modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
2711 if (event->button != 1 || modifiers)
2714 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
2715 pspp_sheet_view_column_cell_set_cell_data (column,
2716 tree_view->priv->model,
2719 if (!pspp_sheet_view_column_get_quick_edit (column)
2720 && _pspp_sheet_view_column_has_editable_cell (column))
2723 flags = 0; /* FIXME: get the right flags */
2724 path_string = gtk_tree_path_to_string (path);
2726 if (!_pspp_sheet_view_column_cell_event (column,
2734 if (cell_editable == NULL)
2737 pspp_sheet_view_real_set_cursor (tree_view, path,
2738 TRUE, TRUE, 0); /* XXX mode? */
2739 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
2742 _pspp_sheet_view_column_get_neighbor_sizes (
2743 column, _pspp_sheet_view_column_get_edited_cell (column), &left, &right);
2746 area.width -= right + left;
2748 pspp_sheet_view_real_start_editing (tree_view,
2755 g_free (path_string);
2756 gtk_tree_path_free (path);
2761 pspp_sheet_view_button_release (GtkWidget *widget,
2762 GdkEventButton *event)
2764 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2766 pspp_sheet_view_stop_editing (tree_view, FALSE);
2767 if (tree_view->priv->rubber_band_status != RUBBER_BAND_ACTIVE
2768 && pspp_sheet_view_button_release_edit (tree_view, event))
2770 if (tree_view->priv->pressed_button == event->button)
2771 tree_view->priv->pressed_button = -1;
2773 tree_view->priv->rubber_band_status = RUBBER_BAND_OFF;
2777 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
2778 return pspp_sheet_view_button_release_drag_column (widget, event);
2780 if (tree_view->priv->rubber_band_status)
2781 pspp_sheet_view_stop_rubber_band (tree_view);
2783 if (tree_view->priv->pressed_button == event->button)
2784 tree_view->priv->pressed_button = -1;
2786 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
2787 return pspp_sheet_view_button_release_column_resize (widget, event);
2793 pspp_sheet_view_grab_broken (GtkWidget *widget,
2794 GdkEventGrabBroken *event)
2796 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2798 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
2799 pspp_sheet_view_button_release_drag_column (widget, (GdkEventButton *)event);
2801 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
2802 pspp_sheet_view_button_release_column_resize (widget, (GdkEventButton *)event);
2807 /* GtkWidget::motion_event function set.
2811 do_prelight (PsppSheetView *tree_view,
2813 /* these are in bin_window coords */
2817 int prev_node = tree_view->priv->prelight_node;
2819 if (prev_node != node)
2821 tree_view->priv->prelight_node = node;
2824 _pspp_sheet_view_queue_draw_node (tree_view, prev_node, NULL);
2827 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
2833 prelight_or_select (PsppSheetView *tree_view,
2835 /* these are in bin_window coords */
2839 PsppSheetSelectionMode mode = pspp_sheet_selection_get_mode (tree_view->priv->selection);
2841 if (tree_view->priv->hover_selection &&
2842 (mode == PSPP_SHEET_SELECTION_SINGLE || mode == PSPP_SHEET_SELECTION_BROWSE) &&
2843 !(tree_view->priv->edited_column &&
2844 tree_view->priv->edited_column->editable_widget))
2848 if (!pspp_sheet_view_node_is_selected (tree_view, node))
2852 path = _pspp_sheet_view_find_path (tree_view, node);
2853 pspp_sheet_selection_select_path (tree_view->priv->selection, path);
2854 if (pspp_sheet_view_node_is_selected (tree_view, node))
2856 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
2857 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, FALSE, 0); /* XXX mode? */
2859 gtk_tree_path_free (path);
2863 else if (mode == PSPP_SHEET_SELECTION_SINGLE)
2864 pspp_sheet_selection_unselect_all (tree_view->priv->selection);
2867 do_prelight (tree_view, node, x, y);
2871 ensure_unprelighted (PsppSheetView *tree_view)
2873 do_prelight (tree_view,
2875 -1000, -1000); /* coords not possibly over an arrow */
2877 g_assert (tree_view->priv->prelight_node < 0);
2881 update_prelight (PsppSheetView *tree_view,
2888 if (tree_view->priv->row_count == 0)
2893 ensure_unprelighted (tree_view);
2897 new_y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, y);
2901 pspp_sheet_view_find_offset (tree_view, new_y, &node);
2904 prelight_or_select (tree_view, node, x, y);
2910 /* Our motion arrow is either a box (in the case of the original spot)
2911 * or an arrow. It is expander_size wide.
2934 pspp_sheet_view_motion_draw_column_motion_arrow (PsppSheetView *tree_view)
2937 PsppSheetViewColumnReorder *reorder = tree_view->priv->cur_reorder;
2938 GtkWidget *widget = GTK_WIDGET (tree_view);
2939 GdkBitmap *mask = NULL;
2944 gint arrow_type = DRAG_COLUMN_WINDOW_STATE_UNSET;
2945 GdkWindowAttr attributes;
2946 guint attributes_mask;
2949 reorder->left_column == tree_view->priv->drag_column ||
2950 reorder->right_column == tree_view->priv->drag_column)
2951 arrow_type = DRAG_COLUMN_WINDOW_STATE_ORIGINAL;
2952 else if (reorder->left_column || reorder->right_column)
2954 GdkRectangle visible_rect;
2955 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
2956 if (reorder->left_column)
2957 x = reorder->left_column->allocation.x + reorder->left_column->allocation.width;
2959 x = reorder->right_column->allocation.x;
2961 if (x < visible_rect.x)
2962 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT;
2963 else if (x > visible_rect.x + visible_rect.width)
2964 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT;
2966 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW;
2969 /* We want to draw the rectangle over the initial location. */
2970 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ORIGINAL)
2975 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ORIGINAL)
2977 if (tree_view->priv->drag_highlight_window)
2979 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
2981 gdk_window_destroy (tree_view->priv->drag_highlight_window);
2984 attributes.window_type = GDK_WINDOW_CHILD;
2985 attributes.wclass = GDK_INPUT_OUTPUT;
2986 attributes.x = tree_view->priv->drag_column_x;
2988 width = attributes.width = tree_view->priv->drag_column->allocation.width;
2989 height = attributes.height = tree_view->priv->drag_column->allocation.height;
2990 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
2991 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
2992 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
2993 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2994 tree_view->priv->drag_highlight_window = gdk_window_new (tree_view->priv->header_window, &attributes, attributes_mask);
2995 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
2997 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
2998 gc = gdk_gc_new (mask);
3000 gdk_gc_set_foreground (gc, &col);
3001 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
3003 gdk_gc_set_foreground(gc, &col);
3004 gdk_draw_rectangle (mask, gc, TRUE, 2, 2, width - 4, height - 4);
3005 g_object_unref (gc);
3007 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
3009 if (mask) g_object_unref (mask);
3010 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_ORIGINAL;
3013 else if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW)
3019 width = tree_view->priv->expander_size;
3021 /* Get x, y, width, height of arrow */
3022 gdk_window_get_origin (tree_view->priv->header_window, &x, &y);
3023 if (reorder->left_column)
3025 x += reorder->left_column->allocation.x + reorder->left_column->allocation.width - width/2;
3026 height = reorder->left_column->allocation.height;
3030 x += reorder->right_column->allocation.x - width/2;
3031 height = reorder->right_column->allocation.height;
3033 y -= tree_view->priv->expander_size/2; /* The arrow takes up only half the space */
3034 height += tree_view->priv->expander_size;
3036 /* Create the new window */
3037 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW)
3039 if (tree_view->priv->drag_highlight_window)
3041 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
3043 gdk_window_destroy (tree_view->priv->drag_highlight_window);
3046 attributes.window_type = GDK_WINDOW_TEMP;
3047 attributes.wclass = GDK_INPUT_OUTPUT;
3048 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
3049 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
3050 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
3051 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
3054 attributes.width = width;
3055 attributes.height = height;
3056 tree_view->priv->drag_highlight_window = gdk_window_new (gtk_widget_get_root_window (widget),
3057 &attributes, attributes_mask);
3058 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
3060 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
3061 gc = gdk_gc_new (mask);
3063 gdk_gc_set_foreground (gc, &col);
3064 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
3066 /* Draw the 2 arrows as per above */
3068 gdk_gc_set_foreground (gc, &col);
3069 for (i = 0; i < width; i ++)
3071 if (i == (width/2 - 1))
3073 gdk_draw_line (mask, gc, i, j, i, height - j);
3074 if (i < (width/2 - 1))
3079 g_object_unref (gc);
3080 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
3082 if (mask) g_object_unref (mask);
3085 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_ARROW;
3086 gdk_window_move (tree_view->priv->drag_highlight_window, x, y);
3088 else if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT ||
3089 arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3095 width = tree_view->priv->expander_size;
3097 /* Get x, y, width, height of arrow */
3098 width = width/2; /* remember, the arrow only takes half the available width */
3099 gdk_window_get_origin (gtk_widget_get_window (widget), &x, &y);
3100 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3101 x += widget->allocation.width - width;
3103 if (reorder->left_column)
3104 height = reorder->left_column->allocation.height;
3106 height = reorder->right_column->allocation.height;
3108 y -= tree_view->priv->expander_size;
3109 height += 2*tree_view->priv->expander_size;
3111 /* Create the new window */
3112 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT &&
3113 tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3115 if (tree_view->priv->drag_highlight_window)
3117 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
3119 gdk_window_destroy (tree_view->priv->drag_highlight_window);
3122 attributes.window_type = GDK_WINDOW_TEMP;
3123 attributes.wclass = GDK_INPUT_OUTPUT;
3124 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
3125 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
3126 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
3127 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
3130 attributes.width = width;
3131 attributes.height = height;
3132 tree_view->priv->drag_highlight_window = gdk_window_new (NULL, &attributes, attributes_mask);
3133 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
3135 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
3136 gc = gdk_gc_new (mask);
3138 gdk_gc_set_foreground (gc, &col);
3139 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
3141 /* Draw the 2 arrows as per above */
3143 gdk_gc_set_foreground (gc, &col);
3144 j = tree_view->priv->expander_size;
3145 for (i = 0; i < width; i ++)
3148 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT)
3152 gdk_draw_line (mask, gc, k, j, k, height - j);
3153 gdk_draw_line (mask, gc, k, 0, k, tree_view->priv->expander_size - j);
3154 gdk_draw_line (mask, gc, k, height, k, height - tree_view->priv->expander_size + j);
3157 g_object_unref (gc);
3158 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
3160 if (mask) g_object_unref (mask);
3163 tree_view->priv->drag_column_window_state = arrow_type;
3164 gdk_window_move (tree_view->priv->drag_highlight_window, x, y);
3168 g_warning (G_STRLOC"Invalid PsppSheetViewColumnReorder struct");
3169 gdk_window_hide (tree_view->priv->drag_highlight_window);
3173 gdk_window_show (tree_view->priv->drag_highlight_window);
3174 gdk_window_raise (tree_view->priv->drag_highlight_window);
3179 pspp_sheet_view_motion_resize_column (GtkWidget *widget,
3180 GdkEventMotion *event)
3184 PsppSheetViewColumn *column;
3185 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
3187 column = pspp_sheet_view_get_column (tree_view, tree_view->priv->drag_pos);
3189 if (event->is_hint || event->window != gtk_widget_get_window (widget))
3190 gtk_widget_get_pointer (widget, &x, NULL);
3194 if (tree_view->priv->hadjustment)
3195 x += gtk_adjustment_get_value (tree_view->priv->hadjustment);
3197 new_width = pspp_sheet_view_new_column_width (tree_view,
3198 tree_view->priv->drag_pos, &x);
3199 if (x != tree_view->priv->x_drag &&
3200 (new_width != column->fixed_width))
3202 column->use_resized_width = TRUE;
3203 column->resized_width = new_width;
3206 column->resized_width -= tree_view->priv->last_extra_space_per_column;
3208 gtk_widget_queue_resize (widget);
3216 pspp_sheet_view_update_current_reorder (PsppSheetView *tree_view)
3218 PsppSheetViewColumnReorder *reorder = NULL;
3222 gdk_window_get_pointer (tree_view->priv->header_window, &mouse_x, NULL, NULL);
3223 for (list = tree_view->priv->column_drag_info; list; list = list->next)
3225 reorder = (PsppSheetViewColumnReorder *) list->data;
3226 if (mouse_x >= reorder->left_align && mouse_x < reorder->right_align)
3231 /* if (reorder && reorder == tree_view->priv->cur_reorder)
3234 tree_view->priv->cur_reorder = reorder;
3235 pspp_sheet_view_motion_draw_column_motion_arrow (tree_view);
3239 pspp_sheet_view_vertical_autoscroll (PsppSheetView *tree_view)
3241 GdkRectangle visible_rect;
3246 gdk_window_get_pointer (tree_view->priv->bin_window, NULL, &y, NULL);
3247 y += tree_view->priv->dy;
3249 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
3251 /* see if we are near the edge. */
3252 offset = y - (visible_rect.y + 2 * SCROLL_EDGE_SIZE);
3255 offset = y - (visible_rect.y + visible_rect.height - 2 * SCROLL_EDGE_SIZE);
3260 value = CLAMP (gtk_adjustment_get_value (tree_view->priv->vadjustment) + offset, 0.0,
3261 gtk_adjustment_get_upper (tree_view->priv->vadjustment) - gtk_adjustment_get_page_size (tree_view->priv->vadjustment));
3262 gtk_adjustment_set_value (tree_view->priv->vadjustment, value);
3266 pspp_sheet_view_horizontal_autoscroll (PsppSheetView *tree_view)
3268 GdkRectangle visible_rect;
3273 gdk_window_get_pointer (tree_view->priv->bin_window, &x, NULL, NULL);
3275 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
3277 /* See if we are near the edge. */
3278 offset = x - (visible_rect.x + SCROLL_EDGE_SIZE);
3281 offset = x - (visible_rect.x + visible_rect.width - SCROLL_EDGE_SIZE);
3287 value = CLAMP (gtk_adjustment_get_value (tree_view->priv->hadjustment) + offset,
3288 0.0, gtk_adjustment_get_upper (tree_view->priv->hadjustment) - gtk_adjustment_get_page_size (tree_view->priv->hadjustment));
3289 gtk_adjustment_set_value (tree_view->priv->hadjustment, value);
3296 pspp_sheet_view_motion_drag_column (GtkWidget *widget,
3297 GdkEventMotion *event)
3299 PsppSheetView *tree_view = (PsppSheetView *) widget;
3300 PsppSheetViewColumn *column = tree_view->priv->drag_column;
3302 GtkAllocation allocation;
3305 if ((column == NULL) ||
3306 (event->window != tree_view->priv->drag_window))
3309 /* Handle moving the header */
3310 gdk_window_get_position (tree_view->priv->drag_window, &x, &y);
3311 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
3312 x = CLAMP (x + (gint)event->x - column->drag_x, 0,
3313 MAX (tree_view->priv->width, allocation.width) - column->allocation.width);
3314 gdk_window_move (tree_view->priv->drag_window, x, y);
3316 /* autoscroll, if needed */
3317 pspp_sheet_view_horizontal_autoscroll (tree_view);
3318 /* Update the current reorder position and arrow; */
3319 pspp_sheet_view_update_current_reorder (tree_view);
3325 pspp_sheet_view_stop_rubber_band (PsppSheetView *tree_view)
3327 remove_scroll_timeout (tree_view);
3328 gtk_grab_remove (GTK_WIDGET (tree_view));
3330 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
3332 GtkTreePath *tmp_path;
3334 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
3336 /* The anchor path should be set to the start path */
3337 tmp_path = _pspp_sheet_view_find_path (tree_view,
3338 tree_view->priv->rubber_band_start_node);
3340 if (tree_view->priv->anchor)
3341 gtk_tree_row_reference_free (tree_view->priv->anchor);
3343 tree_view->priv->anchor =
3344 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
3345 tree_view->priv->model,
3348 gtk_tree_path_free (tmp_path);
3350 /* ... and the cursor to the end path */
3351 tmp_path = _pspp_sheet_view_find_path (tree_view,
3352 tree_view->priv->rubber_band_end_node);
3353 pspp_sheet_view_real_set_cursor (PSPP_SHEET_VIEW (tree_view), tmp_path, FALSE, FALSE, 0); /* XXX mode? */
3354 gtk_tree_path_free (tmp_path);
3356 _pspp_sheet_selection_emit_changed (tree_view->priv->selection);
3359 /* Clear status variables */
3360 tree_view->priv->rubber_band_status = RUBBER_BAND_OFF;
3361 tree_view->priv->rubber_band_shift = 0;
3362 tree_view->priv->rubber_band_ctrl = 0;
3364 tree_view->priv->rubber_band_start_node = -1;
3365 tree_view->priv->rubber_band_end_node = -1;
3369 pspp_sheet_view_update_rubber_band_selection_range (PsppSheetView *tree_view,
3373 gboolean skip_start,
3376 if (start_node == end_node)
3379 /* We skip the first node and jump inside the loop */
3385 /* Small optimization by assuming insensitive nodes are never
3390 if (tree_view->priv->rubber_band_shift)
3391 pspp_sheet_view_node_select (tree_view, start_node);
3392 else if (tree_view->priv->rubber_band_ctrl)
3394 /* Toggle the selection state */
3395 if (pspp_sheet_view_node_is_selected (tree_view, start_node))
3396 pspp_sheet_view_node_unselect (tree_view, start_node);
3398 pspp_sheet_view_node_select (tree_view, start_node);
3401 pspp_sheet_view_node_select (tree_view, start_node);
3405 /* Mirror the above */
3406 if (tree_view->priv->rubber_band_shift)
3407 pspp_sheet_view_node_unselect (tree_view, start_node);
3408 else if (tree_view->priv->rubber_band_ctrl)
3410 /* Toggle the selection state */
3411 if (pspp_sheet_view_node_is_selected (tree_view, start_node))
3412 pspp_sheet_view_node_unselect (tree_view, start_node);
3414 pspp_sheet_view_node_select (tree_view, start_node);
3417 pspp_sheet_view_node_unselect (tree_view, start_node);
3420 _pspp_sheet_view_queue_draw_node (tree_view, start_node, NULL);
3422 if (start_node == end_node)
3427 start_node = pspp_sheet_view_node_next (tree_view, start_node);
3430 /* Ran out of tree */
3433 if (skip_end && start_node == end_node)
3440 pspp_sheet_view_node_find_offset (PsppSheetView *tree_view,
3443 return node * tree_view->priv->fixed_height;
3447 pspp_sheet_view_find_offset (PsppSheetView *tree_view,
3451 int fixed_height = tree_view->priv->fixed_height;
3452 if (fixed_height <= 0
3454 || height >= tree_view->priv->row_count * fixed_height)
3461 *new_node = height / fixed_height;
3462 return height % fixed_height;
3467 pspp_sheet_view_update_rubber_band_selection (PsppSheetView *tree_view)
3472 pspp_sheet_view_find_offset (tree_view, MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y), &start_node);
3473 pspp_sheet_view_find_offset (tree_view, MAX (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y), &end_node);
3475 /* Handle the start area first */
3476 if (tree_view->priv->rubber_band_start_node < 0)
3478 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3485 else if (start_node < tree_view->priv->rubber_band_start_node)
3487 /* New node is above the old one; selection became bigger */
3488 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3490 tree_view->priv->rubber_band_start_node,
3495 else if (start_node > tree_view->priv->rubber_band_start_node)
3497 /* New node is below the old one; selection became smaller */
3498 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3499 tree_view->priv->rubber_band_start_node,
3506 tree_view->priv->rubber_band_start_node = start_node;
3508 /* Next, handle the end area */
3509 if (tree_view->priv->rubber_band_end_node < 0)
3511 /* In the event this happens, start_node was also -1; this case is
3515 else if (end_node < 0)
3517 /* Find the last node in the tree */
3518 pspp_sheet_view_find_offset (tree_view, tree_view->priv->height - 1,
3521 /* Selection reached end of the tree */
3522 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3523 tree_view->priv->rubber_band_end_node,
3529 else if (end_node > tree_view->priv->rubber_band_end_node)
3531 /* New node is below the old one; selection became bigger */
3532 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3533 tree_view->priv->rubber_band_end_node,
3539 else if (end_node < tree_view->priv->rubber_band_end_node)
3541 /* New node is above the old one; selection became smaller */
3542 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3544 tree_view->priv->rubber_band_end_node,
3550 tree_view->priv->rubber_band_end_node = end_node;
3553 #define GDK_RECTANGLE_PTR(X) ((GdkRectangle *)(X))
3556 pspp_sheet_view_update_rubber_band (PsppSheetView *tree_view)
3559 cairo_rectangle_int_t old_area;
3560 cairo_rectangle_int_t new_area;
3561 cairo_rectangle_int_t common;
3562 cairo_region_t *invalid_region;
3563 PsppSheetViewColumn *column;
3565 old_area.x = MIN (tree_view->priv->press_start_x, tree_view->priv->rubber_band_x);
3566 old_area.y = MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y) - tree_view->priv->dy;
3567 old_area.width = ABS (tree_view->priv->rubber_band_x - tree_view->priv->press_start_x) + 1;
3568 old_area.height = ABS (tree_view->priv->rubber_band_y - tree_view->priv->press_start_y) + 1;
3570 gdk_window_get_pointer (tree_view->priv->bin_window, &x, &y, NULL);
3573 y = MAX (y, 0) + tree_view->priv->dy;
3575 new_area.x = MIN (tree_view->priv->press_start_x, x);
3576 new_area.y = MIN (tree_view->priv->press_start_y, y) - tree_view->priv->dy;
3577 new_area.width = ABS (x - tree_view->priv->press_start_x) + 1;
3578 new_area.height = ABS (y - tree_view->priv->press_start_y) + 1;
3580 invalid_region = cairo_region_create_rectangle (&old_area);
3581 cairo_region_union_rectangle (invalid_region, &new_area);
3583 gdk_rectangle_intersect (GDK_RECTANGLE_PTR (&old_area),
3584 GDK_RECTANGLE_PTR (&new_area), GDK_RECTANGLE_PTR (&common));
3585 if (common.width > 2 && common.height > 2)
3587 cairo_region_t *common_region;
3589 /* make sure the border is invalidated */
3595 common_region = cairo_region_create_rectangle (&common);
3597 cairo_region_subtract (invalid_region, common_region);
3598 cairo_region_destroy (common_region);
3601 #if GTK_MAJOR_VERSION == 3
3602 gdk_window_invalidate_region (tree_view->priv->bin_window, invalid_region, TRUE);
3605 cairo_rectangle_int_t extents;
3607 cairo_region_get_extents (invalid_region, &extents);
3608 ereg = gdk_region_rectangle (GDK_RECTANGLE_PTR (&extents));
3609 gdk_window_invalidate_region (tree_view->priv->bin_window, ereg, TRUE);
3610 gdk_region_destroy (ereg);
3614 cairo_region_destroy (invalid_region);
3616 tree_view->priv->rubber_band_x = x;
3617 tree_view->priv->rubber_band_y = y;
3618 pspp_sheet_view_get_path_at_pos (tree_view, x, y, NULL, &column, NULL, NULL);
3620 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
3621 pspp_sheet_selection_select_column_range (tree_view->priv->selection,
3622 tree_view->priv->anchor_column,
3625 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
3627 pspp_sheet_view_update_rubber_band_selection (tree_view);
3632 pspp_sheet_view_paint_rubber_band (PsppSheetView *tree_view,
3637 GdkRectangle rubber_rect;
3641 rubber_rect.x = MIN (tree_view->priv->press_start_x, tree_view->priv->rubber_band_x);
3642 rubber_rect.y = MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y) - tree_view->priv->dy;
3643 rubber_rect.width = ABS (tree_view->priv->press_start_x - tree_view->priv->rubber_band_x) + 1;
3644 rubber_rect.height = ABS (tree_view->priv->press_start_y - tree_view->priv->rubber_band_y) + 1;
3646 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
3649 cr = gdk_cairo_create (tree_view->priv->bin_window);
3650 cairo_set_line_width (cr, 1.0);
3652 style = gtk_widget_get_style (GTK_WIDGET (tree_view));
3653 cairo_set_source_rgba (cr,
3654 style->fg[GTK_STATE_NORMAL].red / 65535.,
3655 style->fg[GTK_STATE_NORMAL].green / 65535.,
3656 style->fg[GTK_STATE_NORMAL].blue / 65535.,
3659 gdk_cairo_rectangle (cr, &rect);
3663 cairo_set_source_rgb (cr,
3664 style->fg[GTK_STATE_NORMAL].red / 65535.,
3665 style->fg[GTK_STATE_NORMAL].green / 65535.,
3666 style->fg[GTK_STATE_NORMAL].blue / 65535.);
3668 cairo_rectangle (cr,
3669 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
3670 rubber_rect.width - 1, rubber_rect.height - 1);
3679 pspp_sheet_view_motion_bin_window (GtkWidget *widget,
3680 GdkEventMotion *event)
3682 PsppSheetView *tree_view;
3686 tree_view = (PsppSheetView *) widget;
3688 if (tree_view->priv->row_count == 0)
3691 if (tree_view->priv->rubber_band_status == RUBBER_BAND_MAYBE_START)
3693 GdkRectangle background_area, cell_area;
3694 PsppSheetViewColumn *column;
3696 if (find_click (tree_view, event->x, event->y, &node, &column,
3697 &background_area, &cell_area)
3698 && tree_view->priv->focus_column == column
3699 && tree_view->priv->press_start_node == node)
3702 gtk_grab_add (GTK_WIDGET (tree_view));
3703 pspp_sheet_view_update_rubber_band (tree_view);
3705 tree_view->priv->rubber_band_status = RUBBER_BAND_ACTIVE;
3707 else if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
3709 pspp_sheet_view_update_rubber_band (tree_view);
3711 add_scroll_timeout (tree_view);
3714 /* only check for an initiated drag when a button is pressed */
3715 if (tree_view->priv->pressed_button >= 0
3716 && !tree_view->priv->rubber_band_status)
3717 pspp_sheet_view_maybe_begin_dragging_row (tree_view, event);
3719 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, event->y);
3723 pspp_sheet_view_find_offset (tree_view, new_y, &node);
3725 tree_view->priv->event_last_x = event->x;
3726 tree_view->priv->event_last_y = event->y;
3728 prelight_or_select (tree_view, node, event->x, event->y);
3734 pspp_sheet_view_motion (GtkWidget *widget,
3735 GdkEventMotion *event)
3737 PsppSheetView *tree_view;
3739 tree_view = (PsppSheetView *) widget;
3741 /* Resizing a column */
3742 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
3743 return pspp_sheet_view_motion_resize_column (widget, event);
3746 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
3747 return pspp_sheet_view_motion_drag_column (widget, event);
3749 /* Sanity check it */
3750 if (event->window == tree_view->priv->bin_window)
3751 return pspp_sheet_view_motion_bin_window (widget, event);
3756 /* Invalidate the focus rectangle near the edge of the bin_window; used when
3757 * the tree is empty.
3760 invalidate_empty_focus (PsppSheetView *tree_view)
3764 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
3769 area.width = gdk_window_get_width (tree_view->priv->bin_window);
3770 area.height = gdk_window_get_height (tree_view->priv->bin_window);
3771 gdk_window_invalidate_rect (tree_view->priv->bin_window, &area, FALSE);
3774 /* Draws a focus rectangle near the edge of the bin_window; used when the tree
3778 draw_empty_focus (PsppSheetView *tree_view)
3780 GtkWidget *widget = GTK_WIDGET (tree_view);
3782 cairo_t *cr = gdk_cairo_create (tree_view->priv->bin_window);
3784 if (!gtk_widget_has_focus (widget))
3787 w = gdk_window_get_width (tree_view->priv->bin_window);
3788 h = gdk_window_get_height (tree_view->priv->bin_window);
3794 gtk_paint_focus (gtk_widget_get_style (widget),
3796 gtk_widget_get_state (widget),
3804 pspp_sheet_view_draw_vertical_grid_lines (PsppSheetView *tree_view,
3806 gint n_visible_columns,
3810 GList *list = tree_view->priv->columns;
3814 if (tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
3815 && tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_BOTH)
3818 /* Only draw the lines for visible rows and columns */
3819 for (list = tree_view->priv->columns; list; list = list->next, i++)
3821 PsppSheetViewColumn *column = list->data;
3823 /* We don't want a line for the last column */
3824 if (i == n_visible_columns - 1)
3827 if (! column->visible)
3830 current_x += column->width;
3832 cairo_set_line_width (cr, 1.0);
3833 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
3834 cairo_move_to (cr, current_x - 0.5, min_y);
3835 cairo_line_to (cr, current_x - 0.5 , max_y - min_y);
3841 /* Warning: Very scary function.
3842 * Modify at your own risk
3844 * KEEP IN SYNC WITH pspp_sheet_view_create_row_drag_icon()!
3845 * FIXME: It's not...
3848 pspp_sheet_view_bin_expose (GtkWidget *widget,
3851 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
3856 int drag_highlight = -1;
3859 gint y_offset, cell_offset;
3861 GdkRectangle background_area;
3862 GdkRectangle cell_area;
3864 gint bin_window_width;
3865 gint bin_window_height;
3866 GtkTreePath *cursor_path;
3867 GtkTreePath *drag_dest_path;
3868 GList *first_column, *last_column;
3869 gint vertical_separator;
3870 gint horizontal_separator;
3871 gint focus_line_width;
3872 gboolean allow_rules;
3873 gboolean has_special_cell;
3875 gint n_visible_columns;
3876 gint grid_line_width;
3877 gboolean row_ending_details;
3878 gboolean draw_vgrid_lines, draw_hgrid_lines;
3882 GtkAllocation allocation;
3883 gtk_widget_get_allocation (widget, &allocation);
3887 Zarea.height = allocation.height;
3889 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
3891 gtk_widget_style_get (widget,
3892 "horizontal-separator", &horizontal_separator,
3893 "vertical-separator", &vertical_separator,
3894 "allow-rules", &allow_rules,
3895 "focus-line-width", &focus_line_width,
3896 "row-ending-details", &row_ending_details,
3899 if (tree_view->priv->row_count == 0)
3901 draw_empty_focus (tree_view);
3906 /* clip event->area to the visible area */
3907 if (Zarea.height < 0.5)
3911 validate_visible_area (tree_view);
3913 new_y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, Zarea.y);
3917 y_offset = -pspp_sheet_view_find_offset (tree_view, new_y, &node);
3919 gdk_window_get_width (tree_view->priv->bin_window);
3922 gdk_window_get_height (tree_view->priv->bin_window);
3925 if (tree_view->priv->height < bin_window_height)
3927 gtk_paint_flat_box (gtk_widget_get_style (widget),
3929 gtk_widget_get_state (widget),
3933 0, tree_view->priv->height,
3935 bin_window_height - tree_view->priv->height);
3941 /* find the path for the node */
3942 path = _pspp_sheet_view_find_path ((PsppSheetView *)widget, node);
3943 gtk_tree_model_get_iter (tree_view->priv->model,
3946 gtk_tree_path_free (path);
3949 drag_dest_path = NULL;
3951 if (tree_view->priv->cursor)
3952 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
3955 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor);
3957 if (tree_view->priv->drag_dest_row)
3958 drag_dest_path = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
3961 _pspp_sheet_view_find_node (tree_view, drag_dest_path,
3965 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
3966 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
3968 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
3969 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
3971 if (draw_vgrid_lines || draw_hgrid_lines)
3972 gtk_widget_style_get (widget, "grid-line-width", &grid_line_width, NULL);
3974 n_visible_columns = 0;
3975 for (list = tree_view->priv->columns; list; list = list->next)
3977 if (! PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
3979 n_visible_columns ++;
3982 /* Find the last column */
3983 for (last_column = g_list_last (tree_view->priv->columns);
3984 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
3985 last_column = last_column->prev)
3989 for (first_column = g_list_first (tree_view->priv->columns);
3990 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
3991 first_column = first_column->next)
3994 /* Actually process the expose event. To do this, we want to
3995 * start at the first node of the event, and walk the tree in
3996 * order, drawing each successive node.
4003 gboolean is_first = FALSE;
4004 gboolean is_last = FALSE;
4005 gboolean done = FALSE;
4008 max_height = ROW_HEIGHT (tree_view);
4012 background_area.y = y_offset + Zarea.y;
4013 background_area.height = max_height;
4014 max_y = background_area.y + max_height;
4018 if (node == tree_view->priv->prelight_node)
4019 flags |= GTK_CELL_RENDERER_PRELIT;
4021 selected = pspp_sheet_view_node_is_selected (tree_view, node);
4025 if (tree_view->priv->special_cells == PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT)
4027 /* we *need* to set cell data on all cells before the call
4028 * to _has_special_cell, else _has_special_cell() does not
4029 * return a correct value.
4031 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
4033 list = (rtl ? list->prev : list->next))
4035 PsppSheetViewColumn *column = list->data;
4036 pspp_sheet_view_column_cell_set_cell_data (column,
4037 tree_view->priv->model,
4041 has_special_cell = pspp_sheet_view_has_special_cell (tree_view);
4044 has_special_cell = tree_view->priv->special_cells == PSPP_SHEET_VIEW_SPECIAL_CELLS_YES;
4046 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
4048 list = (rtl ? list->prev : list->next))
4050 PsppSheetViewColumn *column = list->data;
4051 const gchar *detail = NULL;
4052 gboolean selected_column;
4055 if (!column->visible)
4058 if (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE)
4059 selected_column = column->selected && column->selectable;
4061 selected_column = TRUE;
4064 if (cell_offset > Zarea.x + Zarea.width ||
4065 cell_offset + column->width < Zarea.x)
4067 cell_offset += column->width;
4072 if (selected && selected_column)
4073 flags |= GTK_CELL_RENDERER_SELECTED;
4075 flags &= ~GTK_CELL_RENDERER_SELECTED;
4077 if (column->show_sort_indicator)
4078 flags |= GTK_CELL_RENDERER_SORTED;
4080 flags &= ~GTK_CELL_RENDERER_SORTED;
4083 flags |= GTK_CELL_RENDERER_FOCUSED;
4085 flags &= ~GTK_CELL_RENDERER_FOCUSED;
4087 background_area.x = cell_offset;
4088 background_area.width = column->width;
4090 cell_area = background_area;
4091 cell_area.y += vertical_separator / 2;
4092 cell_area.x += horizontal_separator / 2;
4093 cell_area.height -= vertical_separator;
4094 cell_area.width -= horizontal_separator;
4096 if (draw_vgrid_lines)
4098 if (list == first_column)
4100 cell_area.width -= grid_line_width / 2;
4102 else if (list == last_column)
4104 cell_area.x += grid_line_width / 2;
4105 cell_area.width -= grid_line_width / 2;
4109 cell_area.x += grid_line_width / 2;
4110 cell_area.width -= grid_line_width;
4114 if (draw_hgrid_lines)
4116 cell_area.y += grid_line_width / 2;
4117 cell_area.height -= grid_line_width;
4121 if (gdk_region_rect_in (event->region, &background_area) == GDK_OVERLAP_RECTANGLE_OUT)
4123 cell_offset += column->width;
4128 pspp_sheet_view_column_cell_set_cell_data (column,
4129 tree_view->priv->model,
4132 /* Select the detail for drawing the cell. relevant
4133 * factors are parity, sortedness, and whether to
4136 if (allow_rules && tree_view->priv->has_rules)
4138 if ((flags & GTK_CELL_RENDERER_SORTED) &&
4139 n_visible_columns >= 3)
4142 detail = "cell_odd_ruled_sorted";
4144 detail = "cell_even_ruled_sorted";
4149 detail = "cell_odd_ruled";
4151 detail = "cell_even_ruled";
4156 if ((flags & GTK_CELL_RENDERER_SORTED) &&
4157 n_visible_columns >= 3)
4160 detail = "cell_odd_sorted";
4162 detail = "cell_even_sorted";
4167 detail = "cell_odd";
4169 detail = "cell_even";
4175 if (gtk_widget_get_state (widget) == GTK_STATE_INSENSITIVE)
4176 state = GTK_STATE_INSENSITIVE;
4177 else if (flags & GTK_CELL_RENDERER_SELECTED)
4178 state = GTK_STATE_SELECTED;
4180 state = GTK_STATE_NORMAL;
4182 /* Draw background */
4183 if (row_ending_details)
4185 char new_detail[128];
4187 is_first = (rtl ? !list->next : !list->prev);
4188 is_last = (rtl ? !list->prev : !list->next);
4190 /* (I don't like the snprintfs either, but couldn't find a
4193 if (is_first && is_last)
4194 g_snprintf (new_detail, 127, "%s", detail);
4196 g_snprintf (new_detail, 127, "%s_start", detail);
4198 g_snprintf (new_detail, 127, "%s_end", detail);
4200 g_snprintf (new_detail, 128, "%s_middle", detail);
4202 gtk_paint_flat_box (gtk_widget_get_style (widget),
4210 background_area.width,
4211 background_area.height);
4215 gtk_paint_flat_box (gtk_widget_get_style (widget),
4223 background_area.width,
4224 background_area.height);
4227 if (draw_hgrid_lines)
4229 cairo_set_line_width (cr, 1.0);
4230 cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
4232 if (background_area.y >= 0)
4235 gdk_draw_line (event->window,
4236 tree_view->priv->grid_line_gc[widget->state],
4237 background_area.x, background_area.y,
4238 background_area.x + background_area.width,
4241 cairo_move_to (cr, background_area.x, background_area.y - 0.5);
4242 cairo_line_to (cr, background_area.x + background_area.width,
4243 background_area.y - 0.5);
4247 if (y_offset + max_height >= Zarea.height - 0.5)
4250 gdk_draw_line (event->window,
4251 tree_view->priv->grid_line_gc[widget->state],
4252 background_area.x, background_area.y + max_height,
4253 background_area.x + background_area.width,
4254 background_area.y + max_height);
4257 cairo_move_to (cr, background_area.x, background_area.y + max_height - 0.5);
4258 cairo_line_to (cr, background_area.x + background_area.width,
4259 background_area.y + max_height - 0.5);
4265 _pspp_sheet_view_column_cell_render (column,
4271 if (node == cursor && has_special_cell &&
4272 ((column == tree_view->priv->focus_column &&
4273 PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS) &&
4274 gtk_widget_has_focus (widget)) ||
4275 (column == tree_view->priv->edited_column)))
4277 _pspp_sheet_view_column_cell_draw_focus (column,
4284 cell_offset += column->width;
4287 if (cell_offset < Zarea.x)
4289 gtk_paint_flat_box (gtk_widget_get_style (widget),
4297 Zarea.x - cell_offset,
4298 background_area.height);
4301 if (node == drag_highlight)
4303 /* Draw indicator for the drop
4305 gint highlight_y = -1;
4309 switch (tree_view->priv->drag_dest_pos)
4311 case PSPP_SHEET_VIEW_DROP_BEFORE:
4312 highlight_y = background_area.y - 1;
4313 if (highlight_y < 0)
4317 case PSPP_SHEET_VIEW_DROP_AFTER:
4318 highlight_y = background_area.y + background_area.height - 1;
4321 case PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE:
4322 case PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER:
4323 _pspp_sheet_view_find_node (tree_view, drag_dest_path, &node);
4327 width = gdk_window_get_width (tree_view->priv->bin_window);
4329 if (row_ending_details)
4330 gtk_paint_focus (gtk_widget_get_style (widget),
4332 gtk_widget_get_state (widget),
4335 ? (is_last ? "treeview-drop-indicator" : "treeview-drop-indicator-left" )
4336 : (is_last ? "treeview-drop-indicator-right" : "tree-view-drop-indicator-middle" )),
4337 0, BACKGROUND_FIRST_PIXEL (tree_view, node)
4338 - focus_line_width / 2,
4339 width, ROW_HEIGHT (tree_view)
4340 - focus_line_width + 1);
4342 gtk_paint_focus (gtk_widget_get_style (widget),
4344 gtk_widget_get_state (widget),
4346 "treeview-drop-indicator",
4347 0, BACKGROUND_FIRST_PIXEL (tree_view, node)
4348 - focus_line_width / 2,
4349 width, ROW_HEIGHT (tree_view)
4350 - focus_line_width + 1);
4355 if (highlight_y >= 0)
4357 gdk_draw_line (event->window,
4358 widget->style->fg_gc[gtk_widget_get_state (widget)],
4361 rtl ? 0 : bin_window_width,
4367 /* draw the big row-spanning focus rectangle, if needed */
4368 if (!has_special_cell && node == cursor &&
4369 PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS) &&
4370 gtk_widget_has_focus (widget))
4372 gint tmp_y, tmp_height;
4374 GtkStateType focus_rect_state;
4377 flags & GTK_CELL_RENDERER_SELECTED ? GTK_STATE_SELECTED :
4378 (flags & GTK_CELL_RENDERER_PRELIT ? GTK_STATE_PRELIGHT :
4379 (flags & GTK_CELL_RENDERER_INSENSITIVE ? GTK_STATE_INSENSITIVE :
4382 width = gdk_window_get_width (tree_view->priv->bin_window);
4384 if (draw_hgrid_lines)
4386 tmp_y = BACKGROUND_FIRST_PIXEL (tree_view, node) + grid_line_width / 2;
4387 tmp_height = ROW_HEIGHT (tree_view) - grid_line_width;
4391 tmp_y = BACKGROUND_FIRST_PIXEL (tree_view, node);
4392 tmp_height = ROW_HEIGHT (tree_view);
4395 if (row_ending_details)
4396 gtk_paint_focus (gtk_widget_get_style (widget),
4401 ? (is_last ? "treeview" : "treeview-left" )
4402 : (is_last ? "treeview-right" : "treeview-middle" )),
4406 gtk_paint_focus (gtk_widget_get_style (widget),
4415 y_offset += max_height;
4419 node = pspp_sheet_view_node_next (tree_view, node);
4422 gboolean has_next = gtk_tree_model_iter_next (tree_view->priv->model, &iter);
4426 TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
4433 while (y_offset < Zarea.height);
4436 pspp_sheet_view_draw_vertical_grid_lines (tree_view, cr, n_visible_columns,
4440 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
4442 GdkRectangle *rectangles;
4445 gdk_region_get_rectangles (event->region,
4449 while (n_rectangles--)
4450 pspp_sheet_view_paint_rubber_band (tree_view, &rectangles[n_rectangles]);
4452 g_free (rectangles);
4457 gtk_tree_path_free (cursor_path);
4460 gtk_tree_path_free (drag_dest_path);
4467 pspp_sheet_view_draw (GtkWidget *widget,
4470 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4471 GtkAllocation allocation;
4472 gtk_widget_get_allocation (widget, &allocation);
4474 if (gtk_cairo_should_draw_window (cr, tree_view->priv->bin_window))
4480 cairo_translate (cr, 0, gdk_window_get_height (tree_view->priv->header_window));
4481 retval = pspp_sheet_view_bin_expose (widget, cr);
4484 /* We can't just chain up to Container::expose as it will try to send the
4485 * event to the headers, so we handle propagating it to our children
4486 * (eg. widgets being edited) ourselves.
4488 tmp_list = tree_view->priv->children;
4491 PsppSheetViewChild *child = tmp_list->data;
4492 tmp_list = tmp_list->next;
4494 gtk_container_propagate_draw (GTK_CONTAINER (tree_view), child->widget, cr);
4499 else if (gtk_cairo_should_draw_window (cr, tree_view->priv->header_window))
4501 gint n_visible_columns;
4504 gtk_paint_flat_box (gtk_widget_get_style (widget),
4516 for (list = tree_view->priv->columns; list != NULL; list = list->next)
4518 PsppSheetViewColumn *column = list->data;
4520 if (column == tree_view->priv->drag_column || !column->visible)
4523 if (span_intersects (column->allocation.x, column->allocation.width,
4524 allocation.x, allocation.width)
4525 && column->button != NULL)
4526 gtk_container_propagate_draw (GTK_CONTAINER (tree_view),
4527 column->button, cr);
4530 n_visible_columns = 0;
4531 for (list = tree_view->priv->columns; list; list = list->next)
4533 if (! PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
4535 n_visible_columns ++;
4537 pspp_sheet_view_draw_vertical_grid_lines (tree_view,
4545 else if (gtk_cairo_should_draw_window (cr, tree_view->priv->drag_window))
4547 gtk_container_propagate_draw (GTK_CONTAINER (tree_view),
4548 tree_view->priv->drag_column->button,
4565 /* returns 0x1 when no column has been found -- yes it's hackish */
4566 static PsppSheetViewColumn *
4567 pspp_sheet_view_get_drop_column (PsppSheetView *tree_view,
4568 PsppSheetViewColumn *column,
4571 PsppSheetViewColumn *left_column = NULL;
4572 PsppSheetViewColumn *cur_column = NULL;
4575 if (!column->reorderable)
4576 return (PsppSheetViewColumn *)0x1;
4578 switch (drop_position)
4581 /* find first column where we can drop */
4582 tmp_list = tree_view->priv->columns;
4583 if (column == PSPP_SHEET_VIEW_COLUMN (tmp_list->data))
4584 return (PsppSheetViewColumn *)0x1;
4588 g_assert (tmp_list);
4590 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4591 tmp_list = tmp_list->next;
4593 if (left_column && left_column->visible == FALSE)
4596 if (!tree_view->priv->column_drop_func)
4599 if (!tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4601 left_column = cur_column;
4608 if (!tree_view->priv->column_drop_func)
4611 if (tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data))
4614 return (PsppSheetViewColumn *)0x1;
4618 /* find first column after column where we can drop */
4619 tmp_list = tree_view->priv->columns;
4621 for (; tmp_list; tmp_list = tmp_list->next)
4622 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data) == column)
4625 if (!tmp_list || !tmp_list->next)
4626 return (PsppSheetViewColumn *)0x1;
4628 tmp_list = tmp_list->next;
4629 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4630 tmp_list = tmp_list->next;
4634 g_assert (tmp_list);
4636 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4637 tmp_list = tmp_list->next;
4639 if (left_column && left_column->visible == FALSE)
4641 left_column = cur_column;
4643 tmp_list = tmp_list->next;
4647 if (!tree_view->priv->column_drop_func)
4650 if (!tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4652 left_column = cur_column;
4659 if (!tree_view->priv->column_drop_func)
4662 if (tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data))
4665 return (PsppSheetViewColumn *)0x1;
4669 /* find first column before column where we can drop */
4670 tmp_list = tree_view->priv->columns;
4672 for (; tmp_list; tmp_list = tmp_list->next)
4673 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data) == column)
4676 if (!tmp_list || !tmp_list->prev)
4677 return (PsppSheetViewColumn *)0x1;
4679 tmp_list = tmp_list->prev;
4680 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4681 tmp_list = tmp_list->prev;
4685 g_assert (tmp_list);
4687 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4689 if (left_column && !left_column->visible)
4691 /*if (!tmp_list->prev)
4692 return (PsppSheetViewColumn *)0x1;
4695 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->prev->data);
4696 tmp_list = tmp_list->prev->prev;
4699 cur_column = left_column;
4701 tmp_list = tmp_list->prev;
4705 if (!tree_view->priv->column_drop_func)
4708 if (tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4711 cur_column = left_column;
4712 tmp_list = tmp_list->prev;
4715 if (!tree_view->priv->column_drop_func)
4718 if (tree_view->priv->column_drop_func (tree_view, column, NULL, cur_column, tree_view->priv->column_drop_func_data))
4721 return (PsppSheetViewColumn *)0x1;
4725 /* same as DROP_HOME case, but doing it backwards */
4726 tmp_list = g_list_last (tree_view->priv->columns);
4729 if (column == PSPP_SHEET_VIEW_COLUMN (tmp_list->data))
4730 return (PsppSheetViewColumn *)0x1;
4734 g_assert (tmp_list);
4736 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4738 if (left_column && !left_column->visible)
4740 cur_column = left_column;
4741 tmp_list = tmp_list->prev;
4744 if (!tree_view->priv->column_drop_func)
4747 if (tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4750 cur_column = left_column;
4751 tmp_list = tmp_list->prev;
4754 if (!tree_view->priv->column_drop_func)
4757 if (tree_view->priv->column_drop_func (tree_view, column, NULL, cur_column, tree_view->priv->column_drop_func_data))
4760 return (PsppSheetViewColumn *)0x1;
4764 return (PsppSheetViewColumn *)0x1;
4768 pspp_sheet_view_key_press (GtkWidget *widget,
4771 PsppSheetView *tree_view = (PsppSheetView *) widget;
4773 if (tree_view->priv->rubber_band_status)
4775 if (event->keyval == GDK_Escape)
4776 pspp_sheet_view_stop_rubber_band (tree_view);
4781 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
4783 if (event->keyval == GDK_Escape)
4785 tree_view->priv->cur_reorder = NULL;
4786 pspp_sheet_view_button_release_drag_column (widget, NULL);
4791 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
4793 GList *focus_column;
4796 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
4798 for (focus_column = tree_view->priv->columns;
4800 focus_column = focus_column->next)
4802 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4804 if (column->button && gtk_widget_has_focus (column->button))
4809 (event->state & GDK_SHIFT_MASK) && (event->state & GDK_MOD1_MASK) &&
4810 (event->keyval == GDK_Left || event->keyval == GDK_KP_Left
4811 || event->keyval == GDK_Right || event->keyval == GDK_KP_Right))
4813 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4815 if (!column->resizable)
4817 gtk_widget_error_bell (widget);
4821 if (event->keyval == (rtl ? GDK_Right : GDK_Left)
4822 || event->keyval == (rtl ? GDK_KP_Right : GDK_KP_Left))
4824 gint old_width = column->resized_width;
4826 column->resized_width = MAX (column->resized_width,
4828 column->resized_width -= 2;
4829 if (column->resized_width < 0)
4830 column->resized_width = 0;
4832 if (column->min_width == -1)
4833 column->resized_width = MAX (column->button_request,
4834 column->resized_width);
4836 column->resized_width = MAX (column->min_width,
4837 column->resized_width);
4839 if (column->max_width != -1)
4840 column->resized_width = MIN (column->resized_width,
4843 column->use_resized_width = TRUE;
4845 if (column->resized_width != old_width)
4846 gtk_widget_queue_resize (widget);
4848 gtk_widget_error_bell (widget);
4850 else if (event->keyval == (rtl ? GDK_Left : GDK_Right)
4851 || event->keyval == (rtl ? GDK_KP_Left : GDK_KP_Right))
4853 gint old_width = column->resized_width;
4855 column->resized_width = MAX (column->resized_width,
4857 column->resized_width += 2;
4859 if (column->max_width != -1)
4860 column->resized_width = MIN (column->resized_width,
4863 column->use_resized_width = TRUE;
4865 if (column->resized_width != old_width)
4866 gtk_widget_queue_resize (widget);
4868 gtk_widget_error_bell (widget);
4875 (event->state & GDK_MOD1_MASK) &&
4876 (event->keyval == GDK_Left || event->keyval == GDK_KP_Left
4877 || event->keyval == GDK_Right || event->keyval == GDK_KP_Right
4878 || event->keyval == GDK_Home || event->keyval == GDK_KP_Home
4879 || event->keyval == GDK_End || event->keyval == GDK_KP_End))
4881 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4883 if (event->keyval == (rtl ? GDK_Right : GDK_Left)
4884 || event->keyval == (rtl ? GDK_KP_Right : GDK_KP_Left))
4886 PsppSheetViewColumn *col;
4887 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_LEFT);
4888 if (col != (PsppSheetViewColumn *)0x1)
4889 pspp_sheet_view_move_column_after (tree_view, column, col);
4891 gtk_widget_error_bell (widget);
4893 else if (event->keyval == (rtl ? GDK_Left : GDK_Right)
4894 || event->keyval == (rtl ? GDK_KP_Left : GDK_KP_Right))
4896 PsppSheetViewColumn *col;
4897 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_RIGHT);
4898 if (col != (PsppSheetViewColumn *)0x1)
4899 pspp_sheet_view_move_column_after (tree_view, column, col);
4901 gtk_widget_error_bell (widget);
4903 else if (event->keyval == GDK_Home || event->keyval == GDK_KP_Home)
4905 PsppSheetViewColumn *col;
4906 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_HOME);
4907 if (col != (PsppSheetViewColumn *)0x1)
4908 pspp_sheet_view_move_column_after (tree_view, column, col);
4910 gtk_widget_error_bell (widget);
4912 else if (event->keyval == GDK_End || event->keyval == GDK_KP_End)
4914 PsppSheetViewColumn *col;
4915 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_END);
4916 if (col != (PsppSheetViewColumn *)0x1)
4917 pspp_sheet_view_move_column_after (tree_view, column, col);
4919 gtk_widget_error_bell (widget);
4926 /* Chain up to the parent class. It handles the keybindings. */
4927 if (GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->key_press_event (widget, event))
4930 if (tree_view->priv->search_entry_avoid_unhandled_binding)
4932 tree_view->priv->search_entry_avoid_unhandled_binding = FALSE;
4936 /* We pass the event to the search_entry. If its text changes, then we start
4937 * the typeahead find capabilities. */
4938 if (gtk_widget_has_focus (GTK_WIDGET (tree_view))
4939 && tree_view->priv->enable_search
4940 && !tree_view->priv->search_custom_entry_set)
4942 GdkEvent *new_event;
4944 const char *new_text;
4947 gboolean text_modified;
4948 gulong popup_menu_id;
4950 pspp_sheet_view_ensure_interactive_directory (tree_view);
4952 /* Make a copy of the current text */
4953 old_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry)));
4954 new_event = gdk_event_copy ((GdkEvent *) event);
4955 g_object_unref (((GdkEventKey *) new_event)->window);
4956 ((GdkEventKey *) new_event)->window = g_object_ref (gtk_widget_get_window (tree_view->priv->search_window));
4957 gtk_widget_realize (tree_view->priv->search_window);
4959 popup_menu_id = g_signal_connect (tree_view->priv->search_entry,
4960 "popup-menu", G_CALLBACK (gtk_true),
4963 /* Move the entry off screen */
4964 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
4965 gtk_window_move (GTK_WINDOW (tree_view->priv->search_window),
4966 gdk_screen_get_width (screen) + 1,
4967 gdk_screen_get_height (screen) + 1);
4968 gtk_widget_show (tree_view->priv->search_window);
4970 /* Send the event to the window. If the preedit_changed signal is emitted
4971 * during this event, we will set priv->imcontext_changed */
4972 tree_view->priv->imcontext_changed = FALSE;
4973 retval = gtk_widget_event (tree_view->priv->search_window, new_event);
4974 gdk_event_free (new_event);
4975 gtk_widget_hide (tree_view->priv->search_window);
4977 g_signal_handler_disconnect (tree_view->priv->search_entry,
4980 /* We check to make sure that the entry tried to handle the text, and that
4981 * the text has changed.
4983 new_text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
4984 text_modified = strcmp (old_text, new_text) != 0;
4986 if (tree_view->priv->imcontext_changed || /* we're in a preedit */
4987 (retval && text_modified)) /* ...or the text was modified */
4989 if (pspp_sheet_view_real_start_interactive_search (tree_view, FALSE))
4991 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
4996 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
5006 pspp_sheet_view_key_release (GtkWidget *widget,
5009 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
5011 if (tree_view->priv->rubber_band_status)
5014 return GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->key_release_event (widget, event);
5017 /* FIXME Is this function necessary? Can I get an enter_notify event
5018 * w/o either an expose event or a mouse motion event?
5021 pspp_sheet_view_enter_notify (GtkWidget *widget,
5022 GdkEventCrossing *event)
5024 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
5028 /* Sanity check it */
5029 if (event->window != tree_view->priv->bin_window)
5032 if (tree_view->priv->row_count == 0)
5035 if (event->mode == GDK_CROSSING_GRAB ||
5036 event->mode == GDK_CROSSING_GTK_GRAB ||
5037 event->mode == GDK_CROSSING_GTK_UNGRAB ||
5038 event->mode == GDK_CROSSING_STATE_CHANGED)
5041 /* find the node internally */
5042 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, event->y);
5045 pspp_sheet_view_find_offset (tree_view, new_y, &node);
5047 tree_view->priv->event_last_x = event->x;
5048 tree_view->priv->event_last_y = event->y;
5050 prelight_or_select (tree_view, node, event->x, event->y);
5056 pspp_sheet_view_leave_notify (GtkWidget *widget,
5057 GdkEventCrossing *event)
5059 PsppSheetView *tree_view;
5061 if (event->mode == GDK_CROSSING_GRAB)
5064 tree_view = PSPP_SHEET_VIEW (widget);
5066 if (tree_view->priv->prelight_node >= 0)
5067 _pspp_sheet_view_queue_draw_node (tree_view,
5068 tree_view->priv->prelight_node,
5071 tree_view->priv->event_last_x = -10000;
5072 tree_view->priv->event_last_y = -10000;
5074 prelight_or_select (tree_view,
5076 -1000, -1000); /* coords not possibly over an arrow */
5083 pspp_sheet_view_focus_out (GtkWidget *widget,
5084 GdkEventFocus *event)
5086 PsppSheetView *tree_view;
5088 tree_view = PSPP_SHEET_VIEW (widget);
5090 gtk_widget_queue_draw (widget);
5092 /* destroy interactive search dialog */
5093 if (tree_view->priv->search_window)
5094 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
5100 /* Incremental Reflow
5104 pspp_sheet_view_node_queue_redraw (PsppSheetView *tree_view,
5107 GtkAllocation allocation;
5108 gint y = pspp_sheet_view_node_find_offset (tree_view, node)
5109 - gtk_adjustment_get_value (tree_view->priv->vadjustment)
5110 + TREE_VIEW_HEADER_HEIGHT (tree_view);
5112 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
5114 gtk_widget_queue_draw_area (GTK_WIDGET (tree_view),
5117 tree_view->priv->fixed_height);
5121 node_is_visible (PsppSheetView *tree_view,
5127 y = pspp_sheet_view_node_find_offset (tree_view, node);
5128 height = ROW_HEIGHT (tree_view);
5130 if (y >= gtk_adjustment_get_value (tree_view->priv->vadjustment) &&
5131 y + height <= (gtk_adjustment_get_value (tree_view->priv->vadjustment)
5132 + gtk_adjustment_get_page_size (tree_view->priv->vadjustment)))
5138 /* Returns the row height. */
5140 validate_row (PsppSheetView *tree_view,
5145 PsppSheetViewColumn *column;
5146 GList *list, *first_column, *last_column;
5148 gint horizontal_separator;
5149 gint vertical_separator;
5150 gint focus_line_width;
5151 gboolean draw_vgrid_lines, draw_hgrid_lines;
5153 gint grid_line_width;
5154 gboolean wide_separators;
5155 gint separator_height;
5157 gtk_widget_style_get (GTK_WIDGET (tree_view),
5158 "focus-padding", &focus_pad,
5159 "focus-line-width", &focus_line_width,
5160 "horizontal-separator", &horizontal_separator,
5161 "vertical-separator", &vertical_separator,
5162 "grid-line-width", &grid_line_width,
5163 "wide-separators", &wide_separators,
5164 "separator-height", &separator_height,
5168 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
5169 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
5171 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
5172 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
5174 for (last_column = g_list_last (tree_view->priv->columns);
5175 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
5176 last_column = last_column->prev)
5179 for (first_column = g_list_first (tree_view->priv->columns);
5180 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
5181 first_column = first_column->next)
5184 for (list = tree_view->priv->columns; list; list = list->next)
5189 column = list->data;
5191 if (! column->visible)
5194 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, iter);
5195 pspp_sheet_view_column_cell_get_size (column,
5197 &tmp_width, &tmp_height);
5199 tmp_height += vertical_separator;
5200 height = MAX (height, tmp_height);
5202 tmp_width = tmp_width + horizontal_separator;
5204 if (draw_vgrid_lines)
5206 if (list->data == first_column || list->data == last_column)
5207 tmp_width += grid_line_width / 2.0;
5209 tmp_width += grid_line_width;
5212 if (tmp_width > column->requested_width)
5213 column->requested_width = tmp_width;
5216 if (draw_hgrid_lines)
5217 height += grid_line_width;
5219 tree_view->priv->post_validation_flag = TRUE;
5225 validate_visible_area (PsppSheetView *tree_view)
5227 GtkTreePath *path = NULL;
5228 GtkTreePath *above_path = NULL;
5231 gboolean size_changed = FALSE;
5233 gint area_above = 0;
5234 gint area_below = 0;
5235 GtkAllocation allocation;
5237 if (tree_view->priv->row_count == 0)
5240 if (tree_view->priv->scroll_to_path == NULL)
5243 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
5245 total_height = allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
5247 if (total_height == 0)
5250 path = gtk_tree_row_reference_get_path (tree_view->priv->scroll_to_path);
5253 /* we are going to scroll, and will update dy */
5254 _pspp_sheet_view_find_node (tree_view, path, &node);
5255 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
5257 if (tree_view->priv->scroll_to_use_align)
5259 gint height = ROW_HEIGHT (tree_view);
5260 area_above = (total_height - height) *
5261 tree_view->priv->scroll_to_row_align;
5262 area_below = total_height - area_above - height;
5263 area_above = MAX (area_above, 0);
5264 area_below = MAX (area_below, 0);
5269 * 1) row not visible
5273 gint height = ROW_HEIGHT (tree_view);
5275 dy = pspp_sheet_view_node_find_offset (tree_view, node);
5277 if (dy >= gtk_adjustment_get_value (tree_view->priv->vadjustment) &&
5278 dy + height <= (gtk_adjustment_get_value (tree_view->priv->vadjustment)
5279 + gtk_adjustment_get_page_size (tree_view->priv->vadjustment)))
5281 /* row visible: keep the row at the same position */
5282 area_above = dy - gtk_adjustment_get_value (tree_view->priv->vadjustment);
5283 area_below = (gtk_adjustment_get_value (tree_view->priv->vadjustment) +
5284 gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
5289 /* row not visible */
5291 && dy + height <= gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
5293 /* row at the beginning -- fixed */
5295 area_below = gtk_adjustment_get_page_size (tree_view->priv->vadjustment)
5296 - area_above - height;
5298 else if (dy >= (gtk_adjustment_get_upper (tree_view->priv->vadjustment) -
5299 gtk_adjustment_get_page_size (tree_view->priv->vadjustment)))
5301 /* row at the end -- fixed */
5302 area_above = dy - (gtk_adjustment_get_upper (tree_view->priv->vadjustment) -
5303 gtk_adjustment_get_page_size (tree_view->priv->vadjustment));
5304 area_below = gtk_adjustment_get_page_size (tree_view->priv->vadjustment) -
5305 area_above - height;
5309 area_above = gtk_adjustment_get_page_size (tree_view->priv->vadjustment) - height;
5315 /* row somewhere in the middle, bring it to the top
5319 area_below = total_height - height;
5325 /* the scroll to isn't valid; ignore it.
5328 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
5329 tree_view->priv->scroll_to_path = NULL;
5333 above_path = gtk_tree_path_copy (path);
5335 /* Now, we walk forwards and backwards, measuring rows. Unfortunately,
5336 * backwards is much slower then forward, as there is no iter_prev function.
5337 * We go forwards first in case we run out of tree. Then we go backwards to
5340 while (node >= 0 && area_below > 0)
5342 gboolean done = FALSE;
5345 node = pspp_sheet_view_node_next (tree_view, node);
5348 gboolean has_next = gtk_tree_model_iter_next (tree_view->priv->model, &iter);
5350 gtk_tree_path_next (path);
5353 TREE_VIEW_INTERNAL_ASSERT_VOID (has_next);
5363 area_below -= ROW_HEIGHT (tree_view);
5365 gtk_tree_path_free (path);
5367 /* If we ran out of tree, and have extra area_below left, we need to add it
5370 area_above += area_below;
5372 _pspp_sheet_view_find_node (tree_view, above_path, &node);
5374 /* We walk backwards */
5375 while (area_above > 0)
5377 node = pspp_sheet_view_node_prev (tree_view, node);
5379 /* Always find the new path in the tree. We cannot just assume
5380 * a gtk_tree_path_prev() is enough here, as there might be children
5381 * in between this node and the previous sibling node. If this
5382 * appears to be a performance hotspot in profiles, we can look into
5383 * intrigate logic for keeping path, node and iter in sync like
5384 * we do for forward walks. (Which will be hard because of the lacking
5391 gtk_tree_path_free (above_path);
5392 above_path = _pspp_sheet_view_find_path (tree_view, node);
5394 gtk_tree_model_get_iter (tree_view->priv->model, &iter, above_path);
5396 area_above -= ROW_HEIGHT (tree_view);
5399 /* set the dy here to scroll to the path,
5400 * and sync the top row accordingly
5402 pspp_sheet_view_set_top_row (tree_view, above_path, -area_above);
5403 pspp_sheet_view_top_row_to_dy (tree_view);
5405 /* update width/height and queue a resize */
5408 GtkRequisition requisition;
5410 /* We temporarily guess a size, under the assumption that it will be the
5411 * same when we get our next size_allocate. If we don't do this, we'll be
5412 * in an inconsistent state if we call top_row_to_dy. */
5414 gtk_widget_size_request (GTK_WIDGET (tree_view), &requisition);
5415 gtk_adjustment_set_upper (tree_view->priv->hadjustment, MAX (gtk_adjustment_get_upper (tree_view->priv->hadjustment), (gfloat)requisition.width));
5416 gtk_adjustment_set_upper (tree_view->priv->vadjustment, MAX (gtk_adjustment_get_upper (tree_view->priv->vadjustment), (gfloat)requisition.height));
5417 gtk_adjustment_changed (tree_view->priv->hadjustment);
5418 gtk_adjustment_changed (tree_view->priv->vadjustment);
5419 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
5422 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
5423 tree_view->priv->scroll_to_path = NULL;
5426 gtk_tree_path_free (above_path);
5428 if (tree_view->priv->scroll_to_column)
5430 tree_view->priv->scroll_to_column = NULL;
5432 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
5436 initialize_fixed_height_mode (PsppSheetView *tree_view)
5438 if (!tree_view->priv->row_count)
5441 if (tree_view->priv->fixed_height_set)
5444 if (tree_view->priv->fixed_height < 0)
5451 path = _pspp_sheet_view_find_path (tree_view, node);
5452 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
5454 tree_view->priv->fixed_height = validate_row (tree_view, node, &iter, path);
5456 gtk_tree_path_free (path);
5458 g_object_notify (G_OBJECT (tree_view), "fixed-height");
5462 /* Our strategy for finding nodes to validate is a little convoluted. We find
5463 * the left-most uninvalidated node. We then try walking right, validating
5464 * nodes. Once we find a valid node, we repeat the previous process of finding
5465 * the first invalid node.
5469 validate_rows_handler (PsppSheetView *tree_view)
5471 initialize_fixed_height_mode (tree_view);
5472 if (tree_view->priv->validate_rows_timer)
5474 g_source_remove (tree_view->priv->validate_rows_timer);
5475 tree_view->priv->validate_rows_timer = 0;
5482 do_presize_handler (PsppSheetView *tree_view)
5484 GtkRequisition requisition;
5486 validate_visible_area (tree_view);
5487 tree_view->priv->presize_handler_timer = 0;
5489 if (! gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5492 gtk_widget_size_request (GTK_WIDGET (tree_view), &requisition);
5494 gtk_adjustment_set_upper (tree_view->priv->hadjustment, MAX (gtk_adjustment_get_upper (tree_view->priv->hadjustment), (gfloat)requisition.width));
5495 gtk_adjustment_set_upper (tree_view->priv->vadjustment, MAX (gtk_adjustment_get_upper (tree_view->priv->vadjustment), (gfloat)requisition.height));
5496 gtk_adjustment_changed (tree_view->priv->hadjustment);
5497 gtk_adjustment_changed (tree_view->priv->vadjustment);
5498 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
5504 presize_handler_callback (gpointer data)
5506 do_presize_handler (PSPP_SHEET_VIEW (data));
5512 install_presize_handler (PsppSheetView *tree_view)
5514 if (! gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5517 if (! tree_view->priv->presize_handler_timer)
5519 tree_view->priv->presize_handler_timer =
5520 gdk_threads_add_idle_full (GTK_PRIORITY_RESIZE - 2, presize_handler_callback, tree_view, NULL);
5522 if (! tree_view->priv->validate_rows_timer)
5524 tree_view->priv->validate_rows_timer =
5525 gdk_threads_add_idle_full (PSPP_SHEET_VIEW_PRIORITY_VALIDATE, (GSourceFunc) validate_rows_handler, tree_view, NULL);
5530 scroll_sync_handler (PsppSheetView *tree_view)
5532 if (tree_view->priv->height <= gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
5533 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment), 0);
5534 else if (gtk_tree_row_reference_valid (tree_view->priv->top_row))
5535 pspp_sheet_view_top_row_to_dy (tree_view);
5537 pspp_sheet_view_dy_to_top_row (tree_view);
5539 tree_view->priv->scroll_sync_timer = 0;
5545 install_scroll_sync_handler (PsppSheetView *tree_view)
5547 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5550 if (!tree_view->priv->scroll_sync_timer)
5552 tree_view->priv->scroll_sync_timer =
5553 gdk_threads_add_idle_full (PSPP_SHEET_VIEW_PRIORITY_SCROLL_SYNC, (GSourceFunc) scroll_sync_handler, tree_view, NULL);
5558 pspp_sheet_view_set_top_row (PsppSheetView *tree_view,
5562 gtk_tree_row_reference_free (tree_view->priv->top_row);
5566 tree_view->priv->top_row = NULL;
5567 tree_view->priv->top_row_dy = 0;
5571 tree_view->priv->top_row = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
5572 tree_view->priv->top_row_dy = offset;
5576 /* Always call this iff dy is in the visible range. If the tree is empty, then
5577 * it's set to be NULL, and top_row_dy is 0;
5580 pspp_sheet_view_dy_to_top_row (PsppSheetView *tree_view)
5586 if (tree_view->priv->row_count == 0)
5588 pspp_sheet_view_set_top_row (tree_view, NULL, 0);
5592 offset = pspp_sheet_view_find_offset (tree_view,
5593 tree_view->priv->dy,
5598 pspp_sheet_view_set_top_row (tree_view, NULL, 0);
5602 path = _pspp_sheet_view_find_path (tree_view, node);
5603 pspp_sheet_view_set_top_row (tree_view, path, offset);
5604 gtk_tree_path_free (path);
5610 pspp_sheet_view_top_row_to_dy (PsppSheetView *tree_view)
5616 /* Avoid recursive calls */
5617 if (tree_view->priv->in_top_row_to_dy)
5620 if (tree_view->priv->top_row)
5621 path = gtk_tree_row_reference_get_path (tree_view->priv->top_row);
5628 _pspp_sheet_view_find_node (tree_view, path, &node);
5631 gtk_tree_path_free (path);
5635 /* keep dy and set new toprow */
5636 gtk_tree_row_reference_free (tree_view->priv->top_row);
5637 tree_view->priv->top_row = NULL;
5638 tree_view->priv->top_row_dy = 0;
5639 /* DO NOT install the idle handler */
5640 pspp_sheet_view_dy_to_top_row (tree_view);
5644 if (ROW_HEIGHT (tree_view) < tree_view->priv->top_row_dy)
5646 /* new top row -- do NOT install the idle handler */
5647 pspp_sheet_view_dy_to_top_row (tree_view);
5651 new_dy = pspp_sheet_view_node_find_offset (tree_view, node);
5652 new_dy += tree_view->priv->top_row_dy;
5654 if (new_dy + gtk_adjustment_get_page_size (tree_view->priv->vadjustment) > tree_view->priv->height)
5655 new_dy = tree_view->priv->height - gtk_adjustment_get_page_size (tree_view->priv->vadjustment);
5657 new_dy = MAX (0, new_dy);
5659 tree_view->priv->in_top_row_to_dy = TRUE;
5660 gtk_adjustment_set_value (tree_view->priv->vadjustment, (gdouble)new_dy);
5661 tree_view->priv->in_top_row_to_dy = FALSE;
5666 _pspp_sheet_view_install_mark_rows_col_dirty (PsppSheetView *tree_view)
5668 install_presize_handler (tree_view);
5674 set_source_row (GdkDragContext *context,
5675 GtkTreeModel *model,
5676 GtkTreePath *source_row)
5678 g_object_set_data_full (G_OBJECT (context),
5679 "gtk-tree-view-source-row",
5680 source_row ? gtk_tree_row_reference_new (model, source_row) : NULL,
5681 (GDestroyNotify) (source_row ? gtk_tree_row_reference_free : NULL));
5685 get_source_row (GdkDragContext *context)
5687 GtkTreeRowReference *ref =
5688 g_object_get_data (G_OBJECT (context), "gtk-tree-view-source-row");
5691 return gtk_tree_row_reference_get_path (ref);
5698 GtkTreeRowReference *dest_row;
5699 guint path_down_mode : 1;
5700 guint empty_view_drop : 1;
5701 guint drop_append_mode : 1;
5706 dest_row_free (gpointer data)
5708 DestRow *dr = (DestRow *)data;
5710 gtk_tree_row_reference_free (dr->dest_row);
5711 g_slice_free (DestRow, dr);
5715 set_dest_row (GdkDragContext *context,
5716 GtkTreeModel *model,
5717 GtkTreePath *dest_row,
5718 gboolean path_down_mode,
5719 gboolean empty_view_drop,
5720 gboolean drop_append_mode)
5726 g_object_set_data_full (G_OBJECT (context), "gtk-tree-view-dest-row",
5731 dr = g_slice_new (DestRow);
5733 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5734 dr->path_down_mode = path_down_mode != FALSE;
5735 dr->empty_view_drop = empty_view_drop != FALSE;
5736 dr->drop_append_mode = drop_append_mode != FALSE;
5738 g_object_set_data_full (G_OBJECT (context), "gtk-tree-view-dest-row",
5739 dr, (GDestroyNotify) dest_row_free);
5743 get_dest_row (GdkDragContext *context,
5744 gboolean *path_down_mode)
5747 g_object_get_data (G_OBJECT (context), "gtk-tree-view-dest-row");
5751 GtkTreePath *path = NULL;
5754 *path_down_mode = dr->path_down_mode;
5757 path = gtk_tree_row_reference_get_path (dr->dest_row);
5758 else if (dr->empty_view_drop)
5759 path = gtk_tree_path_new_from_indices (0, -1);
5763 if (path && dr->drop_append_mode)
5764 gtk_tree_path_next (path);
5772 /* Get/set whether drag_motion requested the drag data and
5773 * drag_data_received should thus not actually insert the data,
5774 * since the data doesn't result from a drop.
5777 set_status_pending (GdkDragContext *context,
5778 GdkDragAction suggested_action)
5780 g_object_set_data (G_OBJECT (context),
5781 "gtk-tree-view-status-pending",
5782 GINT_TO_POINTER (suggested_action));
5785 static GdkDragAction
5786 get_status_pending (GdkDragContext *context)
5788 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5789 "gtk-tree-view-status-pending"));
5792 static TreeViewDragInfo*
5793 get_info (PsppSheetView *tree_view)
5795 return g_object_get_data (G_OBJECT (tree_view), "gtk-tree-view-drag-info");
5799 destroy_info (TreeViewDragInfo *di)
5801 g_slice_free (TreeViewDragInfo, di);
5804 static TreeViewDragInfo*
5805 ensure_info (PsppSheetView *tree_view)
5807 TreeViewDragInfo *di;
5809 di = get_info (tree_view);
5813 di = g_slice_new0 (TreeViewDragInfo);
5815 g_object_set_data_full (G_OBJECT (tree_view),
5816 "gtk-tree-view-drag-info",
5818 (GDestroyNotify) destroy_info);
5825 remove_info (PsppSheetView *tree_view)
5827 g_object_set_data (G_OBJECT (tree_view), "gtk-tree-view-drag-info", NULL);
5832 drag_scan_timeout (gpointer data)
5834 PsppSheetView *tree_view;
5836 GdkModifierType state;
5837 GtkTreePath *path = NULL;
5838 PsppSheetViewColumn *column = NULL;
5839 GdkRectangle visible_rect;
5841 GDK_THREADS_ENTER ();
5843 tree_view = PSPP_SHEET_VIEW (data);
5845 gdk_window_get_pointer (tree_view->priv->bin_window,
5848 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
5850 /* See if we are near the edge. */
5851 if ((x - visible_rect.x) < SCROLL_EDGE_SIZE ||
5852 (visible_rect.x + visible_rect.width - x) < SCROLL_EDGE_SIZE ||
5853 (y - visible_rect.y) < SCROLL_EDGE_SIZE ||
5854 (visible_rect.y + visible_rect.height - y) < SCROLL_EDGE_SIZE)
5856 pspp_sheet_view_get_path_at_pos (tree_view,
5857 tree_view->priv->bin_window,
5866 pspp_sheet_view_scroll_to_cell (tree_view,
5872 gtk_tree_path_free (path);
5876 GDK_THREADS_LEAVE ();
5883 add_scroll_timeout (PsppSheetView *tree_view)
5885 if (tree_view->priv->scroll_timeout == 0)
5887 tree_view->priv->scroll_timeout =
5888 gdk_threads_add_timeout (150, scroll_row_timeout, tree_view);
5893 remove_scroll_timeout (PsppSheetView *tree_view)
5895 if (tree_view->priv->scroll_timeout != 0)
5897 g_source_remove (tree_view->priv->scroll_timeout);
5898 tree_view->priv->scroll_timeout = 0;
5903 check_model_dnd (GtkTreeModel *model,
5904 GType required_iface,
5905 const gchar *signal)
5907 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5909 g_warning ("You must override the default '%s' handler "
5910 "on PsppSheetView when using models that don't support "
5911 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5912 "is to connect to '%s' and call "
5913 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5914 "the default handler from running. Look at the source code "
5915 "for the default handler in gtktreeview.c to get an idea what "
5916 "your handler should do. (gtktreeview.c is in the GTK source "
5917 "code.) If you're using GTK from a language other than C, "
5918 "there may be a more natural way to override default handlers, e.g. via derivation.",
5919 signal, g_type_name (required_iface), signal);
5927 scroll_row_timeout (gpointer data)
5929 PsppSheetView *tree_view = data;
5931 pspp_sheet_view_horizontal_autoscroll (tree_view);
5932 pspp_sheet_view_vertical_autoscroll (tree_view);
5934 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
5935 pspp_sheet_view_update_rubber_band (tree_view);
5940 /* Returns TRUE if event should not be propagated to parent widgets */
5942 set_destination_row (PsppSheetView *tree_view,
5943 GdkDragContext *context,
5944 /* coordinates relative to the widget */
5947 GdkDragAction *suggested_action,
5950 GtkTreePath *path = NULL;
5951 PsppSheetViewDropPosition pos;
5952 PsppSheetViewDropPosition old_pos;
5953 TreeViewDragInfo *di;
5955 GtkTreePath *old_dest_path = NULL;
5956 gboolean can_drop = FALSE;
5958 *suggested_action = 0;
5961 widget = GTK_WIDGET (tree_view);
5963 di = get_info (tree_view);
5965 if (di == NULL || y - TREE_VIEW_HEADER_HEIGHT (tree_view) < 0)
5967 /* someone unset us as a drag dest, note that if
5968 * we return FALSE drag_leave isn't called
5971 pspp_sheet_view_set_drag_dest_row (tree_view,
5973 PSPP_SHEET_VIEW_DROP_BEFORE);
5975 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
5977 return FALSE; /* no longer a drop site */
5980 *target = gtk_drag_dest_find_target (widget, context,
5981 gtk_drag_dest_get_target_list (widget));
5982 if (*target == GDK_NONE)
5987 if (!pspp_sheet_view_get_dest_row_at_pos (tree_view,
5993 GtkTreeModel *model;
5995 /* the row got dropped on empty space, let's setup a special case
5999 gtk_tree_path_free (path);
6001 model = pspp_sheet_view_get_model (tree_view);
6003 n_children = gtk_tree_model_iter_n_children (model, NULL);
6006 pos = PSPP_SHEET_VIEW_DROP_AFTER;
6007 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
6011 pos = PSPP_SHEET_VIEW_DROP_BEFORE;
6012 path = gtk_tree_path_new_from_indices (0, -1);
6022 /* If we left the current row's "open" zone, unset the timeout for
6025 pspp_sheet_view_get_drag_dest_row (tree_view,
6030 gtk_tree_path_free (old_dest_path);
6032 if (TRUE /* FIXME if the location droppable predicate */)
6040 GtkWidget *source_widget;
6042 *suggested_action = gdk_drag_context_get_suggested_action (context);
6043 source_widget = gtk_drag_get_source_widget (context);
6045 if (source_widget == widget)
6047 /* Default to MOVE, unless the user has
6048 * pressed ctrl or shift to affect available actions
6050 if ((gdk_drag_context_get_actions (context) & GDK_ACTION_MOVE) != 0)
6051 *suggested_action = GDK_ACTION_MOVE;
6054 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6059 /* can't drop here */
6060 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6062 PSPP_SHEET_VIEW_DROP_BEFORE);
6066 gtk_tree_path_free (path);
6072 get_logical_dest_row (PsppSheetView *tree_view,
6073 gboolean *path_down_mode,
6074 gboolean *drop_append_mode)
6076 /* adjust path to point to the row the drop goes in front of */
6077 GtkTreePath *path = NULL;
6078 PsppSheetViewDropPosition pos;
6080 g_return_val_if_fail (path_down_mode != NULL, NULL);
6081 g_return_val_if_fail (drop_append_mode != NULL, NULL);
6083 *path_down_mode = FALSE;
6084 *drop_append_mode = 0;
6086 pspp_sheet_view_get_drag_dest_row (tree_view, &path, &pos);
6091 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE)
6093 else if (pos == PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE ||
6094 pos == PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER)
6095 *path_down_mode = TRUE;
6099 GtkTreeModel *model = pspp_sheet_view_get_model (tree_view);
6101 g_assert (pos == PSPP_SHEET_VIEW_DROP_AFTER);
6103 if (!gtk_tree_model_get_iter (model, &iter, path) ||
6104 !gtk_tree_model_iter_next (model, &iter))
6105 *drop_append_mode = 1;
6108 *drop_append_mode = 0;
6109 gtk_tree_path_next (path);
6117 pspp_sheet_view_maybe_begin_dragging_row (PsppSheetView *tree_view,
6118 GdkEventMotion *event)
6120 GtkWidget *widget = GTK_WIDGET (tree_view);
6121 GdkDragContext *context;
6122 TreeViewDragInfo *di;
6123 GtkTreePath *path = NULL;
6125 gint cell_x, cell_y;
6126 GtkTreeModel *model;
6127 gboolean retval = FALSE;
6129 di = get_info (tree_view);
6131 if (di == NULL || !di->source_set)
6134 if (tree_view->priv->pressed_button < 0)
6137 if (!gtk_drag_check_threshold (widget,
6138 tree_view->priv->press_start_x,
6139 tree_view->priv->press_start_y,
6140 event->x, event->y))
6143 model = pspp_sheet_view_get_model (tree_view);
6148 button = tree_view->priv->pressed_button;
6149 tree_view->priv->pressed_button = -1;
6151 pspp_sheet_view_get_path_at_pos (tree_view,
6152 tree_view->priv->press_start_x,
6153 tree_view->priv->press_start_y,
6162 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6163 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6167 if (!(GDK_BUTTON1_MASK << (button - 1) & di->start_button_mask))
6170 /* Now we can begin the drag */
6174 context = gtk_drag_begin (widget,
6175 gtk_drag_source_get_target_list (widget),
6180 set_source_row (context, model, path);
6184 gtk_tree_path_free (path);
6192 pspp_sheet_view_drag_begin (GtkWidget *widget,
6193 GdkDragContext *context)
6196 PsppSheetView *tree_view;
6197 GtkTreePath *path = NULL;
6198 gint cell_x, cell_y;
6200 TreeViewDragInfo *di;
6202 tree_view = PSPP_SHEET_VIEW (widget);
6204 /* if the user uses a custom DND source impl, we don't set the icon here */
6205 di = get_info (tree_view);
6207 if (di == NULL || !di->source_set)
6210 pspp_sheet_view_get_path_at_pos (tree_view,
6211 tree_view->priv->press_start_x,
6212 tree_view->priv->press_start_y,
6218 g_return_if_fail (path != NULL);
6220 row_pix = pspp_sheet_view_create_row_drag_icon (tree_view,
6223 gtk_drag_set_icon_pixmap (context,
6224 gdk_drawable_get_colormap (row_pix),
6227 /* the + 1 is for the black border in the icon */
6228 tree_view->priv->press_start_x + 1,
6231 g_object_unref (row_pix);
6232 gtk_tree_path_free (path);
6238 pspp_sheet_view_drag_end (GtkWidget *widget,
6239 GdkDragContext *context)
6244 /* Default signal implementations for the drag signals */
6246 pspp_sheet_view_drag_data_get (GtkWidget *widget,
6247 GdkDragContext *context,
6248 GtkSelectionData *selection_data,
6252 PsppSheetView *tree_view;
6253 GtkTreeModel *model;
6254 TreeViewDragInfo *di;
6255 GtkTreePath *source_row;
6257 tree_view = PSPP_SHEET_VIEW (widget);
6259 model = pspp_sheet_view_get_model (tree_view);
6264 di = get_info (PSPP_SHEET_VIEW (widget));
6269 source_row = get_source_row (context);
6271 if (source_row == NULL)
6274 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6275 * any model; for DragSource models there are some other targets
6279 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6280 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6285 /* If drag_data_get does nothing, try providing row data. */
6286 if (gtk_selection_data_get_target (selection_data) == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6288 gtk_tree_set_row_drag_data (selection_data,
6294 gtk_tree_path_free (source_row);
6299 pspp_sheet_view_drag_data_delete (GtkWidget *widget,
6300 GdkDragContext *context)
6302 TreeViewDragInfo *di;
6303 GtkTreeModel *model;
6304 PsppSheetView *tree_view;
6305 GtkTreePath *source_row;
6307 tree_view = PSPP_SHEET_VIEW (widget);
6308 model = pspp_sheet_view_get_model (tree_view);
6310 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
6313 di = get_info (tree_view);
6318 source_row = get_source_row (context);
6320 if (source_row == NULL)
6323 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6326 gtk_tree_path_free (source_row);
6328 set_source_row (context, NULL, NULL);
6332 pspp_sheet_view_drag_leave (GtkWidget *widget,
6333 GdkDragContext *context,
6336 /* unset any highlight row */
6337 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6339 PSPP_SHEET_VIEW_DROP_BEFORE);
6341 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6346 pspp_sheet_view_drag_motion (GtkWidget *widget,
6347 GdkDragContext *context,
6348 /* coordinates relative to the widget */
6354 GtkTreePath *path = NULL;
6355 PsppSheetViewDropPosition pos;
6356 PsppSheetView *tree_view;
6357 GdkDragAction suggested_action = 0;
6360 tree_view = PSPP_SHEET_VIEW (widget);
6362 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6365 pspp_sheet_view_get_drag_dest_row (tree_view, &path, &pos);
6367 /* we only know this *after* set_desination_row */
6368 empty = tree_view->priv->empty_view_drop;
6370 if (path == NULL && !empty)
6372 /* Can't drop here. */
6373 gdk_drag_status (context, 0, time);
6377 if (tree_view->priv->open_dest_timeout == 0 &&
6378 (pos == PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER ||
6379 pos == PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE))
6385 add_scroll_timeout (tree_view);
6388 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6390 /* Request data so we can use the source row when
6391 * determining whether to accept the drop
6393 set_status_pending (context, suggested_action);
6394 gtk_drag_get_data (widget, context, target, time);
6398 set_status_pending (context, 0);
6399 gdk_drag_status (context, suggested_action, time);
6404 gtk_tree_path_free (path);
6411 pspp_sheet_view_drag_drop (GtkWidget *widget,
6412 GdkDragContext *context,
6413 /* coordinates relative to the widget */
6418 PsppSheetView *tree_view;
6420 GdkDragAction suggested_action = 0;
6421 GdkAtom target = GDK_NONE;
6422 TreeViewDragInfo *di;
6423 GtkTreeModel *model;
6424 gboolean path_down_mode;
6425 gboolean drop_append_mode;
6427 tree_view = PSPP_SHEET_VIEW (widget);
6429 model = pspp_sheet_view_get_model (tree_view);
6431 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6433 di = get_info (tree_view);
6438 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
6441 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6444 path = get_logical_dest_row (tree_view, &path_down_mode, &drop_append_mode);
6446 if (target != GDK_NONE && path != NULL)
6448 /* in case a motion had requested drag data, change things so we
6449 * treat drag data receives as a drop.
6451 set_status_pending (context, 0);
6452 set_dest_row (context, model, path,
6453 path_down_mode, tree_view->priv->empty_view_drop,
6458 gtk_tree_path_free (path);
6460 /* Unset this thing */
6461 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6463 PSPP_SHEET_VIEW_DROP_BEFORE);
6465 if (target != GDK_NONE)
6467 gtk_drag_get_data (widget, context, target, time);
6475 pspp_sheet_view_drag_data_received (GtkWidget *widget,
6476 GdkDragContext *context,
6477 /* coordinates relative to the widget */
6480 GtkSelectionData *selection_data,
6485 TreeViewDragInfo *di;
6486 gboolean accepted = FALSE;
6487 GtkTreeModel *model;
6488 PsppSheetView *tree_view;
6489 GtkTreePath *dest_row;
6490 GdkDragAction suggested_action;
6491 gboolean path_down_mode;
6492 gboolean drop_append_mode;
6494 tree_view = PSPP_SHEET_VIEW (widget);
6496 model = pspp_sheet_view_get_model (tree_view);
6498 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_data_received"))
6501 di = get_info (tree_view);
6506 suggested_action = get_status_pending (context);
6508 if (suggested_action)
6510 /* We are getting this data due to a request in drag_motion,
6511 * rather than due to a request in drag_drop, so we are just
6512 * supposed to call drag_status, not actually paste in the
6515 path = get_logical_dest_row (tree_view, &path_down_mode,
6519 suggested_action = 0;
6520 else if (path_down_mode)
6521 gtk_tree_path_down (path);
6523 if (suggested_action)
6525 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6531 path_down_mode = FALSE;
6532 gtk_tree_path_up (path);
6534 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6537 suggested_action = 0;
6540 suggested_action = 0;
6544 gdk_drag_status (context, suggested_action, time);
6547 gtk_tree_path_free (path);
6549 /* If you can't drop, remove user drop indicator until the next motion */
6550 if (suggested_action == 0)
6551 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6553 PSPP_SHEET_VIEW_DROP_BEFORE);
6558 dest_row = get_dest_row (context, &path_down_mode);
6560 if (dest_row == NULL)
6563 if (gtk_selection_data_get_length (selection_data) >= 0)
6567 gtk_tree_path_down (dest_row);
6568 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6569 dest_row, selection_data))
6570 gtk_tree_path_up (dest_row);
6574 if (gtk_selection_data_get_length (selection_data) >= 0)
6576 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6582 gtk_drag_finish (context,
6584 (gdk_drag_context_get_actions (context) == GDK_ACTION_MOVE),
6587 if (gtk_tree_path_get_depth (dest_row) == 1
6588 && gtk_tree_path_get_indices (dest_row)[0] == 0)
6590 /* special special case drag to "0", scroll to first item */
6591 if (!tree_view->priv->scroll_to_path)
6592 pspp_sheet_view_scroll_to_cell (tree_view, dest_row, NULL, FALSE, 0.0, 0.0);
6595 gtk_tree_path_free (dest_row);
6598 set_dest_row (context, NULL, NULL, FALSE, FALSE, FALSE);
6603 /* GtkContainer Methods
6608 pspp_sheet_view_remove (GtkContainer *container,
6611 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6612 PsppSheetViewChild *child = NULL;
6615 tmp_list = tree_view->priv->children;
6618 child = tmp_list->data;
6619 if (child->widget == widget)
6621 gtk_widget_unparent (widget);
6623 tree_view->priv->children = g_list_remove_link (tree_view->priv->children, tmp_list);
6624 g_list_free_1 (tmp_list);
6625 g_slice_free (PsppSheetViewChild, child);
6629 tmp_list = tmp_list->next;
6632 tmp_list = tree_view->priv->columns;
6636 PsppSheetViewColumn *column;
6637 column = tmp_list->data;
6638 if (column->button == widget)
6640 gtk_widget_unparent (widget);
6643 tmp_list = tmp_list->next;
6648 pspp_sheet_view_forall (GtkContainer *container,
6649 gboolean include_internals,
6650 GtkCallback callback,
6651 gpointer callback_data)
6653 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6654 PsppSheetViewChild *child = NULL;
6655 PsppSheetViewColumn *column;
6658 tmp_list = tree_view->priv->children;
6661 child = tmp_list->data;
6662 tmp_list = tmp_list->next;
6664 (* callback) (child->widget, callback_data);
6666 if (include_internals == FALSE)
6669 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6671 column = tmp_list->data;
6674 (* callback) (column->button, callback_data);
6678 /* Returns TRUE if the treeview contains no "special" (editable or activatable)
6679 * cells. If so we draw one big row-spanning focus rectangle.
6682 pspp_sheet_view_has_special_cell (PsppSheetView *tree_view)
6686 if (tree_view->priv->special_cells != PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT)
6687 return tree_view->priv->special_cells = PSPP_SHEET_VIEW_SPECIAL_CELLS_YES;
6689 for (list = tree_view->priv->columns; list; list = list->next)
6691 if (!((PsppSheetViewColumn *)list->data)->visible)
6693 if (_pspp_sheet_view_column_count_special_cells (list->data))
6701 pspp_sheet_view_focus_column (PsppSheetView *tree_view,
6702 PsppSheetViewColumn *focus_column,
6703 gboolean clamp_column_visible)
6705 g_return_if_fail (focus_column != NULL);
6707 tree_view->priv->focus_column = focus_column;
6708 if (!focus_column->button)
6710 pspp_sheet_view_column_set_need_button (focus_column, TRUE);
6711 // g_return_if_fail (focus_column->button != NULL);
6712 if (focus_column->button == NULL)
6716 if (gtk_container_get_focus_child (GTK_CONTAINER (tree_view)) != focus_column->button)
6717 gtk_widget_grab_focus (focus_column->button);
6719 if (clamp_column_visible)
6720 pspp_sheet_view_clamp_column_visible (tree_view, focus_column, FALSE);
6723 /* Returns TRUE if the focus is within the headers, after the focus operation is
6727 pspp_sheet_view_header_focus (PsppSheetView *tree_view,
6728 GtkDirectionType dir,
6729 gboolean clamp_column_visible)
6731 GtkWidget *focus_child;
6732 PsppSheetViewColumn *focus_column;
6733 GList *last_column, *first_column;
6737 if (! PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
6740 focus_child = gtk_container_get_focus_child (GTK_CONTAINER (tree_view));
6742 first_column = tree_view->priv->columns;
6743 while (first_column)
6745 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (first_column->data);
6747 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6749 first_column = first_column->next;
6752 /* No headers are visible, or are focusable. We can't focus in or out.
6754 if (first_column == NULL)
6757 last_column = g_list_last (tree_view->priv->columns);
6760 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (last_column->data);
6762 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6764 last_column = last_column->prev;
6768 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
6772 case GTK_DIR_TAB_BACKWARD:
6773 case GTK_DIR_TAB_FORWARD:
6776 if (focus_child == NULL)
6778 if (tree_view->priv->focus_column != NULL &&
6779 pspp_sheet_view_column_can_focus (tree_view->priv->focus_column))
6780 focus_column = tree_view->priv->focus_column;
6782 focus_column = first_column->data;
6783 pspp_sheet_view_focus_column (tree_view, focus_column,
6784 clamp_column_visible);
6791 if (focus_child == NULL)
6793 if (tree_view->priv->focus_column != NULL)
6794 focus_column = tree_view->priv->focus_column;
6795 else if (dir == GTK_DIR_LEFT)
6796 focus_column = last_column->data;
6798 focus_column = first_column->data;
6799 pspp_sheet_view_focus_column (tree_view, focus_column,
6800 clamp_column_visible);
6804 if (gtk_widget_child_focus (focus_child, dir))
6806 /* The focus moves inside the button. */
6807 /* This is probably a great example of bad UI */
6808 if (clamp_column_visible)
6809 pspp_sheet_view_clamp_column_visible (tree_view,
6810 tree_view->priv->focus_column,
6815 /* We need to move the focus among the row of buttons. */
6816 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6817 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)->button == focus_child)
6820 if ((tmp_list == first_column && dir == (rtl ? GTK_DIR_RIGHT : GTK_DIR_LEFT))
6821 || (tmp_list == last_column && dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT)))
6823 gtk_widget_error_bell (GTK_WIDGET (tree_view));
6829 PsppSheetViewColumn *column;
6831 if (dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT))
6832 tmp_list = tmp_list->next;
6834 tmp_list = tmp_list->prev;
6836 if (tmp_list == NULL)
6838 g_warning ("Internal button not found");
6841 column = tmp_list->data;
6842 if (column->visible &&
6843 pspp_sheet_view_column_can_focus (column))
6845 pspp_sheet_view_column_set_need_button (column, TRUE);
6848 pspp_sheet_view_focus_column (tree_view, column,
6849 clamp_column_visible);
6857 g_assert_not_reached ();
6864 /* This function returns in 'path' the first focusable path, if the given path
6865 * is already focusable, it's the returned one.
6869 search_first_focusable_path (PsppSheetView *tree_view,
6871 gboolean search_forward,
6874 /* XXX this function is trivial given that the sheetview doesn't support
6878 if (!path || !*path)
6881 _pspp_sheet_view_find_node (tree_view, *path, &node);
6889 return (*path != NULL);
6893 pspp_sheet_view_focus (GtkWidget *widget,
6894 GtkDirectionType direction)
6896 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6897 GtkContainer *container = GTK_CONTAINER (widget);
6898 GtkWidget *focus_child;
6900 if (!gtk_widget_is_sensitive (widget) || !gtk_widget_get_can_focus (widget))
6903 focus_child = gtk_container_get_focus_child (container);
6905 pspp_sheet_view_stop_editing (PSPP_SHEET_VIEW (widget), FALSE);
6906 /* Case 1. Headers currently have focus. */
6913 pspp_sheet_view_header_focus (tree_view, direction, TRUE);
6915 case GTK_DIR_TAB_BACKWARD:
6918 case GTK_DIR_TAB_FORWARD:
6920 gtk_widget_grab_focus (widget);
6923 g_assert_not_reached ();
6928 /* Case 2. We don't have focus at all. */
6929 if (!gtk_widget_has_focus (widget))
6931 if (!pspp_sheet_view_header_focus (tree_view, direction, FALSE))
6932 gtk_widget_grab_focus (widget);
6936 /* Case 3. We have focus already. */
6937 if (direction == GTK_DIR_TAB_BACKWARD)
6938 return (pspp_sheet_view_header_focus (tree_view, direction, FALSE));
6939 else if (direction == GTK_DIR_TAB_FORWARD)
6942 /* Other directions caught by the keybindings */
6943 gtk_widget_grab_focus (widget);
6948 pspp_sheet_view_grab_focus (GtkWidget *widget)
6950 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->grab_focus (widget);
6952 pspp_sheet_view_focus_to_cursor (PSPP_SHEET_VIEW (widget));
6956 pspp_sheet_view_style_set (GtkWidget *widget,
6957 GtkStyle *previous_style)
6959 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6961 PsppSheetViewColumn *column;
6963 if (gtk_widget_get_realized (widget))
6965 gdk_window_set_background (tree_view->priv->bin_window, >k_widget_get_style (widget)->base[gtk_widget_get_state (widget)]);
6966 gtk_style_set_background (gtk_widget_get_style (widget), tree_view->priv->header_window, GTK_STATE_NORMAL);
6967 pspp_sheet_view_set_grid_lines (tree_view, tree_view->priv->grid_lines);
6970 gtk_widget_style_get (widget,
6971 "expander-size", &tree_view->priv->expander_size,
6973 tree_view->priv->expander_size += EXPANDER_EXTRA_PADDING;
6975 for (list = tree_view->priv->columns; list; list = list->next)
6977 column = list->data;
6978 _pspp_sheet_view_column_cell_set_dirty (column);
6981 tree_view->priv->fixed_height = -1;
6983 /* Invalidate cached button style. */
6984 if (tree_view->priv->button_style)
6986 g_object_unref (tree_view->priv->button_style);
6987 tree_view->priv->button_style = NULL;
6990 gtk_widget_queue_resize (widget);
6995 pspp_sheet_view_set_focus_child (GtkContainer *container,
6998 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
7001 for (list = tree_view->priv->columns; list; list = list->next)
7003 if (PSPP_SHEET_VIEW_COLUMN (list->data)->button == child)
7005 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
7010 GTK_CONTAINER_CLASS (pspp_sheet_view_parent_class)->set_focus_child (container, child);
7014 pspp_sheet_view_set_adjustments (PsppSheetView *tree_view,
7015 GtkAdjustment *hadj,
7016 GtkAdjustment *vadj)
7018 gboolean need_adjust = FALSE;
7020 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
7023 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
7025 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
7027 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
7029 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
7031 if (tree_view->priv->hadjustment && (tree_view->priv->hadjustment != hadj))
7033 g_signal_handlers_disconnect_by_func (tree_view->priv->hadjustment,
7034 pspp_sheet_view_adjustment_changed,
7036 g_object_unref (tree_view->priv->hadjustment);
7039 if (tree_view->priv->vadjustment && (tree_view->priv->vadjustment != vadj))
7041 g_signal_handlers_disconnect_by_func (tree_view->priv->vadjustment,
7042 pspp_sheet_view_adjustment_changed,
7044 g_object_unref (tree_view->priv->vadjustment);
7047 if (tree_view->priv->hadjustment != hadj)
7049 tree_view->priv->hadjustment = hadj;
7050 g_object_ref_sink (tree_view->priv->hadjustment);
7052 g_signal_connect (tree_view->priv->hadjustment, "value-changed",
7053 G_CALLBACK (pspp_sheet_view_adjustment_changed),
7058 if (tree_view->priv->vadjustment != vadj)
7060 tree_view->priv->vadjustment = vadj;
7061 g_object_ref_sink (tree_view->priv->vadjustment);
7063 g_signal_connect (tree_view->priv->vadjustment, "value-changed",
7064 G_CALLBACK (pspp_sheet_view_adjustment_changed),
7070 pspp_sheet_view_adjustment_changed (NULL, tree_view);
7075 pspp_sheet_view_real_move_cursor (PsppSheetView *tree_view,
7076 GtkMovementStep step,
7079 PsppSheetSelectMode mode;
7080 GdkModifierType state;
7082 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
7083 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
7084 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
7085 step == GTK_MOVEMENT_DISPLAY_LINES ||
7086 step == GTK_MOVEMENT_PAGES ||
7087 step == GTK_MOVEMENT_BUFFER_ENDS ||
7088 step == GTK_MOVEMENT_DISPLAY_LINE_ENDS, FALSE);
7090 if (tree_view->priv->row_count == 0)
7092 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7095 pspp_sheet_view_stop_editing (tree_view, FALSE);
7096 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
7097 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7100 if (gtk_get_current_event_state (&state))
7102 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
7103 mode |= PSPP_SHEET_SELECT_MODE_TOGGLE;
7104 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
7105 mode |= PSPP_SHEET_SELECT_MODE_EXTEND;
7107 /* else we assume not pressed */
7111 case GTK_MOVEMENT_LOGICAL_POSITIONS:
7112 pspp_sheet_view_move_cursor_tab (tree_view, count);
7114 case GTK_MOVEMENT_VISUAL_POSITIONS:
7115 pspp_sheet_view_move_cursor_left_right (tree_view, count, mode);
7117 case GTK_MOVEMENT_DISPLAY_LINES:
7118 pspp_sheet_view_move_cursor_up_down (tree_view, count, mode);
7120 case GTK_MOVEMENT_PAGES:
7121 pspp_sheet_view_move_cursor_page_up_down (tree_view, count, mode);
7123 case GTK_MOVEMENT_BUFFER_ENDS:
7124 pspp_sheet_view_move_cursor_start_end (tree_view, count, mode);
7126 case GTK_MOVEMENT_DISPLAY_LINE_ENDS:
7127 pspp_sheet_view_move_cursor_line_start_end (tree_view, count, mode);
7130 g_assert_not_reached ();
7137 pspp_sheet_view_put (PsppSheetView *tree_view,
7138 GtkWidget *child_widget,
7139 /* in bin_window coordinates */
7145 PsppSheetViewChild *child;
7147 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
7148 g_return_if_fail (GTK_IS_WIDGET (child_widget));
7150 child = g_slice_new (PsppSheetViewChild);
7152 child->widget = child_widget;
7155 child->width = width;
7156 child->height = height;
7158 tree_view->priv->children = g_list_append (tree_view->priv->children, child);
7160 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7161 gtk_widget_set_parent_window (child->widget, tree_view->priv->bin_window);
7163 gtk_widget_set_parent (child_widget, GTK_WIDGET (tree_view));
7167 _pspp_sheet_view_child_move_resize (PsppSheetView *tree_view,
7169 /* in tree coordinates */
7175 PsppSheetViewChild *child = NULL;
7177 GdkRectangle allocation;
7179 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
7180 g_return_if_fail (GTK_IS_WIDGET (widget));
7182 for (list = tree_view->priv->children; list; list = list->next)
7184 if (((PsppSheetViewChild *)list->data)->widget == widget)
7193 allocation.x = child->x = x;
7194 allocation.y = child->y = y;
7195 allocation.width = child->width = width;
7196 allocation.height = child->height = height;
7198 if (gtk_widget_get_realized (widget))
7199 gtk_widget_size_allocate (widget, &allocation);
7203 /* TreeModel Callbacks
7207 pspp_sheet_view_row_changed (GtkTreeModel *model,
7212 PsppSheetView *tree_view = (PsppSheetView *)data;
7214 gboolean free_path = FALSE;
7215 GtkTreePath *cursor_path;
7217 g_return_if_fail (path != NULL || iter != NULL);
7219 if (tree_view->priv->cursor != NULL)
7220 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7224 if (tree_view->priv->edited_column &&
7225 (cursor_path == NULL || gtk_tree_path_compare (cursor_path, path) == 0))
7226 pspp_sheet_view_stop_editing (tree_view, TRUE);
7228 if (cursor_path != NULL)
7229 gtk_tree_path_free (cursor_path);
7233 path = gtk_tree_model_get_path (model, iter);
7236 else if (iter == NULL)
7237 gtk_tree_model_get_iter (model, iter, path);
7239 _pspp_sheet_view_find_node (tree_view,
7245 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7246 pspp_sheet_view_node_queue_redraw (tree_view, node);
7250 gtk_tree_path_free (path);
7254 pspp_sheet_view_row_inserted (GtkTreeModel *model,
7259 PsppSheetView *tree_view = (PsppSheetView *) data;
7262 gint height = tree_view->priv->fixed_height;
7263 gboolean free_path = FALSE;
7264 gboolean node_visible = TRUE;
7266 g_return_if_fail (path != NULL || iter != NULL);
7270 path = gtk_tree_model_get_path (model, iter);
7273 else if (iter == NULL)
7274 gtk_tree_model_get_iter (model, iter, path);
7276 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7278 /* Update all row-references */
7279 gtk_tree_row_reference_inserted (G_OBJECT (data), path);
7280 indices = gtk_tree_path_get_indices (path);
7281 tmpnode = indices[0];
7283 range_tower_insert0 (tree_view->priv->selected, tmpnode, 1);
7287 if (node_visible && node_is_visible (tree_view, tmpnode))
7288 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7290 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (tree_view));
7293 install_presize_handler (tree_view);
7295 gtk_tree_path_free (path);
7299 pspp_sheet_view_row_deleted (GtkTreeModel *model,
7303 PsppSheetView *tree_view = (PsppSheetView *)data;
7306 g_return_if_fail (path != NULL);
7308 gtk_tree_row_reference_deleted (G_OBJECT (data), path);
7310 _pspp_sheet_view_find_node (tree_view, path, &node);
7315 range_tower_delete (tree_view->priv->selected, node, 1);
7317 /* Ensure we don't have a dangling pointer to a dead node */
7318 ensure_unprelighted (tree_view);
7320 /* Cancel editting if we've started */
7321 pspp_sheet_view_stop_editing (tree_view, TRUE);
7323 if (tree_view->priv->destroy_count_func)
7325 gint child_count = 0;
7326 tree_view->priv->destroy_count_func (tree_view, path, child_count, tree_view->priv->destroy_count_data);
7329 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7331 if (! gtk_tree_row_reference_valid (tree_view->priv->top_row))
7333 gtk_tree_row_reference_free (tree_view->priv->top_row);
7334 tree_view->priv->top_row = NULL;
7337 install_scroll_sync_handler (tree_view);
7339 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7342 if (helper_data.changed)
7343 g_signal_emit_by_name (tree_view->priv->selection, "changed");
7348 pspp_sheet_view_rows_reordered (GtkTreeModel *model,
7349 GtkTreePath *parent,
7354 PsppSheetView *tree_view = PSPP_SHEET_VIEW (data);
7357 /* XXX need to adjust selection */
7358 len = gtk_tree_model_iter_n_children (model, iter);
7363 gtk_tree_row_reference_reordered (G_OBJECT (data),
7368 if (gtk_tree_path_get_depth (parent) != 0)
7371 if (tree_view->priv->edited_column)
7372 pspp_sheet_view_stop_editing (tree_view, TRUE);
7374 /* we need to be unprelighted */
7375 ensure_unprelighted (tree_view);
7377 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
7379 pspp_sheet_view_dy_to_top_row (tree_view);
7383 /* Internal tree functions
7388 pspp_sheet_view_get_background_xrange (PsppSheetView *tree_view,
7389 PsppSheetViewColumn *column,
7393 PsppSheetViewColumn *tmp_column = NULL;
7404 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7407 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
7409 list = (rtl ? list->prev : list->next))
7411 tmp_column = list->data;
7413 if (tmp_column == column)
7416 if (tmp_column->visible)
7417 total_width += tmp_column->width;
7420 if (tmp_column != column)
7422 g_warning (G_STRLOC": passed-in column isn't in the tree");
7431 if (column->visible)
7432 *x2 = total_width + column->width;
7434 *x2 = total_width; /* width of 0 */
7438 /* Make sure the node is visible vertically */
7440 pspp_sheet_view_clamp_node_visible (PsppSheetView *tree_view,
7443 gint node_dy, height;
7444 GtkTreePath *path = NULL;
7446 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7449 /* just return if the node is visible, avoiding a costly expose */
7450 node_dy = pspp_sheet_view_node_find_offset (tree_view, node);
7451 height = ROW_HEIGHT (tree_view);
7452 if (node_dy >= gtk_adjustment_get_value (tree_view->priv->vadjustment)
7453 && node_dy + height <= (gtk_adjustment_get_value (tree_view->priv->vadjustment)
7454 + gtk_adjustment_get_page_size (tree_view->priv->vadjustment)))
7457 path = _pspp_sheet_view_find_path (tree_view, node);
7460 /* We process updates because we want to clear old selected items when we scroll.
7461 * if this is removed, we get a "selection streak" at the bottom. */
7462 gdk_window_process_updates (tree_view->priv->bin_window, TRUE);
7463 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL, FALSE, 0.0, 0.0);
7464 gtk_tree_path_free (path);
7469 pspp_sheet_view_clamp_column_visible (PsppSheetView *tree_view,
7470 PsppSheetViewColumn *column,
7471 gboolean focus_to_cell)
7478 x = column->allocation.x;
7479 width = column->allocation.width;
7481 if (width > gtk_adjustment_get_page_size (tree_view->priv->hadjustment))
7483 /* The column is larger than the horizontal page size. If the
7484 * column has cells which can be focussed individually, then we make
7485 * sure the cell which gets focus is fully visible (if even the
7486 * focus cell is bigger than the page size, we make sure the
7487 * left-hand side of the cell is visible).
7489 * If the column does not have those so-called special cells, we
7490 * make sure the left-hand side of the column is visible.
7493 if (focus_to_cell && pspp_sheet_view_has_special_cell (tree_view))
7495 GtkTreePath *cursor_path;
7496 GdkRectangle background_area, cell_area, focus_area;
7498 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7500 pspp_sheet_view_get_cell_area (tree_view,
7501 cursor_path, column, &cell_area);
7502 pspp_sheet_view_get_background_area (tree_view,
7503 cursor_path, column,
7506 gtk_tree_path_free (cursor_path);
7508 _pspp_sheet_view_column_get_focus_area (column,
7514 width = focus_area.width;
7516 if (width < gtk_adjustment_get_page_size (tree_view->priv->hadjustment))
7518 if ((gtk_adjustment_get_value (tree_view->priv->hadjustment) + gtk_adjustment_get_page_size (tree_view->priv->hadjustment)) < (x + width))
7519 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7520 x + width - gtk_adjustment_get_page_size (tree_view->priv->hadjustment));
7521 else if (gtk_adjustment_get_value (tree_view->priv->hadjustment) > x)
7522 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7526 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7528 gtk_adjustment_get_lower (tree_view->priv->hadjustment),
7529 gtk_adjustment_get_upper (tree_view->priv->hadjustment)
7530 - gtk_adjustment_get_page_size (tree_view->priv->hadjustment)));
7534 if ((gtk_adjustment_get_value (tree_view->priv->hadjustment) + gtk_adjustment_get_page_size (tree_view->priv->hadjustment)) < (x + width))
7535 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7536 x + width - gtk_adjustment_get_page_size (tree_view->priv->hadjustment));
7537 else if (gtk_adjustment_get_value (tree_view->priv->hadjustment) > x)
7538 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7543 _pspp_sheet_view_find_path (PsppSheetView *tree_view,
7548 path = gtk_tree_path_new ();
7550 gtk_tree_path_append_index (path, node);
7555 _pspp_sheet_view_find_node (PsppSheetView *tree_view,
7559 gint *indices = gtk_tree_path_get_indices (path);
7560 gint depth = gtk_tree_path_get_depth (path);
7563 if (depth == 0 || indices[0] < 0 || indices[0] >= tree_view->priv->row_count)
7569 pspp_sheet_view_add_move_binding (GtkBindingSet *binding_set,
7572 gboolean add_shifted_binding,
7573 GtkMovementStep step,
7577 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
7582 if (add_shifted_binding)
7583 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
7588 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
7591 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
7596 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
7603 pspp_sheet_view_set_column_drag_info (PsppSheetView *tree_view,
7604 PsppSheetViewColumn *column)
7606 PsppSheetViewColumn *left_column;
7607 PsppSheetViewColumn *cur_column = NULL;
7608 PsppSheetViewColumnReorder *reorder;
7613 /* We want to precalculate the motion list such that we know what column slots
7617 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7619 /* First, identify all possible drop spots */
7621 tmp_list = g_list_last (tree_view->priv->columns);
7623 tmp_list = g_list_first (tree_view->priv->columns);
7627 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
7628 tmp_list = rtl?g_list_previous (tmp_list):g_list_next (tmp_list);
7630 if (cur_column->visible == FALSE)
7633 /* If it's not the column moving and func tells us to skip over the column, we continue. */
7634 if (left_column != column && cur_column != column &&
7635 tree_view->priv->column_drop_func &&
7636 ! tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
7638 left_column = cur_column;
7641 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7642 reorder->left_column = left_column;
7643 left_column = reorder->right_column = cur_column;
7645 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7648 /* Add the last one */
7649 if (tree_view->priv->column_drop_func == NULL ||
7650 ((left_column != column) &&
7651 tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data)))
7653 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7654 reorder->left_column = left_column;
7655 reorder->right_column = NULL;
7656 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7659 /* We quickly check to see if it even makes sense to reorder columns. */
7660 /* If there is nothing that can be moved, then we return */
7662 if (tree_view->priv->column_drag_info == NULL)
7665 /* We know there are always 2 slots possbile, as you can always return column. */
7666 /* If that's all there is, return */
7667 if (tree_view->priv->column_drag_info->next == NULL ||
7668 (tree_view->priv->column_drag_info->next->next == NULL &&
7669 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->data)->right_column == column &&
7670 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->next->data)->left_column == column))
7672 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7673 g_slice_free (PsppSheetViewColumnReorder, tmp_list->data);
7674 g_list_free (tree_view->priv->column_drag_info);
7675 tree_view->priv->column_drag_info = NULL;
7678 /* We fill in the ranges for the columns, now that we've isolated them */
7679 left = - TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7681 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7683 reorder = (PsppSheetViewColumnReorder *) tmp_list->data;
7685 reorder->left_align = left;
7686 if (tmp_list->next != NULL)
7688 g_assert (tmp_list->next->data);
7689 left = reorder->right_align = (reorder->right_column->allocation.x +
7690 reorder->right_column->allocation.width +
7691 ((PsppSheetViewColumnReorder *)tmp_list->next->data)->left_column->allocation.x)/2;
7695 gint width = gdk_window_get_width (tree_view->priv->header_window);
7696 reorder->right_align = width + TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7702 _pspp_sheet_view_column_start_drag (PsppSheetView *tree_view,
7703 PsppSheetViewColumn *column)
7705 GdkEvent *send_event;
7706 GtkAllocation allocation;
7708 GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
7709 GdkDisplay *display = gdk_screen_get_display (screen);
7711 g_return_if_fail (tree_view->priv->column_drag_info == NULL);
7712 g_return_if_fail (tree_view->priv->cur_reorder == NULL);
7713 g_return_if_fail (column->button);
7715 pspp_sheet_view_set_column_drag_info (tree_view, column);
7717 if (tree_view->priv->column_drag_info == NULL)
7720 if (tree_view->priv->drag_window == NULL)
7722 GdkWindowAttr attributes;
7723 guint attributes_mask;
7725 attributes.window_type = GDK_WINDOW_CHILD;
7726 attributes.wclass = GDK_INPUT_OUTPUT;
7727 attributes.x = column->allocation.x;
7729 attributes.width = column->allocation.width;
7730 attributes.height = column->allocation.height;
7731 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
7732 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
7733 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL ;
7735 tree_view->priv->drag_window = gdk_window_new (tree_view->priv->bin_window,
7738 gdk_window_set_user_data (tree_view->priv->drag_window, GTK_WIDGET (tree_view));
7741 gdk_display_pointer_ungrab (display, GDK_CURRENT_TIME);
7742 gdk_display_keyboard_ungrab (display, GDK_CURRENT_TIME);
7744 gtk_grab_remove (column->button);
7746 send_event = gdk_event_new (GDK_LEAVE_NOTIFY);
7747 send_event->crossing.send_event = TRUE;
7748 send_event->crossing.window = g_object_ref (gtk_button_get_event_window (GTK_BUTTON (column->button)));
7749 send_event->crossing.subwindow = NULL;
7750 send_event->crossing.detail = GDK_NOTIFY_ANCESTOR;
7751 send_event->crossing.time = GDK_CURRENT_TIME;
7753 gtk_propagate_event (column->button, send_event);
7754 gdk_event_free (send_event);
7756 send_event = gdk_event_new (GDK_BUTTON_RELEASE);
7757 send_event->button.window = g_object_ref (gdk_screen_get_root_window (screen));
7758 send_event->button.send_event = TRUE;
7759 send_event->button.time = GDK_CURRENT_TIME;
7760 send_event->button.x = -1;
7761 send_event->button.y = -1;
7762 send_event->button.axes = NULL;
7763 send_event->button.state = 0;
7764 send_event->button.button = 1;
7765 send_event->button.device =
7766 gdk_device_manager_get_client_pointer (gdk_display_get_device_manager (display));
7768 send_event->button.x_root = 0;
7769 send_event->button.y_root = 0;
7771 gtk_propagate_event (column->button, send_event);
7772 gdk_event_free (send_event);
7774 /* Kids, don't try this at home */
7775 g_object_ref (column->button);
7776 gtk_container_remove (GTK_CONTAINER (tree_view), column->button);
7777 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7778 gtk_widget_set_parent (column->button, GTK_WIDGET (tree_view));
7779 g_object_unref (column->button);
7781 tree_view->priv->drag_column_x = column->allocation.x;
7782 allocation = column->allocation;
7784 gtk_widget_size_allocate (column->button, &allocation);
7785 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7787 tree_view->priv->drag_column = column;
7788 gdk_window_show (tree_view->priv->drag_window);
7790 gdk_window_get_origin (tree_view->priv->header_window, &x, &y);
7792 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7793 while (gtk_events_pending ())
7794 gtk_main_iteration ();
7796 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG);
7797 gdk_pointer_grab (tree_view->priv->drag_window,
7799 GDK_POINTER_MOTION_MASK|GDK_BUTTON_RELEASE_MASK,
7800 NULL, NULL, GDK_CURRENT_TIME);
7801 gdk_keyboard_grab (tree_view->priv->drag_window,
7807 _pspp_sheet_view_queue_draw_node (PsppSheetView *tree_view,
7809 const GdkRectangle *clip_rect)
7812 GtkAllocation allocation;
7814 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7817 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
7819 rect.width = MAX (tree_view->priv->width, allocation.width);
7821 rect.y = BACKGROUND_FIRST_PIXEL (tree_view, node);
7822 rect.height = ROW_HEIGHT (tree_view);
7826 GdkRectangle new_rect;
7828 gdk_rectangle_intersect (clip_rect, &rect, &new_rect);
7830 gdk_window_invalidate_rect (tree_view->priv->bin_window, &new_rect, TRUE);
7834 gdk_window_invalidate_rect (tree_view->priv->bin_window, &rect, TRUE);
7839 pspp_sheet_view_queue_draw_path (PsppSheetView *tree_view,
7841 const GdkRectangle *clip_rect)
7845 _pspp_sheet_view_find_node (tree_view, path, &node);
7848 _pspp_sheet_view_queue_draw_node (tree_view, node, clip_rect);
7852 pspp_sheet_view_focus_to_cursor (PsppSheetView *tree_view)
7855 GtkTreePath *cursor_path;
7857 if ((tree_view->priv->row_count == 0) ||
7858 (! gtk_widget_get_realized (GTK_WIDGET (tree_view))))
7862 if (tree_view->priv->cursor)
7863 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7865 if (cursor_path == NULL)
7867 /* There's no cursor. Move the cursor to the first selected row, if any
7868 * are selected, otherwise to the first row in the sheetview.
7870 GList *selected_rows;
7871 GtkTreeModel *model;
7872 PsppSheetSelection *selection;
7874 selection = pspp_sheet_view_get_selection (tree_view);
7875 selected_rows = pspp_sheet_selection_get_selected_rows (selection, &model);
7879 /* XXX we could avoid doing O(n) work to get this result */
7880 cursor_path = gtk_tree_path_copy((const GtkTreePath *)(selected_rows->data));
7881 g_list_foreach (selected_rows, (GFunc)gtk_tree_path_free, NULL);
7882 g_list_free (selected_rows);
7886 cursor_path = gtk_tree_path_new_first ();
7887 search_first_focusable_path (tree_view, &cursor_path,
7891 gtk_tree_row_reference_free (tree_view->priv->cursor);
7892 tree_view->priv->cursor = NULL;
7896 if (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7897 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE)
7898 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, FALSE, FALSE, 0);
7900 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE, 0);
7906 /* Now find a column for the cursor. */
7907 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
7909 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
7910 gtk_tree_path_free (cursor_path);
7912 if (tree_view->priv->focus_column == NULL)
7915 for (list = tree_view->priv->columns; list; list = list->next)
7917 if (PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
7919 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
7920 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
7921 pspp_sheet_selection_select_column (tree_view->priv->selection, tree_view->priv->focus_column);
7931 pspp_sheet_view_move_cursor_up_down (PsppSheetView *tree_view,
7933 PsppSheetSelectMode mode)
7935 gint selection_count;
7936 int cursor_node = -1;
7937 int new_cursor_node = -1;
7938 GtkTreePath *cursor_path = NULL;
7939 gboolean grab_focus = TRUE;
7941 if (! gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7945 if (!gtk_tree_row_reference_valid (tree_view->priv->cursor))
7946 /* FIXME: we lost the cursor; should we get the first? */
7949 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7950 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
7952 if (cursor_node < 0)
7953 /* FIXME: we lost the cursor; should we get the first? */
7956 selection_count = pspp_sheet_selection_count_selected_rows (tree_view->priv->selection);
7958 if (selection_count == 0
7959 && tree_view->priv->selection->type != PSPP_SHEET_SELECTION_NONE
7960 && !(mode & PSPP_SHEET_SELECT_MODE_TOGGLE))
7962 /* Don't move the cursor, but just select the current node */
7963 new_cursor_node = cursor_node;
7968 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
7970 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7973 gtk_tree_path_free (cursor_path);
7975 if (new_cursor_node)
7977 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
7979 search_first_focusable_path (tree_view, &cursor_path,
7984 gtk_tree_path_free (cursor_path);
7988 * If the list has only one item and multi-selection is set then select
7989 * the row (if not yet selected).
7991 if ((tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7992 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE) &&
7993 new_cursor_node < 0)
7996 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7998 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
8000 if (new_cursor_node < 0
8001 && !pspp_sheet_view_node_is_selected (tree_view, cursor_node))
8003 new_cursor_node = cursor_node;
8007 new_cursor_node = -1;
8011 if (new_cursor_node >= 0)
8013 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
8014 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, TRUE, mode);
8015 gtk_tree_path_free (cursor_path);
8019 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8021 if (!(mode & PSPP_SHEET_SELECT_MODE_EXTEND))
8023 if (! gtk_widget_keynav_failed (GTK_WIDGET (tree_view),
8025 GTK_DIR_UP : GTK_DIR_DOWN))
8027 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
8030 gtk_widget_child_focus (toplevel,
8032 GTK_DIR_TAB_BACKWARD :
8033 GTK_DIR_TAB_FORWARD);
8040 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8045 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8047 return new_cursor_node >= 0;
8051 pspp_sheet_view_move_cursor_page_up_down (PsppSheetView *tree_view,
8053 PsppSheetSelectMode mode)
8055 int cursor_node = -1;
8056 GtkTreePath *old_cursor_path = NULL;
8057 GtkTreePath *cursor_path = NULL;
8058 int start_cursor_node = -1;
8061 gint vertical_separator;
8063 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8066 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8067 old_cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8069 /* This is sorta weird. Focus in should give us a cursor */
8072 gtk_widget_style_get (GTK_WIDGET (tree_view), "vertical-separator", &vertical_separator, NULL);
8073 _pspp_sheet_view_find_node (tree_view, old_cursor_path, &cursor_node);
8075 if (cursor_node < 0)
8077 /* FIXME: we lost the cursor. Should we try to get one? */
8078 gtk_tree_path_free (old_cursor_path);
8082 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
8083 window_y = RBTREE_Y_TO_TREE_WINDOW_Y (tree_view, y);
8084 y += tree_view->priv->cursor_offset;
8085 y += count * (int)gtk_adjustment_get_page_increment (tree_view->priv->vadjustment);
8086 y = CLAMP (y, (gint)gtk_adjustment_get_lower (tree_view->priv->vadjustment), (gint)gtk_adjustment_get_upper (tree_view->priv->vadjustment) - vertical_separator);
8088 if (y >= tree_view->priv->height)
8089 y = tree_view->priv->height - 1;
8091 tree_view->priv->cursor_offset =
8092 pspp_sheet_view_find_offset (tree_view, y, &cursor_node);
8094 if (tree_view->priv->cursor_offset > BACKGROUND_HEIGHT (tree_view))
8096 cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
8097 tree_view->priv->cursor_offset -= BACKGROUND_HEIGHT (tree_view);
8100 y -= tree_view->priv->cursor_offset;
8101 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
8103 start_cursor_node = cursor_node;
8105 if (! search_first_focusable_path (tree_view, &cursor_path,
8109 /* It looks like we reached the end of the view without finding
8110 * a focusable row. We will step backwards to find the last
8113 cursor_node = start_cursor_node;
8114 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
8116 search_first_focusable_path (tree_view, &cursor_path,
8125 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
8127 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE, mode);
8130 pspp_sheet_view_scroll_to_point (tree_view, -1, y);
8131 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8132 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8134 if (!gtk_tree_path_compare (old_cursor_path, cursor_path))
8135 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8137 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8140 gtk_tree_path_free (old_cursor_path);
8141 gtk_tree_path_free (cursor_path);
8145 pspp_sheet_view_move_cursor_left_right (PsppSheetView *tree_view,
8147 PsppSheetSelectMode mode)
8149 int cursor_node = -1;
8150 GtkTreePath *cursor_path = NULL;
8151 PsppSheetViewColumn *column;
8154 gboolean found_column = FALSE;
8157 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8159 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8162 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8163 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8167 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8168 if (cursor_node < 0)
8170 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8172 gtk_tree_path_free (cursor_path);
8175 gtk_tree_path_free (cursor_path);
8177 list = rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns);
8178 if (tree_view->priv->focus_column)
8180 for (; list; list = (rtl ? list->prev : list->next))
8182 if (list->data == tree_view->priv->focus_column)
8189 gboolean left, right;
8191 column = list->data;
8192 if (column->visible == FALSE || column->row_head)
8195 pspp_sheet_view_column_cell_set_cell_data (column,
8196 tree_view->priv->model,
8201 right = list->prev ? TRUE : FALSE;
8202 left = list->next ? TRUE : FALSE;
8206 left = list->prev ? TRUE : FALSE;
8207 right = list->next ? TRUE : FALSE;
8210 if (_pspp_sheet_view_column_cell_focus (column, count, left, right))
8212 tree_view->priv->focus_column = column;
8213 found_column = TRUE;
8218 list = rtl ? list->prev : list->next;
8220 list = rtl ? list->next : list->prev;
8225 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8226 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8227 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8231 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8234 pspp_sheet_view_clamp_column_visible (tree_view,
8235 tree_view->priv->focus_column, TRUE);
8239 pspp_sheet_view_move_cursor_line_start_end (PsppSheetView *tree_view,
8241 PsppSheetSelectMode mode)
8243 int cursor_node = -1;
8244 GtkTreePath *cursor_path = NULL;
8245 PsppSheetViewColumn *column;
8246 PsppSheetViewColumn *found_column;
8251 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8253 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8256 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8257 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8261 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8262 if (cursor_node < 0)
8264 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8266 gtk_tree_path_free (cursor_path);
8269 gtk_tree_path_free (cursor_path);
8271 list = rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns);
8272 if (tree_view->priv->focus_column)
8274 for (; list; list = (rtl ? list->prev : list->next))
8276 if (list->data == tree_view->priv->focus_column)
8281 found_column = NULL;
8284 gboolean left, right;
8286 column = list->data;
8287 if (column->visible == FALSE || column->row_head)
8290 pspp_sheet_view_column_cell_set_cell_data (column,
8291 tree_view->priv->model,
8296 right = list->prev ? TRUE : FALSE;
8297 left = list->next ? TRUE : FALSE;
8301 left = list->prev ? TRUE : FALSE;
8302 right = list->next ? TRUE : FALSE;
8305 if (column->tabbable
8306 && _pspp_sheet_view_column_cell_focus (column, count, left, right))
8307 found_column = column;
8311 list = rtl ? list->prev : list->next;
8313 list = rtl ? list->next : list->prev;
8318 tree_view->priv->focus_column = found_column;
8319 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8320 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8321 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8324 pspp_sheet_view_clamp_column_visible (tree_view,
8325 tree_view->priv->focus_column, TRUE);
8329 try_move_cursor_tab (PsppSheetView *tree_view,
8330 gboolean start_at_focus_column,
8333 PsppSheetViewColumn *column;
8335 int cursor_node = -1;
8336 GtkTreePath *cursor_path = NULL;
8340 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8341 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8345 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8346 if (cursor_node < 0)
8348 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8350 gtk_tree_path_free (cursor_path);
8353 gtk_tree_path_free (cursor_path);
8355 rtl = gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL;
8356 if (start_at_focus_column)
8359 ? g_list_last (tree_view->priv->columns)
8360 : g_list_first (tree_view->priv->columns));
8361 if (tree_view->priv->focus_column)
8363 for (; list; list = (rtl ? list->prev : list->next))
8365 if (list->data == tree_view->priv->focus_column)
8372 list = (rtl ^ (count == 1)
8373 ? g_list_first (tree_view->priv->columns)
8374 : g_list_last (tree_view->priv->columns));
8379 gboolean left, right;
8381 column = list->data;
8382 if (column->visible == FALSE || !column->tabbable)
8385 pspp_sheet_view_column_cell_set_cell_data (column,
8386 tree_view->priv->model,
8391 right = list->prev ? TRUE : FALSE;
8392 left = list->next ? TRUE : FALSE;
8396 left = list->prev ? TRUE : FALSE;
8397 right = list->next ? TRUE : FALSE;
8400 if (column->tabbable
8401 && _pspp_sheet_view_column_cell_focus (column, count, left, right))
8403 tree_view->priv->focus_column = column;
8404 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8405 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8406 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8411 list = rtl ? list->prev : list->next;
8413 list = rtl ? list->next : list->prev;
8420 pspp_sheet_view_move_cursor_tab (PsppSheetView *tree_view,
8423 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8426 if (!try_move_cursor_tab (tree_view, TRUE, count))
8428 if (pspp_sheet_view_move_cursor_up_down (tree_view, count, 0)
8429 && !try_move_cursor_tab (tree_view, FALSE, count))
8430 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8433 pspp_sheet_view_clamp_column_visible (tree_view,
8434 tree_view->priv->focus_column, TRUE);
8438 pspp_sheet_view_move_cursor_start_end (PsppSheetView *tree_view,
8440 PsppSheetSelectMode mode)
8444 GtkTreePath *old_path;
8446 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8449 g_return_if_fail (tree_view->priv->row_count > 0);
8451 pspp_sheet_view_get_cursor (tree_view, &old_path, NULL);
8455 /* Now go forward to find the first focusable row. */
8456 path = _pspp_sheet_view_find_path (tree_view, 0);
8457 search_first_focusable_path (tree_view, &path,
8458 TRUE, &cursor_node);
8462 /* Now go backwards to find last focusable row. */
8463 path = _pspp_sheet_view_find_path (tree_view, tree_view->priv->row_count - 1);
8464 search_first_focusable_path (tree_view, &path,
8465 FALSE, &cursor_node);
8471 if (gtk_tree_path_compare (old_path, path))
8473 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, mode);
8474 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8478 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8482 gtk_tree_path_free (old_path);
8483 gtk_tree_path_free (path);
8487 pspp_sheet_view_real_select_all (PsppSheetView *tree_view)
8489 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8492 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8493 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8496 pspp_sheet_selection_select_all (tree_view->priv->selection);
8502 pspp_sheet_view_real_unselect_all (PsppSheetView *tree_view)
8504 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8507 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8508 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8511 pspp_sheet_selection_unselect_all (tree_view->priv->selection);
8517 pspp_sheet_view_real_select_cursor_row (PsppSheetView *tree_view,
8518 gboolean start_editing,
8519 PsppSheetSelectMode mode)
8522 int cursor_node = -1;
8523 GtkTreePath *cursor_path = NULL;
8525 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8528 if (tree_view->priv->cursor)
8529 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8531 if (cursor_path == NULL)
8534 _pspp_sheet_view_find_node (tree_view, cursor_path,
8537 if (cursor_node < 0)
8539 gtk_tree_path_free (cursor_path);
8543 if (!(mode & PSPP_SHEET_SELECT_MODE_EXTEND) && start_editing &&
8544 tree_view->priv->focus_column)
8546 if (pspp_sheet_view_start_editing (tree_view, cursor_path))
8548 gtk_tree_path_free (cursor_path);
8553 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8559 /* We bail out if the original (tree, node) don't exist anymore after
8560 * handling the selection-changed callback. We do return TRUE because
8561 * the key press has been handled at this point.
8563 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8565 if (cursor_node != new_node)
8568 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8570 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8571 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8573 if (!(mode & PSPP_SHEET_SELECT_MODE_EXTEND))
8574 pspp_sheet_view_row_activated (tree_view, cursor_path,
8575 tree_view->priv->focus_column);
8577 gtk_tree_path_free (cursor_path);
8583 pspp_sheet_view_real_toggle_cursor_row (PsppSheetView *tree_view)
8586 int cursor_node = -1;
8587 GtkTreePath *cursor_path = NULL;
8589 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8593 if (tree_view->priv->cursor)
8594 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8596 if (cursor_path == NULL)
8599 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8600 if (cursor_node < 0)
8602 gtk_tree_path_free (cursor_path);
8606 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8609 PSPP_SHEET_SELECT_MODE_TOGGLE,
8612 /* We bail out if the original (tree, node) don't exist anymore after
8613 * handling the selection-changed callback. We do return TRUE because
8614 * the key press has been handled at this point.
8616 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8618 if (cursor_node != new_node)
8621 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8623 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8624 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
8625 gtk_tree_path_free (cursor_path);
8631 pspp_sheet_view_search_entry_flush_timeout (PsppSheetView *tree_view)
8633 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
8634 tree_view->priv->typeselect_flush_timeout = 0;
8639 /* Cut and paste from gtkwindow.c */
8641 send_focus_change (GtkWidget *widget,
8644 GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
8646 fevent->focus_change.type = GDK_FOCUS_CHANGE;
8647 fevent->focus_change.window = g_object_ref (gtk_widget_get_window (widget));
8648 fevent->focus_change.in = in;
8650 gtk_widget_send_focus_change (widget, fevent);
8651 gdk_event_free (fevent);
8655 pspp_sheet_view_ensure_interactive_directory (PsppSheetView *tree_view)
8657 GtkWidget *frame, *vbox, *toplevel;
8660 if (tree_view->priv->search_custom_entry_set)
8663 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
8664 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
8666 if (tree_view->priv->search_window != NULL)
8668 if (gtk_window_get_group (GTK_WINDOW (toplevel)))
8669 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
8670 GTK_WINDOW (tree_view->priv->search_window));
8671 else if (gtk_window_get_group (GTK_WINDOW (tree_view->priv->search_window)))
8672 gtk_window_group_remove_window (gtk_window_get_group (GTK_WINDOW (tree_view->priv->search_window)),
8673 GTK_WINDOW (tree_view->priv->search_window));
8674 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8678 tree_view->priv->search_window = gtk_window_new (GTK_WINDOW_POPUP);
8679 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8681 if (gtk_window_get_group (GTK_WINDOW (toplevel)))
8682 gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)),
8683 GTK_WINDOW (tree_view->priv->search_window));
8685 gtk_window_set_type_hint (GTK_WINDOW (tree_view->priv->search_window),
8686 GDK_WINDOW_TYPE_HINT_UTILITY);
8687 gtk_window_set_modal (GTK_WINDOW (tree_view->priv->search_window), TRUE);
8688 g_signal_connect (tree_view->priv->search_window, "delete-event",
8689 G_CALLBACK (pspp_sheet_view_search_delete_event),
8691 g_signal_connect (tree_view->priv->search_window, "key-press-event",
8692 G_CALLBACK (pspp_sheet_view_search_key_press_event),
8694 g_signal_connect (tree_view->priv->search_window, "button-press-event",
8695 G_CALLBACK (pspp_sheet_view_search_button_press_event),
8697 g_signal_connect (tree_view->priv->search_window, "scroll-event",
8698 G_CALLBACK (pspp_sheet_view_search_scroll_event),
8701 frame = gtk_frame_new (NULL);
8702 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
8703 gtk_widget_show (frame);
8704 gtk_container_add (GTK_CONTAINER (tree_view->priv->search_window), frame);
8706 vbox = gtk_vbox_new (FALSE, 0);
8707 gtk_widget_show (vbox);
8708 gtk_container_add (GTK_CONTAINER (frame), vbox);
8709 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
8712 tree_view->priv->search_entry = gtk_entry_new ();
8713 gtk_widget_show (tree_view->priv->search_entry);
8714 g_signal_connect (tree_view->priv->search_entry, "populate-popup",
8715 G_CALLBACK (pspp_sheet_view_search_disable_popdown),
8717 g_signal_connect (tree_view->priv->search_entry,
8718 "activate", G_CALLBACK (pspp_sheet_view_search_activate),
8722 g_signal_connect (GTK_ENTRY (tree_view->priv->search_entry)->im_context,
8724 G_CALLBACK (pspp_sheet_view_search_preedit_changed),
8728 gtk_container_add (GTK_CONTAINER (vbox),
8729 tree_view->priv->search_entry);
8731 gtk_widget_realize (tree_view->priv->search_entry);
8734 /* Pops up the interactive search entry. If keybinding is TRUE then the user
8735 * started this by typing the start_interactive_search keybinding. Otherwise, it came from
8738 pspp_sheet_view_real_start_interactive_search (PsppSheetView *tree_view,
8739 gboolean keybinding)
8741 /* We only start interactive search if we have focus or the columns
8742 * have focus. If one of our children have focus, we don't want to
8746 gboolean found_focus = FALSE;
8747 GtkWidgetClass *entry_parent_class;
8749 if (!tree_view->priv->enable_search && !keybinding)
8752 if (tree_view->priv->search_custom_entry_set)
8755 if (tree_view->priv->search_window != NULL &&
8756 gtk_widget_get_visible (tree_view->priv->search_window))
8759 for (list = tree_view->priv->columns; list; list = list->next)
8761 PsppSheetViewColumn *column;
8763 column = list->data;
8764 if (! column->visible)
8767 if (column->button && gtk_widget_has_focus (column->button))
8774 if (gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8780 if (tree_view->priv->search_column < 0)
8783 pspp_sheet_view_ensure_interactive_directory (tree_view);
8786 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
8789 tree_view->priv->search_position_func (tree_view, tree_view->priv->search_window, tree_view->priv->search_position_user_data);
8790 gtk_widget_show (tree_view->priv->search_window);
8791 if (tree_view->priv->search_entry_changed_id == 0)
8793 tree_view->priv->search_entry_changed_id =
8794 g_signal_connect (tree_view->priv->search_entry, "changed",
8795 G_CALLBACK (pspp_sheet_view_search_init),
8799 tree_view->priv->typeselect_flush_timeout =
8800 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
8801 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
8804 /* Grab focus will select all the text. We don't want that to happen, so we
8805 * call the parent instance and bypass the selection change. This is probably
8806 * really non-kosher. */
8807 entry_parent_class = g_type_class_peek_parent (GTK_ENTRY_GET_CLASS (tree_view->priv->search_entry));
8808 (entry_parent_class->grab_focus) (tree_view->priv->search_entry);
8810 /* send focus-in event */
8811 send_focus_change (tree_view->priv->search_entry, TRUE);
8813 /* search first matching iter */
8814 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
8820 pspp_sheet_view_start_interactive_search (PsppSheetView *tree_view)
8822 return pspp_sheet_view_real_start_interactive_search (tree_view, TRUE);
8825 /* this function returns the new width of the column being resized given
8826 * the column and x position of the cursor; the x cursor position is passed
8827 * in as a pointer and automagicly corrected if it's beyond min/max limits
8830 pspp_sheet_view_new_column_width (PsppSheetView *tree_view,
8834 PsppSheetViewColumn *column;
8838 /* first translate the x position from gtk_widget_get_window (widget)
8839 * to clist->clist_window
8841 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8842 column = g_list_nth (tree_view->priv->columns, i)->data;
8843 width = rtl ? (column->allocation.x + column->allocation.width - *x) : (*x - column->allocation.x);
8845 /* Clamp down the value */
8846 if (column->min_width == -1)
8847 width = MAX (column->button_request, width);
8849 width = MAX (column->min_width, width);
8850 if (column->max_width != -1)
8851 width = MIN (width, column->max_width);
8853 *x = rtl ? (column->allocation.x + column->allocation.width - width) : (column->allocation.x + width);
8859 /* FIXME this adjust_allocation is a big cut-and-paste from
8860 * GtkCList, needs to be some "official" way to do this
8870 /* The window to which gtk_widget_get_window (widget) is relative */
8871 #define ALLOCATION_WINDOW(widget) \
8872 (!gtk_widget_get_has_window (widget) ? \
8873 gtk_widget_get_window (widget) : \
8874 gdk_window_get_parent (gtk_widget_get_window (widget)))
8877 adjust_allocation_recurse (GtkWidget *widget,
8880 ScrollData *scroll_data = data;
8881 GtkAllocation allocation;
8882 gtk_widget_get_allocation (widget, &allocation);
8883 /* Need to really size allocate instead of just poking
8884 * into widget->allocation if the widget is not realized.
8885 * FIXME someone figure out why this was.
8887 if (!gtk_widget_get_realized (widget))
8889 if (gtk_widget_get_visible (widget))
8891 GdkRectangle tmp_rectangle = allocation;
8892 tmp_rectangle.x += scroll_data->dx;
8893 tmp_rectangle.y += scroll_data->dy;
8895 gtk_widget_size_allocate (widget, &tmp_rectangle);
8900 if (ALLOCATION_WINDOW (widget) == scroll_data->window)
8902 allocation.x += scroll_data->dx;
8903 allocation.y += scroll_data->dy;
8905 if (GTK_IS_CONTAINER (widget))
8906 gtk_container_forall (GTK_CONTAINER (widget),
8907 adjust_allocation_recurse,
8914 adjust_allocation (GtkWidget *widget,
8918 ScrollData scroll_data;
8920 if (gtk_widget_get_realized (widget))
8921 scroll_data.window = ALLOCATION_WINDOW (widget);
8923 scroll_data.window = NULL;
8925 scroll_data.dx = dx;
8926 scroll_data.dy = dy;
8928 adjust_allocation_recurse (widget, &scroll_data);
8932 pspp_sheet_view_column_update_button (PsppSheetViewColumn *tree_column);
8936 pspp_sheet_view_adjustment_changed (GtkAdjustment *adjustment,
8937 PsppSheetView *tree_view)
8939 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
8944 gdk_window_move (tree_view->priv->bin_window,
8945 - gtk_adjustment_get_value (tree_view->priv->hadjustment),
8946 TREE_VIEW_HEADER_HEIGHT (tree_view));
8947 gdk_window_move (tree_view->priv->header_window,
8948 - gtk_adjustment_get_value (tree_view->priv->hadjustment),
8950 dy = tree_view->priv->dy - (int) gtk_adjustment_get_value (tree_view->priv->vadjustment);
8953 update_prelight (tree_view,
8954 tree_view->priv->event_last_x,
8955 tree_view->priv->event_last_y - dy);
8957 if (tree_view->priv->edited_column &&
8958 GTK_IS_WIDGET (tree_view->priv->edited_column->editable_widget))
8962 PsppSheetViewChild *child = NULL;
8964 widget = GTK_WIDGET (tree_view->priv->edited_column->editable_widget);
8965 adjust_allocation (widget, 0, dy);
8967 for (list = tree_view->priv->children; list; list = list->next)
8969 child = (PsppSheetViewChild *)list->data;
8970 if (child->widget == widget)
8978 gdk_window_scroll (tree_view->priv->bin_window, 0, dy);
8980 if (tree_view->priv->dy != (int) gtk_adjustment_get_value (tree_view->priv->vadjustment))
8982 /* update our dy and top_row */
8983 tree_view->priv->dy = (int) gtk_adjustment_get_value (tree_view->priv->vadjustment);
8985 if (!tree_view->priv->in_top_row_to_dy)
8986 pspp_sheet_view_dy_to_top_row (tree_view);
8989 for (list = tree_view->priv->columns; list; list = list->next)
8991 PsppSheetViewColumn *column = list->data;
8992 GtkAllocation *col_allocation = &column->allocation;
8993 GtkAllocation widget_allocation;
8994 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &widget_allocation);
8996 if (span_intersects (col_allocation->x, col_allocation->width,
8997 gtk_adjustment_get_value (tree_view->priv->hadjustment),
8998 widget_allocation.width))
9000 pspp_sheet_view_column_set_need_button (column, TRUE);
9001 if (!column->button)
9002 pspp_sheet_view_column_update_button (column);
9014 * pspp_sheet_view_new:
9016 * Creates a new #PsppSheetView widget.
9018 * Return value: A newly created #PsppSheetView widget.
9021 pspp_sheet_view_new (void)
9023 return g_object_new (PSPP_TYPE_SHEET_VIEW, NULL);
9027 * pspp_sheet_view_new_with_model:
9028 * @model: the model.
9030 * Creates a new #PsppSheetView widget with the model initialized to @model.
9032 * Return value: A newly created #PsppSheetView widget.
9035 pspp_sheet_view_new_with_model (GtkTreeModel *model)
9037 return g_object_new (PSPP_TYPE_SHEET_VIEW, "model", model, NULL);
9044 * pspp_sheet_view_get_model:
9045 * @tree_view: a #PsppSheetView
9047 * Returns the model the #PsppSheetView is based on. Returns %NULL if the
9050 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
9053 pspp_sheet_view_get_model (PsppSheetView *tree_view)
9055 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9057 return tree_view->priv->model;
9061 * pspp_sheet_view_set_model:
9062 * @tree_view: A #GtkTreeNode.
9063 * @model: (allow-none): The model.
9065 * Sets the model for a #PsppSheetView. If the @tree_view already has a model
9066 * set, it will remove it before setting the new model. If @model is %NULL,
9067 * then it will unset the old model.
9070 pspp_sheet_view_set_model (PsppSheetView *tree_view,
9071 GtkTreeModel *model)
9073 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9074 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
9076 if (model == tree_view->priv->model)
9079 if (tree_view->priv->scroll_to_path)
9081 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9082 tree_view->priv->scroll_to_path = NULL;
9085 if (tree_view->priv->model)
9087 GList *tmplist = tree_view->priv->columns;
9089 if (tree_view->priv->selected)
9090 range_tower_set0 (tree_view->priv->selected, 0, ULONG_MAX);
9091 pspp_sheet_view_stop_editing (tree_view, TRUE);
9093 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9094 pspp_sheet_view_row_changed,
9096 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9097 pspp_sheet_view_row_inserted,
9099 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9100 pspp_sheet_view_row_deleted,
9102 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
9103 pspp_sheet_view_rows_reordered,
9106 for (; tmplist; tmplist = tmplist->next)
9107 _pspp_sheet_view_column_unset_model (tmplist->data,
9108 tree_view->priv->model);
9110 tree_view->priv->prelight_node = -1;
9112 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
9113 tree_view->priv->drag_dest_row = NULL;
9114 gtk_tree_row_reference_free (tree_view->priv->cursor);
9115 tree_view->priv->cursor = NULL;
9116 gtk_tree_row_reference_free (tree_view->priv->anchor);
9117 tree_view->priv->anchor = NULL;
9118 gtk_tree_row_reference_free (tree_view->priv->top_row);
9119 tree_view->priv->top_row = NULL;
9120 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9121 tree_view->priv->scroll_to_path = NULL;
9123 tree_view->priv->scroll_to_column = NULL;
9125 g_object_unref (tree_view->priv->model);
9127 tree_view->priv->search_column = -1;
9128 tree_view->priv->fixed_height = -1;
9129 tree_view->priv->dy = tree_view->priv->top_row_dy = 0;
9130 tree_view->priv->last_button_x = -1;
9131 tree_view->priv->last_button_y = -1;
9134 tree_view->priv->model = model;
9136 if (tree_view->priv->model)
9140 if (tree_view->priv->search_column == -1)
9142 for (i = 0; i < gtk_tree_model_get_n_columns (model); i++)
9144 GType type = gtk_tree_model_get_column_type (model, i);
9146 if (g_value_type_transformable (type, G_TYPE_STRING))
9148 tree_view->priv->search_column = i;
9154 g_object_ref (tree_view->priv->model);
9155 g_signal_connect (tree_view->priv->model,
9157 G_CALLBACK (pspp_sheet_view_row_changed),
9159 g_signal_connect (tree_view->priv->model,
9161 G_CALLBACK (pspp_sheet_view_row_inserted),
9163 g_signal_connect (tree_view->priv->model,
9165 G_CALLBACK (pspp_sheet_view_row_deleted),
9167 g_signal_connect (tree_view->priv->model,
9169 G_CALLBACK (pspp_sheet_view_rows_reordered),
9172 tree_view->priv->row_count = gtk_tree_model_iter_n_children (tree_view->priv->model, NULL);
9174 /* FIXME: do I need to do this? pspp_sheet_view_create_buttons (tree_view); */
9175 install_presize_handler (tree_view);
9178 g_object_notify (G_OBJECT (tree_view), "model");
9180 if (tree_view->priv->selection)
9181 _pspp_sheet_selection_emit_changed (tree_view->priv->selection);
9183 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9184 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9188 * pspp_sheet_view_get_selection:
9189 * @tree_view: A #PsppSheetView.
9191 * Gets the #PsppSheetSelection associated with @tree_view.
9193 * Return value: A #PsppSheetSelection object.
9195 PsppSheetSelection *
9196 pspp_sheet_view_get_selection (PsppSheetView *tree_view)
9198 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9200 return tree_view->priv->selection;
9204 * pspp_sheet_view_get_hadjustment:
9205 * @tree_view: A #PsppSheetView
9207 * Gets the #GtkAdjustment currently being used for the horizontal aspect.
9209 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
9213 pspp_sheet_view_get_hadjustment (PsppSheetView *tree_view)
9215 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9217 if (tree_view->priv->hadjustment == NULL)
9218 pspp_sheet_view_set_hadjustment (tree_view, NULL);
9220 return tree_view->priv->hadjustment;
9224 * pspp_sheet_view_set_hadjustment:
9225 * @tree_view: A #PsppSheetView
9226 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
9228 * Sets the #GtkAdjustment for the current horizontal aspect.
9231 pspp_sheet_view_set_hadjustment (PsppSheetView *tree_view,
9232 GtkAdjustment *adjustment)
9234 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9236 pspp_sheet_view_set_adjustments (tree_view,
9238 tree_view->priv->vadjustment);
9240 g_object_notify (G_OBJECT (tree_view), "hadjustment");
9244 * pspp_sheet_view_get_vadjustment:
9245 * @tree_view: A #PsppSheetView
9247 * Gets the #GtkAdjustment currently being used for the vertical aspect.
9249 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
9253 pspp_sheet_view_get_vadjustment (PsppSheetView *tree_view)
9255 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9257 if (tree_view->priv->vadjustment == NULL)
9258 pspp_sheet_view_set_vadjustment (tree_view, NULL);
9260 return tree_view->priv->vadjustment;
9264 * pspp_sheet_view_set_vadjustment:
9265 * @tree_view: A #PsppSheetView
9266 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
9268 * Sets the #GtkAdjustment for the current vertical aspect.
9271 pspp_sheet_view_set_vadjustment (PsppSheetView *tree_view,
9272 GtkAdjustment *adjustment)
9274 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9276 pspp_sheet_view_set_adjustments (tree_view,
9277 tree_view->priv->hadjustment,
9280 g_object_notify (G_OBJECT (tree_view), "vadjustment");
9283 /* Column and header operations */
9286 * pspp_sheet_view_get_headers_visible:
9287 * @tree_view: A #PsppSheetView.
9289 * Returns %TRUE if the headers on the @tree_view are visible.
9291 * Return value: Whether the headers are visible or not.
9294 pspp_sheet_view_get_headers_visible (PsppSheetView *tree_view)
9296 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9298 return PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9302 * pspp_sheet_view_set_headers_visible:
9303 * @tree_view: A #PsppSheetView.
9304 * @headers_visible: %TRUE if the headers are visible
9306 * Sets the visibility state of the headers.
9309 pspp_sheet_view_set_headers_visible (PsppSheetView *tree_view,
9310 gboolean headers_visible)
9314 PsppSheetViewColumn *column;
9315 GtkAllocation allocation;
9317 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9319 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
9321 headers_visible = !! headers_visible;
9323 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE) == headers_visible)
9326 if (headers_visible)
9327 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9329 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9331 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9333 gdk_window_get_position (tree_view->priv->bin_window, &x, &y);
9334 if (headers_visible)
9336 gdk_window_move_resize (tree_view->priv->bin_window, x, y + TREE_VIEW_HEADER_HEIGHT (tree_view),
9337 tree_view->priv->width, allocation.height - + TREE_VIEW_HEADER_HEIGHT (tree_view));
9339 if (gtk_widget_get_mapped (GTK_WIDGET (tree_view)))
9340 pspp_sheet_view_map_buttons (tree_view);
9344 gdk_window_move_resize (tree_view->priv->bin_window, x, y, tree_view->priv->width, tree_view->priv->height);
9346 for (list = tree_view->priv->columns; list; list = list->next)
9348 column = list->data;
9350 gtk_widget_unmap (column->button);
9352 gdk_window_hide (tree_view->priv->header_window);
9356 gtk_adjustment_set_page_size (tree_view->priv->vadjustment, allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view));
9357 gtk_adjustment_set_page_increment (tree_view->priv->vadjustment, (allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view)) / 2);
9358 gtk_adjustment_set_lower (tree_view->priv->vadjustment, 0);
9359 gtk_adjustment_set_upper (tree_view->priv->vadjustment, tree_view->priv->height);
9360 gtk_adjustment_changed (tree_view->priv->vadjustment);
9362 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9364 g_object_notify (G_OBJECT (tree_view), "headers-visible");
9368 * pspp_sheet_view_columns_autosize:
9369 * @tree_view: A #PsppSheetView.
9371 * Resizes all columns to their optimal width. Only works after the
9372 * treeview has been realized.
9375 pspp_sheet_view_columns_autosize (PsppSheetView *tree_view)
9377 gboolean dirty = FALSE;
9379 PsppSheetViewColumn *column;
9381 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9383 for (list = tree_view->priv->columns; list; list = list->next)
9385 column = list->data;
9386 _pspp_sheet_view_column_cell_set_dirty (column);
9391 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9395 * pspp_sheet_view_set_headers_clickable:
9396 * @tree_view: A #PsppSheetView.
9397 * @setting: %TRUE if the columns are clickable.
9399 * Allow the column title buttons to be clicked.
9402 pspp_sheet_view_set_headers_clickable (PsppSheetView *tree_view,
9407 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9409 for (list = tree_view->priv->columns; list; list = list->next)
9410 pspp_sheet_view_column_set_clickable (PSPP_SHEET_VIEW_COLUMN (list->data), setting);
9412 g_object_notify (G_OBJECT (tree_view), "headers-clickable");
9417 * pspp_sheet_view_get_headers_clickable:
9418 * @tree_view: A #PsppSheetView.
9420 * Returns whether all header columns are clickable.
9422 * Return value: %TRUE if all header columns are clickable, otherwise %FALSE
9427 pspp_sheet_view_get_headers_clickable (PsppSheetView *tree_view)
9431 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9433 for (list = tree_view->priv->columns; list; list = list->next)
9434 if (!PSPP_SHEET_VIEW_COLUMN (list->data)->clickable)
9441 * pspp_sheet_view_set_rules_hint
9442 * @tree_view: a #PsppSheetView
9443 * @setting: %TRUE if the tree requires reading across rows
9445 * This function tells GTK+ that the user interface for your
9446 * application requires users to read across tree rows and associate
9447 * cells with one another. By default, GTK+ will then render the tree
9448 * with alternating row colors. Do <emphasis>not</emphasis> use it
9449 * just because you prefer the appearance of the ruled tree; that's a
9450 * question for the theme. Some themes will draw tree rows in
9451 * alternating colors even when rules are turned off, and users who
9452 * prefer that appearance all the time can choose those themes. You
9453 * should call this function only as a <emphasis>semantic</emphasis>
9454 * hint to the theme engine that your tree makes alternating colors
9455 * useful from a functional standpoint (since it has lots of columns,
9460 pspp_sheet_view_set_rules_hint (PsppSheetView *tree_view,
9463 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9465 setting = setting != FALSE;
9467 if (tree_view->priv->has_rules != setting)
9469 tree_view->priv->has_rules = setting;
9470 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
9473 g_object_notify (G_OBJECT (tree_view), "rules-hint");
9477 * pspp_sheet_view_get_rules_hint
9478 * @tree_view: a #PsppSheetView
9480 * Gets the setting set by pspp_sheet_view_set_rules_hint().
9482 * Return value: %TRUE if rules are useful for the user of this tree
9485 pspp_sheet_view_get_rules_hint (PsppSheetView *tree_view)
9487 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9489 return tree_view->priv->has_rules;
9492 /* Public Column functions
9496 * pspp_sheet_view_append_column:
9497 * @tree_view: A #PsppSheetView.
9498 * @column: The #PsppSheetViewColumn to add.
9500 * Appends @column to the list of columns.
9502 * Return value: The number of columns in @tree_view after appending.
9505 pspp_sheet_view_append_column (PsppSheetView *tree_view,
9506 PsppSheetViewColumn *column)
9508 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9509 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9510 g_return_val_if_fail (column->tree_view == NULL, -1);
9512 return pspp_sheet_view_insert_column (tree_view, column, -1);
9517 * pspp_sheet_view_remove_column:
9518 * @tree_view: A #PsppSheetView.
9519 * @column: The #PsppSheetViewColumn to remove.
9521 * Removes @column from @tree_view.
9523 * Return value: The number of columns in @tree_view after removing.
9526 pspp_sheet_view_remove_column (PsppSheetView *tree_view,
9527 PsppSheetViewColumn *column)
9529 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9530 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9531 g_return_val_if_fail (column->tree_view == GTK_WIDGET (tree_view), -1);
9533 if (tree_view->priv->focus_column == column)
9534 tree_view->priv->focus_column = NULL;
9536 if (tree_view->priv->edited_column == column)
9538 pspp_sheet_view_stop_editing (tree_view, TRUE);
9540 /* no need to, but just to be sure ... */
9541 tree_view->priv->edited_column = NULL;
9544 _pspp_sheet_view_column_unset_tree_view (column);
9546 tree_view->priv->columns = g_list_remove (tree_view->priv->columns, column);
9547 tree_view->priv->n_columns--;
9549 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9553 _pspp_sheet_view_column_unrealize_button (column);
9554 for (list = tree_view->priv->columns; list; list = list->next)
9556 PsppSheetViewColumn *tmp_column;
9558 tmp_column = PSPP_SHEET_VIEW_COLUMN (list->data);
9559 if (tmp_column->visible)
9560 _pspp_sheet_view_column_cell_set_dirty (tmp_column);
9563 if (tree_view->priv->n_columns == 0 &&
9564 pspp_sheet_view_get_headers_visible (tree_view) &&
9565 tree_view->priv->header_window)
9566 gdk_window_hide (tree_view->priv->header_window);
9568 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9571 g_object_unref (column);
9572 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9574 return tree_view->priv->n_columns;
9578 * pspp_sheet_view_insert_column:
9579 * @tree_view: A #PsppSheetView.
9580 * @column: The #PsppSheetViewColumn to be inserted.
9581 * @position: The position to insert @column in.
9583 * This inserts the @column into the @tree_view at @position. If @position is
9584 * -1, then the column is inserted at the end.
9586 * Return value: The number of columns in @tree_view after insertion.
9589 pspp_sheet_view_insert_column (PsppSheetView *tree_view,
9590 PsppSheetViewColumn *column,
9593 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9594 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9595 g_return_val_if_fail (column->tree_view == NULL, -1);
9597 g_object_ref_sink (column);
9599 if (tree_view->priv->n_columns == 0 &&
9600 gtk_widget_get_realized (GTK_WIDGET (tree_view)) &&
9601 pspp_sheet_view_get_headers_visible (tree_view))
9603 gdk_window_show (tree_view->priv->header_window);
9606 tree_view->priv->columns = g_list_insert (tree_view->priv->columns,
9608 tree_view->priv->n_columns++;
9610 _pspp_sheet_view_column_set_tree_view (column, tree_view);
9612 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9616 _pspp_sheet_view_column_realize_button (column);
9618 for (list = tree_view->priv->columns; list; list = list->next)
9620 column = PSPP_SHEET_VIEW_COLUMN (list->data);
9621 if (column->visible)
9622 _pspp_sheet_view_column_cell_set_dirty (column);
9624 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9627 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9629 return tree_view->priv->n_columns;
9633 * pspp_sheet_view_insert_column_with_attributes:
9634 * @tree_view: A #PsppSheetView
9635 * @position: The position to insert the new column in.
9636 * @title: The title to set the header to.
9637 * @cell: The #GtkCellRenderer.
9638 * @Varargs: A %NULL-terminated list of attributes.
9640 * Creates a new #PsppSheetViewColumn and inserts it into the @tree_view at
9641 * @position. If @position is -1, then the newly created column is inserted at
9642 * the end. The column is initialized with the attributes given.
9644 * Return value: The number of columns in @tree_view after insertion.
9647 pspp_sheet_view_insert_column_with_attributes (PsppSheetView *tree_view,
9650 GtkCellRenderer *cell,
9653 PsppSheetViewColumn *column;
9658 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9660 column = pspp_sheet_view_column_new ();
9661 pspp_sheet_view_column_set_title (column, title);
9662 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9664 va_start (args, cell);
9666 attribute = va_arg (args, gchar *);
9668 while (attribute != NULL)
9670 column_id = va_arg (args, gint);
9671 pspp_sheet_view_column_add_attribute (column, cell, attribute, column_id);
9672 attribute = va_arg (args, gchar *);
9677 pspp_sheet_view_insert_column (tree_view, column, position);
9679 return tree_view->priv->n_columns;
9683 * pspp_sheet_view_insert_column_with_data_func:
9684 * @tree_view: a #PsppSheetView
9685 * @position: Position to insert, -1 for append
9686 * @title: column title
9687 * @cell: cell renderer for column
9688 * @func: function to set attributes of cell renderer
9689 * @data: data for @func
9690 * @dnotify: destroy notifier for @data
9692 * Convenience function that inserts a new column into the #PsppSheetView
9693 * with the given cell renderer and a #GtkCellDataFunc to set cell renderer
9694 * attributes (normally using data from the model). See also
9695 * pspp_sheet_view_column_set_cell_data_func(), pspp_sheet_view_column_pack_start().
9697 * Return value: number of columns in the tree view post-insert
9700 pspp_sheet_view_insert_column_with_data_func (PsppSheetView *tree_view,
9703 GtkCellRenderer *cell,
9704 PsppSheetCellDataFunc func,
9706 GDestroyNotify dnotify)
9708 PsppSheetViewColumn *column;
9710 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9712 column = pspp_sheet_view_column_new ();
9713 pspp_sheet_view_column_set_title (column, title);
9714 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9715 pspp_sheet_view_column_set_cell_data_func (column, cell, func, data, dnotify);
9717 pspp_sheet_view_insert_column (tree_view, column, position);
9719 return tree_view->priv->n_columns;
9723 * pspp_sheet_view_get_column:
9724 * @tree_view: A #PsppSheetView.
9725 * @n: The position of the column, counting from 0.
9727 * Gets the #PsppSheetViewColumn at the given position in the #tree_view.
9729 * Return value: The #PsppSheetViewColumn, or %NULL if the position is outside the
9732 PsppSheetViewColumn *
9733 pspp_sheet_view_get_column (PsppSheetView *tree_view,
9736 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9738 if (n < 0 || n >= tree_view->priv->n_columns)
9741 if (tree_view->priv->columns == NULL)
9744 return PSPP_SHEET_VIEW_COLUMN (g_list_nth (tree_view->priv->columns, n)->data);
9748 * pspp_sheet_view_get_columns:
9749 * @tree_view: A #PsppSheetView
9751 * Returns a #GList of all the #PsppSheetViewColumn s currently in @tree_view.
9752 * The returned list must be freed with g_list_free ().
9754 * Return value: (element-type PsppSheetViewColumn) (transfer container): A list of #PsppSheetViewColumn s
9757 pspp_sheet_view_get_columns (PsppSheetView *tree_view)
9759 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9761 return g_list_copy (tree_view->priv->columns);
9765 * pspp_sheet_view_move_column_after:
9766 * @tree_view: A #PsppSheetView
9767 * @column: The #PsppSheetViewColumn to be moved.
9768 * @base_column: (allow-none): The #PsppSheetViewColumn to be moved relative to, or %NULL.
9770 * Moves @column to be after to @base_column. If @base_column is %NULL, then
9771 * @column is placed in the first position.
9774 pspp_sheet_view_move_column_after (PsppSheetView *tree_view,
9775 PsppSheetViewColumn *column,
9776 PsppSheetViewColumn *base_column)
9778 GList *column_list_el, *base_el = NULL;
9780 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9782 column_list_el = g_list_find (tree_view->priv->columns, column);
9783 g_return_if_fail (column_list_el != NULL);
9787 base_el = g_list_find (tree_view->priv->columns, base_column);
9788 g_return_if_fail (base_el != NULL);
9791 if (column_list_el->prev == base_el)
9794 tree_view->priv->columns = g_list_remove_link (tree_view->priv->columns, column_list_el);
9795 if (base_el == NULL)
9797 column_list_el->prev = NULL;
9798 column_list_el->next = tree_view->priv->columns;
9799 if (column_list_el->next)
9800 column_list_el->next->prev = column_list_el;
9801 tree_view->priv->columns = column_list_el;
9805 column_list_el->prev = base_el;
9806 column_list_el->next = base_el->next;
9807 if (column_list_el->next)
9808 column_list_el->next->prev = column_list_el;
9809 base_el->next = column_list_el;
9812 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9814 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9815 pspp_sheet_view_size_allocate_columns (GTK_WIDGET (tree_view), NULL);
9818 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9822 * pspp_sheet_view_set_column_drag_function:
9823 * @tree_view: A #PsppSheetView.
9824 * @func: (allow-none): A function to determine which columns are reorderable, or %NULL.
9825 * @user_data: (allow-none): User data to be passed to @func, or %NULL
9826 * @destroy: (allow-none): Destroy notifier for @user_data, or %NULL
9828 * Sets a user function for determining where a column may be dropped when
9829 * dragged. This function is called on every column pair in turn at the
9830 * beginning of a column drag to determine where a drop can take place. The
9831 * arguments passed to @func are: the @tree_view, the #PsppSheetViewColumn being
9832 * dragged, the two #PsppSheetViewColumn s determining the drop spot, and
9833 * @user_data. If either of the #PsppSheetViewColumn arguments for the drop spot
9834 * are %NULL, then they indicate an edge. If @func is set to be %NULL, then
9835 * @tree_view reverts to the default behavior of allowing all columns to be
9836 * dropped everywhere.
9839 pspp_sheet_view_set_column_drag_function (PsppSheetView *tree_view,
9840 PsppSheetViewColumnDropFunc func,
9842 GDestroyNotify destroy)
9844 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9846 if (tree_view->priv->column_drop_func_data_destroy)
9847 tree_view->priv->column_drop_func_data_destroy (tree_view->priv->column_drop_func_data);
9849 tree_view->priv->column_drop_func = func;
9850 tree_view->priv->column_drop_func_data = user_data;
9851 tree_view->priv->column_drop_func_data_destroy = destroy;
9855 * pspp_sheet_view_scroll_to_point:
9856 * @tree_view: a #PsppSheetView
9857 * @tree_x: X coordinate of new top-left pixel of visible area, or -1
9858 * @tree_y: Y coordinate of new top-left pixel of visible area, or -1
9860 * Scrolls the tree view such that the top-left corner of the visible
9861 * area is @tree_x, @tree_y, where @tree_x and @tree_y are specified
9862 * in tree coordinates. The @tree_view must be realized before
9863 * this function is called. If it isn't, you probably want to be
9864 * using pspp_sheet_view_scroll_to_cell().
9866 * If either @tree_x or @tree_y are -1, then that direction isn't scrolled.
9869 pspp_sheet_view_scroll_to_point (PsppSheetView *tree_view,
9873 GtkAdjustment *hadj;
9874 GtkAdjustment *vadj;
9876 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9877 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
9879 hadj = tree_view->priv->hadjustment;
9880 vadj = tree_view->priv->vadjustment;
9883 gtk_adjustment_set_value (hadj, CLAMP (tree_x, gtk_adjustment_get_lower (hadj), gtk_adjustment_get_upper (hadj) - gtk_adjustment_get_page_size (hadj)));
9885 gtk_adjustment_set_value (vadj, CLAMP (tree_y, gtk_adjustment_get_lower (vadj), gtk_adjustment_get_upper (vadj) - gtk_adjustment_get_page_size (vadj)));
9889 * pspp_sheet_view_scroll_to_cell:
9890 * @tree_view: A #PsppSheetView.
9891 * @path: (allow-none): The path of the row to move to, or %NULL.
9892 * @column: (allow-none): The #PsppSheetViewColumn to move horizontally to, or %NULL.
9893 * @use_align: whether to use alignment arguments, or %FALSE.
9894 * @row_align: The vertical alignment of the row specified by @path.
9895 * @col_align: The horizontal alignment of the column specified by @column.
9897 * Moves the alignments of @tree_view to the position specified by @column and
9898 * @path. If @column is %NULL, then no horizontal scrolling occurs. Likewise,
9899 * if @path is %NULL no vertical scrolling occurs. At a minimum, one of @column
9900 * or @path need to be non-%NULL. @row_align determines where the row is
9901 * placed, and @col_align determines where @column is placed. Both are expected
9902 * to be between 0.0 and 1.0. 0.0 means left/top alignment, 1.0 means
9903 * right/bottom alignment, 0.5 means center.
9905 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
9906 * tree does the minimum amount of work to scroll the cell onto the screen.
9907 * This means that the cell will be scrolled to the edge closest to its current
9908 * position. If the cell is currently visible on the screen, nothing is done.
9910 * This function only works if the model is set, and @path is a valid row on the
9911 * model. If the model changes before the @tree_view is realized, the centered
9912 * path will be modified to reflect this change.
9915 pspp_sheet_view_scroll_to_cell (PsppSheetView *tree_view,
9917 PsppSheetViewColumn *column,
9922 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9923 g_return_if_fail (tree_view->priv->model != NULL);
9924 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
9925 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
9926 g_return_if_fail (path != NULL || column != NULL);
9929 g_print ("pspp_sheet_view_scroll_to_cell:\npath: %s\ncolumn: %s\nuse_align: %d\nrow_align: %f\ncol_align: %f\n",
9930 gtk_tree_path_to_string (path), column?"non-null":"null", use_align, row_align, col_align);
9932 row_align = CLAMP (row_align, 0.0, 1.0);
9933 col_align = CLAMP (col_align, 0.0, 1.0);
9936 /* Note: Despite the benefits that come from having one code path for the
9937 * scrolling code, we short-circuit validate_visible_area's immplementation as
9938 * it is much slower than just going to the point.
9940 if (!gtk_widget_get_visible (GTK_WIDGET (tree_view)) ||
9941 !gtk_widget_get_realized (GTK_WIDGET (tree_view))
9942 /* XXX || GTK_WIDGET_ALLOC_NEEDED (tree_view) */)
9944 if (tree_view->priv->scroll_to_path)
9945 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9947 tree_view->priv->scroll_to_path = NULL;
9948 tree_view->priv->scroll_to_column = NULL;
9951 tree_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
9953 tree_view->priv->scroll_to_column = column;
9954 tree_view->priv->scroll_to_use_align = use_align;
9955 tree_view->priv->scroll_to_row_align = row_align;
9956 tree_view->priv->scroll_to_col_align = col_align;
9958 install_presize_handler (tree_view);
9962 GdkRectangle cell_rect;
9963 GdkRectangle vis_rect;
9964 gint dest_x, dest_y;
9966 pspp_sheet_view_get_background_area (tree_view, path, column, &cell_rect);
9967 pspp_sheet_view_get_visible_rect (tree_view, &vis_rect);
9969 cell_rect.y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, cell_rect.y);
9971 dest_x = vis_rect.x;
9972 dest_y = vis_rect.y;
9978 dest_x = cell_rect.x - ((vis_rect.width - cell_rect.width) * col_align);
9982 if (cell_rect.x < vis_rect.x)
9983 dest_x = cell_rect.x;
9984 if (cell_rect.x + cell_rect.width > vis_rect.x + vis_rect.width)
9985 dest_x = cell_rect.x + cell_rect.width - vis_rect.width;
9993 dest_y = cell_rect.y - ((vis_rect.height - cell_rect.height) * row_align);
9994 dest_y = MAX (dest_y, 0);
9998 if (cell_rect.y < vis_rect.y)
9999 dest_y = cell_rect.y;
10000 if (cell_rect.y + cell_rect.height > vis_rect.y + vis_rect.height)
10001 dest_y = cell_rect.y + cell_rect.height - vis_rect.height;
10005 pspp_sheet_view_scroll_to_point (tree_view, dest_x, dest_y);
10010 * pspp_sheet_view_row_activated:
10011 * @tree_view: A #PsppSheetView
10012 * @path: The #GtkTreePath to be activated.
10013 * @column: The #PsppSheetViewColumn to be activated.
10015 * Activates the cell determined by @path and @column.
10018 pspp_sheet_view_row_activated (PsppSheetView *tree_view,
10020 PsppSheetViewColumn *column)
10022 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10024 g_signal_emit (tree_view, tree_view_signals[ROW_ACTIVATED], 0, path, column);
10029 * pspp_sheet_view_get_reorderable:
10030 * @tree_view: a #PsppSheetView
10032 * Retrieves whether the user can reorder the tree via drag-and-drop. See
10033 * pspp_sheet_view_set_reorderable().
10035 * Return value: %TRUE if the tree can be reordered.
10038 pspp_sheet_view_get_reorderable (PsppSheetView *tree_view)
10040 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
10042 return tree_view->priv->reorderable;
10046 * pspp_sheet_view_set_reorderable:
10047 * @tree_view: A #PsppSheetView.
10048 * @reorderable: %TRUE, if the tree can be reordered.
10050 * This function is a convenience function to allow you to reorder
10051 * models that support the #GtkDragSourceIface and the
10052 * #GtkDragDestIface. Both #GtkTreeStore and #GtkListStore support
10053 * these. If @reorderable is %TRUE, then the user can reorder the
10054 * model by dragging and dropping rows. The developer can listen to
10055 * these changes by connecting to the model's row_inserted and
10056 * row_deleted signals. The reordering is implemented by setting up
10057 * the tree view as a drag source and destination. Therefore, drag and
10058 * drop can not be used in a reorderable view for any other purpose.
10060 * This function does not give you any degree of control over the order -- any
10061 * reordering is allowed. If more control is needed, you should probably
10062 * handle drag and drop manually.
10065 pspp_sheet_view_set_reorderable (PsppSheetView *tree_view,
10066 gboolean reorderable)
10068 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10070 reorderable = reorderable != FALSE;
10072 if (tree_view->priv->reorderable == reorderable)
10077 const GtkTargetEntry row_targets[] = {
10078 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
10081 pspp_sheet_view_enable_model_drag_source (tree_view,
10084 G_N_ELEMENTS (row_targets),
10086 pspp_sheet_view_enable_model_drag_dest (tree_view,
10088 G_N_ELEMENTS (row_targets),
10093 pspp_sheet_view_unset_rows_drag_source (tree_view);
10094 pspp_sheet_view_unset_rows_drag_dest (tree_view);
10097 tree_view->priv->reorderable = reorderable;
10099 g_object_notify (G_OBJECT (tree_view), "reorderable");
10102 /* If CLEAR_AND_SELECT is true, then the row will be selected and, unless Shift
10103 is pressed, other rows will be unselected.
10105 If CLAMP_NODE is true, then the sheetview will scroll to make the row
10108 pspp_sheet_view_real_set_cursor (PsppSheetView *tree_view,
10110 gboolean clear_and_select,
10111 gboolean clamp_node,
10112 PsppSheetSelectMode mode)
10116 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
10118 GtkTreePath *cursor_path;
10119 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
10120 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
10121 gtk_tree_path_free (cursor_path);
10124 gtk_tree_row_reference_free (tree_view->priv->cursor);
10125 tree_view->priv->cursor = NULL;
10127 _pspp_sheet_view_find_node (tree_view, path, &node);
10128 tree_view->priv->cursor =
10129 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
10130 tree_view->priv->model,
10133 if (tree_view->priv->row_count > 0)
10137 if (clear_and_select && !(mode & PSPP_SHEET_SELECT_MODE_TOGGLE))
10138 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
10142 /* We have to re-find tree and node here again, somebody might have
10143 * cleared the node or the whole tree in the PsppSheetSelection::changed
10144 * callback. If the nodes differ we bail out here.
10146 _pspp_sheet_view_find_node (tree_view, path, &new_node);
10148 if (node != new_node)
10153 pspp_sheet_view_clamp_node_visible (tree_view, node);
10154 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
10158 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
10162 * pspp_sheet_view_get_cursor:
10163 * @tree_view: A #PsppSheetView
10164 * @path: (allow-none): A pointer to be filled with the current cursor path, or %NULL
10165 * @focus_column: (allow-none): A pointer to be filled with the current focus column, or %NULL
10167 * Fills in @path and @focus_column with the current path and focus column. If
10168 * the cursor isn't currently set, then *@path will be %NULL. If no column
10169 * currently has focus, then *@focus_column will be %NULL.
10171 * The returned #GtkTreePath must be freed with gtk_tree_path_free() when
10172 * you are done with it.
10175 pspp_sheet_view_get_cursor (PsppSheetView *tree_view,
10176 GtkTreePath **path,
10177 PsppSheetViewColumn **focus_column)
10179 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10183 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
10184 *path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
10191 *focus_column = tree_view->priv->focus_column;
10196 * pspp_sheet_view_set_cursor:
10197 * @tree_view: A #PsppSheetView
10198 * @path: A #GtkTreePath
10199 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
10200 * @start_editing: %TRUE if the specified cell should start being edited.
10202 * Sets the current keyboard focus to be at @path, and selects it. This is
10203 * useful when you want to focus the user's attention on a particular row. If
10204 * @focus_column is not %NULL, then focus is given to the column specified by
10205 * it. Additionally, if @focus_column is specified, and @start_editing is
10206 * %TRUE, then editing should be started in the specified cell.
10207 * This function is often followed by @gtk_widget_grab_focus (@tree_view)
10208 * in order to give keyboard focus to the widget. Please note that editing
10209 * can only happen when the widget is realized.
10211 * If @path is invalid for @model, the current cursor (if any) will be unset
10212 * and the function will return without failing.
10215 pspp_sheet_view_set_cursor (PsppSheetView *tree_view,
10217 PsppSheetViewColumn *focus_column,
10218 gboolean start_editing)
10220 pspp_sheet_view_set_cursor_on_cell (tree_view, path, focus_column,
10221 NULL, start_editing);
10225 * pspp_sheet_view_set_cursor_on_cell:
10226 * @tree_view: A #PsppSheetView
10227 * @path: A #GtkTreePath
10228 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
10229 * @focus_cell: (allow-none): A #GtkCellRenderer, or %NULL
10230 * @start_editing: %TRUE if the specified cell should start being edited.
10232 * Sets the current keyboard focus to be at @path, and selects it. This is
10233 * useful when you want to focus the user's attention on a particular row. If
10234 * @focus_column is not %NULL, then focus is given to the column specified by
10235 * it. If @focus_column and @focus_cell are not %NULL, and @focus_column
10236 * contains 2 or more editable or activatable cells, then focus is given to
10237 * the cell specified by @focus_cell. Additionally, if @focus_column is
10238 * specified, and @start_editing is %TRUE, then editing should be started in
10239 * the specified cell. This function is often followed by
10240 * @gtk_widget_grab_focus (@tree_view) in order to give keyboard focus to the
10241 * widget. Please note that editing can only happen when the widget is
10244 * If @path is invalid for @model, the current cursor (if any) will be unset
10245 * and the function will return without failing.
10250 pspp_sheet_view_set_cursor_on_cell (PsppSheetView *tree_view,
10252 PsppSheetViewColumn *focus_column,
10253 GtkCellRenderer *focus_cell,
10254 gboolean start_editing)
10256 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10257 g_return_if_fail (path != NULL);
10258 g_return_if_fail (focus_column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (focus_column));
10260 if (!tree_view->priv->model)
10265 g_return_if_fail (focus_column);
10266 g_return_if_fail (GTK_IS_CELL_RENDERER (focus_cell));
10269 /* cancel the current editing, if it exists */
10270 if (tree_view->priv->edited_column &&
10271 tree_view->priv->edited_column->editable_widget)
10272 pspp_sheet_view_stop_editing (tree_view, TRUE);
10274 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE, 0);
10276 if (focus_column && focus_column->visible)
10279 gboolean column_in_tree = FALSE;
10281 for (list = tree_view->priv->columns; list; list = list->next)
10282 if (list->data == focus_column)
10284 column_in_tree = TRUE;
10287 g_return_if_fail (column_in_tree);
10288 tree_view->priv->focus_column = focus_column;
10290 pspp_sheet_view_column_focus_cell (focus_column, focus_cell);
10292 pspp_sheet_view_start_editing (tree_view, path);
10294 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
10295 pspp_sheet_selection_select_column (tree_view->priv->selection, focus_column);
10301 * pspp_sheet_view_get_bin_window:
10302 * @tree_view: A #PsppSheetView
10304 * Returns the window that @tree_view renders to. This is used primarily to
10305 * compare to <literal>event->window</literal> to confirm that the event on
10306 * @tree_view is on the right window.
10308 * Return value: A #GdkWindow, or %NULL when @tree_view hasn't been realized yet
10311 pspp_sheet_view_get_bin_window (PsppSheetView *tree_view)
10313 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
10315 return tree_view->priv->bin_window;
10319 * pspp_sheet_view_get_path_at_pos:
10320 * @tree_view: A #PsppSheetView.
10321 * @x: The x position to be identified (relative to bin_window).
10322 * @y: The y position to be identified (relative to bin_window).
10323 * @path: (out) (allow-none): A pointer to a #GtkTreePath pointer to be filled in, or %NULL
10324 * @column: (out) (allow-none): A pointer to a #PsppSheetViewColumn pointer to be filled in, or %NULL
10325 * @cell_x: (out) (allow-none): A pointer where the X coordinate relative to the cell can be placed, or %NULL
10326 * @cell_y: (out) (allow-none): A pointer where the Y coordinate relative to the cell can be placed, or %NULL
10328 * Finds the path at the point (@x, @y), relative to bin_window coordinates
10329 * (please see pspp_sheet_view_get_bin_window()).
10330 * That is, @x and @y are relative to an events coordinates. @x and @y must
10331 * come from an event on the @tree_view only where <literal>event->window ==
10332 * pspp_sheet_view_get_bin_window (<!-- -->)</literal>. It is primarily for
10333 * things like popup menus. If @path is non-%NULL, then it will be filled
10334 * with the #GtkTreePath at that point. This path should be freed with
10335 * gtk_tree_path_free(). If @column is non-%NULL, then it will be filled
10336 * with the column at that point. @cell_x and @cell_y return the coordinates
10337 * relative to the cell background (i.e. the @background_area passed to
10338 * gtk_cell_renderer_render()). This function is only meaningful if
10339 * @tree_view is realized. Therefore this function will always return %FALSE
10340 * if @tree_view is not realized or does not have a model.
10342 * For converting widget coordinates (eg. the ones you get from
10343 * GtkWidget::query-tooltip), please see
10344 * pspp_sheet_view_convert_widget_to_bin_window_coords().
10346 * Return value: %TRUE if a row exists at that coordinate.
10349 pspp_sheet_view_get_path_at_pos (PsppSheetView *tree_view,
10352 GtkTreePath **path,
10353 PsppSheetViewColumn **column,
10360 g_return_val_if_fail (tree_view != NULL, FALSE);
10367 if (tree_view->priv->bin_window == NULL)
10370 if (tree_view->priv->row_count == 0)
10373 if (x > gtk_adjustment_get_upper (tree_view->priv->hadjustment))
10376 if (x < 0 || y < 0)
10379 if (column || cell_x)
10381 PsppSheetViewColumn *tmp_column;
10382 PsppSheetViewColumn *last_column = NULL;
10384 gint remaining_x = x;
10385 gboolean found = FALSE;
10388 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
10389 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
10391 list = (rtl ? list->prev : list->next))
10393 tmp_column = list->data;
10395 if (tmp_column->visible == FALSE)
10398 last_column = tmp_column;
10399 if (remaining_x <= tmp_column->width)
10404 *column = tmp_column;
10407 *cell_x = remaining_x;
10411 remaining_x -= tmp_column->width;
10414 /* If found is FALSE and there is a last_column, then it the remainder
10415 * space is in that area
10422 *column = last_column;
10425 *cell_x = last_column->width + remaining_x;
10434 y_offset = pspp_sheet_view_find_offset (tree_view,
10435 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, y),
10442 *cell_y = y_offset;
10445 *path = _pspp_sheet_view_find_path (tree_view, node);
10450 /* Computes 'cell_area' from 'background_area', which must be the background
10451 area for a cell. Set 'subtract_focus_rect' to TRUE to compute the cell area
10452 as passed to a GtkCellRenderer's "render" function, or to FALSE to compute
10453 the cell area as passed to _pspp_sheet_view_column_cell_render().
10455 'column' is required to properly adjust 'cell_area->x' and
10456 'cell_area->width'. It may be set to NULL if these values are not of
10457 interest. In this case 'cell_area->x' and 'cell_area->width' will be
10460 pspp_sheet_view_adjust_cell_area (PsppSheetView *tree_view,
10461 PsppSheetViewColumn *column,
10462 const GdkRectangle *background_area,
10463 gboolean subtract_focus_rect,
10464 GdkRectangle *cell_area)
10466 gint vertical_separator;
10467 gint horizontal_separator;
10469 *cell_area = *background_area;
10471 gtk_widget_style_get (GTK_WIDGET (tree_view),
10472 "vertical-separator", &vertical_separator,
10473 "horizontal-separator", &horizontal_separator,
10475 cell_area->x += horizontal_separator / 2;
10476 cell_area->y += vertical_separator / 2;
10477 cell_area->width -= horizontal_separator;
10478 cell_area->height -= vertical_separator;
10480 if (subtract_focus_rect)
10482 int focus_line_width;
10484 gtk_widget_style_get (GTK_WIDGET (tree_view),
10485 "focus-line-width", &focus_line_width,
10487 cell_area->x += focus_line_width;
10488 cell_area->y += focus_line_width;
10489 cell_area->width -= 2 * focus_line_width;
10490 cell_area->height -= 2 * focus_line_width;
10493 if (tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_NONE)
10495 gint grid_line_width;
10496 gtk_widget_style_get (GTK_WIDGET (tree_view),
10497 "grid-line-width", &grid_line_width,
10500 if ((tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
10501 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10504 PsppSheetViewColumn *first_column, *last_column;
10507 /* Find the last visible column. */
10508 last_column = NULL;
10509 for (list = g_list_last (tree_view->priv->columns);
10513 PsppSheetViewColumn *c = list->data;
10521 /* Find the first visible column. */
10522 first_column = NULL;
10523 for (list = g_list_first (tree_view->priv->columns);
10527 PsppSheetViewColumn *c = list->data;
10535 if (column == first_column)
10537 cell_area->width -= grid_line_width / 2;
10539 else if (column == last_column)
10541 cell_area->x += grid_line_width / 2;
10542 cell_area->width -= grid_line_width / 2;
10546 cell_area->x += grid_line_width / 2;
10547 cell_area->width -= grid_line_width;
10551 if (tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
10552 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10554 cell_area->y += grid_line_width / 2;
10555 cell_area->height -= grid_line_width;
10559 if (column == NULL)
10562 cell_area->width = 0;
10567 * pspp_sheet_view_get_cell_area:
10568 * @tree_view: a #PsppSheetView
10569 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10570 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordinates
10571 * @rect: rectangle to fill with cell rect
10573 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10574 * row specified by @path and the column specified by @column. If @path is
10575 * %NULL, or points to a path not currently displayed, the @y and @height fields
10576 * of the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10577 * fields will be filled with 0. The sum of all cell rects does not cover the
10578 * entire tree; there are extra pixels in between rows, for example. The
10579 * returned rectangle is equivalent to the @cell_area passed to
10580 * gtk_cell_renderer_render(). This function is only valid if @tree_view is
10584 pspp_sheet_view_get_cell_area (PsppSheetView *tree_view,
10586 PsppSheetViewColumn *column,
10587 GdkRectangle *rect)
10589 GdkRectangle background_area;
10591 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10592 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10593 g_return_if_fail (rect != NULL);
10594 g_return_if_fail (!column || column->tree_view == (GtkWidget *) tree_view);
10595 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
10597 pspp_sheet_view_get_background_area (tree_view, path, column,
10599 pspp_sheet_view_adjust_cell_area (tree_view, column, &background_area,
10604 * pspp_sheet_view_get_background_area:
10605 * @tree_view: a #PsppSheetView
10606 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10607 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordiantes
10608 * @rect: rectangle to fill with cell background rect
10610 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10611 * row specified by @path and the column specified by @column. If @path is
10612 * %NULL, or points to a node not found in the tree, the @y and @height fields of
10613 * the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10614 * fields will be filled with 0. The returned rectangle is equivalent to the
10615 * @background_area passed to gtk_cell_renderer_render(). These background
10616 * areas tile to cover the entire bin window. Contrast with the @cell_area,
10617 * returned by pspp_sheet_view_get_cell_area(), which returns only the cell
10618 * itself, excluding surrounding borders.
10622 pspp_sheet_view_get_background_area (PsppSheetView *tree_view,
10624 PsppSheetViewColumn *column,
10625 GdkRectangle *rect)
10629 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10630 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10631 g_return_if_fail (rect != NULL);
10640 /* Get vertical coords */
10642 _pspp_sheet_view_find_node (tree_view, path, &node);
10646 rect->y = BACKGROUND_FIRST_PIXEL (tree_view, node);
10648 rect->height = ROW_HEIGHT (tree_view);
10655 pspp_sheet_view_get_background_xrange (tree_view, column, &rect->x, &x2);
10656 rect->width = x2 - rect->x;
10661 * pspp_sheet_view_get_visible_rect:
10662 * @tree_view: a #PsppSheetView
10663 * @visible_rect: rectangle to fill
10665 * Fills @visible_rect with the currently-visible region of the
10666 * buffer, in tree coordinates. Convert to bin_window coordinates with
10667 * pspp_sheet_view_convert_tree_to_bin_window_coords().
10668 * Tree coordinates start at 0,0 for row 0 of the tree, and cover the entire
10669 * scrollable area of the tree.
10672 pspp_sheet_view_get_visible_rect (PsppSheetView *tree_view,
10673 GdkRectangle *visible_rect)
10677 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10679 widget = GTK_WIDGET (tree_view);
10683 GtkAllocation allocation;
10684 gtk_widget_get_allocation (widget, &allocation);
10685 visible_rect->x = gtk_adjustment_get_value (tree_view->priv->hadjustment);
10686 visible_rect->y = gtk_adjustment_get_value (tree_view->priv->vadjustment);
10687 visible_rect->width = allocation.width;
10688 visible_rect->height = allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
10693 * pspp_sheet_view_widget_to_tree_coords:
10694 * @tree_view: a #PsppSheetView
10695 * @wx: X coordinate relative to bin_window
10696 * @wy: Y coordinate relative to bin_window
10697 * @tx: return location for tree X coordinate
10698 * @ty: return location for tree Y coordinate
10700 * Converts bin_window coordinates to coordinates for the
10701 * tree (the full scrollable area of the tree).
10703 * Deprecated: 2.12: Due to historial reasons the name of this function is
10704 * incorrect. For converting coordinates relative to the widget to
10705 * bin_window coordinates, please see
10706 * pspp_sheet_view_convert_widget_to_bin_window_coords().
10710 pspp_sheet_view_widget_to_tree_coords (PsppSheetView *tree_view,
10716 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10719 *tx = wx + gtk_adjustment_get_value (tree_view->priv->hadjustment);
10721 *ty = wy + tree_view->priv->dy;
10725 * pspp_sheet_view_tree_to_widget_coords:
10726 * @tree_view: a #PsppSheetView
10727 * @tx: tree X coordinate
10728 * @ty: tree Y coordinate
10729 * @wx: return location for X coordinate relative to bin_window
10730 * @wy: return location for Y coordinate relative to bin_window
10732 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10733 * to bin_window coordinates.
10735 * Deprecated: 2.12: Due to historial reasons the name of this function is
10736 * incorrect. For converting bin_window coordinates to coordinates relative
10737 * to bin_window, please see
10738 * pspp_sheet_view_convert_bin_window_to_widget_coords().
10742 pspp_sheet_view_tree_to_widget_coords (PsppSheetView *tree_view,
10748 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10751 *wx = tx - gtk_adjustment_get_value (tree_view->priv->hadjustment);
10753 *wy = ty - tree_view->priv->dy;
10758 * pspp_sheet_view_convert_widget_to_tree_coords:
10759 * @tree_view: a #PsppSheetView
10760 * @wx: X coordinate relative to the widget
10761 * @wy: Y coordinate relative to the widget
10762 * @tx: return location for tree X coordinate
10763 * @ty: return location for tree Y coordinate
10765 * Converts widget coordinates to coordinates for the
10766 * tree (the full scrollable area of the tree).
10771 pspp_sheet_view_convert_widget_to_tree_coords (PsppSheetView *tree_view,
10779 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10781 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view,
10784 pspp_sheet_view_convert_bin_window_to_tree_coords (tree_view,
10790 * pspp_sheet_view_convert_tree_to_widget_coords:
10791 * @tree_view: a #PsppSheetView
10792 * @tx: X coordinate relative to the tree
10793 * @ty: Y coordinate relative to the tree
10794 * @wx: return location for widget X coordinate
10795 * @wy: return location for widget Y coordinate
10797 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10798 * to widget coordinates.
10803 pspp_sheet_view_convert_tree_to_widget_coords (PsppSheetView *tree_view,
10811 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10813 pspp_sheet_view_convert_tree_to_bin_window_coords (tree_view,
10816 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
10822 * pspp_sheet_view_convert_widget_to_bin_window_coords:
10823 * @tree_view: a #PsppSheetView
10824 * @wx: X coordinate relative to the widget
10825 * @wy: Y coordinate relative to the widget
10826 * @bx: return location for bin_window X coordinate
10827 * @by: return location for bin_window Y coordinate
10829 * Converts widget coordinates to coordinates for the bin_window
10830 * (see pspp_sheet_view_get_bin_window()).
10835 pspp_sheet_view_convert_widget_to_bin_window_coords (PsppSheetView *tree_view,
10841 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10844 *bx = wx + gtk_adjustment_get_value (tree_view->priv->hadjustment);
10846 *by = wy - TREE_VIEW_HEADER_HEIGHT (tree_view);
10850 * pspp_sheet_view_convert_bin_window_to_widget_coords:
10851 * @tree_view: a #PsppSheetView
10852 * @bx: bin_window X coordinate
10853 * @by: bin_window Y coordinate
10854 * @wx: return location for widget X coordinate
10855 * @wy: return location for widget Y coordinate
10857 * Converts bin_window coordinates (see pspp_sheet_view_get_bin_window())
10858 * to widget relative coordinates.
10863 pspp_sheet_view_convert_bin_window_to_widget_coords (PsppSheetView *tree_view,
10869 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10872 *wx = bx - gtk_adjustment_get_value (tree_view->priv->hadjustment);
10874 *wy = by + TREE_VIEW_HEADER_HEIGHT (tree_view);
10878 * pspp_sheet_view_convert_tree_to_bin_window_coords:
10879 * @tree_view: a #PsppSheetView
10880 * @tx: tree X coordinate
10881 * @ty: tree Y coordinate
10882 * @bx: return location for X coordinate relative to bin_window
10883 * @by: return location for Y coordinate relative to bin_window
10885 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10886 * to bin_window coordinates.
10891 pspp_sheet_view_convert_tree_to_bin_window_coords (PsppSheetView *tree_view,
10897 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10902 *by = ty - tree_view->priv->dy;
10906 * pspp_sheet_view_convert_bin_window_to_tree_coords:
10907 * @tree_view: a #PsppSheetView
10908 * @bx: X coordinate relative to bin_window
10909 * @by: Y coordinate relative to bin_window
10910 * @tx: return location for tree X coordinate
10911 * @ty: return location for tree Y coordinate
10913 * Converts bin_window coordinates to coordinates for the
10914 * tree (the full scrollable area of the tree).
10919 pspp_sheet_view_convert_bin_window_to_tree_coords (PsppSheetView *tree_view,
10925 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10930 *ty = by + tree_view->priv->dy;
10936 * pspp_sheet_view_get_visible_range:
10937 * @tree_view: A #PsppSheetView
10938 * @start_path: (allow-none): Return location for start of region, or %NULL.
10939 * @end_path: (allow-none): Return location for end of region, or %NULL.
10941 * Sets @start_path and @end_path to be the first and last visible path.
10942 * Note that there may be invisible paths in between.
10944 * The paths should be freed with gtk_tree_path_free() after use.
10946 * Returns: %TRUE, if valid paths were placed in @start_path and @end_path.
10951 pspp_sheet_view_get_visible_range (PsppSheetView *tree_view,
10952 GtkTreePath **start_path,
10953 GtkTreePath **end_path)
10958 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
10960 if (!tree_view->priv->row_count)
10967 pspp_sheet_view_find_offset (tree_view,
10968 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, 0),
10971 *start_path = _pspp_sheet_view_find_path (tree_view, node);
10980 if (tree_view->priv->height < gtk_adjustment_get_page_size (tree_view->priv->vadjustment))
10981 y = tree_view->priv->height - 1;
10983 y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, gtk_adjustment_get_page_size (tree_view->priv->vadjustment)) - 1;
10985 pspp_sheet_view_find_offset (tree_view, y, &node);
10987 *end_path = _pspp_sheet_view_find_path (tree_view, node);
10996 unset_reorderable (PsppSheetView *tree_view)
10998 if (tree_view->priv->reorderable)
11000 tree_view->priv->reorderable = FALSE;
11001 g_object_notify (G_OBJECT (tree_view), "reorderable");
11006 * pspp_sheet_view_enable_model_drag_source:
11007 * @tree_view: a #PsppSheetView
11008 * @start_button_mask: Mask of allowed buttons to start drag
11009 * @targets: the table of targets that the drag will support
11010 * @n_targets: the number of items in @targets
11011 * @actions: the bitmask of possible actions for a drag from this
11014 * Turns @tree_view into a drag source for automatic DND. Calling this
11015 * method sets #PsppSheetView:reorderable to %FALSE.
11018 pspp_sheet_view_enable_model_drag_source (PsppSheetView *tree_view,
11019 GdkModifierType start_button_mask,
11020 const GtkTargetEntry *targets,
11022 GdkDragAction actions)
11024 TreeViewDragInfo *di;
11026 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11028 gtk_drag_source_set (GTK_WIDGET (tree_view),
11034 di = ensure_info (tree_view);
11036 di->start_button_mask = start_button_mask;
11037 di->source_actions = actions;
11038 di->source_set = TRUE;
11040 unset_reorderable (tree_view);
11044 * pspp_sheet_view_enable_model_drag_dest:
11045 * @tree_view: a #PsppSheetView
11046 * @targets: the table of targets that the drag will support
11047 * @n_targets: the number of items in @targets
11048 * @actions: the bitmask of possible actions for a drag from this
11051 * Turns @tree_view into a drop destination for automatic DND. Calling
11052 * this method sets #PsppSheetView:reorderable to %FALSE.
11055 pspp_sheet_view_enable_model_drag_dest (PsppSheetView *tree_view,
11056 const GtkTargetEntry *targets,
11058 GdkDragAction actions)
11060 TreeViewDragInfo *di;
11062 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11064 gtk_drag_dest_set (GTK_WIDGET (tree_view),
11070 di = ensure_info (tree_view);
11071 di->dest_set = TRUE;
11073 unset_reorderable (tree_view);
11077 * pspp_sheet_view_unset_rows_drag_source:
11078 * @tree_view: a #PsppSheetView
11080 * Undoes the effect of
11081 * pspp_sheet_view_enable_model_drag_source(). Calling this method sets
11082 * #PsppSheetView:reorderable to %FALSE.
11085 pspp_sheet_view_unset_rows_drag_source (PsppSheetView *tree_view)
11087 TreeViewDragInfo *di;
11089 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11091 di = get_info (tree_view);
11095 if (di->source_set)
11097 gtk_drag_source_unset (GTK_WIDGET (tree_view));
11098 di->source_set = FALSE;
11101 if (!di->dest_set && !di->source_set)
11102 remove_info (tree_view);
11105 unset_reorderable (tree_view);
11109 * pspp_sheet_view_unset_rows_drag_dest:
11110 * @tree_view: a #PsppSheetView
11112 * Undoes the effect of
11113 * pspp_sheet_view_enable_model_drag_dest(). Calling this method sets
11114 * #PsppSheetView:reorderable to %FALSE.
11117 pspp_sheet_view_unset_rows_drag_dest (PsppSheetView *tree_view)
11119 TreeViewDragInfo *di;
11121 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11123 di = get_info (tree_view);
11129 gtk_drag_dest_unset (GTK_WIDGET (tree_view));
11130 di->dest_set = FALSE;
11133 if (!di->dest_set && !di->source_set)
11134 remove_info (tree_view);
11137 unset_reorderable (tree_view);
11141 * pspp_sheet_view_set_drag_dest_row:
11142 * @tree_view: a #PsppSheetView
11143 * @path: (allow-none): The path of the row to highlight, or %NULL.
11144 * @pos: Specifies whether to drop before, after or into the row
11146 * Sets the row that is highlighted for feedback.
11149 pspp_sheet_view_set_drag_dest_row (PsppSheetView *tree_view,
11151 PsppSheetViewDropPosition pos)
11153 GtkTreePath *current_dest;
11155 /* Note; this function is exported to allow a custom DND
11156 * implementation, so it can't touch TreeViewDragInfo
11159 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11161 current_dest = NULL;
11163 if (tree_view->priv->drag_dest_row)
11165 current_dest = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
11166 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
11169 /* special case a drop on an empty model */
11170 tree_view->priv->empty_view_drop = 0;
11172 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE && path
11173 && gtk_tree_path_get_depth (path) == 1
11174 && gtk_tree_path_get_indices (path)[0] == 0)
11178 n_children = gtk_tree_model_iter_n_children (tree_view->priv->model,
11182 tree_view->priv->empty_view_drop = 1;
11185 tree_view->priv->drag_dest_pos = pos;
11189 tree_view->priv->drag_dest_row =
11190 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
11191 pspp_sheet_view_queue_draw_path (tree_view, path, NULL);
11194 tree_view->priv->drag_dest_row = NULL;
11198 int node, new_node;
11200 _pspp_sheet_view_find_node (tree_view, current_dest, &node);
11201 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
11205 new_node = pspp_sheet_view_node_next (tree_view, node);
11207 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
11209 new_node = pspp_sheet_view_node_prev (tree_view, node);
11211 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
11213 gtk_tree_path_free (current_dest);
11218 * pspp_sheet_view_get_drag_dest_row:
11219 * @tree_view: a #PsppSheetView
11220 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
11221 * @pos: (allow-none): Return location for the drop position, or %NULL
11223 * Gets information about the row that is highlighted for feedback.
11226 pspp_sheet_view_get_drag_dest_row (PsppSheetView *tree_view,
11227 GtkTreePath **path,
11228 PsppSheetViewDropPosition *pos)
11230 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11234 if (tree_view->priv->drag_dest_row)
11235 *path = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
11238 if (tree_view->priv->empty_view_drop)
11239 *path = gtk_tree_path_new_from_indices (0, -1);
11246 *pos = tree_view->priv->drag_dest_pos;
11250 * pspp_sheet_view_get_dest_row_at_pos:
11251 * @tree_view: a #PsppSheetView
11252 * @drag_x: the position to determine the destination row for
11253 * @drag_y: the position to determine the destination row for
11254 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
11255 * @pos: (allow-none): Return location for the drop position, or %NULL
11257 * Determines the destination row for a given position. @drag_x and
11258 * @drag_y are expected to be in widget coordinates. This function is only
11259 * meaningful if @tree_view is realized. Therefore this function will always
11260 * return %FALSE if @tree_view is not realized or does not have a model.
11262 * Return value: whether there is a row at the given position, %TRUE if this
11263 * is indeed the case.
11266 pspp_sheet_view_get_dest_row_at_pos (PsppSheetView *tree_view,
11269 GtkTreePath **path,
11270 PsppSheetViewDropPosition *pos)
11274 gdouble offset_into_row;
11277 PsppSheetViewColumn *column = NULL;
11278 GtkTreePath *tmp_path = NULL;
11280 /* Note; this function is exported to allow a custom DND
11281 * implementation, so it can't touch TreeViewDragInfo
11284 g_return_val_if_fail (tree_view != NULL, FALSE);
11285 g_return_val_if_fail (drag_x >= 0, FALSE);
11286 g_return_val_if_fail (drag_y >= 0, FALSE);
11291 if (tree_view->priv->bin_window == NULL)
11294 if (tree_view->priv->row_count == 0)
11297 /* If in the top third of a row, we drop before that row; if
11298 * in the bottom third, drop after that row; if in the middle,
11299 * and the row has children, drop into the row.
11301 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, drag_x, drag_y,
11304 if (!pspp_sheet_view_get_path_at_pos (tree_view,
11313 pspp_sheet_view_get_background_area (tree_view, tmp_path, column,
11316 offset_into_row = cell_y;
11321 gtk_tree_path_free (tmp_path);
11325 third = cell.height / 3.0;
11329 if (offset_into_row < third)
11331 *pos = PSPP_SHEET_VIEW_DROP_BEFORE;
11333 else if (offset_into_row < (cell.height / 2.0))
11335 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE;
11337 else if (offset_into_row < third * 2.0)
11339 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER;
11343 *pos = PSPP_SHEET_VIEW_DROP_AFTER;
11351 #if GTK3_TRANSITION
11352 /* KEEP IN SYNC WITH PSPP_SHEET_VIEW_BIN_EXPOSE */
11354 * pspp_sheet_view_create_row_drag_icon:
11355 * @tree_view: a #PsppSheetView
11356 * @path: a #GtkTreePath in @tree_view
11358 * Creates a #GdkPixmap representation of the row at @path.
11359 * This image is used for a drag icon.
11361 * Return value: a newly-allocated pixmap of the drag icon.
11364 pspp_sheet_view_create_row_drag_icon (PsppSheetView *tree_view,
11371 GdkRectangle background_area;
11372 GdkRectangle expose_area;
11374 /* start drawing inside the black outline */
11376 GdkDrawable *drawable;
11377 gint bin_window_width;
11380 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11381 g_return_val_if_fail (path != NULL, NULL);
11383 widget = GTK_WIDGET (tree_view);
11385 if (!gtk_widget_get_realized (widget))
11388 _pspp_sheet_view_find_node (tree_view,
11395 if (!gtk_tree_model_get_iter (tree_view->priv->model,
11402 background_area.y = y;
11403 background_area.height = ROW_HEIGHT (tree_view);
11405 bin_window_width = gdk_window_get_width (tree_view->priv->bin_window);
11407 drawable = gdk_pixmap_new (tree_view->priv->bin_window,
11408 bin_window_width + 2,
11409 background_area.height + 2,
11414 expose_area.width = bin_window_width + 2;
11415 expose_area.height = background_area.height + 2;
11417 #if GTK3_TRANSITION
11418 gdk_draw_rectangle (drawable,
11419 widget->style->base_gc [gtk_widget_get_state (widget)],
11422 bin_window_width + 2,
11423 background_area.height + 2);
11426 rtl = gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL;
11428 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
11430 list = (rtl ? list->prev : list->next))
11432 PsppSheetViewColumn *column = list->data;
11433 GdkRectangle cell_area;
11434 gint vertical_separator;
11436 if (!column->visible)
11439 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, &iter);
11441 background_area.x = cell_offset;
11442 background_area.width = column->width;
11444 gtk_widget_style_get (widget,
11445 "vertical-separator", &vertical_separator,
11448 cell_area = background_area;
11450 cell_area.y += vertical_separator / 2;
11451 cell_area.height -= vertical_separator;
11453 if (pspp_sheet_view_column_cell_is_visible (column))
11454 _pspp_sheet_view_column_cell_render (column,
11460 cell_offset += column->width;
11463 #if GTK3_TRANSITION
11464 gdk_draw_rectangle (drawable,
11465 widget->style->black_gc,
11468 bin_window_width + 1,
11469 background_area.height + 1);
11477 * pspp_sheet_view_set_destroy_count_func:
11478 * @tree_view: A #PsppSheetView
11479 * @func: (allow-none): Function to be called when a view row is destroyed, or %NULL
11480 * @data: (allow-none): User data to be passed to @func, or %NULL
11481 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11483 * This function should almost never be used. It is meant for private use by
11484 * ATK for determining the number of visible children that are removed when a row is deleted.
11487 pspp_sheet_view_set_destroy_count_func (PsppSheetView *tree_view,
11488 PsppSheetDestroyCountFunc func,
11490 GDestroyNotify destroy)
11492 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11494 if (tree_view->priv->destroy_count_destroy)
11495 tree_view->priv->destroy_count_destroy (tree_view->priv->destroy_count_data);
11497 tree_view->priv->destroy_count_func = func;
11498 tree_view->priv->destroy_count_data = data;
11499 tree_view->priv->destroy_count_destroy = destroy;
11504 * Interactive search
11508 * pspp_sheet_view_set_enable_search:
11509 * @tree_view: A #PsppSheetView
11510 * @enable_search: %TRUE, if the user can search interactively
11512 * If @enable_search is set, then the user can type in text to search through
11513 * the tree interactively (this is sometimes called "typeahead find").
11515 * Note that even if this is %FALSE, the user can still initiate a search
11516 * using the "start-interactive-search" key binding.
11519 pspp_sheet_view_set_enable_search (PsppSheetView *tree_view,
11520 gboolean enable_search)
11522 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11524 enable_search = !!enable_search;
11526 if (tree_view->priv->enable_search != enable_search)
11528 tree_view->priv->enable_search = enable_search;
11529 g_object_notify (G_OBJECT (tree_view), "enable-search");
11534 * pspp_sheet_view_get_enable_search:
11535 * @tree_view: A #PsppSheetView
11537 * Returns whether or not the tree allows to start interactive searching
11538 * by typing in text.
11540 * Return value: whether or not to let the user search interactively
11543 pspp_sheet_view_get_enable_search (PsppSheetView *tree_view)
11545 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11547 return tree_view->priv->enable_search;
11552 * pspp_sheet_view_get_search_column:
11553 * @tree_view: A #PsppSheetView
11555 * Gets the column searched on by the interactive search code.
11557 * Return value: the column the interactive search code searches in.
11560 pspp_sheet_view_get_search_column (PsppSheetView *tree_view)
11562 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
11564 return (tree_view->priv->search_column);
11568 * pspp_sheet_view_set_search_column:
11569 * @tree_view: A #PsppSheetView
11570 * @column: the column of the model to search in, or -1 to disable searching
11572 * Sets @column as the column where the interactive search code should
11573 * search in for the current model.
11575 * If the search column is set, users can use the "start-interactive-search"
11576 * key binding to bring up search popup. The enable-search property controls
11577 * whether simply typing text will also start an interactive search.
11579 * Note that @column refers to a column of the current model. The search
11580 * column is reset to -1 when the model is changed.
11583 pspp_sheet_view_set_search_column (PsppSheetView *tree_view,
11586 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11587 g_return_if_fail (column >= -1);
11589 if (tree_view->priv->search_column == column)
11592 tree_view->priv->search_column = column;
11593 g_object_notify (G_OBJECT (tree_view), "search-column");
11597 * pspp_sheet_view_get_search_equal_func:
11598 * @tree_view: A #PsppSheetView
11600 * Returns the compare function currently in use.
11602 * Return value: the currently used compare function for the search code.
11605 PsppSheetViewSearchEqualFunc
11606 pspp_sheet_view_get_search_equal_func (PsppSheetView *tree_view)
11608 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11610 return tree_view->priv->search_equal_func;
11614 * pspp_sheet_view_set_search_equal_func:
11615 * @tree_view: A #PsppSheetView
11616 * @search_equal_func: the compare function to use during the search
11617 * @search_user_data: (allow-none): user data to pass to @search_equal_func, or %NULL
11618 * @search_destroy: (allow-none): Destroy notifier for @search_user_data, or %NULL
11620 * Sets the compare function for the interactive search capabilities; note
11621 * that somewhat like strcmp() returning 0 for equality
11622 * #PsppSheetViewSearchEqualFunc returns %FALSE on matches.
11625 pspp_sheet_view_set_search_equal_func (PsppSheetView *tree_view,
11626 PsppSheetViewSearchEqualFunc search_equal_func,
11627 gpointer search_user_data,
11628 GDestroyNotify search_destroy)
11630 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11631 g_return_if_fail (search_equal_func != NULL);
11633 if (tree_view->priv->search_destroy)
11634 tree_view->priv->search_destroy (tree_view->priv->search_user_data);
11636 tree_view->priv->search_equal_func = search_equal_func;
11637 tree_view->priv->search_user_data = search_user_data;
11638 tree_view->priv->search_destroy = search_destroy;
11639 if (tree_view->priv->search_equal_func == NULL)
11640 tree_view->priv->search_equal_func = pspp_sheet_view_search_equal_func;
11644 * pspp_sheet_view_get_search_entry:
11645 * @tree_view: A #PsppSheetView
11647 * Returns the #GtkEntry which is currently in use as interactive search
11648 * entry for @tree_view. In case the built-in entry is being used, %NULL
11649 * will be returned.
11651 * Return value: the entry currently in use as search entry.
11656 pspp_sheet_view_get_search_entry (PsppSheetView *tree_view)
11658 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11660 if (tree_view->priv->search_custom_entry_set)
11661 return GTK_ENTRY (tree_view->priv->search_entry);
11667 * pspp_sheet_view_set_search_entry:
11668 * @tree_view: A #PsppSheetView
11669 * @entry: (allow-none): the entry the interactive search code of @tree_view should use or %NULL
11671 * Sets the entry which the interactive search code will use for this
11672 * @tree_view. This is useful when you want to provide a search entry
11673 * in our interface at all time at a fixed position. Passing %NULL for
11674 * @entry will make the interactive search code use the built-in popup
11680 pspp_sheet_view_set_search_entry (PsppSheetView *tree_view,
11683 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11684 g_return_if_fail (entry == NULL || GTK_IS_ENTRY (entry));
11686 if (tree_view->priv->search_custom_entry_set)
11688 if (tree_view->priv->search_entry_changed_id)
11690 g_signal_handler_disconnect (tree_view->priv->search_entry,
11691 tree_view->priv->search_entry_changed_id);
11692 tree_view->priv->search_entry_changed_id = 0;
11694 g_signal_handlers_disconnect_by_func (tree_view->priv->search_entry,
11695 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11698 g_object_unref (tree_view->priv->search_entry);
11700 else if (tree_view->priv->search_window)
11702 gtk_widget_destroy (tree_view->priv->search_window);
11704 tree_view->priv->search_window = NULL;
11709 tree_view->priv->search_entry = g_object_ref (entry);
11710 tree_view->priv->search_custom_entry_set = TRUE;
11712 if (tree_view->priv->search_entry_changed_id == 0)
11714 tree_view->priv->search_entry_changed_id =
11715 g_signal_connect (tree_view->priv->search_entry, "changed",
11716 G_CALLBACK (pspp_sheet_view_search_init),
11720 g_signal_connect (tree_view->priv->search_entry, "key-press-event",
11721 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11724 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
11728 tree_view->priv->search_entry = NULL;
11729 tree_view->priv->search_custom_entry_set = FALSE;
11734 * pspp_sheet_view_set_search_position_func:
11735 * @tree_view: A #PsppSheetView
11736 * @func: (allow-none): the function to use to position the search dialog, or %NULL
11737 * to use the default search position function
11738 * @data: (allow-none): user data to pass to @func, or %NULL
11739 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11741 * Sets the function to use when positioning the search dialog.
11746 pspp_sheet_view_set_search_position_func (PsppSheetView *tree_view,
11747 PsppSheetViewSearchPositionFunc func,
11748 gpointer user_data,
11749 GDestroyNotify destroy)
11751 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11753 if (tree_view->priv->search_position_destroy)
11754 tree_view->priv->search_position_destroy (tree_view->priv->search_position_user_data);
11756 tree_view->priv->search_position_func = func;
11757 tree_view->priv->search_position_user_data = user_data;
11758 tree_view->priv->search_position_destroy = destroy;
11759 if (tree_view->priv->search_position_func == NULL)
11760 tree_view->priv->search_position_func = pspp_sheet_view_search_position_func;
11764 * pspp_sheet_view_get_search_position_func:
11765 * @tree_view: A #PsppSheetView
11767 * Returns the positioning function currently in use.
11769 * Return value: the currently used function for positioning the search dialog.
11773 PsppSheetViewSearchPositionFunc
11774 pspp_sheet_view_get_search_position_func (PsppSheetView *tree_view)
11776 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11778 return tree_view->priv->search_position_func;
11783 pspp_sheet_view_search_dialog_hide (GtkWidget *search_dialog,
11784 PsppSheetView *tree_view)
11786 if (tree_view->priv->disable_popdown)
11789 if (tree_view->priv->search_entry_changed_id)
11791 g_signal_handler_disconnect (tree_view->priv->search_entry,
11792 tree_view->priv->search_entry_changed_id);
11793 tree_view->priv->search_entry_changed_id = 0;
11795 if (tree_view->priv->typeselect_flush_timeout)
11797 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11798 tree_view->priv->typeselect_flush_timeout = 0;
11801 if (gtk_widget_get_visible (search_dialog))
11803 /* send focus-in event */
11804 send_focus_change (GTK_WIDGET (tree_view->priv->search_entry), FALSE);
11805 gtk_widget_hide (search_dialog);
11806 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
11807 send_focus_change (GTK_WIDGET (tree_view), TRUE);
11812 pspp_sheet_view_search_position_func (PsppSheetView *tree_view,
11813 GtkWidget *search_dialog,
11814 gpointer user_data)
11817 gint tree_x, tree_y;
11818 gint tree_width, tree_height;
11819 GdkWindow *tree_window = gtk_widget_get_window (GTK_WIDGET (tree_view));
11820 GdkScreen *screen = gdk_window_get_screen (tree_window);
11821 GtkRequisition requisition;
11823 GdkRectangle monitor;
11825 monitor_num = gdk_screen_get_monitor_at_window (screen, tree_window);
11826 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
11828 gtk_widget_realize (search_dialog);
11830 gdk_window_get_origin (tree_window, &tree_x, &tree_y);
11831 tree_width = gdk_window_get_width (tree_window);
11832 tree_height = gdk_window_get_height (tree_window);
11834 gtk_widget_size_request (search_dialog, &requisition);
11836 if (tree_x + tree_width > gdk_screen_get_width (screen))
11837 x = gdk_screen_get_width (screen) - requisition.width;
11838 else if (tree_x + tree_width - requisition.width < 0)
11841 x = tree_x + tree_width - requisition.width;
11843 if (tree_y + tree_height + requisition.height > gdk_screen_get_height (screen))
11844 y = gdk_screen_get_height (screen) - requisition.height;
11845 else if (tree_y + tree_height < 0) /* isn't really possible ... */
11848 y = tree_y + tree_height;
11850 gtk_window_move (GTK_WINDOW (search_dialog), x, y);
11854 pspp_sheet_view_search_disable_popdown (GtkEntry *entry,
11858 PsppSheetView *tree_view = (PsppSheetView *)data;
11860 tree_view->priv->disable_popdown = 1;
11861 g_signal_connect (menu, "hide",
11862 G_CALLBACK (pspp_sheet_view_search_enable_popdown), data);
11865 #if GTK3_TRANSITION
11866 /* Because we're visible but offscreen, we just set a flag in the preedit
11870 pspp_sheet_view_search_preedit_changed (GtkIMContext *im_context,
11871 PsppSheetView *tree_view)
11873 tree_view->priv->imcontext_changed = 1;
11874 if (tree_view->priv->typeselect_flush_timeout)
11876 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11877 tree_view->priv->typeselect_flush_timeout =
11878 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11879 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11887 pspp_sheet_view_search_activate (GtkEntry *entry,
11888 PsppSheetView *tree_view)
11893 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window,
11896 /* If we have a row selected and it's the cursor row, we activate
11898 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
11900 path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
11902 _pspp_sheet_view_find_node (tree_view, path, &node);
11904 if (node >= 0 && pspp_sheet_view_node_is_selected (tree_view, node))
11905 pspp_sheet_view_row_activated (tree_view, path, tree_view->priv->focus_column);
11907 gtk_tree_path_free (path);
11912 pspp_sheet_view_real_search_enable_popdown (gpointer data)
11914 PsppSheetView *tree_view = (PsppSheetView *)data;
11916 tree_view->priv->disable_popdown = 0;
11922 pspp_sheet_view_search_enable_popdown (GtkWidget *widget,
11925 gdk_threads_add_timeout_full (G_PRIORITY_HIGH, 200, pspp_sheet_view_real_search_enable_popdown, g_object_ref (data), g_object_unref);
11929 pspp_sheet_view_search_delete_event (GtkWidget *widget,
11930 GdkEventAny *event,
11931 PsppSheetView *tree_view)
11933 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11935 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11941 pspp_sheet_view_search_button_press_event (GtkWidget *widget,
11942 GdkEventButton *event,
11943 PsppSheetView *tree_view)
11945 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11947 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11949 if (event->window == tree_view->priv->bin_window)
11950 pspp_sheet_view_button_press (GTK_WIDGET (tree_view), event);
11956 pspp_sheet_view_search_scroll_event (GtkWidget *widget,
11957 GdkEventScroll *event,
11958 PsppSheetView *tree_view)
11960 gboolean retval = FALSE;
11962 if (event->direction == GDK_SCROLL_UP)
11964 pspp_sheet_view_search_move (widget, tree_view, TRUE);
11967 else if (event->direction == GDK_SCROLL_DOWN)
11969 pspp_sheet_view_search_move (widget, tree_view, FALSE);
11973 /* renew the flush timeout */
11974 if (retval && tree_view->priv->typeselect_flush_timeout
11975 && !tree_view->priv->search_custom_entry_set)
11977 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11978 tree_view->priv->typeselect_flush_timeout =
11979 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11980 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11988 pspp_sheet_view_search_key_press_event (GtkWidget *widget,
11989 GdkEventKey *event,
11990 PsppSheetView *tree_view)
11992 gboolean retval = FALSE;
11994 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11995 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11997 /* close window and cancel the search */
11998 if (!tree_view->priv->search_custom_entry_set
11999 && (event->keyval == GDK_Escape ||
12000 event->keyval == GDK_Tab ||
12001 event->keyval == GDK_KP_Tab ||
12002 event->keyval == GDK_ISO_Left_Tab))
12004 pspp_sheet_view_search_dialog_hide (widget, tree_view);
12008 /* select previous matching iter */
12009 if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up)
12011 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
12012 gtk_widget_error_bell (widget);
12017 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK))
12018 && (event->keyval == GDK_g || event->keyval == GDK_G))
12020 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
12021 gtk_widget_error_bell (widget);
12026 /* select next matching iter */
12027 if (event->keyval == GDK_Down || event->keyval == GDK_KP_Down)
12029 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
12030 gtk_widget_error_bell (widget);
12035 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == GTK_DEFAULT_ACCEL_MOD_MASK)
12036 && (event->keyval == GDK_g || event->keyval == GDK_G))
12038 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
12039 gtk_widget_error_bell (widget);
12044 /* renew the flush timeout */
12045 if (retval && tree_view->priv->typeselect_flush_timeout
12046 && !tree_view->priv->search_custom_entry_set)
12048 g_source_remove (tree_view->priv->typeselect_flush_timeout);
12049 tree_view->priv->typeselect_flush_timeout =
12050 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
12051 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
12058 /* this function returns FALSE if there is a search string but
12059 * nothing was found, and TRUE otherwise.
12062 pspp_sheet_view_search_move (GtkWidget *window,
12063 PsppSheetView *tree_view,
12071 GtkTreeModel *model;
12072 PsppSheetSelection *selection;
12074 text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
12076 g_return_val_if_fail (text != NULL, FALSE);
12078 len = strlen (text);
12080 if (up && tree_view->priv->selected_iter == 1)
12081 return strlen (text) < 1;
12083 len = strlen (text);
12088 model = pspp_sheet_view_get_model (tree_view);
12089 selection = pspp_sheet_view_get_selection (tree_view);
12092 pspp_sheet_selection_unselect_all (selection);
12093 if (!gtk_tree_model_get_iter_first (model, &iter))
12096 ret = pspp_sheet_view_search_iter (model, selection, &iter, text,
12097 &count, up?((tree_view->priv->selected_iter) - 1):((tree_view->priv->selected_iter + 1)));
12102 tree_view->priv->selected_iter += up?(-1):(1);
12107 /* return to old iter */
12109 gtk_tree_model_get_iter_first (model, &iter);
12110 pspp_sheet_view_search_iter (model, selection,
12112 &count, tree_view->priv->selected_iter);
12118 pspp_sheet_view_search_equal_func (GtkTreeModel *model,
12122 gpointer search_data)
12124 gboolean retval = TRUE;
12126 gchar *normalized_string;
12127 gchar *normalized_key;
12128 gchar *case_normalized_string = NULL;
12129 gchar *case_normalized_key = NULL;
12130 GValue value = {0,};
12131 GValue transformed = {0,};
12133 gtk_tree_model_get_value (model, iter, column, &value);
12135 g_value_init (&transformed, G_TYPE_STRING);
12137 if (!g_value_transform (&value, &transformed))
12139 g_value_unset (&value);
12143 g_value_unset (&value);
12145 str = g_value_get_string (&transformed);
12148 g_value_unset (&transformed);
12152 normalized_string = g_utf8_normalize (str, -1, G_NORMALIZE_ALL);
12153 normalized_key = g_utf8_normalize (key, -1, G_NORMALIZE_ALL);
12155 if (normalized_string && normalized_key)
12157 case_normalized_string = g_utf8_casefold (normalized_string, -1);
12158 case_normalized_key = g_utf8_casefold (normalized_key, -1);
12160 if (strncmp (case_normalized_key, case_normalized_string, strlen (case_normalized_key)) == 0)
12164 g_value_unset (&transformed);
12165 g_free (normalized_key);
12166 g_free (normalized_string);
12167 g_free (case_normalized_key);
12168 g_free (case_normalized_string);
12174 pspp_sheet_view_search_iter (GtkTreeModel *model,
12175 PsppSheetSelection *selection,
12184 PsppSheetView *tree_view = pspp_sheet_selection_get_tree_view (selection);
12186 path = gtk_tree_model_get_path (model, iter);
12187 _pspp_sheet_view_find_node (tree_view, path, &node);
12191 gboolean done = FALSE;
12193 if (! tree_view->priv->search_equal_func (model, tree_view->priv->search_column, text, iter, tree_view->priv->search_user_data))
12198 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL,
12200 pspp_sheet_selection_select_iter (selection, iter);
12201 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE, 0);
12204 gtk_tree_path_free (path);
12213 node = pspp_sheet_view_node_next (tree_view, node);
12219 has_next = gtk_tree_model_iter_next (model, iter);
12222 gtk_tree_path_next (path);
12225 TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
12230 gtk_tree_path_free (path);
12232 /* we've run out of tree, done with this func */
12244 pspp_sheet_view_search_init (GtkWidget *entry,
12245 PsppSheetView *tree_view)
12251 GtkTreeModel *model;
12252 PsppSheetSelection *selection;
12254 g_return_if_fail (GTK_IS_ENTRY (entry));
12255 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12257 text = gtk_entry_get_text (GTK_ENTRY (entry));
12259 model = pspp_sheet_view_get_model (tree_view);
12260 selection = pspp_sheet_view_get_selection (tree_view);
12263 pspp_sheet_selection_unselect_all (selection);
12264 if (tree_view->priv->typeselect_flush_timeout
12265 && !tree_view->priv->search_custom_entry_set)
12267 g_source_remove (tree_view->priv->typeselect_flush_timeout);
12268 tree_view->priv->typeselect_flush_timeout =
12269 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
12270 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
12277 if (!gtk_tree_model_get_iter_first (model, &iter))
12280 ret = pspp_sheet_view_search_iter (model, selection,
12285 tree_view->priv->selected_iter = 1;
12289 pspp_sheet_view_remove_widget (GtkCellEditable *cell_editable,
12290 PsppSheetView *tree_view)
12292 if (tree_view->priv->edited_column == NULL)
12295 _pspp_sheet_view_column_stop_editing (tree_view->priv->edited_column);
12296 tree_view->priv->edited_column = NULL;
12298 if (gtk_widget_has_focus (GTK_WIDGET (cell_editable)))
12299 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
12301 g_signal_handlers_disconnect_by_func (cell_editable,
12302 pspp_sheet_view_remove_widget,
12304 g_signal_handlers_disconnect_by_func (cell_editable,
12305 pspp_sheet_view_editable_button_press_event,
12307 g_signal_handlers_disconnect_by_func (cell_editable,
12308 pspp_sheet_view_editable_clicked,
12311 gtk_container_remove (GTK_CONTAINER (tree_view),
12312 GTK_WIDGET (cell_editable));
12314 /* FIXME should only redraw a single node */
12315 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12319 pspp_sheet_view_start_editing (PsppSheetView *tree_view,
12320 GtkTreePath *cursor_path)
12323 GdkRectangle background_area;
12324 GdkRectangle cell_area;
12325 GtkCellEditable *editable_widget = NULL;
12326 gchar *path_string;
12327 guint flags = 0; /* can be 0, as the flags are primarily for rendering */
12328 gint retval = FALSE;
12331 g_assert (tree_view->priv->focus_column);
12333 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
12336 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
12337 if (cursor_node < 0)
12340 path_string = gtk_tree_path_to_string (cursor_path);
12341 gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path);
12343 pspp_sheet_view_column_cell_set_cell_data (tree_view->priv->focus_column,
12344 tree_view->priv->model,
12346 pspp_sheet_view_get_background_area (tree_view,
12348 tree_view->priv->focus_column,
12350 pspp_sheet_view_get_cell_area (tree_view,
12352 tree_view->priv->focus_column,
12355 if (_pspp_sheet_view_column_cell_event (tree_view->priv->focus_column,
12364 if (editable_widget != NULL)
12368 GtkCellRenderer *cell;
12371 cell = _pspp_sheet_view_column_get_edited_cell (tree_view->priv->focus_column);
12373 _pspp_sheet_view_column_get_neighbor_sizes (tree_view->priv->focus_column, cell, &left, &right);
12376 area.width -= right + left;
12378 pspp_sheet_view_real_start_editing (tree_view,
12379 tree_view->priv->focus_column,
12388 g_free (path_string);
12393 pspp_sheet_view_editable_button_press_event (GtkWidget *widget,
12394 GdkEventButton *event,
12395 PsppSheetView *sheet_view)
12399 node = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
12400 "pspp-sheet-view-node"));
12401 return pspp_sheet_view_row_head_clicked (sheet_view,
12403 sheet_view->priv->edited_column,
12408 pspp_sheet_view_editable_clicked (GtkButton *button,
12409 PsppSheetView *sheet_view)
12411 pspp_sheet_view_editable_button_press_event (GTK_WIDGET (button), NULL,
12416 is_all_selected (GtkWidget *widget)
12418 GtkEntryBuffer *buffer;
12419 gint start_pos, end_pos;
12421 if (!GTK_IS_ENTRY (widget))
12424 buffer = gtk_entry_get_buffer (GTK_ENTRY (widget));
12425 return (gtk_editable_get_selection_bounds (GTK_EDITABLE (widget),
12426 &start_pos, &end_pos)
12428 && end_pos == gtk_entry_buffer_get_length (buffer));
12432 is_at_left (GtkWidget *widget)
12434 return (GTK_IS_ENTRY (widget)
12435 && gtk_editable_get_position (GTK_EDITABLE (widget)) == 0);
12439 is_at_right (GtkWidget *widget)
12441 GtkEntryBuffer *buffer;
12444 if (!GTK_IS_ENTRY (widget))
12447 buffer = gtk_entry_get_buffer (GTK_ENTRY (widget));
12448 length = gtk_entry_buffer_get_length (buffer);
12449 return gtk_editable_get_position (GTK_EDITABLE (widget)) == length;
12453 pspp_sheet_view_event (GtkWidget *widget,
12454 GdkEventKey *event,
12455 PsppSheetView *tree_view)
12457 PsppSheetViewColumn *column;
12464 /* Intercept only key press events.
12465 It would make sense to use "key-press-event" instead of "event", but
12466 GtkEntry attaches its own signal handler to "key-press-event" that runs
12467 before ours and overrides our desired behavior for GDK_Up and GDK_Down.
12469 if (event->type != GDK_KEY_PRESS)
12472 keyval = event->keyval;
12474 switch (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK | GDK_MOD1_MASK))
12477 switch (event->keyval)
12479 case GDK_Left: case GDK_KP_Left:
12480 case GDK_Home: case GDK_KP_Home:
12481 if (!is_all_selected (widget) && !is_at_left (widget))
12485 case GDK_Right: case GDK_KP_Right:
12486 case GDK_End: case GDK_KP_End:
12487 if (!is_all_selected (widget) && !is_at_right (widget))
12491 case GDK_Up: case GDK_KP_Up:
12492 case GDK_Down: case GDK_KP_Down:
12495 case GDK_Page_Up: case GDK_KP_Page_Up:
12496 case GDK_Page_Down: case GDK_KP_Page_Down:
12507 case GDK_Tab: case GDK_KP_Tab:
12508 case GDK_ISO_Left_Tab:
12517 case GDK_SHIFT_MASK:
12518 switch (event->keyval)
12521 case GDK_ISO_Left_Tab:
12530 case GDK_CONTROL_MASK:
12531 switch (event->keyval)
12533 case GDK_Left: case GDK_KP_Left:
12534 if (!is_all_selected (widget) && !is_at_left (widget))
12538 case GDK_Right: case GDK_KP_Right:
12539 if (!is_all_selected (widget) && !is_at_right (widget))
12543 case GDK_Up: case GDK_KP_Up:
12544 case GDK_Down: case GDK_KP_Down:
12556 row = tree_view->priv->edited_row;
12557 column = tree_view->priv->edited_column;
12558 path = gtk_tree_path_new_from_indices (row, -1);
12560 pspp_sheet_view_stop_editing (tree_view, cancel);
12561 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
12563 pspp_sheet_view_set_cursor (tree_view, path, column, FALSE);
12564 gtk_tree_path_free (path);
12566 handled = gtk_binding_set_activate (edit_bindings, keyval, event->state,
12567 G_OBJECT (tree_view));
12569 g_signal_stop_emission_by_name (widget, "event");
12571 pspp_sheet_view_get_cursor (tree_view, &path, NULL);
12572 pspp_sheet_view_start_editing (tree_view, path);
12573 gtk_tree_path_free (path);
12579 pspp_sheet_view_override_cell_keypresses (GtkWidget *widget,
12582 PsppSheetView *sheet_view = data;
12584 g_signal_connect (widget, "event",
12585 G_CALLBACK (pspp_sheet_view_event),
12588 if (GTK_IS_CONTAINER (widget))
12589 gtk_container_foreach (GTK_CONTAINER (widget),
12590 pspp_sheet_view_override_cell_keypresses,
12595 pspp_sheet_view_real_start_editing (PsppSheetView *tree_view,
12596 PsppSheetViewColumn *column,
12598 GtkCellEditable *cell_editable,
12599 GdkRectangle *cell_area,
12603 PsppSheetSelectionMode mode = pspp_sheet_selection_get_mode (tree_view->priv->selection);
12604 gint pre_val = gtk_adjustment_get_value (tree_view->priv->vadjustment);
12605 GtkRequisition requisition;
12608 g_return_if_fail (gtk_tree_path_get_depth (path) == 1);
12610 tree_view->priv->edited_column = column;
12611 _pspp_sheet_view_column_start_editing (column, GTK_CELL_EDITABLE (cell_editable));
12613 row = gtk_tree_path_get_indices (path)[0];
12614 tree_view->priv->edited_row = row;
12615 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE, 0);
12616 cell_area->y += pre_val - (int)gtk_adjustment_get_value (tree_view->priv->vadjustment);
12618 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
12619 pspp_sheet_selection_select_column (tree_view->priv->selection, column);
12620 tree_view->priv->anchor_column = column;
12622 gtk_widget_size_request (GTK_WIDGET (cell_editable), &requisition);
12624 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
12626 if (requisition.height < cell_area->height)
12628 gint diff = cell_area->height - requisition.height;
12629 pspp_sheet_view_put (tree_view,
12630 GTK_WIDGET (cell_editable),
12631 cell_area->x, cell_area->y + diff/2,
12632 cell_area->width, requisition.height);
12636 pspp_sheet_view_put (tree_view,
12637 GTK_WIDGET (cell_editable),
12638 cell_area->x, cell_area->y,
12639 cell_area->width, cell_area->height);
12642 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (cell_editable),
12643 (GdkEvent *)event);
12645 gtk_widget_grab_focus (GTK_WIDGET (cell_editable));
12646 g_signal_connect (cell_editable, "remove-widget",
12647 G_CALLBACK (pspp_sheet_view_remove_widget), tree_view);
12648 if (mode == PSPP_SHEET_SELECTION_RECTANGLE && column->row_head &&
12649 GTK_IS_BUTTON (cell_editable))
12651 g_signal_connect (cell_editable, "button-press-event",
12652 G_CALLBACK (pspp_sheet_view_editable_button_press_event),
12654 g_object_set_data (G_OBJECT (cell_editable), "pspp-sheet-view-node",
12655 GINT_TO_POINTER (row));
12656 g_signal_connect (cell_editable, "clicked",
12657 G_CALLBACK (pspp_sheet_view_editable_clicked),
12661 pspp_sheet_view_override_cell_keypresses (GTK_WIDGET (cell_editable),
12666 pspp_sheet_view_stop_editing (PsppSheetView *tree_view,
12667 gboolean cancel_editing)
12669 PsppSheetViewColumn *column;
12670 GtkCellRenderer *cell;
12672 if (tree_view->priv->edited_column == NULL)
12676 * This is very evil. We need to do this, because
12677 * gtk_cell_editable_editing_done may trigger pspp_sheet_view_row_changed
12678 * later on. If pspp_sheet_view_row_changed notices
12679 * tree_view->priv->edited_column != NULL, it'll call
12680 * pspp_sheet_view_stop_editing again. Bad things will happen then.
12682 * Please read that again if you intend to modify anything here.
12685 column = tree_view->priv->edited_column;
12686 tree_view->priv->edited_column = NULL;
12688 cell = _pspp_sheet_view_column_get_edited_cell (column);
12689 gtk_cell_renderer_stop_editing (cell, cancel_editing);
12691 if (!cancel_editing)
12692 gtk_cell_editable_editing_done (column->editable_widget);
12694 tree_view->priv->edited_column = column;
12696 gtk_cell_editable_remove_widget (column->editable_widget);
12701 * pspp_sheet_view_set_hover_selection:
12702 * @tree_view: a #PsppSheetView
12703 * @hover: %TRUE to enable hover selection mode
12705 * Enables of disables the hover selection mode of @tree_view.
12706 * Hover selection makes the selected row follow the pointer.
12707 * Currently, this works only for the selection modes
12708 * %PSPP_SHEET_SELECTION_SINGLE and %PSPP_SHEET_SELECTION_BROWSE.
12713 pspp_sheet_view_set_hover_selection (PsppSheetView *tree_view,
12716 hover = hover != FALSE;
12718 if (hover != tree_view->priv->hover_selection)
12720 tree_view->priv->hover_selection = hover;
12722 g_object_notify (G_OBJECT (tree_view), "hover-selection");
12727 * pspp_sheet_view_get_hover_selection:
12728 * @tree_view: a #PsppSheetView
12730 * Returns whether hover selection mode is turned on for @tree_view.
12732 * Return value: %TRUE if @tree_view is in hover selection mode
12737 pspp_sheet_view_get_hover_selection (PsppSheetView *tree_view)
12739 return tree_view->priv->hover_selection;
12743 * pspp_sheet_view_set_rubber_banding:
12744 * @tree_view: a #PsppSheetView
12745 * @enable: %TRUE to enable rubber banding
12747 * Enables or disables rubber banding in @tree_view. If the selection mode is
12748 * #PSPP_SHEET_SELECTION_MULTIPLE or #PSPP_SHEET_SELECTION_RECTANGLE, rubber
12749 * banding will allow the user to select multiple rows by dragging the mouse.
12754 pspp_sheet_view_set_rubber_banding (PsppSheetView *tree_view,
12757 enable = enable != FALSE;
12759 if (enable != tree_view->priv->rubber_banding_enable)
12761 tree_view->priv->rubber_banding_enable = enable;
12763 g_object_notify (G_OBJECT (tree_view), "rubber-banding");
12768 * pspp_sheet_view_get_rubber_banding:
12769 * @tree_view: a #PsppSheetView
12771 * Returns whether rubber banding is turned on for @tree_view. If the
12772 * selection mode is #PSPP_SHEET_SELECTION_MULTIPLE or
12773 * #PSPP_SHEET_SELECTION_RECTANGLE, rubber banding will allow the user to
12774 * select multiple rows by dragging the mouse.
12776 * Return value: %TRUE if rubber banding in @tree_view is enabled.
12781 pspp_sheet_view_get_rubber_banding (PsppSheetView *tree_view)
12783 return tree_view->priv->rubber_banding_enable;
12787 * pspp_sheet_view_is_rubber_banding_active:
12788 * @tree_view: a #PsppSheetView
12790 * Returns whether a rubber banding operation is currently being done
12793 * Return value: %TRUE if a rubber banding operation is currently being
12794 * done in @tree_view.
12799 pspp_sheet_view_is_rubber_banding_active (PsppSheetView *tree_view)
12801 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
12803 if (tree_view->priv->rubber_banding_enable
12804 && tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
12811 pspp_sheet_view_grab_notify (GtkWidget *widget,
12812 gboolean was_grabbed)
12814 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12816 tree_view->priv->in_grab = !was_grabbed;
12820 tree_view->priv->pressed_button = -1;
12822 if (tree_view->priv->rubber_band_status)
12823 pspp_sheet_view_stop_rubber_band (tree_view);
12828 pspp_sheet_view_state_changed (GtkWidget *widget,
12829 GtkStateType previous_state)
12831 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12833 if (gtk_widget_get_realized (widget))
12835 GtkStyle *style = gtk_widget_get_style (widget);
12836 gdk_window_set_background (tree_view->priv->bin_window, &style->base[gtk_widget_get_state (widget)]);
12839 gtk_widget_queue_draw (widget);
12843 * pspp_sheet_view_get_grid_lines:
12844 * @tree_view: a #PsppSheetView
12846 * Returns which grid lines are enabled in @tree_view.
12848 * Return value: a #PsppSheetViewGridLines value indicating which grid lines
12853 PsppSheetViewGridLines
12854 pspp_sheet_view_get_grid_lines (PsppSheetView *tree_view)
12856 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12858 return tree_view->priv->grid_lines;
12862 * pspp_sheet_view_set_grid_lines:
12863 * @tree_view: a #PsppSheetView
12864 * @grid_lines: a #PsppSheetViewGridLines value indicating which grid lines to
12867 * Sets which grid lines to draw in @tree_view.
12872 pspp_sheet_view_set_grid_lines (PsppSheetView *tree_view,
12873 PsppSheetViewGridLines grid_lines)
12875 PsppSheetViewPrivate *priv;
12876 PsppSheetViewGridLines old_grid_lines;
12878 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12880 priv = tree_view->priv;
12882 old_grid_lines = priv->grid_lines;
12883 priv->grid_lines = grid_lines;
12885 if (old_grid_lines != grid_lines)
12887 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12889 g_object_notify (G_OBJECT (tree_view), "enable-grid-lines");
12894 * pspp_sheet_view_get_special_cells:
12895 * @tree_view: a #PsppSheetView
12897 * Returns which grid lines are enabled in @tree_view.
12899 * Return value: a #PsppSheetViewSpecialCells value indicating whether rows in
12900 * the sheet view contain special cells.
12902 PsppSheetViewSpecialCells
12903 pspp_sheet_view_get_special_cells (PsppSheetView *tree_view)
12905 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12907 return tree_view->priv->special_cells;
12911 * pspp_sheet_view_set_special_cells:
12912 * @tree_view: a #PsppSheetView
12913 * @special_cells: a #PsppSheetViewSpecialCells value indicating whether rows in
12914 * the sheet view contain special cells.
12916 * Sets whether rows in the sheet view contain special cells, controlling the
12917 * rendering of row selections.
12920 pspp_sheet_view_set_special_cells (PsppSheetView *tree_view,
12921 PsppSheetViewSpecialCells special_cells)
12923 PsppSheetViewPrivate *priv;
12925 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12927 priv = tree_view->priv;
12929 if (priv->special_cells != special_cells)
12931 priv->special_cells = special_cells;
12932 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12933 g_object_notify (G_OBJECT (tree_view), "special-cells");
12938 pspp_sheet_view_get_fixed_height (const PsppSheetView *tree_view)
12940 /* XXX (re)calculate fixed_height if necessary */
12941 return tree_view->priv->fixed_height;
12945 pspp_sheet_view_set_fixed_height (PsppSheetView *tree_view,
12948 g_return_if_fail (fixed_height > 0);
12950 if (tree_view->priv->fixed_height != fixed_height)
12952 tree_view->priv->fixed_height = fixed_height;
12953 g_object_notify (G_OBJECT (tree_view), "fixed-height");
12955 if (!tree_view->priv->fixed_height_set)
12957 tree_view->priv->fixed_height_set = TRUE;
12958 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
12963 * pspp_sheet_view_set_tooltip_row:
12964 * @tree_view: a #PsppSheetView
12965 * @tooltip: a #GtkTooltip
12966 * @path: a #GtkTreePath
12968 * Sets the tip area of @tooltip to be the area covered by the row at @path.
12969 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
12970 * See also gtk_tooltip_set_tip_area().
12975 pspp_sheet_view_set_tooltip_row (PsppSheetView *tree_view,
12976 GtkTooltip *tooltip,
12979 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12980 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
12982 pspp_sheet_view_set_tooltip_cell (tree_view, tooltip, path, NULL, NULL);
12986 * pspp_sheet_view_set_tooltip_cell:
12987 * @tree_view: a #PsppSheetView
12988 * @tooltip: a #GtkTooltip
12989 * @path: (allow-none): a #GtkTreePath or %NULL
12990 * @column: (allow-none): a #PsppSheetViewColumn or %NULL
12991 * @cell: (allow-none): a #GtkCellRenderer or %NULL
12993 * Sets the tip area of @tooltip to the area @path, @column and @cell have
12994 * in common. For example if @path is %NULL and @column is set, the tip
12995 * area will be set to the full area covered by @column. See also
12996 * gtk_tooltip_set_tip_area().
12998 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
13003 pspp_sheet_view_set_tooltip_cell (PsppSheetView *tree_view,
13004 GtkTooltip *tooltip,
13006 PsppSheetViewColumn *column,
13007 GtkCellRenderer *cell)
13011 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
13012 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
13013 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
13014 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
13016 /* Determine x values. */
13017 if (column && cell)
13022 pspp_sheet_view_get_cell_area (tree_view, path, column, &tmp);
13023 pspp_sheet_view_column_cell_get_position (column, cell, &start, &width);
13025 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
13028 rect.width = width;
13034 pspp_sheet_view_get_background_area (tree_view, NULL, column, &tmp);
13035 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
13038 rect.width = tmp.width;
13042 GtkAllocation allocation;
13043 gtk_widget_get_allocation (GTK_WIDGET (tree_view), &allocation);
13045 rect.width = allocation.width;
13048 /* Determine y values. */
13053 pspp_sheet_view_get_background_area (tree_view, path, NULL, &tmp);
13054 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
13057 rect.height = tmp.height;
13062 rect.height = gtk_adjustment_get_page_size (tree_view->priv->vadjustment);
13065 gtk_tooltip_set_tip_area (tooltip, &rect);
13069 * pspp_sheet_view_get_tooltip_context:
13070 * @tree_view: a #PsppSheetView
13071 * @x: the x coordinate (relative to widget coordinates)
13072 * @y: the y coordinate (relative to widget coordinates)
13073 * @keyboard_tip: whether this is a keyboard tooltip or not
13074 * @model: (allow-none): a pointer to receive a #GtkTreeModel or %NULL
13075 * @path: (allow-none): a pointer to receive a #GtkTreePath or %NULL
13076 * @iter: (allow-none): a pointer to receive a #GtkTreeIter or %NULL
13078 * This function is supposed to be used in a #GtkWidget::query-tooltip
13079 * signal handler for #PsppSheetView. The @x, @y and @keyboard_tip values
13080 * which are received in the signal handler, should be passed to this
13081 * function without modification.
13083 * The return value indicates whether there is a tree view row at the given
13084 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
13085 * tooltips the row returned will be the cursor row. When %TRUE, then any of
13086 * @model, @path and @iter which have been provided will be set to point to
13087 * that row and the corresponding model. @x and @y will always be converted
13088 * to be relative to @tree_view's bin_window if @keyboard_tooltip is %FALSE.
13090 * Return value: whether or not the given tooltip context points to a row.
13095 pspp_sheet_view_get_tooltip_context (PsppSheetView *tree_view,
13098 gboolean keyboard_tip,
13099 GtkTreeModel **model,
13100 GtkTreePath **path,
13103 GtkTreePath *tmppath = NULL;
13105 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
13106 g_return_val_if_fail (x != NULL, FALSE);
13107 g_return_val_if_fail (y != NULL, FALSE);
13111 pspp_sheet_view_get_cursor (tree_view, &tmppath, NULL);
13118 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, *x, *y,
13121 if (!pspp_sheet_view_get_path_at_pos (tree_view, *x, *y,
13122 &tmppath, NULL, NULL, NULL))
13127 *model = pspp_sheet_view_get_model (tree_view);
13130 gtk_tree_model_get_iter (pspp_sheet_view_get_model (tree_view),
13136 gtk_tree_path_free (tmppath);
13142 pspp_sheet_view_set_tooltip_query_cb (GtkWidget *widget,
13145 gboolean keyboard_tip,
13146 GtkTooltip *tooltip,
13149 GValue value = { 0, };
13150 GValue transformed = { 0, };
13153 GtkTreeModel *model;
13154 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
13156 if (!pspp_sheet_view_get_tooltip_context (PSPP_SHEET_VIEW (widget),
13159 &model, &path, &iter))
13162 gtk_tree_model_get_value (model, &iter,
13163 tree_view->priv->tooltip_column, &value);
13165 g_value_init (&transformed, G_TYPE_STRING);
13167 if (!g_value_transform (&value, &transformed))
13169 g_value_unset (&value);
13170 gtk_tree_path_free (path);
13175 g_value_unset (&value);
13177 if (!g_value_get_string (&transformed))
13179 g_value_unset (&transformed);
13180 gtk_tree_path_free (path);
13185 gtk_tooltip_set_markup (tooltip, g_value_get_string (&transformed));
13186 pspp_sheet_view_set_tooltip_row (tree_view, tooltip, path);
13188 gtk_tree_path_free (path);
13189 g_value_unset (&transformed);
13195 * pspp_sheet_view_set_tooltip_column:
13196 * @tree_view: a #PsppSheetView
13197 * @column: an integer, which is a valid column number for @tree_view's model
13199 * If you only plan to have simple (text-only) tooltips on full rows, you
13200 * can use this function to have #PsppSheetView handle these automatically
13201 * for you. @column should be set to the column in @tree_view's model
13202 * containing the tooltip texts, or -1 to disable this feature.
13204 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
13205 * @tree_view will connect a #GtkWidget::query-tooltip signal handler.
13207 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
13208 * so &, <, etc have to be escaped in the text.
13213 pspp_sheet_view_set_tooltip_column (PsppSheetView *tree_view,
13216 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
13218 if (column == tree_view->priv->tooltip_column)
13223 g_signal_handlers_disconnect_by_func (tree_view,
13224 pspp_sheet_view_set_tooltip_query_cb,
13226 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), FALSE);
13230 if (tree_view->priv->tooltip_column == -1)
13232 g_signal_connect (tree_view, "query-tooltip",
13233 G_CALLBACK (pspp_sheet_view_set_tooltip_query_cb), NULL);
13234 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), TRUE);
13238 tree_view->priv->tooltip_column = column;
13239 g_object_notify (G_OBJECT (tree_view), "tooltip-column");
13243 * pspp_sheet_view_get_tooltip_column:
13244 * @tree_view: a #PsppSheetView
13246 * Returns the column of @tree_view's model which is being used for
13247 * displaying tooltips on @tree_view's rows.
13249 * Return value: the index of the tooltip column that is currently being
13250 * used, or -1 if this is disabled.
13255 pspp_sheet_view_get_tooltip_column (PsppSheetView *tree_view)
13257 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
13259 return tree_view->priv->tooltip_column;
13263 _gtk_boolean_handled_accumulator (GSignalInvocationHint *ihint,
13264 GValue *return_accu,
13265 const GValue *handler_return,
13268 gboolean continue_emission;
13269 gboolean signal_handled;
13271 signal_handled = g_value_get_boolean (handler_return);
13272 g_value_set_boolean (return_accu, signal_handled);
13273 continue_emission = !signal_handled;
13275 return continue_emission;
13280 pspp_sheet_view_grid_lines_get_type (void)
13282 static GType etype = 0;
13283 if (G_UNLIKELY(etype == 0)) {
13284 static const GEnumValue values[] = {
13285 { PSPP_SHEET_VIEW_GRID_LINES_NONE, "PSPP_SHEET_VIEW_GRID_LINES_NONE", "none" },
13286 { PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL, "PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL", "horizontal" },
13287 { PSPP_SHEET_VIEW_GRID_LINES_VERTICAL, "PSPP_SHEET_VIEW_GRID_LINES_VERTICAL", "vertical" },
13288 { PSPP_SHEET_VIEW_GRID_LINES_BOTH, "PSPP_SHEET_VIEW_GRID_LINES_BOTH", "both" },
13291 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewGridLines"), values);
13297 pspp_sheet_view_special_cells_get_type (void)
13299 static GType etype = 0;
13300 if (G_UNLIKELY(etype == 0)) {
13301 static const GEnumValue values[] = {
13302 { PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT, "PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT", "detect" },
13303 { PSPP_SHEET_VIEW_SPECIAL_CELLS_YES, "PSPP_SHEET_VIEW_SPECIAL_CELLS_YES", "yes" },
13304 { PSPP_SHEET_VIEW_SPECIAL_CELLS_NO, "PSPP_SHEET_VIEW_SPECIAL_CELLS_NO", "no" },
13307 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewSpecialCells"), values);