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);
1271 pspp_sheet_view_stop_editing (tree_view, TRUE);
1273 if (tree_view->priv->selected != NULL)
1275 range_tower_destroy (tree_view->priv->selected);
1276 tree_view->priv->selected = NULL;
1280 tree_view->priv->prelight_node = -1;
1283 if (tree_view->priv->scroll_to_path != NULL)
1285 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
1286 tree_view->priv->scroll_to_path = NULL;
1289 if (tree_view->priv->drag_dest_row != NULL)
1291 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
1292 tree_view->priv->drag_dest_row = NULL;
1295 if (tree_view->priv->top_row != NULL)
1297 gtk_tree_row_reference_free (tree_view->priv->top_row);
1298 tree_view->priv->top_row = NULL;
1301 if (tree_view->priv->column_drop_func_data &&
1302 tree_view->priv->column_drop_func_data_destroy)
1304 tree_view->priv->column_drop_func_data_destroy (tree_view->priv->column_drop_func_data);
1305 tree_view->priv->column_drop_func_data = NULL;
1308 if (tree_view->priv->destroy_count_destroy &&
1309 tree_view->priv->destroy_count_data)
1311 tree_view->priv->destroy_count_destroy (tree_view->priv->destroy_count_data);
1312 tree_view->priv->destroy_count_data = NULL;
1315 gtk_tree_row_reference_free (tree_view->priv->cursor);
1316 tree_view->priv->cursor = NULL;
1318 gtk_tree_row_reference_free (tree_view->priv->anchor);
1319 tree_view->priv->anchor = NULL;
1321 /* destroy interactive search dialog */
1322 if (tree_view->priv->search_window)
1324 gtk_widget_destroy (tree_view->priv->search_window);
1325 tree_view->priv->search_window = NULL;
1326 tree_view->priv->search_entry = NULL;
1327 if (tree_view->priv->typeselect_flush_timeout)
1329 g_source_remove (tree_view->priv->typeselect_flush_timeout);
1330 tree_view->priv->typeselect_flush_timeout = 0;
1334 if (tree_view->priv->search_destroy && tree_view->priv->search_user_data)
1336 tree_view->priv->search_destroy (tree_view->priv->search_user_data);
1337 tree_view->priv->search_user_data = NULL;
1340 if (tree_view->priv->search_position_destroy && tree_view->priv->search_position_user_data)
1342 tree_view->priv->search_position_destroy (tree_view->priv->search_position_user_data);
1343 tree_view->priv->search_position_user_data = NULL;
1346 pspp_sheet_view_set_model (tree_view, NULL);
1349 G_OBJECT_CLASS (pspp_sheet_view_parent_class)->finalize (object);
1354 /* GtkWidget Methods
1357 /* GtkWidget::map helper */
1359 pspp_sheet_view_map_buttons (PsppSheetView *tree_view)
1363 g_return_if_fail (gtk_widget_get_mapped (GTK_WIDGET (tree_view)));
1365 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
1367 PsppSheetViewColumn *column;
1369 for (list = tree_view->priv->columns; list; list = list->next)
1371 column = list->data;
1372 if (column->button != NULL &&
1373 gtk_widget_get_visible (column->button) &&
1374 !gtk_widget_get_mapped (column->button))
1375 gtk_widget_map (column->button);
1377 for (list = tree_view->priv->columns; list; list = list->next)
1379 column = list->data;
1380 if (column->visible == FALSE || column->window == NULL)
1382 if (column->resizable)
1384 gdk_window_raise (column->window);
1385 gdk_window_show (column->window);
1388 gdk_window_hide (column->window);
1390 gdk_window_show (tree_view->priv->header_window);
1395 pspp_sheet_view_map (GtkWidget *widget)
1397 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1400 gtk_widget_set_mapped (widget, TRUE);
1402 tmp_list = tree_view->priv->children;
1405 PsppSheetViewChild *child = tmp_list->data;
1406 tmp_list = tmp_list->next;
1408 if (gtk_widget_get_visible (child->widget))
1410 if (!gtk_widget_get_mapped (child->widget))
1411 gtk_widget_map (child->widget);
1414 gdk_window_show (tree_view->priv->bin_window);
1416 pspp_sheet_view_map_buttons (tree_view);
1418 gdk_window_show (widget->window);
1422 pspp_sheet_view_realize (GtkWidget *widget)
1425 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1427 GdkWindowAttr attributes;
1428 gint attributes_mask;
1430 gtk_widget_set_realized (widget, TRUE);
1432 /* Make the main, clipping window */
1433 attributes.window_type = GDK_WINDOW_CHILD;
1434 attributes.x = widget->allocation.x;
1435 attributes.y = widget->allocation.y;
1436 attributes.width = widget->allocation.width;
1437 attributes.height = widget->allocation.height;
1438 attributes.wclass = GDK_INPUT_OUTPUT;
1439 attributes.visual = gtk_widget_get_visual (widget);
1440 attributes.colormap = gtk_widget_get_colormap (widget);
1441 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK;
1443 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1445 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
1446 &attributes, attributes_mask);
1447 gdk_window_set_user_data (widget->window, widget);
1449 /* Make the window for the tree */
1451 attributes.y = TREE_VIEW_HEADER_HEIGHT (tree_view);
1452 attributes.width = MAX (tree_view->priv->width, widget->allocation.width);
1453 attributes.height = widget->allocation.height;
1454 attributes.event_mask = (GDK_EXPOSURE_MASK |
1456 GDK_POINTER_MOTION_MASK |
1457 GDK_ENTER_NOTIFY_MASK |
1458 GDK_LEAVE_NOTIFY_MASK |
1459 GDK_BUTTON_PRESS_MASK |
1460 GDK_BUTTON_RELEASE_MASK |
1461 gtk_widget_get_events (widget));
1463 tree_view->priv->bin_window = gdk_window_new (widget->window,
1464 &attributes, attributes_mask);
1465 gdk_window_set_user_data (tree_view->priv->bin_window, widget);
1467 /* Make the column header window */
1470 attributes.width = MAX (tree_view->priv->width, widget->allocation.width);
1471 attributes.height = tree_view->priv->header_height;
1472 attributes.event_mask = (GDK_EXPOSURE_MASK |
1474 GDK_BUTTON_PRESS_MASK |
1475 GDK_BUTTON_RELEASE_MASK |
1476 GDK_KEY_PRESS_MASK |
1477 GDK_KEY_RELEASE_MASK |
1478 gtk_widget_get_events (widget));
1480 tree_view->priv->header_window = gdk_window_new (widget->window,
1481 &attributes, attributes_mask);
1482 gdk_window_set_user_data (tree_view->priv->header_window, widget);
1484 /* Add them all up. */
1485 widget->style = gtk_style_attach (widget->style, widget->window);
1486 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
1487 gdk_window_set_background (tree_view->priv->bin_window, &widget->style->base[widget->state]);
1488 gtk_style_set_background (widget->style, tree_view->priv->header_window, GTK_STATE_NORMAL);
1490 tmp_list = tree_view->priv->children;
1493 PsppSheetViewChild *child = tmp_list->data;
1494 tmp_list = tmp_list->next;
1496 gtk_widget_set_parent_window (child->widget, tree_view->priv->bin_window);
1499 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
1500 _pspp_sheet_view_column_realize_button (PSPP_SHEET_VIEW_COLUMN (tmp_list->data));
1502 /* Need to call those here, since they create GCs */
1503 pspp_sheet_view_set_grid_lines (tree_view, tree_view->priv->grid_lines);
1505 install_presize_handler (tree_view);
1507 for (i = 0; i < 5; ++i)
1509 tree_view->priv->grid_line_gc[i] = gdk_gc_new (widget->window);
1510 gdk_gc_copy (tree_view->priv->grid_line_gc[i], widget->style->text_aa_gc[i]);
1515 pspp_sheet_view_unrealize (GtkWidget *widget)
1518 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1519 PsppSheetViewPrivate *priv = tree_view->priv;
1522 if (priv->scroll_timeout != 0)
1524 g_source_remove (priv->scroll_timeout);
1525 priv->scroll_timeout = 0;
1528 if (priv->open_dest_timeout != 0)
1530 g_source_remove (priv->open_dest_timeout);
1531 priv->open_dest_timeout = 0;
1534 if (priv->presize_handler_timer != 0)
1536 g_source_remove (priv->presize_handler_timer);
1537 priv->presize_handler_timer = 0;
1540 if (priv->validate_rows_timer != 0)
1542 g_source_remove (priv->validate_rows_timer);
1543 priv->validate_rows_timer = 0;
1546 if (priv->scroll_sync_timer != 0)
1548 g_source_remove (priv->scroll_sync_timer);
1549 priv->scroll_sync_timer = 0;
1552 if (priv->typeselect_flush_timeout)
1554 g_source_remove (priv->typeselect_flush_timeout);
1555 priv->typeselect_flush_timeout = 0;
1558 for (list = priv->columns; list; list = list->next)
1559 _pspp_sheet_view_column_unrealize_button (PSPP_SHEET_VIEW_COLUMN (list->data));
1561 gdk_window_set_user_data (priv->bin_window, NULL);
1562 gdk_window_destroy (priv->bin_window);
1563 priv->bin_window = NULL;
1565 gdk_window_set_user_data (priv->header_window, NULL);
1566 gdk_window_destroy (priv->header_window);
1567 priv->header_window = NULL;
1569 if (priv->drag_window)
1571 gdk_window_set_user_data (priv->drag_window, NULL);
1572 gdk_window_destroy (priv->drag_window);
1573 priv->drag_window = NULL;
1576 if (priv->drag_highlight_window)
1578 gdk_window_set_user_data (priv->drag_highlight_window, NULL);
1579 gdk_window_destroy (priv->drag_highlight_window);
1580 priv->drag_highlight_window = NULL;
1583 for (x = 0 ; x < 5 ; ++x)
1584 g_object_unref (priv->grid_line_gc[x]);
1586 if (tree_view->priv->columns != NULL)
1588 list = tree_view->priv->columns;
1591 PsppSheetViewColumn *column;
1592 column = PSPP_SHEET_VIEW_COLUMN (list->data);
1594 pspp_sheet_view_remove_column (tree_view, column);
1596 tree_view->priv->columns = NULL;
1599 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->unrealize (widget);
1602 /* GtkWidget::size_request helper */
1604 pspp_sheet_view_size_request_columns (PsppSheetView *tree_view)
1608 tree_view->priv->header_height = 0;
1610 if (tree_view->priv->model)
1612 for (list = tree_view->priv->columns; list; list = list->next)
1614 GtkRequisition requisition;
1615 PsppSheetViewColumn *column = list->data;
1617 pspp_sheet_view_column_size_request (column, &requisition);
1618 column->button_request = requisition.width;
1619 tree_view->priv->header_height = MAX (tree_view->priv->header_height, requisition.height);
1625 /* Called only by ::size_request */
1627 pspp_sheet_view_update_size (PsppSheetView *tree_view)
1630 PsppSheetViewColumn *column;
1633 if (tree_view->priv->model == NULL)
1635 tree_view->priv->width = 0;
1636 tree_view->priv->prev_width = 0;
1637 tree_view->priv->height = 0;
1641 tree_view->priv->prev_width = tree_view->priv->width;
1642 tree_view->priv->width = 0;
1644 /* keep this in sync with size_allocate below */
1645 for (list = tree_view->priv->columns, i = 0; list; list = list->next, i++)
1647 gint real_requested_width = 0;
1648 column = list->data;
1649 if (!column->visible)
1652 if (column->use_resized_width)
1654 real_requested_width = column->resized_width;
1658 real_requested_width = column->fixed_width;
1661 if (column->min_width != -1)
1662 real_requested_width = MAX (real_requested_width, column->min_width);
1663 if (column->max_width != -1)
1664 real_requested_width = MIN (real_requested_width, column->max_width);
1666 tree_view->priv->width += real_requested_width;
1669 tree_view->priv->height = tree_view->priv->fixed_height * tree_view->priv->row_count;
1673 pspp_sheet_view_size_request (GtkWidget *widget,
1674 GtkRequisition *requisition)
1676 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1679 /* we validate some rows initially just to make sure we have some size.
1680 * In practice, with a lot of static lists, this should get a good width.
1682 initialize_fixed_height_mode (tree_view);
1683 pspp_sheet_view_size_request_columns (tree_view);
1684 pspp_sheet_view_update_size (PSPP_SHEET_VIEW (widget));
1686 requisition->width = tree_view->priv->width;
1687 requisition->height = tree_view->priv->height + TREE_VIEW_HEADER_HEIGHT (tree_view);
1689 tmp_list = tree_view->priv->children;
1693 PsppSheetViewChild *child = tmp_list->data;
1694 GtkRequisition child_requisition;
1696 tmp_list = tmp_list->next;
1698 if (gtk_widget_get_visible (child->widget))
1699 gtk_widget_size_request (child->widget, &child_requisition);
1704 invalidate_column (PsppSheetView *tree_view,
1705 PsppSheetViewColumn *column)
1707 gint column_offset = 0;
1709 GtkWidget *widget = GTK_WIDGET (tree_view);
1712 if (!gtk_widget_get_realized (widget))
1715 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
1716 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
1718 list = (rtl ? list->prev : list->next))
1720 PsppSheetViewColumn *tmpcolumn = list->data;
1721 if (tmpcolumn == column)
1723 GdkRectangle invalid_rect;
1725 invalid_rect.x = column_offset;
1727 invalid_rect.width = column->width;
1728 invalid_rect.height = widget->allocation.height;
1730 gdk_window_invalidate_rect (widget->window, &invalid_rect, TRUE);
1734 column_offset += tmpcolumn->width;
1739 invalidate_last_column (PsppSheetView *tree_view)
1744 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
1746 for (last_column = (rtl ? g_list_first (tree_view->priv->columns) : g_list_last (tree_view->priv->columns));
1748 last_column = (rtl ? last_column->next : last_column->prev))
1750 if (PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible)
1752 invalidate_column (tree_view, last_column->data);
1759 pspp_sheet_view_get_real_requested_width_from_column (PsppSheetView *tree_view,
1760 PsppSheetViewColumn *column)
1762 gint real_requested_width;
1764 if (column->use_resized_width)
1766 real_requested_width = column->resized_width;
1770 real_requested_width = column->fixed_width;
1773 if (column->min_width != -1)
1774 real_requested_width = MAX (real_requested_width, column->min_width);
1775 if (column->max_width != -1)
1776 real_requested_width = MIN (real_requested_width, column->max_width);
1778 return real_requested_width;
1782 span_intersects (int a0, int a_width,
1783 int b0, int b_width)
1785 int a1 = a0 + a_width;
1786 int b1 = b0 + b_width;
1787 return (a0 >= b0 && a0 < b1) || (b0 >= a0 && b0 < a1);
1790 /* GtkWidget::size_allocate helper */
1792 pspp_sheet_view_size_allocate_columns (GtkWidget *widget,
1793 gboolean *width_changed)
1795 PsppSheetView *tree_view;
1796 GList *list, *first_column, *last_column;
1797 PsppSheetViewColumn *column;
1798 GtkAllocation allocation;
1800 gint extra, extra_per_column;
1801 gint full_requested_width = 0;
1802 gint number_of_expand_columns = 0;
1803 gboolean column_changed = FALSE;
1806 tree_view = PSPP_SHEET_VIEW (widget);
1808 for (last_column = g_list_last (tree_view->priv->columns);
1809 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
1810 last_column = last_column->prev)
1812 if (last_column == NULL)
1815 for (first_column = g_list_first (tree_view->priv->columns);
1816 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
1817 first_column = first_column->next)
1821 allocation.height = tree_view->priv->header_height;
1823 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
1825 /* find out how many extra space and expandable columns we have */
1826 for (list = tree_view->priv->columns; list != last_column->next; list = list->next)
1828 column = (PsppSheetViewColumn *)list->data;
1830 if (!column->visible)
1833 full_requested_width += pspp_sheet_view_get_real_requested_width_from_column (tree_view, column);
1836 number_of_expand_columns++;
1839 extra = MAX (widget->allocation.width - full_requested_width, 0);
1840 if (number_of_expand_columns > 0)
1841 extra_per_column = extra/number_of_expand_columns;
1843 extra_per_column = 0;
1845 for (list = (rtl ? last_column : first_column);
1846 list != (rtl ? first_column->prev : last_column->next);
1847 list = (rtl ? list->prev : list->next))
1849 gint real_requested_width = 0;
1852 column = list->data;
1853 old_width = column->width;
1855 if (!column->visible)
1858 /* We need to handle the dragged button specially.
1860 if (column == tree_view->priv->drag_column)
1862 GtkAllocation drag_allocation;
1863 gdk_drawable_get_size (tree_view->priv->drag_window,
1864 &(drag_allocation.width),
1865 &(drag_allocation.height));
1866 drag_allocation.x = 0;
1867 drag_allocation.y = 0;
1868 pspp_sheet_view_column_size_allocate (tree_view->priv->drag_column,
1870 width += drag_allocation.width;
1874 real_requested_width = pspp_sheet_view_get_real_requested_width_from_column (tree_view, column);
1876 allocation.x = width;
1877 column->width = real_requested_width;
1881 if (number_of_expand_columns == 1)
1883 /* We add the remander to the last column as
1885 column->width += extra;
1889 column->width += extra_per_column;
1890 extra -= extra_per_column;
1891 number_of_expand_columns --;
1895 if (column->width != old_width)
1896 g_object_notify (G_OBJECT (column), "width");
1898 allocation.width = column->width;
1899 width += column->width;
1901 if (column->width > old_width)
1902 column_changed = TRUE;
1904 pspp_sheet_view_column_size_allocate (column, &allocation);
1906 if (span_intersects (allocation.x, allocation.width,
1907 tree_view->priv->hadjustment->value,
1908 widget->allocation.width)
1909 && gtk_widget_get_realized (widget))
1910 pspp_sheet_view_column_set_need_button (column, TRUE);
1913 gdk_window_move_resize (column->window,
1914 allocation.x + (rtl ? 0 : allocation.width) - TREE_VIEW_DRAG_WIDTH/2,
1916 TREE_VIEW_DRAG_WIDTH, allocation.height);
1919 /* We change the width here. The user might have been resizing columns,
1920 * so the total width of the tree view changes.
1922 tree_view->priv->width = width;
1924 *width_changed = TRUE;
1927 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
1932 pspp_sheet_view_size_allocate (GtkWidget *widget,
1933 GtkAllocation *allocation)
1935 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
1937 gboolean width_changed = FALSE;
1938 gint old_width = widget->allocation.width;
1940 if (allocation->width != widget->allocation.width)
1941 width_changed = TRUE;
1943 widget->allocation = *allocation;
1945 tmp_list = tree_view->priv->children;
1949 GtkAllocation allocation;
1951 PsppSheetViewChild *child = tmp_list->data;
1952 tmp_list = tmp_list->next;
1954 /* totally ignore our child's requisition */
1955 allocation.x = child->x;
1956 allocation.y = child->y;
1957 allocation.width = child->width;
1958 allocation.height = child->height;
1959 gtk_widget_size_allocate (child->widget, &allocation);
1962 /* We size-allocate the columns first because the width of the
1963 * tree view (used in updating the adjustments below) might change.
1965 pspp_sheet_view_size_allocate_columns (widget, &width_changed);
1967 tree_view->priv->hadjustment->page_size = allocation->width;
1968 tree_view->priv->hadjustment->page_increment = allocation->width * 0.9;
1969 tree_view->priv->hadjustment->step_increment = allocation->width * 0.1;
1970 tree_view->priv->hadjustment->lower = 0;
1971 tree_view->priv->hadjustment->upper = MAX (tree_view->priv->hadjustment->page_size, tree_view->priv->width);
1973 if (gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL)
1975 if (allocation->width < tree_view->priv->width)
1977 if (tree_view->priv->init_hadjust_value)
1979 tree_view->priv->hadjustment->value = MAX (tree_view->priv->width - allocation->width, 0);
1980 tree_view->priv->init_hadjust_value = FALSE;
1982 else if (allocation->width != old_width)
1984 tree_view->priv->hadjustment->value = CLAMP (tree_view->priv->hadjustment->value - allocation->width + old_width, 0, tree_view->priv->width - allocation->width);
1987 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);
1991 tree_view->priv->hadjustment->value = 0;
1992 tree_view->priv->init_hadjust_value = TRUE;
1996 if (tree_view->priv->hadjustment->value + allocation->width > tree_view->priv->width)
1997 tree_view->priv->hadjustment->value = MAX (tree_view->priv->width - allocation->width, 0);
1999 gtk_adjustment_changed (tree_view->priv->hadjustment);
2001 tree_view->priv->vadjustment->page_size = allocation->height - TREE_VIEW_HEADER_HEIGHT (tree_view);
2002 tree_view->priv->vadjustment->step_increment = tree_view->priv->vadjustment->page_size * 0.1;
2003 tree_view->priv->vadjustment->page_increment = tree_view->priv->vadjustment->page_size * 0.9;
2004 tree_view->priv->vadjustment->lower = 0;
2005 tree_view->priv->vadjustment->upper = MAX (tree_view->priv->vadjustment->page_size, tree_view->priv->height);
2007 gtk_adjustment_changed (tree_view->priv->vadjustment);
2009 /* now the adjustments and window sizes are in sync, we can sync toprow/dy again */
2010 if (tree_view->priv->height <= tree_view->priv->vadjustment->page_size)
2011 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment), 0);
2012 else if (tree_view->priv->vadjustment->value + tree_view->priv->vadjustment->page_size > tree_view->priv->height)
2013 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment),
2014 tree_view->priv->height - tree_view->priv->vadjustment->page_size);
2015 else if (gtk_tree_row_reference_valid (tree_view->priv->top_row))
2016 pspp_sheet_view_top_row_to_dy (tree_view);
2018 pspp_sheet_view_dy_to_top_row (tree_view);
2020 if (gtk_widget_get_realized (widget))
2022 gdk_window_move_resize (widget->window,
2023 allocation->x, allocation->y,
2024 allocation->width, allocation->height);
2025 gdk_window_move_resize (tree_view->priv->header_window,
2026 - (gint) tree_view->priv->hadjustment->value,
2028 MAX (tree_view->priv->width, allocation->width),
2029 tree_view->priv->header_height);
2030 gdk_window_move_resize (tree_view->priv->bin_window,
2031 - (gint) tree_view->priv->hadjustment->value,
2032 TREE_VIEW_HEADER_HEIGHT (tree_view),
2033 MAX (tree_view->priv->width, allocation->width),
2034 allocation->height - TREE_VIEW_HEADER_HEIGHT (tree_view));
2037 if (tree_view->priv->row_count == 0)
2038 invalidate_empty_focus (tree_view);
2040 if (gtk_widget_get_realized (widget))
2042 gboolean has_expand_column = FALSE;
2043 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
2045 if (pspp_sheet_view_column_get_expand (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)))
2047 has_expand_column = TRUE;
2052 /* This little hack only works if we have an LTR locale, and no column has the */
2055 if (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_LTR &&
2056 ! has_expand_column)
2057 invalidate_last_column (tree_view);
2059 gtk_widget_queue_draw (widget);
2064 /* Grabs the focus and unsets the PSPP_SHEET_VIEW_DRAW_KEYFOCUS flag */
2066 grab_focus_and_unset_draw_keyfocus (PsppSheetView *tree_view)
2068 GtkWidget *widget = GTK_WIDGET (tree_view);
2070 if (gtk_widget_get_can_focus (widget) && !gtk_widget_has_focus (widget))
2071 gtk_widget_grab_focus (widget);
2072 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
2076 pspp_sheet_view_node_is_selected (PsppSheetView *tree_view,
2079 return node >= 0 && range_tower_contains (tree_view->priv->selected, node);
2083 pspp_sheet_view_node_select (PsppSheetView *tree_view,
2086 range_tower_set1 (tree_view->priv->selected, node, 1);
2090 pspp_sheet_view_node_unselect (PsppSheetView *tree_view,
2093 range_tower_set0 (tree_view->priv->selected, node, 1);
2097 pspp_sheet_view_node_next (PsppSheetView *tree_view,
2100 return node + 1 < tree_view->priv->row_count ? node + 1 : -1;
2104 pspp_sheet_view_node_prev (PsppSheetView *tree_view,
2107 return node > 0 ? node - 1 : -1;
2111 all_columns_selected (PsppSheetView *tree_view)
2115 for (list = tree_view->priv->columns; list; list = list->next)
2117 PsppSheetViewColumn *column = list->data;
2118 if (column->selectable && !column->selected)
2126 pspp_sheet_view_row_head_clicked (PsppSheetView *tree_view,
2128 PsppSheetViewColumn *column,
2129 GdkEventButton *event)
2131 PsppSheetSelection *selection;
2132 PsppSheetSelectionMode mode;
2134 gboolean update_anchor;
2138 g_return_val_if_fail (tree_view != NULL, FALSE);
2139 g_return_val_if_fail (column != NULL, FALSE);
2141 selection = tree_view->priv->selection;
2142 mode = pspp_sheet_selection_get_mode (selection);
2143 if (mode != PSPP_SHEET_SELECTION_RECTANGLE)
2146 if (!column->row_head)
2151 modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
2152 if (event->type != GDK_BUTTON_PRESS
2153 || (modifiers != GDK_CONTROL_MASK && modifiers != GDK_SHIFT_MASK))
2159 path = gtk_tree_path_new_from_indices (node, -1);
2162 pspp_sheet_selection_unselect_all (selection);
2163 pspp_sheet_selection_select_path (selection, path);
2164 pspp_sheet_selection_select_all_columns (selection);
2165 update_anchor = TRUE;
2168 else if (event->type == GDK_BUTTON_PRESS && event->button == 3)
2170 if (pspp_sheet_selection_count_selected_rows (selection) <= 1
2171 || !all_columns_selected (tree_view))
2173 pspp_sheet_selection_unselect_all (selection);
2174 pspp_sheet_selection_select_path (selection, path);
2175 pspp_sheet_selection_select_all_columns (selection);
2176 update_anchor = TRUE;
2180 update_anchor = handled = FALSE;
2182 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
2183 && modifiers == GDK_CONTROL_MASK)
2185 if (!all_columns_selected (tree_view))
2187 pspp_sheet_selection_unselect_all (selection);
2188 pspp_sheet_selection_select_all_columns (selection);
2191 if (pspp_sheet_selection_path_is_selected (selection, path))
2192 pspp_sheet_selection_unselect_path (selection, path);
2194 pspp_sheet_selection_select_path (selection, path);
2195 update_anchor = TRUE;
2198 else if (event->type == GDK_BUTTON_PRESS && event->button == 1
2199 && modifiers == GDK_SHIFT_MASK)
2201 GtkTreeRowReference *anchor = tree_view->priv->anchor;
2202 GtkTreePath *anchor_path;
2204 if (all_columns_selected (tree_view)
2205 && gtk_tree_row_reference_valid (anchor))
2207 update_anchor = FALSE;
2208 anchor_path = gtk_tree_row_reference_get_path (anchor);
2212 update_anchor = TRUE;
2213 anchor_path = gtk_tree_path_copy (path);
2216 pspp_sheet_selection_unselect_all (selection);
2217 pspp_sheet_selection_select_range (selection, anchor_path, path);
2218 pspp_sheet_selection_select_all_columns (selection);
2220 gtk_tree_path_free (anchor_path);
2225 update_anchor = handled = FALSE;
2229 if (tree_view->priv->anchor)
2230 gtk_tree_row_reference_free (tree_view->priv->anchor);
2231 tree_view->priv->anchor =
2232 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
2233 tree_view->priv->model,
2237 gtk_tree_path_free (path);
2242 find_click (PsppSheetView *tree_view,
2245 PsppSheetViewColumn **column,
2246 GdkRectangle *background_area,
2247 GdkRectangle *cell_area)
2254 /* find the node that was clicked */
2255 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, y);
2258 y_offset = -pspp_sheet_view_find_offset (tree_view, new_y, node);
2263 background_area->y = y_offset + y;
2264 background_area->height = ROW_HEIGHT (tree_view);
2265 background_area->x = 0;
2267 /* Let the column have a chance at selecting it. */
2268 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
2269 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
2270 list; list = (rtl ? list->prev : list->next))
2272 PsppSheetViewColumn *candidate = list->data;
2274 if (!candidate->visible)
2277 background_area->width = candidate->width;
2278 if ((background_area->x > x) ||
2279 (background_area->x + background_area->width <= x))
2281 background_area->x += background_area->width;
2285 /* we found the focus column */
2287 pspp_sheet_view_adjust_cell_area (tree_view, candidate, background_area,
2289 *column = candidate;
2297 pspp_sheet_view_button_press (GtkWidget *widget,
2298 GdkEventButton *event)
2300 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
2302 PsppSheetViewColumn *column = NULL;
2304 GdkRectangle background_area;
2305 GdkRectangle cell_area;
2308 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
2309 pspp_sheet_view_stop_editing (tree_view, FALSE);
2312 /* Because grab_focus can cause reentrancy, we delay grab_focus until after
2313 * we're done handling the button press.
2316 if (event->window == tree_view->priv->bin_window)
2321 gint pre_val, aft_val;
2322 PsppSheetViewColumn *column = NULL;
2323 GtkCellRenderer *focus_cell = NULL;
2324 gboolean row_double_click = FALSE;
2325 gboolean node_selected;
2328 if (tree_view->priv->row_count == 0)
2330 grab_focus_and_unset_draw_keyfocus (tree_view);
2334 if (!find_click (tree_view, event->x, event->y, &node, &column,
2335 &background_area, &cell_area))
2337 grab_focus_and_unset_draw_keyfocus (tree_view);
2341 tree_view->priv->focus_column = column;
2343 if (pspp_sheet_view_row_head_clicked (tree_view, node, column, event))
2347 node_selected = pspp_sheet_view_node_is_selected (tree_view, node);
2348 pre_val = tree_view->priv->vadjustment->value;
2350 path = _pspp_sheet_view_find_path (tree_view, node);
2352 /* we only handle selection modifications on the first button press
2354 if (event->type == GDK_BUTTON_PRESS)
2356 if ((event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
2357 tree_view->priv->ctrl_pressed = TRUE;
2358 if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
2359 tree_view->priv->shift_pressed = TRUE;
2361 focus_cell = _pspp_sheet_view_column_get_cell_at_pos (column, event->x - background_area.x);
2363 pspp_sheet_view_column_focus_cell (column, focus_cell);
2365 if (event->state & GDK_CONTROL_MASK)
2367 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE);
2368 pspp_sheet_view_real_toggle_cursor_row (tree_view);
2370 else if (event->state & GDK_SHIFT_MASK)
2372 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE);
2373 pspp_sheet_view_real_select_cursor_row (tree_view, FALSE);
2377 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE);
2380 if (tree_view->priv->anchor_column == NULL ||
2381 !(event->state & GDK_SHIFT_MASK))
2382 tree_view->priv->anchor_column = column;
2383 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
2384 pspp_sheet_selection_select_column_range (tree_view->priv->selection,
2385 tree_view->priv->anchor_column,
2388 tree_view->priv->ctrl_pressed = FALSE;
2389 tree_view->priv->shift_pressed = FALSE;
2392 /* the treeview may have been scrolled because of _set_cursor,
2396 aft_val = tree_view->priv->vadjustment->value;
2397 dval = pre_val - aft_val;
2399 cell_area.y += dval;
2400 background_area.y += dval;
2402 /* Save press to possibly begin a drag
2404 if (!tree_view->priv->in_grab &&
2405 tree_view->priv->pressed_button < 0)
2407 tree_view->priv->pressed_button = event->button;
2408 tree_view->priv->press_start_x = event->x;
2409 tree_view->priv->press_start_y = event->y;
2410 tree_view->priv->press_start_node = node;
2412 if (tree_view->priv->rubber_banding_enable
2414 && (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
2415 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE))
2417 tree_view->priv->press_start_y += tree_view->priv->dy;
2418 tree_view->priv->rubber_band_x = event->x;
2419 tree_view->priv->rubber_band_y = event->y + tree_view->priv->dy;
2420 tree_view->priv->rubber_band_status = RUBBER_BAND_MAYBE_START;
2422 if ((event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
2423 tree_view->priv->rubber_band_ctrl = TRUE;
2424 if ((event->state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
2425 tree_view->priv->rubber_band_shift = TRUE;
2430 /* Test if a double click happened on the same row. */
2431 if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
2433 int double_click_time, double_click_distance;
2435 g_object_get (gtk_settings_get_for_screen (
2436 gtk_widget_get_screen (widget)),
2437 "gtk-double-click-time", &double_click_time,
2438 "gtk-double-click-distance", &double_click_distance,
2441 /* Same conditions as _gdk_event_button_generate */
2442 if (tree_view->priv->last_button_x != -1 &&
2443 (event->time < tree_view->priv->last_button_time + double_click_time) &&
2444 (ABS (event->x - tree_view->priv->last_button_x) <= double_click_distance) &&
2445 (ABS (event->y - tree_view->priv->last_button_y) <= double_click_distance))
2447 /* We do no longer compare paths of this row and the
2448 * row clicked previously. We use the double click
2449 * distance to decide whether this is a valid click,
2450 * allowing the mouse to slightly move over another row.
2452 row_double_click = TRUE;
2454 tree_view->priv->last_button_time = 0;
2455 tree_view->priv->last_button_x = -1;
2456 tree_view->priv->last_button_y = -1;
2460 tree_view->priv->last_button_time = event->time;
2461 tree_view->priv->last_button_x = event->x;
2462 tree_view->priv->last_button_y = event->y;
2466 if (row_double_click)
2468 gtk_grab_remove (widget);
2469 pspp_sheet_view_row_activated (tree_view, path, column);
2471 if (tree_view->priv->pressed_button == event->button)
2472 tree_view->priv->pressed_button = -1;
2475 gtk_tree_path_free (path);
2477 /* If we activated the row through a double click we don't want to grab
2478 * focus back, as moving focus to another widget is pretty common.
2480 if (!row_double_click)
2481 grab_focus_and_unset_draw_keyfocus (tree_view);
2486 /* We didn't click in the window. Let's check to see if we clicked on a column resize window.
2488 for (i = 0, list = tree_view->priv->columns; list; list = list->next, i++)
2490 column = list->data;
2491 if (event->window == column->window &&
2492 column->resizable &&
2497 if (gdk_pointer_grab (column->window, FALSE,
2498 GDK_POINTER_MOTION_HINT_MASK |
2499 GDK_BUTTON1_MOTION_MASK |
2500 GDK_BUTTON_RELEASE_MASK,
2501 NULL, NULL, event->time))
2504 gtk_grab_add (widget);
2505 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE);
2506 column->resized_width = column->width;
2508 /* block attached dnd signal handler */
2509 drag_data = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
2511 g_signal_handlers_block_matched (widget,
2512 G_SIGNAL_MATCH_DATA,
2516 tree_view->priv->drag_pos = i;
2517 tree_view->priv->x_drag = column->allocation.x + (rtl ? 0 : column->allocation.width);
2519 if (!gtk_widget_has_focus (widget))
2520 gtk_widget_grab_focus (widget);
2528 /* GtkWidget::button_release_event helper */
2530 pspp_sheet_view_button_release_drag_column (GtkWidget *widget,
2531 GdkEventButton *event)
2533 PsppSheetView *tree_view;
2537 tree_view = PSPP_SHEET_VIEW (widget);
2539 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
2540 gdk_display_pointer_ungrab (gtk_widget_get_display (widget), GDK_CURRENT_TIME);
2541 gdk_display_keyboard_ungrab (gtk_widget_get_display (widget), GDK_CURRENT_TIME);
2543 /* Move the button back */
2544 g_return_val_if_fail (tree_view->priv->drag_column->button, FALSE);
2546 g_object_ref (tree_view->priv->drag_column->button);
2547 gtk_container_remove (GTK_CONTAINER (tree_view), tree_view->priv->drag_column->button);
2548 gtk_widget_set_parent_window (tree_view->priv->drag_column->button, tree_view->priv->header_window);
2549 gtk_widget_set_parent (tree_view->priv->drag_column->button, GTK_WIDGET (tree_view));
2550 g_object_unref (tree_view->priv->drag_column->button);
2551 gtk_widget_queue_resize (widget);
2552 if (tree_view->priv->drag_column->resizable)
2554 gdk_window_raise (tree_view->priv->drag_column->window);
2555 gdk_window_show (tree_view->priv->drag_column->window);
2558 gdk_window_hide (tree_view->priv->drag_column->window);
2560 gtk_widget_grab_focus (tree_view->priv->drag_column->button);
2564 if (tree_view->priv->cur_reorder &&
2565 tree_view->priv->cur_reorder->right_column != tree_view->priv->drag_column)
2566 pspp_sheet_view_move_column_after (tree_view, tree_view->priv->drag_column,
2567 tree_view->priv->cur_reorder->right_column);
2571 if (tree_view->priv->cur_reorder &&
2572 tree_view->priv->cur_reorder->left_column != tree_view->priv->drag_column)
2573 pspp_sheet_view_move_column_after (tree_view, tree_view->priv->drag_column,
2574 tree_view->priv->cur_reorder->left_column);
2576 tree_view->priv->drag_column = NULL;
2577 gdk_window_hide (tree_view->priv->drag_window);
2579 for (l = tree_view->priv->column_drag_info; l != NULL; l = l->next)
2580 g_slice_free (PsppSheetViewColumnReorder, l->data);
2581 g_list_free (tree_view->priv->column_drag_info);
2582 tree_view->priv->column_drag_info = NULL;
2583 tree_view->priv->cur_reorder = NULL;
2585 if (tree_view->priv->drag_highlight_window)
2586 gdk_window_hide (tree_view->priv->drag_highlight_window);
2588 /* Reset our flags */
2589 tree_view->priv->drag_column_window_state = DRAG_COLUMN_WINDOW_STATE_UNSET;
2590 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG);
2595 /* GtkWidget::button_release_event helper */
2597 pspp_sheet_view_button_release_column_resize (GtkWidget *widget,
2598 GdkEventButton *event)
2600 PsppSheetView *tree_view;
2603 tree_view = PSPP_SHEET_VIEW (widget);
2605 tree_view->priv->drag_pos = -1;
2607 /* unblock attached dnd signal handler */
2608 drag_data = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
2610 g_signal_handlers_unblock_matched (widget,
2611 G_SIGNAL_MATCH_DATA,
2615 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_RESIZE);
2616 gtk_grab_remove (widget);
2617 gdk_display_pointer_ungrab (gdk_drawable_get_display (event->window),
2623 pspp_sheet_view_button_release_edit (PsppSheetView *tree_view,
2624 GdkEventButton *event)
2626 GtkCellEditable *cell_editable;
2631 PsppSheetViewColumn *column;
2632 GdkRectangle background_area;
2633 GdkRectangle cell_area;
2639 if (event->window != tree_view->priv->bin_window)
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;
3776 GdkRectangle background_area;
3777 GdkRectangle cell_area;
3779 gint bin_window_width;
3780 gint bin_window_height;
3781 GtkTreePath *cursor_path;
3782 GtkTreePath *drag_dest_path;
3783 GList *first_column, *last_column;
3784 gint vertical_separator;
3785 gint horizontal_separator;
3786 gint focus_line_width;
3787 gboolean allow_rules;
3788 gboolean has_special_cell;
3790 gint n_visible_columns;
3791 gint grid_line_width;
3792 gboolean row_ending_details;
3793 gboolean draw_vgrid_lines, draw_hgrid_lines;
3796 rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
3798 gtk_widget_style_get (widget,
3799 "horizontal-separator", &horizontal_separator,
3800 "vertical-separator", &vertical_separator,
3801 "allow-rules", &allow_rules,
3802 "focus-line-width", &focus_line_width,
3803 "row-ending-details", &row_ending_details,
3806 if (tree_view->priv->row_count == 0)
3808 draw_empty_focus (tree_view, &event->area);
3812 /* clip event->area to the visible area */
3813 if (event->area.height < 0)
3816 validate_visible_area (tree_view);
3818 new_y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, event->area.y);
3822 y_offset = -pspp_sheet_view_find_offset (tree_view, new_y, &node);
3823 gdk_drawable_get_size (tree_view->priv->bin_window,
3824 &bin_window_width, &bin_window_height);
3826 if (tree_view->priv->height < bin_window_height)
3828 gtk_paint_flat_box (widget->style,
3835 0, tree_view->priv->height,
3837 bin_window_height - tree_view->priv->height);
3843 /* find the path for the node */
3844 path = _pspp_sheet_view_find_path ((PsppSheetView *)widget, node);
3845 gtk_tree_model_get_iter (tree_view->priv->model,
3848 depth = gtk_tree_path_get_depth (path);
3849 gtk_tree_path_free (path);
3852 drag_dest_path = NULL;
3854 if (tree_view->priv->cursor)
3855 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
3858 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor);
3860 if (tree_view->priv->drag_dest_row)
3861 drag_dest_path = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
3864 _pspp_sheet_view_find_node (tree_view, drag_dest_path,
3868 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
3869 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
3871 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
3872 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
3874 if (draw_vgrid_lines || draw_hgrid_lines)
3875 gtk_widget_style_get (widget, "grid-line-width", &grid_line_width, NULL);
3877 n_visible_columns = 0;
3878 for (list = tree_view->priv->columns; list; list = list->next)
3880 if (! PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
3882 n_visible_columns ++;
3885 /* Find the last column */
3886 for (last_column = g_list_last (tree_view->priv->columns);
3887 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
3888 last_column = last_column->prev)
3892 for (first_column = g_list_first (tree_view->priv->columns);
3893 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
3894 first_column = first_column->next)
3897 /* Actually process the expose event. To do this, we want to
3898 * start at the first node of the event, and walk the tree in
3899 * order, drawing each successive node.
3906 gboolean is_first = FALSE;
3907 gboolean is_last = FALSE;
3908 gboolean done = FALSE;
3911 max_height = ROW_HEIGHT (tree_view);
3915 background_area.y = y_offset + event->area.y;
3916 background_area.height = max_height;
3917 max_y = background_area.y + max_height;
3921 if (node == tree_view->priv->prelight_node)
3922 flags |= GTK_CELL_RENDERER_PRELIT;
3924 selected = pspp_sheet_view_node_is_selected (tree_view, node);
3928 if (tree_view->priv->special_cells == PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT)
3930 /* we *need* to set cell data on all cells before the call
3931 * to _has_special_cell, else _has_special_cell() does not
3932 * return a correct value.
3934 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
3936 list = (rtl ? list->prev : list->next))
3938 PsppSheetViewColumn *column = list->data;
3939 pspp_sheet_view_column_cell_set_cell_data (column,
3940 tree_view->priv->model,
3944 has_special_cell = pspp_sheet_view_has_special_cell (tree_view);
3947 has_special_cell = tree_view->priv->special_cells == PSPP_SHEET_VIEW_SPECIAL_CELLS_YES;
3949 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
3951 list = (rtl ? list->prev : list->next))
3953 PsppSheetViewColumn *column = list->data;
3954 const gchar *detail = NULL;
3955 gboolean selected_column;
3958 if (!column->visible)
3961 if (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE)
3962 selected_column = column->selected && column->selectable;
3964 selected_column = TRUE;
3966 if (cell_offset > event->area.x + event->area.width ||
3967 cell_offset + column->width < event->area.x)
3969 cell_offset += column->width;
3973 if (selected && selected_column)
3974 flags |= GTK_CELL_RENDERER_SELECTED;
3976 flags &= ~GTK_CELL_RENDERER_SELECTED;
3978 if (column->show_sort_indicator)
3979 flags |= GTK_CELL_RENDERER_SORTED;
3981 flags &= ~GTK_CELL_RENDERER_SORTED;
3984 flags |= GTK_CELL_RENDERER_FOCUSED;
3986 flags &= ~GTK_CELL_RENDERER_FOCUSED;
3988 background_area.x = cell_offset;
3989 background_area.width = column->width;
3991 cell_area = background_area;
3992 cell_area.y += vertical_separator / 2;
3993 cell_area.x += horizontal_separator / 2;
3994 cell_area.height -= vertical_separator;
3995 cell_area.width -= horizontal_separator;
3997 if (draw_vgrid_lines)
3999 if (list == first_column)
4001 cell_area.width -= grid_line_width / 2;
4003 else if (list == last_column)
4005 cell_area.x += grid_line_width / 2;
4006 cell_area.width -= grid_line_width / 2;
4010 cell_area.x += grid_line_width / 2;
4011 cell_area.width -= grid_line_width;
4015 if (draw_hgrid_lines)
4017 cell_area.y += grid_line_width / 2;
4018 cell_area.height -= grid_line_width;
4021 if (gdk_region_rect_in (event->region, &background_area) == GDK_OVERLAP_RECTANGLE_OUT)
4023 cell_offset += column->width;
4027 pspp_sheet_view_column_cell_set_cell_data (column,
4028 tree_view->priv->model,
4031 /* Select the detail for drawing the cell. relevant
4032 * factors are parity, sortedness, and whether to
4035 if (allow_rules && tree_view->priv->has_rules)
4037 if ((flags & GTK_CELL_RENDERER_SORTED) &&
4038 n_visible_columns >= 3)
4041 detail = "cell_odd_ruled_sorted";
4043 detail = "cell_even_ruled_sorted";
4048 detail = "cell_odd_ruled";
4050 detail = "cell_even_ruled";
4055 if ((flags & GTK_CELL_RENDERER_SORTED) &&
4056 n_visible_columns >= 3)
4059 detail = "cell_odd_sorted";
4061 detail = "cell_even_sorted";
4066 detail = "cell_odd";
4068 detail = "cell_even";
4074 if (widget->state == GTK_STATE_INSENSITIVE)
4075 state = GTK_STATE_INSENSITIVE;
4076 else if (flags & GTK_CELL_RENDERER_SELECTED)
4077 state = GTK_STATE_SELECTED;
4079 state = GTK_STATE_NORMAL;
4081 /* Draw background */
4082 if (row_ending_details)
4084 char new_detail[128];
4086 is_first = (rtl ? !list->next : !list->prev);
4087 is_last = (rtl ? !list->prev : !list->next);
4089 /* (I don't like the snprintfs either, but couldn't find a
4092 if (is_first && is_last)
4093 g_snprintf (new_detail, 127, "%s", detail);
4095 g_snprintf (new_detail, 127, "%s_start", detail);
4097 g_snprintf (new_detail, 127, "%s_end", detail);
4099 g_snprintf (new_detail, 128, "%s_middle", detail);
4101 gtk_paint_flat_box (widget->style,
4110 background_area.width,
4111 background_area.height);
4115 gtk_paint_flat_box (widget->style,
4124 background_area.width,
4125 background_area.height);
4128 if (draw_hgrid_lines)
4130 if (background_area.y > 0)
4131 gdk_draw_line (event->window,
4132 tree_view->priv->grid_line_gc[widget->state],
4133 background_area.x, background_area.y,
4134 background_area.x + background_area.width,
4137 if (y_offset + max_height >= event->area.height)
4138 gdk_draw_line (event->window,
4139 tree_view->priv->grid_line_gc[widget->state],
4140 background_area.x, background_area.y + max_height,
4141 background_area.x + background_area.width,
4142 background_area.y + max_height);
4145 _pspp_sheet_view_column_cell_render (column,
4152 if (node == cursor && has_special_cell &&
4153 ((column == tree_view->priv->focus_column &&
4154 PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS) &&
4155 gtk_widget_has_focus (widget)) ||
4156 (column == tree_view->priv->edited_column)))
4158 _pspp_sheet_view_column_cell_draw_focus (column,
4166 cell_offset += column->width;
4169 if (cell_offset < event->area.x)
4171 gtk_paint_flat_box (widget->style,
4180 event->area.x - cell_offset,
4181 background_area.height);
4184 if (node == drag_highlight)
4186 /* Draw indicator for the drop
4188 gint highlight_y = -1;
4192 switch (tree_view->priv->drag_dest_pos)
4194 case PSPP_SHEET_VIEW_DROP_BEFORE:
4195 highlight_y = background_area.y - 1;
4196 if (highlight_y < 0)
4200 case PSPP_SHEET_VIEW_DROP_AFTER:
4201 highlight_y = background_area.y + background_area.height - 1;
4204 case PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE:
4205 case PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER:
4206 _pspp_sheet_view_find_node (tree_view, drag_dest_path, &node);
4210 gdk_drawable_get_size (tree_view->priv->bin_window,
4213 if (row_ending_details)
4214 gtk_paint_focus (widget->style,
4215 tree_view->priv->bin_window,
4216 gtk_widget_get_state (widget),
4220 ? (is_last ? "treeview-drop-indicator" : "treeview-drop-indicator-left" )
4221 : (is_last ? "treeview-drop-indicator-right" : "tree-view-drop-indicator-middle" )),
4222 0, BACKGROUND_FIRST_PIXEL (tree_view, node)
4223 - focus_line_width / 2,
4224 width, ROW_HEIGHT (tree_view)
4225 - focus_line_width + 1);
4227 gtk_paint_focus (widget->style,
4228 tree_view->priv->bin_window,
4229 gtk_widget_get_state (widget),
4232 "treeview-drop-indicator",
4233 0, BACKGROUND_FIRST_PIXEL (tree_view, node)
4234 - focus_line_width / 2,
4235 width, ROW_HEIGHT (tree_view)
4236 - focus_line_width + 1);
4240 if (highlight_y >= 0)
4242 gdk_draw_line (event->window,
4243 widget->style->fg_gc[gtk_widget_get_state (widget)],
4246 rtl ? 0 : bin_window_width,
4251 /* draw the big row-spanning focus rectangle, if needed */
4252 if (!has_special_cell && node == cursor &&
4253 PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS) &&
4254 gtk_widget_has_focus (widget))
4256 gint tmp_y, tmp_height;
4258 GtkStateType focus_rect_state;
4261 flags & GTK_CELL_RENDERER_SELECTED ? GTK_STATE_SELECTED :
4262 (flags & GTK_CELL_RENDERER_PRELIT ? GTK_STATE_PRELIGHT :
4263 (flags & GTK_CELL_RENDERER_INSENSITIVE ? GTK_STATE_INSENSITIVE :
4266 gdk_drawable_get_size (tree_view->priv->bin_window,
4269 if (draw_hgrid_lines)
4271 tmp_y = BACKGROUND_FIRST_PIXEL (tree_view, node) + grid_line_width / 2;
4272 tmp_height = ROW_HEIGHT (tree_view) - grid_line_width;
4276 tmp_y = BACKGROUND_FIRST_PIXEL (tree_view, node);
4277 tmp_height = ROW_HEIGHT (tree_view);
4280 if (row_ending_details)
4281 gtk_paint_focus (widget->style,
4282 tree_view->priv->bin_window,
4287 ? (is_last ? "treeview" : "treeview-left" )
4288 : (is_last ? "treeview-right" : "treeview-middle" )),
4292 gtk_paint_focus (widget->style,
4293 tree_view->priv->bin_window,
4302 y_offset += max_height;
4306 node = pspp_sheet_view_node_next (tree_view, node);
4309 gboolean has_next = gtk_tree_model_iter_next (tree_view->priv->model, &iter);
4313 TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
4320 while (y_offset < event->area.height);
4323 pspp_sheet_view_draw_grid_lines (tree_view, event, n_visible_columns,
4326 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
4328 GdkRectangle *rectangles;
4331 gdk_region_get_rectangles (event->region,
4335 while (n_rectangles--)
4336 pspp_sheet_view_paint_rubber_band (tree_view, &rectangles[n_rectangles]);
4338 g_free (rectangles);
4342 gtk_tree_path_free (cursor_path);
4345 gtk_tree_path_free (drag_dest_path);
4351 pspp_sheet_view_expose (GtkWidget *widget,
4352 GdkEventExpose *event)
4354 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4356 if (event->window == tree_view->priv->bin_window)
4361 retval = pspp_sheet_view_bin_expose (widget, event);
4363 /* We can't just chain up to Container::expose as it will try to send the
4364 * event to the headers, so we handle propagating it to our children
4365 * (eg. widgets being edited) ourselves.
4367 tmp_list = tree_view->priv->children;
4370 PsppSheetViewChild *child = tmp_list->data;
4371 tmp_list = tmp_list->next;
4373 gtk_container_propagate_expose (GTK_CONTAINER (tree_view), child->widget, event);
4379 else if (event->window == tree_view->priv->header_window)
4381 gint n_visible_columns;
4384 gtk_paint_flat_box (widget->style,
4394 event->area.height);
4396 for (list = tree_view->priv->columns; list != NULL; list = list->next)
4398 PsppSheetViewColumn *column = list->data;
4400 if (column == tree_view->priv->drag_column || !column->visible)
4403 if (span_intersects (column->allocation.x, column->allocation.width,
4404 event->area.x, event->area.width)
4405 && column->button != NULL)
4406 gtk_container_propagate_expose (GTK_CONTAINER (tree_view),
4407 column->button, event);
4410 n_visible_columns = 0;
4411 for (list = tree_view->priv->columns; list; list = list->next)
4413 if (! PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
4415 n_visible_columns ++;
4417 pspp_sheet_view_draw_grid_lines (tree_view,
4421 event->area.height);
4423 else if (event->window == tree_view->priv->drag_window)
4425 gtk_container_propagate_expose (GTK_CONTAINER (tree_view),
4426 tree_view->priv->drag_column->button,
4440 /* returns 0x1 when no column has been found -- yes it's hackish */
4441 static PsppSheetViewColumn *
4442 pspp_sheet_view_get_drop_column (PsppSheetView *tree_view,
4443 PsppSheetViewColumn *column,
4446 PsppSheetViewColumn *left_column = NULL;
4447 PsppSheetViewColumn *cur_column = NULL;
4450 if (!column->reorderable)
4451 return (PsppSheetViewColumn *)0x1;
4453 switch (drop_position)
4456 /* find first column where we can drop */
4457 tmp_list = tree_view->priv->columns;
4458 if (column == PSPP_SHEET_VIEW_COLUMN (tmp_list->data))
4459 return (PsppSheetViewColumn *)0x1;
4463 g_assert (tmp_list);
4465 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4466 tmp_list = tmp_list->next;
4468 if (left_column && left_column->visible == FALSE)
4471 if (!tree_view->priv->column_drop_func)
4474 if (!tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4476 left_column = cur_column;
4483 if (!tree_view->priv->column_drop_func)
4486 if (tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data))
4489 return (PsppSheetViewColumn *)0x1;
4493 /* find first column after column where we can drop */
4494 tmp_list = tree_view->priv->columns;
4496 for (; tmp_list; tmp_list = tmp_list->next)
4497 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data) == column)
4500 if (!tmp_list || !tmp_list->next)
4501 return (PsppSheetViewColumn *)0x1;
4503 tmp_list = tmp_list->next;
4504 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4505 tmp_list = tmp_list->next;
4509 g_assert (tmp_list);
4511 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4512 tmp_list = tmp_list->next;
4514 if (left_column && left_column->visible == FALSE)
4516 left_column = cur_column;
4518 tmp_list = tmp_list->next;
4522 if (!tree_view->priv->column_drop_func)
4525 if (!tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4527 left_column = cur_column;
4534 if (!tree_view->priv->column_drop_func)
4537 if (tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data))
4540 return (PsppSheetViewColumn *)0x1;
4544 /* find first column before column where we can drop */
4545 tmp_list = tree_view->priv->columns;
4547 for (; tmp_list; tmp_list = tmp_list->next)
4548 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data) == column)
4551 if (!tmp_list || !tmp_list->prev)
4552 return (PsppSheetViewColumn *)0x1;
4554 tmp_list = tmp_list->prev;
4555 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4556 tmp_list = tmp_list->prev;
4560 g_assert (tmp_list);
4562 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4564 if (left_column && !left_column->visible)
4566 /*if (!tmp_list->prev)
4567 return (PsppSheetViewColumn *)0x1;
4570 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->prev->data);
4571 tmp_list = tmp_list->prev->prev;
4574 cur_column = left_column;
4576 tmp_list = tmp_list->prev;
4580 if (!tree_view->priv->column_drop_func)
4583 if (tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4586 cur_column = left_column;
4587 tmp_list = tmp_list->prev;
4590 if (!tree_view->priv->column_drop_func)
4593 if (tree_view->priv->column_drop_func (tree_view, column, NULL, cur_column, tree_view->priv->column_drop_func_data))
4596 return (PsppSheetViewColumn *)0x1;
4600 /* same as DROP_HOME case, but doing it backwards */
4601 tmp_list = g_list_last (tree_view->priv->columns);
4604 if (column == PSPP_SHEET_VIEW_COLUMN (tmp_list->data))
4605 return (PsppSheetViewColumn *)0x1;
4609 g_assert (tmp_list);
4611 left_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
4613 if (left_column && !left_column->visible)
4615 cur_column = left_column;
4616 tmp_list = tmp_list->prev;
4619 if (!tree_view->priv->column_drop_func)
4622 if (tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
4625 cur_column = left_column;
4626 tmp_list = tmp_list->prev;
4629 if (!tree_view->priv->column_drop_func)
4632 if (tree_view->priv->column_drop_func (tree_view, column, NULL, cur_column, tree_view->priv->column_drop_func_data))
4635 return (PsppSheetViewColumn *)0x1;
4639 return (PsppSheetViewColumn *)0x1;
4643 pspp_sheet_view_key_press (GtkWidget *widget,
4646 PsppSheetView *tree_view = (PsppSheetView *) widget;
4648 if (tree_view->priv->rubber_band_status)
4650 if (event->keyval == GDK_Escape)
4651 pspp_sheet_view_stop_rubber_band (tree_view);
4656 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG))
4658 if (event->keyval == GDK_Escape)
4660 tree_view->priv->cur_reorder = NULL;
4661 pspp_sheet_view_button_release_drag_column (widget, NULL);
4666 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
4668 GList *focus_column;
4671 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
4673 for (focus_column = tree_view->priv->columns;
4675 focus_column = focus_column->next)
4677 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4679 if (column->button && gtk_widget_has_focus (column->button))
4684 (event->state & GDK_SHIFT_MASK) && (event->state & GDK_MOD1_MASK) &&
4685 (event->keyval == GDK_Left || event->keyval == GDK_KP_Left
4686 || event->keyval == GDK_Right || event->keyval == GDK_KP_Right))
4688 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4690 if (!column->resizable)
4692 gtk_widget_error_bell (widget);
4696 if (event->keyval == (rtl ? GDK_Right : GDK_Left)
4697 || event->keyval == (rtl ? GDK_KP_Right : GDK_KP_Left))
4699 gint old_width = column->resized_width;
4701 column->resized_width = MAX (column->resized_width,
4703 column->resized_width -= 2;
4704 if (column->resized_width < 0)
4705 column->resized_width = 0;
4707 if (column->min_width == -1)
4708 column->resized_width = MAX (column->button_request,
4709 column->resized_width);
4711 column->resized_width = MAX (column->min_width,
4712 column->resized_width);
4714 if (column->max_width != -1)
4715 column->resized_width = MIN (column->resized_width,
4718 column->use_resized_width = TRUE;
4720 if (column->resized_width != old_width)
4721 gtk_widget_queue_resize (widget);
4723 gtk_widget_error_bell (widget);
4725 else if (event->keyval == (rtl ? GDK_Left : GDK_Right)
4726 || event->keyval == (rtl ? GDK_KP_Left : GDK_KP_Right))
4728 gint old_width = column->resized_width;
4730 column->resized_width = MAX (column->resized_width,
4732 column->resized_width += 2;
4734 if (column->max_width != -1)
4735 column->resized_width = MIN (column->resized_width,
4738 column->use_resized_width = TRUE;
4740 if (column->resized_width != old_width)
4741 gtk_widget_queue_resize (widget);
4743 gtk_widget_error_bell (widget);
4750 (event->state & GDK_MOD1_MASK) &&
4751 (event->keyval == GDK_Left || event->keyval == GDK_KP_Left
4752 || event->keyval == GDK_Right || event->keyval == GDK_KP_Right
4753 || event->keyval == GDK_Home || event->keyval == GDK_KP_Home
4754 || event->keyval == GDK_End || event->keyval == GDK_KP_End))
4756 PsppSheetViewColumn *column = PSPP_SHEET_VIEW_COLUMN (focus_column->data);
4758 if (event->keyval == (rtl ? GDK_Right : GDK_Left)
4759 || event->keyval == (rtl ? GDK_KP_Right : GDK_KP_Left))
4761 PsppSheetViewColumn *col;
4762 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_LEFT);
4763 if (col != (PsppSheetViewColumn *)0x1)
4764 pspp_sheet_view_move_column_after (tree_view, column, col);
4766 gtk_widget_error_bell (widget);
4768 else if (event->keyval == (rtl ? GDK_Left : GDK_Right)
4769 || event->keyval == (rtl ? GDK_KP_Left : GDK_KP_Right))
4771 PsppSheetViewColumn *col;
4772 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_RIGHT);
4773 if (col != (PsppSheetViewColumn *)0x1)
4774 pspp_sheet_view_move_column_after (tree_view, column, col);
4776 gtk_widget_error_bell (widget);
4778 else if (event->keyval == GDK_Home || event->keyval == GDK_KP_Home)
4780 PsppSheetViewColumn *col;
4781 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_HOME);
4782 if (col != (PsppSheetViewColumn *)0x1)
4783 pspp_sheet_view_move_column_after (tree_view, column, col);
4785 gtk_widget_error_bell (widget);
4787 else if (event->keyval == GDK_End || event->keyval == GDK_KP_End)
4789 PsppSheetViewColumn *col;
4790 col = pspp_sheet_view_get_drop_column (tree_view, column, DROP_END);
4791 if (col != (PsppSheetViewColumn *)0x1)
4792 pspp_sheet_view_move_column_after (tree_view, column, col);
4794 gtk_widget_error_bell (widget);
4801 /* Chain up to the parent class. It handles the keybindings. */
4802 if (GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->key_press_event (widget, event))
4805 if (tree_view->priv->search_entry_avoid_unhandled_binding)
4807 tree_view->priv->search_entry_avoid_unhandled_binding = FALSE;
4811 /* We pass the event to the search_entry. If its text changes, then we start
4812 * the typeahead find capabilities. */
4813 if (gtk_widget_has_focus (GTK_WIDGET (tree_view))
4814 && tree_view->priv->enable_search
4815 && !tree_view->priv->search_custom_entry_set)
4817 GdkEvent *new_event;
4819 const char *new_text;
4822 gboolean text_modified;
4823 gulong popup_menu_id;
4825 pspp_sheet_view_ensure_interactive_directory (tree_view);
4827 /* Make a copy of the current text */
4828 old_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry)));
4829 new_event = gdk_event_copy ((GdkEvent *) event);
4830 g_object_unref (((GdkEventKey *) new_event)->window);
4831 ((GdkEventKey *) new_event)->window = g_object_ref (tree_view->priv->search_window->window);
4832 gtk_widget_realize (tree_view->priv->search_window);
4834 popup_menu_id = g_signal_connect (tree_view->priv->search_entry,
4835 "popup-menu", G_CALLBACK (gtk_true),
4838 /* Move the entry off screen */
4839 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
4840 gtk_window_move (GTK_WINDOW (tree_view->priv->search_window),
4841 gdk_screen_get_width (screen) + 1,
4842 gdk_screen_get_height (screen) + 1);
4843 gtk_widget_show (tree_view->priv->search_window);
4845 /* Send the event to the window. If the preedit_changed signal is emitted
4846 * during this event, we will set priv->imcontext_changed */
4847 tree_view->priv->imcontext_changed = FALSE;
4848 retval = gtk_widget_event (tree_view->priv->search_window, new_event);
4849 gdk_event_free (new_event);
4850 gtk_widget_hide (tree_view->priv->search_window);
4852 g_signal_handler_disconnect (tree_view->priv->search_entry,
4855 /* We check to make sure that the entry tried to handle the text, and that
4856 * the text has changed.
4858 new_text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
4859 text_modified = strcmp (old_text, new_text) != 0;
4861 if (tree_view->priv->imcontext_changed || /* we're in a preedit */
4862 (retval && text_modified)) /* ...or the text was modified */
4864 if (pspp_sheet_view_real_start_interactive_search (tree_view, FALSE))
4866 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
4871 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
4881 pspp_sheet_view_key_release (GtkWidget *widget,
4884 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4886 if (tree_view->priv->rubber_band_status)
4889 return GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->key_release_event (widget, event);
4892 /* FIXME Is this function necessary? Can I get an enter_notify event
4893 * w/o either an expose event or a mouse motion event?
4896 pspp_sheet_view_enter_notify (GtkWidget *widget,
4897 GdkEventCrossing *event)
4899 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
4903 /* Sanity check it */
4904 if (event->window != tree_view->priv->bin_window)
4907 if (tree_view->priv->row_count == 0)
4910 if (event->mode == GDK_CROSSING_GRAB ||
4911 event->mode == GDK_CROSSING_GTK_GRAB ||
4912 event->mode == GDK_CROSSING_GTK_UNGRAB ||
4913 event->mode == GDK_CROSSING_STATE_CHANGED)
4916 /* find the node internally */
4917 new_y = TREE_WINDOW_Y_TO_RBTREE_Y(tree_view, event->y);
4920 pspp_sheet_view_find_offset (tree_view, new_y, &node);
4922 tree_view->priv->event_last_x = event->x;
4923 tree_view->priv->event_last_y = event->y;
4925 prelight_or_select (tree_view, node, event->x, event->y);
4931 pspp_sheet_view_leave_notify (GtkWidget *widget,
4932 GdkEventCrossing *event)
4934 PsppSheetView *tree_view;
4936 if (event->mode == GDK_CROSSING_GRAB)
4939 tree_view = PSPP_SHEET_VIEW (widget);
4941 if (tree_view->priv->prelight_node >= 0)
4942 _pspp_sheet_view_queue_draw_node (tree_view,
4943 tree_view->priv->prelight_node,
4946 tree_view->priv->event_last_x = -10000;
4947 tree_view->priv->event_last_y = -10000;
4949 prelight_or_select (tree_view,
4951 -1000, -1000); /* coords not possibly over an arrow */
4958 pspp_sheet_view_focus_out (GtkWidget *widget,
4959 GdkEventFocus *event)
4961 PsppSheetView *tree_view;
4963 tree_view = PSPP_SHEET_VIEW (widget);
4965 gtk_widget_queue_draw (widget);
4967 /* destroy interactive search dialog */
4968 if (tree_view->priv->search_window)
4969 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
4975 /* Incremental Reflow
4979 pspp_sheet_view_node_queue_redraw (PsppSheetView *tree_view,
4984 y = pspp_sheet_view_node_find_offset (tree_view, node)
4985 - tree_view->priv->vadjustment->value
4986 + TREE_VIEW_HEADER_HEIGHT (tree_view);
4988 gtk_widget_queue_draw_area (GTK_WIDGET (tree_view),
4990 GTK_WIDGET (tree_view)->allocation.width,
4991 tree_view->priv->fixed_height);
4995 node_is_visible (PsppSheetView *tree_view,
5001 y = pspp_sheet_view_node_find_offset (tree_view, node);
5002 height = ROW_HEIGHT (tree_view);
5004 if (y >= tree_view->priv->vadjustment->value &&
5005 y + height <= (tree_view->priv->vadjustment->value
5006 + tree_view->priv->vadjustment->page_size))
5012 /* Returns the row height. */
5014 validate_row (PsppSheetView *tree_view,
5019 PsppSheetViewColumn *column;
5020 GList *list, *first_column, *last_column;
5022 gint horizontal_separator;
5023 gint vertical_separator;
5024 gint focus_line_width;
5025 gboolean retval = FALSE;
5026 gboolean draw_vgrid_lines, draw_hgrid_lines;
5028 gint grid_line_width;
5029 gboolean wide_separators;
5030 gint separator_height;
5032 gtk_widget_style_get (GTK_WIDGET (tree_view),
5033 "focus-padding", &focus_pad,
5034 "focus-line-width", &focus_line_width,
5035 "horizontal-separator", &horizontal_separator,
5036 "vertical-separator", &vertical_separator,
5037 "grid-line-width", &grid_line_width,
5038 "wide-separators", &wide_separators,
5039 "separator-height", &separator_height,
5043 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
5044 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
5046 tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
5047 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH;
5049 for (last_column = g_list_last (tree_view->priv->columns);
5050 last_column && !(PSPP_SHEET_VIEW_COLUMN (last_column->data)->visible);
5051 last_column = last_column->prev)
5054 for (first_column = g_list_first (tree_view->priv->columns);
5055 first_column && !(PSPP_SHEET_VIEW_COLUMN (first_column->data)->visible);
5056 first_column = first_column->next)
5059 for (list = tree_view->priv->columns; list; list = list->next)
5064 column = list->data;
5066 if (! column->visible)
5069 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, iter);
5070 pspp_sheet_view_column_cell_get_size (column,
5072 &tmp_width, &tmp_height);
5074 tmp_height += vertical_separator;
5075 height = MAX (height, tmp_height);
5077 tmp_width = tmp_width + horizontal_separator;
5079 if (draw_vgrid_lines)
5081 if (list->data == first_column || list->data == last_column)
5082 tmp_width += grid_line_width / 2.0;
5084 tmp_width += grid_line_width;
5087 if (tmp_width > column->requested_width)
5090 column->requested_width = tmp_width;
5094 if (draw_hgrid_lines)
5095 height += grid_line_width;
5097 tree_view->priv->post_validation_flag = TRUE;
5103 validate_visible_area (PsppSheetView *tree_view)
5105 GtkTreePath *path = NULL;
5106 GtkTreePath *above_path = NULL;
5109 gboolean size_changed = FALSE;
5111 gint area_above = 0;
5112 gint area_below = 0;
5114 if (tree_view->priv->row_count == 0)
5117 if (tree_view->priv->scroll_to_path == NULL)
5120 total_height = GTK_WIDGET (tree_view)->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
5122 if (total_height == 0)
5125 path = gtk_tree_row_reference_get_path (tree_view->priv->scroll_to_path);
5128 /* we are going to scroll, and will update dy */
5129 _pspp_sheet_view_find_node (tree_view, path, &node);
5130 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
5132 if (tree_view->priv->scroll_to_use_align)
5134 gint height = ROW_HEIGHT (tree_view);
5135 area_above = (total_height - height) *
5136 tree_view->priv->scroll_to_row_align;
5137 area_below = total_height - area_above - height;
5138 area_above = MAX (area_above, 0);
5139 area_below = MAX (area_below, 0);
5144 * 1) row not visible
5148 gint height = ROW_HEIGHT (tree_view);
5150 dy = pspp_sheet_view_node_find_offset (tree_view, node);
5152 if (dy >= tree_view->priv->vadjustment->value &&
5153 dy + height <= (tree_view->priv->vadjustment->value
5154 + tree_view->priv->vadjustment->page_size))
5156 /* row visible: keep the row at the same position */
5157 area_above = dy - tree_view->priv->vadjustment->value;
5158 area_below = (tree_view->priv->vadjustment->value +
5159 tree_view->priv->vadjustment->page_size)
5164 /* row not visible */
5166 && dy + height <= tree_view->priv->vadjustment->page_size)
5168 /* row at the beginning -- fixed */
5170 area_below = tree_view->priv->vadjustment->page_size
5171 - area_above - height;
5173 else if (dy >= (tree_view->priv->vadjustment->upper -
5174 tree_view->priv->vadjustment->page_size))
5176 /* row at the end -- fixed */
5177 area_above = dy - (tree_view->priv->vadjustment->upper -
5178 tree_view->priv->vadjustment->page_size);
5179 area_below = tree_view->priv->vadjustment->page_size -
5180 area_above - height;
5184 area_above = tree_view->priv->vadjustment->page_size - height;
5190 /* row somewhere in the middle, bring it to the top
5194 area_below = total_height - height;
5200 /* the scroll to isn't valid; ignore it.
5203 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
5204 tree_view->priv->scroll_to_path = NULL;
5208 above_path = gtk_tree_path_copy (path);
5210 /* Now, we walk forwards and backwards, measuring rows. Unfortunately,
5211 * backwards is much slower then forward, as there is no iter_prev function.
5212 * We go forwards first in case we run out of tree. Then we go backwards to
5215 while (node >= 0 && area_below > 0)
5217 gboolean done = FALSE;
5220 node = pspp_sheet_view_node_next (tree_view, node);
5223 gboolean has_next = gtk_tree_model_iter_next (tree_view->priv->model, &iter);
5225 gtk_tree_path_next (path);
5228 TREE_VIEW_INTERNAL_ASSERT_VOID (has_next);
5238 area_below -= ROW_HEIGHT (tree_view);
5240 gtk_tree_path_free (path);
5242 /* If we ran out of tree, and have extra area_below left, we need to add it
5245 area_above += area_below;
5247 _pspp_sheet_view_find_node (tree_view, above_path, &node);
5249 /* We walk backwards */
5250 while (area_above > 0)
5252 node = pspp_sheet_view_node_prev (tree_view, node);
5254 /* Always find the new path in the tree. We cannot just assume
5255 * a gtk_tree_path_prev() is enough here, as there might be children
5256 * in between this node and the previous sibling node. If this
5257 * appears to be a performance hotspot in profiles, we can look into
5258 * intrigate logic for keeping path, node and iter in sync like
5259 * we do for forward walks. (Which will be hard because of the lacking
5266 gtk_tree_path_free (above_path);
5267 above_path = _pspp_sheet_view_find_path (tree_view, node);
5269 gtk_tree_model_get_iter (tree_view->priv->model, &iter, above_path);
5271 area_above -= ROW_HEIGHT (tree_view);
5274 /* set the dy here to scroll to the path,
5275 * and sync the top row accordingly
5277 pspp_sheet_view_set_top_row (tree_view, above_path, -area_above);
5278 pspp_sheet_view_top_row_to_dy (tree_view);
5280 /* update width/height and queue a resize */
5283 GtkRequisition requisition;
5285 /* We temporarily guess a size, under the assumption that it will be the
5286 * same when we get our next size_allocate. If we don't do this, we'll be
5287 * in an inconsistent state if we call top_row_to_dy. */
5289 gtk_widget_size_request (GTK_WIDGET (tree_view), &requisition);
5290 tree_view->priv->hadjustment->upper = MAX (tree_view->priv->hadjustment->upper, (gfloat)requisition.width);
5291 tree_view->priv->vadjustment->upper = MAX (tree_view->priv->vadjustment->upper, (gfloat)requisition.height);
5292 gtk_adjustment_changed (tree_view->priv->hadjustment);
5293 gtk_adjustment_changed (tree_view->priv->vadjustment);
5294 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
5297 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
5298 tree_view->priv->scroll_to_path = NULL;
5301 gtk_tree_path_free (above_path);
5303 if (tree_view->priv->scroll_to_column)
5305 tree_view->priv->scroll_to_column = NULL;
5307 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
5311 initialize_fixed_height_mode (PsppSheetView *tree_view)
5313 if (!tree_view->priv->row_count)
5316 if (tree_view->priv->fixed_height_set)
5319 if (tree_view->priv->fixed_height < 0)
5326 path = _pspp_sheet_view_find_path (tree_view, node);
5327 gtk_tree_model_get_iter (tree_view->priv->model, &iter, path);
5329 tree_view->priv->fixed_height = validate_row (tree_view, node, &iter, path);
5331 gtk_tree_path_free (path);
5333 g_object_notify (G_OBJECT (tree_view), "fixed-height");
5337 /* Our strategy for finding nodes to validate is a little convoluted. We find
5338 * the left-most uninvalidated node. We then try walking right, validating
5339 * nodes. Once we find a valid node, we repeat the previous process of finding
5340 * the first invalid node.
5344 validate_rows_handler (PsppSheetView *tree_view)
5346 initialize_fixed_height_mode (tree_view);
5347 if (tree_view->priv->validate_rows_timer)
5349 g_source_remove (tree_view->priv->validate_rows_timer);
5350 tree_view->priv->validate_rows_timer = 0;
5357 do_presize_handler (PsppSheetView *tree_view)
5359 GtkRequisition requisition;
5361 validate_visible_area (tree_view);
5362 tree_view->priv->presize_handler_timer = 0;
5364 if (! gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5367 gtk_widget_size_request (GTK_WIDGET (tree_view), &requisition);
5369 tree_view->priv->hadjustment->upper = MAX (tree_view->priv->hadjustment->upper, (gfloat)requisition.width);
5370 tree_view->priv->vadjustment->upper = MAX (tree_view->priv->vadjustment->upper, (gfloat)requisition.height);
5371 gtk_adjustment_changed (tree_view->priv->hadjustment);
5372 gtk_adjustment_changed (tree_view->priv->vadjustment);
5373 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
5379 presize_handler_callback (gpointer data)
5381 do_presize_handler (PSPP_SHEET_VIEW (data));
5387 install_presize_handler (PsppSheetView *tree_view)
5389 if (! gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5392 if (! tree_view->priv->presize_handler_timer)
5394 tree_view->priv->presize_handler_timer =
5395 gdk_threads_add_idle_full (GTK_PRIORITY_RESIZE - 2, presize_handler_callback, tree_view, NULL);
5397 if (! tree_view->priv->validate_rows_timer)
5399 tree_view->priv->validate_rows_timer =
5400 gdk_threads_add_idle_full (PSPP_SHEET_VIEW_PRIORITY_VALIDATE, (GSourceFunc) validate_rows_handler, tree_view, NULL);
5405 scroll_sync_handler (PsppSheetView *tree_view)
5407 if (tree_view->priv->height <= tree_view->priv->vadjustment->page_size)
5408 gtk_adjustment_set_value (GTK_ADJUSTMENT (tree_view->priv->vadjustment), 0);
5409 else if (gtk_tree_row_reference_valid (tree_view->priv->top_row))
5410 pspp_sheet_view_top_row_to_dy (tree_view);
5412 pspp_sheet_view_dy_to_top_row (tree_view);
5414 tree_view->priv->scroll_sync_timer = 0;
5420 install_scroll_sync_handler (PsppSheetView *tree_view)
5422 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
5425 if (!tree_view->priv->scroll_sync_timer)
5427 tree_view->priv->scroll_sync_timer =
5428 gdk_threads_add_idle_full (PSPP_SHEET_VIEW_PRIORITY_SCROLL_SYNC, (GSourceFunc) scroll_sync_handler, tree_view, NULL);
5433 pspp_sheet_view_set_top_row (PsppSheetView *tree_view,
5437 gtk_tree_row_reference_free (tree_view->priv->top_row);
5441 tree_view->priv->top_row = NULL;
5442 tree_view->priv->top_row_dy = 0;
5446 tree_view->priv->top_row = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
5447 tree_view->priv->top_row_dy = offset;
5451 /* Always call this iff dy is in the visible range. If the tree is empty, then
5452 * it's set to be NULL, and top_row_dy is 0;
5455 pspp_sheet_view_dy_to_top_row (PsppSheetView *tree_view)
5461 if (tree_view->priv->row_count == 0)
5463 pspp_sheet_view_set_top_row (tree_view, NULL, 0);
5467 offset = pspp_sheet_view_find_offset (tree_view,
5468 tree_view->priv->dy,
5473 pspp_sheet_view_set_top_row (tree_view, NULL, 0);
5477 path = _pspp_sheet_view_find_path (tree_view, node);
5478 pspp_sheet_view_set_top_row (tree_view, path, offset);
5479 gtk_tree_path_free (path);
5485 pspp_sheet_view_top_row_to_dy (PsppSheetView *tree_view)
5491 /* Avoid recursive calls */
5492 if (tree_view->priv->in_top_row_to_dy)
5495 if (tree_view->priv->top_row)
5496 path = gtk_tree_row_reference_get_path (tree_view->priv->top_row);
5503 _pspp_sheet_view_find_node (tree_view, path, &node);
5506 gtk_tree_path_free (path);
5510 /* keep dy and set new toprow */
5511 gtk_tree_row_reference_free (tree_view->priv->top_row);
5512 tree_view->priv->top_row = NULL;
5513 tree_view->priv->top_row_dy = 0;
5514 /* DO NOT install the idle handler */
5515 pspp_sheet_view_dy_to_top_row (tree_view);
5519 if (ROW_HEIGHT (tree_view) < tree_view->priv->top_row_dy)
5521 /* new top row -- do NOT install the idle handler */
5522 pspp_sheet_view_dy_to_top_row (tree_view);
5526 new_dy = pspp_sheet_view_node_find_offset (tree_view, node);
5527 new_dy += tree_view->priv->top_row_dy;
5529 if (new_dy + tree_view->priv->vadjustment->page_size > tree_view->priv->height)
5530 new_dy = tree_view->priv->height - tree_view->priv->vadjustment->page_size;
5532 new_dy = MAX (0, new_dy);
5534 tree_view->priv->in_top_row_to_dy = TRUE;
5535 gtk_adjustment_set_value (tree_view->priv->vadjustment, (gdouble)new_dy);
5536 tree_view->priv->in_top_row_to_dy = FALSE;
5541 _pspp_sheet_view_install_mark_rows_col_dirty (PsppSheetView *tree_view)
5543 install_presize_handler (tree_view);
5549 set_source_row (GdkDragContext *context,
5550 GtkTreeModel *model,
5551 GtkTreePath *source_row)
5553 g_object_set_data_full (G_OBJECT (context),
5554 "gtk-tree-view-source-row",
5555 source_row ? gtk_tree_row_reference_new (model, source_row) : NULL,
5556 (GDestroyNotify) (source_row ? gtk_tree_row_reference_free : NULL));
5560 get_source_row (GdkDragContext *context)
5562 GtkTreeRowReference *ref =
5563 g_object_get_data (G_OBJECT (context), "gtk-tree-view-source-row");
5566 return gtk_tree_row_reference_get_path (ref);
5573 GtkTreeRowReference *dest_row;
5574 guint path_down_mode : 1;
5575 guint empty_view_drop : 1;
5576 guint drop_append_mode : 1;
5581 dest_row_free (gpointer data)
5583 DestRow *dr = (DestRow *)data;
5585 gtk_tree_row_reference_free (dr->dest_row);
5586 g_slice_free (DestRow, dr);
5590 set_dest_row (GdkDragContext *context,
5591 GtkTreeModel *model,
5592 GtkTreePath *dest_row,
5593 gboolean path_down_mode,
5594 gboolean empty_view_drop,
5595 gboolean drop_append_mode)
5601 g_object_set_data_full (G_OBJECT (context), "gtk-tree-view-dest-row",
5606 dr = g_slice_new (DestRow);
5608 dr->dest_row = gtk_tree_row_reference_new (model, dest_row);
5609 dr->path_down_mode = path_down_mode != FALSE;
5610 dr->empty_view_drop = empty_view_drop != FALSE;
5611 dr->drop_append_mode = drop_append_mode != FALSE;
5613 g_object_set_data_full (G_OBJECT (context), "gtk-tree-view-dest-row",
5614 dr, (GDestroyNotify) dest_row_free);
5618 get_dest_row (GdkDragContext *context,
5619 gboolean *path_down_mode)
5622 g_object_get_data (G_OBJECT (context), "gtk-tree-view-dest-row");
5626 GtkTreePath *path = NULL;
5629 *path_down_mode = dr->path_down_mode;
5632 path = gtk_tree_row_reference_get_path (dr->dest_row);
5633 else if (dr->empty_view_drop)
5634 path = gtk_tree_path_new_from_indices (0, -1);
5638 if (path && dr->drop_append_mode)
5639 gtk_tree_path_next (path);
5647 /* Get/set whether drag_motion requested the drag data and
5648 * drag_data_received should thus not actually insert the data,
5649 * since the data doesn't result from a drop.
5652 set_status_pending (GdkDragContext *context,
5653 GdkDragAction suggested_action)
5655 g_object_set_data (G_OBJECT (context),
5656 "gtk-tree-view-status-pending",
5657 GINT_TO_POINTER (suggested_action));
5660 static GdkDragAction
5661 get_status_pending (GdkDragContext *context)
5663 return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
5664 "gtk-tree-view-status-pending"));
5667 static TreeViewDragInfo*
5668 get_info (PsppSheetView *tree_view)
5670 return g_object_get_data (G_OBJECT (tree_view), "gtk-tree-view-drag-info");
5674 destroy_info (TreeViewDragInfo *di)
5676 g_slice_free (TreeViewDragInfo, di);
5679 static TreeViewDragInfo*
5680 ensure_info (PsppSheetView *tree_view)
5682 TreeViewDragInfo *di;
5684 di = get_info (tree_view);
5688 di = g_slice_new0 (TreeViewDragInfo);
5690 g_object_set_data_full (G_OBJECT (tree_view),
5691 "gtk-tree-view-drag-info",
5693 (GDestroyNotify) destroy_info);
5700 remove_info (PsppSheetView *tree_view)
5702 g_object_set_data (G_OBJECT (tree_view), "gtk-tree-view-drag-info", NULL);
5707 drag_scan_timeout (gpointer data)
5709 PsppSheetView *tree_view;
5711 GdkModifierType state;
5712 GtkTreePath *path = NULL;
5713 PsppSheetViewColumn *column = NULL;
5714 GdkRectangle visible_rect;
5716 GDK_THREADS_ENTER ();
5718 tree_view = PSPP_SHEET_VIEW (data);
5720 gdk_window_get_pointer (tree_view->priv->bin_window,
5723 pspp_sheet_view_get_visible_rect (tree_view, &visible_rect);
5725 /* See if we are near the edge. */
5726 if ((x - visible_rect.x) < SCROLL_EDGE_SIZE ||
5727 (visible_rect.x + visible_rect.width - x) < SCROLL_EDGE_SIZE ||
5728 (y - visible_rect.y) < SCROLL_EDGE_SIZE ||
5729 (visible_rect.y + visible_rect.height - y) < SCROLL_EDGE_SIZE)
5731 pspp_sheet_view_get_path_at_pos (tree_view,
5732 tree_view->priv->bin_window,
5741 pspp_sheet_view_scroll_to_cell (tree_view,
5747 gtk_tree_path_free (path);
5751 GDK_THREADS_LEAVE ();
5758 add_scroll_timeout (PsppSheetView *tree_view)
5760 if (tree_view->priv->scroll_timeout == 0)
5762 tree_view->priv->scroll_timeout =
5763 gdk_threads_add_timeout (150, scroll_row_timeout, tree_view);
5768 remove_scroll_timeout (PsppSheetView *tree_view)
5770 if (tree_view->priv->scroll_timeout != 0)
5772 g_source_remove (tree_view->priv->scroll_timeout);
5773 tree_view->priv->scroll_timeout = 0;
5778 check_model_dnd (GtkTreeModel *model,
5779 GType required_iface,
5780 const gchar *signal)
5782 if (model == NULL || !G_TYPE_CHECK_INSTANCE_TYPE ((model), required_iface))
5784 g_warning ("You must override the default '%s' handler "
5785 "on PsppSheetView when using models that don't support "
5786 "the %s interface and enabling drag-and-drop. The simplest way to do this "
5787 "is to connect to '%s' and call "
5788 "g_signal_stop_emission_by_name() in your signal handler to prevent "
5789 "the default handler from running. Look at the source code "
5790 "for the default handler in gtktreeview.c to get an idea what "
5791 "your handler should do. (gtktreeview.c is in the GTK source "
5792 "code.) If you're using GTK from a language other than C, "
5793 "there may be a more natural way to override default handlers, e.g. via derivation.",
5794 signal, g_type_name (required_iface), signal);
5802 scroll_row_timeout (gpointer data)
5804 PsppSheetView *tree_view = data;
5806 pspp_sheet_view_horizontal_autoscroll (tree_view);
5807 pspp_sheet_view_vertical_autoscroll (tree_view);
5809 if (tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
5810 pspp_sheet_view_update_rubber_band (tree_view);
5815 /* Returns TRUE if event should not be propagated to parent widgets */
5817 set_destination_row (PsppSheetView *tree_view,
5818 GdkDragContext *context,
5819 /* coordinates relative to the widget */
5822 GdkDragAction *suggested_action,
5825 GtkTreePath *path = NULL;
5826 PsppSheetViewDropPosition pos;
5827 PsppSheetViewDropPosition old_pos;
5828 TreeViewDragInfo *di;
5830 GtkTreePath *old_dest_path = NULL;
5831 gboolean can_drop = FALSE;
5833 *suggested_action = 0;
5836 widget = GTK_WIDGET (tree_view);
5838 di = get_info (tree_view);
5840 if (di == NULL || y - TREE_VIEW_HEADER_HEIGHT (tree_view) < 0)
5842 /* someone unset us as a drag dest, note that if
5843 * we return FALSE drag_leave isn't called
5846 pspp_sheet_view_set_drag_dest_row (tree_view,
5848 PSPP_SHEET_VIEW_DROP_BEFORE);
5850 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
5852 return FALSE; /* no longer a drop site */
5855 *target = gtk_drag_dest_find_target (widget, context,
5856 gtk_drag_dest_get_target_list (widget));
5857 if (*target == GDK_NONE)
5862 if (!pspp_sheet_view_get_dest_row_at_pos (tree_view,
5868 GtkTreeModel *model;
5870 /* the row got dropped on empty space, let's setup a special case
5874 gtk_tree_path_free (path);
5876 model = pspp_sheet_view_get_model (tree_view);
5878 n_children = gtk_tree_model_iter_n_children (model, NULL);
5881 pos = PSPP_SHEET_VIEW_DROP_AFTER;
5882 path = gtk_tree_path_new_from_indices (n_children - 1, -1);
5886 pos = PSPP_SHEET_VIEW_DROP_BEFORE;
5887 path = gtk_tree_path_new_from_indices (0, -1);
5897 /* If we left the current row's "open" zone, unset the timeout for
5900 pspp_sheet_view_get_drag_dest_row (tree_view,
5905 gtk_tree_path_free (old_dest_path);
5907 if (TRUE /* FIXME if the location droppable predicate */)
5915 GtkWidget *source_widget;
5917 *suggested_action = context->suggested_action;
5918 source_widget = gtk_drag_get_source_widget (context);
5920 if (source_widget == widget)
5922 /* Default to MOVE, unless the user has
5923 * pressed ctrl or shift to affect available actions
5925 if ((context->actions & GDK_ACTION_MOVE) != 0)
5926 *suggested_action = GDK_ACTION_MOVE;
5929 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
5934 /* can't drop here */
5935 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
5937 PSPP_SHEET_VIEW_DROP_BEFORE);
5941 gtk_tree_path_free (path);
5947 get_logical_dest_row (PsppSheetView *tree_view,
5948 gboolean *path_down_mode,
5949 gboolean *drop_append_mode)
5951 /* adjust path to point to the row the drop goes in front of */
5952 GtkTreePath *path = NULL;
5953 PsppSheetViewDropPosition pos;
5955 g_return_val_if_fail (path_down_mode != NULL, NULL);
5956 g_return_val_if_fail (drop_append_mode != NULL, NULL);
5958 *path_down_mode = FALSE;
5959 *drop_append_mode = 0;
5961 pspp_sheet_view_get_drag_dest_row (tree_view, &path, &pos);
5966 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE)
5968 else if (pos == PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE ||
5969 pos == PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER)
5970 *path_down_mode = TRUE;
5974 GtkTreeModel *model = pspp_sheet_view_get_model (tree_view);
5976 g_assert (pos == PSPP_SHEET_VIEW_DROP_AFTER);
5978 if (!gtk_tree_model_get_iter (model, &iter, path) ||
5979 !gtk_tree_model_iter_next (model, &iter))
5980 *drop_append_mode = 1;
5983 *drop_append_mode = 0;
5984 gtk_tree_path_next (path);
5992 pspp_sheet_view_maybe_begin_dragging_row (PsppSheetView *tree_view,
5993 GdkEventMotion *event)
5995 GtkWidget *widget = GTK_WIDGET (tree_view);
5996 GdkDragContext *context;
5997 TreeViewDragInfo *di;
5998 GtkTreePath *path = NULL;
6000 gint cell_x, cell_y;
6001 GtkTreeModel *model;
6002 gboolean retval = FALSE;
6004 di = get_info (tree_view);
6006 if (di == NULL || !di->source_set)
6009 if (tree_view->priv->pressed_button < 0)
6012 if (!gtk_drag_check_threshold (widget,
6013 tree_view->priv->press_start_x,
6014 tree_view->priv->press_start_y,
6015 event->x, event->y))
6018 model = pspp_sheet_view_get_model (tree_view);
6023 button = tree_view->priv->pressed_button;
6024 tree_view->priv->pressed_button = -1;
6026 pspp_sheet_view_get_path_at_pos (tree_view,
6027 tree_view->priv->press_start_x,
6028 tree_view->priv->press_start_y,
6037 if (!GTK_IS_TREE_DRAG_SOURCE (model) ||
6038 !gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (model),
6042 if (!(GDK_BUTTON1_MASK << (button - 1) & di->start_button_mask))
6045 /* Now we can begin the drag */
6049 context = gtk_drag_begin (widget,
6050 gtk_drag_source_get_target_list (widget),
6055 set_source_row (context, model, path);
6059 gtk_tree_path_free (path);
6066 pspp_sheet_view_drag_begin (GtkWidget *widget,
6067 GdkDragContext *context)
6069 PsppSheetView *tree_view;
6070 GtkTreePath *path = NULL;
6071 gint cell_x, cell_y;
6073 TreeViewDragInfo *di;
6075 tree_view = PSPP_SHEET_VIEW (widget);
6077 /* if the user uses a custom DND source impl, we don't set the icon here */
6078 di = get_info (tree_view);
6080 if (di == NULL || !di->source_set)
6083 pspp_sheet_view_get_path_at_pos (tree_view,
6084 tree_view->priv->press_start_x,
6085 tree_view->priv->press_start_y,
6091 g_return_if_fail (path != NULL);
6093 row_pix = pspp_sheet_view_create_row_drag_icon (tree_view,
6096 gtk_drag_set_icon_pixmap (context,
6097 gdk_drawable_get_colormap (row_pix),
6100 /* the + 1 is for the black border in the icon */
6101 tree_view->priv->press_start_x + 1,
6104 g_object_unref (row_pix);
6105 gtk_tree_path_free (path);
6109 pspp_sheet_view_drag_end (GtkWidget *widget,
6110 GdkDragContext *context)
6115 /* Default signal implementations for the drag signals */
6117 pspp_sheet_view_drag_data_get (GtkWidget *widget,
6118 GdkDragContext *context,
6119 GtkSelectionData *selection_data,
6123 PsppSheetView *tree_view;
6124 GtkTreeModel *model;
6125 TreeViewDragInfo *di;
6126 GtkTreePath *source_row;
6128 tree_view = PSPP_SHEET_VIEW (widget);
6130 model = pspp_sheet_view_get_model (tree_view);
6135 di = get_info (PSPP_SHEET_VIEW (widget));
6140 source_row = get_source_row (context);
6142 if (source_row == NULL)
6145 /* We can implement the GTK_TREE_MODEL_ROW target generically for
6146 * any model; for DragSource models there are some other targets
6150 if (GTK_IS_TREE_DRAG_SOURCE (model) &&
6151 gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (model),
6156 /* If drag_data_get does nothing, try providing row data. */
6157 if (selection_data->target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6159 gtk_tree_set_row_drag_data (selection_data,
6165 gtk_tree_path_free (source_row);
6170 pspp_sheet_view_drag_data_delete (GtkWidget *widget,
6171 GdkDragContext *context)
6173 TreeViewDragInfo *di;
6174 GtkTreeModel *model;
6175 PsppSheetView *tree_view;
6176 GtkTreePath *source_row;
6178 tree_view = PSPP_SHEET_VIEW (widget);
6179 model = pspp_sheet_view_get_model (tree_view);
6181 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_SOURCE, "drag_data_delete"))
6184 di = get_info (tree_view);
6189 source_row = get_source_row (context);
6191 if (source_row == NULL)
6194 gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (model),
6197 gtk_tree_path_free (source_row);
6199 set_source_row (context, NULL, NULL);
6203 pspp_sheet_view_drag_leave (GtkWidget *widget,
6204 GdkDragContext *context,
6207 /* unset any highlight row */
6208 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6210 PSPP_SHEET_VIEW_DROP_BEFORE);
6212 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6217 pspp_sheet_view_drag_motion (GtkWidget *widget,
6218 GdkDragContext *context,
6219 /* coordinates relative to the widget */
6225 GtkTreePath *path = NULL;
6226 PsppSheetViewDropPosition pos;
6227 PsppSheetView *tree_view;
6228 GdkDragAction suggested_action = 0;
6231 tree_view = PSPP_SHEET_VIEW (widget);
6233 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6236 pspp_sheet_view_get_drag_dest_row (tree_view, &path, &pos);
6238 /* we only know this *after* set_desination_row */
6239 empty = tree_view->priv->empty_view_drop;
6241 if (path == NULL && !empty)
6243 /* Can't drop here. */
6244 gdk_drag_status (context, 0, time);
6248 if (tree_view->priv->open_dest_timeout == 0 &&
6249 (pos == PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER ||
6250 pos == PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE))
6256 add_scroll_timeout (tree_view);
6259 if (target == gdk_atom_intern_static_string ("GTK_TREE_MODEL_ROW"))
6261 /* Request data so we can use the source row when
6262 * determining whether to accept the drop
6264 set_status_pending (context, suggested_action);
6265 gtk_drag_get_data (widget, context, target, time);
6269 set_status_pending (context, 0);
6270 gdk_drag_status (context, suggested_action, time);
6275 gtk_tree_path_free (path);
6282 pspp_sheet_view_drag_drop (GtkWidget *widget,
6283 GdkDragContext *context,
6284 /* coordinates relative to the widget */
6289 PsppSheetView *tree_view;
6291 GdkDragAction suggested_action = 0;
6292 GdkAtom target = GDK_NONE;
6293 TreeViewDragInfo *di;
6294 GtkTreeModel *model;
6295 gboolean path_down_mode;
6296 gboolean drop_append_mode;
6298 tree_view = PSPP_SHEET_VIEW (widget);
6300 model = pspp_sheet_view_get_model (tree_view);
6302 remove_scroll_timeout (PSPP_SHEET_VIEW (widget));
6304 di = get_info (tree_view);
6309 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
6312 if (!set_destination_row (tree_view, context, x, y, &suggested_action, &target))
6315 path = get_logical_dest_row (tree_view, &path_down_mode, &drop_append_mode);
6317 if (target != GDK_NONE && path != NULL)
6319 /* in case a motion had requested drag data, change things so we
6320 * treat drag data receives as a drop.
6322 set_status_pending (context, 0);
6323 set_dest_row (context, model, path,
6324 path_down_mode, tree_view->priv->empty_view_drop,
6329 gtk_tree_path_free (path);
6331 /* Unset this thing */
6332 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6334 PSPP_SHEET_VIEW_DROP_BEFORE);
6336 if (target != GDK_NONE)
6338 gtk_drag_get_data (widget, context, target, time);
6346 pspp_sheet_view_drag_data_received (GtkWidget *widget,
6347 GdkDragContext *context,
6348 /* coordinates relative to the widget */
6351 GtkSelectionData *selection_data,
6356 TreeViewDragInfo *di;
6357 gboolean accepted = FALSE;
6358 GtkTreeModel *model;
6359 PsppSheetView *tree_view;
6360 GtkTreePath *dest_row;
6361 GdkDragAction suggested_action;
6362 gboolean path_down_mode;
6363 gboolean drop_append_mode;
6365 tree_view = PSPP_SHEET_VIEW (widget);
6367 model = pspp_sheet_view_get_model (tree_view);
6369 if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_data_received"))
6372 di = get_info (tree_view);
6377 suggested_action = get_status_pending (context);
6379 if (suggested_action)
6381 /* We are getting this data due to a request in drag_motion,
6382 * rather than due to a request in drag_drop, so we are just
6383 * supposed to call drag_status, not actually paste in the
6386 path = get_logical_dest_row (tree_view, &path_down_mode,
6390 suggested_action = 0;
6391 else if (path_down_mode)
6392 gtk_tree_path_down (path);
6394 if (suggested_action)
6396 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6402 path_down_mode = FALSE;
6403 gtk_tree_path_up (path);
6405 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6408 suggested_action = 0;
6411 suggested_action = 0;
6415 gdk_drag_status (context, suggested_action, time);
6418 gtk_tree_path_free (path);
6420 /* If you can't drop, remove user drop indicator until the next motion */
6421 if (suggested_action == 0)
6422 pspp_sheet_view_set_drag_dest_row (PSPP_SHEET_VIEW (widget),
6424 PSPP_SHEET_VIEW_DROP_BEFORE);
6429 dest_row = get_dest_row (context, &path_down_mode);
6431 if (dest_row == NULL)
6434 if (selection_data->length >= 0)
6438 gtk_tree_path_down (dest_row);
6439 if (!gtk_tree_drag_dest_row_drop_possible (GTK_TREE_DRAG_DEST (model),
6440 dest_row, selection_data))
6441 gtk_tree_path_up (dest_row);
6445 if (selection_data->length >= 0)
6447 if (gtk_tree_drag_dest_drag_data_received (GTK_TREE_DRAG_DEST (model),
6453 gtk_drag_finish (context,
6455 (context->action == GDK_ACTION_MOVE),
6458 if (gtk_tree_path_get_depth (dest_row) == 1
6459 && gtk_tree_path_get_indices (dest_row)[0] == 0)
6461 /* special special case drag to "0", scroll to first item */
6462 if (!tree_view->priv->scroll_to_path)
6463 pspp_sheet_view_scroll_to_cell (tree_view, dest_row, NULL, FALSE, 0.0, 0.0);
6466 gtk_tree_path_free (dest_row);
6469 set_dest_row (context, NULL, NULL, FALSE, FALSE, FALSE);
6474 /* GtkContainer Methods
6479 pspp_sheet_view_remove (GtkContainer *container,
6482 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6483 PsppSheetViewChild *child = NULL;
6486 tmp_list = tree_view->priv->children;
6489 child = tmp_list->data;
6490 if (child->widget == widget)
6492 gtk_widget_unparent (widget);
6494 tree_view->priv->children = g_list_remove_link (tree_view->priv->children, tmp_list);
6495 g_list_free_1 (tmp_list);
6496 g_slice_free (PsppSheetViewChild, child);
6500 tmp_list = tmp_list->next;
6503 tmp_list = tree_view->priv->columns;
6507 PsppSheetViewColumn *column;
6508 column = tmp_list->data;
6509 if (column->button == widget)
6511 gtk_widget_unparent (widget);
6514 tmp_list = tmp_list->next;
6519 pspp_sheet_view_forall (GtkContainer *container,
6520 gboolean include_internals,
6521 GtkCallback callback,
6522 gpointer callback_data)
6524 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6525 PsppSheetViewChild *child = NULL;
6526 PsppSheetViewColumn *column;
6529 tmp_list = tree_view->priv->children;
6532 child = tmp_list->data;
6533 tmp_list = tmp_list->next;
6535 (* callback) (child->widget, callback_data);
6537 if (include_internals == FALSE)
6540 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6542 column = tmp_list->data;
6545 (* callback) (column->button, callback_data);
6549 /* Returns TRUE if the treeview contains no "special" (editable or activatable)
6550 * cells. If so we draw one big row-spanning focus rectangle.
6553 pspp_sheet_view_has_special_cell (PsppSheetView *tree_view)
6557 if (tree_view->priv->special_cells != PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT)
6558 return tree_view->priv->special_cells = PSPP_SHEET_VIEW_SPECIAL_CELLS_YES;
6560 for (list = tree_view->priv->columns; list; list = list->next)
6562 if (!((PsppSheetViewColumn *)list->data)->visible)
6564 if (_pspp_sheet_view_column_count_special_cells (list->data))
6572 pspp_sheet_view_focus_column (PsppSheetView *tree_view,
6573 PsppSheetViewColumn *focus_column,
6574 gboolean clamp_column_visible)
6576 g_return_if_fail (focus_column != NULL);
6578 tree_view->priv->focus_column = focus_column;
6579 if (!focus_column->button)
6581 pspp_sheet_view_column_set_need_button (focus_column, TRUE);
6582 g_return_if_fail (focus_column->button != NULL);
6585 if (GTK_CONTAINER (tree_view)->focus_child != focus_column->button)
6586 gtk_widget_grab_focus (focus_column->button);
6588 if (clamp_column_visible)
6589 pspp_sheet_view_clamp_column_visible (tree_view, focus_column, FALSE);
6592 /* Returns TRUE if the focus is within the headers, after the focus operation is
6596 pspp_sheet_view_header_focus (PsppSheetView *tree_view,
6597 GtkDirectionType dir,
6598 gboolean clamp_column_visible)
6600 GtkWidget *focus_child;
6601 PsppSheetViewColumn *focus_column;
6602 GList *last_column, *first_column;
6606 if (! PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE))
6609 focus_child = GTK_CONTAINER (tree_view)->focus_child;
6611 first_column = tree_view->priv->columns;
6612 while (first_column)
6614 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (first_column->data);
6616 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6618 first_column = first_column->next;
6621 /* No headers are visible, or are focusable. We can't focus in or out.
6623 if (first_column == NULL)
6626 last_column = g_list_last (tree_view->priv->columns);
6629 PsppSheetViewColumn *c = PSPP_SHEET_VIEW_COLUMN (last_column->data);
6631 if (pspp_sheet_view_column_can_focus (c) && c->visible)
6633 last_column = last_column->prev;
6637 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
6641 case GTK_DIR_TAB_BACKWARD:
6642 case GTK_DIR_TAB_FORWARD:
6645 if (focus_child == NULL)
6647 if (tree_view->priv->focus_column != NULL &&
6648 pspp_sheet_view_column_can_focus (tree_view->priv->focus_column))
6649 focus_column = tree_view->priv->focus_column;
6651 focus_column = first_column->data;
6652 pspp_sheet_view_focus_column (tree_view, focus_column,
6653 clamp_column_visible);
6660 if (focus_child == NULL)
6662 if (tree_view->priv->focus_column != NULL)
6663 focus_column = tree_view->priv->focus_column;
6664 else if (dir == GTK_DIR_LEFT)
6665 focus_column = last_column->data;
6667 focus_column = first_column->data;
6668 pspp_sheet_view_focus_column (tree_view, focus_column,
6669 clamp_column_visible);
6673 if (gtk_widget_child_focus (focus_child, dir))
6675 /* The focus moves inside the button. */
6676 /* This is probably a great example of bad UI */
6677 if (clamp_column_visible)
6678 pspp_sheet_view_clamp_column_visible (tree_view,
6679 tree_view->priv->focus_column,
6684 /* We need to move the focus among the row of buttons. */
6685 for (tmp_list = tree_view->priv->columns; tmp_list; tmp_list = tmp_list->next)
6686 if (PSPP_SHEET_VIEW_COLUMN (tmp_list->data)->button == focus_child)
6689 if ((tmp_list == first_column && dir == (rtl ? GTK_DIR_RIGHT : GTK_DIR_LEFT))
6690 || (tmp_list == last_column && dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT)))
6692 gtk_widget_error_bell (GTK_WIDGET (tree_view));
6698 PsppSheetViewColumn *column;
6700 if (dir == (rtl ? GTK_DIR_LEFT : GTK_DIR_RIGHT))
6701 tmp_list = tmp_list->next;
6703 tmp_list = tmp_list->prev;
6705 if (tmp_list == NULL)
6707 g_warning ("Internal button not found");
6710 column = tmp_list->data;
6711 if (column->button &&
6713 pspp_sheet_view_column_can_focus (column))
6715 pspp_sheet_view_focus_column (tree_view, column,
6716 clamp_column_visible);
6723 g_assert_not_reached ();
6730 /* This function returns in 'path' the first focusable path, if the given path
6731 * is already focusable, it's the returned one.
6735 search_first_focusable_path (PsppSheetView *tree_view,
6737 gboolean search_forward,
6740 /* XXX this function is trivial given that the sheetview doesn't support
6744 if (!path || !*path)
6747 _pspp_sheet_view_find_node (tree_view, *path, &node);
6755 return (*path != NULL);
6759 pspp_sheet_view_focus (GtkWidget *widget,
6760 GtkDirectionType direction)
6762 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6763 GtkContainer *container = GTK_CONTAINER (widget);
6764 GtkWidget *focus_child;
6766 if (!gtk_widget_is_sensitive (widget) || !gtk_widget_get_can_focus (widget))
6769 focus_child = container->focus_child;
6771 pspp_sheet_view_stop_editing (PSPP_SHEET_VIEW (widget), FALSE);
6772 /* Case 1. Headers currently have focus. */
6779 pspp_sheet_view_header_focus (tree_view, direction, TRUE);
6781 case GTK_DIR_TAB_BACKWARD:
6784 case GTK_DIR_TAB_FORWARD:
6786 gtk_widget_grab_focus (widget);
6789 g_assert_not_reached ();
6794 /* Case 2. We don't have focus at all. */
6795 if (!gtk_widget_has_focus (widget))
6797 if (!pspp_sheet_view_header_focus (tree_view, direction, FALSE))
6798 gtk_widget_grab_focus (widget);
6802 /* Case 3. We have focus already. */
6803 if (direction == GTK_DIR_TAB_BACKWARD)
6804 return (pspp_sheet_view_header_focus (tree_view, direction, FALSE));
6805 else if (direction == GTK_DIR_TAB_FORWARD)
6808 /* Other directions caught by the keybindings */
6809 gtk_widget_grab_focus (widget);
6814 pspp_sheet_view_grab_focus (GtkWidget *widget)
6816 GTK_WIDGET_CLASS (pspp_sheet_view_parent_class)->grab_focus (widget);
6818 pspp_sheet_view_focus_to_cursor (PSPP_SHEET_VIEW (widget));
6822 pspp_sheet_view_style_set (GtkWidget *widget,
6823 GtkStyle *previous_style)
6825 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
6827 PsppSheetViewColumn *column;
6829 if (gtk_widget_get_realized (widget))
6832 PsppSheetViewPrivate *priv = PSPP_SHEET_VIEW (widget)->priv;
6834 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
6835 gdk_window_set_background (tree_view->priv->bin_window, &widget->style->base[widget->state]);
6836 gtk_style_set_background (widget->style, tree_view->priv->header_window, GTK_STATE_NORMAL);
6837 for (i = 0; i < 5 ; ++i)
6839 g_object_unref (priv->grid_line_gc[i]);
6840 priv->grid_line_gc[i] = gdk_gc_new (widget->window);
6841 gdk_gc_copy (priv->grid_line_gc[i], widget->style->text_aa_gc[i]);
6844 pspp_sheet_view_set_grid_lines (tree_view, tree_view->priv->grid_lines);
6847 gtk_widget_style_get (widget,
6848 "expander-size", &tree_view->priv->expander_size,
6850 tree_view->priv->expander_size += EXPANDER_EXTRA_PADDING;
6852 for (list = tree_view->priv->columns; list; list = list->next)
6854 column = list->data;
6855 _pspp_sheet_view_column_cell_set_dirty (column);
6858 tree_view->priv->fixed_height = -1;
6860 /* Invalidate cached button style. */
6861 if (tree_view->priv->button_style)
6863 g_object_unref (tree_view->priv->button_style);
6864 tree_view->priv->button_style = NULL;
6867 gtk_widget_queue_resize (widget);
6872 pspp_sheet_view_set_focus_child (GtkContainer *container,
6875 PsppSheetView *tree_view = PSPP_SHEET_VIEW (container);
6878 for (list = tree_view->priv->columns; list; list = list->next)
6880 if (PSPP_SHEET_VIEW_COLUMN (list->data)->button == child)
6882 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
6887 GTK_CONTAINER_CLASS (pspp_sheet_view_parent_class)->set_focus_child (container, child);
6891 pspp_sheet_view_set_adjustments (PsppSheetView *tree_view,
6892 GtkAdjustment *hadj,
6893 GtkAdjustment *vadj)
6895 gboolean need_adjust = FALSE;
6897 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
6900 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
6902 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
6904 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
6906 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
6908 if (tree_view->priv->hadjustment && (tree_view->priv->hadjustment != hadj))
6910 g_signal_handlers_disconnect_by_func (tree_view->priv->hadjustment,
6911 pspp_sheet_view_adjustment_changed,
6913 g_object_unref (tree_view->priv->hadjustment);
6916 if (tree_view->priv->vadjustment && (tree_view->priv->vadjustment != vadj))
6918 g_signal_handlers_disconnect_by_func (tree_view->priv->vadjustment,
6919 pspp_sheet_view_adjustment_changed,
6921 g_object_unref (tree_view->priv->vadjustment);
6924 if (tree_view->priv->hadjustment != hadj)
6926 tree_view->priv->hadjustment = hadj;
6927 g_object_ref_sink (tree_view->priv->hadjustment);
6929 g_signal_connect (tree_view->priv->hadjustment, "value-changed",
6930 G_CALLBACK (pspp_sheet_view_adjustment_changed),
6935 if (tree_view->priv->vadjustment != vadj)
6937 tree_view->priv->vadjustment = vadj;
6938 g_object_ref_sink (tree_view->priv->vadjustment);
6940 g_signal_connect (tree_view->priv->vadjustment, "value-changed",
6941 G_CALLBACK (pspp_sheet_view_adjustment_changed),
6947 pspp_sheet_view_adjustment_changed (NULL, tree_view);
6952 pspp_sheet_view_real_move_cursor (PsppSheetView *tree_view,
6953 GtkMovementStep step,
6956 GdkModifierType state;
6958 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
6959 g_return_val_if_fail (step == GTK_MOVEMENT_LOGICAL_POSITIONS ||
6960 step == GTK_MOVEMENT_VISUAL_POSITIONS ||
6961 step == GTK_MOVEMENT_DISPLAY_LINES ||
6962 step == GTK_MOVEMENT_PAGES ||
6963 step == GTK_MOVEMENT_BUFFER_ENDS, FALSE);
6965 if (tree_view->priv->row_count == 0)
6967 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
6970 pspp_sheet_view_stop_editing (tree_view, FALSE);
6971 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
6972 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
6974 if (gtk_get_current_event_state (&state))
6976 if ((state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
6977 tree_view->priv->ctrl_pressed = TRUE;
6978 if ((state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)
6979 tree_view->priv->shift_pressed = TRUE;
6981 /* else we assume not pressed */
6985 /* currently we make no distinction. When we go bi-di, we need to */
6986 case GTK_MOVEMENT_LOGICAL_POSITIONS:
6987 case GTK_MOVEMENT_VISUAL_POSITIONS:
6988 pspp_sheet_view_move_cursor_left_right (tree_view, count);
6990 case GTK_MOVEMENT_DISPLAY_LINES:
6991 pspp_sheet_view_move_cursor_up_down (tree_view, count);
6993 case GTK_MOVEMENT_PAGES:
6994 pspp_sheet_view_move_cursor_page_up_down (tree_view, count);
6996 case GTK_MOVEMENT_BUFFER_ENDS:
6997 pspp_sheet_view_move_cursor_start_end (tree_view, count);
7000 g_assert_not_reached ();
7003 tree_view->priv->ctrl_pressed = FALSE;
7004 tree_view->priv->shift_pressed = FALSE;
7010 pspp_sheet_view_put (PsppSheetView *tree_view,
7011 GtkWidget *child_widget,
7012 /* in bin_window coordinates */
7018 PsppSheetViewChild *child;
7020 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
7021 g_return_if_fail (GTK_IS_WIDGET (child_widget));
7023 child = g_slice_new (PsppSheetViewChild);
7025 child->widget = child_widget;
7028 child->width = width;
7029 child->height = height;
7031 tree_view->priv->children = g_list_append (tree_view->priv->children, child);
7033 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7034 gtk_widget_set_parent_window (child->widget, tree_view->priv->bin_window);
7036 gtk_widget_set_parent (child_widget, GTK_WIDGET (tree_view));
7040 _pspp_sheet_view_child_move_resize (PsppSheetView *tree_view,
7042 /* in tree coordinates */
7048 PsppSheetViewChild *child = NULL;
7050 GdkRectangle allocation;
7052 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
7053 g_return_if_fail (GTK_IS_WIDGET (widget));
7055 for (list = tree_view->priv->children; list; list = list->next)
7057 if (((PsppSheetViewChild *)list->data)->widget == widget)
7066 allocation.x = child->x = x;
7067 allocation.y = child->y = y;
7068 allocation.width = child->width = width;
7069 allocation.height = child->height = height;
7071 if (gtk_widget_get_realized (widget))
7072 gtk_widget_size_allocate (widget, &allocation);
7076 /* TreeModel Callbacks
7080 pspp_sheet_view_row_changed (GtkTreeModel *model,
7085 PsppSheetView *tree_view = (PsppSheetView *)data;
7087 gboolean free_path = FALSE;
7088 GtkTreePath *cursor_path;
7090 g_return_if_fail (path != NULL || iter != NULL);
7092 if (tree_view->priv->cursor != NULL)
7093 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7097 if (tree_view->priv->edited_column &&
7098 (cursor_path == NULL || gtk_tree_path_compare (cursor_path, path) == 0))
7099 pspp_sheet_view_stop_editing (tree_view, TRUE);
7101 if (cursor_path != NULL)
7102 gtk_tree_path_free (cursor_path);
7106 path = gtk_tree_model_get_path (model, iter);
7109 else if (iter == NULL)
7110 gtk_tree_model_get_iter (model, iter, path);
7112 _pspp_sheet_view_find_node (tree_view,
7118 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7119 pspp_sheet_view_node_queue_redraw (tree_view, node);
7123 gtk_tree_path_free (path);
7127 pspp_sheet_view_row_inserted (GtkTreeModel *model,
7132 PsppSheetView *tree_view = (PsppSheetView *) data;
7135 gint height = tree_view->priv->fixed_height;
7136 gboolean free_path = FALSE;
7137 gboolean node_visible = TRUE;
7139 g_return_if_fail (path != NULL || iter != NULL);
7143 path = gtk_tree_model_get_path (model, iter);
7146 else if (iter == NULL)
7147 gtk_tree_model_get_iter (model, iter, path);
7149 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7151 /* Update all row-references */
7152 gtk_tree_row_reference_inserted (G_OBJECT (data), path);
7153 indices = gtk_tree_path_get_indices (path);
7154 tmpnode = indices[0];
7156 range_tower_insert0 (tree_view->priv->selected, tmpnode, 1);
7160 if (node_visible && node_is_visible (tree_view, tmpnode))
7161 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7163 gtk_widget_queue_resize_no_redraw (GTK_WIDGET (tree_view));
7166 install_presize_handler (tree_view);
7168 gtk_tree_path_free (path);
7172 pspp_sheet_view_row_deleted (GtkTreeModel *model,
7176 PsppSheetView *tree_view = (PsppSheetView *)data;
7179 g_return_if_fail (path != NULL);
7181 gtk_tree_row_reference_deleted (G_OBJECT (data), path);
7183 _pspp_sheet_view_find_node (tree_view, path, &node);
7188 range_tower_delete (tree_view->priv->selected, node, 1);
7190 /* Ensure we don't have a dangling pointer to a dead node */
7191 ensure_unprelighted (tree_view);
7193 /* Cancel editting if we've started */
7194 pspp_sheet_view_stop_editing (tree_view, TRUE);
7196 if (tree_view->priv->destroy_count_func)
7198 gint child_count = 0;
7199 tree_view->priv->destroy_count_func (tree_view, path, child_count, tree_view->priv->destroy_count_data);
7202 tree_view->priv->row_count = gtk_tree_model_iter_n_children (model, NULL);
7204 if (! gtk_tree_row_reference_valid (tree_view->priv->top_row))
7206 gtk_tree_row_reference_free (tree_view->priv->top_row);
7207 tree_view->priv->top_row = NULL;
7210 install_scroll_sync_handler (tree_view);
7212 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
7215 if (helper_data.changed)
7216 g_signal_emit_by_name (tree_view->priv->selection, "changed");
7221 pspp_sheet_view_rows_reordered (GtkTreeModel *model,
7222 GtkTreePath *parent,
7227 PsppSheetView *tree_view = PSPP_SHEET_VIEW (data);
7230 /* XXX need to adjust selection */
7231 len = gtk_tree_model_iter_n_children (model, iter);
7236 gtk_tree_row_reference_reordered (G_OBJECT (data),
7241 if (gtk_tree_path_get_depth (parent) != 0)
7244 if (tree_view->priv->edited_column)
7245 pspp_sheet_view_stop_editing (tree_view, TRUE);
7247 /* we need to be unprelighted */
7248 ensure_unprelighted (tree_view);
7250 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
7252 pspp_sheet_view_dy_to_top_row (tree_view);
7256 /* Internal tree functions
7261 pspp_sheet_view_get_background_xrange (PsppSheetView *tree_view,
7262 PsppSheetViewColumn *column,
7266 PsppSheetViewColumn *tmp_column = NULL;
7277 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7280 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
7282 list = (rtl ? list->prev : list->next))
7284 tmp_column = list->data;
7286 if (tmp_column == column)
7289 if (tmp_column->visible)
7290 total_width += tmp_column->width;
7293 if (tmp_column != column)
7295 g_warning (G_STRLOC": passed-in column isn't in the tree");
7304 if (column->visible)
7305 *x2 = total_width + column->width;
7307 *x2 = total_width; /* width of 0 */
7311 /* Make sure the node is visible vertically */
7313 pspp_sheet_view_clamp_node_visible (PsppSheetView *tree_view,
7316 gint node_dy, height;
7317 GtkTreePath *path = NULL;
7319 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7322 /* just return if the node is visible, avoiding a costly expose */
7323 node_dy = pspp_sheet_view_node_find_offset (tree_view, node);
7324 height = ROW_HEIGHT (tree_view);
7325 if (node_dy >= tree_view->priv->vadjustment->value
7326 && node_dy + height <= (tree_view->priv->vadjustment->value
7327 + tree_view->priv->vadjustment->page_size))
7330 path = _pspp_sheet_view_find_path (tree_view, node);
7333 /* We process updates because we want to clear old selected items when we scroll.
7334 * if this is removed, we get a "selection streak" at the bottom. */
7335 gdk_window_process_updates (tree_view->priv->bin_window, TRUE);
7336 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL, FALSE, 0.0, 0.0);
7337 gtk_tree_path_free (path);
7342 pspp_sheet_view_clamp_column_visible (PsppSheetView *tree_view,
7343 PsppSheetViewColumn *column,
7344 gboolean focus_to_cell)
7351 x = column->allocation.x;
7352 width = column->allocation.width;
7354 if (width > tree_view->priv->hadjustment->page_size)
7356 /* The column is larger than the horizontal page size. If the
7357 * column has cells which can be focussed individually, then we make
7358 * sure the cell which gets focus is fully visible (if even the
7359 * focus cell is bigger than the page size, we make sure the
7360 * left-hand side of the cell is visible).
7362 * If the column does not have those so-called special cells, we
7363 * make sure the left-hand side of the column is visible.
7366 if (focus_to_cell && pspp_sheet_view_has_special_cell (tree_view))
7368 GtkTreePath *cursor_path;
7369 GdkRectangle background_area, cell_area, focus_area;
7371 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7373 pspp_sheet_view_get_cell_area (tree_view,
7374 cursor_path, column, &cell_area);
7375 pspp_sheet_view_get_background_area (tree_view,
7376 cursor_path, column,
7379 gtk_tree_path_free (cursor_path);
7381 _pspp_sheet_view_column_get_focus_area (column,
7387 width = focus_area.width;
7389 if (width < tree_view->priv->hadjustment->page_size)
7391 if ((tree_view->priv->hadjustment->value + tree_view->priv->hadjustment->page_size) < (x + width))
7392 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7393 x + width - tree_view->priv->hadjustment->page_size);
7394 else if (tree_view->priv->hadjustment->value > x)
7395 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7399 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7401 tree_view->priv->hadjustment->lower,
7402 tree_view->priv->hadjustment->upper
7403 - tree_view->priv->hadjustment->page_size));
7407 if ((tree_view->priv->hadjustment->value + tree_view->priv->hadjustment->page_size) < (x + width))
7408 gtk_adjustment_set_value (tree_view->priv->hadjustment,
7409 x + width - tree_view->priv->hadjustment->page_size);
7410 else if (tree_view->priv->hadjustment->value > x)
7411 gtk_adjustment_set_value (tree_view->priv->hadjustment, x);
7416 _pspp_sheet_view_find_path (PsppSheetView *tree_view,
7421 path = gtk_tree_path_new ();
7423 gtk_tree_path_append_index (path, node);
7428 _pspp_sheet_view_find_node (PsppSheetView *tree_view,
7432 gint *indices = gtk_tree_path_get_indices (path);
7433 gint depth = gtk_tree_path_get_depth (path);
7436 if (depth == 0 || indices[0] < 0 || indices[0] >= tree_view->priv->row_count)
7442 pspp_sheet_view_add_move_binding (GtkBindingSet *binding_set,
7445 gboolean add_shifted_binding,
7446 GtkMovementStep step,
7450 gtk_binding_entry_add_signal (binding_set, keyval, modmask,
7455 if (add_shifted_binding)
7456 gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
7461 if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
7464 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
7469 gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
7476 pspp_sheet_view_set_column_drag_info (PsppSheetView *tree_view,
7477 PsppSheetViewColumn *column)
7479 PsppSheetViewColumn *left_column;
7480 PsppSheetViewColumn *cur_column = NULL;
7481 PsppSheetViewColumnReorder *reorder;
7486 /* We want to precalculate the motion list such that we know what column slots
7490 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
7492 /* First, identify all possible drop spots */
7494 tmp_list = g_list_last (tree_view->priv->columns);
7496 tmp_list = g_list_first (tree_view->priv->columns);
7500 cur_column = PSPP_SHEET_VIEW_COLUMN (tmp_list->data);
7501 tmp_list = rtl?g_list_previous (tmp_list):g_list_next (tmp_list);
7503 if (cur_column->visible == FALSE)
7506 /* If it's not the column moving and func tells us to skip over the column, we continue. */
7507 if (left_column != column && cur_column != column &&
7508 tree_view->priv->column_drop_func &&
7509 ! tree_view->priv->column_drop_func (tree_view, column, left_column, cur_column, tree_view->priv->column_drop_func_data))
7511 left_column = cur_column;
7514 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7515 reorder->left_column = left_column;
7516 left_column = reorder->right_column = cur_column;
7518 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7521 /* Add the last one */
7522 if (tree_view->priv->column_drop_func == NULL ||
7523 ((left_column != column) &&
7524 tree_view->priv->column_drop_func (tree_view, column, left_column, NULL, tree_view->priv->column_drop_func_data)))
7526 reorder = g_slice_new0 (PsppSheetViewColumnReorder);
7527 reorder->left_column = left_column;
7528 reorder->right_column = NULL;
7529 tree_view->priv->column_drag_info = g_list_append (tree_view->priv->column_drag_info, reorder);
7532 /* We quickly check to see if it even makes sense to reorder columns. */
7533 /* If there is nothing that can be moved, then we return */
7535 if (tree_view->priv->column_drag_info == NULL)
7538 /* We know there are always 2 slots possbile, as you can always return column. */
7539 /* If that's all there is, return */
7540 if (tree_view->priv->column_drag_info->next == NULL ||
7541 (tree_view->priv->column_drag_info->next->next == NULL &&
7542 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->data)->right_column == column &&
7543 ((PsppSheetViewColumnReorder *)tree_view->priv->column_drag_info->next->data)->left_column == column))
7545 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7546 g_slice_free (PsppSheetViewColumnReorder, tmp_list->data);
7547 g_list_free (tree_view->priv->column_drag_info);
7548 tree_view->priv->column_drag_info = NULL;
7551 /* We fill in the ranges for the columns, now that we've isolated them */
7552 left = - TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7554 for (tmp_list = tree_view->priv->column_drag_info; tmp_list; tmp_list = tmp_list->next)
7556 reorder = (PsppSheetViewColumnReorder *) tmp_list->data;
7558 reorder->left_align = left;
7559 if (tmp_list->next != NULL)
7561 g_assert (tmp_list->next->data);
7562 left = reorder->right_align = (reorder->right_column->allocation.x +
7563 reorder->right_column->allocation.width +
7564 ((PsppSheetViewColumnReorder *)tmp_list->next->data)->left_column->allocation.x)/2;
7570 gdk_drawable_get_size (tree_view->priv->header_window, &width, NULL);
7571 reorder->right_align = width + TREE_VIEW_COLUMN_DRAG_DEAD_MULTIPLIER (tree_view);
7577 _pspp_sheet_view_column_start_drag (PsppSheetView *tree_view,
7578 PsppSheetViewColumn *column)
7580 GdkEvent *send_event;
7581 GtkAllocation allocation;
7582 gint x, y, width, height;
7583 GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
7584 GdkDisplay *display = gdk_screen_get_display (screen);
7586 g_return_if_fail (tree_view->priv->column_drag_info == NULL);
7587 g_return_if_fail (tree_view->priv->cur_reorder == NULL);
7588 g_return_if_fail (column->button);
7590 pspp_sheet_view_set_column_drag_info (tree_view, column);
7592 if (tree_view->priv->column_drag_info == NULL)
7595 if (tree_view->priv->drag_window == NULL)
7597 GdkWindowAttr attributes;
7598 guint attributes_mask;
7600 attributes.window_type = GDK_WINDOW_CHILD;
7601 attributes.wclass = GDK_INPUT_OUTPUT;
7602 attributes.x = column->allocation.x;
7604 attributes.width = column->allocation.width;
7605 attributes.height = column->allocation.height;
7606 attributes.visual = gtk_widget_get_visual (GTK_WIDGET (tree_view));
7607 attributes.colormap = gtk_widget_get_colormap (GTK_WIDGET (tree_view));
7608 attributes.event_mask = GDK_VISIBILITY_NOTIFY_MASK | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK;
7609 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
7611 tree_view->priv->drag_window = gdk_window_new (tree_view->priv->bin_window,
7614 gdk_window_set_user_data (tree_view->priv->drag_window, GTK_WIDGET (tree_view));
7617 gdk_display_pointer_ungrab (display, GDK_CURRENT_TIME);
7618 gdk_display_keyboard_ungrab (display, GDK_CURRENT_TIME);
7620 gtk_grab_remove (column->button);
7622 send_event = gdk_event_new (GDK_LEAVE_NOTIFY);
7623 send_event->crossing.send_event = TRUE;
7624 send_event->crossing.window = g_object_ref (GTK_BUTTON (column->button)->event_window);
7625 send_event->crossing.subwindow = NULL;
7626 send_event->crossing.detail = GDK_NOTIFY_ANCESTOR;
7627 send_event->crossing.time = GDK_CURRENT_TIME;
7629 gtk_propagate_event (column->button, send_event);
7630 gdk_event_free (send_event);
7632 send_event = gdk_event_new (GDK_BUTTON_RELEASE);
7633 send_event->button.window = g_object_ref (gdk_screen_get_root_window (screen));
7634 send_event->button.send_event = TRUE;
7635 send_event->button.time = GDK_CURRENT_TIME;
7636 send_event->button.x = -1;
7637 send_event->button.y = -1;
7638 send_event->button.axes = NULL;
7639 send_event->button.state = 0;
7640 send_event->button.button = 1;
7641 send_event->button.device = gdk_display_get_core_pointer (display);
7642 send_event->button.x_root = 0;
7643 send_event->button.y_root = 0;
7645 gtk_propagate_event (column->button, send_event);
7646 gdk_event_free (send_event);
7648 /* Kids, don't try this at home */
7649 g_object_ref (column->button);
7650 gtk_container_remove (GTK_CONTAINER (tree_view), column->button);
7651 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7652 gtk_widget_set_parent (column->button, GTK_WIDGET (tree_view));
7653 g_object_unref (column->button);
7655 tree_view->priv->drag_column_x = column->allocation.x;
7656 allocation = column->allocation;
7658 gtk_widget_size_allocate (column->button, &allocation);
7659 gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
7661 tree_view->priv->drag_column = column;
7662 gdk_window_show (tree_view->priv->drag_window);
7664 gdk_window_get_origin (tree_view->priv->header_window, &x, &y);
7665 gdk_drawable_get_size (tree_view->priv->header_window, &width, &height);
7667 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7668 while (gtk_events_pending ())
7669 gtk_main_iteration ();
7671 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_IN_COLUMN_DRAG);
7672 gdk_pointer_grab (tree_view->priv->drag_window,
7674 GDK_POINTER_MOTION_MASK|GDK_BUTTON_RELEASE_MASK,
7675 NULL, NULL, GDK_CURRENT_TIME);
7676 gdk_keyboard_grab (tree_view->priv->drag_window,
7682 _pspp_sheet_view_queue_draw_node (PsppSheetView *tree_view,
7684 const GdkRectangle *clip_rect)
7688 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
7692 rect.width = MAX (tree_view->priv->width, GTK_WIDGET (tree_view)->allocation.width);
7694 rect.y = BACKGROUND_FIRST_PIXEL (tree_view, node);
7695 rect.height = ROW_HEIGHT (tree_view);
7699 GdkRectangle new_rect;
7701 gdk_rectangle_intersect (clip_rect, &rect, &new_rect);
7703 gdk_window_invalidate_rect (tree_view->priv->bin_window, &new_rect, TRUE);
7707 gdk_window_invalidate_rect (tree_view->priv->bin_window, &rect, TRUE);
7712 pspp_sheet_view_queue_draw_path (PsppSheetView *tree_view,
7714 const GdkRectangle *clip_rect)
7718 _pspp_sheet_view_find_node (tree_view, path, &node);
7721 _pspp_sheet_view_queue_draw_node (tree_view, node, clip_rect);
7725 pspp_sheet_view_focus_to_cursor (PsppSheetView *tree_view)
7728 GtkTreePath *cursor_path;
7730 if ((tree_view->priv->row_count == 0) ||
7731 (! gtk_widget_get_realized (GTK_WIDGET (tree_view))))
7735 if (tree_view->priv->cursor)
7736 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7738 if (cursor_path == NULL)
7740 /* There's no cursor. Move the cursor to the first selected row, if any
7741 * are selected, otherwise to the first row in the sheetview.
7743 GList *selected_rows;
7744 GtkTreeModel *model;
7745 PsppSheetSelection *selection;
7747 selection = pspp_sheet_view_get_selection (tree_view);
7748 selected_rows = pspp_sheet_selection_get_selected_rows (selection, &model);
7752 /* XXX we could avoid doing O(n) work to get this result */
7753 cursor_path = gtk_tree_path_copy((const GtkTreePath *)(selected_rows->data));
7754 g_list_foreach (selected_rows, (GFunc)gtk_tree_path_free, NULL);
7755 g_list_free (selected_rows);
7759 cursor_path = gtk_tree_path_new_first ();
7760 search_first_focusable_path (tree_view, &cursor_path,
7764 gtk_tree_row_reference_free (tree_view->priv->cursor);
7765 tree_view->priv->cursor = NULL;
7769 if (tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7770 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE)
7771 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, FALSE, FALSE);
7773 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE);
7779 /* Now find a column for the cursor. */
7780 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
7782 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
7783 gtk_tree_path_free (cursor_path);
7785 if (tree_view->priv->focus_column == NULL)
7788 for (list = tree_view->priv->columns; list; list = list->next)
7790 if (PSPP_SHEET_VIEW_COLUMN (list->data)->visible)
7792 tree_view->priv->focus_column = PSPP_SHEET_VIEW_COLUMN (list->data);
7793 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
7794 pspp_sheet_selection_select_column (tree_view->priv->selection, tree_view->priv->focus_column);
7804 pspp_sheet_view_move_cursor_up_down (PsppSheetView *tree_view,
7807 gint selection_count;
7808 int cursor_node = -1;
7809 int new_cursor_node = -1;
7810 GtkTreePath *cursor_path = NULL;
7811 gboolean grab_focus = TRUE;
7813 if (! gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7817 if (!gtk_tree_row_reference_valid (tree_view->priv->cursor))
7818 /* FIXME: we lost the cursor; should we get the first? */
7821 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7822 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
7824 if (cursor_node < 0)
7825 /* FIXME: we lost the cursor; should we get the first? */
7828 selection_count = pspp_sheet_selection_count_selected_rows (tree_view->priv->selection);
7830 if (selection_count == 0
7831 && tree_view->priv->selection->type != PSPP_SHEET_SELECTION_NONE
7832 && !tree_view->priv->ctrl_pressed)
7834 /* Don't move the cursor, but just select the current node */
7835 new_cursor_node = cursor_node;
7840 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
7842 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7845 gtk_tree_path_free (cursor_path);
7847 if (new_cursor_node)
7849 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
7851 search_first_focusable_path (tree_view, &cursor_path,
7856 gtk_tree_path_free (cursor_path);
7860 * If the list has only one item and multi-selection is set then select
7861 * the row (if not yet selected).
7863 if ((tree_view->priv->selection->type == PSPP_SHEET_SELECTION_MULTIPLE ||
7864 tree_view->priv->selection->type == PSPP_SHEET_SELECTION_RECTANGLE) &&
7865 new_cursor_node < 0)
7868 new_cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7870 new_cursor_node = pspp_sheet_view_node_prev (tree_view, cursor_node);
7872 if (new_cursor_node < 0
7873 && !pspp_sheet_view_node_is_selected (tree_view, cursor_node))
7875 new_cursor_node = cursor_node;
7879 new_cursor_node = -1;
7883 if (new_cursor_node >= 0)
7885 cursor_path = _pspp_sheet_view_find_path (tree_view, new_cursor_node);
7886 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, TRUE);
7887 gtk_tree_path_free (cursor_path);
7891 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
7893 if (!tree_view->priv->shift_pressed)
7895 if (! gtk_widget_keynav_failed (GTK_WIDGET (tree_view),
7897 GTK_DIR_UP : GTK_DIR_DOWN))
7899 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
7902 gtk_widget_child_focus (toplevel,
7904 GTK_DIR_TAB_BACKWARD :
7905 GTK_DIR_TAB_FORWARD);
7912 gtk_widget_error_bell (GTK_WIDGET (tree_view));
7917 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
7921 pspp_sheet_view_move_cursor_page_up_down (PsppSheetView *tree_view,
7924 int cursor_node = -1;
7925 GtkTreePath *old_cursor_path = NULL;
7926 GtkTreePath *cursor_path = NULL;
7927 int start_cursor_node = -1;
7930 gint vertical_separator;
7932 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
7935 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
7936 old_cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
7938 /* This is sorta weird. Focus in should give us a cursor */
7941 gtk_widget_style_get (GTK_WIDGET (tree_view), "vertical-separator", &vertical_separator, NULL);
7942 _pspp_sheet_view_find_node (tree_view, old_cursor_path, &cursor_node);
7944 if (cursor_node < 0)
7946 /* FIXME: we lost the cursor. Should we try to get one? */
7947 gtk_tree_path_free (old_cursor_path);
7951 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
7952 window_y = RBTREE_Y_TO_TREE_WINDOW_Y (tree_view, y);
7953 y += tree_view->priv->cursor_offset;
7954 y += count * (int)tree_view->priv->vadjustment->page_increment;
7955 y = CLAMP (y, (gint)tree_view->priv->vadjustment->lower, (gint)tree_view->priv->vadjustment->upper - vertical_separator);
7957 if (y >= tree_view->priv->height)
7958 y = tree_view->priv->height - 1;
7960 tree_view->priv->cursor_offset =
7961 pspp_sheet_view_find_offset (tree_view, y, &cursor_node);
7963 if (tree_view->priv->cursor_offset > BACKGROUND_HEIGHT (tree_view))
7965 cursor_node = pspp_sheet_view_node_next (tree_view, cursor_node);
7966 tree_view->priv->cursor_offset -= BACKGROUND_HEIGHT (tree_view);
7969 y -= tree_view->priv->cursor_offset;
7970 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
7972 start_cursor_node = cursor_node;
7974 if (! search_first_focusable_path (tree_view, &cursor_path,
7978 /* It looks like we reached the end of the view without finding
7979 * a focusable row. We will step backwards to find the last
7982 cursor_node = start_cursor_node;
7983 cursor_path = _pspp_sheet_view_find_path (tree_view, cursor_node);
7985 search_first_focusable_path (tree_view, &cursor_path,
7994 y = pspp_sheet_view_node_find_offset (tree_view, cursor_node);
7996 pspp_sheet_view_real_set_cursor (tree_view, cursor_path, TRUE, FALSE);
7999 pspp_sheet_view_scroll_to_point (tree_view, -1, y);
8000 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8001 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8003 if (!gtk_tree_path_compare (old_cursor_path, cursor_path))
8004 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8006 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8009 gtk_tree_path_free (old_cursor_path);
8010 gtk_tree_path_free (cursor_path);
8014 pspp_sheet_view_move_cursor_left_right (PsppSheetView *tree_view,
8017 int cursor_node = -1;
8018 GtkTreePath *cursor_path = NULL;
8019 PsppSheetViewColumn *column;
8022 gboolean found_column = FALSE;
8025 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8027 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8030 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
8031 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8035 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8036 if (cursor_node < 0)
8038 if (gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path) == FALSE)
8040 gtk_tree_path_free (cursor_path);
8043 gtk_tree_path_free (cursor_path);
8045 list = rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns);
8046 if (tree_view->priv->focus_column)
8048 for (; list; list = (rtl ? list->prev : list->next))
8050 if (list->data == tree_view->priv->focus_column)
8057 gboolean left, right;
8059 column = list->data;
8060 if (column->visible == FALSE || column->row_head)
8063 pspp_sheet_view_column_cell_set_cell_data (column,
8064 tree_view->priv->model,
8069 right = list->prev ? TRUE : FALSE;
8070 left = list->next ? TRUE : FALSE;
8074 left = list->prev ? TRUE : FALSE;
8075 right = list->next ? TRUE : FALSE;
8078 if (_pspp_sheet_view_column_cell_focus (column, count, left, right))
8080 tree_view->priv->focus_column = column;
8081 found_column = TRUE;
8086 list = rtl ? list->prev : list->next;
8088 list = rtl ? list->next : list->prev;
8093 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8094 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
8095 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8099 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8102 pspp_sheet_view_clamp_column_visible (tree_view,
8103 tree_view->priv->focus_column, TRUE);
8107 pspp_sheet_view_move_cursor_start_end (PsppSheetView *tree_view,
8112 GtkTreePath *old_path;
8114 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8117 g_return_if_fail (tree_view->priv->row_count > 0);
8119 pspp_sheet_view_get_cursor (tree_view, &old_path, NULL);
8123 /* Now go forward to find the first focusable row. */
8124 path = _pspp_sheet_view_find_path (tree_view, 0);
8125 search_first_focusable_path (tree_view, &path,
8126 TRUE, &cursor_node);
8130 /* Now go backwards to find last focusable row. */
8131 path = _pspp_sheet_view_find_path (tree_view, tree_view->priv->row_count - 1);
8132 search_first_focusable_path (tree_view, &path,
8133 FALSE, &cursor_node);
8139 if (gtk_tree_path_compare (old_path, path))
8141 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE);
8142 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8146 gtk_widget_error_bell (GTK_WIDGET (tree_view));
8150 gtk_tree_path_free (old_path);
8151 gtk_tree_path_free (path);
8155 pspp_sheet_view_real_select_all (PsppSheetView *tree_view)
8157 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8160 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8161 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8164 pspp_sheet_selection_select_all (tree_view->priv->selection);
8170 pspp_sheet_view_real_unselect_all (PsppSheetView *tree_view)
8172 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8175 if (tree_view->priv->selection->type != PSPP_SHEET_SELECTION_MULTIPLE &&
8176 tree_view->priv->selection->type != PSPP_SHEET_SELECTION_RECTANGLE)
8179 pspp_sheet_selection_unselect_all (tree_view->priv->selection);
8185 pspp_sheet_view_real_select_cursor_row (PsppSheetView *tree_view,
8186 gboolean start_editing)
8189 int cursor_node = -1;
8190 GtkTreePath *cursor_path = NULL;
8191 GtkTreeSelectMode mode = 0;
8193 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8196 if (tree_view->priv->cursor)
8197 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8199 if (cursor_path == NULL)
8202 _pspp_sheet_view_find_node (tree_view, cursor_path,
8205 if (cursor_node < 0)
8207 gtk_tree_path_free (cursor_path);
8211 if (!tree_view->priv->shift_pressed && start_editing &&
8212 tree_view->priv->focus_column)
8214 if (pspp_sheet_view_start_editing (tree_view, cursor_path))
8216 gtk_tree_path_free (cursor_path);
8221 if (tree_view->priv->ctrl_pressed)
8222 mode |= GTK_TREE_SELECT_MODE_TOGGLE;
8223 if (tree_view->priv->shift_pressed)
8224 mode |= GTK_TREE_SELECT_MODE_EXTEND;
8226 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8232 /* We bail out if the original (tree, node) don't exist anymore after
8233 * handling the selection-changed callback. We do return TRUE because
8234 * the key press has been handled at this point.
8236 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8238 if (cursor_node != new_node)
8241 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8243 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8244 _pspp_sheet_view_queue_draw_node (tree_view, cursor_node, NULL);
8246 if (!tree_view->priv->shift_pressed)
8247 pspp_sheet_view_row_activated (tree_view, cursor_path,
8248 tree_view->priv->focus_column);
8250 gtk_tree_path_free (cursor_path);
8256 pspp_sheet_view_real_toggle_cursor_row (PsppSheetView *tree_view)
8259 int cursor_node = -1;
8260 GtkTreePath *cursor_path = NULL;
8262 if (!gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8266 if (tree_view->priv->cursor)
8267 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
8269 if (cursor_path == NULL)
8272 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
8273 if (cursor_node < 0)
8275 gtk_tree_path_free (cursor_path);
8279 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
8282 GTK_TREE_SELECT_MODE_TOGGLE,
8285 /* We bail out if the original (tree, node) don't exist anymore after
8286 * handling the selection-changed callback. We do return TRUE because
8287 * the key press has been handled at this point.
8289 _pspp_sheet_view_find_node (tree_view, cursor_path, &new_node);
8291 if (cursor_node != new_node)
8294 pspp_sheet_view_clamp_node_visible (tree_view, cursor_node);
8296 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
8297 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
8298 gtk_tree_path_free (cursor_path);
8304 pspp_sheet_view_search_entry_flush_timeout (PsppSheetView *tree_view)
8306 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window, tree_view);
8307 tree_view->priv->typeselect_flush_timeout = 0;
8312 /* Cut and paste from gtkwindow.c */
8314 send_focus_change (GtkWidget *widget,
8317 GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
8319 g_object_ref (widget);
8322 GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS);
8324 GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS);
8326 fevent->focus_change.type = GDK_FOCUS_CHANGE;
8327 fevent->focus_change.window = g_object_ref (widget->window);
8328 fevent->focus_change.in = in;
8330 gtk_widget_event (widget, fevent);
8332 g_object_notify (G_OBJECT (widget), "has-focus");
8334 g_object_unref (widget);
8335 gdk_event_free (fevent);
8339 pspp_sheet_view_ensure_interactive_directory (PsppSheetView *tree_view)
8341 GtkWidget *frame, *vbox, *toplevel;
8344 if (tree_view->priv->search_custom_entry_set)
8347 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (tree_view));
8348 screen = gtk_widget_get_screen (GTK_WIDGET (tree_view));
8350 if (tree_view->priv->search_window != NULL)
8352 if (GTK_WINDOW (toplevel)->group)
8353 gtk_window_group_add_window (GTK_WINDOW (toplevel)->group,
8354 GTK_WINDOW (tree_view->priv->search_window));
8355 else if (GTK_WINDOW (tree_view->priv->search_window)->group)
8356 gtk_window_group_remove_window (GTK_WINDOW (tree_view->priv->search_window)->group,
8357 GTK_WINDOW (tree_view->priv->search_window));
8358 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8362 tree_view->priv->search_window = gtk_window_new (GTK_WINDOW_POPUP);
8363 gtk_window_set_screen (GTK_WINDOW (tree_view->priv->search_window), screen);
8365 if (GTK_WINDOW (toplevel)->group)
8366 gtk_window_group_add_window (GTK_WINDOW (toplevel)->group,
8367 GTK_WINDOW (tree_view->priv->search_window));
8369 gtk_window_set_type_hint (GTK_WINDOW (tree_view->priv->search_window),
8370 GDK_WINDOW_TYPE_HINT_UTILITY);
8371 gtk_window_set_modal (GTK_WINDOW (tree_view->priv->search_window), TRUE);
8372 g_signal_connect (tree_view->priv->search_window, "delete-event",
8373 G_CALLBACK (pspp_sheet_view_search_delete_event),
8375 g_signal_connect (tree_view->priv->search_window, "key-press-event",
8376 G_CALLBACK (pspp_sheet_view_search_key_press_event),
8378 g_signal_connect (tree_view->priv->search_window, "button-press-event",
8379 G_CALLBACK (pspp_sheet_view_search_button_press_event),
8381 g_signal_connect (tree_view->priv->search_window, "scroll-event",
8382 G_CALLBACK (pspp_sheet_view_search_scroll_event),
8385 frame = gtk_frame_new (NULL);
8386 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
8387 gtk_widget_show (frame);
8388 gtk_container_add (GTK_CONTAINER (tree_view->priv->search_window), frame);
8390 vbox = gtk_vbox_new (FALSE, 0);
8391 gtk_widget_show (vbox);
8392 gtk_container_add (GTK_CONTAINER (frame), vbox);
8393 gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
8396 tree_view->priv->search_entry = gtk_entry_new ();
8397 gtk_widget_show (tree_view->priv->search_entry);
8398 g_signal_connect (tree_view->priv->search_entry, "populate-popup",
8399 G_CALLBACK (pspp_sheet_view_search_disable_popdown),
8401 g_signal_connect (tree_view->priv->search_entry,
8402 "activate", G_CALLBACK (pspp_sheet_view_search_activate),
8404 g_signal_connect (GTK_ENTRY (tree_view->priv->search_entry)->im_context,
8406 G_CALLBACK (pspp_sheet_view_search_preedit_changed),
8408 gtk_container_add (GTK_CONTAINER (vbox),
8409 tree_view->priv->search_entry);
8411 gtk_widget_realize (tree_view->priv->search_entry);
8414 /* Pops up the interactive search entry. If keybinding is TRUE then the user
8415 * started this by typing the start_interactive_search keybinding. Otherwise, it came from
8418 pspp_sheet_view_real_start_interactive_search (PsppSheetView *tree_view,
8419 gboolean keybinding)
8421 /* We only start interactive search if we have focus or the columns
8422 * have focus. If one of our children have focus, we don't want to
8426 gboolean found_focus = FALSE;
8427 GtkWidgetClass *entry_parent_class;
8429 if (!tree_view->priv->enable_search && !keybinding)
8432 if (tree_view->priv->search_custom_entry_set)
8435 if (tree_view->priv->search_window != NULL &&
8436 gtk_widget_get_visible (tree_view->priv->search_window))
8439 for (list = tree_view->priv->columns; list; list = list->next)
8441 PsppSheetViewColumn *column;
8443 column = list->data;
8444 if (! column->visible)
8447 if (column->button && gtk_widget_has_focus (column->button))
8454 if (gtk_widget_has_focus (GTK_WIDGET (tree_view)))
8460 if (tree_view->priv->search_column < 0)
8463 pspp_sheet_view_ensure_interactive_directory (tree_view);
8466 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
8469 tree_view->priv->search_position_func (tree_view, tree_view->priv->search_window, tree_view->priv->search_position_user_data);
8470 gtk_widget_show (tree_view->priv->search_window);
8471 if (tree_view->priv->search_entry_changed_id == 0)
8473 tree_view->priv->search_entry_changed_id =
8474 g_signal_connect (tree_view->priv->search_entry, "changed",
8475 G_CALLBACK (pspp_sheet_view_search_init),
8479 tree_view->priv->typeselect_flush_timeout =
8480 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
8481 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
8484 /* Grab focus will select all the text. We don't want that to happen, so we
8485 * call the parent instance and bypass the selection change. This is probably
8486 * really non-kosher. */
8487 entry_parent_class = g_type_class_peek_parent (GTK_ENTRY_GET_CLASS (tree_view->priv->search_entry));
8488 (entry_parent_class->grab_focus) (tree_view->priv->search_entry);
8490 /* send focus-in event */
8491 send_focus_change (tree_view->priv->search_entry, TRUE);
8493 /* search first matching iter */
8494 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
8500 pspp_sheet_view_start_interactive_search (PsppSheetView *tree_view)
8502 return pspp_sheet_view_real_start_interactive_search (tree_view, TRUE);
8505 /* this function returns the new width of the column being resized given
8506 * the column and x position of the cursor; the x cursor position is passed
8507 * in as a pointer and automagicly corrected if it's beyond min/max limits
8510 pspp_sheet_view_new_column_width (PsppSheetView *tree_view,
8514 PsppSheetViewColumn *column;
8518 /* first translate the x position from widget->window
8519 * to clist->clist_window
8521 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
8522 column = g_list_nth (tree_view->priv->columns, i)->data;
8523 width = rtl ? (column->allocation.x + column->allocation.width - *x) : (*x - column->allocation.x);
8525 /* Clamp down the value */
8526 if (column->min_width == -1)
8527 width = MAX (column->button_request, width);
8529 width = MAX (column->min_width, width);
8530 if (column->max_width != -1)
8531 width = MIN (width, column->max_width);
8533 *x = rtl ? (column->allocation.x + column->allocation.width - width) : (column->allocation.x + width);
8539 /* FIXME this adjust_allocation is a big cut-and-paste from
8540 * GtkCList, needs to be some "official" way to do this
8550 /* The window to which widget->window is relative */
8551 #define ALLOCATION_WINDOW(widget) \
8552 (!gtk_widget_get_has_window (widget) ? \
8553 (widget)->window : \
8554 gdk_window_get_parent ((widget)->window))
8557 adjust_allocation_recurse (GtkWidget *widget,
8560 ScrollData *scroll_data = data;
8562 /* Need to really size allocate instead of just poking
8563 * into widget->allocation if the widget is not realized.
8564 * FIXME someone figure out why this was.
8566 if (!gtk_widget_get_realized (widget))
8568 if (gtk_widget_get_visible (widget))
8570 GdkRectangle tmp_rectangle = widget->allocation;
8571 tmp_rectangle.x += scroll_data->dx;
8572 tmp_rectangle.y += scroll_data->dy;
8574 gtk_widget_size_allocate (widget, &tmp_rectangle);
8579 if (ALLOCATION_WINDOW (widget) == scroll_data->window)
8581 widget->allocation.x += scroll_data->dx;
8582 widget->allocation.y += scroll_data->dy;
8584 if (GTK_IS_CONTAINER (widget))
8585 gtk_container_forall (GTK_CONTAINER (widget),
8586 adjust_allocation_recurse,
8593 adjust_allocation (GtkWidget *widget,
8597 ScrollData scroll_data;
8599 if (gtk_widget_get_realized (widget))
8600 scroll_data.window = ALLOCATION_WINDOW (widget);
8602 scroll_data.window = NULL;
8604 scroll_data.dx = dx;
8605 scroll_data.dy = dy;
8607 adjust_allocation_recurse (widget, &scroll_data);
8611 pspp_sheet_view_column_update_button (PsppSheetViewColumn *tree_column);
8615 pspp_sheet_view_adjustment_changed (GtkAdjustment *adjustment,
8616 PsppSheetView *tree_view)
8618 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
8623 gdk_window_move (tree_view->priv->bin_window,
8624 - tree_view->priv->hadjustment->value,
8625 TREE_VIEW_HEADER_HEIGHT (tree_view));
8626 gdk_window_move (tree_view->priv->header_window,
8627 - tree_view->priv->hadjustment->value,
8629 dy = tree_view->priv->dy - (int) tree_view->priv->vadjustment->value;
8632 update_prelight (tree_view,
8633 tree_view->priv->event_last_x,
8634 tree_view->priv->event_last_y - dy);
8636 if (tree_view->priv->edited_column &&
8637 GTK_IS_WIDGET (tree_view->priv->edited_column->editable_widget))
8641 PsppSheetViewChild *child = NULL;
8643 widget = GTK_WIDGET (tree_view->priv->edited_column->editable_widget);
8644 adjust_allocation (widget, 0, dy);
8646 for (list = tree_view->priv->children; list; list = list->next)
8648 child = (PsppSheetViewChild *)list->data;
8649 if (child->widget == widget)
8657 gdk_window_scroll (tree_view->priv->bin_window, 0, dy);
8659 if (tree_view->priv->dy != (int) tree_view->priv->vadjustment->value)
8661 /* update our dy and top_row */
8662 tree_view->priv->dy = (int) tree_view->priv->vadjustment->value;
8664 if (!tree_view->priv->in_top_row_to_dy)
8665 pspp_sheet_view_dy_to_top_row (tree_view);
8668 for (list = tree_view->priv->columns; list; list = list->next)
8670 PsppSheetViewColumn *column = list->data;
8671 GtkAllocation *allocation = &column->allocation;
8673 if (span_intersects (allocation->x, allocation->width,
8674 tree_view->priv->hadjustment->value,
8675 GTK_WIDGET (tree_view)->allocation.width))
8677 pspp_sheet_view_column_set_need_button (column, TRUE);
8678 if (!column->button)
8679 pspp_sheet_view_column_update_button (column);
8691 * pspp_sheet_view_new:
8693 * Creates a new #PsppSheetView widget.
8695 * Return value: A newly created #PsppSheetView widget.
8698 pspp_sheet_view_new (void)
8700 return g_object_new (PSPP_TYPE_SHEET_VIEW, NULL);
8704 * pspp_sheet_view_new_with_model:
8705 * @model: the model.
8707 * Creates a new #PsppSheetView widget with the model initialized to @model.
8709 * Return value: A newly created #PsppSheetView widget.
8712 pspp_sheet_view_new_with_model (GtkTreeModel *model)
8714 return g_object_new (PSPP_TYPE_SHEET_VIEW, "model", model, NULL);
8721 * pspp_sheet_view_get_model:
8722 * @tree_view: a #PsppSheetView
8724 * Returns the model the #PsppSheetView is based on. Returns %NULL if the
8727 * Return value: A #GtkTreeModel, or %NULL if none is currently being used.
8730 pspp_sheet_view_get_model (PsppSheetView *tree_view)
8732 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
8734 return tree_view->priv->model;
8738 * pspp_sheet_view_set_model:
8739 * @tree_view: A #GtkTreeNode.
8740 * @model: (allow-none): The model.
8742 * Sets the model for a #PsppSheetView. If the @tree_view already has a model
8743 * set, it will remove it before setting the new model. If @model is %NULL,
8744 * then it will unset the old model.
8747 pspp_sheet_view_set_model (PsppSheetView *tree_view,
8748 GtkTreeModel *model)
8750 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8751 g_return_if_fail (model == NULL || GTK_IS_TREE_MODEL (model));
8753 if (model == tree_view->priv->model)
8756 if (tree_view->priv->scroll_to_path)
8758 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
8759 tree_view->priv->scroll_to_path = NULL;
8762 if (tree_view->priv->model)
8764 GList *tmplist = tree_view->priv->columns;
8766 if (tree_view->priv->selected)
8767 range_tower_set0 (tree_view->priv->selected, 0, ULONG_MAX);
8768 pspp_sheet_view_stop_editing (tree_view, TRUE);
8770 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
8771 pspp_sheet_view_row_changed,
8773 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
8774 pspp_sheet_view_row_inserted,
8776 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
8777 pspp_sheet_view_row_deleted,
8779 g_signal_handlers_disconnect_by_func (tree_view->priv->model,
8780 pspp_sheet_view_rows_reordered,
8783 for (; tmplist; tmplist = tmplist->next)
8784 _pspp_sheet_view_column_unset_model (tmplist->data,
8785 tree_view->priv->model);
8787 tree_view->priv->prelight_node = -1;
8789 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
8790 tree_view->priv->drag_dest_row = NULL;
8791 gtk_tree_row_reference_free (tree_view->priv->cursor);
8792 tree_view->priv->cursor = NULL;
8793 gtk_tree_row_reference_free (tree_view->priv->anchor);
8794 tree_view->priv->anchor = NULL;
8795 gtk_tree_row_reference_free (tree_view->priv->top_row);
8796 tree_view->priv->top_row = NULL;
8797 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
8798 tree_view->priv->scroll_to_path = NULL;
8800 tree_view->priv->scroll_to_column = NULL;
8802 g_object_unref (tree_view->priv->model);
8804 tree_view->priv->search_column = -1;
8805 tree_view->priv->fixed_height = -1;
8806 tree_view->priv->dy = tree_view->priv->top_row_dy = 0;
8807 tree_view->priv->last_button_x = -1;
8808 tree_view->priv->last_button_y = -1;
8811 tree_view->priv->model = model;
8813 if (tree_view->priv->model)
8816 GtkTreeModelFlags flags;
8818 if (tree_view->priv->search_column == -1)
8820 for (i = 0; i < gtk_tree_model_get_n_columns (model); i++)
8822 GType type = gtk_tree_model_get_column_type (model, i);
8824 if (g_value_type_transformable (type, G_TYPE_STRING))
8826 tree_view->priv->search_column = i;
8832 g_object_ref (tree_view->priv->model);
8833 g_signal_connect (tree_view->priv->model,
8835 G_CALLBACK (pspp_sheet_view_row_changed),
8837 g_signal_connect (tree_view->priv->model,
8839 G_CALLBACK (pspp_sheet_view_row_inserted),
8841 g_signal_connect (tree_view->priv->model,
8843 G_CALLBACK (pspp_sheet_view_row_deleted),
8845 g_signal_connect (tree_view->priv->model,
8847 G_CALLBACK (pspp_sheet_view_rows_reordered),
8850 flags = gtk_tree_model_get_flags (tree_view->priv->model);
8852 tree_view->priv->row_count = gtk_tree_model_iter_n_children (tree_view->priv->model, NULL);
8854 /* FIXME: do I need to do this? pspp_sheet_view_create_buttons (tree_view); */
8855 install_presize_handler (tree_view);
8858 g_object_notify (G_OBJECT (tree_view), "model");
8860 if (tree_view->priv->selection)
8861 _pspp_sheet_selection_emit_changed (tree_view->priv->selection);
8863 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
8864 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
8868 * pspp_sheet_view_get_selection:
8869 * @tree_view: A #PsppSheetView.
8871 * Gets the #PsppSheetSelection associated with @tree_view.
8873 * Return value: A #PsppSheetSelection object.
8875 PsppSheetSelection *
8876 pspp_sheet_view_get_selection (PsppSheetView *tree_view)
8878 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
8880 return tree_view->priv->selection;
8884 * pspp_sheet_view_get_hadjustment:
8885 * @tree_view: A #PsppSheetView
8887 * Gets the #GtkAdjustment currently being used for the horizontal aspect.
8889 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
8893 pspp_sheet_view_get_hadjustment (PsppSheetView *tree_view)
8895 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
8897 if (tree_view->priv->hadjustment == NULL)
8898 pspp_sheet_view_set_hadjustment (tree_view, NULL);
8900 return tree_view->priv->hadjustment;
8904 * pspp_sheet_view_set_hadjustment:
8905 * @tree_view: A #PsppSheetView
8906 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
8908 * Sets the #GtkAdjustment for the current horizontal aspect.
8911 pspp_sheet_view_set_hadjustment (PsppSheetView *tree_view,
8912 GtkAdjustment *adjustment)
8914 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8916 pspp_sheet_view_set_adjustments (tree_view,
8918 tree_view->priv->vadjustment);
8920 g_object_notify (G_OBJECT (tree_view), "hadjustment");
8924 * pspp_sheet_view_get_vadjustment:
8925 * @tree_view: A #PsppSheetView
8927 * Gets the #GtkAdjustment currently being used for the vertical aspect.
8929 * Return value: A #GtkAdjustment object, or %NULL if none is currently being
8933 pspp_sheet_view_get_vadjustment (PsppSheetView *tree_view)
8935 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
8937 if (tree_view->priv->vadjustment == NULL)
8938 pspp_sheet_view_set_vadjustment (tree_view, NULL);
8940 return tree_view->priv->vadjustment;
8944 * pspp_sheet_view_set_vadjustment:
8945 * @tree_view: A #PsppSheetView
8946 * @adjustment: (allow-none): The #GtkAdjustment to set, or %NULL
8948 * Sets the #GtkAdjustment for the current vertical aspect.
8951 pspp_sheet_view_set_vadjustment (PsppSheetView *tree_view,
8952 GtkAdjustment *adjustment)
8954 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8956 pspp_sheet_view_set_adjustments (tree_view,
8957 tree_view->priv->hadjustment,
8960 g_object_notify (G_OBJECT (tree_view), "vadjustment");
8963 /* Column and header operations */
8966 * pspp_sheet_view_get_headers_visible:
8967 * @tree_view: A #PsppSheetView.
8969 * Returns %TRUE if the headers on the @tree_view are visible.
8971 * Return value: Whether the headers are visible or not.
8974 pspp_sheet_view_get_headers_visible (PsppSheetView *tree_view)
8976 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
8978 return PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
8982 * pspp_sheet_view_set_headers_visible:
8983 * @tree_view: A #PsppSheetView.
8984 * @headers_visible: %TRUE if the headers are visible
8986 * Sets the visibility state of the headers.
8989 pspp_sheet_view_set_headers_visible (PsppSheetView *tree_view,
8990 gboolean headers_visible)
8994 PsppSheetViewColumn *column;
8996 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
8998 headers_visible = !! headers_visible;
9000 if (PSPP_SHEET_VIEW_FLAG_SET (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE) == headers_visible)
9003 if (headers_visible)
9004 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9006 PSPP_SHEET_VIEW_UNSET_FLAG (tree_view, PSPP_SHEET_VIEW_HEADERS_VISIBLE);
9008 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9010 gdk_window_get_position (tree_view->priv->bin_window, &x, &y);
9011 if (headers_visible)
9013 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));
9015 if (gtk_widget_get_mapped (GTK_WIDGET (tree_view)))
9016 pspp_sheet_view_map_buttons (tree_view);
9020 gdk_window_move_resize (tree_view->priv->bin_window, x, y, tree_view->priv->width, tree_view->priv->height);
9022 for (list = tree_view->priv->columns; list; list = list->next)
9024 column = list->data;
9026 gtk_widget_unmap (column->button);
9028 gdk_window_hide (tree_view->priv->header_window);
9032 tree_view->priv->vadjustment->page_size = GTK_WIDGET (tree_view)->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
9033 tree_view->priv->vadjustment->page_increment = (GTK_WIDGET (tree_view)->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view)) / 2;
9034 tree_view->priv->vadjustment->lower = 0;
9035 tree_view->priv->vadjustment->upper = tree_view->priv->height;
9036 gtk_adjustment_changed (tree_view->priv->vadjustment);
9038 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9040 g_object_notify (G_OBJECT (tree_view), "headers-visible");
9044 * pspp_sheet_view_columns_autosize:
9045 * @tree_view: A #PsppSheetView.
9047 * Resizes all columns to their optimal width. Only works after the
9048 * treeview has been realized.
9051 pspp_sheet_view_columns_autosize (PsppSheetView *tree_view)
9053 gboolean dirty = FALSE;
9055 PsppSheetViewColumn *column;
9057 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9059 for (list = tree_view->priv->columns; list; list = list->next)
9061 column = list->data;
9062 _pspp_sheet_view_column_cell_set_dirty (column);
9067 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9071 * pspp_sheet_view_set_headers_clickable:
9072 * @tree_view: A #PsppSheetView.
9073 * @setting: %TRUE if the columns are clickable.
9075 * Allow the column title buttons to be clicked.
9078 pspp_sheet_view_set_headers_clickable (PsppSheetView *tree_view,
9083 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9085 for (list = tree_view->priv->columns; list; list = list->next)
9086 pspp_sheet_view_column_set_clickable (PSPP_SHEET_VIEW_COLUMN (list->data), setting);
9088 g_object_notify (G_OBJECT (tree_view), "headers-clickable");
9093 * pspp_sheet_view_get_headers_clickable:
9094 * @tree_view: A #PsppSheetView.
9096 * Returns whether all header columns are clickable.
9098 * Return value: %TRUE if all header columns are clickable, otherwise %FALSE
9103 pspp_sheet_view_get_headers_clickable (PsppSheetView *tree_view)
9107 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9109 for (list = tree_view->priv->columns; list; list = list->next)
9110 if (!PSPP_SHEET_VIEW_COLUMN (list->data)->clickable)
9117 * pspp_sheet_view_set_rules_hint
9118 * @tree_view: a #PsppSheetView
9119 * @setting: %TRUE if the tree requires reading across rows
9121 * This function tells GTK+ that the user interface for your
9122 * application requires users to read across tree rows and associate
9123 * cells with one another. By default, GTK+ will then render the tree
9124 * with alternating row colors. Do <emphasis>not</emphasis> use it
9125 * just because you prefer the appearance of the ruled tree; that's a
9126 * question for the theme. Some themes will draw tree rows in
9127 * alternating colors even when rules are turned off, and users who
9128 * prefer that appearance all the time can choose those themes. You
9129 * should call this function only as a <emphasis>semantic</emphasis>
9130 * hint to the theme engine that your tree makes alternating colors
9131 * useful from a functional standpoint (since it has lots of columns,
9136 pspp_sheet_view_set_rules_hint (PsppSheetView *tree_view,
9139 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9141 setting = setting != FALSE;
9143 if (tree_view->priv->has_rules != setting)
9145 tree_view->priv->has_rules = setting;
9146 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
9149 g_object_notify (G_OBJECT (tree_view), "rules-hint");
9153 * pspp_sheet_view_get_rules_hint
9154 * @tree_view: a #PsppSheetView
9156 * Gets the setting set by pspp_sheet_view_set_rules_hint().
9158 * Return value: %TRUE if rules are useful for the user of this tree
9161 pspp_sheet_view_get_rules_hint (PsppSheetView *tree_view)
9163 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9165 return tree_view->priv->has_rules;
9168 /* Public Column functions
9172 * pspp_sheet_view_append_column:
9173 * @tree_view: A #PsppSheetView.
9174 * @column: The #PsppSheetViewColumn to add.
9176 * Appends @column to the list of columns.
9178 * Return value: The number of columns in @tree_view after appending.
9181 pspp_sheet_view_append_column (PsppSheetView *tree_view,
9182 PsppSheetViewColumn *column)
9184 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9185 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9186 g_return_val_if_fail (column->tree_view == NULL, -1);
9188 return pspp_sheet_view_insert_column (tree_view, column, -1);
9193 * pspp_sheet_view_remove_column:
9194 * @tree_view: A #PsppSheetView.
9195 * @column: The #PsppSheetViewColumn to remove.
9197 * Removes @column from @tree_view.
9199 * Return value: The number of columns in @tree_view after removing.
9202 pspp_sheet_view_remove_column (PsppSheetView *tree_view,
9203 PsppSheetViewColumn *column)
9205 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9206 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9207 g_return_val_if_fail (column->tree_view == GTK_WIDGET (tree_view), -1);
9209 if (tree_view->priv->focus_column == column)
9210 tree_view->priv->focus_column = NULL;
9212 if (tree_view->priv->edited_column == column)
9214 pspp_sheet_view_stop_editing (tree_view, TRUE);
9216 /* no need to, but just to be sure ... */
9217 tree_view->priv->edited_column = NULL;
9220 _pspp_sheet_view_column_unset_tree_view (column);
9222 tree_view->priv->columns = g_list_remove (tree_view->priv->columns, column);
9223 tree_view->priv->n_columns--;
9225 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9229 _pspp_sheet_view_column_unrealize_button (column);
9230 for (list = tree_view->priv->columns; list; list = list->next)
9232 PsppSheetViewColumn *tmp_column;
9234 tmp_column = PSPP_SHEET_VIEW_COLUMN (list->data);
9235 if (tmp_column->visible)
9236 _pspp_sheet_view_column_cell_set_dirty (tmp_column);
9239 if (tree_view->priv->n_columns == 0 &&
9240 pspp_sheet_view_get_headers_visible (tree_view) &&
9241 tree_view->priv->header_window)
9242 gdk_window_hide (tree_view->priv->header_window);
9244 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9247 g_object_unref (column);
9248 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9250 return tree_view->priv->n_columns;
9254 * pspp_sheet_view_insert_column:
9255 * @tree_view: A #PsppSheetView.
9256 * @column: The #PsppSheetViewColumn to be inserted.
9257 * @position: The position to insert @column in.
9259 * This inserts the @column into the @tree_view at @position. If @position is
9260 * -1, then the column is inserted at the end.
9262 * Return value: The number of columns in @tree_view after insertion.
9265 pspp_sheet_view_insert_column (PsppSheetView *tree_view,
9266 PsppSheetViewColumn *column,
9269 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9270 g_return_val_if_fail (PSPP_IS_SHEET_VIEW_COLUMN (column), -1);
9271 g_return_val_if_fail (column->tree_view == NULL, -1);
9273 g_object_ref_sink (column);
9275 if (tree_view->priv->n_columns == 0 &&
9276 gtk_widget_get_realized (GTK_WIDGET (tree_view)) &&
9277 pspp_sheet_view_get_headers_visible (tree_view))
9279 gdk_window_show (tree_view->priv->header_window);
9282 tree_view->priv->columns = g_list_insert (tree_view->priv->columns,
9284 tree_view->priv->n_columns++;
9286 _pspp_sheet_view_column_set_tree_view (column, tree_view);
9288 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9292 _pspp_sheet_view_column_realize_button (column);
9294 for (list = tree_view->priv->columns; list; list = list->next)
9296 column = PSPP_SHEET_VIEW_COLUMN (list->data);
9297 if (column->visible)
9298 _pspp_sheet_view_column_cell_set_dirty (column);
9300 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9303 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9305 return tree_view->priv->n_columns;
9309 * pspp_sheet_view_insert_column_with_attributes:
9310 * @tree_view: A #PsppSheetView
9311 * @position: The position to insert the new column in.
9312 * @title: The title to set the header to.
9313 * @cell: The #GtkCellRenderer.
9314 * @Varargs: A %NULL-terminated list of attributes.
9316 * Creates a new #PsppSheetViewColumn and inserts it into the @tree_view at
9317 * @position. If @position is -1, then the newly created column is inserted at
9318 * the end. The column is initialized with the attributes given.
9320 * Return value: The number of columns in @tree_view after insertion.
9323 pspp_sheet_view_insert_column_with_attributes (PsppSheetView *tree_view,
9326 GtkCellRenderer *cell,
9329 PsppSheetViewColumn *column;
9334 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9336 column = pspp_sheet_view_column_new ();
9337 pspp_sheet_view_column_set_title (column, title);
9338 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9340 va_start (args, cell);
9342 attribute = va_arg (args, gchar *);
9344 while (attribute != NULL)
9346 column_id = va_arg (args, gint);
9347 pspp_sheet_view_column_add_attribute (column, cell, attribute, column_id);
9348 attribute = va_arg (args, gchar *);
9353 pspp_sheet_view_insert_column (tree_view, column, position);
9355 return tree_view->priv->n_columns;
9359 * pspp_sheet_view_insert_column_with_data_func:
9360 * @tree_view: a #PsppSheetView
9361 * @position: Position to insert, -1 for append
9362 * @title: column title
9363 * @cell: cell renderer for column
9364 * @func: function to set attributes of cell renderer
9365 * @data: data for @func
9366 * @dnotify: destroy notifier for @data
9368 * Convenience function that inserts a new column into the #PsppSheetView
9369 * with the given cell renderer and a #GtkCellDataFunc to set cell renderer
9370 * attributes (normally using data from the model). See also
9371 * pspp_sheet_view_column_set_cell_data_func(), pspp_sheet_view_column_pack_start().
9373 * Return value: number of columns in the tree view post-insert
9376 pspp_sheet_view_insert_column_with_data_func (PsppSheetView *tree_view,
9379 GtkCellRenderer *cell,
9380 PsppSheetCellDataFunc func,
9382 GDestroyNotify dnotify)
9384 PsppSheetViewColumn *column;
9386 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
9388 column = pspp_sheet_view_column_new ();
9389 pspp_sheet_view_column_set_title (column, title);
9390 pspp_sheet_view_column_pack_start (column, cell, TRUE);
9391 pspp_sheet_view_column_set_cell_data_func (column, cell, func, data, dnotify);
9393 pspp_sheet_view_insert_column (tree_view, column, position);
9395 return tree_view->priv->n_columns;
9399 * pspp_sheet_view_get_column:
9400 * @tree_view: A #PsppSheetView.
9401 * @n: The position of the column, counting from 0.
9403 * Gets the #PsppSheetViewColumn at the given position in the #tree_view.
9405 * Return value: The #PsppSheetViewColumn, or %NULL if the position is outside the
9408 PsppSheetViewColumn *
9409 pspp_sheet_view_get_column (PsppSheetView *tree_view,
9412 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9414 if (n < 0 || n >= tree_view->priv->n_columns)
9417 if (tree_view->priv->columns == NULL)
9420 return PSPP_SHEET_VIEW_COLUMN (g_list_nth (tree_view->priv->columns, n)->data);
9424 * pspp_sheet_view_get_columns:
9425 * @tree_view: A #PsppSheetView
9427 * Returns a #GList of all the #PsppSheetViewColumn s currently in @tree_view.
9428 * The returned list must be freed with g_list_free ().
9430 * Return value: (element-type PsppSheetViewColumn) (transfer container): A list of #PsppSheetViewColumn s
9433 pspp_sheet_view_get_columns (PsppSheetView *tree_view)
9435 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9437 return g_list_copy (tree_view->priv->columns);
9441 * pspp_sheet_view_move_column_after:
9442 * @tree_view: A #PsppSheetView
9443 * @column: The #PsppSheetViewColumn to be moved.
9444 * @base_column: (allow-none): The #PsppSheetViewColumn to be moved relative to, or %NULL.
9446 * Moves @column to be after to @base_column. If @base_column is %NULL, then
9447 * @column is placed in the first position.
9450 pspp_sheet_view_move_column_after (PsppSheetView *tree_view,
9451 PsppSheetViewColumn *column,
9452 PsppSheetViewColumn *base_column)
9454 GList *column_list_el, *base_el = NULL;
9456 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9458 column_list_el = g_list_find (tree_view->priv->columns, column);
9459 g_return_if_fail (column_list_el != NULL);
9463 base_el = g_list_find (tree_view->priv->columns, base_column);
9464 g_return_if_fail (base_el != NULL);
9467 if (column_list_el->prev == base_el)
9470 tree_view->priv->columns = g_list_remove_link (tree_view->priv->columns, column_list_el);
9471 if (base_el == NULL)
9473 column_list_el->prev = NULL;
9474 column_list_el->next = tree_view->priv->columns;
9475 if (column_list_el->next)
9476 column_list_el->next->prev = column_list_el;
9477 tree_view->priv->columns = column_list_el;
9481 column_list_el->prev = base_el;
9482 column_list_el->next = base_el->next;
9483 if (column_list_el->next)
9484 column_list_el->next->prev = column_list_el;
9485 base_el->next = column_list_el;
9488 if (gtk_widget_get_realized (GTK_WIDGET (tree_view)))
9490 gtk_widget_queue_resize (GTK_WIDGET (tree_view));
9491 pspp_sheet_view_size_allocate_columns (GTK_WIDGET (tree_view), NULL);
9494 g_signal_emit (tree_view, tree_view_signals[COLUMNS_CHANGED], 0);
9498 * pspp_sheet_view_set_column_drag_function:
9499 * @tree_view: A #PsppSheetView.
9500 * @func: (allow-none): A function to determine which columns are reorderable, or %NULL.
9501 * @user_data: (allow-none): User data to be passed to @func, or %NULL
9502 * @destroy: (allow-none): Destroy notifier for @user_data, or %NULL
9504 * Sets a user function for determining where a column may be dropped when
9505 * dragged. This function is called on every column pair in turn at the
9506 * beginning of a column drag to determine where a drop can take place. The
9507 * arguments passed to @func are: the @tree_view, the #PsppSheetViewColumn being
9508 * dragged, the two #PsppSheetViewColumn s determining the drop spot, and
9509 * @user_data. If either of the #PsppSheetViewColumn arguments for the drop spot
9510 * are %NULL, then they indicate an edge. If @func is set to be %NULL, then
9511 * @tree_view reverts to the default behavior of allowing all columns to be
9512 * dropped everywhere.
9515 pspp_sheet_view_set_column_drag_function (PsppSheetView *tree_view,
9516 PsppSheetViewColumnDropFunc func,
9518 GDestroyNotify destroy)
9520 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9522 if (tree_view->priv->column_drop_func_data_destroy)
9523 tree_view->priv->column_drop_func_data_destroy (tree_view->priv->column_drop_func_data);
9525 tree_view->priv->column_drop_func = func;
9526 tree_view->priv->column_drop_func_data = user_data;
9527 tree_view->priv->column_drop_func_data_destroy = destroy;
9531 * pspp_sheet_view_scroll_to_point:
9532 * @tree_view: a #PsppSheetView
9533 * @tree_x: X coordinate of new top-left pixel of visible area, or -1
9534 * @tree_y: Y coordinate of new top-left pixel of visible area, or -1
9536 * Scrolls the tree view such that the top-left corner of the visible
9537 * area is @tree_x, @tree_y, where @tree_x and @tree_y are specified
9538 * in tree coordinates. The @tree_view must be realized before
9539 * this function is called. If it isn't, you probably want to be
9540 * using pspp_sheet_view_scroll_to_cell().
9542 * If either @tree_x or @tree_y are -1, then that direction isn't scrolled.
9545 pspp_sheet_view_scroll_to_point (PsppSheetView *tree_view,
9549 GtkAdjustment *hadj;
9550 GtkAdjustment *vadj;
9552 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9553 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
9555 hadj = tree_view->priv->hadjustment;
9556 vadj = tree_view->priv->vadjustment;
9559 gtk_adjustment_set_value (hadj, CLAMP (tree_x, hadj->lower, hadj->upper - hadj->page_size));
9561 gtk_adjustment_set_value (vadj, CLAMP (tree_y, vadj->lower, vadj->upper - vadj->page_size));
9565 * pspp_sheet_view_scroll_to_cell:
9566 * @tree_view: A #PsppSheetView.
9567 * @path: (allow-none): The path of the row to move to, or %NULL.
9568 * @column: (allow-none): The #PsppSheetViewColumn to move horizontally to, or %NULL.
9569 * @use_align: whether to use alignment arguments, or %FALSE.
9570 * @row_align: The vertical alignment of the row specified by @path.
9571 * @col_align: The horizontal alignment of the column specified by @column.
9573 * Moves the alignments of @tree_view to the position specified by @column and
9574 * @path. If @column is %NULL, then no horizontal scrolling occurs. Likewise,
9575 * if @path is %NULL no vertical scrolling occurs. At a minimum, one of @column
9576 * or @path need to be non-%NULL. @row_align determines where the row is
9577 * placed, and @col_align determines where @column is placed. Both are expected
9578 * to be between 0.0 and 1.0. 0.0 means left/top alignment, 1.0 means
9579 * right/bottom alignment, 0.5 means center.
9581 * If @use_align is %FALSE, then the alignment arguments are ignored, and the
9582 * tree does the minimum amount of work to scroll the cell onto the screen.
9583 * This means that the cell will be scrolled to the edge closest to its current
9584 * position. If the cell is currently visible on the screen, nothing is done.
9586 * This function only works if the model is set, and @path is a valid row on the
9587 * model. If the model changes before the @tree_view is realized, the centered
9588 * path will be modified to reflect this change.
9591 pspp_sheet_view_scroll_to_cell (PsppSheetView *tree_view,
9593 PsppSheetViewColumn *column,
9598 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9599 g_return_if_fail (tree_view->priv->model != NULL);
9600 g_return_if_fail (row_align >= 0.0 && row_align <= 1.0);
9601 g_return_if_fail (col_align >= 0.0 && col_align <= 1.0);
9602 g_return_if_fail (path != NULL || column != NULL);
9605 g_print ("pspp_sheet_view_scroll_to_cell:\npath: %s\ncolumn: %s\nuse_align: %d\nrow_align: %f\ncol_align: %f\n",
9606 gtk_tree_path_to_string (path), column?"non-null":"null", use_align, row_align, col_align);
9608 row_align = CLAMP (row_align, 0.0, 1.0);
9609 col_align = CLAMP (col_align, 0.0, 1.0);
9612 /* Note: Despite the benefits that come from having one code path for the
9613 * scrolling code, we short-circuit validate_visible_area's immplementation as
9614 * it is much slower than just going to the point.
9616 if (!gtk_widget_get_visible (GTK_WIDGET (tree_view)) ||
9617 !gtk_widget_get_realized (GTK_WIDGET (tree_view))
9618 /* XXX || GTK_WIDGET_ALLOC_NEEDED (tree_view) */)
9620 if (tree_view->priv->scroll_to_path)
9621 gtk_tree_row_reference_free (tree_view->priv->scroll_to_path);
9623 tree_view->priv->scroll_to_path = NULL;
9624 tree_view->priv->scroll_to_column = NULL;
9627 tree_view->priv->scroll_to_path = gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
9629 tree_view->priv->scroll_to_column = column;
9630 tree_view->priv->scroll_to_use_align = use_align;
9631 tree_view->priv->scroll_to_row_align = row_align;
9632 tree_view->priv->scroll_to_col_align = col_align;
9634 install_presize_handler (tree_view);
9638 GdkRectangle cell_rect;
9639 GdkRectangle vis_rect;
9640 gint dest_x, dest_y;
9642 pspp_sheet_view_get_background_area (tree_view, path, column, &cell_rect);
9643 pspp_sheet_view_get_visible_rect (tree_view, &vis_rect);
9645 cell_rect.y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, cell_rect.y);
9647 dest_x = vis_rect.x;
9648 dest_y = vis_rect.y;
9654 dest_x = cell_rect.x - ((vis_rect.width - cell_rect.width) * col_align);
9658 if (cell_rect.x < vis_rect.x)
9659 dest_x = cell_rect.x;
9660 if (cell_rect.x + cell_rect.width > vis_rect.x + vis_rect.width)
9661 dest_x = cell_rect.x + cell_rect.width - vis_rect.width;
9669 dest_y = cell_rect.y - ((vis_rect.height - cell_rect.height) * row_align);
9670 dest_y = MAX (dest_y, 0);
9674 if (cell_rect.y < vis_rect.y)
9675 dest_y = cell_rect.y;
9676 if (cell_rect.y + cell_rect.height > vis_rect.y + vis_rect.height)
9677 dest_y = cell_rect.y + cell_rect.height - vis_rect.height;
9681 pspp_sheet_view_scroll_to_point (tree_view, dest_x, dest_y);
9686 * pspp_sheet_view_row_activated:
9687 * @tree_view: A #PsppSheetView
9688 * @path: The #GtkTreePath to be activated.
9689 * @column: The #PsppSheetViewColumn to be activated.
9691 * Activates the cell determined by @path and @column.
9694 pspp_sheet_view_row_activated (PsppSheetView *tree_view,
9696 PsppSheetViewColumn *column)
9698 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9700 g_signal_emit (tree_view, tree_view_signals[ROW_ACTIVATED], 0, path, column);
9705 * pspp_sheet_view_get_reorderable:
9706 * @tree_view: a #PsppSheetView
9708 * Retrieves whether the user can reorder the tree via drag-and-drop. See
9709 * pspp_sheet_view_set_reorderable().
9711 * Return value: %TRUE if the tree can be reordered.
9714 pspp_sheet_view_get_reorderable (PsppSheetView *tree_view)
9716 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
9718 return tree_view->priv->reorderable;
9722 * pspp_sheet_view_set_reorderable:
9723 * @tree_view: A #PsppSheetView.
9724 * @reorderable: %TRUE, if the tree can be reordered.
9726 * This function is a convenience function to allow you to reorder
9727 * models that support the #GtkDragSourceIface and the
9728 * #GtkDragDestIface. Both #GtkTreeStore and #GtkListStore support
9729 * these. If @reorderable is %TRUE, then the user can reorder the
9730 * model by dragging and dropping rows. The developer can listen to
9731 * these changes by connecting to the model's row_inserted and
9732 * row_deleted signals. The reordering is implemented by setting up
9733 * the tree view as a drag source and destination. Therefore, drag and
9734 * drop can not be used in a reorderable view for any other purpose.
9736 * This function does not give you any degree of control over the order -- any
9737 * reordering is allowed. If more control is needed, you should probably
9738 * handle drag and drop manually.
9741 pspp_sheet_view_set_reorderable (PsppSheetView *tree_view,
9742 gboolean reorderable)
9744 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9746 reorderable = reorderable != FALSE;
9748 if (tree_view->priv->reorderable == reorderable)
9753 const GtkTargetEntry row_targets[] = {
9754 { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, 0 }
9757 pspp_sheet_view_enable_model_drag_source (tree_view,
9760 G_N_ELEMENTS (row_targets),
9762 pspp_sheet_view_enable_model_drag_dest (tree_view,
9764 G_N_ELEMENTS (row_targets),
9769 pspp_sheet_view_unset_rows_drag_source (tree_view);
9770 pspp_sheet_view_unset_rows_drag_dest (tree_view);
9773 tree_view->priv->reorderable = reorderable;
9775 g_object_notify (G_OBJECT (tree_view), "reorderable");
9778 /* If CLEAR_AND_SELECT is true, then the row will be selected and, unless Shift
9779 is pressed, other rows will be unselected.
9781 If CLAMP_NODE is true, then the sheetview will scroll to make the row
9784 pspp_sheet_view_real_set_cursor (PsppSheetView *tree_view,
9786 gboolean clear_and_select,
9787 gboolean clamp_node)
9791 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
9793 GtkTreePath *cursor_path;
9794 cursor_path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
9795 pspp_sheet_view_queue_draw_path (tree_view, cursor_path, NULL);
9796 gtk_tree_path_free (cursor_path);
9799 gtk_tree_row_reference_free (tree_view->priv->cursor);
9800 tree_view->priv->cursor = NULL;
9802 _pspp_sheet_view_find_node (tree_view, path, &node);
9803 tree_view->priv->cursor =
9804 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view),
9805 tree_view->priv->model,
9808 if (tree_view->priv->row_count > 0)
9812 if (clear_and_select && !tree_view->priv->ctrl_pressed)
9814 GtkTreeSelectMode mode = 0;
9816 if (tree_view->priv->ctrl_pressed)
9817 mode |= GTK_TREE_SELECT_MODE_TOGGLE;
9818 if (tree_view->priv->shift_pressed)
9819 mode |= GTK_TREE_SELECT_MODE_EXTEND;
9821 _pspp_sheet_selection_internal_select_node (tree_view->priv->selection,
9826 /* We have to re-find tree and node here again, somebody might have
9827 * cleared the node or the whole tree in the PsppSheetSelection::changed
9828 * callback. If the nodes differ we bail out here.
9830 _pspp_sheet_view_find_node (tree_view, path, &new_node);
9832 if (node != new_node)
9837 pspp_sheet_view_clamp_node_visible (tree_view, node);
9838 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
9842 g_signal_emit (tree_view, tree_view_signals[CURSOR_CHANGED], 0);
9846 * pspp_sheet_view_get_cursor:
9847 * @tree_view: A #PsppSheetView
9848 * @path: (allow-none): A pointer to be filled with the current cursor path, or %NULL
9849 * @focus_column: (allow-none): A pointer to be filled with the current focus column, or %NULL
9851 * Fills in @path and @focus_column with the current path and focus column. If
9852 * the cursor isn't currently set, then *@path will be %NULL. If no column
9853 * currently has focus, then *@focus_column will be %NULL.
9855 * The returned #GtkTreePath must be freed with gtk_tree_path_free() when
9856 * you are done with it.
9859 pspp_sheet_view_get_cursor (PsppSheetView *tree_view,
9861 PsppSheetViewColumn **focus_column)
9863 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9867 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
9868 *path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
9875 *focus_column = tree_view->priv->focus_column;
9880 * pspp_sheet_view_set_cursor:
9881 * @tree_view: A #PsppSheetView
9882 * @path: A #GtkTreePath
9883 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
9884 * @start_editing: %TRUE if the specified cell should start being edited.
9886 * Sets the current keyboard focus to be at @path, and selects it. This is
9887 * useful when you want to focus the user's attention on a particular row. If
9888 * @focus_column is not %NULL, then focus is given to the column specified by
9889 * it. Additionally, if @focus_column is specified, and @start_editing is
9890 * %TRUE, then editing should be started in the specified cell.
9891 * This function is often followed by @gtk_widget_grab_focus (@tree_view)
9892 * in order to give keyboard focus to the widget. Please note that editing
9893 * can only happen when the widget is realized.
9895 * If @path is invalid for @model, the current cursor (if any) will be unset
9896 * and the function will return without failing.
9899 pspp_sheet_view_set_cursor (PsppSheetView *tree_view,
9901 PsppSheetViewColumn *focus_column,
9902 gboolean start_editing)
9904 pspp_sheet_view_set_cursor_on_cell (tree_view, path, focus_column,
9905 NULL, start_editing);
9909 * pspp_sheet_view_set_cursor_on_cell:
9910 * @tree_view: A #PsppSheetView
9911 * @path: A #GtkTreePath
9912 * @focus_column: (allow-none): A #PsppSheetViewColumn, or %NULL
9913 * @focus_cell: (allow-none): A #GtkCellRenderer, or %NULL
9914 * @start_editing: %TRUE if the specified cell should start being edited.
9916 * Sets the current keyboard focus to be at @path, and selects it. This is
9917 * useful when you want to focus the user's attention on a particular row. If
9918 * @focus_column is not %NULL, then focus is given to the column specified by
9919 * it. If @focus_column and @focus_cell are not %NULL, and @focus_column
9920 * contains 2 or more editable or activatable cells, then focus is given to
9921 * the cell specified by @focus_cell. Additionally, if @focus_column is
9922 * specified, and @start_editing is %TRUE, then editing should be started in
9923 * the specified cell. This function is often followed by
9924 * @gtk_widget_grab_focus (@tree_view) in order to give keyboard focus to the
9925 * widget. Please note that editing can only happen when the widget is
9928 * If @path is invalid for @model, the current cursor (if any) will be unset
9929 * and the function will return without failing.
9934 pspp_sheet_view_set_cursor_on_cell (PsppSheetView *tree_view,
9936 PsppSheetViewColumn *focus_column,
9937 GtkCellRenderer *focus_cell,
9938 gboolean start_editing)
9940 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
9941 g_return_if_fail (path != NULL);
9942 g_return_if_fail (focus_column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (focus_column));
9944 if (!tree_view->priv->model)
9949 g_return_if_fail (focus_column);
9950 g_return_if_fail (GTK_IS_CELL_RENDERER (focus_cell));
9953 /* cancel the current editing, if it exists */
9954 if (tree_view->priv->edited_column &&
9955 tree_view->priv->edited_column->editable_widget)
9956 pspp_sheet_view_stop_editing (tree_view, TRUE);
9958 pspp_sheet_view_real_set_cursor (tree_view, path, TRUE, TRUE);
9960 if (focus_column && focus_column->visible)
9963 gboolean column_in_tree = FALSE;
9965 for (list = tree_view->priv->columns; list; list = list->next)
9966 if (list->data == focus_column)
9968 column_in_tree = TRUE;
9971 g_return_if_fail (column_in_tree);
9972 tree_view->priv->focus_column = focus_column;
9974 pspp_sheet_view_column_focus_cell (focus_column, focus_cell);
9976 pspp_sheet_view_start_editing (tree_view, path);
9978 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
9979 pspp_sheet_selection_select_column (tree_view->priv->selection, focus_column);
9985 * pspp_sheet_view_get_bin_window:
9986 * @tree_view: A #PsppSheetView
9988 * Returns the window that @tree_view renders to. This is used primarily to
9989 * compare to <literal>event->window</literal> to confirm that the event on
9990 * @tree_view is on the right window.
9992 * Return value: A #GdkWindow, or %NULL when @tree_view hasn't been realized yet
9995 pspp_sheet_view_get_bin_window (PsppSheetView *tree_view)
9997 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
9999 return tree_view->priv->bin_window;
10003 * pspp_sheet_view_get_path_at_pos:
10004 * @tree_view: A #PsppSheetView.
10005 * @x: The x position to be identified (relative to bin_window).
10006 * @y: The y position to be identified (relative to bin_window).
10007 * @path: (out) (allow-none): A pointer to a #GtkTreePath pointer to be filled in, or %NULL
10008 * @column: (out) (allow-none): A pointer to a #PsppSheetViewColumn pointer to be filled in, or %NULL
10009 * @cell_x: (out) (allow-none): A pointer where the X coordinate relative to the cell can be placed, or %NULL
10010 * @cell_y: (out) (allow-none): A pointer where the Y coordinate relative to the cell can be placed, or %NULL
10012 * Finds the path at the point (@x, @y), relative to bin_window coordinates
10013 * (please see pspp_sheet_view_get_bin_window()).
10014 * That is, @x and @y are relative to an events coordinates. @x and @y must
10015 * come from an event on the @tree_view only where <literal>event->window ==
10016 * pspp_sheet_view_get_bin_window (<!-- -->)</literal>. It is primarily for
10017 * things like popup menus. If @path is non-%NULL, then it will be filled
10018 * with the #GtkTreePath at that point. This path should be freed with
10019 * gtk_tree_path_free(). If @column is non-%NULL, then it will be filled
10020 * with the column at that point. @cell_x and @cell_y return the coordinates
10021 * relative to the cell background (i.e. the @background_area passed to
10022 * gtk_cell_renderer_render()). This function is only meaningful if
10023 * @tree_view is realized. Therefore this function will always return %FALSE
10024 * if @tree_view is not realized or does not have a model.
10026 * For converting widget coordinates (eg. the ones you get from
10027 * GtkWidget::query-tooltip), please see
10028 * pspp_sheet_view_convert_widget_to_bin_window_coords().
10030 * Return value: %TRUE if a row exists at that coordinate.
10033 pspp_sheet_view_get_path_at_pos (PsppSheetView *tree_view,
10036 GtkTreePath **path,
10037 PsppSheetViewColumn **column,
10044 g_return_val_if_fail (tree_view != NULL, FALSE);
10051 if (tree_view->priv->bin_window == NULL)
10054 if (tree_view->priv->row_count == 0)
10057 if (x > tree_view->priv->hadjustment->upper)
10060 if (x < 0 || y < 0)
10063 if (column || cell_x)
10065 PsppSheetViewColumn *tmp_column;
10066 PsppSheetViewColumn *last_column = NULL;
10068 gint remaining_x = x;
10069 gboolean found = FALSE;
10072 rtl = (gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL);
10073 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
10075 list = (rtl ? list->prev : list->next))
10077 tmp_column = list->data;
10079 if (tmp_column->visible == FALSE)
10082 last_column = tmp_column;
10083 if (remaining_x <= tmp_column->width)
10088 *column = tmp_column;
10091 *cell_x = remaining_x;
10095 remaining_x -= tmp_column->width;
10098 /* If found is FALSE and there is a last_column, then it the remainder
10099 * space is in that area
10106 *column = last_column;
10109 *cell_x = last_column->width + remaining_x;
10118 y_offset = pspp_sheet_view_find_offset (tree_view,
10119 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, y),
10126 *cell_y = y_offset;
10129 *path = _pspp_sheet_view_find_path (tree_view, node);
10134 /* Computes 'cell_area' from 'background_area', which must be the background
10135 area for a cell. Set 'subtract_focus_rect' to TRUE to compute the cell area
10136 as passed to a GtkCellRenderer's "render" function, or to FALSE to compute
10137 the cell area as passed to _pspp_sheet_view_column_cell_render().
10139 'column' is required to properly adjust 'cell_area->x' and
10140 'cell_area->width'. It may be set to NULL if these values are not of
10141 interest. In this case 'cell_area->x' and 'cell_area->width' will be
10144 pspp_sheet_view_adjust_cell_area (PsppSheetView *tree_view,
10145 PsppSheetViewColumn *column,
10146 const GdkRectangle *background_area,
10147 gboolean subtract_focus_rect,
10148 GdkRectangle *cell_area)
10150 gint vertical_separator;
10151 gint horizontal_separator;
10153 *cell_area = *background_area;
10155 gtk_widget_style_get (GTK_WIDGET (tree_view),
10156 "vertical-separator", &vertical_separator,
10157 "horizontal-separator", &horizontal_separator,
10159 cell_area->x += horizontal_separator / 2;
10160 cell_area->y += vertical_separator / 2;
10161 cell_area->width -= horizontal_separator;
10162 cell_area->height -= vertical_separator;
10164 if (subtract_focus_rect)
10166 int focus_line_width;
10168 gtk_widget_style_get (GTK_WIDGET (tree_view),
10169 "focus-line-width", &focus_line_width,
10171 cell_area->x += focus_line_width;
10172 cell_area->y += focus_line_width;
10173 cell_area->width -= 2 * focus_line_width;
10174 cell_area->height -= 2 * focus_line_width;
10177 if (tree_view->priv->grid_lines != PSPP_SHEET_VIEW_GRID_LINES_NONE)
10179 gint grid_line_width;
10180 gtk_widget_style_get (GTK_WIDGET (tree_view),
10181 "grid-line-width", &grid_line_width,
10184 if ((tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_VERTICAL
10185 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10188 PsppSheetViewColumn *first_column, *last_column;
10191 /* Find the last visible column. */
10192 last_column = NULL;
10193 for (list = g_list_last (tree_view->priv->columns);
10197 PsppSheetViewColumn *c = list->data;
10205 /* Find the first visible column. */
10206 first_column = NULL;
10207 for (list = g_list_first (tree_view->priv->columns);
10211 PsppSheetViewColumn *c = list->data;
10219 if (column == first_column)
10221 cell_area->width -= grid_line_width / 2;
10223 else if (column == last_column)
10225 cell_area->x += grid_line_width / 2;
10226 cell_area->width -= grid_line_width / 2;
10230 cell_area->x += grid_line_width / 2;
10231 cell_area->width -= grid_line_width;
10235 if (tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL
10236 || tree_view->priv->grid_lines == PSPP_SHEET_VIEW_GRID_LINES_BOTH)
10238 cell_area->y += grid_line_width / 2;
10239 cell_area->height -= grid_line_width;
10243 if (column == NULL)
10246 cell_area->width = 0;
10251 * pspp_sheet_view_get_cell_area:
10252 * @tree_view: a #PsppSheetView
10253 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10254 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordinates
10255 * @rect: rectangle to fill with cell rect
10257 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10258 * row specified by @path and the column specified by @column. If @path is
10259 * %NULL, or points to a path not currently displayed, the @y and @height fields
10260 * of the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10261 * fields will be filled with 0. The sum of all cell rects does not cover the
10262 * entire tree; there are extra pixels in between rows, for example. The
10263 * returned rectangle is equivalent to the @cell_area passed to
10264 * gtk_cell_renderer_render(). This function is only valid if @tree_view is
10268 pspp_sheet_view_get_cell_area (PsppSheetView *tree_view,
10270 PsppSheetViewColumn *column,
10271 GdkRectangle *rect)
10273 GdkRectangle background_area;
10275 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10276 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10277 g_return_if_fail (rect != NULL);
10278 g_return_if_fail (!column || column->tree_view == (GtkWidget *) tree_view);
10279 g_return_if_fail (gtk_widget_get_realized (GTK_WIDGET (tree_view)));
10281 pspp_sheet_view_get_background_area (tree_view, path, column,
10283 pspp_sheet_view_adjust_cell_area (tree_view, column, &background_area,
10288 * pspp_sheet_view_get_background_area:
10289 * @tree_view: a #PsppSheetView
10290 * @path: (allow-none): a #GtkTreePath for the row, or %NULL to get only horizontal coordinates
10291 * @column: (allow-none): a #PsppSheetViewColumn for the column, or %NULL to get only vertical coordiantes
10292 * @rect: rectangle to fill with cell background rect
10294 * Fills the bounding rectangle in bin_window coordinates for the cell at the
10295 * row specified by @path and the column specified by @column. If @path is
10296 * %NULL, or points to a node not found in the tree, the @y and @height fields of
10297 * the rectangle will be filled with 0. If @column is %NULL, the @x and @width
10298 * fields will be filled with 0. The returned rectangle is equivalent to the
10299 * @background_area passed to gtk_cell_renderer_render(). These background
10300 * areas tile to cover the entire bin window. Contrast with the @cell_area,
10301 * returned by pspp_sheet_view_get_cell_area(), which returns only the cell
10302 * itself, excluding surrounding borders.
10306 pspp_sheet_view_get_background_area (PsppSheetView *tree_view,
10308 PsppSheetViewColumn *column,
10309 GdkRectangle *rect)
10313 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10314 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
10315 g_return_if_fail (rect != NULL);
10324 /* Get vertical coords */
10326 _pspp_sheet_view_find_node (tree_view, path, &node);
10330 rect->y = BACKGROUND_FIRST_PIXEL (tree_view, node);
10332 rect->height = ROW_HEIGHT (tree_view);
10339 pspp_sheet_view_get_background_xrange (tree_view, column, &rect->x, &x2);
10340 rect->width = x2 - rect->x;
10345 * pspp_sheet_view_get_visible_rect:
10346 * @tree_view: a #PsppSheetView
10347 * @visible_rect: rectangle to fill
10349 * Fills @visible_rect with the currently-visible region of the
10350 * buffer, in tree coordinates. Convert to bin_window coordinates with
10351 * pspp_sheet_view_convert_tree_to_bin_window_coords().
10352 * Tree coordinates start at 0,0 for row 0 of the tree, and cover the entire
10353 * scrollable area of the tree.
10356 pspp_sheet_view_get_visible_rect (PsppSheetView *tree_view,
10357 GdkRectangle *visible_rect)
10361 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10363 widget = GTK_WIDGET (tree_view);
10367 visible_rect->x = tree_view->priv->hadjustment->value;
10368 visible_rect->y = tree_view->priv->vadjustment->value;
10369 visible_rect->width = widget->allocation.width;
10370 visible_rect->height = widget->allocation.height - TREE_VIEW_HEADER_HEIGHT (tree_view);
10375 * pspp_sheet_view_widget_to_tree_coords:
10376 * @tree_view: a #PsppSheetView
10377 * @wx: X coordinate relative to bin_window
10378 * @wy: Y coordinate relative to bin_window
10379 * @tx: return location for tree X coordinate
10380 * @ty: return location for tree Y coordinate
10382 * Converts bin_window coordinates to coordinates for the
10383 * tree (the full scrollable area of the tree).
10385 * Deprecated: 2.12: Due to historial reasons the name of this function is
10386 * incorrect. For converting coordinates relative to the widget to
10387 * bin_window coordinates, please see
10388 * pspp_sheet_view_convert_widget_to_bin_window_coords().
10392 pspp_sheet_view_widget_to_tree_coords (PsppSheetView *tree_view,
10398 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10401 *tx = wx + tree_view->priv->hadjustment->value;
10403 *ty = wy + tree_view->priv->dy;
10407 * pspp_sheet_view_tree_to_widget_coords:
10408 * @tree_view: a #PsppSheetView
10409 * @tx: tree X coordinate
10410 * @ty: tree Y coordinate
10411 * @wx: return location for X coordinate relative to bin_window
10412 * @wy: return location for Y coordinate relative to bin_window
10414 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10415 * to bin_window coordinates.
10417 * Deprecated: 2.12: Due to historial reasons the name of this function is
10418 * incorrect. For converting bin_window coordinates to coordinates relative
10419 * to bin_window, please see
10420 * pspp_sheet_view_convert_bin_window_to_widget_coords().
10424 pspp_sheet_view_tree_to_widget_coords (PsppSheetView *tree_view,
10430 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10433 *wx = tx - tree_view->priv->hadjustment->value;
10435 *wy = ty - tree_view->priv->dy;
10440 * pspp_sheet_view_convert_widget_to_tree_coords:
10441 * @tree_view: a #PsppSheetView
10442 * @wx: X coordinate relative to the widget
10443 * @wy: Y coordinate relative to the widget
10444 * @tx: return location for tree X coordinate
10445 * @ty: return location for tree Y coordinate
10447 * Converts widget coordinates to coordinates for the
10448 * tree (the full scrollable area of the tree).
10453 pspp_sheet_view_convert_widget_to_tree_coords (PsppSheetView *tree_view,
10461 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10463 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view,
10466 pspp_sheet_view_convert_bin_window_to_tree_coords (tree_view,
10472 * pspp_sheet_view_convert_tree_to_widget_coords:
10473 * @tree_view: a #PsppSheetView
10474 * @tx: X coordinate relative to the tree
10475 * @ty: Y coordinate relative to the tree
10476 * @wx: return location for widget X coordinate
10477 * @wy: return location for widget Y coordinate
10479 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10480 * to widget coordinates.
10485 pspp_sheet_view_convert_tree_to_widget_coords (PsppSheetView *tree_view,
10493 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10495 pspp_sheet_view_convert_tree_to_bin_window_coords (tree_view,
10498 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
10504 * pspp_sheet_view_convert_widget_to_bin_window_coords:
10505 * @tree_view: a #PsppSheetView
10506 * @wx: X coordinate relative to the widget
10507 * @wy: Y coordinate relative to the widget
10508 * @bx: return location for bin_window X coordinate
10509 * @by: return location for bin_window Y coordinate
10511 * Converts widget coordinates to coordinates for the bin_window
10512 * (see pspp_sheet_view_get_bin_window()).
10517 pspp_sheet_view_convert_widget_to_bin_window_coords (PsppSheetView *tree_view,
10523 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10526 *bx = wx + tree_view->priv->hadjustment->value;
10528 *by = wy - TREE_VIEW_HEADER_HEIGHT (tree_view);
10532 * pspp_sheet_view_convert_bin_window_to_widget_coords:
10533 * @tree_view: a #PsppSheetView
10534 * @bx: bin_window X coordinate
10535 * @by: bin_window Y coordinate
10536 * @wx: return location for widget X coordinate
10537 * @wy: return location for widget Y coordinate
10539 * Converts bin_window coordinates (see pspp_sheet_view_get_bin_window())
10540 * to widget relative coordinates.
10545 pspp_sheet_view_convert_bin_window_to_widget_coords (PsppSheetView *tree_view,
10551 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10554 *wx = bx - tree_view->priv->hadjustment->value;
10556 *wy = by + TREE_VIEW_HEADER_HEIGHT (tree_view);
10560 * pspp_sheet_view_convert_tree_to_bin_window_coords:
10561 * @tree_view: a #PsppSheetView
10562 * @tx: tree X coordinate
10563 * @ty: tree Y coordinate
10564 * @bx: return location for X coordinate relative to bin_window
10565 * @by: return location for Y coordinate relative to bin_window
10567 * Converts tree coordinates (coordinates in full scrollable area of the tree)
10568 * to bin_window coordinates.
10573 pspp_sheet_view_convert_tree_to_bin_window_coords (PsppSheetView *tree_view,
10579 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10584 *by = ty - tree_view->priv->dy;
10588 * pspp_sheet_view_convert_bin_window_to_tree_coords:
10589 * @tree_view: a #PsppSheetView
10590 * @bx: X coordinate relative to bin_window
10591 * @by: Y coordinate relative to bin_window
10592 * @tx: return location for tree X coordinate
10593 * @ty: return location for tree Y coordinate
10595 * Converts bin_window coordinates to coordinates for the
10596 * tree (the full scrollable area of the tree).
10601 pspp_sheet_view_convert_bin_window_to_tree_coords (PsppSheetView *tree_view,
10607 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10612 *ty = by + tree_view->priv->dy;
10618 * pspp_sheet_view_get_visible_range:
10619 * @tree_view: A #PsppSheetView
10620 * @start_path: (allow-none): Return location for start of region, or %NULL.
10621 * @end_path: (allow-none): Return location for end of region, or %NULL.
10623 * Sets @start_path and @end_path to be the first and last visible path.
10624 * Note that there may be invisible paths in between.
10626 * The paths should be freed with gtk_tree_path_free() after use.
10628 * Returns: %TRUE, if valid paths were placed in @start_path and @end_path.
10633 pspp_sheet_view_get_visible_range (PsppSheetView *tree_view,
10634 GtkTreePath **start_path,
10635 GtkTreePath **end_path)
10640 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
10642 if (!tree_view->priv->row_count)
10649 pspp_sheet_view_find_offset (tree_view,
10650 TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, 0),
10653 *start_path = _pspp_sheet_view_find_path (tree_view, node);
10662 if (tree_view->priv->height < tree_view->priv->vadjustment->page_size)
10663 y = tree_view->priv->height - 1;
10665 y = TREE_WINDOW_Y_TO_RBTREE_Y (tree_view, tree_view->priv->vadjustment->page_size) - 1;
10667 pspp_sheet_view_find_offset (tree_view, y, &node);
10669 *end_path = _pspp_sheet_view_find_path (tree_view, node);
10678 unset_reorderable (PsppSheetView *tree_view)
10680 if (tree_view->priv->reorderable)
10682 tree_view->priv->reorderable = FALSE;
10683 g_object_notify (G_OBJECT (tree_view), "reorderable");
10688 * pspp_sheet_view_enable_model_drag_source:
10689 * @tree_view: a #PsppSheetView
10690 * @start_button_mask: Mask of allowed buttons to start drag
10691 * @targets: the table of targets that the drag will support
10692 * @n_targets: the number of items in @targets
10693 * @actions: the bitmask of possible actions for a drag from this
10696 * Turns @tree_view into a drag source for automatic DND. Calling this
10697 * method sets #PsppSheetView:reorderable to %FALSE.
10700 pspp_sheet_view_enable_model_drag_source (PsppSheetView *tree_view,
10701 GdkModifierType start_button_mask,
10702 const GtkTargetEntry *targets,
10704 GdkDragAction actions)
10706 TreeViewDragInfo *di;
10708 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10710 gtk_drag_source_set (GTK_WIDGET (tree_view),
10716 di = ensure_info (tree_view);
10718 di->start_button_mask = start_button_mask;
10719 di->source_actions = actions;
10720 di->source_set = TRUE;
10722 unset_reorderable (tree_view);
10726 * pspp_sheet_view_enable_model_drag_dest:
10727 * @tree_view: a #PsppSheetView
10728 * @targets: the table of targets that the drag will support
10729 * @n_targets: the number of items in @targets
10730 * @actions: the bitmask of possible actions for a drag from this
10733 * Turns @tree_view into a drop destination for automatic DND. Calling
10734 * this method sets #PsppSheetView:reorderable to %FALSE.
10737 pspp_sheet_view_enable_model_drag_dest (PsppSheetView *tree_view,
10738 const GtkTargetEntry *targets,
10740 GdkDragAction actions)
10742 TreeViewDragInfo *di;
10744 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10746 gtk_drag_dest_set (GTK_WIDGET (tree_view),
10752 di = ensure_info (tree_view);
10753 di->dest_set = TRUE;
10755 unset_reorderable (tree_view);
10759 * pspp_sheet_view_unset_rows_drag_source:
10760 * @tree_view: a #PsppSheetView
10762 * Undoes the effect of
10763 * pspp_sheet_view_enable_model_drag_source(). Calling this method sets
10764 * #PsppSheetView:reorderable to %FALSE.
10767 pspp_sheet_view_unset_rows_drag_source (PsppSheetView *tree_view)
10769 TreeViewDragInfo *di;
10771 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10773 di = get_info (tree_view);
10777 if (di->source_set)
10779 gtk_drag_source_unset (GTK_WIDGET (tree_view));
10780 di->source_set = FALSE;
10783 if (!di->dest_set && !di->source_set)
10784 remove_info (tree_view);
10787 unset_reorderable (tree_view);
10791 * pspp_sheet_view_unset_rows_drag_dest:
10792 * @tree_view: a #PsppSheetView
10794 * Undoes the effect of
10795 * pspp_sheet_view_enable_model_drag_dest(). Calling this method sets
10796 * #PsppSheetView:reorderable to %FALSE.
10799 pspp_sheet_view_unset_rows_drag_dest (PsppSheetView *tree_view)
10801 TreeViewDragInfo *di;
10803 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10805 di = get_info (tree_view);
10811 gtk_drag_dest_unset (GTK_WIDGET (tree_view));
10812 di->dest_set = FALSE;
10815 if (!di->dest_set && !di->source_set)
10816 remove_info (tree_view);
10819 unset_reorderable (tree_view);
10823 * pspp_sheet_view_set_drag_dest_row:
10824 * @tree_view: a #PsppSheetView
10825 * @path: (allow-none): The path of the row to highlight, or %NULL.
10826 * @pos: Specifies whether to drop before, after or into the row
10828 * Sets the row that is highlighted for feedback.
10831 pspp_sheet_view_set_drag_dest_row (PsppSheetView *tree_view,
10833 PsppSheetViewDropPosition pos)
10835 GtkTreePath *current_dest;
10837 /* Note; this function is exported to allow a custom DND
10838 * implementation, so it can't touch TreeViewDragInfo
10841 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10843 current_dest = NULL;
10845 if (tree_view->priv->drag_dest_row)
10847 current_dest = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
10848 gtk_tree_row_reference_free (tree_view->priv->drag_dest_row);
10851 /* special case a drop on an empty model */
10852 tree_view->priv->empty_view_drop = 0;
10854 if (pos == PSPP_SHEET_VIEW_DROP_BEFORE && path
10855 && gtk_tree_path_get_depth (path) == 1
10856 && gtk_tree_path_get_indices (path)[0] == 0)
10860 n_children = gtk_tree_model_iter_n_children (tree_view->priv->model,
10864 tree_view->priv->empty_view_drop = 1;
10867 tree_view->priv->drag_dest_pos = pos;
10871 tree_view->priv->drag_dest_row =
10872 gtk_tree_row_reference_new_proxy (G_OBJECT (tree_view), tree_view->priv->model, path);
10873 pspp_sheet_view_queue_draw_path (tree_view, path, NULL);
10876 tree_view->priv->drag_dest_row = NULL;
10880 int node, new_node;
10882 _pspp_sheet_view_find_node (tree_view, current_dest, &node);
10883 _pspp_sheet_view_queue_draw_node (tree_view, node, NULL);
10887 new_node = pspp_sheet_view_node_next (tree_view, node);
10889 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
10891 new_node = pspp_sheet_view_node_prev (tree_view, node);
10893 _pspp_sheet_view_queue_draw_node (tree_view, new_node, NULL);
10895 gtk_tree_path_free (current_dest);
10900 * pspp_sheet_view_get_drag_dest_row:
10901 * @tree_view: a #PsppSheetView
10902 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
10903 * @pos: (allow-none): Return location for the drop position, or %NULL
10905 * Gets information about the row that is highlighted for feedback.
10908 pspp_sheet_view_get_drag_dest_row (PsppSheetView *tree_view,
10909 GtkTreePath **path,
10910 PsppSheetViewDropPosition *pos)
10912 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
10916 if (tree_view->priv->drag_dest_row)
10917 *path = gtk_tree_row_reference_get_path (tree_view->priv->drag_dest_row);
10920 if (tree_view->priv->empty_view_drop)
10921 *path = gtk_tree_path_new_from_indices (0, -1);
10928 *pos = tree_view->priv->drag_dest_pos;
10932 * pspp_sheet_view_get_dest_row_at_pos:
10933 * @tree_view: a #PsppSheetView
10934 * @drag_x: the position to determine the destination row for
10935 * @drag_y: the position to determine the destination row for
10936 * @path: (allow-none): Return location for the path of the highlighted row, or %NULL.
10937 * @pos: (allow-none): Return location for the drop position, or %NULL
10939 * Determines the destination row for a given position. @drag_x and
10940 * @drag_y are expected to be in widget coordinates. This function is only
10941 * meaningful if @tree_view is realized. Therefore this function will always
10942 * return %FALSE if @tree_view is not realized or does not have a model.
10944 * Return value: whether there is a row at the given position, %TRUE if this
10945 * is indeed the case.
10948 pspp_sheet_view_get_dest_row_at_pos (PsppSheetView *tree_view,
10951 GtkTreePath **path,
10952 PsppSheetViewDropPosition *pos)
10956 gdouble offset_into_row;
10959 PsppSheetViewColumn *column = NULL;
10960 GtkTreePath *tmp_path = NULL;
10962 /* Note; this function is exported to allow a custom DND
10963 * implementation, so it can't touch TreeViewDragInfo
10966 g_return_val_if_fail (tree_view != NULL, FALSE);
10967 g_return_val_if_fail (drag_x >= 0, FALSE);
10968 g_return_val_if_fail (drag_y >= 0, FALSE);
10973 if (tree_view->priv->bin_window == NULL)
10976 if (tree_view->priv->row_count == 0)
10979 /* If in the top third of a row, we drop before that row; if
10980 * in the bottom third, drop after that row; if in the middle,
10981 * and the row has children, drop into the row.
10983 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, drag_x, drag_y,
10986 if (!pspp_sheet_view_get_path_at_pos (tree_view,
10995 pspp_sheet_view_get_background_area (tree_view, tmp_path, column,
10998 offset_into_row = cell_y;
11003 gtk_tree_path_free (tmp_path);
11007 third = cell.height / 3.0;
11011 if (offset_into_row < third)
11013 *pos = PSPP_SHEET_VIEW_DROP_BEFORE;
11015 else if (offset_into_row < (cell.height / 2.0))
11017 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_BEFORE;
11019 else if (offset_into_row < third * 2.0)
11021 *pos = PSPP_SHEET_VIEW_DROP_INTO_OR_AFTER;
11025 *pos = PSPP_SHEET_VIEW_DROP_AFTER;
11034 /* KEEP IN SYNC WITH PSPP_SHEET_VIEW_BIN_EXPOSE */
11036 * pspp_sheet_view_create_row_drag_icon:
11037 * @tree_view: a #PsppSheetView
11038 * @path: a #GtkTreePath in @tree_view
11040 * Creates a #GdkPixmap representation of the row at @path.
11041 * This image is used for a drag icon.
11043 * Return value: a newly-allocated pixmap of the drag icon.
11046 pspp_sheet_view_create_row_drag_icon (PsppSheetView *tree_view,
11053 GdkRectangle background_area;
11054 GdkRectangle expose_area;
11057 /* start drawing inside the black outline */
11059 GdkDrawable *drawable;
11060 gint bin_window_width;
11063 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11064 g_return_val_if_fail (path != NULL, NULL);
11066 widget = GTK_WIDGET (tree_view);
11068 if (!gtk_widget_get_realized (widget))
11071 depth = gtk_tree_path_get_depth (path);
11073 _pspp_sheet_view_find_node (tree_view,
11080 if (!gtk_tree_model_get_iter (tree_view->priv->model,
11087 background_area.y = y;
11088 background_area.height = ROW_HEIGHT (tree_view);
11090 gdk_drawable_get_size (tree_view->priv->bin_window,
11091 &bin_window_width, NULL);
11093 drawable = gdk_pixmap_new (tree_view->priv->bin_window,
11094 bin_window_width + 2,
11095 background_area.height + 2,
11100 expose_area.width = bin_window_width + 2;
11101 expose_area.height = background_area.height + 2;
11103 gdk_draw_rectangle (drawable,
11104 widget->style->base_gc [gtk_widget_get_state (widget)],
11107 bin_window_width + 2,
11108 background_area.height + 2);
11110 rtl = gtk_widget_get_direction (GTK_WIDGET (tree_view)) == GTK_TEXT_DIR_RTL;
11112 for (list = (rtl ? g_list_last (tree_view->priv->columns) : g_list_first (tree_view->priv->columns));
11114 list = (rtl ? list->prev : list->next))
11116 PsppSheetViewColumn *column = list->data;
11117 GdkRectangle cell_area;
11118 gint vertical_separator;
11120 if (!column->visible)
11123 pspp_sheet_view_column_cell_set_cell_data (column, tree_view->priv->model, &iter);
11125 background_area.x = cell_offset;
11126 background_area.width = column->width;
11128 gtk_widget_style_get (widget,
11129 "vertical-separator", &vertical_separator,
11132 cell_area = background_area;
11134 cell_area.y += vertical_separator / 2;
11135 cell_area.height -= vertical_separator;
11137 if (pspp_sheet_view_column_cell_is_visible (column))
11138 _pspp_sheet_view_column_cell_render (column,
11144 cell_offset += column->width;
11147 gdk_draw_rectangle (drawable,
11148 widget->style->black_gc,
11151 bin_window_width + 1,
11152 background_area.height + 1);
11159 * pspp_sheet_view_set_destroy_count_func:
11160 * @tree_view: A #PsppSheetView
11161 * @func: (allow-none): Function to be called when a view row is destroyed, or %NULL
11162 * @data: (allow-none): User data to be passed to @func, or %NULL
11163 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11165 * This function should almost never be used. It is meant for private use by
11166 * ATK for determining the number of visible children that are removed when a row is deleted.
11169 pspp_sheet_view_set_destroy_count_func (PsppSheetView *tree_view,
11170 PsppSheetDestroyCountFunc func,
11172 GDestroyNotify destroy)
11174 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11176 if (tree_view->priv->destroy_count_destroy)
11177 tree_view->priv->destroy_count_destroy (tree_view->priv->destroy_count_data);
11179 tree_view->priv->destroy_count_func = func;
11180 tree_view->priv->destroy_count_data = data;
11181 tree_view->priv->destroy_count_destroy = destroy;
11186 * Interactive search
11190 * pspp_sheet_view_set_enable_search:
11191 * @tree_view: A #PsppSheetView
11192 * @enable_search: %TRUE, if the user can search interactively
11194 * If @enable_search is set, then the user can type in text to search through
11195 * the tree interactively (this is sometimes called "typeahead find").
11197 * Note that even if this is %FALSE, the user can still initiate a search
11198 * using the "start-interactive-search" key binding.
11201 pspp_sheet_view_set_enable_search (PsppSheetView *tree_view,
11202 gboolean enable_search)
11204 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11206 enable_search = !!enable_search;
11208 if (tree_view->priv->enable_search != enable_search)
11210 tree_view->priv->enable_search = enable_search;
11211 g_object_notify (G_OBJECT (tree_view), "enable-search");
11216 * pspp_sheet_view_get_enable_search:
11217 * @tree_view: A #PsppSheetView
11219 * Returns whether or not the tree allows to start interactive searching
11220 * by typing in text.
11222 * Return value: whether or not to let the user search interactively
11225 pspp_sheet_view_get_enable_search (PsppSheetView *tree_view)
11227 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11229 return tree_view->priv->enable_search;
11234 * pspp_sheet_view_get_search_column:
11235 * @tree_view: A #PsppSheetView
11237 * Gets the column searched on by the interactive search code.
11239 * Return value: the column the interactive search code searches in.
11242 pspp_sheet_view_get_search_column (PsppSheetView *tree_view)
11244 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), -1);
11246 return (tree_view->priv->search_column);
11250 * pspp_sheet_view_set_search_column:
11251 * @tree_view: A #PsppSheetView
11252 * @column: the column of the model to search in, or -1 to disable searching
11254 * Sets @column as the column where the interactive search code should
11255 * search in for the current model.
11257 * If the search column is set, users can use the "start-interactive-search"
11258 * key binding to bring up search popup. The enable-search property controls
11259 * whether simply typing text will also start an interactive search.
11261 * Note that @column refers to a column of the current model. The search
11262 * column is reset to -1 when the model is changed.
11265 pspp_sheet_view_set_search_column (PsppSheetView *tree_view,
11268 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11269 g_return_if_fail (column >= -1);
11271 if (tree_view->priv->search_column == column)
11274 tree_view->priv->search_column = column;
11275 g_object_notify (G_OBJECT (tree_view), "search-column");
11279 * pspp_sheet_view_get_search_equal_func:
11280 * @tree_view: A #PsppSheetView
11282 * Returns the compare function currently in use.
11284 * Return value: the currently used compare function for the search code.
11287 PsppSheetViewSearchEqualFunc
11288 pspp_sheet_view_get_search_equal_func (PsppSheetView *tree_view)
11290 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11292 return tree_view->priv->search_equal_func;
11296 * pspp_sheet_view_set_search_equal_func:
11297 * @tree_view: A #PsppSheetView
11298 * @search_equal_func: the compare function to use during the search
11299 * @search_user_data: (allow-none): user data to pass to @search_equal_func, or %NULL
11300 * @search_destroy: (allow-none): Destroy notifier for @search_user_data, or %NULL
11302 * Sets the compare function for the interactive search capabilities; note
11303 * that somewhat like strcmp() returning 0 for equality
11304 * #PsppSheetViewSearchEqualFunc returns %FALSE on matches.
11307 pspp_sheet_view_set_search_equal_func (PsppSheetView *tree_view,
11308 PsppSheetViewSearchEqualFunc search_equal_func,
11309 gpointer search_user_data,
11310 GDestroyNotify search_destroy)
11312 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11313 g_return_if_fail (search_equal_func != NULL);
11315 if (tree_view->priv->search_destroy)
11316 tree_view->priv->search_destroy (tree_view->priv->search_user_data);
11318 tree_view->priv->search_equal_func = search_equal_func;
11319 tree_view->priv->search_user_data = search_user_data;
11320 tree_view->priv->search_destroy = search_destroy;
11321 if (tree_view->priv->search_equal_func == NULL)
11322 tree_view->priv->search_equal_func = pspp_sheet_view_search_equal_func;
11326 * pspp_sheet_view_get_search_entry:
11327 * @tree_view: A #PsppSheetView
11329 * Returns the #GtkEntry which is currently in use as interactive search
11330 * entry for @tree_view. In case the built-in entry is being used, %NULL
11331 * will be returned.
11333 * Return value: the entry currently in use as search entry.
11338 pspp_sheet_view_get_search_entry (PsppSheetView *tree_view)
11340 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11342 if (tree_view->priv->search_custom_entry_set)
11343 return GTK_ENTRY (tree_view->priv->search_entry);
11349 * pspp_sheet_view_set_search_entry:
11350 * @tree_view: A #PsppSheetView
11351 * @entry: (allow-none): the entry the interactive search code of @tree_view should use or %NULL
11353 * Sets the entry which the interactive search code will use for this
11354 * @tree_view. This is useful when you want to provide a search entry
11355 * in our interface at all time at a fixed position. Passing %NULL for
11356 * @entry will make the interactive search code use the built-in popup
11362 pspp_sheet_view_set_search_entry (PsppSheetView *tree_view,
11365 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11366 g_return_if_fail (entry == NULL || GTK_IS_ENTRY (entry));
11368 if (tree_view->priv->search_custom_entry_set)
11370 if (tree_view->priv->search_entry_changed_id)
11372 g_signal_handler_disconnect (tree_view->priv->search_entry,
11373 tree_view->priv->search_entry_changed_id);
11374 tree_view->priv->search_entry_changed_id = 0;
11376 g_signal_handlers_disconnect_by_func (tree_view->priv->search_entry,
11377 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11380 g_object_unref (tree_view->priv->search_entry);
11382 else if (tree_view->priv->search_window)
11384 gtk_widget_destroy (tree_view->priv->search_window);
11386 tree_view->priv->search_window = NULL;
11391 tree_view->priv->search_entry = g_object_ref (entry);
11392 tree_view->priv->search_custom_entry_set = TRUE;
11394 if (tree_view->priv->search_entry_changed_id == 0)
11396 tree_view->priv->search_entry_changed_id =
11397 g_signal_connect (tree_view->priv->search_entry, "changed",
11398 G_CALLBACK (pspp_sheet_view_search_init),
11402 g_signal_connect (tree_view->priv->search_entry, "key-press-event",
11403 G_CALLBACK (pspp_sheet_view_search_key_press_event),
11406 pspp_sheet_view_search_init (tree_view->priv->search_entry, tree_view);
11410 tree_view->priv->search_entry = NULL;
11411 tree_view->priv->search_custom_entry_set = FALSE;
11416 * pspp_sheet_view_set_search_position_func:
11417 * @tree_view: A #PsppSheetView
11418 * @func: (allow-none): the function to use to position the search dialog, or %NULL
11419 * to use the default search position function
11420 * @data: (allow-none): user data to pass to @func, or %NULL
11421 * @destroy: (allow-none): Destroy notifier for @data, or %NULL
11423 * Sets the function to use when positioning the search dialog.
11428 pspp_sheet_view_set_search_position_func (PsppSheetView *tree_view,
11429 PsppSheetViewSearchPositionFunc func,
11430 gpointer user_data,
11431 GDestroyNotify destroy)
11433 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11435 if (tree_view->priv->search_position_destroy)
11436 tree_view->priv->search_position_destroy (tree_view->priv->search_position_user_data);
11438 tree_view->priv->search_position_func = func;
11439 tree_view->priv->search_position_user_data = user_data;
11440 tree_view->priv->search_position_destroy = destroy;
11441 if (tree_view->priv->search_position_func == NULL)
11442 tree_view->priv->search_position_func = pspp_sheet_view_search_position_func;
11446 * pspp_sheet_view_get_search_position_func:
11447 * @tree_view: A #PsppSheetView
11449 * Returns the positioning function currently in use.
11451 * Return value: the currently used function for positioning the search dialog.
11455 PsppSheetViewSearchPositionFunc
11456 pspp_sheet_view_get_search_position_func (PsppSheetView *tree_view)
11458 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), NULL);
11460 return tree_view->priv->search_position_func;
11465 pspp_sheet_view_search_dialog_hide (GtkWidget *search_dialog,
11466 PsppSheetView *tree_view)
11468 if (tree_view->priv->disable_popdown)
11471 if (tree_view->priv->search_entry_changed_id)
11473 g_signal_handler_disconnect (tree_view->priv->search_entry,
11474 tree_view->priv->search_entry_changed_id);
11475 tree_view->priv->search_entry_changed_id = 0;
11477 if (tree_view->priv->typeselect_flush_timeout)
11479 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11480 tree_view->priv->typeselect_flush_timeout = 0;
11483 if (gtk_widget_get_visible (search_dialog))
11485 /* send focus-in event */
11486 send_focus_change (GTK_WIDGET (tree_view->priv->search_entry), FALSE);
11487 gtk_widget_hide (search_dialog);
11488 gtk_entry_set_text (GTK_ENTRY (tree_view->priv->search_entry), "");
11489 send_focus_change (GTK_WIDGET (tree_view), TRUE);
11494 pspp_sheet_view_search_position_func (PsppSheetView *tree_view,
11495 GtkWidget *search_dialog,
11496 gpointer user_data)
11499 gint tree_x, tree_y;
11500 gint tree_width, tree_height;
11501 GdkWindow *tree_window = GTK_WIDGET (tree_view)->window;
11502 GdkScreen *screen = gdk_drawable_get_screen (tree_window);
11503 GtkRequisition requisition;
11505 GdkRectangle monitor;
11507 monitor_num = gdk_screen_get_monitor_at_window (screen, tree_window);
11508 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
11510 gtk_widget_realize (search_dialog);
11512 gdk_window_get_origin (tree_window, &tree_x, &tree_y);
11513 gdk_drawable_get_size (tree_window,
11516 gtk_widget_size_request (search_dialog, &requisition);
11518 if (tree_x + tree_width > gdk_screen_get_width (screen))
11519 x = gdk_screen_get_width (screen) - requisition.width;
11520 else if (tree_x + tree_width - requisition.width < 0)
11523 x = tree_x + tree_width - requisition.width;
11525 if (tree_y + tree_height + requisition.height > gdk_screen_get_height (screen))
11526 y = gdk_screen_get_height (screen) - requisition.height;
11527 else if (tree_y + tree_height < 0) /* isn't really possible ... */
11530 y = tree_y + tree_height;
11532 gtk_window_move (GTK_WINDOW (search_dialog), x, y);
11536 pspp_sheet_view_search_disable_popdown (GtkEntry *entry,
11540 PsppSheetView *tree_view = (PsppSheetView *)data;
11542 tree_view->priv->disable_popdown = 1;
11543 g_signal_connect (menu, "hide",
11544 G_CALLBACK (pspp_sheet_view_search_enable_popdown), data);
11547 /* Because we're visible but offscreen, we just set a flag in the preedit
11551 pspp_sheet_view_search_preedit_changed (GtkIMContext *im_context,
11552 PsppSheetView *tree_view)
11554 tree_view->priv->imcontext_changed = 1;
11555 if (tree_view->priv->typeselect_flush_timeout)
11557 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11558 tree_view->priv->typeselect_flush_timeout =
11559 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11560 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11567 pspp_sheet_view_search_activate (GtkEntry *entry,
11568 PsppSheetView *tree_view)
11573 pspp_sheet_view_search_dialog_hide (tree_view->priv->search_window,
11576 /* If we have a row selected and it's the cursor row, we activate
11578 if (gtk_tree_row_reference_valid (tree_view->priv->cursor))
11580 path = gtk_tree_row_reference_get_path (tree_view->priv->cursor);
11582 _pspp_sheet_view_find_node (tree_view, path, &node);
11584 if (node >= 0 && pspp_sheet_view_node_is_selected (tree_view, node))
11585 pspp_sheet_view_row_activated (tree_view, path, tree_view->priv->focus_column);
11587 gtk_tree_path_free (path);
11592 pspp_sheet_view_real_search_enable_popdown (gpointer data)
11594 PsppSheetView *tree_view = (PsppSheetView *)data;
11596 tree_view->priv->disable_popdown = 0;
11602 pspp_sheet_view_search_enable_popdown (GtkWidget *widget,
11605 gdk_threads_add_timeout_full (G_PRIORITY_HIGH, 200, pspp_sheet_view_real_search_enable_popdown, g_object_ref (data), g_object_unref);
11609 pspp_sheet_view_search_delete_event (GtkWidget *widget,
11610 GdkEventAny *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);
11621 pspp_sheet_view_search_button_press_event (GtkWidget *widget,
11622 GdkEventButton *event,
11623 PsppSheetView *tree_view)
11625 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11627 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11629 if (event->window == tree_view->priv->bin_window)
11630 pspp_sheet_view_button_press (GTK_WIDGET (tree_view), event);
11636 pspp_sheet_view_search_scroll_event (GtkWidget *widget,
11637 GdkEventScroll *event,
11638 PsppSheetView *tree_view)
11640 gboolean retval = FALSE;
11642 if (event->direction == GDK_SCROLL_UP)
11644 pspp_sheet_view_search_move (widget, tree_view, TRUE);
11647 else if (event->direction == GDK_SCROLL_DOWN)
11649 pspp_sheet_view_search_move (widget, tree_view, FALSE);
11653 /* renew the flush timeout */
11654 if (retval && tree_view->priv->typeselect_flush_timeout
11655 && !tree_view->priv->search_custom_entry_set)
11657 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11658 tree_view->priv->typeselect_flush_timeout =
11659 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11660 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11668 pspp_sheet_view_search_key_press_event (GtkWidget *widget,
11669 GdkEventKey *event,
11670 PsppSheetView *tree_view)
11672 gboolean retval = FALSE;
11674 g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
11675 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
11677 /* close window and cancel the search */
11678 if (!tree_view->priv->search_custom_entry_set
11679 && (event->keyval == GDK_Escape ||
11680 event->keyval == GDK_Tab ||
11681 event->keyval == GDK_KP_Tab ||
11682 event->keyval == GDK_ISO_Left_Tab))
11684 pspp_sheet_view_search_dialog_hide (widget, tree_view);
11688 /* select previous matching iter */
11689 if (event->keyval == GDK_Up || event->keyval == GDK_KP_Up)
11691 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
11692 gtk_widget_error_bell (widget);
11697 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK))
11698 && (event->keyval == GDK_g || event->keyval == GDK_G))
11700 if (!pspp_sheet_view_search_move (widget, tree_view, TRUE))
11701 gtk_widget_error_bell (widget);
11706 /* select next matching iter */
11707 if (event->keyval == GDK_Down || event->keyval == GDK_KP_Down)
11709 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
11710 gtk_widget_error_bell (widget);
11715 if (((event->state & (GTK_DEFAULT_ACCEL_MOD_MASK | GDK_SHIFT_MASK)) == GTK_DEFAULT_ACCEL_MOD_MASK)
11716 && (event->keyval == GDK_g || event->keyval == GDK_G))
11718 if (!pspp_sheet_view_search_move (widget, tree_view, FALSE))
11719 gtk_widget_error_bell (widget);
11724 /* renew the flush timeout */
11725 if (retval && tree_view->priv->typeselect_flush_timeout
11726 && !tree_view->priv->search_custom_entry_set)
11728 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11729 tree_view->priv->typeselect_flush_timeout =
11730 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11731 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11738 /* this function returns FALSE if there is a search string but
11739 * nothing was found, and TRUE otherwise.
11742 pspp_sheet_view_search_move (GtkWidget *window,
11743 PsppSheetView *tree_view,
11751 GtkTreeModel *model;
11752 PsppSheetSelection *selection;
11754 text = gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry));
11756 g_return_val_if_fail (text != NULL, FALSE);
11758 len = strlen (text);
11760 if (up && tree_view->priv->selected_iter == 1)
11761 return strlen (text) < 1;
11763 len = strlen (text);
11768 model = pspp_sheet_view_get_model (tree_view);
11769 selection = pspp_sheet_view_get_selection (tree_view);
11772 pspp_sheet_selection_unselect_all (selection);
11773 if (!gtk_tree_model_get_iter_first (model, &iter))
11776 ret = pspp_sheet_view_search_iter (model, selection, &iter, text,
11777 &count, up?((tree_view->priv->selected_iter) - 1):((tree_view->priv->selected_iter + 1)));
11782 tree_view->priv->selected_iter += up?(-1):(1);
11787 /* return to old iter */
11789 gtk_tree_model_get_iter_first (model, &iter);
11790 pspp_sheet_view_search_iter (model, selection,
11792 &count, tree_view->priv->selected_iter);
11798 pspp_sheet_view_search_equal_func (GtkTreeModel *model,
11802 gpointer search_data)
11804 gboolean retval = TRUE;
11806 gchar *normalized_string;
11807 gchar *normalized_key;
11808 gchar *case_normalized_string = NULL;
11809 gchar *case_normalized_key = NULL;
11810 GValue value = {0,};
11811 GValue transformed = {0,};
11813 gtk_tree_model_get_value (model, iter, column, &value);
11815 g_value_init (&transformed, G_TYPE_STRING);
11817 if (!g_value_transform (&value, &transformed))
11819 g_value_unset (&value);
11823 g_value_unset (&value);
11825 str = g_value_get_string (&transformed);
11828 g_value_unset (&transformed);
11832 normalized_string = g_utf8_normalize (str, -1, G_NORMALIZE_ALL);
11833 normalized_key = g_utf8_normalize (key, -1, G_NORMALIZE_ALL);
11835 if (normalized_string && normalized_key)
11837 case_normalized_string = g_utf8_casefold (normalized_string, -1);
11838 case_normalized_key = g_utf8_casefold (normalized_key, -1);
11840 if (strncmp (case_normalized_key, case_normalized_string, strlen (case_normalized_key)) == 0)
11844 g_value_unset (&transformed);
11845 g_free (normalized_key);
11846 g_free (normalized_string);
11847 g_free (case_normalized_key);
11848 g_free (case_normalized_string);
11854 pspp_sheet_view_search_iter (GtkTreeModel *model,
11855 PsppSheetSelection *selection,
11864 PsppSheetView *tree_view = pspp_sheet_selection_get_tree_view (selection);
11866 path = gtk_tree_model_get_path (model, iter);
11867 _pspp_sheet_view_find_node (tree_view, path, &node);
11871 gboolean done = FALSE;
11873 if (! tree_view->priv->search_equal_func (model, tree_view->priv->search_column, text, iter, tree_view->priv->search_user_data))
11878 pspp_sheet_view_scroll_to_cell (tree_view, path, NULL,
11880 pspp_sheet_selection_select_iter (selection, iter);
11881 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE);
11884 gtk_tree_path_free (path);
11893 node = pspp_sheet_view_node_next (tree_view, node);
11899 has_next = gtk_tree_model_iter_next (model, iter);
11902 gtk_tree_path_next (path);
11905 TREE_VIEW_INTERNAL_ASSERT (has_next, FALSE);
11910 gtk_tree_path_free (path);
11912 /* we've run out of tree, done with this func */
11924 pspp_sheet_view_search_init (GtkWidget *entry,
11925 PsppSheetView *tree_view)
11931 GtkTreeModel *model;
11932 PsppSheetSelection *selection;
11934 g_return_if_fail (GTK_IS_ENTRY (entry));
11935 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
11937 text = gtk_entry_get_text (GTK_ENTRY (entry));
11939 model = pspp_sheet_view_get_model (tree_view);
11940 selection = pspp_sheet_view_get_selection (tree_view);
11943 pspp_sheet_selection_unselect_all (selection);
11944 if (tree_view->priv->typeselect_flush_timeout
11945 && !tree_view->priv->search_custom_entry_set)
11947 g_source_remove (tree_view->priv->typeselect_flush_timeout);
11948 tree_view->priv->typeselect_flush_timeout =
11949 gdk_threads_add_timeout (PSPP_SHEET_VIEW_SEARCH_DIALOG_TIMEOUT,
11950 (GSourceFunc) pspp_sheet_view_search_entry_flush_timeout,
11957 if (!gtk_tree_model_get_iter_first (model, &iter))
11960 ret = pspp_sheet_view_search_iter (model, selection,
11965 tree_view->priv->selected_iter = 1;
11969 pspp_sheet_view_remove_widget (GtkCellEditable *cell_editable,
11970 PsppSheetView *tree_view)
11972 if (tree_view->priv->edited_column == NULL)
11975 _pspp_sheet_view_column_stop_editing (tree_view->priv->edited_column);
11976 tree_view->priv->edited_column = NULL;
11978 if (gtk_widget_has_focus (GTK_WIDGET (cell_editable)))
11979 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
11981 g_signal_handlers_disconnect_by_func (cell_editable,
11982 pspp_sheet_view_remove_widget,
11984 g_signal_handlers_disconnect_by_func (cell_editable,
11985 pspp_sheet_view_editable_button_press_event,
11987 g_signal_handlers_disconnect_by_func (cell_editable,
11988 pspp_sheet_view_editable_clicked,
11991 gtk_container_remove (GTK_CONTAINER (tree_view),
11992 GTK_WIDGET (cell_editable));
11994 /* FIXME should only redraw a single node */
11995 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
11999 pspp_sheet_view_start_editing (PsppSheetView *tree_view,
12000 GtkTreePath *cursor_path)
12003 GdkRectangle background_area;
12004 GdkRectangle cell_area;
12005 GtkCellEditable *editable_widget = NULL;
12006 gchar *path_string;
12007 guint flags = 0; /* can be 0, as the flags are primarily for rendering */
12008 gint retval = FALSE;
12011 g_assert (tree_view->priv->focus_column);
12013 if (!gtk_widget_get_realized (GTK_WIDGET (tree_view)))
12016 _pspp_sheet_view_find_node (tree_view, cursor_path, &cursor_node);
12017 if (cursor_node < 0)
12020 path_string = gtk_tree_path_to_string (cursor_path);
12021 gtk_tree_model_get_iter (tree_view->priv->model, &iter, cursor_path);
12023 pspp_sheet_view_column_cell_set_cell_data (tree_view->priv->focus_column,
12024 tree_view->priv->model,
12026 pspp_sheet_view_get_background_area (tree_view,
12028 tree_view->priv->focus_column,
12030 pspp_sheet_view_get_cell_area (tree_view,
12032 tree_view->priv->focus_column,
12035 if (_pspp_sheet_view_column_cell_event (tree_view->priv->focus_column,
12044 if (editable_widget != NULL)
12048 GtkCellRenderer *cell;
12051 cell = _pspp_sheet_view_column_get_edited_cell (tree_view->priv->focus_column);
12053 _pspp_sheet_view_column_get_neighbor_sizes (tree_view->priv->focus_column, cell, &left, &right);
12056 area.width -= right + left;
12058 pspp_sheet_view_real_start_editing (tree_view,
12059 tree_view->priv->focus_column,
12068 g_free (path_string);
12073 pspp_sheet_view_editable_button_press_event (GtkWidget *widget,
12074 GdkEventButton *event,
12075 PsppSheetView *sheet_view)
12079 node = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget),
12080 "pspp-sheet-view-node"));
12081 return pspp_sheet_view_row_head_clicked (sheet_view,
12083 sheet_view->priv->edited_column,
12088 pspp_sheet_view_editable_clicked (GtkButton *button,
12089 PsppSheetView *sheet_view)
12091 pspp_sheet_view_editable_button_press_event (GTK_WIDGET (button), NULL,
12096 is_all_selected (GtkWidget *widget)
12098 GtkEntryBuffer *buffer;
12099 gint start_pos, end_pos;
12101 if (!GTK_IS_ENTRY (widget))
12104 buffer = gtk_entry_get_buffer (GTK_ENTRY (widget));
12105 return (gtk_editable_get_selection_bounds (GTK_EDITABLE (widget),
12106 &start_pos, &end_pos)
12108 && end_pos == gtk_entry_buffer_get_length (buffer));
12112 is_at_left (GtkWidget *widget)
12114 return (GTK_IS_ENTRY (widget)
12115 && gtk_editable_get_position (GTK_EDITABLE (widget)) == 0);
12119 is_at_right (GtkWidget *widget)
12121 GtkEntryBuffer *buffer;
12124 if (!GTK_IS_ENTRY (widget))
12127 buffer = gtk_entry_get_buffer (GTK_ENTRY (widget));
12128 length = gtk_entry_buffer_get_length (buffer);
12129 return gtk_editable_get_position (GTK_EDITABLE (widget)) == length;
12133 pspp_sheet_view_event (GtkWidget *widget,
12134 GdkEventKey *event,
12135 PsppSheetView *tree_view)
12137 PsppSheetViewColumn *column;
12145 /* Intercept only key press events.
12146 It would make sense to use "key-press-event" instead of "event", but
12147 GtkEntry attaches its own signal handler to "key-press-event" that runs
12148 before ours and overrides our desired behavior for GDK_Up and GDK_Down.
12150 if (event->type != GDK_KEY_PRESS)
12153 if (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK | GDK_MOD1_MASK))
12155 /* Pass through most keys that include modifiers. */
12156 if ((event->keyval == GDK_Tab || event->keyval == GDK_ISO_Left_Tab)
12157 && !(event->state & (GDK_CONTROL_MASK | GDK_MOD1_MASK)))
12159 /* Special case for Shift-Tab. */
12165 keyval = event->keyval;
12166 state = event->state & ~(GDK_CONTROL_MASK | GDK_SHIFT_MASK | GDK_MOD1_MASK);
12168 switch (event->keyval)
12170 case GDK_Left: case GDK_KP_Left:
12171 if (!is_all_selected (widget) && !is_at_left (widget))
12175 case GDK_Right: case GDK_KP_Right:
12176 if (!is_all_selected (widget) && !is_at_right (widget))
12180 case GDK_Up: case GDK_KP_Up:
12181 case GDK_Down: case GDK_KP_Down:
12184 case GDK_Page_Up: case GDK_KP_Page_Up:
12185 case GDK_Page_Down: case GDK_KP_Page_Down:
12197 case GDK_ISO_Left_Tab:
12198 keyval = event->state & GDK_SHIFT_MASK ? GDK_Left : GDK_Right;
12205 row = tree_view->priv->edited_row;
12206 column = tree_view->priv->edited_column;
12207 path = gtk_tree_path_new_from_indices (row, -1);
12209 pspp_sheet_view_stop_editing (tree_view, cancel);
12210 gtk_widget_grab_focus (GTK_WIDGET (tree_view));
12212 pspp_sheet_view_set_cursor (tree_view, path, column, FALSE);
12213 gtk_tree_path_free (path);
12215 handled = gtk_binding_set_activate (edit_bindings, keyval, state,
12216 GTK_OBJECT (tree_view));
12218 g_signal_stop_emission_by_name (widget, "event");
12220 pspp_sheet_view_get_cursor (tree_view, &path, NULL);
12221 pspp_sheet_view_start_editing (tree_view, path);
12222 gtk_tree_path_free (path);
12228 pspp_sheet_view_override_cell_keypresses (GtkWidget *widget,
12231 PsppSheetView *sheet_view = data;
12233 g_signal_connect (widget, "event",
12234 G_CALLBACK (pspp_sheet_view_event),
12237 if (GTK_IS_CONTAINER (widget))
12238 gtk_container_foreach (GTK_CONTAINER (widget),
12239 pspp_sheet_view_override_cell_keypresses,
12244 pspp_sheet_view_real_start_editing (PsppSheetView *tree_view,
12245 PsppSheetViewColumn *column,
12247 GtkCellEditable *cell_editable,
12248 GdkRectangle *cell_area,
12252 PsppSheetSelectionMode mode = pspp_sheet_selection_get_mode (tree_view->priv->selection);
12253 gint pre_val = tree_view->priv->vadjustment->value;
12254 GtkRequisition requisition;
12257 g_return_if_fail (gtk_tree_path_get_depth (path) == 1);
12259 tree_view->priv->edited_column = column;
12260 _pspp_sheet_view_column_start_editing (column, GTK_CELL_EDITABLE (cell_editable));
12262 row = gtk_tree_path_get_indices (path)[0];
12263 tree_view->priv->edited_row = row;
12264 pspp_sheet_view_real_set_cursor (tree_view, path, FALSE, TRUE);
12265 cell_area->y += pre_val - (int)tree_view->priv->vadjustment->value;
12267 pspp_sheet_selection_unselect_all_columns (tree_view->priv->selection);
12268 pspp_sheet_selection_select_column (tree_view->priv->selection, column);
12269 tree_view->priv->anchor_column = column;
12271 gtk_widget_size_request (GTK_WIDGET (cell_editable), &requisition);
12273 PSPP_SHEET_VIEW_SET_FLAG (tree_view, PSPP_SHEET_VIEW_DRAW_KEYFOCUS);
12275 if (requisition.height < cell_area->height)
12277 gint diff = cell_area->height - requisition.height;
12278 pspp_sheet_view_put (tree_view,
12279 GTK_WIDGET (cell_editable),
12280 cell_area->x, cell_area->y + diff/2,
12281 cell_area->width, requisition.height);
12285 pspp_sheet_view_put (tree_view,
12286 GTK_WIDGET (cell_editable),
12287 cell_area->x, cell_area->y,
12288 cell_area->width, cell_area->height);
12291 gtk_cell_editable_start_editing (GTK_CELL_EDITABLE (cell_editable),
12292 (GdkEvent *)event);
12294 gtk_widget_grab_focus (GTK_WIDGET (cell_editable));
12295 g_signal_connect (cell_editable, "remove-widget",
12296 G_CALLBACK (pspp_sheet_view_remove_widget), tree_view);
12297 if (mode == PSPP_SHEET_SELECTION_RECTANGLE && column->row_head &&
12298 GTK_IS_BUTTON (cell_editable))
12300 g_signal_connect (cell_editable, "button-press-event",
12301 G_CALLBACK (pspp_sheet_view_editable_button_press_event),
12303 g_object_set_data (G_OBJECT (cell_editable), "pspp-sheet-view-node",
12304 GINT_TO_POINTER (row));
12305 g_signal_connect (cell_editable, "clicked",
12306 G_CALLBACK (pspp_sheet_view_editable_clicked),
12310 pspp_sheet_view_override_cell_keypresses (GTK_WIDGET (cell_editable),
12315 pspp_sheet_view_stop_editing (PsppSheetView *tree_view,
12316 gboolean cancel_editing)
12318 PsppSheetViewColumn *column;
12319 GtkCellRenderer *cell;
12321 if (tree_view->priv->edited_column == NULL)
12325 * This is very evil. We need to do this, because
12326 * gtk_cell_editable_editing_done may trigger pspp_sheet_view_row_changed
12327 * later on. If pspp_sheet_view_row_changed notices
12328 * tree_view->priv->edited_column != NULL, it'll call
12329 * pspp_sheet_view_stop_editing again. Bad things will happen then.
12331 * Please read that again if you intend to modify anything here.
12334 column = tree_view->priv->edited_column;
12335 tree_view->priv->edited_column = NULL;
12337 cell = _pspp_sheet_view_column_get_edited_cell (column);
12338 gtk_cell_renderer_stop_editing (cell, cancel_editing);
12340 if (!cancel_editing)
12341 gtk_cell_editable_editing_done (column->editable_widget);
12343 tree_view->priv->edited_column = column;
12345 gtk_cell_editable_remove_widget (column->editable_widget);
12350 * pspp_sheet_view_set_hover_selection:
12351 * @tree_view: a #PsppSheetView
12352 * @hover: %TRUE to enable hover selection mode
12354 * Enables of disables the hover selection mode of @tree_view.
12355 * Hover selection makes the selected row follow the pointer.
12356 * Currently, this works only for the selection modes
12357 * %PSPP_SHEET_SELECTION_SINGLE and %PSPP_SHEET_SELECTION_BROWSE.
12362 pspp_sheet_view_set_hover_selection (PsppSheetView *tree_view,
12365 hover = hover != FALSE;
12367 if (hover != tree_view->priv->hover_selection)
12369 tree_view->priv->hover_selection = hover;
12371 g_object_notify (G_OBJECT (tree_view), "hover-selection");
12376 * pspp_sheet_view_get_hover_selection:
12377 * @tree_view: a #PsppSheetView
12379 * Returns whether hover selection mode is turned on for @tree_view.
12381 * Return value: %TRUE if @tree_view is in hover selection mode
12386 pspp_sheet_view_get_hover_selection (PsppSheetView *tree_view)
12388 return tree_view->priv->hover_selection;
12392 * pspp_sheet_view_set_rubber_banding:
12393 * @tree_view: a #PsppSheetView
12394 * @enable: %TRUE to enable rubber banding
12396 * Enables or disables rubber banding in @tree_view. If the selection mode is
12397 * #PSPP_SHEET_SELECTION_MULTIPLE or #PSPP_SHEET_SELECTION_RECTANGLE, rubber
12398 * banding will allow the user to select multiple rows by dragging the mouse.
12403 pspp_sheet_view_set_rubber_banding (PsppSheetView *tree_view,
12406 enable = enable != FALSE;
12408 if (enable != tree_view->priv->rubber_banding_enable)
12410 tree_view->priv->rubber_banding_enable = enable;
12412 g_object_notify (G_OBJECT (tree_view), "rubber-banding");
12417 * pspp_sheet_view_get_rubber_banding:
12418 * @tree_view: a #PsppSheetView
12420 * Returns whether rubber banding is turned on for @tree_view. If the
12421 * selection mode is #PSPP_SHEET_SELECTION_MULTIPLE or
12422 * #PSPP_SHEET_SELECTION_RECTANGLE, rubber banding will allow the user to
12423 * select multiple rows by dragging the mouse.
12425 * Return value: %TRUE if rubber banding in @tree_view is enabled.
12430 pspp_sheet_view_get_rubber_banding (PsppSheetView *tree_view)
12432 return tree_view->priv->rubber_banding_enable;
12436 * pspp_sheet_view_is_rubber_banding_active:
12437 * @tree_view: a #PsppSheetView
12439 * Returns whether a rubber banding operation is currently being done
12442 * Return value: %TRUE if a rubber banding operation is currently being
12443 * done in @tree_view.
12448 pspp_sheet_view_is_rubber_banding_active (PsppSheetView *tree_view)
12450 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
12452 if (tree_view->priv->rubber_banding_enable
12453 && tree_view->priv->rubber_band_status == RUBBER_BAND_ACTIVE)
12460 pspp_sheet_view_grab_notify (GtkWidget *widget,
12461 gboolean was_grabbed)
12463 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12465 tree_view->priv->in_grab = !was_grabbed;
12469 tree_view->priv->pressed_button = -1;
12471 if (tree_view->priv->rubber_band_status)
12472 pspp_sheet_view_stop_rubber_band (tree_view);
12477 pspp_sheet_view_state_changed (GtkWidget *widget,
12478 GtkStateType previous_state)
12480 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12482 if (gtk_widget_get_realized (widget))
12484 gdk_window_set_back_pixmap (widget->window, NULL, FALSE);
12485 gdk_window_set_background (tree_view->priv->bin_window, &widget->style->base[widget->state]);
12488 gtk_widget_queue_draw (widget);
12492 * pspp_sheet_view_get_grid_lines:
12493 * @tree_view: a #PsppSheetView
12495 * Returns which grid lines are enabled in @tree_view.
12497 * Return value: a #PsppSheetViewGridLines value indicating which grid lines
12502 PsppSheetViewGridLines
12503 pspp_sheet_view_get_grid_lines (PsppSheetView *tree_view)
12505 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12507 return tree_view->priv->grid_lines;
12511 * pspp_sheet_view_set_grid_lines:
12512 * @tree_view: a #PsppSheetView
12513 * @grid_lines: a #PsppSheetViewGridLines value indicating which grid lines to
12516 * Sets which grid lines to draw in @tree_view.
12521 pspp_sheet_view_set_grid_lines (PsppSheetView *tree_view,
12522 PsppSheetViewGridLines grid_lines)
12524 PsppSheetViewPrivate *priv;
12526 PsppSheetViewGridLines old_grid_lines;
12528 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12530 priv = tree_view->priv;
12531 widget = GTK_WIDGET (tree_view);
12533 old_grid_lines = priv->grid_lines;
12534 priv->grid_lines = grid_lines;
12536 if (old_grid_lines != grid_lines)
12538 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12540 g_object_notify (G_OBJECT (tree_view), "enable-grid-lines");
12545 * pspp_sheet_view_get_special_cells:
12546 * @tree_view: a #PsppSheetView
12548 * Returns which grid lines are enabled in @tree_view.
12550 * Return value: a #PsppSheetViewSpecialCells value indicating whether rows in
12551 * the sheet view contain special cells.
12553 PsppSheetViewSpecialCells
12554 pspp_sheet_view_get_special_cells (PsppSheetView *tree_view)
12556 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12558 return tree_view->priv->special_cells;
12562 * pspp_sheet_view_set_special_cells:
12563 * @tree_view: a #PsppSheetView
12564 * @special_cells: a #PsppSheetViewSpecialCells value indicating whether rows in
12565 * the sheet view contain special cells.
12567 * Sets whether rows in the sheet view contain special cells, controlling the
12568 * rendering of row selections.
12571 pspp_sheet_view_set_special_cells (PsppSheetView *tree_view,
12572 PsppSheetViewSpecialCells special_cells)
12574 PsppSheetViewPrivate *priv;
12577 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12579 priv = tree_view->priv;
12580 widget = GTK_WIDGET (tree_view);
12582 if (priv->special_cells != special_cells)
12584 priv->special_cells = special_cells;
12585 gtk_widget_queue_draw (GTK_WIDGET (tree_view));
12586 g_object_notify (G_OBJECT (tree_view), "special-cells");
12591 pspp_sheet_view_get_fixed_height (const PsppSheetView *tree_view)
12593 /* XXX (re)calculate fixed_height if necessary */
12594 return tree_view->priv->fixed_height;
12598 pspp_sheet_view_set_fixed_height (PsppSheetView *tree_view,
12601 g_return_if_fail (fixed_height > 0);
12603 if (tree_view->priv->fixed_height != fixed_height)
12605 tree_view->priv->fixed_height = fixed_height;
12606 g_object_notify (G_OBJECT (tree_view), "fixed-height");
12608 if (!tree_view->priv->fixed_height_set)
12610 tree_view->priv->fixed_height_set = TRUE;
12611 g_object_notify (G_OBJECT (tree_view), "fixed-height-set");
12616 * pspp_sheet_view_set_tooltip_row:
12617 * @tree_view: a #PsppSheetView
12618 * @tooltip: a #GtkTooltip
12619 * @path: a #GtkTreePath
12621 * Sets the tip area of @tooltip to be the area covered by the row at @path.
12622 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
12623 * See also gtk_tooltip_set_tip_area().
12628 pspp_sheet_view_set_tooltip_row (PsppSheetView *tree_view,
12629 GtkTooltip *tooltip,
12632 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12633 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
12635 pspp_sheet_view_set_tooltip_cell (tree_view, tooltip, path, NULL, NULL);
12639 * pspp_sheet_view_set_tooltip_cell:
12640 * @tree_view: a #PsppSheetView
12641 * @tooltip: a #GtkTooltip
12642 * @path: (allow-none): a #GtkTreePath or %NULL
12643 * @column: (allow-none): a #PsppSheetViewColumn or %NULL
12644 * @cell: (allow-none): a #GtkCellRenderer or %NULL
12646 * Sets the tip area of @tooltip to the area @path, @column and @cell have
12647 * in common. For example if @path is %NULL and @column is set, the tip
12648 * area will be set to the full area covered by @column. See also
12649 * gtk_tooltip_set_tip_area().
12651 * See also pspp_sheet_view_set_tooltip_column() for a simpler alternative.
12656 pspp_sheet_view_set_tooltip_cell (PsppSheetView *tree_view,
12657 GtkTooltip *tooltip,
12659 PsppSheetViewColumn *column,
12660 GtkCellRenderer *cell)
12664 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12665 g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
12666 g_return_if_fail (column == NULL || PSPP_IS_SHEET_VIEW_COLUMN (column));
12667 g_return_if_fail (cell == NULL || GTK_IS_CELL_RENDERER (cell));
12669 /* Determine x values. */
12670 if (column && cell)
12675 pspp_sheet_view_get_cell_area (tree_view, path, column, &tmp);
12676 pspp_sheet_view_column_cell_get_position (column, cell, &start, &width);
12678 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12681 rect.width = width;
12687 pspp_sheet_view_get_background_area (tree_view, NULL, column, &tmp);
12688 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12691 rect.width = tmp.width;
12696 rect.width = GTK_WIDGET (tree_view)->allocation.width;
12699 /* Determine y values. */
12704 pspp_sheet_view_get_background_area (tree_view, path, NULL, &tmp);
12705 pspp_sheet_view_convert_bin_window_to_widget_coords (tree_view,
12708 rect.height = tmp.height;
12713 rect.height = tree_view->priv->vadjustment->page_size;
12716 gtk_tooltip_set_tip_area (tooltip, &rect);
12720 * pspp_sheet_view_get_tooltip_context:
12721 * @tree_view: a #PsppSheetView
12722 * @x: the x coordinate (relative to widget coordinates)
12723 * @y: the y coordinate (relative to widget coordinates)
12724 * @keyboard_tip: whether this is a keyboard tooltip or not
12725 * @model: (allow-none): a pointer to receive a #GtkTreeModel or %NULL
12726 * @path: (allow-none): a pointer to receive a #GtkTreePath or %NULL
12727 * @iter: (allow-none): a pointer to receive a #GtkTreeIter or %NULL
12729 * This function is supposed to be used in a #GtkWidget::query-tooltip
12730 * signal handler for #PsppSheetView. The @x, @y and @keyboard_tip values
12731 * which are received in the signal handler, should be passed to this
12732 * function without modification.
12734 * The return value indicates whether there is a tree view row at the given
12735 * coordinates (%TRUE) or not (%FALSE) for mouse tooltips. For keyboard
12736 * tooltips the row returned will be the cursor row. When %TRUE, then any of
12737 * @model, @path and @iter which have been provided will be set to point to
12738 * that row and the corresponding model. @x and @y will always be converted
12739 * to be relative to @tree_view's bin_window if @keyboard_tooltip is %FALSE.
12741 * Return value: whether or not the given tooltip context points to a row.
12746 pspp_sheet_view_get_tooltip_context (PsppSheetView *tree_view,
12749 gboolean keyboard_tip,
12750 GtkTreeModel **model,
12751 GtkTreePath **path,
12754 GtkTreePath *tmppath = NULL;
12756 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), FALSE);
12757 g_return_val_if_fail (x != NULL, FALSE);
12758 g_return_val_if_fail (y != NULL, FALSE);
12762 pspp_sheet_view_get_cursor (tree_view, &tmppath, NULL);
12769 pspp_sheet_view_convert_widget_to_bin_window_coords (tree_view, *x, *y,
12772 if (!pspp_sheet_view_get_path_at_pos (tree_view, *x, *y,
12773 &tmppath, NULL, NULL, NULL))
12778 *model = pspp_sheet_view_get_model (tree_view);
12781 gtk_tree_model_get_iter (pspp_sheet_view_get_model (tree_view),
12787 gtk_tree_path_free (tmppath);
12793 pspp_sheet_view_set_tooltip_query_cb (GtkWidget *widget,
12796 gboolean keyboard_tip,
12797 GtkTooltip *tooltip,
12800 GValue value = { 0, };
12801 GValue transformed = { 0, };
12804 GtkTreeModel *model;
12805 PsppSheetView *tree_view = PSPP_SHEET_VIEW (widget);
12807 if (!pspp_sheet_view_get_tooltip_context (PSPP_SHEET_VIEW (widget),
12810 &model, &path, &iter))
12813 gtk_tree_model_get_value (model, &iter,
12814 tree_view->priv->tooltip_column, &value);
12816 g_value_init (&transformed, G_TYPE_STRING);
12818 if (!g_value_transform (&value, &transformed))
12820 g_value_unset (&value);
12821 gtk_tree_path_free (path);
12826 g_value_unset (&value);
12828 if (!g_value_get_string (&transformed))
12830 g_value_unset (&transformed);
12831 gtk_tree_path_free (path);
12836 gtk_tooltip_set_markup (tooltip, g_value_get_string (&transformed));
12837 pspp_sheet_view_set_tooltip_row (tree_view, tooltip, path);
12839 gtk_tree_path_free (path);
12840 g_value_unset (&transformed);
12846 * pspp_sheet_view_set_tooltip_column:
12847 * @tree_view: a #PsppSheetView
12848 * @column: an integer, which is a valid column number for @tree_view's model
12850 * If you only plan to have simple (text-only) tooltips on full rows, you
12851 * can use this function to have #PsppSheetView handle these automatically
12852 * for you. @column should be set to the column in @tree_view's model
12853 * containing the tooltip texts, or -1 to disable this feature.
12855 * When enabled, #GtkWidget::has-tooltip will be set to %TRUE and
12856 * @tree_view will connect a #GtkWidget::query-tooltip signal handler.
12858 * Note that the signal handler sets the text with gtk_tooltip_set_markup(),
12859 * so &, <, etc have to be escaped in the text.
12864 pspp_sheet_view_set_tooltip_column (PsppSheetView *tree_view,
12867 g_return_if_fail (PSPP_IS_SHEET_VIEW (tree_view));
12869 if (column == tree_view->priv->tooltip_column)
12874 g_signal_handlers_disconnect_by_func (tree_view,
12875 pspp_sheet_view_set_tooltip_query_cb,
12877 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), FALSE);
12881 if (tree_view->priv->tooltip_column == -1)
12883 g_signal_connect (tree_view, "query-tooltip",
12884 G_CALLBACK (pspp_sheet_view_set_tooltip_query_cb), NULL);
12885 gtk_widget_set_has_tooltip (GTK_WIDGET (tree_view), TRUE);
12889 tree_view->priv->tooltip_column = column;
12890 g_object_notify (G_OBJECT (tree_view), "tooltip-column");
12894 * pspp_sheet_view_get_tooltip_column:
12895 * @tree_view: a #PsppSheetView
12897 * Returns the column of @tree_view's model which is being used for
12898 * displaying tooltips on @tree_view's rows.
12900 * Return value: the index of the tooltip column that is currently being
12901 * used, or -1 if this is disabled.
12906 pspp_sheet_view_get_tooltip_column (PsppSheetView *tree_view)
12908 g_return_val_if_fail (PSPP_IS_SHEET_VIEW (tree_view), 0);
12910 return tree_view->priv->tooltip_column;
12914 _gtk_boolean_handled_accumulator (GSignalInvocationHint *ihint,
12915 GValue *return_accu,
12916 const GValue *handler_return,
12919 gboolean continue_emission;
12920 gboolean signal_handled;
12922 signal_handled = g_value_get_boolean (handler_return);
12923 g_value_set_boolean (return_accu, signal_handled);
12924 continue_emission = !signal_handled;
12926 return continue_emission;
12930 pspp_sheet_view_grid_lines_get_type (void)
12932 static GType etype = 0;
12933 if (G_UNLIKELY(etype == 0)) {
12934 static const GEnumValue values[] = {
12935 { PSPP_SHEET_VIEW_GRID_LINES_NONE, "PSPP_SHEET_VIEW_GRID_LINES_NONE", "none" },
12936 { PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL, "PSPP_SHEET_VIEW_GRID_LINES_HORIZONTAL", "horizontal" },
12937 { PSPP_SHEET_VIEW_GRID_LINES_VERTICAL, "PSPP_SHEET_VIEW_GRID_LINES_VERTICAL", "vertical" },
12938 { PSPP_SHEET_VIEW_GRID_LINES_BOTH, "PSPP_SHEET_VIEW_GRID_LINES_BOTH", "both" },
12941 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewGridLines"), values);
12947 pspp_sheet_view_special_cells_get_type (void)
12949 static GType etype = 0;
12950 if (G_UNLIKELY(etype == 0)) {
12951 static const GEnumValue values[] = {
12952 { PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT, "PSPP_SHEET_VIEW_SPECIAL_CELLS_DETECT", "detect" },
12953 { PSPP_SHEET_VIEW_SPECIAL_CELLS_YES, "PSPP_SHEET_VIEW_SPECIAL_CELLS_YES", "yes" },
12954 { PSPP_SHEET_VIEW_SPECIAL_CELLS_NO, "PSPP_SHEET_VIEW_SPECIAL_CELLS_NO", "no" },
12957 etype = g_enum_register_static (g_intern_static_string ("PsppSheetViewSpecialCells"), values);