1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2011, 2012 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 * Copyright (C) 2000 Red Hat, Inc., Jonathan Blandford <jrb@redhat.com>
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Library General Public
22 * License as published by the Free Software Foundation; either
23 * version 2 of the License, or (at your option) any later version.
25 * This library is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 * Library General Public License for more details.
30 * You should have received a copy of the GNU Library General Public
31 * License along with this library; if not, write to the
32 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
33 * Boston, MA 02111-1307, USA.
38 #include "ui/gui/pspp-sheet-private.h"
42 #include <gdk/gdkkeysyms.h>
45 #include "ui/gui/psppire-marshal.h"
46 #include "ui/gui/pspp-sheet-selection.h"
48 #define P_(STRING) STRING
49 #define GTK_PARAM_READABLE G_PARAM_READABLE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
50 #define GTK_PARAM_READWRITE G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
52 /* Many keyboard shortcuts for Mac are the same as for X
53 * except they use Command key instead of Control (e.g. Cut,
54 * Copy, Paste). This symbol is for those simple cases. */
55 #ifndef GDK_WINDOWING_QUARTZ
56 #define GTK_DEFAULT_ACCEL_MOD_MASK GDK_CONTROL_MASK
58 #define GTK_DEFAULT_ACCEL_MOD_MASK GDK_META_MASK
61 #define PSPP_SHEET_VIEW_PRIORITY_VALIDATE (GDK_PRIORITY_REDRAW + 5)
62 #define PSPP_SHEET_VIEW_PRIORITY_SCROLL_SYNC (PSPP_SHEET_VIEW_PRIORITY_VALIDATE + 2)
63 #define PSPP_SHEET_VIEW_TIME_MS_PER_IDLE 30
64 #define SCROLL_EDGE_SIZE 15
65 #define EXPANDER_EXTRA_PADDING 4
66 #define PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT 5000
68 /* The "background" areas of all rows/cells add up to cover the entire tree.
69 * The background includes all inter-row and inter-cell spacing.
70 * The "cell" areas are the cell_area passed in to gtk_cell_renderer_render(),
71 * i.e. just the cells, no spacing.
74 #define BACKGROUND_HEIGHT(tree_view) (tree_view->priv->fixed_height)
75 #define CELL_HEIGHT(tree_view, separator) ((BACKGROUND_HEIGHT (tree_view)) - (separator))
77 /* Translate from bin_window coordinates to rbtree (tree coordinates) and
80 #define TREE_WINDOW_Y_TO_RBTREE_Y(tree_view,y) ((y) + tree_view->priv->dy)
81 #define RBTREE_Y_TO_TREE_WINDOW_Y(tree_view,y) ((y) - tree_view->priv->dy)
83 /* This is in bin_window coordinates */
84 #define BACKGROUND_FIRST_PIXEL(tree_view,node) (RBTREE_Y_TO_TREE_WINDOW_Y (tree_view, pspp_sheet_view_node_find_offset (tree_view, (node))))
85 #define CELL_FIRST_PIXEL(tree_view,node,separator) (BACKGROUND_FIRST_PIXEL (tree_view,node) + separator/2)
87 #define ROW_HEIGHT(tree_view) \
88 ((tree_view->priv->fixed_height > 0) ? (tree_view->priv->fixed_height) : (tree_view)->priv->expander_size)
91 typedef struct _PsppSheetViewChild PsppSheetViewChild;
92 struct _PsppSheetViewChild
102 typedef struct _TreeViewDragInfo TreeViewDragInfo;
103 struct _TreeViewDragInfo
105 GdkModifierType start_button_mask;
106 GtkTargetList *_unused_source_target_list;
107 GdkDragAction source_actions;
109 GtkTargetList *_unused_dest_target_list;
111 guint source_set : 1;
127 START_INTERACTIVE_SEARCH,
137 PROP_HEADERS_VISIBLE,
138 PROP_HEADERS_CLICKABLE,
143 PROP_HOVER_SELECTION,
145 PROP_ENABLE_GRID_LINES,
149 PROP_FIXED_HEIGHT_SET
153 static void pspp_sheet_view_finalize (GObject *object);
154 static void pspp_sheet_view_set_property (GObject *object,
158 static void pspp_sheet_view_get_property (GObject *object,
163 static void pspp_sheet_view_dispose (GObject *object);
165 /* gtkwidget signals */
166 static void pspp_sheet_view_realize (GtkWidget *widget);
167 static void pspp_sheet_view_unrealize (GtkWidget *widget);
168 static void pspp_sheet_view_map (GtkWidget *widget);
169 static void pspp_sheet_view_size_request (GtkWidget *widget,
170 GtkRequisition *requisition);
171 static void pspp_sheet_view_size_allocate (GtkWidget *widget,
172 GtkAllocation *allocation);
173 static gboolean pspp_sheet_view_expose (GtkWidget *widget,
174 GdkEventExpose *event);
175 static gboolean pspp_sheet_view_key_press (GtkWidget *widget,
177 static gboolean pspp_sheet_view_key_release (GtkWidget *widget,
179 static gboolean pspp_sheet_view_motion (GtkWidget *widget,
180 GdkEventMotion *event);
181 static gboolean pspp_sheet_view_enter_notify (GtkWidget *widget,
182 GdkEventCrossing *event);
183 static gboolean pspp_sheet_view_leave_notify (GtkWidget *widget,
184 GdkEventCrossing *event);
185 static gboolean pspp_sheet_view_button_press (GtkWidget *widget,
186 GdkEventButton *event);
187 static gboolean pspp_sheet_view_button_release (GtkWidget *widget,
188 GdkEventButton *event);
189 static gboolean pspp_sheet_view_grab_broken (GtkWidget *widget,
190 GdkEventGrabBroken *event);
192 static void pspp_sheet_view_set_focus_child (GtkContainer *container,
194 static gint pspp_sheet_view_focus_out (GtkWidget *widget,
195 GdkEventFocus *event);
196 static gint pspp_sheet_view_focus (GtkWidget *widget,
197 GtkDirectionType direction);
198 static void pspp_sheet_view_grab_focus (GtkWidget *widget);
199 static void pspp_sheet_view_style_set (GtkWidget *widget,
200 GtkStyle *previous_style);
201 static void pspp_sheet_view_grab_notify (GtkWidget *widget,
202 gboolean was_grabbed);
203 static void pspp_sheet_view_state_changed (GtkWidget *widget,
204 GtkStateType previous_state);
206 /* container signals */
207 static void pspp_sheet_view_remove (GtkContainer *container,
209 static void pspp_sheet_view_forall (GtkContainer *container,
210 gboolean include_internals,
211 GtkCallback callback,
212 gpointer callback_data);
214 /* Source side drag signals */
215 static void pspp_sheet_view_drag_begin (GtkWidget *widget,
216 GdkDragContext *context);
217 static void pspp_sheet_view_drag_end (GtkWidget *widget,
218 GdkDragContext *context);
219 static void pspp_sheet_view_drag_data_get (GtkWidget *widget,
220 GdkDragContext *context,
221 GtkSelectionData *selection_data,
224 static void pspp_sheet_view_drag_data_delete (GtkWidget *widget,
225 GdkDragContext *context);
227 /* Target side drag signals */
228 static void pspp_sheet_view_drag_leave (GtkWidget *widget,
229 GdkDragContext *context,
231 static gboolean pspp_sheet_view_drag_motion (GtkWidget *widget,
232 GdkDragContext *context,
236 static gboolean pspp_sheet_view_drag_drop (GtkWidget *widget,
237 GdkDragContext *context,
241 static void pspp_sheet_view_drag_data_received (GtkWidget *widget,
242 GdkDragContext *context,
245 GtkSelectionData *selection_data,
249 /* tree_model signals */
250 static void pspp_sheet_view_set_adjustments (PsppSheetView *tree_view,
252 GtkAdjustment *vadj);
253 static gboolean pspp_sheet_view_real_move_cursor (PsppSheetView *tree_view,
254 GtkMovementStep step,
256 static gboolean pspp_sheet_view_real_select_all (PsppSheetView *tree_view);
257 static gboolean pspp_sheet_view_real_unselect_all (PsppSheetView *tree_view);
258 static gboolean pspp_sheet_view_real_select_cursor_row (PsppSheetView *tree_view,
259 gboolean start_editing);
260 static gboolean pspp_sheet_view_real_toggle_cursor_row (PsppSheetView *tree_view);
261 static void pspp_sheet_view_row_changed (GtkTreeModel *model,
265 static void pspp_sheet_view_row_inserted (GtkTreeModel *model,
269 static void pspp_sheet_view_row_deleted (GtkTreeModel *model,
272 static void pspp_sheet_view_rows_reordered (GtkTreeModel *model,
278 /* Incremental reflow */
279 static gint validate_row (PsppSheetView *tree_view,
283 static void validate_visible_area (PsppSheetView *tree_view);
284 static gboolean validate_rows_handler (PsppSheetView *tree_view);
285 static gboolean presize_handler_callback (gpointer data);
286 static void install_presize_handler (PsppSheetView *tree_view);
287 static void install_scroll_sync_handler (PsppSheetView *tree_view);
288 static void pspp_sheet_view_set_top_row (PsppSheetView *tree_view,
291 static void pspp_sheet_view_dy_to_top_row (PsppSheetView *tree_view);
292 static void pspp_sheet_view_top_row_to_dy (PsppSheetView *tree_view);
293 static void invalidate_empty_focus (PsppSheetView *tree_view);
295 /* Internal functions */
296 static void pspp_sheet_view_add_move_binding (GtkBindingSet *binding_set,
299 gboolean add_shifted_binding,
300 GtkMovementStep step,
302 static void pspp_sheet_view_queue_draw_path (PsppSheetView *tree_view,
304 const GdkRectangle *clip_rect);
305 static gint pspp_sheet_view_new_column_width (PsppSheetView *tree_view,
308 static void pspp_sheet_view_adjustment_changed (GtkAdjustment *adjustment,
309 PsppSheetView *tree_view);
310 static void pspp_sheet_view_clamp_node_visible (PsppSheetView *tree_view,
312 static void pspp_sheet_view_clamp_column_visible (PsppSheetView *tree_view,
313 PsppSheetViewColumn *column,
314 gboolean focus_to_cell);
315 static gboolean pspp_sheet_view_maybe_begin_dragging_row (PsppSheetView *tree_view,
316 GdkEventMotion *event);
317 static void pspp_sheet_view_focus_to_cursor (PsppSheetView *tree_view);
318 static void pspp_sheet_view_move_cursor_up_down (PsppSheetView *tree_view,
320 static void pspp_sheet_view_move_cursor_page_up_down (PsppSheetView *tree_view,
322 static void pspp_sheet_view_move_cursor_left_right (PsppSheetView *tree_view,
324 static void pspp_sheet_view_move_cursor_start_end (PsppSheetView *tree_view,
326 static void pspp_sheet_view_real_set_cursor (PsppSheetView *tree_view,
328 gboolean clear_and_select,
329 gboolean clamp_node);
330 static gboolean pspp_sheet_view_has_special_cell (PsppSheetView *tree_view);
331 static void pspp_sheet_view_stop_rubber_band (PsppSheetView *tree_view);
332 static void update_prelight (PsppSheetView *tree_view,
335 static void initialize_fixed_height_mode (PsppSheetView *tree_view);
337 /* interactive search */
338 static void pspp_sheet_view_ensure_interactive_directory (PsppSheetView *tree_view);
339 static void pspp_sheet_view_search_dialog_hide (GtkWidget *search_dialog,
340 PsppSheetView *tree_view);
341 static void pspp_sheet_view_search_position_func (PsppSheetView *tree_view,
342 GtkWidget *search_dialog,
344 static void pspp_sheet_view_search_disable_popdown (GtkEntry *entry,
347 static void pspp_sheet_view_search_preedit_changed (GtkIMContext *im_context,
348 PsppSheetView *tree_view);
349 static void pspp_sheet_view_search_activate (GtkEntry *entry,
350 PsppSheetView *tree_view);
351 static gboolean pspp_sheet_view_real_search_enable_popdown(gpointer data);
352 static void pspp_sheet_view_search_enable_popdown (GtkWidget *widget,
354 static gboolean pspp_sheet_view_search_delete_event (GtkWidget *widget,
356 PsppSheetView *tree_view);
357 static gboolean pspp_sheet_view_search_button_press_event (GtkWidget *widget,
358 GdkEventButton *event,
359 PsppSheetView *tree_view);
360 static gboolean pspp_sheet_view_search_scroll_event (GtkWidget *entry,
361 GdkEventScroll *event,
362 PsppSheetView *tree_view);
363 static gboolean pspp_sheet_view_search_key_press_event (GtkWidget *entry,
365 PsppSheetView *tree_view);
366 static gboolean pspp_sheet_view_search_move (GtkWidget *window,
367 PsppSheetView *tree_view,
369 static gboolean pspp_sheet_view_search_equal_func (GtkTreeModel *model,
373 gpointer search_data);
374 static gboolean pspp_sheet_view_search_iter (GtkTreeModel *model,
375 PsppSheetSelection *selection,
380 static void pspp_sheet_view_search_init (GtkWidget *entry,
381 PsppSheetView *tree_view);
382 static void pspp_sheet_view_put (PsppSheetView *tree_view,
383 GtkWidget *child_widget,
388 static gboolean pspp_sheet_view_start_editing (PsppSheetView *tree_view,
389 GtkTreePath *cursor_path);
390 static gboolean pspp_sheet_view_editable_button_press_event (GtkWidget *,
393 static void pspp_sheet_view_editable_clicked (GtkButton *, PsppSheetView *);
394 static void pspp_sheet_view_real_start_editing (PsppSheetView *tree_view,
395 PsppSheetViewColumn *column,
397 GtkCellEditable *cell_editable,
398 GdkRectangle *cell_area,
401 static gboolean pspp_sheet_view_real_start_interactive_search (PsppSheetView *tree_view,
402 gboolean keybinding);
403 static gboolean pspp_sheet_view_start_interactive_search (PsppSheetView *tree_view);
404 static PsppSheetViewColumn *pspp_sheet_view_get_drop_column (PsppSheetView *tree_view,
405 PsppSheetViewColumn *column,
408 pspp_sheet_view_adjust_cell_area (PsppSheetView *tree_view,
409 PsppSheetViewColumn *column,
410 const GdkRectangle *background_area,
411 gboolean subtract_focus_rect,
412 GdkRectangle *cell_area);
413 static gint pspp_sheet_view_find_offset (PsppSheetView *tree_view,
418 static void pspp_sheet_view_buildable_add_child (GtkBuildable *tree_view,
422 static void pspp_sheet_view_buildable_init (GtkBuildableIface *iface);
425 static gboolean scroll_row_timeout (gpointer data);
426 static void add_scroll_timeout (PsppSheetView *tree_view);
427 static void remove_scroll_timeout (PsppSheetView *tree_view);
429 static guint tree_view_signals [LAST_SIGNAL] = { 0 };
431 static GtkBindingSet *edit_bindings;
438 G_DEFINE_TYPE_WITH_CODE (PsppSheetView, pspp_sheet_view, GTK_TYPE_CONTAINER,
439 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
440 pspp_sheet_view_buildable_init))
443 pspp_sheet_view_class_init (PsppSheetViewClass *class)
445 GObjectClass *o_class;
446 GtkWidgetClass *widget_class;
447 GtkContainerClass *container_class;
448 GtkBindingSet *binding_set[2];
451 binding_set[0] = gtk_binding_set_by_class (class);
453 binding_set[1] = gtk_binding_set_new ("PsppSheetViewEditing");
454 edit_bindings = binding_set[1];
456 o_class = (GObjectClass *) class;
457 widget_class = (GtkWidgetClass *) class;
458 container_class = (GtkContainerClass *) class;
460 /* GObject signals */
461 o_class->set_property = pspp_sheet_view_set_property;
462 o_class->get_property = pspp_sheet_view_get_property;
463 o_class->finalize = pspp_sheet_view_finalize;
464 o_class->dispose = pspp_sheet_view_dispose;
466 /* GtkWidget signals */
467 widget_class->map = pspp_sheet_view_map;
468 widget_class->realize = pspp_sheet_view_realize;
469 widget_class->unrealize = pspp_sheet_view_unrealize;
470 widget_class->size_request = pspp_sheet_view_size_request;
471 widget_class->size_allocate = pspp_sheet_view_size_allocate;
472 widget_class->button_press_event = pspp_sheet_view_button_press;
473 widget_class->button_release_event = pspp_sheet_view_button_release;
474 widget_class->grab_broken_event = pspp_sheet_view_grab_broken;
475 /*widget_class->configure_event = pspp_sheet_view_configure;*/
476 widget_class->motion_notify_event = pspp_sheet_view_motion;
477 widget_class->expose_event = pspp_sheet_view_expose;
478 widget_class->key_press_event = pspp_sheet_view_key_press;
479 widget_class->key_release_event = pspp_sheet_view_key_release;
480 widget_class->enter_notify_event = pspp_sheet_view_enter_notify;
481 widget_class->leave_notify_event = pspp_sheet_view_leave_notify;
482 widget_class->focus_out_event = pspp_sheet_view_focus_out;
483 widget_class->drag_begin = pspp_sheet_view_drag_begin;
484 widget_class->drag_end = pspp_sheet_view_drag_end;
485 widget_class->drag_data_get = pspp_sheet_view_drag_data_get;
486 widget_class->drag_data_delete = pspp_sheet_view_drag_data_delete;
487 widget_class->drag_leave = pspp_sheet_view_drag_leave;
488 widget_class->drag_motion = pspp_sheet_view_drag_motion;
489 widget_class->drag_drop = pspp_sheet_view_drag_drop;
490 widget_class->drag_data_received = pspp_sheet_view_drag_data_received;
491 widget_class->focus = pspp_sheet_view_focus;
492 widget_class->grab_focus = pspp_sheet_view_grab_focus;
493 widget_class->style_set = pspp_sheet_view_style_set;
494 widget_class->grab_notify = pspp_sheet_view_grab_notify;
495 widget_class->state_changed = pspp_sheet_view_state_changed;
497 /* GtkContainer signals */
498 container_class->remove = pspp_sheet_view_remove;
499 container_class->forall = pspp_sheet_view_forall;
500 container_class->set_focus_child = pspp_sheet_view_set_focus_child;
502 class->set_scroll_adjustments = pspp_sheet_view_set_adjustments;
503 class->move_cursor = pspp_sheet_view_real_move_cursor;
504 class->select_all = pspp_sheet_view_real_select_all;
505 class->unselect_all = pspp_sheet_view_real_unselect_all;
506 class->select_cursor_row = pspp_sheet_view_real_select_cursor_row;
507 class->toggle_cursor_row = pspp_sheet_view_real_toggle_cursor_row;
508 class->start_interactive_search = pspp_sheet_view_start_interactive_search;
512 g_object_class_install_property (o_class,
514 g_param_spec_object ("model",
515 P_("TreeView Model"),
516 P_("The model for the tree view"),
518 GTK_PARAM_READWRITE));
520 g_object_class_install_property (o_class,
522 g_param_spec_object ("hadjustment",
523 P_("Horizontal Adjustment"),
524 P_("Horizontal Adjustment for the widget"),
526 GTK_PARAM_READWRITE));
528 g_object_class_install_property (o_class,
530 g_param_spec_object ("vadjustment",
531 P_("Vertical Adjustment"),
532 P_("Vertical Adjustment for the widget"),
534 GTK_PARAM_READWRITE));
536 g_object_class_install_property (o_class,
537 PROP_HEADERS_VISIBLE,
538 g_param_spec_boolean ("headers-visible",
539 P_("Headers Visible"),
540 P_("Show the column header buttons"),
542 GTK_PARAM_READWRITE));
544 g_object_class_install_property (o_class,
545 PROP_HEADERS_CLICKABLE,
546 g_param_spec_boolean ("headers-clickable",
547 P_("Headers Clickable"),
548 P_("Column headers respond to click events"),
550 GTK_PARAM_READWRITE));
552 g_object_class_install_property (o_class,
554 g_param_spec_boolean ("reorderable",
556 P_("View is reorderable"),
558 GTK_PARAM_READWRITE));
560 g_object_class_install_property (o_class,
562 g_param_spec_boolean ("rules-hint",
564 P_("Set a hint to the theme engine to draw rows in alternating colors"),
566 GTK_PARAM_READWRITE));
568 g_object_class_install_property (o_class,
570 g_param_spec_boolean ("enable-search",
572 P_("View allows user to search through columns interactively"),
574 GTK_PARAM_READWRITE));
576 g_object_class_install_property (o_class,
578 g_param_spec_int ("search-column",
580 P_("Model column to search through during interactive search"),
584 GTK_PARAM_READWRITE));
587 * PsppSheetView:hover-selection:
589 * Enables of disables the hover selection mode of @tree_view.
590 * Hover selection makes the selected row follow the pointer.
591 * Currently, this works only for the selection modes
592 * %PSPP_SHEET_SELECTION_SINGLE and %PSPP_SHEET_SELECTION_BROWSE.
594 * This mode is primarily intended for treeviews in popups, e.g.
595 * in #GtkComboBox or #GtkEntryCompletion.
599 g_object_class_install_property (o_class,
600 PROP_HOVER_SELECTION,
601 g_param_spec_boolean ("hover-selection",
602 P_("Hover Selection"),
603 P_("Whether the selection should follow the pointer"),
605 GTK_PARAM_READWRITE));
607 g_object_class_install_property (o_class,
609 g_param_spec_boolean ("rubber-banding",
610 P_("Rubber Banding"),
611 P_("Whether to enable selection of multiple items by dragging the mouse pointer"),
613 GTK_PARAM_READWRITE));
615 g_object_class_install_property (o_class,
616 PROP_ENABLE_GRID_LINES,
617 g_param_spec_enum ("enable-grid-lines",
618 P_("Enable Grid Lines"),
619 P_("Whether grid lines should be drawn in the tree view"),
620 PSPP_TYPE_SHEET_VIEW_GRID_LINES,
621 PSPP_SHEET_VIEW_GRID_LINES_NONE,
622 GTK_PARAM_READWRITE));
624 g_object_class_install_property (o_class,
626 g_param_spec_int ("tooltip-column",
627 P_("Tooltip Column"),
628 P_("The column in the model containing the tooltip texts for the rows"),
632 GTK_PARAM_READWRITE));
634 g_object_class_install_property (o_class,
636 g_param_spec_enum ("special-cells",
638 P_("Whether rows have special cells."),
639 PSPP_TYPE_SHEET_VIEW_SPECIAL_CELLS,
640 PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT,
641 GTK_PARAM_READWRITE));
643 g_object_class_install_property (o_class,
645 g_param_spec_int ("fixed-height",
647 P_("Height of a single row. Normally the height of a row is determined automatically. Writing this property sets fixed-height-set to true, preventing this property's value from changing."),
651 GTK_PARAM_READWRITE));
653 g_object_class_install_property (o_class,
654 PROP_FIXED_HEIGHT_SET,
655 g_param_spec_boolean ("fixed-height-set",
656 P_("Fixed Height Set"),
657 P_("Whether fixed-height was set externally."),
659 GTK_PARAM_READWRITE));
661 /* Style properties */
662 #define _TREE_VIEW_EXPANDER_SIZE 12
663 #define _TREE_VIEW_VERTICAL_SEPARATOR 2
664 #define _TREE_VIEW_HORIZONTAL_SEPARATOR 2
666 gtk_widget_class_install_style_property (widget_class,
667 g_param_spec_int ("expander-size",
669 P_("Size of the expander arrow"),
672 _TREE_VIEW_EXPANDER_SIZE,
673 GTK_PARAM_READABLE));
675 gtk_widget_class_install_style_property (widget_class,
676 g_param_spec_int ("vertical-separator",
677 P_("Vertical Separator Width"),
678 P_("Vertical space between cells. Must be an even number"),
681 _TREE_VIEW_VERTICAL_SEPARATOR,
682 GTK_PARAM_READABLE));
684 gtk_widget_class_install_style_property (widget_class,
685 g_param_spec_int ("horizontal-separator",
686 P_("Horizontal Separator Width"),
687 P_("Horizontal space between cells. Must be an even number"),
690 _TREE_VIEW_HORIZONTAL_SEPARATOR,
691 GTK_PARAM_READABLE));
693 gtk_widget_class_install_style_property (widget_class,
694 g_param_spec_boolean ("allow-rules",
696 P_("Allow drawing of alternating color rows"),
698 GTK_PARAM_READABLE));
700 gtk_widget_class_install_style_property (widget_class,
701 g_param_spec_boxed ("even-row-color",
702 P_("Even Row Color"),
703 P_("Color to use for even rows"),
705 GTK_PARAM_READABLE));
707 gtk_widget_class_install_style_property (widget_class,
708 g_param_spec_boxed ("odd-row-color",
710 P_("Color to use for odd rows"),
712 GTK_PARAM_READABLE));
714 gtk_widget_class_install_style_property (widget_class,
715 g_param_spec_boolean ("row-ending-details",
716 P_("Row Ending details"),
717 P_("Enable extended row background theming"),
719 GTK_PARAM_READABLE));
721 gtk_widget_class_install_style_property (widget_class,
722 g_param_spec_int ("grid-line-width",
723 P_("Grid line width"),
724 P_("Width, in pixels, of the tree view grid lines"),
726 GTK_PARAM_READABLE));
728 gtk_widget_class_install_style_property (widget_class,
729 g_param_spec_int ("tree-line-width",
730 P_("Tree line width"),
731 P_("Width, in pixels, of the tree view lines"),
733 GTK_PARAM_READABLE));
735 gtk_widget_class_install_style_property (widget_class,
736 g_param_spec_string ("tree-line-pattern",
737 P_("Tree line pattern"),
738 P_("Dash pattern used to draw the tree view lines"),
740 GTK_PARAM_READABLE));
744 * PsppSheetView::set-scroll-adjustments
745 * @horizontal: the horizontal #GtkAdjustment
746 * @vertical: the vertical #GtkAdjustment
748 * Set the scroll adjustments for the tree view. Usually scrolled containers
749 * like #GtkScrolledWindow will emit this signal to connect two instances
750 * of #GtkScrollbar to the scroll directions of the #PsppSheetView.
752 widget_class->set_scroll_adjustments_signal =
753 g_signal_new ("set-scroll-adjustments",
754 G_TYPE_FROM_CLASS (o_class),
755 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
756 G_STRUCT_OFFSET (PsppSheetViewClass, set_scroll_adjustments),
758 psppire_marshal_VOID__OBJECT_OBJECT,
761 GTK_TYPE_ADJUSTMENT);
764 * PsppSheetView::row-activated:
765 * @tree_view: the object on which the signal is emitted
766 * @path: the #GtkTreePath for the activated row
767 * @column: the #PsppSheetViewColumn in which the activation occurred
769 * The "row-activated" signal is emitted when the method
770 * pspp_sheet_view_row_activated() is called or the user double clicks
771 * a treeview row. It is also emitted when a non-editable row is
772 * selected and one of the keys: Space, Shift+Space, Return or
775 * For selection handling refer to the <link linkend="TreeWidget">tree
776 * widget conceptual overview</link> as well as #PsppSheetSelection.
778 tree_view_signals[ROW_ACTIVATED] =
779 g_signal_new ("row-activated",
780 G_TYPE_FROM_CLASS (o_class),
781 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
782 G_STRUCT_OFFSET (PsppSheetViewClass, row_activated),
784 psppire_marshal_VOID__BOXED_OBJECT,
787 PSPP_TYPE_SHEET_VIEW_COLUMN);
790 * PsppSheetView::columns-changed:
791 * @tree_view: the object on which the signal is emitted
793 * The number of columns of the treeview has changed.
795 tree_view_signals[COLUMNS_CHANGED] =
796 g_signal_new ("columns-changed",
797 G_TYPE_FROM_CLASS (o_class),
799 G_STRUCT_OFFSET (PsppSheetViewClass, columns_changed),
801 g_cclosure_marshal_VOID__VOID,
805 * PsppSheetView::cursor-changed:
806 * @tree_view: the object on which the signal is emitted
808 * The position of the cursor (focused cell) has changed.
810 tree_view_signals[CURSOR_CHANGED] =
811 g_signal_new ("cursor-changed",
812 G_TYPE_FROM_CLASS (o_class),
814 G_STRUCT_OFFSET (PsppSheetViewClass, cursor_changed),
816 g_cclosure_marshal_VOID__VOID,
819 tree_view_signals[MOVE_CURSOR] =
820 g_signal_new ("move-cursor",
821 G_TYPE_FROM_CLASS (o_class),
822 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
823 G_STRUCT_OFFSET (PsppSheetViewClass, move_cursor),
825 psppire_marshal_BOOLEAN__ENUM_INT,
827 GTK_TYPE_MOVEMENT_STEP,
830 tree_view_signals[SELECT_ALL] =
831 g_signal_new ("select-all",
832 G_TYPE_FROM_CLASS (o_class),
833 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
834 G_STRUCT_OFFSET (PsppSheetViewClass, select_all),
836 psppire_marshal_BOOLEAN__VOID,
839 tree_view_signals[UNSELECT_ALL] =
840 g_signal_new ("unselect-all",
841 G_TYPE_FROM_CLASS (o_class),
842 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
843 G_STRUCT_OFFSET (PsppSheetViewClass, unselect_all),
845 psppire_marshal_BOOLEAN__VOID,
848 tree_view_signals[SELECT_CURSOR_ROW] =
849 g_signal_new ("select-cursor-row",
850 G_TYPE_FROM_CLASS (o_class),
851 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
852 G_STRUCT_OFFSET (PsppSheetViewClass, select_cursor_row),
854 psppire_marshal_BOOLEAN__BOOLEAN,
858 tree_view_signals[TOGGLE_CURSOR_ROW] =
859 g_signal_new ("toggle-cursor-row",
860 G_TYPE_FROM_CLASS (o_class),
861 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
862 G_STRUCT_OFFSET (PsppSheetViewClass, toggle_cursor_row),
864 psppire_marshal_BOOLEAN__VOID,
867 tree_view_signals[START_INTERACTIVE_SEARCH] =
868 g_signal_new ("start-interactive-search",
869 G_TYPE_FROM_CLASS (o_class),
870 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
871 G_STRUCT_OFFSET (PsppSheetViewClass, start_interactive_search),
873 psppire_marshal_BOOLEAN__VOID,
877 for (i = 0; i < 2; i++)
879 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Up, 0, TRUE,
880 GTK_MOVEMENT_DISPLAY_LINES, -1);
881 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Up, 0, TRUE,
882 GTK_MOVEMENT_DISPLAY_LINES, -1);
884 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Down, 0, TRUE,
885 GTK_MOVEMENT_DISPLAY_LINES, 1);
886 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Down, 0, TRUE,
887 GTK_MOVEMENT_DISPLAY_LINES, 1);
889 pspp_sheet_view_add_move_binding (binding_set[i], GDK_p, GDK_CONTROL_MASK, FALSE,
890 GTK_MOVEMENT_DISPLAY_LINES, -1);
892 pspp_sheet_view_add_move_binding (binding_set[i], GDK_n, GDK_CONTROL_MASK, FALSE,
893 GTK_MOVEMENT_DISPLAY_LINES, 1);
895 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Home, 0, TRUE,
896 GTK_MOVEMENT_BUFFER_ENDS, -1);
897 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Home, 0, TRUE,
898 GTK_MOVEMENT_BUFFER_ENDS, -1);
900 pspp_sheet_view_add_move_binding (binding_set[i], GDK_End, 0, TRUE,
901 GTK_MOVEMENT_BUFFER_ENDS, 1);
902 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_End, 0, TRUE,
903 GTK_MOVEMENT_BUFFER_ENDS, 1);
905 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Page_Up, 0, TRUE,
906 GTK_MOVEMENT_PAGES, -1);
907 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Page_Up, 0, TRUE,
908 GTK_MOVEMENT_PAGES, -1);
910 pspp_sheet_view_add_move_binding (binding_set[i], GDK_Page_Down, 0, TRUE,
911 GTK_MOVEMENT_PAGES, 1);
912 pspp_sheet_view_add_move_binding (binding_set[i], GDK_KP_Page_Down, 0, TRUE,
913 GTK_MOVEMENT_PAGES, 1);
916 gtk_binding_entry_add_signal (binding_set[i], GDK_Right, 0, "move-cursor", 2,
917 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
920 gtk_binding_entry_add_signal (binding_set[i], GDK_Left, 0, "move-cursor", 2,
921 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
924 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Right, 0, "move-cursor", 2,
925 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
928 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Left, 0, "move-cursor", 2,
929 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
932 gtk_binding_entry_add_signal (binding_set[i], GDK_Right, GDK_CONTROL_MASK,
934 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
937 gtk_binding_entry_add_signal (binding_set[i], GDK_Left, GDK_CONTROL_MASK,
939 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
942 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Right, GDK_CONTROL_MASK,
944 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
947 gtk_binding_entry_add_signal (binding_set[i], GDK_KP_Left, GDK_CONTROL_MASK,
949 G_TYPE_ENUM, GTK_MOVEMENT_VISUAL_POSITIONS,
952 gtk_binding_entry_add_signal (binding_set[i], GDK_f, GDK_CONTROL_MASK, "start-interactive-search", 0);
954 gtk_binding_entry_add_signal (binding_set[i], GDK_F, GDK_CONTROL_MASK, "start-interactive-search", 0);
957 gtk_binding_entry_add_signal (binding_set[0], GDK_space, GDK_CONTROL_MASK, "toggle-cursor-row", 0);
958 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Space, GDK_CONTROL_MASK, "toggle-cursor-row", 0);
960 gtk_binding_entry_add_signal (binding_set[0], GDK_a, GDK_CONTROL_MASK, "select-all", 0);
961 gtk_binding_entry_add_signal (binding_set[0], GDK_slash, GDK_CONTROL_MASK, "select-all", 0);
963 gtk_binding_entry_add_signal (binding_set[0], GDK_A, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "unselect-all", 0);
964 gtk_binding_entry_add_signal (binding_set[0], GDK_backslash, GDK_CONTROL_MASK, "unselect-all", 0);
966 gtk_binding_entry_add_signal (binding_set[0], GDK_space, GDK_SHIFT_MASK, "select-cursor-row", 1,
967 G_TYPE_BOOLEAN, TRUE);
968 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Space, GDK_SHIFT_MASK, "select-cursor-row", 1,
969 G_TYPE_BOOLEAN, TRUE);
971 gtk_binding_entry_add_signal (binding_set[0], GDK_space, 0, "select-cursor-row", 1,
972 G_TYPE_BOOLEAN, TRUE);
973 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Space, 0, "select-cursor-row", 1,
974 G_TYPE_BOOLEAN, TRUE);
975 gtk_binding_entry_add_signal (binding_set[0], GDK_Return, 0, "select-cursor-row", 1,
976 G_TYPE_BOOLEAN, TRUE);
977 gtk_binding_entry_add_signal (binding_set[0], GDK_ISO_Enter, 0, "select-cursor-row", 1,
978 G_TYPE_BOOLEAN, TRUE);
979 gtk_binding_entry_add_signal (binding_set[0], GDK_KP_Enter, 0, "select-cursor-row", 1,
980 G_TYPE_BOOLEAN, TRUE);
982 gtk_binding_entry_add_signal (binding_set[0], GDK_BackSpace, 0, "select-cursor-parent", 0);
983 gtk_binding_entry_add_signal (binding_set[0], GDK_BackSpace, GDK_CONTROL_MASK, "select-cursor-parent", 0);
985 g_type_class_add_private (o_class, sizeof (PsppSheetViewPrivate));
989 pspp_sheet_view_buildable_init (GtkBuildableIface *iface)
991 iface->add_child = pspp_sheet_view_buildable_add_child;
995 pspp_sheet_view_init (PsppSheetView *tree_view)
997 tree_view->priv = G_TYPE_INSTANCE_GET_PRIVATE (tree_view, PSPP_TYPE_SHEET_VIEW, PsppSheetViewPrivate);
999 gtk_widget_set_can_focus (GTK_WIDGET (tree_view), TRUE);
1000 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (tree_view), FALSE);
1002 tree_view->priv->flags = PSPP_SHEET_VIEW_DRAW_KEYFOCUS
1003 | PSPP_SHEET_VIEW_HEADERS_VISIBLE;
1005 /* We need some padding */
1006 tree_view->priv->selected = range_tower_create ();
1007 tree_view->priv->dy = 0;
1008 tree_view->priv->cursor_offset = 0;
1009 tree_view->priv->n_columns = 0;
1010 tree_view->priv->header_height = 1;
1011 tree_view->priv->x_drag = 0;
1012 tree_view->priv->drag_pos = -1;
1013 tree_view->priv->header_has_focus = FALSE;
1014 tree_view->priv->pressed_button = -1;
1015 tree_view->priv->press_start_x = -1;
1016 tree_view->priv->press_start_y = -1;
1017 tree_view->priv->reorderable = FALSE;
1018 tree_view->priv->presize_handler_timer = 0;
1019 tree_view->priv->scroll_sync_timer = 0;
1020 tree_view->priv->fixed_height = -1;
1021 tree_view->priv->fixed_height_set = FALSE;
1022 pspp_sheet_view_set_adjustments (tree_view, NULL, NULL);
1023 tree_view->priv->selection = _pspp_sheet_selection_new_with_tree_view (tree_view);
1024 tree_view->priv->enable_search = TRUE;
1025 tree_view->priv->search_column = -1;
1026 tree_view->priv->search_position_func = pspp_sheet_view_search_position_func;
1027 tree_view->priv->search_equal_func = pspp_sheet_view_search_equal_func;
1028 tree_view->priv->search_custom_entry_set = FALSE;
1029 tree_view->priv->typeselect_flush_timeout = 0;
1030 tree_view->priv->init_hadjust_value = TRUE;
1031 tree_view->priv->width = 0;
1033 tree_view->priv->hover_selection = FALSE;
1035 tree_view->priv->rubber_banding_enable = FALSE;
1037 tree_view->priv->grid_lines = PSPP_SHEET_VIEW_GRID_LINES_NONE;
1039 tree_view->priv->tooltip_column = -1;
1041 tree_view->priv->special_cells = PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT;
1043 tree_view->priv->post_validation_flag = FALSE;
1045 tree_view->priv->last_button_x = -1;
1046 tree_view->priv->last_button_y = -1;
1048 tree_view->priv->event_last_x = -10000;
1049 tree_view->priv->event_last_y = -10000;
1051 tree_view->priv->prelight_node = -1;
1052 tree_view->priv->rubber_band_start_node = -1;
1053 tree_view->priv->rubber_band_end_node = -1;
1055 tree_view->priv->anchor_column = NULL;
1057 tree_view->priv->button_style = NULL;
1059 tree_view->dispose_has_run = FALSE;
1068 pspp_sheet_view_set_property (GObject *object,
1070 const GValue *value,
1073 PsppSheetView *tree_view;
1075 tree_view = PSPP_SHEET_VIEW (object);
1080 pspp_sheet_view_set_model (tree_view, g_value_get_object (value));
1082 case PROP_HADJUSTMENT:
1083 pspp_sheet_view_set_hadjustment (tree_view, g_value_get_object (value));
1085 case PROP_VADJUSTMENT:
1086 pspp_sheet_view_set_vadjustment (tree_view, g_value_get_object (value));
1088 case PROP_HEADERS_VISIBLE:
1089 pspp_sheet_view_set_headers_visible (tree_view, g_value_get_boolean (value));
1091 case PROP_HEADERS_CLICKABLE:
1092 pspp_sheet_view_set_headers_clickable (tree_view, g_value_get_boolean (value));
1094 case PROP_REORDERABLE:
1095 pspp_sheet_view_set_reorderable (tree_view, g_value_get_boolean (value));
1097 case PROP_RULES_HINT:
1098 pspp_sheet_view_set_rules_hint (tree_view, g_value_get_boolean (value));
1100 case PROP_ENABLE_SEARCH:
1101 pspp_sheet_view_set_enable_search (tree_view, g_value_get_boolean (value));
1103 case PROP_SEARCH_COLUMN:
1104 pspp_sheet_view_set_search_column (tree_view, g_value_get_int (value));
1106 case PROP_HOVER_SELECTION:
1107 tree_view->priv->hover_selection = g_value_get_boolean (value);
1109 case PROP_RUBBER_BANDING:
1110 tree_view->priv->rubber_banding_enable = g_value_get_boolean (value);
1112 case PROP_ENABLE_GRID_LINES:
1113 pspp_sheet_view_set_grid_lines (tree_view, g_value_get_enum (value));
1115 case PROP_TOOLTIP_COLUMN:
1116 pspp_sheet_view_set_tooltip_column (tree_view, g_value_get_int (value));
1118 case PROP_SPECIAL_CELLS:
1119 pspp_sheet_view_set_special_cells (tree_view, g_value_get_enum (value));
1121 case PROP_FIXED_HEIGHT:
1122 pspp_sheet_view_set_fixed_height (tree_view, g_value_get_int (value));
1124 case PROP_FIXED_HEIGHT_SET:
1125 if (g_value_get_boolean (value))
1127 if (!tree_view->priv->fixed_height_set
1128 && tree_view->priv->fixed_height >= 0)
1130 tree_view->priv->fixed_height_set = true;
1131 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
1136 if (tree_view->priv->fixed_height_set)
1138 tree_view->priv->fixed_height_set = false;
1139 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
1140 install_presize_handler (tree_view);
1145 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1151 pspp_sheet_view_get_property (GObject *object,
1156 PsppSheetView *tree_view;
1158 tree_view = PSPP_SHEET_VIEW (object);
1163 g_value_set_object (value, tree_view->priv->model);
1165 case PROP_HADJUSTMENT:
1166 g_value_set_object (value, tree_view->priv->hadjustment);
1168 case PROP_VADJUSTMENT:
1169 g_value_set_object (value, tree_view->priv->vadjustment);
1171 case PROP_HEADERS_VISIBLE:
1172 g_value_set_boolean (value, pspp_sheet_view_get_headers_visible (tree_view));
1174 case PROP_HEADERS_CLICKABLE:
1175 g_value_set_boolean (value, pspp_sheet_view_get_headers_clickable (tree_view));
1177 case PROP_REORDERABLE:
1178 g_value_set_boolean (value, tree_view->priv->reorderable);
1180 case PROP_RULES_HINT:
1181 g_value_set_boolean (value, tree_view->priv->has_rules);
1183 case PROP_ENABLE_SEARCH:
1184 g_value_set_boolean (value, tree_view->priv->enable_search);
1186 case PROP_SEARCH_COLUMN:
1187 g_value_set_int (value, tree_view->priv->search_column);
1189 case PROP_HOVER_SELECTION:
1190 g_value_set_boolean (value, tree_view->priv->hover_selection);
1192 case PROP_RUBBER_BANDING:
1193 g_value_set_boolean (value, tree_view->priv->rubber_banding_enable);
1195 case PROP_ENABLE_GRID_LINES:
1196 g_value_set_enum (value, tree_view->priv->grid_lines);
1198 case PROP_TOOLTIP_COLUMN:
1199 g_value_set_int (value, tree_view->priv->tooltip_column);
1201 case PROP_SPECIAL_CELLS:
1202 g_value_set_enum (value, tree_view->priv->special_cells);
1204 case PROP_FIXED_HEIGHT:
1205 g_value_set_int (value, pspp_sheet_view_get_fixed_height (tree_view));
1207 case PROP_FIXED_HEIGHT_SET:
1208 g_value_set_boolean (value, tree_view->priv->fixed_height_set);
1211 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1217 pspp_sheet_view_dispose (GObject *object)
1219 PsppSheetView *tree_view = PSPP_SHEET_VIEW (object);
1221 if (tree_view->dispose_has_run)
1224 tree_view->dispose_has_run = TRUE;
1226 if (tree_view->priv->selection != NULL)
1228 _pspp_sheet_selection_set_tree_view (tree_view->priv->selection, NULL);
1229 g_object_unref (tree_view->priv->selection);
1230 tree_view->priv->selection = NULL;
1233 if (tree_view->priv->hadjustment)
1235 g_object_unref (tree_view->priv->hadjustment);
1236 tree_view->priv->hadjustment = NULL;
1238 if (tree_view->priv->vadjustment)
1240 g_object_unref (tree_view->priv->vadjustment);
1241 tree_view->priv->vadjustment = NULL;
1244 if (tree_view->priv->button_style)
1246 g_object_unref (tree_view->priv->button_style);
1247 tree_view->priv->button_style = NULL;
1251 G_OBJECT_CLASS (pspp_sheet_view_parent_class)->dispose (object);
1257 pspp_sheet_view_buildable_add_child (GtkBuildable *tree_view,
1258 GtkBuilder *builder,
1262 pspp_sheet_view_append_column (PSPP_SHEET_VIEW (tree_view), PSPP_SHEET_VIEW_COLUMN (child));
1266 pspp_sheet_view_finalize (GObject *object)
1268 PsppSheetView *tree_view = PSPP_SHEET_VIEW (object);
1270 pspp_sheet_view_stop_editing (tree_view, TRUE);
1272 if (tree_view->priv->selected != NULL)
1274 range_tower_destroy (tree_view->priv->selected);
1275 tree_view->priv->selected = NULL;
1279 tree_view->priv->prelight_node = -1;
1282 if (tree_view->priv->scroll_to_path != NULL)
1284 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
1285 tree_view->priv->scroll_to_path = NULL;
1288 if (tree_view->priv->drag_dest_row != NULL)
1290 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
1291 tree_view->priv->drag_dest_row = NULL;
1294 if (tree_view->priv->top_row != NULL)
1296 gtk_tree_row_reference_free (tree_view->priv->top_row);
1297 tree_view->priv->top_row = NULL;
1300 if (tree_view->priv->column_drop_func_data &&
1301 tree_view->priv->column_drop_func_data_destroy)
1303 tree_view->priv->column_drop_func_data_destroy (tree_view->priv->column_drop_func_data);
1304 tree_view->priv->column_drop_func_data = NULL;
1307 if (tree_view->priv->destroy_count_destroy &&
1308 tree_view->priv->destroy_count_data)
1310 tree_view->priv->destroy_count_destroy (tree_view->priv->destroy_count_data);
1311 tree_view->priv->destroy_count_data = NULL;
1314 gtk_tree_row_reference_free (tree_view->priv->cursor);
1315 tree_view->priv->cursor = NULL;
1317 gtk_tree_row_reference_free (tree_view->priv->anchor);
1318 tree_view->priv->anchor = NULL;
1320 /* destroy interactive search dialog */
1321 if (tree_view->priv->search_window)
1323 gtk_widget_destroy (tree_view->priv->search_window);
1324 tree_view->priv->search_window = NULL;
1325 tree_view->priv->search_entry = NULL;
1326 if (tree_view->priv->typeselect_flush_timeout)
1328 g_source_remove (tree_view->priv->typeselect_flush_timeout);
1329 tree_view->priv->typeselect_flush_timeout = 0;
1333 if (tree_view->priv->search_destroy && tree_view->priv->search_user_data)
1335 tree_view->priv->search_destroy (tree_view->priv->search_user_data);
1336 tree_view->priv->search_user_data = NULL;
1339 if (tree_view->priv->search_position_destroy && tree_view->priv->search_position_user_data)
1341 tree_view->priv->search_position_destroy (tree_view->priv->search_position_user_data);
1342 tree_view->priv->search_position_user_data = NULL;
1345 pspp_sheet_view_set_model (tree_view, NULL);
1348 G_OBJECT_CLASS (pspp_sheet_view_parent_class)->finalize (object);
1353 /* GtkWidget Methods
1356 /* GtkWidget::map helper */
1358 pspp_sheet_view_map_buttons (PsppSheetView *tree_view)
1362 g_return_if_fail (gtk_widget_get_mapped (GTK_WIDGET (tree_view)));
1364 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
1366 PsppSheetViewColumn *column;
1368 for (list = tree_view->priv->columns; list; list = list->next)
1370 column = list->data;
1371 if (column->button != NULL &&
1372 gtk_widget_get_visible (column->button) &&
1373 !gtk_widget_get_mapped (column->button))
1374 gtk_widget_map (column->button);
1376 for (list = tree_view->priv->columns; list; list = list->next)
1378 column = list->data;
1379 if (column->visible == FALSE || column->window == NULL)
1381 if (column->resizable)
1383 gdk_window_raise (column->window);
1384 gdk_window_show (column->window);
1387 gdk_window_hide (column->window);
1389 gdk_window_show (tree_view->priv->header_window);
1394 pspp_sheet_view_map (GtkWidget *widget)
1396 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1399 gtk_widget_set_mapped (widget, TRUE);
1401 tmp_list = tree_view->priv->children;
1404 PsppSheetViewChild *child = tmp_list->data;
1405 tmp_list = tmp_list->next;
1407 if (gtk_widget_get_visible (child->widget))
1409 if (!gtk_widget_get_mapped (child->widget))
1410 gtk_widget_map (child->widget);
1413 gdk_window_show (tree_view->priv->bin_window);
1415 pspp_sheet_view_map_buttons (tree_view);
1417 gdk_window_show (widget->window);
1421 pspp_sheet_view_realize (GtkWidget *widget)
1424 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1426 GdkWindowAttr attributes;
1427 gint attributes_mask;
1429 gtk_widget_set_realized (widget, TRUE);
1431 /* Make the main, clipping window */
1432 attributes.window_type = GDK_WINDOW_CHILD;
1433 attributes.x = widget->allocation.x;
1434 attributes.y = widget->allocation.y;
1435 attributes.width = widget->allocation.width;
1436 attributes.height = widget->allocation.height;
1437 attributes.wclass = GDK_INPUT_OUTPUT;
1438 attributes.visual = gtk_widget_get_visual (widget);
1439 attributes.colormap = gtk_widget_get_colormap (widget);
1440 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1442 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1444 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
1445 &attributes, attributes_mask);
1446 gdk_window_set_user_data (widget->window, widget);
1448 /* Make the window for the tree */
1450 attributes.y = TREE_VIEW_HEADER_HEIGHT (tree_view);
1451 attributes.width = MAX (tree_view->priv->width, widget->allocation.width);
1452 attributes.height = widget->allocation.height;
1453 attributes.event_mask = (GDK_EXPOSURE_MASK |
1455 GDK_POINTER_MOTION_MASK |
1456 GDK_ENTER_NOTIFY_MASK |
1457 GDK_LEAVE_NOTIFY_MASK |
1458 GDK_BUTTON_PRESS_MASK |
1459 GDK_BUTTON_RELEASE_MASK |
1460 gtk_widget_get_events (widget));
1462 tree_view->priv->bin_window = gdk_window_new (widget->window,
1463 &attributes, attributes_mask);
1464 gdk_window_set_user_data (tree_view->priv->bin_window, widget);
1466 /* Make the column header window */
1469 attributes.width = MAX (tree_view->priv->width, widget->allocation.width);
1470 attributes.height = tree_view->priv->header_height;
1471 attributes.event_mask = (GDK_EXPOSURE_MASK |
1473 GDK_BUTTON_PRESS_MASK |
1474 GDK_BUTTON_RELEASE_MASK |
1475 GDK_KEY_PRESS_MASK |
1476 GDK_KEY_RELEASE_MASK |
1477 gtk_widget_get_events (widget));
1479 tree_view->priv->header_window = gdk_window_new (widget->window,
1480 &attributes, attributes_mask);
1481 gdk_window_set_user_data (tree_view->priv->header_window, widget);
1483 /* Add them all up. */
1484 widget->style = gtk_style_attach (widget->style, widget->window);
1485 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
1486 gdk_window_set_background (tree_view->priv->bin_window, &widget->style->base[widget->state]);
1487 gtk_style_set_background (widget->style, tree_view->priv->header_window, GTK_STATE_NORMAL);
1489 tmp_list = tree_view->priv->children;
1492 PsppSheetViewChild *child = tmp_list->data;
1493 tmp_list = tmp_list->next;
1495 gtk_widget_set_parent_window (child->widget, tree_view->priv->bin_window);
1498 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
1499 _pspp_sheet_view_column_realize_button (PSPP_SHEET_VIEW_COLUMN (tmp_list->data));
1501 /* Need to call those here, since they create GCs */
1502 pspp_sheet_view_set_grid_lines (tree_view, tree_view->priv->grid_lines);
1504 install_presize_handler (tree_view);
1506 for (i = 0; i < 5; ++i)
1508 tree_view->priv->grid_line_gc[i] = gdk_gc_new (widget->window);
1509 gdk_gc_copy (tree_view->priv->grid_line_gc[i], widget->style->text_aa_gc[i]);
1514 pspp_sheet_view_unrealize (GtkWidget *widget)
1517 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1518 PsppSheetViewPrivate *priv = tree_view->priv;
1521 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->unrealize (widget);
1523 if (priv->scroll_timeout != 0)
1525 g_source_remove (priv->scroll_timeout);
1526 priv->scroll_timeout = 0;
1529 if (priv->open_dest_timeout != 0)
1531 g_source_remove (priv->open_dest_timeout);
1532 priv->open_dest_timeout = 0;
1535 if (priv->presize_handler_timer != 0)
1537 g_source_remove (priv->presize_handler_timer);
1538 priv->presize_handler_timer = 0;
1541 if (priv->validate_rows_timer != 0)
1543 g_source_remove (priv->validate_rows_timer);
1544 priv->validate_rows_timer = 0;
1547 if (priv->scroll_sync_timer != 0)
1549 g_source_remove (priv->scroll_sync_timer);
1550 priv->scroll_sync_timer = 0;
1553 if (priv->typeselect_flush_timeout)
1555 g_source_remove (priv->typeselect_flush_timeout);
1556 priv->typeselect_flush_timeout = 0;
1559 for (list = priv->columns; list; list = list->next)
1560 _pspp_sheet_view_column_unrealize_button (PSPP_SHEET_VIEW_COLUMN (list->data));
1562 gdk_window_set_user_data (priv->bin_window, NULL);
1563 gdk_window_destroy (priv->bin_window);
1564 priv->bin_window = NULL;
1566 gdk_window_set_user_data (priv->header_window, NULL);
1567 gdk_window_destroy (priv->header_window);
1568 priv->header_window = NULL;
1570 if (priv->drag_window)
1572 gdk_window_set_user_data (priv->drag_window, NULL);
1573 gdk_window_destroy (priv->drag_window);
1574 priv->drag_window = NULL;
1577 if (priv->drag_highlight_window)
1579 gdk_window_set_user_data (priv->drag_highlight_window, NULL);
1580 gdk_window_destroy (priv->drag_highlight_window);
1581 priv->drag_highlight_window = NULL;
1584 for (x = 0 ; x < 5 ; ++x)
1585 g_object_unref (priv->grid_line_gc[x]);
1587 if (tree_view->priv->columns != NULL)
1589 list = tree_view->priv->columns;
1592 PsppSheetViewColumn *column;
1593 column = PSPP_SHEET_VIEW_COLUMN (list->data);
1595 pspp_sheet_view_remove_column (tree_view, column);
1597 tree_view->priv->columns = NULL;
1601 /* GtkWidget::size_request helper */
1603 pspp_sheet_view_size_request_columns (PsppSheetView *tree_view)
1607 tree_view->priv->header_height = 0;
1609 if (tree_view->priv->model)
1611 for (list = tree_view->priv->columns; list; list = list->next)
1613 GtkRequisition requisition;
1614 PsppSheetViewColumn *column = list->data;
1616 pspp_sheet_view_column_size_request (column, &requisition);
1617 column->button_request = requisition.width;
1618 tree_view->priv->header_height = MAX (tree_view->priv->header_height, requisition.height);
1624 /* Called only by ::size_request */
1626 pspp_sheet_view_update_size (PsppSheetView *tree_view)
1629 PsppSheetViewColumn *column;
1632 if (tree_view->priv->model == NULL)
1634 tree_view->priv->width = 0;
1635 tree_view->priv->prev_width = 0;
1636 tree_view->priv->height = 0;
1640 tree_view->priv->prev_width = tree_view->priv->width;
1641 tree_view->priv->width = 0;
1643 /* keep this in sync with size_allocate below */
1644 for (list = tree_view->priv->columns, i = 0; list; list = list->next, i++)
1646 gint real_requested_width = 0;
1647 column = list->data;
1648 if (!column->visible)
1651 if (column->use_resized_width)
1653 real_requested_width = column->resized_width;
1657 real_requested_width = column->fixed_width;
1660 if (column->min_width != -1)
1661 real_requested_width = MAX (real_requested_width, column->min_width);
1662 if (column->max_width != -1)
1663 real_requested_width = MIN (real_requested_width, column->max_width);
1665 tree_view->priv->width += real_requested_width;
1668 tree_view->priv->height = tree_view->priv->fixed_height * tree_view->priv->row_count;
1672 pspp_sheet_view_size_request (GtkWidget *widget,
1673 GtkRequisition *requisition)
1675 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1678 /* we validate some rows initially just to make sure we have some size.
1679 * In practice, with a lot of static lists, this should get a good width.
1681 initialize_fixed_height_mode (tree_view);
1682 pspp_sheet_view_size_request_columns (tree_view);
1683 pspp_sheet_view_update_size (PSPP_SHEET_VIEW (widget));
1685 requisition->width = tree_view->priv->width;
1686 requisition->height = tree_view->priv->height + TREE_VIEW_HEADER_HEIGHT (tree_view);
1688 tmp_list = tree_view->priv->children;
1692 PsppSheetViewChild *child = tmp_list->data;
1693 GtkRequisition child_requisition;
1695 tmp_list = tmp_list->next;
1697 if (gtk_widget_get_visible (child->widget))
1698 gtk_widget_size_request (child->widget, &child_requisition);
1703 invalidate_column (PsppSheetView *tree_view,
1704 PsppSheetViewColumn *column)
1706 gint column_offset = 0;
1708 GtkWidget *widget = GTK_WIDGET (tree_view);
1711 if (!gtk_widget_get_realized (widget))
1714 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
1715 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
1717 list = (rtl ? list->prev : list->next))
1719 PsppSheetViewColumn *tmpcolumn = list->data;
1720 if (tmpcolumn == column)
1722 GdkRectangle invalid_rect;
1724 invalid_rect.x = column_offset;
1726 invalid_rect.width = column->width;
1727 invalid_rect.height = widget->allocation.height;
1729 gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
1733 column_offset += tmpcolumn->width;
1738 invalidate_last_column (PsppSheetView *tree_view)
1743 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
1745 for (last_column = (rtl ? g_list_first (tree_view->priv->columns) : g_list_last (tree_view->priv->columns));
1747 last_column = (rtl ? last_column->next : last_column->prev))
1749 if (PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible)
1751 invalidate_column (tree_view, last_column->data);
1758 pspp_sheet_view_get_real_requested_width_from_column (PsppSheetView *tree_view,
1759 PsppSheetViewColumn *column)
1761 gint real_requested_width;
1763 if (column->use_resized_width)
1765 real_requested_width = column->resized_width;
1769 real_requested_width = column->fixed_width;
1772 if (column->min_width != -1)
1773 real_requested_width = MAX (real_requested_width, column->min_width);
1774 if (column->max_width != -1)
1775 real_requested_width = MIN (real_requested_width, column->max_width);
1777 return real_requested_width;
1781 span_intersects (int a0, int a_width,
1782 int b0, int b_width)
1784 int a1 = a0 + a_width;
1785 int b1 = b0 + b_width;
1786 return (a0 >= b0 && a0 < b1) || (b0 >= a0 && b0 < a1);
1789 /* GtkWidget::size_allocate helper */
1791 pspp_sheet_view_size_allocate_columns (GtkWidget *widget,
1792 gboolean *width_changed)
1794 PsppSheetView *tree_view;
1795 GList *list, *first_column, *last_column;
1796 PsppSheetViewColumn *column;
1797 GtkAllocation allocation;
1799 gint extra, extra_per_column;
1800 gint full_requested_width = 0;
1801 gint number_of_expand_columns = 0;
1802 gboolean column_changed = FALSE;
1805 tree_view = PSPP_SHEET_VIEW (widget);
1807 for (last_column = g_list_last (tree_view->priv->columns);
1808 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
1809 last_column = last_column->prev)
1811 if (last_column == NULL)
1814 for (first_column = g_list_first (tree_view->priv->columns);
1815 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
1816 first_column = first_column->next)
1820 allocation.height = tree_view->priv->header_height;
1822 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1824 /* find out how many extra space and expandable columns we have */
1825 for (list = tree_view->priv->columns; list != last_column->next; list = list->next)
1827 column = (PsppSheetViewColumn *)list->data;
1829 if (!column->visible)
1832 full_requested_width += pspp_sheet_view_get_real_requested_width_from_column (tree_view, column);
1835 number_of_expand_columns++;
1838 extra = MAX (widget->allocation.width - full_requested_width, 0);
1839 if (number_of_expand_columns > 0)
1840 extra_per_column = extra/number_of_expand_columns;
1842 extra_per_column = 0;
1844 for (list = (rtl ? last_column : first_column);
1845 list != (rtl ? first_column->prev : last_column->next);
1846 list = (rtl ? list->prev : list->next))
1848 gint real_requested_width = 0;
1851 column = list->data;
1852 old_width = column->width;
1854 if (!column->visible)
1857 /* We need to handle the dragged button specially.
1859 if (column == tree_view->priv->drag_column)
1861 GtkAllocation drag_allocation;
1862 gdk_drawable_get_size (tree_view->priv->drag_window,
1863 &(drag_allocation.width),
1864 &(drag_allocation.height));
1865 drag_allocation.x = 0;
1866 drag_allocation.y = 0;
1867 pspp_sheet_view_column_size_allocate (tree_view->priv->drag_column,
1869 width += drag_allocation.width;
1873 real_requested_width = pspp_sheet_view_get_real_requested_width_from_column (tree_view, column);
1875 allocation.x = width;
1876 column->width = real_requested_width;
1880 if (number_of_expand_columns == 1)
1882 /* We add the remander to the last column as
1884 column->width += extra;
1888 column->width += extra_per_column;
1889 extra -= extra_per_column;
1890 number_of_expand_columns --;
1894 if (column->width != old_width)
1895 g_object_notify (G_OBJECT (column), "width");
1897 allocation.width = column->width;
1898 width += column->width;
1900 if (column->width > old_width)
1901 column_changed = TRUE;
1903 pspp_sheet_view_column_size_allocate (column, &allocation);
1905 if (span_intersects (allocation.x, allocation.width,
1906 tree_view->priv->hadjustment->value,
1907 widget->allocation.width)
1908 && gtk_widget_get_realized (widget))
1909 pspp_sheet_view_column_set_need_button (column, TRUE);
1912 gdk_window_move_resize (column->window,
1913 allocation.x + (rtl ? 0 : allocation.width) - TREE_VIEW_DRAG_WIDTH/2,
1915 TREE_VIEW_DRAG_WIDTH, allocation.height);
1918 /* We change the width here. The user might have been resizing columns,
1919 * so the total width of the tree view changes.
1921 tree_view->priv->width = width;
1923 *width_changed = TRUE;
1926 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
1931 pspp_sheet_view_size_allocate (GtkWidget *widget,
1932 GtkAllocation *allocation)
1934 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1936 gboolean width_changed = FALSE;
1937 gint old_width = widget->allocation.width;
1939 if (allocation->width != widget->allocation.width)
1940 width_changed = TRUE;
1942 widget->allocation = *allocation;
1944 tmp_list = tree_view->priv->children;
1948 GtkAllocation allocation;
1950 PsppSheetViewChild *child = tmp_list->data;
1951 tmp_list = tmp_list->next;
1953 /* totally ignore our child's requisition */
1954 allocation.x = child->x;
1955 allocation.y = child->y;
1956 allocation.width = child->width;
1957 allocation.height = child->height;
1958 gtk_widget_size_allocate (child->widget, &allocation);
1961 /* We size-allocate the columns first because the width of the
1962 * tree view (used in updating the adjustments below) might change.
1964 pspp_sheet_view_size_allocate_columns (widget, &width_changed);
1966 tree_view->priv->hadjustment->page_size = allocation->width;
1967 tree_view->priv->hadjustment->page_increment = allocation->width * 0.9;
1968 tree_view->priv->hadjustment->step_increment = allocation->width * 0.1;
1969 tree_view->priv->hadjustment->lower = 0;
1970 tree_view->priv->hadjustment->upper = MAX (tree_view->priv->hadjustment->page_size, tree_view->priv->width);
1972 if (gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL)
1974 if (allocation->width < tree_view->priv->width)
1976 if (tree_view->priv->init_hadjust_value)
1978 tree_view->priv->hadjustment->value = MAX (tree_view->priv->width - allocation->width, 0);
1979 tree_view->priv->init_hadjust_value = FALSE;
1981 else if (allocation->width != old_width)
1983 tree_view->priv->hadjustment->value = CLAMP (tree_view->priv->hadjustment->value - allocation->width + old_width, 0, tree_view->priv->width - allocation->width);
1986 tree_view->priv->hadjustment->value = CLAMP (tree_view->priv->width - (tree_view->priv->prev_width - tree_view->priv->hadjustment->value), 0, tree_view->priv->width - allocation->width);
1990 tree_view->priv->hadjustment->value = 0;
1991 tree_view->priv->init_hadjust_value = TRUE;
1995 if (tree_view->priv->hadjustment->value + allocation->width > tree_view->priv->width)
1996 tree_view->priv->hadjustment->value = MAX (tree_view->priv->width - allocation->width, 0);
1998 gtk_adjustment_changed (tree_view->priv->hadjustment);
2000 tree_view->priv->vadjustment->page_size = allocation->height - TREE_VIEW_HEADER_HEIGHT (tree_view);
2001 tree_view->priv->vadjustment->step_increment = tree_view->priv->vadjustment->page_size * 0.1;
2002 tree_view->priv->vadjustment->page_increment = tree_view->priv->vadjustment->page_size * 0.9;
2003 tree_view->priv->vadjustment->lower = 0;
2004 tree_view->priv->vadjustment->upper = MAX (tree_view->priv->vadjustment->page_size, tree_view->priv->height);
2006 gtk_adjustment_changed (tree_view->priv->vadjustment);
2008 /* now the adjustments and window sizes are in sync, we can sync toprow/dy again */
2009 if (tree_view->priv->height <= tree_view->priv->vadjustment->page_size)
2010 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment), 0);
2011 else if (tree_view->priv->vadjustment->value + tree_view->priv->vadjustment->page_size > tree_view->priv->height)
2012 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment),
2013 tree_view->priv->height - tree_view->priv->vadjustment->page_size);
2014 else if (gtk_tree_row_reference_valid (tree_view->priv->top_row))
2015 pspp_sheet_view_top_row_to_dy (tree_view);
2017 pspp_sheet_view_dy_to_top_row (tree_view);
2019 if (gtk_widget_get_realized (widget))
2021 gdk_window_move_resize (widget->window,
2022 allocation->x, allocation->y,
2023 allocation->width, allocation->height);
2024 gdk_window_move_resize (tree_view->priv->header_window,
2025 - (gint) tree_view->priv->hadjustment->value,
2027 MAX (tree_view->priv->width, allocation->width),
2028 tree_view->priv->header_height);
2029 gdk_window_move_resize (tree_view->priv->bin_window,
2030 - (gint) tree_view->priv->hadjustment->value,
2031 TREE_VIEW_HEADER_HEIGHT (tree_view),
2032 MAX (tree_view->priv->width, allocation->width),
2033 allocation->height - TREE_VIEW_HEADER_HEIGHT (tree_view));
2036 if (tree_view->priv->row_count == 0)
2037 invalidate_empty_focus (tree_view);
2039 if (gtk_widget_get_realized (widget))
2041 gboolean has_expand_column = FALSE;
2042 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
2044 if (pspp_sheet_view_column_get_expand (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)))
2046 has_expand_column = TRUE;
2051 /* This little hack only works if we have an LTR locale, and no column has the */
2054 if (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_LTR &&
2055 ! has_expand_column)
2056 invalidate_last_column (tree_view);
2058 gtk_widget_queue_draw (widget);
2063 /* Grabs the focus and unsets the PSPP_SHEET_VIEW_DRAW_KEYFOCUS flag */
2065 grab_focus_and_unset_draw_keyfocus (PsppSheetView *tree_view)
2067 GtkWidget *widget = GTK_WIDGET (tree_view);
2069 if (gtk_widget_get_can_focus (widget) && !gtk_widget_has_focus (widget))
2070 gtk_widget_grab_focus (widget);
2071 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
2075 pspp_sheet_view_node_is_selected (PsppSheetView *tree_view,
2078 return node >= 0 && range_tower_contains (tree_view->priv->selected, node);
2082 pspp_sheet_view_node_select (PsppSheetView *tree_view,
2085 range_tower_set1 (tree_view->priv->selected, node, 1);
2089 pspp_sheet_view_node_unselect (PsppSheetView *tree_view,
2092 range_tower_set0 (tree_view->priv->selected, node, 1);
2096 pspp_sheet_view_node_next (PsppSheetView *tree_view,
2099 return node + 1 < tree_view->priv->row_count ? node + 1 : -1;
2103 pspp_sheet_view_node_prev (PsppSheetView *tree_view,
2106 return node > 0 ? node - 1 : -1;
2110 all_columns_selected (PsppSheetView *tree_view)
2114 for (list = tree_view->priv->columns; list; list = list->next)
2116 PsppSheetViewColumn *column = list->data;
2117 if (column->selectable && !column->selected)
2125 pspp_sheet_view_row_head_clicked (PsppSheetView *tree_view,
2127 PsppSheetViewColumn *column,
2128 GdkEventButton *event)
2130 PsppSheetSelection *selection;
2131 PsppSheetSelectionMode mode;
2133 gboolean update_anchor;
2137 g_return_val_if_fail (tree_view != NULL, FALSE);
2138 g_return_val_if_fail (column != NULL, FALSE);
2140 selection = tree_view->priv->selection;
2141 mode = pspp_sheet_selection_get_mode (selection);
2142 if (mode != PSPP_SHEET_SELECTION_RECTANGLE)
2145 if (!column->row_head)
2150 modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
2151 if (event->type != GDK_BUTTON_PRESS
2152 || (modifiers != GDK_CONTROL_MASK && modifiers != GDK_SHIFT_MASK))
2158 path = gtk_tree_path_new_from_indices (node, -1);
2161 pspp_sheet_selection_unselect_all (selection);
2162 pspp_sheet_selection_select_path (selection, path);
2163 pspp_sheet_selection_select_all_columns (selection);
2164 update_anchor = TRUE;
2167 else if (event->type == GDK_BUTTON_PRESS && event->button == 3)
2169 if (pspp_sheet_selection_count_selected_rows (selection) <= 1
2170 || !all_columns_selected (tree_view))
2172 pspp_sheet_selection_unselect_all (selection);
2173 pspp_sheet_selection_select_path (selection, path);
2174 pspp_sheet_selection_select_all_columns (selection);
2175 update_anchor = TRUE;
2179 update_anchor = handled = FALSE;
2181 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
2182 && modifiers == GDK_CONTROL_MASK)
2184 if (!all_columns_selected (tree_view))
2186 pspp_sheet_selection_unselect_all (selection);
2187 pspp_sheet_selection_select_all_columns (selection);
2190 if (pspp_sheet_selection_path_is_selected (selection, path))
2191 pspp_sheet_selection_unselect_path (selection, path);
2193 pspp_sheet_selection_select_path (selection, path);
2194 update_anchor = TRUE;
2197 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
2198 && modifiers == GDK_SHIFT_MASK)
2200 GtkTreeRowReference *anchor = tree_view->priv->anchor;
2201 GtkTreePath *anchor_path;
2203 if (all_columns_selected (tree_view)
2204 && gtk_tree_row_reference_valid (anchor))
2206 update_anchor = FALSE;
2207 anchor_path = gtk_tree_row_reference_get_path (anchor);
2211 update_anchor = TRUE;
2212 anchor_path = gtk_tree_path_copy (path);
2215 pspp_sheet_selection_unselect_all (selection);
2216 pspp_sheet_selection_select_range (selection, anchor_path, path);
2217 pspp_sheet_selection_select_all_columns (selection);
2219 gtk_tree_path_free (anchor_path);
2224 update_anchor = handled = FALSE;
2228 if (tree_view->priv->anchor)
2229 gtk_tree_row_reference_free (tree_view->priv->anchor);
2230 tree_view->priv->anchor =
2231 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
2232 tree_view->priv->model,
2236 gtk_tree_path_free (path);
2241 find_click (PsppSheetView *tree_view,
2244 PsppSheetViewColumn **column,
2245 GdkRectangle *background_area,
2246 GdkRectangle *cell_area)
2253 /* find the node that was clicked */
2254 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, y);
2257 y_offset = -pspp_sheet_view_find_offset (tree_view, new_y, node);
2262 background_area->y = y_offset + y;
2263 background_area->height = ROW_HEIGHT (tree_view);
2264 background_area->x = 0;
2266 /* Let the column have a chance at selecting it. */
2267 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
2268 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
2269 list; list = (rtl ? list->prev : list->next))
2271 PsppSheetViewColumn *candidate = list->data;
2273 if (!candidate->visible)
2276 background_area->width = candidate->width;
2277 if ((background_area->x > x) ||
2278 (background_area->x + background_area->width <= x))
2280 background_area->x += background_area->width;
2284 /* we found the focus column */
2286 pspp_sheet_view_adjust_cell_area (tree_view, candidate, background_area,
2288 *column = candidate;
2296 pspp_sheet_view_button_press (GtkWidget *widget,
2297 GdkEventButton *event)
2299 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2301 PsppSheetViewColumn *column = NULL;
2303 GdkRectangle background_area;
2304 GdkRectangle cell_area;
2307 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
2308 pspp_sheet_view_stop_editing (tree_view, FALSE);
2311 /* Because grab_focus can cause reentrancy, we delay grab_focus until after
2312 * we're done handling the button press.
2315 if (event->window == tree_view->priv->bin_window)
2320 gint pre_val, aft_val;
2321 PsppSheetViewColumn *column = NULL;
2322 GtkCellRenderer *focus_cell = NULL;
2323 gboolean row_double_click = FALSE;
2326 if (tree_view->priv->row_count == 0)
2328 grab_focus_and_unset_draw_keyfocus (tree_view);
2332 if (!find_click (tree_view, event->x, event->y, &node, &column,
2333 &background_area, &cell_area))
2335 grab_focus_and_unset_draw_keyfocus (tree_view);
2339 tree_view->priv->focus_column = column;
2341 if (pspp_sheet_view_row_head_clicked (tree_view, node, column, event))
2345 pre_val = tree_view->priv->vadjustment->value;
2347 path = _pspp_sheet_view_find_path (tree_view, node);
2349 /* we only handle selection modifications on the first button press
2351 if (event->type == GDK_BUTTON_PRESS)
2353 if ((event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
2354 tree_view->priv->ctrl_pressed = TRUE;
2355 if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
2356 tree_view->priv->shift_pressed = TRUE;
2358 focus_cell = _pspp_sheet_view_column_get_cell_at_pos (column, event->x - background_area.x);
2360 pspp_sheet_view_column_focus_cell (column, focus_cell);
2362 if (event->state & GDK_CONTROL_MASK)
2364 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE);
2365 pspp_sheet_view_real_toggle_cursor_row (tree_view);
2367 else if (event->state & GDK_SHIFT_MASK)
2369 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE);
2370 pspp_sheet_view_real_select_cursor_row (tree_view, FALSE);
2374 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE);
2377 if (tree_view->priv->anchor_column == NULL ||
2378 !(event->state & GDK_SHIFT_MASK))
2379 tree_view->priv->anchor_column = column;
2380 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
2381 pspp_sheet_selection_select_column_range (tree_view->priv->selection,
2382 tree_view->priv->anchor_column,
2385 tree_view->priv->ctrl_pressed = FALSE;
2386 tree_view->priv->shift_pressed = FALSE;
2389 /* the treeview may have been scrolled because of _set_cursor,
2393 aft_val = tree_view->priv->vadjustment->value;
2394 dval = pre_val - aft_val;
2396 cell_area.y += dval;
2397 background_area.y += dval;
2399 /* Save press to possibly begin a drag
2401 if (!tree_view->priv->in_grab &&
2402 tree_view->priv->pressed_button < 0)
2404 tree_view->priv->pressed_button = event->button;
2405 tree_view->priv->press_start_x = event->x;
2406 tree_view->priv->press_start_y = event->y;
2407 tree_view->priv->press_start_node = node;
2409 if (tree_view->priv->rubber_banding_enable
2410 && (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
2411 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE))
2413 tree_view->priv->press_start_y += tree_view->priv->dy;
2414 tree_view->priv->rubber_band_x = event->x;
2415 tree_view->priv->rubber_band_y = event->y + tree_view->priv->dy;
2416 tree_view->priv->rubber_band_status = RUBBER_BAND_MAYBE_START;
2418 if ((event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
2419 tree_view->priv->rubber_band_ctrl = TRUE;
2420 if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
2421 tree_view->priv->rubber_band_shift = TRUE;
2426 /* Test if a double click happened on the same row. */
2427 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
2429 int double_click_time, double_click_distance;
2431 g_object_get (gtk_settings_get_for_screen (
2432 gtk_widget_get_screen (widget)),
2433 "gtk-double-click-time", &double_click_time,
2434 "gtk-double-click-distance", &double_click_distance,
2437 /* Same conditions as _gdk_event_button_generate */
2438 if (tree_view->priv->last_button_x != -1 &&
2439 (event->time < tree_view->priv->last_button_time + double_click_time) &&
2440 (ABS (event->x - tree_view->priv->last_button_x) <= double_click_distance) &&
2441 (ABS (event->y - tree_view->priv->last_button_y) <= double_click_distance))
2443 /* We do no longer compare paths of this row and the
2444 * row clicked previously. We use the double click
2445 * distance to decide whether this is a valid click,
2446 * allowing the mouse to slightly move over another row.
2448 row_double_click = TRUE;
2450 tree_view->priv->last_button_time = 0;
2451 tree_view->priv->last_button_x = -1;
2452 tree_view->priv->last_button_y = -1;
2456 tree_view->priv->last_button_time = event->time;
2457 tree_view->priv->last_button_x = event->x;
2458 tree_view->priv->last_button_y = event->y;
2462 if (row_double_click)
2464 gtk_grab_remove (widget);
2465 pspp_sheet_view_row_activated (tree_view, path, column);
2467 if (tree_view->priv->pressed_button == event->button)
2468 tree_view->priv->pressed_button = -1;
2471 gtk_tree_path_free (path);
2473 /* If we activated the row through a double click we don't want to grab
2474 * focus back, as moving focus to another widget is pretty common.
2476 if (!row_double_click)
2477 grab_focus_and_unset_draw_keyfocus (tree_view);
2482 /* We didn't click in the window. Let's check to see if we clicked on a column resize window.
2484 for (i = 0, list = tree_view->priv->columns; list; list = list->next, i++)
2486 column = list->data;
2487 if (event->window == column->window &&
2488 column->resizable &&
2493 if (gdk_pointer_grab (column->window, FALSE,
2494 GDK_POINTER_MOTION_HINT_MASK |
2495 GDK_BUTTON1_MOTION_MASK |
2496 GDK_BUTTON_RELEASE_MASK,
2497 NULL, NULL, event->time))
2500 gtk_grab_add (widget);
2501 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE);
2502 column->resized_width = column->width;
2504 /* block attached dnd signal handler */
2505 drag_data = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
2507 g_signal_handlers_block_matched (widget,
2508 G_SIGNAL_MATCH_DATA,
2512 tree_view->priv->drag_pos = i;
2513 tree_view->priv->x_drag = column->allocation.x + (rtl ? 0 : column->allocation.width);
2515 if (!gtk_widget_has_focus (widget))
2516 gtk_widget_grab_focus (widget);
2524 /* GtkWidget::button_release_event helper */
2526 pspp_sheet_view_button_release_drag_column (GtkWidget *widget,
2527 GdkEventButton *event)
2529 PsppSheetView *tree_view;
2533 tree_view = PSPP_SHEET_VIEW (widget);
2535 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
2536 gdk_display_pointer_ungrab (gtk_widget_get_display (widget), GDK_CURRENT_TIME);
2537 gdk_display_keyboard_ungrab (gtk_widget_get_display (widget), GDK_CURRENT_TIME);
2539 /* Move the button back */
2540 g_return_val_if_fail (tree_view->priv->drag_column->button, FALSE);
2542 g_object_ref (tree_view->priv->drag_column->button);
2543 gtk_container_remove (GTK_CONTAINER (tree_view), tree_view->priv->drag_column->button);
2544 gtk_widget_set_parent_window (tree_view->priv->drag_column->button, tree_view->priv->header_window);
2545 gtk_widget_set_parent (tree_view->priv->drag_column->button, GTK_WIDGET (tree_view));
2546 g_object_unref (tree_view->priv->drag_column->button);
2547 gtk_widget_queue_resize (widget);
2548 if (tree_view->priv->drag_column->resizable)
2550 gdk_window_raise (tree_view->priv->drag_column->window);
2551 gdk_window_show (tree_view->priv->drag_column->window);
2554 gdk_window_hide (tree_view->priv->drag_column->window);
2556 gtk_widget_grab_focus (tree_view->priv->drag_column->button);
2560 if (tree_view->priv->cur_reorder &&
2561 tree_view->priv->cur_reorder->right_column != tree_view->priv->drag_column)
2562 pspp_sheet_view_move_column_after (tree_view, tree_view->priv->drag_column,
2563 tree_view->priv->cur_reorder->right_column);
2567 if (tree_view->priv->cur_reorder &&
2568 tree_view->priv->cur_reorder->left_column != tree_view->priv->drag_column)
2569 pspp_sheet_view_move_column_after (tree_view, tree_view->priv->drag_column,
2570 tree_view->priv->cur_reorder->left_column);
2572 tree_view->priv->drag_column = NULL;
2573 gdk_window_hide (tree_view->priv->drag_window);
2575 for (l = tree_view->priv->column_drag_info; l != NULL; l = l->next)
2576 g_slice_free (PsppSheetViewColumnReorder, l->data);
2577 g_list_free (tree_view->priv->column_drag_info);
2578 tree_view->priv->column_drag_info = NULL;
2579 tree_view->priv->cur_reorder = NULL;
2581 if (tree_view->priv->drag_highlight_window)
2582 gdk_window_hide (tree_view->priv->drag_highlight_window);
2584 /* Reset our flags */
2585 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_UNSET;
2586 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG);
2591 /* GtkWidget::button_release_event helper */
2593 pspp_sheet_view_button_release_column_resize (GtkWidget *widget,
2594 GdkEventButton *event)
2596 PsppSheetView *tree_view;
2599 tree_view = PSPP_SHEET_VIEW (widget);
2601 tree_view->priv->drag_pos = -1;
2603 /* unblock attached dnd signal handler */
2604 drag_data = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
2606 g_signal_handlers_unblock_matched (widget,
2607 G_SIGNAL_MATCH_DATA,
2611 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE);
2612 gtk_grab_remove (widget);
2613 gdk_display_pointer_ungrab (gdk_drawable_get_display (event->window),
2619 pspp_sheet_view_button_release_edit (PsppSheetView *tree_view,
2620 GdkEventButton *event)
2622 GtkCellEditable *cell_editable;
2627 PsppSheetViewColumn *column;
2628 GdkRectangle background_area;
2629 GdkRectangle cell_area;
2635 if (event->window != tree_view->priv->bin_window)
2638 /* Ignore a released button, if that button wasn't depressed */
2639 if (tree_view->priv->pressed_button != event->button)
2642 if (!find_click (tree_view, event->x, event->y, &node, &column, &background_area,
2646 /* decide if we edit */
2647 path = _pspp_sheet_view_find_path (tree_view, node);
2648 modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
2649 if (event->button != 1 || modifiers)
2652 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
2653 pspp_sheet_view_column_cell_set_cell_data (column,
2654 tree_view->priv->model,
2657 if (!pspp_sheet_view_column_get_quick_edit (column)
2658 && _pspp_sheet_view_column_has_editable_cell (column))
2661 flags = 0; /* FIXME: get the right flags */
2662 path_string = gtk_tree_path_to_string (path);
2664 if (!_pspp_sheet_view_column_cell_event (column,
2672 if (cell_editable == NULL)
2675 pspp_sheet_view_real_set_cursor (tree_view, path,
2677 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
2680 _pspp_sheet_view_column_get_neighbor_sizes (
2681 column, _pspp_sheet_view_column_get_edited_cell (column), &left, &right);
2684 area.width -= right + left;
2686 pspp_sheet_view_real_start_editing (tree_view,
2693 g_free (path_string);
2694 gtk_tree_path_free (path);
2699 pspp_sheet_view_button_release (GtkWidget *widget,
2700 GdkEventButton *event)
2702 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2704 pspp_sheet_view_stop_editing (tree_view, FALSE);
2705 if (tree_view->priv->rubber_band_status != RUBBER_BAND_ACTIVE
2706 && pspp_sheet_view_button_release_edit (tree_view, event))
2708 if (tree_view->priv->pressed_button == event->button)
2709 tree_view->priv->pressed_button = -1;
2711 tree_view->priv->rubber_band_status = RUBBER_BAND_OFF;
2715 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
2716 return pspp_sheet_view_button_release_drag_column (widget, event);
2718 if (tree_view->priv->rubber_band_status)
2719 pspp_sheet_view_stop_rubber_band (tree_view);
2721 if (tree_view->priv->pressed_button == event->button)
2722 tree_view->priv->pressed_button = -1;
2724 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
2725 return pspp_sheet_view_button_release_column_resize (widget, event);
2731 pspp_sheet_view_grab_broken (GtkWidget *widget,
2732 GdkEventGrabBroken *event)
2734 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2736 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
2737 pspp_sheet_view_button_release_drag_column (widget, (GdkEventButton *)event);
2739 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
2740 pspp_sheet_view_button_release_column_resize (widget, (GdkEventButton *)event);
2745 /* GtkWidget::motion_event function set.
2749 do_prelight (PsppSheetView *tree_view,
2751 /* these are in bin_window coords */
2755 int prev_node = tree_view->priv->prelight_node;
2757 if (prev_node != node)
2759 tree_view->priv->prelight_node = node;
2762 _pspp_sheet_view_queue_draw_node (tree_view, prev_node, NULL);
2765 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
2770 prelight_or_select (PsppSheetView *tree_view,
2772 /* these are in bin_window coords */
2776 PsppSheetSelectionMode mode = pspp_sheet_selection_get_mode (tree_view->priv->selection);
2778 if (tree_view->priv->hover_selection &&
2779 (mode == PSPP_SHEET_SELECTION_SINGLE || mode == PSPP_SHEET_SELECTION_BROWSE) &&
2780 !(tree_view->priv->edited_column &&
2781 tree_view->priv->edited_column->editable_widget))
2785 if (!pspp_sheet_view_node_is_selected (tree_view, node))
2789 path = _pspp_sheet_view_find_path (tree_view, node);
2790 pspp_sheet_selection_select_path (tree_view->priv->selection, path);
2791 if (pspp_sheet_view_node_is_selected (tree_view, node))
2793 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
2794 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, FALSE);
2796 gtk_tree_path_free (path);
2800 else if (mode == PSPP_SHEET_SELECTION_SINGLE)
2801 pspp_sheet_selection_unselect_all (tree_view->priv->selection);
2804 do_prelight (tree_view, node, x, y);
2808 ensure_unprelighted (PsppSheetView *tree_view)
2810 do_prelight (tree_view,
2812 -1000, -1000); /* coords not possibly over an arrow */
2814 g_assert (tree_view->priv->prelight_node < 0);
2818 update_prelight (PsppSheetView *tree_view,
2825 if (tree_view->priv->row_count == 0)
2830 ensure_unprelighted (tree_view);
2834 new_y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, y);
2838 pspp_sheet_view_find_offset (tree_view, new_y, &node);
2841 prelight_or_select (tree_view, node, x, y);
2847 /* Our motion arrow is either a box (in the case of the original spot)
2848 * or an arrow. It is expander_size wide.
2871 pspp_sheet_view_motion_draw_column_motion_arrow (PsppSheetView *tree_view)
2873 PsppSheetViewColumnReorder *reorder = tree_view->priv->cur_reorder;
2874 GtkWidget *widget = GTK_WIDGET (tree_view);
2875 GdkBitmap *mask = NULL;
2880 gint arrow_type = DRAG_COLUMN_WINDOW_STATE_UNSET;
2881 GdkWindowAttr attributes;
2882 guint attributes_mask;
2885 reorder->left_column == tree_view->priv->drag_column ||
2886 reorder->right_column == tree_view->priv->drag_column)
2887 arrow_type = DRAG_COLUMN_WINDOW_STATE_ORIGINAL;
2888 else if (reorder->left_column || reorder->right_column)
2890 GdkRectangle visible_rect;
2891 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
2892 if (reorder->left_column)
2893 x = reorder->left_column->allocation.x + reorder->left_column->allocation.width;
2895 x = reorder->right_column->allocation.x;
2897 if (x < visible_rect.x)
2898 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT;
2899 else if (x > visible_rect.x + visible_rect.width)
2900 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT;
2902 arrow_type = DRAG_COLUMN_WINDOW_STATE_ARROW;
2905 /* We want to draw the rectangle over the initial location. */
2906 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ORIGINAL)
2911 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ORIGINAL)
2913 if (tree_view->priv->drag_highlight_window)
2915 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
2917 gdk_window_destroy (tree_view->priv->drag_highlight_window);
2920 attributes.window_type = GDK_WINDOW_CHILD;
2921 attributes.wclass = GDK_INPUT_OUTPUT;
2922 attributes.x = tree_view->priv->drag_column_x;
2924 width = attributes.width = tree_view->priv->drag_column->allocation.width;
2925 height = attributes.height = tree_view->priv->drag_column->allocation.height;
2926 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
2927 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
2928 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
2929 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2930 tree_view->priv->drag_highlight_window = gdk_window_new (tree_view->priv->header_window, &attributes, attributes_mask);
2931 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
2933 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
2934 gc = gdk_gc_new (mask);
2936 gdk_gc_set_foreground (gc, &col);
2937 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
2939 gdk_gc_set_foreground(gc, &col);
2940 gdk_draw_rectangle (mask, gc, TRUE, 2, 2, width - 4, height - 4);
2941 g_object_unref (gc);
2943 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
2945 if (mask) g_object_unref (mask);
2946 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_ORIGINAL;
2949 else if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW)
2955 width = tree_view->priv->expander_size;
2957 /* Get x, y, width, height of arrow */
2958 gdk_window_get_origin (tree_view->priv->header_window, &x, &y);
2959 if (reorder->left_column)
2961 x += reorder->left_column->allocation.x + reorder->left_column->allocation.width - width/2;
2962 height = reorder->left_column->allocation.height;
2966 x += reorder->right_column->allocation.x - width/2;
2967 height = reorder->right_column->allocation.height;
2969 y -= tree_view->priv->expander_size/2; /* The arrow takes up only half the space */
2970 height += tree_view->priv->expander_size;
2972 /* Create the new window */
2973 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW)
2975 if (tree_view->priv->drag_highlight_window)
2977 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
2979 gdk_window_destroy (tree_view->priv->drag_highlight_window);
2982 attributes.window_type = GDK_WINDOW_TEMP;
2983 attributes.wclass = GDK_INPUT_OUTPUT;
2984 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
2985 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
2986 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
2987 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
2990 attributes.width = width;
2991 attributes.height = height;
2992 tree_view->priv->drag_highlight_window = gdk_window_new (gtk_widget_get_root_window (widget),
2993 &attributes, attributes_mask);
2994 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
2996 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
2997 gc = gdk_gc_new (mask);
2999 gdk_gc_set_foreground (gc, &col);
3000 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
3002 /* Draw the 2 arrows as per above */
3004 gdk_gc_set_foreground (gc, &col);
3005 for (i = 0; i < width; i ++)
3007 if (i == (width/2 - 1))
3009 gdk_draw_line (mask, gc, i, j, i, height - j);
3010 if (i < (width/2 - 1))
3015 g_object_unref (gc);
3016 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
3018 if (mask) g_object_unref (mask);
3021 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_ARROW;
3022 gdk_window_move (tree_view->priv->drag_highlight_window, x, y);
3024 else if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT ||
3025 arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3031 width = tree_view->priv->expander_size;
3033 /* Get x, y, width, height of arrow */
3034 width = width/2; /* remember, the arrow only takes half the available width */
3035 gdk_window_get_origin (widget->window, &x, &y);
3036 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3037 x += widget->allocation.width - width;
3039 if (reorder->left_column)
3040 height = reorder->left_column->allocation.height;
3042 height = reorder->right_column->allocation.height;
3044 y -= tree_view->priv->expander_size;
3045 height += 2*tree_view->priv->expander_size;
3047 /* Create the new window */
3048 if (tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT &&
3049 tree_view->priv->drag_column_window_state != DRAG_COLUMN_WINDOW_STATE_ARROW_RIGHT)
3051 if (tree_view->priv->drag_highlight_window)
3053 gdk_window_set_user_data (tree_view->priv->drag_highlight_window,
3055 gdk_window_destroy (tree_view->priv->drag_highlight_window);
3058 attributes.window_type = GDK_WINDOW_TEMP;
3059 attributes.wclass = GDK_INPUT_OUTPUT;
3060 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
3061 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
3062 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
3063 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
3066 attributes.width = width;
3067 attributes.height = height;
3068 tree_view->priv->drag_highlight_window = gdk_window_new (NULL, &attributes, attributes_mask);
3069 gdk_window_set_user_data (tree_view->priv->drag_highlight_window, GTK_WIDGET (tree_view));
3071 mask = gdk_pixmap_new (tree_view->priv->drag_highlight_window, width, height, 1);
3072 gc = gdk_gc_new (mask);
3074 gdk_gc_set_foreground (gc, &col);
3075 gdk_draw_rectangle (mask, gc, TRUE, 0, 0, width, height);
3077 /* Draw the 2 arrows as per above */
3079 gdk_gc_set_foreground (gc, &col);
3080 j = tree_view->priv->expander_size;
3081 for (i = 0; i < width; i ++)
3084 if (arrow_type == DRAG_COLUMN_WINDOW_STATE_ARROW_LEFT)
3088 gdk_draw_line (mask, gc, k, j, k, height - j);
3089 gdk_draw_line (mask, gc, k, 0, k, tree_view->priv->expander_size - j);
3090 gdk_draw_line (mask, gc, k, height, k, height - tree_view->priv->expander_size + j);
3093 g_object_unref (gc);
3094 gdk_window_shape_combine_mask (tree_view->priv->drag_highlight_window,
3096 if (mask) g_object_unref (mask);
3099 tree_view->priv->drag_column_window_state = arrow_type;
3100 gdk_window_move (tree_view->priv->drag_highlight_window, x, y);
3104 g_warning (G_STRLOC"Invalid PsppSheetViewColumnReorder struct");
3105 gdk_window_hide (tree_view->priv->drag_highlight_window);
3109 gdk_window_show (tree_view->priv->drag_highlight_window);
3110 gdk_window_raise (tree_view->priv->drag_highlight_window);
3114 pspp_sheet_view_motion_resize_column (GtkWidget *widget,
3115 GdkEventMotion *event)
3119 PsppSheetViewColumn *column;
3120 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
3122 column = pspp_sheet_view_get_column (tree_view, tree_view->priv->drag_pos);
3124 if (event->is_hint || event->window != widget->window)
3125 gtk_widget_get_pointer (widget, &x, NULL);
3129 if (tree_view->priv->hadjustment)
3130 x += tree_view->priv->hadjustment->value;
3132 new_width = pspp_sheet_view_new_column_width (tree_view,
3133 tree_view->priv->drag_pos, &x);
3134 if (x != tree_view->priv->x_drag &&
3135 (new_width != column->fixed_width))
3137 column->use_resized_width = TRUE;
3138 column->resized_width = new_width;
3141 column->resized_width -= tree_view->priv->last_extra_space_per_column;
3143 gtk_widget_queue_resize (widget);
3151 pspp_sheet_view_update_current_reorder (PsppSheetView *tree_view)
3153 PsppSheetViewColumnReorder *reorder = NULL;
3157 gdk_window_get_pointer (tree_view->priv->header_window, &mouse_x, NULL, NULL);
3158 for (list = tree_view->priv->column_drag_info; list; list = list->next)
3160 reorder = (PsppSheetViewColumnReorder *) list->data;
3161 if (mouse_x >= reorder->left_align && mouse_x < reorder->right_align)
3166 /* if (reorder && reorder == tree_view->priv->cur_reorder)
3169 tree_view->priv->cur_reorder = reorder;
3170 pspp_sheet_view_motion_draw_column_motion_arrow (tree_view);
3174 pspp_sheet_view_vertical_autoscroll (PsppSheetView *tree_view)
3176 GdkRectangle visible_rect;
3181 gdk_window_get_pointer (tree_view->priv->bin_window, NULL, &y, NULL);
3182 y += tree_view->priv->dy;
3184 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
3186 /* see if we are near the edge. */
3187 offset = y - (visible_rect.y + 2 * SCROLL_EDGE_SIZE);
3190 offset = y - (visible_rect.y + visible_rect.height - 2 * SCROLL_EDGE_SIZE);
3195 value = CLAMP (tree_view->priv->vadjustment->value + offset, 0.0,
3196 tree_view->priv->vadjustment->upper - tree_view->priv->vadjustment->page_size);
3197 gtk_adjustment_set_value (tree_view->priv->vadjustment, value);
3201 pspp_sheet_view_horizontal_autoscroll (PsppSheetView *tree_view)
3203 GdkRectangle visible_rect;
3208 gdk_window_get_pointer (tree_view->priv->bin_window, &x, NULL, NULL);
3210 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
3212 /* See if we are near the edge. */
3213 offset = x - (visible_rect.x + SCROLL_EDGE_SIZE);
3216 offset = x - (visible_rect.x + visible_rect.width - SCROLL_EDGE_SIZE);
3222 value = CLAMP (tree_view->priv->hadjustment->value + offset,
3223 0.0, tree_view->priv->hadjustment->upper - tree_view->priv->hadjustment->page_size);
3224 gtk_adjustment_set_value (tree_view->priv->hadjustment, value);
3231 pspp_sheet_view_motion_drag_column (GtkWidget *widget,
3232 GdkEventMotion *event)
3234 PsppSheetView *tree_view = (PsppSheetView *) widget;
3235 PsppSheetViewColumn *column = tree_view->priv->drag_column;
3239 if ((column == NULL) ||
3240 (event->window != tree_view->priv->drag_window))
3243 /* Handle moving the header */
3244 gdk_window_get_position (tree_view->priv->drag_window, &x, &y);
3245 x = CLAMP (x + (gint)event->x - column->drag_x, 0,
3246 MAX (tree_view->priv->width, GTK_WIDGET (tree_view)->allocation.width) - column->allocation.width);
3247 gdk_window_move (tree_view->priv->drag_window, x, y);
3249 /* autoscroll, if needed */
3250 pspp_sheet_view_horizontal_autoscroll (tree_view);
3251 /* Update the current reorder position and arrow; */
3252 pspp_sheet_view_update_current_reorder (tree_view);
3258 pspp_sheet_view_stop_rubber_band (PsppSheetView *tree_view)
3260 remove_scroll_timeout (tree_view);
3261 gtk_grab_remove (GTK_WIDGET (tree_view));
3263 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
3265 GtkTreePath *tmp_path;
3267 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
3269 /* The anchor path should be set to the start path */
3270 tmp_path = _pspp_sheet_view_find_path (tree_view,
3271 tree_view->priv->rubber_band_start_node);
3273 if (tree_view->priv->anchor)
3274 gtk_tree_row_reference_free (tree_view->priv->anchor);
3276 tree_view->priv->anchor =
3277 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
3278 tree_view->priv->model,
3281 gtk_tree_path_free (tmp_path);
3283 /* ... and the cursor to the end path */
3284 tmp_path = _pspp_sheet_view_find_path (tree_view,
3285 tree_view->priv->rubber_band_end_node);
3286 pspp_sheet_view_real_set_cursor (PSPP_SHEET_VIEW (tree_view), tmp_path, FALSE, FALSE);
3287 gtk_tree_path_free (tmp_path);
3289 _pspp_sheet_selection_emit_changed (tree_view->priv->selection);
3292 /* Clear status variables */
3293 tree_view->priv->rubber_band_status = RUBBER_BAND_OFF;
3294 tree_view->priv->rubber_band_shift = 0;
3295 tree_view->priv->rubber_band_ctrl = 0;
3297 tree_view->priv->rubber_band_start_node = -1;
3298 tree_view->priv->rubber_band_end_node = -1;
3302 pspp_sheet_view_update_rubber_band_selection_range (PsppSheetView *tree_view,
3306 gboolean skip_start,
3309 if (start_node == end_node)
3312 /* We skip the first node and jump inside the loop */
3318 /* Small optimization by assuming insensitive nodes are never
3323 if (tree_view->priv->rubber_band_shift)
3324 pspp_sheet_view_node_select (tree_view, start_node);
3325 else if (tree_view->priv->rubber_band_ctrl)
3327 /* Toggle the selection state */
3328 if (pspp_sheet_view_node_is_selected (tree_view, start_node))
3329 pspp_sheet_view_node_unselect (tree_view, start_node);
3331 pspp_sheet_view_node_select (tree_view, start_node);
3334 pspp_sheet_view_node_select (tree_view, start_node);
3338 /* Mirror the above */
3339 if (tree_view->priv->rubber_band_shift)
3340 pspp_sheet_view_node_unselect (tree_view, start_node);
3341 else if (tree_view->priv->rubber_band_ctrl)
3343 /* Toggle the selection state */
3344 if (pspp_sheet_view_node_is_selected (tree_view, start_node))
3345 pspp_sheet_view_node_unselect (tree_view, start_node);
3347 pspp_sheet_view_node_select (tree_view, start_node);
3350 pspp_sheet_view_node_unselect (tree_view, start_node);
3353 _pspp_sheet_view_queue_draw_node (tree_view, start_node, NULL);
3355 if (start_node == end_node)
3360 start_node = pspp_sheet_view_node_next (tree_view, start_node);
3363 /* Ran out of tree */
3366 if (skip_end && start_node == end_node)
3373 pspp_sheet_view_node_find_offset (PsppSheetView *tree_view,
3376 return node * tree_view->priv->fixed_height;
3380 pspp_sheet_view_find_offset (PsppSheetView *tree_view,
3384 int fixed_height = tree_view->priv->fixed_height;
3385 if (fixed_height <= 0
3387 || height >= tree_view->priv->row_count * fixed_height)
3394 *new_node = height / fixed_height;
3395 return height % fixed_height;
3400 pspp_sheet_view_update_rubber_band_selection (PsppSheetView *tree_view)
3405 pspp_sheet_view_find_offset (tree_view, MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y), &start_node);
3406 pspp_sheet_view_find_offset (tree_view, MAX (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y), &end_node);
3408 /* Handle the start area first */
3409 if (tree_view->priv->rubber_band_start_node < 0)
3411 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3418 else if (start_node < tree_view->priv->rubber_band_start_node)
3420 /* New node is above the old one; selection became bigger */
3421 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3423 tree_view->priv->rubber_band_start_node,
3428 else if (start_node > tree_view->priv->rubber_band_start_node)
3430 /* New node is below the old one; selection became smaller */
3431 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3432 tree_view->priv->rubber_band_start_node,
3439 tree_view->priv->rubber_band_start_node = start_node;
3441 /* Next, handle the end area */
3442 if (tree_view->priv->rubber_band_end_node < 0)
3444 /* In the event this happens, start_node was also -1; this case is
3448 else if (end_node < 0)
3450 /* Find the last node in the tree */
3451 pspp_sheet_view_find_offset (tree_view, tree_view->priv->height - 1,
3454 /* Selection reached end of the tree */
3455 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3456 tree_view->priv->rubber_band_end_node,
3462 else if (end_node > tree_view->priv->rubber_band_end_node)
3464 /* New node is below the old one; selection became bigger */
3465 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3466 tree_view->priv->rubber_band_end_node,
3472 else if (end_node < tree_view->priv->rubber_band_end_node)
3474 /* New node is above the old one; selection became smaller */
3475 pspp_sheet_view_update_rubber_band_selection_range (tree_view,
3477 tree_view->priv->rubber_band_end_node,
3483 tree_view->priv->rubber_band_end_node = end_node;
3487 pspp_sheet_view_update_rubber_band (PsppSheetView *tree_view)
3490 GdkRectangle old_area;
3491 GdkRectangle new_area;
3492 GdkRectangle common;
3493 GdkRegion *invalid_region;
3494 PsppSheetViewColumn *column;
3496 old_area.x = MIN (tree_view->priv->press_start_x, tree_view->priv->rubber_band_x);
3497 old_area.y = MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y) - tree_view->priv->dy;
3498 old_area.width = ABS (tree_view->priv->rubber_band_x - tree_view->priv->press_start_x) + 1;
3499 old_area.height = ABS (tree_view->priv->rubber_band_y - tree_view->priv->press_start_y) + 1;
3501 gdk_window_get_pointer (tree_view->priv->bin_window, &x, &y, NULL);
3504 y = MAX (y, 0) + tree_view->priv->dy;
3506 new_area.x = MIN (tree_view->priv->press_start_x, x);
3507 new_area.y = MIN (tree_view->priv->press_start_y, y) - tree_view->priv->dy;
3508 new_area.width = ABS (x - tree_view->priv->press_start_x) + 1;
3509 new_area.height = ABS (y - tree_view->priv->press_start_y) + 1;
3511 invalid_region = gdk_region_rectangle (&old_area);
3512 gdk_region_union_with_rect (invalid_region, &new_area);
3514 gdk_rectangle_intersect (&old_area, &new_area, &common);
3515 if (common.width > 2 && common.height > 2)
3517 GdkRegion *common_region;
3519 /* make sure the border is invalidated */
3525 common_region = gdk_region_rectangle (&common);
3527 gdk_region_subtract (invalid_region, common_region);
3528 gdk_region_destroy (common_region);
3531 gdk_window_invalidate_region (tree_view->priv->bin_window, invalid_region, TRUE);
3533 gdk_region_destroy (invalid_region);
3535 tree_view->priv->rubber_band_x = x;
3536 tree_view->priv->rubber_band_y = y;
3537 pspp_sheet_view_get_path_at_pos (tree_view, x, y, NULL, &column, NULL, NULL);
3539 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
3540 pspp_sheet_selection_select_column_range (tree_view->priv->selection,
3541 tree_view->priv->anchor_column,
3544 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
3546 pspp_sheet_view_update_rubber_band_selection (tree_view);
3550 pspp_sheet_view_paint_rubber_band (PsppSheetView *tree_view,
3555 GdkRectangle rubber_rect;
3558 rubber_rect.x = MIN (tree_view->priv->press_start_x, tree_view->priv->rubber_band_x);
3559 rubber_rect.y = MIN (tree_view->priv->press_start_y, tree_view->priv->rubber_band_y) - tree_view->priv->dy;
3560 rubber_rect.width = ABS (tree_view->priv->press_start_x - tree_view->priv->rubber_band_x) + 1;
3561 rubber_rect.height = ABS (tree_view->priv->press_start_y - tree_view->priv->rubber_band_y) + 1;
3563 if (!gdk_rectangle_intersect (&rubber_rect, area, &rect))
3566 cr = gdk_cairo_create (tree_view->priv->bin_window);
3567 cairo_set_line_width (cr, 1.0);
3569 cairo_set_source_rgba (cr,
3570 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].red / 65535.,
3571 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].green / 65535.,
3572 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].blue / 65535.,
3575 gdk_cairo_rectangle (cr, &rect);
3579 cairo_set_source_rgb (cr,
3580 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].red / 65535.,
3581 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].green / 65535.,
3582 GTK_WIDGET (tree_view)->style->fg[GTK_STATE_NORMAL].blue / 65535.);
3584 cairo_rectangle (cr,
3585 rubber_rect.x + 0.5, rubber_rect.y + 0.5,
3586 rubber_rect.width - 1, rubber_rect.height - 1);
3593 pspp_sheet_view_motion_bin_window (GtkWidget *widget,
3594 GdkEventMotion *event)
3596 PsppSheetView *tree_view;
3600 tree_view = (PsppSheetView *) widget;
3602 if (tree_view->priv->row_count == 0)
3605 if (tree_view->priv->rubber_band_status == RUBBER_BAND_MAYBE_START)
3607 GdkRectangle background_area, cell_area;
3608 PsppSheetViewColumn *column;
3610 if (find_click (tree_view, event->x, event->y, &node, &column,
3611 &background_area, &cell_area)
3612 && tree_view->priv->focus_column == column
3613 && tree_view->priv->press_start_node == node)
3616 gtk_grab_add (GTK_WIDGET (tree_view));
3617 pspp_sheet_view_update_rubber_band (tree_view);
3619 tree_view->priv->rubber_band_status = RUBBER_BAND_ACTIVE;
3621 else if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
3623 pspp_sheet_view_update_rubber_band (tree_view);
3625 add_scroll_timeout (tree_view);
3628 /* only check for an initiated drag when a button is pressed */
3629 if (tree_view->priv->pressed_button >= 0
3630 && !tree_view->priv->rubber_band_status)
3631 pspp_sheet_view_maybe_begin_dragging_row (tree_view, event);
3633 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, event->y);
3637 pspp_sheet_view_find_offset (tree_view, new_y, &node);
3639 tree_view->priv->event_last_x = event->x;
3640 tree_view->priv->event_last_y = event->y;
3642 prelight_or_select (tree_view, node, event->x, event->y);
3648 pspp_sheet_view_motion (GtkWidget *widget,
3649 GdkEventMotion *event)
3651 PsppSheetView *tree_view;
3653 tree_view = (PsppSheetView *) widget;
3655 /* Resizing a column */
3656 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE))
3657 return pspp_sheet_view_motion_resize_column (widget, event);
3660 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
3661 return pspp_sheet_view_motion_drag_column (widget, event);
3663 /* Sanity check it */
3664 if (event->window == tree_view->priv->bin_window)
3665 return pspp_sheet_view_motion_bin_window (widget, event);
3670 /* Invalidate the focus rectangle near the edge of the bin_window; used when
3671 * the tree is empty.
3674 invalidate_empty_focus (PsppSheetView *tree_view)
3678 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
3683 gdk_drawable_get_size (tree_view->priv->bin_window, &area.width, &area.height);
3684 gdk_window_invalidate_rect (tree_view->priv->bin_window, &area, FALSE);
3687 /* Draws a focus rectangle near the edge of the bin_window; used when the tree
3691 draw_empty_focus (PsppSheetView *tree_view, GdkRectangle *clip_area)
3693 GtkWidget *widget = GTK_WIDGET (tree_view);
3696 if (!gtk_widget_has_focus (widget))
3699 gdk_drawable_get_size (tree_view->priv->bin_window, &w, &h);
3705 gtk_paint_focus (gtk_widget_get_style (widget),
3706 tree_view->priv->bin_window,
3707 gtk_widget_get_state (widget),
3715 pspp_sheet_view_draw_grid_lines (PsppSheetView *tree_view,
3716 GdkEventExpose *event,
3717 gint n_visible_columns,
3721 GList *list = tree_view->priv->columns;
3726 if (tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
3727 && tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_BOTH)
3730 gdk_drawable_get_size (event->window, NULL, &height);
3732 /* Only draw the lines for visible rows and columns */
3733 for (list = tree_view->priv->columns; list; list = list->next, i++)
3735 PsppSheetViewColumn *column = list->data;
3737 /* We don't want a line for the last column */
3738 if (i == n_visible_columns - 1)
3741 if (! column->visible)
3744 current_x += column->width;
3746 if (current_x - 1 >= event->area.x
3747 && current_x - 1 < event->area.x + event->area.width)
3748 gdk_draw_line (event->window,
3749 tree_view->priv->grid_line_gc[GTK_WIDGET(tree_view)->state],
3750 current_x - 1, min_y,
3751 current_x - 1, max_y - min_y);
3755 /* Warning: Very scary function.
3756 * Modify at your own risk
3758 * KEEP IN SYNC WITH pspp_sheet_view_create_row_drag_icon()!
3759 * FIXME: It's not...
3762 pspp_sheet_view_bin_expose (GtkWidget *widget,
3763 GdkEventExpose *event)
3765 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
3770 int drag_highlight = -1;
3773 gint y_offset, cell_offset;
3775 GdkRectangle background_area;
3776 GdkRectangle cell_area;
3778 gint bin_window_width;
3779 gint bin_window_height;
3780 GtkTreePath *cursor_path;
3781 GtkTreePath *drag_dest_path;
3782 GList *first_column, *last_column;
3783 gint vertical_separator;
3784 gint horizontal_separator;
3785 gint focus_line_width;
3786 gboolean allow_rules;
3787 gboolean has_special_cell;
3789 gint n_visible_columns;
3790 gint grid_line_width;
3791 gboolean row_ending_details;
3792 gboolean draw_vgrid_lines, draw_hgrid_lines;
3795 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
3797 gtk_widget_style_get (widget,
3798 "horizontal-separator", &horizontal_separator,
3799 "vertical-separator", &vertical_separator,
3800 "allow-rules", &allow_rules,
3801 "focus-line-width", &focus_line_width,
3802 "row-ending-details", &row_ending_details,
3805 if (tree_view->priv->row_count == 0)
3807 draw_empty_focus (tree_view, &event->area);
3811 /* clip event->area to the visible area */
3812 if (event->area.height < 0)
3815 validate_visible_area (tree_view);
3817 new_y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, event->area.y);
3821 y_offset = -pspp_sheet_view_find_offset (tree_view, new_y, &node);
3822 gdk_drawable_get_size (tree_view->priv->bin_window,
3823 &bin_window_width, &bin_window_height);
3825 if (tree_view->priv->height < bin_window_height)
3827 gtk_paint_flat_box (widget->style,
3834 0, tree_view->priv->height,
3836 bin_window_height - tree_view->priv->height);
3842 /* find the path for the node */
3843 path = _pspp_sheet_view_find_path ((PsppSheetView *)widget, node);
3844 gtk_tree_model_get_iter (tree_view->priv->model,
3847 gtk_tree_path_free (path);
3850 drag_dest_path = NULL;
3852 if (tree_view->priv->cursor)
3853 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
3856 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor);
3858 if (tree_view->priv->drag_dest_row)
3859 drag_dest_path = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
3862 _pspp_sheet_view_find_node (tree_view, drag_dest_path,
3866 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
3867 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
3869 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
3870 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
3872 if (draw_vgrid_lines || draw_hgrid_lines)
3873 gtk_widget_style_get (widget, "grid-line-width", &grid_line_width, NULL);
3875 n_visible_columns = 0;
3876 for (list = tree_view->priv->columns; list; list = list->next)
3878 if (! PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
3880 n_visible_columns ++;
3883 /* Find the last column */
3884 for (last_column = g_list_last (tree_view->priv->columns);
3885 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
3886 last_column = last_column->prev)
3890 for (first_column = g_list_first (tree_view->priv->columns);
3891 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
3892 first_column = first_column->next)
3895 /* Actually process the expose event. To do this, we want to
3896 * start at the first node of the event, and walk the tree in
3897 * order, drawing each successive node.
3904 gboolean is_first = FALSE;
3905 gboolean is_last = FALSE;
3906 gboolean done = FALSE;
3909 max_height = ROW_HEIGHT (tree_view);
3913 background_area.y = y_offset + event->area.y;
3914 background_area.height = max_height;
3915 max_y = background_area.y + max_height;
3919 if (node == tree_view->priv->prelight_node)
3920 flags |= GTK_CELL_RENDERER_PRELIT;
3922 selected = pspp_sheet_view_node_is_selected (tree_view, node);
3926 if (tree_view->priv->special_cells == PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT)
3928 /* we *need* to set cell data on all cells before the call
3929 * to _has_special_cell, else _has_special_cell() does not
3930 * return a correct value.
3932 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
3934 list = (rtl ? list->prev : list->next))
3936 PsppSheetViewColumn *column = list->data;
3937 pspp_sheet_view_column_cell_set_cell_data (column,
3938 tree_view->priv->model,
3942 has_special_cell = pspp_sheet_view_has_special_cell (tree_view);
3945 has_special_cell = tree_view->priv->special_cells == PSPP_SHEET_VIEW_SPECIAL_CELLS_YES;
3947 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
3949 list = (rtl ? list->prev : list->next))
3951 PsppSheetViewColumn *column = list->data;
3952 const gchar *detail = NULL;
3953 gboolean selected_column;
3956 if (!column->visible)
3959 if (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE)
3960 selected_column = column->selected && column->selectable;
3962 selected_column = TRUE;
3964 if (cell_offset > event->area.x + event->area.width ||
3965 cell_offset + column->width < event->area.x)
3967 cell_offset += column->width;
3971 if (selected && selected_column)
3972 flags |= GTK_CELL_RENDERER_SELECTED;
3974 flags &= ~GTK_CELL_RENDERER_SELECTED;
3976 if (column->show_sort_indicator)
3977 flags |= GTK_CELL_RENDERER_SORTED;
3979 flags &= ~GTK_CELL_RENDERER_SORTED;
3982 flags |= GTK_CELL_RENDERER_FOCUSED;
3984 flags &= ~GTK_CELL_RENDERER_FOCUSED;
3986 background_area.x = cell_offset;
3987 background_area.width = column->width;
3989 cell_area = background_area;
3990 cell_area.y += vertical_separator / 2;
3991 cell_area.x += horizontal_separator / 2;
3992 cell_area.height -= vertical_separator;
3993 cell_area.width -= horizontal_separator;
3995 if (draw_vgrid_lines)
3997 if (list == first_column)
3999 cell_area.width -= grid_line_width / 2;
4001 else if (list == last_column)
4003 cell_area.x += grid_line_width / 2;
4004 cell_area.width -= grid_line_width / 2;
4008 cell_area.x += grid_line_width / 2;
4009 cell_area.width -= grid_line_width;
4013 if (draw_hgrid_lines)
4015 cell_area.y += grid_line_width / 2;
4016 cell_area.height -= grid_line_width;
4019 if (gdk_region_rect_in (event->region, &background_area) == GDK_OVERLAP_RECTANGLE_OUT)
4021 cell_offset += column->width;
4025 pspp_sheet_view_column_cell_set_cell_data (column,
4026 tree_view->priv->model,
4029 /* Select the detail for drawing the cell. relevant
4030 * factors are parity, sortedness, and whether to
4033 if (allow_rules && tree_view->priv->has_rules)
4035 if ((flags & GTK_CELL_RENDERER_SORTED) &&
4036 n_visible_columns >= 3)
4039 detail = "cell_odd_ruled_sorted";
4041 detail = "cell_even_ruled_sorted";
4046 detail = "cell_odd_ruled";
4048 detail = "cell_even_ruled";
4053 if ((flags & GTK_CELL_RENDERER_SORTED) &&
4054 n_visible_columns >= 3)
4057 detail = "cell_odd_sorted";
4059 detail = "cell_even_sorted";
4064 detail = "cell_odd";
4066 detail = "cell_even";
4072 if (widget->state == GTK_STATE_INSENSITIVE)
4073 state = GTK_STATE_INSENSITIVE;
4074 else if (flags & GTK_CELL_RENDERER_SELECTED)
4075 state = GTK_STATE_SELECTED;
4077 state = GTK_STATE_NORMAL;
4079 /* Draw background */
4080 if (row_ending_details)
4082 char new_detail[128];
4084 is_first = (rtl ? !list->next : !list->prev);
4085 is_last = (rtl ? !list->prev : !list->next);
4087 /* (I don't like the snprintfs either, but couldn't find a
4090 if (is_first && is_last)
4091 g_snprintf (new_detail, 127, "%s", detail);
4093 g_snprintf (new_detail, 127, "%s_start", detail);
4095 g_snprintf (new_detail, 127, "%s_end", detail);
4097 g_snprintf (new_detail, 128, "%s_middle", detail);
4099 gtk_paint_flat_box (widget->style,
4108 background_area.width,
4109 background_area.height);
4113 gtk_paint_flat_box (widget->style,
4122 background_area.width,
4123 background_area.height);
4126 if (draw_hgrid_lines)
4128 if (background_area.y > 0)
4129 gdk_draw_line (event->window,
4130 tree_view->priv->grid_line_gc[widget->state],
4131 background_area.x, background_area.y,
4132 background_area.x + background_area.width,
4135 if (y_offset + max_height >= event->area.height)
4136 gdk_draw_line (event->window,
4137 tree_view->priv->grid_line_gc[widget->state],
4138 background_area.x, background_area.y + max_height,
4139 background_area.x + background_area.width,
4140 background_area.y + max_height);
4143 _pspp_sheet_view_column_cell_render (column,
4150 if (node == cursor && has_special_cell &&
4151 ((column == tree_view->priv->focus_column &&
4152 PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS) &&
4153 gtk_widget_has_focus (widget)) ||
4154 (column == tree_view->priv->edited_column)))
4156 _pspp_sheet_view_column_cell_draw_focus (column,
4164 cell_offset += column->width;
4167 if (cell_offset < event->area.x)
4169 gtk_paint_flat_box (widget->style,
4178 event->area.x - cell_offset,
4179 background_area.height);
4182 if (node == drag_highlight)
4184 /* Draw indicator for the drop
4186 gint highlight_y = -1;
4190 switch (tree_view->priv->drag_dest_pos)
4192 case PSPP_SHEET_VIEW_DROP_BEFORE:
4193 highlight_y = background_area.y - 1;
4194 if (highlight_y < 0)
4198 case PSPP_SHEET_VIEW_DROP_AFTER:
4199 highlight_y = background_area.y + background_area.height - 1;
4202 case PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE:
4203 case PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER:
4204 _pspp_sheet_view_find_node (tree_view, drag_dest_path, &node);
4208 gdk_drawable_get_size (tree_view->priv->bin_window,
4211 if (row_ending_details)
4212 gtk_paint_focus (widget->style,
4213 tree_view->priv->bin_window,
4214 gtk_widget_get_state (widget),
4218 ? (is_last ? "treeview-drop-indicator" : "treeview-drop-indicator-left" )
4219 : (is_last ? "treeview-drop-indicator-right" : "tree-view-drop-indicator-middle" )),
4220 0, BACKGROUND_FIRST_PIXEL (tree_view, node)
4221 - focus_line_width / 2,
4222 width, ROW_HEIGHT (tree_view)
4223 - focus_line_width + 1);
4225 gtk_paint_focus (widget->style,
4226 tree_view->priv->bin_window,
4227 gtk_widget_get_state (widget),
4230 "treeview-drop-indicator",
4231 0, BACKGROUND_FIRST_PIXEL (tree_view, node)
4232 - focus_line_width / 2,
4233 width, ROW_HEIGHT (tree_view)
4234 - focus_line_width + 1);
4238 if (highlight_y >= 0)
4240 gdk_draw_line (event->window,
4241 widget->style->fg_gc[gtk_widget_get_state (widget)],
4244 rtl ? 0 : bin_window_width,
4249 /* draw the big row-spanning focus rectangle, if needed */
4250 if (!has_special_cell && node == cursor &&
4251 PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS) &&
4252 gtk_widget_has_focus (widget))
4254 gint tmp_y, tmp_height;
4256 GtkStateType focus_rect_state;
4259 flags & GTK_CELL_RENDERER_SELECTED ? GTK_STATE_SELECTED :
4260 (flags & GTK_CELL_RENDERER_PRELIT ? GTK_STATE_PRELIGHT :
4261 (flags & GTK_CELL_RENDERER_INSENSITIVE ? GTK_STATE_INSENSITIVE :
4264 gdk_drawable_get_size (tree_view->priv->bin_window,
4267 if (draw_hgrid_lines)
4269 tmp_y = BACKGROUND_FIRST_PIXEL (tree_view, node) + grid_line_width / 2;
4270 tmp_height = ROW_HEIGHT (tree_view) - grid_line_width;
4274 tmp_y = BACKGROUND_FIRST_PIXEL (tree_view, node);
4275 tmp_height = ROW_HEIGHT (tree_view);
4278 if (row_ending_details)
4279 gtk_paint_focus (widget->style,
4280 tree_view->priv->bin_window,
4285 ? (is_last ? "treeview" : "treeview-left" )
4286 : (is_last ? "treeview-right" : "treeview-middle" )),
4290 gtk_paint_focus (widget->style,
4291 tree_view->priv->bin_window,
4300 y_offset += max_height;
4304 node = pspp_sheet_view_node_next (tree_view, node);
4307 gboolean has_next = gtk_tree_model_iter_next (tree_view->priv->model, &iter);
4311 TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
4318 while (y_offset < event->area.height);
4321 pspp_sheet_view_draw_grid_lines (tree_view, event, n_visible_columns,
4324 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
4326 GdkRectangle *rectangles;
4329 gdk_region_get_rectangles (event->region,
4333 while (n_rectangles--)
4334 pspp_sheet_view_paint_rubber_band (tree_view, &rectangles[n_rectangles]);
4336 g_free (rectangles);
4340 gtk_tree_path_free (cursor_path);
4343 gtk_tree_path_free (drag_dest_path);
4349 pspp_sheet_view_expose (GtkWidget *widget,
4350 GdkEventExpose *event)
4352 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4354 if (event->window == tree_view->priv->bin_window)
4359 retval = pspp_sheet_view_bin_expose (widget, event);
4361 /* We can't just chain up to Container::expose as it will try to send the
4362 * event to the headers, so we handle propagating it to our children
4363 * (eg. widgets being edited) ourselves.
4365 tmp_list = tree_view->priv->children;
4368 PsppSheetViewChild *child = tmp_list->data;
4369 tmp_list = tmp_list->next;
4371 gtk_container_propagate_expose (GTK_CONTAINER (tree_view), child->widget, event);
4377 else if (event->window == tree_view->priv->header_window)
4379 gint n_visible_columns;
4382 gtk_paint_flat_box (widget->style,
4392 event->area.height);
4394 for (list = tree_view->priv->columns; list != NULL; list = list->next)
4396 PsppSheetViewColumn *column = list->data;
4398 if (column == tree_view->priv->drag_column || !column->visible)
4401 if (span_intersects (column->allocation.x, column->allocation.width,
4402 event->area.x, event->area.width)
4403 && column->button != NULL)
4404 gtk_container_propagate_expose (GTK_CONTAINER (tree_view),
4405 column->button, event);
4408 n_visible_columns = 0;
4409 for (list = tree_view->priv->columns; list; list = list->next)
4411 if (! PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
4413 n_visible_columns ++;
4415 pspp_sheet_view_draw_grid_lines (tree_view,
4419 event->area.height);
4421 else if (event->window == tree_view->priv->drag_window)
4423 gtk_container_propagate_expose (GTK_CONTAINER (tree_view),
4424 tree_view->priv->drag_column->button,
4438 /* returns 0x1 when no column has been found -- yes it's hackish */
4439 static PsppSheetViewColumn *
4440 pspp_sheet_view_get_drop_column (PsppSheetView *tree_view,
4441 PsppSheetViewColumn *column,
4444 PsppSheetViewColumn *left_column = NULL;
4445 PsppSheetViewColumn *cur_column = NULL;
4448 if (!column->reorderable)
4449 return (PsppSheetViewColumn *)0x1;
4451 switch (drop_position)
4454 /* find first column where we can drop */
4455 tmp_list = tree_view->priv->columns;
4456 if (column == PSPP_SHEET_VIEW_COLUMN (tmp_list->data))
4457 return (PsppSheetViewColumn *)0x1;
4461 g_assert (tmp_list);
4463 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4464 tmp_list = tmp_list->next;
4466 if (left_column && left_column->visible == FALSE)
4469 if (!tree_view->priv->column_drop_func)
4472 if (!tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4474 left_column = cur_column;
4481 if (!tree_view->priv->column_drop_func)
4484 if (tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data))
4487 return (PsppSheetViewColumn *)0x1;
4491 /* find first column after column where we can drop */
4492 tmp_list = tree_view->priv->columns;
4494 for (; tmp_list; tmp_list = tmp_list->next)
4495 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data) == column)
4498 if (!tmp_list || !tmp_list->next)
4499 return (PsppSheetViewColumn *)0x1;
4501 tmp_list = tmp_list->next;
4502 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4503 tmp_list = tmp_list->next;
4507 g_assert (tmp_list);
4509 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4510 tmp_list = tmp_list->next;
4512 if (left_column && left_column->visible == FALSE)
4514 left_column = cur_column;
4516 tmp_list = tmp_list->next;
4520 if (!tree_view->priv->column_drop_func)
4523 if (!tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4525 left_column = cur_column;
4532 if (!tree_view->priv->column_drop_func)
4535 if (tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data))
4538 return (PsppSheetViewColumn *)0x1;
4542 /* find first column before column where we can drop */
4543 tmp_list = tree_view->priv->columns;
4545 for (; tmp_list; tmp_list = tmp_list->next)
4546 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data) == column)
4549 if (!tmp_list || !tmp_list->prev)
4550 return (PsppSheetViewColumn *)0x1;
4552 tmp_list = tmp_list->prev;
4553 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4554 tmp_list = tmp_list->prev;
4558 g_assert (tmp_list);
4560 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4562 if (left_column && !left_column->visible)
4564 /*if (!tmp_list->prev)
4565 return (PsppSheetViewColumn *)0x1;
4568 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->prev->data);
4569 tmp_list = tmp_list->prev->prev;
4572 cur_column = left_column;
4574 tmp_list = tmp_list->prev;
4578 if (!tree_view->priv->column_drop_func)
4581 if (tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4584 cur_column = left_column;
4585 tmp_list = tmp_list->prev;
4588 if (!tree_view->priv->column_drop_func)
4591 if (tree_view->priv->column_drop_func (tree_view, column, NULL, cur_column, tree_view->priv->column_drop_func_data))
4594 return (PsppSheetViewColumn *)0x1;
4598 /* same as DROP_HOME case, but doing it backwards */
4599 tmp_list = g_list_last (tree_view->priv->columns);
4602 if (column == PSPP_SHEET_VIEW_COLUMN (tmp_list->data))
4603 return (PsppSheetViewColumn *)0x1;
4607 g_assert (tmp_list);
4609 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4611 if (left_column && !left_column->visible)
4613 cur_column = left_column;
4614 tmp_list = tmp_list->prev;
4617 if (!tree_view->priv->column_drop_func)
4620 if (tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4623 cur_column = left_column;
4624 tmp_list = tmp_list->prev;
4627 if (!tree_view->priv->column_drop_func)
4630 if (tree_view->priv->column_drop_func (tree_view, column, NULL, cur_column, tree_view->priv->column_drop_func_data))
4633 return (PsppSheetViewColumn *)0x1;
4637 return (PsppSheetViewColumn *)0x1;
4641 pspp_sheet_view_key_press (GtkWidget *widget,
4644 PsppSheetView *tree_view = (PsppSheetView *) widget;
4646 if (tree_view->priv->rubber_band_status)
4648 if (event->keyval == GDK_Escape)
4649 pspp_sheet_view_stop_rubber_band (tree_view);
4654 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
4656 if (event->keyval == GDK_Escape)
4658 tree_view->priv->cur_reorder = NULL;
4659 pspp_sheet_view_button_release_drag_column (widget, NULL);
4664 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
4666 GList *focus_column;
4669 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
4671 for (focus_column = tree_view->priv->columns;
4673 focus_column = focus_column->next)
4675 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4677 if (column->button && gtk_widget_has_focus (column->button))
4682 (event->state & GDK_SHIFT_MASK) && (event->state & GDK_MOD1_MASK) &&
4683 (event->keyval == GDK_Left || event->keyval == GDK_KP_Left
4684 || event->keyval == GDK_Right || event->keyval == GDK_KP_Right))
4686 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4688 if (!column->resizable)
4690 gtk_widget_error_bell (widget);
4694 if (event->keyval == (rtl ? GDK_Right : GDK_Left)
4695 || event->keyval == (rtl ? GDK_KP_Right : GDK_KP_Left))
4697 gint old_width = column->resized_width;
4699 column->resized_width = MAX (column->resized_width,
4701 column->resized_width -= 2;
4702 if (column->resized_width < 0)
4703 column->resized_width = 0;
4705 if (column->min_width == -1)
4706 column->resized_width = MAX (column->button_request,
4707 column->resized_width);
4709 column->resized_width = MAX (column->min_width,
4710 column->resized_width);
4712 if (column->max_width != -1)
4713 column->resized_width = MIN (column->resized_width,
4716 column->use_resized_width = TRUE;
4718 if (column->resized_width != old_width)
4719 gtk_widget_queue_resize (widget);
4721 gtk_widget_error_bell (widget);
4723 else if (event->keyval == (rtl ? GDK_Left : GDK_Right)
4724 || event->keyval == (rtl ? GDK_KP_Left : GDK_KP_Right))
4726 gint old_width = column->resized_width;
4728 column->resized_width = MAX (column->resized_width,
4730 column->resized_width += 2;
4732 if (column->max_width != -1)
4733 column->resized_width = MIN (column->resized_width,
4736 column->use_resized_width = TRUE;
4738 if (column->resized_width != old_width)
4739 gtk_widget_queue_resize (widget);
4741 gtk_widget_error_bell (widget);
4748 (event->state & GDK_MOD1_MASK) &&
4749 (event->keyval == GDK_Left || event->keyval == GDK_KP_Left
4750 || event->keyval == GDK_Right || event->keyval == GDK_KP_Right
4751 || event->keyval == GDK_Home || event->keyval == GDK_KP_Home
4752 || event->keyval == GDK_End || event->keyval == GDK_KP_End))
4754 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4756 if (event->keyval == (rtl ? GDK_Right : GDK_Left)
4757 || event->keyval == (rtl ? GDK_KP_Right : GDK_KP_Left))
4759 PsppSheetViewColumn *col;
4760 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_LEFT);
4761 if (col != (PsppSheetViewColumn *)0x1)
4762 pspp_sheet_view_move_column_after (tree_view, column, col);
4764 gtk_widget_error_bell (widget);
4766 else if (event->keyval == (rtl ? GDK_Left : GDK_Right)
4767 || event->keyval == (rtl ? GDK_KP_Left : GDK_KP_Right))
4769 PsppSheetViewColumn *col;
4770 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_RIGHT);
4771 if (col != (PsppSheetViewColumn *)0x1)
4772 pspp_sheet_view_move_column_after (tree_view, column, col);
4774 gtk_widget_error_bell (widget);
4776 else if (event->keyval == GDK_Home || event->keyval == GDK_KP_Home)
4778 PsppSheetViewColumn *col;
4779 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_HOME);
4780 if (col != (PsppSheetViewColumn *)0x1)
4781 pspp_sheet_view_move_column_after (tree_view, column, col);
4783 gtk_widget_error_bell (widget);
4785 else if (event->keyval == GDK_End || event->keyval == GDK_KP_End)
4787 PsppSheetViewColumn *col;
4788 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_END);
4789 if (col != (PsppSheetViewColumn *)0x1)
4790 pspp_sheet_view_move_column_after (tree_view, column, col);
4792 gtk_widget_error_bell (widget);
4799 /* Chain up to the parent class. It handles the keybindings. */
4800 if (GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->key_press_event (widget, event))
4803 if (tree_view->priv->search_entry_avoid_unhandled_binding)
4805 tree_view->priv->search_entry_avoid_unhandled_binding = FALSE;
4809 /* We pass the event to the search_entry. If its text changes, then we start
4810 * the typeahead find capabilities. */
4811 if (gtk_widget_has_focus (GTK_WIDGET (tree_view))
4812 && tree_view->priv->enable_search
4813 && !tree_view->priv->search_custom_entry_set)
4815 GdkEvent *new_event;
4817 const char *new_text;
4820 gboolean text_modified;
4821 gulong popup_menu_id;
4823 pspp_sheet_view_ensure_interactive_directory (tree_view);
4825 /* Make a copy of the current text */
4826 old_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry)));
4827 new_event = gdk_event_copy ((GdkEvent *) event);
4828 g_object_unref (((GdkEventKey *) new_event)->window);
4829 ((GdkEventKey *) new_event)->window = g_object_ref (tree_view->priv->search_window->window);
4830 gtk_widget_realize (tree_view->priv->search_window);
4832 popup_menu_id = g_signal_connect (tree_view->priv->search_entry,
4833 "popup-menu", G_CALLBACK (gtk_true),
4836 /* Move the entry off screen */
4837 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
4838 gtk_window_move (GTK_WINDOW (tree_view->priv->search_window),
4839 gdk_screen_get_width (screen) + 1,
4840 gdk_screen_get_height (screen) + 1);
4841 gtk_widget_show (tree_view->priv->search_window);
4843 /* Send the event to the window. If the preedit_changed signal is emitted
4844 * during this event, we will set priv->imcontext_changed */
4845 tree_view->priv->imcontext_changed = FALSE;
4846 retval = gtk_widget_event (tree_view->priv->search_window, new_event);
4847 gdk_event_free (new_event);
4848 gtk_widget_hide (tree_view->priv->search_window);
4850 g_signal_handler_disconnect (tree_view->priv->search_entry,
4853 /* We check to make sure that the entry tried to handle the text, and that
4854 * the text has changed.
4856 new_text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
4857 text_modified = strcmp (old_text, new_text) != 0;
4859 if (tree_view->priv->imcontext_changed || /* we're in a preedit */
4860 (retval && text_modified)) /* ...or the text was modified */
4862 if (pspp_sheet_view_real_start_interactive_search (tree_view, FALSE))
4864 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
4869 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
4879 pspp_sheet_view_key_release (GtkWidget *widget,
4882 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4884 if (tree_view->priv->rubber_band_status)
4887 return GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->key_release_event (widget, event);
4890 /* FIXME Is this function necessary? Can I get an enter_notify event
4891 * w/o either an expose event or a mouse motion event?
4894 pspp_sheet_view_enter_notify (GtkWidget *widget,
4895 GdkEventCrossing *event)
4897 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4901 /* Sanity check it */
4902 if (event->window != tree_view->priv->bin_window)
4905 if (tree_view->priv->row_count == 0)
4908 if (event->mode == GDK_CROSSING_GRAB ||
4909 event->mode == GDK_CROSSING_GTK_GRAB ||
4910 event->mode == GDK_CROSSING_GTK_UNGRAB ||
4911 event->mode == GDK_CROSSING_STATE_CHANGED)
4914 /* find the node internally */
4915 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, event->y);
4918 pspp_sheet_view_find_offset (tree_view, new_y, &node);
4920 tree_view->priv->event_last_x = event->x;
4921 tree_view->priv->event_last_y = event->y;
4923 prelight_or_select (tree_view, node, event->x, event->y);
4929 pspp_sheet_view_leave_notify (GtkWidget *widget,
4930 GdkEventCrossing *event)
4932 PsppSheetView *tree_view;
4934 if (event->mode == GDK_CROSSING_GRAB)
4937 tree_view = PSPP_SHEET_VIEW (widget);
4939 if (tree_view->priv->prelight_node >= 0)
4940 _pspp_sheet_view_queue_draw_node (tree_view,
4941 tree_view->priv->prelight_node,
4944 tree_view->priv->event_last_x = -10000;
4945 tree_view->priv->event_last_y = -10000;
4947 prelight_or_select (tree_view,
4949 -1000, -1000); /* coords not possibly over an arrow */
4956 pspp_sheet_view_focus_out (GtkWidget *widget,
4957 GdkEventFocus *event)
4959 PsppSheetView *tree_view;
4961 tree_view = PSPP_SHEET_VIEW (widget);
4963 gtk_widget_queue_draw (widget);
4965 /* destroy interactive search dialog */
4966 if (tree_view->priv->search_window)
4967 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
4973 /* Incremental Reflow
4977 pspp_sheet_view_node_queue_redraw (PsppSheetView *tree_view,
4982 y = pspp_sheet_view_node_find_offset (tree_view, node)
4983 - tree_view->priv->vadjustment->value
4984 + TREE_VIEW_HEADER_HEIGHT (tree_view);
4986 gtk_widget_queue_draw_area (GTK_WIDGET (tree_view),
4988 GTK_WIDGET (tree_view)->allocation.width,
4989 tree_view->priv->fixed_height);
4993 node_is_visible (PsppSheetView *tree_view,
4999 y = pspp_sheet_view_node_find_offset (tree_view, node);
5000 height = ROW_HEIGHT (tree_view);
5002 if (y >= tree_view->priv->vadjustment->value &&
5003 y + height <= (tree_view->priv->vadjustment->value
5004 + tree_view->priv->vadjustment->page_size))
5010 /* Returns the row height. */
5012 validate_row (PsppSheetView *tree_view,
5017 PsppSheetViewColumn *column;
5018 GList *list, *first_column, *last_column;
5020 gint horizontal_separator;
5021 gint vertical_separator;
5022 gint focus_line_width;
5023 gboolean draw_vgrid_lines, draw_hgrid_lines;
5025 gint grid_line_width;
5026 gboolean wide_separators;
5027 gint separator_height;
5029 gtk_widget_style_get (GTK_WIDGET (tree_view),
5030 "focus-padding", &focus_pad,
5031 "focus-line-width", &focus_line_width,
5032 "horizontal-separator", &horizontal_separator,
5033 "vertical-separator", &vertical_separator,
5034 "grid-line-width", &grid_line_width,
5035 "wide-separators", &wide_separators,
5036 "separator-height", &separator_height,
5040 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
5041 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
5043 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
5044 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
5046 for (last_column = g_list_last (tree_view->priv->columns);
5047 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
5048 last_column = last_column->prev)
5051 for (first_column = g_list_first (tree_view->priv->columns);
5052 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
5053 first_column = first_column->next)
5056 for (list = tree_view->priv->columns; list; list = list->next)
5061 column = list->data;
5063 if (! column->visible)
5066 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, iter);
5067 pspp_sheet_view_column_cell_get_size (column,
5069 &tmp_width, &tmp_height);
5071 tmp_height += vertical_separator;
5072 height = MAX (height, tmp_height);
5074 tmp_width = tmp_width + horizontal_separator;
5076 if (draw_vgrid_lines)
5078 if (list->data == first_column || list->data == last_column)
5079 tmp_width += grid_line_width / 2.0;
5081 tmp_width += grid_line_width;
5084 if (tmp_width > column->requested_width)
5085 column->requested_width = tmp_width;
5088 if (draw_hgrid_lines)
5089 height += grid_line_width;
5091 tree_view->priv->post_validation_flag = TRUE;
5097 validate_visible_area (PsppSheetView *tree_view)
5099 GtkTreePath *path = NULL;
5100 GtkTreePath *above_path = NULL;
5103 gboolean size_changed = FALSE;
5105 gint area_above = 0;
5106 gint area_below = 0;
5108 if (tree_view->priv->row_count == 0)
5111 if (tree_view->priv->scroll_to_path == NULL)
5114 total_height = GTK_WIDGET (tree_view)->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
5116 if (total_height == 0)
5119 path = gtk_tree_row_reference_get_path (tree_view->priv->scroll_to_path);
5122 /* we are going to scroll, and will update dy */
5123 _pspp_sheet_view_find_node (tree_view, path, &node);
5124 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
5126 if (tree_view->priv->scroll_to_use_align)
5128 gint height = ROW_HEIGHT (tree_view);
5129 area_above = (total_height - height) *
5130 tree_view->priv->scroll_to_row_align;
5131 area_below = total_height - area_above - height;
5132 area_above = MAX (area_above, 0);
5133 area_below = MAX (area_below, 0);
5138 * 1) row not visible
5142 gint height = ROW_HEIGHT (tree_view);
5144 dy = pspp_sheet_view_node_find_offset (tree_view, node);
5146 if (dy >= tree_view->priv->vadjustment->value &&
5147 dy + height <= (tree_view->priv->vadjustment->value
5148 + tree_view->priv->vadjustment->page_size))
5150 /* row visible: keep the row at the same position */
5151 area_above = dy - tree_view->priv->vadjustment->value;
5152 area_below = (tree_view->priv->vadjustment->value +
5153 tree_view->priv->vadjustment->page_size)
5158 /* row not visible */
5160 && dy + height <= tree_view->priv->vadjustment->page_size)
5162 /* row at the beginning -- fixed */
5164 area_below = tree_view->priv->vadjustment->page_size
5165 - area_above - height;
5167 else if (dy >= (tree_view->priv->vadjustment->upper -
5168 tree_view->priv->vadjustment->page_size))
5170 /* row at the end -- fixed */
5171 area_above = dy - (tree_view->priv->vadjustment->upper -
5172 tree_view->priv->vadjustment->page_size);
5173 area_below = tree_view->priv->vadjustment->page_size -
5174 area_above - height;
5178 area_above = tree_view->priv->vadjustment->page_size - height;
5184 /* row somewhere in the middle, bring it to the top
5188 area_below = total_height - height;
5194 /* the scroll to isn't valid; ignore it.
5197 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
5198 tree_view->priv->scroll_to_path = NULL;
5202 above_path = gtk_tree_path_copy (path);
5204 /* Now, we walk forwards and backwards, measuring rows. Unfortunately,
5205 * backwards is much slower then forward, as there is no iter_prev function.
5206 * We go forwards first in case we run out of tree. Then we go backwards to
5209 while (node >= 0 && area_below > 0)
5211 gboolean done = FALSE;
5214 node = pspp_sheet_view_node_next (tree_view, node);
5217 gboolean has_next = gtk_tree_model_iter_next (tree_view->priv->model, &iter);
5219 gtk_tree_path_next (path);
5222 TREE_VIEW_INTERNAL_ASSERT_VOID (has_next);
5232 area_below -= ROW_HEIGHT (tree_view);
5234 gtk_tree_path_free (path);
5236 /* If we ran out of tree, and have extra area_below left, we need to add it
5239 area_above += area_below;
5241 _pspp_sheet_view_find_node (tree_view, above_path, &node);
5243 /* We walk backwards */
5244 while (area_above > 0)
5246 node = pspp_sheet_view_node_prev (tree_view, node);
5248 /* Always find the new path in the tree. We cannot just assume
5249 * a gtk_tree_path_prev() is enough here, as there might be children
5250 * in between this node and the previous sibling node. If this
5251 * appears to be a performance hotspot in profiles, we can look into
5252 * intrigate logic for keeping path, node and iter in sync like
5253 * we do for forward walks. (Which will be hard because of the lacking
5260 gtk_tree_path_free (above_path);
5261 above_path = _pspp_sheet_view_find_path (tree_view, node);
5263 gtk_tree_model_get_iter (tree_view->priv->model, &iter, above_path);
5265 area_above -= ROW_HEIGHT (tree_view);
5268 /* set the dy here to scroll to the path,
5269 * and sync the top row accordingly
5271 pspp_sheet_view_set_top_row (tree_view, above_path, -area_above);
5272 pspp_sheet_view_top_row_to_dy (tree_view);
5274 /* update width/height and queue a resize */
5277 GtkRequisition requisition;
5279 /* We temporarily guess a size, under the assumption that it will be the
5280 * same when we get our next size_allocate. If we don't do this, we'll be
5281 * in an inconsistent state if we call top_row_to_dy. */
5283 gtk_widget_size_request (GTK_WIDGET (tree_view), &requisition);
5284 tree_view->priv->hadjustment->upper = MAX (tree_view->priv->hadjustment->upper, (gfloat)requisition.width);
5285 tree_view->priv->vadjustment->upper = MAX (tree_view->priv->vadjustment->upper, (gfloat)requisition.height);
5286 gtk_adjustment_changed (tree_view->priv->hadjustment);
5287 gtk_adjustment_changed (tree_view->priv->vadjustment);
5288 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
5291 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
5292 tree_view->priv->scroll_to_path = NULL;
5295 gtk_tree_path_free (above_path);
5297 if (tree_view->priv->scroll_to_column)
5299 tree_view->priv->scroll_to_column = NULL;
5301 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
5305 initialize_fixed_height_mode (PsppSheetView *tree_view)
5307 if (!tree_view->priv->row_count)
5310 if (tree_view->priv->fixed_height_set)
5313 if (tree_view->priv->fixed_height < 0)
5320 path = _pspp_sheet_view_find_path (tree_view, node);
5321 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
5323 tree_view->priv->fixed_height = validate_row (tree_view, node, &iter, path);
5325 gtk_tree_path_free (path);
5327 g_object_notify (G_OBJECT (tree_view), "fixed-height");
5331 /* Our strategy for finding nodes to validate is a little convoluted. We find
5332 * the left-most uninvalidated node. We then try walking right, validating
5333 * nodes. Once we find a valid node, we repeat the previous process of finding
5334 * the first invalid node.
5338 validate_rows_handler (PsppSheetView *tree_view)
5340 initialize_fixed_height_mode (tree_view);
5341 if (tree_view->priv->validate_rows_timer)
5343 g_source_remove (tree_view->priv->validate_rows_timer);
5344 tree_view->priv->validate_rows_timer = 0;
5351 do_presize_handler (PsppSheetView *tree_view)
5353 GtkRequisition requisition;
5355 validate_visible_area (tree_view);
5356 tree_view->priv->presize_handler_timer = 0;
5358 if (! gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5361 gtk_widget_size_request (GTK_WIDGET (tree_view), &requisition);
5363 tree_view->priv->hadjustment->upper = MAX (tree_view->priv->hadjustment->upper, (gfloat)requisition.width);
5364 tree_view->priv->vadjustment->upper = MAX (tree_view->priv->vadjustment->upper, (gfloat)requisition.height);
5365 gtk_adjustment_changed (tree_view->priv->hadjustment);
5366 gtk_adjustment_changed (tree_view->priv->vadjustment);
5367 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
5373 presize_handler_callback (gpointer data)
5375 do_presize_handler (PSPP_SHEET_VIEW (data));
5381 install_presize_handler (PsppSheetView *tree_view)
5383 if (! gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5386 if (! tree_view->priv->presize_handler_timer)
5388 tree_view->priv->presize_handler_timer =
5389 gdk_threads_add_idle_full (GTK_PRIORITY_RESIZE - 2, presize_handler_callback, tree_view, NULL);
5391 if (! tree_view->priv->validate_rows_timer)
5393 tree_view->priv->validate_rows_timer =
5394 gdk_threads_add_idle_full (PSPP_SHEET_VIEW_PRIORITY_VALIDATE, (GSourceFunc) validate_rows_handler, tree_view, NULL);
5399 scroll_sync_handler (PsppSheetView *tree_view)
5401 if (tree_view->priv->height <= tree_view->priv->vadjustment->page_size)
5402 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment), 0);
5403 else if (gtk_tree_row_reference_valid (tree_view->priv->top_row))
5404 pspp_sheet_view_top_row_to_dy (tree_view);
5406 pspp_sheet_view_dy_to_top_row (tree_view);
5408 tree_view->priv->scroll_sync_timer = 0;
5414 install_scroll_sync_handler (PsppSheetView *tree_view)
5416 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5419 if (!tree_view->priv->scroll_sync_timer)
5421 tree_view->priv->scroll_sync_timer =
5422 gdk_threads_add_idle_full (PSPP_SHEET_VIEW_PRIORITY_SCROLL_SYNC, (GSourceFunc) scroll_sync_handler, tree_view, NULL);
5427 pspp_sheet_view_set_top_row (PsppSheetView *tree_view,
5431 gtk_tree_row_reference_free (tree_view->priv->top_row);
5435 tree_view->priv->top_row = NULL;
5436 tree_view->priv->top_row_dy = 0;
5440 tree_view->priv->top_row = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
5441 tree_view->priv->top_row_dy = offset;
5445 /* Always call this iff dy is in the visible range. If the tree is empty, then
5446 * it's set to be NULL, and top_row_dy is 0;
5449 pspp_sheet_view_dy_to_top_row (PsppSheetView *tree_view)
5455 if (tree_view->priv->row_count == 0)
5457 pspp_sheet_view_set_top_row (tree_view, NULL, 0);
5461 offset = pspp_sheet_view_find_offset (tree_view,
5462 tree_view->priv->dy,
5467 pspp_sheet_view_set_top_row (tree_view, NULL, 0);
5471 path = _pspp_sheet_view_find_path (tree_view, node);
5472 pspp_sheet_view_set_top_row (tree_view, path, offset);
5473 gtk_tree_path_free (path);
5479 pspp_sheet_view_top_row_to_dy (PsppSheetView *tree_view)
5485 /* Avoid recursive calls */
5486 if (tree_view->priv->in_top_row_to_dy)
5489 if (tree_view->priv->top_row)
5490 path = gtk_tree_row_reference_get_path (tree_view->priv->top_row);
5497 _pspp_sheet_view_find_node (tree_view, path, &node);
5500 gtk_tree_path_free (path);
5504 /* keep dy and set new toprow */
5505 gtk_tree_row_reference_free (tree_view->priv->top_row);
5506 tree_view->priv->top_row = NULL;
5507 tree_view->priv->top_row_dy = 0;
5508 /* DO NOT install the idle handler */
5509 pspp_sheet_view_dy_to_top_row (tree_view);
5513 if (ROW_HEIGHT (tree_view) < tree_view->priv->top_row_dy)
5515 /* new top row -- do NOT install the idle handler */
5516 pspp_sheet_view_dy_to_top_row (tree_view);
5520 new_dy = pspp_sheet_view_node_find_offset (tree_view, node);
5521 new_dy += tree_view->priv->top_row_dy;
5523 if (new_dy + tree_view->priv->vadjustment->page_size > tree_view->priv->height)
5524 new_dy = tree_view->priv->height - tree_view->priv->vadjustment->page_size;
5526 new_dy = MAX (0, new_dy);
5528 tree_view->priv->in_top_row_to_dy = TRUE;
5529 gtk_adjustment_set_value (tree_view->priv->vadjustment, (gdouble)new_dy);
5530 tree_view->priv->in_top_row_to_dy = FALSE;
5535 _pspp_sheet_view_install_mark_rows_col_dirty (PsppSheetView *tree_view)
5537 install_presize_handler (tree_view);
5543 set_source_row (GdkDragContext *context,
5544 GtkTreeModel *model,
5545 GtkTreePath *source_row)
5547 g_object_set_data_full (G_OBJECT (context),
5548 "gtk-tree-view-source-row",
5549 source_row ? gtk_tree_row_reference_new (model, source_row) : NULL,
5550 (GDestroyNotify) (source_row ? gtk_tree_row_reference_free : NULL));
5554 get_source_row (GdkDragContext *context)
5556 GtkTreeRowReference *ref =
5557 g_object_get_data (G_OBJECT (context), "gtk-tree-view-source-row");
5560 return gtk_tree_row_reference_get_path (ref);
5567 GtkTreeRowReference *dest_row;
5568 guint path_down_mode : 1;
5569 guint empty_view_drop : 1;
5570 guint drop_append_mode : 1;
5575 dest_row_free (gpointer data)
5577 DestRow *dr = (DestRow *)data;
5579 gtk_tree_row_reference_free (dr->dest_row);
5580 g_slice_free (DestRow, dr);
5584 set_dest_row (GdkDragContext *context,
5585 GtkTreeModel *model,
5586 GtkTreePath *dest_row,
5587 gboolean path_down_mode,
5588 gboolean empty_view_drop,
5589 gboolean drop_append_mode)
5595 g_object_set_data_full (G_OBJECT (context), "gtk-tree-view-dest-row",
5600 dr = g_slice_new (DestRow);
5602 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5603 dr->path_down_mode = path_down_mode != FALSE;
5604 dr->empty_view_drop = empty_view_drop != FALSE;
5605 dr->drop_append_mode = drop_append_mode != FALSE;
5607 g_object_set_data_full (G_OBJECT (context), "gtk-tree-view-dest-row",
5608 dr, (GDestroyNotify) dest_row_free);
5612 get_dest_row (GdkDragContext *context,
5613 gboolean *path_down_mode)
5616 g_object_get_data (G_OBJECT (context), "gtk-tree-view-dest-row");
5620 GtkTreePath *path = NULL;
5623 *path_down_mode = dr->path_down_mode;
5626 path = gtk_tree_row_reference_get_path (dr->dest_row);
5627 else if (dr->empty_view_drop)
5628 path = gtk_tree_path_new_from_indices (0, -1);
5632 if (path && dr->drop_append_mode)
5633 gtk_tree_path_next (path);
5641 /* Get/set whether drag_motion requested the drag data and
5642 * drag_data_received should thus not actually insert the data,
5643 * since the data doesn't result from a drop.
5646 set_status_pending (GdkDragContext *context,
5647 GdkDragAction suggested_action)
5649 g_object_set_data (G_OBJECT (context),
5650 "gtk-tree-view-status-pending",
5651 GINT_TO_POINTER (suggested_action));
5654 static GdkDragAction
5655 get_status_pending (GdkDragContext *context)
5657 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5658 "gtk-tree-view-status-pending"));
5661 static TreeViewDragInfo*
5662 get_info (PsppSheetView *tree_view)
5664 return g_object_get_data (G_OBJECT (tree_view), "gtk-tree-view-drag-info");
5668 destroy_info (TreeViewDragInfo *di)
5670 g_slice_free (TreeViewDragInfo, di);
5673 static TreeViewDragInfo*
5674 ensure_info (PsppSheetView *tree_view)
5676 TreeViewDragInfo *di;
5678 di = get_info (tree_view);
5682 di = g_slice_new0 (TreeViewDragInfo);
5684 g_object_set_data_full (G_OBJECT (tree_view),
5685 "gtk-tree-view-drag-info",
5687 (GDestroyNotify) destroy_info);
5694 remove_info (PsppSheetView *tree_view)
5696 g_object_set_data (G_OBJECT (tree_view), "gtk-tree-view-drag-info", NULL);
5701 drag_scan_timeout (gpointer data)
5703 PsppSheetView *tree_view;
5705 GdkModifierType state;
5706 GtkTreePath *path = NULL;
5707 PsppSheetViewColumn *column = NULL;
5708 GdkRectangle visible_rect;
5710 GDK_THREADS_ENTER ();
5712 tree_view = PSPP_SHEET_VIEW (data);
5714 gdk_window_get_pointer (tree_view->priv->bin_window,
5717 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
5719 /* See if we are near the edge. */
5720 if ((x - visible_rect.x) < SCROLL_EDGE_SIZE ||
5721 (visible_rect.x + visible_rect.width - x) < SCROLL_EDGE_SIZE ||
5722 (y - visible_rect.y) < SCROLL_EDGE_SIZE ||
5723 (visible_rect.y + visible_rect.height - y) < SCROLL_EDGE_SIZE)
5725 pspp_sheet_view_get_path_at_pos (tree_view,
5726 tree_view->priv->bin_window,
5735 pspp_sheet_view_scroll_to_cell (tree_view,
5741 gtk_tree_path_free (path);
5745 GDK_THREADS_LEAVE ();
5752 add_scroll_timeout (PsppSheetView *tree_view)
5754 if (tree_view->priv->scroll_timeout == 0)
5756 tree_view->priv->scroll_timeout =
5757 gdk_threads_add_timeout (150, scroll_row_timeout, tree_view);
5762 remove_scroll_timeout (PsppSheetView *tree_view)
5764 if (tree_view->priv->scroll_timeout != 0)
5766 g_source_remove (tree_view->priv->scroll_timeout);
5767 tree_view->priv->scroll_timeout = 0;
5772 check_model_dnd (GtkTreeModel *model,
5773 GType required_iface,
5774 const gchar *signal)
5776 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5778 g_warning ("You must override the default '%s' handler "
5779 "on PsppSheetView when using models that don't support "
5780 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5781 "is to connect to '%s' and call "
5782 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5783 "the default handler from running. Look at the source code "
5784 "for the default handler in gtktreeview.c to get an idea what "
5785 "your handler should do. (gtktreeview.c is in the GTK source "
5786 "code.) If you're using GTK from a language other than C, "
5787 "there may be a more natural way to override default handlers, e.g. via derivation.",
5788 signal, g_type_name (required_iface), signal);
5796 scroll_row_timeout (gpointer data)
5798 PsppSheetView *tree_view = data;
5800 pspp_sheet_view_horizontal_autoscroll (tree_view);
5801 pspp_sheet_view_vertical_autoscroll (tree_view);
5803 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
5804 pspp_sheet_view_update_rubber_band (tree_view);
5809 /* Returns TRUE if event should not be propagated to parent widgets */
5811 set_destination_row (PsppSheetView *tree_view,
5812 GdkDragContext *context,
5813 /* coordinates relative to the widget */
5816 GdkDragAction *suggested_action,
5819 GtkTreePath *path = NULL;
5820 PsppSheetViewDropPosition pos;
5821 PsppSheetViewDropPosition old_pos;
5822 TreeViewDragInfo *di;
5824 GtkTreePath *old_dest_path = NULL;
5825 gboolean can_drop = FALSE;
5827 *suggested_action = 0;
5830 widget = GTK_WIDGET (tree_view);
5832 di = get_info (tree_view);
5834 if (di == NULL || y - TREE_VIEW_HEADER_HEIGHT (tree_view) < 0)
5836 /* someone unset us as a drag dest, note that if
5837 * we return FALSE drag_leave isn't called
5840 pspp_sheet_view_set_drag_dest_row (tree_view,
5842 PSPP_SHEET_VIEW_DROP_BEFORE);
5844 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
5846 return FALSE; /* no longer a drop site */
5849 *target = gtk_drag_dest_find_target (widget, context,
5850 gtk_drag_dest_get_target_list (widget));
5851 if (*target == GDK_NONE)
5856 if (!pspp_sheet_view_get_dest_row_at_pos (tree_view,
5862 GtkTreeModel *model;
5864 /* the row got dropped on empty space, let's setup a special case
5868 gtk_tree_path_free (path);
5870 model = pspp_sheet_view_get_model (tree_view);
5872 n_children = gtk_tree_model_iter_n_children (model, NULL);
5875 pos = PSPP_SHEET_VIEW_DROP_AFTER;
5876 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
5880 pos = PSPP_SHEET_VIEW_DROP_BEFORE;
5881 path = gtk_tree_path_new_from_indices (0, -1);
5891 /* If we left the current row's "open" zone, unset the timeout for
5894 pspp_sheet_view_get_drag_dest_row (tree_view,
5899 gtk_tree_path_free (old_dest_path);
5901 if (TRUE /* FIXME if the location droppable predicate */)
5909 GtkWidget *source_widget;
5911 *suggested_action = context->suggested_action;
5912 source_widget = gtk_drag_get_source_widget (context);
5914 if (source_widget == widget)
5916 /* Default to MOVE, unless the user has
5917 * pressed ctrl or shift to affect available actions
5919 if ((context->actions & GDK_ACTION_MOVE) != 0)
5920 *suggested_action = GDK_ACTION_MOVE;
5923 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
5928 /* can't drop here */
5929 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
5931 PSPP_SHEET_VIEW_DROP_BEFORE);
5935 gtk_tree_path_free (path);
5941 get_logical_dest_row (PsppSheetView *tree_view,
5942 gboolean *path_down_mode,
5943 gboolean *drop_append_mode)
5945 /* adjust path to point to the row the drop goes in front of */
5946 GtkTreePath *path = NULL;
5947 PsppSheetViewDropPosition pos;
5949 g_return_val_if_fail (path_down_mode != NULL, NULL);
5950 g_return_val_if_fail (drop_append_mode != NULL, NULL);
5952 *path_down_mode = FALSE;
5953 *drop_append_mode = 0;
5955 pspp_sheet_view_get_drag_dest_row (tree_view, &path, &pos);
5960 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE)
5962 else if (pos == PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE ||
5963 pos == PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER)
5964 *path_down_mode = TRUE;
5968 GtkTreeModel *model = pspp_sheet_view_get_model (tree_view);
5970 g_assert (pos == PSPP_SHEET_VIEW_DROP_AFTER);
5972 if (!gtk_tree_model_get_iter (model, &iter, path) ||
5973 !gtk_tree_model_iter_next (model, &iter))
5974 *drop_append_mode = 1;
5977 *drop_append_mode = 0;
5978 gtk_tree_path_next (path);
5986 pspp_sheet_view_maybe_begin_dragging_row (PsppSheetView *tree_view,
5987 GdkEventMotion *event)
5989 GtkWidget *widget = GTK_WIDGET (tree_view);
5990 GdkDragContext *context;
5991 TreeViewDragInfo *di;
5992 GtkTreePath *path = NULL;
5994 gint cell_x, cell_y;
5995 GtkTreeModel *model;
5996 gboolean retval = FALSE;
5998 di = get_info (tree_view);
6000 if (di == NULL || !di->source_set)
6003 if (tree_view->priv->pressed_button < 0)
6006 if (!gtk_drag_check_threshold (widget,
6007 tree_view->priv->press_start_x,
6008 tree_view->priv->press_start_y,
6009 event->x, event->y))
6012 model = pspp_sheet_view_get_model (tree_view);
6017 button = tree_view->priv->pressed_button;
6018 tree_view->priv->pressed_button = -1;
6020 pspp_sheet_view_get_path_at_pos (tree_view,
6021 tree_view->priv->press_start_x,
6022 tree_view->priv->press_start_y,
6031 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6032 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6036 if (!(GDK_BUTTON1_MASK << (button - 1) & di->start_button_mask))
6039 /* Now we can begin the drag */
6043 context = gtk_drag_begin (widget,
6044 gtk_drag_source_get_target_list (widget),
6049 set_source_row (context, model, path);
6053 gtk_tree_path_free (path);
6060 pspp_sheet_view_drag_begin (GtkWidget *widget,
6061 GdkDragContext *context)
6063 PsppSheetView *tree_view;
6064 GtkTreePath *path = NULL;
6065 gint cell_x, cell_y;
6067 TreeViewDragInfo *di;
6069 tree_view = PSPP_SHEET_VIEW (widget);
6071 /* if the user uses a custom DND source impl, we don't set the icon here */
6072 di = get_info (tree_view);
6074 if (di == NULL || !di->source_set)
6077 pspp_sheet_view_get_path_at_pos (tree_view,
6078 tree_view->priv->press_start_x,
6079 tree_view->priv->press_start_y,
6085 g_return_if_fail (path != NULL);
6087 row_pix = pspp_sheet_view_create_row_drag_icon (tree_view,
6090 gtk_drag_set_icon_pixmap (context,
6091 gdk_drawable_get_colormap (row_pix),
6094 /* the + 1 is for the black border in the icon */
6095 tree_view->priv->press_start_x + 1,
6098 g_object_unref (row_pix);
6099 gtk_tree_path_free (path);
6103 pspp_sheet_view_drag_end (GtkWidget *widget,
6104 GdkDragContext *context)
6109 /* Default signal implementations for the drag signals */
6111 pspp_sheet_view_drag_data_get (GtkWidget *widget,
6112 GdkDragContext *context,
6113 GtkSelectionData *selection_data,
6117 PsppSheetView *tree_view;
6118 GtkTreeModel *model;
6119 TreeViewDragInfo *di;
6120 GtkTreePath *source_row;
6122 tree_view = PSPP_SHEET_VIEW (widget);
6124 model = pspp_sheet_view_get_model (tree_view);
6129 di = get_info (PSPP_SHEET_VIEW (widget));
6134 source_row = get_source_row (context);
6136 if (source_row == NULL)
6139 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6140 * any model; for DragSource models there are some other targets
6144 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6145 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6150 /* If drag_data_get does nothing, try providing row data. */
6151 if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6153 gtk_tree_set_row_drag_data (selection_data,
6159 gtk_tree_path_free (source_row);
6164 pspp_sheet_view_drag_data_delete (GtkWidget *widget,
6165 GdkDragContext *context)
6167 TreeViewDragInfo *di;
6168 GtkTreeModel *model;
6169 PsppSheetView *tree_view;
6170 GtkTreePath *source_row;
6172 tree_view = PSPP_SHEET_VIEW (widget);
6173 model = pspp_sheet_view_get_model (tree_view);
6175 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
6178 di = get_info (tree_view);
6183 source_row = get_source_row (context);
6185 if (source_row == NULL)
6188 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6191 gtk_tree_path_free (source_row);
6193 set_source_row (context, NULL, NULL);
6197 pspp_sheet_view_drag_leave (GtkWidget *widget,
6198 GdkDragContext *context,
6201 /* unset any highlight row */
6202 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6204 PSPP_SHEET_VIEW_DROP_BEFORE);
6206 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6211 pspp_sheet_view_drag_motion (GtkWidget *widget,
6212 GdkDragContext *context,
6213 /* coordinates relative to the widget */
6219 GtkTreePath *path = NULL;
6220 PsppSheetViewDropPosition pos;
6221 PsppSheetView *tree_view;
6222 GdkDragAction suggested_action = 0;
6225 tree_view = PSPP_SHEET_VIEW (widget);
6227 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6230 pspp_sheet_view_get_drag_dest_row (tree_view, &path, &pos);
6232 /* we only know this *after* set_desination_row */
6233 empty = tree_view->priv->empty_view_drop;
6235 if (path == NULL && !empty)
6237 /* Can't drop here. */
6238 gdk_drag_status (context, 0, time);
6242 if (tree_view->priv->open_dest_timeout == 0 &&
6243 (pos == PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER ||
6244 pos == PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE))
6250 add_scroll_timeout (tree_view);
6253 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6255 /* Request data so we can use the source row when
6256 * determining whether to accept the drop
6258 set_status_pending (context, suggested_action);
6259 gtk_drag_get_data (widget, context, target, time);
6263 set_status_pending (context, 0);
6264 gdk_drag_status (context, suggested_action, time);
6269 gtk_tree_path_free (path);
6276 pspp_sheet_view_drag_drop (GtkWidget *widget,
6277 GdkDragContext *context,
6278 /* coordinates relative to the widget */
6283 PsppSheetView *tree_view;
6285 GdkDragAction suggested_action = 0;
6286 GdkAtom target = GDK_NONE;
6287 TreeViewDragInfo *di;
6288 GtkTreeModel *model;
6289 gboolean path_down_mode;
6290 gboolean drop_append_mode;
6292 tree_view = PSPP_SHEET_VIEW (widget);
6294 model = pspp_sheet_view_get_model (tree_view);
6296 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6298 di = get_info (tree_view);
6303 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
6306 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6309 path = get_logical_dest_row (tree_view, &path_down_mode, &drop_append_mode);
6311 if (target != GDK_NONE && path != NULL)
6313 /* in case a motion had requested drag data, change things so we
6314 * treat drag data receives as a drop.
6316 set_status_pending (context, 0);
6317 set_dest_row (context, model, path,
6318 path_down_mode, tree_view->priv->empty_view_drop,
6323 gtk_tree_path_free (path);
6325 /* Unset this thing */
6326 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6328 PSPP_SHEET_VIEW_DROP_BEFORE);
6330 if (target != GDK_NONE)
6332 gtk_drag_get_data (widget, context, target, time);
6340 pspp_sheet_view_drag_data_received (GtkWidget *widget,
6341 GdkDragContext *context,
6342 /* coordinates relative to the widget */
6345 GtkSelectionData *selection_data,
6350 TreeViewDragInfo *di;
6351 gboolean accepted = FALSE;
6352 GtkTreeModel *model;
6353 PsppSheetView *tree_view;
6354 GtkTreePath *dest_row;
6355 GdkDragAction suggested_action;
6356 gboolean path_down_mode;
6357 gboolean drop_append_mode;
6359 tree_view = PSPP_SHEET_VIEW (widget);
6361 model = pspp_sheet_view_get_model (tree_view);
6363 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_data_received"))
6366 di = get_info (tree_view);
6371 suggested_action = get_status_pending (context);
6373 if (suggested_action)
6375 /* We are getting this data due to a request in drag_motion,
6376 * rather than due to a request in drag_drop, so we are just
6377 * supposed to call drag_status, not actually paste in the
6380 path = get_logical_dest_row (tree_view, &path_down_mode,
6384 suggested_action = 0;
6385 else if (path_down_mode)
6386 gtk_tree_path_down (path);
6388 if (suggested_action)
6390 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6396 path_down_mode = FALSE;
6397 gtk_tree_path_up (path);
6399 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6402 suggested_action = 0;
6405 suggested_action = 0;
6409 gdk_drag_status (context, suggested_action, time);
6412 gtk_tree_path_free (path);
6414 /* If you can't drop, remove user drop indicator until the next motion */
6415 if (suggested_action == 0)
6416 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6418 PSPP_SHEET_VIEW_DROP_BEFORE);
6423 dest_row = get_dest_row (context, &path_down_mode);
6425 if (dest_row == NULL)
6428 if (selection_data->length >= 0)
6432 gtk_tree_path_down (dest_row);
6433 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6434 dest_row, selection_data))
6435 gtk_tree_path_up (dest_row);
6439 if (selection_data->length >= 0)
6441 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6447 gtk_drag_finish (context,
6449 (context->action == GDK_ACTION_MOVE),
6452 if (gtk_tree_path_get_depth (dest_row) == 1
6453 && gtk_tree_path_get_indices (dest_row)[0] == 0)
6455 /* special special case drag to "0", scroll to first item */
6456 if (!tree_view->priv->scroll_to_path)
6457 pspp_sheet_view_scroll_to_cell (tree_view, dest_row, NULL, FALSE, 0.0, 0.0);
6460 gtk_tree_path_free (dest_row);
6463 set_dest_row (context, NULL, NULL, FALSE, FALSE, FALSE);
6468 /* GtkContainer Methods
6473 pspp_sheet_view_remove (GtkContainer *container,
6476 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6477 PsppSheetViewChild *child = NULL;
6480 tmp_list = tree_view->priv->children;
6483 child = tmp_list->data;
6484 if (child->widget == widget)
6486 gtk_widget_unparent (widget);
6488 tree_view->priv->children = g_list_remove_link (tree_view->priv->children, tmp_list);
6489 g_list_free_1 (tmp_list);
6490 g_slice_free (PsppSheetViewChild, child);
6494 tmp_list = tmp_list->next;
6497 tmp_list = tree_view->priv->columns;
6501 PsppSheetViewColumn *column;
6502 column = tmp_list->data;
6503 if (column->button == widget)
6505 gtk_widget_unparent (widget);
6508 tmp_list = tmp_list->next;
6513 pspp_sheet_view_forall (GtkContainer *container,
6514 gboolean include_internals,
6515 GtkCallback callback,
6516 gpointer callback_data)
6518 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6519 PsppSheetViewChild *child = NULL;
6520 PsppSheetViewColumn *column;
6523 tmp_list = tree_view->priv->children;
6526 child = tmp_list->data;
6527 tmp_list = tmp_list->next;
6529 (* callback) (child->widget, callback_data);
6531 if (include_internals == FALSE)
6534 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6536 column = tmp_list->data;
6539 (* callback) (column->button, callback_data);
6543 /* Returns TRUE if the treeview contains no "special" (editable or activatable)
6544 * cells. If so we draw one big row-spanning focus rectangle.
6547 pspp_sheet_view_has_special_cell (PsppSheetView *tree_view)
6551 if (tree_view->priv->special_cells != PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT)
6552 return tree_view->priv->special_cells = PSPP_SHEET_VIEW_SPECIAL_CELLS_YES;
6554 for (list = tree_view->priv->columns; list; list = list->next)
6556 if (!((PsppSheetViewColumn *)list->data)->visible)
6558 if (_pspp_sheet_view_column_count_special_cells (list->data))
6566 pspp_sheet_view_focus_column (PsppSheetView *tree_view,
6567 PsppSheetViewColumn *focus_column,
6568 gboolean clamp_column_visible)
6570 g_return_if_fail (focus_column != NULL);
6572 tree_view->priv->focus_column = focus_column;
6573 if (!focus_column->button)
6575 pspp_sheet_view_column_set_need_button (focus_column, TRUE);
6576 g_return_if_fail (focus_column->button != NULL);
6579 if (GTK_CONTAINER (tree_view)->focus_child != focus_column->button)
6580 gtk_widget_grab_focus (focus_column->button);
6582 if (clamp_column_visible)
6583 pspp_sheet_view_clamp_column_visible (tree_view, focus_column, FALSE);
6586 /* Returns TRUE if the focus is within the headers, after the focus operation is
6590 pspp_sheet_view_header_focus (PsppSheetView *tree_view,
6591 GtkDirectionType dir,
6592 gboolean clamp_column_visible)
6594 GtkWidget *focus_child;
6595 PsppSheetViewColumn *focus_column;
6596 GList *last_column, *first_column;
6600 if (! PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
6603 focus_child = GTK_CONTAINER (tree_view)->focus_child;
6605 first_column = tree_view->priv->columns;
6606 while (first_column)
6608 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (first_column->data);
6610 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6612 first_column = first_column->next;
6615 /* No headers are visible, or are focusable. We can't focus in or out.
6617 if (first_column == NULL)
6620 last_column = g_list_last (tree_view->priv->columns);
6623 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (last_column->data);
6625 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6627 last_column = last_column->prev;
6631 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
6635 case GTK_DIR_TAB_BACKWARD:
6636 case GTK_DIR_TAB_FORWARD:
6639 if (focus_child == NULL)
6641 if (tree_view->priv->focus_column != NULL &&
6642 pspp_sheet_view_column_can_focus (tree_view->priv->focus_column))
6643 focus_column = tree_view->priv->focus_column;
6645 focus_column = first_column->data;
6646 pspp_sheet_view_focus_column (tree_view, focus_column,
6647 clamp_column_visible);
6654 if (focus_child == NULL)
6656 if (tree_view->priv->focus_column != NULL)
6657 focus_column = tree_view->priv->focus_column;
6658 else if (dir == GTK_DIR_LEFT)
6659 focus_column = last_column->data;
6661 focus_column = first_column->data;
6662 pspp_sheet_view_focus_column (tree_view, focus_column,
6663 clamp_column_visible);
6667 if (gtk_widget_child_focus (focus_child, dir))
6669 /* The focus moves inside the button. */
6670 /* This is probably a great example of bad UI */
6671 if (clamp_column_visible)
6672 pspp_sheet_view_clamp_column_visible (tree_view,
6673 tree_view->priv->focus_column,
6678 /* We need to move the focus among the row of buttons. */
6679 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6680 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)->button == focus_child)
6683 if ((tmp_list == first_column && dir == (rtl ? GTK_DIR_RIGHT : GTK_DIR_LEFT))
6684 || (tmp_list == last_column && dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT)))
6686 gtk_widget_error_bell (GTK_WIDGET (tree_view));
6692 PsppSheetViewColumn *column;
6694 if (dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT))
6695 tmp_list = tmp_list->next;
6697 tmp_list = tmp_list->prev;
6699 if (tmp_list == NULL)
6701 g_warning ("Internal button not found");
6704 column = tmp_list->data;
6705 if (column->button &&
6707 pspp_sheet_view_column_can_focus (column))
6709 pspp_sheet_view_focus_column (tree_view, column,
6710 clamp_column_visible);
6717 g_assert_not_reached ();
6724 /* This function returns in 'path' the first focusable path, if the given path
6725 * is already focusable, it's the returned one.
6729 search_first_focusable_path (PsppSheetView *tree_view,
6731 gboolean search_forward,
6734 /* XXX this function is trivial given that the sheetview doesn't support
6738 if (!path || !*path)
6741 _pspp_sheet_view_find_node (tree_view, *path, &node);
6749 return (*path != NULL);
6753 pspp_sheet_view_focus (GtkWidget *widget,
6754 GtkDirectionType direction)
6756 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6757 GtkContainer *container = GTK_CONTAINER (widget);
6758 GtkWidget *focus_child;
6760 if (!gtk_widget_is_sensitive (widget) || !gtk_widget_get_can_focus (widget))
6763 focus_child = container->focus_child;
6765 pspp_sheet_view_stop_editing (PSPP_SHEET_VIEW (widget), FALSE);
6766 /* Case 1. Headers currently have focus. */
6773 pspp_sheet_view_header_focus (tree_view, direction, TRUE);
6775 case GTK_DIR_TAB_BACKWARD:
6778 case GTK_DIR_TAB_FORWARD:
6780 gtk_widget_grab_focus (widget);
6783 g_assert_not_reached ();
6788 /* Case 2. We don't have focus at all. */
6789 if (!gtk_widget_has_focus (widget))
6791 if (!pspp_sheet_view_header_focus (tree_view, direction, FALSE))
6792 gtk_widget_grab_focus (widget);
6796 /* Case 3. We have focus already. */
6797 if (direction == GTK_DIR_TAB_BACKWARD)
6798 return (pspp_sheet_view_header_focus (tree_view, direction, FALSE));
6799 else if (direction == GTK_DIR_TAB_FORWARD)
6802 /* Other directions caught by the keybindings */
6803 gtk_widget_grab_focus (widget);
6808 pspp_sheet_view_grab_focus (GtkWidget *widget)
6810 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->grab_focus (widget);
6812 pspp_sheet_view_focus_to_cursor (PSPP_SHEET_VIEW (widget));
6816 pspp_sheet_view_style_set (GtkWidget *widget,
6817 GtkStyle *previous_style)
6819 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6821 PsppSheetViewColumn *column;
6823 if (gtk_widget_get_realized (widget))
6826 PsppSheetViewPrivate *priv = PSPP_SHEET_VIEW (widget)->priv;
6828 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
6829 gdk_window_set_background (tree_view->priv->bin_window, &widget->style->base[widget->state]);
6830 gtk_style_set_background (widget->style, tree_view->priv->header_window, GTK_STATE_NORMAL);
6831 for (i = 0; i < 5 ; ++i)
6833 g_object_unref (priv->grid_line_gc[i]);
6834 priv->grid_line_gc[i] = gdk_gc_new (widget->window);
6835 gdk_gc_copy (priv->grid_line_gc[i], widget->style->text_aa_gc[i]);
6838 pspp_sheet_view_set_grid_lines (tree_view, tree_view->priv->grid_lines);
6841 gtk_widget_style_get (widget,
6842 "expander-size", &tree_view->priv->expander_size,
6844 tree_view->priv->expander_size += EXPANDER_EXTRA_PADDING;
6846 for (list = tree_view->priv->columns; list; list = list->next)
6848 column = list->data;
6849 _pspp_sheet_view_column_cell_set_dirty (column);
6852 tree_view->priv->fixed_height = -1;
6854 /* Invalidate cached button style. */
6855 if (tree_view->priv->button_style)
6857 g_object_unref (tree_view->priv->button_style);
6858 tree_view->priv->button_style = NULL;
6861 gtk_widget_queue_resize (widget);
6866 pspp_sheet_view_set_focus_child (GtkContainer *container,
6869 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6872 for (list = tree_view->priv->columns; list; list = list->next)
6874 if (PSPP_SHEET_VIEW_COLUMN (list->data)->button == child)
6876 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
6881 GTK_CONTAINER_CLASS (pspp_sheet_view_parent_class)->set_focus_child (container, child);
6885 pspp_sheet_view_set_adjustments (PsppSheetView *tree_view,
6886 GtkAdjustment *hadj,
6887 GtkAdjustment *vadj)
6889 gboolean need_adjust = FALSE;
6891 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
6894 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
6896 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
6898 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
6900 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
6902 if (tree_view->priv->hadjustment && (tree_view->priv->hadjustment != hadj))
6904 g_signal_handlers_disconnect_by_func (tree_view->priv->hadjustment,
6905 pspp_sheet_view_adjustment_changed,
6907 g_object_unref (tree_view->priv->hadjustment);
6910 if (tree_view->priv->vadjustment && (tree_view->priv->vadjustment != vadj))
6912 g_signal_handlers_disconnect_by_func (tree_view->priv->vadjustment,
6913 pspp_sheet_view_adjustment_changed,
6915 g_object_unref (tree_view->priv->vadjustment);
6918 if (tree_view->priv->hadjustment != hadj)
6920 tree_view->priv->hadjustment = hadj;
6921 g_object_ref_sink (tree_view->priv->hadjustment);
6923 g_signal_connect (tree_view->priv->hadjustment, "value-changed",
6924 G_CALLBACK (pspp_sheet_view_adjustment_changed),
6929 if (tree_view->priv->vadjustment != vadj)
6931 tree_view->priv->vadjustment = vadj;
6932 g_object_ref_sink (tree_view->priv->vadjustment);
6934 g_signal_connect (tree_view->priv->vadjustment, "value-changed",
6935 G_CALLBACK (pspp_sheet_view_adjustment_changed),
6941 pspp_sheet_view_adjustment_changed (NULL, tree_view);
6946 pspp_sheet_view_real_move_cursor (PsppSheetView *tree_view,
6947 GtkMovementStep step,
6950 GdkModifierType state;
6952 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
6953 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
6954 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
6955 step == GTK_MOVEMENT_DISPLAY_LINES ||
6956 step == GTK_MOVEMENT_PAGES ||
6957 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
6959 if (tree_view->priv->row_count == 0)
6961 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
6964 pspp_sheet_view_stop_editing (tree_view, FALSE);
6965 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
6966 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
6968 if (gtk_get_current_event_state (&state))
6970 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
6971 tree_view->priv->ctrl_pressed = TRUE;
6972 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
6973 tree_view->priv->shift_pressed = TRUE;
6975 /* else we assume not pressed */
6979 /* currently we make no distinction. When we go bi-di, we need to */
6980 case GTK_MOVEMENT_LOGICAL_POSITIONS:
6981 case GTK_MOVEMENT_VISUAL_POSITIONS:
6982 pspp_sheet_view_move_cursor_left_right (tree_view, count);
6984 case GTK_MOVEMENT_DISPLAY_LINES:
6985 pspp_sheet_view_move_cursor_up_down (tree_view, count);
6987 case GTK_MOVEMENT_PAGES:
6988 pspp_sheet_view_move_cursor_page_up_down (tree_view, count);
6990 case GTK_MOVEMENT_BUFFER_ENDS:
6991 pspp_sheet_view_move_cursor_start_end (tree_view, count);
6994 g_assert_not_reached ();
6997 tree_view->priv->ctrl_pressed = FALSE;
6998 tree_view->priv->shift_pressed = FALSE;
7004 pspp_sheet_view_put (PsppSheetView *tree_view,
7005 GtkWidget *child_widget,
7006 /* in bin_window coordinates */
7012 PsppSheetViewChild *child;
7014 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
7015 g_return_if_fail (GTK_IS_WIDGET (child_widget));
7017 child = g_slice_new (PsppSheetViewChild);
7019 child->widget = child_widget;
7022 child->width = width;
7023 child->height = height;
7025 tree_view->priv->children = g_list_append (tree_view->priv->children, child);
7027 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7028 gtk_widget_set_parent_window (child->widget, tree_view->priv->bin_window);
7030 gtk_widget_set_parent (child_widget, GTK_WIDGET (tree_view));
7034 _pspp_sheet_view_child_move_resize (PsppSheetView *tree_view,
7036 /* in tree coordinates */
7042 PsppSheetViewChild *child = NULL;
7044 GdkRectangle allocation;
7046 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
7047 g_return_if_fail (GTK_IS_WIDGET (widget));
7049 for (list = tree_view->priv->children; list; list = list->next)
7051 if (((PsppSheetViewChild *)list->data)->widget == widget)
7060 allocation.x = child->x = x;
7061 allocation.y = child->y = y;
7062 allocation.width = child->width = width;
7063 allocation.height = child->height = height;
7065 if (gtk_widget_get_realized (widget))
7066 gtk_widget_size_allocate (widget, &allocation);
7070 /* TreeModel Callbacks
7074 pspp_sheet_view_row_changed (GtkTreeModel *model,
7079 PsppSheetView *tree_view = (PsppSheetView *)data;
7081 gboolean free_path = FALSE;
7082 GtkTreePath *cursor_path;
7084 g_return_if_fail (path != NULL || iter != NULL);
7086 if (tree_view->priv->cursor != NULL)
7087 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7091 if (tree_view->priv->edited_column &&
7092 (cursor_path == NULL || gtk_tree_path_compare (cursor_path, path) == 0))
7093 pspp_sheet_view_stop_editing (tree_view, TRUE);
7095 if (cursor_path != NULL)
7096 gtk_tree_path_free (cursor_path);
7100 path = gtk_tree_model_get_path (model, iter);
7103 else if (iter == NULL)
7104 gtk_tree_model_get_iter (model, iter, path);
7106 _pspp_sheet_view_find_node (tree_view,
7112 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7113 pspp_sheet_view_node_queue_redraw (tree_view, node);
7117 gtk_tree_path_free (path);
7121 pspp_sheet_view_row_inserted (GtkTreeModel *model,
7126 PsppSheetView *tree_view = (PsppSheetView *) data;
7129 gint height = tree_view->priv->fixed_height;
7130 gboolean free_path = FALSE;
7131 gboolean node_visible = TRUE;
7133 g_return_if_fail (path != NULL || iter != NULL);
7137 path = gtk_tree_model_get_path (model, iter);
7140 else if (iter == NULL)
7141 gtk_tree_model_get_iter (model, iter, path);
7143 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7145 /* Update all row-references */
7146 gtk_tree_row_reference_inserted (G_OBJECT (data), path);
7147 indices = gtk_tree_path_get_indices (path);
7148 tmpnode = indices[0];
7150 range_tower_insert0 (tree_view->priv->selected, tmpnode, 1);
7154 if (node_visible && node_is_visible (tree_view, tmpnode))
7155 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7157 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (tree_view));
7160 install_presize_handler (tree_view);
7162 gtk_tree_path_free (path);
7166 pspp_sheet_view_row_deleted (GtkTreeModel *model,
7170 PsppSheetView *tree_view = (PsppSheetView *)data;
7173 g_return_if_fail (path != NULL);
7175 gtk_tree_row_reference_deleted (G_OBJECT (data), path);
7177 _pspp_sheet_view_find_node (tree_view, path, &node);
7182 range_tower_delete (tree_view->priv->selected, node, 1);
7184 /* Ensure we don't have a dangling pointer to a dead node */
7185 ensure_unprelighted (tree_view);
7187 /* Cancel editting if we've started */
7188 pspp_sheet_view_stop_editing (tree_view, TRUE);
7190 if (tree_view->priv->destroy_count_func)
7192 gint child_count = 0;
7193 tree_view->priv->destroy_count_func (tree_view, path, child_count, tree_view->priv->destroy_count_data);
7196 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7198 if (! gtk_tree_row_reference_valid (tree_view->priv->top_row))
7200 gtk_tree_row_reference_free (tree_view->priv->top_row);
7201 tree_view->priv->top_row = NULL;
7204 install_scroll_sync_handler (tree_view);
7206 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7209 if (helper_data.changed)
7210 g_signal_emit_by_name (tree_view->priv->selection, "changed");
7215 pspp_sheet_view_rows_reordered (GtkTreeModel *model,
7216 GtkTreePath *parent,
7221 PsppSheetView *tree_view = PSPP_SHEET_VIEW (data);
7224 /* XXX need to adjust selection */
7225 len = gtk_tree_model_iter_n_children (model, iter);
7230 gtk_tree_row_reference_reordered (G_OBJECT (data),
7235 if (gtk_tree_path_get_depth (parent) != 0)
7238 if (tree_view->priv->edited_column)
7239 pspp_sheet_view_stop_editing (tree_view, TRUE);
7241 /* we need to be unprelighted */
7242 ensure_unprelighted (tree_view);
7244 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
7246 pspp_sheet_view_dy_to_top_row (tree_view);
7250 /* Internal tree functions
7255 pspp_sheet_view_get_background_xrange (PsppSheetView *tree_view,
7256 PsppSheetViewColumn *column,
7260 PsppSheetViewColumn *tmp_column = NULL;
7271 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7274 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
7276 list = (rtl ? list->prev : list->next))
7278 tmp_column = list->data;
7280 if (tmp_column == column)
7283 if (tmp_column->visible)
7284 total_width += tmp_column->width;
7287 if (tmp_column != column)
7289 g_warning (G_STRLOC": passed-in column isn't in the tree");
7298 if (column->visible)
7299 *x2 = total_width + column->width;
7301 *x2 = total_width; /* width of 0 */
7305 /* Make sure the node is visible vertically */
7307 pspp_sheet_view_clamp_node_visible (PsppSheetView *tree_view,
7310 gint node_dy, height;
7311 GtkTreePath *path = NULL;
7313 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7316 /* just return if the node is visible, avoiding a costly expose */
7317 node_dy = pspp_sheet_view_node_find_offset (tree_view, node);
7318 height = ROW_HEIGHT (tree_view);
7319 if (node_dy >= tree_view->priv->vadjustment->value
7320 && node_dy + height <= (tree_view->priv->vadjustment->value
7321 + tree_view->priv->vadjustment->page_size))
7324 path = _pspp_sheet_view_find_path (tree_view, node);
7327 /* We process updates because we want to clear old selected items when we scroll.
7328 * if this is removed, we get a "selection streak" at the bottom. */
7329 gdk_window_process_updates (tree_view->priv->bin_window, TRUE);
7330 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL, FALSE, 0.0, 0.0);
7331 gtk_tree_path_free (path);
7336 pspp_sheet_view_clamp_column_visible (PsppSheetView *tree_view,
7337 PsppSheetViewColumn *column,
7338 gboolean focus_to_cell)
7345 x = column->allocation.x;
7346 width = column->allocation.width;
7348 if (width > tree_view->priv->hadjustment->page_size)
7350 /* The column is larger than the horizontal page size. If the
7351 * column has cells which can be focussed individually, then we make
7352 * sure the cell which gets focus is fully visible (if even the
7353 * focus cell is bigger than the page size, we make sure the
7354 * left-hand side of the cell is visible).
7356 * If the column does not have those so-called special cells, we
7357 * make sure the left-hand side of the column is visible.
7360 if (focus_to_cell && pspp_sheet_view_has_special_cell (tree_view))
7362 GtkTreePath *cursor_path;
7363 GdkRectangle background_area, cell_area, focus_area;
7365 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7367 pspp_sheet_view_get_cell_area (tree_view,
7368 cursor_path, column, &cell_area);
7369 pspp_sheet_view_get_background_area (tree_view,
7370 cursor_path, column,
7373 gtk_tree_path_free (cursor_path);
7375 _pspp_sheet_view_column_get_focus_area (column,
7381 width = focus_area.width;
7383 if (width < tree_view->priv->hadjustment->page_size)
7385 if ((tree_view->priv->hadjustment->value + tree_view->priv->hadjustment->page_size) < (x + width))
7386 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7387 x + width - tree_view->priv->hadjustment->page_size);
7388 else if (tree_view->priv->hadjustment->value > x)
7389 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7393 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7395 tree_view->priv->hadjustment->lower,
7396 tree_view->priv->hadjustment->upper
7397 - tree_view->priv->hadjustment->page_size));
7401 if ((tree_view->priv->hadjustment->value + tree_view->priv->hadjustment->page_size) < (x + width))
7402 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7403 x + width - tree_view->priv->hadjustment->page_size);
7404 else if (tree_view->priv->hadjustment->value > x)
7405 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7410 _pspp_sheet_view_find_path (PsppSheetView *tree_view,
7415 path = gtk_tree_path_new ();
7417 gtk_tree_path_append_index (path, node);
7422 _pspp_sheet_view_find_node (PsppSheetView *tree_view,
7426 gint *indices = gtk_tree_path_get_indices (path);
7427 gint depth = gtk_tree_path_get_depth (path);
7430 if (depth == 0 || indices[0] < 0 || indices[0] >= tree_view->priv->row_count)
7436 pspp_sheet_view_add_move_binding (GtkBindingSet *binding_set,
7439 gboolean add_shifted_binding,
7440 GtkMovementStep step,
7444 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
7449 if (add_shifted_binding)
7450 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
7455 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
7458 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
7463 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
7470 pspp_sheet_view_set_column_drag_info (PsppSheetView *tree_view,
7471 PsppSheetViewColumn *column)
7473 PsppSheetViewColumn *left_column;
7474 PsppSheetViewColumn *cur_column = NULL;
7475 PsppSheetViewColumnReorder *reorder;
7480 /* We want to precalculate the motion list such that we know what column slots
7484 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7486 /* First, identify all possible drop spots */
7488 tmp_list = g_list_last (tree_view->priv->columns);
7490 tmp_list = g_list_first (tree_view->priv->columns);
7494 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
7495 tmp_list = rtl?g_list_previous (tmp_list):g_list_next (tmp_list);
7497 if (cur_column->visible == FALSE)
7500 /* If it's not the column moving and func tells us to skip over the column, we continue. */
7501 if (left_column != column && cur_column != column &&
7502 tree_view->priv->column_drop_func &&
7503 ! tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
7505 left_column = cur_column;
7508 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7509 reorder->left_column = left_column;
7510 left_column = reorder->right_column = cur_column;
7512 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7515 /* Add the last one */
7516 if (tree_view->priv->column_drop_func == NULL ||
7517 ((left_column != column) &&
7518 tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data)))
7520 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7521 reorder->left_column = left_column;
7522 reorder->right_column = NULL;
7523 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7526 /* We quickly check to see if it even makes sense to reorder columns. */
7527 /* If there is nothing that can be moved, then we return */
7529 if (tree_view->priv->column_drag_info == NULL)
7532 /* We know there are always 2 slots possbile, as you can always return column. */
7533 /* If that's all there is, return */
7534 if (tree_view->priv->column_drag_info->next == NULL ||
7535 (tree_view->priv->column_drag_info->next->next == NULL &&
7536 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->data)->right_column == column &&
7537 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->next->data)->left_column == column))
7539 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7540 g_slice_free (PsppSheetViewColumnReorder, tmp_list->data);
7541 g_list_free (tree_view->priv->column_drag_info);
7542 tree_view->priv->column_drag_info = NULL;
7545 /* We fill in the ranges for the columns, now that we've isolated them */
7546 left = - TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7548 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7550 reorder = (PsppSheetViewColumnReorder *) tmp_list->data;
7552 reorder->left_align = left;
7553 if (tmp_list->next != NULL)
7555 g_assert (tmp_list->next->data);
7556 left = reorder->right_align = (reorder->right_column->allocation.x +
7557 reorder->right_column->allocation.width +
7558 ((PsppSheetViewColumnReorder *)tmp_list->next->data)->left_column->allocation.x)/2;
7564 gdk_drawable_get_size (tree_view->priv->header_window, &width, NULL);
7565 reorder->right_align = width + TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7571 _pspp_sheet_view_column_start_drag (PsppSheetView *tree_view,
7572 PsppSheetViewColumn *column)
7574 GdkEvent *send_event;
7575 GtkAllocation allocation;
7576 gint x, y, width, height;
7577 GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
7578 GdkDisplay *display = gdk_screen_get_display (screen);
7580 g_return_if_fail (tree_view->priv->column_drag_info == NULL);
7581 g_return_if_fail (tree_view->priv->cur_reorder == NULL);
7582 g_return_if_fail (column->button);
7584 pspp_sheet_view_set_column_drag_info (tree_view, column);
7586 if (tree_view->priv->column_drag_info == NULL)
7589 if (tree_view->priv->drag_window == NULL)
7591 GdkWindowAttr attributes;
7592 guint attributes_mask;
7594 attributes.window_type = GDK_WINDOW_CHILD;
7595 attributes.wclass = GDK_INPUT_OUTPUT;
7596 attributes.x = column->allocation.x;
7598 attributes.width = column->allocation.width;
7599 attributes.height = column->allocation.height;
7600 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
7601 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
7602 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
7603 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
7605 tree_view->priv->drag_window = gdk_window_new (tree_view->priv->bin_window,
7608 gdk_window_set_user_data (tree_view->priv->drag_window, GTK_WIDGET (tree_view));
7611 gdk_display_pointer_ungrab (display, GDK_CURRENT_TIME);
7612 gdk_display_keyboard_ungrab (display, GDK_CURRENT_TIME);
7614 gtk_grab_remove (column->button);
7616 send_event = gdk_event_new (GDK_LEAVE_NOTIFY);
7617 send_event->crossing.send_event = TRUE;
7618 send_event->crossing.window = g_object_ref (GTK_BUTTON (column->button)->event_window);
7619 send_event->crossing.subwindow = NULL;
7620 send_event->crossing.detail = GDK_NOTIFY_ANCESTOR;
7621 send_event->crossing.time = GDK_CURRENT_TIME;
7623 gtk_propagate_event (column->button, send_event);
7624 gdk_event_free (send_event);
7626 send_event = gdk_event_new (GDK_BUTTON_RELEASE);
7627 send_event->button.window = g_object_ref (gdk_screen_get_root_window (screen));
7628 send_event->button.send_event = TRUE;
7629 send_event->button.time = GDK_CURRENT_TIME;
7630 send_event->button.x = -1;
7631 send_event->button.y = -1;
7632 send_event->button.axes = NULL;
7633 send_event->button.state = 0;
7634 send_event->button.button = 1;
7635 send_event->button.device = gdk_display_get_core_pointer (display);
7636 send_event->button.x_root = 0;
7637 send_event->button.y_root = 0;
7639 gtk_propagate_event (column->button, send_event);
7640 gdk_event_free (send_event);
7642 /* Kids, don't try this at home */
7643 g_object_ref (column->button);
7644 gtk_container_remove (GTK_CONTAINER (tree_view), column->button);
7645 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7646 gtk_widget_set_parent (column->button, GTK_WIDGET (tree_view));
7647 g_object_unref (column->button);
7649 tree_view->priv->drag_column_x = column->allocation.x;
7650 allocation = column->allocation;
7652 gtk_widget_size_allocate (column->button, &allocation);
7653 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7655 tree_view->priv->drag_column = column;
7656 gdk_window_show (tree_view->priv->drag_window);
7658 gdk_window_get_origin (tree_view->priv->header_window, &x, &y);
7659 gdk_drawable_get_size (tree_view->priv->header_window, &width, &height);
7661 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7662 while (gtk_events_pending ())
7663 gtk_main_iteration ();
7665 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG);
7666 gdk_pointer_grab (tree_view->priv->drag_window,
7668 GDK_POINTER_MOTION_MASK|GDK_BUTTON_RELEASE_MASK,
7669 NULL, NULL, GDK_CURRENT_TIME);
7670 gdk_keyboard_grab (tree_view->priv->drag_window,
7676 _pspp_sheet_view_queue_draw_node (PsppSheetView *tree_view,
7678 const GdkRectangle *clip_rect)
7682 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7686 rect.width = MAX (tree_view->priv->width, GTK_WIDGET (tree_view)->allocation.width);
7688 rect.y = BACKGROUND_FIRST_PIXEL (tree_view, node);
7689 rect.height = ROW_HEIGHT (tree_view);
7693 GdkRectangle new_rect;
7695 gdk_rectangle_intersect (clip_rect, &rect, &new_rect);
7697 gdk_window_invalidate_rect (tree_view->priv->bin_window, &new_rect, TRUE);
7701 gdk_window_invalidate_rect (tree_view->priv->bin_window, &rect, TRUE);
7706 pspp_sheet_view_queue_draw_path (PsppSheetView *tree_view,
7708 const GdkRectangle *clip_rect)
7712 _pspp_sheet_view_find_node (tree_view, path, &node);
7715 _pspp_sheet_view_queue_draw_node (tree_view, node, clip_rect);
7719 pspp_sheet_view_focus_to_cursor (PsppSheetView *tree_view)
7722 GtkTreePath *cursor_path;
7724 if ((tree_view->priv->row_count == 0) ||
7725 (! gtk_widget_get_realized (GTK_WIDGET (tree_view))))
7729 if (tree_view->priv->cursor)
7730 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7732 if (cursor_path == NULL)
7734 /* There's no cursor. Move the cursor to the first selected row, if any
7735 * are selected, otherwise to the first row in the sheetview.
7737 GList *selected_rows;
7738 GtkTreeModel *model;
7739 PsppSheetSelection *selection;
7741 selection = pspp_sheet_view_get_selection (tree_view);
7742 selected_rows = pspp_sheet_selection_get_selected_rows (selection, &model);
7746 /* XXX we could avoid doing O(n) work to get this result */
7747 cursor_path = gtk_tree_path_copy((const GtkTreePath *)(selected_rows->data));
7748 g_list_foreach (selected_rows, (GFunc)gtk_tree_path_free, NULL);
7749 g_list_free (selected_rows);
7753 cursor_path = gtk_tree_path_new_first ();
7754 search_first_focusable_path (tree_view, &cursor_path,
7758 gtk_tree_row_reference_free (tree_view->priv->cursor);
7759 tree_view->priv->cursor = NULL;
7763 if (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7764 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE)
7765 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, FALSE, FALSE);
7767 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE);
7773 /* Now find a column for the cursor. */
7774 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
7776 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
7777 gtk_tree_path_free (cursor_path);
7779 if (tree_view->priv->focus_column == NULL)
7782 for (list = tree_view->priv->columns; list; list = list->next)
7784 if (PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
7786 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
7787 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
7788 pspp_sheet_selection_select_column (tree_view->priv->selection, tree_view->priv->focus_column);
7798 pspp_sheet_view_move_cursor_up_down (PsppSheetView *tree_view,
7801 gint selection_count;
7802 int cursor_node = -1;
7803 int new_cursor_node = -1;
7804 GtkTreePath *cursor_path = NULL;
7805 gboolean grab_focus = TRUE;
7807 if (! gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7811 if (!gtk_tree_row_reference_valid (tree_view->priv->cursor))
7812 /* FIXME: we lost the cursor; should we get the first? */
7815 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7816 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
7818 if (cursor_node < 0)
7819 /* FIXME: we lost the cursor; should we get the first? */
7822 selection_count = pspp_sheet_selection_count_selected_rows (tree_view->priv->selection);
7824 if (selection_count == 0
7825 && tree_view->priv->selection->type != PSPP_SHEET_SELECTION_NONE
7826 && !tree_view->priv->ctrl_pressed)
7828 /* Don't move the cursor, but just select the current node */
7829 new_cursor_node = cursor_node;
7834 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
7836 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7839 gtk_tree_path_free (cursor_path);
7841 if (new_cursor_node)
7843 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
7845 search_first_focusable_path (tree_view, &cursor_path,
7850 gtk_tree_path_free (cursor_path);
7854 * If the list has only one item and multi-selection is set then select
7855 * the row (if not yet selected).
7857 if ((tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7858 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE) &&
7859 new_cursor_node < 0)
7862 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7864 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
7866 if (new_cursor_node < 0
7867 && !pspp_sheet_view_node_is_selected (tree_view, cursor_node))
7869 new_cursor_node = cursor_node;
7873 new_cursor_node = -1;
7877 if (new_cursor_node >= 0)
7879 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
7880 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, TRUE);
7881 gtk_tree_path_free (cursor_path);
7885 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
7887 if (!tree_view->priv->shift_pressed)
7889 if (! gtk_widget_keynav_failed (GTK_WIDGET (tree_view),
7891 GTK_DIR_UP : GTK_DIR_DOWN))
7893 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
7896 gtk_widget_child_focus (toplevel,
7898 GTK_DIR_TAB_BACKWARD :
7899 GTK_DIR_TAB_FORWARD);
7906 gtk_widget_error_bell (GTK_WIDGET (tree_view));
7911 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7915 pspp_sheet_view_move_cursor_page_up_down (PsppSheetView *tree_view,
7918 int cursor_node = -1;
7919 GtkTreePath *old_cursor_path = NULL;
7920 GtkTreePath *cursor_path = NULL;
7921 int start_cursor_node = -1;
7924 gint vertical_separator;
7926 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7929 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
7930 old_cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7932 /* This is sorta weird. Focus in should give us a cursor */
7935 gtk_widget_style_get (GTK_WIDGET (tree_view), "vertical-separator", &vertical_separator, NULL);
7936 _pspp_sheet_view_find_node (tree_view, old_cursor_path, &cursor_node);
7938 if (cursor_node < 0)
7940 /* FIXME: we lost the cursor. Should we try to get one? */
7941 gtk_tree_path_free (old_cursor_path);
7945 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
7946 window_y = RBTREE_Y_TO_TREE_WINDOW_Y (tree_view, y);
7947 y += tree_view->priv->cursor_offset;
7948 y += count * (int)tree_view->priv->vadjustment->page_increment;
7949 y = CLAMP (y, (gint)tree_view->priv->vadjustment->lower, (gint)tree_view->priv->vadjustment->upper - vertical_separator);
7951 if (y >= tree_view->priv->height)
7952 y = tree_view->priv->height - 1;
7954 tree_view->priv->cursor_offset =
7955 pspp_sheet_view_find_offset (tree_view, y, &cursor_node);
7957 if (tree_view->priv->cursor_offset > BACKGROUND_HEIGHT (tree_view))
7959 cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7960 tree_view->priv->cursor_offset -= BACKGROUND_HEIGHT (tree_view);
7963 y -= tree_view->priv->cursor_offset;
7964 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
7966 start_cursor_node = cursor_node;
7968 if (! search_first_focusable_path (tree_view, &cursor_path,
7972 /* It looks like we reached the end of the view without finding
7973 * a focusable row. We will step backwards to find the last
7976 cursor_node = start_cursor_node;
7977 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
7979 search_first_focusable_path (tree_view, &cursor_path,
7988 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
7990 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE);
7993 pspp_sheet_view_scroll_to_point (tree_view, -1, y);
7994 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
7995 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
7997 if (!gtk_tree_path_compare (old_cursor_path, cursor_path))
7998 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8000 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8003 gtk_tree_path_free (old_cursor_path);
8004 gtk_tree_path_free (cursor_path);
8008 pspp_sheet_view_move_cursor_left_right (PsppSheetView *tree_view,
8011 int cursor_node = -1;
8012 GtkTreePath *cursor_path = NULL;
8013 PsppSheetViewColumn *column;
8016 gboolean found_column = FALSE;
8019 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8021 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8024 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8025 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8029 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8030 if (cursor_node < 0)
8032 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8034 gtk_tree_path_free (cursor_path);
8037 gtk_tree_path_free (cursor_path);
8039 list = rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns);
8040 if (tree_view->priv->focus_column)
8042 for (; list; list = (rtl ? list->prev : list->next))
8044 if (list->data == tree_view->priv->focus_column)
8051 gboolean left, right;
8053 column = list->data;
8054 if (column->visible == FALSE || column->row_head)
8057 pspp_sheet_view_column_cell_set_cell_data (column,
8058 tree_view->priv->model,
8063 right = list->prev ? TRUE : FALSE;
8064 left = list->next ? TRUE : FALSE;
8068 left = list->prev ? TRUE : FALSE;
8069 right = list->next ? TRUE : FALSE;
8072 if (_pspp_sheet_view_column_cell_focus (column, count, left, right))
8074 tree_view->priv->focus_column = column;
8075 found_column = TRUE;
8080 list = rtl ? list->prev : list->next;
8082 list = rtl ? list->next : list->prev;
8087 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8088 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8089 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8093 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8096 pspp_sheet_view_clamp_column_visible (tree_view,
8097 tree_view->priv->focus_column, TRUE);
8101 pspp_sheet_view_move_cursor_start_end (PsppSheetView *tree_view,
8106 GtkTreePath *old_path;
8108 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8111 g_return_if_fail (tree_view->priv->row_count > 0);
8113 pspp_sheet_view_get_cursor (tree_view, &old_path, NULL);
8117 /* Now go forward to find the first focusable row. */
8118 path = _pspp_sheet_view_find_path (tree_view, 0);
8119 search_first_focusable_path (tree_view, &path,
8120 TRUE, &cursor_node);
8124 /* Now go backwards to find last focusable row. */
8125 path = _pspp_sheet_view_find_path (tree_view, tree_view->priv->row_count - 1);
8126 search_first_focusable_path (tree_view, &path,
8127 FALSE, &cursor_node);
8133 if (gtk_tree_path_compare (old_path, path))
8135 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE);
8136 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8140 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8144 gtk_tree_path_free (old_path);
8145 gtk_tree_path_free (path);
8149 pspp_sheet_view_real_select_all (PsppSheetView *tree_view)
8151 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8154 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8155 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8158 pspp_sheet_selection_select_all (tree_view->priv->selection);
8164 pspp_sheet_view_real_unselect_all (PsppSheetView *tree_view)
8166 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8169 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8170 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8173 pspp_sheet_selection_unselect_all (tree_view->priv->selection);
8179 pspp_sheet_view_real_select_cursor_row (PsppSheetView *tree_view,
8180 gboolean start_editing)
8183 int cursor_node = -1;
8184 GtkTreePath *cursor_path = NULL;
8185 GtkTreeSelectMode mode = 0;
8187 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8190 if (tree_view->priv->cursor)
8191 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8193 if (cursor_path == NULL)
8196 _pspp_sheet_view_find_node (tree_view, cursor_path,
8199 if (cursor_node < 0)
8201 gtk_tree_path_free (cursor_path);
8205 if (!tree_view->priv->shift_pressed && start_editing &&
8206 tree_view->priv->focus_column)
8208 if (pspp_sheet_view_start_editing (tree_view, cursor_path))
8210 gtk_tree_path_free (cursor_path);
8215 if (tree_view->priv->ctrl_pressed)
8216 mode |= GTK_TREE_SELECT_MODE_TOGGLE;
8217 if (tree_view->priv->shift_pressed)
8218 mode |= GTK_TREE_SELECT_MODE_EXTEND;
8220 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8226 /* We bail out if the original (tree, node) don't exist anymore after
8227 * handling the selection-changed callback. We do return TRUE because
8228 * the key press has been handled at this point.
8230 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8232 if (cursor_node != new_node)
8235 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8237 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8238 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8240 if (!tree_view->priv->shift_pressed)
8241 pspp_sheet_view_row_activated (tree_view, cursor_path,
8242 tree_view->priv->focus_column);
8244 gtk_tree_path_free (cursor_path);
8250 pspp_sheet_view_real_toggle_cursor_row (PsppSheetView *tree_view)
8253 int cursor_node = -1;
8254 GtkTreePath *cursor_path = NULL;
8256 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8260 if (tree_view->priv->cursor)
8261 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8263 if (cursor_path == NULL)
8266 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8267 if (cursor_node < 0)
8269 gtk_tree_path_free (cursor_path);
8273 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8276 GTK_TREE_SELECT_MODE_TOGGLE,
8279 /* We bail out if the original (tree, node) don't exist anymore after
8280 * handling the selection-changed callback. We do return TRUE because
8281 * the key press has been handled at this point.
8283 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8285 if (cursor_node != new_node)
8288 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8290 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8291 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
8292 gtk_tree_path_free (cursor_path);
8298 pspp_sheet_view_search_entry_flush_timeout (PsppSheetView *tree_view)
8300 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
8301 tree_view->priv->typeselect_flush_timeout = 0;
8306 /* Cut and paste from gtkwindow.c */
8308 send_focus_change (GtkWidget *widget,
8311 GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
8313 g_object_ref (widget);
8316 GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS);
8318 GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS);
8320 fevent->focus_change.type = GDK_FOCUS_CHANGE;
8321 fevent->focus_change.window = g_object_ref (widget->window);
8322 fevent->focus_change.in = in;
8324 gtk_widget_event (widget, fevent);
8326 g_object_notify (G_OBJECT (widget), "has-focus");
8328 g_object_unref (widget);
8329 gdk_event_free (fevent);
8333 pspp_sheet_view_ensure_interactive_directory (PsppSheetView *tree_view)
8335 GtkWidget *frame, *vbox, *toplevel;
8338 if (tree_view->priv->search_custom_entry_set)
8341 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
8342 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
8344 if (tree_view->priv->search_window != NULL)
8346 if (GTK_WINDOW (toplevel)->group)
8347 gtk_window_group_add_window (GTK_WINDOW (toplevel)->group,
8348 GTK_WINDOW (tree_view->priv->search_window));
8349 else if (GTK_WINDOW (tree_view->priv->search_window)->group)
8350 gtk_window_group_remove_window (GTK_WINDOW (tree_view->priv->search_window)->group,
8351 GTK_WINDOW (tree_view->priv->search_window));
8352 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8356 tree_view->priv->search_window = gtk_window_new (GTK_WINDOW_POPUP);
8357 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8359 if (GTK_WINDOW (toplevel)->group)
8360 gtk_window_group_add_window (GTK_WINDOW (toplevel)->group,
8361 GTK_WINDOW (tree_view->priv->search_window));
8363 gtk_window_set_type_hint (GTK_WINDOW (tree_view->priv->search_window),
8364 GDK_WINDOW_TYPE_HINT_UTILITY);
8365 gtk_window_set_modal (GTK_WINDOW (tree_view->priv->search_window), TRUE);
8366 g_signal_connect (tree_view->priv->search_window, "delete-event",
8367 G_CALLBACK (pspp_sheet_view_search_delete_event),
8369 g_signal_connect (tree_view->priv->search_window, "key-press-event",
8370 G_CALLBACK (pspp_sheet_view_search_key_press_event),
8372 g_signal_connect (tree_view->priv->search_window, "button-press-event",
8373 G_CALLBACK (pspp_sheet_view_search_button_press_event),
8375 g_signal_connect (tree_view->priv->search_window, "scroll-event",
8376 G_CALLBACK (pspp_sheet_view_search_scroll_event),
8379 frame = gtk_frame_new (NULL);
8380 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
8381 gtk_widget_show (frame);
8382 gtk_container_add (GTK_CONTAINER (tree_view->priv->search_window), frame);
8384 vbox = gtk_vbox_new (FALSE, 0);
8385 gtk_widget_show (vbox);
8386 gtk_container_add (GTK_CONTAINER (frame), vbox);
8387 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
8390 tree_view->priv->search_entry = gtk_entry_new ();
8391 gtk_widget_show (tree_view->priv->search_entry);
8392 g_signal_connect (tree_view->priv->search_entry, "populate-popup",
8393 G_CALLBACK (pspp_sheet_view_search_disable_popdown),
8395 g_signal_connect (tree_view->priv->search_entry,
8396 "activate", G_CALLBACK (pspp_sheet_view_search_activate),
8398 g_signal_connect (GTK_ENTRY (tree_view->priv->search_entry)->im_context,
8400 G_CALLBACK (pspp_sheet_view_search_preedit_changed),
8402 gtk_container_add (GTK_CONTAINER (vbox),
8403 tree_view->priv->search_entry);
8405 gtk_widget_realize (tree_view->priv->search_entry);
8408 /* Pops up the interactive search entry. If keybinding is TRUE then the user
8409 * started this by typing the start_interactive_search keybinding. Otherwise, it came from
8412 pspp_sheet_view_real_start_interactive_search (PsppSheetView *tree_view,
8413 gboolean keybinding)
8415 /* We only start interactive search if we have focus or the columns
8416 * have focus. If one of our children have focus, we don't want to
8420 gboolean found_focus = FALSE;
8421 GtkWidgetClass *entry_parent_class;
8423 if (!tree_view->priv->enable_search && !keybinding)
8426 if (tree_view->priv->search_custom_entry_set)
8429 if (tree_view->priv->search_window != NULL &&
8430 gtk_widget_get_visible (tree_view->priv->search_window))
8433 for (list = tree_view->priv->columns; list; list = list->next)
8435 PsppSheetViewColumn *column;
8437 column = list->data;
8438 if (! column->visible)
8441 if (column->button && gtk_widget_has_focus (column->button))
8448 if (gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8454 if (tree_view->priv->search_column < 0)
8457 pspp_sheet_view_ensure_interactive_directory (tree_view);
8460 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
8463 tree_view->priv->search_position_func (tree_view, tree_view->priv->search_window, tree_view->priv->search_position_user_data);
8464 gtk_widget_show (tree_view->priv->search_window);
8465 if (tree_view->priv->search_entry_changed_id == 0)
8467 tree_view->priv->search_entry_changed_id =
8468 g_signal_connect (tree_view->priv->search_entry, "changed",
8469 G_CALLBACK (pspp_sheet_view_search_init),
8473 tree_view->priv->typeselect_flush_timeout =
8474 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
8475 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
8478 /* Grab focus will select all the text. We don't want that to happen, so we
8479 * call the parent instance and bypass the selection change. This is probably
8480 * really non-kosher. */
8481 entry_parent_class = g_type_class_peek_parent (GTK_ENTRY_GET_CLASS (tree_view->priv->search_entry));
8482 (entry_parent_class->grab_focus) (tree_view->priv->search_entry);
8484 /* send focus-in event */
8485 send_focus_change (tree_view->priv->search_entry, TRUE);
8487 /* search first matching iter */
8488 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
8494 pspp_sheet_view_start_interactive_search (PsppSheetView *tree_view)
8496 return pspp_sheet_view_real_start_interactive_search (tree_view, TRUE);
8499 /* this function returns the new width of the column being resized given
8500 * the column and x position of the cursor; the x cursor position is passed
8501 * in as a pointer and automagicly corrected if it's beyond min/max limits
8504 pspp_sheet_view_new_column_width (PsppSheetView *tree_view,
8508 PsppSheetViewColumn *column;
8512 /* first translate the x position from widget->window
8513 * to clist->clist_window
8515 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8516 column = g_list_nth (tree_view->priv->columns, i)->data;
8517 width = rtl ? (column->allocation.x + column->allocation.width - *x) : (*x - column->allocation.x);
8519 /* Clamp down the value */
8520 if (column->min_width == -1)
8521 width = MAX (column->button_request, width);
8523 width = MAX (column->min_width, width);
8524 if (column->max_width != -1)
8525 width = MIN (width, column->max_width);
8527 *x = rtl ? (column->allocation.x + column->allocation.width - width) : (column->allocation.x + width);
8533 /* FIXME this adjust_allocation is a big cut-and-paste from
8534 * GtkCList, needs to be some "official" way to do this
8544 /* The window to which widget->window is relative */
8545 #define ALLOCATION_WINDOW(widget) \
8546 (!gtk_widget_get_has_window (widget) ? \
8547 (widget)->window : \
8548 gdk_window_get_parent ((widget)->window))
8551 adjust_allocation_recurse (GtkWidget *widget,
8554 ScrollData *scroll_data = data;
8556 /* Need to really size allocate instead of just poking
8557 * into widget->allocation if the widget is not realized.
8558 * FIXME someone figure out why this was.
8560 if (!gtk_widget_get_realized (widget))
8562 if (gtk_widget_get_visible (widget))
8564 GdkRectangle tmp_rectangle = widget->allocation;
8565 tmp_rectangle.x += scroll_data->dx;
8566 tmp_rectangle.y += scroll_data->dy;
8568 gtk_widget_size_allocate (widget, &tmp_rectangle);
8573 if (ALLOCATION_WINDOW (widget) == scroll_data->window)
8575 widget->allocation.x += scroll_data->dx;
8576 widget->allocation.y += scroll_data->dy;
8578 if (GTK_IS_CONTAINER (widget))
8579 gtk_container_forall (GTK_CONTAINER (widget),
8580 adjust_allocation_recurse,
8587 adjust_allocation (GtkWidget *widget,
8591 ScrollData scroll_data;
8593 if (gtk_widget_get_realized (widget))
8594 scroll_data.window = ALLOCATION_WINDOW (widget);
8596 scroll_data.window = NULL;
8598 scroll_data.dx = dx;
8599 scroll_data.dy = dy;
8601 adjust_allocation_recurse (widget, &scroll_data);
8605 pspp_sheet_view_column_update_button (PsppSheetViewColumn *tree_column);
8609 pspp_sheet_view_adjustment_changed (GtkAdjustment *adjustment,
8610 PsppSheetView *tree_view)
8612 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
8617 gdk_window_move (tree_view->priv->bin_window,
8618 - tree_view->priv->hadjustment->value,
8619 TREE_VIEW_HEADER_HEIGHT (tree_view));
8620 gdk_window_move (tree_view->priv->header_window,
8621 - tree_view->priv->hadjustment->value,
8623 dy = tree_view->priv->dy - (int) tree_view->priv->vadjustment->value;
8626 update_prelight (tree_view,
8627 tree_view->priv->event_last_x,
8628 tree_view->priv->event_last_y - dy);
8630 if (tree_view->priv->edited_column &&
8631 GTK_IS_WIDGET (tree_view->priv->edited_column->editable_widget))
8635 PsppSheetViewChild *child = NULL;
8637 widget = GTK_WIDGET (tree_view->priv->edited_column->editable_widget);
8638 adjust_allocation (widget, 0, dy);
8640 for (list = tree_view->priv->children; list; list = list->next)
8642 child = (PsppSheetViewChild *)list->data;
8643 if (child->widget == widget)
8651 gdk_window_scroll (tree_view->priv->bin_window, 0, dy);
8653 if (tree_view->priv->dy != (int) tree_view->priv->vadjustment->value)
8655 /* update our dy and top_row */
8656 tree_view->priv->dy = (int) tree_view->priv->vadjustment->value;
8658 if (!tree_view->priv->in_top_row_to_dy)
8659 pspp_sheet_view_dy_to_top_row (tree_view);
8662 for (list = tree_view->priv->columns; list; list = list->next)
8664 PsppSheetViewColumn *column = list->data;
8665 GtkAllocation *allocation = &column->allocation;
8667 if (span_intersects (allocation->x, allocation->width,
8668 tree_view->priv->hadjustment->value,
8669 GTK_WIDGET (tree_view)->allocation.width))
8671 pspp_sheet_view_column_set_need_button (column, TRUE);
8672 if (!column->button)
8673 pspp_sheet_view_column_update_button (column);
8685 * pspp_sheet_view_new:
8687 * Creates a new #PsppSheetView widget.
8689 * Return value: A newly created #PsppSheetView widget.
8692 pspp_sheet_view_new (void)
8694 return g_object_new (PSPP_TYPE_SHEET_VIEW, NULL);
8698 * pspp_sheet_view_new_with_model:
8699 * @model: the model.
8701 * Creates a new #PsppSheetView widget with the model initialized to @model.
8703 * Return value: A newly created #PsppSheetView widget.
8706 pspp_sheet_view_new_with_model (GtkTreeModel *model)
8708 return g_object_new (PSPP_TYPE_SHEET_VIEW, "model", model, NULL);
8715 * pspp_sheet_view_get_model:
8716 * @tree_view: a #PsppSheetView
8718 * Returns the model the #PsppSheetView is based on. Returns %NULL if the
8721 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
8724 pspp_sheet_view_get_model (PsppSheetView *tree_view)
8726 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
8728 return tree_view->priv->model;
8732 * pspp_sheet_view_set_model:
8733 * @tree_view: A #GtkTreeNode.
8734 * @model: (allow-none): The model.
8736 * Sets the model for a #PsppSheetView. If the @tree_view already has a model
8737 * set, it will remove it before setting the new model. If @model is %NULL,
8738 * then it will unset the old model.
8741 pspp_sheet_view_set_model (PsppSheetView *tree_view,
8742 GtkTreeModel *model)
8744 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8745 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
8747 if (model == tree_view->priv->model)
8750 if (tree_view->priv->scroll_to_path)
8752 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
8753 tree_view->priv->scroll_to_path = NULL;
8756 if (tree_view->priv->model)
8758 GList *tmplist = tree_view->priv->columns;
8760 if (tree_view->priv->selected)
8761 range_tower_set0 (tree_view->priv->selected, 0, ULONG_MAX);
8762 pspp_sheet_view_stop_editing (tree_view, TRUE);
8764 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
8765 pspp_sheet_view_row_changed,
8767 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
8768 pspp_sheet_view_row_inserted,
8770 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
8771 pspp_sheet_view_row_deleted,
8773 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
8774 pspp_sheet_view_rows_reordered,
8777 for (; tmplist; tmplist = tmplist->next)
8778 _pspp_sheet_view_column_unset_model (tmplist->data,
8779 tree_view->priv->model);
8781 tree_view->priv->prelight_node = -1;
8783 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
8784 tree_view->priv->drag_dest_row = NULL;
8785 gtk_tree_row_reference_free (tree_view->priv->cursor);
8786 tree_view->priv->cursor = NULL;
8787 gtk_tree_row_reference_free (tree_view->priv->anchor);
8788 tree_view->priv->anchor = NULL;
8789 gtk_tree_row_reference_free (tree_view->priv->top_row);
8790 tree_view->priv->top_row = NULL;
8791 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
8792 tree_view->priv->scroll_to_path = NULL;
8794 tree_view->priv->scroll_to_column = NULL;
8796 g_object_unref (tree_view->priv->model);
8798 tree_view->priv->search_column = -1;
8799 tree_view->priv->fixed_height = -1;
8800 tree_view->priv->dy = tree_view->priv->top_row_dy = 0;
8801 tree_view->priv->last_button_x = -1;
8802 tree_view->priv->last_button_y = -1;
8805 tree_view->priv->model = model;
8807 if (tree_view->priv->model)
8811 if (tree_view->priv->search_column == -1)
8813 for (i = 0; i < gtk_tree_model_get_n_columns (model); i++)
8815 GType type = gtk_tree_model_get_column_type (model, i);
8817 if (g_value_type_transformable (type, G_TYPE_STRING))
8819 tree_view->priv->search_column = i;
8825 g_object_ref (tree_view->priv->model);
8826 g_signal_connect (tree_view->priv->model,
8828 G_CALLBACK (pspp_sheet_view_row_changed),
8830 g_signal_connect (tree_view->priv->model,
8832 G_CALLBACK (pspp_sheet_view_row_inserted),
8834 g_signal_connect (tree_view->priv->model,
8836 G_CALLBACK (pspp_sheet_view_row_deleted),
8838 g_signal_connect (tree_view->priv->model,
8840 G_CALLBACK (pspp_sheet_view_rows_reordered),
8843 tree_view->priv->row_count = gtk_tree_model_iter_n_children (tree_view->priv->model, NULL);
8845 /* FIXME: do I need to do this? pspp_sheet_view_create_buttons (tree_view); */
8846 install_presize_handler (tree_view);
8849 g_object_notify (G_OBJECT (tree_view), "model");
8851 if (tree_view->priv->selection)
8852 _pspp_sheet_selection_emit_changed (tree_view->priv->selection);
8854 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
8855 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
8859 * pspp_sheet_view_get_selection:
8860 * @tree_view: A #PsppSheetView.
8862 * Gets the #PsppSheetSelection associated with @tree_view.
8864 * Return value: A #PsppSheetSelection object.
8866 PsppSheetSelection *
8867 pspp_sheet_view_get_selection (PsppSheetView *tree_view)
8869 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
8871 return tree_view->priv->selection;
8875 * pspp_sheet_view_get_hadjustment:
8876 * @tree_view: A #PsppSheetView
8878 * Gets the #GtkAdjustment currently being used for the horizontal aspect.
8880 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
8884 pspp_sheet_view_get_hadjustment (PsppSheetView *tree_view)
8886 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
8888 if (tree_view->priv->hadjustment == NULL)
8889 pspp_sheet_view_set_hadjustment (tree_view, NULL);
8891 return tree_view->priv->hadjustment;
8895 * pspp_sheet_view_set_hadjustment:
8896 * @tree_view: A #PsppSheetView
8897 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
8899 * Sets the #GtkAdjustment for the current horizontal aspect.
8902 pspp_sheet_view_set_hadjustment (PsppSheetView *tree_view,
8903 GtkAdjustment *adjustment)
8905 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8907 pspp_sheet_view_set_adjustments (tree_view,
8909 tree_view->priv->vadjustment);
8911 g_object_notify (G_OBJECT (tree_view), "hadjustment");
8915 * pspp_sheet_view_get_vadjustment:
8916 * @tree_view: A #PsppSheetView
8918 * Gets the #GtkAdjustment currently being used for the vertical aspect.
8920 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
8924 pspp_sheet_view_get_vadjustment (PsppSheetView *tree_view)
8926 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
8928 if (tree_view->priv->vadjustment == NULL)
8929 pspp_sheet_view_set_vadjustment (tree_view, NULL);
8931 return tree_view->priv->vadjustment;
8935 * pspp_sheet_view_set_vadjustment:
8936 * @tree_view: A #PsppSheetView
8937 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
8939 * Sets the #GtkAdjustment for the current vertical aspect.
8942 pspp_sheet_view_set_vadjustment (PsppSheetView *tree_view,
8943 GtkAdjustment *adjustment)
8945 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8947 pspp_sheet_view_set_adjustments (tree_view,
8948 tree_view->priv->hadjustment,
8951 g_object_notify (G_OBJECT (tree_view), "vadjustment");
8954 /* Column and header operations */
8957 * pspp_sheet_view_get_headers_visible:
8958 * @tree_view: A #PsppSheetView.
8960 * Returns %TRUE if the headers on the @tree_view are visible.
8962 * Return value: Whether the headers are visible or not.
8965 pspp_sheet_view_get_headers_visible (PsppSheetView *tree_view)
8967 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
8969 return PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
8973 * pspp_sheet_view_set_headers_visible:
8974 * @tree_view: A #PsppSheetView.
8975 * @headers_visible: %TRUE if the headers are visible
8977 * Sets the visibility state of the headers.
8980 pspp_sheet_view_set_headers_visible (PsppSheetView *tree_view,
8981 gboolean headers_visible)
8985 PsppSheetViewColumn *column;
8987 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8989 headers_visible = !! headers_visible;
8991 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE) == headers_visible)
8994 if (headers_visible)
8995 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
8997 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
8999 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9001 gdk_window_get_position (tree_view->priv->bin_window, &x, &y);
9002 if (headers_visible)
9004 gdk_window_move_resize (tree_view->priv->bin_window, x, y + TREE_VIEW_HEADER_HEIGHT (tree_view), tree_view->priv->width, GTK_WIDGET (tree_view)->allocation.height - + TREE_VIEW_HEADER_HEIGHT (tree_view));
9006 if (gtk_widget_get_mapped (GTK_WIDGET (tree_view)))
9007 pspp_sheet_view_map_buttons (tree_view);
9011 gdk_window_move_resize (tree_view->priv->bin_window, x, y, tree_view->priv->width, tree_view->priv->height);
9013 for (list = tree_view->priv->columns; list; list = list->next)
9015 column = list->data;
9017 gtk_widget_unmap (column->button);
9019 gdk_window_hide (tree_view->priv->header_window);
9023 tree_view->priv->vadjustment->page_size = GTK_WIDGET (tree_view)->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
9024 tree_view->priv->vadjustment->page_increment = (GTK_WIDGET (tree_view)->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view)) / 2;
9025 tree_view->priv->vadjustment->lower = 0;
9026 tree_view->priv->vadjustment->upper = tree_view->priv->height;
9027 gtk_adjustment_changed (tree_view->priv->vadjustment);
9029 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9031 g_object_notify (G_OBJECT (tree_view), "headers-visible");
9035 * pspp_sheet_view_columns_autosize:
9036 * @tree_view: A #PsppSheetView.
9038 * Resizes all columns to their optimal width. Only works after the
9039 * treeview has been realized.
9042 pspp_sheet_view_columns_autosize (PsppSheetView *tree_view)
9044 gboolean dirty = FALSE;
9046 PsppSheetViewColumn *column;
9048 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9050 for (list = tree_view->priv->columns; list; list = list->next)
9052 column = list->data;
9053 _pspp_sheet_view_column_cell_set_dirty (column);
9058 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9062 * pspp_sheet_view_set_headers_clickable:
9063 * @tree_view: A #PsppSheetView.
9064 * @setting: %TRUE if the columns are clickable.
9066 * Allow the column title buttons to be clicked.
9069 pspp_sheet_view_set_headers_clickable (PsppSheetView *tree_view,
9074 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9076 for (list = tree_view->priv->columns; list; list = list->next)
9077 pspp_sheet_view_column_set_clickable (PSPP_SHEET_VIEW_COLUMN (list->data), setting);
9079 g_object_notify (G_OBJECT (tree_view), "headers-clickable");
9084 * pspp_sheet_view_get_headers_clickable:
9085 * @tree_view: A #PsppSheetView.
9087 * Returns whether all header columns are clickable.
9089 * Return value: %TRUE if all header columns are clickable, otherwise %FALSE
9094 pspp_sheet_view_get_headers_clickable (PsppSheetView *tree_view)
9098 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9100 for (list = tree_view->priv->columns; list; list = list->next)
9101 if (!PSPP_SHEET_VIEW_COLUMN (list->data)->clickable)
9108 * pspp_sheet_view_set_rules_hint
9109 * @tree_view: a #PsppSheetView
9110 * @setting: %TRUE if the tree requires reading across rows
9112 * This function tells GTK+ that the user interface for your
9113 * application requires users to read across tree rows and associate
9114 * cells with one another. By default, GTK+ will then render the tree
9115 * with alternating row colors. Do <emphasis>not</emphasis> use it
9116 * just because you prefer the appearance of the ruled tree; that's a
9117 * question for the theme. Some themes will draw tree rows in
9118 * alternating colors even when rules are turned off, and users who
9119 * prefer that appearance all the time can choose those themes. You
9120 * should call this function only as a <emphasis>semantic</emphasis>
9121 * hint to the theme engine that your tree makes alternating colors
9122 * useful from a functional standpoint (since it has lots of columns,
9127 pspp_sheet_view_set_rules_hint (PsppSheetView *tree_view,
9130 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9132 setting = setting != FALSE;
9134 if (tree_view->priv->has_rules != setting)
9136 tree_view->priv->has_rules = setting;
9137 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
9140 g_object_notify (G_OBJECT (tree_view), "rules-hint");
9144 * pspp_sheet_view_get_rules_hint
9145 * @tree_view: a #PsppSheetView
9147 * Gets the setting set by pspp_sheet_view_set_rules_hint().
9149 * Return value: %TRUE if rules are useful for the user of this tree
9152 pspp_sheet_view_get_rules_hint (PsppSheetView *tree_view)
9154 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9156 return tree_view->priv->has_rules;
9159 /* Public Column functions
9163 * pspp_sheet_view_append_column:
9164 * @tree_view: A #PsppSheetView.
9165 * @column: The #PsppSheetViewColumn to add.
9167 * Appends @column to the list of columns.
9169 * Return value: The number of columns in @tree_view after appending.
9172 pspp_sheet_view_append_column (PsppSheetView *tree_view,
9173 PsppSheetViewColumn *column)
9175 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9176 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9177 g_return_val_if_fail (column->tree_view == NULL, -1);
9179 return pspp_sheet_view_insert_column (tree_view, column, -1);
9184 * pspp_sheet_view_remove_column:
9185 * @tree_view: A #PsppSheetView.
9186 * @column: The #PsppSheetViewColumn to remove.
9188 * Removes @column from @tree_view.
9190 * Return value: The number of columns in @tree_view after removing.
9193 pspp_sheet_view_remove_column (PsppSheetView *tree_view,
9194 PsppSheetViewColumn *column)
9196 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9197 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9198 g_return_val_if_fail (column->tree_view == GTK_WIDGET (tree_view), -1);
9200 if (tree_view->priv->focus_column == column)
9201 tree_view->priv->focus_column = NULL;
9203 if (tree_view->priv->edited_column == column)
9205 pspp_sheet_view_stop_editing (tree_view, TRUE);
9207 /* no need to, but just to be sure ... */
9208 tree_view->priv->edited_column = NULL;
9211 _pspp_sheet_view_column_unset_tree_view (column);
9213 tree_view->priv->columns = g_list_remove (tree_view->priv->columns, column);
9214 tree_view->priv->n_columns--;
9216 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9220 _pspp_sheet_view_column_unrealize_button (column);
9221 for (list = tree_view->priv->columns; list; list = list->next)
9223 PsppSheetViewColumn *tmp_column;
9225 tmp_column = PSPP_SHEET_VIEW_COLUMN (list->data);
9226 if (tmp_column->visible)
9227 _pspp_sheet_view_column_cell_set_dirty (tmp_column);
9230 if (tree_view->priv->n_columns == 0 &&
9231 pspp_sheet_view_get_headers_visible (tree_view) &&
9232 tree_view->priv->header_window)
9233 gdk_window_hide (tree_view->priv->header_window);
9235 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9238 g_object_unref (column);
9239 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9241 return tree_view->priv->n_columns;
9245 * pspp_sheet_view_insert_column:
9246 * @tree_view: A #PsppSheetView.
9247 * @column: The #PsppSheetViewColumn to be inserted.
9248 * @position: The position to insert @column in.
9250 * This inserts the @column into the @tree_view at @position. If @position is
9251 * -1, then the column is inserted at the end.
9253 * Return value: The number of columns in @tree_view after insertion.
9256 pspp_sheet_view_insert_column (PsppSheetView *tree_view,
9257 PsppSheetViewColumn *column,
9260 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9261 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9262 g_return_val_if_fail (column->tree_view == NULL, -1);
9264 g_object_ref_sink (column);
9266 if (tree_view->priv->n_columns == 0 &&
9267 gtk_widget_get_realized (GTK_WIDGET (tree_view)) &&
9268 pspp_sheet_view_get_headers_visible (tree_view))
9270 gdk_window_show (tree_view->priv->header_window);
9273 tree_view->priv->columns = g_list_insert (tree_view->priv->columns,
9275 tree_view->priv->n_columns++;
9277 _pspp_sheet_view_column_set_tree_view (column, tree_view);
9279 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9283 _pspp_sheet_view_column_realize_button (column);
9285 for (list = tree_view->priv->columns; list; list = list->next)
9287 column = PSPP_SHEET_VIEW_COLUMN (list->data);
9288 if (column->visible)
9289 _pspp_sheet_view_column_cell_set_dirty (column);
9291 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9294 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9296 return tree_view->priv->n_columns;
9300 * pspp_sheet_view_insert_column_with_attributes:
9301 * @tree_view: A #PsppSheetView
9302 * @position: The position to insert the new column in.
9303 * @title: The title to set the header to.
9304 * @cell: The #GtkCellRenderer.
9305 * @Varargs: A %NULL-terminated list of attributes.
9307 * Creates a new #PsppSheetViewColumn and inserts it into the @tree_view at
9308 * @position. If @position is -1, then the newly created column is inserted at
9309 * the end. The column is initialized with the attributes given.
9311 * Return value: The number of columns in @tree_view after insertion.
9314 pspp_sheet_view_insert_column_with_attributes (PsppSheetView *tree_view,
9317 GtkCellRenderer *cell,
9320 PsppSheetViewColumn *column;
9325 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9327 column = pspp_sheet_view_column_new ();
9328 pspp_sheet_view_column_set_title (column, title);
9329 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9331 va_start (args, cell);
9333 attribute = va_arg (args, gchar *);
9335 while (attribute != NULL)
9337 column_id = va_arg (args, gint);
9338 pspp_sheet_view_column_add_attribute (column, cell, attribute, column_id);
9339 attribute = va_arg (args, gchar *);
9344 pspp_sheet_view_insert_column (tree_view, column, position);
9346 return tree_view->priv->n_columns;
9350 * pspp_sheet_view_insert_column_with_data_func:
9351 * @tree_view: a #PsppSheetView
9352 * @position: Position to insert, -1 for append
9353 * @title: column title
9354 * @cell: cell renderer for column
9355 * @func: function to set attributes of cell renderer
9356 * @data: data for @func
9357 * @dnotify: destroy notifier for @data
9359 * Convenience function that inserts a new column into the #PsppSheetView
9360 * with the given cell renderer and a #GtkCellDataFunc to set cell renderer
9361 * attributes (normally using data from the model). See also
9362 * pspp_sheet_view_column_set_cell_data_func(), pspp_sheet_view_column_pack_start().
9364 * Return value: number of columns in the tree view post-insert
9367 pspp_sheet_view_insert_column_with_data_func (PsppSheetView *tree_view,
9370 GtkCellRenderer *cell,
9371 PsppSheetCellDataFunc func,
9373 GDestroyNotify dnotify)
9375 PsppSheetViewColumn *column;
9377 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9379 column = pspp_sheet_view_column_new ();
9380 pspp_sheet_view_column_set_title (column, title);
9381 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9382 pspp_sheet_view_column_set_cell_data_func (column, cell, func, data, dnotify);
9384 pspp_sheet_view_insert_column (tree_view, column, position);
9386 return tree_view->priv->n_columns;
9390 * pspp_sheet_view_get_column:
9391 * @tree_view: A #PsppSheetView.
9392 * @n: The position of the column, counting from 0.
9394 * Gets the #PsppSheetViewColumn at the given position in the #tree_view.
9396 * Return value: The #PsppSheetViewColumn, or %NULL if the position is outside the
9399 PsppSheetViewColumn *
9400 pspp_sheet_view_get_column (PsppSheetView *tree_view,
9403 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9405 if (n < 0 || n >= tree_view->priv->n_columns)
9408 if (tree_view->priv->columns == NULL)
9411 return PSPP_SHEET_VIEW_COLUMN (g_list_nth (tree_view->priv->columns, n)->data);
9415 * pspp_sheet_view_get_columns:
9416 * @tree_view: A #PsppSheetView
9418 * Returns a #GList of all the #PsppSheetViewColumn s currently in @tree_view.
9419 * The returned list must be freed with g_list_free ().
9421 * Return value: (element-type PsppSheetViewColumn) (transfer container): A list of #PsppSheetViewColumn s
9424 pspp_sheet_view_get_columns (PsppSheetView *tree_view)
9426 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9428 return g_list_copy (tree_view->priv->columns);
9432 * pspp_sheet_view_move_column_after:
9433 * @tree_view: A #PsppSheetView
9434 * @column: The #PsppSheetViewColumn to be moved.
9435 * @base_column: (allow-none): The #PsppSheetViewColumn to be moved relative to, or %NULL.
9437 * Moves @column to be after to @base_column. If @base_column is %NULL, then
9438 * @column is placed in the first position.
9441 pspp_sheet_view_move_column_after (PsppSheetView *tree_view,
9442 PsppSheetViewColumn *column,
9443 PsppSheetViewColumn *base_column)
9445 GList *column_list_el, *base_el = NULL;
9447 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9449 column_list_el = g_list_find (tree_view->priv->columns, column);
9450 g_return_if_fail (column_list_el != NULL);
9454 base_el = g_list_find (tree_view->priv->columns, base_column);
9455 g_return_if_fail (base_el != NULL);
9458 if (column_list_el->prev == base_el)
9461 tree_view->priv->columns = g_list_remove_link (tree_view->priv->columns, column_list_el);
9462 if (base_el == NULL)
9464 column_list_el->prev = NULL;
9465 column_list_el->next = tree_view->priv->columns;
9466 if (column_list_el->next)
9467 column_list_el->next->prev = column_list_el;
9468 tree_view->priv->columns = column_list_el;
9472 column_list_el->prev = base_el;
9473 column_list_el->next = base_el->next;
9474 if (column_list_el->next)
9475 column_list_el->next->prev = column_list_el;
9476 base_el->next = column_list_el;
9479 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9481 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9482 pspp_sheet_view_size_allocate_columns (GTK_WIDGET (tree_view), NULL);
9485 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9489 * pspp_sheet_view_set_column_drag_function:
9490 * @tree_view: A #PsppSheetView.
9491 * @func: (allow-none): A function to determine which columns are reorderable, or %NULL.
9492 * @user_data: (allow-none): User data to be passed to @func, or %NULL
9493 * @destroy: (allow-none): Destroy notifier for @user_data, or %NULL
9495 * Sets a user function for determining where a column may be dropped when
9496 * dragged. This function is called on every column pair in turn at the
9497 * beginning of a column drag to determine where a drop can take place. The
9498 * arguments passed to @func are: the @tree_view, the #PsppSheetViewColumn being
9499 * dragged, the two #PsppSheetViewColumn s determining the drop spot, and
9500 * @user_data. If either of the #PsppSheetViewColumn arguments for the drop spot
9501 * are %NULL, then they indicate an edge. If @func is set to be %NULL, then
9502 * @tree_view reverts to the default behavior of allowing all columns to be
9503 * dropped everywhere.
9506 pspp_sheet_view_set_column_drag_function (PsppSheetView *tree_view,
9507 PsppSheetViewColumnDropFunc func,
9509 GDestroyNotify destroy)
9511 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9513 if (tree_view->priv->column_drop_func_data_destroy)
9514 tree_view->priv->column_drop_func_data_destroy (tree_view->priv->column_drop_func_data);
9516 tree_view->priv->column_drop_func = func;
9517 tree_view->priv->column_drop_func_data = user_data;
9518 tree_view->priv->column_drop_func_data_destroy = destroy;
9522 * pspp_sheet_view_scroll_to_point:
9523 * @tree_view: a #PsppSheetView
9524 * @tree_x: X coordinate of new top-left pixel of visible area, or -1
9525 * @tree_y: Y coordinate of new top-left pixel of visible area, or -1
9527 * Scrolls the tree view such that the top-left corner of the visible
9528 * area is @tree_x, @tree_y, where @tree_x and @tree_y are specified
9529 * in tree coordinates. The @tree_view must be realized before
9530 * this function is called. If it isn't, you probably want to be
9531 * using pspp_sheet_view_scroll_to_cell().
9533 * If either @tree_x or @tree_y are -1, then that direction isn't scrolled.
9536 pspp_sheet_view_scroll_to_point (PsppSheetView *tree_view,
9540 GtkAdjustment *hadj;
9541 GtkAdjustment *vadj;
9543 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9544 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
9546 hadj = tree_view->priv->hadjustment;
9547 vadj = tree_view->priv->vadjustment;
9550 gtk_adjustment_set_value (hadj, CLAMP (tree_x, hadj->lower, hadj->upper - hadj->page_size));
9552 gtk_adjustment_set_value (vadj, CLAMP (tree_y, vadj->lower, vadj->upper - vadj->page_size));
9556 * pspp_sheet_view_scroll_to_cell:
9557 * @tree_view: A #PsppSheetView.
9558 * @path: (allow-none): The path of the row to move to, or %NULL.
9559 * @column: (allow-none): The #PsppSheetViewColumn to move horizontally to, or %NULL.
9560 * @use_align: whether to use alignment arguments, or %FALSE.
9561 * @row_align: The vertical alignment of the row specified by @path.
9562 * @col_align: The horizontal alignment of the column specified by @column.
9564 * Moves the alignments of @tree_view to the position specified by @column and
9565 * @path. If @column is %NULL, then no horizontal scrolling occurs. Likewise,
9566 * if @path is %NULL no vertical scrolling occurs. At a minimum, one of @column
9567 * or @path need to be non-%NULL. @row_align determines where the row is
9568 * placed, and @col_align determines where @column is placed. Both are expected
9569 * to be between 0.0 and 1.0. 0.0 means left/top alignment, 1.0 means
9570 * right/bottom alignment, 0.5 means center.
9572 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
9573 * tree does the minimum amount of work to scroll the cell onto the screen.
9574 * This means that the cell will be scrolled to the edge closest to its current
9575 * position. If the cell is currently visible on the screen, nothing is done.
9577 * This function only works if the model is set, and @path is a valid row on the
9578 * model. If the model changes before the @tree_view is realized, the centered
9579 * path will be modified to reflect this change.
9582 pspp_sheet_view_scroll_to_cell (PsppSheetView *tree_view,
9584 PsppSheetViewColumn *column,
9589 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9590 g_return_if_fail (tree_view->priv->model != NULL);
9591 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
9592 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
9593 g_return_if_fail (path != NULL || column != NULL);
9596 g_print ("pspp_sheet_view_scroll_to_cell:\npath: %s\ncolumn: %s\nuse_align: %d\nrow_align: %f\ncol_align: %f\n",
9597 gtk_tree_path_to_string (path), column?"non-null":"null", use_align, row_align, col_align);
9599 row_align = CLAMP (row_align, 0.0, 1.0);
9600 col_align = CLAMP (col_align, 0.0, 1.0);
9603 /* Note: Despite the benefits that come from having one code path for the
9604 * scrolling code, we short-circuit validate_visible_area's immplementation as
9605 * it is much slower than just going to the point.
9607 if (!gtk_widget_get_visible (GTK_WIDGET (tree_view)) ||
9608 !gtk_widget_get_realized (GTK_WIDGET (tree_view))
9609 /* XXX || GTK_WIDGET_ALLOC_NEEDED (tree_view) */)
9611 if (tree_view->priv->scroll_to_path)
9612 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9614 tree_view->priv->scroll_to_path = NULL;
9615 tree_view->priv->scroll_to_column = NULL;
9618 tree_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
9620 tree_view->priv->scroll_to_column = column;
9621 tree_view->priv->scroll_to_use_align = use_align;
9622 tree_view->priv->scroll_to_row_align = row_align;
9623 tree_view->priv->scroll_to_col_align = col_align;
9625 install_presize_handler (tree_view);
9629 GdkRectangle cell_rect;
9630 GdkRectangle vis_rect;
9631 gint dest_x, dest_y;
9633 pspp_sheet_view_get_background_area (tree_view, path, column, &cell_rect);
9634 pspp_sheet_view_get_visible_rect (tree_view, &vis_rect);
9636 cell_rect.y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, cell_rect.y);
9638 dest_x = vis_rect.x;
9639 dest_y = vis_rect.y;
9645 dest_x = cell_rect.x - ((vis_rect.width - cell_rect.width) * col_align);
9649 if (cell_rect.x < vis_rect.x)
9650 dest_x = cell_rect.x;
9651 if (cell_rect.x + cell_rect.width > vis_rect.x + vis_rect.width)
9652 dest_x = cell_rect.x + cell_rect.width - vis_rect.width;
9660 dest_y = cell_rect.y - ((vis_rect.height - cell_rect.height) * row_align);
9661 dest_y = MAX (dest_y, 0);
9665 if (cell_rect.y < vis_rect.y)
9666 dest_y = cell_rect.y;
9667 if (cell_rect.y + cell_rect.height > vis_rect.y + vis_rect.height)
9668 dest_y = cell_rect.y + cell_rect.height - vis_rect.height;
9672 pspp_sheet_view_scroll_to_point (tree_view, dest_x, dest_y);
9677 * pspp_sheet_view_row_activated:
9678 * @tree_view: A #PsppSheetView
9679 * @path: The #GtkTreePath to be activated.
9680 * @column: The #PsppSheetViewColumn to be activated.
9682 * Activates the cell determined by @path and @column.
9685 pspp_sheet_view_row_activated (PsppSheetView *tree_view,
9687 PsppSheetViewColumn *column)
9689 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9691 g_signal_emit (tree_view, tree_view_signals[ROW_ACTIVATED], 0, path, column);
9696 * pspp_sheet_view_get_reorderable:
9697 * @tree_view: a #PsppSheetView
9699 * Retrieves whether the user can reorder the tree via drag-and-drop. See
9700 * pspp_sheet_view_set_reorderable().
9702 * Return value: %TRUE if the tree can be reordered.
9705 pspp_sheet_view_get_reorderable (PsppSheetView *tree_view)
9707 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9709 return tree_view->priv->reorderable;
9713 * pspp_sheet_view_set_reorderable:
9714 * @tree_view: A #PsppSheetView.
9715 * @reorderable: %TRUE, if the tree can be reordered.
9717 * This function is a convenience function to allow you to reorder
9718 * models that support the #GtkDragSourceIface and the
9719 * #GtkDragDestIface. Both #GtkTreeStore and #GtkListStore support
9720 * these. If @reorderable is %TRUE, then the user can reorder the
9721 * model by dragging and dropping rows. The developer can listen to
9722 * these changes by connecting to the model's row_inserted and
9723 * row_deleted signals. The reordering is implemented by setting up
9724 * the tree view as a drag source and destination. Therefore, drag and
9725 * drop can not be used in a reorderable view for any other purpose.
9727 * This function does not give you any degree of control over the order -- any
9728 * reordering is allowed. If more control is needed, you should probably
9729 * handle drag and drop manually.
9732 pspp_sheet_view_set_reorderable (PsppSheetView *tree_view,
9733 gboolean reorderable)
9735 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9737 reorderable = reorderable != FALSE;
9739 if (tree_view->priv->reorderable == reorderable)
9744 const GtkTargetEntry row_targets[] = {
9745 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
9748 pspp_sheet_view_enable_model_drag_source (tree_view,
9751 G_N_ELEMENTS (row_targets),
9753 pspp_sheet_view_enable_model_drag_dest (tree_view,
9755 G_N_ELEMENTS (row_targets),
9760 pspp_sheet_view_unset_rows_drag_source (tree_view);
9761 pspp_sheet_view_unset_rows_drag_dest (tree_view);
9764 tree_view->priv->reorderable = reorderable;
9766 g_object_notify (G_OBJECT (tree_view), "reorderable");
9769 /* If CLEAR_AND_SELECT is true, then the row will be selected and, unless Shift
9770 is pressed, other rows will be unselected.
9772 If CLAMP_NODE is true, then the sheetview will scroll to make the row
9775 pspp_sheet_view_real_set_cursor (PsppSheetView *tree_view,
9777 gboolean clear_and_select,
9778 gboolean clamp_node)
9782 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
9784 GtkTreePath *cursor_path;
9785 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
9786 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
9787 gtk_tree_path_free (cursor_path);
9790 gtk_tree_row_reference_free (tree_view->priv->cursor);
9791 tree_view->priv->cursor = NULL;
9793 _pspp_sheet_view_find_node (tree_view, path, &node);
9794 tree_view->priv->cursor =
9795 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
9796 tree_view->priv->model,
9799 if (tree_view->priv->row_count > 0)
9803 if (clear_and_select && !tree_view->priv->ctrl_pressed)
9805 GtkTreeSelectMode mode = 0;
9807 if (tree_view->priv->ctrl_pressed)
9808 mode |= GTK_TREE_SELECT_MODE_TOGGLE;
9809 if (tree_view->priv->shift_pressed)
9810 mode |= GTK_TREE_SELECT_MODE_EXTEND;
9812 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
9817 /* We have to re-find tree and node here again, somebody might have
9818 * cleared the node or the whole tree in the PsppSheetSelection::changed
9819 * callback. If the nodes differ we bail out here.
9821 _pspp_sheet_view_find_node (tree_view, path, &new_node);
9823 if (node != new_node)
9828 pspp_sheet_view_clamp_node_visible (tree_view, node);
9829 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
9833 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
9837 * pspp_sheet_view_get_cursor:
9838 * @tree_view: A #PsppSheetView
9839 * @path: (allow-none): A pointer to be filled with the current cursor path, or %NULL
9840 * @focus_column: (allow-none): A pointer to be filled with the current focus column, or %NULL
9842 * Fills in @path and @focus_column with the current path and focus column. If
9843 * the cursor isn't currently set, then *@path will be %NULL. If no column
9844 * currently has focus, then *@focus_column will be %NULL.
9846 * The returned #GtkTreePath must be freed with gtk_tree_path_free() when
9847 * you are done with it.
9850 pspp_sheet_view_get_cursor (PsppSheetView *tree_view,
9852 PsppSheetViewColumn **focus_column)
9854 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9858 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
9859 *path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
9866 *focus_column = tree_view->priv->focus_column;
9871 * pspp_sheet_view_set_cursor:
9872 * @tree_view: A #PsppSheetView
9873 * @path: A #GtkTreePath
9874 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
9875 * @start_editing: %TRUE if the specified cell should start being edited.
9877 * Sets the current keyboard focus to be at @path, and selects it. This is
9878 * useful when you want to focus the user's attention on a particular row. If
9879 * @focus_column is not %NULL, then focus is given to the column specified by
9880 * it. Additionally, if @focus_column is specified, and @start_editing is
9881 * %TRUE, then editing should be started in the specified cell.
9882 * This function is often followed by @gtk_widget_grab_focus (@tree_view)
9883 * in order to give keyboard focus to the widget. Please note that editing
9884 * can only happen when the widget is realized.
9886 * If @path is invalid for @model, the current cursor (if any) will be unset
9887 * and the function will return without failing.
9890 pspp_sheet_view_set_cursor (PsppSheetView *tree_view,
9892 PsppSheetViewColumn *focus_column,
9893 gboolean start_editing)
9895 pspp_sheet_view_set_cursor_on_cell (tree_view, path, focus_column,
9896 NULL, start_editing);
9900 * pspp_sheet_view_set_cursor_on_cell:
9901 * @tree_view: A #PsppSheetView
9902 * @path: A #GtkTreePath
9903 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
9904 * @focus_cell: (allow-none): A #GtkCellRenderer, or %NULL
9905 * @start_editing: %TRUE if the specified cell should start being edited.
9907 * Sets the current keyboard focus to be at @path, and selects it. This is
9908 * useful when you want to focus the user's attention on a particular row. If
9909 * @focus_column is not %NULL, then focus is given to the column specified by
9910 * it. If @focus_column and @focus_cell are not %NULL, and @focus_column
9911 * contains 2 or more editable or activatable cells, then focus is given to
9912 * the cell specified by @focus_cell. Additionally, if @focus_column is
9913 * specified, and @start_editing is %TRUE, then editing should be started in
9914 * the specified cell. This function is often followed by
9915 * @gtk_widget_grab_focus (@tree_view) in order to give keyboard focus to the
9916 * widget. Please note that editing can only happen when the widget is
9919 * If @path is invalid for @model, the current cursor (if any) will be unset
9920 * and the function will return without failing.
9925 pspp_sheet_view_set_cursor_on_cell (PsppSheetView *tree_view,
9927 PsppSheetViewColumn *focus_column,
9928 GtkCellRenderer *focus_cell,
9929 gboolean start_editing)
9931 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9932 g_return_if_fail (path != NULL);
9933 g_return_if_fail (focus_column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (focus_column));
9935 if (!tree_view->priv->model)
9940 g_return_if_fail (focus_column);
9941 g_return_if_fail (GTK_IS_CELL_RENDERER (focus_cell));
9944 /* cancel the current editing, if it exists */
9945 if (tree_view->priv->edited_column &&
9946 tree_view->priv->edited_column->editable_widget)
9947 pspp_sheet_view_stop_editing (tree_view, TRUE);
9949 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE);
9951 if (focus_column && focus_column->visible)
9954 gboolean column_in_tree = FALSE;
9956 for (list = tree_view->priv->columns; list; list = list->next)
9957 if (list->data == focus_column)
9959 column_in_tree = TRUE;
9962 g_return_if_fail (column_in_tree);
9963 tree_view->priv->focus_column = focus_column;
9965 pspp_sheet_view_column_focus_cell (focus_column, focus_cell);
9967 pspp_sheet_view_start_editing (tree_view, path);
9969 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
9970 pspp_sheet_selection_select_column (tree_view->priv->selection, focus_column);
9976 * pspp_sheet_view_get_bin_window:
9977 * @tree_view: A #PsppSheetView
9979 * Returns the window that @tree_view renders to. This is used primarily to
9980 * compare to <literal>event->window</literal> to confirm that the event on
9981 * @tree_view is on the right window.
9983 * Return value: A #GdkWindow, or %NULL when @tree_view hasn't been realized yet
9986 pspp_sheet_view_get_bin_window (PsppSheetView *tree_view)
9988 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9990 return tree_view->priv->bin_window;
9994 * pspp_sheet_view_get_path_at_pos:
9995 * @tree_view: A #PsppSheetView.
9996 * @x: The x position to be identified (relative to bin_window).
9997 * @y: The y position to be identified (relative to bin_window).
9998 * @path: (out) (allow-none): A pointer to a #GtkTreePath pointer to be filled in, or %NULL
9999 * @column: (out) (allow-none): A pointer to a #PsppSheetViewColumn pointer to be filled in, or %NULL
10000 * @cell_x: (out) (allow-none): A pointer where the X coordinate relative to the cell can be placed, or %NULL
10001 * @cell_y: (out) (allow-none): A pointer where the Y coordinate relative to the cell can be placed, or %NULL
10003 * Finds the path at the point (@x, @y), relative to bin_window coordinates
10004 * (please see pspp_sheet_view_get_bin_window()).
10005 * That is, @x and @y are relative to an events coordinates. @x and @y must
10006 * come from an event on the @tree_view only where <literal>event->window ==
10007 * pspp_sheet_view_get_bin_window (<!-- -->)</literal>. It is primarily for
10008 * things like popup menus. If @path is non-%NULL, then it will be filled
10009 * with the #GtkTreePath at that point. This path should be freed with
10010 * gtk_tree_path_free(). If @column is non-%NULL, then it will be filled
10011 * with the column at that point. @cell_x and @cell_y return the coordinates
10012 * relative to the cell background (i.e. the @background_area passed to
10013 * gtk_cell_renderer_render()). This function is only meaningful if
10014 * @tree_view is realized. Therefore this function will always return %FALSE
10015 * if @tree_view is not realized or does not have a model.
10017 * For converting widget coordinates (eg. the ones you get from
10018 * GtkWidget::query-tooltip), please see
10019 * pspp_sheet_view_convert_widget_to_bin_window_coords().
10021 * Return value: %TRUE if a row exists at that coordinate.
10024 pspp_sheet_view_get_path_at_pos (PsppSheetView *tree_view,
10027 GtkTreePath **path,
10028 PsppSheetViewColumn **column,
10035 g_return_val_if_fail (tree_view != NULL, FALSE);
10042 if (tree_view->priv->bin_window == NULL)
10045 if (tree_view->priv->row_count == 0)
10048 if (x > tree_view->priv->hadjustment->upper)
10051 if (x < 0 || y < 0)
10054 if (column || cell_x)
10056 PsppSheetViewColumn *tmp_column;
10057 PsppSheetViewColumn *last_column = NULL;
10059 gint remaining_x = x;
10060 gboolean found = FALSE;
10063 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
10064 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
10066 list = (rtl ? list->prev : list->next))
10068 tmp_column = list->data;
10070 if (tmp_column->visible == FALSE)
10073 last_column = tmp_column;
10074 if (remaining_x <= tmp_column->width)
10079 *column = tmp_column;
10082 *cell_x = remaining_x;
10086 remaining_x -= tmp_column->width;
10089 /* If found is FALSE and there is a last_column, then it the remainder
10090 * space is in that area
10097 *column = last_column;
10100 *cell_x = last_column->width + remaining_x;
10109 y_offset = pspp_sheet_view_find_offset (tree_view,
10110 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, y),
10117 *cell_y = y_offset;
10120 *path = _pspp_sheet_view_find_path (tree_view, node);
10125 /* Computes 'cell_area' from 'background_area', which must be the background
10126 area for a cell. Set 'subtract_focus_rect' to TRUE to compute the cell area
10127 as passed to a GtkCellRenderer's "render" function, or to FALSE to compute
10128 the cell area as passed to _pspp_sheet_view_column_cell_render().
10130 'column' is required to properly adjust 'cell_area->x' and
10131 'cell_area->width'. It may be set to NULL if these values are not of
10132 interest. In this case 'cell_area->x' and 'cell_area->width' will be
10135 pspp_sheet_view_adjust_cell_area (PsppSheetView *tree_view,
10136 PsppSheetViewColumn *column,
10137 const GdkRectangle *background_area,
10138 gboolean subtract_focus_rect,
10139 GdkRectangle *cell_area)
10141 gint vertical_separator;
10142 gint horizontal_separator;
10144 *cell_area = *background_area;
10146 gtk_widget_style_get (GTK_WIDGET (tree_view),
10147 "vertical-separator", &vertical_separator,
10148 "horizontal-separator", &horizontal_separator,
10150 cell_area->x += horizontal_separator / 2;
10151 cell_area->y += vertical_separator / 2;
10152 cell_area->width -= horizontal_separator;
10153 cell_area->height -= vertical_separator;
10155 if (subtract_focus_rect)
10157 int focus_line_width;
10159 gtk_widget_style_get (GTK_WIDGET (tree_view),
10160 "focus-line-width", &focus_line_width,
10162 cell_area->x += focus_line_width;
10163 cell_area->y += focus_line_width;
10164 cell_area->width -= 2 * focus_line_width;
10165 cell_area->height -= 2 * focus_line_width;
10168 if (tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_NONE)
10170 gint grid_line_width;
10171 gtk_widget_style_get (GTK_WIDGET (tree_view),
10172 "grid-line-width", &grid_line_width,
10175 if ((tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
10176 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10179 PsppSheetViewColumn *first_column, *last_column;
10182 /* Find the last visible column. */
10183 last_column = NULL;
10184 for (list = g_list_last (tree_view->priv->columns);
10188 PsppSheetViewColumn *c = list->data;
10196 /* Find the first visible column. */
10197 first_column = NULL;
10198 for (list = g_list_first (tree_view->priv->columns);
10202 PsppSheetViewColumn *c = list->data;
10210 if (column == first_column)
10212 cell_area->width -= grid_line_width / 2;
10214 else if (column == last_column)
10216 cell_area->x += grid_line_width / 2;
10217 cell_area->width -= grid_line_width / 2;
10221 cell_area->x += grid_line_width / 2;
10222 cell_area->width -= grid_line_width;
10226 if (tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
10227 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10229 cell_area->y += grid_line_width / 2;
10230 cell_area->height -= grid_line_width;
10234 if (column == NULL)
10237 cell_area->width = 0;
10242 * pspp_sheet_view_get_cell_area:
10243 * @tree_view: a #PsppSheetView
10244 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10245 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordinates
10246 * @rect: rectangle to fill with cell rect
10248 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10249 * row specified by @path and the column specified by @column. If @path is
10250 * %NULL, or points to a path not currently displayed, the @y and @height fields
10251 * of the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10252 * fields will be filled with 0. The sum of all cell rects does not cover the
10253 * entire tree; there are extra pixels in between rows, for example. The
10254 * returned rectangle is equivalent to the @cell_area passed to
10255 * gtk_cell_renderer_render(). This function is only valid if @tree_view is
10259 pspp_sheet_view_get_cell_area (PsppSheetView *tree_view,
10261 PsppSheetViewColumn *column,
10262 GdkRectangle *rect)
10264 GdkRectangle background_area;
10266 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10267 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10268 g_return_if_fail (rect != NULL);
10269 g_return_if_fail (!column || column->tree_view == (GtkWidget *) tree_view);
10270 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
10272 pspp_sheet_view_get_background_area (tree_view, path, column,
10274 pspp_sheet_view_adjust_cell_area (tree_view, column, &background_area,
10279 * pspp_sheet_view_get_background_area:
10280 * @tree_view: a #PsppSheetView
10281 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10282 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordiantes
10283 * @rect: rectangle to fill with cell background rect
10285 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10286 * row specified by @path and the column specified by @column. If @path is
10287 * %NULL, or points to a node not found in the tree, the @y and @height fields of
10288 * the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10289 * fields will be filled with 0. The returned rectangle is equivalent to the
10290 * @background_area passed to gtk_cell_renderer_render(). These background
10291 * areas tile to cover the entire bin window. Contrast with the @cell_area,
10292 * returned by pspp_sheet_view_get_cell_area(), which returns only the cell
10293 * itself, excluding surrounding borders.
10297 pspp_sheet_view_get_background_area (PsppSheetView *tree_view,
10299 PsppSheetViewColumn *column,
10300 GdkRectangle *rect)
10304 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10305 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10306 g_return_if_fail (rect != NULL);
10315 /* Get vertical coords */
10317 _pspp_sheet_view_find_node (tree_view, path, &node);
10321 rect->y = BACKGROUND_FIRST_PIXEL (tree_view, node);
10323 rect->height = ROW_HEIGHT (tree_view);
10330 pspp_sheet_view_get_background_xrange (tree_view, column, &rect->x, &x2);
10331 rect->width = x2 - rect->x;
10336 * pspp_sheet_view_get_visible_rect:
10337 * @tree_view: a #PsppSheetView
10338 * @visible_rect: rectangle to fill
10340 * Fills @visible_rect with the currently-visible region of the
10341 * buffer, in tree coordinates. Convert to bin_window coordinates with
10342 * pspp_sheet_view_convert_tree_to_bin_window_coords().
10343 * Tree coordinates start at 0,0 for row 0 of the tree, and cover the entire
10344 * scrollable area of the tree.
10347 pspp_sheet_view_get_visible_rect (PsppSheetView *tree_view,
10348 GdkRectangle *visible_rect)
10352 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10354 widget = GTK_WIDGET (tree_view);
10358 visible_rect->x = tree_view->priv->hadjustment->value;
10359 visible_rect->y = tree_view->priv->vadjustment->value;
10360 visible_rect->width = widget->allocation.width;
10361 visible_rect->height = widget->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
10366 * pspp_sheet_view_widget_to_tree_coords:
10367 * @tree_view: a #PsppSheetView
10368 * @wx: X coordinate relative to bin_window
10369 * @wy: Y coordinate relative to bin_window
10370 * @tx: return location for tree X coordinate
10371 * @ty: return location for tree Y coordinate
10373 * Converts bin_window coordinates to coordinates for the
10374 * tree (the full scrollable area of the tree).
10376 * Deprecated: 2.12: Due to historial reasons the name of this function is
10377 * incorrect. For converting coordinates relative to the widget to
10378 * bin_window coordinates, please see
10379 * pspp_sheet_view_convert_widget_to_bin_window_coords().
10383 pspp_sheet_view_widget_to_tree_coords (PsppSheetView *tree_view,
10389 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10392 *tx = wx + tree_view->priv->hadjustment->value;
10394 *ty = wy + tree_view->priv->dy;
10398 * pspp_sheet_view_tree_to_widget_coords:
10399 * @tree_view: a #PsppSheetView
10400 * @tx: tree X coordinate
10401 * @ty: tree Y coordinate
10402 * @wx: return location for X coordinate relative to bin_window
10403 * @wy: return location for Y coordinate relative to bin_window
10405 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10406 * to bin_window coordinates.
10408 * Deprecated: 2.12: Due to historial reasons the name of this function is
10409 * incorrect. For converting bin_window coordinates to coordinates relative
10410 * to bin_window, please see
10411 * pspp_sheet_view_convert_bin_window_to_widget_coords().
10415 pspp_sheet_view_tree_to_widget_coords (PsppSheetView *tree_view,
10421 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10424 *wx = tx - tree_view->priv->hadjustment->value;
10426 *wy = ty - tree_view->priv->dy;
10431 * pspp_sheet_view_convert_widget_to_tree_coords:
10432 * @tree_view: a #PsppSheetView
10433 * @wx: X coordinate relative to the widget
10434 * @wy: Y coordinate relative to the widget
10435 * @tx: return location for tree X coordinate
10436 * @ty: return location for tree Y coordinate
10438 * Converts widget coordinates to coordinates for the
10439 * tree (the full scrollable area of the tree).
10444 pspp_sheet_view_convert_widget_to_tree_coords (PsppSheetView *tree_view,
10452 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10454 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view,
10457 pspp_sheet_view_convert_bin_window_to_tree_coords (tree_view,
10463 * pspp_sheet_view_convert_tree_to_widget_coords:
10464 * @tree_view: a #PsppSheetView
10465 * @tx: X coordinate relative to the tree
10466 * @ty: Y coordinate relative to the tree
10467 * @wx: return location for widget X coordinate
10468 * @wy: return location for widget Y coordinate
10470 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10471 * to widget coordinates.
10476 pspp_sheet_view_convert_tree_to_widget_coords (PsppSheetView *tree_view,
10484 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10486 pspp_sheet_view_convert_tree_to_bin_window_coords (tree_view,
10489 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
10495 * pspp_sheet_view_convert_widget_to_bin_window_coords:
10496 * @tree_view: a #PsppSheetView
10497 * @wx: X coordinate relative to the widget
10498 * @wy: Y coordinate relative to the widget
10499 * @bx: return location for bin_window X coordinate
10500 * @by: return location for bin_window Y coordinate
10502 * Converts widget coordinates to coordinates for the bin_window
10503 * (see pspp_sheet_view_get_bin_window()).
10508 pspp_sheet_view_convert_widget_to_bin_window_coords (PsppSheetView *tree_view,
10514 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10517 *bx = wx + tree_view->priv->hadjustment->value;
10519 *by = wy - TREE_VIEW_HEADER_HEIGHT (tree_view);
10523 * pspp_sheet_view_convert_bin_window_to_widget_coords:
10524 * @tree_view: a #PsppSheetView
10525 * @bx: bin_window X coordinate
10526 * @by: bin_window Y coordinate
10527 * @wx: return location for widget X coordinate
10528 * @wy: return location for widget Y coordinate
10530 * Converts bin_window coordinates (see pspp_sheet_view_get_bin_window())
10531 * to widget relative coordinates.
10536 pspp_sheet_view_convert_bin_window_to_widget_coords (PsppSheetView *tree_view,
10542 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10545 *wx = bx - tree_view->priv->hadjustment->value;
10547 *wy = by + TREE_VIEW_HEADER_HEIGHT (tree_view);
10551 * pspp_sheet_view_convert_tree_to_bin_window_coords:
10552 * @tree_view: a #PsppSheetView
10553 * @tx: tree X coordinate
10554 * @ty: tree Y coordinate
10555 * @bx: return location for X coordinate relative to bin_window
10556 * @by: return location for Y coordinate relative to bin_window
10558 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10559 * to bin_window coordinates.
10564 pspp_sheet_view_convert_tree_to_bin_window_coords (PsppSheetView *tree_view,
10570 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10575 *by = ty - tree_view->priv->dy;
10579 * pspp_sheet_view_convert_bin_window_to_tree_coords:
10580 * @tree_view: a #PsppSheetView
10581 * @bx: X coordinate relative to bin_window
10582 * @by: Y coordinate relative to bin_window
10583 * @tx: return location for tree X coordinate
10584 * @ty: return location for tree Y coordinate
10586 * Converts bin_window coordinates to coordinates for the
10587 * tree (the full scrollable area of the tree).
10592 pspp_sheet_view_convert_bin_window_to_tree_coords (PsppSheetView *tree_view,
10598 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10603 *ty = by + tree_view->priv->dy;
10609 * pspp_sheet_view_get_visible_range:
10610 * @tree_view: A #PsppSheetView
10611 * @start_path: (allow-none): Return location for start of region, or %NULL.
10612 * @end_path: (allow-none): Return location for end of region, or %NULL.
10614 * Sets @start_path and @end_path to be the first and last visible path.
10615 * Note that there may be invisible paths in between.
10617 * The paths should be freed with gtk_tree_path_free() after use.
10619 * Returns: %TRUE, if valid paths were placed in @start_path and @end_path.
10624 pspp_sheet_view_get_visible_range (PsppSheetView *tree_view,
10625 GtkTreePath **start_path,
10626 GtkTreePath **end_path)
10631 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
10633 if (!tree_view->priv->row_count)
10640 pspp_sheet_view_find_offset (tree_view,
10641 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, 0),
10644 *start_path = _pspp_sheet_view_find_path (tree_view, node);
10653 if (tree_view->priv->height < tree_view->priv->vadjustment->page_size)
10654 y = tree_view->priv->height - 1;
10656 y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, tree_view->priv->vadjustment->page_size) - 1;
10658 pspp_sheet_view_find_offset (tree_view, y, &node);
10660 *end_path = _pspp_sheet_view_find_path (tree_view, node);
10669 unset_reorderable (PsppSheetView *tree_view)
10671 if (tree_view->priv->reorderable)
10673 tree_view->priv->reorderable = FALSE;
10674 g_object_notify (G_OBJECT (tree_view), "reorderable");
10679 * pspp_sheet_view_enable_model_drag_source:
10680 * @tree_view: a #PsppSheetView
10681 * @start_button_mask: Mask of allowed buttons to start drag
10682 * @targets: the table of targets that the drag will support
10683 * @n_targets: the number of items in @targets
10684 * @actions: the bitmask of possible actions for a drag from this
10687 * Turns @tree_view into a drag source for automatic DND. Calling this
10688 * method sets #PsppSheetView:reorderable to %FALSE.
10691 pspp_sheet_view_enable_model_drag_source (PsppSheetView *tree_view,
10692 GdkModifierType start_button_mask,
10693 const GtkTargetEntry *targets,
10695 GdkDragAction actions)
10697 TreeViewDragInfo *di;
10699 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10701 gtk_drag_source_set (GTK_WIDGET (tree_view),
10707 di = ensure_info (tree_view);
10709 di->start_button_mask = start_button_mask;
10710 di->source_actions = actions;
10711 di->source_set = TRUE;
10713 unset_reorderable (tree_view);
10717 * pspp_sheet_view_enable_model_drag_dest:
10718 * @tree_view: a #PsppSheetView
10719 * @targets: the table of targets that the drag will support
10720 * @n_targets: the number of items in @targets
10721 * @actions: the bitmask of possible actions for a drag from this
10724 * Turns @tree_view into a drop destination for automatic DND. Calling
10725 * this method sets #PsppSheetView:reorderable to %FALSE.
10728 pspp_sheet_view_enable_model_drag_dest (PsppSheetView *tree_view,
10729 const GtkTargetEntry *targets,
10731 GdkDragAction actions)
10733 TreeViewDragInfo *di;
10735 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10737 gtk_drag_dest_set (GTK_WIDGET (tree_view),
10743 di = ensure_info (tree_view);
10744 di->dest_set = TRUE;
10746 unset_reorderable (tree_view);
10750 * pspp_sheet_view_unset_rows_drag_source:
10751 * @tree_view: a #PsppSheetView
10753 * Undoes the effect of
10754 * pspp_sheet_view_enable_model_drag_source(). Calling this method sets
10755 * #PsppSheetView:reorderable to %FALSE.
10758 pspp_sheet_view_unset_rows_drag_source (PsppSheetView *tree_view)
10760 TreeViewDragInfo *di;
10762 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10764 di = get_info (tree_view);
10768 if (di->source_set)
10770 gtk_drag_source_unset (GTK_WIDGET (tree_view));
10771 di->source_set = FALSE;
10774 if (!di->dest_set && !di->source_set)
10775 remove_info (tree_view);
10778 unset_reorderable (tree_view);
10782 * pspp_sheet_view_unset_rows_drag_dest:
10783 * @tree_view: a #PsppSheetView
10785 * Undoes the effect of
10786 * pspp_sheet_view_enable_model_drag_dest(). Calling this method sets
10787 * #PsppSheetView:reorderable to %FALSE.
10790 pspp_sheet_view_unset_rows_drag_dest (PsppSheetView *tree_view)
10792 TreeViewDragInfo *di;
10794 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10796 di = get_info (tree_view);
10802 gtk_drag_dest_unset (GTK_WIDGET (tree_view));
10803 di->dest_set = FALSE;
10806 if (!di->dest_set && !di->source_set)
10807 remove_info (tree_view);
10810 unset_reorderable (tree_view);
10814 * pspp_sheet_view_set_drag_dest_row:
10815 * @tree_view: a #PsppSheetView
10816 * @path: (allow-none): The path of the row to highlight, or %NULL.
10817 * @pos: Specifies whether to drop before, after or into the row
10819 * Sets the row that is highlighted for feedback.
10822 pspp_sheet_view_set_drag_dest_row (PsppSheetView *tree_view,
10824 PsppSheetViewDropPosition pos)
10826 GtkTreePath *current_dest;
10828 /* Note; this function is exported to allow a custom DND
10829 * implementation, so it can't touch TreeViewDragInfo
10832 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10834 current_dest = NULL;
10836 if (tree_view->priv->drag_dest_row)
10838 current_dest = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
10839 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
10842 /* special case a drop on an empty model */
10843 tree_view->priv->empty_view_drop = 0;
10845 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE && path
10846 && gtk_tree_path_get_depth (path) == 1
10847 && gtk_tree_path_get_indices (path)[0] == 0)
10851 n_children = gtk_tree_model_iter_n_children (tree_view->priv->model,
10855 tree_view->priv->empty_view_drop = 1;
10858 tree_view->priv->drag_dest_pos = pos;
10862 tree_view->priv->drag_dest_row =
10863 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
10864 pspp_sheet_view_queue_draw_path (tree_view, path, NULL);
10867 tree_view->priv->drag_dest_row = NULL;
10871 int node, new_node;
10873 _pspp_sheet_view_find_node (tree_view, current_dest, &node);
10874 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
10878 new_node = pspp_sheet_view_node_next (tree_view, node);
10880 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
10882 new_node = pspp_sheet_view_node_prev (tree_view, node);
10884 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
10886 gtk_tree_path_free (current_dest);
10891 * pspp_sheet_view_get_drag_dest_row:
10892 * @tree_view: a #PsppSheetView
10893 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
10894 * @pos: (allow-none): Return location for the drop position, or %NULL
10896 * Gets information about the row that is highlighted for feedback.
10899 pspp_sheet_view_get_drag_dest_row (PsppSheetView *tree_view,
10900 GtkTreePath **path,
10901 PsppSheetViewDropPosition *pos)
10903 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10907 if (tree_view->priv->drag_dest_row)
10908 *path = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
10911 if (tree_view->priv->empty_view_drop)
10912 *path = gtk_tree_path_new_from_indices (0, -1);
10919 *pos = tree_view->priv->drag_dest_pos;
10923 * pspp_sheet_view_get_dest_row_at_pos:
10924 * @tree_view: a #PsppSheetView
10925 * @drag_x: the position to determine the destination row for
10926 * @drag_y: the position to determine the destination row for
10927 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
10928 * @pos: (allow-none): Return location for the drop position, or %NULL
10930 * Determines the destination row for a given position. @drag_x and
10931 * @drag_y are expected to be in widget coordinates. This function is only
10932 * meaningful if @tree_view is realized. Therefore this function will always
10933 * return %FALSE if @tree_view is not realized or does not have a model.
10935 * Return value: whether there is a row at the given position, %TRUE if this
10936 * is indeed the case.
10939 pspp_sheet_view_get_dest_row_at_pos (PsppSheetView *tree_view,
10942 GtkTreePath **path,
10943 PsppSheetViewDropPosition *pos)
10947 gdouble offset_into_row;
10950 PsppSheetViewColumn *column = NULL;
10951 GtkTreePath *tmp_path = NULL;
10953 /* Note; this function is exported to allow a custom DND
10954 * implementation, so it can't touch TreeViewDragInfo
10957 g_return_val_if_fail (tree_view != NULL, FALSE);
10958 g_return_val_if_fail (drag_x >= 0, FALSE);
10959 g_return_val_if_fail (drag_y >= 0, FALSE);
10964 if (tree_view->priv->bin_window == NULL)
10967 if (tree_view->priv->row_count == 0)
10970 /* If in the top third of a row, we drop before that row; if
10971 * in the bottom third, drop after that row; if in the middle,
10972 * and the row has children, drop into the row.
10974 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, drag_x, drag_y,
10977 if (!pspp_sheet_view_get_path_at_pos (tree_view,
10986 pspp_sheet_view_get_background_area (tree_view, tmp_path, column,
10989 offset_into_row = cell_y;
10994 gtk_tree_path_free (tmp_path);
10998 third = cell.height / 3.0;
11002 if (offset_into_row < third)
11004 *pos = PSPP_SHEET_VIEW_DROP_BEFORE;
11006 else if (offset_into_row < (cell.height / 2.0))
11008 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE;
11010 else if (offset_into_row < third * 2.0)
11012 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER;
11016 *pos = PSPP_SHEET_VIEW_DROP_AFTER;
11025 /* KEEP IN SYNC WITH PSPP_SHEET_VIEW_BIN_EXPOSE */
11027 * pspp_sheet_view_create_row_drag_icon:
11028 * @tree_view: a #PsppSheetView
11029 * @path: a #GtkTreePath in @tree_view
11031 * Creates a #GdkPixmap representation of the row at @path.
11032 * This image is used for a drag icon.
11034 * Return value: a newly-allocated pixmap of the drag icon.
11037 pspp_sheet_view_create_row_drag_icon (PsppSheetView *tree_view,
11044 GdkRectangle background_area;
11045 GdkRectangle expose_area;
11047 /* start drawing inside the black outline */
11049 GdkDrawable *drawable;
11050 gint bin_window_width;
11053 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11054 g_return_val_if_fail (path != NULL, NULL);
11056 widget = GTK_WIDGET (tree_view);
11058 if (!gtk_widget_get_realized (widget))
11061 _pspp_sheet_view_find_node (tree_view,
11068 if (!gtk_tree_model_get_iter (tree_view->priv->model,
11075 background_area.y = y;
11076 background_area.height = ROW_HEIGHT (tree_view);
11078 gdk_drawable_get_size (tree_view->priv->bin_window,
11079 &bin_window_width, NULL);
11081 drawable = gdk_pixmap_new (tree_view->priv->bin_window,
11082 bin_window_width + 2,
11083 background_area.height + 2,
11088 expose_area.width = bin_window_width + 2;
11089 expose_area.height = background_area.height + 2;
11091 gdk_draw_rectangle (drawable,
11092 widget->style->base_gc [gtk_widget_get_state (widget)],
11095 bin_window_width + 2,
11096 background_area.height + 2);
11098 rtl = gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL;
11100 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
11102 list = (rtl ? list->prev : list->next))
11104 PsppSheetViewColumn *column = list->data;
11105 GdkRectangle cell_area;
11106 gint vertical_separator;
11108 if (!column->visible)
11111 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, &iter);
11113 background_area.x = cell_offset;
11114 background_area.width = column->width;
11116 gtk_widget_style_get (widget,
11117 "vertical-separator", &vertical_separator,
11120 cell_area = background_area;
11122 cell_area.y += vertical_separator / 2;
11123 cell_area.height -= vertical_separator;
11125 if (pspp_sheet_view_column_cell_is_visible (column))
11126 _pspp_sheet_view_column_cell_render (column,
11132 cell_offset += column->width;
11135 gdk_draw_rectangle (drawable,
11136 widget->style->black_gc,
11139 bin_window_width + 1,
11140 background_area.height + 1);
11147 * pspp_sheet_view_set_destroy_count_func:
11148 * @tree_view: A #PsppSheetView
11149 * @func: (allow-none): Function to be called when a view row is destroyed, or %NULL
11150 * @data: (allow-none): User data to be passed to @func, or %NULL
11151 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11153 * This function should almost never be used. It is meant for private use by
11154 * ATK for determining the number of visible children that are removed when a row is deleted.
11157 pspp_sheet_view_set_destroy_count_func (PsppSheetView *tree_view,
11158 PsppSheetDestroyCountFunc func,
11160 GDestroyNotify destroy)
11162 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11164 if (tree_view->priv->destroy_count_destroy)
11165 tree_view->priv->destroy_count_destroy (tree_view->priv->destroy_count_data);
11167 tree_view->priv->destroy_count_func = func;
11168 tree_view->priv->destroy_count_data = data;
11169 tree_view->priv->destroy_count_destroy = destroy;
11174 * Interactive search
11178 * pspp_sheet_view_set_enable_search:
11179 * @tree_view: A #PsppSheetView
11180 * @enable_search: %TRUE, if the user can search interactively
11182 * If @enable_search is set, then the user can type in text to search through
11183 * the tree interactively (this is sometimes called "typeahead find").
11185 * Note that even if this is %FALSE, the user can still initiate a search
11186 * using the "start-interactive-search" key binding.
11189 pspp_sheet_view_set_enable_search (PsppSheetView *tree_view,
11190 gboolean enable_search)
11192 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11194 enable_search = !!enable_search;
11196 if (tree_view->priv->enable_search != enable_search)
11198 tree_view->priv->enable_search = enable_search;
11199 g_object_notify (G_OBJECT (tree_view), "enable-search");
11204 * pspp_sheet_view_get_enable_search:
11205 * @tree_view: A #PsppSheetView
11207 * Returns whether or not the tree allows to start interactive searching
11208 * by typing in text.
11210 * Return value: whether or not to let the user search interactively
11213 pspp_sheet_view_get_enable_search (PsppSheetView *tree_view)
11215 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11217 return tree_view->priv->enable_search;
11222 * pspp_sheet_view_get_search_column:
11223 * @tree_view: A #PsppSheetView
11225 * Gets the column searched on by the interactive search code.
11227 * Return value: the column the interactive search code searches in.
11230 pspp_sheet_view_get_search_column (PsppSheetView *tree_view)
11232 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
11234 return (tree_view->priv->search_column);
11238 * pspp_sheet_view_set_search_column:
11239 * @tree_view: A #PsppSheetView
11240 * @column: the column of the model to search in, or -1 to disable searching
11242 * Sets @column as the column where the interactive search code should
11243 * search in for the current model.
11245 * If the search column is set, users can use the "start-interactive-search"
11246 * key binding to bring up search popup. The enable-search property controls
11247 * whether simply typing text will also start an interactive search.
11249 * Note that @column refers to a column of the current model. The search
11250 * column is reset to -1 when the model is changed.
11253 pspp_sheet_view_set_search_column (PsppSheetView *tree_view,
11256 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11257 g_return_if_fail (column >= -1);
11259 if (tree_view->priv->search_column == column)
11262 tree_view->priv->search_column = column;
11263 g_object_notify (G_OBJECT (tree_view), "search-column");
11267 * pspp_sheet_view_get_search_equal_func:
11268 * @tree_view: A #PsppSheetView
11270 * Returns the compare function currently in use.
11272 * Return value: the currently used compare function for the search code.
11275 PsppSheetViewSearchEqualFunc
11276 pspp_sheet_view_get_search_equal_func (PsppSheetView *tree_view)
11278 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11280 return tree_view->priv->search_equal_func;
11284 * pspp_sheet_view_set_search_equal_func:
11285 * @tree_view: A #PsppSheetView
11286 * @search_equal_func: the compare function to use during the search
11287 * @search_user_data: (allow-none): user data to pass to @search_equal_func, or %NULL
11288 * @search_destroy: (allow-none): Destroy notifier for @search_user_data, or %NULL
11290 * Sets the compare function for the interactive search capabilities; note
11291 * that somewhat like strcmp() returning 0 for equality
11292 * #PsppSheetViewSearchEqualFunc returns %FALSE on matches.
11295 pspp_sheet_view_set_search_equal_func (PsppSheetView *tree_view,
11296 PsppSheetViewSearchEqualFunc search_equal_func,
11297 gpointer search_user_data,
11298 GDestroyNotify search_destroy)
11300 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11301 g_return_if_fail (search_equal_func != NULL);
11303 if (tree_view->priv->search_destroy)
11304 tree_view->priv->search_destroy (tree_view->priv->search_user_data);
11306 tree_view->priv->search_equal_func = search_equal_func;
11307 tree_view->priv->search_user_data = search_user_data;
11308 tree_view->priv->search_destroy = search_destroy;
11309 if (tree_view->priv->search_equal_func == NULL)
11310 tree_view->priv->search_equal_func = pspp_sheet_view_search_equal_func;
11314 * pspp_sheet_view_get_search_entry:
11315 * @tree_view: A #PsppSheetView
11317 * Returns the #GtkEntry which is currently in use as interactive search
11318 * entry for @tree_view. In case the built-in entry is being used, %NULL
11319 * will be returned.
11321 * Return value: the entry currently in use as search entry.
11326 pspp_sheet_view_get_search_entry (PsppSheetView *tree_view)
11328 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11330 if (tree_view->priv->search_custom_entry_set)
11331 return GTK_ENTRY (tree_view->priv->search_entry);
11337 * pspp_sheet_view_set_search_entry:
11338 * @tree_view: A #PsppSheetView
11339 * @entry: (allow-none): the entry the interactive search code of @tree_view should use or %NULL
11341 * Sets the entry which the interactive search code will use for this
11342 * @tree_view. This is useful when you want to provide a search entry
11343 * in our interface at all time at a fixed position. Passing %NULL for
11344 * @entry will make the interactive search code use the built-in popup
11350 pspp_sheet_view_set_search_entry (PsppSheetView *tree_view,
11353 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11354 g_return_if_fail (entry == NULL || GTK_IS_ENTRY (entry));
11356 if (tree_view->priv->search_custom_entry_set)
11358 if (tree_view->priv->search_entry_changed_id)
11360 g_signal_handler_disconnect (tree_view->priv->search_entry,
11361 tree_view->priv->search_entry_changed_id);
11362 tree_view->priv->search_entry_changed_id = 0;
11364 g_signal_handlers_disconnect_by_func (tree_view->priv->search_entry,
11365 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11368 g_object_unref (tree_view->priv->search_entry);
11370 else if (tree_view->priv->search_window)
11372 gtk_widget_destroy (tree_view->priv->search_window);
11374 tree_view->priv->search_window = NULL;
11379 tree_view->priv->search_entry = g_object_ref (entry);
11380 tree_view->priv->search_custom_entry_set = TRUE;
11382 if (tree_view->priv->search_entry_changed_id == 0)
11384 tree_view->priv->search_entry_changed_id =
11385 g_signal_connect (tree_view->priv->search_entry, "changed",
11386 G_CALLBACK (pspp_sheet_view_search_init),
11390 g_signal_connect (tree_view->priv->search_entry, "key-press-event",
11391 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11394 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
11398 tree_view->priv->search_entry = NULL;
11399 tree_view->priv->search_custom_entry_set = FALSE;
11404 * pspp_sheet_view_set_search_position_func:
11405 * @tree_view: A #PsppSheetView
11406 * @func: (allow-none): the function to use to position the search dialog, or %NULL
11407 * to use the default search position function
11408 * @data: (allow-none): user data to pass to @func, or %NULL
11409 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11411 * Sets the function to use when positioning the search dialog.
11416 pspp_sheet_view_set_search_position_func (PsppSheetView *tree_view,
11417 PsppSheetViewSearchPositionFunc func,
11418 gpointer user_data,
11419 GDestroyNotify destroy)
11421 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11423 if (tree_view->priv->search_position_destroy)
11424 tree_view->priv->search_position_destroy (tree_view->priv->search_position_user_data);
11426 tree_view->priv->search_position_func = func;
11427 tree_view->priv->search_position_user_data = user_data;
11428 tree_view->priv->search_position_destroy = destroy;
11429 if (tree_view->priv->search_position_func == NULL)
11430 tree_view->priv->search_position_func = pspp_sheet_view_search_position_func;
11434 * pspp_sheet_view_get_search_position_func:
11435 * @tree_view: A #PsppSheetView
11437 * Returns the positioning function currently in use.
11439 * Return value: the currently used function for positioning the search dialog.
11443 PsppSheetViewSearchPositionFunc
11444 pspp_sheet_view_get_search_position_func (PsppSheetView *tree_view)
11446 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11448 return tree_view->priv->search_position_func;
11453 pspp_sheet_view_search_dialog_hide (GtkWidget *search_dialog,
11454 PsppSheetView *tree_view)
11456 if (tree_view->priv->disable_popdown)
11459 if (tree_view->priv->search_entry_changed_id)
11461 g_signal_handler_disconnect (tree_view->priv->search_entry,
11462 tree_view->priv->search_entry_changed_id);
11463 tree_view->priv->search_entry_changed_id = 0;
11465 if (tree_view->priv->typeselect_flush_timeout)
11467 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11468 tree_view->priv->typeselect_flush_timeout = 0;
11471 if (gtk_widget_get_visible (search_dialog))
11473 /* send focus-in event */
11474 send_focus_change (GTK_WIDGET (tree_view->priv->search_entry), FALSE);
11475 gtk_widget_hide (search_dialog);
11476 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
11477 send_focus_change (GTK_WIDGET (tree_view), TRUE);
11482 pspp_sheet_view_search_position_func (PsppSheetView *tree_view,
11483 GtkWidget *search_dialog,
11484 gpointer user_data)
11487 gint tree_x, tree_y;
11488 gint tree_width, tree_height;
11489 GdkWindow *tree_window = GTK_WIDGET (tree_view)->window;
11490 GdkScreen *screen = gdk_drawable_get_screen (tree_window);
11491 GtkRequisition requisition;
11493 GdkRectangle monitor;
11495 monitor_num = gdk_screen_get_monitor_at_window (screen, tree_window);
11496 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
11498 gtk_widget_realize (search_dialog);
11500 gdk_window_get_origin (tree_window, &tree_x, &tree_y);
11501 gdk_drawable_get_size (tree_window,
11504 gtk_widget_size_request (search_dialog, &requisition);
11506 if (tree_x + tree_width > gdk_screen_get_width (screen))
11507 x = gdk_screen_get_width (screen) - requisition.width;
11508 else if (tree_x + tree_width - requisition.width < 0)
11511 x = tree_x + tree_width - requisition.width;
11513 if (tree_y + tree_height + requisition.height > gdk_screen_get_height (screen))
11514 y = gdk_screen_get_height (screen) - requisition.height;
11515 else if (tree_y + tree_height < 0) /* isn't really possible ... */
11518 y = tree_y + tree_height;
11520 gtk_window_move (GTK_WINDOW (search_dialog), x, y);
11524 pspp_sheet_view_search_disable_popdown (GtkEntry *entry,
11528 PsppSheetView *tree_view = (PsppSheetView *)data;
11530 tree_view->priv->disable_popdown = 1;
11531 g_signal_connect (menu, "hide",
11532 G_CALLBACK (pspp_sheet_view_search_enable_popdown), data);
11535 /* Because we're visible but offscreen, we just set a flag in the preedit
11539 pspp_sheet_view_search_preedit_changed (GtkIMContext *im_context,
11540 PsppSheetView *tree_view)
11542 tree_view->priv->imcontext_changed = 1;
11543 if (tree_view->priv->typeselect_flush_timeout)
11545 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11546 tree_view->priv->typeselect_flush_timeout =
11547 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11548 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11555 pspp_sheet_view_search_activate (GtkEntry *entry,
11556 PsppSheetView *tree_view)
11561 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window,
11564 /* If we have a row selected and it's the cursor row, we activate
11566 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
11568 path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
11570 _pspp_sheet_view_find_node (tree_view, path, &node);
11572 if (node >= 0 && pspp_sheet_view_node_is_selected (tree_view, node))
11573 pspp_sheet_view_row_activated (tree_view, path, tree_view->priv->focus_column);
11575 gtk_tree_path_free (path);
11580 pspp_sheet_view_real_search_enable_popdown (gpointer data)
11582 PsppSheetView *tree_view = (PsppSheetView *)data;
11584 tree_view->priv->disable_popdown = 0;
11590 pspp_sheet_view_search_enable_popdown (GtkWidget *widget,
11593 gdk_threads_add_timeout_full (G_PRIORITY_HIGH, 200, pspp_sheet_view_real_search_enable_popdown, g_object_ref (data), g_object_unref);
11597 pspp_sheet_view_search_delete_event (GtkWidget *widget,
11598 GdkEventAny *event,
11599 PsppSheetView *tree_view)
11601 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11603 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11609 pspp_sheet_view_search_button_press_event (GtkWidget *widget,
11610 GdkEventButton *event,
11611 PsppSheetView *tree_view)
11613 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11615 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11617 if (event->window == tree_view->priv->bin_window)
11618 pspp_sheet_view_button_press (GTK_WIDGET (tree_view), event);
11624 pspp_sheet_view_search_scroll_event (GtkWidget *widget,
11625 GdkEventScroll *event,
11626 PsppSheetView *tree_view)
11628 gboolean retval = FALSE;
11630 if (event->direction == GDK_SCROLL_UP)
11632 pspp_sheet_view_search_move (widget, tree_view, TRUE);
11635 else if (event->direction == GDK_SCROLL_DOWN)
11637 pspp_sheet_view_search_move (widget, tree_view, FALSE);
11641 /* renew the flush timeout */
11642 if (retval && tree_view->priv->typeselect_flush_timeout
11643 && !tree_view->priv->search_custom_entry_set)
11645 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11646 tree_view->priv->typeselect_flush_timeout =
11647 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11648 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11656 pspp_sheet_view_search_key_press_event (GtkWidget *widget,
11657 GdkEventKey *event,
11658 PsppSheetView *tree_view)
11660 gboolean retval = FALSE;
11662 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11663 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11665 /* close window and cancel the search */
11666 if (!tree_view->priv->search_custom_entry_set
11667 && (event->keyval == GDK_Escape ||
11668 event->keyval == GDK_Tab ||
11669 event->keyval == GDK_KP_Tab ||
11670 event->keyval == GDK_ISO_Left_Tab))
11672 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11676 /* select previous matching iter */
11677 if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up)
11679 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
11680 gtk_widget_error_bell (widget);
11685 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK))
11686 && (event->keyval == GDK_g || event->keyval == GDK_G))
11688 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
11689 gtk_widget_error_bell (widget);
11694 /* select next matching iter */
11695 if (event->keyval == GDK_Down || event->keyval == GDK_KP_Down)
11697 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
11698 gtk_widget_error_bell (widget);
11703 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == GTK_DEFAULT_ACCEL_MOD_MASK)
11704 && (event->keyval == GDK_g || event->keyval == GDK_G))
11706 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
11707 gtk_widget_error_bell (widget);
11712 /* renew the flush timeout */
11713 if (retval && tree_view->priv->typeselect_flush_timeout
11714 && !tree_view->priv->search_custom_entry_set)
11716 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11717 tree_view->priv->typeselect_flush_timeout =
11718 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11719 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11726 /* this function returns FALSE if there is a search string but
11727 * nothing was found, and TRUE otherwise.
11730 pspp_sheet_view_search_move (GtkWidget *window,
11731 PsppSheetView *tree_view,
11739 GtkTreeModel *model;
11740 PsppSheetSelection *selection;
11742 text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
11744 g_return_val_if_fail (text != NULL, FALSE);
11746 len = strlen (text);
11748 if (up && tree_view->priv->selected_iter == 1)
11749 return strlen (text) < 1;
11751 len = strlen (text);
11756 model = pspp_sheet_view_get_model (tree_view);
11757 selection = pspp_sheet_view_get_selection (tree_view);
11760 pspp_sheet_selection_unselect_all (selection);
11761 if (!gtk_tree_model_get_iter_first (model, &iter))
11764 ret = pspp_sheet_view_search_iter (model, selection, &iter, text,
11765 &count, up?((tree_view->priv->selected_iter) - 1):((tree_view->priv->selected_iter + 1)));
11770 tree_view->priv->selected_iter += up?(-1):(1);
11775 /* return to old iter */
11777 gtk_tree_model_get_iter_first (model, &iter);
11778 pspp_sheet_view_search_iter (model, selection,
11780 &count, tree_view->priv->selected_iter);
11786 pspp_sheet_view_search_equal_func (GtkTreeModel *model,
11790 gpointer search_data)
11792 gboolean retval = TRUE;
11794 gchar *normalized_string;
11795 gchar *normalized_key;
11796 gchar *case_normalized_string = NULL;
11797 gchar *case_normalized_key = NULL;
11798 GValue value = {0,};
11799 GValue transformed = {0,};
11801 gtk_tree_model_get_value (model, iter, column, &value);
11803 g_value_init (&transformed, G_TYPE_STRING);
11805 if (!g_value_transform (&value, &transformed))
11807 g_value_unset (&value);
11811 g_value_unset (&value);
11813 str = g_value_get_string (&transformed);
11816 g_value_unset (&transformed);
11820 normalized_string = g_utf8_normalize (str, -1, G_NORMALIZE_ALL);
11821 normalized_key = g_utf8_normalize (key, -1, G_NORMALIZE_ALL);
11823 if (normalized_string && normalized_key)
11825 case_normalized_string = g_utf8_casefold (normalized_string, -1);
11826 case_normalized_key = g_utf8_casefold (normalized_key, -1);
11828 if (strncmp (case_normalized_key, case_normalized_string, strlen (case_normalized_key)) == 0)
11832 g_value_unset (&transformed);
11833 g_free (normalized_key);
11834 g_free (normalized_string);
11835 g_free (case_normalized_key);
11836 g_free (case_normalized_string);
11842 pspp_sheet_view_search_iter (GtkTreeModel *model,
11843 PsppSheetSelection *selection,
11852 PsppSheetView *tree_view = pspp_sheet_selection_get_tree_view (selection);
11854 path = gtk_tree_model_get_path (model, iter);
11855 _pspp_sheet_view_find_node (tree_view, path, &node);
11859 gboolean done = FALSE;
11861 if (! tree_view->priv->search_equal_func (model, tree_view->priv->search_column, text, iter, tree_view->priv->search_user_data))
11866 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL,
11868 pspp_sheet_selection_select_iter (selection, iter);
11869 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE);
11872 gtk_tree_path_free (path);
11881 node = pspp_sheet_view_node_next (tree_view, node);
11887 has_next = gtk_tree_model_iter_next (model, iter);
11890 gtk_tree_path_next (path);
11893 TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
11898 gtk_tree_path_free (path);
11900 /* we've run out of tree, done with this func */
11912 pspp_sheet_view_search_init (GtkWidget *entry,
11913 PsppSheetView *tree_view)
11919 GtkTreeModel *model;
11920 PsppSheetSelection *selection;
11922 g_return_if_fail (GTK_IS_ENTRY (entry));
11923 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11925 text = gtk_entry_get_text (GTK_ENTRY (entry));
11927 model = pspp_sheet_view_get_model (tree_view);
11928 selection = pspp_sheet_view_get_selection (tree_view);
11931 pspp_sheet_selection_unselect_all (selection);
11932 if (tree_view->priv->typeselect_flush_timeout
11933 && !tree_view->priv->search_custom_entry_set)
11935 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11936 tree_view->priv->typeselect_flush_timeout =
11937 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11938 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11945 if (!gtk_tree_model_get_iter_first (model, &iter))
11948 ret = pspp_sheet_view_search_iter (model, selection,
11953 tree_view->priv->selected_iter = 1;
11957 pspp_sheet_view_remove_widget (GtkCellEditable *cell_editable,
11958 PsppSheetView *tree_view)
11960 if (tree_view->priv->edited_column == NULL)
11963 _pspp_sheet_view_column_stop_editing (tree_view->priv->edited_column);
11964 tree_view->priv->edited_column = NULL;
11966 if (gtk_widget_has_focus (GTK_WIDGET (cell_editable)))
11967 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
11969 g_signal_handlers_disconnect_by_func (cell_editable,
11970 pspp_sheet_view_remove_widget,
11972 g_signal_handlers_disconnect_by_func (cell_editable,
11973 pspp_sheet_view_editable_button_press_event,
11975 g_signal_handlers_disconnect_by_func (cell_editable,
11976 pspp_sheet_view_editable_clicked,
11979 gtk_container_remove (GTK_CONTAINER (tree_view),
11980 GTK_WIDGET (cell_editable));
11982 /* FIXME should only redraw a single node */
11983 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
11987 pspp_sheet_view_start_editing (PsppSheetView *tree_view,
11988 GtkTreePath *cursor_path)
11991 GdkRectangle background_area;
11992 GdkRectangle cell_area;
11993 GtkCellEditable *editable_widget = NULL;
11994 gchar *path_string;
11995 guint flags = 0; /* can be 0, as the flags are primarily for rendering */
11996 gint retval = FALSE;
11999 g_assert (tree_view->priv->focus_column);
12001 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
12004 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
12005 if (cursor_node < 0)
12008 path_string = gtk_tree_path_to_string (cursor_path);
12009 gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path);
12011 pspp_sheet_view_column_cell_set_cell_data (tree_view->priv->focus_column,
12012 tree_view->priv->model,
12014 pspp_sheet_view_get_background_area (tree_view,
12016 tree_view->priv->focus_column,
12018 pspp_sheet_view_get_cell_area (tree_view,
12020 tree_view->priv->focus_column,
12023 if (_pspp_sheet_view_column_cell_event (tree_view->priv->focus_column,
12032 if (editable_widget != NULL)
12036 GtkCellRenderer *cell;
12039 cell = _pspp_sheet_view_column_get_edited_cell (tree_view->priv->focus_column);
12041 _pspp_sheet_view_column_get_neighbor_sizes (tree_view->priv->focus_column, cell, &left, &right);
12044 area.width -= right + left;
12046 pspp_sheet_view_real_start_editing (tree_view,
12047 tree_view->priv->focus_column,
12056 g_free (path_string);
12061 pspp_sheet_view_editable_button_press_event (GtkWidget *widget,
12062 GdkEventButton *event,
12063 PsppSheetView *sheet_view)
12067 node = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
12068 "pspp-sheet-view-node"));
12069 return pspp_sheet_view_row_head_clicked (sheet_view,
12071 sheet_view->priv->edited_column,
12076 pspp_sheet_view_editable_clicked (GtkButton *button,
12077 PsppSheetView *sheet_view)
12079 pspp_sheet_view_editable_button_press_event (GTK_WIDGET (button), NULL,
12084 is_all_selected (GtkWidget *widget)
12086 GtkEntryBuffer *buffer;
12087 gint start_pos, end_pos;
12089 if (!GTK_IS_ENTRY (widget))
12092 buffer = gtk_entry_get_buffer (GTK_ENTRY (widget));
12093 return (gtk_editable_get_selection_bounds (GTK_EDITABLE (widget),
12094 &start_pos, &end_pos)
12096 && end_pos == gtk_entry_buffer_get_length (buffer));
12100 is_at_left (GtkWidget *widget)
12102 return (GTK_IS_ENTRY (widget)
12103 && gtk_editable_get_position (GTK_EDITABLE (widget)) == 0);
12107 is_at_right (GtkWidget *widget)
12109 GtkEntryBuffer *buffer;
12112 if (!GTK_IS_ENTRY (widget))
12115 buffer = gtk_entry_get_buffer (GTK_ENTRY (widget));
12116 length = gtk_entry_buffer_get_length (buffer);
12117 return gtk_editable_get_position (GTK_EDITABLE (widget)) == length;
12121 pspp_sheet_view_event (GtkWidget *widget,
12122 GdkEventKey *event,
12123 PsppSheetView *tree_view)
12125 PsppSheetViewColumn *column;
12133 /* Intercept only key press events.
12134 It would make sense to use "key-press-event" instead of "event", but
12135 GtkEntry attaches its own signal handler to "key-press-event" that runs
12136 before ours and overrides our desired behavior for GDK_Up and GDK_Down.
12138 if (event->type != GDK_KEY_PRESS)
12141 if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK | GDK_MOD1_MASK))
12143 /* Pass through most keys that include modifiers. */
12144 if ((event->keyval == GDK_Tab || event->keyval == GDK_ISO_Left_Tab)
12145 && !(event->state & (GDK_CONTROL_MASK | GDK_MOD1_MASK)))
12147 /* Special case for Shift-Tab. */
12153 keyval = event->keyval;
12154 state = event->state & ~(GDK_CONTROL_MASK | GDK_SHIFT_MASK | GDK_MOD1_MASK);
12156 switch (event->keyval)
12158 case GDK_Left: case GDK_KP_Left:
12159 if (!is_all_selected (widget) && !is_at_left (widget))
12163 case GDK_Right: case GDK_KP_Right:
12164 if (!is_all_selected (widget) && !is_at_right (widget))
12168 case GDK_Up: case GDK_KP_Up:
12169 case GDK_Down: case GDK_KP_Down:
12172 case GDK_Page_Up: case GDK_KP_Page_Up:
12173 case GDK_Page_Down: case GDK_KP_Page_Down:
12185 case GDK_ISO_Left_Tab:
12186 keyval = event->state & GDK_SHIFT_MASK ? GDK_Left : GDK_Right;
12193 row = tree_view->priv->edited_row;
12194 column = tree_view->priv->edited_column;
12195 path = gtk_tree_path_new_from_indices (row, -1);
12197 pspp_sheet_view_stop_editing (tree_view, cancel);
12198 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
12200 pspp_sheet_view_set_cursor (tree_view, path, column, FALSE);
12201 gtk_tree_path_free (path);
12203 handled = gtk_binding_set_activate (edit_bindings, keyval, state,
12204 GTK_OBJECT (tree_view));
12206 g_signal_stop_emission_by_name (widget, "event");
12208 pspp_sheet_view_get_cursor (tree_view, &path, NULL);
12209 pspp_sheet_view_start_editing (tree_view, path);
12210 gtk_tree_path_free (path);
12216 pspp_sheet_view_override_cell_keypresses (GtkWidget *widget,
12219 PsppSheetView *sheet_view = data;
12221 g_signal_connect (widget, "event",
12222 G_CALLBACK (pspp_sheet_view_event),
12225 if (GTK_IS_CONTAINER (widget))
12226 gtk_container_foreach (GTK_CONTAINER (widget),
12227 pspp_sheet_view_override_cell_keypresses,
12232 pspp_sheet_view_real_start_editing (PsppSheetView *tree_view,
12233 PsppSheetViewColumn *column,
12235 GtkCellEditable *cell_editable,
12236 GdkRectangle *cell_area,
12240 PsppSheetSelectionMode mode = pspp_sheet_selection_get_mode (tree_view->priv->selection);
12241 gint pre_val = tree_view->priv->vadjustment->value;
12242 GtkRequisition requisition;
12245 g_return_if_fail (gtk_tree_path_get_depth (path) == 1);
12247 tree_view->priv->edited_column = column;
12248 _pspp_sheet_view_column_start_editing (column, GTK_CELL_EDITABLE (cell_editable));
12250 row = gtk_tree_path_get_indices (path)[0];
12251 tree_view->priv->edited_row = row;
12252 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE);
12253 cell_area->y += pre_val - (int)tree_view->priv->vadjustment->value;
12255 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
12256 pspp_sheet_selection_select_column (tree_view->priv->selection, column);
12257 tree_view->priv->anchor_column = column;
12259 gtk_widget_size_request (GTK_WIDGET (cell_editable), &requisition);
12261 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
12263 if (requisition.height < cell_area->height)
12265 gint diff = cell_area->height - requisition.height;
12266 pspp_sheet_view_put (tree_view,
12267 GTK_WIDGET (cell_editable),
12268 cell_area->x, cell_area->y + diff/2,
12269 cell_area->width, requisition.height);
12273 pspp_sheet_view_put (tree_view,
12274 GTK_WIDGET (cell_editable),
12275 cell_area->x, cell_area->y,
12276 cell_area->width, cell_area->height);
12279 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (cell_editable),
12280 (GdkEvent *)event);
12282 gtk_widget_grab_focus (GTK_WIDGET (cell_editable));
12283 g_signal_connect (cell_editable, "remove-widget",
12284 G_CALLBACK (pspp_sheet_view_remove_widget), tree_view);
12285 if (mode == PSPP_SHEET_SELECTION_RECTANGLE && column->row_head &&
12286 GTK_IS_BUTTON (cell_editable))
12288 g_signal_connect (cell_editable, "button-press-event",
12289 G_CALLBACK (pspp_sheet_view_editable_button_press_event),
12291 g_object_set_data (G_OBJECT (cell_editable), "pspp-sheet-view-node",
12292 GINT_TO_POINTER (row));
12293 g_signal_connect (cell_editable, "clicked",
12294 G_CALLBACK (pspp_sheet_view_editable_clicked),
12298 pspp_sheet_view_override_cell_keypresses (GTK_WIDGET (cell_editable),
12303 pspp_sheet_view_stop_editing (PsppSheetView *tree_view,
12304 gboolean cancel_editing)
12306 PsppSheetViewColumn *column;
12307 GtkCellRenderer *cell;
12309 if (tree_view->priv->edited_column == NULL)
12313 * This is very evil. We need to do this, because
12314 * gtk_cell_editable_editing_done may trigger pspp_sheet_view_row_changed
12315 * later on. If pspp_sheet_view_row_changed notices
12316 * tree_view->priv->edited_column != NULL, it'll call
12317 * pspp_sheet_view_stop_editing again. Bad things will happen then.
12319 * Please read that again if you intend to modify anything here.
12322 column = tree_view->priv->edited_column;
12323 tree_view->priv->edited_column = NULL;
12325 cell = _pspp_sheet_view_column_get_edited_cell (column);
12326 gtk_cell_renderer_stop_editing (cell, cancel_editing);
12328 if (!cancel_editing)
12329 gtk_cell_editable_editing_done (column->editable_widget);
12331 tree_view->priv->edited_column = column;
12333 gtk_cell_editable_remove_widget (column->editable_widget);
12338 * pspp_sheet_view_set_hover_selection:
12339 * @tree_view: a #PsppSheetView
12340 * @hover: %TRUE to enable hover selection mode
12342 * Enables of disables the hover selection mode of @tree_view.
12343 * Hover selection makes the selected row follow the pointer.
12344 * Currently, this works only for the selection modes
12345 * %PSPP_SHEET_SELECTION_SINGLE and %PSPP_SHEET_SELECTION_BROWSE.
12350 pspp_sheet_view_set_hover_selection (PsppSheetView *tree_view,
12353 hover = hover != FALSE;
12355 if (hover != tree_view->priv->hover_selection)
12357 tree_view->priv->hover_selection = hover;
12359 g_object_notify (G_OBJECT (tree_view), "hover-selection");
12364 * pspp_sheet_view_get_hover_selection:
12365 * @tree_view: a #PsppSheetView
12367 * Returns whether hover selection mode is turned on for @tree_view.
12369 * Return value: %TRUE if @tree_view is in hover selection mode
12374 pspp_sheet_view_get_hover_selection (PsppSheetView *tree_view)
12376 return tree_view->priv->hover_selection;
12380 * pspp_sheet_view_set_rubber_banding:
12381 * @tree_view: a #PsppSheetView
12382 * @enable: %TRUE to enable rubber banding
12384 * Enables or disables rubber banding in @tree_view. If the selection mode is
12385 * #PSPP_SHEET_SELECTION_MULTIPLE or #PSPP_SHEET_SELECTION_RECTANGLE, rubber
12386 * banding will allow the user to select multiple rows by dragging the mouse.
12391 pspp_sheet_view_set_rubber_banding (PsppSheetView *tree_view,
12394 enable = enable != FALSE;
12396 if (enable != tree_view->priv->rubber_banding_enable)
12398 tree_view->priv->rubber_banding_enable = enable;
12400 g_object_notify (G_OBJECT (tree_view), "rubber-banding");
12405 * pspp_sheet_view_get_rubber_banding:
12406 * @tree_view: a #PsppSheetView
12408 * Returns whether rubber banding is turned on for @tree_view. If the
12409 * selection mode is #PSPP_SHEET_SELECTION_MULTIPLE or
12410 * #PSPP_SHEET_SELECTION_RECTANGLE, rubber banding will allow the user to
12411 * select multiple rows by dragging the mouse.
12413 * Return value: %TRUE if rubber banding in @tree_view is enabled.
12418 pspp_sheet_view_get_rubber_banding (PsppSheetView *tree_view)
12420 return tree_view->priv->rubber_banding_enable;
12424 * pspp_sheet_view_is_rubber_banding_active:
12425 * @tree_view: a #PsppSheetView
12427 * Returns whether a rubber banding operation is currently being done
12430 * Return value: %TRUE if a rubber banding operation is currently being
12431 * done in @tree_view.
12436 pspp_sheet_view_is_rubber_banding_active (PsppSheetView *tree_view)
12438 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
12440 if (tree_view->priv->rubber_banding_enable
12441 && tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
12448 pspp_sheet_view_grab_notify (GtkWidget *widget,
12449 gboolean was_grabbed)
12451 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12453 tree_view->priv->in_grab = !was_grabbed;
12457 tree_view->priv->pressed_button = -1;
12459 if (tree_view->priv->rubber_band_status)
12460 pspp_sheet_view_stop_rubber_band (tree_view);
12465 pspp_sheet_view_state_changed (GtkWidget *widget,
12466 GtkStateType previous_state)
12468 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12470 if (gtk_widget_get_realized (widget))
12472 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
12473 gdk_window_set_background (tree_view->priv->bin_window, &widget->style->base[widget->state]);
12476 gtk_widget_queue_draw (widget);
12480 * pspp_sheet_view_get_grid_lines:
12481 * @tree_view: a #PsppSheetView
12483 * Returns which grid lines are enabled in @tree_view.
12485 * Return value: a #PsppSheetViewGridLines value indicating which grid lines
12490 PsppSheetViewGridLines
12491 pspp_sheet_view_get_grid_lines (PsppSheetView *tree_view)
12493 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12495 return tree_view->priv->grid_lines;
12499 * pspp_sheet_view_set_grid_lines:
12500 * @tree_view: a #PsppSheetView
12501 * @grid_lines: a #PsppSheetViewGridLines value indicating which grid lines to
12504 * Sets which grid lines to draw in @tree_view.
12509 pspp_sheet_view_set_grid_lines (PsppSheetView *tree_view,
12510 PsppSheetViewGridLines grid_lines)
12512 PsppSheetViewPrivate *priv;
12513 PsppSheetViewGridLines old_grid_lines;
12515 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12517 priv = tree_view->priv;
12519 old_grid_lines = priv->grid_lines;
12520 priv->grid_lines = grid_lines;
12522 if (old_grid_lines != grid_lines)
12524 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12526 g_object_notify (G_OBJECT (tree_view), "enable-grid-lines");
12531 * pspp_sheet_view_get_special_cells:
12532 * @tree_view: a #PsppSheetView
12534 * Returns which grid lines are enabled in @tree_view.
12536 * Return value: a #PsppSheetViewSpecialCells value indicating whether rows in
12537 * the sheet view contain special cells.
12539 PsppSheetViewSpecialCells
12540 pspp_sheet_view_get_special_cells (PsppSheetView *tree_view)
12542 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12544 return tree_view->priv->special_cells;
12548 * pspp_sheet_view_set_special_cells:
12549 * @tree_view: a #PsppSheetView
12550 * @special_cells: a #PsppSheetViewSpecialCells value indicating whether rows in
12551 * the sheet view contain special cells.
12553 * Sets whether rows in the sheet view contain special cells, controlling the
12554 * rendering of row selections.
12557 pspp_sheet_view_set_special_cells (PsppSheetView *tree_view,
12558 PsppSheetViewSpecialCells special_cells)
12560 PsppSheetViewPrivate *priv;
12562 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12564 priv = tree_view->priv;
12566 if (priv->special_cells != special_cells)
12568 priv->special_cells = special_cells;
12569 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12570 g_object_notify (G_OBJECT (tree_view), "special-cells");
12575 pspp_sheet_view_get_fixed_height (const PsppSheetView *tree_view)
12577 /* XXX (re)calculate fixed_height if necessary */
12578 return tree_view->priv->fixed_height;
12582 pspp_sheet_view_set_fixed_height (PsppSheetView *tree_view,
12585 g_return_if_fail (fixed_height > 0);
12587 if (tree_view->priv->fixed_height != fixed_height)
12589 tree_view->priv->fixed_height = fixed_height;
12590 g_object_notify (G_OBJECT (tree_view), "fixed-height");
12592 if (!tree_view->priv->fixed_height_set)
12594 tree_view->priv->fixed_height_set = TRUE;
12595 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
12600 * pspp_sheet_view_set_tooltip_row:
12601 * @tree_view: a #PsppSheetView
12602 * @tooltip: a #GtkTooltip
12603 * @path: a #GtkTreePath
12605 * Sets the tip area of @tooltip to be the area covered by the row at @path.
12606 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
12607 * See also gtk_tooltip_set_tip_area().
12612 pspp_sheet_view_set_tooltip_row (PsppSheetView *tree_view,
12613 GtkTooltip *tooltip,
12616 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12617 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
12619 pspp_sheet_view_set_tooltip_cell (tree_view, tooltip, path, NULL, NULL);
12623 * pspp_sheet_view_set_tooltip_cell:
12624 * @tree_view: a #PsppSheetView
12625 * @tooltip: a #GtkTooltip
12626 * @path: (allow-none): a #GtkTreePath or %NULL
12627 * @column: (allow-none): a #PsppSheetViewColumn or %NULL
12628 * @cell: (allow-none): a #GtkCellRenderer or %NULL
12630 * Sets the tip area of @tooltip to the area @path, @column and @cell have
12631 * in common. For example if @path is %NULL and @column is set, the tip
12632 * area will be set to the full area covered by @column. See also
12633 * gtk_tooltip_set_tip_area().
12635 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
12640 pspp_sheet_view_set_tooltip_cell (PsppSheetView *tree_view,
12641 GtkTooltip *tooltip,
12643 PsppSheetViewColumn *column,
12644 GtkCellRenderer *cell)
12648 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12649 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
12650 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
12651 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
12653 /* Determine x values. */
12654 if (column && cell)
12659 pspp_sheet_view_get_cell_area (tree_view, path, column, &tmp);
12660 pspp_sheet_view_column_cell_get_position (column, cell, &start, &width);
12662 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12665 rect.width = width;
12671 pspp_sheet_view_get_background_area (tree_view, NULL, column, &tmp);
12672 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12675 rect.width = tmp.width;
12680 rect.width = GTK_WIDGET (tree_view)->allocation.width;
12683 /* Determine y values. */
12688 pspp_sheet_view_get_background_area (tree_view, path, NULL, &tmp);
12689 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12692 rect.height = tmp.height;
12697 rect.height = tree_view->priv->vadjustment->page_size;
12700 gtk_tooltip_set_tip_area (tooltip, &rect);
12704 * pspp_sheet_view_get_tooltip_context:
12705 * @tree_view: a #PsppSheetView
12706 * @x: the x coordinate (relative to widget coordinates)
12707 * @y: the y coordinate (relative to widget coordinates)
12708 * @keyboard_tip: whether this is a keyboard tooltip or not
12709 * @model: (allow-none): a pointer to receive a #GtkTreeModel or %NULL
12710 * @path: (allow-none): a pointer to receive a #GtkTreePath or %NULL
12711 * @iter: (allow-none): a pointer to receive a #GtkTreeIter or %NULL
12713 * This function is supposed to be used in a #GtkWidget::query-tooltip
12714 * signal handler for #PsppSheetView. The @x, @y and @keyboard_tip values
12715 * which are received in the signal handler, should be passed to this
12716 * function without modification.
12718 * The return value indicates whether there is a tree view row at the given
12719 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
12720 * tooltips the row returned will be the cursor row. When %TRUE, then any of
12721 * @model, @path and @iter which have been provided will be set to point to
12722 * that row and the corresponding model. @x and @y will always be converted
12723 * to be relative to @tree_view's bin_window if @keyboard_tooltip is %FALSE.
12725 * Return value: whether or not the given tooltip context points to a row.
12730 pspp_sheet_view_get_tooltip_context (PsppSheetView *tree_view,
12733 gboolean keyboard_tip,
12734 GtkTreeModel **model,
12735 GtkTreePath **path,
12738 GtkTreePath *tmppath = NULL;
12740 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
12741 g_return_val_if_fail (x != NULL, FALSE);
12742 g_return_val_if_fail (y != NULL, FALSE);
12746 pspp_sheet_view_get_cursor (tree_view, &tmppath, NULL);
12753 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, *x, *y,
12756 if (!pspp_sheet_view_get_path_at_pos (tree_view, *x, *y,
12757 &tmppath, NULL, NULL, NULL))
12762 *model = pspp_sheet_view_get_model (tree_view);
12765 gtk_tree_model_get_iter (pspp_sheet_view_get_model (tree_view),
12771 gtk_tree_path_free (tmppath);
12777 pspp_sheet_view_set_tooltip_query_cb (GtkWidget *widget,
12780 gboolean keyboard_tip,
12781 GtkTooltip *tooltip,
12784 GValue value = { 0, };
12785 GValue transformed = { 0, };
12788 GtkTreeModel *model;
12789 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12791 if (!pspp_sheet_view_get_tooltip_context (PSPP_SHEET_VIEW (widget),
12794 &model, &path, &iter))
12797 gtk_tree_model_get_value (model, &iter,
12798 tree_view->priv->tooltip_column, &value);
12800 g_value_init (&transformed, G_TYPE_STRING);
12802 if (!g_value_transform (&value, &transformed))
12804 g_value_unset (&value);
12805 gtk_tree_path_free (path);
12810 g_value_unset (&value);
12812 if (!g_value_get_string (&transformed))
12814 g_value_unset (&transformed);
12815 gtk_tree_path_free (path);
12820 gtk_tooltip_set_markup (tooltip, g_value_get_string (&transformed));
12821 pspp_sheet_view_set_tooltip_row (tree_view, tooltip, path);
12823 gtk_tree_path_free (path);
12824 g_value_unset (&transformed);
12830 * pspp_sheet_view_set_tooltip_column:
12831 * @tree_view: a #PsppSheetView
12832 * @column: an integer, which is a valid column number for @tree_view's model
12834 * If you only plan to have simple (text-only) tooltips on full rows, you
12835 * can use this function to have #PsppSheetView handle these automatically
12836 * for you. @column should be set to the column in @tree_view's model
12837 * containing the tooltip texts, or -1 to disable this feature.
12839 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
12840 * @tree_view will connect a #GtkWidget::query-tooltip signal handler.
12842 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
12843 * so &, <, etc have to be escaped in the text.
12848 pspp_sheet_view_set_tooltip_column (PsppSheetView *tree_view,
12851 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12853 if (column == tree_view->priv->tooltip_column)
12858 g_signal_handlers_disconnect_by_func (tree_view,
12859 pspp_sheet_view_set_tooltip_query_cb,
12861 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), FALSE);
12865 if (tree_view->priv->tooltip_column == -1)
12867 g_signal_connect (tree_view, "query-tooltip",
12868 G_CALLBACK (pspp_sheet_view_set_tooltip_query_cb), NULL);
12869 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), TRUE);
12873 tree_view->priv->tooltip_column = column;
12874 g_object_notify (G_OBJECT (tree_view), "tooltip-column");
12878 * pspp_sheet_view_get_tooltip_column:
12879 * @tree_view: a #PsppSheetView
12881 * Returns the column of @tree_view's model which is being used for
12882 * displaying tooltips on @tree_view's rows.
12884 * Return value: the index of the tooltip column that is currently being
12885 * used, or -1 if this is disabled.
12890 pspp_sheet_view_get_tooltip_column (PsppSheetView *tree_view)
12892 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12894 return tree_view->priv->tooltip_column;
12898 _gtk_boolean_handled_accumulator (GSignalInvocationHint *ihint,
12899 GValue *return_accu,
12900 const GValue *handler_return,
12903 gboolean continue_emission;
12904 gboolean signal_handled;
12906 signal_handled = g_value_get_boolean (handler_return);
12907 g_value_set_boolean (return_accu, signal_handled);
12908 continue_emission = !signal_handled;
12910 return continue_emission;
12914 pspp_sheet_view_grid_lines_get_type (void)
12916 static GType etype = 0;
12917 if (G_UNLIKELY(etype == 0)) {
12918 static const GEnumValue values[] = {
12919 { PSPP_SHEET_VIEW_GRID_LINES_NONE, "PSPP_SHEET_VIEW_GRID_LINES_NONE", "none" },
12920 { PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL, "PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL", "horizontal" },
12921 { PSPP_SHEET_VIEW_GRID_LINES_VERTICAL, "PSPP_SHEET_VIEW_GRID_LINES_VERTICAL", "vertical" },
12922 { PSPP_SHEET_VIEW_GRID_LINES_BOTH, "PSPP_SHEET_VIEW_GRID_LINES_BOTH", "both" },
12925 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewGridLines"), values);
12931 pspp_sheet_view_special_cells_get_type (void)
12933 static GType etype = 0;
12934 if (G_UNLIKELY(etype == 0)) {
12935 static const GEnumValue values[] = {
12936 { PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT, "PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT", "detect" },
12937 { PSPP_SHEET_VIEW_SPECIAL_CELLS_YES, "PSPP_SHEET_VIEW_SPECIAL_CELLS_YES", "yes" },
12938 { PSPP_SHEET_VIEW_SPECIAL_CELLS_NO, "PSPP_SHEET_VIEW_SPECIAL_CELLS_NO", "no" },
12941 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewSpecialCells"), values);